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.11-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb

Pull USB / Thunderbolt updates from Greg KH:
"Here is the big set of USB and Thunderbolt changes for 6.11-rc1.

Nothing earth-shattering in here, just constant forward progress in
adding support for new hardware and better debugging functionalities
for thunderbolt devices and the subsystem. Included in here are:

- thunderbolt debugging update and driver additions

- xhci driver updates

- typec driver updates

- kselftest device driver changes (acked by the relevant maintainers,
depended on other changes in this tree.)

- cdns3 driver updates

- gadget driver updates

- MODULE_DESCRIPTION() additions

- dwc3 driver updates and fixes

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

* tag 'usb-6.11-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb: (112 commits)
kselftest: devices: Add test to detect device error logs
kselftest: Move ksft helper module to common directory
kselftest: devices: Move discoverable devices test to subdirectory
usb: gadget: f_uac2: fix non-newline-terminated function name
USB: uas: Implement the new shutdown callback
USB: core: add 'shutdown' callback to usb_driver
usb: typec: Drop explicit initialization of struct i2c_device_id::driver_data to 0
usb: dwc3: enable CCI support for AMD-xilinx DWC3 controller
usb: dwc2: add support for other Lantiq SoCs
usb: gadget: Use u16 types for 16-bit fields
usb: gadget: midi2: Fix incorrect default MIDI2 protocol setup
usb: dwc3: core: Check all ports when set phy suspend
usb: typec: tcpci: add support to set connector orientation
dt-bindings: usb: Convert fsl-usb to yaml
usb: typec: ucsi: reorder operations in ucsi_run_command()
usb: typec: ucsi: extract common code for command handling
usb: typec: ucsi: inline ucsi_read_message_in
usb: typec: ucsi: rework command execution functions
usb: typec: ucsi: split read operation
usb: typec: ucsi: simplify command sending API
...

