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

Merge tag 'usb-6.0-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 Thunderbolt and USB changes for 6.0-rc1.

Lots of little things here, nothing major, just constant development
on some new hardware support and cleanups of older drivers. Highlights
are:

- lots of typec changes and improvements for new hardware

- new gadget controller driver

- thunderbolt support for new hardware

- the normal set of new usb-serial device ids and cleanups

- loads of dwc3 controller fixes and improvements

- mtu3 driver updates

- testusb fixes for longtime issues (not many people use this tool it
seems.)

- minor driver fixes and improvements over the USB tree

- chromeos platform driver changes were added and then reverted as
they depened on some typec changes, but the cross-tree merges
caused problems so they will come back later through the platform
tree.

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

* tag 'usb-6.0-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb: (193 commits)
usb: misc: onboard_usb_hub: Remove duplicated power_on delay
usb: misc: onboard_usb_hub: Add TI USB8041 hub support
usb: misc: onboard_usb_hub: Add reset-gpio support
USB: usbsevseg: convert sysfs snprintf to sysfs_emit
dt-bindings: usb: Add binding for TI USB8041 hub controller
ARM: multi_v7_defconfig: enable USB onboard HUB driver
ARM: dts: stm32: add support for USB2514B onboard hub on stm32mp15xx-dkx
usb: misc: onboard-hub: add support for Microchip USB2514B USB 2.0 hub
dt-bindings: usb: generic-ehci: allow usb-hcd schema properties
usb: typec: ucsi: stm32g0: add bootloader support
usb: typec: ucsi: stm32g0: add support for stm32g0 controller
dt-bindings: usb: typec: add bindings for stm32g0 controller
usb: typec: ucsi: Acknowledge the GET_ERROR_STATUS command completion
usb: cdns3: change place of 'priv_ep' assignment in cdns3_gadget_ep_dequeue(), cdns3_gadget_ep_enable()
usb/chipidea: fix repeated words in comments
usb: renesas-xhci: Do not print any log while fw verif success
usb: typec: retimer: Add missing id check in match callback
USB: xhci: Fix comment typo
usb/typec/tcpm: fix repeated words in comments
usb/musb: fix repeated words in comments
...

+8399 -695
+8 -2
Documentation/ABI/testing/configfs-usb-gadget-mass-storage
··· 19 19 Description: 20 20 The attributes: 21 21 22 - =========== ============================================== 22 + ============ ============================================== 23 23 file The path to the backing file for the LUN. 24 24 Required if LUN is not marked as removable. 25 25 ro Flag specifying access to the LUN shall be ··· 32 32 being a CD-ROM. 33 33 nofua Flag specifying that FUA flag 34 34 in SCSI WRITE(10,12) 35 - =========== ============================================== 35 + forced_eject This write-only file is useful only when 36 + the function is active. It causes the backing 37 + file to be forcibly detached from the LUN, 38 + regardless of whether the host has allowed it. 39 + Any non-zero number of bytes written will 40 + result in ejection. 41 + ============ ==============================================
+8
Documentation/ABI/testing/sysfs-bus-platform-onboard-usb-hub
··· 1 + What: /sys/bus/platform/devices/<dev>/always_powered_in_suspend 2 + Date: June 2022 3 + KernelVersion: 5.20 4 + Contact: Matthias Kaehlcke <matthias@kaehlcke.net> 5 + linux-usb@vger.kernel.org 6 + Description: 7 + (RW) Controls whether the USB hub remains always powered 8 + during system suspend or not.
+11
Documentation/ABI/testing/sysfs-bus-usb
··· 253 253 only if the system firmware is capable of describing the 254 254 connection between a port and its connector. 255 255 256 + What: /sys/bus/usb/devices/.../<hub_interface>/port<X>/disable 257 + Date: June 2022 258 + Contact: Michael Grzeschik <m.grzeschik@pengutronix.de> 259 + Description: 260 + This file controls the state of a USB port, including 261 + Vbus power output (but only on hubs that support 262 + power switching -- most hubs don't support it). If 263 + a port is disabled, the port is unusable: Devices 264 + attached to the port will not be detected, initialized, 265 + or enumerated. 266 + 256 267 What: /sys/bus/usb/devices/.../power/usb2_lpm_l1_timeout 257 268 Date: May 2013 258 269 Contact: Mathias Nyman <mathias.nyman@linux.intel.com>
+8
Documentation/ABI/testing/sysfs-class-typec
··· 141 141 - "reverse": CC2 orientation 142 142 - "unknown": Orientation cannot be determined. 143 143 144 + What: /sys/class/typec/<port>/select_usb_power_delivery 145 + Date: May 2022 146 + Contact: Heikki Krogerus <heikki.krogerus@linux.intel.com> 147 + Description: 148 + Lists the USB Power Delivery Capabilities that the port can 149 + advertise to the partner. The currently used capabilities are in 150 + brackets. Selection happens by writing to the file. 151 + 144 152 USB Type-C partner devices (eg. /sys/class/typec/port0-partner/) 145 153 146 154 What: /sys/class/typec/<port>-partner/accessory_mode
+240
Documentation/ABI/testing/sysfs-class-usb_power_delivery
··· 1 + What: /sys/class/usb_power_delivery 2 + Date: May 2022 3 + Contact: Heikki Krogerus <heikki.krogerus@linux.intel.com> 4 + Description: 5 + Directory for USB Power Delivery devices. 6 + 7 + What: /sys/class/usb_power_delivery/.../revision 8 + Date: May 2022 9 + Contact: Heikki Krogerus <heikki.krogerus@linux.intel.com> 10 + Description: 11 + File showing the USB Power Delivery Specification Revision used 12 + in communication. 13 + 14 + What: /sys/class/usb_power_delivery/.../version 15 + Date: May 2022 16 + Contact: Heikki Krogerus <heikki.krogerus@linux.intel.com> 17 + Description: 18 + This is an optional attribute file showing the version of the 19 + specific revision of the USB Power Delivery Specification. In 20 + most cases the specification version is not known and the file 21 + is not available. 22 + 23 + What: /sys/class/usb_power_delivery/.../source-capabilities 24 + Date: May 2022 25 + Contact: Heikki Krogerus <heikki.krogerus@linux.intel.com> 26 + Description: 27 + The source capabilities message "Source_Capabilities" contains a 28 + set of Power Data Objects (PDO), each representing a type of 29 + power supply. The order of the PDO objects is defined in the USB 30 + Power Delivery Specification. Each PDO - power supply - will 31 + have its own device, and the PDO device name will start with the 32 + object position number as the first character followed by the 33 + power supply type name (":" as delimiter). 34 + 35 + /sys/class/usb_power_delivery/.../source_capabilities/<position>:<type> 36 + 37 + What: /sys/class/usb_power_delivery/.../sink-capabilities 38 + Date: May 2022 39 + Contact: Heikki Krogerus <heikki.krogerus@linux.intel.com> 40 + Description: 41 + The sink capability message "Sink_Capabilities" contains a set 42 + of Power Data Objects (PDO) just like with source capabilities, 43 + but instead of describing the power capabilities, these objects 44 + describe the power requirements. 45 + 46 + The order of the objects in the sink capability message is the 47 + same as with the source capabilities message. 48 + 49 + Fixed Supplies 50 + 51 + What: /sys/class/usb_power_delivery/.../<capability>/<position>:fixed_supply 52 + Date: May 2022 53 + Contact: Heikki Krogerus <heikki.krogerus@linux.intel.com> 54 + Description: 55 + Devices containing the attributes (the bit fields) defined for 56 + Fixed Supplies. 57 + 58 + The device "1:fixed_supply" is special. USB Power Delivery 59 + Specification dictates that the first PDO (at object position 60 + 1), and the only mandatory PDO, is always the vSafe5V Fixed 61 + Supply Object. vSafe5V Object has additional fields defined for 62 + it that the other Fixed Supply Objects do not have and that are 63 + related to the USB capabilities rather than power capabilities. 64 + 65 + What: /sys/class/usb_power_delivery/.../<capability>/1:fixed_supply/dual_role_power 66 + Date: May 2022 67 + Contact: Heikki Krogerus <heikki.krogerus@linux.intel.com> 68 + Description: 69 + This file contains boolean value that tells does the device 70 + support both source and sink power roles. 71 + 72 + What: /sys/class/usb_power_delivery/.../<capability>/1:fixed_supply/usb_suspend_supported 73 + Date: May 2022 74 + Contact: Heikki Krogerus <heikki.krogerus@linux.intel.com> 75 + Description: 76 + This file shows the value of the USB Suspend Supported bit in 77 + vSafe5V Fixed Supply Object. If the bit is set then the device 78 + will follow the USB 2.0 and USB 3.2 rules for suspend and 79 + resume. 80 + 81 + What: /sys/class/usb_power_delivery/.../<capability>/1:fixed_supply/unconstrained_power 82 + Date: May 2022 83 + Contact: Heikki Krogerus <heikki.krogerus@linux.intel.com> 84 + Description: 85 + This file shows the value of the Unconstrained Power bit in 86 + vSafe5V Fixed Supply Object. The bit is set when an external 87 + source of power, powerful enough to power the entire system on 88 + its own, is available for the device. 89 + 90 + What: /sys/class/usb_power_delivery/.../<capability>/1:fixed_supply/usb_communication_capable 91 + Date: May 2022 92 + Contact: Heikki Krogerus <heikki.krogerus@linux.intel.com> 93 + Description: 94 + This file shows the value of the USB Communication Capable bit in 95 + vSafe5V Fixed Supply Object. 96 + 97 + What: /sys/class/usb_power_delivery/.../<capability>/1:fixed_supply/dual_role_data 98 + Date: May 2022 99 + Contact: Heikki Krogerus <heikki.krogerus@linux.intel.com> 100 + Description: 101 + This file shows the value of the Dual-Role Data bit in vSafe5V 102 + Fixed Supply Object. Dual role data means ability act as both 103 + USB host and USB device. 104 + 105 + What: /sys/class/usb_power_delivery/.../<capability>/1:fixed_supply/unchunked_extended_messages_supported 106 + Date: May 2022 107 + Contact: Heikki Krogerus <heikki.krogerus@linux.intel.com> 108 + Description: 109 + This file shows the value of the Unchunked Extended Messages 110 + Supported bit in vSafe5V Fixed Supply Object. 111 + 112 + What: /sys/class/usb_power_delivery/.../<capability>/<position>:fixed_supply/voltage 113 + Date: May 2022 114 + Contact: Heikki Krogerus <heikki.krogerus@linux.intel.com> 115 + Description: 116 + The voltage the supply supports in millivolts. 117 + 118 + What: /sys/class/usb_power_delivery/.../source-capabilities/<position>:fixed_supply/maximum_current 119 + Date: May 2022 120 + Contact: Heikki Krogerus <heikki.krogerus@linux.intel.com> 121 + Description: 122 + Maximum current of the fixed source supply in milliamperes. 123 + 124 + What: /sys/class/usb_power_delivery/.../sink-capabilities/<position>:fixed_supply/operational_current 125 + Date: May 2022 126 + Contact: Heikki Krogerus <heikki.krogerus@linux.intel.com> 127 + Description: 128 + Operational current of the sink in milliamperes. 129 + 130 + What: /sys/class/usb_power_delivery/.../sink-capabilities/<position>:fixed_supply/fast_role_swap_current 131 + Date: May 2022 132 + Contact: Heikki Krogerus <heikki.krogerus@linux.intel.com> 133 + Description: 134 + This file contains the value of the "Fast Role Swap USB Type-C 135 + Current" field that tells the current level the sink requires 136 + after a Fast Role Swap. 137 + 0 - Fast Swap not supported" 138 + 1 - Default USB Power" 139 + 2 - 1.5A@5V" 140 + 3 - 3.0A@5V" 141 + 142 + Variable Supplies 143 + 144 + What: /sys/class/usb_power_delivery/.../<capability>/<position>:variable_supply 145 + Date: May 2022 146 + Contact: Heikki Krogerus <heikki.krogerus@linux.intel.com> 147 + Description: 148 + Variable Power Supply PDO. 149 + 150 + What: /sys/class/usb_power_delivery/.../<capability>/<position>:variable_supply/maximum_voltage 151 + Date: May 2022 152 + Contact: Heikki Krogerus <heikki.krogerus@linux.intel.com> 153 + Description: 154 + Maximum Voltage in millivolts. 155 + 156 + What: /sys/class/usb_power_delivery/.../<capability>/<position>:variable_supply/minimum_voltage 157 + Date: May 2022 158 + Contact: Heikki Krogerus <heikki.krogerus@linux.intel.com> 159 + Description: 160 + Minimum Voltage in millivolts. 161 + 162 + What: /sys/class/usb_power_delivery/.../source-capabilities/<position>:variable_supply/maximum_current 163 + Date: May 2022 164 + Contact: Heikki Krogerus <heikki.krogerus@linux.intel.com> 165 + Description: 166 + The maximum current in milliamperes that the source can supply 167 + at the given Voltage range. 168 + 169 + What: /sys/class/usb_power_delivery/.../sink-capabilities/<position>:variable_supply/operational_current 170 + Date: May 2022 171 + Contact: Heikki Krogerus <heikki.krogerus@linux.intel.com> 172 + Description: 173 + The operational current in milliamperes that the sink requires 174 + at the given Voltage range. 175 + 176 + Battery Supplies 177 + 178 + What: /sys/class/usb_power_delivery/.../<capability>/<position>:battery 179 + Date: May 2022 180 + Contact: Heikki Krogerus <heikki.krogerus@linux.intel.com> 181 + Description: 182 + Battery PDO. 183 + 184 + What: /sys/class/usb_power_delivery/.../<capability>/<position>:battery/maximum_voltage 185 + Date: May 2022 186 + Contact: Heikki Krogerus <heikki.krogerus@linux.intel.com> 187 + Description: 188 + Maximum Voltage in millivolts. 189 + 190 + What: /sys/class/usb_power_delivery/.../<capability>/<position>:battery/minimum_voltage 191 + Date: May 2022 192 + Contact: Heikki Krogerus <heikki.krogerus@linux.intel.com> 193 + Description: 194 + Minimum Voltage in millivolts. 195 + 196 + What: /sys/class/usb_power_delivery/.../source-capabilities/<position>:battery/maximum_power 197 + Date: May 2022 198 + Contact: Heikki Krogerus <heikki.krogerus@linux.intel.com> 199 + Description: 200 + Maximum allowable Power in milliwatts. 201 + 202 + What: /sys/class/usb_power_delivery/.../sink-capabilities/<position>:battery/operational_power 203 + Date: May 2022 204 + Contact: Heikki Krogerus <heikki.krogerus@linux.intel.com> 205 + Description: 206 + The operational power that the sink requires at the given 207 + voltage range. 208 + 209 + Standard Power Range (SPR) Programmable Power Supplies 210 + 211 + What: /sys/class/usb_power_delivery/.../<capability>/<position>:programmable_supply 212 + Date: May 2022 213 + Contact: Heikki Krogerus <heikki.krogerus@linux.intel.com> 214 + Description: 215 + Programmable Power Supply (PPS) Augmented PDO (APDO). 216 + 217 + What: /sys/class/usb_power_delivery/.../<capability>/<position>:programmable_supply/maximum_voltage 218 + Date: May 2022 219 + Contact: Heikki Krogerus <heikki.krogerus@linux.intel.com> 220 + Description: 221 + Maximum Voltage in millivolts. 222 + 223 + What: /sys/class/usb_power_delivery/.../<capability>/<position>:programmable_supply/minimum_voltage 224 + Date: May 2022 225 + Contact: Heikki Krogerus <heikki.krogerus@linux.intel.com> 226 + Description: 227 + Minimum Voltage in millivolts. 228 + 229 + What: /sys/class/usb_power_delivery/.../<capability>/<position>:programmable_supply/maximum_current 230 + Date: May 2022 231 + Contact: Heikki Krogerus <heikki.krogerus@linux.intel.com> 232 + Description: 233 + Maximum Current in milliamperes. 234 + 235 + What: /sys/class/usb_power_delivery/.../source-capabilities/<position>:programmable_supply/pps_power_limited 236 + Date: May 2022 237 + Contact: Heikki Krogerus <heikki.krogerus@linux.intel.com> 238 + Description: 239 + The PPS Power Limited bit indicates whether or not the source 240 + supply will exceed the rated output power if requested.
+81
Documentation/devicetree/bindings/usb/analogix,anx7411.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/analogix,anx7411.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Analogix ANX7411 Type-C controller bindings 8 + 9 + maintainers: 10 + - Xin Ji <xji@analogixsemi.com> 11 + 12 + properties: 13 + compatible: 14 + enum: 15 + - analogix,anx7411 16 + 17 + reg: 18 + maxItems: 1 19 + 20 + interrupts: 21 + maxItems: 1 22 + 23 + connector: 24 + type: object 25 + $ref: ../connector/usb-connector.yaml 26 + description: 27 + Properties for usb c connector. 28 + 29 + properties: 30 + compatible: 31 + const: usb-c-connector 32 + 33 + power-role: true 34 + 35 + data-role: true 36 + 37 + try-power-role: true 38 + 39 + required: 40 + - compatible 41 + 42 + required: 43 + - compatible 44 + - reg 45 + - connector 46 + 47 + additionalProperties: false 48 + 49 + examples: 50 + - | 51 + #include <dt-bindings/interrupt-controller/irq.h> 52 + i2c { 53 + #address-cells = <1>; 54 + #size-cells = <0>; 55 + 56 + typec@2c { 57 + compatible = "analogix,anx7411"; 58 + reg = <0x2c>; 59 + interrupts = <8 IRQ_TYPE_EDGE_FALLING>; 60 + interrupt-parent = <&gpio0>; 61 + 62 + typec_con: connector { 63 + compatible = "usb-c-connector"; 64 + power-role = "dual"; 65 + data-role = "dual"; 66 + try-power-role = "source"; 67 + 68 + ports { 69 + #address-cells = <1>; 70 + #size-cells = <0>; 71 + port@0 { 72 + reg = <0>; 73 + typec_con_ep: endpoint { 74 + remote-endpoint = <&usbotg_hs_ep>; 75 + }; 76 + }; 77 + }; 78 + }; 79 + }; 80 + }; 81 + ...
+52
Documentation/devicetree/bindings/usb/aspeed,ast2600-udc.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) 2 + # Copyright (c) 2020 Facebook Inc. 3 + %YAML 1.2 4 + --- 5 + $id: http://devicetree.org/schemas/usb/aspeed,ast2600-udc.yaml# 6 + $schema: http://devicetree.org/meta-schemas/core.yaml# 7 + 8 + title: ASPEED USB 2.0 Device Controller 9 + 10 + maintainers: 11 + - Neal Liu <neal_liu@aspeedtech.com> 12 + 13 + description: |+ 14 + The ASPEED USB 2.0 Device Controller implements 1 control endpoint and 15 + 4 generic endpoints for AST260x. 16 + 17 + Supports independent DMA channel for each generic endpoint. 18 + Supports 32/256 stages descriptor mode for all generic endpoints. 19 + 20 + properties: 21 + compatible: 22 + enum: 23 + - aspeed,ast2600-udc 24 + 25 + reg: 26 + maxItems: 1 27 + 28 + clocks: 29 + maxItems: 1 30 + 31 + interrupts: 32 + maxItems: 1 33 + 34 + required: 35 + - compatible 36 + - reg 37 + - clocks 38 + - interrupts 39 + 40 + additionalProperties: false 41 + 42 + examples: 43 + - | 44 + #include <dt-bindings/clock/aspeed-clock.h> 45 + udc: usb@1e6a2000 { 46 + compatible = "aspeed,ast2600-udc"; 47 + reg = <0x1e6a2000 0x300>; 48 + interrupts = <9>; 49 + clocks = <&syscon ASPEED_CLK_GATE_USBPORT2CLK>; 50 + pinctrl-names = "default"; 51 + pinctrl-0 = <&pinctrl_usb2bd_default>; 52 + };
+3
Documentation/devicetree/bindings/usb/dwc2.yaml
··· 11 11 12 12 allOf: 13 13 - $ref: usb-drd.yaml# 14 + - $ref: usb-hcd.yaml# 14 15 15 16 properties: 16 17 compatible: ··· 161 160 using the OF graph bindings specified, if the "usb-role-switch" 162 161 property is used. 163 162 $ref: /schemas/graph.yaml#/properties/port 163 + 164 + tpl-support: true 164 165 165 166 dependencies: 166 167 port: [ usb-role-switch ]
+1 -6
Documentation/devicetree/bindings/usb/generic-ehci.yaml
··· 131 131 Set this flag to indicate that the hardware sometimes turns on 132 132 the OC bit when an over-current isn't actually present. 133 133 134 - companion: 135 - $ref: /schemas/types.yaml#/definitions/phandle 136 - description: 137 - Phandle of a companion. 138 - 139 134 phys: 140 135 minItems: 1 141 136 maxItems: 3 ··· 151 156 - reg 152 157 - interrupts 153 158 154 - additionalProperties: false 159 + unevaluatedProperties: false 155 160 156 161 examples: 157 162 - |
+5
Documentation/devicetree/bindings/usb/mediatek,mtk-xhci.yaml
··· 31 31 - mediatek,mt8173-xhci 32 32 - mediatek,mt8183-xhci 33 33 - mediatek,mt8186-xhci 34 + - mediatek,mt8188-xhci 34 35 - mediatek,mt8192-xhci 35 36 - mediatek,mt8195-xhci 36 37 - const: mediatek,mtk-xhci ··· 58 57 - description: optional, wakeup interrupt used to support runtime PM 59 58 60 59 interrupt-names: 60 + minItems: 1 61 61 items: 62 62 - const: host 63 63 - const: wakeup ··· 114 112 115 113 vbus-supply: 116 114 description: Regulator of USB VBUS5v 115 + 116 + resets: 117 + maxItems: 1 117 118 118 119 usb3-lpm-capable: true 119 120
+3
Documentation/devicetree/bindings/usb/mediatek,mtu3.yaml
··· 107 107 maximum-speed: 108 108 enum: [super-speed-plus, super-speed, high-speed, full-speed] 109 109 110 + resets: 111 + maxItems: 1 112 + 110 113 "#address-cells": 111 114 enum: [1, 2] 112 115
+138 -14
Documentation/devicetree/bindings/usb/qcom,dwc3.yaml
··· 24 24 - qcom,qcs404-dwc3 25 25 - qcom,sc7180-dwc3 26 26 - qcom,sc7280-dwc3 27 + - qcom,sc8280xp-dwc3 27 28 - qcom,sdm660-dwc3 28 29 - qcom,sdm845-dwc3 29 30 - qcom,sdx55-dwc3 ··· 67 66 - mock_utmi:: Mock utmi clock needed for ITP/SOF generation in host 68 67 mode. Its frequency should be 19.2MHz. 69 68 minItems: 1 70 - maxItems: 6 69 + maxItems: 9 71 70 72 71 clock-names: 73 72 minItems: 1 74 - maxItems: 6 73 + maxItems: 9 75 74 76 75 assigned-clocks: 77 76 items: ··· 94 93 - const: apps-usb 95 94 96 95 interrupts: 97 - items: 98 - - description: The interrupt that is asserted 99 - when a wakeup event is received on USB2 bus. 100 - - description: The interrupt that is asserted 101 - when a wakeup event is received on USB3 bus. 102 - - description: Wakeup event on DM line. 103 - - description: Wakeup event on DP line. 96 + minItems: 1 97 + maxItems: 4 104 98 105 99 interrupt-names: 106 - items: 107 - - const: hs_phy_irq 108 - - const: ss_phy_irq 109 - - const: dm_hs_phy_irq 110 - - const: dp_hs_phy_irq 100 + minItems: 1 101 + maxItems: 4 111 102 112 103 qcom,select-utmi-as-pipe-clk: 113 104 description: ··· 247 254 compatible: 248 255 contains: 249 256 enum: 257 + - qcom,sc8280xp-dwc3 258 + then: 259 + properties: 260 + clocks: 261 + maxItems: 9 262 + clock-names: 263 + items: 264 + - const: cfg_noc 265 + - const: core 266 + - const: iface 267 + - const: sleep 268 + - const: mock_utmi 269 + - const: noc_aggr 270 + - const: noc_aggr_north 271 + - const: noc_aggr_south 272 + - const: noc_sys 273 + 274 + - if: 275 + properties: 276 + compatible: 277 + contains: 278 + enum: 250 279 - qcom,sdm660-dwc3 251 280 then: 252 281 properties: ··· 326 311 - const: mock_utmi 327 312 - const: xo 328 313 314 + - if: 315 + properties: 316 + compatible: 317 + contains: 318 + enum: 319 + - qcom,ipq4019-dwc3 320 + - qcom,ipq6018-dwc3 321 + - qcom,ipq8064-dwc3 322 + - qcom,ipq8074-dwc3 323 + - qcom,msm8994-dwc3 324 + - qcom,qcs404-dwc3 325 + - qcom,sc7180-dwc3 326 + - qcom,sdm845-dwc3 327 + - qcom,sdx55-dwc3 328 + - qcom,sdx65-dwc3 329 + - qcom,sm4250-dwc3 330 + - qcom,sm6115-dwc3 331 + - qcom,sm6125-dwc3 332 + - qcom,sm6350-dwc3 333 + - qcom,sm8150-dwc3 334 + - qcom,sm8250-dwc3 335 + - qcom,sm8350-dwc3 336 + - qcom,sm8450-dwc3 337 + then: 338 + properties: 339 + interrupts: 340 + items: 341 + - description: The interrupt that is asserted 342 + when a wakeup event is received on USB2 bus. 343 + - description: The interrupt that is asserted 344 + when a wakeup event is received on USB3 bus. 345 + - description: Wakeup event on DM line. 346 + - description: Wakeup event on DP line. 347 + interrupt-names: 348 + items: 349 + - const: hs_phy_irq 350 + - const: ss_phy_irq 351 + - const: dm_hs_phy_irq 352 + - const: dp_hs_phy_irq 353 + 354 + - if: 355 + properties: 356 + compatible: 357 + contains: 358 + enum: 359 + - qcom,msm8953-dwc3 360 + - qcom,msm8996-dwc3 361 + - qcom,msm8998-dwc3 362 + then: 363 + properties: 364 + interrupts: 365 + maxItems: 2 366 + interrupt-names: 367 + items: 368 + - const: hs_phy_irq 369 + - const: ss_phy_irq 370 + 371 + - if: 372 + properties: 373 + compatible: 374 + contains: 375 + enum: 376 + - qcom,sdm660-dwc3 377 + then: 378 + properties: 379 + interrupts: 380 + minItems: 1 381 + maxItems: 2 382 + interrupt-names: 383 + minItems: 1 384 + items: 385 + - const: hs_phy_irq 386 + - const: ss_phy_irq 387 + 388 + - if: 389 + properties: 390 + compatible: 391 + contains: 392 + enum: 393 + - qcom,sc7280-dwc3 394 + then: 395 + properties: 396 + interrupts: 397 + minItems: 3 398 + maxItems: 4 399 + interrupt-names: 400 + minItems: 3 401 + items: 402 + - const: hs_phy_irq 403 + - const: dp_hs_phy_irq 404 + - const: dm_hs_phy_irq 405 + - const: ss_phy_irq 406 + 407 + - if: 408 + properties: 409 + compatible: 410 + contains: 411 + enum: 412 + - qcom,sc8280xp-dwc3 413 + then: 414 + properties: 415 + interrupts: 416 + maxItems: 4 417 + interrupt-names: 418 + items: 419 + - const: pwr_event 420 + - const: dp_hs_phy_irq 421 + - const: dm_hs_phy_irq 422 + - const: ss_phy_irq 329 423 330 424 additionalProperties: false 331 425
+5 -5
Documentation/devicetree/bindings/usb/realtek,rts5411.yaml
··· 25 25 description: 26 26 phandle to the regulator that provides power to the hub. 27 27 28 - companion-hub: 28 + peer-hub: 29 29 $ref: '/schemas/types.yaml#/definitions/phandle' 30 30 description: 31 - phandle to the companion hub on the controller. 31 + phandle to the peer hub on the controller. 32 32 33 33 required: 34 - - companion-hub 34 + - peer-hub 35 35 - compatible 36 36 - reg 37 37 ··· 49 49 compatible = "usbbda,5411"; 50 50 reg = <1>; 51 51 vdd-supply = <&pp3300_hub>; 52 - companion-hub = <&hub_3_0>; 52 + peer-hub = <&hub_3_0>; 53 53 }; 54 54 55 55 /* 3.0 hub on port 2 */ ··· 57 57 compatible = "usbbda,411"; 58 58 reg = <2>; 59 59 vdd-supply = <&pp3300_hub>; 60 - companion-hub = <&hub_2_0>; 60 + peer-hub = <&hub_2_0>; 61 61 }; 62 62 };
+5
Documentation/devicetree/bindings/usb/snps,dwc3.yaml
··· 343 343 This port is used with the 'usb-role-switch' property to connect the 344 344 dwc3 to type C connector. 345 345 346 + wakeup-source: 347 + $ref: /schemas/types.yaml#/definitions/flag 348 + description: 349 + Enable USB remote wakeup. 350 + 346 351 unevaluatedProperties: false 347 352 348 353 required:
+91
Documentation/devicetree/bindings/usb/st,typec-stm32g0.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/usb/st,typec-stm32g0.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: STMicroelectronics STM32G0 USB Type-C PD controller 8 + 9 + description: | 10 + The STM32G0 MCU can be programmed to control Type-C connector(s) through I2C 11 + typically using the UCSI protocol over I2C, with a dedicated alert 12 + (interrupt) pin. 13 + 14 + maintainers: 15 + - Fabrice Gasnier <fabrice.gasnier@foss.st.com> 16 + 17 + properties: 18 + compatible: 19 + const: st,stm32g0-typec 20 + 21 + reg: 22 + maxItems: 1 23 + 24 + interrupts: 25 + maxItems: 1 26 + 27 + connector: 28 + type: object 29 + $ref: /schemas/connector/usb-connector.yaml# 30 + unevaluatedProperties: false 31 + 32 + firmware-name: 33 + description: | 34 + Should contain the name of the default firmware image 35 + file located on the firmware search path 36 + 37 + wakeup-source: true 38 + 39 + power-domains: 40 + maxItems: 1 41 + 42 + required: 43 + - compatible 44 + - reg 45 + - interrupts 46 + - connector 47 + 48 + additionalProperties: false 49 + 50 + examples: 51 + - | 52 + #include <dt-bindings/interrupt-controller/irq.h> 53 + i2c { 54 + #address-cells = <1>; 55 + #size-cells = <0>; 56 + 57 + typec@53 { 58 + compatible = "st,stm32g0-typec"; 59 + reg = <0x53>; 60 + /* Alert pin on GPIO PE12 */ 61 + interrupts = <12 IRQ_TYPE_EDGE_FALLING>; 62 + interrupt-parent = <&gpioe>; 63 + 64 + /* Example with one type-C connector */ 65 + connector { 66 + compatible = "usb-c-connector"; 67 + label = "USB-C"; 68 + 69 + ports { 70 + #address-cells = <1>; 71 + #size-cells = <0>; 72 + port@0 { 73 + reg = <0>; 74 + con_usb_c_ep: endpoint { 75 + remote-endpoint = <&usb_ep>; 76 + }; 77 + }; 78 + }; 79 + }; 80 + }; 81 + }; 82 + 83 + usb { 84 + usb-role-switch; 85 + port { 86 + usb_ep: endpoint { 87 + remote-endpoint = <&con_usb_c_ep>; 88 + }; 89 + }; 90 + }; 91 + ...
+67
Documentation/devicetree/bindings/usb/ti,usb8041.yaml
··· 1 + # SPDX-License-Identifier: GPL-2.0-only or BSD-2-Clause 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/usb/ti,usb8041.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Binding for the TI USB8041 USB 3.0 hub controller 8 + 9 + maintainers: 10 + - Alexander Stein <alexander.stein@ew.tq-group.com> 11 + 12 + allOf: 13 + - $ref: usb-device.yaml# 14 + 15 + properties: 16 + compatible: 17 + enum: 18 + - usb451,8140 19 + - usb451,8142 20 + 21 + reg: true 22 + 23 + reset-gpios: 24 + items: 25 + - description: GPIO specifier for GRST# pin. 26 + 27 + vdd-supply: 28 + description: 29 + VDD power supply to the hub 30 + 31 + peer-hub: 32 + $ref: /schemas/types.yaml#/definitions/phandle 33 + description: 34 + phandle to the peer hub on the controller. 35 + 36 + required: 37 + - compatible 38 + - reg 39 + - peer-hub 40 + 41 + additionalProperties: false 42 + 43 + examples: 44 + - | 45 + #include <dt-bindings/gpio/gpio.h> 46 + 47 + usb { 48 + dr_mode = "host"; 49 + #address-cells = <1>; 50 + #size-cells = <0>; 51 + 52 + /* 2.0 hub on port 1 */ 53 + hub_2_0: hub@1 { 54 + compatible = "usb451,8142"; 55 + reg = <1>; 56 + peer-hub = <&hub_3_0>; 57 + reset-gpios = <&gpio1 11 GPIO_ACTIVE_LOW>; 58 + }; 59 + 60 + /* 3.0 hub on port 2 */ 61 + hub_3_0: hub@2 { 62 + compatible = "usb451,8140"; 63 + reg = <2>; 64 + peer-hub = <&hub_2_0>; 65 + reset-gpios = <&gpio1 11 GPIO_ACTIVE_LOW>; 66 + }; 67 + };
+6
Documentation/usb/gadget-testing.rst
··· 333 333 being a CD-ROM. 334 334 nofua Flag specifying that FUA flag 335 335 in SCSI WRITE(10,12) 336 + forced_eject This write-only file is useful only when 337 + the function is active. It causes the backing 338 + file to be forcibly detached from the LUN, 339 + regardless of whether the host has allowed it. 340 + Any non-zero number of bytes written will 341 + result in ejection. 336 342 =============== ============================================== 337 343 338 344 Testing the MASS STORAGE function
+9
Documentation/usb/mass-storage.rst
··· 181 181 Reflects the state of nofua flag for given logical unit. It can 182 182 be read and written. 183 183 184 + - forced_eject 185 + 186 + When written into, it causes the backing file to be forcibly 187 + detached from the LUN, regardless of whether the host has allowed 188 + it. The content doesn't matter, any non-zero number of bytes 189 + written will result in ejection. 190 + 191 + Can not be read. 192 + 184 193 Other then those, as usual, the values of module parameters can be 185 194 read from /sys/module/g_mass_storage/parameters/* files. 186 195
+15
MAINTAINERS
··· 3179 3179 F: Documentation/devicetree/bindings/media/aspeed-video.txt 3180 3180 F: drivers/media/platform/aspeed/ 3181 3181 3182 + ASPEED USB UDC DRIVER 3183 + M: Neal Liu <neal_liu@aspeedtech.com> 3184 + L: linux-aspeed@lists.ozlabs.org (moderated for non-subscribers) 3185 + S: Maintained 3186 + F: Documentation/devicetree/bindings/usb/aspeed,ast2600-udc.yaml 3187 + F: drivers/usb/gadget/udc/aspeed_udc.c 3188 + 3182 3189 ASUS NOTEBOOKS AND EEEPC ACPI/WMI EXTRAS DRIVERS 3183 3190 M: Corentin Chary <corentin.chary@gmail.com> 3184 3191 L: acpi4asus-user@lists.sourceforge.net ··· 15073 15066 T: git git://linuxtv.org/media_tree.git 15074 15067 F: drivers/media/i2c/ov9734.c 15075 15068 15069 + ONBOARD USB HUB DRIVER 15070 + M: Matthias Kaehlcke <mka@chromium.org> 15071 + L: linux-usb@vger.kernel.org 15072 + S: Maintained 15073 + F: Documentation/ABI/testing/sysfs-bus-platform-onboard-usb-hub 15074 + F: drivers/usb/misc/onboard_usb_hub.c 15075 + 15076 15076 ONENAND FLASH DRIVER 15077 15077 M: Kyungmin Park <kyungmin.park@samsung.com> 15078 15078 L: linux-mtd@lists.infradead.org ··· 17472 17458 F: drivers/pci/controller/pcie-microchip-host.c 17473 17459 F: drivers/soc/microchip/ 17474 17460 F: drivers/spi/spi-microchip-core.c 17461 + F: drivers/usb/musb/mpfs.c 17475 17462 F: include/soc/microchip/mpfs.h 17476 17463 17477 17464 RNBD BLOCK DRIVERS
+8
arch/arm/boot/dts/stm32mp15xx-dkx.dtsi
··· 677 677 &usbh_ehci { 678 678 phys = <&usbphyc_port0>; 679 679 status = "okay"; 680 + #address-cells = <1>; 681 + #size-cells = <0>; 682 + /* onboard HUB */ 683 + hub@1 { 684 + compatible = "usb424,2514"; 685 + reg = <1>; 686 + vdd-supply = <&v3v3>; 687 + }; 680 688 }; 681 689 682 690 &usbotg_hs {
+1
arch/arm/configs/multi_v7_defconfig
··· 865 865 CONFIG_USB_CHIPIDEA_HOST=y 866 866 CONFIG_USB_ISP1760=y 867 867 CONFIG_USB_HSIC_USB3503=y 868 + CONFIG_USB_ONBOARD_HUB=m 868 869 CONFIG_AB8500_USB=y 869 870 CONFIG_KEYSTONE_USB_PHY=m 870 871 CONFIG_NOP_USB_XCEIV=y
+1 -1
arch/mips/configs/cavium_octeon_defconfig
··· 134 134 CONFIG_RTC_DRV_DS1307=y 135 135 CONFIG_STAGING=y 136 136 CONFIG_OCTEON_ETHERNET=y 137 - CONFIG_OCTEON_USB=y 137 + CONFIG_USB_OCTEON_HCD=y 138 138 # CONFIG_IOMMU_SUPPORT is not set 139 139 CONFIG_RAS=y 140 140 CONFIG_EXT4_FS=y
-2
drivers/staging/Kconfig
··· 42 42 43 43 source "drivers/staging/octeon/Kconfig" 44 44 45 - source "drivers/staging/octeon-usb/Kconfig" 46 - 47 45 source "drivers/staging/vt6655/Kconfig" 48 46 49 47 source "drivers/staging/vt6656/Kconfig"
-1
drivers/staging/Makefile
··· 11 11 obj-$(CONFIG_R8188EU) += r8188eu/ 12 12 obj-$(CONFIG_RTS5208) += rts5208/ 13 13 obj-$(CONFIG_OCTEON_ETHERNET) += octeon/ 14 - obj-$(CONFIG_OCTEON_USB) += octeon-usb/ 15 14 obj-$(CONFIG_VT6655) += vt6655/ 16 15 obj-$(CONFIG_VT6656) += vt6656/ 17 16 obj-$(CONFIG_VME_BUS) += vme_user/
-6
drivers/staging/gdm724x/gdm_tty.c
··· 17 17 #define GDM_TTY_MAJOR 0 18 18 #define GDM_TTY_MINOR 32 19 19 20 - #define ACM_CTRL_DTR 0x01 21 - #define ACM_CTRL_RTS 0x02 22 - #define ACM_CTRL_DSR 0x02 23 - #define ACM_CTRL_RI 0x08 24 - #define ACM_CTRL_DCD 0x01 25 - 26 20 #define WRITE_SIZE 2048 27 21 28 22 #define MUX_TX_MAX_SIZE 2048
-11
drivers/staging/octeon-usb/Kconfig
··· 1 - # SPDX-License-Identifier: GPL-2.0 2 - config OCTEON_USB 3 - tristate "Cavium Networks Octeon USB support" 4 - depends on CAVIUM_OCTEON_SOC && USB 5 - help 6 - This driver supports USB host controller on some Cavium 7 - Networks' products in the Octeon family. 8 - 9 - To compile this driver as a module, choose M here. The module 10 - will be called octeon-hcd. 11 -
-2
drivers/staging/octeon-usb/Makefile
··· 1 - # SPDX-License-Identifier: GPL-2.0 2 - obj-${CONFIG_OCTEON_USB} := octeon-hcd.o
-8
drivers/staging/octeon-usb/TODO
··· 1 - This driver is functional and has been tested on EdgeRouter Lite, 2 - D-Link DSR-1000N and EBH5600 evaluation board with USB mass storage. 3 - 4 - TODO: 5 - - kernel coding style 6 - - checkpatch warnings 7 - 8 - Contact: Aaro Koskinen <aaro.koskinen@iki.fi>
drivers/staging/octeon-usb/octeon-hcd.c drivers/usb/host/octeon-hcd.c
drivers/staging/octeon-usb/octeon-hcd.h drivers/usb/host/octeon-hcd.h
+3 -3
drivers/thunderbolt/ctl.c
··· 694 694 } 695 695 696 696 /** 697 - * tb_cfg_start() - start/resume the control channel 697 + * tb_ctl_start() - start/resume the control channel 698 698 * @ctl: Control channel to start 699 699 */ 700 700 void tb_ctl_start(struct tb_ctl *ctl) ··· 710 710 } 711 711 712 712 /** 713 - * tb_ctrl_stop() - pause the control channel 713 + * tb_ctl_stop() - pause the control channel 714 714 * @ctl: Control channel to stop 715 715 * 716 716 * All invocations of ctl->callback will have finished after this method ··· 912 912 } 913 913 914 914 /** 915 - * tb_cfg_write() - write from buffer into config space 915 + * tb_cfg_write_raw() - write from buffer into config space 916 916 * @ctl: Pointer to the control channel 917 917 * @buffer: Data to write 918 918 * @route: Route string of the router
+1 -1
drivers/thunderbolt/ctl.h
··· 35 35 * If err = 1 then this is the port that send the 36 36 * error. 37 37 * If err = 0 and if this was a cfg_read/write then 38 - * this is the the upstream port of the responding 38 + * this is the upstream port of the responding 39 39 * switch. 40 40 * Otherwise the field is set to zero. 41 41 */
+2
drivers/thunderbolt/icm.c
··· 2516 2516 case PCI_DEVICE_ID_INTEL_TGL_H_NHI1: 2517 2517 case PCI_DEVICE_ID_INTEL_ADL_NHI0: 2518 2518 case PCI_DEVICE_ID_INTEL_ADL_NHI1: 2519 + case PCI_DEVICE_ID_INTEL_RPL_NHI0: 2520 + case PCI_DEVICE_ID_INTEL_RPL_NHI1: 2519 2521 icm->is_supported = icm_tgl_is_supported; 2520 2522 icm->driver_ready = icm_icl_driver_ready; 2521 2523 icm->set_uuid = icm_icl_set_uuid;
+4
drivers/thunderbolt/nhi.c
··· 1410 1410 .driver_data = (kernel_ulong_t)&icl_nhi_ops }, 1411 1411 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_ADL_NHI1), 1412 1412 .driver_data = (kernel_ulong_t)&icl_nhi_ops }, 1413 + { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_RPL_NHI0), 1414 + .driver_data = (kernel_ulong_t)&icl_nhi_ops }, 1415 + { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_RPL_NHI1), 1416 + .driver_data = (kernel_ulong_t)&icl_nhi_ops }, 1413 1417 1414 1418 /* Any USB4 compliant host */ 1415 1419 { PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_USB4, ~0) },
+2
drivers/thunderbolt/nhi.h
··· 80 80 #define PCI_DEVICE_ID_INTEL_TGL_NHI1 0x9a1d 81 81 #define PCI_DEVICE_ID_INTEL_TGL_H_NHI0 0x9a1f 82 82 #define PCI_DEVICE_ID_INTEL_TGL_H_NHI1 0x9a21 83 + #define PCI_DEVICE_ID_INTEL_RPL_NHI0 0xa73e 84 + #define PCI_DEVICE_ID_INTEL_RPL_NHI1 0xa76d 83 85 84 86 #define PCI_CLASS_SERIAL_USB_USB4 0x0c0340 85 87
+48 -43
drivers/thunderbolt/switch.c
··· 3133 3133 /* 3134 3134 * Actually only needed for Titan Ridge but for simplicity can be 3135 3135 * done for USB4 device too as CLx is re-enabled at resume. 3136 + * CL0s and CL1 are enabled and supported together. 3136 3137 */ 3137 - if (tb_switch_disable_clx(sw, TB_CL0S)) 3138 - tb_sw_warn(sw, "failed to disable CLx on upstream port\n"); 3138 + if (tb_switch_is_clx_enabled(sw, TB_CL1)) { 3139 + if (tb_switch_disable_clx(sw, TB_CL1)) 3140 + tb_sw_warn(sw, "failed to disable %s on upstream port\n", 3141 + tb_switch_clx_name(TB_CL1)); 3142 + } 3139 3143 3140 3144 err = tb_plug_events_active(sw, false); 3141 3145 if (err) ··· 3430 3426 } 3431 3427 3432 3428 switch (clx) { 3433 - case TB_CL0S: 3434 - /* CL0s support requires also CL1 support */ 3429 + case TB_CL1: 3430 + /* CL0s and CL1 are enabled and supported together */ 3435 3431 mask = LANE_ADP_CS_0_CL0S_SUPPORT | LANE_ADP_CS_0_CL1_SUPPORT; 3436 3432 break; 3437 3433 3438 - /* For now we support only CL0s. Not CL1, CL2 */ 3439 - case TB_CL1: 3434 + /* For now we support only CL0s and CL1. Not CL2 */ 3440 3435 case TB_CL2: 3441 3436 default: 3442 3437 return false; ··· 3449 3446 return !!(val & mask); 3450 3447 } 3451 3448 3452 - static inline bool tb_port_cl0s_supported(struct tb_port *port) 3453 - { 3454 - return tb_port_clx_supported(port, TB_CL0S); 3455 - } 3456 - 3457 - static int __tb_port_cl0s_set(struct tb_port *port, bool enable) 3449 + static int __tb_port_clx_set(struct tb_port *port, enum tb_clx clx, bool enable) 3458 3450 { 3459 3451 u32 phy, mask; 3460 3452 int ret; 3461 3453 3462 - /* To enable CL0s also required to enable CL1 */ 3463 - mask = LANE_ADP_CS_1_CL0S_ENABLE | LANE_ADP_CS_1_CL1_ENABLE; 3454 + /* CL0s and CL1 are enabled and supported together */ 3455 + if (clx == TB_CL1) 3456 + mask = LANE_ADP_CS_1_CL0S_ENABLE | LANE_ADP_CS_1_CL1_ENABLE; 3457 + else 3458 + /* For now we support only CL0s and CL1. Not CL2 */ 3459 + return -EOPNOTSUPP; 3460 + 3464 3461 ret = tb_port_read(port, &phy, TB_CFG_PORT, 3465 3462 port->cap_phy + LANE_ADP_CS_1, 1); 3466 3463 if (ret) ··· 3475 3472 port->cap_phy + LANE_ADP_CS_1, 1); 3476 3473 } 3477 3474 3478 - static int tb_port_cl0s_disable(struct tb_port *port) 3475 + static int tb_port_clx_disable(struct tb_port *port, enum tb_clx clx) 3479 3476 { 3480 - return __tb_port_cl0s_set(port, false); 3477 + return __tb_port_clx_set(port, clx, false); 3481 3478 } 3482 3479 3483 - static int tb_port_cl0s_enable(struct tb_port *port) 3480 + static int tb_port_clx_enable(struct tb_port *port, enum tb_clx clx) 3484 3481 { 3485 - return __tb_port_cl0s_set(port, true); 3482 + return __tb_port_clx_set(port, clx, true); 3486 3483 } 3487 3484 3488 - static int tb_switch_enable_cl0s(struct tb_switch *sw) 3485 + static int __tb_switch_enable_clx(struct tb_switch *sw, enum tb_clx clx) 3489 3486 { 3490 3487 struct tb_switch *parent = tb_switch_parent(sw); 3491 - bool up_cl0s_support, down_cl0s_support; 3488 + bool up_clx_support, down_clx_support; 3492 3489 struct tb_port *up, *down; 3493 3490 int ret; 3494 3491 ··· 3513 3510 up = tb_upstream_port(sw); 3514 3511 down = tb_port_at(tb_route(sw), parent); 3515 3512 3516 - up_cl0s_support = tb_port_cl0s_supported(up); 3517 - down_cl0s_support = tb_port_cl0s_supported(down); 3513 + up_clx_support = tb_port_clx_supported(up, clx); 3514 + down_clx_support = tb_port_clx_supported(down, clx); 3518 3515 3519 - tb_port_dbg(up, "CL0s %ssupported\n", 3520 - up_cl0s_support ? "" : "not "); 3521 - tb_port_dbg(down, "CL0s %ssupported\n", 3522 - down_cl0s_support ? "" : "not "); 3516 + tb_port_dbg(up, "%s %ssupported\n", tb_switch_clx_name(clx), 3517 + up_clx_support ? "" : "not "); 3518 + tb_port_dbg(down, "%s %ssupported\n", tb_switch_clx_name(clx), 3519 + down_clx_support ? "" : "not "); 3523 3520 3524 - if (!up_cl0s_support || !down_cl0s_support) 3521 + if (!up_clx_support || !down_clx_support) 3525 3522 return -EOPNOTSUPP; 3526 3523 3527 - ret = tb_port_cl0s_enable(up); 3524 + ret = tb_port_clx_enable(up, clx); 3528 3525 if (ret) 3529 3526 return ret; 3530 3527 3531 - ret = tb_port_cl0s_enable(down); 3528 + ret = tb_port_clx_enable(down, clx); 3532 3529 if (ret) { 3533 - tb_port_cl0s_disable(up); 3530 + tb_port_clx_disable(up, clx); 3534 3531 return ret; 3535 3532 } 3536 3533 3537 3534 ret = tb_switch_mask_clx_objections(sw); 3538 3535 if (ret) { 3539 - tb_port_cl0s_disable(up); 3540 - tb_port_cl0s_disable(down); 3536 + tb_port_clx_disable(up, clx); 3537 + tb_port_clx_disable(down, clx); 3541 3538 return ret; 3542 3539 } 3543 3540 3544 - sw->clx = TB_CL0S; 3541 + sw->clx = clx; 3545 3542 3546 - tb_port_dbg(up, "CL0s enabled\n"); 3543 + tb_port_dbg(up, "%s enabled\n", tb_switch_clx_name(clx)); 3547 3544 return 0; 3548 3545 } 3549 3546 ··· 3557 3554 * to improve performance. CLx is enabled only if both sides of the link 3558 3555 * support CLx, and if both sides of the link are not configured as two 3559 3556 * single lane links and only if the link is not inter-domain link. The 3560 - * complete set of conditions is descibed in CM Guide 1.0 section 8.1. 3557 + * complete set of conditions is described in CM Guide 1.0 section 8.1. 3561 3558 * 3562 3559 * Return: Returns 0 on success or an error code on failure. 3563 3560 */ ··· 3576 3573 return 0; 3577 3574 3578 3575 switch (clx) { 3579 - case TB_CL0S: 3580 - return tb_switch_enable_cl0s(sw); 3576 + case TB_CL1: 3577 + /* CL0s and CL1 are enabled and supported together */ 3578 + return __tb_switch_enable_clx(sw, clx); 3581 3579 3582 3580 default: 3583 3581 return -EOPNOTSUPP; 3584 3582 } 3585 3583 } 3586 3584 3587 - static int tb_switch_disable_cl0s(struct tb_switch *sw) 3585 + static int __tb_switch_disable_clx(struct tb_switch *sw, enum tb_clx clx) 3588 3586 { 3589 3587 struct tb_switch *parent = tb_switch_parent(sw); 3590 3588 struct tb_port *up, *down; ··· 3607 3603 3608 3604 up = tb_upstream_port(sw); 3609 3605 down = tb_port_at(tb_route(sw), parent); 3610 - ret = tb_port_cl0s_disable(up); 3606 + ret = tb_port_clx_disable(up, clx); 3611 3607 if (ret) 3612 3608 return ret; 3613 3609 3614 - ret = tb_port_cl0s_disable(down); 3610 + ret = tb_port_clx_disable(down, clx); 3615 3611 if (ret) 3616 3612 return ret; 3617 3613 3618 3614 sw->clx = TB_CLX_DISABLE; 3619 3615 3620 - tb_port_dbg(up, "CL0s disabled\n"); 3616 + tb_port_dbg(up, "%s disabled\n", tb_switch_clx_name(clx)); 3621 3617 return 0; 3622 3618 } 3623 3619 ··· 3634 3630 return 0; 3635 3631 3636 3632 switch (clx) { 3637 - case TB_CL0S: 3638 - return tb_switch_disable_cl0s(sw); 3633 + case TB_CL1: 3634 + /* CL0s and CL1 are enabled and supported together */ 3635 + return __tb_switch_disable_clx(sw, clx); 3639 3636 3640 3637 default: 3641 3638 return -EOPNOTSUPP;
+56 -12
drivers/thunderbolt/tb.c
··· 118 118 switch (port->config.type) { 119 119 case TB_TYPE_DP_HDMI_IN: 120 120 tunnel = tb_tunnel_discover_dp(tb, port, alloc_hopids); 121 + /* 122 + * In case of DP tunnel exists, change host router's 123 + * 1st children TMU mode to HiFi for CL0s to work. 124 + */ 125 + if (tunnel) 126 + tb_switch_enable_tmu_1st_child(tb->root_switch, 127 + TB_SWITCH_TMU_RATE_HIFI); 121 128 break; 122 129 123 130 case TB_TYPE_PCIE_DOWN: ··· 222 215 int ret; 223 216 224 217 /* If it is already enabled in correct mode, don't touch it */ 225 - if (tb_switch_tmu_hifi_is_enabled(sw, sw->tmu.unidirectional_request)) 218 + if (tb_switch_tmu_is_enabled(sw, sw->tmu.unidirectional_request)) 226 219 return 0; 227 220 228 221 ret = tb_switch_tmu_disable(sw); ··· 582 575 struct tb_cm *tcm = tb_priv(port->sw->tb); 583 576 struct tb_port *upstream_port; 584 577 struct tb_switch *sw; 578 + int ret; 585 579 586 580 if (tb_is_upstream_port(port)) 587 581 return; ··· 671 663 tb_switch_lane_bonding_enable(sw); 672 664 /* Set the link configured */ 673 665 tb_switch_configure_link(sw); 674 - if (tb_switch_enable_clx(sw, TB_CL0S)) 675 - tb_sw_warn(sw, "failed to enable CLx on upstream port\n"); 666 + /* 667 + * CL0s and CL1 are enabled and supported together. 668 + * Silently ignore CLx enabling in case CLx is not supported. 669 + */ 670 + ret = tb_switch_enable_clx(sw, TB_CL1); 671 + if (ret && ret != -EOPNOTSUPP) 672 + tb_sw_warn(sw, "failed to enable %s on upstream port\n", 673 + tb_switch_clx_name(TB_CL1)); 676 674 677 - tb_switch_tmu_configure(sw, TB_SWITCH_TMU_RATE_HIFI, 678 - tb_switch_is_clx_enabled(sw)); 675 + if (tb_switch_is_clx_enabled(sw, TB_CL1)) 676 + /* 677 + * To support highest CLx state, we set router's TMU to 678 + * Normal-Uni mode. 679 + */ 680 + tb_switch_tmu_configure(sw, TB_SWITCH_TMU_RATE_NORMAL, true); 681 + else 682 + /* If CLx disabled, configure router's TMU to HiFi-Bidir mode*/ 683 + tb_switch_tmu_configure(sw, TB_SWITCH_TMU_RATE_HIFI, false); 679 684 680 685 if (tb_enable_tmu(sw)) 681 686 tb_sw_warn(sw, "failed to enable TMU\n"); ··· 986 965 987 966 list_add_tail(&tunnel->list, &tcm->tunnel_list); 988 967 tb_reclaim_usb3_bandwidth(tb, in, out); 968 + /* 969 + * In case of DP tunnel exists, change host router's 1st children 970 + * TMU mode to HiFi for CL0s to work. 971 + */ 972 + tb_switch_enable_tmu_1st_child(tb->root_switch, TB_SWITCH_TMU_RATE_HIFI); 973 + 989 974 return; 990 975 991 976 err_free: ··· 1434 1407 return ret; 1435 1408 } 1436 1409 1437 - tb_switch_tmu_configure(tb->root_switch, TB_SWITCH_TMU_RATE_HIFI, false); 1410 + /* 1411 + * To support highest CLx state, we set host router's TMU to 1412 + * Normal mode. 1413 + */ 1414 + tb_switch_tmu_configure(tb->root_switch, TB_SWITCH_TMU_RATE_NORMAL, 1415 + false); 1438 1416 /* Enable TMU if it is off */ 1439 1417 tb_switch_tmu_enable(tb->root_switch); 1440 1418 /* Full scan to discover devices added before the driver was loaded. */ ··· 1478 1446 static void tb_restore_children(struct tb_switch *sw) 1479 1447 { 1480 1448 struct tb_port *port; 1449 + int ret; 1481 1450 1482 1451 /* No need to restore if the router is already unplugged */ 1483 1452 if (sw->is_unplugged) 1484 1453 return; 1485 1454 1486 - if (tb_switch_enable_clx(sw, TB_CL0S)) 1487 - tb_sw_warn(sw, "failed to re-enable CLx on upstream port\n"); 1488 - 1489 1455 /* 1490 - * tb_switch_tmu_configure() was already called when the switch was 1491 - * added before entering system sleep or runtime suspend, 1492 - * so no need to call it again before enabling TMU. 1456 + * CL0s and CL1 are enabled and supported together. 1457 + * Silently ignore CLx re-enabling in case CLx is not supported. 1493 1458 */ 1459 + ret = tb_switch_enable_clx(sw, TB_CL1); 1460 + if (ret && ret != -EOPNOTSUPP) 1461 + tb_sw_warn(sw, "failed to re-enable %s on upstream port\n", 1462 + tb_switch_clx_name(TB_CL1)); 1463 + 1464 + if (tb_switch_is_clx_enabled(sw, TB_CL1)) 1465 + /* 1466 + * To support highest CLx state, we set router's TMU to 1467 + * Normal-Uni mode. 1468 + */ 1469 + tb_switch_tmu_configure(sw, TB_SWITCH_TMU_RATE_NORMAL, true); 1470 + else 1471 + /* If CLx disabled, configure router's TMU to HiFi-Bidir mode*/ 1472 + tb_switch_tmu_configure(sw, TB_SWITCH_TMU_RATE_HIFI, false); 1473 + 1494 1474 if (tb_enable_tmu(sw)) 1495 1475 tb_sw_warn(sw, "failed to restore TMU configuration\n"); 1496 1476
+26 -22
drivers/thunderbolt/tb.h
··· 13 13 #include <linux/pci.h> 14 14 #include <linux/thunderbolt.h> 15 15 #include <linux/uuid.h> 16 + #include <linux/bitfield.h> 16 17 17 18 #include "tb_regs.h" 18 19 #include "ctl.h" ··· 112 111 113 112 enum tb_clx { 114 113 TB_CLX_DISABLE, 115 - TB_CL0S, 114 + /* CL0s and CL1 are enabled and supported together */ 116 115 TB_CL1, 117 116 TB_CL2, 118 117 }; ··· 934 933 void tb_switch_tmu_configure(struct tb_switch *sw, 935 934 enum tb_switch_tmu_rate rate, 936 935 bool unidirectional); 936 + void tb_switch_enable_tmu_1st_child(struct tb_switch *sw, 937 + enum tb_switch_tmu_rate rate); 937 938 /** 938 - * tb_switch_tmu_hifi_is_enabled() - Checks if the specified TMU mode is enabled 939 + * tb_switch_tmu_is_enabled() - Checks if the specified TMU mode is enabled 939 940 * @sw: Router whose TMU mode to check 940 941 * @unidirectional: If uni-directional (bi-directional otherwise) 941 942 * 942 943 * Return true if hardware TMU configuration matches the one passed in 943 - * as parameter. That is HiFi and either uni-directional or bi-directional. 944 + * as parameter. That is HiFi/Normal and either uni-directional or bi-directional. 944 945 */ 945 - static inline bool tb_switch_tmu_hifi_is_enabled(const struct tb_switch *sw, 946 - bool unidirectional) 946 + static inline bool tb_switch_tmu_is_enabled(const struct tb_switch *sw, 947 + bool unidirectional) 947 948 { 948 - return sw->tmu.rate == TB_SWITCH_TMU_RATE_HIFI && 949 + return sw->tmu.rate == sw->tmu.rate_request && 949 950 sw->tmu.unidirectional == unidirectional; 951 + } 952 + 953 + static inline const char *tb_switch_clx_name(enum tb_clx clx) 954 + { 955 + switch (clx) { 956 + /* CL0s and CL1 are enabled and supported together */ 957 + case TB_CL1: 958 + return "CL0s/CL1"; 959 + default: 960 + return "unknown"; 961 + } 950 962 } 951 963 952 964 int tb_switch_enable_clx(struct tb_switch *sw, enum tb_clx clx); ··· 967 953 968 954 /** 969 955 * tb_switch_is_clx_enabled() - Checks if the CLx is enabled 970 - * @sw: Router to check the CLx state for 956 + * @sw: Router to check for the CLx 957 + * @clx: The CLx state to check for 971 958 * 972 - * Checks if the CLx is enabled on the router upstream link. 959 + * Checks if the specified CLx is enabled on the router upstream link. 973 960 * Not applicable for a host router. 974 961 */ 975 - static inline bool tb_switch_is_clx_enabled(const struct tb_switch *sw) 962 + static inline bool tb_switch_is_clx_enabled(const struct tb_switch *sw, 963 + enum tb_clx clx) 976 964 { 977 - return sw->clx != TB_CLX_DISABLE; 978 - } 979 - 980 - /** 981 - * tb_switch_is_cl0s_enabled() - Checks if the CL0s is enabled 982 - * @sw: Router to check for the CL0s 983 - * 984 - * Checks if the CL0s is enabled on the router upstream link. 985 - * Not applicable for a host router. 986 - */ 987 - static inline bool tb_switch_is_cl0s_enabled(const struct tb_switch *sw) 988 - { 989 - return sw->clx == TB_CL0S; 965 + return sw->clx == clx; 990 966 } 991 967 992 968 /**
+6
drivers/thunderbolt/tb_regs.h
··· 234 234 235 235 /* Router TMU configuration */ 236 236 #define TMU_RTR_CS_0 0x00 237 + #define TMU_RTR_CS_0_FREQ_WIND_MASK GENMASK(26, 16) 237 238 #define TMU_RTR_CS_0_TD BIT(27) 238 239 #define TMU_RTR_CS_0_UCAP BIT(30) 239 240 #define TMU_RTR_CS_1 0x01 ··· 245 244 #define TMU_RTR_CS_3_LOCAL_TIME_NS_MASK GENMASK(15, 0) 246 245 #define TMU_RTR_CS_3_TS_PACKET_INTERVAL_MASK GENMASK(31, 16) 247 246 #define TMU_RTR_CS_3_TS_PACKET_INTERVAL_SHIFT 16 247 + #define TMU_RTR_CS_15 0xf 248 + #define TMU_RTR_CS_15_FREQ_AVG_MASK GENMASK(5, 0) 249 + #define TMU_RTR_CS_15_DELAY_AVG_MASK GENMASK(11, 6) 250 + #define TMU_RTR_CS_15_OFFSET_AVG_MASK GENMASK(17, 12) 251 + #define TMU_RTR_CS_15_ERROR_AVG_MASK GENMASK(23, 18) 248 252 #define TMU_RTR_CS_22 0x16 249 253 #define TMU_RTR_CS_24 0x18 250 254 #define TMU_RTR_CS_25 0x19
+187 -34
drivers/thunderbolt/tmu.c
··· 11 11 12 12 #include "tb.h" 13 13 14 + static int tb_switch_set_tmu_mode_params(struct tb_switch *sw, 15 + enum tb_switch_tmu_rate rate) 16 + { 17 + u32 freq_meas_wind[2] = { 30, 800 }; 18 + u32 avg_const[2] = { 4, 8 }; 19 + u32 freq, avg, val; 20 + int ret; 21 + 22 + if (rate == TB_SWITCH_TMU_RATE_NORMAL) { 23 + freq = freq_meas_wind[0]; 24 + avg = avg_const[0]; 25 + } else if (rate == TB_SWITCH_TMU_RATE_HIFI) { 26 + freq = freq_meas_wind[1]; 27 + avg = avg_const[1]; 28 + } else { 29 + return 0; 30 + } 31 + 32 + ret = tb_sw_read(sw, &val, TB_CFG_SWITCH, 33 + sw->tmu.cap + TMU_RTR_CS_0, 1); 34 + if (ret) 35 + return ret; 36 + 37 + val &= ~TMU_RTR_CS_0_FREQ_WIND_MASK; 38 + val |= FIELD_PREP(TMU_RTR_CS_0_FREQ_WIND_MASK, freq); 39 + 40 + ret = tb_sw_write(sw, &val, TB_CFG_SWITCH, 41 + sw->tmu.cap + TMU_RTR_CS_0, 1); 42 + if (ret) 43 + return ret; 44 + 45 + ret = tb_sw_read(sw, &val, TB_CFG_SWITCH, 46 + sw->tmu.cap + TMU_RTR_CS_15, 1); 47 + if (ret) 48 + return ret; 49 + 50 + val &= ~TMU_RTR_CS_15_FREQ_AVG_MASK & 51 + ~TMU_RTR_CS_15_DELAY_AVG_MASK & 52 + ~TMU_RTR_CS_15_OFFSET_AVG_MASK & 53 + ~TMU_RTR_CS_15_ERROR_AVG_MASK; 54 + val |= FIELD_PREP(TMU_RTR_CS_15_FREQ_AVG_MASK, avg) | 55 + FIELD_PREP(TMU_RTR_CS_15_DELAY_AVG_MASK, avg) | 56 + FIELD_PREP(TMU_RTR_CS_15_OFFSET_AVG_MASK, avg) | 57 + FIELD_PREP(TMU_RTR_CS_15_ERROR_AVG_MASK, avg); 58 + 59 + return tb_sw_write(sw, &val, TB_CFG_SWITCH, 60 + sw->tmu.cap + TMU_RTR_CS_15, 1); 61 + } 62 + 14 63 static const char *tb_switch_tmu_mode_name(const struct tb_switch *sw) 15 64 { 16 65 bool root_switch = !tb_route(sw); ··· 397 348 398 349 399 350 if (tb_route(sw)) { 400 - bool unidirectional = tb_switch_tmu_hifi_is_enabled(sw, true); 351 + bool unidirectional = sw->tmu.unidirectional; 401 352 struct tb_switch *parent = tb_switch_parent(sw); 402 353 struct tb_port *down, *up; 403 354 int ret; ··· 408 359 * In case of uni-directional time sync, TMU handshake is 409 360 * initiated by upstream router. In case of bi-directional 410 361 * time sync, TMU handshake is initiated by downstream router. 411 - * Therefore, we change the rate to off in the respective 412 - * router. 362 + * We change downstream router's rate to off for both uni/bidir 363 + * cases although it is needed only for the bi-directional mode. 364 + * We avoid changing upstream router's mode since it might 365 + * have another downstream router plugged, that is set to 366 + * uni-directional mode and we don't want to change it's TMU 367 + * mode. 413 368 */ 414 - if (unidirectional) 415 - tb_switch_tmu_rate_write(parent, TB_SWITCH_TMU_RATE_OFF); 416 - else 417 - tb_switch_tmu_rate_write(sw, TB_SWITCH_TMU_RATE_OFF); 369 + tb_switch_tmu_rate_write(sw, TB_SWITCH_TMU_RATE_OFF); 418 370 419 371 tb_port_tmu_time_sync_disable(up); 420 372 ret = tb_port_tmu_time_sync_disable(down); ··· 461 411 else 462 412 tb_switch_tmu_rate_write(sw, TB_SWITCH_TMU_RATE_OFF); 463 413 414 + tb_switch_set_tmu_mode_params(sw, sw->tmu.rate); 464 415 tb_port_tmu_unidirectional_disable(down); 465 416 tb_port_tmu_unidirectional_disable(up); 466 417 } ··· 543 492 544 493 up = tb_upstream_port(sw); 545 494 down = tb_port_at(tb_route(sw), parent); 546 - ret = tb_switch_tmu_rate_write(parent, TB_SWITCH_TMU_RATE_HIFI); 495 + ret = tb_switch_tmu_rate_write(parent, sw->tmu.rate_request); 496 + if (ret) 497 + return ret; 498 + 499 + ret = tb_switch_set_tmu_mode_params(sw, sw->tmu.rate_request); 547 500 if (ret) 548 501 return ret; 549 502 ··· 574 519 return ret; 575 520 } 576 521 577 - static int tb_switch_tmu_hifi_enable(struct tb_switch *sw) 522 + static void __tb_switch_tmu_change_mode_prev(struct tb_switch *sw) 523 + { 524 + struct tb_switch *parent = tb_switch_parent(sw); 525 + struct tb_port *down, *up; 526 + 527 + down = tb_port_at(tb_route(sw), parent); 528 + up = tb_upstream_port(sw); 529 + /* 530 + * In case of any failure in one of the steps when change mode, 531 + * get back to the TMU configurations in previous mode. 532 + * In case of additional failures in the functions below, 533 + * ignore them since the caller shall already report a failure. 534 + */ 535 + tb_port_tmu_set_unidirectional(down, sw->tmu.unidirectional); 536 + if (sw->tmu.unidirectional_request) 537 + tb_switch_tmu_rate_write(parent, sw->tmu.rate); 538 + else 539 + tb_switch_tmu_rate_write(sw, sw->tmu.rate); 540 + 541 + tb_switch_set_tmu_mode_params(sw, sw->tmu.rate); 542 + tb_port_tmu_set_unidirectional(up, sw->tmu.unidirectional); 543 + } 544 + 545 + static int __tb_switch_tmu_change_mode(struct tb_switch *sw) 546 + { 547 + struct tb_switch *parent = tb_switch_parent(sw); 548 + struct tb_port *up, *down; 549 + int ret; 550 + 551 + up = tb_upstream_port(sw); 552 + down = tb_port_at(tb_route(sw), parent); 553 + ret = tb_port_tmu_set_unidirectional(down, sw->tmu.unidirectional_request); 554 + if (ret) 555 + goto out; 556 + 557 + if (sw->tmu.unidirectional_request) 558 + ret = tb_switch_tmu_rate_write(parent, sw->tmu.rate_request); 559 + else 560 + ret = tb_switch_tmu_rate_write(sw, sw->tmu.rate_request); 561 + if (ret) 562 + return ret; 563 + 564 + ret = tb_switch_set_tmu_mode_params(sw, sw->tmu.rate_request); 565 + if (ret) 566 + return ret; 567 + 568 + ret = tb_port_tmu_set_unidirectional(up, sw->tmu.unidirectional_request); 569 + if (ret) 570 + goto out; 571 + 572 + ret = tb_port_tmu_time_sync_enable(down); 573 + if (ret) 574 + goto out; 575 + 576 + ret = tb_port_tmu_time_sync_enable(up); 577 + if (ret) 578 + goto out; 579 + 580 + return 0; 581 + 582 + out: 583 + __tb_switch_tmu_change_mode_prev(sw); 584 + return ret; 585 + } 586 + 587 + /** 588 + * tb_switch_tmu_enable() - Enable TMU on a router 589 + * @sw: Router whose TMU to enable 590 + * 591 + * Enables TMU of a router to be in uni-directional Normal/HiFi 592 + * or bi-directional HiFi mode. Calling tb_switch_tmu_configure() is required 593 + * before calling this function, to select the mode Normal/HiFi and 594 + * directionality (uni-directional/bi-directional). 595 + * In HiFi mode all tunneling should work. In Normal mode, DP tunneling can't 596 + * work. Uni-directional mode is required for CLx (Link Low-Power) to work. 597 + */ 598 + int tb_switch_tmu_enable(struct tb_switch *sw) 578 599 { 579 600 bool unidirectional = sw->tmu.unidirectional_request; 580 601 int ret; ··· 666 535 if (!tb_switch_is_clx_supported(sw)) 667 536 return 0; 668 537 669 - if (tb_switch_tmu_hifi_is_enabled(sw, sw->tmu.unidirectional_request)) 538 + if (tb_switch_tmu_is_enabled(sw, sw->tmu.unidirectional_request)) 670 539 return 0; 671 540 672 541 if (tb_switch_is_titan_ridge(sw) && unidirectional) { 673 - /* Titan Ridge supports only CL0s */ 674 - if (!tb_switch_is_cl0s_enabled(sw)) 542 + /* 543 + * Titan Ridge supports CL0s and CL1 only. CL0s and CL1 are 544 + * enabled and supported together. 545 + */ 546 + if (!tb_switch_is_clx_enabled(sw, TB_CL1)) 675 547 return -EOPNOTSUPP; 676 548 677 549 ret = tb_switch_tmu_objection_mask(sw); ··· 691 557 return ret; 692 558 693 559 if (tb_route(sw)) { 694 - /* The used mode changes are from OFF to HiFi-Uni/HiFi-BiDir */ 560 + /* 561 + * The used mode changes are from OFF to 562 + * HiFi-Uni/HiFi-BiDir/Normal-Uni or from Normal-Uni to 563 + * HiFi-Uni. 564 + */ 695 565 if (sw->tmu.rate == TB_SWITCH_TMU_RATE_OFF) { 696 566 if (unidirectional) 697 567 ret = __tb_switch_tmu_enable_unidirectional(sw); 698 568 else 699 569 ret = __tb_switch_tmu_enable_bidirectional(sw); 570 + if (ret) 571 + return ret; 572 + } else if (sw->tmu.rate == TB_SWITCH_TMU_RATE_NORMAL) { 573 + ret = __tb_switch_tmu_change_mode(sw); 700 574 if (ret) 701 575 return ret; 702 576 } ··· 716 574 * of the child node - see above. 717 575 * Here only the host router' rate configuration is written. 718 576 */ 719 - ret = tb_switch_tmu_rate_write(sw, TB_SWITCH_TMU_RATE_HIFI); 577 + ret = tb_switch_tmu_rate_write(sw, sw->tmu.rate_request); 720 578 if (ret) 721 579 return ret; 722 580 } 723 581 724 - sw->tmu.rate = TB_SWITCH_TMU_RATE_HIFI; 582 + sw->tmu.rate = sw->tmu.rate_request; 725 583 726 584 tb_sw_dbg(sw, "TMU: mode set to: %s\n", tb_switch_tmu_mode_name(sw)); 727 585 return tb_switch_tmu_set_time_disruption(sw, false); 728 586 } 729 587 730 588 /** 731 - * tb_switch_tmu_enable() - Enable TMU on a router 732 - * @sw: Router whose TMU to enable 733 - * 734 - * Enables TMU of a router to be in uni-directional or bi-directional HiFi mode. 735 - * Calling tb_switch_tmu_configure() is required before calling this function, 736 - * to select the mode HiFi and directionality (uni-directional/bi-directional). 737 - * In both modes all tunneling should work. Uni-directional mode is required for 738 - * CLx (Link Low-Power) to work. 739 - */ 740 - int tb_switch_tmu_enable(struct tb_switch *sw) 741 - { 742 - if (sw->tmu.rate_request == TB_SWITCH_TMU_RATE_NORMAL) 743 - return -EOPNOTSUPP; 744 - 745 - return tb_switch_tmu_hifi_enable(sw); 746 - } 747 - 748 - /** 749 589 * tb_switch_tmu_configure() - Configure the TMU rate and directionality 750 590 * @sw: Router whose mode to change 751 - * @rate: Rate to configure Off/LowRes/HiFi 591 + * @rate: Rate to configure Off/Normal/HiFi 752 592 * @unidirectional: If uni-directional (bi-directional otherwise) 753 593 * 754 594 * Selects the rate of the TMU and directionality (uni-directional or ··· 741 617 { 742 618 sw->tmu.unidirectional_request = unidirectional; 743 619 sw->tmu.rate_request = rate; 620 + } 621 + 622 + static int tb_switch_tmu_config_enable(struct device *dev, void *rate) 623 + { 624 + if (tb_is_switch(dev)) { 625 + struct tb_switch *sw = tb_to_switch(dev); 626 + 627 + tb_switch_tmu_configure(sw, *(enum tb_switch_tmu_rate *)rate, 628 + tb_switch_is_clx_enabled(sw, TB_CL1)); 629 + if (tb_switch_tmu_enable(sw)) 630 + tb_sw_dbg(sw, "fail switching TMU mode for 1st depth router\n"); 631 + } 632 + 633 + return 0; 634 + } 635 + 636 + /** 637 + * tb_switch_enable_tmu_1st_child - Configure and enable TMU for 1st chidren 638 + * @sw: The router to configure and enable it's children TMU 639 + * @rate: Rate of the TMU to configure the router's chidren to 640 + * 641 + * Configures and enables the TMU mode of 1st depth children of the specified 642 + * router to the specified rate. 643 + */ 644 + void tb_switch_enable_tmu_1st_child(struct tb_switch *sw, 645 + enum tb_switch_tmu_rate rate) 646 + { 647 + device_for_each_child(&sw->dev, &rate, 648 + tb_switch_tmu_config_enable); 744 649 }
+1 -1
drivers/usb/atm/ueagle-atm.c
··· 9 9 * HISTORY : some part of the code was base on ueagle 1.3 BSD driver, 10 10 * Damien Bergamini agree to put his code under a DUAL GPL/BSD license. 11 11 * 12 - * The rest of the code was was rewritten from scratch. 12 + * The rest of the code was rewritten from scratch. 13 13 */ 14 14 15 15 #include <linux/module.h>
+8 -5
drivers/usb/cdns3/cdns3-gadget.c
··· 220 220 221 221 if (!priv_ep->trb_pool) { 222 222 priv_ep->trb_pool = dma_pool_alloc(priv_dev->eps_dma_pool, 223 - GFP_DMA32 | GFP_ATOMIC, 223 + GFP_ATOMIC, 224 224 &priv_ep->trb_pool_dma); 225 225 226 226 if (!priv_ep->trb_pool) ··· 625 625 trace_cdns3_wa2(priv_ep, "removes eldest request"); 626 626 627 627 kfree(priv_req->request.buf); 628 + list_del_init(&priv_req->list); 628 629 cdns3_gadget_ep_free_request(&priv_ep->endpoint, 629 630 &priv_req->request); 630 - list_del_init(&priv_req->list); 631 631 --priv_ep->wa2_counter; 632 632 633 633 if (!chain) ··· 2285 2285 int val; 2286 2286 2287 2287 priv_ep = ep_to_cdns3_ep(ep); 2288 - priv_dev = priv_ep->cdns3_dev; 2289 - comp_desc = priv_ep->endpoint.comp_desc; 2290 2288 2291 2289 if (!ep || !desc || desc->bDescriptorType != USB_DT_ENDPOINT) { 2292 2290 dev_dbg(priv_dev->dev, "usbss: invalid parameters\n"); 2293 2291 return -EINVAL; 2294 2292 } 2293 + 2294 + comp_desc = priv_ep->endpoint.comp_desc; 2295 + priv_dev = priv_ep->cdns3_dev; 2295 2296 2296 2297 if (!desc->wMaxPacketSize) { 2297 2298 dev_err(priv_dev->dev, "usbss: missing wMaxPacketSize\n"); ··· 2601 2600 struct usb_request *request) 2602 2601 { 2603 2602 struct cdns3_endpoint *priv_ep = ep_to_cdns3_ep(ep); 2604 - struct cdns3_device *priv_dev = priv_ep->cdns3_dev; 2603 + struct cdns3_device *priv_dev; 2605 2604 struct usb_request *req, *req_temp; 2606 2605 struct cdns3_request *priv_req; 2607 2606 struct cdns3_trb *link_trb; ··· 2611 2610 2612 2611 if (!ep || !request || !ep->desc) 2613 2612 return -EINVAL; 2613 + 2614 + priv_dev = priv_ep->cdns3_dev; 2614 2615 2615 2616 spin_lock_irqsave(&priv_dev->lock, flags); 2616 2617
+1
drivers/usb/chipidea/ci.h
··· 49 49 OP_USBCMD, 50 50 OP_USBSTS, 51 51 OP_USBINTR, 52 + OP_FRINDEX, 52 53 OP_DEVICEADDR, 53 54 OP_ENDPTLISTADDR, 54 55 OP_TTCTRL,
+7 -16
drivers/usb/chipidea/ci_hdrc_imx.c
··· 348 348 data->pinctrl = devm_pinctrl_get(dev); 349 349 if (PTR_ERR(data->pinctrl) == -ENODEV) 350 350 data->pinctrl = NULL; 351 - else if (IS_ERR(data->pinctrl)) { 352 - if (PTR_ERR(data->pinctrl) != -EPROBE_DEFER) 353 - dev_err(dev, "pinctrl get failed, err=%ld\n", 354 - PTR_ERR(data->pinctrl)); 355 - return PTR_ERR(data->pinctrl); 356 - } 351 + else if (IS_ERR(data->pinctrl)) 352 + return dev_err_probe(dev, PTR_ERR(data->pinctrl), 353 + "pinctrl get failed\n"); 357 354 358 355 data->hsic_pad_regulator = 359 356 devm_regulator_get_optional(dev, "hsic"); 360 357 if (PTR_ERR(data->hsic_pad_regulator) == -ENODEV) { 361 358 /* no pad regualator is needed */ 362 359 data->hsic_pad_regulator = NULL; 363 - } else if (IS_ERR(data->hsic_pad_regulator)) { 364 - if (PTR_ERR(data->hsic_pad_regulator) != -EPROBE_DEFER) 365 - dev_err(dev, 366 - "Get HSIC pad regulator error: %ld\n", 367 - PTR_ERR(data->hsic_pad_regulator)); 368 - return PTR_ERR(data->hsic_pad_regulator); 369 - } 360 + } else if (IS_ERR(data->hsic_pad_regulator)) 361 + return dev_err_probe(dev, PTR_ERR(data->hsic_pad_regulator), 362 + "Get HSIC pad regulator error\n"); 370 363 371 364 if (data->hsic_pad_regulator) { 372 365 ret = regulator_enable(data->hsic_pad_regulator); ··· 451 458 &pdata); 452 459 if (IS_ERR(data->ci_pdev)) { 453 460 ret = PTR_ERR(data->ci_pdev); 454 - if (ret != -EPROBE_DEFER) 455 - dev_err(dev, "ci_hdrc_add_device failed, err=%d\n", 456 - ret); 461 + dev_err_probe(dev, ret, "ci_hdrc_add_device failed\n"); 457 462 goto err_clk; 458 463 } 459 464
+1 -1
drivers/usb/chipidea/ci_hdrc_imx.h
··· 21 21 unsigned int pwr_pol:1; /* power polarity */ 22 22 unsigned int evdo:1; /* set external vbus divider option */ 23 23 unsigned int ulpi:1; /* connected to an ULPI phy */ 24 - unsigned int hsic:1; /* HSIC controlller */ 24 + unsigned int hsic:1; /* HSIC controller */ 25 25 unsigned int ext_id:1; /* ID from exteranl event */ 26 26 unsigned int ext_vbus:1; /* Vbus from exteranl event */ 27 27 struct usb_phy *usb_phy;
+2
drivers/usb/chipidea/core.c
··· 53 53 [OP_USBCMD] = 0x00U, 54 54 [OP_USBSTS] = 0x04U, 55 55 [OP_USBINTR] = 0x08U, 56 + [OP_FRINDEX] = 0x0CU, 56 57 [OP_DEVICEADDR] = 0x14U, 57 58 [OP_ENDPTLISTADDR] = 0x18U, 58 59 [OP_TTCTRL] = 0x1CU, ··· 79 78 [OP_USBCMD] = 0x00U, 80 79 [OP_USBSTS] = 0x04U, 81 80 [OP_USBINTR] = 0x08U, 81 + [OP_FRINDEX] = 0x0CU, 82 82 [OP_DEVICEADDR] = 0x14U, 83 83 [OP_ENDPTLISTADDR] = 0x18U, 84 84 [OP_TTCTRL] = 0x1CU,
+1 -1
drivers/usb/chipidea/otg_fsm.c
··· 459 459 struct ci_hdrc *ci = container_of(fsm, struct ci_hdrc, fsm); 460 460 461 461 if (on) { 462 - /* Enable power power */ 462 + /* Enable power */ 463 463 hw_write(ci, OP_PORTSC, PORTSC_W1C_BITS | PORTSC_PP, 464 464 PORTSC_PP); 465 465 if (ci->platdata->reg_vbus) {
+14
drivers/usb/chipidea/udc.c
··· 1654 1654 /****************************************************************************** 1655 1655 * GADGET block 1656 1656 *****************************************************************************/ 1657 + 1658 + static int ci_udc_get_frame(struct usb_gadget *_gadget) 1659 + { 1660 + struct ci_hdrc *ci = container_of(_gadget, struct ci_hdrc, gadget); 1661 + unsigned long flags; 1662 + int ret; 1663 + 1664 + spin_lock_irqsave(&ci->lock, flags); 1665 + ret = hw_read(ci, OP_FRINDEX, 0x3fff); 1666 + spin_unlock_irqrestore(&ci->lock, flags); 1667 + return ret >> 3; 1668 + } 1669 + 1657 1670 /* 1658 1671 * ci_hdrc_gadget_connect: caller makes sure gadget driver is binded 1659 1672 */ ··· 1823 1810 * Check "usb_gadget.h" for details 1824 1811 */ 1825 1812 static const struct usb_gadget_ops usb_gadget_ops = { 1813 + .get_frame = ci_udc_get_frame, 1826 1814 .vbus_session = ci_udc_vbus_session, 1827 1815 .wakeup = ci_udc_wakeup, 1828 1816 .set_selfpowered = ci_udc_selfpowered,
+22 -22
drivers/usb/class/cdc-acm.c
··· 119 119 retval = usb_control_msg(acm->dev, usb_sndctrlpipe(acm->dev, 0), 120 120 request, USB_RT_ACM, value, 121 121 acm->control->altsetting[0].desc.bInterfaceNumber, 122 - buf, len, 5000); 122 + buf, len, USB_CTRL_SET_TIMEOUT); 123 123 124 124 dev_dbg(&acm->control->dev, 125 125 "%s - rq 0x%02x, val %#x, len %#x, result %d\n", ··· 311 311 dev_dbg(&acm->control->dev, 312 312 "%s - serial state: 0x%x\n", __func__, newctrl); 313 313 314 - if (!acm->clocal && (acm->ctrlin & ~newctrl & ACM_CTRL_DCD)) { 314 + if (!acm->clocal && (acm->ctrlin & ~newctrl & USB_CDC_SERIAL_STATE_DCD)) { 315 315 dev_dbg(&acm->control->dev, 316 316 "%s - calling hangup\n", __func__); 317 317 tty_port_tty_hangup(&acm->port, false); ··· 322 322 acm->ctrlin = newctrl; 323 323 acm->oldcount = acm->iocount; 324 324 325 - if (difference & ACM_CTRL_DSR) 325 + if (difference & USB_CDC_SERIAL_STATE_DSR) 326 326 acm->iocount.dsr++; 327 - if (difference & ACM_CTRL_DCD) 327 + if (difference & USB_CDC_SERIAL_STATE_DCD) 328 328 acm->iocount.dcd++; 329 - if (newctrl & ACM_CTRL_BRK) { 329 + if (newctrl & USB_CDC_SERIAL_STATE_BREAK) { 330 330 acm->iocount.brk++; 331 331 tty_insert_flip_char(&acm->port, 0, TTY_BREAK); 332 332 } 333 - if (newctrl & ACM_CTRL_RI) 333 + if (newctrl & USB_CDC_SERIAL_STATE_RING_SIGNAL) 334 334 acm->iocount.rng++; 335 - if (newctrl & ACM_CTRL_FRAMING) 335 + if (newctrl & USB_CDC_SERIAL_STATE_FRAMING) 336 336 acm->iocount.frame++; 337 - if (newctrl & ACM_CTRL_PARITY) 337 + if (newctrl & USB_CDC_SERIAL_STATE_PARITY) 338 338 acm->iocount.parity++; 339 - if (newctrl & ACM_CTRL_OVERRUN) 339 + if (newctrl & USB_CDC_SERIAL_STATE_OVERRUN) 340 340 acm->iocount.overrun++; 341 341 spin_unlock_irqrestore(&acm->read_lock, flags); 342 342 343 - if (newctrl & ACM_CTRL_BRK) 343 + if (newctrl & USB_CDC_SERIAL_STATE_BREAK) 344 344 tty_flip_buffer_push(&acm->port); 345 345 346 346 if (difference) ··· 658 658 int res; 659 659 660 660 if (raise) 661 - val = ACM_CTRL_DTR | ACM_CTRL_RTS; 661 + val = USB_CDC_CTRL_DTR | USB_CDC_CTRL_RTS; 662 662 else 663 663 val = 0; 664 664 ··· 903 903 { 904 904 struct acm *acm = tty->driver_data; 905 905 906 - return (acm->ctrlout & ACM_CTRL_DTR ? TIOCM_DTR : 0) | 907 - (acm->ctrlout & ACM_CTRL_RTS ? TIOCM_RTS : 0) | 908 - (acm->ctrlin & ACM_CTRL_DSR ? TIOCM_DSR : 0) | 909 - (acm->ctrlin & ACM_CTRL_RI ? TIOCM_RI : 0) | 910 - (acm->ctrlin & ACM_CTRL_DCD ? TIOCM_CD : 0) | 906 + return (acm->ctrlout & USB_CDC_CTRL_DTR ? TIOCM_DTR : 0) | 907 + (acm->ctrlout & USB_CDC_CTRL_RTS ? TIOCM_RTS : 0) | 908 + (acm->ctrlin & USB_CDC_SERIAL_STATE_DSR ? TIOCM_DSR : 0) | 909 + (acm->ctrlin & USB_CDC_SERIAL_STATE_RING_SIGNAL ? TIOCM_RI : 0) | 910 + (acm->ctrlin & USB_CDC_SERIAL_STATE_DCD ? TIOCM_CD : 0) | 911 911 TIOCM_CTS; 912 912 } 913 913 ··· 918 918 unsigned int newctrl; 919 919 920 920 newctrl = acm->ctrlout; 921 - set = (set & TIOCM_DTR ? ACM_CTRL_DTR : 0) | 922 - (set & TIOCM_RTS ? ACM_CTRL_RTS : 0); 923 - clear = (clear & TIOCM_DTR ? ACM_CTRL_DTR : 0) | 924 - (clear & TIOCM_RTS ? ACM_CTRL_RTS : 0); 921 + set = (set & TIOCM_DTR ? USB_CDC_CTRL_DTR : 0) | 922 + (set & TIOCM_RTS ? USB_CDC_CTRL_RTS : 0); 923 + clear = (clear & TIOCM_DTR ? USB_CDC_CTRL_DTR : 0) | 924 + (clear & TIOCM_RTS ? USB_CDC_CTRL_RTS : 0); 925 925 926 926 newctrl = (newctrl & ~clear) | set; 927 927 ··· 1068 1068 1069 1069 if (C_BAUD(tty) == B0) { 1070 1070 newline.dwDTERate = acm->line.dwDTERate; 1071 - newctrl &= ~ACM_CTRL_DTR; 1071 + newctrl &= ~USB_CDC_CTRL_DTR; 1072 1072 } else if (termios_old && (termios_old->c_cflag & CBAUD) == B0) { 1073 - newctrl |= ACM_CTRL_DTR; 1073 + newctrl |= USB_CDC_CTRL_DTR; 1074 1074 } 1075 1075 1076 1076 if (newctrl != acm->ctrlout)
-20
drivers/usb/class/cdc-acm.h
··· 23 23 #define USB_RT_ACM (USB_TYPE_CLASS | USB_RECIP_INTERFACE) 24 24 25 25 /* 26 - * Output control lines. 27 - */ 28 - 29 - #define ACM_CTRL_DTR 0x01 30 - #define ACM_CTRL_RTS 0x02 31 - 32 - /* 33 - * Input control lines and line errors. 34 - */ 35 - 36 - #define ACM_CTRL_DCD 0x01 37 - #define ACM_CTRL_DSR 0x02 38 - #define ACM_CTRL_BRK 0x04 39 - #define ACM_CTRL_RI 0x08 40 - 41 - #define ACM_CTRL_FRAMING 0x10 42 - #define ACM_CTRL_PARITY 0x20 43 - #define ACM_CTRL_OVERRUN 0x40 44 - 45 - /* 46 26 * Internal driver structures. 47 27 */ 48 28
+17
drivers/usb/common/usb-conn-gpio.c
··· 257 257 } 258 258 259 259 platform_set_drvdata(pdev, info); 260 + device_set_wakeup_capable(&pdev->dev, true); 260 261 261 262 /* Perform initial detection */ 262 263 usb_conn_queue_dwork(info, 0); ··· 287 286 { 288 287 struct usb_conn_info *info = dev_get_drvdata(dev); 289 288 289 + if (device_may_wakeup(dev)) { 290 + if (info->id_gpiod) 291 + enable_irq_wake(info->id_irq); 292 + if (info->vbus_gpiod) 293 + enable_irq_wake(info->vbus_irq); 294 + return 0; 295 + } 296 + 290 297 if (info->id_gpiod) 291 298 disable_irq(info->id_irq); 292 299 if (info->vbus_gpiod) ··· 308 299 static int __maybe_unused usb_conn_resume(struct device *dev) 309 300 { 310 301 struct usb_conn_info *info = dev_get_drvdata(dev); 302 + 303 + if (device_may_wakeup(dev)) { 304 + if (info->id_gpiod) 305 + disable_irq_wake(info->id_irq); 306 + if (info->vbus_gpiod) 307 + disable_irq_wake(info->vbus_irq); 308 + return 0; 309 + } 311 310 312 311 pinctrl_pm_select_default_state(dev); 313 312
+4
drivers/usb/core/Makefile
··· 12 12 usbcore-$(CONFIG_USB_PCI) += hcd-pci.o 13 13 usbcore-$(CONFIG_ACPI) += usb-acpi.o 14 14 15 + ifdef CONFIG_USB_ONBOARD_HUB 16 + usbcore-y += ../misc/onboard_usb_hub_pdevs.o 17 + endif 18 + 15 19 obj-$(CONFIG_USB) += usbcore.o 16 20 17 21 obj-$(CONFIG_USB_LEDS_TRIGGER_USBPORT) += ledtrig-usbport.o
+1 -1
drivers/usb/core/driver.c
··· 1482 1482 * @msg: Power Management message describing this state transition 1483 1483 * 1484 1484 * This is the central routine for resuming USB devices. It calls the 1485 - * the resume method for @udev and then calls the resume methods for all 1485 + * resume method for @udev and then calls the resume methods for all 1486 1486 * the interface drivers in @udev. 1487 1487 * 1488 1488 * Autoresume requests originating from a child device or an interface
+22 -12
drivers/usb/core/hcd.c
··· 1691 1691 1692 1692 spin_lock_irq(&bh->lock); 1693 1693 bh->running = true; 1694 - restart: 1695 1694 list_replace_init(&bh->head, &local_list); 1696 1695 spin_unlock_irq(&bh->lock); 1697 1696 ··· 1704 1705 bh->completing_ep = NULL; 1705 1706 } 1706 1707 1707 - /* check if there are new URBs to giveback */ 1708 + /* 1709 + * giveback new URBs next time to prevent this function 1710 + * from not exiting for a long time. 1711 + */ 1708 1712 spin_lock_irq(&bh->lock); 1709 - if (!list_empty(&bh->head)) 1710 - goto restart; 1713 + if (!list_empty(&bh->head)) { 1714 + if (bh->high_prio) 1715 + tasklet_hi_schedule(&bh->bh); 1716 + else 1717 + tasklet_schedule(&bh->bh); 1718 + } 1711 1719 bh->running = false; 1712 1720 spin_unlock_irq(&bh->lock); 1713 1721 } ··· 1743 1737 void usb_hcd_giveback_urb(struct usb_hcd *hcd, struct urb *urb, int status) 1744 1738 { 1745 1739 struct giveback_urb_bh *bh; 1746 - bool running, high_prio_bh; 1740 + bool running; 1747 1741 1748 1742 /* pass status to tasklet via unlinked */ 1749 1743 if (likely(!urb->unlinked)) ··· 1754 1748 return; 1755 1749 } 1756 1750 1757 - if (usb_pipeisoc(urb->pipe) || usb_pipeint(urb->pipe)) { 1751 + if (usb_pipeisoc(urb->pipe) || usb_pipeint(urb->pipe)) 1758 1752 bh = &hcd->high_prio_bh; 1759 - high_prio_bh = true; 1760 - } else { 1753 + else 1761 1754 bh = &hcd->low_prio_bh; 1762 - high_prio_bh = false; 1763 - } 1764 1755 1765 1756 spin_lock(&bh->lock); 1766 1757 list_add_tail(&urb->urb_list, &bh->head); ··· 1766 1763 1767 1764 if (running) 1768 1765 ; 1769 - else if (high_prio_bh) 1766 + else if (bh->high_prio) 1770 1767 tasklet_hi_schedule(&bh->bh); 1771 1768 else 1772 1769 tasklet_schedule(&bh->bh); ··· 2962 2959 2963 2960 /* initialize tasklets */ 2964 2961 init_giveback_urb_bh(&hcd->high_prio_bh); 2962 + hcd->high_prio_bh.high_prio = true; 2965 2963 init_giveback_urb_bh(&hcd->low_prio_bh); 2966 2964 2967 2965 /* enable irqs just before we start the controller, ··· 3037 3033 */ 3038 3034 void usb_remove_hcd(struct usb_hcd *hcd) 3039 3035 { 3040 - struct usb_device *rhdev = hcd->self.root_hub; 3036 + struct usb_device *rhdev; 3041 3037 bool rh_registered; 3038 + 3039 + if (!hcd) { 3040 + pr_debug("%s: hcd is NULL\n", __func__); 3041 + return; 3042 + } 3043 + rhdev = hcd->self.root_hub; 3042 3044 3043 3045 dev_info(hcd->self.controller, "remove, state %x\n", hcd->state); 3044 3046
+49 -59
drivers/usb/core/hub.c
··· 23 23 #include <linux/usb.h> 24 24 #include <linux/usbdevice_fs.h> 25 25 #include <linux/usb/hcd.h> 26 + #include <linux/usb/onboard_hub.h> 26 27 #include <linux/usb/otg.h> 27 28 #include <linux/usb/quirks.h> 28 29 #include <linux/workqueue.h> ··· 614 613 return ret; 615 614 } 616 615 617 - static int hub_port_status(struct usb_hub *hub, int port1, 616 + int usb_hub_port_status(struct usb_hub *hub, int port1, 618 617 u16 *status, u16 *change) 619 618 { 620 619 return hub_ext_port_status(hub, port1, HUB_PORT_STATUS, ··· 1127 1126 u16 portstatus, portchange; 1128 1127 1129 1128 portstatus = portchange = 0; 1130 - status = hub_port_status(hub, port1, &portstatus, &portchange); 1129 + status = usb_hub_port_status(hub, port1, &portstatus, &portchange); 1131 1130 if (status) 1132 1131 goto abort; 1133 1132 ··· 1753 1752 if (hub->quirk_disable_autosuspend) 1754 1753 usb_autopm_put_interface(intf); 1755 1754 1755 + onboard_hub_destroy_pdevs(&hub->onboard_hub_devs); 1756 + 1756 1757 kref_put(&hub->kref, hub_release); 1757 1758 } 1758 1759 ··· 1872 1869 INIT_DELAYED_WORK(&hub->leds, led_work); 1873 1870 INIT_DELAYED_WORK(&hub->init_work, NULL); 1874 1871 INIT_WORK(&hub->events, hub_event); 1872 + INIT_LIST_HEAD(&hub->onboard_hub_devs); 1875 1873 spin_lock_init(&hub->irq_urb_lock); 1876 1874 timer_setup(&hub->irq_urb_retry, hub_retry_irq_urb, 0); 1877 1875 usb_get_intf(intf); ··· 1893 1889 usb_autopm_get_interface_no_resume(intf); 1894 1890 } 1895 1891 1896 - if (hub_configure(hub, &desc->endpoint[0].desc) >= 0) 1892 + if (hub_configure(hub, &desc->endpoint[0].desc) >= 0) { 1893 + onboard_hub_create_pdevs(hdev, &hub->onboard_hub_devs); 1894 + 1897 1895 return 0; 1896 + } 1898 1897 1899 1898 hub_disconnect(intf); 1900 1899 return -ENODEV; ··· 2862 2855 &portstatus, &portchange, 2863 2856 &ext_portstatus); 2864 2857 else 2865 - ret = hub_port_status(hub, port1, &portstatus, 2858 + ret = usb_hub_port_status(hub, port1, &portstatus, 2866 2859 &portchange); 2867 2860 if (ret < 0) 2868 2861 return ret; ··· 2963 2956 * If the caller hasn't explicitly requested a warm reset, 2964 2957 * double check and see if one is needed. 2965 2958 */ 2966 - if (hub_port_status(hub, port1, &portstatus, &portchange) == 0) 2959 + if (usb_hub_port_status(hub, port1, &portstatus, 2960 + &portchange) == 0) 2967 2961 if (hub_port_warm_reset_required(hub, port1, 2968 2962 portstatus)) 2969 2963 warm = true; ··· 3016 3008 * If a USB 3.0 device migrates from reset to an error 3017 3009 * state, re-issue the warm reset. 3018 3010 */ 3019 - if (hub_port_status(hub, port1, 3011 + if (usb_hub_port_status(hub, port1, 3020 3012 &portstatus, &portchange) < 0) 3021 3013 goto done; 3022 3014 ··· 3082 3074 } 3083 3075 3084 3076 /* Check if a port is power on */ 3085 - static int port_is_power_on(struct usb_hub *hub, unsigned portstatus) 3077 + int usb_port_is_power_on(struct usb_hub *hub, unsigned int portstatus) 3086 3078 { 3087 3079 int ret = 0; 3088 3080 ··· 3148 3140 } 3149 3141 /* Is the device still present? */ 3150 3142 else if (status || port_is_suspended(hub, portstatus) || 3151 - !port_is_power_on(hub, portstatus)) { 3143 + !usb_port_is_power_on(hub, portstatus)) { 3152 3144 if (status >= 0) 3153 3145 status = -ENODEV; 3154 3146 } else if (!(portstatus & USB_PORT_STAT_CONNECTION)) { 3155 3147 if (retries--) { 3156 3148 usleep_range(200, 300); 3157 - status = hub_port_status(hub, port1, &portstatus, 3149 + status = usb_hub_port_status(hub, port1, &portstatus, 3158 3150 &portchange); 3159 3151 goto retry; 3160 3152 } ··· 3417 3409 u16 portstatus, portchange; 3418 3410 3419 3411 portstatus = portchange = 0; 3420 - ret = hub_port_status(hub, port1, &portstatus, 3412 + ret = usb_hub_port_status(hub, port1, &portstatus, 3421 3413 &portchange); 3422 3414 3423 3415 dev_dbg(&port_dev->dev, ··· 3595 3587 while (delay_ms < 2000) { 3596 3588 if (status || *portstatus & USB_PORT_STAT_CONNECTION) 3597 3589 break; 3598 - if (!port_is_power_on(hub, *portstatus)) { 3590 + if (!usb_port_is_power_on(hub, *portstatus)) { 3599 3591 status = -ENODEV; 3600 3592 break; 3601 3593 } 3602 3594 msleep(20); 3603 3595 delay_ms += 20; 3604 - status = hub_port_status(hub, port1, portstatus, portchange); 3596 + status = usb_hub_port_status(hub, port1, portstatus, portchange); 3605 3597 } 3606 3598 dev_dbg(&udev->dev, "Waited %dms for CONNECT\n", delay_ms); 3607 3599 return status; ··· 3661 3653 usb_lock_port(port_dev); 3662 3654 3663 3655 /* Skip the initial Clear-Suspend step for a remote wakeup */ 3664 - status = hub_port_status(hub, port1, &portstatus, &portchange); 3656 + status = usb_hub_port_status(hub, port1, &portstatus, &portchange); 3665 3657 if (status == 0 && !port_is_suspended(hub, portstatus)) { 3666 3658 if (portchange & USB_PORT_STAT_C_SUSPEND) 3667 3659 pm_wakeup_event(&udev->dev, 0); ··· 3686 3678 * stop resume signaling. Then finish the resume 3687 3679 * sequence. 3688 3680 */ 3689 - status = hub_port_status(hub, port1, &portstatus, &portchange); 3681 + status = usb_hub_port_status(hub, port1, &portstatus, &portchange); 3690 3682 } 3691 3683 3692 3684 SuspendCleared: ··· 3799 3791 u16 portstatus, portchange; 3800 3792 int status; 3801 3793 3802 - status = hub_port_status(hub, port1, &portstatus, &portchange); 3794 + status = usb_hub_port_status(hub, port1, &portstatus, &portchange); 3803 3795 if (!status && portchange) 3804 3796 return 1; 3805 3797 } ··· 3954 3946 * This function will fail if the SEL or PEL values for udev are greater than 3955 3947 * the maximum allowed values for the link state to be enabled. 3956 3948 */ 3957 - static int usb_req_set_sel(struct usb_device *udev, enum usb3_link_state state) 3949 + static int usb_req_set_sel(struct usb_device *udev) 3958 3950 { 3959 3951 struct usb_set_sel_req *sel_values; 3960 3952 unsigned long long u1_sel; ··· 3963 3955 unsigned long long u2_pel; 3964 3956 int ret; 3965 3957 3966 - if (udev->state != USB_STATE_CONFIGURED) 3958 + if (!udev->parent || udev->speed < USB_SPEED_SUPER || !udev->lpm_capable) 3967 3959 return 0; 3968 3960 3969 3961 /* Convert SEL and PEL stored in ns to us */ ··· 3980 3972 * latency for the link state, and could start a device-initiated 3981 3973 * U1/U2 when the exit latencies are too high. 3982 3974 */ 3983 - if ((state == USB3_LPM_U1 && 3984 - (u1_sel > USB3_LPM_MAX_U1_SEL_PEL || 3985 - u1_pel > USB3_LPM_MAX_U1_SEL_PEL)) || 3986 - (state == USB3_LPM_U2 && 3987 - (u2_sel > USB3_LPM_MAX_U2_SEL_PEL || 3988 - u2_pel > USB3_LPM_MAX_U2_SEL_PEL))) { 3989 - dev_dbg(&udev->dev, "Device-initiated %s disabled due to long SEL %llu us or PEL %llu us\n", 3990 - usb3_lpm_names[state], u1_sel, u1_pel); 3975 + if (u1_sel > USB3_LPM_MAX_U1_SEL_PEL || 3976 + u1_pel > USB3_LPM_MAX_U1_SEL_PEL || 3977 + u2_sel > USB3_LPM_MAX_U2_SEL_PEL || 3978 + u2_pel > USB3_LPM_MAX_U2_SEL_PEL) { 3979 + dev_dbg(&udev->dev, "Device-initiated U1/U2 disabled due to long SEL or PEL\n"); 3991 3980 return -EINVAL; 3992 3981 } 3993 - 3994 - /* 3995 - * If we're enabling device-initiated LPM for one link state, 3996 - * but the other link state has a too high SEL or PEL value, 3997 - * just set those values to the max in the Set SEL request. 3998 - */ 3999 - if (u1_sel > USB3_LPM_MAX_U1_SEL_PEL) 4000 - u1_sel = USB3_LPM_MAX_U1_SEL_PEL; 4001 - 4002 - if (u1_pel > USB3_LPM_MAX_U1_SEL_PEL) 4003 - u1_pel = USB3_LPM_MAX_U1_SEL_PEL; 4004 - 4005 - if (u2_sel > USB3_LPM_MAX_U2_SEL_PEL) 4006 - u2_sel = USB3_LPM_MAX_U2_SEL_PEL; 4007 - 4008 - if (u2_pel > USB3_LPM_MAX_U2_SEL_PEL) 4009 - u2_pel = USB3_LPM_MAX_U2_SEL_PEL; 4010 3982 4011 3983 /* 4012 3984 * usb_enable_lpm() can be called as part of a failed device reset, ··· 4009 4021 sel_values, sizeof *(sel_values), 4010 4022 USB_CTRL_SET_TIMEOUT); 4011 4023 kfree(sel_values); 4024 + 4025 + if (ret > 0) 4026 + udev->lpm_devinit_allow = 1; 4027 + 4012 4028 return ret; 4013 4029 } 4014 4030 ··· 4128 4136 unsigned int sel; /* us */ 4129 4137 int i, j; 4130 4138 4139 + if (!udev->lpm_devinit_allow) 4140 + return false; 4141 + 4131 4142 if (state == USB3_LPM_U1) 4132 4143 sel = DIV_ROUND_UP(udev->u1_params.sel, 1000); 4133 4144 else if (state == USB3_LPM_U2) ··· 4179 4184 static void usb_enable_link_state(struct usb_hcd *hcd, struct usb_device *udev, 4180 4185 enum usb3_link_state state) 4181 4186 { 4182 - int timeout, ret; 4187 + int timeout; 4183 4188 __u8 u1_mel = udev->bos->ss_cap->bU1devExitLat; 4184 4189 __le16 u2_mel = udev->bos->ss_cap->bU2DevExitLat; 4185 4190 ··· 4190 4195 if ((state == USB3_LPM_U1 && u1_mel == 0) || 4191 4196 (state == USB3_LPM_U2 && u2_mel == 0)) 4192 4197 return; 4193 - 4194 - /* 4195 - * First, let the device know about the exit latencies 4196 - * associated with the link state we're about to enable. 4197 - */ 4198 - ret = usb_req_set_sel(udev, state); 4199 - if (ret < 0) { 4200 - dev_warn(&udev->dev, "Set SEL for device-initiated %s failed.\n", 4201 - usb3_lpm_names[state]); 4202 - return; 4203 - } 4204 4198 4205 4199 /* We allow the host controller to set the U1/U2 timeout internally 4206 4200 * first, so that it can change its schedule to account for the ··· 4470 4486 return 0; 4471 4487 } 4472 4488 4489 + static int usb_req_set_sel(struct usb_device *udev) 4490 + { 4491 + return 0; 4492 + } 4493 + 4473 4494 #endif /* CONFIG_PM */ 4474 4495 4475 4496 /* ··· 4543 4554 struct usb_port *port_dev = hub->ports[port1 - 1]; 4544 4555 4545 4556 for (total_time = 0; ; total_time += HUB_DEBOUNCE_STEP) { 4546 - ret = hub_port_status(hub, port1, &portstatus, &portchange); 4557 + ret = usb_hub_port_status(hub, port1, &portstatus, &portchange); 4547 4558 if (ret < 0) 4548 4559 return ret; 4549 4560 ··· 5000 5011 udev->lpm_capable = usb_device_supports_lpm(udev); 5001 5012 udev->lpm_disable_count = 1; 5002 5013 usb_set_lpm_parameters(udev); 5014 + usb_req_set_sel(udev); 5003 5015 } 5004 5016 } 5005 5017 ··· 5230 5240 * but only if the port isn't owned by someone else. 5231 5241 */ 5232 5242 if (hub_is_port_power_switchable(hub) 5233 - && !port_is_power_on(hub, portstatus) 5243 + && !usb_port_is_power_on(hub, portstatus) 5234 5244 && !port_dev->port_owner) 5235 5245 set_port_feature(hdev, port1, USB_PORT_FEAT_POWER); 5236 5246 ··· 5547 5557 clear_bit(port1, hub->event_bits); 5548 5558 clear_bit(port1, hub->wakeup_bits); 5549 5559 5550 - if (hub_port_status(hub, port1, &portstatus, &portchange) < 0) 5560 + if (usb_hub_port_status(hub, port1, &portstatus, &portchange) < 0) 5551 5561 return; 5552 5562 5553 5563 if (portchange & USB_PORT_STAT_C_CONNECTION) { ··· 5584 5594 USB_PORT_FEAT_C_OVER_CURRENT); 5585 5595 msleep(100); /* Cool down */ 5586 5596 hub_power_on(hub, true); 5587 - hub_port_status(hub, port1, &status, &unused); 5597 + usb_hub_port_status(hub, port1, &status, &unused); 5588 5598 if (status & USB_PORT_STAT_OVERCURRENT) 5589 5599 dev_err(&port_dev->dev, "over-current condition\n"); 5590 5600 } ··· 5628 5638 u16 unused; 5629 5639 5630 5640 msleep(20); 5631 - hub_port_status(hub, port1, &portstatus, &unused); 5641 + usb_hub_port_status(hub, port1, &portstatus, &unused); 5632 5642 dev_dbg(&port_dev->dev, "Wait for inactive link disconnect detect\n"); 5633 5643 continue; 5634 5644 } else if (!udev || !(portstatus & USB_PORT_STAT_CONNECTION)
+4
drivers/usb/core/hub.h
··· 73 73 spinlock_t irq_urb_lock; 74 74 struct timer_list irq_urb_retry; 75 75 struct usb_port **ports; 76 + struct list_head onboard_hub_devs; 76 77 }; 77 78 78 79 /** ··· 122 121 bool must_be_connected); 123 122 extern int usb_clear_port_feature(struct usb_device *hdev, 124 123 int port1, int feature); 124 + extern int usb_hub_port_status(struct usb_hub *hub, int port1, 125 + u16 *status, u16 *change); 126 + extern int usb_port_is_power_on(struct usb_hub *hub, unsigned int portstatus); 125 127 126 128 static inline bool hub_is_port_power_switchable(struct usb_hub *hub) 127 129 {
+83
drivers/usb/core/port.c
··· 17 17 18 18 static const struct attribute_group *port_dev_group[]; 19 19 20 + static ssize_t disable_show(struct device *dev, 21 + struct device_attribute *attr, char *buf) 22 + { 23 + struct usb_port *port_dev = to_usb_port(dev); 24 + struct usb_device *hdev = to_usb_device(dev->parent->parent); 25 + struct usb_hub *hub = usb_hub_to_struct_hub(hdev); 26 + struct usb_interface *intf = to_usb_interface(hub->intfdev); 27 + int port1 = port_dev->portnum; 28 + u16 portstatus, unused; 29 + bool disabled; 30 + int rc; 31 + 32 + rc = usb_autopm_get_interface(intf); 33 + if (rc < 0) 34 + return rc; 35 + 36 + usb_lock_device(hdev); 37 + if (hub->disconnected) { 38 + rc = -ENODEV; 39 + goto out_hdev_lock; 40 + } 41 + 42 + usb_hub_port_status(hub, port1, &portstatus, &unused); 43 + disabled = !usb_port_is_power_on(hub, portstatus); 44 + 45 + out_hdev_lock: 46 + usb_unlock_device(hdev); 47 + usb_autopm_put_interface(intf); 48 + 49 + if (rc) 50 + return rc; 51 + 52 + return sysfs_emit(buf, "%s\n", disabled ? "1" : "0"); 53 + } 54 + 55 + static ssize_t disable_store(struct device *dev, struct device_attribute *attr, 56 + const char *buf, size_t count) 57 + { 58 + struct usb_port *port_dev = to_usb_port(dev); 59 + struct usb_device *hdev = to_usb_device(dev->parent->parent); 60 + struct usb_hub *hub = usb_hub_to_struct_hub(hdev); 61 + struct usb_interface *intf = to_usb_interface(hub->intfdev); 62 + int port1 = port_dev->portnum; 63 + bool disabled; 64 + int rc; 65 + 66 + rc = strtobool(buf, &disabled); 67 + if (rc) 68 + return rc; 69 + 70 + rc = usb_autopm_get_interface(intf); 71 + if (rc < 0) 72 + return rc; 73 + 74 + usb_lock_device(hdev); 75 + if (hub->disconnected) { 76 + rc = -ENODEV; 77 + goto out_hdev_lock; 78 + } 79 + 80 + if (disabled && port_dev->child) 81 + usb_disconnect(&port_dev->child); 82 + 83 + rc = usb_hub_set_port_power(hdev, hub, port1, !disabled); 84 + 85 + if (disabled) { 86 + usb_clear_port_feature(hdev, port1, USB_PORT_FEAT_C_CONNECTION); 87 + if (!port_dev->is_superspeed) 88 + usb_clear_port_feature(hdev, port1, USB_PORT_FEAT_C_ENABLE); 89 + } 90 + 91 + if (!rc) 92 + rc = count; 93 + 94 + out_hdev_lock: 95 + usb_unlock_device(hdev); 96 + usb_autopm_put_interface(intf); 97 + 98 + return rc; 99 + } 100 + static DEVICE_ATTR_RW(disable); 101 + 20 102 static ssize_t location_show(struct device *dev, 21 103 struct device_attribute *attr, char *buf) 22 104 { ··· 235 153 &dev_attr_location.attr, 236 154 &dev_attr_quirks.attr, 237 155 &dev_attr_over_current_count.attr, 156 + &dev_attr_disable.attr, 238 157 NULL, 239 158 }; 240 159
+40 -39
drivers/usb/core/sysfs.c
··· 35 35 return -EINTR; \ 36 36 actconfig = udev->actconfig; \ 37 37 if (actconfig) \ 38 - rc = sprintf(buf, format_string, \ 38 + rc = sysfs_emit(buf, format_string, \ 39 39 actconfig->desc.field); \ 40 40 usb_unlock_device(udev); \ 41 41 return rc; \ ··· 61 61 return -EINTR; 62 62 actconfig = udev->actconfig; 63 63 if (actconfig) 64 - rc = sprintf(buf, "%dmA\n", usb_get_max_power(udev, actconfig)); 64 + rc = sysfs_emit(buf, "%dmA\n", usb_get_max_power(udev, actconfig)); 65 65 usb_unlock_device(udev); 66 66 return rc; 67 67 } ··· 80 80 return -EINTR; 81 81 actconfig = udev->actconfig; 82 82 if (actconfig && actconfig->string) 83 - rc = sprintf(buf, "%s\n", actconfig->string); 83 + rc = sysfs_emit(buf, "%s\n", actconfig->string); 84 84 usb_unlock_device(udev); 85 85 return rc; 86 86 } ··· 114 114 { 115 115 struct device_node *of_node = dev->of_node; 116 116 117 - return sprintf(buf, "%pOF\n", of_node); 117 + return sysfs_emit(buf, "%pOF\n", of_node); 118 118 } 119 119 static DEVICE_ATTR_RO(devspec); 120 120 #endif ··· 131 131 retval = usb_lock_device_interruptible(udev); \ 132 132 if (retval < 0) \ 133 133 return -EINTR; \ 134 - retval = sprintf(buf, "%s\n", udev->name); \ 134 + retval = sysfs_emit(buf, "%s\n", udev->name); \ 135 135 usb_unlock_device(udev); \ 136 136 return retval; \ 137 137 } \ ··· 175 175 default: 176 176 speed = "unknown"; 177 177 } 178 - return sprintf(buf, "%s\n", speed); 178 + return sysfs_emit(buf, "%s\n", speed); 179 179 } 180 180 static DEVICE_ATTR_RO(speed); 181 181 ··· 185 185 struct usb_device *udev; 186 186 187 187 udev = to_usb_device(dev); 188 - return sprintf(buf, "%d\n", udev->rx_lanes); 188 + return sysfs_emit(buf, "%d\n", udev->rx_lanes); 189 189 } 190 190 static DEVICE_ATTR_RO(rx_lanes); 191 191 ··· 195 195 struct usb_device *udev; 196 196 197 197 udev = to_usb_device(dev); 198 - return sprintf(buf, "%d\n", udev->tx_lanes); 198 + return sysfs_emit(buf, "%d\n", udev->tx_lanes); 199 199 } 200 200 static DEVICE_ATTR_RO(tx_lanes); 201 201 ··· 205 205 struct usb_device *udev; 206 206 207 207 udev = to_usb_device(dev); 208 - return sprintf(buf, "%d\n", udev->bus->busnum); 208 + return sysfs_emit(buf, "%d\n", udev->bus->busnum); 209 209 } 210 210 static DEVICE_ATTR_RO(busnum); 211 211 ··· 215 215 struct usb_device *udev; 216 216 217 217 udev = to_usb_device(dev); 218 - return sprintf(buf, "%d\n", udev->devnum); 218 + return sysfs_emit(buf, "%d\n", udev->devnum); 219 219 } 220 220 static DEVICE_ATTR_RO(devnum); 221 221 ··· 225 225 struct usb_device *udev; 226 226 227 227 udev = to_usb_device(dev); 228 - return sprintf(buf, "%s\n", udev->devpath); 228 + return sysfs_emit(buf, "%s\n", udev->devpath); 229 229 } 230 230 static DEVICE_ATTR_RO(devpath); 231 231 ··· 237 237 238 238 udev = to_usb_device(dev); 239 239 bcdUSB = le16_to_cpu(udev->descriptor.bcdUSB); 240 - return sprintf(buf, "%2x.%02x\n", bcdUSB >> 8, bcdUSB & 0xff); 240 + return sysfs_emit(buf, "%2x.%02x\n", bcdUSB >> 8, bcdUSB & 0xff); 241 241 } 242 242 static DEVICE_ATTR_RO(version); 243 243 ··· 247 247 struct usb_device *udev; 248 248 249 249 udev = to_usb_device(dev); 250 - return sprintf(buf, "%d\n", udev->maxchild); 250 + return sysfs_emit(buf, "%d\n", udev->maxchild); 251 251 } 252 252 static DEVICE_ATTR_RO(maxchild); 253 253 ··· 257 257 struct usb_device *udev; 258 258 259 259 udev = to_usb_device(dev); 260 - return sprintf(buf, "0x%x\n", udev->quirks); 260 + return sysfs_emit(buf, "0x%x\n", udev->quirks); 261 261 } 262 262 static DEVICE_ATTR_RO(quirks); 263 263 ··· 267 267 struct usb_device *udev; 268 268 269 269 udev = to_usb_device(dev); 270 - return sprintf(buf, "%d\n", !!(udev->quirks & USB_QUIRK_RESET)); 270 + return sysfs_emit(buf, "%d\n", !!(udev->quirks & USB_QUIRK_RESET)); 271 271 } 272 272 273 273 static ssize_t avoid_reset_quirk_store(struct device *dev, ··· 297 297 struct usb_device *udev; 298 298 299 299 udev = to_usb_device(dev); 300 - return sprintf(buf, "%d\n", atomic_read(&udev->urbnum)); 300 + return sysfs_emit(buf, "%d\n", atomic_read(&udev->urbnum)); 301 301 } 302 302 static DEVICE_ATTR_RO(urbnum); 303 303 ··· 305 305 struct device_attribute *attr, char *buf) 306 306 { 307 307 if (usb_device_supports_ltm(to_usb_device(dev))) 308 - return sprintf(buf, "%s\n", "yes"); 309 - return sprintf(buf, "%s\n", "no"); 308 + return sysfs_emit(buf, "%s\n", "yes"); 309 + return sysfs_emit(buf, "%s\n", "no"); 310 310 } 311 311 static DEVICE_ATTR_RO(ltm_capable); 312 312 ··· 317 317 { 318 318 struct usb_device *udev = to_usb_device(dev); 319 319 320 - return sprintf(buf, "%d\n", udev->persist_enabled); 320 + return sysfs_emit(buf, "%d\n", udev->persist_enabled); 321 321 } 322 322 323 323 static ssize_t persist_store(struct device *dev, struct device_attribute *attr, ··· 372 372 { 373 373 struct usb_device *udev = to_usb_device(dev); 374 374 375 - return sprintf(buf, "%u\n", 375 + return sysfs_emit(buf, "%u\n", 376 376 jiffies_to_msecs(jiffies - udev->connect_time)); 377 377 } 378 378 static DEVICE_ATTR_RO(connected_duration); ··· 394 394 duration = jiffies_to_msecs(jiffies + udev->active_duration); 395 395 else 396 396 duration = jiffies_to_msecs(udev->active_duration); 397 - return sprintf(buf, "%u\n", duration); 397 + return sysfs_emit(buf, "%u\n", duration); 398 398 } 399 399 static DEVICE_ATTR_RO(active_duration); 400 400 401 401 static ssize_t autosuspend_show(struct device *dev, 402 402 struct device_attribute *attr, char *buf) 403 403 { 404 - return sprintf(buf, "%d\n", dev->power.autosuspend_delay / 1000); 404 + return sysfs_emit(buf, "%d\n", dev->power.autosuspend_delay / 1000); 405 405 } 406 406 407 407 static ssize_t autosuspend_store(struct device *dev, ··· 442 442 warn_level(); 443 443 if (udev->state != USB_STATE_SUSPENDED && !udev->dev.power.runtime_auto) 444 444 p = on_string; 445 - return sprintf(buf, "%s\n", p); 445 + return sysfs_emit(buf, "%s\n", p); 446 446 } 447 447 448 448 static ssize_t level_store(struct device *dev, struct device_attribute *attr, ··· 490 490 else 491 491 p = "disabled"; 492 492 493 - return sprintf(buf, "%s\n", p); 493 + return sysfs_emit(buf, "%s\n", p); 494 494 } 495 495 496 496 static ssize_t usb2_hardware_lpm_store(struct device *dev, ··· 529 529 char *buf) 530 530 { 531 531 struct usb_device *udev = to_usb_device(dev); 532 - return sprintf(buf, "%d\n", udev->l1_params.timeout); 532 + return sysfs_emit(buf, "%d\n", udev->l1_params.timeout); 533 533 } 534 534 535 535 static ssize_t usb2_lpm_l1_timeout_store(struct device *dev, ··· 552 552 struct device_attribute *attr, char *buf) 553 553 { 554 554 struct usb_device *udev = to_usb_device(dev); 555 - return sprintf(buf, "%d\n", udev->l1_params.besl); 555 + return sysfs_emit(buf, "%d\n", udev->l1_params.besl); 556 556 } 557 557 558 558 static ssize_t usb2_lpm_besl_store(struct device *dev, ··· 589 589 590 590 usb_unlock_device(udev); 591 591 592 - return sprintf(buf, "%s\n", p); 592 + return sysfs_emit(buf, "%s\n", p); 593 593 } 594 594 static DEVICE_ATTR_RO(usb3_hardware_lpm_u1); 595 595 ··· 611 611 612 612 usb_unlock_device(udev); 613 613 614 - return sprintf(buf, "%s\n", p); 614 + return sysfs_emit(buf, "%s\n", p); 615 615 } 616 616 static DEVICE_ATTR_RO(usb3_hardware_lpm_u2); 617 617 ··· 694 694 struct usb_device *udev; \ 695 695 \ 696 696 udev = to_usb_device(dev); \ 697 - return sprintf(buf, format_string, \ 697 + return sysfs_emit(buf, format_string, \ 698 698 le16_to_cpu(udev->descriptor.field)); \ 699 699 } \ 700 700 static DEVICE_ATTR_RO(field) ··· 711 711 struct usb_device *udev; \ 712 712 \ 713 713 udev = to_usb_device(dev); \ 714 - return sprintf(buf, format_string, udev->descriptor.field); \ 714 + return sysfs_emit(buf, format_string, udev->descriptor.field); \ 715 715 } \ 716 716 static DEVICE_ATTR_RO(field) 717 717 ··· 727 727 struct device_attribute *attr, char *buf) 728 728 { 729 729 struct usb_device *usb_dev = to_usb_device(dev); 730 - return snprintf(buf, PAGE_SIZE, "%u\n", usb_dev->authorized); 730 + return sysfs_emit(buf, "%u\n", usb_dev->authorized); 731 731 } 732 732 733 733 /* ··· 918 918 struct usb_hcd *hcd; 919 919 920 920 hcd = bus_to_hcd(usb_bus); 921 - return snprintf(buf, PAGE_SIZE, "%u\n", hcd->dev_policy); 921 + return sysfs_emit(buf, "%u\n", hcd->dev_policy); 922 922 } 923 923 924 924 static ssize_t authorized_default_store(struct device *dev, ··· 957 957 struct usb_device *usb_dev = to_usb_device(dev); 958 958 struct usb_hcd *hcd = bus_to_hcd(usb_dev->bus); 959 959 960 - return sprintf(buf, "%u\n", !!HCD_INTF_AUTHORIZED(hcd)); 960 + return sysfs_emit(buf, "%u\n", !!HCD_INTF_AUTHORIZED(hcd)); 961 961 } 962 962 963 963 /* ··· 1066 1066 { \ 1067 1067 struct usb_interface *intf = to_usb_interface(dev); \ 1068 1068 \ 1069 - return sprintf(buf, format_string, \ 1069 + return sysfs_emit(buf, format_string, \ 1070 1070 intf->intf_assoc->field); \ 1071 1071 } \ 1072 1072 static DEVICE_ATTR_RO(iad_##field) ··· 1085 1085 { \ 1086 1086 struct usb_interface *intf = to_usb_interface(dev); \ 1087 1087 \ 1088 - return sprintf(buf, format_string, \ 1088 + return sysfs_emit(buf, format_string, \ 1089 1089 intf->cur_altsetting->desc.field); \ 1090 1090 } \ 1091 1091 static DEVICE_ATTR_RO(field) ··· 1107 1107 string = READ_ONCE(intf->cur_altsetting->string); 1108 1108 if (!string) 1109 1109 return 0; 1110 - return sprintf(buf, "%s\n", string); 1110 + return sysfs_emit(buf, "%s\n", string); 1111 1111 } 1112 1112 static DEVICE_ATTR_RO(interface); 1113 1113 ··· 1122 1122 udev = interface_to_usbdev(intf); 1123 1123 alt = READ_ONCE(intf->cur_altsetting); 1124 1124 1125 - return sprintf(buf, "usb:v%04Xp%04Xd%04Xdc%02Xdsc%02Xdp%02X" 1125 + return sysfs_emit(buf, 1126 + "usb:v%04Xp%04Xd%04Xdc%02Xdsc%02Xdp%02X" 1126 1127 "ic%02Xisc%02Xip%02Xin%02X\n", 1127 1128 le16_to_cpu(udev->descriptor.idVendor), 1128 1129 le16_to_cpu(udev->descriptor.idProduct), ··· 1151 1150 s = (!dev->driver || to_usb_driver(dev->driver)->supports_autosuspend); 1152 1151 device_unlock(dev); 1153 1152 1154 - return sprintf(buf, "%u\n", s); 1153 + return sysfs_emit(buf, "%u\n", s); 1155 1154 } 1156 1155 static DEVICE_ATTR_RO(supports_autosuspend); 1157 1156 ··· 1164 1163 { 1165 1164 struct usb_interface *intf = to_usb_interface(dev); 1166 1165 1167 - return sprintf(buf, "%u\n", intf->authorized); 1166 + return sysfs_emit(buf, "%u\n", intf->authorized); 1168 1167 } 1169 1168 1170 1169 /*
+1 -1
drivers/usb/core/usb.c
··· 801 801 * is simple: 802 802 * 803 803 * When locking both a device and its parent, always lock the 804 - * the parent first. 804 + * parent first. 805 805 */ 806 806 807 807 /**
+2 -1
drivers/usb/dwc2/gadget.c
··· 3594 3594 void dwc2_hsotg_core_connect(struct dwc2_hsotg *hsotg) 3595 3595 { 3596 3596 /* remove the soft-disconnect and let's go */ 3597 - dwc2_clear_bit(hsotg, DCTL, DCTL_SFTDISCON); 3597 + if (!hsotg->role_sw || (dwc2_readl(hsotg, GOTGCTL) & GOTGCTL_BSESVLD)) 3598 + dwc2_clear_bit(hsotg, DCTL, DCTL_SFTDISCON); 3598 3599 } 3599 3600 3600 3601 /**
+4 -1
drivers/usb/dwc2/hcd.c
··· 52 52 53 53 #include <linux/usb/hcd.h> 54 54 #include <linux/usb/ch11.h> 55 + #include <linux/usb/of.h> 55 56 56 57 #include "core.h" 57 58 #include "hcd.h" ··· 1000 999 1001 1000 /* 1002 1001 * Try to figure out if we're an even or odd frame. If we set 1003 - * even and the current frame number is even the the transfer 1002 + * even and the current frame number is even the transfer 1004 1003 * will happen immediately. Similar if both are odd. If one is 1005 1004 * even and the other is odd then the transfer will happen when 1006 1005 * the frame number ticks. ··· 5339 5338 5340 5339 /* Don't support SG list at this point */ 5341 5340 hcd->self.sg_tablesize = 0; 5341 + 5342 + hcd->tpl_support = of_usb_host_tpl_support(hsotg->dev->of_node); 5342 5343 5343 5344 if (!IS_ERR_OR_NULL(hsotg->uphy)) 5344 5345 otg_set_host(hsotg->uphy->otg, &hcd->self);
+2 -2
drivers/usb/dwc3/Kconfig
··· 9 9 Say Y or M here if your system has a Dual Role SuperSpeed 10 10 USB controller based on the DesignWare USB3 IP Core. 11 11 12 - If you choose to build this driver is a dynamically linked 12 + If you choose to build this driver as a dynamically linked 13 13 module, the module will be called dwc3.ko. 14 14 15 15 if USB_DWC3 ··· 165 165 default USB_DWC3 166 166 help 167 167 Support TI's AM62 platforms with DesignWare Core USB3 IP. 168 - The Designware Core USB3 IP is progammed to operate in 168 + The Designware Core USB3 IP is programmed to operate in 169 169 in USB 2.0 mode only. 170 170 Say 'Y' or 'M' here if you have one such device 171 171 endif
+46 -10
drivers/usb/dwc3/core.c
··· 158 158 break; 159 159 } 160 160 161 - /* For DRD host or device mode only */ 162 - if (dwc->desired_dr_role != DWC3_GCTL_PRTCAP_OTG) { 161 + /* 162 + * When current_dr_role is not set, there's no role switching. 163 + * Only perform GCTL.CoreSoftReset when there's DRD role switching. 164 + */ 165 + if (dwc->current_dr_role && ((DWC3_IP_IS(DWC3) || 166 + DWC3_VER_IS_PRIOR(DWC31, 190A)) && 167 + dwc->desired_dr_role != DWC3_GCTL_PRTCAP_OTG)) { 163 168 reg = dwc3_readl(dwc->regs, DWC3_GCTL); 164 169 reg |= DWC3_GCTL_CORESOFTRESET; 165 170 dwc3_writel(dwc->regs, DWC3_GCTL, reg); ··· 431 426 * otherwise ERR_PTR(errno). 432 427 */ 433 428 static struct dwc3_event_buffer *dwc3_alloc_one_event_buffer(struct dwc3 *dwc, 434 - unsigned length) 429 + unsigned int length) 435 430 { 436 431 struct dwc3_event_buffer *evt; 437 432 ··· 474 469 * Returns 0 on success otherwise negative errno. In the error case, dwc 475 470 * may contain some buffers allocated but not all which were requested. 476 471 */ 477 - static int dwc3_alloc_event_buffers(struct dwc3 *dwc, unsigned length) 472 + static int dwc3_alloc_event_buffers(struct dwc3 *dwc, unsigned int length) 478 473 { 479 474 struct dwc3_event_buffer *evt; 480 475 ··· 1034 1029 dwc3_writel(dwc->regs, DWC3_GSBUSCFG0, cfg); 1035 1030 } 1036 1031 1032 + static void dwc3_set_power_down_clk_scale(struct dwc3 *dwc) 1033 + { 1034 + u32 scale; 1035 + u32 reg; 1036 + 1037 + if (!dwc->susp_clk) 1038 + return; 1039 + 1040 + /* 1041 + * The power down scale field specifies how many suspend_clk 1042 + * periods fit into a 16KHz clock period. When performing 1043 + * the division, round up the remainder. 1044 + * 1045 + * The power down scale value is calculated using the fastest 1046 + * frequency of the suspend_clk. If it isn't fixed (but within 1047 + * the accuracy requirement), the driver may not know the max 1048 + * rate of the suspend_clk, so only update the power down scale 1049 + * if the default is less than the calculated value from 1050 + * clk_get_rate() or if the default is questionably high 1051 + * (3x or more) to be within the requirement. 1052 + */ 1053 + scale = DIV_ROUND_UP(clk_get_rate(dwc->susp_clk), 16000); 1054 + reg = dwc3_readl(dwc->regs, DWC3_GCTL); 1055 + if ((reg & DWC3_GCTL_PWRDNSCALE_MASK) < DWC3_GCTL_PWRDNSCALE(scale) || 1056 + (reg & DWC3_GCTL_PWRDNSCALE_MASK) > DWC3_GCTL_PWRDNSCALE(scale*3)) { 1057 + reg &= ~(DWC3_GCTL_PWRDNSCALE_MASK); 1058 + reg |= DWC3_GCTL_PWRDNSCALE(scale); 1059 + dwc3_writel(dwc->regs, DWC3_GCTL, reg); 1060 + } 1061 + } 1062 + 1037 1063 /** 1038 1064 * dwc3_core_init - Low-level initialization of DWC3 Core 1039 1065 * @dwc: Pointer to our controller context structure ··· 1140 1104 ret = dwc3_setup_scratch_buffers(dwc); 1141 1105 if (ret) 1142 1106 goto err1; 1107 + 1108 + /* Set power down scale of suspend_clk */ 1109 + dwc3_set_power_down_clk_scale(dwc); 1143 1110 1144 1111 /* Adjust Frame Length */ 1145 1112 dwc3_frame_length_adjustment(dwc); ··· 1821 1782 1822 1783 platform_set_drvdata(pdev, dwc); 1823 1784 dwc3_cache_hwparams(dwc); 1785 + device_init_wakeup(&pdev->dev, of_property_read_bool(dev->of_node, "wakeup-source")); 1824 1786 1825 1787 spin_lock_init(&dwc->lock); 1826 1788 mutex_init(&dwc->mutex); ··· 1983 1943 dwc3_core_exit(dwc); 1984 1944 break; 1985 1945 case DWC3_GCTL_PRTCAP_HOST: 1986 - if (!PMSG_IS_AUTO(msg)) { 1946 + if (!PMSG_IS_AUTO(msg) && !device_can_wakeup(dwc->dev)) { 1987 1947 dwc3_core_exit(dwc); 1988 1948 break; 1989 1949 } ··· 2044 2004 spin_unlock_irqrestore(&dwc->lock, flags); 2045 2005 break; 2046 2006 case DWC3_GCTL_PRTCAP_HOST: 2047 - if (!PMSG_IS_AUTO(msg)) { 2007 + if (!PMSG_IS_AUTO(msg) && !device_can_wakeup(dwc->dev)) { 2048 2008 ret = dwc3_core_init_for_resume(dwc); 2049 2009 if (ret) 2050 2010 return ret; ··· 2121 2081 if (ret) 2122 2082 return ret; 2123 2083 2124 - device_init_wakeup(dev, true); 2125 - 2126 2084 return 0; 2127 2085 } 2128 2086 ··· 2128 2090 { 2129 2091 struct dwc3 *dwc = dev_get_drvdata(dev); 2130 2092 int ret; 2131 - 2132 - device_init_wakeup(dev, false); 2133 2093 2134 2094 ret = dwc3_resume_common(dwc, PMSG_AUTO_RESUME); 2135 2095 if (ret)
+3
drivers/usb/dwc3/core.h
··· 231 231 232 232 /* Global Configuration Register */ 233 233 #define DWC3_GCTL_PWRDNSCALE(n) ((n) << 19) 234 + #define DWC3_GCTL_PWRDNSCALE_MASK GENMASK(31, 19) 234 235 #define DWC3_GCTL_U2RSTECN BIT(16) 235 236 #define DWC3_GCTL_RAMCLKSEL(x) (((x) & DWC3_GCTL_CLK_MASK) << 6) 236 237 #define DWC3_GCTL_CLK_BUS (0) ··· 1087 1086 * @dis_u1_entry_quirk: set if link entering into U1 state needs to be disabled. 1088 1087 * @dis_u2_entry_quirk: set if link entering into U2 state needs to be disabled. 1089 1088 * @dis_rxdet_inp3_quirk: set if we disable Rx.Detect in P3 1089 + * @async_callbacks: if set, indicate that async callbacks will be used. 1090 + * 1090 1091 * @dis_u2_freeclk_exists_quirk : set if we clear u2_freeclk_exists 1091 1092 * in GUSB2PHYCFG, specify that USB2 PHY doesn't 1092 1093 * provide a free-running PHY clock.
+105 -45
drivers/usb/dwc3/dwc3-qcom.c
··· 17 17 #include <linux/of_platform.h> 18 18 #include <linux/platform_device.h> 19 19 #include <linux/phy/phy.h> 20 + #include <linux/pm_domain.h> 20 21 #include <linux/usb/of.h> 21 22 #include <linux/reset.h> 22 23 #include <linux/iopoll.h> 23 - 24 + #include <linux/usb/hcd.h> 25 + #include <linux/usb.h> 24 26 #include "core.h" 25 27 26 28 /* USB QSCRATCH Hardware registers */ ··· 78 76 int dp_hs_phy_irq; 79 77 int dm_hs_phy_irq; 80 78 int ss_phy_irq; 79 + enum usb_device_speed usb2_speed; 81 80 82 81 struct extcon_dev *edev; 83 82 struct extcon_dev *host_edev; ··· 299 296 icc_put(qcom->icc_path_apps); 300 297 } 301 298 299 + static enum usb_device_speed dwc3_qcom_read_usb2_speed(struct dwc3_qcom *qcom) 300 + { 301 + struct dwc3 *dwc = platform_get_drvdata(qcom->dwc3); 302 + struct usb_hcd *hcd = platform_get_drvdata(dwc->xhci); 303 + struct usb_device *udev; 304 + 305 + /* 306 + * It is possible to query the speed of all children of 307 + * USB2.0 root hub via usb_hub_for_each_child(). DWC3 code 308 + * currently supports only 1 port per controller. So 309 + * this is sufficient. 310 + */ 311 + udev = usb_hub_find_child(hcd->self.root_hub, 1); 312 + 313 + if (!udev) 314 + return USB_SPEED_UNKNOWN; 315 + 316 + return udev->speed; 317 + } 318 + 319 + static void dwc3_qcom_enable_wakeup_irq(int irq, unsigned int polarity) 320 + { 321 + if (!irq) 322 + return; 323 + 324 + if (polarity) 325 + irq_set_irq_type(irq, polarity); 326 + 327 + enable_irq(irq); 328 + enable_irq_wake(irq); 329 + } 330 + 331 + static void dwc3_qcom_disable_wakeup_irq(int irq) 332 + { 333 + if (!irq) 334 + return; 335 + 336 + disable_irq_wake(irq); 337 + disable_irq_nosync(irq); 338 + } 339 + 302 340 static void dwc3_qcom_disable_interrupts(struct dwc3_qcom *qcom) 303 341 { 304 - if (qcom->hs_phy_irq) { 305 - disable_irq_wake(qcom->hs_phy_irq); 306 - disable_irq_nosync(qcom->hs_phy_irq); 342 + dwc3_qcom_disable_wakeup_irq(qcom->hs_phy_irq); 343 + 344 + if (qcom->usb2_speed == USB_SPEED_LOW) { 345 + dwc3_qcom_disable_wakeup_irq(qcom->dm_hs_phy_irq); 346 + } else if ((qcom->usb2_speed == USB_SPEED_HIGH) || 347 + (qcom->usb2_speed == USB_SPEED_FULL)) { 348 + dwc3_qcom_disable_wakeup_irq(qcom->dp_hs_phy_irq); 349 + } else { 350 + dwc3_qcom_disable_wakeup_irq(qcom->dp_hs_phy_irq); 351 + dwc3_qcom_disable_wakeup_irq(qcom->dm_hs_phy_irq); 307 352 } 308 353 309 - if (qcom->dp_hs_phy_irq) { 310 - disable_irq_wake(qcom->dp_hs_phy_irq); 311 - disable_irq_nosync(qcom->dp_hs_phy_irq); 312 - } 313 - 314 - if (qcom->dm_hs_phy_irq) { 315 - disable_irq_wake(qcom->dm_hs_phy_irq); 316 - disable_irq_nosync(qcom->dm_hs_phy_irq); 317 - } 318 - 319 - if (qcom->ss_phy_irq) { 320 - disable_irq_wake(qcom->ss_phy_irq); 321 - disable_irq_nosync(qcom->ss_phy_irq); 322 - } 354 + dwc3_qcom_disable_wakeup_irq(qcom->ss_phy_irq); 323 355 } 324 356 325 357 static void dwc3_qcom_enable_interrupts(struct dwc3_qcom *qcom) 326 358 { 327 - if (qcom->hs_phy_irq) { 328 - enable_irq(qcom->hs_phy_irq); 329 - enable_irq_wake(qcom->hs_phy_irq); 359 + dwc3_qcom_enable_wakeup_irq(qcom->hs_phy_irq, 0); 360 + 361 + /* 362 + * Configure DP/DM line interrupts based on the USB2 device attached to 363 + * the root hub port. When HS/FS device is connected, configure the DP line 364 + * as falling edge to detect both disconnect and remote wakeup scenarios. When 365 + * LS device is connected, configure DM line as falling edge to detect both 366 + * disconnect and remote wakeup. When no device is connected, configure both 367 + * DP and DM lines as rising edge to detect HS/HS/LS device connect scenario. 368 + */ 369 + 370 + if (qcom->usb2_speed == USB_SPEED_LOW) { 371 + dwc3_qcom_enable_wakeup_irq(qcom->dm_hs_phy_irq, 372 + IRQ_TYPE_EDGE_FALLING); 373 + } else if ((qcom->usb2_speed == USB_SPEED_HIGH) || 374 + (qcom->usb2_speed == USB_SPEED_FULL)) { 375 + dwc3_qcom_enable_wakeup_irq(qcom->dp_hs_phy_irq, 376 + IRQ_TYPE_EDGE_FALLING); 377 + } else { 378 + dwc3_qcom_enable_wakeup_irq(qcom->dp_hs_phy_irq, 379 + IRQ_TYPE_EDGE_RISING); 380 + dwc3_qcom_enable_wakeup_irq(qcom->dm_hs_phy_irq, 381 + IRQ_TYPE_EDGE_RISING); 330 382 } 331 383 332 - if (qcom->dp_hs_phy_irq) { 333 - enable_irq(qcom->dp_hs_phy_irq); 334 - enable_irq_wake(qcom->dp_hs_phy_irq); 335 - } 336 - 337 - if (qcom->dm_hs_phy_irq) { 338 - enable_irq(qcom->dm_hs_phy_irq); 339 - enable_irq_wake(qcom->dm_hs_phy_irq); 340 - } 341 - 342 - if (qcom->ss_phy_irq) { 343 - enable_irq(qcom->ss_phy_irq); 344 - enable_irq_wake(qcom->ss_phy_irq); 345 - } 384 + dwc3_qcom_enable_wakeup_irq(qcom->ss_phy_irq, 0); 346 385 } 347 386 348 387 static int dwc3_qcom_suspend(struct dwc3_qcom *qcom) ··· 406 361 if (ret) 407 362 dev_warn(qcom->dev, "failed to disable interconnect: %d\n", ret); 408 363 409 - if (device_may_wakeup(qcom->dev)) 364 + if (device_may_wakeup(qcom->dev)) { 365 + qcom->usb2_speed = dwc3_qcom_read_usb2_speed(qcom); 410 366 dwc3_qcom_enable_interrupts(qcom); 367 + } 411 368 412 369 qcom->is_suspended = true; 413 370 ··· 490 443 int ret; 491 444 492 445 if (np) 493 - ret = platform_get_irq_byname(pdev_irq, name); 446 + ret = platform_get_irq_byname_optional(pdev_irq, name); 494 447 else 495 - ret = platform_get_irq(pdev_irq, num); 448 + ret = platform_get_irq_optional(pdev_irq, num); 496 449 497 450 return ret; 498 451 } ··· 757 710 758 711 static int dwc3_qcom_probe(struct platform_device *pdev) 759 712 { 760 - struct device_node *np = pdev->dev.of_node; 761 - struct device *dev = &pdev->dev; 762 - struct dwc3_qcom *qcom; 763 - struct resource *res, *parent_res = NULL; 764 - int ret, i; 765 - bool ignore_pipe_clk; 713 + struct device_node *np = pdev->dev.of_node; 714 + struct device *dev = &pdev->dev; 715 + struct dwc3_qcom *qcom; 716 + struct resource *res, *parent_res = NULL; 717 + int ret, i; 718 + bool ignore_pipe_clk; 719 + struct generic_pm_domain *genpd; 766 720 767 721 qcom = devm_kzalloc(&pdev->dev, sizeof(*qcom), GFP_KERNEL); 768 722 if (!qcom) ··· 771 723 772 724 platform_set_drvdata(pdev, qcom); 773 725 qcom->dev = &pdev->dev; 726 + 727 + genpd = pd_to_genpd(qcom->dev->pm_domain); 774 728 775 729 if (has_acpi_companion(dev)) { 776 730 qcom->acpi_pdata = acpi_device_get_match_data(dev); ··· 881 831 if (ret) 882 832 goto interconnect_exit; 883 833 884 - device_init_wakeup(&pdev->dev, 1); 834 + if (device_can_wakeup(&qcom->dwc3->dev)) { 835 + /* 836 + * Setting GENPD_FLAG_ALWAYS_ON flag takes care of keeping 837 + * genpd on in both runtime suspend and system suspend cases. 838 + */ 839 + genpd->flags |= GENPD_FLAG_ALWAYS_ON; 840 + device_init_wakeup(&pdev->dev, true); 841 + } else { 842 + genpd->flags |= GENPD_FLAG_RPM_ALWAYS_ON; 843 + } 844 + 885 845 qcom->is_suspended = false; 886 846 pm_runtime_set_active(dev); 887 847 pm_runtime_enable(dev);
+8 -1
drivers/usb/dwc3/ep0.c
··· 239 239 dwc3_gadget_giveback(dep, req, -ECONNRESET); 240 240 } 241 241 242 + dwc->eps[0]->trb_enqueue = 0; 243 + dwc->eps[1]->trb_enqueue = 0; 242 244 dwc->ep0state = EP0_SETUP_PHASE; 243 245 dwc3_ep0_out_start(dwc); 244 246 } ··· 475 473 case USB_DEVICE_REMOTE_WAKEUP: 476 474 break; 477 475 /* 478 - * 9.4.1 says only only for SS, in AddressState only for 476 + * 9.4.1 says only for SS, in AddressState only for 479 477 * default control pipe 480 478 */ 481 479 case USB_DEVICE_U1_ENABLE: ··· 1141 1139 case DEPEVT_STATUS_CONTROL_STATUS: 1142 1140 if (dwc->ep0_next_event != DWC3_EP0_NRDY_STATUS) 1143 1141 return; 1142 + 1143 + if (dwc->setup_packet_pending) { 1144 + dwc3_ep0_stall_and_restart(dwc); 1145 + return; 1146 + } 1144 1147 1145 1148 dwc->ep0state = EP0_STATUS_PHASE; 1146 1149
+41 -52
drivers/usb/dwc3/gadget.c
··· 657 657 /** 658 658 * dwc3_gadget_calc_tx_fifo_size - calculates the txfifo size value 659 659 * @dwc: pointer to the DWC3 context 660 + * @mult: multiplier to be used when calculating the fifo_size 660 661 * 661 662 * Calculates the size value based on the equation below: 662 663 * ··· 1183 1182 return trbs_left; 1184 1183 } 1185 1184 1186 - static void __dwc3_prepare_one_trb(struct dwc3_ep *dep, struct dwc3_trb *trb, 1187 - dma_addr_t dma, unsigned int length, unsigned int chain, 1188 - unsigned int node, unsigned int stream_id, 1189 - unsigned int short_not_ok, unsigned int no_interrupt, 1190 - unsigned int is_last, bool must_interrupt) 1185 + /** 1186 + * dwc3_prepare_one_trb - setup one TRB from one request 1187 + * @dep: endpoint for which this request is prepared 1188 + * @req: dwc3_request pointer 1189 + * @trb_length: buffer size of the TRB 1190 + * @chain: should this TRB be chained to the next? 1191 + * @node: only for isochronous endpoints. First TRB needs different type. 1192 + * @use_bounce_buffer: set to use bounce buffer 1193 + * @must_interrupt: set to interrupt on TRB completion 1194 + */ 1195 + static void dwc3_prepare_one_trb(struct dwc3_ep *dep, 1196 + struct dwc3_request *req, unsigned int trb_length, 1197 + unsigned int chain, unsigned int node, bool use_bounce_buffer, 1198 + bool must_interrupt) 1191 1199 { 1200 + struct dwc3_trb *trb; 1201 + dma_addr_t dma; 1202 + unsigned int stream_id = req->request.stream_id; 1203 + unsigned int short_not_ok = req->request.short_not_ok; 1204 + unsigned int no_interrupt = req->request.no_interrupt; 1205 + unsigned int is_last = req->request.is_last; 1192 1206 struct dwc3 *dwc = dep->dwc; 1193 1207 struct usb_gadget *gadget = dwc->gadget; 1194 1208 enum usb_device_speed speed = gadget->speed; 1195 1209 1196 - trb->size = DWC3_TRB_SIZE_LENGTH(length); 1210 + if (use_bounce_buffer) 1211 + dma = dep->dwc->bounce_addr; 1212 + else if (req->request.num_sgs > 0) 1213 + dma = sg_dma_address(req->start_sg); 1214 + else 1215 + dma = req->request.dma; 1216 + 1217 + trb = &dep->trb_pool[dep->trb_enqueue]; 1218 + 1219 + if (!req->trb) { 1220 + dwc3_gadget_move_started_request(req); 1221 + req->trb = trb; 1222 + req->trb_dma = dwc3_trb_dma_offset(dep, trb); 1223 + } 1224 + 1225 + req->num_trbs++; 1226 + 1227 + trb->size = DWC3_TRB_SIZE_LENGTH(trb_length); 1197 1228 trb->bpl = lower_32_bits(dma); 1198 1229 trb->bph = upper_32_bits(dma); 1199 1230 ··· 1265 1232 unsigned int mult = 2; 1266 1233 unsigned int maxp = usb_endpoint_maxp(ep->desc); 1267 1234 1268 - if (length <= (2 * maxp)) 1235 + if (req->request.length <= (2 * maxp)) 1269 1236 mult--; 1270 1237 1271 - if (length <= maxp) 1238 + if (req->request.length <= maxp) 1272 1239 mult--; 1273 1240 1274 1241 trb->size |= DWC3_TRB_SIZE_PCM1(mult); ··· 1340 1307 dwc3_ep_inc_enq(dep); 1341 1308 1342 1309 trace_dwc3_prepare_trb(dep, trb); 1343 - } 1344 - 1345 - /** 1346 - * dwc3_prepare_one_trb - setup one TRB from one request 1347 - * @dep: endpoint for which this request is prepared 1348 - * @req: dwc3_request pointer 1349 - * @trb_length: buffer size of the TRB 1350 - * @chain: should this TRB be chained to the next? 1351 - * @node: only for isochronous endpoints. First TRB needs different type. 1352 - * @use_bounce_buffer: set to use bounce buffer 1353 - * @must_interrupt: set to interrupt on TRB completion 1354 - */ 1355 - static void dwc3_prepare_one_trb(struct dwc3_ep *dep, 1356 - struct dwc3_request *req, unsigned int trb_length, 1357 - unsigned int chain, unsigned int node, bool use_bounce_buffer, 1358 - bool must_interrupt) 1359 - { 1360 - struct dwc3_trb *trb; 1361 - dma_addr_t dma; 1362 - unsigned int stream_id = req->request.stream_id; 1363 - unsigned int short_not_ok = req->request.short_not_ok; 1364 - unsigned int no_interrupt = req->request.no_interrupt; 1365 - unsigned int is_last = req->request.is_last; 1366 - 1367 - if (use_bounce_buffer) 1368 - dma = dep->dwc->bounce_addr; 1369 - else if (req->request.num_sgs > 0) 1370 - dma = sg_dma_address(req->start_sg); 1371 - else 1372 - dma = req->request.dma; 1373 - 1374 - trb = &dep->trb_pool[dep->trb_enqueue]; 1375 - 1376 - if (!req->trb) { 1377 - dwc3_gadget_move_started_request(req); 1378 - req->trb = trb; 1379 - req->trb_dma = dwc3_trb_dma_offset(dep, trb); 1380 - } 1381 - 1382 - req->num_trbs++; 1383 - 1384 - __dwc3_prepare_one_trb(dep, trb, dma, trb_length, chain, node, 1385 - stream_id, short_not_ok, no_interrupt, is_last, 1386 - must_interrupt); 1387 1310 } 1388 1311 1389 1312 static bool dwc3_needs_extra_trb(struct dwc3_ep *dep, struct dwc3_request *req)
+5 -15
drivers/usb/gadget/function/f_acm.c
··· 57 57 58 58 /* SetControlLineState request -- CDC 1.1 section 6.2.14 (INPUT) */ 59 59 u16 port_handshake_bits; 60 - #define ACM_CTRL_RTS (1 << 1) /* unused with full duplex */ 61 - #define ACM_CTRL_DTR (1 << 0) /* host is ready for data r/w */ 62 - 63 60 /* SerialState notification -- CDC 1.1 section 6.3.5 (OUTPUT) */ 64 61 u16 serial_state; 65 - #define ACM_CTRL_OVERRUN (1 << 6) 66 - #define ACM_CTRL_PARITY (1 << 5) 67 - #define ACM_CTRL_FRAMING (1 << 4) 68 - #define ACM_CTRL_RI (1 << 3) 69 - #define ACM_CTRL_BRK (1 << 2) 70 - #define ACM_CTRL_DSR (1 << 1) 71 - #define ACM_CTRL_DCD (1 << 0) 72 62 }; 73 63 74 64 static inline struct f_acm *func_to_acm(struct usb_function *f) ··· 377 387 value = 0; 378 388 379 389 /* FIXME we should not allow data to flow until the 380 - * host sets the ACM_CTRL_DTR bit; and when it clears 390 + * host sets the USB_CDC_CTRL_DTR bit; and when it clears 381 391 * that bit, we should return to that no-flow state. 382 392 */ 383 393 acm->port_handshake_bits = w_value; ··· 575 585 { 576 586 struct f_acm *acm = port_to_acm(port); 577 587 578 - acm->serial_state |= ACM_CTRL_DSR | ACM_CTRL_DCD; 588 + acm->serial_state |= USB_CDC_SERIAL_STATE_DSR | USB_CDC_SERIAL_STATE_DCD; 579 589 acm_notify_serial_state(acm); 580 590 } 581 591 ··· 583 593 { 584 594 struct f_acm *acm = port_to_acm(port); 585 595 586 - acm->serial_state &= ~(ACM_CTRL_DSR | ACM_CTRL_DCD); 596 + acm->serial_state &= ~(USB_CDC_SERIAL_STATE_DSR | USB_CDC_SERIAL_STATE_DCD); 587 597 acm_notify_serial_state(acm); 588 598 } 589 599 ··· 593 603 u16 state; 594 604 595 605 state = acm->serial_state; 596 - state &= ~ACM_CTRL_BRK; 606 + state &= ~USB_CDC_SERIAL_STATE_BREAK; 597 607 if (duration) 598 - state |= ACM_CTRL_BRK; 608 + state |= USB_CDC_SERIAL_STATE_BREAK; 599 609 600 610 acm->serial_state = state; 601 611 return acm_notify_serial_state(acm);
+31 -5
drivers/usb/gadget/function/f_mass_storage.c
··· 1192 1192 u8 format; 1193 1193 int i, len; 1194 1194 1195 + format = common->cmnd[2] & 0xf; 1196 + 1195 1197 if ((common->cmnd[1] & ~0x02) != 0 || /* Mask away MSF */ 1196 - start_track > 1) { 1198 + (start_track > 1 && format != 0x1)) { 1197 1199 curlun->sense_data = SS_INVALID_FIELD_IN_CDB; 1198 1200 return -EINVAL; 1199 1201 } 1200 1202 1201 - format = common->cmnd[2] & 0xf; 1202 1203 /* 1203 1204 * Check if CDB is old style SFF-8020i 1204 1205 * i.e. format is in 2 MSBs of byte 9 ··· 1209 1208 format = (common->cmnd[9] >> 6) & 0x3; 1210 1209 1211 1210 switch (format) { 1212 - case 0: 1213 - /* Formatted TOC */ 1211 + case 0: /* Formatted TOC */ 1212 + case 1: /* Multi-session info */ 1214 1213 len = 4 + 2*8; /* 4 byte header + 2 descriptors */ 1215 1214 memset(buf, 0, len); 1216 1215 buf[1] = len - 2; /* TOC Length excludes length field */ ··· 1251 1250 return len; 1252 1251 1253 1252 default: 1254 - /* Multi-session, PMA, ATIP, CD-TEXT not supported/required */ 1253 + /* PMA, ATIP, CD-TEXT not supported/required */ 1255 1254 curlun->sense_data = SS_INVALID_FIELD_IN_CDB; 1256 1255 return -EINVAL; 1257 1256 } ··· 2651 2650 return fsg_store_file(curlun, filesem, buf, count); 2652 2651 } 2653 2652 2653 + static ssize_t forced_eject_store(struct device *dev, 2654 + struct device_attribute *attr, 2655 + const char *buf, size_t count) 2656 + { 2657 + struct fsg_lun *curlun = fsg_lun_from_dev(dev); 2658 + struct rw_semaphore *filesem = dev_get_drvdata(dev); 2659 + 2660 + return fsg_store_forced_eject(curlun, filesem, buf, count); 2661 + } 2662 + 2654 2663 static DEVICE_ATTR_RW(nofua); 2655 2664 /* mode wil be set in fsg_lun_attr_is_visible() */ 2656 2665 static DEVICE_ATTR(ro, 0, ro_show, ro_store); 2657 2666 static DEVICE_ATTR(file, 0, file_show, file_store); 2667 + static DEVICE_ATTR_WO(forced_eject); 2658 2668 2659 2669 /****************************** FSG COMMON ******************************/ 2660 2670 ··· 2819 2807 &dev_attr_ro.attr, 2820 2808 &dev_attr_file.attr, 2821 2809 &dev_attr_nofua.attr, 2810 + &dev_attr_forced_eject.attr, 2822 2811 NULL 2823 2812 }; 2824 2813 ··· 3233 3220 3234 3221 CONFIGFS_ATTR(fsg_lun_opts_, inquiry_string); 3235 3222 3223 + static ssize_t fsg_lun_opts_forced_eject_store(struct config_item *item, 3224 + const char *page, size_t len) 3225 + { 3226 + struct fsg_lun_opts *opts = to_fsg_lun_opts(item); 3227 + struct fsg_opts *fsg_opts = to_fsg_opts(opts->group.cg_item.ci_parent); 3228 + 3229 + return fsg_store_forced_eject(opts->lun, &fsg_opts->common->filesem, 3230 + page, len); 3231 + } 3232 + 3233 + CONFIGFS_ATTR_WO(fsg_lun_opts_, forced_eject); 3234 + 3236 3235 static struct configfs_attribute *fsg_lun_attrs[] = { 3237 3236 &fsg_lun_opts_attr_file, 3238 3237 &fsg_lun_opts_attr_ro, ··· 3252 3227 &fsg_lun_opts_attr_cdrom, 3253 3228 &fsg_lun_opts_attr_nofua, 3254 3229 &fsg_lun_opts_attr_inquiry_string, 3230 + &fsg_lun_opts_attr_forced_eject, 3255 3231 NULL, 3256 3232 }; 3257 3233
+19 -11
drivers/usb/gadget/function/f_uvc.c
··· 141 141 .bEndpointAddress = USB_DIR_IN, 142 142 .bmAttributes = USB_ENDPOINT_SYNC_ASYNC 143 143 | USB_ENDPOINT_XFER_ISOC, 144 - /* The wMaxPacketSize and bInterval values will be initialized from 144 + /* 145 + * The wMaxPacketSize and bInterval values will be initialized from 145 146 * module parameters. 146 147 */ 147 148 }; ··· 153 152 .bEndpointAddress = USB_DIR_IN, 154 153 .bmAttributes = USB_ENDPOINT_SYNC_ASYNC 155 154 | USB_ENDPOINT_XFER_ISOC, 156 - /* The wMaxPacketSize and bInterval values will be initialized from 155 + /* 156 + * The wMaxPacketSize and bInterval values will be initialized from 157 157 * module parameters. 158 158 */ 159 159 }; ··· 166 164 .bEndpointAddress = USB_DIR_IN, 167 165 .bmAttributes = USB_ENDPOINT_SYNC_ASYNC 168 166 | USB_ENDPOINT_XFER_ISOC, 169 - /* The wMaxPacketSize and bInterval values will be initialized from 167 + /* 168 + * The wMaxPacketSize and bInterval values will be initialized from 170 169 * module parameters. 171 170 */ 172 171 }; ··· 175 172 static struct usb_ss_ep_comp_descriptor uvc_ss_streaming_comp = { 176 173 .bLength = sizeof(uvc_ss_streaming_comp), 177 174 .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, 178 - /* The bMaxBurst, bmAttributes and wBytesPerInterval values will be 175 + /* 176 + * The bMaxBurst, bmAttributes and wBytesPerInterval values will be 179 177 * initialized from module parameters. 180 178 */ 181 179 }; ··· 238 234 if (le16_to_cpu(ctrl->wLength) > UVC_MAX_REQUEST_SIZE) 239 235 return -EINVAL; 240 236 241 - /* Tell the complete callback to generate an event for the next request 237 + /* 238 + * Tell the complete callback to generate an event for the next request 242 239 * that will be enqueued by UVCIOC_SEND_RESPONSE. 243 240 */ 244 241 uvc->event_setup_out = !(ctrl->bRequestType & USB_DIR_IN); ··· 505 500 if (!uvc_control_desc || !uvc_streaming_cls) 506 501 return ERR_PTR(-ENODEV); 507 502 508 - /* Descriptors layout 503 + /* 504 + * Descriptors layout 509 505 * 510 506 * uvc_iad 511 507 * uvc_control_intf ··· 603 597 uvcg_info(f, "%s()\n", __func__); 604 598 605 599 opts = fi_to_f_uvc_opts(f->fi); 606 - /* Sanity check the streaming endpoint module parameters. 607 - */ 600 + /* Sanity check the streaming endpoint module parameters. */ 608 601 opts->streaming_interval = clamp(opts->streaming_interval, 1U, 16U); 609 602 opts->streaming_maxpacket = clamp(opts->streaming_maxpacket, 1U, 3072U); 610 603 opts->streaming_maxburst = min(opts->streaming_maxburst, 15U); ··· 616 611 opts->streaming_maxpacket); 617 612 } 618 613 619 - /* Fill in the FS/HS/SS Video Streaming specific descriptors from the 614 + /* 615 + * Fill in the FS/HS/SS Video Streaming specific descriptors from the 620 616 * module parameters. 621 617 * 622 618 * NOTE: We assume that the user knows what they are doing and won't ··· 901 895 902 896 uvcg_info(f, "%s()\n", __func__); 903 897 904 - /* If we know we're connected via v4l2, then there should be a cleanup 898 + /* 899 + * If we know we're connected via v4l2, then there should be a cleanup 905 900 * of the device from userspace either via UVC_EVENT_DISCONNECT or 906 901 * though the video device removal uevent. Allow some time for the 907 902 * application to close out before things get deleted. ··· 919 912 v4l2_device_unregister(&uvc->v4l2_dev); 920 913 921 914 if (uvc->func_connected) { 922 - /* Wait for the release to occur to ensure there are no longer any 915 + /* 916 + * Wait for the release to occur to ensure there are no longer any 923 917 * pending operations that may cause panics when resources are cleaned 924 918 * up. 925 919 */
+15
drivers/usb/gadget/function/storage_common.c
··· 519 519 } 520 520 EXPORT_SYMBOL_GPL(fsg_store_inquiry_string); 521 521 522 + ssize_t fsg_store_forced_eject(struct fsg_lun *curlun, struct rw_semaphore *filesem, 523 + const char *buf, size_t count) 524 + { 525 + int ret; 526 + 527 + /* 528 + * Forcibly detach the backing file from the LUN 529 + * regardless of whether the host has allowed it. 530 + */ 531 + curlun->prevent_medium_removal = 0; 532 + ret = fsg_store_file(curlun, filesem, "", 0); 533 + return ret < 0 ? ret : count; 534 + } 535 + EXPORT_SYMBOL_GPL(fsg_store_forced_eject); 536 + 522 537 MODULE_LICENSE("GPL");
+2
drivers/usb/gadget/function/storage_common.h
··· 219 219 size_t count); 220 220 ssize_t fsg_store_inquiry_string(struct fsg_lun *curlun, const char *buf, 221 221 size_t count); 222 + ssize_t fsg_store_forced_eject(struct fsg_lun *curlun, struct rw_semaphore *filesem, 223 + const char *buf, size_t count); 222 224 223 225 #endif /* USB_STORAGE_COMMON_H */
-1
drivers/usb/gadget/function/u_ether.c
··· 17 17 #include <linux/etherdevice.h> 18 18 #include <linux/ethtool.h> 19 19 #include <linux/if_vlan.h> 20 - #include <linux/etherdevice.h> 21 20 22 21 #include "u_ether.h" 23 22
+16 -7
drivers/usb/gadget/function/uvc_queue.c
··· 44 44 { 45 45 struct uvc_video_queue *queue = vb2_get_drv_priv(vq); 46 46 struct uvc_video *video = container_of(queue, struct uvc_video, queue); 47 - struct usb_composite_dev *cdev = video->uvc->func.config->cdev; 47 + unsigned int req_size; 48 + unsigned int nreq; 48 49 49 50 if (*nbuffers > UVC_MAX_VIDEO_BUFFERS) 50 51 *nbuffers = UVC_MAX_VIDEO_BUFFERS; ··· 54 53 55 54 sizes[0] = video->imagesize; 56 55 57 - if (cdev->gadget->speed < USB_SPEED_SUPER) 58 - video->uvc_num_requests = 4; 59 - else 60 - video->uvc_num_requests = 64; 56 + req_size = video->ep->maxpacket 57 + * max_t(unsigned int, video->ep->maxburst, 1) 58 + * (video->ep->mult); 59 + 60 + /* We divide by two, to increase the chance to run 61 + * into fewer requests for smaller framesizes. 62 + */ 63 + nreq = DIV_ROUND_UP(DIV_ROUND_UP(sizes[0], 2), req_size); 64 + nreq = clamp(nreq, 4U, 64U); 65 + video->uvc_num_requests = nreq; 61 66 62 67 return 0; 63 68 } ··· 111 104 if (likely(!(queue->flags & UVC_QUEUE_DISCONNECTED))) { 112 105 list_add_tail(&buf->queue, &queue->irqqueue); 113 106 } else { 114 - /* If the device is disconnected return the buffer to userspace 107 + /* 108 + * If the device is disconnected return the buffer to userspace 115 109 * directly. The next QBUF call will fail with -ENODEV. 116 110 */ 117 111 buf->state = UVC_BUF_STATE_ERROR; ··· 263 255 } 264 256 queue->buf_used = 0; 265 257 266 - /* This must be protected by the irqlock spinlock to avoid race 258 + /* 259 + * This must be protected by the irqlock spinlock to avoid race 267 260 * conditions between uvc_queue_buffer and the disconnection event that 268 261 * could result in an interruptible wait in uvc_dequeue_buffer. Do not 269 262 * blindly replace this logic by checking for the UVC_DEV_DISCONNECTED
+9 -5
drivers/usb/gadget/function/uvc_video.c
··· 261 261 break; 262 262 263 263 default: 264 - uvcg_info(&video->uvc->func, 264 + uvcg_warn(&video->uvc->func, 265 265 "VS request completed with status %d.\n", 266 266 req->status); 267 267 uvcg_queue_cancel(queue, 0); ··· 378 378 int ret; 379 379 380 380 while (video->ep->enabled) { 381 - /* Retrieve the first available USB request, protected by the 381 + /* 382 + * Retrieve the first available USB request, protected by the 382 383 * request lock. 383 384 */ 384 385 spin_lock_irqsave(&video->req_lock, flags); ··· 392 391 list_del(&req->list); 393 392 spin_unlock_irqrestore(&video->req_lock, flags); 394 393 395 - /* Retrieve the first available video buffer and fill the 394 + /* 395 + * Retrieve the first available video buffer and fill the 396 396 * request, protected by the video queue irqlock. 397 397 */ 398 398 spin_lock_irqsave(&queue->irqlock, flags); ··· 405 403 406 404 video->encode(req, video, buf); 407 405 408 - /* With usb3 we have more requests. This will decrease the 406 + /* 407 + * With usb3 we have more requests. This will decrease the 409 408 * interrupt load to a quarter but also catches the corner 410 - * cases, which needs to be handled */ 409 + * cases, which needs to be handled. 410 + */ 411 411 if (list_empty(&video->req_free) || 412 412 buf->state == UVC_BUF_STATE_DONE || 413 413 !(video->req_int_count %
+1
drivers/usb/gadget/legacy/inode.c
··· 362 362 spin_unlock_irq (&epdata->dev->lock); 363 363 364 364 DBG (epdata->dev, "endpoint gone\n"); 365 + wait_for_completion(&done); 365 366 epdata->status = -ENODEV; 366 367 } 367 368 }
+14 -1
drivers/usb/gadget/udc/Kconfig
··· 311 311 312 312 config USB_AMD5536UDC 313 313 tristate "AMD5536 UDC" 314 - depends on USB_PCI 314 + depends on USB_PCI && HAS_DMA 315 315 select USB_SNP_CORE 316 316 help 317 317 The AMD5536 UDC is part of the AMD Geode CS5536, an x86 southbridge. ··· 462 462 Say "y" to link the driver statically, or "m" to build a 463 463 dynamically linked module called "tegra_xudc" and force all 464 464 gadget drivers to also be dynamically linked. 465 + 466 + config USB_ASPEED_UDC 467 + tristate "Aspeed UDC driver support" 468 + depends on ARCH_ASPEED || COMPILE_TEST 469 + depends on USB_LIBCOMPOSITE 470 + help 471 + Enables Aspeed USB2.0 Device Controller driver for AST260x 472 + family SoCs. The controller supports 1 control endpoint and 473 + 4 programmable endpoints. 474 + 475 + Say "y" to link the driver statically, or "m" to build a 476 + dynamically linked module called "aspeed_udc" and force all 477 + gadget drivers to also be dynamically linked. 465 478 466 479 source "drivers/usb/gadget/udc/aspeed-vhub/Kconfig" 467 480
+1
drivers/usb/gadget/udc/Makefile
··· 40 40 obj-$(CONFIG_USB_GADGET_XILINX) += udc-xilinx.o 41 41 obj-$(CONFIG_USB_SNP_UDC_PLAT) += snps_udc_plat.o 42 42 obj-$(CONFIG_USB_ASPEED_VHUB) += aspeed-vhub/ 43 + obj-$(CONFIG_USB_ASPEED_UDC) += aspeed_udc.o 43 44 obj-$(CONFIG_USB_BDC_UDC) += bdc/ 44 45 obj-$(CONFIG_USB_MAX3420_UDC) += max3420_udc.o
+3 -1
drivers/usb/gadget/udc/aspeed-vhub/hub.c
··· 1059 1059 /* Initialize vhub String Descriptors. */ 1060 1060 INIT_LIST_HEAD(&vhub->vhub_str_desc); 1061 1061 desc_np = of_get_child_by_name(vhub_np, "vhub-strings"); 1062 - if (desc_np) 1062 + if (desc_np) { 1063 1063 ret = ast_vhub_of_parse_str_desc(vhub, desc_np); 1064 + of_node_put(desc_np); 1065 + } 1064 1066 else 1065 1067 ret = ast_vhub_str_alloc_add(vhub, &ast_vhub_strings); 1066 1068
+1597
drivers/usb/gadget/udc/aspeed_udc.c
··· 1 + // SPDX-License-Identifier: GPL-2.0+ 2 + /* 3 + * Copyright (c) 2021 Aspeed Technology Inc. 4 + */ 5 + 6 + #include <linux/clk.h> 7 + #include <linux/delay.h> 8 + #include <linux/dma-mapping.h> 9 + #include <linux/interrupt.h> 10 + #include <linux/kernel.h> 11 + #include <linux/module.h> 12 + #include <linux/of.h> 13 + #include <linux/platform_device.h> 14 + #include <linux/prefetch.h> 15 + #include <linux/usb/ch9.h> 16 + #include <linux/usb/gadget.h> 17 + #include <linux/slab.h> 18 + 19 + #define AST_UDC_NUM_ENDPOINTS (1 + 4) 20 + #define AST_UDC_EP0_MAX_PACKET 64 /* EP0's max packet size */ 21 + #define AST_UDC_EPn_MAX_PACKET 1024 /* Generic EPs max packet size */ 22 + #define AST_UDC_DESCS_COUNT 256 /* Use 256 stages descriptor mode (32/256) */ 23 + #define AST_UDC_DESC_MODE 1 /* Single/Multiple Stage(s) Descriptor Mode */ 24 + 25 + #define AST_UDC_EP_DMA_SIZE (AST_UDC_EPn_MAX_PACKET + 8 * AST_UDC_DESCS_COUNT) 26 + 27 + /***************************** 28 + * * 29 + * UDC register definitions * 30 + * * 31 + *****************************/ 32 + 33 + #define AST_UDC_FUNC_CTRL 0x00 /* Root Function Control & Status Register */ 34 + #define AST_UDC_CONFIG 0x04 /* Root Configuration Setting Register */ 35 + #define AST_UDC_IER 0x08 /* Interrupt Control Register */ 36 + #define AST_UDC_ISR 0x0C /* Interrupt Status Register */ 37 + #define AST_UDC_EP_ACK_IER 0x10 /* Programmable ep Pool ACK Interrupt Enable Reg */ 38 + #define AST_UDC_EP_NAK_IER 0x14 /* Programmable ep Pool NAK Interrupt Enable Reg */ 39 + #define AST_UDC_EP_ACK_ISR 0x18 /* Programmable ep Pool ACK Interrupt Status Reg */ 40 + #define AST_UDC_EP_NAK_ISR 0x1C /* Programmable ep Pool NAK Interrupt Status Reg */ 41 + #define AST_UDC_DEV_RESET 0x20 /* Device Controller Soft Reset Enable Register */ 42 + #define AST_UDC_STS 0x24 /* USB Status Register */ 43 + #define AST_VHUB_EP_DATA 0x28 /* Programmable ep Pool Data Toggle Value Set */ 44 + #define AST_VHUB_ISO_TX_FAIL 0x2C /* Isochronous Transaction Fail Accumulator */ 45 + #define AST_UDC_EP0_CTRL 0x30 /* Endpoint 0 Control/Status Register */ 46 + #define AST_UDC_EP0_DATA_BUFF 0x34 /* Base Address of ep0 IN/OUT Data Buffer Reg */ 47 + #define AST_UDC_SETUP0 0x80 /* Root Device Setup Data Buffer0 */ 48 + #define AST_UDC_SETUP1 0x84 /* Root Device Setup Data Buffer1 */ 49 + 50 + 51 + /* Main control reg */ 52 + #define USB_PHY_CLK_EN BIT(31) 53 + #define USB_FIFO_DYN_PWRD_EN BIT(19) 54 + #define USB_EP_LONG_DESC BIT(18) 55 + #define USB_BIST_TEST_PASS BIT(13) 56 + #define USB_BIST_TURN_ON BIT(12) 57 + #define USB_PHY_RESET_DIS BIT(11) 58 + #define USB_TEST_MODE(x) ((x) << 8) 59 + #define USB_FORCE_TIMER_HS BIT(7) 60 + #define USB_FORCE_HS BIT(6) 61 + #define USB_REMOTE_WAKEUP_12MS BIT(5) 62 + #define USB_REMOTE_WAKEUP_EN BIT(4) 63 + #define USB_AUTO_REMOTE_WAKEUP_EN BIT(3) 64 + #define USB_STOP_CLK_IN_SUPEND BIT(2) 65 + #define USB_UPSTREAM_FS BIT(1) 66 + #define USB_UPSTREAM_EN BIT(0) 67 + 68 + /* Main config reg */ 69 + #define UDC_CFG_SET_ADDR(x) ((x) & 0x3f) 70 + #define UDC_CFG_ADDR_MASK (0x3f) 71 + 72 + /* Interrupt ctrl & status reg */ 73 + #define UDC_IRQ_EP_POOL_NAK BIT(17) 74 + #define UDC_IRQ_EP_POOL_ACK_STALL BIT(16) 75 + #define UDC_IRQ_BUS_RESUME BIT(8) 76 + #define UDC_IRQ_BUS_SUSPEND BIT(7) 77 + #define UDC_IRQ_BUS_RESET BIT(6) 78 + #define UDC_IRQ_EP0_IN_DATA_NAK BIT(4) 79 + #define UDC_IRQ_EP0_IN_ACK_STALL BIT(3) 80 + #define UDC_IRQ_EP0_OUT_NAK BIT(2) 81 + #define UDC_IRQ_EP0_OUT_ACK_STALL BIT(1) 82 + #define UDC_IRQ_EP0_SETUP BIT(0) 83 + #define UDC_IRQ_ACK_ALL (0x1ff) 84 + 85 + /* EP isr reg */ 86 + #define USB_EP3_ISR BIT(3) 87 + #define USB_EP2_ISR BIT(2) 88 + #define USB_EP1_ISR BIT(1) 89 + #define USB_EP0_ISR BIT(0) 90 + #define UDC_IRQ_EP_ACK_ALL (0xf) 91 + 92 + /*Soft reset reg */ 93 + #define ROOT_UDC_SOFT_RESET BIT(0) 94 + 95 + /* USB status reg */ 96 + #define UDC_STS_HIGHSPEED BIT(27) 97 + 98 + /* Programmable EP data toggle */ 99 + #define EP_TOGGLE_SET_EPNUM(x) ((x) & 0x3) 100 + 101 + /* EP0 ctrl reg */ 102 + #define EP0_GET_RX_LEN(x) ((x >> 16) & 0x7f) 103 + #define EP0_TX_LEN(x) ((x & 0x7f) << 8) 104 + #define EP0_RX_BUFF_RDY BIT(2) 105 + #define EP0_TX_BUFF_RDY BIT(1) 106 + #define EP0_STALL BIT(0) 107 + 108 + /************************************* 109 + * * 110 + * per-endpoint register definitions * 111 + * * 112 + *************************************/ 113 + 114 + #define AST_UDC_EP_CONFIG 0x00 /* Endpoint Configuration Register */ 115 + #define AST_UDC_EP_DMA_CTRL 0x04 /* DMA Descriptor List Control/Status Register */ 116 + #define AST_UDC_EP_DMA_BUFF 0x08 /* DMA Descriptor/Buffer Base Address */ 117 + #define AST_UDC_EP_DMA_STS 0x0C /* DMA Descriptor List R/W Pointer and Status */ 118 + 119 + #define AST_UDC_EP_BASE 0x200 120 + #define AST_UDC_EP_OFFSET 0x10 121 + 122 + /* EP config reg */ 123 + #define EP_SET_MAX_PKT(x) ((x & 0x3ff) << 16) 124 + #define EP_DATA_FETCH_CTRL(x) ((x & 0x3) << 14) 125 + #define EP_AUTO_DATA_DISABLE (0x1 << 13) 126 + #define EP_SET_EP_STALL (0x1 << 12) 127 + #define EP_SET_EP_NUM(x) ((x & 0xf) << 8) 128 + #define EP_SET_TYPE_MASK(x) ((x) << 5) 129 + #define EP_TYPE_BULK (0x1) 130 + #define EP_TYPE_INT (0x2) 131 + #define EP_TYPE_ISO (0x3) 132 + #define EP_DIR_OUT (0x1 << 4) 133 + #define EP_ALLOCATED_MASK (0x7 << 1) 134 + #define EP_ENABLE BIT(0) 135 + 136 + /* EP DMA ctrl reg */ 137 + #define EP_DMA_CTRL_GET_PROC_STS(x) ((x >> 4) & 0xf) 138 + #define EP_DMA_CTRL_STS_RX_IDLE 0x0 139 + #define EP_DMA_CTRL_STS_TX_IDLE 0x8 140 + #define EP_DMA_CTRL_IN_LONG_MODE (0x1 << 3) 141 + #define EP_DMA_CTRL_RESET (0x1 << 2) 142 + #define EP_DMA_SINGLE_STAGE (0x1 << 1) 143 + #define EP_DMA_DESC_MODE (0x1 << 0) 144 + 145 + /* EP DMA status reg */ 146 + #define EP_DMA_SET_TX_SIZE(x) ((x & 0x7ff) << 16) 147 + #define EP_DMA_GET_TX_SIZE(x) (((x) >> 16) & 0x7ff) 148 + #define EP_DMA_GET_RPTR(x) (((x) >> 8) & 0xff) 149 + #define EP_DMA_GET_WPTR(x) ((x) & 0xff) 150 + #define EP_DMA_SINGLE_KICK (1 << 0) /* WPTR = 1 for single mode */ 151 + 152 + /* EP desc reg */ 153 + #define AST_EP_DMA_DESC_INTR_ENABLE BIT(31) 154 + #define AST_EP_DMA_DESC_PID_DATA0 (0 << 14) 155 + #define AST_EP_DMA_DESC_PID_DATA2 BIT(14) 156 + #define AST_EP_DMA_DESC_PID_DATA1 (2 << 14) 157 + #define AST_EP_DMA_DESC_PID_MDATA (3 << 14) 158 + #define EP_DESC1_IN_LEN(x) ((x) & 0x1fff) 159 + #define AST_EP_DMA_DESC_MAX_LEN (7680) /* Max packet length for trasmit in 1 desc */ 160 + 161 + struct ast_udc_request { 162 + struct usb_request req; 163 + struct list_head queue; 164 + unsigned mapped:1; 165 + unsigned int actual_dma_length; 166 + u32 saved_dma_wptr; 167 + }; 168 + 169 + #define to_ast_req(__req) container_of(__req, struct ast_udc_request, req) 170 + 171 + struct ast_dma_desc { 172 + u32 des_0; 173 + u32 des_1; 174 + }; 175 + 176 + struct ast_udc_ep { 177 + struct usb_ep ep; 178 + 179 + /* Request queue */ 180 + struct list_head queue; 181 + 182 + struct ast_udc_dev *udc; 183 + void __iomem *ep_reg; 184 + void *epn_buf; 185 + dma_addr_t epn_buf_dma; 186 + const struct usb_endpoint_descriptor *desc; 187 + 188 + /* DMA Descriptors */ 189 + struct ast_dma_desc *descs; 190 + dma_addr_t descs_dma; 191 + u32 descs_wptr; 192 + u32 chunk_max; 193 + 194 + bool dir_in:1; 195 + unsigned stopped:1; 196 + bool desc_mode:1; 197 + }; 198 + 199 + #define to_ast_ep(__ep) container_of(__ep, struct ast_udc_ep, ep) 200 + 201 + struct ast_udc_dev { 202 + struct platform_device *pdev; 203 + void __iomem *reg; 204 + int irq; 205 + spinlock_t lock; 206 + struct clk *clk; 207 + struct work_struct wake_work; 208 + 209 + /* EP0 DMA buffers allocated in one chunk */ 210 + void *ep0_buf; 211 + dma_addr_t ep0_buf_dma; 212 + struct ast_udc_ep ep[AST_UDC_NUM_ENDPOINTS]; 213 + 214 + struct usb_gadget gadget; 215 + struct usb_gadget_driver *driver; 216 + void __iomem *creq; 217 + enum usb_device_state suspended_from; 218 + int desc_mode; 219 + 220 + /* Force full speed only */ 221 + bool force_usb1:1; 222 + unsigned is_control_tx:1; 223 + bool wakeup_en:1; 224 + }; 225 + 226 + #define to_ast_dev(__g) container_of(__g, struct ast_udc_dev, gadget) 227 + 228 + static const char * const ast_ep_name[] = { 229 + "ep0", "ep1", "ep2", "ep3", "ep4" 230 + }; 231 + 232 + #ifdef AST_UDC_DEBUG_ALL 233 + #define AST_UDC_DEBUG 234 + #define AST_SETUP_DEBUG 235 + #define AST_EP_DEBUG 236 + #define AST_ISR_DEBUG 237 + #endif 238 + 239 + #ifdef AST_SETUP_DEBUG 240 + #define SETUP_DBG(u, fmt, ...) \ 241 + dev_dbg(&(u)->pdev->dev, "%s() " fmt, __func__, ##__VA_ARGS__) 242 + #else 243 + #define SETUP_DBG(u, fmt, ...) 244 + #endif 245 + 246 + #ifdef AST_EP_DEBUG 247 + #define EP_DBG(e, fmt, ...) \ 248 + dev_dbg(&(e)->udc->pdev->dev, "%s():%s " fmt, __func__, \ 249 + (e)->ep.name, ##__VA_ARGS__) 250 + #else 251 + #define EP_DBG(ep, fmt, ...) ((void)(ep)) 252 + #endif 253 + 254 + #ifdef AST_UDC_DEBUG 255 + #define UDC_DBG(u, fmt, ...) \ 256 + dev_dbg(&(u)->pdev->dev, "%s() " fmt, __func__, ##__VA_ARGS__) 257 + #else 258 + #define UDC_DBG(u, fmt, ...) 259 + #endif 260 + 261 + #ifdef AST_ISR_DEBUG 262 + #define ISR_DBG(u, fmt, ...) \ 263 + dev_dbg(&(u)->pdev->dev, "%s() " fmt, __func__, ##__VA_ARGS__) 264 + #else 265 + #define ISR_DBG(u, fmt, ...) 266 + #endif 267 + 268 + /*-------------------------------------------------------------------------*/ 269 + #define ast_udc_read(udc, offset) \ 270 + readl((udc)->reg + (offset)) 271 + #define ast_udc_write(udc, val, offset) \ 272 + writel((val), (udc)->reg + (offset)) 273 + 274 + #define ast_ep_read(ep, reg) \ 275 + readl((ep)->ep_reg + (reg)) 276 + #define ast_ep_write(ep, val, reg) \ 277 + writel((val), (ep)->ep_reg + (reg)) 278 + 279 + /*-------------------------------------------------------------------------*/ 280 + 281 + static void ast_udc_done(struct ast_udc_ep *ep, struct ast_udc_request *req, 282 + int status) 283 + { 284 + struct ast_udc_dev *udc = ep->udc; 285 + 286 + EP_DBG(ep, "req @%p, len (%d/%d), buf:0x%x, dir:0x%x\n", 287 + req, req->req.actual, req->req.length, 288 + (u32)req->req.buf, ep->dir_in); 289 + 290 + list_del(&req->queue); 291 + 292 + if (req->req.status == -EINPROGRESS) 293 + req->req.status = status; 294 + else 295 + status = req->req.status; 296 + 297 + if (status && status != -ESHUTDOWN) 298 + EP_DBG(ep, "done req:%p, status:%d\n", req, status); 299 + 300 + spin_unlock(&udc->lock); 301 + usb_gadget_giveback_request(&ep->ep, &req->req); 302 + spin_lock(&udc->lock); 303 + } 304 + 305 + static void ast_udc_nuke(struct ast_udc_ep *ep, int status) 306 + { 307 + int count = 0; 308 + 309 + while (!list_empty(&ep->queue)) { 310 + struct ast_udc_request *req; 311 + 312 + req = list_entry(ep->queue.next, struct ast_udc_request, 313 + queue); 314 + ast_udc_done(ep, req, status); 315 + count++; 316 + } 317 + 318 + if (count) 319 + EP_DBG(ep, "Nuked %d request(s)\n", count); 320 + } 321 + 322 + /* 323 + * Stop activity on all endpoints. 324 + * Device controller for which EP activity is to be stopped. 325 + * 326 + * All the endpoints are stopped and any pending transfer requests if any on 327 + * the endpoint are terminated. 328 + */ 329 + static void ast_udc_stop_activity(struct ast_udc_dev *udc) 330 + { 331 + struct ast_udc_ep *ep; 332 + int i; 333 + 334 + for (i = 0; i < AST_UDC_NUM_ENDPOINTS; i++) { 335 + ep = &udc->ep[i]; 336 + ep->stopped = 1; 337 + ast_udc_nuke(ep, -ESHUTDOWN); 338 + } 339 + } 340 + 341 + static int ast_udc_ep_enable(struct usb_ep *_ep, 342 + const struct usb_endpoint_descriptor *desc) 343 + { 344 + u16 maxpacket = usb_endpoint_maxp(desc); 345 + struct ast_udc_ep *ep = to_ast_ep(_ep); 346 + struct ast_udc_dev *udc = ep->udc; 347 + u8 epnum = usb_endpoint_num(desc); 348 + unsigned long flags; 349 + u32 ep_conf = 0; 350 + u8 dir_in; 351 + u8 type; 352 + 353 + if (!_ep || !ep || !desc || desc->bDescriptorType != USB_DT_ENDPOINT || 354 + maxpacket == 0 || maxpacket > ep->ep.maxpacket) { 355 + EP_DBG(ep, "Failed, invalid EP enable param\n"); 356 + return -EINVAL; 357 + } 358 + 359 + if (!udc->driver) { 360 + EP_DBG(ep, "bogus device state\n"); 361 + return -ESHUTDOWN; 362 + } 363 + 364 + EP_DBG(ep, "maxpacket:0x%x\n", maxpacket); 365 + 366 + spin_lock_irqsave(&udc->lock, flags); 367 + 368 + ep->desc = desc; 369 + ep->stopped = 0; 370 + ep->ep.maxpacket = maxpacket; 371 + ep->chunk_max = AST_EP_DMA_DESC_MAX_LEN; 372 + 373 + if (maxpacket < AST_UDC_EPn_MAX_PACKET) 374 + ep_conf = EP_SET_MAX_PKT(maxpacket); 375 + 376 + ep_conf |= EP_SET_EP_NUM(epnum); 377 + 378 + type = usb_endpoint_type(desc); 379 + dir_in = usb_endpoint_dir_in(desc); 380 + ep->dir_in = dir_in; 381 + if (!ep->dir_in) 382 + ep_conf |= EP_DIR_OUT; 383 + 384 + EP_DBG(ep, "type %d, dir_in %d\n", type, dir_in); 385 + switch (type) { 386 + case USB_ENDPOINT_XFER_ISOC: 387 + ep_conf |= EP_SET_TYPE_MASK(EP_TYPE_ISO); 388 + break; 389 + 390 + case USB_ENDPOINT_XFER_BULK: 391 + ep_conf |= EP_SET_TYPE_MASK(EP_TYPE_BULK); 392 + break; 393 + 394 + case USB_ENDPOINT_XFER_INT: 395 + ep_conf |= EP_SET_TYPE_MASK(EP_TYPE_INT); 396 + break; 397 + } 398 + 399 + ep->desc_mode = udc->desc_mode && ep->descs_dma && ep->dir_in; 400 + if (ep->desc_mode) { 401 + ast_ep_write(ep, EP_DMA_CTRL_RESET, AST_UDC_EP_DMA_CTRL); 402 + ast_ep_write(ep, 0, AST_UDC_EP_DMA_STS); 403 + ast_ep_write(ep, ep->descs_dma, AST_UDC_EP_DMA_BUFF); 404 + 405 + /* Enable Long Descriptor Mode */ 406 + ast_ep_write(ep, EP_DMA_CTRL_IN_LONG_MODE | EP_DMA_DESC_MODE, 407 + AST_UDC_EP_DMA_CTRL); 408 + 409 + ep->descs_wptr = 0; 410 + 411 + } else { 412 + ast_ep_write(ep, EP_DMA_CTRL_RESET, AST_UDC_EP_DMA_CTRL); 413 + ast_ep_write(ep, EP_DMA_SINGLE_STAGE, AST_UDC_EP_DMA_CTRL); 414 + ast_ep_write(ep, 0, AST_UDC_EP_DMA_STS); 415 + } 416 + 417 + /* Cleanup data toggle just in case */ 418 + ast_udc_write(udc, EP_TOGGLE_SET_EPNUM(epnum), AST_VHUB_EP_DATA); 419 + 420 + /* Enable EP */ 421 + ast_ep_write(ep, ep_conf | EP_ENABLE, AST_UDC_EP_CONFIG); 422 + 423 + EP_DBG(ep, "ep_config: 0x%x\n", ast_ep_read(ep, AST_UDC_EP_CONFIG)); 424 + 425 + spin_unlock_irqrestore(&udc->lock, flags); 426 + 427 + return 0; 428 + } 429 + 430 + static int ast_udc_ep_disable(struct usb_ep *_ep) 431 + { 432 + struct ast_udc_ep *ep = to_ast_ep(_ep); 433 + struct ast_udc_dev *udc = ep->udc; 434 + unsigned long flags; 435 + 436 + spin_lock_irqsave(&udc->lock, flags); 437 + 438 + ep->ep.desc = NULL; 439 + ep->stopped = 1; 440 + 441 + ast_udc_nuke(ep, -ESHUTDOWN); 442 + ast_ep_write(ep, 0, AST_UDC_EP_CONFIG); 443 + 444 + spin_unlock_irqrestore(&udc->lock, flags); 445 + 446 + return 0; 447 + } 448 + 449 + static struct usb_request *ast_udc_ep_alloc_request(struct usb_ep *_ep, 450 + gfp_t gfp_flags) 451 + { 452 + struct ast_udc_ep *ep = to_ast_ep(_ep); 453 + struct ast_udc_request *req; 454 + 455 + req = kzalloc(sizeof(struct ast_udc_request), gfp_flags); 456 + if (!req) { 457 + EP_DBG(ep, "request allocation failed\n"); 458 + return NULL; 459 + } 460 + 461 + INIT_LIST_HEAD(&req->queue); 462 + 463 + return &req->req; 464 + } 465 + 466 + static void ast_udc_ep_free_request(struct usb_ep *_ep, 467 + struct usb_request *_req) 468 + { 469 + struct ast_udc_request *req = to_ast_req(_req); 470 + 471 + kfree(req); 472 + } 473 + 474 + static int ast_dma_descriptor_setup(struct ast_udc_ep *ep, u32 dma_buf, 475 + u16 tx_len, struct ast_udc_request *req) 476 + { 477 + struct ast_udc_dev *udc = ep->udc; 478 + struct device *dev = &udc->pdev->dev; 479 + bool last = false; 480 + int chunk, count; 481 + u32 offset; 482 + 483 + if (!ep->descs) { 484 + dev_warn(dev, "%s: Empty DMA descs list failure\n", 485 + ep->ep.name); 486 + return -EINVAL; 487 + } 488 + 489 + chunk = tx_len; 490 + offset = count = 0; 491 + 492 + EP_DBG(ep, "req @%p, %s:%d, %s:0x%x, %s:0x%x\n", req, 493 + "wptr", ep->descs_wptr, "dma_buf", dma_buf, 494 + "tx_len", tx_len); 495 + 496 + /* Create Descriptor Lists */ 497 + while (chunk >= 0 && !last && count < AST_UDC_DESCS_COUNT) { 498 + 499 + ep->descs[ep->descs_wptr].des_0 = dma_buf + offset; 500 + 501 + if (chunk > ep->chunk_max) { 502 + ep->descs[ep->descs_wptr].des_1 = ep->chunk_max; 503 + } else { 504 + ep->descs[ep->descs_wptr].des_1 = chunk; 505 + last = true; 506 + } 507 + 508 + chunk -= ep->chunk_max; 509 + 510 + EP_DBG(ep, "descs[%d]: 0x%x 0x%x\n", 511 + ep->descs_wptr, 512 + ep->descs[ep->descs_wptr].des_0, 513 + ep->descs[ep->descs_wptr].des_1); 514 + 515 + if (count == 0) 516 + req->saved_dma_wptr = ep->descs_wptr; 517 + 518 + ep->descs_wptr++; 519 + count++; 520 + 521 + if (ep->descs_wptr >= AST_UDC_DESCS_COUNT) 522 + ep->descs_wptr = 0; 523 + 524 + offset = ep->chunk_max * count; 525 + } 526 + 527 + return 0; 528 + } 529 + 530 + static void ast_udc_epn_kick(struct ast_udc_ep *ep, struct ast_udc_request *req) 531 + { 532 + u32 tx_len; 533 + u32 last; 534 + 535 + last = req->req.length - req->req.actual; 536 + tx_len = last > ep->ep.maxpacket ? ep->ep.maxpacket : last; 537 + 538 + EP_DBG(ep, "kick req @%p, len:%d, dir:%d\n", 539 + req, tx_len, ep->dir_in); 540 + 541 + ast_ep_write(ep, req->req.dma + req->req.actual, AST_UDC_EP_DMA_BUFF); 542 + 543 + /* Start DMA */ 544 + ast_ep_write(ep, EP_DMA_SET_TX_SIZE(tx_len), AST_UDC_EP_DMA_STS); 545 + ast_ep_write(ep, EP_DMA_SET_TX_SIZE(tx_len) | EP_DMA_SINGLE_KICK, 546 + AST_UDC_EP_DMA_STS); 547 + } 548 + 549 + static void ast_udc_epn_kick_desc(struct ast_udc_ep *ep, 550 + struct ast_udc_request *req) 551 + { 552 + u32 descs_max_size; 553 + u32 tx_len; 554 + u32 last; 555 + 556 + descs_max_size = AST_EP_DMA_DESC_MAX_LEN * AST_UDC_DESCS_COUNT; 557 + 558 + last = req->req.length - req->req.actual; 559 + tx_len = last > descs_max_size ? descs_max_size : last; 560 + 561 + EP_DBG(ep, "kick req @%p, %s:%d, %s:0x%x, %s:0x%x (%d/%d), %s:0x%x\n", 562 + req, "tx_len", tx_len, "dir_in", ep->dir_in, 563 + "dma", req->req.dma + req->req.actual, 564 + req->req.actual, req->req.length, 565 + "descs_max_size", descs_max_size); 566 + 567 + if (!ast_dma_descriptor_setup(ep, req->req.dma + req->req.actual, 568 + tx_len, req)) 569 + req->actual_dma_length += tx_len; 570 + 571 + /* make sure CPU done everything before triggering DMA */ 572 + mb(); 573 + 574 + ast_ep_write(ep, ep->descs_wptr, AST_UDC_EP_DMA_STS); 575 + 576 + EP_DBG(ep, "descs_wptr:%d, dstat:0x%x, dctrl:0x%x\n", 577 + ep->descs_wptr, 578 + ast_ep_read(ep, AST_UDC_EP_DMA_STS), 579 + ast_ep_read(ep, AST_UDC_EP_DMA_CTRL)); 580 + } 581 + 582 + static void ast_udc_ep0_queue(struct ast_udc_ep *ep, 583 + struct ast_udc_request *req) 584 + { 585 + struct ast_udc_dev *udc = ep->udc; 586 + u32 tx_len; 587 + u32 last; 588 + 589 + last = req->req.length - req->req.actual; 590 + tx_len = last > ep->ep.maxpacket ? ep->ep.maxpacket : last; 591 + 592 + ast_udc_write(udc, req->req.dma + req->req.actual, 593 + AST_UDC_EP0_DATA_BUFF); 594 + 595 + if (ep->dir_in) { 596 + /* IN requests, send data */ 597 + SETUP_DBG(udc, "IN: %s:0x%x, %s:0x%x, %s:%d (%d/%d), %s:%d\n", 598 + "buf", (u32)req->req.buf, 599 + "dma", req->req.dma + req->req.actual, 600 + "tx_len", tx_len, 601 + req->req.actual, req->req.length, 602 + "dir_in", ep->dir_in); 603 + 604 + req->req.actual += tx_len; 605 + ast_udc_write(udc, EP0_TX_LEN(tx_len), AST_UDC_EP0_CTRL); 606 + ast_udc_write(udc, EP0_TX_LEN(tx_len) | EP0_TX_BUFF_RDY, 607 + AST_UDC_EP0_CTRL); 608 + 609 + } else { 610 + /* OUT requests, receive data */ 611 + SETUP_DBG(udc, "OUT: %s:%x, %s:%x, %s:(%d/%d), %s:%d\n", 612 + "buf", (u32)req->req.buf, 613 + "dma", req->req.dma + req->req.actual, 614 + "len", req->req.actual, req->req.length, 615 + "dir_in", ep->dir_in); 616 + 617 + if (!req->req.length) { 618 + /* 0 len request, send tx as completion */ 619 + ast_udc_write(udc, EP0_TX_BUFF_RDY, AST_UDC_EP0_CTRL); 620 + ep->dir_in = 0x1; 621 + } else 622 + ast_udc_write(udc, EP0_RX_BUFF_RDY, AST_UDC_EP0_CTRL); 623 + } 624 + } 625 + 626 + static int ast_udc_ep_queue(struct usb_ep *_ep, struct usb_request *_req, 627 + gfp_t gfp_flags) 628 + { 629 + struct ast_udc_request *req = to_ast_req(_req); 630 + struct ast_udc_ep *ep = to_ast_ep(_ep); 631 + struct ast_udc_dev *udc = ep->udc; 632 + struct device *dev = &udc->pdev->dev; 633 + unsigned long flags; 634 + int rc; 635 + 636 + if (unlikely(!_req || !_req->complete || !_req->buf || !_ep)) { 637 + dev_warn(dev, "Invalid EP request !\n"); 638 + return -EINVAL; 639 + } 640 + 641 + if (ep->stopped) { 642 + dev_warn(dev, "%s is already stopped !\n", _ep->name); 643 + return -ESHUTDOWN; 644 + } 645 + 646 + spin_lock_irqsave(&udc->lock, flags); 647 + 648 + list_add_tail(&req->queue, &ep->queue); 649 + 650 + req->req.actual = 0; 651 + req->req.status = -EINPROGRESS; 652 + req->actual_dma_length = 0; 653 + 654 + rc = usb_gadget_map_request(&udc->gadget, &req->req, ep->dir_in); 655 + if (rc) { 656 + EP_DBG(ep, "Request mapping failure %d\n", rc); 657 + dev_warn(dev, "Request mapping failure %d\n", rc); 658 + goto end; 659 + } 660 + 661 + EP_DBG(ep, "enqueue req @%p\n", req); 662 + EP_DBG(ep, "l=%d, dma:0x%x, zero:%d, is_in:%d\n", 663 + _req->length, _req->dma, _req->zero, ep->dir_in); 664 + 665 + /* EP0 request enqueue */ 666 + if (ep->ep.desc == NULL) { 667 + if ((req->req.dma % 4) != 0) { 668 + dev_warn(dev, "EP0 req dma alignment error\n"); 669 + rc = -ESHUTDOWN; 670 + goto end; 671 + } 672 + 673 + ast_udc_ep0_queue(ep, req); 674 + goto end; 675 + } 676 + 677 + /* EPn request enqueue */ 678 + if (list_is_singular(&ep->queue)) { 679 + if (ep->desc_mode) 680 + ast_udc_epn_kick_desc(ep, req); 681 + else 682 + ast_udc_epn_kick(ep, req); 683 + } 684 + 685 + end: 686 + spin_unlock_irqrestore(&udc->lock, flags); 687 + 688 + return rc; 689 + } 690 + 691 + static int ast_udc_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req) 692 + { 693 + struct ast_udc_ep *ep = to_ast_ep(_ep); 694 + struct ast_udc_dev *udc = ep->udc; 695 + struct ast_udc_request *req; 696 + unsigned long flags; 697 + int rc = 0; 698 + 699 + spin_lock_irqsave(&udc->lock, flags); 700 + 701 + /* make sure it's actually queued on this endpoint */ 702 + list_for_each_entry(req, &ep->queue, queue) { 703 + if (&req->req == _req) { 704 + list_del_init(&req->queue); 705 + ast_udc_done(ep, req, -ESHUTDOWN); 706 + _req->status = -ECONNRESET; 707 + break; 708 + } 709 + } 710 + 711 + /* dequeue request not found */ 712 + if (&req->req != _req) 713 + rc = -EINVAL; 714 + 715 + spin_unlock_irqrestore(&udc->lock, flags); 716 + 717 + return rc; 718 + } 719 + 720 + static int ast_udc_ep_set_halt(struct usb_ep *_ep, int value) 721 + { 722 + struct ast_udc_ep *ep = to_ast_ep(_ep); 723 + struct ast_udc_dev *udc = ep->udc; 724 + unsigned long flags; 725 + int epnum; 726 + u32 ctrl; 727 + 728 + EP_DBG(ep, "val:%d\n", value); 729 + 730 + spin_lock_irqsave(&udc->lock, flags); 731 + 732 + epnum = usb_endpoint_num(ep->desc); 733 + 734 + /* EP0 */ 735 + if (epnum == 0) { 736 + ctrl = ast_udc_read(udc, AST_UDC_EP0_CTRL); 737 + if (value) 738 + ctrl |= EP0_STALL; 739 + else 740 + ctrl &= ~EP0_STALL; 741 + 742 + ast_udc_write(udc, ctrl, AST_UDC_EP0_CTRL); 743 + 744 + } else { 745 + /* EPn */ 746 + ctrl = ast_udc_read(udc, AST_UDC_EP_CONFIG); 747 + if (value) 748 + ctrl |= EP_SET_EP_STALL; 749 + else 750 + ctrl &= ~EP_SET_EP_STALL; 751 + 752 + ast_ep_write(ep, ctrl, AST_UDC_EP_CONFIG); 753 + 754 + /* only epn is stopped and waits for clear */ 755 + ep->stopped = value ? 1 : 0; 756 + } 757 + 758 + spin_unlock_irqrestore(&udc->lock, flags); 759 + 760 + return 0; 761 + } 762 + 763 + static const struct usb_ep_ops ast_udc_ep_ops = { 764 + .enable = ast_udc_ep_enable, 765 + .disable = ast_udc_ep_disable, 766 + .alloc_request = ast_udc_ep_alloc_request, 767 + .free_request = ast_udc_ep_free_request, 768 + .queue = ast_udc_ep_queue, 769 + .dequeue = ast_udc_ep_dequeue, 770 + .set_halt = ast_udc_ep_set_halt, 771 + /* there's only imprecise fifo status reporting */ 772 + }; 773 + 774 + static void ast_udc_ep0_rx(struct ast_udc_dev *udc) 775 + { 776 + ast_udc_write(udc, udc->ep0_buf_dma, AST_UDC_EP0_DATA_BUFF); 777 + ast_udc_write(udc, EP0_RX_BUFF_RDY, AST_UDC_EP0_CTRL); 778 + } 779 + 780 + static void ast_udc_ep0_tx(struct ast_udc_dev *udc) 781 + { 782 + ast_udc_write(udc, udc->ep0_buf_dma, AST_UDC_EP0_DATA_BUFF); 783 + ast_udc_write(udc, EP0_TX_BUFF_RDY, AST_UDC_EP0_CTRL); 784 + } 785 + 786 + static void ast_udc_ep0_out(struct ast_udc_dev *udc) 787 + { 788 + struct device *dev = &udc->pdev->dev; 789 + struct ast_udc_ep *ep = &udc->ep[0]; 790 + struct ast_udc_request *req; 791 + u16 rx_len; 792 + 793 + if (list_empty(&ep->queue)) 794 + return; 795 + 796 + req = list_entry(ep->queue.next, struct ast_udc_request, queue); 797 + 798 + rx_len = EP0_GET_RX_LEN(ast_udc_read(udc, AST_UDC_EP0_CTRL)); 799 + req->req.actual += rx_len; 800 + 801 + SETUP_DBG(udc, "req %p (%d/%d)\n", req, 802 + req->req.actual, req->req.length); 803 + 804 + if ((rx_len < ep->ep.maxpacket) || 805 + (req->req.actual == req->req.length)) { 806 + ast_udc_ep0_tx(udc); 807 + if (!ep->dir_in) 808 + ast_udc_done(ep, req, 0); 809 + 810 + } else { 811 + if (rx_len > req->req.length) { 812 + // Issue Fix 813 + dev_warn(dev, "Something wrong (%d/%d)\n", 814 + req->req.actual, req->req.length); 815 + ast_udc_ep0_tx(udc); 816 + ast_udc_done(ep, req, 0); 817 + return; 818 + } 819 + 820 + ep->dir_in = 0; 821 + 822 + /* More works */ 823 + ast_udc_ep0_queue(ep, req); 824 + } 825 + } 826 + 827 + static void ast_udc_ep0_in(struct ast_udc_dev *udc) 828 + { 829 + struct ast_udc_ep *ep = &udc->ep[0]; 830 + struct ast_udc_request *req; 831 + 832 + if (list_empty(&ep->queue)) { 833 + if (udc->is_control_tx) { 834 + ast_udc_ep0_rx(udc); 835 + udc->is_control_tx = 0; 836 + } 837 + 838 + return; 839 + } 840 + 841 + req = list_entry(ep->queue.next, struct ast_udc_request, queue); 842 + 843 + SETUP_DBG(udc, "req %p (%d/%d)\n", req, 844 + req->req.actual, req->req.length); 845 + 846 + if (req->req.length == req->req.actual) { 847 + if (req->req.length) 848 + ast_udc_ep0_rx(udc); 849 + 850 + if (ep->dir_in) 851 + ast_udc_done(ep, req, 0); 852 + 853 + } else { 854 + /* More works */ 855 + ast_udc_ep0_queue(ep, req); 856 + } 857 + } 858 + 859 + static void ast_udc_epn_handle(struct ast_udc_dev *udc, u16 ep_num) 860 + { 861 + struct ast_udc_ep *ep = &udc->ep[ep_num]; 862 + struct ast_udc_request *req; 863 + u16 len = 0; 864 + 865 + if (list_empty(&ep->queue)) 866 + return; 867 + 868 + req = list_first_entry(&ep->queue, struct ast_udc_request, queue); 869 + 870 + len = EP_DMA_GET_TX_SIZE(ast_ep_read(ep, AST_UDC_EP_DMA_STS)); 871 + req->req.actual += len; 872 + 873 + EP_DBG(ep, "req @%p, length:(%d/%d), %s:0x%x\n", req, 874 + req->req.actual, req->req.length, "len", len); 875 + 876 + /* Done this request */ 877 + if (req->req.length == req->req.actual) { 878 + ast_udc_done(ep, req, 0); 879 + req = list_first_entry_or_null(&ep->queue, 880 + struct ast_udc_request, 881 + queue); 882 + 883 + } else { 884 + /* Check for short packet */ 885 + if (len < ep->ep.maxpacket) { 886 + ast_udc_done(ep, req, 0); 887 + req = list_first_entry_or_null(&ep->queue, 888 + struct ast_udc_request, 889 + queue); 890 + } 891 + } 892 + 893 + /* More requests */ 894 + if (req) 895 + ast_udc_epn_kick(ep, req); 896 + } 897 + 898 + static void ast_udc_epn_handle_desc(struct ast_udc_dev *udc, u16 ep_num) 899 + { 900 + struct ast_udc_ep *ep = &udc->ep[ep_num]; 901 + struct device *dev = &udc->pdev->dev; 902 + struct ast_udc_request *req; 903 + u32 proc_sts, wr_ptr, rd_ptr; 904 + u32 len_in_desc, ctrl; 905 + u16 total_len = 0; 906 + int i; 907 + 908 + if (list_empty(&ep->queue)) { 909 + dev_warn(dev, "%s request queue empty!\n", ep->ep.name); 910 + return; 911 + } 912 + 913 + req = list_first_entry(&ep->queue, struct ast_udc_request, queue); 914 + 915 + ctrl = ast_ep_read(ep, AST_UDC_EP_DMA_CTRL); 916 + proc_sts = EP_DMA_CTRL_GET_PROC_STS(ctrl); 917 + 918 + /* Check processing status is idle */ 919 + if (proc_sts != EP_DMA_CTRL_STS_RX_IDLE && 920 + proc_sts != EP_DMA_CTRL_STS_TX_IDLE) { 921 + dev_warn(dev, "EP DMA CTRL: 0x%x, PS:0x%x\n", 922 + ast_ep_read(ep, AST_UDC_EP_DMA_CTRL), 923 + proc_sts); 924 + return; 925 + } 926 + 927 + ctrl = ast_ep_read(ep, AST_UDC_EP_DMA_STS); 928 + rd_ptr = EP_DMA_GET_RPTR(ctrl); 929 + wr_ptr = EP_DMA_GET_WPTR(ctrl); 930 + 931 + if (rd_ptr != wr_ptr) { 932 + dev_warn(dev, "desc list is not empty ! %s:%d, %s:%d\n", 933 + "rptr", rd_ptr, "wptr", wr_ptr); 934 + return; 935 + } 936 + 937 + EP_DBG(ep, "rd_ptr:%d, wr_ptr:%d\n", rd_ptr, wr_ptr); 938 + i = req->saved_dma_wptr; 939 + 940 + do { 941 + len_in_desc = EP_DESC1_IN_LEN(ep->descs[i].des_1); 942 + EP_DBG(ep, "desc[%d] len: %d\n", i, len_in_desc); 943 + total_len += len_in_desc; 944 + i++; 945 + if (i >= AST_UDC_DESCS_COUNT) 946 + i = 0; 947 + 948 + } while (i != wr_ptr); 949 + 950 + req->req.actual += total_len; 951 + 952 + EP_DBG(ep, "req @%p, length:(%d/%d), %s:0x%x\n", req, 953 + req->req.actual, req->req.length, "len", total_len); 954 + 955 + /* Done this request */ 956 + if (req->req.length == req->req.actual) { 957 + ast_udc_done(ep, req, 0); 958 + req = list_first_entry_or_null(&ep->queue, 959 + struct ast_udc_request, 960 + queue); 961 + 962 + } else { 963 + /* Check for short packet */ 964 + if (total_len < ep->ep.maxpacket) { 965 + ast_udc_done(ep, req, 0); 966 + req = list_first_entry_or_null(&ep->queue, 967 + struct ast_udc_request, 968 + queue); 969 + } 970 + } 971 + 972 + /* More requests & dma descs not setup yet */ 973 + if (req && (req->actual_dma_length == req->req.actual)) { 974 + EP_DBG(ep, "More requests\n"); 975 + ast_udc_epn_kick_desc(ep, req); 976 + } 977 + } 978 + 979 + static void ast_udc_ep0_data_tx(struct ast_udc_dev *udc, u8 *tx_data, u32 len) 980 + { 981 + if (len) { 982 + memcpy(udc->ep0_buf, tx_data, len); 983 + 984 + ast_udc_write(udc, udc->ep0_buf_dma, AST_UDC_EP0_DATA_BUFF); 985 + ast_udc_write(udc, EP0_TX_LEN(len), AST_UDC_EP0_CTRL); 986 + ast_udc_write(udc, EP0_TX_LEN(len) | EP0_TX_BUFF_RDY, 987 + AST_UDC_EP0_CTRL); 988 + udc->is_control_tx = 1; 989 + 990 + } else 991 + ast_udc_write(udc, EP0_TX_BUFF_RDY, AST_UDC_EP0_CTRL); 992 + } 993 + 994 + static void ast_udc_getstatus(struct ast_udc_dev *udc) 995 + { 996 + struct usb_ctrlrequest crq; 997 + struct ast_udc_ep *ep; 998 + u16 status = 0; 999 + u16 epnum = 0; 1000 + 1001 + memcpy_fromio(&crq, udc->creq, sizeof(crq)); 1002 + 1003 + switch (crq.bRequestType & USB_RECIP_MASK) { 1004 + case USB_RECIP_DEVICE: 1005 + /* Get device status */ 1006 + status = 1 << USB_DEVICE_SELF_POWERED; 1007 + break; 1008 + case USB_RECIP_INTERFACE: 1009 + break; 1010 + case USB_RECIP_ENDPOINT: 1011 + epnum = crq.wIndex & USB_ENDPOINT_NUMBER_MASK; 1012 + status = udc->ep[epnum].stopped; 1013 + break; 1014 + default: 1015 + goto stall; 1016 + } 1017 + 1018 + ep = &udc->ep[epnum]; 1019 + EP_DBG(ep, "status: 0x%x\n", status); 1020 + ast_udc_ep0_data_tx(udc, (u8 *)&status, sizeof(status)); 1021 + 1022 + return; 1023 + 1024 + stall: 1025 + EP_DBG(ep, "Can't respond request\n"); 1026 + ast_udc_write(udc, ast_udc_read(udc, AST_UDC_EP0_CTRL) | EP0_STALL, 1027 + AST_UDC_EP0_CTRL); 1028 + } 1029 + 1030 + static void ast_udc_ep0_handle_setup(struct ast_udc_dev *udc) 1031 + { 1032 + struct ast_udc_ep *ep = &udc->ep[0]; 1033 + struct ast_udc_request *req; 1034 + struct usb_ctrlrequest crq; 1035 + int req_num = 0; 1036 + int rc = 0; 1037 + u32 reg; 1038 + 1039 + memcpy_fromio(&crq, udc->creq, sizeof(crq)); 1040 + 1041 + SETUP_DBG(udc, "SETUP packet: %02x/%02x/%04x/%04x/%04x\n", 1042 + crq.bRequestType, crq.bRequest, le16_to_cpu(crq.wValue), 1043 + le16_to_cpu(crq.wIndex), le16_to_cpu(crq.wLength)); 1044 + 1045 + /* 1046 + * Cleanup ep0 request(s) in queue because 1047 + * there is a new control setup comes. 1048 + */ 1049 + list_for_each_entry(req, &udc->ep[0].queue, queue) { 1050 + req_num++; 1051 + EP_DBG(ep, "there is req %p in ep0 queue !\n", req); 1052 + } 1053 + 1054 + if (req_num) 1055 + ast_udc_nuke(&udc->ep[0], -ETIMEDOUT); 1056 + 1057 + udc->ep[0].dir_in = crq.bRequestType & USB_DIR_IN; 1058 + 1059 + if ((crq.bRequestType & USB_TYPE_MASK) == USB_TYPE_STANDARD) { 1060 + switch (crq.bRequest) { 1061 + case USB_REQ_SET_ADDRESS: 1062 + if (ast_udc_read(udc, AST_UDC_STS) & UDC_STS_HIGHSPEED) 1063 + udc->gadget.speed = USB_SPEED_HIGH; 1064 + else 1065 + udc->gadget.speed = USB_SPEED_FULL; 1066 + 1067 + SETUP_DBG(udc, "set addr: 0x%x\n", crq.wValue); 1068 + reg = ast_udc_read(udc, AST_UDC_CONFIG); 1069 + reg &= ~UDC_CFG_ADDR_MASK; 1070 + reg |= UDC_CFG_SET_ADDR(crq.wValue); 1071 + ast_udc_write(udc, reg, AST_UDC_CONFIG); 1072 + goto req_complete; 1073 + 1074 + case USB_REQ_CLEAR_FEATURE: 1075 + SETUP_DBG(udc, "ep0: CLEAR FEATURE\n"); 1076 + goto req_driver; 1077 + 1078 + case USB_REQ_SET_FEATURE: 1079 + SETUP_DBG(udc, "ep0: SET FEATURE\n"); 1080 + goto req_driver; 1081 + 1082 + case USB_REQ_GET_STATUS: 1083 + ast_udc_getstatus(udc); 1084 + return; 1085 + 1086 + default: 1087 + goto req_driver; 1088 + } 1089 + 1090 + } 1091 + 1092 + req_driver: 1093 + if (udc->driver) { 1094 + SETUP_DBG(udc, "Forwarding %s to gadget...\n", 1095 + udc->gadget.name); 1096 + 1097 + spin_unlock(&udc->lock); 1098 + rc = udc->driver->setup(&udc->gadget, &crq); 1099 + spin_lock(&udc->lock); 1100 + 1101 + } else { 1102 + SETUP_DBG(udc, "No gadget for request !\n"); 1103 + } 1104 + 1105 + if (rc >= 0) 1106 + return; 1107 + 1108 + /* Stall if gadget failed */ 1109 + SETUP_DBG(udc, "Stalling, rc:0x%x\n", rc); 1110 + ast_udc_write(udc, ast_udc_read(udc, AST_UDC_EP0_CTRL) | EP0_STALL, 1111 + AST_UDC_EP0_CTRL); 1112 + return; 1113 + 1114 + req_complete: 1115 + SETUP_DBG(udc, "ep0: Sending IN status without data\n"); 1116 + ast_udc_write(udc, EP0_TX_BUFF_RDY, AST_UDC_EP0_CTRL); 1117 + } 1118 + 1119 + static irqreturn_t ast_udc_isr(int irq, void *data) 1120 + { 1121 + struct ast_udc_dev *udc = (struct ast_udc_dev *)data; 1122 + struct ast_udc_ep *ep; 1123 + u32 isr, ep_isr; 1124 + int i; 1125 + 1126 + spin_lock(&udc->lock); 1127 + 1128 + isr = ast_udc_read(udc, AST_UDC_ISR); 1129 + if (!isr) 1130 + goto done; 1131 + 1132 + /* Ack interrupts */ 1133 + ast_udc_write(udc, isr, AST_UDC_ISR); 1134 + 1135 + if (isr & UDC_IRQ_BUS_RESET) { 1136 + ISR_DBG(udc, "UDC_IRQ_BUS_RESET\n"); 1137 + udc->gadget.speed = USB_SPEED_UNKNOWN; 1138 + 1139 + ep = &udc->ep[1]; 1140 + EP_DBG(ep, "dctrl:0x%x\n", 1141 + ast_ep_read(ep, AST_UDC_EP_DMA_CTRL)); 1142 + 1143 + if (udc->driver && udc->driver->reset) { 1144 + spin_unlock(&udc->lock); 1145 + udc->driver->reset(&udc->gadget); 1146 + spin_lock(&udc->lock); 1147 + } 1148 + } 1149 + 1150 + if (isr & UDC_IRQ_BUS_SUSPEND) { 1151 + ISR_DBG(udc, "UDC_IRQ_BUS_SUSPEND\n"); 1152 + udc->suspended_from = udc->gadget.state; 1153 + usb_gadget_set_state(&udc->gadget, USB_STATE_SUSPENDED); 1154 + 1155 + if (udc->driver && udc->driver->suspend) { 1156 + spin_unlock(&udc->lock); 1157 + udc->driver->suspend(&udc->gadget); 1158 + spin_lock(&udc->lock); 1159 + } 1160 + } 1161 + 1162 + if (isr & UDC_IRQ_BUS_RESUME) { 1163 + ISR_DBG(udc, "UDC_IRQ_BUS_RESUME\n"); 1164 + usb_gadget_set_state(&udc->gadget, udc->suspended_from); 1165 + 1166 + if (udc->driver && udc->driver->resume) { 1167 + spin_unlock(&udc->lock); 1168 + udc->driver->resume(&udc->gadget); 1169 + spin_lock(&udc->lock); 1170 + } 1171 + } 1172 + 1173 + if (isr & UDC_IRQ_EP0_IN_ACK_STALL) { 1174 + ISR_DBG(udc, "UDC_IRQ_EP0_IN_ACK_STALL\n"); 1175 + ast_udc_ep0_in(udc); 1176 + } 1177 + 1178 + if (isr & UDC_IRQ_EP0_OUT_ACK_STALL) { 1179 + ISR_DBG(udc, "UDC_IRQ_EP0_OUT_ACK_STALL\n"); 1180 + ast_udc_ep0_out(udc); 1181 + } 1182 + 1183 + if (isr & UDC_IRQ_EP0_SETUP) { 1184 + ISR_DBG(udc, "UDC_IRQ_EP0_SETUP\n"); 1185 + ast_udc_ep0_handle_setup(udc); 1186 + } 1187 + 1188 + if (isr & UDC_IRQ_EP_POOL_ACK_STALL) { 1189 + ISR_DBG(udc, "UDC_IRQ_EP_POOL_ACK_STALL\n"); 1190 + ep_isr = ast_udc_read(udc, AST_UDC_EP_ACK_ISR); 1191 + 1192 + /* Ack EP interrupts */ 1193 + ast_udc_write(udc, ep_isr, AST_UDC_EP_ACK_ISR); 1194 + 1195 + /* Handle each EP */ 1196 + for (i = 0; i < AST_UDC_NUM_ENDPOINTS - 1; i++) { 1197 + if (ep_isr & (0x1 << i)) { 1198 + ep = &udc->ep[i + 1]; 1199 + if (ep->desc_mode) 1200 + ast_udc_epn_handle_desc(udc, i + 1); 1201 + else 1202 + ast_udc_epn_handle(udc, i + 1); 1203 + } 1204 + } 1205 + } 1206 + 1207 + done: 1208 + spin_unlock(&udc->lock); 1209 + return IRQ_HANDLED; 1210 + } 1211 + 1212 + static int ast_udc_gadget_getframe(struct usb_gadget *gadget) 1213 + { 1214 + struct ast_udc_dev *udc = to_ast_dev(gadget); 1215 + 1216 + return (ast_udc_read(udc, AST_UDC_STS) >> 16) & 0x7ff; 1217 + } 1218 + 1219 + static void ast_udc_wake_work(struct work_struct *work) 1220 + { 1221 + struct ast_udc_dev *udc = container_of(work, struct ast_udc_dev, 1222 + wake_work); 1223 + unsigned long flags; 1224 + u32 ctrl; 1225 + 1226 + spin_lock_irqsave(&udc->lock, flags); 1227 + 1228 + UDC_DBG(udc, "Wakeup Host !\n"); 1229 + ctrl = ast_udc_read(udc, AST_UDC_FUNC_CTRL); 1230 + ast_udc_write(udc, ctrl | USB_REMOTE_WAKEUP_EN, AST_UDC_FUNC_CTRL); 1231 + 1232 + spin_unlock_irqrestore(&udc->lock, flags); 1233 + } 1234 + 1235 + static void ast_udc_wakeup_all(struct ast_udc_dev *udc) 1236 + { 1237 + /* 1238 + * A device is trying to wake the world, because this 1239 + * can recurse into the device, we break the call chain 1240 + * using a work queue 1241 + */ 1242 + schedule_work(&udc->wake_work); 1243 + } 1244 + 1245 + static int ast_udc_wakeup(struct usb_gadget *gadget) 1246 + { 1247 + struct ast_udc_dev *udc = to_ast_dev(gadget); 1248 + unsigned long flags; 1249 + int rc = 0; 1250 + 1251 + spin_lock_irqsave(&udc->lock, flags); 1252 + 1253 + if (!udc->wakeup_en) { 1254 + UDC_DBG(udc, "Remote Wakeup is disabled\n"); 1255 + rc = -EINVAL; 1256 + goto err; 1257 + } 1258 + 1259 + UDC_DBG(udc, "Device initiated wakeup\n"); 1260 + ast_udc_wakeup_all(udc); 1261 + 1262 + err: 1263 + spin_unlock_irqrestore(&udc->lock, flags); 1264 + return rc; 1265 + } 1266 + 1267 + /* 1268 + * Activate/Deactivate link with host 1269 + */ 1270 + static int ast_udc_pullup(struct usb_gadget *gadget, int is_on) 1271 + { 1272 + struct ast_udc_dev *udc = to_ast_dev(gadget); 1273 + unsigned long flags; 1274 + u32 ctrl; 1275 + 1276 + spin_lock_irqsave(&udc->lock, flags); 1277 + 1278 + UDC_DBG(udc, "is_on: %d\n", is_on); 1279 + if (is_on) 1280 + ctrl = ast_udc_read(udc, AST_UDC_FUNC_CTRL) | USB_UPSTREAM_EN; 1281 + else 1282 + ctrl = ast_udc_read(udc, AST_UDC_FUNC_CTRL) & ~USB_UPSTREAM_EN; 1283 + 1284 + ast_udc_write(udc, ctrl, AST_UDC_FUNC_CTRL); 1285 + 1286 + spin_unlock_irqrestore(&udc->lock, flags); 1287 + 1288 + return 0; 1289 + } 1290 + 1291 + static int ast_udc_start(struct usb_gadget *gadget, 1292 + struct usb_gadget_driver *driver) 1293 + { 1294 + struct ast_udc_dev *udc = to_ast_dev(gadget); 1295 + struct ast_udc_ep *ep; 1296 + unsigned long flags; 1297 + int i; 1298 + 1299 + spin_lock_irqsave(&udc->lock, flags); 1300 + 1301 + UDC_DBG(udc, "\n"); 1302 + udc->driver = driver; 1303 + udc->gadget.dev.of_node = udc->pdev->dev.of_node; 1304 + 1305 + for (i = 0; i < AST_UDC_NUM_ENDPOINTS; i++) { 1306 + ep = &udc->ep[i]; 1307 + ep->stopped = 0; 1308 + } 1309 + 1310 + spin_unlock_irqrestore(&udc->lock, flags); 1311 + 1312 + return 0; 1313 + } 1314 + 1315 + static int ast_udc_stop(struct usb_gadget *gadget) 1316 + { 1317 + struct ast_udc_dev *udc = to_ast_dev(gadget); 1318 + unsigned long flags; 1319 + u32 ctrl; 1320 + 1321 + spin_lock_irqsave(&udc->lock, flags); 1322 + 1323 + UDC_DBG(udc, "\n"); 1324 + ctrl = ast_udc_read(udc, AST_UDC_FUNC_CTRL) & ~USB_UPSTREAM_EN; 1325 + ast_udc_write(udc, ctrl, AST_UDC_FUNC_CTRL); 1326 + 1327 + udc->gadget.speed = USB_SPEED_UNKNOWN; 1328 + udc->driver = NULL; 1329 + 1330 + ast_udc_stop_activity(udc); 1331 + usb_gadget_set_state(&udc->gadget, USB_STATE_NOTATTACHED); 1332 + 1333 + spin_unlock_irqrestore(&udc->lock, flags); 1334 + 1335 + return 0; 1336 + } 1337 + 1338 + static const struct usb_gadget_ops ast_udc_ops = { 1339 + .get_frame = ast_udc_gadget_getframe, 1340 + .wakeup = ast_udc_wakeup, 1341 + .pullup = ast_udc_pullup, 1342 + .udc_start = ast_udc_start, 1343 + .udc_stop = ast_udc_stop, 1344 + }; 1345 + 1346 + /* 1347 + * Support 1 Control Endpoint. 1348 + * Support multiple programmable endpoints that can be configured to 1349 + * Bulk IN/OUT, Interrupt IN/OUT, and Isochronous IN/OUT type endpoint. 1350 + */ 1351 + static void ast_udc_init_ep(struct ast_udc_dev *udc) 1352 + { 1353 + struct ast_udc_ep *ep; 1354 + int i; 1355 + 1356 + for (i = 0; i < AST_UDC_NUM_ENDPOINTS; i++) { 1357 + ep = &udc->ep[i]; 1358 + ep->ep.name = ast_ep_name[i]; 1359 + if (i == 0) { 1360 + ep->ep.caps.type_control = true; 1361 + } else { 1362 + ep->ep.caps.type_iso = true; 1363 + ep->ep.caps.type_bulk = true; 1364 + ep->ep.caps.type_int = true; 1365 + } 1366 + ep->ep.caps.dir_in = true; 1367 + ep->ep.caps.dir_out = true; 1368 + 1369 + ep->ep.ops = &ast_udc_ep_ops; 1370 + ep->udc = udc; 1371 + 1372 + INIT_LIST_HEAD(&ep->queue); 1373 + 1374 + if (i == 0) { 1375 + usb_ep_set_maxpacket_limit(&ep->ep, 1376 + AST_UDC_EP0_MAX_PACKET); 1377 + continue; 1378 + } 1379 + 1380 + ep->ep_reg = udc->reg + AST_UDC_EP_BASE + 1381 + (AST_UDC_EP_OFFSET * (i - 1)); 1382 + 1383 + ep->epn_buf = udc->ep0_buf + (i * AST_UDC_EP_DMA_SIZE); 1384 + ep->epn_buf_dma = udc->ep0_buf_dma + (i * AST_UDC_EP_DMA_SIZE); 1385 + usb_ep_set_maxpacket_limit(&ep->ep, AST_UDC_EPn_MAX_PACKET); 1386 + 1387 + ep->descs = ep->epn_buf + AST_UDC_EPn_MAX_PACKET; 1388 + ep->descs_dma = ep->epn_buf_dma + AST_UDC_EPn_MAX_PACKET; 1389 + ep->descs_wptr = 0; 1390 + 1391 + list_add_tail(&ep->ep.ep_list, &udc->gadget.ep_list); 1392 + } 1393 + } 1394 + 1395 + static void ast_udc_init_dev(struct ast_udc_dev *udc) 1396 + { 1397 + INIT_WORK(&udc->wake_work, ast_udc_wake_work); 1398 + } 1399 + 1400 + static void ast_udc_init_hw(struct ast_udc_dev *udc) 1401 + { 1402 + u32 ctrl; 1403 + 1404 + /* Enable PHY */ 1405 + ctrl = USB_PHY_CLK_EN | USB_PHY_RESET_DIS; 1406 + ast_udc_write(udc, ctrl, AST_UDC_FUNC_CTRL); 1407 + 1408 + udelay(1); 1409 + ast_udc_write(udc, 0, AST_UDC_DEV_RESET); 1410 + 1411 + /* Set descriptor ring size */ 1412 + if (AST_UDC_DESCS_COUNT == 256) { 1413 + ctrl |= USB_EP_LONG_DESC; 1414 + ast_udc_write(udc, ctrl, AST_UDC_FUNC_CTRL); 1415 + } 1416 + 1417 + /* Mask & ack all interrupts before installing the handler */ 1418 + ast_udc_write(udc, 0, AST_UDC_IER); 1419 + ast_udc_write(udc, UDC_IRQ_ACK_ALL, AST_UDC_ISR); 1420 + 1421 + /* Enable some interrupts */ 1422 + ctrl = UDC_IRQ_EP_POOL_ACK_STALL | UDC_IRQ_BUS_RESUME | 1423 + UDC_IRQ_BUS_SUSPEND | UDC_IRQ_BUS_RESET | 1424 + UDC_IRQ_EP0_IN_ACK_STALL | UDC_IRQ_EP0_OUT_ACK_STALL | 1425 + UDC_IRQ_EP0_SETUP; 1426 + ast_udc_write(udc, ctrl, AST_UDC_IER); 1427 + 1428 + /* Cleanup and enable ep ACK interrupts */ 1429 + ast_udc_write(udc, UDC_IRQ_EP_ACK_ALL, AST_UDC_EP_ACK_IER); 1430 + ast_udc_write(udc, UDC_IRQ_EP_ACK_ALL, AST_UDC_EP_ACK_ISR); 1431 + 1432 + ast_udc_write(udc, 0, AST_UDC_EP0_CTRL); 1433 + } 1434 + 1435 + static int ast_udc_remove(struct platform_device *pdev) 1436 + { 1437 + struct ast_udc_dev *udc = platform_get_drvdata(pdev); 1438 + unsigned long flags; 1439 + u32 ctrl; 1440 + 1441 + usb_del_gadget_udc(&udc->gadget); 1442 + if (udc->driver) 1443 + return -EBUSY; 1444 + 1445 + spin_lock_irqsave(&udc->lock, flags); 1446 + 1447 + /* Disable upstream port connection */ 1448 + ctrl = ast_udc_read(udc, AST_UDC_FUNC_CTRL) & ~USB_UPSTREAM_EN; 1449 + ast_udc_write(udc, ctrl, AST_UDC_FUNC_CTRL); 1450 + 1451 + clk_disable_unprepare(udc->clk); 1452 + 1453 + spin_unlock_irqrestore(&udc->lock, flags); 1454 + 1455 + if (udc->ep0_buf) 1456 + dma_free_coherent(&pdev->dev, 1457 + AST_UDC_EP_DMA_SIZE * AST_UDC_NUM_ENDPOINTS, 1458 + udc->ep0_buf, 1459 + udc->ep0_buf_dma); 1460 + 1461 + udc->ep0_buf = NULL; 1462 + 1463 + return 0; 1464 + } 1465 + 1466 + static int ast_udc_probe(struct platform_device *pdev) 1467 + { 1468 + enum usb_device_speed max_speed; 1469 + struct device *dev = &pdev->dev; 1470 + struct ast_udc_dev *udc; 1471 + struct resource *res; 1472 + int rc; 1473 + 1474 + udc = devm_kzalloc(&pdev->dev, sizeof(struct ast_udc_dev), GFP_KERNEL); 1475 + if (!udc) 1476 + return -ENOMEM; 1477 + 1478 + udc->gadget.dev.parent = dev; 1479 + udc->pdev = pdev; 1480 + spin_lock_init(&udc->lock); 1481 + 1482 + udc->gadget.ops = &ast_udc_ops; 1483 + udc->gadget.ep0 = &udc->ep[0].ep; 1484 + udc->gadget.name = "aspeed-udc"; 1485 + udc->gadget.dev.init_name = "gadget"; 1486 + 1487 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1488 + udc->reg = devm_ioremap_resource(&pdev->dev, res); 1489 + if (IS_ERR(udc->reg)) { 1490 + dev_err(&pdev->dev, "Failed to map resources\n"); 1491 + return PTR_ERR(udc->reg); 1492 + } 1493 + 1494 + platform_set_drvdata(pdev, udc); 1495 + 1496 + udc->clk = devm_clk_get(&pdev->dev, NULL); 1497 + if (IS_ERR(udc->clk)) { 1498 + rc = PTR_ERR(udc->clk); 1499 + goto err; 1500 + } 1501 + rc = clk_prepare_enable(udc->clk); 1502 + if (rc) { 1503 + dev_err(&pdev->dev, "Failed to enable clock (0x%x)\n", rc); 1504 + goto err; 1505 + } 1506 + 1507 + /* Check if we need to limit the HW to USB1 */ 1508 + max_speed = usb_get_maximum_speed(&pdev->dev); 1509 + if (max_speed != USB_SPEED_UNKNOWN && max_speed < USB_SPEED_HIGH) 1510 + udc->force_usb1 = true; 1511 + 1512 + /* 1513 + * Allocate DMA buffers for all EPs in one chunk 1514 + */ 1515 + udc->ep0_buf = dma_alloc_coherent(&pdev->dev, 1516 + AST_UDC_EP_DMA_SIZE * 1517 + AST_UDC_NUM_ENDPOINTS, 1518 + &udc->ep0_buf_dma, GFP_KERNEL); 1519 + 1520 + udc->gadget.speed = USB_SPEED_UNKNOWN; 1521 + udc->gadget.max_speed = USB_SPEED_HIGH; 1522 + udc->creq = udc->reg + AST_UDC_SETUP0; 1523 + 1524 + /* 1525 + * Support single stage mode or 32/256 stages descriptor mode. 1526 + * Set default as Descriptor Mode. 1527 + */ 1528 + udc->desc_mode = AST_UDC_DESC_MODE; 1529 + 1530 + dev_info(&pdev->dev, "DMA %s\n", udc->desc_mode ? 1531 + "descriptor mode" : "single mode"); 1532 + 1533 + INIT_LIST_HEAD(&udc->gadget.ep_list); 1534 + INIT_LIST_HEAD(&udc->gadget.ep0->ep_list); 1535 + 1536 + /* Initialized udc ep */ 1537 + ast_udc_init_ep(udc); 1538 + 1539 + /* Initialized udc device */ 1540 + ast_udc_init_dev(udc); 1541 + 1542 + /* Initialized udc hardware */ 1543 + ast_udc_init_hw(udc); 1544 + 1545 + /* Find interrupt and install handler */ 1546 + udc->irq = platform_get_irq(pdev, 0); 1547 + if (udc->irq < 0) { 1548 + rc = udc->irq; 1549 + goto err; 1550 + } 1551 + 1552 + rc = devm_request_irq(&pdev->dev, udc->irq, ast_udc_isr, 0, 1553 + KBUILD_MODNAME, udc); 1554 + if (rc) { 1555 + dev_err(&pdev->dev, "Failed to request interrupt\n"); 1556 + goto err; 1557 + } 1558 + 1559 + rc = usb_add_gadget_udc(&pdev->dev, &udc->gadget); 1560 + if (rc) { 1561 + dev_err(&pdev->dev, "Failed to add gadget udc\n"); 1562 + goto err; 1563 + } 1564 + 1565 + dev_info(&pdev->dev, "Initialized udc in USB%s mode\n", 1566 + udc->force_usb1 ? "1" : "2"); 1567 + 1568 + return 0; 1569 + 1570 + err: 1571 + dev_err(&pdev->dev, "Failed to udc probe, rc:0x%x\n", rc); 1572 + ast_udc_remove(pdev); 1573 + 1574 + return rc; 1575 + } 1576 + 1577 + static const struct of_device_id ast_udc_of_dt_ids[] = { 1578 + { .compatible = "aspeed,ast2600-udc", }, 1579 + {} 1580 + }; 1581 + 1582 + MODULE_DEVICE_TABLE(of, ast_udc_of_dt_ids); 1583 + 1584 + static struct platform_driver ast_udc_driver = { 1585 + .probe = ast_udc_probe, 1586 + .remove = ast_udc_remove, 1587 + .driver = { 1588 + .name = KBUILD_MODNAME, 1589 + .of_match_table = ast_udc_of_dt_ids, 1590 + }, 1591 + }; 1592 + 1593 + module_platform_driver(ast_udc_driver); 1594 + 1595 + MODULE_DESCRIPTION("ASPEED UDC driver"); 1596 + MODULE_AUTHOR("Neal Liu <neal_liu@aspeedtech.com>"); 1597 + MODULE_LICENSE("GPL");
+6 -4
drivers/usb/gadget/udc/atmel_usba_udc.c
··· 2060 2060 .pulse_bias = at91sam9g45_pulse_bias, 2061 2061 }; 2062 2062 2063 - static const struct usba_ep_config ep_config_sam9[] __initconst = { 2063 + static const struct usba_ep_config ep_config_sam9[] = { 2064 2064 { .nr_banks = 1 }, /* ep 0 */ 2065 2065 { .nr_banks = 2, .can_dma = 1, .can_isoc = 1 }, /* ep 1 */ 2066 2066 { .nr_banks = 2, .can_dma = 1, .can_isoc = 1 }, /* ep 2 */ ··· 2070 2070 { .nr_banks = 3, .can_dma = 1, .can_isoc = 1 }, /* ep 6 */ 2071 2071 }; 2072 2072 2073 - static const struct usba_ep_config ep_config_sama5[] __initconst = { 2073 + static const struct usba_ep_config ep_config_sama5[] = { 2074 2074 { .nr_banks = 1 }, /* ep 0 */ 2075 2075 { .nr_banks = 3, .can_dma = 1, .can_isoc = 1 }, /* ep 1 */ 2076 2076 { .nr_banks = 3, .can_dma = 1, .can_isoc = 1 }, /* ep 2 */ ··· 2165 2165 2166 2166 udc->vbus_pin = devm_gpiod_get_optional(&pdev->dev, "atmel,vbus", 2167 2167 GPIOD_IN); 2168 + if (IS_ERR(udc->vbus_pin)) 2169 + return ERR_CAST(udc->vbus_pin); 2168 2170 2169 2171 if (fifo_mode == 0) { 2170 2172 udc->num_ep = udc_config->num_ep; ··· 2449 2447 static SIMPLE_DEV_PM_OPS(usba_udc_pm_ops, usba_udc_suspend, usba_udc_resume); 2450 2448 2451 2449 static struct platform_driver udc_driver = { 2450 + .probe = usba_udc_probe, 2452 2451 .remove = usba_udc_remove, 2453 2452 .driver = { 2454 2453 .name = "atmel_usba_udc", ··· 2457 2454 .of_match_table = atmel_udc_dt_ids, 2458 2455 }, 2459 2456 }; 2460 - 2461 - module_platform_driver_probe(udc_driver, usba_udc_probe); 2457 + module_platform_driver(udc_driver); 2462 2458 2463 2459 MODULE_DESCRIPTION("Atmel USBA UDC driver"); 2464 2460 MODULE_AUTHOR("Haavard Skinnemoen (Atmel)");
+1 -1
drivers/usb/gadget/udc/bdc/bdc_cmd.c
··· 307 307 * his will reset the seq number for non EP0. 308 308 */ 309 309 if (epnum != 1) { 310 - /* if the endpoint it not stallled */ 310 + /* if the endpoint it not stalled */ 311 311 if (!(ep->flags & BDC_EP_STALL)) { 312 312 ret = bdc_ep_set_stall(bdc, epnum); 313 313 if (ret)
+6 -5
drivers/usb/gadget/udc/core.c
··· 1728 1728 return ret; 1729 1729 } 1730 1730 1731 - if (udc->driver) { 1731 + mutex_lock(&udc_lock); 1732 + if (udc->driver) 1732 1733 ret = add_uevent_var(env, "USB_UDC_DRIVER=%s", 1733 1734 udc->driver->function); 1734 - if (ret) { 1735 - dev_err(dev, "failed to add uevent USB_UDC_DRIVER\n"); 1736 - return ret; 1737 - } 1735 + mutex_unlock(&udc_lock); 1736 + if (ret) { 1737 + dev_err(dev, "failed to add uevent USB_UDC_DRIVER\n"); 1738 + return ret; 1738 1739 } 1739 1740 1740 1741 return 0;
+4 -4
drivers/usb/gadget/udc/tegra-xudc.c
··· 3691 3691 int err; 3692 3692 3693 3693 xudc->genpd_dev_device = dev_pm_domain_attach_by_name(dev, "dev"); 3694 - if (IS_ERR(xudc->genpd_dev_device)) { 3695 - err = PTR_ERR(xudc->genpd_dev_device); 3694 + if (IS_ERR_OR_NULL(xudc->genpd_dev_device)) { 3695 + err = PTR_ERR(xudc->genpd_dev_device) ? : -ENODATA; 3696 3696 dev_err(dev, "failed to get device power domain: %d\n", err); 3697 3697 return err; 3698 3698 } 3699 3699 3700 3700 xudc->genpd_dev_ss = dev_pm_domain_attach_by_name(dev, "ss"); 3701 - if (IS_ERR(xudc->genpd_dev_ss)) { 3702 - err = PTR_ERR(xudc->genpd_dev_ss); 3701 + if (IS_ERR_OR_NULL(xudc->genpd_dev_ss)) { 3702 + err = PTR_ERR(xudc->genpd_dev_ss) ? : -ENODATA; 3703 3703 dev_err(dev, "failed to get SuperSpeed power domain: %d\n", err); 3704 3704 return err; 3705 3705 }
+4 -4
drivers/usb/gadget/udc/trace.h
··· 140 140 TP_PROTO(struct usb_ep *ep, int ret), 141 141 TP_ARGS(ep, ret), 142 142 TP_STRUCT__entry( 143 - __dynamic_array(char, name, UDC_TRACE_STR_MAX) 143 + __string(name, ep->name) 144 144 __field(unsigned, maxpacket) 145 145 __field(unsigned, maxpacket_limit) 146 146 __field(unsigned, max_streams) ··· 152 152 __field(int, ret) 153 153 ), 154 154 TP_fast_assign( 155 - snprintf(__get_str(name), UDC_TRACE_STR_MAX, "%s", ep->name); 155 + __assign_str(name, ep->name); 156 156 __entry->maxpacket = ep->maxpacket; 157 157 __entry->maxpacket_limit = ep->maxpacket_limit; 158 158 __entry->max_streams = ep->max_streams; ··· 214 214 TP_PROTO(struct usb_ep *ep, struct usb_request *req, int ret), 215 215 TP_ARGS(ep, req, ret), 216 216 TP_STRUCT__entry( 217 - __dynamic_array(char, name, UDC_TRACE_STR_MAX) 217 + __string(name, ep->name) 218 218 __field(unsigned, length) 219 219 __field(unsigned, actual) 220 220 __field(unsigned, num_sgs) ··· 228 228 __field(struct usb_request *, req) 229 229 ), 230 230 TP_fast_assign( 231 - snprintf(__get_str(name), UDC_TRACE_STR_MAX, "%s", ep->name); 231 + __assign_str(name, ep->name); 232 232 __entry->length = req->length; 233 233 __entry->actual = req->actual; 234 234 __entry->num_sgs = req->num_sgs;
+10
drivers/usb/host/Kconfig
··· 306 306 Dova, Armada 370 and Armada XP. See "Support for Marvell EBU 307 307 on-chip EHCI USB controller" for those. 308 308 309 + config USB_OCTEON_HCD 310 + tristate "Cavium Networks Octeon USB support" 311 + depends on CAVIUM_OCTEON_SOC && USB 312 + help 313 + This driver supports USB host controller on some Cavium 314 + Networks' products in the Octeon family. 315 + 316 + To compile this driver as a module, choose M here. The module 317 + will be called octeon-hcd. 318 + 309 319 config USB_CNS3XXX_EHCI 310 320 bool "Cavium CNS3XXX EHCI Module (DEPRECATED)" 311 321 depends on ARCH_CNS3XXX || COMPILE_TEST
+1
drivers/usb/host/Makefile
··· 63 63 obj-$(CONFIG_USB_OHCI_HCD_LPC32XX) += ohci-nxp.o 64 64 obj-$(CONFIG_USB_OHCI_HCD_PXA27X) += ohci-pxa27x.o 65 65 obj-$(CONFIG_USB_OHCI_HCD_DAVINCI) += ohci-da8xx.o 66 + obj-$(CONFIG_USB_OCTEON_HCD) += octeon-hcd.o 66 67 67 68 obj-$(CONFIG_USB_UHCI_HCD) += uhci-hcd.o 68 69 obj-$(CONFIG_USB_FHCI_HCD) += fhci.o
+2
drivers/usb/host/ehci-platform.c
··· 370 370 hcd->rsrc_start = res_mem->start; 371 371 hcd->rsrc_len = resource_size(res_mem); 372 372 373 + hcd->tpl_support = of_usb_host_tpl_support(dev->dev.of_node); 374 + 373 375 err = usb_add_hcd(hcd, irq, IRQF_SHARED); 374 376 if (err) 375 377 goto err_power;
+1
drivers/usb/host/ehci-ppc-of.c
··· 148 148 } else { 149 149 ehci->has_amcc_usb23 = 1; 150 150 } 151 + of_node_put(np); 151 152 } 152 153 153 154 if (of_get_property(dn, "big-endian", NULL)) {
+1 -1
drivers/usb/host/ehci-q.c
··· 1162 1162 * This is done in two parts: first SETUP req for GetDesc is sent then 1163 1163 * 15 seconds later, the IN stage for GetDesc starts to req data from dev 1164 1164 * 1165 - * is_setup : i/p arguement decides which of the two stage needs to be 1165 + * is_setup : i/p argument decides which of the two stage needs to be 1166 1166 * performed; TRUE - SETUP and FALSE - IN+STATUS 1167 1167 * Returns 0 if success 1168 1168 */
+1 -1
drivers/usb/host/max3421-hcd.c
··· 312 312 313 313 /* 314 314 * See https://www.beyondlogic.org/usbnutshell/usb4.shtml#Control for a 315 - * reasonable overview of how control transfers use the the IN/OUT 315 + * reasonable overview of how control transfers use the IN/OUT 316 316 * tokens. 317 317 */ 318 318 #define MAX3421_HXFR_BULK_IN(ep) (0x00 | (ep)) /* bulk or interrupt */
+46 -23
drivers/usb/host/ohci-at91.c
··· 13 13 * This file is licenced under the GPL. 14 14 */ 15 15 16 + #include <linux/arm-smccc.h> 16 17 #include <linux/clk.h> 17 18 #include <linux/dma-mapping.h> 18 19 #include <linux/gpio/consumer.h> ··· 56 55 bool clocked; 57 56 bool wakeup; /* Saved wake-up state for resume */ 58 57 struct regmap *sfr_regmap; 58 + u32 suspend_smc_id; 59 59 }; 60 60 /* interface and function clocks; sometimes also an AHB clock */ 61 61 ··· 136 134 /*-------------------------------------------------------------------------*/ 137 135 138 136 static void usb_hcd_at91_remove (struct usb_hcd *, struct platform_device *); 137 + 138 + static u32 at91_dt_suspend_smc(struct device *dev) 139 + { 140 + u32 suspend_smc_id; 141 + 142 + if (!dev->of_node) 143 + return 0; 144 + 145 + if (of_property_read_u32(dev->of_node, "microchip,suspend-smc-id", &suspend_smc_id)) 146 + return 0; 147 + 148 + return suspend_smc_id; 149 + } 139 150 140 151 static struct regmap *at91_dt_syscon_sfr(void) 141 152 { ··· 230 215 goto err; 231 216 } 232 217 233 - ohci_at91->sfr_regmap = at91_dt_syscon_sfr(); 234 - if (!ohci_at91->sfr_regmap) 235 - dev_dbg(dev, "failed to find sfr node\n"); 218 + ohci_at91->suspend_smc_id = at91_dt_suspend_smc(dev); 219 + if (!ohci_at91->suspend_smc_id) { 220 + dev_dbg(dev, "failed to find sfr suspend smc id, using regmap\n"); 221 + ohci_at91->sfr_regmap = at91_dt_syscon_sfr(); 222 + if (!ohci_at91->sfr_regmap) 223 + dev_dbg(dev, "failed to find sfr node\n"); 224 + } 236 225 237 226 board = hcd->self.controller->platform_data; 238 227 ohci = hcd_to_ohci(hcd); ··· 322 303 return length; 323 304 } 324 305 325 - static int ohci_at91_port_suspend(struct regmap *regmap, u8 set) 306 + static int ohci_at91_port_suspend(struct ohci_at91_priv *ohci_at91, u8 set) 326 307 { 308 + struct regmap *regmap = ohci_at91->sfr_regmap; 327 309 u32 regval; 328 310 int ret; 329 311 330 - if (!regmap) 331 - return 0; 312 + if (ohci_at91->suspend_smc_id) { 313 + struct arm_smccc_res res; 332 314 333 - ret = regmap_read(regmap, AT91_SFR_OHCIICR, &regval); 334 - if (ret) 335 - return ret; 315 + arm_smccc_smc(ohci_at91->suspend_smc_id, set, 0, 0, 0, 0, 0, 0, &res); 316 + if (res.a0) 317 + return -EINVAL; 318 + } else if (regmap) { 319 + ret = regmap_read(regmap, AT91_SFR_OHCIICR, &regval); 320 + if (ret) 321 + return ret; 336 322 337 - if (set) 338 - regval |= AT91_OHCIICR_USB_SUSPEND; 339 - else 340 - regval &= ~AT91_OHCIICR_USB_SUSPEND; 323 + if (set) 324 + regval |= AT91_OHCIICR_USB_SUSPEND; 325 + else 326 + regval &= ~AT91_OHCIICR_USB_SUSPEND; 341 327 342 - regmap_write(regmap, AT91_SFR_OHCIICR, regval); 328 + regmap_write(regmap, AT91_SFR_OHCIICR, regval); 329 + } 343 330 344 331 return 0; 345 332 } ··· 382 357 383 358 case USB_PORT_FEAT_SUSPEND: 384 359 dev_dbg(hcd->self.controller, "SetPortFeat: SUSPEND\n"); 385 - if (valid_port(wIndex) && ohci_at91->sfr_regmap) { 386 - ohci_at91_port_suspend(ohci_at91->sfr_regmap, 387 - 1); 360 + if (valid_port(wIndex)) { 361 + ohci_at91_port_suspend(ohci_at91, 1); 388 362 return 0; 389 363 } 390 364 break; ··· 424 400 425 401 case USB_PORT_FEAT_SUSPEND: 426 402 dev_dbg(hcd->self.controller, "ClearPortFeature: SUSPEND\n"); 427 - if (valid_port(wIndex) && ohci_at91->sfr_regmap) { 428 - ohci_at91_port_suspend(ohci_at91->sfr_regmap, 429 - 0); 403 + if (valid_port(wIndex)) { 404 + ohci_at91_port_suspend(ohci_at91, 0); 430 405 return 0; 431 406 } 432 407 break; ··· 653 630 /* flush the writes */ 654 631 (void) ohci_readl (ohci, &ohci->regs->control); 655 632 msleep(1); 656 - ohci_at91_port_suspend(ohci_at91->sfr_regmap, 1); 633 + ohci_at91_port_suspend(ohci_at91, 1); 657 634 at91_stop_clock(ohci_at91); 658 635 } else { 659 - ohci_at91_port_suspend(ohci_at91->sfr_regmap, 1); 636 + ohci_at91_port_suspend(ohci_at91, 1); 660 637 } 661 638 662 639 return ret; ··· 668 645 struct usb_hcd *hcd = dev_get_drvdata(dev); 669 646 struct ohci_at91_priv *ohci_at91 = hcd_to_ohci_at91_priv(hcd); 670 647 671 - ohci_at91_port_suspend(ohci_at91->sfr_regmap, 0); 648 + ohci_at91_port_suspend(ohci_at91, 0); 672 649 673 650 if (ohci_at91->wakeup) 674 651 disable_irq_wake(hcd->irq);
+1
drivers/usb/host/ohci-nxp.c
··· 164 164 } 165 165 166 166 isp1301_i2c_client = isp1301_get_client(isp1301_node); 167 + of_node_put(isp1301_node); 167 168 if (!isp1301_i2c_client) 168 169 return -EPROBE_DEFER; 169 170
+3
drivers/usb/host/ohci-platform.c
··· 28 28 #include <linux/usb/ohci_pdriver.h> 29 29 #include <linux/usb.h> 30 30 #include <linux/usb/hcd.h> 31 + #include <linux/usb/of.h> 31 32 32 33 #include "ohci.h" 33 34 ··· 210 209 } 211 210 hcd->rsrc_start = res_mem->start; 212 211 hcd->rsrc_len = resource_size(res_mem); 212 + 213 + hcd->tpl_support = of_usb_host_tpl_support(dev->dev.of_node); 213 214 214 215 err = usb_add_hcd(hcd, irq, IRQF_SHARED); 215 216 if (err)
+1
drivers/usb/host/ohci-ppc-of.c
··· 166 166 release_mem_region(res.start, 0x4); 167 167 } else 168 168 pr_debug("%s: cannot get ehci offset from fdt\n", __FILE__); 169 + of_node_put(np); 169 170 } 170 171 171 172 irq_dispose_mapping(irq);
+1 -1
drivers/usb/host/ohci-sm501.c
··· 153 153 * fine. This is however not always the case - buffers may be allocated 154 154 * using kmalloc() - so the usb core needs to be told that it must copy 155 155 * data into our local memory if the buffers happen to be placed in 156 - * regular memory. A non-null hcd->localmem_pool initialized by the 156 + * regular memory. A non-null hcd->localmem_pool initialized by 157 157 * the call to usb_hcd_setup_local_mem() below does just that. 158 158 */ 159 159
+1 -1
drivers/usb/host/uhci-grlib.c
··· 43 43 44 44 uhci->rh_numports = uhci_count_ports(hcd); 45 45 46 - /* Set up pointers to to generic functions */ 46 + /* Set up pointers to generic functions */ 47 47 uhci->reset_hc = uhci_generic_reset_hc; 48 48 uhci->check_and_reset_hc = uhci_generic_check_and_reset_hc; 49 49 /* No special actions need to be taken for the functions below */
+1 -1
drivers/usb/host/uhci-hcd.h
··· 314 314 * 315 315 * There's a special skeleton QH for Isochronous QHs which never appears 316 316 * on the schedule. Isochronous TDs go on the schedule before the 317 - * the skeleton QHs. The hardware accesses them directly rather than 317 + * skeleton QHs. The hardware accesses them directly rather than 318 318 * through their QH, which is used only for bookkeeping purposes. 319 319 * While the UHCI spec doesn't forbid the use of QHs for Isochronous, 320 320 * it doesn't use them either. And the spec says that queues never
+7
drivers/usb/host/xhci-mtk.c
··· 18 18 #include <linux/pm_wakeirq.h> 19 19 #include <linux/regmap.h> 20 20 #include <linux/regulator/consumer.h> 21 + #include <linux/reset.h> 21 22 22 23 #include "xhci.h" 23 24 #include "xhci-mtk.h" ··· 550 549 ret = clk_bulk_prepare_enable(BULK_CLKS_NUM, mtk->clks); 551 550 if (ret) 552 551 goto disable_ldos; 552 + 553 + ret = device_reset_optional(dev); 554 + if (ret) { 555 + dev_err_probe(dev, ret, "failed to reset controller\n"); 556 + goto disable_clk; 557 + } 553 558 554 559 hcd = usb_create_hcd(driver, dev, dev_name(dev)); 555 560 if (!hcd) {
-4
drivers/usb/host/xhci-pci-renesas.c
··· 120 120 size_t length) 121 121 { 122 122 u16 fw_version_pointer; 123 - u16 fw_version; 124 123 125 124 /* 126 125 * The Firmware's Data Format is describe in ··· 148 149 pr_err("fw ver pointer is outside of the firmware image"); 149 150 return -EINVAL; 150 151 } 151 - 152 - fw_version = get_unaligned_le16(fw_data + fw_version_pointer); 153 - pr_err("got firmware version: %02x.", fw_version); 154 152 155 153 return 0; 156 154 }
+1 -1
drivers/usb/host/xhci-ring.c
··· 1964 1964 1965 1965 /* 1966 1966 * Check to see if xhci-hub.c is waiting on RExit to U0 transition (or 1967 - * RExit to a disconnect state). If so, let the the driver know it's 1967 + * RExit to a disconnect state). If so, let the driver know it's 1968 1968 * out of the RExit state. 1969 1969 */ 1970 1970 if (!DEV_SUPERSPEED_ANY(portsc) && hcd->speed < HCD_USB3 &&
+4 -4
drivers/usb/host/xhci-tegra.c
··· 1010 1010 int err; 1011 1011 1012 1012 tegra->genpd_dev_host = dev_pm_domain_attach_by_name(dev, "xusb_host"); 1013 - if (IS_ERR(tegra->genpd_dev_host)) { 1014 - err = PTR_ERR(tegra->genpd_dev_host); 1013 + if (IS_ERR_OR_NULL(tegra->genpd_dev_host)) { 1014 + err = PTR_ERR(tegra->genpd_dev_host) ? : -ENODATA; 1015 1015 dev_err(dev, "failed to get host pm-domain: %d\n", err); 1016 1016 return err; 1017 1017 } 1018 1018 1019 1019 tegra->genpd_dev_ss = dev_pm_domain_attach_by_name(dev, "xusb_ss"); 1020 - if (IS_ERR(tegra->genpd_dev_ss)) { 1021 - err = PTR_ERR(tegra->genpd_dev_ss); 1020 + if (IS_ERR_OR_NULL(tegra->genpd_dev_ss)) { 1021 + err = PTR_ERR(tegra->genpd_dev_ss) ? : -ENODATA; 1022 1022 dev_err(dev, "failed to get superspeed pm-domain: %d\n", err); 1023 1023 return err; 1024 1024 }
+1 -1
drivers/usb/host/xhci.h
··· 2417 2417 field3 & TRB_CYCLE ? 'C' : 'c'); 2418 2418 break; 2419 2419 case TRB_STOP_RING: 2420 - sprintf(str, 2420 + snprintf(str, size, 2421 2421 "%s: slot %d sp %d ep %d flags %c", 2422 2422 xhci_trb_type_string(type), 2423 2423 TRB_TO_SLOT_ID(field3),
+1 -1
drivers/usb/image/mdc800.c
··· 38 38 * 39 39 * version 0.7.3 40 40 * bugfix : The mdc800->state field gets set to READY after the 41 - * the disconnect function sets it to NOT_CONNECTED. This makes the 41 + * disconnect function sets it to NOT_CONNECTED. This makes the 42 42 * driver running like the camera is connected and causes some 43 43 * hang ups. 44 44 *
+16
drivers/usb/misc/Kconfig
··· 295 295 This option enables support for remapping some USB external 296 296 signals, which are typically on dedicated pins on the chip, 297 297 to any gpio. 298 + 299 + config USB_ONBOARD_HUB 300 + tristate "Onboard USB hub support" 301 + depends on OF || COMPILE_TEST 302 + help 303 + Say Y here if you want to support discrete onboard USB hubs that 304 + don't require an additional control bus for initialization, but 305 + need some non-trivial form of initialization, such as enabling a 306 + power regulator. An example for such a hub is the Realtek 307 + RTS5411. 308 + 309 + This driver can be used as a module but its state (module vs 310 + builtin) must match the state of the USB subsystem. Enabling 311 + this config will enable the driver and it will automatically 312 + match the state of the USB subsystem. If this driver is a 313 + module it will be called onboard_usb_hub.
+1
drivers/usb/misc/Makefile
··· 33 33 obj-$(CONFIG_USB_SISUSBVGA) += sisusbvga/ 34 34 obj-$(CONFIG_USB_LINK_LAYER_TEST) += lvstest.o 35 35 obj-$(CONFIG_BRCM_USB_PINMAP) += brcmstb-usb-pinmap.o 36 + obj-$(CONFIG_USB_ONBOARD_HUB) += onboard_usb_hub.o
+4 -2
drivers/usb/misc/ldusb.c
··· 716 716 dev->interrupt_out_urb = usb_alloc_urb(0, GFP_KERNEL); 717 717 if (!dev->interrupt_out_urb) 718 718 goto error; 719 - dev->interrupt_in_interval = min_interrupt_in_interval > dev->interrupt_in_endpoint->bInterval ? min_interrupt_in_interval : dev->interrupt_in_endpoint->bInterval; 719 + dev->interrupt_in_interval = max_t(int, min_interrupt_in_interval, 720 + dev->interrupt_in_endpoint->bInterval); 720 721 if (dev->interrupt_out_endpoint) 721 - dev->interrupt_out_interval = min_interrupt_out_interval > dev->interrupt_out_endpoint->bInterval ? min_interrupt_out_interval : dev->interrupt_out_endpoint->bInterval; 722 + dev->interrupt_out_interval = max_t(int, min_interrupt_out_interval, 723 + dev->interrupt_out_endpoint->bInterval); 722 724 723 725 /* we can register the device now, as it is ready */ 724 726 usb_set_intfdata(intf, dev);
+458
drivers/usb/misc/onboard_usb_hub.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + /* 3 + * Driver for onboard USB hubs 4 + * 5 + * Copyright (c) 2022, Google LLC 6 + */ 7 + 8 + #include <linux/device.h> 9 + #include <linux/export.h> 10 + #include <linux/gpio/consumer.h> 11 + #include <linux/init.h> 12 + #include <linux/kernel.h> 13 + #include <linux/list.h> 14 + #include <linux/module.h> 15 + #include <linux/mutex.h> 16 + #include <linux/of.h> 17 + #include <linux/of_platform.h> 18 + #include <linux/platform_device.h> 19 + #include <linux/regulator/consumer.h> 20 + #include <linux/slab.h> 21 + #include <linux/suspend.h> 22 + #include <linux/sysfs.h> 23 + #include <linux/usb.h> 24 + #include <linux/usb/hcd.h> 25 + #include <linux/usb/onboard_hub.h> 26 + #include <linux/workqueue.h> 27 + 28 + #include "onboard_usb_hub.h" 29 + 30 + static struct usb_device_driver onboard_hub_usbdev_driver; 31 + 32 + /************************** Platform driver **************************/ 33 + 34 + struct usbdev_node { 35 + struct usb_device *udev; 36 + struct list_head list; 37 + }; 38 + 39 + struct onboard_hub { 40 + struct regulator *vdd; 41 + struct device *dev; 42 + const struct onboard_hub_pdata *pdata; 43 + struct gpio_desc *reset_gpio; 44 + bool always_powered_in_suspend; 45 + bool is_powered_on; 46 + bool going_away; 47 + struct list_head udev_list; 48 + struct work_struct attach_usb_driver_work; 49 + struct mutex lock; 50 + }; 51 + 52 + static int onboard_hub_power_on(struct onboard_hub *hub) 53 + { 54 + int err; 55 + 56 + err = regulator_enable(hub->vdd); 57 + if (err) { 58 + dev_err(hub->dev, "failed to enable regulator: %d\n", err); 59 + return err; 60 + } 61 + 62 + fsleep(hub->pdata->reset_us); 63 + gpiod_set_value_cansleep(hub->reset_gpio, 0); 64 + 65 + hub->is_powered_on = true; 66 + 67 + return 0; 68 + } 69 + 70 + static int onboard_hub_power_off(struct onboard_hub *hub) 71 + { 72 + int err; 73 + 74 + if (hub->reset_gpio) { 75 + gpiod_set_value_cansleep(hub->reset_gpio, 1); 76 + fsleep(hub->pdata->reset_us); 77 + } 78 + 79 + err = regulator_disable(hub->vdd); 80 + if (err) { 81 + dev_err(hub->dev, "failed to disable regulator: %d\n", err); 82 + return err; 83 + } 84 + 85 + hub->is_powered_on = false; 86 + 87 + return 0; 88 + } 89 + 90 + static int __maybe_unused onboard_hub_suspend(struct device *dev) 91 + { 92 + struct onboard_hub *hub = dev_get_drvdata(dev); 93 + struct usbdev_node *node; 94 + bool power_off = true; 95 + 96 + if (hub->always_powered_in_suspend) 97 + return 0; 98 + 99 + mutex_lock(&hub->lock); 100 + 101 + list_for_each_entry(node, &hub->udev_list, list) { 102 + if (!device_may_wakeup(node->udev->bus->controller)) 103 + continue; 104 + 105 + if (usb_wakeup_enabled_descendants(node->udev)) { 106 + power_off = false; 107 + break; 108 + } 109 + } 110 + 111 + mutex_unlock(&hub->lock); 112 + 113 + if (!power_off) 114 + return 0; 115 + 116 + return onboard_hub_power_off(hub); 117 + } 118 + 119 + static int __maybe_unused onboard_hub_resume(struct device *dev) 120 + { 121 + struct onboard_hub *hub = dev_get_drvdata(dev); 122 + 123 + if (hub->is_powered_on) 124 + return 0; 125 + 126 + return onboard_hub_power_on(hub); 127 + } 128 + 129 + static inline void get_udev_link_name(const struct usb_device *udev, char *buf, size_t size) 130 + { 131 + snprintf(buf, size, "usb_dev.%s", dev_name(&udev->dev)); 132 + } 133 + 134 + static int onboard_hub_add_usbdev(struct onboard_hub *hub, struct usb_device *udev) 135 + { 136 + struct usbdev_node *node; 137 + char link_name[64]; 138 + int err; 139 + 140 + mutex_lock(&hub->lock); 141 + 142 + if (hub->going_away) { 143 + err = -EINVAL; 144 + goto error; 145 + } 146 + 147 + node = kzalloc(sizeof(*node), GFP_KERNEL); 148 + if (!node) { 149 + err = -ENOMEM; 150 + goto error; 151 + } 152 + 153 + node->udev = udev; 154 + 155 + list_add(&node->list, &hub->udev_list); 156 + 157 + mutex_unlock(&hub->lock); 158 + 159 + get_udev_link_name(udev, link_name, sizeof(link_name)); 160 + WARN_ON(sysfs_create_link(&hub->dev->kobj, &udev->dev.kobj, link_name)); 161 + 162 + return 0; 163 + 164 + error: 165 + mutex_unlock(&hub->lock); 166 + 167 + return err; 168 + } 169 + 170 + static void onboard_hub_remove_usbdev(struct onboard_hub *hub, const struct usb_device *udev) 171 + { 172 + struct usbdev_node *node; 173 + char link_name[64]; 174 + 175 + get_udev_link_name(udev, link_name, sizeof(link_name)); 176 + sysfs_remove_link(&hub->dev->kobj, link_name); 177 + 178 + mutex_lock(&hub->lock); 179 + 180 + list_for_each_entry(node, &hub->udev_list, list) { 181 + if (node->udev == udev) { 182 + list_del(&node->list); 183 + kfree(node); 184 + break; 185 + } 186 + } 187 + 188 + mutex_unlock(&hub->lock); 189 + } 190 + 191 + static ssize_t always_powered_in_suspend_show(struct device *dev, struct device_attribute *attr, 192 + char *buf) 193 + { 194 + const struct onboard_hub *hub = dev_get_drvdata(dev); 195 + 196 + return sysfs_emit(buf, "%d\n", hub->always_powered_in_suspend); 197 + } 198 + 199 + static ssize_t always_powered_in_suspend_store(struct device *dev, struct device_attribute *attr, 200 + const char *buf, size_t count) 201 + { 202 + struct onboard_hub *hub = dev_get_drvdata(dev); 203 + bool val; 204 + int ret; 205 + 206 + ret = kstrtobool(buf, &val); 207 + if (ret < 0) 208 + return ret; 209 + 210 + hub->always_powered_in_suspend = val; 211 + 212 + return count; 213 + } 214 + static DEVICE_ATTR_RW(always_powered_in_suspend); 215 + 216 + static struct attribute *onboard_hub_attrs[] = { 217 + &dev_attr_always_powered_in_suspend.attr, 218 + NULL, 219 + }; 220 + ATTRIBUTE_GROUPS(onboard_hub); 221 + 222 + static void onboard_hub_attach_usb_driver(struct work_struct *work) 223 + { 224 + int err; 225 + 226 + err = driver_attach(&onboard_hub_usbdev_driver.drvwrap.driver); 227 + if (err) 228 + pr_err("Failed to attach USB driver: %d\n", err); 229 + } 230 + 231 + static int onboard_hub_probe(struct platform_device *pdev) 232 + { 233 + const struct of_device_id *of_id; 234 + struct device *dev = &pdev->dev; 235 + struct onboard_hub *hub; 236 + int err; 237 + 238 + hub = devm_kzalloc(dev, sizeof(*hub), GFP_KERNEL); 239 + if (!hub) 240 + return -ENOMEM; 241 + 242 + of_id = of_match_device(onboard_hub_match, &pdev->dev); 243 + if (!of_id) 244 + return -ENODEV; 245 + 246 + hub->pdata = of_id->data; 247 + if (!hub->pdata) 248 + return -EINVAL; 249 + 250 + hub->vdd = devm_regulator_get(dev, "vdd"); 251 + if (IS_ERR(hub->vdd)) 252 + return PTR_ERR(hub->vdd); 253 + 254 + hub->reset_gpio = devm_gpiod_get_optional(dev, "reset", 255 + GPIOD_OUT_HIGH); 256 + if (IS_ERR(hub->reset_gpio)) 257 + return dev_err_probe(dev, PTR_ERR(hub->reset_gpio), "failed to get reset GPIO\n"); 258 + 259 + hub->dev = dev; 260 + mutex_init(&hub->lock); 261 + INIT_LIST_HEAD(&hub->udev_list); 262 + 263 + dev_set_drvdata(dev, hub); 264 + 265 + err = onboard_hub_power_on(hub); 266 + if (err) 267 + return err; 268 + 269 + /* 270 + * The USB driver might have been detached from the USB devices by 271 + * onboard_hub_remove() (e.g. through an 'unbind' by userspace), 272 + * make sure to re-attach it if needed. 273 + * 274 + * This needs to be done deferred to avoid self-deadlocks on systems 275 + * with nested onboard hubs. 276 + */ 277 + INIT_WORK(&hub->attach_usb_driver_work, onboard_hub_attach_usb_driver); 278 + schedule_work(&hub->attach_usb_driver_work); 279 + 280 + return 0; 281 + } 282 + 283 + static int onboard_hub_remove(struct platform_device *pdev) 284 + { 285 + struct onboard_hub *hub = dev_get_drvdata(&pdev->dev); 286 + struct usbdev_node *node; 287 + struct usb_device *udev; 288 + 289 + hub->going_away = true; 290 + 291 + if (&hub->attach_usb_driver_work != current_work()) 292 + cancel_work_sync(&hub->attach_usb_driver_work); 293 + 294 + mutex_lock(&hub->lock); 295 + 296 + /* unbind the USB devices to avoid dangling references to this device */ 297 + while (!list_empty(&hub->udev_list)) { 298 + node = list_first_entry(&hub->udev_list, struct usbdev_node, list); 299 + udev = node->udev; 300 + 301 + /* 302 + * Unbinding the driver will call onboard_hub_remove_usbdev(), 303 + * which acquires hub->lock. We must release the lock first. 304 + */ 305 + get_device(&udev->dev); 306 + mutex_unlock(&hub->lock); 307 + device_release_driver(&udev->dev); 308 + put_device(&udev->dev); 309 + mutex_lock(&hub->lock); 310 + } 311 + 312 + mutex_unlock(&hub->lock); 313 + 314 + return onboard_hub_power_off(hub); 315 + } 316 + 317 + MODULE_DEVICE_TABLE(of, onboard_hub_match); 318 + 319 + static const struct dev_pm_ops __maybe_unused onboard_hub_pm_ops = { 320 + SET_LATE_SYSTEM_SLEEP_PM_OPS(onboard_hub_suspend, onboard_hub_resume) 321 + }; 322 + 323 + static struct platform_driver onboard_hub_driver = { 324 + .probe = onboard_hub_probe, 325 + .remove = onboard_hub_remove, 326 + 327 + .driver = { 328 + .name = "onboard-usb-hub", 329 + .of_match_table = onboard_hub_match, 330 + .pm = pm_ptr(&onboard_hub_pm_ops), 331 + .dev_groups = onboard_hub_groups, 332 + }, 333 + }; 334 + 335 + /************************** USB driver **************************/ 336 + 337 + #define VENDOR_ID_MICROCHIP 0x0424 338 + #define VENDOR_ID_REALTEK 0x0bda 339 + #define VENDOR_ID_TI 0x0451 340 + 341 + /* 342 + * Returns the onboard_hub platform device that is associated with the USB 343 + * device passed as parameter. 344 + */ 345 + static struct onboard_hub *_find_onboard_hub(struct device *dev) 346 + { 347 + struct platform_device *pdev; 348 + struct device_node *np; 349 + struct onboard_hub *hub; 350 + 351 + pdev = of_find_device_by_node(dev->of_node); 352 + if (!pdev) { 353 + np = of_parse_phandle(dev->of_node, "peer-hub", 0); 354 + if (!np) { 355 + dev_err(dev, "failed to find device node for peer hub\n"); 356 + return ERR_PTR(-EINVAL); 357 + } 358 + 359 + pdev = of_find_device_by_node(np); 360 + of_node_put(np); 361 + 362 + if (!pdev) 363 + return ERR_PTR(-ENODEV); 364 + } 365 + 366 + hub = dev_get_drvdata(&pdev->dev); 367 + put_device(&pdev->dev); 368 + 369 + /* 370 + * The presence of drvdata ('hub') indicates that the platform driver 371 + * finished probing. This handles the case where (conceivably) we could 372 + * be running at the exact same time as the platform driver's probe. If 373 + * we detect the race we request probe deferral and we'll come back and 374 + * try again. 375 + */ 376 + if (!hub) 377 + return ERR_PTR(-EPROBE_DEFER); 378 + 379 + return hub; 380 + } 381 + 382 + static int onboard_hub_usbdev_probe(struct usb_device *udev) 383 + { 384 + struct device *dev = &udev->dev; 385 + struct onboard_hub *hub; 386 + int err; 387 + 388 + /* ignore supported hubs without device tree node */ 389 + if (!dev->of_node) 390 + return -ENODEV; 391 + 392 + hub = _find_onboard_hub(dev); 393 + if (IS_ERR(hub)) 394 + return PTR_ERR(hub); 395 + 396 + dev_set_drvdata(dev, hub); 397 + 398 + err = onboard_hub_add_usbdev(hub, udev); 399 + if (err) 400 + return err; 401 + 402 + return 0; 403 + } 404 + 405 + static void onboard_hub_usbdev_disconnect(struct usb_device *udev) 406 + { 407 + struct onboard_hub *hub = dev_get_drvdata(&udev->dev); 408 + 409 + onboard_hub_remove_usbdev(hub, udev); 410 + } 411 + 412 + static const struct usb_device_id onboard_hub_id_table[] = { 413 + { USB_DEVICE(VENDOR_ID_MICROCHIP, 0x2514) }, /* USB2514B USB 2.0 */ 414 + { USB_DEVICE(VENDOR_ID_REALTEK, 0x0411) }, /* RTS5411 USB 3.1 */ 415 + { USB_DEVICE(VENDOR_ID_REALTEK, 0x5411) }, /* RTS5411 USB 2.1 */ 416 + { USB_DEVICE(VENDOR_ID_REALTEK, 0x0414) }, /* RTS5414 USB 3.2 */ 417 + { USB_DEVICE(VENDOR_ID_REALTEK, 0x5414) }, /* RTS5414 USB 2.1 */ 418 + { USB_DEVICE(VENDOR_ID_TI, 0x8140) }, /* TI USB8041 3.0 */ 419 + { USB_DEVICE(VENDOR_ID_TI, 0x8142) }, /* TI USB8041 2.0 */ 420 + {} 421 + }; 422 + MODULE_DEVICE_TABLE(usb, onboard_hub_id_table); 423 + 424 + static struct usb_device_driver onboard_hub_usbdev_driver = { 425 + .name = "onboard-usb-hub", 426 + .probe = onboard_hub_usbdev_probe, 427 + .disconnect = onboard_hub_usbdev_disconnect, 428 + .generic_subclass = 1, 429 + .supports_autosuspend = 1, 430 + .id_table = onboard_hub_id_table, 431 + }; 432 + 433 + static int __init onboard_hub_init(void) 434 + { 435 + int ret; 436 + 437 + ret = platform_driver_register(&onboard_hub_driver); 438 + if (ret) 439 + return ret; 440 + 441 + ret = usb_register_device_driver(&onboard_hub_usbdev_driver, THIS_MODULE); 442 + if (ret) 443 + platform_driver_unregister(&onboard_hub_driver); 444 + 445 + return ret; 446 + } 447 + module_init(onboard_hub_init); 448 + 449 + static void __exit onboard_hub_exit(void) 450 + { 451 + usb_deregister_device_driver(&onboard_hub_usbdev_driver); 452 + platform_driver_unregister(&onboard_hub_driver); 453 + } 454 + module_exit(onboard_hub_exit); 455 + 456 + MODULE_AUTHOR("Matthias Kaehlcke <mka@chromium.org>"); 457 + MODULE_DESCRIPTION("Driver for discrete onboard USB hubs"); 458 + MODULE_LICENSE("GPL v2");
+36
drivers/usb/misc/onboard_usb_hub.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0+ */ 2 + /* 3 + * Copyright (c) 2022, Google LLC 4 + */ 5 + 6 + #ifndef _USB_MISC_ONBOARD_USB_HUB_H 7 + #define _USB_MISC_ONBOARD_USB_HUB_H 8 + 9 + struct onboard_hub_pdata { 10 + unsigned long reset_us; /* reset pulse width in us */ 11 + }; 12 + 13 + static const struct onboard_hub_pdata microchip_usb424_data = { 14 + .reset_us = 1, 15 + }; 16 + 17 + static const struct onboard_hub_pdata realtek_rts5411_data = { 18 + .reset_us = 0, 19 + }; 20 + 21 + static const struct onboard_hub_pdata ti_tusb8041_data = { 22 + .reset_us = 3000, 23 + }; 24 + 25 + static const struct of_device_id onboard_hub_match[] = { 26 + { .compatible = "usb424,2514", .data = &microchip_usb424_data, }, 27 + { .compatible = "usb451,8140", .data = &ti_tusb8041_data, }, 28 + { .compatible = "usb451,8142", .data = &ti_tusb8041_data, }, 29 + { .compatible = "usbbda,411", .data = &realtek_rts5411_data, }, 30 + { .compatible = "usbbda,5411", .data = &realtek_rts5411_data, }, 31 + { .compatible = "usbbda,414", .data = &realtek_rts5411_data, }, 32 + { .compatible = "usbbda,5414", .data = &realtek_rts5411_data, }, 33 + {} 34 + }; 35 + 36 + #endif /* _USB_MISC_ONBOARD_USB_HUB_H */
+143
drivers/usb/misc/onboard_usb_hub_pdevs.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + /* 3 + * API for creating and destroying USB onboard hub platform devices 4 + * 5 + * Copyright (c) 2022, Google LLC 6 + */ 7 + 8 + #include <linux/device.h> 9 + #include <linux/export.h> 10 + #include <linux/kernel.h> 11 + #include <linux/list.h> 12 + #include <linux/of.h> 13 + #include <linux/of_platform.h> 14 + #include <linux/platform_device.h> 15 + #include <linux/usb.h> 16 + #include <linux/usb/hcd.h> 17 + #include <linux/usb/of.h> 18 + #include <linux/usb/onboard_hub.h> 19 + 20 + #include "onboard_usb_hub.h" 21 + 22 + struct pdev_list_entry { 23 + struct platform_device *pdev; 24 + struct list_head node; 25 + }; 26 + 27 + static bool of_is_onboard_usb_hub(const struct device_node *np) 28 + { 29 + return !!of_match_node(onboard_hub_match, np); 30 + } 31 + 32 + /** 33 + * onboard_hub_create_pdevs -- create platform devices for onboard USB hubs 34 + * @parent_hub : parent hub to scan for connected onboard hubs 35 + * @pdev_list : list of onboard hub platform devices owned by the parent hub 36 + * 37 + * Creates a platform device for each supported onboard hub that is connected to 38 + * the given parent hub. The platform device is in charge of initializing the 39 + * hub (enable regulators, take the hub out of reset, ...) and can optionally 40 + * control whether the hub remains powered during system suspend or not. 41 + * 42 + * To keep track of the platform devices they are added to a list that is owned 43 + * by the parent hub. 44 + * 45 + * Some background about the logic in this function, which can be a bit hard 46 + * to follow: 47 + * 48 + * Root hubs don't have dedicated device tree nodes, but use the node of their 49 + * HCD. The primary and secondary HCD are usually represented by a single DT 50 + * node. That means the root hubs of the primary and secondary HCD share the 51 + * same device tree node (the HCD node). As a result this function can be called 52 + * twice with the same DT node for root hubs. We only want to create a single 53 + * platform device for each physical onboard hub, hence for root hubs the loop 54 + * is only executed for the root hub of the primary HCD. Since the function 55 + * scans through all child nodes it still creates pdevs for onboard hubs 56 + * connected to the root hub of the secondary HCD if needed. 57 + * 58 + * Further there must be only one platform device for onboard hubs with a peer 59 + * hub (the hub is a single physical device). To achieve this two measures are 60 + * taken: pdevs for onboard hubs with a peer are only created when the function 61 + * is called on behalf of the parent hub that is connected to the primary HCD 62 + * (directly or through other hubs). For onboard hubs connected to root hubs 63 + * the function processes the nodes of both peers. A platform device is only 64 + * created if the peer hub doesn't have one already. 65 + */ 66 + void onboard_hub_create_pdevs(struct usb_device *parent_hub, struct list_head *pdev_list) 67 + { 68 + int i; 69 + struct usb_hcd *hcd = bus_to_hcd(parent_hub->bus); 70 + struct device_node *np, *npc; 71 + struct platform_device *pdev; 72 + struct pdev_list_entry *pdle; 73 + 74 + if (!parent_hub->dev.of_node) 75 + return; 76 + 77 + if (!parent_hub->parent && !usb_hcd_is_primary_hcd(hcd)) 78 + return; 79 + 80 + for (i = 1; i <= parent_hub->maxchild; i++) { 81 + np = usb_of_get_device_node(parent_hub, i); 82 + if (!np) 83 + continue; 84 + 85 + if (!of_is_onboard_usb_hub(np)) 86 + goto node_put; 87 + 88 + npc = of_parse_phandle(np, "peer-hub", 0); 89 + if (npc) { 90 + if (!usb_hcd_is_primary_hcd(hcd)) { 91 + of_node_put(npc); 92 + goto node_put; 93 + } 94 + 95 + pdev = of_find_device_by_node(npc); 96 + of_node_put(npc); 97 + 98 + if (pdev) { 99 + put_device(&pdev->dev); 100 + goto node_put; 101 + } 102 + } 103 + 104 + pdev = of_platform_device_create(np, NULL, &parent_hub->dev); 105 + if (!pdev) { 106 + dev_err(&parent_hub->dev, 107 + "failed to create platform device for onboard hub '%pOF'\n", np); 108 + goto node_put; 109 + } 110 + 111 + pdle = kzalloc(sizeof(*pdle), GFP_KERNEL); 112 + if (!pdle) { 113 + of_platform_device_destroy(&pdev->dev, NULL); 114 + goto node_put; 115 + } 116 + 117 + pdle->pdev = pdev; 118 + list_add(&pdle->node, pdev_list); 119 + 120 + node_put: 121 + of_node_put(np); 122 + } 123 + } 124 + EXPORT_SYMBOL_GPL(onboard_hub_create_pdevs); 125 + 126 + /** 127 + * onboard_hub_destroy_pdevs -- free resources of onboard hub platform devices 128 + * @pdev_list : list of onboard hub platform devices 129 + * 130 + * Destroys the platform devices in the given list and frees the memory associated 131 + * with the list entry. 132 + */ 133 + void onboard_hub_destroy_pdevs(struct list_head *pdev_list) 134 + { 135 + struct pdev_list_entry *pdle, *tmp; 136 + 137 + list_for_each_entry_safe(pdle, tmp, pdev_list, node) { 138 + list_del(&pdle->node); 139 + of_platform_device_destroy(&pdle->pdev->dev, NULL); 140 + kfree(pdle); 141 + } 142 + } 143 + EXPORT_SYMBOL_GPL(onboard_hub_destroy_pdevs);
+1 -1
drivers/usb/misc/usbsevseg.c
··· 167 167 struct usb_interface *intf = to_usb_interface(dev); 168 168 struct usb_sevsegdev *mydev = usb_get_intfdata(intf); 169 169 170 - return snprintf(buf, mydev->textlength, "%s\n", mydev->text); 170 + return sysfs_emit(buf, "%s\n", mydev->text); 171 171 } 172 172 173 173 static ssize_t text_store(struct device *dev,
+1 -1
drivers/usb/misc/usbtest.c
··· 2638 2638 * different busses) to use when testing, and allocate one thread per 2639 2639 * test. So discovery is simplified, and we have no device naming issues. 2640 2640 * 2641 - * Don't use these only as stress/load tests. Use them along with with 2641 + * Don't use these only as stress/load tests. Use them along with 2642 2642 * other USB bus activity: plugging, unplugging, mousing, mp3 playback, 2643 2643 * video capture, and so on. Run different tests at different times, in 2644 2644 * different sequences. Nothing here should interact with other devices,
+4 -1
drivers/usb/mtu3/mtu3.h
··· 317 317 * @ep0_req: dummy request used while handling standard USB requests 318 318 * for GET_STATUS and SET_SEL 319 319 * @setup_buf: ep0 response buffer for GET_STATUS and SET_SEL requests 320 + * @u3_capable: is capable of supporting USB3 320 321 */ 321 322 struct mtu3 { 322 323 spinlock_t lock; ··· 354 353 unsigned softconnect:1; 355 354 unsigned u1_enable:1; 356 355 unsigned u2_enable:1; 357 - unsigned is_u3_ip:1; 356 + unsigned u3_capable:1; 358 357 unsigned delayed_status:1; 359 358 unsigned gen2cp:1; 360 359 unsigned connected:1; 360 + unsigned async_callbacks:1; 361 + unsigned separate_fifo:1; 361 362 362 363 u8 address; 363 364 u8 test_mode_nr;
+21 -14
drivers/usb/mtu3/mtu3_core.c
··· 100 100 101 101 mtu3_clrbits(ibase, U3D_SSUSB_IP_PW_CTRL2, SSUSB_IP_DEV_PDN); 102 102 103 - if (mtu->is_u3_ip) { 103 + if (mtu->u3_capable) { 104 104 check_clk = SSUSB_U3_MAC_RST_B_STS; 105 105 mtu3_clrbits(ibase, SSUSB_U3_CTRL(0), 106 106 (SSUSB_U3_PORT_DIS | SSUSB_U3_PORT_PDN | ··· 112 112 113 113 if (mtu->ssusb->dr_mode == USB_DR_MODE_OTG) { 114 114 mtu3_setbits(ibase, SSUSB_U2_CTRL(0), SSUSB_U2_PORT_OTG_SEL); 115 - if (mtu->is_u3_ip) 115 + if (mtu->u3_capable) 116 116 mtu3_setbits(ibase, SSUSB_U3_CTRL(0), 117 117 SSUSB_U3_PORT_DUAL_MODE); 118 118 } ··· 124 124 { 125 125 void __iomem *ibase = mtu->ippc_base; 126 126 127 - if (mtu->is_u3_ip) 127 + if (mtu->u3_capable) 128 128 mtu3_setbits(ibase, SSUSB_U3_CTRL(0), 129 129 (SSUSB_U3_PORT_DIS | SSUSB_U3_PORT_PDN)); 130 130 ··· 133 133 134 134 if (mtu->ssusb->dr_mode == USB_DR_MODE_OTG) { 135 135 mtu3_clrbits(ibase, SSUSB_U2_CTRL(0), SSUSB_U2_PORT_OTG_SEL); 136 - if (mtu->is_u3_ip) 136 + if (mtu->u3_capable) 137 137 mtu3_clrbits(ibase, SSUSB_U3_CTRL(0), 138 138 SSUSB_U3_PORT_DUAL_MODE); 139 139 } ··· 146 146 void __iomem *ibase = mtu->ippc_base; 147 147 148 148 mtu3_clrbits(ibase, U3D_SSUSB_IP_PW_CTRL2, SSUSB_IP_DEV_PDN); 149 - if (mtu->is_u3_ip) 149 + if (mtu->u3_capable) 150 150 mtu3_clrbits(ibase, SSUSB_U3_CTRL(0), SSUSB_U3_PORT_PDN); 151 151 152 152 mtu3_clrbits(ibase, SSUSB_U2_CTRL(0), SSUSB_U2_PORT_PDN); ··· 156 156 { 157 157 void __iomem *ibase = mtu->ippc_base; 158 158 159 - if (mtu->is_u3_ip) 159 + if (mtu->u3_capable) 160 160 mtu3_setbits(ibase, SSUSB_U3_CTRL(0), SSUSB_U3_PORT_PDN); 161 161 162 162 mtu3_setbits(ibase, SSUSB_U2_CTRL(0), SSUSB_U2_PORT_PDN); ··· 213 213 value = SUSPEND_INTR | RESUME_INTR | RESET_INTR; 214 214 mtu3_writel(mbase, U3D_COMMON_USB_INTR_ENABLE, value); 215 215 216 - if (mtu->is_u3_ip) { 216 + if (mtu->u3_capable) { 217 217 /* Enable U3 LTSSM interrupts */ 218 218 value = HOT_RST_INTR | WARM_RST_INTR | 219 219 ENTER_U3_INTR | EXIT_U3_INTR; ··· 273 273 { 274 274 void __iomem *mbase = mtu->mac_base; 275 275 276 - if (mtu->is_u3_ip) { 276 + if (mtu->u3_capable) { 277 277 /* disable LGO_U1/U2 by default */ 278 278 mtu3_clrbits(mbase, U3D_LINK_POWER_CONTROL, 279 279 SW_U1_REQUEST_ENABLE | SW_U2_REQUEST_ENABLE); ··· 341 341 342 342 void mtu3_dev_on_off(struct mtu3 *mtu, int is_on) 343 343 { 344 - if (mtu->is_u3_ip && mtu->speed >= USB_SPEED_SUPER) 344 + if (mtu->u3_capable && mtu->speed >= USB_SPEED_SUPER) 345 345 mtu3_ss_func_set(mtu, is_on); 346 346 else 347 347 mtu3_hs_softconn_set(mtu, is_on); ··· 544 544 struct mtu3_fifo_info *rx_fifo; 545 545 u32 fifosize; 546 546 547 - if (mtu->is_u3_ip) { 547 + if (mtu->separate_fifo) { 548 548 fifosize = mtu3_readl(mtu->mac_base, U3D_CAP_EPNTXFFSZ); 549 549 tx_fifo = &mtu->tx_fifo; 550 550 tx_fifo->base = 0; ··· 821 821 822 822 static void mtu3_check_params(struct mtu3 *mtu) 823 823 { 824 + /* device's u3 port (port0) is disabled */ 825 + if (mtu->u3_capable && (mtu->ssusb->u3p_dis_msk & BIT(0))) 826 + mtu->u3_capable = 0; 827 + 824 828 /* check the max_speed parameter */ 825 829 switch (mtu->max_speed) { 826 830 case USB_SPEED_FULL: ··· 842 838 break; 843 839 } 844 840 845 - if (!mtu->is_u3_ip && (mtu->max_speed > USB_SPEED_HIGH)) 841 + if (!mtu->u3_capable && (mtu->max_speed > USB_SPEED_HIGH)) 846 842 mtu->max_speed = USB_SPEED_HIGH; 847 843 848 844 mtu->speed = mtu->max_speed; ··· 861 857 mtu->gen2cp = !!(mtu->hw_version >= MTU3_TRUNK_VERS_1003); 862 858 863 859 value = mtu3_readl(mtu->ippc_base, U3D_SSUSB_IP_DEV_CAP); 864 - mtu->is_u3_ip = !!SSUSB_IP_DEV_U3_PORT_NUM(value); 860 + mtu->u3_capable = !!SSUSB_IP_DEV_U3_PORT_NUM(value); 861 + /* usb3 ip uses separate fifo */ 862 + mtu->separate_fifo = mtu->u3_capable; 865 863 866 864 dev_info(mtu->dev, "IP version 0x%x(%s IP)\n", mtu->hw_version, 867 - mtu->is_u3_ip ? "U3" : "U2"); 865 + mtu->u3_capable ? "U3" : "U2"); 868 866 869 867 mtu3_check_params(mtu); 870 868 ··· 971 965 goto dma_mask_err; 972 966 } 973 967 974 - ret = devm_request_irq(dev, mtu->irq, mtu3_irq, 0, dev_name(dev), mtu); 968 + ret = devm_request_threaded_irq(dev, mtu->irq, NULL, mtu3_irq, 969 + IRQF_ONESHOT, dev_name(dev), mtu); 975 970 if (ret) { 976 971 dev_err(dev, "request irq %d failed!\n", mtu->irq); 977 972 goto irq_err;
+4 -4
drivers/usb/mtu3/mtu3_debugfs.c
··· 101 101 for (i = 0; i < mtu->num_eps; i++) { 102 102 mep = mtu->in_eps + i; 103 103 if (mep->flags & MTU3_EP_ENABLED) { 104 - seq_printf(sf, "%s - type: %d\n", mep->name, mep->type); 104 + seq_printf(sf, "%s - type: %s\n", mep->name, usb_ep_type_string(mep->type)); 105 105 used++; 106 106 } 107 107 108 108 mep = mtu->out_eps + i; 109 109 if (mep->flags & MTU3_EP_ENABLED) { 110 - seq_printf(sf, "%s - type: %d\n", mep->name, mep->type); 110 + seq_printf(sf, "%s - type: %s\n", mep->name, usb_ep_type_string(mep->type)); 111 111 used++; 112 112 } 113 113 } ··· 177 177 unsigned long flags; 178 178 179 179 spin_lock_irqsave(&mtu->lock, flags); 180 - seq_printf(sf, "ep - type:%d, maxp:%d, slot:%d, flags:%x\n", 181 - mep->type, mep->maxp, mep->slot, mep->flags); 180 + seq_printf(sf, "ep - type:%s, maxp:%d, slot:%d, flags:%x\n", 181 + usb_ep_type_string(mep->type), mep->maxp, mep->slot, mep->flags); 182 182 spin_unlock_irqrestore(&mtu->lock, flags); 183 183 184 184 return 0;
+35 -3
drivers/usb/mtu3/mtu3_gadget.c
··· 433 433 return (int)mtu3_readl(mtu->mac_base, U3D_USB20_FRAME_NUM); 434 434 } 435 435 436 + static void function_wake_notif(struct mtu3 *mtu, u8 intf) 437 + { 438 + mtu3_writel(mtu->mac_base, U3D_DEV_NOTIF_0, 439 + TYPE_FUNCTION_WAKE | DEV_NOTIF_VAL_FW(intf)); 440 + mtu3_setbits(mtu->mac_base, U3D_DEV_NOTIF_0, SEND_DEV_NOTIF); 441 + } 442 + 436 443 static int mtu3_gadget_wakeup(struct usb_gadget *gadget) 437 444 { 438 445 struct mtu3 *mtu = gadget_to_mtu3(gadget); ··· 453 446 454 447 spin_lock_irqsave(&mtu->lock, flags); 455 448 if (mtu->g.speed >= USB_SPEED_SUPER) { 449 + /* 450 + * class driver may do function wakeup even UFP is in U0, 451 + * and UX_EXIT only takes effect in U1/U2/U3; 452 + */ 456 453 mtu3_setbits(mtu->mac_base, U3D_LINK_POWER_CONTROL, UX_EXIT); 454 + /* 455 + * Assume there's only one function on the composite device 456 + * and enable remote wake for the first interface. 457 + * FIXME if the IAD (interface association descriptor) shows 458 + * there is more than one function. 459 + */ 460 + function_wake_notif(mtu, 0); 457 461 } else { 458 462 mtu3_setbits(mtu->mac_base, U3D_POWER_MANAGEMENT, RESUME); 459 463 spin_unlock_irqrestore(&mtu->lock, flags); ··· 610 592 spin_unlock_irqrestore(&mtu->lock, flags); 611 593 } 612 594 595 + static void mtu3_gadget_async_callbacks(struct usb_gadget *g, bool enable) 596 + { 597 + struct mtu3 *mtu = gadget_to_mtu3(g); 598 + unsigned long flags; 599 + 600 + dev_dbg(mtu->dev, "%s %s\n", __func__, enable ? "en" : "dis"); 601 + 602 + spin_lock_irqsave(&mtu->lock, flags); 603 + mtu->async_callbacks = enable; 604 + spin_unlock_irqrestore(&mtu->lock, flags); 605 + } 606 + 613 607 static const struct usb_gadget_ops mtu3_gadget_ops = { 614 608 .get_frame = mtu3_gadget_get_frame, 615 609 .wakeup = mtu3_gadget_wakeup, ··· 630 600 .udc_start = mtu3_gadget_start, 631 601 .udc_stop = mtu3_gadget_stop, 632 602 .udc_set_speed = mtu3_gadget_set_speed, 603 + .udc_async_callbacks = mtu3_gadget_async_callbacks, 633 604 }; 634 605 635 606 static void mtu3_state_reset(struct mtu3 *mtu) ··· 711 680 mtu->g.speed = USB_SPEED_UNKNOWN; 712 681 mtu->g.sg_supported = 0; 713 682 mtu->g.name = MTU3_DRIVER_NAME; 683 + mtu->g.irq = mtu->irq; 714 684 mtu->is_active = 0; 715 685 mtu->delayed_status = false; 716 686 ··· 728 696 void mtu3_gadget_resume(struct mtu3 *mtu) 729 697 { 730 698 dev_dbg(mtu->dev, "gadget RESUME\n"); 731 - if (mtu->gadget_driver && mtu->gadget_driver->resume) { 699 + if (mtu->async_callbacks && mtu->gadget_driver && mtu->gadget_driver->resume) { 732 700 spin_unlock(&mtu->lock); 733 701 mtu->gadget_driver->resume(&mtu->g); 734 702 spin_lock(&mtu->lock); ··· 739 707 void mtu3_gadget_suspend(struct mtu3 *mtu) 740 708 { 741 709 dev_dbg(mtu->dev, "gadget SUSPEND\n"); 742 - if (mtu->gadget_driver && mtu->gadget_driver->suspend) { 710 + if (mtu->async_callbacks && mtu->gadget_driver && mtu->gadget_driver->suspend) { 743 711 spin_unlock(&mtu->lock); 744 712 mtu->gadget_driver->suspend(&mtu->g); 745 713 spin_lock(&mtu->lock); ··· 750 718 void mtu3_gadget_disconnect(struct mtu3 *mtu) 751 719 { 752 720 dev_dbg(mtu->dev, "gadget DISCONNECT\n"); 753 - if (mtu->gadget_driver && mtu->gadget_driver->disconnect) { 721 + if (mtu->async_callbacks && mtu->gadget_driver && mtu->gadget_driver->disconnect) { 754 722 spin_unlock(&mtu->lock); 755 723 mtu->gadget_driver->disconnect(&mtu->g); 756 724 spin_lock(&mtu->lock);
+5 -5
drivers/usb/mtu3/mtu3_gadget_ep0.c
··· 66 66 { 67 67 int ret; 68 68 69 - if (!mtu->gadget_driver) 69 + if (!mtu->gadget_driver || !mtu->async_callbacks) 70 70 return -EOPNOTSUPP; 71 71 72 72 spin_unlock(&mtu->lock); ··· 226 226 227 227 break; 228 228 case USB_RECIP_INTERFACE: 229 + /* status of function remote wakeup, forward request */ 230 + handled = 0; 229 231 break; 230 232 case USB_RECIP_ENDPOINT: 231 233 epnum = (u8) le16_to_cpu(setup->wIndex); ··· 399 397 /* superspeed only */ 400 398 if (value == USB_INTRF_FUNC_SUSPEND && 401 399 mtu->g.speed >= USB_SPEED_SUPER) { 402 - /* 403 - * forward the request because function drivers 404 - * should handle it 405 - */ 400 + /* forward the request for function suspend */ 401 + mtu->may_wakeup = !!(index & USB_INTRF_FUNC_SUSPEND_RW); 406 402 handled = 0; 407 403 } 408 404 break;
+16
drivers/usb/mtu3/mtu3_hw_regs.h
··· 341 341 #define U3D_LINK_UX_INACT_TIMER (SSUSB_USB3_SYS_CSR_BASE + 0x020C) 342 342 #define U3D_LINK_POWER_CONTROL (SSUSB_USB3_SYS_CSR_BASE + 0x0210) 343 343 #define U3D_LINK_ERR_COUNT (SSUSB_USB3_SYS_CSR_BASE + 0x0214) 344 + #define U3D_DEV_NOTIF_0 (SSUSB_USB3_SYS_CSR_BASE + 0x0290) 345 + #define U3D_DEV_NOTIF_1 (SSUSB_USB3_SYS_CSR_BASE + 0x0294) 344 346 345 347 /*---------------- SSUSB_USB3_SYS_CSR FIELD DEFINITION ----------------*/ 346 348 ··· 366 364 /* U3D_LINK_ERR_COUNT */ 367 365 #define CLR_LINK_ERR_CNT BIT(16) 368 366 #define LINK_ERROR_COUNT GENMASK(15, 0) 367 + 368 + /* U3D_DEV_NOTIF_0 */ 369 + #define DEV_NOTIF_TYPE_SPECIFIC_LOW_MSK GENMASK(31, 8) 370 + #define DEV_NOTIF_VAL_FW(x) (((x) & 0xff) << 8) 371 + #define DEV_NOTIF_VAL_LTM(x) (((x) & 0xfff) << 8) 372 + #define DEV_NOTIF_VAL_IAM(x) (((x) & 0xffff) << 8) 373 + #define DEV_NOTIF_TYPE_MSK GENMASK(7, 4) 374 + /* Notification Type */ 375 + #define TYPE_FUNCTION_WAKE (0x1 << 4) 376 + #define TYPE_LATENCY_TOLERANCE_MESSAGE (0x2 << 4) 377 + #define TYPE_BUS_INTERVAL_ADJUST_MESSAGE (0x3 << 4) 378 + #define TYPE_HOST_ROLE_REQUEST (0x4 << 4) 379 + #define TYPE_SUBLINK_SPEED (0x5 << 4) 380 + #define SEND_DEV_NOTIF BIT(0) 369 381 370 382 /*---------------- SSUSB_USB2_CSR REGISTER DEFINITION ----------------*/ 371 383
+37 -6
drivers/usb/mtu3/mtu3_plat.c
··· 13 13 #include <linux/of_irq.h> 14 14 #include <linux/platform_device.h> 15 15 #include <linux/pm_wakeirq.h> 16 + #include <linux/reset.h> 16 17 17 18 #include "mtu3.h" 18 19 #include "mtu3_dr.h" ··· 190 189 mtu3_setbits(ssusb->ippc_base, U3D_SSUSB_IP_PW_CTRL2, SSUSB_IP_DEV_PDN); 191 190 } 192 191 192 + static void ssusb_u3_drd_check(struct ssusb_mtk *ssusb) 193 + { 194 + struct otg_switch_mtk *otg_sx = &ssusb->otg_switch; 195 + u32 dev_u3p_num; 196 + u32 host_u3p_num; 197 + u32 value; 198 + 199 + /* u3 port0 is disabled */ 200 + if (ssusb->u3p_dis_msk & BIT(0)) { 201 + otg_sx->is_u3_drd = false; 202 + goto out; 203 + } 204 + 205 + value = mtu3_readl(ssusb->ippc_base, U3D_SSUSB_IP_DEV_CAP); 206 + dev_u3p_num = SSUSB_IP_DEV_U3_PORT_NUM(value); 207 + 208 + value = mtu3_readl(ssusb->ippc_base, U3D_SSUSB_IP_XHCI_CAP); 209 + host_u3p_num = SSUSB_IP_XHCI_U3_PORT_NUM(value); 210 + 211 + otg_sx->is_u3_drd = !!(dev_u3p_num && host_u3p_num); 212 + 213 + out: 214 + dev_info(ssusb->dev, "usb3-drd: %d\n", otg_sx->is_u3_drd); 215 + } 216 + 193 217 static int get_ssusb_rscs(struct platform_device *pdev, struct ssusb_mtk *ssusb) 194 218 { 195 219 struct device_node *node = pdev->dev.of_node; ··· 269 243 if (ssusb->dr_mode == USB_DR_MODE_UNKNOWN) 270 244 ssusb->dr_mode = USB_DR_MODE_OTG; 271 245 246 + of_property_read_u32(node, "mediatek,u3p-dis-msk", &ssusb->u3p_dis_msk); 247 + 272 248 if (ssusb->dr_mode == USB_DR_MODE_PERIPHERAL) 273 249 goto out; 274 250 ··· 282 254 } 283 255 284 256 /* optional property, ignore the error if it does not exist */ 285 - of_property_read_u32(node, "mediatek,u3p-dis-msk", 286 - &ssusb->u3p_dis_msk); 287 257 of_property_read_u32(node, "mediatek,u2p-dis-msk", 288 258 &ssusb->u2p_dis_msk); 289 259 ··· 295 269 goto out; 296 270 297 271 /* if dual-role mode is supported */ 298 - otg_sx->is_u3_drd = of_property_read_bool(node, "mediatek,usb3-drd"); 299 272 otg_sx->manual_drd_enabled = 300 273 of_property_read_bool(node, "enable-manual-drd"); 301 274 otg_sx->role_sw_used = of_property_read_bool(node, "usb-role-switch"); ··· 314 289 } 315 290 316 291 out: 317 - dev_info(dev, "dr_mode: %d, is_u3_dr: %d, drd: %s\n", 318 - ssusb->dr_mode, otg_sx->is_u3_drd, 319 - otg_sx->manual_drd_enabled ? "manual" : "auto"); 292 + dev_info(dev, "dr_mode: %d, drd: %s\n", ssusb->dr_mode, 293 + otg_sx->manual_drd_enabled ? "manual" : "auto"); 320 294 dev_info(dev, "u2p_dis_msk: %x, u3p_dis_msk: %x\n", 321 295 ssusb->u2p_dis_msk, ssusb->u3p_dis_msk); 322 296 ··· 369 345 dev_info(dev, "wakeup irq %d\n", ssusb->wakeup_irq); 370 346 } 371 347 348 + ret = device_reset_optional(dev); 349 + if (ret) { 350 + dev_err_probe(dev, ret, "failed to reset controller\n"); 351 + goto comm_exit; 352 + } 353 + 372 354 ssusb_ip_sw_reset(ssusb); 355 + ssusb_u3_drd_check(ssusb); 373 356 374 357 if (IS_ENABLED(CONFIG_USB_MTU3_HOST)) 375 358 ssusb->dr_mode = USB_DR_MODE_HOST;
+2 -2
drivers/usb/mtu3/mtu3_trace.h
··· 238 238 __entry->direction = mep->is_in; 239 239 __entry->gpd_ring = &mep->gpd_ring; 240 240 ), 241 - TP_printk("%s: type %d maxp %d slot %d mult %d burst %d ring %p/%pad flags %c:%c%c%c:%c", 242 - __get_str(name), __entry->type, 241 + TP_printk("%s: type %s maxp %d slot %d mult %d burst %d ring %p/%pad flags %c:%c%c%c:%c", 242 + __get_str(name), usb_ep_type_string(__entry->type), 243 243 __entry->maxp, __entry->slot, 244 244 __entry->mult, __entry->maxburst, 245 245 __entry->gpd_ring, &__entry->gpd_ring->dma,
+12 -1
drivers/usb/musb/Kconfig
··· 123 123 select GENERIC_PHY 124 124 select USB_ROLE_SWITCH 125 125 126 + config USB_MUSB_POLARFIRE_SOC 127 + tristate "Microchip PolarFire SoC platforms" 128 + depends on SOC_MICROCHIP_POLARFIRE || COMPILE_TEST 129 + depends on NOP_USB_XCEIV 130 + select USB_MUSB_DUAL_ROLE 131 + help 132 + Say Y here to enable support for USB on Microchip's PolarFire SoC. 133 + 134 + This support is also available as a module. If so, the module 135 + will be called mpfs. 136 + 126 137 comment "MUSB DMA mode" 127 138 128 139 config MUSB_PIO_ONLY ··· 157 146 158 147 config USB_INVENTRA_DMA 159 148 bool 'Inventra' 160 - depends on USB_MUSB_OMAP2PLUS || USB_MUSB_MEDIATEK || USB_MUSB_JZ4740 149 + depends on USB_MUSB_OMAP2PLUS || USB_MUSB_MEDIATEK || USB_MUSB_JZ4740 || USB_MUSB_POLARFIRE_SOC 161 150 help 162 151 Enable DMA transfers using Mentor's engine. 163 152
+1
drivers/usb/musb/Makefile
··· 25 25 obj-$(CONFIG_USB_MUSB_JZ4740) += jz4740.o 26 26 obj-$(CONFIG_USB_MUSB_SUNXI) += sunxi.o 27 27 obj-$(CONFIG_USB_MUSB_MEDIATEK) += mediatek.o 28 + obj-$(CONFIG_USB_MUSB_POLARFIRE_SOC) += mpfs.o 28 29 29 30 # the kconfig must guarantee that only one of the 30 31 # possible I/O schemes will be enabled at a time ...
+269
drivers/usb/musb/mpfs.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * PolarFire SoC (MPFS) MUSB Glue Layer 4 + * 5 + * Copyright (c) 2020-2022 Microchip Corporation. All rights reserved. 6 + * Based on {omap2430,tusb6010,ux500}.c 7 + * 8 + */ 9 + 10 + #include <linux/clk.h> 11 + #include <linux/dma-mapping.h> 12 + #include <linux/err.h> 13 + #include <linux/io.h> 14 + #include <linux/kernel.h> 15 + #include <linux/module.h> 16 + #include <linux/platform_device.h> 17 + #include <linux/usb/usb_phy_generic.h> 18 + #include "musb_core.h" 19 + #include "musb_dma.h" 20 + 21 + #define MPFS_MUSB_MAX_EP_NUM 8 22 + #define MPFS_MUSB_RAM_BITS 12 23 + 24 + struct mpfs_glue { 25 + struct device *dev; 26 + struct platform_device *musb; 27 + struct platform_device *phy; 28 + struct clk *clk; 29 + }; 30 + 31 + static struct musb_fifo_cfg mpfs_musb_mode_cfg[] = { 32 + { .hw_ep_num = 1, .style = FIFO_TX, .maxpacket = 512, }, 33 + { .hw_ep_num = 1, .style = FIFO_RX, .maxpacket = 512, }, 34 + { .hw_ep_num = 2, .style = FIFO_TX, .maxpacket = 512, }, 35 + { .hw_ep_num = 2, .style = FIFO_RX, .maxpacket = 512, }, 36 + { .hw_ep_num = 3, .style = FIFO_TX, .maxpacket = 512, }, 37 + { .hw_ep_num = 3, .style = FIFO_RX, .maxpacket = 512, }, 38 + { .hw_ep_num = 4, .style = FIFO_TX, .maxpacket = 1024, }, 39 + { .hw_ep_num = 4, .style = FIFO_RX, .maxpacket = 4096, }, 40 + }; 41 + 42 + static const struct musb_hdrc_config mpfs_musb_hdrc_config = { 43 + .fifo_cfg = mpfs_musb_mode_cfg, 44 + .fifo_cfg_size = ARRAY_SIZE(mpfs_musb_mode_cfg), 45 + .multipoint = true, 46 + .dyn_fifo = true, 47 + .num_eps = MPFS_MUSB_MAX_EP_NUM, 48 + .ram_bits = MPFS_MUSB_RAM_BITS, 49 + }; 50 + 51 + static irqreturn_t mpfs_musb_interrupt(int irq, void *__hci) 52 + { 53 + unsigned long flags; 54 + irqreturn_t ret = IRQ_NONE; 55 + struct musb *musb = __hci; 56 + 57 + spin_lock_irqsave(&musb->lock, flags); 58 + 59 + musb->int_usb = musb_readb(musb->mregs, MUSB_INTRUSB); 60 + musb->int_tx = musb_readw(musb->mregs, MUSB_INTRTX); 61 + musb->int_rx = musb_readw(musb->mregs, MUSB_INTRRX); 62 + 63 + if (musb->int_usb || musb->int_tx || musb->int_rx) { 64 + musb_writeb(musb->mregs, MUSB_INTRUSB, musb->int_usb); 65 + musb_writew(musb->mregs, MUSB_INTRTX, musb->int_tx); 66 + musb_writew(musb->mregs, MUSB_INTRRX, musb->int_rx); 67 + ret = musb_interrupt(musb); 68 + } 69 + 70 + spin_unlock_irqrestore(&musb->lock, flags); 71 + 72 + return ret; 73 + } 74 + 75 + static void mpfs_musb_set_vbus(struct musb *musb, int is_on) 76 + { 77 + u8 devctl; 78 + 79 + /* 80 + * HDRC controls CPEN, but beware current surges during device 81 + * connect. They can trigger transient overcurrent conditions 82 + * that must be ignored. 83 + */ 84 + devctl = musb_readb(musb->mregs, MUSB_DEVCTL); 85 + 86 + if (is_on) { 87 + musb->is_active = 1; 88 + musb->xceiv->otg->default_a = 1; 89 + musb->xceiv->otg->state = OTG_STATE_A_WAIT_VRISE; 90 + devctl |= MUSB_DEVCTL_SESSION; 91 + MUSB_HST_MODE(musb); 92 + } else { 93 + musb->is_active = 0; 94 + 95 + /* 96 + * NOTE: skipping A_WAIT_VFALL -> A_IDLE and 97 + * jumping right to B_IDLE... 98 + */ 99 + musb->xceiv->otg->default_a = 0; 100 + musb->xceiv->otg->state = OTG_STATE_B_IDLE; 101 + devctl &= ~MUSB_DEVCTL_SESSION; 102 + 103 + MUSB_DEV_MODE(musb); 104 + } 105 + 106 + musb_writeb(musb->mregs, MUSB_DEVCTL, devctl); 107 + 108 + dev_dbg(musb->controller, "VBUS %s, devctl %02x\n", 109 + usb_otg_state_string(musb->xceiv->otg->state), 110 + musb_readb(musb->mregs, MUSB_DEVCTL)); 111 + } 112 + 113 + static int mpfs_musb_init(struct musb *musb) 114 + { 115 + struct device *dev = musb->controller; 116 + 117 + musb->xceiv = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2); 118 + if (IS_ERR(musb->xceiv)) { 119 + dev_err(dev, "HS UDC: no transceiver configured\n"); 120 + return PTR_ERR(musb->xceiv); 121 + } 122 + 123 + musb->dyn_fifo = true; 124 + musb->isr = mpfs_musb_interrupt; 125 + 126 + musb_platform_set_vbus(musb, 1); 127 + 128 + return 0; 129 + } 130 + 131 + static const struct musb_platform_ops mpfs_ops = { 132 + .quirks = MUSB_DMA_INVENTRA, 133 + .init = mpfs_musb_init, 134 + .fifo_mode = 2, 135 + #ifdef CONFIG_USB_INVENTRA_DMA 136 + .dma_init = musbhs_dma_controller_create, 137 + .dma_exit = musbhs_dma_controller_destroy, 138 + #endif 139 + .set_vbus = mpfs_musb_set_vbus 140 + }; 141 + 142 + static int mpfs_probe(struct platform_device *pdev) 143 + { 144 + struct musb_hdrc_platform_data *pdata = dev_get_platdata(&pdev->dev); 145 + struct mpfs_glue *glue; 146 + struct platform_device *musb_pdev; 147 + struct device *dev = &pdev->dev; 148 + struct clk *clk; 149 + int ret; 150 + 151 + glue = devm_kzalloc(dev, sizeof(*glue), GFP_KERNEL); 152 + if (!glue) 153 + return -ENOMEM; 154 + 155 + musb_pdev = platform_device_alloc("musb-hdrc", PLATFORM_DEVID_AUTO); 156 + if (!musb_pdev) { 157 + dev_err(dev, "failed to allocate musb device\n"); 158 + return -ENOMEM; 159 + } 160 + 161 + clk = devm_clk_get(&pdev->dev, NULL); 162 + if (IS_ERR(clk)) { 163 + dev_err(&pdev->dev, "failed to get clock\n"); 164 + ret = PTR_ERR(clk); 165 + goto err_phy_release; 166 + } 167 + 168 + ret = clk_prepare_enable(clk); 169 + if (ret) { 170 + dev_err(&pdev->dev, "failed to enable clock\n"); 171 + goto err_phy_release; 172 + } 173 + 174 + musb_pdev->dev.parent = dev; 175 + musb_pdev->dev.coherent_dma_mask = DMA_BIT_MASK(39); 176 + musb_pdev->dev.dma_mask = &musb_pdev->dev.coherent_dma_mask; 177 + device_set_of_node_from_dev(&musb_pdev->dev, dev); 178 + 179 + glue->dev = dev; 180 + glue->musb = musb_pdev; 181 + glue->clk = clk; 182 + 183 + pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); 184 + if (!pdata) { 185 + ret = -ENOMEM; 186 + goto err_clk_disable; 187 + } 188 + 189 + pdata->config = &mpfs_musb_hdrc_config; 190 + pdata->platform_ops = &mpfs_ops; 191 + 192 + pdata->mode = usb_get_dr_mode(dev); 193 + if (pdata->mode == USB_DR_MODE_UNKNOWN) { 194 + dev_info(dev, "No dr_mode property found, defaulting to otg\n"); 195 + pdata->mode = USB_DR_MODE_OTG; 196 + } 197 + 198 + glue->phy = usb_phy_generic_register(); 199 + if (IS_ERR(glue->phy)) { 200 + dev_err(dev, "failed to register usb-phy %ld\n", 201 + PTR_ERR(glue->phy)); 202 + ret = PTR_ERR(glue->phy); 203 + goto err_clk_disable; 204 + } 205 + 206 + platform_set_drvdata(pdev, glue); 207 + 208 + ret = platform_device_add_resources(musb_pdev, pdev->resource, pdev->num_resources); 209 + if (ret) { 210 + dev_err(dev, "failed to add resources\n"); 211 + goto err_clk_disable; 212 + } 213 + 214 + ret = platform_device_add_data(musb_pdev, pdata, sizeof(*pdata)); 215 + if (ret) { 216 + dev_err(dev, "failed to add platform_data\n"); 217 + goto err_clk_disable; 218 + } 219 + 220 + ret = platform_device_add(musb_pdev); 221 + if (ret) { 222 + dev_err(dev, "failed to register musb device\n"); 223 + goto err_clk_disable; 224 + } 225 + 226 + dev_info(&pdev->dev, "Registered MPFS MUSB driver\n"); 227 + return 0; 228 + 229 + err_clk_disable: 230 + clk_disable_unprepare(clk); 231 + 232 + err_phy_release: 233 + usb_phy_generic_unregister(glue->phy); 234 + platform_device_put(musb_pdev); 235 + return ret; 236 + } 237 + 238 + static int mpfs_remove(struct platform_device *pdev) 239 + { 240 + struct mpfs_glue *glue = platform_get_drvdata(pdev); 241 + 242 + clk_disable_unprepare(glue->clk); 243 + platform_device_unregister(glue->musb); 244 + usb_phy_generic_unregister(pdev); 245 + 246 + return 0; 247 + } 248 + 249 + #ifdef CONFIG_OF 250 + static const struct of_device_id mpfs_id_table[] = { 251 + { .compatible = "microchip,mpfs-musb" }, 252 + { } 253 + }; 254 + MODULE_DEVICE_TABLE(of, mpfs_id_table); 255 + #endif 256 + 257 + static struct platform_driver mpfs_musb_driver = { 258 + .probe = mpfs_probe, 259 + .remove = mpfs_remove, 260 + .driver = { 261 + .name = "mpfs-musb", 262 + .of_match_table = of_match_ptr(mpfs_id_table) 263 + }, 264 + }; 265 + 266 + module_platform_driver(mpfs_musb_driver); 267 + 268 + MODULE_DESCRIPTION("PolarFire SoC MUSB Glue Layer"); 269 + MODULE_LICENSE("GPL");
+2 -14
drivers/usb/musb/musb_core.c
··· 2684 2684 musb->context.devctl = musb_readb(musb_base, MUSB_DEVCTL); 2685 2685 2686 2686 for (i = 0; i < musb->config->num_eps; ++i) { 2687 - struct musb_hw_ep *hw_ep; 2688 - 2689 - hw_ep = &musb->endpoints[i]; 2690 - if (!hw_ep) 2691 - continue; 2692 - 2693 - epio = hw_ep->regs; 2687 + epio = musb->endpoints[i].regs; 2694 2688 if (!epio) 2695 2689 continue; 2696 2690 ··· 2759 2765 musb_writeb(musb_base, MUSB_DEVCTL, musb->context.devctl); 2760 2766 2761 2767 for (i = 0; i < musb->config->num_eps; ++i) { 2762 - struct musb_hw_ep *hw_ep; 2763 - 2764 - hw_ep = &musb->endpoints[i]; 2765 - if (!hw_ep) 2766 - continue; 2767 - 2768 - epio = hw_ep->regs; 2768 + epio = musb->endpoints[i].regs; 2769 2769 if (!epio) 2770 2770 continue; 2771 2771
+1 -1
drivers/usb/musb/musb_cppi41.c
··· 286 286 * receive a FIFO empty interrupt so the only thing we can do is 287 287 * to poll for the bit. On HS it usually takes 2us, on FS around 288 288 * 110us - 150us depending on the transfer size. 289 - * We spin on HS (no longer than than 25us and setup a timer on 289 + * We spin on HS (no longer than 25us and setup a timer on 290 290 * FS to check for the bit and complete the transfer. 291 291 */ 292 292 if (is_host_active(musb)) {
-2
drivers/usb/musb/musb_gadget.c
··· 1910 1910 */ 1911 1911 1912 1912 /* Force check of devctl register for PM runtime */ 1913 - schedule_delayed_work(&musb->irq_work, 0); 1914 - 1915 1913 pm_runtime_mark_last_busy(musb->controller); 1916 1914 pm_runtime_put_autosuspend(musb->controller); 1917 1915
+1 -1
drivers/usb/musb/tusb6010.c
··· 495 495 } 496 496 497 497 /* 498 - * Maybe put TUSB6010 into idle mode mode depending on USB link status, 498 + * Maybe put TUSB6010 into idle mode depending on USB link status, 499 499 * like "disconnected" or "suspended". We'll be woken out of it by 500 500 * connect, resume, or disconnect. 501 501 *
+1 -1
drivers/usb/phy/phy-keystone.c
··· 59 59 60 60 val = keystone_usbphy_readl(k_phy->phy_ctrl, USB_PHY_CTL_CLOCK); 61 61 keystone_usbphy_writel(k_phy->phy_ctrl, USB_PHY_CTL_CLOCK, 62 - val &= ~PHY_REF_SSP_EN); 62 + val & ~PHY_REF_SSP_EN); 63 63 } 64 64 65 65 static int keystone_usbphy_probe(struct platform_device *pdev)
+4
drivers/usb/renesas_usbhs/rza.c
··· 23 23 extal_clk = of_find_node_by_name(NULL, "extal"); 24 24 of_property_read_u32(usb_x1_clk, "clock-frequency", &freq_usb); 25 25 of_property_read_u32(extal_clk, "clock-frequency", &freq_extal); 26 + 27 + of_node_put(usb_x1_clk); 28 + of_node_put(extal_clk); 29 + 26 30 if (freq_usb == 0) { 27 31 if (freq_extal == 12000000) { 28 32 /* Select 12MHz XTAL */
+1 -1
drivers/usb/serial/cypress_m8.c
··· 256 256 /* 257 257 * Mike Isely <isely@pobox.com> 2-Feb-2008: The 258 258 * Cypress app note that describes this mechanism 259 - * states the the low-speed part can't handle more 259 + * states that the low-speed part can't handle more 260 260 * than 800 bytes/sec, in which case 4800 baud is the 261 261 * safest speed for a part like that. 262 262 */
+1 -3
drivers/usb/serial/garmin_gps.c
··· 988 988 garmin_data_p->flags &= ~FLAGS_DROP_DATA; 989 989 spin_unlock_irqrestore(&garmin_data_p->lock, flags); 990 990 991 - buffer = kmalloc(count, GFP_ATOMIC); 991 + buffer = kmemdup(buf, count, GFP_ATOMIC); 992 992 if (!buffer) 993 993 return -ENOMEM; 994 994 ··· 997 997 kfree(buffer); 998 998 return -ENOMEM; 999 999 } 1000 - 1001 - memcpy(buffer, buf, count); 1002 1000 1003 1001 usb_serial_debug_data(&port->dev, __func__, count, buffer); 1004 1002
+2 -2
drivers/usb/serial/io_edgeport.c
··· 220 220 __u8 rxHeader3; /* receive header byte 3 */ 221 221 __u8 rxPort; /* the port that we are currently receiving data for */ 222 222 __u8 rxStatusCode; /* the receive status code */ 223 - __u8 rxStatusParam; /* the receive status paramater */ 223 + __u8 rxStatusParam; /* the receive status parameter */ 224 224 __s16 rxBytesRemaining; /* the number of port bytes left to read */ 225 225 struct usb_serial *serial; /* loop back to the owner of this object */ 226 226 }; ··· 901 901 902 902 if (!edge_port->open) { 903 903 /* open timed out */ 904 - dev_dbg(dev, "%s - open timedout\n", __func__); 904 + dev_dbg(dev, "%s - open timeout\n", __func__); 905 905 edge_port->openPending = false; 906 906 return -ENODEV; 907 907 }
+1 -1
drivers/usb/serial/mos7720.c
··· 826 826 /* 827 827 * The 7715 uses the first bulk in/out endpoint pair for the 828 828 * parallel port, and the second for the serial port. We swap 829 - * the endpoint descriptors here so that the the first and 829 + * the endpoint descriptors here so that the first and 830 830 * only registered port structure uses the serial-port 831 831 * endpoints. 832 832 */
+1 -3
drivers/usb/serial/opticon.c
··· 208 208 priv->outstanding_bytes += count; 209 209 spin_unlock_irqrestore(&priv->lock, flags); 210 210 211 - buffer = kmalloc(count, GFP_ATOMIC); 211 + buffer = kmemdup(buf, count, GFP_ATOMIC); 212 212 if (!buffer) 213 213 goto error_no_buffer; 214 214 215 215 urb = usb_alloc_urb(0, GFP_ATOMIC); 216 216 if (!urb) 217 217 goto error_no_urb; 218 - 219 - memcpy(buffer, buf, count); 220 218 221 219 usb_serial_debug_data(&port->dev, __func__, count, buffer); 222 220
+3 -4
drivers/usb/serial/sierra.c
··· 453 453 goto error_simple; 454 454 } 455 455 456 - buffer = kmalloc(writesize, GFP_ATOMIC); 456 + buffer = kmemdup(buf, writesize, GFP_ATOMIC); 457 457 if (!buffer) { 458 458 retval = -ENOMEM; 459 459 goto error_no_buffer; ··· 464 464 retval = -ENOMEM; 465 465 goto error_no_urb; 466 466 } 467 - 468 - memcpy(buffer, buf, writesize); 469 467 470 468 usb_serial_debug_data(&port->dev, __func__, writesize, buffer); 471 469 ··· 735 737 736 738 /* 737 739 * Need to take susp_lock to make sure port is not already being 738 - * resumed, but no need to hold it due to initialized 740 + * resumed, but no need to hold it due to the tty-port initialized 741 + * flag. 739 742 */ 740 743 spin_lock_irq(&intfdata->susp_lock); 741 744 if (--intfdata->open_ports == 0)
+1 -1
drivers/usb/serial/usb-serial.c
··· 295 295 * 296 296 * Shut down a USB serial port. Serialized against activate by the 297 297 * tport mutex and kept to matching open/close pairs 298 - * of calls by the initialized flag. 298 + * of calls by the tty-port initialized flag. 299 299 * 300 300 * Not called if tty is console. 301 301 */
+8 -5
drivers/usb/serial/usb_wwan.c
··· 29 29 #include <linux/bitops.h> 30 30 #include <linux/uaccess.h> 31 31 #include <linux/usb.h> 32 + #include <linux/usb/cdc.h> 32 33 #include <linux/usb/serial.h> 33 34 #include <linux/serial.h> 34 35 #include "usb-wwan.h" ··· 49 48 portdata = usb_get_serial_port_data(port); 50 49 51 50 if (portdata->dtr_state) 52 - val |= 0x01; 51 + val |= USB_CDC_CTRL_DTR; 53 52 if (portdata->rts_state) 54 - val |= 0x02; 53 + val |= USB_CDC_CTRL_RTS; 55 54 56 55 ifnum = serial->interface->cur_altsetting->desc.bInterfaceNumber; 57 56 ··· 60 59 return res; 61 60 62 61 res = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), 63 - 0x22, 0x21, val, ifnum, NULL, 0, 64 - USB_CTRL_SET_TIMEOUT); 62 + USB_CDC_REQ_SET_CONTROL_LINE_STATE, 63 + USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE, 64 + val, ifnum, NULL, 0, USB_CTRL_SET_TIMEOUT); 65 65 66 66 usb_autopm_put_interface(port->serial->interface); 67 67 ··· 390 388 391 389 /* 392 390 * Need to take susp_lock to make sure port is not already being 393 - * resumed, but no need to hold it due to initialized 391 + * resumed, but no need to hold it due to the tty-port initialized 392 + * flag. 394 393 */ 395 394 spin_lock_irq(&intfdata->susp_lock); 396 395 if (--intfdata->open_ports == 0)
+1 -1
drivers/usb/storage/transport.c
··· 1178 1178 /* 1179 1179 * If the device tried to send back more data than the 1180 1180 * amount requested, the spec requires us to transfer 1181 - * the CSW anyway. Since there's no point retrying the 1181 + * the CSW anyway. Since there's no point retrying 1182 1182 * the command, we'll return fake sense data indicating 1183 1183 * Illegal Request, Invalid Field in CDB. 1184 1184 */
+11
drivers/usb/typec/Kconfig
··· 52 52 53 53 source "drivers/usb/typec/tipd/Kconfig" 54 54 55 + config TYPEC_ANX7411 56 + tristate "Analogix ANX7411 Type-C DRP Port controller driver" 57 + depends on I2C 58 + depends on USB_ROLE_SWITCH 59 + help 60 + Say Y or M here if your system has Analogix ANX7411 Type-C DRP Port 61 + controller driver. 62 + 63 + If you choose to build this driver as a dynamically linked module, the 64 + module will be called anx7411.ko. 65 + 55 66 config TYPEC_RT1719 56 67 tristate "Richtek RT1719 Sink Only Type-C controller driver" 57 68 depends on USB_ROLE_SWITCH || !USB_ROLE_SWITCH
+2 -1
drivers/usb/typec/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 2 obj-$(CONFIG_TYPEC) += typec.o 3 - typec-y := class.o mux.o bus.o 3 + typec-y := class.o mux.o bus.o pd.o retimer.o 4 4 typec-$(CONFIG_ACPI) += port-mapper.o 5 5 obj-$(CONFIG_TYPEC) += altmodes/ 6 6 obj-$(CONFIG_TYPEC_TCPM) += tcpm/ 7 7 obj-$(CONFIG_TYPEC_UCSI) += ucsi/ 8 8 obj-$(CONFIG_TYPEC_TPS6598X) += tipd/ 9 + obj-$(CONFIG_TYPEC_ANX7411) += anx7411.o 9 10 obj-$(CONFIG_TYPEC_HD3SS3220) += hd3ss3220.o 10 11 obj-$(CONFIG_TYPEC_QCOM_PMIC) += qcom-pmic-typec.o 11 12 obj-$(CONFIG_TYPEC_STUSB160X) += stusb160x.o
+1601
drivers/usb/typec/anx7411.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + 3 + /* 4 + * Driver for Analogix ANX7411 USB Type-C and PD controller 5 + * 6 + * Copyright(c) 2022, Analogix Semiconductor. All rights reserved. 7 + * 8 + */ 9 + #include <linux/gpio/consumer.h> 10 + #include <linux/i2c.h> 11 + #include <linux/interrupt.h> 12 + #include <linux/iopoll.h> 13 + #include <linux/kernel.h> 14 + #include <linux/module.h> 15 + #include <linux/mutex.h> 16 + #include <linux/of_graph.h> 17 + #include <linux/of_platform.h> 18 + #include <linux/pm_runtime.h> 19 + #include <linux/regulator/consumer.h> 20 + #include <linux/slab.h> 21 + #include <linux/types.h> 22 + #include <linux/usb/pd.h> 23 + #include <linux/usb/role.h> 24 + #include <linux/usb/tcpci.h> 25 + #include <linux/usb/typec.h> 26 + #include <linux/usb/typec_dp.h> 27 + #include <linux/usb/typec_mux.h> 28 + #include <linux/workqueue.h> 29 + #include <linux/power_supply.h> 30 + 31 + #define TCPC_ADDRESS1 0x58 32 + #define TCPC_ADDRESS2 0x56 33 + #define TCPC_ADDRESS3 0x54 34 + #define TCPC_ADDRESS4 0x52 35 + #define SPI_ADDRESS1 0x7e 36 + #define SPI_ADDRESS2 0x6e 37 + #define SPI_ADDRESS3 0x64 38 + #define SPI_ADDRESS4 0x62 39 + 40 + struct anx7411_i2c_select { 41 + u8 tcpc_address; 42 + u8 spi_address; 43 + }; 44 + 45 + #define VID_ANALOGIX 0x1F29 46 + #define PID_ANALOGIX 0x7411 47 + 48 + /* TCPC register define */ 49 + 50 + #define ANALOG_CTRL_10 0xAA 51 + 52 + #define STATUS_LEN 2 53 + #define ALERT_0 0xCB 54 + #define RECEIVED_MSG BIT(7) 55 + #define SOFTWARE_INT BIT(6) 56 + #define MSG_LEN 32 57 + #define HEADER_LEN 2 58 + #define MSG_HEADER 0x00 59 + #define MSG_TYPE 0x01 60 + #define MSG_RAWDATA 0x02 61 + #define MSG_LEN_MASK 0x1F 62 + 63 + #define ALERT_1 0xCC 64 + #define INTP_POW_ON BIT(7) 65 + #define INTP_POW_OFF BIT(6) 66 + 67 + #define VBUS_THRESHOLD_H 0xDD 68 + #define VBUS_THRESHOLD_L 0xDE 69 + 70 + #define FW_CTRL_0 0xF0 71 + #define UNSTRUCT_VDM_EN BIT(0) 72 + #define DELAY_200MS BIT(1) 73 + #define VSAFE0 0 74 + #define VSAFE1 BIT(2) 75 + #define VSAFE2 BIT(3) 76 + #define VSAFE3 (BIT(2) | BIT(3)) 77 + #define FRS_EN BIT(7) 78 + 79 + #define FW_PARAM 0xF1 80 + #define DONGLE_IOP BIT(0) 81 + 82 + #define FW_CTRL_2 0xF7 83 + #define SINK_CTRL_DIS_FLAG BIT(5) 84 + 85 + /* SPI register define */ 86 + #define OCM_CTRL_0 0x6E 87 + #define OCM_RESET BIT(6) 88 + 89 + #define MAX_VOLTAGE 0xAC 90 + #define MAX_POWER 0xAD 91 + #define MIN_POWER 0xAE 92 + 93 + #define REQUEST_VOLTAGE 0xAF 94 + #define VOLTAGE_UNIT 100 /* mV per unit */ 95 + 96 + #define REQUEST_CURRENT 0xB1 97 + #define CURRENT_UNIT 50 /* mA per unit */ 98 + 99 + #define CMD_SEND_BUF 0xC0 100 + #define CMD_RECV_BUF 0xE0 101 + 102 + #define REQ_VOL_20V_IN_100MV 0xC8 103 + #define REQ_CUR_2_25A_IN_50MA 0x2D 104 + #define REQ_CUR_3_25A_IN_50MA 0x41 105 + 106 + #define DEF_5V 5000 107 + #define DEF_1_5A 1500 108 + 109 + #define LOBYTE(w) ((u8)((w) & 0xFF)) 110 + #define HIBYTE(w) ((u8)(((u16)(w) >> 8) & 0xFF)) 111 + 112 + enum anx7411_typec_message_type { 113 + TYPE_SRC_CAP = 0x00, 114 + TYPE_SNK_CAP = 0x01, 115 + TYPE_SNK_IDENTITY = 0x02, 116 + TYPE_SVID = 0x03, 117 + TYPE_SET_SNK_DP_CAP = 0x08, 118 + TYPE_PSWAP_REQ = 0x10, 119 + TYPE_DSWAP_REQ = 0x11, 120 + TYPE_VDM = 0x14, 121 + TYPE_OBJ_REQ = 0x16, 122 + TYPE_DP_ALT_ENTER = 0x19, 123 + TYPE_DP_DISCOVER_MODES_INFO = 0x27, 124 + TYPE_GET_DP_CONFIG = 0x29, 125 + TYPE_DP_CONFIGURE = 0x2A, 126 + TYPE_GET_DP_DISCOVER_MODES_INFO = 0x2E, 127 + TYPE_GET_DP_ALT_ENTER = 0x2F, 128 + }; 129 + 130 + #define FW_CTRL_1 0xB2 131 + #define AUTO_PD_EN BIT(1) 132 + #define TRYSRC_EN BIT(2) 133 + #define TRYSNK_EN BIT(3) 134 + #define FORCE_SEND_RDO BIT(6) 135 + 136 + #define FW_VER 0xB4 137 + #define FW_SUBVER 0xB5 138 + 139 + #define INT_MASK 0xB6 140 + #define INT_STS 0xB7 141 + #define OCM_BOOT_UP BIT(0) 142 + #define OC_OV_EVENT BIT(1) 143 + #define VCONN_CHANGE BIT(2) 144 + #define VBUS_CHANGE BIT(3) 145 + #define CC_STATUS_CHANGE BIT(4) 146 + #define DATA_ROLE_CHANGE BIT(5) 147 + #define PR_CONSUMER_GOT_POWER BIT(6) 148 + #define HPD_STATUS_CHANGE BIT(7) 149 + 150 + #define SYSTEM_STSTUS 0xB8 151 + /* 0: SINK off; 1: SINK on */ 152 + #define SINK_STATUS BIT(1) 153 + /* 0: VCONN off; 1: VCONN on*/ 154 + #define VCONN_STATUS BIT(2) 155 + /* 0: vbus off; 1: vbus on*/ 156 + #define VBUS_STATUS BIT(3) 157 + /* 1: host; 0:device*/ 158 + #define DATA_ROLE BIT(5) 159 + /* 0: Chunking; 1: Unchunked*/ 160 + #define SUPPORT_UNCHUNKING BIT(6) 161 + /* 0: HPD low; 1: HPD high*/ 162 + #define HPD_STATUS BIT(7) 163 + 164 + #define DATA_DFP 1 165 + #define DATA_UFP 2 166 + #define POWER_SOURCE 1 167 + #define POWER_SINK 2 168 + 169 + #define CC_STATUS 0xB9 170 + #define CC1_RD BIT(0) 171 + #define CC2_RD BIT(4) 172 + #define CC1_RA BIT(1) 173 + #define CC2_RA BIT(5) 174 + #define CC1_RD BIT(0) 175 + #define CC1_RP(cc) (((cc) >> 2) & 0x03) 176 + #define CC2_RP(cc) (((cc) >> 6) & 0x03) 177 + 178 + #define PD_REV_INIT 0xBA 179 + 180 + #define PD_EXT_MSG_CTRL 0xBB 181 + #define SRC_CAP_EXT_REPLY BIT(0) 182 + #define MANUFACTURER_INFO_REPLY BIT(1) 183 + #define BATTERY_STS_REPLY BIT(2) 184 + #define BATTERY_CAP_REPLY BIT(3) 185 + #define ALERT_REPLY BIT(4) 186 + #define STATUS_REPLY BIT(5) 187 + #define PPS_STATUS_REPLY BIT(6) 188 + #define SNK_CAP_EXT_REPLY BIT(7) 189 + 190 + #define NO_CONNECT 0x00 191 + #define USB3_1_CONNECTED 0x01 192 + #define DP_ALT_4LANES 0x02 193 + #define USB3_1_DP_2LANES 0x03 194 + #define CC1_CONNECTED 0x01 195 + #define CC2_CONNECTED 0x02 196 + #define SELECT_PIN_ASSIGMENT_C 0x04 197 + #define SELECT_PIN_ASSIGMENT_D 0x08 198 + #define SELECT_PIN_ASSIGMENT_E 0x10 199 + #define SELECT_PIN_ASSIGMENT_U 0x00 200 + #define REDRIVER_ADDRESS 0x20 201 + #define REDRIVER_OFFSET 0x00 202 + 203 + #define DP_SVID 0xFF01 204 + #define VDM_ACK 0x40 205 + #define VDM_CMD_RES 0x00 206 + #define VDM_CMD_DIS_ID 0x01 207 + #define VDM_CMD_DIS_SVID 0x02 208 + #define VDM_CMD_DIS_MOD 0x03 209 + #define VDM_CMD_ENTER_MODE 0x04 210 + #define VDM_CMD_EXIT_MODE 0x05 211 + #define VDM_CMD_ATTENTION 0x06 212 + #define VDM_CMD_GET_STS 0x10 213 + #define VDM_CMD_AND_ACK_MASK 0x5F 214 + 215 + #define MAX_ALTMODE 2 216 + 217 + #define HAS_SOURCE_CAP BIT(0) 218 + #define HAS_SINK_CAP BIT(1) 219 + #define HAS_SINK_WATT BIT(2) 220 + 221 + enum anx7411_psy_state { 222 + /* copy from drivers/usb/typec/tcpm */ 223 + ANX7411_PSY_OFFLINE = 0, 224 + ANX7411_PSY_FIXED_ONLINE, 225 + 226 + /* private */ 227 + /* PD keep in, but disconnct power to bq25700, 228 + * this state can be active when higher capacity adapter plug in, 229 + * and change to ONLINE state when higher capacity adapter plug out 230 + */ 231 + ANX7411_PSY_HANG = 0xff, 232 + }; 233 + 234 + struct typec_params { 235 + int request_current; /* ma */ 236 + int request_voltage; /* mv */ 237 + int cc_connect; 238 + int cc_orientation_valid; 239 + int cc_status; 240 + int data_role; 241 + int power_role; 242 + int vconn_role; 243 + int dp_altmode_enter; 244 + int cust_altmode_enter; 245 + struct usb_role_switch *role_sw; 246 + struct typec_port *port; 247 + struct typec_partner *partner; 248 + struct typec_mux_dev *typec_mux; 249 + struct typec_switch_dev *typec_switch; 250 + struct typec_altmode *amode[MAX_ALTMODE]; 251 + struct typec_altmode *port_amode[MAX_ALTMODE]; 252 + struct typec_displayport_data data; 253 + int pin_assignment; 254 + struct typec_capability caps; 255 + u32 src_pdo[PDO_MAX_OBJECTS]; 256 + u32 sink_pdo[PDO_MAX_OBJECTS]; 257 + u8 caps_flags; 258 + u8 src_pdo_nr; 259 + u8 sink_pdo_nr; 260 + u8 sink_watt; 261 + u8 sink_voltage; 262 + }; 263 + 264 + #define MAX_BUF_LEN 30 265 + struct fw_msg { 266 + u8 msg_len; 267 + u8 msg_type; 268 + u8 buf[MAX_BUF_LEN]; 269 + } __packed; 270 + 271 + struct anx7411_data { 272 + int fw_version; 273 + int fw_subversion; 274 + struct i2c_client *tcpc_client; 275 + struct i2c_client *spi_client; 276 + struct fw_msg send_msg; 277 + struct fw_msg recv_msg; 278 + struct gpio_desc *intp_gpiod; 279 + struct fwnode_handle *connector_fwnode; 280 + struct typec_params typec; 281 + int intp_irq; 282 + struct work_struct work; 283 + struct workqueue_struct *workqueue; 284 + /* Lock for interrupt work queue */ 285 + struct mutex lock; 286 + 287 + enum anx7411_psy_state psy_online; 288 + enum power_supply_usb_type usb_type; 289 + struct power_supply *psy; 290 + struct power_supply_desc psy_desc; 291 + struct device *dev; 292 + }; 293 + 294 + static u8 snk_identity[] = { 295 + LOBYTE(VID_ANALOGIX), HIBYTE(VID_ANALOGIX), 0x00, 0x82, /* snk_id_hdr */ 296 + 0x00, 0x00, 0x00, 0x00, /* snk_cert */ 297 + 0x00, 0x00, LOBYTE(PID_ANALOGIX), HIBYTE(PID_ANALOGIX), /* 5snk_ama */ 298 + }; 299 + 300 + static u8 dp_caps[4] = {0xC6, 0x00, 0x00, 0x00}; 301 + 302 + static int anx7411_reg_read(struct i2c_client *client, 303 + u8 reg_addr) 304 + { 305 + return i2c_smbus_read_byte_data(client, reg_addr); 306 + } 307 + 308 + static int anx7411_reg_block_read(struct i2c_client *client, 309 + u8 reg_addr, u8 len, u8 *buf) 310 + { 311 + return i2c_smbus_read_i2c_block_data(client, reg_addr, len, buf); 312 + } 313 + 314 + static int anx7411_reg_write(struct i2c_client *client, 315 + u8 reg_addr, u8 reg_val) 316 + { 317 + return i2c_smbus_write_byte_data(client, reg_addr, reg_val); 318 + } 319 + 320 + static int anx7411_reg_block_write(struct i2c_client *client, 321 + u8 reg_addr, u8 len, u8 *buf) 322 + { 323 + return i2c_smbus_write_i2c_block_data(client, reg_addr, len, buf); 324 + } 325 + 326 + static struct anx7411_i2c_select anx7411_i2c_addr[] = { 327 + {TCPC_ADDRESS1, SPI_ADDRESS1}, 328 + {TCPC_ADDRESS2, SPI_ADDRESS2}, 329 + {TCPC_ADDRESS3, SPI_ADDRESS3}, 330 + {TCPC_ADDRESS4, SPI_ADDRESS4}, 331 + }; 332 + 333 + static int anx7411_detect_power_mode(struct anx7411_data *ctx) 334 + { 335 + int ret; 336 + int mode; 337 + 338 + ret = anx7411_reg_read(ctx->spi_client, REQUEST_CURRENT); 339 + if (ret < 0) 340 + return ret; 341 + 342 + ctx->typec.request_current = ret * CURRENT_UNIT; /* 50ma per unit */ 343 + 344 + ret = anx7411_reg_read(ctx->spi_client, REQUEST_VOLTAGE); 345 + if (ret < 0) 346 + return ret; 347 + 348 + ctx->typec.request_voltage = ret * VOLTAGE_UNIT; /* 100mv per unit */ 349 + 350 + if (ctx->psy_online == ANX7411_PSY_OFFLINE) { 351 + ctx->psy_online = ANX7411_PSY_FIXED_ONLINE; 352 + ctx->usb_type = POWER_SUPPLY_USB_TYPE_PD; 353 + power_supply_changed(ctx->psy); 354 + } 355 + 356 + if (!ctx->typec.cc_orientation_valid) 357 + return 0; 358 + 359 + if (ctx->typec.cc_connect == CC1_CONNECTED) 360 + mode = CC1_RP(ctx->typec.cc_status); 361 + else 362 + mode = CC2_RP(ctx->typec.cc_status); 363 + if (mode) { 364 + typec_set_pwr_opmode(ctx->typec.port, mode - 1); 365 + return 0; 366 + } 367 + 368 + typec_set_pwr_opmode(ctx->typec.port, TYPEC_PWR_MODE_PD); 369 + 370 + return 0; 371 + } 372 + 373 + static int anx7411_register_partner(struct anx7411_data *ctx, 374 + int pd, int accessory) 375 + { 376 + struct typec_partner_desc desc; 377 + struct typec_partner *partner; 378 + 379 + if (ctx->typec.partner) 380 + return 0; 381 + 382 + desc.usb_pd = pd; 383 + desc.accessory = accessory; 384 + desc.identity = NULL; 385 + partner = typec_register_partner(ctx->typec.port, &desc); 386 + if (IS_ERR(partner)) 387 + return PTR_ERR(partner); 388 + 389 + ctx->typec.partner = partner; 390 + 391 + return 0; 392 + } 393 + 394 + static int anx7411_detect_cc_orientation(struct anx7411_data *ctx) 395 + { 396 + struct device *dev = &ctx->spi_client->dev; 397 + int ret; 398 + int cc1_rd, cc2_rd; 399 + int cc1_ra, cc2_ra; 400 + int cc1_rp, cc2_rp; 401 + 402 + ret = anx7411_reg_read(ctx->spi_client, CC_STATUS); 403 + if (ret < 0) 404 + return ret; 405 + 406 + ctx->typec.cc_status = ret; 407 + 408 + cc1_rd = ret & CC1_RD ? 1 : 0; 409 + cc2_rd = ret & CC2_RD ? 1 : 0; 410 + cc1_ra = ret & CC1_RA ? 1 : 0; 411 + cc2_ra = ret & CC2_RA ? 1 : 0; 412 + cc1_rp = CC1_RP(ret); 413 + cc2_rp = CC2_RP(ret); 414 + 415 + /* Debug cable, nothing to do */ 416 + if (cc1_rd && cc2_rd) { 417 + ctx->typec.cc_orientation_valid = 0; 418 + return anx7411_register_partner(ctx, 0, TYPEC_ACCESSORY_DEBUG); 419 + } 420 + 421 + if (cc1_ra && cc2_ra) { 422 + ctx->typec.cc_orientation_valid = 0; 423 + return anx7411_register_partner(ctx, 0, TYPEC_ACCESSORY_AUDIO); 424 + } 425 + 426 + ctx->typec.cc_orientation_valid = 1; 427 + 428 + ret = anx7411_register_partner(ctx, 1, TYPEC_ACCESSORY_NONE); 429 + if (ret) { 430 + dev_err(dev, "register partner\n"); 431 + return ret; 432 + } 433 + 434 + if (cc1_rd || cc1_rp) { 435 + typec_set_orientation(ctx->typec.port, TYPEC_ORIENTATION_NORMAL); 436 + ctx->typec.cc_connect = CC1_CONNECTED; 437 + } 438 + 439 + if (cc2_rd || cc2_rp) { 440 + typec_set_orientation(ctx->typec.port, TYPEC_ORIENTATION_REVERSE); 441 + ctx->typec.cc_connect = CC2_CONNECTED; 442 + } 443 + 444 + return 0; 445 + } 446 + 447 + static int anx7411_set_mux(struct anx7411_data *ctx, int pin_assignment) 448 + { 449 + int mode = TYPEC_STATE_SAFE; 450 + 451 + switch (pin_assignment) { 452 + case SELECT_PIN_ASSIGMENT_U: 453 + /* default 4 line USB 3.1 */ 454 + mode = TYPEC_STATE_MODAL; 455 + break; 456 + case SELECT_PIN_ASSIGMENT_C: 457 + case SELECT_PIN_ASSIGMENT_E: 458 + /* 4 line DP */ 459 + mode = TYPEC_STATE_SAFE; 460 + break; 461 + case SELECT_PIN_ASSIGMENT_D: 462 + /* 2 line DP, 2 line USB */ 463 + mode = TYPEC_MODE_USB3; 464 + break; 465 + default: 466 + mode = TYPEC_STATE_SAFE; 467 + break; 468 + } 469 + 470 + ctx->typec.pin_assignment = pin_assignment; 471 + 472 + return typec_set_mode(ctx->typec.port, mode); 473 + } 474 + 475 + static int anx7411_set_usb_role(struct anx7411_data *ctx, enum usb_role role) 476 + { 477 + if (!ctx->typec.role_sw) 478 + return 0; 479 + 480 + return usb_role_switch_set_role(ctx->typec.role_sw, role); 481 + } 482 + 483 + static int anx7411_data_role_detect(struct anx7411_data *ctx) 484 + { 485 + int ret; 486 + 487 + ret = anx7411_reg_read(ctx->spi_client, SYSTEM_STSTUS); 488 + if (ret < 0) 489 + return ret; 490 + 491 + ctx->typec.data_role = (ret & DATA_ROLE) ? TYPEC_HOST : TYPEC_DEVICE; 492 + ctx->typec.vconn_role = (ret & VCONN_STATUS) ? TYPEC_SOURCE : TYPEC_SINK; 493 + 494 + typec_set_data_role(ctx->typec.port, ctx->typec.data_role); 495 + 496 + typec_set_vconn_role(ctx->typec.port, ctx->typec.vconn_role); 497 + 498 + if (ctx->typec.data_role == TYPEC_HOST) 499 + return anx7411_set_usb_role(ctx, USB_ROLE_HOST); 500 + 501 + return anx7411_set_usb_role(ctx, USB_ROLE_DEVICE); 502 + } 503 + 504 + static int anx7411_power_role_detect(struct anx7411_data *ctx) 505 + { 506 + int ret; 507 + 508 + ret = anx7411_reg_read(ctx->spi_client, SYSTEM_STSTUS); 509 + if (ret < 0) 510 + return ret; 511 + 512 + ctx->typec.power_role = (ret & SINK_STATUS) ? TYPEC_SINK : TYPEC_SOURCE; 513 + 514 + if (ctx->typec.power_role == TYPEC_SOURCE) { 515 + ctx->typec.request_current = DEF_1_5A; 516 + ctx->typec.request_voltage = DEF_5V; 517 + } 518 + 519 + typec_set_pwr_role(ctx->typec.port, ctx->typec.power_role); 520 + 521 + return 0; 522 + } 523 + 524 + static int anx7411_cc_status_detect(struct anx7411_data *ctx) 525 + { 526 + anx7411_detect_cc_orientation(ctx); 527 + anx7411_detect_power_mode(ctx); 528 + 529 + return 0; 530 + } 531 + 532 + static void anx7411_partner_unregister_altmode(struct anx7411_data *ctx) 533 + { 534 + int i; 535 + 536 + ctx->typec.dp_altmode_enter = 0; 537 + ctx->typec.cust_altmode_enter = 0; 538 + 539 + for (i = 0; i < MAX_ALTMODE; i++) 540 + if (ctx->typec.amode[i]) { 541 + typec_unregister_altmode(ctx->typec.amode[i]); 542 + ctx->typec.amode[i] = NULL; 543 + } 544 + 545 + ctx->typec.pin_assignment = 0; 546 + } 547 + 548 + static int anx7411_typec_register_altmode(struct anx7411_data *ctx, 549 + int svid, int vdo) 550 + { 551 + struct device *dev = &ctx->spi_client->dev; 552 + struct typec_altmode_desc desc; 553 + int err; 554 + int i; 555 + 556 + desc.svid = svid; 557 + desc.vdo = vdo; 558 + 559 + for (i = 0; i < MAX_ALTMODE; i++) 560 + if (!ctx->typec.amode[i]) 561 + break; 562 + 563 + desc.mode = i + 1; /* start with 1 */ 564 + 565 + if (i >= MAX_ALTMODE) { 566 + dev_err(dev, "no altmode space for registering\n"); 567 + return -ENOMEM; 568 + } 569 + 570 + ctx->typec.amode[i] = typec_partner_register_altmode(ctx->typec.partner, 571 + &desc); 572 + if (IS_ERR(ctx->typec.amode[i])) { 573 + dev_err(dev, "failed to register altmode\n"); 574 + err = PTR_ERR(ctx->typec.amode[i]); 575 + ctx->typec.amode[i] = NULL; 576 + return err; 577 + } 578 + 579 + return 0; 580 + } 581 + 582 + static void anx7411_unregister_partner(struct anx7411_data *ctx) 583 + { 584 + if (ctx->typec.partner) { 585 + typec_unregister_partner(ctx->typec.partner); 586 + ctx->typec.partner = NULL; 587 + } 588 + } 589 + 590 + static int anx7411_update_altmode(struct anx7411_data *ctx, int svid) 591 + { 592 + int i; 593 + 594 + if (svid == DP_SVID) 595 + ctx->typec.dp_altmode_enter = 1; 596 + else 597 + ctx->typec.cust_altmode_enter = 1; 598 + 599 + for (i = 0; i < MAX_ALTMODE; i++) { 600 + if (!ctx->typec.amode[i]) 601 + continue; 602 + 603 + if (ctx->typec.amode[i]->svid == svid) { 604 + typec_altmode_update_active(ctx->typec.amode[i], true); 605 + typec_altmode_notify(ctx->typec.amode[i], 606 + ctx->typec.pin_assignment, 607 + &ctx->typec.data); 608 + break; 609 + } 610 + } 611 + 612 + return 0; 613 + } 614 + 615 + static int anx7411_register_altmode(struct anx7411_data *ctx, 616 + bool dp_altmode, u8 *buf) 617 + { 618 + int ret; 619 + int svid; 620 + int mid; 621 + 622 + if (!ctx->typec.partner) 623 + return 0; 624 + 625 + svid = DP_SVID; 626 + if (dp_altmode) { 627 + mid = buf[0] | (buf[1] << 8) | (buf[2] << 16) | (buf[3] << 24); 628 + 629 + return anx7411_typec_register_altmode(ctx, svid, mid); 630 + } 631 + 632 + svid = (buf[3] << 8) | buf[2]; 633 + if ((buf[0] & VDM_CMD_AND_ACK_MASK) != (VDM_ACK | VDM_CMD_ENTER_MODE)) 634 + return anx7411_update_altmode(ctx, svid); 635 + 636 + if ((buf[0] & VDM_CMD_AND_ACK_MASK) != (VDM_ACK | VDM_CMD_DIS_MOD)) 637 + return 0; 638 + 639 + mid = buf[4] | (buf[5] << 8) | (buf[6] << 16) | (buf[7] << 24); 640 + 641 + ret = anx7411_typec_register_altmode(ctx, svid, mid); 642 + if (ctx->typec.cust_altmode_enter) 643 + ret |= anx7411_update_altmode(ctx, svid); 644 + 645 + return ret; 646 + } 647 + 648 + static int anx7411_parse_cmd(struct anx7411_data *ctx, u8 type, u8 *buf, u8 len) 649 + { 650 + struct device *dev = &ctx->spi_client->dev; 651 + u8 cur_50ma, vol_100mv; 652 + 653 + switch (type) { 654 + case TYPE_SRC_CAP: 655 + cur_50ma = anx7411_reg_read(ctx->spi_client, REQUEST_CURRENT); 656 + vol_100mv = anx7411_reg_read(ctx->spi_client, REQUEST_VOLTAGE); 657 + 658 + ctx->typec.request_voltage = vol_100mv * VOLTAGE_UNIT; 659 + ctx->typec.request_current = cur_50ma * CURRENT_UNIT; 660 + 661 + ctx->psy_online = ANX7411_PSY_FIXED_ONLINE; 662 + ctx->usb_type = POWER_SUPPLY_USB_TYPE_PD; 663 + power_supply_changed(ctx->psy); 664 + break; 665 + case TYPE_SNK_CAP: 666 + break; 667 + case TYPE_SVID: 668 + break; 669 + case TYPE_SNK_IDENTITY: 670 + break; 671 + case TYPE_GET_DP_ALT_ENTER: 672 + /* DP alt mode enter success */ 673 + if (buf[0]) 674 + anx7411_update_altmode(ctx, DP_SVID); 675 + break; 676 + case TYPE_DP_ALT_ENTER: 677 + /* Update DP altmode */ 678 + anx7411_update_altmode(ctx, DP_SVID); 679 + break; 680 + case TYPE_OBJ_REQ: 681 + anx7411_detect_power_mode(ctx); 682 + break; 683 + case TYPE_DP_CONFIGURE: 684 + anx7411_set_mux(ctx, buf[1]); 685 + break; 686 + case TYPE_DP_DISCOVER_MODES_INFO: 687 + /* Make sure discover modes valid */ 688 + if (buf[0] | buf[1]) 689 + /* Register DP Altmode */ 690 + anx7411_register_altmode(ctx, 1, buf); 691 + break; 692 + case TYPE_VDM: 693 + /* Register other altmode */ 694 + anx7411_register_altmode(ctx, 0, buf); 695 + break; 696 + default: 697 + dev_err(dev, "ignore message(0x%.02x).\n", type); 698 + break; 699 + } 700 + 701 + return 0; 702 + } 703 + 704 + static u8 checksum(struct device *dev, u8 *buf, u8 len) 705 + { 706 + u8 ret = 0; 707 + u8 i; 708 + 709 + for (i = 0; i < len; i++) 710 + ret += buf[i]; 711 + 712 + return ret; 713 + } 714 + 715 + static int anx7411_read_msg_ctrl_status(struct i2c_client *client) 716 + { 717 + return anx7411_reg_read(client, CMD_SEND_BUF); 718 + } 719 + 720 + static int anx7411_wait_msg_empty(struct i2c_client *client) 721 + { 722 + int val; 723 + 724 + return readx_poll_timeout(anx7411_read_msg_ctrl_status, 725 + client, val, (val < 0) || (val == 0), 726 + 2000, 2000 * 150); 727 + } 728 + 729 + static int anx7411_send_msg(struct anx7411_data *ctx, u8 type, u8 *buf, u8 size) 730 + { 731 + struct device *dev = &ctx->spi_client->dev; 732 + struct fw_msg *msg = &ctx->send_msg; 733 + u8 crc; 734 + int ret; 735 + 736 + size = min_t(u8, size, (u8)MAX_BUF_LEN); 737 + memcpy(msg->buf, buf, size); 738 + msg->msg_type = type; 739 + /* msg len equals buffer length + msg_type */ 740 + msg->msg_len = size + 1; 741 + 742 + /* Do CRC check for all buffer data and msg_len and msg_type */ 743 + crc = checksum(dev, (u8 *)msg, size + HEADER_LEN); 744 + msg->buf[size] = 0 - crc; 745 + 746 + ret = anx7411_wait_msg_empty(ctx->spi_client); 747 + if (ret) 748 + return ret; 749 + 750 + ret = anx7411_reg_block_write(ctx->spi_client, 751 + CMD_SEND_BUF + 1, size + HEADER_LEN, 752 + &msg->msg_type); 753 + ret |= anx7411_reg_write(ctx->spi_client, CMD_SEND_BUF, 754 + msg->msg_len); 755 + return ret; 756 + } 757 + 758 + static int anx7411_process_cmd(struct anx7411_data *ctx) 759 + { 760 + struct device *dev = &ctx->spi_client->dev; 761 + struct fw_msg *msg = &ctx->recv_msg; 762 + u8 len; 763 + u8 crc; 764 + int ret; 765 + 766 + /* Read message from firmware */ 767 + ret = anx7411_reg_block_read(ctx->spi_client, CMD_RECV_BUF, 768 + MSG_LEN, (u8 *)msg); 769 + if (ret < 0) 770 + return 0; 771 + 772 + if (!msg->msg_len) 773 + return 0; 774 + 775 + ret = anx7411_reg_write(ctx->spi_client, CMD_RECV_BUF, 0); 776 + if (ret) 777 + return ret; 778 + 779 + len = msg->msg_len & MSG_LEN_MASK; 780 + crc = checksum(dev, (u8 *)msg, len + HEADER_LEN); 781 + if (crc) { 782 + dev_err(dev, "message error crc(0x%.02x)\n", crc); 783 + return -ERANGE; 784 + } 785 + 786 + return anx7411_parse_cmd(ctx, msg->msg_type, msg->buf, len - 1); 787 + } 788 + 789 + static void anx7411_translate_payload(struct device *dev, __le32 *payload, 790 + u32 *pdo, int nr, const char *type) 791 + { 792 + int i; 793 + 794 + if (nr > PDO_MAX_OBJECTS) { 795 + dev_err(dev, "nr(%d) exceed PDO_MAX_OBJECTS(%d)\n", 796 + nr, PDO_MAX_OBJECTS); 797 + 798 + return; 799 + } 800 + 801 + for (i = 0; i < nr; i++) 802 + payload[i] = cpu_to_le32(pdo[i]); 803 + } 804 + 805 + static int anx7411_config(struct anx7411_data *ctx) 806 + { 807 + struct device *dev = &ctx->spi_client->dev; 808 + struct typec_params *typecp = &ctx->typec; 809 + __le32 payload[PDO_MAX_OBJECTS]; 810 + int ret; 811 + 812 + /* Config PD FW work under PD 2.0 */ 813 + ret = anx7411_reg_write(ctx->spi_client, PD_REV_INIT, PD_REV20); 814 + ret |= anx7411_reg_write(ctx->tcpc_client, FW_CTRL_0, 815 + UNSTRUCT_VDM_EN | DELAY_200MS | 816 + VSAFE1 | FRS_EN); 817 + ret |= anx7411_reg_write(ctx->spi_client, FW_CTRL_1, 818 + AUTO_PD_EN | FORCE_SEND_RDO); 819 + 820 + /* Set VBUS current threshold */ 821 + ret |= anx7411_reg_write(ctx->tcpc_client, VBUS_THRESHOLD_H, 0xff); 822 + ret |= anx7411_reg_write(ctx->tcpc_client, VBUS_THRESHOLD_L, 0x03); 823 + 824 + /* Fix dongle compatible issue */ 825 + ret |= anx7411_reg_write(ctx->tcpc_client, FW_PARAM, 826 + anx7411_reg_read(ctx->tcpc_client, FW_PARAM) | 827 + DONGLE_IOP); 828 + ret |= anx7411_reg_write(ctx->spi_client, INT_MASK, 0); 829 + 830 + ret |= anx7411_reg_write(ctx->spi_client, PD_EXT_MSG_CTRL, 0xFF); 831 + if (ret) 832 + return ret; 833 + 834 + if (typecp->caps_flags & HAS_SOURCE_CAP) { 835 + anx7411_translate_payload(dev, payload, typecp->src_pdo, 836 + typecp->src_pdo_nr, "source"); 837 + anx7411_send_msg(ctx, TYPE_SRC_CAP, (u8 *)&payload, 838 + typecp->src_pdo_nr * 4); 839 + anx7411_send_msg(ctx, TYPE_SNK_IDENTITY, snk_identity, 840 + sizeof(snk_identity)); 841 + anx7411_send_msg(ctx, TYPE_SET_SNK_DP_CAP, dp_caps, 842 + sizeof(dp_caps)); 843 + } 844 + 845 + if (typecp->caps_flags & HAS_SINK_CAP) { 846 + anx7411_translate_payload(dev, payload, typecp->sink_pdo, 847 + typecp->sink_pdo_nr, "sink"); 848 + anx7411_send_msg(ctx, TYPE_SNK_CAP, (u8 *)&payload, 849 + typecp->sink_pdo_nr * 4); 850 + } 851 + 852 + if (typecp->caps_flags & HAS_SINK_WATT) { 853 + if (typecp->sink_watt) { 854 + ret |= anx7411_reg_write(ctx->spi_client, MAX_POWER, 855 + typecp->sink_watt); 856 + /* Set min power to 1W */ 857 + ret |= anx7411_reg_write(ctx->spi_client, MIN_POWER, 2); 858 + } 859 + 860 + if (typecp->sink_voltage) 861 + ret |= anx7411_reg_write(ctx->spi_client, MAX_VOLTAGE, 862 + typecp->sink_voltage); 863 + if (ret) 864 + return ret; 865 + } 866 + 867 + if (!typecp->caps_flags) 868 + usleep_range(5000, 6000); 869 + 870 + ctx->fw_version = anx7411_reg_read(ctx->spi_client, FW_VER); 871 + ctx->fw_subversion = anx7411_reg_read(ctx->spi_client, FW_SUBVER); 872 + 873 + return 0; 874 + } 875 + 876 + static void anx7411_chip_standby(struct anx7411_data *ctx) 877 + { 878 + int ret; 879 + u8 cc1, cc2; 880 + struct device *dev = &ctx->spi_client->dev; 881 + 882 + ret = anx7411_reg_write(ctx->spi_client, OCM_CTRL_0, 883 + anx7411_reg_read(ctx->spi_client, OCM_CTRL_0) | 884 + OCM_RESET); 885 + ret |= anx7411_reg_write(ctx->tcpc_client, ANALOG_CTRL_10, 0x80); 886 + /* Set TCPC to RD and DRP enable */ 887 + cc1 = TCPC_ROLE_CTRL_CC_RD << TCPC_ROLE_CTRL_CC1_SHIFT; 888 + cc2 = TCPC_ROLE_CTRL_CC_RD << TCPC_ROLE_CTRL_CC2_SHIFT; 889 + ret |= anx7411_reg_write(ctx->tcpc_client, TCPC_ROLE_CTRL, 890 + TCPC_ROLE_CTRL_DRP | cc1 | cc2); 891 + 892 + /* Send DRP toggle command */ 893 + ret |= anx7411_reg_write(ctx->tcpc_client, TCPC_COMMAND, 894 + TCPC_CMD_LOOK4CONNECTION); 895 + 896 + /* Send TCPC enter standby command */ 897 + ret |= anx7411_reg_write(ctx->tcpc_client, 898 + TCPC_COMMAND, TCPC_CMD_I2C_IDLE); 899 + if (ret) 900 + dev_err(dev, "Chip standby failed\n"); 901 + } 902 + 903 + static void anx7411_work_func(struct work_struct *work) 904 + { 905 + int ret; 906 + u8 buf[STATUS_LEN]; 907 + u8 int_change; /* Interrupt change */ 908 + u8 int_status; /* Firmware status update */ 909 + u8 alert0, alert1; /* Interrupt alert source */ 910 + struct anx7411_data *ctx = container_of(work, struct anx7411_data, work); 911 + struct device *dev = &ctx->spi_client->dev; 912 + 913 + mutex_lock(&ctx->lock); 914 + 915 + /* Read interrupt change status */ 916 + ret = anx7411_reg_block_read(ctx->spi_client, INT_STS, STATUS_LEN, buf); 917 + if (ret < 0) { 918 + /* Power standby mode, just return */ 919 + goto unlock; 920 + } 921 + int_change = buf[0]; 922 + int_status = buf[1]; 923 + 924 + /* Read alert register */ 925 + ret = anx7411_reg_block_read(ctx->tcpc_client, ALERT_0, STATUS_LEN, buf); 926 + if (ret < 0) 927 + goto unlock; 928 + 929 + alert0 = buf[0]; 930 + alert1 = buf[1]; 931 + 932 + /* Clear interrupt and alert status */ 933 + ret = anx7411_reg_write(ctx->spi_client, INT_STS, 0); 934 + ret |= anx7411_reg_write(ctx->tcpc_client, ALERT_0, alert0); 935 + ret |= anx7411_reg_write(ctx->tcpc_client, ALERT_1, alert1); 936 + if (ret) 937 + goto unlock; 938 + 939 + if (alert1 & INTP_POW_OFF) { 940 + anx7411_partner_unregister_altmode(ctx); 941 + if (anx7411_set_usb_role(ctx, USB_ROLE_NONE)) 942 + dev_err(dev, "Set usb role\n"); 943 + anx7411_unregister_partner(ctx); 944 + ctx->psy_online = ANX7411_PSY_OFFLINE; 945 + ctx->usb_type = POWER_SUPPLY_USB_TYPE_C; 946 + ctx->typec.request_voltage = 0; 947 + ctx->typec.request_current = 0; 948 + power_supply_changed(ctx->psy); 949 + anx7411_chip_standby(ctx); 950 + goto unlock; 951 + } 952 + 953 + if ((alert0 & SOFTWARE_INT) && (int_change & OCM_BOOT_UP)) { 954 + if (anx7411_config(ctx)) 955 + dev_err(dev, "Config failed\n"); 956 + if (anx7411_data_role_detect(ctx)) 957 + dev_err(dev, "set PD data role\n"); 958 + if (anx7411_power_role_detect(ctx)) 959 + dev_err(dev, "set PD power role\n"); 960 + anx7411_set_mux(ctx, SELECT_PIN_ASSIGMENT_C); 961 + } 962 + 963 + if (alert0 & RECEIVED_MSG) 964 + anx7411_process_cmd(ctx); 965 + 966 + ret = (int_status & DATA_ROLE) ? TYPEC_HOST : TYPEC_DEVICE; 967 + if (ctx->typec.data_role != ret) 968 + if (anx7411_data_role_detect(ctx)) 969 + dev_err(dev, "set PD data role\n"); 970 + 971 + ret = (int_status & SINK_STATUS) ? TYPEC_SINK : TYPEC_SOURCE; 972 + if (ctx->typec.power_role != ret) 973 + if (anx7411_power_role_detect(ctx)) 974 + dev_err(dev, "set PD power role\n"); 975 + 976 + if ((alert0 & SOFTWARE_INT) && (int_change & CC_STATUS_CHANGE)) 977 + anx7411_cc_status_detect(ctx); 978 + 979 + unlock: 980 + mutex_unlock(&ctx->lock); 981 + } 982 + 983 + static irqreturn_t anx7411_intr_isr(int irq, void *data) 984 + { 985 + struct anx7411_data *ctx = (struct anx7411_data *)data; 986 + 987 + queue_work(ctx->workqueue, &ctx->work); 988 + 989 + return IRQ_HANDLED; 990 + } 991 + 992 + static int anx7411_register_i2c_dummy_clients(struct anx7411_data *ctx, 993 + struct i2c_client *client) 994 + { 995 + int i; 996 + u8 spi_addr; 997 + 998 + for (i = 0; i < ARRAY_SIZE(anx7411_i2c_addr); i++) { 999 + if (client->addr == (anx7411_i2c_addr[i].tcpc_address >> 1)) { 1000 + spi_addr = anx7411_i2c_addr[i].spi_address >> 1; 1001 + ctx->spi_client = i2c_new_dummy_device(client->adapter, 1002 + spi_addr); 1003 + if (!IS_ERR(ctx->spi_client)) 1004 + return 0; 1005 + } 1006 + } 1007 + 1008 + dev_err(&client->dev, "unable to get SPI slave\n"); 1009 + return -ENOMEM; 1010 + } 1011 + 1012 + static void anx7411_port_unregister_altmodes(struct typec_altmode **adev) 1013 + { 1014 + int i; 1015 + 1016 + for (i = 0; i < MAX_ALTMODE; i++) 1017 + if (adev[i]) { 1018 + typec_unregister_altmode(adev[i]); 1019 + adev[i] = NULL; 1020 + } 1021 + } 1022 + 1023 + static int anx7411_usb_mux_set(struct typec_mux_dev *mux, 1024 + struct typec_mux_state *state) 1025 + { 1026 + struct anx7411_data *ctx = typec_mux_get_drvdata(mux); 1027 + struct device *dev = &ctx->spi_client->dev; 1028 + int has_dp; 1029 + 1030 + has_dp = (state->alt && state->alt->svid == USB_TYPEC_DP_SID && 1031 + state->alt->mode == USB_TYPEC_DP_MODE); 1032 + if (!has_dp) 1033 + dev_err(dev, "dp altmode not register\n"); 1034 + 1035 + return 0; 1036 + } 1037 + 1038 + static int anx7411_usb_set_orientation(struct typec_switch_dev *sw, 1039 + enum typec_orientation orientation) 1040 + { 1041 + /* No need set */ 1042 + 1043 + return 0; 1044 + } 1045 + 1046 + static int anx7411_register_switch(struct anx7411_data *ctx, 1047 + struct device *dev, 1048 + struct fwnode_handle *fwnode) 1049 + { 1050 + struct typec_switch_desc sw_desc = { }; 1051 + 1052 + sw_desc.fwnode = fwnode; 1053 + sw_desc.drvdata = ctx; 1054 + sw_desc.name = fwnode_get_name(fwnode); 1055 + sw_desc.set = anx7411_usb_set_orientation; 1056 + 1057 + ctx->typec.typec_switch = typec_switch_register(dev, &sw_desc); 1058 + if (IS_ERR(ctx->typec.typec_switch)) { 1059 + dev_err(dev, "switch register failed\n"); 1060 + return PTR_ERR(ctx->typec.typec_switch); 1061 + } 1062 + 1063 + return 0; 1064 + } 1065 + 1066 + static int anx7411_register_mux(struct anx7411_data *ctx, 1067 + struct device *dev, 1068 + struct fwnode_handle *fwnode) 1069 + { 1070 + struct typec_mux_desc mux_desc = { }; 1071 + 1072 + mux_desc.fwnode = fwnode; 1073 + mux_desc.drvdata = ctx; 1074 + mux_desc.name = fwnode_get_name(fwnode); 1075 + mux_desc.set = anx7411_usb_mux_set; 1076 + 1077 + ctx->typec.typec_mux = typec_mux_register(dev, &mux_desc); 1078 + if (IS_ERR(ctx->typec.typec_mux)) { 1079 + dev_err(dev, "mux register failed\n"); 1080 + return PTR_ERR(ctx->typec.typec_mux); 1081 + } 1082 + 1083 + return 0; 1084 + } 1085 + 1086 + static void anx7411_unregister_mux(struct anx7411_data *ctx) 1087 + { 1088 + if (ctx->typec.typec_mux) { 1089 + typec_mux_unregister(ctx->typec.typec_mux); 1090 + ctx->typec.typec_mux = NULL; 1091 + } 1092 + } 1093 + 1094 + static void anx7411_unregister_switch(struct anx7411_data *ctx) 1095 + { 1096 + if (ctx->typec.typec_switch) { 1097 + typec_switch_unregister(ctx->typec.typec_switch); 1098 + ctx->typec.typec_switch = NULL; 1099 + } 1100 + } 1101 + 1102 + static int anx7411_typec_switch_probe(struct anx7411_data *ctx, 1103 + struct device *dev) 1104 + { 1105 + int ret; 1106 + struct device_node *node; 1107 + 1108 + node = of_find_node_by_name(dev->of_node, "orientation_switch"); 1109 + if (!node) 1110 + return 0; 1111 + 1112 + ret = anx7411_register_switch(ctx, dev, &node->fwnode); 1113 + if (ret) { 1114 + dev_err(dev, "failed register switch"); 1115 + return ret; 1116 + } 1117 + 1118 + node = of_find_node_by_name(dev->of_node, "mode_switch"); 1119 + if (!node) { 1120 + dev_err(dev, "no typec mux exist"); 1121 + ret = -ENODEV; 1122 + goto unregister_switch; 1123 + } 1124 + 1125 + ret = anx7411_register_mux(ctx, dev, &node->fwnode); 1126 + if (ret) { 1127 + dev_err(dev, "failed register mode switch"); 1128 + ret = -ENODEV; 1129 + goto unregister_switch; 1130 + } 1131 + 1132 + return 0; 1133 + 1134 + unregister_switch: 1135 + anx7411_unregister_switch(ctx); 1136 + 1137 + return ret; 1138 + } 1139 + 1140 + static int anx7411_typec_port_probe(struct anx7411_data *ctx, 1141 + struct device *dev) 1142 + { 1143 + struct typec_capability *cap = &ctx->typec.caps; 1144 + struct typec_params *typecp = &ctx->typec; 1145 + struct fwnode_handle *fwnode; 1146 + const char *buf; 1147 + int ret, i; 1148 + 1149 + fwnode = device_get_named_child_node(dev, "connector"); 1150 + if (!fwnode) 1151 + return -EINVAL; 1152 + 1153 + ret = fwnode_property_read_string(fwnode, "power-role", &buf); 1154 + if (ret) { 1155 + dev_err(dev, "power-role not found: %d\n", ret); 1156 + return ret; 1157 + } 1158 + 1159 + ret = typec_find_port_power_role(buf); 1160 + if (ret < 0) 1161 + return ret; 1162 + cap->type = ret; 1163 + 1164 + ret = fwnode_property_read_string(fwnode, "data-role", &buf); 1165 + if (ret) { 1166 + dev_err(dev, "data-role not found: %d\n", ret); 1167 + return ret; 1168 + } 1169 + 1170 + ret = typec_find_port_data_role(buf); 1171 + if (ret < 0) 1172 + return ret; 1173 + cap->data = ret; 1174 + 1175 + ret = fwnode_property_read_string(fwnode, "try-power-role", &buf); 1176 + if (ret) { 1177 + dev_err(dev, "try-power-role not found: %d\n", ret); 1178 + return ret; 1179 + } 1180 + 1181 + ret = typec_find_power_role(buf); 1182 + if (ret < 0) 1183 + return ret; 1184 + cap->prefer_role = ret; 1185 + 1186 + /* Get source pdos */ 1187 + ret = fwnode_property_count_u32(fwnode, "source-pdos"); 1188 + if (ret > 0) { 1189 + typecp->src_pdo_nr = min_t(u8, ret, PDO_MAX_OBJECTS); 1190 + ret = fwnode_property_read_u32_array(fwnode, "source-pdos", 1191 + typecp->src_pdo, 1192 + typecp->src_pdo_nr); 1193 + if (ret < 0) { 1194 + dev_err(dev, "source cap validate failed: %d\n", ret); 1195 + return -EINVAL; 1196 + } 1197 + 1198 + typecp->caps_flags |= HAS_SOURCE_CAP; 1199 + } 1200 + 1201 + ret = fwnode_property_count_u32(fwnode, "sink-pdos"); 1202 + if (ret > 0) { 1203 + typecp->sink_pdo_nr = min_t(u8, ret, PDO_MAX_OBJECTS); 1204 + ret = fwnode_property_read_u32_array(fwnode, "sink-pdos", 1205 + typecp->sink_pdo, 1206 + typecp->sink_pdo_nr); 1207 + if (ret < 0) { 1208 + dev_err(dev, "sink cap validate failed: %d\n", ret); 1209 + return -EINVAL; 1210 + } 1211 + 1212 + for (i = 0; i < typecp->sink_pdo_nr; i++) { 1213 + ret = 0; 1214 + switch (pdo_type(typecp->sink_pdo[i])) { 1215 + case PDO_TYPE_FIXED: 1216 + ret = pdo_fixed_voltage(typecp->sink_pdo[i]); 1217 + break; 1218 + case PDO_TYPE_BATT: 1219 + case PDO_TYPE_VAR: 1220 + ret = pdo_max_voltage(typecp->sink_pdo[i]); 1221 + break; 1222 + case PDO_TYPE_APDO: 1223 + default: 1224 + ret = 0; 1225 + break; 1226 + } 1227 + 1228 + /* 100mv per unit */ 1229 + typecp->sink_voltage = max(5000, ret) / 100; 1230 + } 1231 + 1232 + typecp->caps_flags |= HAS_SINK_CAP; 1233 + } 1234 + 1235 + if (!fwnode_property_read_u32(fwnode, "op-sink-microwatt", &ret)) { 1236 + typecp->sink_watt = ret / 500000; /* 500mw per unit */ 1237 + typecp->caps_flags |= HAS_SINK_WATT; 1238 + } 1239 + 1240 + cap->fwnode = fwnode; 1241 + 1242 + ctx->typec.role_sw = usb_role_switch_get(dev); 1243 + if (IS_ERR(ctx->typec.role_sw)) { 1244 + dev_err(dev, "USB role switch not found.\n"); 1245 + ctx->typec.role_sw = NULL; 1246 + } 1247 + 1248 + ctx->typec.port = typec_register_port(dev, cap); 1249 + if (IS_ERR(ctx->typec.port)) { 1250 + ret = PTR_ERR(ctx->typec.port); 1251 + ctx->typec.port = NULL; 1252 + dev_err(dev, "Failed to register type c port %d\n", ret); 1253 + return ret; 1254 + } 1255 + 1256 + typec_port_register_altmodes(ctx->typec.port, NULL, ctx, 1257 + ctx->typec.port_amode, 1258 + MAX_ALTMODE); 1259 + return 0; 1260 + } 1261 + 1262 + static int anx7411_typec_check_connection(struct anx7411_data *ctx) 1263 + { 1264 + int ret; 1265 + 1266 + ret = anx7411_reg_read(ctx->spi_client, FW_VER); 1267 + if (ret < 0) 1268 + return 0; /* No device attached in typec port */ 1269 + 1270 + /* Clear interrupt and alert status */ 1271 + ret = anx7411_reg_write(ctx->spi_client, INT_STS, 0); 1272 + ret |= anx7411_reg_write(ctx->tcpc_client, ALERT_0, 0xFF); 1273 + ret |= anx7411_reg_write(ctx->tcpc_client, ALERT_1, 0xFF); 1274 + if (ret) 1275 + return ret; 1276 + 1277 + ret = anx7411_cc_status_detect(ctx); 1278 + ret |= anx7411_power_role_detect(ctx); 1279 + ret |= anx7411_data_role_detect(ctx); 1280 + ret |= anx7411_set_mux(ctx, SELECT_PIN_ASSIGMENT_C); 1281 + if (ret) 1282 + return ret; 1283 + 1284 + ret = anx7411_send_msg(ctx, TYPE_GET_DP_ALT_ENTER, NULL, 0); 1285 + ret |= anx7411_send_msg(ctx, TYPE_GET_DP_DISCOVER_MODES_INFO, NULL, 0); 1286 + 1287 + return ret; 1288 + } 1289 + 1290 + static int __maybe_unused anx7411_runtime_pm_suspend(struct device *dev) 1291 + { 1292 + struct anx7411_data *ctx = dev_get_drvdata(dev); 1293 + 1294 + mutex_lock(&ctx->lock); 1295 + 1296 + anx7411_partner_unregister_altmode(ctx); 1297 + 1298 + if (ctx->typec.partner) 1299 + anx7411_unregister_partner(ctx); 1300 + 1301 + mutex_unlock(&ctx->lock); 1302 + 1303 + return 0; 1304 + } 1305 + 1306 + static int __maybe_unused anx7411_runtime_pm_resume(struct device *dev) 1307 + { 1308 + struct anx7411_data *ctx = dev_get_drvdata(dev); 1309 + 1310 + mutex_lock(&ctx->lock); 1311 + /* Detect PD connection */ 1312 + if (anx7411_typec_check_connection(ctx)) 1313 + dev_err(dev, "check connection"); 1314 + 1315 + mutex_unlock(&ctx->lock); 1316 + 1317 + return 0; 1318 + } 1319 + 1320 + static const struct dev_pm_ops anx7411_pm_ops = { 1321 + SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, 1322 + pm_runtime_force_resume) 1323 + SET_RUNTIME_PM_OPS(anx7411_runtime_pm_suspend, 1324 + anx7411_runtime_pm_resume, NULL) 1325 + }; 1326 + 1327 + static void anx7411_get_gpio_irq(struct anx7411_data *ctx) 1328 + { 1329 + struct device *dev = &ctx->tcpc_client->dev; 1330 + 1331 + ctx->intp_gpiod = devm_gpiod_get_optional(dev, "interrupt", GPIOD_IN); 1332 + if (IS_ERR_OR_NULL(ctx->intp_gpiod)) { 1333 + dev_err(dev, "no interrupt gpio property\n"); 1334 + return; 1335 + } 1336 + 1337 + ctx->intp_irq = gpiod_to_irq(ctx->intp_gpiod); 1338 + if (ctx->intp_irq < 0) 1339 + dev_err(dev, "failed to get GPIO IRQ\n"); 1340 + } 1341 + 1342 + static enum power_supply_usb_type anx7411_psy_usb_types[] = { 1343 + POWER_SUPPLY_USB_TYPE_C, 1344 + POWER_SUPPLY_USB_TYPE_PD, 1345 + POWER_SUPPLY_USB_TYPE_PD_PPS, 1346 + }; 1347 + 1348 + static enum power_supply_property anx7411_psy_props[] = { 1349 + POWER_SUPPLY_PROP_USB_TYPE, 1350 + POWER_SUPPLY_PROP_ONLINE, 1351 + POWER_SUPPLY_PROP_VOLTAGE_MIN, 1352 + POWER_SUPPLY_PROP_VOLTAGE_MAX, 1353 + POWER_SUPPLY_PROP_VOLTAGE_NOW, 1354 + POWER_SUPPLY_PROP_CURRENT_MAX, 1355 + POWER_SUPPLY_PROP_CURRENT_NOW, 1356 + }; 1357 + 1358 + static int anx7411_psy_set_prop(struct power_supply *psy, 1359 + enum power_supply_property psp, 1360 + const union power_supply_propval *val) 1361 + { 1362 + struct anx7411_data *ctx = power_supply_get_drvdata(psy); 1363 + int ret = 0; 1364 + 1365 + if (psp == POWER_SUPPLY_PROP_ONLINE) 1366 + ctx->psy_online = val->intval; 1367 + else 1368 + ret = -EINVAL; 1369 + 1370 + power_supply_changed(ctx->psy); 1371 + return ret; 1372 + } 1373 + 1374 + static int anx7411_psy_prop_writeable(struct power_supply *psy, 1375 + enum power_supply_property psp) 1376 + { 1377 + return psp == POWER_SUPPLY_PROP_ONLINE; 1378 + } 1379 + 1380 + static int anx7411_psy_get_prop(struct power_supply *psy, 1381 + enum power_supply_property psp, 1382 + union power_supply_propval *val) 1383 + { 1384 + struct anx7411_data *ctx = power_supply_get_drvdata(psy); 1385 + int ret = 0; 1386 + 1387 + switch (psp) { 1388 + case POWER_SUPPLY_PROP_USB_TYPE: 1389 + val->intval = ctx->usb_type; 1390 + break; 1391 + case POWER_SUPPLY_PROP_ONLINE: 1392 + val->intval = ctx->psy_online; 1393 + break; 1394 + case POWER_SUPPLY_PROP_VOLTAGE_NOW: 1395 + case POWER_SUPPLY_PROP_VOLTAGE_MIN: 1396 + case POWER_SUPPLY_PROP_VOLTAGE_MAX: 1397 + val->intval = (ctx->psy_online) ? 1398 + ctx->typec.request_voltage * 1000 : 0; 1399 + break; 1400 + case POWER_SUPPLY_PROP_CURRENT_NOW: 1401 + case POWER_SUPPLY_PROP_CURRENT_MAX: 1402 + val->intval = (ctx->psy_online) ? 1403 + ctx->typec.request_current * 1000 : 0; 1404 + break; 1405 + default: 1406 + ret = -EINVAL; 1407 + break; 1408 + } 1409 + return ret; 1410 + } 1411 + 1412 + static int anx7411_psy_register(struct anx7411_data *ctx) 1413 + { 1414 + struct power_supply_desc *psy_desc = &ctx->psy_desc; 1415 + struct power_supply_config psy_cfg = {}; 1416 + char *psy_name; 1417 + 1418 + psy_name = devm_kasprintf(ctx->dev, GFP_KERNEL, "anx7411-source-psy-%s", 1419 + dev_name(ctx->dev)); 1420 + if (!psy_name) 1421 + return -ENOMEM; 1422 + 1423 + psy_desc->name = psy_name; 1424 + psy_desc->type = POWER_SUPPLY_TYPE_USB; 1425 + psy_desc->usb_types = anx7411_psy_usb_types; 1426 + psy_desc->num_usb_types = ARRAY_SIZE(anx7411_psy_usb_types); 1427 + psy_desc->properties = anx7411_psy_props; 1428 + psy_desc->num_properties = ARRAY_SIZE(anx7411_psy_props); 1429 + 1430 + psy_desc->get_property = anx7411_psy_get_prop; 1431 + psy_desc->set_property = anx7411_psy_set_prop; 1432 + psy_desc->property_is_writeable = anx7411_psy_prop_writeable; 1433 + 1434 + ctx->usb_type = POWER_SUPPLY_USB_TYPE_C; 1435 + ctx->psy = devm_power_supply_register(ctx->dev, psy_desc, &psy_cfg); 1436 + 1437 + if (IS_ERR(ctx->psy)) 1438 + dev_warn(ctx->dev, "unable to register psy\n"); 1439 + 1440 + return PTR_ERR_OR_ZERO(ctx->psy); 1441 + } 1442 + 1443 + static int anx7411_i2c_probe(struct i2c_client *client, 1444 + const struct i2c_device_id *id) 1445 + { 1446 + struct anx7411_data *plat; 1447 + struct device *dev = &client->dev; 1448 + int ret; 1449 + 1450 + if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_I2C_BLOCK)) 1451 + return -ENODEV; 1452 + 1453 + plat = devm_kzalloc(dev, sizeof(*plat), GFP_KERNEL); 1454 + if (!plat) 1455 + return -ENOMEM; 1456 + 1457 + plat->tcpc_client = client; 1458 + i2c_set_clientdata(client, plat); 1459 + 1460 + mutex_init(&plat->lock); 1461 + 1462 + ret = anx7411_register_i2c_dummy_clients(plat, client); 1463 + if (ret) { 1464 + dev_err(dev, "fail to reserve I2C bus\n"); 1465 + return ret; 1466 + } 1467 + 1468 + ret = anx7411_typec_switch_probe(plat, dev); 1469 + if (ret) { 1470 + dev_err(dev, "fail to probe typec switch\n"); 1471 + goto free_i2c_dummy; 1472 + } 1473 + 1474 + ret = anx7411_typec_port_probe(plat, dev); 1475 + if (ret) { 1476 + dev_err(dev, "fail to probe typec property.\n"); 1477 + ret = -ENODEV; 1478 + goto free_typec_switch; 1479 + } 1480 + 1481 + plat->intp_irq = client->irq; 1482 + if (!client->irq) 1483 + anx7411_get_gpio_irq(plat); 1484 + 1485 + if (!plat->intp_irq) { 1486 + dev_err(dev, "fail to get interrupt IRQ\n"); 1487 + ret = -EINVAL; 1488 + goto free_typec_port; 1489 + } 1490 + 1491 + plat->dev = dev; 1492 + plat->psy_online = ANX7411_PSY_OFFLINE; 1493 + ret = anx7411_psy_register(plat); 1494 + if (ret) { 1495 + dev_err(dev, "register psy\n"); 1496 + goto free_typec_port; 1497 + } 1498 + 1499 + INIT_WORK(&plat->work, anx7411_work_func); 1500 + plat->workqueue = alloc_workqueue("anx7411_work", 1501 + WQ_FREEZABLE | 1502 + WQ_MEM_RECLAIM, 1503 + 1); 1504 + if (!plat->workqueue) { 1505 + dev_err(dev, "fail to create work queue\n"); 1506 + ret = -ENOMEM; 1507 + goto free_typec_port; 1508 + } 1509 + 1510 + ret = devm_request_threaded_irq(dev, plat->intp_irq, 1511 + NULL, anx7411_intr_isr, 1512 + IRQF_TRIGGER_FALLING | 1513 + IRQF_ONESHOT, 1514 + "anx7411-intp", plat); 1515 + if (ret) { 1516 + dev_err(dev, "fail to request irq\n"); 1517 + goto free_wq; 1518 + } 1519 + 1520 + if (anx7411_typec_check_connection(plat)) 1521 + dev_err(dev, "check status\n"); 1522 + 1523 + pm_runtime_enable(dev); 1524 + 1525 + return 0; 1526 + 1527 + free_wq: 1528 + destroy_workqueue(plat->workqueue); 1529 + 1530 + free_typec_port: 1531 + typec_unregister_port(plat->typec.port); 1532 + anx7411_port_unregister_altmodes(plat->typec.port_amode); 1533 + 1534 + free_typec_switch: 1535 + anx7411_unregister_switch(plat); 1536 + anx7411_unregister_mux(plat); 1537 + 1538 + free_i2c_dummy: 1539 + i2c_unregister_device(plat->spi_client); 1540 + 1541 + return ret; 1542 + } 1543 + 1544 + static int anx7411_i2c_remove(struct i2c_client *client) 1545 + { 1546 + struct anx7411_data *plat = i2c_get_clientdata(client); 1547 + 1548 + anx7411_partner_unregister_altmode(plat); 1549 + anx7411_unregister_partner(plat); 1550 + 1551 + if (plat->workqueue) 1552 + destroy_workqueue(plat->workqueue); 1553 + 1554 + if (plat->spi_client) 1555 + i2c_unregister_device(plat->spi_client); 1556 + 1557 + if (plat->typec.role_sw) 1558 + usb_role_switch_put(plat->typec.role_sw); 1559 + 1560 + anx7411_unregister_mux(plat); 1561 + 1562 + anx7411_unregister_switch(plat); 1563 + 1564 + if (plat->typec.port) 1565 + typec_unregister_port(plat->typec.port); 1566 + 1567 + anx7411_port_unregister_altmodes(plat->typec.port_amode); 1568 + 1569 + return 0; 1570 + } 1571 + 1572 + static const struct i2c_device_id anx7411_id[] = { 1573 + {"anx7411", 0}, 1574 + {} 1575 + }; 1576 + 1577 + MODULE_DEVICE_TABLE(i2c, anx7411_id); 1578 + 1579 + static const struct of_device_id anx_match_table[] = { 1580 + {.compatible = "analogix,anx7411",}, 1581 + {}, 1582 + }; 1583 + 1584 + static struct i2c_driver anx7411_driver = { 1585 + .driver = { 1586 + .name = "anx7411", 1587 + .of_match_table = anx_match_table, 1588 + .pm = &anx7411_pm_ops, 1589 + }, 1590 + .probe = anx7411_i2c_probe, 1591 + .remove = anx7411_i2c_remove, 1592 + 1593 + .id_table = anx7411_id, 1594 + }; 1595 + 1596 + module_i2c_driver(anx7411_driver); 1597 + 1598 + MODULE_DESCRIPTION("Anx7411 USB Type-C PD driver"); 1599 + MODULE_AUTHOR("Xin Ji <xji@analogixsemi.com>"); 1600 + MODULE_LICENSE("GPL"); 1601 + MODULE_VERSION("0.1.5");
+166 -1
drivers/usb/typec/class.c
··· 12 12 #include <linux/slab.h> 13 13 #include <linux/usb/pd_vdo.h> 14 14 #include <linux/usb/typec_mux.h> 15 + #include <linux/usb/typec_retimer.h> 15 16 16 17 #include "bus.h" 17 18 #include "class.h" 19 + #include "pd.h" 18 20 19 21 static DEFINE_IDA(typec_index_ida); 20 22 ··· 723 721 EXPORT_SYMBOL_GPL(typec_partner_set_pd_revision); 724 722 725 723 /** 724 + * typec_partner_set_usb_power_delivery - Declare USB Power Delivery Contract. 725 + * @partner: The partner device. 726 + * @pd: The USB PD instance. 727 + * 728 + * This routine can be used to declare USB Power Delivery Contract with @partner 729 + * by linking @partner to @pd which contains the objects that were used during the 730 + * negotiation of the contract. 731 + * 732 + * If @pd is NULL, the link is removed and the contract with @partner has ended. 733 + */ 734 + int typec_partner_set_usb_power_delivery(struct typec_partner *partner, 735 + struct usb_power_delivery *pd) 736 + { 737 + int ret; 738 + 739 + if (IS_ERR_OR_NULL(partner) || partner->pd == pd) 740 + return 0; 741 + 742 + if (pd) { 743 + ret = usb_power_delivery_link_device(pd, &partner->dev); 744 + if (ret) 745 + return ret; 746 + } else { 747 + usb_power_delivery_unlink_device(partner->pd, &partner->dev); 748 + } 749 + 750 + partner->pd = pd; 751 + 752 + return 0; 753 + } 754 + EXPORT_SYMBOL_GPL(typec_partner_set_usb_power_delivery); 755 + 756 + /** 726 757 * typec_partner_set_num_altmodes - Set the number of available partner altmodes 727 758 * @partner: The partner to be updated. 728 759 * @num_altmodes: The number of altmodes we want to specify as available. ··· 1205 1170 /* ------------------------------------------------------------------------- */ 1206 1171 /* USB Type-C ports */ 1207 1172 1173 + /** 1174 + * typec_port_set_usb_power_delivery - Assign USB PD for port. 1175 + * @port: USB Type-C port. 1176 + * @pd: USB PD instance. 1177 + * 1178 + * This routine can be used to set the USB Power Delivery Capabilities for @port 1179 + * that it will advertise to the partner. 1180 + * 1181 + * If @pd is NULL, the assignment is removed. 1182 + */ 1183 + int typec_port_set_usb_power_delivery(struct typec_port *port, struct usb_power_delivery *pd) 1184 + { 1185 + int ret; 1186 + 1187 + if (IS_ERR_OR_NULL(port) || port->pd == pd) 1188 + return 0; 1189 + 1190 + if (pd) { 1191 + ret = usb_power_delivery_link_device(pd, &port->dev); 1192 + if (ret) 1193 + return ret; 1194 + } else { 1195 + usb_power_delivery_unlink_device(port->pd, &port->dev); 1196 + } 1197 + 1198 + port->pd = pd; 1199 + 1200 + return 0; 1201 + } 1202 + EXPORT_SYMBOL_GPL(typec_port_set_usb_power_delivery); 1203 + 1204 + static ssize_t select_usb_power_delivery_store(struct device *dev, 1205 + struct device_attribute *attr, 1206 + const char *buf, size_t size) 1207 + { 1208 + struct typec_port *port = to_typec_port(dev); 1209 + struct usb_power_delivery *pd; 1210 + 1211 + if (!port->ops || !port->ops->pd_set) 1212 + return -EOPNOTSUPP; 1213 + 1214 + pd = usb_power_delivery_find(buf); 1215 + if (!pd) 1216 + return -EINVAL; 1217 + 1218 + return port->ops->pd_set(port, pd); 1219 + } 1220 + 1221 + static ssize_t select_usb_power_delivery_show(struct device *dev, 1222 + struct device_attribute *attr, char *buf) 1223 + { 1224 + struct typec_port *port = to_typec_port(dev); 1225 + struct usb_power_delivery **pds; 1226 + struct usb_power_delivery *pd; 1227 + int ret = 0; 1228 + 1229 + if (!port->ops || !port->ops->pd_get) 1230 + return -EOPNOTSUPP; 1231 + 1232 + pds = port->ops->pd_get(port); 1233 + if (!pds) 1234 + return 0; 1235 + 1236 + for (pd = pds[0]; pd; pd++) { 1237 + if (pd == port->pd) 1238 + ret += sysfs_emit(buf + ret, "[%s] ", dev_name(&pd->dev)); 1239 + else 1240 + ret += sysfs_emit(buf + ret, "%s ", dev_name(&pd->dev)); 1241 + } 1242 + 1243 + buf[ret - 1] = '\n'; 1244 + 1245 + return ret; 1246 + } 1247 + static DEVICE_ATTR_RW(select_usb_power_delivery); 1248 + 1249 + static struct attribute *port_attrs[] = { 1250 + &dev_attr_select_usb_power_delivery.attr, 1251 + NULL 1252 + }; 1253 + 1254 + static umode_t port_attr_is_visible(struct kobject *kobj, struct attribute *attr, int n) 1255 + { 1256 + struct typec_port *port = to_typec_port(kobj_to_dev(kobj)); 1257 + 1258 + if (!port->pd || !port->ops || !port->ops->pd_get) 1259 + return 0; 1260 + if (!port->ops->pd_set) 1261 + return 0444; 1262 + 1263 + return attr->mode; 1264 + } 1265 + 1266 + static const struct attribute_group pd_group = { 1267 + .is_visible = port_attr_is_visible, 1268 + .attrs = port_attrs, 1269 + }; 1270 + 1208 1271 static const char * const typec_orientations[] = { 1209 1272 [TYPEC_ORIENTATION_NONE] = "unknown", 1210 1273 [TYPEC_ORIENTATION_NORMAL] = "normal", ··· 1714 1581 1715 1582 static const struct attribute_group *typec_groups[] = { 1716 1583 &typec_group, 1584 + &pd_group, 1717 1585 NULL 1718 1586 }; 1719 1587 ··· 1737 1603 ida_destroy(&port->mode_ids); 1738 1604 typec_switch_put(port->sw); 1739 1605 typec_mux_put(port->mux); 1606 + typec_retimer_put(port->retimer); 1740 1607 kfree(port->cap); 1741 1608 kfree(port); 1742 1609 } ··· 2252 2117 return ERR_PTR(ret); 2253 2118 } 2254 2119 2120 + port->retimer = typec_retimer_get(&port->dev); 2121 + if (IS_ERR(port->retimer)) { 2122 + ret = PTR_ERR(port->retimer); 2123 + put_device(&port->dev); 2124 + return ERR_PTR(ret); 2125 + } 2126 + 2255 2127 ret = device_add(&port->dev); 2256 2128 if (ret) { 2257 2129 dev_err(parent, "failed to register port (%d)\n", ret); 2258 2130 put_device(&port->dev); 2131 + return ERR_PTR(ret); 2132 + } 2133 + 2134 + ret = typec_port_set_usb_power_delivery(port, cap->pd); 2135 + if (ret) { 2136 + dev_err(&port->dev, "failed to link pd\n"); 2137 + device_unregister(&port->dev); 2259 2138 return ERR_PTR(ret); 2260 2139 } 2261 2140 ··· 2291 2142 { 2292 2143 if (!IS_ERR_OR_NULL(port)) { 2293 2144 typec_unlink_ports(port); 2145 + typec_port_set_usb_power_delivery(port, NULL); 2294 2146 device_unregister(&port->dev); 2295 2147 } 2296 2148 } ··· 2309 2159 if (ret) 2310 2160 goto err_unregister_bus; 2311 2161 2312 - ret = class_register(&typec_class); 2162 + ret = class_register(&retimer_class); 2313 2163 if (ret) 2314 2164 goto err_unregister_mux_class; 2315 2165 2166 + ret = class_register(&typec_class); 2167 + if (ret) 2168 + goto err_unregister_retimer_class; 2169 + 2170 + ret = usb_power_delivery_init(); 2171 + if (ret) 2172 + goto err_unregister_class; 2173 + 2316 2174 return 0; 2175 + 2176 + err_unregister_class: 2177 + class_unregister(&typec_class); 2178 + 2179 + err_unregister_retimer_class: 2180 + class_unregister(&retimer_class); 2317 2181 2318 2182 err_unregister_mux_class: 2319 2183 class_unregister(&typec_mux_class); ··· 2341 2177 2342 2178 static void __exit typec_exit(void) 2343 2179 { 2180 + usb_power_delivery_exit(); 2344 2181 class_unregister(&typec_class); 2345 2182 ida_destroy(&typec_index_ida); 2346 2183 bus_unregister(&typec_bus);
+6
drivers/usb/typec/class.h
··· 33 33 int num_altmodes; 34 34 u16 pd_revision; /* 0300H = "3.0" */ 35 35 enum usb_pd_svdm_ver svdm_version; 36 + 37 + struct usb_power_delivery *pd; 36 38 }; 37 39 38 40 struct typec_port { 39 41 unsigned int id; 40 42 struct device dev; 41 43 struct ida mode_ids; 44 + 45 + struct usb_power_delivery *pd; 42 46 43 47 int prefer_role; 44 48 enum typec_data_role data_role; ··· 55 51 enum typec_orientation orientation; 56 52 struct typec_switch *sw; 57 53 struct typec_mux *mux; 54 + struct typec_retimer *retimer; 58 55 59 56 const struct typec_capability *cap; 60 57 const struct typec_operations *ops; ··· 77 72 #define is_typec_port(dev) ((dev)->type == &typec_port_dev_type) 78 73 79 74 extern struct class typec_mux_class; 75 + extern struct class retimer_class; 80 76 extern struct class typec_class; 81 77 82 78 #if defined(CONFIG_ACPI)
+6 -2
drivers/usb/typec/mux.c
··· 281 281 if (match) 282 282 goto find_mux; 283 283 284 - /* Accessory Mode muxes */ 285 284 if (!desc) { 286 - match = fwnode_property_present(fwnode, "accessory"); 285 + /* 286 + * Accessory Mode muxes & muxes which explicitly specify 287 + * the required identifier can avoid SVID matching. 288 + */ 289 + match = fwnode_property_present(fwnode, "accessory") || 290 + fwnode_property_present(fwnode, id); 287 291 if (match) 288 292 goto find_mux; 289 293 return NULL;
+708
drivers/usb/typec/pd.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * USB Power Delivery sysfs entries 4 + * 5 + * Copyright (C) 2022, Intel Corporation 6 + * Author: Heikki Krogerus <heikki.krogerus@linux.intel.com> 7 + */ 8 + 9 + #include <linux/slab.h> 10 + #include <linux/usb/pd.h> 11 + 12 + #include "pd.h" 13 + 14 + static DEFINE_IDA(pd_ida); 15 + 16 + static struct class pd_class = { 17 + .name = "usb_power_delivery", 18 + .owner = THIS_MODULE, 19 + }; 20 + 21 + #define to_pdo(o) container_of(o, struct pdo, dev) 22 + 23 + struct pdo { 24 + struct device dev; 25 + int object_position; 26 + u32 pdo; 27 + }; 28 + 29 + static void pdo_release(struct device *dev) 30 + { 31 + kfree(to_pdo(dev)); 32 + } 33 + 34 + /* -------------------------------------------------------------------------- */ 35 + /* Fixed Supply */ 36 + 37 + static ssize_t 38 + dual_role_power_show(struct device *dev, struct device_attribute *attr, char *buf) 39 + { 40 + return sysfs_emit(buf, "%u\n", !!(to_pdo(dev)->pdo & PDO_FIXED_DUAL_ROLE)); 41 + } 42 + static DEVICE_ATTR_RO(dual_role_power); 43 + 44 + static ssize_t 45 + usb_suspend_supported_show(struct device *dev, struct device_attribute *attr, char *buf) 46 + { 47 + return sysfs_emit(buf, "%u\n", !!(to_pdo(dev)->pdo & PDO_FIXED_SUSPEND)); 48 + } 49 + static DEVICE_ATTR_RO(usb_suspend_supported); 50 + 51 + static ssize_t 52 + unconstrained_power_show(struct device *dev, struct device_attribute *attr, char *buf) 53 + { 54 + return sysfs_emit(buf, "%u\n", !!(to_pdo(dev)->pdo & PDO_FIXED_EXTPOWER)); 55 + } 56 + static DEVICE_ATTR_RO(unconstrained_power); 57 + 58 + static ssize_t 59 + usb_communication_capable_show(struct device *dev, struct device_attribute *attr, char *buf) 60 + { 61 + return sysfs_emit(buf, "%u\n", !!(to_pdo(dev)->pdo & PDO_FIXED_USB_COMM)); 62 + } 63 + static DEVICE_ATTR_RO(usb_communication_capable); 64 + 65 + static ssize_t 66 + dual_role_data_show(struct device *dev, struct device_attribute *attr, char *buf) 67 + { 68 + return sysfs_emit(buf, "%u\n", !!(to_pdo(dev)->pdo & PDO_FIXED_DATA_SWAP)); 69 + } 70 + static DEVICE_ATTR_RO(dual_role_data); 71 + 72 + static ssize_t 73 + unchunked_extended_messages_supported_show(struct device *dev, 74 + struct device_attribute *attr, char *buf) 75 + { 76 + return sysfs_emit(buf, "%u\n", !!(to_pdo(dev)->pdo & PDO_FIXED_UNCHUNK_EXT)); 77 + } 78 + static DEVICE_ATTR_RO(unchunked_extended_messages_supported); 79 + 80 + /* 81 + * REVISIT: Peak Current requires access also to the RDO. 82 + static ssize_t 83 + peak_current_show(struct device *dev, struct device_attribute *attr, char *buf) 84 + { 85 + ... 86 + } 87 + */ 88 + 89 + static ssize_t 90 + fast_role_swap_current_show(struct device *dev, struct device_attribute *attr, char *buf) 91 + { 92 + return sysfs_emit(buf, "%u\n", to_pdo(dev)->pdo >> PDO_FIXED_FRS_CURR_SHIFT) & 3; 93 + } 94 + static DEVICE_ATTR_RO(fast_role_swap_current); 95 + 96 + static ssize_t voltage_show(struct device *dev, struct device_attribute *attr, char *buf) 97 + { 98 + return sysfs_emit(buf, "%umV\n", pdo_fixed_voltage(to_pdo(dev)->pdo)); 99 + } 100 + static DEVICE_ATTR_RO(voltage); 101 + 102 + /* Shared with Variable supplies, both source and sink */ 103 + static ssize_t current_show(struct device *dev, struct device_attribute *attr, char *buf) 104 + { 105 + return sysfs_emit(buf, "%umA\n", pdo_max_current(to_pdo(dev)->pdo)); 106 + } 107 + 108 + /* Shared with Variable type supplies */ 109 + static struct device_attribute maximum_current_attr = { 110 + .attr = { 111 + .name = "maximum_current", 112 + .mode = 0444, 113 + }, 114 + .show = current_show, 115 + }; 116 + 117 + static struct device_attribute operational_current_attr = { 118 + .attr = { 119 + .name = "operational_current", 120 + .mode = 0444, 121 + }, 122 + .show = current_show, 123 + }; 124 + 125 + static struct attribute *source_fixed_supply_attrs[] = { 126 + &dev_attr_dual_role_power.attr, 127 + &dev_attr_usb_suspend_supported.attr, 128 + &dev_attr_unconstrained_power.attr, 129 + &dev_attr_usb_communication_capable.attr, 130 + &dev_attr_dual_role_data.attr, 131 + &dev_attr_unchunked_extended_messages_supported.attr, 132 + /*&dev_attr_peak_current.attr,*/ 133 + &dev_attr_voltage.attr, 134 + &maximum_current_attr.attr, 135 + NULL 136 + }; 137 + 138 + static umode_t fixed_attr_is_visible(struct kobject *kobj, struct attribute *attr, int n) 139 + { 140 + if (to_pdo(kobj_to_dev(kobj))->object_position && 141 + /*attr != &dev_attr_peak_current.attr &&*/ 142 + attr != &dev_attr_voltage.attr && 143 + attr != &maximum_current_attr.attr && 144 + attr != &operational_current_attr.attr) 145 + return 0; 146 + 147 + return attr->mode; 148 + } 149 + 150 + static const struct attribute_group source_fixed_supply_group = { 151 + .is_visible = fixed_attr_is_visible, 152 + .attrs = source_fixed_supply_attrs, 153 + }; 154 + __ATTRIBUTE_GROUPS(source_fixed_supply); 155 + 156 + static struct device_type source_fixed_supply_type = { 157 + .name = "pdo", 158 + .release = pdo_release, 159 + .groups = source_fixed_supply_groups, 160 + }; 161 + 162 + static struct attribute *sink_fixed_supply_attrs[] = { 163 + &dev_attr_dual_role_power.attr, 164 + &dev_attr_usb_suspend_supported.attr, 165 + &dev_attr_unconstrained_power.attr, 166 + &dev_attr_usb_communication_capable.attr, 167 + &dev_attr_dual_role_data.attr, 168 + &dev_attr_unchunked_extended_messages_supported.attr, 169 + &dev_attr_fast_role_swap_current.attr, 170 + &dev_attr_voltage.attr, 171 + &operational_current_attr.attr, 172 + NULL 173 + }; 174 + 175 + static const struct attribute_group sink_fixed_supply_group = { 176 + .is_visible = fixed_attr_is_visible, 177 + .attrs = sink_fixed_supply_attrs, 178 + }; 179 + __ATTRIBUTE_GROUPS(sink_fixed_supply); 180 + 181 + static struct device_type sink_fixed_supply_type = { 182 + .name = "pdo", 183 + .release = pdo_release, 184 + .groups = sink_fixed_supply_groups, 185 + }; 186 + 187 + /* -------------------------------------------------------------------------- */ 188 + /* Variable Supply */ 189 + 190 + static ssize_t 191 + maximum_voltage_show(struct device *dev, struct device_attribute *attr, char *buf) 192 + { 193 + return sysfs_emit(buf, "%umV\n", pdo_max_voltage(to_pdo(dev)->pdo)); 194 + } 195 + static DEVICE_ATTR_RO(maximum_voltage); 196 + 197 + static ssize_t 198 + minimum_voltage_show(struct device *dev, struct device_attribute *attr, char *buf) 199 + { 200 + return sysfs_emit(buf, "%umV\n", pdo_min_voltage(to_pdo(dev)->pdo)); 201 + } 202 + static DEVICE_ATTR_RO(minimum_voltage); 203 + 204 + static struct attribute *source_variable_supply_attrs[] = { 205 + &dev_attr_maximum_voltage.attr, 206 + &dev_attr_minimum_voltage.attr, 207 + &maximum_current_attr.attr, 208 + NULL 209 + }; 210 + ATTRIBUTE_GROUPS(source_variable_supply); 211 + 212 + static struct device_type source_variable_supply_type = { 213 + .name = "pdo", 214 + .release = pdo_release, 215 + .groups = source_variable_supply_groups, 216 + }; 217 + 218 + static struct attribute *sink_variable_supply_attrs[] = { 219 + &dev_attr_maximum_voltage.attr, 220 + &dev_attr_minimum_voltage.attr, 221 + &operational_current_attr.attr, 222 + NULL 223 + }; 224 + ATTRIBUTE_GROUPS(sink_variable_supply); 225 + 226 + static struct device_type sink_variable_supply_type = { 227 + .name = "pdo", 228 + .release = pdo_release, 229 + .groups = sink_variable_supply_groups, 230 + }; 231 + 232 + /* -------------------------------------------------------------------------- */ 233 + /* Battery */ 234 + 235 + static ssize_t 236 + maximum_power_show(struct device *dev, struct device_attribute *attr, char *buf) 237 + { 238 + return sysfs_emit(buf, "%umW\n", pdo_max_power(to_pdo(dev)->pdo)); 239 + } 240 + static DEVICE_ATTR_RO(maximum_power); 241 + 242 + static ssize_t 243 + operational_power_show(struct device *dev, struct device_attribute *attr, char *buf) 244 + { 245 + return sysfs_emit(buf, "%umW\n", pdo_max_power(to_pdo(dev)->pdo)); 246 + } 247 + static DEVICE_ATTR_RO(operational_power); 248 + 249 + static struct attribute *source_battery_attrs[] = { 250 + &dev_attr_maximum_voltage.attr, 251 + &dev_attr_minimum_voltage.attr, 252 + &dev_attr_maximum_power.attr, 253 + NULL 254 + }; 255 + ATTRIBUTE_GROUPS(source_battery); 256 + 257 + static struct device_type source_battery_type = { 258 + .name = "pdo", 259 + .release = pdo_release, 260 + .groups = source_battery_groups, 261 + }; 262 + 263 + static struct attribute *sink_battery_attrs[] = { 264 + &dev_attr_maximum_voltage.attr, 265 + &dev_attr_minimum_voltage.attr, 266 + &dev_attr_operational_power.attr, 267 + NULL 268 + }; 269 + ATTRIBUTE_GROUPS(sink_battery); 270 + 271 + static struct device_type sink_battery_type = { 272 + .name = "pdo", 273 + .release = pdo_release, 274 + .groups = sink_battery_groups, 275 + }; 276 + 277 + /* -------------------------------------------------------------------------- */ 278 + /* Standard Power Range (SPR) Programmable Power Supply (PPS) */ 279 + 280 + static ssize_t 281 + pps_power_limited_show(struct device *dev, struct device_attribute *attr, char *buf) 282 + { 283 + return sysfs_emit(buf, "%u\n", !!(to_pdo(dev)->pdo & BIT(27))); 284 + } 285 + static DEVICE_ATTR_RO(pps_power_limited); 286 + 287 + static ssize_t 288 + pps_max_voltage_show(struct device *dev, struct device_attribute *attr, char *buf) 289 + { 290 + return sysfs_emit(buf, "%umV\n", pdo_pps_apdo_max_voltage(to_pdo(dev)->pdo)); 291 + } 292 + 293 + static ssize_t 294 + pps_min_voltage_show(struct device *dev, struct device_attribute *attr, char *buf) 295 + { 296 + return sysfs_emit(buf, "%umV\n", pdo_pps_apdo_min_voltage(to_pdo(dev)->pdo)); 297 + } 298 + 299 + static ssize_t 300 + pps_max_current_show(struct device *dev, struct device_attribute *attr, char *buf) 301 + { 302 + return sysfs_emit(buf, "%umA\n", pdo_pps_apdo_max_current(to_pdo(dev)->pdo)); 303 + } 304 + 305 + static struct device_attribute pps_max_voltage_attr = { 306 + .attr = { 307 + .name = "maximum_voltage", 308 + .mode = 0444, 309 + }, 310 + .show = pps_max_voltage_show, 311 + }; 312 + 313 + static struct device_attribute pps_min_voltage_attr = { 314 + .attr = { 315 + .name = "minimum_voltage", 316 + .mode = 0444, 317 + }, 318 + .show = pps_min_voltage_show, 319 + }; 320 + 321 + static struct device_attribute pps_max_current_attr = { 322 + .attr = { 323 + .name = "maximum_current", 324 + .mode = 0444, 325 + }, 326 + .show = pps_max_current_show, 327 + }; 328 + 329 + static struct attribute *source_pps_attrs[] = { 330 + &dev_attr_pps_power_limited.attr, 331 + &pps_max_voltage_attr.attr, 332 + &pps_min_voltage_attr.attr, 333 + &pps_max_current_attr.attr, 334 + NULL 335 + }; 336 + ATTRIBUTE_GROUPS(source_pps); 337 + 338 + static struct device_type source_pps_type = { 339 + .name = "pdo", 340 + .release = pdo_release, 341 + .groups = source_pps_groups, 342 + }; 343 + 344 + static struct attribute *sink_pps_attrs[] = { 345 + &pps_max_voltage_attr.attr, 346 + &pps_min_voltage_attr.attr, 347 + &pps_max_current_attr.attr, 348 + NULL 349 + }; 350 + ATTRIBUTE_GROUPS(sink_pps); 351 + 352 + static struct device_type sink_pps_type = { 353 + .name = "pdo", 354 + .release = pdo_release, 355 + .groups = sink_pps_groups, 356 + }; 357 + 358 + /* -------------------------------------------------------------------------- */ 359 + 360 + static const char * const supply_name[] = { 361 + [PDO_TYPE_FIXED] = "fixed_supply", 362 + [PDO_TYPE_BATT] = "battery", 363 + [PDO_TYPE_VAR] = "variable_supply", 364 + }; 365 + 366 + static const char * const apdo_supply_name[] = { 367 + [APDO_TYPE_PPS] = "programmable_supply", 368 + }; 369 + 370 + static struct device_type *source_type[] = { 371 + [PDO_TYPE_FIXED] = &source_fixed_supply_type, 372 + [PDO_TYPE_BATT] = &source_battery_type, 373 + [PDO_TYPE_VAR] = &source_variable_supply_type, 374 + }; 375 + 376 + static struct device_type *source_apdo_type[] = { 377 + [APDO_TYPE_PPS] = &source_pps_type, 378 + }; 379 + 380 + static struct device_type *sink_type[] = { 381 + [PDO_TYPE_FIXED] = &sink_fixed_supply_type, 382 + [PDO_TYPE_BATT] = &sink_battery_type, 383 + [PDO_TYPE_VAR] = &sink_variable_supply_type, 384 + }; 385 + 386 + static struct device_type *sink_apdo_type[] = { 387 + [APDO_TYPE_PPS] = &sink_pps_type, 388 + }; 389 + 390 + /* REVISIT: Export when EPR_*_Capabilities need to be supported. */ 391 + static int add_pdo(struct usb_power_delivery_capabilities *cap, u32 pdo, int position) 392 + { 393 + struct device_type *type; 394 + const char *name; 395 + struct pdo *p; 396 + int ret; 397 + 398 + p = kzalloc(sizeof(*p), GFP_KERNEL); 399 + if (!p) 400 + return -ENOMEM; 401 + 402 + p->pdo = pdo; 403 + p->object_position = position; 404 + 405 + if (pdo_type(pdo) == PDO_TYPE_APDO) { 406 + /* FIXME: Only PPS supported for now! Skipping others. */ 407 + if (pdo_apdo_type(pdo) > APDO_TYPE_PPS) { 408 + dev_warn(&cap->dev, "Unknown APDO type. PDO 0x%08x\n", pdo); 409 + kfree(p); 410 + return 0; 411 + } 412 + 413 + if (is_source(cap->role)) 414 + type = source_apdo_type[pdo_apdo_type(pdo)]; 415 + else 416 + type = sink_apdo_type[pdo_apdo_type(pdo)]; 417 + 418 + name = apdo_supply_name[pdo_apdo_type(pdo)]; 419 + } else { 420 + if (is_source(cap->role)) 421 + type = source_type[pdo_type(pdo)]; 422 + else 423 + type = sink_type[pdo_type(pdo)]; 424 + 425 + name = supply_name[pdo_type(pdo)]; 426 + } 427 + 428 + p->dev.parent = &cap->dev; 429 + p->dev.type = type; 430 + dev_set_name(&p->dev, "%u:%s", position + 1, name); 431 + 432 + ret = device_register(&p->dev); 433 + if (ret) { 434 + put_device(&p->dev); 435 + return ret; 436 + } 437 + 438 + return 0; 439 + } 440 + 441 + static int remove_pdo(struct device *dev, void *data) 442 + { 443 + device_unregister(dev); 444 + return 0; 445 + } 446 + 447 + /* -------------------------------------------------------------------------- */ 448 + 449 + static const char * const cap_name[] = { 450 + [TYPEC_SINK] = "sink-capabilities", 451 + [TYPEC_SOURCE] = "source-capabilities", 452 + }; 453 + 454 + static void pd_capabilities_release(struct device *dev) 455 + { 456 + kfree(to_usb_power_delivery_capabilities(dev)); 457 + } 458 + 459 + static struct device_type pd_capabilities_type = { 460 + .name = "capabilities", 461 + .release = pd_capabilities_release, 462 + }; 463 + 464 + /** 465 + * usb_power_delivery_register_capabilities - Register a set of capabilities. 466 + * @pd: The USB PD instance that the capabilities belong to. 467 + * @desc: Description of the Capablities Message. 468 + * 469 + * This function registers a Capabilities Message described in @desc. The 470 + * capabilities will have their own sub-directory under @pd in sysfs. 471 + * 472 + * The function returns pointer to struct usb_power_delivery_capabilities, or 473 + * ERR_PRT(errno). 474 + */ 475 + struct usb_power_delivery_capabilities * 476 + usb_power_delivery_register_capabilities(struct usb_power_delivery *pd, 477 + struct usb_power_delivery_capabilities_desc *desc) 478 + { 479 + struct usb_power_delivery_capabilities *cap; 480 + int ret; 481 + int i; 482 + 483 + cap = kzalloc(sizeof(*cap), GFP_KERNEL); 484 + if (!cap) 485 + return ERR_PTR(-ENOMEM); 486 + 487 + cap->pd = pd; 488 + cap->role = desc->role; 489 + 490 + cap->dev.parent = &pd->dev; 491 + cap->dev.type = &pd_capabilities_type; 492 + dev_set_name(&cap->dev, "%s", cap_name[cap->role]); 493 + 494 + ret = device_register(&cap->dev); 495 + if (ret) { 496 + put_device(&cap->dev); 497 + return ERR_PTR(ret); 498 + } 499 + 500 + for (i = 0; i < PDO_MAX_OBJECTS && desc->pdo[i]; i++) { 501 + ret = add_pdo(cap, desc->pdo[i], i); 502 + if (ret) { 503 + usb_power_delivery_unregister_capabilities(cap); 504 + return ERR_PTR(ret); 505 + } 506 + } 507 + 508 + return cap; 509 + } 510 + EXPORT_SYMBOL_GPL(usb_power_delivery_register_capabilities); 511 + 512 + /** 513 + * usb_power_delivery_unregister_capabilities - Unregister a set of capabilities 514 + * @cap: The capabilities 515 + */ 516 + void usb_power_delivery_unregister_capabilities(struct usb_power_delivery_capabilities *cap) 517 + { 518 + if (!cap) 519 + return; 520 + 521 + device_for_each_child(&cap->dev, NULL, remove_pdo); 522 + device_unregister(&cap->dev); 523 + } 524 + EXPORT_SYMBOL_GPL(usb_power_delivery_unregister_capabilities); 525 + 526 + /* -------------------------------------------------------------------------- */ 527 + 528 + static ssize_t revision_show(struct device *dev, struct device_attribute *attr, char *buf) 529 + { 530 + struct usb_power_delivery *pd = to_usb_power_delivery(dev); 531 + 532 + return sysfs_emit(buf, "%u.%u\n", (pd->revision >> 8) & 0xff, (pd->revision >> 4) & 0xf); 533 + } 534 + static DEVICE_ATTR_RO(revision); 535 + 536 + static ssize_t version_show(struct device *dev, struct device_attribute *attr, char *buf) 537 + { 538 + struct usb_power_delivery *pd = to_usb_power_delivery(dev); 539 + 540 + return sysfs_emit(buf, "%u.%u\n", (pd->version >> 8) & 0xff, (pd->version >> 4) & 0xf); 541 + } 542 + static DEVICE_ATTR_RO(version); 543 + 544 + static struct attribute *pd_attrs[] = { 545 + &dev_attr_revision.attr, 546 + &dev_attr_version.attr, 547 + NULL 548 + }; 549 + 550 + static umode_t pd_attr_is_visible(struct kobject *kobj, struct attribute *attr, int n) 551 + { 552 + struct usb_power_delivery *pd = to_usb_power_delivery(kobj_to_dev(kobj)); 553 + 554 + if (attr == &dev_attr_version.attr && !pd->version) 555 + return 0; 556 + 557 + return attr->mode; 558 + } 559 + 560 + static const struct attribute_group pd_group = { 561 + .is_visible = pd_attr_is_visible, 562 + .attrs = pd_attrs, 563 + }; 564 + __ATTRIBUTE_GROUPS(pd); 565 + 566 + static void pd_release(struct device *dev) 567 + { 568 + struct usb_power_delivery *pd = to_usb_power_delivery(dev); 569 + 570 + ida_simple_remove(&pd_ida, pd->id); 571 + kfree(pd); 572 + } 573 + 574 + static struct device_type pd_type = { 575 + .name = "usb_power_delivery", 576 + .release = pd_release, 577 + .groups = pd_groups, 578 + }; 579 + 580 + struct usb_power_delivery *usb_power_delivery_find(const char *name) 581 + { 582 + struct device *dev; 583 + 584 + dev = class_find_device_by_name(&pd_class, name); 585 + 586 + return dev ? to_usb_power_delivery(dev) : NULL; 587 + } 588 + 589 + /** 590 + * usb_power_delivery_register - Register USB Power Delivery Support. 591 + * @parent: Parent device. 592 + * @desc: Description of the USB PD contract. 593 + * 594 + * This routine can be used to register USB Power Delivery capabilities that a 595 + * device or devices can support. These capabilities represent all the 596 + * capabilities that can be negotiated with a partner, so not only the Power 597 + * Capabilities that are negotiated using the USB PD Capabilities Message. 598 + * 599 + * The USB Power Delivery Support object that this routine generates can be used 600 + * as the parent object for all the actual USB Power Delivery Messages and 601 + * objects that can be negotiated with the partner. 602 + * 603 + * Returns handle to struct usb_power_delivery or ERR_PTR. 604 + */ 605 + struct usb_power_delivery * 606 + usb_power_delivery_register(struct device *parent, struct usb_power_delivery_desc *desc) 607 + { 608 + struct usb_power_delivery *pd; 609 + int ret; 610 + 611 + pd = kzalloc(sizeof(*pd), GFP_KERNEL); 612 + if (!pd) 613 + return ERR_PTR(-ENOMEM); 614 + 615 + ret = ida_simple_get(&pd_ida, 0, 0, GFP_KERNEL); 616 + if (ret < 0) { 617 + kfree(pd); 618 + return ERR_PTR(ret); 619 + } 620 + 621 + pd->id = ret; 622 + pd->revision = desc->revision; 623 + pd->version = desc->version; 624 + 625 + pd->dev.parent = parent; 626 + pd->dev.type = &pd_type; 627 + pd->dev.class = &pd_class; 628 + dev_set_name(&pd->dev, "pd%d", pd->id); 629 + 630 + ret = device_register(&pd->dev); 631 + if (ret) { 632 + put_device(&pd->dev); 633 + return ERR_PTR(ret); 634 + } 635 + 636 + return pd; 637 + } 638 + EXPORT_SYMBOL_GPL(usb_power_delivery_register); 639 + 640 + /** 641 + * usb_power_delivery_unregister - Unregister USB Power Delivery Support. 642 + * @pd: The USB PD contract. 643 + */ 644 + void usb_power_delivery_unregister(struct usb_power_delivery *pd) 645 + { 646 + if (IS_ERR_OR_NULL(pd)) 647 + return; 648 + 649 + device_unregister(&pd->dev); 650 + } 651 + EXPORT_SYMBOL_GPL(usb_power_delivery_unregister); 652 + 653 + /** 654 + * usb_power_delivery_link_device - Link device to its USB PD object. 655 + * @pd: The USB PD instance. 656 + * @dev: The device. 657 + * 658 + * This function can be used to create a symlink named "usb_power_delivery" for 659 + * @dev that points to @pd. 660 + */ 661 + int usb_power_delivery_link_device(struct usb_power_delivery *pd, struct device *dev) 662 + { 663 + int ret; 664 + 665 + if (IS_ERR_OR_NULL(pd) || !dev) 666 + return 0; 667 + 668 + ret = sysfs_create_link(&dev->kobj, &pd->dev.kobj, "usb_power_delivery"); 669 + if (ret) 670 + return ret; 671 + 672 + get_device(&pd->dev); 673 + get_device(dev); 674 + 675 + return 0; 676 + } 677 + EXPORT_SYMBOL_GPL(usb_power_delivery_link_device); 678 + 679 + /** 680 + * usb_power_delivery_unlink_device - Unlink device from its USB PD object. 681 + * @pd: The USB PD instance. 682 + * @dev: The device. 683 + * 684 + * Remove the symlink that was previously created with pd_link_device(). 685 + */ 686 + void usb_power_delivery_unlink_device(struct usb_power_delivery *pd, struct device *dev) 687 + { 688 + if (IS_ERR_OR_NULL(pd) || !dev) 689 + return; 690 + 691 + sysfs_remove_link(&dev->kobj, "usb_power_delivery"); 692 + put_device(&pd->dev); 693 + put_device(dev); 694 + } 695 + EXPORT_SYMBOL_GPL(usb_power_delivery_unlink_device); 696 + 697 + /* -------------------------------------------------------------------------- */ 698 + 699 + int __init usb_power_delivery_init(void) 700 + { 701 + return class_register(&pd_class); 702 + } 703 + 704 + void __exit usb_power_delivery_exit(void) 705 + { 706 + ida_destroy(&pd_ida); 707 + class_unregister(&pd_class); 708 + }
+30
drivers/usb/typec/pd.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + 3 + #ifndef __USB_POWER_DELIVERY__ 4 + #define __USB_POWER_DELIVERY__ 5 + 6 + #include <linux/device.h> 7 + #include <linux/usb/typec.h> 8 + 9 + struct usb_power_delivery { 10 + struct device dev; 11 + int id; 12 + u16 revision; 13 + u16 version; 14 + }; 15 + 16 + struct usb_power_delivery_capabilities { 17 + struct device dev; 18 + struct usb_power_delivery *pd; 19 + enum typec_role role; 20 + }; 21 + 22 + #define to_usb_power_delivery_capabilities(o) container_of(o, struct usb_power_delivery_capabilities, dev) 23 + #define to_usb_power_delivery(o) container_of(o, struct usb_power_delivery, dev) 24 + 25 + struct usb_power_delivery *usb_power_delivery_find(const char *name); 26 + 27 + int usb_power_delivery_init(void); 28 + void usb_power_delivery_exit(void); 29 + 30 + #endif /* __USB_POWER_DELIVERY__ */
+173
drivers/usb/typec/retimer.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * Copyright 2022 Google LLC 4 + * 5 + * USB Type-C Retimer support. 6 + * Author: Prashant Malani <pmalani@chromium.org> 7 + * 8 + */ 9 + 10 + #include <linux/device.h> 11 + #include <linux/list.h> 12 + #include <linux/module.h> 13 + #include <linux/mutex.h> 14 + #include <linux/property.h> 15 + #include <linux/slab.h> 16 + 17 + #include "class.h" 18 + #include "retimer.h" 19 + 20 + static bool dev_name_ends_with(struct device *dev, const char *suffix) 21 + { 22 + const char *name = dev_name(dev); 23 + const int name_len = strlen(name); 24 + const int suffix_len = strlen(suffix); 25 + 26 + if (suffix_len > name_len) 27 + return false; 28 + 29 + return strcmp(name + (name_len - suffix_len), suffix) == 0; 30 + } 31 + 32 + static int retimer_fwnode_match(struct device *dev, const void *fwnode) 33 + { 34 + return dev_fwnode(dev) == fwnode && dev_name_ends_with(dev, "-retimer"); 35 + } 36 + 37 + static void *typec_retimer_match(struct fwnode_handle *fwnode, const char *id, void *data) 38 + { 39 + struct device *dev; 40 + 41 + if (id && !fwnode_property_present(fwnode, id)) 42 + return NULL; 43 + 44 + dev = class_find_device(&retimer_class, NULL, fwnode, 45 + retimer_fwnode_match); 46 + 47 + return dev ? to_typec_retimer(dev) : ERR_PTR(-EPROBE_DEFER); 48 + } 49 + 50 + /** 51 + * fwnode_typec_retimer_get - Find USB Type-C retimer. 52 + * @fwnode: The caller device node. 53 + * 54 + * Finds a retimer linked to the caller. This function is primarily meant for the 55 + * Type-C drivers. Returns a reference to the retimer on success, NULL if no 56 + * matching connection was found, or ERR_PTR(-EPROBE_DEFER) when a connection 57 + * was found but the retimer has not been enumerated yet. 58 + */ 59 + struct typec_retimer *fwnode_typec_retimer_get(struct fwnode_handle *fwnode) 60 + { 61 + struct typec_retimer *retimer; 62 + 63 + retimer = fwnode_connection_find_match(fwnode, "retimer-switch", NULL, typec_retimer_match); 64 + if (!IS_ERR_OR_NULL(retimer)) 65 + WARN_ON(!try_module_get(retimer->dev.parent->driver->owner)); 66 + 67 + return retimer; 68 + } 69 + EXPORT_SYMBOL_GPL(fwnode_typec_retimer_get); 70 + 71 + /** 72 + * typec_retimer_put - Release handle to a retimer. 73 + * @retimer: USB Type-C Connector Retimer. 74 + * 75 + * Decrements reference count for @retimer. 76 + */ 77 + void typec_retimer_put(struct typec_retimer *retimer) 78 + { 79 + if (!IS_ERR_OR_NULL(retimer)) { 80 + module_put(retimer->dev.parent->driver->owner); 81 + put_device(&retimer->dev); 82 + } 83 + } 84 + EXPORT_SYMBOL_GPL(typec_retimer_put); 85 + 86 + int typec_retimer_set(struct typec_retimer *retimer, struct typec_retimer_state *state) 87 + { 88 + if (IS_ERR_OR_NULL(retimer)) 89 + return 0; 90 + 91 + return retimer->set(retimer, state); 92 + } 93 + EXPORT_SYMBOL_GPL(typec_retimer_set); 94 + 95 + static void typec_retimer_release(struct device *dev) 96 + { 97 + kfree(to_typec_retimer(dev)); 98 + } 99 + 100 + static const struct device_type typec_retimer_dev_type = { 101 + .name = "typec_retimer", 102 + .release = typec_retimer_release, 103 + }; 104 + 105 + /** 106 + * typec_retimer_register - Register a retimer device. 107 + * @parent: Parent device. 108 + * @desc: Retimer description. 109 + * 110 + * Some USB Type-C connectors have their physical lines routed through retimers before they 111 + * reach muxes or host controllers. In some cases (for example: using alternate modes) 112 + * these retimers need to be reconfigured appropriately. This function registers retimer 113 + * switches which route and potentially modify the signals on the Type C physical lines 114 + * enroute to the host controllers. 115 + */ 116 + struct typec_retimer * 117 + typec_retimer_register(struct device *parent, const struct typec_retimer_desc *desc) 118 + { 119 + struct typec_retimer *retimer; 120 + int ret; 121 + 122 + if (!desc || !desc->set) 123 + return ERR_PTR(-EINVAL); 124 + 125 + retimer = kzalloc(sizeof(*retimer), GFP_KERNEL); 126 + if (!retimer) 127 + return ERR_PTR(-ENOMEM); 128 + 129 + retimer->set = desc->set; 130 + 131 + device_initialize(&retimer->dev); 132 + retimer->dev.parent = parent; 133 + retimer->dev.fwnode = desc->fwnode; 134 + retimer->dev.class = &retimer_class; 135 + retimer->dev.type = &typec_retimer_dev_type; 136 + retimer->dev.driver_data = desc->drvdata; 137 + dev_set_name(&retimer->dev, "%s-retimer", 138 + desc->name ? desc->name : dev_name(parent)); 139 + 140 + ret = device_add(&retimer->dev); 141 + if (ret) { 142 + dev_err(parent, "failed to register retimer (%d)\n", ret); 143 + put_device(&retimer->dev); 144 + return ERR_PTR(ret); 145 + } 146 + 147 + return retimer; 148 + } 149 + EXPORT_SYMBOL_GPL(typec_retimer_register); 150 + 151 + /** 152 + * typec_retimer_unregister - Unregister retimer device. 153 + * @retimer: USB Type-C Connector retimer. 154 + * 155 + * Unregister retimer that was registered with typec_retimer_register(). 156 + */ 157 + void typec_retimer_unregister(struct typec_retimer *retimer) 158 + { 159 + if (!IS_ERR_OR_NULL(retimer)) 160 + device_unregister(&retimer->dev); 161 + } 162 + EXPORT_SYMBOL_GPL(typec_retimer_unregister); 163 + 164 + void *typec_retimer_get_drvdata(struct typec_retimer *retimer) 165 + { 166 + return dev_get_drvdata(&retimer->dev); 167 + } 168 + EXPORT_SYMBOL_GPL(typec_retimer_get_drvdata); 169 + 170 + struct class retimer_class = { 171 + .name = "retimer", 172 + .owner = THIS_MODULE, 173 + };
+15
drivers/usb/typec/retimer.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + 3 + #ifndef __USB_TYPEC_RETIMER__ 4 + #define __USB_TYPEC_RETIMER__ 5 + 6 + #include <linux/usb/typec_retimer.h> 7 + 8 + struct typec_retimer { 9 + struct device dev; 10 + typec_retimer_set_fn_t set; 11 + }; 12 + 13 + #define to_typec_retimer(_dev_) container_of(_dev_, struct typec_retimer, dev) 14 + 15 + #endif /* __USB_TYPEC_RETIMER__ */
+1 -2
drivers/usb/typec/tcpm/tcpci.c
··· 13 13 #include <linux/property.h> 14 14 #include <linux/regmap.h> 15 15 #include <linux/usb/pd.h> 16 + #include <linux/usb/tcpci.h> 16 17 #include <linux/usb/tcpm.h> 17 18 #include <linux/usb/typec.h> 18 - 19 - #include "tcpci.h" 20 19 21 20 #define PD_RETRY_COUNT_DEFAULT 3 22 21 #define PD_RETRY_COUNT_3_0_OR_HIGHER 2
+1
drivers/usb/typec/tcpm/tcpci.h include/linux/usb/tcpci.h
··· 9 9 #define __LINUX_USB_TCPCI_H 10 10 11 11 #include <linux/usb/typec.h> 12 + #include <linux/usb/tcpm.h> 12 13 13 14 #define TCPC_VENDOR_ID 0x0 14 15 #define TCPC_PRODUCT_ID 0x2
+1 -2
drivers/usb/typec/tcpm/tcpci_maxim.c
··· 11 11 #include <linux/module.h> 12 12 #include <linux/regmap.h> 13 13 #include <linux/usb/pd.h> 14 + #include <linux/usb/tcpci.h> 14 15 #include <linux/usb/tcpm.h> 15 16 #include <linux/usb/typec.h> 16 - 17 - #include "tcpci.h" 18 17 19 18 #define PD_ACTIVITY_TIMEOUT_MS 10000 20 19
+1 -2
drivers/usb/typec/tcpm/tcpci_mt6360.c
··· 11 11 #include <linux/of.h> 12 12 #include <linux/platform_device.h> 13 13 #include <linux/regmap.h> 14 + #include <linux/usb/tcpci.h> 14 15 #include <linux/usb/tcpm.h> 15 - 16 - #include "tcpci.h" 17 16 18 17 #define MT6360_REG_PHYCTRL1 0x80 19 18 #define MT6360_REG_PHYCTRL3 0x82
+1 -1
drivers/usb/typec/tcpm/tcpci_rt1711h.c
··· 10 10 #include <linux/i2c.h> 11 11 #include <linux/interrupt.h> 12 12 #include <linux/gpio/consumer.h> 13 + #include <linux/usb/tcpci.h> 13 14 #include <linux/usb/tcpm.h> 14 15 #include <linux/regmap.h> 15 - #include "tcpci.h" 16 16 17 17 #define RT1711H_VID 0x29CF 18 18 #define RT1711H_PID 0x1711
+143 -3
drivers/usb/typec/tcpm/tcpm.c
··· 394 394 bool explicit_contract; 395 395 unsigned int rx_msgid; 396 396 397 + /* USB PD objects */ 398 + struct usb_power_delivery *pd; 399 + struct usb_power_delivery_capabilities *port_source_caps; 400 + struct usb_power_delivery_capabilities *port_sink_caps; 401 + struct usb_power_delivery *partner_pd; 402 + struct usb_power_delivery_capabilities *partner_source_caps; 403 + struct usb_power_delivery_capabilities *partner_sink_caps; 404 + 397 405 /* Partner capabilities/requests */ 398 406 u32 sink_request; 399 407 u32 source_caps[PDO_MAX_OBJECTS]; ··· 479 471 480 472 /* 481 473 * When set, port requests PD_P_SNK_STDBY_MW upon entering SNK_DISCOVERY and 482 - * the actual currrent limit after RX of PD_CTRL_PSRDY for PD link, 474 + * the actual current limit after RX of PD_CTRL_PSRDY for PD link, 483 475 * SNK_READY for non-pd link. 484 476 */ 485 477 bool slow_charger_loop; ··· 2360 2352 } 2361 2353 } 2362 2354 2355 + static int tcpm_register_source_caps(struct tcpm_port *port) 2356 + { 2357 + struct usb_power_delivery_desc desc = { port->negotiated_rev }; 2358 + struct usb_power_delivery_capabilities_desc caps = { }; 2359 + struct usb_power_delivery_capabilities *cap; 2360 + 2361 + if (!port->partner_pd) 2362 + port->partner_pd = usb_power_delivery_register(NULL, &desc); 2363 + if (IS_ERR(port->partner_pd)) 2364 + return PTR_ERR(port->partner_pd); 2365 + 2366 + memcpy(caps.pdo, port->source_caps, sizeof(u32) * port->nr_source_caps); 2367 + caps.role = TYPEC_SOURCE; 2368 + 2369 + cap = usb_power_delivery_register_capabilities(port->partner_pd, &caps); 2370 + if (IS_ERR(cap)) 2371 + return PTR_ERR(cap); 2372 + 2373 + port->partner_source_caps = cap; 2374 + 2375 + return 0; 2376 + } 2377 + 2378 + static int tcpm_register_sink_caps(struct tcpm_port *port) 2379 + { 2380 + struct usb_power_delivery_desc desc = { port->negotiated_rev }; 2381 + struct usb_power_delivery_capabilities_desc caps = { }; 2382 + struct usb_power_delivery_capabilities *cap; 2383 + 2384 + if (!port->partner_pd) 2385 + port->partner_pd = usb_power_delivery_register(NULL, &desc); 2386 + if (IS_ERR(port->partner_pd)) 2387 + return PTR_ERR(port->partner_pd); 2388 + 2389 + memcpy(caps.pdo, port->sink_caps, sizeof(u32) * port->nr_sink_caps); 2390 + caps.role = TYPEC_SINK; 2391 + 2392 + cap = usb_power_delivery_register_capabilities(port->partner_pd, &caps); 2393 + if (IS_ERR(cap)) 2394 + return PTR_ERR(cap); 2395 + 2396 + port->partner_sink_caps = cap; 2397 + 2398 + return 0; 2399 + } 2400 + 2363 2401 static void tcpm_pd_data_request(struct tcpm_port *port, 2364 2402 const struct pd_message *msg) 2365 2403 { ··· 2434 2380 2435 2381 tcpm_validate_caps(port, port->source_caps, 2436 2382 port->nr_source_caps); 2383 + 2384 + tcpm_register_source_caps(port); 2437 2385 2438 2386 /* 2439 2387 * Adjust revision in subsequent message headers, as required, ··· 2544 2488 2545 2489 port->nr_sink_caps = cnt; 2546 2490 port->sink_cap_done = true; 2491 + tcpm_register_sink_caps(port); 2492 + 2547 2493 if (port->ams == GET_SINK_CAPABILITIES) 2548 2494 tcpm_set_state(port, ready_state(port), 0); 2549 2495 /* Unexpected Sink Capabilities */ ··· 3612 3554 port->partner = typec_register_partner(port->typec_port, 3613 3555 &port->partner_desc); 3614 3556 port->connected = true; 3557 + typec_partner_set_usb_power_delivery(port->partner, port->partner_pd); 3615 3558 } 3616 3559 } 3617 3560 ··· 3681 3622 static void tcpm_typec_disconnect(struct tcpm_port *port) 3682 3623 { 3683 3624 if (port->connected) { 3625 + typec_partner_set_usb_power_delivery(port->partner, NULL); 3684 3626 typec_unregister_partner(port->partner); 3685 3627 port->partner = NULL; 3686 3628 port->connected = false; ··· 3744 3684 port->sink_cap_done = false; 3745 3685 if (port->tcpc->enable_frs) 3746 3686 port->tcpc->enable_frs(port->tcpc, false); 3687 + 3688 + usb_power_delivery_unregister_capabilities(port->partner_sink_caps); 3689 + port->partner_sink_caps = NULL; 3690 + usb_power_delivery_unregister_capabilities(port->partner_source_caps); 3691 + port->partner_source_caps = NULL; 3692 + usb_power_delivery_unregister(port->partner_pd); 3693 + port->partner_pd = NULL; 3747 3694 } 3748 3695 3749 3696 static void tcpm_detach(struct tcpm_port *port) ··· 4520 4453 * The specification suggests that dual mode ports in sink 4521 4454 * mode should transition to state PE_SRC_Transition_to_default. 4522 4455 * See USB power delivery specification chapter 8.3.3.6.1.3. 4523 - * This would mean to to 4456 + * This would mean to 4524 4457 * - turn off VCONN, reset power supply 4525 4458 * - request hardware reset 4526 4459 * - turn on VCONN ··· 5991 5924 } 5992 5925 EXPORT_SYMBOL_GPL(tcpm_tcpc_reset); 5993 5926 5927 + static void tcpm_port_unregister_pd(struct tcpm_port *port) 5928 + { 5929 + usb_power_delivery_unregister_capabilities(port->port_sink_caps); 5930 + port->port_sink_caps = NULL; 5931 + usb_power_delivery_unregister_capabilities(port->port_source_caps); 5932 + port->port_source_caps = NULL; 5933 + usb_power_delivery_unregister(port->pd); 5934 + port->pd = NULL; 5935 + } 5936 + 5937 + static int tcpm_port_register_pd(struct tcpm_port *port) 5938 + { 5939 + struct usb_power_delivery_desc desc = { port->typec_caps.pd_revision }; 5940 + struct usb_power_delivery_capabilities_desc caps = { }; 5941 + struct usb_power_delivery_capabilities *cap; 5942 + int ret; 5943 + 5944 + if (!port->nr_src_pdo && !port->nr_snk_pdo) 5945 + return 0; 5946 + 5947 + port->pd = usb_power_delivery_register(port->dev, &desc); 5948 + if (IS_ERR(port->pd)) { 5949 + ret = PTR_ERR(port->pd); 5950 + goto err_unregister; 5951 + } 5952 + 5953 + if (port->nr_src_pdo) { 5954 + memcpy_and_pad(caps.pdo, sizeof(caps.pdo), port->src_pdo, 5955 + port->nr_src_pdo * sizeof(u32), 0); 5956 + caps.role = TYPEC_SOURCE; 5957 + 5958 + cap = usb_power_delivery_register_capabilities(port->pd, &caps); 5959 + if (IS_ERR(cap)) { 5960 + ret = PTR_ERR(cap); 5961 + goto err_unregister; 5962 + } 5963 + 5964 + port->port_source_caps = cap; 5965 + } 5966 + 5967 + if (port->nr_snk_pdo) { 5968 + memcpy_and_pad(caps.pdo, sizeof(caps.pdo), port->snk_pdo, 5969 + port->nr_snk_pdo * sizeof(u32), 0); 5970 + caps.role = TYPEC_SINK; 5971 + 5972 + cap = usb_power_delivery_register_capabilities(port->pd, &caps); 5973 + if (IS_ERR(cap)) { 5974 + ret = PTR_ERR(cap); 5975 + goto err_unregister; 5976 + } 5977 + 5978 + port->port_sink_caps = cap; 5979 + } 5980 + 5981 + return 0; 5982 + 5983 + err_unregister: 5984 + tcpm_port_unregister_pd(port); 5985 + 5986 + return ret; 5987 + } 5988 + 5994 5989 static int tcpm_fw_get_caps(struct tcpm_port *port, 5995 5990 struct fwnode_handle *fwnode) 5996 5991 { ··· 6511 6382 goto out_role_sw_put; 6512 6383 power_supply_changed(port->psy); 6513 6384 6385 + err = tcpm_port_register_pd(port); 6386 + if (err) 6387 + goto out_role_sw_put; 6388 + 6389 + port->typec_caps.pd = port->pd; 6390 + 6514 6391 port->typec_port = typec_register_port(port->dev, &port->typec_caps); 6515 6392 if (IS_ERR(port->typec_port)) { 6516 6393 err = PTR_ERR(port->typec_port); 6517 - goto out_role_sw_put; 6394 + goto out_unregister_pd; 6518 6395 } 6519 6396 6520 6397 typec_port_register_altmodes(port->typec_port, ··· 6535 6400 tcpm_log(port, "%s: registered", dev_name(dev)); 6536 6401 return port; 6537 6402 6403 + out_unregister_pd: 6404 + tcpm_port_unregister_pd(port); 6538 6405 out_role_sw_put: 6539 6406 usb_role_switch_put(port->role_sw); 6540 6407 out_destroy_wq: ··· 6559 6422 hrtimer_cancel(&port->state_machine_timer); 6560 6423 6561 6424 tcpm_reset_port(port); 6425 + 6426 + tcpm_port_unregister_pd(port); 6427 + 6562 6428 for (i = 0; i < ARRAY_SIZE(port->port_altmode); i++) 6563 6429 typec_unregister_altmode(port->port_altmode[i]); 6564 6430 typec_unregister_port(port->typec_port);
+10
drivers/usb/typec/ucsi/Kconfig
··· 48 48 To compile the driver as a module, choose M here: the module will be 49 49 called ucsi_acpi 50 50 51 + config UCSI_STM32G0 52 + tristate "UCSI Interface Driver for STM32G0" 53 + depends on I2C 54 + help 55 + This driver enables UCSI support on platforms that expose a STM32G0 56 + Type-C controller over I2C interface. 57 + 58 + To compile the driver as a module, choose M here: the module will be 59 + called ucsi_stm32g0. 60 + 51 61 endif
+1
drivers/usb/typec/ucsi/Makefile
··· 17 17 18 18 obj-$(CONFIG_UCSI_ACPI) += ucsi_acpi.o 19 19 obj-$(CONFIG_UCSI_CCG) += ucsi_ccg.o 20 + obj-$(CONFIG_UCSI_STM32G0) += ucsi_stm32g0.o
+4
drivers/usb/typec/ucsi/ucsi.c
··· 76 76 if (ret) 77 77 return ret; 78 78 79 + ret = ucsi_acknowledge_command(ucsi); 80 + if (ret) 81 + return ret; 82 + 79 83 switch (error) { 80 84 case UCSI_ERROR_INCOMPATIBLE_PARTNER: 81 85 return -EOPNOTSUPP;
+20 -8
drivers/usb/typec/ucsi/ucsi_ccg.c
··· 627 627 return IRQ_HANDLED; 628 628 } 629 629 630 + static int ccg_request_irq(struct ucsi_ccg *uc) 631 + { 632 + unsigned long flags = IRQF_ONESHOT; 633 + 634 + if (!has_acpi_companion(uc->dev)) 635 + flags |= IRQF_TRIGGER_HIGH; 636 + 637 + return request_threaded_irq(uc->irq, NULL, ccg_irq_handler, flags, dev_name(uc->dev), uc); 638 + } 639 + 630 640 static void ccg_pm_workaround_work(struct work_struct *pm_work) 631 641 { 632 642 ccg_irq_handler(0, container_of(pm_work, struct ucsi_ccg, pm_work)); ··· 1260 1250 return status; 1261 1251 } 1262 1252 1263 - status = request_threaded_irq(uc->irq, NULL, ccg_irq_handler, 1264 - IRQF_ONESHOT | IRQF_TRIGGER_HIGH, 1265 - dev_name(dev), uc); 1253 + status = ccg_request_irq(uc); 1266 1254 if (status < 0) { 1267 1255 dev_err(dev, "request_threaded_irq failed - %d\n", status); 1268 1256 return status; ··· 1339 1331 1340 1332 uc->dev = dev; 1341 1333 uc->client = client; 1334 + uc->irq = client->irq; 1342 1335 mutex_init(&uc->lock); 1343 1336 init_completion(&uc->complete); 1344 1337 INIT_WORK(&uc->work, ccg_update_firmware); ··· 1375 1366 1376 1367 ucsi_set_drvdata(uc->ucsi, uc); 1377 1368 1378 - status = request_threaded_irq(client->irq, NULL, ccg_irq_handler, 1379 - IRQF_ONESHOT | IRQF_TRIGGER_HIGH, 1380 - dev_name(dev), uc); 1369 + status = ccg_request_irq(uc); 1381 1370 if (status < 0) { 1382 1371 dev_err(uc->dev, "request_threaded_irq failed - %d\n", status); 1383 1372 goto out_ucsi_destroy; 1384 1373 } 1385 - 1386 - uc->irq = client->irq; 1387 1374 1388 1375 status = ucsi_register(uc->ucsi); 1389 1376 if (status) ··· 1423 1418 }; 1424 1419 MODULE_DEVICE_TABLE(i2c, ucsi_ccg_device_id); 1425 1420 1421 + static const struct acpi_device_id amd_i2c_ucsi_match[] = { 1422 + {"AMDI0042"}, 1423 + {} 1424 + }; 1425 + MODULE_DEVICE_TABLE(acpi, amd_i2c_ucsi_match); 1426 + 1426 1427 static int ucsi_ccg_resume(struct device *dev) 1427 1428 { 1428 1429 struct i2c_client *client = to_i2c_client(dev); ··· 1470 1459 .name = "ucsi_ccg", 1471 1460 .pm = &ucsi_ccg_pm, 1472 1461 .dev_groups = ucsi_ccg_groups, 1462 + .acpi_match_table = amd_i2c_ucsi_match, 1473 1463 }, 1474 1464 .probe = ucsi_ccg_probe, 1475 1465 .remove = ucsi_ccg_remove,
+777
drivers/usb/typec/ucsi/ucsi_stm32g0.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause 2 + /* 3 + * UCSI driver for STMicroelectronics STM32G0 Type-C PD controller 4 + * 5 + * Copyright (C) 2022, STMicroelectronics - All Rights Reserved 6 + * Author: Fabrice Gasnier <fabrice.gasnier@foss.st.com>. 7 + */ 8 + 9 + #include <linux/delay.h> 10 + #include <linux/firmware.h> 11 + #include <linux/i2c.h> 12 + #include <linux/interrupt.h> 13 + #include <linux/module.h> 14 + #include <linux/platform_device.h> 15 + #include <asm/unaligned.h> 16 + 17 + #include "ucsi.h" 18 + 19 + /* STM32G0 I2C bootloader addr: 0b1010001x (See AN2606) */ 20 + #define STM32G0_I2C_BL_ADDR (0xa2 >> 1) 21 + 22 + /* STM32G0 I2C bootloader max data size */ 23 + #define STM32G0_I2C_BL_SZ 256 24 + 25 + /* STM32 I2C bootloader commands (See AN4221) */ 26 + #define STM32_CMD_GVR 0x01 /* Gets the bootloader version */ 27 + #define STM32_CMD_GVR_LEN 1 28 + #define STM32_CMD_RM 0x11 /* Reag memory */ 29 + #define STM32_CMD_WM 0x31 /* Write memory */ 30 + #define STM32_CMD_ADDR_LEN 5 /* Address len for go, mem write... */ 31 + #define STM32_CMD_ERASE 0x44 /* Erase page, bank or all */ 32 + #define STM32_CMD_ERASE_SPECIAL_LEN 3 33 + #define STM32_CMD_GLOBAL_MASS_ERASE 0xffff /* All-bank erase */ 34 + 35 + /* STM32 I2C bootloader answer status */ 36 + #define STM32G0_I2C_BL_ACK 0x79 37 + #define STM32G0_I2C_BL_NACK 0x1f 38 + #define STM32G0_I2C_BL_BUSY 0x76 39 + 40 + /* STM32G0 flash definitions */ 41 + #define STM32G0_USER_OPTION_BYTES 0x1fff7800 42 + #define STM32G0_USER_OB_NBOOT0 BIT(26) 43 + #define STM32G0_USER_OB_NBOOT_SEL BIT(24) 44 + #define STM32G0_USER_OB_BOOT_MAIN (STM32G0_USER_OB_NBOOT0 | STM32G0_USER_OB_NBOOT_SEL) 45 + #define STM32G0_MAIN_MEM_ADDR 0x08000000 46 + 47 + /* STM32 Firmware definitions: additional commands */ 48 + #define STM32G0_FW_GETVER 0x00 /* Gets the firmware version */ 49 + #define STM32G0_FW_GETVER_LEN 4 50 + #define STM32G0_FW_RSTGOBL 0x21 /* Reset and go to bootloader */ 51 + #define STM32G0_FW_KEYWORD 0xa56959a6 52 + 53 + /* ucsi_stm32g0_fw_info located at the end of the firmware */ 54 + struct ucsi_stm32g0_fw_info { 55 + u32 version; 56 + u32 keyword; 57 + }; 58 + 59 + struct ucsi_stm32g0 { 60 + struct i2c_client *client; 61 + struct i2c_client *i2c_bl; 62 + bool in_bootloader; 63 + u8 bl_version; 64 + struct completion complete; 65 + struct device *dev; 66 + unsigned long flags; 67 + const char *fw_name; 68 + struct ucsi *ucsi; 69 + bool suspended; 70 + bool wakeup_event; 71 + }; 72 + 73 + /* 74 + * Bootloader commands helpers: 75 + * - send command (2 bytes) 76 + * - check ack 77 + * Then either: 78 + * - receive data 79 + * - receive data + check ack 80 + * - send data + check ack 81 + * These operations depends on the command and have various length. 82 + */ 83 + static int ucsi_stm32g0_bl_check_ack(struct ucsi *ucsi) 84 + { 85 + struct ucsi_stm32g0 *g0 = ucsi_get_drvdata(ucsi); 86 + struct i2c_client *client = g0->i2c_bl; 87 + unsigned char ack; 88 + struct i2c_msg msg[] = { 89 + { 90 + .addr = client->addr, 91 + .flags = I2C_M_RD, 92 + .len = 1, 93 + .buf = &ack, 94 + }, 95 + }; 96 + int ret; 97 + 98 + ret = i2c_transfer(client->adapter, msg, ARRAY_SIZE(msg)); 99 + if (ret != ARRAY_SIZE(msg)) { 100 + dev_err(g0->dev, "i2c bl ack (%02x), error: %d\n", client->addr, ret); 101 + 102 + return ret < 0 ? ret : -EIO; 103 + } 104 + 105 + /* The 'ack' byte should contain bootloader answer: ack/nack/busy */ 106 + switch (ack) { 107 + case STM32G0_I2C_BL_ACK: 108 + return 0; 109 + case STM32G0_I2C_BL_NACK: 110 + return -ENOENT; 111 + case STM32G0_I2C_BL_BUSY: 112 + return -EBUSY; 113 + default: 114 + dev_err(g0->dev, "i2c bl ack (%02x), invalid byte: %02x\n", 115 + client->addr, ack); 116 + return -EINVAL; 117 + } 118 + } 119 + 120 + static int ucsi_stm32g0_bl_cmd_check_ack(struct ucsi *ucsi, unsigned int cmd, bool check_ack) 121 + { 122 + struct ucsi_stm32g0 *g0 = ucsi_get_drvdata(ucsi); 123 + struct i2c_client *client = g0->i2c_bl; 124 + unsigned char buf[2]; 125 + struct i2c_msg msg[] = { 126 + { 127 + .addr = client->addr, 128 + .flags = 0, 129 + .len = sizeof(buf), 130 + .buf = buf, 131 + }, 132 + }; 133 + int ret; 134 + 135 + /* 136 + * Send STM32 bootloader command format is two bytes: 137 + * - command code 138 + * - XOR'ed command code 139 + */ 140 + buf[0] = cmd; 141 + buf[1] = cmd ^ 0xff; 142 + 143 + ret = i2c_transfer(client->adapter, msg, ARRAY_SIZE(msg)); 144 + if (ret != ARRAY_SIZE(msg)) { 145 + dev_dbg(g0->dev, "i2c bl cmd %d (%02x), error: %d\n", cmd, client->addr, ret); 146 + 147 + return ret < 0 ? ret : -EIO; 148 + } 149 + 150 + if (check_ack) 151 + return ucsi_stm32g0_bl_check_ack(ucsi); 152 + 153 + return 0; 154 + } 155 + 156 + static int ucsi_stm32g0_bl_cmd(struct ucsi *ucsi, unsigned int cmd) 157 + { 158 + return ucsi_stm32g0_bl_cmd_check_ack(ucsi, cmd, true); 159 + } 160 + 161 + static int ucsi_stm32g0_bl_rcv_check_ack(struct ucsi *ucsi, void *data, size_t len, bool check_ack) 162 + { 163 + struct ucsi_stm32g0 *g0 = ucsi_get_drvdata(ucsi); 164 + struct i2c_client *client = g0->i2c_bl; 165 + struct i2c_msg msg[] = { 166 + { 167 + .addr = client->addr, 168 + .flags = I2C_M_RD, 169 + .len = len, 170 + .buf = data, 171 + }, 172 + }; 173 + int ret; 174 + 175 + ret = i2c_transfer(client->adapter, msg, ARRAY_SIZE(msg)); 176 + if (ret != ARRAY_SIZE(msg)) { 177 + dev_err(g0->dev, "i2c bl rcv %02x, error: %d\n", client->addr, ret); 178 + 179 + return ret < 0 ? ret : -EIO; 180 + } 181 + 182 + if (check_ack) 183 + return ucsi_stm32g0_bl_check_ack(ucsi); 184 + 185 + return 0; 186 + } 187 + 188 + static int ucsi_stm32g0_bl_rcv(struct ucsi *ucsi, void *data, size_t len) 189 + { 190 + return ucsi_stm32g0_bl_rcv_check_ack(ucsi, data, len, true); 191 + } 192 + 193 + static int ucsi_stm32g0_bl_rcv_woack(struct ucsi *ucsi, void *data, size_t len) 194 + { 195 + return ucsi_stm32g0_bl_rcv_check_ack(ucsi, data, len, false); 196 + } 197 + 198 + static int ucsi_stm32g0_bl_send(struct ucsi *ucsi, void *data, size_t len) 199 + { 200 + struct ucsi_stm32g0 *g0 = ucsi_get_drvdata(ucsi); 201 + struct i2c_client *client = g0->i2c_bl; 202 + struct i2c_msg msg[] = { 203 + { 204 + .addr = client->addr, 205 + .flags = 0, 206 + .len = len, 207 + .buf = data, 208 + }, 209 + }; 210 + int ret; 211 + 212 + ret = i2c_transfer(client->adapter, msg, ARRAY_SIZE(msg)); 213 + if (ret != ARRAY_SIZE(msg)) { 214 + dev_err(g0->dev, "i2c bl send %02x, error: %d\n", client->addr, ret); 215 + 216 + return ret < 0 ? ret : -EIO; 217 + } 218 + 219 + return ucsi_stm32g0_bl_check_ack(ucsi); 220 + } 221 + 222 + /* Bootloader commands */ 223 + static int ucsi_stm32g0_bl_get_version(struct ucsi *ucsi, u8 *bl_version) 224 + { 225 + int ret; 226 + 227 + ret = ucsi_stm32g0_bl_cmd(ucsi, STM32_CMD_GVR); 228 + if (ret) 229 + return ret; 230 + 231 + return ucsi_stm32g0_bl_rcv(ucsi, bl_version, STM32_CMD_GVR_LEN); 232 + } 233 + 234 + static int ucsi_stm32g0_bl_send_addr(struct ucsi *ucsi, u32 addr) 235 + { 236 + u8 data8[STM32_CMD_ADDR_LEN]; 237 + 238 + /* Address format: 4 bytes addr (MSB first) + XOR'ed addr bytes */ 239 + put_unaligned_be32(addr, data8); 240 + data8[4] = data8[0] ^ data8[1] ^ data8[2] ^ data8[3]; 241 + 242 + return ucsi_stm32g0_bl_send(ucsi, data8, STM32_CMD_ADDR_LEN); 243 + } 244 + 245 + static int ucsi_stm32g0_bl_global_mass_erase(struct ucsi *ucsi) 246 + { 247 + u8 data8[4]; 248 + u16 *data16 = (u16 *)&data8[0]; 249 + int ret; 250 + 251 + data16[0] = STM32_CMD_GLOBAL_MASS_ERASE; 252 + data8[2] = data8[0] ^ data8[1]; 253 + 254 + ret = ucsi_stm32g0_bl_cmd(ucsi, STM32_CMD_ERASE); 255 + if (ret) 256 + return ret; 257 + 258 + return ucsi_stm32g0_bl_send(ucsi, data8, STM32_CMD_ERASE_SPECIAL_LEN); 259 + } 260 + 261 + static int ucsi_stm32g0_bl_write(struct ucsi *ucsi, u32 addr, const void *data, size_t len) 262 + { 263 + u8 *data8; 264 + int i, ret; 265 + 266 + if (!len || len > STM32G0_I2C_BL_SZ) 267 + return -EINVAL; 268 + 269 + /* Write memory: len bytes -1, data up to 256 bytes + XOR'ed bytes */ 270 + data8 = kmalloc(STM32G0_I2C_BL_SZ + 2, GFP_KERNEL); 271 + if (!data8) 272 + return -ENOMEM; 273 + 274 + ret = ucsi_stm32g0_bl_cmd(ucsi, STM32_CMD_WM); 275 + if (ret) 276 + goto free; 277 + 278 + ret = ucsi_stm32g0_bl_send_addr(ucsi, addr); 279 + if (ret) 280 + goto free; 281 + 282 + data8[0] = len - 1; 283 + memcpy(data8 + 1, data, len); 284 + data8[len + 1] = data8[0]; 285 + for (i = 1; i <= len; i++) 286 + data8[len + 1] ^= data8[i]; 287 + 288 + ret = ucsi_stm32g0_bl_send(ucsi, data8, len + 2); 289 + free: 290 + kfree(data8); 291 + 292 + return ret; 293 + } 294 + 295 + static int ucsi_stm32g0_bl_read(struct ucsi *ucsi, u32 addr, void *data, size_t len) 296 + { 297 + int ret; 298 + 299 + if (!len || len > STM32G0_I2C_BL_SZ) 300 + return -EINVAL; 301 + 302 + ret = ucsi_stm32g0_bl_cmd(ucsi, STM32_CMD_RM); 303 + if (ret) 304 + return ret; 305 + 306 + ret = ucsi_stm32g0_bl_send_addr(ucsi, addr); 307 + if (ret) 308 + return ret; 309 + 310 + ret = ucsi_stm32g0_bl_cmd(ucsi, len - 1); 311 + if (ret) 312 + return ret; 313 + 314 + return ucsi_stm32g0_bl_rcv_woack(ucsi, data, len); 315 + } 316 + 317 + /* Firmware commands (the same address as the bootloader) */ 318 + static int ucsi_stm32g0_fw_cmd(struct ucsi *ucsi, unsigned int cmd) 319 + { 320 + return ucsi_stm32g0_bl_cmd_check_ack(ucsi, cmd, false); 321 + } 322 + 323 + static int ucsi_stm32g0_fw_rcv(struct ucsi *ucsi, void *data, size_t len) 324 + { 325 + return ucsi_stm32g0_bl_rcv_woack(ucsi, data, len); 326 + } 327 + 328 + /* UCSI ops */ 329 + static int ucsi_stm32g0_read(struct ucsi *ucsi, unsigned int offset, void *val, size_t len) 330 + { 331 + struct ucsi_stm32g0 *g0 = ucsi_get_drvdata(ucsi); 332 + struct i2c_client *client = g0->client; 333 + u8 reg = offset; 334 + struct i2c_msg msg[] = { 335 + { 336 + .addr = client->addr, 337 + .flags = 0, 338 + .len = 1, 339 + .buf = &reg, 340 + }, 341 + { 342 + .addr = client->addr, 343 + .flags = I2C_M_RD, 344 + .len = len, 345 + .buf = val, 346 + }, 347 + }; 348 + int ret; 349 + 350 + ret = i2c_transfer(client->adapter, msg, ARRAY_SIZE(msg)); 351 + if (ret != ARRAY_SIZE(msg)) { 352 + dev_err(g0->dev, "i2c read %02x, %02x error: %d\n", client->addr, reg, ret); 353 + 354 + return ret < 0 ? ret : -EIO; 355 + } 356 + 357 + return 0; 358 + } 359 + 360 + static int ucsi_stm32g0_async_write(struct ucsi *ucsi, unsigned int offset, const void *val, 361 + size_t len) 362 + { 363 + struct ucsi_stm32g0 *g0 = ucsi_get_drvdata(ucsi); 364 + struct i2c_client *client = g0->client; 365 + struct i2c_msg msg[] = { 366 + { 367 + .addr = client->addr, 368 + .flags = 0, 369 + } 370 + }; 371 + unsigned char *buf; 372 + int ret; 373 + 374 + buf = kmalloc(len + 1, GFP_KERNEL); 375 + if (!buf) 376 + return -ENOMEM; 377 + 378 + buf[0] = offset; 379 + memcpy(&buf[1], val, len); 380 + msg[0].len = len + 1; 381 + msg[0].buf = buf; 382 + 383 + ret = i2c_transfer(client->adapter, msg, ARRAY_SIZE(msg)); 384 + kfree(buf); 385 + if (ret != ARRAY_SIZE(msg)) { 386 + dev_err(g0->dev, "i2c write %02x, %02x error: %d\n", client->addr, offset, ret); 387 + 388 + return ret < 0 ? ret : -EIO; 389 + } 390 + 391 + return 0; 392 + } 393 + 394 + static int ucsi_stm32g0_sync_write(struct ucsi *ucsi, unsigned int offset, const void *val, 395 + size_t len) 396 + { 397 + struct ucsi_stm32g0 *g0 = ucsi_get_drvdata(ucsi); 398 + int ret; 399 + 400 + set_bit(COMMAND_PENDING, &g0->flags); 401 + 402 + ret = ucsi_stm32g0_async_write(ucsi, offset, val, len); 403 + if (ret) 404 + goto out_clear_bit; 405 + 406 + if (!wait_for_completion_timeout(&g0->complete, msecs_to_jiffies(5000))) 407 + ret = -ETIMEDOUT; 408 + 409 + out_clear_bit: 410 + clear_bit(COMMAND_PENDING, &g0->flags); 411 + 412 + return ret; 413 + } 414 + 415 + static irqreturn_t ucsi_stm32g0_irq_handler(int irq, void *data) 416 + { 417 + struct ucsi_stm32g0 *g0 = data; 418 + u32 cci; 419 + int ret; 420 + 421 + if (g0->suspended) 422 + g0->wakeup_event = true; 423 + 424 + ret = ucsi_stm32g0_read(g0->ucsi, UCSI_CCI, &cci, sizeof(cci)); 425 + if (ret) 426 + return IRQ_NONE; 427 + 428 + if (UCSI_CCI_CONNECTOR(cci)) 429 + ucsi_connector_change(g0->ucsi, UCSI_CCI_CONNECTOR(cci)); 430 + 431 + if (test_bit(COMMAND_PENDING, &g0->flags) && 432 + cci & (UCSI_CCI_ACK_COMPLETE | UCSI_CCI_COMMAND_COMPLETE)) 433 + complete(&g0->complete); 434 + 435 + return IRQ_HANDLED; 436 + } 437 + 438 + static const struct ucsi_operations ucsi_stm32g0_ops = { 439 + .read = ucsi_stm32g0_read, 440 + .sync_write = ucsi_stm32g0_sync_write, 441 + .async_write = ucsi_stm32g0_async_write, 442 + }; 443 + 444 + static int ucsi_stm32g0_register(struct ucsi *ucsi) 445 + { 446 + struct ucsi_stm32g0 *g0 = ucsi_get_drvdata(ucsi); 447 + struct i2c_client *client = g0->client; 448 + int ret; 449 + 450 + /* Request alert interrupt */ 451 + ret = request_threaded_irq(client->irq, NULL, ucsi_stm32g0_irq_handler, IRQF_ONESHOT, 452 + dev_name(g0->dev), g0); 453 + if (ret) { 454 + dev_err(g0->dev, "request IRQ failed: %d\n", ret); 455 + return ret; 456 + } 457 + 458 + ret = ucsi_register(ucsi); 459 + if (ret) { 460 + dev_err_probe(g0->dev, ret, "ucsi_register failed\n"); 461 + free_irq(client->irq, g0); 462 + return ret; 463 + } 464 + 465 + return 0; 466 + } 467 + 468 + static void ucsi_stm32g0_unregister(struct ucsi *ucsi) 469 + { 470 + struct ucsi_stm32g0 *g0 = ucsi_get_drvdata(ucsi); 471 + struct i2c_client *client = g0->client; 472 + 473 + ucsi_unregister(ucsi); 474 + free_irq(client->irq, g0); 475 + } 476 + 477 + static void ucsi_stm32g0_fw_cb(const struct firmware *fw, void *context) 478 + { 479 + struct ucsi_stm32g0 *g0; 480 + const u8 *data, *end; 481 + const struct ucsi_stm32g0_fw_info *fw_info; 482 + u32 addr = STM32G0_MAIN_MEM_ADDR, ob, fw_version; 483 + int ret, size; 484 + 485 + if (!context) 486 + return; 487 + 488 + g0 = ucsi_get_drvdata(context); 489 + 490 + if (!fw) 491 + goto fw_release; 492 + 493 + fw_info = (struct ucsi_stm32g0_fw_info *)(fw->data + fw->size - sizeof(*fw_info)); 494 + 495 + if (!g0->in_bootloader) { 496 + /* Read running firmware version */ 497 + ret = ucsi_stm32g0_fw_cmd(g0->ucsi, STM32G0_FW_GETVER); 498 + if (ret) { 499 + dev_err(g0->dev, "Get version cmd failed %d\n", ret); 500 + goto fw_release; 501 + } 502 + ret = ucsi_stm32g0_fw_rcv(g0->ucsi, &fw_version, 503 + STM32G0_FW_GETVER_LEN); 504 + if (ret) { 505 + dev_err(g0->dev, "Get version failed %d\n", ret); 506 + goto fw_release; 507 + } 508 + 509 + /* Sanity check on keyword and firmware version */ 510 + if (fw_info->keyword != STM32G0_FW_KEYWORD || fw_info->version == fw_version) 511 + goto fw_release; 512 + 513 + dev_info(g0->dev, "Flashing FW: %08x (%08x cur)\n", fw_info->version, fw_version); 514 + 515 + /* Switch to bootloader mode */ 516 + ucsi_stm32g0_unregister(g0->ucsi); 517 + ret = ucsi_stm32g0_fw_cmd(g0->ucsi, STM32G0_FW_RSTGOBL); 518 + if (ret) { 519 + dev_err(g0->dev, "bootloader cmd failed %d\n", ret); 520 + goto fw_release; 521 + } 522 + g0->in_bootloader = true; 523 + 524 + /* STM32G0 reboot delay */ 525 + msleep(100); 526 + } 527 + 528 + ret = ucsi_stm32g0_bl_global_mass_erase(g0->ucsi); 529 + if (ret) { 530 + dev_err(g0->dev, "Erase failed %d\n", ret); 531 + goto fw_release; 532 + } 533 + 534 + data = fw->data; 535 + end = fw->data + fw->size; 536 + while (data < end) { 537 + if ((end - data) < STM32G0_I2C_BL_SZ) 538 + size = end - data; 539 + else 540 + size = STM32G0_I2C_BL_SZ; 541 + 542 + ret = ucsi_stm32g0_bl_write(g0->ucsi, addr, data, size); 543 + if (ret) { 544 + dev_err(g0->dev, "Write failed %d\n", ret); 545 + goto fw_release; 546 + } 547 + addr += size; 548 + data += size; 549 + } 550 + 551 + dev_dbg(g0->dev, "Configure to boot from main flash\n"); 552 + 553 + ret = ucsi_stm32g0_bl_read(g0->ucsi, STM32G0_USER_OPTION_BYTES, &ob, sizeof(ob)); 554 + if (ret) { 555 + dev_err(g0->dev, "read user option bytes failed %d\n", ret); 556 + goto fw_release; 557 + } 558 + 559 + dev_dbg(g0->dev, "STM32G0_USER_OPTION_BYTES 0x%08x\n", ob); 560 + 561 + /* Configure user option bytes to boot from main flash next time */ 562 + ob |= STM32G0_USER_OB_BOOT_MAIN; 563 + 564 + /* Writing option bytes will also reset G0 for updates to be loaded */ 565 + ret = ucsi_stm32g0_bl_write(g0->ucsi, STM32G0_USER_OPTION_BYTES, &ob, sizeof(ob)); 566 + if (ret) { 567 + dev_err(g0->dev, "write user option bytes failed %d\n", ret); 568 + goto fw_release; 569 + } 570 + 571 + dev_info(g0->dev, "Starting, option bytes:0x%08x\n", ob); 572 + 573 + /* STM32G0 FW boot delay */ 574 + msleep(500); 575 + 576 + /* Register UCSI interface */ 577 + if (!ucsi_stm32g0_register(g0->ucsi)) 578 + g0->in_bootloader = false; 579 + 580 + fw_release: 581 + release_firmware(fw); 582 + } 583 + 584 + static int ucsi_stm32g0_probe_bootloader(struct ucsi *ucsi) 585 + { 586 + struct ucsi_stm32g0 *g0 = ucsi_get_drvdata(ucsi); 587 + int ret; 588 + u16 ucsi_version; 589 + 590 + /* firmware-name is optional */ 591 + if (device_property_present(g0->dev, "firmware-name")) { 592 + ret = device_property_read_string(g0->dev, "firmware-name", &g0->fw_name); 593 + if (ret < 0) 594 + return dev_err_probe(g0->dev, ret, "Error reading firmware-name\n"); 595 + } 596 + 597 + if (g0->fw_name) { 598 + /* STM32G0 in bootloader mode communicates at reserved address 0x51 */ 599 + g0->i2c_bl = i2c_new_dummy_device(g0->client->adapter, STM32G0_I2C_BL_ADDR); 600 + if (IS_ERR(g0->i2c_bl)) { 601 + ret = dev_err_probe(g0->dev, PTR_ERR(g0->i2c_bl), 602 + "Failed to register booloader I2C address\n"); 603 + return ret; 604 + } 605 + } 606 + 607 + /* 608 + * Try to guess if the STM32G0 is running a UCSI firmware. First probe the UCSI FW at its 609 + * i2c address. Fallback to bootloader i2c address only if firmware-name is specified. 610 + */ 611 + ret = ucsi_stm32g0_read(ucsi, UCSI_VERSION, &ucsi_version, sizeof(ucsi_version)); 612 + if (!ret || !g0->fw_name) 613 + return ret; 614 + 615 + /* Speculatively read the bootloader version that has a known length. */ 616 + ret = ucsi_stm32g0_bl_get_version(ucsi, &g0->bl_version); 617 + if (ret < 0) { 618 + i2c_unregister_device(g0->i2c_bl); 619 + return ret; 620 + } 621 + 622 + /* Device in bootloader mode */ 623 + g0->in_bootloader = true; 624 + dev_info(g0->dev, "Bootloader Version 0x%02x\n", g0->bl_version); 625 + 626 + return 0; 627 + } 628 + 629 + static int ucsi_stm32g0_probe(struct i2c_client *client, const struct i2c_device_id *id) 630 + { 631 + struct device *dev = &client->dev; 632 + struct ucsi_stm32g0 *g0; 633 + int ret; 634 + 635 + g0 = devm_kzalloc(dev, sizeof(*g0), GFP_KERNEL); 636 + if (!g0) 637 + return -ENOMEM; 638 + 639 + g0->dev = dev; 640 + g0->client = client; 641 + init_completion(&g0->complete); 642 + i2c_set_clientdata(client, g0); 643 + 644 + g0->ucsi = ucsi_create(dev, &ucsi_stm32g0_ops); 645 + if (IS_ERR(g0->ucsi)) 646 + return PTR_ERR(g0->ucsi); 647 + 648 + ucsi_set_drvdata(g0->ucsi, g0); 649 + 650 + ret = ucsi_stm32g0_probe_bootloader(g0->ucsi); 651 + if (ret < 0) 652 + goto destroy; 653 + 654 + /* 655 + * Don't register in bootloader mode: wait for the firmware to be loaded and started before 656 + * registering UCSI device. 657 + */ 658 + if (!g0->in_bootloader) { 659 + ret = ucsi_stm32g0_register(g0->ucsi); 660 + if (ret < 0) 661 + goto freei2c; 662 + } 663 + 664 + if (g0->fw_name) { 665 + /* 666 + * Asynchronously flash (e.g. bootloader mode) or update the running firmware, 667 + * not to hang the boot process 668 + */ 669 + ret = request_firmware_nowait(THIS_MODULE, FW_ACTION_UEVENT, g0->fw_name, g0->dev, 670 + GFP_KERNEL, g0->ucsi, ucsi_stm32g0_fw_cb); 671 + if (ret < 0) { 672 + dev_err_probe(dev, ret, "firmware request failed\n"); 673 + goto unregister; 674 + } 675 + } 676 + 677 + return 0; 678 + 679 + unregister: 680 + if (!g0->in_bootloader) 681 + ucsi_stm32g0_unregister(g0->ucsi); 682 + freei2c: 683 + if (g0->fw_name) 684 + i2c_unregister_device(g0->i2c_bl); 685 + destroy: 686 + ucsi_destroy(g0->ucsi); 687 + 688 + return ret; 689 + } 690 + 691 + static int ucsi_stm32g0_remove(struct i2c_client *client) 692 + { 693 + struct ucsi_stm32g0 *g0 = i2c_get_clientdata(client); 694 + 695 + if (!g0->in_bootloader) 696 + ucsi_stm32g0_unregister(g0->ucsi); 697 + if (g0->fw_name) 698 + i2c_unregister_device(g0->i2c_bl); 699 + ucsi_destroy(g0->ucsi); 700 + 701 + return 0; 702 + } 703 + 704 + static int ucsi_stm32g0_suspend(struct device *dev) 705 + { 706 + struct ucsi_stm32g0 *g0 = dev_get_drvdata(dev); 707 + struct i2c_client *client = g0->client; 708 + 709 + if (g0->in_bootloader) 710 + return 0; 711 + 712 + /* Keep the interrupt disabled until the i2c bus has been resumed */ 713 + disable_irq(client->irq); 714 + 715 + g0->suspended = true; 716 + g0->wakeup_event = false; 717 + 718 + if (device_may_wakeup(dev) || device_wakeup_path(dev)) 719 + enable_irq_wake(client->irq); 720 + 721 + return 0; 722 + } 723 + 724 + static int ucsi_stm32g0_resume(struct device *dev) 725 + { 726 + struct ucsi_stm32g0 *g0 = dev_get_drvdata(dev); 727 + struct i2c_client *client = g0->client; 728 + 729 + if (g0->in_bootloader) 730 + return 0; 731 + 732 + if (device_may_wakeup(dev) || device_wakeup_path(dev)) 733 + disable_irq_wake(client->irq); 734 + 735 + enable_irq(client->irq); 736 + 737 + /* Enforce any pending handler gets called to signal a wakeup_event */ 738 + synchronize_irq(client->irq); 739 + 740 + if (g0->wakeup_event) 741 + pm_wakeup_event(g0->dev, 0); 742 + 743 + g0->suspended = false; 744 + 745 + return 0; 746 + } 747 + 748 + static DEFINE_SIMPLE_DEV_PM_OPS(ucsi_stm32g0_pm_ops, ucsi_stm32g0_suspend, ucsi_stm32g0_resume); 749 + 750 + static const struct of_device_id __maybe_unused ucsi_stm32g0_typec_of_match[] = { 751 + { .compatible = "st,stm32g0-typec" }, 752 + {}, 753 + }; 754 + MODULE_DEVICE_TABLE(of, ucsi_stm32g0_typec_of_match); 755 + 756 + static const struct i2c_device_id ucsi_stm32g0_typec_i2c_devid[] = { 757 + {"stm32g0-typec", 0}, 758 + {}, 759 + }; 760 + MODULE_DEVICE_TABLE(i2c, ucsi_stm32g0_typec_i2c_devid); 761 + 762 + static struct i2c_driver ucsi_stm32g0_i2c_driver = { 763 + .driver = { 764 + .name = "ucsi-stm32g0-i2c", 765 + .of_match_table = of_match_ptr(ucsi_stm32g0_typec_of_match), 766 + .pm = pm_sleep_ptr(&ucsi_stm32g0_pm_ops), 767 + }, 768 + .probe = ucsi_stm32g0_probe, 769 + .remove = ucsi_stm32g0_remove, 770 + .id_table = ucsi_stm32g0_typec_i2c_devid 771 + }; 772 + module_i2c_driver(ucsi_stm32g0_i2c_driver); 773 + 774 + MODULE_AUTHOR("Fabrice Gasnier <fabrice.gasnier@foss.st.com>"); 775 + MODULE_DESCRIPTION("STMicroelectronics STM32G0 Type-C controller"); 776 + MODULE_LICENSE("Dual BSD/GPL"); 777 + MODULE_ALIAS("platform:ucsi-stm32g0");
+3 -3
drivers/usb/usbip/vudc_rx.c
··· 104 104 if (pdu->base.direction == USBIP_DIR_IN) 105 105 address |= USB_DIR_IN; 106 106 107 - spin_lock_irq(&udc->lock); 107 + spin_lock_irqsave(&udc->lock, flags); 108 108 urb_p->ep = vudc_find_endpoint(udc, address); 109 109 if (!urb_p->ep) { 110 110 /* we don't know the type, there may be isoc data! */ 111 111 dev_err(&udc->pdev->dev, "request to nonexistent endpoint"); 112 - spin_unlock_irq(&udc->lock); 112 + spin_unlock_irqrestore(&udc->lock, flags); 113 113 usbip_event_add(&udc->ud, VUDC_EVENT_ERROR_TCP); 114 114 ret = -EPIPE; 115 115 goto free_urbp; 116 116 } 117 117 urb_p->type = urb_p->ep->type; 118 - spin_unlock_irq(&udc->lock); 118 + spin_unlock_irqrestore(&udc->lock, flags); 119 119 120 120 urb_p->new = 1; 121 121 urb_p->seqnum = pdu->base.seqnum;
+7 -7
drivers/usb/usbip/vudc_sysfs.c
··· 128 128 goto unlock; 129 129 } 130 130 131 - spin_lock_irq(&udc->ud.lock); 131 + spin_lock(&udc->ud.lock); 132 132 133 133 if (udc->ud.status != SDEV_ST_AVAILABLE) { 134 134 ret = -EINVAL; ··· 150 150 } 151 151 152 152 /* unlock and create threads and get tasks */ 153 - spin_unlock_irq(&udc->ud.lock); 153 + spin_unlock(&udc->ud.lock); 154 154 spin_unlock_irqrestore(&udc->lock, flags); 155 155 156 156 tcp_rx = kthread_create(&v_rx_loop, &udc->ud, "vudc_rx"); ··· 173 173 174 174 /* lock and update udc->ud state */ 175 175 spin_lock_irqsave(&udc->lock, flags); 176 - spin_lock_irq(&udc->ud.lock); 176 + spin_lock(&udc->ud.lock); 177 177 178 178 udc->ud.tcp_socket = socket; 179 179 udc->ud.tcp_rx = tcp_rx; 180 180 udc->ud.tcp_tx = tcp_tx; 181 181 udc->ud.status = SDEV_ST_USED; 182 182 183 - spin_unlock_irq(&udc->ud.lock); 183 + spin_unlock(&udc->ud.lock); 184 184 185 185 ktime_get_ts64(&udc->start_time); 186 186 v_start_timer(udc); ··· 201 201 goto unlock; 202 202 } 203 203 204 - spin_lock_irq(&udc->ud.lock); 204 + spin_lock(&udc->ud.lock); 205 205 if (udc->ud.status != SDEV_ST_USED) { 206 206 ret = -EINVAL; 207 207 goto unlock_ud; 208 208 } 209 - spin_unlock_irq(&udc->ud.lock); 209 + spin_unlock(&udc->ud.lock); 210 210 211 211 usbip_event_add(&udc->ud, VUDC_EVENT_DOWN); 212 212 } ··· 219 219 sock_err: 220 220 sockfd_put(socket); 221 221 unlock_ud: 222 - spin_unlock_irq(&udc->ud.lock); 222 + spin_unlock(&udc->ud.lock); 223 223 unlock: 224 224 spin_unlock_irqrestore(&udc->lock, flags); 225 225 mutex_unlock(&udc->ud.sysfs_lock);
+18 -4
include/linux/of_platform.h
··· 61 61 } 62 62 #endif 63 63 64 + extern int of_platform_bus_probe(struct device_node *root, 65 + const struct of_device_id *matches, 66 + struct device *parent); 67 + 68 + #ifdef CONFIG_OF_ADDRESS 64 69 /* Platform devices and busses creation */ 65 70 extern struct platform_device *of_platform_device_create(struct device_node *np, 66 71 const char *bus_id, 67 72 struct device *parent); 68 73 69 74 extern int of_platform_device_destroy(struct device *dev, void *data); 70 - extern int of_platform_bus_probe(struct device_node *root, 71 - const struct of_device_id *matches, 72 - struct device *parent); 73 - #ifdef CONFIG_OF_ADDRESS 75 + 74 76 extern int of_platform_populate(struct device_node *root, 75 77 const struct of_device_id *matches, 76 78 const struct of_dev_auxdata *lookup, ··· 86 84 87 85 extern void devm_of_platform_depopulate(struct device *dev); 88 86 #else 87 + /* Platform devices and busses creation */ 88 + static inline struct platform_device *of_platform_device_create(struct device_node *np, 89 + const char *bus_id, 90 + struct device *parent) 91 + { 92 + return NULL; 93 + } 94 + static inline int of_platform_device_destroy(struct device *dev, void *data) 95 + { 96 + return -ENODEV; 97 + } 98 + 89 99 static inline int of_platform_populate(struct device_node *root, 90 100 const struct of_device_id *matches, 91 101 const struct of_dev_auxdata *lookup,
+2
include/linux/usb.h
··· 584 584 * @authenticated: Crypto authentication passed 585 585 * @wusb: device is Wireless USB 586 586 * @lpm_capable: device supports LPM 587 + * @lpm_devinit_allow: Allow USB3 device initiated LPM, exit latency is in range 587 588 * @usb2_hw_lpm_capable: device can perform USB2 hardware LPM 588 589 * @usb2_hw_lpm_besl_capable: device can perform USB2 hardware BESL LPM 589 590 * @usb2_hw_lpm_enabled: USB2 hardware LPM is enabled ··· 667 666 unsigned authenticated:1; 668 667 unsigned wusb:1; 669 668 unsigned lpm_capable:1; 669 + unsigned lpm_devinit_allow:1; 670 670 unsigned usb2_hw_lpm_capable:1; 671 671 unsigned usb2_hw_lpm_besl_capable:1; 672 672 unsigned usb2_hw_lpm_enabled:1;
+1
include/linux/usb/hcd.h
··· 66 66 67 67 struct giveback_urb_bh { 68 68 bool running; 69 + bool high_prio; 69 70 spinlock_t lock; 70 71 struct list_head head; 71 72 struct tasklet_struct bh;
+18
include/linux/usb/onboard_hub.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + 3 + #ifndef __LINUX_USB_ONBOARD_HUB_H 4 + #define __LINUX_USB_ONBOARD_HUB_H 5 + 6 + struct usb_device; 7 + struct list_head; 8 + 9 + #if IS_ENABLED(CONFIG_USB_ONBOARD_HUB) 10 + void onboard_hub_create_pdevs(struct usb_device *parent_hub, struct list_head *pdev_list); 11 + void onboard_hub_destroy_pdevs(struct list_head *pdev_list); 12 + #else 13 + static inline void onboard_hub_create_pdevs(struct usb_device *parent_hub, 14 + struct list_head *pdev_list) {} 15 + static inline void onboard_hub_destroy_pdevs(struct list_head *pdev_list) {} 16 + #endif 17 + 18 + #endif /* __LINUX_USB_ONBOARD_HUB_H */
+38
include/linux/usb/pd.h
··· 495 495 496 496 #define PD_P_SNK_STDBY_MW 2500 /* 2500 mW */ 497 497 498 + #if IS_ENABLED(CONFIG_TYPEC) 499 + 500 + struct usb_power_delivery; 501 + 502 + /** 503 + * usb_power_delivery_desc - USB Power Delivery Descriptor 504 + * @revision: USB Power Delivery Specification Revision 505 + * @version: USB Power Delivery Specicication Version - optional 506 + */ 507 + struct usb_power_delivery_desc { 508 + u16 revision; 509 + u16 version; 510 + }; 511 + 512 + /** 513 + * usb_power_delivery_capabilities_desc - Description of USB Power Delivery Capabilities Message 514 + * @pdo: The Power Data Objects in the Capability Message 515 + * @role: Power role of the capabilities 516 + */ 517 + struct usb_power_delivery_capabilities_desc { 518 + u32 pdo[PDO_MAX_OBJECTS]; 519 + enum typec_role role; 520 + }; 521 + 522 + struct usb_power_delivery_capabilities * 523 + usb_power_delivery_register_capabilities(struct usb_power_delivery *pd, 524 + struct usb_power_delivery_capabilities_desc *desc); 525 + void usb_power_delivery_unregister_capabilities(struct usb_power_delivery_capabilities *cap); 526 + 527 + struct usb_power_delivery *usb_power_delivery_register(struct device *parent, 528 + struct usb_power_delivery_desc *desc); 529 + void usb_power_delivery_unregister(struct usb_power_delivery *pd); 530 + 531 + int usb_power_delivery_link_device(struct usb_power_delivery *pd, struct device *dev); 532 + void usb_power_delivery_unlink_device(struct usb_power_delivery *pd, struct device *dev); 533 + 534 + #endif /* CONFIG_TYPEC */ 535 + 498 536 #endif /* __LINUX_USB_PD_H */
+23
include/linux/usb/typec.h
··· 22 22 struct fwnode_handle; 23 23 struct device; 24 24 25 + struct usb_power_delivery; 26 + 25 27 enum typec_port_type { 26 28 TYPEC_PORT_SRC, 27 29 TYPEC_PORT_SNK, ··· 53 51 TYPEC_SINK, 54 52 TYPEC_SOURCE, 55 53 }; 54 + 55 + static inline int is_sink(enum typec_role role) 56 + { 57 + return role == TYPEC_SINK; 58 + } 59 + 60 + static inline int is_source(enum typec_role role) 61 + { 62 + return role == TYPEC_SOURCE; 63 + } 56 64 57 65 enum typec_pwr_opmode { 58 66 TYPEC_PWR_MODE_USB, ··· 225 213 * @pr_set: Set Power Role 226 214 * @vconn_set: Source VCONN 227 215 * @port_type_set: Set port type 216 + * @pd_get: Get available USB Power Delivery Capabilities. 217 + * @pd_set: Set USB Power Delivery Capabilities. 228 218 */ 229 219 struct typec_operations { 230 220 int (*try_role)(struct typec_port *port, int role); ··· 235 221 int (*vconn_set)(struct typec_port *port, enum typec_role role); 236 222 int (*port_type_set)(struct typec_port *port, 237 223 enum typec_port_type type); 224 + struct usb_power_delivery **(*pd_get)(struct typec_port *port); 225 + int (*pd_set)(struct typec_port *port, struct usb_power_delivery *pd); 238 226 }; 239 227 240 228 enum usb_pd_svdm_ver { ··· 256 240 * @accessory: Supported Accessory Modes 257 241 * @fwnode: Optional fwnode of the port 258 242 * @driver_data: Private pointer for driver specific info 243 + * @pd: Optional USB Power Delivery Support 259 244 * @ops: Port operations vector 260 245 * 261 246 * Static capabilities of a single USB Type-C port. ··· 273 256 274 257 struct fwnode_handle *fwnode; 275 258 void *driver_data; 259 + 260 + struct usb_power_delivery *pd; 276 261 277 262 const struct typec_operations *ops; 278 263 }; ··· 326 307 void typec_partner_set_svdm_version(struct typec_partner *partner, 327 308 enum usb_pd_svdm_ver svdm_version); 328 309 int typec_get_negotiated_svdm_version(struct typec_port *port); 310 + 311 + int typec_port_set_usb_power_delivery(struct typec_port *port, struct usb_power_delivery *pd); 312 + int typec_partner_set_usb_power_delivery(struct typec_partner *partner, 313 + struct usb_power_delivery *pd); 329 314 330 315 #endif /* __LINUX_USB_TYPEC_H */
+1 -1
include/linux/usb/typec_altmode.h
··· 124 124 125 125 /** 126 126 * typec_altmode_get_orientation - Get cable plug orientation 127 - * altmode: Handle to the alternate mode 127 + * @altmode: Handle to the alternate mode 128 128 */ 129 129 static inline enum typec_orientation 130 130 typec_altmode_get_orientation(struct typec_altmode *altmode)
+38 -6
include/linux/usb/typec_mux.h
··· 58 58 void *drvdata; 59 59 }; 60 60 61 + #if IS_ENABLED(CONFIG_TYPEC) 62 + 61 63 struct typec_mux *fwnode_typec_mux_get(struct fwnode_handle *fwnode, 62 64 const struct typec_altmode_desc *desc); 63 65 void typec_mux_put(struct typec_mux *mux); 64 66 int typec_mux_set(struct typec_mux *mux, struct typec_mux_state *state); 65 - 66 - static inline struct typec_mux * 67 - typec_mux_get(struct device *dev, const struct typec_altmode_desc *desc) 68 - { 69 - return fwnode_typec_mux_get(dev_fwnode(dev), desc); 70 - } 71 67 72 68 struct typec_mux_dev * 73 69 typec_mux_register(struct device *parent, const struct typec_mux_desc *desc); ··· 71 75 72 76 void typec_mux_set_drvdata(struct typec_mux_dev *mux, void *data); 73 77 void *typec_mux_get_drvdata(struct typec_mux_dev *mux); 78 + 79 + #else 80 + 81 + static inline struct typec_mux *fwnode_typec_mux_get(struct fwnode_handle *fwnode, 82 + const struct typec_altmode_desc *desc) 83 + { 84 + return NULL; 85 + } 86 + 87 + static inline void typec_mux_put(struct typec_mux *mux) {} 88 + 89 + static inline int typec_mux_set(struct typec_mux *mux, struct typec_mux_state *state) 90 + { 91 + return 0; 92 + } 93 + 94 + static inline struct typec_mux_dev * 95 + typec_mux_register(struct device *parent, const struct typec_mux_desc *desc) 96 + { 97 + return ERR_PTR(-EOPNOTSUPP); 98 + } 99 + static inline void typec_mux_unregister(struct typec_mux_dev *mux) {} 100 + 101 + static inline void typec_mux_set_drvdata(struct typec_mux_dev *mux, void *data) {} 102 + static inline void *typec_mux_get_drvdata(struct typec_mux_dev *mux) 103 + { 104 + return ERR_PTR(-EOPNOTSUPP); 105 + } 106 + 107 + #endif /* CONFIG_TYPEC */ 108 + 109 + static inline struct typec_mux * 110 + typec_mux_get(struct device *dev, const struct typec_altmode_desc *desc) 111 + { 112 + return fwnode_typec_mux_get(dev_fwnode(dev), desc); 113 + } 74 114 75 115 #endif /* __USB_TYPEC_MUX */
+45
include/linux/usb/typec_retimer.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + 3 + #ifndef __USB_TYPEC_RETIMER 4 + #define __USB_TYPEC_RETIMER 5 + 6 + #include <linux/property.h> 7 + #include <linux/usb/typec.h> 8 + 9 + struct device; 10 + struct typec_retimer; 11 + struct typec_altmode; 12 + struct fwnode_handle; 13 + 14 + struct typec_retimer_state { 15 + struct typec_altmode *alt; 16 + unsigned long mode; 17 + void *data; 18 + }; 19 + 20 + typedef int (*typec_retimer_set_fn_t)(struct typec_retimer *retimer, 21 + struct typec_retimer_state *state); 22 + 23 + struct typec_retimer_desc { 24 + struct fwnode_handle *fwnode; 25 + typec_retimer_set_fn_t set; 26 + const char *name; 27 + void *drvdata; 28 + }; 29 + 30 + struct typec_retimer *fwnode_typec_retimer_get(struct fwnode_handle *fwnode); 31 + void typec_retimer_put(struct typec_retimer *retimer); 32 + int typec_retimer_set(struct typec_retimer *retimer, struct typec_retimer_state *state); 33 + 34 + static inline struct typec_retimer *typec_retimer_get(struct device *dev) 35 + { 36 + return fwnode_typec_retimer_get(dev_fwnode(dev)); 37 + } 38 + 39 + struct typec_retimer * 40 + typec_retimer_register(struct device *parent, const struct typec_retimer_desc *desc); 41 + void typec_retimer_unregister(struct typec_retimer *retimer); 42 + 43 + void *typec_retimer_get_drvdata(struct typec_retimer *retimer); 44 + 45 + #endif /* __USB_TYPEC_RETIMER */
+13
include/uapi/linux/usb/cdc.h
··· 271 271 __u8 bDataBits; 272 272 } __attribute__ ((packed)); 273 273 274 + /* Control Signal Bitmap Values from 6.2.14 SetControlLineState */ 275 + #define USB_CDC_CTRL_DTR (1 << 0) 276 + #define USB_CDC_CTRL_RTS (1 << 1) 277 + 274 278 /* table 62; bits in multicast filter */ 275 279 #define USB_CDC_PACKET_TYPE_PROMISCUOUS (1 << 0) 276 280 #define USB_CDC_PACKET_TYPE_ALL_MULTICAST (1 << 1) /* no filter */ ··· 305 301 __le16 wIndex; 306 302 __le16 wLength; 307 303 } __attribute__ ((packed)); 304 + 305 + /* UART State Bitmap Values from 6.3.5 SerialState */ 306 + #define USB_CDC_SERIAL_STATE_DCD (1 << 0) 307 + #define USB_CDC_SERIAL_STATE_DSR (1 << 1) 308 + #define USB_CDC_SERIAL_STATE_BREAK (1 << 2) 309 + #define USB_CDC_SERIAL_STATE_RING_SIGNAL (1 << 3) 310 + #define USB_CDC_SERIAL_STATE_FRAMING (1 << 4) 311 + #define USB_CDC_SERIAL_STATE_PARITY (1 << 5) 312 + #define USB_CDC_SERIAL_STATE_OVERRUN (1 << 6) 308 313 309 314 struct usb_cdc_speed_change { 310 315 __le32 DLBitRRate; /* contains the downlink bit rate (IN pipe) */
+12 -6
tools/usb/testusb.c
··· 96 96 enum usb_device_speed { 97 97 USB_SPEED_UNKNOWN = 0, /* enumerating */ 98 98 USB_SPEED_LOW, USB_SPEED_FULL, /* usb 1.1 */ 99 - USB_SPEED_HIGH /* usb 2.0 */ 99 + USB_SPEED_HIGH, /* usb 2.0 */ 100 + USB_SPEED_WIRELESS, /* wireless (usb 2.5) */ 101 + USB_SPEED_SUPER, /* usb 3.0 */ 102 + USB_SPEED_SUPER_PLUS, /* usb 3.1 */ 100 103 }; 101 104 102 105 /*-------------------------------------------------------------------------*/ ··· 107 104 static char *speed (enum usb_device_speed s) 108 105 { 109 106 switch (s) { 110 - case USB_SPEED_UNKNOWN: return "unknown"; 111 - case USB_SPEED_LOW: return "low"; 112 - case USB_SPEED_FULL: return "full"; 113 - case USB_SPEED_HIGH: return "high"; 114 - default: return "??"; 107 + case USB_SPEED_UNKNOWN: return "unknown"; 108 + case USB_SPEED_LOW: return "low"; 109 + case USB_SPEED_FULL: return "full"; 110 + case USB_SPEED_HIGH: return "high"; 111 + case USB_SPEED_WIRELESS: return "wireless"; 112 + case USB_SPEED_SUPER: return "super"; 113 + case USB_SPEED_SUPER_PLUS: return "super-plus"; 114 + default: return "??"; 115 115 } 116 116 } 117 117