Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

Pull USB / Thunderbolt updates from Greg KH:
"Here is the big set of USB and Thunderbolt changes for 6.9-rc1. Lots
of tiny changes and forward progress to support new hardware and
better support for existing devices. Included in here are:

- Thunderbolt (i.e. USB4) updates for newer hardware and uses as more
people start to use the hardware

- default USB authentication mode Kconfig and documentation update to
make it more obvious what is going on

- USB typec updates and enhancements

- usual dwc3 driver updates

- usual xhci driver updates

- function USB (i.e. gadget) driver updates and additions

- new device ids for lots of drivers

- loads of other small updates, full details in the shortlog

All of these, including a "last minute regression fix" have been in
linux-next with no reported issues"

* tag 'usb-6.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb: (185 commits)
usb: usb-acpi: Fix oops due to freeing uninitialized pld pointer
usb: gadget: net2272: Use irqflags in the call to net2272_probe_fin
usb: gadget: tegra-xudc: Fix USB3 PHY retrieval logic
phy: tegra: xusb: Add API to retrieve the port number of phy
USB: gadget: pxa27x_udc: Remove unused of_gpio.h
usb: gadget/snps_udc_plat: Remove unused of_gpio.h
usb: ohci-pxa27x: Remove unused of_gpio.h
usb: sl811-hcd: only defined function checkdone if QUIRK2 is defined
usb: Clarify expected behavior of dev_bin_attrs_are_visible()
xhci: Allow RPM on the USB controller (1022:43f7) by default
usb: isp1760: remove SLAB_MEM_SPREAD flag usage
usb: misc: onboard_hub: use pointer consistently in the probe function
usb: gadget: fsl: Increase size of name buffer for endpoints
usb: gadget: fsl: Add of device table to enable module autoloading
usb: typec: tcpm: add support to set tcpc connector orientatition
usb: typec: tcpci: add generic tcpci fallback compatible
dt-bindings: usb: typec-tcpci: add tcpci fallback binding
usb: gadget: fsl-udc: Replace custom log wrappers by dev_{err,warn,dbg,vdbg}
usb: core: Set connect_type of ports based on DT node
dt-bindings: usb: Add downstream facing ports to realtek binding
...

+9091 -2447
+10 -2
Documentation/ABI/testing/configfs-usb-gadget-ffs
··· 4 4 Description: The purpose of this directory is to create and remove it. 5 5 6 6 A corresponding USB function instance is created/removed. 7 - There are no attributes here. 8 7 9 - All parameters are set through FunctionFS. 8 + All attributes are read only: 9 + 10 + ============= ============================================ 11 + ready 1 if the function is ready to be used, E.G. 12 + if userspace has written descriptors and 13 + strings to ep0, so the gadget can be 14 + enabled - 0 otherwise. 15 + ============= ============================================ 16 + 17 + All other parameters are set through FunctionFS.
+10
Documentation/ABI/testing/sysfs-bus-usb
··· 442 442 Description: 443 443 Contains the interface descriptors, in binary. 444 444 445 + What: /sys/bus/usb/devices/usbX/bos_descriptors 446 + Date: March 2024 447 + Contact: Elbert Mai <code@elbertmai.com> 448 + Description: 449 + Binary file containing the cached binary device object store (BOS) 450 + of the device. This consists of the BOS descriptor followed by the 451 + set of device capability descriptors. All descriptors read from 452 + this file are in bus-endian format. Note that the kernel will not 453 + request the BOS from a device if its bcdUSB is less than 0x0201. 454 + 445 455 What: /sys/bus/usb/devices/usbX/idProduct 446 456 Description: 447 457 Product ID, in hexadecimal.
+6
Documentation/ABI/testing/sysfs-class-usb_role
··· 19 19 - none 20 20 - host 21 21 - device 22 + 23 + What: /sys/class/usb_role/<switch>/connector 24 + Date: Feb 2024 25 + Contact: Heikki Krogerus <heikki.krogerus@linux.intel.com> 26 + Description: 27 + Optional symlink to the USB Type-C connector.
+1
Documentation/devicetree/bindings/regulator/qcom,usb-vbus-regulator.yaml
··· 26 26 - enum: 27 27 - qcom,pm4125-vbus-reg 28 28 - qcom,pm6150-vbus-reg 29 + - qcom,pmi632-vbus-reg 29 30 - const: qcom,pm8150b-vbus-reg 30 31 31 32 reg:
+1
Documentation/devicetree/bindings/soc/qcom/qcom,pmic-glink.yaml
··· 23 23 oneOf: 24 24 - items: 25 25 - enum: 26 + - qcom,qcm6490-pmic-glink 26 27 - qcom,sc8180x-pmic-glink 27 28 - qcom,sc8280xp-pmic-glink 28 29 - qcom,sm8350-pmic-glink
+55
Documentation/devicetree/bindings/sound/qcom,q6usb.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/sound/qcom,q6usb.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Qualcomm ASoC DPCM USB backend DAI 8 + 9 + maintainers: 10 + - Wesley Cheng <quic_wcheng@quicinc.com> 11 + 12 + description: 13 + The USB port is a supported AFE path on the Q6 DSP. This ASoC DPCM 14 + backend DAI will communicate the required settings to initialize the 15 + XHCI host controller properly for enabling the offloaded audio stream. 16 + Parameters defined under this node will carry settings, which will be 17 + passed along during the QMI stream enable request and configuration of 18 + the XHCI host controller. 19 + 20 + allOf: 21 + - $ref: dai-common.yaml# 22 + 23 + properties: 24 + compatible: 25 + enum: 26 + - qcom,q6usb 27 + 28 + iommus: 29 + maxItems: 1 30 + 31 + "#sound-dai-cells": 32 + const: 1 33 + 34 + qcom,usb-audio-intr-idx: 35 + description: 36 + Desired XHCI interrupter number to use. Depending on the audio DSP 37 + on the platform, it will operate on a specific XHCI interrupter. 38 + $ref: /schemas/types.yaml#/definitions/uint16 39 + maximum: 8 40 + 41 + required: 42 + - compatible 43 + - "#sound-dai-cells" 44 + - qcom,usb-audio-intr-idx 45 + 46 + additionalProperties: false 47 + 48 + examples: 49 + - | 50 + dais { 51 + compatible = "qcom,q6usb"; 52 + #sound-dai-cells = <1>; 53 + iommus = <&apps_smmu 0x180f 0x0>; 54 + qcom,usb-audio-intr-idx = /bits/ 16 <2>; 55 + };
-13
Documentation/devicetree/bindings/usb/analogix,anx7411.yaml
··· 23 23 connector: 24 24 type: object 25 25 $ref: ../connector/usb-connector.yaml 26 - unevaluatedProperties: false 27 - 28 - description: 29 - Properties for usb c connector. 30 26 31 27 properties: 32 28 compatible: 33 29 const: usb-c-connector 34 - 35 - power-role: true 36 - 37 - data-role: true 38 - 39 - try-power-role: true 40 - 41 - required: 42 - - compatible 43 30 44 31 required: 45 32 - compatible
+1 -1
Documentation/devicetree/bindings/usb/ci-hdrc-usb2.yaml
··· 313 313 314 314 usb-phy: 315 315 description: phandle for the PHY device. Use "phys" instead. 316 - $ref: /schemas/types.yaml#/definitions/phandle 316 + maxItems: 1 317 317 deprecated: true 318 318 319 319 fsl,usbphy:
+5 -7
Documentation/devicetree/bindings/usb/fcs,fsa4480.yaml
··· 27 27 vcc-supply: 28 28 description: power supply (2.7V-5.5V) 29 29 30 - mode-switch: 31 - description: Flag the port as possible handle of altmode switching 32 - type: boolean 33 - 34 - orientation-switch: 35 - description: Flag the port as possible handler of orientation switching 36 - type: boolean 30 + mode-switch: true 31 + orientation-switch: true 37 32 38 33 port: 39 34 $ref: /schemas/graph.yaml#/$defs/port-base ··· 73 78 - compatible 74 79 - reg 75 80 - port 81 + 82 + allOf: 83 + - $ref: usb-switch.yaml# 76 84 77 85 additionalProperties: false 78 86
+1
Documentation/devicetree/bindings/usb/generic-ehci.yaml
··· 77 77 - const: usb-ehci 78 78 - enum: 79 79 - generic-ehci 80 + - marvell,ac5-ehci 80 81 - marvell,armada-3700-ehci 81 82 - marvell,orion-ehci 82 83 - nuvoton,npcm750-ehci
+5 -7
Documentation/devicetree/bindings/usb/gpio-sbu-mux.yaml
··· 33 33 vcc-supply: 34 34 description: power supply 35 35 36 - mode-switch: 37 - description: Flag the port as possible handle of altmode switching 38 - type: boolean 39 - 40 - orientation-switch: 41 - description: Flag the port as possible handler of orientation switching 42 - type: boolean 36 + mode-switch: true 37 + orientation-switch: true 43 38 44 39 port: 45 40 $ref: /schemas/graph.yaml#/properties/port ··· 48 53 - select-gpios 49 54 - orientation-switch 50 55 - port 56 + 57 + allOf: 58 + - $ref: usb-switch.yaml# 51 59 52 60 additionalProperties: false 53 61
+99
Documentation/devicetree/bindings/usb/hisilicon,hi3798mv200-dwc3.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/usb/hisilicon,hi3798mv200-dwc3.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: HiSilicon Hi3798MV200 DWC3 USB SoC controller 8 + 9 + maintainers: 10 + - Yang Xiwen <forbidden405@foxmail.com> 11 + 12 + properties: 13 + compatible: 14 + const: hisilicon,hi3798mv200-dwc3 15 + 16 + '#address-cells': 17 + const: 1 18 + 19 + '#size-cells': 20 + const: 1 21 + 22 + ranges: true 23 + 24 + clocks: 25 + items: 26 + - description: Controller bus clock 27 + - description: Controller suspend clock 28 + - description: Controller reference clock 29 + - description: Controller gm clock 30 + - description: Controller gs clock 31 + - description: Controller utmi clock 32 + - description: Controller pipe clock 33 + 34 + clock-names: 35 + items: 36 + - const: bus 37 + - const: suspend 38 + - const: ref 39 + - const: gm 40 + - const: gs 41 + - const: utmi 42 + - const: pipe 43 + 44 + resets: 45 + maxItems: 1 46 + 47 + reset-names: 48 + const: soft 49 + 50 + patternProperties: 51 + '^usb@[0-9a-f]+$': 52 + $ref: snps,dwc3.yaml# 53 + 54 + required: 55 + - compatible 56 + - ranges 57 + - '#address-cells' 58 + - '#size-cells' 59 + - clocks 60 + - clock-names 61 + - resets 62 + - reset-names 63 + 64 + additionalProperties: false 65 + 66 + examples: 67 + - | 68 + #include <dt-bindings/interrupt-controller/arm-gic.h> 69 + 70 + usb { 71 + compatible = "hisilicon,hi3798mv200-dwc3"; 72 + ranges; 73 + #address-cells = <1>; 74 + #size-cells = <1>; 75 + clocks = <&clk_bus>, 76 + <&clk_suspend>, 77 + <&clk_ref>, 78 + <&clk_gm>, 79 + <&clk_gs>, 80 + <&clk_utmi>, 81 + <&clk_pipe>; 82 + clock-names = "bus", "suspend", "ref", "gm", "gs", "utmi", "pipe"; 83 + resets = <&crg 0xb0 12>; 84 + reset-names = "soft"; 85 + 86 + usb@98a0000 { 87 + compatible = "snps,dwc3"; 88 + reg = <0x98a0000 0x10000>; 89 + interrupts = <GIC_SPI 69 IRQ_TYPE_LEVEL_HIGH>; 90 + clocks = <&clk_bus>, 91 + <&clk_suspend>, 92 + <&clk_ref>; 93 + clock-names = "bus_early", "suspend", "ref"; 94 + phys = <&usb2_phy1_port2>, <&combphy0 0>; 95 + phy-names = "usb2-phy", "usb3-phy"; 96 + maximum-speed = "super-speed"; 97 + dr_mode = "host"; 98 + }; 99 + };
+72
Documentation/devicetree/bindings/usb/ite,it5205.yaml
··· 1 + # SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/usb/ite,it5205.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: ITE IT5202 Type-C USB Alternate Mode Passive MUX 8 + 9 + maintainers: 10 + - AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com> 11 + - Tianping Fang <tianping.fang@mediatek.com> 12 + 13 + properties: 14 + compatible: 15 + const: ite,it5205 16 + 17 + reg: 18 + maxItems: 1 19 + 20 + vcc-supply: 21 + description: Power supply for VCC pin (3.3V) 22 + 23 + mode-switch: 24 + description: Flag the port as possible handle of altmode switching 25 + type: boolean 26 + 27 + orientation-switch: 28 + description: Flag the port as possible handler of orientation switching 29 + type: boolean 30 + 31 + ite,ovp-enable: 32 + description: Enable Over Voltage Protection functionality 33 + type: boolean 34 + 35 + port: 36 + $ref: /schemas/graph.yaml#/properties/port 37 + description: 38 + A port node to link the IT5205 to a TypeC controller for the purpose of 39 + handling altmode muxing and orientation switching. 40 + 41 + required: 42 + - compatible 43 + - reg 44 + - orientation-switch 45 + - port 46 + 47 + additionalProperties: false 48 + 49 + examples: 50 + - | 51 + #include <dt-bindings/interrupt-controller/irq.h> 52 + i2c2 { 53 + #address-cells = <1>; 54 + #size-cells = <0>; 55 + 56 + typec-mux@48 { 57 + compatible = "ite,it5205"; 58 + reg = <0x48>; 59 + 60 + mode-switch; 61 + orientation-switch; 62 + 63 + vcc-supply = <&mt6359_vibr_ldo_reg>; 64 + 65 + port { 66 + it5205_usbss_sbu: endpoint { 67 + remote-endpoint = <&typec_controller>; 68 + }; 69 + }; 70 + }; 71 + }; 72 + ...
+4 -1
Documentation/devicetree/bindings/usb/mediatek,mtu3.yaml
··· 185 185 2 - used by mt2712 etc, revision 2 with following IPM rule; 186 186 101 - used by mt8183, specific 1.01; 187 187 102 - used by mt8192, specific 1.02; 188 - enum: [1, 2, 101, 102] 188 + 103 - used by mt8195, IP0, specific 1.03; 189 + 105 - used by mt8195, IP2, specific 1.05; 190 + 106 - used by mt8195, IP3, specific 1.06; 191 + enum: [1, 2, 101, 102, 103, 105, 106] 189 192 190 193 mediatek,u3p-dis-msk: 191 194 $ref: /schemas/types.yaml#/definitions/uint32
-2
Documentation/devicetree/bindings/usb/microchip,usb5744.yaml
··· 72 72 i2c-bus: false 73 73 else: 74 74 $ref: /schemas/usb/usb-device.yaml 75 - required: 76 - - peer-hub 77 75 78 76 additionalProperties: false 79 77
+5 -7
Documentation/devicetree/bindings/usb/nxp,ptn36502.yaml
··· 20 20 vdd18-supply: 21 21 description: Power supply for VDD18 pin 22 22 23 - retimer-switch: 24 - description: Flag the port as possible handle of SuperSpeed signals retiming 25 - type: boolean 26 - 27 - orientation-switch: 28 - description: Flag the port as possible handler of orientation switching 29 - type: boolean 23 + orientation-switch: true 24 + retimer-switch: true 30 25 31 26 ports: 32 27 $ref: /schemas/graph.yaml#/properties/ports ··· 43 48 required: 44 49 - compatible 45 50 - reg 51 + 52 + allOf: 53 + - $ref: usb-switch.yaml# 46 54 47 55 additionalProperties: false 48 56
+4 -2
Documentation/devicetree/bindings/usb/nxp,ptn5110.yaml
··· 11 11 12 12 properties: 13 13 compatible: 14 - const: nxp,ptn5110 14 + items: 15 + - const: nxp,ptn5110 16 + - const: tcpci 15 17 16 18 reg: 17 19 maxItems: 1 ··· 43 41 #size-cells = <0>; 44 42 45 43 tcpci@50 { 46 - compatible = "nxp,ptn5110"; 44 + compatible = "nxp,ptn5110", "tcpci"; 47 45 reg = <0x50>; 48 46 interrupt-parent = <&gpio3>; 49 47 interrupts = <3 IRQ_TYPE_LEVEL_LOW>;
+5 -8
Documentation/devicetree/bindings/usb/onnn,nb7vpq904m.yaml
··· 21 21 description: power supply (1.8V) 22 22 23 23 enable-gpios: true 24 - 25 - retimer-switch: 26 - description: Flag the port as possible handle of SuperSpeed signals retiming 27 - type: boolean 28 - 29 - orientation-switch: 30 - description: Flag the port as possible handler of orientation switching 31 - type: boolean 24 + orientation-switch: true 25 + retimer-switch: true 32 26 33 27 ports: 34 28 $ref: /schemas/graph.yaml#/properties/ports ··· 88 94 required: 89 95 - compatible 90 96 - reg 97 + 98 + allOf: 99 + - $ref: usb-switch.yaml# 91 100 92 101 additionalProperties: false 93 102
+1 -1
Documentation/devicetree/bindings/usb/qcom,dwc3.yaml
··· 102 102 description: | 103 103 Different types of interrupts are used based on HS PHY used on target: 104 104 - pwr_event: Used for wakeup based on other power events. 105 - - hs_phY_irq: Apart from DP/DM/QUSB2 PHY interrupts, there is 105 + - hs_phy_irq: Apart from DP/DM/QUSB2 PHY interrupts, there is 106 106 hs_phy_irq which is not triggered by default and its 107 107 functionality is mutually exclusive to that of 108 108 {dp/dm}_hs_phy_irq and qusb2_phy_irq.
+43 -3
Documentation/devicetree/bindings/usb/qcom,pmic-typec.yaml
··· 14 14 15 15 properties: 16 16 compatible: 17 - enum: 18 - - qcom,pm8150b-typec 17 + oneOf: 18 + - enum: 19 + - qcom,pmi632-typec 20 + - qcom,pm8150b-typec 21 + - items: 22 + - enum: 23 + - qcom,pm6150-typec 24 + - const: qcom,pm8150b-typec 25 + - items: 26 + - enum: 27 + - qcom,pm4125-typec 28 + - const: qcom,pmi632-typec 29 + 19 30 20 31 connector: 21 32 type: object ··· 35 24 36 25 reg: 37 26 description: Type-C port and pdphy SPMI register base offsets 27 + minItems: 1 38 28 maxItems: 2 39 29 40 30 interrupts: 31 + minItems: 8 41 32 items: 42 33 - description: Type-C CC attach notification, VBUS error, tCCDebounce done 43 34 - description: Type-C VCONN powered ··· 59 46 - description: Power Domain Fast Role Swap event 60 47 61 48 interrupt-names: 49 + minItems: 8 62 50 items: 63 51 - const: or-rid-detect-change 64 52 - const: vpd-detect ··· 95 81 - interrupts 96 82 - interrupt-names 97 83 - vdd-vbus-supply 98 - - vdd-pdphy-supply 84 + 85 + allOf: 86 + - if: 87 + properties: 88 + compatible: 89 + contains: 90 + enum: 91 + - qcom,pmi632-typec 92 + then: 93 + properties: 94 + reg: 95 + maxItems: 1 96 + interrupts: 97 + maxItems: 8 98 + interrupt-names: 99 + maxItems: 8 100 + vdd-pdphy-supply: false 101 + else: 102 + properties: 103 + reg: 104 + maxItems: 2 105 + interrupts: 106 + minItems: 16 107 + interrupt-names: 108 + maxItems: 16 109 + required: 110 + - vdd-pdphy-supply 99 111 100 112 additionalProperties: false 101 113
+5 -7
Documentation/devicetree/bindings/usb/qcom,wcd939x-usbss.yaml
··· 35 35 vdd-supply: 36 36 description: USBSS VDD power supply 37 37 38 - mode-switch: 39 - description: Flag the port as possible handle of altmode switching 40 - type: boolean 41 - 42 - orientation-switch: 43 - description: Flag the port as possible handler of orientation switching 44 - type: boolean 38 + mode-switch: true 39 + orientation-switch: true 45 40 46 41 ports: 47 42 $ref: /schemas/graph.yaml#/properties/ports ··· 57 62 - compatible 58 63 - reg 59 64 - ports 65 + 66 + allOf: 67 + - $ref: usb-switch.yaml# 60 68 61 69 additionalProperties: false 62 70
+55
Documentation/devicetree/bindings/usb/realtek,rts5411.yaml
··· 21 21 22 22 reg: true 23 23 24 + '#address-cells': 25 + const: 1 26 + 27 + '#size-cells': 28 + const: 0 29 + 24 30 vdd-supply: 25 31 description: 26 32 phandle to the regulator that provides power to the hub. ··· 35 29 $ref: /schemas/types.yaml#/definitions/phandle 36 30 description: 37 31 phandle to the peer hub on the controller. 32 + 33 + ports: 34 + $ref: /schemas/graph.yaml#/properties/ports 35 + 36 + properties: 37 + port@1: 38 + $ref: /schemas/graph.yaml#/properties/port 39 + description: 40 + 1st downstream facing USB port 41 + 42 + port@2: 43 + $ref: /schemas/graph.yaml#/properties/port 44 + description: 45 + 2nd downstream facing USB port 46 + 47 + port@3: 48 + $ref: /schemas/graph.yaml#/properties/port 49 + description: 50 + 3rd downstream facing USB port 51 + 52 + port@4: 53 + $ref: /schemas/graph.yaml#/properties/port 54 + description: 55 + 4th downstream facing USB port 56 + 57 + patternProperties: 58 + '^.*@[1-4]$': 59 + description: The hard wired USB devices 60 + type: object 61 + $ref: /schemas/usb/usb-device.yaml 38 62 39 63 required: 40 64 - peer-hub ··· 86 50 reg = <1>; 87 51 vdd-supply = <&pp3300_hub>; 88 52 peer-hub = <&hub_3_0>; 53 + #address-cells = <1>; 54 + #size-cells = <0>; 55 + /* USB 2.0 device on port 2 */ 56 + device@2 { 57 + compatible = "usb123,4567"; 58 + reg = <2>; 59 + }; 89 60 }; 90 61 91 62 /* 3.0 hub on port 2 */ ··· 101 58 reg = <2>; 102 59 vdd-supply = <&pp3300_hub>; 103 60 peer-hub = <&hub_2_0>; 61 + 62 + ports { 63 + #address-cells = <1>; 64 + #size-cells = <0>; 65 + /* Type-A connector on port 4 */ 66 + port@4 { 67 + reg = <4>; 68 + endpoint { 69 + remote-endpoint = <&usb_a0_ss>; 70 + }; 71 + }; 72 + }; 104 73 }; 105 74 };
+6 -2
Documentation/devicetree/bindings/usb/ti,am62-usb.yaml
··· 14 14 const: ti,am62-usb 15 15 16 16 reg: 17 - maxItems: 1 17 + minItems: 1 18 + items: 19 + - description: USB CFG register space 20 + - description: USB PHY2 register space 18 21 19 22 ranges: true 20 23 ··· 85 82 86 83 usbss1: usb@f910000 { 87 84 compatible = "ti,am62-usb"; 88 - reg = <0x00 0x0f910000 0x00 0x800>; 85 + reg = <0x00 0x0f910000 0x00 0x800>, 86 + <0x00 0x0f918000 0x00 0x400>; 89 87 clocks = <&k3_clks 162 3>; 90 88 clock-names = "ref"; 91 89 ti,syscon-phy-pll-refclk = <&wkup_conf 0x4018>;
+69
Documentation/devicetree/bindings/usb/ti,usb8020b.yaml
··· 1 + # SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/usb/ti,usb8020b.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: TI USB8020B USB 3.0 hub controller 8 + 9 + maintainers: 10 + - Macpaul Lin <macpaul.lin@mediatek.com> 11 + 12 + allOf: 13 + - $ref: usb-device.yaml# 14 + 15 + properties: 16 + compatible: 17 + enum: 18 + - usb451,8025 19 + - usb451,8027 20 + 21 + reg: true 22 + 23 + reset-gpios: 24 + items: 25 + - description: GPIO specifier for GRST# pin. 26 + 27 + vdd-supply: 28 + description: 29 + VDD power supply to the hub 30 + 31 + peer-hub: 32 + $ref: /schemas/types.yaml#/definitions/phandle 33 + description: 34 + phandle to the peer hub on the controller. 35 + 36 + required: 37 + - compatible 38 + - reg 39 + - peer-hub 40 + 41 + additionalProperties: false 42 + 43 + examples: 44 + - | 45 + #include <dt-bindings/gpio/gpio.h> 46 + 47 + usb { 48 + dr_mode = "host"; 49 + #address-cells = <1>; 50 + #size-cells = <0>; 51 + 52 + /* 2.0 hub on port 1 */ 53 + hub_2_0: hub@1 { 54 + compatible = "usb451,8027"; 55 + reg = <1>; 56 + peer-hub = <&hub_3_0>; 57 + reset-gpios = <&pio 7 GPIO_ACTIVE_HIGH>; 58 + vdd-supply = <&usb_hub_fixed_3v3>; 59 + }; 60 + 61 + /* 3.0 hub on port 2 */ 62 + hub_3_0: hub@2 { 63 + compatible = "usb451,8025"; 64 + reg = <2>; 65 + peer-hub = <&hub_2_0>; 66 + reset-gpios = <&pio 7 GPIO_ACTIVE_HIGH>; 67 + vdd-supply = <&usb_hub_fixed_3v3>; 68 + }; 69 + };
+6 -5
Documentation/devicetree/bindings/usb/usb-nop-xceiv.yaml
··· 37 37 description: Should specify the GPIO detecting a VBus insertion 38 38 maxItems: 1 39 39 40 - vbus-regulator: 41 - description: Should specify the regulator supplying current drawn from 42 - the VBus line. 43 - $ref: /schemas/types.yaml#/definitions/phandle 40 + vbus-supply: 41 + description: regulator supplying VBUS. It will be enabled and disabled 42 + dynamically in OTG mode. If the regulator is controlled by a 43 + GPIO line, this should be modeled as a regulator-fixed and 44 + referenced by this supply. 44 45 45 46 wakeup-source: 46 47 description: ··· 66 65 vcc-supply = <&hsusb1_vcc_regulator>; 67 66 reset-gpios = <&gpio1 7 GPIO_ACTIVE_LOW>; 68 67 vbus-detect-gpio = <&gpio2 13 GPIO_ACTIVE_HIGH>; 69 - vbus-regulator = <&vbus_regulator>; 68 + vbus-supply = <&vbus_regulator>; 70 69 #phy-cells = <0>; 71 70 }; 72 71
+67
Documentation/devicetree/bindings/usb/usb-switch.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/usb/usb-switch.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: USB Orientation and Mode Switches Common Properties 8 + 9 + maintainers: 10 + - Greg Kroah-Hartman <gregkh@linuxfoundation.org> 11 + 12 + description: 13 + Common properties for devices handling USB mode and orientation switching. 14 + 15 + properties: 16 + mode-switch: 17 + description: Possible handler of altmode switching 18 + type: boolean 19 + 20 + orientation-switch: 21 + description: Possible handler of orientation switching 22 + type: boolean 23 + 24 + retimer-switch: 25 + description: Possible handler of SuperSpeed signals retiming 26 + type: boolean 27 + 28 + port: 29 + $ref: /schemas/graph.yaml#/properties/port 30 + description: 31 + A port node to link the device to a TypeC controller for the purpose of 32 + handling altmode muxing and orientation switching. 33 + 34 + ports: 35 + $ref: /schemas/graph.yaml#/properties/ports 36 + properties: 37 + port@0: 38 + $ref: /schemas/graph.yaml#/properties/port 39 + description: 40 + Super Speed (SS) Output endpoint to the Type-C connector 41 + 42 + port@1: 43 + $ref: /schemas/graph.yaml#/$defs/port-base 44 + description: 45 + Super Speed (SS) Input endpoint from the Super-Speed PHY 46 + unevaluatedProperties: false 47 + 48 + properties: 49 + endpoint: 50 + $ref: /schemas/graph.yaml#/$defs/endpoint-base 51 + unevaluatedProperties: false 52 + properties: 53 + data-lanes: 54 + $ref: /schemas/types.yaml#/definitions/uint32-array 55 + minItems: 1 56 + maxItems: 8 57 + uniqueItems: true 58 + items: 59 + maximum: 8 60 + 61 + oneOf: 62 + - required: 63 + - port 64 + - required: 65 + - ports 66 + 67 + additionalProperties: true
+2
Documentation/devicetree/bindings/usb/usb.yaml
··· 25 25 26 26 usb-phy: 27 27 $ref: /schemas/types.yaml#/definitions/phandle-array 28 + items: 29 + maxItems: 1 28 30 description: 29 31 List of all the USB PHYs on this HCD to be accepted by the legacy USB 30 32 Physical Layer subsystem.
+4 -2
Documentation/driver-api/usb/callbacks.rst
··· 99 99 This callback is a signal to break any connection with an interface. 100 100 You are not allowed any IO to a device after returning from this 101 101 callback. You also may not do any other operation that may interfere 102 - with another driver bound the interface, eg. a power management 103 - operation. 102 + with another driver bound to the interface, eg. a power management 103 + operation. Outstanding operations on the device must be completed or 104 + aborted before this callback may return. 105 + 104 106 If you are called due to a physical disconnection, all your URBs will be 105 107 killed by usbcore. Note that in this case disconnect will be called some 106 108 time after the physical disconnection. Thus your driver must be prepared
+36
Documentation/usb/functionfs.rst
··· 2 2 How FunctionFS works 3 3 ==================== 4 4 5 + Overview 6 + ======== 7 + 5 8 From kernel point of view it is just a composite function with some 6 9 unique behaviour. It may be added to an USB configuration only after 7 10 the user space driver has registered by writing descriptors and ··· 69 66 70 67 Conversely, the gadget is unregistered after the first USB function 71 68 closes its endpoints. 69 + 70 + DMABUF interface 71 + ================ 72 + 73 + FunctionFS additionally supports a DMABUF based interface, where the 74 + userspace can attach DMABUF objects (externally created) to an endpoint, 75 + and subsequently use them for data transfers. 76 + 77 + A userspace application can then use this interface to share DMABUF 78 + objects between several interfaces, allowing it to transfer data in a 79 + zero-copy fashion, for instance between IIO and the USB stack. 80 + 81 + As part of this interface, three new IOCTLs have been added. These three 82 + IOCTLs have to be performed on a data endpoint (ie. not ep0). They are: 83 + 84 + ``FUNCTIONFS_DMABUF_ATTACH(int)`` 85 + Attach the DMABUF object, identified by its file descriptor, to the 86 + data endpoint. Returns zero on success, and a negative errno value 87 + on error. 88 + 89 + ``FUNCTIONFS_DMABUF_DETACH(int)`` 90 + Detach the given DMABUF object, identified by its file descriptor, 91 + from the data endpoint. Returns zero on success, and a negative 92 + errno value on error. Note that closing the endpoint's file 93 + descriptor will automatically detach all attached DMABUFs. 94 + 95 + ``FUNCTIONFS_DMABUF_TRANSFER(struct usb_ffs_dmabuf_transfer_req *)`` 96 + Enqueue the previously attached DMABUF to the transfer queue. 97 + The argument is a structure that packs the DMABUF's file descriptor, 98 + the size in bytes to transfer (which should generally correspond to 99 + the size of the DMABUF), and a 'flags' field which is unused 100 + for now. Returns zero on success, and a negative errno value on 101 + error.
+8
Documentation/usb/gadget-testing.rst
··· 206 206 process which implements the function proper). The gadget should be enabled 207 207 by writing a suitable string to usb_gadget/<gadget>/UDC. 208 208 209 + The FFS function provides just one attribute in its function directory: 210 + 211 + ready 212 + 213 + The attribute is read-only and signals if the function is ready (1) to be 214 + used, E.G. if userspace has written descriptors and strings to ep0, so 215 + the gadget can be enabled. 216 + 209 217 Testing the FFS function 210 218 ------------------------ 211 219
+46
arch/arm64/boot/dts/qcom/pm6150.dtsi
··· 63 63 }; 64 64 }; 65 65 66 + pm6150_vbus: usb-vbus-regulator@1100 { 67 + compatible = "qcom,pm6150-vbus-reg, 68 + qcom,pm8150b-vbus-reg"; 69 + reg = <0x1100>; 70 + status = "disabled"; 71 + }; 72 + 73 + pm6150_typec: typec@1500 { 74 + compatible = "qcom,pm6150-typec, 75 + qcom,pm8150b-typec"; 76 + reg = <0x1500>, <0x1700>; 77 + interrupts = <0x0 0x15 0x00 IRQ_TYPE_EDGE_RISING>, 78 + <0x0 0x15 0x01 IRQ_TYPE_EDGE_BOTH>, 79 + <0x0 0x15 0x02 IRQ_TYPE_EDGE_RISING>, 80 + <0x0 0x15 0x03 IRQ_TYPE_EDGE_BOTH>, 81 + <0x0 0x15 0x04 IRQ_TYPE_EDGE_RISING>, 82 + <0x0 0x15 0x05 IRQ_TYPE_EDGE_RISING>, 83 + <0x0 0x15 0x06 IRQ_TYPE_EDGE_BOTH>, 84 + <0x0 0x15 0x07 IRQ_TYPE_EDGE_RISING>, 85 + <0x0 0x17 0x00 IRQ_TYPE_EDGE_RISING>, 86 + <0x0 0x17 0x01 IRQ_TYPE_EDGE_RISING>, 87 + <0x0 0x17 0x02 IRQ_TYPE_EDGE_RISING>, 88 + <0x0 0x17 0x03 IRQ_TYPE_EDGE_RISING>, 89 + <0x0 0x17 0x04 IRQ_TYPE_EDGE_RISING>, 90 + <0x0 0x17 0x05 IRQ_TYPE_EDGE_RISING>, 91 + <0x0 0x17 0x06 IRQ_TYPE_EDGE_RISING>, 92 + <0x0 0x17 0x07 IRQ_TYPE_EDGE_RISING>; 93 + interrupt-names = "or-rid-detect-change", 94 + "vpd-detect", 95 + "cc-state-change", 96 + "vconn-oc", 97 + "vbus-change", 98 + "attach-detach", 99 + "legacy-cable-detect", 100 + "try-snk-src-detect", 101 + "sig-tx", 102 + "sig-rx", 103 + "msg-tx", 104 + "msg-rx", 105 + "msg-tx-failed", 106 + "msg-tx-discarded", 107 + "msg-rx-discarded", 108 + "fr-swap"; 109 + status = "disabled"; 110 + }; 111 + 66 112 pm6150_temp: temp-alarm@2400 { 67 113 compatible = "qcom,spmi-temp-alarm"; 68 114 reg = <0x2400>;
+3 -3
arch/powerpc/boot/dts/akebono.dts
··· 126 126 interrupts = <93 2>; 127 127 }; 128 128 129 - EHCI0: ehci@30010000000 { 129 + EHCI0: usb@30010000000 { 130 130 compatible = "ibm,476gtr-ehci", "generic-ehci"; 131 131 reg = <0x300 0x10000000 0x0 0x10000>; 132 132 interrupt-parent = <&MPIC>; ··· 140 140 interrupt-parent = <&MPIC>; 141 141 }; 142 142 143 - OHCI0: ohci@30010010000 { 143 + OHCI0: usb@30010010000 { 144 144 compatible = "ibm,476gtr-ohci", "generic-ohci"; 145 145 reg = <0x300 0x10010000 0x0 0x10000>; 146 146 interrupt-parent = <&MPIC>; 147 147 interrupts = <89 1>; 148 148 }; 149 149 150 - OHCI1: ohci@30010020000 { 150 + OHCI1: usb@30010020000 { 151 151 compatible = "ibm,476gtr-ohci", "generic-ohci"; 152 152 reg = <0x300 0x10020000 0x0 0x10000>; 153 153 interrupt-parent = <&MPIC>;
+1
drivers/phy/Kconfig
··· 87 87 source "drivers/phy/mscc/Kconfig" 88 88 source "drivers/phy/qualcomm/Kconfig" 89 89 source "drivers/phy/ralink/Kconfig" 90 + source "drivers/phy/realtek/Kconfig" 90 91 source "drivers/phy/renesas/Kconfig" 91 92 source "drivers/phy/rockchip/Kconfig" 92 93 source "drivers/phy/samsung/Kconfig"
+1
drivers/phy/Makefile
··· 26 26 mscc/ \ 27 27 qualcomm/ \ 28 28 ralink/ \ 29 + realtek/ \ 29 30 renesas/ \ 30 31 rockchip/ \ 31 32 samsung/ \
+47
drivers/phy/phy-core.c
··· 490 490 EXPORT_SYMBOL_GPL(phy_calibrate); 491 491 492 492 /** 493 + * phy_notify_connect() - phy connect notification 494 + * @phy: the phy returned by phy_get() 495 + * @port: the port index for connect 496 + * 497 + * If the phy needs to get connection status, the callback can be used. 498 + * Returns: %0 if successful, a negative error code otherwise 499 + */ 500 + int phy_notify_connect(struct phy *phy, int port) 501 + { 502 + int ret; 503 + 504 + if (!phy || !phy->ops->connect) 505 + return 0; 506 + 507 + mutex_lock(&phy->mutex); 508 + ret = phy->ops->connect(phy, port); 509 + mutex_unlock(&phy->mutex); 510 + 511 + return ret; 512 + } 513 + EXPORT_SYMBOL_GPL(phy_notify_connect); 514 + 515 + /** 516 + * phy_notify_disconnect() - phy disconnect notification 517 + * @phy: the phy returned by phy_get() 518 + * @port: the port index for disconnect 519 + * 520 + * If the phy needs to get connection status, the callback can be used. 521 + * 522 + * Returns: %0 if successful, a negative error code otherwise 523 + */ 524 + int phy_notify_disconnect(struct phy *phy, int port) 525 + { 526 + int ret; 527 + 528 + if (!phy || !phy->ops->disconnect) 529 + return 0; 530 + 531 + mutex_lock(&phy->mutex); 532 + ret = phy->ops->disconnect(phy, port); 533 + mutex_unlock(&phy->mutex); 534 + 535 + return ret; 536 + } 537 + EXPORT_SYMBOL_GPL(phy_notify_disconnect); 538 + 539 + /** 493 540 * phy_configure() - Changes the phy parameters 494 541 * @phy: the phy returned by phy_get() 495 542 * @opts: New configuration to apply
+32
drivers/phy/realtek/Kconfig
··· 1 + # SPDX-License-Identifier: GPL-2.0 2 + # 3 + # Phy drivers for Realtek platforms 4 + # 5 + 6 + if ARCH_REALTEK || COMPILE_TEST 7 + 8 + config PHY_RTK_RTD_USB2PHY 9 + tristate "Realtek RTD USB2 PHY Transceiver Driver" 10 + depends on USB_SUPPORT 11 + select GENERIC_PHY 12 + select USB_PHY 13 + select USB_COMMON 14 + help 15 + Enable this to support Realtek SoC USB2 phy transceiver. 16 + The DHC (digital home center) RTD series SoCs used the Synopsys 17 + DWC3 USB IP. This driver will do the PHY initialization 18 + of the parameters. 19 + 20 + config PHY_RTK_RTD_USB3PHY 21 + tristate "Realtek RTD USB3 PHY Transceiver Driver" 22 + depends on USB_SUPPORT 23 + select GENERIC_PHY 24 + select USB_PHY 25 + select USB_COMMON 26 + help 27 + Enable this to support Realtek SoC USB3 phy transceiver. 28 + The DHC (digital home center) RTD series SoCs used the Synopsys 29 + DWC3 USB IP. This driver will do the PHY initialization 30 + of the parameters. 31 + 32 + endif # ARCH_REALTEK || COMPILE_TEST
+3
drivers/phy/realtek/Makefile
··· 1 + # SPDX-License-Identifier: GPL-2.0 2 + obj-$(CONFIG_PHY_RTK_RTD_USB2PHY) += phy-rtk-usb2.o 3 + obj-$(CONFIG_PHY_RTK_RTD_USB3PHY) += phy-rtk-usb3.o
+1312
drivers/phy/realtek/phy-rtk-usb2.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * phy-rtk-usb2.c RTK usb2.0 PHY driver 4 + * 5 + * Copyright (C) 2023 Realtek Semiconductor Corporation 6 + * 7 + */ 8 + 9 + #include <linux/module.h> 10 + #include <linux/of.h> 11 + #include <linux/of_address.h> 12 + #include <linux/platform_device.h> 13 + #include <linux/uaccess.h> 14 + #include <linux/debugfs.h> 15 + #include <linux/nvmem-consumer.h> 16 + #include <linux/regmap.h> 17 + #include <linux/sys_soc.h> 18 + #include <linux/mfd/syscon.h> 19 + #include <linux/phy/phy.h> 20 + #include <linux/usb.h> 21 + 22 + /* GUSB2PHYACCn register */ 23 + #define PHY_NEW_REG_REQ BIT(25) 24 + #define PHY_VSTS_BUSY BIT(23) 25 + #define PHY_VCTRL_SHIFT 8 26 + #define PHY_REG_DATA_MASK 0xff 27 + 28 + #define GET_LOW_NIBBLE(addr) ((addr) & 0x0f) 29 + #define GET_HIGH_NIBBLE(addr) (((addr) & 0xf0) >> 4) 30 + 31 + #define EFUS_USB_DC_CAL_RATE 2 32 + #define EFUS_USB_DC_CAL_MAX 7 33 + 34 + #define EFUS_USB_DC_DIS_RATE 1 35 + #define EFUS_USB_DC_DIS_MAX 7 36 + 37 + #define MAX_PHY_DATA_SIZE 20 38 + #define OFFEST_PHY_READ 0x20 39 + 40 + #define MAX_USB_PHY_NUM 4 41 + #define MAX_USB_PHY_PAGE0_DATA_SIZE 16 42 + #define MAX_USB_PHY_PAGE1_DATA_SIZE 16 43 + #define MAX_USB_PHY_PAGE2_DATA_SIZE 8 44 + 45 + #define SET_PAGE_OFFSET 0xf4 46 + #define SET_PAGE_0 0x9b 47 + #define SET_PAGE_1 0xbb 48 + #define SET_PAGE_2 0xdb 49 + 50 + #define PAGE_START 0xe0 51 + #define PAGE0_0XE4 0xe4 52 + #define PAGE0_0XE6 0xe6 53 + #define PAGE0_0XE7 0xe7 54 + #define PAGE1_0XE0 0xe0 55 + #define PAGE1_0XE2 0xe2 56 + 57 + #define SENSITIVITY_CTRL (BIT(4) | BIT(5) | BIT(6)) 58 + #define ENABLE_AUTO_SENSITIVITY_CALIBRATION BIT(2) 59 + #define DEFAULT_DC_DRIVING_VALUE (0x8) 60 + #define DEFAULT_DC_DISCONNECTION_VALUE (0x6) 61 + #define HS_CLK_SELECT BIT(6) 62 + 63 + struct phy_reg { 64 + void __iomem *reg_wrap_vstatus; 65 + void __iomem *reg_gusb2phyacc0; 66 + int vstatus_index; 67 + }; 68 + 69 + struct phy_data { 70 + u8 addr; 71 + u8 data; 72 + }; 73 + 74 + struct phy_cfg { 75 + int page0_size; 76 + struct phy_data page0[MAX_USB_PHY_PAGE0_DATA_SIZE]; 77 + int page1_size; 78 + struct phy_data page1[MAX_USB_PHY_PAGE1_DATA_SIZE]; 79 + int page2_size; 80 + struct phy_data page2[MAX_USB_PHY_PAGE2_DATA_SIZE]; 81 + 82 + int num_phy; 83 + 84 + bool check_efuse; 85 + int check_efuse_version; 86 + #define CHECK_EFUSE_V1 1 87 + #define CHECK_EFUSE_V2 2 88 + int efuse_dc_driving_rate; 89 + int efuse_dc_disconnect_rate; 90 + int dc_driving_mask; 91 + int dc_disconnect_mask; 92 + bool usb_dc_disconnect_at_page0; 93 + int driving_updated_for_dev_dis; 94 + 95 + bool do_toggle; 96 + bool do_toggle_driving; 97 + bool use_default_parameter; 98 + bool is_double_sensitivity_mode; 99 + }; 100 + 101 + struct phy_parameter { 102 + struct phy_reg phy_reg; 103 + 104 + /* Get from efuse */ 105 + s8 efuse_usb_dc_cal; 106 + s8 efuse_usb_dc_dis; 107 + 108 + /* Get from dts */ 109 + bool inverse_hstx_sync_clock; 110 + u32 driving_level; 111 + s32 driving_level_compensate; 112 + s32 disconnection_compensate; 113 + }; 114 + 115 + struct rtk_phy { 116 + struct device *dev; 117 + 118 + struct phy_cfg *phy_cfg; 119 + int num_phy; 120 + struct phy_parameter *phy_parameter; 121 + 122 + struct dentry *debug_dir; 123 + }; 124 + 125 + /* mapping 0xE0 to 0 ... 0xE7 to 7, 0xF0 to 8 ,,, 0xF7 to 15 */ 126 + static inline int page_addr_to_array_index(u8 addr) 127 + { 128 + return (int)((((addr) - PAGE_START) & 0x7) + 129 + ((((addr) - PAGE_START) & 0x10) >> 1)); 130 + } 131 + 132 + static inline u8 array_index_to_page_addr(int index) 133 + { 134 + return ((((index) + PAGE_START) & 0x7) + 135 + ((((index) & 0x8) << 1) + PAGE_START)); 136 + } 137 + 138 + #define PHY_IO_TIMEOUT_USEC (50000) 139 + #define PHY_IO_DELAY_US (100) 140 + 141 + static inline int utmi_wait_register(void __iomem *reg, u32 mask, u32 result) 142 + { 143 + int ret; 144 + unsigned int val; 145 + 146 + ret = read_poll_timeout(readl, val, ((val & mask) == result), 147 + PHY_IO_DELAY_US, PHY_IO_TIMEOUT_USEC, false, reg); 148 + if (ret) { 149 + pr_err("%s can't program USB phy\n", __func__); 150 + return -ETIMEDOUT; 151 + } 152 + 153 + return 0; 154 + } 155 + 156 + static char rtk_phy_read(struct phy_reg *phy_reg, char addr) 157 + { 158 + void __iomem *reg_gusb2phyacc0 = phy_reg->reg_gusb2phyacc0; 159 + unsigned int val; 160 + int ret = 0; 161 + 162 + addr -= OFFEST_PHY_READ; 163 + 164 + /* polling until VBusy == 0 */ 165 + ret = utmi_wait_register(reg_gusb2phyacc0, PHY_VSTS_BUSY, 0); 166 + if (ret) 167 + return (char)ret; 168 + 169 + /* VCtrl = low nibble of addr, and set PHY_NEW_REG_REQ */ 170 + val = PHY_NEW_REG_REQ | (GET_LOW_NIBBLE(addr) << PHY_VCTRL_SHIFT); 171 + writel(val, reg_gusb2phyacc0); 172 + ret = utmi_wait_register(reg_gusb2phyacc0, PHY_VSTS_BUSY, 0); 173 + if (ret) 174 + return (char)ret; 175 + 176 + /* VCtrl = high nibble of addr, and set PHY_NEW_REG_REQ */ 177 + val = PHY_NEW_REG_REQ | (GET_HIGH_NIBBLE(addr) << PHY_VCTRL_SHIFT); 178 + writel(val, reg_gusb2phyacc0); 179 + ret = utmi_wait_register(reg_gusb2phyacc0, PHY_VSTS_BUSY, 0); 180 + if (ret) 181 + return (char)ret; 182 + 183 + val = readl(reg_gusb2phyacc0); 184 + 185 + return (char)(val & PHY_REG_DATA_MASK); 186 + } 187 + 188 + static int rtk_phy_write(struct phy_reg *phy_reg, char addr, char data) 189 + { 190 + unsigned int val; 191 + void __iomem *reg_wrap_vstatus = phy_reg->reg_wrap_vstatus; 192 + void __iomem *reg_gusb2phyacc0 = phy_reg->reg_gusb2phyacc0; 193 + int shift_bits = phy_reg->vstatus_index * 8; 194 + int ret = 0; 195 + 196 + /* write data to VStatusOut2 (data output to phy) */ 197 + writel((u32)data << shift_bits, reg_wrap_vstatus); 198 + 199 + ret = utmi_wait_register(reg_gusb2phyacc0, PHY_VSTS_BUSY, 0); 200 + if (ret) 201 + return ret; 202 + 203 + /* VCtrl = low nibble of addr, set PHY_NEW_REG_REQ */ 204 + val = PHY_NEW_REG_REQ | (GET_LOW_NIBBLE(addr) << PHY_VCTRL_SHIFT); 205 + 206 + writel(val, reg_gusb2phyacc0); 207 + ret = utmi_wait_register(reg_gusb2phyacc0, PHY_VSTS_BUSY, 0); 208 + if (ret) 209 + return ret; 210 + 211 + /* VCtrl = high nibble of addr, set PHY_NEW_REG_REQ */ 212 + val = PHY_NEW_REG_REQ | (GET_HIGH_NIBBLE(addr) << PHY_VCTRL_SHIFT); 213 + 214 + writel(val, reg_gusb2phyacc0); 215 + ret = utmi_wait_register(reg_gusb2phyacc0, PHY_VSTS_BUSY, 0); 216 + if (ret) 217 + return ret; 218 + 219 + return 0; 220 + } 221 + 222 + static int rtk_phy_set_page(struct phy_reg *phy_reg, int page) 223 + { 224 + switch (page) { 225 + case 0: 226 + return rtk_phy_write(phy_reg, SET_PAGE_OFFSET, SET_PAGE_0); 227 + case 1: 228 + return rtk_phy_write(phy_reg, SET_PAGE_OFFSET, SET_PAGE_1); 229 + case 2: 230 + return rtk_phy_write(phy_reg, SET_PAGE_OFFSET, SET_PAGE_2); 231 + default: 232 + pr_err("%s error page=%d\n", __func__, page); 233 + } 234 + 235 + return -EINVAL; 236 + } 237 + 238 + static u8 __updated_dc_disconnect_level_page0_0xe4(struct phy_cfg *phy_cfg, 239 + struct phy_parameter *phy_parameter, u8 data) 240 + { 241 + u8 ret; 242 + s32 val; 243 + s32 dc_disconnect_mask = phy_cfg->dc_disconnect_mask; 244 + int offset = 4; 245 + 246 + val = (s32)((data >> offset) & dc_disconnect_mask) 247 + + phy_parameter->efuse_usb_dc_dis 248 + + phy_parameter->disconnection_compensate; 249 + 250 + if (val > dc_disconnect_mask) 251 + val = dc_disconnect_mask; 252 + else if (val < 0) 253 + val = 0; 254 + 255 + ret = (data & (~(dc_disconnect_mask << offset))) | 256 + (val & dc_disconnect_mask) << offset; 257 + 258 + return ret; 259 + } 260 + 261 + /* updated disconnect level at page0 */ 262 + static void update_dc_disconnect_level_at_page0(struct rtk_phy *rtk_phy, 263 + struct phy_parameter *phy_parameter, bool update) 264 + { 265 + struct phy_cfg *phy_cfg; 266 + struct phy_reg *phy_reg; 267 + struct phy_data *phy_data_page; 268 + struct phy_data *phy_data; 269 + u8 addr, data; 270 + int offset = 4; 271 + s32 dc_disconnect_mask; 272 + int i; 273 + 274 + phy_cfg = rtk_phy->phy_cfg; 275 + phy_reg = &phy_parameter->phy_reg; 276 + 277 + /* Set page 0 */ 278 + phy_data_page = phy_cfg->page0; 279 + rtk_phy_set_page(phy_reg, 0); 280 + 281 + i = page_addr_to_array_index(PAGE0_0XE4); 282 + phy_data = phy_data_page + i; 283 + if (!phy_data->addr) { 284 + phy_data->addr = PAGE0_0XE4; 285 + phy_data->data = rtk_phy_read(phy_reg, PAGE0_0XE4); 286 + } 287 + 288 + addr = phy_data->addr; 289 + data = phy_data->data; 290 + dc_disconnect_mask = phy_cfg->dc_disconnect_mask; 291 + 292 + if (update) 293 + data = __updated_dc_disconnect_level_page0_0xe4(phy_cfg, phy_parameter, data); 294 + else 295 + data = (data & ~(dc_disconnect_mask << offset)) | 296 + (DEFAULT_DC_DISCONNECTION_VALUE << offset); 297 + 298 + if (rtk_phy_write(phy_reg, addr, data)) 299 + dev_err(rtk_phy->dev, 300 + "%s: Error to set page1 parameter addr=0x%x value=0x%x\n", 301 + __func__, addr, data); 302 + } 303 + 304 + static u8 __updated_dc_disconnect_level_page1_0xe2(struct phy_cfg *phy_cfg, 305 + struct phy_parameter *phy_parameter, u8 data) 306 + { 307 + u8 ret; 308 + s32 val; 309 + s32 dc_disconnect_mask = phy_cfg->dc_disconnect_mask; 310 + 311 + if (phy_cfg->check_efuse_version == CHECK_EFUSE_V1) { 312 + val = (s32)(data & dc_disconnect_mask) 313 + + phy_parameter->efuse_usb_dc_dis 314 + + phy_parameter->disconnection_compensate; 315 + } else { /* for CHECK_EFUSE_V2 or no efuse */ 316 + if (phy_parameter->efuse_usb_dc_dis) 317 + val = (s32)(phy_parameter->efuse_usb_dc_dis + 318 + phy_parameter->disconnection_compensate); 319 + else 320 + val = (s32)((data & dc_disconnect_mask) + 321 + phy_parameter->disconnection_compensate); 322 + } 323 + 324 + if (val > dc_disconnect_mask) 325 + val = dc_disconnect_mask; 326 + else if (val < 0) 327 + val = 0; 328 + 329 + ret = (data & (~dc_disconnect_mask)) | (val & dc_disconnect_mask); 330 + 331 + return ret; 332 + } 333 + 334 + /* updated disconnect level at page1 */ 335 + static void update_dc_disconnect_level_at_page1(struct rtk_phy *rtk_phy, 336 + struct phy_parameter *phy_parameter, bool update) 337 + { 338 + struct phy_cfg *phy_cfg; 339 + struct phy_data *phy_data_page; 340 + struct phy_data *phy_data; 341 + struct phy_reg *phy_reg; 342 + u8 addr, data; 343 + s32 dc_disconnect_mask; 344 + int i; 345 + 346 + phy_cfg = rtk_phy->phy_cfg; 347 + phy_reg = &phy_parameter->phy_reg; 348 + 349 + /* Set page 1 */ 350 + phy_data_page = phy_cfg->page1; 351 + rtk_phy_set_page(phy_reg, 1); 352 + 353 + i = page_addr_to_array_index(PAGE1_0XE2); 354 + phy_data = phy_data_page + i; 355 + if (!phy_data->addr) { 356 + phy_data->addr = PAGE1_0XE2; 357 + phy_data->data = rtk_phy_read(phy_reg, PAGE1_0XE2); 358 + } 359 + 360 + addr = phy_data->addr; 361 + data = phy_data->data; 362 + dc_disconnect_mask = phy_cfg->dc_disconnect_mask; 363 + 364 + if (update) 365 + data = __updated_dc_disconnect_level_page1_0xe2(phy_cfg, phy_parameter, data); 366 + else 367 + data = (data & ~dc_disconnect_mask) | DEFAULT_DC_DISCONNECTION_VALUE; 368 + 369 + if (rtk_phy_write(phy_reg, addr, data)) 370 + dev_err(rtk_phy->dev, 371 + "%s: Error to set page1 parameter addr=0x%x value=0x%x\n", 372 + __func__, addr, data); 373 + } 374 + 375 + static void update_dc_disconnect_level(struct rtk_phy *rtk_phy, 376 + struct phy_parameter *phy_parameter, bool update) 377 + { 378 + struct phy_cfg *phy_cfg = rtk_phy->phy_cfg; 379 + 380 + if (phy_cfg->usb_dc_disconnect_at_page0) 381 + update_dc_disconnect_level_at_page0(rtk_phy, phy_parameter, update); 382 + else 383 + update_dc_disconnect_level_at_page1(rtk_phy, phy_parameter, update); 384 + } 385 + 386 + static u8 __update_dc_driving_page0_0xe4(struct phy_cfg *phy_cfg, 387 + struct phy_parameter *phy_parameter, u8 data) 388 + { 389 + s32 driving_level_compensate = phy_parameter->driving_level_compensate; 390 + s32 dc_driving_mask = phy_cfg->dc_driving_mask; 391 + s32 val; 392 + u8 ret; 393 + 394 + if (phy_cfg->check_efuse_version == CHECK_EFUSE_V1) { 395 + val = (s32)(data & dc_driving_mask) + driving_level_compensate 396 + + phy_parameter->efuse_usb_dc_cal; 397 + } else { /* for CHECK_EFUSE_V2 or no efuse */ 398 + if (phy_parameter->efuse_usb_dc_cal) 399 + val = (s32)((phy_parameter->efuse_usb_dc_cal & dc_driving_mask) 400 + + driving_level_compensate); 401 + else 402 + val = (s32)(data & dc_driving_mask); 403 + } 404 + 405 + if (val > dc_driving_mask) 406 + val = dc_driving_mask; 407 + else if (val < 0) 408 + val = 0; 409 + 410 + ret = (data & (~dc_driving_mask)) | (val & dc_driving_mask); 411 + 412 + return ret; 413 + } 414 + 415 + static void update_dc_driving_level(struct rtk_phy *rtk_phy, 416 + struct phy_parameter *phy_parameter) 417 + { 418 + struct phy_cfg *phy_cfg; 419 + struct phy_reg *phy_reg; 420 + 421 + phy_reg = &phy_parameter->phy_reg; 422 + phy_cfg = rtk_phy->phy_cfg; 423 + if (!phy_cfg->page0[4].addr) { 424 + rtk_phy_set_page(phy_reg, 0); 425 + phy_cfg->page0[4].addr = PAGE0_0XE4; 426 + phy_cfg->page0[4].data = rtk_phy_read(phy_reg, PAGE0_0XE4); 427 + } 428 + 429 + if (phy_parameter->driving_level != DEFAULT_DC_DRIVING_VALUE) { 430 + u32 dc_driving_mask; 431 + u8 driving_level; 432 + u8 data; 433 + 434 + data = phy_cfg->page0[4].data; 435 + dc_driving_mask = phy_cfg->dc_driving_mask; 436 + driving_level = data & dc_driving_mask; 437 + 438 + dev_dbg(rtk_phy->dev, "%s driving_level=%d => dts driving_level=%d\n", 439 + __func__, driving_level, phy_parameter->driving_level); 440 + 441 + phy_cfg->page0[4].data = (data & (~dc_driving_mask)) | 442 + (phy_parameter->driving_level & dc_driving_mask); 443 + } 444 + 445 + phy_cfg->page0[4].data = __update_dc_driving_page0_0xe4(phy_cfg, 446 + phy_parameter, 447 + phy_cfg->page0[4].data); 448 + } 449 + 450 + static void update_hs_clk_select(struct rtk_phy *rtk_phy, 451 + struct phy_parameter *phy_parameter) 452 + { 453 + struct phy_cfg *phy_cfg; 454 + struct phy_reg *phy_reg; 455 + 456 + phy_cfg = rtk_phy->phy_cfg; 457 + phy_reg = &phy_parameter->phy_reg; 458 + 459 + if (phy_parameter->inverse_hstx_sync_clock) { 460 + if (!phy_cfg->page0[6].addr) { 461 + rtk_phy_set_page(phy_reg, 0); 462 + phy_cfg->page0[6].addr = PAGE0_0XE6; 463 + phy_cfg->page0[6].data = rtk_phy_read(phy_reg, PAGE0_0XE6); 464 + } 465 + 466 + phy_cfg->page0[6].data = phy_cfg->page0[6].data | HS_CLK_SELECT; 467 + } 468 + } 469 + 470 + static void do_rtk_phy_toggle(struct rtk_phy *rtk_phy, 471 + int index, bool connect) 472 + { 473 + struct phy_parameter *phy_parameter; 474 + struct phy_cfg *phy_cfg; 475 + struct phy_reg *phy_reg; 476 + struct phy_data *phy_data_page; 477 + u8 addr, data; 478 + int i; 479 + 480 + phy_cfg = rtk_phy->phy_cfg; 481 + phy_parameter = &((struct phy_parameter *)rtk_phy->phy_parameter)[index]; 482 + phy_reg = &phy_parameter->phy_reg; 483 + 484 + if (!phy_cfg->do_toggle) 485 + goto out; 486 + 487 + if (phy_cfg->is_double_sensitivity_mode) 488 + goto do_toggle_driving; 489 + 490 + /* Set page 0 */ 491 + rtk_phy_set_page(phy_reg, 0); 492 + 493 + addr = PAGE0_0XE7; 494 + data = rtk_phy_read(phy_reg, addr); 495 + 496 + if (connect) 497 + rtk_phy_write(phy_reg, addr, data & (~SENSITIVITY_CTRL)); 498 + else 499 + rtk_phy_write(phy_reg, addr, data | (SENSITIVITY_CTRL)); 500 + 501 + do_toggle_driving: 502 + 503 + if (!phy_cfg->do_toggle_driving) 504 + goto do_toggle; 505 + 506 + /* Page 0 addr 0xE4 driving capability */ 507 + 508 + /* Set page 0 */ 509 + phy_data_page = phy_cfg->page0; 510 + rtk_phy_set_page(phy_reg, 0); 511 + 512 + i = page_addr_to_array_index(PAGE0_0XE4); 513 + addr = phy_data_page[i].addr; 514 + data = phy_data_page[i].data; 515 + 516 + if (connect) { 517 + rtk_phy_write(phy_reg, addr, data); 518 + } else { 519 + u8 value; 520 + s32 tmp; 521 + s32 driving_updated = 522 + phy_cfg->driving_updated_for_dev_dis; 523 + s32 dc_driving_mask = phy_cfg->dc_driving_mask; 524 + 525 + tmp = (s32)(data & dc_driving_mask) + driving_updated; 526 + 527 + if (tmp > dc_driving_mask) 528 + tmp = dc_driving_mask; 529 + else if (tmp < 0) 530 + tmp = 0; 531 + 532 + value = (data & (~dc_driving_mask)) | (tmp & dc_driving_mask); 533 + 534 + rtk_phy_write(phy_reg, addr, value); 535 + } 536 + 537 + do_toggle: 538 + /* restore dc disconnect level before toggle */ 539 + update_dc_disconnect_level(rtk_phy, phy_parameter, false); 540 + 541 + /* Set page 1 */ 542 + rtk_phy_set_page(phy_reg, 1); 543 + 544 + addr = PAGE1_0XE0; 545 + data = rtk_phy_read(phy_reg, addr); 546 + 547 + rtk_phy_write(phy_reg, addr, data & 548 + (~ENABLE_AUTO_SENSITIVITY_CALIBRATION)); 549 + mdelay(1); 550 + rtk_phy_write(phy_reg, addr, data | 551 + (ENABLE_AUTO_SENSITIVITY_CALIBRATION)); 552 + 553 + /* update dc disconnect level after toggle */ 554 + update_dc_disconnect_level(rtk_phy, phy_parameter, true); 555 + 556 + out: 557 + return; 558 + } 559 + 560 + static int do_rtk_phy_init(struct rtk_phy *rtk_phy, int index) 561 + { 562 + struct phy_parameter *phy_parameter; 563 + struct phy_cfg *phy_cfg; 564 + struct phy_data *phy_data_page; 565 + struct phy_reg *phy_reg; 566 + int i; 567 + 568 + phy_cfg = rtk_phy->phy_cfg; 569 + phy_parameter = &((struct phy_parameter *)rtk_phy->phy_parameter)[index]; 570 + phy_reg = &phy_parameter->phy_reg; 571 + 572 + if (phy_cfg->use_default_parameter) { 573 + dev_dbg(rtk_phy->dev, "%s phy#%d use default parameter\n", 574 + __func__, index); 575 + goto do_toggle; 576 + } 577 + 578 + /* Set page 0 */ 579 + phy_data_page = phy_cfg->page0; 580 + rtk_phy_set_page(phy_reg, 0); 581 + 582 + for (i = 0; i < phy_cfg->page0_size; i++) { 583 + struct phy_data *phy_data = phy_data_page + i; 584 + u8 addr = phy_data->addr; 585 + u8 data = phy_data->data; 586 + 587 + if (!addr) 588 + continue; 589 + 590 + if (rtk_phy_write(phy_reg, addr, data)) { 591 + dev_err(rtk_phy->dev, 592 + "%s: Error to set page0 parameter addr=0x%x value=0x%x\n", 593 + __func__, addr, data); 594 + return -EINVAL; 595 + } 596 + } 597 + 598 + /* Set page 1 */ 599 + phy_data_page = phy_cfg->page1; 600 + rtk_phy_set_page(phy_reg, 1); 601 + 602 + for (i = 0; i < phy_cfg->page1_size; i++) { 603 + struct phy_data *phy_data = phy_data_page + i; 604 + u8 addr = phy_data->addr; 605 + u8 data = phy_data->data; 606 + 607 + if (!addr) 608 + continue; 609 + 610 + if (rtk_phy_write(phy_reg, addr, data)) { 611 + dev_err(rtk_phy->dev, 612 + "%s: Error to set page1 parameter addr=0x%x value=0x%x\n", 613 + __func__, addr, data); 614 + return -EINVAL; 615 + } 616 + } 617 + 618 + if (phy_cfg->page2_size == 0) 619 + goto do_toggle; 620 + 621 + /* Set page 2 */ 622 + phy_data_page = phy_cfg->page2; 623 + rtk_phy_set_page(phy_reg, 2); 624 + 625 + for (i = 0; i < phy_cfg->page2_size; i++) { 626 + struct phy_data *phy_data = phy_data_page + i; 627 + u8 addr = phy_data->addr; 628 + u8 data = phy_data->data; 629 + 630 + if (!addr) 631 + continue; 632 + 633 + if (rtk_phy_write(phy_reg, addr, data)) { 634 + dev_err(rtk_phy->dev, 635 + "%s: Error to set page2 parameter addr=0x%x value=0x%x\n", 636 + __func__, addr, data); 637 + return -EINVAL; 638 + } 639 + } 640 + 641 + do_toggle: 642 + do_rtk_phy_toggle(rtk_phy, index, false); 643 + 644 + return 0; 645 + } 646 + 647 + static int rtk_phy_init(struct phy *phy) 648 + { 649 + struct rtk_phy *rtk_phy = phy_get_drvdata(phy); 650 + unsigned long phy_init_time = jiffies; 651 + int i, ret = 0; 652 + 653 + if (!rtk_phy) 654 + return -EINVAL; 655 + 656 + for (i = 0; i < rtk_phy->num_phy; i++) 657 + ret = do_rtk_phy_init(rtk_phy, i); 658 + 659 + dev_dbg(rtk_phy->dev, "Initialized RTK USB 2.0 PHY (take %dms)\n", 660 + jiffies_to_msecs(jiffies - phy_init_time)); 661 + return ret; 662 + } 663 + 664 + static int rtk_phy_exit(struct phy *phy) 665 + { 666 + return 0; 667 + } 668 + 669 + static void rtk_phy_toggle(struct rtk_phy *rtk_phy, bool connect, int port) 670 + { 671 + int index = port; 672 + 673 + if (index > rtk_phy->num_phy) { 674 + dev_err(rtk_phy->dev, "%s: The port=%d is not in usb phy (num_phy=%d)\n", 675 + __func__, index, rtk_phy->num_phy); 676 + return; 677 + } 678 + 679 + do_rtk_phy_toggle(rtk_phy, index, connect); 680 + } 681 + 682 + static int rtk_phy_connect(struct phy *phy, int port) 683 + { 684 + struct rtk_phy *rtk_phy = phy_get_drvdata(phy); 685 + 686 + dev_dbg(rtk_phy->dev, "%s port=%d\n", __func__, port); 687 + rtk_phy_toggle(rtk_phy, true, port); 688 + 689 + return 0; 690 + } 691 + 692 + static int rtk_phy_disconnect(struct phy *phy, int port) 693 + { 694 + struct rtk_phy *rtk_phy = phy_get_drvdata(phy); 695 + 696 + dev_dbg(rtk_phy->dev, "%s port=%d\n", __func__, port); 697 + rtk_phy_toggle(rtk_phy, false, port); 698 + 699 + return 0; 700 + } 701 + 702 + static const struct phy_ops ops = { 703 + .init = rtk_phy_init, 704 + .exit = rtk_phy_exit, 705 + .connect = rtk_phy_connect, 706 + .disconnect = rtk_phy_disconnect, 707 + .owner = THIS_MODULE, 708 + }; 709 + 710 + #ifdef CONFIG_DEBUG_FS 711 + static struct dentry *create_phy_debug_root(void) 712 + { 713 + struct dentry *phy_debug_root; 714 + 715 + phy_debug_root = debugfs_lookup("phy", usb_debug_root); 716 + if (!phy_debug_root) 717 + phy_debug_root = debugfs_create_dir("phy", usb_debug_root); 718 + 719 + return phy_debug_root; 720 + } 721 + 722 + static int rtk_usb2_parameter_show(struct seq_file *s, void *unused) 723 + { 724 + struct rtk_phy *rtk_phy = s->private; 725 + struct phy_cfg *phy_cfg; 726 + int i, index; 727 + 728 + phy_cfg = rtk_phy->phy_cfg; 729 + 730 + seq_puts(s, "Property:\n"); 731 + seq_printf(s, " check_efuse: %s\n", 732 + phy_cfg->check_efuse ? "Enable" : "Disable"); 733 + seq_printf(s, " check_efuse_version: %d\n", 734 + phy_cfg->check_efuse_version); 735 + seq_printf(s, " efuse_dc_driving_rate: %d\n", 736 + phy_cfg->efuse_dc_driving_rate); 737 + seq_printf(s, " dc_driving_mask: 0x%x\n", 738 + phy_cfg->dc_driving_mask); 739 + seq_printf(s, " efuse_dc_disconnect_rate: %d\n", 740 + phy_cfg->efuse_dc_disconnect_rate); 741 + seq_printf(s, " dc_disconnect_mask: 0x%x\n", 742 + phy_cfg->dc_disconnect_mask); 743 + seq_printf(s, " usb_dc_disconnect_at_page0: %s\n", 744 + phy_cfg->usb_dc_disconnect_at_page0 ? "true" : "false"); 745 + seq_printf(s, " do_toggle: %s\n", 746 + phy_cfg->do_toggle ? "Enable" : "Disable"); 747 + seq_printf(s, " do_toggle_driving: %s\n", 748 + phy_cfg->do_toggle_driving ? "Enable" : "Disable"); 749 + seq_printf(s, " driving_updated_for_dev_dis: 0x%x\n", 750 + phy_cfg->driving_updated_for_dev_dis); 751 + seq_printf(s, " use_default_parameter: %s\n", 752 + phy_cfg->use_default_parameter ? "Enable" : "Disable"); 753 + seq_printf(s, " is_double_sensitivity_mode: %s\n", 754 + phy_cfg->is_double_sensitivity_mode ? "Enable" : "Disable"); 755 + 756 + for (index = 0; index < rtk_phy->num_phy; index++) { 757 + struct phy_parameter *phy_parameter; 758 + struct phy_reg *phy_reg; 759 + struct phy_data *phy_data_page; 760 + 761 + phy_parameter = &((struct phy_parameter *)rtk_phy->phy_parameter)[index]; 762 + phy_reg = &phy_parameter->phy_reg; 763 + 764 + seq_printf(s, "PHY %d:\n", index); 765 + 766 + seq_puts(s, "Page 0:\n"); 767 + /* Set page 0 */ 768 + phy_data_page = phy_cfg->page0; 769 + rtk_phy_set_page(phy_reg, 0); 770 + 771 + for (i = 0; i < phy_cfg->page0_size; i++) { 772 + struct phy_data *phy_data = phy_data_page + i; 773 + u8 addr = array_index_to_page_addr(i); 774 + u8 data = phy_data->data; 775 + u8 value = rtk_phy_read(phy_reg, addr); 776 + 777 + if (phy_data->addr) 778 + seq_printf(s, " Page 0: addr=0x%x data=0x%02x ==> read value=0x%02x\n", 779 + addr, data, value); 780 + else 781 + seq_printf(s, " Page 0: addr=0x%x data=none ==> read value=0x%02x\n", 782 + addr, value); 783 + } 784 + 785 + seq_puts(s, "Page 1:\n"); 786 + /* Set page 1 */ 787 + phy_data_page = phy_cfg->page1; 788 + rtk_phy_set_page(phy_reg, 1); 789 + 790 + for (i = 0; i < phy_cfg->page1_size; i++) { 791 + struct phy_data *phy_data = phy_data_page + i; 792 + u8 addr = array_index_to_page_addr(i); 793 + u8 data = phy_data->data; 794 + u8 value = rtk_phy_read(phy_reg, addr); 795 + 796 + if (phy_data->addr) 797 + seq_printf(s, " Page 1: addr=0x%x data=0x%02x ==> read value=0x%02x\n", 798 + addr, data, value); 799 + else 800 + seq_printf(s, " Page 1: addr=0x%x data=none ==> read value=0x%02x\n", 801 + addr, value); 802 + } 803 + 804 + if (phy_cfg->page2_size == 0) 805 + goto out; 806 + 807 + seq_puts(s, "Page 2:\n"); 808 + /* Set page 2 */ 809 + phy_data_page = phy_cfg->page2; 810 + rtk_phy_set_page(phy_reg, 2); 811 + 812 + for (i = 0; i < phy_cfg->page2_size; i++) { 813 + struct phy_data *phy_data = phy_data_page + i; 814 + u8 addr = array_index_to_page_addr(i); 815 + u8 data = phy_data->data; 816 + u8 value = rtk_phy_read(phy_reg, addr); 817 + 818 + if (phy_data->addr) 819 + seq_printf(s, " Page 2: addr=0x%x data=0x%02x ==> read value=0x%02x\n", 820 + addr, data, value); 821 + else 822 + seq_printf(s, " Page 2: addr=0x%x data=none ==> read value=0x%02x\n", 823 + addr, value); 824 + } 825 + 826 + out: 827 + seq_puts(s, "PHY Property:\n"); 828 + seq_printf(s, " efuse_usb_dc_cal: %d\n", 829 + (int)phy_parameter->efuse_usb_dc_cal); 830 + seq_printf(s, " efuse_usb_dc_dis: %d\n", 831 + (int)phy_parameter->efuse_usb_dc_dis); 832 + seq_printf(s, " inverse_hstx_sync_clock: %s\n", 833 + phy_parameter->inverse_hstx_sync_clock ? "Enable" : "Disable"); 834 + seq_printf(s, " driving_level: %d\n", 835 + phy_parameter->driving_level); 836 + seq_printf(s, " driving_level_compensate: %d\n", 837 + phy_parameter->driving_level_compensate); 838 + seq_printf(s, " disconnection_compensate: %d\n", 839 + phy_parameter->disconnection_compensate); 840 + } 841 + 842 + return 0; 843 + } 844 + DEFINE_SHOW_ATTRIBUTE(rtk_usb2_parameter); 845 + 846 + static inline void create_debug_files(struct rtk_phy *rtk_phy) 847 + { 848 + struct dentry *phy_debug_root = NULL; 849 + 850 + phy_debug_root = create_phy_debug_root(); 851 + if (!phy_debug_root) 852 + return; 853 + 854 + rtk_phy->debug_dir = debugfs_create_dir(dev_name(rtk_phy->dev), 855 + phy_debug_root); 856 + 857 + debugfs_create_file("parameter", 0444, rtk_phy->debug_dir, rtk_phy, 858 + &rtk_usb2_parameter_fops); 859 + } 860 + 861 + static inline void remove_debug_files(struct rtk_phy *rtk_phy) 862 + { 863 + debugfs_remove_recursive(rtk_phy->debug_dir); 864 + } 865 + #else 866 + static inline void create_debug_files(struct rtk_phy *rtk_phy) { } 867 + static inline void remove_debug_files(struct rtk_phy *rtk_phy) { } 868 + #endif /* CONFIG_DEBUG_FS */ 869 + 870 + static int get_phy_data_by_efuse(struct rtk_phy *rtk_phy, 871 + struct phy_parameter *phy_parameter, int index) 872 + { 873 + struct phy_cfg *phy_cfg = rtk_phy->phy_cfg; 874 + u8 value = 0; 875 + struct nvmem_cell *cell; 876 + struct soc_device_attribute rtk_soc_groot[] = { 877 + { .family = "Realtek Groot",}, 878 + { /* empty */ } }; 879 + 880 + if (!phy_cfg->check_efuse) 881 + goto out; 882 + 883 + /* Read efuse for usb dc cal */ 884 + cell = nvmem_cell_get(rtk_phy->dev, "usb-dc-cal"); 885 + if (IS_ERR(cell)) { 886 + dev_dbg(rtk_phy->dev, "%s no usb-dc-cal: %ld\n", 887 + __func__, PTR_ERR(cell)); 888 + } else { 889 + unsigned char *buf; 890 + size_t buf_size; 891 + 892 + buf = nvmem_cell_read(cell, &buf_size); 893 + if (!IS_ERR(buf)) { 894 + value = buf[0] & phy_cfg->dc_driving_mask; 895 + kfree(buf); 896 + } 897 + nvmem_cell_put(cell); 898 + } 899 + 900 + if (phy_cfg->check_efuse_version == CHECK_EFUSE_V1) { 901 + int rate = phy_cfg->efuse_dc_driving_rate; 902 + 903 + if (value <= EFUS_USB_DC_CAL_MAX) 904 + phy_parameter->efuse_usb_dc_cal = (int8_t)(value * rate); 905 + else 906 + phy_parameter->efuse_usb_dc_cal = -(int8_t) 907 + ((EFUS_USB_DC_CAL_MAX & value) * rate); 908 + 909 + if (soc_device_match(rtk_soc_groot)) { 910 + dev_dbg(rtk_phy->dev, "For groot IC we need a workaround to adjust efuse_usb_dc_cal\n"); 911 + 912 + /* We don't multiple dc_cal_rate=2 for positive dc cal compensate */ 913 + if (value <= EFUS_USB_DC_CAL_MAX) 914 + phy_parameter->efuse_usb_dc_cal = (int8_t)(value); 915 + 916 + /* We set max dc cal compensate is 0x8 if otp is 0x7 */ 917 + if (value == 0x7) 918 + phy_parameter->efuse_usb_dc_cal = (int8_t)(value + 1); 919 + } 920 + } else { /* for CHECK_EFUSE_V2 */ 921 + phy_parameter->efuse_usb_dc_cal = value & phy_cfg->dc_driving_mask; 922 + } 923 + 924 + /* Read efuse for usb dc disconnect level */ 925 + value = 0; 926 + cell = nvmem_cell_get(rtk_phy->dev, "usb-dc-dis"); 927 + if (IS_ERR(cell)) { 928 + dev_dbg(rtk_phy->dev, "%s no usb-dc-dis: %ld\n", 929 + __func__, PTR_ERR(cell)); 930 + } else { 931 + unsigned char *buf; 932 + size_t buf_size; 933 + 934 + buf = nvmem_cell_read(cell, &buf_size); 935 + if (!IS_ERR(buf)) { 936 + value = buf[0] & phy_cfg->dc_disconnect_mask; 937 + kfree(buf); 938 + } 939 + nvmem_cell_put(cell); 940 + } 941 + 942 + if (phy_cfg->check_efuse_version == CHECK_EFUSE_V1) { 943 + int rate = phy_cfg->efuse_dc_disconnect_rate; 944 + 945 + if (value <= EFUS_USB_DC_DIS_MAX) 946 + phy_parameter->efuse_usb_dc_dis = (int8_t)(value * rate); 947 + else 948 + phy_parameter->efuse_usb_dc_dis = -(int8_t) 949 + ((EFUS_USB_DC_DIS_MAX & value) * rate); 950 + } else { /* for CHECK_EFUSE_V2 */ 951 + phy_parameter->efuse_usb_dc_dis = value & phy_cfg->dc_disconnect_mask; 952 + } 953 + 954 + out: 955 + return 0; 956 + } 957 + 958 + static int parse_phy_data(struct rtk_phy *rtk_phy) 959 + { 960 + struct device *dev = rtk_phy->dev; 961 + struct device_node *np = dev->of_node; 962 + struct phy_parameter *phy_parameter; 963 + int ret = 0; 964 + int index; 965 + 966 + rtk_phy->phy_parameter = devm_kzalloc(dev, sizeof(struct phy_parameter) * 967 + rtk_phy->num_phy, GFP_KERNEL); 968 + if (!rtk_phy->phy_parameter) 969 + return -ENOMEM; 970 + 971 + for (index = 0; index < rtk_phy->num_phy; index++) { 972 + phy_parameter = &((struct phy_parameter *)rtk_phy->phy_parameter)[index]; 973 + 974 + phy_parameter->phy_reg.reg_wrap_vstatus = of_iomap(np, 0); 975 + phy_parameter->phy_reg.reg_gusb2phyacc0 = of_iomap(np, 1) + index; 976 + phy_parameter->phy_reg.vstatus_index = index; 977 + 978 + if (of_property_read_bool(np, "realtek,inverse-hstx-sync-clock")) 979 + phy_parameter->inverse_hstx_sync_clock = true; 980 + else 981 + phy_parameter->inverse_hstx_sync_clock = false; 982 + 983 + if (of_property_read_u32_index(np, "realtek,driving-level", 984 + index, &phy_parameter->driving_level)) 985 + phy_parameter->driving_level = DEFAULT_DC_DRIVING_VALUE; 986 + 987 + if (of_property_read_u32_index(np, "realtek,driving-level-compensate", 988 + index, &phy_parameter->driving_level_compensate)) 989 + phy_parameter->driving_level_compensate = 0; 990 + 991 + if (of_property_read_u32_index(np, "realtek,disconnection-compensate", 992 + index, &phy_parameter->disconnection_compensate)) 993 + phy_parameter->disconnection_compensate = 0; 994 + 995 + get_phy_data_by_efuse(rtk_phy, phy_parameter, index); 996 + 997 + update_dc_driving_level(rtk_phy, phy_parameter); 998 + 999 + update_hs_clk_select(rtk_phy, phy_parameter); 1000 + } 1001 + 1002 + return ret; 1003 + } 1004 + 1005 + static int rtk_usb2phy_probe(struct platform_device *pdev) 1006 + { 1007 + struct rtk_phy *rtk_phy; 1008 + struct device *dev = &pdev->dev; 1009 + struct phy *generic_phy; 1010 + struct phy_provider *phy_provider; 1011 + const struct phy_cfg *phy_cfg; 1012 + int ret = 0; 1013 + 1014 + phy_cfg = of_device_get_match_data(dev); 1015 + if (!phy_cfg) { 1016 + dev_err(dev, "phy config are not assigned!\n"); 1017 + return -EINVAL; 1018 + } 1019 + 1020 + rtk_phy = devm_kzalloc(dev, sizeof(*rtk_phy), GFP_KERNEL); 1021 + if (!rtk_phy) 1022 + return -ENOMEM; 1023 + 1024 + rtk_phy->dev = &pdev->dev; 1025 + rtk_phy->phy_cfg = devm_kzalloc(dev, sizeof(*phy_cfg), GFP_KERNEL); 1026 + 1027 + memcpy(rtk_phy->phy_cfg, phy_cfg, sizeof(*phy_cfg)); 1028 + 1029 + rtk_phy->num_phy = phy_cfg->num_phy; 1030 + 1031 + ret = parse_phy_data(rtk_phy); 1032 + if (ret) 1033 + goto err; 1034 + 1035 + platform_set_drvdata(pdev, rtk_phy); 1036 + 1037 + generic_phy = devm_phy_create(rtk_phy->dev, NULL, &ops); 1038 + if (IS_ERR(generic_phy)) 1039 + return PTR_ERR(generic_phy); 1040 + 1041 + phy_set_drvdata(generic_phy, rtk_phy); 1042 + 1043 + phy_provider = devm_of_phy_provider_register(rtk_phy->dev, 1044 + of_phy_simple_xlate); 1045 + if (IS_ERR(phy_provider)) 1046 + return PTR_ERR(phy_provider); 1047 + 1048 + create_debug_files(rtk_phy); 1049 + 1050 + err: 1051 + return ret; 1052 + } 1053 + 1054 + static void rtk_usb2phy_remove(struct platform_device *pdev) 1055 + { 1056 + struct rtk_phy *rtk_phy = platform_get_drvdata(pdev); 1057 + 1058 + remove_debug_files(rtk_phy); 1059 + } 1060 + 1061 + static const struct phy_cfg rtd1295_phy_cfg = { 1062 + .page0_size = MAX_USB_PHY_PAGE0_DATA_SIZE, 1063 + .page0 = { [0] = {0xe0, 0x90}, 1064 + [3] = {0xe3, 0x3a}, 1065 + [4] = {0xe4, 0x68}, 1066 + [6] = {0xe6, 0x91}, 1067 + [13] = {0xf5, 0x81}, 1068 + [15] = {0xf7, 0x02}, }, 1069 + .page1_size = 8, 1070 + .page1 = { /* default parameter */ }, 1071 + .page2_size = 0, 1072 + .page2 = { /* no parameter */ }, 1073 + .num_phy = 1, 1074 + .check_efuse = false, 1075 + .check_efuse_version = CHECK_EFUSE_V1, 1076 + .efuse_dc_driving_rate = 1, 1077 + .dc_driving_mask = 0xf, 1078 + .efuse_dc_disconnect_rate = EFUS_USB_DC_DIS_RATE, 1079 + .dc_disconnect_mask = 0xf, 1080 + .usb_dc_disconnect_at_page0 = true, 1081 + .do_toggle = true, 1082 + .do_toggle_driving = false, 1083 + .driving_updated_for_dev_dis = 0xf, 1084 + .use_default_parameter = false, 1085 + .is_double_sensitivity_mode = false, 1086 + }; 1087 + 1088 + static const struct phy_cfg rtd1395_phy_cfg = { 1089 + .page0_size = MAX_USB_PHY_PAGE0_DATA_SIZE, 1090 + .page0 = { [4] = {0xe4, 0xac}, 1091 + [13] = {0xf5, 0x00}, 1092 + [15] = {0xf7, 0x02}, }, 1093 + .page1_size = 8, 1094 + .page1 = { /* default parameter */ }, 1095 + .page2_size = 0, 1096 + .page2 = { /* no parameter */ }, 1097 + .num_phy = 1, 1098 + .check_efuse = false, 1099 + .check_efuse_version = CHECK_EFUSE_V1, 1100 + .efuse_dc_driving_rate = 1, 1101 + .dc_driving_mask = 0xf, 1102 + .efuse_dc_disconnect_rate = EFUS_USB_DC_DIS_RATE, 1103 + .dc_disconnect_mask = 0xf, 1104 + .usb_dc_disconnect_at_page0 = true, 1105 + .do_toggle = true, 1106 + .do_toggle_driving = false, 1107 + .driving_updated_for_dev_dis = 0xf, 1108 + .use_default_parameter = false, 1109 + .is_double_sensitivity_mode = false, 1110 + }; 1111 + 1112 + static const struct phy_cfg rtd1395_phy_cfg_2port = { 1113 + .page0_size = MAX_USB_PHY_PAGE0_DATA_SIZE, 1114 + .page0 = { [4] = {0xe4, 0xac}, 1115 + [13] = {0xf5, 0x00}, 1116 + [15] = {0xf7, 0x02}, }, 1117 + .page1_size = 8, 1118 + .page1 = { /* default parameter */ }, 1119 + .page2_size = 0, 1120 + .page2 = { /* no parameter */ }, 1121 + .num_phy = 2, 1122 + .check_efuse = false, 1123 + .check_efuse_version = CHECK_EFUSE_V1, 1124 + .efuse_dc_driving_rate = 1, 1125 + .dc_driving_mask = 0xf, 1126 + .efuse_dc_disconnect_rate = EFUS_USB_DC_DIS_RATE, 1127 + .dc_disconnect_mask = 0xf, 1128 + .usb_dc_disconnect_at_page0 = true, 1129 + .do_toggle = true, 1130 + .do_toggle_driving = false, 1131 + .driving_updated_for_dev_dis = 0xf, 1132 + .use_default_parameter = false, 1133 + .is_double_sensitivity_mode = false, 1134 + }; 1135 + 1136 + static const struct phy_cfg rtd1619_phy_cfg = { 1137 + .page0_size = MAX_USB_PHY_PAGE0_DATA_SIZE, 1138 + .page0 = { [4] = {0xe4, 0x68}, }, 1139 + .page1_size = 8, 1140 + .page1 = { /* default parameter */ }, 1141 + .page2_size = 0, 1142 + .page2 = { /* no parameter */ }, 1143 + .num_phy = 1, 1144 + .check_efuse = true, 1145 + .check_efuse_version = CHECK_EFUSE_V1, 1146 + .efuse_dc_driving_rate = 1, 1147 + .dc_driving_mask = 0xf, 1148 + .efuse_dc_disconnect_rate = EFUS_USB_DC_DIS_RATE, 1149 + .dc_disconnect_mask = 0xf, 1150 + .usb_dc_disconnect_at_page0 = true, 1151 + .do_toggle = true, 1152 + .do_toggle_driving = false, 1153 + .driving_updated_for_dev_dis = 0xf, 1154 + .use_default_parameter = false, 1155 + .is_double_sensitivity_mode = false, 1156 + }; 1157 + 1158 + static const struct phy_cfg rtd1319_phy_cfg = { 1159 + .page0_size = MAX_USB_PHY_PAGE0_DATA_SIZE, 1160 + .page0 = { [0] = {0xe0, 0x18}, 1161 + [4] = {0xe4, 0x6a}, 1162 + [7] = {0xe7, 0x71}, 1163 + [13] = {0xf5, 0x15}, 1164 + [15] = {0xf7, 0x32}, }, 1165 + .page1_size = 8, 1166 + .page1 = { [3] = {0xe3, 0x44}, }, 1167 + .page2_size = MAX_USB_PHY_PAGE2_DATA_SIZE, 1168 + .page2 = { [0] = {0xe0, 0x01}, }, 1169 + .num_phy = 1, 1170 + .check_efuse = true, 1171 + .check_efuse_version = CHECK_EFUSE_V1, 1172 + .efuse_dc_driving_rate = 1, 1173 + .dc_driving_mask = 0xf, 1174 + .efuse_dc_disconnect_rate = EFUS_USB_DC_DIS_RATE, 1175 + .dc_disconnect_mask = 0xf, 1176 + .usb_dc_disconnect_at_page0 = true, 1177 + .do_toggle = true, 1178 + .do_toggle_driving = true, 1179 + .driving_updated_for_dev_dis = 0xf, 1180 + .use_default_parameter = false, 1181 + .is_double_sensitivity_mode = true, 1182 + }; 1183 + 1184 + static const struct phy_cfg rtd1312c_phy_cfg = { 1185 + .page0_size = MAX_USB_PHY_PAGE0_DATA_SIZE, 1186 + .page0 = { [0] = {0xe0, 0x14}, 1187 + [4] = {0xe4, 0x67}, 1188 + [5] = {0xe5, 0x55}, }, 1189 + .page1_size = 8, 1190 + .page1 = { [3] = {0xe3, 0x23}, 1191 + [6] = {0xe6, 0x58}, }, 1192 + .page2_size = MAX_USB_PHY_PAGE2_DATA_SIZE, 1193 + .page2 = { /* default parameter */ }, 1194 + .num_phy = 1, 1195 + .check_efuse = true, 1196 + .check_efuse_version = CHECK_EFUSE_V1, 1197 + .efuse_dc_driving_rate = 1, 1198 + .dc_driving_mask = 0xf, 1199 + .efuse_dc_disconnect_rate = EFUS_USB_DC_DIS_RATE, 1200 + .dc_disconnect_mask = 0xf, 1201 + .usb_dc_disconnect_at_page0 = true, 1202 + .do_toggle = true, 1203 + .do_toggle_driving = true, 1204 + .driving_updated_for_dev_dis = 0xf, 1205 + .use_default_parameter = false, 1206 + .is_double_sensitivity_mode = true, 1207 + }; 1208 + 1209 + static const struct phy_cfg rtd1619b_phy_cfg = { 1210 + .page0_size = MAX_USB_PHY_PAGE0_DATA_SIZE, 1211 + .page0 = { [0] = {0xe0, 0xa3}, 1212 + [4] = {0xe4, 0xa8}, 1213 + [5] = {0xe5, 0x4f}, 1214 + [6] = {0xe6, 0x02}, }, 1215 + .page1_size = 8, 1216 + .page1 = { [3] = {0xe3, 0x64}, }, 1217 + .page2_size = MAX_USB_PHY_PAGE2_DATA_SIZE, 1218 + .page2 = { [7] = {0xe7, 0x45}, }, 1219 + .num_phy = 1, 1220 + .check_efuse = true, 1221 + .check_efuse_version = CHECK_EFUSE_V1, 1222 + .efuse_dc_driving_rate = EFUS_USB_DC_CAL_RATE, 1223 + .dc_driving_mask = 0x1f, 1224 + .efuse_dc_disconnect_rate = EFUS_USB_DC_DIS_RATE, 1225 + .dc_disconnect_mask = 0xf, 1226 + .usb_dc_disconnect_at_page0 = false, 1227 + .do_toggle = true, 1228 + .do_toggle_driving = true, 1229 + .driving_updated_for_dev_dis = 0x8, 1230 + .use_default_parameter = false, 1231 + .is_double_sensitivity_mode = true, 1232 + }; 1233 + 1234 + static const struct phy_cfg rtd1319d_phy_cfg = { 1235 + .page0_size = MAX_USB_PHY_PAGE0_DATA_SIZE, 1236 + .page0 = { [0] = {0xe0, 0xa3}, 1237 + [4] = {0xe4, 0x8e}, 1238 + [5] = {0xe5, 0x4f}, 1239 + [6] = {0xe6, 0x02}, }, 1240 + .page1_size = MAX_USB_PHY_PAGE1_DATA_SIZE, 1241 + .page1 = { [14] = {0xf5, 0x1}, }, 1242 + .page2_size = MAX_USB_PHY_PAGE2_DATA_SIZE, 1243 + .page2 = { [7] = {0xe7, 0x44}, }, 1244 + .check_efuse = true, 1245 + .num_phy = 1, 1246 + .check_efuse_version = CHECK_EFUSE_V1, 1247 + .efuse_dc_driving_rate = EFUS_USB_DC_CAL_RATE, 1248 + .dc_driving_mask = 0x1f, 1249 + .efuse_dc_disconnect_rate = EFUS_USB_DC_DIS_RATE, 1250 + .dc_disconnect_mask = 0xf, 1251 + .usb_dc_disconnect_at_page0 = false, 1252 + .do_toggle = true, 1253 + .do_toggle_driving = false, 1254 + .driving_updated_for_dev_dis = 0x8, 1255 + .use_default_parameter = false, 1256 + .is_double_sensitivity_mode = true, 1257 + }; 1258 + 1259 + static const struct phy_cfg rtd1315e_phy_cfg = { 1260 + .page0_size = MAX_USB_PHY_PAGE0_DATA_SIZE, 1261 + .page0 = { [0] = {0xe0, 0xa3}, 1262 + [4] = {0xe4, 0x8c}, 1263 + [5] = {0xe5, 0x4f}, 1264 + [6] = {0xe6, 0x02}, }, 1265 + .page1_size = MAX_USB_PHY_PAGE1_DATA_SIZE, 1266 + .page1 = { [3] = {0xe3, 0x7f}, 1267 + [14] = {0xf5, 0x01}, }, 1268 + .page2_size = MAX_USB_PHY_PAGE2_DATA_SIZE, 1269 + .page2 = { [7] = {0xe7, 0x44}, }, 1270 + .num_phy = 1, 1271 + .check_efuse = true, 1272 + .check_efuse_version = CHECK_EFUSE_V2, 1273 + .efuse_dc_driving_rate = EFUS_USB_DC_CAL_RATE, 1274 + .dc_driving_mask = 0x1f, 1275 + .efuse_dc_disconnect_rate = EFUS_USB_DC_DIS_RATE, 1276 + .dc_disconnect_mask = 0xf, 1277 + .usb_dc_disconnect_at_page0 = false, 1278 + .do_toggle = true, 1279 + .do_toggle_driving = false, 1280 + .driving_updated_for_dev_dis = 0x8, 1281 + .use_default_parameter = false, 1282 + .is_double_sensitivity_mode = true, 1283 + }; 1284 + 1285 + static const struct of_device_id usbphy_rtk_dt_match[] = { 1286 + { .compatible = "realtek,rtd1295-usb2phy", .data = &rtd1295_phy_cfg }, 1287 + { .compatible = "realtek,rtd1312c-usb2phy", .data = &rtd1312c_phy_cfg }, 1288 + { .compatible = "realtek,rtd1315e-usb2phy", .data = &rtd1315e_phy_cfg }, 1289 + { .compatible = "realtek,rtd1319-usb2phy", .data = &rtd1319_phy_cfg }, 1290 + { .compatible = "realtek,rtd1319d-usb2phy", .data = &rtd1319d_phy_cfg }, 1291 + { .compatible = "realtek,rtd1395-usb2phy", .data = &rtd1395_phy_cfg }, 1292 + { .compatible = "realtek,rtd1395-usb2phy-2port", .data = &rtd1395_phy_cfg_2port }, 1293 + { .compatible = "realtek,rtd1619-usb2phy", .data = &rtd1619_phy_cfg }, 1294 + { .compatible = "realtek,rtd1619b-usb2phy", .data = &rtd1619b_phy_cfg }, 1295 + {}, 1296 + }; 1297 + MODULE_DEVICE_TABLE(of, usbphy_rtk_dt_match); 1298 + 1299 + static struct platform_driver rtk_usb2phy_driver = { 1300 + .probe = rtk_usb2phy_probe, 1301 + .remove_new = rtk_usb2phy_remove, 1302 + .driver = { 1303 + .name = "rtk-usb2phy", 1304 + .of_match_table = usbphy_rtk_dt_match, 1305 + }, 1306 + }; 1307 + 1308 + module_platform_driver(rtk_usb2phy_driver); 1309 + 1310 + MODULE_LICENSE("GPL"); 1311 + MODULE_AUTHOR("Stanley Chang <stanley_chang@realtek.com>"); 1312 + MODULE_DESCRIPTION("Realtek usb 2.0 phy driver");
+748
drivers/phy/realtek/phy-rtk-usb3.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * phy-rtk-usb3.c RTK usb3.0 phy driver 4 + * 5 + * copyright (c) 2023 realtek semiconductor corporation 6 + * 7 + */ 8 + 9 + #include <linux/module.h> 10 + #include <linux/of.h> 11 + #include <linux/of_address.h> 12 + #include <linux/platform_device.h> 13 + #include <linux/uaccess.h> 14 + #include <linux/debugfs.h> 15 + #include <linux/nvmem-consumer.h> 16 + #include <linux/regmap.h> 17 + #include <linux/sys_soc.h> 18 + #include <linux/mfd/syscon.h> 19 + #include <linux/phy/phy.h> 20 + #include <linux/usb.h> 21 + 22 + #define USB_MDIO_CTRL_PHY_BUSY BIT(7) 23 + #define USB_MDIO_CTRL_PHY_WRITE BIT(0) 24 + #define USB_MDIO_CTRL_PHY_ADDR_SHIFT 8 25 + #define USB_MDIO_CTRL_PHY_DATA_SHIFT 16 26 + 27 + #define MAX_USB_PHY_DATA_SIZE 0x30 28 + #define PHY_ADDR_0X09 0x09 29 + #define PHY_ADDR_0X0B 0x0b 30 + #define PHY_ADDR_0X0D 0x0d 31 + #define PHY_ADDR_0X10 0x10 32 + #define PHY_ADDR_0X1F 0x1f 33 + #define PHY_ADDR_0X20 0x20 34 + #define PHY_ADDR_0X21 0x21 35 + #define PHY_ADDR_0X30 0x30 36 + 37 + #define REG_0X09_FORCE_CALIBRATION BIT(9) 38 + #define REG_0X0B_RX_OFFSET_RANGE_MASK 0xc 39 + #define REG_0X0D_RX_DEBUG_TEST_EN BIT(6) 40 + #define REG_0X10_DEBUG_MODE_SETTING 0x3c0 41 + #define REG_0X10_DEBUG_MODE_SETTING_MASK 0x3f8 42 + #define REG_0X1F_RX_OFFSET_CODE_MASK 0x1e 43 + 44 + #define USB_U3_TX_LFPS_SWING_TRIM_SHIFT 4 45 + #define USB_U3_TX_LFPS_SWING_TRIM_MASK 0xf 46 + #define AMPLITUDE_CONTROL_COARSE_MASK 0xff 47 + #define AMPLITUDE_CONTROL_FINE_MASK 0xffff 48 + #define AMPLITUDE_CONTROL_COARSE_DEFAULT 0xff 49 + #define AMPLITUDE_CONTROL_FINE_DEFAULT 0xffff 50 + 51 + #define PHY_ADDR_MAP_ARRAY_INDEX(addr) (addr) 52 + #define ARRAY_INDEX_MAP_PHY_ADDR(index) (index) 53 + 54 + struct phy_reg { 55 + void __iomem *reg_mdio_ctl; 56 + }; 57 + 58 + struct phy_data { 59 + u8 addr; 60 + u16 data; 61 + }; 62 + 63 + struct phy_cfg { 64 + int param_size; 65 + struct phy_data param[MAX_USB_PHY_DATA_SIZE]; 66 + 67 + bool check_efuse; 68 + bool do_toggle; 69 + bool do_toggle_once; 70 + bool use_default_parameter; 71 + bool check_rx_front_end_offset; 72 + }; 73 + 74 + struct phy_parameter { 75 + struct phy_reg phy_reg; 76 + 77 + /* Get from efuse */ 78 + u8 efuse_usb_u3_tx_lfps_swing_trim; 79 + 80 + /* Get from dts */ 81 + u32 amplitude_control_coarse; 82 + u32 amplitude_control_fine; 83 + }; 84 + 85 + struct rtk_phy { 86 + struct device *dev; 87 + 88 + struct phy_cfg *phy_cfg; 89 + int num_phy; 90 + struct phy_parameter *phy_parameter; 91 + 92 + struct dentry *debug_dir; 93 + }; 94 + 95 + #define PHY_IO_TIMEOUT_USEC (50000) 96 + #define PHY_IO_DELAY_US (100) 97 + 98 + static inline int utmi_wait_register(void __iomem *reg, u32 mask, u32 result) 99 + { 100 + int ret; 101 + unsigned int val; 102 + 103 + ret = read_poll_timeout(readl, val, ((val & mask) == result), 104 + PHY_IO_DELAY_US, PHY_IO_TIMEOUT_USEC, false, reg); 105 + if (ret) { 106 + pr_err("%s can't program USB phy\n", __func__); 107 + return -ETIMEDOUT; 108 + } 109 + 110 + return 0; 111 + } 112 + 113 + static int rtk_phy3_wait_vbusy(struct phy_reg *phy_reg) 114 + { 115 + return utmi_wait_register(phy_reg->reg_mdio_ctl, USB_MDIO_CTRL_PHY_BUSY, 0); 116 + } 117 + 118 + static u16 rtk_phy_read(struct phy_reg *phy_reg, char addr) 119 + { 120 + unsigned int tmp; 121 + u32 value; 122 + 123 + tmp = (addr << USB_MDIO_CTRL_PHY_ADDR_SHIFT); 124 + 125 + writel(tmp, phy_reg->reg_mdio_ctl); 126 + 127 + rtk_phy3_wait_vbusy(phy_reg); 128 + 129 + value = readl(phy_reg->reg_mdio_ctl); 130 + value = value >> USB_MDIO_CTRL_PHY_DATA_SHIFT; 131 + 132 + return (u16)value; 133 + } 134 + 135 + static int rtk_phy_write(struct phy_reg *phy_reg, char addr, u16 data) 136 + { 137 + unsigned int val; 138 + 139 + val = USB_MDIO_CTRL_PHY_WRITE | 140 + (addr << USB_MDIO_CTRL_PHY_ADDR_SHIFT) | 141 + (data << USB_MDIO_CTRL_PHY_DATA_SHIFT); 142 + 143 + writel(val, phy_reg->reg_mdio_ctl); 144 + 145 + rtk_phy3_wait_vbusy(phy_reg); 146 + 147 + return 0; 148 + } 149 + 150 + static void do_rtk_usb3_phy_toggle(struct rtk_phy *rtk_phy, int index, bool connect) 151 + { 152 + struct phy_cfg *phy_cfg = rtk_phy->phy_cfg; 153 + struct phy_reg *phy_reg; 154 + struct phy_parameter *phy_parameter; 155 + struct phy_data *phy_data; 156 + u8 addr; 157 + u16 data; 158 + int i; 159 + 160 + phy_parameter = &((struct phy_parameter *)rtk_phy->phy_parameter)[index]; 161 + phy_reg = &phy_parameter->phy_reg; 162 + 163 + if (!phy_cfg->do_toggle) 164 + return; 165 + 166 + i = PHY_ADDR_MAP_ARRAY_INDEX(PHY_ADDR_0X09); 167 + phy_data = phy_cfg->param + i; 168 + addr = phy_data->addr; 169 + data = phy_data->data; 170 + 171 + if (!addr && !data) { 172 + addr = PHY_ADDR_0X09; 173 + data = rtk_phy_read(phy_reg, addr); 174 + phy_data->addr = addr; 175 + phy_data->data = data; 176 + } 177 + 178 + rtk_phy_write(phy_reg, addr, data & (~REG_0X09_FORCE_CALIBRATION)); 179 + mdelay(1); 180 + rtk_phy_write(phy_reg, addr, data | REG_0X09_FORCE_CALIBRATION); 181 + } 182 + 183 + static int do_rtk_phy_init(struct rtk_phy *rtk_phy, int index) 184 + { 185 + struct phy_cfg *phy_cfg; 186 + struct phy_reg *phy_reg; 187 + struct phy_parameter *phy_parameter; 188 + int i = 0; 189 + 190 + phy_cfg = rtk_phy->phy_cfg; 191 + phy_parameter = &((struct phy_parameter *)rtk_phy->phy_parameter)[index]; 192 + phy_reg = &phy_parameter->phy_reg; 193 + 194 + if (phy_cfg->use_default_parameter) 195 + goto do_toggle; 196 + 197 + for (i = 0; i < phy_cfg->param_size; i++) { 198 + struct phy_data *phy_data = phy_cfg->param + i; 199 + u8 addr = phy_data->addr; 200 + u16 data = phy_data->data; 201 + 202 + if (!addr && !data) 203 + continue; 204 + 205 + rtk_phy_write(phy_reg, addr, data); 206 + } 207 + 208 + do_toggle: 209 + if (phy_cfg->do_toggle_once) 210 + phy_cfg->do_toggle = true; 211 + 212 + do_rtk_usb3_phy_toggle(rtk_phy, index, false); 213 + 214 + if (phy_cfg->do_toggle_once) { 215 + u16 check_value = 0; 216 + int count = 10; 217 + u16 value_0x0d, value_0x10; 218 + 219 + /* Enable Debug mode by set 0x0D and 0x10 */ 220 + value_0x0d = rtk_phy_read(phy_reg, PHY_ADDR_0X0D); 221 + value_0x10 = rtk_phy_read(phy_reg, PHY_ADDR_0X10); 222 + 223 + rtk_phy_write(phy_reg, PHY_ADDR_0X0D, 224 + value_0x0d | REG_0X0D_RX_DEBUG_TEST_EN); 225 + rtk_phy_write(phy_reg, PHY_ADDR_0X10, 226 + (value_0x10 & ~REG_0X10_DEBUG_MODE_SETTING_MASK) | 227 + REG_0X10_DEBUG_MODE_SETTING); 228 + 229 + check_value = rtk_phy_read(phy_reg, PHY_ADDR_0X30); 230 + 231 + while (!(check_value & BIT(15))) { 232 + check_value = rtk_phy_read(phy_reg, PHY_ADDR_0X30); 233 + mdelay(1); 234 + if (count-- < 0) 235 + break; 236 + } 237 + 238 + if (!(check_value & BIT(15))) 239 + dev_info(rtk_phy->dev, "toggle fail addr=0x%02x, data=0x%04x\n", 240 + PHY_ADDR_0X30, check_value); 241 + 242 + /* Disable Debug mode by set 0x0D and 0x10 to default*/ 243 + rtk_phy_write(phy_reg, PHY_ADDR_0X0D, value_0x0d); 244 + rtk_phy_write(phy_reg, PHY_ADDR_0X10, value_0x10); 245 + 246 + phy_cfg->do_toggle = false; 247 + } 248 + 249 + if (phy_cfg->check_rx_front_end_offset) { 250 + u16 rx_offset_code, rx_offset_range; 251 + u16 code_mask = REG_0X1F_RX_OFFSET_CODE_MASK; 252 + u16 range_mask = REG_0X0B_RX_OFFSET_RANGE_MASK; 253 + bool do_update = false; 254 + 255 + rx_offset_code = rtk_phy_read(phy_reg, PHY_ADDR_0X1F); 256 + if (((rx_offset_code & code_mask) == 0x0) || 257 + ((rx_offset_code & code_mask) == code_mask)) 258 + do_update = true; 259 + 260 + rx_offset_range = rtk_phy_read(phy_reg, PHY_ADDR_0X0B); 261 + if (((rx_offset_range & range_mask) == range_mask) && do_update) { 262 + dev_warn(rtk_phy->dev, "Don't update rx_offset_range (rx_offset_code=0x%x, rx_offset_range=0x%x)\n", 263 + rx_offset_code, rx_offset_range); 264 + do_update = false; 265 + } 266 + 267 + if (do_update) { 268 + u16 tmp1, tmp2; 269 + 270 + tmp1 = rx_offset_range & (~range_mask); 271 + tmp2 = rx_offset_range & range_mask; 272 + tmp2 += (1 << 2); 273 + rx_offset_range = tmp1 | (tmp2 & range_mask); 274 + rtk_phy_write(phy_reg, PHY_ADDR_0X0B, rx_offset_range); 275 + goto do_toggle; 276 + } 277 + } 278 + 279 + return 0; 280 + } 281 + 282 + static int rtk_phy_init(struct phy *phy) 283 + { 284 + struct rtk_phy *rtk_phy = phy_get_drvdata(phy); 285 + int ret = 0; 286 + int i; 287 + unsigned long phy_init_time = jiffies; 288 + 289 + for (i = 0; i < rtk_phy->num_phy; i++) 290 + ret = do_rtk_phy_init(rtk_phy, i); 291 + 292 + dev_dbg(rtk_phy->dev, "Initialized RTK USB 3.0 PHY (take %dms)\n", 293 + jiffies_to_msecs(jiffies - phy_init_time)); 294 + 295 + return ret; 296 + } 297 + 298 + static int rtk_phy_exit(struct phy *phy) 299 + { 300 + return 0; 301 + } 302 + 303 + static void rtk_phy_toggle(struct rtk_phy *rtk_phy, bool connect, int port) 304 + { 305 + int index = port; 306 + 307 + if (index > rtk_phy->num_phy) { 308 + dev_err(rtk_phy->dev, "%s: The port=%d is not in usb phy (num_phy=%d)\n", 309 + __func__, index, rtk_phy->num_phy); 310 + return; 311 + } 312 + 313 + do_rtk_usb3_phy_toggle(rtk_phy, index, connect); 314 + } 315 + 316 + static int rtk_phy_connect(struct phy *phy, int port) 317 + { 318 + struct rtk_phy *rtk_phy = phy_get_drvdata(phy); 319 + 320 + dev_dbg(rtk_phy->dev, "%s port=%d\n", __func__, port); 321 + rtk_phy_toggle(rtk_phy, true, port); 322 + 323 + return 0; 324 + } 325 + 326 + static int rtk_phy_disconnect(struct phy *phy, int port) 327 + { 328 + struct rtk_phy *rtk_phy = phy_get_drvdata(phy); 329 + 330 + dev_dbg(rtk_phy->dev, "%s port=%d\n", __func__, port); 331 + rtk_phy_toggle(rtk_phy, false, port); 332 + 333 + return 0; 334 + } 335 + 336 + static const struct phy_ops ops = { 337 + .init = rtk_phy_init, 338 + .exit = rtk_phy_exit, 339 + .connect = rtk_phy_connect, 340 + .disconnect = rtk_phy_disconnect, 341 + .owner = THIS_MODULE, 342 + }; 343 + 344 + #ifdef CONFIG_DEBUG_FS 345 + static struct dentry *create_phy_debug_root(void) 346 + { 347 + struct dentry *phy_debug_root; 348 + 349 + phy_debug_root = debugfs_lookup("phy", usb_debug_root); 350 + if (!phy_debug_root) 351 + phy_debug_root = debugfs_create_dir("phy", usb_debug_root); 352 + 353 + return phy_debug_root; 354 + } 355 + 356 + static int rtk_usb3_parameter_show(struct seq_file *s, void *unused) 357 + { 358 + struct rtk_phy *rtk_phy = s->private; 359 + struct phy_cfg *phy_cfg; 360 + int i, index; 361 + 362 + phy_cfg = rtk_phy->phy_cfg; 363 + 364 + seq_puts(s, "Property:\n"); 365 + seq_printf(s, " check_efuse: %s\n", 366 + phy_cfg->check_efuse ? "Enable" : "Disable"); 367 + seq_printf(s, " do_toggle: %s\n", 368 + phy_cfg->do_toggle ? "Enable" : "Disable"); 369 + seq_printf(s, " do_toggle_once: %s\n", 370 + phy_cfg->do_toggle_once ? "Enable" : "Disable"); 371 + seq_printf(s, " use_default_parameter: %s\n", 372 + phy_cfg->use_default_parameter ? "Enable" : "Disable"); 373 + 374 + for (index = 0; index < rtk_phy->num_phy; index++) { 375 + struct phy_reg *phy_reg; 376 + struct phy_parameter *phy_parameter; 377 + 378 + phy_parameter = &((struct phy_parameter *)rtk_phy->phy_parameter)[index]; 379 + phy_reg = &phy_parameter->phy_reg; 380 + 381 + seq_printf(s, "PHY %d:\n", index); 382 + 383 + for (i = 0; i < phy_cfg->param_size; i++) { 384 + struct phy_data *phy_data = phy_cfg->param + i; 385 + u8 addr = ARRAY_INDEX_MAP_PHY_ADDR(i); 386 + u16 data = phy_data->data; 387 + 388 + if (!phy_data->addr && !data) 389 + seq_printf(s, " addr = 0x%02x, data = none ==> read value = 0x%04x\n", 390 + addr, rtk_phy_read(phy_reg, addr)); 391 + else 392 + seq_printf(s, " addr = 0x%02x, data = 0x%04x ==> read value = 0x%04x\n", 393 + addr, data, rtk_phy_read(phy_reg, addr)); 394 + } 395 + 396 + seq_puts(s, "PHY Property:\n"); 397 + seq_printf(s, " efuse_usb_u3_tx_lfps_swing_trim: 0x%x\n", 398 + (int)phy_parameter->efuse_usb_u3_tx_lfps_swing_trim); 399 + seq_printf(s, " amplitude_control_coarse: 0x%x\n", 400 + (int)phy_parameter->amplitude_control_coarse); 401 + seq_printf(s, " amplitude_control_fine: 0x%x\n", 402 + (int)phy_parameter->amplitude_control_fine); 403 + } 404 + 405 + return 0; 406 + } 407 + DEFINE_SHOW_ATTRIBUTE(rtk_usb3_parameter); 408 + 409 + static inline void create_debug_files(struct rtk_phy *rtk_phy) 410 + { 411 + struct dentry *phy_debug_root = NULL; 412 + 413 + phy_debug_root = create_phy_debug_root(); 414 + 415 + if (!phy_debug_root) 416 + return; 417 + 418 + rtk_phy->debug_dir = debugfs_create_dir(dev_name(rtk_phy->dev), phy_debug_root); 419 + 420 + debugfs_create_file("parameter", 0444, rtk_phy->debug_dir, rtk_phy, 421 + &rtk_usb3_parameter_fops); 422 + } 423 + 424 + static inline void remove_debug_files(struct rtk_phy *rtk_phy) 425 + { 426 + debugfs_remove_recursive(rtk_phy->debug_dir); 427 + } 428 + #else 429 + static inline void create_debug_files(struct rtk_phy *rtk_phy) { } 430 + static inline void remove_debug_files(struct rtk_phy *rtk_phy) { } 431 + #endif /* CONFIG_DEBUG_FS */ 432 + 433 + static int get_phy_data_by_efuse(struct rtk_phy *rtk_phy, 434 + struct phy_parameter *phy_parameter, int index) 435 + { 436 + struct phy_cfg *phy_cfg = rtk_phy->phy_cfg; 437 + u8 value = 0; 438 + struct nvmem_cell *cell; 439 + 440 + if (!phy_cfg->check_efuse) 441 + goto out; 442 + 443 + cell = nvmem_cell_get(rtk_phy->dev, "usb_u3_tx_lfps_swing_trim"); 444 + if (IS_ERR(cell)) { 445 + dev_dbg(rtk_phy->dev, "%s no usb_u3_tx_lfps_swing_trim: %ld\n", 446 + __func__, PTR_ERR(cell)); 447 + } else { 448 + unsigned char *buf; 449 + size_t buf_size; 450 + 451 + buf = nvmem_cell_read(cell, &buf_size); 452 + if (!IS_ERR(buf)) { 453 + value = buf[0] & USB_U3_TX_LFPS_SWING_TRIM_MASK; 454 + kfree(buf); 455 + } 456 + nvmem_cell_put(cell); 457 + } 458 + 459 + if (value > 0 && value < 0x8) 460 + phy_parameter->efuse_usb_u3_tx_lfps_swing_trim = 0x8; 461 + else 462 + phy_parameter->efuse_usb_u3_tx_lfps_swing_trim = (u8)value; 463 + 464 + out: 465 + return 0; 466 + } 467 + 468 + static void update_amplitude_control_value(struct rtk_phy *rtk_phy, 469 + struct phy_parameter *phy_parameter) 470 + { 471 + struct phy_cfg *phy_cfg; 472 + struct phy_reg *phy_reg; 473 + 474 + phy_reg = &phy_parameter->phy_reg; 475 + phy_cfg = rtk_phy->phy_cfg; 476 + 477 + if (phy_parameter->amplitude_control_coarse != AMPLITUDE_CONTROL_COARSE_DEFAULT) { 478 + u16 val_mask = AMPLITUDE_CONTROL_COARSE_MASK; 479 + u16 data; 480 + 481 + if (!phy_cfg->param[PHY_ADDR_0X20].addr && !phy_cfg->param[PHY_ADDR_0X20].data) { 482 + phy_cfg->param[PHY_ADDR_0X20].addr = PHY_ADDR_0X20; 483 + data = rtk_phy_read(phy_reg, PHY_ADDR_0X20); 484 + } else { 485 + data = phy_cfg->param[PHY_ADDR_0X20].data; 486 + } 487 + 488 + data &= (~val_mask); 489 + data |= (phy_parameter->amplitude_control_coarse & val_mask); 490 + 491 + phy_cfg->param[PHY_ADDR_0X20].data = data; 492 + } 493 + 494 + if (phy_parameter->efuse_usb_u3_tx_lfps_swing_trim) { 495 + u8 efuse_val = phy_parameter->efuse_usb_u3_tx_lfps_swing_trim; 496 + u16 val_mask = USB_U3_TX_LFPS_SWING_TRIM_MASK; 497 + int val_shift = USB_U3_TX_LFPS_SWING_TRIM_SHIFT; 498 + u16 data; 499 + 500 + if (!phy_cfg->param[PHY_ADDR_0X20].addr && !phy_cfg->param[PHY_ADDR_0X20].data) { 501 + phy_cfg->param[PHY_ADDR_0X20].addr = PHY_ADDR_0X20; 502 + data = rtk_phy_read(phy_reg, PHY_ADDR_0X20); 503 + } else { 504 + data = phy_cfg->param[PHY_ADDR_0X20].data; 505 + } 506 + 507 + data &= ~(val_mask << val_shift); 508 + data |= ((efuse_val & val_mask) << val_shift); 509 + 510 + phy_cfg->param[PHY_ADDR_0X20].data = data; 511 + } 512 + 513 + if (phy_parameter->amplitude_control_fine != AMPLITUDE_CONTROL_FINE_DEFAULT) { 514 + u16 val_mask = AMPLITUDE_CONTROL_FINE_MASK; 515 + 516 + if (!phy_cfg->param[PHY_ADDR_0X21].addr && !phy_cfg->param[PHY_ADDR_0X21].data) 517 + phy_cfg->param[PHY_ADDR_0X21].addr = PHY_ADDR_0X21; 518 + 519 + phy_cfg->param[PHY_ADDR_0X21].data = 520 + phy_parameter->amplitude_control_fine & val_mask; 521 + } 522 + } 523 + 524 + static int parse_phy_data(struct rtk_phy *rtk_phy) 525 + { 526 + struct device *dev = rtk_phy->dev; 527 + struct phy_parameter *phy_parameter; 528 + int ret = 0; 529 + int index; 530 + 531 + rtk_phy->phy_parameter = devm_kzalloc(dev, sizeof(struct phy_parameter) * 532 + rtk_phy->num_phy, GFP_KERNEL); 533 + if (!rtk_phy->phy_parameter) 534 + return -ENOMEM; 535 + 536 + for (index = 0; index < rtk_phy->num_phy; index++) { 537 + phy_parameter = &((struct phy_parameter *)rtk_phy->phy_parameter)[index]; 538 + 539 + phy_parameter->phy_reg.reg_mdio_ctl = of_iomap(dev->of_node, 0) + index; 540 + 541 + /* Amplitude control address 0x20 bit 0 to bit 7 */ 542 + if (of_property_read_u32(dev->of_node, "realtek,amplitude-control-coarse-tuning", 543 + &phy_parameter->amplitude_control_coarse)) 544 + phy_parameter->amplitude_control_coarse = AMPLITUDE_CONTROL_COARSE_DEFAULT; 545 + 546 + /* Amplitude control address 0x21 bit 0 to bit 16 */ 547 + if (of_property_read_u32(dev->of_node, "realtek,amplitude-control-fine-tuning", 548 + &phy_parameter->amplitude_control_fine)) 549 + phy_parameter->amplitude_control_fine = AMPLITUDE_CONTROL_FINE_DEFAULT; 550 + 551 + get_phy_data_by_efuse(rtk_phy, phy_parameter, index); 552 + 553 + update_amplitude_control_value(rtk_phy, phy_parameter); 554 + } 555 + 556 + return ret; 557 + } 558 + 559 + static int rtk_usb3phy_probe(struct platform_device *pdev) 560 + { 561 + struct rtk_phy *rtk_phy; 562 + struct device *dev = &pdev->dev; 563 + struct phy *generic_phy; 564 + struct phy_provider *phy_provider; 565 + const struct phy_cfg *phy_cfg; 566 + int ret; 567 + 568 + phy_cfg = of_device_get_match_data(dev); 569 + if (!phy_cfg) { 570 + dev_err(dev, "phy config are not assigned!\n"); 571 + return -EINVAL; 572 + } 573 + 574 + rtk_phy = devm_kzalloc(dev, sizeof(*rtk_phy), GFP_KERNEL); 575 + if (!rtk_phy) 576 + return -ENOMEM; 577 + 578 + rtk_phy->dev = &pdev->dev; 579 + rtk_phy->phy_cfg = devm_kzalloc(dev, sizeof(*phy_cfg), GFP_KERNEL); 580 + 581 + memcpy(rtk_phy->phy_cfg, phy_cfg, sizeof(*phy_cfg)); 582 + 583 + rtk_phy->num_phy = 1; 584 + 585 + ret = parse_phy_data(rtk_phy); 586 + if (ret) 587 + goto err; 588 + 589 + platform_set_drvdata(pdev, rtk_phy); 590 + 591 + generic_phy = devm_phy_create(rtk_phy->dev, NULL, &ops); 592 + if (IS_ERR(generic_phy)) 593 + return PTR_ERR(generic_phy); 594 + 595 + phy_set_drvdata(generic_phy, rtk_phy); 596 + 597 + phy_provider = devm_of_phy_provider_register(rtk_phy->dev, of_phy_simple_xlate); 598 + if (IS_ERR(phy_provider)) 599 + return PTR_ERR(phy_provider); 600 + 601 + create_debug_files(rtk_phy); 602 + 603 + err: 604 + return ret; 605 + } 606 + 607 + static void rtk_usb3phy_remove(struct platform_device *pdev) 608 + { 609 + struct rtk_phy *rtk_phy = platform_get_drvdata(pdev); 610 + 611 + remove_debug_files(rtk_phy); 612 + } 613 + 614 + static const struct phy_cfg rtd1295_phy_cfg = { 615 + .param_size = MAX_USB_PHY_DATA_SIZE, 616 + .param = { [0] = {0x01, 0x4008}, [1] = {0x01, 0xe046}, 617 + [2] = {0x02, 0x6046}, [3] = {0x03, 0x2779}, 618 + [4] = {0x04, 0x72f5}, [5] = {0x05, 0x2ad3}, 619 + [6] = {0x06, 0x000e}, [7] = {0x07, 0x2e00}, 620 + [8] = {0x08, 0x3591}, [9] = {0x09, 0x525c}, 621 + [10] = {0x0a, 0xa600}, [11] = {0x0b, 0xa904}, 622 + [12] = {0x0c, 0xc000}, [13] = {0x0d, 0xef1c}, 623 + [14] = {0x0e, 0x2000}, [15] = {0x0f, 0x0000}, 624 + [16] = {0x10, 0x000c}, [17] = {0x11, 0x4c00}, 625 + [18] = {0x12, 0xfc00}, [19] = {0x13, 0x0c81}, 626 + [20] = {0x14, 0xde01}, [21] = {0x15, 0x0000}, 627 + [22] = {0x16, 0x0000}, [23] = {0x17, 0x0000}, 628 + [24] = {0x18, 0x0000}, [25] = {0x19, 0x4004}, 629 + [26] = {0x1a, 0x1260}, [27] = {0x1b, 0xff00}, 630 + [28] = {0x1c, 0xcb00}, [29] = {0x1d, 0xa03f}, 631 + [30] = {0x1e, 0xc2e0}, [31] = {0x1f, 0x2807}, 632 + [32] = {0x20, 0x947a}, [33] = {0x21, 0x88aa}, 633 + [34] = {0x22, 0x0057}, [35] = {0x23, 0xab66}, 634 + [36] = {0x24, 0x0800}, [37] = {0x25, 0x0000}, 635 + [38] = {0x26, 0x040a}, [39] = {0x27, 0x01d6}, 636 + [40] = {0x28, 0xf8c2}, [41] = {0x29, 0x3080}, 637 + [42] = {0x2a, 0x3082}, [43] = {0x2b, 0x2078}, 638 + [44] = {0x2c, 0xffff}, [45] = {0x2d, 0xffff}, 639 + [46] = {0x2e, 0x0000}, [47] = {0x2f, 0x0040}, }, 640 + .check_efuse = false, 641 + .do_toggle = true, 642 + .do_toggle_once = false, 643 + .use_default_parameter = false, 644 + .check_rx_front_end_offset = false, 645 + }; 646 + 647 + static const struct phy_cfg rtd1619_phy_cfg = { 648 + .param_size = MAX_USB_PHY_DATA_SIZE, 649 + .param = { [8] = {0x08, 0x3591}, 650 + [38] = {0x26, 0x840b}, 651 + [40] = {0x28, 0xf842}, }, 652 + .check_efuse = false, 653 + .do_toggle = true, 654 + .do_toggle_once = false, 655 + .use_default_parameter = false, 656 + .check_rx_front_end_offset = false, 657 + }; 658 + 659 + static const struct phy_cfg rtd1319_phy_cfg = { 660 + .param_size = MAX_USB_PHY_DATA_SIZE, 661 + .param = { [1] = {0x01, 0xac86}, 662 + [6] = {0x06, 0x0003}, 663 + [9] = {0x09, 0x924c}, 664 + [10] = {0x0a, 0xa608}, 665 + [11] = {0x0b, 0xb905}, 666 + [14] = {0x0e, 0x2010}, 667 + [32] = {0x20, 0x705a}, 668 + [33] = {0x21, 0xf645}, 669 + [34] = {0x22, 0x0013}, 670 + [35] = {0x23, 0xcb66}, 671 + [41] = {0x29, 0xff00}, }, 672 + .check_efuse = true, 673 + .do_toggle = true, 674 + .do_toggle_once = false, 675 + .use_default_parameter = false, 676 + .check_rx_front_end_offset = false, 677 + }; 678 + 679 + static const struct phy_cfg rtd1619b_phy_cfg = { 680 + .param_size = MAX_USB_PHY_DATA_SIZE, 681 + .param = { [1] = {0x01, 0xac8c}, 682 + [6] = {0x06, 0x0017}, 683 + [9] = {0x09, 0x724c}, 684 + [10] = {0x0a, 0xb610}, 685 + [11] = {0x0b, 0xb90d}, 686 + [13] = {0x0d, 0xef2a}, 687 + [15] = {0x0f, 0x9050}, 688 + [16] = {0x10, 0x000c}, 689 + [32] = {0x20, 0x70ff}, 690 + [34] = {0x22, 0x0013}, 691 + [35] = {0x23, 0xdb66}, 692 + [38] = {0x26, 0x8609}, 693 + [41] = {0x29, 0xff13}, 694 + [42] = {0x2a, 0x3070}, }, 695 + .check_efuse = true, 696 + .do_toggle = false, 697 + .do_toggle_once = true, 698 + .use_default_parameter = false, 699 + .check_rx_front_end_offset = false, 700 + }; 701 + 702 + static const struct phy_cfg rtd1319d_phy_cfg = { 703 + .param_size = MAX_USB_PHY_DATA_SIZE, 704 + .param = { [1] = {0x01, 0xac89}, 705 + [4] = {0x04, 0xf2f5}, 706 + [6] = {0x06, 0x0017}, 707 + [9] = {0x09, 0x424c}, 708 + [10] = {0x0a, 0x9610}, 709 + [11] = {0x0b, 0x9901}, 710 + [12] = {0x0c, 0xf000}, 711 + [13] = {0x0d, 0xef2a}, 712 + [14] = {0x0e, 0x1000}, 713 + [15] = {0x0f, 0x9050}, 714 + [32] = {0x20, 0x7077}, 715 + [35] = {0x23, 0x0b62}, 716 + [37] = {0x25, 0x10ec}, 717 + [42] = {0x2a, 0x3070}, }, 718 + .check_efuse = true, 719 + .do_toggle = false, 720 + .do_toggle_once = true, 721 + .use_default_parameter = false, 722 + .check_rx_front_end_offset = true, 723 + }; 724 + 725 + static const struct of_device_id usbphy_rtk_dt_match[] = { 726 + { .compatible = "realtek,rtd1295-usb3phy", .data = &rtd1295_phy_cfg }, 727 + { .compatible = "realtek,rtd1319-usb3phy", .data = &rtd1319_phy_cfg }, 728 + { .compatible = "realtek,rtd1319d-usb3phy", .data = &rtd1319d_phy_cfg }, 729 + { .compatible = "realtek,rtd1619-usb3phy", .data = &rtd1619_phy_cfg }, 730 + { .compatible = "realtek,rtd1619b-usb3phy", .data = &rtd1619b_phy_cfg }, 731 + {}, 732 + }; 733 + MODULE_DEVICE_TABLE(of, usbphy_rtk_dt_match); 734 + 735 + static struct platform_driver rtk_usb3phy_driver = { 736 + .probe = rtk_usb3phy_probe, 737 + .remove_new = rtk_usb3phy_remove, 738 + .driver = { 739 + .name = "rtk-usb3phy", 740 + .of_match_table = usbphy_rtk_dt_match, 741 + }, 742 + }; 743 + 744 + module_platform_driver(rtk_usb3phy_driver); 745 + 746 + MODULE_LICENSE("GPL"); 747 + MODULE_AUTHOR("Stanley Chang <stanley_chang@realtek.com>"); 748 + MODULE_DESCRIPTION("Realtek usb 3.0 phy driver");
+13
drivers/phy/tegra/xusb.c
··· 1531 1531 } 1532 1532 EXPORT_SYMBOL_GPL(tegra_xusb_padctl_get_usb3_companion); 1533 1533 1534 + int tegra_xusb_padctl_get_port_number(struct phy *phy) 1535 + { 1536 + struct tegra_xusb_lane *lane; 1537 + 1538 + if (!phy) 1539 + return -ENODEV; 1540 + 1541 + lane = phy_get_drvdata(phy); 1542 + 1543 + return lane->index; 1544 + } 1545 + EXPORT_SYMBOL_GPL(tegra_xusb_padctl_get_port_number); 1546 + 1534 1547 MODULE_AUTHOR("Thierry Reding <treding@nvidia.com>"); 1535 1548 MODULE_DESCRIPTION("Tegra XUSB Pad Controller driver"); 1536 1549 MODULE_LICENSE("GPL v2");
+19
drivers/platform/chrome/cros_ec_typec.c
··· 24 24 #define DP_PORT_VDO (DP_CONF_SET_PIN_ASSIGN(BIT(DP_PIN_ASSIGN_C) | BIT(DP_PIN_ASSIGN_D)) | \ 25 25 DP_CAP_DFP_D | DP_CAP_RECEPTACLE) 26 26 27 + static void cros_typec_role_switch_quirk(struct fwnode_handle *fwnode) 28 + { 29 + #ifdef CONFIG_ACPI 30 + struct fwnode_handle *switch_fwnode; 31 + 32 + /* Supply the USB role switch with the correct pld_crc if it's missing. */ 33 + switch_fwnode = fwnode_find_reference(fwnode, "usb-role-switch", 0); 34 + if (!IS_ERR_OR_NULL(switch_fwnode)) { 35 + struct acpi_device *adev = to_acpi_device_node(switch_fwnode); 36 + 37 + if (adev && !adev->pld_crc) 38 + adev->pld_crc = to_acpi_device_node(fwnode)->pld_crc; 39 + fwnode_handle_put(switch_fwnode); 40 + } 41 + #endif 42 + } 43 + 27 44 static int cros_typec_parse_port_props(struct typec_capability *cap, 28 45 struct fwnode_handle *fwnode, 29 46 struct device *dev) ··· 82 65 return ret; 83 66 cap->prefer_role = ret; 84 67 } 68 + 69 + cros_typec_role_switch_quirk(fwnode); 85 70 86 71 cap->fwnode = fwnode; 87 72
+1
drivers/thunderbolt/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0-only 2 + ccflags-y := -I$(src) 2 3 obj-${CONFIG_USB4} := thunderbolt.o 3 4 thunderbolt-objs := nhi.o nhi_ops.o ctl.o tb.o switch.o cap.o path.o tunnel.o eeprom.o 4 5 thunderbolt-objs += domain.o dma_port.o icm.o property.o xdomain.o lc.o tmu.o usb4.o
+17 -2
drivers/thunderbolt/ctl.c
··· 15 15 16 16 #include "ctl.h" 17 17 18 + #define CREATE_TRACE_POINTS 19 + #include "trace.h" 18 20 19 21 #define TB_CTL_RX_PKG_COUNT 10 20 22 #define TB_CTL_RETRIES 4 ··· 34 32 * @timeout_msec: Default timeout for non-raw control messages 35 33 * @callback: Callback called when hotplug message is received 36 34 * @callback_data: Data passed to @callback 35 + * @index: Domain number. This will be output with the trace record. 37 36 */ 38 37 struct tb_ctl { 39 38 struct tb_nhi *nhi; ··· 50 47 int timeout_msec; 51 48 event_cb callback; 52 49 void *callback_data; 50 + 51 + int index; 53 52 }; 54 53 55 54 ··· 374 369 pkg->frame.size = len + 4; 375 370 pkg->frame.sof = type; 376 371 pkg->frame.eof = type; 372 + 373 + trace_tb_tx(ctl->index, type, data, len); 374 + 377 375 cpu_to_be32_array(pkg->buffer, data, len / 4); 378 376 *(__be32 *) (pkg->buffer + len) = tb_crc(pkg->buffer, len); 379 377 ··· 392 384 static bool tb_ctl_handle_event(struct tb_ctl *ctl, enum tb_cfg_pkg_type type, 393 385 struct ctl_pkg *pkg, size_t size) 394 386 { 387 + trace_tb_event(ctl->index, type, pkg->buffer, size); 395 388 return ctl->callback(ctl->callback_data, type, pkg->buffer, size); 396 389 } 397 390 ··· 498 489 * triggered from messing with the active requests. 499 490 */ 500 491 req = tb_cfg_request_find(pkg->ctl, pkg); 492 + 493 + trace_tb_rx(pkg->ctl->index, frame->eof, pkg->buffer, frame->size, !req); 494 + 501 495 if (req) { 502 496 if (req->copy(req, pkg)) 503 497 schedule_work(&req->work); ··· 626 614 /** 627 615 * tb_ctl_alloc() - allocate a control channel 628 616 * @nhi: Pointer to NHI 617 + * @index: Domain number 629 618 * @timeout_msec: Default timeout used with non-raw control messages 630 619 * @cb: Callback called for plug events 631 620 * @cb_data: Data passed to @cb ··· 635 622 * 636 623 * Return: Returns a pointer on success or NULL on failure. 637 624 */ 638 - struct tb_ctl *tb_ctl_alloc(struct tb_nhi *nhi, int timeout_msec, event_cb cb, 639 - void *cb_data) 625 + struct tb_ctl *tb_ctl_alloc(struct tb_nhi *nhi, int index, int timeout_msec, 626 + event_cb cb, void *cb_data) 640 627 { 641 628 int i; 642 629 struct tb_ctl *ctl = kzalloc(sizeof(*ctl), GFP_KERNEL); 643 630 if (!ctl) 644 631 return NULL; 632 + 645 633 ctl->nhi = nhi; 634 + ctl->index = index; 646 635 ctl->timeout_msec = timeout_msec; 647 636 ctl->callback = cb; 648 637 ctl->callback_data = cb_data;
+2 -2
drivers/thunderbolt/ctl.h
··· 21 21 typedef bool (*event_cb)(void *data, enum tb_cfg_pkg_type type, 22 22 const void *buf, size_t size); 23 23 24 - struct tb_ctl *tb_ctl_alloc(struct tb_nhi *nhi, int timeout_msec, event_cb cb, 25 - void *cb_data); 24 + struct tb_ctl *tb_ctl_alloc(struct tb_nhi *nhi, int index, int timeout_msec, 25 + event_cb cb, void *cb_data); 26 26 void tb_ctl_start(struct tb_ctl *ctl); 27 27 void tb_ctl_stop(struct tb_ctl *ctl); 28 28 void tb_ctl_free(struct tb_ctl *ctl);
+12 -7
drivers/thunderbolt/domain.c
··· 321 321 322 322 tb_ctl_free(tb->ctl); 323 323 destroy_workqueue(tb->wq); 324 - ida_simple_remove(&tb_domain_ida, tb->index); 324 + ida_free(&tb_domain_ida, tb->index); 325 325 mutex_destroy(&tb->lock); 326 326 kfree(tb); 327 327 } 328 328 329 - struct device_type tb_domain_type = { 329 + const struct device_type tb_domain_type = { 330 330 .name = "thunderbolt_domain", 331 331 .release = tb_domain_release, 332 332 }; ··· 389 389 tb->nhi = nhi; 390 390 mutex_init(&tb->lock); 391 391 392 - tb->index = ida_simple_get(&tb_domain_ida, 0, 0, GFP_KERNEL); 392 + tb->index = ida_alloc(&tb_domain_ida, GFP_KERNEL); 393 393 if (tb->index < 0) 394 394 goto err_free; 395 395 ··· 397 397 if (!tb->wq) 398 398 goto err_remove_ida; 399 399 400 - tb->ctl = tb_ctl_alloc(nhi, timeout_msec, tb_domain_event_cb, tb); 400 + tb->ctl = tb_ctl_alloc(nhi, tb->index, timeout_msec, tb_domain_event_cb, tb); 401 401 if (!tb->ctl) 402 402 goto err_destroy_wq; 403 403 ··· 413 413 err_destroy_wq: 414 414 destroy_workqueue(tb->wq); 415 415 err_remove_ida: 416 - ida_simple_remove(&tb_domain_ida, tb->index); 416 + ida_free(&tb_domain_ida, tb->index); 417 417 err_free: 418 418 kfree(tb); 419 419 ··· 423 423 /** 424 424 * tb_domain_add() - Add domain to the system 425 425 * @tb: Domain to add 426 + * @reset: Issue reset to the host router 426 427 * 427 428 * Starts the domain and adds it to the system. Hotplugging devices will 428 429 * work after this has been returned successfully. In order to remove ··· 432 431 * 433 432 * Return: %0 in case of success and negative errno in case of error 434 433 */ 435 - int tb_domain_add(struct tb *tb) 434 + int tb_domain_add(struct tb *tb, bool reset) 436 435 { 437 436 int ret; 438 437 ··· 461 460 462 461 /* Start the domain */ 463 462 if (tb->cm_ops->start) { 464 - ret = tb->cm_ops->start(tb); 463 + ret = tb->cm_ops->start(tb, reset); 465 464 if (ret) 466 465 goto err_domain_del; 467 466 } ··· 506 505 mutex_unlock(&tb->lock); 507 506 508 507 flush_workqueue(tb->wq); 508 + 509 + if (tb->cm_ops->deinit) 510 + tb->cm_ops->deinit(tb); 511 + 509 512 device_unregister(&tb->dev); 510 513 } 511 514
+1 -1
drivers/thunderbolt/icm.c
··· 2144 2144 return 0; 2145 2145 } 2146 2146 2147 - static int icm_start(struct tb *tb) 2147 + static int icm_start(struct tb *tb, bool not_used) 2148 2148 { 2149 2149 struct icm *icm = tb_priv(tb); 2150 2150 int ret;
+45
drivers/thunderbolt/lc.c
··· 6 6 * Author: Mika Westerberg <mika.westerberg@linux.intel.com> 7 7 */ 8 8 9 + #include <linux/delay.h> 10 + 9 11 #include "tb.h" 10 12 11 13 /** ··· 45 43 phys = tb_phy_port_from_link(port->port); 46 44 47 45 return sw->cap_lc + start + phys * size; 46 + } 47 + 48 + /** 49 + * tb_lc_reset_port() - Trigger downstream port reset through LC 50 + * @port: Port that is reset 51 + * 52 + * Triggers downstream port reset through link controller registers. 53 + * Returns %0 in case of success negative errno otherwise. Only supports 54 + * non-USB4 routers with link controller (that's Thunderbolt 2 and 55 + * Thunderbolt 3). 56 + */ 57 + int tb_lc_reset_port(struct tb_port *port) 58 + { 59 + struct tb_switch *sw = port->sw; 60 + int cap, ret; 61 + u32 mode; 62 + 63 + if (sw->generation < 2) 64 + return -EINVAL; 65 + 66 + cap = find_port_lc_cap(port); 67 + if (cap < 0) 68 + return cap; 69 + 70 + ret = tb_sw_read(sw, &mode, TB_CFG_SWITCH, cap + TB_LC_PORT_MODE, 1); 71 + if (ret) 72 + return ret; 73 + 74 + mode |= TB_LC_PORT_MODE_DPR; 75 + 76 + ret = tb_sw_write(sw, &mode, TB_CFG_SWITCH, cap + TB_LC_PORT_MODE, 1); 77 + if (ret) 78 + return ret; 79 + 80 + fsleep(10000); 81 + 82 + ret = tb_sw_read(sw, &mode, TB_CFG_SWITCH, cap + TB_LC_PORT_MODE, 1); 83 + if (ret) 84 + return ret; 85 + 86 + mode &= ~TB_LC_PORT_MODE_DPR; 87 + 88 + return tb_sw_write(sw, &mode, TB_CFG_SWITCH, cap + TB_LC_PORT_MODE, 1); 48 89 } 49 90 50 91 static int tb_lc_set_port_configured(struct tb_port *port, bool configured)
+5 -6
drivers/thunderbolt/nhi.c
··· 48 48 49 49 static bool host_reset = true; 50 50 module_param(host_reset, bool, 0444); 51 - MODULE_PARM_DESC(host_reset, "reset USBv2 host router (default: true)"); 51 + MODULE_PARM_DESC(host_reset, "reset USB4 host router (default: true)"); 52 52 53 53 static int ring_interrupt_index(const struct tb_ring *ring) 54 54 { ··· 465 465 if (!nhi->pdev->msix_enabled) 466 466 return 0; 467 467 468 - ret = ida_simple_get(&nhi->msix_ida, 0, MSIX_MAX_VECS, GFP_KERNEL); 468 + ret = ida_alloc_max(&nhi->msix_ida, MSIX_MAX_VECS - 1, GFP_KERNEL); 469 469 if (ret < 0) 470 470 return ret; 471 471 ··· 485 485 return 0; 486 486 487 487 err_ida_remove: 488 - ida_simple_remove(&nhi->msix_ida, ring->vector); 488 + ida_free(&nhi->msix_ida, ring->vector); 489 489 490 490 return ret; 491 491 } ··· 496 496 return; 497 497 498 498 free_irq(ring->irq, ring); 499 - ida_simple_remove(&ring->nhi->msix_ida, ring->vector); 499 + ida_free(&ring->nhi->msix_ida, ring->vector); 500 500 ring->vector = 0; 501 501 ring->irq = 0; 502 502 } ··· 1364 1364 1365 1365 nhi_check_quirks(nhi); 1366 1366 nhi_check_iommu(nhi); 1367 - 1368 1367 nhi_reset(nhi); 1369 1368 1370 1369 res = nhi_init_msi(nhi); ··· 1391 1392 1392 1393 dev_dbg(dev, "NHI initialized, starting thunderbolt\n"); 1393 1394 1394 - res = tb_domain_add(tb); 1395 + res = tb_domain_add(tb, host_reset); 1395 1396 if (res) { 1396 1397 /* 1397 1398 * At this point the RX/TX rings might already have been
+2 -2
drivers/thunderbolt/nvm.c
··· 330 330 if (!nvm) 331 331 return ERR_PTR(-ENOMEM); 332 332 333 - ret = ida_simple_get(&nvm_ida, 0, 0, GFP_KERNEL); 333 + ret = ida_alloc(&nvm_ida, GFP_KERNEL); 334 334 if (ret < 0) { 335 335 kfree(nvm); 336 336 return ERR_PTR(ret); ··· 528 528 nvmem_unregister(nvm->non_active); 529 529 nvmem_unregister(nvm->active); 530 530 vfree(nvm->buf); 531 - ida_simple_remove(&nvm_ida, nvm->id); 531 + ida_free(&nvm_ida, nvm->id); 532 532 } 533 533 kfree(nvm); 534 534 }
+13
drivers/thunderbolt/path.c
··· 446 446 return -ETIMEDOUT; 447 447 } 448 448 449 + /** 450 + * tb_path_deactivate_hop() - Deactivate one path in path config space 451 + * @port: Lane or protocol adapter 452 + * @hop_index: HopID of the path to be cleared 453 + * 454 + * This deactivates or clears a single path config space entry at 455 + * @hop_index. Returns %0 in success and negative errno otherwise. 456 + */ 457 + int tb_path_deactivate_hop(struct tb_port *port, int hop_index) 458 + { 459 + return __tb_path_deactivate_hop(port, hop_index, true); 460 + } 461 + 449 462 static void __tb_path_deactivate_hops(struct tb_path *path, int first_hop) 450 463 { 451 464 int i, res;
+14
drivers/thunderbolt/quirks.c
··· 43 43 } 44 44 } 45 45 46 + static void quirk_block_rpm_in_redrive(struct tb_switch *sw) 47 + { 48 + sw->quirks |= QUIRK_KEEP_POWER_IN_DP_REDRIVE; 49 + tb_sw_dbg(sw, "preventing runtime PM in DP redrive mode\n"); 50 + } 51 + 46 52 struct tb_quirk { 47 53 u16 hw_vendor_id; 48 54 u16 hw_device_id; ··· 92 86 quirk_usb3_maximum_bandwidth }, 93 87 { 0x8087, PCI_DEVICE_ID_INTEL_BARLOW_RIDGE_HUB_40G_BRIDGE, 0x0000, 0x0000, 94 88 quirk_usb3_maximum_bandwidth }, 89 + /* 90 + * Block Runtime PM in DP redrive mode for Intel Barlow Ridge host 91 + * controllers. 92 + */ 93 + { 0x8087, PCI_DEVICE_ID_INTEL_BARLOW_RIDGE_HOST_80G_NHI, 0x0000, 0x0000, 94 + quirk_block_rpm_in_redrive }, 95 + { 0x8087, PCI_DEVICE_ID_INTEL_BARLOW_RIDGE_HOST_40G_NHI, 0x0000, 0x0000, 96 + quirk_block_rpm_in_redrive }, 95 97 /* 96 98 * CLx is not supported on AMD USB4 Yellow Carp and Pink Sardine platforms. 97 99 */
+1 -1
drivers/thunderbolt/retimer.c
··· 356 356 kfree(rt); 357 357 } 358 358 359 - struct device_type tb_retimer_type = { 359 + const struct device_type tb_retimer_type = { 360 360 .name = "thunderbolt_retimer", 361 361 .groups = retimer_groups, 362 362 .release = tb_retimer_release,
+121 -19
drivers/thunderbolt/switch.c
··· 676 676 return __tb_port_enable(port, false); 677 677 } 678 678 679 + static int tb_port_reset(struct tb_port *port) 680 + { 681 + if (tb_switch_is_usb4(port->sw)) 682 + return port->cap_usb4 ? usb4_port_reset(port) : 0; 683 + return tb_lc_reset_port(port); 684 + } 685 + 679 686 /* 680 687 * tb_init_port() - initialize a port 681 688 * ··· 778 771 if (max_hopid < 0 || max_hopid > port_max_hopid) 779 772 max_hopid = port_max_hopid; 780 773 781 - return ida_simple_get(ida, min_hopid, max_hopid + 1, GFP_KERNEL); 774 + return ida_alloc_range(ida, min_hopid, max_hopid, GFP_KERNEL); 782 775 } 783 776 784 777 /** ··· 816 809 */ 817 810 void tb_port_release_in_hopid(struct tb_port *port, int hopid) 818 811 { 819 - ida_simple_remove(&port->in_hopids, hopid); 812 + ida_free(&port->in_hopids, hopid); 820 813 } 821 814 822 815 /** ··· 826 819 */ 827 820 void tb_port_release_out_hopid(struct tb_port *port, int hopid) 828 821 { 829 - ida_simple_remove(&port->out_hopids, hopid); 822 + ida_free(&port->out_hopids, hopid); 830 823 } 831 824 832 825 static inline bool tb_switch_is_reachable(const struct tb_switch *parent, ··· 1127 1120 ret = tb_port_set_link_width(port->dual_link_port, 1128 1121 TB_LINK_WIDTH_DUAL); 1129 1122 if (ret) 1130 - goto err_lane0; 1123 + goto err_lane1; 1131 1124 } 1132 1125 1133 1126 /* ··· 1541 1534 regs->__unknown1, regs->__unknown4); 1542 1535 } 1543 1536 1537 + static int tb_switch_reset_host(struct tb_switch *sw) 1538 + { 1539 + if (sw->generation > 1) { 1540 + struct tb_port *port; 1541 + 1542 + tb_switch_for_each_port(sw, port) { 1543 + int i, ret; 1544 + 1545 + /* 1546 + * For lane adapters we issue downstream port 1547 + * reset and clear up path config spaces. 1548 + * 1549 + * For protocol adapters we disable the path and 1550 + * clear path config space one by one (from 8 to 1551 + * Max Input HopID of the adapter). 1552 + */ 1553 + if (tb_port_is_null(port) && !tb_is_upstream_port(port)) { 1554 + ret = tb_port_reset(port); 1555 + if (ret) 1556 + return ret; 1557 + } else if (tb_port_is_usb3_down(port) || 1558 + tb_port_is_usb3_up(port)) { 1559 + tb_usb3_port_enable(port, false); 1560 + } else if (tb_port_is_dpin(port) || 1561 + tb_port_is_dpout(port)) { 1562 + tb_dp_port_enable(port, false); 1563 + } else if (tb_port_is_pcie_down(port) || 1564 + tb_port_is_pcie_up(port)) { 1565 + tb_pci_port_enable(port, false); 1566 + } else { 1567 + continue; 1568 + } 1569 + 1570 + /* Cleanup path config space of protocol adapter */ 1571 + for (i = TB_PATH_MIN_HOPID; 1572 + i <= port->config.max_in_hop_id; i++) { 1573 + ret = tb_path_deactivate_hop(port, i); 1574 + if (ret) 1575 + return ret; 1576 + } 1577 + } 1578 + } else { 1579 + struct tb_cfg_result res; 1580 + 1581 + /* Thunderbolt 1 uses the "reset" config space packet */ 1582 + res.err = tb_sw_write(sw, ((u32 *) &sw->config) + 2, 1583 + TB_CFG_SWITCH, 2, 2); 1584 + if (res.err) 1585 + return res.err; 1586 + res = tb_cfg_reset(sw->tb->ctl, tb_route(sw)); 1587 + if (res.err > 0) 1588 + return -EIO; 1589 + else if (res.err < 0) 1590 + return res.err; 1591 + } 1592 + 1593 + return 0; 1594 + } 1595 + 1596 + static int tb_switch_reset_device(struct tb_switch *sw) 1597 + { 1598 + return tb_port_reset(tb_switch_downstream_port(sw)); 1599 + } 1600 + 1601 + static bool tb_switch_enumerated(struct tb_switch *sw) 1602 + { 1603 + u32 val; 1604 + int ret; 1605 + 1606 + /* 1607 + * Read directly from the hardware because we use this also 1608 + * during system sleep where sw->config.enabled is already set 1609 + * by us. 1610 + */ 1611 + ret = tb_sw_read(sw, &val, TB_CFG_SWITCH, ROUTER_CS_3, 1); 1612 + if (ret) 1613 + return false; 1614 + 1615 + return !!(val & ROUTER_CS_3_V); 1616 + } 1617 + 1544 1618 /** 1545 - * tb_switch_reset() - reconfigure route, enable and send TB_CFG_PKG_RESET 1546 - * @sw: Switch to reset 1619 + * tb_switch_reset() - Perform reset to the router 1620 + * @sw: Router to reset 1547 1621 * 1548 - * Return: Returns 0 on success or an error code on failure. 1622 + * Issues reset to the router @sw. Can be used for any router. For host 1623 + * routers, resets all the downstream ports and cleans up path config 1624 + * spaces accordingly. For device routers issues downstream port reset 1625 + * through the parent router, so as side effect there will be unplug 1626 + * soon after this is finished. 1627 + * 1628 + * If the router is not enumerated does nothing. 1629 + * 1630 + * Returns %0 on success or negative errno in case of failure. 1549 1631 */ 1550 1632 int tb_switch_reset(struct tb_switch *sw) 1551 1633 { 1552 - struct tb_cfg_result res; 1634 + int ret; 1553 1635 1554 - if (sw->generation > 1) 1636 + /* 1637 + * We cannot access the port config spaces unless the router is 1638 + * already enumerated. If the router is not enumerated it is 1639 + * equal to being reset so we can skip that here. 1640 + */ 1641 + if (!tb_switch_enumerated(sw)) 1555 1642 return 0; 1556 1643 1557 - tb_sw_dbg(sw, "resetting switch\n"); 1644 + tb_sw_dbg(sw, "resetting\n"); 1558 1645 1559 - res.err = tb_sw_write(sw, ((u32 *) &sw->config) + 2, 1560 - TB_CFG_SWITCH, 2, 2); 1561 - if (res.err) 1562 - return res.err; 1563 - res = tb_cfg_reset(sw->tb->ctl, tb_route(sw)); 1564 - if (res.err > 0) 1565 - return -EIO; 1566 - return res.err; 1646 + if (tb_route(sw)) 1647 + ret = tb_switch_reset_device(sw); 1648 + else 1649 + ret = tb_switch_reset_host(sw); 1650 + 1651 + if (ret) 1652 + tb_sw_warn(sw, "failed to reset\n"); 1653 + 1654 + return ret; 1567 1655 } 1568 1656 1569 1657 /** ··· 2330 2228 NULL) 2331 2229 }; 2332 2230 2333 - struct device_type tb_switch_type = { 2231 + const struct device_type tb_switch_type = { 2334 2232 .name = "thunderbolt_device", 2335 2233 .release = tb_switch_release, 2336 2234 .uevent = tb_switch_uevent,
+570 -334
drivers/thunderbolt/tb.c
··· 17 17 #include "tunnel.h" 18 18 19 19 #define TB_TIMEOUT 100 /* ms */ 20 + #define TB_RELEASE_BW_TIMEOUT 10000 /* ms */ 20 21 21 22 /* 22 23 * Minimum bandwidth (in Mb/s) that is needed in the single transmitter/receiver ··· 75 74 u8 port; 76 75 bool unplug; 77 76 }; 78 - 79 - static void tb_init_bandwidth_groups(struct tb_cm *tcm) 80 - { 81 - int i; 82 - 83 - for (i = 0; i < ARRAY_SIZE(tcm->groups); i++) { 84 - struct tb_bandwidth_group *group = &tcm->groups[i]; 85 - 86 - group->tb = tcm_to_tb(tcm); 87 - group->index = i + 1; 88 - INIT_LIST_HEAD(&group->ports); 89 - } 90 - } 91 - 92 - static void tb_bandwidth_group_attach_port(struct tb_bandwidth_group *group, 93 - struct tb_port *in) 94 - { 95 - if (!group || WARN_ON(in->group)) 96 - return; 97 - 98 - in->group = group; 99 - list_add_tail(&in->group_list, &group->ports); 100 - 101 - tb_port_dbg(in, "attached to bandwidth group %d\n", group->index); 102 - } 103 - 104 - static struct tb_bandwidth_group *tb_find_free_bandwidth_group(struct tb_cm *tcm) 105 - { 106 - int i; 107 - 108 - for (i = 0; i < ARRAY_SIZE(tcm->groups); i++) { 109 - struct tb_bandwidth_group *group = &tcm->groups[i]; 110 - 111 - if (list_empty(&group->ports)) 112 - return group; 113 - } 114 - 115 - return NULL; 116 - } 117 - 118 - static struct tb_bandwidth_group * 119 - tb_attach_bandwidth_group(struct tb_cm *tcm, struct tb_port *in, 120 - struct tb_port *out) 121 - { 122 - struct tb_bandwidth_group *group; 123 - struct tb_tunnel *tunnel; 124 - 125 - /* 126 - * Find all DP tunnels that go through all the same USB4 links 127 - * as this one. Because we always setup tunnels the same way we 128 - * can just check for the routers at both ends of the tunnels 129 - * and if they are the same we have a match. 130 - */ 131 - list_for_each_entry(tunnel, &tcm->tunnel_list, list) { 132 - if (!tb_tunnel_is_dp(tunnel)) 133 - continue; 134 - 135 - if (tunnel->src_port->sw == in->sw && 136 - tunnel->dst_port->sw == out->sw) { 137 - group = tunnel->src_port->group; 138 - if (group) { 139 - tb_bandwidth_group_attach_port(group, in); 140 - return group; 141 - } 142 - } 143 - } 144 - 145 - /* Pick up next available group then */ 146 - group = tb_find_free_bandwidth_group(tcm); 147 - if (group) 148 - tb_bandwidth_group_attach_port(group, in); 149 - else 150 - tb_port_warn(in, "no available bandwidth groups\n"); 151 - 152 - return group; 153 - } 154 - 155 - static void tb_discover_bandwidth_group(struct tb_cm *tcm, struct tb_port *in, 156 - struct tb_port *out) 157 - { 158 - if (usb4_dp_port_bandwidth_mode_enabled(in)) { 159 - int index, i; 160 - 161 - index = usb4_dp_port_group_id(in); 162 - for (i = 0; i < ARRAY_SIZE(tcm->groups); i++) { 163 - if (tcm->groups[i].index == index) { 164 - tb_bandwidth_group_attach_port(&tcm->groups[i], in); 165 - return; 166 - } 167 - } 168 - } 169 - 170 - tb_attach_bandwidth_group(tcm, in, out); 171 - } 172 - 173 - static void tb_detach_bandwidth_group(struct tb_port *in) 174 - { 175 - struct tb_bandwidth_group *group = in->group; 176 - 177 - if (group) { 178 - in->group = NULL; 179 - list_del_init(&in->group_list); 180 - 181 - tb_port_dbg(in, "detached from bandwidth group %d\n", group->index); 182 - } 183 - } 184 77 185 78 static void tb_handle_hotplug(struct work_struct *work); 186 79 ··· 367 472 } 368 473 } 369 474 370 - static void tb_discover_tunnels(struct tb *tb) 371 - { 372 - struct tb_cm *tcm = tb_priv(tb); 373 - struct tb_tunnel *tunnel; 374 - 375 - tb_switch_discover_tunnels(tb->root_switch, &tcm->tunnel_list, true); 376 - 377 - list_for_each_entry(tunnel, &tcm->tunnel_list, list) { 378 - if (tb_tunnel_is_pci(tunnel)) { 379 - struct tb_switch *parent = tunnel->dst_port->sw; 380 - 381 - while (parent != tunnel->src_port->sw) { 382 - parent->boot = true; 383 - parent = tb_switch_parent(parent); 384 - } 385 - } else if (tb_tunnel_is_dp(tunnel)) { 386 - struct tb_port *in = tunnel->src_port; 387 - struct tb_port *out = tunnel->dst_port; 388 - 389 - /* Keep the domain from powering down */ 390 - pm_runtime_get_sync(&in->sw->dev); 391 - pm_runtime_get_sync(&out->sw->dev); 392 - 393 - tb_discover_bandwidth_group(tcm, in, out); 394 - } 395 - } 396 - } 397 - 398 475 static int tb_port_configure_xdomain(struct tb_port *port, struct tb_xdomain *xd) 399 476 { 400 477 if (tb_switch_is_usb4(port->sw)) ··· 548 681 * Calculates consumed DP bandwidth at @port between path from @src_port 549 682 * to @dst_port. Does not take tunnel starting from @src_port and ending 550 683 * from @src_port into account. 684 + * 685 + * If there is bandwidth reserved for any of the groups between 686 + * @src_port and @dst_port (but not yet used) that is also taken into 687 + * account in the returned consumed bandwidth. 551 688 */ 552 689 static int tb_consumed_dp_bandwidth(struct tb *tb, 553 690 struct tb_port *src_port, ··· 560 689 int *consumed_up, 561 690 int *consumed_down) 562 691 { 692 + int group_reserved[MAX_GROUPS] = {}; 563 693 struct tb_cm *tcm = tb_priv(tb); 564 694 struct tb_tunnel *tunnel; 565 - int ret; 695 + bool downstream; 696 + int i, ret; 566 697 567 698 *consumed_up = *consumed_down = 0; 568 699 ··· 573 700 * their consumed bandwidth from the available. 574 701 */ 575 702 list_for_each_entry(tunnel, &tcm->tunnel_list, list) { 703 + const struct tb_bandwidth_group *group; 576 704 int dp_consumed_up, dp_consumed_down; 577 705 578 706 if (tb_tunnel_is_invalid(tunnel)) ··· 584 710 585 711 if (!tb_tunnel_port_on_path(tunnel, port)) 586 712 continue; 713 + 714 + /* 715 + * Calculate what is reserved for groups crossing the 716 + * same ports only once (as that is reserved for all the 717 + * tunnels in the group). 718 + */ 719 + group = tunnel->src_port->group; 720 + if (group && group->reserved && !group_reserved[group->index]) 721 + group_reserved[group->index] = group->reserved; 587 722 588 723 /* 589 724 * Ignore the DP tunnel between src_port and dst_port ··· 610 727 611 728 *consumed_up += dp_consumed_up; 612 729 *consumed_down += dp_consumed_down; 730 + } 731 + 732 + downstream = tb_port_path_direction_downstream(src_port, dst_port); 733 + for (i = 0; i < ARRAY_SIZE(group_reserved); i++) { 734 + if (downstream) 735 + *consumed_down += group_reserved[i]; 736 + else 737 + *consumed_up += group_reserved[i]; 613 738 } 614 739 615 740 return 0; ··· 1072 1181 * @tb: Domain structure 1073 1182 * @src_port: Source adapter to start the transition 1074 1183 * @dst_port: Destination adapter 1075 - * @requested_up: New lower bandwidth request upstream (Mb/s) 1076 - * @requested_down: New lower bandwidth request downstream (Mb/s) 1077 1184 * @keep_asym: Keep asymmetric link if preferred 1078 1185 * 1079 1186 * Goes over each link from @src_port to @dst_port and tries to ··· 1079 1190 * allows and link asymmetric preference is ignored (if @keep_asym is %false). 1080 1191 */ 1081 1192 static int tb_configure_sym(struct tb *tb, struct tb_port *src_port, 1082 - struct tb_port *dst_port, int requested_up, 1083 - int requested_down, bool keep_asym) 1193 + struct tb_port *dst_port, bool keep_asym) 1084 1194 { 1085 1195 bool clx = false, clx_disabled = false, downstream; 1086 1196 struct tb_switch *sw; ··· 1118 1230 * guard band 10%) as the link was configured asymmetric 1119 1231 * already. 1120 1232 */ 1121 - if (consumed_down + requested_down >= asym_threshold) 1233 + if (consumed_down >= asym_threshold) 1122 1234 continue; 1123 1235 } else { 1124 - if (consumed_up + requested_up >= asym_threshold) 1236 + if (consumed_up >= asym_threshold) 1125 1237 continue; 1126 1238 } 1127 1239 ··· 1194 1306 struct tb_port *host_port; 1195 1307 1196 1308 host_port = tb_port_at(tb_route(sw), tb->root_switch); 1197 - tb_configure_sym(tb, host_port, up, 0, 0, false); 1309 + tb_configure_sym(tb, host_port, up, false); 1198 1310 } 1199 1311 1200 1312 /* Set the link configured */ ··· 1352 1464 } 1353 1465 } 1354 1466 1467 + static void 1468 + tb_recalc_estimated_bandwidth_for_group(struct tb_bandwidth_group *group) 1469 + { 1470 + struct tb_tunnel *first_tunnel; 1471 + struct tb *tb = group->tb; 1472 + struct tb_port *in; 1473 + int ret; 1474 + 1475 + tb_dbg(tb, "re-calculating bandwidth estimation for group %u\n", 1476 + group->index); 1477 + 1478 + first_tunnel = NULL; 1479 + list_for_each_entry(in, &group->ports, group_list) { 1480 + int estimated_bw, estimated_up, estimated_down; 1481 + struct tb_tunnel *tunnel; 1482 + struct tb_port *out; 1483 + 1484 + if (!usb4_dp_port_bandwidth_mode_enabled(in)) 1485 + continue; 1486 + 1487 + tunnel = tb_find_tunnel(tb, TB_TUNNEL_DP, in, NULL); 1488 + if (WARN_ON(!tunnel)) 1489 + break; 1490 + 1491 + if (!first_tunnel) { 1492 + /* 1493 + * Since USB3 bandwidth is shared by all DP 1494 + * tunnels under the host router USB4 port, even 1495 + * if they do not begin from the host router, we 1496 + * can release USB3 bandwidth just once and not 1497 + * for each tunnel separately. 1498 + */ 1499 + first_tunnel = tunnel; 1500 + ret = tb_release_unused_usb3_bandwidth(tb, 1501 + first_tunnel->src_port, first_tunnel->dst_port); 1502 + if (ret) { 1503 + tb_tunnel_warn(tunnel, 1504 + "failed to release unused bandwidth\n"); 1505 + break; 1506 + } 1507 + } 1508 + 1509 + out = tunnel->dst_port; 1510 + ret = tb_available_bandwidth(tb, in, out, &estimated_up, 1511 + &estimated_down, true); 1512 + if (ret) { 1513 + tb_tunnel_warn(tunnel, 1514 + "failed to re-calculate estimated bandwidth\n"); 1515 + break; 1516 + } 1517 + 1518 + /* 1519 + * Estimated bandwidth includes: 1520 + * - already allocated bandwidth for the DP tunnel 1521 + * - available bandwidth along the path 1522 + * - bandwidth allocated for USB 3.x but not used. 1523 + */ 1524 + if (tb_tunnel_direction_downstream(tunnel)) 1525 + estimated_bw = estimated_down; 1526 + else 1527 + estimated_bw = estimated_up; 1528 + 1529 + /* 1530 + * If there is reserved bandwidth for the group that is 1531 + * not yet released we report that too. 1532 + */ 1533 + tb_tunnel_dbg(tunnel, 1534 + "re-calculated estimated bandwidth %u (+ %u reserved) = %u Mb/s\n", 1535 + estimated_bw, group->reserved, 1536 + estimated_bw + group->reserved); 1537 + 1538 + if (usb4_dp_port_set_estimated_bandwidth(in, 1539 + estimated_bw + group->reserved)) 1540 + tb_tunnel_warn(tunnel, 1541 + "failed to update estimated bandwidth\n"); 1542 + } 1543 + 1544 + if (first_tunnel) 1545 + tb_reclaim_usb3_bandwidth(tb, first_tunnel->src_port, 1546 + first_tunnel->dst_port); 1547 + 1548 + tb_dbg(tb, "bandwidth estimation for group %u done\n", group->index); 1549 + } 1550 + 1551 + static void tb_recalc_estimated_bandwidth(struct tb *tb) 1552 + { 1553 + struct tb_cm *tcm = tb_priv(tb); 1554 + int i; 1555 + 1556 + tb_dbg(tb, "bandwidth consumption changed, re-calculating estimated bandwidth\n"); 1557 + 1558 + for (i = 0; i < ARRAY_SIZE(tcm->groups); i++) { 1559 + struct tb_bandwidth_group *group = &tcm->groups[i]; 1560 + 1561 + if (!list_empty(&group->ports)) 1562 + tb_recalc_estimated_bandwidth_for_group(group); 1563 + } 1564 + 1565 + tb_dbg(tb, "bandwidth re-calculation done\n"); 1566 + } 1567 + 1568 + static bool __release_group_bandwidth(struct tb_bandwidth_group *group) 1569 + { 1570 + if (group->reserved) { 1571 + tb_dbg(group->tb, "group %d released total %d Mb/s\n", group->index, 1572 + group->reserved); 1573 + group->reserved = 0; 1574 + return true; 1575 + } 1576 + return false; 1577 + } 1578 + 1579 + static void __configure_group_sym(struct tb_bandwidth_group *group) 1580 + { 1581 + struct tb_tunnel *tunnel; 1582 + struct tb_port *in; 1583 + 1584 + if (list_empty(&group->ports)) 1585 + return; 1586 + 1587 + /* 1588 + * All the tunnels in the group go through the same USB4 links 1589 + * so we find the first one here and pass the IN and OUT 1590 + * adapters to tb_configure_sym() which now transitions the 1591 + * links back to symmetric if bandwidth requirement < asym_threshold. 1592 + * 1593 + * We do this here to avoid unnecessary transitions (for example 1594 + * if the graphics released bandwidth for other tunnel in the 1595 + * same group). 1596 + */ 1597 + in = list_first_entry(&group->ports, struct tb_port, group_list); 1598 + tunnel = tb_find_tunnel(group->tb, TB_TUNNEL_DP, in, NULL); 1599 + if (tunnel) 1600 + tb_configure_sym(group->tb, in, tunnel->dst_port, true); 1601 + } 1602 + 1603 + static void tb_bandwidth_group_release_work(struct work_struct *work) 1604 + { 1605 + struct tb_bandwidth_group *group = 1606 + container_of(work, typeof(*group), release_work.work); 1607 + struct tb *tb = group->tb; 1608 + 1609 + mutex_lock(&tb->lock); 1610 + if (__release_group_bandwidth(group)) 1611 + tb_recalc_estimated_bandwidth(tb); 1612 + __configure_group_sym(group); 1613 + mutex_unlock(&tb->lock); 1614 + } 1615 + 1616 + static void tb_init_bandwidth_groups(struct tb_cm *tcm) 1617 + { 1618 + int i; 1619 + 1620 + for (i = 0; i < ARRAY_SIZE(tcm->groups); i++) { 1621 + struct tb_bandwidth_group *group = &tcm->groups[i]; 1622 + 1623 + group->tb = tcm_to_tb(tcm); 1624 + group->index = i + 1; 1625 + INIT_LIST_HEAD(&group->ports); 1626 + INIT_DELAYED_WORK(&group->release_work, 1627 + tb_bandwidth_group_release_work); 1628 + } 1629 + } 1630 + 1631 + static void tb_bandwidth_group_attach_port(struct tb_bandwidth_group *group, 1632 + struct tb_port *in) 1633 + { 1634 + if (!group || WARN_ON(in->group)) 1635 + return; 1636 + 1637 + in->group = group; 1638 + list_add_tail(&in->group_list, &group->ports); 1639 + 1640 + tb_port_dbg(in, "attached to bandwidth group %d\n", group->index); 1641 + } 1642 + 1643 + static struct tb_bandwidth_group *tb_find_free_bandwidth_group(struct tb_cm *tcm) 1644 + { 1645 + int i; 1646 + 1647 + for (i = 0; i < ARRAY_SIZE(tcm->groups); i++) { 1648 + struct tb_bandwidth_group *group = &tcm->groups[i]; 1649 + 1650 + if (list_empty(&group->ports)) 1651 + return group; 1652 + } 1653 + 1654 + return NULL; 1655 + } 1656 + 1657 + static struct tb_bandwidth_group * 1658 + tb_attach_bandwidth_group(struct tb_cm *tcm, struct tb_port *in, 1659 + struct tb_port *out) 1660 + { 1661 + struct tb_bandwidth_group *group; 1662 + struct tb_tunnel *tunnel; 1663 + 1664 + /* 1665 + * Find all DP tunnels that go through all the same USB4 links 1666 + * as this one. Because we always setup tunnels the same way we 1667 + * can just check for the routers at both ends of the tunnels 1668 + * and if they are the same we have a match. 1669 + */ 1670 + list_for_each_entry(tunnel, &tcm->tunnel_list, list) { 1671 + if (!tb_tunnel_is_dp(tunnel)) 1672 + continue; 1673 + 1674 + if (tunnel->src_port->sw == in->sw && 1675 + tunnel->dst_port->sw == out->sw) { 1676 + group = tunnel->src_port->group; 1677 + if (group) { 1678 + tb_bandwidth_group_attach_port(group, in); 1679 + return group; 1680 + } 1681 + } 1682 + } 1683 + 1684 + /* Pick up next available group then */ 1685 + group = tb_find_free_bandwidth_group(tcm); 1686 + if (group) 1687 + tb_bandwidth_group_attach_port(group, in); 1688 + else 1689 + tb_port_warn(in, "no available bandwidth groups\n"); 1690 + 1691 + return group; 1692 + } 1693 + 1694 + static void tb_discover_bandwidth_group(struct tb_cm *tcm, struct tb_port *in, 1695 + struct tb_port *out) 1696 + { 1697 + if (usb4_dp_port_bandwidth_mode_enabled(in)) { 1698 + int index, i; 1699 + 1700 + index = usb4_dp_port_group_id(in); 1701 + for (i = 0; i < ARRAY_SIZE(tcm->groups); i++) { 1702 + if (tcm->groups[i].index == index) { 1703 + tb_bandwidth_group_attach_port(&tcm->groups[i], in); 1704 + return; 1705 + } 1706 + } 1707 + } 1708 + 1709 + tb_attach_bandwidth_group(tcm, in, out); 1710 + } 1711 + 1712 + static void tb_detach_bandwidth_group(struct tb_port *in) 1713 + { 1714 + struct tb_bandwidth_group *group = in->group; 1715 + 1716 + if (group) { 1717 + in->group = NULL; 1718 + list_del_init(&in->group_list); 1719 + 1720 + tb_port_dbg(in, "detached from bandwidth group %d\n", group->index); 1721 + 1722 + /* No more tunnels so release the reserved bandwidth if any */ 1723 + if (list_empty(&group->ports)) { 1724 + cancel_delayed_work(&group->release_work); 1725 + __release_group_bandwidth(group); 1726 + } 1727 + } 1728 + } 1729 + 1730 + static void tb_discover_tunnels(struct tb *tb) 1731 + { 1732 + struct tb_cm *tcm = tb_priv(tb); 1733 + struct tb_tunnel *tunnel; 1734 + 1735 + tb_switch_discover_tunnels(tb->root_switch, &tcm->tunnel_list, true); 1736 + 1737 + list_for_each_entry(tunnel, &tcm->tunnel_list, list) { 1738 + if (tb_tunnel_is_pci(tunnel)) { 1739 + struct tb_switch *parent = tunnel->dst_port->sw; 1740 + 1741 + while (parent != tunnel->src_port->sw) { 1742 + parent->boot = true; 1743 + parent = tb_switch_parent(parent); 1744 + } 1745 + } else if (tb_tunnel_is_dp(tunnel)) { 1746 + struct tb_port *in = tunnel->src_port; 1747 + struct tb_port *out = tunnel->dst_port; 1748 + 1749 + /* Keep the domain from powering down */ 1750 + pm_runtime_get_sync(&in->sw->dev); 1751 + pm_runtime_get_sync(&out->sw->dev); 1752 + 1753 + tb_discover_bandwidth_group(tcm, in, out); 1754 + } 1755 + } 1756 + } 1757 + 1355 1758 static void tb_deactivate_and_free_tunnel(struct tb_tunnel *tunnel) 1356 1759 { 1357 1760 struct tb_port *src_port, *dst_port; ··· 1670 1491 * If bandwidth on a link is < asym_threshold 1671 1492 * transition the link to symmetric. 1672 1493 */ 1673 - tb_configure_sym(tb, src_port, dst_port, 0, 0, true); 1494 + tb_configure_sym(tb, src_port, dst_port, true); 1674 1495 /* Now we can allow the domain to runtime suspend again */ 1675 1496 pm_runtime_mark_last_busy(&dst_port->sw->dev); 1676 1497 pm_runtime_put_autosuspend(&dst_port->sw->dev); ··· 1784 1605 return tb_find_unused_port(sw, TB_TYPE_PCIE_DOWN); 1785 1606 } 1786 1607 1787 - static void 1788 - tb_recalc_estimated_bandwidth_for_group(struct tb_bandwidth_group *group) 1789 - { 1790 - struct tb_tunnel *first_tunnel; 1791 - struct tb *tb = group->tb; 1792 - struct tb_port *in; 1793 - int ret; 1794 - 1795 - tb_dbg(tb, "re-calculating bandwidth estimation for group %u\n", 1796 - group->index); 1797 - 1798 - first_tunnel = NULL; 1799 - list_for_each_entry(in, &group->ports, group_list) { 1800 - int estimated_bw, estimated_up, estimated_down; 1801 - struct tb_tunnel *tunnel; 1802 - struct tb_port *out; 1803 - 1804 - if (!usb4_dp_port_bandwidth_mode_enabled(in)) 1805 - continue; 1806 - 1807 - tunnel = tb_find_tunnel(tb, TB_TUNNEL_DP, in, NULL); 1808 - if (WARN_ON(!tunnel)) 1809 - break; 1810 - 1811 - if (!first_tunnel) { 1812 - /* 1813 - * Since USB3 bandwidth is shared by all DP 1814 - * tunnels under the host router USB4 port, even 1815 - * if they do not begin from the host router, we 1816 - * can release USB3 bandwidth just once and not 1817 - * for each tunnel separately. 1818 - */ 1819 - first_tunnel = tunnel; 1820 - ret = tb_release_unused_usb3_bandwidth(tb, 1821 - first_tunnel->src_port, first_tunnel->dst_port); 1822 - if (ret) { 1823 - tb_tunnel_warn(tunnel, 1824 - "failed to release unused bandwidth\n"); 1825 - break; 1826 - } 1827 - } 1828 - 1829 - out = tunnel->dst_port; 1830 - ret = tb_available_bandwidth(tb, in, out, &estimated_up, 1831 - &estimated_down, true); 1832 - if (ret) { 1833 - tb_tunnel_warn(tunnel, 1834 - "failed to re-calculate estimated bandwidth\n"); 1835 - break; 1836 - } 1837 - 1838 - /* 1839 - * Estimated bandwidth includes: 1840 - * - already allocated bandwidth for the DP tunnel 1841 - * - available bandwidth along the path 1842 - * - bandwidth allocated for USB 3.x but not used. 1843 - */ 1844 - tb_tunnel_dbg(tunnel, 1845 - "re-calculated estimated bandwidth %u/%u Mb/s\n", 1846 - estimated_up, estimated_down); 1847 - 1848 - if (tb_port_path_direction_downstream(in, out)) 1849 - estimated_bw = estimated_down; 1850 - else 1851 - estimated_bw = estimated_up; 1852 - 1853 - if (usb4_dp_port_set_estimated_bandwidth(in, estimated_bw)) 1854 - tb_tunnel_warn(tunnel, 1855 - "failed to update estimated bandwidth\n"); 1856 - } 1857 - 1858 - if (first_tunnel) 1859 - tb_reclaim_usb3_bandwidth(tb, first_tunnel->src_port, 1860 - first_tunnel->dst_port); 1861 - 1862 - tb_dbg(tb, "bandwidth estimation for group %u done\n", group->index); 1863 - } 1864 - 1865 - static void tb_recalc_estimated_bandwidth(struct tb *tb) 1866 - { 1867 - struct tb_cm *tcm = tb_priv(tb); 1868 - int i; 1869 - 1870 - tb_dbg(tb, "bandwidth consumption changed, re-calculating estimated bandwidth\n"); 1871 - 1872 - for (i = 0; i < ARRAY_SIZE(tcm->groups); i++) { 1873 - struct tb_bandwidth_group *group = &tcm->groups[i]; 1874 - 1875 - if (!list_empty(&group->ports)) 1876 - tb_recalc_estimated_bandwidth_for_group(group); 1877 - } 1878 - 1879 - tb_dbg(tb, "bandwidth re-calculation done\n"); 1880 - } 1881 - 1882 1608 static struct tb_port *tb_find_dp_out(struct tb *tb, struct tb_port *in) 1883 1609 { 1884 1610 struct tb_port *host_port, *port; ··· 1821 1737 return NULL; 1822 1738 } 1823 1739 1824 - static bool tb_tunnel_one_dp(struct tb *tb) 1740 + static bool tb_tunnel_one_dp(struct tb *tb, struct tb_port *in, 1741 + struct tb_port *out) 1825 1742 { 1826 1743 int available_up, available_down, ret, link_nr; 1827 1744 struct tb_cm *tcm = tb_priv(tb); 1828 - struct tb_port *port, *in, *out; 1829 1745 int consumed_up, consumed_down; 1830 1746 struct tb_tunnel *tunnel; 1831 - 1832 - /* 1833 - * Find pair of inactive DP IN and DP OUT adapters and then 1834 - * establish a DP tunnel between them. 1835 - */ 1836 - tb_dbg(tb, "looking for DP IN <-> DP OUT pairs:\n"); 1837 - 1838 - in = NULL; 1839 - out = NULL; 1840 - list_for_each_entry(port, &tcm->dp_resources, list) { 1841 - if (!tb_port_is_dpin(port)) 1842 - continue; 1843 - 1844 - if (tb_port_is_enabled(port)) { 1845 - tb_port_dbg(port, "DP IN in use\n"); 1846 - continue; 1847 - } 1848 - 1849 - in = port; 1850 - tb_port_dbg(in, "DP IN available\n"); 1851 - 1852 - out = tb_find_dp_out(tb, port); 1853 - if (out) 1854 - break; 1855 - } 1856 - 1857 - if (!in) { 1858 - tb_dbg(tb, "no suitable DP IN adapter available, not tunneling\n"); 1859 - return false; 1860 - } 1861 - if (!out) { 1862 - tb_dbg(tb, "no suitable DP OUT adapter available, not tunneling\n"); 1863 - return false; 1864 - } 1865 1747 1866 1748 /* 1867 1749 * This is only applicable to links that are not bonded (so ··· 1889 1839 goto err_free; 1890 1840 } 1891 1841 1892 - list_add_tail(&tunnel->list, &tcm->tunnel_list); 1893 - tb_reclaim_usb3_bandwidth(tb, in, out); 1842 + /* If fail reading tunnel's consumed bandwidth, tear it down */ 1843 + ret = tb_tunnel_consumed_bandwidth(tunnel, &consumed_up, &consumed_down); 1844 + if (ret) 1845 + goto err_deactivate; 1894 1846 1847 + list_add_tail(&tunnel->list, &tcm->tunnel_list); 1848 + 1849 + tb_reclaim_usb3_bandwidth(tb, in, out); 1895 1850 /* 1896 1851 * Transition the links to asymmetric if the consumption exceeds 1897 1852 * the threshold. 1898 1853 */ 1899 - if (!tb_tunnel_consumed_bandwidth(tunnel, &consumed_up, &consumed_down)) 1900 - tb_configure_asym(tb, in, out, consumed_up, consumed_down); 1854 + tb_configure_asym(tb, in, out, consumed_up, consumed_down); 1901 1855 1902 1856 /* Update the domain with the new bandwidth estimation */ 1903 1857 tb_recalc_estimated_bandwidth(tb); ··· 1913 1859 tb_increase_tmu_accuracy(tunnel); 1914 1860 return true; 1915 1861 1862 + err_deactivate: 1863 + tb_tunnel_deactivate(tunnel); 1916 1864 err_free: 1917 1865 tb_tunnel_free(tunnel); 1918 1866 err_reclaim_usb: ··· 1934 1878 1935 1879 static void tb_tunnel_dp(struct tb *tb) 1936 1880 { 1881 + struct tb_cm *tcm = tb_priv(tb); 1882 + struct tb_port *port, *in, *out; 1883 + 1937 1884 if (!tb_acpi_may_tunnel_dp()) { 1938 1885 tb_dbg(tb, "DP tunneling disabled, not creating tunnel\n"); 1939 1886 return; 1940 1887 } 1941 1888 1942 - while (tb_tunnel_one_dp(tb)) 1943 - ; 1889 + /* 1890 + * Find pair of inactive DP IN and DP OUT adapters and then 1891 + * establish a DP tunnel between them. 1892 + */ 1893 + tb_dbg(tb, "looking for DP IN <-> DP OUT pairs:\n"); 1894 + 1895 + in = NULL; 1896 + out = NULL; 1897 + list_for_each_entry(port, &tcm->dp_resources, list) { 1898 + if (!tb_port_is_dpin(port)) 1899 + continue; 1900 + 1901 + if (tb_port_is_enabled(port)) { 1902 + tb_port_dbg(port, "DP IN in use\n"); 1903 + continue; 1904 + } 1905 + 1906 + in = port; 1907 + tb_port_dbg(in, "DP IN available\n"); 1908 + 1909 + out = tb_find_dp_out(tb, port); 1910 + if (out) 1911 + tb_tunnel_one_dp(tb, in, out); 1912 + else 1913 + tb_port_dbg(in, "no suitable DP OUT adapter available, not tunneling\n"); 1914 + } 1915 + 1916 + if (!in) 1917 + tb_dbg(tb, "no suitable DP IN adapter available, not tunneling\n"); 1918 + } 1919 + 1920 + static void tb_enter_redrive(struct tb_port *port) 1921 + { 1922 + struct tb_switch *sw = port->sw; 1923 + 1924 + if (!(sw->quirks & QUIRK_KEEP_POWER_IN_DP_REDRIVE)) 1925 + return; 1926 + 1927 + /* 1928 + * If we get hot-unplug for the DP IN port of the host router 1929 + * and the DP resource is not available anymore it means there 1930 + * is a monitor connected directly to the Type-C port and we are 1931 + * in "redrive" mode. For this to work we cannot enter RTD3 so 1932 + * we bump up the runtime PM reference count here. 1933 + */ 1934 + if (!tb_port_is_dpin(port)) 1935 + return; 1936 + if (tb_route(sw)) 1937 + return; 1938 + if (!tb_switch_query_dp_resource(sw, port)) { 1939 + port->redrive = true; 1940 + pm_runtime_get(&sw->dev); 1941 + tb_port_dbg(port, "enter redrive mode, keeping powered\n"); 1942 + } 1943 + } 1944 + 1945 + static void tb_exit_redrive(struct tb_port *port) 1946 + { 1947 + struct tb_switch *sw = port->sw; 1948 + 1949 + if (!(sw->quirks & QUIRK_KEEP_POWER_IN_DP_REDRIVE)) 1950 + return; 1951 + 1952 + if (!tb_port_is_dpin(port)) 1953 + return; 1954 + if (tb_route(sw)) 1955 + return; 1956 + if (port->redrive && tb_switch_query_dp_resource(sw, port)) { 1957 + port->redrive = false; 1958 + pm_runtime_put(&sw->dev); 1959 + tb_port_dbg(port, "exit redrive mode\n"); 1960 + } 1944 1961 } 1945 1962 1946 1963 static void tb_dp_resource_unavailable(struct tb *tb, struct tb_port *port) ··· 2032 1903 } 2033 1904 2034 1905 tunnel = tb_find_tunnel(tb, TB_TUNNEL_DP, in, out); 2035 - tb_deactivate_and_free_tunnel(tunnel); 1906 + if (tunnel) 1907 + tb_deactivate_and_free_tunnel(tunnel); 1908 + else 1909 + tb_enter_redrive(port); 2036 1910 list_del_init(&port->list); 2037 1911 2038 1912 /* ··· 2062 1930 tb_port_dbg(port, "DP %s resource available after hotplug\n", 2063 1931 tb_port_is_dpin(port) ? "IN" : "OUT"); 2064 1932 list_add_tail(&port->list, &tcm->dp_resources); 1933 + tb_exit_redrive(port); 2065 1934 2066 1935 /* Look for suitable DP IN <-> DP OUT pairs now */ 2067 1936 tb_tunnel_dp(tb); ··· 2376 2243 int allocated_up, allocated_down, available_up, available_down, ret; 2377 2244 int requested_up_corrected, requested_down_corrected, granularity; 2378 2245 int max_up, max_down, max_up_rounded, max_down_rounded; 2246 + struct tb_bandwidth_group *group; 2379 2247 struct tb *tb = tunnel->tb; 2380 2248 struct tb_port *in, *out; 2249 + bool downstream; 2381 2250 2382 2251 ret = tb_tunnel_allocated_bandwidth(tunnel, &allocated_up, &allocated_down); 2383 2252 if (ret) ··· 2405 2270 */ 2406 2271 ret = tb_tunnel_maximum_bandwidth(tunnel, &max_up, &max_down); 2407 2272 if (ret) 2408 - return ret; 2273 + goto fail; 2409 2274 2410 2275 ret = usb4_dp_port_granularity(in); 2411 2276 if (ret < 0) 2412 - return ret; 2277 + goto fail; 2413 2278 granularity = ret; 2414 2279 2415 2280 max_up_rounded = roundup(max_up, granularity); ··· 2439 2304 "bandwidth request too high (%d/%d Mb/s > %d/%d Mb/s)\n", 2440 2305 requested_up_corrected, requested_down_corrected, 2441 2306 max_up_rounded, max_down_rounded); 2442 - return -ENOBUFS; 2307 + ret = -ENOBUFS; 2308 + goto fail; 2443 2309 } 2310 + 2311 + downstream = tb_tunnel_direction_downstream(tunnel); 2312 + group = in->group; 2444 2313 2445 2314 if ((*requested_up >= 0 && requested_up_corrected <= allocated_up) || 2446 2315 (*requested_down >= 0 && requested_down_corrected <= allocated_down)) { 2447 - /* 2448 - * If bandwidth on a link is < asym_threshold transition 2449 - * the link to symmetric. 2450 - */ 2451 - tb_configure_sym(tb, in, out, *requested_up, *requested_down, true); 2452 - /* 2453 - * If requested bandwidth is less or equal than what is 2454 - * currently allocated to that tunnel we simply change 2455 - * the reservation of the tunnel. Since all the tunnels 2456 - * going out from the same USB4 port are in the same 2457 - * group the released bandwidth will be taken into 2458 - * account for the other tunnels automatically below. 2459 - */ 2316 + if (tunnel->bw_mode) { 2317 + int reserved; 2318 + /* 2319 + * If requested bandwidth is less or equal than 2320 + * what is currently allocated to that tunnel we 2321 + * simply change the reservation of the tunnel 2322 + * and add the released bandwidth for the group 2323 + * for the next 10s. Then we release it for 2324 + * others to use. 2325 + */ 2326 + if (downstream) 2327 + reserved = allocated_down - *requested_down; 2328 + else 2329 + reserved = allocated_up - *requested_up; 2330 + 2331 + if (reserved > 0) { 2332 + group->reserved += reserved; 2333 + tb_dbg(tb, "group %d reserved %d total %d Mb/s\n", 2334 + group->index, reserved, group->reserved); 2335 + 2336 + /* 2337 + * If it was not already pending, 2338 + * schedule release now. If it is then 2339 + * postpone it for the next 10s (unless 2340 + * it is already running in which case 2341 + * the 10s already expired and we should 2342 + * give the reserved back to others). 2343 + */ 2344 + mod_delayed_work(system_wq, &group->release_work, 2345 + msecs_to_jiffies(TB_RELEASE_BW_TIMEOUT)); 2346 + } 2347 + } 2348 + 2460 2349 return tb_tunnel_alloc_bandwidth(tunnel, requested_up, 2461 2350 requested_down); 2462 2351 } ··· 2491 2332 */ 2492 2333 ret = tb_release_unused_usb3_bandwidth(tb, in, out); 2493 2334 if (ret) 2494 - return ret; 2335 + goto fail; 2495 2336 2496 2337 /* 2497 2338 * Then go over all tunnels that cross the same USB4 ports (they ··· 2503 2344 if (ret) 2504 2345 goto reclaim; 2505 2346 2506 - tb_tunnel_dbg(tunnel, "bandwidth available for allocation %d/%d Mb/s\n", 2507 - available_up, available_down); 2347 + tb_tunnel_dbg(tunnel, "bandwidth available for allocation %d/%d (+ %u reserved) Mb/s\n", 2348 + available_up, available_down, group->reserved); 2508 2349 2509 - if ((*requested_up >= 0 && available_up >= requested_up_corrected) || 2510 - (*requested_down >= 0 && available_down >= requested_down_corrected)) { 2350 + if ((*requested_up >= 0 && 2351 + available_up + group->reserved >= requested_up_corrected) || 2352 + (*requested_down >= 0 && 2353 + available_down + group->reserved >= requested_down_corrected)) { 2354 + int released = 0; 2355 + 2511 2356 /* 2512 2357 * If bandwidth on a link is >= asym_threshold 2513 2358 * transition the link to asymmetric. ··· 2519 2356 ret = tb_configure_asym(tb, in, out, *requested_up, 2520 2357 *requested_down); 2521 2358 if (ret) { 2522 - tb_configure_sym(tb, in, out, 0, 0, true); 2523 - return ret; 2359 + tb_configure_sym(tb, in, out, true); 2360 + goto fail; 2524 2361 } 2525 2362 2526 2363 ret = tb_tunnel_alloc_bandwidth(tunnel, requested_up, 2527 2364 requested_down); 2528 2365 if (ret) { 2529 2366 tb_tunnel_warn(tunnel, "failed to allocate bandwidth\n"); 2530 - tb_configure_sym(tb, in, out, 0, 0, true); 2367 + tb_configure_sym(tb, in, out, true); 2368 + } 2369 + 2370 + if (downstream) { 2371 + if (*requested_down > available_down) 2372 + released = *requested_down - available_down; 2373 + } else { 2374 + if (*requested_up > available_up) 2375 + released = *requested_up - available_up; 2376 + } 2377 + if (released) { 2378 + group->reserved -= released; 2379 + tb_dbg(tb, "group %d released %d total %d Mb/s\n", 2380 + group->index, released, group->reserved); 2531 2381 } 2532 2382 } else { 2533 2383 ret = -ENOBUFS; ··· 2548 2372 2549 2373 reclaim: 2550 2374 tb_reclaim_usb3_bandwidth(tb, in, out); 2375 + fail: 2376 + if (ret && ret != -ENODEV) { 2377 + /* 2378 + * Write back the same allocated (so no change), this 2379 + * makes the DPTX request fail on graphics side. 2380 + */ 2381 + tb_tunnel_dbg(tunnel, 2382 + "failing the request by rewriting allocated %d/%d Mb/s\n", 2383 + allocated_up, allocated_down); 2384 + tb_tunnel_alloc_bandwidth(tunnel, &allocated_up, &allocated_down); 2385 + } 2386 + 2551 2387 return ret; 2552 2388 } 2553 2389 ··· 2567 2379 { 2568 2380 struct tb_hotplug_event *ev = container_of(work, typeof(*ev), work); 2569 2381 int requested_bw, requested_up, requested_down, ret; 2570 - struct tb_port *in, *out; 2571 2382 struct tb_tunnel *tunnel; 2572 2383 struct tb *tb = ev->tb; 2573 2384 struct tb_cm *tcm = tb_priv(tb); 2574 2385 struct tb_switch *sw; 2386 + struct tb_port *in; 2575 2387 2576 2388 pm_runtime_get_sync(&tb->dev); 2577 2389 ··· 2594 2406 2595 2407 tb_port_dbg(in, "handling bandwidth allocation request\n"); 2596 2408 2597 - if (!usb4_dp_port_bandwidth_mode_enabled(in)) { 2598 - tb_port_warn(in, "bandwidth allocation mode not enabled\n"); 2599 - goto put_sw; 2600 - } 2601 - 2602 - ret = usb4_dp_port_requested_bandwidth(in); 2603 - if (ret < 0) { 2604 - if (ret == -ENODATA) 2605 - tb_port_dbg(in, "no bandwidth request active\n"); 2606 - else 2607 - tb_port_warn(in, "failed to read requested bandwidth\n"); 2608 - goto put_sw; 2609 - } 2610 - requested_bw = ret; 2611 - 2612 - tb_port_dbg(in, "requested bandwidth %d Mb/s\n", requested_bw); 2613 - 2614 2409 tunnel = tb_find_tunnel(tb, TB_TUNNEL_DP, in, NULL); 2615 2410 if (!tunnel) { 2616 2411 tb_port_warn(in, "failed to find tunnel\n"); 2617 2412 goto put_sw; 2618 2413 } 2619 2414 2620 - out = tunnel->dst_port; 2415 + if (!usb4_dp_port_bandwidth_mode_enabled(in)) { 2416 + if (tunnel->bw_mode) { 2417 + /* 2418 + * Reset the tunnel back to use the legacy 2419 + * allocation. 2420 + */ 2421 + tunnel->bw_mode = false; 2422 + tb_port_dbg(in, "DPTX disabled bandwidth allocation mode\n"); 2423 + } else { 2424 + tb_port_warn(in, "bandwidth allocation mode not enabled\n"); 2425 + } 2426 + goto put_sw; 2427 + } 2621 2428 2622 - if (tb_port_path_direction_downstream(in, out)) { 2429 + ret = usb4_dp_port_requested_bandwidth(in); 2430 + if (ret < 0) { 2431 + if (ret == -ENODATA) { 2432 + /* 2433 + * There is no request active so this means the 2434 + * BW allocation mode was enabled from graphics 2435 + * side. At this point we know that the graphics 2436 + * driver has read the DRPX capabilities so we 2437 + * can offer an better bandwidth estimatation. 2438 + */ 2439 + tb_port_dbg(in, "DPTX enabled bandwidth allocation mode, updating estimated bandwidth\n"); 2440 + tb_recalc_estimated_bandwidth(tb); 2441 + } else { 2442 + tb_port_warn(in, "failed to read requested bandwidth\n"); 2443 + } 2444 + goto put_sw; 2445 + } 2446 + requested_bw = ret; 2447 + 2448 + tb_port_dbg(in, "requested bandwidth %d Mb/s\n", requested_bw); 2449 + 2450 + if (tb_tunnel_direction_downstream(tunnel)) { 2623 2451 requested_up = -1; 2624 2452 requested_down = requested_bw; 2625 2453 } else { ··· 2764 2560 tcm->hotplug_active = false; /* signal tb_handle_hotplug to quit */ 2765 2561 } 2766 2562 2563 + static void tb_deinit(struct tb *tb) 2564 + { 2565 + struct tb_cm *tcm = tb_priv(tb); 2566 + int i; 2567 + 2568 + /* Cancel all the release bandwidth workers */ 2569 + for (i = 0; i < ARRAY_SIZE(tcm->groups); i++) 2570 + cancel_delayed_work_sync(&tcm->groups[i].release_work); 2571 + } 2572 + 2767 2573 static int tb_scan_finalize_switch(struct device *dev, void *data) 2768 2574 { 2769 2575 if (tb_is_switch(dev)) { ··· 2795 2581 return 0; 2796 2582 } 2797 2583 2798 - static int tb_start(struct tb *tb) 2584 + static int tb_start(struct tb *tb, bool reset) 2799 2585 { 2800 2586 struct tb_cm *tcm = tb_priv(tb); 2587 + bool discover = true; 2801 2588 int ret; 2802 2589 2803 2590 tb->root_switch = tb_switch_alloc(tb, &tb->dev, 0); ··· 2837 2622 tb_switch_tmu_configure(tb->root_switch, TB_SWITCH_TMU_MODE_LOWRES); 2838 2623 /* Enable TMU if it is off */ 2839 2624 tb_switch_tmu_enable(tb->root_switch); 2840 - /* Full scan to discover devices added before the driver was loaded. */ 2841 - tb_scan_switch(tb->root_switch); 2842 - /* Find out tunnels created by the boot firmware */ 2843 - tb_discover_tunnels(tb); 2844 - /* Add DP resources from the DP tunnels created by the boot firmware */ 2845 - tb_discover_dp_resources(tb); 2625 + 2626 + /* 2627 + * Boot firmware might have created tunnels of its own. Since we 2628 + * cannot be sure they are usable for us, tear them down and 2629 + * reset the ports to handle it as new hotplug for USB4 v1 2630 + * routers (for USB4 v2 and beyond we already do host reset). 2631 + */ 2632 + if (reset && tb_switch_is_usb4(tb->root_switch)) { 2633 + discover = false; 2634 + if (usb4_switch_version(tb->root_switch) == 1) 2635 + tb_switch_reset(tb->root_switch); 2636 + } 2637 + 2638 + if (discover) { 2639 + /* Full scan to discover devices added before the driver was loaded. */ 2640 + tb_scan_switch(tb->root_switch); 2641 + /* Find out tunnels created by the boot firmware */ 2642 + tb_discover_tunnels(tb); 2643 + /* Add DP resources from the DP tunnels created by the boot firmware */ 2644 + tb_discover_dp_resources(tb); 2645 + } 2646 + 2846 2647 /* 2847 2648 * If the boot firmware did not create USB 3.x tunnels create them 2848 2649 * now for the whole topology. ··· 2929 2698 2930 2699 tb_dbg(tb, "resuming...\n"); 2931 2700 2932 - /* remove any pci devices the firmware might have setup */ 2933 - tb_switch_reset(tb->root_switch); 2701 + /* 2702 + * For non-USB4 hosts (Apple systems) remove any PCIe devices 2703 + * the firmware might have setup. 2704 + */ 2705 + if (!tb_switch_is_usb4(tb->root_switch)) 2706 + tb_switch_reset(tb->root_switch); 2934 2707 2935 2708 tb_switch_resume(tb->root_switch); 2936 2709 tb_free_invalid_tunnels(tb); ··· 3082 2847 static const struct tb_cm_ops tb_cm_ops = { 3083 2848 .start = tb_start, 3084 2849 .stop = tb_stop, 2850 + .deinit = tb_deinit, 3085 2851 .suspend_noirq = tb_suspend_noirq, 3086 2852 .resume_noirq = tb_resume_noirq, 3087 2853 .freeze_noirq = tb_freeze_noirq,
+23 -6
drivers/thunderbolt/tb.h
··· 23 23 #define QUIRK_FORCE_POWER_LINK_CONTROLLER BIT(0) 24 24 /* Disable CLx if not supported */ 25 25 #define QUIRK_NO_CLX BIT(1) 26 + /* Need to keep power on while USB4 port is in redrive mode */ 27 + #define QUIRK_KEEP_POWER_IN_DP_REDRIVE BIT(2) 26 28 27 29 /** 28 30 * struct tb_nvm - Structure holding NVM information ··· 219 217 * @tb: Pointer to the domain the group belongs to 220 218 * @index: Index of the group (aka Group_ID). Valid values %1-%7 221 219 * @ports: DP IN adapters belonging to this group are linked here 220 + * @reserved: Bandwidth released by one tunnel in the group, available 221 + * to others. This is reported as part of estimated_bw for 222 + * the group. 223 + * @release_work: Worker to release the @reserved if it is not used by 224 + * any of the tunnels. 222 225 * 223 226 * Any tunnel that requires isochronous bandwidth (that's DP for now) is 224 227 * attached to a bandwidth group. All tunnels going through the same ··· 234 227 struct tb *tb; 235 228 int index; 236 229 struct list_head ports; 230 + int reserved; 231 + struct delayed_work release_work; 237 232 }; 238 233 239 234 /** ··· 267 258 * @group_list: The adapter is linked to the group's list of ports through this 268 259 * @max_bw: Maximum possible bandwidth through this adapter if set to 269 260 * non-zero. 261 + * @redrive: For DP IN, if true the adapter is in redrive mode. 270 262 * 271 263 * In USB4 terminology this structure represents an adapter (protocol or 272 264 * lane adapter). ··· 296 286 struct tb_bandwidth_group *group; 297 287 struct list_head group_list; 298 288 unsigned int max_bw; 289 + bool redrive; 299 290 }; 300 291 301 292 /** ··· 463 452 * ICM to send driver ready message to the firmware. 464 453 * @start: Starts the domain 465 454 * @stop: Stops the domain 455 + * @deinit: Perform any cleanup after the domain is stopped but before 456 + * it is unregistered. Called without @tb->lock taken. Optional. 466 457 * @suspend_noirq: Connection manager specific suspend_noirq 467 458 * @resume_noirq: Connection manager specific resume_noirq 468 459 * @suspend: Connection manager specific suspend ··· 496 483 */ 497 484 struct tb_cm_ops { 498 485 int (*driver_ready)(struct tb *tb); 499 - int (*start)(struct tb *tb); 486 + int (*start)(struct tb *tb, bool reset); 500 487 void (*stop)(struct tb *tb); 488 + void (*deinit)(struct tb *tb); 501 489 int (*suspend_noirq)(struct tb *tb); 502 490 int (*resume_noirq)(struct tb *tb); 503 491 int (*suspend)(struct tb *tb); ··· 749 735 struct tb *icm_probe(struct tb_nhi *nhi); 750 736 struct tb *tb_probe(struct tb_nhi *nhi); 751 737 752 - extern struct device_type tb_domain_type; 753 - extern struct device_type tb_retimer_type; 754 - extern struct device_type tb_switch_type; 755 - extern struct device_type usb4_port_device_type; 738 + extern const struct device_type tb_domain_type; 739 + extern const struct device_type tb_retimer_type; 740 + extern const struct device_type tb_switch_type; 741 + extern const struct device_type usb4_port_device_type; 756 742 757 743 int tb_domain_init(void); 758 744 void tb_domain_exit(void); ··· 760 746 void tb_xdomain_exit(void); 761 747 762 748 struct tb *tb_domain_alloc(struct tb_nhi *nhi, int timeout_msec, size_t privsize); 763 - int tb_domain_add(struct tb *tb); 749 + int tb_domain_add(struct tb *tb, bool reset); 764 750 void tb_domain_remove(struct tb *tb); 765 751 int tb_domain_suspend_noirq(struct tb *tb); 766 752 int tb_domain_resume_noirq(struct tb *tb); ··· 1164 1150 void tb_path_free(struct tb_path *path); 1165 1151 int tb_path_activate(struct tb_path *path); 1166 1152 void tb_path_deactivate(struct tb_path *path); 1153 + int tb_path_deactivate_hop(struct tb_port *port, int hop_index); 1167 1154 bool tb_path_is_invalid(struct tb_path *path); 1168 1155 bool tb_path_port_on_path(const struct tb_path *path, 1169 1156 const struct tb_port *port); ··· 1184 1169 int tb_drom_read_uid_only(struct tb_switch *sw, u64 *uid); 1185 1170 1186 1171 int tb_lc_read_uuid(struct tb_switch *sw, u32 *uuid); 1172 + int tb_lc_reset_port(struct tb_port *port); 1187 1173 int tb_lc_configure_port(struct tb_port *port); 1188 1174 void tb_lc_unconfigure_port(struct tb_port *port); 1189 1175 int tb_lc_configure_xdomain(struct tb_port *port); ··· 1317 1301 1318 1302 int usb4_port_unlock(struct tb_port *port); 1319 1303 int usb4_port_hotplug_enable(struct tb_port *port); 1304 + int usb4_port_reset(struct tb_port *port); 1320 1305 int usb4_port_configure(struct tb_port *port); 1321 1306 void usb4_port_unconfigure(struct tb_port *port); 1322 1307 int usb4_port_configure_xdomain(struct tb_port *port, struct tb_xdomain *xd);
+6
drivers/thunderbolt/tb_regs.h
··· 194 194 #define USB4_VERSION_MAJOR_MASK GENMASK(7, 5) 195 195 196 196 #define ROUTER_CS_1 0x01 197 + #define ROUTER_CS_3 0x03 198 + #define ROUTER_CS_3_V BIT(31) 197 199 #define ROUTER_CS_4 0x04 198 200 /* Used with the router cmuv field */ 199 201 #define ROUTER_CS_4_CMUV_V1 0x10 ··· 391 389 #define PORT_CS_18_CSA BIT(22) 392 390 #define PORT_CS_18_TIP BIT(24) 393 391 #define PORT_CS_19 0x13 392 + #define PORT_CS_19_DPR BIT(0) 394 393 #define PORT_CS_19_PC BIT(3) 395 394 #define PORT_CS_19_PID BIT(4) 396 395 #define PORT_CS_19_WOC BIT(16) ··· 587 584 #define TB_LC_POWER 0x740 588 585 589 586 /* Link controller registers */ 587 + #define TB_LC_PORT_MODE 0x26 588 + #define TB_LC_PORT_MODE_DPR BIT(0) 589 + 590 590 #define TB_LC_CS_42 0x2a 591 591 #define TB_LC_CS_42_USB_PLUGGED BIT(31) 592 592
+188
drivers/thunderbolt/trace.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + /* 3 + * Thunderbolt tracing support 4 + * 5 + * Copyright (C) 2024, Intel Corporation 6 + * Author: Mika Westerberg <mika.westerberg@linux.intel.com> 7 + * Gil Fine <gil.fine@intel.com> 8 + */ 9 + 10 + #undef TRACE_SYSTEM 11 + #define TRACE_SYSTEM thunderbolt 12 + 13 + #if !defined(TB_TRACE_H_) || defined(TRACE_HEADER_MULTI_READ) 14 + #define TB_TRACE_H_ 15 + 16 + #include <linux/trace_seq.h> 17 + #include <linux/tracepoint.h> 18 + 19 + #include "tb_msgs.h" 20 + 21 + #define tb_cfg_type_name(type) { type, #type } 22 + #define show_type_name(val) \ 23 + __print_symbolic(val, \ 24 + tb_cfg_type_name(TB_CFG_PKG_READ), \ 25 + tb_cfg_type_name(TB_CFG_PKG_WRITE), \ 26 + tb_cfg_type_name(TB_CFG_PKG_ERROR), \ 27 + tb_cfg_type_name(TB_CFG_PKG_NOTIFY_ACK), \ 28 + tb_cfg_type_name(TB_CFG_PKG_EVENT), \ 29 + tb_cfg_type_name(TB_CFG_PKG_XDOMAIN_REQ), \ 30 + tb_cfg_type_name(TB_CFG_PKG_XDOMAIN_RESP), \ 31 + tb_cfg_type_name(TB_CFG_PKG_OVERRIDE), \ 32 + tb_cfg_type_name(TB_CFG_PKG_RESET), \ 33 + tb_cfg_type_name(TB_CFG_PKG_ICM_EVENT), \ 34 + tb_cfg_type_name(TB_CFG_PKG_ICM_CMD), \ 35 + tb_cfg_type_name(TB_CFG_PKG_ICM_RESP)) 36 + 37 + #ifndef TB_TRACE_HELPERS 38 + #define TB_TRACE_HELPERS 39 + static inline const char *show_data_read_write(struct trace_seq *p, 40 + const u32 *data) 41 + { 42 + const struct cfg_read_pkg *msg = (const struct cfg_read_pkg *)data; 43 + const char *ret = trace_seq_buffer_ptr(p); 44 + 45 + trace_seq_printf(p, "offset=%#x, len=%u, port=%d, config=%#x, seq=%d, ", 46 + msg->addr.offset, msg->addr.length, msg->addr.port, 47 + msg->addr.space, msg->addr.seq); 48 + 49 + return ret; 50 + } 51 + 52 + static inline const char *show_data_error(struct trace_seq *p, const u32 *data) 53 + { 54 + const struct cfg_error_pkg *msg = (const struct cfg_error_pkg *)data; 55 + const char *ret = trace_seq_buffer_ptr(p); 56 + 57 + trace_seq_printf(p, "error=%#x, port=%d, plug=%#x, ", msg->error, 58 + msg->port, msg->pg); 59 + 60 + return ret; 61 + } 62 + 63 + static inline const char *show_data_event(struct trace_seq *p, const u32 *data) 64 + { 65 + const struct cfg_event_pkg *msg = (const struct cfg_event_pkg *)data; 66 + const char *ret = trace_seq_buffer_ptr(p); 67 + 68 + trace_seq_printf(p, "port=%d, unplug=%#x, ", msg->port, msg->unplug); 69 + 70 + return ret; 71 + } 72 + 73 + static inline const char *show_route(struct trace_seq *p, const u32 *data) 74 + { 75 + const struct tb_cfg_header *header = (const struct tb_cfg_header *)data; 76 + const char *ret = trace_seq_buffer_ptr(p); 77 + 78 + trace_seq_printf(p, "route=%llx, ", tb_cfg_get_route(header)); 79 + 80 + return ret; 81 + } 82 + 83 + static inline const char *show_data(struct trace_seq *p, u8 type, 84 + const u32 *data, u32 length) 85 + { 86 + const char *ret = trace_seq_buffer_ptr(p); 87 + const char *prefix = ""; 88 + int i; 89 + 90 + show_route(p, data); 91 + 92 + switch (type) { 93 + case TB_CFG_PKG_READ: 94 + case TB_CFG_PKG_WRITE: 95 + show_data_read_write(p, data); 96 + break; 97 + 98 + case TB_CFG_PKG_ERROR: 99 + show_data_error(p, data); 100 + break; 101 + 102 + case TB_CFG_PKG_EVENT: 103 + show_data_event(p, data); 104 + break; 105 + 106 + default: 107 + break; 108 + } 109 + 110 + trace_seq_printf(p, "data=["); 111 + for (i = 0; i < length; i++) { 112 + trace_seq_printf(p, "%s0x%08x", prefix, data[i]); 113 + prefix = ", "; 114 + } 115 + trace_seq_printf(p, "]"); 116 + trace_seq_putc(p, 0); 117 + 118 + return ret; 119 + } 120 + #endif 121 + 122 + DECLARE_EVENT_CLASS(tb_raw, 123 + TP_PROTO(int index, u8 type, const void *data, size_t size), 124 + TP_ARGS(index, type, data, size), 125 + TP_STRUCT__entry( 126 + __field(int, index) 127 + __field(u8, type) 128 + __field(size_t, size) 129 + __dynamic_array(u32, data, size / 4) 130 + ), 131 + TP_fast_assign( 132 + __entry->index = index; 133 + __entry->type = type; 134 + __entry->size = size / 4; 135 + memcpy(__get_dynamic_array(data), data, size); 136 + ), 137 + TP_printk("type=%s, size=%zd, domain=%d, %s", 138 + show_type_name(__entry->type), __entry->size, __entry->index, 139 + show_data(p, __entry->type, __get_dynamic_array(data), 140 + __entry->size) 141 + ) 142 + ); 143 + 144 + DEFINE_EVENT(tb_raw, tb_tx, 145 + TP_PROTO(int index, u8 type, const void *data, size_t size), 146 + TP_ARGS(index, type, data, size) 147 + ); 148 + 149 + DEFINE_EVENT(tb_raw, tb_event, 150 + TP_PROTO(int index, u8 type, const void *data, size_t size), 151 + TP_ARGS(index, type, data, size) 152 + ); 153 + 154 + TRACE_EVENT(tb_rx, 155 + TP_PROTO(int index, u8 type, const void *data, size_t size, bool dropped), 156 + TP_ARGS(index, type, data, size, dropped), 157 + TP_STRUCT__entry( 158 + __field(int, index) 159 + __field(u8, type) 160 + __field(size_t, size) 161 + __dynamic_array(u32, data, size / 4) 162 + __field(bool, dropped) 163 + ), 164 + TP_fast_assign( 165 + __entry->index = index; 166 + __entry->type = type; 167 + __entry->size = size / 4; 168 + memcpy(__get_dynamic_array(data), data, size); 169 + __entry->dropped = dropped; 170 + ), 171 + TP_printk("type=%s, dropped=%u, size=%zd, domain=%d, %s", 172 + show_type_name(__entry->type), __entry->dropped, 173 + __entry->size, __entry->index, 174 + show_data(p, __entry->type, __get_dynamic_array(data), 175 + __entry->size) 176 + ) 177 + ); 178 + 179 + #endif /* TB_TRACE_H_ */ 180 + 181 + #undef TRACE_INCLUDE_PATH 182 + #define TRACE_INCLUDE_PATH . 183 + 184 + #undef TRACE_INCLUDE_FILE 185 + #define TRACE_INCLUDE_FILE trace 186 + 187 + /* This part must be outside protection */ 188 + #include <trace/define_trace.h>
+40 -56
drivers/thunderbolt/tunnel.c
··· 706 706 "DP OUT maximum supported bandwidth %u Mb/s x%u = %u Mb/s\n", 707 707 out_rate, out_lanes, bw); 708 708 709 - if (tb_port_path_direction_downstream(in, out)) 709 + if (tb_tunnel_direction_downstream(tunnel)) 710 710 max_bw = tunnel->max_down; 711 711 else 712 712 max_bw = tunnel->max_up; ··· 831 831 * max_up/down fields. For discovery we just read what the 832 832 * estimation was set to. 833 833 */ 834 - if (tb_port_path_direction_downstream(in, out)) 834 + if (tb_tunnel_direction_downstream(tunnel)) 835 835 estimated_bw = tunnel->max_down; 836 836 else 837 837 estimated_bw = tunnel->max_up; ··· 926 926 return 0; 927 927 } 928 928 929 - /* max_bw is rounded up to next granularity */ 929 + /** 930 + * tb_dp_bandwidth_mode_maximum_bandwidth() - Maximum possible bandwidth 931 + * @tunnel: DP tunnel to check 932 + * @max_bw_rounded: Maximum bandwidth in Mb/s rounded up to the next granularity 933 + * 934 + * Returns maximum possible bandwidth for this tunnel in Mb/s. 935 + */ 930 936 static int tb_dp_bandwidth_mode_maximum_bandwidth(struct tb_tunnel *tunnel, 931 - int *max_bw) 937 + int *max_bw_rounded) 932 938 { 933 939 struct tb_port *in = tunnel->src_port; 934 - int ret, rate, lanes, nrd_bw; 940 + int ret, rate, lanes, max_bw; 935 941 u32 cap; 936 942 937 943 /* ··· 953 947 return ret; 954 948 955 949 rate = tb_dp_cap_get_rate_ext(cap); 956 - if (tb_dp_is_uhbr_rate(rate)) { 957 - /* 958 - * When UHBR is used there is no reduction in lanes so 959 - * we can use this directly. 960 - */ 961 - lanes = tb_dp_cap_get_lanes(cap); 962 - } else { 963 - /* 964 - * If there is no UHBR supported then check the 965 - * non-reduced rate and lanes. 966 - */ 967 - ret = usb4_dp_port_nrd(in, &rate, &lanes); 968 - if (ret) 969 - return ret; 970 - } 950 + lanes = tb_dp_cap_get_lanes(cap); 971 951 972 - nrd_bw = tb_dp_bandwidth(rate, lanes); 952 + max_bw = tb_dp_bandwidth(rate, lanes); 973 953 974 - if (max_bw) { 954 + if (max_bw_rounded) { 975 955 ret = usb4_dp_port_granularity(in); 976 956 if (ret < 0) 977 957 return ret; 978 - *max_bw = roundup(nrd_bw, ret); 958 + *max_bw_rounded = roundup(max_bw, ret); 979 959 } 980 960 981 - return nrd_bw; 961 + return max_bw; 982 962 } 983 963 984 964 static int tb_dp_bandwidth_mode_consumed_bandwidth(struct tb_tunnel *tunnel, 985 965 int *consumed_up, 986 966 int *consumed_down) 987 967 { 988 - struct tb_port *out = tunnel->dst_port; 989 968 struct tb_port *in = tunnel->src_port; 990 - int ret, allocated_bw, max_bw; 969 + int ret, allocated_bw, max_bw_rounded; 991 970 992 971 if (!usb4_dp_port_bandwidth_mode_enabled(in)) 993 972 return -EOPNOTSUPP; ··· 986 995 return ret; 987 996 allocated_bw = ret; 988 997 989 - ret = tb_dp_bandwidth_mode_maximum_bandwidth(tunnel, &max_bw); 998 + ret = tb_dp_bandwidth_mode_maximum_bandwidth(tunnel, &max_bw_rounded); 990 999 if (ret < 0) 991 1000 return ret; 992 - if (allocated_bw == max_bw) 1001 + if (allocated_bw == max_bw_rounded) 993 1002 allocated_bw = ret; 994 1003 995 - if (tb_port_path_direction_downstream(in, out)) { 1004 + if (tb_tunnel_direction_downstream(tunnel)) { 996 1005 *consumed_up = 0; 997 1006 *consumed_down = allocated_bw; 998 1007 } else { ··· 1006 1015 static int tb_dp_allocated_bandwidth(struct tb_tunnel *tunnel, int *allocated_up, 1007 1016 int *allocated_down) 1008 1017 { 1009 - struct tb_port *out = tunnel->dst_port; 1010 1018 struct tb_port *in = tunnel->src_port; 1011 1019 1012 1020 /* ··· 1013 1023 * Otherwise we read it from the DPRX. 1014 1024 */ 1015 1025 if (usb4_dp_port_bandwidth_mode_enabled(in) && tunnel->bw_mode) { 1016 - int ret, allocated_bw, max_bw; 1026 + int ret, allocated_bw, max_bw_rounded; 1017 1027 1018 1028 ret = usb4_dp_port_allocated_bandwidth(in); 1019 1029 if (ret < 0) 1020 1030 return ret; 1021 1031 allocated_bw = ret; 1022 1032 1023 - ret = tb_dp_bandwidth_mode_maximum_bandwidth(tunnel, &max_bw); 1033 + ret = tb_dp_bandwidth_mode_maximum_bandwidth(tunnel, 1034 + &max_bw_rounded); 1024 1035 if (ret < 0) 1025 1036 return ret; 1026 - if (allocated_bw == max_bw) 1037 + if (allocated_bw == max_bw_rounded) 1027 1038 allocated_bw = ret; 1028 1039 1029 - if (tb_port_path_direction_downstream(in, out)) { 1040 + if (tb_tunnel_direction_downstream(tunnel)) { 1030 1041 *allocated_up = 0; 1031 1042 *allocated_down = allocated_bw; 1032 1043 } else { ··· 1044 1053 static int tb_dp_alloc_bandwidth(struct tb_tunnel *tunnel, int *alloc_up, 1045 1054 int *alloc_down) 1046 1055 { 1047 - struct tb_port *out = tunnel->dst_port; 1048 1056 struct tb_port *in = tunnel->src_port; 1049 - int max_bw, ret, tmp; 1057 + int max_bw_rounded, ret, tmp; 1050 1058 1051 1059 if (!usb4_dp_port_bandwidth_mode_enabled(in)) 1052 1060 return -EOPNOTSUPP; 1053 1061 1054 - ret = tb_dp_bandwidth_mode_maximum_bandwidth(tunnel, &max_bw); 1062 + ret = tb_dp_bandwidth_mode_maximum_bandwidth(tunnel, &max_bw_rounded); 1055 1063 if (ret < 0) 1056 1064 return ret; 1057 1065 1058 - if (tb_port_path_direction_downstream(in, out)) { 1059 - tmp = min(*alloc_down, max_bw); 1066 + if (tb_tunnel_direction_downstream(tunnel)) { 1067 + tmp = min(*alloc_down, max_bw_rounded); 1060 1068 ret = usb4_dp_port_allocate_bandwidth(in, tmp); 1061 1069 if (ret) 1062 1070 return ret; 1063 1071 *alloc_down = tmp; 1064 1072 *alloc_up = 0; 1065 1073 } else { 1066 - tmp = min(*alloc_up, max_bw); 1074 + tmp = min(*alloc_up, max_bw_rounded); 1067 1075 ret = usb4_dp_port_allocate_bandwidth(in, tmp); 1068 1076 if (ret) 1069 1077 return ret; ··· 1140 1150 static int tb_dp_maximum_bandwidth(struct tb_tunnel *tunnel, int *max_up, 1141 1151 int *max_down) 1142 1152 { 1143 - struct tb_port *in = tunnel->src_port; 1144 1153 int ret; 1145 1154 1146 - if (!usb4_dp_port_bandwidth_mode_enabled(in)) 1155 + if (!usb4_dp_port_bandwidth_mode_enabled(tunnel->src_port)) 1147 1156 return -EOPNOTSUPP; 1148 1157 1149 1158 ret = tb_dp_bandwidth_mode_maximum_bandwidth(tunnel, NULL); 1150 1159 if (ret < 0) 1151 1160 return ret; 1152 1161 1153 - if (tb_port_path_direction_downstream(in, tunnel->dst_port)) { 1162 + if (tb_tunnel_direction_downstream(tunnel)) { 1154 1163 *max_up = 0; 1155 1164 *max_down = ret; 1156 1165 } else { ··· 1163 1174 static int tb_dp_consumed_bandwidth(struct tb_tunnel *tunnel, int *consumed_up, 1164 1175 int *consumed_down) 1165 1176 { 1166 - struct tb_port *in = tunnel->src_port; 1167 - const struct tb_switch *sw = in->sw; 1177 + const struct tb_switch *sw = tunnel->src_port->sw; 1168 1178 u32 rate = 0, lanes = 0; 1169 1179 int ret; 1170 1180 ··· 1184 1196 /* 1185 1197 * Then see if the DPRX negotiation is ready and if yes 1186 1198 * return that bandwidth (it may be smaller than the 1187 - * reduced one). Otherwise return the remote (possibly 1188 - * reduced) caps. 1199 + * reduced one). According to VESA spec, the DPRX 1200 + * negotiation shall compete in 5 seconds after tunnel 1201 + * established. We give it 100ms extra just in case. 1189 1202 */ 1190 - ret = tb_dp_wait_dprx(tunnel, 150); 1191 - if (ret) { 1192 - if (ret == -ETIMEDOUT) 1193 - ret = tb_dp_read_cap(tunnel, DP_REMOTE_CAP, 1194 - &rate, &lanes); 1195 - if (ret) 1196 - return ret; 1197 - } 1203 + ret = tb_dp_wait_dprx(tunnel, 5100); 1204 + if (ret) 1205 + return ret; 1198 1206 ret = tb_dp_read_cap(tunnel, DP_COMMON_CAP, &rate, &lanes); 1199 1207 if (ret) 1200 1208 return ret; ··· 1205 1221 return 0; 1206 1222 } 1207 1223 1208 - if (tb_port_path_direction_downstream(in, tunnel->dst_port)) { 1224 + if (tb_tunnel_direction_downstream(tunnel)) { 1209 1225 *consumed_up = 0; 1210 1226 *consumed_down = tb_dp_bandwidth(rate, lanes); 1211 1227 } else {
+6
drivers/thunderbolt/tunnel.h
··· 139 139 return tunnel->type == TB_TUNNEL_USB3; 140 140 } 141 141 142 + static inline bool tb_tunnel_direction_downstream(const struct tb_tunnel *tunnel) 143 + { 144 + return tb_port_path_direction_downstream(tunnel->src_port, 145 + tunnel->dst_port); 146 + } 147 + 142 148 const char *tb_tunnel_type_name(const struct tb_tunnel *tunnel); 143 149 144 150 #define __TB_TUNNEL_PRINT(level, tunnel, fmt, arg...) \
+42 -1
drivers/thunderbolt/usb4.c
··· 1113 1113 return tb_port_write(port, &val, TB_CFG_PORT, ADP_CS_5, 1); 1114 1114 } 1115 1115 1116 + /** 1117 + * usb4_port_reset() - Issue downstream port reset 1118 + * @port: USB4 port to reset 1119 + * 1120 + * Issues downstream port reset to @port. 1121 + */ 1122 + int usb4_port_reset(struct tb_port *port) 1123 + { 1124 + int ret; 1125 + u32 val; 1126 + 1127 + if (!port->cap_usb4) 1128 + return -EINVAL; 1129 + 1130 + ret = tb_port_read(port, &val, TB_CFG_PORT, 1131 + port->cap_usb4 + PORT_CS_19, 1); 1132 + if (ret) 1133 + return ret; 1134 + 1135 + val |= PORT_CS_19_DPR; 1136 + 1137 + ret = tb_port_write(port, &val, TB_CFG_PORT, 1138 + port->cap_usb4 + PORT_CS_19, 1); 1139 + if (ret) 1140 + return ret; 1141 + 1142 + fsleep(10000); 1143 + 1144 + ret = tb_port_read(port, &val, TB_CFG_PORT, 1145 + port->cap_usb4 + PORT_CS_19, 1); 1146 + if (ret) 1147 + return ret; 1148 + 1149 + val &= ~PORT_CS_19_DPR; 1150 + 1151 + return tb_port_write(port, &val, TB_CFG_PORT, 1152 + port->cap_usb4 + PORT_CS_19, 1); 1153 + } 1154 + 1116 1155 static int usb4_port_set_configured(struct tb_port *port, bool configured) 1117 1156 { 1118 1157 int ret; ··· 2858 2819 usleep_range(50, 100); 2859 2820 } while (ktime_before(ktime_get(), end)); 2860 2821 2861 - if (val & ADP_DP_CS_8_DR) 2822 + if (val & ADP_DP_CS_8_DR) { 2823 + tb_port_warn(port, "timeout waiting for DPTX request to clear\n"); 2862 2824 return -ETIMEDOUT; 2825 + } 2863 2826 2864 2827 ret = tb_port_read(port, &val, TB_CFG_PORT, 2865 2828 port->cap_adap + ADP_DP_CS_2, 1);
+1 -1
drivers/thunderbolt/usb4_port.c
··· 243 243 kfree(usb4); 244 244 } 245 245 246 - struct device_type usb4_port_device_type = { 246 + const struct device_type usb4_port_device_type = { 247 247 .name = "usb4_port", 248 248 .groups = usb4_port_device_groups, 249 249 .release = usb4_port_device_release,
+8 -8
drivers/thunderbolt/xdomain.c
··· 997 997 struct tb_xdomain *xd = tb_service_parent(svc); 998 998 999 999 tb_service_debugfs_remove(svc); 1000 - ida_simple_remove(&xd->service_ids, svc->id); 1000 + ida_free(&xd->service_ids, svc->id); 1001 1001 kfree(svc->key); 1002 1002 kfree(svc); 1003 1003 } 1004 1004 1005 - struct device_type tb_service_type = { 1005 + const struct device_type tb_service_type = { 1006 1006 .name = "thunderbolt_service", 1007 1007 .groups = tb_service_attr_groups, 1008 1008 .uevent = tb_service_uevent, ··· 1099 1099 break; 1100 1100 } 1101 1101 1102 - id = ida_simple_get(&xd->service_ids, 0, 0, GFP_KERNEL); 1102 + id = ida_alloc(&xd->service_ids, GFP_KERNEL); 1103 1103 if (id < 0) { 1104 1104 kfree(svc->key); 1105 1105 kfree(svc); ··· 1791 1791 1792 1792 switch (xd->link_width) { 1793 1793 case TB_LINK_WIDTH_SINGLE: 1794 - case TB_LINK_WIDTH_ASYM_RX: 1794 + case TB_LINK_WIDTH_ASYM_TX: 1795 1795 width = 1; 1796 1796 break; 1797 1797 case TB_LINK_WIDTH_DUAL: 1798 1798 width = 2; 1799 1799 break; 1800 - case TB_LINK_WIDTH_ASYM_TX: 1800 + case TB_LINK_WIDTH_ASYM_RX: 1801 1801 width = 3; 1802 1802 break; 1803 1803 default: ··· 1817 1817 1818 1818 switch (xd->link_width) { 1819 1819 case TB_LINK_WIDTH_SINGLE: 1820 - case TB_LINK_WIDTH_ASYM_TX: 1820 + case TB_LINK_WIDTH_ASYM_RX: 1821 1821 width = 1; 1822 1822 break; 1823 1823 case TB_LINK_WIDTH_DUAL: 1824 1824 width = 2; 1825 1825 break; 1826 - case TB_LINK_WIDTH_ASYM_RX: 1826 + case TB_LINK_WIDTH_ASYM_TX: 1827 1827 width = 3; 1828 1828 break; 1829 1829 default: ··· 1893 1893 SET_SYSTEM_SLEEP_PM_OPS(tb_xdomain_suspend, tb_xdomain_resume) 1894 1894 }; 1895 1895 1896 - struct device_type tb_xdomain_type = { 1896 + const struct device_type tb_xdomain_type = { 1897 1897 .name = "thunderbolt_xdomain", 1898 1898 .release = tb_xdomain_release, 1899 1899 .pm = &tb_xdomain_pm_ops,
+1 -1
drivers/usb/cdns3/drd.c
··· 435 435 writel(1, &cdns->otg_v1_regs->simulate); 436 436 cdns->version = CDNS3_CONTROLLER_V1; 437 437 } else { 438 - dev_err(cdns->dev, "not supporte DID=0x%08x\n", state); 438 + dev_err(cdns->dev, "not supported DID=0x%08x\n", state); 439 439 return -EINVAL; 440 440 } 441 441
+27
drivers/usb/core/Kconfig
··· 116 116 The default value Linux has always had is 2 seconds. Change 117 117 this value if you want a different delay and cannot modify 118 118 the command line or module parameter. 119 + 120 + config USB_DEFAULT_AUTHORIZATION_MODE 121 + int "Default authorization mode for USB devices" 122 + range 0 2 123 + default 1 124 + depends on USB 125 + help 126 + Select the default USB device authorization mode. Can be overridden 127 + with usbcore.authorized_default command line or module parameter. 128 + 129 + This option allows you to choose whether USB devices that are 130 + connected to the system can be used by default, or if they are 131 + locked down. 132 + 133 + With value 0 all connected USB devices with the exception of root 134 + hub require user space authorization before they can be used. 135 + 136 + With value 1 (default) no user space authorization is required to 137 + use connected USB devices. 138 + 139 + With value 2 all connected USB devices with exception of internal 140 + USB devices require user space authorization before they can be 141 + used. Note that in this mode the differentiation between internal 142 + and external USB devices relies on ACPI, and on systems without 143 + ACPI selecting value 2 is analogous to selecting value 0. 144 + 145 + If unsure, keep the default value.
+2 -6
drivers/usb/core/driver.c
··· 1710 1710 { 1711 1711 int status; 1712 1712 1713 - status = pm_runtime_get_sync(&udev->dev); 1714 - if (status < 0) 1715 - pm_runtime_put_sync(&udev->dev); 1713 + status = pm_runtime_resume_and_get(&udev->dev); 1716 1714 dev_vdbg(&udev->dev, "%s: cnt %d -> %d\n", 1717 1715 __func__, atomic_read(&udev->dev.power.usage_count), 1718 1716 status); ··· 1816 1818 { 1817 1819 int status; 1818 1820 1819 - status = pm_runtime_get_sync(&intf->dev); 1820 - if (status < 0) 1821 - pm_runtime_put_sync(&intf->dev); 1821 + status = pm_runtime_resume_and_get(&intf->dev); 1822 1822 dev_vdbg(&intf->dev, "%s: cnt %d -> %d\n", 1823 1823 __func__, atomic_read(&intf->dev.power.usage_count), 1824 1824 status);
+1 -1
drivers/usb/core/endpoint.c
··· 141 141 kfree(ep_dev); 142 142 } 143 143 144 - struct device_type usb_ep_device_type = { 144 + const struct device_type usb_ep_device_type = { 145 145 .name = "usb_endpoint", 146 146 .release = ep_device_release, 147 147 };
+12 -8
drivers/usb/core/hcd.c
··· 357 357 #define USB_AUTHORIZE_ALL 1 358 358 #define USB_AUTHORIZE_INTERNAL 2 359 359 360 - static int authorized_default = USB_AUTHORIZE_WIRED; 360 + static int authorized_default = CONFIG_USB_DEFAULT_AUTHORIZATION_MODE; 361 361 module_param(authorized_default, int, S_IRUGO|S_IWUSR); 362 362 MODULE_PARM_DESC(authorized_default, 363 - "Default USB device authorization: 0 is not authorized, 1 is " 364 - "authorized, 2 is authorized for internal devices, -1 is " 365 - "authorized (default, same as 1)"); 363 + "Default USB device authorization: 0 is not authorized, 1 is authorized (default), 2 is authorized for internal devices, -1 is authorized (same as 1)"); 366 364 /*-------------------------------------------------------------------------*/ 367 365 368 366 /** ··· 2793 2795 struct usb_device *rhdev; 2794 2796 struct usb_hcd *shared_hcd; 2795 2797 2796 - if (!hcd->skip_phy_initialization && usb_hcd_is_primary_hcd(hcd)) { 2797 - hcd->phy_roothub = usb_phy_roothub_alloc(hcd->self.sysdev); 2798 - if (IS_ERR(hcd->phy_roothub)) 2799 - return PTR_ERR(hcd->phy_roothub); 2798 + if (!hcd->skip_phy_initialization) { 2799 + if (usb_hcd_is_primary_hcd(hcd)) { 2800 + hcd->phy_roothub = usb_phy_roothub_alloc(hcd->self.sysdev); 2801 + if (IS_ERR(hcd->phy_roothub)) 2802 + return PTR_ERR(hcd->phy_roothub); 2803 + } else { 2804 + hcd->phy_roothub = usb_phy_roothub_alloc_usb3_phy(hcd->self.sysdev); 2805 + if (IS_ERR(hcd->phy_roothub)) 2806 + return PTR_ERR(hcd->phy_roothub); 2807 + } 2800 2808 2801 2809 retval = usb_phy_roothub_init(hcd->phy_roothub); 2802 2810 if (retval)
+29
drivers/usb/core/hub.c
··· 37 37 #include <asm/byteorder.h> 38 38 39 39 #include "hub.h" 40 + #include "phy.h" 40 41 #include "otg_productlist.h" 41 42 42 43 #define USB_VENDOR_GENESYS_LOGIC 0x05e3 ··· 635 634 ret = 0; 636 635 } 637 636 mutex_unlock(&hub->status_mutex); 637 + 638 + /* 639 + * There is no need to lock status_mutex here, because status_mutex 640 + * protects hub->status, and the phy driver only checks the port 641 + * status without changing the status. 642 + */ 643 + if (!ret) { 644 + struct usb_device *hdev = hub->hdev; 645 + 646 + /* 647 + * Only roothub will be notified of connection changes, 648 + * since the USB PHY only cares about changes at the next 649 + * level. 650 + */ 651 + if (is_root_hub(hdev)) { 652 + struct usb_hcd *hcd = bus_to_hcd(hdev->bus); 653 + bool connect; 654 + bool connect_change; 655 + 656 + connect_change = *change & USB_PORT_STAT_C_CONNECTION; 657 + connect = *status & USB_PORT_STAT_CONNECTION; 658 + if (connect_change && connect) 659 + usb_phy_roothub_notify_connect(hcd->phy_roothub, port1 - 1); 660 + else if (connect_change) 661 + usb_phy_roothub_notify_disconnect(hcd->phy_roothub, port1 - 1); 662 + } 663 + } 664 + 638 665 return ret; 639 666 } 640 667
+5 -2
drivers/usb/core/message.c
··· 1198 1198 * same status code used to report a true stall. 1199 1199 * 1200 1200 * This call is synchronous, and may not be used in an interrupt context. 1201 + * If a thread in your driver uses this call, make sure your disconnect() 1202 + * method can wait for it to complete. 1201 1203 * 1202 1204 * Return: Zero on success, or else the status code returned by the 1203 1205 * underlying usb_control_msg() call. ··· 1518 1516 * This call is synchronous, and may not be used in an interrupt context. 1519 1517 * Also, drivers must not change altsettings while urbs are scheduled for 1520 1518 * endpoints in that interface; all such urbs must first be completed 1521 - * (perhaps forced by unlinking). 1519 + * (perhaps forced by unlinking). If a thread in your driver uses this call, 1520 + * make sure your disconnect() method can wait for it to complete. 1522 1521 * 1523 1522 * Return: Zero on success, or else the status code returned by the 1524 1523 * underlying usb_control_msg() call. ··· 1852 1849 return 0; 1853 1850 } 1854 1851 1855 - struct device_type usb_if_device_type = { 1852 + const struct device_type usb_if_device_type = { 1856 1853 .name = "usb_interface", 1857 1854 .release = usb_release_interface, 1858 1855 .uevent = usb_if_uevent,
+71
drivers/usb/core/of.c
··· 8 8 */ 9 9 10 10 #include <linux/of.h> 11 + #include <linux/of_graph.h> 11 12 #include <linux/usb/of.h> 12 13 13 14 /** ··· 75 74 return false; 76 75 } 77 76 EXPORT_SYMBOL_GPL(usb_of_has_combined_node); 77 + 78 + static bool usb_of_has_devices_or_graph(const struct usb_device *hub) 79 + { 80 + const struct device_node *np = hub->dev.of_node; 81 + struct device_node *child; 82 + 83 + if (of_graph_is_present(np)) 84 + return true; 85 + 86 + for_each_child_of_node(np, child) 87 + if (of_property_present(child, "reg")) 88 + return true; 89 + 90 + return false; 91 + } 92 + 93 + /** 94 + * usb_of_get_connect_type() - get a USB hub's port connect_type 95 + * @hub: hub to which port is for @port1 96 + * @port1: one-based index of port 97 + * 98 + * Get the connect_type of @port1 based on the device node for @hub. If the 99 + * port is described in the OF graph, the connect_type is "hotplug". If the 100 + * @hub has a child device has with a 'reg' property equal to @port1 the 101 + * connect_type is "hard-wired". If there isn't an OF graph or child node at 102 + * all then the connect_type is "unknown". Otherwise, the port is considered 103 + * "unused" because it isn't described at all. 104 + * 105 + * Return: A connect_type for @port1 based on the device node for @hub. 106 + */ 107 + enum usb_port_connect_type usb_of_get_connect_type(struct usb_device *hub, int port1) 108 + { 109 + struct device_node *np, *child, *ep, *remote_np; 110 + enum usb_port_connect_type connect_type; 111 + 112 + /* Only set connect_type if binding has ports/hardwired devices. */ 113 + if (!usb_of_has_devices_or_graph(hub)) 114 + return USB_PORT_CONNECT_TYPE_UNKNOWN; 115 + 116 + /* Assume port is unused if there's a graph or a child node. */ 117 + connect_type = USB_PORT_NOT_USED; 118 + 119 + np = hub->dev.of_node; 120 + /* 121 + * Hotplug ports are connected to an available remote node, e.g. 122 + * usb-a-connector compatible node, in the OF graph. 123 + */ 124 + if (of_graph_is_present(np)) { 125 + ep = of_graph_get_endpoint_by_regs(np, port1, -1); 126 + if (ep) { 127 + remote_np = of_graph_get_remote_port_parent(ep); 128 + of_node_put(ep); 129 + if (of_device_is_available(remote_np)) 130 + connect_type = USB_PORT_CONNECT_TYPE_HOT_PLUG; 131 + of_node_put(remote_np); 132 + } 133 + } 134 + 135 + /* 136 + * Hard-wired ports are child nodes with a reg property corresponding 137 + * to the port number, i.e. a usb device. 138 + */ 139 + child = usb_of_get_device_node(hub, port1); 140 + if (of_device_is_available(child)) 141 + connect_type = USB_PORT_CONNECT_TYPE_HARD_WIRED; 142 + of_node_put(child); 143 + 144 + return connect_type; 145 + } 146 + EXPORT_SYMBOL_GPL(usb_of_get_connect_type); 78 147 79 148 /** 80 149 * usb_of_get_interface_node() - get a USB interface node
+120
drivers/usb/core/phy.c
··· 19 19 struct list_head list; 20 20 }; 21 21 22 + /* Allocate the roothub_entry by specific name of phy */ 23 + static int usb_phy_roothub_add_phy_by_name(struct device *dev, const char *name, 24 + struct list_head *list) 25 + { 26 + struct usb_phy_roothub *roothub_entry; 27 + struct phy *phy; 28 + 29 + phy = devm_of_phy_get(dev, dev->of_node, name); 30 + if (IS_ERR(phy)) 31 + return PTR_ERR(phy); 32 + 33 + roothub_entry = devm_kzalloc(dev, sizeof(*roothub_entry), GFP_KERNEL); 34 + if (!roothub_entry) 35 + return -ENOMEM; 36 + 37 + INIT_LIST_HEAD(&roothub_entry->list); 38 + 39 + roothub_entry->phy = phy; 40 + 41 + list_add_tail(&roothub_entry->list, list); 42 + 43 + return 0; 44 + } 45 + 22 46 static int usb_phy_roothub_add_phy(struct device *dev, int index, 23 47 struct list_head *list) 24 48 { ··· 89 65 90 66 INIT_LIST_HEAD(&phy_roothub->list); 91 67 68 + if (!usb_phy_roothub_add_phy_by_name(dev, "usb2-phy", &phy_roothub->list)) 69 + return phy_roothub; 70 + 92 71 for (i = 0; i < num_phys; i++) { 93 72 err = usb_phy_roothub_add_phy(dev, i, &phy_roothub->list); 94 73 if (err) ··· 101 74 return phy_roothub; 102 75 } 103 76 EXPORT_SYMBOL_GPL(usb_phy_roothub_alloc); 77 + 78 + /** 79 + * usb_phy_roothub_alloc_usb3_phy - alloc the roothub 80 + * @dev: the device of the host controller 81 + * 82 + * Allocate the usb phy roothub if the host use a generic usb3-phy. 83 + * 84 + * Return: On success, a pointer to the usb_phy_roothub. Otherwise, 85 + * %NULL if no use usb3 phy or %-ENOMEM if out of memory. 86 + */ 87 + struct usb_phy_roothub *usb_phy_roothub_alloc_usb3_phy(struct device *dev) 88 + { 89 + struct usb_phy_roothub *phy_roothub; 90 + int num_phys; 91 + 92 + if (!IS_ENABLED(CONFIG_GENERIC_PHY)) 93 + return NULL; 94 + 95 + num_phys = of_count_phandle_with_args(dev->of_node, "phys", 96 + "#phy-cells"); 97 + if (num_phys <= 0) 98 + return NULL; 99 + 100 + phy_roothub = devm_kzalloc(dev, sizeof(*phy_roothub), GFP_KERNEL); 101 + if (!phy_roothub) 102 + return ERR_PTR(-ENOMEM); 103 + 104 + INIT_LIST_HEAD(&phy_roothub->list); 105 + 106 + if (!usb_phy_roothub_add_phy_by_name(dev, "usb3-phy", &phy_roothub->list)) 107 + return phy_roothub; 108 + 109 + return NULL; 110 + } 111 + EXPORT_SYMBOL_GPL(usb_phy_roothub_alloc_usb3_phy); 104 112 105 113 int usb_phy_roothub_init(struct usb_phy_roothub *phy_roothub) 106 114 { ··· 233 171 return 0; 234 172 } 235 173 EXPORT_SYMBOL_GPL(usb_phy_roothub_calibrate); 174 + 175 + /** 176 + * usb_phy_roothub_notify_connect() - connect notification 177 + * @phy_roothub: the phy of roothub, if the host use a generic phy. 178 + * @port: the port index for connect 179 + * 180 + * If the phy needs to get connection status, the callback can be used. 181 + * Returns: %0 if successful, a negative error code otherwise 182 + */ 183 + int usb_phy_roothub_notify_connect(struct usb_phy_roothub *phy_roothub, int port) 184 + { 185 + struct usb_phy_roothub *roothub_entry; 186 + struct list_head *head; 187 + int err; 188 + 189 + if (!phy_roothub) 190 + return 0; 191 + 192 + head = &phy_roothub->list; 193 + 194 + list_for_each_entry(roothub_entry, head, list) { 195 + err = phy_notify_connect(roothub_entry->phy, port); 196 + if (err) 197 + return err; 198 + } 199 + 200 + return 0; 201 + } 202 + EXPORT_SYMBOL_GPL(usb_phy_roothub_notify_connect); 203 + 204 + /** 205 + * usb_phy_roothub_notify_disconnect() - disconnect notification 206 + * @phy_roothub: the phy of roothub, if the host use a generic phy. 207 + * @port: the port index for disconnect 208 + * 209 + * If the phy needs to get connection status, the callback can be used. 210 + * Returns: %0 if successful, a negative error code otherwise 211 + */ 212 + int usb_phy_roothub_notify_disconnect(struct usb_phy_roothub *phy_roothub, int port) 213 + { 214 + struct usb_phy_roothub *roothub_entry; 215 + struct list_head *head; 216 + int err; 217 + 218 + if (!phy_roothub) 219 + return 0; 220 + 221 + head = &phy_roothub->list; 222 + 223 + list_for_each_entry(roothub_entry, head, list) { 224 + err = phy_notify_disconnect(roothub_entry->phy, port); 225 + if (err) 226 + return err; 227 + } 228 + 229 + return 0; 230 + } 231 + EXPORT_SYMBOL_GPL(usb_phy_roothub_notify_disconnect); 236 232 237 233 int usb_phy_roothub_power_on(struct usb_phy_roothub *phy_roothub) 238 234 {
+3
drivers/usb/core/phy.h
··· 12 12 struct usb_phy_roothub; 13 13 14 14 struct usb_phy_roothub *usb_phy_roothub_alloc(struct device *dev); 15 + struct usb_phy_roothub *usb_phy_roothub_alloc_usb3_phy(struct device *dev); 15 16 16 17 int usb_phy_roothub_init(struct usb_phy_roothub *phy_roothub); 17 18 int usb_phy_roothub_exit(struct usb_phy_roothub *phy_roothub); ··· 20 19 int usb_phy_roothub_set_mode(struct usb_phy_roothub *phy_roothub, 21 20 enum phy_mode mode); 22 21 int usb_phy_roothub_calibrate(struct usb_phy_roothub *phy_roothub); 22 + int usb_phy_roothub_notify_connect(struct usb_phy_roothub *phy_roothub, int port); 23 + int usb_phy_roothub_notify_disconnect(struct usb_phy_roothub *phy_roothub, int port); 23 24 int usb_phy_roothub_power_on(struct usb_phy_roothub *phy_roothub); 24 25 void usb_phy_roothub_power_off(struct usb_phy_roothub *phy_roothub); 25 26
+3 -1
drivers/usb/core/port.c
··· 11 11 #include <linux/slab.h> 12 12 #include <linux/pm_qos.h> 13 13 #include <linux/component.h> 14 + #include <linux/usb/of.h> 14 15 15 16 #include "hub.h" 16 17 ··· 430 429 #endif 431 430 }; 432 431 433 - struct device_type usb_port_device_type = { 432 + const struct device_type usb_port_device_type = { 434 433 .name = "usb_port", 435 434 .release = usb_port_device_release, 436 435 .pm = &usb_port_pm_ops, ··· 710 709 return -ENOMEM; 711 710 } 712 711 712 + port_dev->connect_type = usb_of_get_connect_type(hdev, port1); 713 713 hub->ports[port1 - 1] = port_dev; 714 714 port_dev->portnum = port1; 715 715 set_bit(port1, hub->power_bits);
+76 -27
drivers/usb/core/sysfs.c
··· 273 273 const char *buf, size_t count) 274 274 { 275 275 struct usb_device *udev = to_usb_device(dev); 276 - int val, rc; 276 + bool val; 277 + int rc; 277 278 278 - if (sscanf(buf, "%d", &val) != 1 || val < 0 || val > 1) 279 + if (kstrtobool(buf, &val) != 0) 279 280 return -EINVAL; 280 281 rc = usb_lock_device_interruptible(udev); 281 282 if (rc < 0) ··· 323 322 const char *buf, size_t count) 324 323 { 325 324 struct usb_device *udev = to_usb_device(dev); 326 - int value, rc; 325 + bool value; 326 + int rc; 327 327 328 328 /* Hubs are always enabled for USB_PERSIST */ 329 329 if (udev->descriptor.bDeviceClass == USB_CLASS_HUB) 330 330 return -EPERM; 331 331 332 - if (sscanf(buf, "%d", &value) != 1) 332 + if (kstrtobool(buf, &value) != 0) 333 333 return -EINVAL; 334 334 335 335 rc = usb_lock_device_interruptible(udev); ··· 741 739 { 742 740 ssize_t result; 743 741 struct usb_device *usb_dev = to_usb_device(dev); 744 - unsigned val; 745 - result = sscanf(buf, "%u\n", &val); 746 - if (result != 1) 742 + bool val; 743 + 744 + if (kstrtobool(buf, &val) != 0) 747 745 result = -EINVAL; 748 - else if (val == 0) 749 - result = usb_deauthorize_device(usb_dev); 750 - else 746 + else if (val) 751 747 result = usb_authorize_device(usb_dev); 748 + else 749 + result = usb_deauthorize_device(usb_dev); 752 750 return result < 0 ? result : size; 753 751 } 754 752 static DEVICE_ATTR_IGNORE_LOCKDEP(authorized, S_IRUGO | S_IWUSR, ··· 849 847 .is_visible = dev_string_attrs_are_visible, 850 848 }; 851 849 852 - const struct attribute_group *usb_device_groups[] = { 853 - &dev_attr_grp, 854 - &dev_string_attr_grp, 855 - NULL 856 - }; 857 - 858 850 /* Binary descriptors */ 859 851 860 852 static ssize_t 861 - read_descriptors(struct file *filp, struct kobject *kobj, 853 + descriptors_read(struct file *filp, struct kobject *kobj, 862 854 struct bin_attribute *attr, 863 855 char *buf, loff_t off, size_t count) 864 856 { ··· 874 878 srclen = sizeof(struct usb_device_descriptor); 875 879 } else { 876 880 src = udev->rawdescriptors[cfgno]; 877 - srclen = __le16_to_cpu(udev->config[cfgno].desc. 881 + srclen = le16_to_cpu(udev->config[cfgno].desc. 878 882 wTotalLength); 879 883 } 880 884 if (off < srclen) { ··· 889 893 } 890 894 return count - nleft; 891 895 } 896 + static BIN_ATTR_RO(descriptors, 18 + 65535); /* dev descr + max-size raw descriptor */ 892 897 893 - static struct bin_attribute dev_bin_attr_descriptors = { 894 - .attr = {.name = "descriptors", .mode = 0444}, 895 - .read = read_descriptors, 896 - .size = 18 + 65535, /* dev descr + max-size raw descriptor */ 898 + static ssize_t 899 + bos_descriptors_read(struct file *filp, struct kobject *kobj, 900 + struct bin_attribute *attr, 901 + char *buf, loff_t off, size_t count) 902 + { 903 + struct device *dev = kobj_to_dev(kobj); 904 + struct usb_device *udev = to_usb_device(dev); 905 + struct usb_host_bos *bos = udev->bos; 906 + struct usb_bos_descriptor *desc; 907 + size_t desclen, n = 0; 908 + 909 + if (bos) { 910 + desc = bos->desc; 911 + desclen = le16_to_cpu(desc->wTotalLength); 912 + if (off < desclen) { 913 + n = min(count, desclen - (size_t) off); 914 + memcpy(buf, (void *) desc + off, n); 915 + } 916 + } 917 + return n; 918 + } 919 + static BIN_ATTR_RO(bos_descriptors, 65535); /* max-size BOS */ 920 + 921 + /* When modifying this list, be sure to modify dev_bin_attrs_are_visible() 922 + * accordingly. 923 + */ 924 + static struct bin_attribute *dev_bin_attrs[] = { 925 + &bin_attr_descriptors, 926 + &bin_attr_bos_descriptors, 927 + NULL 928 + }; 929 + 930 + static umode_t dev_bin_attrs_are_visible(struct kobject *kobj, 931 + struct bin_attribute *a, int n) 932 + { 933 + struct device *dev = kobj_to_dev(kobj); 934 + struct usb_device *udev = to_usb_device(dev); 935 + 936 + /* 937 + * There's no need to check if the descriptors attribute should 938 + * be visible because all devices have a device descriptor. The 939 + * bos_descriptors attribute should be visible if and only if 940 + * the device has a BOS, so check if it exists here. 941 + */ 942 + if (a == &bin_attr_bos_descriptors) { 943 + if (udev->bos == NULL) 944 + return 0; 945 + } 946 + return a->attr.mode; 947 + } 948 + 949 + static const struct attribute_group dev_bin_attr_grp = { 950 + .bin_attrs = dev_bin_attrs, 951 + .is_bin_visible = dev_bin_attrs_are_visible, 952 + }; 953 + 954 + const struct attribute_group *usb_device_groups[] = { 955 + &dev_attr_grp, 956 + &dev_string_attr_grp, 957 + &dev_bin_attr_grp, 958 + NULL 897 959 }; 898 960 899 961 /* ··· 1069 1015 struct device *dev = &udev->dev; 1070 1016 int retval; 1071 1017 1072 - retval = device_create_bin_file(dev, &dev_bin_attr_descriptors); 1073 - if (retval) 1074 - goto error; 1075 - 1076 1018 retval = add_persist_attributes(dev); 1077 1019 if (retval) 1078 1020 goto error; ··· 1098 1048 1099 1049 remove_power_attributes(dev); 1100 1050 remove_persist_attributes(dev); 1101 - device_remove_bin_file(dev, &dev_bin_attr_descriptors); 1102 1051 } 1103 1052 1104 1053 /* Interface Association Descriptor fields */
+23 -23
drivers/usb/core/usb-acpi.c
··· 142 142 } 143 143 EXPORT_SYMBOL_GPL(usb_acpi_set_power_state); 144 144 145 - static enum usb_port_connect_type usb_acpi_get_connect_type(acpi_handle handle, 146 - struct acpi_pld_info *pld) 145 + /* 146 + * Private to usb-acpi, all the core needs to know is that 147 + * port_dev->location is non-zero when it has been set by the firmware. 148 + */ 149 + #define USB_ACPI_LOCATION_VALID (1 << 31) 150 + 151 + static void 152 + usb_acpi_get_connect_type(struct usb_port *port_dev, acpi_handle *handle) 147 153 { 148 154 enum usb_port_connect_type connect_type = USB_PORT_CONNECT_TYPE_UNKNOWN; 149 155 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; 150 156 union acpi_object *upc = NULL; 157 + struct acpi_pld_info *pld = NULL; 151 158 acpi_status status; 152 159 153 160 /* ··· 165 158 * a usb device is directly hard-wired to the port. If no visible and 166 159 * no connectable, the port would be not used. 167 160 */ 161 + 162 + status = acpi_get_physical_device_location(handle, &pld); 163 + if (ACPI_SUCCESS(status) && pld) 164 + port_dev->location = USB_ACPI_LOCATION_VALID | 165 + pld->group_token << 8 | pld->group_position; 166 + 168 167 status = acpi_evaluate_object(handle, "_UPC", NULL, &buffer); 169 168 if (ACPI_FAILURE(status)) 170 169 goto out; ··· 179 166 if (!upc || (upc->type != ACPI_TYPE_PACKAGE) || upc->package.count != 4) 180 167 goto out; 181 168 169 + /* UPC states port is connectable */ 182 170 if (upc->package.elements[0].integer.value) 183 - if (pld->user_visible) 171 + if (!pld) 172 + ; /* keep connect_type as unknown */ 173 + else if (pld->user_visible) 184 174 connect_type = USB_PORT_CONNECT_TYPE_HOT_PLUG; 185 175 else 186 176 connect_type = USB_PORT_CONNECT_TYPE_HARD_WIRED; 187 - else if (!pld->user_visible) 177 + else 188 178 connect_type = USB_PORT_NOT_USED; 189 179 out: 180 + port_dev->connect_type = connect_type; 190 181 kfree(upc); 191 - return connect_type; 182 + ACPI_FREE(pld); 192 183 } 193 - 194 - 195 - /* 196 - * Private to usb-acpi, all the core needs to know is that 197 - * port_dev->location is non-zero when it has been set by the firmware. 198 - */ 199 - #define USB_ACPI_LOCATION_VALID (1 << 31) 200 184 201 185 static struct acpi_device * 202 186 usb_acpi_get_companion_for_port(struct usb_port *port_dev) ··· 232 222 usb_acpi_find_companion_for_port(struct usb_port *port_dev) 233 223 { 234 224 struct acpi_device *adev; 235 - struct acpi_pld_info *pld; 236 - acpi_handle *handle; 237 - acpi_status status; 238 225 239 226 adev = usb_acpi_get_companion_for_port(port_dev); 240 227 if (!adev) 241 228 return NULL; 242 229 243 - handle = adev->handle; 244 - status = acpi_get_physical_device_location(handle, &pld); 245 - if (ACPI_SUCCESS(status) && pld) { 246 - port_dev->location = USB_ACPI_LOCATION_VALID 247 - | pld->group_token << 8 | pld->group_position; 248 - port_dev->connect_type = usb_acpi_get_connect_type(handle, pld); 249 - ACPI_FREE(pld); 250 - } 230 + usb_acpi_get_connect_type(port_dev, adev->handle); 251 231 252 232 return adev; 253 233 }
+1 -1
drivers/usb/core/usb.c
··· 592 592 usb_dev->bus->busnum, usb_dev->devnum); 593 593 } 594 594 595 - struct device_type usb_device_type = { 595 + const struct device_type usb_device_type = { 596 596 .name = "usb_device", 597 597 .release = usb_release_dev, 598 598 .uevent = usb_dev_uevent,
+4 -4
drivers/usb/core/usb.h
··· 144 144 extern const struct class usbmisc_class; 145 145 extern const struct bus_type usb_bus_type; 146 146 extern struct mutex usb_port_peer_mutex; 147 - extern struct device_type usb_device_type; 148 - extern struct device_type usb_if_device_type; 149 - extern struct device_type usb_ep_device_type; 150 - extern struct device_type usb_port_device_type; 147 + extern const struct device_type usb_device_type; 148 + extern const struct device_type usb_if_device_type; 149 + extern const struct device_type usb_ep_device_type; 150 + extern const struct device_type usb_port_device_type; 151 151 extern struct usb_device_driver usb_generic_driver; 152 152 153 153 static inline int is_usb_device(const struct device *dev)
+1 -1
drivers/usb/dwc3/Kconfig
··· 131 131 tristate "Qualcomm Platform" 132 132 depends on ARCH_QCOM || COMPILE_TEST 133 133 depends on EXTCON || !EXTCON 134 - depends on (OF || ACPI) 134 + depends on OF 135 135 default USB_DWC3 136 136 help 137 137 Some Qualcomm SoCs use DesignWare Core IP for USB2/3
+2
drivers/usb/dwc3/core.h
··· 755 755 #define DWC3_EP_PENDING_CLEAR_STALL BIT(11) 756 756 #define DWC3_EP_TXFIFO_RESIZED BIT(12) 757 757 #define DWC3_EP_DELAY_STOP BIT(13) 758 + #define DWC3_EP_RESOURCE_ALLOCATED BIT(14) 758 759 759 760 /* This last one is specific to EP0 */ 760 761 #define DWC3_EP0_DIR_IN BIT(31) ··· 1258 1257 #define DWC31_REVISION_170A 0x3137302a 1259 1258 #define DWC31_REVISION_180A 0x3138302a 1260 1259 #define DWC31_REVISION_190A 0x3139302a 1260 + #define DWC31_REVISION_200A 0x3230302a 1261 1261 1262 1262 #define DWC32_REVISION_ANY 0x0 1263 1263 #define DWC32_REVISION_100A 0x3130302a
+30 -12
drivers/usb/dwc3/dwc3-am62.c
··· 97 97 #define USBSS_VBUS_STAT_SESSVALID BIT(2) 98 98 #define USBSS_VBUS_STAT_VBUSVALID BIT(0) 99 99 100 - /* Mask for PHY PLL REFCLK */ 100 + /* USB_PHY_CTRL register bits in CTRL_MMR */ 101 + #define PHY_CORE_VOLTAGE_MASK BIT(31) 101 102 #define PHY_PLL_REFCLK_MASK GENMASK(3, 0) 103 + 104 + /* USB PHY2 register offsets */ 105 + #define USB_PHY_PLL_REG12 0x130 106 + #define USB_PHY_PLL_LDO_REF_EN BIT(5) 107 + #define USB_PHY_PLL_LDO_REF_EN_EN BIT(4) 102 108 103 109 #define DWC3_AM62_AUTOSUSPEND_DELAY 100 104 110 ··· 168 162 169 163 am62->offset = args.args[0]; 170 164 165 + /* Core voltage. PHY_CORE_VOLTAGE bit Recommended to be 0 always */ 166 + ret = regmap_update_bits(am62->syscon, am62->offset, PHY_CORE_VOLTAGE_MASK, 0); 167 + if (ret) { 168 + dev_err(dev, "failed to set phy core voltage\n"); 169 + return ret; 170 + } 171 + 171 172 ret = regmap_update_bits(am62->syscon, am62->offset, PHY_PLL_REFCLK_MASK, am62->rate_code); 172 173 if (ret) { 173 174 dev_err(dev, "failed to set phy pll reference clock rate\n"); ··· 189 176 struct device *dev = &pdev->dev; 190 177 struct device_node *node = pdev->dev.of_node; 191 178 struct dwc3_am62 *am62; 192 - int i, ret; 193 179 unsigned long rate; 180 + void __iomem *phy; 181 + int i, ret; 194 182 u32 reg; 195 183 196 184 am62 = devm_kzalloc(dev, sizeof(*am62), GFP_KERNEL); ··· 232 218 ret = phy_syscon_pll_refclk(am62); 233 219 if (ret) 234 220 return ret; 221 + 222 + /* Workaround Errata i2409 */ 223 + phy = devm_platform_ioremap_resource(pdev, 1); 224 + if (IS_ERR(phy)) { 225 + dev_err(dev, "can't map PHY IOMEM resource. Won't apply i2409 fix.\n"); 226 + phy = NULL; 227 + } else { 228 + reg = readl(phy + USB_PHY_PLL_REG12); 229 + reg |= USB_PHY_PLL_LDO_REF_EN | USB_PHY_PLL_LDO_REF_EN_EN; 230 + writel(reg, phy + USB_PHY_PLL_REG12); 231 + } 235 232 236 233 /* VBUS divider select */ 237 234 am62->vbus_divider = device_property_read_bool(dev, "ti,vbus-divider"); ··· 292 267 return ret; 293 268 } 294 269 295 - static int dwc3_ti_remove_core(struct device *dev, void *c) 296 - { 297 - struct platform_device *pdev = to_platform_device(dev); 298 - 299 - platform_device_unregister(pdev); 300 - return 0; 301 - } 302 - 303 270 static void dwc3_ti_remove(struct platform_device *pdev) 304 271 { 305 272 struct device *dev = &pdev->dev; 306 273 struct dwc3_am62 *am62 = platform_get_drvdata(pdev); 307 274 u32 reg; 308 275 309 - device_for_each_child(dev, NULL, dwc3_ti_remove_core); 276 + pm_runtime_get_sync(dev); 277 + device_init_wakeup(dev, false); 278 + of_platform_depopulate(dev); 310 279 311 280 /* Clear mode valid bit */ 312 281 reg = dwc3_ti_readl(am62, USBSS_MODE_CONTROL); ··· 308 289 dwc3_ti_writel(am62, USBSS_MODE_CONTROL, reg); 309 290 310 291 pm_runtime_put_sync(dev); 311 - clk_disable_unprepare(am62->usb2_refclk); 312 292 pm_runtime_disable(dev); 313 293 pm_runtime_set_suspended(dev); 314 294 }
+2 -2
drivers/usb/dwc3/dwc3-of-simple.c
··· 52 52 if (of_device_is_compatible(np, "rockchip,rk3399-dwc3")) 53 53 simple->need_reset = true; 54 54 55 - simple->resets = of_reset_control_array_get(np, false, true, 56 - true); 55 + simple->resets = of_reset_control_array_get_optional_exclusive(np); 57 56 if (IS_ERR(simple->resets)) { 58 57 ret = PTR_ERR(simple->resets); 59 58 dev_err(dev, "failed to get device resets, err=%d\n", ret); ··· 172 173 { .compatible = "sprd,sc9860-dwc3" }, 173 174 { .compatible = "allwinner,sun50i-h6-dwc3" }, 174 175 { .compatible = "hisilicon,hi3670-dwc3" }, 176 + { .compatible = "hisilicon,hi3798mv200-dwc3" }, 175 177 { .compatible = "intel,keembay-dwc3" }, 176 178 { /* Sentinel */ } 177 179 };
+12 -264
drivers/usb/dwc3/dwc3-qcom.c
··· 4 4 * Inspired by dwc3-of-simple.c 5 5 */ 6 6 7 - #include <linux/acpi.h> 8 7 #include <linux/io.h> 9 8 #include <linux/of.h> 10 9 #include <linux/clk.h> ··· 52 53 #define APPS_USB_AVG_BW 0 53 54 #define APPS_USB_PEAK_BW MBps_to_icc(40) 54 55 55 - struct dwc3_acpi_pdata { 56 - u32 qscratch_base_offset; 57 - u32 qscratch_base_size; 58 - u32 dwc3_core_base_size; 59 - int qusb2_phy_irq_index; 60 - int dp_hs_phy_irq_index; 61 - int dm_hs_phy_irq_index; 62 - int ss_phy_irq_index; 63 - bool is_urs; 64 - }; 65 - 66 56 struct dwc3_qcom { 67 57 struct device *dev; 68 58 void __iomem *qscratch_base; 69 59 struct platform_device *dwc3; 70 - struct platform_device *urs_usb; 71 60 struct clk **clks; 72 61 int num_clocks; 73 62 struct reset_control *resets; ··· 70 83 struct extcon_dev *host_edev; 71 84 struct notifier_block vbus_nb; 72 85 struct notifier_block host_nb; 73 - 74 - const struct dwc3_acpi_pdata *acpi_pdata; 75 86 76 87 enum usb_dr_mode mode; 77 88 bool is_suspended; ··· 232 247 enum usb_device_speed max_speed; 233 248 struct device *dev = qcom->dev; 234 249 int ret; 235 - 236 - if (has_acpi_companion(dev)) 237 - return 0; 238 250 239 251 qcom->icc_path_ddr = of_icc_get(dev, "usb-ddr"); 240 252 if (IS_ERR(qcom->icc_path_ddr)) { ··· 501 519 PIPE_UTMI_CLK_DIS); 502 520 } 503 521 504 - static int dwc3_qcom_get_irq(struct platform_device *pdev, 505 - const char *name, int num) 506 - { 507 - struct dwc3_qcom *qcom = platform_get_drvdata(pdev); 508 - struct platform_device *pdev_irq = qcom->urs_usb ? qcom->urs_usb : pdev; 509 - struct device_node *np = pdev->dev.of_node; 510 - int ret; 511 - 512 - if (np) 513 - ret = platform_get_irq_byname_optional(pdev_irq, name); 514 - else 515 - ret = platform_get_irq_optional(pdev_irq, num); 516 - 517 - return ret; 518 - } 519 - 520 522 static int dwc3_qcom_setup_irq(struct platform_device *pdev) 521 523 { 522 524 struct dwc3_qcom *qcom = platform_get_drvdata(pdev); 523 - const struct dwc3_acpi_pdata *pdata = qcom->acpi_pdata; 524 525 int irq; 525 526 int ret; 526 527 527 - irq = dwc3_qcom_get_irq(pdev, "qusb2_phy", 528 - pdata ? pdata->qusb2_phy_irq_index : -1); 528 + irq = platform_get_irq_byname_optional(pdev, "qusb2_phy"); 529 529 if (irq > 0) { 530 530 /* Keep wakeup interrupts disabled until suspend */ 531 531 ret = devm_request_threaded_irq(qcom->dev, irq, NULL, ··· 521 557 qcom->qusb2_phy_irq = irq; 522 558 } 523 559 524 - irq = dwc3_qcom_get_irq(pdev, "dp_hs_phy_irq", 525 - pdata ? pdata->dp_hs_phy_irq_index : -1); 560 + irq = platform_get_irq_byname_optional(pdev, "dp_hs_phy_irq"); 526 561 if (irq > 0) { 527 562 ret = devm_request_threaded_irq(qcom->dev, irq, NULL, 528 563 qcom_dwc3_resume_irq, ··· 534 571 qcom->dp_hs_phy_irq = irq; 535 572 } 536 573 537 - irq = dwc3_qcom_get_irq(pdev, "dm_hs_phy_irq", 538 - pdata ? pdata->dm_hs_phy_irq_index : -1); 574 + irq = platform_get_irq_byname_optional(pdev, "dm_hs_phy_irq"); 539 575 if (irq > 0) { 540 576 ret = devm_request_threaded_irq(qcom->dev, irq, NULL, 541 577 qcom_dwc3_resume_irq, ··· 547 585 qcom->dm_hs_phy_irq = irq; 548 586 } 549 587 550 - irq = dwc3_qcom_get_irq(pdev, "ss_phy_irq", 551 - pdata ? pdata->ss_phy_irq_index : -1); 588 + irq = platform_get_irq_byname_optional(pdev, "ss_phy_irq"); 552 589 if (irq > 0) { 553 590 ret = devm_request_threaded_irq(qcom->dev, irq, NULL, 554 591 qcom_dwc3_resume_irq, ··· 610 649 return 0; 611 650 } 612 651 613 - static const struct property_entry dwc3_qcom_acpi_properties[] = { 614 - PROPERTY_ENTRY_STRING("dr_mode", "host"), 615 - {} 616 - }; 617 - 618 - static const struct software_node dwc3_qcom_swnode = { 619 - .properties = dwc3_qcom_acpi_properties, 620 - }; 621 - 622 - static int dwc3_qcom_acpi_register_core(struct platform_device *pdev) 623 - { 624 - struct dwc3_qcom *qcom = platform_get_drvdata(pdev); 625 - struct device *dev = &pdev->dev; 626 - struct resource *res, *child_res = NULL; 627 - struct platform_device *pdev_irq = qcom->urs_usb ? qcom->urs_usb : 628 - pdev; 629 - int irq; 630 - int ret; 631 - 632 - qcom->dwc3 = platform_device_alloc("dwc3", PLATFORM_DEVID_AUTO); 633 - if (!qcom->dwc3) 634 - return -ENOMEM; 635 - 636 - qcom->dwc3->dev.parent = dev; 637 - qcom->dwc3->dev.type = dev->type; 638 - qcom->dwc3->dev.dma_mask = dev->dma_mask; 639 - qcom->dwc3->dev.dma_parms = dev->dma_parms; 640 - qcom->dwc3->dev.coherent_dma_mask = dev->coherent_dma_mask; 641 - 642 - child_res = kcalloc(2, sizeof(*child_res), GFP_KERNEL); 643 - if (!child_res) { 644 - platform_device_put(qcom->dwc3); 645 - return -ENOMEM; 646 - } 647 - 648 - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 649 - if (!res) { 650 - dev_err(&pdev->dev, "failed to get memory resource\n"); 651 - ret = -ENODEV; 652 - goto out; 653 - } 654 - 655 - child_res[0].flags = res->flags; 656 - child_res[0].start = res->start; 657 - child_res[0].end = child_res[0].start + 658 - qcom->acpi_pdata->dwc3_core_base_size; 659 - 660 - irq = platform_get_irq(pdev_irq, 0); 661 - if (irq < 0) { 662 - ret = irq; 663 - goto out; 664 - } 665 - child_res[1].flags = IORESOURCE_IRQ; 666 - child_res[1].start = child_res[1].end = irq; 667 - 668 - ret = platform_device_add_resources(qcom->dwc3, child_res, 2); 669 - if (ret) { 670 - dev_err(&pdev->dev, "failed to add resources\n"); 671 - goto out; 672 - } 673 - 674 - ret = device_add_software_node(&qcom->dwc3->dev, &dwc3_qcom_swnode); 675 - if (ret < 0) { 676 - dev_err(&pdev->dev, "failed to add properties\n"); 677 - goto out; 678 - } 679 - 680 - ret = platform_device_add(qcom->dwc3); 681 - if (ret) { 682 - dev_err(&pdev->dev, "failed to add device\n"); 683 - device_remove_software_node(&qcom->dwc3->dev); 684 - goto out; 685 - } 686 - kfree(child_res); 687 - return 0; 688 - 689 - out: 690 - platform_device_put(qcom->dwc3); 691 - kfree(child_res); 692 - return ret; 693 - } 694 - 695 652 static int dwc3_qcom_of_register_core(struct platform_device *pdev) 696 653 { 697 654 struct dwc3_qcom *qcom = platform_get_drvdata(pdev); ··· 642 763 return ret; 643 764 } 644 765 645 - static struct platform_device *dwc3_qcom_create_urs_usb_platdev(struct device *dev) 646 - { 647 - struct platform_device *urs_usb = NULL; 648 - struct fwnode_handle *fwh; 649 - struct acpi_device *adev; 650 - char name[8]; 651 - int ret; 652 - int id; 653 - 654 - /* Figure out device id */ 655 - ret = sscanf(fwnode_get_name(dev->fwnode), "URS%d", &id); 656 - if (!ret) 657 - return NULL; 658 - 659 - /* Find the child using name */ 660 - snprintf(name, sizeof(name), "USB%d", id); 661 - fwh = fwnode_get_named_child_node(dev->fwnode, name); 662 - if (!fwh) 663 - return NULL; 664 - 665 - adev = to_acpi_device_node(fwh); 666 - if (!adev) 667 - goto err_put_handle; 668 - 669 - urs_usb = acpi_create_platform_device(adev, NULL); 670 - if (IS_ERR_OR_NULL(urs_usb)) 671 - goto err_put_handle; 672 - 673 - return urs_usb; 674 - 675 - err_put_handle: 676 - fwnode_handle_put(fwh); 677 - 678 - return urs_usb; 679 - } 680 - 681 - static void dwc3_qcom_destroy_urs_usb_platdev(struct platform_device *urs_usb) 682 - { 683 - struct fwnode_handle *fwh = urs_usb->dev.fwnode; 684 - 685 - platform_device_unregister(urs_usb); 686 - fwnode_handle_put(fwh); 687 - } 688 - 689 766 static int dwc3_qcom_probe(struct platform_device *pdev) 690 767 { 691 768 struct device_node *np = pdev->dev.of_node; 692 769 struct device *dev = &pdev->dev; 693 770 struct dwc3_qcom *qcom; 694 - struct resource *res, *parent_res = NULL; 695 - struct resource local_res; 771 + struct resource *res; 696 772 int ret, i; 697 773 bool ignore_pipe_clk; 698 774 bool wakeup_source; ··· 658 824 659 825 platform_set_drvdata(pdev, qcom); 660 826 qcom->dev = &pdev->dev; 661 - 662 - if (has_acpi_companion(dev)) { 663 - qcom->acpi_pdata = acpi_device_get_match_data(dev); 664 - if (!qcom->acpi_pdata) { 665 - dev_err(&pdev->dev, "no supporting ACPI device data\n"); 666 - return -EINVAL; 667 - } 668 - } 669 827 670 828 qcom->resets = devm_reset_control_array_get_optional_exclusive(dev); 671 829 if (IS_ERR(qcom->resets)) { ··· 687 861 688 862 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 689 863 690 - if (np) { 691 - parent_res = res; 692 - } else { 693 - memcpy(&local_res, res, sizeof(struct resource)); 694 - parent_res = &local_res; 695 - 696 - parent_res->start = res->start + 697 - qcom->acpi_pdata->qscratch_base_offset; 698 - parent_res->end = parent_res->start + 699 - qcom->acpi_pdata->qscratch_base_size; 700 - 701 - if (qcom->acpi_pdata->is_urs) { 702 - qcom->urs_usb = dwc3_qcom_create_urs_usb_platdev(dev); 703 - if (IS_ERR_OR_NULL(qcom->urs_usb)) { 704 - dev_err(dev, "failed to create URS USB platdev\n"); 705 - if (!qcom->urs_usb) 706 - ret = -ENODEV; 707 - else 708 - ret = PTR_ERR(qcom->urs_usb); 709 - goto clk_disable; 710 - } 711 - } 712 - } 713 - 714 - qcom->qscratch_base = devm_ioremap_resource(dev, parent_res); 864 + qcom->qscratch_base = devm_ioremap_resource(dev, res); 715 865 if (IS_ERR(qcom->qscratch_base)) { 716 866 ret = PTR_ERR(qcom->qscratch_base); 717 - goto free_urs; 867 + goto clk_disable; 718 868 } 719 869 720 870 ret = dwc3_qcom_setup_irq(pdev); 721 871 if (ret) { 722 872 dev_err(dev, "failed to setup IRQs, err=%d\n", ret); 723 - goto free_urs; 873 + goto clk_disable; 724 874 } 725 875 726 876 /* ··· 708 906 if (ignore_pipe_clk) 709 907 dwc3_qcom_select_utmi_clk(qcom); 710 908 711 - if (np) 712 - ret = dwc3_qcom_of_register_core(pdev); 713 - else 714 - ret = dwc3_qcom_acpi_register_core(pdev); 715 - 909 + ret = dwc3_qcom_of_register_core(pdev); 716 910 if (ret) { 717 911 dev_err(dev, "failed to register DWC3 Core, err=%d\n", ret); 718 - goto free_urs; 912 + goto clk_disable; 719 913 } 720 914 721 915 ret = dwc3_qcom_interconnect_init(qcom); ··· 743 945 interconnect_exit: 744 946 dwc3_qcom_interconnect_exit(qcom); 745 947 depopulate: 746 - if (np) { 747 - of_platform_depopulate(&pdev->dev); 748 - } else { 749 - device_remove_software_node(&qcom->dwc3->dev); 750 - platform_device_del(qcom->dwc3); 751 - } 948 + of_platform_depopulate(&pdev->dev); 752 949 platform_device_put(qcom->dwc3); 753 - free_urs: 754 - if (qcom->urs_usb) 755 - dwc3_qcom_destroy_urs_usb_platdev(qcom->urs_usb); 756 950 clk_disable: 757 951 for (i = qcom->num_clocks - 1; i >= 0; i--) { 758 952 clk_disable_unprepare(qcom->clks[i]); ··· 759 969 static void dwc3_qcom_remove(struct platform_device *pdev) 760 970 { 761 971 struct dwc3_qcom *qcom = platform_get_drvdata(pdev); 762 - struct device_node *np = pdev->dev.of_node; 763 972 struct device *dev = &pdev->dev; 764 973 int i; 765 974 766 - if (np) { 767 - of_platform_depopulate(&pdev->dev); 768 - } else { 769 - device_remove_software_node(&qcom->dwc3->dev); 770 - platform_device_del(qcom->dwc3); 771 - } 975 + of_platform_depopulate(&pdev->dev); 772 976 platform_device_put(qcom->dwc3); 773 - 774 - if (qcom->urs_usb) 775 - dwc3_qcom_destroy_urs_usb_platdev(qcom->urs_usb); 776 977 777 978 for (i = qcom->num_clocks - 1; i >= 0; i--) { 778 979 clk_disable_unprepare(qcom->clks[i]); ··· 834 1053 }; 835 1054 MODULE_DEVICE_TABLE(of, dwc3_qcom_of_match); 836 1055 837 - #ifdef CONFIG_ACPI 838 - static const struct dwc3_acpi_pdata sdm845_acpi_pdata = { 839 - .qscratch_base_offset = SDM845_QSCRATCH_BASE_OFFSET, 840 - .qscratch_base_size = SDM845_QSCRATCH_SIZE, 841 - .dwc3_core_base_size = SDM845_DWC3_CORE_SIZE, 842 - .qusb2_phy_irq_index = 1, 843 - .dp_hs_phy_irq_index = 4, 844 - .dm_hs_phy_irq_index = 3, 845 - .ss_phy_irq_index = 2 846 - }; 847 - 848 - static const struct dwc3_acpi_pdata sdm845_acpi_urs_pdata = { 849 - .qscratch_base_offset = SDM845_QSCRATCH_BASE_OFFSET, 850 - .qscratch_base_size = SDM845_QSCRATCH_SIZE, 851 - .dwc3_core_base_size = SDM845_DWC3_CORE_SIZE, 852 - .qusb2_phy_irq_index = 1, 853 - .dp_hs_phy_irq_index = 4, 854 - .dm_hs_phy_irq_index = 3, 855 - .ss_phy_irq_index = 2, 856 - .is_urs = true, 857 - }; 858 - 859 - static const struct acpi_device_id dwc3_qcom_acpi_match[] = { 860 - { "QCOM2430", (unsigned long)&sdm845_acpi_pdata }, 861 - { "QCOM0304", (unsigned long)&sdm845_acpi_urs_pdata }, 862 - { "QCOM0497", (unsigned long)&sdm845_acpi_urs_pdata }, 863 - { "QCOM04A6", (unsigned long)&sdm845_acpi_pdata }, 864 - { }, 865 - }; 866 - MODULE_DEVICE_TABLE(acpi, dwc3_qcom_acpi_match); 867 - #endif 868 - 869 1056 static struct platform_driver dwc3_qcom_driver = { 870 1057 .probe = dwc3_qcom_probe, 871 1058 .remove_new = dwc3_qcom_remove, ··· 841 1092 .name = "dwc3-qcom", 842 1093 .pm = &dwc3_qcom_dev_pm_ops, 843 1094 .of_match_table = dwc3_qcom_of_match, 844 - .acpi_match_table = ACPI_PTR(dwc3_qcom_acpi_match), 845 1095 }, 846 1096 }; 847 1097
+1
drivers/usb/dwc3/ep0.c
··· 646 646 return -EINVAL; 647 647 648 648 case USB_STATE_ADDRESS: 649 + dwc3_gadget_start_config(dwc, 2); 649 650 dwc3_gadget_clear_tx_fifos(dwc); 650 651 651 652 ret = dwc3_ep0_delegate_req(dwc, ctrl);
+39 -52
drivers/usb/dwc3/gadget.c
··· 519 519 static int dwc3_gadget_set_xfer_resource(struct dwc3_ep *dep) 520 520 { 521 521 struct dwc3_gadget_ep_cmd_params params; 522 + int ret; 523 + 524 + if (dep->flags & DWC3_EP_RESOURCE_ALLOCATED) 525 + return 0; 522 526 523 527 memset(&params, 0x00, sizeof(params)); 524 528 525 529 params.param0 = DWC3_DEPXFERCFG_NUM_XFER_RES(1); 526 530 527 - return dwc3_send_gadget_ep_cmd(dep, DWC3_DEPCMD_SETTRANSFRESOURCE, 531 + ret = dwc3_send_gadget_ep_cmd(dep, DWC3_DEPCMD_SETTRANSFRESOURCE, 528 532 &params); 533 + if (ret) 534 + return ret; 535 + 536 + dep->flags |= DWC3_EP_RESOURCE_ALLOCATED; 537 + return 0; 529 538 } 530 539 531 540 /** 532 - * dwc3_gadget_start_config - configure ep resources 533 - * @dep: endpoint that is being enabled 541 + * dwc3_gadget_start_config - reset endpoint resources 542 + * @dwc: pointer to the DWC3 context 543 + * @resource_index: DEPSTARTCFG.XferRscIdx value (must be 0 or 2) 534 544 * 535 - * Issue a %DWC3_DEPCMD_DEPSTARTCFG command to @dep. After the command's 536 - * completion, it will set Transfer Resource for all available endpoints. 545 + * Set resource_index=0 to reset all endpoints' resources allocation. Do this as 546 + * part of the power-on/soft-reset initialization. 537 547 * 538 - * The assignment of transfer resources cannot perfectly follow the data book 539 - * due to the fact that the controller driver does not have all knowledge of the 540 - * configuration in advance. It is given this information piecemeal by the 541 - * composite gadget framework after every SET_CONFIGURATION and 542 - * SET_INTERFACE. Trying to follow the databook programming model in this 543 - * scenario can cause errors. For two reasons: 544 - * 545 - * 1) The databook says to do %DWC3_DEPCMD_DEPSTARTCFG for every 546 - * %USB_REQ_SET_CONFIGURATION and %USB_REQ_SET_INTERFACE (8.1.5). This is 547 - * incorrect in the scenario of multiple interfaces. 548 - * 549 - * 2) The databook does not mention doing more %DWC3_DEPCMD_DEPXFERCFG for new 550 - * endpoint on alt setting (8.1.6). 551 - * 552 - * The following simplified method is used instead: 553 - * 554 - * All hardware endpoints can be assigned a transfer resource and this setting 555 - * will stay persistent until either a core reset or hibernation. So whenever we 556 - * do a %DWC3_DEPCMD_DEPSTARTCFG(0) we can go ahead and do 557 - * %DWC3_DEPCMD_DEPXFERCFG for every hardware endpoint as well. We are 558 - * guaranteed that there are as many transfer resources as endpoints. 559 - * 560 - * This function is called for each endpoint when it is being enabled but is 561 - * triggered only when called for EP0-out, which always happens first, and which 562 - * should only happen in one of the above conditions. 548 + * Set resource_index=2 to reset only non-control endpoints' resources. Do this 549 + * on receiving the SET_CONFIGURATION request or hibernation resume. 563 550 */ 564 - static int dwc3_gadget_start_config(struct dwc3_ep *dep) 551 + int dwc3_gadget_start_config(struct dwc3 *dwc, unsigned int resource_index) 565 552 { 566 553 struct dwc3_gadget_ep_cmd_params params; 567 - struct dwc3 *dwc; 568 554 u32 cmd; 569 555 int i; 570 556 int ret; 571 557 572 - if (dep->number) 573 - return 0; 558 + if (resource_index != 0 && resource_index != 2) 559 + return -EINVAL; 574 560 575 561 memset(&params, 0x00, sizeof(params)); 576 562 cmd = DWC3_DEPCMD_DEPSTARTCFG; 577 - dwc = dep->dwc; 563 + cmd |= DWC3_DEPCMD_PARAM(resource_index); 578 564 579 - ret = dwc3_send_gadget_ep_cmd(dep, cmd, &params); 565 + ret = dwc3_send_gadget_ep_cmd(dwc->eps[0], cmd, &params); 580 566 if (ret) 581 567 return ret; 582 568 583 - for (i = 0; i < DWC3_ENDPOINTS_NUM; i++) { 584 - struct dwc3_ep *dep = dwc->eps[i]; 585 - 586 - if (!dep) 587 - continue; 588 - 589 - ret = dwc3_gadget_set_xfer_resource(dep); 590 - if (ret) 591 - return ret; 592 - } 569 + /* Reset resource allocation flags */ 570 + for (i = resource_index; i < dwc->num_eps && dwc->eps[i]; i++) 571 + dwc->eps[i]->flags &= ~DWC3_EP_RESOURCE_ALLOCATED; 593 572 594 573 return 0; 595 574 } ··· 863 884 ret = dwc3_gadget_resize_tx_fifos(dep); 864 885 if (ret) 865 886 return ret; 866 - 867 - ret = dwc3_gadget_start_config(dep); 868 - if (ret) 869 - return ret; 870 887 } 871 888 872 889 ret = dwc3_gadget_set_ep_config(dep, action); 873 890 if (ret) 874 891 return ret; 892 + 893 + if (!(dep->flags & DWC3_EP_RESOURCE_ALLOCATED)) { 894 + ret = dwc3_gadget_set_xfer_resource(dep); 895 + if (ret) 896 + return ret; 897 + } 875 898 876 899 if (!(dep->flags & DWC3_EP_ENABLED)) { 877 900 struct dwc3_trb *trb_st_hw; ··· 1028 1047 1029 1048 dep->stream_capable = false; 1030 1049 dep->type = 0; 1031 - mask = DWC3_EP_TXFIFO_RESIZED; 1050 + mask = DWC3_EP_TXFIFO_RESIZED | DWC3_EP_RESOURCE_ALLOCATED; 1032 1051 /* 1033 1052 * dwc3_remove_requests() can exit early if DWC3 EP delayed stop is 1034 1053 * set. Do not clear DEP flags, so that the end transfer command will ··· 2894 2913 /* Start with SuperSpeed Default */ 2895 2914 dwc3_gadget_ep0_desc.wMaxPacketSize = cpu_to_le16(512); 2896 2915 2916 + ret = dwc3_gadget_start_config(dwc, 0); 2917 + if (ret) { 2918 + dev_err(dwc->dev, "failed to config endpoints\n"); 2919 + return ret; 2920 + } 2921 + 2897 2922 dep = dwc->eps[0]; 2898 2923 dep->flags = 0; 2899 2924 ret = __dwc3_gadget_ep_enable(dep, DWC3_DEPCFG_ACTION_INIT); ··· 3415 3428 struct dwc3_request *req, const struct dwc3_event_depevt *event, 3416 3429 int status) 3417 3430 { 3418 - struct dwc3_trb *trb = &dep->trb_pool[dep->trb_dequeue]; 3431 + struct dwc3_trb *trb; 3419 3432 struct scatterlist *sg = req->sg; 3420 3433 struct scatterlist *s; 3421 3434 unsigned int num_queued = req->num_queued_sgs;
+1
drivers/usb/dwc3/gadget.h
··· 119 119 int __dwc3_gadget_ep_set_halt(struct dwc3_ep *dep, int value, int protocol); 120 120 void dwc3_ep0_send_delayed_status(struct dwc3 *dwc); 121 121 void dwc3_stop_active_transfer(struct dwc3_ep *dep, bool force, bool interrupt); 122 + int dwc3_gadget_start_config(struct dwc3 *dwc, unsigned int resource_index); 122 123 123 124 /** 124 125 * dwc3_gadget_ep_get_transfer_index - Gets transfer index from HW
+50
drivers/usb/dwc3/host.c
··· 11 11 #include <linux/of.h> 12 12 #include <linux/platform_device.h> 13 13 14 + #include "../host/xhci-port.h" 15 + #include "../host/xhci-ext-caps.h" 16 + #include "../host/xhci-caps.h" 14 17 #include "core.h" 18 + 19 + #define XHCI_HCSPARAMS1 0x4 20 + #define XHCI_PORTSC_BASE 0x400 21 + 22 + /** 23 + * dwc3_power_off_all_roothub_ports - Power off all Root hub ports 24 + * @dwc: Pointer to our controller context structure 25 + */ 26 + static void dwc3_power_off_all_roothub_ports(struct dwc3 *dwc) 27 + { 28 + void __iomem *xhci_regs; 29 + u32 op_regs_base; 30 + int port_num; 31 + u32 offset; 32 + u32 reg; 33 + int i; 34 + 35 + /* xhci regs is not mapped yet, do it temperary here */ 36 + if (dwc->xhci_resources[0].start) { 37 + xhci_regs = ioremap(dwc->xhci_resources[0].start, DWC3_XHCI_REGS_END); 38 + if (!xhci_regs) { 39 + dev_err(dwc->dev, "Failed to ioremap xhci_regs\n"); 40 + return; 41 + } 42 + 43 + op_regs_base = HC_LENGTH(readl(xhci_regs)); 44 + reg = readl(xhci_regs + XHCI_HCSPARAMS1); 45 + port_num = HCS_MAX_PORTS(reg); 46 + 47 + for (i = 1; i <= port_num; i++) { 48 + offset = op_regs_base + XHCI_PORTSC_BASE + 0x10 * (i - 1); 49 + reg = readl(xhci_regs + offset); 50 + reg &= ~PORT_POWER; 51 + writel(reg, xhci_regs + offset); 52 + } 53 + 54 + iounmap(xhci_regs); 55 + } else { 56 + dev_err(dwc->dev, "xhci base reg invalid\n"); 57 + } 58 + } 15 59 16 60 static void dwc3_host_fill_xhci_irq_res(struct dwc3 *dwc, 17 61 int irq, char *name) ··· 109 65 struct platform_device *xhci; 110 66 int ret, irq; 111 67 int prop_idx = 0; 68 + 69 + /* 70 + * Some platforms need to power off all Root hub ports immediately after DWC3 set to host 71 + * mode to avoid VBUS glitch happen when xhci get reset later. 72 + */ 73 + dwc3_power_off_all_roothub_ports(dwc); 112 74 113 75 irq = dwc3_host_get_irq(dwc); 114 76 if (irq < 0)
+1
drivers/usb/gadget/Kconfig
··· 190 190 tristate 191 191 192 192 config USB_F_FS 193 + select DMA_SHARED_BUFFER 193 194 tristate 194 195 195 196 config USB_F_UAC1
+513 -20
drivers/usb/gadget/function/f_fs.c
··· 15 15 /* #define VERBOSE_DEBUG */ 16 16 17 17 #include <linux/blkdev.h> 18 + #include <linux/dma-buf.h> 19 + #include <linux/dma-fence.h> 20 + #include <linux/dma-resv.h> 18 21 #include <linux/pagemap.h> 19 22 #include <linux/export.h> 20 23 #include <linux/fs_parser.h> ··· 45 42 #include "configfs.h" 46 43 47 44 #define FUNCTIONFS_MAGIC 0xa647361 /* Chosen by a honest dice roll ;) */ 45 + 46 + MODULE_IMPORT_NS(DMA_BUF); 48 47 49 48 /* Reference counter handling */ 50 49 static void ffs_data_get(struct ffs_data *ffs); ··· 129 124 u8 num; 130 125 }; 131 126 127 + struct ffs_dmabuf_priv { 128 + struct list_head entry; 129 + struct kref ref; 130 + struct ffs_data *ffs; 131 + struct dma_buf_attachment *attach; 132 + struct sg_table *sgt; 133 + enum dma_data_direction dir; 134 + spinlock_t lock; 135 + u64 context; 136 + struct usb_request *req; /* P: ffs->eps_lock */ 137 + struct usb_ep *ep; /* P: ffs->eps_lock */ 138 + }; 139 + 140 + struct ffs_dma_fence { 141 + struct dma_fence base; 142 + struct ffs_dmabuf_priv *priv; 143 + struct work_struct work; 144 + }; 145 + 132 146 struct ffs_epfile { 133 147 /* Protects ep->ep and ep->req. */ 134 148 struct mutex mutex; ··· 221 197 unsigned char isoc; /* P: ffs->eps_lock */ 222 198 223 199 unsigned char _pad; 200 + 201 + /* Protects dmabufs */ 202 + struct mutex dmabufs_mutex; 203 + struct list_head dmabufs; /* P: dmabufs_mutex */ 204 + atomic_t seqno; 224 205 }; 225 206 226 207 struct ffs_buffer { ··· 963 934 return ret; 964 935 } 965 936 937 + static struct ffs_ep *ffs_epfile_wait_ep(struct file *file) 938 + { 939 + struct ffs_epfile *epfile = file->private_data; 940 + struct ffs_ep *ep; 941 + int ret; 942 + 943 + /* Wait for endpoint to be enabled */ 944 + ep = epfile->ep; 945 + if (!ep) { 946 + if (file->f_flags & O_NONBLOCK) 947 + return ERR_PTR(-EAGAIN); 948 + 949 + ret = wait_event_interruptible( 950 + epfile->ffs->wait, (ep = epfile->ep)); 951 + if (ret) 952 + return ERR_PTR(-EINTR); 953 + } 954 + 955 + return ep; 956 + } 957 + 966 958 static ssize_t ffs_epfile_io(struct file *file, struct ffs_io_data *io_data) 967 959 { 968 960 struct ffs_epfile *epfile = file->private_data; ··· 997 947 if (WARN_ON(epfile->ffs->state != FFS_ACTIVE)) 998 948 return -ENODEV; 999 949 1000 - /* Wait for endpoint to be enabled */ 1001 - ep = epfile->ep; 1002 - if (!ep) { 1003 - if (file->f_flags & O_NONBLOCK) 1004 - return -EAGAIN; 1005 - 1006 - ret = wait_event_interruptible( 1007 - epfile->ffs->wait, (ep = epfile->ep)); 1008 - if (ret) 1009 - return -EINTR; 1010 - } 950 + ep = ffs_epfile_wait_ep(file); 951 + if (IS_ERR(ep)) 952 + return PTR_ERR(ep); 1011 953 1012 954 /* Do we halt? */ 1013 955 halt = (!io_data->read == !epfile->in); ··· 1300 1258 return res; 1301 1259 } 1302 1260 1261 + static void ffs_dmabuf_release(struct kref *ref) 1262 + { 1263 + struct ffs_dmabuf_priv *priv = container_of(ref, struct ffs_dmabuf_priv, ref); 1264 + struct dma_buf_attachment *attach = priv->attach; 1265 + struct dma_buf *dmabuf = attach->dmabuf; 1266 + 1267 + pr_vdebug("FFS DMABUF release\n"); 1268 + dma_resv_lock(dmabuf->resv, NULL); 1269 + dma_buf_unmap_attachment(attach, priv->sgt, priv->dir); 1270 + dma_resv_unlock(dmabuf->resv); 1271 + 1272 + dma_buf_detach(attach->dmabuf, attach); 1273 + dma_buf_put(dmabuf); 1274 + kfree(priv); 1275 + } 1276 + 1277 + static void ffs_dmabuf_get(struct dma_buf_attachment *attach) 1278 + { 1279 + struct ffs_dmabuf_priv *priv = attach->importer_priv; 1280 + 1281 + kref_get(&priv->ref); 1282 + } 1283 + 1284 + static void ffs_dmabuf_put(struct dma_buf_attachment *attach) 1285 + { 1286 + struct ffs_dmabuf_priv *priv = attach->importer_priv; 1287 + 1288 + kref_put(&priv->ref, ffs_dmabuf_release); 1289 + } 1290 + 1303 1291 static int 1304 1292 ffs_epfile_release(struct inode *inode, struct file *file) 1305 1293 { 1306 1294 struct ffs_epfile *epfile = inode->i_private; 1295 + struct ffs_dmabuf_priv *priv, *tmp; 1296 + struct ffs_data *ffs = epfile->ffs; 1297 + 1298 + mutex_lock(&epfile->dmabufs_mutex); 1299 + 1300 + /* Close all attached DMABUFs */ 1301 + list_for_each_entry_safe(priv, tmp, &epfile->dmabufs, entry) { 1302 + /* Cancel any pending transfer */ 1303 + spin_lock_irq(&ffs->eps_lock); 1304 + if (priv->ep && priv->req) 1305 + usb_ep_dequeue(priv->ep, priv->req); 1306 + spin_unlock_irq(&ffs->eps_lock); 1307 + 1308 + list_del(&priv->entry); 1309 + ffs_dmabuf_put(priv->attach); 1310 + } 1311 + 1312 + mutex_unlock(&epfile->dmabufs_mutex); 1307 1313 1308 1314 __ffs_epfile_read_buffer_free(epfile); 1309 1315 ffs_data_closed(epfile->ffs); 1310 1316 1311 1317 return 0; 1318 + } 1319 + 1320 + static void ffs_dmabuf_cleanup(struct work_struct *work) 1321 + { 1322 + struct ffs_dma_fence *dma_fence = 1323 + container_of(work, struct ffs_dma_fence, work); 1324 + struct ffs_dmabuf_priv *priv = dma_fence->priv; 1325 + struct dma_buf_attachment *attach = priv->attach; 1326 + struct dma_fence *fence = &dma_fence->base; 1327 + 1328 + ffs_dmabuf_put(attach); 1329 + dma_fence_put(fence); 1330 + } 1331 + 1332 + static void ffs_dmabuf_signal_done(struct ffs_dma_fence *dma_fence, int ret) 1333 + { 1334 + struct ffs_dmabuf_priv *priv = dma_fence->priv; 1335 + struct dma_fence *fence = &dma_fence->base; 1336 + bool cookie = dma_fence_begin_signalling(); 1337 + 1338 + dma_fence_get(fence); 1339 + fence->error = ret; 1340 + dma_fence_signal(fence); 1341 + dma_fence_end_signalling(cookie); 1342 + 1343 + /* 1344 + * The fence will be unref'd in ffs_dmabuf_cleanup. 1345 + * It can't be done here, as the unref functions might try to lock 1346 + * the resv object, which would deadlock. 1347 + */ 1348 + INIT_WORK(&dma_fence->work, ffs_dmabuf_cleanup); 1349 + queue_work(priv->ffs->io_completion_wq, &dma_fence->work); 1350 + } 1351 + 1352 + static void ffs_epfile_dmabuf_io_complete(struct usb_ep *ep, 1353 + struct usb_request *req) 1354 + { 1355 + pr_vdebug("FFS: DMABUF transfer complete, status=%d\n", req->status); 1356 + ffs_dmabuf_signal_done(req->context, req->status); 1357 + usb_ep_free_request(ep, req); 1358 + } 1359 + 1360 + static const char *ffs_dmabuf_get_driver_name(struct dma_fence *fence) 1361 + { 1362 + return "functionfs"; 1363 + } 1364 + 1365 + static const char *ffs_dmabuf_get_timeline_name(struct dma_fence *fence) 1366 + { 1367 + return ""; 1368 + } 1369 + 1370 + static void ffs_dmabuf_fence_release(struct dma_fence *fence) 1371 + { 1372 + struct ffs_dma_fence *dma_fence = 1373 + container_of(fence, struct ffs_dma_fence, base); 1374 + 1375 + kfree(dma_fence); 1376 + } 1377 + 1378 + static const struct dma_fence_ops ffs_dmabuf_fence_ops = { 1379 + .get_driver_name = ffs_dmabuf_get_driver_name, 1380 + .get_timeline_name = ffs_dmabuf_get_timeline_name, 1381 + .release = ffs_dmabuf_fence_release, 1382 + }; 1383 + 1384 + static int ffs_dma_resv_lock(struct dma_buf *dmabuf, bool nonblock) 1385 + { 1386 + if (!nonblock) 1387 + return dma_resv_lock_interruptible(dmabuf->resv, NULL); 1388 + 1389 + if (!dma_resv_trylock(dmabuf->resv)) 1390 + return -EBUSY; 1391 + 1392 + return 0; 1393 + } 1394 + 1395 + static struct dma_buf_attachment * 1396 + ffs_dmabuf_find_attachment(struct ffs_epfile *epfile, struct dma_buf *dmabuf) 1397 + { 1398 + struct device *dev = epfile->ffs->gadget->dev.parent; 1399 + struct dma_buf_attachment *attach = NULL; 1400 + struct ffs_dmabuf_priv *priv; 1401 + 1402 + mutex_lock(&epfile->dmabufs_mutex); 1403 + 1404 + list_for_each_entry(priv, &epfile->dmabufs, entry) { 1405 + if (priv->attach->dev == dev 1406 + && priv->attach->dmabuf == dmabuf) { 1407 + attach = priv->attach; 1408 + break; 1409 + } 1410 + } 1411 + 1412 + if (attach) 1413 + ffs_dmabuf_get(attach); 1414 + 1415 + mutex_unlock(&epfile->dmabufs_mutex); 1416 + 1417 + return attach ?: ERR_PTR(-EPERM); 1418 + } 1419 + 1420 + static int ffs_dmabuf_attach(struct file *file, int fd) 1421 + { 1422 + bool nonblock = file->f_flags & O_NONBLOCK; 1423 + struct ffs_epfile *epfile = file->private_data; 1424 + struct usb_gadget *gadget = epfile->ffs->gadget; 1425 + struct dma_buf_attachment *attach; 1426 + struct ffs_dmabuf_priv *priv; 1427 + enum dma_data_direction dir; 1428 + struct sg_table *sg_table; 1429 + struct dma_buf *dmabuf; 1430 + int err; 1431 + 1432 + if (!gadget || !gadget->sg_supported) 1433 + return -EPERM; 1434 + 1435 + dmabuf = dma_buf_get(fd); 1436 + if (IS_ERR(dmabuf)) 1437 + return PTR_ERR(dmabuf); 1438 + 1439 + attach = dma_buf_attach(dmabuf, gadget->dev.parent); 1440 + if (IS_ERR(attach)) { 1441 + err = PTR_ERR(attach); 1442 + goto err_dmabuf_put; 1443 + } 1444 + 1445 + priv = kzalloc(sizeof(*priv), GFP_KERNEL); 1446 + if (!priv) { 1447 + err = -ENOMEM; 1448 + goto err_dmabuf_detach; 1449 + } 1450 + 1451 + dir = epfile->in ? DMA_FROM_DEVICE : DMA_TO_DEVICE; 1452 + 1453 + err = ffs_dma_resv_lock(dmabuf, nonblock); 1454 + if (err) 1455 + goto err_free_priv; 1456 + 1457 + sg_table = dma_buf_map_attachment(attach, dir); 1458 + dma_resv_unlock(dmabuf->resv); 1459 + 1460 + if (IS_ERR(sg_table)) { 1461 + err = PTR_ERR(sg_table); 1462 + goto err_free_priv; 1463 + } 1464 + 1465 + attach->importer_priv = priv; 1466 + 1467 + priv->sgt = sg_table; 1468 + priv->dir = dir; 1469 + priv->ffs = epfile->ffs; 1470 + priv->attach = attach; 1471 + spin_lock_init(&priv->lock); 1472 + kref_init(&priv->ref); 1473 + priv->context = dma_fence_context_alloc(1); 1474 + 1475 + mutex_lock(&epfile->dmabufs_mutex); 1476 + list_add(&priv->entry, &epfile->dmabufs); 1477 + mutex_unlock(&epfile->dmabufs_mutex); 1478 + 1479 + return 0; 1480 + 1481 + err_free_priv: 1482 + kfree(priv); 1483 + err_dmabuf_detach: 1484 + dma_buf_detach(dmabuf, attach); 1485 + err_dmabuf_put: 1486 + dma_buf_put(dmabuf); 1487 + 1488 + return err; 1489 + } 1490 + 1491 + static int ffs_dmabuf_detach(struct file *file, int fd) 1492 + { 1493 + struct ffs_epfile *epfile = file->private_data; 1494 + struct ffs_data *ffs = epfile->ffs; 1495 + struct device *dev = ffs->gadget->dev.parent; 1496 + struct ffs_dmabuf_priv *priv, *tmp; 1497 + struct dma_buf *dmabuf; 1498 + int ret = -EPERM; 1499 + 1500 + dmabuf = dma_buf_get(fd); 1501 + if (IS_ERR(dmabuf)) 1502 + return PTR_ERR(dmabuf); 1503 + 1504 + mutex_lock(&epfile->dmabufs_mutex); 1505 + 1506 + list_for_each_entry_safe(priv, tmp, &epfile->dmabufs, entry) { 1507 + if (priv->attach->dev == dev 1508 + && priv->attach->dmabuf == dmabuf) { 1509 + /* Cancel any pending transfer */ 1510 + spin_lock_irq(&ffs->eps_lock); 1511 + if (priv->ep && priv->req) 1512 + usb_ep_dequeue(priv->ep, priv->req); 1513 + spin_unlock_irq(&ffs->eps_lock); 1514 + 1515 + list_del(&priv->entry); 1516 + 1517 + /* Unref the reference from ffs_dmabuf_attach() */ 1518 + ffs_dmabuf_put(priv->attach); 1519 + ret = 0; 1520 + break; 1521 + } 1522 + } 1523 + 1524 + mutex_unlock(&epfile->dmabufs_mutex); 1525 + dma_buf_put(dmabuf); 1526 + 1527 + return ret; 1528 + } 1529 + 1530 + static int ffs_dmabuf_transfer(struct file *file, 1531 + const struct usb_ffs_dmabuf_transfer_req *req) 1532 + { 1533 + bool nonblock = file->f_flags & O_NONBLOCK; 1534 + struct ffs_epfile *epfile = file->private_data; 1535 + struct dma_buf_attachment *attach; 1536 + struct ffs_dmabuf_priv *priv; 1537 + struct ffs_dma_fence *fence; 1538 + struct usb_request *usb_req; 1539 + struct dma_buf *dmabuf; 1540 + struct ffs_ep *ep; 1541 + bool cookie; 1542 + u32 seqno; 1543 + int ret; 1544 + 1545 + if (req->flags & ~USB_FFS_DMABUF_TRANSFER_MASK) 1546 + return -EINVAL; 1547 + 1548 + dmabuf = dma_buf_get(req->fd); 1549 + if (IS_ERR(dmabuf)) 1550 + return PTR_ERR(dmabuf); 1551 + 1552 + if (req->length > dmabuf->size || req->length == 0) { 1553 + ret = -EINVAL; 1554 + goto err_dmabuf_put; 1555 + } 1556 + 1557 + attach = ffs_dmabuf_find_attachment(epfile, dmabuf); 1558 + if (IS_ERR(attach)) { 1559 + ret = PTR_ERR(attach); 1560 + goto err_dmabuf_put; 1561 + } 1562 + 1563 + priv = attach->importer_priv; 1564 + 1565 + ep = ffs_epfile_wait_ep(file); 1566 + if (IS_ERR(ep)) { 1567 + ret = PTR_ERR(ep); 1568 + goto err_attachment_put; 1569 + } 1570 + 1571 + ret = ffs_dma_resv_lock(dmabuf, nonblock); 1572 + if (ret) 1573 + goto err_attachment_put; 1574 + 1575 + /* Make sure we don't have writers */ 1576 + if (!dma_resv_test_signaled(dmabuf->resv, DMA_RESV_USAGE_WRITE)) { 1577 + pr_vdebug("FFS WRITE fence is not signaled\n"); 1578 + ret = -EBUSY; 1579 + goto err_resv_unlock; 1580 + } 1581 + 1582 + /* If we're writing to the DMABUF, make sure we don't have readers */ 1583 + if (epfile->in && 1584 + !dma_resv_test_signaled(dmabuf->resv, DMA_RESV_USAGE_READ)) { 1585 + pr_vdebug("FFS READ fence is not signaled\n"); 1586 + ret = -EBUSY; 1587 + goto err_resv_unlock; 1588 + } 1589 + 1590 + ret = dma_resv_reserve_fences(dmabuf->resv, 1); 1591 + if (ret) 1592 + goto err_resv_unlock; 1593 + 1594 + fence = kmalloc(sizeof(*fence), GFP_KERNEL); 1595 + if (!fence) { 1596 + ret = -ENOMEM; 1597 + goto err_resv_unlock; 1598 + } 1599 + 1600 + fence->priv = priv; 1601 + 1602 + spin_lock_irq(&epfile->ffs->eps_lock); 1603 + 1604 + /* In the meantime, endpoint got disabled or changed. */ 1605 + if (epfile->ep != ep) { 1606 + ret = -ESHUTDOWN; 1607 + goto err_fence_put; 1608 + } 1609 + 1610 + usb_req = usb_ep_alloc_request(ep->ep, GFP_ATOMIC); 1611 + if (!usb_req) { 1612 + ret = -ENOMEM; 1613 + goto err_fence_put; 1614 + } 1615 + 1616 + /* 1617 + * usb_ep_queue() guarantees that all transfers are processed in the 1618 + * order they are enqueued, so we can use a simple incrementing 1619 + * sequence number for the dma_fence. 1620 + */ 1621 + seqno = atomic_add_return(1, &epfile->seqno); 1622 + 1623 + dma_fence_init(&fence->base, &ffs_dmabuf_fence_ops, 1624 + &priv->lock, priv->context, seqno); 1625 + 1626 + dma_resv_add_fence(dmabuf->resv, &fence->base, 1627 + dma_resv_usage_rw(epfile->in)); 1628 + dma_resv_unlock(dmabuf->resv); 1629 + 1630 + /* Now that the dma_fence is in place, queue the transfer. */ 1631 + 1632 + usb_req->length = req->length; 1633 + usb_req->buf = NULL; 1634 + usb_req->sg = priv->sgt->sgl; 1635 + usb_req->num_sgs = sg_nents_for_len(priv->sgt->sgl, req->length); 1636 + usb_req->sg_was_mapped = true; 1637 + usb_req->context = fence; 1638 + usb_req->complete = ffs_epfile_dmabuf_io_complete; 1639 + 1640 + cookie = dma_fence_begin_signalling(); 1641 + ret = usb_ep_queue(ep->ep, usb_req, GFP_ATOMIC); 1642 + dma_fence_end_signalling(cookie); 1643 + if (!ret) { 1644 + priv->req = usb_req; 1645 + priv->ep = ep->ep; 1646 + } else { 1647 + pr_warn("FFS: Failed to queue DMABUF: %d\n", ret); 1648 + ffs_dmabuf_signal_done(fence, ret); 1649 + usb_ep_free_request(ep->ep, usb_req); 1650 + } 1651 + 1652 + spin_unlock_irq(&epfile->ffs->eps_lock); 1653 + dma_buf_put(dmabuf); 1654 + 1655 + return ret; 1656 + 1657 + err_fence_put: 1658 + spin_unlock_irq(&epfile->ffs->eps_lock); 1659 + dma_fence_put(&fence->base); 1660 + err_resv_unlock: 1661 + dma_resv_unlock(dmabuf->resv); 1662 + err_attachment_put: 1663 + ffs_dmabuf_put(attach); 1664 + err_dmabuf_put: 1665 + dma_buf_put(dmabuf); 1666 + 1667 + return ret; 1312 1668 } 1313 1669 1314 1670 static long ffs_epfile_ioctl(struct file *file, unsigned code, ··· 1719 1279 if (WARN_ON(epfile->ffs->state != FFS_ACTIVE)) 1720 1280 return -ENODEV; 1721 1281 1722 - /* Wait for endpoint to be enabled */ 1723 - ep = epfile->ep; 1724 - if (!ep) { 1725 - if (file->f_flags & O_NONBLOCK) 1726 - return -EAGAIN; 1282 + switch (code) { 1283 + case FUNCTIONFS_DMABUF_ATTACH: 1284 + { 1285 + int fd; 1727 1286 1728 - ret = wait_event_interruptible( 1729 - epfile->ffs->wait, (ep = epfile->ep)); 1730 - if (ret) 1731 - return -EINTR; 1287 + if (copy_from_user(&fd, (void __user *)value, sizeof(fd))) { 1288 + ret = -EFAULT; 1289 + break; 1290 + } 1291 + 1292 + return ffs_dmabuf_attach(file, fd); 1732 1293 } 1294 + case FUNCTIONFS_DMABUF_DETACH: 1295 + { 1296 + int fd; 1297 + 1298 + if (copy_from_user(&fd, (void __user *)value, sizeof(fd))) { 1299 + ret = -EFAULT; 1300 + break; 1301 + } 1302 + 1303 + return ffs_dmabuf_detach(file, fd); 1304 + } 1305 + case FUNCTIONFS_DMABUF_TRANSFER: 1306 + { 1307 + struct usb_ffs_dmabuf_transfer_req req; 1308 + 1309 + if (copy_from_user(&req, (void __user *)value, sizeof(req))) { 1310 + ret = -EFAULT; 1311 + break; 1312 + } 1313 + 1314 + return ffs_dmabuf_transfer(file, &req); 1315 + } 1316 + default: 1317 + break; 1318 + } 1319 + 1320 + /* Wait for endpoint to be enabled */ 1321 + ep = ffs_epfile_wait_ep(file); 1322 + if (IS_ERR(ep)) 1323 + return PTR_ERR(ep); 1733 1324 1734 1325 spin_lock_irq(&epfile->ffs->eps_lock); 1735 1326 ··· 2334 1863 for (i = 1; i <= count; ++i, ++epfile) { 2335 1864 epfile->ffs = ffs; 2336 1865 mutex_init(&epfile->mutex); 1866 + mutex_init(&epfile->dmabufs_mutex); 1867 + INIT_LIST_HEAD(&epfile->dmabufs); 2337 1868 if (ffs->user_flags & FUNCTIONFS_VIRTUAL_ADDR) 2338 1869 sprintf(epfile->name, "ep%02x", ffs->eps_addrmap[i]); 2339 1870 else ··· 3918 3445 func_inst.group); 3919 3446 } 3920 3447 3448 + static ssize_t f_fs_opts_ready_show(struct config_item *item, char *page) 3449 + { 3450 + struct f_fs_opts *opts = to_ffs_opts(item); 3451 + int ready; 3452 + 3453 + ffs_dev_lock(); 3454 + ready = opts->dev->desc_ready; 3455 + ffs_dev_unlock(); 3456 + 3457 + return sprintf(page, "%d\n", ready); 3458 + } 3459 + 3460 + CONFIGFS_ATTR_RO(f_fs_opts_, ready); 3461 + 3462 + static struct configfs_attribute *ffs_attrs[] = { 3463 + &f_fs_opts_attr_ready, 3464 + NULL, 3465 + }; 3466 + 3921 3467 static void ffs_attr_release(struct config_item *item) 3922 3468 { 3923 3469 struct f_fs_opts *opts = to_ffs_opts(item); ··· 3950 3458 3951 3459 static const struct config_item_type ffs_func_type = { 3952 3460 .ct_item_ops = &ffs_item_ops, 3461 + .ct_attrs = ffs_attrs, 3953 3462 .ct_owner = THIS_MODULE, 3954 3463 }; 3955 3464
+1 -1
drivers/usb/gadget/function/u_ether.c
··· 718 718 .ndo_validate_addr = eth_validate_addr, 719 719 }; 720 720 721 - static struct device_type gadget_type = { 721 + static const struct device_type gadget_type = { 722 722 .name = "gadget", 723 723 }; 724 724
+60 -63
drivers/usb/gadget/function/uvc_video.c
··· 35 35 36 36 data[1] = UVC_STREAM_EOH | video->fid; 37 37 38 + if (video->queue.flags & UVC_QUEUE_DROP_INCOMPLETE) 39 + data[1] |= UVC_STREAM_ERR; 40 + 38 41 if (video->queue.buf_used == 0 && ts.tv_sec) { 39 42 /* dwClockFrequency is 48 MHz */ 40 43 u32 pts = ((u64)ts.tv_sec * USEC_PER_SEC + ts.tv_nsec / NSEC_PER_USEC) * 48; ··· 373 370 struct uvc_video *video = ureq->video; 374 371 struct uvc_video_queue *queue = &video->queue; 375 372 struct uvc_buffer *last_buf; 373 + struct usb_request *to_queue = req; 376 374 unsigned long flags; 377 375 bool is_bulk = video->max_payload_size; 378 376 int ret = 0; ··· 401 397 402 398 case -EXDEV: 403 399 uvcg_dbg(&video->uvc->func, "VS request missed xfer.\n"); 404 - queue->flags |= UVC_QUEUE_DROP_INCOMPLETE; 400 + if (req->length != 0) 401 + queue->flags |= UVC_QUEUE_DROP_INCOMPLETE; 405 402 break; 406 403 407 404 case -ESHUTDOWN: /* disconnect from host. */ ··· 430 425 * we're still streaming before queueing the usb_request 431 426 * back to req_free 432 427 */ 433 - if (video->is_enabled) { 434 - /* 435 - * Here we check whether any request is available in the ready 436 - * list. If it is, queue it to the ep and add the current 437 - * usb_request to the req_free list - for video_pump to fill in. 438 - * Otherwise, just use the current usb_request to queue a 0 439 - * length request to the ep. Since we always add to the req_free 440 - * list if we dequeue from the ready list, there will never 441 - * be a situation where the req_free list is completely out of 442 - * requests and cannot recover. 443 - */ 444 - struct usb_request *to_queue = req; 445 - 446 - to_queue->length = 0; 447 - if (!list_empty(&video->req_ready)) { 448 - to_queue = list_first_entry(&video->req_ready, 449 - struct usb_request, list); 450 - list_del(&to_queue->list); 451 - list_add_tail(&req->list, &video->req_free); 452 - /* 453 - * Queue work to the wq as well since it is possible that a 454 - * buffer may not have been completely encoded with the set of 455 - * in-flight usb requests for whih the complete callbacks are 456 - * firing. 457 - * In that case, if we do not queue work to the worker thread, 458 - * the buffer will never be marked as complete - and therefore 459 - * not be returned to userpsace. As a result, 460 - * dequeue -> queue -> dequeue flow of uvc buffers will not 461 - * happen. 462 - */ 463 - queue_work(video->async_wq, &video->pump); 464 - } 465 - /* 466 - * Queue to the endpoint. The actual queueing to ep will 467 - * only happen on one thread - the async_wq for bulk endpoints 468 - * and this thread for isoc endpoints. 469 - */ 470 - ret = uvcg_video_usb_req_queue(video, to_queue, !is_bulk); 471 - if (ret < 0) { 472 - /* 473 - * Endpoint error, but the stream is still enabled. 474 - * Put request back in req_free for it to be cleaned 475 - * up later. 476 - */ 477 - list_add_tail(&to_queue->list, &video->req_free); 478 - } 479 - } else { 428 + if (!video->is_enabled) { 480 429 uvc_video_free_request(ureq, ep); 481 - ret = 0; 482 - } 483 - spin_unlock_irqrestore(&video->req_lock, flags); 484 - if (ret < 0) 430 + spin_unlock_irqrestore(&video->req_lock, flags); 485 431 uvcg_queue_cancel(queue, 0); 432 + 433 + return; 434 + } 435 + 436 + /* 437 + * Here we check whether any request is available in the ready 438 + * list. If it is, queue it to the ep and add the current 439 + * usb_request to the req_free list - for video_pump to fill in. 440 + * Otherwise, just use the current usb_request to queue a 0 441 + * length request to the ep. Since we always add to the req_free 442 + * list if we dequeue from the ready list, there will never 443 + * be a situation where the req_free list is completely out of 444 + * requests and cannot recover. 445 + */ 446 + to_queue->length = 0; 447 + if (!list_empty(&video->req_ready)) { 448 + to_queue = list_first_entry(&video->req_ready, 449 + struct usb_request, list); 450 + list_del(&to_queue->list); 451 + list_add_tail(&req->list, &video->req_free); 452 + /* 453 + * Queue work to the wq as well since it is possible that a 454 + * buffer may not have been completely encoded with the set of 455 + * in-flight usb requests for whih the complete callbacks are 456 + * firing. 457 + * In that case, if we do not queue work to the worker thread, 458 + * the buffer will never be marked as complete - and therefore 459 + * not be returned to userpsace. As a result, 460 + * dequeue -> queue -> dequeue flow of uvc buffers will not 461 + * happen. 462 + */ 463 + queue_work(video->async_wq, &video->pump); 464 + } 465 + /* 466 + * Queue to the endpoint. The actual queueing to ep will 467 + * only happen on one thread - the async_wq for bulk endpoints 468 + * and this thread for isoc endpoints. 469 + */ 470 + ret = uvcg_video_usb_req_queue(video, to_queue, !is_bulk); 471 + if (ret < 0) { 472 + /* 473 + * Endpoint error, but the stream is still enabled. 474 + * Put request back in req_free for it to be cleaned 475 + * up later. 476 + */ 477 + list_add_tail(&to_queue->list, &video->req_free); 478 + } 479 + 480 + spin_unlock_irqrestore(&video->req_lock, flags); 486 481 } 487 482 488 483 static int ··· 599 594 */ 600 595 spin_lock_irqsave(&queue->irqlock, flags); 601 596 buf = uvcg_queue_head(queue); 602 - 603 - if (buf != NULL) { 604 - video->encode(req, video, buf); 605 - } else { 597 + if (!buf) { 606 598 /* 607 599 * Either the queue has been disconnected or no video buffer 608 600 * available for bulk transfer. Either way, stop processing ··· 608 606 spin_unlock_irqrestore(&queue->irqlock, flags); 609 607 break; 610 608 } 609 + 610 + video->encode(req, video, buf); 611 611 612 612 spin_unlock_irqrestore(&queue->irqlock, flags); 613 613 ··· 627 623 uvcg_queue_cancel(queue, 0); 628 624 break; 629 625 } 630 - 631 - /* The request is owned by the endpoint / ready list. */ 632 - req = NULL; 633 626 } 634 - 635 - if (!req) 636 - return; 637 - 638 627 spin_lock_irqsave(&video->req_lock, flags); 639 628 if (video->is_enabled) 640 629 list_add_tail(&req->list, &video->req_free);
+6 -1
drivers/usb/gadget/udc/core.c
··· 903 903 if (req->length == 0) 904 904 return 0; 905 905 906 + if (req->sg_was_mapped) { 907 + req->num_mapped_sgs = req->num_sgs; 908 + return 0; 909 + } 910 + 906 911 if (req->num_sgs) { 907 912 int mapped; 908 913 ··· 953 948 void usb_gadget_unmap_request_by_dev(struct device *dev, 954 949 struct usb_request *req, int is_in) 955 950 { 956 - if (req->length == 0) 951 + if (req->length == 0 || req->sg_was_mapped) 957 952 return; 958 953 959 954 if (req->num_mapped_sgs) {
+73 -54
drivers/usb/gadget/udc/fsl_udc_core.c
··· 13 13 * code from Dave Liu and Shlomi Gridish. 14 14 */ 15 15 16 - #undef VERBOSE 16 + #define pr_fmt(x) "udc: " x 17 17 18 18 #include <linux/module.h> 19 19 #include <linux/kernel.h> ··· 183 183 usb_gadget_unmap_request(&ep->udc->gadget, &req->req, ep_is_in(ep)); 184 184 185 185 if (status && (status != -ESHUTDOWN)) 186 - VDBG("complete %s req %p stat %d len %u/%u", 187 - ep->ep.name, &req->req, status, 188 - req->req.actual, req->req.length); 186 + dev_vdbg(&udc->gadget.dev, "complete %s req %p stat %d len %u/%u\n", 187 + ep->ep.name, &req->req, status, 188 + req->req.actual, req->req.length); 189 189 190 190 ep->stopped = 1; 191 191 ··· 285 285 timeout = jiffies + FSL_UDC_RESET_TIMEOUT; 286 286 while (fsl_readl(&dr_regs->usbcmd) & USB_CMD_CTRL_RESET) { 287 287 if (time_after(jiffies, timeout)) { 288 - ERR("udc reset timeout!\n"); 288 + dev_err(&udc->gadget.dev, "udc reset timeout!\n"); 289 289 return -ETIMEDOUT; 290 290 } 291 291 cpu_relax(); ··· 308 308 tmp &= USB_EP_LIST_ADDRESS_MASK; 309 309 fsl_writel(tmp, &dr_regs->endpointlistaddr); 310 310 311 - VDBG("vir[qh_base] is %p phy[qh_base] is 0x%8x reg is 0x%8x", 312 - udc->ep_qh, (int)tmp, 313 - fsl_readl(&dr_regs->endpointlistaddr)); 311 + dev_vdbg(&udc->gadget.dev, 312 + "vir[qh_base] is %p phy[qh_base] is 0x%8x reg is 0x%8x\n", 313 + udc->ep_qh, (int)tmp, 314 + fsl_readl(&dr_regs->endpointlistaddr)); 314 315 315 316 max_no_of_ep = (0x0000001F & fsl_readl(&dr_regs->dccparams)); 316 317 for (ep_num = 1; ep_num < max_no_of_ep; ep_num++) { ··· 499 498 tmp = max_pkt_len << EP_QUEUE_HEAD_MAX_PKT_LEN_POS; 500 499 break; 501 500 default: 502 - VDBG("error ep type is %d", ep_type); 501 + dev_vdbg(&udc->gadget.dev, "error ep type is %d\n", ep_type); 503 502 return; 504 503 } 505 504 if (zlt) ··· 612 611 spin_unlock_irqrestore(&udc->lock, flags); 613 612 retval = 0; 614 613 615 - VDBG("enabled %s (ep%d%s) maxpacket %d",ep->ep.name, 616 - ep->ep.desc->bEndpointAddress & 0x0f, 617 - (desc->bEndpointAddress & USB_DIR_IN) 618 - ? "in" : "out", max); 614 + dev_vdbg(&udc->gadget.dev, "enabled %s (ep%d%s) maxpacket %d\n", 615 + ep->ep.name, ep->ep.desc->bEndpointAddress & 0x0f, 616 + (desc->bEndpointAddress & USB_DIR_IN) ? "in" : "out", 617 + max); 619 618 en_done: 620 619 return retval; 621 620 } ··· 634 633 635 634 ep = container_of(_ep, struct fsl_ep, ep); 636 635 if (!_ep || !ep->ep.desc) { 637 - VDBG("%s not enabled", _ep ? ep->ep.name : NULL); 636 + /* 637 + * dev_vdbg(&udc->gadget.dev, "%s not enabled\n", 638 + * _ep ? ep->ep.name : NULL); 639 + */ 638 640 return -EINVAL; 639 641 } 640 642 ··· 663 659 ep->stopped = 1; 664 660 spin_unlock_irqrestore(&udc->lock, flags); 665 661 666 - VDBG("disabled %s OK", _ep->name); 662 + dev_vdbg(&udc->gadget.dev, "disabled %s OK\n", _ep->name); 667 663 return 0; 668 664 } 669 665 ··· 723 719 { 724 720 u32 temp, bitmask, tmp_stat; 725 721 726 - /* VDBG("QH addr Register 0x%8x", dr_regs->endpointlistaddr); 727 - VDBG("ep_qh[%d] addr is 0x%8x", i, (u32)&(ep->udc->ep_qh[i])); */ 722 + /* dev_vdbg(&udc->gadget.dev, "QH addr Register 0x%8x\n", dr_regs->endpointlistaddr); 723 + dev_vdbg(&udc->gadget.dev, "ep_qh[%d] addr is 0x%8x\n", i, (u32)&(ep->udc->ep_qh[i])); */ 728 724 729 725 bitmask = ep_is_in(ep) 730 726 ? (1 << (ep_index(ep) + 16)) ··· 812 808 *is_last = 0; 813 809 814 810 if ((*is_last) == 0) 815 - VDBG("multi-dtd request!"); 811 + dev_vdbg(&udc_controller->gadget.dev, "multi-dtd request!\n"); 816 812 /* Fill in the transfer size; set active bit */ 817 813 swap_temp = ((*length << DTD_LENGTH_BIT_POS) | DTD_STATUS_ACTIVE); 818 814 ··· 824 820 825 821 mb(); 826 822 827 - VDBG("length = %d address= 0x%x", *length, (int)*dma); 823 + dev_vdbg(&udc_controller->gadget.dev, "length = %d address= 0x%x\n", *length, (int)*dma); 828 824 829 825 return dtd; 830 826 } ··· 875 871 /* catch various bogus parameters */ 876 872 if (!_req || !req->req.complete || !req->req.buf 877 873 || !list_empty(&req->queue)) { 878 - VDBG("%s, bad params", __func__); 874 + dev_vdbg(&udc->gadget.dev, "%s, bad params\n", __func__); 879 875 return -EINVAL; 880 876 } 881 877 if (unlikely(!_ep || !ep->ep.desc)) { 882 - VDBG("%s, bad ep", __func__); 878 + dev_vdbg(&udc->gadget.dev, "%s, bad ep\n", __func__); 883 879 return -EINVAL; 884 880 } 885 881 if (usb_endpoint_xfer_isoc(ep->ep.desc)) { ··· 1040 1036 udc->ep0_dir = 0; 1041 1037 } 1042 1038 out: 1043 - VDBG(" %s %s halt stat %d", ep->ep.name, 1044 - value ? "set" : "clear", status); 1039 + dev_vdbg(&udc->gadget.dev, "%s %s halt stat %d\n", ep->ep.name, 1040 + value ? "set" : "clear", status); 1045 1041 1046 1042 return status; 1047 1043 } ··· 1109 1105 /* Wait until flush complete */ 1110 1106 while (fsl_readl(&dr_regs->endptflush)) { 1111 1107 if (time_after(jiffies, timeout)) { 1112 - ERR("ep flush timeout\n"); 1108 + dev_err(&udc_controller->gadget.dev, 1109 + "ep flush timeout\n"); 1113 1110 return; 1114 1111 } 1115 1112 cpu_relax(); ··· 1182 1177 1183 1178 udc = container_of(gadget, struct fsl_udc, gadget); 1184 1179 spin_lock_irqsave(&udc->lock, flags); 1185 - VDBG("VBUS %s", is_active ? "on" : "off"); 1180 + dev_vdbg(&gadget->dev, "VBUS %s\n", is_active ? "on" : "off"); 1186 1181 udc->vbus_active = (is_active != 0); 1187 1182 if (can_pullup(udc)) 1188 1183 fsl_writel((fsl_readl(&dr_regs->usbcmd) | USB_CMD_RUN_STOP), ··· 1548 1543 udc->ep0_state = WAIT_FOR_SETUP; 1549 1544 break; 1550 1545 case WAIT_FOR_SETUP: 1551 - ERR("Unexpected ep0 packets\n"); 1546 + dev_err(&udc->gadget.dev, "Unexpected ep0 packets\n"); 1552 1547 break; 1553 1548 default: 1554 1549 ep0stall(udc); ··· 1617 1612 errors = hc32_to_cpu(curr_td->size_ioc_sts); 1618 1613 if (errors & DTD_ERROR_MASK) { 1619 1614 if (errors & DTD_STATUS_HALTED) { 1620 - ERR("dTD error %08x QH=%d\n", errors, pipe); 1615 + dev_err(&udc->gadget.dev, "dTD error %08x QH=%d\n", errors, pipe); 1621 1616 /* Clear the errors and Halt condition */ 1622 1617 tmp = hc32_to_cpu(curr_qh->size_ioc_int_sts); 1623 1618 tmp &= ~errors; ··· 1628 1623 break; 1629 1624 } 1630 1625 if (errors & DTD_STATUS_DATA_BUFF_ERR) { 1631 - VDBG("Transfer overflow"); 1626 + dev_vdbg(&udc->gadget.dev, "Transfer overflow\n"); 1632 1627 status = -EPROTO; 1633 1628 break; 1634 1629 } else if (errors & DTD_STATUS_TRANSACTION_ERR) { 1635 - VDBG("ISO error"); 1630 + dev_vdbg(&udc->gadget.dev, "ISO error\n"); 1636 1631 status = -EILSEQ; 1637 1632 break; 1638 1633 } else 1639 - ERR("Unknown error has occurred (0x%x)!\n", 1634 + dev_err(&udc->gadget.dev, 1635 + "Unknown error has occurred (0x%x)!\n", 1640 1636 errors); 1641 1637 1642 1638 } else if (hc32_to_cpu(curr_td->size_ioc_sts) 1643 1639 & DTD_STATUS_ACTIVE) { 1644 - VDBG("Request not complete"); 1640 + dev_vdbg(&udc->gadget.dev, "Request not complete\n"); 1645 1641 status = REQ_UNCOMPLETE; 1646 1642 return status; 1647 1643 } else if (remaining_length) { 1648 1644 if (direction) { 1649 - VDBG("Transmit dTD remaining length not zero"); 1645 + dev_vdbg(&udc->gadget.dev, 1646 + "Transmit dTD remaining length not zero\n"); 1650 1647 status = -EPROTO; 1651 1648 break; 1652 1649 } else { 1653 1650 break; 1654 1651 } 1655 1652 } else { 1656 - VDBG("dTD transmitted successful"); 1653 + dev_vdbg(&udc->gadget.dev, 1654 + "dTD transmitted successful\n"); 1657 1655 } 1658 1656 1659 1657 if (j != curr_req->dtd_count - 1) ··· 1699 1691 1700 1692 /* If the ep is configured */ 1701 1693 if (!curr_ep->ep.name) { 1702 - WARNING("Invalid EP?"); 1694 + dev_warn(&udc->gadget.dev, "Invalid EP?\n"); 1703 1695 continue; 1704 1696 } 1705 1697 ··· 1708 1700 queue) { 1709 1701 status = process_ep_req(udc, i, curr_req); 1710 1702 1711 - VDBG("status of process_ep_req= %d, ep = %d", 1712 - status, ep_num); 1703 + dev_vdbg(&udc->gadget.dev, 1704 + "status of process_ep_req= %d, ep = %d\n", 1705 + status, ep_num); 1713 1706 if (status == REQ_UNCOMPLETE) 1714 1707 break; 1715 1708 /* write back status to req */ ··· 1829 1820 while (fsl_readl(&dr_regs->endpointprime)) { 1830 1821 /* Wait until all endptprime bits cleared */ 1831 1822 if (time_after(jiffies, timeout)) { 1832 - ERR("Timeout for reset\n"); 1823 + dev_err(&udc->gadget.dev, "Timeout for reset\n"); 1833 1824 break; 1834 1825 } 1835 1826 cpu_relax(); ··· 1839 1830 fsl_writel(0xffffffff, &dr_regs->endptflush); 1840 1831 1841 1832 if (fsl_readl(&dr_regs->portsc1) & PORTSCX_PORT_RESET) { 1842 - VDBG("Bus reset"); 1833 + dev_vdbg(&udc->gadget.dev, "Bus reset\n"); 1843 1834 /* Bus is reseting */ 1844 1835 udc->bus_reset = 1; 1845 1836 /* Reset all the queues, include XD, dTD, EP queue ··· 1847 1838 reset_queues(udc, true); 1848 1839 udc->usb_state = USB_STATE_DEFAULT; 1849 1840 } else { 1850 - VDBG("Controller reset"); 1841 + dev_vdbg(&udc->gadget.dev, "Controller reset\n"); 1851 1842 /* initialize usb hw reg except for regs for EP, not 1852 1843 * touch usbintr reg */ 1853 1844 dr_controller_setup(udc); ··· 1881 1872 /* Clear notification bits */ 1882 1873 fsl_writel(irq_src, &dr_regs->usbsts); 1883 1874 1884 - /* VDBG("irq_src [0x%8x]", irq_src); */ 1875 + /* dev_vdbg(&udc->gadget.dev, "irq_src [0x%8x]", irq_src); */ 1885 1876 1886 1877 /* Need to resume? */ 1887 1878 if (udc->usb_state == USB_STATE_SUSPENDED) ··· 1890 1881 1891 1882 /* USB Interrupt */ 1892 1883 if (irq_src & USB_STS_INT) { 1893 - VDBG("Packet int"); 1884 + dev_vdbg(&udc->gadget.dev, "Packet int\n"); 1894 1885 /* Setup package, we only support ep0 as control ep */ 1895 1886 if (fsl_readl(&dr_regs->endptsetupstat) & EP_SETUP_STATUS_EP0) { 1896 1887 tripwire_handler(udc, 0, ··· 1919 1910 1920 1911 /* Reset Received */ 1921 1912 if (irq_src & USB_STS_RESET) { 1922 - VDBG("reset int"); 1913 + dev_vdbg(&udc->gadget.dev, "reset int\n"); 1923 1914 reset_irq(udc); 1924 1915 status = IRQ_HANDLED; 1925 1916 } ··· 1931 1922 } 1932 1923 1933 1924 if (irq_src & (USB_STS_ERR | USB_STS_SYS_ERR)) { 1934 - VDBG("Error IRQ %x", irq_src); 1925 + dev_vdbg(&udc->gadget.dev, "Error IRQ %x\n", irq_src); 1935 1926 } 1936 1927 1937 1928 spin_unlock_irqrestore(&udc->lock, flags); ··· 1967 1958 udc_controller->transceiver->otg, 1968 1959 &udc_controller->gadget); 1969 1960 if (retval < 0) { 1970 - ERR("can't bind to transceiver\n"); 1961 + dev_err(&udc_controller->gadget.dev, "can't bind to transceiver\n"); 1971 1962 udc_controller->driver = NULL; 1972 1963 return retval; 1973 1964 } ··· 2252 2243 2253 2244 udc->eps = kcalloc(udc->max_ep, sizeof(struct fsl_ep), GFP_KERNEL); 2254 2245 if (!udc->eps) { 2255 - ERR("kmalloc udc endpoint status failed\n"); 2246 + dev_err(&udc->gadget.dev, "kmalloc udc endpoint status failed\n"); 2256 2247 goto eps_alloc_failed; 2257 2248 } 2258 2249 ··· 2267 2258 udc->ep_qh = dma_alloc_coherent(&pdev->dev, size, 2268 2259 &udc->ep_qh_dma, GFP_KERNEL); 2269 2260 if (!udc->ep_qh) { 2270 - ERR("malloc QHs for udc failed\n"); 2261 + dev_err(&udc->gadget.dev, "malloc QHs for udc failed\n"); 2271 2262 goto ep_queue_alloc_failed; 2272 2263 } 2273 2264 ··· 2278 2269 udc->status_req = container_of(fsl_alloc_request(NULL, GFP_KERNEL), 2279 2270 struct fsl_req, req); 2280 2271 if (!udc->status_req) { 2281 - ERR("kzalloc for udc status request failed\n"); 2272 + dev_err(&udc->gadget.dev, "kzalloc for udc status request failed\n"); 2282 2273 goto udc_status_alloc_failed; 2283 2274 } 2284 2275 2285 2276 /* allocate a small amount of memory to get valid address */ 2286 2277 udc->status_req->req.buf = kmalloc(8, GFP_KERNEL); 2287 2278 if (!udc->status_req->req.buf) { 2288 - ERR("kzalloc for udc request buffer failed\n"); 2279 + dev_err(&udc->gadget.dev, "kzalloc for udc request buffer failed\n"); 2289 2280 goto udc_req_buf_alloc_failed; 2290 2281 } 2291 2282 ··· 2382 2373 if (pdata->operating_mode == FSL_USB2_DR_OTG) { 2383 2374 udc_controller->transceiver = usb_get_phy(USB_PHY_TYPE_USB2); 2384 2375 if (IS_ERR_OR_NULL(udc_controller->transceiver)) { 2385 - ERR("Can't find OTG driver!\n"); 2376 + dev_err(&udc_controller->gadget.dev, "Can't find OTG driver!\n"); 2386 2377 ret = -ENODEV; 2387 2378 goto err_kfree; 2388 2379 } ··· 2398 2389 if (pdata->operating_mode == FSL_USB2_DR_DEVICE) { 2399 2390 if (!request_mem_region(res->start, resource_size(res), 2400 2391 driver_name)) { 2401 - ERR("request mem region for %s failed\n", pdev->name); 2392 + dev_err(&udc_controller->gadget.dev, "request mem region for %s failed\n", pdev->name); 2402 2393 ret = -EBUSY; 2403 2394 goto err_kfree; 2404 2395 } ··· 2429 2420 /* Read Device Controller Capability Parameters register */ 2430 2421 dccparams = fsl_readl(&dr_regs->dccparams); 2431 2422 if (!(dccparams & DCCPARAMS_DC)) { 2432 - ERR("This SOC doesn't support device role\n"); 2423 + dev_err(&udc_controller->gadget.dev, "This SOC doesn't support device role\n"); 2433 2424 ret = -ENODEV; 2434 2425 goto err_exit; 2435 2426 } ··· 2447 2438 ret = request_irq(udc_controller->irq, fsl_udc_irq, IRQF_SHARED, 2448 2439 driver_name, udc_controller); 2449 2440 if (ret != 0) { 2450 - ERR("cannot request irq %d err %d\n", 2441 + dev_err(&udc_controller->gadget.dev, "cannot request irq %d err %d\n", 2451 2442 udc_controller->irq, ret); 2452 2443 goto err_exit; 2453 2444 } 2454 2445 2455 2446 /* Initialize the udc structure including QH member and other member */ 2456 2447 if (struct_udc_setup(udc_controller, pdev)) { 2457 - ERR("Can't initialize udc data structure\n"); 2448 + dev_err(&udc_controller->gadget.dev, "Can't initialize udc data structure\n"); 2458 2449 ret = -ENOMEM; 2459 2450 goto err_free_irq; 2460 2451 } ··· 2495 2486 /* setup the udc->eps[] for non-control endpoints and link 2496 2487 * to gadget.ep_list */ 2497 2488 for (i = 1; i < (int)(udc_controller->max_ep / 2); i++) { 2498 - char name[14]; 2489 + char name[16]; 2499 2490 2500 2491 sprintf(name, "ep%dout", i); 2501 2492 struct_ep_setup(udc_controller, i * 2, name, 1); ··· 2675 2666 } 2676 2667 }; 2677 2668 MODULE_DEVICE_TABLE(platform, fsl_udc_devtype); 2669 + 2670 + static const struct of_device_id fsl_udc_dt_ids[] = { 2671 + { .compatible = "fsl-usb2-dr" }, 2672 + { .compatible = "fsl-usb2-mph" }, 2673 + { .compatible = "fsl,mpc5121-usb2-dr" }, 2674 + { /* sentinel */ } 2675 + }; 2676 + MODULE_DEVICE_TABLE(of, fsl_udc_dt_ids); 2677 + 2678 2678 static struct platform_driver udc_driver = { 2679 2679 .probe = fsl_udc_probe, 2680 2680 .remove_new = fsl_udc_remove, ··· 2693 2675 .resume = fsl_udc_resume, 2694 2676 .driver = { 2695 2677 .name = driver_name, 2678 + .of_match_table = fsl_udc_dt_ids, 2696 2679 /* udc suspend/resume called from OTG driver */ 2697 2680 .suspend = fsl_udc_otg_suspend, 2698 2681 .resume = fsl_udc_otg_resume,
-47
drivers/usb/gadget/udc/fsl_usb2_udc.h
··· 508 508 509 509 /*-------------------------------------------------------------------------*/ 510 510 511 - #ifdef DEBUG 512 - #define DBG(fmt, args...) printk(KERN_DEBUG "[%s] " fmt "\n", \ 513 - __func__, ## args) 514 - #else 515 - #define DBG(fmt, args...) do{}while(0) 516 - #endif 517 - 518 - #if 0 519 - static void dump_msg(const char *label, const u8 * buf, unsigned int length) 520 - { 521 - unsigned int start, num, i; 522 - char line[52], *p; 523 - 524 - if (length >= 512) 525 - return; 526 - DBG("%s, length %u:\n", label, length); 527 - start = 0; 528 - while (length > 0) { 529 - num = min(length, 16u); 530 - p = line; 531 - for (i = 0; i < num; ++i) { 532 - if (i == 8) 533 - *p++ = ' '; 534 - sprintf(p, " %02x", buf[i]); 535 - p += 3; 536 - } 537 - *p = 0; 538 - printk(KERN_DEBUG "%6x: %s\n", start, line); 539 - buf += num; 540 - start += num; 541 - length -= num; 542 - } 543 - } 544 - #endif 545 - 546 - #ifdef VERBOSE 547 - #define VDBG DBG 548 - #else 549 - #define VDBG(stuff...) do{}while(0) 550 - #endif 551 - 552 - #define ERR(stuff...) pr_err("udc: " stuff) 553 - #define WARNING(stuff...) pr_warn("udc: " stuff) 554 - #define INFO(stuff...) pr_info("udc: " stuff) 555 - 556 - /*-------------------------------------------------------------------------*/ 557 - 558 511 /* ### Add board specific defines here 559 512 */ 560 513
+1 -1
drivers/usb/gadget/udc/net2272.c
··· 2650 2650 goto err_req; 2651 2651 } 2652 2652 2653 - ret = net2272_probe_fin(dev, IRQF_TRIGGER_LOW); 2653 + ret = net2272_probe_fin(dev, irqflags); 2654 2654 if (ret) 2655 2655 goto err_io; 2656 2656
-1
drivers/usb/gadget/udc/pxa27x_udc.c
··· 24 24 #include <linux/byteorder/generic.h> 25 25 #include <linux/platform_data/pxa2xx_udc.h> 26 26 #include <linux/of.h> 27 - #include <linux/of_gpio.h> 28 27 29 28 #include <linux/usb.h> 30 29 #include <linux/usb/ch9.h>
-1
drivers/usb/gadget/udc/snps_udc_plat.c
··· 8 8 #include <linux/extcon.h> 9 9 #include <linux/of_address.h> 10 10 #include <linux/of_irq.h> 11 - #include <linux/of_gpio.h> 12 11 #include <linux/platform_device.h> 13 12 #include <linux/phy/phy.h> 14 13 #include <linux/module.h>
+25 -14
drivers/usb/gadget/udc/tegra-xudc.c
··· 3491 3491 3492 3492 static int tegra_xudc_phy_get(struct tegra_xudc *xudc) 3493 3493 { 3494 - int err = 0, usb3; 3495 - unsigned int i; 3494 + int err = 0, usb3_companion_port; 3495 + unsigned int i, j; 3496 3496 3497 3497 xudc->utmi_phy = devm_kcalloc(xudc->dev, xudc->soc->num_phys, 3498 3498 sizeof(*xudc->utmi_phy), GFP_KERNEL); ··· 3520 3520 if (IS_ERR(xudc->utmi_phy[i])) { 3521 3521 err = PTR_ERR(xudc->utmi_phy[i]); 3522 3522 dev_err_probe(xudc->dev, err, 3523 - "failed to get usb2-%d PHY\n", i); 3523 + "failed to get PHY for phy-name usb2-%d\n", i); 3524 3524 goto clean_up; 3525 3525 } else if (xudc->utmi_phy[i]) { 3526 3526 /* Get usb-phy, if utmi phy is available */ ··· 3539 3539 } 3540 3540 3541 3541 /* Get USB3 phy */ 3542 - usb3 = tegra_xusb_padctl_get_usb3_companion(xudc->padctl, i); 3543 - if (usb3 < 0) 3542 + usb3_companion_port = tegra_xusb_padctl_get_usb3_companion(xudc->padctl, i); 3543 + if (usb3_companion_port < 0) 3544 3544 continue; 3545 3545 3546 - snprintf(phy_name, sizeof(phy_name), "usb3-%d", usb3); 3547 - xudc->usb3_phy[i] = devm_phy_optional_get(xudc->dev, phy_name); 3548 - if (IS_ERR(xudc->usb3_phy[i])) { 3549 - err = PTR_ERR(xudc->usb3_phy[i]); 3550 - dev_err_probe(xudc->dev, err, 3551 - "failed to get usb3-%d PHY\n", usb3); 3552 - goto clean_up; 3553 - } else if (xudc->usb3_phy[i]) 3554 - dev_dbg(xudc->dev, "usb3-%d PHY registered", usb3); 3546 + for (j = 0; j < xudc->soc->num_phys; j++) { 3547 + snprintf(phy_name, sizeof(phy_name), "usb3-%d", j); 3548 + xudc->usb3_phy[i] = devm_phy_optional_get(xudc->dev, phy_name); 3549 + if (IS_ERR(xudc->usb3_phy[i])) { 3550 + err = PTR_ERR(xudc->usb3_phy[i]); 3551 + dev_err_probe(xudc->dev, err, 3552 + "failed to get PHY for phy-name usb3-%d\n", j); 3553 + goto clean_up; 3554 + } else if (xudc->usb3_phy[i]) { 3555 + int usb2_port = 3556 + tegra_xusb_padctl_get_port_number(xudc->utmi_phy[i]); 3557 + int usb3_port = 3558 + tegra_xusb_padctl_get_port_number(xudc->usb3_phy[i]); 3559 + if (usb3_port == usb3_companion_port) { 3560 + dev_dbg(xudc->dev, "USB2 port %d is paired with USB3 port %d for device mode port %d\n", 3561 + usb2_port, usb3_port, i); 3562 + break; 3563 + } 3564 + } 3565 + } 3555 3566 } 3556 3567 3557 3568 return err;
+15 -3
drivers/usb/host/ehci-orion.c
··· 66 66 static struct hc_driver __read_mostly ehci_orion_hc_driver; 67 67 68 68 /* 69 + * Legacy DMA mask is 32 bit. 70 + * AC5 has the DDR starting at 8GB, hence it requires 71 + * a larger (34-bit) DMA mask, in order for DMA allocations 72 + * to succeed: 73 + */ 74 + static const u64 dma_mask_orion = DMA_BIT_MASK(32); 75 + static const u64 dma_mask_ac5 = DMA_BIT_MASK(34); 76 + 77 + /* 69 78 * Implement Orion USB controller specification guidelines 70 79 */ 71 80 static void orion_usb_phy_v1_setup(struct usb_hcd *hcd) ··· 220 211 int irq, err; 221 212 enum orion_ehci_phy_ver phy_version; 222 213 struct orion_ehci_hcd *priv; 214 + u64 *dma_mask_ptr; 223 215 224 216 if (usb_disabled()) 225 217 return -ENODEV; ··· 238 228 * set. Since shared usb code relies on it, set it here for 239 229 * now. Once we have dma capability bindings this can go away. 240 230 */ 241 - err = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); 231 + dma_mask_ptr = (u64 *)of_device_get_match_data(&pdev->dev); 232 + err = dma_coerce_mask_and_coherent(&pdev->dev, *dma_mask_ptr); 242 233 if (err) 243 234 goto err; 244 235 ··· 343 332 } 344 333 345 334 static const struct of_device_id ehci_orion_dt_ids[] = { 346 - { .compatible = "marvell,orion-ehci", }, 347 - { .compatible = "marvell,armada-3700-ehci", }, 335 + { .compatible = "marvell,orion-ehci", .data = &dma_mask_orion}, 336 + { .compatible = "marvell,armada-3700-ehci", .data = &dma_mask_orion}, 337 + { .compatible = "marvell,ac5-ehci", .data = &dma_mask_ac5}, 348 338 {}, 349 339 }; 350 340 MODULE_DEVICE_TABLE(of, ehci_orion_dt_ids);
-1
drivers/usb/host/ohci-pxa27x.c
··· 27 27 #include <linux/kernel.h> 28 28 #include <linux/module.h> 29 29 #include <linux/of_platform.h> 30 - #include <linux/of_gpio.h> 31 30 #include <linux/platform_data/usb-ohci-pxa27x.h> 32 31 #include <linux/platform_data/pxa2xx_udc.h> 33 32 #include <linux/platform_device.h>
+2
drivers/usb/host/sl811-hcd.c
··· 585 585 finish_request(sl811, ep, urb, urbstat); 586 586 } 587 587 588 + #ifdef QUIRK2 588 589 static inline u8 checkdone(struct sl811 *sl811) 589 590 { 590 591 u8 ctl; ··· 617 616 #endif 618 617 return irqstat; 619 618 } 619 + #endif 620 620 621 621 static irqreturn_t sl811h_irq(struct usb_hcd *hcd) 622 622 {
+85
drivers/usb/host/xhci-caps.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + 3 + /* hc_capbase bitmasks */ 4 + /* bits 7:0 - how long is the Capabilities register */ 5 + #define HC_LENGTH(p) XHCI_HC_LENGTH(p) 6 + /* bits 31:16 */ 7 + #define HC_VERSION(p) (((p) >> 16) & 0xffff) 8 + 9 + /* HCSPARAMS1 - hcs_params1 - bitmasks */ 10 + /* bits 0:7, Max Device Slots */ 11 + #define HCS_MAX_SLOTS(p) (((p) >> 0) & 0xff) 12 + #define HCS_SLOTS_MASK 0xff 13 + /* bits 8:18, Max Interrupters */ 14 + #define HCS_MAX_INTRS(p) (((p) >> 8) & 0x7ff) 15 + /* bits 24:31, Max Ports - max value is 0x7F = 127 ports */ 16 + #define HCS_MAX_PORTS(p) (((p) >> 24) & 0x7f) 17 + 18 + /* HCSPARAMS2 - hcs_params2 - bitmasks */ 19 + /* bits 0:3, frames or uframes that SW needs to queue transactions 20 + * ahead of the HW to meet periodic deadlines */ 21 + #define HCS_IST(p) (((p) >> 0) & 0xf) 22 + /* bits 4:7, max number of Event Ring segments */ 23 + #define HCS_ERST_MAX(p) (((p) >> 4) & 0xf) 24 + /* bits 21:25 Hi 5 bits of Scratchpad buffers SW must allocate for the HW */ 25 + /* bit 26 Scratchpad restore - for save/restore HW state - not used yet */ 26 + /* bits 27:31 Lo 5 bits of Scratchpad buffers SW must allocate for the HW */ 27 + #define HCS_MAX_SCRATCHPAD(p) ((((p) >> 16) & 0x3e0) | (((p) >> 27) & 0x1f)) 28 + 29 + /* HCSPARAMS3 - hcs_params3 - bitmasks */ 30 + /* bits 0:7, Max U1 to U0 latency for the roothub ports */ 31 + #define HCS_U1_LATENCY(p) (((p) >> 0) & 0xff) 32 + /* bits 16:31, Max U2 to U0 latency for the roothub ports */ 33 + #define HCS_U2_LATENCY(p) (((p) >> 16) & 0xffff) 34 + 35 + /* HCCPARAMS - hcc_params - bitmasks */ 36 + /* true: HC can use 64-bit address pointers */ 37 + #define HCC_64BIT_ADDR(p) ((p) & (1 << 0)) 38 + /* true: HC can do bandwidth negotiation */ 39 + #define HCC_BANDWIDTH_NEG(p) ((p) & (1 << 1)) 40 + /* true: HC uses 64-byte Device Context structures 41 + * FIXME 64-byte context structures aren't supported yet. 42 + */ 43 + #define HCC_64BYTE_CONTEXT(p) ((p) & (1 << 2)) 44 + /* true: HC has port power switches */ 45 + #define HCC_PPC(p) ((p) & (1 << 3)) 46 + /* true: HC has port indicators */ 47 + #define HCS_INDICATOR(p) ((p) & (1 << 4)) 48 + /* true: HC has Light HC Reset Capability */ 49 + #define HCC_LIGHT_RESET(p) ((p) & (1 << 5)) 50 + /* true: HC supports latency tolerance messaging */ 51 + #define HCC_LTC(p) ((p) & (1 << 6)) 52 + /* true: no secondary Stream ID Support */ 53 + #define HCC_NSS(p) ((p) & (1 << 7)) 54 + /* true: HC supports Stopped - Short Packet */ 55 + #define HCC_SPC(p) ((p) & (1 << 9)) 56 + /* true: HC has Contiguous Frame ID Capability */ 57 + #define HCC_CFC(p) ((p) & (1 << 11)) 58 + /* Max size for Primary Stream Arrays - 2^(n+1), where n is bits 12:15 */ 59 + #define HCC_MAX_PSA(p) (1 << ((((p) >> 12) & 0xf) + 1)) 60 + /* Extended Capabilities pointer from PCI base - section 5.3.6 */ 61 + #define HCC_EXT_CAPS(p) XHCI_HCC_EXT_CAPS(p) 62 + 63 + #define CTX_SIZE(_hcc) (HCC_64BYTE_CONTEXT(_hcc) ? 64 : 32) 64 + 65 + /* db_off bitmask - bits 0:1 reserved */ 66 + #define DBOFF_MASK (~0x3) 67 + 68 + /* run_regs_off bitmask - bits 0:4 reserved */ 69 + #define RTSOFF_MASK (~0x1f) 70 + 71 + /* HCCPARAMS2 - hcc_params2 - bitmasks */ 72 + /* true: HC supports U3 entry Capability */ 73 + #define HCC2_U3C(p) ((p) & (1 << 0)) 74 + /* true: HC supports Configure endpoint command Max exit latency too large */ 75 + #define HCC2_CMC(p) ((p) & (1 << 1)) 76 + /* true: HC supports Force Save context Capability */ 77 + #define HCC2_FSC(p) ((p) & (1 << 2)) 78 + /* true: HC supports Compliance Transition Capability */ 79 + #define HCC2_CTC(p) ((p) & (1 << 3)) 80 + /* true: HC support Large ESIT payload Capability > 48k */ 81 + #define HCC2_LEC(p) ((p) & (1 << 4)) 82 + /* true: HC support Configuration Information Capability */ 83 + #define HCC2_CIC(p) ((p) & (1 << 5)) 84 + /* true: HC support Extended TBC Capability, Isoc burst count > 65535 */ 85 + #define HCC2_ETC(p) ((p) & (1 << 6))
+11 -2
drivers/usb/host/xhci-dbgcap.c
··· 634 634 return ret; 635 635 } 636 636 637 - return mod_delayed_work(system_wq, &dbc->event_work, 1); 637 + return mod_delayed_work(system_wq, &dbc->event_work, 638 + msecs_to_jiffies(dbc->poll_interval)); 638 639 } 639 640 640 641 static void xhci_dbc_stop(struct xhci_dbc *dbc) ··· 900 899 enum evtreturn evtr; 901 900 struct xhci_dbc *dbc; 902 901 unsigned long flags; 902 + unsigned int poll_interval; 903 903 904 904 dbc = container_of(to_delayed_work(work), struct xhci_dbc, event_work); 905 + poll_interval = dbc->poll_interval; 905 906 906 907 spin_lock_irqsave(&dbc->lock, flags); 907 908 evtr = xhci_dbc_do_handle_events(dbc); ··· 919 916 dbc->driver->disconnect(dbc); 920 917 break; 921 918 case EVT_DONE: 919 + /* set fast poll rate if there are pending data transfers */ 920 + if (!list_empty(&dbc->eps[BULK_OUT].list_pending) || 921 + !list_empty(&dbc->eps[BULK_IN].list_pending)) 922 + poll_interval = 1; 922 923 break; 923 924 default: 924 925 dev_info(dbc->dev, "stop handling dbc events\n"); 925 926 return; 926 927 } 927 928 928 - mod_delayed_work(system_wq, &dbc->event_work, 1); 929 + mod_delayed_work(system_wq, &dbc->event_work, 930 + msecs_to_jiffies(poll_interval)); 929 931 } 930 932 931 933 static const char * const dbc_state_strings[DS_MAX] = { ··· 1183 1175 dbc->idVendor = DBC_VENDOR_ID; 1184 1176 dbc->bcdDevice = DBC_DEVICE_REV; 1185 1177 dbc->bInterfaceProtocol = DBC_PROTOCOL; 1178 + dbc->poll_interval = DBC_POLL_INTERVAL_DEFAULT; 1186 1179 1187 1180 if (readl(&dbc->regs->control) & DBC_CTRL_DBC_ENABLE) 1188 1181 goto err;
+2
drivers/usb/host/xhci-dbgcap.h
··· 94 94 95 95 #define DBC_QUEUE_SIZE 16 96 96 #define DBC_WRITE_BUF_SIZE 8192 97 + #define DBC_POLL_INTERVAL_DEFAULT 64 /* milliseconds */ 97 98 98 99 /* 99 100 * Private structure for DbC hardware state: ··· 141 140 142 141 enum dbc_state state; 143 142 struct delayed_work event_work; 143 + unsigned int poll_interval; /* ms */ 144 144 unsigned resume_required:1; 145 145 struct dbc_ep eps[2]; 146 146
+11 -58
drivers/usb/host/xhci-hub.c
··· 448 448 } 449 449 EXPORT_SYMBOL_GPL(xhci_port_state_to_neutral); 450 450 451 - /** 452 - * xhci_find_slot_id_by_port() - Find slot id of a usb device on a roothub port 453 - * @hcd: pointer to hcd of the roothub 454 - * @xhci: pointer to xhci structure 455 - * @port: one-based port number of the port in this roothub. 456 - * 457 - * Return: Slot id of the usb device connected to the root port, 0 if not found 458 - */ 459 - 460 - int xhci_find_slot_id_by_port(struct usb_hcd *hcd, struct xhci_hcd *xhci, 461 - u16 port) 462 - { 463 - int slot_id; 464 - int i; 465 - enum usb_device_speed speed; 466 - 467 - slot_id = 0; 468 - for (i = 0; i < MAX_HC_SLOTS; i++) { 469 - if (!xhci->devs[i] || !xhci->devs[i]->udev) 470 - continue; 471 - speed = xhci->devs[i]->udev->speed; 472 - if (((speed >= USB_SPEED_SUPER) == (hcd->speed >= HCD_USB3)) 473 - && xhci->devs[i]->fake_port == port) { 474 - slot_id = i; 475 - break; 476 - } 477 - } 478 - 479 - return slot_id; 480 - } 481 - EXPORT_SYMBOL_GPL(xhci_find_slot_id_by_port); 482 - 483 451 /* 484 452 * Stop device 485 453 * It issues stop endpoint command for EP 0 to 30. And wait the last command ··· 898 930 struct xhci_bus_state *bus_state; 899 931 struct xhci_hcd *xhci; 900 932 struct usb_hcd *hcd; 901 - int slot_id; 902 933 u32 wIndex; 903 934 904 935 hcd = port->rhub->hcd; ··· 953 986 spin_lock_irqsave(&xhci->lock, *flags); 954 987 955 988 if (time_left) { 956 - slot_id = xhci_find_slot_id_by_port(hcd, xhci, 957 - wIndex + 1); 958 - if (!slot_id) { 989 + if (!port->slot_id) { 959 990 xhci_dbg(xhci, "slot_id is zero\n"); 960 991 return -ENODEV; 961 992 } 962 - xhci_ring_device(xhci, slot_id); 993 + xhci_ring_device(xhci, port->slot_id); 963 994 } else { 964 995 int port_status = readl(port->addr); 965 996 ··· 1167 1202 unsigned long flags; 1168 1203 u32 temp, status; 1169 1204 int retval = 0; 1170 - int slot_id; 1171 1205 struct xhci_bus_state *bus_state; 1172 1206 u16 link_state = 0; 1173 1207 u16 wake_mask = 0; ··· 1296 1332 goto error; 1297 1333 } 1298 1334 1299 - slot_id = xhci_find_slot_id_by_port(hcd, xhci, 1300 - portnum1); 1301 - if (!slot_id) { 1335 + if (!port->slot_id) { 1302 1336 xhci_warn(xhci, "slot_id is zero\n"); 1303 1337 goto error; 1304 1338 } 1305 1339 /* unlock to execute stop endpoint commands */ 1306 1340 spin_unlock_irqrestore(&xhci->lock, flags); 1307 - xhci_stop_device(xhci, slot_id, 1); 1341 + xhci_stop_device(xhci, port->slot_id, 1); 1308 1342 spin_lock_irqsave(&xhci->lock, flags); 1309 1343 1310 1344 xhci_set_link_state(xhci, port, XDEV_U3); ··· 1425 1463 1426 1464 if (link_state == USB_SS_PORT_LS_U3) { 1427 1465 int retries = 16; 1428 - slot_id = xhci_find_slot_id_by_port(hcd, xhci, 1429 - portnum1); 1430 - if (slot_id) { 1466 + if (port->slot_id) { 1431 1467 /* unlock to execute stop endpoint 1432 1468 * commands */ 1433 1469 spin_unlock_irqrestore(&xhci->lock, 1434 1470 flags); 1435 - xhci_stop_device(xhci, slot_id, 1); 1471 + xhci_stop_device(xhci, port->slot_id, 1); 1436 1472 spin_lock_irqsave(&xhci->lock, flags); 1437 1473 } 1438 1474 xhci_set_link_state(xhci, port, USB_SS_PORT_LS_U3); ··· 1544 1584 } 1545 1585 bus_state->port_c_suspend |= 1 << wIndex; 1546 1586 1547 - slot_id = xhci_find_slot_id_by_port(hcd, xhci, 1548 - portnum1); 1549 - if (!slot_id) { 1587 + if (!port->slot_id) { 1550 1588 xhci_dbg(xhci, "slot_id is zero\n"); 1551 1589 goto error; 1552 1590 } 1553 - xhci_ring_device(xhci, slot_id); 1591 + xhci_ring_device(xhci, port->slot_id); 1554 1592 break; 1555 1593 case USB_PORT_FEAT_C_SUSPEND: 1556 1594 bus_state->port_c_suspend &= ~(1 << wIndex); ··· 1779 1821 if (!portsc_buf[port_index]) 1780 1822 continue; 1781 1823 if (test_bit(port_index, &bus_state->bus_suspended)) { 1782 - int slot_id; 1783 - 1784 - slot_id = xhci_find_slot_id_by_port(hcd, xhci, 1785 - port_index + 1); 1824 + int slot_id = ports[port_index]->slot_id; 1786 1825 if (slot_id) { 1787 1826 spin_unlock_irqrestore(&xhci->lock, flags); 1788 1827 xhci_stop_device(xhci, slot_id, 1); ··· 1832 1877 struct xhci_bus_state *bus_state; 1833 1878 unsigned long flags; 1834 1879 int max_ports, port_index; 1835 - int slot_id; 1836 1880 int sret; 1837 1881 u32 next_state; 1838 1882 u32 temp, portsc; ··· 1924 1970 continue; 1925 1971 } 1926 1972 xhci_test_and_clear_bit(xhci, ports[port_index], PORT_PLC); 1927 - slot_id = xhci_find_slot_id_by_port(hcd, xhci, port_index + 1); 1928 - if (slot_id) 1929 - xhci_ring_device(xhci, slot_id); 1973 + if (ports[port_index]->slot_id) 1974 + xhci_ring_device(xhci, ports[port_index]->slot_id); 1930 1975 } 1931 1976 (void) readl(&xhci->op_regs->command); 1932 1977
+42 -53
drivers/usb/host/xhci-mem.c
··· 84 84 struct xhci_segment *seg; 85 85 86 86 seg = first->next; 87 - while (seg != first) { 87 + while (seg && seg != first) { 88 88 struct xhci_segment *next = seg->next; 89 89 xhci_segment_free(xhci, seg); 90 90 seg = next; ··· 351 351 352 352 next = xhci_segment_alloc(xhci, cycle_state, max_packet, num, 353 353 flags); 354 - if (!next) { 355 - prev = *first; 356 - while (prev) { 357 - next = prev->next; 358 - xhci_segment_free(xhci, prev); 359 - prev = next; 360 - } 361 - return -ENOMEM; 362 - } 363 - xhci_link_segments(prev, next, type, chain_links); 354 + if (!next) 355 + goto free_segments; 364 356 357 + xhci_link_segments(prev, next, type, chain_links); 365 358 prev = next; 366 359 num++; 367 360 } ··· 362 369 *last = prev; 363 370 364 371 return 0; 372 + 373 + free_segments: 374 + xhci_free_segments_for_ring(xhci, *first); 375 + return -ENOMEM; 365 376 } 366 377 367 378 /* ··· 441 444 if (ret) 442 445 return -ENOMEM; 443 446 444 - if (ring->type == TYPE_STREAM) 447 + if (ring->type == TYPE_STREAM) { 445 448 ret = xhci_update_stream_segment_mapping(ring->trb_address_map, 446 449 ring, first, last, flags); 447 - if (ret) { 448 - struct xhci_segment *next; 449 - do { 450 - next = first->next; 451 - xhci_segment_free(xhci, first); 452 - if (first == last) 453 - break; 454 - first = next; 455 - } while (true); 456 - return ret; 450 + if (ret) 451 + goto free_segments; 457 452 } 458 453 459 454 xhci_link_rings(xhci, ring, first, last, num_new_segs); ··· 455 466 ring->num_segs); 456 467 457 468 return 0; 469 + 470 + free_segments: 471 + xhci_free_segments_for_ring(xhci, first); 472 + return ret; 458 473 } 459 474 460 475 struct xhci_container_ctx *xhci_alloc_container_ctx(struct xhci_hcd *xhci, ··· 782 789 bool slot_found = false; 783 790 784 791 /* If the device never made it past the Set Address stage, 785 - * it may not have the real_port set correctly. 792 + * it may not have the root hub port pointer set correctly. 786 793 */ 787 - if (virt_dev->real_port == 0 || 788 - virt_dev->real_port > HCS_MAX_PORTS(xhci->hcs_params1)) { 789 - xhci_dbg(xhci, "Bad real port.\n"); 794 + if (!virt_dev->rhub_port) { 795 + xhci_dbg(xhci, "Bad rhub port.\n"); 790 796 return; 791 797 } 792 798 793 - tt_list_head = &(xhci->rh_bw[virt_dev->real_port - 1].tts); 799 + tt_list_head = &(xhci->rh_bw[virt_dev->rhub_port->hw_portnum].tts); 794 800 list_for_each_entry_safe(tt_info, next, tt_list_head, tt_list) { 795 801 /* Multi-TT hubs will have more than one entry */ 796 802 if (tt_info->slot_id == slot_id) { ··· 826 834 goto free_tts; 827 835 INIT_LIST_HEAD(&tt_info->tt_list); 828 836 list_add(&tt_info->tt_list, 829 - &xhci->rh_bw[virt_dev->real_port - 1].tts); 837 + &xhci->rh_bw[virt_dev->rhub_port->hw_portnum].tts); 830 838 tt_info->slot_id = virt_dev->udev->slot_id; 831 839 if (tt->multi) 832 840 tt_info->ttport = i+1; ··· 900 908 901 909 if (dev->udev && dev->udev->slot_id) 902 910 dev->udev->slot_id = 0; 911 + if (dev->rhub_port && dev->rhub_port->slot_id == slot_id) 912 + dev->rhub_port->slot_id = 0; 903 913 kfree(xhci->devs[slot_id]); 904 914 xhci->devs[slot_id] = NULL; 905 915 } ··· 923 929 if (!vdev) 924 930 return; 925 931 926 - if (vdev->real_port == 0 || 927 - vdev->real_port > HCS_MAX_PORTS(xhci->hcs_params1)) { 928 - xhci_dbg(xhci, "Bad vdev->real_port.\n"); 932 + if (!vdev->rhub_port) { 933 + xhci_dbg(xhci, "Bad rhub port.\n"); 929 934 goto out; 930 935 } 931 936 932 - tt_list_head = &(xhci->rh_bw[vdev->real_port - 1].tts); 937 + tt_list_head = &(xhci->rh_bw[vdev->rhub_port->hw_portnum].tts); 933 938 list_for_each_entry_safe(tt_info, next, tt_list_head, tt_list) { 934 939 /* is this a hub device that added a tt_info to the tts list */ 935 940 if (tt_info->slot_id == slot_id) { ··· 1044 1051 * The xHCI roothub may have ports of differing speeds in any order in the port 1045 1052 * status registers. 1046 1053 * 1047 - * The xHCI hardware wants to know the roothub port number that the USB device 1054 + * The xHCI hardware wants to know the roothub port that the USB device 1048 1055 * is attached to (or the roothub port its ancestor hub is attached to). All we 1049 1056 * know is the index of that port under either the USB 2.0 or the USB 3.0 1050 1057 * roothub, but that doesn't give us the real index into the HW port status 1051 - * registers. Call xhci_find_raw_port_number() to get real index. 1058 + * registers. 1052 1059 */ 1053 - static u32 xhci_find_real_port_number(struct xhci_hcd *xhci, 1054 - struct usb_device *udev) 1060 + static struct xhci_port *xhci_find_rhub_port(struct xhci_hcd *xhci, struct usb_device *udev) 1055 1061 { 1056 1062 struct usb_device *top_dev; 1063 + struct xhci_hub *rhub; 1057 1064 struct usb_hcd *hcd; 1058 1065 1059 1066 if (udev->speed >= USB_SPEED_SUPER) ··· 1065 1072 top_dev = top_dev->parent) 1066 1073 /* Found device below root hub */; 1067 1074 1068 - return xhci_find_raw_port_number(hcd, top_dev->portnum); 1075 + rhub = xhci_get_rhub(hcd); 1076 + return rhub->ports[top_dev->portnum - 1]; 1069 1077 } 1070 1078 1071 1079 /* Setup an xHCI virtual device for a Set Address command */ ··· 1075 1081 struct xhci_virt_device *dev; 1076 1082 struct xhci_ep_ctx *ep0_ctx; 1077 1083 struct xhci_slot_ctx *slot_ctx; 1078 - u32 port_num; 1079 1084 u32 max_packets; 1080 - struct usb_device *top_dev; 1081 1085 1082 1086 dev = xhci->devs[udev->slot_id]; 1083 1087 /* Slot ID 0 is reserved */ ··· 1116 1124 return -EINVAL; 1117 1125 } 1118 1126 /* Find the root hub port this device is under */ 1119 - port_num = xhci_find_real_port_number(xhci, udev); 1120 - if (!port_num) 1127 + dev->rhub_port = xhci_find_rhub_port(xhci, udev); 1128 + if (!dev->rhub_port) 1121 1129 return -EINVAL; 1122 - slot_ctx->dev_info2 |= cpu_to_le32(ROOT_HUB_PORT(port_num)); 1123 - /* Set the port number in the virtual_device to the faked port number */ 1124 - for (top_dev = udev; top_dev->parent && top_dev->parent->parent; 1125 - top_dev = top_dev->parent) 1126 - /* Found device below root hub */; 1127 - dev->fake_port = top_dev->portnum; 1128 - dev->real_port = port_num; 1129 - xhci_dbg(xhci, "Set root hub portnum to %d\n", port_num); 1130 - xhci_dbg(xhci, "Set fake root hub portnum to %d\n", dev->fake_port); 1130 + /* Slot ID is set to the device directly below the root hub */ 1131 + if (!udev->parent->parent) 1132 + dev->rhub_port->slot_id = udev->slot_id; 1133 + slot_ctx->dev_info2 |= cpu_to_le32(ROOT_HUB_PORT(dev->rhub_port->hw_portnum + 1)); 1134 + xhci_dbg(xhci, "Slot ID %d: HW portnum %d, hcd portnum %d\n", 1135 + udev->slot_id, dev->rhub_port->hw_portnum, dev->rhub_port->hcd_portnum); 1131 1136 1132 1137 /* Find the right bandwidth table that this device will be a part of. 1133 1138 * If this is a full speed device attached directly to a root port (or a ··· 1133 1144 * will never be created for the HS root hub. 1134 1145 */ 1135 1146 if (!udev->tt || !udev->tt->hub->parent) { 1136 - dev->bw_table = &xhci->rh_bw[port_num - 1].bw_table; 1147 + dev->bw_table = &xhci->rh_bw[dev->rhub_port->hw_portnum].bw_table; 1137 1148 } else { 1138 1149 struct xhci_root_port_bw_info *rh_bw; 1139 1150 struct xhci_tt_bw_info *tt_bw; 1140 1151 1141 - rh_bw = &xhci->rh_bw[port_num - 1]; 1152 + rh_bw = &xhci->rh_bw[dev->rhub_port->hw_portnum]; 1142 1153 /* Find the right TT. */ 1143 1154 list_for_each_entry(tt_bw, &rh_bw->tts, tt_list) { 1144 1155 if (tt_bw->slot_id != udev->tt->hub->slot_id) ··· 2522 2533 if (xhci_add_interrupter(xhci, ir, 0)) 2523 2534 goto fail; 2524 2535 2525 - xhci->isoc_bei_interval = AVOID_BEI_INTERVAL_MAX; 2536 + ir->isoc_bei_interval = AVOID_BEI_INTERVAL_MAX; 2526 2537 2527 2538 /* 2528 2539 * XXX: Might need to set the Interrupter Moderation Register to
+5 -9
drivers/usb/host/xhci-mtk-sch.c
··· 122 122 * each HS root port is treated as a single bandwidth domain, 123 123 * but each SS root port is treated as two bandwidth domains, one for IN eps, 124 124 * one for OUT eps. 125 - * @real_port value is defined as follow according to xHCI spec: 126 - * 1 for SSport0, ..., N+1 for SSportN, N+2 for HSport0, N+3 for HSport1, etc 127 - * so the bandwidth domain array is organized as follow for simplification: 128 - * SSport0-OUT, SSport0-IN, ..., SSportX-OUT, SSportX-IN, HSport0, ..., HSportY 129 125 */ 130 126 static struct mu3h_sch_bw_info * 131 127 get_bw_info(struct xhci_hcd_mtk *mtk, struct usb_device *udev, ··· 132 136 int bw_index; 133 137 134 138 virt_dev = xhci->devs[udev->slot_id]; 135 - if (!virt_dev->real_port) { 136 - WARN_ONCE(1, "%s invalid real_port\n", dev_name(&udev->dev)); 139 + if (!virt_dev->rhub_port) { 140 + WARN_ONCE(1, "%s invalid rhub port\n", dev_name(&udev->dev)); 137 141 return NULL; 138 142 } 139 143 140 144 if (udev->speed >= USB_SPEED_SUPER) { 141 145 if (usb_endpoint_dir_out(&ep->desc)) 142 - bw_index = (virt_dev->real_port - 1) * 2; 146 + bw_index = (virt_dev->rhub_port->hw_portnum) * 2; 143 147 else 144 - bw_index = (virt_dev->real_port - 1) * 2 + 1; 148 + bw_index = (virt_dev->rhub_port->hw_portnum) * 2 + 1; 145 149 } else { 146 150 /* add one more for each SS port */ 147 - bw_index = virt_dev->real_port + xhci->usb3_rhub.num_ports - 1; 151 + bw_index = virt_dev->rhub_port->hw_portnum + xhci->usb3_rhub.num_ports; 148 152 } 149 153 150 154 return &mtk->sch_array[bw_index];
+8 -7
drivers/usb/host/xhci-pci.c
··· 307 307 xhci->quirks |= XHCI_RESET_ON_RESUME; 308 308 } 309 309 310 - if (pdev->vendor == PCI_VENDOR_ID_AMD) 310 + if (pdev->vendor == PCI_VENDOR_ID_AMD) { 311 311 xhci->quirks |= XHCI_TRUST_TX_LENGTH; 312 + if (pdev->device == 0x43f7) 313 + xhci->quirks |= XHCI_DEFAULT_PM_RUNTIME_ALLOW; 314 + } 312 315 313 316 if ((pdev->vendor == PCI_VENDOR_ID_AMD) && 314 317 ((pdev->device == PCI_DEVICE_ID_AMD_PROMONTORYA_4) || ··· 823 820 struct xhci_hcd *xhci = hcd_to_xhci(hcd); 824 821 struct xhci_port *port; 825 822 struct usb_device *udev; 826 - unsigned int slot_id; 827 823 u32 portsc; 828 824 int i; 829 825 ··· 845 843 if ((portsc & PORT_PLS_MASK) != XDEV_U3) 846 844 continue; 847 845 848 - slot_id = xhci_find_slot_id_by_port(port->rhub->hcd, xhci, 849 - port->hcd_portnum + 1); 850 - if (!slot_id || !xhci->devs[slot_id]) { 846 + if (!port->slot_id || !xhci->devs[port->slot_id]) { 851 847 xhci_err(xhci, "No dev for slot_id %d for port %d-%d in U3\n", 852 - slot_id, port->rhub->hcd->self.busnum, port->hcd_portnum + 1); 848 + port->slot_id, port->rhub->hcd->self.busnum, 849 + port->hcd_portnum + 1); 853 850 continue; 854 851 } 855 852 856 - udev = xhci->devs[slot_id]->udev; 853 + udev = xhci->devs[port->slot_id]->udev; 857 854 858 855 /* if wakeup is enabled then don't disable the port */ 859 856 if (udev->do_remote_wakeup && do_wakeup)
+176
drivers/usb/host/xhci-port.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + 3 + /* PORTSC - Port Status and Control Register - port_status_base bitmasks */ 4 + /* true: device connected */ 5 + #define PORT_CONNECT (1 << 0) 6 + /* true: port enabled */ 7 + #define PORT_PE (1 << 1) 8 + /* bit 2 reserved and zeroed */ 9 + /* true: port has an over-current condition */ 10 + #define PORT_OC (1 << 3) 11 + /* true: port reset signaling asserted */ 12 + #define PORT_RESET (1 << 4) 13 + /* Port Link State - bits 5:8 14 + * A read gives the current link PM state of the port, 15 + * a write with Link State Write Strobe set sets the link state. 16 + */ 17 + #define PORT_PLS_MASK (0xf << 5) 18 + #define XDEV_U0 (0x0 << 5) 19 + #define XDEV_U1 (0x1 << 5) 20 + #define XDEV_U2 (0x2 << 5) 21 + #define XDEV_U3 (0x3 << 5) 22 + #define XDEV_DISABLED (0x4 << 5) 23 + #define XDEV_RXDETECT (0x5 << 5) 24 + #define XDEV_INACTIVE (0x6 << 5) 25 + #define XDEV_POLLING (0x7 << 5) 26 + #define XDEV_RECOVERY (0x8 << 5) 27 + #define XDEV_HOT_RESET (0x9 << 5) 28 + #define XDEV_COMP_MODE (0xa << 5) 29 + #define XDEV_TEST_MODE (0xb << 5) 30 + #define XDEV_RESUME (0xf << 5) 31 + 32 + /* true: port has power (see HCC_PPC) */ 33 + #define PORT_POWER (1 << 9) 34 + /* bits 10:13 indicate device speed: 35 + * 0 - undefined speed - port hasn't be initialized by a reset yet 36 + * 1 - full speed 37 + * 2 - low speed 38 + * 3 - high speed 39 + * 4 - super speed 40 + * 5-15 reserved 41 + */ 42 + #define DEV_SPEED_MASK (0xf << 10) 43 + #define XDEV_FS (0x1 << 10) 44 + #define XDEV_LS (0x2 << 10) 45 + #define XDEV_HS (0x3 << 10) 46 + #define XDEV_SS (0x4 << 10) 47 + #define XDEV_SSP (0x5 << 10) 48 + #define DEV_UNDEFSPEED(p) (((p) & DEV_SPEED_MASK) == (0x0<<10)) 49 + #define DEV_FULLSPEED(p) (((p) & DEV_SPEED_MASK) == XDEV_FS) 50 + #define DEV_LOWSPEED(p) (((p) & DEV_SPEED_MASK) == XDEV_LS) 51 + #define DEV_HIGHSPEED(p) (((p) & DEV_SPEED_MASK) == XDEV_HS) 52 + #define DEV_SUPERSPEED(p) (((p) & DEV_SPEED_MASK) == XDEV_SS) 53 + #define DEV_SUPERSPEEDPLUS(p) (((p) & DEV_SPEED_MASK) == XDEV_SSP) 54 + #define DEV_SUPERSPEED_ANY(p) (((p) & DEV_SPEED_MASK) >= XDEV_SS) 55 + #define DEV_PORT_SPEED(p) (((p) >> 10) & 0x0f) 56 + 57 + /* Bits 20:23 in the Slot Context are the speed for the device */ 58 + #define SLOT_SPEED_FS (XDEV_FS << 10) 59 + #define SLOT_SPEED_LS (XDEV_LS << 10) 60 + #define SLOT_SPEED_HS (XDEV_HS << 10) 61 + #define SLOT_SPEED_SS (XDEV_SS << 10) 62 + #define SLOT_SPEED_SSP (XDEV_SSP << 10) 63 + /* Port Indicator Control */ 64 + #define PORT_LED_OFF (0 << 14) 65 + #define PORT_LED_AMBER (1 << 14) 66 + #define PORT_LED_GREEN (2 << 14) 67 + #define PORT_LED_MASK (3 << 14) 68 + /* Port Link State Write Strobe - set this when changing link state */ 69 + #define PORT_LINK_STROBE (1 << 16) 70 + /* true: connect status change */ 71 + #define PORT_CSC (1 << 17) 72 + /* true: port enable change */ 73 + #define PORT_PEC (1 << 18) 74 + /* true: warm reset for a USB 3.0 device is done. A "hot" reset puts the port 75 + * into an enabled state, and the device into the default state. A "warm" reset 76 + * also resets the link, forcing the device through the link training sequence. 77 + * SW can also look at the Port Reset register to see when warm reset is done. 78 + */ 79 + #define PORT_WRC (1 << 19) 80 + /* true: over-current change */ 81 + #define PORT_OCC (1 << 20) 82 + /* true: reset change - 1 to 0 transition of PORT_RESET */ 83 + #define PORT_RC (1 << 21) 84 + /* port link status change - set on some port link state transitions: 85 + * Transition Reason 86 + * ------------------------------------------------------------------------------ 87 + * - U3 to Resume Wakeup signaling from a device 88 + * - Resume to Recovery to U0 USB 3.0 device resume 89 + * - Resume to U0 USB 2.0 device resume 90 + * - U3 to Recovery to U0 Software resume of USB 3.0 device complete 91 + * - U3 to U0 Software resume of USB 2.0 device complete 92 + * - U2 to U0 L1 resume of USB 2.1 device complete 93 + * - U0 to U0 (???) L1 entry rejection by USB 2.1 device 94 + * - U0 to disabled L1 entry error with USB 2.1 device 95 + * - Any state to inactive Error on USB 3.0 port 96 + */ 97 + #define PORT_PLC (1 << 22) 98 + /* port configure error change - port failed to configure its link partner */ 99 + #define PORT_CEC (1 << 23) 100 + #define PORT_CHANGE_MASK (PORT_CSC | PORT_PEC | PORT_WRC | PORT_OCC | \ 101 + PORT_RC | PORT_PLC | PORT_CEC) 102 + 103 + 104 + /* Cold Attach Status - xHC can set this bit to report device attached during 105 + * Sx state. Warm port reset should be perfomed to clear this bit and move port 106 + * to connected state. 107 + */ 108 + #define PORT_CAS (1 << 24) 109 + /* wake on connect (enable) */ 110 + #define PORT_WKCONN_E (1 << 25) 111 + /* wake on disconnect (enable) */ 112 + #define PORT_WKDISC_E (1 << 26) 113 + /* wake on over-current (enable) */ 114 + #define PORT_WKOC_E (1 << 27) 115 + /* bits 28:29 reserved */ 116 + /* true: device is non-removable - for USB 3.0 roothub emulation */ 117 + #define PORT_DEV_REMOVE (1 << 30) 118 + /* Initiate a warm port reset - complete when PORT_WRC is '1' */ 119 + #define PORT_WR (1 << 31) 120 + 121 + /* We mark duplicate entries with -1 */ 122 + #define DUPLICATE_ENTRY ((u8)(-1)) 123 + 124 + /* Port Power Management Status and Control - port_power_base bitmasks */ 125 + /* Inactivity timer value for transitions into U1, in microseconds. 126 + * Timeout can be up to 127us. 0xFF means an infinite timeout. 127 + */ 128 + #define PORT_U1_TIMEOUT(p) ((p) & 0xff) 129 + #define PORT_U1_TIMEOUT_MASK 0xff 130 + /* Inactivity timer value for transitions into U2 */ 131 + #define PORT_U2_TIMEOUT(p) (((p) & 0xff) << 8) 132 + #define PORT_U2_TIMEOUT_MASK (0xff << 8) 133 + /* Bits 24:31 for port testing */ 134 + 135 + /* USB2 Protocol PORTSPMSC */ 136 + #define PORT_L1S_MASK 7 137 + #define PORT_L1S_SUCCESS 1 138 + #define PORT_RWE (1 << 3) 139 + #define PORT_HIRD(p) (((p) & 0xf) << 4) 140 + #define PORT_HIRD_MASK (0xf << 4) 141 + #define PORT_L1DS_MASK (0xff << 8) 142 + #define PORT_L1DS(p) (((p) & 0xff) << 8) 143 + #define PORT_HLE (1 << 16) 144 + #define PORT_TEST_MODE_SHIFT 28 145 + 146 + /* USB3 Protocol PORTLI Port Link Information */ 147 + #define PORT_RX_LANES(p) (((p) >> 16) & 0xf) 148 + #define PORT_TX_LANES(p) (((p) >> 20) & 0xf) 149 + 150 + /* USB2 Protocol PORTHLPMC */ 151 + #define PORT_HIRDM(p)((p) & 3) 152 + #define PORT_L1_TIMEOUT(p)(((p) & 0xff) << 2) 153 + #define PORT_BESLD(p)(((p) & 0xf) << 10) 154 + 155 + /* use 512 microseconds as USB2 LPM L1 default timeout. */ 156 + #define XHCI_L1_TIMEOUT 512 157 + 158 + /* Set default HIRD/BESL value to 4 (350/400us) for USB2 L1 LPM resume latency. 159 + * Safe to use with mixed HIRD and BESL systems (host and device) and is used 160 + * by other operating systems. 161 + * 162 + * XHCI 1.0 errata 8/14/12 Table 13 notes: 163 + * "Software should choose xHC BESL/BESLD field values that do not violate a 164 + * device's resume latency requirements, 165 + * e.g. not program values > '4' if BLC = '1' and a HIRD device is attached, 166 + * or not program values < '4' if BLC = '0' and a BESL device is attached. 167 + */ 168 + #define XHCI_DEFAULT_BESL 4 169 + 170 + /* 171 + * USB3 specification define a 360ms tPollingLFPSTiemout for USB3 ports 172 + * to complete link training. usually link trainig completes much faster 173 + * so check status 10 times with 36ms sleep in places we need to wait for 174 + * polling to complete. 175 + */ 176 + #define XHCI_PORT_POLLING_LFPS_TIME 36
+121 -106
drivers/usb/host/xhci-ring.c
··· 113 113 return urb_priv->num_tds_done == urb_priv->num_tds; 114 114 } 115 115 116 + static bool unhandled_event_trb(struct xhci_ring *ring) 117 + { 118 + return ((le32_to_cpu(ring->dequeue->event_cmd.flags) & TRB_CYCLE) == 119 + ring->cycle_state); 120 + } 121 + 116 122 static void inc_td_cnt(struct urb *urb) 117 123 { 118 124 struct urb_priv *urb_priv = urb->hcpriv; ··· 1160 1154 break; 1161 1155 ep->ep_state &= ~EP_STOP_CMD_PENDING; 1162 1156 return; 1157 + case EP_STATE_STOPPED: 1158 + /* 1159 + * NEC uPD720200 sometimes sets this state and fails with 1160 + * Context Error while continuing to process TRBs. 1161 + * Be conservative and trust EP_CTX_STATE on other chips. 1162 + */ 1163 + if (!(xhci->quirks & XHCI_NEC_HOST)) 1164 + break; 1165 + fallthrough; 1163 1166 case EP_STATE_RUNNING: 1164 1167 /* Race, HW handled stop ep cmd before ep was running */ 1165 1168 xhci_dbg(xhci, "Stop ep completion ctx error, ep is running\n"); ··· 1885 1870 u32 port_id; 1886 1871 u32 portsc, cmd_reg; 1887 1872 int max_ports; 1888 - int slot_id; 1889 1873 unsigned int hcd_portnum; 1890 1874 struct xhci_bus_state *bus_state; 1891 1875 bool bogus_port_status = false; ··· 1936 1922 1937 1923 if (hcd->speed >= HCD_USB3 && 1938 1924 (portsc & PORT_PLS_MASK) == XDEV_INACTIVE) { 1939 - slot_id = xhci_find_slot_id_by_port(hcd, xhci, hcd_portnum + 1); 1940 - if (slot_id && xhci->devs[slot_id]) 1941 - xhci->devs[slot_id]->flags |= VDEV_PORT_ERROR; 1925 + if (port->slot_id && xhci->devs[port->slot_id]) 1926 + xhci->devs[port->slot_id]->flags |= VDEV_PORT_ERROR; 1942 1927 } 1943 1928 1944 1929 if ((portsc & PORT_PLC) && (portsc & PORT_PLS_MASK) == XDEV_RESUME) { ··· 1995 1982 * so the roothub behavior is consistent with external 1996 1983 * USB 3.0 hub behavior. 1997 1984 */ 1998 - slot_id = xhci_find_slot_id_by_port(hcd, xhci, hcd_portnum + 1); 1999 - if (slot_id && xhci->devs[slot_id]) 2000 - xhci_ring_device(xhci, slot_id); 1985 + if (port->slot_id && xhci->devs[port->slot_id]) 1986 + xhci_ring_device(xhci, port->slot_id); 2001 1987 if (bus_state->port_remote_wakeup & (1 << hcd_portnum)) { 2002 1988 xhci_test_and_clear_bit(xhci, port, PORT_PLC); 2003 1989 usb_wakeup_notification(hcd->self.root_hub, ··· 2828 2816 td_num--; 2829 2817 2830 2818 /* Is this a TRB in the currently executing TD? */ 2831 - ep_seg = trb_in_td(xhci, ep_ring->deq_seg, ep_ring->dequeue, 2819 + ep_seg = trb_in_td(xhci, td->start_seg, td->first_trb, 2832 2820 td->last_trb, ep_trb_dma, false); 2833 2821 2834 2822 /* ··· 2896 2884 "part of current TD ep_index %d " 2897 2885 "comp_code %u\n", ep_index, 2898 2886 trb_comp_code); 2899 - trb_in_td(xhci, ep_ring->deq_seg, 2900 - ep_ring->dequeue, td->last_trb, 2901 - ep_trb_dma, true); 2887 + trb_in_td(xhci, td->start_seg, td->first_trb, 2888 + td->last_trb, ep_trb_dma, true); 2902 2889 return -ESHUTDOWN; 2903 2890 } 2904 2891 } ··· 2973 2962 } 2974 2963 2975 2964 /* 2976 - * This function handles all OS-owned events on the event ring. It may drop 2965 + * This function handles one OS-owned event on the event ring. It may drop 2977 2966 * xhci->lock between event processing (e.g. to pass up port status changes). 2978 - * Returns >0 for "possibly more events to process" (caller should call again), 2979 - * otherwise 0 if done. In future, <0 returns should indicate error code. 2980 2967 */ 2981 - static int xhci_handle_event(struct xhci_hcd *xhci, struct xhci_interrupter *ir) 2968 + static int xhci_handle_event_trb(struct xhci_hcd *xhci, struct xhci_interrupter *ir, 2969 + union xhci_trb *event) 2982 2970 { 2983 - union xhci_trb *event; 2984 2971 u32 trb_type; 2985 - 2986 - /* Event ring hasn't been allocated yet. */ 2987 - if (!ir || !ir->event_ring || !ir->event_ring->dequeue) { 2988 - xhci_err(xhci, "ERROR interrupter not ready\n"); 2989 - return -ENOMEM; 2990 - } 2991 - 2992 - event = ir->event_ring->dequeue; 2993 - /* Does the HC or OS own the TRB? */ 2994 - if ((le32_to_cpu(event->event_cmd.flags) & TRB_CYCLE) != 2995 - ir->event_ring->cycle_state) 2996 - return 0; 2997 2972 2998 2973 trace_xhci_handle_event(ir->event_ring, &event->generic); 2999 2974 3000 2975 /* 3001 - * Barrier between reading the TRB_CYCLE (valid) flag above and any 2976 + * Barrier between reading the TRB_CYCLE (valid) flag before, and any 3002 2977 * speculative reads of the event's flags/data below. 3003 2978 */ 3004 2979 rmb(); ··· 3014 3017 * to make sure a watchdog timer didn't mark the host as non-responsive. 3015 3018 */ 3016 3019 if (xhci->xhc_state & XHCI_STATE_DYING) { 3017 - xhci_dbg(xhci, "xHCI host dying, returning from " 3018 - "event handler.\n"); 3019 - return 0; 3020 + xhci_dbg(xhci, "xHCI host dying, returning from event handler.\n"); 3021 + return -ENODEV; 3020 3022 } 3021 3023 3022 - /* Update SW event ring dequeue pointer */ 3023 - inc_deq(xhci, ir->event_ring); 3024 - 3025 - /* Are there more items on the event ring? Caller will call us again to 3026 - * check. 3027 - */ 3028 - return 1; 3024 + return 0; 3029 3025 } 3030 3026 3031 3027 /* ··· 3028 3038 */ 3029 3039 static void xhci_update_erst_dequeue(struct xhci_hcd *xhci, 3030 3040 struct xhci_interrupter *ir, 3031 - union xhci_trb *event_ring_deq, 3032 3041 bool clear_ehb) 3033 3042 { 3034 3043 u64 temp_64; 3035 3044 dma_addr_t deq; 3036 3045 3037 3046 temp_64 = xhci_read_64(xhci, &ir->ir_set->erst_dequeue); 3038 - /* If necessary, update the HW's version of the event ring deq ptr. */ 3039 - if (event_ring_deq != ir->event_ring->dequeue) { 3040 - deq = xhci_trb_virt_to_dma(ir->event_ring->deq_seg, 3041 - ir->event_ring->dequeue); 3042 - if (deq == 0) 3043 - xhci_warn(xhci, "WARN something wrong with SW event ring dequeue ptr\n"); 3044 - /* 3045 - * Per 4.9.4, Software writes to the ERDP register shall 3046 - * always advance the Event Ring Dequeue Pointer value. 3047 - */ 3048 - if ((temp_64 & ERST_PTR_MASK) == (deq & ERST_PTR_MASK)) 3049 - return; 3047 + deq = xhci_trb_virt_to_dma(ir->event_ring->deq_seg, 3048 + ir->event_ring->dequeue); 3049 + if (deq == 0) 3050 + xhci_warn(xhci, "WARN something wrong with SW event ring dequeue ptr\n"); 3051 + /* 3052 + * Per 4.9.4, Software writes to the ERDP register shall always advance 3053 + * the Event Ring Dequeue Pointer value. 3054 + */ 3055 + if ((temp_64 & ERST_PTR_MASK) == (deq & ERST_PTR_MASK) && !clear_ehb) 3056 + return; 3050 3057 3051 - /* Update HC event ring dequeue pointer */ 3052 - temp_64 = ir->event_ring->deq_seg->num & ERST_DESI_MASK; 3053 - temp_64 |= deq & ERST_PTR_MASK; 3054 - } 3058 + /* Update HC event ring dequeue pointer */ 3059 + temp_64 = ir->event_ring->deq_seg->num & ERST_DESI_MASK; 3060 + temp_64 |= deq & ERST_PTR_MASK; 3055 3061 3056 3062 /* Clear the event handler busy flag (RW1C) */ 3057 3063 if (clear_ehb) 3058 3064 temp_64 |= ERST_EHB; 3059 3065 xhci_write_64(xhci, temp_64, &ir->ir_set->erst_dequeue); 3066 + } 3067 + 3068 + /* Clear the interrupt pending bit for a specific interrupter. */ 3069 + static void xhci_clear_interrupt_pending(struct xhci_hcd *xhci, 3070 + struct xhci_interrupter *ir) 3071 + { 3072 + if (!ir->ip_autoclear) { 3073 + u32 irq_pending; 3074 + 3075 + irq_pending = readl(&ir->ir_set->irq_pending); 3076 + irq_pending |= IMAN_IP; 3077 + writel(irq_pending, &ir->ir_set->irq_pending); 3078 + } 3079 + } 3080 + 3081 + /* 3082 + * Handle all OS-owned events on an interrupter event ring. It may drop 3083 + * and reaquire xhci->lock between event processing. 3084 + */ 3085 + static int xhci_handle_events(struct xhci_hcd *xhci, struct xhci_interrupter *ir) 3086 + { 3087 + int event_loop = 0; 3088 + int err; 3089 + u64 temp; 3090 + 3091 + xhci_clear_interrupt_pending(xhci, ir); 3092 + 3093 + /* Event ring hasn't been allocated yet. */ 3094 + if (!ir->event_ring || !ir->event_ring->dequeue) { 3095 + xhci_err(xhci, "ERROR interrupter event ring not ready\n"); 3096 + return -ENOMEM; 3097 + } 3098 + 3099 + if (xhci->xhc_state & XHCI_STATE_DYING || 3100 + xhci->xhc_state & XHCI_STATE_HALTED) { 3101 + xhci_dbg(xhci, "xHCI dying, ignoring interrupt. Shouldn't IRQs be disabled?\n"); 3102 + 3103 + /* Clear the event handler busy flag (RW1C) */ 3104 + temp = xhci_read_64(xhci, &ir->ir_set->erst_dequeue); 3105 + xhci_write_64(xhci, temp | ERST_EHB, &ir->ir_set->erst_dequeue); 3106 + return -ENODEV; 3107 + } 3108 + 3109 + /* Process all OS owned event TRBs on this event ring */ 3110 + while (unhandled_event_trb(ir->event_ring)) { 3111 + err = xhci_handle_event_trb(xhci, ir, ir->event_ring->dequeue); 3112 + 3113 + /* 3114 + * If half a segment of events have been handled in one go then 3115 + * update ERDP, and force isoc trbs to interrupt more often 3116 + */ 3117 + if (event_loop++ > TRBS_PER_SEGMENT / 2) { 3118 + xhci_update_erst_dequeue(xhci, ir, false); 3119 + 3120 + if (ir->isoc_bei_interval > AVOID_BEI_INTERVAL_MIN) 3121 + ir->isoc_bei_interval = ir->isoc_bei_interval / 2; 3122 + 3123 + event_loop = 0; 3124 + } 3125 + 3126 + /* Update SW event ring dequeue pointer */ 3127 + inc_deq(xhci, ir->event_ring); 3128 + 3129 + if (err) 3130 + break; 3131 + } 3132 + 3133 + xhci_update_erst_dequeue(xhci, ir, true); 3134 + 3135 + return 0; 3060 3136 } 3061 3137 3062 3138 /* ··· 3133 3077 irqreturn_t xhci_irq(struct usb_hcd *hcd) 3134 3078 { 3135 3079 struct xhci_hcd *xhci = hcd_to_xhci(hcd); 3136 - union xhci_trb *event_ring_deq; 3137 - struct xhci_interrupter *ir; 3138 3080 irqreturn_t ret = IRQ_NONE; 3139 - u64 temp_64; 3140 3081 u32 status; 3141 - int event_loop = 0; 3142 3082 3143 3083 spin_lock(&xhci->lock); 3144 3084 /* Check if the xHC generated the interrupt, or the irq is shared */ ··· 3167 3115 */ 3168 3116 status |= STS_EINT; 3169 3117 writel(status, &xhci->op_regs->status); 3170 - 3171 - /* This is the handler of the primary interrupter */ 3172 - ir = xhci->interrupters[0]; 3173 - if (!hcd->msi_enabled) { 3174 - u32 irq_pending; 3175 - irq_pending = readl(&ir->ir_set->irq_pending); 3176 - irq_pending |= IMAN_IP; 3177 - writel(irq_pending, &ir->ir_set->irq_pending); 3178 - } 3179 - 3180 - if (xhci->xhc_state & XHCI_STATE_DYING || 3181 - xhci->xhc_state & XHCI_STATE_HALTED) { 3182 - xhci_dbg(xhci, "xHCI dying, ignoring interrupt. " 3183 - "Shouldn't IRQs be disabled?\n"); 3184 - /* Clear the event handler busy flag (RW1C); 3185 - * the event ring should be empty. 3186 - */ 3187 - temp_64 = xhci_read_64(xhci, &ir->ir_set->erst_dequeue); 3188 - xhci_write_64(xhci, temp_64 | ERST_EHB, 3189 - &ir->ir_set->erst_dequeue); 3190 - ret = IRQ_HANDLED; 3191 - goto out; 3192 - } 3193 - 3194 - event_ring_deq = ir->event_ring->dequeue; 3195 - /* FIXME this should be a delayed service routine 3196 - * that clears the EHB. 3197 - */ 3198 - while (xhci_handle_event(xhci, ir) > 0) { 3199 - if (event_loop++ < TRBS_PER_SEGMENT / 2) 3200 - continue; 3201 - xhci_update_erst_dequeue(xhci, ir, event_ring_deq, false); 3202 - event_ring_deq = ir->event_ring->dequeue; 3203 - 3204 - /* ring is half-full, force isoc trbs to interrupt more often */ 3205 - if (xhci->isoc_bei_interval > AVOID_BEI_INTERVAL_MIN) 3206 - xhci->isoc_bei_interval = xhci->isoc_bei_interval / 2; 3207 - 3208 - event_loop = 0; 3209 - } 3210 - 3211 - xhci_update_erst_dequeue(xhci, ir, event_ring_deq, true); 3212 3118 ret = IRQ_HANDLED; 3213 3119 3120 + /* This is the handler of the primary interrupter */ 3121 + xhci_handle_events(xhci, xhci->interrupters[0]); 3214 3122 out: 3215 3123 spin_unlock(&xhci->lock); 3216 3124 ··· 4031 4019 } 4032 4020 4033 4021 /* Check if we should generate event interrupt for a TD in an isoc URB */ 4034 - static bool trb_block_event_intr(struct xhci_hcd *xhci, int num_tds, int i) 4022 + static bool trb_block_event_intr(struct xhci_hcd *xhci, int num_tds, int i, 4023 + struct xhci_interrupter *ir) 4035 4024 { 4036 4025 if (xhci->hci_version < 0x100) 4037 4026 return false; ··· 4043 4030 * If AVOID_BEI is set the host handles full event rings poorly, 4044 4031 * generate an event at least every 8th TD to clear the event ring 4045 4032 */ 4046 - if (i && xhci->quirks & XHCI_AVOID_BEI) 4047 - return !!(i % xhci->isoc_bei_interval); 4033 + if (i && ir->isoc_bei_interval && xhci->quirks & XHCI_AVOID_BEI) 4034 + return !!(i % ir->isoc_bei_interval); 4048 4035 4049 4036 return true; 4050 4037 } ··· 4053 4040 static int xhci_queue_isoc_tx(struct xhci_hcd *xhci, gfp_t mem_flags, 4054 4041 struct urb *urb, int slot_id, unsigned int ep_index) 4055 4042 { 4043 + struct xhci_interrupter *ir; 4056 4044 struct xhci_ring *ep_ring; 4057 4045 struct urb_priv *urb_priv; 4058 4046 struct xhci_td *td; ··· 4071 4057 4072 4058 xep = &xhci->devs[slot_id]->eps[ep_index]; 4073 4059 ep_ring = xhci->devs[slot_id]->eps[ep_index].ring; 4060 + ir = xhci->interrupters[0]; 4074 4061 4075 4062 num_tds = urb->number_of_packets; 4076 4063 if (num_tds < 1) { ··· 4159 4144 td->last_trb = ep_ring->enqueue; 4160 4145 td->last_trb_seg = ep_ring->enq_seg; 4161 4146 field |= TRB_IOC; 4162 - if (trb_block_event_intr(xhci, num_tds, i)) 4147 + if (trb_block_event_intr(xhci, num_tds, i, ir)) 4163 4148 field |= TRB_BEI; 4164 4149 } 4165 4150 /* Calculate TRB length */
+6 -6
drivers/usb/host/xhci-trace.h
··· 172 172 __field(void *, vdev) 173 173 __field(unsigned long long, out_ctx) 174 174 __field(unsigned long long, in_ctx) 175 - __field(u8, fake_port) 176 - __field(u8, real_port) 175 + __field(int, hcd_portnum) 176 + __field(int, hw_portnum) 177 177 __field(u16, current_mel) 178 178 179 179 ), ··· 181 181 __entry->vdev = vdev; 182 182 __entry->in_ctx = (unsigned long long) vdev->in_ctx->dma; 183 183 __entry->out_ctx = (unsigned long long) vdev->out_ctx->dma; 184 - __entry->fake_port = (u8) vdev->fake_port; 185 - __entry->real_port = (u8) vdev->real_port; 184 + __entry->hcd_portnum = (int) vdev->rhub_port->hcd_portnum; 185 + __entry->hw_portnum = (int) vdev->rhub_port->hw_portnum; 186 186 __entry->current_mel = (u16) vdev->current_mel; 187 187 ), 188 - TP_printk("vdev %p ctx %llx | %llx fake_port %d real_port %d current_mel %d", 188 + TP_printk("vdev %p ctx %llx | %llx hcd_portnum %d hw_portnum %d current_mel %d", 189 189 __entry->vdev, __entry->in_ctx, __entry->out_ctx, 190 - __entry->fake_port, __entry->real_port, __entry->current_mel 190 + __entry->hcd_portnum, __entry->hw_portnum, __entry->current_mel 191 191 ) 192 192 ); 193 193
+29 -27
drivers/usb/host/xhci.c
··· 346 346 return 0; 347 347 } 348 348 349 + /* interrupt moderation interval imod_interval in nanoseconds */ 350 + static int xhci_set_interrupter_moderation(struct xhci_interrupter *ir, 351 + u32 imod_interval) 352 + { 353 + u32 imod; 354 + 355 + if (!ir || !ir->ir_set || imod_interval > U16_MAX * 250) 356 + return -EINVAL; 357 + 358 + imod = readl(&ir->ir_set->irq_control); 359 + imod &= ~ER_IRQ_INTERVAL_MASK; 360 + imod |= (imod_interval / 250) & ER_IRQ_INTERVAL_MASK; 361 + writel(imod, &ir->ir_set->irq_control); 362 + 363 + return 0; 364 + } 365 + 349 366 static void compliance_mode_recovery(struct timer_list *t) 350 367 { 351 368 struct xhci_hcd *xhci; ··· 545 528 */ 546 529 int xhci_run(struct usb_hcd *hcd) 547 530 { 548 - u32 temp; 549 531 u64 temp_64; 550 532 int ret; 551 533 struct xhci_hcd *xhci = hcd_to_xhci(hcd); ··· 554 538 */ 555 539 556 540 hcd->uses_new_polling = 1; 541 + if (hcd->msi_enabled) 542 + ir->ip_autoclear = true; 543 + 557 544 if (!usb_hcd_is_primary_hcd(hcd)) 558 545 return xhci_run_finished(xhci); 559 546 ··· 567 548 xhci_dbg_trace(xhci, trace_xhci_dbg_init, 568 549 "ERST deq = 64'h%0lx", (long unsigned int) temp_64); 569 550 570 - xhci_dbg_trace(xhci, trace_xhci_dbg_init, 571 - "// Set the interrupt modulation register"); 572 - temp = readl(&ir->ir_set->irq_control); 573 - temp &= ~ER_IRQ_INTERVAL_MASK; 574 - temp |= (xhci->imod_interval / 250) & ER_IRQ_INTERVAL_MASK; 575 - writel(temp, &ir->ir_set->irq_control); 551 + xhci_set_interrupter_moderation(ir, xhci->imod_interval); 576 552 577 553 if (xhci->quirks & XHCI_NEC_HOST) { 578 554 struct xhci_command *command; ··· 794 780 seg = seg->next; 795 781 } while (seg != ring->deq_seg); 796 782 797 - /* Reset the software enqueue and dequeue pointers */ 798 - ring->deq_seg = ring->first_seg; 799 - ring->dequeue = ring->first_seg->trbs; 800 - ring->enq_seg = ring->deq_seg; 801 - ring->enqueue = ring->dequeue; 802 - 803 - ring->num_trbs_free = ring->num_segs * (TRBS_PER_SEGMENT - 1) - 1; 804 - /* 805 - * Ring is now zeroed, so the HW should look for change of ownership 806 - * when the cycle bit is set to 1. 807 - */ 808 - ring->cycle_state = 1; 809 - 783 + xhci_initialize_ring_info(ring, 1); 810 784 /* 811 785 * Reset the hardware dequeue pointer. 812 786 * Yes, this will need to be re-written after resume, but we're paranoid ··· 1219 1217 1220 1218 temp = kzalloc_node(buf_len, GFP_ATOMIC, 1221 1219 dev_to_node(hcd->self.sysdev)); 1220 + if (!temp) 1221 + return -ENOMEM; 1222 1222 1223 1223 if (usb_urb_dir_out(urb)) 1224 1224 sg_pcopy_to_buffer(urb->sg, urb->num_sgs, ··· 2263 2259 struct xhci_tt_bw_info *tt_info; 2264 2260 2265 2261 /* Find the bandwidth table for the root port this TT is attached to. */ 2266 - bw_table = &xhci->rh_bw[virt_dev->real_port - 1].bw_table; 2262 + bw_table = &xhci->rh_bw[virt_dev->rhub_port->hw_portnum].bw_table; 2267 2263 tt_info = virt_dev->tt_info; 2268 2264 /* If this TT already had active endpoints, the bandwidth for this TT 2269 2265 * has already been added. Removing all periodic endpoints (and thus ··· 2381 2377 if (virt_dev->tt_info) { 2382 2378 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, 2383 2379 "Recalculating BW for rootport %u", 2384 - virt_dev->real_port); 2380 + virt_dev->rhub_port->hw_portnum + 1); 2385 2381 if (xhci_check_tt_bw_table(xhci, virt_dev, old_active_eps)) { 2386 2382 xhci_warn(xhci, "Not enough bandwidth on HS bus for " 2387 2383 "newly activated TT.\n"); ··· 2394 2390 } else { 2395 2391 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, 2396 2392 "Recalculating BW for rootport %u", 2397 - virt_dev->real_port); 2393 + virt_dev->rhub_port->hw_portnum + 1); 2398 2394 } 2399 2395 2400 2396 /* Add in how much bandwidth will be used for interval zero, or the ··· 2491 2487 bw_used += overhead + packet_size; 2492 2488 2493 2489 if (!virt_dev->tt_info && virt_dev->udev->speed == USB_SPEED_HIGH) { 2494 - unsigned int port_index = virt_dev->real_port - 1; 2495 - 2496 2490 /* OK, we're manipulating a HS device attached to a 2497 2491 * root port bandwidth domain. Include the number of active TTs 2498 2492 * in the bandwidth used. 2499 2493 */ 2500 2494 bw_used += TT_HS_OVERHEAD * 2501 - xhci->rh_bw[port_index].num_active_tts; 2495 + xhci->rh_bw[virt_dev->rhub_port->hw_portnum].num_active_tts; 2502 2496 } 2503 2497 2504 2498 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, ··· 2683 2681 if (!virt_dev->tt_info) 2684 2682 return; 2685 2683 2686 - rh_bw_info = &xhci->rh_bw[virt_dev->real_port - 1]; 2684 + rh_bw_info = &xhci->rh_bw[virt_dev->rhub_port->hw_portnum]; 2687 2685 if (old_active_eps == 0 && 2688 2686 virt_dev->tt_info->active_eps != 0) { 2689 2687 rh_bw_info->num_active_tts += 1;
+8 -264
drivers/usb/host/xhci.h
··· 22 22 #include "xhci-ext-caps.h" 23 23 #include "pci-quirks.h" 24 24 25 + #include "xhci-port.h" 26 + #include "xhci-caps.h" 27 + 25 28 /* max buffer size for trace and debug messages */ 26 29 #define XHCI_MSG_MAX 500 27 30 ··· 64 61 __le32 hcc_params2; /* xhci 1.1 */ 65 62 /* Reserved up to (CAPLENGTH - 0x1C) */ 66 63 }; 67 - 68 - /* hc_capbase bitmasks */ 69 - /* bits 7:0 - how long is the Capabilities register */ 70 - #define HC_LENGTH(p) XHCI_HC_LENGTH(p) 71 - /* bits 31:16 */ 72 - #define HC_VERSION(p) (((p) >> 16) & 0xffff) 73 - 74 - /* HCSPARAMS1 - hcs_params1 - bitmasks */ 75 - /* bits 0:7, Max Device Slots */ 76 - #define HCS_MAX_SLOTS(p) (((p) >> 0) & 0xff) 77 - #define HCS_SLOTS_MASK 0xff 78 - /* bits 8:18, Max Interrupters */ 79 - #define HCS_MAX_INTRS(p) (((p) >> 8) & 0x7ff) 80 - /* bits 24:31, Max Ports - max value is 0x7F = 127 ports */ 81 - #define HCS_MAX_PORTS(p) (((p) >> 24) & 0x7f) 82 - 83 - /* HCSPARAMS2 - hcs_params2 - bitmasks */ 84 - /* bits 0:3, frames or uframes that SW needs to queue transactions 85 - * ahead of the HW to meet periodic deadlines */ 86 - #define HCS_IST(p) (((p) >> 0) & 0xf) 87 - /* bits 4:7, max number of Event Ring segments */ 88 - #define HCS_ERST_MAX(p) (((p) >> 4) & 0xf) 89 - /* bits 21:25 Hi 5 bits of Scratchpad buffers SW must allocate for the HW */ 90 - /* bit 26 Scratchpad restore - for save/restore HW state - not used yet */ 91 - /* bits 27:31 Lo 5 bits of Scratchpad buffers SW must allocate for the HW */ 92 - #define HCS_MAX_SCRATCHPAD(p) ((((p) >> 16) & 0x3e0) | (((p) >> 27) & 0x1f)) 93 - 94 - /* HCSPARAMS3 - hcs_params3 - bitmasks */ 95 - /* bits 0:7, Max U1 to U0 latency for the roothub ports */ 96 - #define HCS_U1_LATENCY(p) (((p) >> 0) & 0xff) 97 - /* bits 16:31, Max U2 to U0 latency for the roothub ports */ 98 - #define HCS_U2_LATENCY(p) (((p) >> 16) & 0xffff) 99 - 100 - /* HCCPARAMS - hcc_params - bitmasks */ 101 - /* true: HC can use 64-bit address pointers */ 102 - #define HCC_64BIT_ADDR(p) ((p) & (1 << 0)) 103 - /* true: HC can do bandwidth negotiation */ 104 - #define HCC_BANDWIDTH_NEG(p) ((p) & (1 << 1)) 105 - /* true: HC uses 64-byte Device Context structures 106 - * FIXME 64-byte context structures aren't supported yet. 107 - */ 108 - #define HCC_64BYTE_CONTEXT(p) ((p) & (1 << 2)) 109 - /* true: HC has port power switches */ 110 - #define HCC_PPC(p) ((p) & (1 << 3)) 111 - /* true: HC has port indicators */ 112 - #define HCS_INDICATOR(p) ((p) & (1 << 4)) 113 - /* true: HC has Light HC Reset Capability */ 114 - #define HCC_LIGHT_RESET(p) ((p) & (1 << 5)) 115 - /* true: HC supports latency tolerance messaging */ 116 - #define HCC_LTC(p) ((p) & (1 << 6)) 117 - /* true: no secondary Stream ID Support */ 118 - #define HCC_NSS(p) ((p) & (1 << 7)) 119 - /* true: HC supports Stopped - Short Packet */ 120 - #define HCC_SPC(p) ((p) & (1 << 9)) 121 - /* true: HC has Contiguous Frame ID Capability */ 122 - #define HCC_CFC(p) ((p) & (1 << 11)) 123 - /* Max size for Primary Stream Arrays - 2^(n+1), where n is bits 12:15 */ 124 - #define HCC_MAX_PSA(p) (1 << ((((p) >> 12) & 0xf) + 1)) 125 - /* Extended Capabilities pointer from PCI base - section 5.3.6 */ 126 - #define HCC_EXT_CAPS(p) XHCI_HCC_EXT_CAPS(p) 127 - 128 - #define CTX_SIZE(_hcc) (HCC_64BYTE_CONTEXT(_hcc) ? 64 : 32) 129 - 130 - /* db_off bitmask - bits 0:1 reserved */ 131 - #define DBOFF_MASK (~0x3) 132 - 133 - /* run_regs_off bitmask - bits 0:4 reserved */ 134 - #define RTSOFF_MASK (~0x1f) 135 - 136 - /* HCCPARAMS2 - hcc_params2 - bitmasks */ 137 - /* true: HC supports U3 entry Capability */ 138 - #define HCC2_U3C(p) ((p) & (1 << 0)) 139 - /* true: HC supports Configure endpoint command Max exit latency too large */ 140 - #define HCC2_CMC(p) ((p) & (1 << 1)) 141 - /* true: HC supports Force Save context Capability */ 142 - #define HCC2_FSC(p) ((p) & (1 << 2)) 143 - /* true: HC supports Compliance Transition Capability */ 144 - #define HCC2_CTC(p) ((p) & (1 << 3)) 145 - /* true: HC support Large ESIT payload Capability > 48k */ 146 - #define HCC2_LEC(p) ((p) & (1 << 4)) 147 - /* true: HC support Configuration Information Capability */ 148 - #define HCC2_CIC(p) ((p) & (1 << 5)) 149 - /* true: HC support Extended TBC Capability, Isoc burst count > 65535 */ 150 - #define HCC2_ETC(p) ((p) & (1 << 6)) 151 64 152 65 /* Number of registers per port */ 153 66 #define NUM_PORT_REGS 4 ··· 209 290 /* bit 9: Configuration Information Enable, xhci 1.1 */ 210 291 #define CONFIG_CIE (1 << 9) 211 292 /* bits 10:31 - reserved and should be preserved */ 212 - 213 - /* PORTSC - Port Status and Control Register - port_status_base bitmasks */ 214 - /* true: device connected */ 215 - #define PORT_CONNECT (1 << 0) 216 - /* true: port enabled */ 217 - #define PORT_PE (1 << 1) 218 - /* bit 2 reserved and zeroed */ 219 - /* true: port has an over-current condition */ 220 - #define PORT_OC (1 << 3) 221 - /* true: port reset signaling asserted */ 222 - #define PORT_RESET (1 << 4) 223 - /* Port Link State - bits 5:8 224 - * A read gives the current link PM state of the port, 225 - * a write with Link State Write Strobe set sets the link state. 226 - */ 227 - #define PORT_PLS_MASK (0xf << 5) 228 - #define XDEV_U0 (0x0 << 5) 229 - #define XDEV_U1 (0x1 << 5) 230 - #define XDEV_U2 (0x2 << 5) 231 - #define XDEV_U3 (0x3 << 5) 232 - #define XDEV_DISABLED (0x4 << 5) 233 - #define XDEV_RXDETECT (0x5 << 5) 234 - #define XDEV_INACTIVE (0x6 << 5) 235 - #define XDEV_POLLING (0x7 << 5) 236 - #define XDEV_RECOVERY (0x8 << 5) 237 - #define XDEV_HOT_RESET (0x9 << 5) 238 - #define XDEV_COMP_MODE (0xa << 5) 239 - #define XDEV_TEST_MODE (0xb << 5) 240 - #define XDEV_RESUME (0xf << 5) 241 - 242 - /* true: port has power (see HCC_PPC) */ 243 - #define PORT_POWER (1 << 9) 244 - /* bits 10:13 indicate device speed: 245 - * 0 - undefined speed - port hasn't be initialized by a reset yet 246 - * 1 - full speed 247 - * 2 - low speed 248 - * 3 - high speed 249 - * 4 - super speed 250 - * 5-15 reserved 251 - */ 252 - #define DEV_SPEED_MASK (0xf << 10) 253 - #define XDEV_FS (0x1 << 10) 254 - #define XDEV_LS (0x2 << 10) 255 - #define XDEV_HS (0x3 << 10) 256 - #define XDEV_SS (0x4 << 10) 257 - #define XDEV_SSP (0x5 << 10) 258 - #define DEV_UNDEFSPEED(p) (((p) & DEV_SPEED_MASK) == (0x0<<10)) 259 - #define DEV_FULLSPEED(p) (((p) & DEV_SPEED_MASK) == XDEV_FS) 260 - #define DEV_LOWSPEED(p) (((p) & DEV_SPEED_MASK) == XDEV_LS) 261 - #define DEV_HIGHSPEED(p) (((p) & DEV_SPEED_MASK) == XDEV_HS) 262 - #define DEV_SUPERSPEED(p) (((p) & DEV_SPEED_MASK) == XDEV_SS) 263 - #define DEV_SUPERSPEEDPLUS(p) (((p) & DEV_SPEED_MASK) == XDEV_SSP) 264 - #define DEV_SUPERSPEED_ANY(p) (((p) & DEV_SPEED_MASK) >= XDEV_SS) 265 - #define DEV_PORT_SPEED(p) (((p) >> 10) & 0x0f) 266 - 267 - /* Bits 20:23 in the Slot Context are the speed for the device */ 268 - #define SLOT_SPEED_FS (XDEV_FS << 10) 269 - #define SLOT_SPEED_LS (XDEV_LS << 10) 270 - #define SLOT_SPEED_HS (XDEV_HS << 10) 271 - #define SLOT_SPEED_SS (XDEV_SS << 10) 272 - #define SLOT_SPEED_SSP (XDEV_SSP << 10) 273 - /* Port Indicator Control */ 274 - #define PORT_LED_OFF (0 << 14) 275 - #define PORT_LED_AMBER (1 << 14) 276 - #define PORT_LED_GREEN (2 << 14) 277 - #define PORT_LED_MASK (3 << 14) 278 - /* Port Link State Write Strobe - set this when changing link state */ 279 - #define PORT_LINK_STROBE (1 << 16) 280 - /* true: connect status change */ 281 - #define PORT_CSC (1 << 17) 282 - /* true: port enable change */ 283 - #define PORT_PEC (1 << 18) 284 - /* true: warm reset for a USB 3.0 device is done. A "hot" reset puts the port 285 - * into an enabled state, and the device into the default state. A "warm" reset 286 - * also resets the link, forcing the device through the link training sequence. 287 - * SW can also look at the Port Reset register to see when warm reset is done. 288 - */ 289 - #define PORT_WRC (1 << 19) 290 - /* true: over-current change */ 291 - #define PORT_OCC (1 << 20) 292 - /* true: reset change - 1 to 0 transition of PORT_RESET */ 293 - #define PORT_RC (1 << 21) 294 - /* port link status change - set on some port link state transitions: 295 - * Transition Reason 296 - * ------------------------------------------------------------------------------ 297 - * - U3 to Resume Wakeup signaling from a device 298 - * - Resume to Recovery to U0 USB 3.0 device resume 299 - * - Resume to U0 USB 2.0 device resume 300 - * - U3 to Recovery to U0 Software resume of USB 3.0 device complete 301 - * - U3 to U0 Software resume of USB 2.0 device complete 302 - * - U2 to U0 L1 resume of USB 2.1 device complete 303 - * - U0 to U0 (???) L1 entry rejection by USB 2.1 device 304 - * - U0 to disabled L1 entry error with USB 2.1 device 305 - * - Any state to inactive Error on USB 3.0 port 306 - */ 307 - #define PORT_PLC (1 << 22) 308 - /* port configure error change - port failed to configure its link partner */ 309 - #define PORT_CEC (1 << 23) 310 - #define PORT_CHANGE_MASK (PORT_CSC | PORT_PEC | PORT_WRC | PORT_OCC | \ 311 - PORT_RC | PORT_PLC | PORT_CEC) 312 - 313 - 314 - /* Cold Attach Status - xHC can set this bit to report device attached during 315 - * Sx state. Warm port reset should be perfomed to clear this bit and move port 316 - * to connected state. 317 - */ 318 - #define PORT_CAS (1 << 24) 319 - /* wake on connect (enable) */ 320 - #define PORT_WKCONN_E (1 << 25) 321 - /* wake on disconnect (enable) */ 322 - #define PORT_WKDISC_E (1 << 26) 323 - /* wake on over-current (enable) */ 324 - #define PORT_WKOC_E (1 << 27) 325 - /* bits 28:29 reserved */ 326 - /* true: device is non-removable - for USB 3.0 roothub emulation */ 327 - #define PORT_DEV_REMOVE (1 << 30) 328 - /* Initiate a warm port reset - complete when PORT_WRC is '1' */ 329 - #define PORT_WR (1 << 31) 330 - 331 - /* We mark duplicate entries with -1 */ 332 - #define DUPLICATE_ENTRY ((u8)(-1)) 333 - 334 - /* Port Power Management Status and Control - port_power_base bitmasks */ 335 - /* Inactivity timer value for transitions into U1, in microseconds. 336 - * Timeout can be up to 127us. 0xFF means an infinite timeout. 337 - */ 338 - #define PORT_U1_TIMEOUT(p) ((p) & 0xff) 339 - #define PORT_U1_TIMEOUT_MASK 0xff 340 - /* Inactivity timer value for transitions into U2 */ 341 - #define PORT_U2_TIMEOUT(p) (((p) & 0xff) << 8) 342 - #define PORT_U2_TIMEOUT_MASK (0xff << 8) 343 - /* Bits 24:31 for port testing */ 344 - 345 - /* USB2 Protocol PORTSPMSC */ 346 - #define PORT_L1S_MASK 7 347 - #define PORT_L1S_SUCCESS 1 348 - #define PORT_RWE (1 << 3) 349 - #define PORT_HIRD(p) (((p) & 0xf) << 4) 350 - #define PORT_HIRD_MASK (0xf << 4) 351 - #define PORT_L1DS_MASK (0xff << 8) 352 - #define PORT_L1DS(p) (((p) & 0xff) << 8) 353 - #define PORT_HLE (1 << 16) 354 - #define PORT_TEST_MODE_SHIFT 28 355 - 356 - /* USB3 Protocol PORTLI Port Link Information */ 357 - #define PORT_RX_LANES(p) (((p) >> 16) & 0xf) 358 - #define PORT_TX_LANES(p) (((p) >> 20) & 0xf) 359 - 360 - /* USB2 Protocol PORTHLPMC */ 361 - #define PORT_HIRDM(p)((p) & 3) 362 - #define PORT_L1_TIMEOUT(p)(((p) & 0xff) << 2) 363 - #define PORT_BESLD(p)(((p) & 0xf) << 10) 364 - 365 - /* use 512 microseconds as USB2 LPM L1 default timeout. */ 366 - #define XHCI_L1_TIMEOUT 512 367 - 368 - /* Set default HIRD/BESL value to 4 (350/400us) for USB2 L1 LPM resume latency. 369 - * Safe to use with mixed HIRD and BESL systems (host and device) and is used 370 - * by other operating systems. 371 - * 372 - * XHCI 1.0 errata 8/14/12 Table 13 notes: 373 - * "Software should choose xHC BESL/BESLD field values that do not violate a 374 - * device's resume latency requirements, 375 - * e.g. not program values > '4' if BLC = '1' and a HIRD device is attached, 376 - * or not program values < '4' if BLC = '0' and a BESL device is attached. 377 - */ 378 - #define XHCI_DEFAULT_BESL 4 379 - 380 - /* 381 - * USB3 specification define a 360ms tPollingLFPSTiemout for USB3 ports 382 - * to complete link training. usually link trainig completes much faster 383 - * so check status 10 times with 36ms sleep in places we need to wait for 384 - * polling to complete. 385 - */ 386 - #define XHCI_PORT_POLLING_LFPS_TIME 36 387 293 388 294 /** 389 295 * struct xhci_intr_reg - Interrupt Register Set ··· 739 995 /* Used for addressing devices and configuration changes */ 740 996 struct xhci_container_ctx *in_ctx; 741 997 struct xhci_virt_ep eps[EP_CTX_PER_DEV]; 742 - u8 fake_port; 743 - u8 real_port; 998 + struct xhci_port *rhub_port; 744 999 struct xhci_interval_bw_table *bw_table; 745 1000 struct xhci_tt_bw_info *tt_info; 746 1001 /* ··· 1431 1688 struct xhci_erst erst; 1432 1689 struct xhci_intr_reg __iomem *ir_set; 1433 1690 unsigned int intr_num; 1691 + bool ip_autoclear; 1692 + u32 isoc_bei_interval; 1434 1693 /* For interrupter registers save and restore over suspend/resume */ 1435 1694 u32 s3_irq_pending; 1436 1695 u32 s3_irq_control; ··· 1462 1717 unsigned int lpm_incapable:1; 1463 1718 unsigned long resume_timestamp; 1464 1719 bool rexit_active; 1720 + /* Slot ID is the index of the device directly connected to the port */ 1721 + int slot_id; 1465 1722 struct completion rexit_done; 1466 1723 struct completion u3exit_done; 1467 1724 }; ··· 1507 1760 u8 isoc_threshold; 1508 1761 /* imod_interval in ns (I * 250ns) */ 1509 1762 u32 imod_interval; 1510 - u32 isoc_bei_interval; 1511 1763 int event_ring_max; 1512 1764 /* 4KB min, 128MB max */ 1513 1765 int page_size; ··· 1946 2200 #endif /* CONFIG_PM */ 1947 2201 1948 2202 u32 xhci_port_state_to_neutral(u32 state); 1949 - int xhci_find_slot_id_by_port(struct usb_hcd *hcd, struct xhci_hcd *xhci, 1950 - u16 port); 1951 2203 void xhci_ring_device(struct xhci_hcd *xhci, int slot_id); 1952 2204 1953 2205 /* xHCI contexts */
-1
drivers/usb/image/mdc800.c
··· 631 631 mdc800->camera_busy=0; 632 632 mdc800->camera_request_ready=0; 633 633 634 - retval=0; 635 634 mdc800->irq_urb->dev = mdc800->dev; 636 635 retval = usb_submit_urb (mdc800->irq_urb, GFP_KERNEL); 637 636 if (retval) {
+3 -1
drivers/usb/misc/onboard_usb_hub.c
··· 260 260 if (!hub) 261 261 return -ENOMEM; 262 262 263 - hub->pdata = device_get_match_data(&pdev->dev); 263 + hub->pdata = device_get_match_data(dev); 264 264 if (!hub->pdata) 265 265 return -EINVAL; 266 266 ··· 454 454 { USB_DEVICE(VENDOR_ID_REALTEK, 0x5411) }, /* RTS5411 USB 2.1 */ 455 455 { USB_DEVICE(VENDOR_ID_REALTEK, 0x0414) }, /* RTS5414 USB 3.2 */ 456 456 { USB_DEVICE(VENDOR_ID_REALTEK, 0x5414) }, /* RTS5414 USB 2.1 */ 457 + { USB_DEVICE(VENDOR_ID_TI, 0x8025) }, /* TI USB8020B 3.0 */ 458 + { USB_DEVICE(VENDOR_ID_TI, 0x8027) }, /* TI USB8020B 2.0 */ 457 459 { USB_DEVICE(VENDOR_ID_TI, 0x8140) }, /* TI USB8041 3.0 */ 458 460 { USB_DEVICE(VENDOR_ID_TI, 0x8142) }, /* TI USB8041 2.0 */ 459 461 { USB_DEVICE(VENDOR_ID_VIA, 0x0817) }, /* VIA VL817 3.1 */
+7
drivers/usb/misc/onboard_usb_hub.h
··· 26 26 .num_supplies = 1, 27 27 }; 28 28 29 + static const struct onboard_hub_pdata ti_tusb8020b_data = { 30 + .reset_us = 3000, 31 + .num_supplies = 1, 32 + }; 33 + 29 34 static const struct onboard_hub_pdata ti_tusb8041_data = { 30 35 .reset_us = 3000, 31 36 .num_supplies = 1, ··· 67 62 { .compatible = "usb424,2517", .data = &microchip_usb424_data, }, 68 63 { .compatible = "usb424,2744", .data = &microchip_usb5744_data, }, 69 64 { .compatible = "usb424,5744", .data = &microchip_usb5744_data, }, 65 + { .compatible = "usb451,8025", .data = &ti_tusb8020b_data, }, 66 + { .compatible = "usb451,8027", .data = &ti_tusb8020b_data, }, 70 67 { .compatible = "usb451,8140", .data = &ti_tusb8041_data, }, 71 68 { .compatible = "usb451,8142", .data = &ti_tusb8041_data, }, 72 69 { .compatible = "usb4b4,6504", .data = &cypress_hx3_data, },
+30
drivers/usb/mtu3/mtu3_host.c
··· 34 34 #define WC0_SSUSB0_CDEN BIT(6) 35 35 #define WC0_IS_SPM_EN BIT(1) 36 36 37 + /* mt8195 */ 38 + #define PERI_WK_CTRL0_8195 0x04 39 + #define WC0_IS_P_95 BIT(30) /* polarity */ 40 + #define WC0_IS_C_95(x) ((u32)(((x) & 0x7) << 27)) 41 + #define WC0_IS_EN_P3_95 BIT(26) 42 + #define WC0_IS_EN_P2_95 BIT(25) 43 + 44 + #define PERI_WK_CTRL1_8195 0x20 45 + #define WC1_IS_C_95(x) ((u32)(((x) & 0xf) << 28)) 46 + #define WC1_IS_P_95 BIT(12) 47 + #define WC1_IS_EN_P0_95 BIT(6) 48 + 37 49 /* mt2712 etc */ 38 50 #define PERI_SSUSB_SPM_CTRL 0x0 39 51 #define SSC_IP_SLEEP_EN BIT(4) ··· 56 44 SSUSB_UWK_V2, 57 45 SSUSB_UWK_V1_1 = 101, /* specific revision 1.01 */ 58 46 SSUSB_UWK_V1_2, /* specific revision 1.02 */ 47 + SSUSB_UWK_V1_3, /* mt8195 IP0 */ 48 + SSUSB_UWK_V1_5 = 105, /* mt8195 IP2 */ 49 + SSUSB_UWK_V1_6, /* mt8195 IP3 */ 59 50 }; 60 51 61 52 /* ··· 84 69 reg = ssusb->uwk_reg_base + PERI_WK_CTRL0; 85 70 msk = WC0_SSUSB0_CDEN | WC0_IS_SPM_EN; 86 71 val = enable ? msk : 0; 72 + break; 73 + case SSUSB_UWK_V1_3: 74 + reg = ssusb->uwk_reg_base + PERI_WK_CTRL1_8195; 75 + msk = WC1_IS_EN_P0_95 | WC1_IS_C_95(0xf) | WC1_IS_P_95; 76 + val = enable ? (WC1_IS_EN_P0_95 | WC1_IS_C_95(0x1)) : 0; 77 + break; 78 + case SSUSB_UWK_V1_5: 79 + reg = ssusb->uwk_reg_base + PERI_WK_CTRL0_8195; 80 + msk = WC0_IS_EN_P2_95 | WC0_IS_C_95(0x7) | WC0_IS_P_95; 81 + val = enable ? (WC0_IS_EN_P2_95 | WC0_IS_C_95(0x1)) : 0; 82 + break; 83 + case SSUSB_UWK_V1_6: 84 + reg = ssusb->uwk_reg_base + PERI_WK_CTRL0_8195; 85 + msk = WC0_IS_EN_P3_95 | WC0_IS_C_95(0x7) | WC0_IS_P_95; 86 + val = enable ? (WC0_IS_EN_P3_95 | WC0_IS_C_95(0x1)) : 0; 87 87 break; 88 88 case SSUSB_UWK_V2: 89 89 reg = ssusb->uwk_reg_base + PERI_SSUSB_SPM_CTRL;
-4
drivers/usb/musb/musb_gadget.c
··· 1744 1744 { 1745 1745 u8 epnum; 1746 1746 struct musb_hw_ep *hw_ep; 1747 - unsigned count = 0; 1748 1747 1749 1748 /* initialize endpoint list just once */ 1750 1749 INIT_LIST_HEAD(&(musb->g.ep_list)); ··· 1753 1754 epnum++, hw_ep++) { 1754 1755 if (hw_ep->is_shared_fifo /* || !epnum */) { 1755 1756 init_peripheral_ep(musb, &hw_ep->ep_in, epnum, 0); 1756 - count++; 1757 1757 } else { 1758 1758 if (hw_ep->max_packet_sz_tx) { 1759 1759 init_peripheral_ep(musb, &hw_ep->ep_in, 1760 1760 epnum, 1); 1761 - count++; 1762 1761 } 1763 1762 if (hw_ep->max_packet_sz_rx) { 1764 1763 init_peripheral_ep(musb, &hw_ep->ep_out, 1765 1764 epnum, 0); 1766 - count++; 1767 1765 } 1768 1766 } 1769 1767 }
+27 -28
drivers/usb/phy/phy-generic.c
··· 74 74 } 75 75 76 76 /* interface to regulator framework */ 77 - static void nop_set_vbus_draw(struct usb_phy_generic *nop, unsigned mA) 77 + static int nop_set_vbus(struct usb_otg *otg, bool enable) 78 78 { 79 - struct regulator *vbus_draw = nop->vbus_draw; 80 - int enabled; 81 - int ret; 79 + int ret = 0; 80 + struct usb_phy_generic *nop = dev_get_drvdata(otg->usb_phy->dev); 82 81 83 - if (!vbus_draw) 84 - return; 82 + if (!nop->vbus_draw) 83 + return 0; 85 84 86 - enabled = nop->vbus_draw_enabled; 87 - if (mA) { 88 - regulator_set_current_limit(vbus_draw, 0, 1000 * mA); 89 - if (!enabled) { 90 - ret = regulator_enable(vbus_draw); 91 - if (ret < 0) 92 - return; 93 - nop->vbus_draw_enabled = 1; 94 - } 95 - } else { 96 - if (enabled) { 97 - ret = regulator_disable(vbus_draw); 98 - if (ret < 0) 99 - return; 100 - nop->vbus_draw_enabled = 0; 101 - } 85 + if (enable && !nop->vbus_draw_enabled) { 86 + ret = regulator_enable(nop->vbus_draw); 87 + if (ret) 88 + nop->vbus_draw_enabled = false; 89 + else 90 + nop->vbus_draw_enabled = true; 91 + 92 + } else if (!enable && nop->vbus_draw_enabled) { 93 + ret = regulator_disable(nop->vbus_draw); 94 + nop->vbus_draw_enabled = false; 102 95 } 103 - nop->mA = mA; 96 + return ret; 104 97 } 105 98 106 99 ··· 113 120 otg->state = OTG_STATE_B_PERIPHERAL; 114 121 nop->phy.last_event = status; 115 122 116 - /* drawing a "unit load" is *always* OK, except for OTG */ 117 - nop_set_vbus_draw(nop, 100); 118 - 119 123 atomic_notifier_call_chain(&nop->phy.notifier, status, 120 124 otg->gadget); 121 125 } else { 122 - nop_set_vbus_draw(nop, 0); 123 - 124 126 status = USB_EVENT_NONE; 125 127 otg->state = OTG_STATE_B_IDLE; 126 128 nop->phy.last_event = status; ··· 262 274 return dev_err_probe(dev, PTR_ERR(nop->vbus_draw), 263 275 "could not get vbus regulator\n"); 264 276 277 + nop->vbus_draw = devm_regulator_get_exclusive(dev, "vbus"); 278 + if (PTR_ERR(nop->vbus_draw) == -ENODEV) 279 + nop->vbus_draw = NULL; 280 + if (IS_ERR(nop->vbus_draw)) 281 + return dev_err_probe(dev, PTR_ERR(nop->vbus_draw), 282 + "could not get vbus regulator\n"); 283 + 265 284 nop->dev = dev; 266 285 nop->phy.dev = nop->dev; 267 286 nop->phy.label = "nop-xceiv"; ··· 279 284 nop->phy.otg->usb_phy = &nop->phy; 280 285 nop->phy.otg->set_host = nop_set_host; 281 286 nop->phy.otg->set_peripheral = nop_set_peripheral; 287 + nop->phy.otg->set_vbus = nop_set_vbus; 282 288 283 289 return 0; 284 290 } ··· 337 341 struct usb_phy_generic *nop = platform_get_drvdata(pdev); 338 342 339 343 usb_remove_phy(&nop->phy); 344 + 345 + if (nop->vbus_draw && nop->vbus_draw_enabled) 346 + regulator_disable(nop->vbus_draw); 340 347 } 341 348 342 349 static const struct of_device_id nop_xceiv_dt_ids[] = {
+1 -1
drivers/usb/phy/phy.c
··· 699 699 } 700 700 EXPORT_SYMBOL_GPL(usb_add_phy); 701 701 702 - static struct device_type usb_phy_dev_type = { 702 + static const struct device_type usb_phy_dev_type = { 703 703 .name = "usb_phy", 704 704 .uevent = usb_phy_uevent, 705 705 };
+39 -4
drivers/usb/roles/class.c
··· 7 7 * Hans de Goede <hdegoede@redhat.com> 8 8 */ 9 9 10 + #include <linux/component.h> 10 11 #include <linux/usb/role.h> 11 12 #include <linux/property.h> 12 13 #include <linux/device.h> ··· 36 35 }; 37 36 38 37 #define to_role_switch(d) container_of(d, struct usb_role_switch, dev) 38 + 39 + static int connector_bind(struct device *dev, struct device *connector, void *data) 40 + { 41 + int ret; 42 + 43 + ret = sysfs_create_link(&dev->kobj, &connector->kobj, "connector"); 44 + if (ret) 45 + return ret; 46 + 47 + ret = sysfs_create_link(&connector->kobj, &dev->kobj, "usb-role-switch"); 48 + if (ret) 49 + sysfs_remove_link(&dev->kobj, "connector"); 50 + 51 + return ret; 52 + } 53 + 54 + static void connector_unbind(struct device *dev, struct device *connector, void *data) 55 + { 56 + sysfs_remove_link(&connector->kobj, "usb-role-switch"); 57 + sysfs_remove_link(&dev->kobj, "connector"); 58 + } 59 + 60 + static const struct component_ops connector_ops = { 61 + .bind = connector_bind, 62 + .unbind = connector_unbind, 63 + }; 39 64 40 65 /** 41 66 * usb_role_switch_set_role - Set USB role for a switch ··· 388 361 return ERR_PTR(ret); 389 362 } 390 363 364 + if (dev_fwnode(&sw->dev)) { 365 + ret = component_add(&sw->dev, &connector_ops); 366 + if (ret) 367 + dev_warn(&sw->dev, "failed to add component\n"); 368 + } 369 + 391 370 sw->registered = true; 392 371 393 372 /* TODO: Symlinks for the host port and the device controller. */ ··· 410 377 */ 411 378 void usb_role_switch_unregister(struct usb_role_switch *sw) 412 379 { 413 - if (!IS_ERR_OR_NULL(sw)) { 414 - sw->registered = false; 415 - device_unregister(&sw->dev); 416 - } 380 + if (IS_ERR_OR_NULL(sw)) 381 + return; 382 + sw->registered = false; 383 + if (dev_fwnode(&sw->dev)) 384 + component_del(&sw->dev, &connector_ops); 385 + device_unregister(&sw->dev); 417 386 } 418 387 EXPORT_SYMBOL_GPL(usb_role_switch_unregister); 419 388
+4
drivers/usb/serial/cp210x.c
··· 56 56 { USB_DEVICE(0x0471, 0x066A) }, /* AKTAKOM ACE-1001 cable */ 57 57 { USB_DEVICE(0x0489, 0xE000) }, /* Pirelli Broadband S.p.A, DP-L10 SIP/GSM Mobile */ 58 58 { USB_DEVICE(0x0489, 0xE003) }, /* Pirelli Broadband S.p.A, DP-L10 SIP/GSM Mobile */ 59 + { USB_DEVICE(0x04BF, 0x1301) }, /* TDK Corporation NC0110013M - Network Controller */ 60 + { USB_DEVICE(0x04BF, 0x1303) }, /* TDK Corporation MM0110113M - i3 Micro Module */ 59 61 { USB_DEVICE(0x0745, 0x1000) }, /* CipherLab USB CCD Barcode Scanner 1000 */ 60 62 { USB_DEVICE(0x0846, 0x1100) }, /* NetGear Managed Switch M4100 series, M5300 series, M7100 series */ 61 63 { USB_DEVICE(0x08e6, 0x5501) }, /* Gemalto Prox-PU/CU contactless smartcard reader */ ··· 146 144 { USB_DEVICE(0x10C4, 0x85EA) }, /* AC-Services IBUS-IF */ 147 145 { USB_DEVICE(0x10C4, 0x85EB) }, /* AC-Services CIS-IBUS */ 148 146 { USB_DEVICE(0x10C4, 0x85F8) }, /* Virtenio Preon32 */ 147 + { USB_DEVICE(0x10C4, 0x863C) }, /* MGP Instruments PDS100 */ 149 148 { USB_DEVICE(0x10C4, 0x8664) }, /* AC-Services CAN-IF */ 150 149 { USB_DEVICE(0x10C4, 0x8665) }, /* AC-Services OBD-IF */ 151 150 { USB_DEVICE(0x10C4, 0x87ED) }, /* IMST USB-Stick for Smart Meter */ ··· 180 177 { USB_DEVICE(0x10C4, 0xF004) }, /* Elan Digital Systems USBcount50 */ 181 178 { USB_DEVICE(0x10C5, 0xEA61) }, /* Silicon Labs MobiData GPRS USB Modem */ 182 179 { USB_DEVICE(0x10CE, 0xEA6A) }, /* Silicon Labs MobiData GPRS USB Modem 100EU */ 180 + { USB_DEVICE(0x11CA, 0x0212) }, /* Verifone USB to Printer (UART, CP2102) */ 183 181 { USB_DEVICE(0x12B8, 0xEC60) }, /* Link G4 ECU */ 184 182 { USB_DEVICE(0x12B8, 0xEC62) }, /* Link G4+ ECU */ 185 183 { USB_DEVICE(0x13AD, 0x9999) }, /* Baltech card reader */
+3 -1
drivers/usb/serial/ftdi_sio.c
··· 1077 1077 .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk }, 1078 1078 { USB_DEVICE(FTDI_VID, FTDI_FALCONIA_JTAG_UNBUF_PID), 1079 1079 .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk }, 1080 + /* GMC devices */ 1081 + { USB_DEVICE(GMC_VID, GMC_Z216C_PID) }, 1080 1082 { } /* Terminating entry */ 1081 1083 }; 1082 1084 ··· 2612 2610 struct device *ddev = &port->dev; 2613 2611 struct ftdi_private *priv = usb_get_serial_port_data(port); 2614 2612 struct ktermios *termios = &tty->termios; 2615 - unsigned int cflag = termios->c_cflag; 2613 + unsigned int cflag; 2616 2614 u16 value, index; 2617 2615 int ret; 2618 2616
+6
drivers/usb/serial/ftdi_sio_ids.h
··· 1606 1606 #define UBLOX_VID 0x1546 1607 1607 #define UBLOX_C099F9P_ZED_PID 0x0502 1608 1608 #define UBLOX_C099F9P_ODIN_PID 0x0503 1609 + 1610 + /* 1611 + * GMC devices 1612 + */ 1613 + #define GMC_VID 0x1cd7 1614 + #define GMC_Z216C_PID 0x0217 /* GMC Z216C Adapter IR-USB */
-1
drivers/usb/serial/keyspan.c
··· 921 921 922 922 port = urb->context; 923 923 p_priv = usb_get_serial_port_data(port); 924 - data = urb->transfer_buffer; 925 924 926 925 if (urb != p_priv->in_urbs[p_priv->in_flip]) 927 926 return;
+6
drivers/usb/serial/option.c
··· 613 613 /* Luat Air72*U series based on UNISOC UIS8910 uses UNISOC's vendor ID */ 614 614 #define LUAT_PRODUCT_AIR720U 0x4e00 615 615 616 + /* MeiG Smart Technology products */ 617 + #define MEIGSMART_VENDOR_ID 0x2dee 618 + /* MeiG Smart SLM320 based on UNISOC UIS8910 */ 619 + #define MEIGSMART_PRODUCT_SLM320 0x4d41 620 + 616 621 /* Device flags */ 617 622 618 623 /* Highest interface number which can be used with NCTRL() and RSVD() */ ··· 2287 2282 { USB_DEVICE_AND_INTERFACE_INFO(SIERRA_VENDOR_ID, SIERRA_PRODUCT_EM9191, 0xff, 0, 0) }, 2288 2283 { USB_DEVICE_AND_INTERFACE_INFO(UNISOC_VENDOR_ID, TOZED_PRODUCT_LT70C, 0xff, 0, 0) }, 2289 2284 { USB_DEVICE_AND_INTERFACE_INFO(UNISOC_VENDOR_ID, LUAT_PRODUCT_AIR720U, 0xff, 0, 0) }, 2285 + { USB_DEVICE_AND_INTERFACE_INFO(MEIGSMART_VENDOR_ID, MEIGSMART_PRODUCT_SLM320, 0xff, 0, 0) }, 2290 2286 { } /* Terminating entry */ 2291 2287 }; 2292 2288 MODULE_DEVICE_TABLE(usb, option_ids);
-1
drivers/usb/serial/oti6858.c
··· 409 409 cflag = tty->termios.c_cflag; 410 410 411 411 spin_lock_irqsave(&priv->lock, flags); 412 - divisor = priv->pending_setup.divisor; 413 412 frame_fmt = priv->pending_setup.frame_fmt; 414 413 control = priv->pending_setup.control; 415 414 spin_unlock_irqrestore(&priv->lock, flags);
-1
drivers/usb/storage/freecom.c
··· 534 534 } 535 535 line[offset] = 0; 536 536 usb_stor_dbg(us, "%s\n", line); 537 - offset = 0; 538 537 } 539 538 #endif 540 539
+2 -2
drivers/usb/storage/sddr55.c
··· 196 196 unsigned char *buffer; 197 197 198 198 unsigned int pba; 199 - unsigned long address; 199 + unsigned int address; 200 200 201 201 unsigned short pages; 202 202 unsigned int len, offset; ··· 316 316 317 317 unsigned int pba; 318 318 unsigned int new_pba; 319 - unsigned long address; 319 + unsigned int address; 320 320 321 321 unsigned short pages; 322 322 int i;
+160 -5
drivers/usb/typec/altmodes/displayport.c
··· 50 50 enum dp_state { 51 51 DP_STATE_IDLE, 52 52 DP_STATE_ENTER, 53 + DP_STATE_ENTER_PRIME, 53 54 DP_STATE_UPDATE, 54 55 DP_STATE_CONFIGURE, 56 + DP_STATE_CONFIGURE_PRIME, 55 57 DP_STATE_EXIT, 58 + DP_STATE_EXIT_PRIME, 56 59 }; 57 60 58 61 struct dp_altmode { 59 62 struct typec_displayport_data data; 63 + struct typec_displayport_data data_prime; 60 64 61 65 enum dp_state state; 62 66 bool hpd; ··· 71 67 struct typec_altmode *alt; 72 68 const struct typec_altmode *port; 73 69 struct fwnode_handle *connector_fwnode; 70 + struct typec_altmode *plug_prime; 74 71 }; 75 72 76 73 static int dp_altmode_notify(struct dp_altmode *dp) ··· 104 99 conf |= DP_CONF_UFP_U_AS_DFP_D; 105 100 pin_assign = DP_CAP_UFP_D_PIN_ASSIGN(dp->alt->vdo) & 106 101 DP_CAP_DFP_D_PIN_ASSIGN(dp->port->vdo); 102 + /* Account for active cable capabilities */ 103 + if (dp->plug_prime) 104 + pin_assign &= DP_CAP_DFP_D_PIN_ASSIGN(dp->plug_prime->vdo); 107 105 break; 108 106 case DP_STATUS_CON_UFP_D: 109 107 case DP_STATUS_CON_BOTH: /* NOTE: First acting as DP source */ 110 108 conf |= DP_CONF_UFP_U_AS_UFP_D; 111 109 pin_assign = DP_CAP_PIN_ASSIGN_UFP_D(dp->alt->vdo) & 112 110 DP_CAP_PIN_ASSIGN_DFP_D(dp->port->vdo); 111 + /* Account for active cable capabilities */ 112 + if (dp->plug_prime) 113 + pin_assign &= DP_CAP_UFP_D_PIN_ASSIGN(dp->plug_prime->vdo); 113 114 break; 114 115 default: 115 116 break; ··· 141 130 } 142 131 143 132 dp->data.conf = conf; 133 + if (dp->plug_prime) 134 + dp->data_prime.conf = conf; 144 135 145 136 return 0; 146 137 } ··· 156 143 157 144 if (configured && (dp->data.status & DP_STATUS_SWITCH_TO_USB)) { 158 145 dp->data.conf = 0; 159 - dp->state = DP_STATE_CONFIGURE; 146 + dp->data_prime.conf = 0; 147 + dp->state = dp->plug_prime ? DP_STATE_CONFIGURE_PRIME : 148 + DP_STATE_CONFIGURE; 160 149 } else if (dp->data.status & DP_STATUS_EXIT_DP_MODE) { 161 150 dp->state = DP_STATE_EXIT; 162 151 } else if (!(con & DP_CONF_CURRENTLY(dp->data.conf))) { 163 152 ret = dp_altmode_configure(dp, con); 164 153 if (!ret) { 165 - dp->state = DP_STATE_CONFIGURE; 154 + dp->state = dp->plug_prime ? DP_STATE_CONFIGURE_PRIME : 155 + DP_STATE_CONFIGURE; 166 156 if (dp->hpd != hpd) { 167 157 dp->hpd = hpd; 168 158 dp->pending_hpd = true; ··· 225 209 return ret; 226 210 } 227 211 212 + static int dp_altmode_configure_vdm_cable(struct dp_altmode *dp, u32 conf) 213 + { 214 + int svdm_version = typec_altmode_get_cable_svdm_version(dp->plug_prime); 215 + u32 header; 216 + 217 + if (svdm_version < 0) 218 + return svdm_version; 219 + 220 + header = DP_HEADER(dp, svdm_version, DP_CMD_CONFIGURE); 221 + 222 + return typec_cable_altmode_vdm(dp->plug_prime, TYPEC_PLUG_SOP_P, header, &conf, 2); 223 + } 224 + 228 225 static void dp_altmode_work(struct work_struct *work) 229 226 { 230 227 struct dp_altmode *dp = container_of(work, struct dp_altmode, work); ··· 253 224 ret = typec_altmode_enter(dp->alt, NULL); 254 225 if (ret && ret != -EBUSY) 255 226 dev_err(&dp->alt->dev, "failed to enter mode\n"); 227 + break; 228 + case DP_STATE_ENTER_PRIME: 229 + ret = typec_cable_altmode_enter(dp->alt, TYPEC_PLUG_SOP_P, NULL); 230 + /* 231 + * If we fail to enter Alt Mode on SOP', then we should drop the 232 + * plug from the driver and attempt to run the driver without 233 + * it. 234 + */ 235 + if (ret && ret != -EBUSY) { 236 + dev_err(&dp->alt->dev, "plug failed to enter mode\n"); 237 + dp->state = DP_STATE_ENTER; 238 + goto disable_prime; 239 + } 256 240 break; 257 241 case DP_STATE_UPDATE: 258 242 svdm_version = typec_altmode_get_svdm_version(dp->alt); ··· 285 243 dev_err(&dp->alt->dev, 286 244 "unable to send Configure command (%d)\n", ret); 287 245 break; 246 + case DP_STATE_CONFIGURE_PRIME: 247 + ret = dp_altmode_configure_vdm_cable(dp, dp->data_prime.conf); 248 + if (ret) { 249 + dev_err(&dp->plug_prime->dev, 250 + "unable to send Configure command (%d)\n", 251 + ret); 252 + dp->state = DP_STATE_CONFIGURE; 253 + goto disable_prime; 254 + } 255 + break; 288 256 case DP_STATE_EXIT: 289 257 if (typec_altmode_exit(dp->alt)) 290 258 dev_err(&dp->alt->dev, "Exit Mode Failed!\n"); 259 + break; 260 + case DP_STATE_EXIT_PRIME: 261 + if (typec_cable_altmode_exit(dp->plug_prime, TYPEC_PLUG_SOP_P)) 262 + dev_err(&dp->plug_prime->dev, "Exit Mode Failed!\n"); 291 263 break; 292 264 default: 293 265 break; ··· 309 253 310 254 dp->state = DP_STATE_IDLE; 311 255 256 + mutex_unlock(&dp->lock); 257 + return; 258 + 259 + disable_prime: 260 + typec_altmode_put_plug(dp->plug_prime); 261 + dp->plug_prime = NULL; 262 + schedule_work(&dp->work); 312 263 mutex_unlock(&dp->lock); 313 264 } 314 265 ··· 377 314 dp->hpd = false; 378 315 sysfs_notify(&dp->alt->dev.kobj, "displayport", "hpd"); 379 316 } 317 + if (dp->plug_prime) 318 + dp->state = DP_STATE_EXIT_PRIME; 380 319 break; 381 320 case DP_CMD_STATUS_UPDATE: 382 321 dp->data.status = *vdo; ··· 413 348 return ret; 414 349 } 415 350 351 + static int dp_cable_altmode_vdm(struct typec_altmode *alt, enum typec_plug_index sop, 352 + const u32 hdr, const u32 *vdo, int count) 353 + { 354 + struct dp_altmode *dp = typec_altmode_get_drvdata(alt); 355 + int cmd_type = PD_VDO_CMDT(hdr); 356 + int cmd = PD_VDO_CMD(hdr); 357 + int ret = 0; 358 + 359 + mutex_lock(&dp->lock); 360 + 361 + if (dp->state != DP_STATE_IDLE) { 362 + ret = -EBUSY; 363 + goto err_unlock; 364 + } 365 + 366 + switch (cmd_type) { 367 + case CMDT_RSP_ACK: 368 + switch (cmd) { 369 + case CMD_ENTER_MODE: 370 + typec_altmode_update_active(dp->plug_prime, true); 371 + dp->state = DP_STATE_ENTER; 372 + break; 373 + case CMD_EXIT_MODE: 374 + dp->data_prime.status = 0; 375 + dp->data_prime.conf = 0; 376 + typec_altmode_update_active(dp->plug_prime, false); 377 + break; 378 + case DP_CMD_CONFIGURE: 379 + dp->state = DP_STATE_CONFIGURE; 380 + break; 381 + default: 382 + break; 383 + } 384 + break; 385 + case CMDT_RSP_NAK: 386 + switch (cmd) { 387 + case DP_CMD_CONFIGURE: 388 + dp->data_prime.conf = 0; 389 + /* Attempt to configure on SOP, drop plug */ 390 + typec_altmode_put_plug(dp->plug_prime); 391 + dp->plug_prime = NULL; 392 + dp->state = DP_STATE_CONFIGURE; 393 + break; 394 + default: 395 + break; 396 + } 397 + break; 398 + default: 399 + break; 400 + } 401 + 402 + if (dp->state != DP_STATE_IDLE) 403 + schedule_work(&dp->work); 404 + 405 + err_unlock: 406 + mutex_unlock(&dp->lock); 407 + return ret; 408 + } 409 + 416 410 static int dp_altmode_activate(struct typec_altmode *alt, int activate) 417 411 { 418 - return activate ? typec_altmode_enter(alt, NULL) : 419 - typec_altmode_exit(alt); 412 + struct dp_altmode *dp = typec_altmode_get_drvdata(alt); 413 + int ret; 414 + 415 + if (activate) { 416 + if (dp->plug_prime) { 417 + ret = typec_cable_altmode_enter(alt, TYPEC_PLUG_SOP_P, NULL); 418 + if (ret < 0) { 419 + typec_altmode_put_plug(dp->plug_prime); 420 + dp->plug_prime = NULL; 421 + } else { 422 + return ret; 423 + } 424 + } 425 + return typec_altmode_enter(alt, NULL); 426 + } else { 427 + return typec_altmode_exit(alt); 428 + } 420 429 } 421 430 422 431 static const struct typec_altmode_ops dp_altmode_ops = { 423 432 .attention = dp_altmode_attention, 424 433 .vdm = dp_altmode_vdm, 425 434 .activate = dp_altmode_activate, 435 + }; 436 + 437 + static const struct typec_cable_ops dp_cable_ops = { 438 + .vdm = dp_cable_altmode_vdm, 426 439 }; 427 440 428 441 static const char * const configurations[] = { ··· 644 501 645 502 /* Only send Configure command if a configuration has been set */ 646 503 if (dp->alt->active && DP_CONF_CURRENTLY(dp->data.conf)) { 504 + /* todo: send manual configure over SOP'*/ 647 505 ret = dp_altmode_configure_vdm(dp, conf); 648 506 if (ret) 649 507 goto out_unlock; ··· 723 579 int dp_altmode_probe(struct typec_altmode *alt) 724 580 { 725 581 const struct typec_altmode *port = typec_altmode_get_partner(alt); 582 + struct typec_altmode *plug = typec_altmode_get_plug(alt, TYPEC_PLUG_SOP_P); 726 583 struct fwnode_handle *fwnode; 727 584 struct dp_altmode *dp; 728 585 ··· 748 603 alt->desc = "DisplayPort"; 749 604 alt->ops = &dp_altmode_ops; 750 605 606 + if (plug) { 607 + plug->desc = "Displayport"; 608 + plug->cable_ops = &dp_cable_ops; 609 + } 610 + 611 + dp->plug_prime = plug; 612 + 751 613 fwnode = dev_fwnode(alt->dev.parent->parent); /* typec_port fwnode */ 752 614 if (fwnode_property_present(fwnode, "displayport")) 753 615 dp->connector_fwnode = fwnode_find_reference(fwnode, "displayport", 0); ··· 764 612 dp->connector_fwnode = NULL; 765 613 766 614 typec_altmode_set_drvdata(alt, dp); 615 + if (plug) 616 + typec_altmode_set_drvdata(plug, dp); 767 617 768 - dp->state = DP_STATE_ENTER; 618 + dp->state = plug ? DP_STATE_ENTER_PRIME : DP_STATE_ENTER; 769 619 schedule_work(&dp->work); 770 620 771 621 return 0; ··· 779 625 struct dp_altmode *dp = typec_altmode_get_drvdata(alt); 780 626 781 627 cancel_work_sync(&dp->work); 628 + typec_altmode_put_plug(dp->plug_prime); 782 629 783 630 if (dp->connector_fwnode) { 784 631 drm_connector_oob_hotplug_event(dp->connector_fwnode,
+102
drivers/usb/typec/bus.c
··· 245 245 EXPORT_SYMBOL_GPL(typec_altmode_get_partner); 246 246 247 247 /* -------------------------------------------------------------------------- */ 248 + /* API for cable alternate modes */ 249 + 250 + /** 251 + * typec_cable_altmode_enter - Enter Mode 252 + * @adev: The alternate mode 253 + * @sop: Cable plug target for Enter Mode command 254 + * @vdo: VDO for the Enter Mode command 255 + * 256 + * Alternate mode drivers use this function to enter mode on the cable plug. 257 + * If the alternate mode does not require VDO, @vdo must be NULL. 258 + */ 259 + int typec_cable_altmode_enter(struct typec_altmode *adev, enum typec_plug_index sop, u32 *vdo) 260 + { 261 + struct altmode *partner = to_altmode(adev)->partner; 262 + struct typec_altmode *pdev; 263 + 264 + if (!adev || adev->active) 265 + return 0; 266 + 267 + if (!partner) 268 + return -ENODEV; 269 + 270 + pdev = &partner->adev; 271 + 272 + if (!pdev->active) 273 + return -EPERM; 274 + 275 + if (!pdev->cable_ops || !pdev->cable_ops->enter) 276 + return -EOPNOTSUPP; 277 + 278 + return pdev->cable_ops->enter(pdev, sop, vdo); 279 + } 280 + EXPORT_SYMBOL_GPL(typec_cable_altmode_enter); 281 + 282 + /** 283 + * typec_cable_altmode_exit - Exit Mode 284 + * @adev: The alternate mode 285 + * @sop: Cable plug target for Exit Mode command 286 + * 287 + * The alternate mode drivers use this function to exit mode on the cable plug. 288 + */ 289 + int typec_cable_altmode_exit(struct typec_altmode *adev, enum typec_plug_index sop) 290 + { 291 + struct altmode *partner = to_altmode(adev)->partner; 292 + struct typec_altmode *pdev; 293 + 294 + if (!adev || !adev->active) 295 + return 0; 296 + 297 + if (!partner) 298 + return -ENODEV; 299 + 300 + pdev = &partner->adev; 301 + 302 + if (!pdev->cable_ops || !pdev->cable_ops->exit) 303 + return -EOPNOTSUPP; 304 + 305 + return pdev->cable_ops->exit(pdev, sop); 306 + } 307 + EXPORT_SYMBOL_GPL(typec_cable_altmode_exit); 308 + 309 + /** 310 + * typec_cable_altmode_vdm - Send Vendor Defined Messages (VDM) between the cable plug and port. 311 + * @adev: Alternate mode handle 312 + * @sop: Cable plug target for VDM 313 + * @header: VDM Header 314 + * @vdo: Array of Vendor Defined Data Objects 315 + * @count: Number of Data Objects 316 + * 317 + * The alternate mode drivers use this function for SVID specific communication 318 + * with the cable plugs. The port drivers use it to deliver the Structured VDMs 319 + * received from the cable plugs to the alternate mode drivers. 320 + */ 321 + int typec_cable_altmode_vdm(struct typec_altmode *adev, enum typec_plug_index sop, 322 + const u32 header, const u32 *vdo, int count) 323 + { 324 + struct altmode *altmode; 325 + struct typec_altmode *pdev; 326 + 327 + if (!adev) 328 + return 0; 329 + 330 + altmode = to_altmode(adev); 331 + 332 + if (is_typec_plug(adev->dev.parent)) { 333 + if (!altmode->partner) 334 + return -ENODEV; 335 + pdev = &altmode->partner->adev; 336 + } else { 337 + if (!altmode->plug[sop]) 338 + return -ENODEV; 339 + pdev = &altmode->plug[sop]->adev; 340 + } 341 + 342 + if (!pdev->cable_ops || !pdev->cable_ops->vdm) 343 + return -EOPNOTSUPP; 344 + 345 + return pdev->cable_ops->vdm(pdev, sop, header, vdo, count); 346 + } 347 + EXPORT_SYMBOL_GPL(typec_cable_altmode_vdm); 348 + 349 + /* -------------------------------------------------------------------------- */ 248 350 /* API for the alternate mode drivers */ 249 351 250 352 /**
+60 -1
drivers/usb/typec/class.c
··· 21 21 22 22 static DEFINE_IDA(typec_index_ida); 23 23 24 - struct class typec_class = { 24 + const struct class typec_class = { 25 25 .name = "typec", 26 26 }; 27 27 ··· 2132 2132 EXPORT_SYMBOL_GPL(typec_get_negotiated_svdm_version); 2133 2133 2134 2134 /** 2135 + * typec_get_cable_svdm_version - Get cable negotiated SVDM Version 2136 + * @port: USB Type-C Port. 2137 + * 2138 + * Get the negotiated SVDM Version for the cable. The Version is set to the port 2139 + * default value based on the PD Revision during cable registration, and updated 2140 + * after a successful Discover Identity if the negotiated value is less than the 2141 + * default. 2142 + * 2143 + * Returns usb_pd_svdm_ver if the cable has been registered otherwise -ENODEV. 2144 + */ 2145 + int typec_get_cable_svdm_version(struct typec_port *port) 2146 + { 2147 + enum usb_pd_svdm_ver svdm_version; 2148 + struct device *cable_dev; 2149 + 2150 + cable_dev = device_find_child(&port->dev, NULL, cable_match); 2151 + if (!cable_dev) 2152 + return -ENODEV; 2153 + 2154 + svdm_version = to_typec_cable(cable_dev)->svdm_version; 2155 + put_device(cable_dev); 2156 + 2157 + return svdm_version; 2158 + } 2159 + EXPORT_SYMBOL_GPL(typec_get_cable_svdm_version); 2160 + 2161 + /** 2162 + * typec_cable_set_svdm_version - Set negotiated Structured VDM (SVDM) Version 2163 + * @cable: USB Type-C Active Cable that supports SVDM 2164 + * @svdm_version: Negotiated SVDM Version 2165 + * 2166 + * This routine is used to save the negotiated SVDM Version. 2167 + */ 2168 + void typec_cable_set_svdm_version(struct typec_cable *cable, enum usb_pd_svdm_ver svdm_version) 2169 + { 2170 + cable->svdm_version = svdm_version; 2171 + } 2172 + EXPORT_SYMBOL_GPL(typec_cable_set_svdm_version); 2173 + 2174 + /** 2135 2175 * typec_get_drvdata - Return private driver data pointer 2136 2176 * @port: USB Type-C port 2137 2177 */ ··· 2319 2279 } 2320 2280 } 2321 2281 EXPORT_SYMBOL_GPL(typec_port_register_altmodes); 2282 + 2283 + /** 2284 + * typec_port_register_cable_ops - Register typec_cable_ops to port altmodes 2285 + * @altmodes: USB Type-C Port's altmode vector 2286 + * @max_altmodes: The maximum number of alt modes supported by the port 2287 + * @ops: Cable alternate mode vector 2288 + */ 2289 + void typec_port_register_cable_ops(struct typec_altmode **altmodes, int max_altmodes, 2290 + const struct typec_cable_ops *ops) 2291 + { 2292 + int i; 2293 + 2294 + for (i = 0; i < max_altmodes; i++) { 2295 + if (!altmodes[i]) 2296 + return; 2297 + altmodes[i]->cable_ops = ops; 2298 + } 2299 + } 2300 + EXPORT_SYMBOL_GPL(typec_port_register_cable_ops); 2322 2301 2323 2302 /** 2324 2303 * typec_register_port - Register a USB Type-C Port
+4 -3
drivers/usb/typec/class.h
··· 23 23 struct usb_pd_identity *identity; 24 24 unsigned int active:1; 25 25 u16 pd_revision; /* 0300H = "3.0" */ 26 + enum usb_pd_svdm_ver svdm_version; 26 27 }; 27 28 28 29 struct typec_partner { ··· 93 92 #define is_typec_plug(dev) ((dev)->type == &typec_plug_dev_type) 94 93 #define is_typec_port(dev) ((dev)->type == &typec_port_dev_type) 95 94 96 - extern struct class typec_mux_class; 97 - extern struct class retimer_class; 98 - extern struct class typec_class; 95 + extern const struct class typec_mux_class; 96 + extern const struct class retimer_class; 97 + extern const struct class typec_class; 99 98 100 99 #if defined(CONFIG_ACPI) 101 100 int typec_link_ports(struct typec_port *connector);
+1 -1
drivers/usb/typec/mux.c
··· 469 469 } 470 470 EXPORT_SYMBOL_GPL(typec_mux_get_drvdata); 471 471 472 - struct class typec_mux_class = { 472 + const struct class typec_mux_class = { 473 473 .name = "typec_mux", 474 474 };
+10
drivers/usb/typec/mux/Kconfig
··· 36 36 control the USB role switch and also the multiplexer/demultiplexer 37 37 switches used with USB Type-C Alternate Modes. 38 38 39 + config TYPEC_MUX_IT5205 40 + tristate "ITE IT5205 Type-C USB Alt Mode Passive MUX driver" 41 + depends on I2C 42 + select REGMAP_I2C 43 + help 44 + Driver for the ITE IT5205 Type-C USB Alternate Mode Passive MUX 45 + which provides support for muxing DisplayPort and sideband signals 46 + on a common USB Type-C connector. 47 + If compiled as a module, the module will be named it5205. 48 + 39 49 config TYPEC_MUX_NB7VPQ904M 40 50 tristate "On Semiconductor NB7VPQ904M Type-C redriver driver" 41 51 depends on I2C
+1
drivers/usb/typec/mux/Makefile
··· 4 4 obj-$(CONFIG_TYPEC_MUX_GPIO_SBU) += gpio-sbu-mux.o 5 5 obj-$(CONFIG_TYPEC_MUX_PI3USB30532) += pi3usb30532.o 6 6 obj-$(CONFIG_TYPEC_MUX_INTEL_PMC) += intel_pmc_mux.o 7 + obj-$(CONFIG_TYPEC_MUX_IT5205) += it5205.o 7 8 obj-$(CONFIG_TYPEC_MUX_NB7VPQ904M) += nb7vpq904m.o 8 9 obj-$(CONFIG_TYPEC_MUX_PTN36502) += ptn36502.o 9 10 obj-$(CONFIG_TYPEC_MUX_WCD939X_USBSS) += wcd939x-usbss.o
+294
drivers/usb/typec/mux/it5205.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * ITE IT5205 Type-C USB alternate mode passive mux 4 + * 5 + * Copyright (c) 2020 MediaTek Inc. 6 + * Copyright (c) 2024 Collabora Ltd. 7 + * AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com> 8 + * 9 + */ 10 + 11 + #include <linux/delay.h> 12 + #include <linux/i2c.h> 13 + #include <linux/kernel.h> 14 + #include <linux/module.h> 15 + #include <linux/of_platform.h> 16 + #include <linux/platform_device.h> 17 + #include <linux/regmap.h> 18 + #include <linux/regulator/consumer.h> 19 + #include <linux/usb/tcpm.h> 20 + #include <linux/usb/typec.h> 21 + #include <linux/usb/typec_dp.h> 22 + #include <linux/usb/typec_mux.h> 23 + 24 + #define IT5205_REG_CHIP_ID(x) (0x4 + (x)) 25 + #define IT5205FN_CHIP_ID 0x35323035 /* "5205" */ 26 + 27 + /* MUX power down register */ 28 + #define IT5205_REG_MUXPDR 0x10 29 + #define IT5205_MUX_POWER_DOWN BIT(0) 30 + 31 + /* MUX control register */ 32 + #define IT5205_REG_MUXCR 0x11 33 + #define IT5205_POLARITY_INVERTED BIT(4) 34 + #define IT5205_DP_USB_CTRL_MASK GENMASK(3, 0) 35 + #define IT5205_DP 0x0f 36 + #define IT5205_DP_USB 0x03 37 + #define IT5205_USB 0x07 38 + 39 + /* Vref Select Register */ 40 + #define IT5205_REG_VSR 0x10 41 + #define IT5205_VREF_SELECT_MASK GENMASK(5, 4) 42 + #define IT5205_VREF_SELECT_3_3V 0x00 43 + #define IT5205_VREF_SELECT_OFF 0x20 44 + 45 + /* CSBU Over Voltage Protection Register */ 46 + #define IT5205_REG_CSBUOVPSR 0x1e 47 + #define IT5205_OVP_SELECT_MASK GENMASK(5, 4) 48 + #define IT5205_OVP_3_90V 0x00 49 + #define IT5205_OVP_3_68V 0x10 50 + #define IT5205_OVP_3_62V 0x20 51 + #define IT5205_OVP_3_57V 0x30 52 + 53 + /* CSBU Switch Register */ 54 + #define IT5205_REG_CSBUSR 0x22 55 + #define IT5205_CSBUSR_SWITCH BIT(0) 56 + 57 + /* Interrupt Switch Register */ 58 + #define IT5205_REG_ISR 0x25 59 + #define IT5205_ISR_CSBU_MASK BIT(4) 60 + #define IT5205_ISR_CSBU_OVP BIT(0) 61 + 62 + struct it5205 { 63 + struct i2c_client *client; 64 + struct regmap *regmap; 65 + struct typec_switch_dev *sw; 66 + struct typec_mux_dev *mux; 67 + }; 68 + 69 + static int it5205_switch_set(struct typec_switch_dev *sw, enum typec_orientation orientation) 70 + { 71 + struct it5205 *it = typec_switch_get_drvdata(sw); 72 + 73 + switch (orientation) { 74 + case TYPEC_ORIENTATION_NORMAL: 75 + regmap_update_bits(it->regmap, IT5205_REG_MUXCR, 76 + IT5205_POLARITY_INVERTED, 0); 77 + break; 78 + case TYPEC_ORIENTATION_REVERSE: 79 + regmap_update_bits(it->regmap, IT5205_REG_MUXCR, 80 + IT5205_POLARITY_INVERTED, IT5205_POLARITY_INVERTED); 81 + break; 82 + case TYPEC_ORIENTATION_NONE: 83 + fallthrough; 84 + default: 85 + regmap_write(it->regmap, IT5205_REG_MUXCR, 0); 86 + break; 87 + } 88 + 89 + return 0; 90 + } 91 + 92 + static int it5205_mux_set(struct typec_mux_dev *mux, struct typec_mux_state *state) 93 + { 94 + struct it5205 *it = typec_mux_get_drvdata(mux); 95 + u8 val; 96 + 97 + if (state->mode >= TYPEC_STATE_MODAL && 98 + state->alt->svid != USB_TYPEC_DP_SID) 99 + return -EINVAL; 100 + 101 + switch (state->mode) { 102 + case TYPEC_STATE_USB: 103 + val = IT5205_USB; 104 + break; 105 + case TYPEC_DP_STATE_C: 106 + fallthrough; 107 + case TYPEC_DP_STATE_E: 108 + val = IT5205_DP; 109 + break; 110 + case TYPEC_DP_STATE_D: 111 + val = IT5205_DP_USB; 112 + break; 113 + case TYPEC_STATE_SAFE: 114 + fallthrough; 115 + default: 116 + val = 0; 117 + break; 118 + } 119 + 120 + return regmap_update_bits(it->regmap, IT5205_REG_MUXCR, 121 + IT5205_DP_USB_CTRL_MASK, val); 122 + } 123 + 124 + static irqreturn_t it5205_irq_handler(int irq, void *data) 125 + { 126 + struct it5205 *it = data; 127 + int ret; 128 + u32 val; 129 + 130 + ret = regmap_read(it->regmap, IT5205_REG_ISR, &val); 131 + if (ret) 132 + return IRQ_NONE; 133 + 134 + if (val & IT5205_ISR_CSBU_OVP) { 135 + dev_warn(&it->client->dev, "Overvoltage detected!\n"); 136 + 137 + /* Reset CSBU */ 138 + regmap_update_bits(it->regmap, IT5205_REG_CSBUSR, 139 + IT5205_CSBUSR_SWITCH, 0); 140 + regmap_update_bits(it->regmap, IT5205_REG_CSBUSR, 141 + IT5205_CSBUSR_SWITCH, IT5205_CSBUSR_SWITCH); 142 + } 143 + 144 + return IRQ_HANDLED; 145 + } 146 + 147 + static void it5205_enable_ovp(struct it5205 *it) 148 + { 149 + /* Select Vref 3.3v */ 150 + regmap_update_bits(it->regmap, IT5205_REG_VSR, 151 + IT5205_VREF_SELECT_MASK, IT5205_VREF_SELECT_3_3V); 152 + 153 + /* Trigger OVP at 3.68V */ 154 + regmap_update_bits(it->regmap, IT5205_REG_CSBUOVPSR, 155 + IT5205_OVP_SELECT_MASK, IT5205_OVP_3_68V); 156 + 157 + /* Unmask OVP interrupt */ 158 + regmap_update_bits(it->regmap, IT5205_REG_ISR, 159 + IT5205_ISR_CSBU_MASK, 0); 160 + 161 + /* Enable CSBU Interrupt */ 162 + regmap_update_bits(it->regmap, IT5205_REG_CSBUSR, 163 + IT5205_CSBUSR_SWITCH, IT5205_CSBUSR_SWITCH); 164 + } 165 + 166 + static const struct regmap_config it5205_regmap = { 167 + .max_register = 0x2f, 168 + .reg_bits = 8, 169 + .val_bits = 8, 170 + }; 171 + 172 + static int it5205_probe(struct i2c_client *client) 173 + { 174 + struct typec_switch_desc sw_desc = { }; 175 + struct typec_mux_desc mux_desc = { }; 176 + struct device *dev = &client->dev; 177 + struct it5205 *it; 178 + u32 val, chipid = 0; 179 + int i, ret; 180 + 181 + it = devm_kzalloc(dev, sizeof(*it), GFP_KERNEL); 182 + if (!it) 183 + return -ENOMEM; 184 + 185 + ret = devm_regulator_get_enable(dev, "vcc"); 186 + if (ret) 187 + return dev_err_probe(dev, ret, "Failed to get regulator\n"); 188 + 189 + it->client = client; 190 + 191 + it->regmap = devm_regmap_init_i2c(client, &it5205_regmap); 192 + if (IS_ERR(it->regmap)) 193 + return dev_err_probe(dev, PTR_ERR(it->regmap), 194 + "Failed to init regmap\n"); 195 + 196 + /* IT5205 needs a long time to power up after enabling regulator */ 197 + msleep(50); 198 + 199 + /* Unset poweroff bit */ 200 + ret = regmap_write(it->regmap, IT5205_REG_MUXPDR, 0); 201 + if (ret) 202 + return dev_err_probe(dev, ret, "Failed to set power on\n"); 203 + 204 + /* Read the 32 bits ChipID */ 205 + for (i = 3; i >= 0; i--) { 206 + ret = regmap_read(it->regmap, IT5205_REG_CHIP_ID(i), &val); 207 + if (ret) 208 + return ret; 209 + 210 + chipid |= val << (i * 8); 211 + } 212 + 213 + if (chipid != IT5205FN_CHIP_ID) 214 + return dev_err_probe(dev, -EINVAL, 215 + "Unknown ChipID 0x%x\n", chipid); 216 + 217 + /* Initialize as USB mode with default (non-inverted) polarity */ 218 + ret = regmap_write(it->regmap, IT5205_REG_MUXCR, IT5205_USB); 219 + if (ret) 220 + return dev_err_probe(dev, ret, "Cannot set mode to USB\n"); 221 + 222 + sw_desc.drvdata = it; 223 + sw_desc.fwnode = dev_fwnode(dev); 224 + sw_desc.set = it5205_switch_set; 225 + 226 + it->sw = typec_switch_register(dev, &sw_desc); 227 + if (IS_ERR(it->sw)) 228 + return dev_err_probe(dev, PTR_ERR(it->sw), 229 + "failed to register typec switch\n"); 230 + 231 + mux_desc.drvdata = it; 232 + mux_desc.fwnode = dev_fwnode(dev); 233 + mux_desc.set = it5205_mux_set; 234 + 235 + it->mux = typec_mux_register(dev, &mux_desc); 236 + if (IS_ERR(it->mux)) { 237 + typec_switch_unregister(it->sw); 238 + return dev_err_probe(dev, PTR_ERR(it->mux), 239 + "failed to register typec mux\n"); 240 + } 241 + 242 + i2c_set_clientdata(client, it); 243 + 244 + if (of_property_read_bool(dev->of_node, "ite,ovp-enable") && client->irq) { 245 + it5205_enable_ovp(it); 246 + 247 + ret = devm_request_threaded_irq(dev, client->irq, NULL, 248 + it5205_irq_handler, 249 + IRQF_ONESHOT, dev_name(dev), it); 250 + if (ret) { 251 + typec_mux_unregister(it->mux); 252 + typec_switch_unregister(it->sw); 253 + return dev_err_probe(dev, ret, "Failed to request irq\n"); 254 + } 255 + } 256 + 257 + return 0; 258 + } 259 + 260 + static void it5205_remove(struct i2c_client *client) 261 + { 262 + struct it5205 *it = i2c_get_clientdata(client); 263 + 264 + typec_mux_unregister(it->mux); 265 + typec_switch_unregister(it->sw); 266 + } 267 + 268 + static const struct i2c_device_id it5205_table[] = { 269 + { "it5205" }, 270 + { /* sentinel */ } 271 + }; 272 + MODULE_DEVICE_TABLE(i2c, it5205_table); 273 + 274 + static const struct of_device_id it5205_of_table[] = { 275 + { .compatible = "ite,it5205" }, 276 + { /* sentinel */ } 277 + }; 278 + MODULE_DEVICE_TABLE(of, it5205_of_table); 279 + 280 + static struct i2c_driver it5205_driver = { 281 + .driver = { 282 + .name = "it5205", 283 + .of_match_table = it5205_of_table, 284 + }, 285 + .probe = it5205_probe, 286 + .remove = it5205_remove, 287 + .id_table = it5205_table, 288 + }; 289 + module_i2c_driver(it5205_driver); 290 + 291 + MODULE_AUTHOR("Tianping Fang <tianping.fang@mediatek.com>"); 292 + MODULE_AUTHOR("AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>"); 293 + MODULE_DESCRIPTION("ITE IT5205 alternate mode passive MUX driver"); 294 + MODULE_LICENSE("GPL");
+15 -15
drivers/usb/typec/pd.c
··· 157 157 }; 158 158 __ATTRIBUTE_GROUPS(source_fixed_supply); 159 159 160 - static struct device_type source_fixed_supply_type = { 160 + static const struct device_type source_fixed_supply_type = { 161 161 .name = "pdo", 162 162 .release = pdo_release, 163 163 .groups = source_fixed_supply_groups, ··· 182 182 }; 183 183 __ATTRIBUTE_GROUPS(sink_fixed_supply); 184 184 185 - static struct device_type sink_fixed_supply_type = { 185 + static const struct device_type sink_fixed_supply_type = { 186 186 .name = "pdo", 187 187 .release = pdo_release, 188 188 .groups = sink_fixed_supply_groups, ··· 213 213 }; 214 214 ATTRIBUTE_GROUPS(source_variable_supply); 215 215 216 - static struct device_type source_variable_supply_type = { 216 + static const struct device_type source_variable_supply_type = { 217 217 .name = "pdo", 218 218 .release = pdo_release, 219 219 .groups = source_variable_supply_groups, ··· 227 227 }; 228 228 ATTRIBUTE_GROUPS(sink_variable_supply); 229 229 230 - static struct device_type sink_variable_supply_type = { 230 + static const struct device_type sink_variable_supply_type = { 231 231 .name = "pdo", 232 232 .release = pdo_release, 233 233 .groups = sink_variable_supply_groups, ··· 258 258 }; 259 259 ATTRIBUTE_GROUPS(source_battery); 260 260 261 - static struct device_type source_battery_type = { 261 + static const struct device_type source_battery_type = { 262 262 .name = "pdo", 263 263 .release = pdo_release, 264 264 .groups = source_battery_groups, ··· 272 272 }; 273 273 ATTRIBUTE_GROUPS(sink_battery); 274 274 275 - static struct device_type sink_battery_type = { 275 + static const struct device_type sink_battery_type = { 276 276 .name = "pdo", 277 277 .release = pdo_release, 278 278 .groups = sink_battery_groups, ··· 339 339 }; 340 340 ATTRIBUTE_GROUPS(source_pps); 341 341 342 - static struct device_type source_pps_type = { 342 + static const struct device_type source_pps_type = { 343 343 .name = "pdo", 344 344 .release = pdo_release, 345 345 .groups = source_pps_groups, ··· 353 353 }; 354 354 ATTRIBUTE_GROUPS(sink_pps); 355 355 356 - static struct device_type sink_pps_type = { 356 + static const struct device_type sink_pps_type = { 357 357 .name = "pdo", 358 358 .release = pdo_release, 359 359 .groups = sink_pps_groups, ··· 371 371 [APDO_TYPE_PPS] = "programmable_supply", 372 372 }; 373 373 374 - static struct device_type *source_type[] = { 374 + static const struct device_type *source_type[] = { 375 375 [PDO_TYPE_FIXED] = &source_fixed_supply_type, 376 376 [PDO_TYPE_BATT] = &source_battery_type, 377 377 [PDO_TYPE_VAR] = &source_variable_supply_type, 378 378 }; 379 379 380 - static struct device_type *source_apdo_type[] = { 380 + static const struct device_type *source_apdo_type[] = { 381 381 [APDO_TYPE_PPS] = &source_pps_type, 382 382 }; 383 383 384 - static struct device_type *sink_type[] = { 384 + static const struct device_type *sink_type[] = { 385 385 [PDO_TYPE_FIXED] = &sink_fixed_supply_type, 386 386 [PDO_TYPE_BATT] = &sink_battery_type, 387 387 [PDO_TYPE_VAR] = &sink_variable_supply_type, 388 388 }; 389 389 390 - static struct device_type *sink_apdo_type[] = { 390 + static const struct device_type *sink_apdo_type[] = { 391 391 [APDO_TYPE_PPS] = &sink_pps_type, 392 392 }; 393 393 394 394 /* REVISIT: Export when EPR_*_Capabilities need to be supported. */ 395 395 static int add_pdo(struct usb_power_delivery_capabilities *cap, u32 pdo, int position) 396 396 { 397 - struct device_type *type; 397 + const struct device_type *type; 398 398 const char *name; 399 399 struct pdo *p; 400 400 int ret; ··· 460 460 kfree(to_usb_power_delivery_capabilities(dev)); 461 461 } 462 462 463 - static struct device_type pd_capabilities_type = { 463 + static const struct device_type pd_capabilities_type = { 464 464 .name = "capabilities", 465 465 .release = pd_capabilities_release, 466 466 }; ··· 575 575 kfree(pd); 576 576 } 577 577 578 - static struct device_type pd_type = { 578 + static const struct device_type pd_type = { 579 579 .name = "usb_power_delivery", 580 580 .release = pd_release, 581 581 .groups = pd_groups,
+1 -1
drivers/usb/typec/retimer.c
··· 155 155 } 156 156 EXPORT_SYMBOL_GPL(typec_retimer_get_drvdata); 157 157 158 - struct class retimer_class = { 158 + const struct class retimer_class = { 159 159 .name = "retimer", 160 160 };
+1 -1
drivers/usb/typec/tcpm/fusb302.c
··· 1467 1467 if ((!len) && (pd_header_type_le(msg->header) == PD_CTRL_GOOD_CRC)) 1468 1468 tcpm_pd_transmit_complete(chip->tcpm_port, TCPC_TX_SUCCESS); 1469 1469 else 1470 - tcpm_pd_receive(chip->tcpm_port, msg); 1470 + tcpm_pd_receive(chip->tcpm_port, msg, TCPC_TX_SOP); 1471 1471 1472 1472 return ret; 1473 1473 }
+2 -1
drivers/usb/typec/tcpm/qcom/Makefile
··· 3 3 obj-$(CONFIG_TYPEC_QCOM_PMIC) += qcom_pmic_tcpm.o 4 4 qcom_pmic_tcpm-y += qcom_pmic_typec.o \ 5 5 qcom_pmic_typec_port.o \ 6 - qcom_pmic_typec_pdphy.o 6 + qcom_pmic_typec_pdphy.o \ 7 + qcom_pmic_typec_pdphy_stub.o \
+32 -224
drivers/usb/typec/tcpm/qcom/qcom_pmic_typec.c
··· 20 20 21 21 #include <drm/bridge/aux-bridge.h> 22 22 23 + #include "qcom_pmic_typec.h" 23 24 #include "qcom_pmic_typec_pdphy.h" 24 25 #include "qcom_pmic_typec_port.h" 25 26 26 27 struct pmic_typec_resources { 27 - struct pmic_typec_pdphy_resources *pdphy_res; 28 - struct pmic_typec_port_resources *port_res; 28 + const struct pmic_typec_pdphy_resources *pdphy_res; 29 + const struct pmic_typec_port_resources *port_res; 29 30 }; 30 - 31 - struct pmic_typec { 32 - struct device *dev; 33 - struct tcpm_port *tcpm_port; 34 - struct tcpc_dev tcpc; 35 - struct pmic_typec_pdphy *pmic_typec_pdphy; 36 - struct pmic_typec_port *pmic_typec_port; 37 - bool vbus_enabled; 38 - struct mutex lock; /* VBUS state serialization */ 39 - }; 40 - 41 - #define tcpc_to_tcpm(_tcpc_) container_of(_tcpc_, struct pmic_typec, tcpc) 42 - 43 - static int qcom_pmic_typec_get_vbus(struct tcpc_dev *tcpc) 44 - { 45 - struct pmic_typec *tcpm = tcpc_to_tcpm(tcpc); 46 - int ret; 47 - 48 - mutex_lock(&tcpm->lock); 49 - ret = tcpm->vbus_enabled || qcom_pmic_typec_port_get_vbus(tcpm->pmic_typec_port); 50 - mutex_unlock(&tcpm->lock); 51 - 52 - return ret; 53 - } 54 - 55 - static int qcom_pmic_typec_set_vbus(struct tcpc_dev *tcpc, bool on, bool sink) 56 - { 57 - struct pmic_typec *tcpm = tcpc_to_tcpm(tcpc); 58 - int ret = 0; 59 - 60 - mutex_lock(&tcpm->lock); 61 - if (tcpm->vbus_enabled == on) 62 - goto done; 63 - 64 - ret = qcom_pmic_typec_port_set_vbus(tcpm->pmic_typec_port, on); 65 - if (ret) 66 - goto done; 67 - 68 - tcpm->vbus_enabled = on; 69 - tcpm_vbus_change(tcpm->tcpm_port); 70 - 71 - done: 72 - dev_dbg(tcpm->dev, "set_vbus set: %d result %d\n", on, ret); 73 - mutex_unlock(&tcpm->lock); 74 - 75 - return ret; 76 - } 77 - 78 - static int qcom_pmic_typec_set_vconn(struct tcpc_dev *tcpc, bool on) 79 - { 80 - struct pmic_typec *tcpm = tcpc_to_tcpm(tcpc); 81 - 82 - return qcom_pmic_typec_port_set_vconn(tcpm->pmic_typec_port, on); 83 - } 84 - 85 - static int qcom_pmic_typec_get_cc(struct tcpc_dev *tcpc, 86 - enum typec_cc_status *cc1, 87 - enum typec_cc_status *cc2) 88 - { 89 - struct pmic_typec *tcpm = tcpc_to_tcpm(tcpc); 90 - 91 - return qcom_pmic_typec_port_get_cc(tcpm->pmic_typec_port, cc1, cc2); 92 - } 93 - 94 - static int qcom_pmic_typec_set_cc(struct tcpc_dev *tcpc, 95 - enum typec_cc_status cc) 96 - { 97 - struct pmic_typec *tcpm = tcpc_to_tcpm(tcpc); 98 - 99 - return qcom_pmic_typec_port_set_cc(tcpm->pmic_typec_port, cc); 100 - } 101 - 102 - static int qcom_pmic_typec_set_polarity(struct tcpc_dev *tcpc, 103 - enum typec_cc_polarity pol) 104 - { 105 - /* Polarity is set separately by phy-qcom-qmp.c */ 106 - return 0; 107 - } 108 - 109 - static int qcom_pmic_typec_start_toggling(struct tcpc_dev *tcpc, 110 - enum typec_port_type port_type, 111 - enum typec_cc_status cc) 112 - { 113 - struct pmic_typec *tcpm = tcpc_to_tcpm(tcpc); 114 - 115 - return qcom_pmic_typec_port_start_toggling(tcpm->pmic_typec_port, 116 - port_type, cc); 117 - } 118 - 119 - static int qcom_pmic_typec_set_roles(struct tcpc_dev *tcpc, bool attached, 120 - enum typec_role power_role, 121 - enum typec_data_role data_role) 122 - { 123 - struct pmic_typec *tcpm = tcpc_to_tcpm(tcpc); 124 - 125 - return qcom_pmic_typec_pdphy_set_roles(tcpm->pmic_typec_pdphy, 126 - data_role, power_role); 127 - } 128 - 129 - static int qcom_pmic_typec_set_pd_rx(struct tcpc_dev *tcpc, bool on) 130 - { 131 - struct pmic_typec *tcpm = tcpc_to_tcpm(tcpc); 132 - 133 - return qcom_pmic_typec_pdphy_set_pd_rx(tcpm->pmic_typec_pdphy, on); 134 - } 135 - 136 - static int qcom_pmic_typec_pd_transmit(struct tcpc_dev *tcpc, 137 - enum tcpm_transmit_type type, 138 - const struct pd_message *msg, 139 - unsigned int negotiated_rev) 140 - { 141 - struct pmic_typec *tcpm = tcpc_to_tcpm(tcpc); 142 - 143 - return qcom_pmic_typec_pdphy_pd_transmit(tcpm->pmic_typec_pdphy, type, 144 - msg, negotiated_rev); 145 - } 146 31 147 32 static int qcom_pmic_typec_init(struct tcpc_dev *tcpc) 148 33 { ··· 42 157 const struct pmic_typec_resources *res; 43 158 struct regmap *regmap; 44 159 struct device *bridge_dev; 45 - u32 base[2]; 160 + u32 base; 46 161 int ret; 47 162 48 163 res = of_device_get_match_data(dev); ··· 55 170 56 171 tcpm->dev = dev; 57 172 tcpm->tcpc.init = qcom_pmic_typec_init; 58 - tcpm->tcpc.get_vbus = qcom_pmic_typec_get_vbus; 59 - tcpm->tcpc.set_vbus = qcom_pmic_typec_set_vbus; 60 - tcpm->tcpc.set_cc = qcom_pmic_typec_set_cc; 61 - tcpm->tcpc.get_cc = qcom_pmic_typec_get_cc; 62 - tcpm->tcpc.set_polarity = qcom_pmic_typec_set_polarity; 63 - tcpm->tcpc.set_vconn = qcom_pmic_typec_set_vconn; 64 - tcpm->tcpc.start_toggling = qcom_pmic_typec_start_toggling; 65 - tcpm->tcpc.set_pd_rx = qcom_pmic_typec_set_pd_rx; 66 - tcpm->tcpc.set_roles = qcom_pmic_typec_set_roles; 67 - tcpm->tcpc.pd_transmit = qcom_pmic_typec_pd_transmit; 68 173 69 174 regmap = dev_get_regmap(dev->parent, NULL); 70 175 if (!regmap) { ··· 62 187 return -ENODEV; 63 188 } 64 189 65 - ret = of_property_read_u32_array(np, "reg", base, 2); 190 + ret = of_property_read_u32_index(np, "reg", 0, &base); 66 191 if (ret) 67 192 return ret; 68 193 69 - tcpm->pmic_typec_port = qcom_pmic_typec_port_alloc(dev); 70 - if (IS_ERR(tcpm->pmic_typec_port)) 71 - return PTR_ERR(tcpm->pmic_typec_port); 72 - 73 - tcpm->pmic_typec_pdphy = qcom_pmic_typec_pdphy_alloc(dev); 74 - if (IS_ERR(tcpm->pmic_typec_pdphy)) 75 - return PTR_ERR(tcpm->pmic_typec_pdphy); 76 - 77 - ret = qcom_pmic_typec_port_probe(pdev, tcpm->pmic_typec_port, 78 - res->port_res, regmap, base[0]); 194 + ret = qcom_pmic_typec_port_probe(pdev, tcpm, 195 + res->port_res, regmap, base); 79 196 if (ret) 80 197 return ret; 81 198 82 - ret = qcom_pmic_typec_pdphy_probe(pdev, tcpm->pmic_typec_pdphy, 83 - res->pdphy_res, regmap, base[1]); 84 - if (ret) 85 - return ret; 199 + if (res->pdphy_res) { 200 + ret = of_property_read_u32_index(np, "reg", 1, &base); 201 + if (ret) 202 + return ret; 86 203 87 - mutex_init(&tcpm->lock); 204 + ret = qcom_pmic_typec_pdphy_probe(pdev, tcpm, 205 + res->pdphy_res, regmap, base); 206 + if (ret) 207 + return ret; 208 + } else { 209 + ret = qcom_pmic_typec_pdphy_stub_probe(pdev, tcpm); 210 + if (ret) 211 + return ret; 212 + } 213 + 88 214 platform_set_drvdata(pdev, tcpm); 89 215 90 216 tcpm->tcpc.fwnode = device_get_named_child_node(tcpm->dev, "connector"); ··· 102 226 goto fwnode_remove; 103 227 } 104 228 105 - ret = qcom_pmic_typec_port_start(tcpm->pmic_typec_port, 106 - tcpm->tcpm_port); 229 + ret = tcpm->port_start(tcpm, tcpm->tcpm_port); 107 230 if (ret) 108 231 goto fwnode_remove; 109 232 110 - ret = qcom_pmic_typec_pdphy_start(tcpm->pmic_typec_pdphy, 111 - tcpm->tcpm_port); 233 + ret = tcpm->pdphy_start(tcpm, tcpm->tcpm_port); 112 234 if (ret) 113 235 goto fwnode_remove; 114 236 ··· 122 248 { 123 249 struct pmic_typec *tcpm = platform_get_drvdata(pdev); 124 250 125 - qcom_pmic_typec_pdphy_stop(tcpm->pmic_typec_pdphy); 126 - qcom_pmic_typec_port_stop(tcpm->pmic_typec_port); 251 + tcpm->pdphy_stop(tcpm); 252 + tcpm->port_stop(tcpm); 127 253 tcpm_unregister_port(tcpm->tcpm_port); 128 254 fwnode_remove_software_node(tcpm->tcpc.fwnode); 129 255 } 130 256 131 - static struct pmic_typec_pdphy_resources pm8150b_pdphy_res = { 132 - .irq_params = { 133 - { 134 - .virq = PMIC_PDPHY_SIG_TX_IRQ, 135 - .irq_name = "sig-tx", 136 - }, 137 - { 138 - .virq = PMIC_PDPHY_SIG_RX_IRQ, 139 - .irq_name = "sig-rx", 140 - }, 141 - { 142 - .virq = PMIC_PDPHY_MSG_TX_IRQ, 143 - .irq_name = "msg-tx", 144 - }, 145 - { 146 - .virq = PMIC_PDPHY_MSG_RX_IRQ, 147 - .irq_name = "msg-rx", 148 - }, 149 - { 150 - .virq = PMIC_PDPHY_MSG_TX_FAIL_IRQ, 151 - .irq_name = "msg-tx-failed", 152 - }, 153 - { 154 - .virq = PMIC_PDPHY_MSG_TX_DISCARD_IRQ, 155 - .irq_name = "msg-tx-discarded", 156 - }, 157 - { 158 - .virq = PMIC_PDPHY_MSG_RX_DISCARD_IRQ, 159 - .irq_name = "msg-rx-discarded", 160 - }, 161 - }, 162 - .nr_irqs = 7, 163 - }; 164 - 165 - static struct pmic_typec_port_resources pm8150b_port_res = { 166 - .irq_params = { 167 - { 168 - .irq_name = "vpd-detect", 169 - .virq = PMIC_TYPEC_VPD_IRQ, 170 - }, 171 - 172 - { 173 - .irq_name = "cc-state-change", 174 - .virq = PMIC_TYPEC_CC_STATE_IRQ, 175 - }, 176 - { 177 - .irq_name = "vconn-oc", 178 - .virq = PMIC_TYPEC_VCONN_OC_IRQ, 179 - }, 180 - 181 - { 182 - .irq_name = "vbus-change", 183 - .virq = PMIC_TYPEC_VBUS_IRQ, 184 - }, 185 - 186 - { 187 - .irq_name = "attach-detach", 188 - .virq = PMIC_TYPEC_ATTACH_DETACH_IRQ, 189 - }, 190 - { 191 - .irq_name = "legacy-cable-detect", 192 - .virq = PMIC_TYPEC_LEGACY_CABLE_IRQ, 193 - }, 194 - 195 - { 196 - .irq_name = "try-snk-src-detect", 197 - .virq = PMIC_TYPEC_TRY_SNK_SRC_IRQ, 198 - }, 199 - }, 200 - .nr_irqs = 7, 201 - }; 202 - 203 - static struct pmic_typec_resources pm8150b_typec_res = { 257 + static const struct pmic_typec_resources pm8150b_typec_res = { 204 258 .pdphy_res = &pm8150b_pdphy_res, 259 + .port_res = &pm8150b_port_res, 260 + }; 261 + 262 + static const struct pmic_typec_resources pmi632_typec_res = { 263 + /* PD PHY not present */ 205 264 .port_res = &pm8150b_port_res, 206 265 }; 207 266 208 267 static const struct of_device_id qcom_pmic_typec_table[] = { 209 268 { .compatible = "qcom,pm8150b-typec", .data = &pm8150b_typec_res }, 269 + { .compatible = "qcom,pmi632-typec", .data = &pmi632_typec_res }, 210 270 { } 211 271 }; 212 272 MODULE_DEVICE_TABLE(of, qcom_pmic_typec_table);
+27
drivers/usb/typec/tcpm/qcom/qcom_pmic_typec.h
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * Copyright (c) 2023, Linaro Ltd. All rights reserved. 4 + */ 5 + 6 + #ifndef __QCOM_PMIC_TYPEC_H__ 7 + #define __QCOM_PMIC_TYPEC_H__ 8 + 9 + struct pmic_typec { 10 + struct device *dev; 11 + struct tcpm_port *tcpm_port; 12 + struct tcpc_dev tcpc; 13 + struct pmic_typec_pdphy *pmic_typec_pdphy; 14 + struct pmic_typec_port *pmic_typec_port; 15 + 16 + int (*pdphy_start)(struct pmic_typec *tcpm, 17 + struct tcpm_port *tcpm_port); 18 + void (*pdphy_stop)(struct pmic_typec *tcpm); 19 + 20 + int (*port_start)(struct pmic_typec *tcpm, 21 + struct tcpm_port *tcpm_port); 22 + void (*port_stop)(struct pmic_typec *tcpm); 23 + }; 24 + 25 + #define tcpc_to_tcpm(_tcpc_) container_of(_tcpc_, struct pmic_typec, tcpc) 26 + 27 + #endif
+139 -20
drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c
··· 14 14 #include <linux/slab.h> 15 15 #include <linux/usb/pd.h> 16 16 #include <linux/usb/tcpm.h> 17 + #include "qcom_pmic_typec.h" 17 18 #include "qcom_pmic_typec_pdphy.h" 19 + 20 + /* PD PHY register offsets and bit fields */ 21 + #define USB_PDPHY_MSG_CONFIG_REG 0x40 22 + #define MSG_CONFIG_PORT_DATA_ROLE BIT(3) 23 + #define MSG_CONFIG_PORT_POWER_ROLE BIT(2) 24 + #define MSG_CONFIG_SPEC_REV_MASK (BIT(1) | BIT(0)) 25 + 26 + #define USB_PDPHY_EN_CONTROL_REG 0x46 27 + #define CONTROL_ENABLE BIT(0) 28 + 29 + #define USB_PDPHY_RX_STATUS_REG 0x4A 30 + #define RX_FRAME_TYPE (BIT(0) | BIT(1) | BIT(2)) 31 + 32 + #define USB_PDPHY_FRAME_FILTER_REG 0x4C 33 + #define FRAME_FILTER_EN_HARD_RESET BIT(5) 34 + #define FRAME_FILTER_EN_SOP BIT(0) 35 + 36 + #define USB_PDPHY_TX_SIZE_REG 0x42 37 + #define TX_SIZE_MASK 0xF 38 + 39 + #define USB_PDPHY_TX_CONTROL_REG 0x44 40 + #define TX_CONTROL_RETRY_COUNT(n) (((n) & 0x3) << 5) 41 + #define TX_CONTROL_FRAME_TYPE(n) (((n) & 0x7) << 2) 42 + #define TX_CONTROL_FRAME_TYPE_CABLE_RESET (0x1 << 2) 43 + #define TX_CONTROL_SEND_SIGNAL BIT(1) 44 + #define TX_CONTROL_SEND_MSG BIT(0) 45 + 46 + #define USB_PDPHY_RX_SIZE_REG 0x48 47 + 48 + #define USB_PDPHY_RX_ACKNOWLEDGE_REG 0x4B 49 + #define RX_BUFFER_TOKEN BIT(0) 50 + 51 + #define USB_PDPHY_BIST_MODE_REG 0x4E 52 + #define BIST_MODE_MASK 0xF 53 + #define BIST_ENABLE BIT(7) 54 + #define PD_MSG_BIST 0x3 55 + #define PD_BIST_TEST_DATA_MODE 0x8 56 + 57 + #define USB_PDPHY_TX_BUFFER_HDR_REG 0x60 58 + #define USB_PDPHY_TX_BUFFER_DATA_REG 0x62 59 + 60 + #define USB_PDPHY_RX_BUFFER_REG 0x80 61 + 62 + /* VDD regulator */ 63 + #define VDD_PDPHY_VOL_MIN 2800000 /* uV */ 64 + #define VDD_PDPHY_VOL_MAX 3300000 /* uV */ 65 + #define VDD_PDPHY_HPM_LOAD 3000 /* uA */ 66 + 67 + /* Message Spec Rev field */ 68 + #define PD_MSG_HDR_REV(hdr) (((hdr) >> 6) & 3) 69 + 70 + /* timers */ 71 + #define RECEIVER_RESPONSE_TIME 15 /* tReceiverResponse */ 72 + #define HARD_RESET_COMPLETE_TIME 5 /* tHardResetComplete */ 73 + 74 + /* Interrupt numbers */ 75 + #define PMIC_PDPHY_SIG_TX_IRQ 0x0 76 + #define PMIC_PDPHY_SIG_RX_IRQ 0x1 77 + #define PMIC_PDPHY_MSG_TX_IRQ 0x2 78 + #define PMIC_PDPHY_MSG_RX_IRQ 0x3 79 + #define PMIC_PDPHY_MSG_TX_FAIL_IRQ 0x4 80 + #define PMIC_PDPHY_MSG_TX_DISCARD_IRQ 0x5 81 + #define PMIC_PDPHY_MSG_RX_DISCARD_IRQ 0x6 82 + #define PMIC_PDPHY_FR_SWAP_IRQ 0x7 83 + 18 84 19 85 struct pmic_typec_pdphy_irq_data { 20 86 int virq; ··· 297 231 return ret; 298 232 } 299 233 300 - int qcom_pmic_typec_pdphy_pd_transmit(struct pmic_typec_pdphy *pmic_typec_pdphy, 301 - enum tcpm_transmit_type type, 302 - const struct pd_message *msg, 303 - unsigned int negotiated_rev) 234 + static int qcom_pmic_typec_pdphy_pd_transmit(struct tcpc_dev *tcpc, 235 + enum tcpm_transmit_type type, 236 + const struct pd_message *msg, 237 + unsigned int negotiated_rev) 304 238 { 239 + struct pmic_typec *tcpm = tcpc_to_tcpm(tcpc); 240 + struct pmic_typec_pdphy *pmic_typec_pdphy = tcpm->pmic_typec_pdphy; 305 241 struct device *dev = pmic_typec_pdphy->dev; 306 242 int ret; 307 243 ··· 367 299 368 300 if (!ret) { 369 301 dev_vdbg(dev, "pd_receive: handing %d bytes to tcpm\n", size); 370 - tcpm_pd_receive(pmic_typec_pdphy->tcpm_port, &msg); 302 + tcpm_pd_receive(pmic_typec_pdphy->tcpm_port, &msg, TCPC_TX_SOP); 371 303 } 372 304 } 373 305 ··· 404 336 return IRQ_HANDLED; 405 337 } 406 338 407 - int qcom_pmic_typec_pdphy_set_pd_rx(struct pmic_typec_pdphy *pmic_typec_pdphy, bool on) 339 + static int qcom_pmic_typec_pdphy_set_pd_rx(struct tcpc_dev *tcpc, bool on) 408 340 { 341 + struct pmic_typec *tcpm = tcpc_to_tcpm(tcpc); 342 + struct pmic_typec_pdphy *pmic_typec_pdphy = tcpm->pmic_typec_pdphy; 409 343 unsigned long flags; 410 344 int ret; 411 345 ··· 423 353 return ret; 424 354 } 425 355 426 - int qcom_pmic_typec_pdphy_set_roles(struct pmic_typec_pdphy *pmic_typec_pdphy, 427 - bool data_role_host, bool power_role_src) 356 + static int qcom_pmic_typec_pdphy_set_roles(struct tcpc_dev *tcpc, bool attached, 357 + enum typec_role power_role, 358 + enum typec_data_role data_role) 428 359 { 360 + struct pmic_typec *tcpm = tcpc_to_tcpm(tcpc); 361 + struct pmic_typec_pdphy *pmic_typec_pdphy = tcpm->pmic_typec_pdphy; 429 362 struct device *dev = pmic_typec_pdphy->dev; 430 363 unsigned long flags; 431 364 int ret; ··· 439 366 pmic_typec_pdphy->base + USB_PDPHY_MSG_CONFIG_REG, 440 367 MSG_CONFIG_PORT_DATA_ROLE | 441 368 MSG_CONFIG_PORT_POWER_ROLE, 442 - data_role_host << 3 | power_role_src << 2); 369 + (data_role == TYPEC_HOST ? MSG_CONFIG_PORT_DATA_ROLE : 0) | 370 + (power_role == TYPEC_SOURCE ? MSG_CONFIG_PORT_POWER_ROLE : 0)); 443 371 444 372 spin_unlock_irqrestore(&pmic_typec_pdphy->lock, flags); 445 373 446 374 dev_dbg(dev, "pdphy_set_roles: data_role_host=%d power_role_src=%d\n", 447 - data_role_host, power_role_src); 375 + data_role, power_role); 448 376 449 377 return ret; 450 378 } ··· 509 435 return ret; 510 436 } 511 437 512 - int qcom_pmic_typec_pdphy_start(struct pmic_typec_pdphy *pmic_typec_pdphy, 513 - struct tcpm_port *tcpm_port) 438 + static int qcom_pmic_typec_pdphy_start(struct pmic_typec *tcpm, 439 + struct tcpm_port *tcpm_port) 514 440 { 441 + struct pmic_typec_pdphy *pmic_typec_pdphy = tcpm->pmic_typec_pdphy; 515 442 int i; 516 443 int ret; 517 444 ··· 532 457 return 0; 533 458 } 534 459 535 - void qcom_pmic_typec_pdphy_stop(struct pmic_typec_pdphy *pmic_typec_pdphy) 460 + static void qcom_pmic_typec_pdphy_stop(struct pmic_typec *tcpm) 536 461 { 462 + struct pmic_typec_pdphy *pmic_typec_pdphy = tcpm->pmic_typec_pdphy; 537 463 int i; 538 464 539 465 for (i = 0; i < pmic_typec_pdphy->nr_irqs; i++) ··· 545 469 regulator_disable(pmic_typec_pdphy->vdd_pdphy); 546 470 } 547 471 548 - struct pmic_typec_pdphy *qcom_pmic_typec_pdphy_alloc(struct device *dev) 549 - { 550 - return devm_kzalloc(dev, sizeof(struct pmic_typec_pdphy), GFP_KERNEL); 551 - } 552 - 553 472 int qcom_pmic_typec_pdphy_probe(struct platform_device *pdev, 554 - struct pmic_typec_pdphy *pmic_typec_pdphy, 555 - struct pmic_typec_pdphy_resources *res, 473 + struct pmic_typec *tcpm, 474 + const struct pmic_typec_pdphy_resources *res, 556 475 struct regmap *regmap, 557 476 u32 base) 558 477 { 478 + struct pmic_typec_pdphy *pmic_typec_pdphy; 559 479 struct device *dev = &pdev->dev; 560 480 struct pmic_typec_pdphy_irq_data *irq_data; 561 481 int i, ret, irq; 482 + 483 + pmic_typec_pdphy = devm_kzalloc(dev, sizeof(*pmic_typec_pdphy), GFP_KERNEL); 484 + if (!pmic_typec_pdphy) 485 + return -ENOMEM; 562 486 563 487 if (!res->nr_irqs || res->nr_irqs > PMIC_PDPHY_MAX_IRQS) 564 488 return -EINVAL; ··· 598 522 return ret; 599 523 } 600 524 525 + tcpm->pmic_typec_pdphy = pmic_typec_pdphy; 526 + 527 + tcpm->tcpc.set_pd_rx = qcom_pmic_typec_pdphy_set_pd_rx; 528 + tcpm->tcpc.set_roles = qcom_pmic_typec_pdphy_set_roles; 529 + tcpm->tcpc.pd_transmit = qcom_pmic_typec_pdphy_pd_transmit; 530 + 531 + tcpm->pdphy_start = qcom_pmic_typec_pdphy_start; 532 + tcpm->pdphy_stop = qcom_pmic_typec_pdphy_stop; 533 + 601 534 return 0; 602 535 } 536 + 537 + const struct pmic_typec_pdphy_resources pm8150b_pdphy_res = { 538 + .irq_params = { 539 + { 540 + .virq = PMIC_PDPHY_SIG_TX_IRQ, 541 + .irq_name = "sig-tx", 542 + }, 543 + { 544 + .virq = PMIC_PDPHY_SIG_RX_IRQ, 545 + .irq_name = "sig-rx", 546 + }, 547 + { 548 + .virq = PMIC_PDPHY_MSG_TX_IRQ, 549 + .irq_name = "msg-tx", 550 + }, 551 + { 552 + .virq = PMIC_PDPHY_MSG_RX_IRQ, 553 + .irq_name = "msg-rx", 554 + }, 555 + { 556 + .virq = PMIC_PDPHY_MSG_TX_FAIL_IRQ, 557 + .irq_name = "msg-tx-failed", 558 + }, 559 + { 560 + .virq = PMIC_PDPHY_MSG_TX_DISCARD_IRQ, 561 + .irq_name = "msg-tx-discarded", 562 + }, 563 + { 564 + .virq = PMIC_PDPHY_MSG_RX_DISCARD_IRQ, 565 + .irq_name = "msg-rx-discarded", 566 + }, 567 + }, 568 + .nr_irqs = 7, 569 + };
+6 -88
drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.h
··· 8 8 9 9 #include <linux/platform_device.h> 10 10 #include <linux/regmap.h> 11 - #include <linux/usb/tcpm.h> 12 - 13 - #define USB_PDPHY_MAX_DATA_OBJ_LEN 28 14 - #define USB_PDPHY_MSG_HDR_LEN 2 15 - 16 - /* PD PHY register offsets and bit fields */ 17 - #define USB_PDPHY_MSG_CONFIG_REG 0x40 18 - #define MSG_CONFIG_PORT_DATA_ROLE BIT(3) 19 - #define MSG_CONFIG_PORT_POWER_ROLE BIT(2) 20 - #define MSG_CONFIG_SPEC_REV_MASK (BIT(1) | BIT(0)) 21 - 22 - #define USB_PDPHY_EN_CONTROL_REG 0x46 23 - #define CONTROL_ENABLE BIT(0) 24 - 25 - #define USB_PDPHY_RX_STATUS_REG 0x4A 26 - #define RX_FRAME_TYPE (BIT(0) | BIT(1) | BIT(2)) 27 - 28 - #define USB_PDPHY_FRAME_FILTER_REG 0x4C 29 - #define FRAME_FILTER_EN_HARD_RESET BIT(5) 30 - #define FRAME_FILTER_EN_SOP BIT(0) 31 - 32 - #define USB_PDPHY_TX_SIZE_REG 0x42 33 - #define TX_SIZE_MASK 0xF 34 - 35 - #define USB_PDPHY_TX_CONTROL_REG 0x44 36 - #define TX_CONTROL_RETRY_COUNT(n) (((n) & 0x3) << 5) 37 - #define TX_CONTROL_FRAME_TYPE(n) (((n) & 0x7) << 2) 38 - #define TX_CONTROL_FRAME_TYPE_CABLE_RESET (0x1 << 2) 39 - #define TX_CONTROL_SEND_SIGNAL BIT(1) 40 - #define TX_CONTROL_SEND_MSG BIT(0) 41 - 42 - #define USB_PDPHY_RX_SIZE_REG 0x48 43 - 44 - #define USB_PDPHY_RX_ACKNOWLEDGE_REG 0x4B 45 - #define RX_BUFFER_TOKEN BIT(0) 46 - 47 - #define USB_PDPHY_BIST_MODE_REG 0x4E 48 - #define BIST_MODE_MASK 0xF 49 - #define BIST_ENABLE BIT(7) 50 - #define PD_MSG_BIST 0x3 51 - #define PD_BIST_TEST_DATA_MODE 0x8 52 - 53 - #define USB_PDPHY_TX_BUFFER_HDR_REG 0x60 54 - #define USB_PDPHY_TX_BUFFER_DATA_REG 0x62 55 - 56 - #define USB_PDPHY_RX_BUFFER_REG 0x80 57 - 58 - /* VDD regulator */ 59 - #define VDD_PDPHY_VOL_MIN 2800000 /* uV */ 60 - #define VDD_PDPHY_VOL_MAX 3300000 /* uV */ 61 - #define VDD_PDPHY_HPM_LOAD 3000 /* uA */ 62 - 63 - /* Message Spec Rev field */ 64 - #define PD_MSG_HDR_REV(hdr) (((hdr) >> 6) & 3) 65 - 66 - /* timers */ 67 - #define RECEIVER_RESPONSE_TIME 15 /* tReceiverResponse */ 68 - #define HARD_RESET_COMPLETE_TIME 5 /* tHardResetComplete */ 69 - 70 - /* Interrupt numbers */ 71 - #define PMIC_PDPHY_SIG_TX_IRQ 0x0 72 - #define PMIC_PDPHY_SIG_RX_IRQ 0x1 73 - #define PMIC_PDPHY_MSG_TX_IRQ 0x2 74 - #define PMIC_PDPHY_MSG_RX_IRQ 0x3 75 - #define PMIC_PDPHY_MSG_TX_FAIL_IRQ 0x4 76 - #define PMIC_PDPHY_MSG_TX_DISCARD_IRQ 0x5 77 - #define PMIC_PDPHY_MSG_RX_DISCARD_IRQ 0x6 78 - #define PMIC_PDPHY_FR_SWAP_IRQ 0x7 79 11 80 12 /* Resources */ 81 13 #define PMIC_PDPHY_MAX_IRQS 0x08 ··· 19 87 20 88 struct pmic_typec_pdphy_resources { 21 89 unsigned int nr_irqs; 22 - struct pmic_typec_pdphy_irq_params irq_params[PMIC_PDPHY_MAX_IRQS]; 90 + const struct pmic_typec_pdphy_irq_params irq_params[PMIC_PDPHY_MAX_IRQS]; 23 91 }; 24 92 25 93 /* API */ 26 94 struct pmic_typec_pdphy; 27 95 28 - struct pmic_typec_pdphy *qcom_pmic_typec_pdphy_alloc(struct device *dev); 29 - 96 + extern const struct pmic_typec_pdphy_resources pm8150b_pdphy_res; 30 97 int qcom_pmic_typec_pdphy_probe(struct platform_device *pdev, 31 - struct pmic_typec_pdphy *pmic_typec_pdphy, 32 - struct pmic_typec_pdphy_resources *res, 98 + struct pmic_typec *tcpm, 99 + const struct pmic_typec_pdphy_resources *res, 33 100 struct regmap *regmap, 34 101 u32 base); 35 - 36 - int qcom_pmic_typec_pdphy_start(struct pmic_typec_pdphy *pmic_typec_pdphy, 37 - struct tcpm_port *tcpm_port); 38 - 39 - void qcom_pmic_typec_pdphy_stop(struct pmic_typec_pdphy *pmic_typec_pdphy); 40 - 41 - int qcom_pmic_typec_pdphy_set_roles(struct pmic_typec_pdphy *pmic_typec_pdphy, 42 - bool power_role_src, bool data_role_host); 43 - 44 - int qcom_pmic_typec_pdphy_set_pd_rx(struct pmic_typec_pdphy *pmic_typec_pdphy, bool on); 45 - 46 - int qcom_pmic_typec_pdphy_pd_transmit(struct pmic_typec_pdphy *pmic_typec_pdphy, 47 - enum tcpm_transmit_type type, 48 - const struct pd_message *msg, 49 - unsigned int negotiated_rev); 102 + int qcom_pmic_typec_pdphy_stub_probe(struct platform_device *pdev, 103 + struct pmic_typec *tcpm); 50 104 51 105 #endif /* __QCOM_PMIC_TYPEC_PDPHY_H__ */
+80
drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy_stub.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * Copyright (c) 2024, Linaro Ltd. All rights reserved. 4 + */ 5 + 6 + #include <linux/err.h> 7 + #include <linux/interrupt.h> 8 + #include <linux/kernel.h> 9 + #include <linux/mod_devicetable.h> 10 + #include <linux/module.h> 11 + #include <linux/platform_device.h> 12 + #include <linux/regmap.h> 13 + #include <linux/regulator/consumer.h> 14 + #include <linux/slab.h> 15 + #include <linux/usb/pd.h> 16 + #include <linux/usb/tcpm.h> 17 + #include "qcom_pmic_typec.h" 18 + #include "qcom_pmic_typec_pdphy.h" 19 + 20 + static int qcom_pmic_typec_pdphy_stub_pd_transmit(struct tcpc_dev *tcpc, 21 + enum tcpm_transmit_type type, 22 + const struct pd_message *msg, 23 + unsigned int negotiated_rev) 24 + { 25 + struct pmic_typec *tcpm = tcpc_to_tcpm(tcpc); 26 + struct device *dev = tcpm->dev; 27 + 28 + dev_dbg(dev, "pdphy_transmit: type=%d\n", type); 29 + 30 + tcpm_pd_transmit_complete(tcpm->tcpm_port, 31 + TCPC_TX_SUCCESS); 32 + 33 + return 0; 34 + } 35 + 36 + static int qcom_pmic_typec_pdphy_stub_set_pd_rx(struct tcpc_dev *tcpc, bool on) 37 + { 38 + struct pmic_typec *tcpm = tcpc_to_tcpm(tcpc); 39 + struct device *dev = tcpm->dev; 40 + 41 + dev_dbg(dev, "set_pd_rx: %s\n", on ? "on" : "off"); 42 + 43 + return 0; 44 + } 45 + 46 + static int qcom_pmic_typec_pdphy_stub_set_roles(struct tcpc_dev *tcpc, bool attached, 47 + enum typec_role power_role, 48 + enum typec_data_role data_role) 49 + { 50 + struct pmic_typec *tcpm = tcpc_to_tcpm(tcpc); 51 + struct device *dev = tcpm->dev; 52 + 53 + dev_dbg(dev, "pdphy_set_roles: data_role_host=%d power_role_src=%d\n", 54 + data_role, power_role); 55 + 56 + return 0; 57 + } 58 + 59 + static int qcom_pmic_typec_pdphy_stub_start(struct pmic_typec *tcpm, 60 + struct tcpm_port *tcpm_port) 61 + { 62 + return 0; 63 + } 64 + 65 + static void qcom_pmic_typec_pdphy_stub_stop(struct pmic_typec *tcpm) 66 + { 67 + } 68 + 69 + int qcom_pmic_typec_pdphy_stub_probe(struct platform_device *pdev, 70 + struct pmic_typec *tcpm) 71 + { 72 + tcpm->tcpc.set_pd_rx = qcom_pmic_typec_pdphy_stub_set_pd_rx; 73 + tcpm->tcpc.set_roles = qcom_pmic_typec_pdphy_stub_set_roles; 74 + tcpm->tcpc.pd_transmit = qcom_pmic_typec_pdphy_stub_pd_transmit; 75 + 76 + tcpm->pdphy_start = qcom_pmic_typec_pdphy_stub_start; 77 + tcpm->pdphy_stop = qcom_pmic_typec_pdphy_stub_stop; 78 + 79 + return 0; 80 + }
+269 -21
drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c
··· 16 16 #include <linux/usb/tcpm.h> 17 17 #include <linux/usb/typec_mux.h> 18 18 #include <linux/workqueue.h> 19 + 20 + #include "qcom_pmic_typec.h" 19 21 #include "qcom_pmic_typec_port.h" 22 + 23 + #define TYPEC_SNK_STATUS_REG 0x06 24 + #define DETECTED_SNK_TYPE_MASK GENMASK(6, 0) 25 + #define SNK_DAM_MASK GENMASK(6, 4) 26 + #define SNK_DAM_500MA BIT(6) 27 + #define SNK_DAM_1500MA BIT(5) 28 + #define SNK_DAM_3000MA BIT(4) 29 + #define SNK_RP_STD BIT(3) 30 + #define SNK_RP_1P5 BIT(2) 31 + #define SNK_RP_3P0 BIT(1) 32 + #define SNK_RP_SHORT BIT(0) 33 + 34 + #define TYPEC_SRC_STATUS_REG 0x08 35 + #define DETECTED_SRC_TYPE_MASK GENMASK(4, 0) 36 + #define SRC_HIGH_BATT BIT(5) 37 + #define SRC_DEBUG_ACCESS BIT(4) 38 + #define SRC_RD_OPEN BIT(3) 39 + #define SRC_RD_RA_VCONN BIT(2) 40 + #define SRC_RA_OPEN BIT(1) 41 + #define AUDIO_ACCESS_RA_RA BIT(0) 42 + 43 + #define TYPEC_STATE_MACHINE_STATUS_REG 0x09 44 + #define TYPEC_ATTACH_DETACH_STATE BIT(5) 45 + 46 + #define TYPEC_SM_STATUS_REG 0x0A 47 + #define TYPEC_SM_VBUS_VSAFE5V BIT(5) 48 + #define TYPEC_SM_VBUS_VSAFE0V BIT(6) 49 + #define TYPEC_SM_USBIN_LT_LV BIT(7) 50 + 51 + #define TYPEC_MISC_STATUS_REG 0x0B 52 + #define TYPEC_WATER_DETECTION_STATUS BIT(7) 53 + #define SNK_SRC_MODE BIT(6) 54 + #define TYPEC_VBUS_DETECT BIT(5) 55 + #define TYPEC_VBUS_ERROR_STATUS BIT(4) 56 + #define TYPEC_DEBOUNCE_DONE BIT(3) 57 + #define CC_ORIENTATION BIT(1) 58 + #define CC_ATTACHED BIT(0) 59 + 60 + #define LEGACY_CABLE_STATUS_REG 0x0D 61 + #define TYPEC_LEGACY_CABLE_STATUS BIT(1) 62 + #define TYPEC_NONCOMP_LEGACY_CABLE_STATUS BIT(0) 63 + 64 + #define TYPEC_U_USB_STATUS_REG 0x0F 65 + #define U_USB_GROUND_NOVBUS BIT(6) 66 + #define U_USB_GROUND BIT(4) 67 + #define U_USB_FMB1 BIT(3) 68 + #define U_USB_FLOAT1 BIT(2) 69 + #define U_USB_FMB2 BIT(1) 70 + #define U_USB_FLOAT2 BIT(0) 71 + 72 + #define TYPEC_MODE_CFG_REG 0x44 73 + #define TYPEC_TRY_MODE_MASK GENMASK(4, 3) 74 + #define EN_TRY_SNK BIT(4) 75 + #define EN_TRY_SRC BIT(3) 76 + #define TYPEC_POWER_ROLE_CMD_MASK GENMASK(2, 0) 77 + #define EN_SRC_ONLY BIT(2) 78 + #define EN_SNK_ONLY BIT(1) 79 + #define TYPEC_DISABLE_CMD BIT(0) 80 + 81 + #define TYPEC_VCONN_CONTROL_REG 0x46 82 + #define VCONN_EN_ORIENTATION BIT(2) 83 + #define VCONN_EN_VALUE BIT(1) 84 + #define VCONN_EN_SRC BIT(0) 85 + 86 + #define TYPEC_CCOUT_CONTROL_REG 0x48 87 + #define TYPEC_CCOUT_BUFFER_EN BIT(2) 88 + #define TYPEC_CCOUT_VALUE BIT(1) 89 + #define TYPEC_CCOUT_SRC BIT(0) 90 + 91 + #define DEBUG_ACCESS_SRC_CFG_REG 0x4C 92 + #define EN_UNORIENTED_DEBUG_ACCESS_SRC BIT(0) 93 + 94 + #define TYPE_C_CRUDE_SENSOR_CFG_REG 0x4e 95 + #define EN_SRC_CRUDE_SENSOR BIT(1) 96 + #define EN_SNK_CRUDE_SENSOR BIT(0) 97 + 98 + #define TYPEC_EXIT_STATE_CFG_REG 0x50 99 + #define BYPASS_VSAFE0V_DURING_ROLE_SWAP BIT(3) 100 + #define SEL_SRC_UPPER_REF BIT(2) 101 + #define USE_TPD_FOR_EXITING_ATTACHSRC BIT(1) 102 + #define EXIT_SNK_BASED_ON_CC BIT(0) 103 + 104 + #define TYPEC_CURRSRC_CFG_REG 0x52 105 + #define TYPEC_SRC_RP_SEL_330UA BIT(1) 106 + #define TYPEC_SRC_RP_SEL_180UA BIT(0) 107 + #define TYPEC_SRC_RP_SEL_80UA 0 108 + #define TYPEC_SRC_RP_SEL_MASK GENMASK(1, 0) 109 + 110 + #define TYPEC_INTERRUPT_EN_CFG_1_REG 0x5E 111 + #define TYPEC_LEGACY_CABLE_INT_EN BIT(7) 112 + #define TYPEC_NONCOMPLIANT_LEGACY_CABLE_INT_EN BIT(6) 113 + #define TYPEC_TRYSOURCE_DETECT_INT_EN BIT(5) 114 + #define TYPEC_TRYSINK_DETECT_INT_EN BIT(4) 115 + #define TYPEC_CCOUT_DETACH_INT_EN BIT(3) 116 + #define TYPEC_CCOUT_ATTACH_INT_EN BIT(2) 117 + #define TYPEC_VBUS_DEASSERT_INT_EN BIT(1) 118 + #define TYPEC_VBUS_ASSERT_INT_EN BIT(0) 119 + 120 + #define TYPEC_INTERRUPT_EN_CFG_2_REG 0x60 121 + #define TYPEC_SRC_BATT_HPWR_INT_EN BIT(6) 122 + #define MICRO_USB_STATE_CHANGE_INT_EN BIT(5) 123 + #define TYPEC_STATE_MACHINE_CHANGE_INT_EN BIT(4) 124 + #define TYPEC_DEBUG_ACCESS_DETECT_INT_EN BIT(3) 125 + #define TYPEC_WATER_DETECTION_INT_EN BIT(2) 126 + #define TYPEC_VBUS_ERROR_INT_EN BIT(1) 127 + #define TYPEC_DEBOUNCE_DONE_INT_EN BIT(0) 128 + 129 + #define TYPEC_DEBOUNCE_OPTION_REG 0x62 130 + #define REDUCE_TCCDEBOUNCE_TO_2MS BIT(2) 131 + 132 + #define TYPE_C_SBU_CFG_REG 0x6A 133 + #define SEL_SBU1_ISRC_VAL 0x04 134 + #define SEL_SBU2_ISRC_VAL 0x01 135 + 136 + #define TYPEC_U_USB_CFG_REG 0x70 137 + #define EN_MICRO_USB_FACTORY_MODE BIT(1) 138 + #define EN_MICRO_USB_MODE BIT(0) 139 + 140 + #define TYPEC_PMI632_U_USB_WATER_PROTECTION_CFG_REG 0x72 141 + 142 + #define TYPEC_U_USB_WATER_PROTECTION_CFG_REG 0x73 143 + #define EN_MICRO_USB_WATER_PROTECTION BIT(4) 144 + #define MICRO_USB_DETECTION_ON_TIME_CFG_MASK GENMASK(3, 2) 145 + #define MICRO_USB_DETECTION_PERIOD_CFG_MASK GENMASK(1, 0) 146 + 147 + #define TYPEC_PMI632_MICRO_USB_MODE_REG 0x73 148 + #define MICRO_USB_MODE_ONLY BIT(0) 149 + 150 + /* Interrupt numbers */ 151 + #define PMIC_TYPEC_OR_RID_IRQ 0x0 152 + #define PMIC_TYPEC_VPD_IRQ 0x1 153 + #define PMIC_TYPEC_CC_STATE_IRQ 0x2 154 + #define PMIC_TYPEC_VCONN_OC_IRQ 0x3 155 + #define PMIC_TYPEC_VBUS_IRQ 0x4 156 + #define PMIC_TYPEC_ATTACH_DETACH_IRQ 0x5 157 + #define PMIC_TYPEC_LEGACY_CABLE_IRQ 0x6 158 + #define PMIC_TYPEC_TRY_SNK_SRC_IRQ 0x7 20 159 21 160 struct pmic_typec_port_irq_data { 22 161 int virq; ··· 172 33 struct pmic_typec_port_irq_data *irq_data; 173 34 174 35 struct regulator *vdd_vbus; 36 + bool vbus_enabled; 37 + struct mutex vbus_lock; /* VBUS state serialization */ 175 38 176 39 int cc; 177 40 bool debouncing_cc; ··· 272 131 return IRQ_HANDLED; 273 132 } 274 133 275 - int qcom_pmic_typec_port_get_vbus(struct pmic_typec_port *pmic_typec_port) 134 + static int qcom_pmic_typec_port_vbus_detect(struct pmic_typec_port *pmic_typec_port) 276 135 { 277 136 struct device *dev = pmic_typec_port->dev; 278 137 unsigned int misc; ··· 289 148 return !!(misc & TYPEC_VBUS_DETECT); 290 149 } 291 150 292 - int qcom_pmic_typec_port_set_vbus(struct pmic_typec_port *pmic_typec_port, bool on) 151 + static int qcom_pmic_typec_port_vbus_toggle(struct pmic_typec_port *pmic_typec_port, bool on) 293 152 { 294 153 u32 sm_stat; 295 154 u32 val; ··· 320 179 return 0; 321 180 } 322 181 323 - int qcom_pmic_typec_port_get_cc(struct pmic_typec_port *pmic_typec_port, 324 - enum typec_cc_status *cc1, 325 - enum typec_cc_status *cc2) 182 + static int qcom_pmic_typec_port_get_vbus(struct tcpc_dev *tcpc) 326 183 { 184 + struct pmic_typec *tcpm = tcpc_to_tcpm(tcpc); 185 + struct pmic_typec_port *pmic_typec_port = tcpm->pmic_typec_port; 186 + int ret; 187 + 188 + mutex_lock(&pmic_typec_port->vbus_lock); 189 + ret = pmic_typec_port->vbus_enabled || qcom_pmic_typec_port_vbus_detect(pmic_typec_port); 190 + mutex_unlock(&pmic_typec_port->vbus_lock); 191 + 192 + return ret; 193 + } 194 + 195 + static int qcom_pmic_typec_port_set_vbus(struct tcpc_dev *tcpc, bool on, bool sink) 196 + { 197 + struct pmic_typec *tcpm = tcpc_to_tcpm(tcpc); 198 + struct pmic_typec_port *pmic_typec_port = tcpm->pmic_typec_port; 199 + int ret = 0; 200 + 201 + mutex_lock(&pmic_typec_port->vbus_lock); 202 + if (pmic_typec_port->vbus_enabled == on) 203 + goto done; 204 + 205 + ret = qcom_pmic_typec_port_vbus_toggle(pmic_typec_port, on); 206 + if (ret) 207 + goto done; 208 + 209 + pmic_typec_port->vbus_enabled = on; 210 + tcpm_vbus_change(tcpm->tcpm_port); 211 + 212 + done: 213 + dev_dbg(tcpm->dev, "set_vbus set: %d result %d\n", on, ret); 214 + mutex_unlock(&pmic_typec_port->vbus_lock); 215 + 216 + return ret; 217 + } 218 + 219 + static int qcom_pmic_typec_port_get_cc(struct tcpc_dev *tcpc, 220 + enum typec_cc_status *cc1, 221 + enum typec_cc_status *cc2) 222 + { 223 + struct pmic_typec *tcpm = tcpc_to_tcpm(tcpc); 224 + struct pmic_typec_port *pmic_typec_port = tcpm->pmic_typec_port; 327 225 struct device *dev = pmic_typec_port->dev; 328 226 unsigned int misc, val; 329 227 bool attached; ··· 455 275 msecs_to_jiffies(2)); 456 276 } 457 277 458 - int qcom_pmic_typec_port_set_cc(struct pmic_typec_port *pmic_typec_port, 459 - enum typec_cc_status cc) 278 + static int qcom_pmic_typec_port_set_cc(struct tcpc_dev *tcpc, 279 + enum typec_cc_status cc) 460 280 { 281 + struct pmic_typec *tcpm = tcpc_to_tcpm(tcpc); 282 + struct pmic_typec_port *pmic_typec_port = tcpm->pmic_typec_port; 461 283 struct device *dev = pmic_typec_port->dev; 462 284 unsigned int mode, currsrc; 463 285 unsigned int misc; ··· 523 341 return ret; 524 342 } 525 343 526 - int qcom_pmic_typec_port_set_vconn(struct pmic_typec_port *pmic_typec_port, bool on) 344 + static int qcom_pmic_typec_port_set_polarity(struct tcpc_dev *tcpc, 345 + enum typec_cc_polarity pol) 527 346 { 347 + /* Polarity is set separately by phy-qcom-qmp.c */ 348 + return 0; 349 + } 350 + 351 + static int qcom_pmic_typec_port_set_vconn(struct tcpc_dev *tcpc, bool on) 352 + { 353 + struct pmic_typec *tcpm = tcpc_to_tcpm(tcpc); 354 + struct pmic_typec_port *pmic_typec_port = tcpm->pmic_typec_port; 528 355 struct device *dev = pmic_typec_port->dev; 529 356 unsigned int orientation, misc, mask, value; 530 357 unsigned long flags; ··· 568 377 return ret; 569 378 } 570 379 571 - int qcom_pmic_typec_port_start_toggling(struct pmic_typec_port *pmic_typec_port, 572 - enum typec_port_type port_type, 573 - enum typec_cc_status cc) 380 + static int qcom_pmic_typec_port_start_toggling(struct tcpc_dev *tcpc, 381 + enum typec_port_type port_type, 382 + enum typec_cc_status cc) 574 383 { 384 + struct pmic_typec *tcpm = tcpc_to_tcpm(tcpc); 385 + struct pmic_typec_port *pmic_typec_port = tcpm->pmic_typec_port; 575 386 struct device *dev = pmic_typec_port->dev; 576 387 unsigned int misc; 577 388 u8 mode = 0; ··· 634 441 (TYPEC_STATE_MACHINE_CHANGE_INT_EN | TYPEC_VBUS_ERROR_INT_EN | \ 635 442 TYPEC_DEBOUNCE_DONE_INT_EN) 636 443 637 - int qcom_pmic_typec_port_start(struct pmic_typec_port *pmic_typec_port, 638 - struct tcpm_port *tcpm_port) 444 + static int qcom_pmic_typec_port_start(struct pmic_typec *tcpm, 445 + struct tcpm_port *tcpm_port) 639 446 { 447 + struct pmic_typec_port *pmic_typec_port = tcpm->pmic_typec_port; 640 448 int i; 641 449 int mask; 642 450 int ret; ··· 685 491 return ret; 686 492 } 687 493 688 - void qcom_pmic_typec_port_stop(struct pmic_typec_port *pmic_typec_port) 494 + static void qcom_pmic_typec_port_stop(struct pmic_typec *tcpm) 689 495 { 496 + struct pmic_typec_port *pmic_typec_port = tcpm->pmic_typec_port; 690 497 int i; 691 498 692 499 for (i = 0; i < pmic_typec_port->nr_irqs; i++) 693 500 disable_irq(pmic_typec_port->irq_data[i].irq); 694 501 } 695 502 696 - struct pmic_typec_port *qcom_pmic_typec_port_alloc(struct device *dev) 697 - { 698 - return devm_kzalloc(dev, sizeof(struct pmic_typec_port), GFP_KERNEL); 699 - } 700 - 701 503 int qcom_pmic_typec_port_probe(struct platform_device *pdev, 702 - struct pmic_typec_port *pmic_typec_port, 703 - struct pmic_typec_port_resources *res, 504 + struct pmic_typec *tcpm, 505 + const struct pmic_typec_port_resources *res, 704 506 struct regmap *regmap, 705 507 u32 base) 706 508 { 707 509 struct device *dev = &pdev->dev; 708 510 struct pmic_typec_port_irq_data *irq_data; 511 + struct pmic_typec_port *pmic_typec_port; 709 512 int i, ret, irq; 513 + 514 + pmic_typec_port = devm_kzalloc(dev, sizeof(*pmic_typec_port), GFP_KERNEL); 515 + if (!pmic_typec_port) 516 + return -ENOMEM; 710 517 711 518 if (!res->nr_irqs || res->nr_irqs > PMIC_TYPEC_MAX_IRQS) 712 519 return -EINVAL; ··· 716 521 GFP_KERNEL); 717 522 if (!irq_data) 718 523 return -ENOMEM; 524 + 525 + mutex_init(&pmic_typec_port->vbus_lock); 719 526 720 527 pmic_typec_port->vdd_vbus = devm_regulator_get(dev, "vdd-vbus"); 721 528 if (IS_ERR(pmic_typec_port->vdd_vbus)) ··· 753 556 return ret; 754 557 } 755 558 559 + tcpm->pmic_typec_port = pmic_typec_port; 560 + 561 + tcpm->tcpc.get_vbus = qcom_pmic_typec_port_get_vbus; 562 + tcpm->tcpc.set_vbus = qcom_pmic_typec_port_set_vbus; 563 + tcpm->tcpc.set_cc = qcom_pmic_typec_port_set_cc; 564 + tcpm->tcpc.get_cc = qcom_pmic_typec_port_get_cc; 565 + tcpm->tcpc.set_polarity = qcom_pmic_typec_port_set_polarity; 566 + tcpm->tcpc.set_vconn = qcom_pmic_typec_port_set_vconn; 567 + tcpm->tcpc.start_toggling = qcom_pmic_typec_port_start_toggling; 568 + 569 + tcpm->port_start = qcom_pmic_typec_port_start; 570 + tcpm->port_stop = qcom_pmic_typec_port_stop; 571 + 756 572 return 0; 757 573 } 574 + 575 + const struct pmic_typec_port_resources pm8150b_port_res = { 576 + .irq_params = { 577 + { 578 + .irq_name = "vpd-detect", 579 + .virq = PMIC_TYPEC_VPD_IRQ, 580 + }, 581 + 582 + { 583 + .irq_name = "cc-state-change", 584 + .virq = PMIC_TYPEC_CC_STATE_IRQ, 585 + }, 586 + { 587 + .irq_name = "vconn-oc", 588 + .virq = PMIC_TYPEC_VCONN_OC_IRQ, 589 + }, 590 + 591 + { 592 + .irq_name = "vbus-change", 593 + .virq = PMIC_TYPEC_VBUS_IRQ, 594 + }, 595 + 596 + { 597 + .irq_name = "attach-detach", 598 + .virq = PMIC_TYPEC_ATTACH_DETACH_IRQ, 599 + }, 600 + { 601 + .irq_name = "legacy-cable-detect", 602 + .virq = PMIC_TYPEC_LEGACY_CABLE_IRQ, 603 + }, 604 + 605 + { 606 + .irq_name = "try-snk-src-detect", 607 + .virq = PMIC_TYPEC_TRY_SNK_SRC_IRQ, 608 + }, 609 + }, 610 + .nr_irqs = 7, 611 + };
+6 -166
drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.h
··· 3 3 * Copyright (c) 2018-2019 The Linux Foundation. All rights reserved. 4 4 * Copyright (c) 2023, Linaro Ltd. All rights reserved. 5 5 */ 6 - #ifndef __QCOM_PMIC_TYPEC_H__ 7 - #define __QCOM_PMIC_TYPEC_H__ 6 + #ifndef __QCOM_PMIC_TYPEC_PORT_H__ 7 + #define __QCOM_PMIC_TYPEC_PORT_H__ 8 8 9 9 #include <linux/platform_device.h> 10 10 #include <linux/usb/tcpm.h> 11 - 12 - #define TYPEC_SNK_STATUS_REG 0x06 13 - #define DETECTED_SNK_TYPE_MASK GENMASK(6, 0) 14 - #define SNK_DAM_MASK GENMASK(6, 4) 15 - #define SNK_DAM_500MA BIT(6) 16 - #define SNK_DAM_1500MA BIT(5) 17 - #define SNK_DAM_3000MA BIT(4) 18 - #define SNK_RP_STD BIT(3) 19 - #define SNK_RP_1P5 BIT(2) 20 - #define SNK_RP_3P0 BIT(1) 21 - #define SNK_RP_SHORT BIT(0) 22 - 23 - #define TYPEC_SRC_STATUS_REG 0x08 24 - #define DETECTED_SRC_TYPE_MASK GENMASK(4, 0) 25 - #define SRC_HIGH_BATT BIT(5) 26 - #define SRC_DEBUG_ACCESS BIT(4) 27 - #define SRC_RD_OPEN BIT(3) 28 - #define SRC_RD_RA_VCONN BIT(2) 29 - #define SRC_RA_OPEN BIT(1) 30 - #define AUDIO_ACCESS_RA_RA BIT(0) 31 - 32 - #define TYPEC_STATE_MACHINE_STATUS_REG 0x09 33 - #define TYPEC_ATTACH_DETACH_STATE BIT(5) 34 - 35 - #define TYPEC_SM_STATUS_REG 0x0A 36 - #define TYPEC_SM_VBUS_VSAFE5V BIT(5) 37 - #define TYPEC_SM_VBUS_VSAFE0V BIT(6) 38 - #define TYPEC_SM_USBIN_LT_LV BIT(7) 39 - 40 - #define TYPEC_MISC_STATUS_REG 0x0B 41 - #define TYPEC_WATER_DETECTION_STATUS BIT(7) 42 - #define SNK_SRC_MODE BIT(6) 43 - #define TYPEC_VBUS_DETECT BIT(5) 44 - #define TYPEC_VBUS_ERROR_STATUS BIT(4) 45 - #define TYPEC_DEBOUNCE_DONE BIT(3) 46 - #define CC_ORIENTATION BIT(1) 47 - #define CC_ATTACHED BIT(0) 48 - 49 - #define LEGACY_CABLE_STATUS_REG 0x0D 50 - #define TYPEC_LEGACY_CABLE_STATUS BIT(1) 51 - #define TYPEC_NONCOMP_LEGACY_CABLE_STATUS BIT(0) 52 - 53 - #define TYPEC_U_USB_STATUS_REG 0x0F 54 - #define U_USB_GROUND_NOVBUS BIT(6) 55 - #define U_USB_GROUND BIT(4) 56 - #define U_USB_FMB1 BIT(3) 57 - #define U_USB_FLOAT1 BIT(2) 58 - #define U_USB_FMB2 BIT(1) 59 - #define U_USB_FLOAT2 BIT(0) 60 - 61 - #define TYPEC_MODE_CFG_REG 0x44 62 - #define TYPEC_TRY_MODE_MASK GENMASK(4, 3) 63 - #define EN_TRY_SNK BIT(4) 64 - #define EN_TRY_SRC BIT(3) 65 - #define TYPEC_POWER_ROLE_CMD_MASK GENMASK(2, 0) 66 - #define EN_SRC_ONLY BIT(2) 67 - #define EN_SNK_ONLY BIT(1) 68 - #define TYPEC_DISABLE_CMD BIT(0) 69 - 70 - #define TYPEC_VCONN_CONTROL_REG 0x46 71 - #define VCONN_EN_ORIENTATION BIT(2) 72 - #define VCONN_EN_VALUE BIT(1) 73 - #define VCONN_EN_SRC BIT(0) 74 - 75 - #define TYPEC_CCOUT_CONTROL_REG 0x48 76 - #define TYPEC_CCOUT_BUFFER_EN BIT(2) 77 - #define TYPEC_CCOUT_VALUE BIT(1) 78 - #define TYPEC_CCOUT_SRC BIT(0) 79 - 80 - #define DEBUG_ACCESS_SRC_CFG_REG 0x4C 81 - #define EN_UNORIENTED_DEBUG_ACCESS_SRC BIT(0) 82 - 83 - #define TYPE_C_CRUDE_SENSOR_CFG_REG 0x4e 84 - #define EN_SRC_CRUDE_SENSOR BIT(1) 85 - #define EN_SNK_CRUDE_SENSOR BIT(0) 86 - 87 - #define TYPEC_EXIT_STATE_CFG_REG 0x50 88 - #define BYPASS_VSAFE0V_DURING_ROLE_SWAP BIT(3) 89 - #define SEL_SRC_UPPER_REF BIT(2) 90 - #define USE_TPD_FOR_EXITING_ATTACHSRC BIT(1) 91 - #define EXIT_SNK_BASED_ON_CC BIT(0) 92 - 93 - #define TYPEC_CURRSRC_CFG_REG 0x52 94 - #define TYPEC_SRC_RP_SEL_330UA BIT(1) 95 - #define TYPEC_SRC_RP_SEL_180UA BIT(0) 96 - #define TYPEC_SRC_RP_SEL_80UA 0 97 - #define TYPEC_SRC_RP_SEL_MASK GENMASK(1, 0) 98 - 99 - #define TYPEC_INTERRUPT_EN_CFG_1_REG 0x5E 100 - #define TYPEC_LEGACY_CABLE_INT_EN BIT(7) 101 - #define TYPEC_NONCOMPLIANT_LEGACY_CABLE_INT_EN BIT(6) 102 - #define TYPEC_TRYSOURCE_DETECT_INT_EN BIT(5) 103 - #define TYPEC_TRYSINK_DETECT_INT_EN BIT(4) 104 - #define TYPEC_CCOUT_DETACH_INT_EN BIT(3) 105 - #define TYPEC_CCOUT_ATTACH_INT_EN BIT(2) 106 - #define TYPEC_VBUS_DEASSERT_INT_EN BIT(1) 107 - #define TYPEC_VBUS_ASSERT_INT_EN BIT(0) 108 - 109 - #define TYPEC_INTERRUPT_EN_CFG_2_REG 0x60 110 - #define TYPEC_SRC_BATT_HPWR_INT_EN BIT(6) 111 - #define MICRO_USB_STATE_CHANGE_INT_EN BIT(5) 112 - #define TYPEC_STATE_MACHINE_CHANGE_INT_EN BIT(4) 113 - #define TYPEC_DEBUG_ACCESS_DETECT_INT_EN BIT(3) 114 - #define TYPEC_WATER_DETECTION_INT_EN BIT(2) 115 - #define TYPEC_VBUS_ERROR_INT_EN BIT(1) 116 - #define TYPEC_DEBOUNCE_DONE_INT_EN BIT(0) 117 - 118 - #define TYPEC_DEBOUNCE_OPTION_REG 0x62 119 - #define REDUCE_TCCDEBOUNCE_TO_2MS BIT(2) 120 - 121 - #define TYPE_C_SBU_CFG_REG 0x6A 122 - #define SEL_SBU1_ISRC_VAL 0x04 123 - #define SEL_SBU2_ISRC_VAL 0x01 124 - 125 - #define TYPEC_U_USB_CFG_REG 0x70 126 - #define EN_MICRO_USB_FACTORY_MODE BIT(1) 127 - #define EN_MICRO_USB_MODE BIT(0) 128 - 129 - #define TYPEC_PMI632_U_USB_WATER_PROTECTION_CFG_REG 0x72 130 - 131 - #define TYPEC_U_USB_WATER_PROTECTION_CFG_REG 0x73 132 - #define EN_MICRO_USB_WATER_PROTECTION BIT(4) 133 - #define MICRO_USB_DETECTION_ON_TIME_CFG_MASK GENMASK(3, 2) 134 - #define MICRO_USB_DETECTION_PERIOD_CFG_MASK GENMASK(1, 0) 135 - 136 - #define TYPEC_PMI632_MICRO_USB_MODE_REG 0x73 137 - #define MICRO_USB_MODE_ONLY BIT(0) 138 - 139 - /* Interrupt numbers */ 140 - #define PMIC_TYPEC_OR_RID_IRQ 0x0 141 - #define PMIC_TYPEC_VPD_IRQ 0x1 142 - #define PMIC_TYPEC_CC_STATE_IRQ 0x2 143 - #define PMIC_TYPEC_VCONN_OC_IRQ 0x3 144 - #define PMIC_TYPEC_VBUS_IRQ 0x4 145 - #define PMIC_TYPEC_ATTACH_DETACH_IRQ 0x5 146 - #define PMIC_TYPEC_LEGACY_CABLE_IRQ 0x6 147 - #define PMIC_TYPEC_TRY_SNK_SRC_IRQ 0x7 148 11 149 12 /* Resources */ 150 13 #define PMIC_TYPEC_MAX_IRQS 0x08 ··· 19 156 20 157 struct pmic_typec_port_resources { 21 158 unsigned int nr_irqs; 22 - struct pmic_typec_port_irq_params irq_params[PMIC_TYPEC_MAX_IRQS]; 159 + const struct pmic_typec_port_irq_params irq_params[PMIC_TYPEC_MAX_IRQS]; 23 160 }; 24 161 25 162 /* API */ 26 - struct pmic_typec; 27 163 28 - struct pmic_typec_port *qcom_pmic_typec_port_alloc(struct device *dev); 164 + extern const struct pmic_typec_port_resources pm8150b_port_res; 29 165 30 166 int qcom_pmic_typec_port_probe(struct platform_device *pdev, 31 - struct pmic_typec_port *pmic_typec_port, 32 - struct pmic_typec_port_resources *res, 167 + struct pmic_typec *tcpm, 168 + const struct pmic_typec_port_resources *res, 33 169 struct regmap *regmap, 34 170 u32 base); 35 - 36 - int qcom_pmic_typec_port_start(struct pmic_typec_port *pmic_typec_port, 37 - struct tcpm_port *tcpm_port); 38 - 39 - void qcom_pmic_typec_port_stop(struct pmic_typec_port *pmic_typec_port); 40 - 41 - int qcom_pmic_typec_port_get_cc(struct pmic_typec_port *pmic_typec_port, 42 - enum typec_cc_status *cc1, 43 - enum typec_cc_status *cc2); 44 - 45 - int qcom_pmic_typec_port_set_cc(struct pmic_typec_port *pmic_typec_port, 46 - enum typec_cc_status cc); 47 - 48 - int qcom_pmic_typec_port_get_vbus(struct pmic_typec_port *pmic_typec_port); 49 - 50 - int qcom_pmic_typec_port_set_vconn(struct pmic_typec_port *pmic_typec_port, bool on); 51 - 52 - int qcom_pmic_typec_port_start_toggling(struct pmic_typec_port *pmic_typec_port, 53 - enum typec_port_type port_type, 54 - enum typec_cc_status cc); 55 - 56 - int qcom_pmic_typec_port_set_vbus(struct pmic_typec_port *pmic_typec_port, bool on); 57 171 58 172 #endif /* __QCOM_PMIC_TYPE_C_PORT_H__ */
+25 -2
drivers/usb/typec/tcpm/tcpci.c
··· 445 445 unsigned int reg = 0; 446 446 int ret; 447 447 448 - if (enable) 448 + if (enable) { 449 449 reg = TCPC_RX_DETECT_SOP | TCPC_RX_DETECT_HARD_RESET; 450 + if (tcpci->data->cable_comm_capable) 451 + reg |= TCPC_RX_DETECT_SOP1; 452 + } 450 453 ret = regmap_write(tcpci->regmap, TCPC_RX_DETECT, reg); 451 454 if (ret < 0) 452 455 return ret; ··· 587 584 return 0; 588 585 } 589 586 587 + static bool tcpci_cable_comm_capable(struct tcpc_dev *tcpc) 588 + { 589 + struct tcpci *tcpci = tcpc_to_tcpci(tcpc); 590 + 591 + return tcpci->data->cable_comm_capable; 592 + } 593 + 594 + static bool tcpci_attempt_vconn_swap_discovery(struct tcpc_dev *tcpc) 595 + { 596 + struct tcpci *tcpci = tcpc_to_tcpci(tcpc); 597 + 598 + if (tcpci->data->attempt_vconn_swap_discovery) 599 + return tcpci->data->attempt_vconn_swap_discovery(tcpci, tcpci->data); 600 + 601 + return false; 602 + } 603 + 590 604 static int tcpci_init(struct tcpc_dev *tcpc) 591 605 { 592 606 struct tcpci *tcpci = tcpc_to_tcpci(tcpc); ··· 732 712 /* Read complete, clear RX status alert bit */ 733 713 tcpci_write16(tcpci, TCPC_ALERT, TCPC_ALERT_RX_STATUS); 734 714 735 - tcpm_pd_receive(tcpci->port, &msg); 715 + tcpm_pd_receive(tcpci->port, &msg, TCPC_TX_SOP); 736 716 } 737 717 738 718 if (tcpci->data->vbus_vsafe0v && (status & TCPC_ALERT_EXTENDED_STATUS)) { ··· 813 793 tcpci->tcpc.enable_frs = tcpci_enable_frs; 814 794 tcpci->tcpc.frs_sourcing_vbus = tcpci_frs_sourcing_vbus; 815 795 tcpci->tcpc.set_partner_usb_comm_capable = tcpci_set_partner_usb_comm_capable; 796 + tcpci->tcpc.cable_comm_capable = tcpci_cable_comm_capable; 797 + tcpci->tcpc.attempt_vconn_swap_discovery = tcpci_attempt_vconn_swap_discovery; 816 798 817 799 if (tcpci->data->check_contaminant) 818 800 tcpci->tcpc.check_contaminant = tcpci_check_contaminant; ··· 911 889 #ifdef CONFIG_OF 912 890 static const struct of_device_id tcpci_of_match[] = { 913 891 { .compatible = "nxp,ptn5110", }, 892 + { .compatible = "tcpci", }, 914 893 {}, 915 894 }; 916 895 MODULE_DEVICE_TABLE(of, tcpci_of_match);
+1
drivers/usb/typec/tcpm/tcpci_maxim.h
··· 62 62 struct i2c_client *client; 63 63 struct tcpm_port *port; 64 64 enum contamiant_state contaminant_state; 65 + bool veto_vconn_swap; 65 66 }; 66 67 67 68 static inline int max_tcpci_read16(struct max_tcpci_chip *chip, unsigned int reg, u16 *val)
+34 -4
drivers/usb/typec/tcpm/tcpci_maxim_core.c
··· 128 128 u8 count, frame_type, rx_buf[TCPC_RECEIVE_BUFFER_LEN]; 129 129 int ret, payload_index; 130 130 u8 *rx_buf_ptr; 131 + enum tcpm_transmit_type rx_type; 131 132 132 133 /* 133 134 * READABLE_BYTE_COUNT: Indicates the number of bytes in the RX_BUF_BYTE_x registers ··· 144 143 count = rx_buf[TCPC_RECEIVE_BUFFER_COUNT_OFFSET]; 145 144 frame_type = rx_buf[TCPC_RECEIVE_BUFFER_FRAME_TYPE_OFFSET]; 146 145 147 - if (count == 0 || frame_type != TCPC_RX_BUF_FRAME_TYPE_SOP) { 146 + switch (frame_type) { 147 + case TCPC_RX_BUF_FRAME_TYPE_SOP1: 148 + rx_type = TCPC_TX_SOP_PRIME; 149 + break; 150 + case TCPC_RX_BUF_FRAME_TYPE_SOP: 151 + rx_type = TCPC_TX_SOP; 152 + break; 153 + default: 154 + rx_type = TCPC_TX_SOP; 155 + break; 156 + } 157 + 158 + if (count == 0 || (frame_type != TCPC_RX_BUF_FRAME_TYPE_SOP && 159 + frame_type != TCPC_RX_BUF_FRAME_TYPE_SOP1)) { 148 160 max_tcpci_write16(chip, TCPC_ALERT, TCPC_ALERT_RX_STATUS); 149 161 dev_err(chip->dev, "%s\n", count == 0 ? "error: count is 0" : 150 - "error frame_type is not SOP"); 162 + "error frame_type is not SOP/SOP'"); 151 163 return; 152 164 } 153 165 ··· 197 183 if (ret < 0) 198 184 return; 199 185 200 - tcpm_pd_receive(chip->port, &msg); 186 + tcpm_pd_receive(chip->port, &msg, rx_type); 201 187 } 202 188 203 189 static int max_tcpci_set_vbus(struct tcpci *tcpci, struct tcpci_data *tdata, bool source, bool sink) ··· 323 309 if (ret < 0) 324 310 return ret; 325 311 326 - if (reg_status & TCPC_FAULT_STATUS_VCONN_OC) 312 + if (reg_status & TCPC_FAULT_STATUS_VCONN_OC) { 313 + chip->veto_vconn_swap = true; 327 314 tcpm_port_error_recovery(chip->port); 315 + } 328 316 } 329 317 330 318 if (status & TCPC_ALERT_EXTND) { ··· 460 444 tcpm_port_clean(chip->port); 461 445 } 462 446 447 + static bool max_tcpci_attempt_vconn_swap_discovery(struct tcpci *tcpci, struct tcpci_data *tdata) 448 + { 449 + struct max_tcpci_chip *chip = tdata_to_max_tcpci(tdata); 450 + 451 + if (chip->veto_vconn_swap) { 452 + chip->veto_vconn_swap = false; 453 + return false; 454 + } 455 + 456 + return true; 457 + } 458 + 463 459 static int max_tcpci_probe(struct i2c_client *client) 464 460 { 465 461 int ret; ··· 506 478 chip->data.vbus_vsafe0v = true; 507 479 chip->data.set_partner_usb_comm_capable = max_tcpci_set_partner_usb_comm_capable; 508 480 chip->data.check_contaminant = max_tcpci_check_contaminant; 481 + chip->data.cable_comm_capable = true; 482 + chip->data.attempt_vconn_swap_discovery = max_tcpci_attempt_vconn_swap_discovery; 509 483 510 484 max_tcpci_init_regs(chip); 511 485 chip->tcpci = tcpci_register_port(chip->dev, &chip->data);
+898 -152
drivers/usb/typec/tcpm/tcpm.c
··· 108 108 S(VCONN_SWAP_WAIT_FOR_VCONN), \ 109 109 S(VCONN_SWAP_TURN_ON_VCONN), \ 110 110 S(VCONN_SWAP_TURN_OFF_VCONN), \ 111 + S(VCONN_SWAP_SEND_SOFT_RESET), \ 111 112 \ 112 113 S(FR_SWAP_SEND), \ 113 114 S(FR_SWAP_SEND_TIMEOUT), \ ··· 146 145 S(PORT_RESET_WAIT_OFF), \ 147 146 \ 148 147 S(AMS_START), \ 149 - S(CHUNK_NOT_SUPP) 148 + S(CHUNK_NOT_SUPP), \ 149 + \ 150 + S(SRC_VDM_IDENTITY_REQUEST) 150 151 151 152 #define FOREACH_AMS(S) \ 152 153 S(NONE_AMS), \ ··· 330 327 struct typec_partner_desc partner_desc; 331 328 struct typec_partner *partner; 332 329 330 + struct usb_pd_identity cable_ident; 331 + struct typec_cable_desc cable_desc; 332 + struct typec_cable *cable; 333 + struct typec_plug_desc plug_prime_desc; 334 + struct typec_plug *plug_prime; 335 + 333 336 enum typec_cc_status cc_req; 334 337 enum typec_cc_status src_rp; /* work only if pd_supported == false */ 335 338 ··· 477 468 478 469 /* Alternate mode data */ 479 470 struct pd_mode_data mode_data; 471 + struct pd_mode_data mode_data_prime; 480 472 struct typec_altmode *partner_altmode[ALTMODE_DISCOVERY_MAX]; 473 + struct typec_altmode *plug_prime_altmode[ALTMODE_DISCOVERY_MAX]; 481 474 struct typec_altmode *port_altmode[ALTMODE_DISCOVERY_MAX]; 482 475 483 476 /* Deadline in jiffies to exit src_try_wait state */ ··· 516 505 * transitions. 517 506 */ 518 507 bool potential_contaminant; 508 + 509 + /* SOP* Related Fields */ 510 + /* 511 + * Flag to determine if SOP' Discover Identity is available. The flag 512 + * is set if Discover Identity on SOP' does not immediately follow 513 + * Discover Identity on SOP. 514 + */ 515 + bool send_discover_prime; 516 + /* 517 + * tx_sop_type determines which SOP* a message is being sent on. 518 + * For messages that are queued and not sent immediately such as in 519 + * tcpm_queue_message or messages that send after state changes, 520 + * the tx_sop_type is set accordingly. 521 + */ 522 + enum tcpm_transmit_type tx_sop_type; 523 + /* 524 + * Prior to discovering the port partner's Specification Revision, the 525 + * Vconn source and cable plug will use the lower of their two revisions. 526 + * 527 + * When the port partner's Specification Revision is discovered, the following 528 + * rules are put in place. 529 + * 1. If the cable revision (1) is lower than the revision negotiated 530 + * between the port and partner (2), the port and partner will communicate 531 + * on revision (2), but the port and cable will communicate on revision (1). 532 + * 2. If the cable revision (1) is higher than the revision negotiated 533 + * between the port and partner (2), the port and partner will communicate 534 + * on revision (2), and the port and cable will communicate on revision (2) 535 + * as well. 536 + */ 537 + unsigned int negotiated_rev_prime; 538 + /* 539 + * Each SOP* type must maintain their own tx and rx message IDs 540 + */ 541 + unsigned int message_id_prime; 542 + unsigned int rx_msgid_prime; 519 543 #ifdef CONFIG_DEBUG_FS 520 544 struct dentry *dentry; 521 545 struct mutex logbuffer_lock; /* log buffer access lock */ ··· 564 518 struct kthread_work work; 565 519 struct tcpm_port *port; 566 520 struct pd_message msg; 521 + enum tcpm_transmit_type rx_sop_type; 567 522 }; 568 523 569 524 static const char * const pd_rev[] = { ··· 940 893 } 941 894 942 895 static int tcpm_pd_transmit(struct tcpm_port *port, 943 - enum tcpm_transmit_type type, 896 + enum tcpm_transmit_type tx_sop_type, 944 897 const struct pd_message *msg) 945 898 { 946 899 unsigned long timeout; 947 900 int ret; 901 + unsigned int negotiated_rev; 902 + 903 + switch (tx_sop_type) { 904 + case TCPC_TX_SOP_PRIME: 905 + negotiated_rev = port->negotiated_rev_prime; 906 + break; 907 + case TCPC_TX_SOP: 908 + default: 909 + negotiated_rev = port->negotiated_rev; 910 + break; 911 + } 948 912 949 913 if (msg) 950 914 tcpm_log(port, "PD TX, header: %#x", le16_to_cpu(msg->header)); 951 915 else 952 - tcpm_log(port, "PD TX, type: %#x", type); 916 + tcpm_log(port, "PD TX, type: %#x", tx_sop_type); 953 917 954 918 reinit_completion(&port->tx_complete); 955 - ret = port->tcpc->pd_transmit(port->tcpc, type, msg, port->negotiated_rev); 919 + ret = port->tcpc->pd_transmit(port->tcpc, tx_sop_type, msg, negotiated_rev); 956 920 if (ret < 0) 957 921 return ret; 958 922 ··· 976 918 977 919 switch (port->tx_status) { 978 920 case TCPC_TX_SUCCESS: 979 - port->message_id = (port->message_id + 1) & PD_HEADER_ID_MASK; 921 + switch (tx_sop_type) { 922 + case TCPC_TX_SOP_PRIME: 923 + port->message_id_prime = (port->message_id_prime + 1) & 924 + PD_HEADER_ID_MASK; 925 + break; 926 + case TCPC_TX_SOP: 927 + default: 928 + port->message_id = (port->message_id + 1) & 929 + PD_HEADER_ID_MASK; 930 + break; 931 + } 980 932 /* 981 933 * USB PD rev 2.0, 8.3.2.2.1: 982 934 * USB PD rev 3.0, 8.3.2.1.3: ··· 1166 1098 ret = port->tcpc->set_roles(port->tcpc, attached, role, data); 1167 1099 if (ret < 0) 1168 1100 return ret; 1101 + 1102 + if (port->tcpc->set_orientation) { 1103 + ret = port->tcpc->set_orientation(port->tcpc, orientation); 1104 + if (ret < 0) 1105 + return ret; 1106 + } 1169 1107 1170 1108 port->pwr_role = role; 1171 1109 port->data_role = data; ··· 1530 1456 * VDM/VDO handling functions 1531 1457 */ 1532 1458 static void tcpm_queue_vdm(struct tcpm_port *port, const u32 header, 1533 - const u32 *data, int cnt) 1459 + const u32 *data, int cnt, enum tcpm_transmit_type tx_sop_type) 1534 1460 { 1535 1461 u32 vdo_hdr = port->vdo_data[0]; 1536 1462 ··· 1538 1464 1539 1465 /* If is sending discover_identity, handle received message first */ 1540 1466 if (PD_VDO_SVDM(vdo_hdr) && PD_VDO_CMD(vdo_hdr) == CMD_DISCOVER_IDENT) { 1541 - port->send_discover = true; 1467 + if (tx_sop_type == TCPC_TX_SOP_PRIME) 1468 + port->send_discover_prime = true; 1469 + else 1470 + port->send_discover = true; 1542 1471 mod_send_discover_delayed_work(port, SEND_DISCOVER_RETRY_MS); 1543 1472 } else { 1544 1473 /* Make sure we are not still processing a previous VDM packet */ ··· 1556 1479 port->vdm_state = VDM_STATE_READY; 1557 1480 port->vdm_sm_running = true; 1558 1481 1482 + port->tx_sop_type = tx_sop_type; 1483 + 1559 1484 mod_vdm_delayed_work(port, 0); 1560 1485 } 1561 1486 1562 1487 static void tcpm_queue_vdm_unlocked(struct tcpm_port *port, const u32 header, 1563 - const u32 *data, int cnt) 1488 + const u32 *data, int cnt, enum tcpm_transmit_type tx_sop_type) 1564 1489 { 1565 1490 mutex_lock(&port->lock); 1566 - tcpm_queue_vdm(port, header, data, cnt); 1491 + tcpm_queue_vdm(port, header, data, cnt, TCPC_TX_SOP); 1567 1492 mutex_unlock(&port->lock); 1568 1493 } 1569 1494 ··· 1587 1508 PD_PRODUCT_PID(product), product & 0xffff); 1588 1509 } 1589 1510 1590 - static bool svdm_consume_svids(struct tcpm_port *port, const u32 *p, int cnt) 1511 + static void svdm_consume_identity_sop_prime(struct tcpm_port *port, const u32 *p, int cnt) 1591 1512 { 1592 - struct pd_mode_data *pmdata = &port->mode_data; 1513 + u32 idh = p[VDO_INDEX_IDH]; 1514 + u32 product = p[VDO_INDEX_PRODUCT]; 1515 + int svdm_version; 1516 + 1517 + /* 1518 + * Attempt to consume identity only if cable currently is not set 1519 + */ 1520 + if (!IS_ERR_OR_NULL(port->cable)) 1521 + goto register_plug; 1522 + 1523 + /* Reset cable identity */ 1524 + memset(&port->cable_ident, 0, sizeof(port->cable_ident)); 1525 + 1526 + /* Fill out id header, cert, product, cable VDO 1 */ 1527 + port->cable_ident.id_header = idh; 1528 + port->cable_ident.cert_stat = p[VDO_INDEX_CSTAT]; 1529 + port->cable_ident.product = product; 1530 + port->cable_ident.vdo[0] = p[VDO_INDEX_CABLE_1]; 1531 + 1532 + /* Fill out cable desc, infer svdm_version from pd revision */ 1533 + port->cable_desc.type = (enum typec_plug_type) (VDO_TYPEC_CABLE_TYPE(p[VDO_INDEX_CABLE_1]) + 1534 + USB_PLUG_TYPE_A); 1535 + port->cable_desc.active = PD_IDH_PTYPE(idh) == IDH_PTYPE_ACABLE ? 1 : 0; 1536 + /* Log PD Revision and additional cable VDO from negotiated revision */ 1537 + switch (port->negotiated_rev_prime) { 1538 + case PD_REV30: 1539 + port->cable_desc.pd_revision = 0x0300; 1540 + if (port->cable_desc.active) 1541 + port->cable_ident.vdo[1] = p[VDO_INDEX_CABLE_2]; 1542 + break; 1543 + case PD_REV20: 1544 + port->cable_desc.pd_revision = 0x0200; 1545 + break; 1546 + default: 1547 + port->cable_desc.pd_revision = 0x0200; 1548 + break; 1549 + } 1550 + port->cable_desc.identity = &port->cable_ident; 1551 + /* Register Cable, set identity and svdm_version */ 1552 + port->cable = typec_register_cable(port->typec_port, &port->cable_desc); 1553 + if (IS_ERR_OR_NULL(port->cable)) 1554 + return; 1555 + typec_cable_set_identity(port->cable); 1556 + /* Get SVDM version */ 1557 + svdm_version = PD_VDO_SVDM_VER(p[VDO_INDEX_HDR]); 1558 + typec_cable_set_svdm_version(port->cable, svdm_version); 1559 + 1560 + register_plug: 1561 + if (IS_ERR_OR_NULL(port->plug_prime)) { 1562 + port->plug_prime_desc.index = TYPEC_PLUG_SOP_P; 1563 + port->plug_prime = typec_register_plug(port->cable, 1564 + &port->plug_prime_desc); 1565 + } 1566 + } 1567 + 1568 + static bool svdm_consume_svids(struct tcpm_port *port, const u32 *p, int cnt, 1569 + enum tcpm_transmit_type rx_sop_type) 1570 + { 1571 + struct pd_mode_data *pmdata = rx_sop_type == TCPC_TX_SOP_PRIME ? 1572 + &port->mode_data_prime : &port->mode_data; 1593 1573 int i; 1594 1574 1595 1575 for (i = 1; i < cnt; i++) { ··· 1694 1556 return false; 1695 1557 } 1696 1558 1697 - static void svdm_consume_modes(struct tcpm_port *port, const u32 *p, int cnt) 1559 + static void svdm_consume_modes(struct tcpm_port *port, const u32 *p, int cnt, 1560 + enum tcpm_transmit_type rx_sop_type) 1698 1561 { 1699 1562 struct pd_mode_data *pmdata = &port->mode_data; 1700 1563 struct typec_altmode_desc *paltmode; 1701 1564 int i; 1702 1565 1703 - if (pmdata->altmodes >= ARRAY_SIZE(port->partner_altmode)) { 1704 - /* Already logged in svdm_consume_svids() */ 1566 + switch (rx_sop_type) { 1567 + case TCPC_TX_SOP_PRIME: 1568 + pmdata = &port->mode_data_prime; 1569 + if (pmdata->altmodes >= ARRAY_SIZE(port->plug_prime_altmode)) { 1570 + /* Already logged in svdm_consume_svids() */ 1571 + return; 1572 + } 1573 + break; 1574 + case TCPC_TX_SOP: 1575 + pmdata = &port->mode_data; 1576 + if (pmdata->altmodes >= ARRAY_SIZE(port->partner_altmode)) { 1577 + /* Already logged in svdm_consume_svids() */ 1578 + return; 1579 + } 1580 + break; 1581 + default: 1705 1582 return; 1706 1583 } 1707 1584 ··· 1754 1601 } 1755 1602 } 1756 1603 1604 + static void tcpm_register_plug_altmodes(struct tcpm_port *port) 1605 + { 1606 + struct pd_mode_data *modep = &port->mode_data_prime; 1607 + struct typec_altmode *altmode; 1608 + int i; 1609 + 1610 + typec_plug_set_num_altmodes(port->plug_prime, modep->altmodes); 1611 + 1612 + for (i = 0; i < modep->altmodes; i++) { 1613 + altmode = typec_plug_register_altmode(port->plug_prime, 1614 + &modep->altmode_desc[i]); 1615 + if (IS_ERR(altmode)) { 1616 + tcpm_log(port, "Failed to register plug SVID 0x%04x", 1617 + modep->altmode_desc[i].svid); 1618 + altmode = NULL; 1619 + } 1620 + port->plug_prime_altmode[i] = altmode; 1621 + } 1622 + } 1623 + 1757 1624 #define supports_modal(port) PD_IDH_MODAL_SUPP((port)->partner_ident.id_header) 1625 + #define supports_modal_cable(port) PD_IDH_MODAL_SUPP((port)->cable_ident.id_header) 1626 + #define supports_host(port) PD_IDH_HOST_SUPP((port->partner_ident.id_header)) 1627 + 1628 + /* 1629 + * Helper to determine whether the port is capable of SOP' communication at the 1630 + * current point in time. 1631 + */ 1632 + static bool tcpm_can_communicate_sop_prime(struct tcpm_port *port) 1633 + { 1634 + /* Check to see if tcpc supports SOP' communication */ 1635 + if (!port->tcpc->cable_comm_capable || !port->tcpc->cable_comm_capable(port->tcpc)) 1636 + return false; 1637 + /* 1638 + * Power Delivery 2.0 Section 6.3.11 1639 + * Before communicating with a Cable Plug a Port Should ensure that it 1640 + * is the Vconn Source and that the Cable Plugs are powered by 1641 + * performing a Vconn swap if necessary. Since it cannot be guaranteed 1642 + * that the present Vconn Source is supplying Vconn, the only means to 1643 + * ensure that the Cable Plugs are powered is for a Port wishing to 1644 + * communicate with a Cable Plug is to become the Vconn Source. 1645 + * 1646 + * Power Delivery 3.0 Section 6.3.11 1647 + * Before communicating with a Cable Plug a Port Shall ensure that it 1648 + * is the Vconn source. 1649 + */ 1650 + if (port->vconn_role != TYPEC_SOURCE) 1651 + return false; 1652 + /* 1653 + * Power Delivery 2.0 Section 2.4.4 1654 + * When no Contract or an Implicit Contract is in place the Source can 1655 + * communicate with a Cable Plug using SOP' packets in order to discover 1656 + * its characteristics. 1657 + * 1658 + * Power Delivery 3.0 Section 2.4.4 1659 + * When no Contract or an Implicit Contract is in place only the Source 1660 + * port that is supplying Vconn is allowed to send packets to a Cable 1661 + * Plug and is allowed to respond to packets from the Cable Plug. 1662 + */ 1663 + if (!port->explicit_contract) 1664 + return port->pwr_role == TYPEC_SOURCE; 1665 + if (port->negotiated_rev == PD_REV30) 1666 + return true; 1667 + /* 1668 + * Power Delivery 2.0 Section 2.4.4 1669 + * 1670 + * When an Explicit Contract is in place the DFP (either the Source or 1671 + * the Sink) can communicate with the Cable Plug(s) using SOP’/SOP” 1672 + * Packets (see Figure 2-3). 1673 + */ 1674 + if (port->negotiated_rev == PD_REV20) 1675 + return port->data_role == TYPEC_HOST; 1676 + return false; 1677 + } 1678 + 1679 + static bool tcpm_attempt_vconn_swap_discovery(struct tcpm_port *port) 1680 + { 1681 + if (!port->tcpc->attempt_vconn_swap_discovery) 1682 + return false; 1683 + 1684 + /* Port is already source, no need to perform swap */ 1685 + if (port->vconn_role == TYPEC_SOURCE) 1686 + return false; 1687 + 1688 + /* 1689 + * Partner needs to support Alternate Modes with modal support. If 1690 + * partner is also capable of being a USB Host, it could be a device 1691 + * that supports Alternate Modes as the DFP. 1692 + */ 1693 + if (!supports_modal(port) || supports_host(port)) 1694 + return false; 1695 + 1696 + if ((port->negotiated_rev == PD_REV20 && port->data_role == TYPEC_HOST) || 1697 + port->negotiated_rev == PD_REV30) 1698 + return port->tcpc->attempt_vconn_swap_discovery(port->tcpc); 1699 + 1700 + return false; 1701 + } 1702 + 1703 + 1704 + static bool tcpm_cable_vdm_supported(struct tcpm_port *port) 1705 + { 1706 + return !IS_ERR_OR_NULL(port->cable) && 1707 + typec_cable_is_active(port->cable) && 1708 + supports_modal_cable(port) && 1709 + tcpm_can_communicate_sop_prime(port); 1710 + } 1758 1711 1759 1712 static int tcpm_pd_svdm(struct tcpm_port *port, struct typec_altmode *adev, 1760 1713 const u32 *p, int cnt, u32 *response, 1761 - enum adev_actions *adev_action) 1714 + enum adev_actions *adev_action, 1715 + enum tcpm_transmit_type rx_sop_type, 1716 + enum tcpm_transmit_type *response_tx_sop_type) 1762 1717 { 1763 1718 struct typec_port *typec = port->typec_port; 1764 - struct typec_altmode *pdev; 1765 - struct pd_mode_data *modep; 1719 + struct typec_altmode *pdev, *pdev_prime; 1720 + struct pd_mode_data *modep, *modep_prime; 1766 1721 int svdm_version; 1767 1722 int rlen = 0; 1768 1723 int cmd_type; 1769 1724 int cmd; 1770 1725 int i; 1726 + int ret; 1771 1727 1772 1728 cmd_type = PD_VDO_CMDT(p[0]); 1773 1729 cmd = PD_VDO_CMD(p[0]); ··· 1884 1622 tcpm_log(port, "Rx VDM cmd 0x%x type %d cmd %d len %d", 1885 1623 p[0], cmd_type, cmd, cnt); 1886 1624 1887 - modep = &port->mode_data; 1888 - 1889 - pdev = typec_match_altmode(port->partner_altmode, ALTMODE_DISCOVERY_MAX, 1890 - PD_VDO_VID(p[0]), PD_VDO_OPOS(p[0])); 1891 - 1892 - svdm_version = typec_get_negotiated_svdm_version(typec); 1893 - if (svdm_version < 0) 1894 - return 0; 1625 + switch (rx_sop_type) { 1626 + case TCPC_TX_SOP_PRIME: 1627 + modep_prime = &port->mode_data_prime; 1628 + pdev_prime = typec_match_altmode(port->plug_prime_altmode, 1629 + ALTMODE_DISCOVERY_MAX, 1630 + PD_VDO_VID(p[0]), 1631 + PD_VDO_OPOS(p[0])); 1632 + svdm_version = typec_get_cable_svdm_version(typec); 1633 + /* 1634 + * Update SVDM version if cable was discovered before port partner. 1635 + */ 1636 + if (!IS_ERR_OR_NULL(port->cable) && 1637 + PD_VDO_SVDM_VER(p[0]) < svdm_version) 1638 + typec_cable_set_svdm_version(port->cable, svdm_version); 1639 + break; 1640 + case TCPC_TX_SOP: 1641 + modep = &port->mode_data; 1642 + pdev = typec_match_altmode(port->partner_altmode, 1643 + ALTMODE_DISCOVERY_MAX, 1644 + PD_VDO_VID(p[0]), 1645 + PD_VDO_OPOS(p[0])); 1646 + svdm_version = typec_get_negotiated_svdm_version(typec); 1647 + if (svdm_version < 0) 1648 + return 0; 1649 + break; 1650 + default: 1651 + modep = &port->mode_data; 1652 + pdev = typec_match_altmode(port->partner_altmode, 1653 + ALTMODE_DISCOVERY_MAX, 1654 + PD_VDO_VID(p[0]), 1655 + PD_VDO_OPOS(p[0])); 1656 + svdm_version = typec_get_negotiated_svdm_version(typec); 1657 + if (svdm_version < 0) 1658 + return 0; 1659 + break; 1660 + } 1895 1661 1896 1662 switch (cmd_type) { 1897 1663 case CMDT_INIT: 1664 + /* 1665 + * Only the port or port partner is allowed to initialize SVDM 1666 + * commands over SOP'. In case the port partner initializes a 1667 + * sequence when it is not allowed to send SOP' messages, drop 1668 + * the message should the TCPM port try to process it. 1669 + */ 1670 + if (rx_sop_type == TCPC_TX_SOP_PRIME) 1671 + return 0; 1672 + 1898 1673 switch (cmd) { 1899 1674 case CMD_DISCOVER_IDENT: 1900 1675 if (PD_VDO_VID(p[0]) != USB_SID_PD) ··· 1998 1699 (VDO_SVDM_VERS(typec_get_negotiated_svdm_version(typec))); 1999 1700 break; 2000 1701 case CMDT_RSP_ACK: 2001 - /* silently drop message if we are not connected */ 2002 - if (IS_ERR_OR_NULL(port->partner)) 1702 + /* 1703 + * Silently drop message if we are not connected, but can process 1704 + * if SOP' Discover Identity prior to explicit contract. 1705 + */ 1706 + if (IS_ERR_OR_NULL(port->partner) && 1707 + !(rx_sop_type == TCPC_TX_SOP_PRIME && cmd == CMD_DISCOVER_IDENT)) 2003 1708 break; 2004 1709 2005 1710 tcpm_ams_finish(port); 2006 1711 2007 1712 switch (cmd) { 1713 + /* 1714 + * SVDM Command Flow for SOP and SOP': 1715 + * SOP Discover Identity 1716 + * SOP' Discover Identity 1717 + * SOP Discover SVIDs 1718 + * Discover Modes 1719 + * (Active Cables) 1720 + * SOP' Discover SVIDs 1721 + * Discover Modes 1722 + * 1723 + * Perform Discover SOP' if the port can communicate with cable 1724 + * plug. 1725 + */ 2008 1726 case CMD_DISCOVER_IDENT: 2009 - if (PD_VDO_SVDM_VER(p[0]) < svdm_version) 2010 - typec_partner_set_svdm_version(port->partner, 2011 - PD_VDO_SVDM_VER(p[0])); 2012 - /* 6.4.4.3.1 */ 2013 - svdm_consume_identity(port, p, cnt); 2014 - response[0] = VDO(USB_SID_PD, 1, typec_get_negotiated_svdm_version(typec), 2015 - CMD_DISCOVER_SVID); 2016 - rlen = 1; 1727 + switch (rx_sop_type) { 1728 + case TCPC_TX_SOP: 1729 + if (PD_VDO_SVDM_VER(p[0]) < svdm_version) { 1730 + typec_partner_set_svdm_version(port->partner, 1731 + PD_VDO_SVDM_VER(p[0])); 1732 + /* If cable is discovered before partner, downgrade svdm */ 1733 + if (!IS_ERR_OR_NULL(port->cable) && 1734 + (typec_get_cable_svdm_version(port->typec_port) > 1735 + svdm_version)) 1736 + typec_cable_set_svdm_version(port->cable, 1737 + svdm_version); 1738 + } 1739 + /* 6.4.4.3.1 */ 1740 + svdm_consume_identity(port, p, cnt); 1741 + /* Attempt Vconn swap, delay SOP' discovery if necessary */ 1742 + if (tcpm_attempt_vconn_swap_discovery(port)) { 1743 + port->send_discover_prime = true; 1744 + port->upcoming_state = VCONN_SWAP_SEND; 1745 + ret = tcpm_ams_start(port, VCONN_SWAP); 1746 + if (!ret) 1747 + return 0; 1748 + /* Cannot perform Vconn swap */ 1749 + port->upcoming_state = INVALID_STATE; 1750 + port->send_discover_prime = false; 1751 + } 1752 + 1753 + /* 1754 + * Attempt Discover Identity on SOP' if the 1755 + * cable was not discovered previously, and use 1756 + * the SVDM version of the partner to probe. 1757 + */ 1758 + if (IS_ERR_OR_NULL(port->cable) && 1759 + tcpm_can_communicate_sop_prime(port)) { 1760 + *response_tx_sop_type = TCPC_TX_SOP_PRIME; 1761 + port->send_discover_prime = true; 1762 + response[0] = VDO(USB_SID_PD, 1, 1763 + typec_get_negotiated_svdm_version(typec), 1764 + CMD_DISCOVER_IDENT); 1765 + rlen = 1; 1766 + } else { 1767 + *response_tx_sop_type = TCPC_TX_SOP; 1768 + response[0] = VDO(USB_SID_PD, 1, 1769 + typec_get_negotiated_svdm_version(typec), 1770 + CMD_DISCOVER_SVID); 1771 + rlen = 1; 1772 + } 1773 + break; 1774 + case TCPC_TX_SOP_PRIME: 1775 + /* 1776 + * svdm_consume_identity_sop_prime will determine 1777 + * the svdm_version for the cable moving forward. 1778 + */ 1779 + svdm_consume_identity_sop_prime(port, p, cnt); 1780 + 1781 + /* 1782 + * If received in SRC_VDM_IDENTITY_REQUEST, continue 1783 + * to SRC_SEND_CAPABILITIES 1784 + */ 1785 + if (port->state == SRC_VDM_IDENTITY_REQUEST) { 1786 + tcpm_set_state(port, SRC_SEND_CAPABILITIES, 0); 1787 + return 0; 1788 + } 1789 + 1790 + *response_tx_sop_type = TCPC_TX_SOP; 1791 + response[0] = VDO(USB_SID_PD, 1, 1792 + typec_get_negotiated_svdm_version(typec), 1793 + CMD_DISCOVER_SVID); 1794 + rlen = 1; 1795 + break; 1796 + default: 1797 + return 0; 1798 + } 2017 1799 break; 2018 1800 case CMD_DISCOVER_SVID: 1801 + *response_tx_sop_type = rx_sop_type; 2019 1802 /* 6.4.4.3.2 */ 2020 - if (svdm_consume_svids(port, p, cnt)) { 1803 + if (svdm_consume_svids(port, p, cnt, rx_sop_type)) { 2021 1804 response[0] = VDO(USB_SID_PD, 1, svdm_version, CMD_DISCOVER_SVID); 2022 1805 rlen = 1; 2023 - } else if (modep->nsvids && supports_modal(port)) { 2024 - response[0] = VDO(modep->svids[0], 1, svdm_version, 2025 - CMD_DISCOVER_MODES); 2026 - rlen = 1; 1806 + } else { 1807 + if (rx_sop_type == TCPC_TX_SOP) { 1808 + if (modep->nsvids && supports_modal(port)) { 1809 + response[0] = VDO(modep->svids[0], 1, svdm_version, 1810 + CMD_DISCOVER_MODES); 1811 + rlen = 1; 1812 + } 1813 + } else if (rx_sop_type == TCPC_TX_SOP_PRIME) { 1814 + if (modep_prime->nsvids) { 1815 + response[0] = VDO(modep_prime->svids[0], 1, 1816 + svdm_version, CMD_DISCOVER_MODES); 1817 + rlen = 1; 1818 + } 1819 + } 2027 1820 } 2028 1821 break; 2029 1822 case CMD_DISCOVER_MODES: 2030 - /* 6.4.4.3.3 */ 2031 - svdm_consume_modes(port, p, cnt); 2032 - modep->svid_index++; 2033 - if (modep->svid_index < modep->nsvids) { 2034 - u16 svid = modep->svids[modep->svid_index]; 2035 - response[0] = VDO(svid, 1, svdm_version, CMD_DISCOVER_MODES); 2036 - rlen = 1; 2037 - } else { 2038 - tcpm_register_partner_altmodes(port); 1823 + if (rx_sop_type == TCPC_TX_SOP) { 1824 + /* 6.4.4.3.3 */ 1825 + svdm_consume_modes(port, p, cnt, rx_sop_type); 1826 + modep->svid_index++; 1827 + if (modep->svid_index < modep->nsvids) { 1828 + u16 svid = modep->svids[modep->svid_index]; 1829 + *response_tx_sop_type = TCPC_TX_SOP; 1830 + response[0] = VDO(svid, 1, svdm_version, 1831 + CMD_DISCOVER_MODES); 1832 + rlen = 1; 1833 + } else if (tcpm_cable_vdm_supported(port)) { 1834 + *response_tx_sop_type = TCPC_TX_SOP_PRIME; 1835 + response[0] = VDO(USB_SID_PD, 1, 1836 + typec_get_cable_svdm_version(typec), 1837 + CMD_DISCOVER_SVID); 1838 + rlen = 1; 1839 + } else { 1840 + tcpm_register_partner_altmodes(port); 1841 + } 1842 + } else if (rx_sop_type == TCPC_TX_SOP_PRIME) { 1843 + /* 6.4.4.3.3 */ 1844 + svdm_consume_modes(port, p, cnt, rx_sop_type); 1845 + modep_prime->svid_index++; 1846 + if (modep_prime->svid_index < modep_prime->nsvids) { 1847 + u16 svid = modep_prime->svids[modep_prime->svid_index]; 1848 + *response_tx_sop_type = TCPC_TX_SOP_PRIME; 1849 + response[0] = VDO(svid, 1, 1850 + typec_get_cable_svdm_version(typec), 1851 + CMD_DISCOVER_MODES); 1852 + rlen = 1; 1853 + } else { 1854 + tcpm_register_plug_altmodes(port); 1855 + tcpm_register_partner_altmodes(port); 1856 + } 2039 1857 } 2040 1858 break; 2041 1859 case CMD_ENTER_MODE: 2042 - if (adev && pdev) 2043 - *adev_action = ADEV_QUEUE_VDM_SEND_EXIT_MODE_ON_FAIL; 1860 + *response_tx_sop_type = rx_sop_type; 1861 + if (rx_sop_type == TCPC_TX_SOP) { 1862 + if (adev && pdev) { 1863 + typec_altmode_update_active(pdev, true); 1864 + *adev_action = ADEV_QUEUE_VDM_SEND_EXIT_MODE_ON_FAIL; 1865 + } 1866 + } else if (rx_sop_type == TCPC_TX_SOP_PRIME) { 1867 + if (adev && pdev_prime) { 1868 + typec_altmode_update_active(pdev_prime, true); 1869 + *adev_action = ADEV_QUEUE_VDM_SEND_EXIT_MODE_ON_FAIL; 1870 + } 1871 + } 2044 1872 return 0; 2045 1873 case CMD_EXIT_MODE: 2046 - if (adev && pdev) { 2047 - /* Back to USB Operation */ 2048 - *adev_action = ADEV_NOTIFY_USB_AND_QUEUE_VDM; 2049 - return 0; 1874 + *response_tx_sop_type = rx_sop_type; 1875 + if (rx_sop_type == TCPC_TX_SOP) { 1876 + if (adev && pdev) { 1877 + typec_altmode_update_active(pdev, false); 1878 + /* Back to USB Operation */ 1879 + *adev_action = ADEV_NOTIFY_USB_AND_QUEUE_VDM; 1880 + return 0; 1881 + } 2050 1882 } 2051 1883 break; 2052 1884 case VDO_CMD_VENDOR(0) ... VDO_CMD_VENDOR(15): ··· 2230 1800 enum tcpm_ams ams); 2231 1801 2232 1802 static void tcpm_handle_vdm_request(struct tcpm_port *port, 2233 - const __le32 *payload, int cnt) 1803 + const __le32 *payload, int cnt, 1804 + enum tcpm_transmit_type rx_sop_type) 2234 1805 { 2235 1806 enum adev_actions adev_action = ADEV_NONE; 2236 1807 struct typec_altmode *adev; 2237 1808 u32 p[PD_MAX_PAYLOAD]; 2238 1809 u32 response[8] = { }; 2239 1810 int i, rlen = 0; 1811 + enum tcpm_transmit_type response_tx_sop_type = TCPC_TX_SOP; 2240 1812 2241 1813 for (i = 0; i < cnt; i++) 2242 1814 p[i] = le32_to_cpu(payload[i]); ··· 2273 1841 * - We will send NAK and the flag will be cleared in the state machine. 2274 1842 */ 2275 1843 port->vdm_sm_running = true; 2276 - rlen = tcpm_pd_svdm(port, adev, p, cnt, response, &adev_action); 1844 + rlen = tcpm_pd_svdm(port, adev, p, cnt, response, &adev_action, 1845 + rx_sop_type, &response_tx_sop_type); 2277 1846 } else { 2278 1847 if (port->negotiated_rev >= PD_REV30) 2279 1848 tcpm_pd_handle_msg(port, PD_MSG_CTRL_NOT_SUPP, NONE_AMS); ··· 2310 1877 typec_altmode_vdm(adev, p[0], &p[1], cnt); 2311 1878 break; 2312 1879 case ADEV_QUEUE_VDM: 2313 - typec_altmode_vdm(adev, p[0], &p[1], cnt); 1880 + if (response_tx_sop_type == TCPC_TX_SOP_PRIME) 1881 + typec_cable_altmode_vdm(adev, TYPEC_PLUG_SOP_P, p[0], &p[1], cnt); 1882 + else 1883 + typec_altmode_vdm(adev, p[0], &p[1], cnt); 2314 1884 break; 2315 1885 case ADEV_QUEUE_VDM_SEND_EXIT_MODE_ON_FAIL: 2316 - if (typec_altmode_vdm(adev, p[0], &p[1], cnt)) { 2317 - int svdm_version = typec_get_negotiated_svdm_version( 2318 - port->typec_port); 2319 - if (svdm_version < 0) 2320 - break; 1886 + if (response_tx_sop_type == TCPC_TX_SOP_PRIME) { 1887 + if (typec_cable_altmode_vdm(adev, TYPEC_PLUG_SOP_P, 1888 + p[0], &p[1], cnt)) { 1889 + int svdm_version = typec_get_cable_svdm_version( 1890 + port->typec_port); 1891 + if (svdm_version < 0) 1892 + break; 2321 1893 2322 - response[0] = VDO(adev->svid, 1, svdm_version, 2323 - CMD_EXIT_MODE); 2324 - response[0] |= VDO_OPOS(adev->mode); 2325 - rlen = 1; 1894 + response[0] = VDO(adev->svid, 1, svdm_version, 1895 + CMD_EXIT_MODE); 1896 + response[0] |= VDO_OPOS(adev->mode); 1897 + rlen = 1; 1898 + } 1899 + } else { 1900 + if (typec_altmode_vdm(adev, p[0], &p[1], cnt)) { 1901 + int svdm_version = typec_get_negotiated_svdm_version( 1902 + port->typec_port); 1903 + if (svdm_version < 0) 1904 + break; 1905 + 1906 + response[0] = VDO(adev->svid, 1, svdm_version, 1907 + CMD_EXIT_MODE); 1908 + response[0] |= VDO_OPOS(adev->mode); 1909 + rlen = 1; 1910 + } 2326 1911 } 2327 1912 break; 2328 1913 case ADEV_ATTENTION: ··· 2360 1909 mutex_lock(&port->lock); 2361 1910 2362 1911 if (rlen > 0) 2363 - tcpm_queue_vdm(port, response[0], &response[1], rlen - 1); 1912 + tcpm_queue_vdm(port, response[0], &response[1], rlen - 1, response_tx_sop_type); 2364 1913 else 2365 1914 port->vdm_sm_running = false; 2366 1915 } 2367 1916 2368 1917 static void tcpm_send_vdm(struct tcpm_port *port, u32 vid, int cmd, 2369 - const u32 *data, int count) 1918 + const u32 *data, int count, enum tcpm_transmit_type tx_sop_type) 2370 1919 { 2371 - int svdm_version = typec_get_negotiated_svdm_version(port->typec_port); 1920 + int svdm_version; 2372 1921 u32 header; 2373 1922 2374 - if (svdm_version < 0) 2375 - return; 1923 + switch (tx_sop_type) { 1924 + case TCPC_TX_SOP_PRIME: 1925 + /* 1926 + * If the port partner is discovered, then the port partner's 1927 + * SVDM Version will be returned 1928 + */ 1929 + svdm_version = typec_get_cable_svdm_version(port->typec_port); 1930 + if (svdm_version < 0) 1931 + svdm_version = SVDM_VER_MAX; 1932 + break; 1933 + case TCPC_TX_SOP: 1934 + svdm_version = typec_get_negotiated_svdm_version(port->typec_port); 1935 + if (svdm_version < 0) 1936 + return; 1937 + break; 1938 + default: 1939 + svdm_version = typec_get_negotiated_svdm_version(port->typec_port); 1940 + if (svdm_version < 0) 1941 + return; 1942 + break; 1943 + } 2376 1944 2377 1945 if (WARN_ON(count > VDO_MAX_SIZE - 1)) 2378 1946 count = VDO_MAX_SIZE - 1; ··· 2400 1930 header = VDO(vid, ((vid & USB_SID_PD) == USB_SID_PD) ? 2401 1931 1 : (PD_VDO_CMD(cmd) <= CMD_ATTENTION), 2402 1932 svdm_version, cmd); 2403 - tcpm_queue_vdm(port, header, data, count); 1933 + tcpm_queue_vdm(port, header, data, count, tx_sop_type); 2404 1934 } 2405 1935 2406 1936 static unsigned int vdm_ready_timeout(u32 vdm_hdr) ··· 2434 1964 struct pd_message msg; 2435 1965 int i, res = 0; 2436 1966 u32 vdo_hdr = port->vdo_data[0]; 1967 + u32 response[8] = { }; 2437 1968 2438 1969 switch (port->vdm_state) { 2439 1970 case VDM_STATE_READY: ··· 2448 1977 * if there's traffic or we're not in PDO ready state don't send 2449 1978 * a VDM. 2450 1979 */ 2451 - if (port->state != SRC_READY && port->state != SNK_READY) { 1980 + if (port->state != SRC_READY && port->state != SNK_READY && 1981 + port->state != SRC_VDM_IDENTITY_REQUEST) { 2452 1982 port->vdm_sm_running = false; 2453 1983 break; 2454 1984 } ··· 2460 1988 case CMD_DISCOVER_IDENT: 2461 1989 res = tcpm_ams_start(port, DISCOVER_IDENTITY); 2462 1990 if (res == 0) { 2463 - port->send_discover = false; 1991 + switch (port->tx_sop_type) { 1992 + case TCPC_TX_SOP_PRIME: 1993 + port->send_discover_prime = false; 1994 + break; 1995 + case TCPC_TX_SOP: 1996 + port->send_discover = false; 1997 + break; 1998 + default: 1999 + port->send_discover = false; 2000 + break; 2001 + } 2464 2002 } else if (res == -EAGAIN) { 2465 2003 port->vdo_data[0] = 0; 2466 2004 mod_send_discover_delayed_work(port, ··· 2526 2044 break; 2527 2045 case VDM_STATE_ERR_SEND: 2528 2046 /* 2047 + * When sending Discover Identity to SOP' before establishing an 2048 + * explicit contract, do not retry. Instead, weave sending 2049 + * Source_Capabilities over SOP and Discover Identity over SOP'. 2050 + */ 2051 + if (port->state == SRC_VDM_IDENTITY_REQUEST) { 2052 + tcpm_ams_finish(port); 2053 + port->vdm_state = VDM_STATE_DONE; 2054 + tcpm_set_state(port, SRC_SEND_CAPABILITIES, 0); 2055 + /* 2529 2056 * A partner which does not support USB PD will not reply, 2530 2057 * so this is not a fatal error. At the same time, some 2531 2058 * devices may not return GoodCRC under some circumstances, 2532 2059 * so we need to retry. 2533 2060 */ 2534 - if (port->vdm_retries < 3) { 2061 + } else if (port->vdm_retries < 3) { 2535 2062 tcpm_log(port, "VDM Tx error, retry"); 2536 2063 port->vdm_retries++; 2537 2064 port->vdm_state = VDM_STATE_READY; ··· 2548 2057 tcpm_ams_finish(port); 2549 2058 } else { 2550 2059 tcpm_ams_finish(port); 2060 + if (port->tx_sop_type == TCPC_TX_SOP) 2061 + break; 2062 + /* Handle SOP' Transmission Errors */ 2063 + switch (PD_VDO_CMD(vdo_hdr)) { 2064 + /* 2065 + * If Discover Identity fails on SOP', then resume 2066 + * discovery process on SOP only. 2067 + */ 2068 + case CMD_DISCOVER_IDENT: 2069 + port->vdo_data[0] = 0; 2070 + response[0] = VDO(USB_SID_PD, 1, 2071 + typec_get_negotiated_svdm_version( 2072 + port->typec_port), 2073 + CMD_DISCOVER_SVID); 2074 + tcpm_queue_vdm(port, response[0], &response[1], 2075 + 0, TCPC_TX_SOP); 2076 + break; 2077 + /* 2078 + * If Discover SVIDs or Discover Modes fail, then 2079 + * proceed with Alt Mode discovery process on SOP. 2080 + */ 2081 + case CMD_DISCOVER_SVID: 2082 + tcpm_register_partner_altmodes(port); 2083 + break; 2084 + case CMD_DISCOVER_MODES: 2085 + tcpm_register_partner_altmodes(port); 2086 + break; 2087 + default: 2088 + break; 2089 + } 2551 2090 } 2552 2091 break; 2553 2092 case VDM_STATE_SEND_MESSAGE: 2554 2093 /* Prepare and send VDM */ 2555 2094 memset(&msg, 0, sizeof(msg)); 2556 - msg.header = PD_HEADER_LE(PD_DATA_VENDOR_DEF, 2557 - port->pwr_role, 2558 - port->data_role, 2559 - port->negotiated_rev, 2560 - port->message_id, port->vdo_count); 2095 + if (port->tx_sop_type == TCPC_TX_SOP_PRIME) { 2096 + msg.header = PD_HEADER_LE(PD_DATA_VENDOR_DEF, 2097 + 0, /* Cable Plug Indicator for DFP/UFP */ 2098 + 0, /* Reserved */ 2099 + port->negotiated_rev_prime, 2100 + port->message_id_prime, 2101 + port->vdo_count); 2102 + } else { 2103 + msg.header = PD_HEADER_LE(PD_DATA_VENDOR_DEF, 2104 + port->pwr_role, 2105 + port->data_role, 2106 + port->negotiated_rev, 2107 + port->message_id, 2108 + port->vdo_count); 2109 + } 2561 2110 for (i = 0; i < port->vdo_count; i++) 2562 2111 msg.payload[i] = cpu_to_le32(port->vdo_data[i]); 2563 - res = tcpm_pd_transmit(port, TCPC_TX_SOP, &msg); 2112 + res = tcpm_pd_transmit(port, port->tx_sop_type, &msg); 2564 2113 if (res < 0) { 2565 2114 port->vdm_state = VDM_STATE_ERR_SEND; 2566 2115 } else { ··· 2775 2244 header = VDO(altmode->svid, vdo ? 2 : 1, svdm_version, CMD_ENTER_MODE); 2776 2245 header |= VDO_OPOS(altmode->mode); 2777 2246 2778 - tcpm_queue_vdm_unlocked(port, header, vdo, vdo ? 1 : 0); 2247 + tcpm_queue_vdm_unlocked(port, header, vdo, vdo ? 1 : 0, TCPC_TX_SOP); 2779 2248 return 0; 2780 2249 } 2781 2250 ··· 2792 2261 header = VDO(altmode->svid, 1, svdm_version, CMD_EXIT_MODE); 2793 2262 header |= VDO_OPOS(altmode->mode); 2794 2263 2795 - tcpm_queue_vdm_unlocked(port, header, NULL, 0); 2264 + tcpm_queue_vdm_unlocked(port, header, NULL, 0, TCPC_TX_SOP); 2796 2265 return 0; 2797 2266 } 2798 2267 ··· 2801 2270 { 2802 2271 struct tcpm_port *port = typec_altmode_get_drvdata(altmode); 2803 2272 2804 - tcpm_queue_vdm_unlocked(port, header, data, count - 1); 2273 + tcpm_queue_vdm_unlocked(port, header, data, count - 1, TCPC_TX_SOP); 2805 2274 2806 2275 return 0; 2807 2276 } ··· 2810 2279 .enter = tcpm_altmode_enter, 2811 2280 .exit = tcpm_altmode_exit, 2812 2281 .vdm = tcpm_altmode_vdm, 2282 + }; 2283 + 2284 + 2285 + static int tcpm_cable_altmode_enter(struct typec_altmode *altmode, enum typec_plug_index sop, 2286 + u32 *vdo) 2287 + { 2288 + struct tcpm_port *port = typec_altmode_get_drvdata(altmode); 2289 + int svdm_version; 2290 + u32 header; 2291 + 2292 + svdm_version = typec_get_cable_svdm_version(port->typec_port); 2293 + if (svdm_version < 0) 2294 + return svdm_version; 2295 + 2296 + header = VDO(altmode->svid, vdo ? 2 : 1, svdm_version, CMD_ENTER_MODE); 2297 + header |= VDO_OPOS(altmode->mode); 2298 + 2299 + tcpm_queue_vdm_unlocked(port, header, vdo, vdo ? 1 : 0, TCPC_TX_SOP_PRIME); 2300 + return 0; 2301 + } 2302 + 2303 + static int tcpm_cable_altmode_exit(struct typec_altmode *altmode, enum typec_plug_index sop) 2304 + { 2305 + struct tcpm_port *port = typec_altmode_get_drvdata(altmode); 2306 + int svdm_version; 2307 + u32 header; 2308 + 2309 + svdm_version = typec_get_cable_svdm_version(port->typec_port); 2310 + if (svdm_version < 0) 2311 + return svdm_version; 2312 + 2313 + header = VDO(altmode->svid, 1, svdm_version, CMD_EXIT_MODE); 2314 + header |= VDO_OPOS(altmode->mode); 2315 + 2316 + tcpm_queue_vdm_unlocked(port, header, NULL, 0, TCPC_TX_SOP_PRIME); 2317 + return 0; 2318 + } 2319 + 2320 + static int tcpm_cable_altmode_vdm(struct typec_altmode *altmode, enum typec_plug_index sop, 2321 + u32 header, const u32 *data, int count) 2322 + { 2323 + struct tcpm_port *port = typec_altmode_get_drvdata(altmode); 2324 + 2325 + tcpm_queue_vdm_unlocked(port, header, data, count - 1, TCPC_TX_SOP_PRIME); 2326 + 2327 + return 0; 2328 + } 2329 + 2330 + static const struct typec_cable_ops tcpm_cable_ops = { 2331 + .enter = tcpm_cable_altmode_enter, 2332 + .exit = tcpm_cable_altmode_exit, 2333 + .vdm = tcpm_cable_altmode_vdm, 2813 2334 }; 2814 2335 2815 2336 /* ··· 2876 2293 } 2877 2294 2878 2295 static int tcpm_pd_send_control(struct tcpm_port *port, 2879 - enum pd_ctrl_msg_type type); 2296 + enum pd_ctrl_msg_type type, 2297 + enum tcpm_transmit_type tx_sop_type); 2880 2298 2881 2299 static void tcpm_handle_alert(struct tcpm_port *port, const __le32 *payload, 2882 2300 int cnt) ··· 3039 2455 } 3040 2456 3041 2457 static void tcpm_pd_data_request(struct tcpm_port *port, 3042 - const struct pd_message *msg) 2458 + const struct pd_message *msg, 2459 + enum tcpm_transmit_type rx_sop_type) 3043 2460 { 3044 2461 enum pd_data_msg_type type = pd_header_type_le(msg->header); 3045 2462 unsigned int cnt = pd_header_cnt_le(msg->header); ··· 3081 2496 break; 3082 2497 } 3083 2498 3084 - if (rev < PD_MAX_REV) 2499 + if (rev < PD_MAX_REV) { 3085 2500 port->negotiated_rev = rev; 2501 + if (port->negotiated_rev_prime > port->negotiated_rev) 2502 + port->negotiated_rev_prime = port->negotiated_rev; 2503 + } 3086 2504 3087 2505 if (port->pwr_role == TYPEC_SOURCE) { 3088 2506 if (port->ams == GET_SOURCE_CAPABILITIES) ··· 3136 2548 break; 3137 2549 } 3138 2550 3139 - if (rev < PD_MAX_REV) 2551 + if (rev < PD_MAX_REV) { 3140 2552 port->negotiated_rev = rev; 2553 + if (port->negotiated_rev_prime > port->negotiated_rev) 2554 + port->negotiated_rev_prime = port->negotiated_rev; 2555 + } 3141 2556 3142 2557 if (port->pwr_role != TYPEC_SOURCE || cnt != 1) { 3143 2558 tcpm_pd_handle_msg(port, ··· 3196 2605 NONE_AMS); 3197 2606 break; 3198 2607 case PD_DATA_VENDOR_DEF: 3199 - tcpm_handle_vdm_request(port, msg->payload, cnt); 2608 + tcpm_handle_vdm_request(port, msg->payload, cnt, rx_sop_type); 3200 2609 break; 3201 2610 case PD_DATA_BIST: 3202 2611 port->bist_request = le32_to_cpu(msg->payload[0]); ··· 3238 2647 } 3239 2648 3240 2649 static void tcpm_pd_ctrl_request(struct tcpm_port *port, 3241 - const struct pd_message *msg) 2650 + const struct pd_message *msg, 2651 + enum tcpm_transmit_type rx_sop_type) 3242 2652 { 3243 2653 enum pd_ctrl_msg_type type = pd_header_type_le(msg->header); 3244 2654 enum tcpm_state next_state; 2655 + unsigned int rev = pd_header_rev_le(msg->header); 3245 2656 3246 2657 /* 3247 2658 * Stop VDM state machine if interrupted by other Messages while NOT_SUPP is allowed in ··· 3408 2815 case SOFT_RESET_SEND: 3409 2816 if (port->ams == SOFT_RESET_AMS) 3410 2817 tcpm_ams_finish(port); 2818 + /* 2819 + * SOP' Soft Reset is done after Vconn Swap, 2820 + * which returns to ready state 2821 + */ 2822 + if (rx_sop_type == TCPC_TX_SOP_PRIME) { 2823 + if (rev < port->negotiated_rev_prime) 2824 + port->negotiated_rev_prime = rev; 2825 + tcpm_set_state(port, ready_state(port), 0); 2826 + break; 2827 + } 3411 2828 if (port->pwr_role == TYPEC_SOURCE) { 3412 2829 port->upcoming_state = SRC_SEND_CAPABILITIES; 3413 2830 tcpm_ams_start(port, POWER_NEGOTIATION); ··· 3584 2981 const struct pd_message *msg = &event->msg; 3585 2982 unsigned int cnt = pd_header_cnt_le(msg->header); 3586 2983 struct tcpm_port *port = event->port; 2984 + enum tcpm_transmit_type rx_sop_type = event->rx_sop_type; 3587 2985 3588 2986 mutex_lock(&port->lock); 3589 2987 ··· 3596 2992 unsigned int msgid = pd_header_msgid_le(msg->header); 3597 2993 3598 2994 /* 2995 + * Drop SOP' messages if cannot receive via 2996 + * tcpm_can_communicate_sop_prime 2997 + */ 2998 + if (rx_sop_type == TCPC_TX_SOP_PRIME && 2999 + !tcpm_can_communicate_sop_prime(port)) 3000 + goto done; 3001 + 3002 + /* 3599 3003 * USB PD standard, 6.6.1.2: 3600 3004 * "... if MessageID value in a received Message is the 3601 3005 * same as the stored value, the receiver shall return a ··· 3612 3000 * Message). Note: this shall not apply to the Soft_Reset 3613 3001 * Message which always has a MessageID value of zero." 3614 3002 */ 3615 - if (msgid == port->rx_msgid && type != PD_CTRL_SOFT_RESET) 3616 - goto done; 3617 - port->rx_msgid = msgid; 3003 + switch (rx_sop_type) { 3004 + case TCPC_TX_SOP_PRIME: 3005 + if (msgid == port->rx_msgid_prime) 3006 + goto done; 3007 + port->rx_msgid_prime = msgid; 3008 + break; 3009 + case TCPC_TX_SOP: 3010 + default: 3011 + if (msgid == port->rx_msgid && type != PD_CTRL_SOFT_RESET) 3012 + goto done; 3013 + port->rx_msgid = msgid; 3014 + break; 3015 + } 3618 3016 3619 3017 /* 3620 3018 * If both ends believe to be DFP/host, we have a data role 3621 3019 * mismatch. 3622 3020 */ 3623 3021 if (!!(le16_to_cpu(msg->header) & PD_HEADER_DATA_ROLE) == 3624 - (port->data_role == TYPEC_HOST)) { 3022 + (port->data_role == TYPEC_HOST) && rx_sop_type == TCPC_TX_SOP) { 3625 3023 tcpm_log(port, 3626 3024 "Data role mismatch, initiating error recovery"); 3627 3025 tcpm_set_state(port, ERROR_RECOVERY, 0); ··· 3639 3017 if (le16_to_cpu(msg->header) & PD_HEADER_EXT_HDR) 3640 3018 tcpm_pd_ext_msg_request(port, msg); 3641 3019 else if (cnt) 3642 - tcpm_pd_data_request(port, msg); 3020 + tcpm_pd_data_request(port, msg, rx_sop_type); 3643 3021 else 3644 - tcpm_pd_ctrl_request(port, msg); 3022 + tcpm_pd_ctrl_request(port, msg, rx_sop_type); 3645 3023 } 3646 3024 } 3647 3025 ··· 3650 3028 kfree(event); 3651 3029 } 3652 3030 3653 - void tcpm_pd_receive(struct tcpm_port *port, const struct pd_message *msg) 3031 + void tcpm_pd_receive(struct tcpm_port *port, const struct pd_message *msg, 3032 + enum tcpm_transmit_type rx_sop_type) 3654 3033 { 3655 3034 struct pd_rx_event *event; 3656 3035 ··· 3661 3038 3662 3039 kthread_init_work(&event->work, tcpm_pd_rx_handler); 3663 3040 event->port = port; 3041 + event->rx_sop_type = rx_sop_type; 3664 3042 memcpy(&event->msg, msg, sizeof(*msg)); 3665 3043 kthread_queue_work(port->wq, &event->work); 3666 3044 } 3667 3045 EXPORT_SYMBOL_GPL(tcpm_pd_receive); 3668 3046 3669 3047 static int tcpm_pd_send_control(struct tcpm_port *port, 3670 - enum pd_ctrl_msg_type type) 3048 + enum pd_ctrl_msg_type type, 3049 + enum tcpm_transmit_type tx_sop_type) 3671 3050 { 3672 3051 struct pd_message msg; 3673 3052 3674 3053 memset(&msg, 0, sizeof(msg)); 3675 - msg.header = PD_HEADER_LE(type, port->pwr_role, 3676 - port->data_role, 3677 - port->negotiated_rev, 3678 - port->message_id, 0); 3054 + switch (tx_sop_type) { 3055 + case TCPC_TX_SOP_PRIME: 3056 + msg.header = PD_HEADER_LE(type, 3057 + 0, /* Cable Plug Indicator for DFP/UFP */ 3058 + 0, /* Reserved */ 3059 + port->negotiated_rev, 3060 + port->message_id_prime, 3061 + 0); 3062 + break; 3063 + case TCPC_TX_SOP: 3064 + msg.header = PD_HEADER_LE(type, 3065 + port->pwr_role, 3066 + port->data_role, 3067 + port->negotiated_rev, 3068 + port->message_id, 3069 + 0); 3070 + break; 3071 + default: 3072 + msg.header = PD_HEADER_LE(type, 3073 + port->pwr_role, 3074 + port->data_role, 3075 + port->negotiated_rev, 3076 + port->message_id, 3077 + 0); 3078 + break; 3079 + } 3679 3080 3680 - return tcpm_pd_transmit(port, TCPC_TX_SOP, &msg); 3081 + return tcpm_pd_transmit(port, tx_sop_type, &msg); 3681 3082 } 3682 3083 3683 3084 /* ··· 3720 3073 3721 3074 switch (queued_message) { 3722 3075 case PD_MSG_CTRL_WAIT: 3723 - tcpm_pd_send_control(port, PD_CTRL_WAIT); 3076 + tcpm_pd_send_control(port, PD_CTRL_WAIT, TCPC_TX_SOP); 3724 3077 break; 3725 3078 case PD_MSG_CTRL_REJECT: 3726 - tcpm_pd_send_control(port, PD_CTRL_REJECT); 3079 + tcpm_pd_send_control(port, PD_CTRL_REJECT, TCPC_TX_SOP); 3727 3080 break; 3728 3081 case PD_MSG_CTRL_NOT_SUPP: 3729 - tcpm_pd_send_control(port, PD_CTRL_NOT_SUPP); 3082 + tcpm_pd_send_control(port, PD_CTRL_NOT_SUPP, TCPC_TX_SOP); 3730 3083 break; 3731 3084 case PD_MSG_DATA_SINK_CAP: 3732 3085 ret = tcpm_pd_send_sink_caps(port); ··· 4296 3649 4297 3650 port->attached = true; 4298 3651 port->send_discover = true; 3652 + port->send_discover_prime = false; 4299 3653 4300 3654 return 0; 4301 3655 ··· 4313 3665 4314 3666 static void tcpm_typec_disconnect(struct tcpm_port *port) 4315 3667 { 3668 + /* 3669 + * Unregister plug/cable outside of port->connected because cable can 3670 + * be discovered before SRC_READY/SNK_READY states where port->connected 3671 + * is set. 3672 + */ 3673 + typec_unregister_plug(port->plug_prime); 3674 + typec_unregister_cable(port->cable); 3675 + port->plug_prime = NULL; 3676 + port->cable = NULL; 4316 3677 if (port->connected) { 4317 3678 typec_partner_set_usb_power_delivery(port->partner, NULL); 4318 3679 typec_unregister_partner(port->partner); ··· 4333 3676 static void tcpm_unregister_altmodes(struct tcpm_port *port) 4334 3677 { 4335 3678 struct pd_mode_data *modep = &port->mode_data; 3679 + struct pd_mode_data *modep_prime = &port->mode_data_prime; 4336 3680 int i; 4337 3681 4338 3682 for (i = 0; i < modep->altmodes; i++) { 4339 3683 typec_unregister_altmode(port->partner_altmode[i]); 4340 3684 port->partner_altmode[i] = NULL; 4341 3685 } 3686 + for (i = 0; i < modep_prime->altmodes; i++) { 3687 + typec_unregister_altmode(port->plug_prime_altmode[i]); 3688 + port->plug_prime_altmode[i] = NULL; 3689 + } 4342 3690 4343 3691 memset(modep, 0, sizeof(*modep)); 3692 + memset(modep_prime, 0, sizeof(*modep_prime)); 4344 3693 } 4345 3694 4346 3695 static void tcpm_set_partner_usb_comm_capable(struct tcpm_port *port, bool capable) ··· 4375 3712 * we can check tcpm_pd_rx_handler() if we had seen it before. 4376 3713 */ 4377 3714 port->rx_msgid = -1; 3715 + port->rx_msgid_prime = -1; 4378 3716 4379 3717 port->tcpc->set_pd_rx(port->tcpc, false); 4380 3718 tcpm_init_vbus(port); /* also disables charging */ ··· 4447 3783 4448 3784 port->attached = true; 4449 3785 port->send_discover = true; 3786 + port->send_discover_prime = false; 4450 3787 4451 3788 return 0; 4452 3789 } ··· 4688 4023 port->pwr_opmode = TYPEC_PWR_MODE_USB; 4689 4024 port->caps_count = 0; 4690 4025 port->negotiated_rev = PD_MAX_REV; 4026 + port->negotiated_rev_prime = PD_MAX_REV; 4691 4027 port->message_id = 0; 4028 + port->message_id_prime = 0; 4692 4029 port->rx_msgid = -1; 4030 + port->rx_msgid_prime = -1; 4693 4031 port->explicit_contract = false; 4694 4032 /* SNK -> SRC POWER/FAST_ROLE_SWAP finished */ 4695 4033 if (port->ams == POWER_ROLE_SWAP || ··· 4713 4045 } 4714 4046 ret = tcpm_pd_send_source_caps(port); 4715 4047 if (ret < 0) { 4716 - tcpm_set_state(port, SRC_SEND_CAPABILITIES, 4717 - PD_T_SEND_SOURCE_CAP); 4048 + if (tcpm_can_communicate_sop_prime(port) && 4049 + IS_ERR_OR_NULL(port->cable)) 4050 + tcpm_set_state(port, SRC_VDM_IDENTITY_REQUEST, 0); 4051 + else 4052 + tcpm_set_state(port, SRC_SEND_CAPABILITIES, 4053 + PD_T_SEND_SOURCE_CAP); 4718 4054 } else { 4719 4055 /* 4720 4056 * Per standard, we should clear the reset counter here. ··· 4759 4087 case SRC_NEGOTIATE_CAPABILITIES: 4760 4088 ret = tcpm_pd_check_request(port); 4761 4089 if (ret < 0) { 4762 - tcpm_pd_send_control(port, PD_CTRL_REJECT); 4090 + tcpm_pd_send_control(port, PD_CTRL_REJECT, TCPC_TX_SOP); 4763 4091 if (!port->explicit_contract) { 4764 4092 tcpm_set_state(port, 4765 4093 SRC_WAIT_NEW_CAPABILITIES, 0); ··· 4767 4095 tcpm_set_state(port, SRC_READY, 0); 4768 4096 } 4769 4097 } else { 4770 - tcpm_pd_send_control(port, PD_CTRL_ACCEPT); 4098 + tcpm_pd_send_control(port, PD_CTRL_ACCEPT, TCPC_TX_SOP); 4771 4099 tcpm_set_partner_usb_comm_capable(port, 4772 4100 !!(port->sink_request & RDO_USB_COMM)); 4773 4101 tcpm_set_state(port, SRC_TRANSITION_SUPPLY, ··· 4776 4104 break; 4777 4105 case SRC_TRANSITION_SUPPLY: 4778 4106 /* XXX: regulator_set_voltage(vbus, ...) */ 4779 - tcpm_pd_send_control(port, PD_CTRL_PS_RDY); 4107 + tcpm_pd_send_control(port, PD_CTRL_PS_RDY, TCPC_TX_SOP); 4780 4108 port->explicit_contract = true; 4781 4109 typec_set_pwr_opmode(port->typec_port, TYPEC_PWR_MODE_PD); 4782 4110 port->pwr_opmode = TYPEC_PWR_MODE_PD; ··· 4813 4141 * 6.4.4.3.1 Discover Identity 4814 4142 * "The Discover Identity Command Shall only be sent to SOP when there is an 4815 4143 * Explicit Contract." 4816 - * For now, this driver only supports SOP for DISCOVER_IDENTITY, thus using 4817 - * port->explicit_contract to decide whether to send the command. 4144 + * 4145 + * Discover Identity on SOP' should be discovered prior to the 4146 + * ready state, but if done after a Vconn Swap following Discover 4147 + * Identity on SOP then the discovery process can be run here 4148 + * as well. 4818 4149 */ 4819 4150 if (port->explicit_contract) { 4820 - tcpm_set_initial_svdm_version(port); 4151 + if (port->send_discover_prime) { 4152 + port->tx_sop_type = TCPC_TX_SOP_PRIME; 4153 + } else { 4154 + port->tx_sop_type = TCPC_TX_SOP; 4155 + tcpm_set_initial_svdm_version(port); 4156 + } 4821 4157 mod_send_discover_delayed_work(port, 0); 4822 4158 } else { 4823 4159 port->send_discover = false; 4160 + port->send_discover_prime = false; 4824 4161 } 4825 4162 4826 4163 /* ··· 4945 4264 typec_set_pwr_opmode(port->typec_port, opmode); 4946 4265 port->pwr_opmode = TYPEC_PWR_MODE_USB; 4947 4266 port->negotiated_rev = PD_MAX_REV; 4267 + port->negotiated_rev_prime = PD_MAX_REV; 4948 4268 port->message_id = 0; 4269 + port->message_id_prime = 0; 4949 4270 port->rx_msgid = -1; 4271 + port->rx_msgid_prime = -1; 4950 4272 port->explicit_contract = false; 4951 4273 4952 4274 if (port->ams == POWER_ROLE_SWAP || ··· 5121 4437 * 6.4.4.3.1 Discover Identity 5122 4438 * "The Discover Identity Command Shall only be sent to SOP when there is an 5123 4439 * Explicit Contract." 5124 - * For now, this driver only supports SOP for DISCOVER_IDENTITY, thus using 5125 - * port->explicit_contract. 4440 + * 4441 + * Discover Identity on SOP' should be discovered prior to the 4442 + * ready state, but if done after a Vconn Swap following Discover 4443 + * Identity on SOP then the discovery process can be run here 4444 + * as well. 5126 4445 */ 5127 4446 if (port->explicit_contract) { 5128 - tcpm_set_initial_svdm_version(port); 4447 + if (port->send_discover_prime) { 4448 + port->tx_sop_type = TCPC_TX_SOP_PRIME; 4449 + } else { 4450 + port->tx_sop_type = TCPC_TX_SOP; 4451 + tcpm_set_initial_svdm_version(port); 4452 + } 5129 4453 mod_send_discover_delayed_work(port, 0); 5130 4454 } else { 5131 4455 port->send_discover = false; 4456 + port->send_discover_prime = false; 5132 4457 } 5133 4458 5134 4459 power_supply_changed(port->psy); ··· 5178 4485 tcpm_unregister_altmodes(port); 5179 4486 port->nr_sink_caps = 0; 5180 4487 port->send_discover = true; 4488 + port->send_discover_prime = false; 5181 4489 if (port->pwr_role == TYPEC_SOURCE) 5182 4490 tcpm_set_state(port, SRC_HARD_RESET_VBUS_OFF, 5183 4491 PD_T_PS_HARD_RESET); ··· 5280 4586 /* remove existing capabilities */ 5281 4587 usb_power_delivery_unregister_capabilities(port->partner_source_caps); 5282 4588 port->partner_source_caps = NULL; 5283 - tcpm_pd_send_control(port, PD_CTRL_ACCEPT); 4589 + tcpm_pd_send_control(port, PD_CTRL_ACCEPT, TCPC_TX_SOP); 5284 4590 tcpm_ams_finish(port); 5285 4591 if (port->pwr_role == TYPEC_SOURCE) { 5286 4592 port->upcoming_state = SRC_SEND_CAPABILITIES; ··· 5297 4603 tcpm_ams_start(port, SOFT_RESET_AMS); 5298 4604 break; 5299 4605 case SOFT_RESET_SEND: 5300 - port->message_id = 0; 5301 - port->rx_msgid = -1; 5302 - /* remove existing capabilities */ 5303 - usb_power_delivery_unregister_capabilities(port->partner_source_caps); 5304 - port->partner_source_caps = NULL; 5305 - if (tcpm_pd_send_control(port, PD_CTRL_SOFT_RESET)) 5306 - tcpm_set_state_cond(port, hard_reset_state(port), 0); 5307 - else 5308 - tcpm_set_state_cond(port, hard_reset_state(port), 5309 - PD_T_SENDER_RESPONSE); 4606 + /* 4607 + * Power Delivery 3.0 Section 6.3.13 4608 + * 4609 + * A Soft_Reset Message Shall be targeted at a specific entity 4610 + * depending on the type of SOP* packet used. 4611 + */ 4612 + if (port->tx_sop_type == TCPC_TX_SOP_PRIME) { 4613 + port->message_id_prime = 0; 4614 + port->rx_msgid_prime = -1; 4615 + tcpm_pd_send_control(port, PD_CTRL_SOFT_RESET, TCPC_TX_SOP_PRIME); 4616 + tcpm_set_state_cond(port, ready_state(port), PD_T_SENDER_RESPONSE); 4617 + } else { 4618 + port->message_id = 0; 4619 + port->rx_msgid = -1; 4620 + /* remove existing capabilities */ 4621 + usb_power_delivery_unregister_capabilities(port->partner_source_caps); 4622 + port->partner_source_caps = NULL; 4623 + if (tcpm_pd_send_control(port, PD_CTRL_SOFT_RESET, TCPC_TX_SOP)) 4624 + tcpm_set_state_cond(port, hard_reset_state(port), 0); 4625 + else 4626 + tcpm_set_state_cond(port, hard_reset_state(port), 4627 + PD_T_SENDER_RESPONSE); 4628 + } 5310 4629 break; 5311 4630 5312 4631 /* DR_Swap states */ 5313 4632 case DR_SWAP_SEND: 5314 - tcpm_pd_send_control(port, PD_CTRL_DR_SWAP); 5315 - if (port->data_role == TYPEC_DEVICE || port->negotiated_rev > PD_REV20) 4633 + tcpm_pd_send_control(port, PD_CTRL_DR_SWAP, TCPC_TX_SOP); 4634 + if (port->data_role == TYPEC_DEVICE || port->negotiated_rev > PD_REV20) { 5316 4635 port->send_discover = true; 4636 + port->send_discover_prime = false; 4637 + } 5317 4638 tcpm_set_state_cond(port, DR_SWAP_SEND_TIMEOUT, 5318 4639 PD_T_SENDER_RESPONSE); 5319 4640 break; 5320 4641 case DR_SWAP_ACCEPT: 5321 - tcpm_pd_send_control(port, PD_CTRL_ACCEPT); 5322 - if (port->data_role == TYPEC_DEVICE || port->negotiated_rev > PD_REV20) 4642 + tcpm_pd_send_control(port, PD_CTRL_ACCEPT, TCPC_TX_SOP); 4643 + if (port->data_role == TYPEC_DEVICE || port->negotiated_rev > PD_REV20) { 5323 4644 port->send_discover = true; 4645 + port->send_discover_prime = false; 4646 + } 5324 4647 tcpm_set_state_cond(port, DR_SWAP_CHANGE_DR, 0); 5325 4648 break; 5326 4649 case DR_SWAP_SEND_TIMEOUT: 5327 4650 tcpm_swap_complete(port, -ETIMEDOUT); 5328 4651 port->send_discover = false; 4652 + port->send_discover_prime = false; 5329 4653 tcpm_ams_finish(port); 5330 4654 tcpm_set_state(port, ready_state(port), 0); 5331 4655 break; ··· 5360 4648 break; 5361 4649 5362 4650 case FR_SWAP_SEND: 5363 - if (tcpm_pd_send_control(port, PD_CTRL_FR_SWAP)) { 4651 + if (tcpm_pd_send_control(port, PD_CTRL_FR_SWAP, TCPC_TX_SOP)) { 5364 4652 tcpm_set_state(port, ERROR_RECOVERY, 0); 5365 4653 break; 5366 4654 } ··· 5380 4668 break; 5381 4669 case FR_SWAP_SNK_SRC_SOURCE_VBUS_APPLIED: 5382 4670 tcpm_set_pwr_role(port, TYPEC_SOURCE); 5383 - if (tcpm_pd_send_control(port, PD_CTRL_PS_RDY)) { 4671 + if (tcpm_pd_send_control(port, PD_CTRL_PS_RDY, TCPC_TX_SOP)) { 5384 4672 tcpm_set_state(port, ERROR_RECOVERY, 0); 5385 4673 break; 5386 4674 } ··· 5390 4678 5391 4679 /* PR_Swap states */ 5392 4680 case PR_SWAP_ACCEPT: 5393 - tcpm_pd_send_control(port, PD_CTRL_ACCEPT); 4681 + tcpm_pd_send_control(port, PD_CTRL_ACCEPT, TCPC_TX_SOP); 5394 4682 tcpm_set_state(port, PR_SWAP_START, 0); 5395 4683 break; 5396 4684 case PR_SWAP_SEND: 5397 - tcpm_pd_send_control(port, PD_CTRL_PR_SWAP); 4685 + tcpm_pd_send_control(port, PD_CTRL_PR_SWAP, TCPC_TX_SOP); 5398 4686 tcpm_set_state_cond(port, PR_SWAP_SEND_TIMEOUT, 5399 4687 PD_T_SENDER_RESPONSE); 5400 4688 break; ··· 5436 4724 * supply is turned off" 5437 4725 */ 5438 4726 tcpm_set_pwr_role(port, TYPEC_SINK); 5439 - if (tcpm_pd_send_control(port, PD_CTRL_PS_RDY)) { 4727 + if (tcpm_pd_send_control(port, PD_CTRL_PS_RDY, TCPC_TX_SOP)) { 5440 4728 tcpm_set_state(port, ERROR_RECOVERY, 0); 5441 4729 break; 5442 4730 } ··· 5483 4771 * Source." 5484 4772 */ 5485 4773 tcpm_set_pwr_role(port, TYPEC_SOURCE); 5486 - tcpm_pd_send_control(port, PD_CTRL_PS_RDY); 4774 + tcpm_pd_send_control(port, PD_CTRL_PS_RDY, TCPC_TX_SOP); 5487 4775 tcpm_set_state(port, SRC_STARTUP, PD_T_SWAP_SRC_START); 5488 4776 break; 5489 4777 5490 4778 case VCONN_SWAP_ACCEPT: 5491 - tcpm_pd_send_control(port, PD_CTRL_ACCEPT); 4779 + tcpm_pd_send_control(port, PD_CTRL_ACCEPT, TCPC_TX_SOP); 5492 4780 tcpm_ams_finish(port); 5493 4781 tcpm_set_state(port, VCONN_SWAP_START, 0); 5494 4782 break; 5495 4783 case VCONN_SWAP_SEND: 5496 - tcpm_pd_send_control(port, PD_CTRL_VCONN_SWAP); 4784 + tcpm_pd_send_control(port, PD_CTRL_VCONN_SWAP, TCPC_TX_SOP); 5497 4785 tcpm_set_state(port, VCONN_SWAP_SEND_TIMEOUT, 5498 4786 PD_T_SENDER_RESPONSE); 5499 4787 break; ··· 5512 4800 PD_T_VCONN_SOURCE_ON); 5513 4801 break; 5514 4802 case VCONN_SWAP_TURN_ON_VCONN: 5515 - tcpm_set_vconn(port, true); 5516 - tcpm_pd_send_control(port, PD_CTRL_PS_RDY); 5517 - tcpm_set_state(port, ready_state(port), 0); 4803 + ret = tcpm_set_vconn(port, true); 4804 + tcpm_pd_send_control(port, PD_CTRL_PS_RDY, TCPC_TX_SOP); 4805 + /* 4806 + * USB PD 3.0 Section 6.4.4.3.1 4807 + * 4808 + * Note that a Cable Plug or VPD will not be ready for PD 4809 + * Communication until tVCONNStable after VCONN has been applied 4810 + */ 4811 + if (!ret) 4812 + tcpm_set_state(port, VCONN_SWAP_SEND_SOFT_RESET, 4813 + PD_T_VCONN_STABLE); 4814 + else 4815 + tcpm_set_state(port, ready_state(port), 0); 5518 4816 break; 5519 4817 case VCONN_SWAP_TURN_OFF_VCONN: 5520 4818 tcpm_set_vconn(port, false); 5521 4819 tcpm_set_state(port, ready_state(port), 0); 4820 + break; 4821 + case VCONN_SWAP_SEND_SOFT_RESET: 4822 + tcpm_swap_complete(port, port->swap_status); 4823 + if (tcpm_can_communicate_sop_prime(port)) { 4824 + port->tx_sop_type = TCPC_TX_SOP_PRIME; 4825 + port->upcoming_state = SOFT_RESET_SEND; 4826 + tcpm_ams_start(port, SOFT_RESET_AMS); 4827 + } else { 4828 + tcpm_set_state(port, ready_state(port), 0); 4829 + } 5522 4830 break; 5523 4831 5524 4832 case DR_SWAP_CANCEL: ··· 5575 4843 } 5576 4844 break; 5577 4845 case GET_STATUS_SEND: 5578 - tcpm_pd_send_control(port, PD_CTRL_GET_STATUS); 4846 + tcpm_pd_send_control(port, PD_CTRL_GET_STATUS, TCPC_TX_SOP); 5579 4847 tcpm_set_state(port, GET_STATUS_SEND_TIMEOUT, 5580 4848 PD_T_SENDER_RESPONSE); 5581 4849 break; ··· 5583 4851 tcpm_set_state(port, ready_state(port), 0); 5584 4852 break; 5585 4853 case GET_PPS_STATUS_SEND: 5586 - tcpm_pd_send_control(port, PD_CTRL_GET_PPS_STATUS); 4854 + tcpm_pd_send_control(port, PD_CTRL_GET_PPS_STATUS, TCPC_TX_SOP); 5587 4855 tcpm_set_state(port, GET_PPS_STATUS_SEND_TIMEOUT, 5588 4856 PD_T_SENDER_RESPONSE); 5589 4857 break; ··· 5591 4859 tcpm_set_state(port, ready_state(port), 0); 5592 4860 break; 5593 4861 case GET_SINK_CAP: 5594 - tcpm_pd_send_control(port, PD_CTRL_GET_SINK_CAP); 4862 + tcpm_pd_send_control(port, PD_CTRL_GET_SINK_CAP, TCPC_TX_SOP); 5595 4863 tcpm_set_state(port, GET_SINK_CAP_TIMEOUT, PD_T_SENDER_RESPONSE); 5596 4864 break; 5597 4865 case GET_SINK_CAP_TIMEOUT: ··· 5634 4902 5635 4903 /* Chunk state */ 5636 4904 case CHUNK_NOT_SUPP: 5637 - tcpm_pd_send_control(port, PD_CTRL_NOT_SUPP); 4905 + tcpm_pd_send_control(port, PD_CTRL_NOT_SUPP, TCPC_TX_SOP); 5638 4906 tcpm_set_state(port, port->pwr_role == TYPEC_SOURCE ? SRC_READY : SNK_READY, 0); 5639 4907 break; 4908 + 4909 + /* Cable states */ 4910 + case SRC_VDM_IDENTITY_REQUEST: 4911 + port->send_discover_prime = true; 4912 + port->tx_sop_type = TCPC_TX_SOP_PRIME; 4913 + mod_send_discover_delayed_work(port, 0); 4914 + port->upcoming_state = SRC_SEND_CAPABILITIES; 4915 + break; 4916 + 5640 4917 default: 5641 4918 WARN(1, "Unexpected port state %d\n", port->state); 5642 4919 break; ··· 6337 5596 goto unlock; 6338 5597 6339 5598 /* Send when the state machine is idle */ 6340 - if (port->state != SNK_READY || port->vdm_sm_running || port->send_discover) 5599 + if (port->state != SNK_READY || port->vdm_sm_running || port->send_discover || 5600 + port->send_discover_prime) 6341 5601 goto resched; 6342 5602 6343 5603 port->upcoming_state = GET_SINK_CAP; ··· 6361 5619 6362 5620 mutex_lock(&port->lock); 6363 5621 /* No need to send DISCOVER_IDENTITY anymore */ 6364 - if (!port->send_discover) 5622 + if (!port->send_discover && !port->send_discover_prime) 6365 5623 goto unlock; 6366 5624 6367 5625 if (port->data_role == TYPEC_DEVICE && port->negotiated_rev < PD_REV30) { 6368 5626 port->send_discover = false; 5627 + port->send_discover_prime = false; 6369 5628 goto unlock; 6370 5629 } 6371 5630 6372 5631 /* Retry if the port is not idle */ 6373 - if ((port->state != SRC_READY && port->state != SNK_READY) || port->vdm_sm_running) { 5632 + if ((port->state != SRC_READY && port->state != SNK_READY && 5633 + port->state != SRC_VDM_IDENTITY_REQUEST) || port->vdm_sm_running) { 6374 5634 mod_send_discover_delayed_work(port, SEND_DISCOVER_RETRY_MS); 6375 5635 goto unlock; 6376 5636 } 6377 5637 6378 - tcpm_send_vdm(port, USB_SID_PD, CMD_DISCOVER_IDENT, NULL, 0); 5638 + tcpm_send_vdm(port, USB_SID_PD, CMD_DISCOVER_IDENT, NULL, 0, port->tx_sop_type); 6379 5639 6380 5640 unlock: 6381 5641 mutex_unlock(&port->lock); ··· 7604 6860 typec_port_register_altmodes(port->typec_port, 7605 6861 &tcpm_altmode_ops, port, 7606 6862 port->port_altmode, ALTMODE_DISCOVERY_MAX); 6863 + typec_port_register_cable_ops(port->port_altmode, ARRAY_SIZE(port->port_altmode), 6864 + &tcpm_cable_ops); 7607 6865 port->registered = true; 7608 6866 7609 6867 mutex_lock(&port->lock);
+1 -1
drivers/usb/typec/tcpm/wcove.c
··· 535 535 goto err; 536 536 } 537 537 538 - tcpm_pd_receive(wcove->tcpm, &msg); 538 + tcpm_pd_receive(wcove->tcpm, &msg, TCPC_TX_SOP); 539 539 540 540 ret = regmap_read(wcove->regmap, USBC_RXSTATUS, 541 541 &status);
+292 -2
drivers/usb/typec/ucsi/ucsi.c
··· 36 36 */ 37 37 #define UCSI_SWAP_TIMEOUT_MS 5000 38 38 39 + static int ucsi_read_message_in(struct ucsi *ucsi, void *buf, 40 + size_t buf_size) 41 + { 42 + /* 43 + * Below UCSI 2.0, MESSAGE_IN was limited to 16 bytes. Truncate the 44 + * reads here. 45 + */ 46 + if (ucsi->version <= UCSI_VERSION_1_2) 47 + buf_size = clamp(buf_size, 0, 16); 48 + 49 + return ucsi->ops->read(ucsi, UCSI_MESSAGE_IN, buf, buf_size); 50 + } 51 + 39 52 static int ucsi_acknowledge_command(struct ucsi *ucsi) 40 53 { 41 54 u64 ctrl; ··· 85 72 if (ret < 0) 86 73 return ret; 87 74 88 - ret = ucsi->ops->read(ucsi, UCSI_MESSAGE_IN, &error, sizeof(error)); 75 + ret = ucsi_read_message_in(ucsi, &error, sizeof(error)); 89 76 if (ret) 90 77 return ret; 91 78 ··· 183 170 length = ret; 184 171 185 172 if (data) { 186 - ret = ucsi->ops->read(ucsi, UCSI_MESSAGE_IN, data, size); 173 + ret = ucsi_read_message_in(ucsi, data, size); 187 174 if (ret) 188 175 goto out; 189 176 } ··· 399 386 400 387 con->partner_altmode[i] = alt; 401 388 break; 389 + case UCSI_RECIPIENT_SOP_P: 390 + i = ucsi_next_altmode(con->plug_altmode); 391 + if (i < 0) { 392 + ret = i; 393 + goto err; 394 + } 395 + 396 + ret = ucsi_altmode_next_mode(con->plug_altmode, desc->svid); 397 + if (ret < 0) 398 + return ret; 399 + 400 + desc->mode = ret; 401 + 402 + alt = typec_plug_register_altmode(con->plug, desc); 403 + if (IS_ERR(alt)) { 404 + ret = PTR_ERR(alt); 405 + goto err; 406 + } 407 + 408 + con->plug_altmode[i] = alt; 409 + break; 402 410 default: 403 411 return -EINVAL; 404 412 } ··· 587 553 case UCSI_RECIPIENT_SOP: 588 554 adev = con->partner_altmode; 589 555 break; 556 + case UCSI_RECIPIENT_SOP_P: 557 + adev = con->plug_altmode; 558 + break; 590 559 default: 591 560 return; 592 561 } ··· 666 629 con->num_pdos = ret; 667 630 668 631 ucsi_port_psy_changed(con); 632 + 633 + return ret; 634 + } 635 + 636 + static int ucsi_read_identity(struct ucsi_connector *con, u8 recipient, 637 + u8 offset, u8 bytes, void *resp) 638 + { 639 + struct ucsi *ucsi = con->ucsi; 640 + u64 command; 641 + int ret; 642 + 643 + command = UCSI_COMMAND(UCSI_GET_PD_MESSAGE) | 644 + UCSI_CONNECTOR_NUMBER(con->num); 645 + command |= UCSI_GET_PD_MESSAGE_RECIPIENT(recipient); 646 + command |= UCSI_GET_PD_MESSAGE_OFFSET(offset); 647 + command |= UCSI_GET_PD_MESSAGE_BYTES(bytes); 648 + command |= UCSI_GET_PD_MESSAGE_TYPE(UCSI_GET_PD_MESSAGE_TYPE_IDENTITY); 649 + 650 + ret = ucsi_send_command(ucsi, command, resp, bytes); 651 + if (ret < 0) 652 + dev_err(ucsi->dev, "UCSI_GET_PD_MESSAGE failed (%d)\n", ret); 653 + 654 + return ret; 655 + } 656 + 657 + static int ucsi_get_identity(struct ucsi_connector *con, u8 recipient, 658 + struct usb_pd_identity *id) 659 + { 660 + struct ucsi *ucsi = con->ucsi; 661 + struct ucsi_pd_message_disc_id resp = {}; 662 + int ret; 663 + 664 + if (ucsi->version < UCSI_VERSION_2_0) { 665 + /* 666 + * Before UCSI v2.0, MESSAGE_IN is 16 bytes which cannot fit 667 + * the 28 byte identity response including the VDM header. 668 + * First request the VDM header, ID Header VDO, Cert Stat VDO 669 + * and Product VDO. 670 + */ 671 + ret = ucsi_read_identity(con, recipient, 0, 0x10, &resp); 672 + if (ret < 0) 673 + return ret; 674 + 675 + 676 + /* Then request Product Type VDO1 through Product Type VDO3. */ 677 + ret = ucsi_read_identity(con, recipient, 0x10, 0xc, 678 + &resp.vdo[0]); 679 + if (ret < 0) 680 + return ret; 681 + 682 + } else { 683 + /* 684 + * In UCSI v2.0 and after, MESSAGE_IN is large enough to request 685 + * the large enough to request the full Discover Identity 686 + * response at once. 687 + */ 688 + ret = ucsi_read_identity(con, recipient, 0x0, 0x1c, &resp); 689 + if (ret < 0) 690 + return ret; 691 + } 692 + 693 + id->id_header = resp.id_header; 694 + id->cert_stat = resp.cert_stat; 695 + id->product = resp.product; 696 + id->vdo[0] = resp.vdo[0]; 697 + id->vdo[1] = resp.vdo[1]; 698 + id->vdo[2] = resp.vdo[2]; 699 + return 0; 700 + } 701 + 702 + static int ucsi_get_partner_identity(struct ucsi_connector *con) 703 + { 704 + int ret; 705 + 706 + ret = ucsi_get_identity(con, UCSI_RECIPIENT_SOP, 707 + &con->partner_identity); 708 + if (ret < 0) 709 + return ret; 710 + 711 + ret = typec_partner_set_identity(con->partner); 712 + if (ret < 0) { 713 + dev_err(con->ucsi->dev, "Failed to set partner identity (%d)\n", 714 + ret); 715 + } 716 + 717 + return ret; 718 + } 719 + 720 + static int ucsi_get_cable_identity(struct ucsi_connector *con) 721 + { 722 + int ret; 723 + 724 + ret = ucsi_get_identity(con, UCSI_RECIPIENT_SOP_P, 725 + &con->cable_identity); 726 + if (ret < 0) 727 + return ret; 728 + 729 + ret = typec_cable_set_identity(con->cable); 730 + if (ret < 0) { 731 + dev_err(con->ucsi->dev, "Failed to set cable identity (%d)\n", 732 + ret); 733 + } 669 734 670 735 return ret; 671 736 } ··· 860 721 con->partner_pd = NULL; 861 722 } 862 723 724 + static int ucsi_register_plug(struct ucsi_connector *con) 725 + { 726 + struct typec_plug *plug; 727 + struct typec_plug_desc desc = {.index = TYPEC_PLUG_SOP_P}; 728 + 729 + plug = typec_register_plug(con->cable, &desc); 730 + if (IS_ERR(plug)) { 731 + dev_err(con->ucsi->dev, 732 + "con%d: failed to register plug (%ld)\n", con->num, 733 + PTR_ERR(plug)); 734 + return PTR_ERR(plug); 735 + } 736 + 737 + con->plug = plug; 738 + return 0; 739 + } 740 + 741 + static void ucsi_unregister_plug(struct ucsi_connector *con) 742 + { 743 + if (!con->plug) 744 + return; 745 + 746 + ucsi_unregister_altmodes(con, UCSI_RECIPIENT_SOP_P); 747 + typec_unregister_plug(con->plug); 748 + con->plug = NULL; 749 + } 750 + 751 + static int ucsi_register_cable(struct ucsi_connector *con) 752 + { 753 + struct typec_cable *cable; 754 + struct typec_cable_desc desc = {}; 755 + 756 + switch (UCSI_CABLE_PROP_FLAG_PLUG_TYPE(con->cable_prop.flags)) { 757 + case UCSI_CABLE_PROPERTY_PLUG_TYPE_A: 758 + desc.type = USB_PLUG_TYPE_A; 759 + break; 760 + case UCSI_CABLE_PROPERTY_PLUG_TYPE_B: 761 + desc.type = USB_PLUG_TYPE_B; 762 + break; 763 + case UCSI_CABLE_PROPERTY_PLUG_TYPE_C: 764 + desc.type = USB_PLUG_TYPE_C; 765 + break; 766 + default: 767 + desc.type = USB_PLUG_NONE; 768 + break; 769 + } 770 + 771 + desc.identity = &con->cable_identity; 772 + desc.active = !!(UCSI_CABLE_PROP_FLAG_ACTIVE_CABLE & 773 + con->cable_prop.flags); 774 + desc.pd_revision = UCSI_CABLE_PROP_FLAG_PD_MAJOR_REV_AS_BCD( 775 + con->cable_prop.flags); 776 + 777 + cable = typec_register_cable(con->port, &desc); 778 + if (IS_ERR(cable)) { 779 + dev_err(con->ucsi->dev, 780 + "con%d: failed to register cable (%ld)\n", con->num, 781 + PTR_ERR(cable)); 782 + return PTR_ERR(cable); 783 + } 784 + 785 + con->cable = cable; 786 + return 0; 787 + } 788 + 789 + static void ucsi_unregister_cable(struct ucsi_connector *con) 790 + { 791 + if (!con->cable) 792 + return; 793 + 794 + ucsi_unregister_plug(con); 795 + typec_unregister_cable(con->cable); 796 + memset(&con->cable_identity, 0, sizeof(con->cable_identity)); 797 + con->cable = NULL; 798 + } 799 + 863 800 static void ucsi_pwr_opmode_change(struct ucsi_connector *con) 864 801 { 865 802 switch (UCSI_CONSTAT_PWR_OPMODE(con->status.flags)) { ··· 983 768 break; 984 769 } 985 770 771 + desc.identity = &con->partner_identity; 986 772 desc.usb_pd = pwr_opmode == UCSI_CONSTAT_PWR_OPMODE_PD; 773 + desc.pd_revision = UCSI_CONCAP_FLAG_PARTNER_PD_MAJOR_REV_AS_BCD(con->cap.flags); 987 774 988 775 partner = typec_register_partner(con->port, &desc); 989 776 if (IS_ERR(partner)) { ··· 1010 793 typec_partner_set_usb_power_delivery(con->partner, NULL); 1011 794 ucsi_unregister_partner_pdos(con); 1012 795 ucsi_unregister_altmodes(con, UCSI_RECIPIENT_SOP); 796 + ucsi_unregister_cable(con); 1013 797 typec_unregister_partner(con->partner); 798 + memset(&con->partner_identity, 0, sizeof(con->partner_identity)); 1014 799 con->partner = NULL; 1015 800 } 1016 801 ··· 1062 843 con->num, u_role); 1063 844 } 1064 845 846 + static int ucsi_check_connector_capability(struct ucsi_connector *con) 847 + { 848 + u64 command; 849 + int ret; 850 + 851 + if (!con->partner || con->ucsi->version < UCSI_VERSION_2_0) 852 + return 0; 853 + 854 + command = UCSI_GET_CONNECTOR_CAPABILITY | UCSI_CONNECTOR_NUMBER(con->num); 855 + ret = ucsi_send_command(con->ucsi, command, &con->cap, sizeof(con->cap)); 856 + if (ret < 0) { 857 + dev_err(con->ucsi->dev, "GET_CONNECTOR_CAPABILITY failed (%d)\n", ret); 858 + return ret; 859 + } 860 + 861 + typec_partner_set_pd_revision(con->partner, 862 + UCSI_CONCAP_FLAG_PARTNER_PD_MAJOR_REV_AS_BCD(con->cap.flags)); 863 + 864 + return ret; 865 + } 866 + 1065 867 static int ucsi_check_connection(struct ucsi_connector *con) 1066 868 { 1067 869 u8 prev_flags = con->status.flags; ··· 1108 868 ucsi_port_psy_changed(con); 1109 869 ucsi_unregister_partner(con); 1110 870 } 871 + 872 + return 0; 873 + } 874 + 875 + static int ucsi_check_cable(struct ucsi_connector *con) 876 + { 877 + u64 command; 878 + int ret; 879 + 880 + if (con->cable) 881 + return 0; 882 + 883 + command = UCSI_GET_CABLE_PROPERTY | UCSI_CONNECTOR_NUMBER(con->num); 884 + ret = ucsi_send_command(con->ucsi, command, &con->cable_prop, 885 + sizeof(con->cable_prop)); 886 + if (ret < 0) { 887 + dev_err(con->ucsi->dev, "GET_CABLE_PROPERTY failed (%d)\n", 888 + ret); 889 + return ret; 890 + } 891 + 892 + ret = ucsi_register_cable(con); 893 + if (ret < 0) 894 + return ret; 895 + 896 + ret = ucsi_get_cable_identity(con); 897 + if (ret < 0) 898 + return ret; 899 + 900 + ret = ucsi_register_plug(con); 901 + if (ret < 0) 902 + return ret; 903 + 904 + ret = ucsi_register_altmodes(con, UCSI_RECIPIENT_SOP_P); 905 + if (ret < 0) 906 + return ret; 1111 907 1112 908 return 0; 1113 909 } ··· 1188 912 if (con->status.flags & UCSI_CONSTAT_CONNECTED) { 1189 913 ucsi_register_partner(con); 1190 914 ucsi_partner_task(con, ucsi_check_connection, 1, HZ); 915 + ucsi_partner_task(con, ucsi_check_connector_capability, 1, HZ); 916 + ucsi_partner_task(con, ucsi_get_partner_identity, 1, HZ); 917 + ucsi_partner_task(con, ucsi_check_cable, 1, HZ); 1191 918 1192 919 if (UCSI_CONSTAT_PWR_OPMODE(con->status.flags) == 1193 920 UCSI_CONSTAT_PWR_OPMODE_PD) ··· 1589 1310 ucsi_register_partner(con); 1590 1311 ucsi_pwr_opmode_change(con); 1591 1312 ucsi_port_psy_changed(con); 1313 + ucsi_get_partner_identity(con); 1314 + ucsi_check_cable(con); 1592 1315 } 1593 1316 1594 1317 /* Only notify USB controller if partner supports USB data */ ··· 1838 1557 1839 1558 if (!ucsi->version) 1840 1559 return -ENODEV; 1560 + 1561 + /* 1562 + * Version format is JJ.M.N (JJ = Major version, M = Minor version, 1563 + * N = sub-minor version). 1564 + */ 1565 + dev_dbg(ucsi->dev, "Registered UCSI interface with version %x.%x.%x", 1566 + UCSI_BCD_GET_MAJOR(ucsi->version), 1567 + UCSI_BCD_GET_MINOR(ucsi->version), 1568 + UCSI_BCD_GET_SUBMINOR(ucsi->version)); 1841 1569 1842 1570 queue_delayed_work(system_long_wq, &ucsi->work, 0); 1843 1571
+101 -6
drivers/usb/typec/ucsi/ucsi.h
··· 10 10 #include <linux/usb/typec.h> 11 11 #include <linux/usb/pd.h> 12 12 #include <linux/usb/role.h> 13 + #include <asm/unaligned.h> 13 14 14 15 /* -------------------------------------------------------------------------- */ 15 16 ··· 24 23 #define UCSI_CONTROL 8 25 24 #define UCSI_MESSAGE_IN 16 26 25 #define UCSI_MESSAGE_OUT 32 26 + #define UCSIv2_MESSAGE_OUT 272 27 + 28 + /* UCSI versions */ 29 + #define UCSI_VERSION_1_2 0x0120 30 + #define UCSI_VERSION_2_0 0x0200 31 + #define UCSI_VERSION_2_1 0x0210 32 + #define UCSI_VERSION_3_0 0x0300 33 + 34 + #define UCSI_BCD_GET_MAJOR(_v_) (((_v_) >> 8) & 0xFF) 35 + #define UCSI_BCD_GET_MINOR(_v_) (((_v_) >> 4) & 0x0F) 36 + #define UCSI_BCD_GET_SUBMINOR(_v_) ((_v_) & 0x0F) 37 + 38 + /* 39 + * Per USB PD 3.2, Section 6.2.1.1.5, the spec revision is represented by 2 bits 40 + * 0b00 = 1.0, 0b01 = 2.0, 0b10 = 3.0, 0b11 = Reserved, Shall NOT be used. 41 + */ 42 + #define UCSI_SPEC_REVISION_TO_BCD(_v_) (((_v_) + 1) << 8) 27 43 28 44 /* Command Status and Connector Change Indication (CCI) bits */ 29 45 #define UCSI_CCI_CONNECTOR(_c_) (((_c_) & GENMASK(7, 1)) >> 1) ··· 106 88 #define UCSI_GET_CABLE_PROPERTY 0x11 107 89 #define UCSI_GET_CONNECTOR_STATUS 0x12 108 90 #define UCSI_GET_ERROR_STATUS 0x13 91 + #define UCSI_GET_PD_MESSAGE 0x15 109 92 110 93 #define UCSI_CONNECTOR_NUMBER(_num_) ((u64)(_num_) << 16) 111 94 #define UCSI_COMMAND(_cmd_) ((_cmd_) & 0xff) ··· 159 140 #define UCSI_GET_PDOS_NUM_PDOS(_r_) ((u64)(_r_) << 32) 160 141 #define UCSI_MAX_PDOS (4) 161 142 #define UCSI_GET_PDOS_SRC_PDOS ((u64)1 << 34) 143 + 144 + /* GET_PD_MESSAGE command bits */ 145 + #define UCSI_GET_PD_MESSAGE_RECIPIENT(_r_) ((u64)(_r_) << 23) 146 + #define UCSI_GET_PD_MESSAGE_OFFSET(_r_) ((u64)(_r_) << 26) 147 + #define UCSI_GET_PD_MESSAGE_BYTES(_r_) ((u64)(_r_) << 34) 148 + #define UCSI_GET_PD_MESSAGE_TYPE(_r_) ((u64)(_r_) << 42) 149 + #define UCSI_GET_PD_MESSAGE_TYPE_SNK_CAP_EXT 0 150 + #define UCSI_GET_PD_MESSAGE_TYPE_SRC_CAP_EXT 1 151 + #define UCSI_GET_PD_MESSAGE_TYPE_BAT_CAP 2 152 + #define UCSI_GET_PD_MESSAGE_TYPE_BAT_STAT 3 153 + #define UCSI_GET_PD_MESSAGE_TYPE_IDENTITY 4 154 + #define UCSI_GET_PD_MESSAGE_TYPE_REVISION 5 162 155 163 156 /* -------------------------------------------------------------------------- */ 164 157 ··· 234 203 #define UCSI_CONCAP_OPMODE_USB2 BIT(5) 235 204 #define UCSI_CONCAP_OPMODE_USB3 BIT(6) 236 205 #define UCSI_CONCAP_OPMODE_ALT_MODE BIT(7) 237 - u8 flags; 206 + u32 flags; 238 207 #define UCSI_CONCAP_FLAG_PROVIDER BIT(0) 239 208 #define UCSI_CONCAP_FLAG_CONSUMER BIT(1) 209 + #define UCSI_CONCAP_FLAG_SWAP_TO_DFP BIT(2) 210 + #define UCSI_CONCAP_FLAG_SWAP_TO_UFP BIT(3) 211 + #define UCSI_CONCAP_FLAG_SWAP_TO_SRC BIT(4) 212 + #define UCSI_CONCAP_FLAG_SWAP_TO_SINK BIT(5) 213 + #define UCSI_CONCAP_FLAG_EX_OP_MODE(_f_) \ 214 + (((_f_) & GENMASK(13, 6)) >> 6) 215 + #define UCSI_CONCAP_EX_OP_MODE_USB4_GEN2 BIT(0) 216 + #define UCSI_CONCAP_EX_OP_MODE_EPR_SRC BIT(1) 217 + #define UCSI_CONCAP_EX_OP_MODE_EPR_SINK BIT(2) 218 + #define UCSI_CONCAP_EX_OP_MODE_USB4_GEN3 BIT(3) 219 + #define UCSI_CONCAP_EX_OP_MODE_USB4_GEN4 BIT(4) 220 + #define UCSI_CONCAP_FLAG_MISC_CAPS(_f_) \ 221 + (((_f_) & GENMASK(17, 14)) >> 14) 222 + #define UCSI_CONCAP_MISC_CAP_FW_UPDATE BIT(0) 223 + #define UCSI_CONCAP_MISC_CAP_SECURITY BIT(1) 224 + #define UCSI_CONCAP_FLAG_REV_CURR_PROT_SUPPORT BIT(18) 225 + #define UCSI_CONCAP_FLAG_PARTNER_PD_MAJOR_REV(_f_) \ 226 + (((_f_) & GENMASK(20, 19)) >> 19) 227 + #define UCSI_CONCAP_FLAG_PARTNER_PD_MAJOR_REV_AS_BCD(_f_) \ 228 + UCSI_SPEC_REVISION_TO_BCD(UCSI_CONCAP_FLAG_PARTNER_PD_MAJOR_REV(_f_)) 240 229 } __packed; 241 230 242 231 struct ucsi_altmode { ··· 272 221 #define UCSI_CABLE_PROP_FLAG_VBUS_IN_CABLE BIT(0) 273 222 #define UCSI_CABLE_PROP_FLAG_ACTIVE_CABLE BIT(1) 274 223 #define UCSI_CABLE_PROP_FLAG_DIRECTIONALITY BIT(2) 275 - #define UCSI_CABLE_PROP_FLAG_PLUG_TYPE(_f_) ((_f_) & GENMASK(3, 0)) 224 + #define UCSI_CABLE_PROP_FLAG_PLUG_TYPE(_f_) (((_f_) & GENMASK(4, 3)) >> 3) 276 225 #define UCSI_CABLE_PROPERTY_PLUG_TYPE_A 0 277 226 #define UCSI_CABLE_PROPERTY_PLUG_TYPE_B 1 278 227 #define UCSI_CABLE_PROPERTY_PLUG_TYPE_C 2 279 228 #define UCSI_CABLE_PROPERTY_PLUG_OTHER 3 280 - #define UCSI_CABLE_PROP_MODE_SUPPORT BIT(5) 229 + #define UCSI_CABLE_PROP_FLAG_MODE_SUPPORT BIT(5) 230 + #define UCSI_CABLE_PROP_FLAG_PD_MAJOR_REV(_f_) (((_f_) & GENMASK(7, 6)) >> 6) 231 + #define UCSI_CABLE_PROP_FLAG_PD_MAJOR_REV_AS_BCD(_f_) \ 232 + UCSI_SPEC_REVISION_TO_BCD(UCSI_CABLE_PROP_FLAG_PD_MAJOR_REV(_f_)) 281 233 u8 latency; 282 234 } __packed; 283 235 ··· 319 265 #define UCSI_CONSTAT_PARTNER_TYPE_DEBUG 5 320 266 #define UCSI_CONSTAT_PARTNER_TYPE_AUDIO 6 321 267 u32 request_data_obj; 322 - u8 pwr_status; 323 - #define UCSI_CONSTAT_BC_STATUS(_p_) ((_p_) & GENMASK(2, 0)) 268 + 269 + u8 pwr_status[3]; 270 + #define UCSI_CONSTAT_BC_STATUS(_p_) ((_p_[0]) & GENMASK(1, 0)) 324 271 #define UCSI_CONSTAT_BC_NOT_CHARGING 0 325 272 #define UCSI_CONSTAT_BC_NOMINAL_CHARGING 1 326 273 #define UCSI_CONSTAT_BC_SLOW_CHARGING 2 327 274 #define UCSI_CONSTAT_BC_TRICKLE_CHARGING 3 328 - #define UCSI_CONSTAT_PROVIDER_CAP_LIMIT(_p_) (((_p_) & GENMASK(6, 3)) >> 3) 275 + #define UCSI_CONSTAT_PROVIDER_CAP_LIMIT(_p_) (((_p_[0]) & GENMASK(5, 2)) >> 2) 329 276 #define UCSI_CONSTAT_CAP_PWR_LOWERED 0 330 277 #define UCSI_CONSTAT_CAP_PWR_BUDGET_LIMIT 1 278 + #define UCSI_CONSTAT_PROVIDER_PD_VERSION_OPER_MODE(_p_) \ 279 + ((get_unaligned_le32(_p_) & GENMASK(21, 6)) >> 6) 280 + #define UCSI_CONSTAT_ORIENTATION(_p_) (((_p_[2]) & GENMASK(6, 6)) >> 6) 281 + #define UCSI_CONSTAT_ORIENTATION_DIRECT 0 282 + #define UCSI_CONSTAT_ORIENTATION_FLIPPED 1 283 + #define UCSI_CONSTAT_SINK_PATH_STATUS(_p_) (((_p_[2]) & GENMASK(7, 7)) >> 7) 284 + #define UCSI_CONSTAT_SINK_PATH_DISABLED 0 285 + #define UCSI_CONSTAT_SINK_PATH_ENABLED 1 286 + u8 pwr_readings[9]; 287 + #define UCSI_CONSTAT_REV_CURR_PROT_STATUS(_p_) ((_p_[0]) & 0x1) 288 + #define UCSI_CONSTAT_PWR_READING_VALID(_p_) (((_p_[0]) & GENMASK(1, 1)) >> 1) 289 + #define UCSI_CONSTAT_CURRENT_SCALE(_p_) (((_p_[0]) & GENMASK(4, 2)) >> 2) 290 + #define UCSI_CONSTAT_PEAK_CURRENT(_p_) \ 291 + ((get_unaligned_le32(_p_) & GENMASK(20, 5)) >> 5) 292 + #define UCSI_CONSTAT_AVG_CURRENT(_p_) \ 293 + ((get_unaligned_le32(&(_p_)[2]) & GENMASK(20, 5)) >> 5) 294 + #define UCSI_CONSTAT_VOLTAGE_SCALE(_p_) \ 295 + ((get_unaligned_le16(&(_p_)[4]) & GENMASK(8, 5)) >> 5) 296 + #define UCSI_CONSTAT_VOLTAGE_READING(_p_) \ 297 + ((get_unaligned_le32(&(_p_)[5]) & GENMASK(16, 1)) >> 1) 298 + } __packed; 299 + 300 + /* 301 + * Data structure filled by PPM in response to GET_PD_MESSAGE command with the 302 + * Response Message Type set to Discover Identity Response. 303 + */ 304 + struct ucsi_pd_message_disc_id { 305 + u32 vdm_header; 306 + u32 id_header; 307 + u32 cert_stat; 308 + u32 product; 309 + u32 vdo[3]; 331 310 } __packed; 332 311 333 312 /* -------------------------------------------------------------------------- */ ··· 428 341 429 342 struct typec_port *port; 430 343 struct typec_partner *partner; 344 + struct typec_cable *cable; 345 + struct typec_plug *plug; 431 346 432 347 struct typec_altmode *port_altmode[UCSI_MAX_ALTMODES]; 433 348 struct typec_altmode *partner_altmode[UCSI_MAX_ALTMODES]; 349 + struct typec_altmode *plug_altmode[UCSI_MAX_ALTMODES]; 434 350 435 351 struct typec_capability typec_cap; 436 352 437 353 struct ucsi_connector_status status; 438 354 struct ucsi_connector_capability cap; 355 + struct ucsi_cable_property cable_prop; 439 356 struct power_supply *psy; 440 357 struct power_supply_desc psy_desc; 441 358 u32 rdo; ··· 455 364 struct usb_power_delivery_capabilities *partner_sink_caps; 456 365 457 366 struct usb_role_switch *usb_role_sw; 367 + 368 + /* USB PD identity */ 369 + struct usb_pd_identity partner_identity; 370 + struct usb_pd_identity cable_identity; 458 371 }; 459 372 460 373 int ucsi_send_command(struct ucsi *ucsi, u64 command,
+84 -8
drivers/usb/typec/ucsi/ucsi_ccg.c
··· 192 192 bool checked; 193 193 } __packed; 194 194 195 + #define CCGX_MESSAGE_IN_MAX 4 196 + struct op_region { 197 + __le32 cci; 198 + __le32 message_in[CCGX_MESSAGE_IN_MAX]; 199 + }; 200 + 195 201 struct ucsi_ccg { 196 202 struct device *dev; 197 203 struct ucsi *ucsi; ··· 228 222 bool has_multiple_dp; 229 223 struct ucsi_ccg_altmode orig[UCSI_MAX_ALTMODES]; 230 224 struct ucsi_ccg_altmode updated[UCSI_MAX_ALTMODES]; 225 + 226 + /* 227 + * This spinlock protects op_data which includes CCI and MESSAGE_IN that 228 + * will be updated in ISR 229 + */ 230 + spinlock_t op_lock; 231 + struct op_region op_data; 231 232 }; 232 233 233 234 static int ccg_read(struct ucsi_ccg *uc, u16 rab, u8 *data, u32 len) ··· 318 305 return 0; 319 306 } 320 307 308 + static int ccg_op_region_update(struct ucsi_ccg *uc, u32 cci) 309 + { 310 + u16 reg = CCGX_RAB_UCSI_DATA_BLOCK(UCSI_MESSAGE_IN); 311 + struct op_region *data = &uc->op_data; 312 + unsigned char *buf; 313 + size_t size = sizeof(data->message_in); 314 + 315 + buf = kzalloc(size, GFP_ATOMIC); 316 + if (!buf) 317 + return -ENOMEM; 318 + if (UCSI_CCI_LENGTH(cci)) { 319 + int ret = ccg_read(uc, reg, (void *)buf, size); 320 + 321 + if (ret) { 322 + kfree(buf); 323 + return ret; 324 + } 325 + } 326 + 327 + spin_lock(&uc->op_lock); 328 + data->cci = cpu_to_le32(cci); 329 + if (UCSI_CCI_LENGTH(cci)) 330 + memcpy(&data->message_in, buf, size); 331 + spin_unlock(&uc->op_lock); 332 + kfree(buf); 333 + return 0; 334 + } 335 + 321 336 static int ucsi_ccg_init(struct ucsi_ccg *uc) 322 337 { 323 338 unsigned int count = 10; 324 339 u8 data; 325 340 int status; 341 + 342 + spin_lock_init(&uc->op_lock); 326 343 327 344 data = CCGX_RAB_UCSI_CONTROL_STOP; 328 345 status = ccg_write(uc, CCGX_RAB_UCSI_CONTROL, &data, sizeof(data)); ··· 563 520 u16 reg = CCGX_RAB_UCSI_DATA_BLOCK(offset); 564 521 struct ucsi_capability *cap; 565 522 struct ucsi_altmode *alt; 566 - int ret; 523 + int ret = 0; 567 524 568 - ret = ccg_read(uc, reg, val, val_len); 525 + if (offset == UCSI_CCI) { 526 + spin_lock(&uc->op_lock); 527 + memcpy(val, &(uc->op_data).cci, val_len); 528 + spin_unlock(&uc->op_lock); 529 + } else if (offset == UCSI_MESSAGE_IN) { 530 + spin_lock(&uc->op_lock); 531 + memcpy(val, &(uc->op_data).message_in, val_len); 532 + spin_unlock(&uc->op_lock); 533 + } else { 534 + ret = ccg_read(uc, reg, val, val_len); 535 + } 536 + 569 537 if (ret) 570 538 return ret; 571 539 ··· 613 559 static int ucsi_ccg_async_write(struct ucsi *ucsi, unsigned int offset, 614 560 const void *val, size_t val_len) 615 561 { 562 + struct ucsi_ccg *uc = ucsi_get_drvdata(ucsi); 616 563 u16 reg = CCGX_RAB_UCSI_DATA_BLOCK(offset); 617 564 618 - return ccg_write(ucsi_get_drvdata(ucsi), reg, val, val_len); 565 + /* 566 + * UCSI may read CCI instantly after async_write, 567 + * clear CCI to avoid caller getting wrong data before we get CCI from ISR 568 + */ 569 + spin_lock(&uc->op_lock); 570 + uc->op_data.cci = 0; 571 + spin_unlock(&uc->op_lock); 572 + 573 + return ccg_write(uc, reg, val, val_len); 619 574 } 620 575 621 576 static int ucsi_ccg_sync_write(struct ucsi *ucsi, unsigned int offset, ··· 678 615 u16 reg = CCGX_RAB_UCSI_DATA_BLOCK(UCSI_CCI); 679 616 struct ucsi_ccg *uc = data; 680 617 u8 intr_reg; 681 - u32 cci; 682 - int ret; 618 + u32 cci = 0; 619 + int ret = 0; 683 620 684 621 ret = ccg_read(uc, CCGX_RAB_INTR_REG, &intr_reg, sizeof(intr_reg)); 685 622 if (ret) 686 623 return ret; 624 + 625 + if (!intr_reg) 626 + return IRQ_HANDLED; 627 + else if (!(intr_reg & UCSI_READ_INT)) 628 + goto err_clear_irq; 687 629 688 630 ret = ccg_read(uc, reg, (void *)&cci, sizeof(cci)); 689 631 if (ret) ··· 697 629 if (UCSI_CCI_CONNECTOR(cci)) 698 630 ucsi_connector_change(uc->ucsi, UCSI_CCI_CONNECTOR(cci)); 699 631 700 - if (test_bit(DEV_CMD_PENDING, &uc->flags) && 701 - cci & (UCSI_CCI_ACK_COMPLETE | UCSI_CCI_COMMAND_COMPLETE)) 702 - complete(&uc->complete); 632 + /* 633 + * As per CCGx UCSI interface guide, copy CCI and MESSAGE_IN 634 + * to the OpRegion before clear the UCSI interrupt 635 + */ 636 + ret = ccg_op_region_update(uc, cci); 637 + if (ret) 638 + goto err_clear_irq; 703 639 704 640 err_clear_irq: 705 641 ccg_write(uc, CCGX_RAB_INTR_REG, &intr_reg, sizeof(intr_reg)); 642 + 643 + if (!ret && test_bit(DEV_CMD_PENDING, &uc->flags) && 644 + cci & (UCSI_CCI_ACK_COMPLETE | UCSI_CCI_COMMAND_COMPLETE)) 645 + complete(&uc->complete); 706 646 707 647 return IRQ_HANDLED; 708 648 }
+1
drivers/usb/typec/ucsi/ucsi_glink.c
··· 298 298 } 299 299 300 300 static const struct of_device_id pmic_glink_ucsi_of_quirks[] = { 301 + { .compatible = "qcom,qcm6490-pmic-glink", .data = (void *)UCSI_NO_PARTNER_PDOS, }, 301 302 { .compatible = "qcom,sc8180x-pmic-glink", .data = (void *)UCSI_NO_PARTNER_PDOS, }, 302 303 { .compatible = "qcom,sc8280xp-pmic-glink", .data = (void *)UCSI_NO_PARTNER_PDOS, }, 303 304 { .compatible = "qcom,sm8350-pmic-glink", .data = (void *)UCSI_NO_PARTNER_PDOS, },
+21
include/linux/phy/phy.h
··· 122 122 union phy_configure_opts *opts); 123 123 int (*reset)(struct phy *phy); 124 124 int (*calibrate)(struct phy *phy); 125 + 126 + /* notify phy connect status change */ 127 + int (*connect)(struct phy *phy, int port); 128 + int (*disconnect)(struct phy *phy, int port); 129 + 125 130 void (*release)(struct phy *phy); 126 131 struct module *owner; 127 132 }; ··· 248 243 } 249 244 int phy_reset(struct phy *phy); 250 245 int phy_calibrate(struct phy *phy); 246 + int phy_notify_connect(struct phy *phy, int port); 247 + int phy_notify_disconnect(struct phy *phy, int port); 251 248 static inline int phy_get_bus_width(struct phy *phy) 252 249 { 253 250 return phy->attrs.bus_width; ··· 397 390 } 398 391 399 392 static inline int phy_calibrate(struct phy *phy) 393 + { 394 + if (!phy) 395 + return 0; 396 + return -ENOSYS; 397 + } 398 + 399 + static inline int phy_notify_connect(struct phy *phy, int index) 400 + { 401 + if (!phy) 402 + return 0; 403 + return -ENOSYS; 404 + } 405 + 406 + static inline int phy_notify_disconnect(struct phy *phy, int index) 400 407 { 401 408 if (!phy) 402 409 return 0;
+1
include/linux/phy/tegra/xusb.h
··· 26 26 int tegra_phy_xusb_utmi_port_reset(struct phy *phy); 27 27 int tegra_xusb_padctl_get_usb3_companion(struct tegra_xusb_padctl *padctl, 28 28 unsigned int port); 29 + int tegra_xusb_padctl_get_port_number(struct phy *phy); 29 30 int tegra_xusb_padctl_enable_phy_sleepwalk(struct tegra_xusb_padctl *padctl, struct phy *phy, 30 31 enum usb_device_speed speed); 31 32 int tegra_xusb_padctl_disable_phy_sleepwalk(struct tegra_xusb_padctl *padctl, struct phy *phy);
+2 -2
include/linux/thunderbolt.h
··· 87 87 }; 88 88 89 89 extern const struct bus_type tb_bus_type; 90 - extern struct device_type tb_service_type; 91 - extern struct device_type tb_xdomain_type; 90 + extern const struct device_type tb_service_type; 91 + extern const struct device_type tb_xdomain_type; 92 92 93 93 #define TB_LINKS_PER_PHY_PORT 2 94 94
+2 -2
include/linux/usb/audio-v2.h
··· 82 82 #define UAC_CLOCK_SOURCE_TYPE_INT_PROG 0x3 83 83 #define UAC_CLOCK_SOURCE_SYNCED_TO_SOF (1 << 2) 84 84 85 - /* 4.7.2.2 Clock Source Descriptor */ 85 + /* 4.7.2.2 Clock Selector Descriptor */ 86 86 87 87 struct uac_clock_selector_descriptor { 88 88 __u8 bLength; ··· 91 91 __u8 bClockID; 92 92 __u8 bNrInPins; 93 93 __u8 baCSourceID[]; 94 - /* bmControls and iClockSource omitted */ 94 + /* bmControls and iClockSelector omitted */ 95 95 } __attribute__((packed)); 96 96 97 97 /* 4.7.2.3 Clock Multiplier Descriptor */
+2
include/linux/usb/gadget.h
··· 52 52 * @short_not_ok: When reading data, makes short packets be 53 53 * treated as errors (queue stops advancing till cleanup). 54 54 * @dma_mapped: Indicates if request has been mapped to DMA (internal) 55 + * @sg_was_mapped: Set if the scatterlist has been mapped before the request 55 56 * @complete: Function called when request completes, so this request and 56 57 * its buffer may be re-used. The function will always be called with 57 58 * interrupts disabled, and it must not sleep. ··· 112 111 unsigned zero:1; 113 112 unsigned short_not_ok:1; 114 113 unsigned dma_mapped:1; 114 + unsigned sg_was_mapped:1; 115 115 116 116 void (*complete)(struct usb_ep *ep, 117 117 struct usb_request *req);
+7
include/linux/usb/of.h
··· 6 6 #ifndef __LINUX_USB_OF_H 7 7 #define __LINUX_USB_OF_H 8 8 9 + #include <linux/usb.h> 9 10 #include <linux/usb/ch9.h> 10 11 #include <linux/usb/otg.h> 11 12 #include <linux/usb/phy.h> ··· 18 17 bool of_usb_host_tpl_support(struct device_node *np); 19 18 int of_usb_update_otg_caps(struct device_node *np, 20 19 struct usb_otg_caps *otg_caps); 20 + enum usb_port_connect_type usb_of_get_connect_type(struct usb_device *hub, int port1); 21 21 struct device_node *usb_of_get_device_node(struct usb_device *hub, int port1); 22 22 bool usb_of_has_combined_node(struct usb_device *udev); 23 23 struct device_node *usb_of_get_interface_node(struct usb_device *udev, ··· 38 36 struct usb_otg_caps *otg_caps) 39 37 { 40 38 return 0; 39 + } 40 + static inline enum usb_port_connect_type 41 + usb_of_get_connect_type(const struct usb_device *hub, int port1) 42 + { 43 + return USB_PORT_CONNECT_TYPE_UNKNOWN; 41 44 } 42 45 static inline struct device_node * 43 46 usb_of_get_device_node(struct usb_device *hub, int port1)
+1
include/linux/usb/pd.h
··· 483 483 #define PD_T_BIST_CONT_MODE 50 /* 30 - 60 ms */ 484 484 #define PD_T_SINK_TX 16 /* 16 - 20 ms */ 485 485 #define PD_T_CHUNK_NOT_SUPP 42 /* 40 - 50 ms */ 486 + #define PD_T_VCONN_STABLE 50 486 487 487 488 #define PD_T_DRP_TRY 100 /* 75 - 150 ms */ 488 489 #define PD_T_DRP_TRYWAIT 600 /* 400 - 800 ms */
+10 -3
include/linux/usb/pd_vdo.h
··· 7 7 #define __LINUX_USB_PD_VDO_H 8 8 9 9 #include "pd.h" 10 + #include <linux/bitfield.h> 10 11 11 12 /* 12 13 * VDO : Vendor Defined Message Object ··· 87 86 * 88 87 * Request is simply properly formatted SVDM header 89 88 * 90 - * Response is 4 data objects: 89 + * Response is 4 data objects for Power Delivery 2.0 and Passive Cables for 90 + * Power Delivery 3.0. Active Cables in Power Delivery 3.0 have 5 data objects. 91 91 * [0] :: SVDM header 92 92 * [1] :: Identitiy header 93 93 * [2] :: Cert Stat VDO 94 94 * [3] :: (Product | Cable) VDO 95 + * [4] :: Cable VDO 1 95 96 * [4] :: AMA VDO 97 + * [5] :: Cable VDO 2 96 98 * 97 99 */ 98 100 #define VDO_INDEX_HDR 0 ··· 104 100 #define VDO_INDEX_CABLE 3 105 101 #define VDO_INDEX_PRODUCT 3 106 102 #define VDO_INDEX_AMA 4 103 + #define VDO_INDEX_CABLE_1 4 104 + #define VDO_INDEX_CABLE_2 5 107 105 108 106 /* 109 107 * SVDM Identity Header ··· 156 150 #define PD_IDH_MODAL_SUPP(vdo) ((vdo) & (1 << 26)) 157 151 #define PD_IDH_DFP_PTYPE(vdo) (((vdo) >> 23) & 0x7) 158 152 #define PD_IDH_CONN_TYPE(vdo) (((vdo) >> 21) & 0x3) 153 + #define PD_IDH_HOST_SUPP(vdo) ((vdo) & (1 << 31)) 159 154 160 155 /* 161 156 * Cert Stat VDO ··· 189 182 * <5:3> :: Alternate modes 190 183 * <2:0> :: USB highest speed 191 184 */ 192 - #define PD_VDO_UFP_DEVCAP(vdo) (((vdo) & GENMASK(27, 24)) >> 24) 185 + #define PD_VDO_UFP_DEVCAP(vdo) FIELD_GET(GENMASK(27, 24), vdo) 193 186 194 187 /* UFP VDO Version */ 195 188 #define UFP_VDO_VER1_2 2 ··· 248 241 * <21:5> :: Reserved 249 242 * <4:0> :: Port number 250 243 */ 251 - #define PD_VDO_DFP_HOSTCAP(vdo) (((vdo) & GENMASK(26, 24)) >> 24) 244 + #define PD_VDO_DFP_HOSTCAP(vdo) FIELD_GET(GENMASK(26, 24), vdo) 252 245 253 246 #define DFP_VDO_VER1_1 1 254 247 #define HOST_USB2_CAPABLE BIT(0)
+13
include/linux/usb/tcpci.h
··· 145 145 #define TCPC_RX_BYTE_CNT 0x30 146 146 #define TCPC_RX_BUF_FRAME_TYPE 0x31 147 147 #define TCPC_RX_BUF_FRAME_TYPE_SOP 0 148 + #define TCPC_RX_BUF_FRAME_TYPE_SOP1 1 148 149 #define TCPC_RX_HDR 0x32 149 150 #define TCPC_RX_DATA 0x34 /* through 0x4f */ 150 151 ··· 199 198 * Chip level drivers are expected to check for contaminant and call 200 199 * tcpm_clean_port when the port is clean to put the port back into 201 200 * toggling state. 201 + * @cable_comm_capable 202 + * optional; Set when TCPC can communicate with cable plugs over SOP' 203 + * @attempt_vconn_swap_discovery: 204 + * Optional; The callback is called by the TCPM when the result of 205 + * a Discover Identity request indicates that the port partner is 206 + * a receptacle capable of modal operation. Chip level TCPCI drivers 207 + * can implement their own policy to determine if and when a Vconn 208 + * swap following Discover Identity on SOP' occurs. 209 + * Return true when the TCPM is allowed to request a Vconn swap 210 + * after Discovery Identity on SOP. 202 211 */ 203 212 struct tcpci_data { 204 213 struct regmap *regmap; 205 214 unsigned char TX_BUF_BYTE_x_hidden:1; 206 215 unsigned char auto_discharge_disconnect:1; 207 216 unsigned char vbus_vsafe0v:1; 217 + unsigned char cable_comm_capable:1; 208 218 209 219 int (*init)(struct tcpci *tcpci, struct tcpci_data *data); 210 220 int (*set_vconn)(struct tcpci *tcpci, struct tcpci_data *data, ··· 227 215 void (*set_partner_usb_comm_capable)(struct tcpci *tcpci, struct tcpci_data *data, 228 216 bool capable); 229 217 void (*check_contaminant)(struct tcpci *tcpci, struct tcpci_data *data); 218 + bool (*attempt_vconn_swap_discovery)(struct tcpci *tcpci, struct tcpci_data *data); 230 219 }; 231 220 232 221 struct tcpci *tcpci_register_port(struct device *dev, struct tcpci_data *data);
+17 -1
include/linux/usb/tcpm.h
··· 119 119 * at the end of the deboumce period or when the port is still 120 120 * toggling. Chip level drivers are expected to check for contaminant 121 121 * and call tcpm_clean_port when the port is clean. 122 + * @cable_comm_capable 123 + * Optional; Returns whether cable communication over SOP' is supported 124 + * by the tcpc 125 + * @attempt_vconn_swap_discovery: 126 + * Optional; The callback is called by the TCPM when the result of 127 + * a Discover Identity request indicates that the port partner is 128 + * a receptacle capable of modal operation. Chip level TCPCI drivers 129 + * can implement their own policy to determine if and when a Vconn 130 + * swap following Discover Identity on SOP' occurs. 131 + * Return true when the TCPM is allowed to request a Vconn swap 132 + * after Discovery Identity on SOP. 122 133 */ 123 134 struct tcpc_dev { 124 135 struct fwnode_handle *fwnode; ··· 144 133 enum typec_cc_status *cc2); 145 134 int (*set_polarity)(struct tcpc_dev *dev, 146 135 enum typec_cc_polarity polarity); 136 + int (*set_orientation)(struct tcpc_dev *dev, 137 + enum typec_orientation orientation); 147 138 int (*set_vconn)(struct tcpc_dev *dev, bool on); 148 139 int (*set_vbus)(struct tcpc_dev *dev, bool on, bool charge); 149 140 int (*set_current_limit)(struct tcpc_dev *dev, u32 max_ma, u32 mv); ··· 167 154 bool (*is_vbus_vsafe0v)(struct tcpc_dev *dev); 168 155 void (*set_partner_usb_comm_capable)(struct tcpc_dev *dev, bool enable); 169 156 void (*check_contaminant)(struct tcpc_dev *dev); 157 + bool (*cable_comm_capable)(struct tcpc_dev *dev); 158 + bool (*attempt_vconn_swap_discovery)(struct tcpc_dev *dev); 170 159 }; 171 160 172 161 struct tcpm_port; ··· 181 166 void tcpm_sink_frs(struct tcpm_port *port); 182 167 void tcpm_sourcing_vbus(struct tcpm_port *port); 183 168 void tcpm_pd_receive(struct tcpm_port *port, 184 - const struct pd_message *msg); 169 + const struct pd_message *msg, 170 + enum tcpm_transmit_type rx_sop_type); 185 171 void tcpm_pd_transmit_complete(struct tcpm_port *port, 186 172 enum tcpm_transmit_status status); 187 173 void tcpm_pd_hard_reset(struct tcpm_port *port);
+7
include/linux/usb/typec.h
··· 18 18 struct typec_plug; 19 19 struct typec_port; 20 20 struct typec_altmode_ops; 21 + struct typec_cable_ops; 21 22 22 23 struct fwnode_handle; 23 24 struct device; ··· 157 156 void typec_port_register_altmodes(struct typec_port *port, 158 157 const struct typec_altmode_ops *ops, void *drvdata, 159 158 struct typec_altmode **altmodes, size_t n); 159 + 160 + void typec_port_register_cable_ops(struct typec_altmode **altmodes, int max_altmodes, 161 + const struct typec_cable_ops *ops); 160 162 161 163 void typec_unregister_altmode(struct typec_altmode *altmode); 162 164 ··· 336 332 void typec_partner_set_svdm_version(struct typec_partner *partner, 337 333 enum usb_pd_svdm_ver svdm_version); 338 334 int typec_get_negotiated_svdm_version(struct typec_port *port); 335 + 336 + int typec_get_cable_svdm_version(struct typec_port *port); 337 + void typec_cable_set_svdm_version(struct typec_cable *cable, enum usb_pd_svdm_ver svdm_version); 339 338 340 339 struct usb_power_delivery *typec_partner_usb_power_delivery_register(struct typec_partner *partner, 341 340 struct usb_power_delivery_desc *desc);
+30
include/linux/usb/typec_altmode.h
··· 20 20 * @active: Tells has the mode been entered or not 21 21 * @desc: Optional human readable description of the mode 22 22 * @ops: Operations vector from the driver 23 + * @cable_ops: Cable operations vector from the driver. 23 24 */ 24 25 struct typec_altmode { 25 26 struct device dev; ··· 31 30 32 31 char *desc; 33 32 const struct typec_altmode_ops *ops; 33 + const struct typec_cable_ops *cable_ops; 34 34 }; 35 35 36 36 #define to_typec_altmode(d) container_of(d, struct typec_altmode, dev) ··· 76 74 void *data); 77 75 const struct typec_altmode * 78 76 typec_altmode_get_partner(struct typec_altmode *altmode); 77 + 78 + /** 79 + * struct typec_cable_ops - Cable alternate mode operations vector 80 + * @enter: Operations to be executed with Enter Mode Command 81 + * @exit: Operations to be executed with Exit Mode Command 82 + * @vdm: Callback for SVID specific commands 83 + */ 84 + struct typec_cable_ops { 85 + int (*enter)(struct typec_altmode *altmode, enum typec_plug_index sop, u32 *vdo); 86 + int (*exit)(struct typec_altmode *altmode, enum typec_plug_index sop); 87 + int (*vdm)(struct typec_altmode *altmode, enum typec_plug_index sop, 88 + const u32 hdr, const u32 *vdo, int cnt); 89 + }; 90 + 91 + int typec_cable_altmode_enter(struct typec_altmode *altmode, enum typec_plug_index sop, u32 *vdo); 92 + int typec_cable_altmode_exit(struct typec_altmode *altmode, enum typec_plug_index sop); 93 + int typec_cable_altmode_vdm(struct typec_altmode *altmode, enum typec_plug_index sop, 94 + const u32 header, const u32 *vdo, int count); 95 + 96 + /** 97 + * typec_altmode_get_cable_svdm_version - Get negotiated SVDM version for cable plug 98 + * @altmode: Handle to the alternate mode 99 + */ 100 + static inline int 101 + typec_altmode_get_cable_svdm_version(struct typec_altmode *altmode) 102 + { 103 + return typec_get_cable_svdm_version(typec_altmode2port(altmode)); 104 + } 79 105 80 106 /* 81 107 * These are the connector states (USB, Safe and Alt Mode) defined in USB Type-C
+6 -5
include/linux/usb/typec_dp.h
··· 3 3 #define __USB_TYPEC_DP_H 4 4 5 5 #include <linux/usb/typec_altmode.h> 6 + #include <linux/bitfield.h> 6 7 7 8 #define USB_TYPEC_DP_SID 0xff01 8 9 /* USB IF has not assigned a Standard ID (SID) for VirtualLink, ··· 68 67 #define DP_CAP_UFP_D 1 69 68 #define DP_CAP_DFP_D 2 70 69 #define DP_CAP_DFP_D_AND_UFP_D 3 71 - #define DP_CAP_DP_SIGNALLING(_cap_) (((_cap_) & GENMASK(5, 2)) >> 2) 70 + #define DP_CAP_DP_SIGNALLING(_cap_) FIELD_GET(GENMASK(5, 2), _cap_) 72 71 #define DP_CAP_SIGNALLING_HBR3 1 73 72 #define DP_CAP_SIGNALLING_UHBR10 2 74 73 #define DP_CAP_SIGNALLING_UHBR20 3 75 74 #define DP_CAP_RECEPTACLE BIT(6) 76 75 #define DP_CAP_USB BIT(7) 77 - #define DP_CAP_DFP_D_PIN_ASSIGN(_cap_) (((_cap_) & GENMASK(15, 8)) >> 8) 78 - #define DP_CAP_UFP_D_PIN_ASSIGN(_cap_) (((_cap_) & GENMASK(23, 16)) >> 16) 76 + #define DP_CAP_DFP_D_PIN_ASSIGN(_cap_) FIELD_GET(GENMASK(15, 8), _cap_) 77 + #define DP_CAP_UFP_D_PIN_ASSIGN(_cap_) FIELD_GET(GENMASK(23, 16), _cap_) 79 78 /* Get pin assignment taking plug & receptacle into consideration */ 80 79 #define DP_CAP_PIN_ASSIGN_UFP_D(_cap_) ((_cap_ & DP_CAP_RECEPTACLE) ? \ 81 80 DP_CAP_UFP_D_PIN_ASSIGN(_cap_) : DP_CAP_DFP_D_PIN_ASSIGN(_cap_)) 82 81 #define DP_CAP_PIN_ASSIGN_DFP_D(_cap_) ((_cap_ & DP_CAP_RECEPTACLE) ? \ 83 82 DP_CAP_DFP_D_PIN_ASSIGN(_cap_) : DP_CAP_UFP_D_PIN_ASSIGN(_cap_)) 84 83 #define DP_CAP_UHBR_13_5_SUPPORT BIT(26) 85 - #define DP_CAP_CABLE_TYPE(_cap_) (((_cap_) & GENMASK(29, 28)) >> 28) 84 + #define DP_CAP_CABLE_TYPE(_cap_) FIELD_GET(GENMASK(29, 28), _cap_) 86 85 #define DP_CAP_CABLE_TYPE_PASSIVE 0 87 86 #define DP_CAP_CABLE_TYPE_RE_TIMER 1 88 87 #define DP_CAP_CABLE_TYPE_RE_DRIVER 2 ··· 117 116 118 117 /* Helper for setting/getting the pin assignment value to the configuration */ 119 118 #define DP_CONF_SET_PIN_ASSIGN(_a_) ((_a_) << 8) 120 - #define DP_CONF_GET_PIN_ASSIGN(_conf_) (((_conf_) & GENMASK(15, 8)) >> 8) 119 + #define DP_CONF_GET_PIN_ASSIGN(_conf_) FIELD_GET(GENMASK(15, 8), _conf_) 121 120 #define DP_CONF_UHBR13_5_SUPPORT BIT(26) 122 121 #define DP_CONF_CABLE_TYPE_MASK GENMASK(29, 28) 123 122 #define DP_CONF_CABLE_TYPE_SHIFT 28
+5 -4
include/linux/usb/typec_tbt.h
··· 3 3 #define __USB_TYPEC_TBT_H 4 4 5 5 #include <linux/usb/typec_altmode.h> 6 + #include <linux/bitfield.h> 6 7 7 8 #define USB_TYPEC_VENDOR_INTEL 0x8087 8 9 /* Alias for convenience */ ··· 26 25 27 26 /* TBT3 Device Discover Mode VDO bits */ 28 27 #define TBT_MODE BIT(0) 29 - #define TBT_ADAPTER(_vdo_) (((_vdo_) & BIT(16)) >> 16) 28 + #define TBT_ADAPTER(_vdo_) FIELD_GET(BIT(16), _vdo_) 30 29 #define TBT_ADAPTER_LEGACY 0 31 30 #define TBT_ADAPTER_TBT3 1 32 31 #define TBT_INTEL_SPECIFIC_B0 BIT(26) ··· 36 35 #define TBT_SET_ADAPTER(a) (((a) & 1) << 16) 37 36 38 37 /* TBT3 Cable Discover Mode VDO bits */ 39 - #define TBT_CABLE_SPEED(_vdo_) (((_vdo_) & GENMASK(18, 16)) >> 16) 38 + #define TBT_CABLE_SPEED(_vdo_) FIELD_GET(GENMASK(18, 16), _vdo_) 40 39 #define TBT_CABLE_USB3_GEN1 1 41 40 #define TBT_CABLE_USB3_PASSIVE 2 42 41 #define TBT_CABLE_10_AND_20GBPS 3 43 - #define TBT_CABLE_ROUNDED_SUPPORT(_vdo_) \ 44 - (((_vdo_) & GENMASK(20, 19)) >> 19) 42 + #define TBT_CABLE_ROUNDED_SUPPORT(_vdo_) FIELD_GET(GENMASK(20, 19), _vdo_) 43 + 45 44 #define TBT_GEN3_NON_ROUNDED 0 46 45 #define TBT_GEN3_GEN4_ROUNDED_NON_ROUNDED 1 47 46 #define TBT_CABLE_OPTICAL BIT(21)
+2
include/uapi/linux/usb/ch9.h
··· 763 763 #define USB_OTG_SRP (1 << 0) 764 764 #define USB_OTG_HNP (1 << 1) /* swap host/device roles */ 765 765 #define USB_OTG_ADP (1 << 2) /* support ADP */ 766 + /* OTG 3.0 */ 767 + #define USB_OTG_RSP (1 << 3) /* support RSP */ 766 768 767 769 #define OTG_STS_SELECTOR 0xF000 /* OTG status selector */ 768 770 /*-------------------------------------------------------------------------*/
+41
include/uapi/linux/usb/functionfs.h
··· 86 86 __le16 wPropertyNameLength; 87 87 } __attribute__((packed)); 88 88 89 + /* Flags for usb_ffs_dmabuf_transfer_req->flags (none for now) */ 90 + #define USB_FFS_DMABUF_TRANSFER_MASK 0x0 91 + 92 + /** 93 + * struct usb_ffs_dmabuf_transfer_req - Transfer request for a DMABUF object 94 + * @fd: file descriptor of the DMABUF object 95 + * @flags: one or more USB_FFS_DMABUF_TRANSFER_* flags 96 + * @length: number of bytes used in this DMABUF for the data transfer. 97 + * Should generally be set to the DMABUF's size. 98 + */ 99 + struct usb_ffs_dmabuf_transfer_req { 100 + int fd; 101 + __u32 flags; 102 + __u64 length; 103 + } __attribute__((packed)); 104 + 89 105 #ifndef __KERNEL__ 90 106 91 107 /* ··· 306 290 #define FUNCTIONFS_ENDPOINT_DESC _IOR('g', 130, \ 307 291 struct usb_endpoint_descriptor) 308 292 293 + /* 294 + * Attach the DMABUF object, identified by its file descriptor, to the 295 + * data endpoint. Returns zero on success, and a negative errno value 296 + * on error. 297 + */ 298 + #define FUNCTIONFS_DMABUF_ATTACH _IOW('g', 131, int) 309 299 300 + 301 + /* 302 + * Detach the given DMABUF object, identified by its file descriptor, 303 + * from the data endpoint. Returns zero on success, and a negative 304 + * errno value on error. Note that closing the endpoint's file 305 + * descriptor will automatically detach all attached DMABUFs. 306 + */ 307 + #define FUNCTIONFS_DMABUF_DETACH _IOW('g', 132, int) 308 + 309 + /* 310 + * Enqueue the previously attached DMABUF to the transfer queue. 311 + * The argument is a structure that packs the DMABUF's file descriptor, 312 + * the size in bytes to transfer (which should generally correspond to 313 + * the size of the DMABUF), and a 'flags' field which is unused 314 + * for now. Returns zero on success, and a negative errno value on 315 + * error. 316 + */ 317 + #define FUNCTIONFS_DMABUF_TRANSFER _IOW('g', 133, \ 318 + struct usb_ffs_dmabuf_transfer_req) 310 319 311 320 #endif /* _UAPI__LINUX_FUNCTIONFS_H__ */
+1
tools/testing/selftests/Makefile
··· 13 13 TARGETS += cpufreq 14 14 TARGETS += cpu-hotplug 15 15 TARGETS += damon 16 + TARGETS += devices 16 17 TARGETS += dmabuf-heaps 17 18 TARGETS += drivers/dma-buf 18 19 TARGETS += drivers/s390x/uvdevice
+4
tools/testing/selftests/devices/Makefile
··· 1 + TEST_PROGS := test_discoverable_devices.py 2 + TEST_FILES := boards ksft.py 3 + 4 + include ../lib.mk
+40
tools/testing/selftests/devices/boards/Dell Inc.,XPS 13 9300.yaml
··· 1 + # SPDX-License-Identifier: GPL-2.0 2 + # 3 + # This is the device definition for the XPS 13 9300. 4 + # The filename "Dell Inc.,XPS 13 9300" was chosen following the format 5 + # "Vendor,Product", where Vendor comes from 6 + # /sys/devices/virtual/dmi/id/sys_vendor, and Product comes from 7 + # /sys/devices/virtual/dmi/id/product_name. 8 + # 9 + # See google,spherion.yaml for more information. 10 + # 11 + - type: pci-controller 12 + # This machine has a single PCI host controller so it's valid to not have any 13 + # key to identify the controller. If it had more than one controller, the UID 14 + # of the controller from ACPI could be used to distinguish as follows: 15 + #acpi-uid: 0 16 + devices: 17 + - path: 14.0 18 + type: usb-controller 19 + usb-version: 2 20 + devices: 21 + - path: 9 22 + name: camera 23 + interfaces: [0, 1, 2, 3] 24 + - path: 10 25 + name: bluetooth 26 + interfaces: [0, 1] 27 + - path: 2.0 28 + name: gpu 29 + - path: 4.0 30 + name: thermal 31 + - path: 12.0 32 + name: sensors 33 + - path: 14.3 34 + name: wifi 35 + - path: 1d.0/0.0 36 + name: ssd 37 + - path: 1d.7/0.0 38 + name: sdcard-reader 39 + - path: 1f.3 40 + name: audio
+50
tools/testing/selftests/devices/boards/google,spherion.yaml
··· 1 + # SPDX-License-Identifier: GPL-2.0 2 + # 3 + # This is the device definition for the Google Spherion Chromebook. 4 + # The filename "google,spherion" comes from the Devicetree compatible, so this 5 + # file will be automatically used when the test is run on that machine. 6 + # 7 + # The top-level is a list of controllers, either for USB or PCI(e). 8 + # Every controller needs to have a 'type' key set to either 'usb-controller' or 9 + # 'pci-controller'. 10 + # Every controller needs to be uniquely identified on the platform. To achieve 11 + # this, several optional keys can be used: 12 + # - dt-mmio: identify the MMIO address of the controller as defined in the 13 + # Devicetree. 14 + # - usb-version: for USB controllers to differentiate between USB3 and USB2 15 + # buses sharing the same controller. 16 + # - acpi-uid: _UID property of the controller as supplied by the ACPI. Useful to 17 + # distinguish between multiple PCI host controllers. 18 + # 19 + # The 'devices' key defines a list of devices that are accessible under that 20 + # controller. A device might be a leaf device or another controller (see 21 + # 'Dell Inc.,XPS 13 9300.yaml'). 22 + # 23 + # The 'path' key is needed for every child device (that is, not top-level) to 24 + # define how to reach this device from the parent controller. For USB devices it 25 + # follows the format \d(.\d)* and denotes the port in the hub at each level in 26 + # the USB topology. For PCI devices it follows the format \d.\d(/\d.\d)* 27 + # denoting the device (identified by device-function pair) at each level in the 28 + # PCI topology. 29 + # 30 + # The 'name' key is used in the leaf devices to name the device for clarity in 31 + # the test output. 32 + # 33 + # For USB leaf devices, the 'interfaces' key should contain a list of the 34 + # interfaces in that device that should be bound to a driver. 35 + # 36 + - type: usb-controller 37 + dt-mmio: 11200000 38 + usb-version: 2 39 + devices: 40 + - path: 1.4.1 41 + interfaces: [0, 1] 42 + name: camera 43 + - path: 1.4.2 44 + interfaces: [0, 1] 45 + name: bluetooth 46 + - type: pci-controller 47 + dt-mmio: 11230000 48 + devices: 49 + - path: 0.0/0.0 50 + name: wifi
+90
tools/testing/selftests/devices/ksft.py
··· 1 + # SPDX-License-Identifier: GPL-2.0 2 + # 3 + # Copyright (c) 2023 Collabora Ltd 4 + # 5 + # Kselftest helpers for outputting in KTAP format. Based on kselftest.h. 6 + # 7 + 8 + import sys 9 + 10 + ksft_cnt = {"pass": 0, "fail": 0, "skip": 0} 11 + ksft_num_tests = 0 12 + ksft_test_number = 1 13 + 14 + KSFT_PASS = 0 15 + KSFT_FAIL = 1 16 + KSFT_SKIP = 4 17 + 18 + 19 + def print_header(): 20 + print("TAP version 13") 21 + 22 + 23 + def set_plan(num_tests): 24 + global ksft_num_tests 25 + ksft_num_tests = num_tests 26 + print("1..{}".format(num_tests)) 27 + 28 + 29 + def print_cnts(): 30 + print( 31 + f"# Totals: pass:{ksft_cnt['pass']} fail:{ksft_cnt['fail']} xfail:0 xpass:0 skip:{ksft_cnt['skip']} error:0" 32 + ) 33 + 34 + 35 + def print_msg(msg): 36 + print(f"# {msg}") 37 + 38 + 39 + def _test_print(result, description, directive=None): 40 + if directive: 41 + directive_str = f"# {directive}" 42 + else: 43 + directive_str = "" 44 + 45 + global ksft_test_number 46 + print(f"{result} {ksft_test_number} {description} {directive_str}") 47 + ksft_test_number += 1 48 + 49 + 50 + def test_result_pass(description): 51 + _test_print("ok", description) 52 + ksft_cnt["pass"] += 1 53 + 54 + 55 + def test_result_fail(description): 56 + _test_print("not ok", description) 57 + ksft_cnt["fail"] += 1 58 + 59 + 60 + def test_result_skip(description): 61 + _test_print("ok", description, "SKIP") 62 + ksft_cnt["skip"] += 1 63 + 64 + 65 + def test_result(condition, description=""): 66 + if condition: 67 + test_result_pass(description) 68 + else: 69 + test_result_fail(description) 70 + 71 + 72 + def finished(): 73 + if ksft_cnt["pass"] == ksft_num_tests: 74 + exit_code = KSFT_PASS 75 + else: 76 + exit_code = KSFT_FAIL 77 + 78 + print_cnts() 79 + 80 + sys.exit(exit_code) 81 + 82 + 83 + def exit_fail(): 84 + print_cnts() 85 + sys.exit(KSFT_FAIL) 86 + 87 + 88 + def exit_pass(): 89 + print_cnts() 90 + sys.exit(KSFT_PASS)
+318
tools/testing/selftests/devices/test_discoverable_devices.py
··· 1 + #!/usr/bin/python3 2 + # SPDX-License-Identifier: GPL-2.0 3 + # 4 + # Copyright (c) 2023 Collabora Ltd 5 + # 6 + # This script tests for presence and driver binding of devices from discoverable 7 + # buses (ie USB, PCI). 8 + # 9 + # The per-platform YAML file defining the devices to be tested is stored inside 10 + # the boards/ directory and chosen based on DT compatible or DMI IDs (sys_vendor 11 + # and product_name). 12 + # 13 + # See boards/google,spherion.yaml and boards/'Dell Inc.,XPS 13 9300.yaml' for 14 + # the description and examples of the file structure and vocabulary. 15 + # 16 + 17 + import glob 18 + import ksft 19 + import os 20 + import re 21 + import sys 22 + import yaml 23 + 24 + pci_controllers = [] 25 + usb_controllers = [] 26 + 27 + sysfs_usb_devices = "/sys/bus/usb/devices/" 28 + 29 + 30 + def find_pci_controller_dirs(): 31 + sysfs_devices = "/sys/devices" 32 + pci_controller_sysfs_dir = "pci[0-9a-f]{4}:[0-9a-f]{2}" 33 + 34 + dir_regex = re.compile(pci_controller_sysfs_dir) 35 + for path, dirs, _ in os.walk(sysfs_devices): 36 + for d in dirs: 37 + if dir_regex.match(d): 38 + pci_controllers.append(os.path.join(path, d)) 39 + 40 + 41 + def find_usb_controller_dirs(): 42 + usb_controller_sysfs_dir = "usb[\d]+" 43 + 44 + dir_regex = re.compile(usb_controller_sysfs_dir) 45 + for d in os.scandir(sysfs_usb_devices): 46 + if dir_regex.match(d.name): 47 + usb_controllers.append(os.path.realpath(d.path)) 48 + 49 + 50 + def get_dt_mmio(sysfs_dev_dir): 51 + re_dt_mmio = re.compile("OF_FULLNAME=.*@([0-9a-f]+)") 52 + dt_mmio = None 53 + 54 + # PCI controllers' sysfs don't have an of_node, so have to read it from the 55 + # parent 56 + while not dt_mmio: 57 + try: 58 + with open(os.path.join(sysfs_dev_dir, "uevent")) as f: 59 + dt_mmio = re_dt_mmio.search(f.read()).group(1) 60 + return dt_mmio 61 + except: 62 + pass 63 + sysfs_dev_dir = os.path.dirname(sysfs_dev_dir) 64 + 65 + 66 + def get_acpi_uid(sysfs_dev_dir): 67 + with open(os.path.join(sysfs_dev_dir, "firmware_node", "uid")) as f: 68 + return f.read() 69 + 70 + 71 + def get_usb_version(sysfs_dev_dir): 72 + re_usb_version = re.compile("PRODUCT=.*/(\d)/.*") 73 + with open(os.path.join(sysfs_dev_dir, "uevent")) as f: 74 + return int(re_usb_version.search(f.read()).group(1)) 75 + 76 + 77 + def get_usb_busnum(sysfs_dev_dir): 78 + re_busnum = re.compile("BUSNUM=(.*)") 79 + with open(os.path.join(sysfs_dev_dir, "uevent")) as f: 80 + return int(re_busnum.search(f.read()).group(1)) 81 + 82 + 83 + def find_controller_in_sysfs(controller, parent_sysfs=None): 84 + if controller["type"] == "pci-controller": 85 + controllers = pci_controllers 86 + elif controller["type"] == "usb-controller": 87 + controllers = usb_controllers 88 + 89 + result_controllers = [] 90 + 91 + for c in controllers: 92 + if parent_sysfs and parent_sysfs not in c: 93 + continue 94 + 95 + if controller.get("dt-mmio"): 96 + if str(controller["dt-mmio"]) != get_dt_mmio(c): 97 + continue 98 + 99 + if controller.get("usb-version"): 100 + if controller["usb-version"] != get_usb_version(c): 101 + continue 102 + 103 + if controller.get("acpi-uid"): 104 + if controller["acpi-uid"] != get_acpi_uid(c): 105 + continue 106 + 107 + result_controllers.append(c) 108 + 109 + return result_controllers 110 + 111 + 112 + def is_controller(device): 113 + return device.get("type") and "controller" in device.get("type") 114 + 115 + 116 + def path_to_dir(parent_sysfs, dev_type, path): 117 + if dev_type == "usb-device": 118 + usb_dev_sysfs_fmt = "{}-{}" 119 + busnum = get_usb_busnum(parent_sysfs) 120 + dirname = os.path.join( 121 + sysfs_usb_devices, usb_dev_sysfs_fmt.format(busnum, path) 122 + ) 123 + return [os.path.realpath(dirname)] 124 + else: 125 + pci_dev_sysfs_fmt = "????:??:{}" 126 + path_glob = "" 127 + for dev_func in path.split("/"): 128 + dev_func = dev_func.zfill(4) 129 + path_glob = os.path.join(path_glob, pci_dev_sysfs_fmt.format(dev_func)) 130 + 131 + dir_list = glob.glob(os.path.join(parent_sysfs, path_glob)) 132 + 133 + return dir_list 134 + 135 + 136 + def find_in_sysfs(device, parent_sysfs=None): 137 + if parent_sysfs and device.get("path"): 138 + pathdirs = path_to_dir( 139 + parent_sysfs, device["meta"]["type"], str(device["path"]) 140 + ) 141 + if len(pathdirs) != 1: 142 + # Early return to report error 143 + return pathdirs 144 + pathdir = pathdirs[0] 145 + sysfs_path = os.path.join(parent_sysfs, pathdir) 146 + else: 147 + sysfs_path = parent_sysfs 148 + 149 + if is_controller(device): 150 + return find_controller_in_sysfs(device, sysfs_path) 151 + else: 152 + return [sysfs_path] 153 + 154 + 155 + def check_driver_presence(sysfs_dir, current_node): 156 + if current_node["meta"]["type"] == "usb-device": 157 + usb_intf_fmt = "*-*:*.{}" 158 + 159 + interfaces = [] 160 + for i in current_node["interfaces"]: 161 + interfaces.append((i, usb_intf_fmt.format(i))) 162 + 163 + for intf_num, intf_dir_fmt in interfaces: 164 + test_name = f"{current_node['meta']['pathname']}.{intf_num}.driver" 165 + 166 + intf_dirs = glob.glob(os.path.join(sysfs_dir, intf_dir_fmt)) 167 + if len(intf_dirs) != 1: 168 + ksft.test_result_fail(test_name) 169 + continue 170 + intf_dir = intf_dirs[0] 171 + 172 + driver_link = os.path.join(sysfs_dir, intf_dir, "driver") 173 + ksft.test_result(os.path.isdir(driver_link), test_name) 174 + else: 175 + driver_link = os.path.join(sysfs_dir, "driver") 176 + test_name = current_node["meta"]["pathname"] + ".driver" 177 + ksft.test_result(os.path.isdir(driver_link), test_name) 178 + 179 + 180 + def generate_pathname(device): 181 + pathname = "" 182 + 183 + if device.get("path"): 184 + pathname = str(device["path"]) 185 + 186 + if device.get("type"): 187 + dev_type = device["type"] 188 + if device.get("usb-version"): 189 + dev_type = dev_type.replace("usb", "usb" + str(device["usb-version"])) 190 + if device.get("acpi-uid") is not None: 191 + dev_type = dev_type.replace("pci", "pci" + str(device["acpi-uid"])) 192 + pathname = pathname + "/" + dev_type 193 + 194 + if device.get("dt-mmio"): 195 + pathname += "@" + str(device["dt-mmio"]) 196 + 197 + if device.get("name"): 198 + pathname = pathname + "/" + device["name"] 199 + 200 + return pathname 201 + 202 + 203 + def fill_meta_keys(child, parent=None): 204 + child["meta"] = {} 205 + 206 + if parent: 207 + child["meta"]["type"] = parent["type"].replace("controller", "device") 208 + 209 + pathname = generate_pathname(child) 210 + if parent: 211 + pathname = parent["meta"]["pathname"] + "/" + pathname 212 + child["meta"]["pathname"] = pathname 213 + 214 + 215 + def parse_device_tree_node(current_node, parent_sysfs=None): 216 + if not parent_sysfs: 217 + fill_meta_keys(current_node) 218 + 219 + sysfs_dirs = find_in_sysfs(current_node, parent_sysfs) 220 + if len(sysfs_dirs) != 1: 221 + if len(sysfs_dirs) == 0: 222 + ksft.test_result_fail( 223 + f"Couldn't find in sysfs: {current_node['meta']['pathname']}" 224 + ) 225 + else: 226 + ksft.test_result_fail( 227 + f"Found multiple sysfs entries for {current_node['meta']['pathname']}: {sysfs_dirs}" 228 + ) 229 + return 230 + sysfs_dir = sysfs_dirs[0] 231 + 232 + if not is_controller(current_node): 233 + ksft.test_result( 234 + os.path.exists(sysfs_dir), current_node["meta"]["pathname"] + ".device" 235 + ) 236 + check_driver_presence(sysfs_dir, current_node) 237 + else: 238 + for child_device in current_node["devices"]: 239 + fill_meta_keys(child_device, current_node) 240 + parse_device_tree_node(child_device, sysfs_dir) 241 + 242 + 243 + def count_tests(device_trees): 244 + test_count = 0 245 + 246 + def parse_node(device): 247 + nonlocal test_count 248 + if device.get("devices"): 249 + for child in device["devices"]: 250 + parse_node(child) 251 + else: 252 + if device.get("interfaces"): 253 + test_count += len(device["interfaces"]) 254 + else: 255 + test_count += 1 256 + test_count += 1 257 + 258 + for device_tree in device_trees: 259 + parse_node(device_tree) 260 + 261 + return test_count 262 + 263 + 264 + def get_board_filenames(): 265 + filenames = [] 266 + 267 + platform_compatible_file = "/proc/device-tree/compatible" 268 + if os.path.exists(platform_compatible_file): 269 + with open(platform_compatible_file) as f: 270 + for line in f: 271 + filenames.extend(line.split("\0")) 272 + else: 273 + dmi_id_dir = "/sys/devices/virtual/dmi/id" 274 + vendor_dmi_file = os.path.join(dmi_id_dir, "sys_vendor") 275 + product_dmi_file = os.path.join(dmi_id_dir, "product_name") 276 + 277 + with open(vendor_dmi_file) as f: 278 + vendor = f.read().replace("\n", "") 279 + with open(product_dmi_file) as f: 280 + product = f.read().replace("\n", "") 281 + 282 + filenames = [vendor + "," + product] 283 + 284 + return filenames 285 + 286 + 287 + def run_test(yaml_file): 288 + ksft.print_msg(f"Using board file: {yaml_file}") 289 + 290 + with open(yaml_file) as f: 291 + device_trees = yaml.safe_load(f) 292 + 293 + ksft.set_plan(count_tests(device_trees)) 294 + 295 + for device_tree in device_trees: 296 + parse_device_tree_node(device_tree) 297 + 298 + 299 + find_pci_controller_dirs() 300 + find_usb_controller_dirs() 301 + 302 + ksft.print_header() 303 + 304 + board_file = "" 305 + for board_filename in get_board_filenames(): 306 + full_board_filename = os.path.join("boards", board_filename + ".yaml") 307 + 308 + if os.path.exists(full_board_filename): 309 + board_file = full_board_filename 310 + break 311 + 312 + if not board_file: 313 + ksft.print_msg("No matching board file found") 314 + ksft.exit_fail() 315 + 316 + run_test(board_file) 317 + 318 + ksft.finished()