+2567 -1211
+10
Documentation/ABI/testing/sysfs-bus-pci-drivers-xhci_hcd
··· 75 75 The default value is 1 (GNU Remote Debug command). 76 76 Other permissible value is 0 which is for vendor defined debug 77 77 target. 78 + 79 + What: /sys/bus/pci/drivers/xhci_hcd/.../dbc_poll_interval_ms 80 + Date: February 2024 81 + Contact: Mathias Nyman <mathias.nyman@linux.intel.com> 82 + Description: 83 + This attribute adjust the polling interval used to check for 84 + DbC events. Unit is milliseconds. Accepted values range from 0 85 + up to 5000. The default value is 64 ms. 86 + This polling interval is used while DbC is enabled but has no 87 + active data transfers.
+3
Documentation/admin-guide/kernel-parameters.txt
··· 7041 7041 usb-storage.delay_use= 7042 7042 [UMS] The delay in seconds before a new device is 7043 7043 scanned for Logical Units (default 1). 7044 + Optionally the delay in milliseconds if the value has 7045 + suffix with "ms". 7046 + Example: delay_use=2567ms 7044 7047 7045 7048 usb-storage.quirks= 7046 7049 [UMS] A list of quirks entries to supplement or
+12 -3
Documentation/devicetree/bindings/usb/cdns,usb3.yaml
··· 42 42 - const: otg 43 43 - const: wakeup 44 44 45 - dr_mode: 46 - enum: [host, otg, peripheral] 45 + port: 46 + $ref: /schemas/graph.yaml#/properties/port 47 + description: 48 + This port is used with the 'usb-role-switch' property to connect the 49 + cdns3 to type C connector. 47 50 48 51 maximum-speed: 49 52 enum: [super-speed, high-speed, full-speed] ··· 73 70 description: Enable resetting of PHY if Rx fail is detected 74 71 type: boolean 75 72 73 + dependencies: 74 + port: [ usb-role-switch ] 75 + 76 76 required: 77 77 - compatible 78 78 - reg ··· 83 77 - interrupts 84 78 - interrupt-names 85 79 86 - additionalProperties: false 80 + allOf: 81 + - $ref: usb-drd.yaml# 82 + 83 + unevaluatedProperties: false 87 84 88 85 examples: 89 86 - |
+1 -1
Documentation/devicetree/bindings/usb/dwc2.yaml
··· 188 188 - clocks 189 189 - clock-names 190 190 191 - additionalProperties: false 191 + unevaluatedProperties: false 192 192 193 193 examples: 194 194 - |
+95
Documentation/devicetree/bindings/usb/fsl,usb2.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/usb/fsl,usb2.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Freescale SOC USB controllers 8 + 9 + maintainers: 10 + - Frank Li <Frank.Li@nxp.com> 11 + 12 + description: | 13 + The device node for a USB controller that is part of a Freescale 14 + SOC is as described in the document "Open Firmware Recommended 15 + Practice: Universal Serial Bus" with the following modifications 16 + and additions. 17 + 18 + properties: 19 + compatible: 20 + oneOf: 21 + - enum: 22 + - fsl-usb2-mph 23 + - fsl-usb2-dr 24 + - items: 25 + - enum: 26 + - fsl-usb2-dr-v2.2 27 + - fsl-usb2-dr-v2.5 28 + - const: fsl-usb2-dr 29 + 30 + reg: 31 + maxItems: 1 32 + 33 + interrupts: 34 + maxItems: 1 35 + 36 + phy_type: 37 + $ref: /schemas/types.yaml#/definitions/string 38 + enum: [ulpi, serial, utmi, utmi_wide] 39 + 40 + port0: 41 + $ref: /schemas/types.yaml#/definitions/flag 42 + description: 43 + Indicates port0 is connected for fsl-usb2-mph compatible controllers. 44 + 45 + port1: 46 + $ref: /schemas/types.yaml#/definitions/flag 47 + description: 48 + Indicates port1 is connected for "fsl-usb2-mph" compatible controllers. 49 + 50 + fsl,invert-drvvbus: 51 + $ref: /schemas/types.yaml#/definitions/flag 52 + description: 53 + for MPC5121 USB0 only. Indicates the 54 + port power polarity of internal PHY signal DRVVBUS is inverted. 55 + 56 + fsl,invert-pwr-fault: 57 + $ref: /schemas/types.yaml#/definitions/flag 58 + description: 59 + for MPC5121 USB0 only. Indicates 60 + the PWR_FAULT signal polarity is inverted. 61 + 62 + required: 63 + - compatible 64 + - reg 65 + - interrupts 66 + - phy_type 67 + 68 + allOf: 69 + - $ref: usb-drd.yaml# 70 + 71 + unevaluatedProperties: false 72 + 73 + examples: 74 + - | 75 + #include <dt-bindings/interrupt-controller/irq.h> 76 + 77 + usb@22000 { 78 + compatible = "fsl-usb2-mph"; 79 + reg = <22000 1000>; 80 + interrupts = <27 IRQ_TYPE_EDGE_RISING>; 81 + phy_type = "ulpi"; 82 + port0; 83 + port1; 84 + }; 85 + 86 + - | 87 + #include <dt-bindings/interrupt-controller/irq.h> 88 + 89 + usb@23000 { 90 + compatible = "fsl-usb2-dr"; 91 + reg = <23000 1000>; 92 + interrupts = <26 IRQ_TYPE_EDGE_RISING>; 93 + dr_mode = "otg"; 94 + phy_type = "ulpi"; 95 + };
-81
Documentation/devicetree/bindings/usb/fsl-usb.txt
··· 1 - Freescale SOC USB controllers 2 - 3 - The device node for a USB controller that is part of a Freescale 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 : Should be "fsl-usb2-mph" for multi port host USB 10 - controllers, or "fsl-usb2-dr" for dual role USB controllers 11 - or "fsl,mpc5121-usb2-dr" for dual role USB controllers of MPC5121. 12 - Wherever applicable, the IP version of the USB controller should 13 - also be mentioned (for eg. fsl-usb2-dr-v2.2 for bsc9132). 14 - - phy_type : For multi port host USB controllers, should be one of 15 - "ulpi", or "serial". For dual role USB controllers, should be 16 - one of "ulpi", "utmi", "utmi_wide", or "serial". 17 - - reg : Offset and length of the register set for the device 18 - - port0 : boolean; if defined, indicates port0 is connected for 19 - fsl-usb2-mph compatible controllers. Either this property or 20 - "port1" (or both) must be defined for "fsl-usb2-mph" compatible 21 - controllers. 22 - - port1 : boolean; if defined, indicates port1 is connected for 23 - fsl-usb2-mph compatible controllers. Either this property or 24 - "port0" (or both) must be defined for "fsl-usb2-mph" compatible 25 - controllers. 26 - - dr_mode : indicates the working mode for "fsl-usb2-dr" compatible 27 - controllers. Can be "host", "peripheral", or "otg". Default to 28 - "host" if not defined for backward compatibility. 29 - 30 - Recommended properties : 31 - - interrupts : <a b> where a is the interrupt number and b is a 32 - field that represents an encoding of the sense and level 33 - information for the interrupt. This should be encoded based on 34 - the information in section 2) depending on the type of interrupt 35 - controller you have. 36 - 37 - Optional properties : 38 - - fsl,invert-drvvbus : boolean; for MPC5121 USB0 only. Indicates the 39 - port power polarity of internal PHY signal DRVVBUS is inverted. 40 - - fsl,invert-pwr-fault : boolean; for MPC5121 USB0 only. Indicates 41 - the PWR_FAULT signal polarity is inverted. 42 - 43 - Example multi port host USB controller device node : 44 - usb@22000 { 45 - compatible = "fsl-usb2-mph"; 46 - reg = <22000 1000>; 47 - #address-cells = <1>; 48 - #size-cells = <0>; 49 - interrupt-parent = <700>; 50 - interrupts = <27 1>; 51 - phy_type = "ulpi"; 52 - port0; 53 - port1; 54 - }; 55 - 56 - Example dual role USB controller device node : 57 - usb@23000 { 58 - compatible = "fsl-usb2-dr"; 59 - reg = <23000 1000>; 60 - #address-cells = <1>; 61 - #size-cells = <0>; 62 - interrupt-parent = <700>; 63 - interrupts = <26 1>; 64 - dr_mode = "otg"; 65 - phy = "ulpi"; 66 - }; 67 - 68 - Example dual role USB controller device node for MPC5121ADS: 69 - 70 - usb@4000 { 71 - compatible = "fsl,mpc5121-usb2-dr"; 72 - reg = <0x4000 0x1000>; 73 - #address-cells = <1>; 74 - #size-cells = <0>; 75 - interrupt-parent = < &ipic >; 76 - interrupts = <44 0x8>; 77 - dr_mode = "otg"; 78 - phy_type = "utmi_wide"; 79 - fsl,invert-drvvbus; 80 - fsl,invert-pwr-fault; 81 - };
+55 -5
Documentation/devicetree/bindings/usb/genesys,gl850g.yaml
··· 9 9 maintainers: 10 10 - Icenowy Zheng <uwu@icenowy.me> 11 11 12 - allOf: 13 - - $ref: usb-device.yaml# 14 - 15 12 properties: 16 13 compatible: 17 14 enum: ··· 24 27 25 28 vdd-supply: 26 29 description: 27 - the regulator that provides 3.3V core power to the hub. 30 + The regulator that provides 3.3V or 5.0V core power to the hub. 28 31 29 32 peer-hub: 30 33 $ref: /schemas/types.yaml#/definitions/phandle 31 34 description: 32 - phandle to the peer hub on the controller. 35 + For onboard hub controllers that support USB 3.x and USB 2.0 hubs 36 + with shared resets and power supplies, this property is used to identify 37 + the hubs with which these are shared. 33 38 34 39 required: 35 40 - compatible 36 41 - reg 42 + 43 + allOf: 44 + - $ref: usb-device.yaml# 45 + - if: 46 + properties: 47 + compatible: 48 + contains: 49 + enum: 50 + - usb5e3,608 51 + then: 52 + properties: 53 + peer-hub: false 54 + vdd-supply: false 55 + 56 + - if: 57 + properties: 58 + compatible: 59 + contains: 60 + enum: 61 + - usb5e3,610 62 + - usb5e3,620 63 + then: 64 + properties: 65 + peer-hub: true 66 + vdd-supply: true 37 67 38 68 additionalProperties: false 39 69 ··· 76 52 compatible = "usb5e3,608"; 77 53 reg = <1>; 78 54 reset-gpios = <&pio 7 2 GPIO_ACTIVE_LOW>; 55 + }; 56 + }; 57 + 58 + - | 59 + #include <dt-bindings/gpio/gpio.h> 60 + usb { 61 + dr_mode = "host"; 62 + #address-cells = <1>; 63 + #size-cells = <0>; 64 + 65 + /* 2.0 hub on port 1 */ 66 + hub_2_0: hub@1 { 67 + compatible = "usb5e3,610"; 68 + reg = <1>; 69 + peer-hub = <&hub_3_0>; 70 + reset-gpios = <&gpio 20 GPIO_ACTIVE_LOW>; 71 + vdd-supply = <&vcc_5v>; 72 + }; 73 + 74 + /* 3.1 hub on port 4 */ 75 + hub_3_0: hub@2 { 76 + compatible = "usb5e3,620"; 77 + reg = <2>; 78 + peer-hub = <&hub_2_0>; 79 + reset-gpios = <&gpio 20 GPIO_ACTIVE_LOW>; 80 + vdd-supply = <&vcc_5v>; 79 81 }; 80 82 };
+7 -1
Documentation/devicetree/bindings/usb/gpio-sbu-mux.yaml
··· 22 22 - nxp,cbdtu02043 23 23 - onnn,fsusb43l10x 24 24 - pericom,pi3usb102 25 + - ti,tmuxhs4212 25 26 - const: gpio-sbu-mux 26 27 27 28 enable-gpios: ··· 45 44 46 45 required: 47 46 - compatible 48 - - enable-gpios 49 47 - select-gpios 50 48 - orientation-switch 51 49 - port 52 50 53 51 allOf: 54 52 - $ref: usb-switch.yaml# 53 + - if: 54 + required: 55 + - mode-switch 56 + then: 57 + required: 58 + - enable-gpios 55 59 56 60 additionalProperties: false 57 61
+7
Documentation/devicetree/bindings/usb/microchip,mpfs-musb.yaml
··· 34 34 clocks: 35 35 maxItems: 1 36 36 37 + microchip,ext-vbus-drv: 38 + description: 39 + Some ULPI USB PHYs do not support an internal VBUS supply and driving 40 + the CPEN pin requires the configuration of the UPLI_USE__EXTVBUS 41 + bit in ULPI_BUSCONTROL. 42 + $ref: /schemas/types.yaml#/definitions/flag 43 + 37 44 required: 38 45 - compatible 39 46 - reg
+29
Documentation/devicetree/bindings/usb/qcom,dwc3.yaml
··· 30 30 - qcom,sa8775p-dwc3 31 31 - qcom,sc7180-dwc3 32 32 - qcom,sc7280-dwc3 33 + - qcom,sc8180x-dwc3 34 + - qcom,sc8180x-dwc3-mp 33 35 - qcom,sc8280xp-dwc3 34 36 - qcom,sc8280xp-dwc3-mp 35 37 - qcom,sdm660-dwc3 ··· 336 334 contains: 337 335 enum: 338 336 - qcom,qcm2290-dwc3 337 + - qcom,sc8180x-dwc3 338 + - qcom,sc8180x-dwc3-mp 339 339 - qcom,sm6115-dwc3 340 340 - qcom,sm6125-dwc3 341 341 - qcom,sm8150-dwc3 ··· 452 448 - qcom,sa8775p-dwc3 453 449 - qcom,sc7180-dwc3 454 450 - qcom,sc7280-dwc3 451 + - qcom,sc8180x-dwc3 455 452 - qcom,sc8280xp-dwc3 456 453 - qcom,sdm670-dwc3 457 454 - qcom,sdm845-dwc3 ··· 479 474 - const: dp_hs_phy_irq 480 475 - const: dm_hs_phy_irq 481 476 - const: ss_phy_irq 477 + 478 + - if: 479 + properties: 480 + compatible: 481 + contains: 482 + enum: 483 + - qcom,sc8180x-dwc3-mp 484 + then: 485 + properties: 486 + interrupts: 487 + minItems: 10 488 + maxItems: 10 489 + interrupt-names: 490 + items: 491 + - const: pwr_event_1 492 + - const: pwr_event_2 493 + - const: hs_phy_1 494 + - const: hs_phy_2 495 + - const: dp_hs_phy_1 496 + - const: dm_hs_phy_1 497 + - const: dp_hs_phy_2 498 + - const: dm_hs_phy_2 499 + - const: ss_phy_1 500 + - const: ss_phy_2 482 501 483 502 - if: 484 503 properties:
+24 -12
arch/arm64/boot/dts/amlogic/meson-g12b-odroid-n2.dtsi
··· 31 31 enable-active-high; 32 32 }; 33 33 34 + /* USB hub supports both USB 2.0 and USB 3.0 root hub */ 35 + usb-hub { 36 + dr_mode = "host"; 37 + #address-cells = <1>; 38 + #size-cells = <0>; 39 + 40 + /* 2.0 hub on port 1 */ 41 + hub_2_0: hub@1 { 42 + compatible = "usb5e3,610"; 43 + reg = <1>; 44 + peer-hub = <&hub_3_0>; 45 + vdd-supply = <&usb_pwr_en>; 46 + }; 47 + 48 + /* 3.0 hub on port 4 */ 49 + hub_3_0: hub@2 { 50 + compatible = "usb5e3,620"; 51 + reg = <2>; 52 + peer-hub = <&hub_2_0>; 53 + reset-gpios = <&gpio GPIOH_4 GPIO_ACTIVE_LOW>; 54 + vdd-supply = <&vcc_5v>; 55 + }; 56 + }; 57 + 34 58 sound { 35 59 compatible = "amlogic,axg-sound-card"; 36 60 model = "ODROID-N2"; ··· 258 234 "PIN_3", /* GPIOX_17 */ 259 235 "PIN_5", /* GPIOX_18 */ 260 236 "PIN_36"; /* GPIOX_19 */ 261 - /* 262 - * WARNING: The USB Hub on the Odroid-N2 needs a reset signal 263 - * to be turned high in order to be detected by the USB Controller 264 - * This signal should be handled by a USB specific power sequence 265 - * in order to reset the Hub when USB bus is powered down. 266 - */ 267 - usb-hub-hog { 268 - gpio-hog; 269 - gpios = <GPIOH_4 GPIO_ACTIVE_HIGH>; 270 - output-high; 271 - line-name = "usb-hub-reset"; 272 - }; 273 237 }; 274 238 275 239 &i2c3 {
+49
drivers/phy/ti/phy-da8xx-usb.c
··· 14 14 #include <linux/phy/phy.h> 15 15 #include <linux/platform_data/phy-da8xx-usb.h> 16 16 #include <linux/platform_device.h> 17 + #include <linux/pm_runtime.h> 17 18 #include <linux/regmap.h> 18 19 19 20 #define PHY_INIT_BITS (CFGCHIP2_SESENDEN | CFGCHIP2_VBDTCTEN) 20 21 21 22 struct da8xx_usb_phy { 23 + struct device *dev; 22 24 struct phy_provider *phy_provider; 23 25 struct phy *usb11_phy; 24 26 struct phy *usb20_phy; ··· 41 39 regmap_write_bits(d_phy->regmap, CFGCHIP(2), CFGCHIP2_USB1SUSPENDM, 42 40 CFGCHIP2_USB1SUSPENDM); 43 41 42 + /* 43 + * USB1.1 can used USB2.0 output clock as reference clock so this is here to prevent USB2.0 44 + * from shutting PHY's power when USB1.1 might use it 45 + */ 46 + pm_runtime_get_sync(d_phy->dev); 47 + 44 48 return 0; 45 49 } 46 50 ··· 57 49 regmap_write_bits(d_phy->regmap, CFGCHIP(2), CFGCHIP2_USB1SUSPENDM, 0); 58 50 59 51 clk_disable_unprepare(d_phy->usb11_clk); 52 + pm_runtime_put_sync(d_phy->dev); 60 53 61 54 return 0; 62 55 } ··· 127 118 .owner = THIS_MODULE, 128 119 }; 129 120 121 + static int __maybe_unused da8xx_runtime_suspend(struct device *dev) 122 + { 123 + struct da8xx_usb_phy *d_phy = dev_get_drvdata(dev); 124 + 125 + dev_dbg(dev, "Suspending ...\n"); 126 + 127 + regmap_set_bits(d_phy->regmap, CFGCHIP(2), CFGCHIP2_PHYPWRDN | CFGCHIP2_OTGPWRDN); 128 + 129 + return 0; 130 + } 131 + 132 + static int __maybe_unused da8xx_runtime_resume(struct device *dev) 133 + { 134 + u32 mask = CFGCHIP2_RESET | CFGCHIP2_PHYPWRDN | CFGCHIP2_OTGPWRDN | CFGCHIP2_PHY_PLLON; 135 + struct da8xx_usb_phy *d_phy = dev_get_drvdata(dev); 136 + u32 pll_status; 137 + 138 + regmap_update_bits(d_phy->regmap, CFGCHIP(2), mask, CFGCHIP2_PHY_PLLON); 139 + 140 + dev_dbg(dev, "Resuming ...\n"); 141 + 142 + return regmap_read_poll_timeout(d_phy->regmap, CFGCHIP(2), pll_status, 143 + pll_status & CFGCHIP2_PHYCLKGD, 1000, 500000); 144 + } 145 + 146 + static const struct dev_pm_ops da8xx_usb_phy_pm_ops = { 147 + SET_RUNTIME_PM_OPS(da8xx_runtime_suspend, da8xx_runtime_resume, NULL) 148 + }; 149 + 130 150 static struct phy *da8xx_usb_phy_of_xlate(struct device *dev, 131 151 const struct of_phandle_args *args) 132 152 { ··· 184 146 d_phy = devm_kzalloc(dev, sizeof(*d_phy), GFP_KERNEL); 185 147 if (!d_phy) 186 148 return -ENOMEM; 149 + 150 + d_phy->dev = dev; 187 151 188 152 if (pdata) 189 153 d_phy->regmap = pdata->cfgchip; ··· 248 208 regmap_write_bits(d_phy->regmap, CFGCHIP(2), 249 209 PHY_INIT_BITS, PHY_INIT_BITS); 250 210 211 + pm_runtime_set_active(dev); 212 + devm_pm_runtime_enable(dev); 213 + /* 214 + * Prevent runtime pm from being ON by default. Users can enable 215 + * it using power/control in sysfs. 216 + */ 217 + pm_runtime_forbid(dev); 218 + 251 219 return 0; 252 220 } 253 221 ··· 280 232 .remove_new = da8xx_usb_phy_remove, 281 233 .driver = { 282 234 .name = "da8xx-usb-phy", 235 + .pm = &da8xx_usb_phy_pm_ops, 283 236 .of_match_table = da8xx_usb_phy_ids, 284 237 }, 285 238 };
+11 -6
drivers/thunderbolt/Kconfig
··· 22 22 bool "Enable write by debugfs to configuration spaces (DANGEROUS)" 23 23 help 24 24 Enables writing to device configuration registers through 25 - debugfs interface. 25 + debugfs interface. You can use tools such as Thunderbolt/USB4 26 + debugging tools to access these registers. For more 27 + information see: 28 + 29 + https://github.com/intel/tbtools 26 30 27 31 Only enable this if you know what you are doing! Never enable 28 32 this for production systems or distro kernels. 29 33 30 34 config USB4_DEBUGFS_MARGINING 31 - bool "Expose receiver lane margining operations under USB4 ports (DANGEROUS)" 35 + bool "Expose receiver lane margining operations under USB4 ports and retimers (DANGEROUS)" 32 36 depends on DEBUG_FS 33 37 depends on USB4_DEBUGFS_WRITE 34 38 help 35 - Enables hardware and software based receiver lane margining support 36 - under each USB4 port. Used for electrical quality and robustness 37 - validation during manufacturing. Should not be enabled by distro 38 - kernels. 39 + Enables hardware and software based receiver lane margining 40 + support under each USB4 port and retimer, including retimers 41 + on the other side of the cable. Used for electrical quality 42 + and robustness validation during manufacturing. Should not be 43 + enabled by distro kernels. 39 44 40 45 config USB4_KUNIT_TEST 41 46 bool "KUnit tests" if !KUNIT_ALL_TESTS
+484 -164
drivers/thunderbolt/debugfs.c
··· 7 7 * Mika Westerberg <mika.westerberg@linux.intel.com> 8 8 */ 9 9 10 + #include <linux/bitfield.h> 10 11 #include <linux/debugfs.h> 11 12 #include <linux/pm_runtime.h> 12 13 #include <linux/uaccess.h> ··· 33 32 #define PATH_LEN 2 34 33 35 34 #define COUNTER_SET_LEN 3 35 + 36 + /* Sideband registers and their sizes as defined in the USB4 spec */ 37 + struct sb_reg { 38 + unsigned int reg; 39 + unsigned int size; 40 + }; 41 + 42 + #define SB_MAX_SIZE 64 43 + 44 + /* Sideband registers for router */ 45 + static const struct sb_reg port_sb_regs[] = { 46 + { USB4_SB_VENDOR_ID, 4 }, 47 + { USB4_SB_PRODUCT_ID, 4 }, 48 + { USB4_SB_DEBUG_CONF, 4 }, 49 + { USB4_SB_DEBUG, 54 }, 50 + { USB4_SB_LRD_TUNING, 4 }, 51 + { USB4_SB_OPCODE, 4 }, 52 + { USB4_SB_METADATA, 4 }, 53 + { USB4_SB_LINK_CONF, 3 }, 54 + { USB4_SB_GEN23_TXFFE, 4 }, 55 + { USB4_SB_GEN4_TXFFE, 4 }, 56 + { USB4_SB_VERSION, 4 }, 57 + { USB4_SB_DATA, 64 }, 58 + }; 59 + 60 + /* Sideband registers for retimer */ 61 + static const struct sb_reg retimer_sb_regs[] = { 62 + { USB4_SB_VENDOR_ID, 4 }, 63 + { USB4_SB_PRODUCT_ID, 4 }, 64 + { USB4_SB_FW_VERSION, 4 }, 65 + { USB4_SB_LRD_TUNING, 4 }, 66 + { USB4_SB_OPCODE, 4 }, 67 + { USB4_SB_METADATA, 4 }, 68 + { USB4_SB_GEN23_TXFFE, 4 }, 69 + { USB4_SB_GEN4_TXFFE, 4 }, 70 + { USB4_SB_VERSION, 4 }, 71 + { USB4_SB_DATA, 64 }, 72 + }; 36 73 37 74 #define DEBUGFS_ATTR(__space, __write) \ 38 75 static int __space ## _open(struct inode *inode, struct file *file) \ ··· 223 184 224 185 return regs_write(sw, NULL, user_buf, count, ppos); 225 186 } 187 + 188 + static bool parse_sb_line(char **line, u8 *reg, u8 *data, size_t data_size, 189 + size_t *bytes_read) 190 + { 191 + char *field, *token; 192 + int i; 193 + 194 + token = strsep(line, "\n"); 195 + if (!token) 196 + return false; 197 + 198 + /* Parse the register first */ 199 + field = strsep(&token, " "); 200 + if (!field) 201 + return false; 202 + if (kstrtou8(field, 0, reg)) 203 + return false; 204 + 205 + /* Then the values for the register, up to data_size */ 206 + for (i = 0; i < data_size; i++) { 207 + field = strsep(&token, " "); 208 + if (!field) 209 + break; 210 + if (kstrtou8(field, 0, &data[i])) 211 + return false; 212 + } 213 + 214 + *bytes_read = i; 215 + return true; 216 + } 217 + 218 + static ssize_t sb_regs_write(struct tb_port *port, const struct sb_reg *sb_regs, 219 + size_t size, enum usb4_sb_target target, u8 index, 220 + char *buf, size_t count, loff_t *ppos) 221 + { 222 + u8 reg, data[SB_MAX_SIZE]; 223 + size_t bytes_read; 224 + char *line = buf; 225 + 226 + /* User did hardware changes behind the driver's back */ 227 + add_taint(TAINT_USER, LOCKDEP_STILL_OK); 228 + 229 + /* 230 + * For sideband registers we accept: 231 + * reg b0 b1 b2...\n 232 + * 233 + * Here "reg" is the byte offset of the sideband register and "b0".. 234 + * are the byte values. There can be less byte values than the register 235 + * size. The leftovers will not be overwritten. 236 + */ 237 + while (parse_sb_line(&line, &reg, data, ARRAY_SIZE(data), &bytes_read)) { 238 + const struct sb_reg *sb_reg; 239 + int ret; 240 + 241 + /* At least one byte must be passed */ 242 + if (bytes_read < 1) 243 + return -EINVAL; 244 + 245 + /* Find the register */ 246 + sb_reg = NULL; 247 + for (int i = 0; i < size; i++) { 248 + if (sb_regs[i].reg == reg) { 249 + sb_reg = &sb_regs[i]; 250 + break; 251 + } 252 + } 253 + 254 + if (!sb_reg) 255 + return -EINVAL; 256 + 257 + if (bytes_read > sb_regs->size) 258 + return -E2BIG; 259 + 260 + ret = usb4_port_sb_write(port, target, index, sb_reg->reg, data, 261 + bytes_read); 262 + if (ret) 263 + return ret; 264 + } 265 + 266 + return 0; 267 + } 268 + 269 + static ssize_t port_sb_regs_write(struct file *file, const char __user *user_buf, 270 + size_t count, loff_t *ppos) 271 + { 272 + struct seq_file *s = file->private_data; 273 + struct tb_port *port = s->private; 274 + struct tb_switch *sw = port->sw; 275 + struct tb *tb = sw->tb; 276 + char *buf; 277 + int ret; 278 + 279 + buf = validate_and_copy_from_user(user_buf, &count); 280 + if (IS_ERR(buf)) 281 + return PTR_ERR(buf); 282 + 283 + pm_runtime_get_sync(&sw->dev); 284 + 285 + if (mutex_lock_interruptible(&tb->lock)) { 286 + ret = -ERESTARTSYS; 287 + goto out_rpm_put; 288 + } 289 + 290 + ret = sb_regs_write(port, port_sb_regs, ARRAY_SIZE(port_sb_regs), 291 + USB4_SB_TARGET_ROUTER, 0, buf, count, ppos); 292 + 293 + mutex_unlock(&tb->lock); 294 + out_rpm_put: 295 + pm_runtime_mark_last_busy(&sw->dev); 296 + pm_runtime_put_autosuspend(&sw->dev); 297 + 298 + return ret < 0 ? ret : count; 299 + } 300 + 301 + static ssize_t retimer_sb_regs_write(struct file *file, 302 + const char __user *user_buf, 303 + size_t count, loff_t *ppos) 304 + { 305 + struct seq_file *s = file->private_data; 306 + struct tb_retimer *rt = s->private; 307 + struct tb *tb = rt->tb; 308 + char *buf; 309 + int ret; 310 + 311 + buf = validate_and_copy_from_user(user_buf, &count); 312 + if (IS_ERR(buf)) 313 + return PTR_ERR(buf); 314 + 315 + pm_runtime_get_sync(&rt->dev); 316 + 317 + if (mutex_lock_interruptible(&tb->lock)) { 318 + ret = -ERESTARTSYS; 319 + goto out_rpm_put; 320 + } 321 + 322 + ret = sb_regs_write(rt->port, retimer_sb_regs, ARRAY_SIZE(retimer_sb_regs), 323 + USB4_SB_TARGET_RETIMER, rt->index, buf, count, ppos); 324 + 325 + mutex_unlock(&tb->lock); 326 + out_rpm_put: 327 + pm_runtime_mark_last_busy(&rt->dev); 328 + pm_runtime_put_autosuspend(&rt->dev); 329 + 330 + return ret < 0 ? ret : count; 331 + } 226 332 #define DEBUGFS_MODE 0600 227 333 #else 228 334 #define port_regs_write NULL 229 335 #define switch_regs_write NULL 336 + #define port_sb_regs_write NULL 337 + #define retimer_sb_regs_write NULL 230 338 #define DEBUGFS_MODE 0400 231 339 #endif 232 340 233 341 #if IS_ENABLED(CONFIG_USB4_DEBUGFS_MARGINING) 234 342 /** 235 343 * struct tb_margining - Lane margining support 344 + * @port: USB4 port through which the margining operations are run 345 + * @target: Sideband target 346 + * @index: Retimer index if taget is %USB4_SB_TARGET_RETIMER 347 + * @dev: Pointer to the device that is the target (USB4 port or retimer) 236 348 * @caps: Port lane margining capabilities 237 349 * @results: Last lane margining results 238 350 * @lanes: %0, %1 or %7 (all) ··· 400 210 * right/high 401 211 */ 402 212 struct tb_margining { 213 + struct tb_port *port; 214 + enum usb4_sb_target target; 215 + u8 index; 216 + struct device *dev; 403 217 u32 caps[2]; 404 218 u32 results[2]; 405 219 unsigned int lanes; ··· 419 225 bool right_high; 420 226 }; 421 227 422 - static bool supports_software(const struct usb4_port *usb4) 228 + static bool supports_software(const struct tb_margining *margining) 423 229 { 424 - return usb4->margining->caps[0] & USB4_MARGIN_CAP_0_MODES_SW; 230 + return margining->caps[0] & USB4_MARGIN_CAP_0_MODES_SW; 425 231 } 426 232 427 - static bool supports_hardware(const struct usb4_port *usb4) 233 + static bool supports_hardware(const struct tb_margining *margining) 428 234 { 429 - return usb4->margining->caps[0] & USB4_MARGIN_CAP_0_MODES_HW; 235 + return margining->caps[0] & USB4_MARGIN_CAP_0_MODES_HW; 430 236 } 431 237 432 - static bool both_lanes(const struct usb4_port *usb4) 238 + static bool both_lanes(const struct tb_margining *margining) 433 239 { 434 - return usb4->margining->caps[0] & USB4_MARGIN_CAP_0_2_LANES; 240 + return margining->caps[0] & USB4_MARGIN_CAP_0_2_LANES; 435 241 } 436 242 437 - static unsigned int independent_voltage_margins(const struct usb4_port *usb4) 243 + static unsigned int 244 + independent_voltage_margins(const struct tb_margining *margining) 438 245 { 439 - return (usb4->margining->caps[0] & USB4_MARGIN_CAP_0_VOLTAGE_INDP_MASK) >> 440 - USB4_MARGIN_CAP_0_VOLTAGE_INDP_SHIFT; 246 + return FIELD_GET(USB4_MARGIN_CAP_0_VOLTAGE_INDP_MASK, margining->caps[0]); 441 247 } 442 248 443 - static bool supports_time(const struct usb4_port *usb4) 249 + static bool supports_time(const struct tb_margining *margining) 444 250 { 445 - return usb4->margining->caps[0] & USB4_MARGIN_CAP_0_TIME; 251 + return margining->caps[0] & USB4_MARGIN_CAP_0_TIME; 446 252 } 447 253 448 254 /* Only applicable if supports_time() returns true */ 449 - static unsigned int independent_time_margins(const struct usb4_port *usb4) 255 + static unsigned int 256 + independent_time_margins(const struct tb_margining *margining) 450 257 { 451 - return (usb4->margining->caps[1] & USB4_MARGIN_CAP_1_TIME_INDP_MASK) >> 452 - USB4_MARGIN_CAP_1_TIME_INDP_SHIFT; 258 + return FIELD_GET(USB4_MARGIN_CAP_1_TIME_INDP_MASK, margining->caps[1]); 453 259 } 454 260 455 261 static ssize_t ··· 457 263 size_t count, loff_t *ppos) 458 264 { 459 265 struct seq_file *s = file->private_data; 460 - struct tb_port *port = s->private; 461 - struct usb4_port *usb4 = port->usb4; 462 - struct tb *tb = port->sw->tb; 266 + struct tb_margining *margining = s->private; 267 + struct tb *tb = margining->port->sw->tb; 463 268 unsigned int val; 464 269 int ret = 0; 465 270 char *buf; ··· 466 273 if (mutex_lock_interruptible(&tb->lock)) 467 274 return -ERESTARTSYS; 468 275 469 - if (usb4->margining->software) { 276 + if (margining->software) { 470 277 ret = -EINVAL; 471 278 goto out_unlock; 472 279 } ··· 483 290 if (ret) 484 291 goto out_free; 485 292 486 - if (val < usb4->margining->min_ber_level || 487 - val > usb4->margining->max_ber_level) { 293 + if (val < margining->min_ber_level || 294 + val > margining->max_ber_level) { 488 295 ret = -EINVAL; 489 296 goto out_free; 490 297 } 491 298 492 - usb4->margining->ber_level = val; 299 + margining->ber_level = val; 493 300 494 301 out_free: 495 302 free_page((unsigned long)buf); ··· 509 316 510 317 static int margining_ber_level_show(struct seq_file *s, void *not_used) 511 318 { 512 - struct tb_port *port = s->private; 513 - struct usb4_port *usb4 = port->usb4; 319 + const struct tb_margining *margining = s->private; 514 320 515 - if (usb4->margining->software) 321 + if (margining->software) 516 322 return -EINVAL; 517 - ber_level_show(s, usb4->margining->ber_level); 323 + ber_level_show(s, margining->ber_level); 518 324 return 0; 519 325 } 520 326 DEBUGFS_ATTR_RW(margining_ber_level); 521 327 522 328 static int margining_caps_show(struct seq_file *s, void *not_used) 523 329 { 524 - struct tb_port *port = s->private; 525 - struct usb4_port *usb4 = port->usb4; 526 - struct tb *tb = port->sw->tb; 330 + struct tb_margining *margining = s->private; 331 + struct tb *tb = margining->port->sw->tb; 527 332 u32 cap0, cap1; 528 333 529 334 if (mutex_lock_interruptible(&tb->lock)) 530 335 return -ERESTARTSYS; 531 336 532 337 /* Dump the raw caps first */ 533 - cap0 = usb4->margining->caps[0]; 338 + cap0 = margining->caps[0]; 534 339 seq_printf(s, "0x%08x\n", cap0); 535 - cap1 = usb4->margining->caps[1]; 340 + cap1 = margining->caps[1]; 536 341 seq_printf(s, "0x%08x\n", cap1); 537 342 538 343 seq_printf(s, "# software margining: %s\n", 539 - supports_software(usb4) ? "yes" : "no"); 540 - if (supports_hardware(usb4)) { 344 + supports_software(margining) ? "yes" : "no"); 345 + if (supports_hardware(margining)) { 541 346 seq_puts(s, "# hardware margining: yes\n"); 542 347 seq_puts(s, "# minimum BER level contour: "); 543 - ber_level_show(s, usb4->margining->min_ber_level); 348 + ber_level_show(s, margining->min_ber_level); 544 349 seq_puts(s, "# maximum BER level contour: "); 545 - ber_level_show(s, usb4->margining->max_ber_level); 350 + ber_level_show(s, margining->max_ber_level); 546 351 } else { 547 352 seq_puts(s, "# hardware margining: no\n"); 548 353 } 549 354 550 355 seq_printf(s, "# both lanes simultaneously: %s\n", 551 - both_lanes(usb4) ? "yes" : "no"); 356 + both_lanes(margining) ? "yes" : "no"); 552 357 seq_printf(s, "# voltage margin steps: %u\n", 553 - usb4->margining->voltage_steps); 358 + margining->voltage_steps); 554 359 seq_printf(s, "# maximum voltage offset: %u mV\n", 555 - usb4->margining->max_voltage_offset); 360 + margining->max_voltage_offset); 556 361 557 - switch (independent_voltage_margins(usb4)) { 362 + switch (independent_voltage_margins(margining)) { 558 363 case USB4_MARGIN_CAP_0_VOLTAGE_MIN: 559 364 seq_puts(s, "# returns minimum between high and low voltage margins\n"); 560 365 break; ··· 564 373 break; 565 374 } 566 375 567 - if (supports_time(usb4)) { 376 + if (supports_time(margining)) { 568 377 seq_puts(s, "# time margining: yes\n"); 569 378 seq_printf(s, "# time margining is destructive: %s\n", 570 379 cap1 & USB4_MARGIN_CAP_1_TIME_DESTR ? "yes" : "no"); 571 380 572 - switch (independent_time_margins(usb4)) { 381 + switch (independent_time_margins(margining)) { 573 382 case USB4_MARGIN_CAP_1_TIME_MIN: 574 383 seq_puts(s, "# returns minimum between left and right time margins\n"); 575 384 break; ··· 582 391 } 583 392 584 393 seq_printf(s, "# time margin steps: %u\n", 585 - usb4->margining->time_steps); 394 + margining->time_steps); 586 395 seq_printf(s, "# maximum time offset: %u mUI\n", 587 - usb4->margining->max_time_offset); 396 + margining->max_time_offset); 588 397 } else { 589 398 seq_puts(s, "# time margining: no\n"); 590 399 } ··· 599 408 size_t count, loff_t *ppos) 600 409 { 601 410 struct seq_file *s = file->private_data; 602 - struct tb_port *port = s->private; 603 - struct usb4_port *usb4 = port->usb4; 604 - struct tb *tb = port->sw->tb; 411 + struct tb_margining *margining = s->private; 412 + struct tb *tb = margining->port->sw->tb; 605 413 int ret = 0; 606 414 char *buf; 607 415 ··· 616 426 } 617 427 618 428 if (!strcmp(buf, "0")) { 619 - usb4->margining->lanes = 0; 429 + margining->lanes = 0; 620 430 } else if (!strcmp(buf, "1")) { 621 - usb4->margining->lanes = 1; 431 + margining->lanes = 1; 622 432 } else if (!strcmp(buf, "all")) { 623 433 /* Needs to be supported */ 624 - if (both_lanes(usb4)) 625 - usb4->margining->lanes = 7; 434 + if (both_lanes(margining)) 435 + margining->lanes = 7; 626 436 else 627 437 ret = -EINVAL; 628 438 } else { ··· 638 448 639 449 static int margining_lanes_show(struct seq_file *s, void *not_used) 640 450 { 641 - struct tb_port *port = s->private; 642 - struct usb4_port *usb4 = port->usb4; 643 - struct tb *tb = port->sw->tb; 451 + struct tb_margining *margining = s->private; 452 + struct tb *tb = margining->port->sw->tb; 644 453 unsigned int lanes; 645 454 646 455 if (mutex_lock_interruptible(&tb->lock)) 647 456 return -ERESTARTSYS; 648 457 649 - lanes = usb4->margining->lanes; 650 - if (both_lanes(usb4)) { 458 + lanes = margining->lanes; 459 + if (both_lanes(margining)) { 651 460 if (!lanes) 652 461 seq_puts(s, "[0] 1 all\n"); 653 462 else if (lanes == 1) ··· 670 481 size_t count, loff_t *ppos) 671 482 { 672 483 struct seq_file *s = file->private_data; 673 - struct tb_port *port = s->private; 674 - struct usb4_port *usb4 = port->usb4; 675 - struct tb *tb = port->sw->tb; 484 + struct tb_margining *margining = s->private; 485 + struct tb *tb = margining->port->sw->tb; 676 486 int ret = 0; 677 487 char *buf; 678 488 ··· 687 499 } 688 500 689 501 if (!strcmp(buf, "software")) { 690 - if (supports_software(usb4)) 691 - usb4->margining->software = true; 502 + if (supports_software(margining)) 503 + margining->software = true; 692 504 else 693 505 ret = -EINVAL; 694 506 } else if (!strcmp(buf, "hardware")) { 695 - if (supports_hardware(usb4)) 696 - usb4->margining->software = false; 507 + if (supports_hardware(margining)) 508 + margining->software = false; 697 509 else 698 510 ret = -EINVAL; 699 511 } else { ··· 709 521 710 522 static int margining_mode_show(struct seq_file *s, void *not_used) 711 523 { 712 - const struct tb_port *port = s->private; 713 - const struct usb4_port *usb4 = port->usb4; 714 - struct tb *tb = port->sw->tb; 524 + struct tb_margining *margining = s->private; 525 + struct tb *tb = margining->port->sw->tb; 715 526 const char *space = ""; 716 527 717 528 if (mutex_lock_interruptible(&tb->lock)) 718 529 return -ERESTARTSYS; 719 530 720 - if (supports_software(usb4)) { 721 - if (usb4->margining->software) 531 + if (supports_software(margining)) { 532 + if (margining->software) 722 533 seq_puts(s, "[software]"); 723 534 else 724 535 seq_puts(s, "software"); 725 536 space = " "; 726 537 } 727 - if (supports_hardware(usb4)) { 728 - if (usb4->margining->software) 538 + if (supports_hardware(margining)) { 539 + if (margining->software) 729 540 seq_printf(s, "%shardware", space); 730 541 else 731 542 seq_printf(s, "%s[hardware]", space); ··· 739 552 740 553 static int margining_run_write(void *data, u64 val) 741 554 { 742 - struct tb_port *port = data; 743 - struct usb4_port *usb4 = port->usb4; 555 + struct tb_margining *margining = data; 556 + struct tb_port *port = margining->port; 557 + struct device *dev = margining->dev; 744 558 struct tb_switch *sw = port->sw; 745 - struct tb_margining *margining; 746 559 struct tb_switch *down_sw; 747 560 struct tb *tb = sw->tb; 748 561 int ret, clx; ··· 750 563 if (val != 1) 751 564 return -EINVAL; 752 565 753 - pm_runtime_get_sync(&sw->dev); 566 + pm_runtime_get_sync(dev); 754 567 755 568 if (mutex_lock_interruptible(&tb->lock)) { 756 569 ret = -ERESTARTSYS; ··· 777 590 clx = ret; 778 591 } 779 592 780 - margining = usb4->margining; 781 - 782 593 if (margining->software) { 783 - tb_port_dbg(port, "running software %s lane margining for lanes %u\n", 784 - margining->time ? "time" : "voltage", margining->lanes); 785 - ret = usb4_port_sw_margin(port, margining->lanes, margining->time, 594 + tb_port_dbg(port, 595 + "running software %s lane margining for %s lanes %u\n", 596 + margining->time ? "time" : "voltage", dev_name(dev), 597 + margining->lanes); 598 + ret = usb4_port_sw_margin(port, margining->target, margining->index, 599 + margining->lanes, margining->time, 786 600 margining->right_high, 787 601 USB4_MARGIN_SW_COUNTER_CLEAR); 788 602 if (ret) 789 603 goto out_clx; 790 604 791 - ret = usb4_port_sw_margin_errors(port, &margining->results[0]); 605 + ret = usb4_port_sw_margin_errors(port, margining->target, 606 + margining->index, 607 + &margining->results[0]); 792 608 } else { 793 - tb_port_dbg(port, "running hardware %s lane margining for lanes %u\n", 794 - margining->time ? "time" : "voltage", margining->lanes); 609 + tb_port_dbg(port, 610 + "running hardware %s lane margining for %s lanes %u\n", 611 + margining->time ? "time" : "voltage", dev_name(dev), 612 + margining->lanes); 795 613 /* Clear the results */ 796 614 margining->results[0] = 0; 797 615 margining->results[1] = 0; 798 - ret = usb4_port_hw_margin(port, margining->lanes, 799 - margining->ber_level, margining->time, 800 - margining->right_high, margining->results); 616 + ret = usb4_port_hw_margin(port, margining->target, margining->index, 617 + margining->lanes, margining->ber_level, 618 + margining->time, margining->right_high, 619 + margining->results); 801 620 } 802 621 803 622 out_clx: ··· 812 619 out_unlock: 813 620 mutex_unlock(&tb->lock); 814 621 out_rpm_put: 815 - pm_runtime_mark_last_busy(&sw->dev); 816 - pm_runtime_put_autosuspend(&sw->dev); 622 + pm_runtime_mark_last_busy(dev); 623 + pm_runtime_put_autosuspend(dev); 817 624 818 625 return ret; 819 626 } ··· 825 632 size_t count, loff_t *ppos) 826 633 { 827 634 struct seq_file *s = file->private_data; 828 - struct tb_port *port = s->private; 829 - struct usb4_port *usb4 = port->usb4; 830 - struct tb *tb = port->sw->tb; 635 + struct tb_margining *margining = s->private; 636 + struct tb *tb = margining->port->sw->tb; 831 637 832 638 if (mutex_lock_interruptible(&tb->lock)) 833 639 return -ERESTARTSYS; 834 640 835 641 /* Just clear the results */ 836 - usb4->margining->results[0] = 0; 837 - usb4->margining->results[1] = 0; 642 + margining->results[0] = 0; 643 + margining->results[1] = 0; 838 644 839 645 mutex_unlock(&tb->lock); 840 646 return count; ··· 844 652 { 845 653 unsigned int tmp, voltage; 846 654 847 - tmp = val & USB4_MARGIN_HW_RES_1_MARGIN_MASK; 655 + tmp = FIELD_GET(USB4_MARGIN_HW_RES_1_MARGIN_MASK, val); 848 656 voltage = tmp * margining->max_voltage_offset / margining->voltage_steps; 849 657 seq_printf(s, "%u mV (%u)", voltage, tmp); 850 658 if (val & USB4_MARGIN_HW_RES_1_EXCEEDS) ··· 857 665 { 858 666 unsigned int tmp, interval; 859 667 860 - tmp = val & USB4_MARGIN_HW_RES_1_MARGIN_MASK; 668 + tmp = FIELD_GET(USB4_MARGIN_HW_RES_1_MARGIN_MASK, val); 861 669 interval = tmp * margining->max_time_offset / margining->time_steps; 862 670 seq_printf(s, "%u mUI (%u)", interval, tmp); 863 671 if (val & USB4_MARGIN_HW_RES_1_EXCEEDS) ··· 867 675 868 676 static int margining_results_show(struct seq_file *s, void *not_used) 869 677 { 870 - struct tb_port *port = s->private; 871 - struct usb4_port *usb4 = port->usb4; 872 - struct tb_margining *margining; 873 - struct tb *tb = port->sw->tb; 678 + struct tb_margining *margining = s->private; 679 + struct tb *tb = margining->port->sw->tb; 874 680 875 681 if (mutex_lock_interruptible(&tb->lock)) 876 682 return -ERESTARTSYS; 877 683 878 - margining = usb4->margining; 879 684 /* Dump the raw results first */ 880 685 seq_printf(s, "0x%08x\n", margining->results[0]); 881 686 /* Only the hardware margining has two result dwords */ ··· 934 745 size_t count, loff_t *ppos) 935 746 { 936 747 struct seq_file *s = file->private_data; 937 - struct tb_port *port = s->private; 938 - struct usb4_port *usb4 = port->usb4; 939 - struct tb *tb = port->sw->tb; 748 + struct tb_margining *margining = s->private; 749 + struct tb *tb = margining->port->sw->tb; 940 750 int ret = 0; 941 751 char *buf; 942 752 ··· 950 762 goto out_free; 951 763 } 952 764 953 - if (!strcmp(buf, "time") && supports_time(usb4)) 954 - usb4->margining->time = true; 765 + if (!strcmp(buf, "time") && supports_time(margining)) 766 + margining->time = true; 955 767 else if (!strcmp(buf, "voltage")) 956 - usb4->margining->time = false; 768 + margining->time = false; 957 769 else 958 770 ret = -EINVAL; 959 771 ··· 966 778 967 779 static int margining_test_show(struct seq_file *s, void *not_used) 968 780 { 969 - struct tb_port *port = s->private; 970 - struct usb4_port *usb4 = port->usb4; 971 - struct tb *tb = port->sw->tb; 781 + struct tb_margining *margining = s->private; 782 + struct tb *tb = margining->port->sw->tb; 972 783 973 784 if (mutex_lock_interruptible(&tb->lock)) 974 785 return -ERESTARTSYS; 975 786 976 - if (supports_time(usb4)) { 977 - if (usb4->margining->time) 787 + if (supports_time(margining)) { 788 + if (margining->time) 978 789 seq_puts(s, "voltage [time]\n"); 979 790 else 980 791 seq_puts(s, "[voltage] time\n"); ··· 991 804 size_t count, loff_t *ppos) 992 805 { 993 806 struct seq_file *s = file->private_data; 994 - struct tb_port *port = s->private; 995 - struct usb4_port *usb4 = port->usb4; 996 - struct tb *tb = port->sw->tb; 807 + struct tb_margining *margining = s->private; 808 + struct tb *tb = margining->port->sw->tb; 997 809 int ret = 0; 998 810 char *buf; 999 811 ··· 1007 821 goto out_free; 1008 822 } 1009 823 1010 - if (usb4->margining->time) { 824 + if (margining->time) { 1011 825 if (!strcmp(buf, "left")) 1012 - usb4->margining->right_high = false; 826 + margining->right_high = false; 1013 827 else if (!strcmp(buf, "right")) 1014 - usb4->margining->right_high = true; 828 + margining->right_high = true; 1015 829 else 1016 830 ret = -EINVAL; 1017 831 } else { 1018 832 if (!strcmp(buf, "low")) 1019 - usb4->margining->right_high = false; 833 + margining->right_high = false; 1020 834 else if (!strcmp(buf, "high")) 1021 - usb4->margining->right_high = true; 835 + margining->right_high = true; 1022 836 else 1023 837 ret = -EINVAL; 1024 838 } ··· 1032 846 1033 847 static int margining_margin_show(struct seq_file *s, void *not_used) 1034 848 { 1035 - struct tb_port *port = s->private; 1036 - struct usb4_port *usb4 = port->usb4; 1037 - struct tb *tb = port->sw->tb; 849 + struct tb_margining *margining = s->private; 850 + struct tb *tb = margining->port->sw->tb; 1038 851 1039 852 if (mutex_lock_interruptible(&tb->lock)) 1040 853 return -ERESTARTSYS; 1041 854 1042 - if (usb4->margining->time) { 1043 - if (usb4->margining->right_high) 855 + if (margining->time) { 856 + if (margining->right_high) 1044 857 seq_puts(s, "left [right]\n"); 1045 858 else 1046 859 seq_puts(s, "[left] right\n"); 1047 860 } else { 1048 - if (usb4->margining->right_high) 861 + if (margining->right_high) 1049 862 seq_puts(s, "low [high]\n"); 1050 863 else 1051 864 seq_puts(s, "[low] high\n"); ··· 1055 870 } 1056 871 DEBUGFS_ATTR_RW(margining_margin); 1057 872 1058 - static void margining_port_init(struct tb_port *port) 873 + static struct tb_margining *margining_alloc(struct tb_port *port, 874 + struct device *dev, 875 + enum usb4_sb_target target, 876 + u8 index, struct dentry *parent) 1059 877 { 1060 878 struct tb_margining *margining; 1061 - struct dentry *dir, *parent; 1062 - struct usb4_port *usb4; 1063 - char dir_name[10]; 879 + struct dentry *dir; 1064 880 unsigned int val; 1065 881 int ret; 1066 882 1067 - usb4 = port->usb4; 1068 - if (!usb4) 1069 - return; 1070 - 1071 - snprintf(dir_name, sizeof(dir_name), "port%d", port->port); 1072 - parent = debugfs_lookup(dir_name, port->sw->debugfs_dir); 1073 - 1074 883 margining = kzalloc(sizeof(*margining), GFP_KERNEL); 1075 884 if (!margining) 1076 - return; 885 + return NULL; 1077 886 1078 - ret = usb4_port_margining_caps(port, margining->caps); 887 + margining->port = port; 888 + margining->target = target; 889 + margining->index = index; 890 + margining->dev = dev; 891 + 892 + ret = usb4_port_margining_caps(port, target, index, margining->caps); 1079 893 if (ret) { 1080 894 kfree(margining); 1081 - return; 895 + return NULL; 1082 896 } 1083 897 1084 - usb4->margining = margining; 1085 - 1086 898 /* Set the initial mode */ 1087 - if (supports_software(usb4)) 899 + if (supports_software(margining)) 1088 900 margining->software = true; 1089 901 1090 - val = (margining->caps[0] & USB4_MARGIN_CAP_0_VOLTAGE_STEPS_MASK) >> 1091 - USB4_MARGIN_CAP_0_VOLTAGE_STEPS_SHIFT; 902 + val = FIELD_GET(USB4_MARGIN_CAP_0_VOLTAGE_STEPS_MASK, margining->caps[0]); 1092 903 margining->voltage_steps = val; 1093 - val = (margining->caps[0] & USB4_MARGIN_CAP_0_MAX_VOLTAGE_OFFSET_MASK) >> 1094 - USB4_MARGIN_CAP_0_MAX_VOLTAGE_OFFSET_SHIFT; 904 + val = FIELD_GET(USB4_MARGIN_CAP_0_MAX_VOLTAGE_OFFSET_MASK, margining->caps[0]); 1095 905 margining->max_voltage_offset = 74 + val * 2; 1096 906 1097 - if (supports_time(usb4)) { 1098 - val = (margining->caps[1] & USB4_MARGIN_CAP_1_TIME_STEPS_MASK) >> 1099 - USB4_MARGIN_CAP_1_TIME_STEPS_SHIFT; 907 + if (supports_time(margining)) { 908 + val = FIELD_GET(USB4_MARGIN_CAP_1_TIME_STEPS_MASK, margining->caps[1]); 1100 909 margining->time_steps = val; 1101 - val = (margining->caps[1] & USB4_MARGIN_CAP_1_TIME_OFFSET_MASK) >> 1102 - USB4_MARGIN_CAP_1_TIME_OFFSET_SHIFT; 910 + val = FIELD_GET(USB4_MARGIN_CAP_1_TIME_OFFSET_MASK, margining->caps[1]); 1103 911 /* 1104 912 * Store it as mUI (milli Unit Interval) because we want 1105 913 * to keep it as integer. ··· 1101 923 } 1102 924 1103 925 dir = debugfs_create_dir("margining", parent); 1104 - if (supports_hardware(usb4)) { 1105 - val = (margining->caps[1] & USB4_MARGIN_CAP_1_MIN_BER_MASK) >> 1106 - USB4_MARGIN_CAP_1_MIN_BER_SHIFT; 926 + if (supports_hardware(margining)) { 927 + val = FIELD_GET(USB4_MARGIN_CAP_1_MIN_BER_MASK, margining->caps[1]); 1107 928 margining->min_ber_level = val; 1108 - val = (margining->caps[1] & USB4_MARGIN_CAP_1_MAX_BER_MASK) >> 1109 - USB4_MARGIN_CAP_1_MAX_BER_SHIFT; 929 + val = FIELD_GET(USB4_MARGIN_CAP_1_MAX_BER_MASK, margining->caps[1]); 1110 930 margining->max_ber_level = val; 1111 931 1112 932 /* Set the default to minimum */ 1113 933 margining->ber_level = margining->min_ber_level; 1114 934 1115 - debugfs_create_file("ber_level_contour", 0400, dir, port, 935 + debugfs_create_file("ber_level_contour", 0400, dir, margining, 1116 936 &margining_ber_level_fops); 1117 937 } 1118 - debugfs_create_file("caps", 0400, dir, port, &margining_caps_fops); 1119 - debugfs_create_file("lanes", 0600, dir, port, &margining_lanes_fops); 1120 - debugfs_create_file("mode", 0600, dir, port, &margining_mode_fops); 1121 - debugfs_create_file("run", 0600, dir, port, &margining_run_fops); 1122 - debugfs_create_file("results", 0600, dir, port, &margining_results_fops); 1123 - debugfs_create_file("test", 0600, dir, port, &margining_test_fops); 1124 - if (independent_voltage_margins(usb4) == USB4_MARGIN_CAP_0_VOLTAGE_HL || 1125 - (supports_time(usb4) && 1126 - independent_time_margins(usb4) == USB4_MARGIN_CAP_1_TIME_LR)) 1127 - debugfs_create_file("margin", 0600, dir, port, &margining_margin_fops); 938 + debugfs_create_file("caps", 0400, dir, margining, &margining_caps_fops); 939 + debugfs_create_file("lanes", 0600, dir, margining, &margining_lanes_fops); 940 + debugfs_create_file("mode", 0600, dir, margining, &margining_mode_fops); 941 + debugfs_create_file("run", 0600, dir, margining, &margining_run_fops); 942 + debugfs_create_file("results", 0600, dir, margining, 943 + &margining_results_fops); 944 + debugfs_create_file("test", 0600, dir, margining, &margining_test_fops); 945 + if (independent_voltage_margins(margining) == USB4_MARGIN_CAP_0_VOLTAGE_HL || 946 + (supports_time(margining) && 947 + independent_time_margins(margining) == USB4_MARGIN_CAP_1_TIME_LR)) 948 + debugfs_create_file("margin", 0600, dir, margining, 949 + &margining_margin_fops); 950 + return margining; 951 + } 952 + 953 + static void margining_port_init(struct tb_port *port) 954 + { 955 + struct dentry *parent; 956 + char dir_name[10]; 957 + 958 + if (!port->usb4) 959 + return; 960 + 961 + snprintf(dir_name, sizeof(dir_name), "port%d", port->port); 962 + parent = debugfs_lookup(dir_name, port->sw->debugfs_dir); 963 + port->usb4->margining = margining_alloc(port, &port->usb4->dev, 964 + USB4_SB_TARGET_ROUTER, 0, 965 + parent); 1128 966 } 1129 967 1130 968 static void margining_port_remove(struct tb_port *port) ··· 1214 1020 downstream = tb_port_at(xd->route, parent_sw); 1215 1021 margining_port_remove(downstream); 1216 1022 } 1023 + 1024 + static void margining_retimer_init(struct tb_retimer *rt, struct dentry *debugfs_dir) 1025 + { 1026 + rt->margining = margining_alloc(rt->port, &rt->dev, 1027 + USB4_SB_TARGET_RETIMER, rt->index, 1028 + debugfs_dir); 1029 + } 1030 + 1031 + static void margining_retimer_remove(struct tb_retimer *rt) 1032 + { 1033 + kfree(rt->margining); 1034 + rt->margining = NULL; 1035 + } 1217 1036 #else 1218 1037 static inline void margining_switch_init(struct tb_switch *sw) { } 1219 1038 static inline void margining_switch_remove(struct tb_switch *sw) { } 1220 1039 static inline void margining_xdomain_init(struct tb_xdomain *xd) { } 1221 1040 static inline void margining_xdomain_remove(struct tb_xdomain *xd) { } 1041 + static inline void margining_retimer_init(struct tb_retimer *rt, 1042 + struct dentry *debugfs_dir) { } 1043 + static inline void margining_retimer_remove(struct tb_retimer *rt) { } 1222 1044 #endif 1223 1045 1224 1046 static int port_clear_all_counters(struct tb_port *port) ··· 1715 1505 } 1716 1506 DEBUGFS_ATTR_RW(counters); 1717 1507 1508 + static int sb_regs_show(struct tb_port *port, const struct sb_reg *sb_regs, 1509 + size_t size, enum usb4_sb_target target, u8 index, 1510 + struct seq_file *s) 1511 + { 1512 + int ret, i; 1513 + 1514 + seq_puts(s, "# register value\n"); 1515 + 1516 + for (i = 0; i < size; i++) { 1517 + const struct sb_reg *regs = &sb_regs[i]; 1518 + u8 data[64]; 1519 + int j; 1520 + 1521 + memset(data, 0, sizeof(data)); 1522 + ret = usb4_port_sb_read(port, target, index, regs->reg, data, 1523 + regs->size); 1524 + if (ret) 1525 + return ret; 1526 + 1527 + seq_printf(s, "0x%02x", regs->reg); 1528 + for (j = 0; j < regs->size; j++) 1529 + seq_printf(s, " 0x%02x", data[j]); 1530 + seq_puts(s, "\n"); 1531 + } 1532 + 1533 + return 0; 1534 + } 1535 + 1536 + static int port_sb_regs_show(struct seq_file *s, void *not_used) 1537 + { 1538 + struct tb_port *port = s->private; 1539 + struct tb_switch *sw = port->sw; 1540 + struct tb *tb = sw->tb; 1541 + int ret; 1542 + 1543 + pm_runtime_get_sync(&sw->dev); 1544 + 1545 + if (mutex_lock_interruptible(&tb->lock)) { 1546 + ret = -ERESTARTSYS; 1547 + goto out_rpm_put; 1548 + } 1549 + 1550 + ret = sb_regs_show(port, port_sb_regs, ARRAY_SIZE(port_sb_regs), 1551 + USB4_SB_TARGET_ROUTER, 0, s); 1552 + 1553 + mutex_unlock(&tb->lock); 1554 + out_rpm_put: 1555 + pm_runtime_mark_last_busy(&sw->dev); 1556 + pm_runtime_put_autosuspend(&sw->dev); 1557 + 1558 + return ret; 1559 + } 1560 + DEBUGFS_ATTR_RW(port_sb_regs); 1561 + 1718 1562 /** 1719 1563 * tb_switch_debugfs_init() - Add debugfs entries for router 1720 1564 * @sw: Pointer to the router ··· 1803 1539 if (port->config.counters_support) 1804 1540 debugfs_create_file("counters", 0600, debugfs_dir, port, 1805 1541 &counters_fops); 1542 + if (port->usb4) 1543 + debugfs_create_file("sb_regs", DEBUGFS_MODE, debugfs_dir, 1544 + port, &port_sb_regs_fops); 1806 1545 } 1807 1546 1808 1547 margining_switch_init(sw); ··· 1855 1588 { 1856 1589 debugfs_remove_recursive(svc->debugfs_dir); 1857 1590 svc->debugfs_dir = NULL; 1591 + } 1592 + 1593 + static int retimer_sb_regs_show(struct seq_file *s, void *not_used) 1594 + { 1595 + struct tb_retimer *rt = s->private; 1596 + struct tb *tb = rt->tb; 1597 + int ret; 1598 + 1599 + pm_runtime_get_sync(&rt->dev); 1600 + 1601 + if (mutex_lock_interruptible(&tb->lock)) { 1602 + ret = -ERESTARTSYS; 1603 + goto out_rpm_put; 1604 + } 1605 + 1606 + ret = sb_regs_show(rt->port, retimer_sb_regs, ARRAY_SIZE(retimer_sb_regs), 1607 + USB4_SB_TARGET_RETIMER, rt->index, s); 1608 + 1609 + mutex_unlock(&tb->lock); 1610 + out_rpm_put: 1611 + pm_runtime_mark_last_busy(&rt->dev); 1612 + pm_runtime_put_autosuspend(&rt->dev); 1613 + 1614 + return ret; 1615 + } 1616 + DEBUGFS_ATTR_RW(retimer_sb_regs); 1617 + 1618 + /** 1619 + * tb_retimer_debugfs_init() - Add debugfs directory for retimer 1620 + * @rt: Pointer to retimer structure 1621 + * 1622 + * Adds and populates retimer debugfs directory. 1623 + */ 1624 + void tb_retimer_debugfs_init(struct tb_retimer *rt) 1625 + { 1626 + struct dentry *debugfs_dir; 1627 + 1628 + debugfs_dir = debugfs_create_dir(dev_name(&rt->dev), tb_debugfs_root); 1629 + debugfs_create_file("sb_regs", DEBUGFS_MODE, debugfs_dir, rt, 1630 + &retimer_sb_regs_fops); 1631 + margining_retimer_init(rt, debugfs_dir); 1632 + } 1633 + 1634 + /** 1635 + * tb_retimer_debugfs_remove() - Remove retimer debugfs directory 1636 + * @rt: Pointer to retimer structure 1637 + * 1638 + * Removes the retimer debugfs directory along with its contents. 1639 + */ 1640 + void tb_retimer_debugfs_remove(struct tb_retimer *rt) 1641 + { 1642 + debugfs_lookup_and_remove(dev_name(&rt->dev), tb_debugfs_root); 1643 + margining_retimer_remove(rt); 1858 1644 } 1859 1645 1860 1646 void tb_debugfs_init(void)
+32 -21
drivers/thunderbolt/retimer.c
··· 14 14 #include "sb_regs.h" 15 15 #include "tb.h" 16 16 17 + #if IS_ENABLED(CONFIG_USB4_DEBUGFS_MARGINING) 17 18 #define TB_MAX_RETIMER_INDEX 6 19 + #else 20 + #define TB_MAX_RETIMER_INDEX 2 21 + #endif 18 22 19 23 /** 20 24 * tb_retimer_nvm_read() - Read contents of retimer NVM ··· 323 319 324 320 if (!rt->nvm) 325 321 ret = -EAGAIN; 322 + else if (rt->no_nvm_upgrade) 323 + ret = -EOPNOTSUPP; 326 324 else 327 325 ret = sysfs_emit(buf, "%x.%x\n", rt->nvm->major, rt->nvm->minor); 328 326 ··· 372 366 .release = tb_retimer_release, 373 367 }; 374 368 375 - static int tb_retimer_add(struct tb_port *port, u8 index, u32 auth_status) 369 + static int tb_retimer_add(struct tb_port *port, u8 index, u32 auth_status, 370 + bool on_board) 376 371 { 377 372 struct tb_retimer *rt; 378 373 u32 vendor, device; 379 374 int ret; 380 375 381 - ret = usb4_port_retimer_read(port, index, USB4_SB_VENDOR_ID, &vendor, 382 - sizeof(vendor)); 376 + ret = usb4_port_sb_read(port, USB4_SB_TARGET_RETIMER, index, 377 + USB4_SB_VENDOR_ID, &vendor, sizeof(vendor)); 383 378 if (ret) { 384 379 if (ret != -ENODEV) 385 380 tb_port_warn(port, "failed read retimer VendorId: %d\n", ret); 386 381 return ret; 387 382 } 388 383 389 - ret = usb4_port_retimer_read(port, index, USB4_SB_PRODUCT_ID, &device, 390 - sizeof(device)); 384 + ret = usb4_port_sb_read(port, USB4_SB_TARGET_RETIMER, index, 385 + USB4_SB_PRODUCT_ID, &device, sizeof(device)); 391 386 if (ret) { 392 387 if (ret != -ENODEV) 393 388 tb_port_warn(port, "failed read retimer ProductId: %d\n", ret); 394 389 return ret; 395 390 } 396 391 397 - /* 398 - * Check that it supports NVM operations. If not then don't add 399 - * the device at all. 400 - */ 401 - ret = usb4_port_retimer_nvm_sector_size(port, index); 402 - if (ret < 0) 403 - return ret; 404 392 405 393 rt = kzalloc(sizeof(*rt), GFP_KERNEL); 406 394 if (!rt) ··· 406 406 rt->auth_status = auth_status; 407 407 rt->port = port; 408 408 rt->tb = port->sw->tb; 409 + 410 + /* 411 + * Only support NVM upgrade for on-board retimers. The retimers 412 + * on the other side of the connection. 413 + */ 414 + if (!on_board || usb4_port_retimer_nvm_sector_size(port, index) <= 0) 415 + rt->no_nvm_upgrade = true; 409 416 410 417 rt->dev.parent = &port->usb4->dev; 411 418 rt->dev.bus = &tb_bus_type; ··· 444 437 pm_runtime_mark_last_busy(&rt->dev); 445 438 pm_runtime_use_autosuspend(&rt->dev); 446 439 440 + tb_retimer_debugfs_init(rt); 447 441 return 0; 448 442 } 449 443 450 444 static void tb_retimer_remove(struct tb_retimer *rt) 451 445 { 452 446 dev_info(&rt->dev, "retimer disconnected\n"); 447 + tb_retimer_debugfs_remove(rt); 453 448 tb_nvm_free(rt->nvm); 454 449 device_unregister(&rt->dev); 455 450 } ··· 494 485 int tb_retimer_scan(struct tb_port *port, bool add) 495 486 { 496 487 u32 status[TB_MAX_RETIMER_INDEX + 1] = {}; 497 - int ret, i, last_idx = 0; 488 + int ret, i, max, last_idx = 0; 498 489 499 490 /* 500 491 * Send broadcast RT to make sure retimer indices facing this ··· 529 520 break; 530 521 } 531 522 532 - tb_retimer_unset_inbound_sbtx(port); 533 - 534 - if (!last_idx) 535 - return 0; 536 - 537 - /* Add on-board retimers if they do not exist already */ 523 + max = i; 538 524 ret = 0; 539 - for (i = 1; i <= last_idx; i++) { 525 + 526 + /* Add retimers if they do not exist already */ 527 + for (i = 1; i <= max; i++) { 540 528 struct tb_retimer *rt; 529 + 530 + /* Skip cable retimers */ 531 + if (usb4_port_retimer_is_cable(port, i)) 532 + continue; 541 533 542 534 rt = tb_port_find_retimer(port, i); 543 535 if (rt) { 544 536 put_device(&rt->dev); 545 537 } else if (add) { 546 - ret = tb_retimer_add(port, i, status[i]); 538 + ret = tb_retimer_add(port, i, status[i], i <= last_idx); 547 539 if (ret && ret != -EOPNOTSUPP) 548 540 break; 549 541 } 550 542 } 551 543 544 + tb_retimer_unset_inbound_sbtx(port); 552 545 return ret; 553 546 } 554 547
+9 -9
drivers/thunderbolt/sb_regs.h
··· 12 12 13 13 #define USB4_SB_VENDOR_ID 0x00 14 14 #define USB4_SB_PRODUCT_ID 0x01 15 + #define USB4_SB_FW_VERSION 0x02 16 + #define USB4_SB_DEBUG_CONF 0x05 17 + #define USB4_SB_DEBUG 0x06 18 + #define USB4_SB_LRD_TUNING 0x07 15 19 #define USB4_SB_OPCODE 0x08 16 20 17 21 enum usb4_sb_opcode { ··· 26 22 USB4_SB_OPCODE_SET_INBOUND_SBTX = 0x5055534c, /* "LSUP" */ 27 23 USB4_SB_OPCODE_UNSET_INBOUND_SBTX = 0x50555355, /* "USUP" */ 28 24 USB4_SB_OPCODE_QUERY_LAST_RETIMER = 0x5453414c, /* "LAST" */ 25 + USB4_SB_OPCODE_QUERY_CABLE_RETIMER = 0x524c4243, /* "CBLR" */ 29 26 USB4_SB_OPCODE_GET_NVM_SECTOR_SIZE = 0x53534e47, /* "GNSS" */ 30 27 USB4_SB_OPCODE_NVM_SET_OFFSET = 0x53504f42, /* "BOPS" */ 31 28 USB4_SB_OPCODE_NVM_BLOCK_WRITE = 0x574b4c42, /* "BLKW" */ ··· 40 35 41 36 #define USB4_SB_METADATA 0x09 42 37 #define USB4_SB_METADATA_NVM_AUTH_WRITE_MASK GENMASK(5, 0) 38 + #define USB4_SB_LINK_CONF 0x0c 39 + #define USB4_SB_GEN23_TXFFE 0x0d 40 + #define USB4_SB_GEN4_TXFFE 0x0e 41 + #define USB4_SB_VERSION 0x0f 43 42 #define USB4_SB_DATA 0x12 44 43 45 44 /* USB4_SB_OPCODE_READ_LANE_MARGINING_CAP */ ··· 51 42 #define USB4_MARGIN_CAP_0_MODES_SW BIT(1) 52 43 #define USB4_MARGIN_CAP_0_2_LANES BIT(2) 53 44 #define USB4_MARGIN_CAP_0_VOLTAGE_INDP_MASK GENMASK(4, 3) 54 - #define USB4_MARGIN_CAP_0_VOLTAGE_INDP_SHIFT 3 55 45 #define USB4_MARGIN_CAP_0_VOLTAGE_MIN 0x0 56 46 #define USB4_MARGIN_CAP_0_VOLTAGE_HL 0x1 57 47 #define USB4_MARGIN_CAP_0_VOLTAGE_BOTH 0x2 58 48 #define USB4_MARGIN_CAP_0_TIME BIT(5) 59 49 #define USB4_MARGIN_CAP_0_VOLTAGE_STEPS_MASK GENMASK(12, 6) 60 - #define USB4_MARGIN_CAP_0_VOLTAGE_STEPS_SHIFT 6 61 50 #define USB4_MARGIN_CAP_0_MAX_VOLTAGE_OFFSET_MASK GENMASK(18, 13) 62 - #define USB4_MARGIN_CAP_0_MAX_VOLTAGE_OFFSET_SHIFT 13 63 51 #define USB4_MARGIN_CAP_1_TIME_DESTR BIT(8) 64 52 #define USB4_MARGIN_CAP_1_TIME_INDP_MASK GENMASK(10, 9) 65 - #define USB4_MARGIN_CAP_1_TIME_INDP_SHIFT 9 66 53 #define USB4_MARGIN_CAP_1_TIME_MIN 0x0 67 54 #define USB4_MARGIN_CAP_1_TIME_LR 0x1 68 55 #define USB4_MARGIN_CAP_1_TIME_BOTH 0x2 69 56 #define USB4_MARGIN_CAP_1_TIME_STEPS_MASK GENMASK(15, 11) 70 - #define USB4_MARGIN_CAP_1_TIME_STEPS_SHIFT 11 71 57 #define USB4_MARGIN_CAP_1_TIME_OFFSET_MASK GENMASK(20, 16) 72 - #define USB4_MARGIN_CAP_1_TIME_OFFSET_SHIFT 16 73 58 #define USB4_MARGIN_CAP_1_MIN_BER_MASK GENMASK(25, 21) 74 - #define USB4_MARGIN_CAP_1_MIN_BER_SHIFT 21 75 59 #define USB4_MARGIN_CAP_1_MAX_BER_MASK GENMASK(30, 26) 76 - #define USB4_MARGIN_CAP_1_MAX_BER_SHIFT 26 77 - #define USB4_MARGIN_CAP_1_MAX_BER_SHIFT 26 78 60 79 61 /* USB4_SB_OPCODE_RUN_HW_LANE_MARGINING */ 80 62 #define USB4_MARGIN_HW_TIME BIT(3)
+35 -10
drivers/thunderbolt/tb.h
··· 329 329 * @nvm: Pointer to the NVM if the retimer has one (%NULL otherwise) 330 330 * @no_nvm_upgrade: Prevent NVM upgrade of this retimer 331 331 * @auth_status: Status of last NVM authentication 332 + * @margining: Pointer to margining structure if enabled 332 333 */ 333 334 struct tb_retimer { 334 335 struct device dev; ··· 341 340 struct tb_nvm *nvm; 342 341 bool no_nvm_upgrade; 343 342 u32 auth_status; 343 + #ifdef CONFIG_USB4_DEBUGFS_MARGINING 344 + struct tb_margining *margining; 345 + #endif 344 346 }; 345 347 346 348 /** ··· 1331 1327 int usb4_port_router_online(struct tb_port *port); 1332 1328 int usb4_port_enumerate_retimers(struct tb_port *port); 1333 1329 bool usb4_port_clx_supported(struct tb_port *port); 1334 - int usb4_port_margining_caps(struct tb_port *port, u32 *caps); 1335 1330 1336 1331 bool usb4_port_asym_supported(struct tb_port *port); 1337 1332 int usb4_port_asym_set_link_width(struct tb_port *port, enum tb_link_width width); 1338 1333 int usb4_port_asym_start(struct tb_port *port); 1339 1334 1340 - int usb4_port_hw_margin(struct tb_port *port, unsigned int lanes, 1341 - unsigned int ber_level, bool timing, bool right_high, 1342 - u32 *results); 1343 - int usb4_port_sw_margin(struct tb_port *port, unsigned int lanes, bool timing, 1335 + /** 1336 + * enum tb_sb_target - Sideband transaction target 1337 + * @USB4_SB_TARGET_ROUTER: Target is the router itself 1338 + * @USB4_SB_TARGET_PARTNER: Target is partner 1339 + * @USB4_SB_TARGET_RETIMER: Target is retimer 1340 + */ 1341 + enum usb4_sb_target { 1342 + USB4_SB_TARGET_ROUTER, 1343 + USB4_SB_TARGET_PARTNER, 1344 + USB4_SB_TARGET_RETIMER, 1345 + }; 1346 + 1347 + int usb4_port_sb_read(struct tb_port *port, enum usb4_sb_target target, u8 index, 1348 + u8 reg, void *buf, u8 size); 1349 + int usb4_port_sb_write(struct tb_port *port, enum usb4_sb_target target, 1350 + u8 index, u8 reg, const void *buf, u8 size); 1351 + 1352 + int usb4_port_margining_caps(struct tb_port *port, enum usb4_sb_target target, 1353 + u8 index, u32 *caps); 1354 + int usb4_port_hw_margin(struct tb_port *port, enum usb4_sb_target target, 1355 + u8 index, unsigned int lanes, unsigned int ber_level, 1356 + bool timing, bool right_high, u32 *results); 1357 + int usb4_port_sw_margin(struct tb_port *port, enum usb4_sb_target target, 1358 + u8 index, unsigned int lanes, bool timing, 1344 1359 bool right_high, u32 counter); 1345 - int usb4_port_sw_margin_errors(struct tb_port *port, u32 *errors); 1360 + int usb4_port_sw_margin_errors(struct tb_port *port, enum usb4_sb_target target, 1361 + u8 index, u32 *errors); 1346 1362 1347 1363 int usb4_port_retimer_set_inbound_sbtx(struct tb_port *port, u8 index); 1348 1364 int usb4_port_retimer_unset_inbound_sbtx(struct tb_port *port, u8 index); 1349 - int usb4_port_retimer_read(struct tb_port *port, u8 index, u8 reg, void *buf, 1350 - u8 size); 1351 - int usb4_port_retimer_write(struct tb_port *port, u8 index, u8 reg, 1352 - const void *buf, u8 size); 1353 1365 int usb4_port_retimer_is_last(struct tb_port *port, u8 index); 1366 + int usb4_port_retimer_is_cable(struct tb_port *port, u8 index); 1354 1367 int usb4_port_retimer_nvm_sector_size(struct tb_port *port, u8 index); 1355 1368 int usb4_port_retimer_nvm_set_offset(struct tb_port *port, u8 index, 1356 1369 unsigned int address); ··· 1466 1445 void tb_xdomain_debugfs_remove(struct tb_xdomain *xd); 1467 1446 void tb_service_debugfs_init(struct tb_service *svc); 1468 1447 void tb_service_debugfs_remove(struct tb_service *svc); 1448 + void tb_retimer_debugfs_init(struct tb_retimer *rt); 1449 + void tb_retimer_debugfs_remove(struct tb_retimer *rt); 1469 1450 #else 1470 1451 static inline void tb_debugfs_init(void) { } 1471 1452 static inline void tb_debugfs_exit(void) { } ··· 1477 1454 static inline void tb_xdomain_debugfs_remove(struct tb_xdomain *xd) { } 1478 1455 static inline void tb_service_debugfs_init(struct tb_service *svc) { } 1479 1456 static inline void tb_service_debugfs_remove(struct tb_service *svc) { } 1457 + static inline void tb_retimer_debugfs_init(struct tb_retimer *rt) { } 1458 + static inline void tb_retimer_debugfs_remove(struct tb_retimer *rt) { } 1480 1459 #endif 1481 1460 1482 1461 #endif
+100 -87
drivers/thunderbolt/usb4.c
··· 17 17 #define USB4_DATA_RETRIES 3 18 18 #define USB4_DATA_DWORDS 16 19 19 20 - enum usb4_sb_target { 21 - USB4_SB_TARGET_ROUTER, 22 - USB4_SB_TARGET_PARTNER, 23 - USB4_SB_TARGET_RETIMER, 24 - }; 25 - 26 20 #define USB4_NVM_READ_OFFSET_MASK GENMASK(23, 2) 27 21 #define USB4_NVM_READ_OFFSET_SHIFT 2 28 22 #define USB4_NVM_READ_LENGTH_MASK GENMASK(27, 24) ··· 1283 1289 dwords); 1284 1290 } 1285 1291 1286 - static int usb4_port_sb_read(struct tb_port *port, enum usb4_sb_target target, 1287 - u8 index, u8 reg, void *buf, u8 size) 1292 + /** 1293 + * usb4_port_sb_read() - Read from sideband register 1294 + * @port: USB4 port to read 1295 + * @target: Sideband target 1296 + * @index: Retimer index if taget is %USB4_SB_TARGET_RETIMER 1297 + * @reg: Sideband register index 1298 + * @buf: Buffer where the sideband data is copied 1299 + * @size: Size of @buf 1300 + * 1301 + * Reads data from sideband register @reg and copies it into @buf. 1302 + * Returns %0 in case of success and negative errno in case of failure. 1303 + */ 1304 + int usb4_port_sb_read(struct tb_port *port, enum usb4_sb_target target, u8 index, 1305 + u8 reg, void *buf, u8 size) 1288 1306 { 1289 1307 size_t dwords = DIV_ROUND_UP(size, 4); 1290 1308 int ret; ··· 1335 1329 return buf ? usb4_port_read_data(port, buf, dwords) : 0; 1336 1330 } 1337 1331 1338 - static int usb4_port_sb_write(struct tb_port *port, enum usb4_sb_target target, 1339 - u8 index, u8 reg, const void *buf, u8 size) 1332 + /** 1333 + * usb4_port_sb_write() - Write to sideband register 1334 + * @port: USB4 port to write 1335 + * @target: Sideband target 1336 + * @index: Retimer index if taget is %USB4_SB_TARGET_RETIMER 1337 + * @reg: Sideband register index 1338 + * @buf: Data to write 1339 + * @size: Size of @buf 1340 + * 1341 + * Writes @buf to sideband register @reg. Returns %0 in case of success 1342 + * and negative errno in case of failure. 1343 + */ 1344 + int usb4_port_sb_write(struct tb_port *port, enum usb4_sb_target target, 1345 + u8 index, u8 reg, const void *buf, u8 size) 1340 1346 { 1341 1347 size_t dwords = DIV_ROUND_UP(size, 4); 1342 1348 int ret; ··· 1628 1610 /** 1629 1611 * usb4_port_margining_caps() - Read USB4 port marginig capabilities 1630 1612 * @port: USB4 port 1613 + * @target: Sideband target 1614 + * @index: Retimer index if taget is %USB4_SB_TARGET_RETIMER 1631 1615 * @caps: Array with at least two elements to hold the results 1632 1616 * 1633 1617 * Reads the USB4 port lane margining capabilities into @caps. 1634 1618 */ 1635 - int usb4_port_margining_caps(struct tb_port *port, u32 *caps) 1619 + int usb4_port_margining_caps(struct tb_port *port, enum usb4_sb_target target, 1620 + u8 index, u32 *caps) 1636 1621 { 1637 1622 int ret; 1638 1623 1639 - ret = usb4_port_sb_op(port, USB4_SB_TARGET_ROUTER, 0, 1624 + ret = usb4_port_sb_op(port, target, index, 1640 1625 USB4_SB_OPCODE_READ_LANE_MARGINING_CAP, 500); 1641 1626 if (ret) 1642 1627 return ret; 1643 1628 1644 - return usb4_port_sb_read(port, USB4_SB_TARGET_ROUTER, 0, 1645 - USB4_SB_DATA, caps, sizeof(*caps) * 2); 1629 + return usb4_port_sb_read(port, target, index, USB4_SB_DATA, caps, 1630 + sizeof(*caps) * 2); 1646 1631 } 1647 1632 1648 1633 /** 1649 1634 * usb4_port_hw_margin() - Run hardware lane margining on port 1650 1635 * @port: USB4 port 1636 + * @target: Sideband target 1637 + * @index: Retimer index if taget is %USB4_SB_TARGET_RETIMER 1651 1638 * @lanes: Which lanes to run (must match the port capabilities). Can be 1652 1639 * %0, %1 or %7. 1653 1640 * @ber_level: BER level contour value ··· 1663 1640 * Runs hardware lane margining on USB4 port and returns the result in 1664 1641 * @results. 1665 1642 */ 1666 - int usb4_port_hw_margin(struct tb_port *port, unsigned int lanes, 1667 - unsigned int ber_level, bool timing, bool right_high, 1668 - u32 *results) 1643 + int usb4_port_hw_margin(struct tb_port *port, enum usb4_sb_target target, 1644 + u8 index, unsigned int lanes, unsigned int ber_level, 1645 + bool timing, bool right_high, u32 *results) 1669 1646 { 1670 1647 u32 val; 1671 1648 int ret; ··· 1679 1656 val |= (ber_level << USB4_MARGIN_HW_BER_SHIFT) & 1680 1657 USB4_MARGIN_HW_BER_MASK; 1681 1658 1682 - ret = usb4_port_sb_write(port, USB4_SB_TARGET_ROUTER, 0, 1683 - USB4_SB_METADATA, &val, sizeof(val)); 1659 + ret = usb4_port_sb_write(port, target, index, USB4_SB_METADATA, &val, 1660 + sizeof(val)); 1684 1661 if (ret) 1685 1662 return ret; 1686 1663 1687 - ret = usb4_port_sb_op(port, USB4_SB_TARGET_ROUTER, 0, 1664 + ret = usb4_port_sb_op(port, target, index, 1688 1665 USB4_SB_OPCODE_RUN_HW_LANE_MARGINING, 2500); 1689 1666 if (ret) 1690 1667 return ret; 1691 1668 1692 - return usb4_port_sb_read(port, USB4_SB_TARGET_ROUTER, 0, 1693 - USB4_SB_DATA, results, sizeof(*results) * 2); 1669 + return usb4_port_sb_read(port, target, index, USB4_SB_DATA, results, 1670 + sizeof(*results) * 2); 1694 1671 } 1695 1672 1696 1673 /** 1697 1674 * usb4_port_sw_margin() - Run software lane margining on port 1698 1675 * @port: USB4 port 1676 + * @target: Sideband target 1677 + * @index: Retimer index if taget is %USB4_SB_TARGET_RETIMER 1699 1678 * @lanes: Which lanes to run (must match the port capabilities). Can be 1700 1679 * %0, %1 or %7. 1701 1680 * @timing: Perform timing margining instead of voltage ··· 1708 1683 * counters by calling usb4_port_sw_margin_errors(). Returns %0 in 1709 1684 * success and negative errno otherwise. 1710 1685 */ 1711 - int usb4_port_sw_margin(struct tb_port *port, unsigned int lanes, bool timing, 1686 + int usb4_port_sw_margin(struct tb_port *port, enum usb4_sb_target target, 1687 + u8 index, unsigned int lanes, bool timing, 1712 1688 bool right_high, u32 counter) 1713 1689 { 1714 1690 u32 val; ··· 1723 1697 val |= (counter << USB4_MARGIN_SW_COUNTER_SHIFT) & 1724 1698 USB4_MARGIN_SW_COUNTER_MASK; 1725 1699 1726 - ret = usb4_port_sb_write(port, USB4_SB_TARGET_ROUTER, 0, 1727 - USB4_SB_METADATA, &val, sizeof(val)); 1700 + ret = usb4_port_sb_write(port, target, index, USB4_SB_METADATA, &val, 1701 + sizeof(val)); 1728 1702 if (ret) 1729 1703 return ret; 1730 1704 1731 - return usb4_port_sb_op(port, USB4_SB_TARGET_ROUTER, 0, 1705 + return usb4_port_sb_op(port, target, index, 1732 1706 USB4_SB_OPCODE_RUN_SW_LANE_MARGINING, 2500); 1733 1707 } 1734 1708 1735 1709 /** 1736 1710 * usb4_port_sw_margin_errors() - Read the software margining error counters 1737 1711 * @port: USB4 port 1712 + * @target: Sideband target 1713 + * @index: Retimer index if taget is %USB4_SB_TARGET_RETIMER 1738 1714 * @errors: Error metadata is copied here. 1739 1715 * 1740 1716 * This reads back the software margining error counters from the port. 1741 1717 * Returns %0 in success and negative errno otherwise. 1742 1718 */ 1743 - int usb4_port_sw_margin_errors(struct tb_port *port, u32 *errors) 1719 + int usb4_port_sw_margin_errors(struct tb_port *port, enum usb4_sb_target target, 1720 + u8 index, u32 *errors) 1744 1721 { 1745 1722 int ret; 1746 1723 1747 - ret = usb4_port_sb_op(port, USB4_SB_TARGET_ROUTER, 0, 1724 + ret = usb4_port_sb_op(port, target, index, 1748 1725 USB4_SB_OPCODE_READ_SW_MARGIN_ERR, 150); 1749 1726 if (ret) 1750 1727 return ret; 1751 1728 1752 - return usb4_port_sb_read(port, USB4_SB_TARGET_ROUTER, 0, 1753 - USB4_SB_METADATA, errors, sizeof(*errors)); 1729 + return usb4_port_sb_read(port, target, index, USB4_SB_METADATA, errors, 1730 + sizeof(*errors)); 1754 1731 } 1755 1732 1756 1733 static inline int usb4_port_retimer_op(struct tb_port *port, u8 index, ··· 1806 1777 } 1807 1778 1808 1779 /** 1809 - * usb4_port_retimer_read() - Read from retimer sideband registers 1810 - * @port: USB4 port 1811 - * @index: Retimer index 1812 - * @reg: Sideband register to read 1813 - * @buf: Data from @reg is stored here 1814 - * @size: Number of bytes to read 1815 - * 1816 - * Function reads retimer sideband registers starting from @reg. The 1817 - * retimer is connected to @port at @index. Returns %0 in case of 1818 - * success, and read data is copied to @buf. If there is no retimer 1819 - * present at given @index returns %-ENODEV. In any other failure 1820 - * returns negative errno. 1821 - */ 1822 - int usb4_port_retimer_read(struct tb_port *port, u8 index, u8 reg, void *buf, 1823 - u8 size) 1824 - { 1825 - return usb4_port_sb_read(port, USB4_SB_TARGET_RETIMER, index, reg, buf, 1826 - size); 1827 - } 1828 - 1829 - /** 1830 - * usb4_port_retimer_write() - Write to retimer sideband registers 1831 - * @port: USB4 port 1832 - * @index: Retimer index 1833 - * @reg: Sideband register to write 1834 - * @buf: Data that is written starting from @reg 1835 - * @size: Number of bytes to write 1836 - * 1837 - * Writes retimer sideband registers starting from @reg. The retimer is 1838 - * connected to @port at @index. Returns %0 in case of success. If there 1839 - * is no retimer present at given @index returns %-ENODEV. In any other 1840 - * failure returns negative errno. 1841 - */ 1842 - int usb4_port_retimer_write(struct tb_port *port, u8 index, u8 reg, 1843 - const void *buf, u8 size) 1844 - { 1845 - return usb4_port_sb_write(port, USB4_SB_TARGET_RETIMER, index, reg, buf, 1846 - size); 1847 - } 1848 - 1849 - /** 1850 1780 * usb4_port_retimer_is_last() - Is the retimer last on-board retimer 1851 1781 * @port: USB4 port 1852 1782 * @index: Retimer index ··· 1825 1837 if (ret) 1826 1838 return ret; 1827 1839 1828 - ret = usb4_port_retimer_read(port, index, USB4_SB_METADATA, &metadata, 1829 - sizeof(metadata)); 1840 + ret = usb4_port_sb_read(port, USB4_SB_TARGET_RETIMER, index, 1841 + USB4_SB_METADATA, &metadata, sizeof(metadata)); 1842 + return ret ? ret : metadata & 1; 1843 + } 1844 + 1845 + /** 1846 + * usb4_port_retimer_is_cable() - Is the retimer cable retimer 1847 + * @port: USB4 port 1848 + * @index: Retimer index 1849 + * 1850 + * If the retimer at @index is last cable retimer this function returns 1851 + * %1 and %0 if it is on-board retimer. In case a retimer is not present 1852 + * at @index returns %-ENODEV. Otherwise returns negative errno. 1853 + */ 1854 + int usb4_port_retimer_is_cable(struct tb_port *port, u8 index) 1855 + { 1856 + u32 metadata; 1857 + int ret; 1858 + 1859 + ret = usb4_port_retimer_op(port, index, USB4_SB_OPCODE_QUERY_CABLE_RETIMER, 1860 + 500); 1861 + if (ret) 1862 + return ret; 1863 + 1864 + ret = usb4_port_sb_read(port, USB4_SB_TARGET_RETIMER, index, 1865 + USB4_SB_METADATA, &metadata, sizeof(metadata)); 1830 1866 return ret ? ret : metadata & 1; 1831 1867 } 1832 1868 ··· 1875 1863 if (ret) 1876 1864 return ret; 1877 1865 1878 - ret = usb4_port_retimer_read(port, index, USB4_SB_METADATA, &metadata, 1879 - sizeof(metadata)); 1866 + ret = usb4_port_sb_read(port, USB4_SB_TARGET_RETIMER, index, 1867 + USB4_SB_METADATA, &metadata, sizeof(metadata)); 1880 1868 return ret ? ret : metadata & USB4_NVM_SECTOR_SIZE_MASK; 1881 1869 } 1882 1870 ··· 1901 1889 metadata = (dwaddress << USB4_NVM_SET_OFFSET_SHIFT) & 1902 1890 USB4_NVM_SET_OFFSET_MASK; 1903 1891 1904 - ret = usb4_port_retimer_write(port, index, USB4_SB_METADATA, &metadata, 1905 - sizeof(metadata)); 1892 + ret = usb4_port_sb_write(port, USB4_SB_TARGET_RETIMER, index, 1893 + USB4_SB_METADATA, &metadata, sizeof(metadata)); 1906 1894 if (ret) 1907 1895 return ret; 1908 1896 ··· 1924 1912 u8 index = info->index; 1925 1913 int ret; 1926 1914 1927 - ret = usb4_port_retimer_write(port, index, USB4_SB_DATA, 1928 - buf, dwords * 4); 1915 + ret = usb4_port_sb_write(port, USB4_SB_TARGET_RETIMER, index, 1916 + USB4_SB_DATA, buf, dwords * 4); 1929 1917 if (ret) 1930 1918 return ret; 1931 1919 ··· 2004 1992 u32 metadata, val; 2005 1993 int ret; 2006 1994 2007 - ret = usb4_port_retimer_read(port, index, USB4_SB_OPCODE, &val, 2008 - sizeof(val)); 1995 + ret = usb4_port_sb_read(port, USB4_SB_TARGET_RETIMER, index, 1996 + USB4_SB_OPCODE, &val, sizeof(val)); 2009 1997 if (ret) 2010 1998 return ret; 2011 1999 ··· 2016 2004 return 0; 2017 2005 2018 2006 case -EAGAIN: 2019 - ret = usb4_port_retimer_read(port, index, USB4_SB_METADATA, 2020 - &metadata, sizeof(metadata)); 2007 + ret = usb4_port_sb_read(port, USB4_SB_TARGET_RETIMER, index, 2008 + USB4_SB_METADATA, &metadata, 2009 + sizeof(metadata)); 2021 2010 if (ret) 2022 2011 return ret; 2023 2012 ··· 2043 2030 if (dwords < USB4_DATA_DWORDS) 2044 2031 metadata |= dwords << USB4_NVM_READ_LENGTH_SHIFT; 2045 2032 2046 - ret = usb4_port_retimer_write(port, index, USB4_SB_METADATA, &metadata, 2047 - sizeof(metadata)); 2033 + ret = usb4_port_sb_write(port, USB4_SB_TARGET_RETIMER, index, 2034 + USB4_SB_METADATA, &metadata, sizeof(metadata)); 2048 2035 if (ret) 2049 2036 return ret; 2050 2037 ··· 2052 2039 if (ret) 2053 2040 return ret; 2054 2041 2055 - return usb4_port_retimer_read(port, index, USB4_SB_DATA, buf, 2056 - dwords * 4); 2042 + return usb4_port_sb_read(port, USB4_SB_TARGET_RETIMER, index, 2043 + USB4_SB_DATA, buf, dwords * 4); 2057 2044 } 2058 2045 2059 2046 /**
+14 -1
drivers/usb/cdns3/cdns3-ti.c
··· 16 16 #include <linux/of_platform.h> 17 17 #include <linux/pm_runtime.h> 18 18 #include <linux/property.h> 19 + #include "core.h" 19 20 20 21 /* USB Wrapper register offsets */ 21 22 #define USBSS_PID 0x0 ··· 85 84 { 86 85 writel(value, data->usbss + offset); 87 86 } 87 + 88 + static struct cdns3_platform_data cdns_ti_pdata = { 89 + .quirks = CDNS3_DRD_SUSPEND_RESIDENCY_ENABLE, /* Errata i2409 */ 90 + }; 91 + 92 + static const struct of_dev_auxdata cdns_ti_auxdata[] = { 93 + { 94 + .compatible = "cdns,usb3", 95 + .platform_data = &cdns_ti_pdata, 96 + }, 97 + {}, 98 + }; 88 99 89 100 static int cdns_ti_probe(struct platform_device *pdev) 90 101 { ··· 189 176 reg |= USBSS_W1_PWRUP_RST; 190 177 cdns_ti_writel(data, USBSS_W1, reg); 191 178 192 - error = of_platform_populate(node, NULL, NULL, dev); 179 + error = of_platform_populate(node, NULL, cdns_ti_auxdata, dev); 193 180 if (error) { 194 181 dev_err(dev, "failed to create children: %d\n", error); 195 182 goto err;
+1
drivers/usb/cdns3/core.h
··· 44 44 bool suspend, bool wakeup); 45 45 unsigned long quirks; 46 46 #define CDNS3_DEFAULT_PM_RUNTIME_ALLOW BIT(0) 47 + #define CDNS3_DRD_SUSPEND_RESIDENCY_ENABLE BIT(1) 47 48 }; 48 49 49 50 /**
+9 -1
drivers/usb/cdns3/drd.c
··· 389 389 int cdns_drd_init(struct cdns *cdns) 390 390 { 391 391 void __iomem *regs; 392 - u32 state; 392 + u32 state, reg; 393 393 int ret; 394 394 395 395 regs = devm_ioremap_resource(cdns->dev, &cdns->otg_res); ··· 433 433 cdns->otg_irq_regs = (struct cdns_otg_irq_regs __iomem *) 434 434 &cdns->otg_v1_regs->ien; 435 435 writel(1, &cdns->otg_v1_regs->simulate); 436 + 437 + if (cdns->pdata && 438 + (cdns->pdata->quirks & CDNS3_DRD_SUSPEND_RESIDENCY_ENABLE)) { 439 + reg = readl(&cdns->otg_v1_regs->susp_ctrl); 440 + reg |= SUSP_CTRL_SUSPEND_RESIDENCY_ENABLE; 441 + writel(reg, &cdns->otg_v1_regs->susp_ctrl); 442 + } 443 + 436 444 cdns->version = CDNS3_CONTROLLER_V1; 437 445 } else { 438 446 dev_err(cdns->dev, "not supported DID=0x%08x\n", state);
+3
drivers/usb/cdns3/drd.h
··· 193 193 /* OTGREFCLK - bitmasks */ 194 194 #define OTGREFCLK_STB_CLK_SWITCH_EN BIT(31) 195 195 196 + /* SUPS_CTRL - bitmasks */ 197 + #define SUSP_CTRL_SUSPEND_RESIDENCY_ENABLE BIT(17) 198 + 196 199 /* OVERRIDE - bitmasks */ 197 200 #define OVERRIDE_IDPULLUP BIT(0) 198 201 /* Only for CDNS3_CONTROLLER_V0 version */
+9 -10
drivers/usb/chipidea/ci_hdrc_imx.c
··· 557 557 ci_hdrc_imx_remove(pdev); 558 558 } 559 559 560 - static int __maybe_unused imx_controller_suspend(struct device *dev, 560 + static int imx_controller_suspend(struct device *dev, 561 561 pm_message_t msg) 562 562 { 563 563 struct ci_hdrc_imx_data *data = dev_get_drvdata(dev); ··· 582 582 return 0; 583 583 } 584 584 585 - static int __maybe_unused imx_controller_resume(struct device *dev, 585 + static int imx_controller_resume(struct device *dev, 586 586 pm_message_t msg) 587 587 { 588 588 struct ci_hdrc_imx_data *data = dev_get_drvdata(dev); ··· 618 618 return ret; 619 619 } 620 620 621 - static int __maybe_unused ci_hdrc_imx_suspend(struct device *dev) 621 + static int ci_hdrc_imx_suspend(struct device *dev) 622 622 { 623 623 int ret; 624 624 ··· 636 636 return ret; 637 637 } 638 638 639 - static int __maybe_unused ci_hdrc_imx_resume(struct device *dev) 639 + static int ci_hdrc_imx_resume(struct device *dev) 640 640 { 641 641 struct ci_hdrc_imx_data *data = dev_get_drvdata(dev); 642 642 int ret; ··· 652 652 return ret; 653 653 } 654 654 655 - static int __maybe_unused ci_hdrc_imx_runtime_suspend(struct device *dev) 655 + static int ci_hdrc_imx_runtime_suspend(struct device *dev) 656 656 { 657 657 struct ci_hdrc_imx_data *data = dev_get_drvdata(dev); 658 658 ··· 664 664 return imx_controller_suspend(dev, PMSG_AUTO_SUSPEND); 665 665 } 666 666 667 - static int __maybe_unused ci_hdrc_imx_runtime_resume(struct device *dev) 667 + static int ci_hdrc_imx_runtime_resume(struct device *dev) 668 668 { 669 669 return imx_controller_resume(dev, PMSG_AUTO_RESUME); 670 670 } 671 671 672 672 static const struct dev_pm_ops ci_hdrc_imx_pm_ops = { 673 - SET_SYSTEM_SLEEP_PM_OPS(ci_hdrc_imx_suspend, ci_hdrc_imx_resume) 674 - SET_RUNTIME_PM_OPS(ci_hdrc_imx_runtime_suspend, 675 - ci_hdrc_imx_runtime_resume, NULL) 673 + SYSTEM_SLEEP_PM_OPS(ci_hdrc_imx_suspend, ci_hdrc_imx_resume) 674 + RUNTIME_PM_OPS(ci_hdrc_imx_runtime_suspend, ci_hdrc_imx_runtime_resume, NULL) 676 675 }; 677 676 static struct platform_driver ci_hdrc_imx_driver = { 678 677 .probe = ci_hdrc_imx_probe, ··· 680 681 .driver = { 681 682 .name = "imx_usb", 682 683 .of_match_table = ci_hdrc_imx_dt_ids, 683 - .pm = &ci_hdrc_imx_pm_ops, 684 + .pm = pm_ptr(&ci_hdrc_imx_pm_ops), 684 685 }, 685 686 }; 686 687
+1
drivers/usb/chipidea/ci_hdrc_msm.c
··· 303 303 304 304 MODULE_ALIAS("platform:msm_hsusb"); 305 305 MODULE_ALIAS("platform:ci13xxx_msm"); 306 + MODULE_DESCRIPTION("ChipIdea Highspeed Dual Role Controller"); 306 307 MODULE_LICENSE("GPL v2");
+4 -5
drivers/usb/chipidea/ci_hdrc_tegra.c
··· 372 372 pm_runtime_force_suspend(&pdev->dev); 373 373 } 374 374 375 - static int __maybe_unused tegra_usb_runtime_resume(struct device *dev) 375 + static int tegra_usb_runtime_resume(struct device *dev) 376 376 { 377 377 struct tegra_usb *usb = dev_get_drvdata(dev); 378 378 int err; ··· 386 386 return 0; 387 387 } 388 388 389 - static int __maybe_unused tegra_usb_runtime_suspend(struct device *dev) 389 + static int tegra_usb_runtime_suspend(struct device *dev) 390 390 { 391 391 struct tegra_usb *usb = dev_get_drvdata(dev); 392 392 ··· 396 396 } 397 397 398 398 static const struct dev_pm_ops tegra_usb_pm = { 399 - SET_RUNTIME_PM_OPS(tegra_usb_runtime_suspend, tegra_usb_runtime_resume, 400 - NULL) 399 + RUNTIME_PM_OPS(tegra_usb_runtime_suspend, tegra_usb_runtime_resume, NULL) 401 400 }; 402 401 403 402 static struct platform_driver tegra_usb_driver = { 404 403 .driver = { 405 404 .name = "tegra-usb", 406 405 .of_match_table = tegra_usb_of_match, 407 - .pm = &tegra_usb_pm, 406 + .pm = pm_ptr(&tegra_usb_pm), 408 407 }, 409 408 .probe = tegra_usb_probe, 410 409 .remove_new = tegra_usb_remove,
+1
drivers/usb/class/usbtmc.c
··· 2592 2592 2593 2593 module_usb_driver(usbtmc_driver); 2594 2594 2595 + MODULE_DESCRIPTION("USB Test & Measurement class driver"); 2595 2596 MODULE_LICENSE("GPL");
+1
drivers/usb/common/common.c
··· 433 433 subsys_initcall(usb_common_init); 434 434 module_exit(usb_common_exit); 435 435 436 + MODULE_DESCRIPTION("Common code for host and device side USB"); 436 437 MODULE_LICENSE("GPL");
+1
drivers/usb/common/usb-otg-fsm.c
··· 449 449 return fsm->state_changed; 450 450 } 451 451 EXPORT_SYMBOL_GPL(otg_statemachine); 452 + MODULE_DESCRIPTION("OTG Finite State Machine"); 452 453 MODULE_LICENSE("GPL");
+14
drivers/usb/core/driver.c
··· 517 517 return 0; 518 518 } 519 519 520 + static void usb_shutdown_interface(struct device *dev) 521 + { 522 + struct usb_interface *intf = to_usb_interface(dev); 523 + struct usb_driver *driver; 524 + 525 + if (!dev->driver) 526 + return; 527 + 528 + driver = to_usb_driver(dev->driver); 529 + if (driver->shutdown) 530 + driver->shutdown(intf); 531 + } 532 + 520 533 /** 521 534 * usb_driver_claim_interface - bind a driver to an interface 522 535 * @driver: the driver to be bound ··· 1072 1059 new_driver->driver.bus = &usb_bus_type; 1073 1060 new_driver->driver.probe = usb_probe_interface; 1074 1061 new_driver->driver.remove = usb_unbind_interface; 1062 + new_driver->driver.shutdown = usb_shutdown_interface; 1075 1063 new_driver->driver.owner = owner; 1076 1064 new_driver->driver.mod_name = mod_name; 1077 1065 new_driver->driver.dev_groups = new_driver->dev_groups;
+1
drivers/usb/core/usb.c
··· 1150 1150 1151 1151 subsys_initcall(usb_init); 1152 1152 module_exit(usb_exit); 1153 + MODULE_DESCRIPTION("USB core host-side support"); 1153 1154 MODULE_LICENSE("GPL");
+2 -2
drivers/usb/dwc2/gadget.c
··· 885 885 } 886 886 887 887 /* DMA sg buffer */ 888 - for_each_sg(ureq->sg, sg, ureq->num_sgs, i) { 888 + for_each_sg(ureq->sg, sg, ureq->num_mapped_sgs, i) { 889 889 dwc2_gadget_fill_nonisoc_xfer_ddma_one(hs_ep, &desc, 890 890 sg_dma_address(sg) + sg->offset, sg_dma_len(sg), 891 - sg_is_last(sg)); 891 + (i == (ureq->num_mapped_sgs - 1))); 892 892 desc_count += hs_ep->desc_count; 893 893 } 894 894
+25 -5
drivers/usb/dwc2/params.c
··· 133 133 p->no_clock_gating = true; 134 134 } 135 135 136 - static void dwc2_set_ltq_params(struct dwc2_hsotg *hsotg) 136 + static void dwc2_set_ltq_danube_params(struct dwc2_hsotg *hsotg) 137 + { 138 + struct dwc2_core_params *p = &hsotg->params; 139 + 140 + p->otg_caps.hnp_support = false; 141 + p->otg_caps.srp_support = false; 142 + } 143 + 144 + static void dwc2_set_ltq_ase_params(struct dwc2_hsotg *hsotg) 137 145 { 138 146 struct dwc2_core_params *p = &hsotg->params; 139 147 ··· 150 142 p->host_rx_fifo_size = 288; 151 143 p->host_nperio_tx_fifo_size = 128; 152 144 p->host_perio_tx_fifo_size = 96; 153 - p->max_transfer_size = 65535; 154 - p->max_packet_count = 511; 155 145 p->ahbcfg = GAHBCFG_HBSTLEN_INCR16 << 156 146 GAHBCFG_HBSTLEN_SHIFT; 147 + } 148 + 149 + static void dwc2_set_ltq_xrx200_params(struct dwc2_hsotg *hsotg) 150 + { 151 + struct dwc2_core_params *p = &hsotg->params; 152 + 153 + p->otg_caps.hnp_support = false; 154 + p->otg_caps.srp_support = false; 155 + p->host_rx_fifo_size = 288; 156 + p->host_nperio_tx_fifo_size = 128; 157 + p->host_perio_tx_fifo_size = 136; 157 158 } 158 159 159 160 static void dwc2_set_amlogic_params(struct dwc2_hsotg *hsotg) ··· 314 297 { .compatible = "ingenic,x1830-otg", .data = dwc2_set_x1600_params }, 315 298 { .compatible = "ingenic,x2000-otg", .data = dwc2_set_x2000_params }, 316 299 { .compatible = "rockchip,rk3066-usb", .data = dwc2_set_rk_params }, 317 - { .compatible = "lantiq,arx100-usb", .data = dwc2_set_ltq_params }, 318 - { .compatible = "lantiq,xrx200-usb", .data = dwc2_set_ltq_params }, 300 + { .compatible = "lantiq,danube-usb", .data = &dwc2_set_ltq_danube_params }, 301 + { .compatible = "lantiq,ase-usb", .data = &dwc2_set_ltq_ase_params }, 302 + { .compatible = "lantiq,arx100-usb", .data = &dwc2_set_ltq_ase_params }, 303 + { .compatible = "lantiq,xrx200-usb", .data = &dwc2_set_ltq_xrx200_params }, 304 + { .compatible = "lantiq,xrx300-usb", .data = &dwc2_set_ltq_xrx200_params }, 319 305 { .compatible = "snps,dwc2" }, 320 306 { .compatible = "samsung,s3c6400-hsotg", 321 307 .data = dwc2_set_s3c6400_params },
+54 -12
drivers/usb/dwc3/core.c
··· 108 108 void dwc3_enable_susphy(struct dwc3 *dwc, bool enable) 109 109 { 110 110 u32 reg; 111 + int i; 111 112 112 - reg = dwc3_readl(dwc->regs, DWC3_GUSB3PIPECTL(0)); 113 - if (enable && !dwc->dis_u3_susphy_quirk) 114 - reg |= DWC3_GUSB3PIPECTL_SUSPHY; 115 - else 116 - reg &= ~DWC3_GUSB3PIPECTL_SUSPHY; 113 + for (i = 0; i < dwc->num_usb3_ports; i++) { 114 + reg = dwc3_readl(dwc->regs, DWC3_GUSB3PIPECTL(i)); 115 + if (enable && !dwc->dis_u3_susphy_quirk) 116 + reg |= DWC3_GUSB3PIPECTL_SUSPHY; 117 + else 118 + reg &= ~DWC3_GUSB3PIPECTL_SUSPHY; 117 119 118 - dwc3_writel(dwc->regs, DWC3_GUSB3PIPECTL(0), reg); 120 + dwc3_writel(dwc->regs, DWC3_GUSB3PIPECTL(i), reg); 121 + } 119 122 120 - reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)); 121 - if (enable && !dwc->dis_u2_susphy_quirk) 122 - reg |= DWC3_GUSB2PHYCFG_SUSPHY; 123 - else 124 - reg &= ~DWC3_GUSB2PHYCFG_SUSPHY; 123 + for (i = 0; i < dwc->num_usb2_ports; i++) { 124 + reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(i)); 125 + if (enable && !dwc->dis_u2_susphy_quirk) 126 + reg |= DWC3_GUSB2PHYCFG_SUSPHY; 127 + else 128 + reg &= ~DWC3_GUSB2PHYCFG_SUSPHY; 125 129 126 - dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); 130 + dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(i), reg); 131 + } 127 132 } 128 133 129 134 void dwc3_set_prtcap(struct dwc3 *dwc, u32 mode) ··· 602 597 603 598 if (DWC3_IP_IS(DWC32)) 604 599 parms->hwparams9 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS9); 600 + } 601 + 602 + static void dwc3_config_soc_bus(struct dwc3 *dwc) 603 + { 604 + if (dwc->gsbuscfg0_reqinfo != DWC3_GSBUSCFG0_REQINFO_UNSPECIFIED) { 605 + u32 reg; 606 + 607 + reg = dwc3_readl(dwc->regs, DWC3_GSBUSCFG0); 608 + reg &= ~DWC3_GSBUSCFG0_REQINFO(~0); 609 + reg |= DWC3_GSBUSCFG0_REQINFO(dwc->gsbuscfg0_reqinfo); 610 + dwc3_writel(dwc->regs, DWC3_GSBUSCFG0, reg); 611 + } 605 612 } 606 613 607 614 static int dwc3_core_ulpi_init(struct dwc3 *dwc) ··· 1355 1338 1356 1339 dwc3_set_incr_burst_type(dwc); 1357 1340 1341 + dwc3_config_soc_bus(dwc); 1342 + 1358 1343 ret = dwc3_phy_power_on(dwc); 1359 1344 if (ret) 1360 1345 goto err_exit_phy; ··· 1593 1574 1594 1575 /* de-assert DRVVBUS for HOST and OTG mode */ 1595 1576 dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_DEVICE); 1577 + } 1578 + 1579 + static void dwc3_get_software_properties(struct dwc3 *dwc) 1580 + { 1581 + struct device *tmpdev; 1582 + u16 gsbuscfg0_reqinfo; 1583 + int ret; 1584 + 1585 + dwc->gsbuscfg0_reqinfo = DWC3_GSBUSCFG0_REQINFO_UNSPECIFIED; 1586 + 1587 + /* 1588 + * Iterate over all parent nodes for finding swnode properties 1589 + * and non-DT (non-ABI) properties. 1590 + */ 1591 + for (tmpdev = dwc->dev; tmpdev; tmpdev = tmpdev->parent) { 1592 + ret = device_property_read_u16(tmpdev, 1593 + "snps,gsbuscfg0-reqinfo", 1594 + &gsbuscfg0_reqinfo); 1595 + if (!ret) 1596 + dwc->gsbuscfg0_reqinfo = gsbuscfg0_reqinfo; 1597 + } 1596 1598 } 1597 1599 1598 1600 static void dwc3_get_properties(struct dwc3 *dwc) ··· 2129 2089 dwc->regs_size = resource_size(&dwc_res); 2130 2090 2131 2091 dwc3_get_properties(dwc); 2092 + 2093 + dwc3_get_software_properties(dwc); 2132 2094 2133 2095 dwc->reset = devm_reset_control_array_get_optional_shared(dev); 2134 2096 if (IS_ERR(dwc->reset)) {
+8
drivers/usb/dwc3/core.h
··· 194 194 #define DWC3_GSBUSCFG0_INCRBRSTENA (1 << 0) /* undefined length enable */ 195 195 #define DWC3_GSBUSCFG0_INCRBRST_MASK 0xff 196 196 197 + /* Global SoC Bus Configuration Register: AHB-prot/AXI-cache/OCP-ReqInfo */ 198 + #define DWC3_GSBUSCFG0_REQINFO(n) (((n) & 0xffff) << 16) 199 + #define DWC3_GSBUSCFG0_REQINFO_UNSPECIFIED 0xffffffff 200 + 197 201 /* Global Debug LSP MUX Select */ 198 202 #define DWC3_GDBGLSPMUX_ENDBC BIT(15) /* Host only */ 199 203 #define DWC3_GDBGLSPMUX_HOSTSELECT(n) ((n) & 0x3fff) ··· 1157 1153 * @num_ep_resized: carries the current number endpoints which have had its tx 1158 1154 * fifo resized. 1159 1155 * @debug_root: root debugfs directory for this device to put its files in. 1156 + * @gsbuscfg0_reqinfo: store GSBUSCFG0.DATRDREQINFO, DESRDREQINFO, 1157 + * DATWRREQINFO, and DESWRREQINFO value passed from 1158 + * glue driver. 1160 1159 */ 1161 1160 struct dwc3 { 1162 1161 struct work_struct drd_work; ··· 1387 1380 int last_fifo_depth; 1388 1381 int num_ep_resized; 1389 1382 struct dentry *debug_root; 1383 + u32 gsbuscfg0_reqinfo; 1390 1384 }; 1391 1385 1392 1386 #define INCRX_BURST_MODE 0
+29
drivers/usb/dwc3/dwc3-xilinx.c
··· 246 246 }; 247 247 MODULE_DEVICE_TABLE(of, dwc3_xlnx_of_match); 248 248 249 + static int dwc3_set_swnode(struct device *dev) 250 + { 251 + struct device_node *np = dev->of_node, *dwc3_np; 252 + struct property_entry props[2]; 253 + int prop_idx = 0, ret = 0; 254 + 255 + dwc3_np = of_get_compatible_child(np, "snps,dwc3"); 256 + if (!dwc3_np) { 257 + ret = -ENODEV; 258 + dev_err(dev, "failed to find dwc3 core child\n"); 259 + return ret; 260 + } 261 + 262 + memset(props, 0, sizeof(struct property_entry) * ARRAY_SIZE(props)); 263 + if (of_dma_is_coherent(dwc3_np)) 264 + props[prop_idx++] = PROPERTY_ENTRY_U16("snps,gsbuscfg0-reqinfo", 265 + 0xffff); 266 + of_node_put(dwc3_np); 267 + 268 + if (prop_idx) 269 + ret = device_create_managed_software_node(dev, props, NULL); 270 + 271 + return ret; 272 + } 273 + 249 274 static int dwc3_xlnx_probe(struct platform_device *pdev) 250 275 { 251 276 struct dwc3_xlnx *priv_data; ··· 310 285 return ret; 311 286 312 287 ret = priv_data->pltfm_init(priv_data); 288 + if (ret) 289 + goto err_clk_put; 290 + 291 + ret = dwc3_set_swnode(dev); 313 292 if (ret) 314 293 goto err_clk_put; 315 294
+3 -1
drivers/usb/dwc3/host.c
··· 126 126 127 127 int dwc3_host_init(struct dwc3 *dwc) 128 128 { 129 - struct property_entry props[5]; 129 + struct property_entry props[6]; 130 130 struct platform_device *xhci; 131 131 int ret, irq; 132 132 int prop_idx = 0; ··· 161 161 memset(props, 0, sizeof(struct property_entry) * ARRAY_SIZE(props)); 162 162 163 163 props[prop_idx++] = PROPERTY_ENTRY_BOOL("xhci-sg-trb-cache-size-quirk"); 164 + 165 + props[prop_idx++] = PROPERTY_ENTRY_BOOL("write-64-hi-lo-quirk"); 164 166 165 167 if (dwc->usb3_lpm_capable) 166 168 props[prop_idx++] = PROPERTY_ENTRY_BOOL("usb3-lpm-capable");
+1
drivers/usb/gadget/composite.c
··· 2799 2799 } 2800 2800 EXPORT_SYMBOL_GPL(usb_composite_overwrite_options); 2801 2801 2802 + MODULE_DESCRIPTION("infrastructure for Composite USB Gadgets"); 2802 2803 MODULE_LICENSE("GPL"); 2803 2804 MODULE_AUTHOR("David Brownell");
+1
drivers/usb/gadget/function/f_acm.c
··· 854 854 return &opts->func_inst; 855 855 } 856 856 DECLARE_USB_FUNCTION_INIT(acm, acm_alloc_instance, acm_alloc_func); 857 + MODULE_DESCRIPTION("USB CDC serial (ACM) function driver"); 857 858 MODULE_LICENSE("GPL");
+1
drivers/usb/gadget/function/f_ecm.c
··· 966 966 } 967 967 968 968 DECLARE_USB_FUNCTION_INIT(ecm, ecm_alloc_inst, ecm_alloc); 969 + MODULE_DESCRIPTION("USB CDC Ethernet (ECM) link function driver"); 969 970 MODULE_LICENSE("GPL"); 970 971 MODULE_AUTHOR("David Brownell");
+1
drivers/usb/gadget/function/f_eem.c
··· 674 674 } 675 675 676 676 DECLARE_USB_FUNCTION_INIT(eem, eem_alloc_inst, eem_alloc); 677 + MODULE_DESCRIPTION("USB CDC Ethernet (EEM) link function driver"); 677 678 MODULE_LICENSE("GPL"); 678 679 MODULE_AUTHOR("David Brownell");
+1
drivers/usb/gadget/function/f_fs.c
··· 4316 4316 } 4317 4317 4318 4318 DECLARE_USB_FUNCTION_INIT(ffs, ffs_alloc_inst, ffs_alloc); 4319 + MODULE_DESCRIPTION("user mode file system API for USB composite function controllers"); 4319 4320 MODULE_LICENSE("GPL"); 4320 4321 MODULE_AUTHOR("Michal Nazarewicz");
+1
drivers/usb/gadget/function/f_hid.c
··· 1322 1322 } 1323 1323 1324 1324 DECLARE_USB_FUNCTION_INIT(hid, hidg_alloc_inst, hidg_alloc); 1325 + MODULE_DESCRIPTION("USB HID function driver"); 1325 1326 MODULE_LICENSE("GPL"); 1326 1327 MODULE_AUTHOR("Fabien Chouteau"); 1327 1328
+1
drivers/usb/gadget/function/f_loopback.c
··· 593 593 usb_function_unregister(&Loopbackusb_func); 594 594 } 595 595 596 + MODULE_DESCRIPTION("USB peripheral loopback configuration driver"); 596 597 MODULE_LICENSE("GPL");
+1
drivers/usb/gadget/function/f_mass_storage.c
··· 3577 3577 } 3578 3578 3579 3579 DECLARE_USB_FUNCTION_INIT(mass_storage, fsg_alloc_inst, fsg_alloc); 3580 + MODULE_DESCRIPTION("Mass Storage USB Composite Function"); 3580 3581 MODULE_LICENSE("GPL"); 3581 3582 MODULE_AUTHOR("Michal Nazarewicz"); 3582 3583
+1
drivers/usb/gadget/function/f_midi.c
··· 38 38 #include "u_midi.h" 39 39 40 40 MODULE_AUTHOR("Ben Williamson"); 41 + MODULE_DESCRIPTION("USB MIDI class function driver"); 41 42 MODULE_LICENSE("GPL v2"); 42 43 43 44 static const char f_midi_shortname[] = "f_midi";
+12 -8
drivers/usb/gadget/function/f_midi2.c
··· 150 150 151 151 #define func_to_midi2(f) container_of(f, struct f_midi2, func) 152 152 153 + /* convert from MIDI protocol number (1 or 2) to SNDRV_UMP_EP_INFO_PROTO_* */ 154 + #define to_ump_protocol(v) (((v) & 3) << 8) 155 + 153 156 /* get EP name string */ 154 157 static const char *ump_ep_name(const struct f_midi2_ep *ep) 155 158 { ··· 567 564 .status = UMP_STREAM_MSG_STATUS_STREAM_CFG, 568 565 }; 569 566 570 - if ((ep->info.protocol & SNDRV_UMP_EP_INFO_PROTO_MIDI_MASK) == 571 - SNDRV_UMP_EP_INFO_PROTO_MIDI2) 567 + if (ep->info.protocol == 2) 572 568 rep.protocol = UMP_STREAM_MSG_EP_INFO_CAP_MIDI2 >> 8; 573 569 else 574 570 rep.protocol = UMP_STREAM_MSG_EP_INFO_CAP_MIDI1 >> 8; ··· 629 627 return; 630 628 case UMP_STREAM_MSG_STATUS_STREAM_CFG_REQUEST: 631 629 if (*data & UMP_STREAM_MSG_EP_INFO_CAP_MIDI2) { 632 - ep->info.protocol = SNDRV_UMP_EP_INFO_PROTO_MIDI2; 630 + ep->info.protocol = 2; 633 631 DBG(midi2, "Switching Protocol to MIDI2\n"); 634 632 } else { 635 - ep->info.protocol = SNDRV_UMP_EP_INFO_PROTO_MIDI1; 633 + ep->info.protocol = 1; 636 634 DBG(midi2, "Switching Protocol to MIDI1\n"); 637 635 } 638 - snd_ump_switch_protocol(ep->ump, ep->info.protocol); 636 + snd_ump_switch_protocol(ep->ump, to_ump_protocol(ep->info.protocol)); 639 637 reply_ump_stream_ep_config(ep); 640 638 return; 641 639 case UMP_STREAM_MSG_STATUS_FB_DISCOVERY: ··· 1067 1065 group = midi2->out_cable_mapping[cable].group; 1068 1066 bytes = midi1_packet_bytes[*buf & 0x0f]; 1069 1067 for (c = 0; c < bytes; c++) { 1070 - snd_ump_convert_to_ump(cvt, group, ep->info.protocol, 1068 + snd_ump_convert_to_ump(cvt, group, 1069 + to_ump_protocol(ep->info.protocol), 1071 1070 buf[c + 1]); 1072 1071 if (cvt->ump_bytes) { 1073 1072 snd_ump_receive(ep->ump, cvt->ump, ··· 1378 1375 desc->nNumGroupTrm = b->num_groups; 1379 1376 desc->iBlockItem = ep->blks[blk].string_id; 1380 1377 1381 - if (ep->info.protocol & SNDRV_UMP_EP_INFO_PROTO_MIDI2) 1378 + if (ep->info.protocol == 2) 1382 1379 desc->bMIDIProtocol = USB_MS_MIDI_PROTO_2_0; 1383 1380 else 1384 1381 desc->bMIDIProtocol = USB_MS_MIDI_PROTO_1_0_128; ··· 1555 1552 if (midi2->info.static_block) 1556 1553 ump->info.flags |= SNDRV_UMP_EP_INFO_STATIC_BLOCKS; 1557 1554 ump->info.protocol_caps = (ep->info.protocol_caps & 3) << 8; 1558 - ump->info.protocol = (ep->info.protocol & 3) << 8; 1555 + ump->info.protocol = to_ump_protocol(ep->info.protocol); 1559 1556 ump->info.version = 0x0101; 1560 1557 ump->info.family_id = ep->info.family; 1561 1558 ump->info.model_id = ep->info.model; ··· 2871 2868 2872 2869 DECLARE_USB_FUNCTION_INIT(midi2, f_midi2_alloc_inst, f_midi2_alloc); 2873 2870 2871 + MODULE_DESCRIPTION("USB MIDI 2.0 class function driver"); 2874 2872 MODULE_LICENSE("GPL");
+1
drivers/usb/gadget/function/f_ncm.c
··· 1797 1797 } 1798 1798 1799 1799 DECLARE_USB_FUNCTION_INIT(ncm, ncm_alloc_inst, ncm_alloc); 1800 + MODULE_DESCRIPTION("USB CDC Network (NCM) link function driver"); 1800 1801 MODULE_LICENSE("GPL"); 1801 1802 MODULE_AUTHOR("Yauheni Kaliuta");
+1
drivers/usb/gadget/function/f_obex.c
··· 487 487 488 488 DECLARE_USB_FUNCTION_INIT(obex, obex_alloc_inst, obex_alloc); 489 489 MODULE_AUTHOR("Felipe Balbi"); 490 + MODULE_DESCRIPTION("USB CDC OBEX function driver"); 490 491 MODULE_LICENSE("GPL");
+1
drivers/usb/gadget/function/f_phonet.c
··· 729 729 730 730 DECLARE_USB_FUNCTION_INIT(phonet, phonet_alloc_inst, phonet_alloc); 731 731 MODULE_AUTHOR("Rémi Denis-Courmont"); 732 + MODULE_DESCRIPTION("USB CDC Phonet function"); 732 733 MODULE_LICENSE("GPL");
+1
drivers/usb/gadget/function/f_printer.c
··· 1527 1527 } 1528 1528 1529 1529 DECLARE_USB_FUNCTION_INIT(printer, gprinter_alloc_inst, gprinter_alloc); 1530 + MODULE_DESCRIPTION("USB printer function driver"); 1530 1531 MODULE_LICENSE("GPL"); 1531 1532 MODULE_AUTHOR("Craig Nadler"); 1532 1533
+1
drivers/usb/gadget/function/f_rndis.c
··· 1013 1013 } 1014 1014 1015 1015 DECLARE_USB_FUNCTION_INIT(rndis, rndis_alloc_inst, rndis_alloc); 1016 + MODULE_DESCRIPTION("RNDIS link function driver"); 1016 1017 MODULE_LICENSE("GPL"); 1017 1018 MODULE_AUTHOR("David Brownell");
+1
drivers/usb/gadget/function/f_serial.c
··· 392 392 } 393 393 394 394 DECLARE_USB_FUNCTION_INIT(gser, gser_alloc_inst, gser_alloc); 395 + MODULE_DESCRIPTION("generic USB serial function driver"); 395 396 MODULE_LICENSE("GPL"); 396 397 MODULE_AUTHOR("Al Borchers"); 397 398 MODULE_AUTHOR("David Brownell");
+1
drivers/usb/gadget/function/f_sourcesink.c
··· 1284 1284 module_init(sslb_modinit); 1285 1285 module_exit(sslb_modexit); 1286 1286 1287 + MODULE_DESCRIPTION("USB peripheral source/sink configuration driver"); 1287 1288 MODULE_LICENSE("GPL");
+1
drivers/usb/gadget/function/f_subset.c
··· 500 500 } 501 501 502 502 DECLARE_USB_FUNCTION_INIT(geth, geth_alloc_inst, geth_alloc); 503 + MODULE_DESCRIPTION("\"CDC Subset\" Ethernet link function driver"); 503 504 MODULE_LICENSE("GPL"); 504 505 MODULE_AUTHOR("David Brownell");
+1
drivers/usb/gadget/function/f_tcm.c
··· 2301 2301 } 2302 2302 module_exit(tcm_exit); 2303 2303 2304 + MODULE_DESCRIPTION("Target based USB-Gadget"); 2304 2305 MODULE_LICENSE("GPL"); 2305 2306 MODULE_AUTHOR("Sebastian Andrzej Siewior");
+1
drivers/usb/gadget/function/f_uac1.c
··· 1823 1823 } 1824 1824 1825 1825 DECLARE_USB_FUNCTION_INIT(uac1, f_audio_alloc_inst, f_audio_alloc); 1826 + MODULE_DESCRIPTION("USB Audio Class 1.0 Function (using u_audio API)"); 1826 1827 MODULE_LICENSE("GPL"); 1827 1828 MODULE_AUTHOR("Ruslan Bilovol");
+1
drivers/usb/gadget/function/f_uac1_legacy.c
··· 1014 1014 } 1015 1015 1016 1016 DECLARE_USB_FUNCTION_INIT(uac1_legacy, f_audio_alloc_inst, f_audio_alloc); 1017 + MODULE_DESCRIPTION("USB Audio class function driver"); 1017 1018 MODULE_LICENSE("GPL"); 1018 1019 MODULE_AUTHOR("Bryan Wu");
+5 -1
drivers/usb/gadget/function/f_uac2.c
··· 2063 2063 goto end; \ 2064 2064 } \ 2065 2065 \ 2066 - ret = scnprintf(opts->name, min(sizeof(opts->name), len), \ 2066 + if (len && page[len - 1] == '\n') \ 2067 + len--; \ 2068 + \ 2069 + ret = scnprintf(opts->name, min(sizeof(opts->name), len + 1), \ 2067 2070 "%s", page); \ 2068 2071 \ 2069 2072 end: \ ··· 2254 2251 } 2255 2252 2256 2253 DECLARE_USB_FUNCTION_INIT(uac2, afunc_alloc_inst, afunc_alloc); 2254 + MODULE_DESCRIPTION("USB Audio Class 2.0 Function"); 2257 2255 MODULE_LICENSE("GPL"); 2258 2256 MODULE_AUTHOR("Yadwinder Singh"); 2259 2257 MODULE_AUTHOR("Jaswinder Singh");
+1
drivers/usb/gadget/function/f_uvc.c
··· 1118 1118 } 1119 1119 1120 1120 DECLARE_USB_FUNCTION_INIT(uvc, uvc_alloc_inst, uvc_alloc); 1121 + MODULE_DESCRIPTION("USB Video Class Gadget driver"); 1121 1122 MODULE_LICENSE("GPL"); 1122 1123 MODULE_AUTHOR("Laurent Pinchart");
+1
drivers/usb/gadget/function/storage_common.c
··· 537 537 } 538 538 EXPORT_SYMBOL_GPL(fsg_store_forced_eject); 539 539 540 + MODULE_DESCRIPTION("Common definitions for mass storage functionality"); 540 541 MODULE_LICENSE("GPL");
+1
drivers/usb/gadget/function/u_ether.c
··· 1245 1245 } 1246 1246 EXPORT_SYMBOL_GPL(gether_disconnect); 1247 1247 1248 + MODULE_DESCRIPTION("Ethernet-over-USB link layer utilities for Gadget stack"); 1248 1249 MODULE_LICENSE("GPL"); 1249 1250 MODULE_AUTHOR("David Brownell");
+1
drivers/usb/gadget/function/u_serial.c
··· 1536 1536 } 1537 1537 module_exit(userial_cleanup); 1538 1538 1539 + MODULE_DESCRIPTION("utilities for USB gadget \"serial port\"/TTY support"); 1539 1540 MODULE_LICENSE("GPL");
+1
drivers/usb/gadget/legacy/dbgp.c
··· 434 434 } 435 435 436 436 MODULE_AUTHOR("Stephane Duverger"); 437 + MODULE_DESCRIPTION("EHCI Debug Port device gadget"); 437 438 MODULE_LICENSE("GPL"); 438 439 module_init(dbgp_init); 439 440 module_exit(dbgp_exit);
+1
drivers/usb/gadget/legacy/gmidi.c
··· 31 31 /*-------------------------------------------------------------------------*/ 32 32 33 33 MODULE_AUTHOR("Ben Williamson"); 34 + MODULE_DESCRIPTION("USB MIDI Gadget Driver"); 34 35 MODULE_LICENSE("GPL v2"); 35 36 36 37 static const char longname[] = "MIDI Gadget";
+1
drivers/usb/gadget/legacy/zero.c
··· 425 425 module_usb_composite_driver(zero_driver); 426 426 427 427 MODULE_AUTHOR("David Brownell"); 428 + MODULE_DESCRIPTION("Gadget Zero, for USB development"); 428 429 MODULE_LICENSE("GPL");
+2
drivers/usb/gadget/udc/aspeed_udc.c
··· 1009 1009 break; 1010 1010 case USB_RECIP_ENDPOINT: 1011 1011 epnum = crq.wIndex & USB_ENDPOINT_NUMBER_MASK; 1012 + if (epnum >= AST_UDC_NUM_ENDPOINTS) 1013 + goto stall; 1012 1014 status = udc->ep[epnum].stopped; 1013 1015 break; 1014 1016 default:
+1
drivers/usb/host/ohci-exynos.c
··· 293 293 294 294 MODULE_ALIAS("platform:exynos-ohci"); 295 295 MODULE_AUTHOR("Jingoo Han <jg1.han@samsung.com>"); 296 + MODULE_DESCRIPTION("OHCI support for Samsung S5P/Exynos SoC Series"); 296 297 MODULE_LICENSE("GPL v2");
-25
drivers/usb/host/oxu210hp-hcd.c
··· 196 196 #define PORT_RWC_BITS (PORT_CSC | PORT_PEC | PORT_OCC) 197 197 } __packed; 198 198 199 - /* Appendix C, Debug port ... intended for use with special "debug devices" 200 - * that can help if there's no serial console. (nonstandard enumeration.) 201 - */ 202 - struct ehci_dbg_port { 203 - u32 control; 204 - #define DBGP_OWNER (1<<30) 205 - #define DBGP_ENABLED (1<<28) 206 - #define DBGP_DONE (1<<16) 207 - #define DBGP_INUSE (1<<10) 208 - #define DBGP_ERRCODE(x) (((x)>>7)&0x07) 209 - # define DBGP_ERR_BAD 1 210 - # define DBGP_ERR_SIGNAL 2 211 - #define DBGP_ERROR (1<<6) 212 - #define DBGP_GO (1<<5) 213 - #define DBGP_OUT (1<<4) 214 - #define DBGP_LEN(x) (((x)>>0)&0x0f) 215 - u32 pids; 216 - #define DBGP_PID_GET(x) (((x)>>16)&0xff) 217 - #define DBGP_PID_SET(data, tok) (((data)<<8)|(tok)) 218 - u32 data03; 219 - u32 data47; 220 - u32 address; 221 - #define DBGP_EPADDR(dev, ep) (((dev)<<8)|(ep)) 222 - } __packed; 223 - 224 199 #define QTD_NEXT(dma) cpu_to_le32((u32)dma) 225 200 226 201 /*
+38
drivers/usb/host/xhci-dbgcap.c
··· 1150 1150 return size; 1151 1151 } 1152 1152 1153 + static ssize_t dbc_poll_interval_ms_show(struct device *dev, 1154 + struct device_attribute *attr, 1155 + char *buf) 1156 + { 1157 + struct xhci_dbc *dbc; 1158 + struct xhci_hcd *xhci; 1159 + 1160 + xhci = hcd_to_xhci(dev_get_drvdata(dev)); 1161 + dbc = xhci->dbc; 1162 + 1163 + return sysfs_emit(buf, "%u\n", dbc->poll_interval); 1164 + } 1165 + 1166 + static ssize_t dbc_poll_interval_ms_store(struct device *dev, 1167 + struct device_attribute *attr, 1168 + const char *buf, size_t size) 1169 + { 1170 + struct xhci_dbc *dbc; 1171 + struct xhci_hcd *xhci; 1172 + u32 value; 1173 + int ret; 1174 + 1175 + ret = kstrtou32(buf, 0, &value); 1176 + if (ret || value > DBC_POLL_INTERVAL_MAX) 1177 + return -EINVAL; 1178 + 1179 + xhci = hcd_to_xhci(dev_get_drvdata(dev)); 1180 + dbc = xhci->dbc; 1181 + 1182 + dbc->poll_interval = value; 1183 + 1184 + mod_delayed_work(system_wq, &dbc->event_work, 0); 1185 + 1186 + return size; 1187 + } 1188 + 1153 1189 static DEVICE_ATTR_RW(dbc); 1154 1190 static DEVICE_ATTR_RW(dbc_idVendor); 1155 1191 static DEVICE_ATTR_RW(dbc_idProduct); 1156 1192 static DEVICE_ATTR_RW(dbc_bcdDevice); 1157 1193 static DEVICE_ATTR_RW(dbc_bInterfaceProtocol); 1194 + static DEVICE_ATTR_RW(dbc_poll_interval_ms); 1158 1195 1159 1196 static struct attribute *dbc_dev_attrs[] = { 1160 1197 &dev_attr_dbc.attr, ··· 1199 1162 &dev_attr_dbc_idProduct.attr, 1200 1163 &dev_attr_dbc_bcdDevice.attr, 1201 1164 &dev_attr_dbc_bInterfaceProtocol.attr, 1165 + &dev_attr_dbc_poll_interval_ms.attr, 1202 1166 NULL 1203 1167 }; 1204 1168 ATTRIBUTE_GROUPS(dbc_dev);
+1 -1
drivers/usb/host/xhci-dbgcap.h
··· 95 95 #define DBC_QUEUE_SIZE 16 96 96 #define DBC_WRITE_BUF_SIZE 8192 97 97 #define DBC_POLL_INTERVAL_DEFAULT 64 /* milliseconds */ 98 - 98 + #define DBC_POLL_INTERVAL_MAX 5000 /* milliseconds */ 99 99 /* 100 100 * Private structure for DbC hardware state: 101 101 */
+19 -21
drivers/usb/host/xhci-mem.c
··· 136 136 if (!ring || !first || !last) 137 137 return; 138 138 139 - /* Set chain bit for 0.95 hosts, and for isoc rings on AMD 0.96 host */ 140 - chain_links = !!(xhci_link_trb_quirk(xhci) || 141 - (ring->type == TYPE_ISOC && 142 - (xhci->quirks & XHCI_AMD_0x96_HOST))); 139 + chain_links = xhci_link_chain_quirk(xhci, ring->type); 143 140 144 141 next = ring->enq_seg->next; 145 142 xhci_link_segments(ring->enq_seg, first, ring->type, chain_links); ··· 153 156 ring->last_seg = last; 154 157 } 155 158 156 - for (seg = last; seg != ring->last_seg; seg = seg->next) 159 + for (seg = ring->enq_seg; seg != ring->last_seg; seg = seg->next) 157 160 seg->next->num = seg->num + 1; 158 161 } 159 162 ··· 324 327 325 328 /* Allocate segments and link them for a ring */ 326 329 static int xhci_alloc_segments_for_ring(struct xhci_hcd *xhci, 327 - struct xhci_segment **first, struct xhci_segment **last, 328 - unsigned int num_segs, unsigned int num, 329 - unsigned int cycle_state, enum xhci_ring_type type, 330 - unsigned int max_packet, gfp_t flags) 330 + struct xhci_segment **first, 331 + struct xhci_segment **last, 332 + unsigned int num_segs, 333 + unsigned int cycle_state, 334 + enum xhci_ring_type type, 335 + unsigned int max_packet, 336 + gfp_t flags) 331 337 { 332 338 struct xhci_segment *prev; 339 + unsigned int num = 0; 333 340 bool chain_links; 334 341 335 - /* Set chain bit for 0.95 hosts, and for isoc rings on AMD 0.96 host */ 336 - chain_links = !!(xhci_link_trb_quirk(xhci) || 337 - (type == TYPE_ISOC && 338 - (xhci->quirks & XHCI_AMD_0x96_HOST))); 342 + chain_links = xhci_link_chain_quirk(xhci, type); 339 343 340 344 prev = xhci_segment_alloc(xhci, cycle_state, max_packet, num, flags); 341 345 if (!prev) ··· 392 394 if (num_segs == 0) 393 395 return ring; 394 396 395 - ret = xhci_alloc_segments_for_ring(xhci, &ring->first_seg, 396 - &ring->last_seg, num_segs, 0, cycle_state, type, 397 - max_packet, flags); 397 + ret = xhci_alloc_segments_for_ring(xhci, &ring->first_seg, &ring->last_seg, num_segs, 398 + cycle_state, type, max_packet, flags); 398 399 if (ret) 399 400 goto fail; 400 401 ··· 431 434 struct xhci_segment *last; 432 435 int ret; 433 436 434 - ret = xhci_alloc_segments_for_ring(xhci, &first, &last, 435 - num_new_segs, ring->enq_seg->num + 1, 436 - ring->cycle_state, ring->type, 437 - ring->bounce_buf_len, flags); 437 + ret = xhci_alloc_segments_for_ring(xhci, &first, &last, num_new_segs, ring->cycle_state, 438 + ring->type, ring->bounce_buf_len, flags); 438 439 if (ret) 439 440 return -ENOMEM; 440 441 ··· 2320 2325 erst_base = xhci_read_64(xhci, &ir->ir_set->erst_base); 2321 2326 erst_base &= ERST_BASE_RSVDP; 2322 2327 erst_base |= ir->erst.erst_dma_addr & ~ERST_BASE_RSVDP; 2323 - xhci_write_64(xhci, erst_base, &ir->ir_set->erst_base); 2328 + if (xhci->quirks & XHCI_WRITE_64_HI_LO) 2329 + hi_lo_writeq(erst_base, &ir->ir_set->erst_base); 2330 + else 2331 + xhci_write_64(xhci, erst_base, &ir->ir_set->erst_base); 2324 2332 2325 2333 /* Set the event ring dequeue address of this interrupter */ 2326 2334 xhci_set_hc_event_deq(xhci, ir);
+1
drivers/usb/host/xhci-pci-renesas.c
··· 627 627 } 628 628 EXPORT_SYMBOL_GPL(renesas_xhci_check_request_fw); 629 629 630 + MODULE_DESCRIPTION("Support for Renesas xHCI controller with firmware"); 630 631 MODULE_LICENSE("GPL v2");
+3 -1
drivers/usb/host/xhci-pci.c
··· 50 50 #define PCI_DEVICE_ID_INTEL_DENVERTON_XHCI 0x19d0 51 51 #define PCI_DEVICE_ID_INTEL_ICE_LAKE_XHCI 0x8a13 52 52 #define PCI_DEVICE_ID_INTEL_TIGER_LAKE_XHCI 0x9a13 53 + #define PCI_DEVICE_ID_INTEL_TIGER_LAKE_PCH_XHCI 0xa0ed 53 54 #define PCI_DEVICE_ID_INTEL_COMET_LAKE_XHCI 0xa3af 54 55 #define PCI_DEVICE_ID_INTEL_ALDER_LAKE_PCH_XHCI 0x51ed 55 56 #define PCI_DEVICE_ID_INTEL_ALDER_LAKE_N_PCH_XHCI 0x54ed ··· 374 373 xhci->quirks |= XHCI_MISSING_CAS; 375 374 376 375 if (pdev->vendor == PCI_VENDOR_ID_INTEL && 377 - (pdev->device == PCI_DEVICE_ID_INTEL_ALDER_LAKE_PCH_XHCI || 376 + (pdev->device == PCI_DEVICE_ID_INTEL_TIGER_LAKE_PCH_XHCI || 377 + pdev->device == PCI_DEVICE_ID_INTEL_ALDER_LAKE_PCH_XHCI || 378 378 pdev->device == PCI_DEVICE_ID_INTEL_ALDER_LAKE_N_PCH_XHCI)) 379 379 xhci->quirks |= XHCI_RESET_TO_DEFAULT; 380 380
+3
drivers/usb/host/xhci-plat.c
··· 256 256 if (device_property_read_bool(tmpdev, "xhci-sg-trb-cache-size-quirk")) 257 257 xhci->quirks |= XHCI_SG_TRB_CACHE_SIZE_QUIRK; 258 258 259 + if (device_property_read_bool(tmpdev, "write-64-hi-lo-quirk")) 260 + xhci->quirks |= XHCI_WRITE_64_HI_LO; 261 + 259 262 device_property_read_u32(tmpdev, "imod-interval-ns", 260 263 &xhci->imod_interval); 261 264 }
+123 -183
drivers/usb/host/xhci-ring.c
··· 250 250 * AMD 0.96 host, carry over the chain bit of the previous TRB 251 251 * (which may mean the chain bit is cleared). 252 252 */ 253 - if (!(ring->type == TYPE_ISOC && 254 - (xhci->quirks & XHCI_AMD_0x96_HOST)) && 255 - !xhci_link_trb_quirk(xhci)) { 253 + if (!xhci_link_chain_quirk(xhci, ring->type)) { 256 254 next->link.control &= cpu_to_le32(~TRB_CHAIN); 257 255 next->link.control |= cpu_to_le32(chain); 258 256 } ··· 281 283 * Only for transfer and command rings where driver is the producer, not for 282 284 * event rings. 283 285 */ 284 - static unsigned int xhci_num_trbs_free(struct xhci_hcd *xhci, struct xhci_ring *ring) 286 + static unsigned int xhci_num_trbs_free(struct xhci_ring *ring) 285 287 { 286 288 struct xhci_segment *enq_seg = ring->enq_seg; 287 289 union xhci_trb *enq = ring->enqueue; ··· 652 654 stream_id); 653 655 return -ENODEV; 654 656 } 655 - /* 656 - * A cancelled TD can complete with a stall if HW cached the trb. 657 - * In this case driver can't find td, but if the ring is empty we 658 - * can move the dequeue pointer to the current enqueue position. 659 - * We shouldn't hit this anymore as cached cancelled TRBs are given back 660 - * after clearing the cache, but be on the safe side and keep it anyway 661 - */ 662 - if (!td) { 663 - if (list_empty(&ep_ring->td_list)) { 664 - new_seg = ep_ring->enq_seg; 665 - new_deq = ep_ring->enqueue; 666 - new_cycle = ep_ring->cycle_state; 667 - xhci_dbg(xhci, "ep ring empty, Set new dequeue = enqueue"); 668 - goto deq_found; 669 - } else { 670 - xhci_warn(xhci, "Can't find new dequeue state, missing td\n"); 671 - return -EINVAL; 672 - } 673 - } 674 657 675 658 hw_dequeue = xhci_get_hw_deq(xhci, dev, ep_index, stream_id); 676 659 new_seg = ep_ring->deq_seg; ··· 688 709 689 710 } while (!cycle_found || !td_last_trb_found); 690 711 691 - deq_found: 692 - 693 712 /* Don't update the ring cycle state for the producer (us). */ 694 713 addr = xhci_trb_virt_to_dma(new_seg, new_deq); 695 714 if (addr == 0) { ··· 715 738 lower_32_bits(addr) | trb_sct | new_cycle, 716 739 upper_32_bits(addr), 717 740 STREAM_ID_FOR_TRB(stream_id), SLOT_ID_FOR_TRB(slot_id) | 718 - EP_ID_FOR_TRB(ep_index) | TRB_TYPE(TRB_SET_DEQ), false); 741 + EP_INDEX_FOR_TRB(ep_index) | TRB_TYPE(TRB_SET_DEQ), false); 719 742 if (ret < 0) { 720 743 xhci_free_command(xhci, cmd); 721 744 return ret; ··· 760 783 } 761 784 } 762 785 763 - /* 764 - * Must be called with xhci->lock held in interrupt context, 765 - * releases and re-acquires xhci->lock 766 - */ 767 786 static void xhci_giveback_urb_in_irq(struct xhci_hcd *xhci, 768 787 struct xhci_td *cur_td, int status) 769 788 { ··· 1484 1511 ring_doorbell_for_active_rings(xhci, slot_id, ep_index); 1485 1512 } 1486 1513 1487 - static void xhci_handle_cmd_enable_slot(struct xhci_hcd *xhci, int slot_id, 1488 - struct xhci_command *command, u32 cmd_comp_code) 1514 + static void xhci_handle_cmd_enable_slot(int slot_id, struct xhci_command *command, 1515 + u32 cmd_comp_code) 1489 1516 { 1490 1517 if (cmd_comp_code == COMP_SUCCESS) 1491 1518 command->slot_id = slot_id; ··· 1510 1537 xhci_free_device_endpoint_resources(xhci, virt_dev, true); 1511 1538 } 1512 1539 1513 - static void xhci_handle_cmd_config_ep(struct xhci_hcd *xhci, int slot_id, 1514 - u32 cmd_comp_code) 1540 + static void xhci_handle_cmd_config_ep(struct xhci_hcd *xhci, int slot_id) 1515 1541 { 1516 1542 struct xhci_virt_device *virt_dev; 1517 1543 struct xhci_input_control_ctx *ctrl_ctx; ··· 1752 1780 cmd_type = TRB_FIELD_TO_TYPE(le32_to_cpu(cmd_trb->generic.field[3])); 1753 1781 switch (cmd_type) { 1754 1782 case TRB_ENABLE_SLOT: 1755 - xhci_handle_cmd_enable_slot(xhci, slot_id, cmd, cmd_comp_code); 1783 + xhci_handle_cmd_enable_slot(slot_id, cmd, cmd_comp_code); 1756 1784 break; 1757 1785 case TRB_DISABLE_SLOT: 1758 1786 xhci_handle_cmd_disable_slot(xhci, slot_id); 1759 1787 break; 1760 1788 case TRB_CONFIG_EP: 1761 1789 if (!cmd->completion) 1762 - xhci_handle_cmd_config_ep(xhci, slot_id, cmd_comp_code); 1790 + xhci_handle_cmd_config_ep(xhci, slot_id); 1763 1791 break; 1764 1792 case TRB_EVAL_CONTEXT: 1765 1793 break; ··· 1877 1905 } while (!(pll_lock_check & 0x1) && --retry_count); 1878 1906 } 1879 1907 1880 - static void handle_port_status(struct xhci_hcd *xhci, 1881 - struct xhci_interrupter *ir, 1882 - union xhci_trb *event) 1908 + static void handle_port_status(struct xhci_hcd *xhci, union xhci_trb *event) 1883 1909 { 1884 1910 struct usb_hcd *hcd; 1885 1911 u32 port_id; ··· 2126 2156 } 2127 2157 } 2128 2158 2129 - /* Check if an error has halted the endpoint ring. The class driver will 2130 - * cleanup the halt for a non-default control endpoint if we indicate a stall. 2131 - * However, a babble and other errors also halt the endpoint ring, and the class 2132 - * driver won't clear the halt in that case, so we need to issue a Set Transfer 2133 - * Ring Dequeue Pointer command manually. 2159 + /* 2160 + * Check if xhci internal endpoint state has gone to a "halt" state due to an 2161 + * error or stall, including default control pipe protocol stall. 2162 + * The internal halt needs to be cleared with a reset endpoint command. 2163 + * 2164 + * External device side is also halted in functional stall cases. Class driver 2165 + * will clear the device halt with a CLEAR_FEATURE(ENDPOINT_HALT) request later. 2134 2166 */ 2135 - static int xhci_requires_manual_halt_cleanup(struct xhci_hcd *xhci, 2136 - struct xhci_ep_ctx *ep_ctx, 2137 - unsigned int trb_comp_code) 2167 + static bool xhci_halted_host_endpoint(struct xhci_ep_ctx *ep_ctx, unsigned int comp_code) 2138 2168 { 2139 - /* TRB completion codes that may require a manual halt cleanup */ 2140 - if (trb_comp_code == COMP_USB_TRANSACTION_ERROR || 2141 - trb_comp_code == COMP_BABBLE_DETECTED_ERROR || 2142 - trb_comp_code == COMP_SPLIT_TRANSACTION_ERROR) 2143 - /* The 0.95 spec says a babbling control endpoint 2144 - * is not halted. The 0.96 spec says it is. Some HW 2145 - * claims to be 0.95 compliant, but it halts the control 2146 - * endpoint anyway. Check if a babble halted the 2147 - * endpoint. 2169 + /* Stall halts both internal and device side endpoint */ 2170 + if (comp_code == COMP_STALL_ERROR) 2171 + return true; 2172 + 2173 + /* TRB completion codes that may require internal halt cleanup */ 2174 + if (comp_code == COMP_USB_TRANSACTION_ERROR || 2175 + comp_code == COMP_BABBLE_DETECTED_ERROR || 2176 + comp_code == COMP_SPLIT_TRANSACTION_ERROR) 2177 + /* 2178 + * The 0.95 spec says a babbling control endpoint is not halted. 2179 + * The 0.96 spec says it is. Some HW claims to be 0.95 2180 + * compliant, but it halts the control endpoint anyway. 2181 + * Check endpoint context if endpoint is halted. 2148 2182 */ 2149 2183 if (GET_EP_CTX_STATE(ep_ctx) == EP_STATE_HALTED) 2150 - return 1; 2184 + return true; 2151 2185 2152 - return 0; 2186 + return false; 2153 2187 } 2154 2188 2155 2189 int xhci_is_vendor_info_code(struct xhci_hcd *xhci, unsigned int trb_comp_code) ··· 2323 2349 case COMP_STOPPED_LENGTH_INVALID: 2324 2350 goto finish_td; 2325 2351 default: 2326 - if (!xhci_requires_manual_halt_cleanup(xhci, 2327 - ep_ctx, trb_comp_code)) 2352 + if (!xhci_halted_host_endpoint(ep_ctx, trb_comp_code)) 2328 2353 break; 2329 2354 xhci_dbg(xhci, "TRB error %u, halted endpoint index = %u\n", 2330 2355 trb_comp_code, ep->ep_index); ··· 2433 2460 requested = remaining; 2434 2461 break; 2435 2462 case COMP_STOPPED_LENGTH_INVALID: 2436 - requested = 0; 2463 + /* exclude stopped trb with invalid length from length sum */ 2464 + sum_trbs_for_length = true; 2465 + ep_trb_len = 0; 2437 2466 remaining = 0; 2438 2467 break; 2439 2468 default: ··· 2564 2589 return finish_td(xhci, ep, ep_ring, td, trb_comp_code); 2565 2590 } 2566 2591 2592 + /* Transfer events which don't point to a transfer TRB, see xhci 4.17.4 */ 2593 + static int handle_transferless_tx_event(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, 2594 + u32 trb_comp_code) 2595 + { 2596 + switch (trb_comp_code) { 2597 + case COMP_STALL_ERROR: 2598 + case COMP_USB_TRANSACTION_ERROR: 2599 + case COMP_INVALID_STREAM_TYPE_ERROR: 2600 + case COMP_INVALID_STREAM_ID_ERROR: 2601 + xhci_dbg(xhci, "Stream transaction error ep %u no id\n", ep->ep_index); 2602 + if (ep->err_count++ > MAX_SOFT_RETRY) 2603 + xhci_handle_halted_endpoint(xhci, ep, NULL, EP_HARD_RESET); 2604 + else 2605 + xhci_handle_halted_endpoint(xhci, ep, NULL, EP_SOFT_RESET); 2606 + break; 2607 + case COMP_RING_UNDERRUN: 2608 + case COMP_RING_OVERRUN: 2609 + case COMP_STOPPED_LENGTH_INVALID: 2610 + break; 2611 + default: 2612 + xhci_err(xhci, "Transfer event %u for unknown stream ring slot %u ep %u\n", 2613 + trb_comp_code, ep->vdev->slot_id, ep->ep_index); 2614 + return -ENODEV; 2615 + } 2616 + return 0; 2617 + } 2618 + 2567 2619 /* 2568 2620 * If this function returns an error condition, it means it got a Transfer 2569 2621 * event with a corrupted Slot ID, Endpoint ID, or TRB DMA address. ··· 2611 2609 int status = -EINPROGRESS; 2612 2610 struct xhci_ep_ctx *ep_ctx; 2613 2611 u32 trb_comp_code; 2614 - int td_num = 0; 2615 2612 2616 2613 slot_id = TRB_TO_SLOT_ID(le32_to_cpu(event->flags)); 2617 2614 ep_index = TRB_TO_EP_ID(le32_to_cpu(event->flags)) - 1; ··· 2633 2632 goto err_out; 2634 2633 } 2635 2634 2636 - /* Some transfer events don't always point to a trb, see xhci 4.17.4 */ 2637 - if (!ep_ring) { 2638 - switch (trb_comp_code) { 2639 - case COMP_STALL_ERROR: 2640 - case COMP_USB_TRANSACTION_ERROR: 2641 - case COMP_INVALID_STREAM_TYPE_ERROR: 2642 - case COMP_INVALID_STREAM_ID_ERROR: 2643 - xhci_dbg(xhci, "Stream transaction error ep %u no id\n", 2644 - ep_index); 2645 - if (ep->err_count++ > MAX_SOFT_RETRY) 2646 - xhci_handle_halted_endpoint(xhci, ep, NULL, 2647 - EP_HARD_RESET); 2648 - else 2649 - xhci_handle_halted_endpoint(xhci, ep, NULL, 2650 - EP_SOFT_RESET); 2651 - break; 2652 - case COMP_RING_UNDERRUN: 2653 - case COMP_RING_OVERRUN: 2654 - case COMP_STOPPED_LENGTH_INVALID: 2655 - break; 2656 - default: 2657 - xhci_err(xhci, "ERROR Transfer event for unknown stream ring slot %u ep %u\n", 2658 - slot_id, ep_index); 2659 - goto err_out; 2660 - } 2661 - return 0; 2662 - } 2663 - 2664 - /* Count current td numbers if ep->skip is set */ 2665 - if (ep->skip) 2666 - td_num += list_count_nodes(&ep_ring->td_list); 2635 + if (!ep_ring) 2636 + return handle_transferless_tx_event(xhci, ep, trb_comp_code); 2667 2637 2668 2638 /* Look for common error cases */ 2669 2639 switch (trb_comp_code) { ··· 2716 2744 * a Ring Overrun Event for IN Isoch endpoint or Ring 2717 2745 * Underrun Event for OUT Isoch endpoint. 2718 2746 */ 2719 - xhci_dbg(xhci, "underrun event on endpoint\n"); 2720 - if (!list_empty(&ep_ring->td_list)) 2721 - xhci_dbg(xhci, "Underrun Event for slot %u ep %d still with TDs queued?\n", 2722 - slot_id, ep_index); 2747 + xhci_dbg(xhci, "Underrun event on slot %u ep %u\n", slot_id, ep_index); 2723 2748 if (ep->skip) 2724 2749 break; 2725 2750 return 0; 2726 2751 case COMP_RING_OVERRUN: 2727 - xhci_dbg(xhci, "overrun event on endpoint\n"); 2728 - if (!list_empty(&ep_ring->td_list)) 2729 - xhci_dbg(xhci, "Overrun Event for slot %u ep %d still with TDs queued?\n", 2730 - slot_id, ep_index); 2752 + xhci_dbg(xhci, "Overrun event on slot %u ep %u\n", slot_id, ep_index); 2731 2753 if (ep->skip) 2732 2754 break; 2733 2755 return 0; ··· 2788 2822 xhci_dbg(xhci, "td_list is empty while skip flag set. Clear skip flag for slot %u ep %u.\n", 2789 2823 slot_id, ep_index); 2790 2824 } 2791 - if (trb_comp_code == COMP_STALL_ERROR || 2792 - xhci_requires_manual_halt_cleanup(xhci, ep_ctx, 2793 - trb_comp_code)) { 2794 - xhci_handle_halted_endpoint(xhci, ep, NULL, 2795 - EP_HARD_RESET); 2796 - } 2797 - return 0; 2798 - } 2799 2825 2800 - /* We've skipped all the TDs on the ep ring when ep->skip set */ 2801 - if (ep->skip && td_num == 0) { 2802 - ep->skip = false; 2803 - xhci_dbg(xhci, "All tds on the ep_ring skipped. Clear skip flag for slot %u ep %u.\n", 2804 - slot_id, ep_index); 2805 - return 0; 2826 + td = NULL; 2827 + goto check_endpoint_halted; 2806 2828 } 2807 2829 2808 2830 td = list_first_entry(&ep_ring->td_list, struct xhci_td, 2809 2831 td_list); 2810 - if (ep->skip) 2811 - td_num--; 2812 2832 2813 2833 /* Is this a TRB in the currently executing TD? */ 2814 2834 ep_seg = trb_in_td(xhci, td, ep_trb_dma, false); 2815 - 2816 - /* 2817 - * Skip the Force Stopped Event. The event_trb(event_dma) of FSE 2818 - * is not in the current TD pointed by ep_ring->dequeue because 2819 - * that the hardware dequeue pointer still at the previous TRB 2820 - * of the current TD. The previous TRB maybe a Link TD or the 2821 - * last TRB of the previous TD. The command completion handle 2822 - * will take care the rest. 2823 - */ 2824 - if (!ep_seg && (trb_comp_code == COMP_STOPPED || 2825 - trb_comp_code == COMP_STOPPED_LENGTH_INVALID)) { 2826 - continue; 2827 - } 2828 2835 2829 2836 if (!ep_seg) { 2830 2837 2831 2838 if (ep->skip && usb_endpoint_xfer_isoc(&td->urb->ep->desc)) { 2832 2839 skip_isoc_td(xhci, td, ep, status); 2833 2840 continue; 2841 + } 2842 + 2843 + /* 2844 + * Skip the Force Stopped Event. The 'ep_trb' of FSE is not in the current 2845 + * TD pointed by 'ep_ring->dequeue' because that the hardware dequeue 2846 + * pointer still at the previous TRB of the current TD. The previous TRB 2847 + * maybe a Link TD or the last TRB of the previous TD. The command 2848 + * completion handle will take care the rest. 2849 + */ 2850 + if (trb_comp_code == COMP_STOPPED || 2851 + trb_comp_code == COMP_STOPPED_LENGTH_INVALID) { 2852 + return 0; 2834 2853 } 2835 2854 2836 2855 /* ··· 2867 2916 return -ESHUTDOWN; 2868 2917 } 2869 2918 } 2870 - if (trb_comp_code == COMP_SHORT_PACKET) 2871 - ep_ring->last_td_was_short = true; 2872 - else 2873 - ep_ring->last_td_was_short = false; 2874 2919 2875 2920 if (ep->skip) { 2876 2921 xhci_dbg(xhci, ··· 2875 2928 ep->skip = false; 2876 2929 } 2877 2930 2878 - ep_trb = &ep_seg->trbs[(ep_trb_dma - ep_seg->dma) / 2879 - sizeof(*ep_trb)]; 2880 - 2881 - trace_xhci_handle_transfer(ep_ring, 2882 - (struct xhci_generic_trb *) ep_trb); 2883 - 2884 - /* 2885 - * No-op TRB could trigger interrupts in a case where 2886 - * a URB was killed and a STALL_ERROR happens right 2887 - * after the endpoint ring stopped. Reset the halted 2888 - * endpoint. Otherwise, the endpoint remains stalled 2889 - * indefinitely. 2890 - */ 2891 - 2892 - if (trb_is_noop(ep_trb)) { 2893 - if (trb_comp_code == COMP_STALL_ERROR || 2894 - xhci_requires_manual_halt_cleanup(xhci, ep_ctx, 2895 - trb_comp_code)) 2896 - xhci_handle_halted_endpoint(xhci, ep, td, 2897 - EP_HARD_RESET); 2898 - } else { 2899 - td->status = status; 2900 - 2901 - /* update the urb's actual_length and give back to the core */ 2902 - if (usb_endpoint_xfer_control(&td->urb->ep->desc)) 2903 - process_ctrl_td(xhci, ep, ep_ring, td, ep_trb, event); 2904 - else if (usb_endpoint_xfer_isoc(&td->urb->ep->desc)) 2905 - process_isoc_td(xhci, ep, ep_ring, td, ep_trb, event); 2906 - else 2907 - process_bulk_intr_td(xhci, ep, ep_ring, td, ep_trb, event); 2908 - } 2909 2931 /* 2910 2932 * If ep->skip is set, it means there are missed tds on the 2911 2933 * endpoint ring need to take care of. ··· 2882 2966 * the event. 2883 2967 */ 2884 2968 } while (ep->skip); 2969 + 2970 + if (trb_comp_code == COMP_SHORT_PACKET) 2971 + ep_ring->last_td_was_short = true; 2972 + else 2973 + ep_ring->last_td_was_short = false; 2974 + 2975 + ep_trb = &ep_seg->trbs[(ep_trb_dma - ep_seg->dma) / sizeof(*ep_trb)]; 2976 + trace_xhci_handle_transfer(ep_ring, (struct xhci_generic_trb *) ep_trb); 2977 + 2978 + /* 2979 + * No-op TRB could trigger interrupts in a case where a URB was killed 2980 + * and a STALL_ERROR happens right after the endpoint ring stopped. 2981 + * Reset the halted endpoint. Otherwise, the endpoint remains stalled 2982 + * indefinitely. 2983 + */ 2984 + 2985 + if (trb_is_noop(ep_trb)) 2986 + goto check_endpoint_halted; 2987 + 2988 + td->status = status; 2989 + 2990 + /* update the urb's actual_length and give back to the core */ 2991 + if (usb_endpoint_xfer_control(&td->urb->ep->desc)) 2992 + process_ctrl_td(xhci, ep, ep_ring, td, ep_trb, event); 2993 + else if (usb_endpoint_xfer_isoc(&td->urb->ep->desc)) 2994 + process_isoc_td(xhci, ep, ep_ring, td, ep_trb, event); 2995 + else 2996 + process_bulk_intr_td(xhci, ep, ep_ring, td, ep_trb, event); 2997 + 2998 + check_endpoint_halted: 2999 + if (xhci_halted_host_endpoint(ep_ctx, trb_comp_code)) 3000 + xhci_handle_halted_endpoint(xhci, ep, td, EP_HARD_RESET); 2885 3001 2886 3002 return 0; 2887 3003 ··· 2953 3005 handle_cmd_completion(xhci, &event->event_cmd); 2954 3006 break; 2955 3007 case TRB_PORT_STATUS: 2956 - handle_port_status(xhci, ir, event); 3008 + handle_port_status(xhci, event); 2957 3009 break; 2958 3010 case TRB_TRANSFER: 2959 3011 handle_tx_event(xhci, ir, &event->trans_event); ··· 3013 3065 } 3014 3066 3015 3067 /* Clear the interrupt pending bit for a specific interrupter. */ 3016 - static void xhci_clear_interrupt_pending(struct xhci_hcd *xhci, 3017 - struct xhci_interrupter *ir) 3068 + static void xhci_clear_interrupt_pending(struct xhci_interrupter *ir) 3018 3069 { 3019 3070 if (!ir->ip_autoclear) { 3020 3071 u32 irq_pending; ··· 3034 3087 int err; 3035 3088 u64 temp; 3036 3089 3037 - xhci_clear_interrupt_pending(xhci, ir); 3090 + xhci_clear_interrupt_pending(ir); 3038 3091 3039 3092 /* Event ring hasn't been allocated yet. */ 3040 3093 if (!ir->event_ring || !ir->event_ring->dequeue) { ··· 3207 3260 3208 3261 if (ep_ring != xhci->cmd_ring) { 3209 3262 new_segs = xhci_ring_expansion_needed(xhci, ep_ring, num_trbs); 3210 - } else if (xhci_num_trbs_free(xhci, ep_ring) <= num_trbs) { 3263 + } else if (xhci_num_trbs_free(ep_ring) <= num_trbs) { 3211 3264 xhci_err(xhci, "Do not support expand command ring\n"); 3212 3265 return -ENOMEM; 3213 3266 } ··· 3225 3278 /* If we're not dealing with 0.95 hardware or isoc rings 3226 3279 * on AMD 0.96 host, clear the chain bit. 3227 3280 */ 3228 - if (!xhci_link_trb_quirk(xhci) && 3229 - !(ep_ring->type == TYPE_ISOC && 3230 - (xhci->quirks & XHCI_AMD_0x96_HOST))) 3281 + if (!xhci_link_chain_quirk(xhci, ep_ring->type)) 3231 3282 ep_ring->enqueue->link.control &= 3232 3283 cpu_to_le32(~TRB_CHAIN); 3233 3284 else ··· 3380 3435 xhci_ring_ep_doorbell(xhci, slot_id, ep_index, stream_id); 3381 3436 } 3382 3437 3383 - static void check_interval(struct xhci_hcd *xhci, struct urb *urb, 3384 - struct xhci_ep_ctx *ep_ctx) 3438 + static void check_interval(struct urb *urb, struct xhci_ep_ctx *ep_ctx) 3385 3439 { 3386 3440 int xhci_interval; 3387 3441 int ep_interval; ··· 3421 3477 struct xhci_ep_ctx *ep_ctx; 3422 3478 3423 3479 ep_ctx = xhci_get_ep_ctx(xhci, xhci->devs[slot_id]->out_ctx, ep_index); 3424 - check_interval(xhci, urb, ep_ctx); 3480 + check_interval(urb, ep_ctx); 3425 3481 3426 3482 return xhci_queue_bulk_tx(xhci, mem_flags, urb, slot_id, ep_index); 3427 3483 } ··· 3667 3723 upper_32_bits(send_addr), 3668 3724 length_field, 3669 3725 field); 3670 - td->num_trbs++; 3671 3726 addr += trb_buff_len; 3672 3727 sent_len = trb_buff_len; 3673 3728 ··· 3693 3750 urb_priv->td[1].last_trb_seg = ring->enq_seg; 3694 3751 field = TRB_TYPE(TRB_NORMAL) | ring->cycle_state | TRB_IOC; 3695 3752 queue_trb(xhci, ring, 0, 0, 0, TRB_INTR_TARGET(0), field); 3696 - urb_priv->td[1].num_trbs++; 3697 3753 } 3698 3754 3699 3755 check_trb_math(urb, enqd_len); ··· 3743 3801 3744 3802 urb_priv = urb->hcpriv; 3745 3803 td = &urb_priv->td[0]; 3746 - td->num_trbs = num_trbs; 3747 3804 3748 3805 /* 3749 3806 * Don't give the first TRB to the hardware (by toggling the cycle bit) ··· 4063 4122 goto cleanup; 4064 4123 } 4065 4124 td = &urb_priv->td[i]; 4066 - td->num_trbs = trbs_per_td; 4067 4125 /* use SIA as default, if frame id is used overwrite it */ 4068 4126 sia_frame_id = TRB_SIA; 4069 4127 if (!(urb->transfer_flags & URB_ISO_ASAP) && ··· 4226 4286 * Check interval value. This should be done before we start to 4227 4287 * calculate the start frame value. 4228 4288 */ 4229 - check_interval(xhci, urb, ep_ctx); 4289 + check_interval(urb, ep_ctx); 4230 4290 4231 4291 /* Calculate the start frame and put it in urb->start_frame. */ 4232 4292 if (HCC_CFC(xhci->hcc_params) && !list_empty(&ep_ring->td_list)) { ··· 4379 4439 int slot_id, unsigned int ep_index, int suspend) 4380 4440 { 4381 4441 u32 trb_slot_id = SLOT_ID_FOR_TRB(slot_id); 4382 - u32 trb_ep_index = EP_ID_FOR_TRB(ep_index); 4442 + u32 trb_ep_index = EP_INDEX_FOR_TRB(ep_index); 4383 4443 u32 type = TRB_TYPE(TRB_STOP_RING); 4384 4444 u32 trb_suspend = SUSPEND_PORT_FOR_TRB(suspend); 4385 4445 ··· 4392 4452 enum xhci_ep_reset_type reset_type) 4393 4453 { 4394 4454 u32 trb_slot_id = SLOT_ID_FOR_TRB(slot_id); 4395 - u32 trb_ep_index = EP_ID_FOR_TRB(ep_index); 4455 + u32 trb_ep_index = EP_INDEX_FOR_TRB(ep_index); 4396 4456 u32 type = TRB_TYPE(TRB_RESET_EP); 4397 4457 4398 4458 if (reset_type == EP_SOFT_RESET)
+4 -1
drivers/usb/host/xhci-trace.h
··· 250 250 TP_PROTO(struct urb *urb), 251 251 TP_ARGS(urb), 252 252 TP_STRUCT__entry( 253 + __string(devname, dev_name(&urb->dev->dev)) 253 254 __field(void *, urb) 254 255 __field(unsigned int, pipe) 255 256 __field(unsigned int, stream) ··· 266 265 __field(int, slot_id) 267 266 ), 268 267 TP_fast_assign( 268 + __assign_str(devname); 269 269 __entry->urb = urb; 270 270 __entry->pipe = urb->pipe; 271 271 __entry->stream = urb->stream_id; ··· 281 279 __entry->type = usb_endpoint_type(&urb->ep->desc); 282 280 __entry->slot_id = urb->dev->slot_id; 283 281 ), 284 - TP_printk("ep%d%s-%s: urb %p pipe %u slot %d length %d/%d sgs %d/%d stream %d flags %08x", 282 + TP_printk("%s ep%d%s-%s: urb %p pipe %u slot %d length %d/%d sgs %d/%d stream %d flags %08x", 283 + __get_str(devname), 285 284 __entry->epnum, __entry->dir_in ? "in" : "out", 286 285 __print_symbolic(__entry->type, 287 286 { USB_ENDPOINT_XFER_INT, "intr" },
+22 -23
drivers/usb/host/xhci.h
··· 17 17 #include <linux/kernel.h> 18 18 #include <linux/usb/hcd.h> 19 19 #include <linux/io-64-nonatomic-lo-hi.h> 20 + #include <linux/io-64-nonatomic-hi-lo.h> 20 21 21 22 /* Code sharing between pci-quirks and xhci hcd */ 22 23 #include "xhci-ext-caps.h" ··· 806 805 __le32 flags; 807 806 }; 808 807 809 - /* Transfer event TRB length bit mask */ 810 - /* bits 0:23 */ 811 - #define EVENT_TRB_LEN(p) ((p) & 0xffffff) 808 + /* Transfer event flags bitfield, also for select command completion events */ 809 + #define TRB_TO_SLOT_ID(p) (((p) >> 24) & 0xff) 810 + #define SLOT_ID_FOR_TRB(p) (((p) & 0xff) << 24) 812 811 813 - /** Transfer Event bit fields **/ 814 - #define TRB_TO_EP_ID(p) (((p) >> 16) & 0x1f) 812 + #define TRB_TO_EP_ID(p) (((p) >> 16) & 0x1f) /* Endpoint ID 1 - 31 */ 813 + #define EP_ID_FOR_TRB(p) (((p) & 0x1f) << 16) 814 + 815 + #define TRB_TO_EP_INDEX(p) (TRB_TO_EP_ID(p) - 1) /* Endpoint index 0 - 30 */ 816 + #define EP_INDEX_FOR_TRB(p) ((((p) + 1) & 0x1f) << 16) 817 + 818 + /* Transfer event TRB length bit mask */ 819 + #define EVENT_TRB_LEN(p) ((p) & 0xffffff) 815 820 816 821 /* Completion Code - only applicable for some types of TRBs */ 817 822 #define COMP_CODE_MASK (0xff << 24) ··· 957 950 __le32 flags; 958 951 }; 959 952 960 - /* flags bitmasks */ 961 - 962 953 /* Address device - disable SetAddress */ 963 954 #define TRB_BSR (1<<9) 964 955 ··· 992 987 993 988 /* bits 16:23 are the virtual function ID */ 994 989 /* bits 24:31 are the slot ID */ 995 - #define TRB_TO_SLOT_ID(p) (((p) & (0xff<<24)) >> 24) 996 - #define SLOT_ID_FOR_TRB(p) (((p) & 0xff) << 24) 997 990 998 991 /* Stop Endpoint TRB - ep_index to endpoint ID for this TRB */ 999 - #define TRB_TO_EP_INDEX(p) ((((p) & (0x1f << 16)) >> 16) - 1) 1000 - #define EP_ID_FOR_TRB(p) ((((p) + 1) & 0x1f) << 16) 1001 - 1002 992 #define SUSPEND_PORT_FOR_TRB(p) (((p) & 1) << 23) 1003 993 #define TRB_TO_SUSPEND_PORT(p) (((p) & (1 << 23)) >> 23) 1004 994 #define LAST_EP_INDEX 30 ··· 1294 1294 /* actual_length of the URB has already been set */ 1295 1295 bool urb_length_set; 1296 1296 bool error_mid_td; 1297 - unsigned int num_trbs; 1298 1297 }; 1299 1298 1300 1299 /* ··· 1627 1628 #define XHCI_RESET_TO_DEFAULT BIT_ULL(44) 1628 1629 #define XHCI_ZHAOXIN_TRB_FETCH BIT_ULL(45) 1629 1630 #define XHCI_ZHAOXIN_HOST BIT_ULL(46) 1631 + #define XHCI_WRITE_64_HI_LO BIT_ULL(47) 1630 1632 1631 1633 unsigned int num_active_eps; 1632 1634 unsigned int limit_active_eps; ··· 1749 1749 lo_hi_writeq(val, regs); 1750 1750 } 1751 1751 1752 - static inline int xhci_link_trb_quirk(struct xhci_hcd *xhci) 1752 + 1753 + /* Link TRB chain should always be set on 0.95 hosts, and AMD 0.96 ISOC rings */ 1754 + static inline bool xhci_link_chain_quirk(struct xhci_hcd *xhci, enum xhci_ring_type type) 1753 1755 { 1754 - return xhci->quirks & XHCI_LINK_TRB_QUIRK; 1756 + return (xhci->quirks & XHCI_LINK_TRB_QUIRK) || 1757 + (type == TYPE_ISOC && (xhci->quirks & XHCI_AMD_0x96_HOST)); 1755 1758 } 1756 1759 1757 1760 /* xHCI debugging */ ··· 2024 2021 field1, field0, 2025 2022 xhci_trb_comp_code_string(GET_COMP_CODE(field2)), 2026 2023 EVENT_TRB_LEN(field2), TRB_TO_SLOT_ID(field3), 2027 - /* Macro decrements 1, maybe it shouldn't?!? */ 2028 - TRB_TO_EP_INDEX(field3) + 1, 2024 + TRB_TO_EP_ID(field3), 2029 2025 xhci_trb_type_string(type), 2030 2026 field3 & EVENT_DATA ? 'E' : 'e', 2031 2027 field3 & TRB_CYCLE ? 'C' : 'c'); ··· 2139 2137 xhci_trb_type_string(type), 2140 2138 field1, field0, 2141 2139 TRB_TO_SLOT_ID(field3), 2142 - /* Macro decrements 1, maybe it shouldn't?!? */ 2143 - TRB_TO_EP_INDEX(field3) + 1, 2140 + TRB_TO_EP_ID(field3), 2144 2141 field3 & TRB_TSP ? 'T' : 't', 2145 2142 field3 & TRB_CYCLE ? 'C' : 'c'); 2146 2143 break; ··· 2149 2148 xhci_trb_type_string(type), 2150 2149 TRB_TO_SLOT_ID(field3), 2151 2150 TRB_TO_SUSPEND_PORT(field3), 2152 - /* Macro decrements 1, maybe it shouldn't?!? */ 2153 - TRB_TO_EP_INDEX(field3) + 1, 2151 + TRB_TO_EP_ID(field3), 2154 2152 field3 & TRB_CYCLE ? 'C' : 'c'); 2155 2153 break; 2156 2154 case TRB_SET_DEQ: ··· 2159 2159 field1, field0, 2160 2160 TRB_TO_STREAM_ID(field2), 2161 2161 TRB_TO_SLOT_ID(field3), 2162 - /* Macro decrements 1, maybe it shouldn't?!? */ 2163 - TRB_TO_EP_INDEX(field3) + 1, 2162 + TRB_TO_EP_ID(field3), 2164 2163 field3 & TRB_CYCLE ? 'C' : 'c'); 2165 2164 break; 2166 2165 case TRB_RESET_DEV:
+1
drivers/usb/misc/ezusb.c
··· 148 148 EXPORT_SYMBOL_GPL(ezusb_fx2_ihex_firmware_download); 149 149 #endif 150 150 151 + MODULE_DESCRIPTION("EZUSB device support"); 151 152 MODULE_LICENSE("GPL");
+1
drivers/usb/misc/isight_firmware.c
··· 127 127 128 128 module_usb_driver(isight_firmware_driver); 129 129 130 + MODULE_DESCRIPTION("iSight firmware loading support"); 130 131 MODULE_LICENSE("GPL"); 131 132 MODULE_AUTHOR("Matthew Garrett <mjg@redhat.com>");
+7 -4
drivers/usb/misc/onboard_usb_dev.c
··· 454 454 return onboard_dev; 455 455 } 456 456 457 + static bool onboard_dev_usbdev_match(struct usb_device *udev) 458 + { 459 + /* Onboard devices using this driver must have a device tree node */ 460 + return !!udev->dev.of_node; 461 + } 462 + 457 463 static int onboard_dev_usbdev_probe(struct usb_device *udev) 458 464 { 459 465 struct device *dev = &udev->dev; 460 466 struct onboard_dev *onboard_dev; 461 467 int err; 462 - 463 - /* ignore supported devices without device tree node */ 464 - if (!dev->of_node) 465 - return -ENODEV; 466 468 467 469 onboard_dev = _find_onboard_dev(dev); 468 470 if (IS_ERR(onboard_dev)) ··· 515 513 516 514 static struct usb_device_driver onboard_dev_usbdev_driver = { 517 515 .name = "onboard-usb-dev", 516 + .match = onboard_dev_usbdev_match, 518 517 .probe = onboard_dev_usbdev_probe, 519 518 .disconnect = onboard_dev_usbdev_disconnect, 520 519 .generic_subclass = 1,
+9 -9
drivers/usb/misc/usb251xb.c
··· 726 726 static SIMPLE_DEV_PM_OPS(usb251xb_pm_ops, usb251xb_suspend, usb251xb_resume); 727 727 728 728 static const struct i2c_device_id usb251xb_id[] = { 729 - { "usb2422", 0 }, 730 - { "usb2512b", 0 }, 731 - { "usb2512bi", 0 }, 732 - { "usb2513b", 0 }, 733 - { "usb2513bi", 0 }, 734 - { "usb2514b", 0 }, 735 - { "usb2514bi", 0 }, 736 - { "usb2517", 0 }, 737 - { "usb2517i", 0 }, 729 + { "usb2422" }, 730 + { "usb2512b" }, 731 + { "usb2512bi" }, 732 + { "usb2513b" }, 733 + { "usb2513bi" }, 734 + { "usb2514b" }, 735 + { "usb2514bi" }, 736 + { "usb2517" }, 737 + { "usb2517i" }, 738 738 { /* sentinel */ } 739 739 }; 740 740 MODULE_DEVICE_TABLE(i2c, usb251xb_id);
+1 -1
drivers/usb/misc/usb3503.c
··· 390 390 usb3503_platform_resume); 391 391 392 392 static const struct i2c_device_id usb3503_id[] = { 393 - { USB3503_I2C_NAME, 0 }, 393 + { USB3503_I2C_NAME }, 394 394 { } 395 395 }; 396 396 MODULE_DEVICE_TABLE(i2c, usb3503_id);
+1 -1
drivers/usb/misc/usb4604.c
··· 135 135 usb4604_i2c_resume); 136 136 137 137 static const struct i2c_device_id usb4604_id[] = { 138 - { "usb4604", 0 }, 138 + { "usb4604" }, 139 139 { } 140 140 }; 141 141 MODULE_DEVICE_TABLE(i2c, usb4604_id);
+1
drivers/usb/misc/yurex.c
··· 531 531 532 532 module_usb_driver(yurex_driver); 533 533 534 + MODULE_DESCRIPTION("USB YUREX driver support"); 534 535 MODULE_LICENSE("GPL");
+1
drivers/usb/mon/mon_main.c
··· 419 419 module_init(mon_init); 420 420 module_exit(mon_exit); 421 421 422 + MODULE_DESCRIPTION("USB Monitor"); 422 423 MODULE_LICENSE("GPL");
+12 -8
drivers/usb/musb/da8xx.c
··· 191 191 spin_unlock_irqrestore(&musb->lock, flags); 192 192 } 193 193 194 - static void da8xx_musb_try_idle(struct musb *musb, unsigned long timeout) 194 + static void __maybe_unused da8xx_musb_try_idle(struct musb *musb, unsigned long timeout) 195 195 { 196 196 static unsigned long last_timer; 197 197 ··· 218 218 usb_otg_state_string(musb->xceiv->otg->state), 219 219 jiffies_to_msecs(timeout - jiffies)); 220 220 mod_timer(&musb->dev_timer, timeout); 221 + } 222 + 223 + static int da8xx_babble_recover(struct musb *musb) 224 + { 225 + dev_dbg(musb->controller, "resetting controller to recover from babble\n"); 226 + musb_writel(musb->ctrl_base, DA8XX_USB_CTRL_REG, DA8XX_SOFT_RESET_MASK); 227 + return 0; 221 228 } 222 229 223 230 static irqreturn_t da8xx_musb_interrupt(int irq, void *hci) ··· 334 327 { 335 328 struct da8xx_glue *glue = dev_get_drvdata(musb->controller->parent); 336 329 enum phy_mode phy_mode; 337 - 338 - /* 339 - * The PHY has some issues when it is forced in device or host mode. 340 - * Unless the user request another mode, configure the PHY in OTG mode. 341 - */ 342 - if (!musb->is_initialized) 343 - return phy_set_mode(glue->phy, PHY_MODE_USB_OTG); 344 330 345 331 switch (musb_mode) { 346 332 case MUSB_HOST: /* Force VBUS valid, ID = 0 */ ··· 483 483 .disable = da8xx_musb_disable, 484 484 485 485 .set_mode = da8xx_musb_set_mode, 486 + 487 + #ifndef CONFIG_USB_MUSB_HOST 486 488 .try_idle = da8xx_musb_try_idle, 489 + #endif 490 + .recover = da8xx_babble_recover, 487 491 488 492 .set_vbus = da8xx_musb_set_vbus, 489 493 };
+2
drivers/usb/musb/mpfs.c
··· 190 190 pdata->config = &mpfs_musb_hdrc_config; 191 191 pdata->platform_ops = &mpfs_ops; 192 192 193 + pdata->extvbus = device_property_read_bool(dev, "microchip,ext-vbus-drv"); 194 + 193 195 pdata->mode = usb_get_dr_mode(dev); 194 196 if (pdata->mode == USB_DR_MODE_UNKNOWN) { 195 197 dev_info(dev, "No dr_mode property found, defaulting to otg\n");
+1
drivers/usb/phy/phy-am335x-control.c
··· 189 189 }; 190 190 191 191 module_platform_driver(am335x_control_driver); 192 + MODULE_DESCRIPTION("AM335x USB PHY Control Driver"); 192 193 MODULE_LICENSE("GPL v2");
+1
drivers/usb/phy/phy-am335x.c
··· 142 142 }; 143 143 144 144 module_platform_driver(am335x_phy_driver); 145 + MODULE_DESCRIPTION("AM335x USB PHY Driver"); 145 146 MODULE_LICENSE("GPL v2");
+4 -3
drivers/usb/storage/uas.c
··· 423 423 uas_log_cmd_state(cmnd, "data cmplt err", status); 424 424 /* error: no data transfered */ 425 425 scsi_set_resid(cmnd, sdb->length); 426 + set_host_byte(cmnd, DID_ERROR); 426 427 } else { 427 428 scsi_set_resid(cmnd, sdb->length - urb->actual_length); 428 429 } ··· 1233 1232 * hang on reboot when the device is still in uas mode. Note the reset is 1234 1233 * necessary as some devices won't revert to usb-storage mode without it. 1235 1234 */ 1236 - static void uas_shutdown(struct device *dev) 1235 + static void uas_shutdown(struct usb_interface *intf) 1237 1236 { 1238 - struct usb_interface *intf = to_usb_interface(dev); 1239 1237 struct usb_device *udev = interface_to_usbdev(intf); 1240 1238 struct Scsi_Host *shost = usb_get_intfdata(intf); 1241 1239 struct uas_dev_info *devinfo = (struct uas_dev_info *)shost->hostdata; ··· 1257 1257 .suspend = uas_suspend, 1258 1258 .resume = uas_resume, 1259 1259 .reset_resume = uas_reset_resume, 1260 - .driver.shutdown = uas_shutdown, 1260 + .shutdown = uas_shutdown, 1261 1261 .id_table = uas_usb_ids, 1262 1262 }; 1263 1263 ··· 1287 1287 module_init(uas_init); 1288 1288 module_exit(uas_exit); 1289 1289 1290 + MODULE_DESCRIPTION("USB Attached SCSI driver"); 1290 1291 MODULE_LICENSE("GPL"); 1291 1292 MODULE_IMPORT_NS(USB_STORAGE); 1292 1293 MODULE_AUTHOR(
+97 -4
drivers/usb/storage/usb.c
··· 68 68 MODULE_DESCRIPTION("USB Mass Storage driver for Linux"); 69 69 MODULE_LICENSE("GPL"); 70 70 71 - static unsigned int delay_use = 1; 72 - module_param(delay_use, uint, S_IRUGO | S_IWUSR); 73 - MODULE_PARM_DESC(delay_use, "seconds to delay before using a new device"); 71 + static unsigned int delay_use = 1 * MSEC_PER_SEC; 72 + 73 + /** 74 + * parse_delay_str - parse an unsigned decimal integer delay 75 + * @str: String to parse. 76 + * @ndecimals: Number of decimal to scale up. 77 + * @suffix: Suffix string to parse. 78 + * @val: Where to store the parsed value. 79 + * 80 + * Parse an unsigned decimal value in @str, optionally end with @suffix. 81 + * Stores the parsed value in @val just as it is if @str ends with @suffix. 82 + * Otherwise store the value scale up by 10^(@ndecimal). 83 + * 84 + * Returns 0 on success, a negative error code otherwise. 85 + */ 86 + static int parse_delay_str(const char *str, int ndecimals, const char *suffix, 87 + unsigned int *val) 88 + { 89 + int n, n2, l; 90 + char buf[16]; 91 + 92 + l = strlen(suffix); 93 + n = strlen(str); 94 + if (n > 0 && str[n - 1] == '\n') 95 + --n; 96 + if (n >= l && !strncmp(&str[n - l], suffix, l)) { 97 + n -= l; 98 + n2 = 0; 99 + } else 100 + n2 = ndecimals; 101 + 102 + if (n + n2 > sizeof(buf) - 1) 103 + return -EINVAL; 104 + 105 + memcpy(buf, str, n); 106 + while (n2-- > 0) 107 + buf[n++] = '0'; 108 + buf[n] = 0; 109 + 110 + return kstrtouint(buf, 10, val); 111 + } 112 + 113 + /** 114 + * format_delay_ms - format an integer value into a delay string 115 + * @val: The integer value to format, scaled by 10^(@ndecimals). 116 + * @ndecimals: Number of decimal to scale down. 117 + * @suffix: Suffix string to format. 118 + * @str: Where to store the formatted string. 119 + * @size: The size of buffer for @str. 120 + * 121 + * Format an integer value in @val scale down by 10^(@ndecimals) without @suffix 122 + * if @val is divisible by 10^(@ndecimals). 123 + * Otherwise format a value in @val just as it is with @suffix 124 + * 125 + * Returns the number of characters written into @str. 126 + */ 127 + static int format_delay_ms(unsigned int val, int ndecimals, const char *suffix, 128 + char *str, int size) 129 + { 130 + u64 delay_ms = val; 131 + unsigned int rem = do_div(delay_ms, int_pow(10, ndecimals)); 132 + int ret; 133 + 134 + if (rem) 135 + ret = scnprintf(str, size, "%u%s\n", val, suffix); 136 + else 137 + ret = scnprintf(str, size, "%u\n", (unsigned int)delay_ms); 138 + return ret; 139 + } 140 + 141 + static int delay_use_set(const char *s, const struct kernel_param *kp) 142 + { 143 + unsigned int delay_ms; 144 + int ret; 145 + 146 + ret = parse_delay_str(skip_spaces(s), 3, "ms", &delay_ms); 147 + if (ret < 0) 148 + return ret; 149 + 150 + *((unsigned int *)kp->arg) = delay_ms; 151 + return 0; 152 + } 153 + 154 + static int delay_use_get(char *s, const struct kernel_param *kp) 155 + { 156 + unsigned int delay_ms = *((unsigned int *)kp->arg); 157 + 158 + return format_delay_ms(delay_ms, 3, "ms", s, PAGE_SIZE); 159 + } 160 + 161 + static const struct kernel_param_ops delay_use_ops = { 162 + .set = delay_use_set, 163 + .get = delay_use_get, 164 + }; 165 + module_param_cb(delay_use, &delay_use_ops, &delay_use, 0644); 166 + MODULE_PARM_DESC(delay_use, "time to delay before using a new device"); 74 167 75 168 static char quirks[128]; 76 169 module_param_string(quirks, quirks, sizeof(quirks), S_IRUGO | S_IWUSR); ··· 1157 1064 if (delay_use > 0) 1158 1065 dev_dbg(dev, "waiting for device to settle before scanning\n"); 1159 1066 queue_delayed_work(system_freezable_wq, &us->scan_dwork, 1160 - delay_use * HZ); 1067 + msecs_to_jiffies(delay_use)); 1161 1068 return 0; 1162 1069 1163 1070 /* We come here if there are any problems */
+1 -1
drivers/usb/typec/altmodes/displayport.c
··· 746 746 dp->alt = alt; 747 747 748 748 alt->desc = "DisplayPort"; 749 - alt->ops = &dp_altmode_ops; 749 + typec_altmode_set_ops(alt, &dp_altmode_ops); 750 750 751 751 if (plug) { 752 752 plug->desc = "Displayport";
+1 -1
drivers/usb/typec/anx7411.c
··· 1566 1566 } 1567 1567 1568 1568 static const struct i2c_device_id anx7411_id[] = { 1569 - {"anx7411", 0}, 1569 + { "anx7411" }, 1570 1570 {} 1571 1571 }; 1572 1572
+17 -1
drivers/usb/typec/class.c
··· 467 467 NULL 468 468 }; 469 469 470 + /** 471 + * typec_altmode_set_ops - Set ops for altmode 472 + * @adev: Handle to the alternate mode 473 + * @ops: Ops for the alternate mode 474 + * 475 + * After setting ops, attribute visiblity needs to be refreshed if the alternate 476 + * mode can be activated. 477 + */ 478 + void typec_altmode_set_ops(struct typec_altmode *adev, 479 + const struct typec_altmode_ops *ops) 480 + { 481 + adev->ops = ops; 482 + sysfs_update_group(&adev->dev.kobj, &typec_altmode_group); 483 + } 484 + EXPORT_SYMBOL_GPL(typec_altmode_set_ops); 485 + 470 486 static int altmode_id_get(struct device *dev) 471 487 { 472 488 struct ida *ids; ··· 2333 2317 continue; 2334 2318 } 2335 2319 2336 - alt->ops = ops; 2320 + typec_altmode_set_ops(alt, ops); 2337 2321 typec_altmode_set_drvdata(alt, drvdata); 2338 2322 altmodes[index] = alt; 2339 2323 index++;
+5 -1
drivers/usb/typec/mux/gpio-sbu-mux.c
··· 66 66 { 67 67 struct gpio_sbu_mux *sbu_mux = typec_mux_get_drvdata(mux); 68 68 69 + if (!sbu_mux->enable_gpio) 70 + return -EOPNOTSUPP; 71 + 69 72 mutex_lock(&sbu_mux->lock); 70 73 71 74 switch (state->mode) { ··· 105 102 106 103 mutex_init(&sbu_mux->lock); 107 104 108 - sbu_mux->enable_gpio = devm_gpiod_get(dev, "enable", GPIOD_OUT_LOW); 105 + sbu_mux->enable_gpio = devm_gpiod_get_optional(dev, "enable", 106 + GPIOD_OUT_LOW); 109 107 if (IS_ERR(sbu_mux->enable_gpio)) 110 108 return dev_err_probe(dev, PTR_ERR(sbu_mux->enable_gpio), 111 109 "unable to acquire enable gpio\n");
+61 -34
drivers/usb/typec/mux/nb7vpq904m.c
··· 69 69 70 70 bool swap_data_lanes; 71 71 struct typec_switch *typec_switch; 72 + struct typec_mux *typec_mux; 72 73 73 74 struct mutex lock; /* protect non-concurrent retimer & switch */ 74 75 ··· 276 275 static int nb7vpq904m_retimer_set(struct typec_retimer *retimer, struct typec_retimer_state *state) 277 276 { 278 277 struct nb7vpq904m *nb7 = typec_retimer_get_drvdata(retimer); 278 + struct typec_mux_state mux_state; 279 279 int ret = 0; 280 280 281 281 mutex_lock(&nb7->lock); ··· 294 292 295 293 mutex_unlock(&nb7->lock); 296 294 297 - return ret; 295 + if (ret) 296 + return ret; 297 + 298 + mux_state.alt = state->alt; 299 + mux_state.data = state->data; 300 + mux_state.mode = state->mode; 301 + 302 + return typec_mux_set(nb7->typec_mux, &mux_state); 298 303 } 299 304 300 305 static const struct regmap_config nb7_regmap = { ··· 330 321 331 322 ep = of_graph_get_endpoint_by_regs(nb7->client->dev.of_node, 1, 0); 332 323 333 - if (ep) { 334 - ret = of_property_count_u32_elems(ep, "data-lanes"); 335 - if (ret == -EINVAL) 336 - /* Property isn't here, consider default mapping */ 337 - goto out_done; 338 - if (ret < 0) 339 - goto out_error; 324 + if (!ep) 325 + return 0; 340 326 341 - if (ret != DATA_LANES_COUNT) { 342 - dev_err(&nb7->client->dev, "expected 4 data lanes\n"); 343 - ret = -EINVAL; 344 - goto out_error; 345 - } 346 327 347 - ret = of_property_read_u32_array(ep, "data-lanes", data_lanes, DATA_LANES_COUNT); 348 - if (ret) 349 - goto out_error; 328 + ret = of_property_count_u32_elems(ep, "data-lanes"); 329 + if (ret == -EINVAL) 330 + /* Property isn't here, consider default mapping */ 331 + goto out_done; 332 + if (ret < 0) 333 + goto out_error; 350 334 351 - for (i = 0; i < ARRAY_SIZE(supported_data_lane_mapping); i++) { 352 - for (j = 0; j < DATA_LANES_COUNT; j++) { 353 - if (data_lanes[j] != supported_data_lane_mapping[i][j]) 354 - break; 355 - } 335 + if (ret != DATA_LANES_COUNT) { 336 + dev_err(&nb7->client->dev, "expected 4 data lanes\n"); 337 + ret = -EINVAL; 338 + goto out_error; 339 + } 356 340 357 - if (j == DATA_LANES_COUNT) 341 + ret = of_property_read_u32_array(ep, "data-lanes", data_lanes, DATA_LANES_COUNT); 342 + if (ret) 343 + goto out_error; 344 + 345 + for (i = 0; i < ARRAY_SIZE(supported_data_lane_mapping); i++) { 346 + for (j = 0; j < DATA_LANES_COUNT; j++) { 347 + if (data_lanes[j] != supported_data_lane_mapping[i][j]) 358 348 break; 359 349 } 360 350 361 - switch (i) { 362 - case NORMAL_LANE_MAPPING: 351 + if (j == DATA_LANES_COUNT) 363 352 break; 364 - case INVERT_LANE_MAPPING: 365 - nb7->swap_data_lanes = true; 366 - dev_info(&nb7->client->dev, "using inverted data lanes mapping\n"); 367 - break; 368 - default: 369 - dev_err(&nb7->client->dev, "invalid data lanes mapping\n"); 370 - ret = -EINVAL; 371 - goto out_error; 372 - } 353 + } 354 + 355 + switch (i) { 356 + case NORMAL_LANE_MAPPING: 357 + break; 358 + case INVERT_LANE_MAPPING: 359 + nb7->swap_data_lanes = true; 360 + dev_info(&nb7->client->dev, "using inverted data lanes mapping\n"); 361 + break; 362 + default: 363 + dev_err(&nb7->client->dev, "invalid data lanes mapping\n"); 364 + ret = -EINVAL; 365 + goto out_error; 373 366 } 374 367 375 368 out_done: ··· 422 411 return dev_err_probe(dev, PTR_ERR(nb7->typec_switch), 423 412 "failed to acquire orientation-switch\n"); 424 413 414 + nb7->typec_mux = fwnode_typec_mux_get(dev->fwnode); 415 + if (IS_ERR(nb7->typec_mux)) { 416 + ret = dev_err_probe(dev, PTR_ERR(nb7->typec_mux), 417 + "Failed to acquire mode-switch\n"); 418 + goto err_switch_put; 419 + } 420 + 425 421 ret = nb7vpq904m_parse_data_lanes_mapping(nb7); 426 422 if (ret) 427 - return ret; 423 + goto err_mux_put; 428 424 429 425 ret = regulator_enable(nb7->vcc_supply); 430 426 if (ret) ··· 474 456 gpiod_set_value(nb7->enable_gpio, 0); 475 457 regulator_disable(nb7->vcc_supply); 476 458 459 + err_mux_put: 460 + typec_mux_put(nb7->typec_mux); 461 + 462 + err_switch_put: 463 + typec_switch_put(nb7->typec_switch); 464 + 477 465 return ret; 478 466 } 479 467 ··· 493 469 gpiod_set_value(nb7->enable_gpio, 0); 494 470 495 471 regulator_disable(nb7->vcc_supply); 472 + 473 + typec_mux_put(nb7->typec_mux); 474 + typec_switch_put(nb7->typec_switch); 496 475 } 497 476 498 477 static const struct i2c_device_id nb7vpq904m_table[] = {
+30 -3
drivers/usb/typec/mux/ptn36502.c
··· 67 67 struct typec_retimer *retimer; 68 68 69 69 struct typec_switch *typec_switch; 70 + struct typec_mux *typec_mux; 70 71 71 72 struct mutex lock; /* protect non-concurrent retimer & switch */ 72 73 ··· 236 235 static int ptn36502_retimer_set(struct typec_retimer *retimer, struct typec_retimer_state *state) 237 236 { 238 237 struct ptn36502 *ptn = typec_retimer_get_drvdata(retimer); 238 + struct typec_mux_state mux_state; 239 239 int ret = 0; 240 240 241 241 mutex_lock(&ptn->lock); ··· 254 252 255 253 mutex_unlock(&ptn->lock); 256 254 257 - return ret; 255 + if (ret) 256 + return ret; 257 + 258 + mux_state.alt = state->alt; 259 + mux_state.data = state->data; 260 + mux_state.mode = state->mode; 261 + 262 + return typec_mux_set(ptn->typec_mux, &mux_state); 258 263 } 259 264 260 265 static int ptn36502_detect(struct ptn36502 *ptn) ··· 330 321 return dev_err_probe(dev, PTR_ERR(ptn->typec_switch), 331 322 "Failed to acquire orientation-switch\n"); 332 323 324 + ptn->typec_mux = fwnode_typec_mux_get(dev->fwnode); 325 + if (IS_ERR(ptn->typec_mux)) { 326 + ret = dev_err_probe(dev, PTR_ERR(ptn->typec_mux), 327 + "Failed to acquire mode-switch\n"); 328 + goto err_switch_put; 329 + } 330 + 333 331 ret = regulator_enable(ptn->vdd18_supply); 334 - if (ret) 335 - return dev_err_probe(dev, ret, "Failed to enable vdd18\n"); 332 + if (ret) { 333 + ret = dev_err_probe(dev, ret, "Failed to enable vdd18\n"); 334 + goto err_mux_put; 335 + } 336 336 337 337 ret = ptn36502_detect(ptn); 338 338 if (ret) ··· 381 363 err_disable_regulator: 382 364 regulator_disable(ptn->vdd18_supply); 383 365 366 + err_mux_put: 367 + typec_mux_put(ptn->typec_mux); 368 + 369 + err_switch_put: 370 + typec_switch_put(ptn->typec_switch); 371 + 384 372 return ret; 385 373 } 386 374 ··· 398 374 typec_switch_unregister(ptn->sw); 399 375 400 376 regulator_disable(ptn->vdd18_supply); 377 + 378 + typec_mux_put(ptn->typec_mux); 379 + typec_switch_put(ptn->typec_switch); 401 380 } 402 381 403 382 static const struct i2c_device_id ptn36502_table[] = {
+2 -2
drivers/usb/typec/tcpm/fusb302.c
··· 1820 1820 MODULE_DEVICE_TABLE(of, fusb302_dt_match); 1821 1821 1822 1822 static const struct i2c_device_id fusb302_i2c_device_id[] = { 1823 - {"typec_fusb302", 0}, 1824 - {}, 1823 + { "typec_fusb302" }, 1824 + {} 1825 1825 }; 1826 1826 MODULE_DEVICE_TABLE(i2c, fusb302_i2c_device_id); 1827 1827
+45 -1
drivers/usb/typec/tcpm/tcpci.c
··· 67 67 return regmap_raw_write(tcpci->regmap, reg, &val, sizeof(u16)); 68 68 } 69 69 70 + static bool tcpci_check_std_output_cap(struct regmap *regmap, u8 mask) 71 + { 72 + unsigned int reg; 73 + int ret; 74 + 75 + ret = regmap_read(regmap, TCPC_STD_OUTPUT_CAP, &reg); 76 + if (ret < 0) 77 + return ret; 78 + 79 + return (reg & mask) == mask; 80 + } 81 + 70 82 static int tcpci_set_cc(struct tcpc_dev *tcpc, enum typec_cc_status cc) 71 83 { 72 84 struct tcpci *tcpci = tcpc_to_tcpci(tcpc); ··· 311 299 return regmap_write(tcpci->regmap, TCPC_TCPC_CTRL, 312 300 (polarity == TYPEC_POLARITY_CC2) ? 313 301 TCPC_TCPC_CTRL_ORIENTATION : 0); 302 + } 303 + 304 + static int tcpci_set_orientation(struct tcpc_dev *tcpc, 305 + enum typec_orientation orientation) 306 + { 307 + struct tcpci *tcpci = tcpc_to_tcpci(tcpc); 308 + unsigned int reg; 309 + 310 + switch (orientation) { 311 + case TYPEC_ORIENTATION_NONE: 312 + /* We can't put a single output into high impedance */ 313 + fallthrough; 314 + case TYPEC_ORIENTATION_NORMAL: 315 + reg = TCPC_CONFIG_STD_OUTPUT_ORIENTATION_NORMAL; 316 + break; 317 + case TYPEC_ORIENTATION_REVERSE: 318 + reg = TCPC_CONFIG_STD_OUTPUT_ORIENTATION_FLIPPED; 319 + break; 320 + } 321 + 322 + return regmap_update_bits(tcpci->regmap, TCPC_CONFIG_STD_OUTPUT, 323 + TCPC_CONFIG_STD_OUTPUT_ORIENTATION_MASK, reg); 314 324 } 315 325 316 326 static void tcpci_set_partner_usb_comm_capable(struct tcpc_dev *tcpc, bool capable) ··· 864 830 if (tcpci->data->vbus_vsafe0v) 865 831 tcpci->tcpc.is_vbus_vsafe0v = tcpci_is_vbus_vsafe0v; 866 832 833 + if (tcpci->data->set_orientation) 834 + tcpci->tcpc.set_orientation = tcpci_set_orientation; 835 + 867 836 err = tcpci_parse_config(tcpci); 868 837 if (err < 0) 869 838 return ERR_PTR(err); ··· 910 873 if (err < 0) 911 874 return err; 912 875 876 + err = tcpci_check_std_output_cap(chip->data.regmap, 877 + TCPC_STD_OUTPUT_CAP_ORIENTATION); 878 + if (err < 0) 879 + return err; 880 + 881 + chip->data.set_orientation = err; 882 + 913 883 chip->tcpci = tcpci_register_port(&client->dev, &chip->data); 914 884 if (IS_ERR(chip->tcpci)) 915 885 return PTR_ERR(chip->tcpci); ··· 947 903 } 948 904 949 905 static const struct i2c_device_id tcpci_id[] = { 950 - { "tcpci", 0 }, 906 + { "tcpci" }, 951 907 { } 952 908 }; 953 909 MODULE_DEVICE_TABLE(i2c, tcpci_id);
+1 -1
drivers/usb/typec/tcpm/tcpci_maxim_core.c
··· 538 538 } 539 539 540 540 static const struct i2c_device_id max_tcpci_id[] = { 541 - { "maxtcpc", 0 }, 541 + { "maxtcpc" }, 542 542 { } 543 543 }; 544 544 MODULE_DEVICE_TABLE(i2c, max_tcpci_id);
+31 -6
drivers/usb/typec/tcpm/tcpm.c
··· 57 57 S(SNK_DISCOVERY_DEBOUNCE), \ 58 58 S(SNK_DISCOVERY_DEBOUNCE_DONE), \ 59 59 S(SNK_WAIT_CAPABILITIES), \ 60 + S(SNK_WAIT_CAPABILITIES_TIMEOUT), \ 60 61 S(SNK_NEGOTIATE_CAPABILITIES), \ 61 62 S(SNK_NEGOTIATE_PPS_CAPABILITIES), \ 62 63 S(SNK_TRANSITION_SINK), \ ··· 944 943 enum tcpm_transmit_type tx_sop_type, 945 944 const struct pd_message *msg) 946 945 { 947 - unsigned long timeout; 946 + unsigned long time_left; 948 947 int ret; 949 948 unsigned int negotiated_rev; 950 949 ··· 969 968 return ret; 970 969 971 970 mutex_unlock(&port->lock); 972 - timeout = wait_for_completion_timeout(&port->tx_complete, 973 - msecs_to_jiffies(PD_T_TCPC_TX_TIMEOUT)); 971 + time_left = wait_for_completion_timeout(&port->tx_complete, 972 + msecs_to_jiffies(PD_T_TCPC_TX_TIMEOUT)); 974 973 mutex_lock(&port->lock); 975 - if (!timeout) 974 + if (!time_left) 976 975 return -ETIMEDOUT; 977 976 978 977 switch (port->tx_status) { ··· 3111 3110 PD_MSG_CTRL_REJECT : 3112 3111 PD_MSG_CTRL_NOT_SUPP, 3113 3112 NONE_AMS); 3114 - } else if (port->state == SNK_WAIT_CAPABILITIES) { 3113 + } else if (port->state == SNK_WAIT_CAPABILITIES || 3114 + port->state == SNK_WAIT_CAPABILITIES_TIMEOUT) { 3115 3115 /* 3116 3116 * This message may be received even if VBUS is not 3117 3117 * present. This is quite unexpected; see USB PD ··· 5043 5041 tcpm_set_state(port, SNK_SOFT_RESET, 5044 5042 PD_T_SINK_WAIT_CAP); 5045 5043 } else { 5046 - tcpm_set_state(port, hard_reset_state(port), 5044 + tcpm_set_state(port, SNK_WAIT_CAPABILITIES_TIMEOUT, 5047 5045 PD_T_SINK_WAIT_CAP); 5048 5046 } 5047 + break; 5048 + case SNK_WAIT_CAPABILITIES_TIMEOUT: 5049 + /* 5050 + * There are some USB PD sources in the field, which do not 5051 + * properly implement the specification and fail to start 5052 + * sending Source Capability messages after a soft reset. The 5053 + * specification suggests to do a hard reset when no Source 5054 + * capability message is received within PD_T_SINK_WAIT_CAP, 5055 + * but that might effectively kil the machine's power source. 5056 + * 5057 + * This slightly diverges from the specification and tries to 5058 + * recover from this by explicitly asking for the capabilities 5059 + * using the Get_Source_Cap control message before falling back 5060 + * to a hard reset. The control message should also be supported 5061 + * and handled by all USB PD source and dual role devices 5062 + * according to the specification. 5063 + */ 5064 + if (tcpm_pd_send_control(port, PD_CTRL_GET_SOURCE_CAP, TCPC_TX_SOP)) 5065 + tcpm_set_state_cond(port, hard_reset_state(port), 0); 5066 + else 5067 + tcpm_set_state(port, hard_reset_state(port), PD_T_SINK_WAIT_CAP); 5049 5068 break; 5050 5069 case SNK_NEGOTIATE_CAPABILITIES: 5051 5070 port->pd_capable = true; ··· 5210 5187 case HARD_RESET_SEND: 5211 5188 if (port->ams != NONE_AMS) 5212 5189 tcpm_ams_finish(port); 5190 + if (!port->self_powered && port->port_type == TYPEC_PORT_SNK) 5191 + dev_err(port->dev, "Initiating hard-reset, which might result in machine power-loss.\n"); 5213 5192 /* 5214 5193 * State machine will be directed to HARD_RESET_START, 5215 5194 * thus set upcoming_state to INVALID_STATE.
+12 -21
drivers/usb/typec/tipd/core.c
··· 892 892 return 0; 893 893 } 894 894 895 - static int tps_request_firmware(struct tps6598x *tps, const struct firmware **fw) 895 + static int tps_request_firmware(struct tps6598x *tps, const struct firmware **fw, 896 + const char **firmware_name) 896 897 { 897 - const char *firmware_name; 898 898 int ret; 899 899 900 900 ret = device_property_read_string(tps->dev, "firmware-name", 901 - &firmware_name); 901 + firmware_name); 902 902 if (ret) 903 903 return ret; 904 904 905 - ret = request_firmware(fw, firmware_name, tps->dev); 905 + ret = request_firmware(fw, *firmware_name, tps->dev); 906 906 if (ret) { 907 - dev_err(tps->dev, "failed to retrieve \"%s\"\n", firmware_name); 907 + dev_err(tps->dev, "failed to retrieve \"%s\"\n", *firmware_name); 908 908 return ret; 909 909 } 910 910 ··· 999 999 u32 addr; 1000 1000 struct device_node *np = tps->dev->of_node; 1001 1001 1002 - ret = device_property_read_string(tps->dev, "firmware-name", 1003 - &firmware_name); 1004 - if (ret) 1005 - return ret; 1006 - 1007 - ret = tps_request_firmware(tps, &fw); 1002 + ret = tps_request_firmware(tps, &fw, &firmware_name); 1008 1003 if (ret) 1009 1004 return ret; 1010 1005 ··· 1150 1155 const char *firmware_name; 1151 1156 int ret; 1152 1157 1153 - ret = device_property_read_string(tps->dev, "firmware-name", 1154 - &firmware_name); 1155 - if (ret) 1156 - return ret; 1157 - 1158 - ret = tps_request_firmware(tps, &fw); 1158 + ret = tps_request_firmware(tps, &fw, &firmware_name); 1159 1159 if (ret) 1160 1160 return ret; 1161 1161 ··· 1165 1175 1166 1176 bytes_left = fw->size; 1167 1177 while (bytes_left) { 1168 - if (bytes_left < TPS_MAX_LEN) 1169 - in_len = bytes_left; 1170 - else 1171 - in_len = TPS_MAX_LEN; 1178 + in_len = min(bytes_left, TPS_MAX_LEN); 1172 1179 ret = tps6598x_exec_cmd(tps, "PTCd", in_len, 1173 1180 fw->data + copied_bytes, 1174 1181 TPS_PTCD_OUT_BYTES, out); ··· 1192 1205 1193 1206 release_fw: 1194 1207 release_firmware(fw); 1208 + if (ret) { 1209 + dev_err(tps->dev, "Failed to write patch %s of %zu bytes\n", 1210 + firmware_name, fw->size); 1211 + } 1195 1212 1196 1213 return ret; 1197 1214 };
+9
drivers/usb/typec/ucsi/Kconfig
··· 69 69 To compile the driver as a module, choose M here: the module will be 70 70 called ucsi_glink. 71 71 72 + config UCSI_LENOVO_YOGA_C630 73 + tristate "UCSI Interface Driver for Lenovo Yoga C630" 74 + depends on EC_LENOVO_YOGA_C630 75 + help 76 + This driver enables UCSI support on the Lenovo Yoga C630 laptop. 77 + 78 + To compile the driver as a module, choose M here: the module will be 79 + called ucsi_yoga_c630. 80 + 72 81 endif
+1
drivers/usb/typec/ucsi/Makefile
··· 21 21 obj-$(CONFIG_UCSI_CCG) += ucsi_ccg.o 22 22 obj-$(CONFIG_UCSI_STM32G0) += ucsi_stm32g0.o 23 23 obj-$(CONFIG_UCSI_PMIC_GLINK) += ucsi_glink.o 24 + obj-$(CONFIG_UCSI_LENOVO_YOGA_C630) += ucsi_yoga_c630.o
+1 -1
drivers/usb/typec/ucsi/displayport.c
··· 333 333 dp->con = con; 334 334 dp->alt = alt; 335 335 336 - alt->ops = &ucsi_displayport_ops; 336 + typec_altmode_set_ops(alt, &ucsi_displayport_ops); 337 337 typec_altmode_set_drvdata(alt, dp); 338 338 339 339 return alt;
+32
drivers/usb/typec/ucsi/psy.c
··· 20 20 }; 21 21 22 22 static enum power_supply_property ucsi_psy_props[] = { 23 + POWER_SUPPLY_PROP_CHARGE_TYPE, 23 24 POWER_SUPPLY_PROP_USB_TYPE, 24 25 POWER_SUPPLY_PROP_ONLINE, 25 26 POWER_SUPPLY_PROP_VOLTAGE_MIN, ··· 195 194 return 0; 196 195 } 197 196 197 + static int ucsi_psy_get_charge_type(struct ucsi_connector *con, union power_supply_propval *val) 198 + { 199 + if (!(con->status.flags & UCSI_CONSTAT_CONNECTED)) { 200 + val->intval = POWER_SUPPLY_CHARGE_TYPE_NONE; 201 + return 0; 202 + } 203 + 204 + /* The Battery Charging Cabability Status field is only valid in sink role. */ 205 + if ((con->status.flags & UCSI_CONSTAT_PWR_DIR) != TYPEC_SINK) { 206 + val->intval = POWER_SUPPLY_CHARGE_TYPE_UNKNOWN; 207 + return 0; 208 + } 209 + 210 + switch (UCSI_CONSTAT_BC_STATUS(con->status.pwr_status)) { 211 + case UCSI_CONSTAT_BC_NOMINAL_CHARGING: 212 + val->intval = POWER_SUPPLY_CHARGE_TYPE_STANDARD; 213 + break; 214 + case UCSI_CONSTAT_BC_SLOW_CHARGING: 215 + case UCSI_CONSTAT_BC_TRICKLE_CHARGING: 216 + val->intval = POWER_SUPPLY_CHARGE_TYPE_TRICKLE; 217 + break; 218 + default: 219 + val->intval = POWER_SUPPLY_CHARGE_TYPE_NONE; 220 + break; 221 + } 222 + 223 + return 0; 224 + } 225 + 198 226 static int ucsi_psy_get_prop(struct power_supply *psy, 199 227 enum power_supply_property psp, 200 228 union power_supply_propval *val) ··· 231 201 struct ucsi_connector *con = power_supply_get_drvdata(psy); 232 202 233 203 switch (psp) { 204 + case POWER_SUPPLY_PROP_CHARGE_TYPE: 205 + return ucsi_psy_get_charge_type(con, val); 234 206 case POWER_SUPPLY_PROP_USB_TYPE: 235 207 return ucsi_psy_get_usb_type(con, val); 236 208 case POWER_SUPPLY_PROP_ONLINE:
+184 -106
drivers/usb/typec/ucsi/ucsi.c
··· 36 36 */ 37 37 #define UCSI_SWAP_TIMEOUT_MS 5000 38 38 39 - static int ucsi_read_message_in(struct ucsi *ucsi, void *buf, 40 - size_t buf_size) 39 + void ucsi_notify_common(struct ucsi *ucsi, u32 cci) 41 40 { 42 - /* 43 - * Below UCSI 2.0, MESSAGE_IN was limited to 16 bytes. Truncate the 44 - * reads here. 45 - */ 46 - if (ucsi->version <= UCSI_VERSION_1_2) 47 - buf_size = clamp(buf_size, 0, 16); 41 + if (UCSI_CCI_CONNECTOR(cci)) 42 + ucsi_connector_change(ucsi, UCSI_CCI_CONNECTOR(cci)); 48 43 49 - return ucsi->ops->read(ucsi, UCSI_MESSAGE_IN, buf, buf_size); 44 + if (cci & UCSI_CCI_ACK_COMPLETE && 45 + test_bit(ACK_PENDING, &ucsi->flags)) 46 + complete(&ucsi->complete); 47 + 48 + if (cci & UCSI_CCI_COMMAND_COMPLETE && 49 + test_bit(COMMAND_PENDING, &ucsi->flags)) 50 + complete(&ucsi->complete); 50 51 } 52 + EXPORT_SYMBOL_GPL(ucsi_notify_common); 53 + 54 + int ucsi_sync_control_common(struct ucsi *ucsi, u64 command) 55 + { 56 + bool ack = UCSI_COMMAND(command) == UCSI_ACK_CC_CI; 57 + int ret; 58 + 59 + if (ack) 60 + set_bit(ACK_PENDING, &ucsi->flags); 61 + else 62 + set_bit(COMMAND_PENDING, &ucsi->flags); 63 + 64 + ret = ucsi->ops->async_control(ucsi, command); 65 + if (ret) 66 + goto out_clear_bit; 67 + 68 + if (!wait_for_completion_timeout(&ucsi->complete, 5 * HZ)) 69 + ret = -ETIMEDOUT; 70 + 71 + out_clear_bit: 72 + if (ack) 73 + clear_bit(ACK_PENDING, &ucsi->flags); 74 + else 75 + clear_bit(COMMAND_PENDING, &ucsi->flags); 76 + 77 + return ret; 78 + } 79 + EXPORT_SYMBOL_GPL(ucsi_sync_control_common); 51 80 52 81 static int ucsi_acknowledge(struct ucsi *ucsi, bool conn_ack) 53 82 { ··· 89 60 ctrl |= UCSI_ACK_CONNECTOR_CHANGE; 90 61 } 91 62 92 - return ucsi->ops->sync_write(ucsi, UCSI_CONTROL, &ctrl, sizeof(ctrl)); 63 + return ucsi->ops->sync_control(ucsi, ctrl); 93 64 } 94 65 95 - static int ucsi_exec_command(struct ucsi *ucsi, u64 command); 96 - 97 - static int ucsi_read_error(struct ucsi *ucsi) 66 + static int ucsi_run_command(struct ucsi *ucsi, u64 command, u32 *cci, 67 + void *data, size_t size, bool conn_ack) 98 68 { 99 - u16 error; 100 - int ret; 69 + int ret, err; 101 70 102 - /* Acknowledge the command that failed */ 103 - ret = ucsi_acknowledge(ucsi, false); 71 + *cci = 0; 72 + 73 + /* 74 + * Below UCSI 2.0, MESSAGE_IN was limited to 16 bytes. Truncate the 75 + * reads here. 76 + */ 77 + if (ucsi->version <= UCSI_VERSION_1_2) 78 + size = clamp(size, 0, 16); 79 + 80 + ret = ucsi->ops->sync_control(ucsi, command); 104 81 if (ret) 105 82 return ret; 106 83 107 - ret = ucsi_exec_command(ucsi, UCSI_GET_ERROR_STATUS); 84 + ret = ucsi->ops->read_cci(ucsi, cci); 85 + if (ret) 86 + return ret; 87 + 88 + if (*cci & UCSI_CCI_BUSY) 89 + return -EBUSY; 90 + 91 + if (!(*cci & UCSI_CCI_COMMAND_COMPLETE)) 92 + return -EIO; 93 + 94 + if (*cci & UCSI_CCI_NOT_SUPPORTED) 95 + err = -EOPNOTSUPP; 96 + else if (*cci & UCSI_CCI_ERROR) 97 + err = -EIO; 98 + else 99 + err = 0; 100 + 101 + if (!err && data && UCSI_CCI_LENGTH(*cci)) 102 + err = ucsi->ops->read_message_in(ucsi, data, size); 103 + 104 + /* 105 + * Don't ACK connection change if there was an error. 106 + */ 107 + ret = ucsi_acknowledge(ucsi, err ? false : conn_ack); 108 + if (ret) 109 + return ret; 110 + 111 + return err; 112 + } 113 + 114 + static int ucsi_read_error(struct ucsi *ucsi, u8 connector_num) 115 + { 116 + u64 command; 117 + u16 error; 118 + u32 cci; 119 + int ret; 120 + 121 + command = UCSI_GET_ERROR_STATUS | UCSI_CONNECTOR_NUMBER(connector_num); 122 + ret = ucsi_run_command(ucsi, command, &cci, 123 + &error, sizeof(error), false); 124 + 125 + if (cci & UCSI_CCI_BUSY) { 126 + ret = ucsi_run_command(ucsi, UCSI_CANCEL, &cci, NULL, 0, false); 127 + 128 + return ret ? ret : -EBUSY; 129 + } 130 + 108 131 if (ret < 0) 109 132 return ret; 110 133 111 - ret = ucsi_read_message_in(ucsi, &error, sizeof(error)); 112 - if (ret) 113 - return ret; 114 - 115 - ret = ucsi_acknowledge(ucsi, false); 116 - if (ret) 117 - return ret; 134 + if (cci & UCSI_CCI_ERROR) 135 + return -EIO; 118 136 119 137 switch (error) { 120 138 case UCSI_ERROR_INCOMPATIBLE_PARTNER: ··· 193 117 case UCSI_ERROR_SWAP_REJECTED: 194 118 dev_warn(ucsi->dev, "Swap rejected\n"); 195 119 break; 120 + case UCSI_ERROR_REVERSE_CURRENT_PROTECTION: 121 + dev_warn(ucsi->dev, "Reverse Current Protection detected\n"); 122 + break; 123 + case UCSI_ERROR_SET_SINK_PATH_REJECTED: 124 + dev_warn(ucsi->dev, "Set Sink Path rejected\n"); 125 + break; 196 126 case UCSI_ERROR_UNDEFINED: 197 127 default: 198 128 dev_err(ucsi->dev, "unknown error %u\n", error); ··· 208 126 return -EIO; 209 127 } 210 128 211 - static int ucsi_exec_command(struct ucsi *ucsi, u64 cmd) 129 + static int ucsi_send_command_common(struct ucsi *ucsi, u64 cmd, 130 + void *data, size_t size, bool conn_ack) 212 131 { 132 + u8 connector_num; 213 133 u32 cci; 214 134 int ret; 215 135 216 - ret = ucsi->ops->sync_write(ucsi, UCSI_CONTROL, &cmd, sizeof(cmd)); 217 - if (ret) 218 - return ret; 219 - 220 - ret = ucsi->ops->read(ucsi, UCSI_CCI, &cci, sizeof(cci)); 221 - if (ret) 222 - return ret; 223 - 224 - if (cmd != UCSI_CANCEL && cci & UCSI_CCI_BUSY) 225 - return ucsi_exec_command(ucsi, UCSI_CANCEL); 226 - 227 - if (!(cci & UCSI_CCI_COMMAND_COMPLETE)) 228 - return -EIO; 229 - 230 - if (cci & UCSI_CCI_NOT_SUPPORTED) { 231 - if (ucsi_acknowledge(ucsi, false) < 0) 232 - dev_err(ucsi->dev, 233 - "ACK of unsupported command failed\n"); 234 - return -EOPNOTSUPP; 235 - } 236 - 237 - if (cci & UCSI_CCI_ERROR) { 238 - if (cmd == UCSI_GET_ERROR_STATUS) { 239 - ret = ucsi_acknowledge(ucsi, false); 240 - if (ret) 241 - return ret; 242 - 243 - return -EIO; 136 + if (ucsi->version > UCSI_VERSION_1_2) { 137 + switch (UCSI_COMMAND(cmd)) { 138 + case UCSI_GET_ALTERNATE_MODES: 139 + connector_num = UCSI_GET_ALTMODE_GET_CONNECTOR_NUMBER(cmd); 140 + break; 141 + case UCSI_PPM_RESET: 142 + case UCSI_CANCEL: 143 + case UCSI_ACK_CC_CI: 144 + case UCSI_SET_NOTIFICATION_ENABLE: 145 + case UCSI_GET_CAPABILITY: 146 + connector_num = 0; 147 + break; 148 + default: 149 + connector_num = UCSI_DEFAULT_GET_CONNECTOR_NUMBER(cmd); 150 + break; 244 151 } 245 - return ucsi_read_error(ucsi); 152 + } else { 153 + connector_num = 0; 246 154 } 247 - 248 - if (cmd == UCSI_CANCEL && cci & UCSI_CCI_CANCEL_COMPLETE) { 249 - ret = ucsi_acknowledge(ucsi, false); 250 - return ret ? ret : -EBUSY; 251 - } 252 - 253 - return UCSI_CCI_LENGTH(cci); 254 - } 255 - 256 - static int ucsi_send_command_common(struct ucsi *ucsi, u64 command, 257 - void *data, size_t size, bool conn_ack) 258 - { 259 - u8 length; 260 - int ret; 261 155 262 156 mutex_lock(&ucsi->ppm_lock); 263 157 264 - ret = ucsi_exec_command(ucsi, command); 265 - if (ret < 0) 266 - goto out; 267 - 268 - length = ret; 269 - 270 - if (data) { 271 - ret = ucsi_read_message_in(ucsi, data, size); 272 - if (ret) 273 - goto out; 158 + ret = ucsi_run_command(ucsi, cmd, &cci, data, size, conn_ack); 159 + if (cci & UCSI_CCI_BUSY) { 160 + ret = ucsi_run_command(ucsi, UCSI_CANCEL, &cci, NULL, 0, false); 161 + return ret ? ret : -EBUSY; 274 162 } 275 163 276 - ret = ucsi_acknowledge(ucsi, conn_ack); 277 - if (ret) 278 - goto out; 164 + if (cci & UCSI_CCI_ERROR) 165 + return ucsi_read_error(ucsi, connector_num); 279 166 280 - ret = length; 281 - out: 282 167 mutex_unlock(&ucsi->ppm_lock); 283 168 return ret; 284 169 } ··· 695 646 static int ucsi_get_pdos(struct ucsi_connector *con, enum typec_role role, 696 647 int is_partner, u32 *pdos) 697 648 { 649 + struct ucsi *ucsi = con->ucsi; 698 650 u8 num_pdos; 699 651 int ret; 652 + 653 + if (!(ucsi->cap.features & UCSI_CAP_PDO_DETAILS)) 654 + return 0; 700 655 701 656 /* UCSI max payload means only getting at most 4 PDOs at a time */ 702 657 ret = ucsi_read_pdos(con, role, is_partner, pdos, 0, UCSI_MAX_PDOS); ··· 870 817 /* Ignoring the errors in this case. */ 871 818 if (con->partner_altmode[0]) { 872 819 num_partner_am = ucsi_get_num_altmode(con->partner_altmode); 873 - if (num_partner_am > 0) 874 - typec_partner_set_num_altmodes(con->partner, num_partner_am); 820 + typec_partner_set_num_altmodes(con->partner, num_partner_am); 875 821 ucsi_altmode_update_active(con); 876 822 return 0; 823 + } else { 824 + typec_partner_set_num_altmodes(con->partner, 0); 877 825 } 878 826 879 827 return ret; ··· 1022 968 con->rdo = con->status.request_data_obj; 1023 969 typec_set_pwr_opmode(con->port, TYPEC_PWR_MODE_PD); 1024 970 ucsi_partner_task(con, ucsi_get_src_pdos, 30, 0); 1025 - ucsi_partner_task(con, ucsi_check_altmodes, 30, 0); 971 + ucsi_partner_task(con, ucsi_check_altmodes, 30, HZ); 1026 972 ucsi_partner_task(con, ucsi_register_partner_pdos, 1, HZ); 1027 973 break; 1028 974 case UCSI_CONSTAT_PWR_OPMODE_TYPEC1_5: ··· 1197 1143 static int ucsi_check_cable(struct ucsi_connector *con) 1198 1144 { 1199 1145 u64 command; 1200 - int ret; 1146 + int ret, num_plug_am; 1201 1147 1202 1148 if (con->cable) 1203 1149 return 0; ··· 1229 1175 ret = ucsi_register_altmodes(con, UCSI_RECIPIENT_SOP_P); 1230 1176 if (ret < 0) 1231 1177 return ret; 1178 + 1179 + if (con->plug_altmode[0]) { 1180 + num_plug_am = ucsi_get_num_altmode(con->plug_altmode); 1181 + typec_plug_set_num_altmodes(con->plug, num_plug_am); 1182 + } else { 1183 + typec_plug_set_num_altmodes(con->plug, 0); 1184 + } 1232 1185 } 1233 1186 1234 1187 return 0; ··· 1313 1252 } 1314 1253 1315 1254 if (con->status.change & UCSI_CONSTAT_CAM_CHANGE) 1316 - ucsi_partner_task(con, ucsi_check_altmodes, 1, 0); 1255 + ucsi_partner_task(con, ucsi_check_altmodes, 1, HZ); 1256 + 1257 + if (con->status.change & UCSI_CONSTAT_BC_CHANGE) 1258 + ucsi_port_psy_changed(con); 1317 1259 1318 1260 out_unlock: 1319 1261 mutex_unlock(&con->lock); ··· 1362 1298 1363 1299 mutex_lock(&ucsi->ppm_lock); 1364 1300 1365 - ret = ucsi->ops->read(ucsi, UCSI_CCI, &cci, sizeof(cci)); 1301 + ret = ucsi->ops->read_cci(ucsi, &cci); 1366 1302 if (ret < 0) 1367 1303 goto out; 1368 1304 ··· 1374 1310 */ 1375 1311 if (cci & UCSI_CCI_RESET_COMPLETE) { 1376 1312 command = UCSI_SET_NOTIFICATION_ENABLE; 1377 - ret = ucsi->ops->async_write(ucsi, UCSI_CONTROL, &command, 1378 - sizeof(command)); 1313 + ret = ucsi->ops->async_control(ucsi, command); 1379 1314 if (ret < 0) 1380 1315 goto out; 1381 1316 1382 1317 tmo = jiffies + msecs_to_jiffies(UCSI_TIMEOUT_MS); 1383 1318 do { 1384 - ret = ucsi->ops->read(ucsi, UCSI_CCI, 1385 - &cci, sizeof(cci)); 1319 + ret = ucsi->ops->read_cci(ucsi, &cci); 1386 1320 if (ret < 0) 1387 1321 goto out; 1388 1322 if (cci & UCSI_CCI_COMMAND_COMPLETE) ··· 1394 1332 } 1395 1333 1396 1334 command = UCSI_PPM_RESET; 1397 - ret = ucsi->ops->async_write(ucsi, UCSI_CONTROL, &command, 1398 - sizeof(command)); 1335 + ret = ucsi->ops->async_control(ucsi, command); 1399 1336 if (ret < 0) 1400 1337 goto out; 1401 1338 ··· 1409 1348 /* Give the PPM time to process a reset before reading CCI */ 1410 1349 msleep(20); 1411 1350 1412 - ret = ucsi->ops->read(ucsi, UCSI_CCI, &cci, sizeof(cci)); 1351 + ret = ucsi->ops->read_cci(ucsi, &cci); 1413 1352 if (ret) 1414 1353 goto out; 1415 1354 1416 1355 /* If the PPM is still doing something else, reset it again. */ 1417 1356 if (cci & ~UCSI_CCI_RESET_COMPLETE) { 1418 - ret = ucsi->ops->async_write(ucsi, UCSI_CONTROL, 1419 - &command, 1420 - sizeof(command)); 1357 + ret = ucsi->ops->async_control(ucsi, command); 1421 1358 if (ret < 0) 1422 1359 goto out; 1423 1360 } ··· 1728 1669 1729 1670 static u64 ucsi_get_supported_notifications(struct ucsi *ucsi) 1730 1671 { 1731 - u8 features = ucsi->cap.features; 1672 + u16 features = ucsi->cap.features; 1732 1673 u64 ntfy = UCSI_ENABLE_NTFY_ALL; 1733 1674 1734 1675 if (!(features & UCSI_CAP_ALT_MODE_DETAILS)) ··· 1743 1684 1744 1685 if (!(features & UCSI_CAP_PD_RESET)) 1745 1686 ntfy &= ~UCSI_ENABLE_NTFY_PD_RESET_COMPLETE; 1687 + 1688 + if (ucsi->version <= UCSI_VERSION_1_2) 1689 + return ntfy; 1690 + 1691 + ntfy |= UCSI_ENABLE_NTFY_SINK_PATH_STS_CHANGE; 1692 + 1693 + if (features & UCSI_CAP_GET_ATTENTION_VDO) 1694 + ntfy |= UCSI_ENABLE_NTFY_ATTENTION; 1695 + 1696 + if (features & UCSI_CAP_FW_UPDATE_REQUEST) 1697 + ntfy |= UCSI_ENABLE_NTFY_LPM_FW_UPDATE_REQ; 1698 + 1699 + if (features & UCSI_CAP_SECURITY_REQUEST) 1700 + ntfy |= UCSI_ENABLE_NTFY_SECURITY_REQ_PARTNER; 1701 + 1702 + if (features & UCSI_CAP_SET_RETIMER_MODE) 1703 + ntfy |= UCSI_ENABLE_NTFY_SET_RETIMER_MODE; 1746 1704 1747 1705 return ntfy; 1748 1706 } ··· 1829 1753 ucsi->ntfy = ntfy; 1830 1754 1831 1755 mutex_lock(&ucsi->ppm_lock); 1832 - ret = ucsi->ops->read(ucsi, UCSI_CCI, &cci, sizeof(cci)); 1756 + ret = ucsi->ops->read_cci(ucsi, &cci); 1833 1757 mutex_unlock(&ucsi->ppm_lock); 1834 1758 if (ret) 1835 1759 return ret; ··· 1943 1867 { 1944 1868 struct ucsi *ucsi; 1945 1869 1946 - if (!ops || !ops->read || !ops->sync_write || !ops->async_write) 1870 + if (!ops || 1871 + !ops->read_version || !ops->read_cci || !ops->read_message_in || 1872 + !ops->sync_control || !ops->async_control) 1947 1873 return ERR_PTR(-EINVAL); 1948 1874 1949 1875 ucsi = kzalloc(sizeof(*ucsi), GFP_KERNEL); ··· 1955 1877 INIT_WORK(&ucsi->resume_work, ucsi_resume_work); 1956 1878 INIT_DELAYED_WORK(&ucsi->work, ucsi_init_work); 1957 1879 mutex_init(&ucsi->ppm_lock); 1880 + init_completion(&ucsi->complete); 1958 1881 ucsi->dev = dev; 1959 1882 ucsi->ops = ops; 1960 1883 ··· 1982 1903 { 1983 1904 int ret; 1984 1905 1985 - ret = ucsi->ops->read(ucsi, UCSI_VERSION, &ucsi->version, 1986 - sizeof(ucsi->version)); 1906 + ret = ucsi->ops->read_version(ucsi, &ucsi->version); 1987 1907 if (ret) 1988 1908 return ret; 1989 1909 ··· 2021 1943 cancel_work_sync(&ucsi->resume_work); 2022 1944 2023 1945 /* Disable notifications */ 2024 - ucsi->ops->async_write(ucsi, UCSI_CONTROL, &cmd, sizeof(cmd)); 1946 + ucsi->ops->async_control(ucsi, cmd); 2025 1947 2026 1948 if (!ucsi->connector) 2027 1949 return;
+48 -24
drivers/usb/typec/ucsi/ucsi.h
··· 4 4 #define __DRIVER_USB_TYPEC_UCSI_H 5 5 6 6 #include <linux/bitops.h> 7 + #include <linux/completion.h> 7 8 #include <linux/device.h> 8 9 #include <linux/power_supply.h> 9 10 #include <linux/types.h> ··· 57 56 58 57 /** 59 58 * struct ucsi_operations - UCSI I/O operations 60 - * @read: Read operation 61 - * @sync_write: Blocking write operation 62 - * @async_write: Non-blocking write operation 59 + * @read_version: Read implemented UCSI version 60 + * @read_cci: Read CCI register 61 + * @read_message_in: Read message data from UCSI 62 + * @sync_control: Blocking control operation 63 + * @async_control: Non-blocking control operation 63 64 * @update_altmodes: Squashes duplicate DP altmodes 64 65 * @update_connector: Update connector capabilities before registering 65 66 * @connector_status: Updates connector status, called holding connector lock ··· 71 68 * return immediately after sending the data to the PPM. 72 69 */ 73 70 struct ucsi_operations { 74 - int (*read)(struct ucsi *ucsi, unsigned int offset, 75 - void *val, size_t val_len); 76 - int (*sync_write)(struct ucsi *ucsi, unsigned int offset, 77 - const void *val, size_t val_len); 78 - int (*async_write)(struct ucsi *ucsi, unsigned int offset, 79 - const void *val, size_t val_len); 71 + int (*read_version)(struct ucsi *ucsi, u16 *version); 72 + int (*read_cci)(struct ucsi *ucsi, u32 *cci); 73 + int (*read_message_in)(struct ucsi *ucsi, void *val, size_t val_len); 74 + int (*sync_control)(struct ucsi *ucsi, u64 command); 75 + int (*async_control)(struct ucsi *ucsi, u64 command); 80 76 bool (*update_altmodes)(struct ucsi *ucsi, struct ucsi_altmode *orig, 81 77 struct ucsi_altmode *updated); 82 78 void (*update_connector)(struct ucsi_connector *con); ··· 118 116 #define UCSI_CONNECTOR_NUMBER(_num_) ((u64)(_num_) << 16) 119 117 #define UCSI_COMMAND(_cmd_) ((_cmd_) & 0xff) 120 118 119 + #define UCSI_GET_ALTMODE_GET_CONNECTOR_NUMBER(_cmd_) (((_cmd_) >> 24) & GENMASK(6, 0)) 120 + #define UCSI_DEFAULT_GET_CONNECTOR_NUMBER(_cmd_) (((_cmd_) >> 16) & GENMASK(6, 0)) 121 + 121 122 /* CONNECTOR_RESET command bits */ 122 123 #define UCSI_CONNECTOR_RESET_HARD BIT(23) /* Deprecated in v1.1 */ 123 124 ··· 129 124 #define UCSI_ACK_COMMAND_COMPLETE BIT(17) 130 125 131 126 /* SET_NOTIFICATION_ENABLE command bits */ 132 - #define UCSI_ENABLE_NTFY_CMD_COMPLETE BIT(16) 133 - #define UCSI_ENABLE_NTFY_EXT_PWR_SRC_CHANGE BIT(17) 134 - #define UCSI_ENABLE_NTFY_PWR_OPMODE_CHANGE BIT(18) 135 - #define UCSI_ENABLE_NTFY_CAP_CHANGE BIT(21) 136 - #define UCSI_ENABLE_NTFY_PWR_LEVEL_CHANGE BIT(22) 137 - #define UCSI_ENABLE_NTFY_PD_RESET_COMPLETE BIT(23) 138 - #define UCSI_ENABLE_NTFY_CAM_CHANGE BIT(24) 139 - #define UCSI_ENABLE_NTFY_BAT_STATUS_CHANGE BIT(25) 140 - #define UCSI_ENABLE_NTFY_PARTNER_CHANGE BIT(27) 141 - #define UCSI_ENABLE_NTFY_PWR_DIR_CHANGE BIT(28) 142 - #define UCSI_ENABLE_NTFY_CONNECTOR_CHANGE BIT(30) 143 - #define UCSI_ENABLE_NTFY_ERROR BIT(31) 127 + #define UCSI_ENABLE_NTFY_CMD_COMPLETE BIT_ULL(16) 128 + #define UCSI_ENABLE_NTFY_EXT_PWR_SRC_CHANGE BIT_ULL(17) 129 + #define UCSI_ENABLE_NTFY_PWR_OPMODE_CHANGE BIT_ULL(18) 130 + #define UCSI_ENABLE_NTFY_ATTENTION BIT_ULL(19) 131 + #define UCSI_ENABLE_NTFY_LPM_FW_UPDATE_REQ BIT_ULL(20) 132 + #define UCSI_ENABLE_NTFY_CAP_CHANGE BIT_ULL(21) 133 + #define UCSI_ENABLE_NTFY_PWR_LEVEL_CHANGE BIT_ULL(22) 134 + #define UCSI_ENABLE_NTFY_PD_RESET_COMPLETE BIT_ULL(23) 135 + #define UCSI_ENABLE_NTFY_CAM_CHANGE BIT_ULL(24) 136 + #define UCSI_ENABLE_NTFY_BAT_STATUS_CHANGE BIT_ULL(25) 137 + #define UCSI_ENABLE_NTFY_SECURITY_REQ_PARTNER BIT_ULL(26) 138 + #define UCSI_ENABLE_NTFY_PARTNER_CHANGE BIT_ULL(27) 139 + #define UCSI_ENABLE_NTFY_PWR_DIR_CHANGE BIT_ULL(28) 140 + #define UCSI_ENABLE_NTFY_SET_RETIMER_MODE BIT_ULL(29) 141 + #define UCSI_ENABLE_NTFY_CONNECTOR_CHANGE BIT_ULL(30) 142 + #define UCSI_ENABLE_NTFY_ERROR BIT_ULL(31) 143 + #define UCSI_ENABLE_NTFY_SINK_PATH_STS_CHANGE BIT_ULL(32) 144 144 #define UCSI_ENABLE_NTFY_ALL 0xdbe70000 145 145 146 146 /* SET_UOR command bits */ ··· 203 193 #define UCSI_ERROR_HARD_RESET BIT(10) 204 194 #define UCSI_ERROR_PPM_POLICY_CONFLICT BIT(11) 205 195 #define UCSI_ERROR_SWAP_REJECTED BIT(12) 196 + #define UCSI_ERROR_REVERSE_CURRENT_PROTECTION BIT(13) 197 + #define UCSI_ERROR_SET_SINK_PATH_REJECTED BIT(14) 206 198 207 199 #define UCSI_SET_NEW_CAM_ENTER(x) (((x) >> 23) & 0x1) 208 200 #define UCSI_SET_NEW_CAM_GET_AM(x) (((x) >> 24) & 0xff) ··· 232 220 #define UCSI_CAP_CABLE_DETAILS BIT(5) 233 221 #define UCSI_CAP_EXT_SUPPLY_NOTIFICATIONS BIT(6) 234 222 #define UCSI_CAP_PD_RESET BIT(7) 235 - #define UCSI_CAP_GET_PD_MESSAGE BIT(8) 223 + #define UCSI_CAP_GET_PD_MESSAGE BIT(8) 224 + #define UCSI_CAP_GET_ATTENTION_VDO BIT(9) 225 + #define UCSI_CAP_FW_UPDATE_REQUEST BIT(10) 226 + #define UCSI_CAP_NEGOTIATED_PWR_LEVEL_CHANGE BIT(11) 227 + #define UCSI_CAP_SECURITY_REQUEST BIT(12) 228 + #define UCSI_CAP_SET_RETIMER_MODE BIT(13) 229 + #define UCSI_CAP_CHUNKING_SUPPORT BIT(14) 236 230 u8 reserved_1; 237 231 u8 num_alt_modes; 238 232 u8 reserved_2; ··· 402 384 struct ucsi { 403 385 u16 version; 404 386 struct device *dev; 405 - struct driver_data *driver_data; 387 + void *driver_data; 406 388 407 389 const struct ucsi_operations *ops; 408 390 ··· 426 408 /* PPM communication flags */ 427 409 unsigned long flags; 428 410 #define EVENT_PENDING 0 411 + #define COMMAND_PENDING 1 412 + #define ACK_PENDING 2 413 + struct completion complete; 429 414 430 415 unsigned long quirks; 431 416 #define UCSI_NO_PARTNER_PDOS BIT(0) /* Don't read partner's PDOs */ ··· 493 472 void ucsi_altmode_update_active(struct ucsi_connector *con); 494 473 int ucsi_resume(struct ucsi *ucsi); 495 474 475 + void ucsi_notify_common(struct ucsi *ucsi, u32 cci); 476 + int ucsi_sync_control_common(struct ucsi *ucsi, u64 command); 477 + 496 478 #if IS_ENABLED(CONFIG_POWER_SUPPLY) 497 479 int ucsi_register_port_psy(struct ucsi_connector *con); 498 480 void ucsi_unregister_port_psy(struct ucsi_connector *con); ··· 520 496 bool override, int offset, 521 497 struct typec_altmode_desc *desc) 522 498 { 523 - return NULL; 499 + return typec_port_register_altmode(con->port, desc); 524 500 } 525 501 526 502 static inline void
+72 -73
drivers/usb/typec/ucsi/ucsi_acpi.c
··· 21 21 struct device *dev; 22 22 struct ucsi *ucsi; 23 23 void *base; 24 - struct completion complete; 25 - unsigned long flags; 26 - #define UCSI_ACPI_COMMAND_PENDING 1 27 - #define UCSI_ACPI_ACK_PENDING 2 28 - #define UCSI_ACPI_CHECK_BOGUS_EVENT 3 24 + bool check_bogus_event; 29 25 guid_t guid; 30 26 u64 cmd; 31 27 }; ··· 42 46 return 0; 43 47 } 44 48 45 - static int ucsi_acpi_read(struct ucsi *ucsi, unsigned int offset, 46 - void *val, size_t val_len) 49 + static int ucsi_acpi_read_version(struct ucsi *ucsi, u16 *version) 47 50 { 48 51 struct ucsi_acpi *ua = ucsi_get_drvdata(ucsi); 49 52 int ret; ··· 51 56 if (ret) 52 57 return ret; 53 58 54 - memcpy(val, ua->base + offset, val_len); 59 + memcpy(version, ua->base + UCSI_VERSION, sizeof(*version)); 55 60 56 61 return 0; 57 62 } 58 63 59 - static int ucsi_acpi_async_write(struct ucsi *ucsi, unsigned int offset, 60 - const void *val, size_t val_len) 64 + static int ucsi_acpi_read_cci(struct ucsi *ucsi, u32 *cci) 65 + { 66 + struct ucsi_acpi *ua = ucsi_get_drvdata(ucsi); 67 + int ret; 68 + 69 + ret = ucsi_acpi_dsm(ua, UCSI_DSM_FUNC_READ); 70 + if (ret) 71 + return ret; 72 + 73 + memcpy(cci, ua->base + UCSI_CCI, sizeof(*cci)); 74 + 75 + return 0; 76 + } 77 + 78 + static int ucsi_acpi_read_message_in(struct ucsi *ucsi, void *val, size_t val_len) 79 + { 80 + struct ucsi_acpi *ua = ucsi_get_drvdata(ucsi); 81 + int ret; 82 + 83 + ret = ucsi_acpi_dsm(ua, UCSI_DSM_FUNC_READ); 84 + if (ret) 85 + return ret; 86 + 87 + memcpy(val, ua->base + UCSI_MESSAGE_IN, val_len); 88 + 89 + return 0; 90 + } 91 + 92 + static int ucsi_acpi_async_control(struct ucsi *ucsi, u64 command) 61 93 { 62 94 struct ucsi_acpi *ua = ucsi_get_drvdata(ucsi); 63 95 64 - memcpy(ua->base + offset, val, val_len); 65 - ua->cmd = *(u64 *)val; 96 + memcpy(ua->base + UCSI_CONTROL, &command, sizeof(command)); 97 + ua->cmd = command; 66 98 67 99 return ucsi_acpi_dsm(ua, UCSI_DSM_FUNC_WRITE); 68 100 } 69 101 70 - static int ucsi_acpi_sync_write(struct ucsi *ucsi, unsigned int offset, 71 - const void *val, size_t val_len) 72 - { 73 - struct ucsi_acpi *ua = ucsi_get_drvdata(ucsi); 74 - bool ack = UCSI_COMMAND(*(u64 *)val) == UCSI_ACK_CC_CI; 75 - int ret; 76 - 77 - if (ack) 78 - set_bit(UCSI_ACPI_ACK_PENDING, &ua->flags); 79 - else 80 - set_bit(UCSI_ACPI_COMMAND_PENDING, &ua->flags); 81 - 82 - ret = ucsi_acpi_async_write(ucsi, offset, val, val_len); 83 - if (ret) 84 - goto out_clear_bit; 85 - 86 - if (!wait_for_completion_timeout(&ua->complete, 5 * HZ)) 87 - ret = -ETIMEDOUT; 88 - 89 - out_clear_bit: 90 - if (ack) 91 - clear_bit(UCSI_ACPI_ACK_PENDING, &ua->flags); 92 - else 93 - clear_bit(UCSI_ACPI_COMMAND_PENDING, &ua->flags); 94 - 95 - return ret; 96 - } 97 - 98 102 static const struct ucsi_operations ucsi_acpi_ops = { 99 - .read = ucsi_acpi_read, 100 - .sync_write = ucsi_acpi_sync_write, 101 - .async_write = ucsi_acpi_async_write 103 + .read_version = ucsi_acpi_read_version, 104 + .read_cci = ucsi_acpi_read_cci, 105 + .read_message_in = ucsi_acpi_read_message_in, 106 + .sync_control = ucsi_sync_control_common, 107 + .async_control = ucsi_acpi_async_control 102 108 }; 103 109 104 110 static int 105 - ucsi_zenbook_read(struct ucsi *ucsi, unsigned int offset, void *val, size_t val_len) 111 + ucsi_zenbook_read_cci(struct ucsi *ucsi, u32 *cci) 106 112 { 107 113 struct ucsi_acpi *ua = ucsi_get_drvdata(ucsi); 108 114 int ret; 109 115 110 - if (offset == UCSI_VERSION || UCSI_COMMAND(ua->cmd) == UCSI_PPM_RESET) { 116 + if (UCSI_COMMAND(ua->cmd) == UCSI_PPM_RESET) { 111 117 ret = ucsi_acpi_dsm(ua, UCSI_DSM_FUNC_READ); 112 118 if (ret) 113 119 return ret; 114 120 } 115 121 116 - memcpy(val, ua->base + offset, val_len); 122 + memcpy(cci, ua->base + UCSI_CCI, sizeof(*cci)); 123 + 124 + return 0; 125 + } 126 + 127 + static int 128 + ucsi_zenbook_read_message_in(struct ucsi *ucsi, void *val, size_t val_len) 129 + { 130 + struct ucsi_acpi *ua = ucsi_get_drvdata(ucsi); 131 + 132 + /* UCSI_MESSAGE_IN is never read for PPM_RESET, return stored data */ 133 + memcpy(val, ua->base + UCSI_MESSAGE_IN, val_len); 117 134 118 135 return 0; 119 136 } 120 137 121 138 static const struct ucsi_operations ucsi_zenbook_ops = { 122 - .read = ucsi_zenbook_read, 123 - .sync_write = ucsi_acpi_sync_write, 124 - .async_write = ucsi_acpi_async_write 139 + .read_version = ucsi_acpi_read_version, 140 + .read_cci = ucsi_zenbook_read_cci, 141 + .read_message_in = ucsi_zenbook_read_message_in, 142 + .sync_control = ucsi_sync_control_common, 143 + .async_control = ucsi_acpi_async_control 125 144 }; 126 145 127 - static int ucsi_gram_read(struct ucsi *ucsi, unsigned int offset, 128 - void *val, size_t val_len) 146 + static int ucsi_gram_read_message_in(struct ucsi *ucsi, void *val, size_t val_len) 129 147 { 130 148 u16 bogus_change = UCSI_CONSTAT_POWER_LEVEL_CHANGE | 131 149 UCSI_CONSTAT_PDOS_CHANGE; ··· 146 138 struct ucsi_connector_status *status; 147 139 int ret; 148 140 149 - ret = ucsi_acpi_read(ucsi, offset, val, val_len); 141 + ret = ucsi_acpi_read_message_in(ucsi, val, val_len); 150 142 if (ret < 0) 151 143 return ret; 152 144 153 145 if (UCSI_COMMAND(ua->cmd) == UCSI_GET_CONNECTOR_STATUS && 154 - test_bit(UCSI_ACPI_CHECK_BOGUS_EVENT, &ua->flags) && 155 - offset == UCSI_MESSAGE_IN) { 146 + ua->check_bogus_event) { 156 147 status = (struct ucsi_connector_status *)val; 157 148 158 149 /* Clear the bogus change */ 159 150 if (status->change == bogus_change) 160 151 status->change = 0; 161 152 162 - clear_bit(UCSI_ACPI_CHECK_BOGUS_EVENT, &ua->flags); 153 + ua->check_bogus_event = false; 163 154 } 164 155 165 156 return ret; 166 157 } 167 158 168 - static int ucsi_gram_sync_write(struct ucsi *ucsi, unsigned int offset, 169 - const void *val, size_t val_len) 159 + static int ucsi_gram_sync_control(struct ucsi *ucsi, u64 command) 170 160 { 171 161 struct ucsi_acpi *ua = ucsi_get_drvdata(ucsi); 172 162 int ret; 173 163 174 - ret = ucsi_acpi_sync_write(ucsi, offset, val, val_len); 164 + ret = ucsi_sync_control_common(ucsi, command); 175 165 if (ret < 0) 176 166 return ret; 177 167 178 168 if (UCSI_COMMAND(ua->cmd) == UCSI_GET_PDOS && 179 169 ua->cmd & UCSI_GET_PDOS_PARTNER_PDO(1) && 180 170 ua->cmd & UCSI_GET_PDOS_SRC_PDOS) 181 - set_bit(UCSI_ACPI_CHECK_BOGUS_EVENT, &ua->flags); 171 + ua->check_bogus_event = true; 182 172 183 173 return ret; 184 174 } 185 175 186 176 static const struct ucsi_operations ucsi_gram_ops = { 187 - .read = ucsi_gram_read, 188 - .sync_write = ucsi_gram_sync_write, 189 - .async_write = ucsi_acpi_async_write 177 + .read_version = ucsi_acpi_read_version, 178 + .read_cci = ucsi_acpi_read_cci, 179 + .read_message_in = ucsi_gram_read_message_in, 180 + .sync_control = ucsi_gram_sync_control, 181 + .async_control = ucsi_acpi_async_control 190 182 }; 191 183 192 184 static const struct dmi_system_id ucsi_acpi_quirks[] = { ··· 214 206 u32 cci; 215 207 int ret; 216 208 217 - ret = ua->ucsi->ops->read(ua->ucsi, UCSI_CCI, &cci, sizeof(cci)); 209 + ret = ua->ucsi->ops->read_cci(ua->ucsi, &cci); 218 210 if (ret) 219 211 return; 220 212 221 - if (UCSI_CCI_CONNECTOR(cci)) 222 - ucsi_connector_change(ua->ucsi, UCSI_CCI_CONNECTOR(cci)); 223 - 224 - if (cci & UCSI_CCI_ACK_COMPLETE && 225 - test_bit(UCSI_ACPI_ACK_PENDING, &ua->flags)) 226 - complete(&ua->complete); 227 - if (cci & UCSI_CCI_COMMAND_COMPLETE && 228 - test_bit(UCSI_ACPI_COMMAND_PENDING, &ua->flags)) 229 - complete(&ua->complete); 213 + ucsi_notify_common(ua->ucsi, cci); 230 214 } 231 215 232 216 static int ucsi_acpi_probe(struct platform_device *pdev) ··· 252 252 if (ret) 253 253 return ret; 254 254 255 - init_completion(&ua->complete); 256 255 ua->dev = &pdev->dev; 257 256 258 257 id = dmi_first_match(ucsi_acpi_quirks);
+45 -60
drivers/usb/typec/ucsi/ucsi_ccg.c
··· 222 222 u16 fw_build; 223 223 struct work_struct pm_work; 224 224 225 - struct completion complete; 226 - 227 225 u64 last_cmd_sent; 228 226 bool has_multiple_dp; 229 227 struct ucsi_ccg_altmode orig[UCSI_MAX_ALTMODES]; ··· 554 556 } 555 557 } 556 558 557 - static int ucsi_ccg_read(struct ucsi *ucsi, unsigned int offset, 558 - void *val, size_t val_len) 559 + static int ucsi_ccg_read_version(struct ucsi *ucsi, u16 *version) 559 560 { 560 561 struct ucsi_ccg *uc = ucsi_get_drvdata(ucsi); 561 - u16 reg = CCGX_RAB_UCSI_DATA_BLOCK(offset); 562 + u16 reg = CCGX_RAB_UCSI_DATA_BLOCK(UCSI_VERSION); 563 + 564 + return ccg_read(uc, reg, (u8 *)version, sizeof(*version)); 565 + } 566 + 567 + static int ucsi_ccg_read_cci(struct ucsi *ucsi, u32 *cci) 568 + { 569 + struct ucsi_ccg *uc = ucsi_get_drvdata(ucsi); 570 + 571 + spin_lock(&uc->op_lock); 572 + *cci = uc->op_data.cci; 573 + spin_unlock(&uc->op_lock); 574 + 575 + return 0; 576 + } 577 + 578 + static int ucsi_ccg_read_message_in(struct ucsi *ucsi, void *val, size_t val_len) 579 + { 580 + struct ucsi_ccg *uc = ucsi_get_drvdata(ucsi); 562 581 struct ucsi_capability *cap; 563 582 struct ucsi_altmode *alt; 564 - int ret = 0; 565 583 566 - if (offset == UCSI_CCI) { 567 - spin_lock(&uc->op_lock); 568 - memcpy(val, &(uc->op_data).cci, val_len); 569 - spin_unlock(&uc->op_lock); 570 - } else if (offset == UCSI_MESSAGE_IN) { 571 - spin_lock(&uc->op_lock); 572 - memcpy(val, &(uc->op_data).message_in, val_len); 573 - spin_unlock(&uc->op_lock); 574 - } else { 575 - ret = ccg_read(uc, reg, val, val_len); 576 - } 577 - 578 - if (ret) 579 - return ret; 580 - 581 - if (offset != UCSI_MESSAGE_IN) 582 - return ret; 584 + spin_lock(&uc->op_lock); 585 + memcpy(val, uc->op_data.message_in, val_len); 586 + spin_unlock(&uc->op_lock); 583 587 584 588 switch (UCSI_COMMAND(uc->last_cmd_sent)) { 585 589 case UCSI_GET_CURRENT_CAM: ··· 607 607 } 608 608 uc->last_cmd_sent = 0; 609 609 610 - return ret; 610 + return 0; 611 611 } 612 612 613 - static int ucsi_ccg_async_write(struct ucsi *ucsi, unsigned int offset, 614 - const void *val, size_t val_len) 613 + static int ucsi_ccg_async_control(struct ucsi *ucsi, u64 command) 615 614 { 616 615 struct ucsi_ccg *uc = ucsi_get_drvdata(ucsi); 617 - u16 reg = CCGX_RAB_UCSI_DATA_BLOCK(offset); 616 + u16 reg = CCGX_RAB_UCSI_DATA_BLOCK(UCSI_CONTROL); 618 617 619 618 /* 620 - * UCSI may read CCI instantly after async_write, 619 + * UCSI may read CCI instantly after async_control, 621 620 * clear CCI to avoid caller getting wrong data before we get CCI from ISR 622 621 */ 623 622 spin_lock(&uc->op_lock); 624 623 uc->op_data.cci = 0; 625 624 spin_unlock(&uc->op_lock); 626 625 627 - return ccg_write(uc, reg, val, val_len); 626 + return ccg_write(uc, reg, (u8 *)&command, sizeof(command)); 628 627 } 629 628 630 - static int ucsi_ccg_sync_write(struct ucsi *ucsi, unsigned int offset, 631 - const void *val, size_t val_len) 629 + static int ucsi_ccg_sync_control(struct ucsi *ucsi, u64 command) 632 630 { 633 631 struct ucsi_ccg *uc = ucsi_get_drvdata(ucsi); 634 632 struct ucsi_connector *con; ··· 635 637 636 638 mutex_lock(&uc->lock); 637 639 pm_runtime_get_sync(uc->dev); 638 - set_bit(DEV_CMD_PENDING, &uc->flags); 639 640 640 - if (offset == UCSI_CONTROL && val_len == sizeof(uc->last_cmd_sent)) { 641 - uc->last_cmd_sent = *(u64 *)val; 641 + uc->last_cmd_sent = command; 642 642 643 - if (UCSI_COMMAND(uc->last_cmd_sent) == UCSI_SET_NEW_CAM && 644 - uc->has_multiple_dp) { 645 - con_index = (uc->last_cmd_sent >> 16) & 646 - UCSI_CMD_CONNECTOR_MASK; 647 - con = &uc->ucsi->connector[con_index - 1]; 648 - ucsi_ccg_update_set_new_cam_cmd(uc, con, (u64 *)val); 649 - } 643 + if (UCSI_COMMAND(uc->last_cmd_sent) == UCSI_SET_NEW_CAM && 644 + uc->has_multiple_dp) { 645 + con_index = (uc->last_cmd_sent >> 16) & 646 + UCSI_CMD_CONNECTOR_MASK; 647 + con = &uc->ucsi->connector[con_index - 1]; 648 + ucsi_ccg_update_set_new_cam_cmd(uc, con, &command); 650 649 } 651 650 652 - ret = ucsi_ccg_async_write(ucsi, offset, val, val_len); 653 - if (ret) 654 - goto err_clear_bit; 651 + ret = ucsi_sync_control_common(ucsi, command); 655 652 656 - if (!wait_for_completion_timeout(&uc->complete, msecs_to_jiffies(5000))) 657 - ret = -ETIMEDOUT; 658 - 659 - err_clear_bit: 660 - clear_bit(DEV_CMD_PENDING, &uc->flags); 661 653 pm_runtime_put_sync(uc->dev); 662 654 mutex_unlock(&uc->lock); 663 655 ··· 655 667 } 656 668 657 669 static const struct ucsi_operations ucsi_ccg_ops = { 658 - .read = ucsi_ccg_read, 659 - .sync_write = ucsi_ccg_sync_write, 660 - .async_write = ucsi_ccg_async_write, 670 + .read_version = ucsi_ccg_read_version, 671 + .read_cci = ucsi_ccg_read_cci, 672 + .read_message_in = ucsi_ccg_read_message_in, 673 + .sync_control = ucsi_ccg_sync_control, 674 + .async_control = ucsi_ccg_async_control, 661 675 .update_altmodes = ucsi_ccg_update_altmodes 662 676 }; 663 677 ··· 684 694 if (ret) 685 695 goto err_clear_irq; 686 696 687 - if (UCSI_CCI_CONNECTOR(cci)) 688 - ucsi_connector_change(uc->ucsi, UCSI_CCI_CONNECTOR(cci)); 689 - 690 697 /* 691 698 * As per CCGx UCSI interface guide, copy CCI and MESSAGE_IN 692 699 * to the OpRegion before clear the UCSI interrupt ··· 695 708 err_clear_irq: 696 709 ccg_write(uc, CCGX_RAB_INTR_REG, &intr_reg, sizeof(intr_reg)); 697 710 698 - if (!ret && test_bit(DEV_CMD_PENDING, &uc->flags) && 699 - cci & (UCSI_CCI_ACK_COMPLETE | UCSI_CCI_COMMAND_COMPLETE)) 700 - complete(&uc->complete); 711 + if (!ret) 712 + ucsi_notify_common(uc->ucsi, cci); 701 713 702 714 return IRQ_HANDLED; 703 715 } ··· 1415 1429 uc->client = client; 1416 1430 uc->irq = client->irq; 1417 1431 mutex_init(&uc->lock); 1418 - init_completion(&uc->complete); 1419 1432 INIT_WORK(&uc->work, ccg_update_firmware); 1420 1433 INIT_WORK(&uc->pm_work, ccg_pm_workaround_work); 1421 1434 ··· 1501 1516 MODULE_DEVICE_TABLE(of, ucsi_ccg_of_match_table); 1502 1517 1503 1518 static const struct i2c_device_id ucsi_ccg_device_id[] = { 1504 - {"ccgx-ucsi", 0}, 1519 + { "ccgx-ucsi" }, 1505 1520 {} 1506 1521 }; 1507 1522 MODULE_DEVICE_TABLE(i2c, ucsi_ccg_device_id);
+23 -51
drivers/usb/typec/ucsi/ucsi_glink.c
··· 64 64 struct ucsi *ucsi; 65 65 struct completion read_ack; 66 66 struct completion write_ack; 67 - struct completion sync_ack; 68 - bool sync_pending; 69 67 struct mutex lock; /* protects concurrent access to PMIC Glink interface */ 70 - 71 - int sync_val; 72 68 73 69 struct work_struct notify_work; 74 70 struct work_struct register_work; ··· 110 114 return ret; 111 115 } 112 116 117 + static int pmic_glink_ucsi_read_version(struct ucsi *ucsi, u16 *version) 118 + { 119 + return pmic_glink_ucsi_read(ucsi, UCSI_VERSION, version, sizeof(*version)); 120 + } 121 + 122 + static int pmic_glink_ucsi_read_cci(struct ucsi *ucsi, u32 *cci) 123 + { 124 + return pmic_glink_ucsi_read(ucsi, UCSI_CCI, cci, sizeof(*cci)); 125 + } 126 + 127 + static int pmic_glink_ucsi_read_message_in(struct ucsi *ucsi, void *val, size_t val_len) 128 + { 129 + return pmic_glink_ucsi_read(ucsi, UCSI_MESSAGE_IN, val, val_len); 130 + } 131 + 113 132 static int pmic_glink_ucsi_locked_write(struct pmic_glink_ucsi *ucsi, unsigned int offset, 114 133 const void *val, size_t val_len) 115 134 { ··· 154 143 return 0; 155 144 } 156 145 157 - static int pmic_glink_ucsi_async_write(struct ucsi *__ucsi, unsigned int offset, 158 - const void *val, size_t val_len) 146 + static int pmic_glink_ucsi_async_control(struct ucsi *__ucsi, u64 command) 159 147 { 160 148 struct pmic_glink_ucsi *ucsi = ucsi_get_drvdata(__ucsi); 161 149 int ret; 162 150 163 151 mutex_lock(&ucsi->lock); 164 - ret = pmic_glink_ucsi_locked_write(ucsi, offset, val, val_len); 152 + ret = pmic_glink_ucsi_locked_write(ucsi, UCSI_CONTROL, &command, sizeof(command)); 165 153 mutex_unlock(&ucsi->lock); 166 - 167 - return ret; 168 - } 169 - 170 - static int pmic_glink_ucsi_sync_write(struct ucsi *__ucsi, unsigned int offset, 171 - const void *val, size_t val_len) 172 - { 173 - struct pmic_glink_ucsi *ucsi = ucsi_get_drvdata(__ucsi); 174 - unsigned long left; 175 - int ret; 176 - 177 - /* TOFIX: Downstream forces recipient to CON when UCSI_GET_ALTERNATE_MODES command */ 178 - 179 - mutex_lock(&ucsi->lock); 180 - ucsi->sync_val = 0; 181 - reinit_completion(&ucsi->sync_ack); 182 - ucsi->sync_pending = true; 183 - ret = pmic_glink_ucsi_locked_write(ucsi, offset, val, val_len); 184 - mutex_unlock(&ucsi->lock); 185 - 186 - left = wait_for_completion_timeout(&ucsi->sync_ack, 5 * HZ); 187 - if (!left) { 188 - dev_err(ucsi->dev, "timeout waiting for UCSI sync write response\n"); 189 - /* return 0 here and let core UCSI code handle the CCI_BUSY */ 190 - ret = 0; 191 - } else if (ucsi->sync_val) { 192 - dev_err(ucsi->dev, "sync write returned: %d\n", ucsi->sync_val); 193 - } 194 - 195 - ucsi->sync_pending = false; 196 154 197 155 return ret; 198 156 } ··· 196 216 } 197 217 198 218 static const struct ucsi_operations pmic_glink_ucsi_ops = { 199 - .read = pmic_glink_ucsi_read, 200 - .sync_write = pmic_glink_ucsi_sync_write, 201 - .async_write = pmic_glink_ucsi_async_write, 219 + .read_version = pmic_glink_ucsi_read_version, 220 + .read_cci = pmic_glink_ucsi_read_cci, 221 + .read_message_in = pmic_glink_ucsi_read_message_in, 222 + .sync_control = ucsi_sync_control_common, 223 + .async_control = pmic_glink_ucsi_async_control, 202 224 .update_connector = pmic_glink_ucsi_update_connector, 203 225 .connector_status = pmic_glink_ucsi_connector_status, 204 226 }; ··· 223 241 if (resp->ret_code) 224 242 return; 225 243 226 - ucsi->sync_val = resp->ret_code; 227 244 complete(&ucsi->write_ack); 228 245 } 229 246 230 247 static void pmic_glink_ucsi_notify(struct work_struct *work) 231 248 { 232 249 struct pmic_glink_ucsi *ucsi = container_of(work, struct pmic_glink_ucsi, notify_work); 233 - unsigned int con_num; 234 250 u32 cci; 235 251 int ret; 236 252 ··· 238 258 return; 239 259 } 240 260 241 - con_num = UCSI_CCI_CONNECTOR(cci); 242 - if (con_num) 243 - ucsi_connector_change(ucsi->ucsi, con_num); 244 - 245 - if (ucsi->sync_pending && 246 - (cci & (UCSI_CCI_ACK_COMPLETE | UCSI_CCI_COMMAND_COMPLETE))) { 247 - complete(&ucsi->sync_ack); 248 - } 261 + ucsi_notify_common(ucsi->ucsi, cci); 249 262 } 250 263 251 264 static void pmic_glink_ucsi_register(struct work_struct *work) ··· 320 347 INIT_WORK(&ucsi->register_work, pmic_glink_ucsi_register); 321 348 init_completion(&ucsi->read_ack); 322 349 init_completion(&ucsi->write_ack); 323 - init_completion(&ucsi->sync_ack); 324 350 mutex_init(&ucsi->lock); 325 351 326 352 ucsi->ucsi = ucsi_create(dev, &pmic_glink_ucsi_ops);
+29 -54
drivers/usb/typec/ucsi/ucsi_stm32g0.c
··· 61 61 struct i2c_client *i2c_bl; 62 62 bool in_bootloader; 63 63 u8 bl_version; 64 - struct completion complete; 65 64 struct device *dev; 66 - unsigned long flags; 67 - #define COMMAND_PENDING 1 68 - #define ACK_PENDING 2 69 65 const char *fw_name; 70 66 struct ucsi *ucsi; 71 67 bool suspended; ··· 355 359 return 0; 356 360 } 357 361 358 - static int ucsi_stm32g0_async_write(struct ucsi *ucsi, unsigned int offset, const void *val, 359 - size_t len) 362 + static int ucsi_stm32g0_read_version(struct ucsi *ucsi, u16 *version) 363 + { 364 + return ucsi_stm32g0_read(ucsi, UCSI_VERSION, version, sizeof(*version)); 365 + } 366 + 367 + static int ucsi_stm32g0_read_cci(struct ucsi *ucsi, u32 *cci) 368 + { 369 + return ucsi_stm32g0_read(ucsi, UCSI_CCI, cci, sizeof(*cci)); 370 + } 371 + 372 + static int ucsi_stm32g0_read_message_in(struct ucsi *ucsi, void *val, size_t len) 373 + { 374 + return ucsi_stm32g0_read(ucsi, UCSI_MESSAGE_IN, val, len); 375 + } 376 + 377 + static int ucsi_stm32g0_async_control(struct ucsi *ucsi, u64 command) 360 378 { 361 379 struct ucsi_stm32g0 *g0 = ucsi_get_drvdata(ucsi); 362 380 struct i2c_client *client = g0->client; ··· 383 373 unsigned char *buf; 384 374 int ret; 385 375 386 - buf = kmalloc(len + 1, GFP_KERNEL); 376 + buf = kmalloc(sizeof(command) + 1, GFP_KERNEL); 387 377 if (!buf) 388 378 return -ENOMEM; 389 379 390 - buf[0] = offset; 391 - memcpy(&buf[1], val, len); 392 - msg[0].len = len + 1; 380 + buf[0] = UCSI_CONTROL; 381 + memcpy(&buf[1], &command, sizeof(command)); 382 + msg[0].len = sizeof(command) + 1; 393 383 msg[0].buf = buf; 394 384 395 385 ret = i2c_transfer(client->adapter, msg, ARRAY_SIZE(msg)); 396 386 kfree(buf); 397 387 if (ret != ARRAY_SIZE(msg)) { 398 - dev_err(g0->dev, "i2c write %02x, %02x error: %d\n", client->addr, offset, ret); 388 + dev_err(g0->dev, "i2c write %02x, %02x error: %d\n", client->addr, UCSI_CONTROL, ret); 399 389 400 390 return ret < 0 ? ret : -EIO; 401 391 } 402 392 403 393 return 0; 404 - } 405 - 406 - static int ucsi_stm32g0_sync_write(struct ucsi *ucsi, unsigned int offset, const void *val, 407 - size_t len) 408 - { 409 - struct ucsi_stm32g0 *g0 = ucsi_get_drvdata(ucsi); 410 - bool ack = UCSI_COMMAND(*(u64 *)val) == UCSI_ACK_CC_CI; 411 - int ret; 412 - 413 - if (ack) 414 - set_bit(ACK_PENDING, &g0->flags); 415 - else 416 - set_bit(COMMAND_PENDING, &g0->flags); 417 - 418 - ret = ucsi_stm32g0_async_write(ucsi, offset, val, len); 419 - if (ret) 420 - goto out_clear_bit; 421 - 422 - if (!wait_for_completion_timeout(&g0->complete, msecs_to_jiffies(5000))) 423 - ret = -ETIMEDOUT; 424 - else 425 - return 0; 426 - 427 - out_clear_bit: 428 - if (ack) 429 - clear_bit(ACK_PENDING, &g0->flags); 430 - else 431 - clear_bit(COMMAND_PENDING, &g0->flags); 432 - 433 - return ret; 434 394 } 435 395 436 396 static irqreturn_t ucsi_stm32g0_irq_handler(int irq, void *data) ··· 416 436 if (ret) 417 437 return IRQ_NONE; 418 438 419 - if (UCSI_CCI_CONNECTOR(cci)) 420 - ucsi_connector_change(g0->ucsi, UCSI_CCI_CONNECTOR(cci)); 421 - 422 - if (cci & UCSI_CCI_ACK_COMPLETE && test_and_clear_bit(ACK_PENDING, &g0->flags)) 423 - complete(&g0->complete); 424 - if (cci & UCSI_CCI_COMMAND_COMPLETE && test_and_clear_bit(COMMAND_PENDING, &g0->flags)) 425 - complete(&g0->complete); 439 + ucsi_notify_common(g0->ucsi, cci); 426 440 427 441 return IRQ_HANDLED; 428 442 } 429 443 430 444 static const struct ucsi_operations ucsi_stm32g0_ops = { 431 - .read = ucsi_stm32g0_read, 432 - .sync_write = ucsi_stm32g0_sync_write, 433 - .async_write = ucsi_stm32g0_async_write, 445 + .read_version = ucsi_stm32g0_read_version, 446 + .read_cci = ucsi_stm32g0_read_cci, 447 + .read_message_in = ucsi_stm32g0_read_message_in, 448 + .sync_control = ucsi_sync_control_common, 449 + .async_control = ucsi_stm32g0_async_control, 434 450 }; 435 451 436 452 static int ucsi_stm32g0_register(struct ucsi *ucsi) ··· 626 650 627 651 g0->dev = dev; 628 652 g0->client = client; 629 - init_completion(&g0->complete); 630 653 i2c_set_clientdata(client, g0); 631 654 632 655 g0->ucsi = ucsi_create(dev, &ucsi_stm32g0_ops); ··· 739 764 MODULE_DEVICE_TABLE(of, ucsi_stm32g0_typec_of_match); 740 765 741 766 static const struct i2c_device_id ucsi_stm32g0_typec_i2c_devid[] = { 742 - {"stm32g0-typec", 0}, 743 - {}, 767 + { "stm32g0-typec" }, 768 + {} 744 769 }; 745 770 MODULE_DEVICE_TABLE(i2c, ucsi_stm32g0_typec_i2c_devid); 746 771
+164
drivers/usb/typec/ucsi/ucsi_yoga_c630.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + /* 3 + * Copyright (c) 2022-2024, Linaro Ltd 4 + * Authors: 5 + * Bjorn Andersson 6 + * Dmitry Baryshkov 7 + */ 8 + #include <linux/auxiliary_bus.h> 9 + #include <linux/bitops.h> 10 + #include <linux/completion.h> 11 + #include <linux/container_of.h> 12 + #include <linux/module.h> 13 + #include <linux/notifier.h> 14 + #include <linux/string.h> 15 + #include <linux/platform_data/lenovo-yoga-c630.h> 16 + 17 + #include "ucsi.h" 18 + 19 + struct yoga_c630_ucsi { 20 + struct yoga_c630_ec *ec; 21 + struct ucsi *ucsi; 22 + struct notifier_block nb; 23 + u16 version; 24 + }; 25 + 26 + static int yoga_c630_ucsi_read_version(struct ucsi *ucsi, u16 *version) 27 + { 28 + struct yoga_c630_ucsi *uec = ucsi_get_drvdata(ucsi); 29 + 30 + *version = uec->version; 31 + 32 + return 0; 33 + } 34 + 35 + static int yoga_c630_ucsi_read_cci(struct ucsi *ucsi, u32 *cci) 36 + { 37 + struct yoga_c630_ucsi *uec = ucsi_get_drvdata(ucsi); 38 + u8 buf[YOGA_C630_UCSI_READ_SIZE]; 39 + int ret; 40 + 41 + ret = yoga_c630_ec_ucsi_read(uec->ec, buf); 42 + if (ret) 43 + return ret; 44 + 45 + memcpy(cci, buf, sizeof(*cci)); 46 + 47 + return 0; 48 + } 49 + 50 + static int yoga_c630_ucsi_read_message_in(struct ucsi *ucsi, 51 + void *val, size_t val_len) 52 + { 53 + struct yoga_c630_ucsi *uec = ucsi_get_drvdata(ucsi); 54 + u8 buf[YOGA_C630_UCSI_READ_SIZE]; 55 + int ret; 56 + 57 + ret = yoga_c630_ec_ucsi_read(uec->ec, buf); 58 + if (ret) 59 + return ret; 60 + 61 + memcpy(val, buf + YOGA_C630_UCSI_CCI_SIZE, 62 + min(val_len, YOGA_C630_UCSI_DATA_SIZE)); 63 + 64 + return 0; 65 + } 66 + 67 + static int yoga_c630_ucsi_async_control(struct ucsi *ucsi, u64 command) 68 + { 69 + struct yoga_c630_ucsi *uec = ucsi_get_drvdata(ucsi); 70 + 71 + return yoga_c630_ec_ucsi_write(uec->ec, (u8*)&command); 72 + } 73 + 74 + const struct ucsi_operations yoga_c630_ucsi_ops = { 75 + .read_version = yoga_c630_ucsi_read_version, 76 + .read_cci = yoga_c630_ucsi_read_cci, 77 + .read_message_in = yoga_c630_ucsi_read_message_in, 78 + .sync_control = ucsi_sync_control_common, 79 + .async_control = yoga_c630_ucsi_async_control, 80 + }; 81 + 82 + static int yoga_c630_ucsi_notify(struct notifier_block *nb, 83 + unsigned long action, void *data) 84 + { 85 + struct yoga_c630_ucsi *uec = container_of(nb, struct yoga_c630_ucsi, nb); 86 + u32 cci; 87 + int ret; 88 + 89 + switch (action) { 90 + case LENOVO_EC_EVENT_USB: 91 + case LENOVO_EC_EVENT_HPD: 92 + ucsi_connector_change(uec->ucsi, 1); 93 + return NOTIFY_OK; 94 + 95 + case LENOVO_EC_EVENT_UCSI: 96 + ret = uec->ucsi->ops->read_cci(uec->ucsi, &cci); 97 + if (ret) 98 + return NOTIFY_DONE; 99 + 100 + ucsi_notify_common(uec->ucsi, cci); 101 + 102 + return NOTIFY_OK; 103 + 104 + default: 105 + return NOTIFY_DONE; 106 + } 107 + } 108 + 109 + static int yoga_c630_ucsi_probe(struct auxiliary_device *adev, 110 + const struct auxiliary_device_id *id) 111 + { 112 + struct yoga_c630_ec *ec = adev->dev.platform_data; 113 + struct yoga_c630_ucsi *uec; 114 + int ret; 115 + 116 + uec = devm_kzalloc(&adev->dev, sizeof(*uec), GFP_KERNEL); 117 + if (!uec) 118 + return -ENOMEM; 119 + 120 + uec->ec = ec; 121 + uec->nb.notifier_call = yoga_c630_ucsi_notify; 122 + 123 + uec->ucsi = ucsi_create(&adev->dev, &yoga_c630_ucsi_ops); 124 + if (IS_ERR(uec->ucsi)) 125 + return PTR_ERR(uec->ucsi); 126 + 127 + ucsi_set_drvdata(uec->ucsi, uec); 128 + 129 + uec->version = yoga_c630_ec_ucsi_get_version(uec->ec); 130 + 131 + auxiliary_set_drvdata(adev, uec); 132 + 133 + ret = yoga_c630_ec_register_notify(ec, &uec->nb); 134 + if (ret) 135 + return ret; 136 + 137 + return ucsi_register(uec->ucsi); 138 + } 139 + 140 + static void yoga_c630_ucsi_remove(struct auxiliary_device *adev) 141 + { 142 + struct yoga_c630_ucsi *uec = auxiliary_get_drvdata(adev); 143 + 144 + yoga_c630_ec_unregister_notify(uec->ec, &uec->nb); 145 + ucsi_unregister(uec->ucsi); 146 + } 147 + 148 + static const struct auxiliary_device_id yoga_c630_ucsi_id_table[] = { 149 + { .name = YOGA_C630_MOD_NAME "." YOGA_C630_DEV_UCSI, }, 150 + {} 151 + }; 152 + MODULE_DEVICE_TABLE(auxiliary, yoga_c630_ucsi_id_table); 153 + 154 + static struct auxiliary_driver yoga_c630_ucsi_driver = { 155 + .name = YOGA_C630_DEV_UCSI, 156 + .id_table = yoga_c630_ucsi_id_table, 157 + .probe = yoga_c630_ucsi_probe, 158 + .remove = yoga_c630_ucsi_remove, 159 + }; 160 + 161 + module_auxiliary_driver(yoga_c630_ucsi_driver); 162 + 163 + MODULE_DESCRIPTION("Lenovo Yoga C630 UCSI"); 164 + MODULE_LICENSE("GPL");
+50 -27
drivers/usb/usbip/stub_rx.c
··· 144 144 if (err && err != -ENODEV) 145 145 dev_err(&sdev->udev->dev, "can't set config #%d, error %d\n", 146 146 config, err); 147 - return 0; 147 + return err; 148 148 } 149 149 150 150 static int tweak_reset_device_cmd(struct urb *urb) 151 151 { 152 152 struct stub_priv *priv = (struct stub_priv *) urb->context; 153 153 struct stub_device *sdev = priv->sdev; 154 + int err; 154 155 155 156 dev_info(&urb->dev->dev, "usb_queue_reset_device\n"); 156 157 157 - if (usb_lock_device_for_reset(sdev->udev, NULL) < 0) { 158 + err = usb_lock_device_for_reset(sdev->udev, NULL); 159 + if (err < 0) { 158 160 dev_err(&urb->dev->dev, "could not obtain lock to reset device\n"); 159 - return 0; 161 + return err; 160 162 } 161 - usb_reset_device(sdev->udev); 163 + err = usb_reset_device(sdev->udev); 162 164 usb_unlock_device(sdev->udev); 163 165 164 - return 0; 166 + return err; 165 167 } 166 168 167 169 /* 168 170 * clear_halt, set_interface, and set_configuration require special tricks. 171 + * Returns 1 if request was tweaked, 0 otherwise. 169 172 */ 170 - static void tweak_special_requests(struct urb *urb) 173 + static int tweak_special_requests(struct urb *urb) 171 174 { 175 + int err; 176 + 172 177 if (!urb || !urb->setup_packet) 173 - return; 178 + return 0; 174 179 175 180 if (usb_pipetype(urb->pipe) != PIPE_CONTROL) 176 - return; 181 + return 0; 177 182 178 183 if (is_clear_halt_cmd(urb)) 179 184 /* tweak clear_halt */ 180 - tweak_clear_halt_cmd(urb); 185 + err = tweak_clear_halt_cmd(urb); 181 186 182 187 else if (is_set_interface_cmd(urb)) 183 188 /* tweak set_interface */ 184 - tweak_set_interface_cmd(urb); 189 + err = tweak_set_interface_cmd(urb); 185 190 186 191 else if (is_set_configuration_cmd(urb)) 187 192 /* tweak set_configuration */ 188 - tweak_set_configuration_cmd(urb); 193 + err = tweak_set_configuration_cmd(urb); 189 194 190 195 else if (is_reset_device_cmd(urb)) 191 - tweak_reset_device_cmd(urb); 192 - else 196 + err = tweak_reset_device_cmd(urb); 197 + else { 193 198 usbip_dbg_stub_rx("no need to tweak\n"); 199 + return 0; 200 + } 201 + 202 + return !err; 194 203 } 195 204 196 205 /* ··· 477 468 int support_sg = 1; 478 469 int np = 0; 479 470 int ret, i; 471 + int is_tweaked; 480 472 481 473 if (pipe == -1) 482 474 return; ··· 590 580 priv->urbs[i]->pipe = pipe; 591 581 priv->urbs[i]->complete = stub_complete; 592 582 593 - /* no need to submit an intercepted request, but harmless? */ 594 - tweak_special_requests(priv->urbs[i]); 583 + /* 584 + * all URBs belong to a single PDU, so a global is_tweaked flag is 585 + * enough 586 + */ 587 + is_tweaked = tweak_special_requests(priv->urbs[i]); 595 588 596 589 masking_bogus_flags(priv->urbs[i]); 597 590 } ··· 607 594 608 595 /* urb is now ready to submit */ 609 596 for (i = 0; i < priv->num_urbs; i++) { 610 - ret = usb_submit_urb(priv->urbs[i], GFP_KERNEL); 597 + if (!is_tweaked) { 598 + ret = usb_submit_urb(priv->urbs[i], GFP_KERNEL); 611 599 612 - if (ret == 0) 613 - usbip_dbg_stub_rx("submit urb ok, seqnum %u\n", 614 - pdu->base.seqnum); 615 - else { 616 - dev_err(&udev->dev, "submit_urb error, %d\n", ret); 617 - usbip_dump_header(pdu); 618 - usbip_dump_urb(priv->urbs[i]); 600 + if (ret == 0) 601 + usbip_dbg_stub_rx("submit urb ok, seqnum %u\n", 602 + pdu->base.seqnum); 603 + else { 604 + dev_err(&udev->dev, "submit_urb error, %d\n", ret); 605 + usbip_dump_header(pdu); 606 + usbip_dump_urb(priv->urbs[i]); 619 607 608 + /* 609 + * Pessimistic. 610 + * This connection will be discarded. 611 + */ 612 + usbip_event_add(ud, SDEV_EVENT_ERROR_SUBMIT); 613 + break; 614 + } 615 + } else { 620 616 /* 621 - * Pessimistic. 622 - * This connection will be discarded. 617 + * An identical URB was already submitted in 618 + * tweak_special_requests(). Skip submitting this URB to not 619 + * duplicate the request. 623 620 */ 624 - usbip_event_add(ud, SDEV_EVENT_ERROR_SUBMIT); 625 - break; 621 + priv->urbs[i]->status = 0; 622 + stub_complete(priv->urbs[i]); 626 623 } 627 624 } 628 625
+3
include/linux/usb.h
··· 1171 1171 * post_reset method is called. 1172 1172 * @post_reset: Called by usb_reset_device() after the device 1173 1173 * has been reset 1174 + * @shutdown: Called at shut-down time to quiesce the device. 1174 1175 * @id_table: USB drivers use ID table to support hotplugging. 1175 1176 * Export this with MODULE_DEVICE_TABLE(usb,...). This must be set 1176 1177 * or your driver's probe function will never get called. ··· 1222 1221 1223 1222 int (*pre_reset)(struct usb_interface *intf); 1224 1223 int (*post_reset)(struct usb_interface *intf); 1224 + 1225 + void (*shutdown)(struct usb_interface *intf); 1225 1226 1226 1227 const struct usb_device_id *id_table; 1227 1228 const struct attribute_group **dev_groups;
+5 -5
include/linux/usb/gadget.h
··· 229 229 230 230 const char *name; 231 231 const struct usb_ep_ops *ops; 232 + const struct usb_endpoint_descriptor *desc; 233 + const struct usb_ss_ep_comp_descriptor *comp_desc; 232 234 struct list_head ep_list; 233 235 struct usb_ep_caps caps; 234 236 bool claimed; 235 237 bool enabled; 236 - unsigned maxpacket:16; 237 - unsigned maxpacket_limit:16; 238 - unsigned max_streams:16; 239 238 unsigned mult:2; 240 239 unsigned maxburst:5; 241 240 u8 address; 242 - const struct usb_endpoint_descriptor *desc; 243 - const struct usb_ss_ep_comp_descriptor *comp_desc; 241 + u16 maxpacket; 242 + u16 maxpacket_limit; 243 + u16 max_streams; 244 244 }; 245 245 246 246 /*-------------------------------------------------------------------------*/
+8
include/linux/usb/tcpci.h
··· 47 47 #define TCPC_SINK_FAST_ROLE_SWAP BIT(0) 48 48 49 49 #define TCPC_CONFIG_STD_OUTPUT 0x18 50 + #define TCPC_CONFIG_STD_OUTPUT_ORIENTATION_MASK BIT(0) 51 + #define TCPC_CONFIG_STD_OUTPUT_ORIENTATION_NORMAL 0 52 + #define TCPC_CONFIG_STD_OUTPUT_ORIENTATION_FLIPPED 1 50 53 51 54 #define TCPC_TCPC_CTRL 0x19 52 55 #define TCPC_TCPC_CTRL_ORIENTATION BIT(0) ··· 130 127 #define TCPC_DEV_CAP_2 0x26 131 128 #define TCPC_STD_INPUT_CAP 0x28 132 129 #define TCPC_STD_OUTPUT_CAP 0x29 130 + #define TCPC_STD_OUTPUT_CAP_ORIENTATION BIT(0) 133 131 134 132 #define TCPC_MSG_HDR_INFO 0x2e 135 133 #define TCPC_MSG_HDR_INFO_DATA_ROLE BIT(3) ··· 213 209 * swap following Discover Identity on SOP' occurs. 214 210 * Return true when the TCPM is allowed to request a Vconn swap 215 211 * after Discovery Identity on SOP. 212 + * @set_orientation: 213 + * Optional; Enable setting the connector orientation 214 + * CONFIG_STANDARD_OUTPUT (0x18) bit0. 216 215 */ 217 216 struct tcpci_data { 218 217 struct regmap *regmap; ··· 223 216 unsigned char auto_discharge_disconnect:1; 224 217 unsigned char vbus_vsafe0v:1; 225 218 unsigned char cable_comm_capable:1; 219 + unsigned char set_orientation:1; 226 220 227 221 int (*init)(struct tcpci *tcpci, struct tcpci_data *data); 228 222 int (*set_vconn)(struct tcpci *tcpci, struct tcpci_data *data,
+3
include/linux/usb/typec.h
··· 167 167 168 168 void typec_altmode_update_active(struct typec_altmode *alt, bool active); 169 169 170 + void typec_altmode_set_ops(struct typec_altmode *alt, 171 + const struct typec_altmode_ops *ops); 172 + 170 173 enum typec_plug_index { 171 174 TYPEC_PLUG_SOP_P, 172 175 TYPEC_PLUG_SOP_PP,
+3 -1
tools/testing/selftests/Makefile
··· 13 13 TARGETS += cpufreq 14 14 TARGETS += cpu-hotplug 15 15 TARGETS += damon 16 - TARGETS += devices 16 + TARGETS += devices/error_logs 17 + TARGETS += devices/probe 17 18 TARGETS += dmabuf-heaps 18 19 TARGETS += drivers/dma-buf 19 20 TARGETS += drivers/s390x/uvdevice ··· 253 252 install -m 744 kselftest/runner.sh $(INSTALL_PATH)/kselftest/ 254 253 install -m 744 kselftest/prefix.pl $(INSTALL_PATH)/kselftest/ 255 254 install -m 744 kselftest/ktap_helpers.sh $(INSTALL_PATH)/kselftest/ 255 + install -m 744 kselftest/ksft.py $(INSTALL_PATH)/kselftest/ 256 256 install -m 744 run_kselftest.sh $(INSTALL_PATH)/ 257 257 rm -f $(TEST_LIST) 258 258 @ret=1; \
-4
tools/testing/selftests/devices/Makefile
··· 1 - TEST_PROGS := test_discoverable_devices.py 2 - TEST_FILES := boards ksft.py 3 - 4 - include ../lib.mk
tools/testing/selftests/devices/boards/Dell Inc.,XPS 13 9300.yaml tools/testing/selftests/devices/probe/boards/Dell Inc.,XPS 13 9300.yaml
+4
tools/testing/selftests/devices/boards/google,spherion.yaml tools/testing/selftests/devices/probe/boards/google,spherion.yaml
··· 11 11 # this, several optional keys can be used: 12 12 # - dt-mmio: identify the MMIO address of the controller as defined in the 13 13 # Devicetree. 14 + # - of-fullname-regex: regular expression to match against the OF_FULLNAME 15 + # property. Useful when the controller's address is not unique across other 16 + # sibling controllers. In this case, dt-mmio can't be used, and this property 17 + # allows the matching to include parent nodes as well to make it unique. 14 18 # - usb-version: for USB controllers to differentiate between USB3 and USB2 15 19 # buses sharing the same controller. 16 20 # - acpi-uid: _UID property of the controller as supplied by the ACPI. Useful to
+3
tools/testing/selftests/devices/error_logs/Makefile
··· 1 + TEST_PROGS := test_device_error_logs.py 2 + 3 + include ../../lib.mk
+85
tools/testing/selftests/devices/error_logs/test_device_error_logs.py
··· 1 + #!/usr/bin/env python3 2 + # SPDX-License-Identifier: GPL-2.0 3 + # 4 + # Copyright (c) 2024 Collabora Ltd 5 + # 6 + # This test checks for the presence of error (or more critical) log messages 7 + # coming from devices in the kernel log. 8 + # 9 + # One failed test case is reported for each device that has outputted error 10 + # logs. Devices with no errors do not produce a passing test case to avoid 11 + # polluting the results, therefore a successful run will list 0 tests run. 12 + # 13 + 14 + import glob 15 + import os 16 + import re 17 + import sys 18 + 19 + # Allow ksft module to be imported from different directory 20 + this_dir = os.path.dirname(os.path.realpath(__file__)) 21 + sys.path.append(os.path.join(this_dir, "../../kselftest/")) 22 + 23 + import ksft 24 + 25 + kmsg = "/dev/kmsg" 26 + 27 + RE_log = re.compile( 28 + r"(?P<prefix>[0-9]+),(?P<sequence>[0-9]+),(?P<timestamp>[0-9]+),(?P<flag>[^;]*)(,[^;]*)*;(?P<message>.*)" 29 + ) 30 + RE_tag = re.compile(r" (?P<key>[^=]+)=(?P<value>.*)") 31 + 32 + PREFIX_ERROR = 3 33 + 34 + logs = [] 35 + error_log_per_device = {} 36 + 37 + 38 + def parse_kmsg(): 39 + current_log = {} 40 + 41 + with open(kmsg) as f: 42 + os.set_blocking(f.fileno(), False) 43 + 44 + for line in f: 45 + tag_line = RE_tag.match(line) 46 + log_line = RE_log.match(line) 47 + 48 + if log_line: 49 + if current_log: 50 + logs.append(current_log) # Save last log 51 + 52 + current_log = { 53 + "prefix": int(log_line.group("prefix")), 54 + "sequence": int(log_line.group("sequence")), 55 + "timestamp": int(log_line.group("timestamp")), 56 + "flag": log_line.group("flag"), 57 + "message": log_line.group("message"), 58 + } 59 + elif tag_line: 60 + current_log[tag_line.group("key")] = tag_line.group("value") 61 + 62 + 63 + def generate_per_device_error_log(): 64 + for log in logs: 65 + if log.get("DEVICE") and log["prefix"] <= PREFIX_ERROR: 66 + if not error_log_per_device.get(log["DEVICE"]): 67 + error_log_per_device[log["DEVICE"]] = [] 68 + error_log_per_device[log["DEVICE"]].append(log) 69 + 70 + 71 + parse_kmsg() 72 + 73 + generate_per_device_error_log() 74 + num_tests = len(error_log_per_device) 75 + 76 + ksft.print_header() 77 + ksft.set_plan(num_tests) 78 + 79 + for device in error_log_per_device: 80 + for log in error_log_per_device[device]: 81 + ksft.print_msg(log["message"]) 82 + ksft.test_result_fail(device) 83 + if num_tests == 0: 84 + ksft.print_msg("No device error logs found") 85 + ksft.finished()
tools/testing/selftests/devices/ksft.py tools/testing/selftests/kselftest/ksft.py
+4
tools/testing/selftests/devices/probe/Makefile
··· 1 + TEST_PROGS := test_discoverable_devices.py 2 + TEST_FILES := boards 3 + 4 + include ../../lib.mk
+42 -2
tools/testing/selftests/devices/test_discoverable_devices.py tools/testing/selftests/devices/probe/test_discoverable_devices.py
··· 14 14 # the description and examples of the file structure and vocabulary. 15 15 # 16 16 17 + import argparse 17 18 import glob 18 - import ksft 19 19 import os 20 20 import re 21 21 import sys 22 22 import yaml 23 + 24 + # Allow ksft module to be imported from different directory 25 + this_dir = os.path.dirname(os.path.realpath(__file__)) 26 + sys.path.append(os.path.join(this_dir, "../../kselftest/")) 27 + 28 + import ksft 23 29 24 30 pci_controllers = [] 25 31 usb_controllers = [] ··· 69 63 sysfs_dev_dir = os.path.dirname(sysfs_dev_dir) 70 64 71 65 66 + def get_of_fullname(sysfs_dev_dir): 67 + re_of_fullname = re.compile("OF_FULLNAME=(.*)") 68 + of_full_name = None 69 + 70 + # PCI controllers' sysfs don't have an of_node, so have to read it from the 71 + # parent 72 + while not of_full_name: 73 + try: 74 + with open(os.path.join(sysfs_dev_dir, "uevent")) as f: 75 + of_fullname = re_of_fullname.search(f.read()).group(1) 76 + return of_fullname 77 + except: 78 + pass 79 + sysfs_dev_dir = os.path.dirname(sysfs_dev_dir) 80 + 81 + 72 82 def get_acpi_uid(sysfs_dev_dir): 73 83 with open(os.path.join(sysfs_dev_dir, "firmware_node", "uid")) as f: 74 84 return f.read() ··· 116 94 117 95 if controller.get("dt-mmio"): 118 96 if str(controller["dt-mmio"]) != get_dt_mmio(c): 97 + continue 98 + 99 + if controller.get("of-fullname-regex"): 100 + re_of_fullname = re.compile(str(controller["of-fullname-regex"])) 101 + if not re_of_fullname.match(get_of_fullname(c)): 119 102 continue 120 103 121 104 if controller.get("usb-version"): ··· 220 193 221 194 if device.get("dt-mmio"): 222 195 pathname += "@" + str(device["dt-mmio"]) 196 + 197 + if device.get("of-fullname-regex"): 198 + pathname += "-" + str(device["of-fullname-regex"]) 223 199 224 200 if device.get("name"): 225 201 pathname = pathname + "/" + device["name"] ··· 326 296 parse_device_tree_node(device_tree) 327 297 328 298 299 + parser = argparse.ArgumentParser() 300 + parser.add_argument( 301 + "--boards-dir", default="boards", help="Directory containing the board YAML files" 302 + ) 303 + args = parser.parse_args() 304 + 329 305 find_pci_controller_dirs() 330 306 find_usb_controller_dirs() 331 307 332 308 ksft.print_header() 333 309 310 + if not os.path.exists(args.boards_dir): 311 + ksft.print_msg(f"Boards directory '{args.boards_dir}' doesn't exist") 312 + ksft.exit_fail() 313 + 334 314 board_file = "" 335 315 for board_filename in get_board_filenames(): 336 - full_board_filename = os.path.join("boards", board_filename + ".yaml") 316 + full_board_filename = os.path.join(args.boards_dir, board_filename + ".yaml") 337 317 338 318 if os.path.exists(full_board_filename): 339 319 board_file = full_board_filename