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.1-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 driver changes for 6.1-rc1.

Nothing major in here, lots of little things with new devices
supported and updates for a few drivers. Highlights include:

- thunderbolt/USB4 devices supported a bit better than before, and
some new ids to enable new hardware devices

- USB gadget uvc updates for newer video formats and better v4l
integration (the v4l portions were acked by those maintainers)

- typec updates for tiny issues and more typec drivers for new chips.

- xhci tiny updates for minor issues

- big usb-serial ftdi_sio driver update to handle new devices better

- lots of tiny dwc3 fixes and updates for the IP block that is
showing up everywhere these days

- dts updates for new devices being supported

- other tiny janitorial and cleanups fixes for lots of different USB
drivers. Full details are in the shortlog.

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

* tag 'usb-6.1-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb: (169 commits)
usb: gadget: uvc: don't put item still in use
usb: gadget: uvc: Fix argument to sizeof() in uvc_register_video()
usb: host: ehci-exynos: switch to using gpiod API
Revert "usb: dwc3: Don't switch OTG -> peripheral if extcon is present"
Revert "USB: fixup for merge issue with "usb: dwc3: Don't switch OTG -> peripheral if extcon is present""
dt-bindings: usb: Convert FOTG210 to dt schema
usb: mtu3: fix failed runtime suspend in host only mode
USB: omap_udc: Fix spelling mistake: "tranceiver_ctrl" -> "transceiver_ctrl"
usb: typec: ucsi_ccg: Disable UCSI ALT support on Tegra
usb: typec: Replace custom implementation of device_match_fwnode()
usb: typec: ucsi: Don't warn on probe deferral
usb: add quirks for Lenovo OneLink+ Dock
MAINTAINERS: switch dwc3 to Thinh
usb: idmouse: fix an uninit-value in idmouse_open
USB: PHY: JZ4770: Switch to use dev_err_probe() helper
usb: phy: generic: Switch to use dev_err_probe() helper
usb: ulpi: use DEFINE_SHOW_ATTRIBUTE to simplify ulpi_regs
usb: cdns3: remove dead code
usb: cdc-wdm: Use skb_put_data() instead of skb_put/memcpy pair
usb: musb: sunxi: Switch to use dev_err_probe() helper
...

+4600 -2276
+2 -2
Documentation/ABI/testing/sysfs-bus-thunderbolt
··· 153 153 KernelVersion: 5.5 154 154 Contact: Mika Westerberg <mika.westerberg@linux.intel.com> 155 155 Description: This attribute reports number of RX lanes the device is 156 - using simultaneusly through its upstream port. 156 + using simultaneously through its upstream port. 157 157 158 158 What: /sys/bus/thunderbolt/devices/.../tx_speed 159 159 Date: Jan 2020 ··· 167 167 KernelVersion: 5.5 168 168 Contact: Mika Westerberg <mika.westerberg@linux.intel.com> 169 169 Description: This attribute reports number of TX lanes the device is 170 - using simultaneusly through its upstream port. 170 + using simultaneously through its upstream port. 171 171 172 172 What: /sys/bus/thunderbolt/devices/.../vendor 173 173 Date: Sep 2017
+2 -2
Documentation/devicetree/bindings/phy/mxs-usb-phy.txt
··· 15 15 - fsl,anatop: phandle for anatop register, it is only for imx6 SoC series 16 16 17 17 Optional properties: 18 - - fsl,tx-cal-45-dn-ohms: Integer [30-55]. Resistance (in ohms) of switchable 18 + - fsl,tx-cal-45-dn-ohms: Integer [35-54]. Resistance (in ohms) of switchable 19 19 high-speed trimming resistor connected in parallel with the 45 ohm resistor 20 20 that terminates the DN output signal. Default: 45 21 - - fsl,tx-cal-45-dp-ohms: Integer [30-55]. Resistance (in ohms) of switchable 21 + - fsl,tx-cal-45-dp-ohms: Integer [35-54]. Resistance (in ohms) of switchable 22 22 high-speed trimming resistor connected in parallel with the 45 ohm resistor 23 23 that terminates the DP output signal. Default: 45 24 24 - fsl,tx-d-cal: Integer [79-119]. Current trimming value (as a percentage) of
+2
Documentation/devicetree/bindings/usb/analogix,anx7411.yaml
··· 23 23 connector: 24 24 type: object 25 25 $ref: ../connector/usb-connector.yaml 26 + unevaluatedProperties: false 27 + 26 28 description: 27 29 Properties for usb c connector. 28 30
+2
Documentation/devicetree/bindings/usb/aspeed,usb-vhub.yaml
··· 67 67 68 68 vhub-strings: 69 69 type: object 70 + additionalProperties: false 70 71 71 72 properties: 72 73 '#address-cells': ··· 79 78 patternProperties: 80 79 '^string@[0-9a-f]+$': 81 80 type: object 81 + additionalProperties: false 82 82 description: string descriptors of the specific language 83 83 84 84 properties:
+1
Documentation/devicetree/bindings/usb/dwc2.yaml
··· 32 32 - enum: 33 33 - rockchip,px30-usb 34 34 - rockchip,rk3036-usb 35 + - rockchip,rk3128-usb 35 36 - rockchip,rk3188-usb 36 37 - rockchip,rk3228-usb 37 38 - rockchip,rk3288-usb
-35
Documentation/devicetree/bindings/usb/faraday,fotg210.txt
··· 1 - Faraday FOTG Host controller 2 - 3 - This OTG-capable USB host controller is found in Cortina Systems 4 - Gemini and other SoC products. 5 - 6 - Required properties: 7 - - compatible: should be one of: 8 - "faraday,fotg210" 9 - "cortina,gemini-usb", "faraday,fotg210" 10 - - reg: should contain one register range i.e. start and length 11 - - interrupts: description of the interrupt line 12 - 13 - Optional properties: 14 - - clocks: should contain the IP block clock 15 - - clock-names: should be "PCLK" for the IP block clock 16 - 17 - Required properties for "cortina,gemini-usb" compatible: 18 - - syscon: a phandle to the system controller to access PHY registers 19 - 20 - Optional properties for "cortina,gemini-usb" compatible: 21 - - cortina,gemini-mini-b: boolean property that indicates that a Mini-B 22 - OTG connector is in use 23 - - wakeup-source: see power/wakeup-source.txt 24 - 25 - Example for Gemini: 26 - 27 - usb@68000000 { 28 - compatible = "cortina,gemini-usb", "faraday,fotg210"; 29 - reg = <0x68000000 0x1000>; 30 - interrupts = <10 IRQ_TYPE_LEVEL_HIGH>; 31 - clocks = <&cc 12>; 32 - clock-names = "PCLK"; 33 - syscon = <&syscon>; 34 - wakeup-source; 35 - };
+77
Documentation/devicetree/bindings/usb/faraday,fotg210.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) 2 + # Copyright 2022 Linaro Ltd. 3 + %YAML 1.2 4 + --- 5 + $id: http://devicetree.org/schemas/usb/faraday,fotg210.yaml# 6 + $schema: http://devicetree.org/meta-schemas/core.yaml# 7 + 8 + title: Faraday Technology FOTG210 HS OTG USB 2.0 controller Bindings 9 + 10 + maintainers: 11 + - Linus Walleij <linus.walleij@linaro.org> 12 + 13 + allOf: 14 + - $ref: usb-drd.yaml# 15 + - $ref: usb-hcd.yaml# 16 + 17 + properties: 18 + compatible: 19 + oneOf: 20 + - const: faraday,fotg210 21 + - items: 22 + - const: cortina,gemini-usb 23 + - const: faraday,fotg210 24 + 25 + reg: 26 + maxItems: 1 27 + 28 + interrupts: 29 + maxItems: 1 30 + 31 + clocks: 32 + maxItems: 1 33 + 34 + clock-names: 35 + items: 36 + - const: PCLK 37 + 38 + resets: 39 + maxItems: 1 40 + 41 + syscon: 42 + $ref: /schemas/types.yaml#/definitions/phandle 43 + description: a phandle to the global Gemini system controller on 44 + Gemini systems 45 + 46 + dr_mode: true 47 + 48 + phys: 49 + maxItems: 1 50 + 51 + phy-names: 52 + const: usb2-phy 53 + 54 + required: 55 + - compatible 56 + - reg 57 + - interrupts 58 + - clocks 59 + - clock-names 60 + 61 + additionalProperties: false 62 + 63 + examples: 64 + - | 65 + #include <dt-bindings/interrupt-controller/irq.h> 66 + #include <dt-bindings/clock/cortina,gemini-clock.h> 67 + #include <dt-bindings/reset/cortina,gemini-reset.h> 68 + usb0: usb@68000000 { 69 + compatible = "cortina,gemini-usb", "faraday,fotg210"; 70 + reg = <0x68000000 0x1000>; 71 + interrupts = <10 IRQ_TYPE_LEVEL_HIGH>; 72 + resets = <&syscon GEMINI_RESET_USB0>; 73 + clocks = <&syscon GEMINI_CLK_GATE_USB0>; 74 + clock-names = "PCLK"; 75 + syscon = <&syscon>; 76 + dr_mode = "host"; 77 + };
+36
Documentation/devicetree/bindings/usb/mediatek,mt6370-tcpc.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/mediatek,mt6370-tcpc.yaml#" 5 + $schema: "http://devicetree.org/meta-schemas/core.yaml#" 6 + 7 + title: MediatTek MT6370 Type-C Port Switch and Power Delivery controller 8 + 9 + maintainers: 10 + - ChiYuan Huang <cy_huang@richtek.com> 11 + 12 + description: | 13 + MediaTek MT6370 is a multi-functional device. 14 + It integrates charger, ADC, flash, RGB indicators, 15 + regulators (DSV/VIBLDO), and TypeC Port Switch with Power Delivery controller. 16 + This document only describes MT6370 Type-C Port Switch and 17 + Power Delivery controller. 18 + 19 + properties: 20 + compatible: 21 + enum: 22 + - mediatek,mt6370-tcpc 23 + 24 + interrupts: 25 + maxItems: 1 26 + 27 + connector: 28 + type: object 29 + $ref: /schemas/connector/usb-connector.yaml# 30 + unevaluatedProperties: false 31 + 32 + additionalProperties: false 33 + 34 + required: 35 + - compatible 36 + - interrupts
+3 -1
Documentation/devicetree/bindings/usb/npcm7xx-usb.txt
··· 5 5 ----- 6 6 7 7 Required properties: 8 - - compatible: "nuvoton,npcm750-ehci" 8 + - compatible: should be one of 9 + "nuvoton,npcm750-ehci" 10 + "nuvoton,npcm845-ehci" 9 11 - interrupts: Should contain the EHCI interrupt 10 12 - reg: Physical address and length of the register set for the device 11 13
+5 -1
Documentation/devicetree/bindings/usb/qcom,dwc3.yaml
··· 26 26 - qcom,sc7280-dwc3 27 27 - qcom,sc8280xp-dwc3 28 28 - qcom,sdm660-dwc3 29 + - qcom,sdm670-dwc3 29 30 - qcom,sdm845-dwc3 30 31 - qcom,sdx55-dwc3 31 32 - qcom,sdx65-dwc3 ··· 176 175 - qcom,msm8998-dwc3 177 176 - qcom,sc7180-dwc3 178 177 - qcom,sc7280-dwc3 178 + - qcom,sdm670-dwc3 179 179 - qcom,sdm845-dwc3 180 180 - qcom,sdx55-dwc3 181 181 - qcom,sm6350-dwc3 ··· 296 294 compatible: 297 295 contains: 298 296 enum: 297 + - qcom,sm6115-dwc3 299 298 - qcom,sm6125-dwc3 300 299 - qcom,sm8150-dwc3 301 300 - qcom,sm8250-dwc3 ··· 347 344 - qcom,msm8994-dwc3 348 345 - qcom,qcs404-dwc3 349 346 - qcom,sc7180-dwc3 347 + - qcom,sdm670-dwc3 350 348 - qcom,sdm845-dwc3 351 349 - qcom,sdx55-dwc3 352 350 - qcom,sdx65-dwc3 353 351 - qcom,sm4250-dwc3 354 - - qcom,sm6115-dwc3 355 352 - qcom,sm6125-dwc3 356 353 - qcom,sm6350-dwc3 357 354 - qcom,sm8150-dwc3 ··· 383 380 - qcom,msm8953-dwc3 384 381 - qcom,msm8996-dwc3 385 382 - qcom,msm8998-dwc3 383 + - qcom,sm6115-dwc3 386 384 then: 387 385 properties: 388 386 interrupts:
+84 -15
Documentation/devicetree/bindings/usb/renesas,usb3-peri.yaml
··· 11 11 12 12 properties: 13 13 compatible: 14 - items: 15 - - enum: 16 - - renesas,r8a774a1-usb3-peri # RZ/G2M 17 - - renesas,r8a774b1-usb3-peri # RZ/G2N 18 - - renesas,r8a774c0-usb3-peri # RZ/G2E 19 - - renesas,r8a774e1-usb3-peri # RZ/G2H 20 - - renesas,r8a7795-usb3-peri # R-Car H3 21 - - renesas,r8a7796-usb3-peri # R-Car M3-W 22 - - renesas,r8a77961-usb3-peri # R-Car M3-W+ 23 - - renesas,r8a77965-usb3-peri # R-Car M3-N 24 - - renesas,r8a77990-usb3-peri # R-Car E3 25 - - const: renesas,rcar-gen3-usb3-peri 14 + oneOf: 15 + - items: 16 + - enum: 17 + - renesas,r8a774a1-usb3-peri # RZ/G2M 18 + - renesas,r8a774b1-usb3-peri # RZ/G2N 19 + - renesas,r8a774c0-usb3-peri # RZ/G2E 20 + - renesas,r8a774e1-usb3-peri # RZ/G2H 21 + - renesas,r8a7795-usb3-peri # R-Car H3 22 + - renesas,r8a7796-usb3-peri # R-Car M3-W 23 + - renesas,r8a77961-usb3-peri # R-Car M3-W+ 24 + - renesas,r8a77965-usb3-peri # R-Car M3-N 25 + - renesas,r8a77990-usb3-peri # R-Car E3 26 + - const: renesas,rcar-gen3-usb3-peri 27 + 28 + - items: 29 + - enum: 30 + - renesas,r9a09g011-usb3-peri # RZ/V2M 31 + - const: renesas,rzv2m-usb3-peri 26 32 27 33 reg: 28 34 maxItems: 1 29 35 30 36 interrupts: 31 - maxItems: 1 37 + minItems: 1 38 + items: 39 + - description: Combined interrupt for DMA, SYS and ERR 40 + - description: Dual Role Device (DRD) 41 + - description: Battery Charging 42 + - description: Global Purpose Input 43 + 44 + interrupt-names: 45 + minItems: 1 46 + items: 47 + - const: all_p 48 + - const: drd 49 + - const: bc 50 + - const: gpi 32 51 33 52 clocks: 34 - maxItems: 1 53 + minItems: 1 54 + items: 55 + - description: Main clock 56 + - description: Register access clock 57 + 58 + clock-names: 59 + minItems: 1 60 + items: 61 + - const: aclk 62 + - const: reg 35 63 36 64 phys: 37 65 maxItems: 1 ··· 71 43 maxItems: 1 72 44 73 45 resets: 74 - maxItems: 1 46 + minItems: 1 47 + items: 48 + - description: Peripheral reset 49 + - description: DRD reset 50 + 51 + reset-names: 52 + items: 53 + - const: aresetn_p 54 + - const: drd_reset 75 55 76 56 usb-role-switch: 77 57 $ref: /schemas/types.yaml#/definitions/flag ··· 113 77 - compatible 114 78 - interrupts 115 79 - clocks 80 + 81 + allOf: 82 + - if: 83 + properties: 84 + compatible: 85 + contains: 86 + enum: 87 + - renesas,rzv2m-usb3-peri 88 + then: 89 + properties: 90 + clocks: 91 + minItems: 2 92 + clock-names: 93 + minItems: 2 94 + interrupts: 95 + minItems: 4 96 + interrupt-names: 97 + minItems: 4 98 + resets: 99 + minItems: 2 100 + required: 101 + - clock-names 102 + - interrupt-names 103 + - resets 104 + - reset-names 105 + else: 106 + properties: 107 + clocks: 108 + maxItems: 1 109 + interrupts: 110 + maxItems: 1 111 + resets: 112 + maxItems: 1 116 113 117 114 additionalProperties: false 118 115
+100
Documentation/devicetree/bindings/usb/richtek,rt1711h.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + $id: "http://devicetree.org/schemas/usb/richtek,rt1711h.yaml#" 5 + $schema: "http://devicetree.org/meta-schemas/core.yaml#" 6 + 7 + title: Richtek RT1711H Type-C Port Switch and Power Delivery controller 8 + 9 + maintainers: 10 + - Gene Chen <gene_chen@richtek.com> 11 + 12 + description: | 13 + The RT1711H is a USB Type-C controller that complies with the latest 14 + USB Type-C and PD standards. It does the USB Type-C detection including attach 15 + and orientation. It integrates the physical layer of the USB BMC power 16 + delivery protocol to allow up to 100W of power. The BMC PD block enables full 17 + support for alternative interfaces of the Type-C specification. 18 + 19 + properties: 20 + compatible: 21 + enum: 22 + - richtek,rt1711h 23 + - richtek,rt1715 24 + description: 25 + RT1711H support PD20, RT1715 support PD30 except Fast Role Swap. 26 + 27 + reg: 28 + maxItems: 1 29 + 30 + interrupts: 31 + maxItems: 1 32 + 33 + wakeup-source: 34 + type: boolean 35 + 36 + connector: 37 + type: object 38 + $ref: /schemas/connector/usb-connector.yaml# 39 + description: 40 + Properties for usb c connector. 41 + 42 + additionalProperties: false 43 + 44 + required: 45 + - compatible 46 + - reg 47 + - connector 48 + - interrupts 49 + 50 + examples: 51 + - | 52 + #include <dt-bindings/interrupt-controller/irq.h> 53 + #include <dt-bindings/usb/pd.h> 54 + i2c0 { 55 + #address-cells = <1>; 56 + #size-cells = <0>; 57 + 58 + rt1711h@4e { 59 + compatible = "richtek,rt1711h"; 60 + reg = <0x4e>; 61 + interrupts-extended = <&gpio26 3 IRQ_TYPE_LEVEL_LOW>; 62 + wakeup-source; 63 + 64 + connector { 65 + compatible = "usb-c-connector"; 66 + label = "USB-C"; 67 + data-role = "dual"; 68 + power-role = "dual"; 69 + try-power-role = "sink"; 70 + source-pdos = <PDO_FIXED(5000, 2000, PDO_FIXED_DUAL_ROLE | PDO_FIXED_DATA_SWAP)>; 71 + sink-pdos = <PDO_FIXED(5000, 2000, PDO_FIXED_DUAL_ROLE | PDO_FIXED_DATA_SWAP)>; 72 + op-sink-microwatt = <10000000>; 73 + 74 + ports { 75 + #address-cells = <1>; 76 + #size-cells = <0>; 77 + 78 + port@0 { 79 + reg = <0>; 80 + endpoint { 81 + remote-endpoint = <&usb_hs>; 82 + }; 83 + }; 84 + port@1 { 85 + reg = <1>; 86 + endpoint { 87 + remote-endpoint = <&usb_ss>; 88 + }; 89 + }; 90 + port@2 { 91 + reg = <2>; 92 + endpoint { 93 + remote-endpoint = <&dp_aux>; 94 + }; 95 + }; 96 + }; 97 + }; 98 + }; 99 + }; 100 + ...
+12
Documentation/devicetree/bindings/usb/snps,dwc3.yaml
··· 234 234 avoid -EPROTO errors with usbhid on some devices (Hikey 970). 235 235 type: boolean 236 236 237 + snps,gfladj-refclk-lpm-sel-quirk: 238 + description: 239 + When set, run the SOF/ITP counter based on ref_clk. 240 + type: boolean 241 + 242 + snps,resume-hs-terminations: 243 + description: 244 + Fix the issue of HS terminations CRC error on resume by enabling this 245 + quirk. When set, all the termsel, xcvrsel, opmode becomes 0 during end 246 + of resume. This option is to support certain legacy ULPI PHYs. 247 + type: boolean 248 + 237 249 snps,is-utmi-l1-suspend: 238 250 description: 239 251 True when DWC3 asserts output signal utmi_l1_suspend_n, false when
+9 -3
Documentation/devicetree/bindings/usb/st,stusb160x.yaml
··· 33 33 connector: 34 34 type: object 35 35 $ref: /schemas/connector/usb-connector.yaml# 36 + unevaluatedProperties: false 36 37 37 38 properties: 38 39 compatible: ··· 75 74 data-role = "dual"; 76 75 typec-power-opmode = "default"; 77 76 78 - port { 79 - typec_con_ep: endpoint { 80 - remote-endpoint = <&usbotg_hs_ep>; 77 + ports { 78 + #address-cells = <1>; 79 + #size-cells = <0>; 80 + port@0 { 81 + reg = <0>; 82 + typec_con_ep: endpoint { 83 + remote-endpoint = <&usbotg_hs_ep>; 84 + }; 81 85 }; 82 86 }; 83 87 };
+1
Documentation/devicetree/bindings/usb/willsemi,wusb3801.yaml
··· 28 28 connector: 29 29 type: object 30 30 $ref: ../connector/usb-connector.yaml# 31 + unevaluatedProperties: false 31 32 description: 32 33 The managed USB Type-C connector. Since WUSB3801 does not support 33 34 Power Delivery, the node should have the "pd-disable" property.
+6 -7
Documentation/usb/usbip_protocol.rst
··· 340 340 | 0 | 20 | usbip_header_basic, 'command' shall be 0x00000001 | 341 341 +-----------+--------+---------------------------------------------------+ 342 342 | 0x14 | 4 | transfer_flags: possible values depend on the | 343 - | | | URB transfer_flags (refer to URB doc in | 344 - | | | Documentation/driver-api/usb/URB.rst) | 345 - | | | but with URB_NO_TRANSFER_DMA_MAP masked. Refer to | 346 - | | | function usbip_pack_cmd_submit and function | 347 - | | | tweak_transfer_flags in drivers/usb/usbip/ | 348 - | | | usbip_common.c. The following fields may also ref | 349 - | | | to function usbip_pack_cmd_submit and URB doc | 343 + | | | USBIP_URB transfer_flags. | 344 + | | | Refer to include/uapi/linux/usbip.h and | 345 + | | | Documentation/driver-api/usb/URB.rst. | 346 + | | | Refer to usbip_pack_cmd_submit() and | 347 + | | | tweak_transfer_flags() in drivers/usb/usbip/ | 348 + | | | usbip_common.c. | 350 349 +-----------+--------+---------------------------------------------------+ 351 350 | 0x18 | 4 | transfer_buffer_length: | 352 351 | | | use URB transfer_buffer_length |
+1 -2
MAINTAINERS
··· 5921 5921 F: drivers/usb/dwc2/ 5922 5922 5923 5923 DESIGNWARE USB3 DRD IP DRIVER 5924 - M: Felipe Balbi <balbi@kernel.org> 5924 + M: Thinh Nguyen <Thinh.Nguyen@synopsys.com> 5925 5925 L: linux-usb@vger.kernel.org 5926 5926 S: Maintained 5927 - T: git git://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb.git 5928 5927 F: drivers/usb/dwc3/ 5929 5928 5930 5929 DEVANTECH SRF ULTRASONIC RANGER IIO DRIVER
+9 -1
arch/arm/mach-s3c/mach-gta02.c
··· 421 421 /* Get PMU to set USB current limit accordingly. */ 422 422 static struct s3c2410_udc_mach_info gta02_udc_cfg __initdata = { 423 423 .vbus_draw = gta02_udc_vbus_draw, 424 - .pullup_pin = GTA02_GPIO_USB_PULLUP, 424 + }; 425 + 426 + static struct gpiod_lookup_table gta02_udc_gpio_table = { 427 + .dev_id = "s3c2410-usbgadget", 428 + .table = { 429 + GPIO_LOOKUP("GPIOB", 9, "pullup", GPIO_ACTIVE_HIGH), 430 + { }, 431 + }, 425 432 }; 426 433 427 434 /* USB */ ··· 562 555 s3c_gpio_cfgall_range(S3C2410_GPE(0), 5, S3C_GPIO_SFN(2), 563 556 S3C_GPIO_PULL_NONE); 564 557 558 + gpiod_add_lookup_table(&gta02_udc_gpio_table); 565 559 gpiod_add_lookup_table(&gta02_audio_gpio_table); 566 560 gpiod_add_lookup_table(&gta02_mmc_gpio_table); 567 561 platform_add_devices(gta02_devices, ARRAY_SIZE(gta02_devices));
+10 -3
arch/arm/mach-s3c/mach-h1940.c
··· 167 167 }; 168 168 169 169 static struct s3c2410_udc_mach_info h1940_udc_cfg __initdata = { 170 - .vbus_pin = S3C2410_GPG(5), 171 - .vbus_pin_inverted = 1, 172 - .pullup_pin = H1940_LATCH_USB_DP, 170 + }; 171 + 172 + static struct gpiod_lookup_table h1940_udc_gpio_table = { 173 + .dev_id = "s3c2410-usbgadget", 174 + .table = { 175 + GPIO_LOOKUP("GPIOG", 5, "vbus", GPIO_ACTIVE_LOW), 176 + GPIO_LOOKUP("H1940_LATCH", 7, "pullup", GPIO_ACTIVE_HIGH), 177 + { }, 178 + }, 173 179 }; 174 180 175 181 static struct s3c2410_ts_mach_info h1940_ts_cfg __initdata = { ··· 731 725 u32 tmp; 732 726 733 727 s3c24xx_fb_set_platdata(&h1940_fb_info); 728 + gpiod_add_lookup_table(&h1940_udc_gpio_table); 734 729 gpiod_add_lookup_table(&h1940_mmc_gpio_table); 735 730 gpiod_add_lookup_table(&h1940_audio_gpio_table); 736 731 gpiod_add_lookup_table(&h1940_bat_gpio_table);
+9 -1
arch/arm/mach-s3c/mach-jive.c
··· 493 493 }; 494 494 495 495 static struct s3c2410_udc_mach_info jive_udc_cfg __initdata = { 496 - .vbus_pin = S3C2410_GPG(1), /* detect is on GPG1 */ 496 + }; 497 + 498 + static struct gpiod_lookup_table jive_udc_gpio_table = { 499 + .dev_id = "s3c2410-usbgadget", 500 + .table = { 501 + GPIO_LOOKUP("GPIOG", 1, "vbus", GPIO_ACTIVE_HIGH), 502 + { }, 503 + }, 497 504 }; 498 505 499 506 /* Jive power management device */ ··· 676 669 677 670 pm_power_off = jive_power_off; 678 671 672 + gpiod_add_lookup_table(&jive_udc_gpio_table); 679 673 gpiod_add_lookup_table(&jive_lcdspi_gpiod_table); 680 674 gpiod_add_lookup_table(&jive_wm8750_gpiod_table); 681 675 platform_add_devices(jive_devices, ARRAY_SIZE(jive_devices));
+8 -1
arch/arm/mach-s3c/mach-mini2440.c
··· 93 93 /* USB device UDC support */ 94 94 95 95 static struct s3c2410_udc_mach_info mini2440_udc_cfg __initdata = { 96 - .pullup_pin = S3C2410_GPC(5), 97 96 }; 98 97 98 + static struct gpiod_lookup_table mini2440_udc_gpio_table = { 99 + .dev_id = "s3c2410-usbgadget", 100 + .table = { 101 + GPIO_LOOKUP("GPIOC", 5, "pullup", GPIO_ACTIVE_HIGH), 102 + { }, 103 + }, 104 + }; 99 105 100 106 /* LCD timing and setup */ 101 107 ··· 761 755 s3c24xx_fb_set_platdata(&mini2440_fb_info); 762 756 } 763 757 758 + gpiod_add_lookup_table(&mini2440_udc_gpio_table); 764 759 s3c24xx_udc_set_platdata(&mini2440_udc_cfg); 765 760 gpiod_add_lookup_table(&mini2440_mmc_gpio_table); 766 761 s3c24xx_mci_set_platdata(&mini2440_mmc_cfg);
+10 -3
arch/arm/mach-s3c/mach-n30.c
··· 84 84 }; 85 85 86 86 static struct s3c2410_udc_mach_info n30_udc_cfg __initdata = { 87 - .vbus_pin = S3C2410_GPG(1), 88 - .vbus_pin_inverted = 0, 89 - .pullup_pin = S3C2410_GPB(3), 87 + }; 88 + 89 + static struct gpiod_lookup_table n30_udc_gpio_table = { 90 + .dev_id = "s3c2410-usbgadget", 91 + .table = { 92 + GPIO_LOOKUP("GPIOG", 1, "vbus", GPIO_ACTIVE_HIGH), 93 + GPIO_LOOKUP("GPIOB", 3, "pullup", GPIO_ACTIVE_HIGH), 94 + { }, 95 + }, 90 96 }; 91 97 92 98 static struct gpio_keys_button n30_buttons[] = { ··· 601 595 WARN_ON(gpio_request(S3C2410_GPG(4), "mmc power")); 602 596 603 597 s3c24xx_fb_set_platdata(&n30_fb_info); 598 + gpiod_add_lookup_table(&n30_udc_gpio_table); 604 599 s3c24xx_udc_set_platdata(&n30_udc_cfg); 605 600 gpiod_add_lookup_table(&n30_mci_gpio_table); 606 601 s3c24xx_mci_set_platdata(&n30_mci_cfg);
+10 -3
arch/arm/mach-s3c/mach-rx1950.c
··· 643 643 }; 644 644 645 645 static struct s3c2410_udc_mach_info rx1950_udc_cfg __initdata = { 646 - .vbus_pin = S3C2410_GPG(5), 647 - .vbus_pin_inverted = 1, 648 - .pullup_pin = S3C2410_GPJ(5), 646 + }; 647 + 648 + static struct gpiod_lookup_table rx1950_udc_gpio_table = { 649 + .dev_id = "s3c2410-usbgadget", 650 + .table = { 651 + GPIO_LOOKUP("GPIOG", 5, "vbus", GPIO_ACTIVE_LOW), 652 + GPIO_LOOKUP("GPIOJ", 5, "pullup", GPIO_ACTIVE_HIGH), 653 + { }, 654 + }, 649 655 }; 650 656 651 657 static struct s3c2410_ts_mach_info rx1950_ts_cfg __initdata = { ··· 853 847 gpio_direction_output(S3C2410_GPJ(6), 0); 854 848 855 849 pwm_add_table(rx1950_pwm_lookup, ARRAY_SIZE(rx1950_pwm_lookup)); 850 + gpiod_add_lookup_table(&rx1950_udc_gpio_table); 856 851 gpiod_add_lookup_table(&rx1950_audio_gpio_table); 857 852 gpiod_add_lookup_table(&rx1950_bat_gpio_table); 858 853 /* Configure the I2S pins (GPE0...GPE4) in correct mode */
+9 -3
arch/arm/mach-s3c/mach-smdk2413.c
··· 12 12 #include <linux/list.h> 13 13 #include <linux/timer.h> 14 14 #include <linux/init.h> 15 - #include <linux/gpio.h> 15 + #include <linux/gpio/machine.h> 16 16 #include <linux/serial_core.h> 17 17 #include <linux/serial_s3c.h> 18 18 #include <linux/platform_device.h> ··· 74 74 75 75 76 76 static struct s3c2410_udc_mach_info smdk2413_udc_cfg __initdata = { 77 - .pullup_pin = S3C2410_GPF(2), 78 77 }; 79 78 79 + static struct gpiod_lookup_table smdk2413_udc_gpio_table = { 80 + .dev_id = "s3c2410-usbgadget", 81 + .table = { 82 + GPIO_LOOKUP("GPIOF", 2, "pullup", GPIO_ACTIVE_HIGH), 83 + { }, 84 + }, 85 + }; 80 86 81 87 static struct platform_device *smdk2413_devices[] __initdata = { 82 88 &s3c_device_ohci, ··· 121 115 S3C2410_MISCCR_USBSUSPND0 | 122 116 S3C2410_MISCCR_USBSUSPND1, 0x0); 123 117 124 - 118 + gpiod_add_lookup_table(&smdk2413_udc_gpio_table); 125 119 s3c24xx_udc_set_platdata(&smdk2413_udc_cfg); 126 120 s3c_i2c0_set_platdata(NULL); 127 121 /* Configure the I2S pins (GPE0...GPE4) in correct mode */
+2 -2
arch/arm64/boot/dts/freescale/imx8mp.dtsi
··· 1299 1299 interrupts = <GIC_SPI 40 IRQ_TYPE_LEVEL_HIGH>; 1300 1300 phys = <&usb3_phy0>, <&usb3_phy0>; 1301 1301 phy-names = "usb2-phy", "usb3-phy"; 1302 - snps,dis-u2-freeclk-exists-quirk; 1302 + snps,gfladj-refclk-lpm-sel-quirk; 1303 1303 }; 1304 1304 1305 1305 }; ··· 1341 1341 interrupts = <GIC_SPI 41 IRQ_TYPE_LEVEL_HIGH>; 1342 1342 phys = <&usb3_phy1>, <&usb3_phy1>; 1343 1343 phy-names = "usb2-phy", "usb3-phy"; 1344 - snps,dis-u2-freeclk-exists-quirk; 1344 + snps,gfladj-refclk-lpm-sel-quirk; 1345 1345 }; 1346 1346 }; 1347 1347
+14 -8
drivers/media/usb/b2c2/flexcop-usb.c
··· 425 425 426 426 static int flexcop_usb_transfer_init(struct flexcop_usb *fc_usb) 427 427 { 428 - u16 frame_size = le16_to_cpu( 429 - fc_usb->uintf->cur_altsetting->endpoint[0].desc.wMaxPacketSize); 430 - int bufsize = B2C2_USB_NUM_ISO_URB * B2C2_USB_FRAMES_PER_ISO * 431 - frame_size, i, j, ret; 428 + struct usb_host_interface *alt = fc_usb->uintf->cur_altsetting; 429 + u16 frame_size; 430 + int bufsize, i, j, ret; 432 431 int buffer_offset = 0; 432 + 433 + frame_size = usb_endpoint_maxp(&alt->endpoint[0].desc); 434 + bufsize = B2C2_USB_NUM_ISO_URB * B2C2_USB_FRAMES_PER_ISO * frame_size; 433 435 434 436 deb_ts("creating %d iso-urbs with %d frames each of %d bytes size = %d.\n", 435 437 B2C2_USB_NUM_ISO_URB, ··· 503 501 504 502 static int flexcop_usb_init(struct flexcop_usb *fc_usb) 505 503 { 506 - /* use the alternate setting with the larges buffer */ 507 - int ret = usb_set_interface(fc_usb->udev, 0, 1); 504 + struct usb_host_interface *alt; 505 + int ret; 508 506 507 + /* use the alternate setting with the largest buffer */ 508 + ret = usb_set_interface(fc_usb->udev, 0, 1); 509 509 if (ret) { 510 510 err("set interface failed."); 511 511 return ret; 512 512 } 513 513 514 - if (fc_usb->uintf->cur_altsetting->desc.bNumEndpoints < 1) 514 + alt = fc_usb->uintf->cur_altsetting; 515 + 516 + if (alt->desc.bNumEndpoints < 1) 515 517 return -ENODEV; 516 - if (!usb_endpoint_is_isoc_in(&fc_usb->uintf->cur_altsetting->endpoint[0].desc)) 518 + if (!usb_endpoint_is_isoc_in(&alt->endpoint[0].desc)) 517 519 return -ENODEV; 518 520 519 521 switch (fc_usb->udev->speed) {
+1
drivers/media/usb/uvc/uvc_ctrl.c
··· 18 18 #include <linux/workqueue.h> 19 19 #include <linux/atomic.h> 20 20 #include <media/v4l2-ctrls.h> 21 + #include <media/v4l2-uvc.h> 21 22 22 23 #include "uvcvideo.h" 23 24
+1 -289
drivers/media/usb/uvc/uvc_driver.c
··· 20 20 21 21 #include <media/v4l2-common.h> 22 22 #include <media/v4l2-ioctl.h> 23 + #include <media/v4l2-uvc.h> 23 24 24 25 #include "uvcvideo.h" 25 26 ··· 36 35 unsigned int uvc_timeout_param = UVC_CTRL_STREAMING_TIMEOUT; 37 36 38 37 /* ------------------------------------------------------------------------ 39 - * Video formats 40 - */ 41 - 42 - static struct uvc_format_desc uvc_fmts[] = { 43 - { 44 - .name = "YUV 4:2:2 (YUYV)", 45 - .guid = UVC_GUID_FORMAT_YUY2, 46 - .fcc = V4L2_PIX_FMT_YUYV, 47 - }, 48 - { 49 - .name = "YUV 4:2:2 (YUYV)", 50 - .guid = UVC_GUID_FORMAT_YUY2_ISIGHT, 51 - .fcc = V4L2_PIX_FMT_YUYV, 52 - }, 53 - { 54 - .name = "YUV 4:2:0 (NV12)", 55 - .guid = UVC_GUID_FORMAT_NV12, 56 - .fcc = V4L2_PIX_FMT_NV12, 57 - }, 58 - { 59 - .name = "MJPEG", 60 - .guid = UVC_GUID_FORMAT_MJPEG, 61 - .fcc = V4L2_PIX_FMT_MJPEG, 62 - }, 63 - { 64 - .name = "YVU 4:2:0 (YV12)", 65 - .guid = UVC_GUID_FORMAT_YV12, 66 - .fcc = V4L2_PIX_FMT_YVU420, 67 - }, 68 - { 69 - .name = "YUV 4:2:0 (I420)", 70 - .guid = UVC_GUID_FORMAT_I420, 71 - .fcc = V4L2_PIX_FMT_YUV420, 72 - }, 73 - { 74 - .name = "YUV 4:2:0 (M420)", 75 - .guid = UVC_GUID_FORMAT_M420, 76 - .fcc = V4L2_PIX_FMT_M420, 77 - }, 78 - { 79 - .name = "YUV 4:2:2 (UYVY)", 80 - .guid = UVC_GUID_FORMAT_UYVY, 81 - .fcc = V4L2_PIX_FMT_UYVY, 82 - }, 83 - { 84 - .name = "Greyscale 8-bit (Y800)", 85 - .guid = UVC_GUID_FORMAT_Y800, 86 - .fcc = V4L2_PIX_FMT_GREY, 87 - }, 88 - { 89 - .name = "Greyscale 8-bit (Y8 )", 90 - .guid = UVC_GUID_FORMAT_Y8, 91 - .fcc = V4L2_PIX_FMT_GREY, 92 - }, 93 - { 94 - .name = "Greyscale 8-bit (D3DFMT_L8)", 95 - .guid = UVC_GUID_FORMAT_D3DFMT_L8, 96 - .fcc = V4L2_PIX_FMT_GREY, 97 - }, 98 - { 99 - .name = "IR 8-bit (L8_IR)", 100 - .guid = UVC_GUID_FORMAT_KSMEDIA_L8_IR, 101 - .fcc = V4L2_PIX_FMT_GREY, 102 - }, 103 - { 104 - .name = "Greyscale 10-bit (Y10 )", 105 - .guid = UVC_GUID_FORMAT_Y10, 106 - .fcc = V4L2_PIX_FMT_Y10, 107 - }, 108 - { 109 - .name = "Greyscale 12-bit (Y12 )", 110 - .guid = UVC_GUID_FORMAT_Y12, 111 - .fcc = V4L2_PIX_FMT_Y12, 112 - }, 113 - { 114 - .name = "Greyscale 16-bit (Y16 )", 115 - .guid = UVC_GUID_FORMAT_Y16, 116 - .fcc = V4L2_PIX_FMT_Y16, 117 - }, 118 - { 119 - .name = "BGGR Bayer (BY8 )", 120 - .guid = UVC_GUID_FORMAT_BY8, 121 - .fcc = V4L2_PIX_FMT_SBGGR8, 122 - }, 123 - { 124 - .name = "BGGR Bayer (BA81)", 125 - .guid = UVC_GUID_FORMAT_BA81, 126 - .fcc = V4L2_PIX_FMT_SBGGR8, 127 - }, 128 - { 129 - .name = "GBRG Bayer (GBRG)", 130 - .guid = UVC_GUID_FORMAT_GBRG, 131 - .fcc = V4L2_PIX_FMT_SGBRG8, 132 - }, 133 - { 134 - .name = "GRBG Bayer (GRBG)", 135 - .guid = UVC_GUID_FORMAT_GRBG, 136 - .fcc = V4L2_PIX_FMT_SGRBG8, 137 - }, 138 - { 139 - .name = "RGGB Bayer (RGGB)", 140 - .guid = UVC_GUID_FORMAT_RGGB, 141 - .fcc = V4L2_PIX_FMT_SRGGB8, 142 - }, 143 - { 144 - .name = "RGB565", 145 - .guid = UVC_GUID_FORMAT_RGBP, 146 - .fcc = V4L2_PIX_FMT_RGB565, 147 - }, 148 - { 149 - .name = "BGR 8:8:8 (BGR3)", 150 - .guid = UVC_GUID_FORMAT_BGR3, 151 - .fcc = V4L2_PIX_FMT_BGR24, 152 - }, 153 - { 154 - .name = "H.264", 155 - .guid = UVC_GUID_FORMAT_H264, 156 - .fcc = V4L2_PIX_FMT_H264, 157 - }, 158 - { 159 - .name = "H.265", 160 - .guid = UVC_GUID_FORMAT_H265, 161 - .fcc = V4L2_PIX_FMT_HEVC, 162 - }, 163 - { 164 - .name = "Greyscale 8 L/R (Y8I)", 165 - .guid = UVC_GUID_FORMAT_Y8I, 166 - .fcc = V4L2_PIX_FMT_Y8I, 167 - }, 168 - { 169 - .name = "Greyscale 12 L/R (Y12I)", 170 - .guid = UVC_GUID_FORMAT_Y12I, 171 - .fcc = V4L2_PIX_FMT_Y12I, 172 - }, 173 - { 174 - .name = "Depth data 16-bit (Z16)", 175 - .guid = UVC_GUID_FORMAT_Z16, 176 - .fcc = V4L2_PIX_FMT_Z16, 177 - }, 178 - { 179 - .name = "Bayer 10-bit (SRGGB10P)", 180 - .guid = UVC_GUID_FORMAT_RW10, 181 - .fcc = V4L2_PIX_FMT_SRGGB10P, 182 - }, 183 - { 184 - .name = "Bayer 16-bit (SBGGR16)", 185 - .guid = UVC_GUID_FORMAT_BG16, 186 - .fcc = V4L2_PIX_FMT_SBGGR16, 187 - }, 188 - { 189 - .name = "Bayer 16-bit (SGBRG16)", 190 - .guid = UVC_GUID_FORMAT_GB16, 191 - .fcc = V4L2_PIX_FMT_SGBRG16, 192 - }, 193 - { 194 - .name = "Bayer 16-bit (SRGGB16)", 195 - .guid = UVC_GUID_FORMAT_RG16, 196 - .fcc = V4L2_PIX_FMT_SRGGB16, 197 - }, 198 - { 199 - .name = "Bayer 16-bit (SGRBG16)", 200 - .guid = UVC_GUID_FORMAT_GR16, 201 - .fcc = V4L2_PIX_FMT_SGRBG16, 202 - }, 203 - { 204 - .name = "Depth data 16-bit (Z16)", 205 - .guid = UVC_GUID_FORMAT_INVZ, 206 - .fcc = V4L2_PIX_FMT_Z16, 207 - }, 208 - { 209 - .name = "Greyscale 10-bit (Y10 )", 210 - .guid = UVC_GUID_FORMAT_INVI, 211 - .fcc = V4L2_PIX_FMT_Y10, 212 - }, 213 - { 214 - .name = "IR:Depth 26-bit (INZI)", 215 - .guid = UVC_GUID_FORMAT_INZI, 216 - .fcc = V4L2_PIX_FMT_INZI, 217 - }, 218 - { 219 - .name = "4-bit Depth Confidence (Packed)", 220 - .guid = UVC_GUID_FORMAT_CNF4, 221 - .fcc = V4L2_PIX_FMT_CNF4, 222 - }, 223 - { 224 - .name = "HEVC", 225 - .guid = UVC_GUID_FORMAT_HEVC, 226 - .fcc = V4L2_PIX_FMT_HEVC, 227 - }, 228 - }; 229 - 230 - /* ------------------------------------------------------------------------ 231 38 * Utility functions 232 39 */ 233 40 ··· 49 240 ep = &alts->endpoint[i]; 50 241 if (ep->desc.bEndpointAddress == epaddr) 51 242 return ep; 52 - } 53 - 54 - return NULL; 55 - } 56 - 57 - static struct uvc_format_desc *uvc_format_by_guid(const u8 guid[16]) 58 - { 59 - unsigned int len = ARRAY_SIZE(uvc_fmts); 60 - unsigned int i; 61 - 62 - for (i = 0; i < len; ++i) { 63 - if (memcmp(guid, uvc_fmts[i].guid, 16) == 0) 64 - return &uvc_fmts[i]; 65 243 } 66 244 67 245 return NULL; ··· 123 327 return ycbcr_encs[matrix_coefficients]; 124 328 125 329 return V4L2_YCBCR_ENC_DEFAULT; /* Reserved */ 126 - } 127 - 128 - /* 129 - * Simplify a fraction using a simple continued fraction decomposition. The 130 - * idea here is to convert fractions such as 333333/10000000 to 1/30 using 131 - * 32 bit arithmetic only. The algorithm is not perfect and relies upon two 132 - * arbitrary parameters to remove non-significative terms from the simple 133 - * continued fraction decomposition. Using 8 and 333 for n_terms and threshold 134 - * respectively seems to give nice results. 135 - */ 136 - void uvc_simplify_fraction(u32 *numerator, u32 *denominator, 137 - unsigned int n_terms, unsigned int threshold) 138 - { 139 - u32 *an; 140 - u32 x, y, r; 141 - unsigned int i, n; 142 - 143 - an = kmalloc_array(n_terms, sizeof(*an), GFP_KERNEL); 144 - if (an == NULL) 145 - return; 146 - 147 - /* 148 - * Convert the fraction to a simple continued fraction. See 149 - * https://en.wikipedia.org/wiki/Continued_fraction 150 - * Stop if the current term is bigger than or equal to the given 151 - * threshold. 152 - */ 153 - x = *numerator; 154 - y = *denominator; 155 - 156 - for (n = 0; n < n_terms && y != 0; ++n) { 157 - an[n] = x / y; 158 - if (an[n] >= threshold) { 159 - if (n < 2) 160 - n++; 161 - break; 162 - } 163 - 164 - r = x - an[n] * y; 165 - x = y; 166 - y = r; 167 - } 168 - 169 - /* Expand the simple continued fraction back to an integer fraction. */ 170 - x = 0; 171 - y = 1; 172 - 173 - for (i = n; i > 0; --i) { 174 - r = y; 175 - y = an[i-1] * y + x; 176 - x = r; 177 - } 178 - 179 - *numerator = y; 180 - *denominator = x; 181 - kfree(an); 182 - } 183 - 184 - /* 185 - * Convert a fraction to a frame interval in 100ns multiples. The idea here is 186 - * to compute numerator / denominator * 10000000 using 32 bit fixed point 187 - * arithmetic only. 188 - */ 189 - u32 uvc_fraction_to_interval(u32 numerator, u32 denominator) 190 - { 191 - u32 multiplier; 192 - 193 - /* Saturate the result if the operation would overflow. */ 194 - if (denominator == 0 || 195 - numerator/denominator >= ((u32)-1)/10000000) 196 - return (u32)-1; 197 - 198 - /* 199 - * Divide both the denominator and the multiplier by two until 200 - * numerator * multiplier doesn't overflow. If anyone knows a better 201 - * algorithm please let me know. 202 - */ 203 - multiplier = 10000000; 204 - while (numerator > ((u32)-1)/multiplier) { 205 - multiplier /= 2; 206 - denominator /= 2; 207 - } 208 - 209 - return denominator ? numerator * multiplier / denominator : 0; 210 330 } 211 331 212 332 /* ------------------------------------------------------------------------
+7 -7
drivers/media/usb/uvc/uvc_v4l2.c
··· 386 386 mutex_unlock(&stream->mutex); 387 387 388 388 denominator = 10000000; 389 - uvc_simplify_fraction(&numerator, &denominator, 8, 333); 389 + v4l2_simplify_fraction(&numerator, &denominator, 8, 333); 390 390 391 391 memset(parm, 0, sizeof(*parm)); 392 392 parm->type = stream->type; ··· 427 427 else 428 428 timeperframe = parm->parm.output.timeperframe; 429 429 430 - interval = uvc_fraction_to_interval(timeperframe.numerator, 430 + interval = v4l2_fraction_to_interval(timeperframe.numerator, 431 431 timeperframe.denominator); 432 432 uvc_dbg(stream->dev, FORMAT, "Setting frame interval to %u/%u (%u)\n", 433 433 timeperframe.numerator, timeperframe.denominator, interval); ··· 481 481 /* Return the actual frame period. */ 482 482 timeperframe.numerator = probe.dwFrameInterval; 483 483 timeperframe.denominator = 10000000; 484 - uvc_simplify_fraction(&timeperframe.numerator, 484 + v4l2_simplify_fraction(&timeperframe.numerator, 485 485 &timeperframe.denominator, 8, 333); 486 486 487 487 if (parm->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) { ··· 1275 1275 fival->discrete.numerator = 1276 1276 frame->dwFrameInterval[index]; 1277 1277 fival->discrete.denominator = 10000000; 1278 - uvc_simplify_fraction(&fival->discrete.numerator, 1278 + v4l2_simplify_fraction(&fival->discrete.numerator, 1279 1279 &fival->discrete.denominator, 8, 333); 1280 1280 } else { 1281 1281 fival->type = V4L2_FRMIVAL_TYPE_STEPWISE; ··· 1285 1285 fival->stepwise.max.denominator = 10000000; 1286 1286 fival->stepwise.step.numerator = frame->dwFrameInterval[2]; 1287 1287 fival->stepwise.step.denominator = 10000000; 1288 - uvc_simplify_fraction(&fival->stepwise.min.numerator, 1288 + v4l2_simplify_fraction(&fival->stepwise.min.numerator, 1289 1289 &fival->stepwise.min.denominator, 8, 333); 1290 - uvc_simplify_fraction(&fival->stepwise.max.numerator, 1290 + v4l2_simplify_fraction(&fival->stepwise.max.numerator, 1291 1291 &fival->stepwise.max.denominator, 8, 333); 1292 - uvc_simplify_fraction(&fival->stepwise.step.numerator, 1292 + v4l2_simplify_fraction(&fival->stepwise.step.numerator, 1293 1293 &fival->stepwise.step.denominator, 8, 333); 1294 1294 } 1295 1295
-147
drivers/media/usb/uvc/uvcvideo.h
··· 42 42 #define UVC_EXT_GPIO_UNIT_ID 0x100 43 43 44 44 /* ------------------------------------------------------------------------ 45 - * GUIDs 46 - */ 47 - #define UVC_GUID_UVC_CAMERA \ 48 - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 49 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01} 50 - #define UVC_GUID_UVC_OUTPUT \ 51 - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 52 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02} 53 - #define UVC_GUID_UVC_MEDIA_TRANSPORT_INPUT \ 54 - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 55 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03} 56 - #define UVC_GUID_UVC_PROCESSING \ 57 - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 58 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01} 59 - #define UVC_GUID_UVC_SELECTOR \ 60 - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 61 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02} 62 - #define UVC_GUID_EXT_GPIO_CONTROLLER \ 63 - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 64 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03} 65 - 66 - #define UVC_GUID_FORMAT_MJPEG \ 67 - { 'M', 'J', 'P', 'G', 0x00, 0x00, 0x10, 0x00, \ 68 - 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 69 - #define UVC_GUID_FORMAT_YUY2 \ 70 - { 'Y', 'U', 'Y', '2', 0x00, 0x00, 0x10, 0x00, \ 71 - 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 72 - #define UVC_GUID_FORMAT_YUY2_ISIGHT \ 73 - { 'Y', 'U', 'Y', '2', 0x00, 0x00, 0x10, 0x00, \ 74 - 0x80, 0x00, 0x00, 0x00, 0x00, 0x38, 0x9b, 0x71} 75 - #define UVC_GUID_FORMAT_NV12 \ 76 - { 'N', 'V', '1', '2', 0x00, 0x00, 0x10, 0x00, \ 77 - 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 78 - #define UVC_GUID_FORMAT_YV12 \ 79 - { 'Y', 'V', '1', '2', 0x00, 0x00, 0x10, 0x00, \ 80 - 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 81 - #define UVC_GUID_FORMAT_I420 \ 82 - { 'I', '4', '2', '0', 0x00, 0x00, 0x10, 0x00, \ 83 - 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 84 - #define UVC_GUID_FORMAT_UYVY \ 85 - { 'U', 'Y', 'V', 'Y', 0x00, 0x00, 0x10, 0x00, \ 86 - 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 87 - #define UVC_GUID_FORMAT_Y800 \ 88 - { 'Y', '8', '0', '0', 0x00, 0x00, 0x10, 0x00, \ 89 - 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 90 - #define UVC_GUID_FORMAT_Y8 \ 91 - { 'Y', '8', ' ', ' ', 0x00, 0x00, 0x10, 0x00, \ 92 - 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 93 - #define UVC_GUID_FORMAT_Y10 \ 94 - { 'Y', '1', '0', ' ', 0x00, 0x00, 0x10, 0x00, \ 95 - 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 96 - #define UVC_GUID_FORMAT_Y12 \ 97 - { 'Y', '1', '2', ' ', 0x00, 0x00, 0x10, 0x00, \ 98 - 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 99 - #define UVC_GUID_FORMAT_Y16 \ 100 - { 'Y', '1', '6', ' ', 0x00, 0x00, 0x10, 0x00, \ 101 - 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 102 - #define UVC_GUID_FORMAT_BY8 \ 103 - { 'B', 'Y', '8', ' ', 0x00, 0x00, 0x10, 0x00, \ 104 - 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 105 - #define UVC_GUID_FORMAT_BA81 \ 106 - { 'B', 'A', '8', '1', 0x00, 0x00, 0x10, 0x00, \ 107 - 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 108 - #define UVC_GUID_FORMAT_GBRG \ 109 - { 'G', 'B', 'R', 'G', 0x00, 0x00, 0x10, 0x00, \ 110 - 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 111 - #define UVC_GUID_FORMAT_GRBG \ 112 - { 'G', 'R', 'B', 'G', 0x00, 0x00, 0x10, 0x00, \ 113 - 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 114 - #define UVC_GUID_FORMAT_RGGB \ 115 - { 'R', 'G', 'G', 'B', 0x00, 0x00, 0x10, 0x00, \ 116 - 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 117 - #define UVC_GUID_FORMAT_BG16 \ 118 - { 'B', 'G', '1', '6', 0x00, 0x00, 0x10, 0x00, \ 119 - 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 120 - #define UVC_GUID_FORMAT_GB16 \ 121 - { 'G', 'B', '1', '6', 0x00, 0x00, 0x10, 0x00, \ 122 - 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 123 - #define UVC_GUID_FORMAT_RG16 \ 124 - { 'R', 'G', '1', '6', 0x00, 0x00, 0x10, 0x00, \ 125 - 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 126 - #define UVC_GUID_FORMAT_GR16 \ 127 - { 'G', 'R', '1', '6', 0x00, 0x00, 0x10, 0x00, \ 128 - 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 129 - #define UVC_GUID_FORMAT_RGBP \ 130 - { 'R', 'G', 'B', 'P', 0x00, 0x00, 0x10, 0x00, \ 131 - 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 132 - #define UVC_GUID_FORMAT_BGR3 \ 133 - { 0x7d, 0xeb, 0x36, 0xe4, 0x4f, 0x52, 0xce, 0x11, \ 134 - 0x9f, 0x53, 0x00, 0x20, 0xaf, 0x0b, 0xa7, 0x70} 135 - #define UVC_GUID_FORMAT_M420 \ 136 - { 'M', '4', '2', '0', 0x00, 0x00, 0x10, 0x00, \ 137 - 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 138 - 139 - #define UVC_GUID_FORMAT_H264 \ 140 - { 'H', '2', '6', '4', 0x00, 0x00, 0x10, 0x00, \ 141 - 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 142 - #define UVC_GUID_FORMAT_H265 \ 143 - { 'H', '2', '6', '5', 0x00, 0x00, 0x10, 0x00, \ 144 - 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 145 - #define UVC_GUID_FORMAT_Y8I \ 146 - { 'Y', '8', 'I', ' ', 0x00, 0x00, 0x10, 0x00, \ 147 - 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 148 - #define UVC_GUID_FORMAT_Y12I \ 149 - { 'Y', '1', '2', 'I', 0x00, 0x00, 0x10, 0x00, \ 150 - 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 151 - #define UVC_GUID_FORMAT_Z16 \ 152 - { 'Z', '1', '6', ' ', 0x00, 0x00, 0x10, 0x00, \ 153 - 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 154 - #define UVC_GUID_FORMAT_RW10 \ 155 - { 'R', 'W', '1', '0', 0x00, 0x00, 0x10, 0x00, \ 156 - 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 157 - #define UVC_GUID_FORMAT_INVZ \ 158 - { 'I', 'N', 'V', 'Z', 0x90, 0x2d, 0x58, 0x4a, \ 159 - 0x92, 0x0b, 0x77, 0x3f, 0x1f, 0x2c, 0x55, 0x6b} 160 - #define UVC_GUID_FORMAT_INZI \ 161 - { 'I', 'N', 'Z', 'I', 0x66, 0x1a, 0x42, 0xa2, \ 162 - 0x90, 0x65, 0xd0, 0x18, 0x14, 0xa8, 0xef, 0x8a} 163 - #define UVC_GUID_FORMAT_INVI \ 164 - { 'I', 'N', 'V', 'I', 0xdb, 0x57, 0x49, 0x5e, \ 165 - 0x8e, 0x3f, 0xf4, 0x79, 0x53, 0x2b, 0x94, 0x6f} 166 - #define UVC_GUID_FORMAT_CNF4 \ 167 - { 'C', ' ', ' ', ' ', 0x00, 0x00, 0x10, 0x00, \ 168 - 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 169 - 170 - #define UVC_GUID_FORMAT_D3DFMT_L8 \ 171 - {0x32, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, \ 172 - 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 173 - #define UVC_GUID_FORMAT_KSMEDIA_L8_IR \ 174 - {0x32, 0x00, 0x00, 0x00, 0x02, 0x00, 0x10, 0x00, \ 175 - 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 176 - 177 - #define UVC_GUID_FORMAT_HEVC \ 178 - { 'H', 'E', 'V', 'C', 0x00, 0x00, 0x10, 0x00, \ 179 - 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 180 - 181 - 182 - /* ------------------------------------------------------------------------ 183 45 * Driver specific constants. 184 46 */ 185 47 ··· 143 281 u8 *uvc_data; 144 282 145 283 struct uvc_fh *handle; /* File handle that last changed the control. */ 146 - }; 147 - 148 - struct uvc_format_desc { 149 - char *name; 150 - u8 guid[16]; 151 - u32 fcc; 152 284 }; 153 285 154 286 /* ··· 767 911 struct uvc_xu_control_query *xqry); 768 912 769 913 /* Utility functions */ 770 - void uvc_simplify_fraction(u32 *numerator, u32 *denominator, 771 - unsigned int n_terms, unsigned int threshold); 772 - u32 uvc_fraction_to_interval(u32 numerator, u32 denominator); 773 914 struct usb_host_endpoint *uvc_find_endpoint(struct usb_host_interface *alts, 774 915 u8 epaddr); 775 916 u16 uvc_endpoint_max_bpi(struct usb_device *dev, struct usb_host_endpoint *ep);
+86
drivers/media/v4l2-core/v4l2-common.c
··· 484 484 return freq > 0 ? freq : -EINVAL; 485 485 } 486 486 EXPORT_SYMBOL_GPL(v4l2_get_link_freq); 487 + 488 + /* 489 + * Simplify a fraction using a simple continued fraction decomposition. The 490 + * idea here is to convert fractions such as 333333/10000000 to 1/30 using 491 + * 32 bit arithmetic only. The algorithm is not perfect and relies upon two 492 + * arbitrary parameters to remove non-significative terms from the simple 493 + * continued fraction decomposition. Using 8 and 333 for n_terms and threshold 494 + * respectively seems to give nice results. 495 + */ 496 + void v4l2_simplify_fraction(u32 *numerator, u32 *denominator, 497 + unsigned int n_terms, unsigned int threshold) 498 + { 499 + u32 *an; 500 + u32 x, y, r; 501 + unsigned int i, n; 502 + 503 + an = kmalloc_array(n_terms, sizeof(*an), GFP_KERNEL); 504 + if (an == NULL) 505 + return; 506 + 507 + /* 508 + * Convert the fraction to a simple continued fraction. See 509 + * https://en.wikipedia.org/wiki/Continued_fraction 510 + * Stop if the current term is bigger than or equal to the given 511 + * threshold. 512 + */ 513 + x = *numerator; 514 + y = *denominator; 515 + 516 + for (n = 0; n < n_terms && y != 0; ++n) { 517 + an[n] = x / y; 518 + if (an[n] >= threshold) { 519 + if (n < 2) 520 + n++; 521 + break; 522 + } 523 + 524 + r = x - an[n] * y; 525 + x = y; 526 + y = r; 527 + } 528 + 529 + /* Expand the simple continued fraction back to an integer fraction. */ 530 + x = 0; 531 + y = 1; 532 + 533 + for (i = n; i > 0; --i) { 534 + r = y; 535 + y = an[i-1] * y + x; 536 + x = r; 537 + } 538 + 539 + *numerator = y; 540 + *denominator = x; 541 + kfree(an); 542 + } 543 + EXPORT_SYMBOL_GPL(v4l2_simplify_fraction); 544 + 545 + /* 546 + * Convert a fraction to a frame interval in 100ns multiples. The idea here is 547 + * to compute numerator / denominator * 10000000 using 32 bit fixed point 548 + * arithmetic only. 549 + */ 550 + u32 v4l2_fraction_to_interval(u32 numerator, u32 denominator) 551 + { 552 + u32 multiplier; 553 + 554 + /* Saturate the result if the operation would overflow. */ 555 + if (denominator == 0 || 556 + numerator/denominator >= ((u32)-1)/10000000) 557 + return (u32)-1; 558 + 559 + /* 560 + * Divide both the denominator and the multiplier by two until 561 + * numerator * multiplier doesn't overflow. If anyone knows a better 562 + * algorithm please let me know. 563 + */ 564 + multiplier = 10000000; 565 + while (numerator > ((u32)-1)/multiplier) { 566 + multiplier /= 2; 567 + denominator /= 2; 568 + } 569 + 570 + return denominator ? numerator * multiplier / denominator : 0; 571 + } 572 + EXPORT_SYMBOL_GPL(v4l2_fraction_to_interval);
+12 -7
drivers/phy/tegra/xusb-tegra186.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 /* 3 - * Copyright (c) 2016-2020, NVIDIA CORPORATION. All rights reserved. 3 + * Copyright (c) 2016-2022, NVIDIA CORPORATION. All rights reserved. 4 4 */ 5 5 6 6 #include <linux/delay.h> ··· 638 638 mutex_unlock(&padctl->lock); 639 639 } 640 640 641 - static void tegra_phy_xusb_utmi_pad_power_on(struct phy *phy) 641 + static void tegra186_utmi_pad_power_on(struct phy *phy) 642 642 { 643 643 struct tegra_xusb_lane *lane = phy_get_drvdata(phy); 644 644 struct tegra_xusb_padctl *padctl = lane->pad->padctl; ··· 656 656 return; 657 657 } 658 658 659 + dev_dbg(dev, "power on UTMI pad %u\n", index); 660 + 659 661 tegra186_utmi_bias_pad_power_on(padctl); 660 662 661 663 udelay(2); ··· 671 669 padctl_writel(padctl, value, XUSB_PADCTL_USB2_OTG_PADX_CTL1(index)); 672 670 } 673 671 674 - static void tegra_phy_xusb_utmi_pad_power_down(struct phy *phy) 672 + static void tegra186_utmi_pad_power_down(struct phy *phy) 675 673 { 676 674 struct tegra_xusb_lane *lane = phy_get_drvdata(phy); 677 675 struct tegra_xusb_padctl *padctl = lane->pad->padctl; ··· 680 678 681 679 if (!phy) 682 680 return; 681 + 682 + dev_dbg(padctl->dev, "power down UTMI pad %u\n", index); 683 683 684 684 value = padctl_readl(padctl, XUSB_PADCTL_USB2_OTG_PADX_CTL0(index)); 685 685 value |= USB2_OTG_PD; ··· 853 849 value |= RPD_CTRL(priv->calib.rpd_ctrl); 854 850 padctl_writel(padctl, value, XUSB_PADCTL_USB2_OTG_PADX_CTL1(index)); 855 851 856 - /* TODO: pad power saving */ 857 - tegra_phy_xusb_utmi_pad_power_on(phy); 852 + tegra186_utmi_pad_power_on(phy); 853 + 858 854 return 0; 859 855 } 860 856 861 857 static int tegra186_utmi_phy_power_off(struct phy *phy) 862 858 { 863 - /* TODO: pad power saving */ 864 - tegra_phy_xusb_utmi_pad_power_down(phy); 859 + tegra186_utmi_pad_power_down(phy); 865 860 866 861 return 0; 867 862 } ··· 1486 1483 .suspend_noirq = tegra186_xusb_padctl_suspend_noirq, 1487 1484 .resume_noirq = tegra186_xusb_padctl_resume_noirq, 1488 1485 .vbus_override = tegra186_xusb_padctl_vbus_override, 1486 + .utmi_pad_power_on = tegra186_utmi_pad_power_on, 1487 + .utmi_pad_power_down = tegra186_utmi_pad_power_down, 1489 1488 }; 1490 1489 1491 1490 #if IS_ENABLED(CONFIG_ARCH_TEGRA_186_SOC)
+21 -1
drivers/phy/tegra/xusb.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0-only 2 2 /* 3 - * Copyright (c) 2014-2020, NVIDIA CORPORATION. All rights reserved. 3 + * Copyright (c) 2014-2022, NVIDIA CORPORATION. All rights reserved. 4 4 */ 5 5 6 6 #include <linux/delay.h> ··· 1458 1458 return -ENOTSUPP; 1459 1459 } 1460 1460 EXPORT_SYMBOL_GPL(tegra_phy_xusb_utmi_port_reset); 1461 + 1462 + void tegra_phy_xusb_utmi_pad_power_on(struct phy *phy) 1463 + { 1464 + struct tegra_xusb_lane *lane = phy_get_drvdata(phy); 1465 + struct tegra_xusb_padctl *padctl = lane->pad->padctl; 1466 + 1467 + if (padctl->soc->ops->utmi_pad_power_on) 1468 + padctl->soc->ops->utmi_pad_power_on(phy); 1469 + } 1470 + EXPORT_SYMBOL_GPL(tegra_phy_xusb_utmi_pad_power_on); 1471 + 1472 + void tegra_phy_xusb_utmi_pad_power_down(struct phy *phy) 1473 + { 1474 + struct tegra_xusb_lane *lane = phy_get_drvdata(phy); 1475 + struct tegra_xusb_padctl *padctl = lane->pad->padctl; 1476 + 1477 + if (padctl->soc->ops->utmi_pad_power_down) 1478 + padctl->soc->ops->utmi_pad_power_down(phy); 1479 + } 1480 + EXPORT_SYMBOL_GPL(tegra_phy_xusb_utmi_pad_power_down); 1461 1481 1462 1482 int tegra_xusb_padctl_get_usb3_companion(struct tegra_xusb_padctl *padctl, 1463 1483 unsigned int port)
+3 -1
drivers/phy/tegra/xusb.h
··· 1 1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 2 /* 3 - * Copyright (c) 2014-2020, NVIDIA CORPORATION. All rights reserved. 3 + * Copyright (c) 2014-2022, NVIDIA CORPORATION. All rights reserved. 4 4 * Copyright (c) 2015, Google Inc. 5 5 */ 6 6 ··· 412 412 unsigned int index, bool enable); 413 413 int (*vbus_override)(struct tegra_xusb_padctl *padctl, bool set); 414 414 int (*utmi_port_reset)(struct phy *phy); 415 + void (*utmi_pad_power_on)(struct phy *phy); 416 + void (*utmi_pad_power_down)(struct phy *phy); 415 417 }; 416 418 417 419 struct tegra_xusb_padctl_soc {
+10
drivers/thunderbolt/Kconfig
··· 27 27 Only enable this if you know what you are doing! Never enable 28 28 this for production systems or distro kernels. 29 29 30 + config USB4_DEBUGFS_MARGINING 31 + bool "Expose receiver lane margining operations under USB4 ports (DANGEROUS)" 32 + depends on DEBUG_FS 33 + depends on USB4_DEBUGFS_WRITE 34 + 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 + 30 40 config USB4_KUNIT_TEST 31 41 bool "KUnit tests" if !KUNIT_ALL_TESTS 32 42 depends on USB4 && KUNIT=y
+836
drivers/thunderbolt/debugfs.c
··· 12 12 #include <linux/uaccess.h> 13 13 14 14 #include "tb.h" 15 + #include "sb_regs.h" 15 16 16 17 #define PORT_CAP_PCIE_LEN 1 17 18 #define PORT_CAP_POWER_LEN 2 ··· 186 185 #define port_regs_write NULL 187 186 #define switch_regs_write NULL 188 187 #define DEBUGFS_MODE 0400 188 + #endif 189 + 190 + #if IS_ENABLED(CONFIG_USB4_DEBUGFS_MARGINING) 191 + /** 192 + * struct tb_margining - Lane margining support 193 + * @caps: Port lane margining capabilities 194 + * @results: Last lane margining results 195 + * @lanes: %0, %1 or %7 (all) 196 + * @min_ber_level: Minimum supported BER level contour value 197 + * @max_ber_level: Maximum supported BER level contour value 198 + * @ber_level: Current BER level contour value 199 + * @voltage_steps: Number of mandatory voltage steps 200 + * @max_voltage_offset: Maximum mandatory voltage offset (in mV) 201 + * @time_steps: Number of time margin steps 202 + * @max_time_offset: Maximum time margin offset (in mUI) 203 + * @software: %true if software margining is used instead of hardware 204 + * @time: %true if time margining is used instead of voltage 205 + * @right_high: %false if left/low margin test is performed, %true if 206 + * right/high 207 + */ 208 + struct tb_margining { 209 + u32 caps[2]; 210 + u32 results[2]; 211 + unsigned int lanes; 212 + unsigned int min_ber_level; 213 + unsigned int max_ber_level; 214 + unsigned int ber_level; 215 + unsigned int voltage_steps; 216 + unsigned int max_voltage_offset; 217 + unsigned int time_steps; 218 + unsigned int max_time_offset; 219 + bool software; 220 + bool time; 221 + bool right_high; 222 + }; 223 + 224 + static bool supports_software(const struct usb4_port *usb4) 225 + { 226 + return usb4->margining->caps[0] & USB4_MARGIN_CAP_0_MODES_SW; 227 + } 228 + 229 + static bool supports_hardware(const struct usb4_port *usb4) 230 + { 231 + return usb4->margining->caps[0] & USB4_MARGIN_CAP_0_MODES_HW; 232 + } 233 + 234 + static bool both_lanes(const struct usb4_port *usb4) 235 + { 236 + return usb4->margining->caps[0] & USB4_MARGIN_CAP_0_2_LANES; 237 + } 238 + 239 + static unsigned int independent_voltage_margins(const struct usb4_port *usb4) 240 + { 241 + return (usb4->margining->caps[0] & USB4_MARGIN_CAP_0_VOLTAGE_INDP_MASK) >> 242 + USB4_MARGIN_CAP_0_VOLTAGE_INDP_SHIFT; 243 + } 244 + 245 + static bool supports_time(const struct usb4_port *usb4) 246 + { 247 + return usb4->margining->caps[0] & USB4_MARGIN_CAP_0_TIME; 248 + } 249 + 250 + /* Only applicable if supports_time() returns true */ 251 + static unsigned int independent_time_margins(const struct usb4_port *usb4) 252 + { 253 + return (usb4->margining->caps[1] & USB4_MARGIN_CAP_1_TIME_INDP_MASK) >> 254 + USB4_MARGIN_CAP_1_TIME_INDP_SHIFT; 255 + } 256 + 257 + static ssize_t 258 + margining_ber_level_write(struct file *file, const char __user *user_buf, 259 + size_t count, loff_t *ppos) 260 + { 261 + struct seq_file *s = file->private_data; 262 + struct tb_port *port = s->private; 263 + struct usb4_port *usb4 = port->usb4; 264 + struct tb *tb = port->sw->tb; 265 + unsigned int val; 266 + int ret = 0; 267 + char *buf; 268 + 269 + if (mutex_lock_interruptible(&tb->lock)) 270 + return -ERESTARTSYS; 271 + 272 + if (usb4->margining->software) { 273 + ret = -EINVAL; 274 + goto out_unlock; 275 + } 276 + 277 + buf = validate_and_copy_from_user(user_buf, &count); 278 + if (IS_ERR(buf)) { 279 + ret = PTR_ERR(buf); 280 + goto out_unlock; 281 + } 282 + 283 + buf[count - 1] = '\0'; 284 + 285 + ret = kstrtouint(buf, 10, &val); 286 + if (ret) 287 + goto out_free; 288 + 289 + if (val < usb4->margining->min_ber_level || 290 + val > usb4->margining->max_ber_level) { 291 + ret = -EINVAL; 292 + goto out_free; 293 + } 294 + 295 + usb4->margining->ber_level = val; 296 + 297 + out_free: 298 + free_page((unsigned long)buf); 299 + out_unlock: 300 + mutex_unlock(&tb->lock); 301 + 302 + return ret < 0 ? ret : count; 303 + } 304 + 305 + static void ber_level_show(struct seq_file *s, unsigned int val) 306 + { 307 + if (val % 2) 308 + seq_printf(s, "3 * 1e%d (%u)\n", -12 + (val + 1) / 2, val); 309 + else 310 + seq_printf(s, "1e%d (%u)\n", -12 + val / 2, val); 311 + } 312 + 313 + static int margining_ber_level_show(struct seq_file *s, void *not_used) 314 + { 315 + struct tb_port *port = s->private; 316 + struct usb4_port *usb4 = port->usb4; 317 + 318 + if (usb4->margining->software) 319 + return -EINVAL; 320 + ber_level_show(s, usb4->margining->ber_level); 321 + return 0; 322 + } 323 + DEBUGFS_ATTR_RW(margining_ber_level); 324 + 325 + static int margining_caps_show(struct seq_file *s, void *not_used) 326 + { 327 + struct tb_port *port = s->private; 328 + struct usb4_port *usb4 = port->usb4; 329 + struct tb *tb = port->sw->tb; 330 + u32 cap0, cap1; 331 + 332 + if (mutex_lock_interruptible(&tb->lock)) 333 + return -ERESTARTSYS; 334 + 335 + /* Dump the raw caps first */ 336 + cap0 = usb4->margining->caps[0]; 337 + seq_printf(s, "0x%08x\n", cap0); 338 + cap1 = usb4->margining->caps[1]; 339 + seq_printf(s, "0x%08x\n", cap1); 340 + 341 + seq_printf(s, "# software margining: %s\n", 342 + supports_software(usb4) ? "yes" : "no"); 343 + if (supports_hardware(usb4)) { 344 + seq_puts(s, "# hardware margining: yes\n"); 345 + seq_puts(s, "# minimum BER level contour: "); 346 + ber_level_show(s, usb4->margining->min_ber_level); 347 + seq_puts(s, "# maximum BER level contour: "); 348 + ber_level_show(s, usb4->margining->max_ber_level); 349 + } else { 350 + seq_puts(s, "# hardware margining: no\n"); 351 + } 352 + 353 + seq_printf(s, "# both lanes simultaneously: %s\n", 354 + both_lanes(usb4) ? "yes" : "no"); 355 + seq_printf(s, "# voltage margin steps: %u\n", 356 + usb4->margining->voltage_steps); 357 + seq_printf(s, "# maximum voltage offset: %u mV\n", 358 + usb4->margining->max_voltage_offset); 359 + 360 + switch (independent_voltage_margins(usb4)) { 361 + case USB4_MARGIN_CAP_0_VOLTAGE_MIN: 362 + seq_puts(s, "# returns minimum between high and low voltage margins\n"); 363 + break; 364 + case USB4_MARGIN_CAP_0_VOLTAGE_HL: 365 + seq_puts(s, "# returns high or low voltage margin\n"); 366 + break; 367 + case USB4_MARGIN_CAP_0_VOLTAGE_BOTH: 368 + seq_puts(s, "# returns both high and low margins\n"); 369 + break; 370 + } 371 + 372 + if (supports_time(usb4)) { 373 + seq_puts(s, "# time margining: yes\n"); 374 + seq_printf(s, "# time margining is destructive: %s\n", 375 + cap1 & USB4_MARGIN_CAP_1_TIME_DESTR ? "yes" : "no"); 376 + 377 + switch (independent_time_margins(usb4)) { 378 + case USB4_MARGIN_CAP_1_TIME_MIN: 379 + seq_puts(s, "# returns minimum between left and right time margins\n"); 380 + break; 381 + case USB4_MARGIN_CAP_1_TIME_LR: 382 + seq_puts(s, "# returns left or right margin\n"); 383 + break; 384 + case USB4_MARGIN_CAP_1_TIME_BOTH: 385 + seq_puts(s, "# returns both left and right margins\n"); 386 + break; 387 + } 388 + 389 + seq_printf(s, "# time margin steps: %u\n", 390 + usb4->margining->time_steps); 391 + seq_printf(s, "# maximum time offset: %u mUI\n", 392 + usb4->margining->max_time_offset); 393 + } else { 394 + seq_puts(s, "# time margining: no\n"); 395 + } 396 + 397 + mutex_unlock(&tb->lock); 398 + return 0; 399 + } 400 + DEBUGFS_ATTR_RO(margining_caps); 401 + 402 + static ssize_t 403 + margining_lanes_write(struct file *file, const char __user *user_buf, 404 + size_t count, loff_t *ppos) 405 + { 406 + struct seq_file *s = file->private_data; 407 + struct tb_port *port = s->private; 408 + struct usb4_port *usb4 = port->usb4; 409 + struct tb *tb = port->sw->tb; 410 + int ret = 0; 411 + char *buf; 412 + 413 + buf = validate_and_copy_from_user(user_buf, &count); 414 + if (IS_ERR(buf)) 415 + return PTR_ERR(buf); 416 + 417 + buf[count - 1] = '\0'; 418 + 419 + if (mutex_lock_interruptible(&tb->lock)) { 420 + ret = -ERESTARTSYS; 421 + goto out_free; 422 + } 423 + 424 + if (!strcmp(buf, "0")) { 425 + usb4->margining->lanes = 0; 426 + } else if (!strcmp(buf, "1")) { 427 + usb4->margining->lanes = 1; 428 + } else if (!strcmp(buf, "all")) { 429 + /* Needs to be supported */ 430 + if (both_lanes(usb4)) 431 + usb4->margining->lanes = 7; 432 + else 433 + ret = -EINVAL; 434 + } else { 435 + ret = -EINVAL; 436 + } 437 + 438 + mutex_unlock(&tb->lock); 439 + 440 + out_free: 441 + free_page((unsigned long)buf); 442 + return ret < 0 ? ret : count; 443 + } 444 + 445 + static int margining_lanes_show(struct seq_file *s, void *not_used) 446 + { 447 + struct tb_port *port = s->private; 448 + struct usb4_port *usb4 = port->usb4; 449 + struct tb *tb = port->sw->tb; 450 + unsigned int lanes; 451 + 452 + if (mutex_lock_interruptible(&tb->lock)) 453 + return -ERESTARTSYS; 454 + 455 + lanes = usb4->margining->lanes; 456 + if (both_lanes(usb4)) { 457 + if (!lanes) 458 + seq_puts(s, "[0] 1 all\n"); 459 + else if (lanes == 1) 460 + seq_puts(s, "0 [1] all\n"); 461 + else 462 + seq_puts(s, "0 1 [all]\n"); 463 + } else { 464 + if (!lanes) 465 + seq_puts(s, "[0] 1\n"); 466 + else 467 + seq_puts(s, "0 [1]\n"); 468 + } 469 + 470 + mutex_unlock(&tb->lock); 471 + return 0; 472 + } 473 + DEBUGFS_ATTR_RW(margining_lanes); 474 + 475 + static ssize_t margining_mode_write(struct file *file, 476 + const char __user *user_buf, 477 + size_t count, loff_t *ppos) 478 + { 479 + struct seq_file *s = file->private_data; 480 + struct tb_port *port = s->private; 481 + struct usb4_port *usb4 = port->usb4; 482 + struct tb *tb = port->sw->tb; 483 + int ret = 0; 484 + char *buf; 485 + 486 + buf = validate_and_copy_from_user(user_buf, &count); 487 + if (IS_ERR(buf)) 488 + return PTR_ERR(buf); 489 + 490 + buf[count - 1] = '\0'; 491 + 492 + if (mutex_lock_interruptible(&tb->lock)) { 493 + ret = -ERESTARTSYS; 494 + goto out_free; 495 + } 496 + 497 + if (!strcmp(buf, "software")) { 498 + if (supports_software(usb4)) 499 + usb4->margining->software = true; 500 + else 501 + ret = -EINVAL; 502 + } else if (!strcmp(buf, "hardware")) { 503 + if (supports_hardware(usb4)) 504 + usb4->margining->software = false; 505 + else 506 + ret = -EINVAL; 507 + } else { 508 + ret = -EINVAL; 509 + } 510 + 511 + mutex_unlock(&tb->lock); 512 + 513 + out_free: 514 + free_page((unsigned long)buf); 515 + return ret ? ret : count; 516 + } 517 + 518 + static int margining_mode_show(struct seq_file *s, void *not_used) 519 + { 520 + const struct tb_port *port = s->private; 521 + const struct usb4_port *usb4 = port->usb4; 522 + struct tb *tb = port->sw->tb; 523 + const char *space = ""; 524 + 525 + if (mutex_lock_interruptible(&tb->lock)) 526 + return -ERESTARTSYS; 527 + 528 + if (supports_software(usb4)) { 529 + if (usb4->margining->software) 530 + seq_puts(s, "[software]"); 531 + else 532 + seq_puts(s, "software"); 533 + space = " "; 534 + } 535 + if (supports_hardware(usb4)) { 536 + if (usb4->margining->software) 537 + seq_printf(s, "%shardware", space); 538 + else 539 + seq_printf(s, "%s[hardware]", space); 540 + } 541 + 542 + mutex_unlock(&tb->lock); 543 + 544 + seq_puts(s, "\n"); 545 + return 0; 546 + } 547 + DEBUGFS_ATTR_RW(margining_mode); 548 + 549 + static int margining_run_write(void *data, u64 val) 550 + { 551 + struct tb_port *port = data; 552 + struct usb4_port *usb4 = port->usb4; 553 + struct tb_switch *sw = port->sw; 554 + struct tb_margining *margining; 555 + struct tb *tb = sw->tb; 556 + int ret; 557 + 558 + if (val != 1) 559 + return -EINVAL; 560 + 561 + pm_runtime_get_sync(&sw->dev); 562 + 563 + if (mutex_lock_interruptible(&tb->lock)) { 564 + ret = -ERESTARTSYS; 565 + goto out_rpm_put; 566 + } 567 + 568 + /* 569 + * CL states may interfere with lane margining so inform the user know 570 + * and bail out. 571 + */ 572 + if (tb_port_is_clx_enabled(port, TB_CL1 | TB_CL2)) { 573 + tb_port_warn(port, 574 + "CL states are enabled, Disable them with clx=0 and re-connect\n"); 575 + ret = -EINVAL; 576 + goto out_unlock; 577 + } 578 + 579 + margining = usb4->margining; 580 + 581 + if (margining->software) { 582 + tb_port_dbg(port, "running software %s lane margining for lanes %u\n", 583 + margining->time ? "time" : "voltage", margining->lanes); 584 + ret = usb4_port_sw_margin(port, margining->lanes, margining->time, 585 + margining->right_high, 586 + USB4_MARGIN_SW_COUNTER_CLEAR); 587 + if (ret) 588 + goto out_unlock; 589 + 590 + ret = usb4_port_sw_margin_errors(port, &margining->results[0]); 591 + } else { 592 + tb_port_dbg(port, "running hardware %s lane margining for lanes %u\n", 593 + margining->time ? "time" : "voltage", margining->lanes); 594 + /* Clear the results */ 595 + margining->results[0] = 0; 596 + margining->results[1] = 0; 597 + ret = usb4_port_hw_margin(port, margining->lanes, 598 + margining->ber_level, margining->time, 599 + margining->right_high, margining->results); 600 + } 601 + 602 + out_unlock: 603 + mutex_unlock(&tb->lock); 604 + out_rpm_put: 605 + pm_runtime_mark_last_busy(&sw->dev); 606 + pm_runtime_put_autosuspend(&sw->dev); 607 + 608 + return ret; 609 + } 610 + DEFINE_DEBUGFS_ATTRIBUTE(margining_run_fops, NULL, margining_run_write, 611 + "%llu\n"); 612 + 613 + static ssize_t margining_results_write(struct file *file, 614 + const char __user *user_buf, 615 + size_t count, loff_t *ppos) 616 + { 617 + struct seq_file *s = file->private_data; 618 + struct tb_port *port = s->private; 619 + struct usb4_port *usb4 = port->usb4; 620 + struct tb *tb = port->sw->tb; 621 + 622 + if (mutex_lock_interruptible(&tb->lock)) 623 + return -ERESTARTSYS; 624 + 625 + /* Just clear the results */ 626 + usb4->margining->results[0] = 0; 627 + usb4->margining->results[1] = 0; 628 + 629 + mutex_unlock(&tb->lock); 630 + return count; 631 + } 632 + 633 + static void voltage_margin_show(struct seq_file *s, 634 + const struct tb_margining *margining, u8 val) 635 + { 636 + unsigned int tmp, voltage; 637 + 638 + tmp = val & USB4_MARGIN_HW_RES_1_MARGIN_MASK; 639 + voltage = tmp * margining->max_voltage_offset / margining->voltage_steps; 640 + seq_printf(s, "%u mV (%u)", voltage, tmp); 641 + if (val & USB4_MARGIN_HW_RES_1_EXCEEDS) 642 + seq_puts(s, " exceeds maximum"); 643 + seq_puts(s, "\n"); 644 + } 645 + 646 + static void time_margin_show(struct seq_file *s, 647 + const struct tb_margining *margining, u8 val) 648 + { 649 + unsigned int tmp, interval; 650 + 651 + tmp = val & USB4_MARGIN_HW_RES_1_MARGIN_MASK; 652 + interval = tmp * margining->max_time_offset / margining->time_steps; 653 + seq_printf(s, "%u mUI (%u)", interval, tmp); 654 + if (val & USB4_MARGIN_HW_RES_1_EXCEEDS) 655 + seq_puts(s, " exceeds maximum"); 656 + seq_puts(s, "\n"); 657 + } 658 + 659 + static int margining_results_show(struct seq_file *s, void *not_used) 660 + { 661 + struct tb_port *port = s->private; 662 + struct usb4_port *usb4 = port->usb4; 663 + struct tb_margining *margining; 664 + struct tb *tb = port->sw->tb; 665 + 666 + if (mutex_lock_interruptible(&tb->lock)) 667 + return -ERESTARTSYS; 668 + 669 + margining = usb4->margining; 670 + /* Dump the raw results first */ 671 + seq_printf(s, "0x%08x\n", margining->results[0]); 672 + /* Only the hardware margining has two result dwords */ 673 + if (!margining->software) { 674 + unsigned int val; 675 + 676 + seq_printf(s, "0x%08x\n", margining->results[1]); 677 + 678 + if (margining->time) { 679 + if (!margining->lanes || margining->lanes == 7) { 680 + val = margining->results[1]; 681 + seq_puts(s, "# lane 0 right time margin: "); 682 + time_margin_show(s, margining, val); 683 + val = margining->results[1] >> 684 + USB4_MARGIN_HW_RES_1_L0_LL_MARGIN_SHIFT; 685 + seq_puts(s, "# lane 0 left time margin: "); 686 + time_margin_show(s, margining, val); 687 + } 688 + if (margining->lanes == 1 || margining->lanes == 7) { 689 + val = margining->results[1] >> 690 + USB4_MARGIN_HW_RES_1_L1_RH_MARGIN_SHIFT; 691 + seq_puts(s, "# lane 1 right time margin: "); 692 + time_margin_show(s, margining, val); 693 + val = margining->results[1] >> 694 + USB4_MARGIN_HW_RES_1_L1_LL_MARGIN_SHIFT; 695 + seq_puts(s, "# lane 1 left time margin: "); 696 + time_margin_show(s, margining, val); 697 + } 698 + } else { 699 + if (!margining->lanes || margining->lanes == 7) { 700 + val = margining->results[1]; 701 + seq_puts(s, "# lane 0 high voltage margin: "); 702 + voltage_margin_show(s, margining, val); 703 + val = margining->results[1] >> 704 + USB4_MARGIN_HW_RES_1_L0_LL_MARGIN_SHIFT; 705 + seq_puts(s, "# lane 0 low voltage margin: "); 706 + voltage_margin_show(s, margining, val); 707 + } 708 + if (margining->lanes == 1 || margining->lanes == 7) { 709 + val = margining->results[1] >> 710 + USB4_MARGIN_HW_RES_1_L1_RH_MARGIN_SHIFT; 711 + seq_puts(s, "# lane 1 high voltage margin: "); 712 + voltage_margin_show(s, margining, val); 713 + val = margining->results[1] >> 714 + USB4_MARGIN_HW_RES_1_L1_LL_MARGIN_SHIFT; 715 + seq_puts(s, "# lane 1 low voltage margin: "); 716 + voltage_margin_show(s, margining, val); 717 + } 718 + } 719 + } 720 + 721 + mutex_unlock(&tb->lock); 722 + return 0; 723 + } 724 + DEBUGFS_ATTR_RW(margining_results); 725 + 726 + static ssize_t margining_test_write(struct file *file, 727 + const char __user *user_buf, 728 + size_t count, loff_t *ppos) 729 + { 730 + struct seq_file *s = file->private_data; 731 + struct tb_port *port = s->private; 732 + struct usb4_port *usb4 = port->usb4; 733 + struct tb *tb = port->sw->tb; 734 + int ret = 0; 735 + char *buf; 736 + 737 + buf = validate_and_copy_from_user(user_buf, &count); 738 + if (IS_ERR(buf)) 739 + return PTR_ERR(buf); 740 + 741 + buf[count - 1] = '\0'; 742 + 743 + if (mutex_lock_interruptible(&tb->lock)) { 744 + ret = -ERESTARTSYS; 745 + goto out_free; 746 + } 747 + 748 + if (!strcmp(buf, "time") && supports_time(usb4)) 749 + usb4->margining->time = true; 750 + else if (!strcmp(buf, "voltage")) 751 + usb4->margining->time = false; 752 + else 753 + ret = -EINVAL; 754 + 755 + mutex_unlock(&tb->lock); 756 + 757 + out_free: 758 + free_page((unsigned long)buf); 759 + return ret ? ret : count; 760 + } 761 + 762 + static int margining_test_show(struct seq_file *s, void *not_used) 763 + { 764 + struct tb_port *port = s->private; 765 + struct usb4_port *usb4 = port->usb4; 766 + struct tb *tb = port->sw->tb; 767 + 768 + if (mutex_lock_interruptible(&tb->lock)) 769 + return -ERESTARTSYS; 770 + 771 + if (supports_time(usb4)) { 772 + if (usb4->margining->time) 773 + seq_puts(s, "voltage [time]\n"); 774 + else 775 + seq_puts(s, "[voltage] time\n"); 776 + } else { 777 + seq_puts(s, "[voltage]\n"); 778 + } 779 + 780 + mutex_unlock(&tb->lock); 781 + return 0; 782 + } 783 + DEBUGFS_ATTR_RW(margining_test); 784 + 785 + static ssize_t margining_margin_write(struct file *file, 786 + const char __user *user_buf, 787 + size_t count, loff_t *ppos) 788 + { 789 + struct seq_file *s = file->private_data; 790 + struct tb_port *port = s->private; 791 + struct usb4_port *usb4 = port->usb4; 792 + struct tb *tb = port->sw->tb; 793 + int ret = 0; 794 + char *buf; 795 + 796 + buf = validate_and_copy_from_user(user_buf, &count); 797 + if (IS_ERR(buf)) 798 + return PTR_ERR(buf); 799 + 800 + buf[count - 1] = '\0'; 801 + 802 + if (mutex_lock_interruptible(&tb->lock)) { 803 + ret = -ERESTARTSYS; 804 + goto out_free; 805 + } 806 + 807 + if (usb4->margining->time) { 808 + if (!strcmp(buf, "left")) 809 + usb4->margining->right_high = false; 810 + else if (!strcmp(buf, "right")) 811 + usb4->margining->right_high = true; 812 + else 813 + ret = -EINVAL; 814 + } else { 815 + if (!strcmp(buf, "low")) 816 + usb4->margining->right_high = false; 817 + else if (!strcmp(buf, "high")) 818 + usb4->margining->right_high = true; 819 + else 820 + ret = -EINVAL; 821 + } 822 + 823 + mutex_unlock(&tb->lock); 824 + 825 + out_free: 826 + free_page((unsigned long)buf); 827 + return ret ? ret : count; 828 + } 829 + 830 + static int margining_margin_show(struct seq_file *s, void *not_used) 831 + { 832 + struct tb_port *port = s->private; 833 + struct usb4_port *usb4 = port->usb4; 834 + struct tb *tb = port->sw->tb; 835 + 836 + if (mutex_lock_interruptible(&tb->lock)) 837 + return -ERESTARTSYS; 838 + 839 + if (usb4->margining->time) { 840 + if (usb4->margining->right_high) 841 + seq_puts(s, "left [right]\n"); 842 + else 843 + seq_puts(s, "[left] right\n"); 844 + } else { 845 + if (usb4->margining->right_high) 846 + seq_puts(s, "low [high]\n"); 847 + else 848 + seq_puts(s, "[low] high\n"); 849 + } 850 + 851 + mutex_unlock(&tb->lock); 852 + return 0; 853 + } 854 + DEBUGFS_ATTR_RW(margining_margin); 855 + 856 + static void margining_port_init(struct tb_port *port) 857 + { 858 + struct tb_margining *margining; 859 + struct dentry *dir, *parent; 860 + struct usb4_port *usb4; 861 + char dir_name[10]; 862 + unsigned int val; 863 + int ret; 864 + 865 + usb4 = port->usb4; 866 + if (!usb4) 867 + return; 868 + 869 + snprintf(dir_name, sizeof(dir_name), "port%d", port->port); 870 + parent = debugfs_lookup(dir_name, port->sw->debugfs_dir); 871 + 872 + margining = kzalloc(sizeof(*margining), GFP_KERNEL); 873 + if (!margining) 874 + return; 875 + 876 + ret = usb4_port_margining_caps(port, margining->caps); 877 + if (ret) { 878 + kfree(margining); 879 + return; 880 + } 881 + 882 + usb4->margining = margining; 883 + 884 + /* Set the initial mode */ 885 + if (supports_software(usb4)) 886 + margining->software = true; 887 + 888 + val = (margining->caps[0] & USB4_MARGIN_CAP_0_VOLTAGE_STEPS_MASK) >> 889 + USB4_MARGIN_CAP_0_VOLTAGE_STEPS_SHIFT; 890 + margining->voltage_steps = val; 891 + val = (margining->caps[0] & USB4_MARGIN_CAP_0_MAX_VOLTAGE_OFFSET_MASK) >> 892 + USB4_MARGIN_CAP_0_MAX_VOLTAGE_OFFSET_SHIFT; 893 + margining->max_voltage_offset = 74 + val * 2; 894 + 895 + if (supports_time(usb4)) { 896 + val = (margining->caps[1] & USB4_MARGIN_CAP_1_TIME_STEPS_MASK) >> 897 + USB4_MARGIN_CAP_1_TIME_STEPS_SHIFT; 898 + margining->time_steps = val; 899 + val = (margining->caps[1] & USB4_MARGIN_CAP_1_TIME_OFFSET_MASK) >> 900 + USB4_MARGIN_CAP_1_TIME_OFFSET_SHIFT; 901 + /* 902 + * Store it as mUI (milli Unit Interval) because we want 903 + * to keep it as integer. 904 + */ 905 + margining->max_time_offset = 200 + 10 * val; 906 + } 907 + 908 + dir = debugfs_create_dir("margining", parent); 909 + if (supports_hardware(usb4)) { 910 + val = (margining->caps[1] & USB4_MARGIN_CAP_1_MIN_BER_MASK) >> 911 + USB4_MARGIN_CAP_1_MIN_BER_SHIFT; 912 + margining->min_ber_level = val; 913 + val = (margining->caps[1] & USB4_MARGIN_CAP_1_MAX_BER_MASK) >> 914 + USB4_MARGIN_CAP_1_MAX_BER_SHIFT; 915 + margining->max_ber_level = val; 916 + 917 + /* Set the default to minimum */ 918 + margining->ber_level = margining->min_ber_level; 919 + 920 + debugfs_create_file("ber_level_contour", 0400, dir, port, 921 + &margining_ber_level_fops); 922 + } 923 + debugfs_create_file("caps", 0400, dir, port, &margining_caps_fops); 924 + debugfs_create_file("lanes", 0600, dir, port, &margining_lanes_fops); 925 + debugfs_create_file("mode", 0600, dir, port, &margining_mode_fops); 926 + debugfs_create_file("run", 0600, dir, port, &margining_run_fops); 927 + debugfs_create_file("results", 0600, dir, port, &margining_results_fops); 928 + debugfs_create_file("test", 0600, dir, port, &margining_test_fops); 929 + if (independent_voltage_margins(usb4) || 930 + (supports_time(usb4) && independent_time_margins(usb4))) 931 + debugfs_create_file("margin", 0600, dir, port, &margining_margin_fops); 932 + } 933 + 934 + static void margining_port_remove(struct tb_port *port) 935 + { 936 + struct dentry *parent; 937 + char dir_name[10]; 938 + 939 + if (!port->usb4) 940 + return; 941 + 942 + snprintf(dir_name, sizeof(dir_name), "port%d", port->port); 943 + parent = debugfs_lookup(dir_name, port->sw->debugfs_dir); 944 + debugfs_remove_recursive(debugfs_lookup("margining", parent)); 945 + 946 + kfree(port->usb4->margining); 947 + port->usb4->margining = NULL; 948 + } 949 + 950 + static void margining_switch_init(struct tb_switch *sw) 951 + { 952 + struct tb_port *upstream, *downstream; 953 + struct tb_switch *parent_sw; 954 + u64 route = tb_route(sw); 955 + 956 + if (!route) 957 + return; 958 + 959 + upstream = tb_upstream_port(sw); 960 + parent_sw = tb_switch_parent(sw); 961 + downstream = tb_port_at(route, parent_sw); 962 + 963 + margining_port_init(downstream); 964 + margining_port_init(upstream); 965 + } 966 + 967 + static void margining_switch_remove(struct tb_switch *sw) 968 + { 969 + struct tb_switch *parent_sw; 970 + struct tb_port *downstream; 971 + u64 route = tb_route(sw); 972 + 973 + if (!route) 974 + return; 975 + 976 + /* 977 + * Upstream is removed with the router itself but we need to 978 + * remove the downstream port margining directory. 979 + */ 980 + parent_sw = tb_switch_parent(sw); 981 + downstream = tb_port_at(route, parent_sw); 982 + margining_port_remove(downstream); 983 + } 984 + 985 + static void margining_xdomain_init(struct tb_xdomain *xd) 986 + { 987 + struct tb_switch *parent_sw; 988 + struct tb_port *downstream; 989 + 990 + parent_sw = tb_xdomain_parent(xd); 991 + downstream = tb_port_at(xd->route, parent_sw); 992 + 993 + margining_port_init(downstream); 994 + } 995 + 996 + static void margining_xdomain_remove(struct tb_xdomain *xd) 997 + { 998 + struct tb_switch *parent_sw; 999 + struct tb_port *downstream; 1000 + 1001 + parent_sw = tb_xdomain_parent(xd); 1002 + downstream = tb_port_at(xd->route, parent_sw); 1003 + margining_port_remove(downstream); 1004 + } 1005 + #else 1006 + static inline void margining_switch_init(struct tb_switch *sw) { } 1007 + static inline void margining_switch_remove(struct tb_switch *sw) { } 1008 + static inline void margining_xdomain_init(struct tb_xdomain *xd) { } 1009 + static inline void margining_xdomain_remove(struct tb_xdomain *xd) { } 189 1010 #endif 190 1011 191 1012 static int port_clear_all_counters(struct tb_port *port) ··· 1512 689 debugfs_create_file("counters", 0600, debugfs_dir, port, 1513 690 &counters_fops); 1514 691 } 692 + 693 + margining_switch_init(sw); 1515 694 } 1516 695 1517 696 /** ··· 1524 699 */ 1525 700 void tb_switch_debugfs_remove(struct tb_switch *sw) 1526 701 { 702 + margining_switch_remove(sw); 1527 703 debugfs_remove_recursive(sw->debugfs_dir); 704 + } 705 + 706 + void tb_xdomain_debugfs_init(struct tb_xdomain *xd) 707 + { 708 + margining_xdomain_init(xd); 709 + } 710 + 711 + void tb_xdomain_debugfs_remove(struct tb_xdomain *xd) 712 + { 713 + margining_xdomain_remove(xd); 1528 714 } 1529 715 1530 716 /**
+4 -6
drivers/thunderbolt/domain.c
··· 144 144 145 145 for (ret = 0, i = 0; i < tb->nboot_acl; i++) { 146 146 if (!uuid_is_null(&uuids[i])) 147 - ret += scnprintf(buf + ret, PAGE_SIZE - ret, "%pUb", 148 - &uuids[i]); 147 + ret += sysfs_emit_at(buf, ret, "%pUb", &uuids[i]); 149 148 150 - ret += scnprintf(buf + ret, PAGE_SIZE - ret, "%s", 151 - i < tb->nboot_acl - 1 ? "," : "\n"); 149 + ret += sysfs_emit_at(buf, ret, "%s", i < tb->nboot_acl - 1 ? "," : "\n"); 152 150 } 153 151 154 152 out: ··· 245 247 tb->security_level == TB_SECURITY_SECURE) 246 248 deauthorization = !!tb->cm_ops->disapprove_switch; 247 249 248 - return sprintf(buf, "%d\n", deauthorization); 250 + return sysfs_emit(buf, "%d\n", deauthorization); 249 251 } 250 252 static DEVICE_ATTR_RO(deauthorization); 251 253 ··· 268 270 if (tb->security_level < ARRAY_SIZE(tb_security_names)) 269 271 name = tb_security_names[tb->security_level]; 270 272 271 - return sprintf(buf, "%s\n", name); 273 + return sysfs_emit(buf, "%s\n", name); 272 274 } 273 275 static DEVICE_ATTR_RO(security); 274 276
+3
drivers/thunderbolt/icm.c
··· 2518 2518 case PCI_DEVICE_ID_INTEL_ADL_NHI1: 2519 2519 case PCI_DEVICE_ID_INTEL_RPL_NHI0: 2520 2520 case PCI_DEVICE_ID_INTEL_RPL_NHI1: 2521 + case PCI_DEVICE_ID_INTEL_MTL_M_NHI0: 2522 + case PCI_DEVICE_ID_INTEL_MTL_P_NHI0: 2523 + case PCI_DEVICE_ID_INTEL_MTL_P_NHI1: 2521 2524 icm->is_supported = icm_tgl_is_supported; 2522 2525 icm->driver_ready = icm_icl_driver_ready; 2523 2526 icm->set_uuid = icm_icl_set_uuid;
+25 -30
drivers/thunderbolt/nhi.c
··· 1184 1184 static int nhi_init_msi(struct tb_nhi *nhi) 1185 1185 { 1186 1186 struct pci_dev *pdev = nhi->pdev; 1187 + struct device *dev = &pdev->dev; 1187 1188 int res, irq, nvec; 1188 1189 1189 1190 /* In case someone left them on. */ ··· 1215 1214 1216 1215 res = devm_request_irq(&pdev->dev, irq, nhi_msi, 1217 1216 IRQF_NO_SUSPEND, "thunderbolt", nhi); 1218 - if (res) { 1219 - dev_err(&pdev->dev, "request_irq failed, aborting\n"); 1220 - return res; 1221 - } 1217 + if (res) 1218 + return dev_err_probe(dev, res, "request_irq failed, aborting\n"); 1222 1219 } 1223 1220 1224 1221 return 0; ··· 1257 1258 1258 1259 static int nhi_probe(struct pci_dev *pdev, const struct pci_device_id *id) 1259 1260 { 1261 + struct device *dev = &pdev->dev; 1260 1262 struct tb_nhi *nhi; 1261 1263 struct tb *tb; 1262 1264 int res; 1263 1265 1264 - if (!nhi_imr_valid(pdev)) { 1265 - dev_warn(&pdev->dev, "firmware image not valid, aborting\n"); 1266 - return -ENODEV; 1267 - } 1266 + if (!nhi_imr_valid(pdev)) 1267 + return dev_err_probe(dev, -ENODEV, "firmware image not valid, aborting\n"); 1268 1268 1269 1269 res = pcim_enable_device(pdev); 1270 - if (res) { 1271 - dev_err(&pdev->dev, "cannot enable PCI device, aborting\n"); 1272 - return res; 1273 - } 1270 + if (res) 1271 + return dev_err_probe(dev, res, "cannot enable PCI device, aborting\n"); 1274 1272 1275 1273 res = pcim_iomap_regions(pdev, 1 << 0, "thunderbolt"); 1276 - if (res) { 1277 - dev_err(&pdev->dev, "cannot obtain PCI resources, aborting\n"); 1278 - return res; 1279 - } 1274 + if (res) 1275 + return dev_err_probe(dev, res, "cannot obtain PCI resources, aborting\n"); 1280 1276 1281 1277 nhi = devm_kzalloc(&pdev->dev, sizeof(*nhi), GFP_KERNEL); 1282 1278 if (!nhi) ··· 1282 1288 /* cannot fail - table is allocated in pcim_iomap_regions */ 1283 1289 nhi->iobase = pcim_iomap_table(pdev)[0]; 1284 1290 nhi->hop_count = ioread32(nhi->iobase + REG_HOP_COUNT) & 0x3ff; 1285 - dev_dbg(&pdev->dev, "total paths: %d\n", nhi->hop_count); 1291 + dev_dbg(dev, "total paths: %d\n", nhi->hop_count); 1286 1292 1287 1293 nhi->tx_rings = devm_kcalloc(&pdev->dev, nhi->hop_count, 1288 1294 sizeof(*nhi->tx_rings), GFP_KERNEL); ··· 1295 1301 nhi_check_iommu(nhi); 1296 1302 1297 1303 res = nhi_init_msi(nhi); 1298 - if (res) { 1299 - dev_err(&pdev->dev, "cannot enable MSI, aborting\n"); 1300 - return res; 1301 - } 1304 + if (res) 1305 + return dev_err_probe(dev, res, "cannot enable MSI, aborting\n"); 1302 1306 1303 1307 spin_lock_init(&nhi->lock); 1304 1308 1305 1309 res = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); 1306 - if (res) { 1307 - dev_err(&pdev->dev, "failed to set DMA mask\n"); 1308 - return res; 1309 - } 1310 + if (res) 1311 + return dev_err_probe(dev, res, "failed to set DMA mask\n"); 1310 1312 1311 1313 pci_set_master(pdev); 1312 1314 ··· 1313 1323 } 1314 1324 1315 1325 tb = nhi_select_cm(nhi); 1316 - if (!tb) { 1317 - dev_err(&nhi->pdev->dev, 1326 + if (!tb) 1327 + return dev_err_probe(dev, -ENODEV, 1318 1328 "failed to determine connection manager, aborting\n"); 1319 - return -ENODEV; 1320 - } 1321 1329 1322 - dev_dbg(&nhi->pdev->dev, "NHI initialized, starting thunderbolt\n"); 1330 + dev_dbg(dev, "NHI initialized, starting thunderbolt\n"); 1323 1331 1324 1332 res = tb_domain_add(tb); 1325 1333 if (res) { ··· 1421 1433 .driver_data = (kernel_ulong_t)&icl_nhi_ops }, 1422 1434 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_ICL_NHI1), 1423 1435 .driver_data = (kernel_ulong_t)&icl_nhi_ops }, 1436 + /* Thunderbolt 4 */ 1424 1437 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_TGL_NHI0), 1425 1438 .driver_data = (kernel_ulong_t)&icl_nhi_ops }, 1426 1439 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_TGL_NHI1), ··· 1437 1448 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_RPL_NHI0), 1438 1449 .driver_data = (kernel_ulong_t)&icl_nhi_ops }, 1439 1450 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_RPL_NHI1), 1451 + .driver_data = (kernel_ulong_t)&icl_nhi_ops }, 1452 + { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_MTL_M_NHI0), 1453 + .driver_data = (kernel_ulong_t)&icl_nhi_ops }, 1454 + { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_MTL_P_NHI0), 1455 + .driver_data = (kernel_ulong_t)&icl_nhi_ops }, 1456 + { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_MTL_P_NHI1), 1440 1457 .driver_data = (kernel_ulong_t)&icl_nhi_ops }, 1441 1458 1442 1459 /* Any USB4 compliant host */
+3
drivers/thunderbolt/nhi.h
··· 75 75 #define PCI_DEVICE_ID_INTEL_TITAN_RIDGE_DD_BRIDGE 0x15ef 76 76 #define PCI_DEVICE_ID_INTEL_ADL_NHI0 0x463e 77 77 #define PCI_DEVICE_ID_INTEL_ADL_NHI1 0x466d 78 + #define PCI_DEVICE_ID_INTEL_MTL_M_NHI0 0x7eb2 79 + #define PCI_DEVICE_ID_INTEL_MTL_P_NHI0 0x7ec2 80 + #define PCI_DEVICE_ID_INTEL_MTL_P_NHI1 0x7ec3 78 81 #define PCI_DEVICE_ID_INTEL_ICL_NHI1 0x8a0d 79 82 #define PCI_DEVICE_ID_INTEL_ICL_NHI0 0x8a17 80 83 #define PCI_DEVICE_ID_INTEL_TGL_NHI0 0x9a1b
+376 -9
drivers/thunderbolt/nvm.c
··· 12 12 13 13 #include "tb.h" 14 14 15 + /* Intel specific NVM offsets */ 16 + #define INTEL_NVM_DEVID 0x05 17 + #define INTEL_NVM_VERSION 0x08 18 + #define INTEL_NVM_CSS 0x10 19 + #define INTEL_NVM_FLASH_SIZE 0x45 20 + 21 + /* ASMedia specific NVM offsets */ 22 + #define ASMEDIA_NVM_DATE 0x1c 23 + #define ASMEDIA_NVM_VERSION 0x28 24 + 15 25 static DEFINE_IDA(nvm_ida); 26 + 27 + /** 28 + * struct tb_nvm_vendor_ops - Vendor specific NVM operations 29 + * @read_version: Reads out NVM version from the flash 30 + * @validate: Validates the NVM image before update (optional) 31 + * @write_headers: Writes headers before the rest of the image (optional) 32 + */ 33 + struct tb_nvm_vendor_ops { 34 + int (*read_version)(struct tb_nvm *nvm); 35 + int (*validate)(struct tb_nvm *nvm); 36 + int (*write_headers)(struct tb_nvm *nvm); 37 + }; 38 + 39 + /** 40 + * struct tb_nvm_vendor - Vendor to &struct tb_nvm_vendor_ops mapping 41 + * @vendor: Vendor ID 42 + * @vops: Vendor specific NVM operations 43 + * 44 + * Maps vendor ID to NVM vendor operations. If there is no mapping then 45 + * NVM firmware upgrade is disabled for the device. 46 + */ 47 + struct tb_nvm_vendor { 48 + u16 vendor; 49 + const struct tb_nvm_vendor_ops *vops; 50 + }; 51 + 52 + static int intel_switch_nvm_version(struct tb_nvm *nvm) 53 + { 54 + struct tb_switch *sw = tb_to_switch(nvm->dev); 55 + u32 val, nvm_size, hdr_size; 56 + int ret; 57 + 58 + /* 59 + * If the switch is in safe-mode the only accessible portion of 60 + * the NVM is the non-active one where userspace is expected to 61 + * write new functional NVM. 62 + */ 63 + if (sw->safe_mode) 64 + return 0; 65 + 66 + ret = tb_switch_nvm_read(sw, INTEL_NVM_FLASH_SIZE, &val, sizeof(val)); 67 + if (ret) 68 + return ret; 69 + 70 + hdr_size = sw->generation < 3 ? SZ_8K : SZ_16K; 71 + nvm_size = (SZ_1M << (val & 7)) / 8; 72 + nvm_size = (nvm_size - hdr_size) / 2; 73 + 74 + ret = tb_switch_nvm_read(sw, INTEL_NVM_VERSION, &val, sizeof(val)); 75 + if (ret) 76 + return ret; 77 + 78 + nvm->major = (val >> 16) & 0xff; 79 + nvm->minor = (val >> 8) & 0xff; 80 + nvm->active_size = nvm_size; 81 + 82 + return 0; 83 + } 84 + 85 + static int intel_switch_nvm_validate(struct tb_nvm *nvm) 86 + { 87 + struct tb_switch *sw = tb_to_switch(nvm->dev); 88 + unsigned int image_size, hdr_size; 89 + u16 ds_size, device_id; 90 + u8 *buf = nvm->buf; 91 + 92 + image_size = nvm->buf_data_size; 93 + 94 + /* 95 + * FARB pointer must point inside the image and must at least 96 + * contain parts of the digital section we will be reading here. 97 + */ 98 + hdr_size = (*(u32 *)buf) & 0xffffff; 99 + if (hdr_size + INTEL_NVM_DEVID + 2 >= image_size) 100 + return -EINVAL; 101 + 102 + /* Digital section start should be aligned to 4k page */ 103 + if (!IS_ALIGNED(hdr_size, SZ_4K)) 104 + return -EINVAL; 105 + 106 + /* 107 + * Read digital section size and check that it also fits inside 108 + * the image. 109 + */ 110 + ds_size = *(u16 *)(buf + hdr_size); 111 + if (ds_size >= image_size) 112 + return -EINVAL; 113 + 114 + if (sw->safe_mode) 115 + return 0; 116 + 117 + /* 118 + * Make sure the device ID in the image matches the one 119 + * we read from the switch config space. 120 + */ 121 + device_id = *(u16 *)(buf + hdr_size + INTEL_NVM_DEVID); 122 + if (device_id != sw->config.device_id) 123 + return -EINVAL; 124 + 125 + /* Skip headers in the image */ 126 + nvm->buf_data_start = buf + hdr_size; 127 + nvm->buf_data_size = image_size - hdr_size; 128 + 129 + return 0; 130 + } 131 + 132 + static int intel_switch_nvm_write_headers(struct tb_nvm *nvm) 133 + { 134 + struct tb_switch *sw = tb_to_switch(nvm->dev); 135 + 136 + if (sw->generation < 3) { 137 + int ret; 138 + 139 + /* Write CSS headers first */ 140 + ret = dma_port_flash_write(sw->dma_port, 141 + DMA_PORT_CSS_ADDRESS, nvm->buf + INTEL_NVM_CSS, 142 + DMA_PORT_CSS_MAX_SIZE); 143 + if (ret) 144 + return ret; 145 + } 146 + 147 + return 0; 148 + } 149 + 150 + static const struct tb_nvm_vendor_ops intel_switch_nvm_ops = { 151 + .read_version = intel_switch_nvm_version, 152 + .validate = intel_switch_nvm_validate, 153 + .write_headers = intel_switch_nvm_write_headers, 154 + }; 155 + 156 + static int asmedia_switch_nvm_version(struct tb_nvm *nvm) 157 + { 158 + struct tb_switch *sw = tb_to_switch(nvm->dev); 159 + u32 val; 160 + int ret; 161 + 162 + ret = tb_switch_nvm_read(sw, ASMEDIA_NVM_VERSION, &val, sizeof(val)); 163 + if (ret) 164 + return ret; 165 + 166 + nvm->major = (val << 16) & 0xff0000; 167 + nvm->major |= val & 0x00ff00; 168 + nvm->major |= (val >> 16) & 0x0000ff; 169 + 170 + ret = tb_switch_nvm_read(sw, ASMEDIA_NVM_DATE, &val, sizeof(val)); 171 + if (ret) 172 + return ret; 173 + 174 + nvm->minor = (val << 16) & 0xff0000; 175 + nvm->minor |= val & 0x00ff00; 176 + nvm->minor |= (val >> 16) & 0x0000ff; 177 + 178 + /* ASMedia NVM size is fixed to 512k */ 179 + nvm->active_size = SZ_512K; 180 + 181 + return 0; 182 + } 183 + 184 + static const struct tb_nvm_vendor_ops asmedia_switch_nvm_ops = { 185 + .read_version = asmedia_switch_nvm_version, 186 + }; 187 + 188 + /* Router vendor NVM support table */ 189 + static const struct tb_nvm_vendor switch_nvm_vendors[] = { 190 + { 0x174c, &asmedia_switch_nvm_ops }, 191 + { PCI_VENDOR_ID_INTEL, &intel_switch_nvm_ops }, 192 + { 0x8087, &intel_switch_nvm_ops }, 193 + }; 194 + 195 + static int intel_retimer_nvm_version(struct tb_nvm *nvm) 196 + { 197 + struct tb_retimer *rt = tb_to_retimer(nvm->dev); 198 + u32 val, nvm_size; 199 + int ret; 200 + 201 + ret = tb_retimer_nvm_read(rt, INTEL_NVM_VERSION, &val, sizeof(val)); 202 + if (ret) 203 + return ret; 204 + 205 + nvm->major = (val >> 16) & 0xff; 206 + nvm->minor = (val >> 8) & 0xff; 207 + 208 + ret = tb_retimer_nvm_read(rt, INTEL_NVM_FLASH_SIZE, &val, sizeof(val)); 209 + if (ret) 210 + return ret; 211 + 212 + nvm_size = (SZ_1M << (val & 7)) / 8; 213 + nvm_size = (nvm_size - SZ_16K) / 2; 214 + nvm->active_size = nvm_size; 215 + 216 + return 0; 217 + } 218 + 219 + static int intel_retimer_nvm_validate(struct tb_nvm *nvm) 220 + { 221 + struct tb_retimer *rt = tb_to_retimer(nvm->dev); 222 + unsigned int image_size, hdr_size; 223 + u8 *buf = nvm->buf; 224 + u16 ds_size, device; 225 + 226 + image_size = nvm->buf_data_size; 227 + 228 + /* 229 + * FARB pointer must point inside the image and must at least 230 + * contain parts of the digital section we will be reading here. 231 + */ 232 + hdr_size = (*(u32 *)buf) & 0xffffff; 233 + if (hdr_size + INTEL_NVM_DEVID + 2 >= image_size) 234 + return -EINVAL; 235 + 236 + /* Digital section start should be aligned to 4k page */ 237 + if (!IS_ALIGNED(hdr_size, SZ_4K)) 238 + return -EINVAL; 239 + 240 + /* 241 + * Read digital section size and check that it also fits inside 242 + * the image. 243 + */ 244 + ds_size = *(u16 *)(buf + hdr_size); 245 + if (ds_size >= image_size) 246 + return -EINVAL; 247 + 248 + /* 249 + * Make sure the device ID in the image matches the retimer 250 + * hardware. 251 + */ 252 + device = *(u16 *)(buf + hdr_size + INTEL_NVM_DEVID); 253 + if (device != rt->device) 254 + return -EINVAL; 255 + 256 + /* Skip headers in the image */ 257 + nvm->buf_data_start = buf + hdr_size; 258 + nvm->buf_data_size = image_size - hdr_size; 259 + 260 + return 0; 261 + } 262 + 263 + static const struct tb_nvm_vendor_ops intel_retimer_nvm_ops = { 264 + .read_version = intel_retimer_nvm_version, 265 + .validate = intel_retimer_nvm_validate, 266 + }; 267 + 268 + /* Retimer vendor NVM support table */ 269 + static const struct tb_nvm_vendor retimer_nvm_vendors[] = { 270 + { 0x8087, &intel_retimer_nvm_ops }, 271 + }; 16 272 17 273 /** 18 274 * tb_nvm_alloc() - Allocate new NVM structure 19 275 * @dev: Device owning the NVM 20 276 * 21 277 * Allocates new NVM structure with unique @id and returns it. In case 22 - * of error returns ERR_PTR(). 278 + * of error returns ERR_PTR(). Specifically returns %-EOPNOTSUPP if the 279 + * NVM format of the @dev is not known by the kernel. 23 280 */ 24 281 struct tb_nvm *tb_nvm_alloc(struct device *dev) 25 282 { 283 + const struct tb_nvm_vendor_ops *vops = NULL; 26 284 struct tb_nvm *nvm; 27 - int ret; 285 + int ret, i; 286 + 287 + if (tb_is_switch(dev)) { 288 + const struct tb_switch *sw = tb_to_switch(dev); 289 + 290 + for (i = 0; i < ARRAY_SIZE(switch_nvm_vendors); i++) { 291 + const struct tb_nvm_vendor *v = &switch_nvm_vendors[i]; 292 + 293 + if (v->vendor == sw->config.vendor_id) { 294 + vops = v->vops; 295 + break; 296 + } 297 + } 298 + 299 + if (!vops) { 300 + tb_sw_dbg(sw, "router NVM format of vendor %#x unknown\n", 301 + sw->config.vendor_id); 302 + return ERR_PTR(-EOPNOTSUPP); 303 + } 304 + } else if (tb_is_retimer(dev)) { 305 + const struct tb_retimer *rt = tb_to_retimer(dev); 306 + 307 + for (i = 0; i < ARRAY_SIZE(retimer_nvm_vendors); i++) { 308 + const struct tb_nvm_vendor *v = &retimer_nvm_vendors[i]; 309 + 310 + if (v->vendor == rt->vendor) { 311 + vops = v->vops; 312 + break; 313 + } 314 + } 315 + 316 + if (!vops) { 317 + dev_dbg(dev, "retimer NVM format of vendor %#x unknown\n", 318 + rt->vendor); 319 + return ERR_PTR(-EOPNOTSUPP); 320 + } 321 + } else { 322 + return ERR_PTR(-EOPNOTSUPP); 323 + } 28 324 29 325 nvm = kzalloc(sizeof(*nvm), GFP_KERNEL); 30 326 if (!nvm) ··· 334 38 335 39 nvm->id = ret; 336 40 nvm->dev = dev; 41 + nvm->vops = vops; 337 42 338 43 return nvm; 339 44 } 340 45 341 46 /** 47 + * tb_nvm_read_version() - Read and populate NVM version 48 + * @nvm: NVM structure 49 + * 50 + * Uses vendor specific means to read out and fill in the existing 51 + * active NVM version. Returns %0 in case of success and negative errno 52 + * otherwise. 53 + */ 54 + int tb_nvm_read_version(struct tb_nvm *nvm) 55 + { 56 + const struct tb_nvm_vendor_ops *vops = nvm->vops; 57 + 58 + if (vops && vops->read_version) 59 + return vops->read_version(nvm); 60 + 61 + return -EOPNOTSUPP; 62 + } 63 + 64 + /** 65 + * tb_nvm_validate() - Validate new NVM image 66 + * @nvm: NVM structure 67 + * 68 + * Runs vendor specific validation over the new NVM image and if all 69 + * checks pass returns %0. As side effect updates @nvm->buf_data_start 70 + * and @nvm->buf_data_size fields to match the actual data to be written 71 + * to the NVM. 72 + * 73 + * If the validation does not pass then returns negative errno. 74 + */ 75 + int tb_nvm_validate(struct tb_nvm *nvm) 76 + { 77 + const struct tb_nvm_vendor_ops *vops = nvm->vops; 78 + unsigned int image_size; 79 + u8 *buf = nvm->buf; 80 + 81 + if (!buf) 82 + return -EINVAL; 83 + if (!vops) 84 + return -EOPNOTSUPP; 85 + 86 + /* Just do basic image size checks */ 87 + image_size = nvm->buf_data_size; 88 + if (image_size < NVM_MIN_SIZE || image_size > NVM_MAX_SIZE) 89 + return -EINVAL; 90 + 91 + /* 92 + * Set the default data start in the buffer. The validate method 93 + * below can change this if needed. 94 + */ 95 + nvm->buf_data_start = buf; 96 + 97 + return vops->validate ? vops->validate(nvm) : 0; 98 + } 99 + 100 + /** 101 + * tb_nvm_write_headers() - Write headers before the rest of the image 102 + * @nvm: NVM structure 103 + * 104 + * If the vendor NVM format requires writing headers before the rest of 105 + * the image, this function does that. Can be called even if the device 106 + * does not need this. 107 + * 108 + * Returns %0 in case of success and negative errno otherwise. 109 + */ 110 + int tb_nvm_write_headers(struct tb_nvm *nvm) 111 + { 112 + const struct tb_nvm_vendor_ops *vops = nvm->vops; 113 + 114 + return vops->write_headers ? vops->write_headers(nvm) : 0; 115 + } 116 + 117 + /** 342 118 * tb_nvm_add_active() - Adds active NVMem device to NVM 343 119 * @nvm: NVM structure 344 - * @size: Size of the active NVM in bytes 345 120 * @reg_read: Pointer to the function to read the NVM (passed directly to the 346 121 * NVMem device) 347 122 * ··· 421 54 * needed. The first parameter passed to @reg_read is @nvm structure. 422 55 * Returns %0 in success and negative errno otherwise. 423 56 */ 424 - int tb_nvm_add_active(struct tb_nvm *nvm, size_t size, nvmem_reg_read_t reg_read) 57 + int tb_nvm_add_active(struct tb_nvm *nvm, nvmem_reg_read_t reg_read) 425 58 { 426 59 struct nvmem_config config; 427 60 struct nvmem_device *nvmem; ··· 434 67 config.id = nvm->id; 435 68 config.stride = 4; 436 69 config.word_size = 4; 437 - config.size = size; 70 + config.size = nvm->active_size; 438 71 config.dev = nvm->dev; 439 72 config.owner = THIS_MODULE; 440 73 config.priv = nvm; ··· 476 109 /** 477 110 * tb_nvm_add_non_active() - Adds non-active NVMem device to NVM 478 111 * @nvm: NVM structure 479 - * @size: Size of the non-active NVM in bytes 480 112 * @reg_write: Pointer to the function to write the NVM (passed directly 481 113 * to the NVMem device) 482 114 * 483 115 * Registers new non-active NVmem device for @nvm. The @reg_write is called 484 116 * directly from NVMem so it must handle possible concurrent access if 485 117 * needed. The first parameter passed to @reg_write is @nvm structure. 118 + * The size of the NVMem device is set to %NVM_MAX_SIZE. 119 + * 486 120 * Returns %0 in success and negative errno otherwise. 487 121 */ 488 - int tb_nvm_add_non_active(struct tb_nvm *nvm, size_t size, 489 - nvmem_reg_write_t reg_write) 122 + int tb_nvm_add_non_active(struct tb_nvm *nvm, nvmem_reg_write_t reg_write) 490 123 { 491 124 struct nvmem_config config; 492 125 struct nvmem_device *nvmem; ··· 499 132 config.id = nvm->id; 500 133 config.stride = 4; 501 134 config.word_size = 4; 502 - config.size = size; 135 + config.size = NVM_MAX_SIZE; 503 136 config.dev = nvm->dev; 504 137 config.owner = THIS_MODULE; 505 138 config.priv = nvm;
+47 -68
drivers/thunderbolt/retimer.c
··· 16 16 17 17 #define TB_MAX_RETIMER_INDEX 6 18 18 19 - static int tb_retimer_nvm_read(void *priv, unsigned int offset, void *val, 20 - size_t bytes) 19 + /** 20 + * tb_retimer_nvm_read() - Read contents of retimer NVM 21 + * @rt: Retimer device 22 + * @address: NVM address (in bytes) to start reading 23 + * @buf: Data read from NVM is stored here 24 + * @size: Number of bytes to read 25 + * 26 + * Reads retimer NVM and copies the contents to @buf. Returns %0 if the 27 + * read was successful and negative errno in case of failure. 28 + */ 29 + int tb_retimer_nvm_read(struct tb_retimer *rt, unsigned int address, void *buf, 30 + size_t size) 31 + { 32 + return usb4_port_retimer_nvm_read(rt->port, rt->index, address, buf, size); 33 + } 34 + 35 + static int nvm_read(void *priv, unsigned int offset, void *val, size_t bytes) 21 36 { 22 37 struct tb_nvm *nvm = priv; 23 38 struct tb_retimer *rt = tb_to_retimer(nvm->dev); ··· 45 30 goto out; 46 31 } 47 32 48 - ret = usb4_port_retimer_nvm_read(rt->port, rt->index, offset, val, bytes); 33 + ret = tb_retimer_nvm_read(rt, offset, val, bytes); 49 34 mutex_unlock(&rt->tb->lock); 50 35 51 36 out: ··· 55 40 return ret; 56 41 } 57 42 58 - static int tb_retimer_nvm_write(void *priv, unsigned int offset, void *val, 59 - size_t bytes) 43 + static int nvm_write(void *priv, unsigned int offset, void *val, size_t bytes) 60 44 { 61 45 struct tb_nvm *nvm = priv; 62 46 struct tb_retimer *rt = tb_to_retimer(nvm->dev); ··· 73 59 static int tb_retimer_nvm_add(struct tb_retimer *rt) 74 60 { 75 61 struct tb_nvm *nvm; 76 - u32 val, nvm_size; 77 62 int ret; 78 63 79 64 nvm = tb_nvm_alloc(&rt->dev); 80 - if (IS_ERR(nvm)) 81 - return PTR_ERR(nvm); 65 + if (IS_ERR(nvm)) { 66 + ret = PTR_ERR(nvm) == -EOPNOTSUPP ? 0 : PTR_ERR(nvm); 67 + goto err_nvm; 68 + } 82 69 83 - ret = usb4_port_retimer_nvm_read(rt->port, rt->index, NVM_VERSION, &val, 84 - sizeof(val)); 70 + ret = tb_nvm_read_version(nvm); 85 71 if (ret) 86 72 goto err_nvm; 87 73 88 - nvm->major = val >> 16; 89 - nvm->minor = val >> 8; 90 - 91 - ret = usb4_port_retimer_nvm_read(rt->port, rt->index, NVM_FLASH_SIZE, 92 - &val, sizeof(val)); 74 + ret = tb_nvm_add_active(nvm, nvm_read); 93 75 if (ret) 94 76 goto err_nvm; 95 77 96 - nvm_size = (SZ_1M << (val & 7)) / 8; 97 - nvm_size = (nvm_size - SZ_16K) / 2; 98 - 99 - ret = tb_nvm_add_active(nvm, nvm_size, tb_retimer_nvm_read); 100 - if (ret) 101 - goto err_nvm; 102 - 103 - ret = tb_nvm_add_non_active(nvm, NVM_MAX_SIZE, tb_retimer_nvm_write); 78 + ret = tb_nvm_add_non_active(nvm, nvm_write); 104 79 if (ret) 105 80 goto err_nvm; 106 81 ··· 97 94 return 0; 98 95 99 96 err_nvm: 100 - tb_nvm_free(nvm); 97 + dev_dbg(&rt->dev, "NVM upgrade disabled\n"); 98 + if (!IS_ERR(nvm)) 99 + tb_nvm_free(nvm); 100 + 101 101 return ret; 102 102 } 103 103 104 104 static int tb_retimer_nvm_validate_and_write(struct tb_retimer *rt) 105 105 { 106 - unsigned int image_size, hdr_size; 107 - const u8 *buf = rt->nvm->buf; 108 - u16 ds_size, device; 106 + unsigned int image_size; 107 + const u8 *buf; 109 108 int ret; 110 109 110 + ret = tb_nvm_validate(rt->nvm); 111 + if (ret) 112 + return ret; 113 + 114 + buf = rt->nvm->buf_data_start; 111 115 image_size = rt->nvm->buf_data_size; 112 - if (image_size < NVM_MIN_SIZE || image_size > NVM_MAX_SIZE) 113 - return -EINVAL; 114 - 115 - /* 116 - * FARB pointer must point inside the image and must at least 117 - * contain parts of the digital section we will be reading here. 118 - */ 119 - hdr_size = (*(u32 *)buf) & 0xffffff; 120 - if (hdr_size + NVM_DEVID + 2 >= image_size) 121 - return -EINVAL; 122 - 123 - /* Digital section start should be aligned to 4k page */ 124 - if (!IS_ALIGNED(hdr_size, SZ_4K)) 125 - return -EINVAL; 126 - 127 - /* 128 - * Read digital section size and check that it also fits inside 129 - * the image. 130 - */ 131 - ds_size = *(u16 *)(buf + hdr_size); 132 - if (ds_size >= image_size) 133 - return -EINVAL; 134 - 135 - /* 136 - * Make sure the device ID in the image matches the retimer 137 - * hardware. 138 - */ 139 - device = *(u16 *)(buf + hdr_size + NVM_DEVID); 140 - if (device != rt->device) 141 - return -EINVAL; 142 - 143 - /* Skip headers in the image */ 144 - buf += hdr_size; 145 - image_size -= hdr_size; 146 116 147 117 ret = usb4_port_retimer_nvm_write(rt->port, rt->index, 0, buf, 148 118 image_size); 149 - if (!ret) 150 - rt->nvm->flushed = true; 119 + if (ret) 120 + return ret; 151 121 152 - return ret; 122 + rt->nvm->flushed = true; 123 + return 0; 153 124 } 154 125 155 126 static int tb_retimer_nvm_authenticate(struct tb_retimer *rt, bool auth_only) ··· 162 185 { 163 186 struct tb_retimer *rt = tb_to_retimer(dev); 164 187 165 - return sprintf(buf, "%#x\n", rt->device); 188 + return sysfs_emit(buf, "%#x\n", rt->device); 166 189 } 167 190 static DEVICE_ATTR_RO(device); 168 191 ··· 177 200 178 201 if (!rt->nvm) 179 202 ret = -EAGAIN; 203 + else if (rt->no_nvm_upgrade) 204 + ret = -EOPNOTSUPP; 180 205 else 181 - ret = sprintf(buf, "%#x\n", rt->auth_status); 206 + ret = sysfs_emit(buf, "%#x\n", rt->auth_status); 182 207 183 208 mutex_unlock(&rt->tb->lock); 184 209 ··· 255 276 if (!rt->nvm) 256 277 ret = -EAGAIN; 257 278 else 258 - ret = sprintf(buf, "%x.%x\n", rt->nvm->major, rt->nvm->minor); 279 + ret = sysfs_emit(buf, "%x.%x\n", rt->nvm->major, rt->nvm->minor); 259 280 260 281 mutex_unlock(&rt->tb->lock); 261 282 return ret; ··· 267 288 { 268 289 struct tb_retimer *rt = tb_to_retimer(dev); 269 290 270 - return sprintf(buf, "%#x\n", rt->vendor); 291 + return sysfs_emit(buf, "%#x\n", rt->vendor); 271 292 } 272 293 static DEVICE_ATTR_RO(vendor); 273 294
+58
drivers/thunderbolt/sb_regs.h
··· 26 26 USB4_SB_OPCODE_NVM_BLOCK_WRITE = 0x574b4c42, /* "BLKW" */ 27 27 USB4_SB_OPCODE_NVM_AUTH_WRITE = 0x48545541, /* "AUTH" */ 28 28 USB4_SB_OPCODE_NVM_READ = 0x52524641, /* "AFRR" */ 29 + USB4_SB_OPCODE_READ_LANE_MARGINING_CAP = 0x50434452, /* "RDCP" */ 30 + USB4_SB_OPCODE_RUN_HW_LANE_MARGINING = 0x474d4852, /* "RHMG" */ 31 + USB4_SB_OPCODE_RUN_SW_LANE_MARGINING = 0x474d5352, /* "RSMG" */ 32 + USB4_SB_OPCODE_READ_SW_MARGIN_ERR = 0x57534452, /* "RDSW" */ 29 33 }; 30 34 31 35 #define USB4_SB_METADATA 0x09 32 36 #define USB4_SB_METADATA_NVM_AUTH_WRITE_MASK GENMASK(5, 0) 33 37 #define USB4_SB_DATA 0x12 38 + 39 + /* USB4_SB_OPCODE_READ_LANE_MARGINING_CAP */ 40 + #define USB4_MARGIN_CAP_0_MODES_HW BIT(0) 41 + #define USB4_MARGIN_CAP_0_MODES_SW BIT(1) 42 + #define USB4_MARGIN_CAP_0_2_LANES BIT(2) 43 + #define USB4_MARGIN_CAP_0_VOLTAGE_INDP_MASK GENMASK(4, 3) 44 + #define USB4_MARGIN_CAP_0_VOLTAGE_INDP_SHIFT 3 45 + #define USB4_MARGIN_CAP_0_VOLTAGE_MIN 0x0 46 + #define USB4_MARGIN_CAP_0_VOLTAGE_HL 0x1 47 + #define USB4_MARGIN_CAP_0_VOLTAGE_BOTH 0x2 48 + #define USB4_MARGIN_CAP_0_TIME BIT(5) 49 + #define USB4_MARGIN_CAP_0_VOLTAGE_STEPS_MASK GENMASK(12, 6) 50 + #define USB4_MARGIN_CAP_0_VOLTAGE_STEPS_SHIFT 6 51 + #define USB4_MARGIN_CAP_0_MAX_VOLTAGE_OFFSET_MASK GENMASK(18, 13) 52 + #define USB4_MARGIN_CAP_0_MAX_VOLTAGE_OFFSET_SHIFT 13 53 + #define USB4_MARGIN_CAP_1_TIME_DESTR BIT(8) 54 + #define USB4_MARGIN_CAP_1_TIME_INDP_MASK GENMASK(10, 9) 55 + #define USB4_MARGIN_CAP_1_TIME_INDP_SHIFT 9 56 + #define USB4_MARGIN_CAP_1_TIME_MIN 0x0 57 + #define USB4_MARGIN_CAP_1_TIME_LR 0x1 58 + #define USB4_MARGIN_CAP_1_TIME_BOTH 0x2 59 + #define USB4_MARGIN_CAP_1_TIME_STEPS_MASK GENMASK(15, 11) 60 + #define USB4_MARGIN_CAP_1_TIME_STEPS_SHIFT 11 61 + #define USB4_MARGIN_CAP_1_TIME_OFFSET_MASK GENMASK(20, 16) 62 + #define USB4_MARGIN_CAP_1_TIME_OFFSET_SHIFT 16 63 + #define USB4_MARGIN_CAP_1_MIN_BER_MASK GENMASK(25, 21) 64 + #define USB4_MARGIN_CAP_1_MIN_BER_SHIFT 21 65 + #define USB4_MARGIN_CAP_1_MAX_BER_MASK GENMASK(30, 26) 66 + #define USB4_MARGIN_CAP_1_MAX_BER_SHIFT 26 67 + #define USB4_MARGIN_CAP_1_MAX_BER_SHIFT 26 68 + 69 + /* USB4_SB_OPCODE_RUN_HW_LANE_MARGINING */ 70 + #define USB4_MARGIN_HW_TIME BIT(3) 71 + #define USB4_MARGIN_HW_RH BIT(4) 72 + #define USB4_MARGIN_HW_BER_MASK GENMASK(9, 5) 73 + #define USB4_MARGIN_HW_BER_SHIFT 5 74 + 75 + /* Applicable to all margin values */ 76 + #define USB4_MARGIN_HW_RES_1_MARGIN_MASK GENMASK(6, 0) 77 + #define USB4_MARGIN_HW_RES_1_EXCEEDS BIT(7) 78 + /* Different lane margin shifts */ 79 + #define USB4_MARGIN_HW_RES_1_L0_LL_MARGIN_SHIFT 8 80 + #define USB4_MARGIN_HW_RES_1_L1_RH_MARGIN_SHIFT 16 81 + #define USB4_MARGIN_HW_RES_1_L1_LL_MARGIN_SHIFT 24 82 + 83 + /* USB4_SB_OPCODE_RUN_SW_LANE_MARGINING */ 84 + #define USB4_MARGIN_SW_TIME BIT(3) 85 + #define USB4_MARGIN_SW_RH BIT(4) 86 + #define USB4_MARGIN_SW_COUNTER_MASK GENMASK(14, 13) 87 + #define USB4_MARGIN_SW_COUNTER_SHIFT 13 88 + #define USB4_MARGIN_SW_COUNTER_NOP 0x0 89 + #define USB4_MARGIN_SW_COUNTER_CLEAR 0x1 90 + #define USB4_MARGIN_SW_COUNTER_START 0x2 91 + #define USB4_MARGIN_SW_COUNTER_STOP 0x3 34 92 35 93 #endif
+223 -226
drivers/thunderbolt/switch.c
··· 19 19 20 20 /* Switch NVM support */ 21 21 22 - #define NVM_CSS 0x10 23 - 24 22 struct nvm_auth_status { 25 23 struct list_head list; 26 24 uuid_t uuid; ··· 100 102 101 103 static int nvm_validate_and_write(struct tb_switch *sw) 102 104 { 103 - unsigned int image_size, hdr_size; 104 - const u8 *buf = sw->nvm->buf; 105 - u16 ds_size; 105 + unsigned int image_size; 106 + const u8 *buf; 106 107 int ret; 107 108 108 - if (!buf) 109 - return -EINVAL; 109 + ret = tb_nvm_validate(sw->nvm); 110 + if (ret) 111 + return ret; 110 112 113 + ret = tb_nvm_write_headers(sw->nvm); 114 + if (ret) 115 + return ret; 116 + 117 + buf = sw->nvm->buf_data_start; 111 118 image_size = sw->nvm->buf_data_size; 112 - if (image_size < NVM_MIN_SIZE || image_size > NVM_MAX_SIZE) 113 - return -EINVAL; 114 - 115 - /* 116 - * FARB pointer must point inside the image and must at least 117 - * contain parts of the digital section we will be reading here. 118 - */ 119 - hdr_size = (*(u32 *)buf) & 0xffffff; 120 - if (hdr_size + NVM_DEVID + 2 >= image_size) 121 - return -EINVAL; 122 - 123 - /* Digital section start should be aligned to 4k page */ 124 - if (!IS_ALIGNED(hdr_size, SZ_4K)) 125 - return -EINVAL; 126 - 127 - /* 128 - * Read digital section size and check that it also fits inside 129 - * the image. 130 - */ 131 - ds_size = *(u16 *)(buf + hdr_size); 132 - if (ds_size >= image_size) 133 - return -EINVAL; 134 - 135 - if (!sw->safe_mode) { 136 - u16 device_id; 137 - 138 - /* 139 - * Make sure the device ID in the image matches the one 140 - * we read from the switch config space. 141 - */ 142 - device_id = *(u16 *)(buf + hdr_size + NVM_DEVID); 143 - if (device_id != sw->config.device_id) 144 - return -EINVAL; 145 - 146 - if (sw->generation < 3) { 147 - /* Write CSS headers first */ 148 - ret = dma_port_flash_write(sw->dma_port, 149 - DMA_PORT_CSS_ADDRESS, buf + NVM_CSS, 150 - DMA_PORT_CSS_MAX_SIZE); 151 - if (ret) 152 - return ret; 153 - } 154 - 155 - /* Skip headers in the image */ 156 - buf += hdr_size; 157 - image_size -= hdr_size; 158 - } 159 119 160 120 if (tb_switch_is_usb4(sw)) 161 121 ret = usb4_switch_nvm_write(sw, 0, buf, image_size); 162 122 else 163 123 ret = dma_port_flash_write(sw->dma_port, 0, buf, image_size); 164 - if (!ret) 165 - sw->nvm->flushed = true; 166 - return ret; 124 + if (ret) 125 + return ret; 126 + 127 + sw->nvm->flushed = true; 128 + return 0; 167 129 } 168 130 169 131 static int nvm_authenticate_host_dma_port(struct tb_switch *sw) ··· 258 300 return nvm_readable(sw); 259 301 } 260 302 261 - static inline int nvm_read(struct tb_switch *sw, unsigned int address, 262 - void *buf, size_t size) 263 - { 264 - if (tb_switch_is_usb4(sw)) 265 - return usb4_switch_nvm_read(sw, address, buf, size); 266 - return dma_port_flash_read(sw->dma_port, address, buf, size); 267 - } 268 - 269 303 static int nvm_authenticate(struct tb_switch *sw, bool auth_only) 270 304 { 271 305 int ret; ··· 285 335 return ret; 286 336 } 287 337 288 - static int tb_switch_nvm_read(void *priv, unsigned int offset, void *val, 289 - size_t bytes) 338 + /** 339 + * tb_switch_nvm_read() - Read router NVM 340 + * @sw: Router whose NVM to read 341 + * @address: Start address on the NVM 342 + * @buf: Buffer where the read data is copied 343 + * @size: Size of the buffer in bytes 344 + * 345 + * Reads from router NVM and returns the requested data in @buf. Locking 346 + * is up to the caller. Returns %0 in success and negative errno in case 347 + * of failure. 348 + */ 349 + int tb_switch_nvm_read(struct tb_switch *sw, unsigned int address, void *buf, 350 + size_t size) 351 + { 352 + if (tb_switch_is_usb4(sw)) 353 + return usb4_switch_nvm_read(sw, address, buf, size); 354 + return dma_port_flash_read(sw->dma_port, address, buf, size); 355 + } 356 + 357 + static int nvm_read(void *priv, unsigned int offset, void *val, size_t bytes) 290 358 { 291 359 struct tb_nvm *nvm = priv; 292 360 struct tb_switch *sw = tb_to_switch(nvm->dev); ··· 317 349 goto out; 318 350 } 319 351 320 - ret = nvm_read(sw, offset, val, bytes); 352 + ret = tb_switch_nvm_read(sw, offset, val, bytes); 321 353 mutex_unlock(&sw->tb->lock); 322 354 323 355 out: ··· 327 359 return ret; 328 360 } 329 361 330 - static int tb_switch_nvm_write(void *priv, unsigned int offset, void *val, 331 - size_t bytes) 362 + static int nvm_write(void *priv, unsigned int offset, void *val, size_t bytes) 332 363 { 333 364 struct tb_nvm *nvm = priv; 334 365 struct tb_switch *sw = tb_to_switch(nvm->dev); ··· 351 384 static int tb_switch_nvm_add(struct tb_switch *sw) 352 385 { 353 386 struct tb_nvm *nvm; 354 - u32 val; 355 387 int ret; 356 388 357 389 if (!nvm_readable(sw)) 358 390 return 0; 359 391 360 - /* 361 - * The NVM format of non-Intel hardware is not known so 362 - * currently restrict NVM upgrade for Intel hardware. We may 363 - * relax this in the future when we learn other NVM formats. 364 - */ 365 - if (sw->config.vendor_id != PCI_VENDOR_ID_INTEL && 366 - sw->config.vendor_id != 0x8087) { 367 - dev_info(&sw->dev, 368 - "NVM format of vendor %#x is not known, disabling NVM upgrade\n", 369 - sw->config.vendor_id); 370 - return 0; 392 + nvm = tb_nvm_alloc(&sw->dev); 393 + if (IS_ERR(nvm)) { 394 + ret = PTR_ERR(nvm) == -EOPNOTSUPP ? 0 : PTR_ERR(nvm); 395 + goto err_nvm; 371 396 } 372 397 373 - nvm = tb_nvm_alloc(&sw->dev); 374 - if (IS_ERR(nvm)) 375 - return PTR_ERR(nvm); 398 + ret = tb_nvm_read_version(nvm); 399 + if (ret) 400 + goto err_nvm; 376 401 377 402 /* 378 403 * If the switch is in safe-mode the only accessible portion of ··· 372 413 * write new functional NVM. 373 414 */ 374 415 if (!sw->safe_mode) { 375 - u32 nvm_size, hdr_size; 376 - 377 - ret = nvm_read(sw, NVM_FLASH_SIZE, &val, sizeof(val)); 378 - if (ret) 379 - goto err_nvm; 380 - 381 - hdr_size = sw->generation < 3 ? SZ_8K : SZ_16K; 382 - nvm_size = (SZ_1M << (val & 7)) / 8; 383 - nvm_size = (nvm_size - hdr_size) / 2; 384 - 385 - ret = nvm_read(sw, NVM_VERSION, &val, sizeof(val)); 386 - if (ret) 387 - goto err_nvm; 388 - 389 - nvm->major = val >> 16; 390 - nvm->minor = val >> 8; 391 - 392 - ret = tb_nvm_add_active(nvm, nvm_size, tb_switch_nvm_read); 416 + ret = tb_nvm_add_active(nvm, nvm_read); 393 417 if (ret) 394 418 goto err_nvm; 395 419 } 396 420 397 421 if (!sw->no_nvm_upgrade) { 398 - ret = tb_nvm_add_non_active(nvm, NVM_MAX_SIZE, 399 - tb_switch_nvm_write); 422 + ret = tb_nvm_add_non_active(nvm, nvm_write); 400 423 if (ret) 401 424 goto err_nvm; 402 425 } ··· 387 446 return 0; 388 447 389 448 err_nvm: 390 - tb_nvm_free(nvm); 449 + tb_sw_dbg(sw, "NVM upgrade disabled\n"); 450 + sw->no_nvm_upgrade = true; 451 + if (!IS_ERR(nvm)) 452 + tb_nvm_free(nvm); 453 + 391 454 return ret; 392 455 } 393 456 ··· 1174 1229 return tb_port_do_update_credits(port->dual_link_port); 1175 1230 } 1176 1231 1232 + static int __tb_port_pm_secondary_set(struct tb_port *port, bool secondary) 1233 + { 1234 + u32 phy; 1235 + int ret; 1236 + 1237 + ret = tb_port_read(port, &phy, TB_CFG_PORT, 1238 + port->cap_phy + LANE_ADP_CS_1, 1); 1239 + if (ret) 1240 + return ret; 1241 + 1242 + if (secondary) 1243 + phy |= LANE_ADP_CS_1_PMS; 1244 + else 1245 + phy &= ~LANE_ADP_CS_1_PMS; 1246 + 1247 + return tb_port_write(port, &phy, TB_CFG_PORT, 1248 + port->cap_phy + LANE_ADP_CS_1, 1); 1249 + } 1250 + 1251 + static int tb_port_pm_secondary_enable(struct tb_port *port) 1252 + { 1253 + return __tb_port_pm_secondary_set(port, true); 1254 + } 1255 + 1256 + static int tb_port_pm_secondary_disable(struct tb_port *port) 1257 + { 1258 + return __tb_port_pm_secondary_set(port, false); 1259 + } 1260 + 1261 + /* Called for USB4 or Titan Ridge routers only */ 1262 + static bool tb_port_clx_supported(struct tb_port *port, unsigned int clx_mask) 1263 + { 1264 + u32 val, mask = 0; 1265 + bool ret; 1266 + 1267 + /* Don't enable CLx in case of two single-lane links */ 1268 + if (!port->bonded && port->dual_link_port) 1269 + return false; 1270 + 1271 + /* Don't enable CLx in case of inter-domain link */ 1272 + if (port->xdomain) 1273 + return false; 1274 + 1275 + if (tb_switch_is_usb4(port->sw)) { 1276 + if (!usb4_port_clx_supported(port)) 1277 + return false; 1278 + } else if (!tb_lc_is_clx_supported(port)) { 1279 + return false; 1280 + } 1281 + 1282 + if (clx_mask & TB_CL1) { 1283 + /* CL0s and CL1 are enabled and supported together */ 1284 + mask |= LANE_ADP_CS_0_CL0S_SUPPORT | LANE_ADP_CS_0_CL1_SUPPORT; 1285 + } 1286 + if (clx_mask & TB_CL2) 1287 + mask |= LANE_ADP_CS_0_CL2_SUPPORT; 1288 + 1289 + ret = tb_port_read(port, &val, TB_CFG_PORT, 1290 + port->cap_phy + LANE_ADP_CS_0, 1); 1291 + if (ret) 1292 + return false; 1293 + 1294 + return !!(val & mask); 1295 + } 1296 + 1297 + static int __tb_port_clx_set(struct tb_port *port, enum tb_clx clx, bool enable) 1298 + { 1299 + u32 phy, mask; 1300 + int ret; 1301 + 1302 + /* CL0s and CL1 are enabled and supported together */ 1303 + if (clx == TB_CL1) 1304 + mask = LANE_ADP_CS_1_CL0S_ENABLE | LANE_ADP_CS_1_CL1_ENABLE; 1305 + else 1306 + /* For now we support only CL0s and CL1. Not CL2 */ 1307 + return -EOPNOTSUPP; 1308 + 1309 + ret = tb_port_read(port, &phy, TB_CFG_PORT, 1310 + port->cap_phy + LANE_ADP_CS_1, 1); 1311 + if (ret) 1312 + return ret; 1313 + 1314 + if (enable) 1315 + phy |= mask; 1316 + else 1317 + phy &= ~mask; 1318 + 1319 + return tb_port_write(port, &phy, TB_CFG_PORT, 1320 + port->cap_phy + LANE_ADP_CS_1, 1); 1321 + } 1322 + 1323 + static int tb_port_clx_disable(struct tb_port *port, enum tb_clx clx) 1324 + { 1325 + return __tb_port_clx_set(port, clx, false); 1326 + } 1327 + 1328 + static int tb_port_clx_enable(struct tb_port *port, enum tb_clx clx) 1329 + { 1330 + return __tb_port_clx_set(port, clx, true); 1331 + } 1332 + 1333 + /** 1334 + * tb_port_is_clx_enabled() - Is given CL state enabled 1335 + * @port: USB4 port to check 1336 + * @clx_mask: Mask of CL states to check 1337 + * 1338 + * Returns true if any of the given CL states is enabled for @port. 1339 + */ 1340 + bool tb_port_is_clx_enabled(struct tb_port *port, unsigned int clx_mask) 1341 + { 1342 + u32 val, mask = 0; 1343 + int ret; 1344 + 1345 + if (!tb_port_clx_supported(port, clx_mask)) 1346 + return false; 1347 + 1348 + if (clx_mask & TB_CL1) 1349 + mask |= LANE_ADP_CS_1_CL0S_ENABLE | LANE_ADP_CS_1_CL1_ENABLE; 1350 + if (clx_mask & TB_CL2) 1351 + mask |= LANE_ADP_CS_1_CL2_ENABLE; 1352 + 1353 + ret = tb_port_read(port, &val, TB_CFG_PORT, 1354 + port->cap_phy + LANE_ADP_CS_1, 1); 1355 + if (ret) 1356 + return false; 1357 + 1358 + return !!(val & mask); 1359 + } 1360 + 1177 1361 static int tb_port_start_lane_initialization(struct tb_port *port) 1178 1362 { 1179 1363 int ret; ··· 1694 1620 { 1695 1621 struct tb_switch *sw = tb_to_switch(dev); 1696 1622 1697 - return sprintf(buf, "%u\n", sw->authorized); 1623 + return sysfs_emit(buf, "%u\n", sw->authorized); 1698 1624 } 1699 1625 1700 1626 static int disapprove_switch(struct device *dev, void *not_used) ··· 1804 1730 { 1805 1731 struct tb_switch *sw = tb_to_switch(dev); 1806 1732 1807 - return sprintf(buf, "%u\n", sw->boot); 1733 + return sysfs_emit(buf, "%u\n", sw->boot); 1808 1734 } 1809 1735 static DEVICE_ATTR_RO(boot); 1810 1736 ··· 1813 1739 { 1814 1740 struct tb_switch *sw = tb_to_switch(dev); 1815 1741 1816 - return sprintf(buf, "%#x\n", sw->device); 1742 + return sysfs_emit(buf, "%#x\n", sw->device); 1817 1743 } 1818 1744 static DEVICE_ATTR_RO(device); 1819 1745 ··· 1822 1748 { 1823 1749 struct tb_switch *sw = tb_to_switch(dev); 1824 1750 1825 - return sprintf(buf, "%s\n", sw->device_name ? sw->device_name : ""); 1751 + return sysfs_emit(buf, "%s\n", sw->device_name ?: ""); 1826 1752 } 1827 1753 static DEVICE_ATTR_RO(device_name); 1828 1754 ··· 1831 1757 { 1832 1758 struct tb_switch *sw = tb_to_switch(dev); 1833 1759 1834 - return sprintf(buf, "%u\n", sw->generation); 1760 + return sysfs_emit(buf, "%u\n", sw->generation); 1835 1761 } 1836 1762 static DEVICE_ATTR_RO(generation); 1837 1763 ··· 1845 1771 return restart_syscall(); 1846 1772 1847 1773 if (sw->key) 1848 - ret = sprintf(buf, "%*phN\n", TB_SWITCH_KEY_SIZE, sw->key); 1774 + ret = sysfs_emit(buf, "%*phN\n", TB_SWITCH_KEY_SIZE, sw->key); 1849 1775 else 1850 - ret = sprintf(buf, "\n"); 1776 + ret = sysfs_emit(buf, "\n"); 1851 1777 1852 1778 mutex_unlock(&sw->tb->lock); 1853 1779 return ret; ··· 1892 1818 { 1893 1819 struct tb_switch *sw = tb_to_switch(dev); 1894 1820 1895 - return sprintf(buf, "%u.0 Gb/s\n", sw->link_speed); 1821 + return sysfs_emit(buf, "%u.0 Gb/s\n", sw->link_speed); 1896 1822 } 1897 1823 1898 1824 /* ··· 1907 1833 { 1908 1834 struct tb_switch *sw = tb_to_switch(dev); 1909 1835 1910 - return sprintf(buf, "%u\n", sw->link_width); 1836 + return sysfs_emit(buf, "%u\n", sw->link_width); 1911 1837 } 1912 1838 1913 1839 /* ··· 1924 1850 u32 status; 1925 1851 1926 1852 nvm_get_auth_status(sw, &status); 1927 - return sprintf(buf, "%#x\n", status); 1853 + return sysfs_emit(buf, "%#x\n", status); 1928 1854 } 1929 1855 1930 1856 static ssize_t nvm_authenticate_sysfs(struct device *dev, const char *buf, ··· 1938 1864 if (!mutex_trylock(&sw->tb->lock)) { 1939 1865 ret = restart_syscall(); 1940 1866 goto exit_rpm; 1867 + } 1868 + 1869 + if (sw->no_nvm_upgrade) { 1870 + ret = -EOPNOTSUPP; 1871 + goto exit_unlock; 1941 1872 } 1942 1873 1943 1874 /* If NVMem devices are not yet added */ ··· 2033 1954 else if (!sw->nvm) 2034 1955 ret = -EAGAIN; 2035 1956 else 2036 - ret = sprintf(buf, "%x.%x\n", sw->nvm->major, sw->nvm->minor); 1957 + ret = sysfs_emit(buf, "%x.%x\n", sw->nvm->major, sw->nvm->minor); 2037 1958 2038 1959 mutex_unlock(&sw->tb->lock); 2039 1960 ··· 2046 1967 { 2047 1968 struct tb_switch *sw = tb_to_switch(dev); 2048 1969 2049 - return sprintf(buf, "%#x\n", sw->vendor); 1970 + return sysfs_emit(buf, "%#x\n", sw->vendor); 2050 1971 } 2051 1972 static DEVICE_ATTR_RO(vendor); 2052 1973 ··· 2055 1976 { 2056 1977 struct tb_switch *sw = tb_to_switch(dev); 2057 1978 2058 - return sprintf(buf, "%s\n", sw->vendor_name ? sw->vendor_name : ""); 1979 + return sysfs_emit(buf, "%s\n", sw->vendor_name ?: ""); 2059 1980 } 2060 1981 static DEVICE_ATTR_RO(vendor_name); 2061 1982 ··· 2064 1985 { 2065 1986 struct tb_switch *sw = tb_to_switch(dev); 2066 1987 2067 - return sprintf(buf, "%pUb\n", sw->uuid); 1988 + return sysfs_emit(buf, "%pUb\n", sw->uuid); 2068 1989 } 2069 1990 static DEVICE_ATTR_RO(unique_id); 2070 1991 ··· 2901 2822 tb_sw_info(sw, "failed to determine preferred buffer allocation, using defaults\n"); 2902 2823 } 2903 2824 2825 + static int tb_switch_port_hotplug_enable(struct tb_switch *sw) 2826 + { 2827 + struct tb_port *port; 2828 + 2829 + if (tb_switch_is_icm(sw)) 2830 + return 0; 2831 + 2832 + tb_switch_for_each_port(sw, port) { 2833 + int res; 2834 + 2835 + if (!port->cap_usb4) 2836 + continue; 2837 + 2838 + res = usb4_port_hotplug_enable(port); 2839 + if (res) 2840 + return res; 2841 + } 2842 + return 0; 2843 + } 2844 + 2904 2845 /** 2905 2846 * tb_switch_add() - Add a switch to the domain 2906 2847 * @sw: Switch to add ··· 2989 2890 if (ret) 2990 2891 return ret; 2991 2892 } 2893 + 2894 + ret = tb_switch_port_hotplug_enable(sw); 2895 + if (ret) 2896 + return ret; 2992 2897 2993 2898 ret = device_add(&sw->dev); 2994 2899 if (ret) { ··· 3465 3362 return NULL; 3466 3363 } 3467 3364 3468 - static int __tb_port_pm_secondary_set(struct tb_port *port, bool secondary) 3469 - { 3470 - u32 phy; 3471 - int ret; 3472 - 3473 - ret = tb_port_read(port, &phy, TB_CFG_PORT, 3474 - port->cap_phy + LANE_ADP_CS_1, 1); 3475 - if (ret) 3476 - return ret; 3477 - 3478 - if (secondary) 3479 - phy |= LANE_ADP_CS_1_PMS; 3480 - else 3481 - phy &= ~LANE_ADP_CS_1_PMS; 3482 - 3483 - return tb_port_write(port, &phy, TB_CFG_PORT, 3484 - port->cap_phy + LANE_ADP_CS_1, 1); 3485 - } 3486 - 3487 - static int tb_port_pm_secondary_enable(struct tb_port *port) 3488 - { 3489 - return __tb_port_pm_secondary_set(port, true); 3490 - } 3491 - 3492 - static int tb_port_pm_secondary_disable(struct tb_port *port) 3493 - { 3494 - return __tb_port_pm_secondary_set(port, false); 3495 - } 3496 - 3497 3365 static int tb_switch_pm_secondary_resolve(struct tb_switch *sw) 3498 3366 { 3499 3367 struct tb_switch *parent = tb_switch_parent(sw); ··· 3481 3407 return ret; 3482 3408 3483 3409 return tb_port_pm_secondary_disable(down); 3484 - } 3485 - 3486 - /* Called for USB4 or Titan Ridge routers only */ 3487 - static bool tb_port_clx_supported(struct tb_port *port, enum tb_clx clx) 3488 - { 3489 - u32 mask, val; 3490 - bool ret; 3491 - 3492 - /* Don't enable CLx in case of two single-lane links */ 3493 - if (!port->bonded && port->dual_link_port) 3494 - return false; 3495 - 3496 - /* Don't enable CLx in case of inter-domain link */ 3497 - if (port->xdomain) 3498 - return false; 3499 - 3500 - if (tb_switch_is_usb4(port->sw)) { 3501 - if (!usb4_port_clx_supported(port)) 3502 - return false; 3503 - } else if (!tb_lc_is_clx_supported(port)) { 3504 - return false; 3505 - } 3506 - 3507 - switch (clx) { 3508 - case TB_CL1: 3509 - /* CL0s and CL1 are enabled and supported together */ 3510 - mask = LANE_ADP_CS_0_CL0S_SUPPORT | LANE_ADP_CS_0_CL1_SUPPORT; 3511 - break; 3512 - 3513 - /* For now we support only CL0s and CL1. Not CL2 */ 3514 - case TB_CL2: 3515 - default: 3516 - return false; 3517 - } 3518 - 3519 - ret = tb_port_read(port, &val, TB_CFG_PORT, 3520 - port->cap_phy + LANE_ADP_CS_0, 1); 3521 - if (ret) 3522 - return false; 3523 - 3524 - return !!(val & mask); 3525 - } 3526 - 3527 - static int __tb_port_clx_set(struct tb_port *port, enum tb_clx clx, bool enable) 3528 - { 3529 - u32 phy, mask; 3530 - int ret; 3531 - 3532 - /* CL0s and CL1 are enabled and supported together */ 3533 - if (clx == TB_CL1) 3534 - mask = LANE_ADP_CS_1_CL0S_ENABLE | LANE_ADP_CS_1_CL1_ENABLE; 3535 - else 3536 - /* For now we support only CL0s and CL1. Not CL2 */ 3537 - return -EOPNOTSUPP; 3538 - 3539 - ret = tb_port_read(port, &phy, TB_CFG_PORT, 3540 - port->cap_phy + LANE_ADP_CS_1, 1); 3541 - if (ret) 3542 - return ret; 3543 - 3544 - if (enable) 3545 - phy |= mask; 3546 - else 3547 - phy &= ~mask; 3548 - 3549 - return tb_port_write(port, &phy, TB_CFG_PORT, 3550 - port->cap_phy + LANE_ADP_CS_1, 1); 3551 - } 3552 - 3553 - static int tb_port_clx_disable(struct tb_port *port, enum tb_clx clx) 3554 - { 3555 - return __tb_port_clx_set(port, clx, false); 3556 - } 3557 - 3558 - static int tb_port_clx_enable(struct tb_port *port, enum tb_clx clx) 3559 - { 3560 - return __tb_port_clx_set(port, clx, true); 3561 3410 } 3562 3411 3563 3412 static int __tb_switch_enable_clx(struct tb_switch *sw, enum tb_clx clx)
+32 -1
drivers/thunderbolt/tb.c
··· 105 105 } 106 106 } 107 107 108 + static void tb_discover_dp_resource(struct tb *tb, struct tb_port *port) 109 + { 110 + struct tb_cm *tcm = tb_priv(tb); 111 + struct tb_port *p; 112 + 113 + list_for_each_entry(p, &tcm->dp_resources, list) { 114 + if (p == port) 115 + return; 116 + } 117 + 118 + tb_port_dbg(port, "DP %s resource available discovered\n", 119 + tb_port_is_dpin(port) ? "IN" : "OUT"); 120 + list_add_tail(&port->list, &tcm->dp_resources); 121 + } 122 + 123 + static void tb_discover_dp_resources(struct tb *tb) 124 + { 125 + struct tb_cm *tcm = tb_priv(tb); 126 + struct tb_tunnel *tunnel; 127 + 128 + list_for_each_entry(tunnel, &tcm->tunnel_list, list) { 129 + if (tb_tunnel_is_dp(tunnel)) 130 + tb_discover_dp_resource(tb, tunnel->dst_port); 131 + } 132 + } 133 + 108 134 static void tb_switch_discover_tunnels(struct tb_switch *sw, 109 135 struct list_head *list, 110 136 bool alloc_hopids) ··· 1442 1416 * ICM firmware upgrade needs running firmware and in native 1443 1417 * mode that is not available so disable firmware upgrade of the 1444 1418 * root switch. 1419 + * 1420 + * However, USB4 routers support NVM firmware upgrade if they 1421 + * implement the necessary router operations. 1445 1422 */ 1446 - tb->root_switch->no_nvm_upgrade = true; 1423 + tb->root_switch->no_nvm_upgrade = !tb_switch_is_usb4(tb->root_switch); 1447 1424 /* All USB4 routers support runtime PM */ 1448 1425 tb->root_switch->rpm = tb_switch_is_usb4(tb->root_switch); 1449 1426 ··· 1475 1446 tb_scan_switch(tb->root_switch); 1476 1447 /* Find out tunnels created by the boot firmware */ 1477 1448 tb_discover_tunnels(tb); 1449 + /* Add DP resources from the DP tunnels created by the boot firmware */ 1450 + tb_discover_dp_resources(tb); 1478 1451 /* 1479 1452 * If the boot firmware did not create USB 3.x tunnels create them 1480 1453 * now for the whole topology.
+44 -12
drivers/thunderbolt/tb.h
··· 23 23 #define NVM_MAX_SIZE SZ_512K 24 24 #define NVM_DATA_DWORDS 16 25 25 26 - /* Intel specific NVM offsets */ 27 - #define NVM_DEVID 0x05 28 - #define NVM_VERSION 0x08 29 - #define NVM_FLASH_SIZE 0x45 30 - 31 26 /** 32 27 * struct tb_nvm - Structure holding NVM information 33 28 * @dev: Owner of the NVM ··· 30 35 * @minor: Minor version number of the active NVM portion 31 36 * @id: Identifier used with both NVM portions 32 37 * @active: Active portion NVMem device 38 + * @active_size: Size in bytes of the active NVM 33 39 * @non_active: Non-active portion NVMem device 34 40 * @buf: Buffer where the NVM image is stored before it is written to 35 41 * the actual NVM flash device 42 + * @buf_data_start: Where the actual image starts after skipping 43 + * possible headers 36 44 * @buf_data_size: Number of bytes actually consumed by the new NVM 37 45 * image 38 46 * @authenticating: The device is authenticating the new NVM 39 47 * @flushed: The image has been flushed to the storage area 48 + * @vops: Router vendor specific NVM operations (optional) 40 49 * 41 50 * The user of this structure needs to handle serialization of possible 42 51 * concurrent access. 43 52 */ 44 53 struct tb_nvm { 45 54 struct device *dev; 46 - u8 major; 47 - u8 minor; 55 + u32 major; 56 + u32 minor; 48 57 int id; 49 58 struct nvmem_device *active; 59 + size_t active_size; 50 60 struct nvmem_device *non_active; 51 61 void *buf; 62 + void *buf_data_start; 52 63 size_t buf_data_size; 53 64 bool authenticating; 54 65 bool flushed; 66 + const struct tb_nvm_vendor_ops *vops; 55 67 }; 56 68 57 69 enum tb_nvm_write_ops { ··· 115 113 enum tb_clx { 116 114 TB_CLX_DISABLE, 117 115 /* CL0s and CL1 are enabled and supported together */ 118 - TB_CL1, 119 - TB_CL2, 116 + TB_CL1 = BIT(0), 117 + TB_CL2 = BIT(1), 120 118 }; 121 119 122 120 /** ··· 281 279 * @can_offline: Does the port have necessary platform support to moved 282 280 * it into offline mode and back 283 281 * @offline: The port is currently in offline mode 282 + * @margining: Pointer to margining structure if enabled 284 283 */ 285 284 struct usb4_port { 286 285 struct device dev; 287 286 struct tb_port *port; 288 287 bool can_offline; 289 288 bool offline; 289 + #ifdef CONFIG_USB4_DEBUGFS_MARGINING 290 + struct tb_margining *margining; 291 + #endif 290 292 }; 291 293 292 294 /** ··· 302 296 * @device: Device ID of the retimer 303 297 * @port: Pointer to the lane 0 adapter 304 298 * @nvm: Pointer to the NVM if the retimer has one (%NULL otherwise) 299 + * @no_nvm_upgrade: Prevent NVM upgrade of this retimer 305 300 * @auth_status: Status of last NVM authentication 306 301 */ 307 302 struct tb_retimer { ··· 313 306 u32 device; 314 307 struct tb_port *port; 315 308 struct tb_nvm *nvm; 309 + bool no_nvm_upgrade; 316 310 u32 auth_status; 317 311 }; 318 312 ··· 745 737 } 746 738 747 739 struct tb_nvm *tb_nvm_alloc(struct device *dev); 748 - int tb_nvm_add_active(struct tb_nvm *nvm, size_t size, nvmem_reg_read_t reg_read); 740 + int tb_nvm_read_version(struct tb_nvm *nvm); 741 + int tb_nvm_validate(struct tb_nvm *nvm); 742 + int tb_nvm_write_headers(struct tb_nvm *nvm); 743 + int tb_nvm_add_active(struct tb_nvm *nvm, nvmem_reg_read_t reg_read); 749 744 int tb_nvm_write_buf(struct tb_nvm *nvm, unsigned int offset, void *val, 750 745 size_t bytes); 751 - int tb_nvm_add_non_active(struct tb_nvm *nvm, size_t size, 752 - nvmem_reg_write_t reg_write); 746 + int tb_nvm_add_non_active(struct tb_nvm *nvm, nvmem_reg_write_t reg_write); 753 747 void tb_nvm_free(struct tb_nvm *nvm); 754 748 void tb_nvm_exit(void); 755 749 ··· 765 755 unsigned int retries, write_block_fn write_next_block, 766 756 void *write_block_data); 767 757 758 + int tb_switch_nvm_read(struct tb_switch *sw, unsigned int address, void *buf, 759 + size_t size); 768 760 struct tb_switch *tb_switch_alloc(struct tb *tb, struct device *parent, 769 761 u64 route); 770 762 struct tb_switch *tb_switch_alloc_safe_mode(struct tb *tb, ··· 1047 1035 int tb_port_wait_for_link_width(struct tb_port *port, int width, 1048 1036 int timeout_msec); 1049 1037 int tb_port_update_credits(struct tb_port *port); 1038 + bool tb_port_is_clx_enabled(struct tb_port *port, enum tb_clx clx); 1050 1039 1051 1040 int tb_switch_find_vse_cap(struct tb_switch *sw, enum tb_switch_vse_cap vsec); 1052 1041 int tb_switch_find_cap(struct tb_switch *sw, enum tb_switch_cap cap); ··· 1145 1132 struct tb_xdomain *tb_xdomain_find_by_link_depth(struct tb *tb, u8 link, 1146 1133 u8 depth); 1147 1134 1135 + static inline struct tb_switch *tb_xdomain_parent(struct tb_xdomain *xd) 1136 + { 1137 + return tb_to_switch(xd->dev.parent); 1138 + } 1139 + 1140 + int tb_retimer_nvm_read(struct tb_retimer *rt, unsigned int address, void *buf, 1141 + size_t size); 1148 1142 int tb_retimer_scan(struct tb_port *port, bool add); 1149 1143 void tb_retimer_remove_all(struct tb_port *port); 1150 1144 ··· 1194 1174 void usb4_switch_remove_ports(struct tb_switch *sw); 1195 1175 1196 1176 int usb4_port_unlock(struct tb_port *port); 1177 + int usb4_port_hotplug_enable(struct tb_port *port); 1197 1178 int usb4_port_configure(struct tb_port *port); 1198 1179 void usb4_port_unconfigure(struct tb_port *port); 1199 1180 int usb4_port_configure_xdomain(struct tb_port *port, struct tb_xdomain *xd); ··· 1203 1182 int usb4_port_router_online(struct tb_port *port); 1204 1183 int usb4_port_enumerate_retimers(struct tb_port *port); 1205 1184 bool usb4_port_clx_supported(struct tb_port *port); 1185 + int usb4_port_margining_caps(struct tb_port *port, u32 *caps); 1186 + int usb4_port_hw_margin(struct tb_port *port, unsigned int lanes, 1187 + unsigned int ber_level, bool timing, bool right_high, 1188 + u32 *results); 1189 + int usb4_port_sw_margin(struct tb_port *port, unsigned int lanes, bool timing, 1190 + bool right_high, u32 counter); 1191 + int usb4_port_sw_margin_errors(struct tb_port *port, u32 *errors); 1206 1192 1207 1193 int usb4_port_retimer_set_inbound_sbtx(struct tb_port *port, u8 index); 1208 1194 int usb4_port_retimer_read(struct tb_port *port, u8 index, u8 reg, void *buf, ··· 1292 1264 void tb_debugfs_exit(void); 1293 1265 void tb_switch_debugfs_init(struct tb_switch *sw); 1294 1266 void tb_switch_debugfs_remove(struct tb_switch *sw); 1267 + void tb_xdomain_debugfs_init(struct tb_xdomain *xd); 1268 + void tb_xdomain_debugfs_remove(struct tb_xdomain *xd); 1295 1269 void tb_service_debugfs_init(struct tb_service *svc); 1296 1270 void tb_service_debugfs_remove(struct tb_service *svc); 1297 1271 #else ··· 1301 1271 static inline void tb_debugfs_exit(void) { } 1302 1272 static inline void tb_switch_debugfs_init(struct tb_switch *sw) { } 1303 1273 static inline void tb_switch_debugfs_remove(struct tb_switch *sw) { } 1274 + static inline void tb_xdomain_debugfs_init(struct tb_xdomain *xd) { } 1275 + static inline void tb_xdomain_debugfs_remove(struct tb_xdomain *xd) { } 1304 1276 static inline void tb_service_debugfs_init(struct tb_service *svc) { } 1305 1277 static inline void tb_service_debugfs_remove(struct tb_service *svc) { } 1306 1278 #endif
+3
drivers/thunderbolt/tb_regs.h
··· 308 308 #define ADP_CS_5 0x05 309 309 #define ADP_CS_5_LCA_MASK GENMASK(28, 22) 310 310 #define ADP_CS_5_LCA_SHIFT 22 311 + #define ADP_CS_5_DHP BIT(31) 311 312 312 313 /* TMU adapter registers */ 313 314 #define TMU_ADP_CS_3 0x03 ··· 325 324 #define LANE_ADP_CS_0_SUPPORTED_WIDTH_DUAL 0x2 326 325 #define LANE_ADP_CS_0_CL0S_SUPPORT BIT(26) 327 326 #define LANE_ADP_CS_0_CL1_SUPPORT BIT(27) 327 + #define LANE_ADP_CS_0_CL2_SUPPORT BIT(28) 328 328 #define LANE_ADP_CS_1 0x01 329 329 #define LANE_ADP_CS_1_TARGET_SPEED_MASK GENMASK(3, 0) 330 330 #define LANE_ADP_CS_1_TARGET_SPEED_GEN3 0xc ··· 335 333 #define LANE_ADP_CS_1_TARGET_WIDTH_DUAL 0x3 336 334 #define LANE_ADP_CS_1_CL0S_ENABLE BIT(10) 337 335 #define LANE_ADP_CS_1_CL1_ENABLE BIT(11) 336 + #define LANE_ADP_CS_1_CL2_ENABLE BIT(12) 338 337 #define LANE_ADP_CS_1_LD BIT(14) 339 338 #define LANE_ADP_CS_1_LB BIT(15) 340 339 #define LANE_ADP_CS_1_CURRENT_SPEED_MASK GENMASK(19, 16)
+140
drivers/thunderbolt/usb4.c
··· 1046 1046 return tb_port_write(port, &val, TB_CFG_PORT, ADP_CS_4, 1); 1047 1047 } 1048 1048 1049 + /** 1050 + * usb4_port_hotplug_enable() - Enables hotplug for a port 1051 + * @port: USB4 port to operate on 1052 + * 1053 + * Enables hot plug events on a given port. This is only intended 1054 + * to be used on lane, DP-IN, and DP-OUT adapters. 1055 + */ 1056 + int usb4_port_hotplug_enable(struct tb_port *port) 1057 + { 1058 + int ret; 1059 + u32 val; 1060 + 1061 + ret = tb_port_read(port, &val, TB_CFG_PORT, ADP_CS_5, 1); 1062 + if (ret) 1063 + return ret; 1064 + 1065 + val &= ~ADP_CS_5_DHP; 1066 + return tb_port_write(port, &val, TB_CFG_PORT, ADP_CS_5, 1); 1067 + } 1068 + 1049 1069 static int usb4_port_set_configured(struct tb_port *port, bool configured) 1050 1070 { 1051 1071 int ret; ··· 1404 1384 return false; 1405 1385 1406 1386 return !!(val & PORT_CS_18_CPS); 1387 + } 1388 + 1389 + /** 1390 + * usb4_port_margining_caps() - Read USB4 port marginig capabilities 1391 + * @port: USB4 port 1392 + * @caps: Array with at least two elements to hold the results 1393 + * 1394 + * Reads the USB4 port lane margining capabilities into @caps. 1395 + */ 1396 + int usb4_port_margining_caps(struct tb_port *port, u32 *caps) 1397 + { 1398 + int ret; 1399 + 1400 + ret = usb4_port_sb_op(port, USB4_SB_TARGET_ROUTER, 0, 1401 + USB4_SB_OPCODE_READ_LANE_MARGINING_CAP, 500); 1402 + if (ret) 1403 + return ret; 1404 + 1405 + return usb4_port_sb_read(port, USB4_SB_TARGET_ROUTER, 0, 1406 + USB4_SB_DATA, caps, sizeof(*caps) * 2); 1407 + } 1408 + 1409 + /** 1410 + * usb4_port_hw_margin() - Run hardware lane margining on port 1411 + * @port: USB4 port 1412 + * @lanes: Which lanes to run (must match the port capabilities). Can be 1413 + * %0, %1 or %7. 1414 + * @ber_level: BER level contour value 1415 + * @timing: Perform timing margining instead of voltage 1416 + * @right_high: Use Right/high margin instead of left/low 1417 + * @results: Array with at least two elements to hold the results 1418 + * 1419 + * Runs hardware lane margining on USB4 port and returns the result in 1420 + * @results. 1421 + */ 1422 + int usb4_port_hw_margin(struct tb_port *port, unsigned int lanes, 1423 + unsigned int ber_level, bool timing, bool right_high, 1424 + u32 *results) 1425 + { 1426 + u32 val; 1427 + int ret; 1428 + 1429 + val = lanes; 1430 + if (timing) 1431 + val |= USB4_MARGIN_HW_TIME; 1432 + if (right_high) 1433 + val |= USB4_MARGIN_HW_RH; 1434 + if (ber_level) 1435 + val |= (ber_level << USB4_MARGIN_HW_BER_SHIFT) & 1436 + USB4_MARGIN_HW_BER_MASK; 1437 + 1438 + ret = usb4_port_sb_write(port, USB4_SB_TARGET_ROUTER, 0, 1439 + USB4_SB_METADATA, &val, sizeof(val)); 1440 + if (ret) 1441 + return ret; 1442 + 1443 + ret = usb4_port_sb_op(port, USB4_SB_TARGET_ROUTER, 0, 1444 + USB4_SB_OPCODE_RUN_HW_LANE_MARGINING, 2500); 1445 + if (ret) 1446 + return ret; 1447 + 1448 + return usb4_port_sb_read(port, USB4_SB_TARGET_ROUTER, 0, 1449 + USB4_SB_DATA, results, sizeof(*results) * 2); 1450 + } 1451 + 1452 + /** 1453 + * usb4_port_sw_margin() - Run software lane margining on port 1454 + * @port: USB4 port 1455 + * @lanes: Which lanes to run (must match the port capabilities). Can be 1456 + * %0, %1 or %7. 1457 + * @timing: Perform timing margining instead of voltage 1458 + * @right_high: Use Right/high margin instead of left/low 1459 + * @counter: What to do with the error counter 1460 + * 1461 + * Runs software lane margining on USB4 port. Read back the error 1462 + * counters by calling usb4_port_sw_margin_errors(). Returns %0 in 1463 + * success and negative errno otherwise. 1464 + */ 1465 + int usb4_port_sw_margin(struct tb_port *port, unsigned int lanes, bool timing, 1466 + bool right_high, u32 counter) 1467 + { 1468 + u32 val; 1469 + int ret; 1470 + 1471 + val = lanes; 1472 + if (timing) 1473 + val |= USB4_MARGIN_SW_TIME; 1474 + if (right_high) 1475 + val |= USB4_MARGIN_SW_RH; 1476 + val |= (counter << USB4_MARGIN_SW_COUNTER_SHIFT) & 1477 + USB4_MARGIN_SW_COUNTER_MASK; 1478 + 1479 + ret = usb4_port_sb_write(port, USB4_SB_TARGET_ROUTER, 0, 1480 + USB4_SB_METADATA, &val, sizeof(val)); 1481 + if (ret) 1482 + return ret; 1483 + 1484 + return usb4_port_sb_op(port, USB4_SB_TARGET_ROUTER, 0, 1485 + USB4_SB_OPCODE_RUN_SW_LANE_MARGINING, 2500); 1486 + } 1487 + 1488 + /** 1489 + * usb4_port_sw_margin_errors() - Read the software margining error counters 1490 + * @port: USB4 port 1491 + * @errors: Error metadata is copied here. 1492 + * 1493 + * This reads back the software margining error counters from the port. 1494 + * Returns %0 in success and negative errno otherwise. 1495 + */ 1496 + int usb4_port_sw_margin_errors(struct tb_port *port, u32 *errors) 1497 + { 1498 + int ret; 1499 + 1500 + ret = usb4_port_sb_op(port, USB4_SB_TARGET_ROUTER, 0, 1501 + USB4_SB_OPCODE_READ_SW_MARGIN_ERR, 150); 1502 + if (ret) 1503 + return ret; 1504 + 1505 + return usb4_port_sb_read(port, USB4_SB_TARGET_ROUTER, 0, 1506 + USB4_SB_METADATA, errors, sizeof(*errors)); 1407 1507 } 1408 1508 1409 1509 static inline int usb4_port_retimer_op(struct tb_port *port, u8 index,
+17 -18
drivers/thunderbolt/xdomain.c
··· 877 877 * It should be null terminated but anything else is pretty much 878 878 * allowed. 879 879 */ 880 - return sprintf(buf, "%*pE\n", (int)strlen(svc->key), svc->key); 880 + return sysfs_emit(buf, "%*pE\n", (int)strlen(svc->key), svc->key); 881 881 } 882 882 static DEVICE_ATTR_RO(key); 883 883 ··· 903 903 { 904 904 struct tb_service *svc = container_of(dev, struct tb_service, dev); 905 905 906 - return sprintf(buf, "%u\n", svc->prtcid); 906 + return sysfs_emit(buf, "%u\n", svc->prtcid); 907 907 } 908 908 static DEVICE_ATTR_RO(prtcid); 909 909 ··· 912 912 { 913 913 struct tb_service *svc = container_of(dev, struct tb_service, dev); 914 914 915 - return sprintf(buf, "%u\n", svc->prtcvers); 915 + return sysfs_emit(buf, "%u\n", svc->prtcvers); 916 916 } 917 917 static DEVICE_ATTR_RO(prtcvers); 918 918 ··· 921 921 { 922 922 struct tb_service *svc = container_of(dev, struct tb_service, dev); 923 923 924 - return sprintf(buf, "%u\n", svc->prtcrevs); 924 + return sysfs_emit(buf, "%u\n", svc->prtcrevs); 925 925 } 926 926 static DEVICE_ATTR_RO(prtcrevs); 927 927 ··· 930 930 { 931 931 struct tb_service *svc = container_of(dev, struct tb_service, dev); 932 932 933 - return sprintf(buf, "0x%08x\n", svc->prtcstns); 933 + return sysfs_emit(buf, "0x%08x\n", svc->prtcstns); 934 934 } 935 935 static DEVICE_ATTR_RO(prtcstns); 936 936 ··· 1129 1129 xd->vendor_name = kstrdup(p->value.text, GFP_KERNEL); 1130 1130 1131 1131 return 0; 1132 - } 1133 - 1134 - static inline struct tb_switch *tb_xdomain_parent(struct tb_xdomain *xd) 1135 - { 1136 - return tb_to_switch(xd->dev.parent); 1137 1132 } 1138 1133 1139 1134 static int tb_xdomain_update_link_attributes(struct tb_xdomain *xd) ··· 1435 1440 if (xd->vendor_name && xd->device_name) 1436 1441 dev_info(&xd->dev, "%s %s\n", xd->vendor_name, 1437 1442 xd->device_name); 1443 + 1444 + tb_xdomain_debugfs_init(xd); 1438 1445 } else { 1439 1446 kobject_uevent(&xd->dev.kobj, KOBJ_CHANGE); 1440 1447 } ··· 1661 1664 { 1662 1665 struct tb_xdomain *xd = container_of(dev, struct tb_xdomain, dev); 1663 1666 1664 - return sprintf(buf, "%#x\n", xd->device); 1667 + return sysfs_emit(buf, "%#x\n", xd->device); 1665 1668 } 1666 1669 static DEVICE_ATTR_RO(device); 1667 1670 ··· 1673 1676 1674 1677 if (mutex_lock_interruptible(&xd->lock)) 1675 1678 return -ERESTARTSYS; 1676 - ret = sprintf(buf, "%s\n", xd->device_name ? xd->device_name : ""); 1679 + ret = sysfs_emit(buf, "%s\n", xd->device_name ?: ""); 1677 1680 mutex_unlock(&xd->lock); 1678 1681 1679 1682 return ret; ··· 1685 1688 { 1686 1689 struct tb_xdomain *xd = container_of(dev, struct tb_xdomain, dev); 1687 1690 1688 - return sprintf(buf, "%d\n", xd->remote_max_hopid); 1691 + return sysfs_emit(buf, "%d\n", xd->remote_max_hopid); 1689 1692 } 1690 1693 static DEVICE_ATTR_RO(maxhopid); 1691 1694 ··· 1694 1697 { 1695 1698 struct tb_xdomain *xd = container_of(dev, struct tb_xdomain, dev); 1696 1699 1697 - return sprintf(buf, "%#x\n", xd->vendor); 1700 + return sysfs_emit(buf, "%#x\n", xd->vendor); 1698 1701 } 1699 1702 static DEVICE_ATTR_RO(vendor); 1700 1703 ··· 1706 1709 1707 1710 if (mutex_lock_interruptible(&xd->lock)) 1708 1711 return -ERESTARTSYS; 1709 - ret = sprintf(buf, "%s\n", xd->vendor_name ? xd->vendor_name : ""); 1712 + ret = sysfs_emit(buf, "%s\n", xd->vendor_name ?: ""); 1710 1713 mutex_unlock(&xd->lock); 1711 1714 1712 1715 return ret; ··· 1718 1721 { 1719 1722 struct tb_xdomain *xd = container_of(dev, struct tb_xdomain, dev); 1720 1723 1721 - return sprintf(buf, "%pUb\n", xd->remote_uuid); 1724 + return sysfs_emit(buf, "%pUb\n", xd->remote_uuid); 1722 1725 } 1723 1726 static DEVICE_ATTR_RO(unique_id); 1724 1727 ··· 1727 1730 { 1728 1731 struct tb_xdomain *xd = container_of(dev, struct tb_xdomain, dev); 1729 1732 1730 - return sprintf(buf, "%u.0 Gb/s\n", xd->link_speed); 1733 + return sysfs_emit(buf, "%u.0 Gb/s\n", xd->link_speed); 1731 1734 } 1732 1735 1733 1736 static DEVICE_ATTR(rx_speed, 0444, speed_show, NULL); ··· 1738 1741 { 1739 1742 struct tb_xdomain *xd = container_of(dev, struct tb_xdomain, dev); 1740 1743 1741 - return sprintf(buf, "%u\n", xd->link_width); 1744 + return sysfs_emit(buf, "%u\n", xd->link_width); 1742 1745 } 1743 1746 1744 1747 static DEVICE_ATTR(rx_lanes, 0444, lanes_show, NULL); ··· 1937 1940 */ 1938 1941 void tb_xdomain_remove(struct tb_xdomain *xd) 1939 1942 { 1943 + tb_xdomain_debugfs_remove(xd); 1944 + 1940 1945 stop_handshake(xd); 1941 1946 1942 1947 device_for_each_child_reverse(&xd->dev, xd, unregister_service);
+1 -1
drivers/usb/atm/usbatm.c
··· 1026 1026 /* public fields */ 1027 1027 1028 1028 instance->driver = driver; 1029 - strlcpy(instance->driver_name, driver->driver_name, 1029 + strscpy(instance->driver_name, driver->driver_name, 1030 1030 sizeof(instance->driver_name)); 1031 1031 1032 1032 instance->usb_dev = usb_dev;
-2
drivers/usb/cdns3/cdns3-plat.c
··· 110 110 cdns->wakeup_irq = platform_get_irq_byname_optional(pdev, "wakeup"); 111 111 if (cdns->wakeup_irq == -EPROBE_DEFER) 112 112 return cdns->wakeup_irq; 113 - else if (cdns->wakeup_irq == 0) 114 - return -EINVAL; 115 113 116 114 if (cdns->wakeup_irq < 0) { 117 115 dev_dbg(dev, "couldn't get wakeup irq\n");
+5 -5
drivers/usb/chipidea/Kconfig
··· 34 34 ChipIdea driver. 35 35 36 36 config USB_CHIPIDEA_PCI 37 - tristate "Enable PCI glue driver" if EMBEDDED 37 + tristate "Enable PCI glue driver" if EXPERT 38 38 depends on USB_PCI 39 39 depends on NOP_USB_XCEIV 40 40 default USB_CHIPIDEA 41 41 42 42 config USB_CHIPIDEA_MSM 43 - tristate "Enable MSM hsusb glue driver" if EMBEDDED 43 + tristate "Enable MSM hsusb glue driver" if EXPERT 44 44 default USB_CHIPIDEA 45 45 46 46 config USB_CHIPIDEA_IMX 47 - tristate "Enable i.MX USB glue driver" if EMBEDDED 47 + tristate "Enable i.MX USB glue driver" if EXPERT 48 48 depends on OF 49 49 default USB_CHIPIDEA 50 50 51 51 config USB_CHIPIDEA_GENERIC 52 - tristate "Enable generic USB2 glue driver" if EMBEDDED 52 + tristate "Enable generic USB2 glue driver" if EXPERT 53 53 default USB_CHIPIDEA 54 54 55 55 config USB_CHIPIDEA_TEGRA 56 - tristate "Enable Tegra USB glue driver" if EMBEDDED 56 + tristate "Enable Tegra USB glue driver" if EXPERT 57 57 depends on OF 58 58 default USB_CHIPIDEA 59 59
+1
drivers/usb/chipidea/ci_hdrc_usb2.c
··· 30 30 31 31 static const struct ci_hdrc_platform_data ci_zynq_pdata = { 32 32 .capoffset = DEF_CAPOFFSET, 33 + .flags = CI_HDRC_PHY_VBUS_CONTROL, 33 34 }; 34 35 35 36 static const struct ci_hdrc_platform_data ci_zevio_pdata = {
+7
drivers/usb/chipidea/host.c
··· 63 63 priv->enabled = enable; 64 64 } 65 65 66 + if (ci->platdata->flags & CI_HDRC_PHY_VBUS_CONTROL) { 67 + if (enable) 68 + usb_phy_vbus_on(ci->usb_phy); 69 + else 70 + usb_phy_vbus_off(ci->usb_phy); 71 + } 72 + 66 73 if (enable && (ci->platdata->phy_mode == USBPHY_INTERFACE_MODE_HSIC)) { 67 74 /* 68 75 * Marvell 28nm HSIC PHY requires forcing the port to HS mode.
+7
drivers/usb/chipidea/otg_fsm.c
··· 471 471 return; 472 472 } 473 473 } 474 + 475 + if (ci->platdata->flags & CI_HDRC_PHY_VBUS_CONTROL) 476 + usb_phy_vbus_on(ci->usb_phy); 477 + 474 478 /* Disable data pulse irq */ 475 479 hw_write_otgsc(ci, OTGSC_DPIE, 0); 476 480 ··· 483 479 } else { 484 480 if (ci->platdata->reg_vbus) 485 481 regulator_disable(ci->platdata->reg_vbus); 482 + 483 + if (ci->platdata->flags & CI_HDRC_PHY_VBUS_CONTROL) 484 + usb_phy_vbus_off(ci->usb_phy); 486 485 487 486 fsm->a_bus_drop = 1; 488 487 fsm->a_bus_req = 0;
+1 -1
drivers/usb/class/cdc-wdm.c
··· 958 958 if (!skb) 959 959 return; 960 960 961 - memcpy(skb_put(skb, length), desc->inbuf, length); 961 + skb_put_data(skb, desc->inbuf, length); 962 962 wwan_port_rx(port, skb); 963 963 964 964 /* inbuf has been copied, it is safe to check for outstanding data */
+64 -32
drivers/usb/common/debug.c
··· 208 208 snprintf(str, size, "Set Isochronous Delay(Delay = %d ns)", wValue); 209 209 } 210 210 211 - /** 212 - * usb_decode_ctrl - Returns human readable representation of control request. 213 - * @str: buffer to return a human-readable representation of control request. 214 - * This buffer should have about 200 bytes. 215 - * @size: size of str buffer. 216 - * @bRequestType: matches the USB bmRequestType field 217 - * @bRequest: matches the USB bRequest field 218 - * @wValue: matches the USB wValue field (CPU byte order) 219 - * @wIndex: matches the USB wIndex field (CPU byte order) 220 - * @wLength: matches the USB wLength field (CPU byte order) 221 - * 222 - * Function returns decoded, formatted and human-readable description of 223 - * control request packet. 224 - * 225 - * The usage scenario for this is for tracepoints, so function as a return 226 - * use the same value as in parameters. This approach allows to use this 227 - * function in TP_printk 228 - * 229 - * Important: wValue, wIndex, wLength parameters before invoking this function 230 - * should be processed by le16_to_cpu macro. 231 - */ 232 - const char *usb_decode_ctrl(char *str, size_t size, __u8 bRequestType, 233 - __u8 bRequest, __u16 wValue, __u16 wIndex, 234 - __u16 wLength) 211 + static void usb_decode_ctrl_generic(char *str, size_t size, __u8 bRequestType, 212 + __u8 bRequest, __u16 wValue, __u16 wIndex, 213 + __u16 wLength) 214 + { 215 + u8 recip = bRequestType & USB_RECIP_MASK; 216 + u8 type = bRequestType & USB_TYPE_MASK; 217 + 218 + snprintf(str, size, 219 + "Type=%s Recipient=%s Dir=%s bRequest=%u wValue=%u wIndex=%u wLength=%u", 220 + (type == USB_TYPE_STANDARD) ? "Standard" : 221 + (type == USB_TYPE_VENDOR) ? "Vendor" : 222 + (type == USB_TYPE_CLASS) ? "Class" : "Unknown", 223 + (recip == USB_RECIP_DEVICE) ? "Device" : 224 + (recip == USB_RECIP_INTERFACE) ? "Interface" : 225 + (recip == USB_RECIP_ENDPOINT) ? "Endpoint" : "Unknown", 226 + (bRequestType & USB_DIR_IN) ? "IN" : "OUT", 227 + bRequest, wValue, wIndex, wLength); 228 + } 229 + 230 + static void usb_decode_ctrl_standard(char *str, size_t size, __u8 bRequestType, 231 + __u8 bRequest, __u16 wValue, __u16 wIndex, 232 + __u16 wLength) 235 233 { 236 234 switch (bRequest) { 237 235 case USB_REQ_GET_STATUS: ··· 270 272 usb_decode_set_isoch_delay(wValue, str, size); 271 273 break; 272 274 default: 273 - snprintf(str, size, "%02x %02x %02x %02x %02x %02x %02x %02x", 274 - bRequestType, bRequest, 275 - (u8)(cpu_to_le16(wValue) & 0xff), 276 - (u8)(cpu_to_le16(wValue) >> 8), 277 - (u8)(cpu_to_le16(wIndex) & 0xff), 278 - (u8)(cpu_to_le16(wIndex) >> 8), 279 - (u8)(cpu_to_le16(wLength) & 0xff), 280 - (u8)(cpu_to_le16(wLength) >> 8)); 275 + usb_decode_ctrl_generic(str, size, bRequestType, bRequest, 276 + wValue, wIndex, wLength); 277 + break; 278 + } 279 + } 280 + 281 + /** 282 + * usb_decode_ctrl - Returns human readable representation of control request. 283 + * @str: buffer to return a human-readable representation of control request. 284 + * This buffer should have about 200 bytes. 285 + * @size: size of str buffer. 286 + * @bRequestType: matches the USB bmRequestType field 287 + * @bRequest: matches the USB bRequest field 288 + * @wValue: matches the USB wValue field (CPU byte order) 289 + * @wIndex: matches the USB wIndex field (CPU byte order) 290 + * @wLength: matches the USB wLength field (CPU byte order) 291 + * 292 + * Function returns decoded, formatted and human-readable description of 293 + * control request packet. 294 + * 295 + * The usage scenario for this is for tracepoints, so function as a return 296 + * use the same value as in parameters. This approach allows to use this 297 + * function in TP_printk 298 + * 299 + * Important: wValue, wIndex, wLength parameters before invoking this function 300 + * should be processed by le16_to_cpu macro. 301 + */ 302 + const char *usb_decode_ctrl(char *str, size_t size, __u8 bRequestType, 303 + __u8 bRequest, __u16 wValue, __u16 wIndex, 304 + __u16 wLength) 305 + { 306 + switch (bRequestType & USB_TYPE_MASK) { 307 + case USB_TYPE_STANDARD: 308 + usb_decode_ctrl_standard(str, size, bRequestType, bRequest, 309 + wValue, wIndex, wLength); 310 + break; 311 + case USB_TYPE_VENDOR: 312 + case USB_TYPE_CLASS: 313 + default: 314 + usb_decode_ctrl_generic(str, size, bRequestType, bRequest, 315 + wValue, wIndex, wLength); 316 + break; 281 317 } 282 318 283 319 return str;
+3 -17
drivers/usb/common/ulpi.c
··· 233 233 return 0; 234 234 } 235 235 236 - static int ulpi_regs_read(struct seq_file *seq, void *data) 236 + static int ulpi_regs_show(struct seq_file *seq, void *data) 237 237 { 238 238 struct ulpi *ulpi = seq->private; 239 239 ··· 269 269 270 270 return 0; 271 271 } 272 - 273 - static int ulpi_regs_open(struct inode *inode, struct file *f) 274 - { 275 - struct ulpi *ulpi = inode->i_private; 276 - 277 - return single_open(f, ulpi_regs_read, ulpi); 278 - } 279 - 280 - static const struct file_operations ulpi_regs_ops = { 281 - .owner = THIS_MODULE, 282 - .open = ulpi_regs_open, 283 - .release = single_release, 284 - .read = seq_read, 285 - .llseek = seq_lseek 286 - }; 272 + DEFINE_SHOW_ATTRIBUTE(ulpi_regs); 287 273 288 274 #define ULPI_ROOT debugfs_lookup(KBUILD_MODNAME, NULL) 289 275 ··· 302 316 } 303 317 304 318 root = debugfs_create_dir(dev_name(dev), ULPI_ROOT); 305 - debugfs_create_file("regs", 0444, root, ulpi, &ulpi_regs_ops); 319 + debugfs_create_file("regs", 0444, root, ulpi, &ulpi_regs_fops); 306 320 307 321 dev_dbg(&ulpi->dev, "registered ULPI PHY: vendor %04x, product %04x\n", 308 322 ulpi->id.vendor, ulpi->id.product);
+2 -4
drivers/usb/common/usb-conn-gpio.c
··· 208 208 if (PTR_ERR(info->vbus) == -ENODEV) 209 209 info->vbus = NULL; 210 210 211 - if (IS_ERR(info->vbus)) { 212 - ret = PTR_ERR(info->vbus); 213 - return dev_err_probe(dev, ret, "failed to get vbus :%d\n", ret); 214 - } 211 + if (IS_ERR(info->vbus)) 212 + return dev_err_probe(dev, PTR_ERR(info->vbus), "failed to get vbus\n"); 215 213 216 214 info->role_sw = usb_role_switch_get(dev); 217 215 if (IS_ERR(info->role_sw))
+1 -1
drivers/usb/core/devio.c
··· 1434 1434 if (!intf || !intf->dev.driver) 1435 1435 ret = -ENODATA; 1436 1436 else { 1437 - strlcpy(gd.driver, intf->dev.driver->name, 1437 + strscpy(gd.driver, intf->dev.driver->name, 1438 1438 sizeof(gd.driver)); 1439 1439 ret = (copy_to_user(arg, &gd, sizeof(gd)) ? -EFAULT : 0); 1440 1440 }
+1 -6
drivers/usb/core/hcd-pci.c
··· 157 157 /** 158 158 * usb_hcd_pci_probe - initialize PCI-based HCDs 159 159 * @dev: USB Host Controller being probed 160 - * @id: pci hotplug id connecting controller to HCD framework 161 160 * @driver: USB HC driver handle 162 161 * 163 162 * Context: task context, might sleep ··· 169 170 * 170 171 * Return: 0 if successful. 171 172 */ 172 - int usb_hcd_pci_probe(struct pci_dev *dev, const struct pci_device_id *id, 173 - const struct hc_driver *driver) 173 + int usb_hcd_pci_probe(struct pci_dev *dev, const struct hc_driver *driver) 174 174 { 175 175 struct usb_hcd *hcd; 176 176 int retval; ··· 177 179 178 180 if (usb_disabled()) 179 181 return -ENODEV; 180 - 181 - if (!id) 182 - return -EINVAL; 183 182 184 183 if (!driver) 185 184 return -EINVAL;
+2 -9
drivers/usb/core/hcd.c
··· 1474 1474 urb->sg, 1475 1475 urb->num_sgs, 1476 1476 dir); 1477 - if (n <= 0) 1477 + if (!n) 1478 1478 ret = -EAGAIN; 1479 1479 else 1480 1480 urb->transfer_flags |= URB_DMA_MAP_SG; ··· 2158 2158 { 2159 2159 struct urb *urb; 2160 2160 struct usb_hcd *hcd = bus_to_hcd(udev->bus); 2161 - struct usb_host_endpoint *ep; 2162 2161 2163 2162 urb = usb_alloc_urb(0, GFP_KERNEL); 2164 2163 if (!urb) 2165 2164 return NULL; 2166 2165 2167 2166 urb->pipe = usb_rcvctrlpipe(udev, 0); 2168 - ep = (usb_pipein(urb->pipe) ? udev->ep_in : udev->ep_out) 2169 - [usb_pipeendpoint(urb->pipe)]; 2170 - if (!ep) { 2171 - usb_free_urb(urb); 2172 - return NULL; 2173 - } 2174 2167 2175 - urb->ep = ep; 2168 + urb->ep = &udev->ep0; 2176 2169 urb->dev = udev; 2177 2170 urb->setup_packet = (void *)dr; 2178 2171 urb->transfer_buffer = buf;
+13
drivers/usb/core/quirks.c
··· 388 388 /* Kingston DataTraveler 3.0 */ 389 389 { USB_DEVICE(0x0951, 0x1666), .driver_info = USB_QUIRK_NO_LPM }, 390 390 391 + /* NVIDIA Jetson devices in Force Recovery mode */ 392 + { USB_DEVICE(0x0955, 0x7018), .driver_info = USB_QUIRK_RESET_RESUME }, 393 + { USB_DEVICE(0x0955, 0x7019), .driver_info = USB_QUIRK_RESET_RESUME }, 394 + { USB_DEVICE(0x0955, 0x7418), .driver_info = USB_QUIRK_RESET_RESUME }, 395 + { USB_DEVICE(0x0955, 0x7721), .driver_info = USB_QUIRK_RESET_RESUME }, 396 + { USB_DEVICE(0x0955, 0x7c18), .driver_info = USB_QUIRK_RESET_RESUME }, 397 + { USB_DEVICE(0x0955, 0x7e19), .driver_info = USB_QUIRK_RESET_RESUME }, 398 + { USB_DEVICE(0x0955, 0x7f21), .driver_info = USB_QUIRK_RESET_RESUME }, 399 + 391 400 /* X-Rite/Gretag-Macbeth Eye-One Pro display colorimeter */ 392 401 { USB_DEVICE(0x0971, 0x2000), .driver_info = USB_QUIRK_NO_SET_INTF }, 393 402 ··· 445 436 /* Razer - Razer Blade Keyboard */ 446 437 { USB_DEVICE(0x1532, 0x0116), .driver_info = 447 438 USB_QUIRK_LINEAR_UFRAME_INTR_BINTERVAL }, 439 + 440 + /* Lenovo ThinkPad OneLink+ Dock twin hub controllers (VIA Labs VL812) */ 441 + { USB_DEVICE(0x17ef, 0x1018), .driver_info = USB_QUIRK_RESET_RESUME }, 442 + { USB_DEVICE(0x17ef, 0x1019), .driver_info = USB_QUIRK_RESET_RESUME }, 448 443 449 444 /* Lenovo USB-C to Ethernet Adapter RTL8153-04 */ 450 445 { USB_DEVICE(0x17ef, 0x720c), .driver_info = USB_QUIRK_NO_LPM },
-30
drivers/usb/dwc2/core.c
··· 3 3 * core.c - DesignWare HS OTG Controller common routines 4 4 * 5 5 * Copyright (C) 2004-2013 Synopsys, Inc. 6 - * 7 - * Redistribution and use in source and binary forms, with or without 8 - * modification, are permitted provided that the following conditions 9 - * are met: 10 - * 1. Redistributions of source code must retain the above copyright 11 - * notice, this list of conditions, and the following disclaimer, 12 - * without modification. 13 - * 2. Redistributions in binary form must reproduce the above copyright 14 - * notice, this list of conditions and the following disclaimer in the 15 - * documentation and/or other materials provided with the distribution. 16 - * 3. The names of the above-listed copyright holders may not be used 17 - * to endorse or promote products derived from this software without 18 - * specific prior written permission. 19 - * 20 - * ALTERNATIVELY, this software may be distributed under the terms of the 21 - * GNU General Public License ("GPL") as published by the Free Software 22 - * Foundation; either version 2 of the License, or (at your option) any 23 - * later version. 24 - * 25 - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 26 - * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 27 - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 28 - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 29 - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 30 - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 31 - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 32 - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 33 - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 34 - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 35 - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 6 */ 37 7 38 8 /*
-30
drivers/usb/dwc2/core.h
··· 3 3 * core.h - DesignWare HS OTG Controller common declarations 4 4 * 5 5 * Copyright (C) 2004-2013 Synopsys, Inc. 6 - * 7 - * Redistribution and use in source and binary forms, with or without 8 - * modification, are permitted provided that the following conditions 9 - * are met: 10 - * 1. Redistributions of source code must retain the above copyright 11 - * notice, this list of conditions, and the following disclaimer, 12 - * without modification. 13 - * 2. Redistributions in binary form must reproduce the above copyright 14 - * notice, this list of conditions and the following disclaimer in the 15 - * documentation and/or other materials provided with the distribution. 16 - * 3. The names of the above-listed copyright holders may not be used 17 - * to endorse or promote products derived from this software without 18 - * specific prior written permission. 19 - * 20 - * ALTERNATIVELY, this software may be distributed under the terms of the 21 - * GNU General Public License ("GPL") as published by the Free Software 22 - * Foundation; either version 2 of the License, or (at your option) any 23 - * later version. 24 - * 25 - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 26 - * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 27 - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 28 - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 29 - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 30 - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 31 - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 32 - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 33 - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 34 - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 35 - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 6 */ 37 7 38 8 #ifndef __DWC2_CORE_H__
-30
drivers/usb/dwc2/core_intr.c
··· 3 3 * core_intr.c - DesignWare HS OTG Controller common interrupt handling 4 4 * 5 5 * Copyright (C) 2004-2013 Synopsys, Inc. 6 - * 7 - * Redistribution and use in source and binary forms, with or without 8 - * modification, are permitted provided that the following conditions 9 - * are met: 10 - * 1. Redistributions of source code must retain the above copyright 11 - * notice, this list of conditions, and the following disclaimer, 12 - * without modification. 13 - * 2. Redistributions in binary form must reproduce the above copyright 14 - * notice, this list of conditions and the following disclaimer in the 15 - * documentation and/or other materials provided with the distribution. 16 - * 3. The names of the above-listed copyright holders may not be used 17 - * to endorse or promote products derived from this software without 18 - * specific prior written permission. 19 - * 20 - * ALTERNATIVELY, this software may be distributed under the terms of the 21 - * GNU General Public License ("GPL") as published by the Free Software 22 - * Foundation; either version 2 of the License, or (at your option) any 23 - * later version. 24 - * 25 - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 26 - * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 27 - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 28 - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 29 - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 30 - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 31 - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 32 - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 33 - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 34 - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 35 - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 6 */ 37 7 38 8 /*
-30
drivers/usb/dwc2/hcd.c
··· 3 3 * hcd.c - DesignWare HS OTG Controller host-mode routines 4 4 * 5 5 * Copyright (C) 2004-2013 Synopsys, Inc. 6 - * 7 - * Redistribution and use in source and binary forms, with or without 8 - * modification, are permitted provided that the following conditions 9 - * are met: 10 - * 1. Redistributions of source code must retain the above copyright 11 - * notice, this list of conditions, and the following disclaimer, 12 - * without modification. 13 - * 2. Redistributions in binary form must reproduce the above copyright 14 - * notice, this list of conditions and the following disclaimer in the 15 - * documentation and/or other materials provided with the distribution. 16 - * 3. The names of the above-listed copyright holders may not be used 17 - * to endorse or promote products derived from this software without 18 - * specific prior written permission. 19 - * 20 - * ALTERNATIVELY, this software may be distributed under the terms of the 21 - * GNU General Public License ("GPL") as published by the Free Software 22 - * Foundation; either version 2 of the License, or (at your option) any 23 - * later version. 24 - * 25 - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 26 - * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 27 - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 28 - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 29 - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 30 - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 31 - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 32 - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 33 - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 34 - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 35 - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 6 */ 37 7 38 8 /*
+1 -30
drivers/usb/dwc2/hcd.h
··· 3 3 * hcd.h - DesignWare HS OTG Controller host-mode declarations 4 4 * 5 5 * Copyright (C) 2004-2013 Synopsys, Inc. 6 - * 7 - * Redistribution and use in source and binary forms, with or without 8 - * modification, are permitted provided that the following conditions 9 - * are met: 10 - * 1. Redistributions of source code must retain the above copyright 11 - * notice, this list of conditions, and the following disclaimer, 12 - * without modification. 13 - * 2. Redistributions in binary form must reproduce the above copyright 14 - * notice, this list of conditions and the following disclaimer in the 15 - * documentation and/or other materials provided with the distribution. 16 - * 3. The names of the above-listed copyright holders may not be used 17 - * to endorse or promote products derived from this software without 18 - * specific prior written permission. 19 - * 20 - * ALTERNATIVELY, this software may be distributed under the terms of the 21 - * GNU General Public License ("GPL") as published by the Free Software 22 - * Foundation; either version 2 of the License, or (at your option) any 23 - * later version. 24 - * 25 - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 26 - * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 27 - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 28 - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 29 - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 30 - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 31 - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 32 - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 33 - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 34 - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 35 - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 6 */ 7 + 37 8 #ifndef __DWC2_HCD_H__ 38 9 #define __DWC2_HCD_H__ 39 10
-30
drivers/usb/dwc2/hcd_ddma.c
··· 3 3 * hcd_ddma.c - DesignWare HS OTG Controller descriptor DMA routines 4 4 * 5 5 * Copyright (C) 2004-2013 Synopsys, Inc. 6 - * 7 - * Redistribution and use in source and binary forms, with or without 8 - * modification, are permitted provided that the following conditions 9 - * are met: 10 - * 1. Redistributions of source code must retain the above copyright 11 - * notice, this list of conditions, and the following disclaimer, 12 - * without modification. 13 - * 2. Redistributions in binary form must reproduce the above copyright 14 - * notice, this list of conditions and the following disclaimer in the 15 - * documentation and/or other materials provided with the distribution. 16 - * 3. The names of the above-listed copyright holders may not be used 17 - * to endorse or promote products derived from this software without 18 - * specific prior written permission. 19 - * 20 - * ALTERNATIVELY, this software may be distributed under the terms of the 21 - * GNU General Public License ("GPL") as published by the Free Software 22 - * Foundation; either version 2 of the License, or (at your option) any 23 - * later version. 24 - * 25 - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 26 - * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 27 - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 28 - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 29 - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 30 - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 31 - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 32 - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 33 - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 34 - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 35 - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 6 */ 37 7 38 8 /*
-30
drivers/usb/dwc2/hcd_intr.c
··· 3 3 * hcd_intr.c - DesignWare HS OTG Controller host-mode interrupt handling 4 4 * 5 5 * Copyright (C) 2004-2013 Synopsys, Inc. 6 - * 7 - * Redistribution and use in source and binary forms, with or without 8 - * modification, are permitted provided that the following conditions 9 - * are met: 10 - * 1. Redistributions of source code must retain the above copyright 11 - * notice, this list of conditions, and the following disclaimer, 12 - * without modification. 13 - * 2. Redistributions in binary form must reproduce the above copyright 14 - * notice, this list of conditions and the following disclaimer in the 15 - * documentation and/or other materials provided with the distribution. 16 - * 3. The names of the above-listed copyright holders may not be used 17 - * to endorse or promote products derived from this software without 18 - * specific prior written permission. 19 - * 20 - * ALTERNATIVELY, this software may be distributed under the terms of the 21 - * GNU General Public License ("GPL") as published by the Free Software 22 - * Foundation; either version 2 of the License, or (at your option) any 23 - * later version. 24 - * 25 - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 26 - * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 27 - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 28 - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 29 - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 30 - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 31 - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 32 - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 33 - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 34 - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 35 - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 6 */ 37 7 38 8 /*
-30
drivers/usb/dwc2/hcd_queue.c
··· 3 3 * hcd_queue.c - DesignWare HS OTG Controller host queuing routines 4 4 * 5 5 * Copyright (C) 2004-2013 Synopsys, Inc. 6 - * 7 - * Redistribution and use in source and binary forms, with or without 8 - * modification, are permitted provided that the following conditions 9 - * are met: 10 - * 1. Redistributions of source code must retain the above copyright 11 - * notice, this list of conditions, and the following disclaimer, 12 - * without modification. 13 - * 2. Redistributions in binary form must reproduce the above copyright 14 - * notice, this list of conditions and the following disclaimer in the 15 - * documentation and/or other materials provided with the distribution. 16 - * 3. The names of the above-listed copyright holders may not be used 17 - * to endorse or promote products derived from this software without 18 - * specific prior written permission. 19 - * 20 - * ALTERNATIVELY, this software may be distributed under the terms of the 21 - * GNU General Public License ("GPL") as published by the Free Software 22 - * Foundation; either version 2 of the License, or (at your option) any 23 - * later version. 24 - * 25 - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 26 - * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 27 - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 28 - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 29 - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 30 - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 31 - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 32 - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 33 - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 34 - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 35 - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 6 */ 37 7 38 8 /*
-30
drivers/usb/dwc2/hw.h
··· 3 3 * hw.h - DesignWare HS OTG Controller hardware definitions 4 4 * 5 5 * Copyright 2004-2013 Synopsys, Inc. 6 - * 7 - * Redistribution and use in source and binary forms, with or without 8 - * modification, are permitted provided that the following conditions 9 - * are met: 10 - * 1. Redistributions of source code must retain the above copyright 11 - * notice, this list of conditions, and the following disclaimer, 12 - * without modification. 13 - * 2. Redistributions in binary form must reproduce the above copyright 14 - * notice, this list of conditions and the following disclaimer in the 15 - * documentation and/or other materials provided with the distribution. 16 - * 3. The names of the above-listed copyright holders may not be used 17 - * to endorse or promote products derived from this software without 18 - * specific prior written permission. 19 - * 20 - * ALTERNATIVELY, this software may be distributed under the terms of the 21 - * GNU General Public License ("GPL") as published by the Free Software 22 - * Foundation; either version 2 of the License, or (at your option) any 23 - * later version. 24 - * 25 - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 26 - * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 27 - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 28 - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 29 - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 30 - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 31 - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 32 - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 33 - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 34 - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 35 - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 6 */ 37 7 38 8 #ifndef __DWC2_HW_H__
-30
drivers/usb/dwc2/params.c
··· 1 1 // SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) 2 2 /* 3 3 * Copyright (C) 2004-2016 Synopsys, Inc. 4 - * 5 - * Redistribution and use in source and binary forms, with or without 6 - * modification, are permitted provided that the following conditions 7 - * are met: 8 - * 1. Redistributions of source code must retain the above copyright 9 - * notice, this list of conditions, and the following disclaimer, 10 - * without modification. 11 - * 2. Redistributions in binary form must reproduce the above copyright 12 - * notice, this list of conditions and the following disclaimer in the 13 - * documentation and/or other materials provided with the distribution. 14 - * 3. The names of the above-listed copyright holders may not be used 15 - * to endorse or promote products derived from this software without 16 - * specific prior written permission. 17 - * 18 - * ALTERNATIVELY, this software may be distributed under the terms of the 19 - * GNU General Public License ("GPL") as published by the Free Software 20 - * Foundation; either version 2 of the License, or (at your option) any 21 - * later version. 22 - * 23 - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 - * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 27 - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 4 */ 35 5 36 6 #include <linux/kernel.h>
-30
drivers/usb/dwc2/pci.c
··· 3 3 * pci.c - DesignWare HS OTG Controller PCI driver 4 4 * 5 5 * Copyright (C) 2004-2013 Synopsys, Inc. 6 - * 7 - * Redistribution and use in source and binary forms, with or without 8 - * modification, are permitted provided that the following conditions 9 - * are met: 10 - * 1. Redistributions of source code must retain the above copyright 11 - * notice, this list of conditions, and the following disclaimer, 12 - * without modification. 13 - * 2. Redistributions in binary form must reproduce the above copyright 14 - * notice, this list of conditions and the following disclaimer in the 15 - * documentation and/or other materials provided with the distribution. 16 - * 3. The names of the above-listed copyright holders may not be used 17 - * to endorse or promote products derived from this software without 18 - * specific prior written permission. 19 - * 20 - * ALTERNATIVELY, this software may be distributed under the terms of the 21 - * GNU General Public License ("GPL") as published by the Free Software 22 - * Foundation; either version 2 of the License, or (at your option) any 23 - * later version. 24 - * 25 - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 26 - * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 27 - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 28 - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 29 - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 30 - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 31 - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 32 - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 33 - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 34 - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 35 - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 6 */ 37 7 38 8 /*
-30
drivers/usb/dwc2/platform.c
··· 3 3 * platform.c - DesignWare HS OTG Controller platform driver 4 4 * 5 5 * Copyright (C) Matthijs Kooijman <matthijs@stdin.nl> 6 - * 7 - * Redistribution and use in source and binary forms, with or without 8 - * modification, are permitted provided that the following conditions 9 - * are met: 10 - * 1. Redistributions of source code must retain the above copyright 11 - * notice, this list of conditions, and the following disclaimer, 12 - * without modification. 13 - * 2. Redistributions in binary form must reproduce the above copyright 14 - * notice, this list of conditions and the following disclaimer in the 15 - * documentation and/or other materials provided with the distribution. 16 - * 3. The names of the above-listed copyright holders may not be used 17 - * to endorse or promote products derived from this software without 18 - * specific prior written permission. 19 - * 20 - * ALTERNATIVELY, this software may be distributed under the terms of the 21 - * GNU General Public License ("GPL") as published by the Free Software 22 - * Foundation; either version 2 of the License, or (at your option) any 23 - * later version. 24 - * 25 - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 26 - * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 27 - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 28 - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 29 - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 30 - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 31 - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 32 - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 33 - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 34 - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 35 - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 6 */ 37 7 38 8 #include <linux/kernel.h>
+61 -76
drivers/usb/dwc3/core.c
··· 23 23 #include <linux/delay.h> 24 24 #include <linux/dma-mapping.h> 25 25 #include <linux/of.h> 26 - #include <linux/of_graph.h> 27 26 #include <linux/acpi.h> 28 27 #include <linux/pinctrl/consumer.h> 29 28 #include <linux/reset.h> ··· 85 86 * mode. If the controller supports DRD but the dr_mode is not 86 87 * specified or set to OTG, then set the mode to peripheral. 87 88 */ 88 - if (mode == USB_DR_MODE_OTG && !dwc->edev && 89 + if (mode == USB_DR_MODE_OTG && 89 90 (!IS_ENABLED(CONFIG_USB_ROLE_SWITCH) || 90 91 !device_property_read_bool(dwc->dev, "usb-role-switch")) && 91 92 !DWC3_VER_IS_PRIOR(DWC3, 330A)) ··· 407 408 reg |= FIELD_PREP(DWC3_GFLADJ_REFCLK_FLADJ_MASK, fladj) 408 409 | FIELD_PREP(DWC3_GFLADJ_240MHZDECR, decr >> 1) 409 410 | FIELD_PREP(DWC3_GFLADJ_240MHZDECR_PLS1, decr & 1); 411 + 412 + if (dwc->gfladj_refclk_lpm_sel) 413 + reg |= DWC3_GFLADJ_REFCLK_LPM_SEL; 414 + 410 415 dwc3_writel(dwc->regs, DWC3_GFLADJ, reg); 411 416 } 412 417 ··· 792 789 else 793 790 reg |= DWC3_GUSB2PHYCFG_ENBLSLPM; 794 791 795 - if (dwc->dis_u2_freeclk_exists_quirk) 792 + if (dwc->dis_u2_freeclk_exists_quirk || dwc->gfladj_refclk_lpm_sel) 796 793 reg &= ~DWC3_GUSB2PHYCFG_U2_FREECLK_EXISTS; 797 794 798 795 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); ··· 1183 1180 dwc3_writel(dwc->regs, DWC3_GUCTL2, reg); 1184 1181 } 1185 1182 1183 + /* 1184 + * When configured in HOST mode, after issuing U3/L2 exit controller 1185 + * fails to send proper CRC checksum in CRC5 feild. Because of this 1186 + * behaviour Transaction Error is generated, resulting in reset and 1187 + * re-enumeration of usb device attached. All the termsel, xcvrsel, 1188 + * opmode becomes 0 during end of resume. Enabling bit 10 of GUCTL1 1189 + * will correct this problem. This option is to support certain 1190 + * legacy ULPI PHYs. 1191 + */ 1192 + if (dwc->resume_hs_terminations) { 1193 + reg = dwc3_readl(dwc->regs, DWC3_GUCTL1); 1194 + reg |= DWC3_GUCTL1_RESUME_OPMODE_HS_HOST; 1195 + dwc3_writel(dwc->regs, DWC3_GUCTL1, reg); 1196 + } 1197 + 1186 1198 if (!DWC3_VER_IS_PRIOR(DWC3, 250A)) { 1187 1199 reg = dwc3_readl(dwc->regs, DWC3_GUCTL1); 1188 1200 ··· 1541 1523 "snps,dis-del-phy-power-chg-quirk"); 1542 1524 dwc->dis_tx_ipgap_linecheck_quirk = device_property_read_bool(dev, 1543 1525 "snps,dis-tx-ipgap-linecheck-quirk"); 1526 + dwc->resume_hs_terminations = device_property_read_bool(dev, 1527 + "snps,resume-hs-terminations"); 1544 1528 dwc->parkmode_disable_ss_quirk = device_property_read_bool(dev, 1545 1529 "snps,parkmode-disable-ss-quirk"); 1530 + dwc->gfladj_refclk_lpm_sel = device_property_read_bool(dev, 1531 + "snps,gfladj-refclk-lpm-sel-quirk"); 1546 1532 1547 1533 dwc->tx_de_emphasis_quirk = device_property_read_bool(dev, 1548 1534 "snps,tx_de_emphasis_quirk"); ··· 1690 1668 } 1691 1669 } 1692 1670 1693 - static struct extcon_dev *dwc3_get_extcon(struct dwc3 *dwc) 1694 - { 1695 - struct device *dev = dwc->dev; 1696 - struct device_node *np_phy; 1697 - struct extcon_dev *edev = NULL; 1698 - const char *name; 1699 - 1700 - if (device_property_read_bool(dev, "extcon")) 1701 - return extcon_get_edev_by_phandle(dev, 0); 1702 - 1703 - /* 1704 - * Device tree platforms should get extcon via phandle. 1705 - * On ACPI platforms, we get the name from a device property. 1706 - * This device property is for kernel internal use only and 1707 - * is expected to be set by the glue code. 1708 - */ 1709 - if (device_property_read_string(dev, "linux,extcon-name", &name) == 0) 1710 - return extcon_get_extcon_dev(name); 1711 - 1712 - /* 1713 - * Try to get an extcon device from the USB PHY controller's "port" 1714 - * node. Check if it has the "port" node first, to avoid printing the 1715 - * error message from underlying code, as it's a valid case: extcon 1716 - * device (and "port" node) may be missing in case of "usb-role-switch" 1717 - * or OTG mode. 1718 - */ 1719 - np_phy = of_parse_phandle(dev->of_node, "phys", 0); 1720 - if (of_graph_is_present(np_phy)) { 1721 - struct device_node *np_conn; 1722 - 1723 - np_conn = of_graph_get_remote_node(np_phy, -1, -1); 1724 - if (np_conn) 1725 - edev = extcon_find_edev_by_node(np_conn); 1726 - of_node_put(np_conn); 1727 - } 1728 - of_node_put(np_phy); 1729 - 1730 - return edev; 1731 - } 1732 - 1733 1671 static int dwc3_probe(struct platform_device *pdev) 1734 1672 { 1735 1673 struct device *dev = &pdev->dev; ··· 1735 1753 dwc3_get_properties(dwc); 1736 1754 1737 1755 dwc->reset = devm_reset_control_array_get_optional_shared(dev); 1738 - if (IS_ERR(dwc->reset)) 1739 - return PTR_ERR(dwc->reset); 1756 + if (IS_ERR(dwc->reset)) { 1757 + ret = PTR_ERR(dwc->reset); 1758 + goto put_usb_psy; 1759 + } 1740 1760 1741 1761 if (dev->of_node) { 1742 1762 /* ··· 1748 1764 * check for them to retain backwards compatibility. 1749 1765 */ 1750 1766 dwc->bus_clk = devm_clk_get_optional(dev, "bus_early"); 1751 - if (IS_ERR(dwc->bus_clk)) 1752 - return dev_err_probe(dev, PTR_ERR(dwc->bus_clk), 1753 - "could not get bus clock\n"); 1767 + if (IS_ERR(dwc->bus_clk)) { 1768 + ret = dev_err_probe(dev, PTR_ERR(dwc->bus_clk), 1769 + "could not get bus clock\n"); 1770 + goto put_usb_psy; 1771 + } 1754 1772 1755 1773 if (dwc->bus_clk == NULL) { 1756 1774 dwc->bus_clk = devm_clk_get_optional(dev, "bus_clk"); 1757 - if (IS_ERR(dwc->bus_clk)) 1758 - return dev_err_probe(dev, PTR_ERR(dwc->bus_clk), 1759 - "could not get bus clock\n"); 1775 + if (IS_ERR(dwc->bus_clk)) { 1776 + ret = dev_err_probe(dev, PTR_ERR(dwc->bus_clk), 1777 + "could not get bus clock\n"); 1778 + goto put_usb_psy; 1779 + } 1760 1780 } 1761 1781 1762 1782 dwc->ref_clk = devm_clk_get_optional(dev, "ref"); 1763 - if (IS_ERR(dwc->ref_clk)) 1764 - return dev_err_probe(dev, PTR_ERR(dwc->ref_clk), 1765 - "could not get ref clock\n"); 1783 + if (IS_ERR(dwc->ref_clk)) { 1784 + ret = dev_err_probe(dev, PTR_ERR(dwc->ref_clk), 1785 + "could not get ref clock\n"); 1786 + goto put_usb_psy; 1787 + } 1766 1788 1767 1789 if (dwc->ref_clk == NULL) { 1768 1790 dwc->ref_clk = devm_clk_get_optional(dev, "ref_clk"); 1769 - if (IS_ERR(dwc->ref_clk)) 1770 - return dev_err_probe(dev, PTR_ERR(dwc->ref_clk), 1771 - "could not get ref clock\n"); 1791 + if (IS_ERR(dwc->ref_clk)) { 1792 + ret = dev_err_probe(dev, PTR_ERR(dwc->ref_clk), 1793 + "could not get ref clock\n"); 1794 + goto put_usb_psy; 1795 + } 1772 1796 } 1773 1797 1774 1798 dwc->susp_clk = devm_clk_get_optional(dev, "suspend"); 1775 - if (IS_ERR(dwc->susp_clk)) 1776 - return dev_err_probe(dev, PTR_ERR(dwc->susp_clk), 1777 - "could not get suspend clock\n"); 1799 + if (IS_ERR(dwc->susp_clk)) { 1800 + ret = dev_err_probe(dev, PTR_ERR(dwc->susp_clk), 1801 + "could not get suspend clock\n"); 1802 + goto put_usb_psy; 1803 + } 1778 1804 1779 1805 if (dwc->susp_clk == NULL) { 1780 1806 dwc->susp_clk = devm_clk_get_optional(dev, "suspend_clk"); 1781 - if (IS_ERR(dwc->susp_clk)) 1782 - return dev_err_probe(dev, PTR_ERR(dwc->susp_clk), 1783 - "could not get suspend clock\n"); 1807 + if (IS_ERR(dwc->susp_clk)) { 1808 + ret = dev_err_probe(dev, PTR_ERR(dwc->susp_clk), 1809 + "could not get suspend clock\n"); 1810 + goto put_usb_psy; 1811 + } 1784 1812 } 1785 1813 } 1786 1814 1787 1815 ret = reset_control_deassert(dwc->reset); 1788 1816 if (ret) 1789 - return ret; 1817 + goto put_usb_psy; 1790 1818 1791 1819 ret = dwc3_clk_enable(dwc); 1792 1820 if (ret) ··· 1838 1842 dev_err(dwc->dev, "failed to allocate event buffers\n"); 1839 1843 ret = -ENOMEM; 1840 1844 goto err2; 1841 - } 1842 - 1843 - dwc->edev = dwc3_get_extcon(dwc); 1844 - if (IS_ERR(dwc->edev)) { 1845 - ret = PTR_ERR(dwc->edev); 1846 - dev_err_probe(dwc->dev, ret, "failed to get extcon\n"); 1847 - goto err3; 1848 1845 } 1849 1846 1850 1847 ret = dwc3_get_dr_mode(dwc); ··· 1898 1909 dwc3_clk_disable(dwc); 1899 1910 assert_reset: 1900 1911 reset_control_assert(dwc->reset); 1901 - 1912 + put_usb_psy: 1902 1913 if (dwc->usb_psy) 1903 1914 power_supply_put(dwc->usb_psy); 1904 1915 ··· 1966 1977 case DWC3_GCTL_PRTCAP_DEVICE: 1967 1978 if (pm_runtime_suspended(dwc->dev)) 1968 1979 break; 1969 - spin_lock_irqsave(&dwc->lock, flags); 1970 1980 dwc3_gadget_suspend(dwc); 1971 - spin_unlock_irqrestore(&dwc->lock, flags); 1972 1981 synchronize_irq(dwc->irq_gadget); 1973 1982 dwc3_core_exit(dwc); 1974 1983 break; ··· 2027 2040 return ret; 2028 2041 2029 2042 dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_DEVICE); 2030 - spin_lock_irqsave(&dwc->lock, flags); 2031 2043 dwc3_gadget_resume(dwc); 2032 - spin_unlock_irqrestore(&dwc->lock, flags); 2033 2044 break; 2034 2045 case DWC3_GCTL_PRTCAP_HOST: 2035 2046 if (!PMSG_IS_AUTO(msg) && !device_may_wakeup(dwc->dev)) {
+7
drivers/usb/dwc3/core.h
··· 263 263 #define DWC3_GUCTL1_DEV_FORCE_20_CLK_FOR_30_CLK BIT(26) 264 264 #define DWC3_GUCTL1_DEV_L1_EXIT_BY_HW BIT(24) 265 265 #define DWC3_GUCTL1_PARKMODE_DISABLE_SS BIT(17) 266 + #define DWC3_GUCTL1_RESUME_OPMODE_HS_HOST BIT(10) 266 267 267 268 /* Global Status Register */ 268 269 #define DWC3_GSTS_OTG_IP BIT(10) ··· 392 391 #define DWC3_GFLADJ_30MHZ_SDBND_SEL BIT(7) 393 392 #define DWC3_GFLADJ_30MHZ_MASK 0x3f 394 393 #define DWC3_GFLADJ_REFCLK_FLADJ_MASK GENMASK(21, 8) 394 + #define DWC3_GFLADJ_REFCLK_LPM_SEL BIT(23) 395 395 #define DWC3_GFLADJ_240MHZDECR GENMASK(30, 24) 396 396 #define DWC3_GFLADJ_240MHZDECR_PLS1 BIT(31) 397 397 ··· 1098 1096 * change quirk. 1099 1097 * @dis_tx_ipgap_linecheck_quirk: set if we disable u2mac linestate 1100 1098 * check during HS transmit. 1099 + * @resume-hs-terminations: Set if we enable quirk for fixing improper crc 1100 + * generation after resume from suspend. 1101 1101 * @parkmode_disable_ss_quirk: set if we need to disable all SuperSpeed 1102 1102 * instances in park mode. 1103 1103 * @tx_de_emphasis_quirk: set if we enable Tx de-emphasis quirk ··· 1315 1311 unsigned dis_u2_freeclk_exists_quirk:1; 1316 1312 unsigned dis_del_phy_power_chg_quirk:1; 1317 1313 unsigned dis_tx_ipgap_linecheck_quirk:1; 1314 + unsigned resume_hs_terminations:1; 1318 1315 unsigned parkmode_disable_ss_quirk:1; 1316 + unsigned gfladj_refclk_lpm_sel:1; 1319 1317 1320 1318 unsigned tx_de_emphasis_quirk:1; 1321 1319 unsigned tx_de_emphasis:2; ··· 1566 1560 int dwc3_send_gadget_generic_command(struct dwc3 *dwc, unsigned int cmd, 1567 1561 u32 param); 1568 1562 void dwc3_gadget_clear_tx_fifos(struct dwc3 *dwc); 1563 + void dwc3_remove_requests(struct dwc3 *dwc, struct dwc3_ep *dep, int status); 1569 1564 #else 1570 1565 static inline int dwc3_gadget_init(struct dwc3 *dwc) 1571 1566 { return 0; }
+2 -2
drivers/usb/dwc3/debug.h
··· 278 278 break; 279 279 case DWC3_DEPEVT_XFERINPROGRESS: 280 280 scnprintf(str + len, size - len, 281 - "Transfer In Progress [%d] (%c%c%c)", 281 + "Transfer In Progress [%08x] (%c%c%c)", 282 282 event->parameters, 283 283 status & DEPEVT_STATUS_SHORT ? 'S' : 's', 284 284 status & DEPEVT_STATUS_IOC ? 'I' : 'i', ··· 286 286 break; 287 287 case DWC3_DEPEVT_XFERNOTREADY: 288 288 len += scnprintf(str + len, size - len, 289 - "Transfer Not Ready [%d]%s", 289 + "Transfer Not Ready [%08x]%s", 290 290 event->parameters, 291 291 status & DEPEVT_STATUS_TRANSFER_ACTIVE ? 292 292 " (Active)" : " (Not Active)");
+50
drivers/usb/dwc3/drd.c
··· 8 8 */ 9 9 10 10 #include <linux/extcon.h> 11 + #include <linux/of_graph.h> 11 12 #include <linux/of_platform.h> 12 13 #include <linux/platform_device.h> 13 14 #include <linux/property.h> ··· 439 438 return NOTIFY_DONE; 440 439 } 441 440 441 + static struct extcon_dev *dwc3_get_extcon(struct dwc3 *dwc) 442 + { 443 + struct device *dev = dwc->dev; 444 + struct device_node *np_phy; 445 + struct extcon_dev *edev = NULL; 446 + const char *name; 447 + 448 + if (device_property_read_bool(dev, "extcon")) 449 + return extcon_get_edev_by_phandle(dev, 0); 450 + 451 + /* 452 + * Device tree platforms should get extcon via phandle. 453 + * On ACPI platforms, we get the name from a device property. 454 + * This device property is for kernel internal use only and 455 + * is expected to be set by the glue code. 456 + */ 457 + if (device_property_read_string(dev, "linux,extcon-name", &name) == 0) { 458 + edev = extcon_get_extcon_dev(name); 459 + if (!edev) 460 + return ERR_PTR(-EPROBE_DEFER); 461 + 462 + return edev; 463 + } 464 + 465 + /* 466 + * Try to get an extcon device from the USB PHY controller's "port" 467 + * node. Check if it has the "port" node first, to avoid printing the 468 + * error message from underlying code, as it's a valid case: extcon 469 + * device (and "port" node) may be missing in case of "usb-role-switch" 470 + * or OTG mode. 471 + */ 472 + np_phy = of_parse_phandle(dev->of_node, "phys", 0); 473 + if (of_graph_is_present(np_phy)) { 474 + struct device_node *np_conn; 475 + 476 + np_conn = of_graph_get_remote_node(np_phy, -1, -1); 477 + if (np_conn) 478 + edev = extcon_find_edev_by_node(np_conn); 479 + of_node_put(np_conn); 480 + } 481 + of_node_put(np_phy); 482 + 483 + return edev; 484 + } 485 + 442 486 #if IS_ENABLED(CONFIG_USB_ROLE_SWITCH) 443 487 #define ROLE_SWITCH 1 444 488 static int dwc3_usb_role_switch_set(struct usb_role_switch *sw, ··· 587 541 if (ROLE_SWITCH && 588 542 device_property_read_bool(dwc->dev, "usb-role-switch")) 589 543 return dwc3_setup_role_switch(dwc); 544 + 545 + dwc->edev = dwc3_get_extcon(dwc); 546 + if (IS_ERR(dwc->edev)) 547 + return PTR_ERR(dwc->edev); 590 548 591 549 if (dwc->edev) { 592 550 dwc->edev_nb.notifier_call = dwc3_drd_notifier;
+9 -5
drivers/usb/dwc3/dwc3-pci.c
··· 40 40 #define PCI_DEVICE_ID_INTEL_TGPLP 0xa0ee 41 41 #define PCI_DEVICE_ID_INTEL_TGPH 0x43ee 42 42 #define PCI_DEVICE_ID_INTEL_JSP 0x4dee 43 - #define PCI_DEVICE_ID_INTEL_ADL 0x465e 44 - #define PCI_DEVICE_ID_INTEL_ADLP 0x51ee 45 - #define PCI_DEVICE_ID_INTEL_ADLM 0x54ee 43 + #define PCI_DEVICE_ID_INTEL_ADL 0x460e 44 + #define PCI_DEVICE_ID_INTEL_ADL_PCH 0x51ee 45 + #define PCI_DEVICE_ID_INTEL_ADLN 0x465e 46 + #define PCI_DEVICE_ID_INTEL_ADLN_PCH 0x54ee 46 47 #define PCI_DEVICE_ID_INTEL_ADLS 0x7ae1 47 48 #define PCI_DEVICE_ID_INTEL_RPL 0x460e 48 49 #define PCI_DEVICE_ID_INTEL_RPLS 0x7a61 ··· 449 448 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_ADL), 450 449 (kernel_ulong_t) &dwc3_pci_intel_swnode, }, 451 450 452 - { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_ADLP), 451 + { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_ADL_PCH), 453 452 (kernel_ulong_t) &dwc3_pci_intel_swnode, }, 454 453 455 - { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_ADLM), 454 + { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_ADLN), 455 + (kernel_ulong_t) &dwc3_pci_intel_swnode, }, 456 + 457 + { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_ADLN_PCH), 456 458 (kernel_ulong_t) &dwc3_pci_intel_swnode, }, 457 459 458 460 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_ADLS),
+9 -13
drivers/usb/dwc3/dwc3-qcom.c
··· 243 243 */ 244 244 static int dwc3_qcom_interconnect_init(struct dwc3_qcom *qcom) 245 245 { 246 + enum usb_device_speed max_speed; 246 247 struct device *dev = qcom->dev; 247 248 int ret; 248 249 ··· 253 252 qcom->icc_path_ddr = of_icc_get(dev, "usb-ddr"); 254 253 if (IS_ERR(qcom->icc_path_ddr)) { 255 254 dev_err(dev, "failed to get usb-ddr path: %ld\n", 256 - PTR_ERR(qcom->icc_path_ddr)); 255 + PTR_ERR(qcom->icc_path_ddr)); 257 256 return PTR_ERR(qcom->icc_path_ddr); 258 257 } 259 258 ··· 264 263 return PTR_ERR(qcom->icc_path_apps); 265 264 } 266 265 267 - if (usb_get_maximum_speed(&qcom->dwc3->dev) >= USB_SPEED_SUPER || 268 - usb_get_maximum_speed(&qcom->dwc3->dev) == USB_SPEED_UNKNOWN) 266 + max_speed = usb_get_maximum_speed(&qcom->dwc3->dev); 267 + if (max_speed >= USB_SPEED_SUPER || max_speed == USB_SPEED_UNKNOWN) { 269 268 ret = icc_set_bw(qcom->icc_path_ddr, 270 - USB_MEMORY_AVG_SS_BW, USB_MEMORY_PEAK_SS_BW); 271 - else 269 + USB_MEMORY_AVG_SS_BW, USB_MEMORY_PEAK_SS_BW); 270 + } else { 272 271 ret = icc_set_bw(qcom->icc_path_ddr, 273 - USB_MEMORY_AVG_HS_BW, USB_MEMORY_PEAK_HS_BW); 274 - 272 + USB_MEMORY_AVG_HS_BW, USB_MEMORY_PEAK_HS_BW); 273 + } 275 274 if (ret) { 276 275 dev_err(dev, "failed to set bandwidth for usb-ddr path: %d\n", ret); 277 276 return ret; 278 277 } 279 278 280 - ret = icc_set_bw(qcom->icc_path_apps, 281 - APPS_USB_AVG_BW, APPS_USB_PEAK_BW); 279 + ret = icc_set_bw(qcom->icc_path_apps, APPS_USB_AVG_BW, APPS_USB_PEAK_BW); 282 280 if (ret) { 283 281 dev_err(dev, "failed to set bandwidth for apps-usb path: %d\n", ret); 284 282 return ret; ··· 1007 1007 1008 1008 static const struct of_device_id dwc3_qcom_of_match[] = { 1009 1009 { .compatible = "qcom,dwc3" }, 1010 - { .compatible = "qcom,msm8996-dwc3" }, 1011 - { .compatible = "qcom,msm8998-dwc3" }, 1012 - { .compatible = "qcom,sdm660-dwc3" }, 1013 - { .compatible = "qcom,sdm845-dwc3" }, 1014 1010 { } 1015 1011 }; 1016 1012 MODULE_DEVICE_TABLE(of, dwc3_qcom_of_match);
+50 -13
drivers/usb/dwc3/dwc3-xilinx.c
··· 47 47 struct device *dev; 48 48 void __iomem *regs; 49 49 int (*pltfm_init)(struct dwc3_xlnx *data); 50 + struct phy *usb3_phy; 50 51 }; 51 52 52 53 static void dwc3_xlnx_mask_phy_rst(struct dwc3_xlnx *priv_data, bool mask) ··· 101 100 struct device *dev = priv_data->dev; 102 101 struct reset_control *crst, *hibrst, *apbrst; 103 102 struct gpio_desc *reset_gpio; 104 - struct phy *usb3_phy; 105 103 int ret = 0; 106 104 u32 reg; 107 105 108 - usb3_phy = devm_phy_optional_get(dev, "usb3-phy"); 109 - if (IS_ERR(usb3_phy)) { 110 - ret = PTR_ERR(usb3_phy); 106 + priv_data->usb3_phy = devm_phy_optional_get(dev, "usb3-phy"); 107 + if (IS_ERR(priv_data->usb3_phy)) { 108 + ret = PTR_ERR(priv_data->usb3_phy); 111 109 dev_err_probe(dev, ret, 112 110 "failed to get USB3 PHY\n"); 113 111 goto err; ··· 121 121 * in use but the usb3-phy entry is missing from the device tree. 122 122 * Therefore, skip these operations in this case. 123 123 */ 124 - if (!usb3_phy) 124 + if (!priv_data->usb3_phy) 125 125 goto skip_usb3_phy; 126 126 127 127 crst = devm_reset_control_get_exclusive(dev, "usb_crst"); ··· 166 166 goto err; 167 167 } 168 168 169 - ret = phy_init(usb3_phy); 169 + ret = phy_init(priv_data->usb3_phy); 170 170 if (ret < 0) { 171 - phy_exit(usb3_phy); 171 + phy_exit(priv_data->usb3_phy); 172 172 goto err; 173 173 } 174 174 ··· 196 196 goto err; 197 197 } 198 198 199 - ret = phy_power_on(usb3_phy); 199 + ret = phy_power_on(priv_data->usb3_phy); 200 200 if (ret < 0) { 201 - phy_exit(usb3_phy); 201 + phy_exit(priv_data->usb3_phy); 202 202 goto err; 203 203 } 204 204 ··· 322 322 return 0; 323 323 } 324 324 325 - static int __maybe_unused dwc3_xlnx_suspend_common(struct device *dev) 325 + static int __maybe_unused dwc3_xlnx_runtime_suspend(struct device *dev) 326 326 { 327 327 struct dwc3_xlnx *priv_data = dev_get_drvdata(dev); 328 328 ··· 331 331 return 0; 332 332 } 333 333 334 - static int __maybe_unused dwc3_xlnx_resume_common(struct device *dev) 334 + static int __maybe_unused dwc3_xlnx_runtime_resume(struct device *dev) 335 335 { 336 336 struct dwc3_xlnx *priv_data = dev_get_drvdata(dev); 337 337 ··· 346 346 return 0; 347 347 } 348 348 349 - static UNIVERSAL_DEV_PM_OPS(dwc3_xlnx_dev_pm_ops, dwc3_xlnx_suspend_common, 350 - dwc3_xlnx_resume_common, dwc3_xlnx_runtime_idle); 349 + static int __maybe_unused dwc3_xlnx_suspend(struct device *dev) 350 + { 351 + struct dwc3_xlnx *priv_data = dev_get_drvdata(dev); 352 + 353 + phy_exit(priv_data->usb3_phy); 354 + 355 + /* Disable the clocks */ 356 + clk_bulk_disable(priv_data->num_clocks, priv_data->clks); 357 + 358 + return 0; 359 + } 360 + 361 + static int __maybe_unused dwc3_xlnx_resume(struct device *dev) 362 + { 363 + struct dwc3_xlnx *priv_data = dev_get_drvdata(dev); 364 + int ret; 365 + 366 + ret = clk_bulk_enable(priv_data->num_clocks, priv_data->clks); 367 + if (ret) 368 + return ret; 369 + 370 + ret = phy_init(priv_data->usb3_phy); 371 + if (ret < 0) 372 + return ret; 373 + 374 + ret = phy_power_on(priv_data->usb3_phy); 375 + if (ret < 0) { 376 + phy_exit(priv_data->usb3_phy); 377 + return ret; 378 + } 379 + 380 + return 0; 381 + } 382 + 383 + static const struct dev_pm_ops dwc3_xlnx_dev_pm_ops = { 384 + SET_SYSTEM_SLEEP_PM_OPS(dwc3_xlnx_suspend, dwc3_xlnx_resume) 385 + SET_RUNTIME_PM_OPS(dwc3_xlnx_runtime_suspend, 386 + dwc3_xlnx_runtime_resume, dwc3_xlnx_runtime_idle) 387 + }; 351 388 352 389 static struct platform_driver dwc3_xlnx_driver = { 353 390 .probe = dwc3_xlnx_probe,
+8 -3
drivers/usb/dwc3/ep0.c
··· 197 197 int ret; 198 198 199 199 spin_lock_irqsave(&dwc->lock, flags); 200 - if (!dep->endpoint.desc || !dwc->pullups_connected) { 200 + if (!dep->endpoint.desc || !dwc->pullups_connected || !dwc->connected) { 201 201 dev_err(dwc->dev, "%s: can't queue to disabled endpoint\n", 202 202 dep->name); 203 203 ret = -ESHUTDOWN; ··· 293 293 continue; 294 294 295 295 dwc3_ep->flags &= ~DWC3_EP_DELAY_STOP; 296 - dwc3_stop_active_transfer(dwc3_ep, true, true); 296 + if (dwc->connected) 297 + dwc3_stop_active_transfer(dwc3_ep, true, true); 298 + else 299 + dwc3_remove_requests(dwc, dwc3_ep, -ESHUTDOWN); 297 300 } 298 301 } 299 302 ··· 818 815 int ret = -EINVAL; 819 816 u32 len; 820 817 821 - if (!dwc->gadget_driver || !dwc->connected) 818 + if (!dwc->gadget_driver || !dwc->softconnect || !dwc->connected) 822 819 goto out; 823 820 824 821 trace_dwc3_ctrl_req(ctrl); ··· 1121 1118 { 1122 1119 switch (event->status) { 1123 1120 case DEPEVT_STATUS_CONTROL_DATA: 1121 + if (!dwc->softconnect || !dwc->connected) 1122 + return; 1124 1123 /* 1125 1124 * We already have a DATA transfer in the controller's cache, 1126 1125 * if we receive a XferNotReady(DATA) we will ignore it, unless
+58 -15
drivers/usb/dwc3/gadget.c
··· 366 366 367 367 dwc3_writel(dep->regs, DWC3_DEPCMD, cmd); 368 368 369 - if (!(cmd & DWC3_DEPCMD_CMDACT)) { 369 + if (!(cmd & DWC3_DEPCMD_CMDACT) || 370 + (DWC3_DEPCMD_CMD(cmd) == DWC3_DEPCMD_ENDTRANSFER && 371 + !(cmd & DWC3_DEPCMD_CMDIOC))) { 370 372 ret = 0; 371 373 goto skip_status; 372 374 } ··· 967 965 return 0; 968 966 } 969 967 970 - static void dwc3_remove_requests(struct dwc3 *dwc, struct dwc3_ep *dep) 968 + void dwc3_remove_requests(struct dwc3 *dwc, struct dwc3_ep *dep, int status) 971 969 { 972 970 struct dwc3_request *req; 973 971 974 972 dwc3_stop_active_transfer(dep, true, false); 975 973 974 + /* If endxfer is delayed, avoid unmapping requests */ 975 + if (dep->flags & DWC3_EP_DELAY_STOP) 976 + return; 977 + 976 978 /* - giveback all requests to gadget driver */ 977 979 while (!list_empty(&dep->started_list)) { 978 980 req = next_request(&dep->started_list); 979 981 980 - dwc3_gadget_giveback(dep, req, -ESHUTDOWN); 982 + dwc3_gadget_giveback(dep, req, status); 981 983 } 982 984 983 985 while (!list_empty(&dep->pending_list)) { 984 986 req = next_request(&dep->pending_list); 985 987 986 - dwc3_gadget_giveback(dep, req, -ESHUTDOWN); 988 + dwc3_gadget_giveback(dep, req, status); 987 989 } 988 990 989 991 while (!list_empty(&dep->cancelled_list)) { 990 992 req = next_request(&dep->cancelled_list); 991 993 992 - dwc3_gadget_giveback(dep, req, -ESHUTDOWN); 994 + dwc3_gadget_giveback(dep, req, status); 993 995 } 994 996 } 995 997 ··· 1011 1005 { 1012 1006 struct dwc3 *dwc = dep->dwc; 1013 1007 u32 reg; 1008 + u32 mask; 1014 1009 1015 1010 trace_dwc3_gadget_ep_disable(dep); 1016 1011 ··· 1029 1022 dep->endpoint.desc = NULL; 1030 1023 } 1031 1024 1032 - dwc3_remove_requests(dwc, dep); 1025 + dwc3_remove_requests(dwc, dep, -ECONNRESET); 1033 1026 1034 1027 dep->stream_capable = false; 1035 1028 dep->type = 0; 1036 - dep->flags &= DWC3_EP_TXFIFO_RESIZED; 1029 + mask = DWC3_EP_TXFIFO_RESIZED; 1030 + /* 1031 + * dwc3_remove_requests() can exit early if DWC3 EP delayed stop is 1032 + * set. Do not clear DEP flags, so that the end transfer command will 1033 + * be reattempted during the next SETUP stage. 1034 + */ 1035 + if (dep->flags & DWC3_EP_DELAY_STOP) 1036 + mask |= (DWC3_EP_DELAY_STOP | DWC3_EP_TRANSFER_STARTED); 1037 + dep->flags &= mask; 1037 1038 1038 1039 return 0; 1039 1040 } ··· 2355 2340 if (!dep) 2356 2341 continue; 2357 2342 2358 - dwc3_remove_requests(dwc, dep); 2343 + dwc3_remove_requests(dwc, dep, -ESHUTDOWN); 2359 2344 } 2360 2345 } 2361 2346 ··· 2455 2440 static int dwc3_gadget_run_stop(struct dwc3 *dwc, int is_on, int suspend) 2456 2441 { 2457 2442 u32 reg; 2458 - u32 timeout = 500; 2443 + u32 timeout = 2000; 2459 2444 2460 2445 if (pm_runtime_suspended(dwc->dev)) 2461 2446 return 0; ··· 2488 2473 dwc3_gadget_dctl_write_safe(dwc, reg); 2489 2474 2490 2475 do { 2476 + usleep_range(1000, 2000); 2491 2477 reg = dwc3_readl(dwc->regs, DWC3_DSTS); 2492 2478 reg &= DWC3_DSTS_DEVCTRLHLT; 2493 2479 } while (--timeout && !(!is_on ^ !reg)); ··· 2516 2500 */ 2517 2501 if (dwc->ep0state != EP0_SETUP_PHASE) { 2518 2502 int ret; 2503 + 2504 + if (dwc->delayed_status) 2505 + dwc3_ep0_send_delayed_status(dwc); 2519 2506 2520 2507 reinit_completion(&dwc->ep0_in_setup); 2521 2508 ··· 2586 2567 pm_runtime_put(dwc->dev); 2587 2568 return 0; 2588 2569 } 2570 + 2571 + synchronize_irq(dwc->irq_gadget); 2589 2572 2590 2573 if (!is_on) { 2591 2574 ret = dwc3_gadget_soft_disconnect(dwc); ··· 2739 2718 dwc3_gadget_ep0_desc.wMaxPacketSize = cpu_to_le16(512); 2740 2719 2741 2720 dep = dwc->eps[0]; 2721 + dep->flags = 0; 2742 2722 ret = __dwc3_gadget_ep_enable(dep, DWC3_DEPCFG_ACTION_INIT); 2743 2723 if (ret) { 2744 2724 dev_err(dwc->dev, "failed to enable %s\n", dep->name); ··· 2747 2725 } 2748 2726 2749 2727 dep = dwc->eps[1]; 2728 + dep->flags = 0; 2750 2729 ret = __dwc3_gadget_ep_enable(dep, DWC3_DEPCFG_ACTION_INIT); 2751 2730 if (ret) { 2752 2731 dev_err(dwc->dev, "failed to enable %s\n", dep->name); ··· 3591 3568 * streams are updated, and the device controller will not be 3592 3569 * triggered to generate ERDY to move the next stream data. To 3593 3570 * workaround this and maintain compatibility with various 3594 - * hosts, force to reinitate the stream until the host is ready 3571 + * hosts, force to reinitiate the stream until the host is ready 3595 3572 * instead of waiting for the host to prime the endpoint. 3596 3573 */ 3597 3574 if (DWC3_VER_IS_WITHIN(DWC32, 100A, ANY)) { ··· 3619 3596 dep = dwc->eps[epnum]; 3620 3597 3621 3598 if (!(dep->flags & DWC3_EP_ENABLED)) { 3622 - if (!(dep->flags & DWC3_EP_TRANSFER_STARTED)) 3599 + if ((epnum > 1) && !(dep->flags & DWC3_EP_TRANSFER_STARTED)) 3623 3600 return; 3624 3601 3625 3602 /* Handle only EPCMDCMPLT when EP disabled */ 3626 - if (event->endpoint_event != DWC3_DEPEVT_EPCMDCMPLT) 3603 + if ((event->endpoint_event != DWC3_DEPEVT_EPCMDCMPLT) && 3604 + !(epnum <= 1 && event->endpoint_event == DWC3_DEPEVT_XFERCOMPLETE)) 3627 3605 return; 3628 3606 } 3629 3607 ··· 3719 3695 * timeout. Delay issuing the End Transfer command until the Setup TRB is 3720 3696 * prepared. 3721 3697 */ 3722 - if (dwc->ep0state != EP0_SETUP_PHASE && !dwc->delayed_status) { 3698 + if (dwc->ep0state != EP0_SETUP_PHASE) { 3723 3699 dep->flags |= DWC3_EP_DELAY_STOP; 3724 3700 return; 3725 3701 } ··· 3787 3763 reg &= ~DWC3_DCTL_INITU2ENA; 3788 3764 dwc3_gadget_dctl_write_safe(dwc, reg); 3789 3765 3766 + dwc->connected = false; 3767 + 3790 3768 dwc3_disconnect_gadget(dwc); 3791 3769 3792 3770 dwc->gadget->speed = USB_SPEED_UNKNOWN; 3793 3771 dwc->setup_packet_pending = false; 3794 3772 usb_gadget_set_state(dwc->gadget, USB_STATE_NOTATTACHED); 3795 3773 3796 - dwc->connected = false; 3774 + if (dwc->ep0state != EP0_SETUP_PHASE) { 3775 + unsigned int dir; 3776 + 3777 + dir = !!dwc->ep0_expect_in; 3778 + if (dwc->ep0state == EP0_DATA_PHASE) 3779 + dwc3_ep0_end_control_data(dwc, dwc->eps[dir]); 3780 + else 3781 + dwc3_ep0_end_control_data(dwc, dwc->eps[!dir]); 3782 + dwc3_ep0_stall_and_restart(dwc); 3783 + } 3797 3784 } 3798 3785 3799 3786 static void dwc3_gadget_reset_interrupt(struct dwc3 *dwc) ··· 3901 3866 u32 reg; 3902 3867 u8 lanes = 1; 3903 3868 u8 speed; 3869 + 3870 + if (!dwc->softconnect) 3871 + return; 3904 3872 3905 3873 reg = dwc3_readl(dwc->regs, DWC3_DSTS); 3906 3874 speed = reg & DWC3_DSTS_CONNECTSPD; ··· 4167 4129 unsigned int is_ss = evtinfo & BIT(4); 4168 4130 4169 4131 /* 4170 - * WORKAROUND: DWC3 revison 2.20a with hibernation support 4132 + * WORKAROUND: DWC3 revision 2.20a with hibernation support 4171 4133 * have a known issue which can cause USB CV TD.9.23 to fail 4172 4134 * randomly. 4173 4135 * ··· 4545 4507 4546 4508 int dwc3_gadget_suspend(struct dwc3 *dwc) 4547 4509 { 4510 + unsigned long flags; 4511 + 4548 4512 if (!dwc->gadget_driver) 4549 4513 return 0; 4550 4514 4551 4515 dwc3_gadget_run_stop(dwc, false, false); 4516 + 4517 + spin_lock_irqsave(&dwc->lock, flags); 4552 4518 dwc3_disconnect_gadget(dwc); 4553 4519 __dwc3_gadget_stop(dwc); 4520 + spin_unlock_irqrestore(&dwc->lock, flags); 4554 4521 4555 4522 return 0; 4556 4523 }
+2 -1
drivers/usb/dwc3/trace.h
··· 241 241 __entry->enqueue = dep->trb_enqueue; 242 242 __entry->dequeue = dep->trb_dequeue; 243 243 ), 244 - TP_printk("%s: trb %p (E%d:D%d) buf %08x%08x size %s%d ctrl %08x (%c%c%c%c:%c%c:%s)", 244 + TP_printk("%s: trb %p (E%d:D%d) buf %08x%08x size %s%d ctrl %08x sofn %08x (%c%c%c%c:%c%c:%s)", 245 245 __get_str(name), __entry->trb, __entry->enqueue, 246 246 __entry->dequeue, __entry->bph, __entry->bpl, 247 247 ({char *s; ··· 267 267 s = ""; 268 268 } s; }), 269 269 DWC3_TRB_SIZE_LENGTH(__entry->size), __entry->ctrl, 270 + DWC3_TRB_CTRL_GET_SID_SOFN(__entry->ctrl), 270 271 __entry->ctrl & DWC3_TRB_CTRL_HWO ? 'H' : 'h', 271 272 __entry->ctrl & DWC3_TRB_CTRL_LST ? 'L' : 'l', 272 273 __entry->ctrl & DWC3_TRB_CTRL_CHN ? 'C' : 'c',
+3 -3
drivers/usb/gadget/function/f_fs.c
··· 2645 2645 unsigned i = 0; 2646 2646 vla_group(d); 2647 2647 vla_item(d, struct usb_gadget_strings *, stringtabs, 2648 - lang_count + 1); 2648 + size_add(lang_count, 1)); 2649 2649 vla_item(d, struct usb_gadget_strings, stringtab, lang_count); 2650 2650 vla_item(d, struct usb_string, strings, 2651 - lang_count*(needed_count+1)); 2651 + size_mul(lang_count, (needed_count + 1))); 2652 2652 2653 2653 char *vlabuf = kmalloc(vla_group_size(d), GFP_KERNEL); 2654 2654 ··· 3700 3700 3701 3701 existing = _ffs_do_find_dev(name); 3702 3702 if (!existing) 3703 - strlcpy(dev->name, name, ARRAY_SIZE(dev->name)); 3703 + strscpy(dev->name, name, ARRAY_SIZE(dev->name)); 3704 3704 else if (existing != dev) 3705 3705 ret = -EBUSY; 3706 3706
+8 -3
drivers/usb/gadget/function/f_mass_storage.c
··· 2662 2662 } 2663 2663 2664 2664 static DEVICE_ATTR_RW(nofua); 2665 - /* mode wil be set in fsg_lun_attr_is_visible() */ 2666 - static DEVICE_ATTR(ro, 0, ro_show, ro_store); 2667 - static DEVICE_ATTR(file, 0, file_show, file_store); 2668 2665 static DEVICE_ATTR_WO(forced_eject); 2666 + 2667 + /* 2668 + * Mode of the ro and file attribute files will be overridden in 2669 + * fsg_lun_dev_is_visible() depending on if this is a cdrom, or if it is a 2670 + * removable device. 2671 + */ 2672 + static DEVICE_ATTR_RW(ro); 2673 + static DEVICE_ATTR_RW(file); 2669 2674 2670 2675 /****************************** FSG COMMON ******************************/ 2671 2676
+28 -32
drivers/usb/gadget/function/f_ncm.c
··· 450 450 unsigned next_ndp_index; 451 451 }; 452 452 453 - #define INIT_NDP16_OPTS { \ 454 - .nth_sign = USB_CDC_NCM_NTH16_SIGN, \ 455 - .ndp_sign = USB_CDC_NCM_NDP16_NOCRC_SIGN, \ 456 - .nth_size = sizeof(struct usb_cdc_ncm_nth16), \ 457 - .ndp_size = sizeof(struct usb_cdc_ncm_ndp16), \ 458 - .dpe_size = sizeof(struct usb_cdc_ncm_dpe16), \ 459 - .ndplen_align = 4, \ 460 - .dgram_item_len = 1, \ 461 - .block_length = 1, \ 462 - .ndp_index = 1, \ 463 - .reserved1 = 0, \ 464 - .reserved2 = 0, \ 465 - .next_ndp_index = 1, \ 466 - } 453 + static const struct ndp_parser_opts ndp16_opts = { 454 + .nth_sign = USB_CDC_NCM_NTH16_SIGN, 455 + .ndp_sign = USB_CDC_NCM_NDP16_NOCRC_SIGN, 456 + .nth_size = sizeof(struct usb_cdc_ncm_nth16), 457 + .ndp_size = sizeof(struct usb_cdc_ncm_ndp16), 458 + .dpe_size = sizeof(struct usb_cdc_ncm_dpe16), 459 + .ndplen_align = 4, 460 + .dgram_item_len = 1, 461 + .block_length = 1, 462 + .ndp_index = 1, 463 + .reserved1 = 0, 464 + .reserved2 = 0, 465 + .next_ndp_index = 1, 466 + }; 467 467 468 - 469 - #define INIT_NDP32_OPTS { \ 470 - .nth_sign = USB_CDC_NCM_NTH32_SIGN, \ 471 - .ndp_sign = USB_CDC_NCM_NDP32_NOCRC_SIGN, \ 472 - .nth_size = sizeof(struct usb_cdc_ncm_nth32), \ 473 - .ndp_size = sizeof(struct usb_cdc_ncm_ndp32), \ 474 - .dpe_size = sizeof(struct usb_cdc_ncm_dpe32), \ 475 - .ndplen_align = 8, \ 476 - .dgram_item_len = 2, \ 477 - .block_length = 2, \ 478 - .ndp_index = 2, \ 479 - .reserved1 = 1, \ 480 - .reserved2 = 2, \ 481 - .next_ndp_index = 2, \ 482 - } 483 - 484 - static const struct ndp_parser_opts ndp16_opts = INIT_NDP16_OPTS; 485 - static const struct ndp_parser_opts ndp32_opts = INIT_NDP32_OPTS; 468 + static const struct ndp_parser_opts ndp32_opts = { 469 + .nth_sign = USB_CDC_NCM_NTH32_SIGN, 470 + .ndp_sign = USB_CDC_NCM_NDP32_NOCRC_SIGN, 471 + .nth_size = sizeof(struct usb_cdc_ncm_nth32), 472 + .ndp_size = sizeof(struct usb_cdc_ncm_ndp32), 473 + .dpe_size = sizeof(struct usb_cdc_ncm_dpe32), 474 + .ndplen_align = 8, 475 + .dgram_item_len = 2, 476 + .block_length = 2, 477 + .ndp_index = 2, 478 + .reserved1 = 1, 479 + .reserved2 = 2, 480 + .next_ndp_index = 2, 481 + }; 486 482 487 483 static inline void put_ncm(__le16 **p, unsigned size, unsigned val) 488 484 {
+6 -6
drivers/usb/gadget/function/f_printer.c
··· 89 89 u8 printer_cdev_open; 90 90 wait_queue_head_t wait; 91 91 unsigned q_len; 92 - char *pnp_string; /* We don't own memory! */ 92 + char **pnp_string; /* We don't own memory! */ 93 93 struct usb_function function; 94 94 }; 95 95 ··· 1000 1000 if ((wIndex>>8) != dev->interface) 1001 1001 break; 1002 1002 1003 - if (!dev->pnp_string) { 1003 + if (!*dev->pnp_string) { 1004 1004 value = 0; 1005 1005 break; 1006 1006 } 1007 - value = strlen(dev->pnp_string); 1007 + value = strlen(*dev->pnp_string); 1008 1008 buf[0] = (value >> 8) & 0xFF; 1009 1009 buf[1] = value & 0xFF; 1010 - memcpy(buf + 2, dev->pnp_string, value); 1010 + memcpy(buf + 2, *dev->pnp_string, value); 1011 1011 DBG(dev, "1284 PNP String: %x %s\n", value, 1012 - dev->pnp_string); 1012 + *dev->pnp_string); 1013 1013 break; 1014 1014 1015 1015 case GET_PORT_STATUS: /* Get Port Status */ ··· 1475 1475 kref_init(&dev->kref); 1476 1476 ++opts->refcnt; 1477 1477 dev->minor = opts->minor; 1478 - dev->pnp_string = opts->pnp_string; 1478 + dev->pnp_string = &opts->pnp_string; 1479 1479 dev->q_len = opts->q_len; 1480 1480 mutex_unlock(&opts->lock); 1481 1481
+2 -2
drivers/usb/gadget/function/f_tcm.c
··· 2306 2306 2307 2307 DECLARE_USB_FUNCTION(tcm, tcm_alloc_inst, tcm_alloc); 2308 2308 2309 - static int tcm_init(void) 2309 + static int __init tcm_init(void) 2310 2310 { 2311 2311 int ret; 2312 2312 ··· 2322 2322 } 2323 2323 module_init(tcm_init); 2324 2324 2325 - static void tcm_exit(void) 2325 + static void __exit tcm_exit(void) 2326 2326 { 2327 2327 target_unregister_template(&usbg_ops); 2328 2328 usb_function_unregister(&tcmusb_func);
+35 -2
drivers/usb/gadget/function/f_uvc.c
··· 421 421 int ret; 422 422 423 423 /* TODO reference counting. */ 424 - memset(&uvc->vdev, 0, sizeof(uvc->video)); 424 + memset(&uvc->vdev, 0, sizeof(uvc->vdev)); 425 425 uvc->vdev.v4l2_dev = &uvc->v4l2_dev; 426 426 uvc->vdev.v4l2_dev->dev = &cdev->gadget->dev; 427 427 uvc->vdev.fops = &uvc_v4l2_fops; ··· 430 430 uvc->vdev.vfl_dir = VFL_DIR_TX; 431 431 uvc->vdev.lock = &uvc->video.mutex; 432 432 uvc->vdev.device_caps = V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_STREAMING; 433 - strlcpy(uvc->vdev.name, cdev->gadget->name, sizeof(uvc->vdev.name)); 433 + strscpy(uvc->vdev.name, cdev->gadget->name, sizeof(uvc->vdev.name)); 434 434 435 435 video_set_drvdata(&uvc->vdev, uvc); 436 436 ··· 888 888 struct uvc_device *uvc = to_uvc(f); 889 889 struct f_uvc_opts *opts = container_of(f->fi, struct f_uvc_opts, 890 890 func_inst); 891 + config_item_put(&uvc->header->item); 891 892 --opts->refcnt; 892 893 kfree(uvc); 893 894 } ··· 898 897 { 899 898 struct usb_composite_dev *cdev = c->cdev; 900 899 struct uvc_device *uvc = to_uvc(f); 900 + struct uvc_video *video = &uvc->video; 901 901 long wait_ret = 1; 902 902 903 903 uvcg_info(f, "%s()\n", __func__); 904 + 905 + if (video->async_wq) 906 + destroy_workqueue(video->async_wq); 904 907 905 908 /* 906 909 * If we know we're connected via v4l2, then there should be a cleanup ··· 946 941 struct uvc_device *uvc; 947 942 struct f_uvc_opts *opts; 948 943 struct uvc_descriptor_header **strm_cls; 944 + struct config_item *streaming, *header, *h; 949 945 950 946 uvc = kzalloc(sizeof(*uvc), GFP_KERNEL); 951 947 if (uvc == NULL) ··· 979 973 uvc->desc.fs_streaming = opts->fs_streaming; 980 974 uvc->desc.hs_streaming = opts->hs_streaming; 981 975 uvc->desc.ss_streaming = opts->ss_streaming; 976 + 977 + streaming = config_group_find_item(&opts->func_inst.group, "streaming"); 978 + if (!streaming) 979 + goto err_config; 980 + 981 + header = config_group_find_item(to_config_group(streaming), "header"); 982 + config_item_put(streaming); 983 + if (!header) 984 + goto err_config; 985 + 986 + h = config_group_find_item(to_config_group(header), "h"); 987 + config_item_put(header); 988 + if (!h) 989 + goto err_config; 990 + 991 + uvc->header = to_uvcg_streaming_header(h); 992 + if (!uvc->header->linked) { 993 + mutex_unlock(&opts->lock); 994 + kfree(uvc); 995 + return ERR_PTR(-EBUSY); 996 + } 997 + 982 998 ++opts->refcnt; 983 999 mutex_unlock(&opts->lock); 984 1000 ··· 1016 988 uvc->func.bind_deactivated = true; 1017 989 1018 990 return &uvc->func; 991 + 992 + err_config: 993 + mutex_unlock(&opts->lock); 994 + kfree(uvc); 995 + return ERR_PTR(-ENOENT); 1019 996 } 1020 997 1021 998 DECLARE_USB_FUNCTION_INIT(uvc, uvc_alloc_inst, uvc_alloc);
+2 -2
drivers/usb/gadget/function/rndis.c
··· 869 869 870 870 static inline int rndis_get_nr(void) 871 871 { 872 - return ida_simple_get(&rndis_ida, 0, 0, GFP_KERNEL); 872 + return ida_simple_get(&rndis_ida, 0, 1000, GFP_KERNEL); 873 873 } 874 874 875 875 static inline void rndis_put_nr(int nr) ··· 1105 1105 "used : %s\n" 1106 1106 "state : %s\n" 1107 1107 "medium : 0x%08X\n" 1108 - "speed : %d\n" 1108 + "speed : %u\n" 1109 1109 "cable : %s\n" 1110 1110 "vendor ID : 0x%08X\n" 1111 1111 "vendor : %s\n",
+4 -4
drivers/usb/gadget/function/u_ether.c
··· 144 144 { 145 145 struct eth_dev *dev = netdev_priv(net); 146 146 147 - strlcpy(p->driver, "g_ether", sizeof(p->driver)); 148 - strlcpy(p->version, UETH__VERSION, sizeof(p->version)); 149 - strlcpy(p->fw_version, dev->gadget->name, sizeof(p->fw_version)); 150 - strlcpy(p->bus_info, dev_name(&dev->gadget->dev), sizeof(p->bus_info)); 147 + strscpy(p->driver, "g_ether", sizeof(p->driver)); 148 + strscpy(p->version, UETH__VERSION, sizeof(p->version)); 149 + strscpy(p->fw_version, dev->gadget->name, sizeof(p->fw_version)); 150 + strscpy(p->bus_info, dev_name(&dev->gadget->dev), sizeof(p->bus_info)); 151 151 } 152 152 153 153 /* REVISIT can also support:
+2 -2
drivers/usb/gadget/function/u_serial.c
··· 1443 1443 } 1444 1444 EXPORT_SYMBOL_GPL(gserial_resume); 1445 1445 1446 - static int userial_init(void) 1446 + static int __init userial_init(void) 1447 1447 { 1448 1448 struct tty_driver *driver; 1449 1449 unsigned i; ··· 1496 1496 } 1497 1497 module_init(userial_init); 1498 1498 1499 - static void userial_cleanup(void) 1499 + static void __exit userial_cleanup(void) 1500 1500 { 1501 1501 tty_unregister_driver(gs_tty_driver); 1502 1502 tty_driver_kref_put(gs_tty_driver);
+3
drivers/usb/gadget/function/uvc.h
··· 88 88 struct usb_ep *ep; 89 89 90 90 struct work_struct pump; 91 + struct workqueue_struct *async_wq; 91 92 92 93 /* Frame parameters */ 93 94 u8 bpp; ··· 133 132 struct uvc_video video; 134 133 bool func_connected; 135 134 wait_queue_head_t func_connected_queue; 135 + 136 + struct uvcg_streaming_header *header; 136 137 137 138 /* Descriptors */ 138 139 struct {
+290 -4
drivers/usb/gadget/function/uvc_v4l2.c
··· 18 18 #include <media/v4l2-dev.h> 19 19 #include <media/v4l2-event.h> 20 20 #include <media/v4l2-ioctl.h> 21 + #include <media/v4l2-uvc.h> 21 22 22 23 #include "f_uvc.h" 23 24 #include "uvc.h" 24 25 #include "uvc_queue.h" 25 26 #include "uvc_video.h" 26 27 #include "uvc_v4l2.h" 28 + #include "uvc_configfs.h" 29 + 30 + static struct uvc_format_desc *to_uvc_format(struct uvcg_format *uformat) 31 + { 32 + char guid[16] = UVC_GUID_FORMAT_MJPEG; 33 + struct uvc_format_desc *format; 34 + struct uvcg_uncompressed *unc; 35 + 36 + if (uformat->type == UVCG_UNCOMPRESSED) { 37 + unc = to_uvcg_uncompressed(&uformat->group.cg_item); 38 + if (!unc) 39 + return ERR_PTR(-EINVAL); 40 + 41 + memcpy(guid, unc->desc.guidFormat, sizeof(guid)); 42 + } 43 + 44 + format = uvc_format_by_guid(guid); 45 + if (!format) 46 + return ERR_PTR(-EINVAL); 47 + 48 + return format; 49 + } 50 + 51 + static int uvc_v4l2_get_bytesperline(struct uvcg_format *uformat, 52 + struct uvcg_frame *uframe) 53 + { 54 + struct uvcg_uncompressed *u; 55 + 56 + if (uformat->type == UVCG_UNCOMPRESSED) { 57 + u = to_uvcg_uncompressed(&uformat->group.cg_item); 58 + if (!u) 59 + return 0; 60 + 61 + return u->desc.bBitsPerPixel * uframe->frame.w_width / 8; 62 + } 63 + 64 + return 0; 65 + } 66 + 67 + static int uvc_get_frame_size(struct uvcg_format *uformat, 68 + struct uvcg_frame *uframe) 69 + { 70 + unsigned int bpl = uvc_v4l2_get_bytesperline(uformat, uframe); 71 + 72 + return bpl ? bpl * uframe->frame.w_height : 73 + uframe->frame.dw_max_video_frame_buffer_size; 74 + } 75 + 76 + static struct uvcg_format *find_format_by_index(struct uvc_device *uvc, int index) 77 + { 78 + struct uvcg_format_ptr *format; 79 + struct uvcg_format *uformat = NULL; 80 + int i = 1; 81 + 82 + list_for_each_entry(format, &uvc->header->formats, entry) { 83 + if (index == i) { 84 + uformat = format->fmt; 85 + break; 86 + } 87 + i++; 88 + } 89 + 90 + return uformat; 91 + } 92 + 93 + static struct uvcg_frame *find_frame_by_index(struct uvc_device *uvc, 94 + struct uvcg_format *uformat, 95 + int index) 96 + { 97 + struct uvcg_format_ptr *format; 98 + struct uvcg_frame_ptr *frame; 99 + struct uvcg_frame *uframe = NULL; 100 + 101 + list_for_each_entry(format, &uvc->header->formats, entry) { 102 + if (format->fmt->type != uformat->type) 103 + continue; 104 + list_for_each_entry(frame, &format->fmt->frames, entry) { 105 + if (index == frame->frm->frame.b_frame_index) { 106 + uframe = frame->frm; 107 + break; 108 + } 109 + } 110 + } 111 + 112 + return uframe; 113 + } 114 + 115 + static struct uvcg_format *find_format_by_pix(struct uvc_device *uvc, 116 + u32 pixelformat) 117 + { 118 + struct uvcg_format_ptr *format; 119 + struct uvcg_format *uformat = NULL; 120 + 121 + list_for_each_entry(format, &uvc->header->formats, entry) { 122 + struct uvc_format_desc *fmtdesc = to_uvc_format(format->fmt); 123 + 124 + if (fmtdesc->fcc == pixelformat) { 125 + uformat = format->fmt; 126 + break; 127 + } 128 + } 129 + 130 + return uformat; 131 + } 132 + 133 + static struct uvcg_frame *find_closest_frame_by_size(struct uvc_device *uvc, 134 + struct uvcg_format *uformat, 135 + u16 rw, u16 rh) 136 + { 137 + struct uvc_video *video = &uvc->video; 138 + struct uvcg_format_ptr *format; 139 + struct uvcg_frame_ptr *frame; 140 + struct uvcg_frame *uframe = NULL; 141 + unsigned int d, maxd; 142 + 143 + /* Find the closest image size. The distance between image sizes is 144 + * the size in pixels of the non-overlapping regions between the 145 + * requested size and the frame-specified size. 146 + */ 147 + maxd = (unsigned int)-1; 148 + 149 + list_for_each_entry(format, &uvc->header->formats, entry) { 150 + if (format->fmt->type != uformat->type) 151 + continue; 152 + 153 + list_for_each_entry(frame, &format->fmt->frames, entry) { 154 + u16 w, h; 155 + 156 + w = frame->frm->frame.w_width; 157 + h = frame->frm->frame.w_height; 158 + 159 + d = min(w, rw) * min(h, rh); 160 + d = w*h + rw*rh - 2*d; 161 + if (d < maxd) { 162 + maxd = d; 163 + uframe = frame->frm; 164 + } 165 + 166 + if (maxd == 0) 167 + break; 168 + } 169 + } 170 + 171 + if (!uframe) 172 + uvcg_dbg(&video->uvc->func, "Unsupported size %ux%u\n", rw, rh); 173 + 174 + return uframe; 175 + } 27 176 28 177 /* -------------------------------------------------------------------------- 29 178 * Requests handling ··· 216 67 struct uvc_device *uvc = video_get_drvdata(vdev); 217 68 struct usb_composite_dev *cdev = uvc->func.config->cdev; 218 69 219 - strlcpy(cap->driver, "g_uvc", sizeof(cap->driver)); 220 - strlcpy(cap->card, cdev->gadget->name, sizeof(cap->card)); 221 - strlcpy(cap->bus_info, dev_name(&cdev->gadget->dev), 70 + strscpy(cap->driver, "g_uvc", sizeof(cap->driver)); 71 + strscpy(cap->card, cdev->gadget->name, sizeof(cap->card)); 72 + strscpy(cap->bus_info, dev_name(&cdev->gadget->dev), 222 73 sizeof(cap->bus_info)); 223 74 return 0; 224 75 } ··· 284 135 } 285 136 286 137 static int 138 + uvc_v4l2_try_format(struct file *file, void *fh, struct v4l2_format *fmt) 139 + { 140 + struct video_device *vdev = video_devdata(file); 141 + struct uvc_device *uvc = video_get_drvdata(vdev); 142 + struct uvc_video *video = &uvc->video; 143 + struct uvcg_format *uformat; 144 + struct uvcg_frame *uframe; 145 + u8 *fcc; 146 + 147 + if (fmt->type != video->queue.queue.type) 148 + return -EINVAL; 149 + 150 + fcc = (u8 *)&fmt->fmt.pix.pixelformat; 151 + uvcg_dbg(&uvc->func, "Trying format 0x%08x (%c%c%c%c): %ux%u\n", 152 + fmt->fmt.pix.pixelformat, 153 + fcc[0], fcc[1], fcc[2], fcc[3], 154 + fmt->fmt.pix.width, fmt->fmt.pix.height); 155 + 156 + uformat = find_format_by_pix(uvc, fmt->fmt.pix.pixelformat); 157 + if (!uformat) 158 + return -EINVAL; 159 + 160 + uframe = find_closest_frame_by_size(uvc, uformat, 161 + fmt->fmt.pix.width, fmt->fmt.pix.height); 162 + if (!uframe) 163 + return -EINVAL; 164 + 165 + fmt->fmt.pix.width = uframe->frame.w_width; 166 + fmt->fmt.pix.height = uframe->frame.w_height; 167 + fmt->fmt.pix.field = V4L2_FIELD_NONE; 168 + fmt->fmt.pix.bytesperline = uvc_v4l2_get_bytesperline(uformat, uframe); 169 + fmt->fmt.pix.sizeimage = uvc_get_frame_size(uformat, uframe); 170 + fmt->fmt.pix.pixelformat = to_uvc_format(uformat)->fcc; 171 + fmt->fmt.pix.colorspace = V4L2_COLORSPACE_SRGB; 172 + fmt->fmt.pix.priv = 0; 173 + 174 + return 0; 175 + } 176 + 177 + static int 178 + uvc_v4l2_enum_frameintervals(struct file *file, void *fh, 179 + struct v4l2_frmivalenum *fival) 180 + { 181 + struct video_device *vdev = video_devdata(file); 182 + struct uvc_device *uvc = video_get_drvdata(vdev); 183 + struct uvcg_format *uformat = NULL; 184 + struct uvcg_frame *uframe = NULL; 185 + struct uvcg_frame_ptr *frame; 186 + 187 + uformat = find_format_by_pix(uvc, fival->pixel_format); 188 + if (!uformat) 189 + return -EINVAL; 190 + 191 + list_for_each_entry(frame, &uformat->frames, entry) { 192 + if (frame->frm->frame.w_width == fival->width && 193 + frame->frm->frame.w_height == fival->height) { 194 + uframe = frame->frm; 195 + break; 196 + } 197 + } 198 + if (!uframe) 199 + return -EINVAL; 200 + 201 + if (fival->index >= uframe->frame.b_frame_interval_type) 202 + return -EINVAL; 203 + 204 + fival->discrete.numerator = 205 + uframe->dw_frame_interval[fival->index]; 206 + 207 + /* TODO: handle V4L2_FRMIVAL_TYPE_STEPWISE */ 208 + fival->type = V4L2_FRMIVAL_TYPE_DISCRETE; 209 + fival->discrete.denominator = 10000000; 210 + v4l2_simplify_fraction(&fival->discrete.numerator, 211 + &fival->discrete.denominator, 8, 333); 212 + 213 + return 0; 214 + } 215 + 216 + static int 217 + uvc_v4l2_enum_framesizes(struct file *file, void *fh, 218 + struct v4l2_frmsizeenum *fsize) 219 + { 220 + struct video_device *vdev = video_devdata(file); 221 + struct uvc_device *uvc = video_get_drvdata(vdev); 222 + struct uvcg_format *uformat = NULL; 223 + struct uvcg_frame *uframe = NULL; 224 + 225 + uformat = find_format_by_pix(uvc, fsize->pixel_format); 226 + if (!uformat) 227 + return -EINVAL; 228 + 229 + if (fsize->index >= uformat->num_frames) 230 + return -EINVAL; 231 + 232 + uframe = find_frame_by_index(uvc, uformat, fsize->index + 1); 233 + if (!uframe) 234 + return -EINVAL; 235 + 236 + fsize->type = V4L2_FRMSIZE_TYPE_DISCRETE; 237 + fsize->discrete.width = uframe->frame.w_width; 238 + fsize->discrete.height = uframe->frame.w_height; 239 + 240 + return 0; 241 + } 242 + 243 + static int 244 + uvc_v4l2_enum_format(struct file *file, void *fh, struct v4l2_fmtdesc *f) 245 + { 246 + struct video_device *vdev = video_devdata(file); 247 + struct uvc_device *uvc = video_get_drvdata(vdev); 248 + struct uvc_format_desc *fmtdesc; 249 + struct uvcg_format *uformat; 250 + 251 + if (f->index >= uvc->header->num_fmt) 252 + return -EINVAL; 253 + 254 + uformat = find_format_by_index(uvc, f->index + 1); 255 + if (!uformat) 256 + return -EINVAL; 257 + 258 + if (uformat->type != UVCG_UNCOMPRESSED) 259 + f->flags |= V4L2_FMT_FLAG_COMPRESSED; 260 + 261 + fmtdesc = to_uvc_format(uformat); 262 + f->pixelformat = fmtdesc->fcc; 263 + 264 + strscpy(f->description, fmtdesc->name, sizeof(f->description)); 265 + f->description[strlen(fmtdesc->name) - 1] = 0; 266 + 267 + return 0; 268 + } 269 + 270 + static int 287 271 uvc_v4l2_reqbufs(struct file *file, void *fh, struct v4l2_requestbuffers *b) 288 272 { 289 273 struct video_device *vdev = video_devdata(file); ··· 452 170 return ret; 453 171 454 172 if (uvc->state == UVC_STATE_STREAMING) 455 - schedule_work(&video->pump); 173 + queue_work(video->async_wq, &video->pump); 456 174 457 175 return ret; 458 176 } ··· 580 298 581 299 const struct v4l2_ioctl_ops uvc_v4l2_ioctl_ops = { 582 300 .vidioc_querycap = uvc_v4l2_querycap, 301 + .vidioc_try_fmt_vid_out = uvc_v4l2_try_format, 583 302 .vidioc_g_fmt_vid_out = uvc_v4l2_get_format, 584 303 .vidioc_s_fmt_vid_out = uvc_v4l2_set_format, 304 + .vidioc_enum_frameintervals = uvc_v4l2_enum_frameintervals, 305 + .vidioc_enum_framesizes = uvc_v4l2_enum_framesizes, 306 + .vidioc_enum_fmt_vid_out = uvc_v4l2_enum_format, 585 307 .vidioc_reqbufs = uvc_v4l2_reqbufs, 586 308 .vidioc_querybuf = uvc_v4l2_querybuf, 587 309 .vidioc_qbuf = uvc_v4l2_qbuf,
+7 -2
drivers/usb/gadget/function/uvc_video.c
··· 277 277 spin_unlock_irqrestore(&video->req_lock, flags); 278 278 279 279 if (uvc->state == UVC_STATE_STREAMING) 280 - schedule_work(&video->pump); 280 + queue_work(video->async_wq, &video->pump); 281 281 } 282 282 283 283 static int ··· 485 485 486 486 video->req_int_count = 0; 487 487 488 - schedule_work(&video->pump); 488 + queue_work(video->async_wq, &video->pump); 489 489 490 490 return ret; 491 491 } ··· 498 498 INIT_LIST_HEAD(&video->req_free); 499 499 spin_lock_init(&video->req_lock); 500 500 INIT_WORK(&video->pump, uvcg_video_pump); 501 + 502 + /* Allocate a work queue for asynchronous video pump handler. */ 503 + video->async_wq = alloc_workqueue("uvcgadget", WQ_UNBOUND | WQ_HIGHPRI, 0); 504 + if (!video->async_wq) 505 + return -EINVAL; 501 506 502 507 video->uvc = uvc; 503 508 video->fcc = V4L2_PIX_FMT_YUYV;
+6 -4
drivers/usb/gadget/udc/at91_udc.c
··· 994 994 .udc_stop = at91_stop, 995 995 996 996 /* 997 - * VBUS-powered devices may also also want to support bigger 997 + * VBUS-powered devices may also want to support bigger 998 998 * power budgets after an appropriate SET_CONFIGURATION. 999 999 */ 1000 1000 /* .vbus_power = at91_vbus_power, */ ··· 1779 1779 if (of_property_read_u32(np, "atmel,vbus-polled", &val) == 0) 1780 1780 board->vbus_polled = 1; 1781 1781 1782 - board->vbus_pin = gpiod_get_from_of_node(np, "atmel,vbus-gpio", 0, 1783 - GPIOD_IN, "udc_vbus"); 1782 + board->vbus_pin = fwnode_gpiod_get_index(of_fwnode_handle(np), 1783 + "atmel,vbus", 0, GPIOD_IN, 1784 + "udc_vbus"); 1784 1785 if (IS_ERR(board->vbus_pin)) 1785 1786 board->vbus_pin = NULL; 1786 1787 1787 - board->pullup_pin = gpiod_get_from_of_node(np, "atmel,pullup-gpio", 0, 1788 + board->pullup_pin = fwnode_gpiod_get_index(of_fwnode_handle(np), 1789 + "atmel,pullup", 0, 1788 1790 GPIOD_ASIS, "udc_pullup"); 1789 1791 if (IS_ERR(board->pullup_pin)) 1790 1792 board->pullup_pin = NULL;
+2 -2
drivers/usb/gadget/udc/net2272.c
··· 91 91 * mode 2 == ep-a 1k, ep-b 1k, ep-c 512db 92 92 * mode 3 == ep-a 1k, ep-b disabled, ep-c 512db 93 93 */ 94 - static ushort fifo_mode = 0; 94 + static ushort fifo_mode; 95 95 module_param(fifo_mode, ushort, 0644); 96 96 97 97 /* ··· 100 100 * USB suspend requests will be ignored. This is acceptable for 101 101 * self-powered devices. For bus powered devices set this to 1. 102 102 */ 103 - static ushort enable_suspend = 0; 103 + static ushort enable_suspend; 104 104 module_param(enable_suspend, ushort, 0644); 105 105 106 106 static void assert_out_naking(struct net2272_ep *ep, const char *where)
+2 -2
drivers/usb/gadget/udc/omap_udc.c
··· 2234 2234 char *ctrl_name = "(UNKNOWN)"; 2235 2235 2236 2236 tmp = omap_readl(OTG_REV); 2237 - ctrl_name = "tranceiver_ctrl"; 2237 + ctrl_name = "transceiver_ctrl"; 2238 2238 trans = omap_readw(USB_TRANSCEIVER_CTRL); 2239 2239 seq_printf(s, "\nOTG rev %d.%d, %s %05x\n", 2240 2240 tmp >> 4, tmp & 0xf, ctrl_name, trans); ··· 2558 2558 2559 2559 /* set up driver data structures */ 2560 2560 BUG_ON(strlen(name) >= sizeof ep->name); 2561 - strlcpy(ep->name, name, sizeof ep->name); 2561 + strscpy(ep->name, name, sizeof(ep->name)); 2562 2562 INIT_LIST_HEAD(&ep->queue); 2563 2563 INIT_LIST_HEAD(&ep->iso); 2564 2564 ep->bEndpointAddress = addr;
+104 -27
drivers/usb/gadget/udc/renesas_usb3.c
··· 17 17 #include <linux/phy/phy.h> 18 18 #include <linux/platform_device.h> 19 19 #include <linux/pm_runtime.h> 20 + #include <linux/reset.h> 20 21 #include <linux/sizes.h> 21 22 #include <linux/slab.h> 22 23 #include <linux/string.h> ··· 39 38 #define USB3_USB20_CON 0x204 40 39 #define USB3_USB30_CON 0x208 41 40 #define USB3_USB_STA 0x210 42 - #define USB3_DRD_CON 0x218 41 + #define USB3_DRD_CON(p) ((p)->is_rzv2m ? 0x400 : 0x218) 43 42 #define USB3_USB_INT_STA_1 0x220 44 43 #define USB3_USB_INT_STA_2 0x224 45 44 #define USB3_USB_INT_ENA_1 0x228 46 45 #define USB3_USB_INT_ENA_2 0x22c 47 46 #define USB3_STUP_DAT_0 0x230 48 47 #define USB3_STUP_DAT_1 0x234 49 - #define USB3_USB_OTG_STA 0x268 50 - #define USB3_USB_OTG_INT_STA 0x26c 51 - #define USB3_USB_OTG_INT_ENA 0x270 48 + #define USB3_USB_OTG_STA(p) ((p)->is_rzv2m ? 0x410 : 0x268) 49 + #define USB3_USB_OTG_INT_STA(p) ((p)->is_rzv2m ? 0x414 : 0x26c) 50 + #define USB3_USB_OTG_INT_ENA(p) ((p)->is_rzv2m ? 0x418 : 0x270) 52 51 #define USB3_P0_MOD 0x280 53 52 #define USB3_P0_CON 0x288 54 53 #define USB3_P0_STA 0x28c ··· 136 135 #define USB_STA_VBUS_STA BIT(0) 137 136 138 137 /* DRD_CON */ 138 + #define DRD_CON_PERI_RST BIT(31) /* rzv2m only */ 139 + #define DRD_CON_HOST_RST BIT(30) /* rzv2m only */ 139 140 #define DRD_CON_PERI_CON BIT(24) 140 141 #define DRD_CON_VBOUT BIT(0) 141 142 ··· 158 155 #define USB_INT_2_PIPE(n) BIT(n) 159 156 160 157 /* USB_OTG_STA, USB_OTG_INT_STA and USB_OTG_INT_ENA */ 161 - #define USB_OTG_IDMON BIT(4) 158 + #define USB_OTG_IDMON(p) ((p)->is_rzv2m ? BIT(0) : BIT(4)) 162 159 163 160 /* P0_MOD */ 164 161 #define P0_MOD_DIR BIT(6) ··· 258 255 #define USB3_EP0_SS_MAX_PACKET_SIZE 512 259 256 #define USB3_EP0_HSFS_MAX_PACKET_SIZE 64 260 257 #define USB3_EP0_BUF_SIZE 8 261 - #define USB3_MAX_NUM_PIPES 6 /* This includes PIPE 0 */ 258 + #define USB3_MAX_NUM_PIPES(p) ((p)->is_rzv2m ? 16 : 6) /* This includes PIPE 0 */ 262 259 #define USB3_WAIT_US 3 263 260 #define USB3_DMA_NUM_SETTING_AREA 4 264 261 /* ··· 329 326 int num_ramif; 330 327 int ramsize_per_pipe; /* unit = bytes */ 331 328 bool workaround_for_vbus; /* if true, don't check vbus signal */ 329 + bool is_rzv2m; /* if true, RZ/V2M SoC */ 332 330 }; 333 331 334 332 struct renesas_usb3 { 335 333 void __iomem *reg; 334 + struct reset_control *drd_rstc; 335 + struct reset_control *usbp_rstc; 336 336 337 337 struct usb_gadget gadget; 338 338 struct usb_gadget_driver *driver; ··· 369 363 bool forced_b_device; 370 364 bool start_to_connect; 371 365 bool role_sw_by_connector; 366 + bool is_rzv2m; 372 367 }; 373 368 374 369 #define gadget_to_renesas_usb3(_gadget) \ ··· 474 467 475 468 static bool usb3_is_host(struct renesas_usb3 *usb3) 476 469 { 477 - return !(usb3_read(usb3, USB3_DRD_CON) & DRD_CON_PERI_CON); 470 + return !(usb3_read(usb3, USB3_DRD_CON(usb3)) & DRD_CON_PERI_CON); 478 471 } 479 472 480 473 static void usb3_init_axi_bridge(struct renesas_usb3 *usb3) ··· 681 674 682 675 static void usb3_set_mode(struct renesas_usb3 *usb3, bool host) 683 676 { 677 + if (usb3->is_rzv2m) { 678 + if (host) { 679 + usb3_set_bit(usb3, DRD_CON_PERI_RST, USB3_DRD_CON(usb3)); 680 + usb3_clear_bit(usb3, DRD_CON_HOST_RST, USB3_DRD_CON(usb3)); 681 + } else { 682 + usb3_set_bit(usb3, DRD_CON_HOST_RST, USB3_DRD_CON(usb3)); 683 + usb3_clear_bit(usb3, DRD_CON_PERI_RST, USB3_DRD_CON(usb3)); 684 + } 685 + } 686 + 684 687 if (host) 685 - usb3_clear_bit(usb3, DRD_CON_PERI_CON, USB3_DRD_CON); 688 + usb3_clear_bit(usb3, DRD_CON_PERI_CON, USB3_DRD_CON(usb3)); 686 689 else 687 - usb3_set_bit(usb3, DRD_CON_PERI_CON, USB3_DRD_CON); 690 + usb3_set_bit(usb3, DRD_CON_PERI_CON, USB3_DRD_CON(usb3)); 688 691 } 689 692 690 693 static void usb3_set_mode_by_role_sw(struct renesas_usb3 *usb3, bool host) ··· 710 693 static void usb3_vbus_out(struct renesas_usb3 *usb3, bool enable) 711 694 { 712 695 if (enable) 713 - usb3_set_bit(usb3, DRD_CON_VBOUT, USB3_DRD_CON); 696 + usb3_set_bit(usb3, DRD_CON_VBOUT, USB3_DRD_CON(usb3)); 714 697 else 715 - usb3_clear_bit(usb3, DRD_CON_VBOUT, USB3_DRD_CON); 698 + usb3_clear_bit(usb3, DRD_CON_VBOUT, USB3_DRD_CON(usb3)); 716 699 } 717 700 718 701 static void usb3_mode_config(struct renesas_usb3 *usb3, bool host, bool a_dev) ··· 733 716 734 717 static bool usb3_is_a_device(struct renesas_usb3 *usb3) 735 718 { 736 - return !(usb3_read(usb3, USB3_USB_OTG_STA) & USB_OTG_IDMON); 719 + return !(usb3_read(usb3, USB3_USB_OTG_STA(usb3)) & USB_OTG_IDMON(usb3)); 737 720 } 738 721 739 722 static void usb3_check_id(struct renesas_usb3 *usb3) ··· 756 739 usb3_set_bit(usb3, USB_COM_CON_PN_WDATAIF_NL | 757 740 USB_COM_CON_PN_RDATAIF_NL | USB_COM_CON_PN_LSTTR_PP, 758 741 USB3_USB_COM_CON); 759 - usb3_write(usb3, USB_OTG_IDMON, USB3_USB_OTG_INT_STA); 760 - usb3_write(usb3, USB_OTG_IDMON, USB3_USB_OTG_INT_ENA); 742 + usb3_write(usb3, USB_OTG_IDMON(usb3), USB3_USB_OTG_INT_STA(usb3)); 743 + usb3_write(usb3, USB_OTG_IDMON(usb3), USB3_USB_OTG_INT_ENA(usb3)); 761 744 762 745 usb3_check_id(usb3); 763 746 usb3_check_vbus(usb3); ··· 767 750 { 768 751 usb3_disconnect(usb3); 769 752 usb3_write(usb3, 0, USB3_P0_INT_ENA); 770 - usb3_write(usb3, 0, USB3_USB_OTG_INT_ENA); 753 + usb3_write(usb3, 0, USB3_USB_OTG_INT_ENA(usb3)); 771 754 usb3_write(usb3, 0, USB3_USB_INT_ENA_1); 772 755 usb3_write(usb3, 0, USB3_USB_INT_ENA_2); 773 756 usb3_write(usb3, 0, USB3_AXI_INT_ENA); ··· 2022 2005 usb3_check_id(usb3); 2023 2006 } 2024 2007 2025 - static void usb3_irq_otg_int(struct renesas_usb3 *usb3, u32 otg_int_sta) 2008 + static void usb3_irq_otg_int(struct renesas_usb3 *usb3) 2026 2009 { 2027 - if (otg_int_sta & USB_OTG_IDMON) 2010 + u32 otg_int_sta = usb3_read(usb3, USB3_USB_OTG_INT_STA(usb3)); 2011 + 2012 + otg_int_sta &= usb3_read(usb3, USB3_USB_OTG_INT_ENA(usb3)); 2013 + if (otg_int_sta) 2014 + usb3_write(usb3, otg_int_sta, USB3_USB_OTG_INT_STA(usb3)); 2015 + 2016 + if (otg_int_sta & USB_OTG_IDMON(usb3)) 2028 2017 usb3_irq_idmon_change(usb3); 2029 2018 } 2030 2019 ··· 2038 2015 { 2039 2016 u32 int_sta_1 = usb3_read(usb3, USB3_USB_INT_STA_1); 2040 2017 u32 int_sta_2 = usb3_read(usb3, USB3_USB_INT_STA_2); 2041 - u32 otg_int_sta = usb3_read(usb3, USB3_USB_OTG_INT_STA); 2042 2018 2043 2019 int_sta_1 &= usb3_read(usb3, USB3_USB_INT_ENA_1); 2044 2020 if (int_sta_1) { ··· 2049 2027 if (int_sta_2) 2050 2028 usb3_irq_epc_int_2(usb3, int_sta_2); 2051 2029 2052 - otg_int_sta &= usb3_read(usb3, USB3_USB_OTG_INT_ENA); 2053 - if (otg_int_sta) { 2054 - usb3_write(usb3, otg_int_sta, USB3_USB_OTG_INT_STA); 2055 - usb3_irq_otg_int(usb3, otg_int_sta); 2056 - } 2030 + if (!usb3->is_rzv2m) 2031 + usb3_irq_otg_int(usb3); 2057 2032 } 2058 2033 2059 2034 static void usb3_irq_dma_int(struct renesas_usb3 *usb3, u32 dma_sta) ··· 2102 2083 } 2103 2084 2104 2085 return ret; 2086 + } 2087 + 2088 + static irqreturn_t renesas_usb3_otg_irq(int irq, void *_usb3) 2089 + { 2090 + struct renesas_usb3 *usb3 = _usb3; 2091 + 2092 + usb3_irq_otg_int(usb3); 2093 + 2094 + return IRQ_HANDLED; 2105 2095 } 2106 2096 2107 2097 static void usb3_write_pn_mod(struct renesas_usb3_ep *usb3_ep, ··· 2599 2571 usb_role_switch_unregister(usb3->role_sw); 2600 2572 2601 2573 usb_del_gadget_udc(&usb3->gadget); 2574 + reset_control_assert(usb3->usbp_rstc); 2575 + reset_control_assert(usb3->drd_rstc); 2602 2576 renesas_usb3_dma_free_prd(usb3, &pdev->dev); 2603 2577 2604 2578 __renesas_usb3_ep_free_request(usb3->ep0_req); ··· 2619 2589 usb3->num_usb3_eps = priv->ramsize_per_ramif * priv->num_ramif * 2 / 2620 2590 priv->ramsize_per_pipe + 1; 2621 2591 2622 - if (usb3->num_usb3_eps > USB3_MAX_NUM_PIPES) 2623 - usb3->num_usb3_eps = USB3_MAX_NUM_PIPES; 2592 + if (usb3->num_usb3_eps > USB3_MAX_NUM_PIPES(usb3)) 2593 + usb3->num_usb3_eps = USB3_MAX_NUM_PIPES(usb3); 2624 2594 2625 2595 usb3->usb3_ep = devm_kcalloc(dev, 2626 2596 usb3->num_usb3_eps, sizeof(*usb3_ep), ··· 2737 2707 .workaround_for_vbus = true, 2738 2708 }; 2739 2709 2710 + static const struct renesas_usb3_priv renesas_usb3_priv_rzv2m = { 2711 + .ramsize_per_ramif = SZ_16K, 2712 + .num_ramif = 1, 2713 + .ramsize_per_pipe = SZ_4K, 2714 + .is_rzv2m = true, 2715 + }; 2716 + 2740 2717 static const struct of_device_id usb3_of_match[] = { 2741 2718 { 2742 2719 .compatible = "renesas,r8a774c0-usb3-peri", ··· 2754 2717 }, { 2755 2718 .compatible = "renesas,r8a77990-usb3-peri", 2756 2719 .data = &renesas_usb3_priv_r8a77990, 2720 + }, { 2721 + .compatible = "renesas,rzv2m-usb3-peri", 2722 + .data = &renesas_usb3_priv_rzv2m, 2757 2723 }, { 2758 2724 .compatible = "renesas,rcar-gen3-usb3-peri", 2759 2725 .data = &renesas_usb3_priv_gen3, ··· 2788 2748 static int renesas_usb3_probe(struct platform_device *pdev) 2789 2749 { 2790 2750 struct renesas_usb3 *usb3; 2791 - int irq, ret; 2751 + int irq, drd_irq, ret; 2792 2752 const struct renesas_usb3_priv *priv; 2793 2753 const struct soc_device_attribute *attr; 2794 2754 ··· 2802 2762 if (irq < 0) 2803 2763 return irq; 2804 2764 2765 + if (priv->is_rzv2m) { 2766 + drd_irq = platform_get_irq_byname(pdev, "drd"); 2767 + if (drd_irq < 0) 2768 + return drd_irq; 2769 + } 2770 + 2805 2771 usb3 = devm_kzalloc(&pdev->dev, sizeof(*usb3), GFP_KERNEL); 2806 2772 if (!usb3) 2807 2773 return -ENOMEM; 2774 + 2775 + usb3->is_rzv2m = priv->is_rzv2m; 2808 2776 2809 2777 usb3->reg = devm_platform_ioremap_resource(pdev, 0); 2810 2778 if (IS_ERR(usb3->reg)) ··· 2834 2786 dev_name(&pdev->dev), usb3); 2835 2787 if (ret < 0) 2836 2788 return ret; 2789 + 2790 + if (usb3->is_rzv2m) { 2791 + ret = devm_request_irq(&pdev->dev, drd_irq, 2792 + renesas_usb3_otg_irq, 0, 2793 + dev_name(&pdev->dev), usb3); 2794 + if (ret < 0) 2795 + return ret; 2796 + } 2837 2797 2838 2798 INIT_WORK(&usb3->extcon_work, renesas_usb3_extcon_work); 2839 2799 usb3->extcon = devm_extcon_dev_allocate(&pdev->dev, renesas_usb3_cable); ··· 2873 2817 goto err_add_udc; 2874 2818 } 2875 2819 2820 + usb3->drd_rstc = devm_reset_control_get_optional_shared(&pdev->dev, 2821 + "drd_reset"); 2822 + if (IS_ERR(usb3->drd_rstc)) { 2823 + ret = PTR_ERR(usb3->drd_rstc); 2824 + goto err_add_udc; 2825 + } 2826 + 2827 + usb3->usbp_rstc = devm_reset_control_get_optional_shared(&pdev->dev, 2828 + "aresetn_p"); 2829 + if (IS_ERR(usb3->usbp_rstc)) { 2830 + ret = PTR_ERR(usb3->usbp_rstc); 2831 + goto err_add_udc; 2832 + } 2833 + 2834 + reset_control_deassert(usb3->drd_rstc); 2835 + reset_control_deassert(usb3->usbp_rstc); 2836 + 2876 2837 pm_runtime_enable(&pdev->dev); 2877 2838 ret = usb_add_gadget_udc(&pdev->dev, &usb3->gadget); 2878 2839 if (ret < 0) 2879 - goto err_add_udc; 2840 + goto err_reset; 2880 2841 2881 2842 ret = device_create_file(&pdev->dev, &dev_attr_role); 2882 2843 if (ret < 0) ··· 2930 2857 2931 2858 err_dev_create: 2932 2859 usb_del_gadget_udc(&usb3->gadget); 2860 + 2861 + err_reset: 2862 + reset_control_assert(usb3->usbp_rstc); 2863 + reset_control_assert(usb3->drd_rstc); 2933 2864 2934 2865 err_add_udc: 2935 2866 renesas_usb3_dma_free_prd(usb3, &pdev->dev);
+32 -46
drivers/usb/gadget/udc/s3c2410_udc.c
··· 23 23 #include <linux/interrupt.h> 24 24 #include <linux/platform_device.h> 25 25 #include <linux/clk.h> 26 - #include <linux/gpio.h> 26 + #include <linux/gpio/consumer.h> 27 27 #include <linux/prefetch.h> 28 28 #include <linux/io.h> 29 29 ··· 1419 1419 { 1420 1420 dprintk(DEBUG_NORMAL, "%s()\n", __func__); 1421 1421 1422 - if (udc_info && (udc_info->udc_command || 1423 - gpio_is_valid(udc_info->pullup_pin))) { 1422 + if (udc_info && (udc_info->udc_command || udc->pullup_gpiod)) { 1424 1423 1425 1424 if (is_on) 1426 1425 s3c2410_udc_enable(udc); ··· 1466 1467 1467 1468 dprintk(DEBUG_NORMAL, "%s()\n", __func__); 1468 1469 1469 - value = gpio_get_value(udc_info->vbus_pin) ? 1 : 0; 1470 - if (udc_info->vbus_pin_inverted) 1471 - value = !value; 1470 + value = gpiod_get_value(dev->vbus_gpiod); 1472 1471 1473 1472 if (value != dev->vbus) 1474 1473 s3c2410_udc_vbus_session(&dev->gadget, value); ··· 1501 1504 .udc_stop = s3c2410_udc_stop, 1502 1505 }; 1503 1506 1504 - static void s3c2410_udc_command(enum s3c2410_udc_cmd_e cmd) 1507 + static void s3c2410_udc_command(struct s3c2410_udc *udc, 1508 + enum s3c2410_udc_cmd_e cmd) 1505 1509 { 1506 1510 if (!udc_info) 1507 1511 return; 1508 1512 1509 1513 if (udc_info->udc_command) { 1510 1514 udc_info->udc_command(cmd); 1511 - } else if (gpio_is_valid(udc_info->pullup_pin)) { 1515 + } else if (udc->pullup_gpiod) { 1512 1516 int value; 1513 1517 1514 1518 switch (cmd) { ··· 1522 1524 default: 1523 1525 return; 1524 1526 } 1525 - value ^= udc_info->pullup_pin_inverted; 1526 1527 1527 - gpio_set_value(udc_info->pullup_pin, value); 1528 + gpiod_set_value(udc->pullup_gpiod, value); 1528 1529 } 1529 1530 } 1530 1531 ··· 1548 1551 udc_write(0x1F, S3C2410_UDC_EP_INT_REG); 1549 1552 1550 1553 /* Good bye, cruel world */ 1551 - s3c2410_udc_command(S3C2410_UDC_P_DISABLE); 1554 + s3c2410_udc_command(dev, S3C2410_UDC_P_DISABLE); 1552 1555 1553 1556 /* Set speed to unknown */ 1554 1557 dev->gadget.speed = USB_SPEED_UNKNOWN; ··· 1610 1613 udc_write(S3C2410_UDC_INT_EP0, S3C2410_UDC_EP_INT_EN_REG); 1611 1614 1612 1615 /* time to say "hello, world" */ 1613 - s3c2410_udc_command(S3C2410_UDC_P_ENABLE); 1616 + s3c2410_udc_command(dev, S3C2410_UDC_P_ENABLE); 1614 1617 } 1615 1618 1616 1619 static int s3c2410_udc_start(struct usb_gadget *g, ··· 1799 1802 1800 1803 dev_dbg(dev, "got irq %i\n", irq_usbd); 1801 1804 1802 - if (udc_info && udc_info->vbus_pin > 0) { 1803 - retval = gpio_request(udc_info->vbus_pin, "udc vbus"); 1804 - if (retval < 0) { 1805 - dev_err(dev, "cannot claim vbus pin\n"); 1806 - goto err_int; 1807 - } 1805 + udc->vbus_gpiod = gpiod_get_optional(dev, "vbus", GPIOD_IN); 1806 + if (IS_ERR(udc->vbus_gpiod)) { 1807 + retval = PTR_ERR(udc->vbus_gpiod); 1808 + goto err_int; 1809 + } 1810 + if (udc->vbus_gpiod) { 1811 + gpiod_set_consumer_name(udc->vbus_gpiod, "udc vbus"); 1808 1812 1809 - irq = gpio_to_irq(udc_info->vbus_pin); 1813 + irq = gpiod_to_irq(udc->vbus_gpiod); 1810 1814 if (irq < 0) { 1811 1815 dev_err(dev, "no irq for gpio vbus pin\n"); 1812 1816 retval = irq; ··· 1831 1833 udc->vbus = 1; 1832 1834 } 1833 1835 1834 - if (udc_info && !udc_info->udc_command && 1835 - gpio_is_valid(udc_info->pullup_pin)) { 1836 - 1837 - retval = gpio_request_one(udc_info->pullup_pin, 1838 - udc_info->vbus_pin_inverted ? 1839 - GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW, 1840 - "udc pullup"); 1841 - if (retval) 1842 - goto err_vbus_irq; 1836 + udc->pullup_gpiod = gpiod_get_optional(dev, "pullup", GPIOD_OUT_LOW); 1837 + if (IS_ERR(udc->pullup_gpiod)) { 1838 + retval = PTR_ERR(udc->pullup_gpiod); 1839 + goto err_vbus_irq; 1843 1840 } 1841 + gpiod_set_consumer_name(udc->pullup_gpiod, "udc pullup"); 1844 1842 1845 1843 retval = usb_add_gadget_udc(&pdev->dev, &udc->gadget); 1846 1844 if (retval) ··· 1850 1856 return 0; 1851 1857 1852 1858 err_add_udc: 1853 - if (udc_info && !udc_info->udc_command && 1854 - gpio_is_valid(udc_info->pullup_pin)) 1855 - gpio_free(udc_info->pullup_pin); 1856 1859 err_vbus_irq: 1857 - if (udc_info && udc_info->vbus_pin > 0) 1858 - free_irq(gpio_to_irq(udc_info->vbus_pin), udc); 1860 + if (udc->vbus_gpiod) 1861 + free_irq(gpiod_to_irq(udc->vbus_gpiod), udc); 1859 1862 err_gpio_claim: 1860 - if (udc_info && udc_info->vbus_pin > 0) 1861 - gpio_free(udc_info->vbus_pin); 1862 1863 err_int: 1863 1864 free_irq(irq_usbd, udc); 1864 1865 err_udc_clk: ··· 1874 1885 static int s3c2410_udc_remove(struct platform_device *pdev) 1875 1886 { 1876 1887 struct s3c2410_udc *udc = platform_get_drvdata(pdev); 1877 - unsigned int irq; 1878 1888 1879 1889 dev_dbg(&pdev->dev, "%s()\n", __func__); 1880 1890 ··· 1883 1895 usb_del_gadget_udc(&udc->gadget); 1884 1896 debugfs_remove(debugfs_lookup("registers", s3c2410_udc_debugfs_root)); 1885 1897 1886 - if (udc_info && !udc_info->udc_command && 1887 - gpio_is_valid(udc_info->pullup_pin)) 1888 - gpio_free(udc_info->pullup_pin); 1889 - 1890 - if (udc_info && udc_info->vbus_pin > 0) { 1891 - irq = gpio_to_irq(udc_info->vbus_pin); 1892 - free_irq(irq, udc); 1893 - } 1898 + if (udc->vbus_gpiod) 1899 + free_irq(gpiod_to_irq(udc->vbus_gpiod), udc); 1894 1900 1895 1901 free_irq(irq_usbd, udc); 1896 1902 ··· 1908 1926 static int 1909 1927 s3c2410_udc_suspend(struct platform_device *pdev, pm_message_t message) 1910 1928 { 1911 - s3c2410_udc_command(S3C2410_UDC_P_DISABLE); 1929 + struct s3c2410_udc *udc = platform_get_drvdata(pdev); 1930 + 1931 + s3c2410_udc_command(udc, S3C2410_UDC_P_DISABLE); 1912 1932 1913 1933 return 0; 1914 1934 } 1915 1935 1916 1936 static int s3c2410_udc_resume(struct platform_device *pdev) 1917 1937 { 1918 - s3c2410_udc_command(S3C2410_UDC_P_ENABLE); 1938 + struct s3c2410_udc *udc = platform_get_drvdata(pdev); 1939 + 1940 + s3c2410_udc_command(udc, S3C2410_UDC_P_ENABLE); 1919 1941 1920 1942 return 0; 1921 1943 }
+3
drivers/usb/gadget/udc/s3c2410_udc.h
··· 83 83 u32 port_status; 84 84 int ep0state; 85 85 86 + struct gpio_desc *vbus_gpiod; 87 + struct gpio_desc *pullup_gpiod; 88 + 86 89 unsigned got_irq : 1; 87 90 88 91 unsigned req_std : 1;
+5 -1
drivers/usb/gadget/udc/tegra-xudc.c
··· 2 2 /* 3 3 * NVIDIA Tegra XUSB device mode controller 4 4 * 5 - * Copyright (c) 2013-2019, NVIDIA CORPORATION. All rights reserved. 5 + * Copyright (c) 2013-2022, NVIDIA CORPORATION. All rights reserved. 6 6 * Copyright (c) 2015, Google Inc. 7 7 */ 8 8 ··· 702 702 703 703 pm_runtime_get_sync(xudc->dev); 704 704 705 + tegra_phy_xusb_utmi_pad_power_on(xudc->curr_utmi_phy); 706 + 705 707 err = phy_power_on(xudc->curr_utmi_phy); 706 708 if (err < 0) 707 709 dev_err(xudc->dev, "UTMI power on failed: %d\n", err); ··· 757 755 758 756 /* Make sure interrupt handler has completed before powergating. */ 759 757 synchronize_irq(xudc->irq); 758 + 759 + tegra_phy_xusb_utmi_pad_power_down(xudc->curr_utmi_phy); 760 760 761 761 err = phy_power_off(xudc->curr_utmi_phy); 762 762 if (err < 0)
+4 -4
drivers/usb/host/Kconfig
··· 205 205 Variation of ARC USB block used in some Freescale chips. 206 206 207 207 config USB_EHCI_HCD_NPCM7XX 208 - tristate "Support for Nuvoton NPCM7XX on-chip EHCI USB controller" 209 - depends on (USB_EHCI_HCD && ARCH_NPCM7XX) || COMPILE_TEST 210 - default y if (USB_EHCI_HCD && ARCH_NPCM7XX) 208 + tristate "Support for Nuvoton NPCM on-chip EHCI USB controller" 209 + depends on (USB_EHCI_HCD && ARCH_NPCM) || COMPILE_TEST 210 + default y if (USB_EHCI_HCD && ARCH_NPCM) 211 211 help 212 212 Enables support for the on-chip EHCI controller on 213 - Nuvoton NPCM7XX chips. 213 + Nuvoton NPCM chips. 214 214 215 215 config USB_EHCI_HCD_OMAP 216 216 tristate "EHCI support for OMAP3 and later chips"
-3
drivers/usb/host/ehci-atmel.c
··· 25 25 26 26 #define DRIVER_DESC "EHCI Atmel driver" 27 27 28 - static const char hcd_name[] = "ehci-atmel"; 29 - 30 28 #define EHCI_INSNREG(index) ((index) * 4 + 0x90) 31 29 #define EHCI_INSNREG08_HSIC_EN BIT(2) 32 30 ··· 237 239 if (usb_disabled()) 238 240 return -ENODEV; 239 241 240 - pr_info("%s: " DRIVER_DESC "\n", hcd_name); 241 242 ehci_init_driver(&ehci_atmel_hc_driver, &ehci_atmel_drv_overrides); 242 243 return platform_driver_register(&ehci_atmel_driver); 243 244 }
+5 -14
drivers/usb/host/ehci-exynos.c
··· 13 13 #include <linux/kernel.h> 14 14 #include <linux/module.h> 15 15 #include <linux/of.h> 16 - #include <linux/of_gpio.h> 16 + #include <linux/gpio/consumer.h> 17 17 #include <linux/phy/phy.h> 18 18 #include <linux/platform_device.h> 19 19 #include <linux/usb.h> ··· 32 32 (EHCI_INSNREG00_ENA_INCR16 | EHCI_INSNREG00_ENA_INCR8 | \ 33 33 EHCI_INSNREG00_ENA_INCR4 | EHCI_INSNREG00_ENA_INCRX_ALIGN) 34 34 35 - static const char hcd_name[] = "ehci-exynos"; 36 35 static struct hc_driver __read_mostly exynos_ehci_hc_driver; 37 36 38 37 #define PHY_NUMBER 3 ··· 131 132 132 133 static void exynos_setup_vbus_gpio(struct device *dev) 133 134 { 135 + struct gpio_desc *gpio; 134 136 int err; 135 - int gpio; 136 137 137 - if (!dev->of_node) 138 - return; 139 - 140 - gpio = of_get_named_gpio(dev->of_node, "samsung,vbus-gpio", 0); 141 - if (!gpio_is_valid(gpio)) 142 - return; 143 - 144 - err = devm_gpio_request_one(dev, gpio, GPIOF_OUT_INIT_HIGH, 145 - "ehci_vbus_gpio"); 138 + gpio = devm_gpiod_get_optional(dev, "samsung,vbus", GPIOD_OUT_HIGH); 139 + err = PTR_ERR_OR_ZERO(gpio); 146 140 if (err) 147 - dev_err(dev, "can't request ehci vbus gpio %d", gpio); 141 + dev_err(dev, "can't request ehci vbus gpio: %d\n", err); 148 142 } 149 143 150 144 static int exynos_ehci_probe(struct platform_device *pdev) ··· 339 347 if (usb_disabled()) 340 348 return -ENODEV; 341 349 342 - pr_info("%s: " DRIVER_DESC "\n", hcd_name); 343 350 ehci_init_driver(&exynos_ehci_hc_driver, &exynos_overrides); 344 351 return platform_driver_register(&exynos_ehci_driver); 345 352 }
-2
drivers/usb/host/ehci-fsl.c
··· 722 722 if (usb_disabled()) 723 723 return -ENODEV; 724 724 725 - pr_info(DRV_NAME ": " DRIVER_DESC "\n"); 726 - 727 725 ehci_init_driver(&fsl_ehci_hc_driver, &ehci_fsl_overrides); 728 726 729 727 fsl_ehci_hc_driver.product_desc =
-1
drivers/usb/host/ehci-hcd.c
··· 1351 1351 if (usb_disabled()) 1352 1352 return -ENODEV; 1353 1353 1354 - printk(KERN_INFO "%s: " DRIVER_DESC "\n", hcd_name); 1355 1354 set_bit(USB_EHCI_LOADED, &usb_hcds_loaded); 1356 1355 if (test_bit(USB_UHCI_LOADED, &usb_hcds_loaded) || 1357 1356 test_bit(USB_OHCI_LOADED, &usb_hcds_loaded))
-53
drivers/usb/host/ehci-npcm7xx.c
··· 22 22 23 23 #include "ehci.h" 24 24 25 - #include <linux/regmap.h> 26 - #include <linux/mfd/syscon.h> 27 - 28 25 #define DRIVER_DESC "EHCI npcm7xx driver" 29 - 30 - static const char hcd_name[] = "npcm7xx-ehci"; 31 - 32 - #define USB2PHYCTL_OFFSET 0x144 33 - 34 - #define IPSRST2_OFFSET 0x24 35 - #define IPSRST3_OFFSET 0x34 36 - 37 26 38 27 static struct hc_driver __read_mostly ehci_npcm7xx_hc_driver; 39 28 ··· 49 60 { 50 61 struct usb_hcd *hcd; 51 62 struct resource *res; 52 - struct regmap *gcr_regmap; 53 - struct regmap *rst_regmap; 54 63 const struct hc_driver *driver = &ehci_npcm7xx_hc_driver; 55 64 int irq; 56 65 int retval; 57 66 58 67 dev_dbg(&pdev->dev, "initializing npcm7xx ehci USB Controller\n"); 59 - 60 - gcr_regmap = syscon_regmap_lookup_by_compatible("nuvoton,npcm750-gcr"); 61 - if (IS_ERR(gcr_regmap)) { 62 - dev_err(&pdev->dev, "%s: failed to find nuvoton,npcm750-gcr\n", 63 - __func__); 64 - return PTR_ERR(gcr_regmap); 65 - } 66 - 67 - rst_regmap = syscon_regmap_lookup_by_compatible("nuvoton,npcm750-rst"); 68 - if (IS_ERR(rst_regmap)) { 69 - dev_err(&pdev->dev, "%s: failed to find nuvoton,npcm750-rst\n", 70 - __func__); 71 - return PTR_ERR(rst_regmap); 72 - } 73 - 74 - /********* phy init ******/ 75 - // reset usb host 76 - regmap_update_bits(rst_regmap, IPSRST2_OFFSET, 77 - (0x1 << 26), (0x1 << 26)); 78 - regmap_update_bits(rst_regmap, IPSRST3_OFFSET, 79 - (0x1 << 25), (0x1 << 25)); 80 - regmap_update_bits(gcr_regmap, USB2PHYCTL_OFFSET, 81 - (0x1 << 28), 0); 82 - 83 - udelay(1); 84 - 85 - // enable phy 86 - regmap_update_bits(rst_regmap, IPSRST3_OFFSET, 87 - (0x1 << 25), 0); 88 - 89 - udelay(50); // enable phy 90 - 91 - regmap_update_bits(gcr_regmap, USB2PHYCTL_OFFSET, 92 - (0x1 << 28), (0x1 << 28)); 93 - 94 - // enable host 95 - regmap_update_bits(rst_regmap, IPSRST2_OFFSET, 96 - (0x1 << 26), 0); 97 68 98 69 if (usb_disabled()) 99 70 return -ENODEV; ··· 139 190 { 140 191 if (usb_disabled()) 141 192 return -ENODEV; 142 - 143 - pr_info("%s: " DRIVER_DESC "\n", hcd_name); 144 193 145 194 ehci_init_driver(&ehci_npcm7xx_hc_driver, NULL); 146 195 return platform_driver_register(&npcm7xx_ehci_hcd_driver);
-2
drivers/usb/host/ehci-omap.c
··· 284 284 if (usb_disabled()) 285 285 return -ENODEV; 286 286 287 - pr_info("%s: " DRIVER_DESC "\n", hcd_name); 288 - 289 287 ehci_init_driver(&ehci_omap_hc_driver, &ehci_omap_overrides); 290 288 return platform_driver_register(&ehci_hcd_omap_driver); 291 289 }
-4
drivers/usb/host/ehci-orion.c
··· 65 65 struct phy *phy; 66 66 }; 67 67 68 - static const char hcd_name[] = "ehci-orion"; 69 - 70 68 static struct hc_driver __read_mostly ehci_orion_hc_driver; 71 69 72 70 /* ··· 358 360 { 359 361 if (usb_disabled()) 360 362 return -ENODEV; 361 - 362 - pr_info("%s: " DRIVER_DESC "\n", hcd_name); 363 363 364 364 ehci_init_driver(&ehci_orion_hc_driver, &orion_overrides); 365 365 return platform_driver_register(&ehci_orion_driver);
+1 -3
drivers/usb/host/ehci-pci.c
··· 382 382 { 383 383 if (is_bypassed_id(pdev)) 384 384 return -ENODEV; 385 - return usb_hcd_pci_probe(pdev, id, &ehci_pci_hc_driver); 385 + return usb_hcd_pci_probe(pdev, &ehci_pci_hc_driver); 386 386 } 387 387 388 388 static void ehci_pci_remove(struct pci_dev *pdev) ··· 422 422 { 423 423 if (usb_disabled()) 424 424 return -ENODEV; 425 - 426 - pr_info("%s: " DRIVER_DESC "\n", hcd_name); 427 425 428 426 ehci_init_driver(&ehci_pci_hc_driver, &pci_overrides); 429 427
-4
drivers/usb/host/ehci-platform.c
··· 53 53 struct delayed_work poll_work; 54 54 }; 55 55 56 - static const char hcd_name[] = "ehci-platform"; 57 - 58 56 static int ehci_platform_reset(struct usb_hcd *hcd) 59 57 { 60 58 struct platform_device *pdev = to_platform_device(hcd->self.controller); ··· 526 528 { 527 529 if (usb_disabled()) 528 530 return -ENODEV; 529 - 530 - pr_info("%s: " DRIVER_DESC "\n", hcd_name); 531 531 532 532 ehci_init_driver(&ehci_platform_hc_driver, &platform_overrides); 533 533 return platform_driver_register(&ehci_platform_driver);
+2 -2
drivers/usb/host/ehci-q.c
··· 645 645 token |= (1 /* "in" */ << 8); 646 646 /* else it's already initted to "out" pid (0 << 8) */ 647 647 648 - maxpacket = usb_maxpacket(urb->dev, urb->pipe); 648 + maxpacket = usb_endpoint_maxp(&urb->ep->desc); 649 649 650 650 /* 651 651 * buffer gets wrapped in one or more qtds; ··· 1218 1218 1219 1219 token |= (1 /* "in" */ << 8); /*This is IN stage*/ 1220 1220 1221 - maxpacket = usb_maxpacket(urb->dev, urb->pipe); 1221 + maxpacket = usb_endpoint_maxp(&urb->ep->desc); 1222 1222 1223 1223 qtd_fill(ehci, qtd, buf, len, token, maxpacket); 1224 1224
-4
drivers/usb/host/ehci-spear.c
··· 24 24 25 25 #define DRIVER_DESC "EHCI SPEAr driver" 26 26 27 - static const char hcd_name[] = "SPEAr-ehci"; 28 - 29 27 struct spear_ehci { 30 28 struct clk *clk; 31 29 }; ··· 164 166 { 165 167 if (usb_disabled()) 166 168 return -ENODEV; 167 - 168 - pr_info("%s: " DRIVER_DESC "\n", hcd_name); 169 169 170 170 ehci_init_driver(&ehci_spear_hc_driver, &spear_overrides); 171 171 return platform_driver_register(&spear_ehci_hcd_driver);
-4
drivers/usb/host/ehci-st.c
··· 42 42 #define hcd_to_ehci_priv(h) \ 43 43 ((struct st_ehci_platform_priv *)hcd_to_ehci(h)->priv) 44 44 45 - static const char hcd_name[] = "ehci-st"; 46 - 47 45 #define EHCI_CAPS_SIZE 0x10 48 46 #define AHB2STBUS_INSREG01 (EHCI_CAPS_SIZE + 0x84) 49 47 ··· 343 345 { 344 346 if (usb_disabled()) 345 347 return -ENODEV; 346 - 347 - pr_info("%s: " DRIVER_DESC "\n", hcd_name); 348 348 349 349 ehci_init_driver(&ehci_platform_hc_driver, &platform_overrides); 350 350 return platform_driver_register(&ehci_platform_driver);
+17 -44
drivers/usb/host/fhci-hcd.c
··· 25 25 #include <linux/of_address.h> 26 26 #include <linux/of_irq.h> 27 27 #include <linux/of_platform.h> 28 - #include <linux/of_gpio.h> 29 28 #include <linux/slab.h> 29 + #include <linux/gpio/consumer.h> 30 30 #include <soc/fsl/qe/qe.h> 31 31 #include <asm/fsl_gtm.h> 32 32 #include "fhci.h" ··· 150 150 u8 bits = 0; 151 151 152 152 /* check USBOE,if transmitting,exit */ 153 - if (!gpio_get_value(fhci->gpios[GPIO_USBOE])) 153 + if (!gpiod_get_value(fhci->gpiods[GPIO_USBOE])) 154 154 return -1; 155 155 156 156 /* check USBRP */ 157 - if (gpio_get_value(fhci->gpios[GPIO_USBRP])) 157 + if (gpiod_get_value(fhci->gpiods[GPIO_USBRP])) 158 158 bits |= 0x2; 159 159 160 160 /* check USBRN */ 161 - if (gpio_get_value(fhci->gpios[GPIO_USBRN])) 161 + if (gpiod_get_value(fhci->gpiods[GPIO_USBRN])) 162 162 bits |= 0x1; 163 163 164 164 return bits; ··· 630 630 631 631 /* GPIOs and pins */ 632 632 for (i = 0; i < NUM_GPIOS; i++) { 633 - int gpio; 634 - enum of_gpio_flags flags; 633 + if (i < GPIO_SPEED) 634 + fhci->gpiods[i] = devm_gpiod_get_index(dev, 635 + NULL, i, GPIOD_IN); 635 636 636 - gpio = of_get_gpio_flags(node, i, &flags); 637 - fhci->gpios[i] = gpio; 638 - fhci->alow_gpios[i] = flags & OF_GPIO_ACTIVE_LOW; 637 + else 638 + fhci->gpiods[i] = devm_gpiod_get_index_optional(dev, 639 + NULL, i, GPIOD_OUT_LOW); 639 640 640 - if (!gpio_is_valid(gpio)) { 641 - if (i < GPIO_SPEED) { 642 - dev_err(dev, "incorrect GPIO%d: %d\n", 643 - i, gpio); 644 - goto err_gpios; 645 - } else { 646 - dev_info(dev, "assuming board doesn't have " 647 - "%s gpio\n", i == GPIO_SPEED ? 648 - "speed" : "power"); 649 - continue; 650 - } 651 - } 652 - 653 - ret = gpio_request(gpio, dev_name(dev)); 654 - if (ret) { 655 - dev_err(dev, "failed to request gpio %d", i); 641 + if (IS_ERR(fhci->gpiods[i])) { 642 + dev_err(dev, "incorrect GPIO%d: %ld\n", 643 + i, PTR_ERR(fhci->gpiods[i])); 656 644 goto err_gpios; 657 645 } 658 - 659 - if (i >= GPIO_SPEED) { 660 - ret = gpio_direction_output(gpio, 0); 661 - if (ret) { 662 - dev_err(dev, "failed to set gpio %d as " 663 - "an output\n", i); 664 - i++; 665 - goto err_gpios; 666 - } 646 + if (!fhci->gpiods[i]) { 647 + dev_info(dev, "assuming board doesn't have " 648 + "%s gpio\n", i == GPIO_SPEED ? 649 + "speed" : "power"); 667 650 } 668 651 } 669 652 ··· 749 766 while (--j >= 0) 750 767 qe_pin_free(fhci->pins[j]); 751 768 err_gpios: 752 - while (--i >= 0) { 753 - if (gpio_is_valid(fhci->gpios[i])) 754 - gpio_free(fhci->gpios[i]); 755 - } 756 769 cpm_muram_free(pram_addr); 757 770 err_pram: 758 771 iounmap(hcd->regs); ··· 761 782 { 762 783 struct usb_hcd *hcd = dev_get_drvdata(dev); 763 784 struct fhci_hcd *fhci = hcd_to_fhci(hcd); 764 - int i; 765 785 int j; 766 786 767 787 usb_remove_hcd(hcd); 768 788 free_irq(fhci->timer->irq, hcd); 769 789 gtm_put_timer16(fhci->timer); 770 790 cpm_muram_free(cpm_muram_offset(fhci->pram)); 771 - for (i = 0; i < NUM_GPIOS; i++) { 772 - if (!gpio_is_valid(fhci->gpios[i])) 773 - continue; 774 - gpio_free(fhci->gpios[i]); 775 - } 776 791 for (j = 0; j < NUM_PINS; j++) 777 792 qe_pin_free(fhci->pins[j]); 778 793 fhci_dfs_destroy(fhci);
+7 -8
drivers/usb/host/fhci-hub.c
··· 19 19 #include <linux/io.h> 20 20 #include <linux/usb.h> 21 21 #include <linux/usb/hcd.h> 22 - #include <linux/gpio.h> 22 + #include <linux/gpio/consumer.h> 23 23 #include <soc/fsl/qe/qe.h> 24 24 #include "fhci.h" 25 25 ··· 38 38 39 39 static void fhci_gpio_set_value(struct fhci_hcd *fhci, int gpio_nr, bool on) 40 40 { 41 - int gpio = fhci->gpios[gpio_nr]; 42 - bool alow = fhci->alow_gpios[gpio_nr]; 41 + struct gpio_desc *gpiod = fhci->gpiods[gpio_nr]; 43 42 44 - if (!gpio_is_valid(gpio)) 43 + if (!gpiod) 45 44 return; 46 45 47 - gpio_set_value(gpio, on ^ alow); 46 + gpiod_set_value(gpiod, on); 48 47 mdelay(5); 49 48 } 50 49 ··· 128 129 { 129 130 fhci_dbg(fhci, "-> %s\n", __func__); 130 131 131 - gpio_direction_output(fhci->gpios[GPIO_USBOE], 0); 132 - gpio_direction_output(fhci->gpios[GPIO_USBTP], 0); 133 - gpio_direction_output(fhci->gpios[GPIO_USBTN], 0); 132 + gpiod_direction_output(fhci->gpiods[GPIO_USBOE], 0); 133 + gpiod_direction_output(fhci->gpiods[GPIO_USBTP], 0); 134 + gpiod_direction_output(fhci->gpiods[GPIO_USBTN], 0); 134 135 135 136 mdelay(5); 136 137
+2 -2
drivers/usb/host/fhci.h
··· 23 23 #include <linux/io.h> 24 24 #include <linux/usb.h> 25 25 #include <linux/usb/hcd.h> 26 + #include <linux/gpio/consumer.h> 26 27 #include <soc/fsl/qe/qe.h> 27 28 #include <soc/fsl/qe/immap_qe.h> 28 29 ··· 243 242 enum qe_clock fullspeed_clk; 244 243 enum qe_clock lowspeed_clk; 245 244 struct qe_pin *pins[NUM_PINS]; 246 - int gpios[NUM_GPIOS]; 247 - bool alow_gpios[NUM_GPIOS]; 245 + struct gpio_desc *gpiods[NUM_GPIOS]; 248 246 249 247 struct qe_usb_ctlr __iomem *regs; /* I/O memory used to communicate */ 250 248 struct fhci_pram __iomem *pram; /* Parameter RAM */
-1
drivers/usb/host/fotg210-hcd.c
··· 5692 5692 if (usb_disabled()) 5693 5693 return -ENODEV; 5694 5694 5695 - pr_info("%s: " DRIVER_DESC "\n", hcd_name); 5696 5695 set_bit(USB_EHCI_LOADED, &usb_hcds_loaded); 5697 5696 if (test_bit(USB_UHCI_LOADED, &usb_hcds_loaded) || 5698 5697 test_bit(USB_OHCI_LOADED, &usb_hcds_loaded))
-3
drivers/usb/host/ohci-at91.c
··· 62 62 63 63 #define DRIVER_DESC "OHCI Atmel driver" 64 64 65 - static const char hcd_name[] = "ohci-atmel"; 66 - 67 65 static struct hc_driver __read_mostly ohci_at91_hc_driver; 68 66 69 67 static const struct ohci_driver_overrides ohci_at91_drv_overrides __initconst = { ··· 697 699 if (usb_disabled()) 698 700 return -ENODEV; 699 701 700 - pr_info("%s: " DRIVER_DESC "\n", hcd_name); 701 702 ohci_init_driver(&ohci_at91_hc_driver, &ohci_at91_drv_overrides); 702 703 703 704 /*
-1
drivers/usb/host/ohci-da8xx.c
··· 551 551 if (usb_disabled()) 552 552 return -ENODEV; 553 553 554 - pr_info("%s: " DRIVER_DESC "\n", DRV_NAME); 555 554 ohci_init_driver(&ohci_da8xx_hc_driver, &da8xx_overrides); 556 555 557 556 /*
-2
drivers/usb/host/ohci-exynos.c
··· 21 21 22 22 #define DRIVER_DESC "OHCI Exynos driver" 23 23 24 - static const char hcd_name[] = "ohci-exynos"; 25 24 static struct hc_driver __read_mostly exynos_ohci_hc_driver; 26 25 27 26 #define to_exynos_ohci(hcd) (struct exynos_ohci_hcd *)(hcd_to_ohci(hcd)->priv) ··· 309 310 if (usb_disabled()) 310 311 return -ENODEV; 311 312 312 - pr_info("%s: " DRIVER_DESC "\n", hcd_name); 313 313 ohci_init_driver(&exynos_ohci_hc_driver, &exynos_overrides); 314 314 return platform_driver_register(&exynos_ohci_driver); 315 315 }
-1
drivers/usb/host/ohci-hcd.c
··· 1276 1276 if (usb_disabled()) 1277 1277 return -ENODEV; 1278 1278 1279 - printk(KERN_INFO "%s: " DRIVER_DESC "\n", hcd_name); 1280 1279 pr_debug ("%s: block sizes: ed %zd td %zd\n", hcd_name, 1281 1280 sizeof (struct ed), sizeof (struct td)); 1282 1281 set_bit(USB_OHCI_LOADED, &usb_hcds_loaded);
-2
drivers/usb/host/ohci-nxp.c
··· 275 275 if (usb_disabled()) 276 276 return -ENODEV; 277 277 278 - pr_info("%s: " DRIVER_DESC "\n", hcd_name); 279 - 280 278 ohci_init_driver(&ohci_nxp_hc_driver, NULL); 281 279 return platform_driver_register(&ohci_hcd_nxp_driver); 282 280 }
-2
drivers/usb/host/ohci-omap.c
··· 423 423 if (usb_disabled()) 424 424 return -ENODEV; 425 425 426 - pr_info("%s: " DRIVER_DESC "\n", hcd_name); 427 - 428 426 ohci_init_driver(&ohci_omap_hc_driver, &omap_overrides); 429 427 return platform_driver_register(&ohci_hcd_omap_driver); 430 428 }
+1 -3
drivers/usb/host/ohci-pci.c
··· 282 282 283 283 static int ohci_pci_probe(struct pci_dev *dev, const struct pci_device_id *id) 284 284 { 285 - return usb_hcd_pci_probe(dev, id, &ohci_pci_hc_driver); 285 + return usb_hcd_pci_probe(dev, &ohci_pci_hc_driver); 286 286 } 287 287 288 288 /* pci driver glue; this is a "new style" PCI driver module */ ··· 305 305 { 306 306 if (usb_disabled()) 307 307 return -ENODEV; 308 - 309 - pr_info("%s: " DRIVER_DESC "\n", hcd_name); 310 308 311 309 ohci_init_driver(&ohci_pci_hc_driver, &pci_overrides); 312 310
+24 -8
drivers/usb/host/ohci-platform.c
··· 41 41 struct reset_control *resets; 42 42 }; 43 43 44 - static const char hcd_name[] = "ohci-platform"; 45 - 46 44 static int ohci_platform_power_on(struct platform_device *dev) 47 45 { 48 46 struct usb_hcd *hcd = platform_get_drvdata(dev); ··· 287 289 return ret; 288 290 } 289 291 290 - static int ohci_platform_resume(struct device *dev) 292 + static int ohci_platform_resume_common(struct device *dev, bool hibernated) 291 293 { 292 294 struct usb_hcd *hcd = dev_get_drvdata(dev); 293 295 struct usb_ohci_pdata *pdata = dev_get_platdata(dev); ··· 299 301 return err; 300 302 } 301 303 302 - ohci_resume(hcd, false); 304 + ohci_resume(hcd, hibernated); 303 305 304 306 pm_runtime_disable(dev); 305 307 pm_runtime_set_active(dev); 306 308 pm_runtime_enable(dev); 307 309 308 310 return 0; 311 + } 312 + 313 + static int ohci_platform_resume(struct device *dev) 314 + { 315 + return ohci_platform_resume_common(dev, false); 316 + } 317 + 318 + static int ohci_platform_restore(struct device *dev) 319 + { 320 + return ohci_platform_resume_common(dev, true); 309 321 } 310 322 #endif /* CONFIG_PM_SLEEP */ 311 323 ··· 333 325 }; 334 326 MODULE_DEVICE_TABLE(platform, ohci_platform_table); 335 327 336 - static SIMPLE_DEV_PM_OPS(ohci_platform_pm_ops, ohci_platform_suspend, 337 - ohci_platform_resume); 328 + #ifdef CONFIG_PM_SLEEP 329 + static const struct dev_pm_ops ohci_platform_pm_ops = { 330 + .suspend = ohci_platform_suspend, 331 + .resume = ohci_platform_resume, 332 + .freeze = ohci_platform_suspend, 333 + .thaw = ohci_platform_resume, 334 + .poweroff = ohci_platform_suspend, 335 + .restore = ohci_platform_restore, 336 + }; 337 + #endif 338 338 339 339 static struct platform_driver ohci_platform_driver = { 340 340 .id_table = ohci_platform_table, ··· 351 335 .shutdown = usb_hcd_platform_shutdown, 352 336 .driver = { 353 337 .name = "ohci-platform", 338 + #ifdef CONFIG_PM_SLEEP 354 339 .pm = &ohci_platform_pm_ops, 340 + #endif 355 341 .of_match_table = ohci_platform_ids, 356 342 .probe_type = PROBE_PREFER_ASYNCHRONOUS, 357 343 } ··· 363 345 { 364 346 if (usb_disabled()) 365 347 return -ENODEV; 366 - 367 - pr_info("%s: " DRIVER_DESC "\n", hcd_name); 368 348 369 349 ohci_init_driver(&ohci_platform_hc_driver, &platform_overrides); 370 350 return platform_driver_register(&ohci_platform_driver);
-4
drivers/usb/host/ohci-pxa27x.c
··· 114 114 115 115 #define PXA_UHC_MAX_PORTNUM 3 116 116 117 - static const char hcd_name[] = "ohci-pxa27x"; 118 - 119 117 static struct hc_driver __read_mostly ohci_pxa27x_hc_driver; 120 118 121 119 struct pxa27x_ohci { ··· 605 607 { 606 608 if (usb_disabled()) 607 609 return -ENODEV; 608 - 609 - pr_info("%s: " DRIVER_DESC "\n", hcd_name); 610 610 611 611 ohci_init_driver(&ohci_pxa27x_hc_driver, &pxa27x_overrides); 612 612 ohci_pxa27x_hc_driver.hub_control = pxa27x_ohci_hub_control;
-3
drivers/usb/host/ohci-s3c2410.c
··· 39 39 40 40 #define DRIVER_DESC "OHCI S3C2410 driver" 41 41 42 - static const char hcd_name[] = "ohci-s3c2410"; 43 - 44 42 static struct clk *clk; 45 43 static struct clk *usb_clk; 46 44 ··· 472 474 if (usb_disabled()) 473 475 return -ENODEV; 474 476 475 - pr_info("%s: " DRIVER_DESC "\n", hcd_name); 476 477 ohci_init_driver(&ohci_s3c2410_hc_driver, NULL); 477 478 478 479 /*
-3
drivers/usb/host/ohci-spear.c
··· 23 23 24 24 #define DRIVER_DESC "OHCI SPEAr driver" 25 25 26 - static const char hcd_name[] = "SPEAr-ohci"; 27 26 struct spear_ohci { 28 27 struct clk *clk; 29 28 }; ··· 177 178 { 178 179 if (usb_disabled()) 179 180 return -ENODEV; 180 - 181 - pr_info("%s: " DRIVER_DESC "\n", hcd_name); 182 181 183 182 ohci_init_driver(&ohci_spear_hc_driver, &spear_overrides); 184 183 return platform_driver_register(&spear_ohci_hcd_driver);
-4
drivers/usb/host/ohci-st.c
··· 40 40 #define hcd_to_ohci_priv(h) \ 41 41 ((struct st_ohci_platform_priv *)hcd_to_ohci(h)->priv) 42 42 43 - static const char hcd_name[] = "ohci-st"; 44 - 45 43 static int st_ohci_platform_power_on(struct platform_device *dev) 46 44 { 47 45 struct usb_hcd *hcd = platform_get_drvdata(dev); ··· 321 323 { 322 324 if (usb_disabled()) 323 325 return -ENODEV; 324 - 325 - pr_info("%s: " DRIVER_DESC "\n", hcd_name); 326 326 327 327 ohci_init_driver(&ohci_platform_hc_driver, &platform_overrides); 328 328 return platform_driver_register(&ohci_platform_driver);
-1
drivers/usb/host/u132-hcd.c
··· 3190 3190 u132_exiting = 0; 3191 3191 if (usb_disabled()) 3192 3192 return -ENODEV; 3193 - printk(KERN_INFO "driver %s\n", hcd_name); 3194 3193 workqueue = create_singlethread_workqueue("u132"); 3195 3194 if (!workqueue) 3196 3195 return -ENOMEM;
-2
drivers/usb/host/uhci-hcd.c
··· 867 867 if (usb_disabled()) 868 868 return -ENODEV; 869 869 870 - printk(KERN_INFO "uhci_hcd: " DRIVER_DESC "%s\n", 871 - ignore_oc ? ", overcurrent ignored" : ""); 872 870 set_bit(USB_UHCI_LOADED, &usb_hcds_loaded); 873 871 874 872 #ifdef CONFIG_DYNAMIC_DEBUG
+1 -1
drivers/usb/host/uhci-pci.c
··· 294 294 295 295 static int uhci_pci_probe(struct pci_dev *dev, const struct pci_device_id *id) 296 296 { 297 - return usb_hcd_pci_probe(dev, id, &uhci_driver); 297 + return usb_hcd_pci_probe(dev, &uhci_driver); 298 298 } 299 299 300 300 static struct pci_driver uhci_pci_driver = {
+1 -1
drivers/usb/host/xhci-dbgcap.c
··· 988 988 dbc->driver = driver; 989 989 990 990 if (readl(&dbc->regs->control) & DBC_CTRL_DBC_ENABLE) 991 - return NULL; 991 + goto err; 992 992 993 993 INIT_DELAYED_WORK(&dbc->event_work, xhci_dbc_handle_events); 994 994 spin_lock_init(&dbc->lock);
+6 -1
drivers/usb/host/xhci-mem.c
··· 641 641 num_stream_ctxs, &stream_info->ctx_array_dma, 642 642 mem_flags); 643 643 if (!stream_info->stream_ctx_array) 644 - goto cleanup_ctx; 644 + goto cleanup_ring_array; 645 645 memset(stream_info->stream_ctx_array, 0, 646 646 sizeof(struct xhci_stream_ctx)*num_stream_ctxs); 647 647 ··· 702 702 } 703 703 xhci_free_command(xhci, stream_info->free_streams_command); 704 704 cleanup_ctx: 705 + xhci_free_stream_ctx(xhci, 706 + stream_info->num_stream_ctxs, 707 + stream_info->stream_ctx_array, 708 + stream_info->ctx_array_dma); 709 + cleanup_ring_array: 705 710 kfree(stream_info->stream_rings); 706 711 cleanup_info: 707 712 kfree(stream_info);
+1 -1
drivers/usb/host/xhci-pci.c
··· 431 431 * to say USB 2.0, but I'm not sure what the implications would be in 432 432 * the other parts of the HCD code. 433 433 */ 434 - retval = usb_hcd_pci_probe(dev, id, &xhci_pci_hc_driver); 434 + retval = usb_hcd_pci_probe(dev, &xhci_pci_hc_driver); 435 435 436 436 if (retval) 437 437 goto put_runtime_pm;
+16 -2
drivers/usb/host/xhci-plat.c
··· 123 123 }; 124 124 125 125 static const struct xhci_plat_priv xhci_plat_brcm = { 126 - .quirks = XHCI_RESET_ON_RESUME, 126 + .quirks = XHCI_RESET_ON_RESUME | XHCI_SUSPEND_RESUME_CLKS, 127 127 }; 128 128 129 129 static const struct of_device_id usb_xhci_of_match[] = { ··· 437 437 * xhci_suspend() needs `do_wakeup` to know whether host is allowed 438 438 * to do wakeup during suspend. 439 439 */ 440 - return xhci_suspend(xhci, device_may_wakeup(dev)); 440 + ret = xhci_suspend(xhci, device_may_wakeup(dev)); 441 + if (ret) 442 + return ret; 443 + 444 + if (!device_may_wakeup(dev) && (xhci->quirks & XHCI_SUSPEND_RESUME_CLKS)) { 445 + clk_disable_unprepare(xhci->clk); 446 + clk_disable_unprepare(xhci->reg_clk); 447 + } 448 + 449 + return 0; 441 450 } 442 451 443 452 static int __maybe_unused xhci_plat_resume(struct device *dev) ··· 454 445 struct usb_hcd *hcd = dev_get_drvdata(dev); 455 446 struct xhci_hcd *xhci = hcd_to_xhci(hcd); 456 447 int ret; 448 + 449 + if (!device_may_wakeup(dev) && (xhci->quirks & XHCI_SUSPEND_RESUME_CLKS)) { 450 + clk_prepare_enable(xhci->clk); 451 + clk_prepare_enable(xhci->reg_clk); 452 + } 457 453 458 454 ret = xhci_priv_resume_quirk(hcd); 459 455 if (ret)
+5 -3
drivers/usb/host/xhci.c
··· 1183 1183 /* re-initialize the HC on Restore Error, or Host Controller Error */ 1184 1184 if (temp & (STS_SRE | STS_HCE)) { 1185 1185 reinit_xhc = true; 1186 - xhci_warn(xhci, "xHC error in resume, USBSTS 0x%x, Reinit\n", temp); 1186 + if (!xhci->broken_suspend) 1187 + xhci_warn(xhci, "xHC error in resume, USBSTS 0x%x, Reinit\n", temp); 1187 1188 } 1188 1189 1189 1190 if (reinit_xhc) { ··· 1483 1482 /* The reverse operation to xhci_get_endpoint_index. Calculate the USB endpoint 1484 1483 * address from the XHCI endpoint index. 1485 1484 */ 1486 - unsigned int xhci_get_endpoint_address(unsigned int ep_index) 1485 + static unsigned int xhci_get_endpoint_address(unsigned int ep_index) 1487 1486 { 1488 1487 unsigned int number = DIV_ROUND_UP(ep_index, 2); 1489 1488 unsigned int direction = ep_index % 2 ? USB_DIR_OUT : USB_DIR_IN; ··· 4096 4095 slot_id = command->slot_id; 4097 4096 4098 4097 if (!slot_id || command->status != COMP_SUCCESS) { 4099 - xhci_err(xhci, "Error while assigning device slot ID\n"); 4098 + xhci_err(xhci, "Error while assigning device slot ID: %s\n", 4099 + xhci_trb_comp_code_string(command->status)); 4100 4100 xhci_err(xhci, "Max number of devices this xHCI host supports is %u.\n", 4101 4101 HCS_MAX_SLOTS( 4102 4102 readl(&xhci->cap_regs->hcs_params1)));
+1 -4
drivers/usb/host/xhci.h
··· 1807 1807 struct xhci_erst erst; 1808 1808 /* Scratchpad */ 1809 1809 struct xhci_scratchpad *scratchpad; 1810 - /* Store LPM test failed devices' information */ 1811 - struct list_head lpm_failed_devs; 1812 1810 1813 1811 /* slot enabling and address device helpers */ 1814 1812 /* these are not thread safe so use mutex */ ··· 1825 1827 /* Host controller watchdog timer structures */ 1826 1828 unsigned int xhc_state; 1827 1829 unsigned long run_graceperiod; 1828 - u32 command; 1829 1830 struct s3_save s3; 1830 1831 /* Host controller is dying - not responding to commands. "I'm not dead yet!" 1831 1832 * ··· 1896 1899 #define XHCI_NO_SOFT_RETRY BIT_ULL(40) 1897 1900 #define XHCI_BROKEN_D3COLD BIT_ULL(41) 1898 1901 #define XHCI_EP_CTX_BROKEN_DCS BIT_ULL(42) 1902 + #define XHCI_SUSPEND_RESUME_CLKS BIT_ULL(43) 1899 1903 1900 1904 unsigned int num_active_eps; 1901 1905 unsigned int limit_active_eps; ··· 2039 2041 void xhci_copy_ep0_dequeue_into_input_ctx(struct xhci_hcd *xhci, 2040 2042 struct usb_device *udev); 2041 2043 unsigned int xhci_get_endpoint_index(struct usb_endpoint_descriptor *desc); 2042 - unsigned int xhci_get_endpoint_address(unsigned int ep_index); 2043 2044 unsigned int xhci_last_valid_endpoint(u32 added_ctxs); 2044 2045 void xhci_endpoint_zero(struct xhci_hcd *xhci, struct xhci_virt_device *virt_dev, struct usb_host_endpoint *ep); 2045 2046 void xhci_update_tt_active_eps(struct xhci_hcd *xhci,
+4 -4
drivers/usb/misc/idmouse.c
··· 177 177 bytes_read += bulk_read; 178 178 } 179 179 180 - /* reset the device */ 181 - reset: 182 - ftip_command(dev, FTIP_RELEASE, 0, 0); 183 - 184 180 /* check for valid image */ 185 181 /* right border should be black (0x00) */ 186 182 for (bytes_read = sizeof(HEADER)-1 + WIDTH-1; bytes_read < IMGSIZE; bytes_read += WIDTH) ··· 187 191 for (bytes_read = IMGSIZE-WIDTH; bytes_read < IMGSIZE-1; bytes_read++) 188 192 if (dev->bulk_in_buffer[bytes_read] != 0xFF) 189 193 return -EAGAIN; 194 + 195 + /* reset the device */ 196 + reset: 197 + ftip_command(dev, FTIP_RELEASE, 0, 0); 190 198 191 199 /* should be IMGSIZE == 65040 */ 192 200 dev_dbg(&dev->interface->dev, "read %d bytes fingerprint data\n",
+7 -11
drivers/usb/misc/usb251xb.c
··· 400 400 { 401 401 struct device *dev = hub->dev; 402 402 struct device_node *np = dev->of_node; 403 - int len, err; 403 + int len; 404 404 u32 property_u32 = 0; 405 405 const char *cproperty_char; 406 406 char str[USB251XB_STRING_BUFSIZE / 2]; ··· 416 416 hub->skip_config = 0; 417 417 418 418 hub->gpio_reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH); 419 - if (PTR_ERR(hub->gpio_reset) == -EPROBE_DEFER) { 420 - return -EPROBE_DEFER; 421 - } else if (IS_ERR(hub->gpio_reset)) { 422 - err = PTR_ERR(hub->gpio_reset); 423 - dev_err(dev, "unable to request GPIO reset pin (%d)\n", err); 424 - return err; 425 - } 419 + if (IS_ERR(hub->gpio_reset)) 420 + return dev_err_probe(dev, PTR_ERR(hub->gpio_reset), 421 + "unable to request GPIO reset pin\n"); 426 422 427 423 if (of_property_read_u16_array(np, "vendor-id", &hub->vendor_id, 1)) 428 424 hub->vendor_id = USB251XB_DEF_VENDOR_ID; ··· 543 547 hub->boost_up = USB251XB_DEF_BOOST_UP; 544 548 545 549 cproperty_char = of_get_property(np, "manufacturer", NULL); 546 - strlcpy(str, cproperty_char ? : USB251XB_DEF_MANUFACTURER_STRING, 550 + strscpy(str, cproperty_char ? : USB251XB_DEF_MANUFACTURER_STRING, 547 551 sizeof(str)); 548 552 hub->manufacturer_len = strlen(str) & 0xFF; 549 553 memset(hub->manufacturer, 0, USB251XB_STRING_BUFSIZE); ··· 553 557 USB251XB_STRING_BUFSIZE); 554 558 555 559 cproperty_char = of_get_property(np, "product", NULL); 556 - strlcpy(str, cproperty_char ? : data->product_str, sizeof(str)); 560 + strscpy(str, cproperty_char ? : data->product_str, sizeof(str)); 557 561 hub->product_len = strlen(str) & 0xFF; 558 562 memset(hub->product, 0, USB251XB_STRING_BUFSIZE); 559 563 len = min_t(size_t, USB251XB_STRING_BUFSIZE / 2, strlen(str)); ··· 562 566 USB251XB_STRING_BUFSIZE); 563 567 564 568 cproperty_char = of_get_property(np, "serial", NULL); 565 - strlcpy(str, cproperty_char ? : USB251XB_DEF_SERIAL_STRING, 569 + strscpy(str, cproperty_char ? : USB251XB_DEF_SERIAL_STRING, 566 570 sizeof(str)); 567 571 hub->serial_len = strlen(str) & 0xFF; 568 572 memset(hub->serial, 0, USB251XB_STRING_BUFSIZE);
+19 -6
drivers/usb/misc/usb3503.c
··· 160 160 struct usb3503_platform_data *pdata = dev_get_platdata(dev); 161 161 struct device_node *np = dev->of_node; 162 162 int err; 163 + bool is_clk_enabled = false; 163 164 u32 mode = USB3503_MODE_HUB; 164 165 const u32 *property; 165 166 enum gpiod_flags flags; ··· 218 217 return err; 219 218 } 220 219 220 + is_clk_enabled = true; 221 221 property = of_get_property(np, "disabled-ports", &len); 222 222 if (property && (len / sizeof(u32)) > 0) { 223 223 int i; ··· 238 236 else 239 237 flags = GPIOD_OUT_HIGH; 240 238 hub->intn = devm_gpiod_get_optional(dev, "intn", flags); 241 - if (IS_ERR(hub->intn)) 242 - return PTR_ERR(hub->intn); 239 + if (IS_ERR(hub->intn)) { 240 + err = PTR_ERR(hub->intn); 241 + goto err_clk; 242 + } 243 243 if (hub->intn) 244 244 gpiod_set_consumer_name(hub->intn, "usb3503 intn"); 245 245 246 246 hub->connect = devm_gpiod_get_optional(dev, "connect", GPIOD_OUT_LOW); 247 - if (IS_ERR(hub->connect)) 248 - return PTR_ERR(hub->connect); 247 + if (IS_ERR(hub->connect)) { 248 + err = PTR_ERR(hub->connect); 249 + goto err_clk; 250 + } 249 251 if (hub->connect) 250 252 gpiod_set_consumer_name(hub->connect, "usb3503 connect"); 251 253 252 254 hub->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH); 253 - if (IS_ERR(hub->reset)) 254 - return PTR_ERR(hub->reset); 255 + if (IS_ERR(hub->reset)) { 256 + err = PTR_ERR(hub->reset); 257 + goto err_clk; 258 + } 255 259 if (hub->reset) { 256 260 /* Datasheet defines a hardware reset to be at least 100us */ 257 261 usleep_range(100, 10000); ··· 273 265 (hub->mode == USB3503_MODE_HUB) ? "hub" : "standby"); 274 266 275 267 return 0; 268 + 269 + err_clk: 270 + if (is_clk_enabled) 271 + clk_disable_unprepare(hub->clk); 272 + return err; 276 273 } 277 274 278 275 static int usb3503_i2c_probe(struct i2c_client *i2c,
+4 -4
drivers/usb/misc/uss720.c
··· 502 502 #else 503 503 struct parport_uss720_private *priv = pp->private_data; 504 504 struct usb_device *usbdev = priv->usbdev; 505 - int rlen; 505 + int rlen = 0; 506 506 int i; 507 507 508 508 if (!usbdev) ··· 563 563 { 564 564 struct parport_uss720_private *priv = pp->private_data; 565 565 struct usb_device *usbdev = priv->usbdev; 566 - int rlen; 566 + int rlen = 0; 567 567 int i; 568 568 569 569 if (!usbdev) ··· 581 581 { 582 582 struct parport_uss720_private *priv = pp->private_data; 583 583 struct usb_device *usbdev = priv->usbdev; 584 - int rlen; 584 + int rlen = 0; 585 585 int i; 586 586 587 587 if (!usbdev) ··· 614 614 { 615 615 struct parport_uss720_private *priv = pp->private_data; 616 616 struct usb_device *usbdev = priv->usbdev; 617 - int rlen; 617 + int rlen = 0; 618 618 int i; 619 619 620 620 if (!usbdev)
+5
drivers/usb/mon/mon_bin.c
··· 1268 1268 { 1269 1269 /* don't do anything here: "fault" will set up page table entries */ 1270 1270 vma->vm_ops = &mon_bin_vm_ops; 1271 + 1272 + if (vma->vm_flags & VM_WRITE) 1273 + return -EPERM; 1274 + 1275 + vma->vm_flags &= ~VM_MAYWRITE; 1271 1276 vma->vm_flags |= VM_DONTEXPAND | VM_DONTDUMP; 1272 1277 vma->vm_private_data = filp->private_data; 1273 1278 mon_bin_vma_open(vma);
-2
drivers/usb/mtu3/mtu3_core.c
··· 978 978 goto irq_err; 979 979 } 980 980 981 - device_init_wakeup(dev, true); 982 - 983 981 /* power down device IP for power saving by default */ 984 982 mtu3_stop(mtu); 985 983
+2
drivers/usb/mtu3/mtu3_plat.c
··· 356 356 pm_runtime_enable(dev); 357 357 pm_runtime_get_sync(dev); 358 358 359 + device_init_wakeup(dev, true); 360 + 359 361 ret = ssusb_rscs_init(ssusb); 360 362 if (ret) 361 363 goto comm_init_err;
+3 -5
drivers/usb/musb/da8xx.c
··· 523 523 } 524 524 525 525 glue->phy = devm_phy_get(&pdev->dev, "usb-phy"); 526 - if (IS_ERR(glue->phy)) { 527 - if (PTR_ERR(glue->phy) != -EPROBE_DEFER) 528 - dev_err(&pdev->dev, "failed to get phy\n"); 529 - return PTR_ERR(glue->phy); 530 - } 526 + if (IS_ERR(glue->phy)) 527 + return dev_err_probe(&pdev->dev, PTR_ERR(glue->phy), 528 + "failed to get phy\n"); 531 529 532 530 glue->dev = &pdev->dev; 533 531 glue->clk = clk;
+3 -7
drivers/usb/musb/jz4740.c
··· 105 105 .driver_data = glue, 106 106 .fwnode = dev_fwnode(dev), 107 107 }; 108 - int err; 109 108 110 109 glue->musb = musb; 111 110 ··· 112 113 musb->xceiv = devm_usb_get_phy_by_phandle(dev, "phys", 0); 113 114 else 114 115 musb->xceiv = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2); 115 - if (IS_ERR(musb->xceiv)) { 116 - err = PTR_ERR(musb->xceiv); 117 - if (err != -EPROBE_DEFER) 118 - dev_err(dev, "No transceiver configured: %d\n", err); 119 - return err; 120 - } 116 + if (IS_ERR(musb->xceiv)) 117 + return dev_err_probe(dev, PTR_ERR(musb->xceiv), 118 + "No transceiver configured\n"); 121 119 122 120 glue->role_sw = usb_role_switch_register(dev, &role_sw_desc); 123 121 if (IS_ERR(glue->role_sw)) {
+1 -3
drivers/usb/musb/musb_core.c
··· 2595 2595 musb_platform_exit(musb); 2596 2596 2597 2597 fail1: 2598 - if (status != -EPROBE_DEFER) 2599 - dev_err(musb->controller, 2600 - "%s failed with status %d\n", __func__, status); 2598 + dev_err_probe(musb->controller, status, "%s failed\n", __func__); 2601 2599 2602 2600 musb_free(musb); 2603 2601
+2 -4
drivers/usb/musb/musb_cppi41.c
··· 718 718 719 719 dc = dma_request_chan(dev->parent, str); 720 720 if (IS_ERR(dc)) { 721 - ret = PTR_ERR(dc); 722 - if (ret != -EPROBE_DEFER) 723 - dev_err(dev, "Failed to request %s: %d.\n", 724 - str, ret); 721 + ret = dev_err_probe(dev, PTR_ERR(dc), 722 + "Failed to request %s.\n", str); 725 723 goto err; 726 724 } 727 725
+3
drivers/usb/musb/musb_gadget.c
··· 760 760 musb_writew(epio, MUSB_RXCSR, csr); 761 761 762 762 buffer_aint_mapped: 763 + fifo_count = min_t(unsigned int, 764 + request->length - request->actual, 765 + (unsigned int)fifo_count); 763 766 musb_read_fifo(musb_ep->hw_ep, fifo_count, (u8 *) 764 767 (request->buf + request->actual)); 765 768 request->actual += fifo_count;
+9 -20
drivers/usb/musb/sunxi.c
··· 743 743 744 744 if (test_bit(SUNXI_MUSB_FL_HAS_RESET, &glue->flags)) { 745 745 glue->rst = devm_reset_control_get(&pdev->dev, NULL); 746 - if (IS_ERR(glue->rst)) { 747 - if (PTR_ERR(glue->rst) == -EPROBE_DEFER) 748 - return -EPROBE_DEFER; 749 - dev_err(&pdev->dev, "Error getting reset %ld\n", 750 - PTR_ERR(glue->rst)); 751 - return PTR_ERR(glue->rst); 752 - } 746 + if (IS_ERR(glue->rst)) 747 + return dev_err_probe(&pdev->dev, PTR_ERR(glue->rst), 748 + "Error getting reset\n"); 753 749 } 754 750 755 751 glue->extcon = extcon_get_edev_by_phandle(&pdev->dev, 0); 756 - if (IS_ERR(glue->extcon)) { 757 - if (PTR_ERR(glue->extcon) == -EPROBE_DEFER) 758 - return -EPROBE_DEFER; 759 - dev_err(&pdev->dev, "Invalid or missing extcon\n"); 760 - return PTR_ERR(glue->extcon); 761 - } 752 + if (IS_ERR(glue->extcon)) 753 + return dev_err_probe(&pdev->dev, PTR_ERR(glue->extcon), 754 + "Invalid or missing extcon\n"); 762 755 763 756 glue->phy = devm_phy_get(&pdev->dev, "usb"); 764 - if (IS_ERR(glue->phy)) { 765 - if (PTR_ERR(glue->phy) == -EPROBE_DEFER) 766 - return -EPROBE_DEFER; 767 - dev_err(&pdev->dev, "Error getting phy %ld\n", 768 - PTR_ERR(glue->phy)); 769 - return PTR_ERR(glue->phy); 770 - } 757 + if (IS_ERR(glue->phy)) 758 + return dev_err_probe(&pdev->dev, PTR_ERR(glue->phy), 759 + "Error getting phy\n"); 771 760 772 761 glue->usb_phy = usb_phy_generic_register(); 773 762 if (IS_ERR(glue->usb_phy)) {
+3 -6
drivers/usb/phy/phy-generic.c
··· 230 230 err = PTR_ERR_OR_ZERO(nop->gpiod_vbus); 231 231 } 232 232 233 - if (err == -EPROBE_DEFER) 234 - return -EPROBE_DEFER; 235 - if (err) { 236 - dev_err(dev, "Error requesting RESET or VBUS GPIO\n"); 237 - return err; 238 - } 233 + if (err) 234 + return dev_err_probe(dev, err, 235 + "Error requesting RESET or VBUS GPIO\n"); 239 236 if (nop->gpiod_reset) 240 237 gpiod_direction_output(nop->gpiod_reset, 1); 241 238
+8 -17
drivers/usb/phy/phy-jz4770.c
··· 321 321 } 322 322 323 323 priv->clk = devm_clk_get(dev, NULL); 324 - if (IS_ERR(priv->clk)) { 325 - err = PTR_ERR(priv->clk); 326 - if (err != -EPROBE_DEFER) 327 - dev_err(dev, "Failed to get clock\n"); 328 - return err; 329 - } 324 + if (IS_ERR(priv->clk)) 325 + return dev_err_probe(dev, PTR_ERR(priv->clk), 326 + "Failed to get clock\n"); 330 327 331 328 priv->vcc_supply = devm_regulator_get(dev, "vcc"); 332 - if (IS_ERR(priv->vcc_supply)) { 333 - err = PTR_ERR(priv->vcc_supply); 334 - if (err != -EPROBE_DEFER) 335 - dev_err(dev, "Failed to get regulator\n"); 336 - return err; 337 - } 329 + if (IS_ERR(priv->vcc_supply)) 330 + return dev_err_probe(dev, PTR_ERR(priv->vcc_supply), 331 + "Failed to get regulator\n"); 338 332 339 333 err = usb_add_phy(&priv->phy, USB_PHY_TYPE_USB2); 340 - if (err) { 341 - if (err != -EPROBE_DEFER) 342 - dev_err(dev, "Unable to register PHY\n"); 343 - return err; 344 - } 334 + if (err) 335 + return dev_err_probe(dev, err, "Unable to register PHY\n"); 345 336 346 337 return devm_add_action_or_reset(dev, ingenic_usb_phy_remove, &priv->phy); 347 338 }
+2 -2
drivers/usb/phy/phy-mxs-usb.c
··· 144 144 #define MXS_PHY_NEED_IP_FIX BIT(3) 145 145 146 146 /* Minimum and maximum values for device tree entries */ 147 - #define MXS_PHY_TX_CAL45_MIN 30 148 - #define MXS_PHY_TX_CAL45_MAX 55 147 + #define MXS_PHY_TX_CAL45_MIN 35 148 + #define MXS_PHY_TX_CAL45_MAX 54 149 149 #define MXS_PHY_TX_D_CAL_MIN 79 150 150 #define MXS_PHY_TX_D_CAL_MAX 119 151 151
+10 -4
drivers/usb/phy/phy-tegra-usb.c
··· 1440 1440 return err; 1441 1441 } 1442 1442 1443 - gpiod = devm_gpiod_get_from_of_node(&pdev->dev, np, 1444 - "nvidia,phy-reset-gpio", 1445 - 0, GPIOD_OUT_HIGH, 1446 - "ulpi_phy_reset_b"); 1443 + gpiod = devm_gpiod_get(&pdev->dev, "nvidia,phy-reset", 1444 + GPIOD_OUT_HIGH); 1447 1445 err = PTR_ERR_OR_ZERO(gpiod); 1448 1446 if (err) { 1449 1447 dev_err(&pdev->dev, 1450 1448 "Request failed for reset GPIO: %d\n", err); 1451 1449 return err; 1452 1450 } 1451 + 1452 + err = gpiod_set_consumer_name(gpiod, "ulpi_phy_reset_b"); 1453 + if (err) { 1454 + dev_err(&pdev->dev, 1455 + "Failed to set up reset GPIO name: %d\n", err); 1456 + return err; 1457 + } 1458 + 1453 1459 tegra_phy->reset_gpio = gpiod; 1454 1460 1455 1461 phy = devm_otg_ulpi_create(&pdev->dev,
+1 -1
drivers/usb/serial/console.c
··· 189 189 info->port = NULL; 190 190 usb_autopm_put_interface(serial->interface); 191 191 error_get_interface: 192 - usb_serial_put(serial); 193 192 mutex_unlock(&serial->disc_mutex); 193 + usb_serial_put(serial); 194 194 return retval; 195 195 } 196 196
+231 -252
drivers/usb/serial/ftdi_sio.c
··· 47 47 #define DRIVER_AUTHOR "Greg Kroah-Hartman <greg@kroah.com>, Bill Ryder <bryder@sgi.com>, Kuba Ober <kuba@mareimbrium.org>, Andreas Mohr, Johan Hovold <jhovold@gmail.com>" 48 48 #define DRIVER_DESC "USB FTDI Serial Converters Driver" 49 49 50 + enum ftdi_chip_type { 51 + SIO, 52 + FT232A, 53 + FT232B, 54 + FT2232C, 55 + FT232R, 56 + FT232H, 57 + FT2232H, 58 + FT4232H, 59 + FT4232HA, 60 + FT232HP, 61 + FT233HP, 62 + FT2232HP, 63 + FT2233HP, 64 + FT4232HP, 65 + FT4233HP, 66 + FTX, 67 + }; 50 68 51 69 struct ftdi_private { 52 70 enum ftdi_chip_type chip_type; 53 - /* type of device, either SIO or FT8U232AM */ 54 71 int baud_base; /* baud base clock for divisor setting */ 55 72 int custom_divisor; /* custom_divisor kludge, this is for 56 73 baud_base (different from what goes to the ··· 79 62 unsigned long last_dtr_rts; /* saved modem control outputs */ 80 63 char prev_status; /* Used for TIOCMIWAIT */ 81 64 char transmit_empty; /* If transmitter is empty or not */ 82 - u16 interface; /* FT2232C, FT2232H or FT4232H port interface 83 - (0 for FT232/245) */ 65 + u16 channel; /* channel index, or 0 for legacy types */ 84 66 85 67 speed_t force_baud; /* if non-zero, force the baud rate to 86 68 this value */ ··· 100 84 #endif 101 85 }; 102 86 103 - /* struct ftdi_sio_quirk is used by devices requiring special attention. */ 104 - struct ftdi_sio_quirk { 87 + struct ftdi_quirk { 105 88 int (*probe)(struct usb_serial *); 106 89 /* Special settings for probed ports. */ 107 90 void (*port_probe)(struct ftdi_private *); ··· 113 98 static void ftdi_USB_UIRT_setup(struct ftdi_private *priv); 114 99 static void ftdi_HE_TIRA1_setup(struct ftdi_private *priv); 115 100 116 - static const struct ftdi_sio_quirk ftdi_jtag_quirk = { 101 + static const struct ftdi_quirk ftdi_jtag_quirk = { 117 102 .probe = ftdi_jtag_probe, 118 103 }; 119 104 120 - static const struct ftdi_sio_quirk ftdi_NDI_device_quirk = { 105 + static const struct ftdi_quirk ftdi_NDI_device_quirk = { 121 106 .probe = ftdi_NDI_device_setup, 122 107 }; 123 108 124 - static const struct ftdi_sio_quirk ftdi_USB_UIRT_quirk = { 109 + static const struct ftdi_quirk ftdi_USB_UIRT_quirk = { 125 110 .port_probe = ftdi_USB_UIRT_setup, 126 111 }; 127 112 128 - static const struct ftdi_sio_quirk ftdi_HE_TIRA1_quirk = { 113 + static const struct ftdi_quirk ftdi_HE_TIRA1_quirk = { 129 114 .port_probe = ftdi_HE_TIRA1_setup, 130 115 }; 131 116 132 - static const struct ftdi_sio_quirk ftdi_stmclite_quirk = { 117 + static const struct ftdi_quirk ftdi_stmclite_quirk = { 133 118 .probe = ftdi_stmclite_probe, 134 119 }; 135 120 136 - static const struct ftdi_sio_quirk ftdi_8u2232c_quirk = { 121 + static const struct ftdi_quirk ftdi_8u2232c_quirk = { 137 122 .probe = ftdi_8u2232c_probe, 138 123 }; 139 124 ··· 195 180 { USB_DEVICE(FTDI_VID, FTDI_4232H_PID) }, 196 181 { USB_DEVICE(FTDI_VID, FTDI_232H_PID) }, 197 182 { USB_DEVICE(FTDI_VID, FTDI_FTX_PID) }, 183 + { USB_DEVICE(FTDI_VID, FTDI_FT2233HP_PID) }, 184 + { USB_DEVICE(FTDI_VID, FTDI_FT4233HP_PID) }, 185 + { USB_DEVICE(FTDI_VID, FTDI_FT2232HP_PID) }, 186 + { USB_DEVICE(FTDI_VID, FTDI_FT4232HP_PID) }, 187 + { USB_DEVICE(FTDI_VID, FTDI_FT233HP_PID) }, 188 + { USB_DEVICE(FTDI_VID, FTDI_FT232HP_PID) }, 189 + { USB_DEVICE(FTDI_VID, FTDI_FT4232HA_PID) }, 198 190 { USB_DEVICE(FTDI_VID, FTDI_MICRO_CHAMELEON_PID) }, 199 191 { USB_DEVICE(FTDI_VID, FTDI_RELAIS_PID) }, 200 192 { USB_DEVICE(FTDI_VID, FTDI_OPENDCC_PID) }, ··· 1083 1061 MODULE_DEVICE_TABLE(usb, id_table_combined); 1084 1062 1085 1063 static const char *ftdi_chip_name[] = { 1086 - [SIO] = "SIO", /* the serial part of FT8U100AX */ 1087 - [FT8U232AM] = "FT8U232AM", 1088 - [FT232BM] = "FT232BM", 1089 - [FT2232C] = "FT2232C", 1090 - [FT232RL] = "FT232RL", 1091 - [FT2232H] = "FT2232H", 1092 - [FT4232H] = "FT4232H", 1093 - [FT232H] = "FT232H", 1094 - [FTX] = "FT-X" 1064 + [SIO] = "SIO", /* the serial part of FT8U100AX */ 1065 + [FT232A] = "FT232A", 1066 + [FT232B] = "FT232B", 1067 + [FT2232C] = "FT2232C/D", 1068 + [FT232R] = "FT232R", 1069 + [FT232H] = "FT232H", 1070 + [FT2232H] = "FT2232H", 1071 + [FT4232H] = "FT4232H", 1072 + [FT4232HA] = "FT4232HA", 1073 + [FT232HP] = "FT232HP", 1074 + [FT233HP] = "FT233HP", 1075 + [FT2232HP] = "FT2232HP", 1076 + [FT2233HP] = "FT2233HP", 1077 + [FT4232HP] = "FT4232HP", 1078 + [FT4233HP] = "FT4233HP", 1079 + [FTX] = "FT-X", 1095 1080 }; 1096 1081 1097 1082 ··· 1107 1078 #define FTDI_STATUS_B1_MASK (FTDI_RS_BI) 1108 1079 /* End TIOCMIWAIT */ 1109 1080 1110 - /* function prototypes for a FTDI serial converter */ 1111 - static int ftdi_sio_probe(struct usb_serial *serial, 1112 - const struct usb_device_id *id); 1113 - static int ftdi_sio_port_probe(struct usb_serial_port *port); 1114 - static void ftdi_sio_port_remove(struct usb_serial_port *port); 1115 - static int ftdi_open(struct tty_struct *tty, struct usb_serial_port *port); 1116 - static void ftdi_dtr_rts(struct usb_serial_port *port, int on); 1117 - static void ftdi_process_read_urb(struct urb *urb); 1118 - static int ftdi_prepare_write_buffer(struct usb_serial_port *port, 1119 - void *dest, size_t size); 1120 1081 static void ftdi_set_termios(struct tty_struct *tty, 1121 1082 struct usb_serial_port *port, 1122 1083 const struct ktermios *old_termios); 1123 - static int ftdi_tiocmget(struct tty_struct *tty); 1124 - static int ftdi_tiocmset(struct tty_struct *tty, 1125 - unsigned int set, unsigned int clear); 1126 - static int ftdi_ioctl(struct tty_struct *tty, 1127 - unsigned int cmd, unsigned long arg); 1128 - static void get_serial_info(struct tty_struct *tty, struct serial_struct *ss); 1129 - static int set_serial_info(struct tty_struct *tty, 1130 - struct serial_struct *ss); 1131 - static void ftdi_break_ctl(struct tty_struct *tty, int break_state); 1132 - static bool ftdi_tx_empty(struct usb_serial_port *port); 1133 1084 static int ftdi_get_modem_status(struct usb_serial_port *port, 1134 1085 unsigned char status[2]); 1135 - 1136 - static unsigned short int ftdi_232am_baud_base_to_divisor(int baud, int base); 1137 - static unsigned short int ftdi_232am_baud_to_divisor(int baud); 1138 - static u32 ftdi_232bm_baud_base_to_divisor(int baud, int base); 1139 - static u32 ftdi_232bm_baud_to_divisor(int baud); 1140 - static u32 ftdi_2232h_baud_base_to_divisor(int baud, int base); 1141 - static u32 ftdi_2232h_baud_to_divisor(int baud); 1142 - 1143 - static struct usb_serial_driver ftdi_sio_device = { 1144 - .driver = { 1145 - .owner = THIS_MODULE, 1146 - .name = "ftdi_sio", 1147 - }, 1148 - .description = "FTDI USB Serial Device", 1149 - .id_table = id_table_combined, 1150 - .num_ports = 1, 1151 - .bulk_in_size = 512, 1152 - .bulk_out_size = 256, 1153 - .probe = ftdi_sio_probe, 1154 - .port_probe = ftdi_sio_port_probe, 1155 - .port_remove = ftdi_sio_port_remove, 1156 - .open = ftdi_open, 1157 - .dtr_rts = ftdi_dtr_rts, 1158 - .throttle = usb_serial_generic_throttle, 1159 - .unthrottle = usb_serial_generic_unthrottle, 1160 - .process_read_urb = ftdi_process_read_urb, 1161 - .prepare_write_buffer = ftdi_prepare_write_buffer, 1162 - .tiocmget = ftdi_tiocmget, 1163 - .tiocmset = ftdi_tiocmset, 1164 - .tiocmiwait = usb_serial_generic_tiocmiwait, 1165 - .get_icount = usb_serial_generic_get_icount, 1166 - .ioctl = ftdi_ioctl, 1167 - .get_serial = get_serial_info, 1168 - .set_serial = set_serial_info, 1169 - .set_termios = ftdi_set_termios, 1170 - .break_ctl = ftdi_break_ctl, 1171 - .tx_empty = ftdi_tx_empty, 1172 - }; 1173 - 1174 - static struct usb_serial_driver * const serial_drivers[] = { 1175 - &ftdi_sio_device, NULL 1176 - }; 1177 - 1178 1086 1179 1087 #define WDR_TIMEOUT 5000 /* default urb timeout */ 1180 1088 #define WDR_SHORT_TIMEOUT 1000 /* shorter urb timeout */ ··· 1228 1262 usb_sndctrlpipe(port->serial->dev, 0), 1229 1263 FTDI_SIO_SET_MODEM_CTRL_REQUEST, 1230 1264 FTDI_SIO_SET_MODEM_CTRL_REQUEST_TYPE, 1231 - value, priv->interface, 1265 + value, priv->channel, 1232 1266 NULL, 0, WDR_TIMEOUT); 1233 1267 if (rv < 0) { 1234 1268 dev_dbg(dev, "%s Error from MODEM_CTRL urb: DTR %s, RTS %s\n", ··· 1274 1308 if (!baud) 1275 1309 baud = 9600; 1276 1310 switch (priv->chip_type) { 1277 - case SIO: /* SIO chip */ 1311 + case SIO: 1278 1312 switch (baud) { 1279 1313 case 300: div_value = ftdi_sio_b300; break; 1280 1314 case 600: div_value = ftdi_sio_b600; break; ··· 1286 1320 case 38400: div_value = ftdi_sio_b38400; break; 1287 1321 case 57600: div_value = ftdi_sio_b57600; break; 1288 1322 case 115200: div_value = ftdi_sio_b115200; break; 1289 - } /* baud */ 1290 - if (div_value == 0) { 1323 + default: 1291 1324 dev_dbg(dev, "%s - Baudrate (%d) requested is not supported\n", 1292 1325 __func__, baud); 1293 1326 div_value = ftdi_sio_b9600; ··· 1294 1329 div_okay = 0; 1295 1330 } 1296 1331 break; 1297 - case FT8U232AM: /* 8U232AM chip */ 1332 + case FT232A: 1298 1333 if (baud <= 3000000) { 1299 1334 div_value = ftdi_232am_baud_to_divisor(baud); 1300 1335 } else { ··· 1304 1339 div_okay = 0; 1305 1340 } 1306 1341 break; 1307 - case FT232BM: /* FT232BM chip */ 1308 - case FT2232C: /* FT2232C chip */ 1309 - case FT232RL: /* FT232RL chip */ 1310 - case FTX: /* FT-X series */ 1342 + case FT232B: 1343 + case FT2232C: 1344 + case FT232R: 1345 + case FTX: 1311 1346 if (baud <= 3000000) { 1312 1347 u16 product_id = le16_to_cpu( 1313 1348 port->serial->dev->descriptor.idProduct); ··· 1327 1362 baud = 9600; 1328 1363 } 1329 1364 break; 1330 - case FT2232H: /* FT2232H chip */ 1331 - case FT4232H: /* FT4232H chip */ 1332 - case FT232H: /* FT232H chip */ 1365 + default: 1333 1366 if ((baud <= 12000000) && (baud >= 1200)) { 1334 1367 div_value = ftdi_2232h_baud_to_divisor(baud); 1335 1368 } else if (baud < 1200) { ··· 1339 1376 baud = 9600; 1340 1377 } 1341 1378 break; 1342 - } /* priv->chip_type */ 1379 + } 1343 1380 1344 1381 if (div_okay) { 1345 1382 dev_dbg(dev, "%s - Baud rate set to %d (divisor 0x%lX) on chip %s\n", ··· 1362 1399 index_value = get_ftdi_divisor(tty, port); 1363 1400 value = (u16)index_value; 1364 1401 index = (u16)(index_value >> 16); 1365 - if (priv->chip_type == FT2232C || priv->chip_type == FT2232H || 1366 - priv->chip_type == FT4232H || priv->chip_type == FT232H || 1367 - priv->chip_type == FTX) { 1368 - /* Probably the BM type needs the MSB of the encoded fractional 1369 - * divider also moved like for the chips above. Any infos? */ 1370 - index = (u16)((index << 8) | priv->interface); 1371 - } 1402 + if (priv->channel) 1403 + index = (u16)((index << 8) | priv->channel); 1372 1404 1373 1405 rv = usb_control_msg(port->serial->dev, 1374 1406 usb_sndctrlpipe(port->serial->dev, 0), ··· 1381 1423 int rv; 1382 1424 int l = priv->latency; 1383 1425 1384 - if (priv->chip_type == SIO || priv->chip_type == FT8U232AM) 1426 + if (priv->chip_type == SIO || priv->chip_type == FT232A) 1385 1427 return -EINVAL; 1386 1428 1387 1429 if (priv->flags & ASYNC_LOW_LATENCY) ··· 1393 1435 usb_sndctrlpipe(udev, 0), 1394 1436 FTDI_SIO_SET_LATENCY_TIMER_REQUEST, 1395 1437 FTDI_SIO_SET_LATENCY_TIMER_REQUEST_TYPE, 1396 - l, priv->interface, 1438 + l, priv->channel, 1397 1439 NULL, 0, WDR_TIMEOUT); 1398 1440 if (rv < 0) 1399 1441 dev_err(&port->dev, "Unable to write latency timer: %i\n", rv); ··· 1409 1451 1410 1452 rv = usb_control_msg_recv(udev, 0, FTDI_SIO_GET_LATENCY_TIMER_REQUEST, 1411 1453 FTDI_SIO_GET_LATENCY_TIMER_REQUEST_TYPE, 0, 1412 - priv->interface, &buf, 1, WDR_TIMEOUT, 1454 + priv->channel, &buf, 1, WDR_TIMEOUT, 1413 1455 GFP_KERNEL); 1414 1456 if (rv == 0) 1415 1457 rv = buf; ··· 1422 1464 struct ftdi_private *priv = usb_get_serial_port_data(port); 1423 1465 int rv; 1424 1466 1425 - if (priv->chip_type == SIO || priv->chip_type == FT8U232AM) 1467 + if (priv->chip_type == SIO || priv->chip_type == FT232A) 1426 1468 return -EINVAL; 1427 1469 1428 1470 rv = _read_latency_timer(port); ··· 1497 1539 return 0; 1498 1540 } 1499 1541 1500 - 1501 - /* Determine type of FTDI chip based on USB config and descriptor. */ 1502 - static void ftdi_determine_type(struct usb_serial_port *port) 1542 + static int ftdi_determine_type(struct usb_serial_port *port) 1503 1543 { 1504 1544 struct ftdi_private *priv = usb_get_serial_port_data(port); 1505 1545 struct usb_serial *serial = port->serial; 1506 1546 struct usb_device *udev = serial->dev; 1507 - unsigned version; 1508 - unsigned interfaces; 1509 - 1510 - /* Assume it is not the original SIO device for now. */ 1511 - priv->baud_base = 48000000 / 2; 1547 + unsigned int version, ifnum; 1512 1548 1513 1549 version = le16_to_cpu(udev->descriptor.bcdDevice); 1514 - interfaces = udev->actconfig->desc.bNumInterfaces; 1515 - dev_dbg(&port->dev, "%s: bcdDevice = 0x%x, bNumInterfaces = %u\n", __func__, 1516 - version, interfaces); 1517 - if (interfaces > 1) { 1518 - struct usb_interface *intf = serial->interface; 1519 - int ifnum = intf->cur_altsetting->desc.bInterfaceNumber; 1550 + ifnum = serial->interface->cur_altsetting->desc.bInterfaceNumber; 1520 1551 1521 - /* Multiple interfaces.*/ 1522 - if (version == 0x0800) { 1523 - priv->chip_type = FT4232H; 1524 - /* Hi-speed - baud clock runs at 120MHz */ 1525 - priv->baud_base = 120000000 / 2; 1526 - } else if (version == 0x0700) { 1527 - priv->chip_type = FT2232H; 1528 - /* Hi-speed - baud clock runs at 120MHz */ 1529 - priv->baud_base = 120000000 / 2; 1530 - } else 1531 - priv->chip_type = FT2232C; 1552 + /* Assume Hi-Speed type */ 1553 + priv->baud_base = 120000000 / 2; 1554 + priv->channel = CHANNEL_A + ifnum; 1532 1555 1533 - /* Determine interface code. */ 1534 - if (ifnum == 0) 1535 - priv->interface = INTERFACE_A; 1536 - else if (ifnum == 1) 1537 - priv->interface = INTERFACE_B; 1538 - else if (ifnum == 2) 1539 - priv->interface = INTERFACE_C; 1540 - else if (ifnum == 3) 1541 - priv->interface = INTERFACE_D; 1542 - 1543 - /* BM-type devices have a bug where bcdDevice gets set 1544 - * to 0x200 when iSerialNumber is 0. */ 1545 - if (version < 0x500) { 1546 - dev_dbg(&port->dev, 1547 - "%s: something fishy - bcdDevice too low for multi-interface device\n", 1548 - __func__); 1549 - } 1550 - } else if (version < 0x200) { 1551 - /* Old device. Assume it's the original SIO. */ 1552 - priv->chip_type = SIO; 1553 - priv->baud_base = 12000000 / 16; 1554 - } else if (version < 0x400) { 1555 - /* Assume it's an FT8U232AM (or FT8U245AM) */ 1556 - priv->chip_type = FT8U232AM; 1556 + switch (version) { 1557 + case 0x200: 1558 + priv->chip_type = FT232A; 1559 + priv->baud_base = 48000000 / 2; 1560 + priv->channel = 0; 1557 1561 /* 1558 - * It might be a BM type because of the iSerialNumber bug. 1559 - * If iSerialNumber==0 and the latency timer is readable, 1560 - * assume it is BM type. 1562 + * FT232B devices have a bug where bcdDevice gets set to 0x200 1563 + * when iSerialNumber is 0. Assume it is an FT232B in case the 1564 + * latency timer is readable. 1561 1565 */ 1562 1566 if (udev->descriptor.iSerialNumber == 0 && 1563 1567 _read_latency_timer(port) >= 0) { 1564 - dev_dbg(&port->dev, 1565 - "%s: has latency timer so not an AM type\n", 1566 - __func__); 1567 - priv->chip_type = FT232BM; 1568 + priv->chip_type = FT232B; 1568 1569 } 1569 - } else if (version < 0x600) { 1570 - /* Assume it's an FT232BM (or FT245BM) */ 1571 - priv->chip_type = FT232BM; 1572 - } else if (version < 0x900) { 1573 - /* Assume it's an FT232RL */ 1574 - priv->chip_type = FT232RL; 1575 - } else if (version < 0x1000) { 1576 - /* Assume it's an FT232H */ 1570 + break; 1571 + case 0x400: 1572 + priv->chip_type = FT232B; 1573 + priv->baud_base = 48000000 / 2; 1574 + priv->channel = 0; 1575 + break; 1576 + case 0x500: 1577 + priv->chip_type = FT2232C; 1578 + priv->baud_base = 48000000 / 2; 1579 + break; 1580 + case 0x600: 1581 + priv->chip_type = FT232R; 1582 + priv->baud_base = 48000000 / 2; 1583 + priv->channel = 0; 1584 + break; 1585 + case 0x700: 1586 + priv->chip_type = FT2232H; 1587 + break; 1588 + case 0x800: 1589 + priv->chip_type = FT4232H; 1590 + break; 1591 + case 0x900: 1577 1592 priv->chip_type = FT232H; 1578 - } else { 1579 - /* Assume it's an FT-X series device */ 1593 + break; 1594 + case 0x1000: 1580 1595 priv->chip_type = FTX; 1596 + priv->baud_base = 48000000 / 2; 1597 + break; 1598 + case 0x2800: 1599 + priv->chip_type = FT2233HP; 1600 + break; 1601 + case 0x2900: 1602 + priv->chip_type = FT4233HP; 1603 + break; 1604 + case 0x3000: 1605 + priv->chip_type = FT2232HP; 1606 + break; 1607 + case 0x3100: 1608 + priv->chip_type = FT4232HP; 1609 + break; 1610 + case 0x3200: 1611 + priv->chip_type = FT233HP; 1612 + break; 1613 + case 0x3300: 1614 + priv->chip_type = FT232HP; 1615 + break; 1616 + case 0x3600: 1617 + priv->chip_type = FT4232HA; 1618 + break; 1619 + default: 1620 + if (version < 0x200) { 1621 + priv->chip_type = SIO; 1622 + priv->baud_base = 12000000 / 16; 1623 + priv->channel = 0; 1624 + } else { 1625 + dev_err(&port->dev, "unknown device type: 0x%02x\n", version); 1626 + return -ENODEV; 1627 + } 1581 1628 } 1582 1629 1583 1630 dev_info(&udev->dev, "Detected %s\n", ftdi_chip_name[priv->chip_type]); 1631 + 1632 + return 0; 1584 1633 } 1585 1634 1586 1635 ··· 1686 1721 usb_sndctrlpipe(udev, 0), 1687 1722 FTDI_SIO_SET_EVENT_CHAR_REQUEST, 1688 1723 FTDI_SIO_SET_EVENT_CHAR_REQUEST_TYPE, 1689 - v, priv->interface, 1724 + v, priv->channel, 1690 1725 NULL, 0, WDR_TIMEOUT); 1691 1726 if (rv < 0) { 1692 1727 dev_dbg(&port->dev, "Unable to write event character: %i\n", rv); ··· 1697 1732 } 1698 1733 static DEVICE_ATTR_WO(event_char); 1699 1734 1700 - static int create_sysfs_attrs(struct usb_serial_port *port) 1735 + static struct attribute *ftdi_attrs[] = { 1736 + &dev_attr_event_char.attr, 1737 + &dev_attr_latency_timer.attr, 1738 + NULL 1739 + }; 1740 + 1741 + static umode_t ftdi_is_visible(struct kobject *kobj, struct attribute *attr, int idx) 1701 1742 { 1743 + struct device *dev = kobj_to_dev(kobj); 1744 + struct usb_serial_port *port = to_usb_serial_port(dev); 1702 1745 struct ftdi_private *priv = usb_get_serial_port_data(port); 1703 - int retval = 0; 1746 + enum ftdi_chip_type type = priv->chip_type; 1704 1747 1705 - /* XXX I've no idea if the original SIO supports the event_char 1706 - * sysfs parameter, so I'm playing it safe. */ 1707 - if (priv->chip_type != SIO) { 1708 - dev_dbg(&port->dev, "sysfs attributes for %s\n", ftdi_chip_name[priv->chip_type]); 1709 - retval = device_create_file(&port->dev, &dev_attr_event_char); 1710 - if ((!retval) && 1711 - (priv->chip_type == FT232BM || 1712 - priv->chip_type == FT2232C || 1713 - priv->chip_type == FT232RL || 1714 - priv->chip_type == FT2232H || 1715 - priv->chip_type == FT4232H || 1716 - priv->chip_type == FT232H || 1717 - priv->chip_type == FTX)) { 1718 - retval = device_create_file(&port->dev, 1719 - &dev_attr_latency_timer); 1720 - } 1721 - } 1722 - return retval; 1723 - } 1724 - 1725 - static void remove_sysfs_attrs(struct usb_serial_port *port) 1726 - { 1727 - struct ftdi_private *priv = usb_get_serial_port_data(port); 1728 - 1729 - /* XXX see create_sysfs_attrs */ 1730 - if (priv->chip_type != SIO) { 1731 - device_remove_file(&port->dev, &dev_attr_event_char); 1732 - if (priv->chip_type == FT232BM || 1733 - priv->chip_type == FT2232C || 1734 - priv->chip_type == FT232RL || 1735 - priv->chip_type == FT2232H || 1736 - priv->chip_type == FT4232H || 1737 - priv->chip_type == FT232H || 1738 - priv->chip_type == FTX) { 1739 - device_remove_file(&port->dev, &dev_attr_latency_timer); 1740 - } 1748 + if (attr == &dev_attr_event_char.attr) { 1749 + if (type == SIO) 1750 + return 0; 1741 1751 } 1742 1752 1753 + if (attr == &dev_attr_latency_timer.attr) { 1754 + if (type == SIO || type == FT232A) 1755 + return 0; 1756 + } 1757 + 1758 + return attr->mode; 1743 1759 } 1760 + 1761 + static const struct attribute_group ftdi_group = { 1762 + .attrs = ftdi_attrs, 1763 + .is_visible = ftdi_is_visible, 1764 + }; 1765 + 1766 + static const struct attribute_group *ftdi_groups[] = { 1767 + &ftdi_group, 1768 + NULL 1769 + }; 1744 1770 1745 1771 #ifdef CONFIG_GPIOLIB 1746 1772 ··· 1751 1795 usb_sndctrlpipe(serial->dev, 0), 1752 1796 FTDI_SIO_SET_BITMODE_REQUEST, 1753 1797 FTDI_SIO_SET_BITMODE_REQUEST_TYPE, val, 1754 - priv->interface, NULL, 0, WDR_TIMEOUT); 1798 + priv->channel, NULL, 0, WDR_TIMEOUT); 1755 1799 if (result < 0) { 1756 1800 dev_err(&serial->interface->dev, 1757 1801 "bitmode request failed for value 0x%04x: %d\n", ··· 1815 1859 result = usb_control_msg_recv(serial->dev, 0, 1816 1860 FTDI_SIO_READ_PINS_REQUEST, 1817 1861 FTDI_SIO_READ_PINS_REQUEST_TYPE, 0, 1818 - priv->interface, &buf, 1, WDR_TIMEOUT, 1862 + priv->channel, &buf, 1, WDR_TIMEOUT, 1819 1863 GFP_KERNEL); 1820 1864 if (result == 0) 1821 1865 result = buf; ··· 2100 2144 case FT232H: 2101 2145 result = ftdi_gpio_init_ft232h(port); 2102 2146 break; 2103 - case FT232RL: 2147 + case FT232R: 2104 2148 result = ftdi_gpio_init_ft232r(port); 2105 2149 break; 2106 2150 case FTX: ··· 2170 2214 * *************************************************************************** 2171 2215 */ 2172 2216 2173 - /* Probe function to check for special devices */ 2174 - static int ftdi_sio_probe(struct usb_serial *serial, 2175 - const struct usb_device_id *id) 2217 + static int ftdi_probe(struct usb_serial *serial, const struct usb_device_id *id) 2176 2218 { 2177 - const struct ftdi_sio_quirk *quirk = 2178 - (struct ftdi_sio_quirk *)id->driver_info; 2219 + const struct ftdi_quirk *quirk = (struct ftdi_quirk *)id->driver_info; 2179 2220 2180 2221 if (quirk && quirk->probe) { 2181 2222 int ret = quirk->probe(serial); ··· 2185 2232 return 0; 2186 2233 } 2187 2234 2188 - static int ftdi_sio_port_probe(struct usb_serial_port *port) 2235 + static int ftdi_port_probe(struct usb_serial_port *port) 2189 2236 { 2237 + const struct ftdi_quirk *quirk = usb_get_serial_data(port->serial); 2190 2238 struct ftdi_private *priv; 2191 - const struct ftdi_sio_quirk *quirk = usb_get_serial_data(port->serial); 2192 2239 int result; 2193 2240 2194 2241 priv = kzalloc(sizeof(struct ftdi_private), GFP_KERNEL); ··· 2202 2249 2203 2250 usb_set_serial_port_data(port, priv); 2204 2251 2205 - ftdi_determine_type(port); 2252 + result = ftdi_determine_type(port); 2253 + if (result) 2254 + goto err_free; 2255 + 2206 2256 ftdi_set_max_packet_size(port); 2207 2257 if (read_latency_timer(port) < 0) 2208 2258 priv->latency = 16; 2209 2259 write_latency_timer(port); 2210 - create_sysfs_attrs(port); 2211 2260 2212 2261 result = ftdi_gpio_init(port); 2213 2262 if (result < 0) { ··· 2219 2264 } 2220 2265 2221 2266 return 0; 2267 + 2268 + err_free: 2269 + kfree(priv); 2270 + 2271 + return result; 2222 2272 } 2223 2273 2224 2274 /* Setup for the USB-UIRT device, which requires hardwired ··· 2334 2374 return 0; 2335 2375 } 2336 2376 2337 - static void ftdi_sio_port_remove(struct usb_serial_port *port) 2377 + static void ftdi_port_remove(struct usb_serial_port *port) 2338 2378 { 2339 2379 struct ftdi_private *priv = usb_get_serial_port_data(port); 2340 2380 2341 2381 ftdi_gpio_remove(port); 2342 - 2343 - remove_sysfs_attrs(port); 2344 2382 2345 2383 kfree(priv); 2346 2384 } ··· 2353 2395 usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 2354 2396 FTDI_SIO_RESET_REQUEST, FTDI_SIO_RESET_REQUEST_TYPE, 2355 2397 FTDI_SIO_RESET_SIO, 2356 - priv->interface, NULL, 0, WDR_TIMEOUT); 2398 + priv->channel, NULL, 0, WDR_TIMEOUT); 2357 2399 2358 2400 /* Termios defaults are set by usb_serial_init. We don't change 2359 2401 port->tty->termios - this would lose speed settings, etc. ··· 2376 2418 usb_sndctrlpipe(port->serial->dev, 0), 2377 2419 FTDI_SIO_SET_FLOW_CTRL_REQUEST, 2378 2420 FTDI_SIO_SET_FLOW_CTRL_REQUEST_TYPE, 2379 - 0, priv->interface, NULL, 0, 2421 + 0, priv->channel, NULL, 0, 2380 2422 WDR_TIMEOUT) < 0) { 2381 2423 dev_err(&port->dev, "error from flowcontrol urb\n"); 2382 2424 } ··· 2569 2611 usb_sndctrlpipe(port->serial->dev, 0), 2570 2612 FTDI_SIO_SET_DATA_REQUEST, 2571 2613 FTDI_SIO_SET_DATA_REQUEST_TYPE, 2572 - value , priv->interface, 2614 + value, priv->channel, 2573 2615 NULL, 0, WDR_TIMEOUT) < 0) { 2574 2616 dev_err(&port->dev, "%s FAILED to enable/disable break state (state was %d)\n", 2575 2617 __func__, break_state); ··· 2706 2748 if (usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 2707 2749 FTDI_SIO_SET_DATA_REQUEST, 2708 2750 FTDI_SIO_SET_DATA_REQUEST_TYPE, 2709 - value , priv->interface, 2751 + value, priv->channel, 2710 2752 NULL, 0, WDR_SHORT_TIMEOUT) < 0) { 2711 2753 dev_err(ddev, "%s FAILED to set databits/stopbits/parity\n", 2712 2754 __func__); ··· 2719 2761 if (usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 2720 2762 FTDI_SIO_SET_FLOW_CTRL_REQUEST, 2721 2763 FTDI_SIO_SET_FLOW_CTRL_REQUEST_TYPE, 2722 - 0, priv->interface, 2764 + 0, priv->channel, 2723 2765 NULL, 0, WDR_TIMEOUT) < 0) { 2724 2766 dev_err(ddev, "%s error from disable flowcontrol urb\n", 2725 2767 __func__); ··· 2753 2795 index = FTDI_SIO_DISABLE_FLOW_CTRL; 2754 2796 } 2755 2797 2756 - index |= priv->interface; 2798 + index |= priv->channel; 2757 2799 2758 2800 ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 2759 2801 FTDI_SIO_SET_FLOW_CTRL_REQUEST, ··· 2781 2823 if (!buf) 2782 2824 return -ENOMEM; 2783 2825 /* 2784 - * The 8U232AM returns a two byte value (the SIO a 1 byte value) in 2785 - * the same format as the data returned from the in point. 2826 + * The device returns a two byte value (the SIO a 1 byte value) in the 2827 + * same format as the data returned from the IN endpoint. 2786 2828 */ 2787 - switch (priv->chip_type) { 2788 - case SIO: 2829 + if (priv->chip_type == SIO) 2789 2830 len = 1; 2790 - break; 2791 - case FT8U232AM: 2792 - case FT232BM: 2793 - case FT2232C: 2794 - case FT232RL: 2795 - case FT2232H: 2796 - case FT4232H: 2797 - case FT232H: 2798 - case FTX: 2831 + else 2799 2832 len = 2; 2800 - break; 2801 - default: 2802 - ret = -EFAULT; 2803 - goto out; 2804 - } 2805 2833 2806 2834 ret = usb_control_msg(port->serial->dev, 2807 2835 usb_rcvctrlpipe(port->serial->dev, 0), 2808 2836 FTDI_SIO_GET_MODEM_STATUS_REQUEST, 2809 2837 FTDI_SIO_GET_MODEM_STATUS_REQUEST_TYPE, 2810 - 0, priv->interface, 2838 + 0, priv->channel, 2811 2839 buf, len, WDR_TIMEOUT); 2812 2840 2813 2841 /* NOTE: We allow short responses and handle that below. */ ··· 2863 2919 return -ENOIOCTLCMD; 2864 2920 } 2865 2921 2922 + static struct usb_serial_driver ftdi_device = { 2923 + .driver = { 2924 + .owner = THIS_MODULE, 2925 + .name = "ftdi_sio", 2926 + .dev_groups = ftdi_groups, 2927 + }, 2928 + .description = "FTDI USB Serial Device", 2929 + .id_table = id_table_combined, 2930 + .num_ports = 1, 2931 + .bulk_in_size = 512, 2932 + .bulk_out_size = 256, 2933 + .probe = ftdi_probe, 2934 + .port_probe = ftdi_port_probe, 2935 + .port_remove = ftdi_port_remove, 2936 + .open = ftdi_open, 2937 + .dtr_rts = ftdi_dtr_rts, 2938 + .throttle = usb_serial_generic_throttle, 2939 + .unthrottle = usb_serial_generic_unthrottle, 2940 + .process_read_urb = ftdi_process_read_urb, 2941 + .prepare_write_buffer = ftdi_prepare_write_buffer, 2942 + .tiocmget = ftdi_tiocmget, 2943 + .tiocmset = ftdi_tiocmset, 2944 + .tiocmiwait = usb_serial_generic_tiocmiwait, 2945 + .get_icount = usb_serial_generic_get_icount, 2946 + .ioctl = ftdi_ioctl, 2947 + .get_serial = get_serial_info, 2948 + .set_serial = set_serial_info, 2949 + .set_termios = ftdi_set_termios, 2950 + .break_ctl = ftdi_break_ctl, 2951 + .tx_empty = ftdi_tx_empty, 2952 + }; 2953 + 2954 + static struct usb_serial_driver * const serial_drivers[] = { 2955 + &ftdi_device, NULL 2956 + }; 2866 2957 module_usb_serial_driver(serial_drivers, id_table_combined); 2867 2958 2868 2959 MODULE_AUTHOR(DRIVER_AUTHOR);
+5 -17
drivers/usb/serial/ftdi_sio.h
··· 40 40 #define FTDI_SIO_READ_PINS 0x0c /* Read immediate value of pins */ 41 41 #define FTDI_SIO_READ_EEPROM 0x90 /* Read EEPROM */ 42 42 43 - /* Interface indices for FT2232, FT2232H and FT4232H devices */ 44 - #define INTERFACE_A 1 45 - #define INTERFACE_B 2 46 - #define INTERFACE_C 3 47 - #define INTERFACE_D 4 43 + /* Channel indices for FT2232, FT2232H and FT4232H devices */ 44 + #define CHANNEL_A 1 45 + #define CHANNEL_B 2 46 + #define CHANNEL_C 3 47 + #define CHANNEL_D 4 48 48 49 49 50 50 /* ··· 152 152 * (1.5), this needs to be replaced with 0x0001 (1) (but this divisor value is 153 153 * not supported by the FT8U232AM). 154 154 */ 155 - 156 - enum ftdi_chip_type { 157 - SIO = 1, 158 - FT8U232AM = 2, 159 - FT232BM = 3, 160 - FT2232C = 4, 161 - FT232RL = 5, 162 - FT2232H = 6, 163 - FT4232H = 7, 164 - FT232H = 8, 165 - FTX = 9, 166 - }; 167 155 168 156 enum ftdi_sio_baudrate { 169 157 ftdi_sio_b300 = 0,
+7
drivers/usb/serial/ftdi_sio_ids.h
··· 25 25 #define FTDI_4232H_PID 0x6011 /* Quad channel hi-speed device */ 26 26 #define FTDI_232H_PID 0x6014 /* Single channel hi-speed device */ 27 27 #define FTDI_FTX_PID 0x6015 /* FT-X series (FT201X, FT230X, FT231X, etc) */ 28 + #define FTDI_FT2233HP_PID 0x6040 /* Dual channel hi-speed device with PD */ 29 + #define FTDI_FT4233HP_PID 0x6041 /* Quad channel hi-speed device with PD */ 30 + #define FTDI_FT2232HP_PID 0x6042 /* Dual channel hi-speed device with PD */ 31 + #define FTDI_FT4232HP_PID 0x6043 /* Quad channel hi-speed device with PD */ 32 + #define FTDI_FT233HP_PID 0x6044 /* Dual channel hi-speed device with PD */ 33 + #define FTDI_FT232HP_PID 0x6045 /* Dual channel hi-speed device with PD */ 34 + #define FTDI_FT4232HA_PID 0x6048 /* Quad channel automotive grade hi-speed device */ 28 35 #define FTDI_SIO_PID 0x8372 /* Product Id SIO application of 8U100AX */ 29 36 #define FTDI_232RL_PID 0xFBFA /* Product ID for FT232RL */ 30 37
+1
drivers/usb/serial/qcserial.c
··· 177 177 {DEVICE_SWI(0x413c, 0x81b3)}, /* Dell Wireless 5809e Gobi(TM) 4G LTE Mobile Broadband Card (rev3) */ 178 178 {DEVICE_SWI(0x413c, 0x81b5)}, /* Dell Wireless 5811e QDL */ 179 179 {DEVICE_SWI(0x413c, 0x81b6)}, /* Dell Wireless 5811e QDL */ 180 + {DEVICE_SWI(0x413c, 0x81c2)}, /* Dell Wireless 5811e */ 180 181 {DEVICE_SWI(0x413c, 0x81cb)}, /* Dell Wireless 5816e QDL */ 181 182 {DEVICE_SWI(0x413c, 0x81cc)}, /* Dell Wireless 5816e */ 182 183 {DEVICE_SWI(0x413c, 0x81cf)}, /* Dell Wireless 5819 */
+1 -1
drivers/usb/storage/onetouch.c
··· 201 201 onetouch->dev = input_dev; 202 202 203 203 if (udev->manufacturer) 204 - strlcpy(onetouch->name, udev->manufacturer, 204 + strscpy(onetouch->name, udev->manufacturer, 205 205 sizeof(onetouch->name)); 206 206 if (udev->product) { 207 207 if (udev->manufacturer)
-6
drivers/usb/storage/unusual_devs.h
··· 1275 1275 USB_SC_RBC, USB_PR_BULK, NULL, 1276 1276 0 ), 1277 1277 1278 - UNUSUAL_DEV(0x090c, 0x1000, 0x1100, 0x1100, 1279 - "Samsung", 1280 - "Flash Drive FIT", 1281 - USB_SC_DEVICE, USB_PR_DEVICE, NULL, 1282 - US_FL_MAX_SECTORS_64), 1283 - 1284 1278 /* aeb */ 1285 1279 UNUSUAL_DEV( 0x090c, 0x1132, 0x0000, 0xffff, 1286 1280 "Feiya",
+2 -2
drivers/usb/typec/anx7411.c
··· 1105 1105 int ret; 1106 1106 struct device_node *node; 1107 1107 1108 - node = of_find_node_by_name(dev->of_node, "orientation_switch"); 1108 + node = of_get_child_by_name(dev->of_node, "orientation_switch"); 1109 1109 if (!node) 1110 1110 return 0; 1111 1111 ··· 1115 1115 return ret; 1116 1116 } 1117 1117 1118 - node = of_find_node_by_name(dev->of_node, "mode_switch"); 1118 + node = of_get_child_by_name(dev->of_node, "mode_switch"); 1119 1119 if (!node) { 1120 1120 dev_err(dev, "no typec mux exist"); 1121 1121 ret = -ENODEV;
+2 -2
drivers/usb/typec/mux.c
··· 29 29 if (!is_typec_switch_dev(dev)) 30 30 return 0; 31 31 32 - return dev_fwnode(dev) == fwnode; 32 + return device_match_fwnode(dev, fwnode); 33 33 } 34 34 35 35 static void *typec_switch_match(struct fwnode_handle *fwnode, const char *id, ··· 259 259 if (!is_typec_mux_dev(dev)) 260 260 return 0; 261 261 262 - return dev_fwnode(dev) == fwnode; 262 + return device_match_fwnode(dev, fwnode); 263 263 } 264 264 265 265 static void *typec_mux_match(struct fwnode_handle *fwnode, const char *id,
+2 -3
drivers/usb/typec/qcom-pmic-typec.c
··· 195 195 196 196 qcom_usb->role_sw = fwnode_usb_role_switch_get(dev_fwnode(qcom_usb->dev)); 197 197 if (IS_ERR(qcom_usb->role_sw)) { 198 - if (PTR_ERR(qcom_usb->role_sw) != -EPROBE_DEFER) 199 - dev_err(dev, "failed to get role switch\n"); 200 - ret = PTR_ERR(qcom_usb->role_sw); 198 + ret = dev_err_probe(dev, PTR_ERR(qcom_usb->role_sw), 199 + "failed to get role switch\n"); 201 200 goto err_typec_port; 202 201 } 203 202
+1 -1
drivers/usb/typec/retimer.c
··· 31 31 32 32 static int retimer_fwnode_match(struct device *dev, const void *fwnode) 33 33 { 34 - return dev_fwnode(dev) == fwnode && dev_name_ends_with(dev, "-retimer"); 34 + return device_match_fwnode(dev, fwnode) && dev_name_ends_with(dev, "-retimer"); 35 35 } 36 36 37 37 static void *typec_retimer_match(struct fwnode_handle *fwnode, const char *id, void *data)
+2 -5
drivers/usb/typec/stusb160x.c
··· 750 750 if (client->irq) { 751 751 chip->role_sw = fwnode_usb_role_switch_get(fwnode); 752 752 if (IS_ERR(chip->role_sw)) { 753 - ret = PTR_ERR(chip->role_sw); 754 - if (ret != -EPROBE_DEFER) 755 - dev_err(chip->dev, 756 - "Failed to get usb role switch: %d\n", 757 - ret); 753 + ret = dev_err_probe(chip->dev, PTR_ERR(chip->role_sw), 754 + "Failed to get usb role switch\n"); 758 755 goto port_unregister; 759 756 } 760 757
+11
drivers/usb/typec/tcpm/Kconfig
··· 35 35 USB Type-C. It works with Type-C Port Controller Manager 36 36 to provide USB PD and USB Type-C functionalities. 37 37 38 + config TYPEC_TCPCI_MT6370 39 + tristate "MediaTek MT6370 Type-C driver" 40 + depends on MFD_MT6370 41 + help 42 + MediaTek MT6370 is a multi-functional IC that includes 43 + USB Type-C. It works with Type-C Port Controller Manager 44 + to provide USB PD and USB Type-C functionalities. 45 + 46 + This driver can also be built as a module. The module 47 + will be called "tcpci_mt6370". 48 + 38 49 config TYPEC_TCPCI_MAXIM 39 50 tristate "Maxim TCPCI based Type-C chip driver" 40 51 help
+1
drivers/usb/typec/tcpm/Makefile
··· 6 6 obj-$(CONFIG_TYPEC_TCPCI) += tcpci.o 7 7 obj-$(CONFIG_TYPEC_RT1711H) += tcpci_rt1711h.o 8 8 obj-$(CONFIG_TYPEC_MT6360) += tcpci_mt6360.o 9 + obj-$(CONFIG_TYPEC_TCPCI_MT6370) += tcpci_mt6370.o 9 10 obj-$(CONFIG_TYPEC_TCPCI_MAXIM) += tcpci_maxim.o
+3 -4
drivers/usb/typec/tcpm/fusb302.c
··· 151 151 152 152 if (fusb302_log_full(chip)) { 153 153 chip->logbuffer_head = max(chip->logbuffer_head - 1, 0); 154 - strlcpy(tmpbuffer, "overflow", sizeof(tmpbuffer)); 154 + strscpy(tmpbuffer, "overflow", sizeof(tmpbuffer)); 155 155 } 156 156 157 157 if (chip->logbuffer_head < 0 || ··· 1743 1743 chip->tcpm_port = tcpm_register_port(&client->dev, &chip->tcpc_dev); 1744 1744 if (IS_ERR(chip->tcpm_port)) { 1745 1745 fwnode_handle_put(chip->tcpc_dev.fwnode); 1746 - ret = PTR_ERR(chip->tcpm_port); 1747 - if (ret != -EPROBE_DEFER) 1748 - dev_err(dev, "cannot register tcpm port, ret=%d", ret); 1746 + ret = dev_err_probe(dev, PTR_ERR(chip->tcpm_port), 1747 + "cannot register tcpm port\n"); 1749 1748 goto destroy_workqueue; 1750 1749 } 1751 1750
-22
drivers/usb/typec/tcpm/tcpci.c
··· 27 27 #define VPPS_VALID_MIN_MV 100 28 28 #define VSINKDISCONNECT_PD_MIN_PERCENT 90 29 29 30 - #define tcpc_presenting_rd(reg, cc) \ 31 - (!(TCPC_ROLE_CTRL_DRP & (reg)) && \ 32 - (((reg) & (TCPC_ROLE_CTRL_## cc ##_MASK << TCPC_ROLE_CTRL_## cc ##_SHIFT)) == \ 33 - (TCPC_ROLE_CTRL_CC_RD << TCPC_ROLE_CTRL_## cc ##_SHIFT))) 34 - 35 30 struct tcpci { 36 31 struct device *dev; 37 32 ··· 211 216 return ret; 212 217 return regmap_write(tcpci->regmap, TCPC_COMMAND, 213 218 TCPC_CMD_LOOK4CONNECTION); 214 - } 215 - 216 - static enum typec_cc_status tcpci_to_typec_cc(unsigned int cc, bool sink) 217 - { 218 - switch (cc) { 219 - case 0x1: 220 - return sink ? TYPEC_CC_RP_DEF : TYPEC_CC_RA; 221 - case 0x2: 222 - return sink ? TYPEC_CC_RP_1_5 : TYPEC_CC_RD; 223 - case 0x3: 224 - if (sink) 225 - return TYPEC_CC_RP_3_0; 226 - fallthrough; 227 - case 0x0: 228 - default: 229 - return TYPEC_CC_OPEN; 230 - } 231 219 } 232 220 233 221 static int tcpci_get_cc(struct tcpc_dev *tcpc,
+207
drivers/usb/typec/tcpm/tcpci_mt6370.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + /* 3 + * Copyright (C) 2022 Richtek Technology Corp. 4 + * 5 + * Author: ChiYuan Huang <cy_huang@richtek.com> 6 + */ 7 + 8 + #include <linux/bits.h> 9 + #include <linux/interrupt.h> 10 + #include <linux/kernel.h> 11 + #include <linux/mod_devicetable.h> 12 + #include <linux/module.h> 13 + #include <linux/platform_device.h> 14 + #include <linux/pm_wakeup.h> 15 + #include <linux/pm_wakeirq.h> 16 + #include <linux/regmap.h> 17 + #include <linux/regulator/consumer.h> 18 + #include <linux/usb/tcpci.h> 19 + #include <linux/usb/tcpm.h> 20 + 21 + #define MT6370_REG_SYSCTRL8 0x9B 22 + 23 + #define MT6370_AUTOIDLE_MASK BIT(3) 24 + 25 + #define MT6370_VENDOR_ID 0x29CF 26 + #define MT6370_TCPC_DID_A 0x2170 27 + 28 + struct mt6370_priv { 29 + struct device *dev; 30 + struct regulator *vbus; 31 + struct tcpci *tcpci; 32 + struct tcpci_data tcpci_data; 33 + }; 34 + 35 + static const struct reg_sequence mt6370_reg_init[] = { 36 + REG_SEQ(0xA0, 0x1, 1000), 37 + REG_SEQ(0x81, 0x38, 0), 38 + REG_SEQ(0x82, 0x82, 0), 39 + REG_SEQ(0xBA, 0xFC, 0), 40 + REG_SEQ(0xBB, 0x50, 0), 41 + REG_SEQ(0x9E, 0x8F, 0), 42 + REG_SEQ(0xA1, 0x5, 0), 43 + REG_SEQ(0xA2, 0x4, 0), 44 + REG_SEQ(0xA3, 0x4A, 0), 45 + REG_SEQ(0xA4, 0x01, 0), 46 + REG_SEQ(0x95, 0x01, 0), 47 + REG_SEQ(0x80, 0x71, 0), 48 + REG_SEQ(0x9B, 0x3A, 1000), 49 + }; 50 + 51 + static int mt6370_tcpc_init(struct tcpci *tcpci, struct tcpci_data *data) 52 + { 53 + u16 did; 54 + int ret; 55 + 56 + ret = regmap_register_patch(data->regmap, mt6370_reg_init, 57 + ARRAY_SIZE(mt6370_reg_init)); 58 + if (ret) 59 + return ret; 60 + 61 + ret = regmap_raw_read(data->regmap, TCPC_BCD_DEV, &did, sizeof(u16)); 62 + if (ret) 63 + return ret; 64 + 65 + if (did == MT6370_TCPC_DID_A) 66 + return regmap_write(data->regmap, TCPC_FAULT_CTRL, 0x80); 67 + 68 + return 0; 69 + } 70 + 71 + static int mt6370_tcpc_set_vconn(struct tcpci *tcpci, struct tcpci_data *data, 72 + bool enable) 73 + { 74 + return regmap_update_bits(data->regmap, MT6370_REG_SYSCTRL8, 75 + MT6370_AUTOIDLE_MASK, 76 + enable ? 0 : MT6370_AUTOIDLE_MASK); 77 + } 78 + 79 + static int mt6370_tcpc_set_vbus(struct tcpci *tcpci, struct tcpci_data *data, 80 + bool source, bool sink) 81 + { 82 + struct mt6370_priv *priv = container_of(data, struct mt6370_priv, 83 + tcpci_data); 84 + int ret; 85 + 86 + ret = regulator_is_enabled(priv->vbus); 87 + if (ret < 0) 88 + return ret; 89 + 90 + if (ret && !source) 91 + return regulator_disable(priv->vbus); 92 + 93 + if (!ret && source) 94 + return regulator_enable(priv->vbus); 95 + 96 + return 0; 97 + } 98 + 99 + static irqreturn_t mt6370_irq_handler(int irq, void *dev_id) 100 + { 101 + struct mt6370_priv *priv = dev_id; 102 + 103 + return tcpci_irq(priv->tcpci); 104 + } 105 + 106 + static int mt6370_check_vendor_info(struct mt6370_priv *priv) 107 + { 108 + struct regmap *regmap = priv->tcpci_data.regmap; 109 + u16 vid; 110 + int ret; 111 + 112 + ret = regmap_raw_read(regmap, TCPC_VENDOR_ID, &vid, sizeof(u16)); 113 + if (ret) 114 + return ret; 115 + 116 + if (vid != MT6370_VENDOR_ID) 117 + return dev_err_probe(priv->dev, -ENODEV, 118 + "Vendor ID not correct 0x%02x\n", vid); 119 + 120 + return 0; 121 + } 122 + 123 + static void mt6370_unregister_tcpci_port(void *tcpci) 124 + { 125 + tcpci_unregister_port(tcpci); 126 + } 127 + 128 + static int mt6370_tcpc_probe(struct platform_device *pdev) 129 + { 130 + struct mt6370_priv *priv; 131 + struct device *dev = &pdev->dev; 132 + int irq, ret; 133 + 134 + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); 135 + if (!priv) 136 + return -ENOMEM; 137 + 138 + priv->dev = dev; 139 + 140 + priv->tcpci_data.regmap = dev_get_regmap(dev->parent, NULL); 141 + if (!priv->tcpci_data.regmap) 142 + return dev_err_probe(dev, -ENODEV, "Failed to init regmap\n"); 143 + 144 + ret = mt6370_check_vendor_info(priv); 145 + if (ret) 146 + return ret; 147 + 148 + irq = platform_get_irq(pdev, 0); 149 + if (irq < 0) 150 + return dev_err_probe(dev, irq, "Failed to get irq\n"); 151 + 152 + /* Assign TCPCI feature and ops */ 153 + priv->tcpci_data.auto_discharge_disconnect = 1; 154 + priv->tcpci_data.init = mt6370_tcpc_init; 155 + priv->tcpci_data.set_vconn = mt6370_tcpc_set_vconn; 156 + 157 + priv->vbus = devm_regulator_get_optional(dev, "vbus"); 158 + if (!IS_ERR(priv->vbus)) 159 + priv->tcpci_data.set_vbus = mt6370_tcpc_set_vbus; 160 + 161 + priv->tcpci = tcpci_register_port(dev, &priv->tcpci_data); 162 + if (IS_ERR(priv->tcpci)) 163 + return dev_err_probe(dev, PTR_ERR(priv->tcpci), 164 + "Failed to register tcpci port\n"); 165 + 166 + ret = devm_add_action_or_reset(dev, mt6370_unregister_tcpci_port, priv->tcpci); 167 + if (ret) 168 + return ret; 169 + 170 + ret = devm_request_threaded_irq(dev, irq, NULL, mt6370_irq_handler, 171 + IRQF_ONESHOT, dev_name(dev), priv); 172 + if (ret) 173 + return dev_err_probe(dev, ret, "Failed to allocate irq\n"); 174 + 175 + device_init_wakeup(dev, true); 176 + dev_pm_set_wake_irq(dev, irq); 177 + 178 + return 0; 179 + } 180 + 181 + static int mt6370_tcpc_remove(struct platform_device *pdev) 182 + { 183 + dev_pm_clear_wake_irq(&pdev->dev); 184 + device_init_wakeup(&pdev->dev, false); 185 + 186 + return 0; 187 + } 188 + 189 + static const struct of_device_id mt6370_tcpc_devid_table[] = { 190 + { .compatible = "mediatek,mt6370-tcpc" }, 191 + {} 192 + }; 193 + MODULE_DEVICE_TABLE(of, mt6370_tcpc_devid_table); 194 + 195 + static struct platform_driver mt6370_tcpc_driver = { 196 + .driver = { 197 + .name = "mt6370-tcpc", 198 + .of_match_table = mt6370_tcpc_devid_table, 199 + }, 200 + .probe = mt6370_tcpc_probe, 201 + .remove = mt6370_tcpc_remove, 202 + }; 203 + module_platform_driver(mt6370_tcpc_driver); 204 + 205 + MODULE_AUTHOR("ChiYuan Huang <cy_huang@richtek.com>"); 206 + MODULE_DESCRIPTION("MT6370 USB Type-C Port Controller Interface Driver"); 207 + MODULE_LICENSE("GPL v2");
+137 -13
drivers/usb/typec/tcpm/tcpci_rt1711h.c
··· 5 5 * Richtek RT1711H Type-C Chip Driver 6 6 */ 7 7 8 + #include <linux/bits.h> 8 9 #include <linux/kernel.h> 9 10 #include <linux/module.h> 10 11 #include <linux/i2c.h> ··· 14 13 #include <linux/usb/tcpci.h> 15 14 #include <linux/usb/tcpm.h> 16 15 #include <linux/regmap.h> 16 + #include <linux/regulator/consumer.h> 17 17 18 18 #define RT1711H_VID 0x29CF 19 19 #define RT1711H_PID 0x1711 20 + #define RT1711H_DID 0x2171 21 + #define RT1715_DID 0x2173 22 + 23 + #define RT1711H_PHYCTRL1 0x80 24 + #define RT1711H_PHYCTRL2 0x81 25 + 26 + #define RT1711H_RTCTRL4 0x93 27 + /* rx threshold of rd/rp: 1b0 for level 0.4V/0.7V, 1b1 for 0.35V/0.75V */ 28 + #define RT1711H_BMCIO_RXDZSEL BIT(0) 20 29 21 30 #define RT1711H_RTCTRL8 0x9B 22 - 23 31 /* Autoidle timeout = (tout * 2 + 1) * 6.4ms */ 24 32 #define RT1711H_RTCTRL8_SET(ck300, ship_off, auto_idle, tout) \ 25 33 (((ck300) << 7) | ((ship_off) << 5) | \ 26 34 ((auto_idle) << 3) | ((tout) & 0x07)) 35 + #define RT1711H_AUTOIDLEEN BIT(3) 36 + #define RT1711H_ENEXTMSG BIT(4) 27 37 28 38 #define RT1711H_RTCTRL11 0x9E 29 39 ··· 47 35 #define RT1711H_RTCTRL15 0xA2 48 36 #define RT1711H_RTCTRL16 0xA3 49 37 38 + #define RT1711H_RTCTRL18 0xAF 39 + /* 1b0 as fixed rx threshold of rd/rp 0.55V, 1b1 depends on RTCRTL4[0] */ 40 + #define BMCIO_RXDZEN BIT(0) 41 + 50 42 struct rt1711h_chip { 51 43 struct tcpci_data data; 52 44 struct tcpci *tcpci; 53 45 struct device *dev; 46 + struct regulator *vbus; 47 + bool src_en; 48 + u16 did; 54 49 }; 55 50 56 51 static int rt1711h_read16(struct rt1711h_chip *chip, unsigned int reg, u16 *val) ··· 94 75 95 76 static int rt1711h_init(struct tcpci *tcpci, struct tcpci_data *tdata) 96 77 { 97 - int ret; 98 78 struct rt1711h_chip *chip = tdata_to_rt1711h(tdata); 79 + struct regmap *regmap = chip->data.regmap; 80 + int ret; 99 81 100 82 /* CK 300K from 320K, shipping off, auto_idle enable, tout = 32ms */ 101 83 ret = rt1711h_write8(chip, RT1711H_RTCTRL8, 102 84 RT1711H_RTCTRL8_SET(0, 1, 1, 2)); 103 85 if (ret < 0) 104 86 return ret; 87 + 88 + /* Enable PD30 extended message for RT1715 */ 89 + if (chip->did == RT1715_DID) { 90 + ret = regmap_update_bits(regmap, RT1711H_RTCTRL8, 91 + RT1711H_ENEXTMSG, RT1711H_ENEXTMSG); 92 + if (ret < 0) 93 + return ret; 94 + } 105 95 106 96 /* I2C reset : (val + 1) * 12.5ms */ 107 97 ret = rt1711h_write8(chip, RT1711H_RTCTRL11, ··· 129 101 return ret; 130 102 131 103 /* dcSRC.DRP : 33% */ 132 - return rt1711h_write16(chip, RT1711H_RTCTRL16, 330); 104 + ret = rt1711h_write16(chip, RT1711H_RTCTRL16, 330); 105 + if (ret < 0) 106 + return ret; 107 + 108 + /* Enable phy discard retry, retry count 7, rx filter deglitch 100 us */ 109 + ret = rt1711h_write8(chip, RT1711H_PHYCTRL1, 0xF1); 110 + if (ret < 0) 111 + return ret; 112 + 113 + /* Decrease wait time of BMC-encoded 1 bit from 2.67us to 2.55us */ 114 + /* wait time : (val * .4167) us */ 115 + return rt1711h_write8(chip, RT1711H_PHYCTRL2, 62); 116 + } 117 + 118 + static int rt1711h_set_vbus(struct tcpci *tcpci, struct tcpci_data *tdata, 119 + bool src, bool snk) 120 + { 121 + struct rt1711h_chip *chip = tdata_to_rt1711h(tdata); 122 + int ret; 123 + 124 + if (chip->src_en == src) 125 + return 0; 126 + 127 + if (src) 128 + ret = regulator_enable(chip->vbus); 129 + else 130 + ret = regulator_disable(chip->vbus); 131 + 132 + if (!ret) 133 + chip->src_en = src; 134 + return ret; 133 135 } 134 136 135 137 static int rt1711h_set_vconn(struct tcpci *tcpci, struct tcpci_data *tdata, ··· 167 109 { 168 110 struct rt1711h_chip *chip = tdata_to_rt1711h(tdata); 169 111 170 - return rt1711h_write8(chip, RT1711H_RTCTRL8, 171 - RT1711H_RTCTRL8_SET(0, 1, !enable, 2)); 112 + return regmap_update_bits(chip->data.regmap, RT1711H_RTCTRL8, 113 + RT1711H_AUTOIDLEEN, enable ? 0 : RT1711H_AUTOIDLEEN); 114 + } 115 + 116 + /* 117 + * Selects the CC PHY noise filter voltage level according to the remote current 118 + * CC voltage level. 119 + * 120 + * @status: The port's current cc status read from IC 121 + * Return 0 if writes succeed; failure code otherwise 122 + */ 123 + static inline int rt1711h_init_cc_params(struct rt1711h_chip *chip, u8 status) 124 + { 125 + int ret, cc1, cc2; 126 + u8 role = 0; 127 + u32 rxdz_en, rxdz_sel; 128 + 129 + ret = rt1711h_read8(chip, TCPC_ROLE_CTRL, &role); 130 + if (ret < 0) 131 + return ret; 132 + 133 + cc1 = tcpci_to_typec_cc((status >> TCPC_CC_STATUS_CC1_SHIFT) & 134 + TCPC_CC_STATUS_CC1_MASK, 135 + status & TCPC_CC_STATUS_TERM || 136 + tcpc_presenting_rd(role, CC1)); 137 + cc2 = tcpci_to_typec_cc((status >> TCPC_CC_STATUS_CC2_SHIFT) & 138 + TCPC_CC_STATUS_CC2_MASK, 139 + status & TCPC_CC_STATUS_TERM || 140 + tcpc_presenting_rd(role, CC2)); 141 + 142 + if ((cc1 >= TYPEC_CC_RP_1_5 && cc2 < TYPEC_CC_RP_DEF) || 143 + (cc2 >= TYPEC_CC_RP_1_5 && cc1 < TYPEC_CC_RP_DEF)) { 144 + rxdz_en = BMCIO_RXDZEN; 145 + if (chip->did == RT1715_DID) 146 + rxdz_sel = RT1711H_BMCIO_RXDZSEL; 147 + else 148 + rxdz_sel = 0; 149 + } else { 150 + rxdz_en = 0; 151 + rxdz_sel = RT1711H_BMCIO_RXDZSEL; 152 + } 153 + 154 + ret = regmap_update_bits(chip->data.regmap, RT1711H_RTCTRL18, 155 + BMCIO_RXDZEN, rxdz_en); 156 + if (ret < 0) 157 + return ret; 158 + 159 + return regmap_update_bits(chip->data.regmap, RT1711H_RTCTRL4, 160 + RT1711H_BMCIO_RXDZSEL, rxdz_sel); 172 161 } 173 162 174 163 static int rt1711h_start_drp_toggling(struct tcpci *tcpci, ··· 278 173 /* Clear cc change event triggered by starting toggling */ 279 174 if (status & TCPC_CC_STATUS_TOGGLING) 280 175 rt1711h_write8(chip, TCPC_ALERT, TCPC_ALERT_CC_STATUS); 176 + else 177 + rt1711h_init_cc_params(chip, status); 281 178 } 282 179 283 180 out: ··· 298 191 return 0; 299 192 } 300 193 301 - static int rt1711h_check_revision(struct i2c_client *i2c) 194 + static int rt1711h_check_revision(struct i2c_client *i2c, struct rt1711h_chip *chip) 302 195 { 303 196 int ret; 304 197 ··· 316 209 dev_err(&i2c->dev, "pid is not correct, 0x%04x\n", ret); 317 210 return -ENODEV; 318 211 } 319 - return 0; 212 + ret = i2c_smbus_read_word_data(i2c, TCPC_BCD_DEV); 213 + if (ret < 0) 214 + return ret; 215 + if (ret != chip->did) { 216 + dev_err(&i2c->dev, "did is not correct, 0x%04x\n", ret); 217 + return -ENODEV; 218 + } 219 + dev_dbg(&i2c->dev, "did is 0x%04x\n", ret); 220 + return ret; 320 221 } 321 222 322 223 static int rt1711h_probe(struct i2c_client *client, ··· 333 218 int ret; 334 219 struct rt1711h_chip *chip; 335 220 336 - ret = rt1711h_check_revision(client); 221 + chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL); 222 + if (!chip) 223 + return -ENOMEM; 224 + 225 + chip->did = (size_t)device_get_match_data(&client->dev); 226 + 227 + ret = rt1711h_check_revision(client, chip); 337 228 if (ret < 0) { 338 229 dev_err(&client->dev, "check vid/pid fail\n"); 339 230 return ret; 340 231 } 341 - 342 - chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL); 343 - if (!chip) 344 - return -ENOMEM; 345 232 346 233 chip->data.regmap = devm_regmap_init_i2c(client, 347 234 &rt1711h_regmap_config); ··· 362 245 if (ret < 0) 363 246 return ret; 364 247 248 + chip->vbus = devm_regulator_get(&client->dev, "vbus"); 249 + if (IS_ERR(chip->vbus)) 250 + return PTR_ERR(chip->vbus); 251 + 365 252 chip->data.init = rt1711h_init; 253 + chip->data.set_vbus = rt1711h_set_vbus; 366 254 chip->data.set_vconn = rt1711h_set_vconn; 367 255 chip->data.start_drp_toggling = rt1711h_start_drp_toggling; 368 256 chip->tcpci = tcpci_register_port(chip->dev, &chip->data); ··· 394 272 395 273 static const struct i2c_device_id rt1711h_id[] = { 396 274 { "rt1711h", 0 }, 275 + { "rt1715", 0 }, 397 276 { } 398 277 }; 399 278 MODULE_DEVICE_TABLE(i2c, rt1711h_id); 400 279 401 280 #ifdef CONFIG_OF 402 281 static const struct of_device_id rt1711h_of_match[] = { 403 - { .compatible = "richtek,rt1711h", }, 282 + { .compatible = "richtek,rt1711h", .data = (void *)RT1711H_DID }, 283 + { .compatible = "richtek,rt1715", .data = (void *)RT1715_DID }, 404 284 {}, 405 285 }; 406 286 MODULE_DEVICE_TABLE(of, rt1711h_of_match);
+3 -5
drivers/usb/typec/ucsi/ucsi.c
··· 1067 1067 1068 1068 cap->fwnode = ucsi_find_fwnode(con); 1069 1069 con->usb_role_sw = fwnode_usb_role_switch_get(cap->fwnode); 1070 - if (IS_ERR(con->usb_role_sw)) { 1071 - dev_err(ucsi->dev, "con%d: failed to get usb role switch\n", 1072 - con->num); 1073 - return PTR_ERR(con->usb_role_sw); 1074 - } 1070 + if (IS_ERR(con->usb_role_sw)) 1071 + return dev_err_probe(ucsi->dev, PTR_ERR(con->usb_role_sw), 1072 + "con%d: failed to get usb role switch\n", con->num); 1075 1073 1076 1074 /* Delay other interactions with the con until registration is complete */ 1077 1075 mutex_lock(&con->lock);
+12
drivers/usb/typec/ucsi/ucsi_ccg.c
··· 125 125 #define CCG_FW_BUILD_NVIDIA (('n' << 8) | 'v') 126 126 #define CCG_OLD_FW_VERSION (CCG_VERSION(0x31) | CCG_VERSION_PATCH(10)) 127 127 128 + /* Firmware for Tegra doesn't support UCSI ALT command, built 129 + * for NVIDIA has known issue of reporting wrong capability info 130 + */ 131 + #define CCG_FW_BUILD_NVIDIA_TEGRA (('g' << 8) | 'n') 132 + 128 133 /* Altmode offset for NVIDIA Function Test Board (FTB) */ 129 134 #define NVIDIA_FTB_DP_OFFSET (2) 130 135 #define NVIDIA_FTB_DBG_OFFSET (3) ··· 518 513 { 519 514 struct ucsi_ccg *uc = ucsi_get_drvdata(ucsi); 520 515 u16 reg = CCGX_RAB_UCSI_DATA_BLOCK(offset); 516 + struct ucsi_capability *cap; 521 517 struct ucsi_altmode *alt; 522 518 int ret; 523 519 ··· 540 534 alt = val; 541 535 if (alt[0].svid == USB_TYPEC_NVIDIA_VLINK_SID) 542 536 ucsi_ccg_nvidia_altmode(uc, alt); 537 + } 538 + break; 539 + case UCSI_GET_CAPABILITY: 540 + if (uc->fw_build == CCG_FW_BUILD_NVIDIA_TEGRA) { 541 + cap = val; 542 + cap->features &= ~UCSI_CAP_ALT_MODE_DETAILS; 543 543 } 544 544 break; 545 545 default:
+1 -1
drivers/usb/typec/ucsi/ucsi_stm32g0.c
··· 599 599 g0->i2c_bl = i2c_new_dummy_device(g0->client->adapter, STM32G0_I2C_BL_ADDR); 600 600 if (IS_ERR(g0->i2c_bl)) { 601 601 ret = dev_err_probe(g0->dev, PTR_ERR(g0->i2c_bl), 602 - "Failed to register booloader I2C address\n"); 602 + "Failed to register bootloader I2C address\n"); 603 603 return ret; 604 604 } 605 605 }
+1 -1
drivers/usb/usbip/stub_main.c
··· 100 100 for (i = 0; i < MAX_BUSID; i++) { 101 101 spin_lock(&busid_table[i].busid_lock); 102 102 if (!busid_table[i].name[0]) { 103 - strlcpy(busid_table[i].name, busid, BUSID_SIZE); 103 + strscpy(busid_table[i].name, busid, BUSID_SIZE); 104 104 if ((busid_table[i].status != STUB_BUSID_ALLOC) && 105 105 (busid_table[i].status != STUB_BUSID_REMOV)) 106 106 busid_table[i].status = STUB_BUSID_ADDED;
+2 -2
drivers/usb/usbip/stub_rx.c
··· 464 464 int nents; 465 465 int num_urbs = 1; 466 466 int pipe = get_pipe(sdev, pdu); 467 - int use_sg = pdu->u.cmd_submit.transfer_flags & URB_DMA_MAP_SG; 467 + int use_sg = pdu->u.cmd_submit.transfer_flags & USBIP_URB_DMA_MAP_SG; 468 468 int support_sg = 1; 469 469 int np = 0; 470 470 int ret, i; ··· 514 514 num_urbs = nents; 515 515 priv->completed_urbs = 0; 516 516 pdu->u.cmd_submit.transfer_flags &= 517 - ~URB_DMA_MAP_SG; 517 + ~USBIP_URB_DMA_MAP_SG; 518 518 } 519 519 } else { 520 520 buffer = kzalloc(buf_len, GFP_KERNEL);
+88 -3
drivers/usb/usbip/usbip_common.c
··· 344 344 return flags; 345 345 } 346 346 347 + /* 348 + * USBIP driver packs URB transfer flags in PDUs that are exchanged 349 + * between Server (usbip_host) and Client (vhci_hcd). URB_* flags 350 + * are internal to kernel and could change. Where as USBIP URB flags 351 + * exchanged in PDUs are USBIP user API must not change. 352 + * 353 + * USBIP_URB* flags are exported as explicit API and client and server 354 + * do mapping from kernel flags to USBIP_URB*. Details as follows: 355 + * 356 + * Client tx path (USBIP_CMD_SUBMIT): 357 + * - Maps URB_* to USBIP_URB_* when it sends USBIP_CMD_SUBMIT packet. 358 + * 359 + * Server rx path (USBIP_CMD_SUBMIT): 360 + * - Maps USBIP_URB_* to URB_* when it receives USBIP_CMD_SUBMIT packet. 361 + * 362 + * Flags aren't included in USBIP_CMD_UNLINK and USBIP_RET_SUBMIT packets 363 + * and no special handling is needed for them in the following cases: 364 + * - Server rx path (USBIP_CMD_UNLINK) 365 + * - Client rx path & Server tx path (USBIP_RET_SUBMIT) 366 + * 367 + * Code paths: 368 + * usbip_pack_pdu() is the common routine that handles packing pdu from 369 + * urb and unpack pdu to an urb. 370 + * 371 + * usbip_pack_cmd_submit() and usbip_pack_ret_submit() handle 372 + * USBIP_CMD_SUBMIT and USBIP_RET_SUBMIT respectively. 373 + * 374 + * usbip_map_urb_to_usbip() and usbip_map_usbip_to_urb() are used 375 + * by usbip_pack_cmd_submit() and usbip_pack_ret_submit() to map 376 + * flags. 377 + */ 378 + 379 + struct urb_to_usbip_flags { 380 + u32 urb_flag; 381 + u32 usbip_flag; 382 + }; 383 + 384 + #define NUM_USBIP_FLAGS 17 385 + 386 + static const struct urb_to_usbip_flags flag_map[NUM_USBIP_FLAGS] = { 387 + {URB_SHORT_NOT_OK, USBIP_URB_SHORT_NOT_OK}, 388 + {URB_ISO_ASAP, USBIP_URB_ISO_ASAP}, 389 + {URB_NO_TRANSFER_DMA_MAP, USBIP_URB_NO_TRANSFER_DMA_MAP}, 390 + {URB_ZERO_PACKET, USBIP_URB_ZERO_PACKET}, 391 + {URB_NO_INTERRUPT, USBIP_URB_NO_INTERRUPT}, 392 + {URB_FREE_BUFFER, USBIP_URB_FREE_BUFFER}, 393 + {URB_DIR_IN, USBIP_URB_DIR_IN}, 394 + {URB_DIR_OUT, USBIP_URB_DIR_OUT}, 395 + {URB_DIR_MASK, USBIP_URB_DIR_MASK}, 396 + {URB_DMA_MAP_SINGLE, USBIP_URB_DMA_MAP_SINGLE}, 397 + {URB_DMA_MAP_PAGE, USBIP_URB_DMA_MAP_PAGE}, 398 + {URB_DMA_MAP_SG, USBIP_URB_DMA_MAP_SG}, 399 + {URB_MAP_LOCAL, USBIP_URB_MAP_LOCAL}, 400 + {URB_SETUP_MAP_SINGLE, USBIP_URB_SETUP_MAP_SINGLE}, 401 + {URB_SETUP_MAP_LOCAL, USBIP_URB_SETUP_MAP_LOCAL}, 402 + {URB_DMA_SG_COMBINED, USBIP_URB_DMA_SG_COMBINED}, 403 + {URB_ALIGNED_TEMP_BUFFER, USBIP_URB_ALIGNED_TEMP_BUFFER}, 404 + }; 405 + 406 + static unsigned int urb_to_usbip(unsigned int flags) 407 + { 408 + unsigned int map_flags = 0; 409 + int loop; 410 + 411 + for (loop = 0; loop < NUM_USBIP_FLAGS; loop++) { 412 + if (flags & flag_map[loop].urb_flag) 413 + map_flags |= flag_map[loop].usbip_flag; 414 + } 415 + 416 + return map_flags; 417 + } 418 + 419 + static unsigned int usbip_to_urb(unsigned int flags) 420 + { 421 + unsigned int map_flags = 0; 422 + int loop; 423 + 424 + for (loop = 0; loop < NUM_USBIP_FLAGS; loop++) { 425 + if (flags & flag_map[loop].usbip_flag) 426 + map_flags |= flag_map[loop].urb_flag; 427 + } 428 + 429 + return map_flags; 430 + } 431 + 347 432 static void usbip_pack_cmd_submit(struct usbip_header *pdu, struct urb *urb, 348 433 int pack) 349 434 { ··· 439 354 * will be discussed when usbip is ported to other operating systems. 440 355 */ 441 356 if (pack) { 442 - spdu->transfer_flags = 443 - tweak_transfer_flags(urb->transfer_flags); 357 + /* map after tweaking the urb flags */ 358 + spdu->transfer_flags = urb_to_usbip(tweak_transfer_flags(urb->transfer_flags)); 444 359 spdu->transfer_buffer_length = urb->transfer_buffer_length; 445 360 spdu->start_frame = urb->start_frame; 446 361 spdu->number_of_packets = urb->number_of_packets; 447 362 spdu->interval = urb->interval; 448 363 } else { 449 - urb->transfer_flags = spdu->transfer_flags; 364 + urb->transfer_flags = usbip_to_urb(spdu->transfer_flags); 450 365 urb->transfer_buffer_length = spdu->transfer_buffer_length; 451 366 urb->start_frame = spdu->start_frame; 452 367 urb->number_of_packets = spdu->number_of_packets;
+3 -1
include/linux/phy/tegra/xusb.h
··· 1 1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 2 /* 3 - * Copyright (c) 2016-2020, NVIDIA CORPORATION. All rights reserved. 3 + * Copyright (c) 2016-2022, NVIDIA CORPORATION. All rights reserved. 4 4 */ 5 5 6 6 #ifndef PHY_TEGRA_XUSB_H ··· 21 21 unsigned int port, bool enable); 22 22 int tegra_xusb_padctl_set_vbus_override(struct tegra_xusb_padctl *padctl, 23 23 bool val); 24 + void tegra_phy_xusb_utmi_pad_power_on(struct phy *phy); 25 + void tegra_phy_xusb_utmi_pad_power_down(struct phy *phy); 24 26 int tegra_phy_xusb_utmi_port_reset(struct phy *phy); 25 27 int tegra_xusb_padctl_get_usb3_companion(struct tegra_xusb_padctl *padctl, 26 28 unsigned int port);
-6
include/linux/platform_data/usb-s3c2410_udc.h
··· 22 22 struct s3c2410_udc_mach_info { 23 23 void (*udc_command)(enum s3c2410_udc_cmd_e); 24 24 void (*vbus_draw)(unsigned int ma); 25 - 26 - unsigned int pullup_pin; 27 - unsigned int pullup_pin_inverted; 28 - 29 - unsigned int vbus_pin; 30 - unsigned char vbus_pin_inverted; 31 25 }; 32 26 33 27 extern void __init s3c24xx_udc_set_platdata(struct s3c2410_udc_mach_info *);
+1
include/linux/usb/chipidea.h
··· 62 62 #define CI_HDRC_REQUIRES_ALIGNED_DMA BIT(13) 63 63 #define CI_HDRC_IMX_IS_HSIC BIT(14) 64 64 #define CI_HDRC_PMQOS BIT(15) 65 + #define CI_HDRC_PHY_VBUS_CONTROL BIT(16) 65 66 enum usb_dr_mode dr_mode; 66 67 #define CI_HDRC_CONTROLLER_RESET_EVENT 0 67 68 #define CI_HDRC_CONTROLLER_STOPPED_EVENT 1
-1
include/linux/usb/hcd.h
··· 479 479 struct pci_dev; 480 480 struct pci_device_id; 481 481 extern int usb_hcd_pci_probe(struct pci_dev *dev, 482 - const struct pci_device_id *id, 483 482 const struct hc_driver *driver); 484 483 extern void usb_hcd_pci_remove(struct pci_dev *dev); 485 484 extern void usb_hcd_pci_shutdown(struct pci_dev *dev);
+22
include/linux/usb/tcpci.h
··· 167 167 /* I2C_WRITE_BYTE_COUNT + 1 when TX_BUF_BYTE_x is only accessible I2C_WRITE_BYTE_COUNT */ 168 168 #define TCPC_TRANSMIT_BUFFER_MAX_LEN 31 169 169 170 + #define tcpc_presenting_rd(reg, cc) \ 171 + (!(TCPC_ROLE_CTRL_DRP & (reg)) && \ 172 + (((reg) & (TCPC_ROLE_CTRL_## cc ##_MASK << TCPC_ROLE_CTRL_## cc ##_SHIFT)) == \ 173 + (TCPC_ROLE_CTRL_CC_RD << TCPC_ROLE_CTRL_## cc ##_SHIFT))) 174 + 170 175 struct tcpci; 171 176 172 177 /* ··· 212 207 213 208 struct tcpm_port; 214 209 struct tcpm_port *tcpci_get_tcpm_port(struct tcpci *tcpci); 210 + 211 + static inline enum typec_cc_status tcpci_to_typec_cc(unsigned int cc, bool sink) 212 + { 213 + switch (cc) { 214 + case 0x1: 215 + return sink ? TYPEC_CC_RP_DEF : TYPEC_CC_RA; 216 + case 0x2: 217 + return sink ? TYPEC_CC_RP_1_5 : TYPEC_CC_RD; 218 + case 0x3: 219 + if (sink) 220 + return TYPEC_CC_RP_3_0; 221 + fallthrough; 222 + case 0x0: 223 + default: 224 + return TYPEC_CC_OPEN; 225 + } 226 + } 215 227 #endif /* __LINUX_USB_TCPCI_H */
+4
include/media/v4l2-common.h
··· 540 540 s64 v4l2_get_link_freq(struct v4l2_ctrl_handler *handler, unsigned int mul, 541 541 unsigned int div); 542 542 543 + void v4l2_simplify_fraction(u32 *numerator, u32 *denominator, 544 + unsigned int n_terms, unsigned int threshold); 545 + u32 v4l2_fraction_to_interval(u32 numerator, u32 denominator); 546 + 543 547 static inline u64 v4l2_buffer_get_timestamp(const struct v4l2_buffer *buf) 544 548 { 545 549 /*
+359
include/media/v4l2-uvc.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 + /* 3 + * v4l2 uvc internal API header 4 + * 5 + * Some commonly needed functions for uvc drivers 6 + */ 7 + 8 + #ifndef __LINUX_V4L2_UVC_H 9 + #define __LINUX_V4L2_UVC_H 10 + 11 + /* ------------------------------------------------------------------------ 12 + * GUIDs 13 + */ 14 + #define UVC_GUID_UVC_CAMERA \ 15 + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 16 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01} 17 + #define UVC_GUID_UVC_OUTPUT \ 18 + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 19 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02} 20 + #define UVC_GUID_UVC_MEDIA_TRANSPORT_INPUT \ 21 + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 22 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03} 23 + #define UVC_GUID_UVC_PROCESSING \ 24 + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 25 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01} 26 + #define UVC_GUID_UVC_SELECTOR \ 27 + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 28 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02} 29 + #define UVC_GUID_EXT_GPIO_CONTROLLER \ 30 + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 31 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03} 32 + 33 + #define UVC_GUID_FORMAT_MJPEG \ 34 + { 'M', 'J', 'P', 'G', 0x00, 0x00, 0x10, 0x00, \ 35 + 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 36 + #define UVC_GUID_FORMAT_YUY2 \ 37 + { 'Y', 'U', 'Y', '2', 0x00, 0x00, 0x10, 0x00, \ 38 + 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 39 + #define UVC_GUID_FORMAT_YUY2_ISIGHT \ 40 + { 'Y', 'U', 'Y', '2', 0x00, 0x00, 0x10, 0x00, \ 41 + 0x80, 0x00, 0x00, 0x00, 0x00, 0x38, 0x9b, 0x71} 42 + #define UVC_GUID_FORMAT_NV12 \ 43 + { 'N', 'V', '1', '2', 0x00, 0x00, 0x10, 0x00, \ 44 + 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 45 + #define UVC_GUID_FORMAT_YV12 \ 46 + { 'Y', 'V', '1', '2', 0x00, 0x00, 0x10, 0x00, \ 47 + 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 48 + #define UVC_GUID_FORMAT_I420 \ 49 + { 'I', '4', '2', '0', 0x00, 0x00, 0x10, 0x00, \ 50 + 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 51 + #define UVC_GUID_FORMAT_UYVY \ 52 + { 'U', 'Y', 'V', 'Y', 0x00, 0x00, 0x10, 0x00, \ 53 + 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 54 + #define UVC_GUID_FORMAT_Y800 \ 55 + { 'Y', '8', '0', '0', 0x00, 0x00, 0x10, 0x00, \ 56 + 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 57 + #define UVC_GUID_FORMAT_Y8 \ 58 + { 'Y', '8', ' ', ' ', 0x00, 0x00, 0x10, 0x00, \ 59 + 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 60 + #define UVC_GUID_FORMAT_Y10 \ 61 + { 'Y', '1', '0', ' ', 0x00, 0x00, 0x10, 0x00, \ 62 + 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 63 + #define UVC_GUID_FORMAT_Y12 \ 64 + { 'Y', '1', '2', ' ', 0x00, 0x00, 0x10, 0x00, \ 65 + 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 66 + #define UVC_GUID_FORMAT_Y16 \ 67 + { 'Y', '1', '6', ' ', 0x00, 0x00, 0x10, 0x00, \ 68 + 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 69 + #define UVC_GUID_FORMAT_BY8 \ 70 + { 'B', 'Y', '8', ' ', 0x00, 0x00, 0x10, 0x00, \ 71 + 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 72 + #define UVC_GUID_FORMAT_BA81 \ 73 + { 'B', 'A', '8', '1', 0x00, 0x00, 0x10, 0x00, \ 74 + 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 75 + #define UVC_GUID_FORMAT_GBRG \ 76 + { 'G', 'B', 'R', 'G', 0x00, 0x00, 0x10, 0x00, \ 77 + 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 78 + #define UVC_GUID_FORMAT_GRBG \ 79 + { 'G', 'R', 'B', 'G', 0x00, 0x00, 0x10, 0x00, \ 80 + 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 81 + #define UVC_GUID_FORMAT_RGGB \ 82 + { 'R', 'G', 'G', 'B', 0x00, 0x00, 0x10, 0x00, \ 83 + 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 84 + #define UVC_GUID_FORMAT_BG16 \ 85 + { 'B', 'G', '1', '6', 0x00, 0x00, 0x10, 0x00, \ 86 + 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 87 + #define UVC_GUID_FORMAT_GB16 \ 88 + { 'G', 'B', '1', '6', 0x00, 0x00, 0x10, 0x00, \ 89 + 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 90 + #define UVC_GUID_FORMAT_RG16 \ 91 + { 'R', 'G', '1', '6', 0x00, 0x00, 0x10, 0x00, \ 92 + 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 93 + #define UVC_GUID_FORMAT_GR16 \ 94 + { 'G', 'R', '1', '6', 0x00, 0x00, 0x10, 0x00, \ 95 + 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 96 + #define UVC_GUID_FORMAT_RGBP \ 97 + { 'R', 'G', 'B', 'P', 0x00, 0x00, 0x10, 0x00, \ 98 + 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 99 + #define UVC_GUID_FORMAT_BGR3 \ 100 + { 0x7d, 0xeb, 0x36, 0xe4, 0x4f, 0x52, 0xce, 0x11, \ 101 + 0x9f, 0x53, 0x00, 0x20, 0xaf, 0x0b, 0xa7, 0x70} 102 + #define UVC_GUID_FORMAT_M420 \ 103 + { 'M', '4', '2', '0', 0x00, 0x00, 0x10, 0x00, \ 104 + 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 105 + 106 + #define UVC_GUID_FORMAT_H264 \ 107 + { 'H', '2', '6', '4', 0x00, 0x00, 0x10, 0x00, \ 108 + 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 109 + #define UVC_GUID_FORMAT_H265 \ 110 + { 'H', '2', '6', '5', 0x00, 0x00, 0x10, 0x00, \ 111 + 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 112 + #define UVC_GUID_FORMAT_Y8I \ 113 + { 'Y', '8', 'I', ' ', 0x00, 0x00, 0x10, 0x00, \ 114 + 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 115 + #define UVC_GUID_FORMAT_Y12I \ 116 + { 'Y', '1', '2', 'I', 0x00, 0x00, 0x10, 0x00, \ 117 + 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 118 + #define UVC_GUID_FORMAT_Z16 \ 119 + { 'Z', '1', '6', ' ', 0x00, 0x00, 0x10, 0x00, \ 120 + 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 121 + #define UVC_GUID_FORMAT_RW10 \ 122 + { 'R', 'W', '1', '0', 0x00, 0x00, 0x10, 0x00, \ 123 + 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 124 + #define UVC_GUID_FORMAT_INVZ \ 125 + { 'I', 'N', 'V', 'Z', 0x90, 0x2d, 0x58, 0x4a, \ 126 + 0x92, 0x0b, 0x77, 0x3f, 0x1f, 0x2c, 0x55, 0x6b} 127 + #define UVC_GUID_FORMAT_INZI \ 128 + { 'I', 'N', 'Z', 'I', 0x66, 0x1a, 0x42, 0xa2, \ 129 + 0x90, 0x65, 0xd0, 0x18, 0x14, 0xa8, 0xef, 0x8a} 130 + #define UVC_GUID_FORMAT_INVI \ 131 + { 'I', 'N', 'V', 'I', 0xdb, 0x57, 0x49, 0x5e, \ 132 + 0x8e, 0x3f, 0xf4, 0x79, 0x53, 0x2b, 0x94, 0x6f} 133 + #define UVC_GUID_FORMAT_CNF4 \ 134 + { 'C', ' ', ' ', ' ', 0x00, 0x00, 0x10, 0x00, \ 135 + 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 136 + 137 + #define UVC_GUID_FORMAT_D3DFMT_L8 \ 138 + {0x32, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, \ 139 + 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 140 + #define UVC_GUID_FORMAT_KSMEDIA_L8_IR \ 141 + {0x32, 0x00, 0x00, 0x00, 0x02, 0x00, 0x10, 0x00, \ 142 + 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 143 + 144 + #define UVC_GUID_FORMAT_HEVC \ 145 + { 'H', 'E', 'V', 'C', 0x00, 0x00, 0x10, 0x00, \ 146 + 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 147 + 148 + /* ------------------------------------------------------------------------ 149 + * Video formats 150 + */ 151 + 152 + struct uvc_format_desc { 153 + char *name; 154 + u8 guid[16]; 155 + u32 fcc; 156 + }; 157 + 158 + static struct uvc_format_desc uvc_fmts[] = { 159 + { 160 + .name = "YUV 4:2:2 (YUYV)", 161 + .guid = UVC_GUID_FORMAT_YUY2, 162 + .fcc = V4L2_PIX_FMT_YUYV, 163 + }, 164 + { 165 + .name = "YUV 4:2:2 (YUYV)", 166 + .guid = UVC_GUID_FORMAT_YUY2_ISIGHT, 167 + .fcc = V4L2_PIX_FMT_YUYV, 168 + }, 169 + { 170 + .name = "YUV 4:2:0 (NV12)", 171 + .guid = UVC_GUID_FORMAT_NV12, 172 + .fcc = V4L2_PIX_FMT_NV12, 173 + }, 174 + { 175 + .name = "MJPEG", 176 + .guid = UVC_GUID_FORMAT_MJPEG, 177 + .fcc = V4L2_PIX_FMT_MJPEG, 178 + }, 179 + { 180 + .name = "YVU 4:2:0 (YV12)", 181 + .guid = UVC_GUID_FORMAT_YV12, 182 + .fcc = V4L2_PIX_FMT_YVU420, 183 + }, 184 + { 185 + .name = "YUV 4:2:0 (I420)", 186 + .guid = UVC_GUID_FORMAT_I420, 187 + .fcc = V4L2_PIX_FMT_YUV420, 188 + }, 189 + { 190 + .name = "YUV 4:2:0 (M420)", 191 + .guid = UVC_GUID_FORMAT_M420, 192 + .fcc = V4L2_PIX_FMT_M420, 193 + }, 194 + { 195 + .name = "YUV 4:2:2 (UYVY)", 196 + .guid = UVC_GUID_FORMAT_UYVY, 197 + .fcc = V4L2_PIX_FMT_UYVY, 198 + }, 199 + { 200 + .name = "Greyscale 8-bit (Y800)", 201 + .guid = UVC_GUID_FORMAT_Y800, 202 + .fcc = V4L2_PIX_FMT_GREY, 203 + }, 204 + { 205 + .name = "Greyscale 8-bit (Y8 )", 206 + .guid = UVC_GUID_FORMAT_Y8, 207 + .fcc = V4L2_PIX_FMT_GREY, 208 + }, 209 + { 210 + .name = "Greyscale 8-bit (D3DFMT_L8)", 211 + .guid = UVC_GUID_FORMAT_D3DFMT_L8, 212 + .fcc = V4L2_PIX_FMT_GREY, 213 + }, 214 + { 215 + .name = "IR 8-bit (L8_IR)", 216 + .guid = UVC_GUID_FORMAT_KSMEDIA_L8_IR, 217 + .fcc = V4L2_PIX_FMT_GREY, 218 + }, 219 + { 220 + .name = "Greyscale 10-bit (Y10 )", 221 + .guid = UVC_GUID_FORMAT_Y10, 222 + .fcc = V4L2_PIX_FMT_Y10, 223 + }, 224 + { 225 + .name = "Greyscale 12-bit (Y12 )", 226 + .guid = UVC_GUID_FORMAT_Y12, 227 + .fcc = V4L2_PIX_FMT_Y12, 228 + }, 229 + { 230 + .name = "Greyscale 16-bit (Y16 )", 231 + .guid = UVC_GUID_FORMAT_Y16, 232 + .fcc = V4L2_PIX_FMT_Y16, 233 + }, 234 + { 235 + .name = "BGGR Bayer (BY8 )", 236 + .guid = UVC_GUID_FORMAT_BY8, 237 + .fcc = V4L2_PIX_FMT_SBGGR8, 238 + }, 239 + { 240 + .name = "BGGR Bayer (BA81)", 241 + .guid = UVC_GUID_FORMAT_BA81, 242 + .fcc = V4L2_PIX_FMT_SBGGR8, 243 + }, 244 + { 245 + .name = "GBRG Bayer (GBRG)", 246 + .guid = UVC_GUID_FORMAT_GBRG, 247 + .fcc = V4L2_PIX_FMT_SGBRG8, 248 + }, 249 + { 250 + .name = "GRBG Bayer (GRBG)", 251 + .guid = UVC_GUID_FORMAT_GRBG, 252 + .fcc = V4L2_PIX_FMT_SGRBG8, 253 + }, 254 + { 255 + .name = "RGGB Bayer (RGGB)", 256 + .guid = UVC_GUID_FORMAT_RGGB, 257 + .fcc = V4L2_PIX_FMT_SRGGB8, 258 + }, 259 + { 260 + .name = "RGB565", 261 + .guid = UVC_GUID_FORMAT_RGBP, 262 + .fcc = V4L2_PIX_FMT_RGB565, 263 + }, 264 + { 265 + .name = "BGR 8:8:8 (BGR3)", 266 + .guid = UVC_GUID_FORMAT_BGR3, 267 + .fcc = V4L2_PIX_FMT_BGR24, 268 + }, 269 + { 270 + .name = "H.264", 271 + .guid = UVC_GUID_FORMAT_H264, 272 + .fcc = V4L2_PIX_FMT_H264, 273 + }, 274 + { 275 + .name = "H.265", 276 + .guid = UVC_GUID_FORMAT_H265, 277 + .fcc = V4L2_PIX_FMT_HEVC, 278 + }, 279 + { 280 + .name = "Greyscale 8 L/R (Y8I)", 281 + .guid = UVC_GUID_FORMAT_Y8I, 282 + .fcc = V4L2_PIX_FMT_Y8I, 283 + }, 284 + { 285 + .name = "Greyscale 12 L/R (Y12I)", 286 + .guid = UVC_GUID_FORMAT_Y12I, 287 + .fcc = V4L2_PIX_FMT_Y12I, 288 + }, 289 + { 290 + .name = "Depth data 16-bit (Z16)", 291 + .guid = UVC_GUID_FORMAT_Z16, 292 + .fcc = V4L2_PIX_FMT_Z16, 293 + }, 294 + { 295 + .name = "Bayer 10-bit (SRGGB10P)", 296 + .guid = UVC_GUID_FORMAT_RW10, 297 + .fcc = V4L2_PIX_FMT_SRGGB10P, 298 + }, 299 + { 300 + .name = "Bayer 16-bit (SBGGR16)", 301 + .guid = UVC_GUID_FORMAT_BG16, 302 + .fcc = V4L2_PIX_FMT_SBGGR16, 303 + }, 304 + { 305 + .name = "Bayer 16-bit (SGBRG16)", 306 + .guid = UVC_GUID_FORMAT_GB16, 307 + .fcc = V4L2_PIX_FMT_SGBRG16, 308 + }, 309 + { 310 + .name = "Bayer 16-bit (SRGGB16)", 311 + .guid = UVC_GUID_FORMAT_RG16, 312 + .fcc = V4L2_PIX_FMT_SRGGB16, 313 + }, 314 + { 315 + .name = "Bayer 16-bit (SGRBG16)", 316 + .guid = UVC_GUID_FORMAT_GR16, 317 + .fcc = V4L2_PIX_FMT_SGRBG16, 318 + }, 319 + { 320 + .name = "Depth data 16-bit (Z16)", 321 + .guid = UVC_GUID_FORMAT_INVZ, 322 + .fcc = V4L2_PIX_FMT_Z16, 323 + }, 324 + { 325 + .name = "Greyscale 10-bit (Y10 )", 326 + .guid = UVC_GUID_FORMAT_INVI, 327 + .fcc = V4L2_PIX_FMT_Y10, 328 + }, 329 + { 330 + .name = "IR:Depth 26-bit (INZI)", 331 + .guid = UVC_GUID_FORMAT_INZI, 332 + .fcc = V4L2_PIX_FMT_INZI, 333 + }, 334 + { 335 + .name = "4-bit Depth Confidence (Packed)", 336 + .guid = UVC_GUID_FORMAT_CNF4, 337 + .fcc = V4L2_PIX_FMT_CNF4, 338 + }, 339 + { 340 + .name = "HEVC", 341 + .guid = UVC_GUID_FORMAT_HEVC, 342 + .fcc = V4L2_PIX_FMT_HEVC, 343 + }, 344 + }; 345 + 346 + static inline struct uvc_format_desc *uvc_format_by_guid(const u8 guid[16]) 347 + { 348 + unsigned int len = ARRAY_SIZE(uvc_fmts); 349 + unsigned int i; 350 + 351 + for (i = 0; i < len; ++i) { 352 + if (memcmp(guid, uvc_fmts[i].guid, 16) == 0) 353 + return &uvc_fmts[i]; 354 + } 355 + 356 + return NULL; 357 + } 358 + 359 + #endif /* __LINUX_V4L2_UVC_H */
+26
include/uapi/linux/usbip.h
··· 24 24 VDEV_ST_USED, 25 25 VDEV_ST_ERROR 26 26 }; 27 + 28 + /* USB URB Transfer flags: 29 + * 30 + * USBIP server and client (vchi) pack URBs in TCP packets. The following 31 + * are the transfer type defines used in USBIP protocol. 32 + */ 33 + 34 + #define USBIP_URB_SHORT_NOT_OK 0x0001 35 + #define USBIP_URB_ISO_ASAP 0x0002 36 + #define USBIP_URB_NO_TRANSFER_DMA_MAP 0x0004 37 + #define USBIP_URB_ZERO_PACKET 0x0040 38 + #define USBIP_URB_NO_INTERRUPT 0x0080 39 + #define USBIP_URB_FREE_BUFFER 0x0100 40 + #define USBIP_URB_DIR_IN 0x0200 41 + #define USBIP_URB_DIR_OUT 0 42 + #define USBIP_URB_DIR_MASK USBIP_URB_DIR_IN 43 + 44 + #define USBIP_URB_DMA_MAP_SINGLE 0x00010000 45 + #define USBIP_URB_DMA_MAP_PAGE 0x00020000 46 + #define USBIP_URB_DMA_MAP_SG 0x00040000 47 + #define USBIP_URB_MAP_LOCAL 0x00080000 48 + #define USBIP_URB_SETUP_MAP_SINGLE 0x00100000 49 + #define USBIP_URB_SETUP_MAP_LOCAL 0x00200000 50 + #define USBIP_URB_DMA_SG_COMBINED 0x00400000 51 + #define USBIP_URB_ALIGNED_TEMP_BUFFER 0x00800000 52 + 27 53 #endif /* _UAPI_LINUX_USBIP_H */