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

Merge tag 'usb-5.18-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 5.18-rc1.

Nothing major in here, just lots of little improvements and cleanups
and new device support. Highlights are:

- list iterator fixups for when we walk past the end of the list (a
common problem that was cut/pasted in almost all USB gadget
drivers)

- xen USB driver "hardening" for malicious hosts

- xhci driver updates and fixes for more hardware types

- xhci debug cable fixes to make it actually work again

- usb gadget audio driver improvements

- usb gadget storage fixes to work with OS-X

- lots of other small usb gadget fixes and updates

- USB DWC3 driver improvements for more hardware types

- Lots of other small USB driver improvements

- DTS updates for some USB platforms

All of these have been in linux-next for a while with no reported
issues"

* tag 'usb-5.18-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb: (172 commits)
usb: gadget: fsl_qe_udc: Add missing semicolon in qe_ep_dequeue()
dt-bindings: usb: mtk-xhci: add compatible for mt8186
usb: dwc3: Issue core soft reset before enabling run/stop
usb: gadget: Makefile: remove ccflags-y
USB: usb-storage: Fix use of bitfields for hardware data in ene_ub6250.c
usb: gadget: eliminate anonymous module_init & module_exit
usb: usbip: eliminate anonymous module_init & module_exit
xen/usb: harden xen_hcd against malicious backends
usb: dwc3: gadget: Wait for ep0 xfers to complete during dequeue
usb: dwc3: gadget: move cmd_endtransfer to extra function
usb: dwc3: gadget: ep_queue simplify isoc start condition
xen/usb: don't use arbitrary_virt_to_machine()
usb: isp1760: remove redundant max_packet() macro
usb: oxu210hp-hcd: remove redundant call to max_packet() macro
usb: common: usb-conn-gpio: Make VBUS supply completely optional
USB: storage: ums-realtek: fix error code in rts51x_read_mem()
usb: early: xhci-dbc: Fix xdbc number parsing
usb: early: xhci-dbc: Remove duplicate keep parsing
x86/tsc: Be consistent about use_tsc_delay()
usb: gadget: udc: s3c2410: remove usage of list iterator past the loop body
...

+4886 -1248
+3 -2
Documentation/ABI/testing/configfs-usb-gadget-uac1
··· 6 6 7 7 ===================== ======================================= 8 8 c_chmask capture channel mask 9 - c_srate capture sampling rate 9 + c_srate list of capture sampling rates (comma-separated) 10 10 c_ssize capture sample size (bytes) 11 11 c_mute_present capture mute control enable 12 12 c_volume_present capture volume control enable ··· 17 17 c_volume_res capture volume control resolution 18 18 (in 1/256 dB) 19 19 p_chmask playback channel mask 20 - p_srate playback sampling rate 20 + p_srate list of playback sampling rates (comma-separated) 21 21 p_ssize playback sample size (bytes) 22 22 p_mute_present playback mute control enable 23 23 p_volume_present playback volume control enable ··· 29 29 (in 1/256 dB) 30 30 req_number the number of pre-allocated requests 31 31 for both capture and playback 32 + function_name name of the interface 32 33 ===================== =======================================
+5 -2
Documentation/ABI/testing/configfs-usb-gadget-uac2
··· 6 6 7 7 ===================== ======================================= 8 8 c_chmask capture channel mask 9 - c_srate capture sampling rate 9 + c_srate list of capture sampling rates (comma-separated) 10 10 c_ssize capture sample size (bytes) 11 + c_hs_bint capture bInterval for HS/SS (1-4: fixed, 0: auto) 11 12 c_sync capture synchronization type 12 13 (async/adaptive) 13 14 c_mute_present capture mute control enable ··· 21 20 (in 1/256 dB) 22 21 fb_max maximum extra bandwidth in async mode 23 22 p_chmask playback channel mask 24 - p_srate playback sampling rate 23 + p_srate list of playback sampling rates (comma-separated) 25 24 p_ssize playback sample size (bytes) 25 + p_hs_bint playback bInterval for HS/SS (1-4: fixed, 0: auto) 26 26 p_mute_present playback mute control enable 27 27 p_volume_present playback volume control enable 28 28 p_volume_min playback volume control min value ··· 34 32 (in 1/256 dB) 35 33 req_number the number of pre-allocated requests 36 34 for both capture and playback 35 + function_name name of the interface 37 36 ===================== =======================================
+9
Documentation/ABI/testing/sysfs-driver-eud
··· 1 + What: /sys/bus/platform/drivers/eud/.../enable 2 + Date: February 2022 3 + Contact: Souradeep Chowdhury <quic_schowdhu@quicinc.com> 4 + Description: 5 + The Enable/Disable sysfs interface for Embedded 6 + USB Debugger(EUD). This enables and disables the 7 + EUD based on a 1 or a 0 value. By enabling EUD, 8 + the user is able to activate the mini-usb hub of 9 + EUD for debug and trace capabilities.
+77
Documentation/devicetree/bindings/soc/qcom/qcom,eud.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + $id: "http://devicetree.org/schemas/soc/qcom/qcom,eud.yaml#" 5 + $schema: "http://devicetree.org/meta-schemas/core.yaml#" 6 + 7 + title: Qualcomm Embedded USB Debugger 8 + 9 + maintainers: 10 + - Souradeep Chowdhury <quic_schowdhu@quicinc.com> 11 + 12 + description: 13 + This binding is used to describe the Qualcomm Embedded USB Debugger, which is 14 + mini USB-hub implemented on chip to support USB-based debug capabilities. 15 + 16 + properties: 17 + compatible: 18 + items: 19 + - enum: 20 + - qcom,sc7280-eud 21 + - const: qcom,eud 22 + 23 + reg: 24 + items: 25 + - description: EUD Base Register Region 26 + - description: EUD Mode Manager Register 27 + 28 + interrupts: 29 + description: EUD interrupt 30 + maxItems: 1 31 + 32 + ports: 33 + $ref: /schemas/graph.yaml#/properties/ports 34 + description: 35 + These ports is to be attached to the endpoint of the DWC3 controller node 36 + and type C connector node. The controller has the "usb-role-switch" 37 + property. 38 + 39 + properties: 40 + port@0: 41 + $ref: /schemas/graph.yaml#/properties/port 42 + description: This port is to be attached to the DWC3 controller. 43 + 44 + port@1: 45 + $ref: /schemas/graph.yaml#/properties/port 46 + description: This port is to be attached to the type C connector. 47 + 48 + required: 49 + - compatible 50 + - reg 51 + - ports 52 + 53 + additionalProperties: false 54 + 55 + examples: 56 + - | 57 + eud@88e0000 { 58 + compatible = "qcom,sc7280-eud","qcom,eud"; 59 + reg = <0x88e0000 0x2000>, 60 + <0x88e2000 0x1000>; 61 + ports { 62 + #address-cells = <1>; 63 + #size-cells = <0>; 64 + port@0 { 65 + reg = <0>; 66 + eud_ep: endpoint { 67 + remote-endpoint = <&usb2_role_switch>; 68 + }; 69 + }; 70 + port@1 { 71 + reg = <1>; 72 + eud_con: endpoint { 73 + remote-endpoint = <&con_eud>; 74 + }; 75 + }; 76 + }; 77 + };
-115
Documentation/devicetree/bindings/usb/exynos-usb.txt
··· 1 - Samsung Exynos SoC USB controller 2 - 3 - The USB devices interface with USB controllers on Exynos SOCs. 4 - The device node has following properties. 5 - 6 - EHCI 7 - Required properties: 8 - - compatible: should be "samsung,exynos4210-ehci" for USB 2.0 9 - EHCI controller in host mode. 10 - - reg: physical base address of the controller and length of memory mapped 11 - region. 12 - - interrupts: interrupt number to the cpu. 13 - - clocks: from common clock binding: handle to usb clock. 14 - - clock-names: from common clock binding: Shall be "usbhost". 15 - - phys: from the *Generic PHY* bindings; array specifying phy(s) used 16 - by the root port. 17 - - phy-names: from the *Generic PHY* bindings; array of the names for 18 - each phy for the root ports, must be a subset of the following: 19 - "host", "hsic0", "hsic1". 20 - 21 - Optional properties: 22 - - samsung,vbus-gpio: if present, specifies the GPIO that 23 - needs to be pulled up for the bus to be powered. 24 - 25 - Example: 26 - 27 - usb@12110000 { 28 - compatible = "samsung,exynos4210-ehci"; 29 - reg = <0x12110000 0x100>; 30 - interrupts = <0 71 0>; 31 - samsung,vbus-gpio = <&gpx2 6 1 3 3>; 32 - 33 - clocks = <&clock 285>; 34 - clock-names = "usbhost"; 35 - 36 - phys = <&usb2phy 1>; 37 - phy-names = "host"; 38 - }; 39 - 40 - OHCI 41 - Required properties: 42 - - compatible: should be "samsung,exynos4210-ohci" for USB 2.0 43 - OHCI companion controller in host mode. 44 - - reg: physical base address of the controller and length of memory mapped 45 - region. 46 - - interrupts: interrupt number to the cpu. 47 - - clocks: from common clock binding: handle to usb clock. 48 - - clock-names: from common clock binding: Shall be "usbhost". 49 - - phys: from the *Generic PHY* bindings; array specifying phy(s) used 50 - by the root port. 51 - - phy-names: from the *Generic PHY* bindings; array of the names for 52 - each phy for the root ports, must be a subset of the following: 53 - "host", "hsic0", "hsic1". 54 - 55 - Example: 56 - usb@12120000 { 57 - compatible = "samsung,exynos4210-ohci"; 58 - reg = <0x12120000 0x100>; 59 - interrupts = <0 71 0>; 60 - 61 - clocks = <&clock 285>; 62 - clock-names = "usbhost"; 63 - 64 - phys = <&usb2phy 1>; 65 - phy-names = "host"; 66 - }; 67 - 68 - DWC3 69 - Required properties: 70 - - compatible: should be one of the following - 71 - "samsung,exynos5250-dwusb3": for USB 3.0 DWC3 controller on 72 - Exynos5250/5420. 73 - "samsung,exynos5433-dwusb3": for USB 3.0 DWC3 controller on 74 - Exynos5433. 75 - "samsung,exynos7-dwusb3": for USB 3.0 DWC3 controller on Exynos7. 76 - - #address-cells, #size-cells : should be '1' if the device has sub-nodes 77 - with 'reg' property. 78 - - ranges: allows valid 1:1 translation between child's address space and 79 - parent's address space 80 - - clocks: Clock IDs array as required by the controller. 81 - - clock-names: Names of clocks corresponding to IDs in the clock property. 82 - Following clock names shall be provided for different 83 - compatibles: 84 - - samsung,exynos5250-dwusb3: "usbdrd30", 85 - - samsung,exynos5433-dwusb3: "aclk", "susp_clk", "pipe_pclk", 86 - "phyclk", 87 - - samsung,exynos7-dwusb3: "usbdrd30", "usbdrd30_susp_clk", 88 - "usbdrd30_axius_clk" 89 - - vdd10-supply: 1.0V powr supply 90 - - vdd33-supply: 3.0V/3.3V power supply 91 - 92 - Sub-nodes: 93 - The dwc3 core should be added as subnode to Exynos dwc3 glue. 94 - - dwc3 : 95 - The binding details of dwc3 can be found in: 96 - Documentation/devicetree/bindings/usb/snps,dwc3.yaml 97 - 98 - Example: 99 - usb@12000000 { 100 - compatible = "samsung,exynos5250-dwusb3"; 101 - clocks = <&clock 286>; 102 - clock-names = "usbdrd30"; 103 - #address-cells = <1>; 104 - #size-cells = <1>; 105 - ranges; 106 - vdd10-supply = <&ldo11_reg>; 107 - vdd33-supply = <&ldo9_reg>; 108 - 109 - dwc3 { 110 - compatible = "synopsys,dwc3"; 111 - reg = <0x12000000 0x10000>; 112 - interrupts = <0 72 0>; 113 - usb-phy = <&usb2_phy &usb3_phy>; 114 - }; 115 - };
+27 -4
Documentation/devicetree/bindings/usb/fsl,imx8mp-dwc3.yaml
··· 15 15 const: fsl,imx8mp-dwc3 16 16 17 17 reg: 18 - maxItems: 1 19 - description: Address and length of the register set for the wrapper of 20 - dwc3 core on the SOC. 18 + items: 19 + - description: Address and length of the register set for HSIO Block Control 20 + - description: Address and length of the register set for the wrapper of dwc3 core on the SOC. 21 21 22 22 "#address-cells": 23 23 enum: [ 1, 2 ] ··· 49 49 - const: hsio 50 50 - const: suspend 51 51 52 + fsl,permanently-attached: 53 + type: boolean 54 + description: 55 + Indicates if the device atached to a downstream port is 56 + permanently attached. 57 + 58 + fsl,disable-port-power-control: 59 + type: boolean 60 + description: 61 + Indicates whether the host controller implementation includes port 62 + power control. Defines Bit 3 in capability register (HCCPARAMS). 63 + 64 + fsl,over-current-active-low: 65 + type: boolean 66 + description: 67 + Over current signal polarity is active low. 68 + 69 + fsl,power-active-low: 70 + type: boolean 71 + description: 72 + Power pad (PWR) polarity is active low. 73 + 52 74 # Required child node: 53 75 54 76 patternProperties: ··· 96 74 #include <dt-bindings/interrupt-controller/arm-gic.h> 97 75 usb3_0: usb@32f10100 { 98 76 compatible = "fsl,imx8mp-dwc3"; 99 - reg = <0x32f10100 0x8>; 77 + reg = <0x32f10100 0x8>, 78 + <0x381f0000 0x20>; 100 79 clocks = <&clk IMX8MP_CLK_HSIO_ROOT>, 101 80 <&clk IMX8MP_CLK_USB_ROOT>; 102 81 clock-names = "hsio", "suspend";
+6 -1
Documentation/devicetree/bindings/usb/mediatek,mtk-xhci.yaml
··· 30 30 - mediatek,mt7629-xhci 31 31 - mediatek,mt8173-xhci 32 32 - mediatek,mt8183-xhci 33 + - mediatek,mt8186-xhci 33 34 - mediatek,mt8192-xhci 34 35 - mediatek,mt8195-xhci 35 36 - const: mediatek,mtk-xhci ··· 147 146 2 - used by mt2712 etc, revision 2 following IPM rule; 148 147 101 - used by mt8183, specific 1.01; 149 148 102 - used by mt8192, specific 1.02; 150 - enum: [1, 2, 101, 102] 149 + 103 - used by mt8195, IP0, specific 1.03; 150 + 104 - used by mt8195, IP1, specific 1.04; 151 + 105 - used by mt8195, IP2, specific 1.05; 152 + 106 - used by mt8195, IP3, specific 1.06; 153 + enum: [1, 2, 101, 102, 103, 104, 105, 106] 151 154 152 155 mediatek,u3p-dis-msk: 153 156 $ref: /schemas/types.yaml#/definitions/uint32
+59
Documentation/devicetree/bindings/usb/microchip,mpfs-musb.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/microchip,mpfs-musb.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Microchip MPFS USB Controller Device Tree Bindings 8 + 9 + allOf: 10 + - $ref: usb-drd.yaml# 11 + 12 + maintainers: 13 + - Conor Dooley <conor.dooley@microchip.com> 14 + 15 + properties: 16 + compatible: 17 + enum: 18 + - microchip,mpfs-musb 19 + 20 + dr_mode: true 21 + 22 + reg: 23 + maxItems: 1 24 + 25 + interrupts: 26 + minItems: 2 27 + maxItems: 2 28 + 29 + interrupt-names: 30 + items: 31 + - const: dma 32 + - const: mc 33 + 34 + clocks: 35 + maxItems: 1 36 + 37 + required: 38 + - compatible 39 + - reg 40 + - interrupts 41 + - interrupt-names 42 + - clocks 43 + 44 + additionalProperties: false 45 + 46 + examples: 47 + - | 48 + #include "dt-bindings/clock/microchip,mpfs-clock.h" 49 + usb@20201000 { 50 + compatible = "microchip,mpfs-musb"; 51 + reg = <0x20201000 0x1000>; 52 + clocks = <&clkcfg CLK_USB>; 53 + interrupt-parent = <&plic>; 54 + interrupts = <86>, <87>; 55 + interrupt-names = "dma", "mc"; 56 + dr_mode = "host"; 57 + }; 58 + 59 + ...
+1
Documentation/devicetree/bindings/usb/qcom,dwc3.yaml
··· 16 16 - qcom,ipq4019-dwc3 17 17 - qcom,ipq6018-dwc3 18 18 - qcom,ipq8064-dwc3 19 + - qcom,msm8953-dwc3 19 20 - qcom,msm8996-dwc3 20 21 - qcom,msm8998-dwc3 21 22 - qcom,sc7180-dwc3
+85
Documentation/devicetree/bindings/usb/richtek,rt1719.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/richtek,rt1719.yaml#" 5 + $schema: "http://devicetree.org/meta-schemas/core.yaml#" 6 + 7 + title: Richtek RT1719 sink-only Type-C PD controller bindings 8 + 9 + maintainers: 10 + - ChiYuan Huang <cy_huang@richtek.com> 11 + 12 + description: | 13 + The RT1719 is a sink-only USB Type-C contoller that complies with the latest 14 + USB Type-C and PD standards. It does the USB Type-C detection including attach 15 + and orientation. It integrates the physical layer of the USB BMC power 16 + delivery protocol to allow up to 100W of power. The BMC PD block enables full 17 + support for alternative interfaces of the Type-C specification. 18 + 19 + properties: 20 + compatible: 21 + enum: 22 + - richtek,rt1719 23 + 24 + reg: 25 + maxItems: 1 26 + 27 + interrupts: 28 + maxItems: 1 29 + 30 + wakeup-source: 31 + description: enable IRQ remote wakeup, see power/wakeup-source.txt 32 + type: boolean 33 + 34 + connector: 35 + type: object 36 + $ref: ../connector/usb-connector.yaml# 37 + description: 38 + Properties for usb c connector. 39 + 40 + additionalProperties: false 41 + 42 + required: 43 + - compatible 44 + - reg 45 + - connector 46 + - interrupts 47 + 48 + examples: 49 + - | 50 + #include <dt-bindings/interrupt-controller/irq.h> 51 + i2c0 { 52 + #address-cells = <1>; 53 + #size-cells = <0>; 54 + 55 + rt1719@43 { 56 + compatible = "richtek,rt1719"; 57 + reg = <0x43>; 58 + interrupts-extended = <&gpio26 2 IRQ_TYPE_LEVEL_LOW>; 59 + wakeup-source; 60 + 61 + connector { 62 + compatible = "usb-c-connector"; 63 + label = "USB-C"; 64 + 65 + ports { 66 + #address-cells = <1>; 67 + #size-cells = <0>; 68 + 69 + port@0 { 70 + reg = <0>; 71 + endpoint { 72 + remote-endpoint = <&usb_hs>; 73 + }; 74 + }; 75 + port@1 { 76 + reg = <1>; 77 + endpoint { 78 + remote-endpoint = <&usb_ss>; 79 + }; 80 + }; 81 + }; 82 + }; 83 + }; 84 + }; 85 + ...
+2
Documentation/devicetree/bindings/usb/rockchip,dwc3.yaml
··· 30 30 enum: 31 31 - rockchip,rk3328-dwc3 32 32 - rockchip,rk3399-dwc3 33 + - rockchip,rk3568-dwc3 33 34 required: 34 35 - compatible 35 36 ··· 40 39 - enum: 41 40 - rockchip,rk3328-dwc3 42 41 - rockchip,rk3399-dwc3 42 + - rockchip,rk3568-dwc3 43 43 - const: snps,dwc3 44 44 45 45 reg:
+129
Documentation/devicetree/bindings/usb/samsung,exynos-dwc3.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/samsung,exynos-dwc3.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Samsung Exynos SoC USB 3.0 DWC3 Controller 8 + 9 + maintainers: 10 + - Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com> 11 + 12 + properties: 13 + compatible: 14 + enum: 15 + - samsung,exynos5250-dwusb3 16 + - samsung,exynos5433-dwusb3 17 + - samsung,exynos7-dwusb3 18 + 19 + '#address-cells': 20 + const: 1 21 + 22 + clocks: 23 + minItems: 1 24 + maxItems: 4 25 + 26 + clock-names: 27 + minItems: 1 28 + maxItems: 4 29 + 30 + ranges: true 31 + 32 + '#size-cells': 33 + const: 1 34 + 35 + vdd10-supply: 36 + description: 1.0V power supply 37 + 38 + vdd33-supply: 39 + description: 3.0V/3.3V power supply 40 + 41 + patternProperties: 42 + "^usb@[0-9a-f]+$": 43 + $ref: snps,dwc3.yaml# 44 + description: Required child node 45 + 46 + required: 47 + - compatible 48 + - '#address-cells' 49 + - clocks 50 + - clock-names 51 + - ranges 52 + - '#size-cells' 53 + - vdd10-supply 54 + - vdd33-supply 55 + 56 + allOf: 57 + - if: 58 + properties: 59 + compatible: 60 + contains: 61 + const: samsung,exynos5250-dwusb3 62 + then: 63 + properties: 64 + clocks: 65 + minItems: 1 66 + maxItems: 1 67 + clock-names: 68 + items: 69 + - const: usbdrd30 70 + 71 + - if: 72 + properties: 73 + compatible: 74 + contains: 75 + const: samsung,exynos54333-dwusb3 76 + then: 77 + properties: 78 + clocks: 79 + minItems: 4 80 + maxItems: 4 81 + clock-names: 82 + items: 83 + - const: aclk 84 + - const: susp_clk 85 + - const: pipe_pclk 86 + - const: phyclk 87 + 88 + - if: 89 + properties: 90 + compatible: 91 + contains: 92 + const: samsung,exynos7-dwusb3 93 + then: 94 + properties: 95 + clocks: 96 + minItems: 3 97 + maxItems: 3 98 + clock-names: 99 + items: 100 + - const: usbdrd30 101 + - const: usbdrd30_susp_clk 102 + - const: usbdrd30_axius_clk 103 + 104 + additionalProperties: false 105 + 106 + examples: 107 + - | 108 + #include <dt-bindings/clock/exynos5420.h> 109 + #include <dt-bindings/interrupt-controller/arm-gic.h> 110 + 111 + usb { 112 + compatible = "samsung,exynos5250-dwusb3"; 113 + #address-cells = <1>; 114 + #size-cells = <1>; 115 + ranges; 116 + clocks = <&clock CLK_USBD300>; 117 + clock-names = "usbdrd30"; 118 + vdd33-supply = <&ldo9_reg>; 119 + vdd10-supply = <&ldo11_reg>; 120 + 121 + usb@12000000 { 122 + compatible = "snps,dwc3"; 123 + reg = <0x12000000 0x10000>; 124 + interrupts = <GIC_SPI 72 IRQ_TYPE_LEVEL_HIGH>; 125 + phys = <&usbdrd_phy0 0>, <&usbdrd_phy0 1>; 126 + phy-names = "usb2-phy", "usb3-phy"; 127 + snps,dis_u3_susphy_quirk; 128 + }; 129 + };
+117
Documentation/devicetree/bindings/usb/samsung,exynos-usb2.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/samsung,exynos-usb2.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Samsung Exynos SoC USB 2.0 EHCI/OHCI Controller 8 + 9 + maintainers: 10 + - Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com> 11 + 12 + properties: 13 + compatible: 14 + enum: 15 + - samsung,exynos4210-ehci 16 + - samsung,exynos4210-ohci 17 + 18 + '#address-cells': 19 + const: 1 20 + 21 + clocks: 22 + maxItems: 1 23 + 24 + clock-names: 25 + items: 26 + - const: usbhost 27 + 28 + interrupts: 29 + maxItems: 1 30 + 31 + phys: 32 + minItems: 1 33 + maxItems: 3 34 + 35 + phy-names: 36 + items: 37 + enum: [host, hsic0, hsic1] 38 + minItems: 1 39 + maxItems: 3 40 + 41 + reg: 42 + maxItems: 1 43 + 44 + samsung,vbus-gpio: 45 + description: 46 + Only for controller in EHCI mode, if present, specifies the GPIO that 47 + needs to be pulled up for the bus to be powered. 48 + 49 + '#size-cells': 50 + const: 0 51 + 52 + patternProperties: 53 + "^.*@[0-9a-f]{1,2}$": 54 + description: The hard wired USB devices 55 + type: object 56 + $ref: /usb/usb-device.yaml 57 + 58 + required: 59 + - compatible 60 + - clocks 61 + - clock-names 62 + - interrupts 63 + - phys 64 + - phy-names 65 + 66 + allOf: 67 + - if: 68 + properties: 69 + compatible: 70 + contains: 71 + const: samsung,exynos4210-ohci 72 + then: 73 + properties: 74 + samsung,vbus-gpio: false 75 + 76 + additionalProperties: false 77 + 78 + examples: 79 + - | 80 + #include <dt-bindings/clock/exynos5420.h> 81 + #include <dt-bindings/interrupt-controller/arm-gic.h> 82 + 83 + usb@12110000 { 84 + compatible = "samsung,exynos4210-ehci"; 85 + reg = <0x12110000 0x100>; 86 + interrupts = <GIC_SPI 71 IRQ_TYPE_LEVEL_HIGH>; 87 + clocks = <&clock CLK_USBH20>; 88 + clock-names = "usbhost"; 89 + phys = <&usb2_phy 0>; 90 + phy-names = "host"; 91 + 92 + #address-cells = <1>; 93 + #size-cells = <0>; 94 + 95 + hub@1 { 96 + compatible = "usb0424,9514"; 97 + reg = <1>; 98 + #address-cells = <1>; 99 + #size-cells = <0>; 100 + 101 + usbether@1 { 102 + compatible = "usb0424,ec00"; 103 + reg = <1>; 104 + local-mac-address = [00 00 00 00 00 00]; 105 + }; 106 + }; 107 + }; 108 + 109 + usb@12120000 { 110 + compatible = "samsung,exynos4210-ohci"; 111 + reg = <0x12120000 0x100>; 112 + interrupts = <GIC_SPI 71 IRQ_TYPE_LEVEL_HIGH>; 113 + clocks = <&clock CLK_USBH20>; 114 + clock-names = "usbhost"; 115 + phys = <&usb2_phy 0>; 116 + phy-names = "host"; 117 + };
+11 -2
Documentation/devicetree/bindings/usb/snps,dwc3.yaml
··· 263 263 Value for REFCLKPER field of GUCTL register for reference clock period in 264 264 nanoseconds, when the hardware set default does not match the actual 265 265 clock. 266 - minimum: 1 267 - maximum: 0x3ff 266 + 267 + This binding is deprecated. Instead, provide an appropriate reference clock. 268 + minimum: 8 269 + maximum: 62 270 + deprecated: true 268 271 269 272 snps,rx-thr-num-pkt-prd: 270 273 description: ··· 334 331 uniqueItems: true 335 332 items: 336 333 enum: [1, 4, 8, 16, 32, 64, 128, 256] 334 + 335 + port: 336 + $ref: /schemas/graph.yaml#/properties/port 337 + description: 338 + This port is used with the 'usb-role-switch' property to connect the 339 + dwc3 to type C connector. 337 340 338 341 unevaluatedProperties: false 339 342
+1 -1
Documentation/devicetree/bindings/usb/usb-hcd.yaml
··· 33 33 "^.*@[0-9a-f]{1,2}$": 34 34 description: The hard wired USB devices 35 35 type: object 36 - $ref: /usb/usb-device.yaml 36 + $ref: /schemas/usb/usb-device.yaml 37 37 38 38 additionalProperties: true 39 39
+75
Documentation/devicetree/bindings/usb/willsemi,wusb3801.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/willsemi,wusb3801.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: WUSB3801 Type-C port controller DT bindings 8 + 9 + description: 10 + The Will Semiconductor WUSB3801 is a USB Type-C port controller which 11 + supports role and plug orientation detection using the CC pins. It is 12 + compatible with the USB Type-C Cable and Connector Specification v1.2. 13 + 14 + maintainers: 15 + - Samuel Holland <samuel@sholland.org> 16 + 17 + properties: 18 + compatible: 19 + enum: 20 + - willsemi,wusb3801 21 + 22 + reg: 23 + maxItems: 1 24 + 25 + interrupts: 26 + maxItems: 1 27 + 28 + connector: 29 + type: object 30 + $ref: ../connector/usb-connector.yaml# 31 + description: 32 + The managed USB Type-C connector. Since WUSB3801 does not support 33 + Power Delivery, the node should have the "pd-disable" property. 34 + 35 + properties: 36 + compatible: 37 + const: usb-c-connector 38 + 39 + required: 40 + - pd-disable 41 + 42 + required: 43 + - compatible 44 + - reg 45 + - interrupts 46 + - connector 47 + 48 + additionalProperties: false 49 + 50 + examples: 51 + - | 52 + #include <dt-bindings/interrupt-controller/irq.h> 53 + 54 + i2c { 55 + #address-cells = <1>; 56 + #size-cells = <0>; 57 + 58 + tcpc@60 { 59 + compatible = "willsemi,wusb3801"; 60 + reg = <0x60>; 61 + interrupt-parent = <&gpio0>; 62 + interrupts = <4 IRQ_TYPE_LEVEL_LOW>; 63 + 64 + connector { 65 + compatible = "usb-c-connector"; 66 + label = "USB-C"; 67 + vbus-supply = <&otg_switch>; 68 + power-role = "dual"; 69 + try-power-role = "sink"; 70 + data-role = "dual"; 71 + typec-power-opmode = "default"; 72 + pd-disable; 73 + }; 74 + }; 75 + };
+2
Documentation/devicetree/bindings/vendor-prefixes.yaml
··· 1371 1371 description: Wi2Wi, Inc. 1372 1372 "^wiligear,.*": 1373 1373 description: Wiligear, Ltd. 1374 + "^willsemi,.*": 1375 + description: Will Semiconductor Ltd. 1374 1376 "^winbond,.*": 1375 1377 description: Winbond Electronics corp. 1376 1378 "^wingtech,.*":
+8 -4
Documentation/usb/gadget-testing.rst
··· 726 726 727 727 ================ ==================================================== 728 728 c_chmask capture channel mask 729 - c_srate capture sampling rate 729 + c_srate list of capture sampling rates (comma-separated) 730 730 c_ssize capture sample size (bytes) 731 731 c_sync capture synchronization type (async/adaptive) 732 732 c_mute_present capture mute control enable ··· 734 734 c_volume_min capture volume control min value (in 1/256 dB) 735 735 c_volume_max capture volume control max value (in 1/256 dB) 736 736 c_volume_res capture volume control resolution (in 1/256 dB) 737 + c_hs_bint capture bInterval for HS/SS (1-4: fixed, 0: auto) 737 738 fb_max maximum extra bandwidth in async mode 738 739 p_chmask playback channel mask 739 - p_srate playback sampling rate 740 + p_srate list of playback sampling rates (comma-separated) 740 741 p_ssize playback sample size (bytes) 741 742 p_mute_present playback mute control enable 742 743 p_volume_present playback volume control enable 743 744 p_volume_min playback volume control min value (in 1/256 dB) 744 745 p_volume_max playback volume control max value (in 1/256 dB) 745 746 p_volume_res playback volume control resolution (in 1/256 dB) 747 + p_hs_bint playback bInterval for HS/SS (1-4: fixed, 0: auto) 746 748 req_number the number of pre-allocated request for both capture 747 749 and playback 750 + function_name name of the interface 748 751 ================ ==================================================== 749 752 750 753 The attributes have sane default values. ··· 919 916 920 917 ================ ==================================================== 921 918 c_chmask capture channel mask 922 - c_srate capture sampling rate 919 + c_srate list of capture sampling rates (comma-separated) 923 920 c_ssize capture sample size (bytes) 924 921 c_mute_present capture mute control enable 925 922 c_volume_present capture volume control enable ··· 927 924 c_volume_max capture volume control max value (in 1/256 dB) 928 925 c_volume_res capture volume control resolution (in 1/256 dB) 929 926 p_chmask playback channel mask 930 - p_srate playback sampling rate 927 + p_srate list of playback sampling rates (comma-separated) 931 928 p_ssize playback sample size (bytes) 932 929 p_mute_present playback mute control enable 933 930 p_volume_present playback volume control enable ··· 936 933 p_volume_res playback volume control resolution (in 1/256 dB) 937 934 req_number the number of pre-allocated requests for both capture 938 935 and playback 936 + function_name name of the interface 939 937 ================ ==================================================== 940 938 941 939 The attributes have sane default values.
+8
MAINTAINERS
··· 15917 15917 F: sound/soc/codecs/wsa881x.c 15918 15918 F: sound/soc/qcom/ 15919 15919 15920 + QCOM EMBEDDED USB DEBUGGER (EUD) 15921 + M: Souradeep Chowdhury <quic_schowdhu@quicinc.com> 15922 + L: linux-arm-msm@vger.kernel.org 15923 + S: Maintained 15924 + F: Documentation/ABI/testing/sysfs-driver-eud 15925 + F: Documentation/devicetree/bindings/soc/qcom/qcom,eud.yaml 15926 + F: drivers/usb/misc/qcom_eud.c 15927 + 15920 15928 QCOM IPA DRIVER 15921 15929 M: Alex Elder <elder@kernel.org> 15922 15930 L: netdev@vger.kernel.org
+4 -2
arch/arm64/boot/dts/freescale/imx8mp.dtsi
··· 921 921 922 922 usb3_0: usb@32f10100 { 923 923 compatible = "fsl,imx8mp-dwc3"; 924 - reg = <0x32f10100 0x8>; 924 + reg = <0x32f10100 0x8>, 925 + <0x381f0000 0x20>; 925 926 clocks = <&clk IMX8MP_CLK_HSIO_ROOT>, 926 927 <&clk IMX8MP_CLK_USB_ROOT>; 927 928 clock-names = "hsio", "suspend"; ··· 964 963 965 964 usb3_1: usb@32f10108 { 966 965 compatible = "fsl,imx8mp-dwc3"; 967 - reg = <0x32f10108 0x8>; 966 + reg = <0x32f10108 0x8>, 967 + <0x382f0000 0x20>; 968 968 clocks = <&clk IMX8MP_CLK_HSIO_ROOT>, 969 969 <&clk IMX8MP_CLK_USB_ROOT>; 970 970 clock-names = "hsio", "suspend";
+2 -1
arch/arm64/boot/dts/qcom/ipq6018.dtsi
··· 752 752 interrupts = <GIC_SPI 140 IRQ_TYPE_LEVEL_HIGH>; 753 753 phys = <&qusb_phy_0>, <&usb0_ssphy>; 754 754 phy-names = "usb2-phy", "usb3-phy"; 755 + clocks = <&xo>; 756 + clock-names = "ref"; 755 757 tx-fifo-resize; 756 758 snps,is-utmi-l1-suspend; 757 759 snps,hird-threshold = /bits/ 8 <0x0>; 758 760 snps,dis_u2_susphy_quirk; 759 761 snps,dis_u3_susphy_quirk; 760 - snps,ref-clock-period-ns = <0x29>; 761 762 dr_mode = "host"; 762 763 }; 763 764 };
+2 -2
arch/arm64/boot/dts/xilinx/zynqmp-clk-ccf.dtsi
··· 223 223 clocks = <&zynqmp_clk UART1_REF>, <&zynqmp_clk LPD_LSBUS>; 224 224 }; 225 225 226 - &usb0 { 226 + &dwc3_0 { 227 227 clocks = <&zynqmp_clk USB0_BUS_REF>, <&zynqmp_clk USB3_DUAL_REF>; 228 228 }; 229 229 230 - &usb1 { 230 + &dwc3_1 { 231 231 clocks = <&zynqmp_clk USB1_BUS_REF>, <&zynqmp_clk USB3_DUAL_REF>; 232 232 }; 233 233
+2 -2
arch/arm64/boot/dts/xilinx/zynqmp.dtsi
··· 809 809 status = "disabled"; 810 810 compatible = "xlnx,zynqmp-dwc3"; 811 811 reg = <0x0 0xff9d0000 0x0 0x100>; 812 - clock-names = "bus_clk", "ref_clk"; 813 812 power-domains = <&zynqmp_firmware PD_USB_0>; 814 813 resets = <&zynqmp_reset ZYNQMP_RESET_USB0_CORERESET>, 815 814 <&zynqmp_reset ZYNQMP_RESET_USB0_HIBERRESET>, ··· 822 823 interrupt-parent = <&gic>; 823 824 interrupt-names = "dwc_usb3", "otg"; 824 825 interrupts = <0 65 4>, <0 69 4>; 826 + clock-names = "bus_early", "ref"; 825 827 iommus = <&smmu 0x860>; 826 828 snps,quirk-frame-length-adjustment = <0x20>; 827 829 /* dma-coherent; */ ··· 835 835 status = "disabled"; 836 836 compatible = "xlnx,zynqmp-dwc3"; 837 837 reg = <0x0 0xff9e0000 0x0 0x100>; 838 - clock-names = "bus_clk", "ref_clk"; 839 838 power-domains = <&zynqmp_firmware PD_USB_1>; 840 839 resets = <&zynqmp_reset ZYNQMP_RESET_USB1_CORERESET>, 841 840 <&zynqmp_reset ZYNQMP_RESET_USB1_HIBERRESET>, ··· 848 849 interrupt-parent = <&gic>; 849 850 interrupt-names = "dwc_usb3", "otg"; 850 851 interrupts = <0 70 4>, <0 74 4>; 852 + clock-names = "bus_early", "ref"; 851 853 iommus = <&smmu 0x861>; 852 854 snps,quirk-frame-length-adjustment = <0x20>; 853 855 /* dma-coherent; */
+1 -1
arch/x86/kernel/early_printk.c
··· 387 387 #endif 388 388 #ifdef CONFIG_EARLY_PRINTK_USB_XDBC 389 389 if (!strncmp(buf, "xdbc", 4)) 390 - early_xdbc_parse_parameter(buf + 4); 390 + early_xdbc_parse_parameter(buf + 4, keep); 391 391 #endif 392 392 393 393 buf++;
+3 -3
arch/x86/kernel/tsc.c
··· 1487 1487 1488 1488 static void __init tsc_enable_sched_clock(void) 1489 1489 { 1490 + loops_per_jiffy = get_loops_per_jiffy(); 1491 + use_tsc_delay(); 1492 + 1490 1493 /* Sanitize TSC ADJUST before cyc2ns gets initialized */ 1491 1494 tsc_store_and_check_tsc_adjust(true); 1492 1495 cyc2ns_init_boot_cpu(); ··· 1505 1502 return; 1506 1503 if (!determine_cpu_tsc_frequencies(true)) 1507 1504 return; 1508 - loops_per_jiffy = get_loops_per_jiffy(); 1509 - 1510 1505 tsc_enable_sched_clock(); 1511 1506 } 1512 1507 ··· 1538 1537 enable_sched_clock_irqtime(); 1539 1538 1540 1539 lpj_fine = get_loops_per_jiffy(); 1541 - use_tsc_delay(); 1542 1540 1543 1541 check_system_tsc_reliable(); 1544 1542
+2 -2
drivers/thunderbolt/acpi.c
··· 14 14 static acpi_status tb_acpi_add_link(acpi_handle handle, u32 level, void *data, 15 15 void **return_value) 16 16 { 17 + struct acpi_device *adev = acpi_fetch_acpi_dev(handle); 17 18 struct fwnode_reference_args args; 18 19 struct fwnode_handle *fwnode; 19 20 struct tb_nhi *nhi = data; 20 - struct acpi_device *adev; 21 21 struct pci_dev *pdev; 22 22 struct device *dev; 23 23 int ret; 24 24 25 - if (acpi_bus_get_device(handle, &adev)) 25 + if (!adev) 26 26 return AE_OK; 27 27 28 28 fwnode = acpi_fwnode_handle(adev);
+22 -19
drivers/thunderbolt/eeprom.c
··· 17 17 */ 18 18 static int tb_eeprom_ctl_write(struct tb_switch *sw, struct tb_eeprom_ctl *ctl) 19 19 { 20 - return tb_sw_write(sw, ctl, TB_CFG_SWITCH, sw->cap_plug_events + 4, 1); 20 + return tb_sw_write(sw, ctl, TB_CFG_SWITCH, sw->cap_plug_events + ROUTER_CS_4, 1); 21 21 } 22 22 23 23 /* ··· 25 25 */ 26 26 static int tb_eeprom_ctl_read(struct tb_switch *sw, struct tb_eeprom_ctl *ctl) 27 27 { 28 - return tb_sw_read(sw, ctl, TB_CFG_SWITCH, sw->cap_plug_events + 4, 1); 28 + return tb_sw_read(sw, ctl, TB_CFG_SWITCH, sw->cap_plug_events + ROUTER_CS_4, 1); 29 29 } 30 30 31 31 enum tb_eeprom_transfer { ··· 46 46 if (res) 47 47 return res; 48 48 if (enable) { 49 - ctl.access_high = 1; 49 + ctl.bit_banging_enable = 1; 50 50 res = tb_eeprom_ctl_write(sw, &ctl); 51 51 if (res) 52 52 return res; 53 - ctl.access_low = 0; 53 + ctl.fl_cs = 0; 54 54 return tb_eeprom_ctl_write(sw, &ctl); 55 55 } else { 56 - ctl.access_low = 1; 56 + ctl.fl_cs = 1; 57 57 res = tb_eeprom_ctl_write(sw, &ctl); 58 58 if (res) 59 59 return res; 60 - ctl.access_high = 0; 60 + ctl.bit_banging_enable = 0; 61 61 return tb_eeprom_ctl_write(sw, &ctl); 62 62 } 63 63 } ··· 65 65 /* 66 66 * tb_eeprom_transfer - transfer one bit 67 67 * 68 - * If TB_EEPROM_IN is passed, then the bit can be retrieved from ctl->data_in. 69 - * If TB_EEPROM_OUT is passed, then ctl->data_out will be written. 68 + * If TB_EEPROM_IN is passed, then the bit can be retrieved from ctl->fl_do. 69 + * If TB_EEPROM_OUT is passed, then ctl->fl_di will be written. 70 70 */ 71 71 static int tb_eeprom_transfer(struct tb_switch *sw, struct tb_eeprom_ctl *ctl, 72 72 enum tb_eeprom_transfer direction) ··· 77 77 if (res) 78 78 return res; 79 79 } 80 - ctl->clock = 1; 80 + ctl->fl_sk = 1; 81 81 res = tb_eeprom_ctl_write(sw, ctl); 82 82 if (res) 83 83 return res; ··· 86 86 if (res) 87 87 return res; 88 88 } 89 - ctl->clock = 0; 89 + ctl->fl_sk = 0; 90 90 return tb_eeprom_ctl_write(sw, ctl); 91 91 } 92 92 ··· 101 101 if (res) 102 102 return res; 103 103 for (i = 0; i < 8; i++) { 104 - ctl.data_out = val & 0x80; 104 + ctl.fl_di = val & 0x80; 105 105 res = tb_eeprom_transfer(sw, &ctl, TB_EEPROM_OUT); 106 106 if (res) 107 107 return res; ··· 126 126 res = tb_eeprom_transfer(sw, &ctl, TB_EEPROM_IN); 127 127 if (res) 128 128 return res; 129 - *val |= ctl.data_in; 129 + *val |= ctl.fl_do; 130 130 } 131 131 return 0; 132 132 } ··· 553 553 crc = tb_crc8((u8 *) &header->uid, 8); 554 554 if (crc != header->uid_crc8) { 555 555 tb_sw_warn(sw, 556 - "DROM UID CRC8 mismatch (expected: %#x, got: %#x), aborting\n", 556 + "DROM UID CRC8 mismatch (expected: %#x, got: %#x)\n", 557 557 header->uid_crc8, crc); 558 - return -EINVAL; 558 + return -EILSEQ; 559 559 } 560 560 if (!sw->uid) 561 561 sw->uid = header->uid; ··· 654 654 sw->drom = kzalloc(size, GFP_KERNEL); 655 655 if (!sw->drom) 656 656 return -ENOMEM; 657 + read: 657 658 res = tb_drom_read_n(sw, 0, sw->drom, size); 658 659 if (res) 659 660 goto err; ··· 663 662 header = (void *) sw->drom; 664 663 665 664 if (header->data_len + TB_DROM_DATA_START != size) { 666 - tb_sw_warn(sw, "drom size mismatch, aborting\n"); 665 + tb_sw_warn(sw, "drom size mismatch\n"); 666 + if (retries--) { 667 + msleep(100); 668 + goto read; 669 + } 667 670 goto err; 668 671 } 669 672 ··· 688 683 689 684 /* If the DROM parsing fails, wait a moment and retry once */ 690 685 if (res == -EILSEQ && retries--) { 691 - tb_sw_warn(sw, "parsing DROM failed, retrying\n"); 686 + tb_sw_warn(sw, "parsing DROM failed\n"); 692 687 msleep(100); 693 - res = tb_drom_read_n(sw, 0, sw->drom, size); 694 - if (!res) 695 - goto parse; 688 + goto read; 696 689 } 697 690 698 691 if (!res)
+110
drivers/thunderbolt/lc.c
··· 217 217 return !!(val & TB_LC_LINK_ATTR_CPS); 218 218 } 219 219 220 + /** 221 + * tb_lc_is_usb_plugged() - Is there USB device connected to port 222 + * @port: Device router lane 0 adapter 223 + * 224 + * Returns true if the @port has USB type-C device connected. 225 + */ 226 + bool tb_lc_is_usb_plugged(struct tb_port *port) 227 + { 228 + struct tb_switch *sw = port->sw; 229 + int cap, ret; 230 + u32 val; 231 + 232 + if (sw->generation != 3) 233 + return false; 234 + 235 + cap = find_port_lc_cap(port); 236 + if (cap < 0) 237 + return false; 238 + 239 + ret = tb_sw_read(sw, &val, TB_CFG_SWITCH, cap + TB_LC_CS_42, 1); 240 + if (ret) 241 + return false; 242 + 243 + return !!(val & TB_LC_CS_42_USB_PLUGGED); 244 + } 245 + 246 + /** 247 + * tb_lc_is_xhci_connected() - Is the internal xHCI connected 248 + * @port: Device router lane 0 adapter 249 + * 250 + * Returns true if the internal xHCI has been connected to @port. 251 + */ 252 + bool tb_lc_is_xhci_connected(struct tb_port *port) 253 + { 254 + struct tb_switch *sw = port->sw; 255 + int cap, ret; 256 + u32 val; 257 + 258 + if (sw->generation != 3) 259 + return false; 260 + 261 + cap = find_port_lc_cap(port); 262 + if (cap < 0) 263 + return false; 264 + 265 + ret = tb_sw_read(sw, &val, TB_CFG_SWITCH, cap + TB_LC_LINK_REQ, 1); 266 + if (ret) 267 + return false; 268 + 269 + return !!(val & TB_LC_LINK_REQ_XHCI_CONNECT); 270 + } 271 + 272 + static int __tb_lc_xhci_connect(struct tb_port *port, bool connect) 273 + { 274 + struct tb_switch *sw = port->sw; 275 + int cap, ret; 276 + u32 val; 277 + 278 + if (sw->generation != 3) 279 + return -EINVAL; 280 + 281 + cap = find_port_lc_cap(port); 282 + if (cap < 0) 283 + return cap; 284 + 285 + ret = tb_sw_read(sw, &val, TB_CFG_SWITCH, cap + TB_LC_LINK_REQ, 1); 286 + if (ret) 287 + return ret; 288 + 289 + if (connect) 290 + val |= TB_LC_LINK_REQ_XHCI_CONNECT; 291 + else 292 + val &= ~TB_LC_LINK_REQ_XHCI_CONNECT; 293 + 294 + return tb_sw_write(sw, &val, TB_CFG_SWITCH, cap + TB_LC_LINK_REQ, 1); 295 + } 296 + 297 + /** 298 + * tb_lc_xhci_connect() - Connect internal xHCI 299 + * @port: Device router lane 0 adapter 300 + * 301 + * Tells LC to connect the internal xHCI to @port. Returns %0 on success 302 + * and negative errno in case of failure. Can be called for Thunderbolt 3 303 + * routers only. 304 + */ 305 + int tb_lc_xhci_connect(struct tb_port *port) 306 + { 307 + int ret; 308 + 309 + ret = __tb_lc_xhci_connect(port, true); 310 + if (ret) 311 + return ret; 312 + 313 + tb_port_dbg(port, "xHCI connected\n"); 314 + return 0; 315 + } 316 + 317 + /** 318 + * tb_lc_xhci_disconnect() - Disconnect internal xHCI 319 + * @port: Device router lane 0 adapter 320 + * 321 + * Tells LC to disconnect the internal xHCI from @port. Can be called 322 + * for Thunderbolt 3 routers only. 323 + */ 324 + void tb_lc_xhci_disconnect(struct tb_port *port) 325 + { 326 + __tb_lc_xhci_connect(port, false); 327 + tb_port_dbg(port, "xHCI disconnected\n"); 328 + } 329 + 220 330 static int tb_lc_set_wake_one(struct tb_switch *sw, unsigned int offset, 221 331 unsigned int flags) 222 332 {
+1 -2
drivers/thunderbolt/nhi.c
··· 13 13 #include <linux/slab.h> 14 14 #include <linux/errno.h> 15 15 #include <linux/pci.h> 16 + #include <linux/dma-mapping.h> 16 17 #include <linux/interrupt.h> 17 18 #include <linux/module.h> 18 19 #include <linux/delay.h> ··· 1230 1229 spin_lock_init(&nhi->lock); 1231 1230 1232 1231 res = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); 1233 - if (res) 1234 - res = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); 1235 1232 if (res) { 1236 1233 dev_err(&pdev->dev, "failed to set DMA mask\n"); 1237 1234 return res;
+76 -5
drivers/thunderbolt/switch.c
··· 1528 1528 case PCI_DEVICE_ID_INTEL_PORT_RIDGE: 1529 1529 break; 1530 1530 default: 1531 - data |= 4; 1531 + /* 1532 + * Skip Alpine Ridge, it needs to have vendor 1533 + * specific USB hotplug event enabled for the 1534 + * internal xHCI to work. 1535 + */ 1536 + if (!tb_switch_is_alpine_ridge(sw)) 1537 + data |= TB_PLUG_EVENTS_USB_DISABLE; 1532 1538 } 1533 1539 } else { 1534 1540 data = data | 0x7c; ··· 2784 2778 2785 2779 /* read drom */ 2786 2780 ret = tb_drom_read(sw); 2787 - if (ret) { 2788 - dev_err(&sw->dev, "reading DROM failed\n"); 2789 - return ret; 2790 - } 2781 + if (ret) 2782 + dev_warn(&sw->dev, "reading DROM failed: %d\n", ret); 2791 2783 tb_sw_dbg(sw, "uid: %#llx\n", sw->uid); 2792 2784 2793 2785 tb_check_quirks(sw); ··· 2977 2973 tb_sw_info(sw, "switch not present anymore\n"); 2978 2974 return err; 2979 2975 } 2976 + 2977 + /* We don't have any way to confirm this was the same device */ 2978 + if (!sw->uid) 2979 + return -ENODEV; 2980 2980 2981 2981 if (tb_switch_is_usb4(sw)) 2982 2982 err = usb4_switch_read_uid(sw, &uid); ··· 3696 3688 3697 3689 /* Write to Upstream PCIe bridge #0 aka Up0 */ 3698 3690 return tb_switch_pcie_bridge_write(sw, 0, 0x143, 0x0c5806b1); 3691 + } 3692 + 3693 + /** 3694 + * tb_switch_xhci_connect() - Connect internal xHCI 3695 + * @sw: Router whose xHCI to connect 3696 + * 3697 + * Can be called to any router. For Alpine Ridge and Titan Ridge 3698 + * performs special flows that bring the xHCI functional for any device 3699 + * connected to the type-C port. Call only after PCIe tunnel has been 3700 + * established. The function only does the connect if not done already 3701 + * so can be called several times for the same router. 3702 + */ 3703 + int tb_switch_xhci_connect(struct tb_switch *sw) 3704 + { 3705 + bool usb_port1, usb_port3, xhci_port1, xhci_port3; 3706 + struct tb_port *port1, *port3; 3707 + int ret; 3708 + 3709 + port1 = &sw->ports[1]; 3710 + port3 = &sw->ports[3]; 3711 + 3712 + if (tb_switch_is_alpine_ridge(sw)) { 3713 + usb_port1 = tb_lc_is_usb_plugged(port1); 3714 + usb_port3 = tb_lc_is_usb_plugged(port3); 3715 + xhci_port1 = tb_lc_is_xhci_connected(port1); 3716 + xhci_port3 = tb_lc_is_xhci_connected(port3); 3717 + 3718 + /* Figure out correct USB port to connect */ 3719 + if (usb_port1 && !xhci_port1) { 3720 + ret = tb_lc_xhci_connect(port1); 3721 + if (ret) 3722 + return ret; 3723 + } 3724 + if (usb_port3 && !xhci_port3) 3725 + return tb_lc_xhci_connect(port3); 3726 + } else if (tb_switch_is_titan_ridge(sw)) { 3727 + ret = tb_lc_xhci_connect(port1); 3728 + if (ret) 3729 + return ret; 3730 + return tb_lc_xhci_connect(port3); 3731 + } 3732 + 3733 + return 0; 3734 + } 3735 + 3736 + /** 3737 + * tb_switch_xhci_disconnect() - Disconnect internal xHCI 3738 + * @sw: Router whose xHCI to disconnect 3739 + * 3740 + * The opposite of tb_switch_xhci_connect(). Disconnects xHCI on both 3741 + * ports. 3742 + */ 3743 + void tb_switch_xhci_disconnect(struct tb_switch *sw) 3744 + { 3745 + if (sw->generation == 3) { 3746 + struct tb_port *port1 = &sw->ports[1]; 3747 + struct tb_port *port3 = &sw->ports[3]; 3748 + 3749 + tb_lc_xhci_disconnect(port1); 3750 + tb_port_dbg(port1, "disconnected xHCI\n"); 3751 + tb_lc_xhci_disconnect(port3); 3752 + tb_port_dbg(port3, "disconnected xHCI\n"); 3753 + } 3699 3754 }
+11
drivers/thunderbolt/tb.c
··· 1054 1054 if (WARN_ON(!tunnel)) 1055 1055 return -ENODEV; 1056 1056 1057 + tb_switch_xhci_disconnect(sw); 1058 + 1057 1059 tb_tunnel_deactivate(tunnel); 1058 1060 list_del(&tunnel->list); 1059 1061 tb_tunnel_free(tunnel); ··· 1100 1098 */ 1101 1099 if (tb_switch_pcie_l1_enable(sw)) 1102 1100 tb_sw_warn(sw, "failed to enable PCIe L1 for Titan Ridge\n"); 1101 + 1102 + if (tb_switch_xhci_connect(sw)) 1103 + tb_sw_warn(sw, "failed to connect xHCI\n"); 1103 1104 1104 1105 list_add_tail(&tunnel->list, &tcm->tunnel_list); 1105 1106 return 0; ··· 1261 1256 tb_port_unconfigure_xdomain(port); 1262 1257 } else if (tb_port_is_dpout(port) || tb_port_is_dpin(port)) { 1263 1258 tb_dp_resource_unavailable(tb, port); 1259 + } else if (!port->port) { 1260 + tb_sw_dbg(sw, "xHCI disconnect request\n"); 1261 + tb_switch_xhci_disconnect(sw); 1264 1262 } else { 1265 1263 tb_port_dbg(port, 1266 1264 "got unplug event for disconnected port, ignoring\n"); 1267 1265 } 1268 1266 } else if (port->remote) { 1269 1267 tb_port_dbg(port, "got plug event for connected port, ignoring\n"); 1268 + } else if (!port->port && sw->authorized) { 1269 + tb_sw_dbg(sw, "xHCI connect request\n"); 1270 + tb_switch_xhci_connect(sw); 1270 1271 } else { 1271 1272 if (tb_port_is_null(port)) { 1272 1273 tb_port_dbg(port, "hotplug: scanning\n");
+8
drivers/thunderbolt/tb.h
··· 855 855 if (sw->config.vendor_id == PCI_VENDOR_ID_INTEL) { 856 856 switch (sw->config.device_id) { 857 857 case PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_2C_BRIDGE: 858 + case PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_4C_BRIDGE: 858 859 case PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_LP_BRIDGE: 859 860 case PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_C_4C_BRIDGE: 860 861 case PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_C_2C_BRIDGE: ··· 988 987 989 988 int tb_switch_pcie_l1_enable(struct tb_switch *sw); 990 989 990 + int tb_switch_xhci_connect(struct tb_switch *sw); 991 + void tb_switch_xhci_disconnect(struct tb_switch *sw); 992 + 991 993 int tb_wait_for_port(struct tb_port *port, bool wait_if_unplugged); 992 994 int tb_port_add_nfc_credits(struct tb_port *port, int credits); 993 995 int tb_port_clear_counter(struct tb_port *port, int counter); ··· 1085 1081 void tb_lc_unconfigure_xdomain(struct tb_port *port); 1086 1082 int tb_lc_start_lane_initialization(struct tb_port *port); 1087 1083 bool tb_lc_is_clx_supported(struct tb_port *port); 1084 + bool tb_lc_is_usb_plugged(struct tb_port *port); 1085 + bool tb_lc_is_xhci_connected(struct tb_port *port); 1086 + int tb_lc_xhci_connect(struct tb_port *port); 1087 + void tb_lc_xhci_disconnect(struct tb_port *port); 1088 1088 int tb_lc_set_wake(struct tb_switch *sw, unsigned int flags); 1089 1089 int tb_lc_set_sleep(struct tb_switch *sw); 1090 1090 bool tb_lc_lane_bonding_possible(struct tb_switch *sw);
+25 -12
drivers/thunderbolt/tb_regs.h
··· 133 133 } __packed; 134 134 135 135 struct tb_eeprom_ctl { 136 - bool clock:1; /* send pulse to transfer one bit */ 137 - bool access_low:1; /* set to 0 before access */ 138 - bool data_out:1; /* to eeprom */ 139 - bool data_in:1; /* from eeprom */ 140 - bool access_high:1; /* set to 1 before access */ 136 + bool fl_sk:1; /* send pulse to transfer one bit */ 137 + bool fl_cs:1; /* set to 0 before access */ 138 + bool fl_di:1; /* to eeprom */ 139 + bool fl_do:1; /* from eeprom */ 140 + bool bit_banging_enable:1; /* set to 1 before access */ 141 141 bool not_present:1; /* should be 0 */ 142 142 bool unknown1:1; 143 143 bool present:1; /* should be 1 */ ··· 146 146 147 147 struct tb_cap_plug_events { 148 148 struct tb_cap_extended_short cap_header; 149 - u32 __unknown1:2; 150 - u32 plug_events:5; 151 - u32 __unknown2:25; 152 - u32 __unknown3; 153 - u32 __unknown4; 149 + u32 __unknown1:2; /* VSC_CS_1 */ 150 + u32 plug_events:5; /* VSC_CS_1 */ 151 + u32 __unknown2:25; /* VSC_CS_1 */ 152 + u32 vsc_cs_2; 153 + u32 vsc_cs_3; 154 154 struct tb_eeprom_ctl eeprom_ctl; 155 - u32 __unknown5[7]; 156 - u32 drom_offset; /* 32 bit register, but eeprom addresses are 16 bit */ 155 + u32 __unknown5[7]; /* VSC_CS_5 -> VSC_CS_11 */ 156 + u32 drom_offset; /* VSC_CS_12: 32 bit register, but eeprom addresses are 16 bit */ 157 157 } __packed; 158 158 159 159 /* device headers */ ··· 389 389 #define DP_COMMON_CAP_1_LANE 0x0 390 390 #define DP_COMMON_CAP_2_LANES 0x1 391 391 #define DP_COMMON_CAP_4_LANES 0x2 392 + #define DP_COMMON_CAP_LTTPR_NS BIT(27) 392 393 #define DP_COMMON_CAP_DPRX_DONE BIT(31) 393 394 394 395 /* PCIe adapter registers */ ··· 463 462 #define TMU_ADP_CS_6_DISABLE_TMU_OBJ_CL2 BIT(3) 464 463 465 464 /* Plug Events registers */ 465 + #define TB_PLUG_EVENTS_USB_DISABLE BIT(2) 466 + #define TB_PLUG_EVENTS_CS_1_LANE_DISABLE BIT(3) 467 + #define TB_PLUG_EVENTS_CS_1_DPOUT_DISABLE BIT(4) 468 + #define TB_PLUG_EVENTS_CS_1_LOW_DPIN_DISABLE BIT(5) 469 + #define TB_PLUG_EVENTS_CS_1_HIGH_DPIN_DISABLE BIT(6) 470 + 466 471 #define TB_PLUG_EVENTS_PCIE_WR_DATA 0x1b 467 472 #define TB_PLUG_EVENTS_PCIE_CMD 0x1c 468 473 #define TB_PLUG_EVENTS_PCIE_CMD_DW_OFFSET_MASK GENMASK(9, 0) ··· 508 501 #define TB_LC_POWER 0x740 509 502 510 503 /* Link controller registers */ 504 + #define TB_LC_CS_42 0x2a 505 + #define TB_LC_CS_42_USB_PLUGGED BIT(31) 506 + 511 507 #define TB_LC_PORT_ATTR 0x8d 512 508 #define TB_LC_PORT_ATTR_BE BIT(12) 513 509 ··· 530 520 #define TB_LC_SX_CTRL_SLP BIT(31) 531 521 #define TB_LC_LINK_ATTR 0x97 532 522 #define TB_LC_LINK_ATTR_CPS BIT(18) 523 + 524 + #define TB_LC_LINK_REQ 0xad 525 + #define TB_LC_LINK_REQ_XHCI_CONNECT BIT(31) 533 526 534 527 #endif
+10
drivers/thunderbolt/tunnel.c
··· 580 580 out_dp_cap = tb_dp_cap_set_lanes(out_dp_cap, new_lanes); 581 581 } 582 582 583 + /* 584 + * Titan Ridge does not disable AUX timers when it gets 585 + * SET_CONFIG with SET_LTTPR_MODE set. This causes problems with 586 + * DP tunneling. 587 + */ 588 + if (tb_route(out->sw) && tb_switch_is_titan_ridge(out->sw)) { 589 + out_dp_cap |= DP_COMMON_CAP_LTTPR_NS; 590 + tb_port_dbg(out, "disabling LTTPR\n"); 591 + } 592 + 583 593 return tb_port_write(in, &out_dp_cap, TB_CFG_PORT, 584 594 in->cap_adap + DP_REMOTE_CAP, 1); 585 595 }
+153 -150
drivers/usb/cdns3/cdnsp-debug.h
··· 182 182 int ep_id = TRB_TO_EP_INDEX(field3) - 1; 183 183 int type = TRB_FIELD_TO_TYPE(field3); 184 184 unsigned int ep_num; 185 - int ret = 0; 185 + int ret; 186 186 u32 temp; 187 187 188 188 ep_num = DIV_ROUND_UP(ep_id, 2); 189 189 190 190 switch (type) { 191 191 case TRB_LINK: 192 - ret += snprintf(str, size, 193 - "LINK %08x%08x intr %ld type '%s' flags %c:%c:%c:%c", 194 - field1, field0, GET_INTR_TARGET(field2), 195 - cdnsp_trb_type_string(type), 196 - field3 & TRB_IOC ? 'I' : 'i', 197 - field3 & TRB_CHAIN ? 'C' : 'c', 198 - field3 & TRB_TC ? 'T' : 't', 199 - field3 & TRB_CYCLE ? 'C' : 'c'); 192 + ret = snprintf(str, size, 193 + "LINK %08x%08x intr %ld type '%s' flags %c:%c:%c:%c", 194 + field1, field0, GET_INTR_TARGET(field2), 195 + cdnsp_trb_type_string(type), 196 + field3 & TRB_IOC ? 'I' : 'i', 197 + field3 & TRB_CHAIN ? 'C' : 'c', 198 + field3 & TRB_TC ? 'T' : 't', 199 + field3 & TRB_CYCLE ? 'C' : 'c'); 200 200 break; 201 201 case TRB_TRANSFER: 202 202 case TRB_COMPLETION: 203 203 case TRB_PORT_STATUS: 204 204 case TRB_HC_EVENT: 205 - ret += snprintf(str, size, 206 - "ep%d%s(%d) type '%s' TRB %08x%08x status '%s'" 207 - " len %ld slot %ld flags %c:%c", 208 - ep_num, ep_id % 2 ? "out" : "in", 209 - TRB_TO_EP_INDEX(field3), 210 - cdnsp_trb_type_string(type), field1, field0, 211 - cdnsp_trb_comp_code_string(GET_COMP_CODE(field2)), 212 - EVENT_TRB_LEN(field2), TRB_TO_SLOT_ID(field3), 213 - field3 & EVENT_DATA ? 'E' : 'e', 214 - field3 & TRB_CYCLE ? 'C' : 'c'); 205 + ret = snprintf(str, size, 206 + "ep%d%s(%d) type '%s' TRB %08x%08x status '%s'" 207 + " len %ld slot %ld flags %c:%c", 208 + ep_num, ep_id % 2 ? "out" : "in", 209 + TRB_TO_EP_INDEX(field3), 210 + cdnsp_trb_type_string(type), field1, field0, 211 + cdnsp_trb_comp_code_string(GET_COMP_CODE(field2)), 212 + EVENT_TRB_LEN(field2), TRB_TO_SLOT_ID(field3), 213 + field3 & EVENT_DATA ? 'E' : 'e', 214 + field3 & TRB_CYCLE ? 'C' : 'c'); 215 215 break; 216 216 case TRB_MFINDEX_WRAP: 217 - ret += snprintf(str, size, "%s: flags %c", 218 - cdnsp_trb_type_string(type), 219 - field3 & TRB_CYCLE ? 'C' : 'c'); 217 + ret = snprintf(str, size, "%s: flags %c", 218 + cdnsp_trb_type_string(type), 219 + field3 & TRB_CYCLE ? 'C' : 'c'); 220 220 break; 221 221 case TRB_SETUP: 222 - ret += snprintf(str, size, 223 - "type '%s' bRequestType %02x bRequest %02x " 224 - "wValue %02x%02x wIndex %02x%02x wLength %d " 225 - "length %ld TD size %ld intr %ld Setup ID %ld " 226 - "flags %c:%c:%c", 227 - cdnsp_trb_type_string(type), 228 - field0 & 0xff, 229 - (field0 & 0xff00) >> 8, 230 - (field0 & 0xff000000) >> 24, 231 - (field0 & 0xff0000) >> 16, 232 - (field1 & 0xff00) >> 8, 233 - field1 & 0xff, 234 - (field1 & 0xff000000) >> 16 | 235 - (field1 & 0xff0000) >> 16, 236 - TRB_LEN(field2), GET_TD_SIZE(field2), 237 - GET_INTR_TARGET(field2), 238 - TRB_SETUPID_TO_TYPE(field3), 239 - field3 & TRB_IDT ? 'D' : 'd', 240 - field3 & TRB_IOC ? 'I' : 'i', 241 - field3 & TRB_CYCLE ? 'C' : 'c'); 222 + ret = snprintf(str, size, 223 + "type '%s' bRequestType %02x bRequest %02x " 224 + "wValue %02x%02x wIndex %02x%02x wLength %d " 225 + "length %ld TD size %ld intr %ld Setup ID %ld " 226 + "flags %c:%c:%c", 227 + cdnsp_trb_type_string(type), 228 + field0 & 0xff, 229 + (field0 & 0xff00) >> 8, 230 + (field0 & 0xff000000) >> 24, 231 + (field0 & 0xff0000) >> 16, 232 + (field1 & 0xff00) >> 8, 233 + field1 & 0xff, 234 + (field1 & 0xff000000) >> 16 | 235 + (field1 & 0xff0000) >> 16, 236 + TRB_LEN(field2), GET_TD_SIZE(field2), 237 + GET_INTR_TARGET(field2), 238 + TRB_SETUPID_TO_TYPE(field3), 239 + field3 & TRB_IDT ? 'D' : 'd', 240 + field3 & TRB_IOC ? 'I' : 'i', 241 + field3 & TRB_CYCLE ? 'C' : 'c'); 242 242 break; 243 243 case TRB_DATA: 244 - ret += snprintf(str, size, 245 - "type '%s' Buffer %08x%08x length %ld TD size %ld " 246 - "intr %ld flags %c:%c:%c:%c:%c:%c:%c", 247 - cdnsp_trb_type_string(type), 248 - field1, field0, TRB_LEN(field2), 249 - GET_TD_SIZE(field2), 250 - GET_INTR_TARGET(field2), 251 - field3 & TRB_IDT ? 'D' : 'i', 252 - field3 & TRB_IOC ? 'I' : 'i', 253 - field3 & TRB_CHAIN ? 'C' : 'c', 254 - field3 & TRB_NO_SNOOP ? 'S' : 's', 255 - field3 & TRB_ISP ? 'I' : 'i', 256 - field3 & TRB_ENT ? 'E' : 'e', 257 - field3 & TRB_CYCLE ? 'C' : 'c'); 244 + ret = snprintf(str, size, 245 + "type '%s' Buffer %08x%08x length %ld TD size %ld " 246 + "intr %ld flags %c:%c:%c:%c:%c:%c:%c", 247 + cdnsp_trb_type_string(type), 248 + field1, field0, TRB_LEN(field2), 249 + GET_TD_SIZE(field2), 250 + GET_INTR_TARGET(field2), 251 + field3 & TRB_IDT ? 'D' : 'i', 252 + field3 & TRB_IOC ? 'I' : 'i', 253 + field3 & TRB_CHAIN ? 'C' : 'c', 254 + field3 & TRB_NO_SNOOP ? 'S' : 's', 255 + field3 & TRB_ISP ? 'I' : 'i', 256 + field3 & TRB_ENT ? 'E' : 'e', 257 + field3 & TRB_CYCLE ? 'C' : 'c'); 258 258 break; 259 259 case TRB_STATUS: 260 - ret += snprintf(str, size, 261 - "Buffer %08x%08x length %ld TD size %ld intr" 262 - "%ld type '%s' flags %c:%c:%c:%c", 263 - field1, field0, TRB_LEN(field2), 264 - GET_TD_SIZE(field2), 265 - GET_INTR_TARGET(field2), 266 - cdnsp_trb_type_string(type), 267 - field3 & TRB_IOC ? 'I' : 'i', 268 - field3 & TRB_CHAIN ? 'C' : 'c', 269 - field3 & TRB_ENT ? 'E' : 'e', 270 - field3 & TRB_CYCLE ? 'C' : 'c'); 260 + ret = snprintf(str, size, 261 + "Buffer %08x%08x length %ld TD size %ld intr" 262 + "%ld type '%s' flags %c:%c:%c:%c", 263 + field1, field0, TRB_LEN(field2), 264 + GET_TD_SIZE(field2), 265 + GET_INTR_TARGET(field2), 266 + cdnsp_trb_type_string(type), 267 + field3 & TRB_IOC ? 'I' : 'i', 268 + field3 & TRB_CHAIN ? 'C' : 'c', 269 + field3 & TRB_ENT ? 'E' : 'e', 270 + field3 & TRB_CYCLE ? 'C' : 'c'); 271 271 break; 272 272 case TRB_NORMAL: 273 273 case TRB_ISOC: 274 274 case TRB_EVENT_DATA: 275 275 case TRB_TR_NOOP: 276 - ret += snprintf(str, size, 277 - "type '%s' Buffer %08x%08x length %ld " 278 - "TD size %ld intr %ld " 279 - "flags %c:%c:%c:%c:%c:%c:%c:%c:%c", 280 - cdnsp_trb_type_string(type), 281 - field1, field0, TRB_LEN(field2), 282 - GET_TD_SIZE(field2), 283 - GET_INTR_TARGET(field2), 284 - field3 & TRB_BEI ? 'B' : 'b', 285 - field3 & TRB_IDT ? 'T' : 't', 286 - field3 & TRB_IOC ? 'I' : 'i', 287 - field3 & TRB_CHAIN ? 'C' : 'c', 288 - field3 & TRB_NO_SNOOP ? 'S' : 's', 289 - field3 & TRB_ISP ? 'I' : 'i', 290 - field3 & TRB_ENT ? 'E' : 'e', 291 - field3 & TRB_CYCLE ? 'C' : 'c', 292 - !(field3 & TRB_EVENT_INVALIDATE) ? 'V' : 'v'); 276 + ret = snprintf(str, size, 277 + "type '%s' Buffer %08x%08x length %ld " 278 + "TD size %ld intr %ld " 279 + "flags %c:%c:%c:%c:%c:%c:%c:%c:%c", 280 + cdnsp_trb_type_string(type), 281 + field1, field0, TRB_LEN(field2), 282 + GET_TD_SIZE(field2), 283 + GET_INTR_TARGET(field2), 284 + field3 & TRB_BEI ? 'B' : 'b', 285 + field3 & TRB_IDT ? 'T' : 't', 286 + field3 & TRB_IOC ? 'I' : 'i', 287 + field3 & TRB_CHAIN ? 'C' : 'c', 288 + field3 & TRB_NO_SNOOP ? 'S' : 's', 289 + field3 & TRB_ISP ? 'I' : 'i', 290 + field3 & TRB_ENT ? 'E' : 'e', 291 + field3 & TRB_CYCLE ? 'C' : 'c', 292 + !(field3 & TRB_EVENT_INVALIDATE) ? 'V' : 'v'); 293 293 break; 294 294 case TRB_CMD_NOOP: 295 295 case TRB_ENABLE_SLOT: 296 - ret += snprintf(str, size, "%s: flags %c", 297 - cdnsp_trb_type_string(type), 298 - field3 & TRB_CYCLE ? 'C' : 'c'); 296 + ret = snprintf(str, size, "%s: flags %c", 297 + cdnsp_trb_type_string(type), 298 + field3 & TRB_CYCLE ? 'C' : 'c'); 299 299 break; 300 300 case TRB_DISABLE_SLOT: 301 - ret += snprintf(str, size, "%s: slot %ld flags %c", 302 - cdnsp_trb_type_string(type), 303 - TRB_TO_SLOT_ID(field3), 304 - field3 & TRB_CYCLE ? 'C' : 'c'); 301 + ret = snprintf(str, size, "%s: slot %ld flags %c", 302 + cdnsp_trb_type_string(type), 303 + TRB_TO_SLOT_ID(field3), 304 + field3 & TRB_CYCLE ? 'C' : 'c'); 305 305 break; 306 306 case TRB_ADDR_DEV: 307 - ret += snprintf(str, size, 308 - "%s: ctx %08x%08x slot %ld flags %c:%c", 309 - cdnsp_trb_type_string(type), field1, field0, 310 - TRB_TO_SLOT_ID(field3), 311 - field3 & TRB_BSR ? 'B' : 'b', 312 - field3 & TRB_CYCLE ? 'C' : 'c'); 307 + ret = snprintf(str, size, 308 + "%s: ctx %08x%08x slot %ld flags %c:%c", 309 + cdnsp_trb_type_string(type), field1, field0, 310 + TRB_TO_SLOT_ID(field3), 311 + field3 & TRB_BSR ? 'B' : 'b', 312 + field3 & TRB_CYCLE ? 'C' : 'c'); 313 313 break; 314 314 case TRB_CONFIG_EP: 315 - ret += snprintf(str, size, 316 - "%s: ctx %08x%08x slot %ld flags %c:%c", 317 - cdnsp_trb_type_string(type), field1, field0, 318 - TRB_TO_SLOT_ID(field3), 319 - field3 & TRB_DC ? 'D' : 'd', 320 - field3 & TRB_CYCLE ? 'C' : 'c'); 315 + ret = snprintf(str, size, 316 + "%s: ctx %08x%08x slot %ld flags %c:%c", 317 + cdnsp_trb_type_string(type), field1, field0, 318 + TRB_TO_SLOT_ID(field3), 319 + field3 & TRB_DC ? 'D' : 'd', 320 + field3 & TRB_CYCLE ? 'C' : 'c'); 321 321 break; 322 322 case TRB_EVAL_CONTEXT: 323 - ret += snprintf(str, size, 324 - "%s: ctx %08x%08x slot %ld flags %c", 325 - cdnsp_trb_type_string(type), field1, field0, 326 - TRB_TO_SLOT_ID(field3), 327 - field3 & TRB_CYCLE ? 'C' : 'c'); 323 + ret = snprintf(str, size, 324 + "%s: ctx %08x%08x slot %ld flags %c", 325 + cdnsp_trb_type_string(type), field1, field0, 326 + TRB_TO_SLOT_ID(field3), 327 + field3 & TRB_CYCLE ? 'C' : 'c'); 328 328 break; 329 329 case TRB_RESET_EP: 330 330 case TRB_HALT_ENDPOINT: 331 331 case TRB_FLUSH_ENDPOINT: 332 - ret += snprintf(str, size, 333 - "%s: ep%d%s(%d) ctx %08x%08x slot %ld flags %c", 334 - cdnsp_trb_type_string(type), 335 - ep_num, ep_id % 2 ? "out" : "in", 336 - TRB_TO_EP_INDEX(field3), field1, field0, 337 - TRB_TO_SLOT_ID(field3), 338 - field3 & TRB_CYCLE ? 'C' : 'c'); 332 + ret = snprintf(str, size, 333 + "%s: ep%d%s(%d) ctx %08x%08x slot %ld flags %c", 334 + cdnsp_trb_type_string(type), 335 + ep_num, ep_id % 2 ? "out" : "in", 336 + TRB_TO_EP_INDEX(field3), field1, field0, 337 + TRB_TO_SLOT_ID(field3), 338 + field3 & TRB_CYCLE ? 'C' : 'c'); 339 339 break; 340 340 case TRB_STOP_RING: 341 - ret += snprintf(str, size, 342 - "%s: ep%d%s(%d) slot %ld sp %d flags %c", 343 - cdnsp_trb_type_string(type), 344 - ep_num, ep_id % 2 ? "out" : "in", 345 - TRB_TO_EP_INDEX(field3), 346 - TRB_TO_SLOT_ID(field3), 347 - TRB_TO_SUSPEND_PORT(field3), 348 - field3 & TRB_CYCLE ? 'C' : 'c'); 341 + ret = snprintf(str, size, 342 + "%s: ep%d%s(%d) slot %ld sp %d flags %c", 343 + cdnsp_trb_type_string(type), 344 + ep_num, ep_id % 2 ? "out" : "in", 345 + TRB_TO_EP_INDEX(field3), 346 + TRB_TO_SLOT_ID(field3), 347 + TRB_TO_SUSPEND_PORT(field3), 348 + field3 & TRB_CYCLE ? 'C' : 'c'); 349 349 break; 350 350 case TRB_SET_DEQ: 351 - ret += snprintf(str, size, 352 - "%s: ep%d%s(%d) deq %08x%08x stream %ld slot %ld flags %c", 353 - cdnsp_trb_type_string(type), 354 - ep_num, ep_id % 2 ? "out" : "in", 355 - TRB_TO_EP_INDEX(field3), field1, field0, 356 - TRB_TO_STREAM_ID(field2), 357 - TRB_TO_SLOT_ID(field3), 358 - field3 & TRB_CYCLE ? 'C' : 'c'); 351 + ret = snprintf(str, size, 352 + "%s: ep%d%s(%d) deq %08x%08x stream %ld slot %ld flags %c", 353 + cdnsp_trb_type_string(type), 354 + ep_num, ep_id % 2 ? "out" : "in", 355 + TRB_TO_EP_INDEX(field3), field1, field0, 356 + TRB_TO_STREAM_ID(field2), 357 + TRB_TO_SLOT_ID(field3), 358 + field3 & TRB_CYCLE ? 'C' : 'c'); 359 359 break; 360 360 case TRB_RESET_DEV: 361 - ret += snprintf(str, size, "%s: slot %ld flags %c", 362 - cdnsp_trb_type_string(type), 363 - TRB_TO_SLOT_ID(field3), 364 - field3 & TRB_CYCLE ? 'C' : 'c'); 361 + ret = snprintf(str, size, "%s: slot %ld flags %c", 362 + cdnsp_trb_type_string(type), 363 + TRB_TO_SLOT_ID(field3), 364 + field3 & TRB_CYCLE ? 'C' : 'c'); 365 365 break; 366 366 case TRB_ENDPOINT_NRDY: 367 - temp = TRB_TO_HOST_STREAM(field2); 367 + temp = TRB_TO_HOST_STREAM(field2); 368 368 369 - ret += snprintf(str, size, 370 - "%s: ep%d%s(%d) H_SID %x%s%s D_SID %lx flags %c:%c", 371 - cdnsp_trb_type_string(type), 372 - ep_num, ep_id % 2 ? "out" : "in", 373 - TRB_TO_EP_INDEX(field3), temp, 374 - temp == STREAM_PRIME_ACK ? "(PRIME)" : "", 375 - temp == STREAM_REJECTED ? "(REJECTED)" : "", 376 - TRB_TO_DEV_STREAM(field0), 377 - field3 & TRB_STAT ? 'S' : 's', 378 - field3 & TRB_CYCLE ? 'C' : 'c'); 369 + ret = snprintf(str, size, 370 + "%s: ep%d%s(%d) H_SID %x%s%s D_SID %lx flags %c:%c", 371 + cdnsp_trb_type_string(type), 372 + ep_num, ep_id % 2 ? "out" : "in", 373 + TRB_TO_EP_INDEX(field3), temp, 374 + temp == STREAM_PRIME_ACK ? "(PRIME)" : "", 375 + temp == STREAM_REJECTED ? "(REJECTED)" : "", 376 + TRB_TO_DEV_STREAM(field0), 377 + field3 & TRB_STAT ? 'S' : 's', 378 + field3 & TRB_CYCLE ? 'C' : 'c'); 379 379 break; 380 380 default: 381 - ret += snprintf(str, size, 382 - "type '%s' -> raw %08x %08x %08x %08x", 383 - cdnsp_trb_type_string(type), 384 - field0, field1, field2, field3); 381 + ret = snprintf(str, size, 382 + "type '%s' -> raw %08x %08x %08x %08x", 383 + cdnsp_trb_type_string(type), 384 + field0, field1, field2, field3); 385 385 } 386 + 387 + if (ret >= size) 388 + pr_info("CDNSP: buffer overflowed.\n"); 386 389 387 390 return str; 388 391 }
-3
drivers/usb/cdns3/cdnsp-gadget.c
··· 1243 1243 enum usb_device_speed speed) 1244 1244 { 1245 1245 u32 fs_speed = 0; 1246 - u64 temp_64; 1247 1246 u32 temp; 1248 1247 int ret; 1249 1248 1250 - temp_64 = cdnsp_read_64(&pdev->ir_set->erst_dequeue); 1251 - temp_64 &= ~ERST_PTR_MASK; 1252 1249 temp = readl(&pdev->ir_set->irq_control); 1253 1250 temp &= ~IMOD_INTERVAL_MASK; 1254 1251 temp |= ((IMOD_DEFAULT_INTERVAL / 250) & IMOD_INTERVAL_MASK);
+1 -1
drivers/usb/chipidea/udc.c
··· 2152 2152 { 2153 2153 /* 2154 2154 * host doesn't care B_SESSION_VALID event 2155 - * so clear and disbale BSV irq 2155 + * so clear and disable BSV irq 2156 2156 */ 2157 2157 if (ci->is_otg) 2158 2158 hw_write_otgsc(ci, OTGSC_BSVIE | OTGSC_BSVIS, OTGSC_BSVIS);
+70 -1
drivers/usb/common/ulpi.c
··· 13 13 #include <linux/module.h> 14 14 #include <linux/slab.h> 15 15 #include <linux/acpi.h> 16 + #include <linux/debugfs.h> 16 17 #include <linux/of.h> 17 18 #include <linux/of_device.h> 18 19 #include <linux/clk/clk-conf.h> ··· 233 232 return 0; 234 233 } 235 234 235 + static int ulpi_regs_read(struct seq_file *seq, void *data) 236 + { 237 + struct ulpi *ulpi = seq->private; 238 + 239 + #define ulpi_print(name, reg) do { \ 240 + int ret = ulpi_read(ulpi, reg); \ 241 + if (ret < 0) \ 242 + return ret; \ 243 + seq_printf(seq, name " %.02x\n", ret); \ 244 + } while (0) 245 + 246 + ulpi_print("Vendor ID Low ", ULPI_VENDOR_ID_LOW); 247 + ulpi_print("Vendor ID High ", ULPI_VENDOR_ID_HIGH); 248 + ulpi_print("Product ID Low ", ULPI_PRODUCT_ID_LOW); 249 + ulpi_print("Product ID High ", ULPI_PRODUCT_ID_HIGH); 250 + ulpi_print("Function Control ", ULPI_FUNC_CTRL); 251 + ulpi_print("Interface Control ", ULPI_IFC_CTRL); 252 + ulpi_print("OTG Control ", ULPI_OTG_CTRL); 253 + ulpi_print("USB Interrupt Enable Rising ", ULPI_USB_INT_EN_RISE); 254 + ulpi_print("USB Interrupt Enable Falling", ULPI_USB_INT_EN_FALL); 255 + ulpi_print("USB Interrupt Status ", ULPI_USB_INT_STS); 256 + ulpi_print("USB Interrupt Latch ", ULPI_USB_INT_LATCH); 257 + ulpi_print("Debug ", ULPI_DEBUG); 258 + ulpi_print("Scratch Register ", ULPI_SCRATCH); 259 + ulpi_print("Carkit Control ", ULPI_CARKIT_CTRL); 260 + ulpi_print("Carkit Interrupt Delay ", ULPI_CARKIT_INT_DELAY); 261 + ulpi_print("Carkit Interrupt Enable ", ULPI_CARKIT_INT_EN); 262 + ulpi_print("Carkit Interrupt Status ", ULPI_CARKIT_INT_STS); 263 + ulpi_print("Carkit Interrupt Latch ", ULPI_CARKIT_INT_LATCH); 264 + ulpi_print("Carkit Pulse Control ", ULPI_CARKIT_PLS_CTRL); 265 + ulpi_print("Transmit Positive Width ", ULPI_TX_POS_WIDTH); 266 + ulpi_print("Transmit Negative Width ", ULPI_TX_NEG_WIDTH); 267 + ulpi_print("Receive Polarity Recovery ", ULPI_POLARITY_RECOVERY); 268 + 269 + return 0; 270 + } 271 + 272 + static int ulpi_regs_open(struct inode *inode, struct file *f) 273 + { 274 + struct ulpi *ulpi = inode->i_private; 275 + 276 + return single_open(f, ulpi_regs_read, ulpi); 277 + } 278 + 279 + static const struct file_operations ulpi_regs_ops = { 280 + .owner = THIS_MODULE, 281 + .open = ulpi_regs_open, 282 + .release = single_release, 283 + .read = seq_read, 284 + .llseek = seq_lseek 285 + }; 286 + 287 + #define ULPI_ROOT debugfs_lookup(KBUILD_MODNAME, NULL) 288 + 236 289 static int ulpi_register(struct device *dev, struct ulpi *ulpi) 237 290 { 238 291 int ret; 292 + struct dentry *root; 239 293 240 294 ulpi->dev.parent = dev; /* needed early for ops */ 241 295 ulpi->dev.bus = &ulpi_bus; ··· 314 258 put_device(&ulpi->dev); 315 259 return ret; 316 260 } 261 + 262 + root = debugfs_create_dir(dev_name(dev), ULPI_ROOT); 263 + debugfs_create_file("regs", 0444, root, ulpi, &ulpi_regs_ops); 317 264 318 265 dev_dbg(&ulpi->dev, "registered ULPI PHY: vendor %04x, product %04x\n", 319 266 ulpi->id.vendor, ulpi->id.product); ··· 363 304 */ 364 305 void ulpi_unregister_interface(struct ulpi *ulpi) 365 306 { 307 + debugfs_remove_recursive(debugfs_lookup(dev_name(&ulpi->dev), 308 + ULPI_ROOT)); 366 309 device_unregister(&ulpi->dev); 367 310 } 368 311 EXPORT_SYMBOL_GPL(ulpi_unregister_interface); ··· 373 312 374 313 static int __init ulpi_init(void) 375 314 { 376 - return bus_register(&ulpi_bus); 315 + int ret; 316 + struct dentry *root; 317 + 318 + root = debugfs_create_dir(KBUILD_MODNAME, NULL); 319 + ret = bus_register(&ulpi_bus); 320 + if (ret) 321 + debugfs_remove(root); 322 + return ret; 377 323 } 378 324 subsys_initcall(ulpi_init); 379 325 380 326 static void __exit ulpi_exit(void) 381 327 { 382 328 bus_unregister(&ulpi_bus); 329 + debugfs_remove_recursive(ULPI_ROOT); 383 330 } 384 331 module_exit(ulpi_exit); 385 332
+3 -17
drivers/usb/common/usb-conn-gpio.c
··· 175 175 { 176 176 struct device *dev = &pdev->dev; 177 177 struct usb_conn_info *info; 178 - bool need_vbus = true; 179 178 int ret = 0; 180 179 181 180 info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL); ··· 204 205 205 206 INIT_DELAYED_WORK(&info->dw_det, usb_conn_detect_cable); 206 207 207 - /* 208 - * If the USB connector is a child of a USB port and that port already provides the VBUS 209 - * supply, there's no need for the USB connector to provide it again. 210 - */ 211 - if (dev->parent && dev->parent->of_node) { 212 - if (of_find_property(dev->parent->of_node, "vbus-supply", NULL)) 213 - need_vbus = false; 214 - } 215 - 216 - if (!need_vbus) { 217 - info->vbus = devm_regulator_get_optional(dev, "vbus"); 218 - if (PTR_ERR(info->vbus) == -ENODEV) 219 - info->vbus = NULL; 220 - } else { 221 - info->vbus = devm_regulator_get(dev, "vbus"); 222 - } 208 + info->vbus = devm_regulator_get_optional(dev, "vbus"); 209 + if (PTR_ERR(info->vbus) == -ENODEV) 210 + info->vbus = NULL; 223 211 224 212 if (IS_ERR(info->vbus)) { 225 213 ret = PTR_ERR(info->vbus);
+22 -10
drivers/usb/core/devio.c
··· 139 139 /* Hard limit, necessary to avoid arithmetic overflow */ 140 140 #define USBFS_XFER_MAX (UINT_MAX / 2 - 1000000) 141 141 142 - static atomic64_t usbfs_memory_usage; /* Total memory currently allocated */ 142 + static DEFINE_SPINLOCK(usbfs_memory_usage_lock); 143 + static u64 usbfs_memory_usage; /* Total memory currently allocated */ 143 144 144 145 /* Check whether it's okay to allocate more memory for a transfer */ 145 146 static int usbfs_increase_memory_usage(u64 amount) 146 147 { 147 - u64 lim; 148 + u64 lim, total_mem; 149 + unsigned long flags; 150 + int ret; 148 151 149 152 lim = READ_ONCE(usbfs_memory_mb); 150 153 lim <<= 20; 151 154 152 - atomic64_add(amount, &usbfs_memory_usage); 155 + ret = 0; 156 + spin_lock_irqsave(&usbfs_memory_usage_lock, flags); 157 + total_mem = usbfs_memory_usage + amount; 158 + if (lim > 0 && total_mem > lim) 159 + ret = -ENOMEM; 160 + else 161 + usbfs_memory_usage = total_mem; 162 + spin_unlock_irqrestore(&usbfs_memory_usage_lock, flags); 153 163 154 - if (lim > 0 && atomic64_read(&usbfs_memory_usage) > lim) { 155 - atomic64_sub(amount, &usbfs_memory_usage); 156 - return -ENOMEM; 157 - } 158 - 159 - return 0; 164 + return ret; 160 165 } 161 166 162 167 /* Memory for a transfer is being deallocated */ 163 168 static void usbfs_decrease_memory_usage(u64 amount) 164 169 { 165 - atomic64_sub(amount, &usbfs_memory_usage); 170 + unsigned long flags; 171 + 172 + spin_lock_irqsave(&usbfs_memory_usage_lock, flags); 173 + if (amount > usbfs_memory_usage) 174 + usbfs_memory_usage = 0; 175 + else 176 + usbfs_memory_usage -= amount; 177 + spin_unlock_irqrestore(&usbfs_memory_usage_lock, flags); 166 178 } 167 179 168 180 static int connected(struct usb_dev_state *ps)
+1 -1
drivers/usb/core/hcd-pci.c
··· 248 248 hcd->rsrc_len, driver->description)) 249 249 break; 250 250 } 251 - if (region == PCI_ROM_RESOURCE) { 251 + if (region == PCI_STD_NUM_BARS) { 252 252 dev_dbg(&dev->dev, "no i/o regions available\n"); 253 253 retval = -EBUSY; 254 254 goto put_hcd;
+7 -14
drivers/usb/core/hub.c
··· 2983 2983 status); 2984 2984 } 2985 2985 2986 - /* Check for disconnect or reset */ 2987 - if (status == 0 || status == -ENOTCONN || status == -ENODEV) { 2986 + /* 2987 + * Check for disconnect or reset, and bail out after several 2988 + * reset attempts to avoid warm reset loop. 2989 + */ 2990 + if (status == 0 || status == -ENOTCONN || status == -ENODEV || 2991 + (status == -EBUSY && i == PORT_RESET_TRIES - 1)) { 2988 2992 usb_clear_port_feature(hub->hdev, port1, 2989 2993 USB_PORT_FEAT_C_RESET); 2990 2994 ··· 5009 5005 retval = usb_get_bos_descriptor(udev); 5010 5006 if (!retval) { 5011 5007 udev->lpm_capable = usb_device_supports_lpm(udev); 5008 + udev->lpm_disable_count = 1; 5012 5009 usb_set_lpm_parameters(udev); 5013 5010 } 5014 5011 } ··· 5933 5928 */ 5934 5929 usb_disable_usb2_hardware_lpm(udev); 5935 5930 5936 - /* Disable LPM while we reset the device and reinstall the alt settings. 5937 - * Device-initiated LPM, and system exit latency settings are cleared 5938 - * when the device is reset, so we have to set them up again. 5939 - */ 5940 - ret = usb_unlocked_disable_lpm(udev); 5941 - if (ret) { 5942 - dev_err(&udev->dev, "%s Failed to disable LPM\n", __func__); 5943 - goto re_enumerate_no_bos; 5944 - } 5945 - 5946 5931 bos = udev->bos; 5947 5932 udev->bos = NULL; 5948 5933 ··· 6037 6042 re_enumerate: 6038 6043 usb_release_bos_descriptor(udev); 6039 6044 udev->bos = bos; 6040 - re_enumerate_no_bos: 6041 - /* LPM state doesn't matter when we're about to destroy the device. */ 6042 6045 hub_port_logical_disconnect(parent_hub, port1); 6043 6046 return -ENODEV; 6044 6047 }
+1 -1
drivers/usb/core/usb-acpi.c
··· 166 166 if (!parent_handle) 167 167 return NULL; 168 168 169 - acpi_bus_get_device(parent_handle, &adev); 169 + adev = acpi_fetch_acpi_dev(parent_handle); 170 170 port1 = port_dev->portnum; 171 171 } 172 172
+8
drivers/usb/core/usb.c
··· 688 688 * Drivers for USB interfaces should normally record such references in 689 689 * their probe() methods, when they bind to an interface, and release 690 690 * them by calling usb_put_dev(), in their disconnect() methods. 691 + * However, if a driver does not access the usb_device structure after 692 + * its disconnect() method returns then refcounting is not necessary, 693 + * because the USB core guarantees that a usb_device will not be 694 + * deallocated until after all of its interface drivers have been unbound. 691 695 * 692 696 * Return: A pointer to the device with the incremented reference counter. 693 697 */ ··· 726 722 * Drivers for USB interfaces should normally record such references in 727 723 * their probe() methods, when they bind to an interface, and release 728 724 * them by calling usb_put_intf(), in their disconnect() methods. 725 + * However, if a driver does not access the usb_interface structure after 726 + * its disconnect() method returns then refcounting is not necessary, 727 + * because the USB core guarantees that a usb_interface will not be 728 + * deallocated until after its driver has been unbound. 729 729 * 730 730 * Return: A pointer to the interface with the incremented reference counter. 731 731 */
+10
drivers/usb/dwc2/params.c
··· 82 82 p->phy_utmi_width = 8; 83 83 } 84 84 85 + static void dwc2_set_socfpga_agilex_params(struct dwc2_hsotg *hsotg) 86 + { 87 + struct dwc2_core_params *p = &hsotg->params; 88 + 89 + p->power_down = DWC2_POWER_DOWN_PARAM_NONE; 90 + p->no_clock_gating = true; 91 + } 92 + 85 93 static void dwc2_set_rk_params(struct dwc2_hsotg *hsotg) 86 94 { 87 95 struct dwc2_core_params *p = &hsotg->params; ··· 247 239 .data = dwc2_set_stm32mp15_fsotg_params }, 248 240 { .compatible = "st,stm32mp15-hsotg", 249 241 .data = dwc2_set_stm32mp15_hsotg_params }, 242 + { .compatible = "intel,socfpga-agilex-hsotg", 243 + .data = dwc2_set_socfpga_agilex_params }, 250 244 {}, 251 245 }; 252 246 MODULE_DEVICE_TABLE(of, dwc2_of_match_table);
+106 -18
drivers/usb/dwc3/core.c
··· 115 115 dwc->current_dr_role = mode; 116 116 } 117 117 118 - static int dwc3_core_soft_reset(struct dwc3 *dwc); 119 - 120 118 static void __dwc3_set_mode(struct work_struct *work) 121 119 { 122 120 struct dwc3 *dwc = work_to_dwc(work); ··· 259 261 * dwc3_core_soft_reset - Issues core soft reset and PHY reset 260 262 * @dwc: pointer to our context structure 261 263 */ 262 - static int dwc3_core_soft_reset(struct dwc3 *dwc) 264 + int dwc3_core_soft_reset(struct dwc3 *dwc) 263 265 { 264 266 u32 reg; 265 267 int retries = 1000; ··· 345 347 */ 346 348 static void dwc3_ref_clk_period(struct dwc3 *dwc) 347 349 { 350 + unsigned long period; 351 + unsigned long fladj; 352 + unsigned long decr; 353 + unsigned long rate; 348 354 u32 reg; 349 355 350 - if (dwc->ref_clk_per == 0) 356 + if (dwc->ref_clk) { 357 + rate = clk_get_rate(dwc->ref_clk); 358 + if (!rate) 359 + return; 360 + period = NSEC_PER_SEC / rate; 361 + } else if (dwc->ref_clk_per) { 362 + period = dwc->ref_clk_per; 363 + rate = NSEC_PER_SEC / period; 364 + } else { 351 365 return; 366 + } 352 367 353 368 reg = dwc3_readl(dwc->regs, DWC3_GUCTL); 354 369 reg &= ~DWC3_GUCTL_REFCLKPER_MASK; 355 - reg |= FIELD_PREP(DWC3_GUCTL_REFCLKPER_MASK, dwc->ref_clk_per); 370 + reg |= FIELD_PREP(DWC3_GUCTL_REFCLKPER_MASK, period); 356 371 dwc3_writel(dwc->regs, DWC3_GUCTL, reg); 357 - } 358 372 373 + if (DWC3_VER_IS_PRIOR(DWC3, 250A)) 374 + return; 375 + 376 + /* 377 + * The calculation below is 378 + * 379 + * 125000 * (NSEC_PER_SEC / (rate * period) - 1) 380 + * 381 + * but rearranged for fixed-point arithmetic. The division must be 382 + * 64-bit because 125000 * NSEC_PER_SEC doesn't fit in 32 bits (and 383 + * neither does rate * period). 384 + * 385 + * Note that rate * period ~= NSEC_PER_SECOND, minus the number of 386 + * nanoseconds of error caused by the truncation which happened during 387 + * the division when calculating rate or period (whichever one was 388 + * derived from the other). We first calculate the relative error, then 389 + * scale it to units of 8 ppm. 390 + */ 391 + fladj = div64_u64(125000ULL * NSEC_PER_SEC, (u64)rate * period); 392 + fladj -= 125000; 393 + 394 + /* 395 + * The documented 240MHz constant is scaled by 2 to get PLS1 as well. 396 + */ 397 + decr = 480000000 / rate; 398 + 399 + reg = dwc3_readl(dwc->regs, DWC3_GFLADJ); 400 + reg &= ~DWC3_GFLADJ_REFCLK_FLADJ_MASK 401 + & ~DWC3_GFLADJ_240MHZDECR 402 + & ~DWC3_GFLADJ_240MHZDECR_PLS1; 403 + reg |= FIELD_PREP(DWC3_GFLADJ_REFCLK_FLADJ_MASK, fladj) 404 + | FIELD_PREP(DWC3_GFLADJ_240MHZDECR, decr >> 1) 405 + | FIELD_PREP(DWC3_GFLADJ_240MHZDECR_PLS1, decr & 1); 406 + dwc3_writel(dwc->regs, DWC3_GFLADJ, reg); 407 + } 359 408 360 409 /** 361 410 * dwc3_free_one_event_buffer - Frees one event buffer ··· 790 745 return 0; 791 746 } 792 747 748 + static int dwc3_clk_enable(struct dwc3 *dwc) 749 + { 750 + int ret; 751 + 752 + ret = clk_prepare_enable(dwc->bus_clk); 753 + if (ret) 754 + return ret; 755 + 756 + ret = clk_prepare_enable(dwc->ref_clk); 757 + if (ret) 758 + goto disable_bus_clk; 759 + 760 + ret = clk_prepare_enable(dwc->susp_clk); 761 + if (ret) 762 + goto disable_ref_clk; 763 + 764 + return 0; 765 + 766 + disable_ref_clk: 767 + clk_disable_unprepare(dwc->ref_clk); 768 + disable_bus_clk: 769 + clk_disable_unprepare(dwc->bus_clk); 770 + return ret; 771 + } 772 + 773 + static void dwc3_clk_disable(struct dwc3 *dwc) 774 + { 775 + clk_disable_unprepare(dwc->susp_clk); 776 + clk_disable_unprepare(dwc->ref_clk); 777 + clk_disable_unprepare(dwc->bus_clk); 778 + } 779 + 793 780 static void dwc3_core_exit(struct dwc3 *dwc) 794 781 { 795 782 dwc3_event_buffers_cleanup(dwc); ··· 835 758 usb_phy_set_suspend(dwc->usb3_phy, 1); 836 759 phy_power_off(dwc->usb2_generic_phy); 837 760 phy_power_off(dwc->usb3_generic_phy); 838 - clk_bulk_disable_unprepare(dwc->num_clks, dwc->clks); 761 + dwc3_clk_disable(dwc); 839 762 reset_control_assert(dwc->reset); 840 763 } 841 764 ··· 1164 1087 1165 1088 if (dwc->parkmode_disable_ss_quirk) 1166 1089 reg |= DWC3_GUCTL1_PARKMODE_DISABLE_SS; 1090 + 1091 + if (DWC3_VER_IS_WITHIN(DWC3, 290A, ANY) && 1092 + (dwc->maximum_speed == USB_SPEED_HIGH || 1093 + dwc->maximum_speed == USB_SPEED_FULL)) 1094 + reg |= DWC3_GUCTL1_DEV_FORCE_20_CLK_FOR_30_CLK; 1167 1095 1168 1096 dwc3_writel(dwc->regs, DWC3_GUCTL1, reg); 1169 1097 } ··· 1687 1605 return PTR_ERR(dwc->reset); 1688 1606 1689 1607 if (dev->of_node) { 1690 - ret = devm_clk_bulk_get_all(dev, &dwc->clks); 1691 - if (ret == -EPROBE_DEFER) 1692 - return ret; 1693 1608 /* 1694 1609 * Clocks are optional, but new DT platforms should support all 1695 1610 * clocks as required by the DT-binding. 1696 1611 */ 1697 - if (ret < 0) 1698 - dwc->num_clks = 0; 1699 - else 1700 - dwc->num_clks = ret; 1612 + dwc->bus_clk = devm_clk_get_optional(dev, "bus_early"); 1613 + if (IS_ERR(dwc->bus_clk)) 1614 + return dev_err_probe(dev, PTR_ERR(dwc->bus_clk), 1615 + "could not get bus clock\n"); 1701 1616 1617 + dwc->ref_clk = devm_clk_get_optional(dev, "ref"); 1618 + if (IS_ERR(dwc->ref_clk)) 1619 + return dev_err_probe(dev, PTR_ERR(dwc->ref_clk), 1620 + "could not get ref clock\n"); 1621 + 1622 + dwc->susp_clk = devm_clk_get_optional(dev, "suspend"); 1623 + if (IS_ERR(dwc->susp_clk)) 1624 + return dev_err_probe(dev, PTR_ERR(dwc->susp_clk), 1625 + "could not get suspend clock\n"); 1702 1626 } 1703 1627 1704 1628 ret = reset_control_deassert(dwc->reset); 1705 1629 if (ret) 1706 1630 return ret; 1707 1631 1708 - ret = clk_bulk_prepare_enable(dwc->num_clks, dwc->clks); 1632 + ret = dwc3_clk_enable(dwc); 1709 1633 if (ret) 1710 1634 goto assert_reset; 1711 1635 ··· 1799 1711 pm_runtime_disable(&pdev->dev); 1800 1712 1801 1713 disable_clks: 1802 - clk_bulk_disable_unprepare(dwc->num_clks, dwc->clks); 1714 + dwc3_clk_disable(dwc); 1803 1715 assert_reset: 1804 1716 reset_control_assert(dwc->reset); 1805 1717 ··· 1843 1755 if (ret) 1844 1756 return ret; 1845 1757 1846 - ret = clk_bulk_prepare_enable(dwc->num_clks, dwc->clks); 1758 + ret = dwc3_clk_enable(dwc); 1847 1759 if (ret) 1848 1760 goto assert_reset; 1849 1761 ··· 1854 1766 return 0; 1855 1767 1856 1768 disable_clks: 1857 - clk_bulk_disable_unprepare(dwc->num_clks, dwc->clks); 1769 + dwc3_clk_disable(dwc); 1858 1770 assert_reset: 1859 1771 reset_control_assert(dwc->reset); 1860 1772
+13 -4
drivers/usb/dwc3/core.h
··· 259 259 /* Global User Control 1 Register */ 260 260 #define DWC3_GUCTL1_DEV_DECOUPLE_L1L2_EVT BIT(31) 261 261 #define DWC3_GUCTL1_TX_IPGAP_LINECHECK_DIS BIT(28) 262 + #define DWC3_GUCTL1_DEV_FORCE_20_CLK_FOR_30_CLK BIT(26) 262 263 #define DWC3_GUCTL1_DEV_L1_EXIT_BY_HW BIT(24) 263 264 #define DWC3_GUCTL1_PARKMODE_DISABLE_SS BIT(17) 264 265 ··· 389 388 /* Global Frame Length Adjustment Register */ 390 389 #define DWC3_GFLADJ_30MHZ_SDBND_SEL BIT(7) 391 390 #define DWC3_GFLADJ_30MHZ_MASK 0x3f 391 + #define DWC3_GFLADJ_REFCLK_FLADJ_MASK GENMASK(21, 8) 392 + #define DWC3_GFLADJ_240MHZDECR GENMASK(30, 24) 393 + #define DWC3_GFLADJ_240MHZDECR_PLS1 BIT(31) 392 394 393 395 /* Global User Control Register*/ 394 396 #define DWC3_GUCTL_REFCLKPER_MASK 0xffc00000 ··· 737 733 #define DWC3_EP_FIRST_STREAM_PRIMED BIT(10) 738 734 #define DWC3_EP_PENDING_CLEAR_STALL BIT(11) 739 735 #define DWC3_EP_TXFIFO_RESIZED BIT(12) 736 + #define DWC3_EP_DELAY_STOP BIT(13) 740 737 741 738 /* This last one is specific to EP0 */ 742 739 #define DWC3_EP0_DIR_IN BIT(31) ··· 983 978 * @eps: endpoint array 984 979 * @gadget: device side representation of the peripheral controller 985 980 * @gadget_driver: pointer to the gadget driver 986 - * @clks: array of clocks 987 - * @num_clks: number of clocks 981 + * @bus_clk: clock for accessing the registers 982 + * @ref_clk: reference clock 983 + * @susp_clk: clock used when the SS phy is in low power (S3) state 988 984 * @reset: reset control 989 985 * @regs: base address for our registers 990 986 * @regs_size: address space size ··· 1140 1134 struct usb_gadget *gadget; 1141 1135 struct usb_gadget_driver *gadget_driver; 1142 1136 1143 - struct clk_bulk_data *clks; 1144 - int num_clks; 1137 + struct clk *bus_clk; 1138 + struct clk *ref_clk; 1139 + struct clk *susp_clk; 1145 1140 1146 1141 struct reset_control *reset; 1147 1142 ··· 1531 1524 1532 1525 int dwc3_event_buffers_setup(struct dwc3 *dwc); 1533 1526 void dwc3_event_buffers_cleanup(struct dwc3 *dwc); 1527 + 1528 + int dwc3_core_soft_reset(struct dwc3 *dwc); 1534 1529 1535 1530 #if IS_ENABLED(CONFIG_USB_DWC3_HOST) || IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE) 1536 1531 int dwc3_host_init(struct dwc3 *dwc);
+13
drivers/usb/dwc3/drd.c
··· 9 9 10 10 #include <linux/extcon.h> 11 11 #include <linux/of_graph.h> 12 + #include <linux/of_platform.h> 12 13 #include <linux/platform_device.h> 13 14 #include <linux/property.h> 14 15 ··· 559 558 dwc->role_sw = usb_role_switch_register(dwc->dev, &dwc3_role_switch); 560 559 if (IS_ERR(dwc->role_sw)) 561 560 return PTR_ERR(dwc->role_sw); 561 + 562 + if (dwc->dev->of_node) { 563 + /* populate connector entry */ 564 + int ret = devm_of_platform_populate(dwc->dev); 565 + 566 + if (ret) { 567 + usb_role_switch_unregister(dwc->role_sw); 568 + dwc->role_sw = NULL; 569 + dev_err(dwc->dev, "DWC3 platform devices creation failed: %i\n", ret); 570 + return ret; 571 + } 572 + } 562 573 563 574 dwc3_set_mode(dwc, mode); 564 575 return 0;
+70 -7
drivers/usb/dwc3/dwc3-imx8mp.c
··· 36 36 37 37 #define USB_WAKEUP_EN_MASK GENMASK(5, 0) 38 38 39 + /* USB glue registers */ 40 + #define USB_CTRL0 0x00 41 + #define USB_CTRL1 0x04 42 + 43 + #define USB_CTRL0_PORTPWR_EN BIT(12) /* 1 - PPC enabled (default) */ 44 + #define USB_CTRL0_USB3_FIXED BIT(22) /* 1 - USB3 permanent attached */ 45 + #define USB_CTRL0_USB2_FIXED BIT(23) /* 1 - USB2 permanent attached */ 46 + 47 + #define USB_CTRL1_OC_POLARITY BIT(16) /* 0 - HIGH / 1 - LOW */ 48 + #define USB_CTRL1_PWR_POLARITY BIT(17) /* 0 - HIGH / 1 - LOW */ 49 + 39 50 struct dwc3_imx8mp { 40 51 struct device *dev; 41 52 struct platform_device *dwc3; 53 + void __iomem *hsio_blk_base; 42 54 void __iomem *glue_base; 43 55 struct clk *hsio_clk; 44 56 struct clk *suspend_clk; ··· 58 46 bool pm_suspended; 59 47 bool wakeup_pending; 60 48 }; 49 + 50 + static void imx8mp_configure_glue(struct dwc3_imx8mp *dwc3_imx) 51 + { 52 + struct device *dev = dwc3_imx->dev; 53 + u32 value; 54 + 55 + if (!dwc3_imx->glue_base) 56 + return; 57 + 58 + value = readl(dwc3_imx->glue_base + USB_CTRL0); 59 + 60 + if (device_property_read_bool(dev, "fsl,permanently-attached")) 61 + value |= (USB_CTRL0_USB2_FIXED | USB_CTRL0_USB3_FIXED); 62 + else 63 + value &= ~(USB_CTRL0_USB2_FIXED | USB_CTRL0_USB3_FIXED); 64 + 65 + if (device_property_read_bool(dev, "fsl,disable-port-power-control")) 66 + value &= ~(USB_CTRL0_PORTPWR_EN); 67 + else 68 + value |= USB_CTRL0_PORTPWR_EN; 69 + 70 + writel(value, dwc3_imx->glue_base + USB_CTRL0); 71 + 72 + value = readl(dwc3_imx->glue_base + USB_CTRL1); 73 + if (device_property_read_bool(dev, "fsl,over-current-active-low")) 74 + value |= USB_CTRL1_OC_POLARITY; 75 + else 76 + value &= ~USB_CTRL1_OC_POLARITY; 77 + 78 + if (device_property_read_bool(dev, "fsl,power-active-low")) 79 + value |= USB_CTRL1_PWR_POLARITY; 80 + else 81 + value &= ~USB_CTRL1_PWR_POLARITY; 82 + 83 + writel(value, dwc3_imx->glue_base + USB_CTRL1); 84 + } 61 85 62 86 static void dwc3_imx8mp_wakeup_enable(struct dwc3_imx8mp *dwc3_imx) 63 87 { ··· 103 55 if (!dwc3) 104 56 return; 105 57 106 - val = readl(dwc3_imx->glue_base + USB_WAKEUP_CTRL); 58 + val = readl(dwc3_imx->hsio_blk_base + USB_WAKEUP_CTRL); 107 59 108 60 if ((dwc3->current_dr_role == DWC3_GCTL_PRTCAP_HOST) && dwc3->xhci) 109 61 val |= USB_WAKEUP_EN | USB_WAKEUP_SS_CONN | ··· 112 64 val |= USB_WAKEUP_EN | USB_WAKEUP_VBUS_EN | 113 65 USB_WAKEUP_VBUS_SRC_SESS_VAL; 114 66 115 - writel(val, dwc3_imx->glue_base + USB_WAKEUP_CTRL); 67 + writel(val, dwc3_imx->hsio_blk_base + USB_WAKEUP_CTRL); 116 68 } 117 69 118 70 static void dwc3_imx8mp_wakeup_disable(struct dwc3_imx8mp *dwc3_imx) 119 71 { 120 72 u32 val; 121 73 122 - val = readl(dwc3_imx->glue_base + USB_WAKEUP_CTRL); 74 + val = readl(dwc3_imx->hsio_blk_base + USB_WAKEUP_CTRL); 123 75 val &= ~(USB_WAKEUP_EN | USB_WAKEUP_EN_MASK); 124 - writel(val, dwc3_imx->glue_base + USB_WAKEUP_CTRL); 76 + writel(val, dwc3_imx->hsio_blk_base + USB_WAKEUP_CTRL); 125 77 } 126 78 127 79 static irqreturn_t dwc3_imx8mp_interrupt(int irq, void *_dwc3_imx) ··· 148 100 struct device *dev = &pdev->dev; 149 101 struct device_node *dwc3_np, *node = dev->of_node; 150 102 struct dwc3_imx8mp *dwc3_imx; 103 + struct resource *res; 151 104 int err, irq; 152 105 153 106 if (!node) { ··· 164 115 165 116 dwc3_imx->dev = dev; 166 117 167 - dwc3_imx->glue_base = devm_platform_ioremap_resource(pdev, 0); 168 - if (IS_ERR(dwc3_imx->glue_base)) 169 - return PTR_ERR(dwc3_imx->glue_base); 118 + dwc3_imx->hsio_blk_base = devm_platform_ioremap_resource(pdev, 0); 119 + if (IS_ERR(dwc3_imx->hsio_blk_base)) 120 + return PTR_ERR(dwc3_imx->hsio_blk_base); 121 + 122 + res = platform_get_resource(pdev, IORESOURCE_MEM, 1); 123 + if (!res) { 124 + dev_warn(dev, "Base address for glue layer missing. Continuing without, some features are missing though."); 125 + } else { 126 + dwc3_imx->glue_base = devm_ioremap_resource(dev, res); 127 + if (IS_ERR(dwc3_imx->glue_base)) 128 + return PTR_ERR(dwc3_imx->glue_base); 129 + } 170 130 171 131 dwc3_imx->hsio_clk = devm_clk_get(dev, "hsio"); 172 132 if (IS_ERR(dwc3_imx->hsio_clk)) { ··· 209 151 goto disable_clks; 210 152 } 211 153 dwc3_imx->irq = irq; 154 + 155 + imx8mp_configure_glue(dwc3_imx); 212 156 213 157 pm_runtime_set_active(dev); 214 158 pm_runtime_enable(dev); ··· 311 251 /* Wakeup disable */ 312 252 dwc3_imx8mp_wakeup_disable(dwc3_imx); 313 253 dwc3_imx->pm_suspended = false; 254 + 255 + /* Upon power loss any previous configuration is lost, restore it */ 256 + imx8mp_configure_glue(dwc3_imx); 314 257 315 258 if (dwc3_imx->wakeup_pending) { 316 259 dwc3_imx->wakeup_pending = false;
+5 -5
drivers/usb/dwc3/dwc3-meson-g12a.c
··· 188 188 * reset to recover usage of the port. 189 189 */ 190 190 191 - static struct dwc3_meson_g12a_drvdata gxl_drvdata = { 191 + static const struct dwc3_meson_g12a_drvdata gxl_drvdata = { 192 192 .otg_switch_supported = true, 193 193 .otg_phy_host_port_disable = true, 194 194 .clks = meson_gxl_clocks, ··· 202 202 .usb_post_init = dwc3_meson_gxl_usb_post_init, 203 203 }; 204 204 205 - static struct dwc3_meson_g12a_drvdata gxm_drvdata = { 205 + static const struct dwc3_meson_g12a_drvdata gxm_drvdata = { 206 206 .otg_switch_supported = true, 207 207 .otg_phy_host_port_disable = true, 208 208 .clks = meson_gxl_clocks, ··· 216 216 .usb_post_init = dwc3_meson_gxl_usb_post_init, 217 217 }; 218 218 219 - static struct dwc3_meson_g12a_drvdata axg_drvdata = { 219 + static const struct dwc3_meson_g12a_drvdata axg_drvdata = { 220 220 .otg_switch_supported = true, 221 221 .clks = meson_gxl_clocks, 222 222 .num_clks = ARRAY_SIZE(meson_gxl_clocks), ··· 229 229 .usb_post_init = dwc3_meson_gxl_usb_post_init, 230 230 }; 231 231 232 - static struct dwc3_meson_g12a_drvdata g12a_drvdata = { 232 + static const struct dwc3_meson_g12a_drvdata g12a_drvdata = { 233 233 .otg_switch_supported = true, 234 234 .clks = meson_g12a_clocks, 235 235 .num_clks = ARRAY_SIZE(meson_g12a_clocks), ··· 241 241 .usb_init = dwc3_meson_g12a_usb_init, 242 242 }; 243 243 244 - static struct dwc3_meson_g12a_drvdata a1_drvdata = { 244 + static const struct dwc3_meson_g12a_drvdata a1_drvdata = { 245 245 .otg_switch_supported = false, 246 246 .clks = meson_a1_clocks, 247 247 .num_clks = ARRAY_SIZE(meson_a1_clocks),
+1 -1
drivers/usb/dwc3/dwc3-omap.c
··· 242 242 break; 243 243 244 244 case OMAP_DWC3_ID_FLOAT: 245 - if (omap->vbus_reg) 245 + if (omap->vbus_reg && regulator_is_enabled(omap->vbus_reg)) 246 246 regulator_disable(omap->vbus_reg); 247 247 val = dwc3_omap_read_utmi_ctrl(omap); 248 248 val |= USBOTGSS_UTMI_OTG_CTRL_IDDIG;
+39 -7
drivers/usb/dwc3/dwc3-pci.c
··· 40 40 #define PCI_DEVICE_ID_INTEL_TGPLP 0xa0ee 41 41 #define PCI_DEVICE_ID_INTEL_TGPH 0x43ee 42 42 #define PCI_DEVICE_ID_INTEL_JSP 0x4dee 43 + #define PCI_DEVICE_ID_INTEL_ADL 0x465e 43 44 #define PCI_DEVICE_ID_INTEL_ADLP 0x51ee 44 45 #define PCI_DEVICE_ID_INTEL_ADLM 0x54ee 45 46 #define PCI_DEVICE_ID_INTEL_ADLS 0x7ae1 ··· 121 120 {} 122 121 }; 123 122 123 + static const struct property_entry dwc3_pci_intel_phy_charger_detect_properties[] = { 124 + PROPERTY_ENTRY_STRING("dr_mode", "peripheral"), 125 + PROPERTY_ENTRY_BOOL("snps,dis_u2_susphy_quirk"), 126 + PROPERTY_ENTRY_BOOL("linux,phy_charger_detect"), 127 + {} 128 + }; 129 + 124 130 static const struct property_entry dwc3_pci_intel_byt_properties[] = { 125 131 PROPERTY_ENTRY_STRING("dr_mode", "peripheral"), 126 132 PROPERTY_ENTRY_BOOL("snps,dis_u2_susphy_quirk"), ··· 177 169 .properties = dwc3_pci_intel_properties, 178 170 }; 179 171 172 + static const struct software_node dwc3_pci_intel_phy_charger_detect_swnode = { 173 + .properties = dwc3_pci_intel_phy_charger_detect_properties, 174 + }; 175 + 180 176 static const struct software_node dwc3_pci_intel_byt_swnode = { 181 177 .properties = dwc3_pci_intel_byt_properties, 182 178 }; ··· 197 185 .properties = dwc3_pci_mr_properties, 198 186 }; 199 187 200 - static int dwc3_pci_quirks(struct dwc3_pci *dwc) 188 + static int dwc3_pci_quirks(struct dwc3_pci *dwc, 189 + const struct software_node *swnode) 201 190 { 202 191 struct pci_dev *pdev = dwc->pci; 203 192 ··· 252 239 gpiod_put(gpio); 253 240 usleep_range(10000, 11000); 254 241 } 242 + 243 + /* 244 + * Make the pdev name predictable (only 1 DWC3 on BYT) 245 + * and patch the phy dev-name into the lookup table so 246 + * that the phy-driver can get the GPIOs. 247 + */ 248 + dwc->dwc3->id = PLATFORM_DEVID_NONE; 249 + platform_bytcr_gpios.dev_id = "dwc3.ulpi"; 250 + 251 + /* 252 + * Some Android tablets with a Crystal Cove PMIC 253 + * (INT33FD), rely on the TUSB1211 phy for charger 254 + * detection. These can be identified by them _not_ 255 + * using the standard ACPI battery and ac drivers. 256 + */ 257 + if (acpi_dev_present("INT33FD", "1", 2) && 258 + acpi_quirk_skip_acpi_ac_and_battery()) { 259 + dev_info(&pdev->dev, "Using TUSB1211 phy for charger detection\n"); 260 + swnode = &dwc3_pci_intel_phy_charger_detect_swnode; 261 + } 255 262 } 256 263 } 257 264 258 - return 0; 265 + return device_add_software_node(&dwc->dwc3->dev, swnode); 259 266 } 260 267 261 268 #ifdef CONFIG_PM ··· 340 307 dwc->dwc3->dev.parent = dev; 341 308 ACPI_COMPANION_SET(&dwc->dwc3->dev, ACPI_COMPANION(dev)); 342 309 343 - ret = device_add_software_node(&dwc->dwc3->dev, (void *)id->driver_data); 344 - if (ret < 0) 345 - goto err; 346 - 347 - ret = dwc3_pci_quirks(dwc); 310 + ret = dwc3_pci_quirks(dwc, (void *)id->driver_data); 348 311 if (ret) 349 312 goto err; 350 313 ··· 439 410 (kernel_ulong_t) &dwc3_pci_intel_swnode, }, 440 411 441 412 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_JSP), 413 + (kernel_ulong_t) &dwc3_pci_intel_swnode, }, 414 + 415 + { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_ADL), 442 416 (kernel_ulong_t) &dwc3_pci_intel_swnode, }, 443 417 444 418 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_ADLP),
+14
drivers/usb/dwc3/ep0.c
··· 271 271 { 272 272 struct dwc3_ep *dep; 273 273 int ret; 274 + int i; 274 275 275 276 complete(&dwc->ep0_in_setup); 276 277 ··· 280 279 DWC3_TRBCTL_CONTROL_SETUP, false); 281 280 ret = dwc3_ep0_start_trans(dep); 282 281 WARN_ON(ret < 0); 282 + for (i = 2; i < DWC3_ENDPOINTS_NUM; i++) { 283 + struct dwc3_ep *dwc3_ep; 284 + 285 + dwc3_ep = dwc->eps[i]; 286 + if (!dwc3_ep) 287 + continue; 288 + 289 + if (!(dwc3_ep->flags & DWC3_EP_DELAY_STOP)) 290 + continue; 291 + 292 + dwc3_ep->flags &= ~DWC3_EP_DELAY_STOP; 293 + dwc3_stop_active_transfer(dwc3_ep, true, true); 294 + } 283 295 } 284 296 285 297 static struct dwc3_ep *dwc3_wIndex_to_dep(struct dwc3 *dwc, __le16 wIndex_le)
+74 -44
drivers/usb/dwc3/gadget.c
··· 654 654 return dwc3_send_gadget_ep_cmd(dep, DWC3_DEPCMD_SETEPCONFIG, &params); 655 655 } 656 656 657 - static void dwc3_stop_active_transfer(struct dwc3_ep *dep, bool force, 658 - bool interrupt); 659 - 660 657 /** 661 658 * dwc3_gadget_calc_tx_fifo_size - calculates the txfifo size value 662 659 * @dwc: pointer to the DWC3 context ··· 1671 1674 } 1672 1675 1673 1676 /** 1677 + * __dwc3_stop_active_transfer - stop the current active transfer 1678 + * @dep: isoc endpoint 1679 + * @force: set forcerm bit in the command 1680 + * @interrupt: command complete interrupt after End Transfer command 1681 + * 1682 + * When setting force, the ForceRM bit will be set. In that case 1683 + * the controller won't update the TRB progress on command 1684 + * completion. It also won't clear the HWO bit in the TRB. 1685 + * The command will also not complete immediately in that case. 1686 + */ 1687 + static int __dwc3_stop_active_transfer(struct dwc3_ep *dep, bool force, bool interrupt) 1688 + { 1689 + struct dwc3_gadget_ep_cmd_params params; 1690 + u32 cmd; 1691 + int ret; 1692 + 1693 + cmd = DWC3_DEPCMD_ENDTRANSFER; 1694 + cmd |= force ? DWC3_DEPCMD_HIPRI_FORCERM : 0; 1695 + cmd |= interrupt ? DWC3_DEPCMD_CMDIOC : 0; 1696 + cmd |= DWC3_DEPCMD_PARAM(dep->resource_index); 1697 + memset(&params, 0, sizeof(params)); 1698 + ret = dwc3_send_gadget_ep_cmd(dep, cmd, &params); 1699 + WARN_ON_ONCE(ret); 1700 + dep->resource_index = 0; 1701 + 1702 + if (!interrupt) 1703 + dep->flags &= ~DWC3_EP_TRANSFER_STARTED; 1704 + else if (!ret) 1705 + dep->flags |= DWC3_EP_END_TRANSFER_PENDING; 1706 + 1707 + return ret; 1708 + } 1709 + 1710 + /** 1674 1711 * dwc3_gadget_start_isoc_quirk - workaround invalid frame number 1675 1712 * @dep: isoc endpoint 1676 1713 * ··· 1861 1830 } 1862 1831 1863 1832 for (i = 0; i < DWC3_ISOC_MAX_RETRIES; i++) { 1864 - dep->frame_number = DWC3_ALIGN_FRAME(dep, i + 1); 1833 + int future_interval = i + 1; 1834 + 1835 + /* Give the controller at least 500us to schedule transfers */ 1836 + if (desc->bInterval < 3) 1837 + future_interval += 3 - desc->bInterval; 1838 + 1839 + dep->frame_number = DWC3_ALIGN_FRAME(dep, future_interval); 1865 1840 1866 1841 ret = __dwc3_gadget_kick_transfer(dep); 1867 1842 if (ret != -EAGAIN) ··· 1879 1842 * status, issue END_TRANSFER command and retry on the next XferNotReady 1880 1843 * event. 1881 1844 */ 1882 - if (ret == -EAGAIN) { 1883 - struct dwc3_gadget_ep_cmd_params params; 1884 - u32 cmd; 1885 - 1886 - cmd = DWC3_DEPCMD_ENDTRANSFER | 1887 - DWC3_DEPCMD_CMDIOC | 1888 - DWC3_DEPCMD_PARAM(dep->resource_index); 1889 - 1890 - dep->resource_index = 0; 1891 - memset(&params, 0, sizeof(params)); 1892 - 1893 - ret = dwc3_send_gadget_ep_cmd(dep, cmd, &params); 1894 - if (!ret) 1895 - dep->flags |= DWC3_EP_END_TRANSFER_PENDING; 1896 - } 1845 + if (ret == -EAGAIN) 1846 + ret = __dwc3_stop_active_transfer(dep, false, true); 1897 1847 1898 1848 return ret; 1899 1849 } ··· 1923 1899 */ 1924 1900 if ((dep->flags & DWC3_EP_END_TRANSFER_PENDING) || 1925 1901 (dep->flags & DWC3_EP_WEDGE) || 1902 + (dep->flags & DWC3_EP_DELAY_STOP) || 1926 1903 (dep->flags & DWC3_EP_STALL)) { 1927 1904 dep->flags |= DWC3_EP_DELAY_START; 1928 1905 return 0; ··· 1938 1913 * errors which will force us issue EndTransfer command. 1939 1914 */ 1940 1915 if (usb_endpoint_xfer_isoc(dep->endpoint.desc)) { 1941 - if (!(dep->flags & DWC3_EP_PENDING_REQUEST) && 1942 - !(dep->flags & DWC3_EP_TRANSFER_STARTED)) 1943 - return 0; 1944 - 1945 - if ((dep->flags & DWC3_EP_PENDING_REQUEST)) { 1946 - if (!(dep->flags & DWC3_EP_TRANSFER_STARTED)) 1916 + if (!(dep->flags & DWC3_EP_TRANSFER_STARTED)) { 1917 + if ((dep->flags & DWC3_EP_PENDING_REQUEST)) 1947 1918 return __dwc3_gadget_start_isoc(dep); 1919 + 1920 + return 0; 1948 1921 } 1949 1922 } 1950 1923 ··· 2056 2033 if (r == req) { 2057 2034 struct dwc3_request *t; 2058 2035 2036 + /* 2037 + * If a Setup packet is received but yet to DMA out, the controller will 2038 + * not process the End Transfer command of any endpoint. Polling of its 2039 + * DEPCMD.CmdAct may block setting up TRB for Setup packet, causing a 2040 + * timeout. Delay issuing the End Transfer command until the Setup TRB is 2041 + * prepared. 2042 + */ 2043 + if (dwc->ep0state != EP0_SETUP_PHASE && !dwc->delayed_status) 2044 + dep->flags |= DWC3_EP_DELAY_STOP; 2045 + 2059 2046 /* wait until it is processed */ 2060 2047 dwc3_stop_active_transfer(dep, true, true); 2061 2048 ··· 2149 2116 list_for_each_entry_safe(req, tmp, &dep->started_list, list) 2150 2117 dwc3_gadget_move_cancelled_request(req, DWC3_REQUEST_STATUS_STALLED); 2151 2118 2152 - if (dep->flags & DWC3_EP_END_TRANSFER_PENDING) { 2119 + if (dep->flags & DWC3_EP_END_TRANSFER_PENDING || 2120 + (dep->flags & DWC3_EP_DELAY_STOP)) { 2153 2121 dep->flags |= DWC3_EP_PENDING_CLEAR_STALL; 2154 2122 return 0; 2155 2123 } ··· 2578 2544 dwc->ev_buf->length; 2579 2545 } 2580 2546 } else { 2547 + /* 2548 + * In the Synopsys DWC_usb31 1.90a programming guide section 2549 + * 4.1.9, it specifies that for a reconnect after a 2550 + * device-initiated disconnect requires a core soft reset 2551 + * (DCTL.CSftRst) before enabling the run/stop bit. 2552 + */ 2553 + spin_unlock_irqrestore(&dwc->lock, flags); 2554 + dwc3_core_soft_reset(dwc); 2555 + spin_lock_irqsave(&dwc->lock, flags); 2556 + 2557 + dwc3_event_buffers_setup(dwc); 2581 2558 __dwc3_gadget_start(dwc); 2582 2559 } 2583 2560 ··· 3641 3596 } 3642 3597 } 3643 3598 3644 - static void dwc3_stop_active_transfer(struct dwc3_ep *dep, bool force, 3599 + void dwc3_stop_active_transfer(struct dwc3_ep *dep, bool force, 3645 3600 bool interrupt) 3646 3601 { 3647 - struct dwc3_gadget_ep_cmd_params params; 3648 - u32 cmd; 3649 - int ret; 3650 - 3651 3602 if (!(dep->flags & DWC3_EP_TRANSFER_STARTED) || 3603 + (dep->flags & DWC3_EP_DELAY_STOP) || 3652 3604 (dep->flags & DWC3_EP_END_TRANSFER_PENDING)) 3653 3605 return; 3654 3606 ··· 3676 3634 * This mode is NOT available on the DWC_usb31 IP. 3677 3635 */ 3678 3636 3679 - cmd = DWC3_DEPCMD_ENDTRANSFER; 3680 - cmd |= force ? DWC3_DEPCMD_HIPRI_FORCERM : 0; 3681 - cmd |= interrupt ? DWC3_DEPCMD_CMDIOC : 0; 3682 - cmd |= DWC3_DEPCMD_PARAM(dep->resource_index); 3683 - memset(&params, 0, sizeof(params)); 3684 - ret = dwc3_send_gadget_ep_cmd(dep, cmd, &params); 3685 - WARN_ON_ONCE(ret); 3686 - dep->resource_index = 0; 3687 - 3688 - if (!interrupt) 3689 - dep->flags &= ~DWC3_EP_TRANSFER_STARTED; 3690 - else 3691 - dep->flags |= DWC3_EP_END_TRANSFER_PENDING; 3637 + __dwc3_stop_active_transfer(dep, force, interrupt); 3692 3638 } 3693 3639 3694 3640 static void dwc3_clear_stall_all_ep(struct dwc3 *dwc)
+1
drivers/usb/dwc3/gadget.h
··· 116 116 gfp_t gfp_flags); 117 117 int __dwc3_gadget_ep_set_halt(struct dwc3_ep *dep, int value, int protocol); 118 118 void dwc3_ep0_send_delayed_status(struct dwc3 *dwc); 119 + void dwc3_stop_active_transfer(struct dwc3_ep *dep, bool force, bool interrupt); 119 120 120 121 /** 121 122 * dwc3_gadget_ep_get_transfer_index - Gets transfer index from HW
+8 -5
drivers/usb/early/xhci-dbc.c
··· 599 599 return 0; 600 600 } 601 601 602 - int __init early_xdbc_parse_parameter(char *s) 602 + int __init early_xdbc_parse_parameter(char *s, int keep_early) 603 603 { 604 604 unsigned long dbgp_num = 0; 605 605 u32 bus, dev, func, offset; 606 + char *e; 606 607 int ret; 607 608 608 609 if (!early_pci_allowed()) 609 610 return -EPERM; 610 611 611 - if (strstr(s, "keep")) 612 - early_console_keep = true; 612 + early_console_keep = keep_early; 613 613 614 614 if (xdbc.xdbc_reg) 615 615 return 0; 616 616 617 - if (*s && kstrtoul(s, 0, &dbgp_num)) 618 - dbgp_num = 0; 617 + if (*s) { 618 + dbgp_num = simple_strtoul(s, &e, 10); 619 + if (s == e) 620 + dbgp_num = 0; 621 + } 619 622 620 623 pr_notice("dbgp_num: %lu\n", dbgp_num); 621 624
-1
drivers/usb/gadget/Makefile
··· 4 4 # 5 5 subdir-ccflags-$(CONFIG_USB_GADGET_DEBUG) := -DDEBUG 6 6 subdir-ccflags-$(CONFIG_USB_GADGET_VERBOSE) += -DVERBOSE_DEBUG 7 - ccflags-y += -I$(srctree)/drivers/usb/gadget/udc 8 7 9 8 obj-$(CONFIG_USB_LIBCOMPOSITE) += libcomposite.o 10 9 libcomposite-y := usbstring.o config.o epautoconf.o
+19 -17
drivers/usb/gadget/composite.c
··· 863 863 const struct usb_ctrlrequest *ctrl, unsigned number) 864 864 { 865 865 struct usb_gadget *gadget = cdev->gadget; 866 - struct usb_configuration *c = NULL; 866 + struct usb_configuration *c = NULL, *iter; 867 867 int result = -EINVAL; 868 868 unsigned power = gadget_is_otg(gadget) ? 8 : 100; 869 869 int tmp; 870 870 871 871 if (number) { 872 - list_for_each_entry(c, &cdev->configs, list) { 873 - if (c->bConfigurationValue == number) { 874 - /* 875 - * We disable the FDs of the previous 876 - * configuration only if the new configuration 877 - * is a valid one 878 - */ 879 - if (cdev->config) 880 - reset_config(cdev); 881 - result = 0; 882 - break; 883 - } 872 + list_for_each_entry(iter, &cdev->configs, list) { 873 + if (iter->bConfigurationValue != number) 874 + continue; 875 + /* 876 + * We disable the FDs of the previous 877 + * configuration only if the new configuration 878 + * is a valid one 879 + */ 880 + if (cdev->config) 881 + reset_config(cdev); 882 + c = iter; 883 + result = 0; 884 + break; 884 885 } 885 886 if (result < 0) 886 887 goto done; ··· 1691 1690 u16 w_value = le16_to_cpu(ctrl->wValue); 1692 1691 u16 w_length = le16_to_cpu(ctrl->wLength); 1693 1692 struct usb_function *f = NULL; 1693 + struct usb_function *iter; 1694 1694 u8 endp; 1695 1695 1696 1696 if (w_length > USB_COMP_EP0_BUFSIZ) { ··· 2048 2046 if (!cdev->config) 2049 2047 break; 2050 2048 endp = ((w_index & 0x80) >> 3) | (w_index & 0x0f); 2051 - list_for_each_entry(f, &cdev->config->functions, list) { 2052 - if (test_bit(endp, f->endpoints)) 2049 + list_for_each_entry(iter, &cdev->config->functions, list) { 2050 + if (test_bit(endp, iter->endpoints)) { 2051 + f = iter; 2053 2052 break; 2053 + } 2054 2054 } 2055 - if (&f->list == &cdev->config->functions) 2056 - f = NULL; 2057 2055 break; 2058 2056 } 2059 2057 try_fun_setup:
+14 -10
drivers/usb/gadget/configfs.c
··· 418 418 419 419 struct usb_function_instance *fi = 420 420 to_usb_function_instance(usb_func_ci); 421 - struct usb_function_instance *a_fi; 421 + struct usb_function_instance *a_fi = NULL, *iter; 422 422 struct usb_function *f; 423 423 int ret; 424 424 ··· 428 428 * from another gadget or a random directory. 429 429 * Also a function instance can only be linked once. 430 430 */ 431 - list_for_each_entry(a_fi, &gi->available_func, cfs_list) { 432 - if (a_fi == fi) 433 - break; 431 + list_for_each_entry(iter, &gi->available_func, cfs_list) { 432 + if (iter != fi) 433 + continue; 434 + a_fi = iter; 435 + break; 434 436 } 435 - if (a_fi != fi) { 437 + if (!a_fi) { 436 438 ret = -EINVAL; 437 439 goto out; 438 440 } ··· 884 882 struct gadget_info *gi = os_desc_item_to_gadget_info(os_desc_ci); 885 883 struct usb_composite_dev *cdev = &gi->cdev; 886 884 struct config_usb_cfg *c_target = to_config_usb_cfg(usb_cfg_ci); 887 - struct usb_configuration *c; 885 + struct usb_configuration *c = NULL, *iter; 888 886 int ret; 889 887 890 888 mutex_lock(&gi->lock); 891 - list_for_each_entry(c, &cdev->configs, list) { 892 - if (c == &c_target->c) 893 - break; 889 + list_for_each_entry(iter, &cdev->configs, list) { 890 + if (iter != &c_target->c) 891 + continue; 892 + c = iter; 893 + break; 894 894 } 895 - if (c != &c_target->c) { 895 + if (!c) { 896 896 ret = -EINVAL; 897 897 goto out; 898 898 }
+2 -2
drivers/usb/gadget/function/f_fs.c
··· 919 919 data_len, ret); 920 920 921 921 data_len -= ret; 922 - buf = kmalloc(sizeof(*buf) + data_len, GFP_KERNEL); 922 + buf = kmalloc(struct_size(buf, storage, data_len), GFP_KERNEL); 923 923 if (!buf) 924 924 return -ENOMEM; 925 925 buf->length = data_len; 926 926 buf->data = buf->storage; 927 - memcpy(buf->storage, data + ret, data_len); 927 + memcpy(buf->storage, data + ret, flex_array_size(buf, storage, data_len)); 928 928 929 929 /* 930 930 * At this point read_buffer is NULL or READ_BUFFER_DROP (if
+58 -12
drivers/usb/gadget/function/f_mass_storage.c
··· 1189 1189 int msf = common->cmnd[1] & 0x02; 1190 1190 int start_track = common->cmnd[6]; 1191 1191 u8 *buf = (u8 *)bh->buf; 1192 + u8 format; 1193 + int i, len; 1192 1194 1193 1195 if ((common->cmnd[1] & ~0x02) != 0 || /* Mask away MSF */ 1194 1196 start_track > 1) { ··· 1198 1196 return -EINVAL; 1199 1197 } 1200 1198 1201 - memset(buf, 0, 20); 1202 - buf[1] = (20-2); /* TOC data length */ 1203 - buf[2] = 1; /* First track number */ 1204 - buf[3] = 1; /* Last track number */ 1205 - buf[5] = 0x16; /* Data track, copying allowed */ 1206 - buf[6] = 0x01; /* Only track is number 1 */ 1207 - store_cdrom_address(&buf[8], msf, 0); 1199 + format = common->cmnd[2] & 0xf; 1200 + /* 1201 + * Check if CDB is old style SFF-8020i 1202 + * i.e. format is in 2 MSBs of byte 9 1203 + * Mac OS-X host sends us this. 1204 + */ 1205 + if (format == 0) 1206 + format = (common->cmnd[9] >> 6) & 0x3; 1208 1207 1209 - buf[13] = 0x16; /* Lead-out track is data */ 1210 - buf[14] = 0xAA; /* Lead-out track number */ 1211 - store_cdrom_address(&buf[16], msf, curlun->num_sectors); 1212 - return 20; 1208 + switch (format) { 1209 + case 0: 1210 + /* Formatted TOC */ 1211 + len = 4 + 2*8; /* 4 byte header + 2 descriptors */ 1212 + memset(buf, 0, len); 1213 + buf[1] = len - 2; /* TOC Length excludes length field */ 1214 + buf[2] = 1; /* First track number */ 1215 + buf[3] = 1; /* Last track number */ 1216 + buf[5] = 0x16; /* Data track, copying allowed */ 1217 + buf[6] = 0x01; /* Only track is number 1 */ 1218 + store_cdrom_address(&buf[8], msf, 0); 1219 + 1220 + buf[13] = 0x16; /* Lead-out track is data */ 1221 + buf[14] = 0xAA; /* Lead-out track number */ 1222 + store_cdrom_address(&buf[16], msf, curlun->num_sectors); 1223 + return len; 1224 + 1225 + case 2: 1226 + /* Raw TOC */ 1227 + len = 4 + 3*11; /* 4 byte header + 3 descriptors */ 1228 + memset(buf, 0, len); /* Header + A0, A1 & A2 descriptors */ 1229 + buf[1] = len - 2; /* TOC Length excludes length field */ 1230 + buf[2] = 1; /* First complete session */ 1231 + buf[3] = 1; /* Last complete session */ 1232 + 1233 + buf += 4; 1234 + /* fill in A0, A1 and A2 points */ 1235 + for (i = 0; i < 3; i++) { 1236 + buf[0] = 1; /* Session number */ 1237 + buf[1] = 0x16; /* Data track, copying allowed */ 1238 + /* 2 - Track number 0 -> TOC */ 1239 + buf[3] = 0xA0 + i; /* A0, A1, A2 point */ 1240 + /* 4, 5, 6 - Min, sec, frame is zero */ 1241 + buf[8] = 1; /* Pmin: last track number */ 1242 + buf += 11; /* go to next track descriptor */ 1243 + } 1244 + buf -= 11; /* go back to A2 descriptor */ 1245 + 1246 + /* For A2, 7, 8, 9, 10 - zero, Pmin, Psec, Pframe of Lead out */ 1247 + store_cdrom_address(&buf[7], msf, curlun->num_sectors); 1248 + return len; 1249 + 1250 + default: 1251 + /* Multi-session, PMA, ATIP, CD-TEXT not supported/required */ 1252 + curlun->sense_data = SS_INVALID_FIELD_IN_CDB; 1253 + return -EINVAL; 1254 + } 1213 1255 } 1214 1256 1215 1257 static int do_mode_sense(struct fsg_common *common, struct fsg_buffhd *bh) ··· 1991 1945 common->data_size_from_cmnd = 1992 1946 get_unaligned_be16(&common->cmnd[7]); 1993 1947 reply = check_command(common, 10, DATA_DIR_TO_HOST, 1994 - (7<<6) | (1<<1), 1, 1948 + (0xf<<6) | (3<<1), 1, 1995 1949 "READ TOC"); 1996 1950 if (reply == 0) 1997 1951 reply = do_read_toc(common, bh);
+1 -3
drivers/usb/gadget/function/f_phonet.c
··· 668 668 { 669 669 struct f_phonet *fp; 670 670 struct f_phonet_opts *opts; 671 - int size; 672 671 673 - size = sizeof(*fp) + (phonet_rxq_size * sizeof(struct usb_request *)); 674 - fp = kzalloc(size, GFP_KERNEL); 672 + fp = kzalloc(struct_size(fp, out_reqv, phonet_rxq_size), GFP_KERNEL); 675 673 if (!fp) 676 674 return ERR_PTR(-ENOMEM); 677 675
+4
drivers/usb/gadget/function/f_serial.c
··· 345 345 346 346 static void gser_unbind(struct usb_configuration *c, struct usb_function *f) 347 347 { 348 + struct f_gser *gser = func_to_gser(f); 349 + 350 + /* Ensure port is disconnected before unbinding */ 351 + gserial_disconnect(&gser->port); 348 352 usb_free_all_descriptors(f); 349 353 } 350 354
+209 -27
drivers/usb/gadget/function/f_uac1.c
··· 3 3 * f_uac1.c -- USB Audio Class 1.0 Function (using u_audio API) 4 4 * 5 5 * Copyright (C) 2016 Ruslan Bilovol <ruslan.bilovol@gmail.com> 6 + * Copyright (C) 2021 Julian Scheel <julian@jusst.de> 6 7 * 7 8 * This driver doesn't expect any real Audio codec to be present 8 9 * on the device - the audio streams are simply sinked to and ··· 43 42 /* Interrupt IN endpoint of AC interface */ 44 43 struct usb_ep *int_ep; 45 44 atomic_t int_count; 45 + int ctl_id; /* EP id */ 46 + int c_srate; /* current capture srate */ 47 + int p_srate; /* current playback prate */ 46 48 }; 47 49 48 50 static inline struct f_uac1 *func_to_uac1(struct usb_function *f) ··· 192 188 .wFormatTag = cpu_to_le16(UAC_FORMAT_TYPE_I_PCM), 193 189 }; 194 190 195 - DECLARE_UAC_FORMAT_TYPE_I_DISCRETE_DESC(1); 191 + DECLARE_UAC_FORMAT_TYPE_I_DISCRETE_DESC(UAC_MAX_RATES); 192 + #define uac_format_type_i_discrete_descriptor \ 193 + uac_format_type_i_discrete_descriptor_##UAC_MAX_RATES 196 194 197 - static struct uac_format_type_i_discrete_descriptor_1 as_out_type_i_desc = { 198 - .bLength = UAC_FORMAT_TYPE_I_DISCRETE_DESC_SIZE(1), 195 + static struct uac_format_type_i_discrete_descriptor as_out_type_i_desc = { 196 + .bLength = 0, /* filled on rate setup */ 199 197 .bDescriptorType = USB_DT_CS_INTERFACE, 200 198 .bDescriptorSubtype = UAC_FORMAT_TYPE, 201 199 .bFormatType = UAC_FORMAT_TYPE_I, 202 200 .bSubframeSize = 2, 203 201 .bBitResolution = 16, 204 - .bSamFreqType = 1, 202 + .bSamFreqType = 0, /* filled on rate setup */ 205 203 }; 206 204 207 205 /* Standard ISO OUT Endpoint Descriptor */ ··· 227 221 .wLockDelay = cpu_to_le16(1), 228 222 }; 229 223 230 - static struct uac_format_type_i_discrete_descriptor_1 as_in_type_i_desc = { 231 - .bLength = UAC_FORMAT_TYPE_I_DISCRETE_DESC_SIZE(1), 224 + static struct uac_format_type_i_discrete_descriptor as_in_type_i_desc = { 225 + .bLength = 0, /* filled on rate setup */ 232 226 .bDescriptorType = USB_DT_CS_INTERFACE, 233 227 .bDescriptorSubtype = UAC_FORMAT_TYPE, 234 228 .bFormatType = UAC_FORMAT_TYPE_I, 235 229 .bSubframeSize = 2, 236 230 .bBitResolution = 16, 237 - .bSamFreqType = 1, 231 + .bSamFreqType = 0, /* filled on rate setup */ 238 232 }; 239 233 240 234 /* Standard ISO OUT Endpoint Descriptor */ ··· 309 303 }; 310 304 311 305 static struct usb_string strings_uac1[] = { 312 - [STR_AC_IF].s = "AC Interface", 306 + /* [STR_AC_IF].s = DYNAMIC, */ 313 307 [STR_USB_OUT_IT].s = "Playback Input terminal", 314 308 [STR_USB_OUT_IT_CH_NAMES].s = "Playback Channels", 315 309 [STR_IO_OUT_OT].s = "Playback Output terminal", ··· 338 332 /* 339 333 * This function is an ALSA sound card following USB Audio Class Spec 1.0. 340 334 */ 335 + 336 + static void uac_cs_attr_sample_rate(struct usb_ep *ep, struct usb_request *req) 337 + { 338 + struct usb_function *fn = ep->driver_data; 339 + struct usb_composite_dev *cdev = fn->config->cdev; 340 + struct g_audio *agdev = func_to_g_audio(fn); 341 + struct f_uac1 *uac1 = func_to_uac1(fn); 342 + u8 *buf = (u8 *)req->buf; 343 + u32 val = 0; 344 + 345 + if (req->actual != 3) { 346 + WARN(cdev, "Invalid data size for UAC_EP_CS_ATTR_SAMPLE_RATE.\n"); 347 + return; 348 + } 349 + 350 + val = buf[0] | (buf[1] << 8) | (buf[2] << 16); 351 + if (uac1->ctl_id == (USB_DIR_IN | 2)) { 352 + uac1->p_srate = val; 353 + u_audio_set_playback_srate(agdev, uac1->p_srate); 354 + } else if (uac1->ctl_id == (USB_DIR_OUT | 1)) { 355 + uac1->c_srate = val; 356 + u_audio_set_capture_srate(agdev, uac1->c_srate); 357 + } 358 + } 341 359 342 360 static void audio_notify_complete(struct usb_ep *_ep, struct usb_request *req) 343 361 { ··· 737 707 const struct usb_ctrlrequest *ctrl) 738 708 { 739 709 struct usb_composite_dev *cdev = f->config->cdev; 710 + struct usb_request *req = f->config->cdev->req; 711 + struct f_uac1 *uac1 = func_to_uac1(f); 740 712 int value = -EOPNOTSUPP; 741 713 u16 ep = le16_to_cpu(ctrl->wIndex); 742 714 u16 len = le16_to_cpu(ctrl->wLength); 743 715 u16 w_value = le16_to_cpu(ctrl->wValue); 716 + u8 cs = w_value >> 8; 744 717 745 718 DBG(cdev, "bRequest 0x%x, w_value 0x%04x, len %d, endpoint %d\n", 746 719 ctrl->bRequest, w_value, len, ep); 747 720 748 721 switch (ctrl->bRequest) { 749 - case UAC_SET_CUR: 722 + case UAC_SET_CUR: { 723 + if (cs == UAC_EP_CS_ATTR_SAMPLE_RATE) { 724 + cdev->gadget->ep0->driver_data = f; 725 + uac1->ctl_id = ep; 726 + req->complete = uac_cs_attr_sample_rate; 727 + } 750 728 value = len; 751 729 break; 730 + } 752 731 753 732 case UAC_SET_MIN: 754 733 break; ··· 782 743 const struct usb_ctrlrequest *ctrl) 783 744 { 784 745 struct usb_composite_dev *cdev = f->config->cdev; 746 + struct usb_request *req = f->config->cdev->req; 747 + struct f_uac1 *uac1 = func_to_uac1(f); 748 + u8 *buf = (u8 *)req->buf; 785 749 int value = -EOPNOTSUPP; 786 - u8 ep = ((le16_to_cpu(ctrl->wIndex) >> 8) & 0xFF); 750 + u8 ep = le16_to_cpu(ctrl->wIndex); 787 751 u16 len = le16_to_cpu(ctrl->wLength); 788 752 u16 w_value = le16_to_cpu(ctrl->wValue); 753 + u8 cs = w_value >> 8; 754 + u32 val = 0; 789 755 790 756 DBG(cdev, "bRequest 0x%x, w_value 0x%04x, len %d, endpoint %d\n", 791 757 ctrl->bRequest, w_value, len, ep); 792 758 793 759 switch (ctrl->bRequest) { 794 - case UAC_GET_CUR: 760 + case UAC_GET_CUR: { 761 + if (cs == UAC_EP_CS_ATTR_SAMPLE_RATE) { 762 + if (ep == (USB_DIR_IN | 2)) 763 + val = uac1->p_srate; 764 + else if (ep == (USB_DIR_OUT | 1)) 765 + val = uac1->c_srate; 766 + buf[2] = (val >> 16) & 0xff; 767 + buf[1] = (val >> 8) & 0xff; 768 + buf[0] = val & 0xff; 769 + } 770 + value = len; 771 + break; 772 + } 795 773 case UAC_GET_MIN: 796 774 case UAC_GET_MAX: 797 775 case UAC_GET_RES: ··· 959 903 u_audio_stop_capture(&uac1->g_audio); 960 904 if (uac1->int_ep) 961 905 usb_ep_disable(uac1->int_ep); 906 + } 907 + 908 + static void 909 + f_audio_suspend(struct usb_function *f) 910 + { 911 + struct f_uac1 *uac1 = func_to_uac1(f); 912 + 913 + u_audio_suspend(&uac1->g_audio); 962 914 } 963 915 964 916 /*-------------------------------------------------------------------------*/ ··· 1138 1074 } else if ((opts->c_ssize < 1) || (opts->c_ssize > 4)) { 1139 1075 dev_err(dev, "Error: incorrect capture sample size\n"); 1140 1076 return -EINVAL; 1141 - } else if (!opts->p_srate) { 1077 + } else if (!opts->p_srates[0]) { 1142 1078 dev_err(dev, "Error: incorrect playback sampling rate\n"); 1143 1079 return -EINVAL; 1144 - } else if (!opts->c_srate) { 1080 + } else if (!opts->c_srates[0]) { 1145 1081 dev_err(dev, "Error: incorrect capture sampling rate\n"); 1146 1082 return -EINVAL; 1147 1083 } ··· 1182 1118 struct f_uac1_opts *audio_opts; 1183 1119 struct usb_ep *ep = NULL; 1184 1120 struct usb_string *us; 1185 - u8 *sam_freq; 1186 - int rate; 1187 1121 int ba_iface_id; 1188 1122 int status; 1123 + int idx, i; 1189 1124 1190 1125 status = f_audio_validate_opts(audio, dev); 1191 1126 if (status) 1192 1127 return status; 1193 1128 1194 1129 audio_opts = container_of(f->fi, struct f_uac1_opts, func_inst); 1130 + 1131 + strings_uac1[STR_AC_IF].s = audio_opts->function_name; 1195 1132 1196 1133 us = usb_gstrings_attach(cdev, uac1_strings, ARRAY_SIZE(strings_uac1)); 1197 1134 if (IS_ERR(us)) ··· 1278 1213 } 1279 1214 1280 1215 /* Set sample rates */ 1281 - rate = audio_opts->c_srate; 1282 - sam_freq = as_out_type_i_desc.tSamFreq[0]; 1283 - memcpy(sam_freq, &rate, 3); 1284 - rate = audio_opts->p_srate; 1285 - sam_freq = as_in_type_i_desc.tSamFreq[0]; 1286 - memcpy(sam_freq, &rate, 3); 1216 + for (i = 0, idx = 0; i < UAC_MAX_RATES; i++) { 1217 + if (audio_opts->c_srates[i] == 0) 1218 + break; 1219 + memcpy(as_out_type_i_desc.tSamFreq[idx++], 1220 + &audio_opts->c_srates[i], 3); 1221 + } 1222 + as_out_type_i_desc.bLength = UAC_FORMAT_TYPE_I_DISCRETE_DESC_SIZE(idx); 1223 + as_out_type_i_desc.bSamFreqType = idx; 1224 + 1225 + for (i = 0, idx = 0; i < UAC_MAX_RATES; i++) { 1226 + if (audio_opts->p_srates[i] == 0) 1227 + break; 1228 + memcpy(as_in_type_i_desc.tSamFreq[idx++], 1229 + &audio_opts->p_srates[i], 3); 1230 + } 1231 + as_in_type_i_desc.bLength = UAC_FORMAT_TYPE_I_DISCRETE_DESC_SIZE(idx); 1232 + as_in_type_i_desc.bSamFreqType = idx; 1233 + uac1->p_srate = audio_opts->p_srates[0]; 1234 + uac1->c_srate = audio_opts->c_srates[0]; 1287 1235 1288 1236 /* allocate instance-specific interface IDs, and patch descriptors */ 1289 1237 status = usb_interface_id(c, f); ··· 1375 1297 audio->out_ep_maxpsize = le16_to_cpu(as_out_ep_desc.wMaxPacketSize); 1376 1298 audio->in_ep_maxpsize = le16_to_cpu(as_in_ep_desc.wMaxPacketSize); 1377 1299 audio->params.c_chmask = audio_opts->c_chmask; 1378 - audio->params.c_srate = audio_opts->c_srate; 1300 + memcpy(audio->params.c_srates, audio_opts->c_srates, 1301 + sizeof(audio->params.c_srates)); 1379 1302 audio->params.c_ssize = audio_opts->c_ssize; 1380 1303 if (FUIN_EN(audio_opts)) { 1381 1304 audio->params.p_fu.id = USB_IN_FU_ID; ··· 1388 1309 audio->params.p_fu.volume_res = audio_opts->p_volume_res; 1389 1310 } 1390 1311 audio->params.p_chmask = audio_opts->p_chmask; 1391 - audio->params.p_srate = audio_opts->p_srate; 1312 + memcpy(audio->params.p_srates, audio_opts->p_srates, 1313 + sizeof(audio->params.p_srates)); 1392 1314 audio->params.p_ssize = audio_opts->p_ssize; 1393 1315 if (FUOUT_EN(audio_opts)) { 1394 1316 audio->params.c_fu.id = USB_OUT_FU_ID; ··· 1494 1414 \ 1495 1415 CONFIGFS_ATTR(f_uac1_opts_, name) 1496 1416 1417 + #define UAC1_RATE_ATTRIBUTE(name) \ 1418 + static ssize_t f_uac1_opts_##name##_show(struct config_item *item, \ 1419 + char *page) \ 1420 + { \ 1421 + struct f_uac1_opts *opts = to_f_uac1_opts(item); \ 1422 + int result = 0; \ 1423 + int i; \ 1424 + \ 1425 + mutex_lock(&opts->lock); \ 1426 + page[0] = '\0'; \ 1427 + for (i = 0; i < UAC_MAX_RATES; i++) { \ 1428 + if (opts->name##s[i] == 0) \ 1429 + break; \ 1430 + result += sprintf(page + strlen(page), "%u,", \ 1431 + opts->name##s[i]); \ 1432 + } \ 1433 + if (strlen(page) > 0) \ 1434 + page[strlen(page) - 1] = '\n'; \ 1435 + mutex_unlock(&opts->lock); \ 1436 + \ 1437 + return result; \ 1438 + } \ 1439 + \ 1440 + static ssize_t f_uac1_opts_##name##_store(struct config_item *item, \ 1441 + const char *page, size_t len) \ 1442 + { \ 1443 + struct f_uac1_opts *opts = to_f_uac1_opts(item); \ 1444 + char *split_page = NULL; \ 1445 + int ret = -EINVAL; \ 1446 + char *token; \ 1447 + u32 num; \ 1448 + int i; \ 1449 + \ 1450 + mutex_lock(&opts->lock); \ 1451 + if (opts->refcnt) { \ 1452 + ret = -EBUSY; \ 1453 + goto end; \ 1454 + } \ 1455 + \ 1456 + i = 0; \ 1457 + memset(opts->name##s, 0x00, sizeof(opts->name##s)); \ 1458 + split_page = kstrdup(page, GFP_KERNEL); \ 1459 + while ((token = strsep(&split_page, ",")) != NULL) { \ 1460 + ret = kstrtou32(token, 0, &num); \ 1461 + if (ret) \ 1462 + goto end; \ 1463 + \ 1464 + opts->name##s[i++] = num; \ 1465 + ret = len; \ 1466 + }; \ 1467 + \ 1468 + end: \ 1469 + kfree(split_page); \ 1470 + mutex_unlock(&opts->lock); \ 1471 + return ret; \ 1472 + } \ 1473 + \ 1474 + CONFIGFS_ATTR(f_uac1_opts_, name) 1475 + 1476 + #define UAC1_ATTRIBUTE_STRING(name) \ 1477 + static ssize_t f_uac1_opts_##name##_show(struct config_item *item, \ 1478 + char *page) \ 1479 + { \ 1480 + struct f_uac1_opts *opts = to_f_uac1_opts(item); \ 1481 + int result; \ 1482 + \ 1483 + mutex_lock(&opts->lock); \ 1484 + result = snprintf(page, sizeof(opts->name), "%s", opts->name); \ 1485 + mutex_unlock(&opts->lock); \ 1486 + \ 1487 + return result; \ 1488 + } \ 1489 + \ 1490 + static ssize_t f_uac1_opts_##name##_store(struct config_item *item, \ 1491 + const char *page, size_t len) \ 1492 + { \ 1493 + struct f_uac1_opts *opts = to_f_uac1_opts(item); \ 1494 + int ret = 0; \ 1495 + \ 1496 + mutex_lock(&opts->lock); \ 1497 + if (opts->refcnt) { \ 1498 + ret = -EBUSY; \ 1499 + goto end; \ 1500 + } \ 1501 + \ 1502 + ret = snprintf(opts->name, min(sizeof(opts->name), len), \ 1503 + "%s", page); \ 1504 + \ 1505 + end: \ 1506 + mutex_unlock(&opts->lock); \ 1507 + return ret; \ 1508 + } \ 1509 + \ 1510 + CONFIGFS_ATTR(f_uac1_opts_, name) 1511 + 1497 1512 UAC1_ATTRIBUTE(u32, c_chmask); 1498 - UAC1_ATTRIBUTE(u32, c_srate); 1513 + UAC1_RATE_ATTRIBUTE(c_srate); 1499 1514 UAC1_ATTRIBUTE(u32, c_ssize); 1500 1515 UAC1_ATTRIBUTE(u32, p_chmask); 1501 - UAC1_ATTRIBUTE(u32, p_srate); 1516 + UAC1_RATE_ATTRIBUTE(p_srate); 1502 1517 UAC1_ATTRIBUTE(u32, p_ssize); 1503 1518 UAC1_ATTRIBUTE(u32, req_number); 1504 1519 ··· 1608 1433 UAC1_ATTRIBUTE(s16, c_volume_min); 1609 1434 UAC1_ATTRIBUTE(s16, c_volume_max); 1610 1435 UAC1_ATTRIBUTE(s16, c_volume_res); 1436 + UAC1_ATTRIBUTE_STRING(function_name); 1611 1437 1612 1438 static struct configfs_attribute *f_uac1_attrs[] = { 1613 1439 &f_uac1_opts_attr_c_chmask, ··· 1630 1454 &f_uac1_opts_attr_c_volume_min, 1631 1455 &f_uac1_opts_attr_c_volume_max, 1632 1456 &f_uac1_opts_attr_c_volume_res, 1457 + 1458 + &f_uac1_opts_attr_function_name, 1633 1459 1634 1460 NULL, 1635 1461 }; ··· 1665 1487 &f_uac1_func_type); 1666 1488 1667 1489 opts->c_chmask = UAC1_DEF_CCHMASK; 1668 - opts->c_srate = UAC1_DEF_CSRATE; 1490 + opts->c_srates[0] = UAC1_DEF_CSRATE; 1669 1491 opts->c_ssize = UAC1_DEF_CSSIZE; 1670 1492 opts->p_chmask = UAC1_DEF_PCHMASK; 1671 - opts->p_srate = UAC1_DEF_PSRATE; 1493 + opts->p_srates[0] = UAC1_DEF_PSRATE; 1672 1494 opts->p_ssize = UAC1_DEF_PSSIZE; 1673 1495 1674 1496 opts->p_mute_present = UAC1_DEF_MUTE_PRESENT; ··· 1684 1506 opts->c_volume_res = UAC1_DEF_RES_DB; 1685 1507 1686 1508 opts->req_number = UAC1_DEF_REQ_NUM; 1509 + 1510 + snprintf(opts->function_name, sizeof(opts->function_name), "AC Interface"); 1511 + 1687 1512 return &opts->func_inst; 1688 1513 } 1689 1514 ··· 1743 1562 uac1->g_audio.func.get_alt = f_audio_get_alt; 1744 1563 uac1->g_audio.func.setup = f_audio_setup; 1745 1564 uac1->g_audio.func.disable = f_audio_disable; 1565 + uac1->g_audio.func.suspend = f_audio_suspend; 1746 1566 uac1->g_audio.func.free_func = f_audio_free; 1747 1567 1748 1568 return &uac1->g_audio.func;
+354 -120
drivers/usb/gadget/function/f_uac2.c
··· 70 70 /* Interrupt IN endpoint of AC interface */ 71 71 struct usb_ep *int_ep; 72 72 atomic_t int_count; 73 + /* transient state, only valid during handling of a single control request */ 74 + int clock_id; 73 75 }; 74 76 75 77 static inline struct f_uac2 *func_to_uac2(struct usb_function *f) ··· 106 104 STR_AS_IN_ALT1, 107 105 }; 108 106 109 - static char clksrc_in[8]; 110 - static char clksrc_out[8]; 111 - 112 107 static struct usb_string strings_fn[] = { 113 - [STR_ASSOC].s = "Source/Sink", 108 + /* [STR_ASSOC].s = DYNAMIC, */ 114 109 [STR_IF_CTRL].s = "Topology Control", 115 - [STR_CLKSRC_IN].s = clksrc_in, 116 - [STR_CLKSRC_OUT].s = clksrc_out, 110 + [STR_CLKSRC_IN].s = "Input Clock", 111 + [STR_CLKSRC_OUT].s = "Output Clock", 117 112 [STR_USB_IT].s = "USBH Out", 118 113 [STR_IO_IT].s = "USBD Out", 119 114 [STR_USB_OT].s = "USBH In", ··· 122 123 [STR_AS_IN_ALT0].s = "Capture Inactive", 123 124 [STR_AS_IN_ALT1].s = "Capture Active", 124 125 { }, 126 + }; 127 + 128 + static const char *const speed_names[] = { 129 + [USB_SPEED_UNKNOWN] = "UNKNOWN", 130 + [USB_SPEED_LOW] = "LS", 131 + [USB_SPEED_FULL] = "FS", 132 + [USB_SPEED_HIGH] = "HS", 133 + [USB_SPEED_WIRELESS] = "W", 134 + [USB_SPEED_SUPER] = "SS", 135 + [USB_SPEED_SUPER_PLUS] = "SS+", 125 136 }; 126 137 127 138 static struct usb_gadget_strings str_fn = { ··· 175 166 .bDescriptorSubtype = UAC2_CLOCK_SOURCE, 176 167 /* .bClockID = DYNAMIC */ 177 168 .bmAttributes = UAC_CLOCK_SOURCE_TYPE_INT_FIXED, 178 - .bmControls = (CONTROL_RDONLY << CLK_FREQ_CTRL), 169 + .bmControls = (CONTROL_RDWR << CLK_FREQ_CTRL), 179 170 .bAssocTerminal = 0, 180 171 }; 181 172 ··· 187 178 .bDescriptorSubtype = UAC2_CLOCK_SOURCE, 188 179 /* .bClockID = DYNAMIC */ 189 180 .bmAttributes = UAC_CLOCK_SOURCE_TYPE_INT_FIXED, 190 - .bmControls = (CONTROL_RDONLY << CLK_FREQ_CTRL), 181 + .bmControls = (CONTROL_RDWR << CLK_FREQ_CTRL), 191 182 .bAssocTerminal = 0, 192 183 }; 193 184 ··· 353 344 354 345 /* .bmAttributes = DYNAMIC */ 355 346 /* .wMaxPacketSize = DYNAMIC */ 356 - .bInterval = 4, 347 + /* .bInterval = DYNAMIC */ 357 348 }; 358 349 359 350 static struct usb_endpoint_descriptor ss_epout_desc = { ··· 363 354 .bEndpointAddress = USB_DIR_OUT, 364 355 /* .bmAttributes = DYNAMIC */ 365 356 /* .wMaxPacketSize = DYNAMIC */ 366 - .bInterval = 4, 357 + /* .bInterval = DYNAMIC */ 367 358 }; 368 359 369 360 static struct usb_ss_ep_comp_descriptor ss_epout_desc_comp = { ··· 487 478 488 479 .bmAttributes = USB_ENDPOINT_XFER_ISOC | USB_ENDPOINT_SYNC_ASYNC, 489 480 /* .wMaxPacketSize = DYNAMIC */ 490 - .bInterval = 4, 481 + /* .bInterval = DYNAMIC */ 491 482 }; 492 483 493 484 static struct usb_endpoint_descriptor ss_epin_desc = { ··· 497 488 .bEndpointAddress = USB_DIR_IN, 498 489 .bmAttributes = USB_ENDPOINT_XFER_ISOC | USB_ENDPOINT_SYNC_ASYNC, 499 490 /* .wMaxPacketSize = DYNAMIC */ 500 - .bInterval = 4, 491 + /* .bInterval = DYNAMIC */ 501 492 }; 502 493 503 494 static struct usb_ss_ep_comp_descriptor ss_epin_desc_comp = { ··· 643 634 __le32 dCUR; 644 635 }; 645 636 646 - struct cntrl_range_lay3 { 647 - __le16 wNumSubRanges; 637 + struct cntrl_subrange_lay3 { 648 638 __le32 dMIN; 649 639 __le32 dMAX; 650 640 __le32 dRES; 651 641 } __packed; 652 642 653 - static int set_ep_max_packet_size(const struct f_uac2_opts *uac2_opts, 654 - struct usb_endpoint_descriptor *ep_desc, 655 - enum usb_device_speed speed, bool is_playback) 643 + #define ranges_lay3_size(c) (sizeof(c.wNumSubRanges) \ 644 + + le16_to_cpu(c.wNumSubRanges) \ 645 + * sizeof(struct cntrl_subrange_lay3)) 646 + 647 + #define DECLARE_UAC2_CNTRL_RANGES_LAY3(k, n) \ 648 + struct cntrl_ranges_lay3_##k { \ 649 + __le16 wNumSubRanges; \ 650 + struct cntrl_subrange_lay3 r[n]; \ 651 + } __packed 652 + 653 + DECLARE_UAC2_CNTRL_RANGES_LAY3(srates, UAC_MAX_RATES); 654 + 655 + static int get_max_srate(const int *srates) 656 + { 657 + int i, max_srate = 0; 658 + 659 + for (i = 0; i < UAC_MAX_RATES; i++) { 660 + if (srates[i] == 0) 661 + break; 662 + if (srates[i] > max_srate) 663 + max_srate = srates[i]; 664 + } 665 + return max_srate; 666 + } 667 + 668 + static int get_max_bw_for_bint(const struct f_uac2_opts *uac2_opts, 669 + u8 bint, unsigned int factor, bool is_playback) 656 670 { 657 671 int chmask, srate, ssize; 658 - u16 max_size_bw, max_size_ep; 659 - unsigned int factor; 660 - 661 - switch (speed) { 662 - case USB_SPEED_FULL: 663 - max_size_ep = 1023; 664 - factor = 1000; 665 - break; 666 - 667 - case USB_SPEED_HIGH: 668 - case USB_SPEED_SUPER: 669 - max_size_ep = 1024; 670 - factor = 8000; 671 - break; 672 - 673 - default: 674 - return -EINVAL; 675 - } 672 + u16 max_size_bw; 676 673 677 674 if (is_playback) { 678 675 chmask = uac2_opts->p_chmask; 679 - srate = uac2_opts->p_srate; 676 + srate = get_max_srate(uac2_opts->p_srates); 680 677 ssize = uac2_opts->p_ssize; 681 678 } else { 682 679 chmask = uac2_opts->c_chmask; 683 - srate = uac2_opts->c_srate; 680 + srate = get_max_srate(uac2_opts->c_srates); 684 681 ssize = uac2_opts->c_ssize; 685 682 } 686 683 ··· 696 681 srate = srate * (1000 + uac2_opts->fb_max) / 1000; 697 682 // updated srate is always bigger, therefore DIV_ROUND_UP always yields +1 698 683 max_size_bw = num_channels(chmask) * ssize * 699 - (DIV_ROUND_UP(srate, factor / (1 << (ep_desc->bInterval - 1)))); 684 + (DIV_ROUND_UP(srate, factor / (1 << (bint - 1)))); 700 685 } else { 701 686 // adding 1 frame provision for Win10 702 687 max_size_bw = num_channels(chmask) * ssize * 703 - (DIV_ROUND_UP(srate, factor / (1 << (ep_desc->bInterval - 1))) + 1); 688 + (DIV_ROUND_UP(srate, factor / (1 << (bint - 1))) + 1); 704 689 } 705 - ep_desc->wMaxPacketSize = cpu_to_le16(min_t(u16, max_size_bw, 706 - max_size_ep)); 690 + return max_size_bw; 691 + } 692 + 693 + static int set_ep_max_packet_size_bint(struct device *dev, const struct f_uac2_opts *uac2_opts, 694 + struct usb_endpoint_descriptor *ep_desc, 695 + enum usb_device_speed speed, bool is_playback) 696 + { 697 + u16 max_size_bw, max_size_ep; 698 + u8 bint, opts_bint; 699 + char *dir; 700 + 701 + switch (speed) { 702 + case USB_SPEED_FULL: 703 + max_size_ep = 1023; 704 + // fixed 705 + bint = ep_desc->bInterval; 706 + max_size_bw = get_max_bw_for_bint(uac2_opts, bint, 1000, is_playback); 707 + break; 708 + 709 + case USB_SPEED_HIGH: 710 + case USB_SPEED_SUPER: 711 + max_size_ep = 1024; 712 + if (is_playback) 713 + opts_bint = uac2_opts->p_hs_bint; 714 + else 715 + opts_bint = uac2_opts->c_hs_bint; 716 + 717 + if (opts_bint > 0) { 718 + /* fixed bint */ 719 + bint = opts_bint; 720 + max_size_bw = get_max_bw_for_bint(uac2_opts, bint, 8000, is_playback); 721 + } else { 722 + /* checking bInterval from 4 to 1 whether the required bandwidth fits */ 723 + for (bint = 4; bint > 0; --bint) { 724 + max_size_bw = get_max_bw_for_bint( 725 + uac2_opts, bint, 8000, is_playback); 726 + if (max_size_bw <= max_size_ep) 727 + break; 728 + } 729 + } 730 + break; 731 + 732 + default: 733 + return -EINVAL; 734 + } 735 + 736 + if (is_playback) 737 + dir = "Playback"; 738 + else 739 + dir = "Capture"; 740 + 741 + if (max_size_bw <= max_size_ep) 742 + dev_dbg(dev, 743 + "%s %s: Would use wMaxPacketSize %d and bInterval %d\n", 744 + speed_names[speed], dir, max_size_bw, bint); 745 + else { 746 + dev_warn(dev, 747 + "%s %s: Req. wMaxPacketSize %d at bInterval %d > max ISOC %d, may drop data!\n", 748 + speed_names[speed], dir, max_size_bw, bint, max_size_ep); 749 + max_size_bw = max_size_ep; 750 + } 751 + 752 + ep_desc->wMaxPacketSize = cpu_to_le16(max_size_bw); 753 + ep_desc->bInterval = bint; 707 754 708 755 return 0; 709 756 } ··· 973 896 static int afunc_validate_opts(struct g_audio *agdev, struct device *dev) 974 897 { 975 898 struct f_uac2_opts *opts = g_audio_to_uac2_opts(agdev); 899 + const char *msg = NULL; 976 900 977 - if (!opts->p_chmask && !opts->c_chmask) { 978 - dev_err(dev, "Error: no playback and capture channels\n"); 979 - return -EINVAL; 980 - } else if (opts->p_chmask & ~UAC2_CHANNEL_MASK) { 981 - dev_err(dev, "Error: unsupported playback channels mask\n"); 982 - return -EINVAL; 983 - } else if (opts->c_chmask & ~UAC2_CHANNEL_MASK) { 984 - dev_err(dev, "Error: unsupported capture channels mask\n"); 985 - return -EINVAL; 986 - } else if ((opts->p_ssize < 1) || (opts->p_ssize > 4)) { 987 - dev_err(dev, "Error: incorrect playback sample size\n"); 988 - return -EINVAL; 989 - } else if ((opts->c_ssize < 1) || (opts->c_ssize > 4)) { 990 - dev_err(dev, "Error: incorrect capture sample size\n"); 991 - return -EINVAL; 992 - } else if (!opts->p_srate) { 993 - dev_err(dev, "Error: incorrect playback sampling rate\n"); 994 - return -EINVAL; 995 - } else if (!opts->c_srate) { 996 - dev_err(dev, "Error: incorrect capture sampling rate\n"); 997 - return -EINVAL; 998 - } 901 + if (!opts->p_chmask && !opts->c_chmask) 902 + msg = "no playback and capture channels"; 903 + else if (opts->p_chmask & ~UAC2_CHANNEL_MASK) 904 + msg = "unsupported playback channels mask"; 905 + else if (opts->c_chmask & ~UAC2_CHANNEL_MASK) 906 + msg = "unsupported capture channels mask"; 907 + else if ((opts->p_ssize < 1) || (opts->p_ssize > 4)) 908 + msg = "incorrect playback sample size"; 909 + else if ((opts->c_ssize < 1) || (opts->c_ssize > 4)) 910 + msg = "incorrect capture sample size"; 911 + else if (!opts->p_srates[0]) 912 + msg = "incorrect playback sampling rate"; 913 + else if (!opts->c_srates[0]) 914 + msg = "incorrect capture sampling rate"; 999 915 1000 - if (opts->p_volume_max <= opts->p_volume_min) { 1001 - dev_err(dev, "Error: incorrect playback volume max/min\n"); 1002 - return -EINVAL; 1003 - } else if (opts->c_volume_max <= opts->c_volume_min) { 1004 - dev_err(dev, "Error: incorrect capture volume max/min\n"); 1005 - return -EINVAL; 1006 - } else if (opts->p_volume_res <= 0) { 1007 - dev_err(dev, "Error: negative/zero playback volume resolution\n"); 1008 - return -EINVAL; 1009 - } else if (opts->c_volume_res <= 0) { 1010 - dev_err(dev, "Error: negative/zero capture volume resolution\n"); 1011 - return -EINVAL; 1012 - } 916 + else if (opts->p_volume_max <= opts->p_volume_min) 917 + msg = "incorrect playback volume max/min"; 918 + else if (opts->c_volume_max <= opts->c_volume_min) 919 + msg = "incorrect capture volume max/min"; 920 + else if (opts->p_volume_res <= 0) 921 + msg = "negative/zero playback volume resolution"; 922 + else if (opts->c_volume_res <= 0) 923 + msg = "negative/zero capture volume resolution"; 1013 924 1014 - if ((opts->p_volume_max - opts->p_volume_min) % opts->p_volume_res) { 1015 - dev_err(dev, "Error: incorrect playback volume resolution\n"); 1016 - return -EINVAL; 1017 - } else if ((opts->c_volume_max - opts->c_volume_min) % opts->c_volume_res) { 1018 - dev_err(dev, "Error: incorrect capture volume resolution\n"); 1019 - return -EINVAL; 925 + else if ((opts->p_volume_max - opts->p_volume_min) % opts->p_volume_res) 926 + msg = "incorrect playback volume resolution"; 927 + else if ((opts->c_volume_max - opts->c_volume_min) % opts->c_volume_res) 928 + msg = "incorrect capture volume resolution"; 929 + 930 + else if ((opts->p_hs_bint < 0) || (opts->p_hs_bint > 4)) 931 + msg = "incorrect playback HS/SS bInterval (1-4: fixed, 0: auto)"; 932 + else if ((opts->c_hs_bint < 0) || (opts->c_hs_bint > 4)) 933 + msg = "incorrect capture HS/SS bInterval (1-4: fixed, 0: auto)"; 934 + 935 + if (msg) { 936 + dev_err(dev, "Error: %s\n", msg); 937 + return -EINVAL; 1020 938 } 1021 939 1022 940 return 0; ··· 1032 960 ret = afunc_validate_opts(agdev, dev); 1033 961 if (ret) 1034 962 return ret; 963 + 964 + strings_fn[STR_ASSOC].s = uac2_opts->function_name; 1035 965 1036 966 us = usb_gstrings_attach(cdev, fn_strings, ARRAY_SIZE(strings_fn)); 1037 967 if (IS_ERR(us)) ··· 1111 1037 *bma = cpu_to_le32(control); 1112 1038 } 1113 1039 1114 - snprintf(clksrc_in, sizeof(clksrc_in), "%uHz", uac2_opts->p_srate); 1115 - snprintf(clksrc_out, sizeof(clksrc_out), "%uHz", uac2_opts->c_srate); 1116 - 1117 1040 ret = usb_interface_id(cfg, fn); 1118 1041 if (ret < 0) { 1119 1042 dev_err(dev, "%s:%d Error!\n", __func__, __LINE__); ··· 1174 1103 std_ac_if_desc.bNumEndpoints = 1; 1175 1104 } 1176 1105 1106 + hs_epin_desc.bInterval = uac2_opts->p_hs_bint; 1107 + ss_epin_desc.bInterval = uac2_opts->p_hs_bint; 1108 + hs_epout_desc.bInterval = uac2_opts->c_hs_bint; 1109 + ss_epout_desc.bInterval = uac2_opts->c_hs_bint; 1110 + 1177 1111 /* Calculate wMaxPacketSize according to audio bandwidth */ 1178 - ret = set_ep_max_packet_size(uac2_opts, &fs_epin_desc, USB_SPEED_FULL, 1179 - true); 1112 + ret = set_ep_max_packet_size_bint(dev, uac2_opts, &fs_epin_desc, 1113 + USB_SPEED_FULL, true); 1180 1114 if (ret < 0) { 1181 1115 dev_err(dev, "%s:%d Error!\n", __func__, __LINE__); 1182 1116 return ret; 1183 1117 } 1184 1118 1185 - ret = set_ep_max_packet_size(uac2_opts, &fs_epout_desc, USB_SPEED_FULL, 1186 - false); 1119 + ret = set_ep_max_packet_size_bint(dev, uac2_opts, &fs_epout_desc, 1120 + USB_SPEED_FULL, false); 1187 1121 if (ret < 0) { 1188 1122 dev_err(dev, "%s:%d Error!\n", __func__, __LINE__); 1189 1123 return ret; 1190 1124 } 1191 1125 1192 - ret = set_ep_max_packet_size(uac2_opts, &hs_epin_desc, USB_SPEED_HIGH, 1193 - true); 1126 + ret = set_ep_max_packet_size_bint(dev, uac2_opts, &hs_epin_desc, 1127 + USB_SPEED_HIGH, true); 1194 1128 if (ret < 0) { 1195 1129 dev_err(dev, "%s:%d Error!\n", __func__, __LINE__); 1196 1130 return ret; 1197 1131 } 1198 1132 1199 - ret = set_ep_max_packet_size(uac2_opts, &hs_epout_desc, USB_SPEED_HIGH, 1200 - false); 1133 + ret = set_ep_max_packet_size_bint(dev, uac2_opts, &hs_epout_desc, 1134 + USB_SPEED_HIGH, false); 1201 1135 if (ret < 0) { 1202 1136 dev_err(dev, "%s:%d Error!\n", __func__, __LINE__); 1203 1137 return ret; 1204 1138 } 1205 1139 1206 - ret = set_ep_max_packet_size(uac2_opts, &ss_epin_desc, USB_SPEED_SUPER, 1207 - true); 1140 + ret = set_ep_max_packet_size_bint(dev, uac2_opts, &ss_epin_desc, 1141 + USB_SPEED_SUPER, true); 1208 1142 if (ret < 0) { 1209 1143 dev_err(dev, "%s:%d Error!\n", __func__, __LINE__); 1210 1144 return ret; 1211 1145 } 1212 1146 1213 - ret = set_ep_max_packet_size(uac2_opts, &ss_epout_desc, USB_SPEED_SUPER, 1214 - false); 1147 + ret = set_ep_max_packet_size_bint(dev, uac2_opts, &ss_epout_desc, 1148 + USB_SPEED_SUPER, false); 1215 1149 if (ret < 0) { 1216 1150 dev_err(dev, "%s:%d Error!\n", __func__, __LINE__); 1217 1151 return ret; ··· 1285 1209 agdev->gadget = gadget; 1286 1210 1287 1211 agdev->params.p_chmask = uac2_opts->p_chmask; 1288 - agdev->params.p_srate = uac2_opts->p_srate; 1212 + memcpy(agdev->params.p_srates, uac2_opts->p_srates, 1213 + sizeof(agdev->params.p_srates)); 1289 1214 agdev->params.p_ssize = uac2_opts->p_ssize; 1290 1215 if (FUIN_EN(uac2_opts)) { 1291 1216 agdev->params.p_fu.id = USB_IN_FU_ID; ··· 1297 1220 agdev->params.p_fu.volume_res = uac2_opts->p_volume_res; 1298 1221 } 1299 1222 agdev->params.c_chmask = uac2_opts->c_chmask; 1300 - agdev->params.c_srate = uac2_opts->c_srate; 1223 + memcpy(agdev->params.c_srates, uac2_opts->c_srates, 1224 + sizeof(agdev->params.c_srates)); 1301 1225 agdev->params.c_ssize = uac2_opts->c_ssize; 1302 1226 if (FUOUT_EN(uac2_opts)) { 1303 1227 agdev->params.c_fu.id = USB_OUT_FU_ID; ··· 1489 1411 usb_ep_disable(uac2->int_ep); 1490 1412 } 1491 1413 1414 + static void 1415 + afunc_suspend(struct usb_function *fn) 1416 + { 1417 + struct f_uac2 *uac2 = func_to_uac2(fn); 1418 + 1419 + u_audio_suspend(&uac2->g_audio); 1420 + } 1421 + 1492 1422 static int 1493 1423 in_rq_cur(struct usb_function *fn, const struct usb_ctrlrequest *cr) 1494 1424 { ··· 1509 1423 u8 entity_id = (w_index >> 8) & 0xff; 1510 1424 u8 control_selector = w_value >> 8; 1511 1425 int value = -EOPNOTSUPP; 1512 - int p_srate, c_srate; 1426 + u32 p_srate, c_srate; 1513 1427 1514 - p_srate = opts->p_srate; 1515 - c_srate = opts->c_srate; 1428 + u_audio_get_playback_srate(agdev, &p_srate); 1429 + u_audio_get_capture_srate(agdev, &c_srate); 1516 1430 1517 1431 if ((entity_id == USB_IN_CLK_ID) || (entity_id == USB_OUT_CLK_ID)) { 1518 1432 if (control_selector == UAC2_CS_CONTROL_SAM_FREQ) { ··· 1586 1500 u8 entity_id = (w_index >> 8) & 0xff; 1587 1501 u8 control_selector = w_value >> 8; 1588 1502 int value = -EOPNOTSUPP; 1589 - int p_srate, c_srate; 1590 - 1591 - p_srate = opts->p_srate; 1592 - c_srate = opts->c_srate; 1593 1503 1594 1504 if ((entity_id == USB_IN_CLK_ID) || (entity_id == USB_OUT_CLK_ID)) { 1595 1505 if (control_selector == UAC2_CS_CONTROL_SAM_FREQ) { 1596 - struct cntrl_range_lay3 r; 1506 + struct cntrl_ranges_lay3_srates rs; 1507 + int i; 1508 + int wNumSubRanges = 0; 1509 + int srate; 1510 + int *srates; 1597 1511 1598 1512 if (entity_id == USB_IN_CLK_ID) 1599 - r.dMIN = cpu_to_le32(p_srate); 1513 + srates = opts->p_srates; 1600 1514 else if (entity_id == USB_OUT_CLK_ID) 1601 - r.dMIN = cpu_to_le32(c_srate); 1515 + srates = opts->c_srates; 1602 1516 else 1603 1517 return -EOPNOTSUPP; 1518 + for (i = 0; i < UAC_MAX_RATES; i++) { 1519 + srate = srates[i]; 1520 + if (srate == 0) 1521 + break; 1604 1522 1605 - r.dMAX = r.dMIN; 1606 - r.dRES = 0; 1607 - r.wNumSubRanges = cpu_to_le16(1); 1608 - 1609 - value = min_t(unsigned int, w_length, sizeof(r)); 1610 - memcpy(req->buf, &r, value); 1523 + rs.r[wNumSubRanges].dMIN = cpu_to_le32(srate); 1524 + rs.r[wNumSubRanges].dMAX = cpu_to_le32(srate); 1525 + rs.r[wNumSubRanges].dRES = 0; 1526 + wNumSubRanges++; 1527 + dev_dbg(&agdev->gadget->dev, 1528 + "%s(): clk %d: rate ID %d: %d\n", 1529 + __func__, entity_id, wNumSubRanges, srate); 1530 + } 1531 + rs.wNumSubRanges = cpu_to_le16(wNumSubRanges); 1532 + value = min_t(unsigned int, w_length, ranges_lay3_size(rs)); 1533 + dev_dbg(&agdev->gadget->dev, "%s(): sending %d rates, size %d\n", 1534 + __func__, rs.wNumSubRanges, value); 1535 + memcpy(req->buf, &rs, value); 1611 1536 } else { 1612 1537 dev_err(&agdev->gadget->dev, 1613 1538 "%s:%d control_selector=%d TODO!\n", ··· 1677 1580 return -EOPNOTSUPP; 1678 1581 } 1679 1582 1583 + static void uac2_cs_control_sam_freq(struct usb_ep *ep, struct usb_request *req) 1584 + { 1585 + struct usb_function *fn = ep->driver_data; 1586 + struct g_audio *agdev = func_to_g_audio(fn); 1587 + struct f_uac2 *uac2 = func_to_uac2(fn); 1588 + u32 val; 1589 + 1590 + if (req->actual != 4) 1591 + return; 1592 + 1593 + val = le32_to_cpu(*((__le32 *)req->buf)); 1594 + dev_dbg(&agdev->gadget->dev, "%s val: %d.\n", __func__, val); 1595 + if (uac2->clock_id == USB_IN_CLK_ID) { 1596 + u_audio_set_playback_srate(agdev, val); 1597 + } else if (uac2->clock_id == USB_OUT_CLK_ID) { 1598 + u_audio_set_capture_srate(agdev, val); 1599 + } 1600 + } 1601 + 1680 1602 static void 1681 1603 out_rq_cur_complete(struct usb_ep *ep, struct usb_request *req) 1682 1604 { ··· 1747 1631 static int 1748 1632 out_rq_cur(struct usb_function *fn, const struct usb_ctrlrequest *cr) 1749 1633 { 1634 + struct usb_composite_dev *cdev = fn->config->cdev; 1750 1635 struct usb_request *req = fn->config->cdev->req; 1751 1636 struct g_audio *agdev = func_to_g_audio(fn); 1752 1637 struct f_uac2_opts *opts = g_audio_to_uac2_opts(agdev); ··· 1757 1640 u16 w_value = le16_to_cpu(cr->wValue); 1758 1641 u8 entity_id = (w_index >> 8) & 0xff; 1759 1642 u8 control_selector = w_value >> 8; 1643 + u8 clock_id = w_index >> 8; 1760 1644 1761 1645 if ((entity_id == USB_IN_CLK_ID) || (entity_id == USB_OUT_CLK_ID)) { 1762 - if (control_selector == UAC2_CS_CONTROL_SAM_FREQ) 1646 + if (control_selector == UAC2_CS_CONTROL_SAM_FREQ) { 1647 + dev_dbg(&agdev->gadget->dev, 1648 + "control_selector UAC2_CS_CONTROL_SAM_FREQ, clock: %d\n", clock_id); 1649 + cdev->gadget->ep0->driver_data = fn; 1650 + uac2->clock_id = clock_id; 1651 + req->complete = uac2_cs_control_sam_freq; 1763 1652 return w_length; 1653 + } 1764 1654 } else if ((FUIN_EN(opts) && (entity_id == USB_IN_FU_ID)) || 1765 1655 (FUOUT_EN(opts) && (entity_id == USB_OUT_FU_ID))) { 1766 1656 memcpy(&uac2->setup_cr, cr, sizeof(*cr)); ··· 1855 1731 .release = f_uac2_attr_release, 1856 1732 }; 1857 1733 1734 + #define uac2_kstrtou8 kstrtou8 1858 1735 #define uac2_kstrtou32 kstrtou32 1859 1736 #define uac2_kstrtos16 kstrtos16 1860 1737 #define uac2_kstrtobool(s, base, res) kstrtobool((s), (res)) 1861 1738 1739 + static const char *u8_fmt = "%u\n"; 1862 1740 static const char *u32_fmt = "%u\n"; 1863 1741 static const char *s16_fmt = "%hd\n"; 1864 1742 static const char *bool_fmt = "%u\n"; ··· 1962 1836 \ 1963 1837 CONFIGFS_ATTR(f_uac2_opts_, name) 1964 1838 1839 + #define UAC2_RATE_ATTRIBUTE(name) \ 1840 + static ssize_t f_uac2_opts_##name##_show(struct config_item *item, \ 1841 + char *page) \ 1842 + { \ 1843 + struct f_uac2_opts *opts = to_f_uac2_opts(item); \ 1844 + int result = 0; \ 1845 + int i; \ 1846 + \ 1847 + mutex_lock(&opts->lock); \ 1848 + page[0] = '\0'; \ 1849 + for (i = 0; i < UAC_MAX_RATES; i++) { \ 1850 + if (opts->name##s[i] == 0) \ 1851 + break; \ 1852 + result += sprintf(page + strlen(page), "%u,", \ 1853 + opts->name##s[i]); \ 1854 + } \ 1855 + if (strlen(page) > 0) \ 1856 + page[strlen(page) - 1] = '\n'; \ 1857 + mutex_unlock(&opts->lock); \ 1858 + \ 1859 + return result; \ 1860 + } \ 1861 + \ 1862 + static ssize_t f_uac2_opts_##name##_store(struct config_item *item, \ 1863 + const char *page, size_t len) \ 1864 + { \ 1865 + struct f_uac2_opts *opts = to_f_uac2_opts(item); \ 1866 + char *split_page = NULL; \ 1867 + int ret = -EINVAL; \ 1868 + char *token; \ 1869 + u32 num; \ 1870 + int i; \ 1871 + \ 1872 + mutex_lock(&opts->lock); \ 1873 + if (opts->refcnt) { \ 1874 + ret = -EBUSY; \ 1875 + goto end; \ 1876 + } \ 1877 + \ 1878 + i = 0; \ 1879 + memset(opts->name##s, 0x00, sizeof(opts->name##s)); \ 1880 + split_page = kstrdup(page, GFP_KERNEL); \ 1881 + while ((token = strsep(&split_page, ",")) != NULL) { \ 1882 + ret = kstrtou32(token, 0, &num); \ 1883 + if (ret) \ 1884 + goto end; \ 1885 + \ 1886 + opts->name##s[i++] = num; \ 1887 + ret = len; \ 1888 + }; \ 1889 + \ 1890 + end: \ 1891 + kfree(split_page); \ 1892 + mutex_unlock(&opts->lock); \ 1893 + return ret; \ 1894 + } \ 1895 + \ 1896 + CONFIGFS_ATTR(f_uac2_opts_, name) 1897 + 1898 + #define UAC2_ATTRIBUTE_STRING(name) \ 1899 + static ssize_t f_uac2_opts_##name##_show(struct config_item *item, \ 1900 + char *page) \ 1901 + { \ 1902 + struct f_uac2_opts *opts = to_f_uac2_opts(item); \ 1903 + int result; \ 1904 + \ 1905 + mutex_lock(&opts->lock); \ 1906 + result = snprintf(page, sizeof(opts->name), "%s", opts->name); \ 1907 + mutex_unlock(&opts->lock); \ 1908 + \ 1909 + return result; \ 1910 + } \ 1911 + \ 1912 + static ssize_t f_uac2_opts_##name##_store(struct config_item *item, \ 1913 + const char *page, size_t len) \ 1914 + { \ 1915 + struct f_uac2_opts *opts = to_f_uac2_opts(item); \ 1916 + int ret = 0; \ 1917 + \ 1918 + mutex_lock(&opts->lock); \ 1919 + if (opts->refcnt) { \ 1920 + ret = -EBUSY; \ 1921 + goto end; \ 1922 + } \ 1923 + \ 1924 + ret = snprintf(opts->name, min(sizeof(opts->name), len), \ 1925 + "%s", page); \ 1926 + \ 1927 + end: \ 1928 + mutex_unlock(&opts->lock); \ 1929 + return ret; \ 1930 + } \ 1931 + \ 1932 + CONFIGFS_ATTR(f_uac2_opts_, name) 1933 + 1965 1934 UAC2_ATTRIBUTE(u32, p_chmask); 1966 - UAC2_ATTRIBUTE(u32, p_srate); 1935 + UAC2_RATE_ATTRIBUTE(p_srate); 1967 1936 UAC2_ATTRIBUTE(u32, p_ssize); 1937 + UAC2_ATTRIBUTE(u8, p_hs_bint); 1968 1938 UAC2_ATTRIBUTE(u32, c_chmask); 1969 - UAC2_ATTRIBUTE(u32, c_srate); 1939 + UAC2_RATE_ATTRIBUTE(c_srate); 1970 1940 UAC2_ATTRIBUTE_SYNC(c_sync); 1971 1941 UAC2_ATTRIBUTE(u32, c_ssize); 1942 + UAC2_ATTRIBUTE(u8, c_hs_bint); 1972 1943 UAC2_ATTRIBUTE(u32, req_number); 1973 1944 1974 1945 UAC2_ATTRIBUTE(bool, p_mute_present); ··· 2080 1857 UAC2_ATTRIBUTE(s16, c_volume_max); 2081 1858 UAC2_ATTRIBUTE(s16, c_volume_res); 2082 1859 UAC2_ATTRIBUTE(u32, fb_max); 1860 + UAC2_ATTRIBUTE_STRING(function_name); 2083 1861 2084 1862 static struct configfs_attribute *f_uac2_attrs[] = { 2085 1863 &f_uac2_opts_attr_p_chmask, 2086 1864 &f_uac2_opts_attr_p_srate, 2087 1865 &f_uac2_opts_attr_p_ssize, 1866 + &f_uac2_opts_attr_p_hs_bint, 2088 1867 &f_uac2_opts_attr_c_chmask, 2089 1868 &f_uac2_opts_attr_c_srate, 2090 1869 &f_uac2_opts_attr_c_ssize, 1870 + &f_uac2_opts_attr_c_hs_bint, 2091 1871 &f_uac2_opts_attr_c_sync, 2092 1872 &f_uac2_opts_attr_req_number, 2093 1873 &f_uac2_opts_attr_fb_max, ··· 2106 1880 &f_uac2_opts_attr_c_volume_min, 2107 1881 &f_uac2_opts_attr_c_volume_max, 2108 1882 &f_uac2_opts_attr_c_volume_res, 1883 + 1884 + &f_uac2_opts_attr_function_name, 2109 1885 2110 1886 NULL, 2111 1887 }; ··· 2141 1913 &f_uac2_func_type); 2142 1914 2143 1915 opts->p_chmask = UAC2_DEF_PCHMASK; 2144 - opts->p_srate = UAC2_DEF_PSRATE; 1916 + opts->p_srates[0] = UAC2_DEF_PSRATE; 2145 1917 opts->p_ssize = UAC2_DEF_PSSIZE; 1918 + opts->p_hs_bint = UAC2_DEF_PHSBINT; 2146 1919 opts->c_chmask = UAC2_DEF_CCHMASK; 2147 - opts->c_srate = UAC2_DEF_CSRATE; 1920 + opts->c_srates[0] = UAC2_DEF_CSRATE; 2148 1921 opts->c_ssize = UAC2_DEF_CSSIZE; 1922 + opts->c_hs_bint = UAC2_DEF_CHSBINT; 2149 1923 opts->c_sync = UAC2_DEF_CSYNC; 2150 1924 2151 1925 opts->p_mute_present = UAC2_DEF_MUTE_PRESENT; ··· 2164 1934 2165 1935 opts->req_number = UAC2_DEF_REQ_NUM; 2166 1936 opts->fb_max = FBACK_FAST_MAX; 1937 + 1938 + snprintf(opts->function_name, sizeof(opts->function_name), "Source/Sink"); 1939 + 2167 1940 return &opts->func_inst; 2168 1941 } 2169 1942 ··· 2218 1985 uac2->g_audio.func.set_alt = afunc_set_alt; 2219 1986 uac2->g_audio.func.get_alt = afunc_get_alt; 2220 1987 uac2->g_audio.func.disable = afunc_disable; 1988 + uac2->g_audio.func.suspend = afunc_suspend; 2221 1989 uac2->g_audio.func.setup = afunc_setup; 2222 1990 uac2->g_audio.func.free_func = afunc_free; 2223 1991
+218 -20
drivers/usb/gadget/function/u_audio.c
··· 32 32 UAC_P_PITCH_CTRL, 33 33 UAC_MUTE_CTRL, 34 34 UAC_VOLUME_CTRL, 35 + UAC_RATE_CTRL, 35 36 }; 36 37 37 38 /* Runtime data params for one stream */ ··· 62 61 s16 volume_min, volume_max, volume_res; 63 62 s16 volume; 64 63 int mute; 64 + 65 + struct snd_kcontrol *snd_kctl_rate; /* read-only current rate */ 66 + int srate; /* selected samplerate */ 67 + int active; /* playback/capture running */ 65 68 66 69 spinlock_t lock; /* lock for control transfers */ 67 70 ··· 155 150 struct snd_pcm_runtime *runtime; 156 151 struct uac_rtd_params *prm = req->context; 157 152 struct snd_uac_chip *uac = prm->uac; 158 - struct g_audio *audio_dev = uac->audio_dev; 159 - struct uac_params *params = &audio_dev->params; 160 153 unsigned int frames, p_pktsize; 161 154 unsigned long long pitched_rate_mil, p_pktsize_residue_mil, 162 155 residue_frames_mil, div_result; ··· 199 196 */ 200 197 unsigned long long p_interval_mil = uac->p_interval * 1000000ULL; 201 198 202 - pitched_rate_mil = (unsigned long long) 203 - params->p_srate * prm->pitch; 199 + pitched_rate_mil = (unsigned long long) prm->srate * prm->pitch; 204 200 div_result = pitched_rate_mil; 205 201 do_div(div_result, uac->p_interval); 206 202 do_div(div_result, 1000000); 207 203 frames = (unsigned int) div_result; 208 204 209 205 pr_debug("p_srate %d, pitch %d, interval_mil %llu, frames %d\n", 210 - params->p_srate, prm->pitch, p_interval_mil, frames); 206 + prm->srate, prm->pitch, p_interval_mil, frames); 211 207 212 208 p_pktsize = min_t(unsigned int, 213 209 uac->p_framesize * frames, ··· 283 281 struct uac_rtd_params *prm = req->context; 284 282 struct snd_uac_chip *uac = prm->uac; 285 283 struct g_audio *audio_dev = uac->audio_dev; 286 - struct uac_params *params = &audio_dev->params; 287 284 int status = req->status; 288 285 289 286 /* i/f shutting down */ ··· 304 303 __func__, status, req->actual, req->length); 305 304 306 305 u_audio_set_fback_frequency(audio_dev->gadget->speed, audio_dev->out_ep, 307 - params->c_srate, prm->pitch, 306 + prm->srate, prm->pitch, 308 307 req->buf); 309 308 310 309 if (usb_ep_queue(ep, req, GFP_ATOMIC)) ··· 388 387 struct snd_pcm_runtime *runtime = substream->runtime; 389 388 struct g_audio *audio_dev; 390 389 struct uac_params *params; 390 + struct uac_rtd_params *prm; 391 391 int p_ssize, c_ssize; 392 - int p_srate, c_srate; 393 392 int p_chmask, c_chmask; 394 393 395 394 audio_dev = uac->audio_dev; 396 395 params = &audio_dev->params; 397 396 p_ssize = params->p_ssize; 398 397 c_ssize = params->c_ssize; 399 - p_srate = params->p_srate; 400 - c_srate = params->c_srate; 401 398 p_chmask = params->p_chmask; 402 399 c_chmask = params->c_chmask; 403 400 uac->p_residue_mil = 0; ··· 403 404 runtime->hw = uac_pcm_hardware; 404 405 405 406 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { 406 - runtime->hw.rate_min = p_srate; 407 407 runtime->hw.formats = uac_ssize_to_fmt(p_ssize); 408 408 runtime->hw.channels_min = num_channels(p_chmask); 409 - runtime->hw.period_bytes_min = 2 * uac->p_prm.max_psize 410 - / runtime->hw.periods_min; 409 + prm = &uac->p_prm; 411 410 } else { 412 - runtime->hw.rate_min = c_srate; 413 411 runtime->hw.formats = uac_ssize_to_fmt(c_ssize); 414 412 runtime->hw.channels_min = num_channels(c_chmask); 415 - runtime->hw.period_bytes_min = 2 * uac->c_prm.max_psize 416 - / runtime->hw.periods_min; 413 + prm = &uac->c_prm; 417 414 } 418 415 416 + runtime->hw.period_bytes_min = 2 * prm->max_psize 417 + / runtime->hw.periods_min; 418 + runtime->hw.rate_min = prm->srate; 419 419 runtime->hw.rate_max = runtime->hw.rate_min; 420 420 runtime->hw.channels_max = runtime->hw.channels_min; 421 421 ··· 491 493 dev_err(uac->card->dev, "%s:%d Error!\n", __func__, __LINE__); 492 494 } 493 495 496 + static void set_active(struct uac_rtd_params *prm, bool active) 497 + { 498 + // notifying through the Rate ctrl 499 + struct snd_kcontrol *kctl = prm->snd_kctl_rate; 500 + unsigned long flags; 501 + 502 + spin_lock_irqsave(&prm->lock, flags); 503 + if (prm->active != active) { 504 + prm->active = active; 505 + snd_ctl_notify(prm->uac->card, SNDRV_CTL_EVENT_MASK_VALUE, 506 + &kctl->id); 507 + } 508 + spin_unlock_irqrestore(&prm->lock, flags); 509 + } 510 + 511 + int u_audio_set_capture_srate(struct g_audio *audio_dev, int srate) 512 + { 513 + struct uac_params *params = &audio_dev->params; 514 + struct snd_uac_chip *uac = audio_dev->uac; 515 + struct uac_rtd_params *prm; 516 + int i; 517 + unsigned long flags; 518 + 519 + dev_dbg(&audio_dev->gadget->dev, "%s: srate %d\n", __func__, srate); 520 + prm = &uac->c_prm; 521 + for (i = 0; i < UAC_MAX_RATES; i++) { 522 + if (params->c_srates[i] == srate) { 523 + spin_lock_irqsave(&prm->lock, flags); 524 + prm->srate = srate; 525 + spin_unlock_irqrestore(&prm->lock, flags); 526 + return 0; 527 + } 528 + if (params->c_srates[i] == 0) 529 + break; 530 + } 531 + 532 + return -EINVAL; 533 + } 534 + EXPORT_SYMBOL_GPL(u_audio_set_capture_srate); 535 + 536 + int u_audio_get_capture_srate(struct g_audio *audio_dev, u32 *val) 537 + { 538 + struct snd_uac_chip *uac = audio_dev->uac; 539 + struct uac_rtd_params *prm; 540 + unsigned long flags; 541 + 542 + prm = &uac->c_prm; 543 + spin_lock_irqsave(&prm->lock, flags); 544 + *val = prm->srate; 545 + spin_unlock_irqrestore(&prm->lock, flags); 546 + return 0; 547 + } 548 + EXPORT_SYMBOL_GPL(u_audio_get_capture_srate); 549 + 550 + int u_audio_set_playback_srate(struct g_audio *audio_dev, int srate) 551 + { 552 + struct uac_params *params = &audio_dev->params; 553 + struct snd_uac_chip *uac = audio_dev->uac; 554 + struct uac_rtd_params *prm; 555 + int i; 556 + unsigned long flags; 557 + 558 + dev_dbg(&audio_dev->gadget->dev, "%s: srate %d\n", __func__, srate); 559 + prm = &uac->p_prm; 560 + for (i = 0; i < UAC_MAX_RATES; i++) { 561 + if (params->p_srates[i] == srate) { 562 + spin_lock_irqsave(&prm->lock, flags); 563 + prm->srate = srate; 564 + spin_unlock_irqrestore(&prm->lock, flags); 565 + return 0; 566 + } 567 + if (params->p_srates[i] == 0) 568 + break; 569 + } 570 + 571 + return -EINVAL; 572 + } 573 + EXPORT_SYMBOL_GPL(u_audio_set_playback_srate); 574 + 575 + int u_audio_get_playback_srate(struct g_audio *audio_dev, u32 *val) 576 + { 577 + struct snd_uac_chip *uac = audio_dev->uac; 578 + struct uac_rtd_params *prm; 579 + unsigned long flags; 580 + 581 + prm = &uac->p_prm; 582 + spin_lock_irqsave(&prm->lock, flags); 583 + *val = prm->srate; 584 + spin_unlock_irqrestore(&prm->lock, flags); 585 + return 0; 586 + } 587 + EXPORT_SYMBOL_GPL(u_audio_get_playback_srate); 588 + 494 589 int u_audio_start_capture(struct g_audio *audio_dev) 495 590 { 496 591 struct snd_uac_chip *uac = audio_dev->uac; ··· 595 504 struct uac_params *params = &audio_dev->params; 596 505 int req_len, i; 597 506 598 - ep = audio_dev->out_ep; 599 507 prm = &uac->c_prm; 508 + dev_dbg(dev, "start capture with rate %d\n", prm->srate); 509 + ep = audio_dev->out_ep; 600 510 config_ep_by_speed(gadget, &audio_dev->func, ep); 601 511 req_len = ep->maxpacket; 602 512 ··· 622 530 if (usb_ep_queue(ep, prm->reqs[i], GFP_ATOMIC)) 623 531 dev_err(dev, "%s:%d Error!\n", __func__, __LINE__); 624 532 } 533 + 534 + set_active(&uac->c_prm, true); 625 535 626 536 ep_fback = audio_dev->in_ep_fback; 627 537 if (!ep_fback) ··· 656 562 */ 657 563 prm->pitch = 1000000; 658 564 u_audio_set_fback_frequency(audio_dev->gadget->speed, ep, 659 - params->c_srate, prm->pitch, 565 + prm->srate, prm->pitch, 660 566 req_fback->buf); 661 567 662 568 if (usb_ep_queue(ep_fback, req_fback, GFP_ATOMIC)) ··· 670 576 { 671 577 struct snd_uac_chip *uac = audio_dev->uac; 672 578 579 + set_active(&uac->c_prm, false); 673 580 if (audio_dev->in_ep_fback) 674 581 free_ep_fback(&uac->c_prm, audio_dev->in_ep_fback); 675 582 free_ep(&uac->c_prm, audio_dev->out_ep); ··· 691 596 int req_len, i; 692 597 unsigned int p_pktsize; 693 598 694 - ep = audio_dev->in_ep; 695 599 prm = &uac->p_prm; 600 + dev_dbg(dev, "start playback with rate %d\n", prm->srate); 601 + ep = audio_dev->in_ep; 696 602 config_ep_by_speed(gadget, &audio_dev->func, ep); 697 603 698 604 ep_desc = ep->desc; ··· 714 618 uac->p_interval = factor / (1 << (ep_desc->bInterval - 1)); 715 619 p_pktsize = min_t(unsigned int, 716 620 uac->p_framesize * 717 - (params->p_srate / uac->p_interval), 621 + (prm->srate / uac->p_interval), 718 622 ep->maxpacket); 719 623 720 624 req_len = p_pktsize; ··· 742 646 dev_err(dev, "%s:%d Error!\n", __func__, __LINE__); 743 647 } 744 648 649 + set_active(&uac->p_prm, true); 650 + 745 651 return 0; 746 652 } 747 653 EXPORT_SYMBOL_GPL(u_audio_start_playback); ··· 752 654 { 753 655 struct snd_uac_chip *uac = audio_dev->uac; 754 656 657 + set_active(&uac->p_prm, false); 755 658 free_ep(&uac->p_prm, audio_dev->in_ep); 756 659 } 757 660 EXPORT_SYMBOL_GPL(u_audio_stop_playback); 661 + 662 + void u_audio_suspend(struct g_audio *audio_dev) 663 + { 664 + struct snd_uac_chip *uac = audio_dev->uac; 665 + 666 + set_active(&uac->p_prm, false); 667 + set_active(&uac->c_prm, false); 668 + } 669 + EXPORT_SYMBOL_GPL(u_audio_suspend); 758 670 759 671 int u_audio_get_volume(struct g_audio *audio_dev, int playback, s16 *val) 760 672 { ··· 1051 943 return change; 1052 944 } 1053 945 946 + static int get_max_srate(const int *srates) 947 + { 948 + int i, max_srate = 0; 949 + 950 + for (i = 0; i < UAC_MAX_RATES; i++) { 951 + if (srates[i] == 0) 952 + break; 953 + if (srates[i] > max_srate) 954 + max_srate = srates[i]; 955 + } 956 + return max_srate; 957 + } 958 + 959 + static int get_min_srate(const int *srates) 960 + { 961 + int i, min_srate = INT_MAX; 962 + 963 + for (i = 0; i < UAC_MAX_RATES; i++) { 964 + if (srates[i] == 0) 965 + break; 966 + if (srates[i] < min_srate) 967 + min_srate = srates[i]; 968 + } 969 + return min_srate; 970 + } 971 + 972 + static int u_audio_rate_info(struct snd_kcontrol *kcontrol, 973 + struct snd_ctl_elem_info *uinfo) 974 + { 975 + const int *srates; 976 + struct uac_rtd_params *prm = snd_kcontrol_chip(kcontrol); 977 + struct snd_uac_chip *uac = prm->uac; 978 + struct g_audio *audio_dev = uac->audio_dev; 979 + struct uac_params *params = &audio_dev->params; 980 + 981 + uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 982 + uinfo->count = 1; 983 + 984 + if (prm == &uac->c_prm) 985 + srates = params->c_srates; 986 + else 987 + srates = params->p_srates; 988 + uinfo->value.integer.min = get_min_srate(srates); 989 + uinfo->value.integer.max = get_max_srate(srates); 990 + return 0; 991 + } 992 + 993 + static int u_audio_rate_get(struct snd_kcontrol *kcontrol, 994 + struct snd_ctl_elem_value *ucontrol) 995 + { 996 + struct uac_rtd_params *prm = snd_kcontrol_chip(kcontrol); 997 + unsigned long flags; 998 + 999 + spin_lock_irqsave(&prm->lock, flags); 1000 + if (prm->active) 1001 + ucontrol->value.integer.value[0] = prm->srate; 1002 + else 1003 + /* not active: reporting zero rate */ 1004 + ucontrol->value.integer.value[0] = 0; 1005 + spin_unlock_irqrestore(&prm->lock, flags); 1006 + return 0; 1007 + } 1054 1008 1055 1009 static struct snd_kcontrol_new u_audio_controls[] = { 1056 1010 [UAC_FBACK_CTRL] { ··· 1142 972 .info = u_audio_volume_info, 1143 973 .get = u_audio_volume_get, 1144 974 .put = u_audio_volume_put, 975 + }, 976 + [UAC_RATE_CTRL] { 977 + .iface = SNDRV_CTL_ELEM_IFACE_PCM, 978 + .name = "", /* will be filled later */ 979 + .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, 980 + .info = u_audio_rate_info, 981 + .get = u_audio_rate_get, 1145 982 }, 1146 983 }; 1147 984 ··· 1182 1005 spin_lock_init(&prm->lock); 1183 1006 uac->c_prm.uac = uac; 1184 1007 prm->max_psize = g_audio->out_ep_maxpsize; 1008 + prm->srate = params->c_srates[0]; 1185 1009 1186 1010 prm->reqs = kcalloc(params->req_number, 1187 1011 sizeof(struct usb_request *), ··· 1207 1029 spin_lock_init(&prm->lock); 1208 1030 uac->p_prm.uac = uac; 1209 1031 prm->max_psize = g_audio->in_ep_maxpsize; 1032 + prm->srate = params->p_srates[0]; 1210 1033 1211 1034 prm->reqs = kcalloc(params->req_number, 1212 1035 sizeof(struct usb_request *), ··· 1365 1186 prm->volume_min = fu->volume_min; 1366 1187 prm->volume_res = fu->volume_res; 1367 1188 } 1189 + 1190 + /* Add rate control */ 1191 + snprintf(ctrl_name, sizeof(ctrl_name), 1192 + "%s Rate", direction); 1193 + u_audio_controls[UAC_RATE_CTRL].name = ctrl_name; 1194 + 1195 + kctl = snd_ctl_new1(&u_audio_controls[UAC_RATE_CTRL], prm); 1196 + if (!kctl) { 1197 + err = -ENOMEM; 1198 + goto snd_fail; 1199 + } 1200 + 1201 + kctl->id.device = pcm->device; 1202 + kctl->id.subdevice = 0; 1203 + 1204 + err = snd_ctl_add(card, kctl); 1205 + if (err < 0) 1206 + goto snd_fail; 1207 + prm->snd_kctl_rate = kctl; 1368 1208 } 1369 1209 1370 1210 strscpy(card->driver, card_name, sizeof(card->driver));
+12 -2
drivers/usb/gadget/function/u_audio.h
··· 10 10 #define __U_AUDIO_H 11 11 12 12 #include <linux/usb/composite.h> 13 + #include "uac_common.h" 13 14 14 15 /* 15 16 * Same maximum frequency deviation on the slower side as in ··· 41 40 struct uac_params { 42 41 /* playback */ 43 42 int p_chmask; /* channel mask */ 44 - int p_srate; /* rate in Hz */ 43 + int p_srates[UAC_MAX_RATES]; /* available rates in Hz (0 terminated list) */ 45 44 int p_ssize; /* sample size */ 46 45 struct uac_fu_params p_fu; /* Feature Unit parameters */ 47 46 48 47 /* capture */ 49 48 int c_chmask; /* channel mask */ 50 - int c_srate; /* rate in Hz */ 49 + int c_srates[UAC_MAX_RATES]; /* available rates in Hz (0 terminated list) */ 51 50 int c_ssize; /* sample size */ 52 51 struct uac_fu_params c_fu; /* Feature Unit parameters */ 52 + 53 + /* rates are dynamic, in uac_rtd_params */ 53 54 54 55 int req_number; /* number of preallocated requests */ 55 56 int fb_max; /* upper frequency drift feedback limit per-mil */ ··· 120 117 int u_audio_start_playback(struct g_audio *g_audio); 121 118 void u_audio_stop_playback(struct g_audio *g_audio); 122 119 120 + int u_audio_get_capture_srate(struct g_audio *audio_dev, u32 *val); 121 + int u_audio_set_capture_srate(struct g_audio *audio_dev, int srate); 122 + int u_audio_get_playback_srate(struct g_audio *audio_dev, u32 *val); 123 + int u_audio_set_playback_srate(struct g_audio *audio_dev, int srate); 124 + 123 125 int u_audio_get_volume(struct g_audio *g_audio, int playback, s16 *val); 124 126 int u_audio_set_volume(struct g_audio *g_audio, int playback, s16 val); 125 127 int u_audio_get_mute(struct g_audio *g_audio, int playback, int *val); 126 128 int u_audio_set_mute(struct g_audio *g_audio, int playback, int val); 129 + 130 + void u_audio_suspend(struct g_audio *g_audio); 127 131 128 132 #endif /* __U_AUDIO_H */
+5 -2
drivers/usb/gadget/function/u_uac1.h
··· 9 9 #define __U_UAC1_H 10 10 11 11 #include <linux/usb/composite.h> 12 + #include "uac_common.h" 12 13 13 14 #define UAC1_OUT_EP_MAX_PACKET_SIZE 200 14 15 #define UAC1_DEF_CCHMASK 0x3 ··· 31 30 struct f_uac1_opts { 32 31 struct usb_function_instance func_inst; 33 32 int c_chmask; 34 - int c_srate; 33 + int c_srates[UAC_MAX_RATES]; 35 34 int c_ssize; 36 35 int p_chmask; 37 - int p_srate; 36 + int p_srates[UAC_MAX_RATES]; 38 37 int p_ssize; 39 38 40 39 bool p_mute_present; ··· 51 50 52 51 int req_number; 53 52 unsigned bound:1; 53 + 54 + char function_name[32]; 54 55 55 56 struct mutex lock; 56 57 int refcnt;
+9 -2
drivers/usb/gadget/function/u_uac2.h
··· 14 14 #define U_UAC2_H 15 15 16 16 #include <linux/usb/composite.h> 17 + #include "uac_common.h" 17 18 18 19 #define UAC2_DEF_PCHMASK 0x3 19 20 #define UAC2_DEF_PSRATE 48000 20 21 #define UAC2_DEF_PSSIZE 2 22 + #define UAC2_DEF_PHSBINT 0 21 23 #define UAC2_DEF_CCHMASK 0x3 22 24 #define UAC2_DEF_CSRATE 64000 23 25 #define UAC2_DEF_CSSIZE 2 26 + #define UAC2_DEF_CHSBINT 0 24 27 #define UAC2_DEF_CSYNC USB_ENDPOINT_SYNC_ASYNC 25 28 26 29 #define UAC2_DEF_MUTE_PRESENT 1 ··· 38 35 struct f_uac2_opts { 39 36 struct usb_function_instance func_inst; 40 37 int p_chmask; 41 - int p_srate; 38 + int p_srates[UAC_MAX_RATES]; 42 39 int p_ssize; 40 + u8 p_hs_bint; 43 41 int c_chmask; 44 - int c_srate; 42 + int c_srates[UAC_MAX_RATES]; 45 43 int c_ssize; 46 44 int c_sync; 45 + u8 c_hs_bint; 47 46 48 47 bool p_mute_present; 49 48 bool p_volume_present; ··· 62 57 int req_number; 63 58 int fb_max; 64 59 bool bound; 60 + 61 + char function_name[32]; 65 62 66 63 struct mutex lock; 67 64 int refcnt;
+9
drivers/usb/gadget/function/uac_common.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0+ */ 2 + /* 3 + */ 4 + 5 + #ifndef UAC_COMMON_H 6 + #define UAC_COMMON_H 7 + 8 + #define UAC_MAX_RATES 10 /* maximum number of rates configurable by f_uac1/2 */ 9 + #endif
+63 -30
drivers/usb/gadget/legacy/audio.c
··· 22 22 23 23 /* Playback(USB-IN) Default Stereo - Fl/Fr */ 24 24 static int p_chmask = UAC2_DEF_PCHMASK; 25 - module_param(p_chmask, uint, S_IRUGO); 25 + module_param(p_chmask, uint, 0444); 26 26 MODULE_PARM_DESC(p_chmask, "Playback Channel Mask"); 27 27 28 28 /* Playback Default 48 KHz */ 29 - static int p_srate = UAC2_DEF_PSRATE; 30 - module_param(p_srate, uint, S_IRUGO); 31 - MODULE_PARM_DESC(p_srate, "Playback Sampling Rate"); 29 + static int p_srates[UAC_MAX_RATES] = {UAC2_DEF_PSRATE}; 30 + static int p_srates_cnt = 1; 31 + module_param_array_named(p_srate, p_srates, uint, &p_srates_cnt, 0444); 32 + MODULE_PARM_DESC(p_srate, "Playback Sampling Rates (array)"); 32 33 33 34 /* Playback Default 16bits/sample */ 34 35 static int p_ssize = UAC2_DEF_PSSIZE; 35 - module_param(p_ssize, uint, S_IRUGO); 36 + module_param(p_ssize, uint, 0444); 36 37 MODULE_PARM_DESC(p_ssize, "Playback Sample Size(bytes)"); 38 + 39 + /* Playback bInterval for HS/SS (1-4: fixed, 0: auto) */ 40 + static u8 p_hs_bint = UAC2_DEF_PHSBINT; 41 + module_param(p_hs_bint, byte, 0444); 42 + MODULE_PARM_DESC(p_hs_bint, 43 + "Playback bInterval for HS/SS (1-4: fixed, 0: auto)"); 37 44 38 45 /* Capture(USB-OUT) Default Stereo - Fl/Fr */ 39 46 static int c_chmask = UAC2_DEF_CCHMASK; 40 - module_param(c_chmask, uint, S_IRUGO); 47 + module_param(c_chmask, uint, 0444); 41 48 MODULE_PARM_DESC(c_chmask, "Capture Channel Mask"); 42 49 43 50 /* Capture Default 64 KHz */ 44 - static int c_srate = UAC2_DEF_CSRATE; 45 - module_param(c_srate, uint, S_IRUGO); 46 - MODULE_PARM_DESC(c_srate, "Capture Sampling Rate"); 51 + static int c_srates[UAC_MAX_RATES] = {UAC2_DEF_CSRATE}; 52 + static int c_srates_cnt = 1; 53 + module_param_array_named(c_srate, c_srates, uint, &c_srates_cnt, 0444); 54 + MODULE_PARM_DESC(c_srate, "Capture Sampling Rates (array)"); 47 55 48 56 /* Capture Default 16bits/sample */ 49 57 static int c_ssize = UAC2_DEF_CSSIZE; 50 - module_param(c_ssize, uint, S_IRUGO); 58 + module_param(c_ssize, uint, 0444); 51 59 MODULE_PARM_DESC(c_ssize, "Capture Sample Size(bytes)"); 60 + 61 + /* capture bInterval for HS/SS (1-4: fixed, 0: auto) */ 62 + static u8 c_hs_bint = UAC2_DEF_CHSBINT; 63 + module_param(c_hs_bint, byte, 0444); 64 + MODULE_PARM_DESC(c_hs_bint, 65 + "Capture bInterval for HS/SS (1-4: fixed, 0: auto)"); 66 + 52 67 #else 53 68 #ifndef CONFIG_GADGET_UAC1_LEGACY 54 69 #include "u_uac1.h" 55 70 56 71 /* Playback(USB-IN) Default Stereo - Fl/Fr */ 57 72 static int p_chmask = UAC1_DEF_PCHMASK; 58 - module_param(p_chmask, uint, S_IRUGO); 73 + module_param(p_chmask, uint, 0444); 59 74 MODULE_PARM_DESC(p_chmask, "Playback Channel Mask"); 60 75 61 76 /* Playback Default 48 KHz */ 62 - static int p_srate = UAC1_DEF_PSRATE; 63 - module_param(p_srate, uint, S_IRUGO); 64 - MODULE_PARM_DESC(p_srate, "Playback Sampling Rate"); 77 + static int p_srates[UAC_MAX_RATES] = {UAC1_DEF_PSRATE}; 78 + static int p_srates_cnt = 1; 79 + module_param_array_named(p_srate, p_srates, uint, &p_srates_cnt, 0444); 80 + MODULE_PARM_DESC(p_srate, "Playback Sampling Rates (array)"); 65 81 66 82 /* Playback Default 16bits/sample */ 67 83 static int p_ssize = UAC1_DEF_PSSIZE; 68 - module_param(p_ssize, uint, S_IRUGO); 84 + module_param(p_ssize, uint, 0444); 69 85 MODULE_PARM_DESC(p_ssize, "Playback Sample Size(bytes)"); 70 86 71 87 /* Capture(USB-OUT) Default Stereo - Fl/Fr */ 72 88 static int c_chmask = UAC1_DEF_CCHMASK; 73 - module_param(c_chmask, uint, S_IRUGO); 89 + module_param(c_chmask, uint, 0444); 74 90 MODULE_PARM_DESC(c_chmask, "Capture Channel Mask"); 75 91 76 92 /* Capture Default 48 KHz */ 77 - static int c_srate = UAC1_DEF_CSRATE; 78 - module_param(c_srate, uint, S_IRUGO); 79 - MODULE_PARM_DESC(c_srate, "Capture Sampling Rate"); 93 + static int c_srates[UAC_MAX_RATES] = {UAC1_DEF_CSRATE}; 94 + static int c_srates_cnt = 1; 95 + module_param_array_named(c_srate, c_srates, uint, &c_srates_cnt, 0444); 96 + MODULE_PARM_DESC(c_srate, "Capture Sampling Rates (array)"); 80 97 81 98 /* Capture Default 16bits/sample */ 82 99 static int c_ssize = UAC1_DEF_CSSIZE; 83 - module_param(c_ssize, uint, S_IRUGO); 100 + module_param(c_ssize, uint, 0444); 84 101 MODULE_PARM_DESC(c_ssize, "Capture Sample Size(bytes)"); 85 102 #else /* CONFIG_GADGET_UAC1_LEGACY */ 86 103 #include "u_uac1_legacy.h" 87 104 88 105 static char *fn_play = FILE_PCM_PLAYBACK; 89 - module_param(fn_play, charp, S_IRUGO); 106 + module_param(fn_play, charp, 0444); 90 107 MODULE_PARM_DESC(fn_play, "Playback PCM device file name"); 91 108 92 109 static char *fn_cap = FILE_PCM_CAPTURE; 93 - module_param(fn_cap, charp, S_IRUGO); 110 + module_param(fn_cap, charp, 0444); 94 111 MODULE_PARM_DESC(fn_cap, "Capture PCM device file name"); 95 112 96 113 static char *fn_cntl = FILE_CONTROL; 97 - module_param(fn_cntl, charp, S_IRUGO); 114 + module_param(fn_cntl, charp, 0444); 98 115 MODULE_PARM_DESC(fn_cntl, "Control device file name"); 99 116 100 117 static int req_buf_size = UAC1_OUT_EP_MAX_PACKET_SIZE; 101 - module_param(req_buf_size, int, S_IRUGO); 118 + module_param(req_buf_size, int, 0444); 102 119 MODULE_PARM_DESC(req_buf_size, "ISO OUT endpoint request buffer size"); 103 120 104 121 static int req_count = UAC1_REQ_COUNT; 105 - module_param(req_count, int, S_IRUGO); 122 + module_param(req_count, int, 0444); 106 123 MODULE_PARM_DESC(req_count, "ISO OUT endpoint request count"); 107 124 108 125 static int audio_buf_size = UAC1_AUDIO_BUF_SIZE; 109 - module_param(audio_buf_size, int, S_IRUGO); 126 + module_param(audio_buf_size, int, 0444); 110 127 MODULE_PARM_DESC(audio_buf_size, "Audio buffer size"); 111 128 #endif /* CONFIG_GADGET_UAC1_LEGACY */ 112 129 #endif ··· 254 237 { 255 238 #ifndef CONFIG_GADGET_UAC1 256 239 struct f_uac2_opts *uac2_opts; 240 + int i; 257 241 #else 258 242 #ifndef CONFIG_GADGET_UAC1_LEGACY 259 243 struct f_uac1_opts *uac1_opts; 244 + int i; 260 245 #else 261 246 struct f_uac1_legacy_opts *uac1_opts; 262 247 #endif ··· 282 263 #ifndef CONFIG_GADGET_UAC1 283 264 uac2_opts = container_of(fi_uac2, struct f_uac2_opts, func_inst); 284 265 uac2_opts->p_chmask = p_chmask; 285 - uac2_opts->p_srate = p_srate; 266 + 267 + for (i = 0; i < p_srates_cnt; ++i) 268 + uac2_opts->p_srates[i] = p_srates[i]; 269 + 286 270 uac2_opts->p_ssize = p_ssize; 271 + uac2_opts->p_hs_bint = p_hs_bint; 287 272 uac2_opts->c_chmask = c_chmask; 288 - uac2_opts->c_srate = c_srate; 273 + 274 + for (i = 0; i < c_srates_cnt; ++i) 275 + uac2_opts->c_srates[i] = c_srates[i]; 276 + 289 277 uac2_opts->c_ssize = c_ssize; 278 + uac2_opts->c_hs_bint = c_hs_bint; 290 279 uac2_opts->req_number = UAC2_DEF_REQ_NUM; 291 280 #else 292 281 #ifndef CONFIG_GADGET_UAC1_LEGACY 293 282 uac1_opts = container_of(fi_uac1, struct f_uac1_opts, func_inst); 294 283 uac1_opts->p_chmask = p_chmask; 295 - uac1_opts->p_srate = p_srate; 284 + 285 + for (i = 0; i < p_srates_cnt; ++i) 286 + uac1_opts->p_srates[i] = p_srates[i]; 287 + 296 288 uac1_opts->p_ssize = p_ssize; 297 289 uac1_opts->c_chmask = c_chmask; 298 - uac1_opts->c_srate = c_srate; 290 + 291 + for (i = 0; i < c_srates_cnt; ++i) 292 + uac1_opts->c_srates[i] = c_srates[i]; 293 + 299 294 uac1_opts->c_ssize = c_ssize; 300 295 uac1_opts->req_number = UAC1_DEF_REQ_NUM; 301 296 #else /* CONFIG_GADGET_UAC1_LEGACY */
+12 -11
drivers/usb/gadget/legacy/hid.c
··· 134 134 { 135 135 struct usb_gadget *gadget = cdev->gadget; 136 136 struct list_head *tmp; 137 - struct hidg_func_node *n, *m; 137 + struct hidg_func_node *n = NULL, *m, *iter_n; 138 138 struct f_hid_opts *hid_opts; 139 139 int status, funcs = 0; 140 140 ··· 144 144 if (!funcs) 145 145 return -ENODEV; 146 146 147 - list_for_each_entry(n, &hidg_func_list, node) { 148 - n->fi = usb_get_function_instance("hid"); 149 - if (IS_ERR(n->fi)) { 150 - status = PTR_ERR(n->fi); 147 + list_for_each_entry(iter_n, &hidg_func_list, node) { 148 + iter_n->fi = usb_get_function_instance("hid"); 149 + if (IS_ERR(iter_n->fi)) { 150 + status = PTR_ERR(iter_n->fi); 151 + n = iter_n; 151 152 goto put; 152 153 } 153 - hid_opts = container_of(n->fi, struct f_hid_opts, func_inst); 154 - hid_opts->subclass = n->func->subclass; 155 - hid_opts->protocol = n->func->protocol; 156 - hid_opts->report_length = n->func->report_length; 157 - hid_opts->report_desc_length = n->func->report_desc_length; 158 - hid_opts->report_desc = n->func->report_desc; 154 + hid_opts = container_of(iter_n->fi, struct f_hid_opts, func_inst); 155 + hid_opts->subclass = iter_n->func->subclass; 156 + hid_opts->protocol = iter_n->func->protocol; 157 + hid_opts->report_length = iter_n->func->report_length; 158 + hid_opts->report_desc_length = iter_n->func->report_desc_length; 159 + hid_opts->report_desc = iter_n->func->report_desc; 159 160 } 160 161 161 162
+4 -4
drivers/usb/gadget/legacy/inode.c
··· 2101 2101 2102 2102 /*----------------------------------------------------------------------*/ 2103 2103 2104 - static int __init init (void) 2104 + static int __init gadgetfs_init (void) 2105 2105 { 2106 2106 int status; 2107 2107 ··· 2111 2111 shortname, driver_desc); 2112 2112 return status; 2113 2113 } 2114 - module_init (init); 2114 + module_init (gadgetfs_init); 2115 2115 2116 - static void __exit cleanup (void) 2116 + static void __exit gadgetfs_cleanup (void) 2117 2117 { 2118 2118 pr_debug ("unregister %s\n", shortname); 2119 2119 unregister_filesystem (&gadgetfs_type); 2120 2120 } 2121 - module_exit (cleanup); 2121 + module_exit (gadgetfs_cleanup); 2122 2122
+12 -6
drivers/usb/gadget/legacy/raw_gadget.c
··· 758 758 unsigned long flags; 759 759 struct usb_endpoint_descriptor *desc; 760 760 struct raw_ep *ep; 761 + bool ep_props_matched = false; 761 762 762 763 desc = memdup_user((void __user *)value, sizeof(*desc)); 763 764 if (IS_ERR(desc)) ··· 788 787 789 788 for (i = 0; i < dev->eps_num; i++) { 790 789 ep = &dev->eps[i]; 791 - if (ep->state != STATE_EP_DISABLED) 792 - continue; 793 790 if (ep->addr != usb_endpoint_num(desc) && 794 791 ep->addr != USB_RAW_EP_ADDR_ANY) 795 792 continue; 796 793 if (!usb_gadget_ep_match_desc(dev->gadget, ep->ep, desc, NULL)) 794 + continue; 795 + ep_props_matched = true; 796 + if (ep->state != STATE_EP_DISABLED) 797 797 continue; 798 798 ep->ep->desc = desc; 799 799 ret = usb_ep_enable(ep->ep); ··· 817 815 goto out_unlock; 818 816 } 819 817 820 - dev_dbg(&dev->gadget->dev, "fail, no gadget endpoints available\n"); 821 - ret = -EBUSY; 818 + if (!ep_props_matched) { 819 + dev_dbg(&dev->gadget->dev, "fail, bad endpoint descriptor\n"); 820 + ret = -EINVAL; 821 + } else { 822 + dev_dbg(&dev->gadget->dev, "fail, no endpoints available\n"); 823 + ret = -EBUSY; 824 + } 822 825 823 826 out_free: 824 827 kfree(desc); ··· 1164 1157 struct usb_raw_eps_info *info; 1165 1158 struct raw_ep *ep; 1166 1159 1167 - info = kmalloc(sizeof(*info), GFP_KERNEL); 1160 + info = kzalloc(sizeof(*info), GFP_KERNEL); 1168 1161 if (!info) { 1169 1162 ret = -ENOMEM; 1170 1163 goto out; ··· 1184 1177 goto out_free; 1185 1178 } 1186 1179 1187 - memset(info, 0, sizeof(*info)); 1188 1180 for (i = 0; i < dev->eps_num; i++) { 1189 1181 ep = &dev->eps[i]; 1190 1182 strscpy(&info->eps[i].name[0], ep->ep->name,
+5 -5
drivers/usb/gadget/legacy/serial.c
··· 273 273 static int switch_gserial_enable(bool do_enable) 274 274 { 275 275 if (!serial_config_driver.label) 276 - /* init() was not called, yet */ 276 + /* gserial_init() was not called, yet */ 277 277 return 0; 278 278 279 279 if (do_enable) ··· 283 283 return 0; 284 284 } 285 285 286 - static int __init init(void) 286 + static int __init gserial_init(void) 287 287 { 288 288 /* We *could* export two configs; that'd be much cleaner... 289 289 * but neither of these product IDs was defined that way. ··· 314 314 315 315 return usb_composite_probe(&gserial_driver); 316 316 } 317 - module_init(init); 317 + module_init(gserial_init); 318 318 319 - static void __exit cleanup(void) 319 + static void __exit gserial_cleanup(void) 320 320 { 321 321 if (enable) 322 322 usb_composite_unregister(&gserial_driver); 323 323 } 324 - module_exit(cleanup); 324 + module_exit(gserial_cleanup);
+7 -5
drivers/usb/gadget/udc/aspeed-vhub/epn.c
··· 466 466 { 467 467 struct ast_vhub_ep *ep = to_ast_ep(u_ep); 468 468 struct ast_vhub *vhub = ep->vhub; 469 - struct ast_vhub_req *req; 469 + struct ast_vhub_req *req = NULL, *iter; 470 470 unsigned long flags; 471 471 int rc = -EINVAL; 472 472 473 473 spin_lock_irqsave(&vhub->lock, flags); 474 474 475 475 /* Make sure it's actually queued on this endpoint */ 476 - list_for_each_entry (req, &ep->queue, queue) { 477 - if (&req->req == u_req) 478 - break; 476 + list_for_each_entry(iter, &ep->queue, queue) { 477 + if (&iter->req != u_req) 478 + continue; 479 + req = iter; 480 + break; 479 481 } 480 482 481 - if (&req->req == u_req) { 483 + if (req) { 482 484 EPVDBG(ep, "dequeue req @%p active=%d\n", 483 485 req, req->active); 484 486 if (req->active)
+7 -5
drivers/usb/gadget/udc/at91_udc.c
··· 704 704 static int at91_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req) 705 705 { 706 706 struct at91_ep *ep; 707 - struct at91_request *req; 707 + struct at91_request *req = NULL, *iter; 708 708 unsigned long flags; 709 709 struct at91_udc *udc; 710 710 ··· 717 717 spin_lock_irqsave(&udc->lock, flags); 718 718 719 719 /* make sure it's actually queued on this endpoint */ 720 - list_for_each_entry (req, &ep->queue, queue) { 721 - if (&req->req == _req) 722 - break; 720 + list_for_each_entry(iter, &ep->queue, queue) { 721 + if (&iter->req != _req) 722 + continue; 723 + req = iter; 724 + break; 723 725 } 724 - if (&req->req != _req) { 726 + if (!req) { 725 727 spin_unlock_irqrestore(&udc->lock, flags); 726 728 return -EINVAL; 727 729 }
+8 -5
drivers/usb/gadget/udc/atmel_usba_udc.c
··· 860 860 { 861 861 struct usba_ep *ep = to_usba_ep(_ep); 862 862 struct usba_udc *udc = ep->udc; 863 - struct usba_request *req; 863 + struct usba_request *req = NULL; 864 + struct usba_request *iter; 864 865 unsigned long flags; 865 866 u32 status; 866 867 ··· 870 869 871 870 spin_lock_irqsave(&udc->lock, flags); 872 871 873 - list_for_each_entry(req, &ep->queue, queue) { 874 - if (&req->req == _req) 875 - break; 872 + list_for_each_entry(iter, &ep->queue, queue) { 873 + if (&iter->req != _req) 874 + continue; 875 + req = iter; 876 + break; 876 877 } 877 878 878 - if (&req->req != _req) { 879 + if (!req) { 879 880 spin_unlock_irqrestore(&udc->lock, flags); 880 881 return -EINVAL; 881 882 }
+9 -4
drivers/usb/gadget/udc/bdc/bdc_ep.c
··· 1757 1757 struct usb_request *_req) 1758 1758 { 1759 1759 struct bdc_req *req; 1760 + struct bdc_req *iter; 1760 1761 unsigned long flags; 1761 1762 struct bdc_ep *ep; 1762 1763 struct bdc *bdc; ··· 1772 1771 dev_dbg(bdc->dev, "%s ep:%s req:%p\n", __func__, ep->name, req); 1773 1772 bdc_dbg_bd_list(bdc, ep); 1774 1773 spin_lock_irqsave(&bdc->lock, flags); 1774 + 1775 + req = NULL; 1775 1776 /* make sure it's still queued on this endpoint */ 1776 - list_for_each_entry(req, &ep->queue, queue) { 1777 - if (&req->usb_req == _req) 1778 - break; 1777 + list_for_each_entry(iter, &ep->queue, queue) { 1778 + if (&iter->usb_req != _req) 1779 + continue; 1780 + req = iter; 1781 + break; 1779 1782 } 1780 - if (&req->usb_req != _req) { 1783 + if (!req) { 1781 1784 spin_unlock_irqrestore(&bdc->lock, flags); 1782 1785 dev_err(bdc->dev, "usb_req !=req n"); 1783 1786 return -EINVAL;
+12 -8
drivers/usb/gadget/udc/core.c
··· 1525 1525 1526 1526 int usb_gadget_probe_driver(struct usb_gadget_driver *driver) 1527 1527 { 1528 - struct usb_udc *udc = NULL; 1528 + struct usb_udc *udc = NULL, *iter; 1529 1529 int ret = -ENODEV; 1530 1530 1531 1531 if (!driver || !driver->bind || !driver->setup) ··· 1533 1533 1534 1534 mutex_lock(&udc_lock); 1535 1535 if (driver->udc_name) { 1536 - list_for_each_entry(udc, &udc_list, list) { 1537 - ret = strcmp(driver->udc_name, dev_name(&udc->dev)); 1538 - if (!ret) 1539 - break; 1536 + list_for_each_entry(iter, &udc_list, list) { 1537 + ret = strcmp(driver->udc_name, dev_name(&iter->dev)); 1538 + if (ret) 1539 + continue; 1540 + udc = iter; 1541 + break; 1540 1542 } 1541 1543 if (ret) 1542 1544 ret = -ENODEV; ··· 1547 1545 else 1548 1546 goto found; 1549 1547 } else { 1550 - list_for_each_entry(udc, &udc_list, list) { 1548 + list_for_each_entry(iter, &udc_list, list) { 1551 1549 /* For now we take the first one */ 1552 - if (!udc->driver) 1553 - goto found; 1550 + if (iter->driver) 1551 + continue; 1552 + udc = iter; 1553 + goto found; 1554 1554 } 1555 1555 } 1556 1556
+13 -12
drivers/usb/gadget/udc/dummy_hcd.c
··· 751 751 struct dummy *dum; 752 752 int retval = -EINVAL; 753 753 unsigned long flags; 754 - struct dummy_request *req = NULL; 754 + struct dummy_request *req = NULL, *iter; 755 755 756 756 if (!_ep || !_req) 757 757 return retval; ··· 763 763 764 764 local_irq_save(flags); 765 765 spin_lock(&dum->lock); 766 - list_for_each_entry(req, &ep->queue, queue) { 767 - if (&req->req == _req) { 768 - list_del_init(&req->queue); 769 - _req->status = -ECONNRESET; 770 - retval = 0; 771 - break; 772 - } 766 + list_for_each_entry(iter, &ep->queue, queue) { 767 + if (&iter->req != _req) 768 + continue; 769 + list_del_init(&iter->queue); 770 + _req->status = -ECONNRESET; 771 + req = iter; 772 + retval = 0; 773 + break; 773 774 } 774 775 spin_unlock(&dum->lock); 775 776 ··· 2766 2765 static struct platform_device *the_udc_pdev[MAX_NUM_UDC]; 2767 2766 static struct platform_device *the_hcd_pdev[MAX_NUM_UDC]; 2768 2767 2769 - static int __init init(void) 2768 + static int __init dummy_hcd_init(void) 2770 2769 { 2771 2770 int retval = -ENOMEM; 2772 2771 int i; ··· 2888 2887 platform_device_put(the_hcd_pdev[i]); 2889 2888 return retval; 2890 2889 } 2891 - module_init(init); 2890 + module_init(dummy_hcd_init); 2892 2891 2893 - static void __exit cleanup(void) 2892 + static void __exit dummy_hcd_cleanup(void) 2894 2893 { 2895 2894 int i; 2896 2895 ··· 2906 2905 platform_driver_unregister(&dummy_udc_driver); 2907 2906 platform_driver_unregister(&dummy_hcd_driver); 2908 2907 } 2909 - module_exit(cleanup); 2908 + module_exit(dummy_hcd_cleanup);
+8 -5
drivers/usb/gadget/udc/fsl_qe_udc.c
··· 1776 1776 static int qe_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req) 1777 1777 { 1778 1778 struct qe_ep *ep = container_of(_ep, struct qe_ep, ep); 1779 - struct qe_req *req; 1779 + struct qe_req *req = NULL; 1780 + struct qe_req *iter; 1780 1781 unsigned long flags; 1781 1782 1782 1783 if (!_ep || !_req) ··· 1786 1785 spin_lock_irqsave(&ep->udc->lock, flags); 1787 1786 1788 1787 /* make sure it's actually queued on this endpoint */ 1789 - list_for_each_entry(req, &ep->queue, queue) { 1790 - if (&req->req == _req) 1791 - break; 1788 + list_for_each_entry(iter, &ep->queue, queue) { 1789 + if (&iter->req != _req) 1790 + continue; 1791 + req = iter; 1792 + break; 1792 1793 } 1793 1794 1794 - if (&req->req != _req) { 1795 + if (!req) { 1795 1796 spin_unlock_irqrestore(&ep->udc->lock, flags); 1796 1797 return -EINVAL; 1797 1798 }
+8 -5
drivers/usb/gadget/udc/fsl_udc_core.c
··· 918 918 static int fsl_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req) 919 919 { 920 920 struct fsl_ep *ep = container_of(_ep, struct fsl_ep, ep); 921 - struct fsl_req *req; 921 + struct fsl_req *req = NULL; 922 + struct fsl_req *iter; 922 923 unsigned long flags; 923 924 int ep_num, stopped, ret = 0; 924 925 u32 epctrl; ··· 941 940 fsl_writel(epctrl, &dr_regs->endptctrl[ep_num]); 942 941 943 942 /* make sure it's actually queued on this endpoint */ 944 - list_for_each_entry(req, &ep->queue, queue) { 945 - if (&req->req == _req) 946 - break; 943 + list_for_each_entry(iter, &ep->queue, queue) { 944 + if (&iter->req != _req) 945 + continue; 946 + req = iter; 947 + break; 947 948 } 948 - if (&req->req != _req) { 949 + if (!req) { 949 950 ret = -EINVAL; 950 951 goto out; 951 952 }
+7 -5
drivers/usb/gadget/udc/goku_udc.c
··· 809 809 /* dequeue JUST ONE request */ 810 810 static int goku_dequeue(struct usb_ep *_ep, struct usb_request *_req) 811 811 { 812 - struct goku_request *req; 812 + struct goku_request *req = NULL, *iter; 813 813 struct goku_ep *ep; 814 814 struct goku_udc *dev; 815 815 unsigned long flags; ··· 833 833 spin_lock_irqsave(&dev->lock, flags); 834 834 835 835 /* make sure it's actually queued on this endpoint */ 836 - list_for_each_entry (req, &ep->queue, queue) { 837 - if (&req->req == _req) 838 - break; 836 + list_for_each_entry(iter, &ep->queue, queue) { 837 + if (&iter->req != _req) 838 + continue; 839 + req = iter; 840 + break; 839 841 } 840 - if (&req->req != _req) { 842 + if (!req) { 841 843 spin_unlock_irqrestore (&dev->lock, flags); 842 844 return -EINVAL; 843 845 }
+7 -5
drivers/usb/gadget/udc/gr_udc.c
··· 1690 1690 /* Dequeue JUST ONE request */ 1691 1691 static int gr_dequeue(struct usb_ep *_ep, struct usb_request *_req) 1692 1692 { 1693 - struct gr_request *req; 1693 + struct gr_request *req = NULL, *iter; 1694 1694 struct gr_ep *ep; 1695 1695 struct gr_udc *dev; 1696 1696 int ret = 0; ··· 1710 1710 spin_lock_irqsave(&dev->lock, flags); 1711 1711 1712 1712 /* Make sure it's actually queued on this endpoint */ 1713 - list_for_each_entry(req, &ep->queue, queue) { 1714 - if (&req->req == _req) 1715 - break; 1713 + list_for_each_entry(iter, &ep->queue, queue) { 1714 + if (&iter->req != _req) 1715 + continue; 1716 + req = iter; 1717 + break; 1716 1718 } 1717 - if (&req->req != _req) { 1719 + if (!req) { 1718 1720 ret = -EINVAL; 1719 1721 goto out; 1720 1722 }
+7 -5
drivers/usb/gadget/udc/lpc32xx_udc.c
··· 1830 1830 static int lpc32xx_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req) 1831 1831 { 1832 1832 struct lpc32xx_ep *ep; 1833 - struct lpc32xx_request *req; 1833 + struct lpc32xx_request *req = NULL, *iter; 1834 1834 unsigned long flags; 1835 1835 1836 1836 ep = container_of(_ep, struct lpc32xx_ep, ep); ··· 1840 1840 spin_lock_irqsave(&ep->udc->lock, flags); 1841 1841 1842 1842 /* make sure it's actually queued on this endpoint */ 1843 - list_for_each_entry(req, &ep->queue, queue) { 1844 - if (&req->req == _req) 1845 - break; 1843 + list_for_each_entry(iter, &ep->queue, queue) { 1844 + if (&iter->req != _req) 1845 + continue; 1846 + req = iter; 1847 + break; 1846 1848 } 1847 - if (&req->req != _req) { 1849 + if (!req) { 1848 1850 spin_unlock_irqrestore(&ep->udc->lock, flags); 1849 1851 return -EINVAL; 1850 1852 }
+11 -7
drivers/usb/gadget/udc/max3420_udc.c
··· 1044 1044 1045 1045 static int max3420_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req) 1046 1046 { 1047 - struct max3420_req *t, *req = to_max3420_req(_req); 1047 + struct max3420_req *t = NULL; 1048 + struct max3420_req *req = to_max3420_req(_req); 1049 + struct max3420_req *iter; 1048 1050 struct max3420_ep *ep = to_max3420_ep(_ep); 1049 1051 unsigned long flags; 1050 1052 1051 1053 spin_lock_irqsave(&ep->lock, flags); 1052 1054 1053 1055 /* Pluck the descriptor from queue */ 1054 - list_for_each_entry(t, &ep->queue, queue) 1055 - if (t == req) { 1056 - list_del_init(&req->queue); 1057 - break; 1058 - } 1056 + list_for_each_entry(iter, &ep->queue, queue) { 1057 + if (iter != req) 1058 + continue; 1059 + list_del_init(&req->queue); 1060 + t = iter; 1061 + break; 1062 + } 1059 1063 1060 1064 spin_unlock_irqrestore(&ep->lock, flags); 1061 1065 1062 - if (t == req) 1066 + if (t) 1063 1067 max3420_req_done(req, -ECONNRESET); 1064 1068 1065 1069 return 0;
+7 -5
drivers/usb/gadget/udc/mv_u3d_core.c
··· 844 844 static int mv_u3d_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req) 845 845 { 846 846 struct mv_u3d_ep *ep; 847 - struct mv_u3d_req *req; 847 + struct mv_u3d_req *req = NULL, *iter; 848 848 struct mv_u3d *u3d; 849 849 struct mv_u3d_ep_context *ep_context; 850 850 struct mv_u3d_req *next_req; ··· 861 861 spin_lock_irqsave(&ep->u3d->lock, flags); 862 862 863 863 /* make sure it's actually queued on this endpoint */ 864 - list_for_each_entry(req, &ep->queue, queue) { 865 - if (&req->req == _req) 866 - break; 864 + list_for_each_entry(iter, &ep->queue, queue) { 865 + if (&iter->req != _req) 866 + continue; 867 + req = iter; 868 + break; 867 869 } 868 - if (&req->req != _req) { 870 + if (!req) { 869 871 ret = -EINVAL; 870 872 goto out; 871 873 }
+7 -5
drivers/usb/gadget/udc/mv_udc_core.c
··· 771 771 static int mv_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req) 772 772 { 773 773 struct mv_ep *ep = container_of(_ep, struct mv_ep, ep); 774 - struct mv_req *req; 774 + struct mv_req *req = NULL, *iter; 775 775 struct mv_udc *udc = ep->udc; 776 776 unsigned long flags; 777 777 int stopped, ret = 0; ··· 793 793 writel(epctrlx, &udc->op_regs->epctrlx[ep->ep_num]); 794 794 795 795 /* make sure it's actually queued on this endpoint */ 796 - list_for_each_entry(req, &ep->queue, queue) { 797 - if (&req->req == _req) 798 - break; 796 + list_for_each_entry(iter, &ep->queue, queue) { 797 + if (&iter->req != _req) 798 + continue; 799 + req = iter; 800 + break; 799 801 } 800 - if (&req->req != _req) { 802 + if (!req) { 801 803 ret = -EINVAL; 802 804 goto out; 803 805 }
+7 -6
drivers/usb/gadget/udc/net2272.c
··· 926 926 net2272_dequeue(struct usb_ep *_ep, struct usb_request *_req) 927 927 { 928 928 struct net2272_ep *ep; 929 - struct net2272_request *req; 929 + struct net2272_request *req = NULL, *iter; 930 930 unsigned long flags; 931 931 int stopped; 932 932 ··· 939 939 ep->stopped = 1; 940 940 941 941 /* make sure it's still queued on this endpoint */ 942 - list_for_each_entry(req, &ep->queue, queue) { 943 - if (&req->req == _req) 944 - break; 942 + list_for_each_entry(iter, &ep->queue, queue) { 943 + if (&iter->req != _req) 944 + continue; 945 + req = iter; 946 + break; 945 947 } 946 - if (&req->req != _req) { 948 + if (!req) { 947 949 ep->stopped = stopped; 948 950 spin_unlock_irqrestore(&ep->dev->lock, flags); 949 951 return -EINVAL; ··· 956 954 dev_dbg(ep->dev->dev, "unlink (%s) pio\n", _ep->name); 957 955 net2272_done(ep, req, -ECONNRESET); 958 956 } 959 - req = NULL; 960 957 ep->stopped = stopped; 961 958 962 959 spin_unlock_irqrestore(&ep->dev->lock, flags);
+8 -5
drivers/usb/gadget/udc/net2280.c
··· 1240 1240 static int net2280_dequeue(struct usb_ep *_ep, struct usb_request *_req) 1241 1241 { 1242 1242 struct net2280_ep *ep; 1243 - struct net2280_request *req; 1243 + struct net2280_request *req = NULL; 1244 + struct net2280_request *iter; 1244 1245 unsigned long flags; 1245 1246 u32 dmactl; 1246 1247 int stopped; ··· 1267 1266 } 1268 1267 1269 1268 /* make sure it's still queued on this endpoint */ 1270 - list_for_each_entry(req, &ep->queue, queue) { 1271 - if (&req->req == _req) 1272 - break; 1269 + list_for_each_entry(iter, &ep->queue, queue) { 1270 + if (&iter->req != _req) 1271 + continue; 1272 + req = iter; 1273 + break; 1273 1274 } 1274 - if (&req->req != _req) { 1275 + if (!req) { 1275 1276 ep->stopped = stopped; 1276 1277 spin_unlock_irqrestore(&ep->dev->lock, flags); 1277 1278 ep_dbg(ep->dev, "%s: Request mismatch\n", __func__);
+7 -5
drivers/usb/gadget/udc/omap_udc.c
··· 1003 1003 static int omap_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req) 1004 1004 { 1005 1005 struct omap_ep *ep = container_of(_ep, struct omap_ep, ep); 1006 - struct omap_req *req; 1006 + struct omap_req *req = NULL, *iter; 1007 1007 unsigned long flags; 1008 1008 1009 1009 if (!_ep || !_req) ··· 1012 1012 spin_lock_irqsave(&ep->udc->lock, flags); 1013 1013 1014 1014 /* make sure it's actually queued on this endpoint */ 1015 - list_for_each_entry(req, &ep->queue, queue) { 1016 - if (&req->req == _req) 1017 - break; 1015 + list_for_each_entry(iter, &ep->queue, queue) { 1016 + if (&iter->req != _req) 1017 + continue; 1018 + req = iter; 1019 + break; 1018 1020 } 1019 - if (&req->req != _req) { 1021 + if (!req) { 1020 1022 spin_unlock_irqrestore(&ep->udc->lock, flags); 1021 1023 return -EINVAL; 1022 1024 }
+8 -5
drivers/usb/gadget/udc/pxa25x_udc.c
··· 966 966 static int pxa25x_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req) 967 967 { 968 968 struct pxa25x_ep *ep; 969 - struct pxa25x_request *req; 969 + struct pxa25x_request *req = NULL; 970 + struct pxa25x_request *iter; 970 971 unsigned long flags; 971 972 972 973 ep = container_of(_ep, struct pxa25x_ep, ep); ··· 977 976 local_irq_save(flags); 978 977 979 978 /* make sure it's actually queued on this endpoint */ 980 - list_for_each_entry (req, &ep->queue, queue) { 981 - if (&req->req == _req) 982 - break; 979 + list_for_each_entry(iter, &ep->queue, queue) { 980 + if (&iter->req != _req) 981 + continue; 982 + req = iter; 983 + break; 983 984 } 984 - if (&req->req != _req) { 985 + if (!req) { 985 986 local_irq_restore(flags); 986 987 return -EINVAL; 987 988 }
+7 -6
drivers/usb/gadget/udc/pxa27x_udc.c
··· 1159 1159 { 1160 1160 struct pxa_ep *ep; 1161 1161 struct udc_usb_ep *udc_usb_ep; 1162 - struct pxa27x_request *req; 1162 + struct pxa27x_request *req = NULL, *iter; 1163 1163 unsigned long flags; 1164 1164 int rc = -EINVAL; 1165 1165 ··· 1173 1173 spin_lock_irqsave(&ep->lock, flags); 1174 1174 1175 1175 /* make sure it's actually queued on this endpoint */ 1176 - list_for_each_entry(req, &ep->queue, queue) { 1177 - if (&req->req == _req) { 1178 - rc = 0; 1179 - break; 1180 - } 1176 + list_for_each_entry(iter, &ep->queue, queue) { 1177 + if (&iter->req != _req) 1178 + continue; 1179 + req = iter; 1180 + rc = 0; 1181 + break; 1181 1182 } 1182 1183 1183 1184 spin_unlock_irqrestore(&ep->lock, flags);
+1 -1
drivers/usb/gadget/udc/renesas_usb3.c
··· 2730 2730 .soc_id = "r8a7795", .revision = "ES1.*", 2731 2731 .data = &renesas_usb3_priv_r8a7795_es1, 2732 2732 }, 2733 - { /* sentinel */ }, 2733 + { /* sentinel */ } 2734 2734 }; 2735 2735 2736 2736 static const unsigned int renesas_usb3_cable[] = {
+7 -5
drivers/usb/gadget/udc/s3c-hsudc.c
··· 877 877 { 878 878 struct s3c_hsudc_ep *hsep = our_ep(_ep); 879 879 struct s3c_hsudc *hsudc = hsep->dev; 880 - struct s3c_hsudc_req *hsreq; 880 + struct s3c_hsudc_req *hsreq = NULL, *iter; 881 881 unsigned long flags; 882 882 883 883 hsep = our_ep(_ep); ··· 886 886 887 887 spin_lock_irqsave(&hsudc->lock, flags); 888 888 889 - list_for_each_entry(hsreq, &hsep->queue, queue) { 890 - if (&hsreq->req == _req) 891 - break; 889 + list_for_each_entry(iter, &hsep->queue, queue) { 890 + if (&iter->req != _req) 891 + continue; 892 + hsreq = iter; 893 + break; 892 894 } 893 - if (&hsreq->req != _req) { 895 + if (!hsreq) { 894 896 spin_unlock_irqrestore(&hsudc->lock, flags); 895 897 return -EINVAL; 896 898 }
+9 -8
drivers/usb/gadget/udc/s3c2410_udc.c
··· 1265 1265 struct s3c2410_ep *ep = to_s3c2410_ep(_ep); 1266 1266 int retval = -EINVAL; 1267 1267 unsigned long flags; 1268 - struct s3c2410_request *req = NULL; 1268 + struct s3c2410_request *req = NULL, *iter; 1269 1269 1270 1270 dprintk(DEBUG_VERBOSE, "%s(%p,%p)\n", __func__, _ep, _req); 1271 1271 ··· 1277 1277 1278 1278 local_irq_save(flags); 1279 1279 1280 - list_for_each_entry(req, &ep->queue, queue) { 1281 - if (&req->req == _req) { 1282 - list_del_init(&req->queue); 1283 - _req->status = -ECONNRESET; 1284 - retval = 0; 1285 - break; 1286 - } 1280 + list_for_each_entry(iter, &ep->queue, queue) { 1281 + if (&iter->req != _req) 1282 + continue; 1283 + list_del_init(&iter->queue); 1284 + _req->status = -ECONNRESET; 1285 + req = iter; 1286 + retval = 0; 1287 + break; 1287 1288 } 1288 1289 1289 1290 if (retval == 0) {
+1 -1
drivers/usb/gadget/udc/snps_udc_core.c
··· 80 80 * This cannot be solved by letting the RX DMA disabled until a 81 81 * request gets queued because there may be other OUT packets 82 82 * in the FIFO (important for not blocking control traffic). 83 - * The value of set_rde controls the correspondig timer. 83 + * The value of set_rde controls the corresponding timer. 84 84 * 85 85 * set_rde -1 == not used, means it is alloed to be set to 0 or 1 86 86 * set_rde 0 == do not touch RDE, do no start the RDE timer
+17 -15
drivers/usb/gadget/udc/tegra-xudc.c
··· 32 32 #include <linux/workqueue.h> 33 33 34 34 /* XUSB_DEV registers */ 35 - #define SPARAM 0x000 36 - #define SPARAM_ERSTMAX_MASK GENMASK(20, 16) 37 - #define SPARAM_ERSTMAX(x) (((x) << 16) & SPARAM_ERSTMAX_MASK) 38 35 #define DB 0x004 39 36 #define DB_TARGET_MASK GENMASK(15, 8) 40 37 #define DB_TARGET(x) (((x) << 8) & DB_TARGET_MASK) ··· 272 275 BUILD_EP_CONTEXT_RW(avg_trb_len, tx_info, 0, 0xffff) 273 276 BUILD_EP_CONTEXT_RW(max_esit_payload, tx_info, 16, 0xffff) 274 277 BUILD_EP_CONTEXT_RW(edtla, rsvd[0], 0, 0xffffff) 275 - BUILD_EP_CONTEXT_RW(seq_num, rsvd[0], 24, 0xff) 278 + BUILD_EP_CONTEXT_RW(rsvd, rsvd[0], 24, 0x1) 276 279 BUILD_EP_CONTEXT_RW(partial_td, rsvd[0], 25, 0x1) 280 + BUILD_EP_CONTEXT_RW(splitxstate, rsvd[0], 26, 0x1) 281 + BUILD_EP_CONTEXT_RW(seq_num, rsvd[0], 27, 0x1f) 277 282 BUILD_EP_CONTEXT_RW(cerrcnt, rsvd[1], 18, 0x3) 278 283 BUILD_EP_CONTEXT_RW(data_offset, rsvd[2], 0, 0x1ffff) 279 284 BUILD_EP_CONTEXT_RW(numtrbs, rsvd[2], 22, 0x1f) ··· 1412 1413 struct tegra_xudc_request *req) 1413 1414 { 1414 1415 struct tegra_xudc *xudc = ep->xudc; 1415 - struct tegra_xudc_request *r; 1416 + struct tegra_xudc_request *r = NULL, *iter; 1416 1417 struct tegra_xudc_trb *deq_trb; 1417 1418 bool busy, kick_queue = false; 1418 1419 int ret = 0; 1419 1420 1420 1421 /* Make sure the request is actually queued to this endpoint. */ 1421 - list_for_each_entry(r, &ep->queue, list) { 1422 - if (r == req) 1423 - break; 1422 + list_for_each_entry(iter, &ep->queue, list) { 1423 + if (iter != req) 1424 + continue; 1425 + r = iter; 1426 + break; 1424 1427 } 1425 1428 1426 - if (r != req) 1429 + if (!r) 1427 1430 return -EINVAL; 1428 1431 1429 1432 /* Request hasn't been queued in the transfer ring yet. */ ··· 1558 1557 ep_reload(xudc, ep->index); 1559 1558 1560 1559 ep_ctx_write_state(ep->context, EP_STATE_RUNNING); 1560 + ep_ctx_write_rsvd(ep->context, 0); 1561 + ep_ctx_write_partial_td(ep->context, 0); 1562 + ep_ctx_write_splitxstate(ep->context, 0); 1561 1563 ep_ctx_write_seq_num(ep->context, 0); 1562 1564 1563 1565 ep_reload(xudc, ep->index); ··· 2816 2812 xudc->setup_seq_num = 0; 2817 2813 xudc->queued_setup_packet = false; 2818 2814 2819 - ep_ctx_write_seq_num(ep0->context, xudc->setup_seq_num); 2815 + ep_ctx_write_rsvd(ep0->context, 0); 2816 + ep_ctx_write_partial_td(ep0->context, 0); 2817 + ep_ctx_write_splitxstate(ep0->context, 0); 2818 + ep_ctx_write_seq_num(ep0->context, 0); 2820 2819 2821 2820 deq_ptr = trb_virt_to_phys(ep0, &ep0->transfer_ring[ep0->deq_ptr]); 2822 2821 ··· 3301 3294 { 3302 3295 unsigned int i; 3303 3296 u32 val; 3304 - 3305 - val = xudc_readl(xudc, SPARAM); 3306 - val &= ~(SPARAM_ERSTMAX_MASK); 3307 - val |= SPARAM_ERSTMAX(XUDC_NR_EVENT_RINGS); 3308 - xudc_writel(xudc, val, SPARAM); 3309 3297 3310 3298 for (i = 0; i < ARRAY_SIZE(xudc->event_ring); i++) { 3311 3299 memset(xudc->event_ring[i], 0, XUDC_EVENT_RING_SIZE *
+8 -5
drivers/usb/gadget/udc/udc-xilinx.c
··· 1136 1136 static int xudc_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req) 1137 1137 { 1138 1138 struct xusb_ep *ep = to_xusb_ep(_ep); 1139 - struct xusb_req *req = to_xusb_req(_req); 1139 + struct xusb_req *req = NULL; 1140 + struct xusb_req *iter; 1140 1141 struct xusb_udc *udc = ep->udc; 1141 1142 unsigned long flags; 1142 1143 1143 1144 spin_lock_irqsave(&udc->lock, flags); 1144 1145 /* Make sure it's actually queued on this endpoint */ 1145 - list_for_each_entry(req, &ep->queue, queue) { 1146 - if (&req->usb_req == _req) 1147 - break; 1146 + list_for_each_entry(iter, &ep->queue, queue) { 1147 + if (&iter->usb_req != _req) 1148 + continue; 1149 + req = iter; 1150 + break; 1148 1151 } 1149 - if (&req->usb_req != _req) { 1152 + if (!req) { 1150 1153 spin_unlock_irqrestore(&udc->lock, flags); 1151 1154 return -EINVAL; 1152 1155 }
+2 -2
drivers/usb/host/ehci-dbg.c
··· 931 931 932 932 static int fill_buffer(struct debug_buffer *buf) 933 933 { 934 - int ret = 0; 934 + int ret; 935 935 936 936 if (!buf->output_buf) 937 937 buf->output_buf = vmalloc(buf->alloc_size); ··· 956 956 size_t len, loff_t *offset) 957 957 { 958 958 struct debug_buffer *buf = file->private_data; 959 - int ret = 0; 959 + int ret; 960 960 961 961 mutex_lock(&buf->mutex); 962 962 if (buf->count == 0) {
+9
drivers/usb/host/ehci-pci.c
··· 21 21 /* defined here to avoid adding to pci_ids.h for single instance use */ 22 22 #define PCI_DEVICE_ID_INTEL_CE4100_USB 0x2e70 23 23 24 + #define PCI_VENDOR_ID_ASPEED 0x1a03 25 + #define PCI_DEVICE_ID_ASPEED_EHCI 0x2603 26 + 24 27 /*-------------------------------------------------------------------------*/ 25 28 #define PCI_DEVICE_ID_INTEL_QUARK_X1000_SOC 0x0939 26 29 static inline bool is_intel_quark_x1000(struct pci_dev *pdev) ··· 223 220 if (pdev->device == 0xa239) { 224 221 ehci_info(ehci, "applying Synopsys HC workaround\n"); 225 222 ehci->has_synopsys_hc_bug = 1; 223 + } 224 + break; 225 + case PCI_VENDOR_ID_ASPEED: 226 + if (pdev->device == PCI_DEVICE_ID_ASPEED_EHCI) { 227 + ehci_info(ehci, "applying Aspeed HC workaround\n"); 228 + ehci->is_aspeed = 1; 226 229 } 227 230 break; 228 231 }
+1 -2
drivers/usb/host/ehci-platform.c
··· 43 43 #define hcd_to_ehci_priv(h) ((struct ehci_platform_priv *)hcd_to_ehci(h)->priv) 44 44 45 45 #define BCM_USB_FIFO_THRESHOLD 0x00800040 46 - #define bcm_iproc_insnreg01 hostpc[0] 47 46 48 47 struct ehci_platform_priv { 49 48 struct clk *clks[EHCI_MAX_CLKS]; ··· 80 81 81 82 if (of_device_is_compatible(pdev->dev.of_node, "brcm,xgs-iproc-ehci")) 82 83 ehci_writel(ehci, BCM_USB_FIFO_THRESHOLD, 83 - &ehci->regs->bcm_iproc_insnreg01); 84 + &ehci->regs->brcm_insnreg[1]); 84 85 85 86 return 0; 86 87 }
+4 -3
drivers/usb/host/ehci-q.c
··· 33 33 34 34 /* fill a qtd, returning how much of the buffer we were able to queue up */ 35 35 36 - static int 36 + static unsigned int 37 37 qtd_fill(struct ehci_hcd *ehci, struct ehci_qtd *qtd, dma_addr_t buf, 38 38 size_t len, int token, int maxpacket) 39 39 { 40 - int i, count; 40 + unsigned int count; 41 41 u64 addr = buf; 42 + int i; 42 43 43 44 /* one buffer entry per 4K ... first might be short or unaligned */ 44 45 qtd->hw_buf[0] = cpu_to_hc32(ehci, (u32)addr); ··· 653 652 * and may serve as a control status ack 654 653 */ 655 654 for (;;) { 656 - int this_qtd_len; 655 + unsigned int this_qtd_len; 657 656 658 657 this_qtd_len = qtd_fill(ehci, qtd, buf, this_sg_len, token, 659 658 maxpacket);
+1 -3
drivers/usb/host/ehci-sched.c
··· 1165 1165 iso_sched_alloc(unsigned packets, gfp_t mem_flags) 1166 1166 { 1167 1167 struct ehci_iso_sched *iso_sched; 1168 - int size = sizeof(*iso_sched); 1169 1168 1170 - size += packets * sizeof(struct ehci_iso_packet); 1171 - iso_sched = kzalloc(size, mem_flags); 1169 + iso_sched = kzalloc(struct_size(iso_sched, packet, packets), mem_flags); 1172 1170 if (likely(iso_sched != NULL)) 1173 1171 INIT_LIST_HEAD(&iso_sched->td_list); 1174 1172
+1 -3
drivers/usb/host/fotg210-hcd.c
··· 4014 4014 gfp_t mem_flags) 4015 4015 { 4016 4016 struct fotg210_iso_sched *iso_sched; 4017 - int size = sizeof(*iso_sched); 4018 4017 4019 - size += packets * sizeof(struct fotg210_iso_packet); 4020 - iso_sched = kzalloc(size, mem_flags); 4018 + iso_sched = kzalloc(struct_size(iso_sched, packet, packets), mem_flags); 4021 4019 if (likely(iso_sched != NULL)) 4022 4020 INIT_LIST_HEAD(&iso_sched->td_list); 4023 4021
+2 -2
drivers/usb/host/ohci-dbg.c
··· 680 680 681 681 static int fill_buffer(struct debug_buffer *buf) 682 682 { 683 - int ret = 0; 683 + int ret; 684 684 685 685 if (!buf->page) 686 686 buf->page = (char *)get_zeroed_page(GFP_KERNEL); ··· 705 705 size_t len, loff_t *offset) 706 706 { 707 707 struct debug_buffer *buf = file->private_data; 708 - int ret = 0; 708 + int ret; 709 709 710 710 mutex_lock(&buf->mutex); 711 711 if (buf->count == 0) {
+1 -1
drivers/usb/host/oxu210hp-hcd.c
··· 1685 1685 token |= (1 /* "in" */ << 8); 1686 1686 /* else it's already initted to "out" pid (0 << 8) */ 1687 1687 1688 - maxpacket = max_packet(usb_maxpacket(urb->dev, urb->pipe, !is_input)); 1688 + maxpacket = usb_maxpacket(urb->dev, urb->pipe, !is_input); 1689 1689 1690 1690 /* 1691 1691 * buffer gets wrapped in one or more qtds;
+44 -17
drivers/usb/host/xen-hcd.c
··· 51 51 struct usb_shadow { 52 52 struct xenusb_urb_request req; 53 53 struct urb *urb; 54 + bool in_flight; 54 55 }; 55 56 56 57 struct xenhcd_info { ··· 590 589 int nr_pages, int flags) 591 590 { 592 591 grant_ref_t ref; 593 - unsigned long buffer_mfn; 594 592 unsigned int offset; 595 593 unsigned int len = length; 596 594 unsigned int bytes; 597 595 int i; 598 596 599 597 for (i = 0; i < nr_pages; i++) { 600 - buffer_mfn = PFN_DOWN(arbitrary_virt_to_machine(addr).maddr); 601 598 offset = offset_in_page(addr); 602 599 603 600 bytes = PAGE_SIZE - offset; ··· 604 605 605 606 ref = gnttab_claim_grant_reference(gref_head); 606 607 gnttab_grant_foreign_access_ref(ref, info->xbdev->otherend_id, 607 - buffer_mfn, flags); 608 + virt_to_gfn(addr), flags); 608 609 seg[i].gref = ref; 609 610 seg[i].offset = (__u16)offset; 610 611 seg[i].length = (__u16)bytes; ··· 721 722 int nr_segs = 0; 722 723 int i; 723 724 725 + if (!shadow->in_flight) { 726 + xenhcd_set_error(info, "Illegal request id"); 727 + return; 728 + } 729 + shadow->in_flight = false; 730 + 724 731 nr_segs = shadow->req.nr_buffer_segs; 725 732 726 733 if (xenusb_pipeisoc(shadow->req.pipe)) ··· 810 805 811 806 info->urb_ring.req_prod_pvt++; 812 807 info->shadow[id].urb = urb; 808 + info->shadow[id].in_flight = true; 813 809 814 810 RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(&info->urb_ring, notify); 815 811 if (notify) ··· 939 933 return ret; 940 934 } 941 935 942 - static int xenhcd_urb_request_done(struct xenhcd_info *info) 936 + static void xenhcd_res_to_urb(struct xenhcd_info *info, 937 + struct xenusb_urb_response *res, struct urb *urb) 938 + { 939 + if (unlikely(!urb)) 940 + return; 941 + 942 + if (res->actual_length > urb->transfer_buffer_length) 943 + urb->actual_length = urb->transfer_buffer_length; 944 + else if (res->actual_length < 0) 945 + urb->actual_length = 0; 946 + else 947 + urb->actual_length = res->actual_length; 948 + urb->error_count = res->error_count; 949 + urb->start_frame = res->start_frame; 950 + xenhcd_giveback_urb(info, urb, res->status); 951 + } 952 + 953 + static int xenhcd_urb_request_done(struct xenhcd_info *info, 954 + unsigned int *eoiflag) 943 955 { 944 956 struct xenusb_urb_response res; 945 - struct urb *urb; 946 957 RING_IDX i, rp; 947 958 __u16 id; 948 959 int more_to_do = 0; ··· 986 963 xenhcd_gnttab_done(info, id); 987 964 if (info->error) 988 965 goto err; 989 - urb = info->shadow[id].urb; 990 - if (likely(urb)) { 991 - urb->actual_length = res.actual_length; 992 - urb->error_count = res.error_count; 993 - urb->start_frame = res.start_frame; 994 - xenhcd_giveback_urb(info, urb, res.status); 995 - } 966 + xenhcd_res_to_urb(info, &res, info->shadow[id].urb); 996 967 } 997 968 998 969 xenhcd_add_id_to_freelist(info, id); 970 + 971 + *eoiflag = 0; 999 972 } 1000 973 info->urb_ring.rsp_cons = i; 1001 974 ··· 1009 990 return 0; 1010 991 } 1011 992 1012 - static int xenhcd_conn_notify(struct xenhcd_info *info) 993 + static int xenhcd_conn_notify(struct xenhcd_info *info, unsigned int *eoiflag) 1013 994 { 1014 995 struct xenusb_conn_response res; 1015 996 struct xenusb_conn_request *req; ··· 1054 1035 info->conn_ring.req_prod_pvt); 1055 1036 req->id = id; 1056 1037 info->conn_ring.req_prod_pvt++; 1038 + 1039 + *eoiflag = 0; 1057 1040 } 1058 1041 1059 1042 if (rc != info->conn_ring.req_prod_pvt) ··· 1078 1057 static irqreturn_t xenhcd_int(int irq, void *dev_id) 1079 1058 { 1080 1059 struct xenhcd_info *info = (struct xenhcd_info *)dev_id; 1060 + unsigned int eoiflag = XEN_EOI_FLAG_SPURIOUS; 1081 1061 1082 - if (unlikely(info->error)) 1062 + if (unlikely(info->error)) { 1063 + xen_irq_lateeoi(irq, XEN_EOI_FLAG_SPURIOUS); 1083 1064 return IRQ_HANDLED; 1065 + } 1084 1066 1085 - while (xenhcd_urb_request_done(info) | xenhcd_conn_notify(info)) 1067 + while (xenhcd_urb_request_done(info, &eoiflag) | 1068 + xenhcd_conn_notify(info, &eoiflag)) 1086 1069 /* Yield point for this unbounded loop. */ 1087 1070 cond_resched(); 1088 1071 1072 + xen_irq_lateeoi(irq, eoiflag); 1089 1073 return IRQ_HANDLED; 1090 1074 } 1091 1075 ··· 1167 1141 goto fail; 1168 1142 } 1169 1143 1170 - err = bind_evtchn_to_irq(info->evtchn); 1144 + err = bind_evtchn_to_irq_lateeoi(info->evtchn); 1171 1145 if (err <= 0) { 1172 - xenbus_dev_fatal(dev, err, "bind_evtchn_to_irq"); 1146 + xenbus_dev_fatal(dev, err, "bind_evtchn_to_irq_lateeoi"); 1173 1147 goto fail; 1174 1148 } 1175 1149 ··· 1522 1496 for (i = 0; i < XENUSB_URB_RING_SIZE; i++) { 1523 1497 info->shadow[i].req.id = i + 1; 1524 1498 info->shadow[i].urb = NULL; 1499 + info->shadow[i].in_flight = false; 1525 1500 } 1526 1501 info->shadow[XENUSB_URB_RING_SIZE - 1].req.id = 0x0fff; 1527 1502
+72 -73
drivers/usb/host/xhci-dbgcap.c
··· 914 914 mod_delayed_work(system_wq, &dbc->event_work, 1); 915 915 } 916 916 917 - static void xhci_do_dbc_exit(struct xhci_hcd *xhci) 918 - { 919 - unsigned long flags; 920 - 921 - spin_lock_irqsave(&xhci->lock, flags); 922 - kfree(xhci->dbc); 923 - xhci->dbc = NULL; 924 - spin_unlock_irqrestore(&xhci->lock, flags); 925 - } 926 - 927 - static int xhci_do_dbc_init(struct xhci_hcd *xhci) 928 - { 929 - u32 reg; 930 - struct xhci_dbc *dbc; 931 - unsigned long flags; 932 - void __iomem *base; 933 - int dbc_cap_offs; 934 - 935 - base = &xhci->cap_regs->hc_capbase; 936 - dbc_cap_offs = xhci_find_next_ext_cap(base, 0, XHCI_EXT_CAPS_DEBUG); 937 - if (!dbc_cap_offs) 938 - return -ENODEV; 939 - 940 - dbc = kzalloc(sizeof(*dbc), GFP_KERNEL); 941 - if (!dbc) 942 - return -ENOMEM; 943 - 944 - dbc->regs = base + dbc_cap_offs; 945 - 946 - /* We will avoid using DbC in xhci driver if it's in use. */ 947 - reg = readl(&dbc->regs->control); 948 - if (reg & DBC_CTRL_DBC_ENABLE) { 949 - kfree(dbc); 950 - return -EBUSY; 951 - } 952 - 953 - spin_lock_irqsave(&xhci->lock, flags); 954 - if (xhci->dbc) { 955 - spin_unlock_irqrestore(&xhci->lock, flags); 956 - kfree(dbc); 957 - return -EBUSY; 958 - } 959 - xhci->dbc = dbc; 960 - spin_unlock_irqrestore(&xhci->lock, flags); 961 - 962 - dbc->xhci = xhci; 963 - dbc->dev = xhci_to_hcd(xhci)->self.sysdev; 964 - INIT_DELAYED_WORK(&dbc->event_work, xhci_dbc_handle_events); 965 - spin_lock_init(&dbc->lock); 966 - 967 - return 0; 968 - } 969 - 970 917 static ssize_t dbc_show(struct device *dev, 971 918 struct device_attribute *attr, 972 919 char *buf) ··· 973 1026 974 1027 static DEVICE_ATTR_RW(dbc); 975 1028 976 - int xhci_dbc_init(struct xhci_hcd *xhci) 1029 + struct xhci_dbc * 1030 + xhci_alloc_dbc(struct device *dev, void __iomem *base, const struct dbc_driver *driver) 977 1031 { 1032 + struct xhci_dbc *dbc; 978 1033 int ret; 979 - struct device *dev = xhci_to_hcd(xhci)->self.controller; 980 1034 981 - ret = xhci_do_dbc_init(xhci); 982 - if (ret) 983 - goto init_err3; 1035 + dbc = kzalloc(sizeof(*dbc), GFP_KERNEL); 1036 + if (!dbc) 1037 + return NULL; 984 1038 985 - ret = xhci_dbc_tty_probe(xhci); 986 - if (ret) 987 - goto init_err2; 1039 + dbc->regs = base; 1040 + dbc->dev = dev; 1041 + dbc->driver = driver; 1042 + 1043 + if (readl(&dbc->regs->control) & DBC_CTRL_DBC_ENABLE) 1044 + return NULL; 1045 + 1046 + INIT_DELAYED_WORK(&dbc->event_work, xhci_dbc_handle_events); 1047 + spin_lock_init(&dbc->lock); 988 1048 989 1049 ret = device_create_file(dev, &dev_attr_dbc); 990 1050 if (ret) 991 - goto init_err1; 1051 + goto err; 992 1052 993 - return 0; 1053 + return dbc; 1054 + err: 1055 + kfree(dbc); 1056 + return NULL; 1057 + } 994 1058 995 - init_err1: 996 - xhci_dbc_tty_remove(xhci->dbc); 997 - init_err2: 998 - xhci_do_dbc_exit(xhci); 999 - init_err3: 1059 + /* undo what xhci_alloc_dbc() did */ 1060 + void xhci_dbc_remove(struct xhci_dbc *dbc) 1061 + { 1062 + if (!dbc) 1063 + return; 1064 + /* stop hw, stop wq and call dbc->ops->stop() */ 1065 + xhci_dbc_stop(dbc); 1066 + 1067 + /* remove sysfs files */ 1068 + device_remove_file(dbc->dev, &dev_attr_dbc); 1069 + 1070 + kfree(dbc); 1071 + } 1072 + 1073 + 1074 + int xhci_create_dbc_dev(struct xhci_hcd *xhci) 1075 + { 1076 + struct device *dev; 1077 + void __iomem *base; 1078 + int ret; 1079 + int dbc_cap_offs; 1080 + 1081 + /* create all parameters needed resembling a dbc device */ 1082 + dev = xhci_to_hcd(xhci)->self.controller; 1083 + base = &xhci->cap_regs->hc_capbase; 1084 + 1085 + dbc_cap_offs = xhci_find_next_ext_cap(base, 0, XHCI_EXT_CAPS_DEBUG); 1086 + if (!dbc_cap_offs) 1087 + return -ENODEV; 1088 + 1089 + /* already allocated and in use */ 1090 + if (xhci->dbc) 1091 + return -EBUSY; 1092 + 1093 + ret = xhci_dbc_tty_probe(dev, base + dbc_cap_offs, xhci); 1094 + 1000 1095 return ret; 1001 1096 } 1002 1097 1003 - void xhci_dbc_exit(struct xhci_hcd *xhci) 1098 + void xhci_remove_dbc_dev(struct xhci_hcd *xhci) 1004 1099 { 1005 - struct device *dev = xhci_to_hcd(xhci)->self.controller; 1100 + unsigned long flags; 1006 1101 1007 1102 if (!xhci->dbc) 1008 1103 return; 1009 1104 1010 - device_remove_file(dev, &dev_attr_dbc); 1011 1105 xhci_dbc_tty_remove(xhci->dbc); 1012 - xhci_dbc_stop(xhci->dbc); 1013 - xhci_do_dbc_exit(xhci); 1106 + spin_lock_irqsave(&xhci->lock, flags); 1107 + xhci->dbc = NULL; 1108 + spin_unlock_irqrestore(&xhci->lock, flags); 1014 1109 } 1015 1110 1016 1111 #ifdef CONFIG_PM ··· 1087 1098 return ret; 1088 1099 } 1089 1100 #endif /* CONFIG_PM */ 1101 + 1102 + int xhci_dbc_init(void) 1103 + { 1104 + return dbc_tty_init(); 1105 + } 1106 + 1107 + void xhci_dbc_exit(void) 1108 + { 1109 + dbc_tty_exit(); 1110 + }
+20 -6
drivers/usb/host/xhci-dbgcap.h
··· 100 100 struct dbc_port { 101 101 struct tty_port port; 102 102 spinlock_t port_lock; /* port access */ 103 + int minor; 103 104 104 105 struct list_head read_pool; 105 106 struct list_head read_queue; ··· 195 194 } 196 195 197 196 #ifdef CONFIG_USB_XHCI_DBGCAP 198 - int xhci_dbc_init(struct xhci_hcd *xhci); 199 - void xhci_dbc_exit(struct xhci_hcd *xhci); 200 - int xhci_dbc_tty_probe(struct xhci_hcd *xhci); 197 + int xhci_create_dbc_dev(struct xhci_hcd *xhci); 198 + void xhci_remove_dbc_dev(struct xhci_hcd *xhci); 199 + int xhci_dbc_init(void); 200 + void xhci_dbc_exit(void); 201 + int dbc_tty_init(void); 202 + void dbc_tty_exit(void); 203 + int xhci_dbc_tty_probe(struct device *dev, void __iomem *res, struct xhci_hcd *xhci); 201 204 void xhci_dbc_tty_remove(struct xhci_dbc *dbc); 205 + struct xhci_dbc *xhci_alloc_dbc(struct device *dev, void __iomem *res, 206 + const struct dbc_driver *driver); 207 + void xhci_dbc_remove(struct xhci_dbc *dbc); 202 208 struct dbc_request *dbc_alloc_request(struct xhci_dbc *dbc, 203 209 unsigned int direction, 204 210 gfp_t flags); ··· 216 208 int xhci_dbc_resume(struct xhci_hcd *xhci); 217 209 #endif /* CONFIG_PM */ 218 210 #else 219 - static inline int xhci_dbc_init(struct xhci_hcd *xhci) 211 + static inline int xhci_create_dbc_dev(struct xhci_hcd *xhci) 220 212 { 221 213 return 0; 222 214 } 223 215 224 - static inline void xhci_dbc_exit(struct xhci_hcd *xhci) 216 + static inline void xhci_remove_dbc_dev(struct xhci_hcd *xhci) 225 217 { 226 218 } 227 - 219 + static inline int xhci_dbc_init(void) 220 + { 221 + return 0; 222 + } 223 + static inline void xhci_dbc_exit(void) 224 + { 225 + } 228 226 static inline int xhci_dbc_suspend(struct xhci_hcd *xhci) 229 227 { 230 228 return 0;
+57 -29
drivers/usb/host/xhci-dbgtty.c
··· 10 10 #include <linux/slab.h> 11 11 #include <linux/tty.h> 12 12 #include <linux/tty_flip.h> 13 + #include <linux/idr.h> 13 14 14 15 #include "xhci.h" 15 16 #include "xhci-dbgcap.h" 16 17 17 - static int dbc_tty_init(void); 18 - static void dbc_tty_exit(void); 19 - 20 18 static struct tty_driver *dbc_tty_driver; 19 + static struct idr dbc_tty_minors; 20 + static DEFINE_MUTEX(dbc_tty_minors_lock); 21 21 22 22 static inline struct dbc_port *dbc_to_port(struct xhci_dbc *dbc) 23 23 { ··· 180 180 181 181 static int dbc_tty_install(struct tty_driver *driver, struct tty_struct *tty) 182 182 { 183 - struct dbc_port *port = driver->driver_state; 183 + struct dbc_port *port; 184 + 185 + mutex_lock(&dbc_tty_minors_lock); 186 + port = idr_find(&dbc_tty_minors, tty->index); 187 + mutex_unlock(&dbc_tty_minors_lock); 188 + 189 + if (!port) 190 + return -ENXIO; 184 191 185 192 tty->driver_data = port; 186 193 ··· 416 409 417 410 xhci_dbc_tty_init_port(dbc, port); 418 411 412 + mutex_lock(&dbc_tty_minors_lock); 413 + port->minor = idr_alloc(&dbc_tty_minors, port, 0, 64, GFP_KERNEL); 414 + mutex_unlock(&dbc_tty_minors_lock); 415 + 416 + if (port->minor < 0) { 417 + ret = port->minor; 418 + goto err_idr; 419 + } 420 + 419 421 ret = kfifo_alloc(&port->write_fifo, DBC_WRITE_BUF_SIZE, GFP_KERNEL); 420 422 if (ret) 421 423 goto err_exit_port; ··· 440 424 goto err_free_requests; 441 425 442 426 tty_dev = tty_port_register_device(&port->port, 443 - dbc_tty_driver, 0, NULL); 427 + dbc_tty_driver, port->minor, NULL); 444 428 if (IS_ERR(tty_dev)) { 445 429 ret = PTR_ERR(tty_dev); 446 430 goto err_free_requests; ··· 456 440 err_free_fifo: 457 441 kfifo_free(&port->write_fifo); 458 442 err_exit_port: 443 + idr_remove(&dbc_tty_minors, port->minor); 444 + err_idr: 459 445 xhci_dbc_tty_exit_port(port); 460 446 461 447 dev_err(dbc->dev, "can't register tty port, err %d\n", ret); ··· 471 453 472 454 if (!port->registered) 473 455 return; 474 - tty_unregister_device(dbc_tty_driver, 0); 456 + tty_unregister_device(dbc_tty_driver, port->minor); 475 457 xhci_dbc_tty_exit_port(port); 476 458 port->registered = false; 459 + 460 + mutex_lock(&dbc_tty_minors_lock); 461 + idr_remove(&dbc_tty_minors, port->minor); 462 + mutex_unlock(&dbc_tty_minors_lock); 477 463 478 464 kfifo_free(&port->write_fifo); 479 465 xhci_dbc_free_requests(&port->read_pool); ··· 490 468 .disconnect = xhci_dbc_tty_unregister_device, 491 469 }; 492 470 493 - int xhci_dbc_tty_probe(struct xhci_hcd *xhci) 471 + int xhci_dbc_tty_probe(struct device *dev, void __iomem *base, struct xhci_hcd *xhci) 494 472 { 495 - struct xhci_dbc *dbc = xhci->dbc; 473 + struct xhci_dbc *dbc; 496 474 struct dbc_port *port; 497 475 int status; 498 476 499 - /* dbc_tty_init will be called by module init() in the future */ 500 - status = dbc_tty_init(); 501 - if (status) 502 - return status; 477 + if (!dbc_tty_driver) 478 + return -ENODEV; 503 479 504 480 port = kzalloc(sizeof(*port), GFP_KERNEL); 505 - if (!port) { 481 + if (!port) 482 + return -ENOMEM; 483 + 484 + dbc = xhci_alloc_dbc(dev, base, &dbc_driver); 485 + 486 + if (!dbc) { 506 487 status = -ENOMEM; 507 - goto out; 488 + goto out2; 508 489 } 509 490 510 - dbc->driver = &dbc_driver; 511 491 dbc->priv = port; 512 492 513 - 514 - dbc_tty_driver->driver_state = port; 493 + /* get rid of xhci once this is a real driver binding to a device */ 494 + xhci->dbc = dbc; 515 495 516 496 return 0; 517 - out: 518 - /* dbc_tty_exit will be called by module_exit() in the future */ 519 - dbc_tty_exit(); 497 + out2: 498 + kfree(port); 499 + 520 500 return status; 521 501 } 522 502 ··· 530 506 { 531 507 struct dbc_port *port = dbc_to_port(dbc); 532 508 533 - dbc->driver = NULL; 534 - dbc->priv = NULL; 509 + xhci_dbc_remove(dbc); 535 510 kfree(port); 536 - 537 - /* dbc_tty_exit will be called by module_exit() in the future */ 538 - dbc_tty_exit(); 539 511 } 540 512 541 - static int dbc_tty_init(void) 513 + int dbc_tty_init(void) 542 514 { 543 515 int ret; 544 516 545 - dbc_tty_driver = tty_alloc_driver(1, TTY_DRIVER_REAL_RAW | 517 + idr_init(&dbc_tty_minors); 518 + 519 + dbc_tty_driver = tty_alloc_driver(64, TTY_DRIVER_REAL_RAW | 546 520 TTY_DRIVER_DYNAMIC_DEV); 547 - if (IS_ERR(dbc_tty_driver)) 521 + if (IS_ERR(dbc_tty_driver)) { 522 + idr_destroy(&dbc_tty_minors); 548 523 return PTR_ERR(dbc_tty_driver); 524 + } 549 525 550 526 dbc_tty_driver->driver_name = "dbc_serial"; 551 527 dbc_tty_driver->name = "ttyDBC"; ··· 564 540 if (ret) { 565 541 pr_err("Can't register dbc tty driver\n"); 566 542 tty_driver_kref_put(dbc_tty_driver); 543 + idr_destroy(&dbc_tty_minors); 567 544 } 545 + 568 546 return ret; 569 547 } 570 548 571 - static void dbc_tty_exit(void) 549 + void dbc_tty_exit(void) 572 550 { 573 551 if (dbc_tty_driver) { 574 552 tty_unregister_driver(dbc_tty_driver); 575 553 tty_driver_kref_put(dbc_tty_driver); 576 554 dbc_tty_driver = NULL; 577 555 } 556 + 557 + idr_destroy(&dbc_tty_minors); 578 558 }
+4 -1
drivers/usb/host/xhci-hub.c
··· 762 762 } 763 763 pm_runtime_allow(xhci_to_hcd(xhci)->self.controller); 764 764 xhci->test_mode = 0; 765 - return xhci_reset(xhci); 765 + return xhci_reset(xhci, XHCI_RESET_SHORT_USEC); 766 766 } 767 767 768 768 void xhci_set_link_state(struct xhci_hcd *xhci, struct xhci_port *port, ··· 1088 1088 if (link_state == XDEV_U2) 1089 1089 *status |= USB_PORT_STAT_L1; 1090 1090 if (link_state == XDEV_U0) { 1091 + if (bus_state->resume_done[portnum]) 1092 + usb_hcd_end_port_resume(&port->rhub->hcd->self, 1093 + portnum); 1091 1094 bus_state->resume_done[portnum] = 0; 1092 1095 clear_bit(portnum, &bus_state->resuming_ports); 1093 1096 if (bus_state->suspended_ports & (1 << portnum)) {
+5 -17
drivers/usb/host/xhci-mem.c
··· 57 57 /* If the cycle state is 0, set the cycle bit to 1 for all the TRBs */ 58 58 if (cycle_state == 0) { 59 59 for (i = 0; i < TRBS_PER_SEGMENT; i++) 60 - seg->trbs[i].link.control |= cpu_to_le32(TRB_CYCLE); 60 + seg->trbs[i].link.control = cpu_to_le32(TRB_CYCLE); 61 61 } 62 62 seg->dma = dma; 63 63 seg->next = NULL; ··· 433 433 (TRBS_PER_SEGMENT - 1); 434 434 435 435 /* Allocate number of segments we needed, or double the ring size */ 436 - num_segs = ring->num_segs > num_segs_needed ? 437 - ring->num_segs : num_segs_needed; 436 + num_segs = max(ring->num_segs, num_segs_needed); 438 437 439 438 ret = xhci_alloc_segments_for_ring(xhci, &first, &last, 440 439 num_segs, ring->cycle_state, ring->type, ··· 1845 1846 xhci->event_ring = NULL; 1846 1847 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Freed event ring"); 1847 1848 1848 - if (xhci->lpm_command) 1849 - xhci_free_command(xhci, xhci->lpm_command); 1850 - xhci->lpm_command = NULL; 1851 1849 if (xhci->cmd_ring) 1852 1850 xhci_ring_free(xhci, xhci->cmd_ring); 1853 1851 xhci->cmd_ring = NULL; ··· 2391 2395 page_size = readl(&xhci->op_regs->page_size); 2392 2396 xhci_dbg_trace(xhci, trace_xhci_dbg_init, 2393 2397 "Supported page size register = 0x%x", page_size); 2394 - for (i = 0; i < 16; i++) { 2395 - if ((0x1 & page_size) != 0) 2396 - break; 2397 - page_size = page_size >> 1; 2398 - } 2398 + i = ffs(page_size); 2399 2399 if (i < 16) 2400 2400 xhci_dbg_trace(xhci, trace_xhci_dbg_init, 2401 2401 "Supported page size of %iK", (1 << (i+12)) / 1024); ··· 2417 2425 writel(val, &xhci->op_regs->config_reg); 2418 2426 2419 2427 /* 2420 - * xHCI section 5.4.6 - doorbell array must be 2428 + * xHCI section 5.4.6 - Device Context array must be 2421 2429 * "physically contiguous and 64-byte (cache line) aligned". 2422 2430 */ 2423 2431 xhci->dcbaa = dma_alloc_coherent(dev, sizeof(*xhci->dcbaa), &dma, ··· 2479 2487 xhci_dbg_trace(xhci, trace_xhci_dbg_init, 2480 2488 "// Setting command ring address to 0x%016llx", val_64); 2481 2489 xhci_write_64(xhci, val_64, &xhci->op_regs->cmd_ring); 2482 - 2483 - xhci->lpm_command = xhci_alloc_command_with_ctx(xhci, true, flags); 2484 - if (!xhci->lpm_command) 2485 - goto fail; 2486 2490 2487 2491 /* Reserve one command ring TRB for disabling LPM. 2488 2492 * Since the USB core grabs the shared usb_bus bandwidth mutex before ··· 2571 2583 2572 2584 fail: 2573 2585 xhci_halt(xhci); 2574 - xhci_reset(xhci); 2586 + xhci_reset(xhci, XHCI_RESET_SHORT_USEC); 2575 2587 xhci_mem_cleanup(xhci); 2576 2588 return -ENOMEM; 2577 2589 }
+3 -4
drivers/usb/host/xhci-mtk-sch.c
··· 248 248 struct mu3h_sch_bw_info *bw_info; 249 249 struct mu3h_sch_tt *tt = NULL; 250 250 u32 len_bw_budget_table; 251 - size_t mem_size; 252 251 253 252 bw_info = get_bw_info(mtk, udev, ep); 254 253 if (!bw_info) ··· 261 262 else 262 263 len_bw_budget_table = 1; 263 264 264 - mem_size = sizeof(struct mu3h_sch_ep_info) + 265 - len_bw_budget_table * sizeof(u32); 266 - sch_ep = kzalloc(mem_size, GFP_KERNEL); 265 + sch_ep = kzalloc(struct_size(sch_ep, bw_budget_table, 266 + len_bw_budget_table), 267 + GFP_KERNEL); 267 268 if (!sch_ep) 268 269 return ERR_PTR(-ENOMEM); 269 270
+48 -33
drivers/usb/host/xhci-mtk.c
··· 95 95 #define WC0_SSUSB0_CDEN BIT(6) 96 96 #define WC0_IS_SPM_EN BIT(1) 97 97 98 + /* mt8195 */ 99 + #define PERI_WK_CTRL0_8195 0x04 100 + #define WC0_IS_P_95 BIT(30) /* polarity */ 101 + #define WC0_IS_C_95(x) ((u32)(((x) & 0x7) << 27)) 102 + #define WC0_IS_EN_P3_95 BIT(26) 103 + #define WC0_IS_EN_P2_95 BIT(25) 104 + #define WC0_IS_EN_P1_95 BIT(24) 105 + 106 + #define PERI_WK_CTRL1_8195 0x20 107 + #define WC1_IS_C_95(x) ((u32)(((x) & 0xf) << 28)) 108 + #define WC1_IS_P_95 BIT(12) 109 + #define WC1_IS_EN_P0_95 BIT(6) 110 + 98 111 /* mt2712 etc */ 99 112 #define PERI_SSUSB_SPM_CTRL 0x0 100 113 #define SSC_IP_SLEEP_EN BIT(4) ··· 118 105 SSUSB_UWK_V2, 119 106 SSUSB_UWK_V1_1 = 101, /* specific revision 1.01 */ 120 107 SSUSB_UWK_V1_2, /* specific revision 1.2 */ 108 + SSUSB_UWK_V1_3, /* mt8195 IP0 */ 109 + SSUSB_UWK_V1_4, /* mt8195 IP1 */ 110 + SSUSB_UWK_V1_5, /* mt8195 IP2 */ 111 + SSUSB_UWK_V1_6, /* mt8195 IP3 */ 121 112 }; 122 113 123 114 /* ··· 325 308 msk = WC0_SSUSB0_CDEN | WC0_IS_SPM_EN; 326 309 val = enable ? msk : 0; 327 310 break; 311 + case SSUSB_UWK_V1_3: 312 + reg = mtk->uwk_reg_base + PERI_WK_CTRL1_8195; 313 + msk = WC1_IS_EN_P0_95 | WC1_IS_C_95(0xf) | WC1_IS_P_95; 314 + val = enable ? (WC1_IS_EN_P0_95 | WC1_IS_C_95(0x1)) : 0; 315 + break; 316 + case SSUSB_UWK_V1_4: 317 + reg = mtk->uwk_reg_base + PERI_WK_CTRL0_8195; 318 + msk = WC0_IS_EN_P1_95 | WC0_IS_C_95(0x7) | WC0_IS_P_95; 319 + val = enable ? (WC0_IS_EN_P1_95 | WC0_IS_C_95(0x1)) : 0; 320 + break; 321 + case SSUSB_UWK_V1_5: 322 + reg = mtk->uwk_reg_base + PERI_WK_CTRL0_8195; 323 + msk = WC0_IS_EN_P2_95 | WC0_IS_C_95(0x7) | WC0_IS_P_95; 324 + val = enable ? (WC0_IS_EN_P2_95 | WC0_IS_C_95(0x1)) : 0; 325 + break; 326 + case SSUSB_UWK_V1_6: 327 + reg = mtk->uwk_reg_base + PERI_WK_CTRL0_8195; 328 + msk = WC0_IS_EN_P3_95 | WC0_IS_C_95(0x7) | WC0_IS_P_95; 329 + val = enable ? (WC0_IS_EN_P3_95 | WC0_IS_C_95(0x1)) : 0; 330 + break; 328 331 case SSUSB_UWK_V2: 329 332 reg = mtk->uwk_reg_base + PERI_SSUSB_SPM_CTRL; 330 333 msk = SSC_IP_SLEEP_EN | SSC_SPM_INT_EN; ··· 401 364 return devm_clk_bulk_get_optional(mtk->dev, BULK_CLKS_NUM, clks); 402 365 } 403 366 404 - static int xhci_mtk_ldos_enable(struct xhci_hcd_mtk *mtk) 367 + static int xhci_mtk_vregs_get(struct xhci_hcd_mtk *mtk) 405 368 { 406 - int ret; 369 + struct regulator_bulk_data *supplies = mtk->supplies; 407 370 408 - ret = regulator_enable(mtk->vbus); 409 - if (ret) { 410 - dev_err(mtk->dev, "failed to enable vbus\n"); 411 - return ret; 412 - } 371 + supplies[0].supply = "vbus"; 372 + supplies[1].supply = "vusb33"; 413 373 414 - ret = regulator_enable(mtk->vusb33); 415 - if (ret) { 416 - dev_err(mtk->dev, "failed to enable vusb33\n"); 417 - regulator_disable(mtk->vbus); 418 - return ret; 419 - } 420 - return 0; 421 - } 422 - 423 - static void xhci_mtk_ldos_disable(struct xhci_hcd_mtk *mtk) 424 - { 425 - regulator_disable(mtk->vbus); 426 - regulator_disable(mtk->vusb33); 374 + return devm_regulator_bulk_get(mtk->dev, BULK_VREGS_NUM, supplies); 427 375 } 428 376 429 377 static void xhci_mtk_quirks(struct device *dev, struct xhci_hcd *xhci) ··· 498 476 return -ENOMEM; 499 477 500 478 mtk->dev = dev; 501 - mtk->vbus = devm_regulator_get(dev, "vbus"); 502 - if (IS_ERR(mtk->vbus)) { 503 - dev_err(dev, "fail to get vbus\n"); 504 - return PTR_ERR(mtk->vbus); 505 - } 506 479 507 - mtk->vusb33 = devm_regulator_get(dev, "vusb33"); 508 - if (IS_ERR(mtk->vusb33)) { 509 - dev_err(dev, "fail to get vusb33\n"); 510 - return PTR_ERR(mtk->vusb33); 511 - } 480 + ret = xhci_mtk_vregs_get(mtk); 481 + if (ret) 482 + return dev_err_probe(dev, ret, "Failed to get regulators\n"); 512 483 513 484 ret = xhci_mtk_clks_get(mtk); 514 485 if (ret) ··· 542 527 pm_runtime_enable(dev); 543 528 pm_runtime_get_sync(dev); 544 529 545 - ret = xhci_mtk_ldos_enable(mtk); 530 + ret = regulator_bulk_enable(BULK_VREGS_NUM, mtk->supplies); 546 531 if (ret) 547 532 goto disable_pm; 548 533 ··· 651 636 clk_bulk_disable_unprepare(BULK_CLKS_NUM, mtk->clks); 652 637 653 638 disable_ldos: 654 - xhci_mtk_ldos_disable(mtk); 639 + regulator_bulk_disable(BULK_VREGS_NUM, mtk->supplies); 655 640 656 641 disable_pm: 657 642 pm_runtime_put_noidle(dev); ··· 679 664 usb_put_hcd(hcd); 680 665 xhci_mtk_sch_exit(mtk); 681 666 clk_bulk_disable_unprepare(BULK_CLKS_NUM, mtk->clks); 682 - xhci_mtk_ldos_disable(mtk); 667 + regulator_bulk_disable(BULK_VREGS_NUM, mtk->supplies); 683 668 684 669 pm_runtime_disable(dev); 685 670 pm_runtime_put_noidle(dev);
+3 -2
drivers/usb/host/xhci-mtk.h
··· 11 11 12 12 #include <linux/clk.h> 13 13 #include <linux/hashtable.h> 14 + #include <linux/regulator/consumer.h> 14 15 15 16 #include "xhci.h" 16 17 17 18 #define BULK_CLKS_NUM 5 19 + #define BULK_VREGS_NUM 2 18 20 19 21 /* support at most 64 ep, use 32 size hash table */ 20 22 #define SCH_EP_HASH_BITS 5 ··· 152 150 int num_u3_ports; 153 151 int u2p_dis_msk; 154 152 int u3p_dis_msk; 155 - struct regulator *vusb33; 156 - struct regulator *vbus; 157 153 struct clk_bulk_data clks[BULK_CLKS_NUM]; 154 + struct regulator_bulk_data supplies[BULK_VREGS_NUM]; 158 155 unsigned int has_ippc:1; 159 156 unsigned int lpm_support:1; 160 157 unsigned int u2_lpm_disable:1;
+3 -10
drivers/usb/host/xhci-plat.c
··· 226 226 if (!sysdev) 227 227 sysdev = &pdev->dev; 228 228 229 - /* Try to set 64-bit DMA first */ 230 229 if (WARN_ON(!sysdev->dma_mask)) 231 230 /* Platform did not initialize dma_mask */ 232 - ret = dma_coerce_mask_and_coherent(sysdev, 233 - DMA_BIT_MASK(64)); 231 + ret = dma_coerce_mask_and_coherent(sysdev, DMA_BIT_MASK(64)); 234 232 else 235 233 ret = dma_set_mask_and_coherent(sysdev, DMA_BIT_MASK(64)); 236 - 237 - /* If seting 64-bit DMA mask fails, fall back to 32-bit DMA mask */ 238 - if (ret) { 239 - ret = dma_set_mask_and_coherent(sysdev, DMA_BIT_MASK(32)); 240 - if (ret) 241 - return ret; 242 - } 234 + if (ret) 235 + return ret; 243 236 244 237 pm_runtime_set_active(&pdev->dev); 245 238 pm_runtime_enable(&pdev->dev);
+1 -1
drivers/usb/host/xhci-rcar.c
··· 82 82 .soc_id = "r8a7795", .revision = "ES1.*", 83 83 .data = (void *)RCAR_XHCI_FIRMWARE_V2, 84 84 }, 85 - { /* sentinel */ }, 85 + { /* sentinel */ } 86 86 }; 87 87 88 88 static void xhci_rcar_start_gen2(struct usb_hcd *hcd)
+29 -36
drivers/usb/host/xhci.c
··· 65 65 * handshake done). There are two failure modes: "usec" have passed (major 66 66 * hardware flakeout), or the register reads as all-ones (hardware removed). 67 67 */ 68 - int xhci_handshake(void __iomem *ptr, u32 mask, u32 done, int usec) 68 + int xhci_handshake(void __iomem *ptr, u32 mask, u32 done, u64 timeout_us) 69 69 { 70 70 u32 result; 71 71 int ret; ··· 73 73 ret = readl_poll_timeout_atomic(ptr, result, 74 74 (result & mask) == done || 75 75 result == U32_MAX, 76 - 1, usec); 76 + 1, timeout_us); 77 77 if (result == U32_MAX) /* card removed */ 78 78 return -ENODEV; 79 79 ··· 110 110 int xhci_halt(struct xhci_hcd *xhci) 111 111 { 112 112 int ret; 113 + 113 114 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "// Halt the HC"); 114 115 xhci_quiesce(xhci); 115 116 ··· 120 119 xhci_warn(xhci, "Host halt failed, %d\n", ret); 121 120 return ret; 122 121 } 122 + 123 123 xhci->xhc_state |= XHCI_STATE_HALTED; 124 124 xhci->cmd_ring_state = CMD_RING_STATE_STOPPED; 125 + 125 126 return ret; 126 127 } 127 128 ··· 165 162 * Transactions will be terminated immediately, and operational registers 166 163 * will be set to their defaults. 167 164 */ 168 - int xhci_reset(struct xhci_hcd *xhci) 165 + int xhci_reset(struct xhci_hcd *xhci, u64 timeout_us) 169 166 { 170 167 u32 command; 171 168 u32 state; ··· 198 195 if (xhci->quirks & XHCI_INTEL_HOST) 199 196 udelay(1000); 200 197 201 - ret = xhci_handshake(&xhci->op_regs->command, 202 - CMD_RESET, 0, 10 * 1000 * 1000); 198 + ret = xhci_handshake(&xhci->op_regs->command, CMD_RESET, 0, timeout_us); 203 199 if (ret) 204 200 return ret; 205 201 ··· 211 209 * xHCI cannot write to any doorbells or operational registers other 212 210 * than status until the "Controller Not Ready" flag is cleared. 213 211 */ 214 - ret = xhci_handshake(&xhci->op_regs->status, 215 - STS_CNR, 0, 10 * 1000 * 1000); 212 + ret = xhci_handshake(&xhci->op_regs->status, STS_CNR, 0, timeout_us); 216 213 217 214 xhci->usb2_rhub.bus_state.port_c_suspend = 0; 218 215 xhci->usb2_rhub.bus_state.suspended_ports = 0; ··· 325 324 */ 326 325 static int xhci_setup_msix(struct xhci_hcd *xhci) 327 326 { 328 - int i, ret = 0; 327 + int i, ret; 329 328 struct usb_hcd *hcd = xhci_to_hcd(xhci); 330 329 struct pci_dev *pdev = to_pci_dev(hcd->self.controller); 331 330 ··· 579 578 static int xhci_init(struct usb_hcd *hcd) 580 579 { 581 580 struct xhci_hcd *xhci = hcd_to_xhci(hcd); 582 - int retval = 0; 581 + int retval; 583 582 584 583 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "xhci_init"); 585 584 spin_lock_init(&xhci->lock); ··· 696 695 xhci_dbg_trace(xhci, trace_xhci_dbg_init, 697 696 "Finished xhci_run for USB2 roothub"); 698 697 699 - xhci_dbc_init(xhci); 698 + xhci_create_dbc_dev(xhci); 700 699 701 700 xhci_debugfs_init(xhci); 702 701 ··· 726 725 return; 727 726 } 728 727 729 - xhci_dbc_exit(xhci); 728 + xhci_remove_dbc_dev(xhci); 730 729 731 730 spin_lock_irq(&xhci->lock); 732 731 xhci->xhc_state |= XHCI_STATE_HALTED; 733 732 xhci->cmd_ring_state = CMD_RING_STATE_STOPPED; 734 733 xhci_halt(xhci); 735 - xhci_reset(xhci); 734 + xhci_reset(xhci, XHCI_RESET_SHORT_USEC); 736 735 spin_unlock_irq(&xhci->lock); 737 736 738 737 xhci_cleanup_msix(xhci); ··· 785 784 xhci_halt(xhci); 786 785 /* Workaround for spurious wakeups at shutdown with HSW */ 787 786 if (xhci->quirks & XHCI_SPURIOUS_WAKEUP) 788 - xhci_reset(xhci); 787 + xhci_reset(xhci, XHCI_RESET_SHORT_USEC); 789 788 spin_unlock_irq(&xhci->lock); 790 789 791 790 xhci_cleanup_msix(xhci); ··· 1171 1170 xhci_dbg(xhci, "Stop HCD\n"); 1172 1171 xhci_halt(xhci); 1173 1172 xhci_zero_64b_regs(xhci); 1174 - retval = xhci_reset(xhci); 1173 + retval = xhci_reset(xhci, XHCI_RESET_LONG_USEC); 1175 1174 spin_unlock_irq(&xhci->lock); 1176 1175 if (retval) 1177 1176 return retval; ··· 3161 3160 3162 3161 ep_index = xhci_get_endpoint_index(&host_ep->desc); 3163 3162 ep = &vdev->eps[ep_index]; 3164 - if (!ep) 3165 - goto done; 3166 3163 3167 3164 /* wait for hub_tt_work to finish clearing hub TT */ 3168 3165 if (ep->ep_state & EP_CLEARING_TT) { ··· 3218 3219 return; 3219 3220 ep_index = xhci_get_endpoint_index(&host_ep->desc); 3220 3221 ep = &vdev->eps[ep_index]; 3221 - if (!ep) 3222 - return; 3223 3222 3224 3223 /* Bail out if toggle is already being cleared by a endpoint reset */ 3225 3224 spin_lock_irqsave(&xhci->lock, flags); ··· 3975 3978 struct xhci_command *command; 3976 3979 unsigned long flags; 3977 3980 u32 state; 3978 - int ret = 0; 3981 + int ret; 3979 3982 3980 3983 command = xhci_alloc_command(xhci, true, GFP_KERNEL); 3981 3984 if (!command) ··· 4011 4014 4012 4015 xhci_free_command(xhci, command); 4013 4016 4014 - return ret; 4017 + return 0; 4015 4018 } 4016 4019 4017 4020 /* ··· 4351 4354 unsigned long flags; 4352 4355 int ret; 4353 4356 4357 + command = xhci_alloc_command_with_ctx(xhci, true, GFP_KERNEL); 4358 + if (!command) 4359 + return -ENOMEM; 4360 + 4354 4361 spin_lock_irqsave(&xhci->lock, flags); 4355 4362 4356 4363 virt_dev = xhci->devs[udev->slot_id]; ··· 4371 4370 } 4372 4371 4373 4372 /* Attempt to issue an Evaluate Context command to change the MEL. */ 4374 - command = xhci->lpm_command; 4375 4373 ctrl_ctx = xhci_get_input_control_ctx(command->in_ctx); 4376 4374 if (!ctrl_ctx) { 4377 4375 spin_unlock_irqrestore(&xhci->lock, flags); 4376 + xhci_free_command(xhci, command); 4378 4377 xhci_warn(xhci, "%s: Could not get input context, bad type.\n", 4379 4378 __func__); 4380 4379 return -ENOMEM; ··· 4401 4400 virt_dev->current_mel = max_exit_latency; 4402 4401 spin_unlock_irqrestore(&xhci->lock, flags); 4403 4402 } 4403 + 4404 + xhci_free_command(xhci, command); 4405 + 4404 4406 return ret; 4405 4407 } 4406 4408 ··· 4524 4520 exit_latency = xhci_besl_encoding[hird]; 4525 4521 spin_unlock_irqrestore(&xhci->lock, flags); 4526 4522 4527 - /* USB 3.0 code dedicate one xhci->lpm_command->in_ctx 4528 - * input context for link powermanagement evaluate 4529 - * context commands. It is protected by hcd->bandwidth 4530 - * mutex and is shared by all devices. We need to set 4531 - * the max ext latency in USB 2 BESL LPM as well, so 4532 - * use the same mutex and xhci_change_max_exit_latency() 4533 - */ 4534 - mutex_lock(hcd->bandwidth_mutex); 4535 4523 ret = xhci_change_max_exit_latency(xhci, udev, 4536 4524 exit_latency); 4537 - mutex_unlock(hcd->bandwidth_mutex); 4538 - 4539 4525 if (ret < 0) 4540 4526 return ret; 4541 4527 spin_lock_irqsave(&xhci->lock, flags); ··· 4553 4559 readl(pm_addr); 4554 4560 if (udev->usb2_hw_lpm_besl_capable) { 4555 4561 spin_unlock_irqrestore(&xhci->lock, flags); 4556 - mutex_lock(hcd->bandwidth_mutex); 4557 4562 xhci_change_max_exit_latency(xhci, udev, 0); 4558 - mutex_unlock(hcd->bandwidth_mutex); 4559 4563 readl_poll_timeout(ports[port_num]->addr, pm_val, 4560 4564 (pm_val & PORT_PLS_MASK) == XDEV_U0, 4561 4565 100, 10000); ··· 5282 5290 xhci->hcs_params1 = readl(&xhci->cap_regs->hcs_params1); 5283 5291 xhci->hcs_params2 = readl(&xhci->cap_regs->hcs_params2); 5284 5292 xhci->hcs_params3 = readl(&xhci->cap_regs->hcs_params3); 5285 - xhci->hcc_params = readl(&xhci->cap_regs->hc_capbase); 5286 - xhci->hci_version = HC_VERSION(xhci->hcc_params); 5293 + xhci->hci_version = HC_VERSION(readl(&xhci->cap_regs->hc_capbase)); 5287 5294 xhci->hcc_params = readl(&xhci->cap_regs->hcc_params); 5288 5295 if (xhci->hci_version > 0x100) 5289 5296 xhci->hcc_params2 = readl(&xhci->cap_regs->hcc_params2); ··· 5307 5316 5308 5317 xhci_dbg(xhci, "Resetting HCD\n"); 5309 5318 /* Reset the internal HC memory state and registers. */ 5310 - retval = xhci_reset(xhci); 5319 + retval = xhci_reset(xhci, XHCI_RESET_LONG_USEC); 5311 5320 if (retval) 5312 5321 return retval; 5313 5322 xhci_dbg(xhci, "Reset complete\n"); ··· 5496 5505 return -ENODEV; 5497 5506 5498 5507 xhci_debugfs_create_root(); 5508 + xhci_dbc_init(); 5499 5509 5500 5510 return 0; 5501 5511 } ··· 5508 5516 static void __exit xhci_hcd_fini(void) 5509 5517 { 5510 5518 xhci_debugfs_remove_root(); 5519 + xhci_dbc_exit(); 5511 5520 } 5512 5521 5513 5522 module_init(xhci_hcd_init);
+11 -5
drivers/usb/host/xhci.h
··· 229 229 #define CMD_ETE (1 << 14) 230 230 /* bits 15:31 are reserved (and should be preserved on writes). */ 231 231 232 + #define XHCI_RESET_LONG_USEC (10 * 1000 * 1000) 233 + #define XHCI_RESET_SHORT_USEC (250 * 1000) 234 + 232 235 /* IMAN - Interrupt Management Register */ 233 236 #define IMAN_IE (1 << 1) 234 237 #define IMAN_IP (1 << 0) ··· 1815 1812 /* slot enabling and address device helpers */ 1816 1813 /* these are not thread safe so use mutex */ 1817 1814 struct mutex mutex; 1818 - /* For USB 3.0 LPM enable/disable. */ 1819 - struct xhci_command *lpm_command; 1820 1815 /* Internal mirror of the HW's dcbaa */ 1821 1816 struct xhci_virt_device *devs[MAX_HC_SLOTS]; 1822 1817 /* For keeping track of bandwidth domains per roothub. */ ··· 2084 2083 2085 2084 /* xHCI host controller glue */ 2086 2085 typedef void (*xhci_get_quirks_t)(struct device *, struct xhci_hcd *); 2087 - int xhci_handshake(void __iomem *ptr, u32 mask, u32 done, int usec); 2086 + int xhci_handshake(void __iomem *ptr, u32 mask, u32 done, u64 timeout_us); 2088 2087 void xhci_quiesce(struct xhci_hcd *xhci); 2089 2088 int xhci_halt(struct xhci_hcd *xhci); 2090 2089 int xhci_start(struct xhci_hcd *xhci); 2091 - int xhci_reset(struct xhci_hcd *xhci); 2090 + int xhci_reset(struct xhci_hcd *xhci, u64 timeout_us); 2092 2091 int xhci_run(struct usb_hcd *hcd); 2093 2092 int xhci_gen_setup(struct usb_hcd *hcd, xhci_get_quirks_t get_quirks); 2094 2093 void xhci_shutdown(struct usb_hcd *hcd); ··· 2468 2467 unsigned int bit; 2469 2468 int ret = 0; 2470 2469 2470 + str[0] = '\0'; 2471 + 2471 2472 if (drop) { 2472 2473 ret = sprintf(str, "Drop:"); 2473 2474 for_each_set_bit(bit, &drop, 32) ··· 2627 2624 { 2628 2625 int ret = 0; 2629 2626 2627 + ret = sprintf(str, " 0x%08x", usbsts); 2628 + 2630 2629 if (usbsts == ~(u32)0) 2631 - return " 0xffffffff"; 2630 + return str; 2631 + 2632 2632 if (usbsts & STS_HALT) 2633 2633 ret += sprintf(str + ret, " HCHalted"); 2634 2634 if (usbsts & STS_FATAL)
+2 -3
drivers/usb/isp1760/isp1760-hcd.c
··· 1768 1768 * Packetize urb->transfer_buffer into list of packets of size wMaxPacketSize. 1769 1769 * Also calculate the PID type (SETUP/IN/OUT) for each packet. 1770 1770 */ 1771 - #define max_packet(wMaxPacketSize) ((wMaxPacketSize) & 0x07ff) 1772 1771 static void packetize_urb(struct usb_hcd *hcd, 1773 1772 struct urb *urb, struct list_head *head, gfp_t flags) 1774 1773 { ··· 1808 1809 packet_type = IN_PID; 1809 1810 } 1810 1811 1811 - maxpacketsize = max_packet(usb_maxpacket(urb->dev, urb->pipe, 1812 - usb_pipeout(urb->pipe))); 1812 + maxpacketsize = usb_maxpacket(urb->dev, urb->pipe, 1813 + usb_pipeout(urb->pipe)); 1813 1814 1814 1815 /* 1815 1816 * buffer gets wrapped in one or more qtds;
+11
drivers/usb/misc/Kconfig
··· 137 137 Say Y here if you want to control the backlight of Apple Cinema 138 138 Displays over USB. This driver provides a sysfs interface. 139 139 140 + config USB_QCOM_EUD 141 + tristate "QCOM Embedded USB Debugger(EUD) Driver" 142 + depends on ARCH_QCOM || COMPILE_TEST 143 + select USB_ROLE_SWITCH 144 + help 145 + This module enables support for Qualcomm Technologies, Inc. 146 + Embedded USB Debugger (EUD). The EUD is a control peripheral 147 + which reports VBUS attach/detach events and has USB-based 148 + debug and trace capabilities. On selecting m, the module name 149 + that is built is qcom_eud.ko 150 + 140 151 config APPLE_MFI_FASTCHARGE 141 152 tristate "Fast charge control for iOS devices" 142 153 select POWER_SUPPLY
+1
drivers/usb/misc/Makefile
··· 18 18 obj-$(CONFIG_USB_LCD) += usblcd.o 19 19 obj-$(CONFIG_USB_LD) += ldusb.o 20 20 obj-$(CONFIG_USB_LEGOTOWER) += legousbtower.o 21 + obj-$(CONFIG_USB_QCOM_EUD) += qcom_eud.o 21 22 obj-$(CONFIG_USB_TEST) += usbtest.o 22 23 obj-$(CONFIG_USB_EHSET_TEST_FIXTURE) += ehset.o 23 24 obj-$(CONFIG_USB_TRANCEVIBRATOR) += trancevibrator.o
+251
drivers/usb/misc/qcom_eud.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + /* 3 + * Copyright (c) 2015-2021, The Linux Foundation. All rights reserved. 4 + */ 5 + 6 + #include <linux/bitops.h> 7 + #include <linux/err.h> 8 + #include <linux/interrupt.h> 9 + #include <linux/io.h> 10 + #include <linux/iopoll.h> 11 + #include <linux/kernel.h> 12 + #include <linux/module.h> 13 + #include <linux/of.h> 14 + #include <linux/platform_device.h> 15 + #include <linux/slab.h> 16 + #include <linux/sysfs.h> 17 + #include <linux/usb/role.h> 18 + 19 + #define EUD_REG_INT1_EN_MASK 0x0024 20 + #define EUD_REG_INT_STATUS_1 0x0044 21 + #define EUD_REG_CTL_OUT_1 0x0074 22 + #define EUD_REG_VBUS_INT_CLR 0x0080 23 + #define EUD_REG_CSR_EUD_EN 0x1014 24 + #define EUD_REG_SW_ATTACH_DET 0x1018 25 + #define EUD_REG_EUD_EN2 0x0000 26 + 27 + #define EUD_ENABLE BIT(0) 28 + #define EUD_INT_PET_EUD BIT(0) 29 + #define EUD_INT_VBUS BIT(2) 30 + #define EUD_INT_SAFE_MODE BIT(4) 31 + #define EUD_INT_ALL (EUD_INT_VBUS | EUD_INT_SAFE_MODE) 32 + 33 + struct eud_chip { 34 + struct device *dev; 35 + struct usb_role_switch *role_sw; 36 + void __iomem *base; 37 + void __iomem *mode_mgr; 38 + unsigned int int_status; 39 + int irq; 40 + bool enabled; 41 + bool usb_attached; 42 + }; 43 + 44 + static int enable_eud(struct eud_chip *priv) 45 + { 46 + writel(EUD_ENABLE, priv->base + EUD_REG_CSR_EUD_EN); 47 + writel(EUD_INT_VBUS | EUD_INT_SAFE_MODE, 48 + priv->base + EUD_REG_INT1_EN_MASK); 49 + writel(1, priv->mode_mgr + EUD_REG_EUD_EN2); 50 + 51 + return usb_role_switch_set_role(priv->role_sw, USB_ROLE_DEVICE); 52 + } 53 + 54 + static void disable_eud(struct eud_chip *priv) 55 + { 56 + writel(0, priv->base + EUD_REG_CSR_EUD_EN); 57 + writel(0, priv->mode_mgr + EUD_REG_EUD_EN2); 58 + } 59 + 60 + static ssize_t enable_show(struct device *dev, 61 + struct device_attribute *attr, char *buf) 62 + { 63 + struct eud_chip *chip = dev_get_drvdata(dev); 64 + 65 + return sysfs_emit(buf, "%d\n", chip->enabled); 66 + } 67 + 68 + static ssize_t enable_store(struct device *dev, 69 + struct device_attribute *attr, 70 + const char *buf, size_t count) 71 + { 72 + struct eud_chip *chip = dev_get_drvdata(dev); 73 + bool enable; 74 + int ret; 75 + 76 + if (kstrtobool(buf, &enable)) 77 + return -EINVAL; 78 + 79 + if (enable) { 80 + ret = enable_eud(chip); 81 + if (!ret) 82 + chip->enabled = enable; 83 + else 84 + disable_eud(chip); 85 + } else { 86 + disable_eud(chip); 87 + } 88 + 89 + return count; 90 + } 91 + 92 + static DEVICE_ATTR_RW(enable); 93 + 94 + static struct attribute *eud_attrs[] = { 95 + &dev_attr_enable.attr, 96 + NULL, 97 + }; 98 + ATTRIBUTE_GROUPS(eud); 99 + 100 + static void usb_attach_detach(struct eud_chip *chip) 101 + { 102 + u32 reg; 103 + 104 + /* read ctl_out_1[4] to find USB attach or detach event */ 105 + reg = readl(chip->base + EUD_REG_CTL_OUT_1); 106 + chip->usb_attached = reg & EUD_INT_SAFE_MODE; 107 + } 108 + 109 + static void pet_eud(struct eud_chip *chip) 110 + { 111 + u32 reg; 112 + int ret; 113 + 114 + /* When the EUD_INT_PET_EUD in SW_ATTACH_DET is set, the cable has been 115 + * disconnected and we need to detach the pet to check if EUD is in safe 116 + * mode before attaching again. 117 + */ 118 + reg = readl(chip->base + EUD_REG_SW_ATTACH_DET); 119 + if (reg & EUD_INT_PET_EUD) { 120 + /* Detach & Attach pet for EUD */ 121 + writel(0, chip->base + EUD_REG_SW_ATTACH_DET); 122 + /* Delay to make sure detach pet is done before attach pet */ 123 + ret = readl_poll_timeout(chip->base + EUD_REG_SW_ATTACH_DET, 124 + reg, (reg == 0), 1, 100); 125 + if (ret) { 126 + dev_err(chip->dev, "Detach pet failed\n"); 127 + return; 128 + } 129 + } 130 + /* Attach pet for EUD */ 131 + writel(EUD_INT_PET_EUD, chip->base + EUD_REG_SW_ATTACH_DET); 132 + } 133 + 134 + static irqreturn_t handle_eud_irq(int irq, void *data) 135 + { 136 + struct eud_chip *chip = data; 137 + u32 reg; 138 + 139 + reg = readl(chip->base + EUD_REG_INT_STATUS_1); 140 + switch (reg & EUD_INT_ALL) { 141 + case EUD_INT_VBUS: 142 + usb_attach_detach(chip); 143 + return IRQ_WAKE_THREAD; 144 + case EUD_INT_SAFE_MODE: 145 + pet_eud(chip); 146 + return IRQ_HANDLED; 147 + default: 148 + return IRQ_NONE; 149 + } 150 + } 151 + 152 + static irqreturn_t handle_eud_irq_thread(int irq, void *data) 153 + { 154 + struct eud_chip *chip = data; 155 + int ret; 156 + 157 + if (chip->usb_attached) 158 + ret = usb_role_switch_set_role(chip->role_sw, USB_ROLE_DEVICE); 159 + else 160 + ret = usb_role_switch_set_role(chip->role_sw, USB_ROLE_HOST); 161 + if (ret) 162 + dev_err(chip->dev, "failed to set role switch\n"); 163 + 164 + /* set and clear vbus_int_clr[0] to clear interrupt */ 165 + writel(BIT(0), chip->base + EUD_REG_VBUS_INT_CLR); 166 + writel(0, chip->base + EUD_REG_VBUS_INT_CLR); 167 + 168 + return IRQ_HANDLED; 169 + } 170 + 171 + static void eud_role_switch_release(void *data) 172 + { 173 + struct eud_chip *chip = data; 174 + 175 + usb_role_switch_put(chip->role_sw); 176 + } 177 + 178 + static int eud_probe(struct platform_device *pdev) 179 + { 180 + struct eud_chip *chip; 181 + int ret; 182 + 183 + chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL); 184 + if (!chip) 185 + return -ENOMEM; 186 + 187 + chip->dev = &pdev->dev; 188 + 189 + ret = devm_add_action_or_reset(chip->dev, eud_role_switch_release, chip); 190 + if (ret) 191 + return dev_err_probe(chip->dev, ret, 192 + "failed to add role switch release action\n"); 193 + 194 + chip->role_sw = usb_role_switch_get(&pdev->dev); 195 + if (IS_ERR(chip->role_sw)) 196 + return dev_err_probe(chip->dev, PTR_ERR(chip->role_sw), 197 + "failed to get role switch\n"); 198 + 199 + chip->base = devm_platform_ioremap_resource(pdev, 0); 200 + if (IS_ERR(chip->base)) 201 + return PTR_ERR(chip->base); 202 + 203 + chip->mode_mgr = devm_platform_ioremap_resource(pdev, 1); 204 + if (IS_ERR(chip->mode_mgr)) 205 + return PTR_ERR(chip->mode_mgr); 206 + 207 + chip->irq = platform_get_irq(pdev, 0); 208 + ret = devm_request_threaded_irq(&pdev->dev, chip->irq, handle_eud_irq, 209 + handle_eud_irq_thread, IRQF_ONESHOT, NULL, chip); 210 + if (ret) 211 + return dev_err_probe(chip->dev, ret, "failed to allocate irq\n"); 212 + 213 + enable_irq_wake(chip->irq); 214 + 215 + platform_set_drvdata(pdev, chip); 216 + 217 + return 0; 218 + } 219 + 220 + static int eud_remove(struct platform_device *pdev) 221 + { 222 + struct eud_chip *chip = platform_get_drvdata(pdev); 223 + 224 + if (chip->enabled) 225 + disable_eud(chip); 226 + 227 + device_init_wakeup(&pdev->dev, false); 228 + disable_irq_wake(chip->irq); 229 + 230 + return 0; 231 + } 232 + 233 + static const struct of_device_id eud_dt_match[] = { 234 + { .compatible = "qcom,sc7280-eud" }, 235 + { } 236 + }; 237 + MODULE_DEVICE_TABLE(of, eud_dt_match); 238 + 239 + static struct platform_driver eud_driver = { 240 + .probe = eud_probe, 241 + .remove = eud_remove, 242 + .driver = { 243 + .name = "qcom_eud", 244 + .dev_groups = eud_groups, 245 + .of_match_table = eud_dt_match, 246 + }, 247 + }; 248 + module_platform_driver(eud_driver); 249 + 250 + MODULE_DESCRIPTION("QTI EUD driver"); 251 + MODULE_LICENSE("GPL v2");
+1
drivers/usb/serial/Kconfig
··· 66 66 - Libtransistor USB console 67 67 - a number of Motorola phones 68 68 - Motorola Tetra devices 69 + - Nokia mobile phones 69 70 - Novatel Wireless GPS receivers 70 71 - Siemens USB/MPI adapter. 71 72 - ViVOtech ViVOpay USB device.
+2
drivers/usb/serial/pl2303.c
··· 116 116 { USB_DEVICE(ADLINK_VENDOR_ID, ADLINK_ND6530GC_PRODUCT_ID) }, 117 117 { USB_DEVICE(SMART_VENDOR_ID, SMART_PRODUCT_ID) }, 118 118 { USB_DEVICE(AT_VENDOR_ID, AT_VTKIT3_PRODUCT_ID) }, 119 + { USB_DEVICE(IBM_VENDOR_ID, IBM_PRODUCT_ID) }, 119 120 { } /* Terminating entry */ 120 121 }; 121 122 ··· 436 435 case 0x105: 437 436 case 0x305: 438 437 case 0x405: 438 + case 0x605: 439 439 /* 440 440 * Assume it's an HXN-type if the device doesn't 441 441 * support the old read request value.
+3
drivers/usb/serial/pl2303.h
··· 35 35 #define ATEN_PRODUCT_UC232B 0x2022 36 36 #define ATEN_PRODUCT_ID2 0x2118 37 37 38 + #define IBM_VENDOR_ID 0x04b3 39 + #define IBM_PRODUCT_ID 0x4016 40 + 38 41 #define IODATA_VENDOR_ID 0x04bb 39 42 #define IODATA_PRODUCT_ID 0x0a03 40 43 #define IODATA_PRODUCT_ID_RSAQ5 0x0a0e
+7
drivers/usb/serial/usb-serial-simple.c
··· 91 91 { USB_DEVICE(0x0cad, 0x9016) } /* TPG2200 */ 92 92 DEVICE(motorola_tetra, MOTOROLA_TETRA_IDS); 93 93 94 + /* Nokia mobile phone driver */ 95 + #define NOKIA_IDS() \ 96 + { USB_DEVICE(0x0421, 0x069a) } /* Nokia 130 (RM-1035) */ 97 + DEVICE(nokia, NOKIA_IDS); 98 + 94 99 /* Novatel Wireless GPS driver */ 95 100 #define NOVATEL_IDS() \ 96 101 { USB_DEVICE(0x09d7, 0x0100) } /* NovAtel FlexPack GPS */ ··· 128 123 &vivopay_device, 129 124 &moto_modem_device, 130 125 &motorola_tetra_device, 126 + &nokia_device, 131 127 &novatel_gps_device, 132 128 &hp4x_device, 133 129 &suunto_device, ··· 146 140 VIVOPAY_IDS(), 147 141 MOTO_IDS(), 148 142 MOTOROLA_TETRA_IDS(), 143 + NOKIA_IDS(), 149 144 NOVATEL_IDS(), 150 145 HP4X_IDS(), 151 146 SUUNTO_IDS(),
-1
drivers/usb/serial/usb_wwan.c
··· 148 148 149 149 dev_dbg(&port->dev, "%s: write (%d chars)\n", __func__, count); 150 150 151 - i = 0; 152 151 left = count; 153 152 for (i = 0; left > 0 && i < N_OUT_URB; i++) { 154 153 todo = left;
+73 -76
drivers/usb/storage/ene_ub6250.c
··· 237 237 #define memstick_logaddr(logadr1, logadr0) ((((u16)(logadr1)) << 8) | (logadr0)) 238 238 239 239 240 - struct SD_STATUS { 241 - u8 Insert:1; 242 - u8 Ready:1; 243 - u8 MediaChange:1; 244 - u8 IsMMC:1; 245 - u8 HiCapacity:1; 246 - u8 HiSpeed:1; 247 - u8 WtP:1; 248 - u8 Reserved:1; 249 - }; 240 + /* SD_STATUS bits */ 241 + #define SD_Insert BIT(0) 242 + #define SD_Ready BIT(1) 243 + #define SD_MediaChange BIT(2) 244 + #define SD_IsMMC BIT(3) 245 + #define SD_HiCapacity BIT(4) 246 + #define SD_HiSpeed BIT(5) 247 + #define SD_WtP BIT(6) 248 + /* Bit 7 reserved */ 250 249 251 - struct MS_STATUS { 252 - u8 Insert:1; 253 - u8 Ready:1; 254 - u8 MediaChange:1; 255 - u8 IsMSPro:1; 256 - u8 IsMSPHG:1; 257 - u8 Reserved1:1; 258 - u8 WtP:1; 259 - u8 Reserved2:1; 260 - }; 250 + /* MS_STATUS bits */ 251 + #define MS_Insert BIT(0) 252 + #define MS_Ready BIT(1) 253 + #define MS_MediaChange BIT(2) 254 + #define MS_IsMSPro BIT(3) 255 + #define MS_IsMSPHG BIT(4) 256 + /* Bit 5 reserved */ 257 + #define MS_WtP BIT(6) 258 + /* Bit 7 reserved */ 261 259 262 - struct SM_STATUS { 263 - u8 Insert:1; 264 - u8 Ready:1; 265 - u8 MediaChange:1; 266 - u8 Reserved:3; 267 - u8 WtP:1; 268 - u8 IsMS:1; 269 - }; 260 + /* SM_STATUS bits */ 261 + #define SM_Insert BIT(0) 262 + #define SM_Ready BIT(1) 263 + #define SM_MediaChange BIT(2) 264 + /* Bits 3-5 reserved */ 265 + #define SM_WtP BIT(6) 266 + #define SM_IsMS BIT(7) 270 267 271 268 struct ms_bootblock_cis { 272 269 u8 bCistplDEVICE[6]; /* 0 */ ··· 434 437 u8 *bbuf; 435 438 436 439 /* for 6250 code */ 437 - struct SD_STATUS SD_Status; 438 - struct MS_STATUS MS_Status; 439 - struct SM_STATUS SM_Status; 440 + u8 SD_Status; 441 + u8 MS_Status; 442 + u8 SM_Status; 440 443 441 444 /* ----- SD Control Data ---------------- */ 442 445 /*SD_REGISTER SD_Regs; */ ··· 599 602 { 600 603 struct ene_ub6250_info *info = (struct ene_ub6250_info *) us->extra; 601 604 602 - if (info->SD_Status.Insert && info->SD_Status.Ready) 605 + if ((info->SD_Status & SD_Insert) && (info->SD_Status & SD_Ready)) 603 606 return USB_STOR_TRANSPORT_GOOD; 604 607 else { 605 608 ene_sd_init(us); ··· 619 622 0x0b, 0x00, 0x80, 0x08, 0x00, 0x00, 620 623 0x71, 0xc0, 0x00, 0x00, 0x02, 0x00 }; 621 624 622 - if (info->SD_Status.WtP) 625 + if (info->SD_Status & SD_WtP) 623 626 usb_stor_set_xfer_buf(mediaWP, 12, srb); 624 627 else 625 628 usb_stor_set_xfer_buf(mediaNoWP, 12, srb); ··· 638 641 struct ene_ub6250_info *info = (struct ene_ub6250_info *) us->extra; 639 642 640 643 usb_stor_dbg(us, "sd_scsi_read_capacity\n"); 641 - if (info->SD_Status.HiCapacity) { 644 + if (info->SD_Status & SD_HiCapacity) { 642 645 bl_len = 0x200; 643 - if (info->SD_Status.IsMMC) 646 + if (info->SD_Status & SD_IsMMC) 644 647 bl_num = info->HC_C_SIZE-1; 645 648 else 646 649 bl_num = (info->HC_C_SIZE + 1) * 1024 - 1; ··· 690 693 return USB_STOR_TRANSPORT_ERROR; 691 694 } 692 695 693 - if (info->SD_Status.HiCapacity) 696 + if (info->SD_Status & SD_HiCapacity) 694 697 bnByte = bn; 695 698 696 699 /* set up the command wrapper */ ··· 730 733 return USB_STOR_TRANSPORT_ERROR; 731 734 } 732 735 733 - if (info->SD_Status.HiCapacity) 736 + if (info->SD_Status & SD_HiCapacity) 734 737 bnByte = bn; 735 738 736 739 /* set up the command wrapper */ ··· 1453 1456 struct ene_ub6250_info *info = (struct ene_ub6250_info *)(us->extra); 1454 1457 1455 1458 /* pr_info("MS_SCSI_Test_Unit_Ready\n"); */ 1456 - if (info->MS_Status.Insert && info->MS_Status.Ready) { 1459 + if ((info->MS_Status & MS_Insert) && (info->MS_Status & MS_Ready)) { 1457 1460 return USB_STOR_TRANSPORT_GOOD; 1458 1461 } else { 1459 1462 ene_ms_init(us); ··· 1473 1476 0x0b, 0x00, 0x80, 0x08, 0x00, 0x00, 1474 1477 0x71, 0xc0, 0x00, 0x00, 0x02, 0x00 }; 1475 1478 1476 - if (info->MS_Status.WtP) 1479 + if (info->MS_Status & MS_WtP) 1477 1480 usb_stor_set_xfer_buf(mediaWP, 12, srb); 1478 1481 else 1479 1482 usb_stor_set_xfer_buf(mediaNoWP, 12, srb); ··· 1492 1495 1493 1496 usb_stor_dbg(us, "ms_scsi_read_capacity\n"); 1494 1497 bl_len = 0x200; 1495 - if (info->MS_Status.IsMSPro) 1498 + if (info->MS_Status & MS_IsMSPro) 1496 1499 bl_num = info->MSP_TotalBlock - 1; 1497 1500 else 1498 1501 bl_num = info->MS_Lib.NumberOfLogBlock * info->MS_Lib.blockSize * 2 - 1; ··· 1647 1650 if (bn > info->bl_num) 1648 1651 return USB_STOR_TRANSPORT_ERROR; 1649 1652 1650 - if (info->MS_Status.IsMSPro) { 1653 + if (info->MS_Status & MS_IsMSPro) { 1651 1654 result = ene_load_bincode(us, MSP_RW_PATTERN); 1652 1655 if (result != USB_STOR_XFER_GOOD) { 1653 1656 usb_stor_dbg(us, "Load MPS RW pattern Fail !!\n"); ··· 1748 1751 if (bn > info->bl_num) 1749 1752 return USB_STOR_TRANSPORT_ERROR; 1750 1753 1751 - if (info->MS_Status.IsMSPro) { 1754 + if (info->MS_Status & MS_IsMSPro) { 1752 1755 result = ene_load_bincode(us, MSP_RW_PATTERN); 1753 1756 if (result != USB_STOR_XFER_GOOD) { 1754 1757 pr_info("Load MSP RW pattern Fail !!\n"); ··· 1856 1859 1857 1860 tmpreg = (u16) reg4b; 1858 1861 reg4b = *(u32 *)(&buf[0x14]); 1859 - if (info->SD_Status.HiCapacity && !info->SD_Status.IsMMC) 1862 + if ((info->SD_Status & SD_HiCapacity) && !(info->SD_Status & SD_IsMMC)) 1860 1863 info->HC_C_SIZE = (reg4b >> 8) & 0x3fffff; 1861 1864 1862 1865 info->SD_C_SIZE = ((tmpreg & 0x03) << 10) | (u16)(reg4b >> 22); 1863 1866 info->SD_C_SIZE_MULT = (u8)(reg4b >> 7) & 0x07; 1864 - if (info->SD_Status.HiCapacity && info->SD_Status.IsMMC) 1867 + if ((info->SD_Status & SD_HiCapacity) && (info->SD_Status & SD_IsMMC)) 1865 1868 info->HC_C_SIZE = *(u32 *)(&buf[0x100]); 1866 1869 1867 1870 if (info->SD_READ_BL_LEN > SD_BLOCK_LEN) { ··· 2073 2076 u16 MSP_BlockSize, MSP_UserAreaBlocks; 2074 2077 struct ene_ub6250_info *info = (struct ene_ub6250_info *) us->extra; 2075 2078 u8 *bbuf = info->bbuf; 2079 + unsigned int s; 2076 2080 2077 2081 printk(KERN_INFO "transport --- ENE_MSInit\n"); 2078 2082 ··· 2098 2100 return USB_STOR_TRANSPORT_ERROR; 2099 2101 } 2100 2102 /* the same part to test ENE */ 2101 - info->MS_Status = *(struct MS_STATUS *) bbuf; 2103 + info->MS_Status = bbuf[0]; 2102 2104 2103 - if (info->MS_Status.Insert && info->MS_Status.Ready) { 2104 - printk(KERN_INFO "Insert = %x\n", info->MS_Status.Insert); 2105 - printk(KERN_INFO "Ready = %x\n", info->MS_Status.Ready); 2106 - printk(KERN_INFO "IsMSPro = %x\n", info->MS_Status.IsMSPro); 2107 - printk(KERN_INFO "IsMSPHG = %x\n", info->MS_Status.IsMSPHG); 2108 - printk(KERN_INFO "WtP= %x\n", info->MS_Status.WtP); 2109 - if (info->MS_Status.IsMSPro) { 2105 + s = info->MS_Status; 2106 + if ((s & MS_Insert) && (s & MS_Ready)) { 2107 + printk(KERN_INFO "Insert = %x\n", !!(s & MS_Insert)); 2108 + printk(KERN_INFO "Ready = %x\n", !!(s & MS_Ready)); 2109 + printk(KERN_INFO "IsMSPro = %x\n", !!(s & MS_IsMSPro)); 2110 + printk(KERN_INFO "IsMSPHG = %x\n", !!(s & MS_IsMSPHG)); 2111 + printk(KERN_INFO "WtP= %x\n", !!(s & MS_WtP)); 2112 + if (s & MS_IsMSPro) { 2110 2113 MSP_BlockSize = (bbuf[6] << 8) | bbuf[7]; 2111 2114 MSP_UserAreaBlocks = (bbuf[10] << 8) | bbuf[11]; 2112 2115 info->MSP_TotalBlock = MSP_BlockSize * MSP_UserAreaBlocks; ··· 2168 2169 return USB_STOR_TRANSPORT_ERROR; 2169 2170 } 2170 2171 2171 - info->SD_Status = *(struct SD_STATUS *) bbuf; 2172 - if (info->SD_Status.Insert && info->SD_Status.Ready) { 2173 - struct SD_STATUS *s = &info->SD_Status; 2172 + info->SD_Status = bbuf[0]; 2173 + if ((info->SD_Status & SD_Insert) && (info->SD_Status & SD_Ready)) { 2174 + unsigned int s = info->SD_Status; 2174 2175 2175 2176 ene_get_card_status(us, bbuf); 2176 - usb_stor_dbg(us, "Insert = %x\n", s->Insert); 2177 - usb_stor_dbg(us, "Ready = %x\n", s->Ready); 2178 - usb_stor_dbg(us, "IsMMC = %x\n", s->IsMMC); 2179 - usb_stor_dbg(us, "HiCapacity = %x\n", s->HiCapacity); 2180 - usb_stor_dbg(us, "HiSpeed = %x\n", s->HiSpeed); 2181 - usb_stor_dbg(us, "WtP = %x\n", s->WtP); 2177 + usb_stor_dbg(us, "Insert = %x\n", !!(s & SD_Insert)); 2178 + usb_stor_dbg(us, "Ready = %x\n", !!(s & SD_Ready)); 2179 + usb_stor_dbg(us, "IsMMC = %x\n", !!(s & SD_IsMMC)); 2180 + usb_stor_dbg(us, "HiCapacity = %x\n", !!(s & SD_HiCapacity)); 2181 + usb_stor_dbg(us, "HiSpeed = %x\n", !!(s & SD_HiSpeed)); 2182 + usb_stor_dbg(us, "WtP = %x\n", !!(s & SD_WtP)); 2182 2183 } else { 2183 2184 usb_stor_dbg(us, "SD Card Not Ready --- %x\n", bbuf[0]); 2184 2185 return USB_STOR_TRANSPORT_ERROR; ··· 2200 2201 2201 2202 misc_reg03 = bbuf[0]; 2202 2203 if (misc_reg03 & 0x01) { 2203 - if (!info->SD_Status.Ready) { 2204 + if (!(info->SD_Status & SD_Ready)) { 2204 2205 result = ene_sd_init(us); 2205 2206 if (result != USB_STOR_XFER_GOOD) 2206 2207 return USB_STOR_TRANSPORT_ERROR; 2207 2208 } 2208 2209 } 2209 2210 if (misc_reg03 & 0x02) { 2210 - if (!info->MS_Status.Ready) { 2211 + if (!(info->MS_Status & MS_Ready)) { 2211 2212 result = ene_ms_init(us); 2212 2213 if (result != USB_STOR_XFER_GOOD) 2213 2214 return USB_STOR_TRANSPORT_ERROR; ··· 2306 2307 2307 2308 /*US_DEBUG(usb_stor_show_command(us, srb)); */ 2308 2309 scsi_set_resid(srb, 0); 2309 - if (unlikely(!(info->SD_Status.Ready || info->MS_Status.Ready))) 2310 + if (unlikely(!(info->SD_Status & SD_Ready) || (info->MS_Status & MS_Ready))) 2310 2311 result = ene_init(us); 2311 2312 if (result == USB_STOR_XFER_GOOD) { 2312 2313 result = USB_STOR_TRANSPORT_ERROR; 2313 - if (info->SD_Status.Ready) 2314 + if (info->SD_Status & SD_Ready) 2314 2315 result = sd_scsi_irp(us, srb); 2315 2316 2316 - if (info->MS_Status.Ready) 2317 + if (info->MS_Status & MS_Ready) 2317 2318 result = ms_scsi_irp(us, srb); 2318 2319 } 2319 2320 return result; ··· 2377 2378 2378 2379 static int ene_ub6250_resume(struct usb_interface *iface) 2379 2380 { 2380 - u8 tmp = 0; 2381 2381 struct us_data *us = usb_get_intfdata(iface); 2382 2382 struct ene_ub6250_info *info = (struct ene_ub6250_info *)(us->extra); 2383 2383 ··· 2388 2390 mutex_unlock(&us->dev_mutex); 2389 2391 2390 2392 info->Power_IsResum = true; 2391 - /*info->SD_Status.Ready = 0; */ 2392 - info->SD_Status = *(struct SD_STATUS *)&tmp; 2393 - info->MS_Status = *(struct MS_STATUS *)&tmp; 2394 - info->SM_Status = *(struct SM_STATUS *)&tmp; 2393 + /* info->SD_Status &= ~SD_Ready; */ 2394 + info->SD_Status = 0; 2395 + info->MS_Status = 0; 2396 + info->SM_Status = 0; 2395 2397 2396 2398 return 0; 2397 2399 } 2398 2400 2399 2401 static int ene_ub6250_reset_resume(struct usb_interface *iface) 2400 2402 { 2401 - u8 tmp = 0; 2402 2403 struct us_data *us = usb_get_intfdata(iface); 2403 2404 struct ene_ub6250_info *info = (struct ene_ub6250_info *)(us->extra); 2404 2405 ··· 2409 2412 * the device 2410 2413 */ 2411 2414 info->Power_IsResum = true; 2412 - /*info->SD_Status.Ready = 0; */ 2413 - info->SD_Status = *(struct SD_STATUS *)&tmp; 2414 - info->MS_Status = *(struct MS_STATUS *)&tmp; 2415 - info->SM_Status = *(struct SM_STATUS *)&tmp; 2415 + /* info->SD_Status &= ~SD_Ready; */ 2416 + info->SD_Status = 0; 2417 + info->MS_Status = 0; 2418 + info->SM_Status = 0; 2416 2419 2417 2420 return 0; 2418 2421 }
+1 -1
drivers/usb/storage/realtek_cr.c
··· 365 365 366 366 buf = kmalloc(len, GFP_NOIO); 367 367 if (buf == NULL) 368 - return USB_STOR_TRANSPORT_ERROR; 368 + return -ENOMEM; 369 369 370 370 usb_stor_dbg(us, "addr = 0x%x, len = %d\n", addr, len); 371 371
+22
drivers/usb/typec/Kconfig
··· 52 52 53 53 source "drivers/usb/typec/tipd/Kconfig" 54 54 55 + config TYPEC_RT1719 56 + tristate "Richtek RT1719 Sink Only Type-C controller driver" 57 + depends on USB_ROLE_SWITCH || !USB_ROLE_SWITCH 58 + depends on I2C 59 + select REGMAP_I2C 60 + help 61 + Say Y or M here if your system has Richtek RT1719 sink only 62 + Type-C port controller driver. 63 + 64 + If you choose to build this driver as a dynamically linked module, the 65 + module will be called rt1719.ko 66 + 55 67 config TYPEC_HD3SS3220 56 68 tristate "TI HD3SS3220 Type-C DRP Port controller driver" 57 69 depends on I2C ··· 99 87 100 88 It will also enable the VBUS output to connected devices when a 101 89 DFP connection is made. 90 + 91 + config TYPEC_WUSB3801 92 + tristate "Willsemi WUSB3801 Type-C port controller driver" 93 + depends on I2C 94 + select REGMAP_I2C 95 + help 96 + Say Y or M here if your system has a WUSB3801 Type-C port controller. 97 + 98 + If you choose to build this driver as a dynamically linked module, the 99 + module will be called wusb3801.ko. 102 100 103 101 source "drivers/usb/typec/mux/Kconfig" 104 102
+2
drivers/usb/typec/Makefile
··· 9 9 obj-$(CONFIG_TYPEC_HD3SS3220) += hd3ss3220.o 10 10 obj-$(CONFIG_TYPEC_QCOM_PMIC) += qcom-pmic-typec.o 11 11 obj-$(CONFIG_TYPEC_STUSB160X) += stusb160x.o 12 + obj-$(CONFIG_TYPEC_RT1719) += rt1719.o 13 + obj-$(CONFIG_TYPEC_WUSB3801) += wusb3801.o 12 14 obj-$(CONFIG_TYPEC) += mux/
+43
drivers/usb/typec/class.c
··· 1894 1894 } 1895 1895 EXPORT_SYMBOL_GPL(typec_get_drvdata); 1896 1896 1897 + int typec_get_fw_cap(struct typec_capability *cap, 1898 + struct fwnode_handle *fwnode) 1899 + { 1900 + const char *cap_str; 1901 + int ret; 1902 + 1903 + cap->fwnode = fwnode; 1904 + 1905 + ret = fwnode_property_read_string(fwnode, "power-role", &cap_str); 1906 + if (ret < 0) 1907 + return ret; 1908 + 1909 + ret = typec_find_port_power_role(cap_str); 1910 + if (ret < 0) 1911 + return ret; 1912 + cap->type = ret; 1913 + 1914 + /* USB data support is optional */ 1915 + ret = fwnode_property_read_string(fwnode, "data-role", &cap_str); 1916 + if (ret == 0) { 1917 + ret = typec_find_port_data_role(cap_str); 1918 + if (ret < 0) 1919 + return ret; 1920 + cap->data = ret; 1921 + } 1922 + 1923 + /* Get the preferred power role for a DRP */ 1924 + if (cap->type == TYPEC_PORT_DRP) { 1925 + cap->prefer_role = TYPEC_NO_PREFERRED_ROLE; 1926 + 1927 + ret = fwnode_property_read_string(fwnode, "try-power-role", &cap_str); 1928 + if (ret == 0) { 1929 + ret = typec_find_power_role(cap_str); 1930 + if (ret < 0) 1931 + return ret; 1932 + cap->prefer_role = ret; 1933 + } 1934 + } 1935 + 1936 + return 0; 1937 + } 1938 + EXPORT_SYMBOL_GPL(typec_get_fw_cap); 1939 + 1897 1940 /** 1898 1941 * typec_port_register_altmode - Register USB Type-C Port Alternate Mode 1899 1942 * @port: USB Type-C Port that supports the alternate mode
+961
drivers/usb/typec/rt1719.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + 3 + #include <linux/bitfield.h> 4 + #include <linux/completion.h> 5 + #include <linux/i2c.h> 6 + #include <linux/interrupt.h> 7 + #include <linux/kernel.h> 8 + #include <linux/module.h> 9 + #include <linux/power_supply.h> 10 + #include <linux/regmap.h> 11 + #include <linux/usb/pd.h> 12 + #include <linux/usb/role.h> 13 + #include <linux/usb/typec.h> 14 + 15 + #define RT1719_REG_TXCTRL1 0x03 16 + #define RT1719_REG_TXCTRL2 0x04 17 + #define RT1719_REG_POLICYINFO 0x0E 18 + #define RT1719_REG_SRCPDO1 0x11 19 + #define RT1719_REG_MASKS 0x2D 20 + #define RT1719_REG_EVENTS 0x33 21 + #define RT1719_REG_STATS 0x37 22 + #define RT1719_REG_PSELINFO 0x3C 23 + #define RT1719_REG_USBSETINFO 0x3E 24 + #define RT1719_REG_VENID 0x82 25 + 26 + #define RT1719_UNIQUE_PID 0x1719 27 + #define RT1719_REQDRSWAP_MASK BIT(7) 28 + #define RT1719_EVALMODE_MASK BIT(4) 29 + #define RT1719_REQSRCPDO_MASK GENMASK(2, 0) 30 + #define RT1719_TXSPDOREQ_MASK BIT(7) 31 + #define RT1719_INT_DRSW_ACCEPT BIT(23) 32 + #define RT1719_INT_RX_SRCCAP BIT(21) 33 + #define RT1719_INT_VBUS_DCT BIT(6) 34 + #define RT1719_INT_VBUS_PRESENT BIT(5) 35 + #define RT1719_INT_PE_SNK_RDY BIT(2) 36 + #define RT1719_CC1_STAT GENMASK(9, 8) 37 + #define RT1719_CC2_STAT GENMASK(11, 10) 38 + #define RT1719_POLARITY_MASK BIT(23) 39 + #define RT1719_DATAROLE_MASK BIT(22) 40 + #define RT1719_PDSPECREV_MASK GENMASK(21, 20) 41 + #define RT1719_SPDOSEL_MASK GENMASK(18, 16) 42 + #define RT1719_SPDONUM_MASK GENMASK(15, 13) 43 + #define RT1719_ATTACH_VBUS BIT(12) 44 + #define RT1719_ATTACH_DBG BIT(10) 45 + #define RT1719_ATTACH_SNK BIT(9) 46 + #define RT1719_ATTACHDEV_MASK (RT1719_ATTACH_VBUS | RT1719_ATTACH_DBG | \ 47 + RT1719_ATTACH_SNK) 48 + #define RT1719_PE_EXP_CONTRACT BIT(2) 49 + #define RT1719_PSEL_SUPPORT BIT(15) 50 + #define RT1719_TBLSEL_MASK BIT(6) 51 + #define RT1719_LATPSEL_MASK GENMASK(5, 0) 52 + #define RT1719_USBINFO_MASK GENMASK(1, 0) 53 + #define RT1719_USB_DFPUFP 3 54 + #define RT1719_MAX_SRCPDO 7 55 + 56 + enum { 57 + SNK_PWR_OPEN = 0, 58 + SNK_PWR_DEF, 59 + SNK_PWR_1P5A, 60 + SNK_PWR_3A 61 + }; 62 + 63 + enum { 64 + USBPD_SPECREV_1_0 = 0, 65 + USBPD_SPECREV_2_0, 66 + USBPD_SPECREV_3_0 67 + }; 68 + 69 + enum rt1719_snkcap { 70 + RT1719_SNKCAP_5V = 0, 71 + RT1719_SNKCAP_9V, 72 + RT1719_SNKCAP_12V, 73 + RT1719_SNKCAP_15V, 74 + RT1719_SNKCAP_20V, 75 + RT1719_MAX_SNKCAP 76 + }; 77 + 78 + struct rt1719_psel_cap { 79 + u8 lomask; 80 + u8 himask; 81 + u32 milliwatt; 82 + u32 milliamp; 83 + }; 84 + 85 + struct rt1719_data { 86 + struct device *dev; 87 + struct regmap *regmap; 88 + struct typec_port *port; 89 + struct usb_role_switch *role_sw; 90 + struct power_supply *psy; 91 + struct typec_partner *partner; 92 + struct power_supply_desc psy_desc; 93 + struct usb_pd_identity partner_ident; 94 + struct typec_partner_desc partner_desc; 95 + struct completion req_completion; 96 + enum power_supply_usb_type usb_type; 97 + bool attached; 98 + bool pd_capable; 99 + bool drswap_support; 100 + u32 voltage; 101 + u32 req_voltage; 102 + u32 max_current; 103 + u32 op_current; 104 + u32 spdos[RT1719_MAX_SRCPDO]; 105 + u16 snkcaps[RT1719_MAX_SNKCAP]; 106 + int spdo_num; 107 + int spdo_sel; 108 + u32 conn_info; 109 + u16 conn_stat; 110 + }; 111 + 112 + static const enum power_supply_usb_type rt1719_psy_usb_types[] = { 113 + POWER_SUPPLY_USB_TYPE_C, 114 + POWER_SUPPLY_USB_TYPE_PD, 115 + POWER_SUPPLY_USB_TYPE_PD_PPS 116 + }; 117 + 118 + static const enum power_supply_property rt1719_psy_properties[] = { 119 + POWER_SUPPLY_PROP_ONLINE, 120 + POWER_SUPPLY_PROP_USB_TYPE, 121 + POWER_SUPPLY_PROP_VOLTAGE_NOW, 122 + POWER_SUPPLY_PROP_CURRENT_MAX, 123 + POWER_SUPPLY_PROP_CURRENT_NOW 124 + }; 125 + 126 + static int rt1719_read16(struct rt1719_data *data, unsigned int reg, u16 *val) 127 + { 128 + __le16 regval; 129 + int ret; 130 + 131 + ret = regmap_raw_read(data->regmap, reg, &regval, sizeof(regval)); 132 + if (ret) 133 + return ret; 134 + 135 + *val = le16_to_cpu(regval); 136 + return 0; 137 + } 138 + 139 + static int rt1719_read32(struct rt1719_data *data, unsigned int reg, u32 *val) 140 + { 141 + __le32 regval; 142 + int ret; 143 + 144 + ret = regmap_raw_read(data->regmap, reg, &regval, sizeof(regval)); 145 + if (ret) 146 + return ret; 147 + 148 + *val = le32_to_cpu(regval); 149 + return 0; 150 + } 151 + 152 + static int rt1719_write32(struct rt1719_data *data, unsigned int reg, u32 val) 153 + { 154 + __le32 regval = cpu_to_le32(val); 155 + 156 + return regmap_raw_write(data->regmap, reg, &regval, sizeof(regval)); 157 + } 158 + 159 + static enum typec_pwr_opmode rt1719_get_pwr_opmode(u32 conn, u16 stat) 160 + { 161 + u16 cc1, cc2, cc_stat; 162 + 163 + cc1 = FIELD_GET(RT1719_CC1_STAT, stat); 164 + cc2 = FIELD_GET(RT1719_CC2_STAT, stat); 165 + 166 + if (conn & RT1719_ATTACH_SNK) { 167 + if (conn & RT1719_POLARITY_MASK) 168 + cc_stat = cc2; 169 + else 170 + cc_stat = cc1; 171 + 172 + switch (cc_stat) { 173 + case SNK_PWR_3A: 174 + return TYPEC_PWR_MODE_3_0A; 175 + case SNK_PWR_1P5A: 176 + return TYPEC_PWR_MODE_1_5A; 177 + } 178 + } else if (conn & RT1719_ATTACH_DBG) { 179 + if ((cc1 == SNK_PWR_1P5A && cc2 == SNK_PWR_DEF) || 180 + (cc1 == SNK_PWR_DEF && cc2 == SNK_PWR_1P5A)) 181 + return TYPEC_PWR_MODE_1_5A; 182 + else if ((cc1 == SNK_PWR_3A && cc2 == SNK_PWR_DEF) || 183 + (cc1 == SNK_PWR_DEF && cc2 == SNK_PWR_3A)) 184 + return TYPEC_PWR_MODE_3_0A; 185 + } 186 + 187 + return TYPEC_PWR_MODE_USB; 188 + } 189 + 190 + static enum typec_data_role rt1719_get_data_role(u32 conn) 191 + { 192 + if (conn & RT1719_DATAROLE_MASK) 193 + return TYPEC_HOST; 194 + return TYPEC_DEVICE; 195 + } 196 + 197 + static void rt1719_set_data_role(struct rt1719_data *data, 198 + enum typec_data_role data_role, 199 + bool attached) 200 + { 201 + enum usb_role usb_role = USB_ROLE_NONE; 202 + 203 + if (attached) { 204 + if (data_role == TYPEC_HOST) 205 + usb_role = USB_ROLE_HOST; 206 + else 207 + usb_role = USB_ROLE_DEVICE; 208 + } 209 + 210 + usb_role_switch_set_role(data->role_sw, usb_role); 211 + typec_set_data_role(data->port, data_role); 212 + } 213 + 214 + static void rt1719_update_data_role(struct rt1719_data *data) 215 + { 216 + if (!data->attached) 217 + return; 218 + 219 + rt1719_set_data_role(data, rt1719_get_data_role(data->conn_info), true); 220 + } 221 + 222 + static void rt1719_register_partner(struct rt1719_data *data) 223 + { 224 + u16 spec_rev = 0; 225 + 226 + if (data->pd_capable) { 227 + u32 rev; 228 + 229 + rev = FIELD_GET(RT1719_PDSPECREV_MASK, data->conn_info); 230 + switch (rev) { 231 + case USBPD_SPECREV_3_0: 232 + spec_rev = 0x0300; 233 + break; 234 + case USBPD_SPECREV_2_0: 235 + spec_rev = 0x0200; 236 + break; 237 + default: 238 + spec_rev = 0x0100; 239 + break; 240 + } 241 + } 242 + 243 + /* Just to prevent multiple times attach */ 244 + if (data->partner) 245 + typec_unregister_partner(data->partner); 246 + 247 + memset(&data->partner_ident, 0, sizeof(data->partner_ident)); 248 + data->partner_desc.usb_pd = data->pd_capable; 249 + data->partner_desc.pd_revision = spec_rev; 250 + 251 + if (data->conn_info & RT1719_ATTACH_DBG) 252 + data->partner_desc.accessory = TYPEC_ACCESSORY_DEBUG; 253 + else 254 + data->partner_desc.accessory = TYPEC_ACCESSORY_NONE; 255 + 256 + data->partner = typec_register_partner(data->port, &data->partner_desc); 257 + } 258 + 259 + static void rt1719_attach(struct rt1719_data *data) 260 + { 261 + enum typec_pwr_opmode pwr_opmode; 262 + enum typec_data_role data_role; 263 + u32 volt = 5000, curr = 500; 264 + 265 + if (!(data->conn_info & RT1719_ATTACHDEV_MASK)) 266 + return; 267 + 268 + pwr_opmode = rt1719_get_pwr_opmode(data->conn_info, data->conn_stat); 269 + data_role = rt1719_get_data_role(data->conn_info); 270 + 271 + typec_set_pwr_opmode(data->port, pwr_opmode); 272 + rt1719_set_data_role(data, data_role, true); 273 + 274 + if (data->conn_info & RT1719_ATTACH_SNK) 275 + rt1719_register_partner(data); 276 + 277 + if (pwr_opmode == TYPEC_PWR_MODE_3_0A) 278 + curr = 3000; 279 + else if (pwr_opmode == TYPEC_PWR_MODE_1_5A) 280 + curr = 1500; 281 + 282 + data->voltage = volt * 1000; 283 + data->max_current = data->op_current = curr * 1000; 284 + data->attached = true; 285 + 286 + power_supply_changed(data->psy); 287 + } 288 + 289 + static void rt1719_detach(struct rt1719_data *data) 290 + { 291 + if (!data->attached || (data->conn_info & RT1719_ATTACHDEV_MASK)) 292 + return; 293 + 294 + typec_unregister_partner(data->partner); 295 + data->partner = NULL; 296 + 297 + typec_set_pwr_opmode(data->port, TYPEC_PWR_MODE_USB); 298 + rt1719_set_data_role(data, TYPEC_DEVICE, false); 299 + 300 + memset32(data->spdos, 0, RT1719_MAX_SRCPDO); 301 + data->spdo_num = 0; 302 + data->voltage = data->max_current = data->op_current = 0; 303 + data->attached = data->pd_capable = false; 304 + 305 + data->usb_type = POWER_SUPPLY_USB_TYPE_C; 306 + 307 + power_supply_changed(data->psy); 308 + } 309 + 310 + static void rt1719_update_operating_status(struct rt1719_data *data) 311 + { 312 + enum power_supply_usb_type usb_type = POWER_SUPPLY_USB_TYPE_PD; 313 + u32 voltage, max_current, op_current; 314 + int i, snk_sel; 315 + 316 + for (i = 0; i < data->spdo_num; i++) { 317 + u32 pdo = data->spdos[i]; 318 + enum pd_pdo_type type = pdo_type(pdo); 319 + 320 + if (type == PDO_TYPE_APDO) { 321 + usb_type = POWER_SUPPLY_USB_TYPE_PD_PPS; 322 + break; 323 + } 324 + } 325 + 326 + data->spdo_sel = FIELD_GET(RT1719_SPDOSEL_MASK, data->conn_info); 327 + if (data->spdo_sel <= 0) 328 + return; 329 + 330 + data->usb_type = usb_type; 331 + 332 + voltage = pdo_fixed_voltage(data->spdos[data->spdo_sel - 1]); 333 + max_current = pdo_max_current(data->spdos[data->spdo_sel - 1]); 334 + 335 + switch (voltage) { 336 + case 5000: 337 + snk_sel = RT1719_SNKCAP_5V; 338 + break; 339 + case 9000: 340 + snk_sel = RT1719_SNKCAP_9V; 341 + break; 342 + case 12000: 343 + snk_sel = RT1719_SNKCAP_12V; 344 + break; 345 + case 15000: 346 + snk_sel = RT1719_SNKCAP_15V; 347 + break; 348 + case 20000: 349 + snk_sel = RT1719_SNKCAP_20V; 350 + break; 351 + default: 352 + return; 353 + } 354 + 355 + op_current = min(max_current, pdo_max_current(data->snkcaps[snk_sel])); 356 + 357 + /* covert mV/mA to uV/uA */ 358 + data->voltage = voltage * 1000; 359 + data->max_current = max_current * 1000; 360 + data->op_current = op_current * 1000; 361 + 362 + power_supply_changed(data->psy); 363 + } 364 + 365 + static void rt1719_update_pwr_opmode(struct rt1719_data *data) 366 + { 367 + if (!data->attached) 368 + return; 369 + 370 + if (!data->pd_capable) { 371 + data->pd_capable = true; 372 + 373 + typec_set_pwr_opmode(data->port, TYPEC_PWR_MODE_PD); 374 + rt1719_register_partner(data); 375 + } 376 + 377 + rt1719_update_operating_status(data); 378 + } 379 + 380 + static void rt1719_update_source_pdos(struct rt1719_data *data) 381 + { 382 + int spdo_num = FIELD_GET(RT1719_SPDONUM_MASK, data->conn_info); 383 + __le32 src_pdos[RT1719_MAX_SRCPDO] = { }; 384 + int i, ret; 385 + 386 + if (!data->attached) 387 + return; 388 + 389 + ret = regmap_raw_read(data->regmap, RT1719_REG_SRCPDO1, src_pdos, 390 + sizeof(__le32) * spdo_num); 391 + if (ret) 392 + return; 393 + 394 + data->spdo_num = spdo_num; 395 + for (i = 0; i < spdo_num; i++) 396 + data->spdos[i] = le32_to_cpu(src_pdos[i]); 397 + } 398 + 399 + static int rt1719_dr_set(struct typec_port *port, enum typec_data_role role) 400 + { 401 + struct rt1719_data *data = typec_get_drvdata(port); 402 + enum typec_data_role cur_role; 403 + int ret; 404 + 405 + if (!data->attached || !data->pd_capable || !data->drswap_support) 406 + return -EOPNOTSUPP; 407 + 408 + if (data->spdo_num > 0 && !(data->spdos[0] & PDO_FIXED_DATA_SWAP)) 409 + return -EINVAL; 410 + 411 + cur_role = rt1719_get_data_role(data->conn_info); 412 + if (cur_role == role) 413 + return 0; 414 + 415 + ret = regmap_update_bits(data->regmap, RT1719_REG_TXCTRL1, 416 + RT1719_REQDRSWAP_MASK, RT1719_REQDRSWAP_MASK); 417 + if (ret) 418 + return ret; 419 + 420 + reinit_completion(&data->req_completion); 421 + ret = wait_for_completion_timeout(&data->req_completion, 422 + msecs_to_jiffies(400)); 423 + if (ret == 0) 424 + return -ETIMEDOUT; 425 + 426 + cur_role = rt1719_get_data_role(data->conn_info); 427 + if (cur_role != role) 428 + return -EAGAIN; 429 + 430 + rt1719_set_data_role(data, role, true); 431 + return 0; 432 + } 433 + 434 + static const struct typec_operations rt1719_port_ops = { 435 + .dr_set = rt1719_dr_set, 436 + }; 437 + 438 + static int rt1719_usbpd_request_voltage(struct rt1719_data *data) 439 + { 440 + u32 src_voltage; 441 + int snk_sel, src_sel = -1; 442 + int i, ret; 443 + 444 + if (!data->attached || !data->pd_capable || data->spdo_sel <= 0) 445 + return -EINVAL; 446 + 447 + src_voltage = pdo_fixed_voltage(data->spdos[data->spdo_sel - 1]); 448 + if (src_voltage == data->req_voltage) 449 + return 0; 450 + 451 + switch (data->req_voltage) { 452 + case 5000: 453 + snk_sel = RT1719_SNKCAP_5V; 454 + break; 455 + case 9000: 456 + snk_sel = RT1719_SNKCAP_9V; 457 + break; 458 + case 12000: 459 + snk_sel = RT1719_SNKCAP_12V; 460 + break; 461 + case 15000: 462 + snk_sel = RT1719_SNKCAP_15V; 463 + break; 464 + case 20000: 465 + snk_sel = RT1719_SNKCAP_20V; 466 + break; 467 + default: 468 + return -EINVAL; 469 + } 470 + 471 + if (!(data->snkcaps[snk_sel] & RT1719_PSEL_SUPPORT)) 472 + return -EINVAL; 473 + 474 + for (i = 0; i < data->spdo_num; i++) { 475 + enum pd_pdo_type type = pdo_type(data->spdos[i]); 476 + 477 + if (type != PDO_TYPE_FIXED) 478 + continue; 479 + 480 + src_voltage = pdo_fixed_voltage(data->spdos[i]); 481 + if (src_voltage == data->req_voltage) { 482 + src_sel = i; 483 + break; 484 + } 485 + } 486 + 487 + if (src_sel == -1) 488 + return -EOPNOTSUPP; 489 + 490 + ret = regmap_update_bits(data->regmap, RT1719_REG_TXCTRL1, 491 + RT1719_EVALMODE_MASK | RT1719_REQSRCPDO_MASK, 492 + RT1719_EVALMODE_MASK | (src_sel + 1)); 493 + ret |= regmap_update_bits(data->regmap, RT1719_REG_TXCTRL2, 494 + RT1719_TXSPDOREQ_MASK, RT1719_TXSPDOREQ_MASK); 495 + if (ret) 496 + return ret; 497 + 498 + reinit_completion(&data->req_completion); 499 + ret = wait_for_completion_timeout(&data->req_completion, 500 + msecs_to_jiffies(400)); 501 + if (!ret) 502 + return -ETIMEDOUT; 503 + 504 + return 0; 505 + } 506 + 507 + static int rt1719_psy_set_property(struct power_supply *psy, 508 + enum power_supply_property psp, 509 + const union power_supply_propval *val) 510 + { 511 + struct rt1719_data *data = power_supply_get_drvdata(psy); 512 + 513 + if (psp == POWER_SUPPLY_PROP_VOLTAGE_NOW) { 514 + data->req_voltage = val->intval / 1000; 515 + return rt1719_usbpd_request_voltage(data); 516 + } 517 + 518 + return -EINVAL; 519 + } 520 + 521 + static int rt1719_psy_get_property(struct power_supply *psy, 522 + enum power_supply_property psp, 523 + union power_supply_propval *val) 524 + { 525 + struct rt1719_data *data = power_supply_get_drvdata(psy); 526 + int ret = 0; 527 + 528 + switch (psp) { 529 + case POWER_SUPPLY_PROP_ONLINE: 530 + val->intval = data->attached ? 1 : 0; 531 + break; 532 + case POWER_SUPPLY_PROP_USB_TYPE: 533 + val->intval = data->usb_type; 534 + break; 535 + case POWER_SUPPLY_PROP_VOLTAGE_NOW: 536 + val->intval = data->voltage; 537 + break; 538 + case POWER_SUPPLY_PROP_CURRENT_MAX: 539 + val->intval = data->max_current; 540 + break; 541 + case POWER_SUPPLY_PROP_CURRENT_NOW: 542 + val->intval = data->op_current; 543 + break; 544 + default: 545 + ret = -EINVAL; 546 + break; 547 + } 548 + 549 + return ret; 550 + } 551 + 552 + static int rt1719_psy_property_is_writeable(struct power_supply *psy, 553 + enum power_supply_property psp) 554 + { 555 + if (psp == POWER_SUPPLY_PROP_VOLTAGE_NOW) 556 + return 1; 557 + return 0; 558 + } 559 + 560 + static int devm_rt1719_psy_register(struct rt1719_data *data) 561 + { 562 + struct power_supply_config psy_cfg = { }; 563 + char *psy_name; 564 + 565 + psy_cfg.fwnode = dev_fwnode(data->dev); 566 + psy_cfg.drv_data = data; 567 + 568 + psy_name = devm_kasprintf(data->dev, GFP_KERNEL, "rt1719-source-psy-%s", 569 + dev_name(data->dev)); 570 + if (!psy_name) 571 + return -ENOMEM; 572 + 573 + data->psy_desc.name = psy_name; 574 + data->psy_desc.type = POWER_SUPPLY_TYPE_USB; 575 + data->psy_desc.usb_types = rt1719_psy_usb_types; 576 + data->psy_desc.num_usb_types = ARRAY_SIZE(rt1719_psy_usb_types); 577 + data->psy_desc.properties = rt1719_psy_properties; 578 + data->psy_desc.num_properties = ARRAY_SIZE(rt1719_psy_properties); 579 + data->psy_desc.get_property = rt1719_psy_get_property; 580 + data->psy_desc.set_property = rt1719_psy_set_property; 581 + data->psy_desc.property_is_writeable = rt1719_psy_property_is_writeable; 582 + 583 + data->usb_type = POWER_SUPPLY_USB_TYPE_C; 584 + 585 + data->psy = devm_power_supply_register(data->dev, &data->psy_desc, 586 + &psy_cfg); 587 + 588 + return PTR_ERR_OR_ZERO(data->psy); 589 + } 590 + 591 + static irqreturn_t rt1719_irq_handler(int irq, void *priv) 592 + { 593 + struct rt1719_data *data = priv; 594 + u32 events, conn_info; 595 + u16 conn_stat; 596 + int ret; 597 + 598 + ret = rt1719_read32(data, RT1719_REG_EVENTS, &events); 599 + ret |= rt1719_read32(data, RT1719_REG_POLICYINFO, &conn_info); 600 + ret |= rt1719_read16(data, RT1719_REG_STATS, &conn_stat); 601 + if (ret) 602 + return IRQ_NONE; 603 + 604 + data->conn_info = conn_info; 605 + data->conn_stat = conn_stat; 606 + 607 + events &= (RT1719_INT_DRSW_ACCEPT | RT1719_INT_RX_SRCCAP | 608 + RT1719_INT_VBUS_PRESENT | RT1719_INT_VBUS_DCT | 609 + RT1719_INT_PE_SNK_RDY); 610 + 611 + if (events & RT1719_INT_DRSW_ACCEPT) 612 + rt1719_update_data_role(data); 613 + 614 + if (events & RT1719_INT_VBUS_PRESENT) 615 + rt1719_attach(data); 616 + 617 + if (events & RT1719_INT_VBUS_DCT) 618 + rt1719_detach(data); 619 + 620 + if (events & RT1719_INT_RX_SRCCAP) 621 + rt1719_update_source_pdos(data); 622 + 623 + if (events & RT1719_INT_PE_SNK_RDY) { 624 + complete(&data->req_completion); 625 + rt1719_update_pwr_opmode(data); 626 + } 627 + 628 + /* Write 1 to clear already handled events */ 629 + rt1719_write32(data, RT1719_REG_EVENTS, events); 630 + 631 + return IRQ_HANDLED; 632 + } 633 + 634 + static int rt1719_irq_init(struct rt1719_data *data) 635 + { 636 + struct i2c_client *i2c = to_i2c_client(data->dev); 637 + u32 irq_enable; 638 + int ret; 639 + 640 + irq_enable = RT1719_INT_DRSW_ACCEPT | RT1719_INT_RX_SRCCAP | 641 + RT1719_INT_VBUS_DCT | RT1719_INT_VBUS_PRESENT | 642 + RT1719_INT_PE_SNK_RDY; 643 + 644 + ret = rt1719_write32(data, RT1719_REG_MASKS, irq_enable); 645 + if (ret) { 646 + dev_err(&i2c->dev, "Failed to config irq enable\n"); 647 + return ret; 648 + } 649 + 650 + return devm_request_threaded_irq(&i2c->dev, i2c->irq, NULL, 651 + rt1719_irq_handler, IRQF_ONESHOT, 652 + dev_name(&i2c->dev), data); 653 + } 654 + 655 + static int rt1719_init_attach_state(struct rt1719_data *data) 656 + { 657 + u32 conn_info, irq_clear; 658 + u16 conn_stat; 659 + int ret; 660 + 661 + irq_clear = RT1719_INT_DRSW_ACCEPT | RT1719_INT_RX_SRCCAP | 662 + RT1719_INT_VBUS_DCT | RT1719_INT_VBUS_PRESENT | 663 + RT1719_INT_PE_SNK_RDY; 664 + 665 + ret = rt1719_read32(data, RT1719_REG_POLICYINFO, &conn_info); 666 + ret |= rt1719_read16(data, RT1719_REG_STATS, &conn_stat); 667 + ret |= rt1719_write32(data, RT1719_REG_EVENTS, irq_clear); 668 + if (ret) 669 + return ret; 670 + 671 + data->conn_info = conn_info; 672 + data->conn_stat = conn_stat; 673 + 674 + if (conn_info & RT1719_ATTACHDEV_MASK) 675 + rt1719_attach(data); 676 + 677 + if (conn_info & RT1719_PE_EXP_CONTRACT) { 678 + rt1719_update_source_pdos(data); 679 + rt1719_update_pwr_opmode(data); 680 + } 681 + 682 + return 0; 683 + } 684 + 685 + #define RT1719_PSEL_CAPINFO(_lomask, _milliwatt, _himask, _milliamp) { \ 686 + .lomask = _lomask, \ 687 + .milliwatt = _milliwatt, \ 688 + .himask = _himask, \ 689 + .milliamp = _milliamp, \ 690 + } 691 + 692 + static const struct rt1719_psel_cap rt1719_psel_caps[] = { 693 + RT1719_PSEL_CAPINFO(0x18, 75000, 0x10, 5000), 694 + RT1719_PSEL_CAPINFO(0x18, 60000, 0x10, 4500), 695 + RT1719_PSEL_CAPINFO(0x18, 45000, 0x10, 4000), 696 + RT1719_PSEL_CAPINFO(0x18, 30000, 0x10, 3500), 697 + RT1719_PSEL_CAPINFO(0x18, 25000, 0x10, 3000), 698 + RT1719_PSEL_CAPINFO(0x18, 20000, 0x10, 2500), 699 + RT1719_PSEL_CAPINFO(0x18, 15000, 0x10, 2000), 700 + RT1719_PSEL_CAPINFO(0x18, 10000, 0x10, 1000), 701 + RT1719_PSEL_CAPINFO(0x1C, 60000, 0x1F, 5000), 702 + RT1719_PSEL_CAPINFO(0x1C, 45000, 0x1F, 4500), 703 + RT1719_PSEL_CAPINFO(0x1C, 30000, 0x1F, 4000), 704 + RT1719_PSEL_CAPINFO(0x1C, 24000, 0x1F, 3500), 705 + RT1719_PSEL_CAPINFO(0x1C, 15000, 0x1F, 3000), 706 + RT1719_PSEL_CAPINFO(0x1C, 10000, 0x1F, 2500), 707 + RT1719_PSEL_CAPINFO(0x0C, 60000, 0x1F, 2000), 708 + RT1719_PSEL_CAPINFO(0x0C, 45000, 0x1F, 1000), 709 + RT1719_PSEL_CAPINFO(0x0C, 36000, 0x08, 5000), 710 + RT1719_PSEL_CAPINFO(0x0C, 30000, 0x08, 4500), 711 + RT1719_PSEL_CAPINFO(0x0C, 24000, 0x08, 4000), 712 + RT1719_PSEL_CAPINFO(0x0C, 15000, 0x08, 3500), 713 + RT1719_PSEL_CAPINFO(0x0C, 10000, 0x08, 3000), 714 + RT1719_PSEL_CAPINFO(0x1E, 45000, 0x08, 2500), 715 + RT1719_PSEL_CAPINFO(0x1E, 36000, 0x08, 2000), 716 + RT1719_PSEL_CAPINFO(0x1E, 27000, 0x08, 1500), 717 + RT1719_PSEL_CAPINFO(0x1E, 20000, 0x08, 1000), 718 + RT1719_PSEL_CAPINFO(0x1E, 15000, 0x0F, 5000), 719 + RT1719_PSEL_CAPINFO(0x1E, 9000, 0x0F, 4500), 720 + RT1719_PSEL_CAPINFO(0x0E, 45000, 0x0F, 4000), 721 + RT1719_PSEL_CAPINFO(0x0E, 36000, 0x0F, 3500), 722 + RT1719_PSEL_CAPINFO(0x0E, 27000, 0x0F, 3000), 723 + RT1719_PSEL_CAPINFO(0x0E, 20000, 0x0F, 2500), 724 + RT1719_PSEL_CAPINFO(0x0E, 15000, 0x0F, 2000), 725 + RT1719_PSEL_CAPINFO(0x0E, 9000, 0x0F, 1500), 726 + RT1719_PSEL_CAPINFO(0x06, 45000, 0x0F, 1000), 727 + RT1719_PSEL_CAPINFO(0x06, 36000, 0x0F, 500), 728 + RT1719_PSEL_CAPINFO(0x06, 27000, 0x04, 5000), 729 + RT1719_PSEL_CAPINFO(0x06, 24000, 0x04, 4500), 730 + RT1719_PSEL_CAPINFO(0x06, 18000, 0x04, 4000), 731 + RT1719_PSEL_CAPINFO(0x06, 12000, 0x04, 3500), 732 + RT1719_PSEL_CAPINFO(0x06, 9000, 0x04, 3000), 733 + RT1719_PSEL_CAPINFO(0x1F, 25000, 0x04, 2500), 734 + RT1719_PSEL_CAPINFO(0x1F, 20000, 0x04, 2000), 735 + RT1719_PSEL_CAPINFO(0x1F, 15000, 0x04, 1500), 736 + RT1719_PSEL_CAPINFO(0x1F, 10000, 0x04, 1000), 737 + RT1719_PSEL_CAPINFO(0x1F, 7500, 0x07, 5000), 738 + RT1719_PSEL_CAPINFO(0x0F, 25000, 0x07, 4500), 739 + RT1719_PSEL_CAPINFO(0x0F, 20000, 0x07, 4000), 740 + RT1719_PSEL_CAPINFO(0x0F, 15000, 0x07, 3500), 741 + RT1719_PSEL_CAPINFO(0x0F, 10000, 0x07, 3000), 742 + RT1719_PSEL_CAPINFO(0x0F, 7500, 0x07, 2500), 743 + RT1719_PSEL_CAPINFO(0x07, 25000, 0x07, 2000), 744 + RT1719_PSEL_CAPINFO(0x07, 20000, 0x07, 1500), 745 + RT1719_PSEL_CAPINFO(0x07, 15000, 0x07, 1000), 746 + RT1719_PSEL_CAPINFO(0x07, 10000, 0x07, 500), 747 + RT1719_PSEL_CAPINFO(0x07, 7500, 0x03, 5000), 748 + RT1719_PSEL_CAPINFO(0x03, 25000, 0x03, 4500), 749 + RT1719_PSEL_CAPINFO(0x03, 20000, 0x03, 4000), 750 + RT1719_PSEL_CAPINFO(0x03, 15000, 0x03, 3500), 751 + RT1719_PSEL_CAPINFO(0x03, 10000, 0x03, 3000), 752 + RT1719_PSEL_CAPINFO(0x03, 7500, 0x03, 2500), 753 + RT1719_PSEL_CAPINFO(0x01, 15000, 0x03, 2000), 754 + RT1719_PSEL_CAPINFO(0x01, 10000, 0x03, 1500), 755 + RT1719_PSEL_CAPINFO(0x01, 7500, 0x03, 1000), 756 + RT1719_PSEL_CAPINFO(0x01, 2500, 0x03, 500) 757 + }; 758 + 759 + static u16 rt1719_gen_snkcap_by_current(const struct rt1719_psel_cap *psel_cap, 760 + enum rt1719_snkcap capsel) 761 + { 762 + u16 cap = RT1719_PSEL_SUPPORT; 763 + 764 + if (!(psel_cap->himask & BIT(capsel))) 765 + return 0; 766 + 767 + cap |= psel_cap->milliamp / 10; 768 + return cap; 769 + } 770 + 771 + static u16 rt1719_gen_snkcap_by_watt(const struct rt1719_psel_cap *psel_cap, 772 + enum rt1719_snkcap capsel) 773 + { 774 + u32 volt_div[RT1719_MAX_SNKCAP] = { 5, 9, 12, 15, 20 }; 775 + u16 cap = RT1719_PSEL_SUPPORT; 776 + 777 + if (!(psel_cap->lomask & BIT(capsel))) 778 + return 0; 779 + 780 + cap |= min(psel_cap->milliwatt / volt_div[capsel], (u32)5000) / 10; 781 + return cap; 782 + } 783 + 784 + static u16 rt1719_gen_snkcap(unsigned int pselinfo, enum rt1719_snkcap capsel) 785 + { 786 + int psel = FIELD_GET(RT1719_LATPSEL_MASK, pselinfo); 787 + const struct rt1719_psel_cap *psel_cap; 788 + bool by_current = false; 789 + 790 + if (pselinfo & RT1719_TBLSEL_MASK) 791 + by_current = true; 792 + 793 + psel_cap = rt1719_psel_caps + psel; 794 + if (by_current) 795 + return rt1719_gen_snkcap_by_current(psel_cap, capsel); 796 + 797 + return rt1719_gen_snkcap_by_watt(psel_cap, capsel); 798 + } 799 + 800 + static int rt1719_get_caps(struct rt1719_data *data) 801 + { 802 + unsigned int pselinfo, usbinfo; 803 + int i, ret; 804 + 805 + ret = regmap_read(data->regmap, RT1719_REG_PSELINFO, &pselinfo); 806 + ret |= regmap_read(data->regmap, RT1719_REG_USBSETINFO, &usbinfo); 807 + if (ret) 808 + return ret; 809 + 810 + for (i = 0; i < RT1719_MAX_SNKCAP; i++) 811 + data->snkcaps[i] = rt1719_gen_snkcap(pselinfo, i); 812 + 813 + usbinfo = FIELD_GET(RT1719_USBINFO_MASK, usbinfo); 814 + if (usbinfo == RT1719_USB_DFPUFP) 815 + data->drswap_support = true; 816 + 817 + return 0; 818 + } 819 + 820 + static int rt1719_check_exist(struct rt1719_data *data) 821 + { 822 + u16 pid; 823 + int ret; 824 + 825 + ret = rt1719_read16(data, RT1719_REG_VENID, &pid); 826 + if (ret) 827 + return ret; 828 + 829 + if (pid != RT1719_UNIQUE_PID) { 830 + dev_err(data->dev, "Incorrect PID 0x%04x\n", pid); 831 + return -ENODEV; 832 + } 833 + 834 + return 0; 835 + } 836 + 837 + static const struct regmap_config rt1719_regmap_config = { 838 + .reg_bits = 8, 839 + .val_bits = 8, 840 + .max_register = 0xff, 841 + }; 842 + 843 + static int rt1719_probe(struct i2c_client *i2c) 844 + { 845 + struct rt1719_data *data; 846 + struct fwnode_handle *fwnode; 847 + struct typec_capability typec_cap = { }; 848 + int ret; 849 + 850 + data = devm_kzalloc(&i2c->dev, sizeof(*data), GFP_KERNEL); 851 + if (!data) 852 + return -ENOMEM; 853 + 854 + data->dev = &i2c->dev; 855 + init_completion(&data->req_completion); 856 + 857 + data->regmap = devm_regmap_init_i2c(i2c, &rt1719_regmap_config); 858 + if (IS_ERR(data->regmap)) { 859 + ret = PTR_ERR(data->regmap); 860 + dev_err(&i2c->dev, "Failed to init regmap (%d)\n", ret); 861 + return ret; 862 + } 863 + 864 + ret = rt1719_check_exist(data); 865 + if (ret) 866 + return ret; 867 + 868 + ret = rt1719_get_caps(data); 869 + if (ret) 870 + return ret; 871 + 872 + fwnode = device_get_named_child_node(&i2c->dev, "connector"); 873 + if (!fwnode) 874 + return -ENODEV; 875 + 876 + data->role_sw = fwnode_usb_role_switch_get(fwnode); 877 + if (IS_ERR(data->role_sw)) { 878 + ret = PTR_ERR(data->role_sw); 879 + dev_err(&i2c->dev, "Failed to get usb role switch (%d)\n", ret); 880 + goto err_fwnode_put; 881 + } 882 + 883 + ret = devm_rt1719_psy_register(data); 884 + if (ret) { 885 + dev_err(&i2c->dev, "Failed to register psy (%d)\n", ret); 886 + goto err_role_put; 887 + } 888 + 889 + typec_cap.revision = USB_TYPEC_REV_1_2; 890 + typec_cap.pd_revision = 0x300; /* USB-PD spec release 3.0 */ 891 + typec_cap.type = TYPEC_PORT_SNK; 892 + typec_cap.data = TYPEC_PORT_DRD; 893 + typec_cap.ops = &rt1719_port_ops; 894 + typec_cap.fwnode = fwnode; 895 + typec_cap.driver_data = data; 896 + typec_cap.accessory[0] = TYPEC_ACCESSORY_DEBUG; 897 + 898 + data->partner_desc.identity = &data->partner_ident; 899 + 900 + data->port = typec_register_port(&i2c->dev, &typec_cap); 901 + if (IS_ERR(data->port)) { 902 + ret = PTR_ERR(data->port); 903 + dev_err(&i2c->dev, "Failed to register typec port (%d)\n", ret); 904 + goto err_role_put; 905 + } 906 + 907 + ret = rt1719_init_attach_state(data); 908 + if (ret) { 909 + dev_err(&i2c->dev, "Failed to init attach state (%d)\n", ret); 910 + goto err_role_put; 911 + } 912 + 913 + ret = rt1719_irq_init(data); 914 + if (ret) { 915 + dev_err(&i2c->dev, "Failed to init irq\n"); 916 + goto err_role_put; 917 + } 918 + 919 + fwnode_handle_put(fwnode); 920 + 921 + i2c_set_clientdata(i2c, data); 922 + 923 + return 0; 924 + 925 + err_role_put: 926 + usb_role_switch_put(data->role_sw); 927 + err_fwnode_put: 928 + fwnode_handle_put(fwnode); 929 + 930 + return ret; 931 + } 932 + 933 + static int rt1719_remove(struct i2c_client *i2c) 934 + { 935 + struct rt1719_data *data = i2c_get_clientdata(i2c); 936 + 937 + typec_unregister_port(data->port); 938 + usb_role_switch_put(data->role_sw); 939 + 940 + return 0; 941 + } 942 + 943 + static const struct of_device_id __maybe_unused rt1719_device_table[] = { 944 + { .compatible = "richtek,rt1719", }, 945 + { } 946 + }; 947 + MODULE_DEVICE_TABLE(of, rt1719_device_table); 948 + 949 + static struct i2c_driver rt1719_driver = { 950 + .driver = { 951 + .name = "rt1719", 952 + .of_match_table = rt1719_device_table, 953 + }, 954 + .probe_new = rt1719_probe, 955 + .remove = rt1719_remove, 956 + }; 957 + module_i2c_driver(rt1719_driver); 958 + 959 + MODULE_AUTHOR("ChiYuan Huang <cy_huang@richtek.com>"); 960 + MODULE_DESCRIPTION("Richtek RT1719 Sink Only USBPD Controller Driver"); 961 + MODULE_LICENSE("GPL v2");
+1 -23
drivers/usb/typec/tcpm/tcpm.c
··· 5928 5928 struct fwnode_handle *fwnode) 5929 5929 { 5930 5930 const char *opmode_str; 5931 - const char *cap_str; 5932 5931 int ret; 5933 5932 u32 mw, frs_current; 5934 5933 ··· 5943 5944 */ 5944 5945 fw_devlink_purge_absent_suppliers(fwnode); 5945 5946 5946 - /* USB data support is optional */ 5947 - ret = fwnode_property_read_string(fwnode, "data-role", &cap_str); 5948 - if (ret == 0) { 5949 - ret = typec_find_port_data_role(cap_str); 5950 - if (ret < 0) 5951 - return ret; 5952 - port->typec_caps.data = ret; 5953 - } 5954 - 5955 - ret = fwnode_property_read_string(fwnode, "power-role", &cap_str); 5947 + ret = typec_get_fw_cap(&port->typec_caps, fwnode); 5956 5948 if (ret < 0) 5957 5949 return ret; 5958 5950 5959 - ret = typec_find_port_power_role(cap_str); 5960 - if (ret < 0) 5961 - return ret; 5962 - port->typec_caps.type = ret; 5963 5951 port->port_type = port->typec_caps.type; 5964 5952 port->pd_supported = !fwnode_property_read_bool(fwnode, "pd-disable"); 5965 5953 ··· 5983 5997 if (port->port_type == TYPEC_PORT_SRC) 5984 5998 return 0; 5985 5999 5986 - /* Get the preferred power role for DRP */ 5987 - ret = fwnode_property_read_string(fwnode, "try-power-role", &cap_str); 5988 - if (ret < 0) 5989 - return ret; 5990 - 5991 - port->typec_caps.prefer_role = typec_find_power_role(cap_str); 5992 - if (port->typec_caps.prefer_role < 0) 5993 - return -EINVAL; 5994 6000 sink: 5995 6001 port->self_powered = fwnode_property_read_bool(fwnode, "self-powered"); 5996 6002
+5
drivers/usb/typec/tipd/core.c
··· 256 256 typec_set_pwr_opmode(tps->port, mode); 257 257 typec_set_pwr_role(tps->port, TPS_STATUS_TO_TYPEC_PORTROLE(status)); 258 258 typec_set_vconn_role(tps->port, TPS_STATUS_TO_TYPEC_VCONN(status)); 259 + if (TPS_STATUS_TO_UPSIDE_DOWN(status)) 260 + typec_set_orientation(tps->port, TYPEC_ORIENTATION_REVERSE); 261 + else 262 + typec_set_orientation(tps->port, TYPEC_ORIENTATION_NORMAL); 259 263 tps6598x_set_data_role(tps, TPS_STATUS_TO_TYPEC_DATAROLE(status), true); 260 264 261 265 tps->partner = typec_register_partner(tps->port, &desc); ··· 282 278 typec_set_pwr_opmode(tps->port, TYPEC_PWR_MODE_USB); 283 279 typec_set_pwr_role(tps->port, TPS_STATUS_TO_TYPEC_PORTROLE(status)); 284 280 typec_set_vconn_role(tps->port, TPS_STATUS_TO_TYPEC_VCONN(status)); 281 + typec_set_orientation(tps->port, TYPEC_ORIENTATION_NONE); 285 282 tps6598x_set_data_role(tps, TPS_STATUS_TO_TYPEC_DATAROLE(status), false); 286 283 287 284 power_supply_changed(tps->psy);
+1
drivers/usb/typec/tipd/tps6598x.h
··· 17 17 /* TPS_REG_STATUS bits */ 18 18 #define TPS_STATUS_PLUG_PRESENT BIT(0) 19 19 #define TPS_STATUS_PLUG_UPSIDE_DOWN BIT(4) 20 + #define TPS_STATUS_TO_UPSIDE_DOWN(s) (!!((s) & TPS_STATUS_PLUG_UPSIDE_DOWN)) 20 21 #define TPS_STATUS_PORTROLE BIT(5) 21 22 #define TPS_STATUS_TO_TYPEC_PORTROLE(s) (!!((s) & TPS_STATUS_PORTROLE)) 22 23 #define TPS_STATUS_DATAROLE BIT(6)
+437
drivers/usb/typec/wusb3801.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * Willsemi WUSB3801 Type-C port controller driver 4 + * 5 + * Copyright (C) 2022 Samuel Holland <samuel@sholland.org> 6 + */ 7 + 8 + #include <linux/i2c.h> 9 + #include <linux/module.h> 10 + #include <linux/regmap.h> 11 + #include <linux/regulator/consumer.h> 12 + #include <linux/usb/typec.h> 13 + 14 + #define WUSB3801_REG_DEVICE_ID 0x01 15 + #define WUSB3801_REG_CTRL0 0x02 16 + #define WUSB3801_REG_INT 0x03 17 + #define WUSB3801_REG_STAT 0x04 18 + #define WUSB3801_REG_CTRL1 0x05 19 + #define WUSB3801_REG_TEST00 0x06 20 + #define WUSB3801_REG_TEST01 0x07 21 + #define WUSB3801_REG_TEST02 0x08 22 + #define WUSB3801_REG_TEST03 0x09 23 + #define WUSB3801_REG_TEST04 0x0a 24 + #define WUSB3801_REG_TEST05 0x0b 25 + #define WUSB3801_REG_TEST06 0x0c 26 + #define WUSB3801_REG_TEST07 0x0d 27 + #define WUSB3801_REG_TEST08 0x0e 28 + #define WUSB3801_REG_TEST09 0x0f 29 + #define WUSB3801_REG_TEST0A 0x10 30 + #define WUSB3801_REG_TEST0B 0x11 31 + #define WUSB3801_REG_TEST0C 0x12 32 + #define WUSB3801_REG_TEST0D 0x13 33 + #define WUSB3801_REG_TEST0E 0x14 34 + #define WUSB3801_REG_TEST0F 0x15 35 + #define WUSB3801_REG_TEST10 0x16 36 + #define WUSB3801_REG_TEST11 0x17 37 + #define WUSB3801_REG_TEST12 0x18 38 + 39 + #define WUSB3801_DEVICE_ID_VERSION_ID GENMASK(7, 3) 40 + #define WUSB3801_DEVICE_ID_VENDOR_ID GENMASK(2, 0) 41 + 42 + #define WUSB3801_CTRL0_DIS_ACC_SUPPORT BIT(7) 43 + #define WUSB3801_CTRL0_TRY GENMASK(6, 5) 44 + #define WUSB3801_CTRL0_TRY_NONE (0x0 << 5) 45 + #define WUSB3801_CTRL0_TRY_SNK (0x1 << 5) 46 + #define WUSB3801_CTRL0_TRY_SRC (0x2 << 5) 47 + #define WUSB3801_CTRL0_CURRENT GENMASK(4, 3) /* SRC */ 48 + #define WUSB3801_CTRL0_CURRENT_DEFAULT (0x0 << 3) 49 + #define WUSB3801_CTRL0_CURRENT_1_5A (0x1 << 3) 50 + #define WUSB3801_CTRL0_CURRENT_3_0A (0x2 << 3) 51 + #define WUSB3801_CTRL0_ROLE GENMASK(2, 1) 52 + #define WUSB3801_CTRL0_ROLE_SNK (0x0 << 1) 53 + #define WUSB3801_CTRL0_ROLE_SRC (0x1 << 1) 54 + #define WUSB3801_CTRL0_ROLE_DRP (0x2 << 1) 55 + #define WUSB3801_CTRL0_INT_MASK BIT(0) 56 + 57 + #define WUSB3801_INT_ATTACHED BIT(0) 58 + #define WUSB3801_INT_DETACHED BIT(1) 59 + 60 + #define WUSB3801_STAT_VBUS_DETECTED BIT(7) 61 + #define WUSB3801_STAT_CURRENT GENMASK(6, 5) /* SNK */ 62 + #define WUSB3801_STAT_CURRENT_STANDBY (0x0 << 5) 63 + #define WUSB3801_STAT_CURRENT_DEFAULT (0x1 << 5) 64 + #define WUSB3801_STAT_CURRENT_1_5A (0x2 << 5) 65 + #define WUSB3801_STAT_CURRENT_3_0A (0x3 << 5) 66 + #define WUSB3801_STAT_PARTNER GENMASK(4, 2) 67 + #define WUSB3801_STAT_PARTNER_STANDBY (0x0 << 2) 68 + #define WUSB3801_STAT_PARTNER_SNK (0x1 << 2) 69 + #define WUSB3801_STAT_PARTNER_SRC (0x2 << 2) 70 + #define WUSB3801_STAT_PARTNER_AUDIO (0x3 << 2) 71 + #define WUSB3801_STAT_PARTNER_DEBUG (0x4 << 2) 72 + #define WUSB3801_STAT_ORIENTATION GENMASK(1, 0) 73 + #define WUSB3801_STAT_ORIENTATION_NONE (0x0 << 0) 74 + #define WUSB3801_STAT_ORIENTATION_CC1 (0x1 << 0) 75 + #define WUSB3801_STAT_ORIENTATION_CC2 (0x2 << 0) 76 + #define WUSB3801_STAT_ORIENTATION_BOTH (0x3 << 0) 77 + 78 + #define WUSB3801_CTRL1_SM_RESET BIT(0) 79 + 80 + #define WUSB3801_TEST01_VENDOR_SUB_ID (BIT(8) | BIT(6)) 81 + 82 + #define WUSB3801_TEST02_FORCE_ERR_RCY BIT(8) 83 + 84 + #define WUSB3801_TEST0A_WAIT_VBUS BIT(5) 85 + 86 + struct wusb3801 { 87 + struct typec_capability cap; 88 + struct device *dev; 89 + struct typec_partner *partner; 90 + struct typec_port *port; 91 + struct regmap *regmap; 92 + struct regulator *vbus_supply; 93 + unsigned int partner_type; 94 + enum typec_port_type port_type; 95 + enum typec_pwr_opmode pwr_opmode; 96 + bool vbus_on; 97 + }; 98 + 99 + static enum typec_role wusb3801_get_default_role(struct wusb3801 *wusb3801) 100 + { 101 + switch (wusb3801->port_type) { 102 + case TYPEC_PORT_SRC: 103 + return TYPEC_SOURCE; 104 + case TYPEC_PORT_SNK: 105 + return TYPEC_SINK; 106 + case TYPEC_PORT_DRP: 107 + default: 108 + if (wusb3801->cap.prefer_role == TYPEC_SOURCE) 109 + return TYPEC_SOURCE; 110 + return TYPEC_SINK; 111 + } 112 + } 113 + 114 + static int wusb3801_map_port_type(enum typec_port_type type) 115 + { 116 + switch (type) { 117 + case TYPEC_PORT_SRC: 118 + return WUSB3801_CTRL0_ROLE_SRC; 119 + case TYPEC_PORT_SNK: 120 + return WUSB3801_CTRL0_ROLE_SNK; 121 + case TYPEC_PORT_DRP: 122 + default: 123 + return WUSB3801_CTRL0_ROLE_DRP; 124 + } 125 + } 126 + 127 + static int wusb3801_map_pwr_opmode(enum typec_pwr_opmode mode) 128 + { 129 + switch (mode) { 130 + case TYPEC_PWR_MODE_USB: 131 + default: 132 + return WUSB3801_CTRL0_CURRENT_DEFAULT; 133 + case TYPEC_PWR_MODE_1_5A: 134 + return WUSB3801_CTRL0_CURRENT_1_5A; 135 + case TYPEC_PWR_MODE_3_0A: 136 + return WUSB3801_CTRL0_CURRENT_3_0A; 137 + } 138 + } 139 + 140 + static unsigned int wusb3801_map_try_role(int role) 141 + { 142 + switch (role) { 143 + case TYPEC_NO_PREFERRED_ROLE: 144 + default: 145 + return WUSB3801_CTRL0_TRY_NONE; 146 + case TYPEC_SINK: 147 + return WUSB3801_CTRL0_TRY_SNK; 148 + case TYPEC_SOURCE: 149 + return WUSB3801_CTRL0_TRY_SRC; 150 + } 151 + } 152 + 153 + static enum typec_orientation wusb3801_unmap_orientation(unsigned int status) 154 + { 155 + switch (status & WUSB3801_STAT_ORIENTATION) { 156 + case WUSB3801_STAT_ORIENTATION_NONE: 157 + case WUSB3801_STAT_ORIENTATION_BOTH: 158 + default: 159 + return TYPEC_ORIENTATION_NONE; 160 + case WUSB3801_STAT_ORIENTATION_CC1: 161 + return TYPEC_ORIENTATION_NORMAL; 162 + case WUSB3801_STAT_ORIENTATION_CC2: 163 + return TYPEC_ORIENTATION_REVERSE; 164 + } 165 + } 166 + 167 + static enum typec_pwr_opmode wusb3801_unmap_pwr_opmode(unsigned int status) 168 + { 169 + switch (status & WUSB3801_STAT_CURRENT) { 170 + case WUSB3801_STAT_CURRENT_STANDBY: 171 + case WUSB3801_STAT_CURRENT_DEFAULT: 172 + default: 173 + return TYPEC_PWR_MODE_USB; 174 + case WUSB3801_STAT_CURRENT_1_5A: 175 + return TYPEC_PWR_MODE_1_5A; 176 + case WUSB3801_STAT_CURRENT_3_0A: 177 + return TYPEC_PWR_MODE_3_0A; 178 + } 179 + } 180 + 181 + static int wusb3801_try_role(struct typec_port *port, int role) 182 + { 183 + struct wusb3801 *wusb3801 = typec_get_drvdata(port); 184 + 185 + return regmap_update_bits(wusb3801->regmap, WUSB3801_REG_CTRL0, 186 + WUSB3801_CTRL0_TRY, 187 + wusb3801_map_try_role(role)); 188 + } 189 + 190 + static int wusb3801_port_type_set(struct typec_port *port, 191 + enum typec_port_type type) 192 + { 193 + struct wusb3801 *wusb3801 = typec_get_drvdata(port); 194 + int ret; 195 + 196 + ret = regmap_update_bits(wusb3801->regmap, WUSB3801_REG_CTRL0, 197 + WUSB3801_CTRL0_ROLE, 198 + wusb3801_map_port_type(type)); 199 + if (ret) 200 + return ret; 201 + 202 + wusb3801->port_type = type; 203 + 204 + return 0; 205 + } 206 + 207 + static const struct typec_operations wusb3801_typec_ops = { 208 + .try_role = wusb3801_try_role, 209 + .port_type_set = wusb3801_port_type_set, 210 + }; 211 + 212 + static int wusb3801_hw_init(struct wusb3801 *wusb3801) 213 + { 214 + return regmap_write(wusb3801->regmap, WUSB3801_REG_CTRL0, 215 + wusb3801_map_try_role(wusb3801->cap.prefer_role) | 216 + wusb3801_map_pwr_opmode(wusb3801->pwr_opmode) | 217 + wusb3801_map_port_type(wusb3801->port_type)); 218 + } 219 + 220 + static void wusb3801_hw_update(struct wusb3801 *wusb3801) 221 + { 222 + struct typec_port *port = wusb3801->port; 223 + struct device *dev = wusb3801->dev; 224 + unsigned int partner_type, status; 225 + int ret; 226 + 227 + ret = regmap_read(wusb3801->regmap, WUSB3801_REG_STAT, &status); 228 + if (ret) { 229 + dev_warn(dev, "Failed to read port status: %d\n", ret); 230 + status = 0; 231 + } 232 + dev_dbg(dev, "status = 0x%02x\n", status); 233 + 234 + partner_type = status & WUSB3801_STAT_PARTNER; 235 + 236 + if (partner_type == WUSB3801_STAT_PARTNER_SNK) { 237 + if (!wusb3801->vbus_on) { 238 + ret = regulator_enable(wusb3801->vbus_supply); 239 + if (ret) 240 + dev_warn(dev, "Failed to enable VBUS: %d\n", ret); 241 + wusb3801->vbus_on = true; 242 + } 243 + } else { 244 + if (wusb3801->vbus_on) { 245 + regulator_disable(wusb3801->vbus_supply); 246 + wusb3801->vbus_on = false; 247 + } 248 + } 249 + 250 + if (partner_type != wusb3801->partner_type) { 251 + struct typec_partner_desc desc = {}; 252 + enum typec_data_role data_role; 253 + enum typec_role pwr_role = wusb3801_get_default_role(wusb3801); 254 + 255 + switch (partner_type) { 256 + case WUSB3801_STAT_PARTNER_STANDBY: 257 + break; 258 + case WUSB3801_STAT_PARTNER_SNK: 259 + pwr_role = TYPEC_SOURCE; 260 + break; 261 + case WUSB3801_STAT_PARTNER_SRC: 262 + pwr_role = TYPEC_SINK; 263 + break; 264 + case WUSB3801_STAT_PARTNER_AUDIO: 265 + desc.accessory = TYPEC_ACCESSORY_AUDIO; 266 + break; 267 + case WUSB3801_STAT_PARTNER_DEBUG: 268 + desc.accessory = TYPEC_ACCESSORY_DEBUG; 269 + break; 270 + } 271 + 272 + if (wusb3801->partner) { 273 + typec_unregister_partner(wusb3801->partner); 274 + wusb3801->partner = NULL; 275 + } 276 + 277 + if (partner_type != WUSB3801_STAT_PARTNER_STANDBY) { 278 + wusb3801->partner = typec_register_partner(port, &desc); 279 + if (IS_ERR(wusb3801->partner)) 280 + dev_err(dev, "Failed to register partner: %ld\n", 281 + PTR_ERR(wusb3801->partner)); 282 + } 283 + 284 + data_role = pwr_role == TYPEC_SOURCE ? TYPEC_HOST : TYPEC_DEVICE; 285 + typec_set_data_role(port, data_role); 286 + typec_set_pwr_role(port, pwr_role); 287 + typec_set_vconn_role(port, pwr_role); 288 + } 289 + 290 + typec_set_pwr_opmode(wusb3801->port, 291 + partner_type == WUSB3801_STAT_PARTNER_SRC 292 + ? wusb3801_unmap_pwr_opmode(status) 293 + : wusb3801->pwr_opmode); 294 + typec_set_orientation(wusb3801->port, 295 + wusb3801_unmap_orientation(status)); 296 + 297 + wusb3801->partner_type = partner_type; 298 + } 299 + 300 + static irqreturn_t wusb3801_irq(int irq, void *data) 301 + { 302 + struct wusb3801 *wusb3801 = data; 303 + unsigned int dummy; 304 + 305 + /* 306 + * The interrupt register must be read in order to clear the IRQ, 307 + * but all of the useful information is in the status register. 308 + */ 309 + regmap_read(wusb3801->regmap, WUSB3801_REG_INT, &dummy); 310 + 311 + wusb3801_hw_update(wusb3801); 312 + 313 + return IRQ_HANDLED; 314 + } 315 + 316 + static const struct regmap_config config = { 317 + .reg_bits = 8, 318 + .val_bits = 8, 319 + .max_register = WUSB3801_REG_TEST12, 320 + }; 321 + 322 + static int wusb3801_probe(struct i2c_client *client) 323 + { 324 + struct device *dev = &client->dev; 325 + struct fwnode_handle *connector; 326 + struct wusb3801 *wusb3801; 327 + const char *cap_str; 328 + int ret; 329 + 330 + wusb3801 = devm_kzalloc(dev, sizeof(*wusb3801), GFP_KERNEL); 331 + if (!wusb3801) 332 + return -ENOMEM; 333 + 334 + i2c_set_clientdata(client, wusb3801); 335 + 336 + wusb3801->dev = dev; 337 + 338 + wusb3801->regmap = devm_regmap_init_i2c(client, &config); 339 + if (IS_ERR(wusb3801->regmap)) 340 + return PTR_ERR(wusb3801->regmap); 341 + 342 + wusb3801->vbus_supply = devm_regulator_get(dev, "vbus"); 343 + if (IS_ERR(wusb3801->vbus_supply)) 344 + return PTR_ERR(wusb3801->vbus_supply); 345 + 346 + connector = device_get_named_child_node(dev, "connector"); 347 + if (!connector) 348 + return -ENODEV; 349 + 350 + ret = typec_get_fw_cap(&wusb3801->cap, connector); 351 + if (ret) 352 + goto err_put_connector; 353 + wusb3801->port_type = wusb3801->cap.type; 354 + 355 + ret = fwnode_property_read_string(connector, "typec-power-opmode", &cap_str); 356 + if (ret) 357 + goto err_put_connector; 358 + 359 + ret = typec_find_pwr_opmode(cap_str); 360 + if (ret < 0 || ret == TYPEC_PWR_MODE_PD) 361 + goto err_put_connector; 362 + wusb3801->pwr_opmode = ret; 363 + 364 + /* Initialize the hardware with the devicetree settings. */ 365 + ret = wusb3801_hw_init(wusb3801); 366 + if (ret) 367 + return ret; 368 + 369 + wusb3801->cap.revision = USB_TYPEC_REV_1_2; 370 + wusb3801->cap.accessory[0] = TYPEC_ACCESSORY_AUDIO; 371 + wusb3801->cap.accessory[1] = TYPEC_ACCESSORY_DEBUG; 372 + wusb3801->cap.orientation_aware = true; 373 + wusb3801->cap.driver_data = wusb3801; 374 + wusb3801->cap.ops = &wusb3801_typec_ops; 375 + 376 + wusb3801->port = typec_register_port(dev, &wusb3801->cap); 377 + if (IS_ERR(wusb3801->port)) { 378 + ret = PTR_ERR(wusb3801->port); 379 + goto err_put_connector; 380 + } 381 + 382 + /* Initialize the port attributes from the hardware state. */ 383 + wusb3801_hw_update(wusb3801); 384 + 385 + ret = request_threaded_irq(client->irq, NULL, wusb3801_irq, 386 + IRQF_ONESHOT, dev_name(dev), wusb3801); 387 + if (ret) 388 + goto err_unregister_port; 389 + 390 + fwnode_handle_put(connector); 391 + 392 + return 0; 393 + 394 + err_unregister_port: 395 + typec_unregister_port(wusb3801->port); 396 + err_put_connector: 397 + fwnode_handle_put(connector); 398 + 399 + return ret; 400 + } 401 + 402 + static int wusb3801_remove(struct i2c_client *client) 403 + { 404 + struct wusb3801 *wusb3801 = i2c_get_clientdata(client); 405 + 406 + free_irq(client->irq, wusb3801); 407 + 408 + if (wusb3801->partner) 409 + typec_unregister_partner(wusb3801->partner); 410 + typec_unregister_port(wusb3801->port); 411 + 412 + if (wusb3801->vbus_on) 413 + regulator_disable(wusb3801->vbus_supply); 414 + 415 + return 0; 416 + } 417 + 418 + static const struct of_device_id wusb3801_of_match[] = { 419 + { .compatible = "willsemi,wusb3801" }, 420 + {} 421 + }; 422 + MODULE_DEVICE_TABLE(of, wusb3801_of_match); 423 + 424 + static struct i2c_driver wusb3801_driver = { 425 + .probe_new = wusb3801_probe, 426 + .remove = wusb3801_remove, 427 + .driver = { 428 + .name = "wusb3801", 429 + .of_match_table = wusb3801_of_match, 430 + }, 431 + }; 432 + 433 + module_i2c_driver(wusb3801_driver); 434 + 435 + MODULE_AUTHOR("Samuel Holland <samuel@sholland.org>"); 436 + MODULE_DESCRIPTION("Willsemi WUSB3801 Type-C port controller driver"); 437 + MODULE_LICENSE("GPL");
+5 -5
drivers/usb/usbip/vudc_main.c
··· 26 26 }, 27 27 }; 28 28 29 - static struct list_head vudc_devices = LIST_HEAD_INIT(vudc_devices); 29 + static LIST_HEAD(vudc_devices); 30 30 31 - static int __init init(void) 31 + static int __init vudc_init(void) 32 32 { 33 33 int retval = -ENOMEM; 34 34 int i; ··· 86 86 out: 87 87 return retval; 88 88 } 89 - module_init(init); 89 + module_init(vudc_init); 90 90 91 - static void __exit cleanup(void) 91 + static void __exit vudc_cleanup(void) 92 92 { 93 93 struct vudc_device *udc_dev = NULL, *udc_dev2 = NULL; 94 94 ··· 103 103 } 104 104 platform_driver_unregister(&vudc_driver); 105 105 } 106 - module_exit(cleanup); 106 + module_exit(vudc_cleanup); 107 107 108 108 MODULE_DESCRIPTION("USB over IP Device Controller"); 109 109 MODULE_AUTHOR("Krzysztof Opasiak, Karol Kosik, Igor Kotrasinski");
+3
include/linux/usb/typec.h
··· 295 295 296 296 void *typec_get_drvdata(struct typec_port *port); 297 297 298 + int typec_get_fw_cap(struct typec_capability *cap, 299 + struct fwnode_handle *fwnode); 300 + 298 301 int typec_find_pwr_opmode(const char *name); 299 302 int typec_find_orientation(const char *name); 300 303 int typec_find_port_power_role(const char *name);
+1 -1
include/linux/usb/xhci-dbgp.h
··· 15 15 #define __LINUX_XHCI_DBGP_H 16 16 17 17 #ifdef CONFIG_EARLY_PRINTK_USB_XDBC 18 - int __init early_xdbc_parse_parameter(char *s); 18 + int __init early_xdbc_parse_parameter(char *s, int keep_early); 19 19 int __init early_xdbc_setup_hardware(void); 20 20 void __init early_xdbc_register_console(void); 21 21 #else