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

Configure Feed

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

Merge tag 'usb-6.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 drivers for 6.18-rc1. It
was another normal development cycle, with lots of the usual drivers
getting updates:

- Thunderbolt driver cleanups and additions

- dwc3 driver updates

- dwc2 driver updates

- typec driver updates

- xhci driver updates and additions

- offload USB engine updates for better power management

- unused tracepoint removals

- usb gadget fixes and updates as more users start to rely on these
drivers instead of the "old" function gadget drivers

- new USB device ids

- other minor driver USB driver updates

- new USB I/O driver framework and driver additions"

The last item, the usb i/o driver, has an i2c and gpio driver added
through this tree. Those drivers were acked by the respective
subsystem maintainers.

All of these have been in linux-next for a while"

* tag 'usb-6.18-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb: (132 commits)
usb: vhci-hcd: Prevent suspending virtually attached devices
USB: serial: option: add SIMCom 8230C compositions
thunderbolt: Fix use-after-free in tb_dp_dprx_work
usb: xhci: align PORTSC trace with one-based port numbering
usb: xhci: correct indentation for PORTSC tracing function
usb: xhci: improve TR Dequeue Pointer mask
usb: xhci-pci: add support for hosts with zero USB3 ports
usb: xhci: Update a comment about Stop Endpoint retries
Revert "usb: xhci: Avoid Stop Endpoint retry loop if the endpoint seems Running"
usb: gadget: f_rndis: Refactor bind path to use __free()
usb: gadget: f_ecm: Refactor bind path to use __free()
usb: gadget: f_acm: Refactor bind path to use __free()
usb: gadget: f_ncm: Refactor bind path to use __free()
usb: gadget: Introduce free_usb_request helper
usb: gadget: Store endpoint pointer in usb_request
usb: host: xhci-rcar: Add Renesas RZ/G3E USB3 Host driver support
usb: host: xhci-plat: Add .post_resume_quirk for struct xhci_plat_priv
usb: host: xhci-rcar: Move R-Car reg definitions
dt-bindings: usb: Document Renesas RZ/G3E USB3HOST
usb: gadget: f_fs: Fix epfile null pointer access after ep enable.
...

+4793 -1226
+5
CREDITS
··· 1890 1890 S: RG6 2NU 1891 1891 S: United Kingdom 1892 1892 1893 + N: Michael Jamet 1894 + E: michael.jamet@intel.com 1895 + D: Thunderbolt/USB4 driver maintainer 1896 + D: Thunderbolt/USB4 networking driver maintainer 1897 + 1893 1898 N: Dave Jeffery 1894 1899 E: dhjeffery@gmail.com 1895 1900 D: SCSI hacks and IBM ServeRAID RAID driver maintenance
+39
Documentation/devicetree/bindings/usb/intel,ixp4xx-udc.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/intel,ixp4xx-udc.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Intel IXP4xx SoC USB Device Controller (UDC) 8 + 9 + description: The IXP4xx SoCs has a full-speed USB Device 10 + Controller with 16 endpoints and a built-in transceiver. 11 + 12 + maintainers: 13 + - Linus Walleij <linus.walleij@linaro.org> 14 + 15 + properties: 16 + compatible: 17 + const: intel,ixp4xx-udc 18 + 19 + reg: 20 + maxItems: 1 21 + 22 + interrupts: 23 + maxItems: 1 24 + 25 + required: 26 + - compatible 27 + - reg 28 + - interrupts 29 + 30 + additionalProperties: false 31 + 32 + examples: 33 + - | 34 + #include <dt-bindings/interrupt-controller/irq.h> 35 + usb@c800b000 { 36 + compatible = "intel,ixp4xx-udc"; 37 + reg = <0xc800b000 0x1000>; 38 + interrupts = <12 IRQ_TYPE_LEVEL_HIGH>; 39 + };
-23
Documentation/devicetree/bindings/usb/nvidia,tegra20-ehci.txt
··· 1 - Tegra SOC USB controllers 2 - 3 - The device node for a USB controller that is part of a Tegra 4 - SOC is as described in the document "Open Firmware Recommended 5 - Practice : Universal Serial Bus" with the following modifications 6 - and additions : 7 - 8 - Required properties : 9 - - compatible : For Tegra20, must contain "nvidia,tegra20-ehci". 10 - For Tegra30, must contain "nvidia,tegra30-ehci". Otherwise, must contain 11 - "nvidia,<chip>-ehci" plus at least one of the above, where <chip> is 12 - tegra114, tegra124, tegra132, or tegra210. 13 - - nvidia,phy : phandle of the PHY that the controller is connected to. 14 - - clocks : Must contain one entry, for the module clock. 15 - See ../clocks/clock-bindings.txt for details. 16 - - resets : Must contain an entry for each entry in reset-names. 17 - See ../reset/reset.txt for details. 18 - - reset-names : Must include the following entries: 19 - - usb 20 - 21 - Optional properties: 22 - - nvidia,needs-double-reset : boolean is to be set for some of the Tegra20 23 - USB ports, which need reset twice due to hardware issues.
+87
Documentation/devicetree/bindings/usb/renesas,rzg3e-xhci.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/renesas,rzg3e-xhci.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Renesas RZ/G3E USB 3.2 Gen2 Host controller 8 + 9 + maintainers: 10 + - Biju Das <biju.das.jz@bp.renesas.com> 11 + 12 + properties: 13 + compatible: 14 + const: renesas,r9a09g047-xhci 15 + 16 + reg: 17 + maxItems: 1 18 + 19 + interrupts: 20 + items: 21 + - description: Logical OR of all interrupt signals. 22 + - description: System management interrupt 23 + - description: Host system error interrupt 24 + - description: Power management event interrupt 25 + - description: xHC interrupt 26 + 27 + interrupt-names: 28 + items: 29 + - const: all 30 + - const: smi 31 + - const: hse 32 + - const: pme 33 + - const: xhc 34 + 35 + clocks: 36 + maxItems: 1 37 + 38 + phys: 39 + maxItems: 2 40 + 41 + phy-names: 42 + items: 43 + - const: usb2-phy 44 + - const: usb3-phy 45 + 46 + power-domains: 47 + maxItems: 1 48 + 49 + resets: 50 + maxItems: 1 51 + 52 + required: 53 + - compatible 54 + - reg 55 + - interrupts 56 + - interrupt-names 57 + - clocks 58 + - power-domains 59 + - resets 60 + - phys 61 + - phy-names 62 + 63 + allOf: 64 + - $ref: usb-xhci.yaml 65 + 66 + additionalProperties: false 67 + 68 + examples: 69 + - | 70 + #include <dt-bindings/clock/renesas,r9a09g047-cpg.h> 71 + #include <dt-bindings/interrupt-controller/arm-gic.h> 72 + 73 + usb@15850000 { 74 + compatible = "renesas,r9a09g047-xhci"; 75 + reg = <0x15850000 0x10000>; 76 + interrupts = <GIC_SPI 759 IRQ_TYPE_LEVEL_HIGH>, 77 + <GIC_SPI 758 IRQ_TYPE_LEVEL_HIGH>, 78 + <GIC_SPI 757 IRQ_TYPE_LEVEL_HIGH>, 79 + <GIC_SPI 756 IRQ_TYPE_LEVEL_HIGH>, 80 + <GIC_SPI 755 IRQ_TYPE_LEVEL_HIGH>; 81 + interrupt-names = "all", "smi", "hse", "pme", "xhc"; 82 + clocks = <&cpg CPG_MOD 0xaf>; 83 + power-domains = <&cpg>; 84 + resets = <&cpg 0xaa>; 85 + phys = <&usb3_phy>, <&usb3_phy>; 86 + phy-names = "usb2-phy", "usb3-phy"; 87 + };
+25 -3
Documentation/devicetree/bindings/usb/renesas,usbhs.yaml
··· 59 59 - renesas,usbhs-r8a77995 # R-Car D3 60 60 - const: renesas,rcar-gen3-usbhs 61 61 62 + - const: renesas,usbhs-r9a09g077 # RZ/T2H 63 + 64 + - items: 65 + - const: renesas,usbhs-r9a09g087 # RZ/N2H 66 + - const: renesas,usbhs-r9a09g077 # RZ/T2H 67 + 62 68 reg: 63 69 maxItems: 1 64 70 ··· 147 141 required: 148 142 - resets 149 143 else: 150 - properties: 151 - interrupts: 152 - maxItems: 1 144 + if: 145 + properties: 146 + compatible: 147 + contains: 148 + const: renesas,usbhs-r9a09g077 149 + then: 150 + properties: 151 + resets: false 152 + clocks: 153 + maxItems: 1 154 + interrupts: 155 + items: 156 + - description: USB function interrupt USB_FI 157 + - description: USB function DMA0 transmit completion interrupt USB_FDMA0 158 + - description: USB function DMA1 transmit completion interrupt USB_FDMA1 159 + else: 160 + properties: 161 + interrupts: 162 + maxItems: 1 153 163 154 164 additionalProperties: false 155 165
-22
Documentation/devicetree/bindings/usb/s3c2410-usb.txt
··· 1 - Samsung S3C2410 and compatible SoC USB controller 2 - 3 - OHCI 4 - 5 - Required properties: 6 - - compatible: should be "samsung,s3c2410-ohci" for USB host controller 7 - - reg: address and length of the controller memory mapped region 8 - - interrupts: interrupt number for the USB OHCI controller 9 - - clocks: Should reference the bus and host clocks 10 - - clock-names: Should contain two strings 11 - "usb-bus-host" for the USB bus clock 12 - "usb-host" for the USB host clock 13 - 14 - Example: 15 - 16 - usb0: ohci@49000000 { 17 - compatible = "samsung,s3c2410-ohci"; 18 - reg = <0x49000000 0x100>; 19 - interrupts = <0 0 26 3>; 20 - clocks = <&clocks UCLK>, <&clocks HCLK_USBH>; 21 - clock-names = "usb-bus-host", "usb-host"; 22 - };
+121
Documentation/devicetree/bindings/usb/spacemit,k1-dwc3.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/usb/spacemit,k1-dwc3.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: SpacemiT K1 SuperSpeed DWC3 USB SoC Controller 8 + 9 + maintainers: 10 + - Ze Huang <huang.ze@linux.dev> 11 + 12 + description: | 13 + The SpacemiT K1 embeds a DWC3 USB IP Core which supports Host functions 14 + for USB 3.0 and DRD for USB 2.0. 15 + 16 + Key features: 17 + - USB3.0 SuperSpeed and USB2.0 High/Full/Low-Speed support 18 + - Supports low-power modes (USB2.0 suspend, USB3.0 U1/U2/U3) 19 + - Internal DMA controller and flexible endpoint FIFO sizing 20 + 21 + Communication Interface: 22 + - Use of PIPE3 (125MHz) interface for USB3.0 PHY 23 + - Use of UTMI+ (30/60MHz) interface for USB2.0 PHY 24 + 25 + allOf: 26 + - $ref: snps,dwc3-common.yaml# 27 + 28 + properties: 29 + compatible: 30 + const: spacemit,k1-dwc3 31 + 32 + reg: 33 + maxItems: 1 34 + 35 + clocks: 36 + maxItems: 1 37 + 38 + clock-names: 39 + const: usbdrd30 40 + 41 + interrupts: 42 + maxItems: 1 43 + 44 + phys: 45 + items: 46 + - description: phandle to USB2/HS PHY 47 + - description: phandle to USB3/SS PHY 48 + 49 + phy-names: 50 + items: 51 + - const: usb2-phy 52 + - const: usb3-phy 53 + 54 + resets: 55 + items: 56 + - description: USB3.0 AHB reset 57 + - description: USB3.0 VCC reset 58 + - description: USB3.0 PHY reset 59 + 60 + reset-names: 61 + items: 62 + - const: ahb 63 + - const: vcc 64 + - const: phy 65 + 66 + reset-delay: 67 + $ref: /schemas/types.yaml#/definitions/uint32 68 + default: 2 69 + description: delay after reset sequence [us] 70 + 71 + vbus-supply: 72 + description: A phandle to the regulator supplying the VBUS voltage. 73 + 74 + required: 75 + - compatible 76 + - reg 77 + - clocks 78 + - clock-names 79 + - interrupts 80 + - phys 81 + - phy-names 82 + - resets 83 + - reset-names 84 + 85 + unevaluatedProperties: false 86 + 87 + examples: 88 + - | 89 + usb@c0a00000 { 90 + compatible = "spacemit,k1-dwc3"; 91 + reg = <0xc0a00000 0x10000>; 92 + clocks = <&syscon_apmu 16>; 93 + clock-names = "usbdrd30"; 94 + interrupts = <125>; 95 + phys = <&usb2phy>, <&usb3phy>; 96 + phy-names = "usb2-phy", "usb3-phy"; 97 + resets = <&syscon_apmu 8>, 98 + <&syscon_apmu 9>, 99 + <&syscon_apmu 10>; 100 + reset-names = "ahb", "vcc", "phy"; 101 + reset-delay = <2>; 102 + vbus-supply = <&usb3_vbus>; 103 + #address-cells = <1>; 104 + #size-cells = <0>; 105 + 106 + hub_2_0: hub@1 { 107 + compatible = "usb2109,2817"; 108 + reg = <1>; 109 + vdd-supply = <&usb3_vhub>; 110 + peer-hub = <&hub_3_0>; 111 + reset-gpios = <&gpio 3 28 1>; 112 + }; 113 + 114 + hub_3_0: hub@2 { 115 + compatible = "usb2109,817"; 116 + reg = <2>; 117 + vdd-supply = <&usb3_vhub>; 118 + peer-hub = <&hub_2_0>; 119 + reset-gpios = <&gpio 3 28 1>; 120 + }; 121 + };
+74
Documentation/devicetree/bindings/usb/ti,twl4030-usb.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/usb/ti,twl4030-usb.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Texas Instruments TWL4030 USB PHY and Comparator 8 + 9 + maintainers: 10 + - Peter Ujfalusi <peter.ujfalusi@gmail.com> 11 + 12 + description: 13 + Bindings for the USB PHY and comparator module found within the 14 + TWL4030 family of companion chips. If a sibling node is compatible with 15 + "ti,twl4030-bci", the driver for that node will query this device for 16 + USB power status. 17 + 18 + properties: 19 + compatible: 20 + const: ti,twl4030-usb 21 + 22 + interrupts: 23 + minItems: 1 24 + items: 25 + - description: OTG interrupt number for ID events. 26 + - description: USB interrupt number for VBUS events. 27 + 28 + usb1v5-supply: 29 + description: Phandle to the vusb1v5 regulator. 30 + 31 + usb1v8-supply: 32 + description: Phandle to the vusb1v8 regulator. 33 + 34 + usb3v1-supply: 35 + description: Phandle to the vusb3v1 regulator. 36 + 37 + usb_mode: 38 + description: | 39 + The mode used by the PHY to connect to the controller: 40 + 1: ULPI mode 41 + 2: CEA2011_3PIN mode 42 + $ref: /schemas/types.yaml#/definitions/uint32 43 + enum: [1, 2] 44 + 45 + '#phy-cells': 46 + const: 0 47 + 48 + required: 49 + - compatible 50 + - interrupts 51 + - usb1v5-supply 52 + - usb1v8-supply 53 + - usb3v1-supply 54 + - usb_mode 55 + 56 + additionalProperties: false 57 + 58 + examples: 59 + - | 60 + #include <dt-bindings/interrupt-controller/irq.h> 61 + 62 + usb-phy { 63 + compatible = "ti,twl4030-usb"; 64 + 65 + interrupts = <10 IRQ_TYPE_LEVEL_HIGH>; 66 + interrupt-parent = <&gic>; 67 + 68 + usb1v5-supply = <&reg_vusb1v5>; 69 + usb1v8-supply = <&reg_vusb1v8>; 70 + usb3v1-supply = <&reg_vusb3v1>; 71 + usb_mode = <1>; 72 + 73 + #phy-cells = <0>; 74 + };
+48
Documentation/devicetree/bindings/usb/ti,twl6030-usb.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/usb/ti,twl6030-usb.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Texas Instruments TWL6030 USB Comparator 8 + 9 + maintainers: 10 + - Peter Ujfalusi <peter.ujfalusi@gmail.com> 11 + 12 + description: 13 + Bindings for the USB comparator module found within the TWL6030 14 + family of companion chips. 15 + 16 + properties: 17 + compatible: 18 + const: ti,twl6030-usb 19 + 20 + interrupts: 21 + items: 22 + - description: OTG for ID events in host mode 23 + - description: USB device mode for VBUS events 24 + 25 + usb-supply: 26 + description: 27 + Phandle to the VUSB regulator. For TWL6030, this should be the 'vusb' 28 + regulator. For TWL6032 subclass, it should be the 'ldousb' regulator. 29 + 30 + required: 31 + - compatible 32 + - interrupts 33 + - usb-supply 34 + 35 + additionalProperties: false 36 + 37 + examples: 38 + - | 39 + #include <dt-bindings/interrupt-controller/irq.h> 40 + 41 + usb { 42 + compatible = "ti,twl6030-usb"; 43 + 44 + interrupts = <4 IRQ_TYPE_LEVEL_HIGH>, <10 IRQ_TYPE_LEVEL_HIGH>; 45 + interrupt-parent = <&gic>; 46 + 47 + usb-supply = <&reg_vusb>; 48 + };
-43
Documentation/devicetree/bindings/usb/twlxxxx-usb.txt
··· 1 - USB COMPARATOR OF TWL CHIPS 2 - 3 - TWL6030 USB COMPARATOR 4 - - compatible : Should be "ti,twl6030-usb" 5 - - interrupts : Two interrupt numbers to the cpu should be specified. First 6 - interrupt number is the otg interrupt number that raises ID interrupts when 7 - the controller has to act as host and the second interrupt number is the 8 - usb interrupt number that raises VBUS interrupts when the controller has to 9 - act as device 10 - - usb-supply : phandle to the regulator device tree node. It should be vusb 11 - if it is twl6030 or ldousb if it is twl6032 subclass. 12 - 13 - twl6030-usb { 14 - compatible = "ti,twl6030-usb"; 15 - interrupts = < 4 10 >; 16 - }; 17 - 18 - Board specific device node entry 19 - &twl6030-usb { 20 - usb-supply = <&vusb>; 21 - }; 22 - 23 - TWL4030 USB PHY AND COMPARATOR 24 - - compatible : Should be "ti,twl4030-usb" 25 - - interrupts : The interrupt numbers to the cpu should be specified. First 26 - interrupt number is the otg interrupt number that raises ID interrupts 27 - and VBUS interrupts. The second interrupt number is optional. 28 - - <supply-name>-supply : phandle to the regulator device tree node. 29 - <supply-name> should be vusb1v5, vusb1v8 and vusb3v1 30 - - usb_mode : The mode used by the phy to connect to the controller. "1" 31 - specifies "ULPI" mode and "2" specifies "CEA2011_3PIN" mode. 32 - 33 - If a sibling node is compatible "ti,twl4030-bci", then it will find 34 - this device and query it for USB power status. 35 - 36 - twl4030-usb { 37 - compatible = "ti,twl4030-usb"; 38 - interrupts = < 10 4 >; 39 - usb1v5-supply = <&vusb1v5>; 40 - usb1v8-supply = <&vusb1v8>; 41 - usb3v1-supply = <&vusb3v1>; 42 - usb_mode = <1>; 43 - };
+8 -1
Documentation/devicetree/bindings/usb/usb251xb.yaml
··· 240 240 241 241 required: 242 242 - compatible 243 - - reg 244 243 245 244 examples: 246 245 - | ··· 267 268 /* correct misplaced usb connectors on port 1,2 */ 268 269 swap-dx-lanes = <1 2>; 269 270 }; 271 + }; 272 + 273 + - | 274 + #include <dt-bindings/gpio/gpio.h> 275 + usb-hub { 276 + /* I2C is not connected */ 277 + compatible = "microchip,usb2512b"; 278 + reset-gpios = <&porta 8 GPIO_ACTIVE_LOW>; 270 279 };
+10 -2
MAINTAINERS
··· 12875 12875 F: Documentation/admin-guide/pm/intel_uncore_frequency_scaling.rst 12876 12876 F: drivers/platform/x86/intel/uncore-frequency/ 12877 12877 12878 + INTEL USBIO USB I/O EXPANDER DRIVERS 12879 + M: Israel Cepeda <israel.a.cepeda.lopez@intel.com> 12880 + M: Hans de Goede <hansg@kernel.org> 12881 + R: Sakari Ailus <sakari.ailus@linux.intel.com> 12882 + S: Maintained 12883 + F: drivers/gpio/gpio-usbio.c 12884 + F: drivers/i2c/busses/i2c-usbio.c 12885 + F: drivers/usb/misc/usbio.c 12886 + F: include/linux/usb/usbio.h 12887 + 12878 12888 INTEL VENDOR SPECIFIC EXTENDED CAPABILITIES DRIVER 12879 12889 M: David E. Box <david.e.box@linux.intel.com> 12880 12890 S: Supported ··· 25502 25492 25503 25493 THUNDERBOLT DRIVER 25504 25494 M: Andreas Noever <andreas.noever@gmail.com> 25505 - M: Michael Jamet <michael.jamet@intel.com> 25506 25495 M: Mika Westerberg <westeri@kernel.org> 25507 25496 M: Yehezkel Bernat <YehezkelShB@gmail.com> 25508 25497 L: linux-usb@vger.kernel.org ··· 25512 25503 F: include/linux/thunderbolt.h 25513 25504 25514 25505 THUNDERBOLT NETWORK DRIVER 25515 - M: Michael Jamet <michael.jamet@intel.com> 25516 25506 M: Mika Westerberg <westeri@kernel.org> 25517 25507 M: Yehezkel Bernat <YehezkelShB@gmail.com> 25518 25508 L: netdev@vger.kernel.org
+11
drivers/gpio/Kconfig
··· 1951 1951 GPIO driver for FTDI's MPSSE interface. These can do input and 1952 1952 output. Each MPSSE provides 16 IO pins. 1953 1953 1954 + config GPIO_USBIO 1955 + tristate "Intel USBIO GPIO support" 1956 + depends on USB_USBIO 1957 + default USB_USBIO 1958 + help 1959 + Select this option to enable GPIO driver for the INTEL 1960 + USBIO driver stack. 1961 + 1962 + This driver can also be built as a module. If so, the module 1963 + will be called gpio_usbio. 1964 + 1954 1965 endmenu 1955 1966 1956 1967 menu "Virtual GPIO drivers"
+1
drivers/gpio/Makefile
··· 194 194 obj-$(CONFIG_GPIO_TWL4030) += gpio-twl4030.o 195 195 obj-$(CONFIG_GPIO_TWL6040) += gpio-twl6040.o 196 196 obj-$(CONFIG_GPIO_UNIPHIER) += gpio-uniphier.o 197 + obj-$(CONFIG_GPIO_USBIO) += gpio-usbio.o 197 198 obj-$(CONFIG_GPIO_VF610) += gpio-vf610.o 198 199 obj-$(CONFIG_GPIO_VIPERBOARD) += gpio-viperboard.o 199 200 obj-$(CONFIG_GPIO_VIRTUSER) += gpio-virtuser.o
+247
drivers/gpio/gpio-usbio.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * Copyright (c) 2025 Intel Corporation. 4 + * Copyright (c) 2025 Red Hat, Inc. 5 + */ 6 + 7 + #include <linux/acpi.h> 8 + #include <linux/auxiliary_bus.h> 9 + #include <linux/cleanup.h> 10 + #include <linux/device.h> 11 + #include <linux/gpio/driver.h> 12 + #include <linux/mutex.h> 13 + #include <linux/types.h> 14 + #include <linux/usb/usbio.h> 15 + 16 + struct usbio_gpio_bank { 17 + u8 config[USBIO_GPIOSPERBANK]; 18 + u32 bitmap; 19 + }; 20 + 21 + struct usbio_gpio { 22 + struct mutex config_mutex; /* Protects banks[x].config */ 23 + struct usbio_gpio_bank banks[USBIO_MAX_GPIOBANKS]; 24 + struct gpio_chip gc; 25 + struct auxiliary_device *adev; 26 + }; 27 + 28 + static const struct acpi_device_id usbio_gpio_acpi_hids[] = { 29 + { "INTC1007" }, /* MTL */ 30 + { "INTC10B2" }, /* ARL */ 31 + { "INTC10B5" }, /* LNL */ 32 + { "INTC10E2" }, /* PTL */ 33 + { } 34 + }; 35 + 36 + static void usbio_gpio_get_bank_and_pin(struct gpio_chip *gc, unsigned int offset, 37 + struct usbio_gpio_bank **bank_ret, 38 + unsigned int *pin_ret) 39 + { 40 + struct usbio_gpio *gpio = gpiochip_get_data(gc); 41 + struct device *dev = &gpio->adev->dev; 42 + struct usbio_gpio_bank *bank; 43 + unsigned int pin; 44 + 45 + bank = &gpio->banks[offset / USBIO_GPIOSPERBANK]; 46 + pin = offset % USBIO_GPIOSPERBANK; 47 + if (~bank->bitmap & BIT(pin)) { 48 + /* The FW bitmap sometimes is invalid, warn and continue */ 49 + dev_warn_once(dev, FW_BUG "GPIO %u is not in FW pins bitmap\n", offset); 50 + } 51 + 52 + *bank_ret = bank; 53 + *pin_ret = pin; 54 + } 55 + 56 + static int usbio_gpio_get_direction(struct gpio_chip *gc, unsigned int offset) 57 + { 58 + struct usbio_gpio_bank *bank; 59 + unsigned int pin; 60 + u8 cfg; 61 + 62 + usbio_gpio_get_bank_and_pin(gc, offset, &bank, &pin); 63 + 64 + cfg = bank->config[pin] & USBIO_GPIO_PINMOD_MASK; 65 + 66 + return (cfg == USBIO_GPIO_PINMOD_OUTPUT) ? 67 + GPIO_LINE_DIRECTION_OUT : GPIO_LINE_DIRECTION_IN; 68 + } 69 + 70 + static int usbio_gpio_get(struct gpio_chip *gc, unsigned int offset) 71 + { 72 + struct usbio_gpio *gpio = gpiochip_get_data(gc); 73 + struct usbio_gpio_bank *bank; 74 + struct usbio_gpio_rw gbuf; 75 + unsigned int pin; 76 + int ret; 77 + 78 + usbio_gpio_get_bank_and_pin(gc, offset, &bank, &pin); 79 + 80 + gbuf.bankid = offset / USBIO_GPIOSPERBANK; 81 + gbuf.pincount = 1; 82 + gbuf.pin = pin; 83 + 84 + ret = usbio_control_msg(gpio->adev, USBIO_PKTTYPE_GPIO, USBIO_GPIOCMD_READ, 85 + &gbuf, sizeof(gbuf) - sizeof(gbuf.value), 86 + &gbuf, sizeof(gbuf)); 87 + if (ret != sizeof(gbuf)) 88 + return (ret < 0) ? ret : -EPROTO; 89 + 90 + return (le32_to_cpu(gbuf.value) >> pin) & 1; 91 + } 92 + 93 + static int usbio_gpio_set(struct gpio_chip *gc, unsigned int offset, int value) 94 + { 95 + struct usbio_gpio *gpio = gpiochip_get_data(gc); 96 + struct usbio_gpio_bank *bank; 97 + struct usbio_gpio_rw gbuf; 98 + unsigned int pin; 99 + 100 + usbio_gpio_get_bank_and_pin(gc, offset, &bank, &pin); 101 + 102 + gbuf.bankid = offset / USBIO_GPIOSPERBANK; 103 + gbuf.pincount = 1; 104 + gbuf.pin = pin; 105 + gbuf.value = cpu_to_le32(value << pin); 106 + 107 + return usbio_control_msg(gpio->adev, USBIO_PKTTYPE_GPIO, USBIO_GPIOCMD_WRITE, 108 + &gbuf, sizeof(gbuf), NULL, 0); 109 + } 110 + 111 + static int usbio_gpio_update_config(struct gpio_chip *gc, unsigned int offset, 112 + u8 mask, u8 value) 113 + { 114 + struct usbio_gpio *gpio = gpiochip_get_data(gc); 115 + struct usbio_gpio_bank *bank; 116 + struct usbio_gpio_init gbuf; 117 + unsigned int pin; 118 + 119 + usbio_gpio_get_bank_and_pin(gc, offset, &bank, &pin); 120 + 121 + guard(mutex)(&gpio->config_mutex); 122 + 123 + bank->config[pin] &= ~mask; 124 + bank->config[pin] |= value; 125 + 126 + gbuf.bankid = offset / USBIO_GPIOSPERBANK; 127 + gbuf.config = bank->config[pin]; 128 + gbuf.pincount = 1; 129 + gbuf.pin = pin; 130 + 131 + return usbio_control_msg(gpio->adev, USBIO_PKTTYPE_GPIO, USBIO_GPIOCMD_INIT, 132 + &gbuf, sizeof(gbuf), NULL, 0); 133 + } 134 + 135 + static int usbio_gpio_direction_input(struct gpio_chip *gc, unsigned int offset) 136 + { 137 + return usbio_gpio_update_config(gc, offset, USBIO_GPIO_PINMOD_MASK, 138 + USBIO_GPIO_SET_PINMOD(USBIO_GPIO_PINMOD_INPUT)); 139 + } 140 + 141 + static int usbio_gpio_direction_output(struct gpio_chip *gc, 142 + unsigned int offset, int value) 143 + { 144 + int ret; 145 + 146 + ret = usbio_gpio_update_config(gc, offset, USBIO_GPIO_PINMOD_MASK, 147 + USBIO_GPIO_SET_PINMOD(USBIO_GPIO_PINMOD_OUTPUT)); 148 + if (ret) 149 + return ret; 150 + 151 + return usbio_gpio_set(gc, offset, value); 152 + } 153 + 154 + static int usbio_gpio_set_config(struct gpio_chip *gc, unsigned int offset, 155 + unsigned long config) 156 + { 157 + u8 value; 158 + 159 + switch (pinconf_to_config_param(config)) { 160 + case PIN_CONFIG_BIAS_PULL_PIN_DEFAULT: 161 + value = USBIO_GPIO_SET_PINCFG(USBIO_GPIO_PINCFG_DEFAULT); 162 + break; 163 + case PIN_CONFIG_BIAS_PULL_UP: 164 + value = USBIO_GPIO_SET_PINCFG(USBIO_GPIO_PINCFG_PULLUP); 165 + break; 166 + case PIN_CONFIG_BIAS_PULL_DOWN: 167 + value = USBIO_GPIO_SET_PINCFG(USBIO_GPIO_PINCFG_PULLDOWN); 168 + break; 169 + case PIN_CONFIG_DRIVE_PUSH_PULL: 170 + value = USBIO_GPIO_SET_PINCFG(USBIO_GPIO_PINCFG_PUSHPULL); 171 + break; 172 + default: 173 + return -ENOTSUPP; 174 + } 175 + 176 + return usbio_gpio_update_config(gc, offset, USBIO_GPIO_PINCFG_MASK, value); 177 + } 178 + 179 + static int usbio_gpio_probe(struct auxiliary_device *adev, 180 + const struct auxiliary_device_id *adev_id) 181 + { 182 + struct usbio_gpio_bank_desc *bank_desc; 183 + struct device *dev = &adev->dev; 184 + struct usbio_gpio *gpio; 185 + int bank, ret; 186 + 187 + bank_desc = dev_get_platdata(dev); 188 + if (!bank_desc) 189 + return -EINVAL; 190 + 191 + gpio = devm_kzalloc(dev, sizeof(*gpio), GFP_KERNEL); 192 + if (!gpio) 193 + return -ENOMEM; 194 + 195 + ret = devm_mutex_init(dev, &gpio->config_mutex); 196 + if (ret) 197 + return ret; 198 + 199 + gpio->adev = adev; 200 + 201 + usbio_acpi_bind(gpio->adev, usbio_gpio_acpi_hids); 202 + 203 + for (bank = 0; bank < USBIO_MAX_GPIOBANKS && bank_desc[bank].bmap; bank++) 204 + gpio->banks[bank].bitmap = le32_to_cpu(bank_desc[bank].bmap); 205 + 206 + gpio->gc.label = ACPI_COMPANION(dev) ? 207 + acpi_dev_name(ACPI_COMPANION(dev)) : dev_name(dev); 208 + gpio->gc.parent = dev; 209 + gpio->gc.owner = THIS_MODULE; 210 + gpio->gc.get_direction = usbio_gpio_get_direction; 211 + gpio->gc.direction_input = usbio_gpio_direction_input; 212 + gpio->gc.direction_output = usbio_gpio_direction_output; 213 + gpio->gc.get = usbio_gpio_get; 214 + gpio->gc.set = usbio_gpio_set; 215 + gpio->gc.set_config = usbio_gpio_set_config; 216 + gpio->gc.base = -1; 217 + gpio->gc.ngpio = bank * USBIO_GPIOSPERBANK; 218 + gpio->gc.can_sleep = true; 219 + 220 + ret = devm_gpiochip_add_data(dev, &gpio->gc, gpio); 221 + if (ret) 222 + return ret; 223 + 224 + if (has_acpi_companion(dev)) 225 + acpi_dev_clear_dependencies(ACPI_COMPANION(dev)); 226 + 227 + return 0; 228 + } 229 + 230 + static const struct auxiliary_device_id usbio_gpio_id_table[] = { 231 + { "usbio.usbio-gpio" }, 232 + { } 233 + }; 234 + MODULE_DEVICE_TABLE(auxiliary, usbio_gpio_id_table); 235 + 236 + static struct auxiliary_driver usbio_gpio_driver = { 237 + .name = USBIO_GPIO_CLIENT, 238 + .probe = usbio_gpio_probe, 239 + .id_table = usbio_gpio_id_table 240 + }; 241 + module_auxiliary_driver(usbio_gpio_driver); 242 + 243 + MODULE_DESCRIPTION("Intel USBIO GPIO driver"); 244 + MODULE_AUTHOR("Israel Cepeda <israel.a.cepeda.lopez@intel.com>"); 245 + MODULE_AUTHOR("Hans de Goede <hansg@kernel.org>"); 246 + MODULE_LICENSE("GPL"); 247 + MODULE_IMPORT_NS("USBIO");
+11
drivers/i2c/busses/Kconfig
··· 1368 1368 This driver can also be built as a module. If so, the module will 1369 1369 be called i2c-nct6694. 1370 1370 1371 + config I2C_USBIO 1372 + tristate "Intel USBIO I2C Adapter support" 1373 + depends on USB_USBIO 1374 + default USB_USBIO 1375 + help 1376 + Select this option to enable I2C driver for the INTEL 1377 + USBIO driver stack. 1378 + 1379 + This driver can also be built as a module. If so, the module 1380 + will be called i2c_usbio. 1381 + 1371 1382 config I2C_CP2615 1372 1383 tristate "Silicon Labs CP2615 USB sound card and I2C adapter" 1373 1384 depends on USB
+1
drivers/i2c/busses/Makefile
··· 136 136 obj-$(CONFIG_I2C_DLN2) += i2c-dln2.o 137 137 obj-$(CONFIG_I2C_LJCA) += i2c-ljca.o 138 138 obj-$(CONFIG_I2C_NCT6694) += i2c-nct6694.o 139 + obj-$(CONFIG_I2C_USBIO) += i2c-usbio.o 139 140 obj-$(CONFIG_I2C_CP2615) += i2c-cp2615.o 140 141 obj-$(CONFIG_I2C_PARPORT) += i2c-parport.o 141 142 obj-$(CONFIG_I2C_PCI1XXXX) += i2c-mchp-pci1xxxx.o
+320
drivers/i2c/busses/i2c-usbio.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * Copyright (c) 2025 Intel Corporation. 4 + * Copyright (c) 2025 Red Hat, Inc. 5 + */ 6 + 7 + #include <linux/auxiliary_bus.h> 8 + #include <linux/dev_printk.h> 9 + #include <linux/device.h> 10 + #include <linux/i2c.h> 11 + #include <linux/types.h> 12 + #include <linux/usb/usbio.h> 13 + 14 + #define I2C_RW_OVERHEAD (sizeof(struct usbio_bulk_packet) + sizeof(struct usbio_i2c_rw)) 15 + 16 + struct usbio_i2c { 17 + struct i2c_adapter adap; 18 + struct auxiliary_device *adev; 19 + struct usbio_i2c_rw *rwbuf; 20 + unsigned long quirks; 21 + u32 speed; 22 + u16 txbuf_len; 23 + u16 rxbuf_len; 24 + }; 25 + 26 + static const struct acpi_device_id usbio_i2c_acpi_hids[] = { 27 + { "INTC1008" }, /* MTL */ 28 + { "INTC10B3" }, /* ARL */ 29 + { "INTC10B6" }, /* LNL */ 30 + { "INTC10E3" }, /* PTL */ 31 + { } 32 + }; 33 + 34 + static const u32 usbio_i2c_speeds[] = { 35 + I2C_MAX_STANDARD_MODE_FREQ, 36 + I2C_MAX_FAST_MODE_FREQ, 37 + I2C_MAX_FAST_MODE_PLUS_FREQ, 38 + I2C_MAX_HIGH_SPEED_MODE_FREQ 39 + }; 40 + 41 + static void usbio_i2c_uninit(struct i2c_adapter *adap, struct i2c_msg *msg) 42 + { 43 + struct usbio_i2c *i2c = i2c_get_adapdata(adap); 44 + struct usbio_i2c_uninit ubuf; 45 + 46 + ubuf.busid = i2c->adev->id; 47 + ubuf.config = cpu_to_le16(msg->addr); 48 + 49 + usbio_bulk_msg(i2c->adev, USBIO_PKTTYPE_I2C, USBIO_I2CCMD_UNINIT, true, 50 + &ubuf, sizeof(ubuf), NULL, 0); 51 + } 52 + 53 + static int usbio_i2c_init(struct i2c_adapter *adap, struct i2c_msg *msg) 54 + { 55 + struct usbio_i2c *i2c = i2c_get_adapdata(adap); 56 + struct usbio_i2c_init ibuf; 57 + void *reply_buf; 58 + u16 reply_len; 59 + int ret; 60 + 61 + ibuf.busid = i2c->adev->id; 62 + ibuf.config = cpu_to_le16(msg->addr); 63 + ibuf.speed = cpu_to_le32(i2c->speed); 64 + 65 + if (i2c->quirks & USBIO_QUIRK_I2C_NO_INIT_ACK) { 66 + reply_buf = NULL; 67 + reply_len = 0; 68 + } else { 69 + reply_buf = &ibuf; 70 + reply_len = sizeof(ibuf); 71 + } 72 + 73 + ret = usbio_bulk_msg(i2c->adev, USBIO_PKTTYPE_I2C, USBIO_I2CCMD_INIT, true, 74 + &ibuf, sizeof(ibuf), reply_buf, reply_len); 75 + if (ret != sizeof(ibuf)) 76 + return (ret < 0) ? ret : -EIO; 77 + 78 + return 0; 79 + } 80 + 81 + static int usbio_i2c_read(struct i2c_adapter *adap, struct i2c_msg *msg) 82 + { 83 + struct usbio_i2c *i2c = i2c_get_adapdata(adap); 84 + u16 rxchunk = i2c->rxbuf_len - I2C_RW_OVERHEAD; 85 + struct usbio_i2c_rw *rbuf = i2c->rwbuf; 86 + int ret; 87 + 88 + rbuf->busid = i2c->adev->id; 89 + rbuf->config = cpu_to_le16(msg->addr); 90 + rbuf->size = cpu_to_le16(msg->len); 91 + 92 + if (msg->len > rxchunk) { 93 + /* Need to split the input buffer */ 94 + u16 len = 0; 95 + 96 + do { 97 + if (msg->len - len < rxchunk) 98 + rxchunk = msg->len - len; 99 + 100 + ret = usbio_bulk_msg(i2c->adev, USBIO_PKTTYPE_I2C, 101 + USBIO_I2CCMD_READ, true, 102 + rbuf, len == 0 ? sizeof(*rbuf) : 0, 103 + rbuf, sizeof(*rbuf) + rxchunk); 104 + if (ret < 0) 105 + return ret; 106 + 107 + memcpy(&msg->buf[len], rbuf->data, rxchunk); 108 + len += rxchunk; 109 + } while (msg->len > len); 110 + 111 + return 0; 112 + } 113 + 114 + ret = usbio_bulk_msg(i2c->adev, USBIO_PKTTYPE_I2C, USBIO_I2CCMD_READ, true, 115 + rbuf, sizeof(*rbuf), rbuf, sizeof(*rbuf) + msg->len); 116 + if (ret != sizeof(*rbuf) + msg->len) 117 + return (ret < 0) ? ret : -EIO; 118 + 119 + memcpy(msg->buf, rbuf->data, msg->len); 120 + 121 + return 0; 122 + } 123 + 124 + static int usbio_i2c_write(struct i2c_adapter *adap, struct i2c_msg *msg) 125 + { 126 + struct usbio_i2c *i2c = i2c_get_adapdata(adap); 127 + u16 txchunk = i2c->txbuf_len - I2C_RW_OVERHEAD; 128 + struct usbio_i2c_rw *wbuf = i2c->rwbuf; 129 + int ret; 130 + 131 + if (msg->len > txchunk) { 132 + /* Need to split the output buffer */ 133 + u16 len = 0; 134 + 135 + do { 136 + wbuf->busid = i2c->adev->id; 137 + wbuf->config = cpu_to_le16(msg->addr); 138 + 139 + if (i2c->quirks & USBIO_QUIRK_I2C_USE_CHUNK_LEN) 140 + wbuf->size = cpu_to_le16(txchunk); 141 + else 142 + wbuf->size = cpu_to_le16(msg->len); 143 + 144 + memcpy(wbuf->data, &msg->buf[len], txchunk); 145 + len += txchunk; 146 + 147 + ret = usbio_bulk_msg(i2c->adev, USBIO_PKTTYPE_I2C, 148 + USBIO_I2CCMD_WRITE, msg->len == len, 149 + wbuf, sizeof(*wbuf) + txchunk, 150 + wbuf, sizeof(*wbuf)); 151 + if (ret < 0) 152 + return ret; 153 + 154 + if (msg->len - len < txchunk) 155 + txchunk = msg->len - len; 156 + } while (msg->len > len); 157 + 158 + return 0; 159 + } 160 + 161 + wbuf->busid = i2c->adev->id; 162 + wbuf->config = cpu_to_le16(msg->addr); 163 + wbuf->size = cpu_to_le16(msg->len); 164 + memcpy(wbuf->data, msg->buf, msg->len); 165 + 166 + ret = usbio_bulk_msg(i2c->adev, USBIO_PKTTYPE_I2C, USBIO_I2CCMD_WRITE, true, 167 + wbuf, sizeof(*wbuf) + msg->len, wbuf, sizeof(*wbuf)); 168 + if (ret != sizeof(*wbuf) || le16_to_cpu(wbuf->size) != msg->len) 169 + return (ret < 0) ? ret : -EIO; 170 + 171 + return 0; 172 + } 173 + 174 + static int usbio_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num) 175 + { 176 + struct usbio_i2c *i2c = i2c_get_adapdata(adap); 177 + int ret; 178 + 179 + usbio_acquire(i2c->adev); 180 + 181 + ret = usbio_i2c_init(adap, msgs); 182 + if (ret) 183 + goto out_release; 184 + 185 + for (int i = 0; i < num; ret = ++i) { 186 + if (msgs[i].flags & I2C_M_RD) 187 + ret = usbio_i2c_read(adap, &msgs[i]); 188 + else 189 + ret = usbio_i2c_write(adap, &msgs[i]); 190 + 191 + if (ret) 192 + break; 193 + } 194 + 195 + usbio_i2c_uninit(adap, msgs); 196 + 197 + out_release: 198 + usbio_release(i2c->adev); 199 + 200 + return ret; 201 + } 202 + 203 + static u32 usbio_i2c_func(struct i2c_adapter *adap) 204 + { 205 + return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; 206 + } 207 + 208 + static const struct i2c_adapter_quirks usbio_i2c_quirks = { 209 + .flags = I2C_AQ_NO_ZERO_LEN | I2C_AQ_NO_REP_START, 210 + .max_read_len = SZ_4K, 211 + .max_write_len = SZ_4K, 212 + }; 213 + 214 + static const struct i2c_adapter_quirks usbio_i2c_quirks_max_rw_len52 = { 215 + .flags = I2C_AQ_NO_ZERO_LEN | I2C_AQ_NO_REP_START, 216 + .max_read_len = 52, 217 + .max_write_len = 52, 218 + }; 219 + 220 + static const struct i2c_algorithm usbio_i2c_algo = { 221 + .master_xfer = usbio_i2c_xfer, 222 + .functionality = usbio_i2c_func, 223 + }; 224 + 225 + static int usbio_i2c_probe(struct auxiliary_device *adev, 226 + const struct auxiliary_device_id *adev_id) 227 + { 228 + struct usbio_i2c_bus_desc *i2c_desc; 229 + struct device *dev = &adev->dev; 230 + struct usbio_i2c *i2c; 231 + u32 max_speed; 232 + int ret; 233 + 234 + i2c_desc = dev_get_platdata(dev); 235 + if (!i2c_desc) 236 + return -EINVAL; 237 + 238 + i2c = devm_kzalloc(dev, sizeof(*i2c), GFP_KERNEL); 239 + if (!i2c) 240 + return -ENOMEM; 241 + 242 + i2c->adev = adev; 243 + 244 + usbio_acpi_bind(i2c->adev, usbio_i2c_acpi_hids); 245 + usbio_get_txrxbuf_len(i2c->adev, &i2c->txbuf_len, &i2c->rxbuf_len); 246 + 247 + i2c->rwbuf = devm_kzalloc(dev, max(i2c->txbuf_len, i2c->rxbuf_len), GFP_KERNEL); 248 + if (!i2c->rwbuf) 249 + return -ENOMEM; 250 + 251 + i2c->quirks = usbio_get_quirks(i2c->adev); 252 + 253 + max_speed = usbio_i2c_speeds[i2c_desc->caps & USBIO_I2C_BUS_MODE_CAP_MASK]; 254 + if (max_speed < I2C_MAX_FAST_MODE_FREQ && 255 + (i2c->quirks & USBIO_QUIRK_I2C_ALLOW_400KHZ)) 256 + max_speed = I2C_MAX_FAST_MODE_FREQ; 257 + 258 + i2c->speed = i2c_acpi_find_bus_speed(dev); 259 + if (!i2c->speed) 260 + i2c->speed = I2C_MAX_STANDARD_MODE_FREQ; 261 + else if (i2c->speed > max_speed) { 262 + dev_warn(dev, "Invalid speed %u adjusting to bus max %u\n", 263 + i2c->speed, max_speed); 264 + i2c->speed = max_speed; 265 + } 266 + 267 + i2c->adap.owner = THIS_MODULE; 268 + i2c->adap.class = I2C_CLASS_HWMON; 269 + i2c->adap.dev.parent = dev; 270 + i2c->adap.algo = &usbio_i2c_algo; 271 + 272 + if (i2c->quirks & USBIO_QUIRK_I2C_MAX_RW_LEN_52) 273 + i2c->adap.quirks = &usbio_i2c_quirks_max_rw_len52; 274 + else 275 + i2c->adap.quirks = &usbio_i2c_quirks; 276 + 277 + snprintf(i2c->adap.name, sizeof(i2c->adap.name), "%s.%d", 278 + USBIO_I2C_CLIENT, i2c->adev->id); 279 + 280 + device_set_node(&i2c->adap.dev, dev_fwnode(&adev->dev)); 281 + 282 + auxiliary_set_drvdata(adev, i2c); 283 + i2c_set_adapdata(&i2c->adap, i2c); 284 + 285 + ret = i2c_add_adapter(&i2c->adap); 286 + if (ret) 287 + return ret; 288 + 289 + if (has_acpi_companion(&i2c->adap.dev)) 290 + acpi_dev_clear_dependencies(ACPI_COMPANION(&i2c->adap.dev)); 291 + 292 + return 0; 293 + } 294 + 295 + static void usbio_i2c_remove(struct auxiliary_device *adev) 296 + { 297 + struct usbio_i2c *i2c = auxiliary_get_drvdata(adev); 298 + 299 + i2c_del_adapter(&i2c->adap); 300 + } 301 + 302 + static const struct auxiliary_device_id usbio_i2c_id_table[] = { 303 + { "usbio.usbio-i2c" }, 304 + { } 305 + }; 306 + MODULE_DEVICE_TABLE(auxiliary, usbio_i2c_id_table); 307 + 308 + static struct auxiliary_driver usbio_i2c_driver = { 309 + .name = USBIO_I2C_CLIENT, 310 + .probe = usbio_i2c_probe, 311 + .remove = usbio_i2c_remove, 312 + .id_table = usbio_i2c_id_table 313 + }; 314 + module_auxiliary_driver(usbio_i2c_driver); 315 + 316 + MODULE_DESCRIPTION("Intel USBIO I2C driver"); 317 + MODULE_AUTHOR("Israel Cepeda <israel.a.cepeda.lopez@intel.com>"); 318 + MODULE_AUTHOR("Hans de Goede <hansg@kernel.org>"); 319 + MODULE_LICENSE("GPL"); 320 + MODULE_IMPORT_NS("USBIO");
+2 -2
drivers/media/usb/uvc/uvc_driver.c
··· 538 538 unsigned int nformats = 0, nframes = 0, nintervals = 0; 539 539 unsigned int size, i, n, p; 540 540 u32 *interval; 541 - u16 psize; 541 + u32 psize; 542 542 int ret = -EINVAL; 543 543 544 544 if (intf->cur_altsetting->desc.bInterfaceSubClass ··· 774 774 streaming->header.bEndpointAddress); 775 775 if (ep == NULL) 776 776 continue; 777 - psize = uvc_endpoint_max_bpi(dev->udev, ep); 777 + psize = usb_endpoint_max_periodic_payload(dev->udev, ep); 778 778 if (psize > streaming->maxpsize) 779 779 streaming->maxpsize = psize; 780 780 }
+3 -21
drivers/media/usb/uvc/uvc_video.c
··· 1870 1870 } 1871 1871 1872 1872 /* 1873 - * Compute the maximum number of bytes per interval for an endpoint. 1874 - */ 1875 - u16 uvc_endpoint_max_bpi(struct usb_device *dev, struct usb_host_endpoint *ep) 1876 - { 1877 - u16 psize; 1878 - 1879 - switch (dev->speed) { 1880 - case USB_SPEED_SUPER: 1881 - case USB_SPEED_SUPER_PLUS: 1882 - return le16_to_cpu(ep->ss_ep_comp.wBytesPerInterval); 1883 - default: 1884 - psize = usb_endpoint_maxp(&ep->desc); 1885 - psize *= usb_endpoint_maxp_mult(&ep->desc); 1886 - return psize; 1887 - } 1888 - } 1889 - 1890 - /* 1891 1873 * Initialize isochronous URBs and allocate transfer buffers. The packet size 1892 1874 * is given by the endpoint. 1893 1875 */ ··· 1879 1897 struct urb *urb; 1880 1898 struct uvc_urb *uvc_urb; 1881 1899 unsigned int npackets, i; 1882 - u16 psize; 1900 + u32 psize; 1883 1901 u32 size; 1884 1902 1885 - psize = uvc_endpoint_max_bpi(stream->dev->udev, ep); 1903 + psize = usb_endpoint_max_periodic_payload(stream->dev->udev, ep); 1886 1904 size = stream->ctrl.dwMaxVideoFrameSize; 1887 1905 1888 1906 npackets = uvc_alloc_urb_buffers(stream, size, psize, gfp_flags); ··· 2025 2043 continue; 2026 2044 2027 2045 /* Check if the bandwidth is high enough. */ 2028 - psize = uvc_endpoint_max_bpi(stream->dev->udev, ep); 2046 + psize = usb_endpoint_max_periodic_payload(stream->dev->udev, ep); 2029 2047 if (psize >= bandwidth && psize < best_psize) { 2030 2048 altsetting = alts->desc.bAlternateSetting; 2031 2049 best_psize = psize;
+1 -3
drivers/media/usb/uvc/uvcvideo.h
··· 458 458 459 459 struct usb_interface *intf; 460 460 int intfnum; 461 - u16 maxpsize; 461 + u32 maxpsize; 462 462 463 463 struct uvc_streaming_header header; 464 464 enum v4l2_buf_type type; ··· 797 797 /* Utility functions */ 798 798 struct usb_host_endpoint *uvc_find_endpoint(struct usb_host_interface *alts, 799 799 u8 epaddr); 800 - u16 uvc_endpoint_max_bpi(struct usb_device *dev, struct usb_host_endpoint *ep); 801 - 802 800 /* Quirks support */ 803 801 void uvc_video_decode_isight(struct uvc_urb *uvc_urb, 804 802 struct uvc_buffer *buf,
+1 -1
drivers/pci/quirks.c
··· 3829 3829 */ 3830 3830 static void quirk_thunderbolt_hotplug_msi(struct pci_dev *pdev) 3831 3831 { 3832 - if (pdev->is_hotplug_bridge && 3832 + if (pdev->is_pciehp && 3833 3833 (pdev->device != PCI_DEVICE_ID_INTEL_CACTUS_RIDGE_4C || 3834 3834 pdev->revision <= 1)) 3835 3835 pdev->no_msi = 1;
+2 -2
drivers/thunderbolt/Kconfig
··· 4 4 depends on PCI 5 5 select APPLE_PROPERTIES if EFI_STUB && X86 6 6 select CRC32 7 - select CRYPTO 8 - select CRYPTO_HASH 7 + select CRYPTO_LIB_SHA256 8 + select CRYPTO_LIB_UTILS 9 9 select NVMEM 10 10 help 11 11 USB4 and Thunderbolt driver. USB4 is the public specification
+15 -13
drivers/thunderbolt/acpi.c
··· 86 86 * @nhi ACPI node. For each reference a device link is added. The link 87 87 * is automatically removed by the driver core. 88 88 * 89 - * Returns %true if at least one link was created. 89 + * Returns %true if at least one link was created, %false otherwise. 90 90 */ 91 91 bool tb_acpi_add_links(struct tb_nhi *nhi) 92 92 { ··· 113 113 /** 114 114 * tb_acpi_is_native() - Did the platform grant native TBT/USB4 control 115 115 * 116 - * Returns %true if the platform granted OS native control over 117 - * TBT/USB4. In this case software based connection manager can be used, 116 + * Return: %true if the platform granted OS native control over 117 + * TBT/USB4, %false otherwise. 118 + * 119 + * When returned %true, software based connection manager can be used, 118 120 * otherwise there is firmware based connection manager running. 119 121 */ 120 122 bool tb_acpi_is_native(void) ··· 128 126 /** 129 127 * tb_acpi_may_tunnel_usb3() - Is USB3 tunneling allowed by the platform 130 128 * 131 - * When software based connection manager is used, this function 132 - * returns %true if platform allows native USB3 tunneling. 129 + * Return: %true if software based connection manager is used and 130 + * platform allows native USB 3.x tunneling, %false otherwise. 133 131 */ 134 132 bool tb_acpi_may_tunnel_usb3(void) 135 133 { ··· 141 139 /** 142 140 * tb_acpi_may_tunnel_dp() - Is DisplayPort tunneling allowed by the platform 143 141 * 144 - * When software based connection manager is used, this function 145 - * returns %true if platform allows native DP tunneling. 142 + * Return: %true if software based connection manager is used and 143 + * platform allows native DP tunneling, %false otherwise. 146 144 */ 147 145 bool tb_acpi_may_tunnel_dp(void) 148 146 { ··· 154 152 /** 155 153 * tb_acpi_may_tunnel_pcie() - Is PCIe tunneling allowed by the platform 156 154 * 157 - * When software based connection manager is used, this function 158 - * returns %true if platform allows native PCIe tunneling. 155 + * Return: %true if software based connection manager is used and 156 + * platform allows native PCIe tunneling, %false otherwise. 159 157 */ 160 158 bool tb_acpi_may_tunnel_pcie(void) 161 159 { ··· 167 165 /** 168 166 * tb_acpi_is_xdomain_allowed() - Are XDomain connections allowed 169 167 * 170 - * When software based connection manager is used, this function 171 - * returns %true if platform allows XDomain connections. 168 + * Return: %true if software based connection manager is used and 169 + * platform allows XDomain tunneling, %false otherwise. 172 170 */ 173 171 bool tb_acpi_is_xdomain_allowed(void) 174 172 { ··· 258 256 * 259 257 * This should only be called if the USB4/TBT link is not up. 260 258 * 261 - * Returns %0 on success. 259 + * Return: %0 on success, negative errno otherwise. 262 260 */ 263 261 int tb_acpi_power_on_retimers(struct tb_port *port) 264 262 { ··· 272 270 * This is the opposite of tb_acpi_power_on_retimers(). After returning 273 271 * successfully the normal operations with the @port can continue. 274 272 * 275 - * Returns %0 on success. 273 + * Return: %0 on success, negative errno otherwise. 276 274 */ 277 275 int tb_acpi_power_off_retimers(struct tb_port *port) 278 276 {
+31 -18
drivers/thunderbolt/cap.c
··· 64 64 * @port: Port to find the capability for 65 65 * @offset: Previous capability offset (%0 for start) 66 66 * 67 - * Returns dword offset of the next capability in port config space 68 - * capability list and returns it. Passing %0 returns the first entry in 69 - * the capability list. If no next capability is found returns %0. In case 70 - * of failure returns negative errno. 67 + * Finds dword offset of the next capability in port config space 68 + * capability list. When passed %0 in @offset parameter, first entry 69 + * will be returned, if it exists. 70 + * 71 + * Return: 72 + * * Double word offset of the first or next capability - On success. 73 + * * %0 - If no next capability is found. 74 + * * Negative errno - Another error occurred. 71 75 */ 72 76 int tb_port_next_cap(struct tb_port *port, unsigned int offset) 73 77 { ··· 116 112 * @port: Port to find the capability for 117 113 * @cap: Capability to look 118 114 * 119 - * Returns offset to start of capability or %-ENOENT if no such 120 - * capability was found. Negative errno is returned if there was an 121 - * error. 115 + * Return: 116 + * * Offset to the start of capability - On success. 117 + * * %-ENOENT - If no such capability was found. 118 + * * Negative errno - Another error occurred. 122 119 */ 123 120 int tb_port_find_cap(struct tb_port *port, enum tb_port_cap cap) 124 121 { ··· 142 137 * @sw: Switch to find the capability for 143 138 * @offset: Previous capability offset (%0 for start) 144 139 * 145 - * Finds dword offset of the next capability in router config space 146 - * capability list and returns it. Passing %0 returns the first entry in 147 - * the capability list. If no next capability is found returns %0. In case 148 - * of failure returns negative errno. 140 + * Finds dword offset of the next capability in port config space 141 + * capability list. When passed %0 in @offset parameter, first entry 142 + * will be returned, if it exists. 143 + * 144 + * Return: 145 + * * Double word offset of the first or next capability - On success. 146 + * * %0 - If no next capability is found. 147 + * * Negative errno - Another error occurred. 149 148 */ 150 149 int tb_switch_next_cap(struct tb_switch *sw, unsigned int offset) 151 150 { ··· 190 181 * @sw: Switch to find the capability for 191 182 * @cap: Capability to look 192 183 * 193 - * Returns offset to start of capability or %-ENOENT if no such 194 - * capability was found. Negative errno is returned if there was an 195 - * error. 184 + * Return: 185 + * * Offset to the start of capability - On success. 186 + * * %-ENOENT - If no such capability was found. 187 + * * Negative errno - Another error occurred. 196 188 */ 197 189 int tb_switch_find_cap(struct tb_switch *sw, enum tb_switch_cap cap) 198 190 { ··· 223 213 * @sw: Switch to find the capability for 224 214 * @vsec: Vendor specific capability to look 225 215 * 226 - * Functions enumerates vendor specific capabilities (VSEC) of a switch 227 - * and returns offset when capability matching @vsec is found. If no 228 - * such capability is found returns %-ENOENT. In case of error returns 229 - * negative errno. 216 + * This function enumerates vendor specific capabilities (VSEC) of a 217 + * switch and returns offset when capability matching @vsec is found. 218 + * 219 + * Return: 220 + * * Offset of capability - On success. 221 + * * %-ENOENT - If capability was not found. 222 + * * Negative errno - Another error occurred. 230 223 */ 231 224 int tb_switch_find_vse_cap(struct tb_switch *sw, enum tb_switch_vse_cap vsec) 232 225 {
+7 -5
drivers/thunderbolt/clx.c
··· 167 167 * @port: USB4 port to check 168 168 * @clx: Mask of CL states to check 169 169 * 170 - * Returns true if any of the given CL states is enabled for @port. 170 + * Return: %true if any of the given CL states is enabled for @port, 171 + * %false otherwise. 171 172 */ 172 173 bool tb_port_clx_is_enabled(struct tb_port *port, unsigned int clx) 173 174 { ··· 178 177 /** 179 178 * tb_switch_clx_is_supported() - Is CLx supported on this type of router 180 179 * @sw: The router to check CLx support for 180 + * 181 + * Return: %true if CLx is supported, %false otherwise. 181 182 */ 182 183 static bool tb_switch_clx_is_supported(const struct tb_switch *sw) 183 184 { ··· 206 203 * Can be called for any router. Initializes the current CL state by 207 204 * reading it from the hardware. 208 205 * 209 - * Returns %0 in case of success and negative errno in case of failure. 206 + * Return: %0 on success, negative errno otherwise. 210 207 */ 211 208 int tb_switch_clx_init(struct tb_switch *sw) 212 209 { ··· 316 313 * is not inter-domain link. The complete set of conditions is described in CM 317 314 * Guide 1.0 section 8.1. 318 315 * 319 - * Returns %0 on success or an error code on failure. 316 + * Return: %0 on success, negative errno otherwise. 320 317 */ 321 318 int tb_switch_clx_enable(struct tb_switch *sw, unsigned int clx) 322 319 { ··· 393 390 * Disables all CL states of the given router. Can be called on any 394 391 * router and if the states were not enabled already does nothing. 395 392 * 396 - * Returns the CL states that were disabled or negative errno in case of 397 - * failure. 393 + * Return: CL states that were disabled or negative errno otherwise. 398 394 */ 399 395 int tb_switch_clx_disable(struct tb_switch *sw) 400 396 {
+25 -8
drivers/thunderbolt/ctl.c
··· 82 82 * 83 83 * This is refcounted object so when you are done with this, call 84 84 * tb_cfg_request_put() to it. 85 + * 86 + * Return: &struct tb_cfg_request on success, %NULL otherwise. 85 87 */ 86 88 struct tb_cfg_request *tb_cfg_request_alloc(void) 87 89 { ··· 361 359 * 362 360 * len must be a multiple of four. 363 361 * 364 - * Return: Returns 0 on success or an error code on failure. 362 + * Return: %0 on success, negative errno otherwise. 365 363 */ 366 364 static int tb_ctl_tx(struct tb_ctl *ctl, const void *data, size_t len, 367 365 enum tb_cfg_pkg_type type) ··· 541 539 * 542 540 * This queues @req on the given control channel without waiting for it 543 541 * to complete. When the request completes @callback is called. 542 + * 543 + * Return: %0 on success, negative errno otherwise. 544 544 */ 545 545 int tb_cfg_request(struct tb_ctl *ctl, struct tb_cfg_request *req, 546 546 void (*callback)(void *), void *callback_data) ··· 609 605 * triggers the request is canceled before function returns. Note the 610 606 * caller needs to make sure only one message for given switch is active 611 607 * at a time. 608 + * 609 + * Return: &struct tb_cfg_result with non-zero @err field if error 610 + * has occurred. 612 611 */ 613 612 struct tb_cfg_result tb_cfg_request_sync(struct tb_ctl *ctl, 614 613 struct tb_cfg_request *req, ··· 648 641 * 649 642 * cb will be invoked once for every hot plug event. 650 643 * 651 - * Return: Returns a pointer on success or NULL on failure. 644 + * Return: Pointer to &struct tb_ctl, %NULL on failure. 652 645 */ 653 646 struct tb_ctl *tb_ctl_alloc(struct tb_nhi *nhi, int index, int timeout_msec, 654 647 event_cb cb, void *cb_data) ··· 771 764 * @route: Router that originated the event 772 765 * @error: Pointer to the notification package 773 766 * 774 - * Call this as response for non-plug notification to ack it. Returns 775 - * %0 on success or an error code on failure. 767 + * Call this as a response for non-plug notification to ack it. 768 + * 769 + * Return: %0 on success, negative errno otherwise. 776 770 */ 777 771 int tb_cfg_ack_notification(struct tb_ctl *ctl, u64 route, 778 772 const struct cfg_error_pkg *error) ··· 835 827 * @port: Port where the hot plug/unplug happened 836 828 * @unplug: Ack hot plug or unplug 837 829 * 838 - * Call this as response for hot plug/unplug event to ack it. 839 - * Returns %0 on success or an error code on failure. 830 + * Call this as a response for hot plug/unplug event to ack it. 831 + * 832 + * Return: %0 on success, negative errno otherwise. 840 833 */ 841 834 int tb_cfg_ack_plug(struct tb_ctl *ctl, u64 route, u32 port, bool unplug) 842 835 { ··· 904 895 * If the switch at route is incorrectly configured then we will not receive a 905 896 * reply (even though the switch will reset). The caller should check for 906 897 * -ETIMEDOUT and attempt to reconfigure the switch. 898 + * 899 + * Return: &struct tb_cfg_result with non-zero @err field if error 900 + * has occurred. 907 901 */ 908 902 struct tb_cfg_result tb_cfg_reset(struct tb_ctl *ctl, u64 route) 909 903 { ··· 949 937 * @timeout_msec: Timeout in ms how long to wait for the response 950 938 * 951 939 * Reads from router config space without translating the possible error. 940 + * 941 + * Return: &struct tb_cfg_result with non-zero @err field if error 942 + * has occurred. 952 943 */ 953 944 struct tb_cfg_result tb_cfg_read_raw(struct tb_ctl *ctl, void *buffer, 954 945 u64 route, u32 port, enum tb_cfg_space space, ··· 1023 1008 * @timeout_msec: Timeout in ms how long to wait for the response 1024 1009 * 1025 1010 * Writes to router config space without translating the possible error. 1011 + * 1012 + * Return: &struct tb_cfg_result with non-zero @err field if error 1013 + * has occurred. 1026 1014 */ 1027 1015 struct tb_cfg_result tb_cfg_write_raw(struct tb_ctl *ctl, const void *buffer, 1028 1016 u64 route, u32 port, enum tb_cfg_space space, ··· 1168 1150 * Reads the first dword from the switches TB_CFG_SWITCH config area and 1169 1151 * returns the port number from which the reply originated. 1170 1152 * 1171 - * Return: Returns the upstream port number on success or an error code on 1172 - * failure. 1153 + * Return: Upstream port number on success or negative error code on failure. 1173 1154 */ 1174 1155 int tb_cfg_get_upstream_port(struct tb_ctl *ctl, u64 route) 1175 1156 {
+1
drivers/thunderbolt/ctl.h
··· 54 54 * @kref: Reference count 55 55 * @ctl: Pointer to the control channel structure. Only set when the 56 56 * request is queued. 57 + * @request: Request is stored here 57 58 * @request_size: Size of the request packet (in bytes) 58 59 * @request_type: Type of the request packet 59 60 * @response: Response is stored here
+2 -1
drivers/thunderbolt/debugfs.c
··· 12 12 #include <linux/debugfs.h> 13 13 #include <linux/delay.h> 14 14 #include <linux/pm_runtime.h> 15 + #include <linux/string_choices.h> 15 16 #include <linux/uaccess.h> 16 17 17 18 #include "tb.h" ··· 692 691 seq_printf(s, "0x%08x\n", margining->caps[i]); 693 692 694 693 seq_printf(s, "# software margining: %s\n", 695 - supports_software(margining) ? "yes" : "no"); 694 + str_yes_no(supports_software(margining))); 696 695 if (supports_hardware(margining)) { 697 696 seq_puts(s, "# hardware margining: yes\n"); 698 697 seq_puts(s, "# minimum BER level contour: ");
+16 -5
drivers/thunderbolt/dma_port.c
··· 197 197 * 198 198 * The DMA control port is functional also when the switch is in safe 199 199 * mode. 200 + * 201 + * Return: &struct tb_dma_port on success, %NULL otherwise. 200 202 */ 201 203 struct tb_dma_port *dma_port_alloc(struct tb_switch *sw) 202 204 { ··· 356 354 * @address: Address relative to the start of active region 357 355 * @buf: Buffer where the data is read 358 356 * @size: Size of the buffer 357 + * 358 + * Return: %0 on success, negative errno otherwise. 359 359 */ 360 360 int dma_port_flash_read(struct tb_dma_port *dma, unsigned int address, 361 361 void *buf, size_t size) ··· 376 372 * Writes block of data to the non-active flash region of the switch. If 377 373 * the address is given as %DMA_PORT_CSS_ADDRESS the block is written 378 374 * using CSS command. 375 + * 376 + * Return: %0 on success, negative errno otherwise. 379 377 */ 380 378 int dma_port_flash_write(struct tb_dma_port *dma, unsigned int address, 381 379 const void *buf, size_t size) ··· 399 393 * dma_port_flash_update_auth_status() to get status of this command. 400 394 * This is because if the switch in question is root switch the 401 395 * thunderbolt host controller gets reset as well. 396 + * 397 + * Return: %0 on success, negative errno otherwise. 402 398 */ 403 399 int dma_port_flash_update_auth(struct tb_dma_port *dma) 404 400 { ··· 418 410 * @status: Status code of the operation 419 411 * 420 412 * The function checks if there is status available from the last update 421 - * auth command. Returns %0 if there is no status and no further 422 - * action is required. If there is status, %1 is returned instead and 423 - * @status holds the failure code. 413 + * auth command. 424 414 * 425 - * Negative return means there was an error reading status from the 426 - * switch. 415 + * Return: 416 + * * %0 - If there is no status and no further action is required. 417 + * * %1 - If there is some status. @status holds the failure code. 418 + * * Negative errno - An error occurred when reading status from the 419 + * switch. 427 420 */ 428 421 int dma_port_flash_update_auth_status(struct tb_dma_port *dma, u32 *status) 429 422 { ··· 455 446 * @dma: DMA control port 456 447 * 457 448 * Triggers power cycle to the switch. 449 + * 450 + * Return: %0 on success, negative errno otherwise. 458 451 */ 459 452 int dma_port_power_cycle(struct tb_dma_port *dma) 460 453 {
+26 -47
drivers/thunderbolt/domain.c
··· 12 12 #include <linux/pm_runtime.h> 13 13 #include <linux/slab.h> 14 14 #include <linux/random.h> 15 - #include <crypto/hash.h> 15 + #include <crypto/sha2.h> 16 + #include <crypto/utils.h> 16 17 17 18 #include "tb.h" 18 19 ··· 369 368 * Call tb_domain_put() to release the domain before it has been added 370 369 * to the system. 371 370 * 372 - * Return: allocated domain structure on %NULL in case of error 371 + * Return: Pointer to &struct tb or %NULL in case of error. 373 372 */ 374 373 struct tb *tb_domain_alloc(struct tb_nhi *nhi, int timeout_msec, size_t privsize) 375 374 { ··· 431 430 * and release the domain after this function has been called, call 432 431 * tb_domain_remove(). 433 432 * 434 - * Return: %0 in case of success and negative errno in case of error 433 + * Return: %0 on success, negative errno otherwise. 435 434 */ 436 435 int tb_domain_add(struct tb *tb, bool reset) 437 436 { ··· 519 518 * @tb: Domain to suspend 520 519 * 521 520 * Suspends all devices in the domain and stops the control channel. 521 + * 522 + * Return: %0 on success, negative errno otherwise. 522 523 */ 523 524 int tb_domain_suspend_noirq(struct tb *tb) 524 525 { ··· 547 544 * 548 545 * Re-starts the control channel, and resumes all devices connected to 549 546 * the domain. 547 + * 548 + * Return: %0 on success, negative errno otherwise. 550 549 */ 551 550 int tb_domain_resume_noirq(struct tb *tb) 552 551 { ··· 648 643 * This will approve switch by connection manager specific means. In 649 644 * case of success the connection manager will create PCIe tunnel from 650 645 * parent to @sw. 646 + * 647 + * Return: %0 on success, negative errno otherwise. 651 648 */ 652 649 int tb_domain_approve_switch(struct tb *tb, struct tb_switch *sw) 653 650 { ··· 715 708 u8 response[TB_SWITCH_KEY_SIZE]; 716 709 u8 hmac[TB_SWITCH_KEY_SIZE]; 717 710 struct tb_switch *parent_sw; 718 - struct crypto_shash *tfm; 719 - struct shash_desc *shash; 720 711 int ret; 721 712 722 713 if (!tb->cm_ops->approve_switch || !tb->cm_ops->challenge_switch_key) ··· 730 725 if (ret) 731 726 return ret; 732 727 733 - tfm = crypto_alloc_shash("hmac(sha256)", 0, 0); 734 - if (IS_ERR(tfm)) 735 - return PTR_ERR(tfm); 736 - 737 - ret = crypto_shash_setkey(tfm, sw->key, TB_SWITCH_KEY_SIZE); 738 - if (ret) 739 - goto err_free_tfm; 740 - 741 - shash = kzalloc(sizeof(*shash) + crypto_shash_descsize(tfm), 742 - GFP_KERNEL); 743 - if (!shash) { 744 - ret = -ENOMEM; 745 - goto err_free_tfm; 746 - } 747 - 748 - shash->tfm = tfm; 749 - 750 - memset(hmac, 0, sizeof(hmac)); 751 - ret = crypto_shash_digest(shash, challenge, sizeof(hmac), hmac); 752 - if (ret) 753 - goto err_free_shash; 728 + static_assert(sizeof(hmac) == SHA256_DIGEST_SIZE); 729 + hmac_sha256_usingrawkey(sw->key, TB_SWITCH_KEY_SIZE, 730 + challenge, sizeof(challenge), hmac); 754 731 755 732 /* The returned HMAC must match the one we calculated */ 756 - if (memcmp(response, hmac, sizeof(hmac))) { 757 - ret = -EKEYREJECTED; 758 - goto err_free_shash; 759 - } 760 - 761 - crypto_free_shash(tfm); 762 - kfree(shash); 733 + if (crypto_memneq(response, hmac, sizeof(hmac))) 734 + return -EKEYREJECTED; 763 735 764 736 return tb->cm_ops->approve_switch(tb, sw); 765 - 766 - err_free_shash: 767 - kfree(shash); 768 - err_free_tfm: 769 - crypto_free_shash(tfm); 770 - 771 - return ret; 772 737 } 773 738 774 739 /** ··· 748 773 * This needs to be called in preparation for NVM upgrade of the host 749 774 * controller. Makes sure all PCIe paths are disconnected. 750 775 * 751 - * Return %0 on success and negative errno in case of error. 776 + * Return: %0 on success and negative errno in case of error. 752 777 */ 753 778 int tb_domain_disconnect_pcie_paths(struct tb *tb) 754 779 { ··· 770 795 * Calls connection manager specific method to enable DMA paths to the 771 796 * XDomain in question. 772 797 * 773 - * Return: 0% in case of success and negative errno otherwise. In 774 - * particular returns %-ENOTSUPP if the connection manager 775 - * implementation does not support XDomains. 798 + * Return: 799 + * * %0 - On success. 800 + * * %-ENOTSUPP - If the connection manager implementation does not support 801 + * XDomains. 802 + * * Negative errno - An error occurred. 776 803 */ 777 804 int tb_domain_approve_xdomain_paths(struct tb *tb, struct tb_xdomain *xd, 778 805 int transmit_path, int transmit_ring, ··· 799 822 * Calls connection manager specific method to disconnect DMA paths to 800 823 * the XDomain in question. 801 824 * 802 - * Return: 0% in case of success and negative errno otherwise. In 803 - * particular returns %-ENOTSUPP if the connection manager 804 - * implementation does not support XDomains. 825 + * Return: 826 + * * %0 - On success. 827 + * * %-ENOTSUPP - If the connection manager implementation does not support 828 + * XDomains. 829 + * * Negative errno - An error occurred. 805 830 */ 806 831 int tb_domain_disconnect_xdomain_paths(struct tb *tb, struct tb_xdomain *xd, 807 832 int transmit_path, int transmit_ring,
+3 -1
drivers/thunderbolt/eeprom.c
··· 298 298 * 299 299 * Does not use the cached copy in sw->drom. Used during resume to check switch 300 300 * identity. 301 + * 302 + * Return: %0 on success, negative errno otherwise. 301 303 */ 302 304 int tb_drom_read_uid_only(struct tb_switch *sw, u64 *uid) 303 305 { ··· 711 709 * populates the fields in @sw accordingly. Can be called for any router 712 710 * generation. 713 711 * 714 - * Returns %0 in case of success and negative errno otherwise. 712 + * Return: %0 on success, negative errno otherwise. 715 713 */ 716 714 int tb_drom_read(struct tb_switch *sw) 717 715 {
+43 -15
drivers/thunderbolt/lc.c
··· 14 14 * tb_lc_read_uuid() - Read switch UUID from link controller common register 15 15 * @sw: Switch whose UUID is read 16 16 * @uuid: UUID is placed here 17 + * 18 + * Return: %0 on success, negative errno otherwise. 17 19 */ 18 20 int tb_lc_read_uuid(struct tb_switch *sw, u32 *uuid) 19 21 { ··· 54 52 * @port: Port that is reset 55 53 * 56 54 * Triggers downstream port reset through link controller registers. 57 - * Returns %0 in case of success negative errno otherwise. Only supports 58 - * non-USB4 routers with link controller (that's Thunderbolt 2 and 59 - * Thunderbolt 3). 55 + * Only supports non-USB4 routers with link controller (that's 56 + * Thunderbolt 2 and Thunderbolt 3). 57 + * 58 + * Return: %0 on success, negative errno otherwise. 60 59 */ 61 60 int tb_lc_reset_port(struct tb_port *port) 62 61 { ··· 135 132 * @port: Port that is set as configured 136 133 * 137 134 * Sets the port configured for power management purposes. 135 + * 136 + * Return: %0 on success, negative errno otherwise. 138 137 */ 139 138 int tb_lc_configure_port(struct tb_port *port) 140 139 { ··· 148 143 * @port: Port that is set as configured 149 144 * 150 145 * Sets the port unconfigured for power management purposes. 146 + * 147 + * Return: %0 on success, negative errno otherwise. 151 148 */ 152 149 void tb_lc_unconfigure_port(struct tb_port *port) 153 150 { ··· 191 184 * tb_lc_configure_xdomain() - Inform LC that the link is XDomain 192 185 * @port: Switch downstream port connected to another host 193 186 * 194 - * Sets the lane configured for XDomain accordingly so that the LC knows 195 - * about this. Returns %0 in success and negative errno in failure. 187 + * Sets the lane configured for XDomain accordingly so that LC knows 188 + * about this. 189 + * 190 + * Return: %0 on success, negative errno otherwise. 196 191 */ 197 192 int tb_lc_configure_xdomain(struct tb_port *port) 198 193 { ··· 220 211 * sleep. Should be called for those downstream lane adapters that were 221 212 * not connected (tb_lc_configure_port() was not called) before sleep. 222 213 * 223 - * Returns %0 in success and negative errno in case of failure. 214 + * Return: %0 on success, negative errno otherwise. 224 215 */ 225 216 int tb_lc_start_lane_initialization(struct tb_port *port) 226 217 { ··· 253 244 * 254 245 * TB_LC_LINK_ATTR_CPS bit reflects if the link supports CLx including 255 246 * active cables (if connected on the link). 247 + * 248 + * Return: %true if CLx is supported, %false otherwise. 256 249 */ 257 250 bool tb_lc_is_clx_supported(struct tb_port *port) 258 251 { ··· 277 266 * tb_lc_is_usb_plugged() - Is there USB device connected to port 278 267 * @port: Device router lane 0 adapter 279 268 * 280 - * Returns true if the @port has USB type-C device connected. 269 + * Return: %true if the @port has USB Type-C device connected, %false 270 + * otherwise. 281 271 */ 282 272 bool tb_lc_is_usb_plugged(struct tb_port *port) 283 273 { ··· 304 292 * tb_lc_is_xhci_connected() - Is the internal xHCI connected 305 293 * @port: Device router lane 0 adapter 306 294 * 307 - * Returns true if the internal xHCI has been connected to @port. 295 + * Return: %true if the internal xHCI has been connected to 296 + * @port, %false otherwise. 308 297 */ 309 298 bool tb_lc_is_xhci_connected(struct tb_port *port) 310 299 { ··· 356 343 * tb_lc_xhci_connect() - Connect internal xHCI 357 344 * @port: Device router lane 0 adapter 358 345 * 359 - * Tells LC to connect the internal xHCI to @port. Returns %0 on success 360 - * and negative errno in case of failure. Can be called for Thunderbolt 3 361 - * routers only. 346 + * Tells LC to connect the internal xHCI to @port. Can be called for 347 + * Thunderbolt 3 routers only. 348 + * 349 + * Return: %0 on success, negative errno otherwise. 362 350 */ 363 351 int tb_lc_xhci_connect(struct tb_port *port) 364 352 { ··· 422 408 * @flags: Wakeup flags (%0 to disable) 423 409 * 424 410 * For each LC sets wake bits accordingly. 411 + * 412 + * Return: %0 on success, negative errno otherwise. 425 413 */ 426 414 int tb_lc_set_wake(struct tb_switch *sw, unsigned int flags) 427 415 { ··· 463 447 * 464 448 * Let the switch link controllers know that the switch is going to 465 449 * sleep. 450 + * 451 + * Return: %0 on success, negative errno otherwise. 466 452 */ 467 453 int tb_lc_set_sleep(struct tb_switch *sw) 468 454 { ··· 509 491 * 510 492 * Checks whether conditions for lane bonding from parent to @sw are 511 493 * possible. 494 + * 495 + * Return: %true if lane bonding is possible, %false otherwise. 512 496 */ 513 497 bool tb_lc_lane_bonding_possible(struct tb_switch *sw) 514 498 { ··· 582 562 * 583 563 * Queries through LC SNK_ALLOCATION registers whether DP sink is available 584 564 * for the given DP IN port or not. 565 + * 566 + * Return: %true if DP sink is available, %false otherwise. 585 567 */ 586 568 bool tb_lc_dp_sink_query(struct tb_switch *sw, struct tb_port *in) 587 569 { ··· 608 586 * @sw: Switch whose DP sink is allocated 609 587 * @in: DP IN port the DP sink is allocated for 610 588 * 611 - * Allocate DP sink for @in via LC SNK_ALLOCATION registers. If the 612 - * resource is available and allocation is successful returns %0. In all 613 - * other cases returs negative errno. In particular %-EBUSY is returned if 614 - * the resource was not available. 589 + * Allocate DP sink for @in via LC SNK_ALLOCATION registers. 590 + * 591 + * Return: 592 + * * %0 - If the resource is available and allocation is successful. 593 + * * %-EBUSY - If resource is not available. 594 + * * Negative errno - Another error occurred. 615 595 */ 616 596 int tb_lc_dp_sink_alloc(struct tb_switch *sw, struct tb_port *in) 617 597 { ··· 661 637 * @in: DP IN port whose DP sink is de-allocated 662 638 * 663 639 * De-allocate DP sink from @in using LC SNK_ALLOCATION registers. 640 + * 641 + * Return: %0 on success, negative errno otherwise. 664 642 */ 665 643 int tb_lc_dp_sink_dealloc(struct tb_switch *sw, struct tb_port *in) 666 644 { ··· 706 680 * 707 681 * This is useful to let authentication cycle pass even without 708 682 * a Thunderbolt link present. 683 + * 684 + * Return: %0 on success, negative errno otherwise. 709 685 */ 710 686 int tb_lc_force_power(struct tb_switch *sw) 711 687 {
+15 -5
drivers/thunderbolt/nhi.c
··· 19 19 #include <linux/module.h> 20 20 #include <linux/delay.h> 21 21 #include <linux/property.h> 22 + #include <linux/string_choices.h> 22 23 #include <linux/string_helpers.h> 23 24 24 25 #include "nhi.h" ··· 147 146 dev_WARN(&ring->nhi->pdev->dev, 148 147 "interrupt for %s %d is already %s\n", 149 148 RING_TYPE(ring), ring->hop, 150 - active ? "enabled" : "disabled"); 149 + str_enabled_disabled(active)); 151 150 152 151 if (active) 153 152 iowrite32(new, ring->nhi->iobase + reg); ··· 344 343 * 345 344 * This function can be called when @start_poll callback of the @ring 346 345 * has been called. It will read one completed frame from the ring and 347 - * return it to the caller. Returns %NULL if there is no more completed 348 - * frames. 346 + * return it to the caller. 347 + * 348 + * Return: Pointer to &struct ring_frame, %NULL if there is no more 349 + * completed frames. 349 350 */ 350 351 struct ring_frame *tb_ring_poll(struct tb_ring *ring) 351 352 { ··· 642 639 * @hop: HopID (ring) to allocate 643 640 * @size: Number of entries in the ring 644 641 * @flags: Flags for the ring 642 + * 643 + * Return: Pointer to &struct tb_ring, %NULL otherwise. 645 644 */ 646 645 struct tb_ring *tb_ring_alloc_tx(struct tb_nhi *nhi, int hop, int size, 647 646 unsigned int flags) ··· 665 660 * interrupt is triggered and masked, instead of callback 666 661 * in each Rx frame. 667 662 * @poll_data: Optional data passed to @start_poll 663 + * 664 + * Return: Pointer to &struct tb_ring, %NULL otherwise. 668 665 */ 669 666 struct tb_ring *tb_ring_alloc_rx(struct tb_nhi *nhi, int hop, int size, 670 667 unsigned int flags, int e2e_tx_hop, ··· 860 853 * @cmd: Command to send 861 854 * @data: Data to be send with the command 862 855 * 863 - * Sends mailbox command to the firmware running on NHI. Returns %0 in 864 - * case of success and negative errno in case of failure. 856 + * Sends mailbox command to the firmware running on NHI. 857 + * 858 + * Return: %0 on success, negative errno otherwise. 865 859 */ 866 860 int nhi_mailbox_cmd(struct tb_nhi *nhi, enum nhi_mailbox_cmd cmd, u32 data) 867 861 { ··· 898 890 * 899 891 * The function reads current firmware operation mode using NHI mailbox 900 892 * registers and returns it to the caller. 893 + * 894 + * Return: &enum nhi_fw_mode. 901 895 */ 902 896 enum nhi_fw_mode nhi_mailbox_mode(struct tb_nhi *nhi) 903 897 {
+6
drivers/thunderbolt/nhi_regs.h
··· 21 21 22 22 /** 23 23 * struct ring_desc - TX/RX ring entry 24 + * @phys: DMA mapped address of the frame 25 + * @length: Size of the ring 26 + * @eof: End of frame protocol defined field 27 + * @sof: Start of frame protocol defined field 28 + * @flags: Ring descriptor flags 29 + * @time: Fill with zero 24 30 * 25 31 * For TX set length/eof/sof. 26 32 * For RX length/eof/sof are set by the NHI.
+26 -16
drivers/thunderbolt/nvm.c
··· 278 278 * tb_nvm_alloc() - Allocate new NVM structure 279 279 * @dev: Device owning the NVM 280 280 * 281 - * Allocates new NVM structure with unique @id and returns it. In case 282 - * of error returns ERR_PTR(). Specifically returns %-EOPNOTSUPP if the 283 - * NVM format of the @dev is not known by the kernel. 281 + * Allocates new NVM structure with unique @id and returns it. 282 + * 283 + * Return: 284 + * * Pointer to &struct tb_nvm - On success. 285 + * * %-EOPNOTSUPP - If the NVM format of the @dev is not known by the 286 + * kernel. 287 + * * %ERR_PTR - In case of failure. 284 288 */ 285 289 struct tb_nvm *tb_nvm_alloc(struct device *dev) 286 290 { ··· 351 347 * tb_nvm_read_version() - Read and populate NVM version 352 348 * @nvm: NVM structure 353 349 * 354 - * Uses vendor specific means to read out and fill in the existing 355 - * active NVM version. Returns %0 in case of success and negative errno 356 - * otherwise. 350 + * Uses vendor specific means to read and fill out the existing 351 + * active NVM version. 352 + * 353 + * Return: %0 on success, negative errno otherwise. 357 354 */ 358 355 int tb_nvm_read_version(struct tb_nvm *nvm) 359 356 { ··· 370 365 * tb_nvm_validate() - Validate new NVM image 371 366 * @nvm: NVM structure 372 367 * 373 - * Runs vendor specific validation over the new NVM image and if all 374 - * checks pass returns %0. As side effect updates @nvm->buf_data_start 375 - * and @nvm->buf_data_size fields to match the actual data to be written 376 - * to the NVM. 368 + * Runs vendor specific validation over the new NVM image. As a 369 + * side effect, updates @nvm->buf_data_start and @nvm->buf_data_size 370 + * fields to match the actual data to be written to the NVM. 377 371 * 378 - * If the validation does not pass then returns negative errno. 372 + * Return: %0 on successful validation, negative errno otherwise. 379 373 */ 380 374 int tb_nvm_validate(struct tb_nvm *nvm) 381 375 { ··· 409 405 * the image, this function does that. Can be called even if the device 410 406 * does not need this. 411 407 * 412 - * Returns %0 in case of success and negative errno otherwise. 408 + * Return: %0 on success, negative errno otherwise. 413 409 */ 414 410 int tb_nvm_write_headers(struct tb_nvm *nvm) 415 411 { ··· 427 423 * Registers new active NVmem device for @nvm. The @reg_read is called 428 424 * directly from NVMem so it must handle possible concurrent access if 429 425 * needed. The first parameter passed to @reg_read is @nvm structure. 430 - * Returns %0 in success and negative errno otherwise. 426 + * 427 + * Return: %0 on success, negative errno otherwise. 431 428 */ 432 429 int tb_nvm_add_active(struct tb_nvm *nvm, nvmem_reg_read_t reg_read) 433 430 { ··· 466 461 * Helper function to cache the new NVM image before it is actually 467 462 * written to the flash. Copies @bytes from @val to @nvm->buf starting 468 463 * from @offset. 464 + * 465 + * Return: 466 + * * %0 - On success. 467 + * * %-ENOMEM - If buffer allocation failed. 468 + * * Negative errno - Another error occurred. 469 469 */ 470 470 int tb_nvm_write_buf(struct tb_nvm *nvm, unsigned int offset, void *val, 471 471 size_t bytes) ··· 498 488 * needed. The first parameter passed to @reg_write is @nvm structure. 499 489 * The size of the NVMem device is set to %NVM_MAX_SIZE. 500 490 * 501 - * Returns %0 in success and negative errno otherwise. 491 + * Return: %0 on success, negative errno otherwise. 502 492 */ 503 493 int tb_nvm_add_non_active(struct tb_nvm *nvm, nvmem_reg_write_t reg_write) 504 494 { ··· 555 545 * This is a generic function that reads data from NVM or NVM like 556 546 * device. 557 547 * 558 - * Returns %0 on success and negative errno otherwise. 548 + * Return: %0 on success, negative errno otherwise. 559 549 */ 560 550 int tb_nvm_read_data(unsigned int address, void *buf, size_t size, 561 551 unsigned int retries, read_block_fn read_block, ··· 602 592 * 603 593 * This is generic function that writes data to NVM or NVM like device. 604 594 * 605 - * Returns %0 on success and negative errno otherwise. 595 + * Return: %0 on success, negative errno otherwise. 606 596 */ 607 597 int tb_nvm_write_data(unsigned int address, const void *buf, size_t size, 608 598 unsigned int retries, write_block_fn write_block,
+9 -5
drivers/thunderbolt/path.c
··· 96 96 * that the @dst port is the expected one. If it is not, the path can be 97 97 * cleaned up by calling tb_path_deactivate() before tb_path_free(). 98 98 * 99 - * Return: Discovered path on success, %NULL in case of failure 99 + * Return: Pointer to &struct tb_path, %NULL in case of failure. 100 100 */ 101 101 struct tb_path *tb_path_discover(struct tb_port *src, int src_hopid, 102 102 struct tb_port *dst, int dst_hopid, ··· 233 233 * links on the path, prioritizes using @link_nr but takes into account 234 234 * that the lanes may be bonded. 235 235 * 236 - * Return: Returns a tb_path on success or NULL on failure. 236 + * Return: Pointer to &struct tb_path, %NULL in case of failure. 237 237 */ 238 238 struct tb_path *tb_path_alloc(struct tb *tb, struct tb_port *src, int src_hopid, 239 239 struct tb_port *dst, int dst_hopid, int link_nr, ··· 452 452 * @hop_index: HopID of the path to be cleared 453 453 * 454 454 * This deactivates or clears a single path config space entry at 455 - * @hop_index. Returns %0 in success and negative errno otherwise. 455 + * @hop_index. 456 + * 457 + * Return: %0 on success, negative errno otherwise. 456 458 */ 457 459 int tb_path_deactivate_hop(struct tb_port *port, int hop_index) 458 460 { ··· 500 498 * Activate a path starting with the last hop and iterating backwards. The 501 499 * caller must fill path->hops before calling tb_path_activate(). 502 500 * 503 - * Return: Returns 0 on success or an error code on failure. 501 + * Return: %0 on success, negative errno otherwise. 504 502 */ 505 503 int tb_path_activate(struct tb_path *path) 506 504 { ··· 594 592 * tb_path_is_invalid() - check whether any ports on the path are invalid 595 593 * @path: Path to check 596 594 * 597 - * Return: Returns true if the path is invalid, false otherwise. 595 + * Return: %true if the path is invalid, %false otherwise. 598 596 */ 599 597 bool tb_path_is_invalid(struct tb_path *path) 600 598 { ··· 615 613 * 616 614 * Goes over all hops on path and checks if @port is any of them. 617 615 * Direction does not matter. 616 + * 617 + * Return: %true if port is on the path, %false otherwise. 618 618 */ 619 619 bool tb_path_port_on_path(const struct tb_path *path, const struct tb_port *port) 620 620 {
+28 -10
drivers/thunderbolt/property.c
··· 211 211 * 212 212 * This function parses the XDomain properties data block into format that 213 213 * can be traversed using the helper functions provided by this module. 214 - * Upon success returns the parsed directory. In case of error returns 215 - * %NULL. The resulting &struct tb_property_dir needs to be released by 214 + * 215 + * The resulting &struct tb_property_dir needs to be released by 216 216 * calling tb_property_free_dir() when not needed anymore. 217 217 * 218 218 * The @block is expected to be root directory. 219 + * 220 + * Return: Pointer to &struct tb_property_dir, %NULL in case of failure. 219 221 */ 220 222 struct tb_property_dir *tb_property_parse_dir(const u32 *block, 221 223 size_t block_len) ··· 240 238 * 241 239 * Creates new, empty property directory. If @uuid is %NULL then the 242 240 * directory is assumed to be root directory. 241 + * 242 + * Return: Pointer to &struct tb_property_dir, %NULL in case of failure. 243 243 */ 244 244 struct tb_property_dir *tb_property_create_dir(const uuid_t *uuid) 245 245 { ··· 485 481 * @block_len: Length of the property block 486 482 * 487 483 * This function formats the directory to the packed format that can be 488 - * then send over the thunderbolt fabric to receiving host. Returns %0 in 489 - * case of success and negative errno on faulure. Passing %NULL in @block 490 - * returns number of entries the block takes. 484 + * then sent over the thunderbolt fabric to receiving host. 485 + * 486 + * Passing %NULL in @block returns number of entries the block takes. 487 + * 488 + * Return: %0 on success, negative errno otherwise. 491 489 */ 492 490 ssize_t tb_property_format_dir(const struct tb_property_dir *dir, u32 *block, 493 491 size_t block_len) ··· 511 505 * tb_property_copy_dir() - Take a deep copy of directory 512 506 * @dir: Directory to copy 513 507 * 514 - * This function takes a deep copy of @dir and returns back the copy. In 515 - * case of error returns %NULL. The resulting directory needs to be 516 - * released by calling tb_property_free_dir(). 508 + * The resulting directory needs to be released by calling tb_property_free_dir(). 509 + * 510 + * Return: Pointer to &struct tb_property_dir, %NULL in case of failure. 517 511 */ 518 512 struct tb_property_dir *tb_property_copy_dir(const struct tb_property_dir *dir) 519 513 { ··· 583 577 * @parent: Directory to add the property 584 578 * @key: Key for the property 585 579 * @value: Immediate value to store with the property 580 + * 581 + * Return: %0 on success, negative errno otherwise. 586 582 */ 587 583 int tb_property_add_immediate(struct tb_property_dir *parent, const char *key, 588 584 u32 value) ··· 614 606 * @buflen: Number of bytes in the data buffer 615 607 * 616 608 * Function takes a copy of @buf and adds it to the directory. 609 + * 610 + * Return: %0 on success, negative errno otherwise. 617 611 */ 618 612 int tb_property_add_data(struct tb_property_dir *parent, const char *key, 619 613 const void *buf, size_t buflen) ··· 652 642 * @text: String to add 653 643 * 654 644 * Function takes a copy of @text and adds it to the directory. 645 + * 646 + * Return: %0 on success, negative errno otherwise. 655 647 */ 656 648 int tb_property_add_text(struct tb_property_dir *parent, const char *key, 657 649 const char *text) ··· 688 676 * @parent: Directory to add the property 689 677 * @key: Key for the property 690 678 * @dir: Directory to add 679 + * 680 + * Return: %0 on success, negative errno otherwise. 691 681 */ 692 682 int tb_property_add_dir(struct tb_property_dir *parent, const char *key, 693 683 struct tb_property_dir *dir) ··· 730 716 * @key: Key to look for 731 717 * @type: Type of the property 732 718 * 733 - * Finds and returns property from the given directory. Does not recurse 734 - * into sub-directories. Returns %NULL if the property was not found. 719 + * Finds and returns property from the given directory. Does not 720 + * recurse into sub-directories. 721 + * 722 + * Return: Pointer to &struct tb_property, %NULL if the property was not found. 735 723 */ 736 724 struct tb_property *tb_property_find(struct tb_property_dir *dir, 737 725 const char *key, enum tb_property_type type) ··· 753 737 * tb_property_get_next() - Get next property from directory 754 738 * @dir: Directory holding properties 755 739 * @prev: Previous property in the directory (%NULL returns the first) 740 + * 741 + * Return: Pointer to &struct tb_property, %NULL if property was not found. 756 742 */ 757 743 struct tb_property *tb_property_get_next(struct tb_property_dir *dir, 758 744 struct tb_property *prev)
+5 -2
drivers/thunderbolt/retimer.c
··· 27 27 * @buf: Data read from NVM is stored here 28 28 * @size: Number of bytes to read 29 29 * 30 - * Reads retimer NVM and copies the contents to @buf. Returns %0 if the 31 - * read was successful and negative errno in case of failure. 30 + * Reads retimer NVM and copies the contents to @buf. 31 + * 32 + * Return: %0 if the read was successful, negative errno in case of failure. 32 33 */ 33 34 int tb_retimer_nvm_read(struct tb_retimer *rt, unsigned int address, void *buf, 34 35 size_t size) ··· 504 503 * Then Tries to enumerate on-board retimers connected to @port. Found 505 504 * retimers are registered as children of @port if @add is set. Does 506 505 * not scan for cable retimers for now. 506 + * 507 + * Return: %0 on success, negative errno otherwise. 507 508 */ 508 509 int tb_retimer_scan(struct tb_port *port, bool add) 509 510 {
+102 -38
drivers/thunderbolt/switch.c
··· 290 290 * @size: Size of the buffer in bytes 291 291 * 292 292 * Reads from router NVM and returns the requested data in @buf. Locking 293 - * is up to the caller. Returns %0 in success and negative errno in case 294 - * of failure. 293 + * is up to the caller. 294 + * 295 + * Return: %0 on success, negative errno otherwise. 295 296 */ 296 297 int tb_switch_nvm_read(struct tb_switch *sw, unsigned int address, void *buf, 297 298 size_t size) ··· 465 464 * 466 465 * The port must have a TB_CAP_PHY (i.e. it should be a real port). 467 466 * 468 - * Return: Returns an enum tb_port_state on success or an error code on failure. 467 + * Return: &enum tb_port_state or negative error code on failure. 469 468 */ 470 469 int tb_port_state(struct tb_port *port) 471 470 { ··· 492 491 * switch resume). Otherwise we only wait if a device is registered but the link 493 492 * has not yet been established. 494 493 * 495 - * Return: Returns an error code on failure. Returns 0 if the port is not 496 - * connected or failed to reach state TB_PORT_UP within one second. Returns 1 497 - * if the port is connected and in state TB_PORT_UP. 494 + * Return: 495 + * * %0 - If the port is not connected or failed to reach 496 + * state %TB_PORT_UP within one second. 497 + * * %1 - If the port is connected and in state %TB_PORT_UP. 498 + * * Negative errno - An error occurred. 498 499 */ 499 500 int tb_wait_for_port(struct tb_port *port, bool wait_if_unplugged) 500 501 { ··· 565 562 * Change the number of NFC credits allocated to @port by @credits. To remove 566 563 * NFC credits pass a negative amount of credits. 567 564 * 568 - * Return: Returns 0 on success or an error code on failure. 565 + * Return: %0 on success, negative errno otherwise. 569 566 */ 570 567 int tb_port_add_nfc_credits(struct tb_port *port, int credits) 571 568 { ··· 602 599 * @port: Port whose counters to clear 603 600 * @counter: Counter index to clear 604 601 * 605 - * Return: Returns 0 on success or an error code on failure. 602 + * Return: %0 on success, negative errno otherwise. 606 603 */ 607 604 int tb_port_clear_counter(struct tb_port *port, int counter) 608 605 { ··· 617 614 * 618 615 * Needed for USB4 but can be called for any CIO/USB4 ports. Makes the 619 616 * downstream router accessible for CM. 617 + * 618 + * Return: %0 on success, negative errno otherwise. 620 619 */ 621 620 int tb_port_unlock(struct tb_port *port) 622 621 { ··· 664 659 * @port: Port to enable (can be %NULL) 665 660 * 666 661 * This is used for lane 0 and 1 adapters to enable it. 662 + * 663 + * Return: %0 on success, negative errno otherwise. 667 664 */ 668 665 int tb_port_enable(struct tb_port *port) 669 666 { ··· 677 670 * @port: Port to disable (can be %NULL) 678 671 * 679 672 * This is used for lane 0 and 1 adapters to disable it. 673 + * 674 + * Return: %0 on success, negative errno otherwise. 680 675 */ 681 676 int tb_port_disable(struct tb_port *port) 682 677 { ··· 698 689 * This is a helper method for tb_switch_alloc. Does not check or initialize 699 690 * any downstream switches. 700 691 * 701 - * Return: Returns 0 on success or an error code on failure. 692 + * Return: %0 on success, negative errno otherwise. 702 693 */ 703 694 static int tb_init_port(struct tb_port *port) 704 695 { ··· 856 847 * link port, the function follows that link and returns another end on 857 848 * that same link. 858 849 * 859 - * If the @end port has been reached, return %NULL. 860 - * 861 850 * Domain tb->lock must be held when this function is called. 851 + * 852 + * Return: Pointer to &struct tb_port, %NULL if the @end port has been reached. 862 853 */ 863 854 struct tb_port *tb_next_port_on_path(struct tb_port *start, struct tb_port *end, 864 855 struct tb_port *prev) ··· 903 894 * tb_port_get_link_speed() - Get current link speed 904 895 * @port: Port to check (USB4 or CIO) 905 896 * 906 - * Returns link speed in Gb/s or negative errno in case of failure. 897 + * Return: Link speed in Gb/s or negative errno in case of failure. 907 898 */ 908 899 int tb_port_get_link_speed(struct tb_port *port) 909 900 { ··· 935 926 * tb_port_get_link_generation() - Returns link generation 936 927 * @port: Lane adapter 937 928 * 938 - * Returns link generation as number or negative errno in case of 939 - * failure. Does not distinguish between Thunderbolt 1 and Thunderbolt 2 940 - * links so for those always returns 2. 929 + * Return: Link generation as a number or negative errno in case of 930 + * failure. 931 + * 932 + * Does not distinguish between Thunderbolt 1 and Thunderbolt 2 933 + * links so for those always returns %2. 941 934 */ 942 935 int tb_port_get_link_generation(struct tb_port *port) 943 936 { ··· 963 952 * tb_port_get_link_width() - Get current link width 964 953 * @port: Port to check (USB4 or CIO) 965 954 * 966 - * Returns link width. Return the link width as encoded in &enum 967 - * tb_link_width or negative errno in case of failure. 955 + * Return: Link width encoded in &enum tb_link_width or 956 + * negative errno in case of failure. 968 957 */ 969 958 int tb_port_get_link_width(struct tb_port *port) 970 959 { ··· 990 979 * @width: Widths to check (bitmask) 991 980 * 992 981 * Can be called to any lane adapter. Checks if given @width is 993 - * supported by the hardware and returns %true if it is. 982 + * supported by the hardware. 983 + * 984 + * Return: %true if link width is supported, %false otherwise. 994 985 */ 995 986 bool tb_port_width_supported(struct tb_port *port, unsigned int width) 996 987 { ··· 1029 1016 * Sets the target link width of the lane adapter to @width. Does not 1030 1017 * enable/disable lane bonding. For that call tb_port_set_lane_bonding(). 1031 1018 * 1032 - * Return: %0 in case of success and negative errno in case of error 1019 + * Return: %0 on success, negative errno otherwise. 1033 1020 */ 1034 1021 int tb_port_set_link_width(struct tb_port *port, enum tb_link_width width) 1035 1022 { ··· 1083 1070 * cases one should use tb_port_lane_bonding_enable() instead to enable 1084 1071 * lane bonding. 1085 1072 * 1086 - * Return: %0 in case of success and negative errno in case of error 1073 + * Return: %0 on success, negative errno otherwise. 1087 1074 */ 1088 1075 static int tb_port_set_lane_bonding(struct tb_port *port, bool bonding) 1089 1076 { ··· 1117 1104 * tb_port_wait_for_link_width() before enabling any paths through the 1118 1105 * link to make sure the link is in expected state. 1119 1106 * 1120 - * Return: %0 in case of success and negative errno in case of error 1107 + * Return: %0 on success, negative errno otherwise. 1121 1108 */ 1122 1109 int tb_port_lane_bonding_enable(struct tb_port *port) 1123 1110 { ··· 1194 1181 * 1195 1182 * Should be used after both ends of the link have been bonded (or 1196 1183 * bonding has been disabled) to wait until the link actually reaches 1197 - * the expected state. Returns %-ETIMEDOUT if the width was not reached 1198 - * within the given timeout, %0 if it did. Can be passed a mask of 1199 - * expected widths and succeeds if any of the widths is reached. 1184 + * the expected state. 1185 + * 1186 + * Can be passed a mask of expected widths. 1187 + * 1188 + * Return: 1189 + * * %0 - If link reaches any of the specified widths. 1190 + * * %-ETIMEDOUT - If link does not reach specified width. 1191 + * * Negative errno - Another error occurred. 1200 1192 */ 1201 1193 int tb_port_wait_for_link_width(struct tb_port *port, unsigned int width, 1202 1194 int timeout_msec) ··· 1266 1248 * After the link is bonded (or bonding was disabled) the port total 1267 1249 * credits may change, so this function needs to be called to re-read 1268 1250 * the credits. Updates also the second lane adapter. 1251 + * 1252 + * Return: %0 on success, negative errno otherwise. 1269 1253 */ 1270 1254 int tb_port_update_credits(struct tb_port *port) 1271 1255 { ··· 1323 1303 /** 1324 1304 * tb_port_is_enabled() - Is the adapter port enabled 1325 1305 * @port: Port to check 1306 + * 1307 + * Return: %true if port is enabled, %false otherwise. 1326 1308 */ 1327 1309 bool tb_port_is_enabled(struct tb_port *port) 1328 1310 { ··· 1349 1327 /** 1350 1328 * tb_usb3_port_is_enabled() - Is the USB3 adapter port enabled 1351 1329 * @port: USB3 adapter port to check 1330 + * 1331 + * Return: %true if port is enabled, %false otherwise. 1352 1332 */ 1353 1333 bool tb_usb3_port_is_enabled(struct tb_port *port) 1354 1334 { ··· 1367 1343 * tb_usb3_port_enable() - Enable USB3 adapter port 1368 1344 * @port: USB3 adapter port to enable 1369 1345 * @enable: Enable/disable the USB3 adapter 1346 + * 1347 + * Return: %0 on success, negative errno otherwise. 1370 1348 */ 1371 1349 int tb_usb3_port_enable(struct tb_port *port, bool enable) 1372 1350 { ··· 1384 1358 /** 1385 1359 * tb_pci_port_is_enabled() - Is the PCIe adapter port enabled 1386 1360 * @port: PCIe port to check 1361 + * 1362 + * Return: %true if port is enabled, %false otherwise. 1387 1363 */ 1388 1364 bool tb_pci_port_is_enabled(struct tb_port *port) 1389 1365 { ··· 1402 1374 * tb_pci_port_enable() - Enable PCIe adapter port 1403 1375 * @port: PCIe port to enable 1404 1376 * @enable: Enable/disable the PCIe adapter 1377 + * 1378 + * Return: %0 on success, negative errno otherwise. 1405 1379 */ 1406 1380 int tb_pci_port_enable(struct tb_port *port, bool enable) 1407 1381 { ··· 1419 1389 * @port: DP out port to check 1420 1390 * 1421 1391 * Checks if the DP OUT adapter port has HPD bit already set. 1392 + * 1393 + * Return: %1 if HPD is active, %0 otherwise. 1422 1394 */ 1423 1395 int tb_dp_port_hpd_is_active(struct tb_port *port) 1424 1396 { ··· 1440 1408 * @port: Port to clear HPD 1441 1409 * 1442 1410 * If the DP IN port has HPD set, this function can be used to clear it. 1411 + * 1412 + * Return: %0 on success, negative errno otherwise. 1443 1413 */ 1444 1414 int tb_dp_port_hpd_clear(struct tb_port *port) 1445 1415 { ··· 1468 1434 * Programs specified Hop IDs for DP IN/OUT port. Can be called for USB4 1469 1435 * router DP adapters too but does not program the values as the fields 1470 1436 * are read-only. 1437 + * 1438 + * Return: %0 on success, negative errno otherwise. 1471 1439 */ 1472 1440 int tb_dp_port_set_hops(struct tb_port *port, unsigned int video, 1473 1441 unsigned int aux_tx, unsigned int aux_rx) ··· 1502 1466 /** 1503 1467 * tb_dp_port_is_enabled() - Is DP adapter port enabled 1504 1468 * @port: DP adapter port to check 1469 + * 1470 + * Return: %true if DP port is enabled, %false otherwise. 1505 1471 */ 1506 1472 bool tb_dp_port_is_enabled(struct tb_port *port) 1507 1473 { ··· 1523 1485 * 1524 1486 * Once Hop IDs are programmed DP paths can be enabled or disabled by 1525 1487 * calling this function. 1488 + * 1489 + * Return: %0 on success, negative errno otherwise. 1526 1490 */ 1527 1491 int tb_dp_port_enable(struct tb_port *port, bool enable) 1528 1492 { ··· 1674 1634 * 1675 1635 * If the router is not enumerated does nothing. 1676 1636 * 1677 - * Returns %0 on success or negative errno in case of failure. 1637 + * Return: %0 on success, negative errno otherwise. 1678 1638 */ 1679 1639 int tb_switch_reset(struct tb_switch *sw) 1680 1640 { ··· 1710 1670 * @timeout_msec: Timeout in ms how long to wait 1711 1671 * 1712 1672 * Wait till the specified bits in specified offset reach specified value. 1713 - * Returns %0 in case of success, %-ETIMEDOUT if the @value was not reached 1714 - * within the given timeout or a negative errno in case of failure. 1673 + * 1674 + * Return: 1675 + * * %0 - On success. 1676 + * * %-ETIMEDOUT - If the @value was not reached within 1677 + * the given timeout. 1678 + * * Negative errno - In case of failure. 1715 1679 */ 1716 1680 int tb_switch_wait_for_bit(struct tb_switch *sw, u32 offset, u32 bit, 1717 1681 u32 value, int timeout_msec) ··· 1744 1700 * 1745 1701 * Also configures a sane plug_events_delay of 255ms. 1746 1702 * 1747 - * Return: Returns 0 on success or an error code on failure. 1703 + * Return: %0 on success, negative errno otherwise. 1748 1704 */ 1749 1705 static int tb_plug_events_active(struct tb_switch *sw, bool active) 1750 1706 { ··· 2450 2406 * separately. The returned switch should be released by calling 2451 2407 * tb_switch_put(). 2452 2408 * 2453 - * Return: Pointer to the allocated switch or ERR_PTR() in case of 2454 - * failure. 2409 + * Return: Pointer to &struct tb_switch or ERR_PTR() in case of failure. 2455 2410 */ 2456 2411 struct tb_switch *tb_switch_alloc(struct tb *tb, struct device *parent, 2457 2412 u64 route) ··· 2569 2526 * 2570 2527 * The returned switch must be released by calling tb_switch_put(). 2571 2528 * 2572 - * Return: Pointer to the allocated switch or ERR_PTR() in case of failure 2529 + * Return: Pointer to &struct tb_switch or ERR_PTR() in case of failure. 2573 2530 */ 2574 2531 struct tb_switch * 2575 2532 tb_switch_alloc_safe_mode(struct tb *tb, struct device *parent, u64 route) ··· 2605 2562 * connection manager to use. Can be called to the switch again after 2606 2563 * resume from low power states to re-initialize it. 2607 2564 * 2608 - * Return: %0 in case of success and negative errno in case of failure 2565 + * Return: %0 on success, negative errno otherwise. 2609 2566 */ 2610 2567 int tb_switch_configure(struct tb_switch *sw) 2611 2568 { ··· 2668 2625 * Needs to be called before any tunnels can be setup through the 2669 2626 * router. Can be called to any router. 2670 2627 * 2671 - * Returns %0 in success and negative errno otherwise. 2628 + * Return: %0 on success, negative errno otherwise. 2672 2629 */ 2673 2630 int tb_switch_configuration_valid(struct tb_switch *sw) 2674 2631 { ··· 2943 2900 * Connection manager can call this function to enable lane bonding of a 2944 2901 * switch. If conditions are correct and both switches support the feature, 2945 2902 * lanes are bonded. It is safe to call this to any switch. 2903 + * 2904 + * Return: %0 on success, negative errno otherwise. 2946 2905 */ 2947 2906 static int tb_switch_lane_bonding_enable(struct tb_switch *sw) 2948 2907 { ··· 2995 2950 * 2996 2951 * Disables lane bonding between @sw and parent. This can be called even 2997 2952 * if lanes were not bonded originally. 2953 + * 2954 + * Return: %0 on success, negative errno otherwise. 2998 2955 */ 2999 2956 static int tb_switch_lane_bonding_disable(struct tb_switch *sw) 3000 2957 { ··· 3121 3074 * 3122 3075 * Does nothing for host router. 3123 3076 * 3124 - * Returns %0 in case of success, negative errno otherwise. 3077 + * Return: %0 on success, negative errno otherwise. 3125 3078 */ 3126 3079 int tb_switch_set_link_width(struct tb_switch *sw, enum tb_link_width width) 3127 3080 { ··· 3192 3145 * 3193 3146 * It is recommended that this is called after lane bonding is enabled. 3194 3147 * 3195 - * Returns %0 on success and negative errno in case of error. 3148 + * Return: %0 on success and negative errno otherwise. 3196 3149 */ 3197 3150 int tb_switch_configure_link(struct tb_switch *sw) 3198 3151 { ··· 3292 3245 * exposed to the userspace when this function successfully returns. To 3293 3246 * remove and release the switch, call tb_switch_remove(). 3294 3247 * 3295 - * Return: %0 in case of success and negative errno in case of failure 3248 + * Return: %0 on success, negative errno otherwise. 3296 3249 */ 3297 3250 int tb_switch_add(struct tb_switch *sw) 3298 3251 { ··· 3514 3467 * suspend. If this is resume from system sleep, notifies PM core about the 3515 3468 * wakes occurred during suspend. Disables all wakes, except USB4 wake of 3516 3469 * upstream port for USB4 routers that shall be always enabled. 3470 + * 3471 + * Return: %0 on success, negative errno otherwise. 3517 3472 */ 3518 3473 int tb_switch_resume(struct tb_switch *sw, bool runtime) 3519 3474 { ··· 3666 3617 * @in: DP IN port 3667 3618 * 3668 3619 * Queries availability of DP resource for DP tunneling using switch 3669 - * specific means. Returns %true if resource is available. 3620 + * specific means. 3621 + * 3622 + * Return: %true if resource is available, %false otherwise. 3670 3623 */ 3671 3624 bool tb_switch_query_dp_resource(struct tb_switch *sw, struct tb_port *in) 3672 3625 { ··· 3684 3633 * 3685 3634 * Allocates DP resource for DP tunneling. The resource must be 3686 3635 * available for this to succeed (see tb_switch_query_dp_resource()). 3687 - * Returns %0 in success and negative errno otherwise. 3636 + * 3637 + * Return: %0 on success, negative errno otherwise. 3688 3638 */ 3689 3639 int tb_switch_alloc_dp_resource(struct tb_switch *sw, struct tb_port *in) 3690 3640 { ··· 3770 3718 * 3771 3719 * Returned switch has reference count increased so the caller needs to 3772 3720 * call tb_switch_put() when done with the switch. 3721 + * 3722 + * Return: Pointer to &struct tb_switch, %NULL if not found. 3773 3723 */ 3774 3724 struct tb_switch *tb_switch_find_by_link_depth(struct tb *tb, u8 link, u8 depth) 3775 3725 { ··· 3797 3743 * 3798 3744 * Returned switch has reference count increased so the caller needs to 3799 3745 * call tb_switch_put() when done with the switch. 3746 + * 3747 + * Return: Pointer to &struct tb_switch, %NULL if not found. 3800 3748 */ 3801 3749 struct tb_switch *tb_switch_find_by_uuid(struct tb *tb, const uuid_t *uuid) 3802 3750 { ··· 3823 3767 * 3824 3768 * Returned switch has reference count increased so the caller needs to 3825 3769 * call tb_switch_put() when done with the switch. 3770 + * 3771 + * Return: Pointer to &struct tb_switch, %NULL if not found. 3826 3772 */ 3827 3773 struct tb_switch *tb_switch_find_by_route(struct tb *tb, u64 route) 3828 3774 { ··· 3849 3791 * tb_switch_find_port() - return the first port of @type on @sw or NULL 3850 3792 * @sw: Switch to find the port from 3851 3793 * @type: Port type to look for 3794 + * 3795 + * Return: Pointer to &struct tb_port, %NULL if not found. 3852 3796 */ 3853 3797 struct tb_port *tb_switch_find_port(struct tb_switch *sw, 3854 3798 enum tb_port_type type) ··· 3919 3859 * entry to PCIe L1 state. Shall be called after the upstream PCIe tunnel 3920 3860 * was configured. Due to Intel platforms limitation, shall be called only 3921 3861 * for first hop switch. 3862 + * 3863 + * Return: %0 on success, negative errno otherwise. 3922 3864 */ 3923 3865 int tb_switch_pcie_l1_enable(struct tb_switch *sw) 3924 3866 { ··· 3955 3893 * connected to the type-C port. Call only after PCIe tunnel has been 3956 3894 * established. The function only does the connect if not done already 3957 3895 * so can be called several times for the same router. 3896 + * 3897 + * Return: %0 on success, negative errno otherwise. 3958 3898 */ 3959 3899 int tb_switch_xhci_connect(struct tb_switch *sw) 3960 3900 {
+20 -12
drivers/thunderbolt/tb.c
··· 225 225 return ret == -EOPNOTSUPP ? 0 : ret; 226 226 } 227 227 228 - /** 229 - * tb_disable_clx() - Disable CL states up to host router 230 - * @sw: Router to start 228 + /* 229 + * Disables CL states from @sw up to the host router. 231 230 * 232 - * Disables CL states from @sw up to the host router. Returns true if 233 - * any CL state were disabled. This can be used to figure out whether 234 - * the link was setup by us or the boot firmware so we don't 235 - * accidentally enable them if they were not enabled during discovery. 231 + * This can be used to figure out whether the link was setup by us or the 232 + * boot firmware so we don't accidentally enable them if they were not 233 + * enabled during discovery. 236 234 */ 237 235 static bool tb_disable_clx(struct tb_switch *sw) 238 236 { ··· 454 456 } 455 457 } 456 458 457 - /** 458 - * tb_find_unused_port() - return the first inactive port on @sw 459 - * @sw: Switch to find the port on 460 - * @type: Port type to look for 459 + /* 460 + * Returns the first inactive port on @sw. 461 461 */ 462 462 static struct tb_port *tb_find_unused_port(struct tb_switch *sw, 463 463 enum tb_port_type type) ··· 545 549 * from @src_port to @dst_port. Does not take USB3 tunnel starting from 546 550 * @src_port and ending on @src_port into account because that bandwidth is 547 551 * already included in as part of the "first hop" USB3 tunnel. 552 + * 553 + * Return: %0 on success, negative errno otherwise. 548 554 */ 549 555 static int tb_consumed_usb3_pcie_bandwidth(struct tb *tb, 550 556 struct tb_port *src_port, ··· 599 601 * If there is bandwidth reserved for any of the groups between 600 602 * @src_port and @dst_port (but not yet used) that is also taken into 601 603 * account in the returned consumed bandwidth. 604 + * 605 + * Return: %0 on success, negative errno otherwise. 602 606 */ 603 607 static int tb_consumed_dp_bandwidth(struct tb *tb, 604 608 struct tb_port *src_port, ··· 701 701 * single link at @port. If @include_asym is set then includes the 702 702 * additional banwdith if the links are transitioned into asymmetric to 703 703 * direction from @src_port to @dst_port. 704 + * 705 + * Return: %0 on success, negative errno otherwise. 704 706 */ 705 707 static int tb_maximum_bandwidth(struct tb *tb, struct tb_port *src_port, 706 708 struct tb_port *dst_port, struct tb_port *port, ··· 809 807 * If @include_asym is true then includes also bandwidth that can be 810 808 * added when the links are transitioned into asymmetric (but does not 811 809 * transition the links). 810 + * 811 + * Return: %0 on success, negative errno otherwise. 812 812 */ 813 813 static int tb_available_bandwidth(struct tb *tb, struct tb_port *src_port, 814 814 struct tb_port *dst_port, int *available_up, ··· 1033 1029 * (requested + currently consumed) on that link exceed @asym_threshold. 1034 1030 * 1035 1031 * Must be called with available >= requested over all links. 1032 + * 1033 + * Return: %0 on success, negative errno otherwise. 1036 1034 */ 1037 1035 static int tb_configure_asym(struct tb *tb, struct tb_port *src_port, 1038 1036 struct tb_port *dst_port, int requested_up, ··· 1141 1135 * Goes over each link from @src_port to @dst_port and tries to 1142 1136 * transition the link to symmetric if the currently consumed bandwidth 1143 1137 * allows and link asymmetric preference is ignored (if @keep_asym is %false). 1138 + * 1139 + * Return: %0 on success, negative errno otherwise. 1144 1140 */ 1145 1141 static int tb_configure_sym(struct tb *tb, struct tb_port *src_port, 1146 1142 struct tb_port *dst_port, bool keep_asym) ··· 3344 3336 if (!pci_is_pcie(pdev)) 3345 3337 continue; 3346 3338 if (pci_pcie_type(pdev) != PCI_EXP_TYPE_DOWNSTREAM || 3347 - !pdev->is_hotplug_bridge) 3339 + !pdev->is_pciehp) 3348 3340 continue; 3349 3341 3350 3342 link = device_link_add(&pdev->dev, &nhi->pdev->dev,
+29 -16
drivers/thunderbolt/tb.h
··· 324 324 }; 325 325 326 326 /** 327 - * tb_retimer: Thunderbolt retimer 327 + * struct tb_retimer - Thunderbolt retimer 328 328 * @dev: Device for the retimer 329 329 * @tb: Pointer to the domain the retimer belongs to 330 330 * @index: Retimer index facing the router USB4 port ··· 552 552 553 553 /** 554 554 * tb_upstream_port() - return the upstream port of a switch 555 + * @sw: Router 555 556 * 556 557 * Every switch has an upstream port (for the root switch it is the NHI). 557 558 * 558 559 * During switch alloc/init tb_upstream_port()->remote may be NULL, even for 559 560 * non root switches (on the NHI port remote is always NULL). 560 561 * 561 - * Return: Returns the upstream port of the switch. 562 + * Return: Pointer to &struct tb_port. 562 563 */ 563 564 static inline struct tb_port *tb_upstream_port(struct tb_switch *sw) 564 565 { ··· 570 569 * tb_is_upstream_port() - Is the port upstream facing 571 570 * @port: Port to check 572 571 * 573 - * Returns true if @port is upstream facing port. In case of dual link 574 - * ports both return true. 572 + * Return: %true if @port is upstream facing port. In case of dual link 573 + * ports, both return %true. 575 574 */ 576 575 static inline bool tb_is_upstream_port(const struct tb_port *port) 577 576 { ··· 614 613 * tb_port_has_remote() - Does the port have switch connected downstream 615 614 * @port: Port to check 616 615 * 617 - * Returns true only when the port is primary port and has remote set. 616 + * Return: %true only when the port is primary port and has remote set. 618 617 */ 619 618 static inline bool tb_port_has_remote(const struct tb_port *port) 620 619 { ··· 906 905 * tb_switch_downstream_port() - Return downstream facing port of parent router 907 906 * @sw: Device router pointer 908 907 * 909 - * Only call for device routers. Returns the downstream facing port of 910 - * the parent router. 908 + * Call only for device routers. 909 + * 910 + * Return: Pointer to &struct tb_port or %NULL in case of failure. 911 911 */ 912 912 static inline struct tb_port *tb_switch_downstream_port(struct tb_switch *sw) 913 913 { ··· 920 918 /** 921 919 * tb_switch_depth() - Returns depth of the connected router 922 920 * @sw: Router 921 + * 922 + * Return: Router depth level as a number. 923 923 */ 924 924 static inline int tb_switch_depth(const struct tb_switch *sw) 925 925 { ··· 1014 1010 * is handling @sw this function can be called. It is valid to call this 1015 1011 * after tb_switch_alloc() and tb_switch_configure() has been called 1016 1012 * (latter only for SW CM case). 1013 + * 1014 + * Return: %true if switch is handled by ICM, %false if handled by 1015 + * software CM. 1017 1016 */ 1018 1017 static inline bool tb_switch_is_icm(const struct tb_switch *sw) 1019 1018 { ··· 1044 1037 * 1045 1038 * Checks if given router TMU mode is configured to @mode. Note the 1046 1039 * router TMU might not be enabled to this mode. 1040 + * 1041 + * Return: %true if TMU mode is equal to @mode, %false otherwise. 1047 1042 */ 1048 1043 static inline bool tb_switch_tmu_is_configured(const struct tb_switch *sw, 1049 1044 enum tb_switch_tmu_mode mode) ··· 1057 1048 * tb_switch_tmu_is_enabled() - Checks if the specified TMU mode is enabled 1058 1049 * @sw: Router whose TMU mode to check 1059 1050 * 1060 - * Return true if hardware TMU configuration matches the requested 1061 - * configuration (and is not %TB_SWITCH_TMU_MODE_OFF). 1051 + * Return: %true if hardware TMU configuration matches the requested 1052 + * configuration (and is not %TB_SWITCH_TMU_MODE_OFF), %false otherwise. 1062 1053 */ 1063 1054 static inline bool tb_switch_tmu_is_enabled(const struct tb_switch *sw) 1064 1055 { ··· 1078 1069 * @clx: The CLx states to check for 1079 1070 * 1080 1071 * Checks if the specified CLx is enabled on the router upstream link. 1081 - * Returns true if any of the given states is enabled. 1082 1072 * 1083 1073 * Not applicable for a host router. 1074 + * 1075 + * Return: %true if any of the given states is enabled, %false otherwise. 1084 1076 */ 1085 1077 static inline bool tb_switch_clx_is_enabled(const struct tb_switch *sw, 1086 1078 unsigned int clx) ··· 1113 1103 * @src: Source adapter 1114 1104 * @dst: Destination adapter 1115 1105 * 1116 - * Returns %true only if the specified path from source adapter (@src) 1106 + * Return: %true only if the specified path from source adapter (@src) 1117 1107 * to destination adapter (@dst) is directed downstream. 1118 1108 */ 1119 1109 static inline bool ··· 1242 1232 1243 1233 /** 1244 1234 * tb_downstream_route() - get route to downstream switch 1235 + * @port: Port to check 1245 1236 * 1246 1237 * Port must not be the upstream port (otherwise a loop is created). 1247 1238 * 1248 - * Return: Returns a route to the switch behind @port. 1239 + * Return: Route to the switch behind @port. 1249 1240 */ 1250 1241 static inline u64 tb_downstream_route(struct tb_port *port) 1251 1242 { ··· 1274 1263 * tb_xdomain_downstream_port() - Return downstream facing port of parent router 1275 1264 * @xd: Xdomain pointer 1276 1265 * 1277 - * Returns the downstream port the XDomain is connected to. 1266 + * Return: Pointer to &struct tb_port or %NULL in case of failure. 1278 1267 */ 1279 1268 static inline struct tb_port *tb_xdomain_downstream_port(struct tb_xdomain *xd) 1280 1269 { ··· 1302 1291 * usb4_switch_version() - Returns USB4 version of the router 1303 1292 * @sw: Router to check 1304 1293 * 1305 - * Returns major version of USB4 router (%1 for v1, %2 for v2 and so 1294 + * Return: Major version of USB4 router (%1 for v1, %2 for v2 and so 1306 1295 * on). Can be called to pre-USB4 router too and in that case returns %0. 1307 1296 */ 1308 1297 static inline unsigned int usb4_switch_version(const struct tb_switch *sw) ··· 1314 1303 * tb_switch_is_usb4() - Is the switch USB4 compliant 1315 1304 * @sw: Switch to check 1316 1305 * 1317 - * Returns true if the @sw is USB4 compliant router, false otherwise. 1306 + * Return: %true if the @sw is USB4 compliant router, %false otherwise. 1318 1307 */ 1319 1308 static inline bool tb_switch_is_usb4(const struct tb_switch *sw) 1320 1309 { ··· 1366 1355 int usb4_port_asym_start(struct tb_port *port); 1367 1356 1368 1357 /** 1369 - * enum tb_sb_target - Sideband transaction target 1358 + * enum usb4_sb_target - Sideband transaction target 1370 1359 * @USB4_SB_TARGET_ROUTER: Target is the router itself 1371 1360 * @USB4_SB_TARGET_PARTNER: Target is partner 1372 1361 * @USB4_SB_TARGET_RETIMER: Target is retimer ··· 1411 1400 * @voltage_time_offset: Offset for voltage / time for software margining 1412 1401 * @optional_voltage_offset_range: Enable optional extended voltage range 1413 1402 * @right_high: %false if left/low margin test is performed, %true if right/high 1403 + * @upper_eye: %true if margin test is done on upper eye, %false if done on 1404 + * lower eye 1414 1405 * @time: %true if time margining is used instead of voltage 1415 1406 */ 1416 1407 struct usb4_port_margining_params {
+13 -3
drivers/thunderbolt/tmu.c
··· 405 405 * This function must be called before other TMU related functions to 406 406 * makes the internal structures are filled in correctly. Does not 407 407 * change any hardware configuration. 408 + * 409 + * Return: %0 on success, negative errno otherwise. 408 410 */ 409 411 int tb_switch_tmu_init(struct tb_switch *sw) 410 412 { ··· 441 439 * @sw: Switch whose time to update 442 440 * 443 441 * Updates switch local time using time posting procedure. 442 + * 443 + * Return: %0 on success, negative errno otherwise. 444 444 */ 445 445 int tb_switch_tmu_post_time(struct tb_switch *sw) 446 446 { ··· 559 555 * @sw: Switch whose TMU to disable 560 556 * 561 557 * Turns off TMU of @sw if it is enabled. If not enabled does nothing. 558 + * 559 + * Return: %0 on success, negative errno otherwise. 562 560 */ 563 561 int tb_switch_tmu_disable(struct tb_switch *sw) 564 562 { ··· 944 938 * Enables TMU of a router to be in uni-directional Normal/HiFi or 945 939 * bi-directional HiFi mode. Calling tb_switch_tmu_configure() is 946 940 * required before calling this function. 941 + * 942 + * Return: %0 on success, negative errno otherwise. 947 943 */ 948 944 int tb_switch_tmu_enable(struct tb_switch *sw) 949 945 { ··· 1025 1017 * Selects the TMU mode that is enabled when tb_switch_tmu_enable() is 1026 1018 * next called. 1027 1019 * 1028 - * Returns %0 in success and negative errno otherwise. Specifically 1029 - * returns %-EOPNOTSUPP if the requested mode is not possible (not 1030 - * supported by the router and/or topology). 1020 + * Return: 1021 + * * %0 - On success. 1022 + * * %-EOPNOTSUPP - If the requested mode is not possible (not supported by 1023 + * the router and/or topology). 1024 + * * Negative errno - Another error occurred. 1031 1025 */ 1032 1026 int tb_switch_tmu_configure(struct tb_switch *sw, enum tb_switch_tmu_mode mode) 1033 1027 {
+56 -34
drivers/thunderbolt/tunnel.c
··· 121 121 * @port: Lane adapter to check 122 122 * @max_dp_streams: If non-%NULL stores maximum number of simultaneous DP 123 123 * streams possible through this lane adapter 124 + * 125 + * Return: Number of available credits. 124 126 */ 125 127 static unsigned int tb_available_credits(const struct tb_port *port, 126 128 size_t *max_dp_streams) ··· 417 415 * @alloc_hopid: Allocate HopIDs from visited ports 418 416 * 419 417 * If @down adapter is active, follows the tunnel to the PCIe upstream 420 - * adapter and back. Returns the discovered tunnel or %NULL if there was 421 - * no tunnel. 418 + * adapter and back. 419 + * 420 + * Return: Pointer to &struct tb_tunnel or %NULL if there was no tunnel. 422 421 */ 423 422 struct tb_tunnel *tb_tunnel_discover_pci(struct tb *tb, struct tb_port *down, 424 423 bool alloc_hopid) ··· 499 496 * Allocate a PCI tunnel. The ports must be of type TB_TYPE_PCIE_UP and 500 497 * TB_TYPE_PCIE_DOWN. 501 498 * 502 - * Return: Returns a tb_tunnel on success or NULL on failure. 499 + * Return: Pointer to @struct tb_tunnel or %NULL on failure. 503 500 */ 504 501 struct tb_tunnel *tb_tunnel_alloc_pci(struct tb *tb, struct tb_port *up, 505 502 struct tb_port *down) ··· 546 543 * 547 544 * Can be called to any connected lane 0 adapter to find out how much 548 545 * bandwidth needs to be left in reserve for possible PCIe bulk traffic. 549 - * Returns true if there is something to be reserved and writes the 550 - * amount to @reserved_down/@reserved_up. Otherwise returns false and 551 - * does not touch the parameters. 546 + * 547 + * Return: 548 + * * %true - If there is something to be reserved. Writes the amount to 549 + * @reserved_down/@reserved_up. 550 + * * %false - Nothing to be reserved. Leaves @reserved_down/@reserved_up 551 + * unmodified. 552 552 */ 553 553 bool tb_tunnel_reserved_pci(struct tb_port *port, int *reserved_up, 554 554 int *reserved_down) ··· 1079 1073 1080 1074 if (tunnel->callback) 1081 1075 tunnel->callback(tunnel, tunnel->callback_data); 1076 + tb_tunnel_put(tunnel); 1082 1077 } 1083 1078 1084 1079 static int tb_dp_dprx_start(struct tb_tunnel *tunnel) ··· 1107 1100 if (tunnel->dprx_started) { 1108 1101 tunnel->dprx_started = false; 1109 1102 tunnel->dprx_canceled = true; 1110 - cancel_delayed_work(&tunnel->dprx_work); 1111 - tb_tunnel_put(tunnel); 1103 + if (cancel_delayed_work(&tunnel->dprx_work)) 1104 + tb_tunnel_put(tunnel); 1112 1105 } 1113 1106 } 1114 1107 ··· 1158 1151 * @tunnel: DP tunnel to check 1159 1152 * @max_bw_rounded: Maximum bandwidth in Mb/s rounded up to the next granularity 1160 1153 * 1161 - * Returns maximum possible bandwidth for this tunnel in Mb/s. 1154 + * Return: Maximum possible bandwidth for this tunnel in Mb/s, negative errno 1155 + * in case of failure. 1162 1156 */ 1163 1157 static int tb_dp_bandwidth_mode_maximum_bandwidth(struct tb_tunnel *tunnel, 1164 1158 int *max_bw_rounded) ··· 1555 1547 * and back. Returns the discovered tunnel or %NULL if there was no 1556 1548 * tunnel. 1557 1549 * 1558 - * Return: DP tunnel or %NULL if no tunnel found. 1550 + * Return: Pointer to &struct tb_tunnel or %NULL if no tunnel found. 1559 1551 */ 1560 1552 struct tb_tunnel *tb_tunnel_discover_dp(struct tb *tb, struct tb_port *in, 1561 1553 bool alloc_hopid) ··· 1656 1648 * successful (or if it returns %false there was some sort of issue). 1657 1649 * The @callback is called without @tb->lock held. 1658 1650 * 1659 - * Return: Returns a tb_tunnel on success or &NULL on failure. 1651 + * Return: Pointer to @struct tb_tunnel or %NULL in case of failure. 1660 1652 */ 1661 1653 struct tb_tunnel *tb_tunnel_alloc_dp(struct tb *tb, struct tb_port *in, 1662 1654 struct tb_port *out, int link_nr, ··· 1869 1861 * @receive_ring: NHI ring number used to receive packets from the 1870 1862 * other domain. Set to %-1 if RX path is not needed. 1871 1863 * 1872 - * Return: Returns a tb_tunnel on success or NULL on failure. 1864 + * Return: Pointer to @struct tb_tunnel or %NULL in case of failure. 1873 1865 */ 1874 1866 struct tb_tunnel *tb_tunnel_alloc_dma(struct tb *tb, struct tb_port *nhi, 1875 1867 struct tb_port *dst, int transmit_path, ··· 1946 1938 * 1947 1939 * This function can be used to match specific DMA tunnel, if there are 1948 1940 * multiple DMA tunnels going through the same XDomain connection. 1949 - * Returns true if there is match and false otherwise. 1941 + * 1942 + * Return: %true if there is a match, %false otherwise. 1950 1943 */ 1951 1944 bool tb_tunnel_match_dma(const struct tb_tunnel *tunnel, int transmit_path, 1952 1945 int transmit_ring, int receive_path, int receive_ring) ··· 2169 2160 * @alloc_hopid: Allocate HopIDs from visited ports 2170 2161 * 2171 2162 * If @down adapter is active, follows the tunnel to the USB3 upstream 2172 - * adapter and back. Returns the discovered tunnel or %NULL if there was 2173 - * no tunnel. 2163 + * adapter and back. 2164 + * 2165 + * Return: Pointer to &struct tb_tunnel or %NULL if there was no tunnel. 2174 2166 */ 2175 2167 struct tb_tunnel *tb_tunnel_discover_usb3(struct tb *tb, struct tb_port *down, 2176 2168 bool alloc_hopid) ··· 2276 2266 * Allocate an USB3 tunnel. The ports must be of type @TB_TYPE_USB3_UP and 2277 2267 * @TB_TYPE_USB3_DOWN. 2278 2268 * 2279 - * Return: Returns a tb_tunnel on success or %NULL on failure. 2269 + * Return: Pointer to @struct tb_tunnel or %NULL in case of failure. 2280 2270 */ 2281 2271 struct tb_tunnel *tb_tunnel_alloc_usb3(struct tb *tb, struct tb_port *up, 2282 2272 struct tb_port *down, int max_up, ··· 2347 2337 /** 2348 2338 * tb_tunnel_is_invalid - check whether an activated path is still valid 2349 2339 * @tunnel: Tunnel to check 2340 + * 2341 + * Return: %true if path is valid, %false otherwise. 2350 2342 */ 2351 2343 bool tb_tunnel_is_invalid(struct tb_tunnel *tunnel) 2352 2344 { ··· 2367 2355 * tb_tunnel_activate() - activate a tunnel 2368 2356 * @tunnel: Tunnel to activate 2369 2357 * 2370 - * Return: 0 on success and negative errno in case if failure. 2371 - * Specifically returns %-EINPROGRESS if the tunnel activation is still 2372 - * in progress (that's for DP tunnels to complete DPRX capabilities 2373 - * read). 2358 + * Return: 2359 + * * %0 - On success. 2360 + * * %-EINPROGRESS - If the tunnel activation is still in progress (that's 2361 + * for DP tunnels to complete DPRX capabilities read). 2362 + * * Negative errno - Another error occurred. 2374 2363 */ 2375 2364 int tb_tunnel_activate(struct tb_tunnel *tunnel) 2376 2365 { ··· 2451 2438 * @tunnel: Tunnel to check 2452 2439 * @port: Port to check 2453 2440 * 2454 - * Returns true if @tunnel goes through @port (direction does not matter), 2455 - * false otherwise. 2441 + * Return: %true if @tunnel goes through @port (direction does not matter), 2442 + * %false otherwise. 2456 2443 */ 2457 2444 bool tb_tunnel_port_on_path(const struct tb_tunnel *tunnel, 2458 2445 const struct tb_port *port) ··· 2482 2469 * @max_up: Maximum upstream bandwidth in Mb/s 2483 2470 * @max_down: Maximum downstream bandwidth in Mb/s 2484 2471 * 2485 - * Returns maximum possible bandwidth this tunnel can go if not limited 2486 - * by other bandwidth clients. If the tunnel does not support this 2487 - * returns %-EOPNOTSUPP. 2472 + * Return: 2473 + * * Maximum possible bandwidth this tunnel can support if not 2474 + * limited by other bandwidth clients. 2475 + * * %-EOPNOTSUPP - If the tunnel does not support this function. 2476 + * * %-ENOTCONN - If the tunnel is not active. 2488 2477 */ 2489 2478 int tb_tunnel_maximum_bandwidth(struct tb_tunnel *tunnel, int *max_up, 2490 2479 int *max_down) ··· 2506 2491 * @allocated_down: Currently allocated downstream bandwidth in Mb/s is 2507 2492 * stored here 2508 2493 * 2509 - * Returns the bandwidth allocated for the tunnel. This may be higher 2510 - * than what the tunnel actually consumes. 2494 + * Return: 2495 + * * Bandwidth allocated for the tunnel. This may be higher than what the 2496 + * tunnel actually consumes. 2497 + * * %-EOPNOTSUPP - If the tunnel does not support this function. 2498 + * * %-ENOTCONN - If the tunnel is not active. 2499 + * * Negative errno - Another error occurred. 2511 2500 */ 2512 2501 int tb_tunnel_allocated_bandwidth(struct tb_tunnel *tunnel, int *allocated_up, 2513 2502 int *allocated_down) ··· 2531 2512 * @alloc_up: New upstream bandwidth in Mb/s 2532 2513 * @alloc_down: New downstream bandwidth in Mb/s 2533 2514 * 2534 - * Tries to change tunnel bandwidth allocation. If succeeds returns %0 2535 - * and updates @alloc_up and @alloc_down to that was actually allocated 2536 - * (it may not be the same as passed originally). Returns negative errno 2537 - * in case of failure. 2515 + * Tries to change tunnel bandwidth allocation. 2516 + * 2517 + * Return: 2518 + * * %0 - On success. Updates @alloc_up and @alloc_down to values that were 2519 + * actually allocated (it may not be the same as passed originally). 2520 + * * Negative errno - In case of failure. 2538 2521 */ 2539 2522 int tb_tunnel_alloc_bandwidth(struct tb_tunnel *tunnel, int *alloc_up, 2540 2523 int *alloc_down) ··· 2567 2546 * Can be %NULL. 2568 2547 * 2569 2548 * Stores the amount of isochronous bandwidth @tunnel consumes in 2570 - * @consumed_up and @consumed_down. In case of success returns %0, 2571 - * negative errno otherwise. 2549 + * @consumed_up and @consumed_down. 2550 + * 2551 + * Return: %0 on success, negative errno otherwise. 2572 2552 */ 2573 2553 int tb_tunnel_consumed_bandwidth(struct tb_tunnel *tunnel, int *consumed_up, 2574 2554 int *consumed_down) ··· 2607 2585 * If tunnel supports dynamic bandwidth management (USB3 tunnels at the 2608 2586 * moment) this function makes it to release all the unused bandwidth. 2609 2587 * 2610 - * Returns %0 in case of success and negative errno otherwise. 2588 + * Return: %0 on success, negative errno otherwise. 2611 2589 */ 2612 2590 int tb_tunnel_release_unused_bandwidth(struct tb_tunnel *tunnel) 2613 2591 {
+5 -4
drivers/thunderbolt/tunnel.h
··· 142 142 * tb_tunnel_is_active() - Is tunnel fully activated 143 143 * @tunnel: Tunnel to check 144 144 * 145 - * Returns %true if @tunnel is fully activated. For other than DP 146 - * tunnels this is pretty much once tb_tunnel_activate() returns 147 - * successfully. However, for DP tunnels this returns %true only once the 148 - * DPRX capabilities read has been issued successfully. 145 + * Return: %true if @tunnel is fully activated. 146 + * 147 + * Note for DP tunnels this returns %true only once the DPRX capabilities 148 + * read has been issued successfully. For other tunnels, this function 149 + * returns %true pretty much once tb_tunnel_activate() returns successfully. 149 150 */ 150 151 static inline bool tb_tunnel_is_active(const struct tb_tunnel *tunnel) 151 152 {
+236 -110
drivers/thunderbolt/usb4.c
··· 9 9 10 10 #include <linux/delay.h> 11 11 #include <linux/ktime.h> 12 + #include <linux/string_choices.h> 12 13 #include <linux/units.h> 13 14 14 15 #include "sb_regs.h" ··· 173 172 return; 174 173 175 174 tb_sw_dbg(sw, "PCIe wake: %s, USB3 wake: %s\n", 176 - (val & ROUTER_CS_6_WOPS) ? "yes" : "no", 177 - (val & ROUTER_CS_6_WOUS) ? "yes" : "no"); 175 + str_yes_no(val & ROUTER_CS_6_WOPS), 176 + str_yes_no(val & ROUTER_CS_6_WOUS)); 178 177 179 178 wakeup = val & (ROUTER_CS_6_WOPS | ROUTER_CS_6_WOUS); 180 179 } ··· 192 191 break; 193 192 194 193 tb_port_dbg(port, "USB4 wake: %s, connection wake: %s, disconnection wake: %s\n", 195 - (val & PORT_CS_18_WOU4S) ? "yes" : "no", 196 - (val & PORT_CS_18_WOCS) ? "yes" : "no", 197 - (val & PORT_CS_18_WODS) ? "yes" : "no"); 194 + str_yes_no(val & PORT_CS_18_WOU4S), 195 + str_yes_no(val & PORT_CS_18_WOCS), 196 + str_yes_no(val & PORT_CS_18_WODS)); 198 197 199 198 wakeup_usb4 = val & (PORT_CS_18_WOU4S | PORT_CS_18_WOCS | 200 199 PORT_CS_18_WODS); ··· 237 236 * 238 237 * This does not set the configuration valid bit of the router. To do 239 238 * that call usb4_switch_configuration_valid(). 239 + * 240 + * Return: %0 on success, negative errno otherwise. 240 241 */ 241 242 int usb4_switch_setup(struct tb_switch *sw) 242 243 { ··· 263 260 tbt3 = !(val & ROUTER_CS_6_TNS); 264 261 265 262 tb_sw_dbg(sw, "TBT3 support: %s, xHCI: %s\n", 266 - tbt3 ? "yes" : "no", xhci ? "yes" : "no"); 263 + str_yes_no(tbt3), str_yes_no(xhci)); 267 264 268 265 ret = tb_sw_read(sw, &val, TB_CFG_SWITCH, ROUTER_CS_5, 1); 269 266 if (ret) ··· 306 303 * usb4_switch_setup() has been called. Can be called to host and device 307 304 * routers (does nothing for the latter). 308 305 * 309 - * Returns %0 in success and negative errno otherwise. 306 + * Return: %0 on success, negative errno otherwise. 310 307 */ 311 308 int usb4_switch_configuration_valid(struct tb_switch *sw) 312 309 { ··· 336 333 * @uid: UID is stored here 337 334 * 338 335 * Reads 64-bit UID from USB4 router config space. 336 + * 337 + * Return: %0 on success, negative errno otherwise. 339 338 */ 340 339 int usb4_switch_read_uid(struct tb_switch *sw, u64 *uid) 341 340 { ··· 375 370 * Uses USB4 router operations to read router DROM. For devices this 376 371 * should always work but for hosts it may return %-EOPNOTSUPP in which 377 372 * case the host router does not have DROM. 373 + * 374 + * Return: %0 on success, negative errno otherwise. 378 375 */ 379 376 int usb4_switch_drom_read(struct tb_switch *sw, unsigned int address, void *buf, 380 377 size_t size) ··· 391 384 * 392 385 * Checks whether conditions are met so that lane bonding can be 393 386 * established with the upstream router. Call only for device routers. 387 + * 388 + * Return: %true if lane bonding is possible, %false otherwise. 394 389 */ 395 390 bool usb4_switch_lane_bonding_possible(struct tb_switch *sw) 396 391 { ··· 415 406 * @runtime: Wake is being programmed during system runtime 416 407 * 417 408 * Enables/disables router to wake up from sleep. 409 + * 410 + * Return: %0 on success, negative errno otherwise. 418 411 */ 419 412 int usb4_switch_set_wake(struct tb_switch *sw, unsigned int flags, bool runtime) 420 413 { ··· 494 483 * usb4_switch_set_sleep() - Prepare the router to enter sleep 495 484 * @sw: USB4 router 496 485 * 497 - * Sets sleep bit for the router. Returns when the router sleep ready 486 + * Sets sleep bit for the router and waits until router sleep ready 498 487 * bit has been asserted. 488 + * 489 + * Return: %0 on success, negative errno otherwise. 499 490 */ 500 491 int usb4_switch_set_sleep(struct tb_switch *sw) 501 492 { ··· 523 510 * usb4_switch_nvm_sector_size() - Return router NVM sector size 524 511 * @sw: USB4 router 525 512 * 526 - * If the router supports NVM operations this function returns the NVM 527 - * sector size in bytes. If NVM operations are not supported returns 528 - * %-EOPNOTSUPP. 513 + * Return: 514 + * * NVM sector size in bytes if router supports NVM operations. 515 + * * %-EOPNOTSUPP - If router does not support NVM operations. 516 + * * Negative errno - Another error occurred. 529 517 */ 530 518 int usb4_switch_nvm_sector_size(struct tb_switch *sw) 531 519 { ··· 573 559 * @buf: Read data is placed here 574 560 * @size: How many bytes to read 575 561 * 576 - * Reads NVM contents of the router. If NVM is not supported returns 577 - * %-EOPNOTSUPP. 562 + * Reads NVM contents of the router. 563 + * 564 + * Return: 565 + * * %0 - Read completed successfully. 566 + * * %-EOPNOTSUPP - NVM not supported. 567 + * * Negative errno - Another error occurred. 578 568 */ 579 569 int usb4_switch_nvm_read(struct tb_switch *sw, unsigned int address, void *buf, 580 570 size_t size) ··· 595 577 * Explicitly sets NVM write offset. Normally when writing to NVM this 596 578 * is done automatically by usb4_switch_nvm_write(). 597 579 * 598 - * Returns %0 in success and negative errno if there was a failure. 580 + * Return: %0 on success, negative errno otherwise. 599 581 */ 600 582 int usb4_switch_nvm_set_offset(struct tb_switch *sw, unsigned int address) 601 583 { ··· 637 619 * @buf: Pointer to the data to write 638 620 * @size: Size of @buf in bytes 639 621 * 640 - * Writes @buf to the router NVM using USB4 router operations. If NVM 641 - * write is not supported returns %-EOPNOTSUPP. 622 + * Writes @buf to the router NVM using USB4 router operations. 623 + * 624 + * Return: 625 + * * %0 - Write completed successfully. 626 + * * %-EOPNOTSUPP - NVM write not supported. 627 + * * Negative errno - Another error occurred. 642 628 */ 643 629 int usb4_switch_nvm_write(struct tb_switch *sw, unsigned int address, 644 630 const void *buf, size_t size) ··· 664 642 * After the new NVM has been written via usb4_switch_nvm_write(), this 665 643 * function triggers NVM authentication process. The router gets power 666 644 * cycled and if the authentication is successful the new NVM starts 667 - * running. In case of failure returns negative errno. 645 + * running. 668 646 * 669 647 * The caller should call usb4_switch_nvm_authenticate_status() to read 670 648 * the status of the authentication after power cycle. It should be the 671 649 * first router operation to avoid the status being lost. 650 + * 651 + * Return: %0 on success, negative errno otherwise. 672 652 */ 673 653 int usb4_switch_nvm_authenticate(struct tb_switch *sw) 674 654 { ··· 698 674 * @status: Status code of the operation 699 675 * 700 676 * The function checks if there is status available from the last NVM 701 - * authenticate router operation. If there is status then %0 is returned 702 - * and the status code is placed in @status. Returns negative errno in case 703 - * of failure. 677 + * authenticate router operation. 704 678 * 705 679 * Must be called before any other router operation. 680 + * 681 + * Return: 682 + * * %0 - If there is status. Status code is placed in @status. 683 + * * Negative errno - Failure occurred. 706 684 */ 707 685 int usb4_switch_nvm_authenticate_status(struct tb_switch *sw, u32 *status) 708 686 { ··· 748 722 * allocation fields accordingly. Specifically @sw->credits_allocation 749 723 * is set to %true if these parameters can be used in tunneling. 750 724 * 751 - * Returns %0 on success and negative errno otherwise. 725 + * Return: %0 on success, negative errno otherwise. 752 726 */ 753 727 int usb4_switch_credits_init(struct tb_switch *sw) 754 728 { ··· 887 861 * @in: DP IN adapter 888 862 * 889 863 * For DP tunneling this function can be used to query availability of 890 - * DP IN resource. Returns true if the resource is available for DP 891 - * tunneling, false otherwise. 864 + * DP IN resource. 865 + * 866 + * Return: %true if the resource is available for DP tunneling, %false 867 + * otherwise. 892 868 */ 893 869 bool usb4_switch_query_dp_resource(struct tb_switch *sw, struct tb_port *in) 894 870 { ··· 918 890 * @in: DP IN adapter 919 891 * 920 892 * Allocates DP IN resource for DP tunneling using USB4 router 921 - * operations. If the resource was allocated returns %0. Otherwise 922 - * returns negative errno, in particular %-EBUSY if the resource is 923 - * already allocated. 893 + * operations. 894 + * 895 + * Return: 896 + * * %0 - Resource allocated successfully. 897 + * * %-EBUSY - Resource is already allocated. 898 + * * Negative errno - Other failure occurred. 924 899 */ 925 900 int usb4_switch_alloc_dp_resource(struct tb_switch *sw, struct tb_port *in) 926 901 { ··· 947 916 * @in: DP IN adapter 948 917 * 949 918 * Releases the previously allocated DP IN resource. 919 + * 920 + * Return: %0 on success, negative errno otherwise. 950 921 */ 951 922 int usb4_switch_dealloc_dp_resource(struct tb_switch *sw, struct tb_port *in) 952 923 { ··· 1004 971 * downstream adapters where the PCIe topology is extended. This 1005 972 * function returns the corresponding downstream PCIe adapter or %NULL 1006 973 * if no such mapping was possible. 974 + * 975 + * Return: Pointer to &struct tb_port or %NULL if not found. 1007 976 */ 1008 977 struct tb_port *usb4_switch_map_pcie_down(struct tb_switch *sw, 1009 978 const struct tb_port *port) ··· 1037 1002 * downstream adapters where the USB 3.x topology is extended. This 1038 1003 * function returns the corresponding downstream USB 3.x adapter or 1039 1004 * %NULL if no such mapping was possible. 1005 + * 1006 + * Return: Pointer to &struct tb_port or %NULL if not found. 1040 1007 */ 1041 1008 struct tb_port *usb4_switch_map_usb3_down(struct tb_switch *sw, 1042 1009 const struct tb_port *port) ··· 1068 1031 * For USB4 router finds all USB4 ports and registers devices for each. 1069 1032 * Can be called to any router. 1070 1033 * 1071 - * Return %0 in case of success and negative errno in case of failure. 1034 + * Return: %0 on success, negative errno otherwise. 1072 1035 */ 1073 1036 int usb4_switch_add_ports(struct tb_switch *sw) 1074 1037 { ··· 1121 1084 * 1122 1085 * Unlocks USB4 downstream port so that the connection manager can 1123 1086 * access the router below this port. 1087 + * 1088 + * Return: %0 on success, negative errno otherwise. 1124 1089 */ 1125 1090 int usb4_port_unlock(struct tb_port *port) 1126 1091 { ··· 1143 1104 * 1144 1105 * Enables hot plug events on a given port. This is only intended 1145 1106 * to be used on lane, DP-IN, and DP-OUT adapters. 1107 + * 1108 + * Return: %0 on success, negative errno otherwise. 1146 1109 */ 1147 1110 int usb4_port_hotplug_enable(struct tb_port *port) 1148 1111 { ··· 1164 1123 * @port: USB4 port to reset 1165 1124 * 1166 1125 * Issues downstream port reset to @port. 1126 + * 1127 + * Return: %0 on success, negative errno otherwise. 1167 1128 */ 1168 1129 int usb4_port_reset(struct tb_port *port) 1169 1130 { ··· 1227 1184 * @port: USB4 router 1228 1185 * 1229 1186 * Sets the USB4 link to be configured for power management purposes. 1187 + * 1188 + * Return: %0 on success, negative errno otherwise. 1230 1189 */ 1231 1190 int usb4_port_configure(struct tb_port *port) 1232 1191 { ··· 1240 1195 * @port: USB4 router 1241 1196 * 1242 1197 * Sets the USB4 link to be unconfigured for power management purposes. 1198 + * 1199 + * Return: %0 on success, negative errno otherwise. 1243 1200 */ 1244 1201 void usb4_port_unconfigure(struct tb_port *port) 1245 1202 { ··· 1276 1229 * @xd: XDomain that is connected to the port 1277 1230 * 1278 1231 * Marks the USB4 port as being connected to another host and updates 1279 - * the link type. Returns %0 in success and negative errno in failure. 1232 + * the link type. 1233 + * 1234 + * Return: %0 on success, negative errno otherwise. 1280 1235 */ 1281 1236 int usb4_port_configure_xdomain(struct tb_port *port, struct tb_xdomain *xd) 1282 1237 { ··· 1348 1299 * @size: Size of @buf 1349 1300 * 1350 1301 * Reads data from sideband register @reg and copies it into @buf. 1351 - * Returns %0 in case of success and negative errno in case of failure. 1302 + * 1303 + * Return: %0 on success, negative errno otherwise. 1352 1304 */ 1353 1305 int usb4_port_sb_read(struct tb_port *port, enum usb4_sb_target target, u8 index, 1354 1306 u8 reg, void *buf, u8 size) ··· 1400 1350 * @buf: Data to write 1401 1351 * @size: Size of @buf 1402 1352 * 1403 - * Writes @buf to sideband register @reg. Returns %0 in case of success 1404 - * and negative errno in case of failure. 1353 + * Writes @buf to sideband register @reg. 1354 + * 1355 + * Return: %0 on success, negative errno otherwise. 1405 1356 */ 1406 1357 int usb4_port_sb_write(struct tb_port *port, enum usb4_sb_target target, 1407 1358 u8 index, u8 reg, const void *buf, u8 size) ··· 1519 1468 * port does not react on hotplug events anymore. This needs to be 1520 1469 * called before retimer access is done when the USB4 links is not up. 1521 1470 * 1522 - * Returns %0 in case of success and negative errno if there was an 1523 - * error. 1471 + * Return: %0 on success, negative errno otherwise. 1524 1472 */ 1525 1473 int usb4_port_router_offline(struct tb_port *port) 1526 1474 { ··· 1531 1481 * @port: USB4 port 1532 1482 * 1533 1483 * Makes the USB4 port functional again. 1484 + * 1485 + * Return: %0 on success, negative errno otherwise. 1534 1486 */ 1535 1487 int usb4_port_router_online(struct tb_port *port) 1536 1488 { ··· 1544 1492 * @port: USB4 port 1545 1493 * 1546 1494 * This forces the USB4 port to send broadcast RT transaction which 1547 - * makes the retimers on the link to assign index to themselves. Returns 1548 - * %0 in case of success and negative errno if there was an error. 1495 + * makes the retimers on the link assign index to themselves. 1496 + * 1497 + * Return: %0 on success, negative errno otherwise. 1549 1498 */ 1550 1499 int usb4_port_enumerate_retimers(struct tb_port *port) 1551 1500 { ··· 1563 1510 * 1564 1511 * PORT_CS_18_CPS bit reflects if the link supports CLx including 1565 1512 * active cables (if connected on the link). 1513 + * 1514 + * Return: %true if Clx is supported, %false otherwise. 1566 1515 */ 1567 1516 bool usb4_port_clx_supported(struct tb_port *port) 1568 1517 { ··· 1583 1528 * usb4_port_asym_supported() - If the port supports asymmetric link 1584 1529 * @port: USB4 port 1585 1530 * 1586 - * Checks if the port and the cable supports asymmetric link and returns 1587 - * %true in that case. 1531 + * Checks if the port and the cable support asymmetric link. 1532 + * 1533 + * Return: %true if asymmetric link is supported, %false otherwise. 1588 1534 */ 1589 1535 bool usb4_port_asym_supported(struct tb_port *port) 1590 1536 { ··· 1607 1551 * 1608 1552 * Sets USB4 port link width to @width. Can be called for widths where 1609 1553 * usb4_port_asym_width_supported() returned @true. 1554 + * 1555 + * Return: %0 on success, negative errno otherwise. 1610 1556 */ 1611 1557 int usb4_port_asym_set_link_width(struct tb_port *port, enum tb_link_width width) 1612 1558 { ··· 1653 1595 * (according to what was previously set in tb_port_set_link_width(). 1654 1596 * Wait for completion of the change. 1655 1597 * 1656 - * Returns %0 in case of success, %-ETIMEDOUT if case of timeout or 1657 - * a negative errno in case of a failure. 1598 + * Return: 1599 + * * %0 - Symmetry change was successful. 1600 + * * %-ETIMEDOUT - Timeout occurred. 1601 + * * Negative errno - Other failure occurred. 1658 1602 */ 1659 1603 int usb4_port_asym_start(struct tb_port *port) 1660 1604 { ··· 1700 1640 * @ncaps: Number of elements in the caps array 1701 1641 * 1702 1642 * Reads the USB4 port lane margining capabilities into @caps. 1643 + * 1644 + * Return: %0 on success, negative errno otherwise. 1703 1645 */ 1704 1646 int usb4_port_margining_caps(struct tb_port *port, enum usb4_sb_target target, 1705 1647 u8 index, u32 *caps, size_t ncaps) ··· 1728 1666 * 1729 1667 * Runs hardware lane margining on USB4 port and returns the result in 1730 1668 * @results. 1669 + * 1670 + * Return: %0 on success, negative errno otherwise. 1731 1671 */ 1732 1672 int usb4_port_hw_margin(struct tb_port *port, enum usb4_sb_target target, 1733 1673 u8 index, const struct usb4_port_margining_params *params, ··· 1774 1710 * @results: Data word for the operation completion data 1775 1711 * 1776 1712 * Runs software lane margining on USB4 port. Read back the error 1777 - * counters by calling usb4_port_sw_margin_errors(). Returns %0 in 1778 - * success and negative errno otherwise. 1713 + * counters by calling usb4_port_sw_margin_errors(). 1714 + * 1715 + * Return: %0 on success, negative errno otherwise. 1779 1716 */ 1780 1717 int usb4_port_sw_margin(struct tb_port *port, enum usb4_sb_target target, 1781 1718 u8 index, const struct usb4_port_margining_params *params, ··· 1823 1758 * @errors: Error metadata is copied here. 1824 1759 * 1825 1760 * This reads back the software margining error counters from the port. 1826 - * Returns %0 in success and negative errno otherwise. 1761 + * 1762 + * Return: %0 on success, negative errno otherwise. 1827 1763 */ 1828 1764 int usb4_port_sw_margin_errors(struct tb_port *port, enum usb4_sb_target target, 1829 1765 u8 index, u32 *errors) ··· 1855 1789 * 1856 1790 * Enables sideband channel transations on SBTX. Can be used when USB4 1857 1791 * link does not go up, for example if there is no device connected. 1792 + * 1793 + * Return: %0 on success, negative errno otherwise. 1858 1794 */ 1859 1795 int usb4_port_retimer_set_inbound_sbtx(struct tb_port *port, u8 index) 1860 1796 { ··· 1884 1816 * 1885 1817 * Disables sideband channel transations on SBTX. The reverse of 1886 1818 * usb4_port_retimer_set_inbound_sbtx(). 1819 + * 1820 + * Return: %0 on success, negative errno otherwise. 1887 1821 */ 1888 1822 int usb4_port_retimer_unset_inbound_sbtx(struct tb_port *port, u8 index) 1889 1823 { ··· 1898 1828 * @port: USB4 port 1899 1829 * @index: Retimer index 1900 1830 * 1901 - * If the retimer at @index is last one (connected directly to the 1902 - * Type-C port) this function returns %1. If it is not returns %0. If 1903 - * the retimer is not present returns %-ENODEV. Otherwise returns 1904 - * negative errno. 1831 + * Return: 1832 + * * %1 - Retimer at @index is the last one (connected directly to the 1833 + * Type-C port). 1834 + * * %0 - Retimer at @index is not the last one. 1835 + * * %-ENODEV - Retimer is not present. 1836 + * * Negative errno - Other failure occurred. 1905 1837 */ 1906 1838 int usb4_port_retimer_is_last(struct tb_port *port, u8 index) 1907 1839 { ··· 1925 1853 * @port: USB4 port 1926 1854 * @index: Retimer index 1927 1855 * 1928 - * If the retimer at @index is last cable retimer this function returns 1929 - * %1 and %0 if it is on-board retimer. In case a retimer is not present 1930 - * at @index returns %-ENODEV. Otherwise returns negative errno. 1856 + * Return: 1857 + * * %1 - Retimer at @index is the last cable retimer. 1858 + * * %0 - Retimer at @index is on-board retimer. 1859 + * * %-ENODEV - Retimer is not present. 1860 + * * Negative errno - Other failure occurred. 1931 1861 */ 1932 1862 int usb4_port_retimer_is_cable(struct tb_port *port, u8 index) 1933 1863 { ··· 1953 1879 * 1954 1880 * Reads NVM sector size (in bytes) of a retimer at @index. This 1955 1881 * operation can be used to determine whether the retimer supports NVM 1956 - * upgrade for example. Returns sector size in bytes or negative errno 1957 - * in case of error. Specifically returns %-ENODEV if there is no 1958 - * retimer at @index. 1882 + * upgrade for example. 1883 + * 1884 + * Return: 1885 + * * Sector size in bytes. 1886 + * * %-ENODEV - If there is no retimer at @index. 1887 + * * Negative errno - In case of an error. 1959 1888 */ 1960 1889 int usb4_port_retimer_nvm_sector_size(struct tb_port *port, u8 index) 1961 1890 { ··· 1984 1907 * Exlicitly sets NVM write offset. Normally when writing to NVM this is 1985 1908 * done automatically by usb4_port_retimer_nvm_write(). 1986 1909 * 1987 - * Returns %0 in success and negative errno if there was a failure. 1910 + * Return: %0 on success, negative errno otherwise. 1988 1911 */ 1989 1912 int usb4_port_retimer_nvm_set_offset(struct tb_port *port, u8 index, 1990 1913 unsigned int address) ··· 2037 1960 * @size: Size in bytes how much to write 2038 1961 * 2039 1962 * Writes @size bytes from @buf to the retimer NVM. Used for NVM 2040 - * upgrade. Returns %0 if the data was written successfully and negative 2041 - * errno in case of failure. Specifically returns %-ENODEV if there is 2042 - * no retimer at @index. 1963 + * upgrade. 1964 + * 1965 + * Return: 1966 + * * %0 - If the data was written successfully. 1967 + * * %-ENODEV - If there is no retimer at @index. 1968 + * * Negative errno - In case of an error. 2043 1969 */ 2044 1970 int usb4_port_retimer_nvm_write(struct tb_port *port, u8 index, unsigned int address, 2045 1971 const void *buf, size_t size) ··· 2068 1988 * successful the retimer restarts with the new NVM and may not have the 2069 1989 * index set so one needs to call usb4_port_enumerate_retimers() to 2070 1990 * force index to be assigned. 1991 + * 1992 + * Return: %0 on success, negative errno otherwise. 2071 1993 */ 2072 1994 int usb4_port_retimer_nvm_authenticate(struct tb_port *port, u8 index) 2073 1995 { ··· 2094 2012 * This can be called after usb4_port_retimer_nvm_authenticate() and 2095 2013 * usb4_port_enumerate_retimers() to fetch status of the NVM upgrade. 2096 2014 * 2097 - * Returns %0 if the authentication status was successfully read. The 2015 + * Return: %0 if the authentication status was successfully read. The 2098 2016 * completion metadata (the result) is then stored into @status. If 2099 - * reading the status fails, returns negative errno. 2017 + * status read fails, returns negative errno. 2100 2018 */ 2101 2019 int usb4_port_retimer_nvm_authenticate_status(struct tb_port *port, u8 index, 2102 2020 u32 *status) ··· 2164 2082 * @buf: Data read from NVM is stored here 2165 2083 * @size: Number of bytes to read 2166 2084 * 2167 - * Reads retimer NVM and copies the contents to @buf. Returns %0 if the 2168 - * read was successful and negative errno in case of failure. 2169 - * Specifically returns %-ENODEV if there is no retimer at @index. 2085 + * Reads retimer NVM and copies the contents to @buf. 2086 + * 2087 + * Return: 2088 + * * %0 - If the read was successful. 2089 + * * %-ENODEV - If there is no retimer at @index. 2090 + * * Negative errno - In case of an error. 2170 2091 */ 2171 2092 int usb4_port_retimer_nvm_read(struct tb_port *port, u8 index, 2172 2093 unsigned int address, void *buf, size_t size) ··· 2193 2108 * usb4_usb3_port_max_link_rate() - Maximum support USB3 link rate 2194 2109 * @port: USB3 adapter port 2195 2110 * 2196 - * Return maximum supported link rate of a USB3 adapter in Mb/s. 2197 - * Negative errno in case of error. 2111 + * Return: Maximum supported link rate of a USB3 adapter in Mb/s. 2112 + * Negative errno in case of an error. 2198 2113 */ 2199 2114 int usb4_usb3_port_max_link_rate(struct tb_port *port) 2200 2115 { ··· 2312 2227 * @downstream_bw: Allocated downstream bandwidth is stored here 2313 2228 * 2314 2229 * Stores currently allocated USB3 bandwidth into @upstream_bw and 2315 - * @downstream_bw in Mb/s. Returns %0 in case of success and negative 2316 - * errno in failure. 2230 + * @downstream_bw in Mb/s. 2231 + * 2232 + * Return: %0 on success, negative errno otherwise. 2317 2233 */ 2318 2234 int usb4_usb3_port_allocated_bandwidth(struct tb_port *port, int *upstream_bw, 2319 2235 int *downstream_bw) ··· 2416 2330 * cannot be taken away by CM). The actual new values are returned in 2417 2331 * @upstream_bw and @downstream_bw. 2418 2332 * 2419 - * Returns %0 in case of success and negative errno if there was a 2420 - * failure. 2333 + * Return: %0 on success, negative errno otherwise. 2421 2334 */ 2422 2335 int usb4_usb3_port_allocate_bandwidth(struct tb_port *port, int *upstream_bw, 2423 2336 int *downstream_bw) ··· 2458 2373 * Releases USB3 allocated bandwidth down to what is actually consumed. 2459 2374 * The new bandwidth is returned in @upstream_bw and @downstream_bw. 2460 2375 * 2461 - * Returns 0% in success and negative errno in case of failure. 2376 + * Return: %0 on success, negative errno otherwise. 2462 2377 */ 2463 2378 int usb4_usb3_port_release_bandwidth(struct tb_port *port, int *upstream_bw, 2464 2379 int *downstream_bw) ··· 2510 2425 * @port: DP IN adapter 2511 2426 * @cm_id: CM ID to assign 2512 2427 * 2513 - * Sets CM ID for the @port. Returns %0 on success and negative errno 2514 - * otherwise. Speficially returns %-EOPNOTSUPP if the @port does not 2515 - * support this. 2428 + * Sets CM ID for the @port. 2429 + * 2430 + * Return: 2431 + * * %0 - On success. 2432 + * * %-EOPNOTSUPP - If the @port does not support this. 2433 + * * Negative errno - Another error occurred. 2516 2434 */ 2517 2435 int usb4_dp_port_set_cm_id(struct tb_port *port, int cm_id) 2518 2436 { ··· 2542 2454 * supported 2543 2455 * @port: DP IN adapter to check 2544 2456 * 2545 - * Can be called to any DP IN adapter. Returns true if the adapter 2546 - * supports USB4 bandwidth allocation mode, false otherwise. 2457 + * Can be called to any DP IN adapter. 2458 + * 2459 + * Return: %true if the adapter supports USB4 bandwidth allocation mode, 2460 + * %false otherwise. 2547 2461 */ 2548 2462 bool usb4_dp_port_bandwidth_mode_supported(struct tb_port *port) 2549 2463 { ··· 2568 2478 * enabled 2569 2479 * @port: DP IN adapter to check 2570 2480 * 2571 - * Can be called to any DP IN adapter. Returns true if the bandwidth 2572 - * allocation mode has been enabled, false otherwise. 2481 + * Can be called to any DP IN adapter. 2482 + * 2483 + * Return: %true if the bandwidth allocation mode has been enabled, 2484 + * %false otherwise. 2573 2485 */ 2574 2486 bool usb4_dp_port_bandwidth_mode_enabled(struct tb_port *port) 2575 2487 { ··· 2596 2504 * @supported: Does the CM support bandwidth allocation mode 2597 2505 * 2598 2506 * Can be called to any DP IN adapter. Sets or clears the CM support bit 2599 - * of the DP IN adapter. Returns %0 in success and negative errno 2600 - * otherwise. Specifically returns %-OPNOTSUPP if the passed in adapter 2601 - * does not support this. 2507 + * of the DP IN adapter. 2508 + * 2509 + * * Return: 2510 + * * %0 - On success. 2511 + * * %-EOPNOTSUPP - If the passed IN adapter does not support this. 2512 + * * Negative errno - Another error occurred. 2602 2513 */ 2603 2514 int usb4_dp_port_set_cm_bandwidth_mode_supported(struct tb_port *port, 2604 2515 bool supported) ··· 2631 2536 * @port: DP IN adapter 2632 2537 * 2633 2538 * Reads bandwidth allocation Group ID from the DP IN adapter and 2634 - * returns it. If the adapter does not support setting Group_ID 2635 - * %-EOPNOTSUPP is returned. 2539 + * returns it. 2540 + * 2541 + * Return: 2542 + * * Group ID assigned to adapter @port. 2543 + * * %-EOPNOTSUPP - If adapter does not support setting GROUP_ID. 2544 + * * Negative errno - Another error occurred. 2636 2545 */ 2637 2546 int usb4_dp_port_group_id(struct tb_port *port) 2638 2547 { ··· 2660 2561 * @group_id: Group ID for the adapter 2661 2562 * 2662 2563 * Sets bandwidth allocation mode Group ID for the DP IN adapter. 2663 - * Returns %0 in case of success and negative errno otherwise. 2664 - * Specifically returns %-EOPNOTSUPP if the adapter does not support 2665 - * this. 2564 + * 2565 + * Return: 2566 + * * %0 - On success. 2567 + * * %-EOPNOTSUPP - If the adapter does not support this. 2568 + * * Negative errno - Another error occurred. 2666 2569 */ 2667 2570 int usb4_dp_port_set_group_id(struct tb_port *port, int group_id) 2668 2571 { ··· 2692 2591 * @rate: Non-reduced rate in Mb/s is placed here 2693 2592 * @lanes: Non-reduced lanes are placed here 2694 2593 * 2695 - * Reads the non-reduced rate and lanes from the DP IN adapter. Returns 2696 - * %0 in success and negative errno otherwise. Specifically returns 2697 - * %-EOPNOTSUPP if the adapter does not support this. 2594 + * Reads the non-reduced rate and lanes from the DP IN adapter. 2595 + * 2596 + * Return: 2597 + * * %0 - On success. 2598 + * * %-EOPNOTSUPP - If the adapter does not support this. 2599 + * * Negative errno - Another error occurred. 2698 2600 */ 2699 2601 int usb4_dp_port_nrd(struct tb_port *port, int *rate, int *lanes) 2700 2602 { ··· 2750 2646 * @rate: Non-reduced rate in Mb/s 2751 2647 * @lanes: Non-reduced lanes 2752 2648 * 2753 - * Before the capabilities reduction this function can be used to set 2754 - * the non-reduced values for the DP IN adapter. Returns %0 in success 2755 - * and negative errno otherwise. If the adapter does not support this 2756 - * %-EOPNOTSUPP is returned. 2649 + * Before the capabilities reduction, this function can be used to set 2650 + * the non-reduced values for the DP IN adapter. 2651 + * 2652 + * Return: 2653 + * * %0 - On success. 2654 + * * %-EOPNOTSUPP - If the adapter does not support this. 2655 + * * Negative errno - Another error occurred. 2757 2656 */ 2758 2657 int usb4_dp_port_set_nrd(struct tb_port *port, int rate, int lanes) 2759 2658 { ··· 2815 2708 * usb4_dp_port_granularity() - Return granularity for the bandwidth values 2816 2709 * @port: DP IN adapter 2817 2710 * 2818 - * Reads the programmed granularity from @port. If the DP IN adapter does 2819 - * not support bandwidth allocation mode returns %-EOPNOTSUPP and negative 2820 - * errno in other error cases. 2711 + * Reads the programmed granularity from @port. 2712 + * 2713 + * Return: 2714 + * * Granularity value of a @port. 2715 + * * %-EOPNOTSUPP - If the DP IN adapter does not support bandwidth 2716 + * allocation mode. 2717 + * * Negative errno - Another error occurred. 2821 2718 */ 2822 2719 int usb4_dp_port_granularity(struct tb_port *port) 2823 2720 { ··· 2857 2746 * @granularity: Granularity in Mb/s. Supported values: 1000, 500 and 250. 2858 2747 * 2859 2748 * Sets the granularity used with the estimated, allocated and requested 2860 - * bandwidth. Returns %0 in success and negative errno otherwise. If the 2861 - * adapter does not support this %-EOPNOTSUPP is returned. 2749 + * bandwidth. 2750 + * 2751 + * Return: 2752 + * * %0 - On success. 2753 + * * %-EOPNOTSUPP - If the adapter does not support this. 2754 + * * Negative errno - Another error occurred. 2862 2755 */ 2863 2756 int usb4_dp_port_set_granularity(struct tb_port *port, int granularity) 2864 2757 { ··· 2903 2788 * @bw: Estimated bandwidth in Mb/s. 2904 2789 * 2905 2790 * Sets the estimated bandwidth to @bw. Set the granularity by calling 2906 - * usb4_dp_port_set_granularity() before calling this. The @bw is round 2907 - * down to the closest granularity multiplier. Returns %0 in success 2908 - * and negative errno otherwise. Specifically returns %-EOPNOTSUPP if 2909 - * the adapter does not support this. 2791 + * usb4_dp_port_set_granularity() before calling this. The @bw is rounded 2792 + * down to the closest granularity multiplier. 2793 + * 2794 + * Return: 2795 + * * %0 - On success. 2796 + * * %-EOPNOTSUPP - If the adapter does not support this. 2797 + * * Negative errno - Another error occurred. 2910 2798 */ 2911 2799 int usb4_dp_port_set_estimated_bandwidth(struct tb_port *port, int bw) 2912 2800 { ··· 2940 2822 * usb4_dp_port_allocated_bandwidth() - Return allocated bandwidth 2941 2823 * @port: DP IN adapter 2942 2824 * 2943 - * Reads and returns allocated bandwidth for @port in Mb/s (taking into 2944 - * account the programmed granularity). Returns negative errno in case 2945 - * of error. 2825 + * Reads the allocated bandwidth for @port in Mb/s (taking into account 2826 + * the programmed granularity). 2827 + * 2828 + * Return: Allocated bandwidth in Mb/s or negative errno in case of an error. 2946 2829 */ 2947 2830 int usb4_dp_port_allocated_bandwidth(struct tb_port *port) 2948 2831 { ··· 3038 2919 * @bw: New allocated bandwidth in Mb/s 3039 2920 * 3040 2921 * Communicates the new allocated bandwidth with the DPCD (graphics 3041 - * driver). Takes into account the programmed granularity. Returns %0 in 3042 - * success and negative errno in case of error. 2922 + * driver). Takes into account the programmed granularity. 2923 + * 2924 + * Return: %0 on success, negative errno otherwise. 3043 2925 */ 3044 2926 int usb4_dp_port_allocate_bandwidth(struct tb_port *port, int bw) 3045 2927 { ··· 3080 2960 * @port: DP IN adapter 3081 2961 * 3082 2962 * Reads the DPCD (graphics driver) requested bandwidth and returns it 3083 - * in Mb/s. Takes the programmed granularity into account. In case of 3084 - * error returns negative errno. Specifically returns %-EOPNOTSUPP if 3085 - * the adapter does not support bandwidth allocation mode, and %ENODATA 3086 - * if there is no active bandwidth request from the graphics driver. 2963 + * in Mb/s. Takes the programmed granularity into account. 2964 + * 2965 + * Return: 2966 + * * Requested bandwidth in Mb/s - On success. 2967 + * * %-EOPNOTSUPP - If the adapter does not support bandwidth allocation 2968 + * mode. 2969 + * * %ENODATA - If there is no active bandwidth request from the graphics 2970 + * driver. 2971 + * * Negative errno - On failure. 3087 2972 */ 3088 2973 int usb4_dp_port_requested_bandwidth(struct tb_port *port) 3089 2974 { ··· 3120 2995 * @enable: Enable/disable extended encapsulation 3121 2996 * 3122 2997 * Enables or disables extended encapsulation used in PCIe tunneling. Caller 3123 - * needs to make sure both adapters support this before enabling. Returns %0 on 3124 - * success and negative errno otherwise. 2998 + * needs to make sure both adapters support this before enabling. 2999 + * 3000 + * Return: %0 on success, negative errno otherwise. 3125 3001 */ 3126 3002 int usb4_pci_port_set_ext_encapsulation(struct tb_port *port, bool enable) 3127 3003 {
+5 -2
drivers/thunderbolt/usb4_port.c
··· 296 296 * usb4_port_device_add() - Add USB4 port device 297 297 * @port: Lane 0 adapter port to add the USB4 port 298 298 * 299 - * Creates and registers a USB4 port device for @port. Returns the new 300 - * USB4 port device pointer or ERR_PTR() in case of error. 299 + * Creates and registers a USB4 port device for @port. 300 + * 301 + * Return: Pointer to &struct usb4_port or ERR_PTR() in case of an error. 301 302 */ 302 303 struct usb4_port *usb4_port_device_add(struct tb_port *port) 303 304 { ··· 357 356 * @usb4: USB4 port device 358 357 * 359 358 * Used to resume USB4 port device after sleep state. 359 + * 360 + * Return: %0 on success, negative errno otherwise. 360 361 */ 361 362 int usb4_port_device_resume(struct usb4_port *usb4) 362 363 {
+36 -17
drivers/thunderbolt/xdomain.c
··· 160 160 * This can be used to send a XDomain response message to the other 161 161 * domain. No response for the message is expected. 162 162 * 163 - * Return: %0 in case of success and negative errno in case of failure 163 + * Return: %0 on success, negative errno otherwise. 164 164 */ 165 165 int tb_xdomain_response(struct tb_xdomain *xd, const void *response, 166 166 size_t size, enum tb_cfg_pkg_type type) ··· 212 212 * the other domain. The function waits until the response is received 213 213 * or when timeout triggers. Whichever comes first. 214 214 * 215 - * Return: %0 in case of success and negative errno in case of failure 215 + * Return: %0 on success, negative errno otherwise. 216 216 */ 217 217 int tb_xdomain_request(struct tb_xdomain *xd, const void *request, 218 218 size_t request_size, enum tb_cfg_pkg_type request_type, ··· 613 613 * messages. After this function is called the service driver needs to 614 614 * be able to handle calls to callback whenever a package with the 615 615 * registered protocol is received. 616 + * 617 + * Return: %0 on success, negative errno otherwise. 616 618 */ 617 619 int tb_register_protocol_handler(struct tb_protocol_handler *handler) 618 620 { ··· 879 877 * @drv: Driver to register 880 878 * 881 879 * Registers new service driver from @drv to the bus. 880 + * 881 + * Return: %0 on success, negative errno otherwise. 882 882 */ 883 883 int tb_register_service_driver(struct tb_service_driver *drv) 884 884 { ··· 1959 1955 * 1960 1956 * Allocates new XDomain structure and returns pointer to that. The 1961 1957 * object must be released by calling tb_xdomain_put(). 1958 + * 1959 + * Return: Pointer to &struct tb_xdomain, %NULL in case of failure. 1962 1960 */ 1963 1961 struct tb_xdomain *tb_xdomain_alloc(struct tb *tb, struct device *parent, 1964 1962 u64 route, const uuid_t *local_uuid, ··· 2097 2091 * to enable bonding by first enabling the port and waiting for the CL0 2098 2092 * state. 2099 2093 * 2100 - * Return: %0 in case of success and negative errno in case of error. 2094 + * Return: %0 on success, negative errno otherwise. 2101 2095 */ 2102 2096 int tb_xdomain_lane_bonding_enable(struct tb_xdomain *xd) 2103 2097 { ··· 2177 2171 * @xd: XDomain connection 2178 2172 * @hopid: Preferred HopID or %-1 for next available 2179 2173 * 2180 - * Returns allocated HopID or negative errno. Specifically returns 2181 - * %-ENOSPC if there are no more available HopIDs. Returned HopID is 2182 - * guaranteed to be within range supported by the input lane adapter. 2174 + * Returned HopID is guaranteed to be within range supported by the input 2175 + * lane adapter. 2183 2176 * Call tb_xdomain_release_in_hopid() to release the allocated HopID. 2177 + * 2178 + * Return: 2179 + * * Allocated HopID - On success. 2180 + * * %-ENOSPC - If there are no more available HopIDs. 2181 + * * Negative errno - Another error occurred. 2184 2182 */ 2185 2183 int tb_xdomain_alloc_in_hopid(struct tb_xdomain *xd, int hopid) 2186 2184 { ··· 2203 2193 * @xd: XDomain connection 2204 2194 * @hopid: Preferred HopID or %-1 for next available 2205 2195 * 2206 - * Returns allocated HopID or negative errno. Specifically returns 2207 - * %-ENOSPC if there are no more available HopIDs. Returned HopID is 2208 - * guaranteed to be within range supported by the output lane adapter. 2209 - * Call tb_xdomain_release_in_hopid() to release the allocated HopID. 2196 + * Returned HopID is guaranteed to be within range supported by the 2197 + * output lane adapter. 2198 + * Call tb_xdomain_release_out_hopid() to release the allocated HopID. 2199 + * 2200 + * Return: 2201 + * * Allocated HopID - On success. 2202 + * * %-ENOSPC - If there are no more available HopIDs. 2203 + * * Negative errno - Another error occurred. 2210 2204 */ 2211 2205 int tb_xdomain_alloc_out_hopid(struct tb_xdomain *xd, int hopid) 2212 2206 { ··· 2259 2245 * path. If a transmit or receive path is not needed, pass %-1 for those 2260 2246 * parameters. 2261 2247 * 2262 - * Return: %0 in case of success and negative errno in case of error 2248 + * Return: %0 on success, negative errno otherwise. 2263 2249 */ 2264 2250 int tb_xdomain_enable_paths(struct tb_xdomain *xd, int transmit_path, 2265 2251 int transmit_ring, int receive_path, ··· 2284 2270 * as path/ring parameter means don't care. Normally the callers should 2285 2271 * pass the same values here as they do when paths are enabled. 2286 2272 * 2287 - * Return: %0 in case of success and negative errno in case of error 2273 + * Return: %0 on success, negative errno otherwise. 2288 2274 */ 2289 2275 int tb_xdomain_disable_paths(struct tb_xdomain *xd, int transmit_path, 2290 2276 int transmit_ring, int receive_path, ··· 2349 2335 * to the bus (handshake is still in progress). 2350 2336 * 2351 2337 * The caller needs to hold @tb->lock. 2338 + * 2339 + * Return: Pointer to &struct tb_xdomain or %NULL if not found. 2352 2340 */ 2353 2341 struct tb_xdomain *tb_xdomain_find_by_uuid(struct tb *tb, const uuid_t *uuid) 2354 2342 { ··· 2380 2364 * to the bus (handshake is still in progress). 2381 2365 * 2382 2366 * The caller needs to hold @tb->lock. 2367 + * 2368 + * Return: Pointer to &struct tb_xdomain or %NULL if not found. 2383 2369 */ 2384 2370 struct tb_xdomain *tb_xdomain_find_by_link_depth(struct tb *tb, u8 link, 2385 2371 u8 depth) ··· 2411 2393 * to the bus (handshake is still in progress). 2412 2394 * 2413 2395 * The caller needs to hold @tb->lock. 2396 + * 2397 + * Return: Pointer to &struct tb_xdomain or %NULL if not found. 2414 2398 */ 2415 2399 struct tb_xdomain *tb_xdomain_find_by_route(struct tb *tb, u64 route) 2416 2400 { ··· 2511 2491 * notified so they can re-read properties of this host if they are 2512 2492 * interested. 2513 2493 * 2514 - * Return: %0 on success and negative errno on failure 2494 + * Return: %0 on success, negative errno otherwise. 2515 2495 */ 2516 2496 int tb_register_property_dir(const char *key, struct tb_property_dir *dir) 2517 2497 { ··· 2582 2562 * Rest of the properties are filled dynamically based on these 2583 2563 * when the P2P connection is made. 2584 2564 */ 2585 - tb_property_add_immediate(xdomain_property_dir, "vendorid", 2586 - PCI_VENDOR_ID_INTEL); 2587 - tb_property_add_text(xdomain_property_dir, "vendorid", "Intel Corp."); 2588 - tb_property_add_immediate(xdomain_property_dir, "deviceid", 0x1); 2565 + tb_property_add_immediate(xdomain_property_dir, "vendorid", 0x1d6b); 2566 + tb_property_add_text(xdomain_property_dir, "vendorid", "Linux"); 2567 + tb_property_add_immediate(xdomain_property_dir, "deviceid", 0x0004); 2589 2568 tb_property_add_immediate(xdomain_property_dir, "devicerv", 0x80000100); 2590 2569 2591 2570 xdomain_property_block_gen = get_random_u32();
-61
drivers/usb/cdns3/cdns3-trace.h
··· 283 283 __entry->length) 284 284 ); 285 285 286 - DECLARE_EVENT_CLASS(cdns3_stream_split_transfer_len, 287 - TP_PROTO(struct cdns3_request *req), 288 - TP_ARGS(req), 289 - TP_STRUCT__entry( 290 - __string(name, req->priv_ep->name) 291 - __field(struct cdns3_request *, req) 292 - __field(unsigned int, length) 293 - __field(unsigned int, actual) 294 - __field(unsigned int, stream_id) 295 - ), 296 - TP_fast_assign( 297 - __assign_str(name); 298 - __entry->req = req; 299 - __entry->actual = req->request.length; 300 - __entry->length = req->request.actual; 301 - __entry->stream_id = req->request.stream_id; 302 - ), 303 - TP_printk("%s: req: %p,request length: %u actual length: %u SID: %u", 304 - __get_str(name), __entry->req, __entry->length, 305 - __entry->actual, __entry->stream_id) 306 - ); 307 - 308 - DEFINE_EVENT(cdns3_stream_split_transfer_len, cdns3_stream_transfer_split, 309 - TP_PROTO(struct cdns3_request *req), 310 - TP_ARGS(req) 311 - ); 312 - 313 - DEFINE_EVENT(cdns3_stream_split_transfer_len, 314 - cdns3_stream_transfer_split_next_part, 315 - TP_PROTO(struct cdns3_request *req), 316 - TP_ARGS(req) 317 - ); 318 - 319 286 DECLARE_EVENT_CLASS(cdns3_log_aligned_request, 320 287 TP_PROTO(struct cdns3_request *priv_req), 321 288 TP_ARGS(priv_req), ··· 319 352 DEFINE_EVENT(cdns3_log_aligned_request, cdns3_prepare_aligned_request, 320 353 TP_PROTO(struct cdns3_request *req), 321 354 TP_ARGS(req) 322 - ); 323 - 324 - DECLARE_EVENT_CLASS(cdns3_log_map_request, 325 - TP_PROTO(struct cdns3_request *priv_req), 326 - TP_ARGS(priv_req), 327 - TP_STRUCT__entry( 328 - __string(name, priv_req->priv_ep->name) 329 - __field(struct usb_request *, req) 330 - __field(void *, buf) 331 - __field(dma_addr_t, dma) 332 - ), 333 - TP_fast_assign( 334 - __assign_str(name); 335 - __entry->req = &priv_req->request; 336 - __entry->buf = priv_req->request.buf; 337 - __entry->dma = priv_req->request.dma; 338 - ), 339 - TP_printk("%s: req: %p, req buf %p, dma %p", 340 - __get_str(name), __entry->req, __entry->buf, &__entry->dma 341 - ) 342 - ); 343 - DEFINE_EVENT(cdns3_log_map_request, cdns3_map_request, 344 - TP_PROTO(struct cdns3_request *req), 345 - TP_ARGS(req) 346 - ); 347 - DEFINE_EVENT(cdns3_log_map_request, cdns3_mapped_request, 348 - TP_PROTO(struct cdns3_request *req), 349 - TP_ARGS(req) 350 355 ); 351 356 352 357 DECLARE_EVENT_CLASS(cdns3_log_trb,
+6 -2
drivers/usb/cdns3/cdnsp-gadget.c
··· 1976 1976 return 0; 1977 1977 1978 1978 del_gadget: 1979 - usb_del_gadget_udc(&pdev->gadget); 1979 + usb_del_gadget(&pdev->gadget); 1980 + cdnsp_gadget_free_endpoints(pdev); 1981 + usb_put_gadget(&pdev->gadget); 1982 + goto halt_pdev; 1980 1983 free_endpoints: 1981 1984 cdnsp_gadget_free_endpoints(pdev); 1982 1985 halt_pdev: ··· 2001 1998 devm_free_irq(pdev->dev, cdns->dev_irq, pdev); 2002 1999 pm_runtime_mark_last_busy(cdns->dev); 2003 2000 pm_runtime_put_autosuspend(cdns->dev); 2004 - usb_del_gadget_udc(&pdev->gadget); 2001 + usb_del_gadget(&pdev->gadget); 2005 2002 cdnsp_gadget_free_endpoints(pdev); 2003 + usb_put_gadget(&pdev->gadget); 2006 2004 cdnsp_mem_cleanup(pdev); 2007 2005 kfree(pdev); 2008 2006 cdns->gadget_dev = NULL;
+1 -4
drivers/usb/cdns3/cdnsp-pci.c
··· 85 85 cdnsp = kzalloc(sizeof(*cdnsp), GFP_KERNEL); 86 86 if (!cdnsp) { 87 87 ret = -ENOMEM; 88 - goto disable_pci; 88 + goto put_pci; 89 89 } 90 90 } 91 91 ··· 167 167 free_cdnsp: 168 168 if (!pci_is_enabled(func)) 169 169 kfree(cdnsp); 170 - 171 - disable_pci: 172 - pci_disable_device(pdev); 173 170 174 171 put_pci: 175 172 pci_dev_put(func);
-25
drivers/usb/cdns3/cdnsp-trace.h
··· 178 178 TP_ARGS(msg) 179 179 ); 180 180 181 - DEFINE_EVENT(cdnsp_log_simple, cdnsp_ep0_halted, 182 - TP_PROTO(char *msg), 183 - TP_ARGS(msg) 184 - ); 185 - 186 181 DEFINE_EVENT(cdnsp_log_simple, cdnsp_ep_halt, 187 182 TP_PROTO(char *msg), 188 183 TP_ARGS(msg) ··· 394 399 TP_ARGS(ring, trb) 395 400 ); 396 401 397 - DEFINE_EVENT(cdnsp_log_trb, cdnsp_defered_event, 398 - TP_PROTO(struct cdnsp_ring *ring, struct cdnsp_generic_trb *trb), 399 - TP_ARGS(ring, trb) 400 - ); 401 - 402 402 DECLARE_EVENT_CLASS(cdnsp_log_pdev, 403 403 TP_PROTO(struct cdnsp_device *pdev), 404 404 TP_ARGS(pdev), ··· 419 429 ); 420 430 421 431 DEFINE_EVENT(cdnsp_log_pdev, cdnsp_alloc_priv_device, 422 - TP_PROTO(struct cdnsp_device *vdev), 423 - TP_ARGS(vdev) 424 - ); 425 - 426 - DEFINE_EVENT(cdnsp_log_pdev, cdnsp_free_priv_device, 427 - TP_PROTO(struct cdnsp_device *vdev), 428 - TP_ARGS(vdev) 429 - ); 430 - 431 - DEFINE_EVENT(cdnsp_log_pdev, cdnsp_setup_device, 432 432 TP_PROTO(struct cdnsp_device *vdev), 433 433 TP_ARGS(vdev) 434 434 ); ··· 551 571 ); 552 572 553 573 DEFINE_EVENT(cdnsp_log_ep_ctx, cdnsp_handle_cmd_stop_ep, 554 - TP_PROTO(struct cdnsp_ep_ctx *ctx), 555 - TP_ARGS(ctx) 556 - ); 557 - 558 - DEFINE_EVENT(cdnsp_log_ep_ctx, cdnsp_handle_cmd_flush_ep, 559 574 TP_PROTO(struct cdnsp_ep_ctx *ctx), 560 575 TP_ARGS(ctx) 561 576 );
+2 -1
drivers/usb/class/usblp.c
··· 34 34 35 35 #include <linux/module.h> 36 36 #include <linux/kernel.h> 37 + #include <linux/minmax.h> 37 38 #include <linux/sched/signal.h> 38 39 #include <linux/signal.h> 39 40 #include <linux/poll.h> ··· 872 871 goto done; 873 872 } 874 873 875 - count = len < avail - usblp->readcount ? len : avail - usblp->readcount; 874 + count = min_t(ssize_t, len, avail - usblp->readcount); 876 875 if (count != 0 && 877 876 copy_to_user(buffer, usblp->readbuf + usblp->readcount, count)) { 878 877 count = -EFAULT;
+1
drivers/usb/core/Makefile
··· 9 9 usbcore-y += phy.o port.o 10 10 11 11 usbcore-$(CONFIG_OF) += of.o 12 + usbcore-$(CONFIG_USB_XHCI_SIDEBAND) += offload.o 12 13 usbcore-$(CONFIG_USB_PCI) += hcd-pci.o 13 14 usbcore-$(CONFIG_ACPI) += usb-acpi.o 14 15
+2 -2
drivers/usb/core/config.c
··· 507 507 } 508 508 509 509 /* Parse a possible eUSB2 periodic endpoint companion descriptor */ 510 - if (bcdUSB == 0x0220 && d->wMaxPacketSize == 0 && 511 - (usb_endpoint_xfer_isoc(d) || usb_endpoint_xfer_int(d))) 510 + if (udev->speed == USB_SPEED_HIGH && bcdUSB == 0x0220 && 511 + !le16_to_cpu(d->wMaxPacketSize) && usb_endpoint_is_isoc_in(d)) 512 512 usb_parse_eusb2_isoc_endpoint_companion(ddev, cfgno, inum, asnum, 513 513 endpoint, buffer, size); 514 514
+46 -12
drivers/usb/core/driver.c
··· 332 332 return error; 333 333 334 334 if (udev->authorized == 0) { 335 - dev_err(&intf->dev, "Device is not authorized for usage\n"); 335 + dev_info(&intf->dev, "Device is not authorized for usage\n"); 336 336 return error; 337 337 } else if (intf->authorized == 0) { 338 - dev_err(&intf->dev, "Interface %d is not authorized for usage\n", 338 + dev_info(&intf->dev, "Interface %d is not authorized for usage\n", 339 339 intf->altsetting->desc.bInterfaceNumber); 340 340 return error; 341 341 } ··· 1420 1420 udev->state == USB_STATE_SUSPENDED) 1421 1421 goto done; 1422 1422 1423 + if (msg.event == PM_EVENT_SUSPEND && usb_offload_check(udev)) { 1424 + dev_dbg(&udev->dev, "device offloaded, skip suspend.\n"); 1425 + udev->offload_at_suspend = 1; 1426 + } 1427 + 1423 1428 /* Suspend all the interfaces and then udev itself */ 1424 1429 if (udev->actconfig) { 1425 1430 n = udev->actconfig->desc.bNumInterfaces; 1426 1431 for (i = n - 1; i >= 0; --i) { 1427 1432 intf = udev->actconfig->interface[i]; 1433 + /* 1434 + * Don't suspend interfaces with remote wakeup while 1435 + * the controller is active. This preserves pending 1436 + * interrupt urbs, allowing interrupt events to be 1437 + * handled during system suspend. 1438 + */ 1439 + if (udev->offload_at_suspend && 1440 + intf->needs_remote_wakeup) { 1441 + dev_dbg(&intf->dev, 1442 + "device offloaded, skip suspend.\n"); 1443 + continue; 1444 + } 1428 1445 status = usb_suspend_interface(udev, intf, msg); 1429 1446 1430 1447 /* Ignore errors during system sleep transitions */ ··· 1452 1435 } 1453 1436 } 1454 1437 if (status == 0) { 1455 - status = usb_suspend_device(udev, msg); 1438 + if (!udev->offload_at_suspend) 1439 + status = usb_suspend_device(udev, msg); 1456 1440 1457 1441 /* 1458 1442 * Ignore errors from non-root-hub devices during ··· 1498 1480 */ 1499 1481 } else { 1500 1482 udev->can_submit = 0; 1501 - for (i = 0; i < 16; ++i) { 1502 - usb_hcd_flush_endpoint(udev, udev->ep_out[i]); 1503 - usb_hcd_flush_endpoint(udev, udev->ep_in[i]); 1483 + if (!udev->offload_at_suspend) { 1484 + for (i = 0; i < 16; ++i) { 1485 + usb_hcd_flush_endpoint(udev, udev->ep_out[i]); 1486 + usb_hcd_flush_endpoint(udev, udev->ep_in[i]); 1487 + } 1504 1488 } 1505 1489 } 1506 1490 ··· 1544 1524 udev->can_submit = 1; 1545 1525 1546 1526 /* Resume the device */ 1547 - if (udev->state == USB_STATE_SUSPENDED || udev->reset_resume) 1548 - status = usb_resume_device(udev, msg); 1527 + if (udev->state == USB_STATE_SUSPENDED || udev->reset_resume) { 1528 + if (!udev->offload_at_suspend) 1529 + status = usb_resume_device(udev, msg); 1530 + else 1531 + dev_dbg(&udev->dev, 1532 + "device offloaded, skip resume.\n"); 1533 + } 1549 1534 1550 1535 /* Resume the interfaces */ 1551 1536 if (status == 0 && udev->actconfig) { 1552 1537 for (i = 0; i < udev->actconfig->desc.bNumInterfaces; i++) { 1553 1538 intf = udev->actconfig->interface[i]; 1539 + /* 1540 + * Interfaces with remote wakeup aren't suspended 1541 + * while the controller is active. This preserves 1542 + * pending interrupt urbs, allowing interrupt events 1543 + * to be handled during system suspend. 1544 + */ 1545 + if (udev->offload_at_suspend && 1546 + intf->needs_remote_wakeup) { 1547 + dev_dbg(&intf->dev, 1548 + "device offloaded, skip resume.\n"); 1549 + continue; 1550 + } 1554 1551 usb_resume_interface(udev, intf, msg, 1555 1552 udev->reset_resume); 1556 1553 } 1557 1554 } 1555 + udev->offload_at_suspend = 0; 1558 1556 usb_mark_last_busy(udev); 1559 1557 1560 1558 done: ··· 1761 1723 dev_vdbg(&udev->dev, "%s: cnt %d -> %d\n", 1762 1724 __func__, atomic_read(&udev->dev.power.usage_count), 1763 1725 status); 1764 - if (status > 0) 1765 - status = 0; 1766 1726 return status; 1767 1727 } 1768 1728 ··· 1865 1829 dev_vdbg(&intf->dev, "%s: cnt %d -> %d\n", 1866 1830 __func__, atomic_read(&intf->dev.power.usage_count), 1867 1831 status); 1868 - if (status > 0) 1869 - status = 0; 1870 1832 return status; 1871 1833 } 1872 1834 EXPORT_SYMBOL_GPL(usb_autopm_get_interface);
+1 -1
drivers/usb/core/generic.c
··· 243 243 * with the driver core and lets interface drivers bind to them. 244 244 */ 245 245 if (udev->authorized == 0) 246 - dev_err(&udev->dev, "Device is not authorized for usage\n"); 246 + dev_info(&udev->dev, "Device is not authorized for usage\n"); 247 247 else { 248 248 c = usb_choose_configuration(udev); 249 249 if (c >= 0) {
+136
drivers/usb/core/offload.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + 3 + /* 4 + * offload.c - USB offload related functions 5 + * 6 + * Copyright (c) 2025, Google LLC. 7 + * 8 + * Author: Guan-Yu Lin 9 + */ 10 + 11 + #include <linux/usb.h> 12 + 13 + #include "usb.h" 14 + 15 + /** 16 + * usb_offload_get - increment the offload_usage of a USB device 17 + * @udev: the USB device to increment its offload_usage 18 + * 19 + * Incrementing the offload_usage of a usb_device indicates that offload is 20 + * enabled on this usb_device; that is, another entity is actively handling USB 21 + * transfers. This information allows the USB driver to adjust its power 22 + * management policy based on offload activity. 23 + * 24 + * Return: 0 on success. A negative error code otherwise. 25 + */ 26 + int usb_offload_get(struct usb_device *udev) 27 + { 28 + int ret; 29 + 30 + usb_lock_device(udev); 31 + if (udev->state == USB_STATE_NOTATTACHED) { 32 + usb_unlock_device(udev); 33 + return -ENODEV; 34 + } 35 + 36 + if (udev->state == USB_STATE_SUSPENDED || 37 + udev->offload_at_suspend) { 38 + usb_unlock_device(udev); 39 + return -EBUSY; 40 + } 41 + 42 + /* 43 + * offload_usage could only be modified when the device is active, since 44 + * it will alter the suspend flow of the device. 45 + */ 46 + ret = usb_autoresume_device(udev); 47 + if (ret < 0) { 48 + usb_unlock_device(udev); 49 + return ret; 50 + } 51 + 52 + udev->offload_usage++; 53 + usb_autosuspend_device(udev); 54 + usb_unlock_device(udev); 55 + 56 + return ret; 57 + } 58 + EXPORT_SYMBOL_GPL(usb_offload_get); 59 + 60 + /** 61 + * usb_offload_put - drop the offload_usage of a USB device 62 + * @udev: the USB device to drop its offload_usage 63 + * 64 + * The inverse operation of usb_offload_get, which drops the offload_usage of 65 + * a USB device. This information allows the USB driver to adjust its power 66 + * management policy based on offload activity. 67 + * 68 + * Return: 0 on success. A negative error code otherwise. 69 + */ 70 + int usb_offload_put(struct usb_device *udev) 71 + { 72 + int ret; 73 + 74 + usb_lock_device(udev); 75 + if (udev->state == USB_STATE_NOTATTACHED) { 76 + usb_unlock_device(udev); 77 + return -ENODEV; 78 + } 79 + 80 + if (udev->state == USB_STATE_SUSPENDED || 81 + udev->offload_at_suspend) { 82 + usb_unlock_device(udev); 83 + return -EBUSY; 84 + } 85 + 86 + /* 87 + * offload_usage could only be modified when the device is active, since 88 + * it will alter the suspend flow of the device. 89 + */ 90 + ret = usb_autoresume_device(udev); 91 + if (ret < 0) { 92 + usb_unlock_device(udev); 93 + return ret; 94 + } 95 + 96 + /* Drop the count when it wasn't 0, ignore the operation otherwise. */ 97 + if (udev->offload_usage) 98 + udev->offload_usage--; 99 + usb_autosuspend_device(udev); 100 + usb_unlock_device(udev); 101 + 102 + return ret; 103 + } 104 + EXPORT_SYMBOL_GPL(usb_offload_put); 105 + 106 + /** 107 + * usb_offload_check - check offload activities on a USB device 108 + * @udev: the USB device to check its offload activity. 109 + * 110 + * Check if there are any offload activity on the USB device right now. This 111 + * information could be used for power management or other forms of resource 112 + * management. 113 + * 114 + * The caller must hold @udev's device lock. In addition, the caller should 115 + * ensure downstream usb devices are all either suspended or marked as 116 + * "offload_at_suspend" to ensure the correctness of the return value. 117 + * 118 + * Returns true on any offload activity, false otherwise. 119 + */ 120 + bool usb_offload_check(struct usb_device *udev) __must_hold(&udev->dev->mutex) 121 + { 122 + struct usb_device *child; 123 + bool active; 124 + int port1; 125 + 126 + usb_hub_for_each_child(udev, port1, child) { 127 + usb_lock_device(child); 128 + active = usb_offload_check(child); 129 + usb_unlock_device(child); 130 + if (active) 131 + return true; 132 + } 133 + 134 + return !!udev->offload_usage; 135 + } 136 + EXPORT_SYMBOL_GPL(usb_offload_check);
+10 -4
drivers/usb/core/urb.c
··· 372 372 struct usb_host_endpoint *ep; 373 373 int is_out; 374 374 unsigned int allowed; 375 + bool is_eusb2_isoch_double; 375 376 376 377 if (!urb || !urb->complete) 377 378 return -EINVAL; ··· 435 434 return -ENODEV; 436 435 437 436 max = usb_endpoint_maxp(&ep->desc); 438 - if (max <= 0) { 437 + is_eusb2_isoch_double = usb_endpoint_is_hs_isoc_double(dev, ep); 438 + if (!max && !is_eusb2_isoch_double) { 439 439 dev_dbg(&dev->dev, 440 440 "bogus endpoint ep%d%s in %s (bad maxpacket %d)\n", 441 441 usb_endpoint_num(&ep->desc), is_out ? "out" : "in", ··· 469 467 max = le32_to_cpu(isoc_ep_comp->dwBytesPerInterval); 470 468 } 471 469 472 - /* "high bandwidth" mode, 1-3 packets/uframe? */ 473 - if (dev->speed == USB_SPEED_HIGH) 474 - max *= usb_endpoint_maxp_mult(&ep->desc); 470 + /* High speed, 1-3 packets/uframe, max 6 for eUSB2 double bw */ 471 + if (dev->speed == USB_SPEED_HIGH) { 472 + if (is_eusb2_isoch_double) 473 + max = le32_to_cpu(ep->eusb2_isoc_ep_comp.dwBytesPerInterval); 474 + else 475 + max *= usb_endpoint_maxp_mult(&ep->desc); 476 + } 475 477 476 478 if (urb->number_of_packets <= 0) 477 479 return -EINVAL;
+51
drivers/usb/core/usb.c
··· 670 670 set_dev_node(&dev->dev, dev_to_node(bus->sysdev)); 671 671 dev->state = USB_STATE_ATTACHED; 672 672 dev->lpm_disable_count = 1; 673 + dev->offload_usage = 0; 673 674 atomic_set(&dev->urbnum, 0); 674 675 675 676 INIT_LIST_HEAD(&dev->ep0.urb_list); ··· 1110 1109 dma_free_noncontiguous(dmadev, size, table, dir); 1111 1110 } 1112 1111 EXPORT_SYMBOL_GPL(usb_free_noncoherent); 1112 + 1113 + /** 1114 + * usb_endpoint_max_periodic_payload - Get maximum payload bytes per service 1115 + * interval 1116 + * @udev: The USB device 1117 + * @ep: The endpoint 1118 + * 1119 + * Returns: the maximum number of bytes isochronous or interrupt endpoint @ep 1120 + * can transfer during a service interval, or 0 for other endpoints. 1121 + */ 1122 + u32 usb_endpoint_max_periodic_payload(struct usb_device *udev, 1123 + const struct usb_host_endpoint *ep) 1124 + { 1125 + if (!usb_endpoint_xfer_isoc(&ep->desc) && 1126 + !usb_endpoint_xfer_int(&ep->desc)) 1127 + return 0; 1128 + 1129 + switch (udev->speed) { 1130 + case USB_SPEED_SUPER_PLUS: 1131 + if (USB_SS_SSP_ISOC_COMP(ep->ss_ep_comp.bmAttributes)) 1132 + return le32_to_cpu(ep->ssp_isoc_ep_comp.dwBytesPerInterval); 1133 + fallthrough; 1134 + case USB_SPEED_SUPER: 1135 + return le16_to_cpu(ep->ss_ep_comp.wBytesPerInterval); 1136 + default: 1137 + if (usb_endpoint_is_hs_isoc_double(udev, ep)) 1138 + return le32_to_cpu(ep->eusb2_isoc_ep_comp.dwBytesPerInterval); 1139 + return usb_endpoint_maxp(&ep->desc) * usb_endpoint_maxp_mult(&ep->desc); 1140 + } 1141 + } 1142 + EXPORT_SYMBOL_GPL(usb_endpoint_max_periodic_payload); 1143 + 1144 + /** 1145 + * usb_endpoint_is_hs_isoc_double - Tell whether an endpoint uses USB 2 1146 + * Isochronous Double IN Bandwidth 1147 + * @udev: The USB device 1148 + * @ep: The endpoint 1149 + * 1150 + * Returns: true if an endpoint @ep conforms to USB 2 Isochronous Double IN 1151 + * Bandwidth ECN, false otherwise. 1152 + */ 1153 + bool usb_endpoint_is_hs_isoc_double(struct usb_device *udev, 1154 + const struct usb_host_endpoint *ep) 1155 + { 1156 + return ep->eusb2_isoc_ep_comp.bDescriptorType && 1157 + le16_to_cpu(udev->descriptor.bcdUSB) == 0x220 && 1158 + usb_endpoint_is_isoc_in(&ep->desc) && 1159 + !le16_to_cpu(ep->desc.wMaxPacketSize); 1160 + } 1161 + EXPORT_SYMBOL_GPL(usb_endpoint_is_hs_isoc_double); 1113 1162 1114 1163 /* 1115 1164 * Notifications of device and interface registration
+26
drivers/usb/dwc2/params.c
··· 1029 1029 return 0; 1030 1030 } 1031 1031 1032 + static int dwc2_limit_speed(struct dwc2_hsotg *hsotg) 1033 + { 1034 + enum usb_device_speed usb_speed; 1035 + 1036 + usb_speed = usb_get_maximum_speed(hsotg->dev); 1037 + switch (usb_speed) { 1038 + case USB_SPEED_LOW: 1039 + dev_err(hsotg->dev, "Maximum speed cannot be forced to low-speed\n"); 1040 + return -EINVAL; 1041 + case USB_SPEED_FULL: 1042 + if (hsotg->params.speed == DWC2_SPEED_PARAM_LOW) 1043 + break; 1044 + hsotg->params.speed = DWC2_SPEED_PARAM_FULL; 1045 + break; 1046 + default: 1047 + break; 1048 + } 1049 + 1050 + return 0; 1051 + } 1052 + 1032 1053 typedef void (*set_params_cb)(struct dwc2_hsotg *data); 1033 1054 1034 1055 int dwc2_init_params(struct dwc2_hsotg *hsotg) 1035 1056 { 1036 1057 set_params_cb set_params; 1058 + int ret; 1037 1059 1038 1060 dwc2_set_default_params(hsotg); 1039 1061 dwc2_get_device_properties(hsotg); ··· 1072 1050 set_params(hsotg); 1073 1051 } 1074 1052 } 1053 + 1054 + ret = dwc2_limit_speed(hsotg); 1055 + if (ret) 1056 + return ret; 1075 1057 1076 1058 dwc2_check_params(hsotg); 1077 1059
+11
drivers/usb/dwc3/Kconfig
··· 189 189 or dual-role mode. 190 190 Say 'Y' or 'M' if you have such device. 191 191 192 + config USB_DWC3_GENERIC_PLAT 193 + tristate "DWC3 Generic Platform Driver" 194 + depends on OF && COMMON_CLK 195 + default USB_DWC3 196 + help 197 + Support USB3 functionality in simple SoC integrations. 198 + Currently supports SpacemiT DWC USB3. Platforms using 199 + dwc3-of-simple can easily switch to dwc3-generic by flattening 200 + the dwc3 child node in the device tree. 201 + Say 'Y' or 'M' here if your platform integrates DWC3 in a similar way. 202 + 192 203 endif
+1
drivers/usb/dwc3/Makefile
··· 57 57 obj-$(CONFIG_USB_DWC3_XILINX) += dwc3-xilinx.o 58 58 obj-$(CONFIG_USB_DWC3_OCTEON) += dwc3-octeon.o 59 59 obj-$(CONFIG_USB_DWC3_RTK) += dwc3-rtk.o 60 + obj-$(CONFIG_USB_DWC3_GENERIC_PLAT) += dwc3-generic-plat.o
+2
drivers/usb/dwc3/core.c
··· 156 156 dwc3_writel(dwc->regs, DWC3_GCTL, reg); 157 157 158 158 dwc->current_dr_role = mode; 159 + trace_dwc3_set_prtcap(mode); 159 160 } 160 161 161 162 static void __dwc3_set_mode(struct work_struct *work) ··· 2352 2351 return -ENOMEM; 2353 2352 2354 2353 dwc->dev = &pdev->dev; 2354 + dwc->glue_ops = NULL; 2355 2355 2356 2356 probe_data.dwc = dwc; 2357 2357 probe_data.res = res;
+26
drivers/usb/dwc3/core.h
··· 993 993 }; 994 994 995 995 /** 996 + * struct dwc3_glue_ops - The ops indicate the notifications that 997 + * need to be passed on to glue layer 998 + * @pre_set_role: Notify glue of role switch notifications 999 + * @pre_run_stop: Notify run stop enable/disable information to glue 1000 + */ 1001 + struct dwc3_glue_ops { 1002 + void (*pre_set_role)(struct dwc3 *dwc, enum usb_role role); 1003 + void (*pre_run_stop)(struct dwc3 *dwc, bool is_on); 1004 + }; 1005 + 1006 + /** 996 1007 * struct dwc3 - representation of our controller 997 1008 * @drd_work: workqueue used for role swapping 998 1009 * @ep0_trb: trb which is used for the ctrl_req ··· 1023 1012 * @eps: endpoint array 1024 1013 * @gadget: device side representation of the peripheral controller 1025 1014 * @gadget_driver: pointer to the gadget driver 1015 + * @glue_ops: Vendor callbacks for flattened device implementations. 1026 1016 * @bus_clk: clock for accessing the registers 1027 1017 * @ref_clk: reference clock 1028 1018 * @susp_clk: clock used when the SS phy is in low power (S3) state ··· 1208 1196 1209 1197 struct usb_gadget *gadget; 1210 1198 struct usb_gadget_driver *gadget_driver; 1199 + 1200 + const struct dwc3_glue_ops *glue_ops; 1211 1201 1212 1202 struct clk *bus_clk; 1213 1203 struct clk *ref_clk; ··· 1627 1613 1628 1614 int dwc3_core_soft_reset(struct dwc3 *dwc); 1629 1615 void dwc3_enable_susphy(struct dwc3 *dwc, bool enable); 1616 + 1617 + static inline void dwc3_pre_set_role(struct dwc3 *dwc, enum usb_role role) 1618 + { 1619 + if (dwc->glue_ops && dwc->glue_ops->pre_set_role) 1620 + dwc->glue_ops->pre_set_role(dwc, role); 1621 + } 1622 + 1623 + static inline void dwc3_pre_run_stop(struct dwc3 *dwc, bool is_on) 1624 + { 1625 + if (dwc->glue_ops && dwc->glue_ops->pre_run_stop) 1626 + dwc->glue_ops->pre_run_stop(dwc, is_on); 1627 + } 1630 1628 1631 1629 #if IS_ENABLED(CONFIG_USB_DWC3_HOST) || IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE) 1632 1630 int dwc3_host_init(struct dwc3 *dwc);
+18
drivers/usb/dwc3/debug.h
··· 14 14 #include "core.h" 15 15 16 16 /** 17 + * dwc3_mode_string - returns mode name 18 + * @mode: GCTL.PrtCapDir value 19 + */ 20 + static inline const char *dwc3_mode_string(u32 mode) 21 + { 22 + switch (mode) { 23 + case DWC3_GCTL_PRTCAP_HOST: 24 + return "host"; 25 + case DWC3_GCTL_PRTCAP_DEVICE: 26 + return "device"; 27 + case DWC3_GCTL_PRTCAP_OTG: 28 + return "otg"; 29 + default: 30 + return "UNKNOWN"; 31 + } 32 + } 33 + 34 + /** 17 35 * dwc3_gadget_ep_cmd_string - returns endpoint command string 18 36 * @cmd: command code 19 37 */
+5 -7
drivers/usb/dwc3/debugfs.c
··· 402 402 struct dwc3 *dwc = s->private; 403 403 unsigned long flags; 404 404 u32 reg; 405 + u32 mode; 405 406 int ret; 406 407 407 408 ret = pm_runtime_resume_and_get(dwc->dev); ··· 413 412 reg = dwc3_readl(dwc->regs, DWC3_GCTL); 414 413 spin_unlock_irqrestore(&dwc->lock, flags); 415 414 416 - switch (DWC3_GCTL_PRTCAP(reg)) { 415 + mode = DWC3_GCTL_PRTCAP(reg); 416 + switch (mode) { 417 417 case DWC3_GCTL_PRTCAP_HOST: 418 - seq_puts(s, "host\n"); 419 - break; 420 418 case DWC3_GCTL_PRTCAP_DEVICE: 421 - seq_puts(s, "device\n"); 422 - break; 423 419 case DWC3_GCTL_PRTCAP_OTG: 424 - seq_puts(s, "otg\n"); 420 + seq_printf(s, "%s\n", dwc3_mode_string(mode)); 425 421 break; 426 422 default: 427 - seq_printf(s, "UNKNOWN %08x\n", DWC3_GCTL_PRTCAP(reg)); 423 + seq_printf(s, "UNKNOWN %08x\n", mode); 428 424 } 429 425 430 426 pm_runtime_put_sync(dwc->dev);
+1
drivers/usb/dwc3/drd.c
··· 464 464 break; 465 465 } 466 466 467 + dwc3_pre_set_role(dwc, role); 467 468 dwc3_set_mode(dwc, mode); 468 469 return 0; 469 470 }
+166
drivers/usb/dwc3/dwc3-generic-plat.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + /* 3 + * dwc3-generic-plat.c - DesignWare USB3 generic platform driver 4 + * 5 + * Copyright (C) 2025 Ze Huang <huang.ze@linux.dev> 6 + * 7 + * Inspired by dwc3-qcom.c and dwc3-of-simple.c 8 + */ 9 + 10 + #include <linux/clk.h> 11 + #include <linux/platform_device.h> 12 + #include <linux/reset.h> 13 + #include "glue.h" 14 + 15 + struct dwc3_generic { 16 + struct device *dev; 17 + struct dwc3 dwc; 18 + struct clk_bulk_data *clks; 19 + int num_clocks; 20 + struct reset_control *resets; 21 + }; 22 + 23 + #define to_dwc3_generic(d) container_of((d), struct dwc3_generic, dwc) 24 + 25 + static void dwc3_generic_reset_control_assert(void *data) 26 + { 27 + reset_control_assert(data); 28 + } 29 + 30 + static int dwc3_generic_probe(struct platform_device *pdev) 31 + { 32 + struct dwc3_probe_data probe_data = {}; 33 + struct device *dev = &pdev->dev; 34 + struct dwc3_generic *dwc3g; 35 + struct resource *res; 36 + int ret; 37 + 38 + dwc3g = devm_kzalloc(dev, sizeof(*dwc3g), GFP_KERNEL); 39 + if (!dwc3g) 40 + return -ENOMEM; 41 + 42 + dwc3g->dev = dev; 43 + 44 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 45 + if (!res) { 46 + dev_err(&pdev->dev, "missing memory resource\n"); 47 + return -ENODEV; 48 + } 49 + 50 + dwc3g->resets = devm_reset_control_array_get_optional_exclusive(dev); 51 + if (IS_ERR(dwc3g->resets)) 52 + return dev_err_probe(dev, PTR_ERR(dwc3g->resets), "failed to get resets\n"); 53 + 54 + ret = reset_control_assert(dwc3g->resets); 55 + if (ret) 56 + return dev_err_probe(dev, ret, "failed to assert resets\n"); 57 + 58 + /* Not strict timing, just for safety */ 59 + udelay(2); 60 + 61 + ret = reset_control_deassert(dwc3g->resets); 62 + if (ret) 63 + return dev_err_probe(dev, ret, "failed to deassert resets\n"); 64 + 65 + ret = devm_add_action_or_reset(dev, dwc3_generic_reset_control_assert, dwc3g->resets); 66 + if (ret) 67 + return ret; 68 + 69 + ret = devm_clk_bulk_get_all_enabled(dwc3g->dev, &dwc3g->clks); 70 + if (ret < 0) 71 + return dev_err_probe(dev, ret, "failed to get clocks\n"); 72 + 73 + dwc3g->num_clocks = ret; 74 + dwc3g->dwc.dev = dev; 75 + probe_data.dwc = &dwc3g->dwc; 76 + probe_data.res = res; 77 + probe_data.ignore_clocks_and_resets = true; 78 + ret = dwc3_core_probe(&probe_data); 79 + if (ret) 80 + return dev_err_probe(dev, ret, "failed to register DWC3 Core\n"); 81 + 82 + return 0; 83 + } 84 + 85 + static void dwc3_generic_remove(struct platform_device *pdev) 86 + { 87 + struct dwc3 *dwc = platform_get_drvdata(pdev); 88 + struct dwc3_generic *dwc3g = to_dwc3_generic(dwc); 89 + 90 + dwc3_core_remove(dwc); 91 + 92 + clk_bulk_disable_unprepare(dwc3g->num_clocks, dwc3g->clks); 93 + } 94 + 95 + static int dwc3_generic_suspend(struct device *dev) 96 + { 97 + struct dwc3 *dwc = dev_get_drvdata(dev); 98 + struct dwc3_generic *dwc3g = to_dwc3_generic(dwc); 99 + int ret; 100 + 101 + ret = dwc3_pm_suspend(dwc); 102 + if (ret) 103 + return ret; 104 + 105 + clk_bulk_disable_unprepare(dwc3g->num_clocks, dwc3g->clks); 106 + 107 + return 0; 108 + } 109 + 110 + static int dwc3_generic_resume(struct device *dev) 111 + { 112 + struct dwc3 *dwc = dev_get_drvdata(dev); 113 + struct dwc3_generic *dwc3g = to_dwc3_generic(dwc); 114 + int ret; 115 + 116 + ret = clk_bulk_prepare_enable(dwc3g->num_clocks, dwc3g->clks); 117 + if (ret) 118 + return ret; 119 + 120 + ret = dwc3_pm_resume(dwc); 121 + if (ret) 122 + return ret; 123 + 124 + return 0; 125 + } 126 + 127 + static int dwc3_generic_runtime_suspend(struct device *dev) 128 + { 129 + return dwc3_runtime_suspend(dev_get_drvdata(dev)); 130 + } 131 + 132 + static int dwc3_generic_runtime_resume(struct device *dev) 133 + { 134 + return dwc3_runtime_resume(dev_get_drvdata(dev)); 135 + } 136 + 137 + static int dwc3_generic_runtime_idle(struct device *dev) 138 + { 139 + return dwc3_runtime_idle(dev_get_drvdata(dev)); 140 + } 141 + 142 + static const struct dev_pm_ops dwc3_generic_dev_pm_ops = { 143 + SYSTEM_SLEEP_PM_OPS(dwc3_generic_suspend, dwc3_generic_resume) 144 + RUNTIME_PM_OPS(dwc3_generic_runtime_suspend, dwc3_generic_runtime_resume, 145 + dwc3_generic_runtime_idle) 146 + }; 147 + 148 + static const struct of_device_id dwc3_generic_of_match[] = { 149 + { .compatible = "spacemit,k1-dwc3", }, 150 + { /* sentinel */ } 151 + }; 152 + MODULE_DEVICE_TABLE(of, dwc3_generic_of_match); 153 + 154 + static struct platform_driver dwc3_generic_driver = { 155 + .probe = dwc3_generic_probe, 156 + .remove = dwc3_generic_remove, 157 + .driver = { 158 + .name = "dwc3-generic-plat", 159 + .of_match_table = dwc3_generic_of_match, 160 + .pm = pm_ptr(&dwc3_generic_dev_pm_ops), 161 + }, 162 + }; 163 + module_platform_driver(dwc3_generic_driver); 164 + 165 + MODULE_LICENSE("GPL"); 166 + MODULE_DESCRIPTION("DesignWare USB3 generic platform driver");
+74 -100
drivers/usb/dwc3/dwc3-qcom.c
··· 11 11 #include <linux/of_clk.h> 12 12 #include <linux/module.h> 13 13 #include <linux/kernel.h> 14 - #include <linux/extcon.h> 15 14 #include <linux/interconnect.h> 16 15 #include <linux/platform_device.h> 17 16 #include <linux/phy/phy.h> ··· 78 79 struct dwc3_qcom_port ports[DWC3_QCOM_MAX_PORTS]; 79 80 u8 num_ports; 80 81 81 - struct extcon_dev *edev; 82 - struct extcon_dev *host_edev; 83 - struct notifier_block vbus_nb; 84 - struct notifier_block host_nb; 85 - 86 82 enum usb_dr_mode mode; 87 83 bool is_suspended; 88 84 bool pm_suspended; 89 85 struct icc_path *icc_path_ddr; 90 86 struct icc_path *icc_path_apps; 87 + 88 + enum usb_role current_role; 91 89 }; 92 90 93 91 #define to_dwc3_qcom(d) container_of((d), struct dwc3_qcom, dwc) ··· 113 117 readl(base + offset); 114 118 } 115 119 116 - /* 117 - * TODO: Make the in-core role switching code invoke dwc3_qcom_vbus_override_enable(), 118 - * validate that the in-core extcon support is functional, and drop extcon 119 - * handling from the glue 120 - */ 121 120 static void dwc3_qcom_vbus_override_enable(struct dwc3_qcom *qcom, bool enable) 122 121 { 123 122 if (enable) { ··· 126 135 dwc3_qcom_clrbits(qcom->qscratch_base, QSCRATCH_HS_PHY_CTRL, 127 136 UTMI_OTG_VBUS_VALID | SW_SESSVLD_SEL); 128 137 } 129 - } 130 - 131 - static int dwc3_qcom_vbus_notifier(struct notifier_block *nb, 132 - unsigned long event, void *ptr) 133 - { 134 - struct dwc3_qcom *qcom = container_of(nb, struct dwc3_qcom, vbus_nb); 135 - 136 - /* enable vbus override for device mode */ 137 - dwc3_qcom_vbus_override_enable(qcom, event); 138 - qcom->mode = event ? USB_DR_MODE_PERIPHERAL : USB_DR_MODE_HOST; 139 - 140 - return NOTIFY_DONE; 141 - } 142 - 143 - static int dwc3_qcom_host_notifier(struct notifier_block *nb, 144 - unsigned long event, void *ptr) 145 - { 146 - struct dwc3_qcom *qcom = container_of(nb, struct dwc3_qcom, host_nb); 147 - 148 - /* disable vbus override in host mode */ 149 - dwc3_qcom_vbus_override_enable(qcom, !event); 150 - qcom->mode = event ? USB_DR_MODE_HOST : USB_DR_MODE_PERIPHERAL; 151 - 152 - return NOTIFY_DONE; 153 - } 154 - 155 - static int dwc3_qcom_register_extcon(struct dwc3_qcom *qcom) 156 - { 157 - struct device *dev = qcom->dev; 158 - struct extcon_dev *host_edev; 159 - int ret; 160 - 161 - if (!of_property_present(dev->of_node, "extcon")) 162 - return 0; 163 - 164 - qcom->edev = extcon_get_edev_by_phandle(dev, 0); 165 - if (IS_ERR(qcom->edev)) 166 - return dev_err_probe(dev, PTR_ERR(qcom->edev), 167 - "Failed to get extcon\n"); 168 - 169 - qcom->vbus_nb.notifier_call = dwc3_qcom_vbus_notifier; 170 - 171 - qcom->host_edev = extcon_get_edev_by_phandle(dev, 1); 172 - if (IS_ERR(qcom->host_edev)) 173 - qcom->host_edev = NULL; 174 - 175 - ret = devm_extcon_register_notifier(dev, qcom->edev, EXTCON_USB, 176 - &qcom->vbus_nb); 177 - if (ret < 0) { 178 - dev_err(dev, "VBUS notifier register failed\n"); 179 - return ret; 180 - } 181 - 182 - if (qcom->host_edev) 183 - host_edev = qcom->host_edev; 184 - else 185 - host_edev = qcom->edev; 186 - 187 - qcom->host_nb.notifier_call = dwc3_qcom_host_notifier; 188 - ret = devm_extcon_register_notifier(dev, host_edev, EXTCON_USB_HOST, 189 - &qcom->host_nb); 190 - if (ret < 0) { 191 - dev_err(dev, "Host notifier register failed\n"); 192 - return ret; 193 - } 194 - 195 - /* Update initial VBUS override based on extcon state */ 196 - if (extcon_get_state(qcom->edev, EXTCON_USB) || 197 - !extcon_get_state(host_edev, EXTCON_USB_HOST)) 198 - dwc3_qcom_vbus_notifier(&qcom->vbus_nb, true, qcom->edev); 199 - else 200 - dwc3_qcom_vbus_notifier(&qcom->vbus_nb, false, qcom->edev); 201 - 202 - return 0; 203 138 } 204 139 205 140 static int dwc3_qcom_interconnect_enable(struct dwc3_qcom *qcom) ··· 558 641 return 0; 559 642 } 560 643 644 + static void dwc3_qcom_set_role_notifier(struct dwc3 *dwc, enum usb_role next_role) 645 + { 646 + struct dwc3_qcom *qcom = to_dwc3_qcom(dwc); 647 + 648 + if (qcom->current_role == next_role) 649 + return; 650 + 651 + if (pm_runtime_resume_and_get(qcom->dev)) { 652 + dev_dbg(qcom->dev, "Failed to resume device\n"); 653 + return; 654 + } 655 + 656 + if (qcom->current_role == USB_ROLE_DEVICE) 657 + dwc3_qcom_vbus_override_enable(qcom, false); 658 + else if (qcom->current_role != USB_ROLE_DEVICE) 659 + dwc3_qcom_vbus_override_enable(qcom, true); 660 + 661 + pm_runtime_mark_last_busy(qcom->dev); 662 + pm_runtime_put_sync(qcom->dev); 663 + 664 + /* 665 + * Current role changes via usb_role_switch_set_role callback protected 666 + * internally by mutex lock. 667 + */ 668 + qcom->current_role = next_role; 669 + } 670 + 671 + static void dwc3_qcom_run_stop_notifier(struct dwc3 *dwc, bool is_on) 672 + { 673 + struct dwc3_qcom *qcom = to_dwc3_qcom(dwc); 674 + 675 + /* 676 + * When autosuspend is enabled and controller goes to suspend 677 + * after removing UDC from userspace, the next UDC write needs 678 + * setting of QSCRATCH VBUS_VALID to "1" to generate a connect 679 + * done event. 680 + */ 681 + if (!is_on) 682 + return; 683 + 684 + dwc3_qcom_vbus_override_enable(qcom, true); 685 + pm_runtime_mark_last_busy(qcom->dev); 686 + } 687 + 688 + struct dwc3_glue_ops dwc3_qcom_glue_ops = { 689 + .pre_set_role = dwc3_qcom_set_role_notifier, 690 + .pre_run_stop = dwc3_qcom_run_stop_notifier, 691 + }; 692 + 561 693 static int dwc3_qcom_probe(struct platform_device *pdev) 562 694 { 563 695 struct dwc3_probe_data probe_data = {}; ··· 683 717 if (ignore_pipe_clk) 684 718 dwc3_qcom_select_utmi_clk(qcom); 685 719 720 + qcom->mode = usb_get_dr_mode(dev); 721 + 722 + if (qcom->mode == USB_DR_MODE_HOST) { 723 + qcom->current_role = USB_ROLE_HOST; 724 + } else if (qcom->mode == USB_DR_MODE_PERIPHERAL) { 725 + qcom->current_role = USB_ROLE_DEVICE; 726 + dwc3_qcom_vbus_override_enable(qcom, true); 727 + } else { 728 + if ((device_property_read_bool(dev, "usb-role-switch")) && 729 + (usb_get_role_switch_default_mode(dev) == USB_DR_MODE_HOST)) 730 + qcom->current_role = USB_ROLE_HOST; 731 + else 732 + qcom->current_role = USB_ROLE_DEVICE; 733 + } 734 + 735 + qcom->dwc.glue_ops = &dwc3_qcom_glue_ops; 736 + 686 737 qcom->dwc.dev = dev; 687 738 probe_data.dwc = &qcom->dwc; 688 739 probe_data.res = &res; ··· 714 731 if (ret) 715 732 goto remove_core; 716 733 717 - qcom->mode = usb_get_dr_mode(dev); 718 - 719 - /* enable vbus override for device mode */ 720 - if (qcom->mode != USB_DR_MODE_HOST) 721 - dwc3_qcom_vbus_override_enable(qcom, true); 722 - 723 - /* register extcon to override sw_vbus on Vbus change later */ 724 - ret = dwc3_qcom_register_extcon(qcom); 725 - if (ret) 726 - goto interconnect_exit; 727 - 728 734 wakeup_source = of_property_read_bool(dev->of_node, "wakeup-source"); 729 735 device_init_wakeup(&pdev->dev, wakeup_source); 730 736 ··· 721 749 722 750 return 0; 723 751 724 - interconnect_exit: 725 - dwc3_qcom_interconnect_exit(qcom); 726 752 remove_core: 727 753 dwc3_core_remove(&qcom->dwc); 728 754 clk_disable: ··· 734 764 struct dwc3 *dwc = platform_get_drvdata(pdev); 735 765 struct dwc3_qcom *qcom = to_dwc3_qcom(dwc); 736 766 767 + if (pm_runtime_resume_and_get(qcom->dev) < 0) 768 + return; 769 + 737 770 dwc3_core_remove(&qcom->dwc); 738 - 739 771 clk_bulk_disable_unprepare(qcom->num_clocks, qcom->clks); 740 - 741 772 dwc3_qcom_interconnect_exit(qcom); 773 + 774 + pm_runtime_put_noidle(qcom->dev); 742 775 } 743 776 744 777 static int dwc3_qcom_pm_suspend(struct device *dev) ··· 846 873 static struct platform_driver dwc3_qcom_driver = { 847 874 .probe = dwc3_qcom_probe, 848 875 .remove = dwc3_qcom_remove, 876 + .shutdown = dwc3_qcom_remove, 849 877 .driver = { 850 878 .name = "dwc3-qcom", 851 879 .pm = pm_ptr(&dwc3_qcom_dev_pm_ops),
+1
drivers/usb/dwc3/gadget.c
··· 2662 2662 dwc->pullups_connected = false; 2663 2663 } 2664 2664 2665 + dwc3_pre_run_stop(dwc, is_on); 2665 2666 dwc3_gadget_dctl_write_safe(dwc, reg); 2666 2667 2667 2668 do {
+17
drivers/usb/dwc3/trace.h
··· 19 19 #include "core.h" 20 20 #include "debug.h" 21 21 22 + DECLARE_EVENT_CLASS(dwc3_log_set_prtcap, 23 + TP_PROTO(u32 mode), 24 + TP_ARGS(mode), 25 + TP_STRUCT__entry( 26 + __field(u32, mode) 27 + ), 28 + TP_fast_assign( 29 + __entry->mode = mode; 30 + ), 31 + TP_printk("mode %s", dwc3_mode_string(__entry->mode)) 32 + ); 33 + 34 + DEFINE_EVENT(dwc3_log_set_prtcap, dwc3_set_prtcap, 35 + TP_PROTO(u32 mode), 36 + TP_ARGS(mode) 37 + ); 38 + 22 39 DECLARE_EVENT_CLASS(dwc3_log_io, 23 40 TP_PROTO(void *base, u32 offset, u32 value), 24 41 TP_ARGS(base, offset, value),
+2
drivers/usb/gadget/configfs.c
··· 1750 1750 cdev->use_os_string = true; 1751 1751 cdev->b_vendor_code = gi->b_vendor_code; 1752 1752 memcpy(cdev->qw_sign, gi->qw_sign, OS_STRING_QW_SIGN_LEN); 1753 + } else { 1754 + cdev->use_os_string = false; 1753 1755 } 1754 1756 1755 1757 if (gadget_is_otg(gadget) && !otg_desc[0]) {
+19 -23
drivers/usb/gadget/function/f_acm.c
··· 11 11 12 12 /* #define VERBOSE_DEBUG */ 13 13 14 + #include <linux/cleanup.h> 14 15 #include <linux/slab.h> 15 16 #include <linux/kernel.h> 16 17 #include <linux/module.h> 17 18 #include <linux/device.h> 18 19 #include <linux/err.h> 20 + 21 + #include <linux/usb/gadget.h> 19 22 20 23 #include "u_serial.h" 21 24 ··· 616 613 struct usb_string *us; 617 614 int status; 618 615 struct usb_ep *ep; 616 + struct usb_request *request __free(free_usb_request) = NULL; 619 617 620 618 /* REVISIT might want instance-specific strings to help 621 619 * distinguish instances ... ··· 634 630 /* allocate instance-specific interface IDs, and patch descriptors */ 635 631 status = usb_interface_id(c, f); 636 632 if (status < 0) 637 - goto fail; 633 + return status; 638 634 acm->ctrl_id = status; 639 635 acm_iad_descriptor.bFirstInterface = status; 640 636 ··· 643 639 644 640 status = usb_interface_id(c, f); 645 641 if (status < 0) 646 - goto fail; 642 + return status; 647 643 acm->data_id = status; 648 644 649 645 acm_data_interface_desc.bInterfaceNumber = status; 650 646 acm_union_desc.bSlaveInterface0 = status; 651 647 acm_call_mgmt_descriptor.bDataInterface = status; 652 648 653 - status = -ENODEV; 654 - 655 649 /* allocate instance-specific endpoints */ 656 650 ep = usb_ep_autoconfig(cdev->gadget, &acm_fs_in_desc); 657 651 if (!ep) 658 - goto fail; 652 + return -ENODEV; 659 653 acm->port.in = ep; 660 654 661 655 ep = usb_ep_autoconfig(cdev->gadget, &acm_fs_out_desc); 662 656 if (!ep) 663 - goto fail; 657 + return -ENODEV; 664 658 acm->port.out = ep; 665 659 666 660 ep = usb_ep_autoconfig(cdev->gadget, &acm_fs_notify_desc); 667 661 if (!ep) 668 - goto fail; 662 + return -ENODEV; 669 663 acm->notify = ep; 670 664 671 665 acm_iad_descriptor.bFunctionProtocol = acm->bInterfaceProtocol; 672 666 acm_control_interface_desc.bInterfaceProtocol = acm->bInterfaceProtocol; 673 667 674 668 /* allocate notification */ 675 - acm->notify_req = gs_alloc_req(ep, 676 - sizeof(struct usb_cdc_notification) + 2, 677 - GFP_KERNEL); 678 - if (!acm->notify_req) 679 - goto fail; 669 + request = gs_alloc_req(ep, 670 + sizeof(struct usb_cdc_notification) + 2, 671 + GFP_KERNEL); 672 + if (!request) 673 + return -ENODEV; 680 674 681 - acm->notify_req->complete = acm_cdc_notify_complete; 682 - acm->notify_req->context = acm; 675 + request->complete = acm_cdc_notify_complete; 676 + request->context = acm; 683 677 684 678 /* support all relevant hardware speeds... we expect that when 685 679 * hardware is dual speed, all bulk-capable endpoints work at ··· 694 692 status = usb_assign_descriptors(f, acm_fs_function, acm_hs_function, 695 693 acm_ss_function, acm_ss_function); 696 694 if (status) 697 - goto fail; 695 + return status; 696 + 697 + acm->notify_req = no_free_ptr(request); 698 698 699 699 dev_dbg(&cdev->gadget->dev, 700 700 "acm ttyGS%d: IN/%s OUT/%s NOTIFY/%s\n", ··· 704 700 acm->port.in->name, acm->port.out->name, 705 701 acm->notify->name); 706 702 return 0; 707 - 708 - fail: 709 - if (acm->notify_req) 710 - gs_free_req(acm->notify, acm->notify_req); 711 - 712 - ERROR(cdev, "%s/%p: can't bind, err %d\n", f->name, f, status); 713 - 714 - return status; 715 703 } 716 704 717 705 static void acm_unbind(struct usb_configuration *c, struct usb_function *f)
+20 -28
drivers/usb/gadget/function/f_ecm.c
··· 8 8 9 9 /* #define VERBOSE_DEBUG */ 10 10 11 + #include <linux/cleanup.h> 11 12 #include <linux/slab.h> 12 13 #include <linux/kernel.h> 13 14 #include <linux/module.h> 14 15 #include <linux/device.h> 15 16 #include <linux/etherdevice.h> 16 17 #include <linux/string_choices.h> 18 + 19 + #include <linux/usb/gadget.h> 17 20 18 21 #include "u_ether.h" 19 22 #include "u_ether_configfs.h" ··· 681 678 struct usb_ep *ep; 682 679 683 680 struct f_ecm_opts *ecm_opts; 681 + struct usb_request *request __free(free_usb_request) = NULL; 684 682 685 683 if (!can_support_ecm(cdev->gadget)) 686 684 return -EINVAL; ··· 715 711 /* allocate instance-specific interface IDs */ 716 712 status = usb_interface_id(c, f); 717 713 if (status < 0) 718 - goto fail; 714 + return status; 719 715 ecm->ctrl_id = status; 720 716 ecm_iad_descriptor.bFirstInterface = status; 721 717 ··· 724 720 725 721 status = usb_interface_id(c, f); 726 722 if (status < 0) 727 - goto fail; 723 + return status; 728 724 ecm->data_id = status; 729 725 730 726 ecm_data_nop_intf.bInterfaceNumber = status; 731 727 ecm_data_intf.bInterfaceNumber = status; 732 728 ecm_union_desc.bSlaveInterface0 = status; 733 729 734 - status = -ENODEV; 735 - 736 730 /* allocate instance-specific endpoints */ 737 731 ep = usb_ep_autoconfig(cdev->gadget, &fs_ecm_in_desc); 738 732 if (!ep) 739 - goto fail; 733 + return -ENODEV; 740 734 ecm->port.in_ep = ep; 741 735 742 736 ep = usb_ep_autoconfig(cdev->gadget, &fs_ecm_out_desc); 743 737 if (!ep) 744 - goto fail; 738 + return -ENODEV; 745 739 ecm->port.out_ep = ep; 746 740 747 741 /* NOTE: a status/notification endpoint is *OPTIONAL* but we ··· 748 746 */ 749 747 ep = usb_ep_autoconfig(cdev->gadget, &fs_ecm_notify_desc); 750 748 if (!ep) 751 - goto fail; 749 + return -ENODEV; 752 750 ecm->notify = ep; 753 751 754 - status = -ENOMEM; 755 - 756 752 /* allocate notification request and buffer */ 757 - ecm->notify_req = usb_ep_alloc_request(ep, GFP_KERNEL); 758 - if (!ecm->notify_req) 759 - goto fail; 760 - ecm->notify_req->buf = kmalloc(ECM_STATUS_BYTECOUNT, GFP_KERNEL); 761 - if (!ecm->notify_req->buf) 762 - goto fail; 763 - ecm->notify_req->context = ecm; 764 - ecm->notify_req->complete = ecm_notify_complete; 753 + request = usb_ep_alloc_request(ep, GFP_KERNEL); 754 + if (!request) 755 + return -ENOMEM; 756 + request->buf = kmalloc(ECM_STATUS_BYTECOUNT, GFP_KERNEL); 757 + if (!request->buf) 758 + return -ENOMEM; 759 + request->context = ecm; 760 + request->complete = ecm_notify_complete; 765 761 766 762 /* support all relevant hardware speeds... we expect that when 767 763 * hardware is dual speed, all bulk-capable endpoints work at ··· 778 778 status = usb_assign_descriptors(f, ecm_fs_function, ecm_hs_function, 779 779 ecm_ss_function, ecm_ss_function); 780 780 if (status) 781 - goto fail; 781 + return status; 782 782 783 783 /* NOTE: all that is done without knowing or caring about 784 784 * the network link ... which is unavailable to this code ··· 788 788 ecm->port.open = ecm_open; 789 789 ecm->port.close = ecm_close; 790 790 791 + ecm->notify_req = no_free_ptr(request); 792 + 791 793 DBG(cdev, "CDC Ethernet: IN/%s OUT/%s NOTIFY/%s\n", 792 794 ecm->port.in_ep->name, ecm->port.out_ep->name, 793 795 ecm->notify->name); 794 796 return 0; 795 - 796 - fail: 797 - if (ecm->notify_req) { 798 - kfree(ecm->notify_req->buf); 799 - usb_ep_free_request(ecm->notify, ecm->notify_req); 800 - } 801 - 802 - ERROR(cdev, "%s: can't bind, err %d\n", f->name, status); 803 - 804 - return status; 805 797 } 806 798 807 799 static inline struct f_ecm_opts *to_f_ecm_opts(struct config_item *item)
+7 -1
drivers/usb/gadget/function/f_fs.c
··· 2407 2407 ep = func->eps; 2408 2408 epfile = ffs->epfiles; 2409 2409 count = ffs->eps_count; 2410 - while(count--) { 2410 + if (!epfile) { 2411 + ret = -ENOMEM; 2412 + goto done; 2413 + } 2414 + 2415 + while (count--) { 2411 2416 ep->ep->driver_data = ep; 2412 2417 2413 2418 ret = config_ep_by_speed(func->gadget, &func->function, ep->ep); ··· 2436 2431 } 2437 2432 2438 2433 wake_up_interruptible(&ffs->wait); 2434 + done: 2439 2435 spin_unlock_irqrestore(&func->ffs->eps_lock, flags); 2440 2436 2441 2437 return ret;
+2 -2
drivers/usb/gadget/function/f_hid.c
··· 511 511 } 512 512 513 513 req->status = 0; 514 - req->zero = 0; 514 + req->zero = 1; 515 515 req->length = count; 516 516 req->complete = f_hidg_req_complete; 517 517 req->context = hidg; ··· 967 967 return -EOPNOTSUPP; 968 968 969 969 respond: 970 - req->zero = 0; 970 + req->zero = 1; 971 971 req->length = length; 972 972 status = usb_ep_queue(cdev->gadget->ep0, req, GFP_ATOMIC); 973 973 if (status < 0)
+35 -46
drivers/usb/gadget/function/f_ncm.c
··· 11 11 * Copyright (C) 2008 Nokia Corporation 12 12 */ 13 13 14 + #include <linux/cleanup.h> 14 15 #include <linux/kernel.h> 15 16 #include <linux/interrupt.h> 16 17 #include <linux/module.h> ··· 21 20 #include <linux/string_choices.h> 22 21 23 22 #include <linux/usb/cdc.h> 23 + #include <linux/usb/gadget.h> 24 24 25 25 #include "u_ether.h" 26 26 #include "u_ether_configfs.h" ··· 1438 1436 struct usb_ep *ep; 1439 1437 struct f_ncm_opts *ncm_opts; 1440 1438 1439 + struct usb_os_desc_table *os_desc_table __free(kfree) = NULL; 1440 + struct usb_request *request __free(free_usb_request) = NULL; 1441 + 1441 1442 if (!can_support_ecm(cdev->gadget)) 1442 1443 return -EINVAL; 1443 1444 1444 1445 ncm_opts = container_of(f->fi, struct f_ncm_opts, func_inst); 1445 1446 1446 1447 if (cdev->use_os_string) { 1447 - f->os_desc_table = kzalloc(sizeof(*f->os_desc_table), 1448 - GFP_KERNEL); 1449 - if (!f->os_desc_table) 1448 + os_desc_table = kzalloc(sizeof(*os_desc_table), GFP_KERNEL); 1449 + if (!os_desc_table) 1450 1450 return -ENOMEM; 1451 - f->os_desc_n = 1; 1452 - f->os_desc_table[0].os_desc = &ncm_opts->ncm_os_desc; 1453 1451 } 1454 1452 1455 1453 mutex_lock(&ncm_opts->lock); ··· 1461 1459 mutex_unlock(&ncm_opts->lock); 1462 1460 1463 1461 if (status) 1464 - goto fail; 1462 + return status; 1465 1463 1466 1464 ncm_opts->bound = true; 1467 1465 1466 + ncm_string_defs[1].s = ncm->ethaddr; 1467 + 1468 1468 us = usb_gstrings_attach(cdev, ncm_strings, 1469 1469 ARRAY_SIZE(ncm_string_defs)); 1470 - if (IS_ERR(us)) { 1471 - status = PTR_ERR(us); 1472 - goto fail; 1473 - } 1470 + if (IS_ERR(us)) 1471 + return PTR_ERR(us); 1472 + 1474 1473 ncm_control_intf.iInterface = us[STRING_CTRL_IDX].id; 1475 1474 ncm_data_nop_intf.iInterface = us[STRING_DATA_IDX].id; 1476 1475 ncm_data_intf.iInterface = us[STRING_DATA_IDX].id; ··· 1481 1478 /* allocate instance-specific interface IDs */ 1482 1479 status = usb_interface_id(c, f); 1483 1480 if (status < 0) 1484 - goto fail; 1481 + return status; 1485 1482 ncm->ctrl_id = status; 1486 1483 ncm_iad_desc.bFirstInterface = status; 1487 1484 1488 1485 ncm_control_intf.bInterfaceNumber = status; 1489 1486 ncm_union_desc.bMasterInterface0 = status; 1490 1487 1491 - if (cdev->use_os_string) 1492 - f->os_desc_table[0].if_id = 1493 - ncm_iad_desc.bFirstInterface; 1494 - 1495 1488 status = usb_interface_id(c, f); 1496 1489 if (status < 0) 1497 - goto fail; 1490 + return status; 1498 1491 ncm->data_id = status; 1499 1492 1500 1493 ncm_data_nop_intf.bInterfaceNumber = status; ··· 1499 1500 1500 1501 ecm_desc.wMaxSegmentSize = cpu_to_le16(ncm_opts->max_segment_size); 1501 1502 1502 - status = -ENODEV; 1503 - 1504 1503 /* allocate instance-specific endpoints */ 1505 1504 ep = usb_ep_autoconfig(cdev->gadget, &fs_ncm_in_desc); 1506 1505 if (!ep) 1507 - goto fail; 1506 + return -ENODEV; 1508 1507 ncm->port.in_ep = ep; 1509 1508 1510 1509 ep = usb_ep_autoconfig(cdev->gadget, &fs_ncm_out_desc); 1511 1510 if (!ep) 1512 - goto fail; 1511 + return -ENODEV; 1513 1512 ncm->port.out_ep = ep; 1514 1513 1515 1514 ep = usb_ep_autoconfig(cdev->gadget, &fs_ncm_notify_desc); 1516 1515 if (!ep) 1517 - goto fail; 1516 + return -ENODEV; 1518 1517 ncm->notify = ep; 1519 1518 1520 - status = -ENOMEM; 1521 - 1522 1519 /* allocate notification request and buffer */ 1523 - ncm->notify_req = usb_ep_alloc_request(ep, GFP_KERNEL); 1524 - if (!ncm->notify_req) 1525 - goto fail; 1526 - ncm->notify_req->buf = kmalloc(NCM_STATUS_BYTECOUNT, GFP_KERNEL); 1527 - if (!ncm->notify_req->buf) 1528 - goto fail; 1529 - ncm->notify_req->context = ncm; 1530 - ncm->notify_req->complete = ncm_notify_complete; 1520 + request = usb_ep_alloc_request(ep, GFP_KERNEL); 1521 + if (!request) 1522 + return -ENOMEM; 1523 + request->buf = kmalloc(NCM_STATUS_BYTECOUNT, GFP_KERNEL); 1524 + if (!request->buf) 1525 + return -ENOMEM; 1526 + request->context = ncm; 1527 + request->complete = ncm_notify_complete; 1531 1528 1532 1529 /* 1533 1530 * support all relevant hardware speeds... we expect that when ··· 1543 1548 status = usb_assign_descriptors(f, ncm_fs_function, ncm_hs_function, 1544 1549 ncm_ss_function, ncm_ss_function); 1545 1550 if (status) 1546 - goto fail; 1551 + return status; 1547 1552 1548 1553 /* 1549 1554 * NOTE: all that is done without knowing or caring about ··· 1556 1561 1557 1562 hrtimer_setup(&ncm->task_timer, ncm_tx_timeout, CLOCK_MONOTONIC, HRTIMER_MODE_REL_SOFT); 1558 1563 1564 + if (cdev->use_os_string) { 1565 + os_desc_table[0].os_desc = &ncm_opts->ncm_os_desc; 1566 + os_desc_table[0].if_id = ncm_iad_desc.bFirstInterface; 1567 + f->os_desc_table = no_free_ptr(os_desc_table); 1568 + f->os_desc_n = 1; 1569 + } 1570 + ncm->notify_req = no_free_ptr(request); 1571 + 1559 1572 DBG(cdev, "CDC Network: IN/%s OUT/%s NOTIFY/%s\n", 1560 1573 ncm->port.in_ep->name, ncm->port.out_ep->name, 1561 1574 ncm->notify->name); 1562 1575 return 0; 1563 - 1564 - fail: 1565 - kfree(f->os_desc_table); 1566 - f->os_desc_n = 0; 1567 - 1568 - if (ncm->notify_req) { 1569 - kfree(ncm->notify_req->buf); 1570 - usb_ep_free_request(ncm->notify, ncm->notify_req); 1571 - } 1572 - 1573 - ERROR(cdev, "%s: can't bind, err %d\n", f->name, status); 1574 - 1575 - return status; 1576 1576 } 1577 1577 1578 1578 static inline struct f_ncm_opts *to_f_ncm_opts(struct config_item *item) ··· 1761 1771 mutex_unlock(&opts->lock); 1762 1772 return ERR_PTR(-EINVAL); 1763 1773 } 1764 - ncm_string_defs[STRING_MAC_IDX].s = ncm->ethaddr; 1765 1774 1766 1775 spin_lock_init(&ncm->lock); 1767 1776 ncm_reset_values(ncm);
+35 -50
drivers/usb/gadget/function/f_rndis.c
··· 19 19 20 20 #include <linux/atomic.h> 21 21 22 + #include <linux/usb/gadget.h> 23 + 22 24 #include "u_ether.h" 23 25 #include "u_ether_configfs.h" 24 26 #include "u_rndis.h" ··· 664 662 struct usb_ep *ep; 665 663 666 664 struct f_rndis_opts *rndis_opts; 665 + struct usb_os_desc_table *os_desc_table __free(kfree) = NULL; 666 + struct usb_request *request __free(free_usb_request) = NULL; 667 667 668 668 if (!can_support_rndis(c)) 669 669 return -EINVAL; ··· 673 669 rndis_opts = container_of(f->fi, struct f_rndis_opts, func_inst); 674 670 675 671 if (cdev->use_os_string) { 676 - f->os_desc_table = kzalloc(sizeof(*f->os_desc_table), 677 - GFP_KERNEL); 678 - if (!f->os_desc_table) 672 + os_desc_table = kzalloc(sizeof(*os_desc_table), GFP_KERNEL); 673 + if (!os_desc_table) 679 674 return -ENOMEM; 680 - f->os_desc_n = 1; 681 - f->os_desc_table[0].os_desc = &rndis_opts->rndis_os_desc; 682 675 } 683 676 684 677 rndis_iad_descriptor.bFunctionClass = rndis_opts->class; ··· 693 692 gether_set_gadget(rndis_opts->net, cdev->gadget); 694 693 status = gether_register_netdev(rndis_opts->net); 695 694 if (status) 696 - goto fail; 695 + return status; 697 696 rndis_opts->bound = true; 698 697 } 699 698 700 699 us = usb_gstrings_attach(cdev, rndis_strings, 701 700 ARRAY_SIZE(rndis_string_defs)); 702 - if (IS_ERR(us)) { 703 - status = PTR_ERR(us); 704 - goto fail; 705 - } 701 + if (IS_ERR(us)) 702 + return PTR_ERR(us); 706 703 rndis_control_intf.iInterface = us[0].id; 707 704 rndis_data_intf.iInterface = us[1].id; 708 705 rndis_iad_descriptor.iFunction = us[2].id; ··· 708 709 /* allocate instance-specific interface IDs */ 709 710 status = usb_interface_id(c, f); 710 711 if (status < 0) 711 - goto fail; 712 + return status; 712 713 rndis->ctrl_id = status; 713 714 rndis_iad_descriptor.bFirstInterface = status; 714 715 715 716 rndis_control_intf.bInterfaceNumber = status; 716 717 rndis_union_desc.bMasterInterface0 = status; 717 718 718 - if (cdev->use_os_string) 719 - f->os_desc_table[0].if_id = 720 - rndis_iad_descriptor.bFirstInterface; 721 - 722 719 status = usb_interface_id(c, f); 723 720 if (status < 0) 724 - goto fail; 721 + return status; 725 722 rndis->data_id = status; 726 723 727 724 rndis_data_intf.bInterfaceNumber = status; 728 725 rndis_union_desc.bSlaveInterface0 = status; 729 726 730 - status = -ENODEV; 731 - 732 727 /* allocate instance-specific endpoints */ 733 728 ep = usb_ep_autoconfig(cdev->gadget, &fs_in_desc); 734 729 if (!ep) 735 - goto fail; 730 + return -ENODEV; 736 731 rndis->port.in_ep = ep; 737 732 738 733 ep = usb_ep_autoconfig(cdev->gadget, &fs_out_desc); 739 734 if (!ep) 740 - goto fail; 735 + return -ENODEV; 741 736 rndis->port.out_ep = ep; 742 737 743 738 /* NOTE: a status/notification endpoint is, strictly speaking, ··· 740 747 */ 741 748 ep = usb_ep_autoconfig(cdev->gadget, &fs_notify_desc); 742 749 if (!ep) 743 - goto fail; 750 + return -ENODEV; 744 751 rndis->notify = ep; 745 752 746 - status = -ENOMEM; 747 - 748 753 /* allocate notification request and buffer */ 749 - rndis->notify_req = usb_ep_alloc_request(ep, GFP_KERNEL); 750 - if (!rndis->notify_req) 751 - goto fail; 752 - rndis->notify_req->buf = kmalloc(STATUS_BYTECOUNT, GFP_KERNEL); 753 - if (!rndis->notify_req->buf) 754 - goto fail; 755 - rndis->notify_req->length = STATUS_BYTECOUNT; 756 - rndis->notify_req->context = rndis; 757 - rndis->notify_req->complete = rndis_response_complete; 754 + request = usb_ep_alloc_request(ep, GFP_KERNEL); 755 + if (!request) 756 + return -ENOMEM; 757 + request->buf = kmalloc(STATUS_BYTECOUNT, GFP_KERNEL); 758 + if (!request->buf) 759 + return -ENOMEM; 760 + request->length = STATUS_BYTECOUNT; 761 + request->context = rndis; 762 + request->complete = rndis_response_complete; 758 763 759 764 /* support all relevant hardware speeds... we expect that when 760 765 * hardware is dual speed, all bulk-capable endpoints work at ··· 769 778 status = usb_assign_descriptors(f, eth_fs_function, eth_hs_function, 770 779 eth_ss_function, eth_ss_function); 771 780 if (status) 772 - goto fail; 781 + return status; 773 782 774 783 rndis->port.open = rndis_open; 775 784 rndis->port.close = rndis_close; ··· 780 789 if (rndis->manufacturer && rndis->vendorID && 781 790 rndis_set_param_vendor(rndis->params, rndis->vendorID, 782 791 rndis->manufacturer)) { 783 - status = -EINVAL; 784 - goto fail_free_descs; 792 + usb_free_all_descriptors(f); 793 + return -EINVAL; 785 794 } 795 + 796 + if (cdev->use_os_string) { 797 + os_desc_table[0].os_desc = &rndis_opts->rndis_os_desc; 798 + os_desc_table[0].if_id = rndis_iad_descriptor.bFirstInterface; 799 + f->os_desc_table = no_free_ptr(os_desc_table); 800 + f->os_desc_n = 1; 801 + 802 + } 803 + rndis->notify_req = no_free_ptr(request); 786 804 787 805 /* NOTE: all that is done without knowing or caring about 788 806 * the network link ... which is unavailable to this code ··· 802 802 rndis->port.in_ep->name, rndis->port.out_ep->name, 803 803 rndis->notify->name); 804 804 return 0; 805 - 806 - fail_free_descs: 807 - usb_free_all_descriptors(f); 808 - fail: 809 - kfree(f->os_desc_table); 810 - f->os_desc_n = 0; 811 - 812 - if (rndis->notify_req) { 813 - kfree(rndis->notify_req->buf); 814 - usb_ep_free_request(rndis->notify, rndis->notify_req); 815 - } 816 - 817 - ERROR(cdev, "%s: can't bind, err %d\n", f->name, status); 818 - 819 - return status; 820 805 } 821 806 822 807 void rndis_borrow_net(struct usb_function_instance *f, struct net_device *net)
-69
drivers/usb/gadget/udc/cdns2/cdns2-trace.h
··· 47 47 TP_ARGS(set) 48 48 ); 49 49 50 - DEFINE_EVENT(cdns2_log_enable_disable, cdns2_lpm, 51 - TP_PROTO(int set), 52 - TP_ARGS(set) 53 - ); 54 - 55 - DEFINE_EVENT(cdns2_log_enable_disable, cdns2_may_wakeup, 56 - TP_PROTO(int set), 57 - TP_ARGS(set) 58 - ); 59 - 60 50 DECLARE_EVENT_CLASS(cdns2_log_simple, 61 51 TP_PROTO(char *msg), 62 52 TP_ARGS(msg), ··· 65 75 ); 66 76 67 77 DEFINE_EVENT(cdns2_log_simple, cdns2_ep0_status_stage, 68 - TP_PROTO(char *msg), 69 - TP_ARGS(msg) 70 - ); 71 - 72 - DEFINE_EVENT(cdns2_log_simple, cdns2_ep0_set_config, 73 78 TP_PROTO(char *msg), 74 79 TP_ARGS(msg) 75 80 ); ··· 325 340 TP_ARGS(preq) 326 341 ); 327 342 328 - DEFINE_EVENT(cdns2_log_request, cdns2_ep_queue, 329 - TP_PROTO(struct cdns2_request *preq), 330 - TP_ARGS(preq) 331 - ); 332 - 333 343 DEFINE_EVENT(cdns2_log_request, cdns2_request_dequeue, 334 344 TP_PROTO(struct cdns2_request *preq), 335 345 TP_ARGS(preq) ··· 333 353 DEFINE_EVENT(cdns2_log_request, cdns2_request_giveback, 334 354 TP_PROTO(struct cdns2_request *preq), 335 355 TP_ARGS(preq) 336 - ); 337 - 338 - TRACE_EVENT(cdns2_ep0_enqueue, 339 - TP_PROTO(struct cdns2_device *dev_priv, struct usb_request *request), 340 - TP_ARGS(dev_priv, request), 341 - TP_STRUCT__entry( 342 - __field(int, dir) 343 - __field(int, length) 344 - ), 345 - TP_fast_assign( 346 - __entry->dir = dev_priv->eps[0].dir; 347 - __entry->length = request->length; 348 - ), 349 - TP_printk("Queue to ep0%s length: %u", __entry->dir ? "in" : "out", 350 - __entry->length) 351 - ); 352 - 353 - DECLARE_EVENT_CLASS(cdns2_log_map_request, 354 - TP_PROTO(struct cdns2_request *priv_req), 355 - TP_ARGS(priv_req), 356 - TP_STRUCT__entry( 357 - __string(name, priv_req->pep->name) 358 - __field(struct usb_request *, req) 359 - __field(void *, buf) 360 - __field(dma_addr_t, dma) 361 - ), 362 - TP_fast_assign( 363 - __assign_str(name); 364 - __entry->req = &priv_req->request; 365 - __entry->buf = priv_req->request.buf; 366 - __entry->dma = priv_req->request.dma; 367 - ), 368 - TP_printk("%s: req: %p, req buf %p, dma %p", 369 - __get_str(name), __entry->req, __entry->buf, &__entry->dma 370 - ) 371 - ); 372 - 373 - DEFINE_EVENT(cdns2_log_map_request, cdns2_map_request, 374 - TP_PROTO(struct cdns2_request *req), 375 - TP_ARGS(req) 376 - ); 377 - DEFINE_EVENT(cdns2_log_map_request, cdns2_mapped_request, 378 - TP_PROTO(struct cdns2_request *req), 379 - TP_ARGS(req) 380 356 ); 381 357 382 358 DECLARE_EVENT_CLASS(cdns2_log_trb, ··· 439 503 ); 440 504 441 505 DEFINE_EVENT(cdns2_log_ep, cdns2_gadget_ep_disable, 442 - TP_PROTO(struct cdns2_endpoint *pep), 443 - TP_ARGS(pep) 444 - ); 445 - 446 - DEFINE_EVENT(cdns2_log_ep, cdns2_iso_out_ep_disable, 447 506 TP_PROTO(struct cdns2_endpoint *pep), 448 507 TP_ARGS(pep) 449 508 );
+4
drivers/usb/gadget/udc/core.c
··· 194 194 195 195 req = ep->ops->alloc_request(ep, gfp_flags); 196 196 197 + if (req) 198 + req->ep = ep; 199 + 197 200 trace_usb_ep_alloc_request(ep, req, req ? 0 : -ENOMEM); 198 201 199 202 return req; ··· 1128 1125 { 1129 1126 gadget->state = state; 1130 1127 schedule_work(&gadget->work); 1128 + trace_usb_gadget_set_state(gadget, 0); 1131 1129 } 1132 1130 EXPORT_SYMBOL_GPL(usb_gadget_set_state); 1133 1131
+1 -2
drivers/usb/gadget/udc/tegra-xudc.c
··· 812 812 return; 813 813 } 814 814 815 - xudc->device_mode = (usbphy->last_event == USB_EVENT_VBUS) ? true : 816 - false; 815 + xudc->device_mode = usbphy->last_event == USB_EVENT_VBUS; 817 816 818 817 phy_index = tegra_xudc_get_phy_index(xudc, usbphy); 819 818 dev_dbg(xudc->dev, "%s(): current phy index is %d\n", __func__,
+5
drivers/usb/gadget/udc/trace.h
··· 81 81 __entry->ret) 82 82 ); 83 83 84 + DEFINE_EVENT(udc_log_gadget, usb_gadget_set_state, 85 + TP_PROTO(struct usb_gadget *g, int ret), 86 + TP_ARGS(g, ret) 87 + ); 88 + 84 89 DEFINE_EVENT(udc_log_gadget, usb_gadget_frame_number, 85 90 TP_PROTO(struct usb_gadget *g, int ret), 86 91 TP_ARGS(g, ret)
+1 -1
drivers/usb/host/Kconfig
··· 93 93 default ARCH_RENESAS 94 94 help 95 95 Say 'Y' to enable the support for the xHCI host controller 96 - found in Renesas R-Car ARM SoCs. 96 + found in Renesas R-Car and RZ/G3E alike ARM SoCs. 97 97 98 98 config USB_XHCI_RZV2M 99 99 bool "xHCI support for Renesas RZ/V2M SoC"
+1 -1
drivers/usb/host/max3421-hcd.c
··· 1916 1916 if (hcd) { 1917 1917 kfree(max3421_hcd->tx); 1918 1918 kfree(max3421_hcd->rx); 1919 - if (max3421_hcd->spi_thread) 1919 + if (!IS_ERR_OR_NULL(max3421_hcd->spi_thread)) 1920 1920 kthread_stop(max3421_hcd->spi_thread); 1921 1921 usb_put_hcd(hcd); 1922 1922 }
-8
drivers/usb/host/ohci-s3c2410.c
··· 448 448 .resume = ohci_hcd_s3c2410_drv_resume, 449 449 }; 450 450 451 - static const struct of_device_id ohci_hcd_s3c2410_dt_ids[] = { 452 - { .compatible = "samsung,s3c2410-ohci" }, 453 - { /* sentinel */ } 454 - }; 455 - 456 - MODULE_DEVICE_TABLE(of, ohci_hcd_s3c2410_dt_ids); 457 - 458 451 static struct platform_driver ohci_hcd_s3c2410_driver = { 459 452 .probe = ohci_hcd_s3c2410_probe, 460 453 .remove = ohci_hcd_s3c2410_remove, ··· 455 462 .driver = { 456 463 .name = "s3c2410-ohci", 457 464 .pm = &ohci_hcd_s3c2410_pm_ops, 458 - .of_match_table = ohci_hcd_s3c2410_dt_ids, 459 465 }, 460 466 }; 461 467
+2
drivers/usb/host/xhci-caps.h
··· 89 89 #define HCC2_GSC(p) ((p) & (1 << 8)) 90 90 /* true: HC support Virtualization Based Trusted I/O Capability */ 91 91 #define HCC2_VTC(p) ((p) & (1 << 9)) 92 + /* true: HC support Double BW on a eUSB2 HS ISOC EP */ 93 + #define HCC2_EUSB2_DIC(p) ((p) & (1 << 11))
+41 -44
drivers/usb/host/xhci-mem.c
··· 1330 1330 return interval; 1331 1331 } 1332 1332 1333 - /* The "Mult" field in the endpoint context is only set for SuperSpeed isoc eps. 1333 + /* 1334 + * xHCs without LEC use the "Mult" field in the endpoint context for SuperSpeed 1335 + * isoc eps, and High speed isoc eps that support bandwidth doubling. Standard 1334 1336 * High speed endpoint descriptors can define "the number of additional 1335 1337 * transaction opportunities per microframe", but that goes in the Max Burst 1336 1338 * endpoint context field. 1337 1339 */ 1338 - static u32 xhci_get_endpoint_mult(struct usb_device *udev, 1339 - struct usb_host_endpoint *ep) 1340 + static u32 xhci_get_endpoint_mult(struct xhci_hcd *xhci, 1341 + struct usb_device *udev, 1342 + struct usb_host_endpoint *ep) 1340 1343 { 1341 - if (udev->speed < USB_SPEED_SUPER || 1342 - !usb_endpoint_xfer_isoc(&ep->desc)) 1343 - return 0; 1344 - return ep->ss_ep_comp.bmAttributes; 1344 + bool lec; 1345 + 1346 + /* xHCI 1.1 with LEC set does not use mult field, except intel eUSB2 */ 1347 + lec = xhci->hci_version > 0x100 && HCC2_LEC(xhci->hcc_params2); 1348 + 1349 + /* eUSB2 double isoc bw devices are the only USB2 devices using mult */ 1350 + if (usb_endpoint_is_hs_isoc_double(udev, ep) && 1351 + (!lec || xhci->quirks & XHCI_INTEL_HOST)) 1352 + return 1; 1353 + 1354 + /* SuperSpeed isoc transfers on hosts without LEC uses mult field */ 1355 + if (udev->speed >= USB_SPEED_SUPER && 1356 + usb_endpoint_xfer_isoc(&ep->desc) && !lec) 1357 + return ep->ss_ep_comp.bmAttributes; 1358 + 1359 + return 0; 1345 1360 } 1346 1361 1347 1362 static u32 xhci_get_endpoint_max_burst(struct usb_device *udev, ··· 1368 1353 1369 1354 if (udev->speed == USB_SPEED_HIGH && 1370 1355 (usb_endpoint_xfer_isoc(&ep->desc) || 1371 - usb_endpoint_xfer_int(&ep->desc))) 1356 + usb_endpoint_xfer_int(&ep->desc))) { 1357 + /* 1358 + * USB 2 Isochronous Double IN Bandwidth ECN uses fixed burst 1359 + * size and max packets bits 12:11 are invalid. 1360 + */ 1361 + if (usb_endpoint_is_hs_isoc_double(udev, ep)) 1362 + return 2; 1363 + 1372 1364 return usb_endpoint_maxp_mult(&ep->desc) - 1; 1365 + } 1373 1366 1374 1367 return 0; 1375 1368 } ··· 1399 1376 return in ? INT_IN_EP : INT_OUT_EP; 1400 1377 } 1401 1378 return 0; 1402 - } 1403 - 1404 - /* Return the maximum endpoint service interval time (ESIT) payload. 1405 - * Basically, this is the maxpacket size, multiplied by the burst size 1406 - * and mult size. 1407 - */ 1408 - static u32 xhci_get_max_esit_payload(struct usb_device *udev, 1409 - struct usb_host_endpoint *ep) 1410 - { 1411 - int max_burst; 1412 - int max_packet; 1413 - 1414 - /* Only applies for interrupt or isochronous endpoints */ 1415 - if (usb_endpoint_xfer_control(&ep->desc) || 1416 - usb_endpoint_xfer_bulk(&ep->desc)) 1417 - return 0; 1418 - 1419 - /* SuperSpeedPlus Isoc ep sending over 48k per esit */ 1420 - if ((udev->speed >= USB_SPEED_SUPER_PLUS) && 1421 - USB_SS_SSP_ISOC_COMP(ep->ss_ep_comp.bmAttributes)) 1422 - return le32_to_cpu(ep->ssp_isoc_ep_comp.dwBytesPerInterval); 1423 - 1424 - /* SuperSpeed or SuperSpeedPlus Isoc ep with less than 48k per esit */ 1425 - if (udev->speed >= USB_SPEED_SUPER) 1426 - return le16_to_cpu(ep->ss_ep_comp.wBytesPerInterval); 1427 - 1428 - max_packet = usb_endpoint_maxp(&ep->desc); 1429 - max_burst = usb_endpoint_maxp_mult(&ep->desc); 1430 - /* A 0 in max burst means 1 transfer per ESIT */ 1431 - return max_packet * max_burst; 1432 1379 } 1433 1380 1434 1381 /* Set up an endpoint with one ring segment. Do not allocate stream rings. ··· 1432 1439 1433 1440 ring_type = usb_endpoint_type(&ep->desc); 1434 1441 1442 + /* Ensure host supports double isoc bandwidth for eUSB2 devices */ 1443 + if (usb_endpoint_is_hs_isoc_double(udev, ep) && 1444 + !HCC2_EUSB2_DIC(xhci->hcc_params2)) { 1445 + dev_dbg(&udev->dev, "Double Isoc Bandwidth not supported by xhci\n"); 1446 + return -EINVAL; 1447 + } 1448 + 1435 1449 /* 1436 1450 * Get values to fill the endpoint context, mostly from ep descriptor. 1437 1451 * The average TRB buffer lengt for bulk endpoints is unclear as we 1438 1452 * have no clue on scatter gather list entry size. For Isoc and Int, 1439 1453 * set it to max available. See xHCI 1.1 spec 4.14.1.1 for details. 1440 1454 */ 1441 - max_esit_payload = xhci_get_max_esit_payload(udev, ep); 1455 + max_esit_payload = usb_endpoint_max_periodic_payload(udev, ep); 1442 1456 interval = xhci_get_endpoint_interval(udev, ep); 1443 1457 1444 1458 /* Periodic endpoint bInterval limit quirk */ ··· 1462 1462 } 1463 1463 } 1464 1464 1465 - mult = xhci_get_endpoint_mult(udev, ep); 1466 - max_packet = usb_endpoint_maxp(&ep->desc); 1465 + mult = xhci_get_endpoint_mult(xhci, udev, ep); 1466 + max_packet = xhci_usb_endpoint_maxp(udev, ep); 1467 1467 max_burst = xhci_get_endpoint_max_burst(udev, ep); 1468 1468 avg_trb_len = max_esit_payload; 1469 1469 ··· 1484 1484 /* xHCI 1.0 and 1.1 indicates that ctrl ep avg TRB Length should be 8 */ 1485 1485 if (usb_endpoint_xfer_control(&ep->desc) && xhci->hci_version >= 0x100) 1486 1486 avg_trb_len = 8; 1487 - /* xhci 1.1 with LEC support doesn't use mult field, use RsvdZ */ 1488 - if ((xhci->hci_version > 0x100) && HCC2_LEC(xhci->hcc_params2)) 1489 - mult = 0; 1490 1487 1491 1488 /* Set up the endpoint ring */ 1492 1489 virt_dev->eps[ep_index].new_ring =
+25 -19
drivers/usb/host/xhci-pci.c
··· 610 610 { 611 611 int retval; 612 612 struct xhci_hcd *xhci; 613 - struct usb_hcd *hcd; 613 + struct usb_hcd *hcd, *usb3_hcd; 614 614 struct reset_control *reset; 615 615 616 616 reset = devm_reset_control_get_optional_exclusive(&dev->dev, NULL); ··· 636 636 hcd = dev_get_drvdata(&dev->dev); 637 637 xhci = hcd_to_xhci(hcd); 638 638 xhci->reset = reset; 639 - xhci->shared_hcd = usb_create_shared_hcd(&xhci_pci_hc_driver, &dev->dev, 640 - pci_name(dev), hcd); 641 - if (!xhci->shared_hcd) { 642 - retval = -ENOMEM; 643 - goto dealloc_usb2_hcd; 639 + 640 + xhci->allow_single_roothub = 1; 641 + if (!xhci_has_one_roothub(xhci)) { 642 + xhci->shared_hcd = usb_create_shared_hcd(&xhci_pci_hc_driver, &dev->dev, 643 + pci_name(dev), hcd); 644 + if (!xhci->shared_hcd) { 645 + retval = -ENOMEM; 646 + goto dealloc_usb2_hcd; 647 + } 648 + 649 + retval = xhci_ext_cap_init(xhci); 650 + if (retval) 651 + goto put_usb3_hcd; 652 + 653 + retval = usb_add_hcd(xhci->shared_hcd, dev->irq, IRQF_SHARED); 654 + if (retval) 655 + goto put_usb3_hcd; 656 + } else { 657 + retval = xhci_ext_cap_init(xhci); 658 + if (retval) 659 + goto dealloc_usb2_hcd; 644 660 } 645 661 646 - retval = xhci_ext_cap_init(xhci); 647 - if (retval) 648 - goto put_usb3_hcd; 649 - 650 - retval = usb_add_hcd(xhci->shared_hcd, dev->irq, 651 - IRQF_SHARED); 652 - if (retval) 653 - goto put_usb3_hcd; 654 - /* Roothub already marked as USB 3.0 speed */ 655 - 656 - if (!(xhci->quirks & XHCI_BROKEN_STREAMS) && 657 - HCC_MAX_PSA(xhci->hcc_params) >= 4) 658 - xhci->shared_hcd->can_do_streams = 1; 662 + usb3_hcd = xhci_get_usb3_hcd(xhci); 663 + if (usb3_hcd && !(xhci->quirks & XHCI_BROKEN_STREAMS) && HCC_MAX_PSA(xhci->hcc_params) >= 4) 664 + usb3_hcd->can_do_streams = 1; 659 665 660 666 /* USB-2 and USB-3 roothubs initialized, allow runtime pm suspend */ 661 667 pm_runtime_put_noidle(&dev->dev);
+53 -4
drivers/usb/host/xhci-plat.c
··· 20 20 #include <linux/acpi.h> 21 21 #include <linux/usb/of.h> 22 22 #include <linux/reset.h> 23 + #include <linux/usb/xhci-sideband.h> 23 24 24 25 #include "xhci.h" 25 26 #include "xhci-plat.h" ··· 73 72 return 0; 74 73 75 74 return priv->resume_quirk(hcd); 75 + } 76 + 77 + static int xhci_priv_post_resume_quirk(struct usb_hcd *hcd) 78 + { 79 + struct xhci_plat_priv *priv = hcd_to_xhci_priv(hcd); 80 + 81 + if (!priv->post_resume_quirk) 82 + return 0; 83 + 84 + return priv->post_resume_quirk(hcd); 76 85 } 77 86 78 87 static void xhci_plat_quirks(struct device *dev, struct xhci_hcd *xhci) ··· 182 171 return ret; 183 172 184 173 pm_runtime_set_active(&pdev->dev); 174 + pm_runtime_use_autosuspend(&pdev->dev); 185 175 pm_runtime_enable(&pdev->dev); 186 176 pm_runtime_get_noresume(&pdev->dev); 187 177 ··· 466 454 } 467 455 EXPORT_SYMBOL_GPL(xhci_plat_remove); 468 456 469 - static int xhci_plat_suspend(struct device *dev) 457 + static int xhci_plat_suspend_common(struct device *dev) 470 458 { 471 459 struct usb_hcd *hcd = dev_get_drvdata(dev); 472 460 struct xhci_hcd *xhci = hcd_to_xhci(hcd); ··· 492 480 } 493 481 494 482 return 0; 483 + } 484 + 485 + static int xhci_plat_suspend(struct device *dev) 486 + { 487 + struct usb_hcd *hcd = dev_get_drvdata(dev); 488 + struct xhci_plat_priv *priv = hcd_to_xhci_priv(hcd); 489 + 490 + if (xhci_sideband_check(hcd)) { 491 + priv->sideband_at_suspend = 1; 492 + dev_dbg(dev, "sideband instance active, skip suspend.\n"); 493 + return 0; 494 + } 495 + 496 + return xhci_plat_suspend_common(dev); 497 + } 498 + 499 + static int xhci_plat_freeze(struct device *dev) 500 + { 501 + return xhci_plat_suspend_common(dev); 495 502 } 496 503 497 504 static int xhci_plat_resume_common(struct device *dev, bool power_lost) ··· 540 509 if (ret) 541 510 goto disable_clks; 542 511 512 + ret = xhci_priv_post_resume_quirk(hcd); 513 + if (ret) 514 + goto disable_clks; 515 + 543 516 pm_runtime_disable(dev); 544 517 pm_runtime_set_active(dev); 545 518 pm_runtime_enable(dev); ··· 560 525 } 561 526 562 527 static int xhci_plat_resume(struct device *dev) 528 + { 529 + struct usb_hcd *hcd = dev_get_drvdata(dev); 530 + struct xhci_plat_priv *priv = hcd_to_xhci_priv(hcd); 531 + 532 + if (priv->sideband_at_suspend) { 533 + priv->sideband_at_suspend = 0; 534 + dev_dbg(dev, "sideband instance active, skip resume.\n"); 535 + return 0; 536 + } 537 + 538 + return xhci_plat_resume_common(dev, false); 539 + } 540 + 541 + static int xhci_plat_thaw(struct device *dev) 563 542 { 564 543 return xhci_plat_resume_common(dev, false); 565 544 } ··· 607 558 const struct dev_pm_ops xhci_plat_pm_ops = { 608 559 .suspend = pm_sleep_ptr(xhci_plat_suspend), 609 560 .resume = pm_sleep_ptr(xhci_plat_resume), 610 - .freeze = pm_sleep_ptr(xhci_plat_suspend), 611 - .thaw = pm_sleep_ptr(xhci_plat_resume), 612 - .poweroff = pm_sleep_ptr(xhci_plat_suspend), 561 + .freeze = pm_sleep_ptr(xhci_plat_freeze), 562 + .thaw = pm_sleep_ptr(xhci_plat_thaw), 563 + .poweroff = pm_sleep_ptr(xhci_plat_freeze), 613 564 .restore = pm_sleep_ptr(xhci_plat_restore), 614 565 615 566 SET_RUNTIME_PM_OPS(xhci_plat_runtime_suspend,
+2
drivers/usb/host/xhci-plat.h
··· 16 16 const char *firmware_name; 17 17 unsigned long long quirks; 18 18 bool power_lost; 19 + unsigned sideband_at_suspend:1; 19 20 void (*plat_start)(struct usb_hcd *); 20 21 int (*init_quirk)(struct usb_hcd *); 21 22 int (*suspend_quirk)(struct usb_hcd *); 22 23 int (*resume_quirk)(struct usb_hcd *); 24 + int (*post_resume_quirk)(struct usb_hcd *); 23 25 }; 24 26 25 27 #define hcd_to_xhci_priv(h) ((struct xhci_plat_priv *)hcd_to_xhci(h)->priv)
+49
drivers/usb/host/xhci-rcar-regs.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + #ifndef __XHCI_RCAR_H 3 + #define __XHCI_RCAR_H 4 + 5 + /*** Register Offset ***/ 6 + #define RCAR_USB3_AXH_STA 0x104 /* AXI Host Control Status */ 7 + #define RCAR_USB3_INT_ENA 0x224 /* Interrupt Enable */ 8 + #define RCAR_USB3_DL_CTRL 0x250 /* FW Download Control & Status */ 9 + #define RCAR_USB3_FW_DATA0 0x258 /* FW Data0 */ 10 + 11 + #define RCAR_USB3_LCLK 0xa44 /* LCLK Select */ 12 + #define RCAR_USB3_CONF1 0xa48 /* USB3.0 Configuration1 */ 13 + #define RCAR_USB3_CONF2 0xa5c /* USB3.0 Configuration2 */ 14 + #define RCAR_USB3_CONF3 0xaa8 /* USB3.0 Configuration3 */ 15 + #define RCAR_USB3_RX_POL 0xab0 /* USB3.0 RX Polarity */ 16 + #define RCAR_USB3_TX_POL 0xab8 /* USB3.0 TX Polarity */ 17 + 18 + /*** Register Settings ***/ 19 + /* AXI Host Control Status */ 20 + #define RCAR_USB3_AXH_STA_B3_PLL_ACTIVE 0x00010000 21 + #define RCAR_USB3_AXH_STA_B2_PLL_ACTIVE 0x00000001 22 + #define RCAR_USB3_AXH_STA_PLL_ACTIVE_MASK (RCAR_USB3_AXH_STA_B3_PLL_ACTIVE | \ 23 + RCAR_USB3_AXH_STA_B2_PLL_ACTIVE) 24 + 25 + /* Interrupt Enable */ 26 + #define RCAR_USB3_INT_XHC_ENA 0x00000001 27 + #define RCAR_USB3_INT_PME_ENA 0x00000002 28 + #define RCAR_USB3_INT_HSE_ENA 0x00000004 29 + #define RCAR_USB3_INT_ENA_VAL (RCAR_USB3_INT_XHC_ENA | \ 30 + RCAR_USB3_INT_PME_ENA | RCAR_USB3_INT_HSE_ENA) 31 + 32 + /* FW Download Control & Status */ 33 + #define RCAR_USB3_DL_CTRL_ENABLE 0x00000001 34 + #define RCAR_USB3_DL_CTRL_FW_SUCCESS 0x00000010 35 + #define RCAR_USB3_DL_CTRL_FW_SET_DATA0 0x00000100 36 + 37 + /* LCLK Select */ 38 + #define RCAR_USB3_LCLK_ENA_VAL 0x01030001 39 + 40 + /* USB3.0 Configuration */ 41 + #define RCAR_USB3_CONF1_VAL 0x00030204 42 + #define RCAR_USB3_CONF2_VAL 0x00030300 43 + #define RCAR_USB3_CONF3_VAL 0x13802007 44 + 45 + /* USB3.0 Polarity */ 46 + #define RCAR_USB3_RX_POL_VAL BIT(21) 47 + #define RCAR_USB3_TX_POL_VAL BIT(4) 48 + 49 + #endif /* __XHCI_RCAR_H */
+56 -44
drivers/usb/host/xhci-rcar.c
··· 11 11 #include <linux/platform_device.h> 12 12 #include <linux/of.h> 13 13 #include <linux/usb/phy.h> 14 + #include <linux/reset.h> 14 15 15 16 #include "xhci.h" 16 17 #include "xhci-plat.h" 18 + #include "xhci-rcar-regs.h" 19 + #include "xhci-rzg3e-regs.h" 17 20 #include "xhci-rzv2m.h" 18 21 19 22 #define XHCI_RCAR_FIRMWARE_NAME_V1 "r8a779x_usb3_v1.dlmem" ··· 31 28 */ 32 29 MODULE_FIRMWARE(XHCI_RCAR_FIRMWARE_NAME_V1); 33 30 MODULE_FIRMWARE(XHCI_RCAR_FIRMWARE_NAME_V3); 34 - 35 - /*** Register Offset ***/ 36 - #define RCAR_USB3_AXH_STA 0x104 /* AXI Host Control Status */ 37 - #define RCAR_USB3_INT_ENA 0x224 /* Interrupt Enable */ 38 - #define RCAR_USB3_DL_CTRL 0x250 /* FW Download Control & Status */ 39 - #define RCAR_USB3_FW_DATA0 0x258 /* FW Data0 */ 40 - 41 - #define RCAR_USB3_LCLK 0xa44 /* LCLK Select */ 42 - #define RCAR_USB3_CONF1 0xa48 /* USB3.0 Configuration1 */ 43 - #define RCAR_USB3_CONF2 0xa5c /* USB3.0 Configuration2 */ 44 - #define RCAR_USB3_CONF3 0xaa8 /* USB3.0 Configuration3 */ 45 - #define RCAR_USB3_RX_POL 0xab0 /* USB3.0 RX Polarity */ 46 - #define RCAR_USB3_TX_POL 0xab8 /* USB3.0 TX Polarity */ 47 - 48 - /*** Register Settings ***/ 49 - /* AXI Host Control Status */ 50 - #define RCAR_USB3_AXH_STA_B3_PLL_ACTIVE 0x00010000 51 - #define RCAR_USB3_AXH_STA_B2_PLL_ACTIVE 0x00000001 52 - #define RCAR_USB3_AXH_STA_PLL_ACTIVE_MASK (RCAR_USB3_AXH_STA_B3_PLL_ACTIVE | \ 53 - RCAR_USB3_AXH_STA_B2_PLL_ACTIVE) 54 - 55 - /* Interrupt Enable */ 56 - #define RCAR_USB3_INT_XHC_ENA 0x00000001 57 - #define RCAR_USB3_INT_PME_ENA 0x00000002 58 - #define RCAR_USB3_INT_HSE_ENA 0x00000004 59 - #define RCAR_USB3_INT_ENA_VAL (RCAR_USB3_INT_XHC_ENA | \ 60 - RCAR_USB3_INT_PME_ENA | RCAR_USB3_INT_HSE_ENA) 61 - 62 - /* FW Download Control & Status */ 63 - #define RCAR_USB3_DL_CTRL_ENABLE 0x00000001 64 - #define RCAR_USB3_DL_CTRL_FW_SUCCESS 0x00000010 65 - #define RCAR_USB3_DL_CTRL_FW_SET_DATA0 0x00000100 66 - 67 - /* LCLK Select */ 68 - #define RCAR_USB3_LCLK_ENA_VAL 0x01030001 69 - 70 - /* USB3.0 Configuration */ 71 - #define RCAR_USB3_CONF1_VAL 0x00030204 72 - #define RCAR_USB3_CONF2_VAL 0x00030300 73 - #define RCAR_USB3_CONF3_VAL 0x13802007 74 - 75 - /* USB3.0 Polarity */ 76 - #define RCAR_USB3_RX_POL_VAL BIT(21) 77 - #define RCAR_USB3_TX_POL_VAL BIT(4) 78 31 79 32 static void xhci_rcar_start_gen2(struct usb_hcd *hcd) 80 33 { ··· 67 108 if (xhci_rcar_is_gen2(hcd->self.controller)) 68 109 xhci_rcar_start_gen2(hcd); 69 110 } 111 + } 112 + 113 + static void xhci_rzg3e_start(struct usb_hcd *hcd) 114 + { 115 + u32 int_en; 116 + 117 + if (hcd->regs) { 118 + /* Update the controller initial setting */ 119 + writel(0x03130200, hcd->regs + RZG3E_USB3_HOST_U3P0PIPESC(0)); 120 + writel(0x00160200, hcd->regs + RZG3E_USB3_HOST_U3P0PIPESC(1)); 121 + writel(0x03150000, hcd->regs + RZG3E_USB3_HOST_U3P0PIPESC(2)); 122 + writel(0x03130200, hcd->regs + RZG3E_USB3_HOST_U3P0PIPESC(3)); 123 + writel(0x00180000, hcd->regs + RZG3E_USB3_HOST_U3P0PIPESC(4)); 124 + 125 + /* Interrupt Enable */ 126 + int_en = readl(hcd->regs + RZG3E_USB3_HOST_INTEN); 127 + int_en |= RZG3E_USB3_HOST_INTEN_ENA; 128 + writel(int_en, hcd->regs + RZG3E_USB3_HOST_INTEN); 129 + } 130 + } 131 + 132 + static int xhci_rzg3e_resume(struct usb_hcd *hcd) 133 + { 134 + struct xhci_hcd *xhci = hcd_to_xhci(hcd); 135 + 136 + return reset_control_deassert(xhci->reset); 137 + } 138 + 139 + static int xhci_rzg3e_post_resume(struct usb_hcd *hcd) 140 + { 141 + xhci_rzg3e_start(hcd); 142 + 143 + return 0; 144 + } 145 + 146 + static int xhci_rzg3e_suspend(struct usb_hcd *hcd) 147 + { 148 + struct xhci_hcd *xhci = hcd_to_xhci(hcd); 149 + 150 + reset_control_assert(xhci->reset); 151 + 152 + return 0; 70 153 } 71 154 72 155 static int xhci_rcar_download_firmware(struct usb_hcd *hcd) ··· 234 233 .plat_start = xhci_rzv2m_start, 235 234 }; 236 235 236 + static const struct xhci_plat_priv xhci_plat_renesas_rzg3e = { 237 + .quirks = XHCI_NO_64BIT_SUPPORT | XHCI_RESET_ON_RESUME | XHCI_SUSPEND_RESUME_CLKS, 238 + .plat_start = xhci_rzg3e_start, 239 + .suspend_quirk = xhci_rzg3e_suspend, 240 + .resume_quirk = xhci_rzg3e_resume, 241 + .post_resume_quirk = xhci_rzg3e_post_resume, 242 + }; 243 + 237 244 static const struct of_device_id usb_xhci_of_match[] = { 238 245 { 239 246 .compatible = "renesas,xhci-r8a7790", ··· 258 249 }, { 259 250 .compatible = "renesas,xhci-r8a7796", 260 251 .data = &xhci_plat_renesas_rcar_gen3, 252 + }, { 253 + .compatible = "renesas,r9a09g047-xhci", 254 + .data = &xhci_plat_renesas_rzg3e, 261 255 }, { 262 256 .compatible = "renesas,rcar-gen2-xhci", 263 257 .data = &xhci_plat_renesas_rcar_gen2,
+14 -16
drivers/usb/host/xhci-ring.c
··· 711 711 return -ENODEV; 712 712 } 713 713 714 - hw_dequeue = xhci_get_hw_deq(xhci, dev, ep_index, stream_id); 714 + hw_dequeue = xhci_get_hw_deq(xhci, dev, ep_index, stream_id) & TR_DEQ_PTR_MASK; 715 715 new_seg = ep_ring->deq_seg; 716 716 new_deq = ep_ring->dequeue; 717 717 new_cycle = le32_to_cpu(td->end_trb->generic.field[3]) & TRB_CYCLE; ··· 723 723 */ 724 724 do { 725 725 if (!hw_dequeue_found && xhci_trb_virt_to_dma(new_seg, new_deq) 726 - == (dma_addr_t)(hw_dequeue & ~0xf)) { 726 + == (dma_addr_t)hw_dequeue) { 727 727 hw_dequeue_found = true; 728 728 if (td_last_trb_found) 729 729 break; ··· 1066 1066 */ 1067 1067 hw_deq = xhci_get_hw_deq(xhci, ep->vdev, ep->ep_index, 1068 1068 td->urb->stream_id); 1069 - hw_deq &= ~0xf; 1069 + hw_deq &= TR_DEQ_PTR_MASK; 1070 1070 1071 1071 if (td->cancel_status == TD_HALTED || trb_in_td(td, hw_deq)) { 1072 1072 switch (td->cancel_status) { ··· 1156 1156 1157 1157 if (!list_empty(&ep->ring->td_list)) { /* Not streams compatible */ 1158 1158 hw_deq = xhci_get_hw_deq(ep->xhci, ep->vdev, ep->ep_index, 0); 1159 - hw_deq &= ~0xf; 1159 + hw_deq &= TR_DEQ_PTR_MASK; 1160 1160 td = list_first_entry(&ep->ring->td_list, struct xhci_td, td_list); 1161 1161 if (trb_in_td(td, hw_deq)) 1162 1162 return td; ··· 1262 1262 * Stopped state, but it will soon change to Running. 1263 1263 * 1264 1264 * Assume this bug on unexpected Stop Endpoint failures. 1265 - * Keep retrying until the EP starts and stops again. 1265 + * Keep retrying until the EP starts and stops again or 1266 + * up to a timeout (a defective HC may never start, or a 1267 + * driver bug may cause stopping an already stopped EP). 1266 1268 */ 1269 + if (time_is_before_jiffies(ep->stop_time + msecs_to_jiffies(100))) 1270 + break; 1267 1271 fallthrough; 1268 1272 case EP_STATE_RUNNING: 1269 1273 /* Race, HW handled stop ep cmd before ep was running */ 1270 1274 xhci_dbg(xhci, "Stop ep completion ctx error, ctx_state %d\n", 1271 1275 GET_EP_CTX_STATE(ep_ctx)); 1272 - /* 1273 - * Don't retry forever if we guessed wrong or a defective HC never starts 1274 - * the EP or says 'Running' but fails the command. We must give back TDs. 1275 - */ 1276 - if (time_is_before_jiffies(ep->stop_time + msecs_to_jiffies(100))) 1277 - break; 1278 1276 1279 1277 command = xhci_alloc_command(xhci, false, GFP_ATOMIC); 1280 1278 if (!command) { ··· 1479 1481 u64 deq; 1480 1482 /* 4.6.10 deq ptr is written to the stream ctx for streams */ 1481 1483 if (ep->ep_state & EP_HAS_STREAMS) { 1482 - deq = le64_to_cpu(stream_ctx->stream_ring) & SCTX_DEQ_MASK; 1484 + deq = le64_to_cpu(stream_ctx->stream_ring) & TR_DEQ_PTR_MASK; 1483 1485 1484 1486 /* 1485 1487 * Cadence xHCI controllers store some endpoint state ··· 1495 1497 stream_ctx->reserved[1] = 0; 1496 1498 } 1497 1499 } else { 1498 - deq = le64_to_cpu(ep_ctx->deq) & ~EP_CTX_CYCLE_MASK; 1500 + deq = le64_to_cpu(ep_ctx->deq) & TR_DEQ_PTR_MASK; 1499 1501 } 1500 1502 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb, 1501 1503 "Successful Set TR Deq Ptr cmd, deq = @%08llx", deq); ··· 3548 3550 if ((xhci->quirks & XHCI_MTK_HOST) && (xhci->hci_version < 0x100)) 3549 3551 trb_buff_len = 0; 3550 3552 3551 - maxp = usb_endpoint_maxp(&urb->ep->desc); 3553 + maxp = xhci_usb_endpoint_maxp(urb->dev, urb->ep); 3552 3554 total_packet_count = DIV_ROUND_UP(td_total_len, maxp); 3553 3555 3554 3556 /* Queueing functions don't count the current TRB into transferred */ ··· 3565 3567 u32 new_buff_len; 3566 3568 size_t len; 3567 3569 3568 - max_pkt = usb_endpoint_maxp(&urb->ep->desc); 3570 + max_pkt = xhci_usb_endpoint_maxp(urb->dev, urb->ep); 3569 3571 unalign = (enqd_len + *trb_buff_len) % max_pkt; 3570 3572 3571 3573 /* we got lucky, last normal TRB data on segment is packet aligned */ ··· 4136 4138 addr = start_addr + urb->iso_frame_desc[i].offset; 4137 4139 td_len = urb->iso_frame_desc[i].length; 4138 4140 td_remain_len = td_len; 4139 - max_pkt = usb_endpoint_maxp(&urb->ep->desc); 4141 + max_pkt = xhci_usb_endpoint_maxp(urb->dev, urb->ep); 4140 4142 total_pkt_count = DIV_ROUND_UP(td_len, max_pkt); 4141 4143 4142 4144 /* A zero-length transfer still involves at least one packet. */
+12
drivers/usb/host/xhci-rzg3e-regs.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + #ifndef __XHCI_RZG3E_H 3 + #define __XHCI_RZG3E_H 4 + 5 + #define RZG3E_USB3_HOST_INTEN 0x1044 /* Interrupt Enable */ 6 + #define RZG3E_USB3_HOST_U3P0PIPESC(x) (0x10c0 + (x) * 4) /* PIPE Status and Control Register */ 7 + 8 + #define RZG3E_USB3_HOST_INTEN_XHC BIT(0) 9 + #define RZG3E_USB3_HOST_INTEN_HSE BIT(2) 10 + #define RZG3E_USB3_HOST_INTEN_ENA (RZG3E_USB3_HOST_INTEN_XHC | RZG3E_USB3_HOST_INTEN_HSE) 11 + 12 + #endif /* __XHCI_RZG3E_H */
+36
drivers/usb/host/xhci-sideband.c
··· 267 267 EXPORT_SYMBOL_GPL(xhci_sideband_get_event_buffer); 268 268 269 269 /** 270 + * xhci_sideband_check - check the existence of active sidebands 271 + * @hcd: the host controller driver associated with the target host controller 272 + * 273 + * Allow other drivers, such as usb controller driver, to check if there are 274 + * any sideband activity on the host controller. This information could be used 275 + * for power management or other forms of resource management. The caller should 276 + * ensure downstream usb devices are all either suspended or marked as 277 + * "offload_at_suspend" to ensure the correctness of the return value. 278 + * 279 + * Returns true on any active sideband existence, false otherwise. 280 + */ 281 + bool xhci_sideband_check(struct usb_hcd *hcd) 282 + { 283 + struct usb_device *udev = hcd->self.root_hub; 284 + bool active; 285 + 286 + usb_lock_device(udev); 287 + active = usb_offload_check(udev); 288 + usb_unlock_device(udev); 289 + 290 + return active; 291 + } 292 + EXPORT_SYMBOL_GPL(xhci_sideband_check); 293 + 294 + /** 270 295 * xhci_sideband_create_interrupter - creates a new interrupter for this sideband 271 296 * @sb: sideband instance for this usb device 272 297 * @num_seg: number of event ring segments to allocate ··· 311 286 bool ip_autoclear, u32 imod_interval, int intr_num) 312 287 { 313 288 int ret = 0; 289 + struct usb_device *udev; 314 290 315 291 if (!sb || !sb->xhci) 316 292 return -ENODEV; ··· 329 303 ret = -ENOMEM; 330 304 goto out; 331 305 } 306 + 307 + udev = sb->vdev->udev; 308 + ret = usb_offload_get(udev); 332 309 333 310 sb->ir->ip_autoclear = ip_autoclear; 334 311 ··· 352 323 void 353 324 xhci_sideband_remove_interrupter(struct xhci_sideband *sb) 354 325 { 326 + struct usb_device *udev; 327 + 355 328 if (!sb || !sb->ir) 356 329 return; 357 330 ··· 361 330 xhci_remove_secondary_interrupter(xhci_to_hcd(sb->xhci), sb->ir); 362 331 363 332 sb->ir = NULL; 333 + udev = sb->vdev->udev; 334 + 335 + if (udev->state != USB_STATE_NOTATTACHED) 336 + usb_offload_put(udev); 337 + 364 338 mutex_unlock(&sb->mutex); 365 339 } 366 340 EXPORT_SYMBOL_GPL(xhci_sideband_remove_interrupter);
+81 -3
drivers/usb/host/xhci-tegra.c
··· 155 155 #define FW_IOCTL_TYPE_SHIFT 24 156 156 #define FW_IOCTL_CFGTBL_READ 17 157 157 158 + #define WAKE_IRQ_START_INDEX 2 159 + 158 160 struct tegra_xusb_fw_header { 159 161 __le32 boot_loadaddr_in_imem; 160 162 __le32 boot_codedfi_offset; ··· 230 228 unsigned int num_supplies; 231 229 const struct tegra_xusb_phy_type *phy_types; 232 230 unsigned int num_types; 231 + unsigned int max_num_wakes; 233 232 const struct tegra_xusb_context_soc *context; 234 233 235 234 struct { ··· 266 263 int xhci_irq; 267 264 int mbox_irq; 268 265 int padctl_irq; 266 + int *wake_irqs; 269 267 270 268 void __iomem *ipfs_base; 271 269 void __iomem *fpci_base; ··· 317 313 bool suspended; 318 314 struct tegra_xusb_context context; 319 315 u8 lp0_utmi_pad_mask; 316 + int num_wakes; 320 317 }; 321 318 322 319 static struct hc_driver __read_mostly tegra_xhci_hc_driver; ··· 1487 1482 1488 1483 tegra->otg_usb2_port = tegra_xusb_get_usb2_port(tegra, usbphy); 1489 1484 1490 - tegra->host_mode = (usbphy->last_event == USB_EVENT_ID) ? true : false; 1485 + tegra->host_mode = usbphy->last_event == USB_EVENT_ID; 1491 1486 1492 1487 schedule_work(&tegra->id_work); 1493 1488 ··· 1542 1537 otg_set_host(tegra->usbphy[i]->otg, NULL); 1543 1538 } 1544 1539 1540 + static int tegra_xusb_setup_wakeup(struct platform_device *pdev, struct tegra_xusb *tegra) 1541 + { 1542 + unsigned int i; 1543 + 1544 + if (tegra->soc->max_num_wakes == 0) 1545 + return 0; 1546 + 1547 + tegra->wake_irqs = devm_kcalloc(tegra->dev, 1548 + tegra->soc->max_num_wakes, 1549 + sizeof(*tegra->wake_irqs), GFP_KERNEL); 1550 + if (!tegra->wake_irqs) 1551 + return -ENOMEM; 1552 + 1553 + /* 1554 + * USB wake events are independent of each other, so it is not necessary for a platform 1555 + * to utilize all wake-up events supported for a given device. The USB host can operate 1556 + * even if wake-up events are not defined or fail to be configured. Therefore, we only 1557 + * return critical errors, such as -ENOMEM. 1558 + */ 1559 + for (i = 0; i < tegra->soc->max_num_wakes; i++) { 1560 + struct irq_data *data; 1561 + 1562 + tegra->wake_irqs[i] = platform_get_irq(pdev, i + WAKE_IRQ_START_INDEX); 1563 + if (tegra->wake_irqs[i] < 0) 1564 + break; 1565 + 1566 + data = irq_get_irq_data(tegra->wake_irqs[i]); 1567 + if (!data) { 1568 + dev_warn(tegra->dev, "get wake event %d irq data fail\n", i); 1569 + irq_dispose_mapping(tegra->wake_irqs[i]); 1570 + break; 1571 + } 1572 + 1573 + irq_set_irq_type(tegra->wake_irqs[i], irqd_get_trigger_type(data)); 1574 + } 1575 + 1576 + tegra->num_wakes = i; 1577 + dev_dbg(tegra->dev, "setup %d wake events\n", tegra->num_wakes); 1578 + 1579 + return 0; 1580 + } 1581 + 1582 + static void tegra_xusb_dispose_wake(struct tegra_xusb *tegra) 1583 + { 1584 + unsigned int i; 1585 + 1586 + for (i = 0; i < tegra->num_wakes; i++) 1587 + irq_dispose_mapping(tegra->wake_irqs[i]); 1588 + 1589 + tegra->num_wakes = 0; 1590 + } 1591 + 1545 1592 static int tegra_xusb_probe(struct platform_device *pdev) 1546 1593 { 1547 1594 struct tegra_xusb *tegra; ··· 1644 1587 if (tegra->mbox_irq < 0) 1645 1588 return tegra->mbox_irq; 1646 1589 1590 + err = tegra_xusb_setup_wakeup(pdev, tegra); 1591 + if (err) 1592 + return err; 1593 + 1647 1594 tegra->padctl = tegra_xusb_padctl_get(&pdev->dev); 1648 - if (IS_ERR(tegra->padctl)) 1649 - return PTR_ERR(tegra->padctl); 1595 + if (IS_ERR(tegra->padctl)) { 1596 + err = PTR_ERR(tegra->padctl); 1597 + goto dispose_wake; 1598 + } 1650 1599 1651 1600 np = of_parse_phandle(pdev->dev.of_node, "nvidia,xusb-padctl", 0); 1652 1601 if (!np) { ··· 1976 1913 put_padctl: 1977 1914 of_node_put(np); 1978 1915 tegra_xusb_padctl_put(tegra->padctl); 1916 + dispose_wake: 1917 + tegra_xusb_dispose_wake(tegra); 1979 1918 return err; 1980 1919 } 1981 1920 ··· 2009 1944 2010 1945 if (tegra->padctl_irq) 2011 1946 pm_runtime_disable(&pdev->dev); 1947 + 1948 + tegra_xusb_dispose_wake(tegra); 2012 1949 2013 1950 pm_runtime_put(&pdev->dev); 2014 1951 ··· 2422 2355 pm_runtime_disable(dev); 2423 2356 2424 2357 if (device_may_wakeup(dev)) { 2358 + unsigned int i; 2359 + 2425 2360 if (enable_irq_wake(tegra->padctl_irq)) 2426 2361 dev_err(dev, "failed to enable padctl wakes\n"); 2362 + 2363 + for (i = 0; i < tegra->num_wakes; i++) 2364 + enable_irq_wake(tegra->wake_irqs[i]); 2427 2365 } 2428 2366 } 2429 2367 ··· 2456 2384 } 2457 2385 2458 2386 if (device_may_wakeup(dev)) { 2387 + unsigned int i; 2388 + 2459 2389 if (disable_irq_wake(tegra->padctl_irq)) 2460 2390 dev_err(dev, "failed to disable padctl wakes\n"); 2391 + 2392 + for (i = 0; i < tegra->num_wakes; i++) 2393 + disable_irq_wake(tegra->wake_irqs[i]); 2461 2394 } 2462 2395 tegra->suspended = false; 2463 2396 mutex_unlock(&tegra->lock); ··· 2713 2636 .num_supplies = ARRAY_SIZE(tegra194_supply_names), 2714 2637 .phy_types = tegra194_phy_types, 2715 2638 .num_types = ARRAY_SIZE(tegra194_phy_types), 2639 + .max_num_wakes = 7, 2716 2640 .context = &tegra186_xusb_context, 2717 2641 .ports = { 2718 2642 .usb3 = { .offset = 0, .count = 4, },
+17 -17
drivers/usb/host/xhci-trace.h
··· 541 541 ); 542 542 543 543 DECLARE_EVENT_CLASS(xhci_log_portsc, 544 - TP_PROTO(struct xhci_port *port, u32 portsc), 545 - TP_ARGS(port, portsc), 546 - TP_STRUCT__entry( 547 - __field(u32, busnum) 548 - __field(u32, portnum) 549 - __field(u32, portsc) 550 - ), 551 - TP_fast_assign( 552 - __entry->busnum = port->rhub->hcd->self.busnum; 553 - __entry->portnum = port->hcd_portnum; 554 - __entry->portsc = portsc; 555 - ), 556 - TP_printk("port %d-%d: %s", 557 - __entry->busnum, 558 - __entry->portnum, 559 - xhci_decode_portsc(__get_buf(XHCI_MSG_MAX), __entry->portsc) 560 - ) 544 + TP_PROTO(struct xhci_port *port, u32 portsc), 545 + TP_ARGS(port, portsc), 546 + TP_STRUCT__entry( 547 + __field(u32, busnum) 548 + __field(u32, portnum) 549 + __field(u32, portsc) 550 + ), 551 + TP_fast_assign( 552 + __entry->busnum = port->rhub->hcd->self.busnum; 553 + __entry->portnum = port->hcd_portnum + 1; 554 + __entry->portsc = portsc; 555 + ), 556 + TP_printk("port %d-%d: %s", 557 + __entry->busnum, 558 + __entry->portnum, 559 + xhci_decode_portsc(__get_buf(XHCI_MSG_MAX), __entry->portsc) 560 + ) 561 561 ); 562 562 563 563 DEFINE_EVENT(xhci_log_portsc, xhci_handle_port_status,
+15 -1
drivers/usb/host/xhci.c
··· 1336 1336 struct scatterlist *tail_sg; 1337 1337 1338 1338 tail_sg = urb->sg; 1339 - max_pkt = usb_endpoint_maxp(&urb->ep->desc); 1339 + max_pkt = xhci_usb_endpoint_maxp(urb->dev, urb->ep); 1340 1340 1341 1341 if (!urb->num_sgs) 1342 1342 return ret; ··· 2923 2923 return ret; 2924 2924 } 2925 2925 EXPORT_SYMBOL_GPL(xhci_stop_endpoint_sync); 2926 + 2927 + /* 2928 + * xhci_usb_endpoint_maxp - get endpoint max packet size 2929 + * @host_ep: USB host endpoint to be checked 2930 + * 2931 + * Returns max packet from the correct descriptor 2932 + */ 2933 + int xhci_usb_endpoint_maxp(struct usb_device *udev, 2934 + struct usb_host_endpoint *host_ep) 2935 + { 2936 + if (usb_endpoint_is_hs_isoc_double(udev, host_ep)) 2937 + return le16_to_cpu(host_ep->eusb2_isoc_ep_comp.wMaxPacketSize); 2938 + return usb_endpoint_maxp(&host_ep->desc); 2939 + } 2926 2940 2927 2941 /* Issue a configure endpoint command or evaluate context command 2928 2942 * and wait for it to finish.
+4 -1
drivers/usb/host/xhci.h
··· 500 500 501 501 /* deq bitmasks */ 502 502 #define EP_CTX_CYCLE_MASK (1 << 0) 503 - #define SCTX_DEQ_MASK (~0xfL) 503 + /* bits 63:4 - TR Dequeue Pointer */ 504 + #define TR_DEQ_PTR_MASK GENMASK_ULL(63, 4) 504 505 505 506 506 507 /** ··· 1959 1958 struct xhci_interrupter *ir, 1960 1959 bool clear_ehb); 1961 1960 void xhci_add_interrupter(struct xhci_hcd *xhci, unsigned int intr_num); 1961 + int xhci_usb_endpoint_maxp(struct usb_device *udev, 1962 + struct usb_host_endpoint *host_ep); 1962 1963 1963 1964 /* xHCI roothub code */ 1964 1965 void xhci_set_link_state(struct xhci_hcd *xhci, struct xhci_port *port,
+17 -2
drivers/usb/misc/Kconfig
··· 147 147 config USB_QCOM_EUD 148 148 tristate "QCOM Embedded USB Debugger(EUD) Driver" 149 149 depends on ARCH_QCOM || COMPILE_TEST 150 + select QCOM_SCM 150 151 select USB_ROLE_SWITCH 151 152 help 152 153 This module enables support for Qualcomm Technologies, Inc. ··· 178 177 179 178 This driver can also be built as a module. If so, the module 180 179 will be called usb-ljca. 180 + 181 + config USB_USBIO 182 + tristate "Intel USBIO Bridge support" 183 + depends on USB && ACPI 184 + select AUXILIARY_BUS 185 + help 186 + This adds support for Intel USBIO drivers. 187 + This enables the USBIO bridge driver module in charge to talk 188 + to the USB device. Additional drivers such as GPIO_USBIO and 189 + I2C_USBIO must be enabled in order to use the device's full 190 + functionality. 191 + 192 + This driver can also be built as a module. If so, the module 193 + will be called usbio. 181 194 182 195 source "drivers/usb/misc/sisusbvga/Kconfig" 183 196 ··· 246 231 VID/PID pairs. This driver then initiates a corresponding test mode on 247 232 the downstream port to which the test fixture is attached. 248 233 249 - See <http://www.usb.org/developers/onthego/EHSET_v1.01.pdf> for more 250 - information. 234 + See <https://www.usb.org/sites/default/files/EHSET_v1.01%281%29.pdf> 235 + for more information. 251 236 252 237 config USB_ISIGHTFW 253 238 tristate "iSight firmware loading support"
+1
drivers/usb/misc/Makefile
··· 12 12 obj-$(CONFIG_USB_EZUSB_FX2) += ezusb.o 13 13 obj-$(CONFIG_APPLE_MFI_FASTCHARGE) += apple-mfi-fastcharge.o 14 14 obj-$(CONFIG_USB_LJCA) += usb-ljca.o 15 + obj-$(CONFIG_USB_USBIO) += usbio.o 15 16 obj-$(CONFIG_USB_IDMOUSE) += idmouse.o 16 17 obj-$(CONFIG_USB_IOWARRIOR) += iowarrior.o 17 18 obj-$(CONFIG_USB_ISIGHTFW) += isight_firmware.o
+25 -11
drivers/usb/misc/qcom_eud.c
··· 15 15 #include <linux/slab.h> 16 16 #include <linux/sysfs.h> 17 17 #include <linux/usb/role.h> 18 + #include <linux/firmware/qcom/qcom_scm.h> 18 19 19 20 #define EUD_REG_INT1_EN_MASK 0x0024 20 21 #define EUD_REG_INT_STATUS_1 0x0044 ··· 35 34 struct device *dev; 36 35 struct usb_role_switch *role_sw; 37 36 void __iomem *base; 38 - void __iomem *mode_mgr; 37 + phys_addr_t mode_mgr; 39 38 unsigned int int_status; 40 39 int irq; 41 40 bool enabled; ··· 44 43 45 44 static int enable_eud(struct eud_chip *priv) 46 45 { 46 + int ret; 47 + 48 + ret = qcom_scm_io_writel(priv->mode_mgr + EUD_REG_EUD_EN2, 1); 49 + if (ret) 50 + return ret; 51 + 47 52 writel(EUD_ENABLE, priv->base + EUD_REG_CSR_EUD_EN); 48 53 writel(EUD_INT_VBUS | EUD_INT_SAFE_MODE, 49 54 priv->base + EUD_REG_INT1_EN_MASK); 50 - writel(1, priv->mode_mgr + EUD_REG_EUD_EN2); 51 55 52 56 return usb_role_switch_set_role(priv->role_sw, USB_ROLE_DEVICE); 53 57 } 54 58 55 - static void disable_eud(struct eud_chip *priv) 59 + static int disable_eud(struct eud_chip *priv) 56 60 { 61 + int ret; 62 + 63 + ret = qcom_scm_io_writel(priv->mode_mgr + EUD_REG_EUD_EN2, 0); 64 + if (ret) 65 + return ret; 66 + 57 67 writel(0, priv->base + EUD_REG_CSR_EUD_EN); 58 - writel(0, priv->mode_mgr + EUD_REG_EUD_EN2); 68 + return 0; 59 69 } 60 70 61 71 static ssize_t enable_show(struct device *dev, ··· 94 82 chip->enabled = enable; 95 83 else 96 84 disable_eud(chip); 85 + 97 86 } else { 98 - disable_eud(chip); 87 + ret = disable_eud(chip); 99 88 } 100 89 101 - return count; 90 + return ret < 0 ? ret : count; 102 91 } 103 92 104 93 static DEVICE_ATTR_RW(enable); ··· 191 178 static int eud_probe(struct platform_device *pdev) 192 179 { 193 180 struct eud_chip *chip; 181 + struct resource *res; 194 182 int ret; 195 183 196 184 chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL); ··· 207 193 208 194 ret = devm_add_action_or_reset(chip->dev, eud_role_switch_release, chip); 209 195 if (ret) 210 - return dev_err_probe(chip->dev, ret, 211 - "failed to add role switch release action\n"); 196 + return ret; 212 197 213 198 chip->base = devm_platform_ioremap_resource(pdev, 0); 214 199 if (IS_ERR(chip->base)) 215 200 return PTR_ERR(chip->base); 216 201 217 - chip->mode_mgr = devm_platform_ioremap_resource(pdev, 1); 218 - if (IS_ERR(chip->mode_mgr)) 219 - return PTR_ERR(chip->mode_mgr); 202 + res = platform_get_resource(pdev, IORESOURCE_MEM, 1); 203 + if (!res) 204 + return -ENODEV; 205 + chip->mode_mgr = res->start; 220 206 221 207 chip->irq = platform_get_irq(pdev, 0); 222 208 if (chip->irq < 0)
+95 -13
drivers/usb/misc/usb251xb.c
··· 17 17 #include <linux/module.h> 18 18 #include <linux/nls.h> 19 19 #include <linux/of.h> 20 + #include <linux/platform_device.h> 20 21 #include <linux/regulator/consumer.h> 21 22 #include <linux/slab.h> 22 23 ··· 243 242 static int usb251x_check_gpio_chip(struct usb251xb *hub) 244 243 { 245 244 struct gpio_chip *gc = gpiod_to_chip(hub->gpio_reset); 246 - struct i2c_adapter *adap = hub->i2c->adapter; 245 + struct i2c_adapter *adap; 247 246 int ret; 247 + 248 + if (!hub->i2c) 249 + return 0; 248 250 249 251 if (!hub->gpio_reset) 250 252 return 0; ··· 255 251 if (!gc) 256 252 return -EINVAL; 257 253 254 + adap = hub->i2c->adapter; 258 255 ret = usb251xb_check_dev_children(&adap->dev, gc->parent); 259 256 if (ret) { 260 257 dev_err(hub->dev, "Reset GPIO chip is at the same i2c-bus\n"); ··· 276 271 if (!hub->gpio_reset) 277 272 return; 278 273 279 - i2c_lock_bus(hub->i2c->adapter, I2C_LOCK_SEGMENT); 274 + if (hub->i2c) 275 + i2c_lock_bus(hub->i2c->adapter, I2C_LOCK_SEGMENT); 280 276 281 277 gpiod_set_value_cansleep(hub->gpio_reset, 1); 282 278 usleep_range(1, 10); /* >=1us RESET_N asserted */ ··· 286 280 /* wait for hub recovery/stabilization */ 287 281 usleep_range(500, 750); /* >=500us after RESET_N deasserted */ 288 282 289 - i2c_unlock_bus(hub->i2c->adapter, I2C_LOCK_SEGMENT); 283 + if (hub->i2c) 284 + i2c_unlock_bus(hub->i2c->adapter, I2C_LOCK_SEGMENT); 290 285 } 291 286 292 287 static int usb251xb_connect(struct usb251xb *hub) ··· 295 288 struct device *dev = hub->dev; 296 289 int err, i; 297 290 char i2c_wb[USB251XB_I2C_REG_SZ]; 291 + 292 + if (!hub->i2c) { 293 + usb251xb_reset(hub); 294 + dev_info(dev, "hub is put in default configuration.\n"); 295 + return 0; 296 + } 298 297 299 298 memset(i2c_wb, 0, USB251XB_I2C_REG_SZ); 300 299 ··· 711 698 return usb251xb_probe(hub); 712 699 } 713 700 714 - static int __maybe_unused usb251xb_suspend(struct device *dev) 701 + static int usb251xb_suspend(struct usb251xb *hub) 715 702 { 716 - struct i2c_client *client = to_i2c_client(dev); 717 - struct usb251xb *hub = i2c_get_clientdata(client); 718 - 719 703 return regulator_disable(hub->vdd); 720 704 } 721 705 722 - static int __maybe_unused usb251xb_resume(struct device *dev) 706 + static int usb251xb_resume(struct usb251xb *hub) 723 707 { 724 - struct i2c_client *client = to_i2c_client(dev); 725 - struct usb251xb *hub = i2c_get_clientdata(client); 726 708 int err; 727 709 728 710 err = regulator_enable(hub->vdd); ··· 727 719 return usb251xb_connect(hub); 728 720 } 729 721 730 - static SIMPLE_DEV_PM_OPS(usb251xb_pm_ops, usb251xb_suspend, usb251xb_resume); 722 + static int usb251xb_i2c_suspend(struct device *dev) 723 + { 724 + struct i2c_client *client = to_i2c_client(dev); 725 + struct usb251xb *hub = i2c_get_clientdata(client); 726 + 727 + return usb251xb_suspend(hub); 728 + } 729 + 730 + static int usb251xb_i2c_resume(struct device *dev) 731 + { 732 + struct i2c_client *client = to_i2c_client(dev); 733 + struct usb251xb *hub = i2c_get_clientdata(client); 734 + 735 + return usb251xb_resume(hub); 736 + } 737 + 738 + static DEFINE_SIMPLE_DEV_PM_OPS(usb251xb_i2c_pm_ops, usb251xb_i2c_suspend, usb251xb_i2c_resume); 731 739 732 740 static const struct i2c_device_id usb251xb_id[] = { 733 741 { "usb2422" }, ··· 763 739 .driver = { 764 740 .name = DRIVER_NAME, 765 741 .of_match_table = usb251xb_of_match, 766 - .pm = &usb251xb_pm_ops, 742 + .pm = pm_sleep_ptr(&usb251xb_i2c_pm_ops), 767 743 }, 768 744 .probe = usb251xb_i2c_probe, 769 745 .id_table = usb251xb_id, 770 746 }; 771 747 772 - module_i2c_driver(usb251xb_i2c_driver); 748 + static int usb251xb_plat_probe(struct platform_device *pdev) 749 + { 750 + struct usb251xb *hub; 751 + 752 + hub = devm_kzalloc(&pdev->dev, sizeof(*hub), GFP_KERNEL); 753 + if (!hub) 754 + return -ENOMEM; 755 + 756 + platform_set_drvdata(pdev, hub); 757 + hub->dev = &pdev->dev; 758 + 759 + return usb251xb_probe(hub); 760 + } 761 + 762 + static int usb251xb_plat_suspend(struct device *dev) 763 + { 764 + return usb251xb_suspend(dev_get_drvdata(dev)); 765 + } 766 + 767 + static int usb251xb_plat_resume(struct device *dev) 768 + { 769 + return usb251xb_resume(dev_get_drvdata(dev)); 770 + } 771 + 772 + static DEFINE_SIMPLE_DEV_PM_OPS(usb251xb_plat_pm_ops, usb251xb_plat_suspend, usb251xb_plat_resume); 773 + 774 + static struct platform_driver usb251xb_plat_driver = { 775 + .driver = { 776 + .name = DRIVER_NAME, 777 + .of_match_table = usb251xb_of_match, 778 + .pm = pm_sleep_ptr(&usb251xb_plat_pm_ops), 779 + }, 780 + .probe = usb251xb_plat_probe, 781 + }; 782 + 783 + static int __init usb251xb_init(void) 784 + { 785 + int err; 786 + 787 + err = i2c_add_driver(&usb251xb_i2c_driver); 788 + if (err) 789 + return err; 790 + 791 + err = platform_driver_register(&usb251xb_plat_driver); 792 + if (err) { 793 + i2c_del_driver(&usb251xb_i2c_driver); 794 + return err; 795 + } 796 + 797 + return 0; 798 + } 799 + module_init(usb251xb_init); 800 + 801 + static void __exit usb251xb_exit(void) 802 + { 803 + platform_driver_unregister(&usb251xb_plat_driver); 804 + i2c_del_driver(&usb251xb_i2c_driver); 805 + } 806 + module_exit(usb251xb_exit); 773 807 774 808 MODULE_AUTHOR("Richard Leitner <richard.leitner@skidata.com>"); 775 809 MODULE_DESCRIPTION("USB251x/xBi USB 2.0 Hub Controller Driver");
+749
drivers/usb/misc/usbio.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * Intel USBIO Bridge driver 4 + * 5 + * Copyright (c) 2025 Intel Corporation. 6 + * Copyright (c) 2025 Red Hat, Inc. 7 + */ 8 + 9 + #include <linux/acpi.h> 10 + #include <linux/auxiliary_bus.h> 11 + #include <linux/byteorder/generic.h> 12 + #include <linux/cleanup.h> 13 + #include <linux/completion.h> 14 + #include <linux/dev_printk.h> 15 + #include <linux/device.h> 16 + #include <linux/lockdep.h> 17 + #include <linux/mutex.h> 18 + #include <linux/string.h> 19 + #include <linux/types.h> 20 + #include <linux/usb.h> 21 + #include <linux/usb/usbio.h> 22 + 23 + /************************************* 24 + * USBIO Bridge Protocol Definitions * 25 + *************************************/ 26 + 27 + /* USBIO Control Commands */ 28 + #define USBIO_CTRLCMD_PROTVER 0 29 + #define USBIO_CTRLCMD_FWVER 1 30 + #define USBIO_CTRLCMD_HS 2 31 + #define USBIO_CTRLCMD_ENUMGPIO 16 32 + #define USBIO_CTRLCMD_ENUMI2C 17 33 + 34 + /* USBIO Packet Flags */ 35 + #define USBIO_PKTFLAG_ACK BIT(0) 36 + #define USBIO_PKTFLAG_RSP BIT(1) 37 + #define USBIO_PKTFLAG_CMP BIT(2) 38 + #define USBIO_PKTFLAG_ERR BIT(3) 39 + 40 + #define USBIO_PKTFLAGS_REQRESP (USBIO_PKTFLAG_CMP | USBIO_PKTFLAG_ACK) 41 + 42 + #define USBIO_CTRLXFER_TIMEOUT 0 43 + #define USBIO_BULKXFER_TIMEOUT 100 44 + 45 + struct usbio_protver { 46 + u8 ver; 47 + } __packed; 48 + 49 + struct usbio_fwver { 50 + u8 major; 51 + u8 minor; 52 + __le16 patch; 53 + __le16 build; 54 + } __packed; 55 + 56 + /*********************************** 57 + * USBIO Bridge Device Definitions * 58 + ***********************************/ 59 + 60 + /** 61 + * struct usbio_device - the usb device exposing IOs 62 + * 63 + * @dev: the device in the usb interface 64 + * @udev: the detected usb device 65 + * @intf: the usb interface 66 + * @quirks: quirks 67 + * @ctrl_mutex: protects ctrl_buf 68 + * @ctrl_pipe: the control transfer pipe 69 + * @ctrlbuf_len: the size of the control transfer pipe 70 + * @ctrlbuf: the buffer used for control transfers 71 + * @bulk_mutex: protects tx_buf, rx_buf and split bulk-transfers getting interrupted 72 + * @tx_pipe: the bulk out pipe 73 + * @txbuf_len: the size of the bulk out pipe 74 + * @txbuf: the buffer used for bulk out transfers 75 + * @rx_pipe: the bulk in pipe 76 + * @rxbuf_len: the size of the bulk in pipe 77 + * @rxdat_len: the data length at rx buffer 78 + * @rxbuf: the buffer used for bulk in transfers 79 + * @urb: the urb to read bulk pipe 80 + * @done: completion object as request is done 81 + * @cli_list: device's client list 82 + * @nr_gpio_banks: Number of GPIO banks 83 + * @gpios: GPIO bank descriptors 84 + * @nr_gpio_banks: Number of I2C busses 85 + * @gpios: I2C bank descriptors 86 + */ 87 + struct usbio_device { 88 + struct device *dev; 89 + struct usb_device *udev; 90 + struct usb_interface *intf; 91 + unsigned long quirks; 92 + 93 + struct mutex ctrl_mutex; 94 + unsigned int ctrl_pipe; 95 + u16 ctrlbuf_len; 96 + void *ctrlbuf; 97 + 98 + struct mutex bulk_mutex; 99 + unsigned int tx_pipe; 100 + u16 txbuf_len; 101 + void *txbuf; 102 + 103 + unsigned int rx_pipe; 104 + u16 rxbuf_len; 105 + u16 rxdat_len; 106 + void *rxbuf; 107 + struct urb *urb; 108 + 109 + struct completion done; 110 + 111 + struct list_head cli_list; 112 + 113 + unsigned int nr_gpio_banks; 114 + struct usbio_gpio_bank_desc gpios[USBIO_MAX_GPIOBANKS]; 115 + 116 + unsigned int nr_i2c_buses; 117 + struct usbio_i2c_bus_desc i2cs[USBIO_MAX_I2CBUSES]; 118 + }; 119 + 120 + /** 121 + * struct usbio_client - represents a usbio client 122 + * 123 + * @auxdev: auxiliary device object 124 + * @mutex: protects @bridge 125 + * @bridge: usbio bridge who service the client 126 + * @link: usbio bridge clients list member 127 + */ 128 + struct usbio_client { 129 + struct auxiliary_device auxdev; 130 + struct mutex mutex; 131 + struct usbio_device *bridge; 132 + struct list_head link; 133 + }; 134 + 135 + #define adev_to_client(adev) container_of_const(adev, struct usbio_client, auxdev) 136 + 137 + static int usbio_ctrl_msg(struct usbio_device *usbio, u8 type, u8 cmd, 138 + const void *obuf, u16 obuf_len, void *ibuf, u16 ibuf_len) 139 + { 140 + u8 request = USB_TYPE_VENDOR | USB_RECIP_DEVICE; 141 + struct usbio_ctrl_packet *cpkt; 142 + unsigned int pipe; 143 + u16 cpkt_len; 144 + int ret; 145 + 146 + lockdep_assert_held(&usbio->ctrl_mutex); 147 + 148 + if ((obuf_len > (usbio->ctrlbuf_len - sizeof(*cpkt))) || 149 + (ibuf_len > (usbio->ctrlbuf_len - sizeof(*cpkt)))) 150 + return -EMSGSIZE; 151 + 152 + /* Prepare Control Packet Header */ 153 + cpkt = usbio->ctrlbuf; 154 + cpkt->header.type = type; 155 + cpkt->header.cmd = cmd; 156 + if (type == USBIO_PKTTYPE_CTRL || ibuf_len) 157 + cpkt->header.flags = USBIO_PKTFLAGS_REQRESP; 158 + else 159 + cpkt->header.flags = USBIO_PKTFLAG_CMP; 160 + cpkt->len = obuf_len; 161 + 162 + /* Copy the data */ 163 + memcpy(cpkt->data, obuf, obuf_len); 164 + 165 + pipe = usb_sndctrlpipe(usbio->udev, usbio->ctrl_pipe); 166 + cpkt_len = sizeof(*cpkt) + obuf_len; 167 + ret = usb_control_msg(usbio->udev, pipe, 0, request | USB_DIR_OUT, 0, 0, 168 + cpkt, cpkt_len, USBIO_CTRLXFER_TIMEOUT); 169 + dev_dbg(usbio->dev, "control out %d hdr %*phN data %*phN\n", ret, 170 + (int)sizeof(*cpkt), cpkt, (int)cpkt->len, cpkt->data); 171 + 172 + if (ret != cpkt_len) { 173 + dev_err(usbio->dev, "USB control out failed: %d\n", ret); 174 + return (ret < 0) ? ret : -EPROTO; 175 + } 176 + 177 + if (!(cpkt->header.flags & USBIO_PKTFLAG_ACK)) 178 + return 0; 179 + 180 + pipe = usb_rcvctrlpipe(usbio->udev, usbio->ctrl_pipe); 181 + cpkt_len = sizeof(*cpkt) + ibuf_len; 182 + ret = usb_control_msg(usbio->udev, pipe, 0, request | USB_DIR_IN, 0, 0, 183 + cpkt, cpkt_len, USBIO_CTRLXFER_TIMEOUT); 184 + dev_dbg(usbio->dev, "control in %d hdr %*phN data %*phN\n", ret, 185 + (int)sizeof(*cpkt), cpkt, (int)cpkt->len, cpkt->data); 186 + 187 + if (ret < sizeof(*cpkt)) { 188 + dev_err(usbio->dev, "USB control in failed: %d\n", ret); 189 + return (ret < 0) ? ret : -EPROTO; 190 + } 191 + 192 + if (cpkt->header.type != type || cpkt->header.cmd != cmd || 193 + !(cpkt->header.flags & USBIO_PKTFLAG_RSP)) { 194 + dev_err(usbio->dev, "Unexpected reply type: %u, cmd: %u, flags: %u\n", 195 + cpkt->header.type, cpkt->header.cmd, cpkt->header.flags); 196 + return -EPROTO; 197 + } 198 + 199 + if (cpkt->header.flags & USBIO_PKTFLAG_ERR) 200 + return -EREMOTEIO; 201 + 202 + if (ibuf_len < cpkt->len) 203 + return -ENOSPC; 204 + 205 + memcpy(ibuf, cpkt->data, cpkt->len); 206 + 207 + return cpkt->len; 208 + } 209 + 210 + int usbio_control_msg(struct auxiliary_device *adev, u8 type, u8 cmd, 211 + const void *obuf, u16 obuf_len, void *ibuf, u16 ibuf_len) 212 + { 213 + struct usbio_client *client = adev_to_client(adev); 214 + struct usbio_device *usbio; 215 + int ret; 216 + 217 + guard(mutex)(&client->mutex); 218 + 219 + usbio = client->bridge; 220 + if (!usbio) 221 + return -ENODEV; /* Disconnected */ 222 + 223 + ret = usb_autopm_get_interface(usbio->intf); 224 + if (ret) 225 + return ret; 226 + 227 + mutex_lock(&usbio->ctrl_mutex); 228 + 229 + ret = usbio_ctrl_msg(client->bridge, type, cmd, obuf, obuf_len, ibuf, ibuf_len); 230 + 231 + mutex_unlock(&usbio->ctrl_mutex); 232 + usb_autopm_put_interface(usbio->intf); 233 + 234 + return ret; 235 + } 236 + EXPORT_SYMBOL_NS_GPL(usbio_control_msg, "USBIO"); 237 + 238 + static void usbio_bulk_recv(struct urb *urb) 239 + { 240 + struct usbio_bulk_packet *bpkt = urb->transfer_buffer; 241 + struct usbio_device *usbio = urb->context; 242 + 243 + if (!urb->status) { 244 + if (bpkt->header.flags & USBIO_PKTFLAG_RSP) { 245 + usbio->rxdat_len = urb->actual_length; 246 + complete(&usbio->done); 247 + } 248 + } else if (urb->status != -ENOENT) { 249 + dev_err(usbio->dev, "Bulk in error %d\n", urb->status); 250 + } 251 + 252 + usb_submit_urb(usbio->urb, GFP_ATOMIC); 253 + } 254 + 255 + int usbio_bulk_msg(struct auxiliary_device *adev, u8 type, u8 cmd, bool last, 256 + const void *obuf, u16 obuf_len, void *ibuf, u16 ibuf_len) 257 + { 258 + struct usbio_client *client = adev_to_client(adev); 259 + struct usbio_device *usbio = client->bridge; 260 + struct usbio_bulk_packet *bpkt; 261 + int ret, act = 0; 262 + u16 bpkt_len; 263 + 264 + lockdep_assert_held(&client->mutex); 265 + lockdep_assert_held(&usbio->bulk_mutex); 266 + 267 + if ((obuf_len > (usbio->txbuf_len - sizeof(*bpkt))) || 268 + (ibuf_len > (usbio->txbuf_len - sizeof(*bpkt)))) 269 + return -EMSGSIZE; 270 + 271 + if (ibuf_len) 272 + reinit_completion(&usbio->done); 273 + 274 + /* If no data to send, skip to read */ 275 + if (!obuf_len) 276 + goto read; 277 + 278 + /* Prepare Bulk Packet Header */ 279 + bpkt = usbio->txbuf; 280 + bpkt->header.type = type; 281 + bpkt->header.cmd = cmd; 282 + if (!last) 283 + bpkt->header.flags = 0; 284 + else if (ibuf_len) 285 + bpkt->header.flags = USBIO_PKTFLAGS_REQRESP; 286 + else 287 + bpkt->header.flags = USBIO_PKTFLAG_CMP; 288 + bpkt->len = cpu_to_le16(obuf_len); 289 + 290 + /* Copy the data */ 291 + memcpy(bpkt->data, obuf, obuf_len); 292 + 293 + bpkt_len = sizeof(*bpkt) + obuf_len; 294 + ret = usb_bulk_msg(usbio->udev, usbio->tx_pipe, bpkt, bpkt_len, &act, 295 + USBIO_BULKXFER_TIMEOUT); 296 + dev_dbg(usbio->dev, "bulk out %d hdr %*phN data %*phN\n", act, 297 + (int)sizeof(*bpkt), bpkt, obuf_len, bpkt->data); 298 + 299 + if (ret || act != bpkt_len) { 300 + dev_err(usbio->dev, "Bulk out failed: %d\n", ret); 301 + return ret ?: -EPROTO; 302 + } 303 + 304 + if (!(bpkt->header.flags & USBIO_PKTFLAG_ACK)) 305 + return obuf_len; 306 + 307 + read: 308 + ret = wait_for_completion_timeout(&usbio->done, USBIO_BULKXFER_TIMEOUT); 309 + if (ret <= 0) { 310 + dev_err(usbio->dev, "Bulk in wait failed: %d\n", ret); 311 + return ret ?: -ETIMEDOUT; 312 + } 313 + 314 + act = usbio->rxdat_len; 315 + bpkt = usbio->rxbuf; 316 + bpkt_len = le16_to_cpu(bpkt->len); 317 + dev_dbg(usbio->dev, "bulk in %d hdr %*phN data %*phN\n", act, 318 + (int)sizeof(*bpkt), bpkt, bpkt_len, bpkt->data); 319 + 320 + /* 321 + * Unsupported bulk commands get only an usbio_packet_header with 322 + * the error flag set as reply. Return -EPIPE for this case. 323 + */ 324 + if (act == sizeof(struct usbio_packet_header) && 325 + (bpkt->header.flags & USBIO_PKTFLAG_ERR)) 326 + return -EPIPE; 327 + 328 + if (act < sizeof(*bpkt)) { 329 + dev_err(usbio->dev, "Bulk in short read: %d\n", act); 330 + return -EPROTO; 331 + } 332 + 333 + if (bpkt->header.type != type || bpkt->header.cmd != cmd || 334 + !(bpkt->header.flags & USBIO_PKTFLAG_RSP)) { 335 + dev_err(usbio->dev, 336 + "Unexpected bulk in type 0x%02x cmd 0x%02x flags 0x%02x\n", 337 + bpkt->header.type, bpkt->header.cmd, bpkt->header.flags); 338 + return -EPROTO; 339 + } 340 + 341 + if (bpkt->header.flags & USBIO_PKTFLAG_ERR) 342 + return -EREMOTEIO; 343 + 344 + if (ibuf_len < bpkt_len) 345 + return -ENOSPC; 346 + 347 + memcpy(ibuf, bpkt->data, bpkt_len); 348 + 349 + return bpkt_len; 350 + } 351 + EXPORT_SYMBOL_NS_GPL(usbio_bulk_msg, "USBIO"); 352 + 353 + int usbio_acquire(struct auxiliary_device *adev) 354 + { 355 + struct usbio_client *client = adev_to_client(adev); 356 + struct usbio_device *usbio; 357 + int ret; 358 + 359 + mutex_lock(&client->mutex); 360 + 361 + usbio = client->bridge; 362 + if (!usbio) { 363 + ret = -ENODEV; /* Disconnected */ 364 + goto err_unlock; 365 + } 366 + 367 + ret = usb_autopm_get_interface(usbio->intf); 368 + if (ret) 369 + goto err_unlock; 370 + 371 + mutex_lock(&usbio->bulk_mutex); 372 + 373 + /* Leave client locked until release to avoid abba deadlock issues */ 374 + return 0; 375 + 376 + err_unlock: 377 + mutex_unlock(&client->mutex); 378 + 379 + return ret; 380 + } 381 + EXPORT_SYMBOL_NS_GPL(usbio_acquire, "USBIO"); 382 + 383 + void usbio_release(struct auxiliary_device *adev) 384 + { 385 + struct usbio_client *client = adev_to_client(adev); 386 + struct usbio_device *usbio = client->bridge; 387 + 388 + lockdep_assert_held(&client->mutex); 389 + 390 + mutex_unlock(&usbio->bulk_mutex); 391 + usb_autopm_put_interface(usbio->intf); 392 + mutex_unlock(&client->mutex); 393 + } 394 + EXPORT_SYMBOL_NS_GPL(usbio_release, "USBIO"); 395 + 396 + void usbio_get_txrxbuf_len(struct auxiliary_device *adev, u16 *txbuf_len, u16 *rxbuf_len) 397 + { 398 + struct usbio_client *client = adev_to_client(adev); 399 + struct usbio_device *usbio; 400 + 401 + guard(mutex)(&client->mutex); 402 + 403 + usbio = client->bridge; 404 + if (!usbio) 405 + return; /* Disconnected */ 406 + 407 + *txbuf_len = usbio->txbuf_len; 408 + *rxbuf_len = usbio->rxbuf_len; 409 + } 410 + EXPORT_SYMBOL_NS_GPL(usbio_get_txrxbuf_len, "USBIO"); 411 + 412 + unsigned long usbio_get_quirks(struct auxiliary_device *adev) 413 + { 414 + struct usbio_client *client = adev_to_client(adev); 415 + struct usbio_device *usbio; 416 + 417 + guard(mutex)(&client->mutex); 418 + 419 + usbio = client->bridge; 420 + if (!usbio) 421 + return 0; /* Disconnected */ 422 + 423 + return usbio->quirks; 424 + } 425 + EXPORT_SYMBOL_NS_GPL(usbio_get_quirks, "USBIO"); 426 + 427 + static void usbio_auxdev_release(struct device *dev) 428 + { 429 + struct auxiliary_device *adev = to_auxiliary_dev(dev); 430 + struct usbio_client *client = adev_to_client(adev); 431 + 432 + mutex_destroy(&client->mutex); 433 + kfree(client); 434 + } 435 + 436 + static int usbio_add_client(struct usbio_device *usbio, char *name, u8 id, void *data) 437 + { 438 + struct usbio_client *client; 439 + struct auxiliary_device *adev; 440 + int ret; 441 + 442 + client = kzalloc(sizeof(*client), GFP_KERNEL); 443 + if (!client) 444 + return -ENOMEM; 445 + 446 + mutex_init(&client->mutex); 447 + client->bridge = usbio; 448 + adev = &client->auxdev; 449 + adev->name = name; 450 + adev->id = id; 451 + 452 + adev->dev.parent = usbio->dev; 453 + adev->dev.platform_data = data; 454 + adev->dev.release = usbio_auxdev_release; 455 + 456 + ret = auxiliary_device_init(adev); 457 + if (ret) { 458 + usbio_auxdev_release(&adev->dev); 459 + return ret; 460 + } 461 + 462 + ret = auxiliary_device_add(adev); 463 + if (ret) { 464 + auxiliary_device_uninit(adev); 465 + return ret; 466 + } 467 + 468 + list_add_tail(&client->link, &usbio->cli_list); 469 + 470 + return 0; 471 + } 472 + 473 + static int usbio_enum_gpios(struct usbio_device *usbio) 474 + { 475 + struct usbio_gpio_bank_desc *gpio = usbio->gpios; 476 + 477 + dev_dbg(usbio->dev, "GPIO Banks: %d\n", usbio->nr_gpio_banks); 478 + 479 + for (unsigned int i = 0; i < usbio->nr_gpio_banks; i++) 480 + dev_dbg(usbio->dev, "\tBank%d[%d] map: %#08x\n", 481 + gpio[i].id, gpio[i].pins, gpio[i].bmap); 482 + 483 + usbio_add_client(usbio, USBIO_GPIO_CLIENT, 0, gpio); 484 + 485 + return 0; 486 + } 487 + 488 + static int usbio_enum_i2cs(struct usbio_device *usbio) 489 + { 490 + struct usbio_i2c_bus_desc *i2c = usbio->i2cs; 491 + 492 + dev_dbg(usbio->dev, "I2C Busses: %d\n", usbio->nr_i2c_buses); 493 + 494 + for (unsigned int i = 0; i < usbio->nr_i2c_buses; i++) { 495 + dev_dbg(usbio->dev, "\tBus%d caps: %#02x\n", i2c[i].id, i2c[i].caps); 496 + usbio_add_client(usbio, USBIO_I2C_CLIENT, i, &i2c[i]); 497 + } 498 + 499 + return 0; 500 + } 501 + 502 + static int usbio_suspend(struct usb_interface *intf, pm_message_t msg) 503 + { 504 + struct usbio_device *usbio = usb_get_intfdata(intf); 505 + 506 + usb_kill_urb(usbio->urb); 507 + 508 + return 0; 509 + } 510 + 511 + static int usbio_resume(struct usb_interface *intf) 512 + { 513 + struct usbio_device *usbio = usb_get_intfdata(intf); 514 + 515 + return usb_submit_urb(usbio->urb, GFP_KERNEL); 516 + } 517 + 518 + static void usbio_disconnect(struct usb_interface *intf) 519 + { 520 + struct usbio_device *usbio = usb_get_intfdata(intf); 521 + struct usbio_client *client; 522 + 523 + /* Wakeup any clients waiting for a reply */ 524 + usbio->rxdat_len = 0; 525 + complete(&usbio->done); 526 + 527 + /* Let clients know the bridge is gone */ 528 + list_for_each_entry(client, &usbio->cli_list, link) { 529 + mutex_lock(&client->mutex); 530 + client->bridge = NULL; 531 + mutex_unlock(&client->mutex); 532 + } 533 + 534 + /* From here on clients will no longer touch struct usbio_device */ 535 + usb_kill_urb(usbio->urb); 536 + usb_free_urb(usbio->urb); 537 + 538 + list_for_each_entry_reverse(client, &usbio->cli_list, link) { 539 + auxiliary_device_delete(&client->auxdev); 540 + auxiliary_device_uninit(&client->auxdev); 541 + } 542 + } 543 + 544 + static int usbio_probe(struct usb_interface *intf, const struct usb_device_id *id) 545 + { 546 + struct usb_device *udev = interface_to_usbdev(intf); 547 + struct usb_endpoint_descriptor *ep_in, *ep_out; 548 + struct device *dev = &intf->dev; 549 + struct usbio_protver protver; 550 + struct usbio_device *usbio; 551 + struct usbio_fwver fwver; 552 + int ret; 553 + 554 + usbio = devm_kzalloc(dev, sizeof(*usbio), GFP_KERNEL); 555 + if (!usbio) 556 + return -ENOMEM; 557 + 558 + ret = devm_mutex_init(dev, &usbio->ctrl_mutex); 559 + if (ret) 560 + return ret; 561 + 562 + ret = devm_mutex_init(dev, &usbio->bulk_mutex); 563 + if (ret) 564 + return ret; 565 + 566 + usbio->dev = dev; 567 + usbio->udev = udev; 568 + usbio->intf = intf; 569 + usbio->quirks = id ? id->driver_info : 0; 570 + init_completion(&usbio->done); 571 + INIT_LIST_HEAD(&usbio->cli_list); 572 + usb_set_intfdata(intf, usbio); 573 + 574 + usbio->ctrl_pipe = usb_endpoint_num(&udev->ep0.desc); 575 + usbio->ctrlbuf_len = usb_maxpacket(udev, usbio->ctrl_pipe); 576 + usbio->ctrlbuf = devm_kzalloc(dev, usbio->ctrlbuf_len, GFP_KERNEL); 577 + if (!usbio->ctrlbuf) 578 + return -ENOMEM; 579 + 580 + /* Find the first bulk-in and bulk-out endpoints */ 581 + ret = usb_find_common_endpoints(intf->cur_altsetting, &ep_in, &ep_out, 582 + NULL, NULL); 583 + if (ret) { 584 + dev_err(dev, "Cannot find bulk endpoints: %d\n", ret); 585 + return ret; 586 + } 587 + 588 + usbio->tx_pipe = usb_sndbulkpipe(udev, usb_endpoint_num(ep_out)); 589 + 590 + if (usbio->quirks & USBIO_QUIRK_BULK_MAXP_63) 591 + usbio->txbuf_len = 63; 592 + else 593 + usbio->txbuf_len = usb_endpoint_maxp(ep_out); 594 + 595 + usbio->txbuf = devm_kzalloc(dev, usbio->txbuf_len, GFP_KERNEL); 596 + if (!usbio->txbuf) 597 + return -ENOMEM; 598 + 599 + usbio->rx_pipe = usb_rcvbulkpipe(udev, usb_endpoint_num(ep_in)); 600 + 601 + if (usbio->quirks & USBIO_QUIRK_BULK_MAXP_63) 602 + usbio->rxbuf_len = 63; 603 + else 604 + usbio->rxbuf_len = usb_endpoint_maxp(ep_in); 605 + 606 + usbio->rxbuf = devm_kzalloc(dev, usbio->rxbuf_len, GFP_KERNEL); 607 + if (!usbio->rxbuf) 608 + return -ENOMEM; 609 + 610 + usbio->urb = usb_alloc_urb(0, GFP_KERNEL); 611 + if (!usbio->urb) 612 + return -ENOMEM; 613 + 614 + usb_fill_bulk_urb(usbio->urb, udev, usbio->rx_pipe, usbio->rxbuf, 615 + usbio->rxbuf_len, usbio_bulk_recv, usbio); 616 + ret = usb_submit_urb(usbio->urb, GFP_KERNEL); 617 + if (ret) 618 + return dev_err_probe(dev, ret, "Submitting usb urb\n"); 619 + 620 + mutex_lock(&usbio->ctrl_mutex); 621 + 622 + ret = usbio_ctrl_msg(usbio, USBIO_PKTTYPE_CTRL, USBIO_CTRLCMD_HS, NULL, 0, NULL, 0); 623 + if (ret < 0) 624 + goto err_unlock; 625 + 626 + ret = usbio_ctrl_msg(usbio, USBIO_PKTTYPE_CTRL, USBIO_CTRLCMD_PROTVER, NULL, 0, 627 + &protver, sizeof(protver)); 628 + if (ret < 0) 629 + goto err_unlock; 630 + 631 + ret = usbio_ctrl_msg(usbio, USBIO_PKTTYPE_CTRL, USBIO_CTRLCMD_FWVER, NULL, 0, 632 + &fwver, sizeof(fwver)); 633 + if (ret < 0) 634 + goto err_unlock; 635 + 636 + ret = usbio_ctrl_msg(usbio, USBIO_PKTTYPE_CTRL, USBIO_CTRLCMD_ENUMGPIO, NULL, 0, 637 + usbio->gpios, sizeof(usbio->gpios)); 638 + if (ret < 0 || ret % sizeof(struct usbio_gpio_bank_desc)) { 639 + ret = (ret < 0) ? ret : -EPROTO; 640 + goto err_unlock; 641 + } 642 + usbio->nr_gpio_banks = ret / sizeof(struct usbio_gpio_bank_desc); 643 + 644 + ret = usbio_ctrl_msg(usbio, USBIO_PKTTYPE_CTRL, USBIO_CTRLCMD_ENUMI2C, NULL, 0, 645 + usbio->i2cs, sizeof(usbio->i2cs)); 646 + if (ret < 0 || ret % sizeof(struct usbio_i2c_bus_desc)) { 647 + ret = (ret < 0) ? ret : -EPROTO; 648 + goto err_unlock; 649 + } 650 + usbio->nr_i2c_buses = ret / sizeof(struct usbio_i2c_bus_desc); 651 + 652 + mutex_unlock(&usbio->ctrl_mutex); 653 + 654 + dev_dbg(dev, "ProtVer(BCD): %02x FwVer: %d.%d.%d.%d\n", 655 + protver.ver, fwver.major, fwver.minor, 656 + le16_to_cpu(fwver.patch), le16_to_cpu(fwver.build)); 657 + 658 + usbio_enum_gpios(usbio); 659 + usbio_enum_i2cs(usbio); 660 + 661 + return 0; 662 + 663 + err_unlock: 664 + mutex_unlock(&usbio->ctrl_mutex); 665 + usb_kill_urb(usbio->urb); 666 + usb_free_urb(usbio->urb); 667 + 668 + return ret; 669 + } 670 + 671 + static const struct usb_device_id usbio_table[] = { 672 + { USB_DEVICE(0x2ac1, 0x20c1), /* Lattice NX40 */ 673 + .driver_info = USBIO_QUIRK_I2C_MAX_RW_LEN_52 }, 674 + { USB_DEVICE(0x2ac1, 0x20c9), /* Lattice NX33 */ 675 + .driver_info = USBIO_QUIRK_I2C_NO_INIT_ACK | USBIO_QUIRK_I2C_MAX_RW_LEN_52 | 676 + USBIO_QUIRK_I2C_ALLOW_400KHZ }, 677 + { USB_DEVICE(0x2ac1, 0x20cb) }, /* Lattice NX33U */ 678 + { USB_DEVICE(0x06cb, 0x0701), /* Synaptics Sabre */ 679 + .driver_info = USBIO_QUIRK_BULK_MAXP_63 | USBIO_QUIRK_I2C_USE_CHUNK_LEN }, 680 + { } 681 + }; 682 + MODULE_DEVICE_TABLE(usb, usbio_table); 683 + 684 + static struct usb_driver usbio_driver = { 685 + .name = "usbio-bridge", 686 + .probe = usbio_probe, 687 + .disconnect = usbio_disconnect, 688 + .suspend = usbio_suspend, 689 + .resume = usbio_resume, 690 + .id_table = usbio_table, 691 + .supports_autosuspend = 1, 692 + }; 693 + module_usb_driver(usbio_driver); 694 + 695 + struct usbio_match_ids_walk_data { 696 + struct acpi_device *adev; 697 + const struct acpi_device_id *hids; 698 + unsigned int id; 699 + }; 700 + 701 + static int usbio_match_device_ids(struct acpi_device *adev, void *data) 702 + { 703 + struct usbio_match_ids_walk_data *wd = data; 704 + unsigned int id = 0; 705 + char *uid; 706 + 707 + if (acpi_match_device_ids(adev, wd->hids)) 708 + return 0; 709 + 710 + uid = acpi_device_uid(adev); 711 + if (uid) { 712 + for (int i = 0; i < strlen(uid); i++) { 713 + if (!kstrtouint(&uid[i], 10, &id)) 714 + break; 715 + } 716 + } 717 + 718 + if (!uid || wd->id == id) { 719 + wd->adev = adev; 720 + return 1; 721 + } 722 + 723 + return 0; 724 + } 725 + 726 + void usbio_acpi_bind(struct auxiliary_device *adev, const struct acpi_device_id *hids) 727 + { 728 + struct device *dev = &adev->dev; 729 + struct acpi_device *parent; 730 + struct usbio_match_ids_walk_data wd = { 731 + .adev = NULL, 732 + .hids = hids, 733 + .id = adev->id, 734 + }; 735 + 736 + parent = ACPI_COMPANION(dev->parent); 737 + if (!parent) 738 + return; 739 + 740 + acpi_dev_for_each_child(parent, usbio_match_device_ids, &wd); 741 + if (wd.adev) 742 + ACPI_COMPANION_SET(dev, wd.adev); 743 + } 744 + EXPORT_SYMBOL_NS_GPL(usbio_acpi_bind, "USBIO"); 745 + 746 + MODULE_DESCRIPTION("Intel USBIO Bridge driver"); 747 + MODULE_AUTHOR("Israel Cepeda <israel.a.cepeda.lopez@intel.com>"); 748 + MODULE_AUTHOR("Hans de Goede <hansg@kernel.org>"); 749 + MODULE_LICENSE("GPL");
+8 -6
drivers/usb/mon/mon_bin.c
··· 68 68 * The magic limit was calculated so that it allows the monitoring 69 69 * application to pick data once in two ticks. This way, another application, 70 70 * which presumably drives the bus, gets to hog CPU, yet we collect our data. 71 - * If HZ is 100, a 480 mbit/s bus drives 614 KB every jiffy. USB has an 72 - * enormous overhead built into the bus protocol, so we need about 1000 KB. 71 + * 72 + * Originally, for a 480 Mbit/s bus this required a buffer of about 1 MB. For 73 + * modern 20 Gbps buses, this value increases to over 50 MB. The maximum 74 + * buffer size is set to 64 MiB to accommodate this. 73 75 * 74 76 * This is still too much for most cases, where we just snoop a few 75 77 * descriptor fetches for enumeration. So, the default is a "reasonable" 76 - * amount for systems with HZ=250 and incomplete bus saturation. 78 + * amount for typical, low-throughput use cases. 77 79 * 78 80 * XXX What about multi-megabyte URBs which take minutes to transfer? 79 81 */ 80 - #define BUFF_MAX CHUNK_ALIGN(1200*1024) 81 - #define BUFF_DFL CHUNK_ALIGN(300*1024) 82 - #define BUFF_MIN CHUNK_ALIGN(8*1024) 82 + #define BUFF_MAX CHUNK_ALIGN(64*1024*1024) 83 + #define BUFF_DFL CHUNK_ALIGN(300*1024) 84 + #define BUFF_MIN CHUNK_ALIGN(8*1024) 83 85 84 86 /* 85 87 * The per-event API header (2 per URB).
+1 -1
drivers/usb/musb/musb_dsps.c
··· 839 839 { 840 840 int error; 841 841 842 - glue->vbus_irq = platform_get_irq_byname(pdev, "vbus"); 842 + glue->vbus_irq = platform_get_irq_byname_optional(pdev, "vbus"); 843 843 if (glue->vbus_irq == -EPROBE_DEFER) 844 844 return -EPROBE_DEFER; 845 845
+1 -2
drivers/usb/phy/phy-twl6030-usb.c
··· 328 328 329 329 static int twl6030_usb_probe(struct platform_device *pdev) 330 330 { 331 - u32 ret; 332 331 struct twl6030_usb *twl; 333 - int status, err; 332 + int status, err, ret; 334 333 struct device_node *np = pdev->dev.of_node; 335 334 struct device *dev = &pdev->dev; 336 335
+4
drivers/usb/renesas_usbhs/common.c
··· 580 580 .data = &usbhs_rzg2l_plat_info, 581 581 }, 582 582 { 583 + .compatible = "renesas,usbhs-r9a09g077", 584 + .data = &usbhs_rzg2l_plat_info, 585 + }, 586 + { 583 587 .compatible = "renesas,rcar-gen2-usbhs", 584 588 .data = &usbhs_rcar_gen2_plat_info, 585 589 },
+6
drivers/usb/serial/option.c
··· 2114 2114 { USB_DEVICE_INTERFACE_CLASS(0x1e0e, 0x9003, 0xff) }, /* Simcom SIM7500/SIM7600 MBIM mode */ 2115 2115 { USB_DEVICE_INTERFACE_CLASS(0x1e0e, 0x9011, 0xff), /* Simcom SIM7500/SIM7600 RNDIS mode */ 2116 2116 .driver_info = RSVD(7) }, 2117 + { USB_DEVICE(0x1e0e, 0x9071), /* Simcom SIM8230 RMNET mode */ 2118 + .driver_info = RSVD(3) | RSVD(4) }, 2119 + { USB_DEVICE_INTERFACE_CLASS(0x1e0e, 0x9078, 0xff), /* Simcom SIM8230 ECM mode */ 2120 + .driver_info = RSVD(5) }, 2121 + { USB_DEVICE_INTERFACE_CLASS(0x1e0e, 0x907b, 0xff), /* Simcom SIM8230 RNDIS mode */ 2122 + .driver_info = RSVD(5) }, 2117 2123 { USB_DEVICE_INTERFACE_CLASS(0x1e0e, 0x9205, 0xff) }, /* Simcom SIM7070/SIM7080/SIM7090 AT+ECM mode */ 2118 2124 { USB_DEVICE_INTERFACE_CLASS(0x1e0e, 0x9206, 0xff) }, /* Simcom SIM7070/SIM7080/SIM7090 AT-only mode */ 2119 2125 { USB_DEVICE(ALCATEL_VENDOR_ID, ALCATEL_PRODUCT_X060S_X200),
+1 -1
drivers/usb/serial/oti6858.c
··· 106 106 #define PIN_DTR 0x04 /* output pin */ 107 107 #define PIN_RI 0x02 /* input pin, active low */ 108 108 #define PIN_DCD 0x01 /* input pin, active low */ 109 - u8 rx_bytes_avail; /* number of bytes in rx buffer */; 109 + u8 rx_bytes_avail; /* number of bytes in rx buffer */ 110 110 }; 111 111 112 112 #define OTI6858_CTRL_PKT_SIZE sizeof(struct oti6858_control_pkt)
+2 -2
drivers/usb/storage/realtek_cr.c
··· 260 260 * try to compute the actual residue, based on how much data 261 261 * was really transferred and what the device tells us 262 262 */ 263 - if (residue) 264 - residue = residue < buf_len ? residue : buf_len; 263 + if (residue > buf_len) 264 + residue = buf_len; 265 265 266 266 if (act_len) 267 267 *act_len = buf_len - residue;
+1 -1
drivers/usb/typec/mux/tusb1046.c
··· 129 129 130 130 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); 131 131 if (!priv) 132 - return dev_err_probe(dev, -ENOMEM, "failed to allocate driver data\n"); 132 + return -ENOMEM; 133 133 134 134 priv->client = client; 135 135
+1 -1
drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c
··· 567 567 if (!res->nr_irqs || res->nr_irqs > PMIC_PDPHY_MAX_IRQS) 568 568 return -EINVAL; 569 569 570 - irq_data = devm_kzalloc(dev, sizeof(*irq_data) * res->nr_irqs, 570 + irq_data = devm_kcalloc(dev, res->nr_irqs, sizeof(*irq_data), 571 571 GFP_KERNEL); 572 572 if (!irq_data) 573 573 return -ENOMEM;
+1 -1
drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c
··· 713 713 if (!res->nr_irqs || res->nr_irqs > PMIC_TYPEC_MAX_IRQS) 714 714 return -EINVAL; 715 715 716 - irq_data = devm_kzalloc(dev, sizeof(*irq_data) * res->nr_irqs, 716 + irq_data = devm_kcalloc(dev, res->nr_irqs, sizeof(*irq_data), 717 717 GFP_KERNEL); 718 718 if (!irq_data) 719 719 return -ENOMEM;
+33
drivers/usb/typec/tcpm/tcpci.c
··· 949 949 if (err < 0) 950 950 goto unregister_port; 951 951 952 + device_set_wakeup_capable(chip->tcpci->dev, true); 953 + 952 954 return 0; 953 955 954 956 unregister_port: ··· 971 969 tcpci_unregister_port(chip->tcpci); 972 970 } 973 971 972 + static int tcpci_suspend(struct device *dev) 973 + { 974 + struct i2c_client *i2c = to_i2c_client(dev); 975 + struct tcpci_chip *chip = i2c_get_clientdata(i2c); 976 + int ret; 977 + 978 + if (device_may_wakeup(dev)) 979 + ret = enable_irq_wake(i2c->irq); 980 + else 981 + ret = tcpci_write16(chip->tcpci, TCPC_ALERT_MASK, 0); 982 + 983 + return ret; 984 + } 985 + 986 + static int tcpci_resume(struct device *dev) 987 + { 988 + struct i2c_client *i2c = to_i2c_client(dev); 989 + struct tcpci_chip *chip = i2c_get_clientdata(i2c); 990 + int ret; 991 + 992 + if (device_may_wakeup(dev)) 993 + ret = disable_irq_wake(i2c->irq); 994 + else 995 + ret = tcpci_write16(chip->tcpci, TCPC_ALERT_MASK, chip->tcpci->alert_mask); 996 + 997 + return ret; 998 + } 999 + 1000 + DEFINE_SIMPLE_DEV_PM_OPS(tcpci_pm_ops, tcpci_suspend, tcpci_resume); 1001 + 974 1002 static const struct i2c_device_id tcpci_id[] = { 975 1003 { "tcpci" }, 976 1004 { } ··· 1019 987 static struct i2c_driver tcpci_i2c_driver = { 1020 988 .driver = { 1021 989 .name = "tcpci", 990 + .pm = pm_sleep_ptr(&tcpci_pm_ops), 1022 991 .of_match_table = of_match_ptr(tcpci_of_match), 1023 992 }, 1024 993 .probe = tcpci_probe,
+506 -53
drivers/usb/typec/tipd/core.c
··· 16 16 #include <linux/interrupt.h> 17 17 #include <linux/usb/typec.h> 18 18 #include <linux/usb/typec_altmode.h> 19 + #include <linux/usb/typec_dp.h> 20 + #include <linux/usb/typec_mux.h> 21 + #include <linux/usb/typec_tbt.h> 19 22 #include <linux/usb/role.h> 20 23 #include <linux/workqueue.h> 21 24 #include <linux/firmware.h> ··· 38 35 #define TPS_REG_INT_MASK2 0x17 39 36 #define TPS_REG_INT_CLEAR1 0x18 40 37 #define TPS_REG_INT_CLEAR2 0x19 41 - #define TPS_REG_SYSTEM_POWER_STATE 0x20 42 38 #define TPS_REG_STATUS 0x1a 39 + #define TPS_REG_SYSTEM_POWER_STATE 0x20 40 + #define TPS_REG_USB4_STATUS 0x24 43 41 #define TPS_REG_SYSTEM_CONF 0x28 44 42 #define TPS_REG_CTRL_CONF 0x29 45 43 #define TPS_REG_BOOT_STATUS 0x2D 46 44 #define TPS_REG_POWER_STATUS 0x3f 47 45 #define TPS_REG_PD_STATUS 0x40 48 46 #define TPS_REG_RX_IDENTITY_SOP 0x48 47 + #define TPS_REG_CF_VID_STATUS 0x5e 48 + #define TPS_REG_DP_SID_STATUS 0x58 49 + #define TPS_REG_INTEL_VID_STATUS 0x59 49 50 #define TPS_REG_DATA_STATUS 0x5f 50 51 #define TPS_REG_SLEEP_CONF 0x70 51 52 ··· 92 85 struct usb_pd_identity identity; 93 86 } __packed; 94 87 88 + /* TPS_REG_USB4_STATUS */ 89 + struct tps6598x_usb4_status_reg { 90 + u8 mode_status; 91 + __le32 eudo; 92 + __le32 unknown; 93 + } __packed; 94 + 95 + /* TPS_REG_DP_SID_STATUS */ 96 + struct tps6598x_dp_sid_status_reg { 97 + u8 mode_status; 98 + __le32 status_tx; 99 + __le32 status_rx; 100 + __le32 configure; 101 + __le32 mode_data; 102 + } __packed; 103 + 104 + /* TPS_REG_INTEL_VID_STATUS */ 105 + struct tps6598x_intel_vid_status_reg { 106 + u8 mode_status; 107 + __le32 attention_vdo; 108 + __le16 enter_vdo; 109 + __le16 device_mode; 110 + __le16 cable_mode; 111 + } __packed; 112 + 95 113 /* Standard Task return codes */ 96 114 #define TPS_TASK_TIMEOUT 1 97 115 #define TPS_TASK_REJECTED 3 116 + 117 + /* Debounce delay for mode changes, in milliseconds */ 118 + #define CD321X_DEBOUNCE_DELAY_MS 500 98 119 99 120 enum { 100 121 TPS_MODE_APP, ··· 147 112 148 113 struct tipd_data { 149 114 irq_handler_t irq_handler; 115 + u64 irq_mask1; 116 + size_t tps_struct_size; 117 + void (*remove)(struct tps6598x *tps); 150 118 int (*register_port)(struct tps6598x *tps, struct fwnode_handle *node); 119 + void (*unregister_port)(struct tps6598x *tps); 120 + void (*trace_data_status)(u32 status); 151 121 void (*trace_power_status)(u16 status); 152 122 void (*trace_status)(u32 status); 153 123 int (*apply_patch)(struct tps6598x *tps); 154 124 int (*init)(struct tps6598x *tps); 125 + int (*switch_power_state)(struct tps6598x *tps, u8 target_state); 126 + bool (*read_data_status)(struct tps6598x *tps); 155 127 int (*reset)(struct tps6598x *tps); 128 + int (*connect)(struct tps6598x *tps, u32 status); 156 129 }; 157 130 158 131 struct tps6598x { ··· 182 139 183 140 int wakeup; 184 141 u32 status; /* status reg */ 142 + u32 data_status; 185 143 u16 pwr_status; 186 144 struct delayed_work wq_poll; 187 145 188 146 const struct tipd_data *data; 147 + }; 148 + 149 + struct cd321x_status { 150 + u32 status; 151 + u32 pwr_status; 152 + u32 data_status; 153 + u32 status_changed; 154 + struct usb_pd_identity partner_identity; 155 + struct tps6598x_dp_sid_status_reg dp_sid_status; 156 + struct tps6598x_intel_vid_status_reg intel_vid_status; 157 + struct tps6598x_usb4_status_reg usb4_status; 158 + }; 159 + 160 + struct cd321x { 161 + struct tps6598x tps; 162 + 163 + struct tps6598x_dp_sid_status_reg dp_sid_status; 164 + struct tps6598x_intel_vid_status_reg intel_vid_status; 165 + struct tps6598x_usb4_status_reg usb4_status; 166 + 167 + struct typec_altmode *port_altmode_dp; 168 + struct typec_altmode *port_altmode_tbt; 169 + 170 + struct typec_mux *mux; 171 + struct typec_mux_state state; 172 + 173 + struct cd321x_status update_status; 174 + struct delayed_work update_work; 175 + struct usb_pd_identity cur_partner_identity; 189 176 }; 190 177 191 178 static enum power_supply_property tps6598x_psy_props[] = { ··· 563 490 dev_err(tps->dev, "failed to read data status: %d\n", ret); 564 491 return false; 565 492 } 566 - trace_tps6598x_data_status(data_status); 493 + tps->data_status = data_status; 494 + 495 + if (tps->data->trace_data_status) 496 + tps->data->trace_data_status(data_status); 497 + 498 + return true; 499 + } 500 + 501 + static bool cd321x_read_data_status(struct tps6598x *tps) 502 + { 503 + struct cd321x *cd321x = container_of(tps, struct cd321x, tps); 504 + int ret; 505 + 506 + ret = tps6598x_read_data_status(tps); 507 + if (ret < 0) 508 + return false; 509 + 510 + if (tps->data_status & TPS_DATA_STATUS_DP_CONNECTION) { 511 + ret = tps6598x_block_read(tps, TPS_REG_DP_SID_STATUS, 512 + &cd321x->dp_sid_status, sizeof(cd321x->dp_sid_status)); 513 + if (ret) 514 + dev_err(tps->dev, "Failed to read DP SID Status: %d\n", 515 + ret); 516 + } 517 + 518 + if (tps->data_status & TPS_DATA_STATUS_TBT_CONNECTION) { 519 + ret = tps6598x_block_read(tps, TPS_REG_INTEL_VID_STATUS, 520 + &cd321x->intel_vid_status, sizeof(cd321x->intel_vid_status)); 521 + if (ret) 522 + dev_err(tps->dev, "Failed to read Intel VID Status: %d\n", ret); 523 + } 524 + 525 + if (tps->data_status & CD321X_DATA_STATUS_USB4_CONNECTION) { 526 + ret = tps6598x_block_read(tps, TPS_REG_USB4_STATUS, 527 + &cd321x->usb4_status, sizeof(cd321x->usb4_status)); 528 + if (ret) 529 + dev_err(tps->dev, 530 + "Failed to read USB4 Status: %d\n", ret); 531 + } 567 532 568 533 return true; 569 534 } ··· 637 526 } 638 527 } 639 528 529 + static void cd321x_typec_update_mode(struct tps6598x *tps, struct cd321x_status *st) 530 + { 531 + struct cd321x *cd321x = container_of(tps, struct cd321x, tps); 532 + 533 + if (!(st->data_status & TPS_DATA_STATUS_DATA_CONNECTION)) { 534 + if (cd321x->state.mode == TYPEC_STATE_SAFE) 535 + return; 536 + cd321x->state.alt = NULL; 537 + cd321x->state.mode = TYPEC_STATE_SAFE; 538 + cd321x->state.data = NULL; 539 + typec_mux_set(cd321x->mux, &cd321x->state); 540 + } else if (st->data_status & TPS_DATA_STATUS_DP_CONNECTION) { 541 + struct typec_displayport_data dp_data; 542 + unsigned long mode; 543 + 544 + switch (TPS_DATA_STATUS_DP_SPEC_PIN_ASSIGNMENT(st->data_status)) { 545 + case TPS_DATA_STATUS_DP_SPEC_PIN_ASSIGNMENT_A: 546 + mode = TYPEC_DP_STATE_A; 547 + break; 548 + case TPS_DATA_STATUS_DP_SPEC_PIN_ASSIGNMENT_B: 549 + mode = TYPEC_DP_STATE_B; 550 + break; 551 + case TPS_DATA_STATUS_DP_SPEC_PIN_ASSIGNMENT_C: 552 + mode = TYPEC_DP_STATE_C; 553 + break; 554 + case TPS_DATA_STATUS_DP_SPEC_PIN_ASSIGNMENT_D: 555 + mode = TYPEC_DP_STATE_D; 556 + break; 557 + case TPS_DATA_STATUS_DP_SPEC_PIN_ASSIGNMENT_E: 558 + mode = TYPEC_DP_STATE_E; 559 + break; 560 + case TPS_DATA_STATUS_DP_SPEC_PIN_ASSIGNMENT_F: 561 + mode = TYPEC_DP_STATE_F; 562 + break; 563 + default: 564 + dev_err(tps->dev, "Invalid DP pin assignment\n"); 565 + return; 566 + } 567 + 568 + if (cd321x->state.alt == cd321x->port_altmode_dp && 569 + cd321x->state.mode == mode) { 570 + return; 571 + } 572 + 573 + dp_data.status = le32_to_cpu(st->dp_sid_status.status_rx); 574 + dp_data.conf = le32_to_cpu(st->dp_sid_status.configure); 575 + cd321x->state.alt = cd321x->port_altmode_dp; 576 + cd321x->state.data = &dp_data; 577 + cd321x->state.mode = mode; 578 + typec_mux_set(cd321x->mux, &cd321x->state); 579 + } else if (st->data_status & TPS_DATA_STATUS_TBT_CONNECTION) { 580 + struct typec_thunderbolt_data tbt_data; 581 + 582 + if (cd321x->state.alt == cd321x->port_altmode_tbt && 583 + cd321x->state.mode == TYPEC_TBT_MODE) 584 + return; 585 + 586 + tbt_data.cable_mode = le16_to_cpu(st->intel_vid_status.cable_mode); 587 + tbt_data.device_mode = le16_to_cpu(st->intel_vid_status.device_mode); 588 + tbt_data.enter_vdo = le16_to_cpu(st->intel_vid_status.enter_vdo); 589 + cd321x->state.alt = cd321x->port_altmode_tbt; 590 + cd321x->state.mode = TYPEC_TBT_MODE; 591 + cd321x->state.data = &tbt_data; 592 + typec_mux_set(cd321x->mux, &cd321x->state); 593 + } else if (st->data_status & CD321X_DATA_STATUS_USB4_CONNECTION) { 594 + struct enter_usb_data eusb_data; 595 + 596 + if (cd321x->state.alt == NULL && cd321x->state.mode == TYPEC_MODE_USB4) 597 + return; 598 + 599 + eusb_data.eudo = le32_to_cpu(st->usb4_status.eudo); 600 + eusb_data.active_link_training = 601 + !!(st->data_status & TPS_DATA_STATUS_ACTIVE_LINK_TRAIN); 602 + 603 + cd321x->state.alt = NULL; 604 + cd321x->state.data = &eusb_data; 605 + cd321x->state.mode = TYPEC_MODE_USB4; 606 + typec_mux_set(cd321x->mux, &cd321x->state); 607 + } else { 608 + if (cd321x->state.alt == NULL && cd321x->state.mode == TYPEC_STATE_USB) 609 + return; 610 + cd321x->state.alt = NULL; 611 + cd321x->state.mode = TYPEC_STATE_USB; 612 + cd321x->state.data = NULL; 613 + typec_mux_set(cd321x->mux, &cd321x->state); 614 + } 615 + 616 + /* Clear data since it's no longer used after typec_mux_set and points to the stack */ 617 + cd321x->state.data = NULL; 618 + } 619 + 620 + static void cd321x_update_work(struct work_struct *work) 621 + { 622 + struct cd321x *cd321x = container_of(to_delayed_work(work), 623 + struct cd321x, update_work); 624 + struct tps6598x *tps = &cd321x->tps; 625 + struct cd321x_status st; 626 + 627 + guard(mutex)(&tps->lock); 628 + 629 + st = cd321x->update_status; 630 + cd321x->update_status.status_changed = 0; 631 + 632 + bool old_connected = !!tps->partner; 633 + bool new_connected = st.status & TPS_STATUS_PLUG_PRESENT; 634 + bool was_disconnected = st.status_changed & TPS_STATUS_PLUG_PRESENT; 635 + 636 + bool usb_connection = st.data_status & 637 + (TPS_DATA_STATUS_USB2_CONNECTION | TPS_DATA_STATUS_USB3_CONNECTION); 638 + 639 + enum usb_role old_role = usb_role_switch_get_role(tps->role_sw); 640 + enum usb_role new_role = USB_ROLE_NONE; 641 + enum typec_pwr_opmode pwr_opmode = TYPEC_PWR_MODE_USB; 642 + enum typec_orientation orientation = TYPEC_ORIENTATION_NONE; 643 + 644 + if (usb_connection) { 645 + if (tps->data_status & TPS_DATA_STATUS_USB_DATA_ROLE) 646 + new_role = USB_ROLE_DEVICE; 647 + else 648 + new_role = USB_ROLE_HOST; 649 + } 650 + 651 + if (new_connected) { 652 + pwr_opmode = TPS_POWER_STATUS_PWROPMODE(st.pwr_status); 653 + orientation = TPS_STATUS_TO_UPSIDE_DOWN(st.status) ? 654 + TYPEC_ORIENTATION_REVERSE : TYPEC_ORIENTATION_NORMAL; 655 + } 656 + 657 + bool is_pd = pwr_opmode == TYPEC_PWR_MODE_PD; 658 + bool partner_changed = old_connected && new_connected && 659 + (was_disconnected || 660 + (is_pd && memcmp(&st.partner_identity, 661 + &cd321x->cur_partner_identity, sizeof(struct usb_pd_identity)))); 662 + 663 + /* If we are switching from an active role, transition to USB_ROLE_NONE first */ 664 + if (old_role != USB_ROLE_NONE && (new_role != old_role || was_disconnected)) 665 + usb_role_switch_set_role(tps->role_sw, USB_ROLE_NONE); 666 + 667 + /* Process partner disconnection or change */ 668 + if (!new_connected || partner_changed) { 669 + if (!IS_ERR(tps->partner)) 670 + typec_unregister_partner(tps->partner); 671 + tps->partner = NULL; 672 + } 673 + 674 + /* If there was a disconnection, set PHY to off */ 675 + if (!new_connected || was_disconnected) { 676 + cd321x->state.alt = NULL; 677 + cd321x->state.mode = TYPEC_STATE_SAFE; 678 + cd321x->state.data = NULL; 679 + typec_set_mode(tps->port, TYPEC_STATE_SAFE); 680 + } 681 + 682 + /* Update Type-C properties */ 683 + typec_set_pwr_opmode(tps->port, pwr_opmode); 684 + typec_set_pwr_role(tps->port, TPS_STATUS_TO_TYPEC_PORTROLE(st.status)); 685 + typec_set_vconn_role(tps->port, TPS_STATUS_TO_TYPEC_VCONN(st.status)); 686 + typec_set_orientation(tps->port, orientation); 687 + typec_set_data_role(tps->port, TPS_STATUS_TO_TYPEC_DATAROLE(st.status)); 688 + power_supply_changed(tps->psy); 689 + 690 + /* If the plug is disconnected, we are done */ 691 + if (!new_connected) 692 + return; 693 + 694 + /* Set up partner if we were previously disconnected (or changed). */ 695 + if (!tps->partner) { 696 + struct typec_partner_desc desc; 697 + 698 + desc.usb_pd = is_pd; 699 + desc.accessory = TYPEC_ACCESSORY_NONE; /* XXX: handle accessories */ 700 + desc.identity = NULL; 701 + 702 + if (desc.usb_pd) 703 + desc.identity = &st.partner_identity; 704 + 705 + tps->partner = typec_register_partner(tps->port, &desc); 706 + if (IS_ERR(tps->partner)) 707 + dev_warn(tps->dev, "%s: failed to register partnet\n", __func__); 708 + 709 + if (desc.identity) { 710 + typec_partner_set_identity(tps->partner); 711 + cd321x->cur_partner_identity = st.partner_identity; 712 + } 713 + } 714 + 715 + /* Update the TypeC MUX/PHY state */ 716 + cd321x_typec_update_mode(tps, &st); 717 + 718 + /* Launch the USB role switch */ 719 + usb_role_switch_set_role(tps->role_sw, new_role); 720 + 721 + power_supply_changed(tps->psy); 722 + } 723 + 724 + static void cd321x_queue_status(struct cd321x *cd321x) 725 + { 726 + cd321x->update_status.status_changed |= cd321x->update_status.status ^ cd321x->tps.status; 727 + 728 + cd321x->update_status.status = cd321x->tps.status; 729 + cd321x->update_status.pwr_status = cd321x->tps.pwr_status; 730 + cd321x->update_status.data_status = cd321x->tps.data_status; 731 + 732 + cd321x->update_status.partner_identity = cd321x->tps.partner_identity; 733 + cd321x->update_status.dp_sid_status = cd321x->dp_sid_status; 734 + cd321x->update_status.intel_vid_status = cd321x->intel_vid_status; 735 + cd321x->update_status.usb4_status = cd321x->usb4_status; 736 + } 737 + 738 + static int cd321x_connect(struct tps6598x *tps, u32 status) 739 + { 740 + struct cd321x *cd321x = container_of(tps, struct cd321x, tps); 741 + 742 + tps->status = status; 743 + cd321x_queue_status(cd321x); 744 + 745 + /* 746 + * Cancel pending work if not already running, then requeue after CD321X_DEBOUNCE_DELAY_MS 747 + * regardless since the work function will check for any plug or altmodes changes since 748 + * its last run anyway. 749 + */ 750 + cancel_delayed_work(&cd321x->update_work); 751 + schedule_delayed_work(&cd321x->update_work, msecs_to_jiffies(CD321X_DEBOUNCE_DELAY_MS)); 752 + 753 + return 0; 754 + } 755 + 640 756 static irqreturn_t cd321x_interrupt(int irq, void *data) 641 757 { 642 758 struct tps6598x *tps = data; ··· 883 545 if (!event) 884 546 goto err_unlock; 885 547 886 - if (!tps6598x_read_status(tps, &status)) 887 - goto err_clear_ints; 548 + tps6598x_write64(tps, TPS_REG_INT_CLEAR1, event); 888 549 889 - if (event & APPLE_CD_REG_INT_POWER_STATUS_UPDATE) 550 + if (!tps6598x_read_status(tps, &status)) 551 + goto err_unlock; 552 + 553 + if (event & APPLE_CD_REG_INT_POWER_STATUS_UPDATE) { 890 554 if (!tps6598x_read_power_status(tps)) 891 - goto err_clear_ints; 555 + goto err_unlock; 556 + if (TPS_POWER_STATUS_PWROPMODE(tps->pwr_status) == TYPEC_PWR_MODE_PD) { 557 + if (tps6598x_read_partner_identity(tps)) { 558 + dev_err(tps->dev, "failed to read partner identity\n"); 559 + tps->partner_identity = (struct usb_pd_identity) {0}; 560 + } 561 + } 562 + } 892 563 893 564 if (event & APPLE_CD_REG_INT_DATA_STATUS_UPDATE) 894 - if (!tps6598x_read_data_status(tps)) 895 - goto err_clear_ints; 565 + if (!tps->data->read_data_status(tps)) 566 + goto err_unlock; 896 567 897 - /* Handle plug insert or removal */ 898 - if (event & APPLE_CD_REG_INT_PLUG_EVENT) 899 - tps6598x_handle_plug_event(tps, status); 900 - 901 - err_clear_ints: 902 - tps6598x_write64(tps, TPS_REG_INT_CLEAR1, event); 568 + /* Can be called uncondtionally since it will check for any changes itself */ 569 + cd321x_connect(tps, status); 903 570 904 571 err_unlock: 905 572 mutex_unlock(&tps->lock); ··· 948 605 goto err_clear_ints; 949 606 950 607 if (event[0] & TPS_REG_INT_DATA_STATUS_UPDATE) 951 - if (!tps6598x_read_data_status(tps)) 608 + if (!tps->data->read_data_status(tps)) 952 609 goto err_clear_ints; 953 610 954 611 /* ··· 1011 668 if (!(event1[0] | event1[1] | event2[0] | event2[1])) 1012 669 goto err_unlock; 1013 670 671 + tps6598x_block_write(tps, TPS_REG_INT_CLEAR1, event1, intev_len); 672 + tps6598x_block_write(tps, TPS_REG_INT_CLEAR2, event2, intev_len); 673 + 1014 674 if (!tps6598x_read_status(tps, &status)) 1015 - goto err_clear_ints; 675 + goto err_unlock; 1016 676 1017 677 if ((event1[0] | event2[0]) & TPS_REG_INT_POWER_STATUS_UPDATE) 1018 678 if (!tps6598x_read_power_status(tps)) 1019 - goto err_clear_ints; 679 + goto err_unlock; 1020 680 1021 681 if ((event1[0] | event2[0]) & TPS_REG_INT_DATA_STATUS_UPDATE) 1022 - if (!tps6598x_read_data_status(tps)) 1023 - goto err_clear_ints; 682 + if (!tps->data->read_data_status(tps)) 683 + goto err_unlock; 1024 684 1025 685 /* Handle plug insert or removal */ 1026 686 if ((event1[0] | event2[0]) & TPS_REG_INT_PLUG_EVENT) 1027 687 tps6598x_handle_plug_event(tps, status); 1028 - 1029 - err_clear_ints: 1030 - tps6598x_block_write(tps, TPS_REG_INT_CLEAR1, event1, intev_len); 1031 - tps6598x_block_write(tps, TPS_REG_INT_CLEAR2, event2, intev_len); 1032 688 1033 689 err_unlock: 1034 690 mutex_unlock(&tps->lock); ··· 1227 885 return PTR_ERR(tps->port); 1228 886 1229 887 return 0; 888 + } 889 + 890 + static int cd321x_register_port_altmodes(struct cd321x *cd321x) 891 + { 892 + struct typec_altmode_desc desc; 893 + struct typec_altmode *amode; 894 + 895 + memset(&desc, 0, sizeof(desc)); 896 + desc.svid = USB_TYPEC_DP_SID; 897 + desc.mode = USB_TYPEC_DP_MODE; 898 + desc.vdo = DP_CONF_SET_PIN_ASSIGN(BIT(DP_PIN_ASSIGN_C) | BIT(DP_PIN_ASSIGN_D)); 899 + desc.vdo |= DP_CAP_DFP_D; 900 + amode = typec_port_register_altmode(cd321x->tps.port, &desc); 901 + if (IS_ERR(amode)) 902 + return PTR_ERR(amode); 903 + cd321x->port_altmode_dp = amode; 904 + 905 + memset(&desc, 0, sizeof(desc)); 906 + desc.svid = USB_TYPEC_TBT_SID; 907 + desc.mode = TYPEC_ANY_MODE; 908 + amode = typec_port_register_altmode(cd321x->tps.port, &desc); 909 + if (IS_ERR(amode)) { 910 + typec_unregister_altmode(cd321x->port_altmode_dp); 911 + cd321x->port_altmode_dp = NULL; 912 + return PTR_ERR(amode); 913 + } 914 + cd321x->port_altmode_tbt = amode; 915 + 916 + return 0; 917 + } 918 + 919 + static int 920 + cd321x_register_port(struct tps6598x *tps, struct fwnode_handle *fwnode) 921 + { 922 + struct cd321x *cd321x = container_of(tps, struct cd321x, tps); 923 + int ret; 924 + 925 + INIT_DELAYED_WORK(&cd321x->update_work, cd321x_update_work); 926 + 927 + ret = tps6598x_register_port(tps, fwnode); 928 + if (ret) 929 + return ret; 930 + 931 + ret = cd321x_register_port_altmodes(cd321x); 932 + if (ret) 933 + goto err_unregister_port; 934 + 935 + cd321x->mux = fwnode_typec_mux_get(fwnode); 936 + if (IS_ERR(cd321x->mux)) { 937 + ret = PTR_ERR(cd321x->mux); 938 + goto err_unregister_altmodes; 939 + } 940 + 941 + cd321x->state.alt = NULL; 942 + cd321x->state.mode = TYPEC_STATE_SAFE; 943 + cd321x->state.data = NULL; 944 + typec_set_mode(tps->port, TYPEC_STATE_SAFE); 945 + 946 + return 0; 947 + 948 + err_unregister_altmodes: 949 + typec_unregister_altmode(cd321x->port_altmode_dp); 950 + typec_unregister_altmode(cd321x->port_altmode_tbt); 951 + cd321x->port_altmode_dp = NULL; 952 + cd321x->port_altmode_tbt = NULL; 953 + err_unregister_port: 954 + typec_unregister_port(tps->port); 955 + return ret; 956 + } 957 + 958 + static void 959 + tps6598x_unregister_port(struct tps6598x *tps) 960 + { 961 + typec_unregister_port(tps->port); 962 + } 963 + 964 + static void 965 + cd321x_unregister_port(struct tps6598x *tps) 966 + { 967 + struct cd321x *cd321x = container_of(tps, struct cd321x, tps); 968 + 969 + typec_mux_put(cd321x->mux); 970 + cd321x->mux = NULL; 971 + typec_unregister_altmode(cd321x->port_altmode_dp); 972 + cd321x->port_altmode_dp = NULL; 973 + typec_unregister_altmode(cd321x->port_altmode_tbt); 974 + cd321x->port_altmode_tbt = NULL; 975 + typec_unregister_port(tps->port); 1230 976 } 1231 977 1232 978 static int tps_request_firmware(struct tps6598x *tps, const struct firmware **fw, ··· 1722 1292 return 0; 1723 1293 } 1724 1294 1295 + static void cd321x_remove(struct tps6598x *tps) 1296 + { 1297 + struct cd321x *cd321x = container_of(tps, struct cd321x, tps); 1298 + 1299 + cancel_delayed_work_sync(&cd321x->update_work); 1300 + } 1301 + 1725 1302 static int tps6598x_probe(struct i2c_client *client) 1726 1303 { 1727 - struct device_node *np = client->dev.of_node; 1304 + const struct tipd_data *data; 1728 1305 struct tps6598x *tps; 1729 1306 struct fwnode_handle *fwnode; 1730 1307 u32 status; 1731 1308 u32 vid; 1732 1309 int ret; 1733 - u64 mask1; 1734 1310 1735 - tps = devm_kzalloc(&client->dev, sizeof(*tps), GFP_KERNEL); 1311 + data = i2c_get_match_data(client); 1312 + if (!data) 1313 + return -EINVAL; 1314 + 1315 + tps = devm_kzalloc(&client->dev, data->tps_struct_size, GFP_KERNEL); 1736 1316 if (!tps) 1737 1317 return -ENOMEM; 1738 1318 1739 1319 mutex_init(&tps->lock); 1740 1320 tps->dev = &client->dev; 1321 + tps->data = data; 1741 1322 1742 1323 tps->reset = devm_gpiod_get_optional(tps->dev, "reset", GPIOD_OUT_LOW); 1743 1324 if (IS_ERR(tps->reset)) ··· 1774 1333 if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) 1775 1334 tps->i2c_protocol = true; 1776 1335 1777 - if (np && of_device_is_compatible(np, "apple,cd321x")) { 1778 - /* Switch CD321X chips to the correct system power state */ 1779 - ret = cd321x_switch_power_state(tps, TPS_SYSTEM_POWER_STATE_S0); 1336 + if (tps->data->switch_power_state) { 1337 + ret = tps->data->switch_power_state(tps, TPS_SYSTEM_POWER_STATE_S0); 1780 1338 if (ret) 1781 1339 return ret; 1782 - 1783 - /* CD321X chips have all interrupts masked initially */ 1784 - mask1 = APPLE_CD_REG_INT_POWER_STATUS_UPDATE | 1785 - APPLE_CD_REG_INT_DATA_STATUS_UPDATE | 1786 - APPLE_CD_REG_INT_PLUG_EVENT; 1787 - 1788 - } else { 1789 - /* Enable power status, data status and plug event interrupts */ 1790 - mask1 = TPS_REG_INT_POWER_STATUS_UPDATE | 1791 - TPS_REG_INT_DATA_STATUS_UPDATE | 1792 - TPS_REG_INT_PLUG_EVENT; 1793 1340 } 1794 - 1795 - tps->data = i2c_get_match_data(client); 1796 - if (!tps->data) 1797 - return -EINVAL; 1798 1341 1799 1342 /* Make sure the controller has application firmware running */ 1800 1343 ret = tps6598x_check_mode(tps); ··· 1791 1366 return ret; 1792 1367 } 1793 1368 1794 - ret = tps6598x_write64(tps, TPS_REG_INT_MASK1, mask1); 1369 + ret = tps6598x_write64(tps, TPS_REG_INT_MASK1, tps->data->irq_mask1); 1795 1370 if (ret) 1796 1371 goto err_reset_controller; 1797 1372 ··· 1826 1401 goto err_role_put; 1827 1402 1828 1403 if (status & TPS_STATUS_PLUG_PRESENT) { 1829 - ret = tps6598x_read16(tps, TPS_REG_POWER_STATUS, &tps->pwr_status); 1830 - if (ret < 0) { 1831 - dev_err(tps->dev, "failed to read power status: %d\n", ret); 1404 + if (!tps6598x_read_power_status(tps)) 1832 1405 goto err_unregister_port; 1833 - } 1834 - ret = tps6598x_connect(tps, status); 1406 + if (!tps->data->read_data_status(tps)) 1407 + goto err_unregister_port; 1408 + ret = tps->data->connect(tps, status); 1835 1409 if (ret) 1836 1410 dev_err(&client->dev, "failed to register partner\n"); 1837 1411 } ··· 1864 1440 err_disconnect: 1865 1441 tps6598x_disconnect(tps, 0); 1866 1442 err_unregister_port: 1867 - typec_unregister_port(tps->port); 1443 + tps->data->unregister_port(tps); 1868 1444 err_role_put: 1869 1445 usb_role_switch_put(tps->role_sw); 1870 1446 err_fwnode_put: ··· 1887 1463 else 1888 1464 devm_free_irq(tps->dev, client->irq, tps); 1889 1465 1466 + if (tps->data->remove) 1467 + tps->data->remove(tps); 1468 + 1890 1469 tps6598x_disconnect(tps, 0); 1891 - typec_unregister_port(tps->port); 1470 + tps->data->unregister_port(tps); 1892 1471 usb_role_switch_put(tps->role_sw); 1893 1472 1894 1473 /* Reset PD controller to remove any applied patch */ ··· 1956 1529 1957 1530 static const struct tipd_data cd321x_data = { 1958 1531 .irq_handler = cd321x_interrupt, 1959 - .register_port = tps6598x_register_port, 1532 + .irq_mask1 = APPLE_CD_REG_INT_POWER_STATUS_UPDATE | 1533 + APPLE_CD_REG_INT_DATA_STATUS_UPDATE | 1534 + APPLE_CD_REG_INT_PLUG_EVENT, 1535 + .tps_struct_size = sizeof(struct cd321x), 1536 + .remove = cd321x_remove, 1537 + .register_port = cd321x_register_port, 1538 + .unregister_port = cd321x_unregister_port, 1539 + .trace_data_status = trace_cd321x_data_status, 1960 1540 .trace_power_status = trace_tps6598x_power_status, 1961 1541 .trace_status = trace_tps6598x_status, 1962 1542 .init = cd321x_init, 1543 + .read_data_status = cd321x_read_data_status, 1963 1544 .reset = cd321x_reset, 1545 + .switch_power_state = cd321x_switch_power_state, 1546 + .connect = cd321x_connect, 1964 1547 }; 1965 1548 1966 1549 static const struct tipd_data tps6598x_data = { 1967 1550 .irq_handler = tps6598x_interrupt, 1551 + .irq_mask1 = TPS_REG_INT_POWER_STATUS_UPDATE | 1552 + TPS_REG_INT_DATA_STATUS_UPDATE | 1553 + TPS_REG_INT_PLUG_EVENT, 1554 + .tps_struct_size = sizeof(struct tps6598x), 1968 1555 .register_port = tps6598x_register_port, 1556 + .unregister_port = tps6598x_unregister_port, 1557 + .trace_data_status = trace_tps6598x_data_status, 1969 1558 .trace_power_status = trace_tps6598x_power_status, 1970 1559 .trace_status = trace_tps6598x_status, 1971 1560 .apply_patch = tps6598x_apply_patch, 1972 1561 .init = tps6598x_init, 1562 + .read_data_status = tps6598x_read_data_status, 1973 1563 .reset = tps6598x_reset, 1564 + .connect = tps6598x_connect, 1974 1565 }; 1975 1566 1976 1567 static const struct tipd_data tps25750_data = { 1977 1568 .irq_handler = tps25750_interrupt, 1569 + .irq_mask1 = TPS_REG_INT_POWER_STATUS_UPDATE | 1570 + TPS_REG_INT_DATA_STATUS_UPDATE | 1571 + TPS_REG_INT_PLUG_EVENT, 1572 + .tps_struct_size = sizeof(struct tps6598x), 1978 1573 .register_port = tps25750_register_port, 1574 + .unregister_port = tps6598x_unregister_port, 1575 + .trace_data_status = trace_tps6598x_data_status, 1979 1576 .trace_power_status = trace_tps25750_power_status, 1980 1577 .trace_status = trace_tps25750_status, 1981 1578 .apply_patch = tps25750_apply_patch, 1982 1579 .init = tps25750_init, 1580 + .read_data_status = tps6598x_read_data_status, 1983 1581 .reset = tps25750_reset, 1582 + .connect = tps6598x_connect, 1984 1583 }; 1985 1584 1986 1585 static const struct of_device_id tps6598x_of_match[] = {
+5
drivers/usb/typec/tipd/tps6598x.h
··· 197 197 #define TPS_DATA_STATUS_FORCE_LSX BIT(23) 198 198 #define TPS_DATA_STATUS_POWER_MISMATCH BIT(24) 199 199 200 + /* modified TPS_REG_DATA_STATUS bits for CD321x (and likely also TPS65987DDK) */ 201 + #define CD321X_DATA_STATUS_HPD_IRQ BIT(14) 202 + #define CD321X_DATA_STATUS_HPD_LEVEL BIT(15) 203 + #define CD321X_DATA_STATUS_USB4_CONNECTION BIT(23) 204 + 200 205 #define TPS_DATA_STATUS_DP_PIN_ASSIGNMENT_MASK GENMASK(11, 10) 201 206 #define TPS_DATA_STATUS_DP_PIN_ASSIGNMENT(x) \ 202 207 TPS_FIELD_GET(TPS_DATA_STATUS_DP_PIN_ASSIGNMENT_MASK, (x))
+39
drivers/usb/typec/tipd/trace.h
··· 217 217 { TPS_DATA_STATUS_FORCE_LSX, "FORCE_LSX" }, \ 218 218 { TPS_DATA_STATUS_POWER_MISMATCH, "POWER_MISMATCH" }) 219 219 220 + #define show_cd321x_data_status_flags(data_status) \ 221 + __print_flags(data_status & TPS_DATA_STATUS_FLAGS_MASK, "|", \ 222 + { TPS_DATA_STATUS_DATA_CONNECTION, "DATA_CONNECTION" }, \ 223 + { TPS_DATA_STATUS_UPSIDE_DOWN, "DATA_UPSIDE_DOWN" }, \ 224 + { TPS_DATA_STATUS_ACTIVE_CABLE, "ACTIVE_CABLE" }, \ 225 + { TPS_DATA_STATUS_USB2_CONNECTION, "USB2_CONNECTION" }, \ 226 + { TPS_DATA_STATUS_USB3_CONNECTION, "USB3_CONNECTION" }, \ 227 + { TPS_DATA_STATUS_USB3_GEN2, "USB3_GEN2" }, \ 228 + { TPS_DATA_STATUS_USB_DATA_ROLE, "USB_DATA_ROLE" }, \ 229 + { TPS_DATA_STATUS_DP_CONNECTION, "DP_CONNECTION" }, \ 230 + { TPS_DATA_STATUS_DP_SINK, "DP_SINK" }, \ 231 + { CD321X_DATA_STATUS_HPD_IRQ, "HPD_IRQ" }, \ 232 + { CD321X_DATA_STATUS_HPD_LEVEL, "HPD_LEVEL" }, \ 233 + { TPS_DATA_STATUS_TBT_CONNECTION, "TBT_CONNECTION" }, \ 234 + { TPS_DATA_STATUS_TBT_TYPE, "TBT_TYPE" }, \ 235 + { TPS_DATA_STATUS_OPTICAL_CABLE, "OPTICAL_CABLE" }, \ 236 + { TPS_DATA_STATUS_ACTIVE_LINK_TRAIN, "ACTIVE_LINK_TRAIN" }, \ 237 + { CD321X_DATA_STATUS_USB4_CONNECTION, "USB4" }, \ 238 + { TPS_DATA_STATUS_POWER_MISMATCH, "POWER_MISMATCH" }) 239 + 220 240 #define show_data_status_dp_pin_assignment(data_status) \ 221 241 __print_symbolic(TPS_DATA_STATUS_DP_SPEC_PIN_ASSIGNMENT(data_status), \ 222 242 { TPS_DATA_STATUS_DP_SPEC_PIN_ASSIGNMENT_E, "E" }, \ ··· 406 386 __entry->data_status & TPS_DATA_STATUS_DP_CONNECTION ? ", DP pinout " : "", 407 387 maybe_show_data_status_dp_pin_assignment(__entry->data_status) 408 388 ) 389 + ); 390 + 391 + TRACE_EVENT(cd321x_data_status, 392 + TP_PROTO(u32 data_status), 393 + TP_ARGS(data_status), 394 + 395 + TP_STRUCT__entry( 396 + __field(u32, data_status) 397 + ), 398 + 399 + TP_fast_assign( 400 + __entry->data_status = data_status; 401 + ), 402 + 403 + TP_printk("%s%s%s", 404 + show_cd321x_data_status_flags(__entry->data_status), 405 + __entry->data_status & TPS_DATA_STATUS_DP_CONNECTION ? ", DP pinout " : "", 406 + maybe_show_data_status_dp_pin_assignment(__entry->data_status) 407 + ) 409 408 ); 410 409 411 410 #endif /* _TPS6598X_TRACE_H_ */
+31
drivers/usb/typec/ucsi/debugfs.c
··· 35 35 case UCSI_SET_SINK_PATH: 36 36 case UCSI_SET_NEW_CAM: 37 37 case UCSI_SET_USB: 38 + case UCSI_READ_POWER_LEVEL: 38 39 ret = ucsi_send_command(ucsi, val, NULL, 0); 39 40 break; 40 41 case UCSI_GET_CAPABILITY: ··· 81 80 } 82 81 DEFINE_SHOW_ATTRIBUTE(ucsi_resp); 83 82 83 + static int ucsi_peak_curr_show(struct seq_file *m, void *v) 84 + { 85 + struct ucsi *ucsi = m->private; 86 + 87 + seq_printf(m, "%u mA\n", ucsi->connector->peak_current); 88 + return 0; 89 + } 90 + DEFINE_SHOW_ATTRIBUTE(ucsi_peak_curr); 91 + 92 + static int ucsi_avg_curr_show(struct seq_file *m, void *v) 93 + { 94 + struct ucsi *ucsi = m->private; 95 + 96 + seq_printf(m, "%u mA\n", ucsi->connector->avg_current); 97 + return 0; 98 + } 99 + DEFINE_SHOW_ATTRIBUTE(ucsi_avg_curr); 100 + 101 + static int ucsi_vbus_volt_show(struct seq_file *m, void *v) 102 + { 103 + struct ucsi *ucsi = m->private; 104 + 105 + seq_printf(m, "%u mV\n", ucsi->connector->vbus_voltage); 106 + return 0; 107 + } 108 + DEFINE_SHOW_ATTRIBUTE(ucsi_vbus_volt); 109 + 84 110 void ucsi_debugfs_register(struct ucsi *ucsi) 85 111 { 86 112 ucsi->debugfs = kzalloc(sizeof(*ucsi->debugfs), GFP_KERNEL); ··· 117 89 ucsi->debugfs->dentry = debugfs_create_dir(dev_name(ucsi->dev), ucsi_debugfs_root); 118 90 debugfs_create_file("command", 0200, ucsi->debugfs->dentry, ucsi, &ucsi_cmd_fops); 119 91 debugfs_create_file("response", 0400, ucsi->debugfs->dentry, ucsi, &ucsi_resp_fops); 92 + debugfs_create_file("peak_current", 0400, ucsi->debugfs->dentry, ucsi, &ucsi_peak_curr_fops); 93 + debugfs_create_file("avg_current", 0400, ucsi->debugfs->dentry, ucsi, &ucsi_avg_curr_fops); 94 + debugfs_create_file("vbus_voltage", 0400, ucsi->debugfs->dentry, ucsi, &ucsi_vbus_volt_fops); 120 95 } 121 96 122 97 void ucsi_debugfs_unregister(struct ucsi *ucsi)
+17
drivers/usb/typec/ucsi/ucsi.c
··· 1217 1217 struct ucsi_connector *con = container_of(work, struct ucsi_connector, 1218 1218 work); 1219 1219 struct ucsi *ucsi = con->ucsi; 1220 + u8 curr_scale, volt_scale; 1220 1221 enum typec_role role; 1221 1222 u16 change; 1222 1223 int ret; 1224 + u32 val; 1223 1225 1224 1226 mutex_lock(&con->lock); 1225 1227 ··· 1292 1290 1293 1291 if (change & UCSI_CONSTAT_BC_CHANGE) 1294 1292 ucsi_port_psy_changed(con); 1293 + 1294 + if (con->ucsi->version >= UCSI_VERSION_2_1 && 1295 + UCSI_CONSTAT(con, PWR_READING_READY_V2_1)) { 1296 + curr_scale = UCSI_CONSTAT(con, CURRENT_SCALE_V2_1); 1297 + volt_scale = UCSI_CONSTAT(con, VOLTAGE_SCALE_V2_1); 1298 + 1299 + val = UCSI_CONSTAT(con, PEAK_CURRENT_V2_1); 1300 + con->peak_current = UCSI_CONSTAT_CURR_SCALE_MULT * curr_scale * val; 1301 + 1302 + val = UCSI_CONSTAT(con, AVG_CURRENT_V2_1); 1303 + con->avg_current = UCSI_CONSTAT_CURR_SCALE_MULT * curr_scale * val; 1304 + 1305 + val = UCSI_CONSTAT(con, VBUS_VOLTAGE_V2_1); 1306 + con->vbus_voltage = UCSI_CONSTAT_VOLT_SCALE_MULT * volt_scale * val; 1307 + } 1295 1308 1296 1309 out_unlock: 1297 1310 mutex_unlock(&con->lock);
+13
drivers/usb/typec/ucsi/ucsi.h
··· 131 131 #define UCSI_GET_PD_MESSAGE 0x15 132 132 #define UCSI_GET_CAM_CS 0x18 133 133 #define UCSI_SET_SINK_PATH 0x1c 134 + #define UCSI_READ_POWER_LEVEL 0x1e 134 135 #define UCSI_SET_USB 0x21 135 136 #define UCSI_GET_LPM_PPM_INFO 0x22 136 137 ··· 360 359 #define UCSI_CONSTAT_BC_SLOW_CHARGING 2 361 360 #define UCSI_CONSTAT_BC_TRICKLE_CHARGING 3 362 361 #define UCSI_CONSTAT_PD_VERSION_V1_2 UCSI_DECLARE_BITFIELD_V1_2(70, 16) 362 + #define UCSI_CONSTAT_PWR_READING_READY_V2_1 UCSI_DECLARE_BITFIELD_V2_1(89, 1) 363 + #define UCSI_CONSTAT_CURRENT_SCALE_V2_1 UCSI_DECLARE_BITFIELD_V2_1(90, 3) 364 + #define UCSI_CONSTAT_PEAK_CURRENT_V2_1 UCSI_DECLARE_BITFIELD_V2_1(93, 16) 365 + #define UCSI_CONSTAT_AVG_CURRENT_V2_1 UCSI_DECLARE_BITFIELD_V2_1(109, 16) 366 + #define UCSI_CONSTAT_VOLTAGE_SCALE_V2_1 UCSI_DECLARE_BITFIELD_V2_1(125, 4) 367 + #define UCSI_CONSTAT_VBUS_VOLTAGE_V2_1 UCSI_DECLARE_BITFIELD_V2_1(129, 16) 368 + #define UCSI_CONSTAT_CURR_SCALE_MULT 5 369 + #define UCSI_CONSTAT_VOLT_SCALE_MULT 5 363 370 364 371 /* Connector Status Change Bits. */ 365 372 #define UCSI_CONSTAT_EXT_SUPPLY_CHANGE BIT(1) ··· 527 518 u32 rdo; 528 519 u32 src_pdos[PDO_MAX_OBJECTS]; 529 520 int num_pdos; 521 + 522 + u32 peak_current; 523 + u32 avg_current; 524 + u32 vbus_voltage; 530 525 531 526 /* USB PD objects */ 532 527 struct usb_power_delivery *pd;
+2 -5
drivers/usb/typec/ucsi/ucsi_stm32g0.c
··· 10 10 #include <linux/firmware.h> 11 11 #include <linux/i2c.h> 12 12 #include <linux/interrupt.h> 13 + #include <linux/minmax.h> 13 14 #include <linux/module.h> 14 15 #include <linux/platform_device.h> 15 16 #include <linux/unaligned.h> ··· 524 523 data = fw->data; 525 524 end = fw->data + fw->size; 526 525 while (data < end) { 527 - if ((end - data) < STM32G0_I2C_BL_SZ) 528 - size = end - data; 529 - else 530 - size = STM32G0_I2C_BL_SZ; 531 - 526 + size = min(end - data, STM32G0_I2C_BL_SZ); 532 527 ret = ucsi_stm32g0_bl_write(g0->ucsi, addr, data, size); 533 528 if (ret) { 534 529 dev_err(g0->dev, "Write failed %d\n", ret);
+22
drivers/usb/usbip/vhci_hcd.c
··· 765 765 ctrlreq->wValue, vdev->rhport); 766 766 767 767 vdev->udev = usb_get_dev(urb->dev); 768 + /* 769 + * NOTE: A similar operation has been done via 770 + * USB_REQ_GET_DESCRIPTOR handler below, which is 771 + * supposed to always precede USB_REQ_SET_ADDRESS. 772 + * 773 + * It's not entirely clear if operating on a different 774 + * usb_device instance here is a real possibility, 775 + * otherwise this call and vdev->udev assignment above 776 + * should be dropped. 777 + */ 778 + dev_pm_syscore_device(&vdev->udev->dev, true); 768 779 usb_put_dev(old); 769 780 770 781 spin_lock(&vdev->ud.lock); ··· 796 785 "Not yet?:Get_Descriptor to device 0 (get max pipe size)\n"); 797 786 798 787 vdev->udev = usb_get_dev(urb->dev); 788 + /* 789 + * Set syscore PM flag for the virtually attached 790 + * devices to ensure they will not enter suspend on 791 + * the client side. 792 + * 793 + * Note this doesn't have any impact on the physical 794 + * devices attached to the host system on the server 795 + * side, hence there is no need to undo the operation 796 + * on disconnect. 797 + */ 798 + dev_pm_syscore_device(&vdev->udev->dev, true); 799 799 usb_put_dev(old); 800 800 goto out; 801 801
+14 -11
include/linux/thunderbolt.h
··· 213 213 * queried first 214 214 * @service_ids: Used to generate IDs for the services 215 215 * @in_hopids: Input HopIDs for DMA tunneling 216 - * @out_hopids; Output HopIDs for DMA tunneling 216 + * @out_hopids: Output HopIDs for DMA tunneling 217 217 * @local_property_block: Local block of properties 218 218 * @local_property_block_gen: Generation of @local_property_block 219 219 * @local_property_block_len: Length of the @local_property_block in dwords ··· 356 356 unsigned int timeout_msec); 357 357 358 358 /** 359 - * tb_protocol_handler - Protocol specific handler 359 + * struct tb_protocol_handler - Protocol specific handler 360 360 * @uuid: XDomain messages with this UUID are dispatched to this handler 361 361 * @callback: Callback called with the XDomain message. Returning %1 362 362 * here tells the XDomain core that the message was handled ··· 437 437 } 438 438 439 439 /** 440 - * tb_service_driver - Thunderbolt service driver 440 + * struct tb_service_driver - Thunderbolt service driver 441 441 * @driver: Driver structure 442 442 * @probe: Called when the driver is probed 443 443 * @remove: Called when the driver is removed (optional) ··· 519 519 * @head: Head of the ring (write next descriptor here) 520 520 * @tail: Tail of the ring (complete next descriptor here) 521 521 * @descriptors: Allocated descriptors for this ring 522 + * @descriptors_dma: DMA address of descriptors for this ring 522 523 * @queue: Queue holding frames to be transferred over this ring 523 524 * @in_flight: Queue holding frames that are currently in flight 524 525 * @work: Interrupt work structure ··· 572 571 573 572 /** 574 573 * enum ring_desc_flags - Flags for DMA ring descriptor 575 - * %RING_DESC_ISOCH: Enable isonchronous DMA (Tx only) 576 - * %RING_DESC_CRC_ERROR: In frame mode CRC check failed for the frame (Rx only) 577 - * %RING_DESC_COMPLETED: Descriptor completed (set by NHI) 578 - * %RING_DESC_POSTED: Always set this 579 - * %RING_DESC_BUFFER_OVERRUN: RX buffer overrun 580 - * %RING_DESC_INTERRUPT: Request an interrupt on completion 574 + * @RING_DESC_ISOCH: Enable isonchronous DMA (Tx only) 575 + * @RING_DESC_CRC_ERROR: In frame mode CRC check failed for the frame (Rx only) 576 + * @RING_DESC_COMPLETED: Descriptor completed (set by NHI) 577 + * @RING_DESC_POSTED: Always set this 578 + * @RING_DESC_BUFFER_OVERRUN: RX buffer overrun 579 + * @RING_DESC_INTERRUPT: Request an interrupt on completion 581 580 */ 582 581 enum ring_desc_flags { 583 582 RING_DESC_ISOCH = 0x1, ··· 637 636 * If ring_stop() is called after the packet has been enqueued 638 637 * @frame->callback will be called with canceled set to true. 639 638 * 640 - * Return: Returns %-ESHUTDOWN if ring_stop has been called. Zero otherwise. 639 + * Return: %-ESHUTDOWN if ring_stop() has been called, %0 otherwise. 641 640 */ 642 641 static inline int tb_ring_rx(struct tb_ring *ring, struct ring_frame *frame) 643 642 { ··· 658 657 * If ring_stop() is called after the packet has been enqueued @frame->callback 659 658 * will be called with canceled set to true. 660 659 * 661 - * Return: Returns %-ESHUTDOWN if ring_stop has been called. Zero otherwise. 660 + * Return: %-ESHUTDOWN if ring_stop has been called, %0 otherwise. 662 661 */ 663 662 static inline int tb_ring_tx(struct tb_ring *ring, struct ring_frame *frame) 664 663 { ··· 676 675 * 677 676 * Use this function when you are mapping DMA for buffers that are 678 677 * passed to the ring for sending/receiving. 678 + * 679 + * Return: Pointer to device used for DMA mapping. 679 680 */ 680 681 static inline struct device *tb_ring_dma_device(struct tb_ring *ring) 681 682 {
+24
include/linux/usb.h
··· 636 636 * @do_remote_wakeup: remote wakeup should be enabled 637 637 * @reset_resume: needs reset instead of resume 638 638 * @port_is_suspended: the upstream port is suspended (L2 or U3) 639 + * @offload_at_suspend: offload activities during suspend is enabled. 640 + * @offload_usage: number of offload activities happening on this usb device. 639 641 * @slot_id: Slot ID assigned by xHCI 640 642 * @l1_params: best effor service latency for USB2 L1 LPM state, and L1 timeout. 641 643 * @u1_params: exit latencies for USB3 U1 LPM state, and hub-initiated timeout. ··· 726 724 unsigned do_remote_wakeup:1; 727 725 unsigned reset_resume:1; 728 726 unsigned port_is_suspended:1; 727 + unsigned offload_at_suspend:1; 728 + int offload_usage; 729 729 enum usb_link_tunnel_mode tunnel_mode; 730 730 struct device_link *usb4_link; 731 731 ··· 843 839 { } 844 840 static inline void usb_mark_last_busy(struct usb_device *udev) 845 841 { } 842 + #endif 843 + 844 + #if IS_ENABLED(CONFIG_USB_XHCI_SIDEBAND) 845 + int usb_offload_get(struct usb_device *udev); 846 + int usb_offload_put(struct usb_device *udev); 847 + bool usb_offload_check(struct usb_device *udev); 848 + #else 849 + 850 + static inline int usb_offload_get(struct usb_device *udev) 851 + { return 0; } 852 + static inline int usb_offload_put(struct usb_device *udev) 853 + { return 0; } 854 + static inline bool usb_offload_check(struct usb_device *udev) 855 + { return false; } 846 856 #endif 847 857 848 858 extern int usb_disable_lpm(struct usb_device *udev); ··· 2056 2038 /* NOTE: only 0x07ff bits are for packet size... */ 2057 2039 return usb_endpoint_maxp(&ep->desc); 2058 2040 } 2041 + 2042 + u32 usb_endpoint_max_periodic_payload(struct usb_device *udev, 2043 + const struct usb_host_endpoint *ep); 2044 + 2045 + bool usb_endpoint_is_hs_isoc_double(struct usb_device *udev, 2046 + const struct usb_host_endpoint *ep); 2059 2047 2060 2048 /* translate USB error codes to codes user space understands */ 2061 2049 static inline int usb_translate_errors(int error_code)
+25
include/linux/usb/gadget.h
··· 15 15 #ifndef __LINUX_USB_GADGET_H 16 16 #define __LINUX_USB_GADGET_H 17 17 18 + #include <linux/cleanup.h> 18 19 #include <linux/configfs.h> 19 20 #include <linux/device.h> 20 21 #include <linux/errno.h> ··· 33 32 34 33 /** 35 34 * struct usb_request - describes one i/o request 35 + * @ep: The associated endpoint set by usb_ep_alloc_request(). 36 36 * @buf: Buffer used for data. Always provide this; some controllers 37 37 * only use PIO, or don't use DMA for some endpoints. 38 38 * @dma: DMA address corresponding to 'buf'. If you don't set this ··· 100 98 */ 101 99 102 100 struct usb_request { 101 + struct usb_ep *ep; 103 102 void *buf; 104 103 unsigned length; 105 104 dma_addr_t dma; ··· 291 288 static inline void usb_ep_fifo_flush(struct usb_ep *ep) 292 289 { } 293 290 #endif /* USB_GADGET */ 291 + 292 + /*-------------------------------------------------------------------------*/ 293 + 294 + /** 295 + * free_usb_request - frees a usb_request object and its buffer 296 + * @req: the request being freed 297 + * 298 + * This helper function frees both the request's buffer and the request object 299 + * itself by calling usb_ep_free_request(). Its signature is designed to be used 300 + * with DEFINE_FREE() to enable automatic, scope-based cleanup for usb_request 301 + * pointers. 302 + */ 303 + static inline void free_usb_request(struct usb_request *req) 304 + { 305 + if (!req) 306 + return; 307 + 308 + kfree(req->buf); 309 + usb_ep_free_request(req->ep, req); 310 + } 311 + 312 + DEFINE_FREE(free_usb_request, struct usb_request *, free_usb_request(_T)) 294 313 295 314 /*-------------------------------------------------------------------------*/ 296 315
+41 -5
include/linux/usb/typec_mux.h
··· 3 3 #ifndef __USB_TYPEC_MUX 4 4 #define __USB_TYPEC_MUX 5 5 6 + #include <linux/err.h> 6 7 #include <linux/property.h> 7 8 #include <linux/usb/typec.h> 8 9 ··· 25 24 void *drvdata; 26 25 }; 27 26 27 + #if IS_ENABLED(CONFIG_TYPEC) 28 + 28 29 struct typec_switch *fwnode_typec_switch_get(struct fwnode_handle *fwnode); 29 30 void typec_switch_put(struct typec_switch *sw); 30 31 int typec_switch_set(struct typec_switch *sw, 31 32 enum typec_orientation orientation); 32 - 33 - static inline struct typec_switch *typec_switch_get(struct device *dev) 34 - { 35 - return fwnode_typec_switch_get(dev_fwnode(dev)); 36 - } 37 33 38 34 struct typec_switch_dev * 39 35 typec_switch_register(struct device *parent, ··· 39 41 40 42 void typec_switch_set_drvdata(struct typec_switch_dev *sw, void *data); 41 43 void *typec_switch_get_drvdata(struct typec_switch_dev *sw); 44 + 45 + #else 46 + 47 + static inline struct typec_switch * 48 + fwnode_typec_switch_get(struct fwnode_handle *fwnode) 49 + { 50 + return NULL; 51 + } 52 + 53 + static inline void typec_switch_put(struct typec_switch *sw) {} 54 + 55 + static inline int typec_switch_set(struct typec_switch *sw, 56 + enum typec_orientation orientation) 57 + { 58 + return 0; 59 + } 60 + 61 + static inline struct typec_switch_dev * 62 + typec_switch_register(struct device *parent, 63 + const struct typec_switch_desc *desc) 64 + { 65 + return ERR_PTR(-EOPNOTSUPP); 66 + } 67 + 68 + static inline void typec_switch_unregister(struct typec_switch_dev *sw) {} 69 + 70 + static inline void typec_switch_set_drvdata(struct typec_switch_dev *sw, void *data) {} 71 + static inline void *typec_switch_get_drvdata(struct typec_switch_dev *sw) 72 + { 73 + return ERR_PTR(-EOPNOTSUPP); 74 + } 75 + 76 + #endif /* CONFIG_TYPEC */ 77 + 78 + static inline struct typec_switch *typec_switch_get(struct device *dev) 79 + { 80 + return fwnode_typec_switch_get(dev_fwnode(dev)); 81 + } 42 82 43 83 struct typec_mux_state { 44 84 struct typec_altmode *alt;
+177
include/linux/usb/usbio.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + /* 3 + * Copyright (c) 2025 Intel Corporation. 4 + * 5 + */ 6 + 7 + #ifndef _LINUX_USBIO_H_ 8 + #define _LINUX_USBIO_H_ 9 + 10 + #include <linux/auxiliary_bus.h> 11 + #include <linux/byteorder/generic.h> 12 + #include <linux/list.h> 13 + #include <linux/types.h> 14 + 15 + /*********************** 16 + * USBIO Clients Names * 17 + ***********************/ 18 + #define USBIO_GPIO_CLIENT "usbio-gpio" 19 + #define USBIO_I2C_CLIENT "usbio-i2c" 20 + 21 + /**************** 22 + * USBIO quirks * 23 + ****************/ 24 + #define USBIO_QUIRK_BULK_MAXP_63 BIT(0) /* Force bulk endpoint maxp to 63 */ 25 + #define USBIO_QUIRK_I2C_NO_INIT_ACK BIT(8) /* Do not ask for ack on I2C init */ 26 + #define USBIO_QUIRK_I2C_MAX_RW_LEN_52 BIT(9) /* Set i2c-adapter max r/w len to 52 */ 27 + #define USBIO_QUIRK_I2C_USE_CHUNK_LEN BIT(10) /* Send chunk-len for split xfers */ 28 + #define USBIO_QUIRK_I2C_ALLOW_400KHZ BIT(11) /* Override desc, allowing 400 KHz */ 29 + 30 + /************************** 31 + * USBIO Type Definitions * 32 + **************************/ 33 + 34 + /* USBIO Packet Type */ 35 + #define USBIO_PKTTYPE_CTRL 1 36 + #define USBIO_PKTTYPE_DBG 2 37 + #define USBIO_PKTTYPE_GPIO 3 38 + #define USBIO_PKTTYPE_I2C 4 39 + 40 + /* USBIO Packet Header */ 41 + struct usbio_packet_header { 42 + u8 type; 43 + u8 cmd; 44 + u8 flags; 45 + } __packed; 46 + 47 + /* USBIO Control Transfer Packet */ 48 + struct usbio_ctrl_packet { 49 + struct usbio_packet_header header; 50 + u8 len; 51 + u8 data[] __counted_by(len); 52 + } __packed; 53 + 54 + /* USBIO Bulk Transfer Packet */ 55 + struct usbio_bulk_packet { 56 + struct usbio_packet_header header; 57 + __le16 len; 58 + u8 data[] __counted_by(len); 59 + } __packed; 60 + 61 + /* USBIO GPIO commands */ 62 + enum usbio_gpio_cmd { 63 + USBIO_GPIOCMD_DEINIT, 64 + USBIO_GPIOCMD_INIT, 65 + USBIO_GPIOCMD_READ, 66 + USBIO_GPIOCMD_WRITE, 67 + USBIO_GPIOCMD_END 68 + }; 69 + 70 + /* USBIO GPIO config */ 71 + enum usbio_gpio_pincfg { 72 + USBIO_GPIO_PINCFG_DEFAULT, 73 + USBIO_GPIO_PINCFG_PULLUP, 74 + USBIO_GPIO_PINCFG_PULLDOWN, 75 + USBIO_GPIO_PINCFG_PUSHPULL 76 + }; 77 + 78 + #define USBIO_GPIO_PINCFG_SHIFT 2 79 + #define USBIO_GPIO_PINCFG_MASK (0x3 << USBIO_GPIO_PINCFG_SHIFT) 80 + #define USBIO_GPIO_SET_PINCFG(pincfg) \ 81 + (((pincfg) << USBIO_GPIO_PINCFG_SHIFT) & USBIO_GPIO_PINCFG_MASK) 82 + 83 + enum usbio_gpio_pinmode { 84 + USBIO_GPIO_PINMOD_INVAL, 85 + USBIO_GPIO_PINMOD_INPUT, 86 + USBIO_GPIO_PINMOD_OUTPUT, 87 + USBIO_GPIO_PINMOD_MAXVAL 88 + }; 89 + 90 + #define USBIO_GPIO_PINMOD_MASK 0x3 91 + #define USBIO_GPIO_SET_PINMOD(pin) (pin & USBIO_GPIO_PINMOD_MASK) 92 + 93 + /************************* 94 + * USBIO GPIO Controller * 95 + *************************/ 96 + 97 + #define USBIO_MAX_GPIOBANKS 5 98 + #define USBIO_GPIOSPERBANK 32 99 + 100 + struct usbio_gpio_bank_desc { 101 + u8 id; 102 + u8 pins; 103 + __le32 bmap; 104 + } __packed; 105 + 106 + struct usbio_gpio_init { 107 + u8 bankid; 108 + u8 config; 109 + u8 pincount; 110 + u8 pin; 111 + } __packed; 112 + 113 + struct usbio_gpio_rw { 114 + u8 bankid; 115 + u8 pincount; 116 + u8 pin; 117 + __le32 value; 118 + } __packed; 119 + 120 + /* USBIO I2C commands */ 121 + enum usbio_i2c_cmd { 122 + USBIO_I2CCMD_UNINIT, 123 + USBIO_I2CCMD_INIT, 124 + USBIO_I2CCMD_READ, 125 + USBIO_I2CCMD_WRITE, 126 + USBIO_I2CCMD_END 127 + }; 128 + 129 + /************************ 130 + * USBIO I2C Controller * 131 + ************************/ 132 + 133 + #define USBIO_MAX_I2CBUSES 5 134 + 135 + #define USBIO_I2C_BUS_ADDR_CAP_10B BIT(3) /* 10bit address support */ 136 + #define USBIO_I2C_BUS_MODE_CAP_MASK 0x3 137 + #define USBIO_I2C_BUS_MODE_CAP_SM 0 /* Standard Mode */ 138 + #define USBIO_I2C_BUS_MODE_CAP_FM 1 /* Fast Mode */ 139 + #define USBIO_I2C_BUS_MODE_CAP_FMP 2 /* Fast Mode+ */ 140 + #define USBIO_I2C_BUS_MODE_CAP_HSM 3 /* High-Speed Mode */ 141 + 142 + struct usbio_i2c_bus_desc { 143 + u8 id; 144 + u8 caps; 145 + } __packed; 146 + 147 + struct usbio_i2c_uninit { 148 + u8 busid; 149 + __le16 config; 150 + } __packed; 151 + 152 + struct usbio_i2c_init { 153 + u8 busid; 154 + __le16 config; 155 + __le32 speed; 156 + } __packed; 157 + 158 + struct usbio_i2c_rw { 159 + u8 busid; 160 + __le16 config; 161 + __le16 size; 162 + u8 data[] __counted_by(size); 163 + } __packed; 164 + 165 + int usbio_control_msg(struct auxiliary_device *adev, u8 type, u8 cmd, 166 + const void *obuf, u16 obuf_len, void *ibuf, u16 ibuf_len); 167 + 168 + int usbio_bulk_msg(struct auxiliary_device *adev, u8 type, u8 cmd, bool last, 169 + const void *obuf, u16 obuf_len, void *ibuf, u16 ibuf_len); 170 + 171 + int usbio_acquire(struct auxiliary_device *adev); 172 + void usbio_release(struct auxiliary_device *adev); 173 + void usbio_get_txrxbuf_len(struct auxiliary_device *adev, u16 *txbuf_len, u16 *rxbuf_len); 174 + unsigned long usbio_get_quirks(struct auxiliary_device *adev); 175 + void usbio_acpi_bind(struct auxiliary_device *adev, const struct acpi_device_id *hids); 176 + 177 + #endif
+9
include/linux/usb/xhci-sideband.h
··· 11 11 12 12 #include <linux/scatterlist.h> 13 13 #include <linux/usb.h> 14 + #include <linux/usb/hcd.h> 14 15 15 16 #define EP_CTX_PER_DEV 31 /* FIXME defined twice, from xhci.h */ 16 17 ··· 84 83 struct usb_host_endpoint *host_ep); 85 84 struct sg_table * 86 85 xhci_sideband_get_event_buffer(struct xhci_sideband *sb); 86 + 87 + #if IS_ENABLED(CONFIG_USB_XHCI_SIDEBAND) 88 + bool xhci_sideband_check(struct usb_hcd *hcd); 89 + #else 90 + static inline bool xhci_sideband_check(struct usb_hcd *hcd) 91 + { return false; } 92 + #endif /* IS_ENABLED(CONFIG_USB_XHCI_SIDEBAND) */ 93 + 87 94 int 88 95 xhci_sideband_create_interrupter(struct xhci_sideband *sb, int num_seg, 89 96 bool ip_autoclear, u32 imod_interval, int intr_num);
+2 -2
tools/usb/usbip/src/usbipd.c
··· 396 396 397 397 usbip_net_set_reuseaddr(sock); 398 398 usbip_net_set_nodelay(sock); 399 - /* We use seperate sockets for IPv4 and IPv6 399 + /* We use separate sockets for IPv4 and IPv6 400 400 * (see do_standalone_mode()) */ 401 401 usbip_net_set_v6only(sock); 402 402 ··· 517 517 518 518 /* 519 519 * To suppress warnings on systems with bindv6only disabled 520 - * (default), we use seperate sockets for IPv6 and IPv4 and set 520 + * (default), we use separate sockets for IPv6 and IPv4 and set 521 521 * IPV6_V6ONLY on the IPv6 sockets. 522 522 */ 523 523 if (ipv4 && ipv6)