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

Merge tag 'usb-4.19-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb

Pull USB/PHY updates from Greg KH:
"Here is the big USB and phy driver patch set for 4.19-rc1.

Nothing huge but there was a lot of work that happened this
development cycle:

- lots of type-c work, with drivers graduating out of staging, and
displayport support being added.

- new PHY drivers

- the normal collection of gadget driver updates and fixes

- code churn to work on the urb handling path, using irqsave()
everywhere in anticipation of making this codepath a lot simpler in
the future.

- usbserial driver fixes and reworks

- other misc changes

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

* tag 'usb-4.19-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb: (159 commits)
USB: serial: pl2303: add a new device id for ATEN
usb: renesas_usbhs: Kconfig: convert to SPDX identifiers
usb: dwc3: gadget: Check MaxPacketSize from descriptor
usb: dwc2: Turn on uframe_sched on "stm32f4x9_fsotg" platforms
usb: dwc2: Turn on uframe_sched on "amlogic" platforms
usb: dwc2: Turn on uframe_sched on "his" platforms
usb: dwc2: Turn on uframe_sched on "bcm" platforms
usb: dwc2: gadget: ISOC's starting flow improvement
usb: dwc2: Make dwc2_readl/writel functions endianness-agnostic.
usb: dwc3: core: Enable AutoRetry feature in the controller
usb: dwc3: Set default mode for dwc_usb31
usb: gadget: udc: renesas_usb3: Add register of usb role switch
usb: dwc2: replace ioread32/iowrite32_rep with dwc2_readl/writel_rep
usb: dwc2: Modify dwc2_readl/writel functions prototype
usb: dwc3: pci: Intel Merrifield can be host
usb: dwc3: pci: Supply device properties via driver data
arm64: dts: dwc3: description of incr burst type
usb: dwc3: Enable undefined length INCR burst type
usb: dwc3: add global soc bus configuration reg0
usb: dwc3: Describe 'wakeup_work' field of struct dwc3_pci
...

+5849 -1815
+48
Documentation/ABI/obsolete/sysfs-class-typec
··· 1 + These files are deprecated and will be removed. The same files are available 2 + under /sys/bus/typec (see Documentation/ABI/testing/sysfs-bus-typec). 3 + 4 + What: /sys/class/typec/<port|partner|cable>/<dev>/svid 5 + Date: April 2017 6 + Contact: Heikki Krogerus <heikki.krogerus@linux.intel.com> 7 + Description: 8 + The SVID (Standard or Vendor ID) assigned by USB-IF for this 9 + alternate mode. 10 + 11 + What: /sys/class/typec/<port|partner|cable>/<dev>/mode<index>/ 12 + Date: April 2017 13 + Contact: Heikki Krogerus <heikki.krogerus@linux.intel.com> 14 + Description: 15 + Every supported mode will have its own directory. The name of 16 + a mode will be "mode<index>" (for example mode1), where <index> 17 + is the actual index to the mode VDO returned by Discover Modes 18 + USB power delivery command. 19 + 20 + What: /sys/class/typec/<port|partner|cable>/<dev>/mode<index>/description 21 + Date: April 2017 22 + Contact: Heikki Krogerus <heikki.krogerus@linux.intel.com> 23 + Description: 24 + Shows description of the mode. The description is optional for 25 + the drivers, just like with the Billboard Devices. 26 + 27 + What: /sys/class/typec/<port|partner|cable>/<dev>/mode<index>/vdo 28 + Date: April 2017 29 + Contact: Heikki Krogerus <heikki.krogerus@linux.intel.com> 30 + Description: 31 + Shows the VDO in hexadecimal returned by Discover Modes command 32 + for this mode. 33 + 34 + What: /sys/class/typec/<port|partner|cable>/<dev>/mode<index>/active 35 + Date: April 2017 36 + Contact: Heikki Krogerus <heikki.krogerus@linux.intel.com> 37 + Description: 38 + Shows if the mode is active or not. The attribute can be used 39 + for entering/exiting the mode with partners and cable plugs, and 40 + with the port alternate modes it can be used for disabling 41 + support for specific alternate modes. Entering/exiting modes is 42 + supported as synchronous operation so write(2) to the attribute 43 + does not return until the enter/exit mode operation has 44 + finished. The attribute is notified when the mode is 45 + entered/exited so poll(2) on the attribute wakes up. 46 + Entering/exiting a mode will also generate uevent KOBJ_CHANGE. 47 + 48 + Valid values: yes, no
+5
Documentation/ABI/testing/configfs-usb-gadget-uvc
··· 263 263 is connected 264 264 bmInfo - capabilities of this video streaming 265 265 interface 266 + 267 + What: /sys/class/udc/udc.name/device/gadget/video4linux/video.name/function_name 268 + Date: May 2018 269 + KernelVersion: 4.19 270 + Description: UVC configfs function instance name
+51
Documentation/ABI/testing/sysfs-bus-typec
··· 1 + What: /sys/bus/typec/devices/.../active 2 + Date: July 2018 3 + Contact: Heikki Krogerus <heikki.krogerus@linux.intel.com> 4 + Description: 5 + Shows if the mode is active or not. The attribute can be used 6 + for entering/exiting the mode. Entering/exiting modes is 7 + supported as synchronous operation so write(2) to the attribute 8 + does not return until the enter/exit mode operation has 9 + finished. The attribute is notified when the mode is 10 + entered/exited so poll(2) on the attribute wakes up. 11 + Entering/exiting a mode will also generate uevent KOBJ_CHANGE. 12 + 13 + Valid values are boolean. 14 + 15 + What: /sys/bus/typec/devices/.../description 16 + Date: July 2018 17 + Contact: Heikki Krogerus <heikki.krogerus@linux.intel.com> 18 + Description: 19 + Shows description of the mode. The description is optional for 20 + the drivers, just like with the Billboard Devices. 21 + 22 + What: /sys/bus/typec/devices/.../mode 23 + Date: July 2018 24 + Contact: Heikki Krogerus <heikki.krogerus@linux.intel.com> 25 + Description: 26 + The index number of the mode returned by Discover Modes USB 27 + Power Delivery command. Depending on the alternate mode, the 28 + mode index may be significant. 29 + 30 + With some alternate modes (SVIDs), the mode index is assigned 31 + for specific functionality in the specification for that 32 + alternate mode. 33 + 34 + With other alternate modes, the mode index values are not 35 + assigned, and can not be therefore used for identification. When 36 + the mode index is not assigned, identifying the alternate mode 37 + must be done with either mode VDO or the description. 38 + 39 + What: /sys/bus/typec/devices/.../svid 40 + Date: July 2018 41 + Contact: Heikki Krogerus <heikki.krogerus@linux.intel.com> 42 + Description: 43 + The Standard or Vendor ID (SVID) assigned by USB-IF for this 44 + alternate mode. 45 + 46 + What: /sys/bus/typec/devices/.../vdo 47 + Date: July 2018 48 + Contact: Heikki Krogerus <heikki.krogerus@linux.intel.com> 49 + Description: 50 + Shows the VDO in hexadecimal returned by Discover Modes command 51 + for this mode.
+2 -60
Documentation/ABI/testing/sysfs-class-typec
··· 222 222 available. The value can be polled. 223 223 224 224 225 - Alternate Mode devices. 225 + USB Type-C port alternate mode devices. 226 226 227 - The alternate modes will have Standard or Vendor ID (SVID) assigned by USB-IF. 228 - The ports, partners and cable plugs can have alternate modes. A supported SVID 229 - will consist of a set of modes. Every SVID a port/partner/plug supports will 230 - have a device created for it, and every supported mode for a supported SVID will 231 - have its own directory under that device. Below <dev> refers to the device for 232 - the alternate mode. 233 - 234 - What: /sys/class/typec/<port|partner|cable>/<dev>/svid 235 - Date: April 2017 236 - Contact: Heikki Krogerus <heikki.krogerus@linux.intel.com> 237 - Description: 238 - The SVID (Standard or Vendor ID) assigned by USB-IF for this 239 - alternate mode. 240 - 241 - What: /sys/class/typec/<port|partner|cable>/<dev>/mode<index>/ 242 - Date: April 2017 243 - Contact: Heikki Krogerus <heikki.krogerus@linux.intel.com> 244 - Description: 245 - Every supported mode will have its own directory. The name of 246 - a mode will be "mode<index>" (for example mode1), where <index> 247 - is the actual index to the mode VDO returned by Discover Modes 248 - USB power delivery command. 249 - 250 - What: /sys/class/typec/<port|partner|cable>/<dev>/mode<index>/description 251 - Date: April 2017 252 - Contact: Heikki Krogerus <heikki.krogerus@linux.intel.com> 253 - Description: 254 - Shows description of the mode. The description is optional for 255 - the drivers, just like with the Billboard Devices. 256 - 257 - What: /sys/class/typec/<port|partner|cable>/<dev>/mode<index>/vdo 258 - Date: April 2017 259 - Contact: Heikki Krogerus <heikki.krogerus@linux.intel.com> 260 - Description: 261 - Shows the VDO in hexadecimal returned by Discover Modes command 262 - for this mode. 263 - 264 - What: /sys/class/typec/<port|partner|cable>/<dev>/mode<index>/active 265 - Date: April 2017 266 - Contact: Heikki Krogerus <heikki.krogerus@linux.intel.com> 267 - Description: 268 - Shows if the mode is active or not. The attribute can be used 269 - for entering/exiting the mode with partners and cable plugs, and 270 - with the port alternate modes it can be used for disabling 271 - support for specific alternate modes. Entering/exiting modes is 272 - supported as synchronous operation so write(2) to the attribute 273 - does not return until the enter/exit mode operation has 274 - finished. The attribute is notified when the mode is 275 - entered/exited so poll(2) on the attribute wakes up. 276 - Entering/exiting a mode will also generate uevent KOBJ_CHANGE. 277 - 278 - Valid values: yes, no 279 - 280 - What: /sys/class/typec/<port>/<dev>/mode<index>/supported_roles 227 + What: /sys/class/typec/<port>/<alt mode>/supported_roles 281 228 Date: April 2017 282 229 Contact: Heikki Krogerus <heikki.krogerus@linux.intel.com> 283 230 Description: 284 231 Space separated list of the supported roles. 285 - 286 - This attribute is available for the devices describing the 287 - alternate modes a port supports, and it will not be exposed with 288 - the devices presenting the alternate modes the partners or cable 289 - plugs support. 290 232 291 233 Valid values: source, sink
+49
Documentation/ABI/testing/sysfs-driver-typec-displayport
··· 1 + What: /sys/bus/typec/devices/.../displayport/configuration 2 + Date: July 2018 3 + Contact: Heikki Krogerus <heikki.krogerus@linux.intel.com> 4 + Description: 5 + Shows the current DisplayPort configuration for the connector. 6 + Valid values are USB, source and sink. Source means DisplayPort 7 + source, and sink means DisplayPort sink. 8 + 9 + All supported configurations are listed as space separated list 10 + with the active one wrapped in square brackets. 11 + 12 + Source example: 13 + 14 + USB [source] sink 15 + 16 + The configuration can be changed by writing to the file 17 + 18 + Note. USB configuration does not equal to Exit Mode. It is 19 + separate configuration defined in VESA DisplayPort Alt Mode on 20 + USB Type-C Standard. Functionally it equals to the situation 21 + where the mode has been exited (to exit the mode, see 22 + Documentation/ABI/testing/sysfs-bus-typec, and use file 23 + /sys/bus/typec/devices/.../active). 24 + 25 + What: /sys/bus/typec/devices/.../displayport/pin_assignment 26 + Date: July 2018 27 + Contact: Heikki Krogerus <heikki.krogerus@linux.intel.com> 28 + Description: 29 + VESA DisplayPort Alt Mode on USB Type-C Standard defines six 30 + different pin assignments for USB Type-C connector that are 31 + labeled A, B, C, D, E, and F. The supported pin assignments are 32 + listed as space separated list with the active one wrapped in 33 + square brackets. 34 + 35 + Example: 36 + 37 + C [D] 38 + 39 + Pin assignment can be changed by writing to the file. It is 40 + possible to set pin assignment before configuration has been 41 + set, but the assignment will not be active before the 42 + connector is actually configured. 43 + 44 + Note. As of VESA DisplayPort Alt Mode on USB Type-C Standard 45 + version 1.0b, pin assignments A, B, and F are deprecated. Only 46 + pin assignment D can now carry simultaneously one channel of 47 + USB SuperSpeed protocol. From user perspective pin assignments C 48 + and E are equal, where all channels on the connector are used 49 + for carrying DisplayPort protocol (allowing higher resolutions).
+44
Documentation/devicetree/bindings/connector/usb-connector.txt
··· 15 15 - type: size of the connector, should be specified in case of USB-A, USB-B 16 16 non-fullsize connectors: "mini", "micro". 17 17 18 + Optional properties for usb-c-connector: 19 + - power-role: should be one of "source", "sink" or "dual"(DRP) if typec 20 + connector has power support. 21 + - try-power-role: preferred power role if "dual"(DRP) can support Try.SNK 22 + or Try.SRC, should be "sink" for Try.SNK or "source" for Try.SRC. 23 + - data-role: should be one of "host", "device", "dual"(DRD) if typec 24 + connector supports USB data. 25 + 26 + Required properties for usb-c-connector with power delivery support: 27 + - source-pdos: An array of u32 with each entry providing supported power 28 + source data object(PDO), the detailed bit definitions of PDO can be found 29 + in "Universal Serial Bus Power Delivery Specification" chapter 6.4.1.2 30 + Source_Capabilities Message, the order of each entry(PDO) should follow 31 + the PD spec chapter 6.4.1. Required for power source and power dual role. 32 + User can specify the source PDO array via PDO_FIXED/BATT/VAR() defined in 33 + dt-bindings/usb/pd.h. 34 + - sink-pdos: An array of u32 with each entry providing supported power 35 + sink data object(PDO), the detailed bit definitions of PDO can be found 36 + in "Universal Serial Bus Power Delivery Specification" chapter 6.4.1.3 37 + Sink Capabilities Message, the order of each entry(PDO) should follow 38 + the PD spec chapter 6.4.1. Required for power sink and power dual role. 39 + User can specify the sink PDO array via PDO_FIXED/BATT/VAR() defined in 40 + dt-bindings/usb/pd.h. 41 + - op-sink-microwatt: Sink required operating power in microwatt, if source 42 + can't offer the power, Capability Mismatch is set. Required for power 43 + sink and power dual role. 44 + 18 45 Required nodes: 19 46 - any data bus to the connector should be modeled using the OF graph bindings 20 47 specified in bindings/graph.txt, unless the bus is between parent node and ··· 98 71 }; 99 72 }; 100 73 }; 74 + }; 75 + }; 76 + 77 + 3. USB-C connector attached to a typec port controller(ptn5110), which has 78 + power delivery support and enables drp. 79 + 80 + typec: ptn5110@50 { 81 + ... 82 + usb_con: connector { 83 + compatible = "usb-c-connector"; 84 + label = "USB-C"; 85 + power-role = "dual"; 86 + try-power-role = "sink"; 87 + source-pdos = <PDO_FIXED(5000, 2000, PDO_FIXED_USB_COMM)>; 88 + sink-pdos = <PDO_FIXED(5000, 2000, PDO_FIXED_USB_COMM) 89 + PDO_VAR(5000, 12000, 2000)>; 90 + op-sink-microwatt = <10000000>; 101 91 }; 102 92 };
+41
Documentation/devicetree/bindings/phy/brcm,sr-pcie-phy.txt
··· 1 + Broadcom Stingray PCIe PHY 2 + 3 + Required properties: 4 + - compatible: must be "brcm,sr-pcie-phy" 5 + - reg: base address and length of the PCIe SS register space 6 + - brcm,sr-cdru: phandle to the CDRU syscon node 7 + - brcm,sr-mhb: phandle to the MHB syscon node 8 + - #phy-cells: Must be 1, denotes the PHY index 9 + 10 + For PAXB based root complex, one can have a configuration of up to 8 PHYs 11 + PHY index goes from 0 to 7 12 + 13 + For the internal PAXC based root complex, PHY index is always 8 14 + 15 + Example: 16 + mhb: syscon@60401000 { 17 + compatible = "brcm,sr-mhb", "syscon"; 18 + reg = <0 0x60401000 0 0x38c>; 19 + }; 20 + 21 + cdru: syscon@6641d000 { 22 + compatible = "brcm,sr-cdru", "syscon"; 23 + reg = <0 0x6641d000 0 0x400>; 24 + }; 25 + 26 + pcie_phy: phy@40000000 { 27 + compatible = "brcm,sr-pcie-phy"; 28 + reg = <0 0x40000000 0 0x800>; 29 + brcm,sr-cdru = <&cdru>; 30 + brcm,sr-mhb = <&mhb>; 31 + #phy-cells = <1>; 32 + }; 33 + 34 + /* users of the PCIe PHY */ 35 + 36 + pcie0: pcie@48000000 { 37 + ... 38 + ... 39 + phys = <&pcie_phy 0>; 40 + phy-names = "pcie-phy"; 41 + };
+6
Documentation/devicetree/bindings/phy/phy-mtk-tphy.txt
··· 47 47 - PHY_TYPE_PCIE 48 48 - PHY_TYPE_SATA 49 49 50 + Optional properties (PHY_TYPE_USB2 port (child) node): 51 + - mediatek,eye-src : u32, the value of slew rate calibrate 52 + - mediatek,eye-vrt : u32, the selection of VRT reference voltage 53 + - mediatek,eye-term : u32, the selection of HS_TX TERM reference voltage 54 + - mediatek,bc12 : bool, enable BC12 of u2phy if support it 55 + 50 56 Example: 51 57 52 58 u3phy: usb-phy@11290000 {
+12 -2
Documentation/devicetree/bindings/phy/qcom-qmp-phy.txt
··· 12 12 "qcom,sdm845-qmp-usb3-phy" for USB3 QMP V3 phy on sdm845, 13 13 "qcom,sdm845-qmp-usb3-uni-phy" for USB3 QMP V3 UNI phy on sdm845. 14 14 15 - - reg: offset and length of register set for PHY's common serdes block. 15 + - reg: 16 + - For "qcom,sdm845-qmp-usb3-phy": 17 + - index 0: address and length of register set for PHY's common serdes 18 + block. 19 + - named register "dp_com" (using reg-names): address and length of the 20 + DP_COM control block. 21 + - For all others: 22 + - offset and length of register set for PHY's common serdes block. 16 23 17 24 - #clock-cells: must be 1 18 25 - Phy pll outputs a bunch of clocks for Tx, Rx and Pipe ··· 67 60 68 61 Required properties for child node: 69 62 - reg: list of offset and length pairs of register sets for PHY blocks - 70 - tx, rx and pcs. 63 + - index 0: tx 64 + - index 1: rx 65 + - index 2: pcs 66 + - index 3: pcs_misc (optional) 71 67 72 68 - #phy-cells: must be 0 73 69
+24
Documentation/devicetree/bindings/phy/rcar-gen3-phy-pcie.txt
··· 1 + * Renesas R-Car generation 3 PCIe PHY 2 + 3 + This file provides information on what the device node for the R-Car 4 + generation 3 PCIe PHY contains. 5 + 6 + Required properties: 7 + - compatible: "renesas,r8a77980-pcie-phy" if the device is a part of the 8 + R8A77980 SoC. 9 + - reg: offset and length of the register block. 10 + - clocks: clock phandle and specifier pair. 11 + - power-domains: power domain phandle and specifier pair. 12 + - resets: reset phandle and specifier pair. 13 + - #phy-cells: see phy-bindings.txt in the same directory, must be <0>. 14 + 15 + Example (R-Car V3H): 16 + 17 + pcie-phy@e65d0000 { 18 + compatible = "renesas,r8a77980-pcie-phy"; 19 + reg = <0 0xe65d0000 0 0x8000>; 20 + #phy-cells = <0>; 21 + clocks = <&cpg CPG_MOD 319>; 22 + power-domains = <&sysc 32>; 23 + resets = <&cpg 319>; 24 + };
+2
Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt
··· 10 10 SoC. 11 11 "renesas,usb2-phy-r8a77965" if the device is a part of an 12 12 R8A77965 SoC. 13 + "renesas,usb2-phy-r8a77990" if the device is a part of an 14 + R8A77990 SoC. 13 15 "renesas,usb2-phy-r8a77995" if the device is a part of an 14 16 R8A77995 SoC. 15 17 "renesas,rcar-gen3-usb2-phy" for a generic R-Car Gen3 compatible device.
+6
Documentation/devicetree/bindings/usb/dwc3.txt
··· 96 96 enable periodic ESS TX threshold. 97 97 98 98 - <DEPRECATED> tx-fifo-resize: determines if the FIFO *has* to be reallocated. 99 + - snps,incr-burst-type-adjustment: Value for INCR burst type of GSBUSCFG0 100 + register, undefined length INCR burst type enable and INCRx type. 101 + When just one value, which means INCRX burst mode enabled. When 102 + more than one value, which means undefined length INCR burst type 103 + enabled. The values can be 1, 4, 8, 16, 32, 64, 128 and 256. 99 104 100 105 - in addition all properties from usb-xhci.txt from the current directory are 101 106 supported as well ··· 113 108 reg = <0x4a030000 0xcfff>; 114 109 interrupts = <0 92 4> 115 110 usb-phy = <&usb2_phy>, <&usb3,phy>; 111 + snps,incr-burst-type-adjustment = <1>, <4>, <8>, <16>; 116 112 };
+18
Documentation/devicetree/bindings/usb/npcm7xx-usb.txt
··· 1 + Nuvoton NPCM7XX SoC USB controllers: 2 + ----------------------------- 3 + 4 + EHCI: 5 + ----- 6 + 7 + Required properties: 8 + - compatible: "nuvoton,npcm750-ehci" 9 + - interrupts: Should contain the EHCI interrupt 10 + - reg: Physical address and length of the register set for the device 11 + 12 + Example: 13 + 14 + ehci1: usb@f0806000 { 15 + compatible = "nuvoton,npcm750-ehci"; 16 + reg = <0xf0806000 0x1000>; 17 + interrupts = <0 61 4>; 18 + };
+49
Documentation/devicetree/bindings/usb/typec-tcpci.txt
··· 1 + TCPCI(Typec port cotroller interface) binding 2 + --------------------------------------------- 3 + 4 + Required properties: 5 + - compatible: should be set one of following: 6 + - "nxp,ptn5110" for NXP USB PD TCPC PHY IC ptn5110. 7 + 8 + - reg: the i2c slave address of typec port controller device. 9 + - interrupt-parent: the phandle to the interrupt controller which provides 10 + the interrupt. 11 + - interrupts: interrupt specification for tcpci alert. 12 + 13 + Required sub-node: 14 + - connector: The "usb-c-connector" attached to the tcpci chip, the bindings 15 + of connector node are specified in 16 + Documentation/devicetree/bindings/connector/usb-connector.txt 17 + 18 + Example: 19 + 20 + ptn5110@50 { 21 + compatible = "nxp,ptn5110"; 22 + reg = <0x50>; 23 + interrupt-parent = <&gpio3>; 24 + interrupts = <3 IRQ_TYPE_LEVEL_LOW>; 25 + 26 + usb_con: connector { 27 + compatible = "usb-c-connector"; 28 + label = "USB-C"; 29 + data-role = "dual"; 30 + power-role = "dual"; 31 + try-power-role = "sink"; 32 + source-pdos = <PDO_FIXED(5000, 2000, PDO_FIXED_USB_COMM)>; 33 + sink-pdos = <PDO_FIXED(5000, 2000, PDO_FIXED_USB_COMM) 34 + PDO_VAR(5000, 12000, 2000)>; 35 + op-sink-microwatt = <10000000>; 36 + 37 + ports { 38 + #address-cells = <1>; 39 + #size-cells = <0>; 40 + 41 + port@1 { 42 + reg = <1>; 43 + usb_con_ss: endpoint { 44 + remote-endpoint = <&usb3_data_ss>; 45 + }; 46 + }; 47 + }; 48 + }; 49 + };
+1
Documentation/devicetree/bindings/usb/usb-xhci.txt
··· 14 14 - "renesas,xhci-r8a7795" for r8a7795 SoC 15 15 - "renesas,xhci-r8a7796" for r8a7796 SoC 16 16 - "renesas,xhci-r8a77965" for r8a77965 SoC 17 + - "renesas,xhci-r8a77990" for r8a77990 SoC 17 18 - "renesas,rcar-gen2-xhci" for a generic R-Car Gen2 or RZ/G1 compatible 18 19 device 19 20 - "renesas,rcar-gen3-xhci" for a generic R-Car Gen3 compatible device
+136
Documentation/driver-api/usb/typec_bus.rst
··· 1 + 2 + API for USB Type-C Alternate Mode drivers 3 + ========================================= 4 + 5 + Introduction 6 + ------------ 7 + 8 + Alternate modes require communication with the partner using Vendor Defined 9 + Messages (VDM) as defined in USB Type-C and USB Power Delivery Specifications. 10 + The communication is SVID (Standard or Vendor ID) specific, i.e. specific for 11 + every alternate mode, so every alternate mode will need a custom driver. 12 + 13 + USB Type-C bus allows binding a driver to the discovered partner alternate 14 + modes by using the SVID and the mode number. 15 + 16 + USB Type-C Connector Class provides a device for every alternate mode a port 17 + supports, and separate device for every alternate mode the partner supports. 18 + The drivers for the alternate modes are bound to the partner alternate mode 19 + devices, and the port alternate mode devices must be handled by the port 20 + drivers. 21 + 22 + When a new partner alternate mode device is registered, it is linked to the 23 + alternate mode device of the port that the partner is attached to, that has 24 + matching SVID and mode. Communication between the port driver and alternate mode 25 + driver will happen using the same API. 26 + 27 + The port alternate mode devices are used as a proxy between the partner and the 28 + alternate mode drivers, so the port drivers are only expected to pass the SVID 29 + specific commands from the alternate mode drivers to the partner, and from the 30 + partners to the alternate mode drivers. No direct SVID specific communication is 31 + needed from the port drivers, but the port drivers need to provide the operation 32 + callbacks for the port alternate mode devices, just like the alternate mode 33 + drivers need to provide them for the partner alternate mode devices. 34 + 35 + Usage: 36 + ------ 37 + 38 + General 39 + ~~~~~~~ 40 + 41 + By default, the alternate mode drivers are responsible for entering the mode. 42 + It is also possible to leave the decision about entering the mode to the user 43 + space (See Documentation/ABI/testing/sysfs-class-typec). Port drivers should not 44 + enter any modes on their own. 45 + 46 + ``->vdm`` is the most important callback in the operation callbacks vector. It 47 + will be used to deliver all the SVID specific commands from the partner to the 48 + alternate mode driver, and vice versa in case of port drivers. The drivers send 49 + the SVID specific commands to each other using :c:func:`typec_altmode_vmd()`. 50 + 51 + If the communication with the partner using the SVID specific commands results 52 + in need to reconfigure the pins on the connector, the alternate mode driver 53 + needs to notify the bus using :c:func:`typec_altmode_notify()`. The driver 54 + passes the negotiated SVID specific pin configuration value to the function as 55 + parameter. The bus driver will then configure the mux behind the connector using 56 + that value as the state value for the mux, and also call blocking notification 57 + chain to notify the external drivers about the state of the connector that need 58 + to know it. 59 + 60 + NOTE: The SVID specific pin configuration values must always start from 61 + ``TYPEC_STATE_MODAL``. USB Type-C specification defines two default states for 62 + the connector: ``TYPEC_STATE_USB`` and ``TYPEC_STATE_SAFE``. These values are 63 + reserved by the bus as the first possible values for the state. When the 64 + alternate mode is entered, the bus will put the connector into 65 + ``TYPEC_STATE_SAFE`` before sending Enter or Exit Mode command as defined in USB 66 + Type-C Specification, and also put the connector back to ``TYPEC_STATE_USB`` 67 + after the mode has been exited. 68 + 69 + An example of working definitions for SVID specific pin configurations would 70 + look like this: 71 + 72 + enum { 73 + ALTMODEX_CONF_A = TYPEC_STATE_MODAL, 74 + ALTMODEX_CONF_B, 75 + ... 76 + }; 77 + 78 + Helper macro ``TYPEC_MODAL_STATE()`` can also be used: 79 + 80 + #define ALTMODEX_CONF_A = TYPEC_MODAL_STATE(0); 81 + #define ALTMODEX_CONF_B = TYPEC_MODAL_STATE(1); 82 + 83 + Notification chain 84 + ~~~~~~~~~~~~~~~~~~ 85 + 86 + The drivers for the components that the alternate modes are designed for need to 87 + get details regarding the results of the negotiation with the partner, and the 88 + pin configuration of the connector. In case of DisplayPort alternate mode for 89 + example, the GPU drivers will need to know those details. In case of 90 + Thunderbolt alternate mode, the thunderbolt drivers will need to know them, and 91 + so on. 92 + 93 + The notification chain is designed for this purpose. The drivers can register 94 + notifiers with :c:func:`typec_altmode_register_notifier()`. 95 + 96 + Cable plug alternate modes 97 + ~~~~~~~~~~~~~~~~~~~~~~~~~~ 98 + 99 + The alternate mode drivers are not bound to cable plug alternate mode devices, 100 + only to the partner alternate mode devices. If the alternate mode supports, or 101 + requires, a cable that responds to SOP Prime, and optionally SOP Double Prime 102 + messages, the driver for that alternate mode must request handle to the cable 103 + plug alternate modes using :c:func:`typec_altmode_get_plug()`, and take over 104 + their control. 105 + 106 + Driver API 107 + ---------- 108 + 109 + Alternate mode driver registering/unregistering 110 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 111 + 112 + .. kernel-doc:: drivers/usb/typec/bus.c 113 + :functions: typec_altmode_register_driver typec_altmode_unregister_driver 114 + 115 + Alternate mode driver operations 116 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 117 + 118 + .. kernel-doc:: drivers/usb/typec/bus.c 119 + :functions: typec_altmode_enter typec_altmode_exit typec_altmode_attention typec_altmode_vdm typec_altmode_notify 120 + 121 + API for the port drivers 122 + ~~~~~~~~~~~~~~~~~~~~~~~~ 123 + 124 + .. kernel-doc:: drivers/usb/typec/bus.c 125 + :functions: typec_match_altmode 126 + 127 + Cable Plug operations 128 + ~~~~~~~~~~~~~~~~~~~~~ 129 + 130 + .. kernel-doc:: drivers/usb/typec/bus.c 131 + :functions: typec_altmode_get_plug typec_altmode_put_plug 132 + 133 + Notifications 134 + ~~~~~~~~~~~~~ 135 + .. kernel-doc:: drivers/usb/typec/class.c 136 + :functions: typec_altmode_register_notifier typec_altmode_unregister_notifier
-9
Documentation/usb/usb-serial.txt
··· 418 418 why it is wise to cut down on the rate used is wise for large 419 419 transfers until this is settled. 420 420 421 - Options supported: 422 - If this driver is compiled as a module you can pass the following 423 - options to it: 424 - debug - extra verbose debugging info 425 - (default: 0; nonzero enables) 426 - use_lowlatency - use low_latency flag to speed up tty layer 427 - when reading from the device. 428 - (default: 0; nonzero enables) 429 - 430 421 See http://www.uuhaus.de/linux/palmconnect.html for up-to-date 431 422 information on this driver. 432 423
+13 -2
MAINTAINERS
··· 1665 1665 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 1666 1666 L: linux-mediatek@lists.infradead.org (moderated for non-subscribers) 1667 1667 S: Maintained 1668 - F: drivers/phy/mediatek/phy-mtk-tphy.c 1668 + F: drivers/phy/mediatek/ 1669 + F: Documentation/devicetree/bindings/phy/phy-mtk-* 1669 1670 1670 1671 ARM/MICREL KS8695 ARCHITECTURE 1671 1672 M: Greg Ungerer <gerg@uclinux.org> ··· 15118 15117 S: Maintained 15119 15118 F: drivers/usb/typec/mux/pi3usb30532.c 15120 15119 15121 - USB TYPEC SUBSYSTEM 15120 + USB TYPEC CLASS 15122 15121 M: Heikki Krogerus <heikki.krogerus@linux.intel.com> 15123 15122 L: linux-usb@vger.kernel.org 15124 15123 S: Maintained ··· 15126 15125 F: Documentation/driver-api/usb/typec.rst 15127 15126 F: drivers/usb/typec/ 15128 15127 F: include/linux/usb/typec.h 15128 + 15129 + USB TYPEC BUS FOR ALTERNATE MODES 15130 + M: Heikki Krogerus <heikki.krogerus@linux.intel.com> 15131 + L: linux-usb@vger.kernel.org 15132 + S: Maintained 15133 + F: Documentation/ABI/testing/sysfs-bus-typec 15134 + F: Documentation/driver-api/usb/typec_bus.rst 15135 + F: drivers/usb/typec/altmodes/ 15136 + F: include/linux/usb/typec_altmode.h 15129 15137 15130 15138 USB UHCI DRIVER 15131 15139 M: Alan Stern <stern@rowland.harvard.edu> ··· 15166 15156 S: Maintained 15167 15157 F: drivers/usb/gadget/function/*uvc* 15168 15158 F: drivers/usb/gadget/legacy/webcam.c 15159 + F: include/uapi/linux/usb/g_uvc.h 15169 15160 15170 15161 USB WIRELESS RNDIS DRIVER (rndis_wlan) 15171 15162 M: Jussi Kivilinna <jussi.kivilinna@iki.fi>
+3 -2
drivers/nfc/nfcmrvl/usb.c
··· 160 160 struct nci_dev *ndev = (struct nci_dev *)skb->dev; 161 161 struct nfcmrvl_private *priv = nci_get_drvdata(ndev); 162 162 struct nfcmrvl_usb_drv_data *drv_data = priv->drv_data; 163 + unsigned long flags; 163 164 164 165 nfc_info(priv->dev, "urb %p status %d count %d\n", 165 166 urb, urb->status, urb->actual_length); 166 167 167 - spin_lock(&drv_data->txlock); 168 + spin_lock_irqsave(&drv_data->txlock, flags); 168 169 drv_data->tx_in_flight--; 169 - spin_unlock(&drv_data->txlock); 170 + spin_unlock_irqrestore(&drv_data->txlock, flags); 170 171 171 172 kfree(urb->setup_packet); 172 173 kfree_skb(skb);
+10
drivers/phy/broadcom/Kconfig
··· 80 80 This driver is required by the USB XHCI, EHCI and OHCI 81 81 drivers. 82 82 If unsure, say N. 83 + 84 + config PHY_BCM_SR_PCIE 85 + tristate "Broadcom Stingray PCIe PHY driver" 86 + depends on OF && (ARCH_BCM_IPROC || COMPILE_TEST) 87 + select GENERIC_PHY 88 + select MFD_SYSCON 89 + default ARCH_BCM_IPROC 90 + help 91 + Enable this to support the Broadcom Stingray PCIe PHY 92 + If unsure, say N.
+2
drivers/phy/broadcom/Makefile
··· 9 9 obj-$(CONFIG_PHY_BRCM_USB) += phy-brcm-usb-dvr.o 10 10 11 11 phy-brcm-usb-dvr-objs := phy-brcm-usb.o phy-brcm-usb-init.o 12 + 13 + obj-$(CONFIG_PHY_BCM_SR_PCIE) += phy-bcm-sr-pcie.o
+305
drivers/phy/broadcom/phy-bcm-sr-pcie.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * Copyright (C) 2016-2018 Broadcom 4 + */ 5 + 6 + #include <linux/clk.h> 7 + #include <linux/delay.h> 8 + #include <linux/io.h> 9 + #include <linux/module.h> 10 + #include <linux/mfd/syscon.h> 11 + #include <linux/of.h> 12 + #include <linux/phy/phy.h> 13 + #include <linux/platform_device.h> 14 + #include <linux/regmap.h> 15 + 16 + /* we have up to 8 PAXB based RC. The 9th one is always PAXC */ 17 + #define SR_NR_PCIE_PHYS 9 18 + #define SR_PAXC_PHY_IDX (SR_NR_PCIE_PHYS - 1) 19 + 20 + #define PCIE_PIPEMUX_CFG_OFFSET 0x10c 21 + #define PCIE_PIPEMUX_SELECT_STRAP 0xf 22 + 23 + #define CDRU_STRAP_DATA_LSW_OFFSET 0x5c 24 + #define PCIE_PIPEMUX_SHIFT 19 25 + #define PCIE_PIPEMUX_MASK 0xf 26 + 27 + #define MHB_MEM_PW_PAXC_OFFSET 0x1c0 28 + #define MHB_PWR_ARR_POWERON 0x8 29 + #define MHB_PWR_ARR_POWEROK 0x4 30 + #define MHB_PWR_POWERON 0x2 31 + #define MHB_PWR_POWEROK 0x1 32 + #define MHB_PWR_STATUS_MASK (MHB_PWR_ARR_POWERON | \ 33 + MHB_PWR_ARR_POWEROK | \ 34 + MHB_PWR_POWERON | \ 35 + MHB_PWR_POWEROK) 36 + 37 + struct sr_pcie_phy_core; 38 + 39 + /** 40 + * struct sr_pcie_phy - Stingray PCIe PHY 41 + * 42 + * @core: pointer to the Stingray PCIe PHY core control 43 + * @index: PHY index 44 + * @phy: pointer to the kernel PHY device 45 + */ 46 + struct sr_pcie_phy { 47 + struct sr_pcie_phy_core *core; 48 + unsigned int index; 49 + struct phy *phy; 50 + }; 51 + 52 + /** 53 + * struct sr_pcie_phy_core - Stingray PCIe PHY core control 54 + * 55 + * @dev: pointer to device 56 + * @base: base register of PCIe SS 57 + * @cdru: regmap to the CDRU device 58 + * @mhb: regmap to the MHB device 59 + * @pipemux: pipemuex strap 60 + * @phys: array of PCIe PHYs 61 + */ 62 + struct sr_pcie_phy_core { 63 + struct device *dev; 64 + void __iomem *base; 65 + struct regmap *cdru; 66 + struct regmap *mhb; 67 + u32 pipemux; 68 + struct sr_pcie_phy phys[SR_NR_PCIE_PHYS]; 69 + }; 70 + 71 + /* 72 + * PCIe PIPEMUX lookup table 73 + * 74 + * Each array index represents a PIPEMUX strap setting 75 + * The array element represents a bitmap where a set bit means the PCIe 76 + * core and associated serdes has been enabled as RC and is available for use 77 + */ 78 + static const u8 pipemux_table[] = { 79 + /* PIPEMUX = 0, EP 1x16 */ 80 + 0x00, 81 + /* PIPEMUX = 1, EP 2x8 */ 82 + 0x00, 83 + /* PIPEMUX = 2, EP 4x4 */ 84 + 0x00, 85 + /* PIPEMUX = 3, RC 2x8, cores 0, 7 */ 86 + 0x81, 87 + /* PIPEMUX = 4, RC 4x4, cores 0, 1, 6, 7 */ 88 + 0xc3, 89 + /* PIPEMUX = 5, RC 8x2, all 8 cores */ 90 + 0xff, 91 + /* PIPEMUX = 6, RC 3x4 + 2x2, cores 0, 2, 3, 6, 7 */ 92 + 0xcd, 93 + /* PIPEMUX = 7, RC 1x4 + 6x2, cores 0, 2, 3, 4, 5, 6, 7 */ 94 + 0xfd, 95 + /* PIPEMUX = 8, EP 1x8 + RC 4x2, cores 4, 5, 6, 7 */ 96 + 0xf0, 97 + /* PIPEMUX = 9, EP 1x8 + RC 2x4, cores 6, 7 */ 98 + 0xc0, 99 + /* PIPEMUX = 10, EP 2x4 + RC 2x4, cores 1, 6 */ 100 + 0x42, 101 + /* PIPEMUX = 11, EP 2x4 + RC 4x2, cores 2, 3, 4, 5 */ 102 + 0x3c, 103 + /* PIPEMUX = 12, EP 1x4 + RC 6x2, cores 2, 3, 4, 5, 6, 7 */ 104 + 0xfc, 105 + /* PIPEMUX = 13, RC 2x4 + RC 1x4 + 2x2, cores 2, 3, 6 */ 106 + 0x4c, 107 + }; 108 + 109 + /* 110 + * Return true if the strap setting is valid 111 + */ 112 + static bool pipemux_strap_is_valid(u32 pipemux) 113 + { 114 + return !!(pipemux < ARRAY_SIZE(pipemux_table)); 115 + } 116 + 117 + /* 118 + * Read the PCIe PIPEMUX from strap 119 + */ 120 + static u32 pipemux_strap_read(struct sr_pcie_phy_core *core) 121 + { 122 + u32 pipemux; 123 + 124 + /* 125 + * Read PIPEMUX configuration register to determine the pipemux setting 126 + * 127 + * In the case when the value indicates using HW strap, fall back to 128 + * use HW strap 129 + */ 130 + pipemux = readl(core->base + PCIE_PIPEMUX_CFG_OFFSET); 131 + pipemux &= PCIE_PIPEMUX_MASK; 132 + if (pipemux == PCIE_PIPEMUX_SELECT_STRAP) { 133 + regmap_read(core->cdru, CDRU_STRAP_DATA_LSW_OFFSET, &pipemux); 134 + pipemux >>= PCIE_PIPEMUX_SHIFT; 135 + pipemux &= PCIE_PIPEMUX_MASK; 136 + } 137 + 138 + return pipemux; 139 + } 140 + 141 + /* 142 + * Given a PIPEMUX strap and PCIe core index, this function returns true if the 143 + * PCIe core needs to be enabled 144 + */ 145 + static bool pcie_core_is_for_rc(struct sr_pcie_phy *phy) 146 + { 147 + struct sr_pcie_phy_core *core = phy->core; 148 + unsigned int core_idx = phy->index; 149 + 150 + return !!((pipemux_table[core->pipemux] >> core_idx) & 0x1); 151 + } 152 + 153 + static int sr_pcie_phy_init(struct phy *p) 154 + { 155 + struct sr_pcie_phy *phy = phy_get_drvdata(p); 156 + 157 + /* 158 + * Check whether this PHY is for root complex or not. If yes, return 159 + * zero so the host driver can proceed to enumeration. If not, return 160 + * an error and that will force the host driver to bail out 161 + */ 162 + if (pcie_core_is_for_rc(phy)) 163 + return 0; 164 + 165 + return -ENODEV; 166 + } 167 + 168 + static int sr_paxc_phy_init(struct phy *p) 169 + { 170 + struct sr_pcie_phy *phy = phy_get_drvdata(p); 171 + struct sr_pcie_phy_core *core = phy->core; 172 + unsigned int core_idx = phy->index; 173 + u32 val; 174 + 175 + if (core_idx != SR_PAXC_PHY_IDX) 176 + return -EINVAL; 177 + 178 + regmap_read(core->mhb, MHB_MEM_PW_PAXC_OFFSET, &val); 179 + if ((val & MHB_PWR_STATUS_MASK) != MHB_PWR_STATUS_MASK) { 180 + dev_err(core->dev, "PAXC is not powered up\n"); 181 + return -ENODEV; 182 + } 183 + 184 + return 0; 185 + } 186 + 187 + static const struct phy_ops sr_pcie_phy_ops = { 188 + .init = sr_pcie_phy_init, 189 + .owner = THIS_MODULE, 190 + }; 191 + 192 + static const struct phy_ops sr_paxc_phy_ops = { 193 + .init = sr_paxc_phy_init, 194 + .owner = THIS_MODULE, 195 + }; 196 + 197 + static struct phy *sr_pcie_phy_xlate(struct device *dev, 198 + struct of_phandle_args *args) 199 + { 200 + struct sr_pcie_phy_core *core; 201 + int phy_idx; 202 + 203 + core = dev_get_drvdata(dev); 204 + if (!core) 205 + return ERR_PTR(-EINVAL); 206 + 207 + phy_idx = args->args[0]; 208 + 209 + if (WARN_ON(phy_idx >= SR_NR_PCIE_PHYS)) 210 + return ERR_PTR(-ENODEV); 211 + 212 + return core->phys[phy_idx].phy; 213 + } 214 + 215 + static int sr_pcie_phy_probe(struct platform_device *pdev) 216 + { 217 + struct device *dev = &pdev->dev; 218 + struct device_node *node = dev->of_node; 219 + struct sr_pcie_phy_core *core; 220 + struct resource *res; 221 + struct phy_provider *provider; 222 + unsigned int phy_idx = 0; 223 + 224 + core = devm_kzalloc(dev, sizeof(*core), GFP_KERNEL); 225 + if (!core) 226 + return -ENOMEM; 227 + 228 + core->dev = dev; 229 + 230 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 231 + core->base = devm_ioremap_resource(core->dev, res); 232 + if (IS_ERR(core->base)) 233 + return PTR_ERR(core->base); 234 + 235 + core->cdru = syscon_regmap_lookup_by_phandle(node, "brcm,sr-cdru"); 236 + if (IS_ERR(core->cdru)) { 237 + dev_err(core->dev, "unable to find CDRU device\n"); 238 + return PTR_ERR(core->cdru); 239 + } 240 + 241 + core->mhb = syscon_regmap_lookup_by_phandle(node, "brcm,sr-mhb"); 242 + if (IS_ERR(core->mhb)) { 243 + dev_err(core->dev, "unable to find MHB device\n"); 244 + return PTR_ERR(core->mhb); 245 + } 246 + 247 + /* read the PCIe PIPEMUX strap setting */ 248 + core->pipemux = pipemux_strap_read(core); 249 + if (!pipemux_strap_is_valid(core->pipemux)) { 250 + dev_err(core->dev, "invalid PCIe PIPEMUX strap %u\n", 251 + core->pipemux); 252 + return -EIO; 253 + } 254 + 255 + for (phy_idx = 0; phy_idx < SR_NR_PCIE_PHYS; phy_idx++) { 256 + struct sr_pcie_phy *p = &core->phys[phy_idx]; 257 + const struct phy_ops *ops; 258 + 259 + if (phy_idx == SR_PAXC_PHY_IDX) 260 + ops = &sr_paxc_phy_ops; 261 + else 262 + ops = &sr_pcie_phy_ops; 263 + 264 + p->phy = devm_phy_create(dev, NULL, ops); 265 + if (IS_ERR(p->phy)) { 266 + dev_err(dev, "failed to create PCIe PHY\n"); 267 + return PTR_ERR(p->phy); 268 + } 269 + 270 + p->core = core; 271 + p->index = phy_idx; 272 + phy_set_drvdata(p->phy, p); 273 + } 274 + 275 + dev_set_drvdata(dev, core); 276 + 277 + provider = devm_of_phy_provider_register(dev, sr_pcie_phy_xlate); 278 + if (IS_ERR(provider)) { 279 + dev_err(dev, "failed to register PHY provider\n"); 280 + return PTR_ERR(provider); 281 + } 282 + 283 + dev_info(dev, "Stingray PCIe PHY driver initialized\n"); 284 + 285 + return 0; 286 + } 287 + 288 + static const struct of_device_id sr_pcie_phy_match_table[] = { 289 + { .compatible = "brcm,sr-pcie-phy" }, 290 + { } 291 + }; 292 + MODULE_DEVICE_TABLE(of, sr_pcie_phy_match_table); 293 + 294 + static struct platform_driver sr_pcie_phy_driver = { 295 + .driver = { 296 + .name = "sr-pcie-phy", 297 + .of_match_table = sr_pcie_phy_match_table, 298 + }, 299 + .probe = sr_pcie_phy_probe, 300 + }; 301 + module_platform_driver(sr_pcie_phy_driver); 302 + 303 + MODULE_AUTHOR("Ray Jui <ray.jui@broadcom.com>"); 304 + MODULE_DESCRIPTION("Broadcom Stingray PCIe PHY driver"); 305 + MODULE_LICENSE("GPL v2");
+1 -4
drivers/phy/marvell/phy-berlin-sata.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 1 2 /* 2 3 * Marvell Berlin SATA PHY driver 3 4 * 4 5 * Copyright (C) 2014 Marvell Technology Group Ltd. 5 6 * 6 7 * Antoine Ténart <antoine.tenart@free-electrons.com> 7 - * 8 - * This file is licensed under the terms of the GNU General Public 9 - * License version 2. This program is licensed "as is" without any 10 - * warranty of any kind, whether express or implied. 11 8 */ 12 9 13 10 #include <linux/clk.h>
+1 -4
drivers/phy/marvell/phy-berlin-usb.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 1 2 /* 2 3 * Copyright (C) 2014 Marvell Technology Group Ltd. 3 4 * 4 5 * Antoine Tenart <antoine.tenart@free-electrons.com> 5 6 * Jisheng Zhang <jszhang@marvell.com> 6 - * 7 - * This file is licensed under the terms of the GNU General Public 8 - * License version 2. This program is licensed "as is" without any 9 - * warranty of any kind, whether express or implied. 10 7 */ 11 8 12 9 #include <linux/io.h>
+1 -4
drivers/phy/marvell/phy-mvebu-cp110-comphy.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 1 2 /* 2 3 * Copyright (C) 2017 Marvell 3 4 * 4 5 * Antoine Tenart <antoine.tenart@free-electrons.com> 5 - * 6 - * This file is licensed under the terms of the GNU General Public 7 - * License version 2. This program is licensed "as is" without any 8 - * warranty of any kind, whether express or implied. 9 6 */ 10 7 11 8 #include <linux/io.h>
+1
drivers/phy/mediatek/Makefile
··· 1 + # SPDX-License-Identifier: GPL-2.0 1 2 # 2 3 # Makefile for the phy drivers. 3 4 #
+76 -9
drivers/phy/mediatek/phy-mtk-tphy.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 1 2 /* 2 3 * Copyright (c) 2015 MediaTek Inc. 3 4 * Author: Chunfeng Yun <chunfeng.yun@mediatek.com> 4 - * 5 - * This software is licensed under the terms of the GNU General Public 6 - * License version 2, as published by the Free Software Foundation, and 7 - * may be copied, distributed, and modified under those terms. 8 - * 9 - * This program is distributed in the hope that it will be useful, 10 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 - * GNU General Public License for more details. 13 5 * 14 6 */ 15 7 ··· 41 49 #define U3P_USBPHYACR0 0x000 42 50 #define PA0_RG_U2PLL_FORCE_ON BIT(15) 43 51 #define PA0_RG_USB20_INTR_EN BIT(5) 52 + 53 + #define U3P_USBPHYACR1 0x004 54 + #define PA1_RG_VRT_SEL GENMASK(14, 12) 55 + #define PA1_RG_VRT_SEL_VAL(x) ((0x7 & (x)) << 12) 56 + #define PA1_RG_TERM_SEL GENMASK(10, 8) 57 + #define PA1_RG_TERM_SEL_VAL(x) ((0x7 & (x)) << 8) 44 58 45 59 #define U3P_USBPHYACR2 0x008 46 60 #define PA2_RG_SIF_U2PLL_FORCE_EN BIT(18) ··· 100 102 #define P2C_RG_SESSEND BIT(4) 101 103 #define P2C_RG_AVALID BIT(2) 102 104 #define P2C_RG_IDDIG BIT(1) 105 + 106 + #define U3P_U2PHYBC12C 0x080 107 + #define P2C_RG_CHGDT_EN BIT(0) 103 108 104 109 #define U3P_U3_CHIP_GPIO_CTLD 0x0c 105 110 #define P3C_REG_IP_SW_RST BIT(31) ··· 297 296 struct clk *ref_clk; /* reference clock of anolog phy */ 298 297 u32 index; 299 298 u8 type; 299 + int eye_src; 300 + int eye_vrt; 301 + int eye_term; 302 + bool bc12_en; 300 303 }; 301 304 302 305 struct mtk_tphy { ··· 324 319 int calibration_val; 325 320 int fm_out; 326 321 u32 tmp; 322 + 323 + /* use force value */ 324 + if (instance->eye_src) 325 + return; 327 326 328 327 /* enable USB ring oscillator */ 329 328 tmp = readl(com + U3P_USBPHYACR5); ··· 835 826 } 836 827 } 837 828 829 + static void phy_parse_property(struct mtk_tphy *tphy, 830 + struct mtk_phy_instance *instance) 831 + { 832 + struct device *dev = &instance->phy->dev; 833 + 834 + if (instance->type != PHY_TYPE_USB2) 835 + return; 836 + 837 + instance->bc12_en = device_property_read_bool(dev, "mediatek,bc12"); 838 + device_property_read_u32(dev, "mediatek,eye-src", 839 + &instance->eye_src); 840 + device_property_read_u32(dev, "mediatek,eye-vrt", 841 + &instance->eye_vrt); 842 + device_property_read_u32(dev, "mediatek,eye-term", 843 + &instance->eye_term); 844 + dev_dbg(dev, "bc12:%d, src:%d, vrt:%d, term:%d\n", 845 + instance->bc12_en, instance->eye_src, 846 + instance->eye_vrt, instance->eye_term); 847 + } 848 + 849 + static void u2_phy_props_set(struct mtk_tphy *tphy, 850 + struct mtk_phy_instance *instance) 851 + { 852 + struct u2phy_banks *u2_banks = &instance->u2_banks; 853 + void __iomem *com = u2_banks->com; 854 + u32 tmp; 855 + 856 + if (instance->bc12_en) { 857 + tmp = readl(com + U3P_U2PHYBC12C); 858 + tmp |= P2C_RG_CHGDT_EN; /* BC1.2 path Enable */ 859 + writel(tmp, com + U3P_U2PHYBC12C); 860 + } 861 + 862 + if (instance->eye_src) { 863 + tmp = readl(com + U3P_USBPHYACR5); 864 + tmp &= ~PA5_RG_U2_HSTX_SRCTRL; 865 + tmp |= PA5_RG_U2_HSTX_SRCTRL_VAL(instance->eye_src); 866 + writel(tmp, com + U3P_USBPHYACR5); 867 + } 868 + 869 + if (instance->eye_vrt) { 870 + tmp = readl(com + U3P_USBPHYACR1); 871 + tmp &= ~PA1_RG_VRT_SEL; 872 + tmp |= PA1_RG_VRT_SEL_VAL(instance->eye_vrt); 873 + writel(tmp, com + U3P_USBPHYACR1); 874 + } 875 + 876 + if (instance->eye_term) { 877 + tmp = readl(com + U3P_USBPHYACR1); 878 + tmp &= ~PA1_RG_TERM_SEL; 879 + tmp |= PA1_RG_TERM_SEL_VAL(instance->eye_term); 880 + writel(tmp, com + U3P_USBPHYACR1); 881 + } 882 + } 883 + 838 884 static int mtk_phy_init(struct phy *phy) 839 885 { 840 886 struct mtk_phy_instance *instance = phy_get_drvdata(phy); ··· 911 847 switch (instance->type) { 912 848 case PHY_TYPE_USB2: 913 849 u2_phy_instance_init(tphy, instance); 850 + u2_phy_props_set(tphy, instance); 914 851 break; 915 852 case PHY_TYPE_USB3: 916 853 u3_phy_instance_init(tphy, instance); ··· 1023 958 dev_err(dev, "phy version is not supported\n"); 1024 959 return ERR_PTR(-EINVAL); 1025 960 } 961 + 962 + phy_parse_property(tphy, instance); 1026 963 1027 964 return instance->phy; 1028 965 }
+1
drivers/phy/qualcomm/phy-qcom-usb-hs.c
··· 55 55 case PHY_MODE_USB_OTG: 56 56 case PHY_MODE_USB_HOST: 57 57 val |= ULPI_INT_IDGRD; 58 + /* fall through */ 58 59 case PHY_MODE_USB_DEVICE: 59 60 val |= ULPI_INT_SESS_VALID; 60 61 default:
+7
drivers/phy/renesas/Kconfig
··· 8 8 help 9 9 Support for USB PHY found on Renesas R-Car generation 2 SoCs. 10 10 11 + config PHY_RCAR_GEN3_PCIE 12 + tristate "Renesas R-Car generation 3 PCIe PHY driver" 13 + depends on ARCH_RENESAS 14 + select GENERIC_PHY 15 + help 16 + Support for the PCIe PHY found on Renesas R-Car generation 3 SoCs. 17 + 11 18 config PHY_RCAR_GEN3_USB2 12 19 tristate "Renesas R-Car generation 3 USB 2.0 PHY driver" 13 20 depends on ARCH_RENESAS
+1
drivers/phy/renesas/Makefile
··· 1 1 obj-$(CONFIG_PHY_RCAR_GEN2) += phy-rcar-gen2.o 2 + obj-$(CONFIG_PHY_RCAR_GEN3_PCIE) += phy-rcar-gen3-pcie.o 2 3 obj-$(CONFIG_PHY_RCAR_GEN3_USB2) += phy-rcar-gen3-usb2.o 3 4 obj-$(CONFIG_PHY_RCAR_GEN3_USB3) += phy-rcar-gen3-usb3.o
+151
drivers/phy/renesas/phy-rcar-gen3-pcie.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * Renesas R-Car Gen3 PCIe PHY driver 4 + * 5 + * Copyright (C) 2018 Cogent Embedded, Inc. 6 + */ 7 + 8 + #include <linux/clk.h> 9 + #include <linux/io.h> 10 + #include <linux/module.h> 11 + #include <linux/of.h> 12 + #include <linux/phy/phy.h> 13 + #include <linux/of_device.h> 14 + #include <linux/platform_device.h> 15 + #include <linux/spinlock.h> 16 + 17 + #define PHY_CTRL 0x4000 /* R8A77980 only */ 18 + 19 + /* PHY control register (PHY_CTRL) */ 20 + #define PHY_CTRL_PHY_PWDN BIT(2) 21 + 22 + struct rcar_gen3_phy { 23 + struct phy *phy; 24 + spinlock_t lock; 25 + void __iomem *base; 26 + }; 27 + 28 + static void rcar_gen3_phy_pcie_modify_reg(struct phy *p, unsigned int reg, 29 + u32 clear, u32 set) 30 + { 31 + struct rcar_gen3_phy *phy = phy_get_drvdata(p); 32 + void __iomem *base = phy->base; 33 + unsigned long flags; 34 + u32 value; 35 + 36 + spin_lock_irqsave(&phy->lock, flags); 37 + 38 + value = readl(base + reg); 39 + value &= ~clear; 40 + value |= set; 41 + writel(value, base + reg); 42 + 43 + spin_unlock_irqrestore(&phy->lock, flags); 44 + } 45 + 46 + static int r8a77980_phy_pcie_power_on(struct phy *p) 47 + { 48 + /* Power on the PCIe PHY */ 49 + rcar_gen3_phy_pcie_modify_reg(p, PHY_CTRL, PHY_CTRL_PHY_PWDN, 0); 50 + 51 + return 0; 52 + } 53 + 54 + static int r8a77980_phy_pcie_power_off(struct phy *p) 55 + { 56 + /* Power off the PCIe PHY */ 57 + rcar_gen3_phy_pcie_modify_reg(p, PHY_CTRL, 0, PHY_CTRL_PHY_PWDN); 58 + 59 + return 0; 60 + } 61 + 62 + static const struct phy_ops r8a77980_phy_pcie_ops = { 63 + .power_on = r8a77980_phy_pcie_power_on, 64 + .power_off = r8a77980_phy_pcie_power_off, 65 + .owner = THIS_MODULE, 66 + }; 67 + 68 + static const struct of_device_id rcar_gen3_phy_pcie_match_table[] = { 69 + { .compatible = "renesas,r8a77980-pcie-phy" }, 70 + { } 71 + }; 72 + MODULE_DEVICE_TABLE(of, rcar_gen3_phy_pcie_match_table); 73 + 74 + static int rcar_gen3_phy_pcie_probe(struct platform_device *pdev) 75 + { 76 + struct device *dev = &pdev->dev; 77 + struct phy_provider *provider; 78 + struct rcar_gen3_phy *phy; 79 + struct resource *res; 80 + void __iomem *base; 81 + int error; 82 + 83 + if (!dev->of_node) { 84 + dev_err(dev, 85 + "This driver must only be instantiated from the device tree\n"); 86 + return -EINVAL; 87 + } 88 + 89 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 90 + base = devm_ioremap_resource(dev, res); 91 + if (IS_ERR(base)) 92 + return PTR_ERR(base); 93 + 94 + phy = devm_kzalloc(dev, sizeof(*phy), GFP_KERNEL); 95 + if (!phy) 96 + return -ENOMEM; 97 + 98 + spin_lock_init(&phy->lock); 99 + 100 + phy->base = base; 101 + 102 + /* 103 + * devm_phy_create() will call pm_runtime_enable(&phy->dev); 104 + * And then, phy-core will manage runtime PM for this device. 105 + */ 106 + pm_runtime_enable(dev); 107 + 108 + phy->phy = devm_phy_create(dev, NULL, &r8a77980_phy_pcie_ops); 109 + if (IS_ERR(phy->phy)) { 110 + dev_err(dev, "Failed to create PCIe PHY\n"); 111 + error = PTR_ERR(phy->phy); 112 + goto error; 113 + } 114 + phy_set_drvdata(phy->phy, phy); 115 + 116 + provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate); 117 + if (IS_ERR(provider)) { 118 + dev_err(dev, "Failed to register PHY provider\n"); 119 + error = PTR_ERR(provider); 120 + goto error; 121 + } 122 + 123 + return 0; 124 + 125 + error: 126 + pm_runtime_disable(dev); 127 + 128 + return error; 129 + } 130 + 131 + static int rcar_gen3_phy_pcie_remove(struct platform_device *pdev) 132 + { 133 + pm_runtime_disable(&pdev->dev); 134 + 135 + return 0; 136 + }; 137 + 138 + static struct platform_driver rcar_gen3_phy_driver = { 139 + .driver = { 140 + .name = "phy_rcar_gen3_pcie", 141 + .of_match_table = rcar_gen3_phy_pcie_match_table, 142 + }, 143 + .probe = rcar_gen3_phy_pcie_probe, 144 + .remove = rcar_gen3_phy_pcie_remove, 145 + }; 146 + 147 + module_platform_driver(rcar_gen3_phy_driver); 148 + 149 + MODULE_LICENSE("GPL v2"); 150 + MODULE_DESCRIPTION("Renesas R-Car Gen3 PCIe PHY"); 151 + MODULE_AUTHOR("Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>");
-2
drivers/staging/Kconfig
··· 106 106 107 107 source "drivers/staging/vc04_services/Kconfig" 108 108 109 - source "drivers/staging/typec/Kconfig" 110 - 111 109 source "drivers/staging/vboxvideo/Kconfig" 112 110 113 111 source "drivers/staging/pi433/Kconfig"
-1
drivers/staging/Makefile
··· 2 2 # Makefile for staging directory 3 3 4 4 obj-y += media/ 5 - obj-y += typec/ 6 5 obj-$(CONFIG_PRISM2_USB) += wlan-ng/ 7 6 obj-$(CONFIG_COMEDI) += comedi/ 8 7 obj-$(CONFIG_FB_OLPC_DCON) += olpc_dcon/
-23
drivers/staging/typec/Kconfig
··· 1 - menu "USB Power Delivery and Type-C drivers" 2 - 3 - if TYPEC_TCPM 4 - 5 - config TYPEC_TCPCI 6 - tristate "Type-C Port Controller Interface driver" 7 - depends on I2C 8 - select REGMAP_I2C 9 - help 10 - Type-C Port Controller driver for TCPCI-compliant controller. 11 - 12 - config TYPEC_RT1711H 13 - tristate "Richtek RT1711H Type-C chip driver" 14 - depends on I2C 15 - select TYPEC_TCPCI 16 - help 17 - Richtek RT1711H Type-C chip driver that works with 18 - Type-C Port Controller Manager to provide USB PD and USB 19 - Type-C functionalities. 20 - 21 - endif 22 - 23 - endmenu
-2
drivers/staging/typec/Makefile
··· 1 - obj-$(CONFIG_TYPEC_TCPCI) += tcpci.o 2 - obj-$(CONFIG_TYPEC_RT1711H) += tcpci_rt1711h.o
-5
drivers/staging/typec/TODO
··· 1 - tcpci: 2 - - Test with real hardware 3 - 4 - Please send patches to Guenter Roeck <linux@roeck-us.net> and copy 5 - Heikki Krogerus <heikki.krogerus@linux.intel.com>.
+41 -25
drivers/staging/typec/tcpci.c drivers/usb/typec/tcpci.c
··· 10 10 #include <linux/module.h> 11 11 #include <linux/i2c.h> 12 12 #include <linux/interrupt.h> 13 + #include <linux/property.h> 13 14 #include <linux/regmap.h> 14 15 #include <linux/usb/pd.h> 15 16 #include <linux/usb/tcpm.h> ··· 185 184 enum typec_cc_polarity polarity) 186 185 { 187 186 struct tcpci *tcpci = tcpc_to_tcpci(tcpc); 187 + unsigned int reg; 188 188 int ret; 189 189 190 - ret = regmap_write(tcpci->regmap, TCPC_TCPC_CTRL, 191 - (polarity == TYPEC_POLARITY_CC2) ? 192 - TCPC_TCPC_CTRL_ORIENTATION : 0); 190 + /* Keep the disconnect cc line open */ 191 + ret = regmap_read(tcpci->regmap, TCPC_ROLE_CTRL, &reg); 193 192 if (ret < 0) 194 193 return ret; 195 194 196 - return 0; 195 + if (polarity == TYPEC_POLARITY_CC2) 196 + reg |= TCPC_ROLE_CTRL_CC_OPEN << TCPC_ROLE_CTRL_CC1_SHIFT; 197 + else 198 + reg |= TCPC_ROLE_CTRL_CC_OPEN << TCPC_ROLE_CTRL_CC2_SHIFT; 199 + ret = regmap_write(tcpci->regmap, TCPC_ROLE_CTRL, reg); 200 + if (ret < 0) 201 + return ret; 202 + 203 + return regmap_write(tcpci->regmap, TCPC_TCPC_CTRL, 204 + (polarity == TYPEC_POLARITY_CC2) ? 205 + TCPC_TCPC_CTRL_ORIENTATION : 0); 197 206 } 198 207 199 208 static int tcpci_set_vconn(struct tcpc_dev *tcpc, bool enable) ··· 218 207 return ret; 219 208 } 220 209 221 - ret = regmap_write(tcpci->regmap, TCPC_POWER_CTRL, 222 - enable ? TCPC_POWER_CTRL_VCONN_ENABLE : 0); 223 - if (ret < 0) 224 - return ret; 225 - 226 - return 0; 210 + return regmap_update_bits(tcpci->regmap, TCPC_POWER_CTRL, 211 + TCPC_POWER_CTRL_VCONN_ENABLE, 212 + enable ? TCPC_POWER_CTRL_VCONN_ENABLE : 0); 227 213 } 228 214 229 215 static int tcpci_set_roles(struct tcpc_dev *tcpc, bool attached, ··· 380 372 if (ret < 0) 381 373 return ret; 382 374 375 + /* Enable Vbus detection */ 376 + ret = regmap_write(tcpci->regmap, TCPC_COMMAND, 377 + TCPC_CMD_ENABLE_VBUS_DETECT); 378 + if (ret < 0) 379 + return ret; 380 + 383 381 reg = TCPC_ALERT_TX_SUCCESS | TCPC_ALERT_TX_FAILED | 384 382 TCPC_ALERT_TX_DISCARDED | TCPC_ALERT_RX_STATUS | 385 383 TCPC_ALERT_RX_HARD_RST | TCPC_ALERT_CC_STATUS; ··· 477 463 .max_register = 0x7F, /* 0x80 .. 0xFF are vendor defined */ 478 464 }; 479 465 480 - static const struct tcpc_config tcpci_tcpc_config = { 481 - .type = TYPEC_PORT_DFP, 482 - .default_role = TYPEC_SINK, 483 - }; 484 - 485 466 static int tcpci_parse_config(struct tcpci *tcpci) 486 467 { 487 468 tcpci->controls_vbus = true; /* XXX */ 488 469 489 - /* TODO: Populate struct tcpc_config from ACPI/device-tree */ 490 - tcpci->tcpc.config = &tcpci_tcpc_config; 470 + tcpci->tcpc.fwnode = device_get_named_child_node(tcpci->dev, 471 + "connector"); 472 + if (!tcpci->tcpc.fwnode) { 473 + dev_err(tcpci->dev, "Can't find connector node.\n"); 474 + return -EINVAL; 475 + } 491 476 492 477 return 0; 493 478 } ··· 522 509 return ERR_PTR(err); 523 510 524 511 tcpci->port = tcpm_register_port(tcpci->dev, &tcpci->tcpc); 525 - if (PTR_ERR_OR_ZERO(tcpci->port)) 512 + if (IS_ERR(tcpci->port)) 526 513 return ERR_CAST(tcpci->port); 527 514 528 515 return tcpci; ··· 550 537 if (IS_ERR(chip->data.regmap)) 551 538 return PTR_ERR(chip->data.regmap); 552 539 540 + i2c_set_clientdata(client, chip); 541 + 553 542 /* Disable chip interrupts before requesting irq */ 554 543 err = regmap_raw_write(chip->data.regmap, TCPC_ALERT_MASK, &val, 555 544 sizeof(u16)); 556 545 if (err < 0) 557 546 return err; 558 547 548 + chip->tcpci = tcpci_register_port(&client->dev, &chip->data); 549 + if (IS_ERR(chip->tcpci)) 550 + return PTR_ERR(chip->tcpci); 551 + 559 552 err = devm_request_threaded_irq(&client->dev, client->irq, NULL, 560 553 _tcpci_irq, 561 554 IRQF_ONESHOT | IRQF_TRIGGER_LOW, 562 555 dev_name(&client->dev), chip); 563 - if (err < 0) 556 + if (err < 0) { 557 + tcpci_unregister_port(chip->tcpci); 564 558 return err; 559 + } 565 560 566 - chip->tcpci = tcpci_register_port(&client->dev, &chip->data); 567 - if (PTR_ERR_OR_ZERO(chip->tcpci)) 568 - return PTR_ERR(chip->tcpci); 569 - 570 - i2c_set_clientdata(client, chip); 571 561 return 0; 572 562 } 573 563 ··· 591 575 592 576 #ifdef CONFIG_OF 593 577 static const struct of_device_id tcpci_of_match[] = { 594 - { .compatible = "usb,tcpci", }, 578 + { .compatible = "nxp,ptn5110", }, 595 579 {}, 596 580 }; 597 581 MODULE_DEVICE_TABLE(of, tcpci_of_match);
drivers/staging/typec/tcpci.h drivers/usb/typec/tcpci.h
drivers/staging/typec/tcpci_rt1711h.c drivers/usb/typec/tcpci_rt1711h.c
+2 -2
drivers/usb/chipidea/ci_hdrc_tegra.c
··· 33 33 }; 34 34 35 35 static const struct tegra_udc_soc_info tegra114_udc_soc_info = { 36 - .flags = 0, 36 + .flags = CI_HDRC_REQUIRES_ALIGNED_DMA, 37 37 }; 38 38 39 39 static const struct tegra_udc_soc_info tegra124_udc_soc_info = { 40 - .flags = 0, 40 + .flags = CI_HDRC_REQUIRES_ALIGNED_DMA, 41 41 }; 42 42 43 43 static const struct of_device_id tegra_udc_of_match[] = {
+20 -20
drivers/usb/class/cdc-acm.c
··· 276 276 { 277 277 int newctrl; 278 278 int difference; 279 + unsigned long flags; 279 280 struct usb_cdc_notification *dr = (struct usb_cdc_notification *)buf; 280 281 unsigned char *data = buf + sizeof(struct usb_cdc_notification); 281 282 ··· 304 303 } 305 304 306 305 difference = acm->ctrlin ^ newctrl; 307 - spin_lock(&acm->read_lock); 306 + spin_lock_irqsave(&acm->read_lock, flags); 308 307 acm->ctrlin = newctrl; 309 308 acm->oldcount = acm->iocount; 310 309 ··· 322 321 acm->iocount.parity++; 323 322 if (difference & ACM_CTRL_OVERRUN) 324 323 acm->iocount.overrun++; 325 - spin_unlock(&acm->read_lock); 324 + spin_unlock_irqrestore(&acm->read_lock, flags); 326 325 327 326 if (difference) 328 327 wake_up_all(&acm->wioctl); ··· 1379 1378 if (acm == NULL) 1380 1379 goto alloc_fail; 1381 1380 1381 + tty_port_init(&acm->port); 1382 + acm->port.ops = &acm_port_ops; 1383 + 1382 1384 minor = acm_alloc_minor(acm); 1383 1385 if (minor < 0) 1384 1386 goto alloc_fail1; ··· 1417 1413 acm->out = usb_sndintpipe(usb_dev, epwrite->bEndpointAddress); 1418 1414 else 1419 1415 acm->out = usb_sndbulkpipe(usb_dev, epwrite->bEndpointAddress); 1420 - tty_port_init(&acm->port); 1421 - acm->port.ops = &acm_port_ops; 1422 1416 init_usb_anchor(&acm->delayed); 1423 1417 acm->quirks = quirks; 1424 1418 1425 1419 buf = usb_alloc_coherent(usb_dev, ctrlsize, GFP_KERNEL, &acm->ctrl_dma); 1426 1420 if (!buf) 1427 - goto alloc_fail2; 1421 + goto alloc_fail1; 1428 1422 acm->ctrl_buffer = buf; 1429 1423 1430 1424 if (acm_write_buffers_alloc(acm) < 0) 1431 - goto alloc_fail4; 1425 + goto alloc_fail2; 1432 1426 1433 1427 acm->ctrlurb = usb_alloc_urb(0, GFP_KERNEL); 1434 1428 if (!acm->ctrlurb) 1435 - goto alloc_fail5; 1429 + goto alloc_fail3; 1436 1430 1437 1431 for (i = 0; i < num_rx_buf; i++) { 1438 1432 struct acm_rb *rb = &(acm->read_buffers[i]); ··· 1439 1437 rb->base = usb_alloc_coherent(acm->dev, readsize, GFP_KERNEL, 1440 1438 &rb->dma); 1441 1439 if (!rb->base) 1442 - goto alloc_fail6; 1440 + goto alloc_fail4; 1443 1441 rb->index = i; 1444 1442 rb->instance = acm; 1445 1443 1446 1444 urb = usb_alloc_urb(0, GFP_KERNEL); 1447 1445 if (!urb) 1448 - goto alloc_fail6; 1446 + goto alloc_fail4; 1449 1447 1450 1448 urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; 1451 1449 urb->transfer_dma = rb->dma; ··· 1467 1465 1468 1466 snd->urb = usb_alloc_urb(0, GFP_KERNEL); 1469 1467 if (snd->urb == NULL) 1470 - goto alloc_fail7; 1468 + goto alloc_fail5; 1471 1469 1472 1470 if (usb_endpoint_xfer_int(epwrite)) 1473 1471 usb_fill_int_urb(snd->urb, usb_dev, acm->out, ··· 1485 1483 1486 1484 i = device_create_file(&intf->dev, &dev_attr_bmCapabilities); 1487 1485 if (i < 0) 1488 - goto alloc_fail7; 1486 + goto alloc_fail5; 1489 1487 1490 1488 if (h.usb_cdc_country_functional_desc) { /* export the country data */ 1491 1489 struct usb_cdc_country_functional_desc * cfd = ··· 1544 1542 &control_interface->dev); 1545 1543 if (IS_ERR(tty_dev)) { 1546 1544 rv = PTR_ERR(tty_dev); 1547 - goto alloc_fail8; 1545 + goto alloc_fail6; 1548 1546 } 1549 1547 1550 1548 if (quirks & CLEAR_HALT_CONDITIONS) { ··· 1553 1551 } 1554 1552 1555 1553 return 0; 1556 - alloc_fail8: 1554 + alloc_fail6: 1557 1555 if (acm->country_codes) { 1558 1556 device_remove_file(&acm->control->dev, 1559 1557 &dev_attr_wCountryCodes); ··· 1562 1560 kfree(acm->country_codes); 1563 1561 } 1564 1562 device_remove_file(&acm->control->dev, &dev_attr_bmCapabilities); 1565 - alloc_fail7: 1563 + alloc_fail5: 1566 1564 usb_set_intfdata(intf, NULL); 1567 1565 for (i = 0; i < ACM_NW; i++) 1568 1566 usb_free_urb(acm->wb[i].urb); 1569 - alloc_fail6: 1567 + alloc_fail4: 1570 1568 for (i = 0; i < num_rx_buf; i++) 1571 1569 usb_free_urb(acm->read_urbs[i]); 1572 1570 acm_read_buffers_free(acm); 1573 1571 usb_free_urb(acm->ctrlurb); 1574 - alloc_fail5: 1572 + alloc_fail3: 1575 1573 acm_write_buffers_free(acm); 1576 - alloc_fail4: 1577 - usb_free_coherent(usb_dev, ctrlsize, acm->ctrl_buffer, acm->ctrl_dma); 1578 1574 alloc_fail2: 1579 - acm_release_minor(acm); 1575 + usb_free_coherent(usb_dev, ctrlsize, acm->ctrl_buffer, acm->ctrl_dma); 1580 1576 alloc_fail1: 1581 - kfree(acm); 1577 + tty_port_put(&acm->port); 1582 1578 alloc_fail: 1583 1579 return rv; 1584 1580 }
+34 -13
drivers/usb/class/cdc-wdm.c
··· 96 96 struct mutex rlock; 97 97 wait_queue_head_t wait; 98 98 struct work_struct rxwork; 99 + struct work_struct service_outs_intr; 99 100 int werr; 100 101 int rerr; 101 102 int resp_count; ··· 142 141 static void wdm_out_callback(struct urb *urb) 143 142 { 144 143 struct wdm_device *desc; 144 + unsigned long flags; 145 + 145 146 desc = urb->context; 146 - spin_lock(&desc->iuspin); 147 + spin_lock_irqsave(&desc->iuspin, flags); 147 148 desc->werr = urb->status; 148 - spin_unlock(&desc->iuspin); 149 + spin_unlock_irqrestore(&desc->iuspin, flags); 149 150 kfree(desc->outbuf); 150 151 desc->outbuf = NULL; 151 152 clear_bit(WDM_IN_USE, &desc->flags); 152 153 wake_up(&desc->wait); 153 154 } 154 155 155 - /* forward declaration */ 156 - static int service_outstanding_interrupt(struct wdm_device *desc); 157 - 158 156 static void wdm_in_callback(struct urb *urb) 159 157 { 158 + unsigned long flags; 160 159 struct wdm_device *desc = urb->context; 161 160 int status = urb->status; 162 161 int length = urb->actual_length; 163 162 164 - spin_lock(&desc->iuspin); 163 + spin_lock_irqsave(&desc->iuspin, flags); 165 164 clear_bit(WDM_RESPONDING, &desc->flags); 166 165 167 166 if (status) { ··· 210 209 } 211 210 } 212 211 skip_error: 213 - set_bit(WDM_READ, &desc->flags); 214 - wake_up(&desc->wait); 215 212 216 213 if (desc->rerr) { 217 214 /* ··· 218 219 * We should respond to further attempts from the device to send 219 220 * data, so that we can get unstuck. 220 221 */ 221 - service_outstanding_interrupt(desc); 222 + schedule_work(&desc->service_outs_intr); 223 + } else { 224 + set_bit(WDM_READ, &desc->flags); 225 + wake_up(&desc->wait); 222 226 } 223 - 224 - spin_unlock(&desc->iuspin); 227 + spin_unlock_irqrestore(&desc->iuspin, flags); 225 228 } 226 229 227 230 static void wdm_int_callback(struct urb *urb) 228 231 { 232 + unsigned long flags; 229 233 int rv = 0; 230 234 int responding; 231 235 int status = urb->status; ··· 288 286 goto exit; 289 287 } 290 288 291 - spin_lock(&desc->iuspin); 289 + spin_lock_irqsave(&desc->iuspin, flags); 292 290 responding = test_and_set_bit(WDM_RESPONDING, &desc->flags); 293 291 if (!desc->resp_count++ && !responding 294 292 && !test_bit(WDM_DISCONNECTING, &desc->flags) ··· 296 294 rv = usb_submit_urb(desc->response, GFP_ATOMIC); 297 295 dev_dbg(&desc->intf->dev, "submit response URB %d\n", rv); 298 296 } 299 - spin_unlock(&desc->iuspin); 297 + spin_unlock_irqrestore(&desc->iuspin, flags); 300 298 if (rv < 0) { 301 299 clear_bit(WDM_RESPONDING, &desc->flags); 302 300 if (rv == -EPERM) ··· 760 758 } 761 759 } 762 760 761 + static void service_interrupt_work(struct work_struct *work) 762 + { 763 + struct wdm_device *desc; 764 + 765 + desc = container_of(work, struct wdm_device, service_outs_intr); 766 + 767 + spin_lock_irq(&desc->iuspin); 768 + service_outstanding_interrupt(desc); 769 + if (!desc->resp_count) { 770 + set_bit(WDM_READ, &desc->flags); 771 + wake_up(&desc->wait); 772 + } 773 + spin_unlock_irq(&desc->iuspin); 774 + } 775 + 763 776 /* --- hotplug --- */ 764 777 765 778 static int wdm_create(struct usb_interface *intf, struct usb_endpoint_descriptor *ep, ··· 796 779 desc->inum = cpu_to_le16((u16)intf->cur_altsetting->desc.bInterfaceNumber); 797 780 desc->intf = intf; 798 781 INIT_WORK(&desc->rxwork, wdm_rxwork); 782 + INIT_WORK(&desc->service_outs_intr, service_interrupt_work); 799 783 800 784 rv = -EINVAL; 801 785 if (!usb_endpoint_is_int_in(ep)) ··· 982 964 mutex_lock(&desc->wlock); 983 965 kill_urbs(desc); 984 966 cancel_work_sync(&desc->rxwork); 967 + cancel_work_sync(&desc->service_outs_intr); 985 968 mutex_unlock(&desc->wlock); 986 969 mutex_unlock(&desc->rlock); 987 970 ··· 1025 1006 /* callback submits work - order is essential */ 1026 1007 kill_urbs(desc); 1027 1008 cancel_work_sync(&desc->rxwork); 1009 + cancel_work_sync(&desc->service_outs_intr); 1028 1010 } 1029 1011 if (!PMSG_IS_AUTO(message)) { 1030 1012 mutex_unlock(&desc->wlock); ··· 1085 1065 mutex_lock(&desc->wlock); 1086 1066 kill_urbs(desc); 1087 1067 cancel_work_sync(&desc->rxwork); 1068 + cancel_work_sync(&desc->service_outs_intr); 1088 1069 return 0; 1089 1070 } 1090 1071
+6 -4
drivers/usb/class/usblp.c
··· 292 292 { 293 293 struct usblp *usblp = urb->context; 294 294 int status = urb->status; 295 + unsigned long flags; 295 296 296 297 if (usblp->present && usblp->used) { 297 298 if (status) ··· 300 299 "nonzero read bulk status received: %d\n", 301 300 usblp->minor, status); 302 301 } 303 - spin_lock(&usblp->lock); 302 + spin_lock_irqsave(&usblp->lock, flags); 304 303 if (status < 0) 305 304 usblp->rstatus = status; 306 305 else 307 306 usblp->rstatus = urb->actual_length; 308 307 usblp->rcomplete = 1; 309 308 wake_up(&usblp->rwait); 310 - spin_unlock(&usblp->lock); 309 + spin_unlock_irqrestore(&usblp->lock, flags); 311 310 312 311 usb_free_urb(urb); 313 312 } ··· 316 315 { 317 316 struct usblp *usblp = urb->context; 318 317 int status = urb->status; 318 + unsigned long flags; 319 319 320 320 if (usblp->present && usblp->used) { 321 321 if (status) ··· 324 322 "nonzero write bulk status received: %d\n", 325 323 usblp->minor, status); 326 324 } 327 - spin_lock(&usblp->lock); 325 + spin_lock_irqsave(&usblp->lock, flags); 328 326 if (status < 0) 329 327 usblp->wstatus = status; 330 328 else ··· 332 330 usblp->no_paper = 0; 333 331 usblp->wcomplete = 1; 334 332 wake_up(&usblp->wwait); 335 - spin_unlock(&usblp->lock); 333 + spin_unlock_irqrestore(&usblp->lock, flags); 336 334 337 335 usb_free_urb(urb); 338 336 }
+280 -42
drivers/usb/class/usbtmc.c
··· 18 18 #include <linux/poll.h> 19 19 #include <linux/mutex.h> 20 20 #include <linux/usb.h> 21 + #include <linux/compat.h> 21 22 #include <linux/usb/tmc.h> 22 23 23 24 ··· 31 30 */ 32 31 #define USBTMC_SIZE_IOBUFFER 2048 33 32 33 + /* Minimum USB timeout (in milliseconds) */ 34 + #define USBTMC_MIN_TIMEOUT 100 34 35 /* Default USB timeout (in milliseconds) */ 35 36 #define USBTMC_TIMEOUT 5000 36 37 ··· 70 67 const struct usb_device_id *id; 71 68 struct usb_device *usb_dev; 72 69 struct usb_interface *intf; 70 + struct list_head file_list; 73 71 74 72 unsigned int bulk_in; 75 73 unsigned int bulk_out; ··· 91 87 int iin_interval; 92 88 struct urb *iin_urb; 93 89 u16 iin_wMaxPacketSize; 94 - atomic_t srq_asserted; 95 90 96 91 /* coalesced usb488_caps from usbtmc_dev_capabilities */ 97 92 __u8 usb488_caps; ··· 107 104 struct mutex io_mutex; /* only one i/o function running at a time */ 108 105 wait_queue_head_t waitq; 109 106 struct fasync_struct *fasync; 107 + spinlock_t dev_lock; /* lock for file_list */ 110 108 }; 111 109 #define to_usbtmc_data(d) container_of(d, struct usbtmc_device_data, kref) 110 + 111 + /* 112 + * This structure holds private data for each USBTMC file handle. 113 + */ 114 + struct usbtmc_file_data { 115 + struct usbtmc_device_data *data; 116 + struct list_head file_elem; 117 + 118 + u32 timeout; 119 + u8 srq_byte; 120 + atomic_t srq_asserted; 121 + u8 eom_val; 122 + u8 term_char; 123 + bool term_char_enabled; 124 + }; 112 125 113 126 /* Forward declarations */ 114 127 static struct usb_driver usbtmc_driver; ··· 141 122 { 142 123 struct usb_interface *intf; 143 124 struct usbtmc_device_data *data; 144 - int retval = 0; 125 + struct usbtmc_file_data *file_data; 145 126 146 127 intf = usb_find_interface(&usbtmc_driver, iminor(inode)); 147 128 if (!intf) { ··· 149 130 return -ENODEV; 150 131 } 151 132 133 + file_data = kzalloc(sizeof(*file_data), GFP_KERNEL); 134 + if (!file_data) 135 + return -ENOMEM; 136 + 152 137 data = usb_get_intfdata(intf); 153 138 /* Protect reference to data from file structure until release */ 154 139 kref_get(&data->kref); 155 140 156 - /* Store pointer in file structure's private data field */ 157 - filp->private_data = data; 141 + mutex_lock(&data->io_mutex); 142 + file_data->data = data; 158 143 159 - return retval; 144 + /* copy default values from device settings */ 145 + file_data->timeout = USBTMC_TIMEOUT; 146 + file_data->term_char = data->TermChar; 147 + file_data->term_char_enabled = data->TermCharEnabled; 148 + file_data->eom_val = 1; 149 + 150 + INIT_LIST_HEAD(&file_data->file_elem); 151 + spin_lock_irq(&data->dev_lock); 152 + list_add_tail(&file_data->file_elem, &data->file_list); 153 + spin_unlock_irq(&data->dev_lock); 154 + mutex_unlock(&data->io_mutex); 155 + 156 + /* Store pointer in file structure's private data field */ 157 + filp->private_data = file_data; 158 + 159 + return 0; 160 160 } 161 161 162 162 static int usbtmc_release(struct inode *inode, struct file *file) 163 163 { 164 - struct usbtmc_device_data *data = file->private_data; 164 + struct usbtmc_file_data *file_data = file->private_data; 165 165 166 - kref_put(&data->kref, usbtmc_delete); 166 + /* prevent IO _AND_ usbtmc_interrupt */ 167 + mutex_lock(&file_data->data->io_mutex); 168 + spin_lock_irq(&file_data->data->dev_lock); 169 + 170 + list_del(&file_data->file_elem); 171 + 172 + spin_unlock_irq(&file_data->data->dev_lock); 173 + mutex_unlock(&file_data->data->io_mutex); 174 + 175 + kref_put(&file_data->data->kref, usbtmc_delete); 176 + file_data->data = NULL; 177 + kfree(file_data); 167 178 return 0; 168 179 } 169 180 ··· 418 369 return rv; 419 370 } 420 371 421 - static int usbtmc488_ioctl_read_stb(struct usbtmc_device_data *data, 372 + static int usbtmc488_ioctl_read_stb(struct usbtmc_file_data *file_data, 422 373 void __user *arg) 423 374 { 375 + struct usbtmc_device_data *data = file_data->data; 424 376 struct device *dev = &data->intf->dev; 377 + int srq_asserted = 0; 425 378 u8 *buffer; 426 379 u8 tag; 427 380 __u8 stb; ··· 432 381 dev_dbg(dev, "Enter ioctl_read_stb iin_ep_present: %d\n", 433 382 data->iin_ep_present); 434 383 384 + spin_lock_irq(&data->dev_lock); 385 + srq_asserted = atomic_xchg(&file_data->srq_asserted, srq_asserted); 386 + if (srq_asserted) { 387 + /* a STB with SRQ is already received */ 388 + stb = file_data->srq_byte; 389 + spin_unlock_irq(&data->dev_lock); 390 + rv = put_user(stb, (__u8 __user *)arg); 391 + dev_dbg(dev, "stb:0x%02x with srq received %d\n", 392 + (unsigned int)stb, rv); 393 + return rv; 394 + } 395 + spin_unlock_irq(&data->dev_lock); 396 + 435 397 buffer = kmalloc(8, GFP_KERNEL); 436 398 if (!buffer) 437 399 return -ENOMEM; 438 400 439 401 atomic_set(&data->iin_data_valid, 0); 440 - 441 - /* must issue read_stb before using poll or select */ 442 - atomic_set(&data->srq_asserted, 0); 443 402 444 403 rv = usb_control_msg(data->usb_dev, 445 404 usb_rcvctrlpipe(data->usb_dev, 0), ··· 473 412 rv = wait_event_interruptible_timeout( 474 413 data->waitq, 475 414 atomic_read(&data->iin_data_valid) != 0, 476 - USBTMC_TIMEOUT); 415 + file_data->timeout); 477 416 if (rv < 0) { 478 417 dev_dbg(dev, "wait interrupted %d\n", rv); 479 418 goto exit; ··· 481 420 482 421 if (rv == 0) { 483 422 dev_dbg(dev, "wait timed out\n"); 484 - rv = -ETIME; 423 + rv = -ETIMEDOUT; 485 424 goto exit; 486 425 } 487 426 ··· 496 435 stb = buffer[2]; 497 436 } 498 437 499 - rv = copy_to_user(arg, &stb, sizeof(stb)); 500 - if (rv) 501 - rv = -EFAULT; 438 + rv = put_user(stb, (__u8 __user *)arg); 439 + dev_dbg(dev, "stb:0x%02x received %d\n", (unsigned int)stb, rv); 502 440 503 441 exit: 504 442 /* bump interrupt bTag */ ··· 566 506 } 567 507 568 508 /* 509 + * Sends a TRIGGER Bulk-OUT command message 510 + * See the USBTMC-USB488 specification, Table 2. 511 + * 512 + * Also updates bTag_last_write. 513 + */ 514 + static int usbtmc488_ioctl_trigger(struct usbtmc_file_data *file_data) 515 + { 516 + struct usbtmc_device_data *data = file_data->data; 517 + int retval; 518 + u8 *buffer; 519 + int actual; 520 + 521 + buffer = kzalloc(USBTMC_HEADER_SIZE, GFP_KERNEL); 522 + if (!buffer) 523 + return -ENOMEM; 524 + 525 + buffer[0] = 128; 526 + buffer[1] = data->bTag; 527 + buffer[2] = ~data->bTag; 528 + 529 + retval = usb_bulk_msg(data->usb_dev, 530 + usb_sndbulkpipe(data->usb_dev, 531 + data->bulk_out), 532 + buffer, USBTMC_HEADER_SIZE, 533 + &actual, file_data->timeout); 534 + 535 + /* Store bTag (in case we need to abort) */ 536 + data->bTag_last_write = data->bTag; 537 + 538 + /* Increment bTag -- and increment again if zero */ 539 + data->bTag++; 540 + if (!data->bTag) 541 + data->bTag++; 542 + 543 + kfree(buffer); 544 + if (retval < 0) { 545 + dev_err(&data->intf->dev, "%s returned %d\n", 546 + __func__, retval); 547 + return retval; 548 + } 549 + 550 + return 0; 551 + } 552 + 553 + /* 569 554 * Sends a REQUEST_DEV_DEP_MSG_IN message on the Bulk-OUT endpoint. 570 555 * @transfer_size: number of bytes to request from the device. 571 556 * ··· 618 513 * 619 514 * Also updates bTag_last_write. 620 515 */ 621 - static int send_request_dev_dep_msg_in(struct usbtmc_device_data *data, size_t transfer_size) 516 + static int send_request_dev_dep_msg_in(struct usbtmc_file_data *file_data, 517 + size_t transfer_size) 622 518 { 519 + struct usbtmc_device_data *data = file_data->data; 623 520 int retval; 624 521 u8 *buffer; 625 522 int actual; ··· 640 533 buffer[5] = transfer_size >> 8; 641 534 buffer[6] = transfer_size >> 16; 642 535 buffer[7] = transfer_size >> 24; 643 - buffer[8] = data->TermCharEnabled * 2; 536 + buffer[8] = file_data->term_char_enabled * 2; 644 537 /* Use term character? */ 645 - buffer[9] = data->TermChar; 538 + buffer[9] = file_data->term_char; 646 539 buffer[10] = 0; /* Reserved */ 647 540 buffer[11] = 0; /* Reserved */ 648 541 ··· 650 543 retval = usb_bulk_msg(data->usb_dev, 651 544 usb_sndbulkpipe(data->usb_dev, 652 545 data->bulk_out), 653 - buffer, USBTMC_HEADER_SIZE, &actual, USBTMC_TIMEOUT); 546 + buffer, USBTMC_HEADER_SIZE, 547 + &actual, file_data->timeout); 654 548 655 549 /* Store bTag (in case we need to abort) */ 656 550 data->bTag_last_write = data->bTag; ··· 673 565 static ssize_t usbtmc_read(struct file *filp, char __user *buf, 674 566 size_t count, loff_t *f_pos) 675 567 { 568 + struct usbtmc_file_data *file_data; 676 569 struct usbtmc_device_data *data; 677 570 struct device *dev; 678 571 u32 n_characters; ··· 685 576 size_t this_part; 686 577 687 578 /* Get pointer to private data structure */ 688 - data = filp->private_data; 579 + file_data = filp->private_data; 580 + data = file_data->data; 689 581 dev = &data->intf->dev; 690 582 691 583 buffer = kmalloc(USBTMC_SIZE_IOBUFFER, GFP_KERNEL); ··· 701 591 702 592 dev_dbg(dev, "usb_bulk_msg_in: count(%zu)\n", count); 703 593 704 - retval = send_request_dev_dep_msg_in(data, count); 594 + retval = send_request_dev_dep_msg_in(file_data, count); 705 595 706 596 if (retval < 0) { 707 597 if (data->auto_abort) ··· 720 610 usb_rcvbulkpipe(data->usb_dev, 721 611 data->bulk_in), 722 612 buffer, USBTMC_SIZE_IOBUFFER, &actual, 723 - USBTMC_TIMEOUT); 613 + file_data->timeout); 724 614 725 615 dev_dbg(dev, "usb_bulk_msg: retval(%u), done(%zu), remaining(%zu), actual(%d)\n", retval, done, remaining, actual); 726 616 ··· 831 721 static ssize_t usbtmc_write(struct file *filp, const char __user *buf, 832 722 size_t count, loff_t *f_pos) 833 723 { 724 + struct usbtmc_file_data *file_data; 834 725 struct usbtmc_device_data *data; 835 726 u8 *buffer; 836 727 int retval; ··· 841 730 int done; 842 731 int this_part; 843 732 844 - data = filp->private_data; 733 + file_data = filp->private_data; 734 + data = file_data->data; 845 735 846 736 buffer = kmalloc(USBTMC_SIZE_IOBUFFER, GFP_KERNEL); 847 737 if (!buffer) ··· 863 751 buffer[8] = 0; 864 752 } else { 865 753 this_part = remaining; 866 - buffer[8] = 1; 754 + buffer[8] = file_data->eom_val; 867 755 } 868 756 869 757 /* Setup IO buffer for DEV_DEP_MSG_OUT message */ ··· 893 781 usb_sndbulkpipe(data->usb_dev, 894 782 data->bulk_out), 895 783 buffer, n_bytes, 896 - &actual, USBTMC_TIMEOUT); 784 + &actual, file_data->timeout); 897 785 if (retval != 0) 898 786 break; 899 787 n_bytes -= actual; ··· 1250 1138 return rv; 1251 1139 } 1252 1140 1141 + /* 1142 + * Get the usb timeout value 1143 + */ 1144 + static int usbtmc_ioctl_get_timeout(struct usbtmc_file_data *file_data, 1145 + void __user *arg) 1146 + { 1147 + u32 timeout; 1148 + 1149 + timeout = file_data->timeout; 1150 + 1151 + return put_user(timeout, (__u32 __user *)arg); 1152 + } 1153 + 1154 + /* 1155 + * Set the usb timeout value 1156 + */ 1157 + static int usbtmc_ioctl_set_timeout(struct usbtmc_file_data *file_data, 1158 + void __user *arg) 1159 + { 1160 + u32 timeout; 1161 + 1162 + if (get_user(timeout, (__u32 __user *)arg)) 1163 + return -EFAULT; 1164 + 1165 + /* Note that timeout = 0 means 1166 + * MAX_SCHEDULE_TIMEOUT in usb_control_msg 1167 + */ 1168 + if (timeout < USBTMC_MIN_TIMEOUT) 1169 + return -EINVAL; 1170 + 1171 + file_data->timeout = timeout; 1172 + 1173 + return 0; 1174 + } 1175 + 1176 + /* 1177 + * enables/disables sending EOM on write 1178 + */ 1179 + static int usbtmc_ioctl_eom_enable(struct usbtmc_file_data *file_data, 1180 + void __user *arg) 1181 + { 1182 + u8 eom_enable; 1183 + 1184 + if (copy_from_user(&eom_enable, arg, sizeof(eom_enable))) 1185 + return -EFAULT; 1186 + 1187 + if (eom_enable > 1) 1188 + return -EINVAL; 1189 + 1190 + file_data->eom_val = eom_enable; 1191 + 1192 + return 0; 1193 + } 1194 + 1195 + /* 1196 + * Configure termination character for read() 1197 + */ 1198 + static int usbtmc_ioctl_config_termc(struct usbtmc_file_data *file_data, 1199 + void __user *arg) 1200 + { 1201 + struct usbtmc_termchar termc; 1202 + 1203 + if (copy_from_user(&termc, arg, sizeof(termc))) 1204 + return -EFAULT; 1205 + 1206 + if ((termc.term_char_enabled > 1) || 1207 + (termc.term_char_enabled && 1208 + !(file_data->data->capabilities.device_capabilities & 1))) 1209 + return -EINVAL; 1210 + 1211 + file_data->term_char = termc.term_char; 1212 + file_data->term_char_enabled = termc.term_char_enabled; 1213 + 1214 + return 0; 1215 + } 1216 + 1253 1217 static long usbtmc_ioctl(struct file *file, unsigned int cmd, unsigned long arg) 1254 1218 { 1219 + struct usbtmc_file_data *file_data; 1255 1220 struct usbtmc_device_data *data; 1256 1221 int retval = -EBADRQC; 1257 1222 1258 - data = file->private_data; 1223 + file_data = file->private_data; 1224 + data = file_data->data; 1225 + 1259 1226 mutex_lock(&data->io_mutex); 1260 1227 if (data->zombie) { 1261 1228 retval = -ENODEV; ··· 1366 1175 retval = usbtmc_ioctl_abort_bulk_in(data); 1367 1176 break; 1368 1177 1178 + case USBTMC_IOCTL_GET_TIMEOUT: 1179 + retval = usbtmc_ioctl_get_timeout(file_data, 1180 + (void __user *)arg); 1181 + break; 1182 + 1183 + case USBTMC_IOCTL_SET_TIMEOUT: 1184 + retval = usbtmc_ioctl_set_timeout(file_data, 1185 + (void __user *)arg); 1186 + break; 1187 + 1188 + case USBTMC_IOCTL_EOM_ENABLE: 1189 + retval = usbtmc_ioctl_eom_enable(file_data, 1190 + (void __user *)arg); 1191 + break; 1192 + 1193 + case USBTMC_IOCTL_CONFIG_TERMCHAR: 1194 + retval = usbtmc_ioctl_config_termc(file_data, 1195 + (void __user *)arg); 1196 + break; 1197 + 1369 1198 case USBTMC488_IOCTL_GET_CAPS: 1370 1199 retval = copy_to_user((void __user *)arg, 1371 1200 &data->usb488_caps, ··· 1395 1184 break; 1396 1185 1397 1186 case USBTMC488_IOCTL_READ_STB: 1398 - retval = usbtmc488_ioctl_read_stb(data, (void __user *)arg); 1187 + retval = usbtmc488_ioctl_read_stb(file_data, 1188 + (void __user *)arg); 1399 1189 break; 1400 1190 1401 1191 case USBTMC488_IOCTL_REN_CONTROL: ··· 1413 1201 retval = usbtmc488_ioctl_simple(data, (void __user *)arg, 1414 1202 USBTMC488_REQUEST_LOCAL_LOCKOUT); 1415 1203 break; 1204 + 1205 + case USBTMC488_IOCTL_TRIGGER: 1206 + retval = usbtmc488_ioctl_trigger(file_data); 1207 + break; 1416 1208 } 1417 1209 1418 1210 skip_io_on_zombie: ··· 1426 1210 1427 1211 static int usbtmc_fasync(int fd, struct file *file, int on) 1428 1212 { 1429 - struct usbtmc_device_data *data = file->private_data; 1213 + struct usbtmc_file_data *file_data = file->private_data; 1430 1214 1431 - return fasync_helper(fd, file, on, &data->fasync); 1215 + return fasync_helper(fd, file, on, &file_data->data->fasync); 1432 1216 } 1433 1217 1434 1218 static __poll_t usbtmc_poll(struct file *file, poll_table *wait) 1435 1219 { 1436 - struct usbtmc_device_data *data = file->private_data; 1220 + struct usbtmc_file_data *file_data = file->private_data; 1221 + struct usbtmc_device_data *data = file_data->data; 1437 1222 __poll_t mask; 1438 1223 1439 1224 mutex_lock(&data->io_mutex); ··· 1446 1229 1447 1230 poll_wait(file, &data->waitq, wait); 1448 1231 1449 - mask = (atomic_read(&data->srq_asserted)) ? EPOLLIN | EPOLLRDNORM : 0; 1232 + mask = (atomic_read(&file_data->srq_asserted)) ? EPOLLPRI : 0; 1450 1233 1451 1234 no_poll: 1452 1235 mutex_unlock(&data->io_mutex); ··· 1460 1243 .open = usbtmc_open, 1461 1244 .release = usbtmc_release, 1462 1245 .unlocked_ioctl = usbtmc_ioctl, 1246 + #ifdef CONFIG_COMPAT 1247 + .compat_ioctl = usbtmc_ioctl, 1248 + #endif 1463 1249 .fasync = usbtmc_fasync, 1464 1250 .poll = usbtmc_poll, 1465 1251 .llseek = default_llseek, ··· 1496 1276 } 1497 1277 /* check for SRQ notification */ 1498 1278 if (data->iin_buffer[0] == 0x81) { 1279 + unsigned long flags; 1280 + struct list_head *elem; 1281 + 1499 1282 if (data->fasync) 1500 1283 kill_fasync(&data->fasync, 1501 - SIGIO, POLL_IN); 1284 + SIGIO, POLL_PRI); 1502 1285 1503 - atomic_set(&data->srq_asserted, 1); 1504 - wake_up_interruptible(&data->waitq); 1286 + spin_lock_irqsave(&data->dev_lock, flags); 1287 + list_for_each(elem, &data->file_list) { 1288 + struct usbtmc_file_data *file_data; 1289 + 1290 + file_data = list_entry(elem, 1291 + struct usbtmc_file_data, 1292 + file_elem); 1293 + file_data->srq_byte = data->iin_buffer[1]; 1294 + atomic_set(&file_data->srq_asserted, 1); 1295 + } 1296 + spin_unlock_irqrestore(&data->dev_lock, flags); 1297 + 1298 + dev_dbg(dev, "srq received bTag %x stb %x\n", 1299 + (unsigned int)data->iin_buffer[0], 1300 + (unsigned int)data->iin_buffer[1]); 1301 + wake_up_interruptible_all(&data->waitq); 1505 1302 goto exit; 1506 1303 } 1507 - dev_warn(dev, "invalid notification: %x\n", data->iin_buffer[0]); 1304 + dev_warn(dev, "invalid notification: %x\n", 1305 + data->iin_buffer[0]); 1508 1306 break; 1509 1307 case -EOVERFLOW: 1510 1308 dev_err(dev, "overflow with length %d, actual length is %d\n", ··· 1533 1295 case -ESHUTDOWN: 1534 1296 case -EILSEQ: 1535 1297 case -ETIME: 1298 + case -EPIPE: 1536 1299 /* urb terminated, clean up */ 1537 1300 dev_dbg(dev, "urb terminated, status: %d\n", status); 1538 1301 return; ··· 1578 1339 mutex_init(&data->io_mutex); 1579 1340 init_waitqueue_head(&data->waitq); 1580 1341 atomic_set(&data->iin_data_valid, 0); 1581 - atomic_set(&data->srq_asserted, 0); 1342 + INIT_LIST_HEAD(&data->file_list); 1343 + spin_lock_init(&data->dev_lock); 1344 + 1582 1345 data->zombie = 0; 1583 1346 1584 1347 /* Initialize USBTMC bTag and other fields */ ··· 1683 1442 1684 1443 static void usbtmc_disconnect(struct usb_interface *intf) 1685 1444 { 1686 - struct usbtmc_device_data *data; 1445 + struct usbtmc_device_data *data = usb_get_intfdata(intf); 1687 1446 1688 - dev_dbg(&intf->dev, "usbtmc_disconnect called\n"); 1689 - 1690 - data = usb_get_intfdata(intf); 1691 1447 usb_deregister_dev(intf, &usbtmc_class); 1692 1448 sysfs_remove_group(&intf->dev.kobj, &capability_attr_grp); 1693 1449 sysfs_remove_group(&intf->dev.kobj, &data_attr_grp); 1694 1450 mutex_lock(&data->io_mutex); 1695 1451 data->zombie = 1; 1696 - wake_up_all(&data->waitq); 1452 + wake_up_interruptible_all(&data->waitq); 1697 1453 mutex_unlock(&data->io_mutex); 1698 1454 usbtmc_free_int(data); 1699 1455 kref_put(&data->kref, usbtmc_delete);
+3 -2
drivers/usb/core/devio.c
··· 585 585 struct siginfo sinfo; 586 586 struct pid *pid = NULL; 587 587 const struct cred *cred = NULL; 588 + unsigned long flags; 588 589 int signr; 589 590 590 - spin_lock(&ps->lock); 591 + spin_lock_irqsave(&ps->lock, flags); 591 592 list_move_tail(&as->asynclist, &ps->async_completed); 592 593 as->status = urb->status; 593 594 signr = as->signr; ··· 612 611 cancel_bulk_urbs(ps, as->bulk_addr); 613 612 614 613 wake_up(&ps->wait); 615 - spin_unlock(&ps->lock); 614 + spin_unlock_irqrestore(&ps->lock, flags); 616 615 617 616 if (signr) { 618 617 kill_pid_info_as_cred(sinfo.si_signo, &sinfo, pid, cred);
+42
drivers/usb/core/hub.c
··· 3660 3660 return 0; 3661 3661 } 3662 3662 3663 + /* Report wakeup requests from the ports of a resuming root hub */ 3664 + static void report_wakeup_requests(struct usb_hub *hub) 3665 + { 3666 + struct usb_device *hdev = hub->hdev; 3667 + struct usb_device *udev; 3668 + struct usb_hcd *hcd; 3669 + unsigned long resuming_ports; 3670 + int i; 3671 + 3672 + if (hdev->parent) 3673 + return; /* Not a root hub */ 3674 + 3675 + hcd = bus_to_hcd(hdev->bus); 3676 + if (hcd->driver->get_resuming_ports) { 3677 + 3678 + /* 3679 + * The get_resuming_ports() method returns a bitmap (origin 0) 3680 + * of ports which have started wakeup signaling but have not 3681 + * yet finished resuming. During system resume we will 3682 + * resume all the enabled ports, regardless of any wakeup 3683 + * signals, which means the wakeup requests would be lost. 3684 + * To prevent this, report them to the PM core here. 3685 + */ 3686 + resuming_ports = hcd->driver->get_resuming_ports(hcd); 3687 + for (i = 0; i < hdev->maxchild; ++i) { 3688 + if (test_bit(i, &resuming_ports)) { 3689 + udev = hub->ports[i]->child; 3690 + if (udev) 3691 + pm_wakeup_event(&udev->dev, 0); 3692 + } 3693 + } 3694 + } 3695 + } 3696 + 3663 3697 static int hub_resume(struct usb_interface *intf) 3664 3698 { 3665 3699 struct usb_hub *hub = usb_get_intfdata(intf); 3666 3700 3667 3701 dev_dbg(&intf->dev, "%s\n", __func__); 3668 3702 hub_activate(hub, HUB_RESUME); 3703 + 3704 + /* 3705 + * This should be called only for system resume, not runtime resume. 3706 + * We can't tell the difference here, so some wakeup requests will be 3707 + * reported at the wrong time or more than once. This shouldn't 3708 + * matter much, so long as they do get reported. 3709 + */ 3710 + report_wakeup_requests(hub); 3669 3711 return 0; 3670 3712 } 3671 3713
+5 -4
drivers/usb/core/message.c
··· 269 269 270 270 static void sg_complete(struct urb *urb) 271 271 { 272 + unsigned long flags; 272 273 struct usb_sg_request *io = urb->context; 273 274 int status = urb->status; 274 275 275 - spin_lock(&io->lock); 276 + spin_lock_irqsave(&io->lock, flags); 276 277 277 278 /* In 2.5 we require hcds' endpoint queues not to progress after fault 278 279 * reports, until the completion callback (this!) returns. That lets ··· 307 306 * unlink pending urbs so they won't rx/tx bad data. 308 307 * careful: unlink can sometimes be synchronous... 309 308 */ 310 - spin_unlock(&io->lock); 309 + spin_unlock_irqrestore(&io->lock, flags); 311 310 for (i = 0, found = 0; i < io->entries; i++) { 312 311 if (!io->urbs[i]) 313 312 continue; ··· 324 323 } else if (urb == io->urbs[i]) 325 324 found = 1; 326 325 } 327 - spin_lock(&io->lock); 326 + spin_lock_irqsave(&io->lock, flags); 328 327 } 329 328 330 329 /* on the last completion, signal usb_sg_wait() */ ··· 333 332 if (!io->count) 334 333 complete(&io->complete); 335 334 336 - spin_unlock(&io->lock); 335 + spin_unlock_irqrestore(&io->lock, flags); 337 336 } 338 337 339 338
+121 -120
drivers/usb/dwc2/core.c
··· 73 73 /* Backup global regs */ 74 74 gr = &hsotg->gr_backup; 75 75 76 - gr->gotgctl = dwc2_readl(hsotg->regs + GOTGCTL); 77 - gr->gintmsk = dwc2_readl(hsotg->regs + GINTMSK); 78 - gr->gahbcfg = dwc2_readl(hsotg->regs + GAHBCFG); 79 - gr->gusbcfg = dwc2_readl(hsotg->regs + GUSBCFG); 80 - gr->grxfsiz = dwc2_readl(hsotg->regs + GRXFSIZ); 81 - gr->gnptxfsiz = dwc2_readl(hsotg->regs + GNPTXFSIZ); 82 - gr->gdfifocfg = dwc2_readl(hsotg->regs + GDFIFOCFG); 83 - gr->pcgcctl1 = dwc2_readl(hsotg->regs + PCGCCTL1); 84 - gr->glpmcfg = dwc2_readl(hsotg->regs + GLPMCFG); 85 - gr->gi2cctl = dwc2_readl(hsotg->regs + GI2CCTL); 86 - gr->pcgcctl = dwc2_readl(hsotg->regs + PCGCTL); 76 + gr->gotgctl = dwc2_readl(hsotg, GOTGCTL); 77 + gr->gintmsk = dwc2_readl(hsotg, GINTMSK); 78 + gr->gahbcfg = dwc2_readl(hsotg, GAHBCFG); 79 + gr->gusbcfg = dwc2_readl(hsotg, GUSBCFG); 80 + gr->grxfsiz = dwc2_readl(hsotg, GRXFSIZ); 81 + gr->gnptxfsiz = dwc2_readl(hsotg, GNPTXFSIZ); 82 + gr->gdfifocfg = dwc2_readl(hsotg, GDFIFOCFG); 83 + gr->pcgcctl1 = dwc2_readl(hsotg, PCGCCTL1); 84 + gr->glpmcfg = dwc2_readl(hsotg, GLPMCFG); 85 + gr->gi2cctl = dwc2_readl(hsotg, GI2CCTL); 86 + gr->pcgcctl = dwc2_readl(hsotg, PCGCTL); 87 87 88 88 gr->valid = true; 89 89 return 0; ··· 111 111 } 112 112 gr->valid = false; 113 113 114 - dwc2_writel(0xffffffff, hsotg->regs + GINTSTS); 115 - dwc2_writel(gr->gotgctl, hsotg->regs + GOTGCTL); 116 - dwc2_writel(gr->gintmsk, hsotg->regs + GINTMSK); 117 - dwc2_writel(gr->gusbcfg, hsotg->regs + GUSBCFG); 118 - dwc2_writel(gr->gahbcfg, hsotg->regs + GAHBCFG); 119 - dwc2_writel(gr->grxfsiz, hsotg->regs + GRXFSIZ); 120 - dwc2_writel(gr->gnptxfsiz, hsotg->regs + GNPTXFSIZ); 121 - dwc2_writel(gr->gdfifocfg, hsotg->regs + GDFIFOCFG); 122 - dwc2_writel(gr->pcgcctl1, hsotg->regs + PCGCCTL1); 123 - dwc2_writel(gr->glpmcfg, hsotg->regs + GLPMCFG); 124 - dwc2_writel(gr->pcgcctl, hsotg->regs + PCGCTL); 125 - dwc2_writel(gr->gi2cctl, hsotg->regs + GI2CCTL); 114 + dwc2_writel(hsotg, 0xffffffff, GINTSTS); 115 + dwc2_writel(hsotg, gr->gotgctl, GOTGCTL); 116 + dwc2_writel(hsotg, gr->gintmsk, GINTMSK); 117 + dwc2_writel(hsotg, gr->gusbcfg, GUSBCFG); 118 + dwc2_writel(hsotg, gr->gahbcfg, GAHBCFG); 119 + dwc2_writel(hsotg, gr->grxfsiz, GRXFSIZ); 120 + dwc2_writel(hsotg, gr->gnptxfsiz, GNPTXFSIZ); 121 + dwc2_writel(hsotg, gr->gdfifocfg, GDFIFOCFG); 122 + dwc2_writel(hsotg, gr->pcgcctl1, PCGCCTL1); 123 + dwc2_writel(hsotg, gr->glpmcfg, GLPMCFG); 124 + dwc2_writel(hsotg, gr->pcgcctl, PCGCTL); 125 + dwc2_writel(hsotg, gr->gi2cctl, GI2CCTL); 126 126 127 127 return 0; 128 128 } ··· 141 141 if (hsotg->params.power_down != DWC2_POWER_DOWN_PARAM_PARTIAL) 142 142 return -ENOTSUPP; 143 143 144 - pcgcctl = dwc2_readl(hsotg->regs + PCGCTL); 144 + pcgcctl = dwc2_readl(hsotg, PCGCTL); 145 145 pcgcctl &= ~PCGCTL_STOPPCLK; 146 - dwc2_writel(pcgcctl, hsotg->regs + PCGCTL); 146 + dwc2_writel(hsotg, pcgcctl, PCGCTL); 147 147 148 - pcgcctl = dwc2_readl(hsotg->regs + PCGCTL); 148 + pcgcctl = dwc2_readl(hsotg, PCGCTL); 149 149 pcgcctl &= ~PCGCTL_PWRCLMP; 150 - dwc2_writel(pcgcctl, hsotg->regs + PCGCTL); 150 + dwc2_writel(hsotg, pcgcctl, PCGCTL); 151 151 152 - pcgcctl = dwc2_readl(hsotg->regs + PCGCTL); 152 + pcgcctl = dwc2_readl(hsotg, PCGCTL); 153 153 pcgcctl &= ~PCGCTL_RSTPDWNMODULE; 154 - dwc2_writel(pcgcctl, hsotg->regs + PCGCTL); 154 + dwc2_writel(hsotg, pcgcctl, PCGCTL); 155 155 156 156 udelay(100); 157 157 if (restore) { ··· 222 222 * Clear any pending interrupts since dwc2 will not be able to 223 223 * clear them after entering partial_power_down. 224 224 */ 225 - dwc2_writel(0xffffffff, hsotg->regs + GINTSTS); 225 + dwc2_writel(hsotg, 0xffffffff, GINTSTS); 226 226 227 227 /* Put the controller in low power state */ 228 - pcgcctl = dwc2_readl(hsotg->regs + PCGCTL); 228 + pcgcctl = dwc2_readl(hsotg, PCGCTL); 229 229 230 230 pcgcctl |= PCGCTL_PWRCLMP; 231 - dwc2_writel(pcgcctl, hsotg->regs + PCGCTL); 231 + dwc2_writel(hsotg, pcgcctl, PCGCTL); 232 232 ndelay(20); 233 233 234 234 pcgcctl |= PCGCTL_RSTPDWNMODULE; 235 - dwc2_writel(pcgcctl, hsotg->regs + PCGCTL); 235 + dwc2_writel(hsotg, pcgcctl, PCGCTL); 236 236 ndelay(20); 237 237 238 238 pcgcctl |= PCGCTL_STOPPCLK; 239 - dwc2_writel(pcgcctl, hsotg->regs + PCGCTL); 239 + dwc2_writel(hsotg, pcgcctl, PCGCTL); 240 240 241 241 return ret; 242 242 } ··· 272 272 if (!(pcgcctl & PCGCTL_P2HD_DEV_ENUM_SPD_MASK)) 273 273 pcgcctl |= BIT(17); 274 274 } 275 - dwc2_writel(pcgcctl, hsotg->regs + PCGCTL); 275 + dwc2_writel(hsotg, pcgcctl, PCGCTL); 276 276 277 277 /* Umnask global Interrupt in GAHBCFG and restore it */ 278 - dwc2_writel(gr->gahbcfg | GAHBCFG_GLBL_INTR_EN, hsotg->regs + GAHBCFG); 278 + dwc2_writel(hsotg, gr->gahbcfg | GAHBCFG_GLBL_INTR_EN, GAHBCFG); 279 279 280 280 /* Clear all pending interupts */ 281 - dwc2_writel(0xffffffff, hsotg->regs + GINTSTS); 281 + dwc2_writel(hsotg, 0xffffffff, GINTSTS); 282 282 283 283 /* Unmask restore done interrupt */ 284 - dwc2_writel(GINTSTS_RESTOREDONE, hsotg->regs + GINTMSK); 284 + dwc2_writel(hsotg, GINTSTS_RESTOREDONE, GINTMSK); 285 285 286 286 /* Restore GUSBCFG and HCFG/DCFG */ 287 - dwc2_writel(gr->gusbcfg, hsotg->regs + GUSBCFG); 287 + dwc2_writel(hsotg, gr->gusbcfg, GUSBCFG); 288 288 289 289 if (is_host) { 290 - dwc2_writel(hr->hcfg, hsotg->regs + HCFG); 290 + dwc2_writel(hsotg, hr->hcfg, HCFG); 291 291 if (rmode) 292 292 pcgcctl |= PCGCTL_RESTOREMODE; 293 - dwc2_writel(pcgcctl, hsotg->regs + PCGCTL); 293 + dwc2_writel(hsotg, pcgcctl, PCGCTL); 294 294 udelay(10); 295 295 296 296 pcgcctl |= PCGCTL_ESS_REG_RESTORED; 297 - dwc2_writel(pcgcctl, hsotg->regs + PCGCTL); 297 + dwc2_writel(hsotg, pcgcctl, PCGCTL); 298 298 udelay(10); 299 299 } else { 300 - dwc2_writel(dr->dcfg, hsotg->regs + DCFG); 300 + dwc2_writel(hsotg, dr->dcfg, DCFG); 301 301 if (!rmode) 302 302 pcgcctl |= PCGCTL_RESTOREMODE | PCGCTL_RSTPDWNMODULE; 303 - dwc2_writel(pcgcctl, hsotg->regs + PCGCTL); 303 + dwc2_writel(hsotg, pcgcctl, PCGCTL); 304 304 udelay(10); 305 305 306 306 pcgcctl |= PCGCTL_ESS_REG_RESTORED; 307 - dwc2_writel(pcgcctl, hsotg->regs + PCGCTL); 307 + dwc2_writel(hsotg, pcgcctl, PCGCTL); 308 308 udelay(10); 309 309 } 310 310 } ··· 322 322 u32 gpwrdn; 323 323 324 324 /* Switch-on voltage to the core */ 325 - gpwrdn = dwc2_readl(hsotg->regs + GPWRDN); 325 + gpwrdn = dwc2_readl(hsotg, GPWRDN); 326 326 gpwrdn &= ~GPWRDN_PWRDNSWTCH; 327 - dwc2_writel(gpwrdn, hsotg->regs + GPWRDN); 327 + dwc2_writel(hsotg, gpwrdn, GPWRDN); 328 328 udelay(10); 329 329 330 330 /* Reset core */ 331 - gpwrdn = dwc2_readl(hsotg->regs + GPWRDN); 331 + gpwrdn = dwc2_readl(hsotg, GPWRDN); 332 332 gpwrdn &= ~GPWRDN_PWRDNRSTN; 333 - dwc2_writel(gpwrdn, hsotg->regs + GPWRDN); 333 + dwc2_writel(hsotg, gpwrdn, GPWRDN); 334 334 udelay(10); 335 335 336 336 /* Enable restore from PMU */ 337 - gpwrdn = dwc2_readl(hsotg->regs + GPWRDN); 337 + gpwrdn = dwc2_readl(hsotg, GPWRDN); 338 338 gpwrdn |= GPWRDN_RESTORE; 339 - dwc2_writel(gpwrdn, hsotg->regs + GPWRDN); 339 + dwc2_writel(hsotg, gpwrdn, GPWRDN); 340 340 udelay(10); 341 341 342 342 /* Disable Power Down Clamp */ 343 - gpwrdn = dwc2_readl(hsotg->regs + GPWRDN); 343 + gpwrdn = dwc2_readl(hsotg, GPWRDN); 344 344 gpwrdn &= ~GPWRDN_PWRDNCLMP; 345 - dwc2_writel(gpwrdn, hsotg->regs + GPWRDN); 345 + dwc2_writel(hsotg, gpwrdn, GPWRDN); 346 346 udelay(50); 347 347 348 348 if (!is_host && rem_wakeup) 349 349 udelay(70); 350 350 351 351 /* Deassert reset core */ 352 - gpwrdn = dwc2_readl(hsotg->regs + GPWRDN); 352 + gpwrdn = dwc2_readl(hsotg, GPWRDN); 353 353 gpwrdn |= GPWRDN_PWRDNRSTN; 354 - dwc2_writel(gpwrdn, hsotg->regs + GPWRDN); 354 + dwc2_writel(hsotg, gpwrdn, GPWRDN); 355 355 udelay(10); 356 356 357 357 /* Disable PMU interrupt */ 358 - gpwrdn = dwc2_readl(hsotg->regs + GPWRDN); 358 + gpwrdn = dwc2_readl(hsotg, GPWRDN); 359 359 gpwrdn &= ~GPWRDN_PMUINTSEL; 360 - dwc2_writel(gpwrdn, hsotg->regs + GPWRDN); 360 + dwc2_writel(hsotg, gpwrdn, GPWRDN); 361 361 udelay(10); 362 362 363 363 /* Set Restore Essential Regs bit in PCGCCTL register */ ··· 431 431 return false; 432 432 433 433 /* Check if core configuration includes the IDDIG filter. */ 434 - ghwcfg4 = dwc2_readl(hsotg->regs + GHWCFG4); 434 + ghwcfg4 = dwc2_readl(hsotg, GHWCFG4); 435 435 if (!(ghwcfg4 & GHWCFG4_IDDIG_FILT_EN)) 436 436 return false; 437 437 ··· 439 439 * Check if the IDDIG debounce filter is bypassed. Available 440 440 * in core version >= 3.10a. 441 441 */ 442 - gsnpsid = dwc2_readl(hsotg->regs + GSNPSID); 442 + gsnpsid = dwc2_readl(hsotg, GSNPSID); 443 443 if (gsnpsid >= DWC2_CORE_REV_3_10a) { 444 - u32 gotgctl = dwc2_readl(hsotg->regs + GOTGCTL); 444 + u32 gotgctl = dwc2_readl(hsotg, GOTGCTL); 445 445 446 446 if (gotgctl & GOTGCTL_DBNCE_FLTR_BYPASS) 447 447 return false; ··· 510 510 * reset and account for this delay after the reset. 511 511 */ 512 512 if (dwc2_iddig_filter_enabled(hsotg)) { 513 - u32 gotgctl = dwc2_readl(hsotg->regs + GOTGCTL); 514 - u32 gusbcfg = dwc2_readl(hsotg->regs + GUSBCFG); 513 + u32 gotgctl = dwc2_readl(hsotg, GOTGCTL); 514 + u32 gusbcfg = dwc2_readl(hsotg, GUSBCFG); 515 515 516 516 if (!(gotgctl & GOTGCTL_CONID_B) || 517 517 (gusbcfg & GUSBCFG_FORCEHOSTMODE)) { ··· 520 520 } 521 521 522 522 /* Core Soft Reset */ 523 - greset = dwc2_readl(hsotg->regs + GRSTCTL); 523 + greset = dwc2_readl(hsotg, GRSTCTL); 524 524 greset |= GRSTCTL_CSFTRST; 525 - dwc2_writel(greset, hsotg->regs + GRSTCTL); 525 + dwc2_writel(hsotg, greset, GRSTCTL); 526 526 527 527 if (dwc2_hsotg_wait_bit_clear(hsotg, GRSTCTL, GRSTCTL_CSFTRST, 50)) { 528 528 dev_warn(hsotg->dev, "%s: HANG! Soft Reset timeout GRSTCTL GRSTCTL_CSFTRST\n", ··· 594 594 if (WARN_ON(!host && hsotg->dr_mode == USB_DR_MODE_HOST)) 595 595 return; 596 596 597 - gusbcfg = dwc2_readl(hsotg->regs + GUSBCFG); 597 + gusbcfg = dwc2_readl(hsotg, GUSBCFG); 598 598 599 599 set = host ? GUSBCFG_FORCEHOSTMODE : GUSBCFG_FORCEDEVMODE; 600 600 clear = host ? GUSBCFG_FORCEDEVMODE : GUSBCFG_FORCEHOSTMODE; 601 601 602 602 gusbcfg &= ~clear; 603 603 gusbcfg |= set; 604 - dwc2_writel(gusbcfg, hsotg->regs + GUSBCFG); 604 + dwc2_writel(hsotg, gusbcfg, GUSBCFG); 605 605 606 606 dwc2_wait_for_mode(hsotg, host); 607 607 return; ··· 627 627 628 628 dev_dbg(hsotg->dev, "Clearing force mode bits\n"); 629 629 630 - gusbcfg = dwc2_readl(hsotg->regs + GUSBCFG); 630 + gusbcfg = dwc2_readl(hsotg, GUSBCFG); 631 631 gusbcfg &= ~GUSBCFG_FORCEHOSTMODE; 632 632 gusbcfg &= ~GUSBCFG_FORCEDEVMODE; 633 - dwc2_writel(gusbcfg, hsotg->regs + GUSBCFG); 633 + dwc2_writel(hsotg, gusbcfg, GUSBCFG); 634 634 635 635 if (dwc2_iddig_filter_enabled(hsotg)) 636 636 msleep(100); ··· 670 670 void dwc2_enable_acg(struct dwc2_hsotg *hsotg) 671 671 { 672 672 if (hsotg->params.acg_enable) { 673 - u32 pcgcctl1 = dwc2_readl(hsotg->regs + PCGCCTL1); 673 + u32 pcgcctl1 = dwc2_readl(hsotg, PCGCCTL1); 674 674 675 675 dev_dbg(hsotg->dev, "Enabling Active Clock Gating\n"); 676 676 pcgcctl1 |= PCGCCTL1_GATEEN; 677 - dwc2_writel(pcgcctl1, hsotg->regs + PCGCCTL1); 677 + dwc2_writel(hsotg, pcgcctl1, PCGCCTL1); 678 678 } 679 679 } 680 680 ··· 695 695 dev_dbg(hsotg->dev, "Host Global Registers\n"); 696 696 addr = hsotg->regs + HCFG; 697 697 dev_dbg(hsotg->dev, "HCFG @0x%08lX : 0x%08X\n", 698 - (unsigned long)addr, dwc2_readl(addr)); 698 + (unsigned long)addr, dwc2_readl(hsotg, HCFG)); 699 699 addr = hsotg->regs + HFIR; 700 700 dev_dbg(hsotg->dev, "HFIR @0x%08lX : 0x%08X\n", 701 - (unsigned long)addr, dwc2_readl(addr)); 701 + (unsigned long)addr, dwc2_readl(hsotg, HFIR)); 702 702 addr = hsotg->regs + HFNUM; 703 703 dev_dbg(hsotg->dev, "HFNUM @0x%08lX : 0x%08X\n", 704 - (unsigned long)addr, dwc2_readl(addr)); 704 + (unsigned long)addr, dwc2_readl(hsotg, HFNUM)); 705 705 addr = hsotg->regs + HPTXSTS; 706 706 dev_dbg(hsotg->dev, "HPTXSTS @0x%08lX : 0x%08X\n", 707 - (unsigned long)addr, dwc2_readl(addr)); 707 + (unsigned long)addr, dwc2_readl(hsotg, HPTXSTS)); 708 708 addr = hsotg->regs + HAINT; 709 709 dev_dbg(hsotg->dev, "HAINT @0x%08lX : 0x%08X\n", 710 - (unsigned long)addr, dwc2_readl(addr)); 710 + (unsigned long)addr, dwc2_readl(hsotg, HAINT)); 711 711 addr = hsotg->regs + HAINTMSK; 712 712 dev_dbg(hsotg->dev, "HAINTMSK @0x%08lX : 0x%08X\n", 713 - (unsigned long)addr, dwc2_readl(addr)); 713 + (unsigned long)addr, dwc2_readl(hsotg, HAINTMSK)); 714 714 if (hsotg->params.dma_desc_enable) { 715 715 addr = hsotg->regs + HFLBADDR; 716 716 dev_dbg(hsotg->dev, "HFLBADDR @0x%08lX : 0x%08X\n", 717 - (unsigned long)addr, dwc2_readl(addr)); 717 + (unsigned long)addr, dwc2_readl(hsotg, HFLBADDR)); 718 718 } 719 719 720 720 addr = hsotg->regs + HPRT0; 721 721 dev_dbg(hsotg->dev, "HPRT0 @0x%08lX : 0x%08X\n", 722 - (unsigned long)addr, dwc2_readl(addr)); 722 + (unsigned long)addr, dwc2_readl(hsotg, HPRT0)); 723 723 724 724 for (i = 0; i < hsotg->params.host_channels; i++) { 725 725 dev_dbg(hsotg->dev, "Host Channel %d Specific Registers\n", i); 726 726 addr = hsotg->regs + HCCHAR(i); 727 727 dev_dbg(hsotg->dev, "HCCHAR @0x%08lX : 0x%08X\n", 728 - (unsigned long)addr, dwc2_readl(addr)); 728 + (unsigned long)addr, dwc2_readl(hsotg, HCCHAR(i))); 729 729 addr = hsotg->regs + HCSPLT(i); 730 730 dev_dbg(hsotg->dev, "HCSPLT @0x%08lX : 0x%08X\n", 731 - (unsigned long)addr, dwc2_readl(addr)); 731 + (unsigned long)addr, dwc2_readl(hsotg, HCSPLT(i))); 732 732 addr = hsotg->regs + HCINT(i); 733 733 dev_dbg(hsotg->dev, "HCINT @0x%08lX : 0x%08X\n", 734 - (unsigned long)addr, dwc2_readl(addr)); 734 + (unsigned long)addr, dwc2_readl(hsotg, HCINT(i))); 735 735 addr = hsotg->regs + HCINTMSK(i); 736 736 dev_dbg(hsotg->dev, "HCINTMSK @0x%08lX : 0x%08X\n", 737 - (unsigned long)addr, dwc2_readl(addr)); 737 + (unsigned long)addr, dwc2_readl(hsotg, HCINTMSK(i))); 738 738 addr = hsotg->regs + HCTSIZ(i); 739 739 dev_dbg(hsotg->dev, "HCTSIZ @0x%08lX : 0x%08X\n", 740 - (unsigned long)addr, dwc2_readl(addr)); 740 + (unsigned long)addr, dwc2_readl(hsotg, HCTSIZ(i))); 741 741 addr = hsotg->regs + HCDMA(i); 742 742 dev_dbg(hsotg->dev, "HCDMA @0x%08lX : 0x%08X\n", 743 - (unsigned long)addr, dwc2_readl(addr)); 743 + (unsigned long)addr, dwc2_readl(hsotg, HCDMA(i))); 744 744 if (hsotg->params.dma_desc_enable) { 745 745 addr = hsotg->regs + HCDMAB(i); 746 746 dev_dbg(hsotg->dev, "HCDMAB @0x%08lX : 0x%08X\n", 747 - (unsigned long)addr, dwc2_readl(addr)); 747 + (unsigned long)addr, dwc2_readl(hsotg, 748 + HCDMAB(i))); 748 749 } 749 750 } 750 751 #endif ··· 767 766 dev_dbg(hsotg->dev, "Core Global Registers\n"); 768 767 addr = hsotg->regs + GOTGCTL; 769 768 dev_dbg(hsotg->dev, "GOTGCTL @0x%08lX : 0x%08X\n", 770 - (unsigned long)addr, dwc2_readl(addr)); 769 + (unsigned long)addr, dwc2_readl(hsotg, GOTGCTL)); 771 770 addr = hsotg->regs + GOTGINT; 772 771 dev_dbg(hsotg->dev, "GOTGINT @0x%08lX : 0x%08X\n", 773 - (unsigned long)addr, dwc2_readl(addr)); 772 + (unsigned long)addr, dwc2_readl(hsotg, GOTGINT)); 774 773 addr = hsotg->regs + GAHBCFG; 775 774 dev_dbg(hsotg->dev, "GAHBCFG @0x%08lX : 0x%08X\n", 776 - (unsigned long)addr, dwc2_readl(addr)); 775 + (unsigned long)addr, dwc2_readl(hsotg, GAHBCFG)); 777 776 addr = hsotg->regs + GUSBCFG; 778 777 dev_dbg(hsotg->dev, "GUSBCFG @0x%08lX : 0x%08X\n", 779 - (unsigned long)addr, dwc2_readl(addr)); 778 + (unsigned long)addr, dwc2_readl(hsotg, GUSBCFG)); 780 779 addr = hsotg->regs + GRSTCTL; 781 780 dev_dbg(hsotg->dev, "GRSTCTL @0x%08lX : 0x%08X\n", 782 - (unsigned long)addr, dwc2_readl(addr)); 781 + (unsigned long)addr, dwc2_readl(hsotg, GRSTCTL)); 783 782 addr = hsotg->regs + GINTSTS; 784 783 dev_dbg(hsotg->dev, "GINTSTS @0x%08lX : 0x%08X\n", 785 - (unsigned long)addr, dwc2_readl(addr)); 784 + (unsigned long)addr, dwc2_readl(hsotg, GINTSTS)); 786 785 addr = hsotg->regs + GINTMSK; 787 786 dev_dbg(hsotg->dev, "GINTMSK @0x%08lX : 0x%08X\n", 788 - (unsigned long)addr, dwc2_readl(addr)); 787 + (unsigned long)addr, dwc2_readl(hsotg, GINTMSK)); 789 788 addr = hsotg->regs + GRXSTSR; 790 789 dev_dbg(hsotg->dev, "GRXSTSR @0x%08lX : 0x%08X\n", 791 - (unsigned long)addr, dwc2_readl(addr)); 790 + (unsigned long)addr, dwc2_readl(hsotg, GRXSTSR)); 792 791 addr = hsotg->regs + GRXFSIZ; 793 792 dev_dbg(hsotg->dev, "GRXFSIZ @0x%08lX : 0x%08X\n", 794 - (unsigned long)addr, dwc2_readl(addr)); 793 + (unsigned long)addr, dwc2_readl(hsotg, GRXFSIZ)); 795 794 addr = hsotg->regs + GNPTXFSIZ; 796 795 dev_dbg(hsotg->dev, "GNPTXFSIZ @0x%08lX : 0x%08X\n", 797 - (unsigned long)addr, dwc2_readl(addr)); 796 + (unsigned long)addr, dwc2_readl(hsotg, GNPTXFSIZ)); 798 797 addr = hsotg->regs + GNPTXSTS; 799 798 dev_dbg(hsotg->dev, "GNPTXSTS @0x%08lX : 0x%08X\n", 800 - (unsigned long)addr, dwc2_readl(addr)); 799 + (unsigned long)addr, dwc2_readl(hsotg, GNPTXSTS)); 801 800 addr = hsotg->regs + GI2CCTL; 802 801 dev_dbg(hsotg->dev, "GI2CCTL @0x%08lX : 0x%08X\n", 803 - (unsigned long)addr, dwc2_readl(addr)); 802 + (unsigned long)addr, dwc2_readl(hsotg, GI2CCTL)); 804 803 addr = hsotg->regs + GPVNDCTL; 805 804 dev_dbg(hsotg->dev, "GPVNDCTL @0x%08lX : 0x%08X\n", 806 - (unsigned long)addr, dwc2_readl(addr)); 805 + (unsigned long)addr, dwc2_readl(hsotg, GPVNDCTL)); 807 806 addr = hsotg->regs + GGPIO; 808 807 dev_dbg(hsotg->dev, "GGPIO @0x%08lX : 0x%08X\n", 809 - (unsigned long)addr, dwc2_readl(addr)); 808 + (unsigned long)addr, dwc2_readl(hsotg, GGPIO)); 810 809 addr = hsotg->regs + GUID; 811 810 dev_dbg(hsotg->dev, "GUID @0x%08lX : 0x%08X\n", 812 - (unsigned long)addr, dwc2_readl(addr)); 811 + (unsigned long)addr, dwc2_readl(hsotg, GUID)); 813 812 addr = hsotg->regs + GSNPSID; 814 813 dev_dbg(hsotg->dev, "GSNPSID @0x%08lX : 0x%08X\n", 815 - (unsigned long)addr, dwc2_readl(addr)); 814 + (unsigned long)addr, dwc2_readl(hsotg, GSNPSID)); 816 815 addr = hsotg->regs + GHWCFG1; 817 816 dev_dbg(hsotg->dev, "GHWCFG1 @0x%08lX : 0x%08X\n", 818 - (unsigned long)addr, dwc2_readl(addr)); 817 + (unsigned long)addr, dwc2_readl(hsotg, GHWCFG1)); 819 818 addr = hsotg->regs + GHWCFG2; 820 819 dev_dbg(hsotg->dev, "GHWCFG2 @0x%08lX : 0x%08X\n", 821 - (unsigned long)addr, dwc2_readl(addr)); 820 + (unsigned long)addr, dwc2_readl(hsotg, GHWCFG2)); 822 821 addr = hsotg->regs + GHWCFG3; 823 822 dev_dbg(hsotg->dev, "GHWCFG3 @0x%08lX : 0x%08X\n", 824 - (unsigned long)addr, dwc2_readl(addr)); 823 + (unsigned long)addr, dwc2_readl(hsotg, GHWCFG3)); 825 824 addr = hsotg->regs + GHWCFG4; 826 825 dev_dbg(hsotg->dev, "GHWCFG4 @0x%08lX : 0x%08X\n", 827 - (unsigned long)addr, dwc2_readl(addr)); 826 + (unsigned long)addr, dwc2_readl(hsotg, GHWCFG4)); 828 827 addr = hsotg->regs + GLPMCFG; 829 828 dev_dbg(hsotg->dev, "GLPMCFG @0x%08lX : 0x%08X\n", 830 - (unsigned long)addr, dwc2_readl(addr)); 829 + (unsigned long)addr, dwc2_readl(hsotg, GLPMCFG)); 831 830 addr = hsotg->regs + GPWRDN; 832 831 dev_dbg(hsotg->dev, "GPWRDN @0x%08lX : 0x%08X\n", 833 - (unsigned long)addr, dwc2_readl(addr)); 832 + (unsigned long)addr, dwc2_readl(hsotg, GPWRDN)); 834 833 addr = hsotg->regs + GDFIFOCFG; 835 834 dev_dbg(hsotg->dev, "GDFIFOCFG @0x%08lX : 0x%08X\n", 836 - (unsigned long)addr, dwc2_readl(addr)); 835 + (unsigned long)addr, dwc2_readl(hsotg, GDFIFOCFG)); 837 836 addr = hsotg->regs + HPTXFSIZ; 838 837 dev_dbg(hsotg->dev, "HPTXFSIZ @0x%08lX : 0x%08X\n", 839 - (unsigned long)addr, dwc2_readl(addr)); 838 + (unsigned long)addr, dwc2_readl(hsotg, HPTXFSIZ)); 840 839 841 840 addr = hsotg->regs + PCGCTL; 842 841 dev_dbg(hsotg->dev, "PCGCTL @0x%08lX : 0x%08X\n", 843 - (unsigned long)addr, dwc2_readl(addr)); 842 + (unsigned long)addr, dwc2_readl(hsotg, PCGCTL)); 844 843 #endif 845 844 } 846 845 ··· 863 862 864 863 greset = GRSTCTL_TXFFLSH; 865 864 greset |= num << GRSTCTL_TXFNUM_SHIFT & GRSTCTL_TXFNUM_MASK; 866 - dwc2_writel(greset, hsotg->regs + GRSTCTL); 865 + dwc2_writel(hsotg, greset, GRSTCTL); 867 866 868 867 if (dwc2_hsotg_wait_bit_clear(hsotg, GRSTCTL, GRSTCTL_TXFFLSH, 10000)) 869 868 dev_warn(hsotg->dev, "%s: HANG! timeout GRSTCTL GRSTCTL_TXFFLSH\n", ··· 890 889 __func__); 891 890 892 891 greset = GRSTCTL_RXFFLSH; 893 - dwc2_writel(greset, hsotg->regs + GRSTCTL); 892 + dwc2_writel(hsotg, greset, GRSTCTL); 894 893 895 894 /* Wait for RxFIFO flush done */ 896 895 if (dwc2_hsotg_wait_bit_clear(hsotg, GRSTCTL, GRSTCTL_RXFFLSH, 10000)) ··· 903 902 904 903 bool dwc2_is_controller_alive(struct dwc2_hsotg *hsotg) 905 904 { 906 - if (dwc2_readl(hsotg->regs + GSNPSID) == 0xffffffff) 905 + if (dwc2_readl(hsotg, GSNPSID) == 0xffffffff) 907 906 return false; 908 907 else 909 908 return true; ··· 917 916 */ 918 917 void dwc2_enable_global_interrupts(struct dwc2_hsotg *hsotg) 919 918 { 920 - u32 ahbcfg = dwc2_readl(hsotg->regs + GAHBCFG); 919 + u32 ahbcfg = dwc2_readl(hsotg, GAHBCFG); 921 920 922 921 ahbcfg |= GAHBCFG_GLBL_INTR_EN; 923 - dwc2_writel(ahbcfg, hsotg->regs + GAHBCFG); 922 + dwc2_writel(hsotg, ahbcfg, GAHBCFG); 924 923 } 925 924 926 925 /** ··· 931 930 */ 932 931 void dwc2_disable_global_interrupts(struct dwc2_hsotg *hsotg) 933 932 { 934 - u32 ahbcfg = dwc2_readl(hsotg->regs + GAHBCFG); 933 + u32 ahbcfg = dwc2_readl(hsotg, GAHBCFG); 935 934 936 935 ahbcfg &= ~GAHBCFG_GLBL_INTR_EN; 937 - dwc2_writel(ahbcfg, hsotg->regs + GAHBCFG); 936 + dwc2_writel(hsotg, ahbcfg, GAHBCFG); 938 937 } 939 938 940 939 /* Returns the controller's GHWCFG2.OTG_MODE. */ 941 940 unsigned int dwc2_op_mode(struct dwc2_hsotg *hsotg) 942 941 { 943 - u32 ghwcfg2 = dwc2_readl(hsotg->regs + GHWCFG2); 942 + u32 ghwcfg2 = dwc2_readl(hsotg, GHWCFG2); 944 943 945 944 return (ghwcfg2 & GHWCFG2_OP_MODE_MASK) >> 946 945 GHWCFG2_OP_MODE_SHIFT; ··· 989 988 u32 i; 990 989 991 990 for (i = 0; i < timeout; i++) { 992 - if (dwc2_readl(hsotg->regs + offset) & mask) 991 + if (dwc2_readl(hsotg, offset) & mask) 993 992 return 0; 994 993 udelay(1); 995 994 } ··· 1012 1011 u32 i; 1013 1012 1014 1013 for (i = 0; i < timeout; i++) { 1015 - if (!(dwc2_readl(hsotg->regs + offset) & mask)) 1014 + if (!(dwc2_readl(hsotg, offset) & mask)) 1016 1015 return 0; 1017 1016 udelay(1); 1018 1017 }
+53 -56
drivers/usb/dwc2/core.h
··· 65 65 DWC2_TRACE_SCHEDULER_VB(pr_fmt("%s: SCH: " fmt), \ 66 66 dev_name(hsotg->dev), ##__VA_ARGS__) 67 67 68 - #ifdef CONFIG_MIPS 69 - /* 70 - * There are some MIPS machines that can run in either big-endian 71 - * or little-endian mode and that use the dwc2 register without 72 - * a byteswap in both ways. 73 - * Unlike other architectures, MIPS apparently does not require a 74 - * barrier before the __raw_writel() to synchronize with DMA but does 75 - * require the barrier after the __raw_writel() to serialize a set of 76 - * writes. This set of operations was added specifically for MIPS and 77 - * should only be used there. 78 - */ 79 - static inline u32 dwc2_readl(const void __iomem *addr) 80 - { 81 - u32 value = __raw_readl(addr); 82 - 83 - /* In order to preserve endianness __raw_* operation is used. Therefore 84 - * a barrier is needed to ensure IO access is not re-ordered across 85 - * reads or writes 86 - */ 87 - mb(); 88 - return value; 89 - } 90 - 91 - static inline void dwc2_writel(u32 value, void __iomem *addr) 92 - { 93 - __raw_writel(value, addr); 94 - 95 - /* 96 - * In order to preserve endianness __raw_* operation is used. Therefore 97 - * a barrier is needed to ensure IO access is not re-ordered across 98 - * reads or writes 99 - */ 100 - mb(); 101 - #ifdef DWC2_LOG_WRITES 102 - pr_info("INFO:: wrote %08x to %p\n", value, addr); 103 - #endif 104 - } 105 - #else 106 - /* Normal architectures just use readl/write */ 107 - static inline u32 dwc2_readl(const void __iomem *addr) 108 - { 109 - return readl(addr); 110 - } 111 - 112 - static inline void dwc2_writel(u32 value, void __iomem *addr) 113 - { 114 - writel(value, addr); 115 - 116 - #ifdef DWC2_LOG_WRITES 117 - pr_info("info:: wrote %08x to %p\n", value, addr); 118 - #endif 119 - } 120 - #endif 121 - 122 68 /* Maximum number of Endpoints/HostChannels */ 123 69 #define MAX_EPS_CHANNELS 16 124 70 ··· 857 911 * @gr_backup: Backup of global registers during suspend 858 912 * @dr_backup: Backup of device registers during suspend 859 913 * @hr_backup: Backup of host registers during suspend 914 + * @needs_byte_swap: Specifies whether the opposite endianness. 860 915 * 861 916 * These are for host mode: 862 917 * ··· 1047 1100 1048 1101 struct dentry *debug_root; 1049 1102 struct debugfs_regset32 *regset; 1103 + bool needs_byte_swap; 1050 1104 1051 1105 /* DWC OTG HW Release versions */ 1052 1106 #define DWC2_CORE_REV_2_71a 0x4f54271a ··· 1163 1215 #endif /* CONFIG_USB_DWC2_PERIPHERAL || CONFIG_USB_DWC2_DUAL_ROLE */ 1164 1216 }; 1165 1217 1218 + /* Normal architectures just use readl/write */ 1219 + static inline u32 dwc2_readl(struct dwc2_hsotg *hsotg, u32 offset) 1220 + { 1221 + u32 val; 1222 + 1223 + val = readl(hsotg->regs + offset); 1224 + if (hsotg->needs_byte_swap) 1225 + return swab32(val); 1226 + else 1227 + return val; 1228 + } 1229 + 1230 + static inline void dwc2_writel(struct dwc2_hsotg *hsotg, u32 value, u32 offset) 1231 + { 1232 + if (hsotg->needs_byte_swap) 1233 + writel(swab32(value), hsotg->regs + offset); 1234 + else 1235 + writel(value, hsotg->regs + offset); 1236 + 1237 + #ifdef DWC2_LOG_WRITES 1238 + pr_info("info:: wrote %08x to %p\n", value, hsotg->regs + offset); 1239 + #endif 1240 + } 1241 + 1242 + static inline void dwc2_readl_rep(struct dwc2_hsotg *hsotg, u32 offset, 1243 + void *buffer, unsigned int count) 1244 + { 1245 + if (count) { 1246 + u32 *buf = buffer; 1247 + 1248 + do { 1249 + u32 x = dwc2_readl(hsotg, offset); 1250 + *buf++ = x; 1251 + } while (--count); 1252 + } 1253 + } 1254 + 1255 + static inline void dwc2_writel_rep(struct dwc2_hsotg *hsotg, u32 offset, 1256 + const void *buffer, unsigned int count) 1257 + { 1258 + if (count) { 1259 + const u32 *buf = buffer; 1260 + 1261 + do { 1262 + dwc2_writel(hsotg, *buf++, offset); 1263 + } while (--count); 1264 + } 1265 + } 1266 + 1166 1267 /* Reasons for halting a host channel */ 1167 1268 enum dwc2_halt_status { 1168 1269 DWC2_HC_XFER_NO_HALT_STATUS, ··· 1317 1320 */ 1318 1321 static inline int dwc2_is_host_mode(struct dwc2_hsotg *hsotg) 1319 1322 { 1320 - return (dwc2_readl(hsotg->regs + GINTSTS) & GINTSTS_CURMODE_HOST) != 0; 1323 + return (dwc2_readl(hsotg, GINTSTS) & GINTSTS_CURMODE_HOST) != 0; 1321 1324 } 1322 1325 1323 1326 static inline int dwc2_is_device_mode(struct dwc2_hsotg *hsotg) 1324 1327 { 1325 - return (dwc2_readl(hsotg->regs + GINTSTS) & GINTSTS_CURMODE_HOST) == 0; 1328 + return (dwc2_readl(hsotg, GINTSTS) & GINTSTS_CURMODE_HOST) == 0; 1326 1329 } 1327 1330 1328 1331 /*
+59 -59
drivers/usb/dwc2/core_intr.c
··· 81 81 */ 82 82 static void dwc2_handle_usb_port_intr(struct dwc2_hsotg *hsotg) 83 83 { 84 - u32 hprt0 = dwc2_readl(hsotg->regs + HPRT0); 84 + u32 hprt0 = dwc2_readl(hsotg, HPRT0); 85 85 86 86 if (hprt0 & HPRT0_ENACHG) { 87 87 hprt0 &= ~HPRT0_ENA; 88 - dwc2_writel(hprt0, hsotg->regs + HPRT0); 88 + dwc2_writel(hsotg, hprt0, HPRT0); 89 89 } 90 90 } 91 91 ··· 97 97 static void dwc2_handle_mode_mismatch_intr(struct dwc2_hsotg *hsotg) 98 98 { 99 99 /* Clear interrupt */ 100 - dwc2_writel(GINTSTS_MODEMIS, hsotg->regs + GINTSTS); 100 + dwc2_writel(hsotg, GINTSTS_MODEMIS, GINTSTS); 101 101 102 102 dev_warn(hsotg->dev, "Mode Mismatch Interrupt: currently in %s mode\n", 103 103 dwc2_is_host_mode(hsotg) ? "Host" : "Device"); ··· 115 115 u32 gotgctl; 116 116 u32 gintmsk; 117 117 118 - gotgint = dwc2_readl(hsotg->regs + GOTGINT); 119 - gotgctl = dwc2_readl(hsotg->regs + GOTGCTL); 118 + gotgint = dwc2_readl(hsotg, GOTGINT); 119 + gotgctl = dwc2_readl(hsotg, GOTGCTL); 120 120 dev_dbg(hsotg->dev, "++OTG Interrupt gotgint=%0x [%s]\n", gotgint, 121 121 dwc2_op_state_str(hsotg)); 122 122 ··· 124 124 dev_dbg(hsotg->dev, 125 125 " ++OTG Interrupt: Session End Detected++ (%s)\n", 126 126 dwc2_op_state_str(hsotg)); 127 - gotgctl = dwc2_readl(hsotg->regs + GOTGCTL); 127 + gotgctl = dwc2_readl(hsotg, GOTGCTL); 128 128 129 129 if (dwc2_is_device_mode(hsotg)) 130 130 dwc2_hsotg_disconnect(hsotg); ··· 150 150 hsotg->lx_state = DWC2_L0; 151 151 } 152 152 153 - gotgctl = dwc2_readl(hsotg->regs + GOTGCTL); 153 + gotgctl = dwc2_readl(hsotg, GOTGCTL); 154 154 gotgctl &= ~GOTGCTL_DEVHNPEN; 155 - dwc2_writel(gotgctl, hsotg->regs + GOTGCTL); 155 + dwc2_writel(hsotg, gotgctl, GOTGCTL); 156 156 } 157 157 158 158 if (gotgint & GOTGINT_SES_REQ_SUC_STS_CHNG) { 159 159 dev_dbg(hsotg->dev, 160 160 " ++OTG Interrupt: Session Request Success Status Change++\n"); 161 - gotgctl = dwc2_readl(hsotg->regs + GOTGCTL); 161 + gotgctl = dwc2_readl(hsotg, GOTGCTL); 162 162 if (gotgctl & GOTGCTL_SESREQSCS) { 163 163 if (hsotg->params.phy_type == DWC2_PHY_TYPE_PARAM_FS && 164 164 hsotg->params.i2c_enable) { 165 165 hsotg->srp_success = 1; 166 166 } else { 167 167 /* Clear Session Request */ 168 - gotgctl = dwc2_readl(hsotg->regs + GOTGCTL); 168 + gotgctl = dwc2_readl(hsotg, GOTGCTL); 169 169 gotgctl &= ~GOTGCTL_SESREQ; 170 - dwc2_writel(gotgctl, hsotg->regs + GOTGCTL); 170 + dwc2_writel(hsotg, gotgctl, GOTGCTL); 171 171 } 172 172 } 173 173 } ··· 177 177 * Print statements during the HNP interrupt handling 178 178 * can cause it to fail 179 179 */ 180 - gotgctl = dwc2_readl(hsotg->regs + GOTGCTL); 180 + gotgctl = dwc2_readl(hsotg, GOTGCTL); 181 181 /* 182 182 * WA for 3.00a- HW is not setting cur_mode, even sometimes 183 183 * this does not help ··· 197 197 * interrupt does not get handled and Linux 198 198 * complains loudly. 199 199 */ 200 - gintmsk = dwc2_readl(hsotg->regs + GINTMSK); 200 + gintmsk = dwc2_readl(hsotg, GINTMSK); 201 201 gintmsk &= ~GINTSTS_SOF; 202 - dwc2_writel(gintmsk, hsotg->regs + GINTMSK); 202 + dwc2_writel(hsotg, gintmsk, GINTMSK); 203 203 204 204 /* 205 205 * Call callback function with spin lock ··· 213 213 hsotg->op_state = OTG_STATE_B_HOST; 214 214 } 215 215 } else { 216 - gotgctl = dwc2_readl(hsotg->regs + GOTGCTL); 216 + gotgctl = dwc2_readl(hsotg, GOTGCTL); 217 217 gotgctl &= ~(GOTGCTL_HNPREQ | GOTGCTL_DEVHNPEN); 218 - dwc2_writel(gotgctl, hsotg->regs + GOTGCTL); 218 + dwc2_writel(hsotg, gotgctl, GOTGCTL); 219 219 dev_dbg(hsotg->dev, "HNP Failed\n"); 220 220 dev_err(hsotg->dev, 221 221 "Device Not Connected/Responding\n"); ··· 241 241 hsotg->op_state = OTG_STATE_A_PERIPHERAL; 242 242 } else { 243 243 /* Need to disable SOF interrupt immediately */ 244 - gintmsk = dwc2_readl(hsotg->regs + GINTMSK); 244 + gintmsk = dwc2_readl(hsotg, GINTMSK); 245 245 gintmsk &= ~GINTSTS_SOF; 246 - dwc2_writel(gintmsk, hsotg->regs + GINTMSK); 246 + dwc2_writel(hsotg, gintmsk, GINTMSK); 247 247 spin_unlock(&hsotg->lock); 248 248 dwc2_hcd_start(hsotg); 249 249 spin_lock(&hsotg->lock); ··· 258 258 dev_dbg(hsotg->dev, " ++OTG Interrupt: Debounce Done++\n"); 259 259 260 260 /* Clear GOTGINT */ 261 - dwc2_writel(gotgint, hsotg->regs + GOTGINT); 261 + dwc2_writel(hsotg, gotgint, GOTGINT); 262 262 } 263 263 264 264 /** ··· 276 276 u32 gintmsk; 277 277 278 278 /* Clear interrupt */ 279 - dwc2_writel(GINTSTS_CONIDSTSCHNG, hsotg->regs + GINTSTS); 279 + dwc2_writel(hsotg, GINTSTS_CONIDSTSCHNG, GINTSTS); 280 280 281 281 /* Need to disable SOF interrupt immediately */ 282 - gintmsk = dwc2_readl(hsotg->regs + GINTMSK); 282 + gintmsk = dwc2_readl(hsotg, GINTMSK); 283 283 gintmsk &= ~GINTSTS_SOF; 284 - dwc2_writel(gintmsk, hsotg->regs + GINTMSK); 284 + dwc2_writel(hsotg, gintmsk, GINTMSK); 285 285 286 286 dev_dbg(hsotg->dev, " ++Connector ID Status Change Interrupt++ (%s)\n", 287 287 dwc2_is_host_mode(hsotg) ? "Host" : "Device"); ··· 314 314 int ret; 315 315 316 316 /* Clear interrupt */ 317 - dwc2_writel(GINTSTS_SESSREQINT, hsotg->regs + GINTSTS); 317 + dwc2_writel(hsotg, GINTSTS_SESSREQINT, GINTSTS); 318 318 319 319 dev_dbg(hsotg->dev, "Session request interrupt - lx_state=%d\n", 320 320 hsotg->lx_state); ··· 351 351 return; 352 352 } 353 353 354 - glpmcfg = dwc2_readl(hsotg->regs + GLPMCFG); 354 + glpmcfg = dwc2_readl(hsotg, GLPMCFG); 355 355 if (dwc2_is_device_mode(hsotg)) { 356 356 dev_dbg(hsotg->dev, "Exit from L1 state\n"); 357 357 glpmcfg &= ~GLPMCFG_ENBLSLPM; 358 358 glpmcfg &= ~GLPMCFG_HIRD_THRES_EN; 359 - dwc2_writel(glpmcfg, hsotg->regs + GLPMCFG); 359 + dwc2_writel(hsotg, glpmcfg, GLPMCFG); 360 360 361 361 do { 362 - glpmcfg = dwc2_readl(hsotg->regs + GLPMCFG); 362 + glpmcfg = dwc2_readl(hsotg, GLPMCFG); 363 363 364 364 if (!(glpmcfg & (GLPMCFG_COREL1RES_MASK | 365 365 GLPMCFG_L1RESUMEOK | GLPMCFG_SLPSTS))) ··· 398 398 int ret; 399 399 400 400 /* Clear interrupt */ 401 - dwc2_writel(GINTSTS_WKUPINT, hsotg->regs + GINTSTS); 401 + dwc2_writel(hsotg, GINTSTS_WKUPINT, GINTSTS); 402 402 403 403 dev_dbg(hsotg->dev, "++Resume or Remote Wakeup Detected Interrupt++\n"); 404 404 dev_dbg(hsotg->dev, "%s lxstate = %d\n", __func__, hsotg->lx_state); ··· 410 410 411 411 if (dwc2_is_device_mode(hsotg)) { 412 412 dev_dbg(hsotg->dev, "DSTS=0x%0x\n", 413 - dwc2_readl(hsotg->regs + DSTS)); 413 + dwc2_readl(hsotg, DSTS)); 414 414 if (hsotg->lx_state == DWC2_L2) { 415 - u32 dctl = dwc2_readl(hsotg->regs + DCTL); 415 + u32 dctl = dwc2_readl(hsotg, DCTL); 416 416 417 417 /* Clear Remote Wakeup Signaling */ 418 418 dctl &= ~DCTL_RMTWKUPSIG; 419 - dwc2_writel(dctl, hsotg->regs + DCTL); 419 + dwc2_writel(hsotg, dctl, DCTL); 420 420 ret = dwc2_exit_partial_power_down(hsotg, true); 421 421 if (ret && (ret != -ENOTSUPP)) 422 422 dev_err(hsotg->dev, "exit power_down failed\n"); ··· 430 430 return; 431 431 432 432 if (hsotg->lx_state != DWC2_L1) { 433 - u32 pcgcctl = dwc2_readl(hsotg->regs + PCGCTL); 433 + u32 pcgcctl = dwc2_readl(hsotg, PCGCTL); 434 434 435 435 /* Restart the Phy Clock */ 436 436 pcgcctl &= ~PCGCTL_STOPPCLK; 437 - dwc2_writel(pcgcctl, hsotg->regs + PCGCTL); 437 + dwc2_writel(hsotg, pcgcctl, PCGCTL); 438 438 mod_timer(&hsotg->wkp_timer, 439 439 jiffies + msecs_to_jiffies(71)); 440 440 } else { ··· 450 450 */ 451 451 static void dwc2_handle_disconnect_intr(struct dwc2_hsotg *hsotg) 452 452 { 453 - dwc2_writel(GINTSTS_DISCONNINT, hsotg->regs + GINTSTS); 453 + dwc2_writel(hsotg, GINTSTS_DISCONNINT, GINTSTS); 454 454 455 455 dev_dbg(hsotg->dev, "++Disconnect Detected Interrupt++ (%s) %s\n", 456 456 dwc2_is_host_mode(hsotg) ? "Host" : "Device", ··· 474 474 int ret; 475 475 476 476 /* Clear interrupt */ 477 - dwc2_writel(GINTSTS_USBSUSP, hsotg->regs + GINTSTS); 477 + dwc2_writel(hsotg, GINTSTS_USBSUSP, GINTSTS); 478 478 479 479 dev_dbg(hsotg->dev, "USB SUSPEND\n"); 480 480 ··· 483 483 * Check the Device status register to determine if the Suspend 484 484 * state is active 485 485 */ 486 - dsts = dwc2_readl(hsotg->regs + DSTS); 486 + dsts = dwc2_readl(hsotg, DSTS); 487 487 dev_dbg(hsotg->dev, "%s: DSTS=0x%0x\n", __func__, dsts); 488 488 dev_dbg(hsotg->dev, 489 489 "DSTS.Suspend Status=%d HWCFG4.Power Optimize=%d HWCFG4.Hibernation=%d\n", ··· 563 563 u32 enslpm; 564 564 565 565 /* Clear interrupt */ 566 - dwc2_writel(GINTSTS_LPMTRANRCVD, hsotg->regs + GINTSTS); 566 + dwc2_writel(hsotg, GINTSTS_LPMTRANRCVD, GINTSTS); 567 567 568 - glpmcfg = dwc2_readl(hsotg->regs + GLPMCFG); 568 + glpmcfg = dwc2_readl(hsotg, GLPMCFG); 569 569 570 570 if (!(glpmcfg & GLPMCFG_LPMCAP)) { 571 571 dev_err(hsotg->dev, "Unexpected LPM interrupt\n"); ··· 588 588 } else { 589 589 dev_dbg(hsotg->dev, "Entering Sleep with L1 Gating\n"); 590 590 591 - pcgcctl = dwc2_readl(hsotg->regs + PCGCTL); 591 + pcgcctl = dwc2_readl(hsotg, PCGCTL); 592 592 pcgcctl |= PCGCTL_ENBL_SLEEP_GATING; 593 - dwc2_writel(pcgcctl, hsotg->regs + PCGCTL); 593 + dwc2_writel(hsotg, pcgcctl, PCGCTL); 594 594 } 595 595 /** 596 596 * Examine prt_sleep_sts after TL1TokenTetry period max (10 us) 597 597 */ 598 598 udelay(10); 599 599 600 - glpmcfg = dwc2_readl(hsotg->regs + GLPMCFG); 600 + glpmcfg = dwc2_readl(hsotg, GLPMCFG); 601 601 602 602 if (glpmcfg & GLPMCFG_SLPSTS) { 603 603 /* Save the current state */ ··· 627 627 u32 gahbcfg; 628 628 u32 gintmsk_common = GINTMSK_COMMON; 629 629 630 - gintsts = dwc2_readl(hsotg->regs + GINTSTS); 631 - gintmsk = dwc2_readl(hsotg->regs + GINTMSK); 632 - gahbcfg = dwc2_readl(hsotg->regs + GAHBCFG); 630 + gintsts = dwc2_readl(hsotg, GINTSTS); 631 + gintmsk = dwc2_readl(hsotg, GINTMSK); 632 + gahbcfg = dwc2_readl(hsotg, GAHBCFG); 633 633 634 634 /* If any common interrupts set */ 635 635 if (gintsts & gintmsk_common) ··· 653 653 u32 gpwrdn; 654 654 int linestate; 655 655 656 - gpwrdn = dwc2_readl(hsotg->regs + GPWRDN); 656 + gpwrdn = dwc2_readl(hsotg, GPWRDN); 657 657 /* clear all interrupt */ 658 - dwc2_writel(gpwrdn, hsotg->regs + GPWRDN); 658 + dwc2_writel(hsotg, gpwrdn, GPWRDN); 659 659 linestate = (gpwrdn & GPWRDN_LINESTATE_MASK) >> GPWRDN_LINESTATE_SHIFT; 660 660 dev_dbg(hsotg->dev, 661 661 "%s: dwc2_handle_gpwrdwn_intr called gpwrdn= %08x\n", __func__, ··· 668 668 dev_dbg(hsotg->dev, "%s: GPWRDN_DISCONN_DET\n", __func__); 669 669 670 670 /* Switch-on voltage to the core */ 671 - gpwrdn_tmp = dwc2_readl(hsotg->regs + GPWRDN); 671 + gpwrdn_tmp = dwc2_readl(hsotg, GPWRDN); 672 672 gpwrdn_tmp &= ~GPWRDN_PWRDNSWTCH; 673 - dwc2_writel(gpwrdn_tmp, hsotg->regs + GPWRDN); 673 + dwc2_writel(hsotg, gpwrdn_tmp, GPWRDN); 674 674 udelay(10); 675 675 676 676 /* Reset core */ 677 - gpwrdn_tmp = dwc2_readl(hsotg->regs + GPWRDN); 677 + gpwrdn_tmp = dwc2_readl(hsotg, GPWRDN); 678 678 gpwrdn_tmp &= ~GPWRDN_PWRDNRSTN; 679 - dwc2_writel(gpwrdn_tmp, hsotg->regs + GPWRDN); 679 + dwc2_writel(hsotg, gpwrdn_tmp, GPWRDN); 680 680 udelay(10); 681 681 682 682 /* Disable Power Down Clamp */ 683 - gpwrdn_tmp = dwc2_readl(hsotg->regs + GPWRDN); 683 + gpwrdn_tmp = dwc2_readl(hsotg, GPWRDN); 684 684 gpwrdn_tmp &= ~GPWRDN_PWRDNCLMP; 685 - dwc2_writel(gpwrdn_tmp, hsotg->regs + GPWRDN); 685 + dwc2_writel(hsotg, gpwrdn_tmp, GPWRDN); 686 686 udelay(10); 687 687 688 688 /* Deassert reset core */ 689 - gpwrdn_tmp = dwc2_readl(hsotg->regs + GPWRDN); 689 + gpwrdn_tmp = dwc2_readl(hsotg, GPWRDN); 690 690 gpwrdn_tmp |= GPWRDN_PWRDNRSTN; 691 - dwc2_writel(gpwrdn_tmp, hsotg->regs + GPWRDN); 691 + dwc2_writel(hsotg, gpwrdn_tmp, GPWRDN); 692 692 udelay(10); 693 693 694 694 /* Disable PMU interrupt */ 695 - gpwrdn_tmp = dwc2_readl(hsotg->regs + GPWRDN); 695 + gpwrdn_tmp = dwc2_readl(hsotg, GPWRDN); 696 696 gpwrdn_tmp &= ~GPWRDN_PMUINTSEL; 697 - dwc2_writel(gpwrdn_tmp, hsotg->regs + GPWRDN); 697 + dwc2_writel(hsotg, gpwrdn_tmp, GPWRDN); 698 698 699 699 /* De-assert Wakeup Logic */ 700 - gpwrdn_tmp = dwc2_readl(hsotg->regs + GPWRDN); 700 + gpwrdn_tmp = dwc2_readl(hsotg, GPWRDN); 701 701 gpwrdn_tmp &= ~GPWRDN_PMUACTV; 702 - dwc2_writel(gpwrdn_tmp, hsotg->regs + GPWRDN); 702 + dwc2_writel(hsotg, gpwrdn_tmp, GPWRDN); 703 703 704 704 hsotg->hibernated = 0; 705 705 ··· 780 780 781 781 /* Reading current frame number value in device or host modes. */ 782 782 if (dwc2_is_device_mode(hsotg)) 783 - hsotg->frame_number = (dwc2_readl(hsotg->regs + DSTS) 783 + hsotg->frame_number = (dwc2_readl(hsotg, DSTS) 784 784 & DSTS_SOFFN_MASK) >> DSTS_SOFFN_SHIFT; 785 785 else 786 - hsotg->frame_number = (dwc2_readl(hsotg->regs + HFNUM) 786 + hsotg->frame_number = (dwc2_readl(hsotg, HFNUM) 787 787 & HFNUM_FRNUM_MASK) >> HFNUM_FRNUM_SHIFT; 788 788 789 789 gintsts = dwc2_read_common_intr(hsotg);
+26 -29
drivers/usb/dwc2/debugfs.c
··· 69 69 int dctl; 70 70 71 71 spin_lock_irqsave(&hsotg->lock, flags); 72 - dctl = dwc2_readl(hsotg->regs + DCTL); 72 + dctl = dwc2_readl(hsotg, DCTL); 73 73 dctl &= DCTL_TSTCTL_MASK; 74 74 dctl >>= DCTL_TSTCTL_SHIFT; 75 75 spin_unlock_irqrestore(&hsotg->lock, flags); ··· 126 126 static int state_show(struct seq_file *seq, void *v) 127 127 { 128 128 struct dwc2_hsotg *hsotg = seq->private; 129 - void __iomem *regs = hsotg->regs; 130 129 int idx; 131 130 132 131 seq_printf(seq, "DCFG=0x%08x, DCTL=0x%08x, DSTS=0x%08x\n", 133 - dwc2_readl(regs + DCFG), 134 - dwc2_readl(regs + DCTL), 135 - dwc2_readl(regs + DSTS)); 132 + dwc2_readl(hsotg, DCFG), 133 + dwc2_readl(hsotg, DCTL), 134 + dwc2_readl(hsotg, DSTS)); 136 135 137 136 seq_printf(seq, "DIEPMSK=0x%08x, DOEPMASK=0x%08x\n", 138 - dwc2_readl(regs + DIEPMSK), dwc2_readl(regs + DOEPMSK)); 137 + dwc2_readl(hsotg, DIEPMSK), dwc2_readl(hsotg, DOEPMSK)); 139 138 140 139 seq_printf(seq, "GINTMSK=0x%08x, GINTSTS=0x%08x\n", 141 - dwc2_readl(regs + GINTMSK), 142 - dwc2_readl(regs + GINTSTS)); 140 + dwc2_readl(hsotg, GINTMSK), 141 + dwc2_readl(hsotg, GINTSTS)); 143 142 144 143 seq_printf(seq, "DAINTMSK=0x%08x, DAINT=0x%08x\n", 145 - dwc2_readl(regs + DAINTMSK), 146 - dwc2_readl(regs + DAINT)); 144 + dwc2_readl(hsotg, DAINTMSK), 145 + dwc2_readl(hsotg, DAINT)); 147 146 148 147 seq_printf(seq, "GNPTXSTS=0x%08x, GRXSTSR=%08x\n", 149 - dwc2_readl(regs + GNPTXSTS), 150 - dwc2_readl(regs + GRXSTSR)); 148 + dwc2_readl(hsotg, GNPTXSTS), 149 + dwc2_readl(hsotg, GRXSTSR)); 151 150 152 151 seq_puts(seq, "\nEndpoint status:\n"); 153 152 154 153 for (idx = 0; idx < hsotg->num_of_eps; idx++) { 155 154 u32 in, out; 156 155 157 - in = dwc2_readl(regs + DIEPCTL(idx)); 158 - out = dwc2_readl(regs + DOEPCTL(idx)); 156 + in = dwc2_readl(hsotg, DIEPCTL(idx)); 157 + out = dwc2_readl(hsotg, DOEPCTL(idx)); 159 158 160 159 seq_printf(seq, "ep%d: DIEPCTL=0x%08x, DOEPCTL=0x%08x", 161 160 idx, in, out); 162 161 163 - in = dwc2_readl(regs + DIEPTSIZ(idx)); 164 - out = dwc2_readl(regs + DOEPTSIZ(idx)); 162 + in = dwc2_readl(hsotg, DIEPTSIZ(idx)); 163 + out = dwc2_readl(hsotg, DOEPTSIZ(idx)); 165 164 166 165 seq_printf(seq, ", DIEPTSIZ=0x%08x, DOEPTSIZ=0x%08x", 167 166 in, out); ··· 183 184 static int fifo_show(struct seq_file *seq, void *v) 184 185 { 185 186 struct dwc2_hsotg *hsotg = seq->private; 186 - void __iomem *regs = hsotg->regs; 187 187 u32 val; 188 188 int idx; 189 189 190 190 seq_puts(seq, "Non-periodic FIFOs:\n"); 191 - seq_printf(seq, "RXFIFO: Size %d\n", dwc2_readl(regs + GRXFSIZ)); 191 + seq_printf(seq, "RXFIFO: Size %d\n", dwc2_readl(hsotg, GRXFSIZ)); 192 192 193 - val = dwc2_readl(regs + GNPTXFSIZ); 193 + val = dwc2_readl(hsotg, GNPTXFSIZ); 194 194 seq_printf(seq, "NPTXFIFO: Size %d, Start 0x%08x\n", 195 195 val >> FIFOSIZE_DEPTH_SHIFT, 196 196 val & FIFOSIZE_STARTADDR_MASK); ··· 197 199 seq_puts(seq, "\nPeriodic TXFIFOs:\n"); 198 200 199 201 for (idx = 1; idx < hsotg->num_of_eps; idx++) { 200 - val = dwc2_readl(regs + DPTXFSIZN(idx)); 202 + val = dwc2_readl(hsotg, DPTXFSIZN(idx)); 201 203 202 204 seq_printf(seq, "\tDPTXFIFO%2d: Size %d, Start 0x%08x\n", idx, 203 205 val >> FIFOSIZE_DEPTH_SHIFT, ··· 226 228 struct dwc2_hsotg_ep *ep = seq->private; 227 229 struct dwc2_hsotg *hsotg = ep->parent; 228 230 struct dwc2_hsotg_req *req; 229 - void __iomem *regs = hsotg->regs; 230 231 int index = ep->index; 231 232 int show_limit = 15; 232 233 unsigned long flags; ··· 236 239 /* first show the register state */ 237 240 238 241 seq_printf(seq, "\tDIEPCTL=0x%08x, DOEPCTL=0x%08x\n", 239 - dwc2_readl(regs + DIEPCTL(index)), 240 - dwc2_readl(regs + DOEPCTL(index))); 242 + dwc2_readl(hsotg, DIEPCTL(index)), 243 + dwc2_readl(hsotg, DOEPCTL(index))); 241 244 242 245 seq_printf(seq, "\tDIEPDMA=0x%08x, DOEPDMA=0x%08x\n", 243 - dwc2_readl(regs + DIEPDMA(index)), 244 - dwc2_readl(regs + DOEPDMA(index))); 246 + dwc2_readl(hsotg, DIEPDMA(index)), 247 + dwc2_readl(hsotg, DOEPDMA(index))); 245 248 246 249 seq_printf(seq, "\tDIEPINT=0x%08x, DOEPINT=0x%08x\n", 247 - dwc2_readl(regs + DIEPINT(index)), 248 - dwc2_readl(regs + DOEPINT(index))); 250 + dwc2_readl(hsotg, DIEPINT(index)), 251 + dwc2_readl(hsotg, DOEPINT(index))); 249 252 250 253 seq_printf(seq, "\tDIEPTSIZ=0x%08x, DOEPTSIZ=0x%08x\n", 251 - dwc2_readl(regs + DIEPTSIZ(index)), 252 - dwc2_readl(regs + DOEPTSIZ(index))); 254 + dwc2_readl(hsotg, DIEPTSIZ(index)), 255 + dwc2_readl(hsotg, DOEPTSIZ(index))); 253 256 254 257 seq_puts(seq, "\n"); 255 258 seq_printf(seq, "mps %d\n", ep->ep.maxpacket);
+259 -272
drivers/usb/dwc2/gadget.c
··· 47 47 return container_of(gadget, struct dwc2_hsotg, gadget); 48 48 } 49 49 50 - static inline void dwc2_set_bit(void __iomem *ptr, u32 val) 50 + static inline void dwc2_set_bit(struct dwc2_hsotg *hsotg, u32 offset, u32 val) 51 51 { 52 - dwc2_writel(dwc2_readl(ptr) | val, ptr); 52 + dwc2_writel(hsotg, dwc2_readl(hsotg, offset) | val, offset); 53 53 } 54 54 55 - static inline void dwc2_clear_bit(void __iomem *ptr, u32 val) 55 + static inline void dwc2_clear_bit(struct dwc2_hsotg *hsotg, u32 offset, u32 val) 56 56 { 57 - dwc2_writel(dwc2_readl(ptr) & ~val, ptr); 57 + dwc2_writel(hsotg, dwc2_readl(hsotg, offset) & ~val, offset); 58 58 } 59 59 60 60 static inline struct dwc2_hsotg_ep *index_to_ep(struct dwc2_hsotg *hsotg, ··· 129 129 */ 130 130 static void dwc2_hsotg_en_gsint(struct dwc2_hsotg *hsotg, u32 ints) 131 131 { 132 - u32 gsintmsk = dwc2_readl(hsotg->regs + GINTMSK); 132 + u32 gsintmsk = dwc2_readl(hsotg, GINTMSK); 133 133 u32 new_gsintmsk; 134 134 135 135 new_gsintmsk = gsintmsk | ints; 136 136 137 137 if (new_gsintmsk != gsintmsk) { 138 138 dev_dbg(hsotg->dev, "gsintmsk now 0x%08x\n", new_gsintmsk); 139 - dwc2_writel(new_gsintmsk, hsotg->regs + GINTMSK); 139 + dwc2_writel(hsotg, new_gsintmsk, GINTMSK); 140 140 } 141 141 } 142 142 ··· 147 147 */ 148 148 static void dwc2_hsotg_disable_gsint(struct dwc2_hsotg *hsotg, u32 ints) 149 149 { 150 - u32 gsintmsk = dwc2_readl(hsotg->regs + GINTMSK); 150 + u32 gsintmsk = dwc2_readl(hsotg, GINTMSK); 151 151 u32 new_gsintmsk; 152 152 153 153 new_gsintmsk = gsintmsk & ~ints; 154 154 155 155 if (new_gsintmsk != gsintmsk) 156 - dwc2_writel(new_gsintmsk, hsotg->regs + GINTMSK); 156 + dwc2_writel(hsotg, new_gsintmsk, GINTMSK); 157 157 } 158 158 159 159 /** ··· 178 178 bit <<= 16; 179 179 180 180 local_irq_save(flags); 181 - daint = dwc2_readl(hsotg->regs + DAINTMSK); 181 + daint = dwc2_readl(hsotg, DAINTMSK); 182 182 if (en) 183 183 daint |= bit; 184 184 else 185 185 daint &= ~bit; 186 - dwc2_writel(daint, hsotg->regs + DAINTMSK); 186 + dwc2_writel(hsotg, daint, DAINTMSK); 187 187 local_irq_restore(flags); 188 188 } 189 189 ··· 266 266 hsotg->fifo_map = 0; 267 267 268 268 /* set RX/NPTX FIFO sizes */ 269 - dwc2_writel(hsotg->params.g_rx_fifo_size, hsotg->regs + GRXFSIZ); 270 - dwc2_writel((hsotg->params.g_rx_fifo_size << FIFOSIZE_STARTADDR_SHIFT) | 269 + dwc2_writel(hsotg, hsotg->params.g_rx_fifo_size, GRXFSIZ); 270 + dwc2_writel(hsotg, (hsotg->params.g_rx_fifo_size << 271 + FIFOSIZE_STARTADDR_SHIFT) | 271 272 (hsotg->params.g_np_tx_fifo_size << FIFOSIZE_DEPTH_SHIFT), 272 - hsotg->regs + GNPTXFSIZ); 273 + GNPTXFSIZ); 273 274 274 275 /* 275 276 * arange all the rest of the TX FIFOs, as some versions of this ··· 296 295 "insufficient fifo memory"); 297 296 addr += txfsz[ep]; 298 297 299 - dwc2_writel(val, hsotg->regs + DPTXFSIZN(ep)); 300 - val = dwc2_readl(hsotg->regs + DPTXFSIZN(ep)); 298 + dwc2_writel(hsotg, val, DPTXFSIZN(ep)); 299 + val = dwc2_readl(hsotg, DPTXFSIZN(ep)); 301 300 } 302 301 303 - dwc2_writel(hsotg->hw_params.total_fifo_size | 302 + dwc2_writel(hsotg, hsotg->hw_params.total_fifo_size | 304 303 addr << GDFIFOCFG_EPINFOBASE_SHIFT, 305 - hsotg->regs + GDFIFOCFG); 304 + GDFIFOCFG); 306 305 /* 307 306 * according to p428 of the design guide, we need to ensure that 308 307 * all fifos are flushed before continuing 309 308 */ 310 309 311 - dwc2_writel(GRSTCTL_TXFNUM(0x10) | GRSTCTL_TXFFLSH | 312 - GRSTCTL_RXFFLSH, hsotg->regs + GRSTCTL); 310 + dwc2_writel(hsotg, GRSTCTL_TXFNUM(0x10) | GRSTCTL_TXFFLSH | 311 + GRSTCTL_RXFFLSH, GRSTCTL); 313 312 314 313 /* wait until the fifos are both flushed */ 315 314 timeout = 100; 316 315 while (1) { 317 - val = dwc2_readl(hsotg->regs + GRSTCTL); 316 + val = dwc2_readl(hsotg, GRSTCTL); 318 317 319 318 if ((val & (GRSTCTL_TXFFLSH | GRSTCTL_RXFFLSH)) == 0) 320 319 break; ··· 452 451 struct dwc2_hsotg_req *hs_req) 453 452 { 454 453 bool periodic = is_ep_periodic(hs_ep); 455 - u32 gnptxsts = dwc2_readl(hsotg->regs + GNPTXSTS); 454 + u32 gnptxsts = dwc2_readl(hsotg, GNPTXSTS); 456 455 int buf_pos = hs_req->req.actual; 457 456 int to_write = hs_ep->size_loaded; 458 457 void *data; ··· 467 466 return 0; 468 467 469 468 if (periodic && !hsotg->dedicated_fifos) { 470 - u32 epsize = dwc2_readl(hsotg->regs + DIEPTSIZ(hs_ep->index)); 469 + u32 epsize = dwc2_readl(hsotg, DIEPTSIZ(hs_ep->index)); 471 470 int size_left; 472 471 int size_done; 473 472 ··· 508 507 return -ENOSPC; 509 508 } 510 509 } else if (hsotg->dedicated_fifos && hs_ep->index != 0) { 511 - can_write = dwc2_readl(hsotg->regs + 512 - DTXFSTS(hs_ep->fifo_index)); 510 + can_write = dwc2_readl(hsotg, 511 + DTXFSTS(hs_ep->fifo_index)); 513 512 514 513 can_write &= 0xffff; 515 514 can_write *= 4; ··· 599 598 to_write = DIV_ROUND_UP(to_write, 4); 600 599 data = hs_req->req.buf + buf_pos; 601 600 602 - iowrite32_rep(hsotg->regs + EPFIFO(hs_ep->index), data, to_write); 601 + dwc2_writel_rep(hsotg, EPFIFO(hs_ep->index), data, to_write); 603 602 604 603 return (to_write >= can_write) ? -ENOSPC : 0; 605 604 } ··· 653 652 { 654 653 u32 dsts; 655 654 656 - dsts = dwc2_readl(hsotg->regs + DSTS); 655 + dsts = dwc2_readl(hsotg, DSTS); 657 656 dsts &= DSTS_SOFFN_MASK; 658 657 dsts >>= DSTS_SOFFN_SHIFT; 659 658 ··· 916 915 dma_reg = hs_ep->dir_in ? DIEPDMA(index) : DOEPDMA(index); 917 916 918 917 /* write descriptor chain address to control register */ 919 - dwc2_writel(hs_ep->desc_list_dma, hsotg->regs + dma_reg); 918 + dwc2_writel(hsotg, hs_ep->desc_list_dma, dma_reg); 920 919 921 - ctrl = dwc2_readl(hsotg->regs + depctl); 920 + ctrl = dwc2_readl(hsotg, depctl); 922 921 ctrl |= DXEPCTL_EPENA | DXEPCTL_CNAK; 923 - dwc2_writel(ctrl, hsotg->regs + depctl); 922 + dwc2_writel(hsotg, ctrl, depctl); 924 923 } 925 924 926 925 /** ··· 968 967 epsize_reg = dir_in ? DIEPTSIZ(index) : DOEPTSIZ(index); 969 968 970 969 dev_dbg(hsotg->dev, "%s: DxEPCTL=0x%08x, ep %d, dir %s\n", 971 - __func__, dwc2_readl(hsotg->regs + epctrl_reg), index, 970 + __func__, dwc2_readl(hsotg, epctrl_reg), index, 972 971 hs_ep->dir_in ? "in" : "out"); 973 972 974 973 /* If endpoint is stalled, we will restart request later */ 975 - ctrl = dwc2_readl(hsotg->regs + epctrl_reg); 974 + ctrl = dwc2_readl(hsotg, epctrl_reg); 976 975 977 976 if (index && ctrl & DXEPCTL_STALL) { 978 977 dev_warn(hsotg->dev, "%s: ep%d is stalled\n", __func__, index); ··· 1065 1064 length); 1066 1065 1067 1066 /* write descriptor chain address to control register */ 1068 - dwc2_writel(hs_ep->desc_list_dma, hsotg->regs + dma_reg); 1067 + dwc2_writel(hsotg, hs_ep->desc_list_dma, dma_reg); 1069 1068 1070 1069 dev_dbg(hsotg->dev, "%s: %08x pad => 0x%08x\n", 1071 1070 __func__, (u32)hs_ep->desc_list_dma, dma_reg); 1072 1071 } else { 1073 1072 /* write size / packets */ 1074 - dwc2_writel(epsize, hsotg->regs + epsize_reg); 1073 + dwc2_writel(hsotg, epsize, epsize_reg); 1075 1074 1076 1075 if (using_dma(hsotg) && !continuing && (length != 0)) { 1077 1076 /* ··· 1079 1078 * already synced by dwc2_hsotg_ep_queue(). 1080 1079 */ 1081 1080 1082 - dwc2_writel(ureq->dma, hsotg->regs + dma_reg); 1081 + dwc2_writel(hsotg, ureq->dma, dma_reg); 1083 1082 1084 1083 dev_dbg(hsotg->dev, "%s: %pad => 0x%08x\n", 1085 1084 __func__, &ureq->dma, dma_reg); ··· 1105 1104 ctrl |= DXEPCTL_CNAK; /* clear NAK set by core */ 1106 1105 1107 1106 dev_dbg(hsotg->dev, "%s: DxEPCTL=0x%08x\n", __func__, ctrl); 1108 - dwc2_writel(ctrl, hsotg->regs + epctrl_reg); 1107 + dwc2_writel(hsotg, ctrl, epctrl_reg); 1109 1108 1110 1109 /* 1111 1110 * set these, it seems that DMA support increments past the end ··· 1128 1127 */ 1129 1128 1130 1129 /* check ep is enabled */ 1131 - if (!(dwc2_readl(hsotg->regs + epctrl_reg) & DXEPCTL_EPENA)) 1130 + if (!(dwc2_readl(hsotg, epctrl_reg) & DXEPCTL_EPENA)) 1132 1131 dev_dbg(hsotg->dev, 1133 1132 "ep%d: failed to become enabled (DXEPCTL=0x%08x)?\n", 1134 - index, dwc2_readl(hsotg->regs + epctrl_reg)); 1133 + index, dwc2_readl(hsotg, epctrl_reg)); 1135 1134 1136 1135 dev_dbg(hsotg->dev, "%s: DXEPCTL=0x%08x\n", 1137 - __func__, dwc2_readl(hsotg->regs + epctrl_reg)); 1136 + __func__, dwc2_readl(hsotg, epctrl_reg)); 1138 1137 1139 1138 /* enable ep interrupts */ 1140 1139 dwc2_hsotg_ctrl_epint(hsotg, hs_ep->index, hs_ep->dir_in, 1); ··· 1467 1466 */ 1468 1467 int dwc2_hsotg_set_test_mode(struct dwc2_hsotg *hsotg, int testmode) 1469 1468 { 1470 - int dctl = dwc2_readl(hsotg->regs + DCTL); 1469 + int dctl = dwc2_readl(hsotg, DCTL); 1471 1470 1472 1471 dctl &= ~DCTL_TSTCTL_MASK; 1473 1472 switch (testmode) { ··· 1481 1480 default: 1482 1481 return -EINVAL; 1483 1482 } 1484 - dwc2_writel(dctl, hsotg->regs + DCTL); 1483 + dwc2_writel(hsotg, dctl, DCTL); 1485 1484 return 0; 1486 1485 } 1487 1486 ··· 1635 1634 } else { 1636 1635 dev_dbg(hsotg->dev, "%s: No more ISOC-OUT requests\n", 1637 1636 __func__); 1638 - mask = dwc2_readl(hsotg->regs + epmsk_reg); 1637 + mask = dwc2_readl(hsotg, epmsk_reg); 1639 1638 mask |= DOEPMSK_OUTTKNEPDISMSK; 1640 - dwc2_writel(mask, hsotg->regs + epmsk_reg); 1639 + dwc2_writel(hsotg, mask, epmsk_reg); 1641 1640 } 1642 1641 } 1643 1642 ··· 1774 1773 * taken effect, so no need to clear later. 1775 1774 */ 1776 1775 1777 - ctrl = dwc2_readl(hsotg->regs + reg); 1776 + ctrl = dwc2_readl(hsotg, reg); 1778 1777 ctrl |= DXEPCTL_STALL; 1779 1778 ctrl |= DXEPCTL_CNAK; 1780 - dwc2_writel(ctrl, hsotg->regs + reg); 1779 + dwc2_writel(hsotg, ctrl, reg); 1781 1780 1782 1781 dev_dbg(hsotg->dev, 1783 1782 "written DXEPCTL=0x%08x to %08x (DXEPCTL=0x%08x)\n", 1784 - ctrl, reg, dwc2_readl(hsotg->regs + reg)); 1783 + ctrl, reg, dwc2_readl(hsotg, reg)); 1785 1784 1786 1785 /* 1787 1786 * complete won't be called, so we enqueue ··· 1826 1825 switch (ctrl->bRequest) { 1827 1826 case USB_REQ_SET_ADDRESS: 1828 1827 hsotg->connected = 1; 1829 - dcfg = dwc2_readl(hsotg->regs + DCFG); 1828 + dcfg = dwc2_readl(hsotg, DCFG); 1830 1829 dcfg &= ~DCFG_DEVADDR_MASK; 1831 1830 dcfg |= (le16_to_cpu(ctrl->wValue) << 1832 1831 DCFG_DEVADDR_SHIFT) & DCFG_DEVADDR_MASK; 1833 - dwc2_writel(dcfg, hsotg->regs + DCFG); 1832 + dwc2_writel(hsotg, dcfg, DCFG); 1834 1833 1835 1834 dev_info(hsotg->dev, "new address %d\n", ctrl->wValue); 1836 1835 ··· 1956 1955 1957 1956 dwc2_gadget_config_nonisoc_xfer_ddma(hs_ep, dma, 0); 1958 1957 } else { 1959 - dwc2_writel(DXEPTSIZ_MC(1) | DXEPTSIZ_PKTCNT(1) | 1960 - DXEPTSIZ_XFERSIZE(0), hsotg->regs + 1958 + dwc2_writel(hsotg, DXEPTSIZ_MC(1) | DXEPTSIZ_PKTCNT(1) | 1959 + DXEPTSIZ_XFERSIZE(0), 1961 1960 epsiz_reg); 1962 1961 } 1963 1962 1964 - ctrl = dwc2_readl(hsotg->regs + epctl_reg); 1963 + ctrl = dwc2_readl(hsotg, epctl_reg); 1965 1964 ctrl |= DXEPCTL_CNAK; /* clear NAK set by core */ 1966 1965 ctrl |= DXEPCTL_EPENA; /* ensure ep enabled */ 1967 1966 ctrl |= DXEPCTL_USBACTEP; 1968 - dwc2_writel(ctrl, hsotg->regs + epctl_reg); 1967 + dwc2_writel(hsotg, ctrl, epctl_reg); 1969 1968 } 1970 1969 1971 1970 /** ··· 2125 2124 { 2126 2125 struct dwc2_hsotg_ep *hs_ep = hsotg->eps_out[ep_idx]; 2127 2126 struct dwc2_hsotg_req *hs_req = hs_ep->req; 2128 - void __iomem *fifo = hsotg->regs + EPFIFO(ep_idx); 2129 2127 int to_read; 2130 2128 int max_req; 2131 2129 int read_ptr; 2132 2130 2133 2131 if (!hs_req) { 2134 - u32 epctl = dwc2_readl(hsotg->regs + DOEPCTL(ep_idx)); 2132 + u32 epctl = dwc2_readl(hsotg, DOEPCTL(ep_idx)); 2135 2133 int ptr; 2136 2134 2137 2135 dev_dbg(hsotg->dev, ··· 2139 2139 2140 2140 /* dump the data from the FIFO, we've nothing we can do */ 2141 2141 for (ptr = 0; ptr < size; ptr += 4) 2142 - (void)dwc2_readl(fifo); 2142 + (void)dwc2_readl(hsotg, EPFIFO(ep_idx)); 2143 2143 2144 2144 return; 2145 2145 } ··· 2169 2169 * note, we might over-write the buffer end by 3 bytes depending on 2170 2170 * alignment of the data. 2171 2171 */ 2172 - ioread32_rep(fifo, hs_req->req.buf + read_ptr, to_read); 2172 + dwc2_readl_rep(hsotg, EPFIFO(ep_idx), 2173 + hs_req->req.buf + read_ptr, to_read); 2173 2174 } 2174 2175 2175 2176 /** ··· 2199 2198 { 2200 2199 u32 ctrl; 2201 2200 2202 - ctrl = dwc2_readl(hsotg->regs + epctl_reg); 2201 + ctrl = dwc2_readl(hsotg, epctl_reg); 2203 2202 if (ctrl & DXEPCTL_EOFRNUM) 2204 2203 ctrl |= DXEPCTL_SETEVENFR; 2205 2204 else 2206 2205 ctrl |= DXEPCTL_SETODDFR; 2207 - dwc2_writel(ctrl, hsotg->regs + epctl_reg); 2206 + dwc2_writel(hsotg, ctrl, epctl_reg); 2208 2207 } 2209 2208 2210 2209 /* ··· 2248 2247 */ 2249 2248 static void dwc2_hsotg_handle_outdone(struct dwc2_hsotg *hsotg, int epnum) 2250 2249 { 2251 - u32 epsize = dwc2_readl(hsotg->regs + DOEPTSIZ(epnum)); 2250 + u32 epsize = dwc2_readl(hsotg, DOEPTSIZ(epnum)); 2252 2251 struct dwc2_hsotg_ep *hs_ep = hsotg->eps_out[epnum]; 2253 2252 struct dwc2_hsotg_req *hs_req = hs_ep->req; 2254 2253 struct usb_request *req = &hs_req->req; ··· 2344 2343 */ 2345 2344 static void dwc2_hsotg_handle_rx(struct dwc2_hsotg *hsotg) 2346 2345 { 2347 - u32 grxstsr = dwc2_readl(hsotg->regs + GRXSTSP); 2346 + u32 grxstsr = dwc2_readl(hsotg, GRXSTSP); 2348 2347 u32 epnum, status, size; 2349 2348 2350 2349 WARN_ON(using_dma(hsotg)); ··· 2375 2374 dev_dbg(hsotg->dev, 2376 2375 "SetupDone (Frame=0x%08x, DOPEPCTL=0x%08x)\n", 2377 2376 dwc2_hsotg_read_frameno(hsotg), 2378 - dwc2_readl(hsotg->regs + DOEPCTL(0))); 2377 + dwc2_readl(hsotg, DOEPCTL(0))); 2379 2378 /* 2380 2379 * Call dwc2_hsotg_handle_outdone here if it was not called from 2381 2380 * GRXSTS_PKTSTS_OUTDONE. That is, if the core didn't ··· 2393 2392 dev_dbg(hsotg->dev, 2394 2393 "SetupRX (Frame=0x%08x, DOPEPCTL=0x%08x)\n", 2395 2394 dwc2_hsotg_read_frameno(hsotg), 2396 - dwc2_readl(hsotg->regs + DOEPCTL(0))); 2395 + dwc2_readl(hsotg, DOEPCTL(0))); 2397 2396 2398 2397 WARN_ON(hsotg->ep0_state != DWC2_EP0_SETUP); 2399 2398 ··· 2447 2446 unsigned int mc, unsigned int dir_in) 2448 2447 { 2449 2448 struct dwc2_hsotg_ep *hs_ep; 2450 - void __iomem *regs = hsotg->regs; 2451 2449 u32 reg; 2452 2450 2453 2451 hs_ep = index_to_ep(hsotg, ep, dir_in); ··· 2472 2472 } 2473 2473 2474 2474 if (dir_in) { 2475 - reg = dwc2_readl(regs + DIEPCTL(ep)); 2475 + reg = dwc2_readl(hsotg, DIEPCTL(ep)); 2476 2476 reg &= ~DXEPCTL_MPS_MASK; 2477 2477 reg |= mps; 2478 - dwc2_writel(reg, regs + DIEPCTL(ep)); 2478 + dwc2_writel(hsotg, reg, DIEPCTL(ep)); 2479 2479 } else { 2480 - reg = dwc2_readl(regs + DOEPCTL(ep)); 2480 + reg = dwc2_readl(hsotg, DOEPCTL(ep)); 2481 2481 reg &= ~DXEPCTL_MPS_MASK; 2482 2482 reg |= mps; 2483 - dwc2_writel(reg, regs + DOEPCTL(ep)); 2483 + dwc2_writel(hsotg, reg, DOEPCTL(ep)); 2484 2484 } 2485 2485 2486 2486 return; ··· 2496 2496 */ 2497 2497 static void dwc2_hsotg_txfifo_flush(struct dwc2_hsotg *hsotg, unsigned int idx) 2498 2498 { 2499 - dwc2_writel(GRSTCTL_TXFNUM(idx) | GRSTCTL_TXFFLSH, 2500 - hsotg->regs + GRSTCTL); 2499 + dwc2_writel(hsotg, GRSTCTL_TXFNUM(idx) | GRSTCTL_TXFFLSH, 2500 + GRSTCTL); 2501 2501 2502 2502 /* wait until the fifo is flushed */ 2503 2503 if (dwc2_hsotg_wait_bit_clear(hsotg, GRSTCTL, GRSTCTL_TXFFLSH, 100)) ··· 2550 2550 struct dwc2_hsotg_ep *hs_ep) 2551 2551 { 2552 2552 struct dwc2_hsotg_req *hs_req = hs_ep->req; 2553 - u32 epsize = dwc2_readl(hsotg->regs + DIEPTSIZ(hs_ep->index)); 2553 + u32 epsize = dwc2_readl(hsotg, DIEPTSIZ(hs_ep->index)); 2554 2554 int size_left, size_done; 2555 2555 2556 2556 if (!hs_req) { ··· 2654 2654 u32 mask; 2655 2655 u32 diepempmsk; 2656 2656 2657 - mask = dwc2_readl(hsotg->regs + epmsk_reg); 2658 - diepempmsk = dwc2_readl(hsotg->regs + DIEPEMPMSK); 2657 + mask = dwc2_readl(hsotg, epmsk_reg); 2658 + diepempmsk = dwc2_readl(hsotg, DIEPEMPMSK); 2659 2659 mask |= ((diepempmsk >> idx) & 0x1) ? DIEPMSK_TXFIFOEMPTY : 0; 2660 2660 mask |= DXEPINT_SETUP_RCVD; 2661 2661 2662 - ints = dwc2_readl(hsotg->regs + epint_reg); 2662 + ints = dwc2_readl(hsotg, epint_reg); 2663 2663 ints &= mask; 2664 2664 return ints; 2665 2665 } ··· 2684 2684 unsigned char idx = hs_ep->index; 2685 2685 int dir_in = hs_ep->dir_in; 2686 2686 u32 epctl_reg = dir_in ? DIEPCTL(idx) : DOEPCTL(idx); 2687 - int dctl = dwc2_readl(hsotg->regs + DCTL); 2687 + int dctl = dwc2_readl(hsotg, DCTL); 2688 2688 2689 2689 dev_dbg(hsotg->dev, "%s: EPDisbld\n", __func__); 2690 2690 2691 2691 if (dir_in) { 2692 - int epctl = dwc2_readl(hsotg->regs + epctl_reg); 2692 + int epctl = dwc2_readl(hsotg, epctl_reg); 2693 2693 2694 2694 dwc2_hsotg_txfifo_flush(hsotg, hs_ep->fifo_index); 2695 2695 ··· 2699 2699 } 2700 2700 2701 2701 if ((epctl & DXEPCTL_STALL) && (epctl & DXEPCTL_EPTYPE_BULK)) { 2702 - int dctl = dwc2_readl(hsotg->regs + DCTL); 2702 + int dctl = dwc2_readl(hsotg, DCTL); 2703 2703 2704 2704 dctl |= DCTL_CGNPINNAK; 2705 - dwc2_writel(dctl, hsotg->regs + DCTL); 2705 + dwc2_writel(hsotg, dctl, DCTL); 2706 2706 } 2707 2707 return; 2708 2708 } 2709 2709 2710 2710 if (dctl & DCTL_GOUTNAKSTS) { 2711 2711 dctl |= DCTL_CGOUTNAK; 2712 - dwc2_writel(dctl, hsotg->regs + DCTL); 2712 + dwc2_writel(hsotg, dctl, DCTL); 2713 2713 } 2714 2714 2715 2715 if (!hs_ep->isochronous) ··· 2750 2750 struct dwc2_hsotg *hsotg = ep->parent; 2751 2751 int dir_in = ep->dir_in; 2752 2752 u32 doepmsk; 2753 - u32 tmp; 2754 2753 2755 2754 if (dir_in || !ep->isochronous) 2756 2755 return; 2757 2756 2758 - /* 2759 - * Store frame in which irq was asserted here, as 2760 - * it can change while completing request below. 2761 - */ 2762 - tmp = dwc2_hsotg_read_frameno(hsotg); 2763 - 2764 2757 if (using_desc_dma(hsotg)) { 2765 2758 if (ep->target_frame == TARGET_FRAME_INITIAL) { 2766 2759 /* Start first ISO Out */ 2767 - ep->target_frame = tmp; 2760 + ep->target_frame = hsotg->frame_number; 2768 2761 dwc2_gadget_start_isoc_ddma(ep); 2769 2762 } 2770 2763 return; ··· 2765 2772 2766 2773 if (ep->interval > 1 && 2767 2774 ep->target_frame == TARGET_FRAME_INITIAL) { 2768 - u32 dsts; 2769 2775 u32 ctrl; 2770 2776 2771 - dsts = dwc2_readl(hsotg->regs + DSTS); 2772 - ep->target_frame = dwc2_hsotg_read_frameno(hsotg); 2777 + ep->target_frame = hsotg->frame_number; 2773 2778 dwc2_gadget_incr_frame_num(ep); 2774 2779 2775 - ctrl = dwc2_readl(hsotg->regs + DOEPCTL(ep->index)); 2780 + ctrl = dwc2_readl(hsotg, DOEPCTL(ep->index)); 2776 2781 if (ep->target_frame & 0x1) 2777 2782 ctrl |= DXEPCTL_SETODDFR; 2778 2783 else 2779 2784 ctrl |= DXEPCTL_SETEVENFR; 2780 2785 2781 - dwc2_writel(ctrl, hsotg->regs + DOEPCTL(ep->index)); 2786 + dwc2_writel(hsotg, ctrl, DOEPCTL(ep->index)); 2782 2787 } 2783 2788 2784 2789 dwc2_gadget_start_next_request(ep); 2785 - doepmsk = dwc2_readl(hsotg->regs + DOEPMSK); 2790 + doepmsk = dwc2_readl(hsotg, DOEPMSK); 2786 2791 doepmsk &= ~DOEPMSK_OUTTKNEPDISMSK; 2787 - dwc2_writel(doepmsk, hsotg->regs + DOEPMSK); 2792 + dwc2_writel(hsotg, doepmsk, DOEPMSK); 2788 2793 } 2789 2794 2790 2795 /** ··· 2803 2812 { 2804 2813 struct dwc2_hsotg *hsotg = hs_ep->parent; 2805 2814 int dir_in = hs_ep->dir_in; 2806 - u32 tmp; 2807 2815 2808 2816 if (!dir_in || !hs_ep->isochronous) 2809 2817 return; 2810 2818 2811 2819 if (hs_ep->target_frame == TARGET_FRAME_INITIAL) { 2812 2820 2813 - tmp = dwc2_hsotg_read_frameno(hsotg); 2814 2821 if (using_desc_dma(hsotg)) { 2815 - hs_ep->target_frame = tmp; 2822 + hs_ep->target_frame = hsotg->frame_number; 2816 2823 dwc2_gadget_incr_frame_num(hs_ep); 2817 2824 dwc2_gadget_start_isoc_ddma(hs_ep); 2818 2825 return; 2819 2826 } 2820 2827 2821 - hs_ep->target_frame = tmp; 2828 + hs_ep->target_frame = hsotg->frame_number; 2822 2829 if (hs_ep->interval > 1) { 2823 - u32 ctrl = dwc2_readl(hsotg->regs + 2830 + u32 ctrl = dwc2_readl(hsotg, 2824 2831 DIEPCTL(hs_ep->index)); 2825 2832 if (hs_ep->target_frame & 0x1) 2826 2833 ctrl |= DXEPCTL_SETODDFR; 2827 2834 else 2828 2835 ctrl |= DXEPCTL_SETEVENFR; 2829 2836 2830 - dwc2_writel(ctrl, hsotg->regs + DIEPCTL(hs_ep->index)); 2837 + dwc2_writel(hsotg, ctrl, DIEPCTL(hs_ep->index)); 2831 2838 } 2832 2839 2833 2840 dwc2_hsotg_complete_request(hsotg, hs_ep, ··· 2855 2866 u32 ctrl; 2856 2867 2857 2868 ints = dwc2_gadget_read_ep_interrupts(hsotg, idx, dir_in); 2858 - ctrl = dwc2_readl(hsotg->regs + epctl_reg); 2869 + ctrl = dwc2_readl(hsotg, epctl_reg); 2859 2870 2860 2871 /* Clear endpoint interrupts */ 2861 - dwc2_writel(ints, hsotg->regs + epint_reg); 2872 + dwc2_writel(hsotg, ints, epint_reg); 2862 2873 2863 2874 if (!hs_ep) { 2864 2875 dev_err(hsotg->dev, "%s:Interrupt for unconfigured ep%d(%s)\n", ··· 2886 2897 if (ints & DXEPINT_XFERCOMPL) { 2887 2898 dev_dbg(hsotg->dev, 2888 2899 "%s: XferCompl: DxEPCTL=0x%08x, DXEPTSIZ=%08x\n", 2889 - __func__, dwc2_readl(hsotg->regs + epctl_reg), 2890 - dwc2_readl(hsotg->regs + epsiz_reg)); 2900 + __func__, dwc2_readl(hsotg, epctl_reg), 2901 + dwc2_readl(hsotg, epsiz_reg)); 2891 2902 2892 2903 /* In DDMA handle isochronous requests separately */ 2893 2904 if (using_desc_dma(hsotg) && hs_ep->isochronous) { ··· 3005 3016 */ 3006 3017 static void dwc2_hsotg_irq_enumdone(struct dwc2_hsotg *hsotg) 3007 3018 { 3008 - u32 dsts = dwc2_readl(hsotg->regs + DSTS); 3019 + u32 dsts = dwc2_readl(hsotg, DSTS); 3009 3020 int ep0_mps = 0, ep_mps = 8; 3010 3021 3011 3022 /* ··· 3076 3087 dwc2_hsotg_enqueue_setup(hsotg); 3077 3088 3078 3089 dev_dbg(hsotg->dev, "EP0: DIEPCTL0=0x%08x, DOEPCTL0=0x%08x\n", 3079 - dwc2_readl(hsotg->regs + DIEPCTL0), 3080 - dwc2_readl(hsotg->regs + DOEPCTL0)); 3090 + dwc2_readl(hsotg, DIEPCTL0), 3091 + dwc2_readl(hsotg, DOEPCTL0)); 3081 3092 } 3082 3093 3083 3094 /** ··· 3104 3115 3105 3116 if (!hsotg->dedicated_fifos) 3106 3117 return; 3107 - size = (dwc2_readl(hsotg->regs + DTXFSTS(ep->fifo_index)) & 0xffff) * 4; 3118 + size = (dwc2_readl(hsotg, DTXFSTS(ep->fifo_index)) & 0xffff) * 4; 3108 3119 if (size < ep->fifo_size) 3109 3120 dwc2_hsotg_txfifo_flush(hsotg, ep->fifo_index); 3110 3121 } ··· 3205 3216 */ 3206 3217 3207 3218 /* keep other bits untouched (so e.g. forced modes are not lost) */ 3208 - usbcfg = dwc2_readl(hsotg->regs + GUSBCFG); 3219 + usbcfg = dwc2_readl(hsotg, GUSBCFG); 3209 3220 usbcfg &= ~(GUSBCFG_TOUTCAL_MASK | GUSBCFG_PHYIF16 | GUSBCFG_SRPCAP | 3210 3221 GUSBCFG_HNPCAP | GUSBCFG_USBTRDTIM_MASK); 3211 3222 ··· 3220 3231 usbcfg |= hsotg->phyif | GUSBCFG_TOUTCAL(7) | 3221 3232 (val << GUSBCFG_USBTRDTIM_SHIFT); 3222 3233 } 3223 - dwc2_writel(usbcfg, hsotg->regs + GUSBCFG); 3234 + dwc2_writel(hsotg, usbcfg, GUSBCFG); 3224 3235 3225 3236 dwc2_hsotg_init_fifo(hsotg); 3226 3237 3227 3238 if (!is_usb_reset) 3228 - dwc2_set_bit(hsotg->regs + DCTL, DCTL_SFTDISCON); 3239 + dwc2_set_bit(hsotg, DCTL, DCTL_SFTDISCON); 3229 3240 3230 3241 dcfg |= DCFG_EPMISCNT(1); 3231 3242 ··· 3246 3257 if (hsotg->params.ipg_isoc_en) 3247 3258 dcfg |= DCFG_IPG_ISOC_SUPPORDED; 3248 3259 3249 - dwc2_writel(dcfg, hsotg->regs + DCFG); 3260 + dwc2_writel(hsotg, dcfg, DCFG); 3250 3261 3251 3262 /* Clear any pending OTG interrupts */ 3252 - dwc2_writel(0xffffffff, hsotg->regs + GOTGINT); 3263 + dwc2_writel(hsotg, 0xffffffff, GOTGINT); 3253 3264 3254 3265 /* Clear any pending interrupts */ 3255 - dwc2_writel(0xffffffff, hsotg->regs + GINTSTS); 3266 + dwc2_writel(hsotg, 0xffffffff, GINTSTS); 3256 3267 intmsk = GINTSTS_ERLYSUSP | GINTSTS_SESSREQINT | 3257 3268 GINTSTS_GOUTNAKEFF | GINTSTS_GINNAKEFF | 3258 3269 GINTSTS_USBRST | GINTSTS_RESETDET | ··· 3266 3277 if (!hsotg->params.external_id_pin_ctl) 3267 3278 intmsk |= GINTSTS_CONIDSTSCHNG; 3268 3279 3269 - dwc2_writel(intmsk, hsotg->regs + GINTMSK); 3280 + dwc2_writel(hsotg, intmsk, GINTMSK); 3270 3281 3271 3282 if (using_dma(hsotg)) { 3272 - dwc2_writel(GAHBCFG_GLBL_INTR_EN | GAHBCFG_DMA_EN | 3283 + dwc2_writel(hsotg, GAHBCFG_GLBL_INTR_EN | GAHBCFG_DMA_EN | 3273 3284 hsotg->params.ahbcfg, 3274 - hsotg->regs + GAHBCFG); 3285 + GAHBCFG); 3275 3286 3276 3287 /* Set DDMA mode support in the core if needed */ 3277 3288 if (using_desc_dma(hsotg)) 3278 - dwc2_set_bit(hsotg->regs + DCFG, DCFG_DESCDMA_EN); 3289 + dwc2_set_bit(hsotg, DCFG, DCFG_DESCDMA_EN); 3279 3290 3280 3291 } else { 3281 - dwc2_writel(((hsotg->dedicated_fifos) ? 3292 + dwc2_writel(hsotg, ((hsotg->dedicated_fifos) ? 3282 3293 (GAHBCFG_NP_TXF_EMP_LVL | 3283 3294 GAHBCFG_P_TXF_EMP_LVL) : 0) | 3284 - GAHBCFG_GLBL_INTR_EN, hsotg->regs + GAHBCFG); 3295 + GAHBCFG_GLBL_INTR_EN, GAHBCFG); 3285 3296 } 3286 3297 3287 3298 /* ··· 3290 3301 * interrupts. 3291 3302 */ 3292 3303 3293 - dwc2_writel(((hsotg->dedicated_fifos && !using_dma(hsotg)) ? 3304 + dwc2_writel(hsotg, ((hsotg->dedicated_fifos && !using_dma(hsotg)) ? 3294 3305 DIEPMSK_TXFIFOEMPTY | DIEPMSK_INTKNTXFEMPMSK : 0) | 3295 3306 DIEPMSK_EPDISBLDMSK | DIEPMSK_XFERCOMPLMSK | 3296 3307 DIEPMSK_TIMEOUTMSK | DIEPMSK_AHBERRMSK, 3297 - hsotg->regs + DIEPMSK); 3308 + DIEPMSK); 3298 3309 3299 3310 /* 3300 3311 * don't need XferCompl, we get that from RXFIFO in slave mode. In 3301 3312 * DMA mode we may need this and StsPhseRcvd. 3302 3313 */ 3303 - dwc2_writel((using_dma(hsotg) ? (DIEPMSK_XFERCOMPLMSK | 3314 + dwc2_writel(hsotg, (using_dma(hsotg) ? (DIEPMSK_XFERCOMPLMSK | 3304 3315 DOEPMSK_STSPHSERCVDMSK) : 0) | 3305 3316 DOEPMSK_EPDISBLDMSK | DOEPMSK_AHBERRMSK | 3306 3317 DOEPMSK_SETUPMSK, 3307 - hsotg->regs + DOEPMSK); 3318 + DOEPMSK); 3308 3319 3309 3320 /* Enable BNA interrupt for DDMA */ 3310 3321 if (using_desc_dma(hsotg)) { 3311 - dwc2_set_bit(hsotg->regs + DOEPMSK, DOEPMSK_BNAMSK); 3312 - dwc2_set_bit(hsotg->regs + DIEPMSK, DIEPMSK_BNAININTRMSK); 3322 + dwc2_set_bit(hsotg, DOEPMSK, DOEPMSK_BNAMSK); 3323 + dwc2_set_bit(hsotg, DIEPMSK, DIEPMSK_BNAININTRMSK); 3313 3324 } 3314 3325 3315 - dwc2_writel(0, hsotg->regs + DAINTMSK); 3326 + dwc2_writel(hsotg, 0, DAINTMSK); 3316 3327 3317 3328 dev_dbg(hsotg->dev, "EP0: DIEPCTL0=0x%08x, DOEPCTL0=0x%08x\n", 3318 - dwc2_readl(hsotg->regs + DIEPCTL0), 3319 - dwc2_readl(hsotg->regs + DOEPCTL0)); 3329 + dwc2_readl(hsotg, DIEPCTL0), 3330 + dwc2_readl(hsotg, DOEPCTL0)); 3320 3331 3321 3332 /* enable in and out endpoint interrupts */ 3322 3333 dwc2_hsotg_en_gsint(hsotg, GINTSTS_OEPINT | GINTSTS_IEPINT); ··· 3334 3345 dwc2_hsotg_ctrl_epint(hsotg, 0, 1, 1); 3335 3346 3336 3347 if (!is_usb_reset) { 3337 - dwc2_set_bit(hsotg->regs + DCTL, DCTL_PWRONPRGDONE); 3348 + dwc2_set_bit(hsotg, DCTL, DCTL_PWRONPRGDONE); 3338 3349 udelay(10); /* see openiboot */ 3339 - dwc2_clear_bit(hsotg->regs + DCTL, DCTL_PWRONPRGDONE); 3350 + dwc2_clear_bit(hsotg, DCTL, DCTL_PWRONPRGDONE); 3340 3351 } 3341 3352 3342 - dev_dbg(hsotg->dev, "DCTL=0x%08x\n", dwc2_readl(hsotg->regs + DCTL)); 3353 + dev_dbg(hsotg->dev, "DCTL=0x%08x\n", dwc2_readl(hsotg, DCTL)); 3343 3354 3344 3355 /* 3345 3356 * DxEPCTL_USBActEp says RO in manual, but seems to be set by ··· 3347 3358 */ 3348 3359 3349 3360 /* set to read 1 8byte packet */ 3350 - dwc2_writel(DXEPTSIZ_MC(1) | DXEPTSIZ_PKTCNT(1) | 3351 - DXEPTSIZ_XFERSIZE(8), hsotg->regs + DOEPTSIZ0); 3361 + dwc2_writel(hsotg, DXEPTSIZ_MC(1) | DXEPTSIZ_PKTCNT(1) | 3362 + DXEPTSIZ_XFERSIZE(8), DOEPTSIZ0); 3352 3363 3353 - dwc2_writel(dwc2_hsotg_ep0_mps(hsotg->eps_out[0]->ep.maxpacket) | 3364 + dwc2_writel(hsotg, dwc2_hsotg_ep0_mps(hsotg->eps_out[0]->ep.maxpacket) | 3354 3365 DXEPCTL_CNAK | DXEPCTL_EPENA | 3355 3366 DXEPCTL_USBACTEP, 3356 - hsotg->regs + DOEPCTL0); 3367 + DOEPCTL0); 3357 3368 3358 3369 /* enable, but don't activate EP0in */ 3359 - dwc2_writel(dwc2_hsotg_ep0_mps(hsotg->eps_out[0]->ep.maxpacket) | 3360 - DXEPCTL_USBACTEP, hsotg->regs + DIEPCTL0); 3370 + dwc2_writel(hsotg, dwc2_hsotg_ep0_mps(hsotg->eps_out[0]->ep.maxpacket) | 3371 + DXEPCTL_USBACTEP, DIEPCTL0); 3361 3372 3362 3373 /* clear global NAKs */ 3363 3374 val = DCTL_CGOUTNAK | DCTL_CGNPINNAK; 3364 3375 if (!is_usb_reset) 3365 3376 val |= DCTL_SFTDISCON; 3366 - dwc2_set_bit(hsotg->regs + DCTL, val); 3377 + dwc2_set_bit(hsotg, DCTL, val); 3367 3378 3368 3379 /* configure the core to support LPM */ 3369 3380 dwc2_gadget_init_lpm(hsotg); ··· 3376 3387 dwc2_hsotg_enqueue_setup(hsotg); 3377 3388 3378 3389 dev_dbg(hsotg->dev, "EP0: DIEPCTL0=0x%08x, DOEPCTL0=0x%08x\n", 3379 - dwc2_readl(hsotg->regs + DIEPCTL0), 3380 - dwc2_readl(hsotg->regs + DOEPCTL0)); 3390 + dwc2_readl(hsotg, DIEPCTL0), 3391 + dwc2_readl(hsotg, DOEPCTL0)); 3381 3392 } 3382 3393 3383 3394 static void dwc2_hsotg_core_disconnect(struct dwc2_hsotg *hsotg) 3384 3395 { 3385 3396 /* set the soft-disconnect bit */ 3386 - dwc2_set_bit(hsotg->regs + DCTL, DCTL_SFTDISCON); 3397 + dwc2_set_bit(hsotg, DCTL, DCTL_SFTDISCON); 3387 3398 } 3388 3399 3389 3400 void dwc2_hsotg_core_connect(struct dwc2_hsotg *hsotg) 3390 3401 { 3391 3402 /* remove the soft-disconnect and let's go */ 3392 - dwc2_clear_bit(hsotg->regs + DCTL, DCTL_SFTDISCON); 3403 + dwc2_clear_bit(hsotg, DCTL, DCTL_SFTDISCON); 3393 3404 } 3394 3405 3395 3406 /** ··· 3414 3425 3415 3426 dev_dbg(hsotg->dev, "Incomplete isoc in interrupt received:\n"); 3416 3427 3417 - daintmsk = dwc2_readl(hsotg->regs + DAINTMSK); 3428 + daintmsk = dwc2_readl(hsotg, DAINTMSK); 3418 3429 3419 3430 for (idx = 1; idx < hsotg->num_of_eps; idx++) { 3420 3431 hs_ep = hsotg->eps_in[idx]; ··· 3422 3433 if ((BIT(idx) & ~daintmsk) || !hs_ep->isochronous) 3423 3434 continue; 3424 3435 3425 - epctrl = dwc2_readl(hsotg->regs + DIEPCTL(idx)); 3436 + epctrl = dwc2_readl(hsotg, DIEPCTL(idx)); 3426 3437 if ((epctrl & DXEPCTL_EPENA) && 3427 3438 dwc2_gadget_target_frame_elapsed(hs_ep)) { 3428 3439 epctrl |= DXEPCTL_SNAK; 3429 3440 epctrl |= DXEPCTL_EPDIS; 3430 - dwc2_writel(epctrl, hsotg->regs + DIEPCTL(idx)); 3441 + dwc2_writel(hsotg, epctrl, DIEPCTL(idx)); 3431 3442 } 3432 3443 } 3433 3444 3434 3445 /* Clear interrupt */ 3435 - dwc2_writel(GINTSTS_INCOMPL_SOIN, hsotg->regs + GINTSTS); 3446 + dwc2_writel(hsotg, GINTSTS_INCOMPL_SOIN, GINTSTS); 3436 3447 } 3437 3448 3438 3449 /** ··· 3459 3470 3460 3471 dev_dbg(hsotg->dev, "%s: GINTSTS_INCOMPL_SOOUT\n", __func__); 3461 3472 3462 - daintmsk = dwc2_readl(hsotg->regs + DAINTMSK); 3473 + daintmsk = dwc2_readl(hsotg, DAINTMSK); 3463 3474 daintmsk >>= DAINT_OUTEP_SHIFT; 3464 3475 3465 3476 for (idx = 1; idx < hsotg->num_of_eps; idx++) { ··· 3468 3479 if ((BIT(idx) & ~daintmsk) || !hs_ep->isochronous) 3469 3480 continue; 3470 3481 3471 - epctrl = dwc2_readl(hsotg->regs + DOEPCTL(idx)); 3482 + epctrl = dwc2_readl(hsotg, DOEPCTL(idx)); 3472 3483 if ((epctrl & DXEPCTL_EPENA) && 3473 3484 dwc2_gadget_target_frame_elapsed(hs_ep)) { 3474 3485 /* Unmask GOUTNAKEFF interrupt */ 3475 - gintmsk = dwc2_readl(hsotg->regs + GINTMSK); 3486 + gintmsk = dwc2_readl(hsotg, GINTMSK); 3476 3487 gintmsk |= GINTSTS_GOUTNAKEFF; 3477 - dwc2_writel(gintmsk, hsotg->regs + GINTMSK); 3488 + dwc2_writel(hsotg, gintmsk, GINTMSK); 3478 3489 3479 - gintsts = dwc2_readl(hsotg->regs + GINTSTS); 3490 + gintsts = dwc2_readl(hsotg, GINTSTS); 3480 3491 if (!(gintsts & GINTSTS_GOUTNAKEFF)) { 3481 - dwc2_set_bit(hsotg->regs + DCTL, DCTL_SGOUTNAK); 3492 + dwc2_set_bit(hsotg, DCTL, DCTL_SGOUTNAK); 3482 3493 break; 3483 3494 } 3484 3495 } 3485 3496 } 3486 3497 3487 3498 /* Clear interrupt */ 3488 - dwc2_writel(GINTSTS_INCOMPL_SOOUT, hsotg->regs + GINTSTS); 3499 + dwc2_writel(hsotg, GINTSTS_INCOMPL_SOOUT, GINTSTS); 3489 3500 } 3490 3501 3491 3502 /** ··· 3505 3516 3506 3517 spin_lock(&hsotg->lock); 3507 3518 irq_retry: 3508 - gintsts = dwc2_readl(hsotg->regs + GINTSTS); 3509 - gintmsk = dwc2_readl(hsotg->regs + GINTMSK); 3519 + gintsts = dwc2_readl(hsotg, GINTSTS); 3520 + gintmsk = dwc2_readl(hsotg, GINTMSK); 3510 3521 3511 3522 dev_dbg(hsotg->dev, "%s: %08x %08x (%08x) retry %d\n", 3512 3523 __func__, gintsts, gintsts & gintmsk, gintmsk, retry_count); ··· 3516 3527 if (gintsts & GINTSTS_RESETDET) { 3517 3528 dev_dbg(hsotg->dev, "%s: USBRstDet\n", __func__); 3518 3529 3519 - dwc2_writel(GINTSTS_RESETDET, hsotg->regs + GINTSTS); 3530 + dwc2_writel(hsotg, GINTSTS_RESETDET, GINTSTS); 3520 3531 3521 3532 /* This event must be used only if controller is suspended */ 3522 3533 if (hsotg->lx_state == DWC2_L2) { ··· 3526 3537 } 3527 3538 3528 3539 if (gintsts & (GINTSTS_USBRST | GINTSTS_RESETDET)) { 3529 - u32 usb_status = dwc2_readl(hsotg->regs + GOTGCTL); 3540 + u32 usb_status = dwc2_readl(hsotg, GOTGCTL); 3530 3541 u32 connected = hsotg->connected; 3531 3542 3532 3543 dev_dbg(hsotg->dev, "%s: USBRst\n", __func__); 3533 3544 dev_dbg(hsotg->dev, "GNPTXSTS=%08x\n", 3534 - dwc2_readl(hsotg->regs + GNPTXSTS)); 3545 + dwc2_readl(hsotg, GNPTXSTS)); 3535 3546 3536 - dwc2_writel(GINTSTS_USBRST, hsotg->regs + GINTSTS); 3547 + dwc2_writel(hsotg, GINTSTS_USBRST, GINTSTS); 3537 3548 3538 3549 /* Report disconnection if it is not already done. */ 3539 3550 dwc2_hsotg_disconnect(hsotg); 3540 3551 3541 3552 /* Reset device address to zero */ 3542 - dwc2_clear_bit(hsotg->regs + DCFG, DCFG_DEVADDR_MASK); 3553 + dwc2_clear_bit(hsotg, DCFG, DCFG_DEVADDR_MASK); 3543 3554 3544 3555 if (usb_status & GOTGCTL_BSESVLD && connected) 3545 3556 dwc2_hsotg_core_init_disconnected(hsotg, true); 3546 3557 } 3547 3558 3548 3559 if (gintsts & GINTSTS_ENUMDONE) { 3549 - dwc2_writel(GINTSTS_ENUMDONE, hsotg->regs + GINTSTS); 3560 + dwc2_writel(hsotg, GINTSTS_ENUMDONE, GINTSTS); 3550 3561 3551 3562 dwc2_hsotg_irq_enumdone(hsotg); 3552 3563 } 3553 3564 3554 3565 if (gintsts & (GINTSTS_OEPINT | GINTSTS_IEPINT)) { 3555 - u32 daint = dwc2_readl(hsotg->regs + DAINT); 3556 - u32 daintmsk = dwc2_readl(hsotg->regs + DAINTMSK); 3566 + u32 daint = dwc2_readl(hsotg, DAINT); 3567 + u32 daintmsk = dwc2_readl(hsotg, DAINTMSK); 3557 3568 u32 daint_out, daint_in; 3558 3569 int ep; 3559 3570 ··· 3612 3623 3613 3624 if (gintsts & GINTSTS_ERLYSUSP) { 3614 3625 dev_dbg(hsotg->dev, "GINTSTS_ErlySusp\n"); 3615 - dwc2_writel(GINTSTS_ERLYSUSP, hsotg->regs + GINTSTS); 3626 + dwc2_writel(hsotg, GINTSTS_ERLYSUSP, GINTSTS); 3616 3627 } 3617 3628 3618 3629 /* ··· 3628 3639 u32 daintmsk; 3629 3640 struct dwc2_hsotg_ep *hs_ep; 3630 3641 3631 - daintmsk = dwc2_readl(hsotg->regs + DAINTMSK); 3642 + daintmsk = dwc2_readl(hsotg, DAINTMSK); 3632 3643 daintmsk >>= DAINT_OUTEP_SHIFT; 3633 3644 /* Mask this interrupt */ 3634 - gintmsk = dwc2_readl(hsotg->regs + GINTMSK); 3645 + gintmsk = dwc2_readl(hsotg, GINTMSK); 3635 3646 gintmsk &= ~GINTSTS_GOUTNAKEFF; 3636 - dwc2_writel(gintmsk, hsotg->regs + GINTMSK); 3647 + dwc2_writel(hsotg, gintmsk, GINTMSK); 3637 3648 3638 3649 dev_dbg(hsotg->dev, "GOUTNakEff triggered\n"); 3639 3650 for (idx = 1; idx < hsotg->num_of_eps; idx++) { ··· 3642 3653 if ((BIT(idx) & ~daintmsk) || !hs_ep->isochronous) 3643 3654 continue; 3644 3655 3645 - epctrl = dwc2_readl(hsotg->regs + DOEPCTL(idx)); 3656 + epctrl = dwc2_readl(hsotg, DOEPCTL(idx)); 3646 3657 3647 3658 if (epctrl & DXEPCTL_EPENA) { 3648 3659 epctrl |= DXEPCTL_SNAK; 3649 3660 epctrl |= DXEPCTL_EPDIS; 3650 - dwc2_writel(epctrl, hsotg->regs + DOEPCTL(idx)); 3661 + dwc2_writel(hsotg, epctrl, DOEPCTL(idx)); 3651 3662 } 3652 3663 } 3653 3664 ··· 3657 3668 if (gintsts & GINTSTS_GINNAKEFF) { 3658 3669 dev_info(hsotg->dev, "GINNakEff triggered\n"); 3659 3670 3660 - dwc2_set_bit(hsotg->regs + DCTL, DCTL_CGNPINNAK); 3671 + dwc2_set_bit(hsotg, DCTL, DCTL_CGNPINNAK); 3661 3672 3662 3673 dwc2_hsotg_dump(hsotg); 3663 3674 } ··· 3697 3708 3698 3709 if (hs_ep->dir_in) { 3699 3710 if (hsotg->dedicated_fifos || hs_ep->periodic) { 3700 - dwc2_set_bit(hsotg->regs + epctrl_reg, DXEPCTL_SNAK); 3711 + dwc2_set_bit(hsotg, epctrl_reg, DXEPCTL_SNAK); 3701 3712 /* Wait for Nak effect */ 3702 3713 if (dwc2_hsotg_wait_bit_set(hsotg, epint_reg, 3703 3714 DXEPINT_INEPNAKEFF, 100)) ··· 3705 3716 "%s: timeout DIEPINT.NAKEFF\n", 3706 3717 __func__); 3707 3718 } else { 3708 - dwc2_set_bit(hsotg->regs + DCTL, DCTL_SGNPINNAK); 3719 + dwc2_set_bit(hsotg, DCTL, DCTL_SGNPINNAK); 3709 3720 /* Wait for Nak effect */ 3710 3721 if (dwc2_hsotg_wait_bit_set(hsotg, GINTSTS, 3711 3722 GINTSTS_GINNAKEFF, 100)) ··· 3714 3725 __func__); 3715 3726 } 3716 3727 } else { 3717 - if (!(dwc2_readl(hsotg->regs + GINTSTS) & GINTSTS_GOUTNAKEFF)) 3718 - dwc2_set_bit(hsotg->regs + DCTL, DCTL_SGOUTNAK); 3728 + if (!(dwc2_readl(hsotg, GINTSTS) & GINTSTS_GOUTNAKEFF)) 3729 + dwc2_set_bit(hsotg, DCTL, DCTL_SGOUTNAK); 3719 3730 3720 3731 /* Wait for global nak to take effect */ 3721 3732 if (dwc2_hsotg_wait_bit_set(hsotg, GINTSTS, ··· 3725 3736 } 3726 3737 3727 3738 /* Disable ep */ 3728 - dwc2_set_bit(hsotg->regs + epctrl_reg, DXEPCTL_EPDIS | DXEPCTL_SNAK); 3739 + dwc2_set_bit(hsotg, epctrl_reg, DXEPCTL_EPDIS | DXEPCTL_SNAK); 3729 3740 3730 3741 /* Wait for ep to be disabled */ 3731 3742 if (dwc2_hsotg_wait_bit_set(hsotg, epint_reg, DXEPINT_EPDISBLD, 100)) ··· 3733 3744 "%s: timeout DOEPCTL.EPDisable\n", __func__); 3734 3745 3735 3746 /* Clear EPDISBLD interrupt */ 3736 - dwc2_set_bit(hsotg->regs + epint_reg, DXEPINT_EPDISBLD); 3747 + dwc2_set_bit(hsotg, epint_reg, DXEPINT_EPDISBLD); 3737 3748 3738 3749 if (hs_ep->dir_in) { 3739 3750 unsigned short fifo_index; ··· 3748 3759 3749 3760 /* Clear Global In NP NAK in Shared FIFO for non periodic ep */ 3750 3761 if (!hsotg->dedicated_fifos && !hs_ep->periodic) 3751 - dwc2_set_bit(hsotg->regs + DCTL, DCTL_CGNPINNAK); 3762 + dwc2_set_bit(hsotg, DCTL, DCTL_CGNPINNAK); 3752 3763 3753 3764 } else { 3754 3765 /* Remove global NAKs */ 3755 - dwc2_set_bit(hsotg->regs + DCTL, DCTL_CGOUTNAK); 3766 + dwc2_set_bit(hsotg, DCTL, DCTL_CGOUTNAK); 3756 3767 } 3757 3768 } 3758 3769 ··· 3820 3831 /* note, we handle this here instead of dwc2_hsotg_set_ep_maxpacket */ 3821 3832 3822 3833 epctrl_reg = dir_in ? DIEPCTL(index) : DOEPCTL(index); 3823 - epctrl = dwc2_readl(hsotg->regs + epctrl_reg); 3834 + epctrl = dwc2_readl(hsotg, epctrl_reg); 3824 3835 3825 3836 dev_dbg(hsotg->dev, "%s: read DxEPCTL=0x%08x from 0x%08x\n", 3826 3837 __func__, epctrl, epctrl_reg); ··· 3868 3879 hs_ep->compl_desc = 0; 3869 3880 if (dir_in) { 3870 3881 hs_ep->periodic = 1; 3871 - mask = dwc2_readl(hsotg->regs + DIEPMSK); 3882 + mask = dwc2_readl(hsotg, DIEPMSK); 3872 3883 mask |= DIEPMSK_NAKMSK; 3873 - dwc2_writel(mask, hsotg->regs + DIEPMSK); 3884 + dwc2_writel(hsotg, mask, DIEPMSK); 3874 3885 } else { 3875 - mask = dwc2_readl(hsotg->regs + DOEPMSK); 3886 + mask = dwc2_readl(hsotg, DOEPMSK); 3876 3887 mask |= DOEPMSK_OUTTKNEPDISMSK; 3877 - dwc2_writel(mask, hsotg->regs + DOEPMSK); 3888 + dwc2_writel(hsotg, mask, DOEPMSK); 3878 3889 } 3879 3890 break; 3880 3891 ··· 3909 3920 for (i = 1; i < hsotg->num_of_eps; ++i) { 3910 3921 if (hsotg->fifo_map & (1 << i)) 3911 3922 continue; 3912 - val = dwc2_readl(hsotg->regs + DPTXFSIZN(i)); 3923 + val = dwc2_readl(hsotg, DPTXFSIZN(i)); 3913 3924 val = (val >> FIFOSIZE_DEPTH_SHIFT) * 4; 3914 3925 if (val < size) 3915 3926 continue; ··· 3947 3958 * to 4.00a (including both). Also for FS_IOT_1.00a 3948 3959 * and HS_IOT_1.00a. 3949 3960 */ 3950 - u32 gsnpsid = dwc2_readl(hsotg->regs + GSNPSID); 3961 + u32 gsnpsid = dwc2_readl(hsotg, GSNPSID); 3951 3962 3952 3963 if ((gsnpsid >= DWC2_CORE_REV_2_72a && 3953 3964 gsnpsid <= DWC2_CORE_REV_4_00a) || ··· 3959 3970 dev_dbg(hsotg->dev, "%s: write DxEPCTL=0x%08x\n", 3960 3971 __func__, epctrl); 3961 3972 3962 - dwc2_writel(epctrl, hsotg->regs + epctrl_reg); 3973 + dwc2_writel(hsotg, epctrl, epctrl_reg); 3963 3974 dev_dbg(hsotg->dev, "%s: read DxEPCTL=0x%08x\n", 3964 - __func__, dwc2_readl(hsotg->regs + epctrl_reg)); 3975 + __func__, dwc2_readl(hsotg, epctrl_reg)); 3965 3976 3966 3977 /* enable the endpoint interrupt */ 3967 3978 dwc2_hsotg_ctrl_epint(hsotg, index, dir_in, 1); ··· 4010 4021 4011 4022 spin_lock_irqsave(&hsotg->lock, flags); 4012 4023 4013 - ctrl = dwc2_readl(hsotg->regs + epctrl_reg); 4024 + ctrl = dwc2_readl(hsotg, epctrl_reg); 4014 4025 4015 4026 if (ctrl & DXEPCTL_EPENA) 4016 4027 dwc2_hsotg_ep_stop_xfr(hsotg, hs_ep); ··· 4020 4031 ctrl |= DXEPCTL_SNAK; 4021 4032 4022 4033 dev_dbg(hsotg->dev, "%s: DxEPCTL=0x%08x\n", __func__, ctrl); 4023 - dwc2_writel(ctrl, hsotg->regs + epctrl_reg); 4034 + dwc2_writel(hsotg, ctrl, epctrl_reg); 4024 4035 4025 4036 /* disable endpoint interrupts */ 4026 4037 dwc2_hsotg_ctrl_epint(hsotg, hs_ep->index, hs_ep->dir_in, 0); ··· 4127 4138 4128 4139 if (hs_ep->dir_in) { 4129 4140 epreg = DIEPCTL(index); 4130 - epctl = dwc2_readl(hs->regs + epreg); 4141 + epctl = dwc2_readl(hs, epreg); 4131 4142 4132 4143 if (value) { 4133 4144 epctl |= DXEPCTL_STALL | DXEPCTL_SNAK; ··· 4140 4151 xfertype == DXEPCTL_EPTYPE_INTERRUPT) 4141 4152 epctl |= DXEPCTL_SETD0PID; 4142 4153 } 4143 - dwc2_writel(epctl, hs->regs + epreg); 4154 + dwc2_writel(hs, epctl, epreg); 4144 4155 } else { 4145 4156 epreg = DOEPCTL(index); 4146 - epctl = dwc2_readl(hs->regs + epreg); 4157 + epctl = dwc2_readl(hs, epreg); 4147 4158 4148 4159 if (value) { 4149 4160 epctl |= DXEPCTL_STALL; ··· 4154 4165 xfertype == DXEPCTL_EPTYPE_INTERRUPT) 4155 4166 epctl |= DXEPCTL_SETD0PID; 4156 4167 } 4157 - dwc2_writel(epctl, hs->regs + epreg); 4168 + dwc2_writel(hs, epctl, epreg); 4158 4169 } 4159 4170 4160 4171 hs_ep->halted = value; ··· 4202 4213 u32 usbcfg; 4203 4214 /* unmask subset of endpoint interrupts */ 4204 4215 4205 - dwc2_writel(DIEPMSK_TIMEOUTMSK | DIEPMSK_AHBERRMSK | 4216 + dwc2_writel(hsotg, DIEPMSK_TIMEOUTMSK | DIEPMSK_AHBERRMSK | 4206 4217 DIEPMSK_EPDISBLDMSK | DIEPMSK_XFERCOMPLMSK, 4207 - hsotg->regs + DIEPMSK); 4218 + DIEPMSK); 4208 4219 4209 - dwc2_writel(DOEPMSK_SETUPMSK | DOEPMSK_AHBERRMSK | 4220 + dwc2_writel(hsotg, DOEPMSK_SETUPMSK | DOEPMSK_AHBERRMSK | 4210 4221 DOEPMSK_EPDISBLDMSK | DOEPMSK_XFERCOMPLMSK, 4211 - hsotg->regs + DOEPMSK); 4222 + DOEPMSK); 4212 4223 4213 - dwc2_writel(0, hsotg->regs + DAINTMSK); 4224 + dwc2_writel(hsotg, 0, DAINTMSK); 4214 4225 4215 4226 /* Be in disconnected state until gadget is registered */ 4216 - dwc2_set_bit(hsotg->regs + DCTL, DCTL_SFTDISCON); 4227 + dwc2_set_bit(hsotg, DCTL, DCTL_SFTDISCON); 4217 4228 4218 4229 /* setup fifos */ 4219 4230 4220 4231 dev_dbg(hsotg->dev, "GRXFSIZ=0x%08x, GNPTXFSIZ=0x%08x\n", 4221 - dwc2_readl(hsotg->regs + GRXFSIZ), 4222 - dwc2_readl(hsotg->regs + GNPTXFSIZ)); 4232 + dwc2_readl(hsotg, GRXFSIZ), 4233 + dwc2_readl(hsotg, GNPTXFSIZ)); 4223 4234 4224 4235 dwc2_hsotg_init_fifo(hsotg); 4225 4236 4226 4237 /* keep other bits untouched (so e.g. forced modes are not lost) */ 4227 - usbcfg = dwc2_readl(hsotg->regs + GUSBCFG); 4238 + usbcfg = dwc2_readl(hsotg, GUSBCFG); 4228 4239 usbcfg &= ~(GUSBCFG_TOUTCAL_MASK | GUSBCFG_PHYIF16 | GUSBCFG_SRPCAP | 4229 4240 GUSBCFG_HNPCAP | GUSBCFG_USBTRDTIM_MASK); 4230 4241 ··· 4232 4243 trdtim = (hsotg->phyif == GUSBCFG_PHYIF8) ? 9 : 5; 4233 4244 usbcfg |= hsotg->phyif | GUSBCFG_TOUTCAL(7) | 4234 4245 (trdtim << GUSBCFG_USBTRDTIM_SHIFT); 4235 - dwc2_writel(usbcfg, hsotg->regs + GUSBCFG); 4246 + dwc2_writel(hsotg, usbcfg, GUSBCFG); 4236 4247 4237 4248 if (using_dma(hsotg)) 4238 - dwc2_set_bit(hsotg->regs + GAHBCFG, GAHBCFG_DMA_EN); 4249 + dwc2_set_bit(hsotg, GAHBCFG, GAHBCFG_DMA_EN); 4239 4250 } 4240 4251 4241 4252 /** ··· 4525 4536 u32 next = DXEPCTL_NEXTEP((epnum + 1) % 15); 4526 4537 4527 4538 if (dir_in) 4528 - dwc2_writel(next, hsotg->regs + DIEPCTL(epnum)); 4539 + dwc2_writel(hsotg, next, DIEPCTL(epnum)); 4529 4540 else 4530 - dwc2_writel(next, hsotg->regs + DOEPCTL(epnum)); 4541 + dwc2_writel(hsotg, next, DOEPCTL(epnum)); 4531 4542 } 4532 4543 } 4533 4544 ··· 4596 4607 { 4597 4608 #ifdef DEBUG 4598 4609 struct device *dev = hsotg->dev; 4599 - void __iomem *regs = hsotg->regs; 4600 4610 u32 val; 4601 4611 int idx; 4602 4612 4603 4613 dev_info(dev, "DCFG=0x%08x, DCTL=0x%08x, DIEPMSK=%08x\n", 4604 - dwc2_readl(regs + DCFG), dwc2_readl(regs + DCTL), 4605 - dwc2_readl(regs + DIEPMSK)); 4614 + dwc2_readl(hsotg, DCFG), dwc2_readl(hsotg, DCTL), 4615 + dwc2_readl(hsotg, DIEPMSK)); 4606 4616 4607 4617 dev_info(dev, "GAHBCFG=0x%08x, GHWCFG1=0x%08x\n", 4608 - dwc2_readl(regs + GAHBCFG), dwc2_readl(regs + GHWCFG1)); 4618 + dwc2_readl(hsotg, GAHBCFG), dwc2_readl(hsotg, GHWCFG1)); 4609 4619 4610 4620 dev_info(dev, "GRXFSIZ=0x%08x, GNPTXFSIZ=0x%08x\n", 4611 - dwc2_readl(regs + GRXFSIZ), dwc2_readl(regs + GNPTXFSIZ)); 4621 + dwc2_readl(hsotg, GRXFSIZ), dwc2_readl(hsotg, GNPTXFSIZ)); 4612 4622 4613 4623 /* show periodic fifo settings */ 4614 4624 4615 4625 for (idx = 1; idx < hsotg->num_of_eps; idx++) { 4616 - val = dwc2_readl(regs + DPTXFSIZN(idx)); 4626 + val = dwc2_readl(hsotg, DPTXFSIZN(idx)); 4617 4627 dev_info(dev, "DPTx[%d] FSize=%d, StAddr=0x%08x\n", idx, 4618 4628 val >> FIFOSIZE_DEPTH_SHIFT, 4619 4629 val & FIFOSIZE_STARTADDR_MASK); ··· 4621 4633 for (idx = 0; idx < hsotg->num_of_eps; idx++) { 4622 4634 dev_info(dev, 4623 4635 "ep%d-in: EPCTL=0x%08x, SIZ=0x%08x, DMA=0x%08x\n", idx, 4624 - dwc2_readl(regs + DIEPCTL(idx)), 4625 - dwc2_readl(regs + DIEPTSIZ(idx)), 4626 - dwc2_readl(regs + DIEPDMA(idx))); 4636 + dwc2_readl(hsotg, DIEPCTL(idx)), 4637 + dwc2_readl(hsotg, DIEPTSIZ(idx)), 4638 + dwc2_readl(hsotg, DIEPDMA(idx))); 4627 4639 4628 - val = dwc2_readl(regs + DOEPCTL(idx)); 4640 + val = dwc2_readl(hsotg, DOEPCTL(idx)); 4629 4641 dev_info(dev, 4630 4642 "ep%d-out: EPCTL=0x%08x, SIZ=0x%08x, DMA=0x%08x\n", 4631 - idx, dwc2_readl(regs + DOEPCTL(idx)), 4632 - dwc2_readl(regs + DOEPTSIZ(idx)), 4633 - dwc2_readl(regs + DOEPDMA(idx))); 4643 + idx, dwc2_readl(hsotg, DOEPCTL(idx)), 4644 + dwc2_readl(hsotg, DOEPTSIZ(idx)), 4645 + dwc2_readl(hsotg, DOEPDMA(idx))); 4634 4646 } 4635 4647 4636 4648 dev_info(dev, "DVBUSDIS=0x%08x, DVBUSPULSE=%08x\n", 4637 - dwc2_readl(regs + DVBUSDIS), dwc2_readl(regs + DVBUSPULSE)); 4649 + dwc2_readl(hsotg, DVBUSDIS), dwc2_readl(hsotg, DVBUSPULSE)); 4638 4650 #endif 4639 4651 } 4640 4652 ··· 4823 4835 /* Backup dev regs */ 4824 4836 dr = &hsotg->dr_backup; 4825 4837 4826 - dr->dcfg = dwc2_readl(hsotg->regs + DCFG); 4827 - dr->dctl = dwc2_readl(hsotg->regs + DCTL); 4828 - dr->daintmsk = dwc2_readl(hsotg->regs + DAINTMSK); 4829 - dr->diepmsk = dwc2_readl(hsotg->regs + DIEPMSK); 4830 - dr->doepmsk = dwc2_readl(hsotg->regs + DOEPMSK); 4838 + dr->dcfg = dwc2_readl(hsotg, DCFG); 4839 + dr->dctl = dwc2_readl(hsotg, DCTL); 4840 + dr->daintmsk = dwc2_readl(hsotg, DAINTMSK); 4841 + dr->diepmsk = dwc2_readl(hsotg, DIEPMSK); 4842 + dr->doepmsk = dwc2_readl(hsotg, DOEPMSK); 4831 4843 4832 4844 for (i = 0; i < hsotg->num_of_eps; i++) { 4833 4845 /* Backup IN EPs */ 4834 - dr->diepctl[i] = dwc2_readl(hsotg->regs + DIEPCTL(i)); 4846 + dr->diepctl[i] = dwc2_readl(hsotg, DIEPCTL(i)); 4835 4847 4836 4848 /* Ensure DATA PID is correctly configured */ 4837 4849 if (dr->diepctl[i] & DXEPCTL_DPID) ··· 4839 4851 else 4840 4852 dr->diepctl[i] |= DXEPCTL_SETD0PID; 4841 4853 4842 - dr->dieptsiz[i] = dwc2_readl(hsotg->regs + DIEPTSIZ(i)); 4843 - dr->diepdma[i] = dwc2_readl(hsotg->regs + DIEPDMA(i)); 4854 + dr->dieptsiz[i] = dwc2_readl(hsotg, DIEPTSIZ(i)); 4855 + dr->diepdma[i] = dwc2_readl(hsotg, DIEPDMA(i)); 4844 4856 4845 4857 /* Backup OUT EPs */ 4846 - dr->doepctl[i] = dwc2_readl(hsotg->regs + DOEPCTL(i)); 4858 + dr->doepctl[i] = dwc2_readl(hsotg, DOEPCTL(i)); 4847 4859 4848 4860 /* Ensure DATA PID is correctly configured */ 4849 4861 if (dr->doepctl[i] & DXEPCTL_DPID) ··· 4851 4863 else 4852 4864 dr->doepctl[i] |= DXEPCTL_SETD0PID; 4853 4865 4854 - dr->doeptsiz[i] = dwc2_readl(hsotg->regs + DOEPTSIZ(i)); 4855 - dr->doepdma[i] = dwc2_readl(hsotg->regs + DOEPDMA(i)); 4856 - dr->dtxfsiz[i] = dwc2_readl(hsotg->regs + DPTXFSIZN(i)); 4866 + dr->doeptsiz[i] = dwc2_readl(hsotg, DOEPTSIZ(i)); 4867 + dr->doepdma[i] = dwc2_readl(hsotg, DOEPDMA(i)); 4868 + dr->dtxfsiz[i] = dwc2_readl(hsotg, DPTXFSIZN(i)); 4857 4869 } 4858 4870 dr->valid = true; 4859 4871 return 0; ··· 4886 4898 dr->valid = false; 4887 4899 4888 4900 if (!remote_wakeup) 4889 - dwc2_writel(dr->dctl, hsotg->regs + DCTL); 4901 + dwc2_writel(hsotg, dr->dctl, DCTL); 4890 4902 4891 - dwc2_writel(dr->daintmsk, hsotg->regs + DAINTMSK); 4892 - dwc2_writel(dr->diepmsk, hsotg->regs + DIEPMSK); 4893 - dwc2_writel(dr->doepmsk, hsotg->regs + DOEPMSK); 4903 + dwc2_writel(hsotg, dr->daintmsk, DAINTMSK); 4904 + dwc2_writel(hsotg, dr->diepmsk, DIEPMSK); 4905 + dwc2_writel(hsotg, dr->doepmsk, DOEPMSK); 4894 4906 4895 4907 for (i = 0; i < hsotg->num_of_eps; i++) { 4896 4908 /* Restore IN EPs */ 4897 - dwc2_writel(dr->dieptsiz[i], hsotg->regs + DIEPTSIZ(i)); 4898 - dwc2_writel(dr->diepdma[i], hsotg->regs + DIEPDMA(i)); 4899 - dwc2_writel(dr->doeptsiz[i], hsotg->regs + DOEPTSIZ(i)); 4909 + dwc2_writel(hsotg, dr->dieptsiz[i], DIEPTSIZ(i)); 4910 + dwc2_writel(hsotg, dr->diepdma[i], DIEPDMA(i)); 4911 + dwc2_writel(hsotg, dr->doeptsiz[i], DOEPTSIZ(i)); 4900 4912 /** WA for enabled EPx's IN in DDMA mode. On entering to 4901 4913 * hibernation wrong value read and saved from DIEPDMAx, 4902 4914 * as result BNA interrupt asserted on hibernation exit ··· 4905 4917 if (hsotg->params.g_dma_desc && 4906 4918 (dr->diepctl[i] & DXEPCTL_EPENA)) 4907 4919 dr->diepdma[i] = hsotg->eps_in[i]->desc_list_dma; 4908 - dwc2_writel(dr->dtxfsiz[i], hsotg->regs + DPTXFSIZN(i)); 4909 - dwc2_writel(dr->diepctl[i], hsotg->regs + DIEPCTL(i)); 4920 + dwc2_writel(hsotg, dr->dtxfsiz[i], DPTXFSIZN(i)); 4921 + dwc2_writel(hsotg, dr->diepctl[i], DIEPCTL(i)); 4910 4922 /* Restore OUT EPs */ 4911 - dwc2_writel(dr->doeptsiz[i], hsotg->regs + DOEPTSIZ(i)); 4923 + dwc2_writel(hsotg, dr->doeptsiz[i], DOEPTSIZ(i)); 4912 4924 /* WA for enabled EPx's OUT in DDMA mode. On entering to 4913 4925 * hibernation wrong value read and saved from DOEPDMAx, 4914 4926 * as result BNA interrupt asserted on hibernation exit ··· 4917 4929 if (hsotg->params.g_dma_desc && 4918 4930 (dr->doepctl[i] & DXEPCTL_EPENA)) 4919 4931 dr->doepdma[i] = hsotg->eps_out[i]->desc_list_dma; 4920 - dwc2_writel(dr->doepdma[i], hsotg->regs + DOEPDMA(i)); 4921 - dwc2_writel(dr->doepctl[i], hsotg->regs + DOEPCTL(i)); 4932 + dwc2_writel(hsotg, dr->doepdma[i], DOEPDMA(i)); 4933 + dwc2_writel(hsotg, dr->doepctl[i], DOEPCTL(i)); 4922 4934 } 4923 4935 4924 4936 return 0; ··· 4942 4954 val |= hsotg->params.lpm_clock_gating ? GLPMCFG_ENBLSLPM : 0; 4943 4955 val |= hsotg->params.hird_threshold << GLPMCFG_HIRD_THRES_SHIFT; 4944 4956 val |= hsotg->params.besl ? GLPMCFG_ENBESL : 0; 4945 - dwc2_writel(val, hsotg->regs + GLPMCFG); 4946 - dev_dbg(hsotg->dev, "GLPMCFG=0x%08x\n", dwc2_readl(hsotg->regs 4947 - + GLPMCFG)); 4957 + dwc2_writel(hsotg, val, GLPMCFG); 4958 + dev_dbg(hsotg->dev, "GLPMCFG=0x%08x\n", dwc2_readl(hsotg, GLPMCFG)); 4948 4959 } 4949 4960 4950 4961 /** ··· 4976 4989 4977 4990 gpwrdn = GPWRDN_PWRDNRSTN; 4978 4991 gpwrdn |= GPWRDN_PMUACTV; 4979 - dwc2_writel(gpwrdn, hsotg->regs + GPWRDN); 4992 + dwc2_writel(hsotg, gpwrdn, GPWRDN); 4980 4993 udelay(10); 4981 4994 4982 4995 /* Set flag to indicate that we are in hibernation */ 4983 4996 hsotg->hibernated = 1; 4984 4997 4985 4998 /* Enable interrupts from wake up logic */ 4986 - gpwrdn = dwc2_readl(hsotg->regs + GPWRDN); 4999 + gpwrdn = dwc2_readl(hsotg, GPWRDN); 4987 5000 gpwrdn |= GPWRDN_PMUINTSEL; 4988 - dwc2_writel(gpwrdn, hsotg->regs + GPWRDN); 5001 + dwc2_writel(hsotg, gpwrdn, GPWRDN); 4989 5002 udelay(10); 4990 5003 4991 5004 /* Unmask device mode interrupts in GPWRDN */ 4992 - gpwrdn = dwc2_readl(hsotg->regs + GPWRDN); 5005 + gpwrdn = dwc2_readl(hsotg, GPWRDN); 4993 5006 gpwrdn |= GPWRDN_RST_DET_MSK; 4994 5007 gpwrdn |= GPWRDN_LNSTSCHG_MSK; 4995 5008 gpwrdn |= GPWRDN_STS_CHGINT_MSK; 4996 - dwc2_writel(gpwrdn, hsotg->regs + GPWRDN); 5009 + dwc2_writel(hsotg, gpwrdn, GPWRDN); 4997 5010 udelay(10); 4998 5011 4999 5012 /* Enable Power Down Clamp */ 5000 - gpwrdn = dwc2_readl(hsotg->regs + GPWRDN); 5013 + gpwrdn = dwc2_readl(hsotg, GPWRDN); 5001 5014 gpwrdn |= GPWRDN_PWRDNCLMP; 5002 - dwc2_writel(gpwrdn, hsotg->regs + GPWRDN); 5015 + dwc2_writel(hsotg, gpwrdn, GPWRDN); 5003 5016 udelay(10); 5004 5017 5005 5018 /* Switch off VDD */ 5006 - gpwrdn = dwc2_readl(hsotg->regs + GPWRDN); 5019 + gpwrdn = dwc2_readl(hsotg, GPWRDN); 5007 5020 gpwrdn |= GPWRDN_PWRDNSWTCH; 5008 - dwc2_writel(gpwrdn, hsotg->regs + GPWRDN); 5021 + dwc2_writel(hsotg, gpwrdn, GPWRDN); 5009 5022 udelay(10); 5010 5023 5011 5024 /* Save gpwrdn register for further usage if stschng interrupt */ 5012 - hsotg->gr_backup.gpwrdn = dwc2_readl(hsotg->regs + GPWRDN); 5025 + hsotg->gr_backup.gpwrdn = dwc2_readl(hsotg, GPWRDN); 5013 5026 dev_dbg(hsotg->dev, "Hibernation completed\n"); 5014 5027 5015 5028 return ret; ··· 5051 5064 5052 5065 if (!reset) { 5053 5066 /* Clear all pending interupts */ 5054 - dwc2_writel(0xffffffff, hsotg->regs + GINTSTS); 5067 + dwc2_writel(hsotg, 0xffffffff, GINTSTS); 5055 5068 } 5056 5069 5057 5070 /* De-assert Restore */ 5058 - gpwrdn = dwc2_readl(hsotg->regs + GPWRDN); 5071 + gpwrdn = dwc2_readl(hsotg, GPWRDN); 5059 5072 gpwrdn &= ~GPWRDN_RESTORE; 5060 - dwc2_writel(gpwrdn, hsotg->regs + GPWRDN); 5073 + dwc2_writel(hsotg, gpwrdn, GPWRDN); 5061 5074 udelay(10); 5062 5075 5063 5076 if (!rem_wakeup) { 5064 - pcgcctl = dwc2_readl(hsotg->regs + PCGCTL); 5077 + pcgcctl = dwc2_readl(hsotg, PCGCTL); 5065 5078 pcgcctl &= ~PCGCTL_RSTPDWNMODULE; 5066 - dwc2_writel(pcgcctl, hsotg->regs + PCGCTL); 5079 + dwc2_writel(hsotg, pcgcctl, PCGCTL); 5067 5080 } 5068 5081 5069 5082 /* Restore GUSBCFG, DCFG and DCTL */ 5070 - dwc2_writel(gr->gusbcfg, hsotg->regs + GUSBCFG); 5071 - dwc2_writel(dr->dcfg, hsotg->regs + DCFG); 5072 - dwc2_writel(dr->dctl, hsotg->regs + DCTL); 5083 + dwc2_writel(hsotg, gr->gusbcfg, GUSBCFG); 5084 + dwc2_writel(hsotg, dr->dcfg, DCFG); 5085 + dwc2_writel(hsotg, dr->dctl, DCTL); 5073 5086 5074 5087 /* De-assert Wakeup Logic */ 5075 - gpwrdn = dwc2_readl(hsotg->regs + GPWRDN); 5088 + gpwrdn = dwc2_readl(hsotg, GPWRDN); 5076 5089 gpwrdn &= ~GPWRDN_PMUACTV; 5077 - dwc2_writel(gpwrdn, hsotg->regs + GPWRDN); 5090 + dwc2_writel(hsotg, gpwrdn, GPWRDN); 5078 5091 5079 5092 if (rem_wakeup) { 5080 5093 udelay(10); 5081 5094 /* Start Remote Wakeup Signaling */ 5082 - dwc2_writel(dr->dctl | DCTL_RMTWKUPSIG, hsotg->regs + DCTL); 5095 + dwc2_writel(hsotg, dr->dctl | DCTL_RMTWKUPSIG, DCTL); 5083 5096 } else { 5084 5097 udelay(50); 5085 5098 /* Set Device programming done bit */ 5086 - dctl = dwc2_readl(hsotg->regs + DCTL); 5099 + dctl = dwc2_readl(hsotg, DCTL); 5087 5100 dctl |= DCTL_PWRONPRGDONE; 5088 - dwc2_writel(dctl, hsotg->regs + DCTL); 5101 + dwc2_writel(hsotg, dctl, DCTL); 5089 5102 } 5090 5103 /* Wait for interrupts which must be cleared */ 5091 5104 mdelay(2); 5092 5105 /* Clear all pending interupts */ 5093 - dwc2_writel(0xffffffff, hsotg->regs + GINTSTS); 5106 + dwc2_writel(hsotg, 0xffffffff, GINTSTS); 5094 5107 5095 5108 /* Restore global registers */ 5096 5109 ret = dwc2_restore_global_registers(hsotg); ··· 5110 5123 5111 5124 if (rem_wakeup) { 5112 5125 mdelay(10); 5113 - dctl = dwc2_readl(hsotg->regs + DCTL); 5126 + dctl = dwc2_readl(hsotg, DCTL); 5114 5127 dctl &= ~DCTL_RMTWKUPSIG; 5115 - dwc2_writel(dctl, hsotg->regs + DCTL); 5128 + dwc2_writel(hsotg, dctl, DCTL); 5116 5129 } 5117 5130 5118 5131 hsotg->hibernated = 0;
+229 -230
drivers/usb/dwc2/hcd.c
··· 75 75 u32 intmsk; 76 76 77 77 /* Clear any pending OTG Interrupts */ 78 - dwc2_writel(0xffffffff, hsotg->regs + GOTGINT); 78 + dwc2_writel(hsotg, 0xffffffff, GOTGINT); 79 79 80 80 /* Clear any pending interrupts */ 81 - dwc2_writel(0xffffffff, hsotg->regs + GINTSTS); 81 + dwc2_writel(hsotg, 0xffffffff, GINTSTS); 82 82 83 83 /* Enable the interrupts in the GINTMSK */ 84 84 intmsk = GINTSTS_MODEMIS | GINTSTS_OTGINT; ··· 94 94 if (dwc2_is_device_mode(hsotg) && hsotg->params.lpm) 95 95 intmsk |= GINTSTS_LPMTRANRCVD; 96 96 97 - dwc2_writel(intmsk, hsotg->regs + GINTMSK); 97 + dwc2_writel(hsotg, intmsk, GINTMSK); 98 98 } 99 99 100 100 /* ··· 117 117 } 118 118 119 119 dev_dbg(hsotg->dev, "Initializing HCFG.FSLSPClkSel to %08x\n", val); 120 - hcfg = dwc2_readl(hsotg->regs + HCFG); 120 + hcfg = dwc2_readl(hsotg, HCFG); 121 121 hcfg &= ~HCFG_FSLSPCLKSEL_MASK; 122 122 hcfg |= val << HCFG_FSLSPCLKSEL_SHIFT; 123 - dwc2_writel(hcfg, hsotg->regs + HCFG); 123 + dwc2_writel(hsotg, hcfg, HCFG); 124 124 } 125 125 126 126 static int dwc2_fs_phy_init(struct dwc2_hsotg *hsotg, bool select_phy) ··· 135 135 if (select_phy) { 136 136 dev_dbg(hsotg->dev, "FS PHY selected\n"); 137 137 138 - usbcfg = dwc2_readl(hsotg->regs + GUSBCFG); 138 + usbcfg = dwc2_readl(hsotg, GUSBCFG); 139 139 if (!(usbcfg & GUSBCFG_PHYSEL)) { 140 140 usbcfg |= GUSBCFG_PHYSEL; 141 - dwc2_writel(usbcfg, hsotg->regs + GUSBCFG); 141 + dwc2_writel(hsotg, usbcfg, GUSBCFG); 142 142 143 143 /* Reset after a PHY select */ 144 144 retval = dwc2_core_reset(hsotg, false); ··· 151 151 } 152 152 153 153 if (hsotg->params.activate_stm_fs_transceiver) { 154 - ggpio = dwc2_readl(hsotg->regs + GGPIO); 154 + ggpio = dwc2_readl(hsotg, GGPIO); 155 155 if (!(ggpio & GGPIO_STM32_OTG_GCCFG_PWRDWN)) { 156 156 dev_dbg(hsotg->dev, "Activating transceiver\n"); 157 157 /* ··· 159 159 * core configuration register. 160 160 */ 161 161 ggpio |= GGPIO_STM32_OTG_GCCFG_PWRDWN; 162 - dwc2_writel(ggpio, hsotg->regs + GGPIO); 162 + dwc2_writel(hsotg, ggpio, GGPIO); 163 163 } 164 164 } 165 165 } ··· 176 176 dev_dbg(hsotg->dev, "FS PHY enabling I2C\n"); 177 177 178 178 /* Program GUSBCFG.OtgUtmiFsSel to I2C */ 179 - usbcfg = dwc2_readl(hsotg->regs + GUSBCFG); 179 + usbcfg = dwc2_readl(hsotg, GUSBCFG); 180 180 usbcfg |= GUSBCFG_OTG_UTMI_FS_SEL; 181 - dwc2_writel(usbcfg, hsotg->regs + GUSBCFG); 181 + dwc2_writel(hsotg, usbcfg, GUSBCFG); 182 182 183 183 /* Program GI2CCTL.I2CEn */ 184 - i2cctl = dwc2_readl(hsotg->regs + GI2CCTL); 184 + i2cctl = dwc2_readl(hsotg, GI2CCTL); 185 185 i2cctl &= ~GI2CCTL_I2CDEVADDR_MASK; 186 186 i2cctl |= 1 << GI2CCTL_I2CDEVADDR_SHIFT; 187 187 i2cctl &= ~GI2CCTL_I2CEN; 188 - dwc2_writel(i2cctl, hsotg->regs + GI2CCTL); 188 + dwc2_writel(hsotg, i2cctl, GI2CCTL); 189 189 i2cctl |= GI2CCTL_I2CEN; 190 - dwc2_writel(i2cctl, hsotg->regs + GI2CCTL); 190 + dwc2_writel(hsotg, i2cctl, GI2CCTL); 191 191 } 192 192 193 193 return retval; ··· 201 201 if (!select_phy) 202 202 return 0; 203 203 204 - usbcfg = dwc2_readl(hsotg->regs + GUSBCFG); 204 + usbcfg = dwc2_readl(hsotg, GUSBCFG); 205 205 usbcfg_old = usbcfg; 206 206 207 207 /* ··· 236 236 } 237 237 238 238 if (usbcfg != usbcfg_old) { 239 - dwc2_writel(usbcfg, hsotg->regs + GUSBCFG); 239 + dwc2_writel(hsotg, usbcfg, GUSBCFG); 240 240 241 241 /* Reset after setting the PHY parameters */ 242 242 retval = dwc2_core_reset(hsotg, false); ··· 273 273 hsotg->hw_params.fs_phy_type == GHWCFG2_FS_PHY_TYPE_DEDICATED && 274 274 hsotg->params.ulpi_fs_ls) { 275 275 dev_dbg(hsotg->dev, "Setting ULPI FSLS\n"); 276 - usbcfg = dwc2_readl(hsotg->regs + GUSBCFG); 276 + usbcfg = dwc2_readl(hsotg, GUSBCFG); 277 277 usbcfg |= GUSBCFG_ULPI_FS_LS; 278 278 usbcfg |= GUSBCFG_ULPI_CLK_SUSP_M; 279 - dwc2_writel(usbcfg, hsotg->regs + GUSBCFG); 279 + dwc2_writel(hsotg, usbcfg, GUSBCFG); 280 280 } else { 281 - usbcfg = dwc2_readl(hsotg->regs + GUSBCFG); 281 + usbcfg = dwc2_readl(hsotg, GUSBCFG); 282 282 usbcfg &= ~GUSBCFG_ULPI_FS_LS; 283 283 usbcfg &= ~GUSBCFG_ULPI_CLK_SUSP_M; 284 - dwc2_writel(usbcfg, hsotg->regs + GUSBCFG); 284 + dwc2_writel(hsotg, usbcfg, GUSBCFG); 285 285 } 286 286 287 287 return retval; ··· 289 289 290 290 static int dwc2_gahbcfg_init(struct dwc2_hsotg *hsotg) 291 291 { 292 - u32 ahbcfg = dwc2_readl(hsotg->regs + GAHBCFG); 292 + u32 ahbcfg = dwc2_readl(hsotg, GAHBCFG); 293 293 294 294 switch (hsotg->hw_params.arch) { 295 295 case GHWCFG2_EXT_DMA_ARCH: ··· 316 316 else 317 317 hsotg->params.dma_desc_enable = false; 318 318 319 - dwc2_writel(ahbcfg, hsotg->regs + GAHBCFG); 319 + dwc2_writel(hsotg, ahbcfg, GAHBCFG); 320 320 321 321 return 0; 322 322 } ··· 325 325 { 326 326 u32 usbcfg; 327 327 328 - usbcfg = dwc2_readl(hsotg->regs + GUSBCFG); 328 + usbcfg = dwc2_readl(hsotg, GUSBCFG); 329 329 usbcfg &= ~(GUSBCFG_HNPCAP | GUSBCFG_SRPCAP); 330 330 331 331 switch (hsotg->hw_params.op_mode) { ··· 353 353 break; 354 354 } 355 355 356 - dwc2_writel(usbcfg, hsotg->regs + GUSBCFG); 356 + dwc2_writel(hsotg, usbcfg, GUSBCFG); 357 357 } 358 358 359 359 static int dwc2_vbus_supply_init(struct dwc2_hsotg *hsotg) ··· 390 390 dev_dbg(hsotg->dev, "%s()\n", __func__); 391 391 392 392 /* Disable all interrupts */ 393 - dwc2_writel(0, hsotg->regs + GINTMSK); 394 - dwc2_writel(0, hsotg->regs + HAINTMSK); 393 + dwc2_writel(hsotg, 0, GINTMSK); 394 + dwc2_writel(hsotg, 0, HAINTMSK); 395 395 396 396 /* Enable the common interrupts */ 397 397 dwc2_enable_common_interrupts(hsotg); 398 398 399 399 /* Enable host mode interrupts without disturbing common interrupts */ 400 - intmsk = dwc2_readl(hsotg->regs + GINTMSK); 400 + intmsk = dwc2_readl(hsotg, GINTMSK); 401 401 intmsk |= GINTSTS_DISCONNINT | GINTSTS_PRTINT | GINTSTS_HCHINT; 402 - dwc2_writel(intmsk, hsotg->regs + GINTMSK); 402 + dwc2_writel(hsotg, intmsk, GINTMSK); 403 403 } 404 404 405 405 /** ··· 409 409 */ 410 410 static void dwc2_disable_host_interrupts(struct dwc2_hsotg *hsotg) 411 411 { 412 - u32 intmsk = dwc2_readl(hsotg->regs + GINTMSK); 412 + u32 intmsk = dwc2_readl(hsotg, GINTMSK); 413 413 414 414 /* Disable host mode interrupts without disturbing common interrupts */ 415 415 intmsk &= ~(GINTSTS_SOF | GINTSTS_PRTINT | GINTSTS_HCHINT | 416 416 GINTSTS_PTXFEMP | GINTSTS_NPTXFEMP | GINTSTS_DISCONNINT); 417 - dwc2_writel(intmsk, hsotg->regs + GINTMSK); 417 + dwc2_writel(hsotg, intmsk, GINTMSK); 418 418 } 419 419 420 420 /* ··· 494 494 dwc2_calculate_dynamic_fifo(hsotg); 495 495 496 496 /* Rx FIFO */ 497 - grxfsiz = dwc2_readl(hsotg->regs + GRXFSIZ); 497 + grxfsiz = dwc2_readl(hsotg, GRXFSIZ); 498 498 dev_dbg(hsotg->dev, "initial grxfsiz=%08x\n", grxfsiz); 499 499 grxfsiz &= ~GRXFSIZ_DEPTH_MASK; 500 500 grxfsiz |= params->host_rx_fifo_size << 501 501 GRXFSIZ_DEPTH_SHIFT & GRXFSIZ_DEPTH_MASK; 502 - dwc2_writel(grxfsiz, hsotg->regs + GRXFSIZ); 502 + dwc2_writel(hsotg, grxfsiz, GRXFSIZ); 503 503 dev_dbg(hsotg->dev, "new grxfsiz=%08x\n", 504 - dwc2_readl(hsotg->regs + GRXFSIZ)); 504 + dwc2_readl(hsotg, GRXFSIZ)); 505 505 506 506 /* Non-periodic Tx FIFO */ 507 507 dev_dbg(hsotg->dev, "initial gnptxfsiz=%08x\n", 508 - dwc2_readl(hsotg->regs + GNPTXFSIZ)); 508 + dwc2_readl(hsotg, GNPTXFSIZ)); 509 509 nptxfsiz = params->host_nperio_tx_fifo_size << 510 510 FIFOSIZE_DEPTH_SHIFT & FIFOSIZE_DEPTH_MASK; 511 511 nptxfsiz |= params->host_rx_fifo_size << 512 512 FIFOSIZE_STARTADDR_SHIFT & FIFOSIZE_STARTADDR_MASK; 513 - dwc2_writel(nptxfsiz, hsotg->regs + GNPTXFSIZ); 513 + dwc2_writel(hsotg, nptxfsiz, GNPTXFSIZ); 514 514 dev_dbg(hsotg->dev, "new gnptxfsiz=%08x\n", 515 - dwc2_readl(hsotg->regs + GNPTXFSIZ)); 515 + dwc2_readl(hsotg, GNPTXFSIZ)); 516 516 517 517 /* Periodic Tx FIFO */ 518 518 dev_dbg(hsotg->dev, "initial hptxfsiz=%08x\n", 519 - dwc2_readl(hsotg->regs + HPTXFSIZ)); 519 + dwc2_readl(hsotg, HPTXFSIZ)); 520 520 hptxfsiz = params->host_perio_tx_fifo_size << 521 521 FIFOSIZE_DEPTH_SHIFT & FIFOSIZE_DEPTH_MASK; 522 522 hptxfsiz |= (params->host_rx_fifo_size + 523 523 params->host_nperio_tx_fifo_size) << 524 524 FIFOSIZE_STARTADDR_SHIFT & FIFOSIZE_STARTADDR_MASK; 525 - dwc2_writel(hptxfsiz, hsotg->regs + HPTXFSIZ); 525 + dwc2_writel(hsotg, hptxfsiz, HPTXFSIZ); 526 526 dev_dbg(hsotg->dev, "new hptxfsiz=%08x\n", 527 - dwc2_readl(hsotg->regs + HPTXFSIZ)); 527 + dwc2_readl(hsotg, HPTXFSIZ)); 528 528 529 529 if (hsotg->params.en_multiple_tx_fifo && 530 530 hsotg->hw_params.snpsid >= DWC2_CORE_REV_2_91a) { ··· 533 533 * Global DFIFOCFG calculation for Host mode - 534 534 * include RxFIFO, NPTXFIFO and HPTXFIFO 535 535 */ 536 - dfifocfg = dwc2_readl(hsotg->regs + GDFIFOCFG); 536 + dfifocfg = dwc2_readl(hsotg, GDFIFOCFG); 537 537 dfifocfg &= ~GDFIFOCFG_EPINFOBASE_MASK; 538 538 dfifocfg |= (params->host_rx_fifo_size + 539 539 params->host_nperio_tx_fifo_size + 540 540 params->host_perio_tx_fifo_size) << 541 541 GDFIFOCFG_EPINFOBASE_SHIFT & 542 542 GDFIFOCFG_EPINFOBASE_MASK; 543 - dwc2_writel(dfifocfg, hsotg->regs + GDFIFOCFG); 543 + dwc2_writel(hsotg, dfifocfg, GDFIFOCFG); 544 544 } 545 545 } 546 546 ··· 560 560 u32 hprt0; 561 561 int clock = 60; /* default value */ 562 562 563 - usbcfg = dwc2_readl(hsotg->regs + GUSBCFG); 564 - hprt0 = dwc2_readl(hsotg->regs + HPRT0); 563 + usbcfg = dwc2_readl(hsotg, GUSBCFG); 564 + hprt0 = dwc2_readl(hsotg, HPRT0); 565 565 566 566 if (!(usbcfg & GUSBCFG_PHYSEL) && (usbcfg & GUSBCFG_ULPI_UTMI_SEL) && 567 567 !(usbcfg & GUSBCFG_PHYIF16)) ··· 603 603 */ 604 604 void dwc2_read_packet(struct dwc2_hsotg *hsotg, u8 *dest, u16 bytes) 605 605 { 606 - u32 __iomem *fifo = hsotg->regs + HCFIFO(0); 607 606 u32 *data_buf = (u32 *)dest; 608 607 int word_count = (bytes + 3) / 4; 609 608 int i; ··· 616 617 dev_vdbg(hsotg->dev, "%s(%p,%p,%d)\n", __func__, hsotg, dest, bytes); 617 618 618 619 for (i = 0; i < word_count; i++, data_buf++) 619 - *data_buf = dwc2_readl(fifo); 620 + *data_buf = dwc2_readl(hsotg, HCFIFO(0)); 620 621 } 621 622 622 623 /** ··· 645 646 if (!chan) 646 647 return; 647 648 648 - hcchar = dwc2_readl(hsotg->regs + HCCHAR(chan->hc_num)); 649 - hcsplt = dwc2_readl(hsotg->regs + HCSPLT(chan->hc_num)); 650 - hctsiz = dwc2_readl(hsotg->regs + HCTSIZ(chan->hc_num)); 651 - hc_dma = dwc2_readl(hsotg->regs + HCDMA(chan->hc_num)); 649 + hcchar = dwc2_readl(hsotg, HCCHAR(chan->hc_num)); 650 + hcsplt = dwc2_readl(hsotg, HCSPLT(chan->hc_num)); 651 + hctsiz = dwc2_readl(hsotg, HCTSIZ(chan->hc_num)); 652 + hc_dma = dwc2_readl(hsotg, HCDMA(chan->hc_num)); 652 653 653 654 dev_dbg(hsotg->dev, " Assigned to channel %p:\n", chan); 654 655 dev_dbg(hsotg->dev, " hcchar 0x%08x, hcsplt 0x%08x\n", ··· 796 797 break; 797 798 } 798 799 799 - dwc2_writel(hcintmsk, hsotg->regs + HCINTMSK(chan->hc_num)); 800 + dwc2_writel(hsotg, hcintmsk, HCINTMSK(chan->hc_num)); 800 801 if (dbg_hc(chan)) 801 802 dev_vdbg(hsotg->dev, "set HCINTMSK to %08x\n", hcintmsk); 802 803 } ··· 833 834 } 834 835 } 835 836 836 - dwc2_writel(hcintmsk, hsotg->regs + HCINTMSK(chan->hc_num)); 837 + dwc2_writel(hsotg, hcintmsk, HCINTMSK(chan->hc_num)); 837 838 if (dbg_hc(chan)) 838 839 dev_vdbg(hsotg->dev, "set HCINTMSK to %08x\n", hcintmsk); 839 840 } ··· 854 855 } 855 856 856 857 /* Enable the top level host channel interrupt */ 857 - intmsk = dwc2_readl(hsotg->regs + HAINTMSK); 858 + intmsk = dwc2_readl(hsotg, HAINTMSK); 858 859 intmsk |= 1 << chan->hc_num; 859 - dwc2_writel(intmsk, hsotg->regs + HAINTMSK); 860 + dwc2_writel(hsotg, intmsk, HAINTMSK); 860 861 if (dbg_hc(chan)) 861 862 dev_vdbg(hsotg->dev, "set HAINTMSK to %08x\n", intmsk); 862 863 863 864 /* Make sure host channel interrupts are enabled */ 864 - intmsk = dwc2_readl(hsotg->regs + GINTMSK); 865 + intmsk = dwc2_readl(hsotg, GINTMSK); 865 866 intmsk |= GINTSTS_HCHINT; 866 - dwc2_writel(intmsk, hsotg->regs + GINTMSK); 867 + dwc2_writel(hsotg, intmsk, GINTMSK); 867 868 if (dbg_hc(chan)) 868 869 dev_vdbg(hsotg->dev, "set GINTMSK to %08x\n", intmsk); 869 870 } ··· 892 893 /* Clear old interrupt conditions for this host channel */ 893 894 hcintmsk = 0xffffffff; 894 895 hcintmsk &= ~HCINTMSK_RESERVED14_31; 895 - dwc2_writel(hcintmsk, hsotg->regs + HCINT(hc_num)); 896 + dwc2_writel(hsotg, hcintmsk, HCINT(hc_num)); 896 897 897 898 /* Enable channel interrupts required for this transfer */ 898 899 dwc2_hc_enable_ints(hsotg, chan); ··· 909 910 hcchar |= HCCHAR_LSPDDEV; 910 911 hcchar |= chan->ep_type << HCCHAR_EPTYPE_SHIFT & HCCHAR_EPTYPE_MASK; 911 912 hcchar |= chan->max_packet << HCCHAR_MPS_SHIFT & HCCHAR_MPS_MASK; 912 - dwc2_writel(hcchar, hsotg->regs + HCCHAR(hc_num)); 913 + dwc2_writel(hsotg, hcchar, HCCHAR(hc_num)); 913 914 if (dbg_hc(chan)) { 914 915 dev_vdbg(hsotg->dev, "set HCCHAR(%d) to %08x\n", 915 916 hc_num, hcchar); ··· 963 964 } 964 965 } 965 966 966 - dwc2_writel(hcsplt, hsotg->regs + HCSPLT(hc_num)); 967 + dwc2_writel(hsotg, hcsplt, HCSPLT(hc_num)); 967 968 } 968 969 969 970 /** ··· 1033 1034 u32 hcintmsk = HCINTMSK_CHHLTD; 1034 1035 1035 1036 dev_vdbg(hsotg->dev, "dequeue/error\n"); 1036 - dwc2_writel(hcintmsk, hsotg->regs + HCINTMSK(chan->hc_num)); 1037 + dwc2_writel(hsotg, hcintmsk, HCINTMSK(chan->hc_num)); 1037 1038 1038 1039 /* 1039 1040 * Make sure no other interrupts besides halt are currently 1040 1041 * pending. Handling another interrupt could cause a crash due 1041 1042 * to the QTD and QH state. 1042 1043 */ 1043 - dwc2_writel(~hcintmsk, hsotg->regs + HCINT(chan->hc_num)); 1044 + dwc2_writel(hsotg, ~hcintmsk, HCINT(chan->hc_num)); 1044 1045 1045 1046 /* 1046 1047 * Make sure the halt status is set to URB_DEQUEUE or AHB_ERR ··· 1049 1050 */ 1050 1051 chan->halt_status = halt_status; 1051 1052 1052 - hcchar = dwc2_readl(hsotg->regs + HCCHAR(chan->hc_num)); 1053 + hcchar = dwc2_readl(hsotg, HCCHAR(chan->hc_num)); 1053 1054 if (!(hcchar & HCCHAR_CHENA)) { 1054 1055 /* 1055 1056 * The channel is either already halted or it hasn't ··· 1077 1078 return; 1078 1079 } 1079 1080 1080 - hcchar = dwc2_readl(hsotg->regs + HCCHAR(chan->hc_num)); 1081 + hcchar = dwc2_readl(hsotg, HCCHAR(chan->hc_num)); 1081 1082 1082 1083 /* No need to set the bit in DDMA for disabling the channel */ 1083 1084 /* TODO check it everywhere channel is disabled */ ··· 1100 1101 if (chan->ep_type == USB_ENDPOINT_XFER_CONTROL || 1101 1102 chan->ep_type == USB_ENDPOINT_XFER_BULK) { 1102 1103 dev_vdbg(hsotg->dev, "control/bulk\n"); 1103 - nptxsts = dwc2_readl(hsotg->regs + GNPTXSTS); 1104 + nptxsts = dwc2_readl(hsotg, GNPTXSTS); 1104 1105 if ((nptxsts & TXSTS_QSPCAVAIL_MASK) == 0) { 1105 1106 dev_vdbg(hsotg->dev, "Disabling channel\n"); 1106 1107 hcchar &= ~HCCHAR_CHENA; ··· 1108 1109 } else { 1109 1110 if (dbg_perio()) 1110 1111 dev_vdbg(hsotg->dev, "isoc/intr\n"); 1111 - hptxsts = dwc2_readl(hsotg->regs + HPTXSTS); 1112 + hptxsts = dwc2_readl(hsotg, HPTXSTS); 1112 1113 if ((hptxsts & TXSTS_QSPCAVAIL_MASK) == 0 || 1113 1114 hsotg->queuing_high_bandwidth) { 1114 1115 if (dbg_perio()) ··· 1121 1122 dev_vdbg(hsotg->dev, "DMA enabled\n"); 1122 1123 } 1123 1124 1124 - dwc2_writel(hcchar, hsotg->regs + HCCHAR(chan->hc_num)); 1125 + dwc2_writel(hsotg, hcchar, HCCHAR(chan->hc_num)); 1125 1126 chan->halt_status = halt_status; 1126 1127 1127 1128 if (hcchar & HCCHAR_CHENA) { ··· 1170 1171 * Clear channel interrupt enables and any unhandled channel interrupt 1171 1172 * conditions 1172 1173 */ 1173 - dwc2_writel(0, hsotg->regs + HCINTMSK(chan->hc_num)); 1174 + dwc2_writel(hsotg, 0, HCINTMSK(chan->hc_num)); 1174 1175 hcintmsk = 0xffffffff; 1175 1176 hcintmsk &= ~HCINTMSK_RESERVED14_31; 1176 - dwc2_writel(hcintmsk, hsotg->regs + HCINT(chan->hc_num)); 1177 + dwc2_writel(hsotg, hcintmsk, HCINT(chan->hc_num)); 1177 1178 } 1178 1179 1179 1180 /** ··· 1227 1228 !chan->do_split) ? chan->speed : USB_SPEED_HIGH; 1228 1229 1229 1230 /* See how many bytes are in the periodic FIFO right now */ 1230 - fifo_space = (dwc2_readl(hsotg->regs + HPTXSTS) & 1231 + fifo_space = (dwc2_readl(hsotg, HPTXSTS) & 1231 1232 TXSTS_FSPCAVAIL_MASK) >> TXSTS_FSPCAVAIL_SHIFT; 1232 1233 bytes_in_fifo = sizeof(u32) * 1233 1234 (hsotg->params.host_perio_tx_fifo_size - ··· 1347 1348 if (((unsigned long)data_buf & 0x3) == 0) { 1348 1349 /* xfer_buf is DWORD aligned */ 1349 1350 for (i = 0; i < dword_count; i++, data_buf++) 1350 - dwc2_writel(*data_buf, data_fifo); 1351 + dwc2_writel(hsotg, *data_buf, HCFIFO(chan->hc_num)); 1351 1352 } else { 1352 1353 /* xfer_buf is not DWORD aligned */ 1353 1354 for (i = 0; i < dword_count; i++, data_buf++) { 1354 1355 u32 data = data_buf[0] | data_buf[1] << 8 | 1355 1356 data_buf[2] << 16 | data_buf[3] << 24; 1356 - dwc2_writel(data, data_fifo); 1357 + dwc2_writel(hsotg, data, HCFIFO(chan->hc_num)); 1357 1358 } 1358 1359 } 1359 1360 ··· 1382 1383 1383 1384 hctsiz = TSIZ_DOPNG; 1384 1385 hctsiz |= 1 << TSIZ_PKTCNT_SHIFT; 1385 - dwc2_writel(hctsiz, hsotg->regs + HCTSIZ(chan->hc_num)); 1386 + dwc2_writel(hsotg, hctsiz, HCTSIZ(chan->hc_num)); 1386 1387 1387 - hcchar = dwc2_readl(hsotg->regs + HCCHAR(chan->hc_num)); 1388 + hcchar = dwc2_readl(hsotg, HCCHAR(chan->hc_num)); 1388 1389 hcchar |= HCCHAR_CHENA; 1389 1390 hcchar &= ~HCCHAR_CHDIS; 1390 - dwc2_writel(hcchar, hsotg->regs + HCCHAR(chan->hc_num)); 1391 + dwc2_writel(hsotg, hcchar, HCCHAR(chan->hc_num)); 1391 1392 } 1392 1393 1393 1394 /** ··· 1547 1548 hctsiz |= num_packets << TSIZ_PKTCNT_SHIFT & TSIZ_PKTCNT_MASK; 1548 1549 hctsiz |= chan->data_pid_start << TSIZ_SC_MC_PID_SHIFT & 1549 1550 TSIZ_SC_MC_PID_MASK; 1550 - dwc2_writel(hctsiz, hsotg->regs + HCTSIZ(chan->hc_num)); 1551 + dwc2_writel(hsotg, hctsiz, HCTSIZ(chan->hc_num)); 1551 1552 if (dbg_hc(chan)) { 1552 1553 dev_vdbg(hsotg->dev, "Wrote %08x to HCTSIZ(%d)\n", 1553 1554 hctsiz, chan->hc_num); ··· 1575 1576 } else { 1576 1577 dma_addr = chan->xfer_dma; 1577 1578 } 1578 - dwc2_writel((u32)dma_addr, hsotg->regs + HCDMA(chan->hc_num)); 1579 + dwc2_writel(hsotg, (u32)dma_addr, HCDMA(chan->hc_num)); 1579 1580 1580 1581 if (dbg_hc(chan)) 1581 1582 dev_vdbg(hsotg->dev, "Wrote %08lx to HCDMA(%d)\n", ··· 1584 1585 1585 1586 /* Start the split */ 1586 1587 if (chan->do_split) { 1587 - u32 hcsplt = dwc2_readl(hsotg->regs + HCSPLT(chan->hc_num)); 1588 + u32 hcsplt = dwc2_readl(hsotg, HCSPLT(chan->hc_num)); 1588 1589 1589 1590 hcsplt |= HCSPLT_SPLTENA; 1590 - dwc2_writel(hcsplt, hsotg->regs + HCSPLT(chan->hc_num)); 1591 + dwc2_writel(hsotg, hcsplt, HCSPLT(chan->hc_num)); 1591 1592 } 1592 1593 1593 - hcchar = dwc2_readl(hsotg->regs + HCCHAR(chan->hc_num)); 1594 + hcchar = dwc2_readl(hsotg, HCCHAR(chan->hc_num)); 1594 1595 hcchar &= ~HCCHAR_MULTICNT_MASK; 1595 1596 hcchar |= (ec_mc << HCCHAR_MULTICNT_SHIFT) & HCCHAR_MULTICNT_MASK; 1596 1597 dwc2_hc_set_even_odd_frame(hsotg, chan, &hcchar); ··· 1609 1610 (hcchar & HCCHAR_MULTICNT_MASK) >> 1610 1611 HCCHAR_MULTICNT_SHIFT); 1611 1612 1612 - dwc2_writel(hcchar, hsotg->regs + HCCHAR(chan->hc_num)); 1613 + dwc2_writel(hsotg, hcchar, HCCHAR(chan->hc_num)); 1613 1614 if (dbg_hc(chan)) 1614 1615 dev_vdbg(hsotg->dev, "Wrote %08x to HCCHAR(%d)\n", hcchar, 1615 1616 chan->hc_num); ··· 1667 1668 dev_vdbg(hsotg->dev, " NTD: %d\n", chan->ntd - 1); 1668 1669 } 1669 1670 1670 - dwc2_writel(hctsiz, hsotg->regs + HCTSIZ(chan->hc_num)); 1671 + dwc2_writel(hsotg, hctsiz, HCTSIZ(chan->hc_num)); 1671 1672 1672 1673 dma_sync_single_for_device(hsotg->dev, chan->desc_list_addr, 1673 1674 chan->desc_list_sz, DMA_TO_DEVICE); 1674 1675 1675 - dwc2_writel(chan->desc_list_addr, hsotg->regs + HCDMA(chan->hc_num)); 1676 + dwc2_writel(hsotg, chan->desc_list_addr, HCDMA(chan->hc_num)); 1676 1677 1677 1678 if (dbg_hc(chan)) 1678 1679 dev_vdbg(hsotg->dev, "Wrote %pad to HCDMA(%d)\n", 1679 1680 &chan->desc_list_addr, chan->hc_num); 1680 1681 1681 - hcchar = dwc2_readl(hsotg->regs + HCCHAR(chan->hc_num)); 1682 + hcchar = dwc2_readl(hsotg, HCCHAR(chan->hc_num)); 1682 1683 hcchar &= ~HCCHAR_MULTICNT_MASK; 1683 1684 hcchar |= chan->multi_count << HCCHAR_MULTICNT_SHIFT & 1684 1685 HCCHAR_MULTICNT_MASK; ··· 1697 1698 (hcchar & HCCHAR_MULTICNT_MASK) >> 1698 1699 HCCHAR_MULTICNT_SHIFT); 1699 1700 1700 - dwc2_writel(hcchar, hsotg->regs + HCCHAR(chan->hc_num)); 1701 + dwc2_writel(hsotg, hcchar, HCCHAR(chan->hc_num)); 1701 1702 if (dbg_hc(chan)) 1702 1703 dev_vdbg(hsotg->dev, "Wrote %08x to HCCHAR(%d)\n", hcchar, 1703 1704 chan->hc_num); ··· 1754 1755 * transfer completes, the extra requests for the channel will 1755 1756 * be flushed. 1756 1757 */ 1757 - u32 hcchar = dwc2_readl(hsotg->regs + HCCHAR(chan->hc_num)); 1758 + u32 hcchar = dwc2_readl(hsotg, HCCHAR(chan->hc_num)); 1758 1759 1759 1760 dwc2_hc_set_even_odd_frame(hsotg, chan, &hcchar); 1760 1761 hcchar |= HCCHAR_CHENA; ··· 1762 1763 if (dbg_hc(chan)) 1763 1764 dev_vdbg(hsotg->dev, " IN xfer: hcchar = 0x%08x\n", 1764 1765 hcchar); 1765 - dwc2_writel(hcchar, hsotg->regs + HCCHAR(chan->hc_num)); 1766 + dwc2_writel(hsotg, hcchar, HCCHAR(chan->hc_num)); 1766 1767 chan->requests++; 1767 1768 return 1; 1768 1769 } ··· 1772 1773 if (chan->xfer_count < chan->xfer_len) { 1773 1774 if (chan->ep_type == USB_ENDPOINT_XFER_INT || 1774 1775 chan->ep_type == USB_ENDPOINT_XFER_ISOC) { 1775 - u32 hcchar = dwc2_readl(hsotg->regs + 1776 + u32 hcchar = dwc2_readl(hsotg, 1776 1777 HCCHAR(chan->hc_num)); 1777 1778 1778 1779 dwc2_hc_set_even_odd_frame(hsotg, chan, ··· 1886 1887 */ 1887 1888 hprt0 = dwc2_read_hprt0(hsotg); 1888 1889 hprt0 |= HPRT0_RST; 1889 - dwc2_writel(hprt0, hsotg->regs + HPRT0); 1890 + dwc2_writel(hsotg, hprt0, HPRT0); 1890 1891 } 1891 1892 1892 1893 queue_delayed_work(hsotg->wq_otg, &hsotg->start_work, ··· 1907 1908 channel = hsotg->hc_ptr_array[i]; 1908 1909 if (!list_empty(&channel->hc_list_entry)) 1909 1910 continue; 1910 - hcchar = dwc2_readl(hsotg->regs + HCCHAR(i)); 1911 + hcchar = dwc2_readl(hsotg, HCCHAR(i)); 1911 1912 if (hcchar & HCCHAR_CHENA) { 1912 1913 hcchar &= ~(HCCHAR_CHENA | HCCHAR_EPDIR); 1913 1914 hcchar |= HCCHAR_CHDIS; 1914 - dwc2_writel(hcchar, hsotg->regs + HCCHAR(i)); 1915 + dwc2_writel(hsotg, hcchar, HCCHAR(i)); 1915 1916 } 1916 1917 } 1917 1918 } ··· 1920 1921 channel = hsotg->hc_ptr_array[i]; 1921 1922 if (!list_empty(&channel->hc_list_entry)) 1922 1923 continue; 1923 - hcchar = dwc2_readl(hsotg->regs + HCCHAR(i)); 1924 + hcchar = dwc2_readl(hsotg, HCCHAR(i)); 1924 1925 if (hcchar & HCCHAR_CHENA) { 1925 1926 /* Halt the channel */ 1926 1927 hcchar |= HCCHAR_CHDIS; 1927 - dwc2_writel(hcchar, hsotg->regs + HCCHAR(i)); 1928 + dwc2_writel(hsotg, hcchar, HCCHAR(i)); 1928 1929 } 1929 1930 1930 1931 dwc2_hc_cleanup(hsotg, channel); ··· 1984 1985 * interrupt mask and status bits and disabling subsequent host 1985 1986 * channel interrupts. 1986 1987 */ 1987 - intr = dwc2_readl(hsotg->regs + GINTMSK); 1988 + intr = dwc2_readl(hsotg, GINTMSK); 1988 1989 intr &= ~(GINTSTS_NPTXFEMP | GINTSTS_PTXFEMP | GINTSTS_HCHINT); 1989 - dwc2_writel(intr, hsotg->regs + GINTMSK); 1990 + dwc2_writel(hsotg, intr, GINTMSK); 1990 1991 intr = GINTSTS_NPTXFEMP | GINTSTS_PTXFEMP | GINTSTS_HCHINT; 1991 - dwc2_writel(intr, hsotg->regs + GINTSTS); 1992 + dwc2_writel(hsotg, intr, GINTSTS); 1992 1993 1993 1994 /* 1994 1995 * Turn off the vbus power only if the core has transitioned to device ··· 1998 1999 if (dwc2_is_device_mode(hsotg)) { 1999 2000 if (hsotg->op_state != OTG_STATE_A_SUSPEND) { 2000 2001 dev_dbg(hsotg->dev, "Disconnect: PortPower off\n"); 2001 - dwc2_writel(0, hsotg->regs + HPRT0); 2002 + dwc2_writel(hsotg, 0, HPRT0); 2002 2003 } 2003 2004 2004 2005 dwc2_disable_host_interrupts(hsotg); ··· 2026 2027 * and won't get any future interrupts to handle the connect. 2027 2028 */ 2028 2029 if (!force) { 2029 - hprt0 = dwc2_readl(hsotg->regs + HPRT0); 2030 + hprt0 = dwc2_readl(hsotg, HPRT0); 2030 2031 if (!(hprt0 & HPRT0_CONNDET) && (hprt0 & HPRT0_CONNSTS)) 2031 2032 dwc2_hcd_connect(hsotg); 2032 2033 } ··· 2070 2071 2071 2072 /* Turn off the vbus power */ 2072 2073 dev_dbg(hsotg->dev, "PortPower off\n"); 2073 - dwc2_writel(0, hsotg->regs + HPRT0); 2074 + dwc2_writel(hsotg, 0, HPRT0); 2074 2075 } 2075 2076 2076 2077 /* Caller must hold driver lock */ ··· 2094 2095 if ((dev_speed == USB_SPEED_LOW) && 2095 2096 (hsotg->hw_params.fs_phy_type == GHWCFG2_FS_PHY_TYPE_DEDICATED) && 2096 2097 (hsotg->hw_params.hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI)) { 2097 - u32 hprt0 = dwc2_readl(hsotg->regs + HPRT0); 2098 + u32 hprt0 = dwc2_readl(hsotg, HPRT0); 2098 2099 u32 prtspd = (hprt0 & HPRT0_SPD_MASK) >> HPRT0_SPD_SHIFT; 2099 2100 2100 2101 if (prtspd == HPRT0_SPD_FULL_SPEED) ··· 2113 2114 return retval; 2114 2115 } 2115 2116 2116 - intr_mask = dwc2_readl(hsotg->regs + GINTMSK); 2117 + intr_mask = dwc2_readl(hsotg, GINTMSK); 2117 2118 if (!(intr_mask & GINTSTS_SOF)) { 2118 2119 enum dwc2_transaction_type tr_type; 2119 2120 ··· 2278 2279 2279 2280 dev_dbg(hsotg->dev, "%s(%p)\n", __func__, hsotg); 2280 2281 2281 - usbcfg = dwc2_readl(hsotg->regs + GUSBCFG); 2282 + usbcfg = dwc2_readl(hsotg, GUSBCFG); 2282 2283 2283 2284 /* Set ULPI External VBUS bit if needed */ 2284 2285 usbcfg &= ~GUSBCFG_ULPI_EXT_VBUS_DRV; ··· 2290 2291 if (hsotg->params.ts_dline) 2291 2292 usbcfg |= GUSBCFG_TERMSELDLPULSE; 2292 2293 2293 - dwc2_writel(usbcfg, hsotg->regs + GUSBCFG); 2294 + dwc2_writel(hsotg, usbcfg, GUSBCFG); 2294 2295 2295 2296 /* 2296 2297 * Reset the Controller ··· 2324 2325 dwc2_gusbcfg_init(hsotg); 2325 2326 2326 2327 /* Program the GOTGCTL register */ 2327 - otgctl = dwc2_readl(hsotg->regs + GOTGCTL); 2328 + otgctl = dwc2_readl(hsotg, GOTGCTL); 2328 2329 otgctl &= ~GOTGCTL_OTGVER; 2329 - dwc2_writel(otgctl, hsotg->regs + GOTGCTL); 2330 + dwc2_writel(hsotg, otgctl, GOTGCTL); 2330 2331 2331 2332 /* Clear the SRP success bit for FS-I2c */ 2332 2333 hsotg->srp_success = 0; ··· 2373 2374 * introduced by the PHY in generating the linestate condition 2374 2375 * can vary from one PHY to another. 2375 2376 */ 2376 - usbcfg = dwc2_readl(hsotg->regs + GUSBCFG); 2377 + usbcfg = dwc2_readl(hsotg, GUSBCFG); 2377 2378 usbcfg |= GUSBCFG_TOUTCAL(7); 2378 - dwc2_writel(usbcfg, hsotg->regs + GUSBCFG); 2379 + dwc2_writel(hsotg, usbcfg, GUSBCFG); 2379 2380 2380 2381 /* Restart the Phy Clock */ 2381 - dwc2_writel(0, hsotg->regs + PCGCTL); 2382 + dwc2_writel(hsotg, 0, PCGCTL); 2382 2383 2383 2384 /* Initialize Host Configuration Register */ 2384 2385 dwc2_init_fs_ls_pclk_sel(hsotg); 2385 2386 if (hsotg->params.speed == DWC2_SPEED_PARAM_FULL || 2386 2387 hsotg->params.speed == DWC2_SPEED_PARAM_LOW) { 2387 - hcfg = dwc2_readl(hsotg->regs + HCFG); 2388 + hcfg = dwc2_readl(hsotg, HCFG); 2388 2389 hcfg |= HCFG_FSLSSUPP; 2389 - dwc2_writel(hcfg, hsotg->regs + HCFG); 2390 + dwc2_writel(hsotg, hcfg, HCFG); 2390 2391 } 2391 2392 2392 2393 /* ··· 2395 2396 * and its value must not be changed during runtime. 2396 2397 */ 2397 2398 if (hsotg->params.reload_ctl) { 2398 - hfir = dwc2_readl(hsotg->regs + HFIR); 2399 + hfir = dwc2_readl(hsotg, HFIR); 2399 2400 hfir |= HFIR_RLDCTRL; 2400 - dwc2_writel(hfir, hsotg->regs + HFIR); 2401 + dwc2_writel(hsotg, hfir, HFIR); 2401 2402 } 2402 2403 2403 2404 if (hsotg->params.dma_desc_enable) { ··· 2414 2415 "falling back to buffer DMA mode.\n"); 2415 2416 hsotg->params.dma_desc_enable = false; 2416 2417 } else { 2417 - hcfg = dwc2_readl(hsotg->regs + HCFG); 2418 + hcfg = dwc2_readl(hsotg, HCFG); 2418 2419 hcfg |= HCFG_DESCDMA; 2419 - dwc2_writel(hcfg, hsotg->regs + HCFG); 2420 + dwc2_writel(hsotg, hcfg, HCFG); 2420 2421 } 2421 2422 } 2422 2423 ··· 2425 2426 2426 2427 /* TODO - check this */ 2427 2428 /* Clear Host Set HNP Enable in the OTG Control Register */ 2428 - otgctl = dwc2_readl(hsotg->regs + GOTGCTL); 2429 + otgctl = dwc2_readl(hsotg, GOTGCTL); 2429 2430 otgctl &= ~GOTGCTL_HSTSETHNPEN; 2430 - dwc2_writel(otgctl, hsotg->regs + GOTGCTL); 2431 + dwc2_writel(hsotg, otgctl, GOTGCTL); 2431 2432 2432 2433 /* Make sure the FIFOs are flushed */ 2433 2434 dwc2_flush_tx_fifo(hsotg, 0x10 /* all TX FIFOs */); 2434 2435 dwc2_flush_rx_fifo(hsotg); 2435 2436 2436 2437 /* Clear Host Set HNP Enable in the OTG Control Register */ 2437 - otgctl = dwc2_readl(hsotg->regs + GOTGCTL); 2438 + otgctl = dwc2_readl(hsotg, GOTGCTL); 2438 2439 otgctl &= ~GOTGCTL_HSTSETHNPEN; 2439 - dwc2_writel(otgctl, hsotg->regs + GOTGCTL); 2440 + dwc2_writel(hsotg, otgctl, GOTGCTL); 2440 2441 2441 2442 if (!hsotg->params.dma_desc_enable) { 2442 2443 int num_channels, i; ··· 2445 2446 /* Flush out any leftover queued requests */ 2446 2447 num_channels = hsotg->params.host_channels; 2447 2448 for (i = 0; i < num_channels; i++) { 2448 - hcchar = dwc2_readl(hsotg->regs + HCCHAR(i)); 2449 + hcchar = dwc2_readl(hsotg, HCCHAR(i)); 2449 2450 hcchar &= ~HCCHAR_CHENA; 2450 2451 hcchar |= HCCHAR_CHDIS; 2451 2452 hcchar &= ~HCCHAR_EPDIR; 2452 - dwc2_writel(hcchar, hsotg->regs + HCCHAR(i)); 2453 + dwc2_writel(hsotg, hcchar, HCCHAR(i)); 2453 2454 } 2454 2455 2455 2456 /* Halt all channels to put them into a known state */ 2456 2457 for (i = 0; i < num_channels; i++) { 2457 - hcchar = dwc2_readl(hsotg->regs + HCCHAR(i)); 2458 + hcchar = dwc2_readl(hsotg, HCCHAR(i)); 2458 2459 hcchar |= HCCHAR_CHENA | HCCHAR_CHDIS; 2459 2460 hcchar &= ~HCCHAR_EPDIR; 2460 - dwc2_writel(hcchar, hsotg->regs + HCCHAR(i)); 2461 + dwc2_writel(hsotg, hcchar, HCCHAR(i)); 2461 2462 dev_dbg(hsotg->dev, "%s: Halt channel %d\n", 2462 2463 __func__, i); 2463 2464 ··· 2481 2482 !!(hprt0 & HPRT0_PWR)); 2482 2483 if (!(hprt0 & HPRT0_PWR)) { 2483 2484 hprt0 |= HPRT0_PWR; 2484 - dwc2_writel(hprt0, hsotg->regs + HPRT0); 2485 + dwc2_writel(hsotg, hprt0, HPRT0); 2485 2486 } 2486 2487 } 2487 2488 ··· 3083 3084 if (dbg_perio()) 3084 3085 dev_vdbg(hsotg->dev, "Queue periodic transactions\n"); 3085 3086 3086 - tx_status = dwc2_readl(hsotg->regs + HPTXSTS); 3087 + tx_status = dwc2_readl(hsotg, HPTXSTS); 3087 3088 qspcavail = (tx_status & TXSTS_QSPCAVAIL_MASK) >> 3088 3089 TXSTS_QSPCAVAIL_SHIFT; 3089 3090 fspcavail = (tx_status & TXSTS_FSPCAVAIL_MASK) >> ··· 3098 3099 3099 3100 qh_ptr = hsotg->periodic_sched_assigned.next; 3100 3101 while (qh_ptr != &hsotg->periodic_sched_assigned) { 3101 - tx_status = dwc2_readl(hsotg->regs + HPTXSTS); 3102 + tx_status = dwc2_readl(hsotg, HPTXSTS); 3102 3103 qspcavail = (tx_status & TXSTS_QSPCAVAIL_MASK) >> 3103 3104 TXSTS_QSPCAVAIL_SHIFT; 3104 3105 if (qspcavail == 0) { ··· 3168 3169 * level to ensure that new requests are loaded as 3169 3170 * soon as possible.) 3170 3171 */ 3171 - gintmsk = dwc2_readl(hsotg->regs + GINTMSK); 3172 + gintmsk = dwc2_readl(hsotg, GINTMSK); 3172 3173 if (!(gintmsk & GINTSTS_PTXFEMP)) { 3173 3174 gintmsk |= GINTSTS_PTXFEMP; 3174 - dwc2_writel(gintmsk, hsotg->regs + GINTMSK); 3175 + dwc2_writel(hsotg, gintmsk, GINTMSK); 3175 3176 } 3176 3177 } else { 3177 3178 /* ··· 3181 3182 * handlers to queue more transactions as transfer 3182 3183 * states change. 3183 3184 */ 3184 - gintmsk = dwc2_readl(hsotg->regs + GINTMSK); 3185 + gintmsk = dwc2_readl(hsotg, GINTMSK); 3185 3186 if (gintmsk & GINTSTS_PTXFEMP) { 3186 3187 gintmsk &= ~GINTSTS_PTXFEMP; 3187 - dwc2_writel(gintmsk, hsotg->regs + GINTMSK); 3188 + dwc2_writel(hsotg, gintmsk, GINTMSK); 3188 3189 } 3189 3190 } 3190 3191 } ··· 3213 3214 3214 3215 dev_vdbg(hsotg->dev, "Queue non-periodic transactions\n"); 3215 3216 3216 - tx_status = dwc2_readl(hsotg->regs + GNPTXSTS); 3217 + tx_status = dwc2_readl(hsotg, GNPTXSTS); 3217 3218 qspcavail = (tx_status & TXSTS_QSPCAVAIL_MASK) >> 3218 3219 TXSTS_QSPCAVAIL_SHIFT; 3219 3220 fspcavail = (tx_status & TXSTS_FSPCAVAIL_MASK) >> ··· 3236 3237 * available in the request queue or the Tx FIFO 3237 3238 */ 3238 3239 do { 3239 - tx_status = dwc2_readl(hsotg->regs + GNPTXSTS); 3240 + tx_status = dwc2_readl(hsotg, GNPTXSTS); 3240 3241 qspcavail = (tx_status & TXSTS_QSPCAVAIL_MASK) >> 3241 3242 TXSTS_QSPCAVAIL_SHIFT; 3242 3243 if (!hsotg->params.host_dma && qspcavail == 0) { ··· 3273 3274 } while (hsotg->non_periodic_qh_ptr != orig_qh_ptr); 3274 3275 3275 3276 if (!hsotg->params.host_dma) { 3276 - tx_status = dwc2_readl(hsotg->regs + GNPTXSTS); 3277 + tx_status = dwc2_readl(hsotg, GNPTXSTS); 3277 3278 qspcavail = (tx_status & TXSTS_QSPCAVAIL_MASK) >> 3278 3279 TXSTS_QSPCAVAIL_SHIFT; 3279 3280 fspcavail = (tx_status & TXSTS_FSPCAVAIL_MASK) >> ··· 3293 3294 * level to ensure that new requests are loaded as 3294 3295 * soon as possible.) 3295 3296 */ 3296 - gintmsk = dwc2_readl(hsotg->regs + GINTMSK); 3297 + gintmsk = dwc2_readl(hsotg, GINTMSK); 3297 3298 gintmsk |= GINTSTS_NPTXFEMP; 3298 - dwc2_writel(gintmsk, hsotg->regs + GINTMSK); 3299 + dwc2_writel(hsotg, gintmsk, GINTMSK); 3299 3300 } else { 3300 3301 /* 3301 3302 * Disable the Tx FIFO empty interrupt since there are ··· 3304 3305 * handlers to queue more transactions as transfer 3305 3306 * states change. 3306 3307 */ 3307 - gintmsk = dwc2_readl(hsotg->regs + GINTMSK); 3308 + gintmsk = dwc2_readl(hsotg, GINTMSK); 3308 3309 gintmsk &= ~GINTSTS_NPTXFEMP; 3309 - dwc2_writel(gintmsk, hsotg->regs + GINTMSK); 3310 + dwc2_writel(hsotg, gintmsk, GINTMSK); 3310 3311 } 3311 3312 } 3312 3313 } ··· 3343 3344 * Ensure NP Tx FIFO empty interrupt is disabled when 3344 3345 * there are no non-periodic transfers to process 3345 3346 */ 3346 - u32 gintmsk = dwc2_readl(hsotg->regs + GINTMSK); 3347 + u32 gintmsk = dwc2_readl(hsotg, GINTMSK); 3347 3348 3348 3349 gintmsk &= ~GINTSTS_NPTXFEMP; 3349 - dwc2_writel(gintmsk, hsotg->regs + GINTMSK); 3350 + dwc2_writel(hsotg, gintmsk, GINTMSK); 3350 3351 } 3351 3352 } 3352 3353 } ··· 3361 3362 3362 3363 dev_dbg(hsotg->dev, "%s()\n", __func__); 3363 3364 3364 - gotgctl = dwc2_readl(hsotg->regs + GOTGCTL); 3365 + gotgctl = dwc2_readl(hsotg, GOTGCTL); 3365 3366 dev_dbg(hsotg->dev, "gotgctl=%0x\n", gotgctl); 3366 3367 dev_dbg(hsotg->dev, "gotgctl.b.conidsts=%d\n", 3367 3368 !!(gotgctl & GOTGCTL_CONID_B)); ··· 3387 3388 * check it again and jump to host mode if that was 3388 3389 * the case. 3389 3390 */ 3390 - gotgctl = dwc2_readl(hsotg->regs + GOTGCTL); 3391 + gotgctl = dwc2_readl(hsotg, GOTGCTL); 3391 3392 if (!(gotgctl & GOTGCTL_CONID_B)) 3392 3393 goto host; 3393 3394 if (++count > 250) ··· 3447 3448 hprt0 = dwc2_read_hprt0(hsotg); 3448 3449 dev_dbg(hsotg->dev, "Resume: HPRT0=%0x\n", hprt0); 3449 3450 hprt0 &= ~HPRT0_RES; 3450 - dwc2_writel(hprt0, hsotg->regs + HPRT0); 3451 + dwc2_writel(hsotg, hprt0, HPRT0); 3451 3452 dev_dbg(hsotg->dev, "Clear Resume: HPRT0=%0x\n", 3452 - dwc2_readl(hsotg->regs + HPRT0)); 3453 + dwc2_readl(hsotg, HPRT0)); 3453 3454 3454 3455 dwc2_hcd_rem_wakeup(hsotg); 3455 3456 hsotg->bus_suspended = false; ··· 3478 3479 spin_lock_irqsave(&hsotg->lock, flags); 3479 3480 3480 3481 if (windex == hsotg->otg_port && dwc2_host_is_b_hnp_enabled(hsotg)) { 3481 - gotgctl = dwc2_readl(hsotg->regs + GOTGCTL); 3482 + gotgctl = dwc2_readl(hsotg, GOTGCTL); 3482 3483 gotgctl |= GOTGCTL_HSTSETHNPEN; 3483 - dwc2_writel(gotgctl, hsotg->regs + GOTGCTL); 3484 + dwc2_writel(hsotg, gotgctl, GOTGCTL); 3484 3485 hsotg->op_state = OTG_STATE_A_SUSPEND; 3485 3486 } 3486 3487 3487 3488 hprt0 = dwc2_read_hprt0(hsotg); 3488 3489 hprt0 |= HPRT0_SUSP; 3489 - dwc2_writel(hprt0, hsotg->regs + HPRT0); 3490 + dwc2_writel(hsotg, hprt0, HPRT0); 3490 3491 3491 3492 hsotg->bus_suspended = true; 3492 3493 ··· 3496 3497 */ 3497 3498 if (!hsotg->params.power_down) { 3498 3499 /* Suspend the Phy Clock */ 3499 - pcgctl = dwc2_readl(hsotg->regs + PCGCTL); 3500 + pcgctl = dwc2_readl(hsotg, PCGCTL); 3500 3501 pcgctl |= PCGCTL_STOPPCLK; 3501 - dwc2_writel(pcgctl, hsotg->regs + PCGCTL); 3502 + dwc2_writel(hsotg, pcgctl, PCGCTL); 3502 3503 udelay(10); 3503 3504 } 3504 3505 3505 3506 /* For HNP the bus must be suspended for at least 200ms */ 3506 3507 if (dwc2_host_is_b_hnp_enabled(hsotg)) { 3507 - pcgctl = dwc2_readl(hsotg->regs + PCGCTL); 3508 + pcgctl = dwc2_readl(hsotg, PCGCTL); 3508 3509 pcgctl &= ~PCGCTL_STOPPCLK; 3509 - dwc2_writel(pcgctl, hsotg->regs + PCGCTL); 3510 + dwc2_writel(hsotg, pcgctl, PCGCTL); 3510 3511 3511 3512 spin_unlock_irqrestore(&hsotg->lock, flags); 3512 3513 ··· 3530 3531 * after registers restore. 3531 3532 */ 3532 3533 if (!hsotg->params.power_down) { 3533 - pcgctl = dwc2_readl(hsotg->regs + PCGCTL); 3534 + pcgctl = dwc2_readl(hsotg, PCGCTL); 3534 3535 pcgctl &= ~PCGCTL_STOPPCLK; 3535 - dwc2_writel(pcgctl, hsotg->regs + PCGCTL); 3536 + dwc2_writel(hsotg, pcgctl, PCGCTL); 3536 3537 spin_unlock_irqrestore(&hsotg->lock, flags); 3537 3538 msleep(20); 3538 3539 spin_lock_irqsave(&hsotg->lock, flags); ··· 3541 3542 hprt0 = dwc2_read_hprt0(hsotg); 3542 3543 hprt0 |= HPRT0_RES; 3543 3544 hprt0 &= ~HPRT0_SUSP; 3544 - dwc2_writel(hprt0, hsotg->regs + HPRT0); 3545 + dwc2_writel(hsotg, hprt0, HPRT0); 3545 3546 spin_unlock_irqrestore(&hsotg->lock, flags); 3546 3547 3547 3548 msleep(USB_RESUME_TIMEOUT); ··· 3549 3550 spin_lock_irqsave(&hsotg->lock, flags); 3550 3551 hprt0 = dwc2_read_hprt0(hsotg); 3551 3552 hprt0 &= ~(HPRT0_RES | HPRT0_SUSP); 3552 - dwc2_writel(hprt0, hsotg->regs + HPRT0); 3553 + dwc2_writel(hsotg, hprt0, HPRT0); 3553 3554 hsotg->bus_suspended = false; 3554 3555 spin_unlock_irqrestore(&hsotg->lock, flags); 3555 3556 } ··· 3593 3594 "ClearPortFeature USB_PORT_FEAT_ENABLE\n"); 3594 3595 hprt0 = dwc2_read_hprt0(hsotg); 3595 3596 hprt0 |= HPRT0_ENA; 3596 - dwc2_writel(hprt0, hsotg->regs + HPRT0); 3597 + dwc2_writel(hsotg, hprt0, HPRT0); 3597 3598 break; 3598 3599 3599 3600 case USB_PORT_FEAT_SUSPEND: ··· 3613 3614 "ClearPortFeature USB_PORT_FEAT_POWER\n"); 3614 3615 hprt0 = dwc2_read_hprt0(hsotg); 3615 3616 hprt0 &= ~HPRT0_PWR; 3616 - dwc2_writel(hprt0, hsotg->regs + HPRT0); 3617 + dwc2_writel(hsotg, hprt0, HPRT0); 3617 3618 break; 3618 3619 3619 3620 case USB_PORT_FEAT_INDICATOR: ··· 3734 3735 break; 3735 3736 } 3736 3737 3737 - hprt0 = dwc2_readl(hsotg->regs + HPRT0); 3738 + hprt0 = dwc2_readl(hsotg, HPRT0); 3738 3739 dev_vdbg(hsotg->dev, " HPRT0: 0x%08x\n", hprt0); 3739 3740 3740 3741 if (hprt0 & HPRT0_CONNSTS) ··· 3775 3776 3776 3777 dev_info(hsotg->dev, "Enabling descriptor DMA mode\n"); 3777 3778 hsotg->params.dma_desc_enable = true; 3778 - hcfg = dwc2_readl(hsotg->regs + HCFG); 3779 + hcfg = dwc2_readl(hsotg, HCFG); 3779 3780 hcfg |= HCFG_DESCDMA; 3780 - dwc2_writel(hcfg, hsotg->regs + HCFG); 3781 + dwc2_writel(hsotg, hcfg, HCFG); 3781 3782 hsotg->new_connection = false; 3782 3783 } 3783 3784 } ··· 3824 3825 "SetPortFeature - USB_PORT_FEAT_POWER\n"); 3825 3826 hprt0 = dwc2_read_hprt0(hsotg); 3826 3827 hprt0 |= HPRT0_PWR; 3827 - dwc2_writel(hprt0, hsotg->regs + HPRT0); 3828 + dwc2_writel(hsotg, hprt0, HPRT0); 3828 3829 break; 3829 3830 3830 3831 case USB_PORT_FEAT_RESET: ··· 3834 3835 hprt0 = dwc2_read_hprt0(hsotg); 3835 3836 dev_dbg(hsotg->dev, 3836 3837 "SetPortFeature - USB_PORT_FEAT_RESET\n"); 3837 - pcgctl = dwc2_readl(hsotg->regs + PCGCTL); 3838 + pcgctl = dwc2_readl(hsotg, PCGCTL); 3838 3839 pcgctl &= ~(PCGCTL_ENBL_SLEEP_GATING | PCGCTL_STOPPCLK); 3839 - dwc2_writel(pcgctl, hsotg->regs + PCGCTL); 3840 + dwc2_writel(hsotg, pcgctl, PCGCTL); 3840 3841 /* ??? Original driver does this */ 3841 - dwc2_writel(0, hsotg->regs + PCGCTL); 3842 + dwc2_writel(hsotg, 0, PCGCTL); 3842 3843 3843 3844 hprt0 = dwc2_read_hprt0(hsotg); 3844 3845 /* Clear suspend bit if resetting from suspend state */ ··· 3853 3854 hprt0 |= HPRT0_PWR | HPRT0_RST; 3854 3855 dev_dbg(hsotg->dev, 3855 3856 "In host mode, hprt0=%08x\n", hprt0); 3856 - dwc2_writel(hprt0, hsotg->regs + HPRT0); 3857 + dwc2_writel(hsotg, hprt0, HPRT0); 3857 3858 } 3858 3859 3859 3860 /* Clear reset bit in 10ms (FS/LS) or 50ms (HS) */ 3860 3861 msleep(50); 3861 3862 hprt0 &= ~HPRT0_RST; 3862 - dwc2_writel(hprt0, hsotg->regs + HPRT0); 3863 + dwc2_writel(hsotg, hprt0, HPRT0); 3863 3864 hsotg->lx_state = DWC2_L0; /* Now back to On state */ 3864 3865 break; 3865 3866 ··· 3875 3876 "SetPortFeature - USB_PORT_FEAT_TEST\n"); 3876 3877 hprt0 &= ~HPRT0_TSTCTL_MASK; 3877 3878 hprt0 |= (windex >> 8) << HPRT0_TSTCTL_SHIFT; 3878 - dwc2_writel(hprt0, hsotg->regs + HPRT0); 3879 + dwc2_writel(hsotg, hprt0, HPRT0); 3879 3880 break; 3880 3881 3881 3882 default: ··· 3932 3933 3933 3934 int dwc2_hcd_get_frame_number(struct dwc2_hsotg *hsotg) 3934 3935 { 3935 - u32 hfnum = dwc2_readl(hsotg->regs + HFNUM); 3936 + u32 hfnum = dwc2_readl(hsotg, HFNUM); 3936 3937 3937 3938 #ifdef DWC2_DEBUG_SOF 3938 3939 dev_vdbg(hsotg->dev, "DWC OTG HCD GET FRAME NUMBER %d\n", ··· 3943 3944 3944 3945 int dwc2_hcd_get_future_frame_number(struct dwc2_hsotg *hsotg, int us) 3945 3946 { 3946 - u32 hprt = dwc2_readl(hsotg->regs + HPRT0); 3947 - u32 hfir = dwc2_readl(hsotg->regs + HFIR); 3948 - u32 hfnum = dwc2_readl(hsotg->regs + HFNUM); 3947 + u32 hprt = dwc2_readl(hsotg, HPRT0); 3948 + u32 hfir = dwc2_readl(hsotg, HFIR); 3949 + u32 hfnum = dwc2_readl(hsotg, HFNUM); 3949 3950 unsigned int us_per_frame; 3950 3951 unsigned int frame_number; 3951 3952 unsigned int remaining; ··· 4064 4065 if (chan->xfer_started) { 4065 4066 u32 hfnum, hcchar, hctsiz, hcint, hcintmsk; 4066 4067 4067 - hfnum = dwc2_readl(hsotg->regs + HFNUM); 4068 - hcchar = dwc2_readl(hsotg->regs + HCCHAR(i)); 4069 - hctsiz = dwc2_readl(hsotg->regs + HCTSIZ(i)); 4070 - hcint = dwc2_readl(hsotg->regs + HCINT(i)); 4071 - hcintmsk = dwc2_readl(hsotg->regs + HCINTMSK(i)); 4068 + hfnum = dwc2_readl(hsotg, HFNUM); 4069 + hcchar = dwc2_readl(hsotg, HCCHAR(i)); 4070 + hctsiz = dwc2_readl(hsotg, HCTSIZ(i)); 4071 + hcint = dwc2_readl(hsotg, HCINT(i)); 4072 + hcintmsk = dwc2_readl(hsotg, HCINTMSK(i)); 4072 4073 dev_dbg(hsotg->dev, " hfnum: 0x%08x\n", hfnum); 4073 4074 dev_dbg(hsotg->dev, " hcchar: 0x%08x\n", hcchar); 4074 4075 dev_dbg(hsotg->dev, " hctsiz: 0x%08x\n", hctsiz); ··· 4116 4117 dev_dbg(hsotg->dev, " periodic_channels: %d\n", 4117 4118 hsotg->periodic_channels); 4118 4119 dev_dbg(hsotg->dev, " periodic_usecs: %d\n", hsotg->periodic_usecs); 4119 - np_tx_status = dwc2_readl(hsotg->regs + GNPTXSTS); 4120 + np_tx_status = dwc2_readl(hsotg, GNPTXSTS); 4120 4121 dev_dbg(hsotg->dev, " NP Tx Req Queue Space Avail: %d\n", 4121 4122 (np_tx_status & TXSTS_QSPCAVAIL_MASK) >> TXSTS_QSPCAVAIL_SHIFT); 4122 4123 dev_dbg(hsotg->dev, " NP Tx FIFO Space Avail: %d\n", 4123 4124 (np_tx_status & TXSTS_FSPCAVAIL_MASK) >> TXSTS_FSPCAVAIL_SHIFT); 4124 - p_tx_status = dwc2_readl(hsotg->regs + HPTXSTS); 4125 + p_tx_status = dwc2_readl(hsotg, HPTXSTS); 4125 4126 dev_dbg(hsotg->dev, " P Tx Req Queue Space Avail: %d\n", 4126 4127 (p_tx_status & TXSTS_QSPCAVAIL_MASK) >> TXSTS_QSPCAVAIL_SHIFT); 4127 4128 dev_dbg(hsotg->dev, " P Tx FIFO Space Avail: %d\n", ··· 4371 4372 4372 4373 hprt0 = dwc2_read_hprt0(hsotg); 4373 4374 hprt0 &= ~HPRT0_RST; 4374 - dwc2_writel(hprt0, hsotg->regs + HPRT0); 4375 + dwc2_writel(hsotg, hprt0, HPRT0); 4375 4376 hsotg->flags.b.port_reset_change = 1; 4376 4377 4377 4378 spin_unlock_irqrestore(&hsotg->lock, flags); ··· 4481 4482 hprt0 = dwc2_read_hprt0(hsotg); 4482 4483 hprt0 |= HPRT0_SUSP; 4483 4484 hprt0 &= ~HPRT0_PWR; 4484 - dwc2_writel(hprt0, hsotg->regs + HPRT0); 4485 + dwc2_writel(hsotg, hprt0, HPRT0); 4485 4486 dwc2_vbus_supply_exit(hsotg); 4486 4487 } 4487 4488 ··· 4572 4573 * Clear Port Enable and Port Status changes. 4573 4574 * Enable Port Power. 4574 4575 */ 4575 - dwc2_writel(HPRT0_PWR | HPRT0_CONNDET | 4576 - HPRT0_ENACHG, hsotg->regs + HPRT0); 4576 + dwc2_writel(hsotg, HPRT0_PWR | HPRT0_CONNDET | 4577 + HPRT0_ENACHG, HPRT0); 4577 4578 /* Wait for controller to detect Port Connect */ 4578 4579 usleep_range(5000, 7000); 4579 4580 } ··· 5093 5094 hsotg->status_buf = NULL; 5094 5095 } 5095 5096 5096 - ahbcfg = dwc2_readl(hsotg->regs + GAHBCFG); 5097 + ahbcfg = dwc2_readl(hsotg, GAHBCFG); 5097 5098 5098 5099 /* Disable all interrupts */ 5099 5100 ahbcfg &= ~GAHBCFG_GLBL_INTR_EN; 5100 - dwc2_writel(ahbcfg, hsotg->regs + GAHBCFG); 5101 - dwc2_writel(0, hsotg->regs + GINTMSK); 5101 + dwc2_writel(hsotg, ahbcfg, GAHBCFG); 5102 + dwc2_writel(hsotg, 0, GINTMSK); 5102 5103 5103 5104 if (hsotg->hw_params.snpsid >= DWC2_CORE_REV_3_00a) { 5104 - dctl = dwc2_readl(hsotg->regs + DCTL); 5105 + dctl = dwc2_readl(hsotg, DCTL); 5105 5106 dctl |= DCTL_SFTDISCON; 5106 - dwc2_writel(dctl, hsotg->regs + DCTL); 5107 + dwc2_writel(hsotg, dctl, DCTL); 5107 5108 } 5108 5109 5109 5110 if (hsotg->wq_otg) { ··· 5146 5147 5147 5148 retval = -ENOMEM; 5148 5149 5149 - hcfg = dwc2_readl(hsotg->regs + HCFG); 5150 + hcfg = dwc2_readl(hsotg, HCFG); 5150 5151 dev_dbg(hsotg->dev, "hcfg=%08x\n", hcfg); 5151 5152 5152 5153 #ifdef CONFIG_USB_DWC2_TRACK_MISSED_SOFS ··· 5436 5437 5437 5438 /* Backup Host regs */ 5438 5439 hr = &hsotg->hr_backup; 5439 - hr->hcfg = dwc2_readl(hsotg->regs + HCFG); 5440 - hr->haintmsk = dwc2_readl(hsotg->regs + HAINTMSK); 5440 + hr->hcfg = dwc2_readl(hsotg, HCFG); 5441 + hr->haintmsk = dwc2_readl(hsotg, HAINTMSK); 5441 5442 for (i = 0; i < hsotg->params.host_channels; ++i) 5442 - hr->hcintmsk[i] = dwc2_readl(hsotg->regs + HCINTMSK(i)); 5443 + hr->hcintmsk[i] = dwc2_readl(hsotg, HCINTMSK(i)); 5443 5444 5444 5445 hr->hprt0 = dwc2_read_hprt0(hsotg); 5445 - hr->hfir = dwc2_readl(hsotg->regs + HFIR); 5446 - hr->hptxfsiz = dwc2_readl(hsotg->regs + HPTXFSIZ); 5446 + hr->hfir = dwc2_readl(hsotg, HFIR); 5447 + hr->hptxfsiz = dwc2_readl(hsotg, HPTXFSIZ); 5447 5448 hr->valid = true; 5448 5449 5449 5450 return 0; ··· 5472 5473 } 5473 5474 hr->valid = false; 5474 5475 5475 - dwc2_writel(hr->hcfg, hsotg->regs + HCFG); 5476 - dwc2_writel(hr->haintmsk, hsotg->regs + HAINTMSK); 5476 + dwc2_writel(hsotg, hr->hcfg, HCFG); 5477 + dwc2_writel(hsotg, hr->haintmsk, HAINTMSK); 5477 5478 5478 5479 for (i = 0; i < hsotg->params.host_channels; ++i) 5479 - dwc2_writel(hr->hcintmsk[i], hsotg->regs + HCINTMSK(i)); 5480 + dwc2_writel(hsotg, hr->hcintmsk[i], HCINTMSK(i)); 5480 5481 5481 - dwc2_writel(hr->hprt0, hsotg->regs + HPRT0); 5482 - dwc2_writel(hr->hfir, hsotg->regs + HFIR); 5483 - dwc2_writel(hr->hptxfsiz, hsotg->regs + HPTXFSIZ); 5482 + dwc2_writel(hsotg, hr->hprt0, HPRT0); 5483 + dwc2_writel(hsotg, hr->hfir, HFIR); 5484 + dwc2_writel(hsotg, hr->hptxfsiz, HPTXFSIZ); 5484 5485 hsotg->frame_number = 0; 5485 5486 5486 5487 return 0; ··· 5515 5516 } 5516 5517 5517 5518 /* Enter USB Suspend Mode */ 5518 - hprt0 = dwc2_readl(hsotg->regs + HPRT0); 5519 + hprt0 = dwc2_readl(hsotg, HPRT0); 5519 5520 hprt0 |= HPRT0_SUSP; 5520 5521 hprt0 &= ~HPRT0_ENA; 5521 - dwc2_writel(hprt0, hsotg->regs + HPRT0); 5522 + dwc2_writel(hsotg, hprt0, HPRT0); 5522 5523 5523 5524 /* Wait for the HPRT0.PrtSusp register field to be set */ 5524 5525 if (dwc2_hsotg_wait_bit_set(hsotg, HPRT0, HPRT0_SUSP, 3000)) ··· 5531 5532 spin_lock_irqsave(&hsotg->lock, flags); 5532 5533 hsotg->lx_state = DWC2_L2; 5533 5534 5534 - gusbcfg = dwc2_readl(hsotg->regs + GUSBCFG); 5535 + gusbcfg = dwc2_readl(hsotg, GUSBCFG); 5535 5536 if (gusbcfg & GUSBCFG_ULPI_UTMI_SEL) { 5536 5537 /* ULPI interface */ 5537 5538 /* Suspend the Phy Clock */ 5538 - pcgcctl = dwc2_readl(hsotg->regs + PCGCTL); 5539 + pcgcctl = dwc2_readl(hsotg, PCGCTL); 5539 5540 pcgcctl |= PCGCTL_STOPPCLK; 5540 - dwc2_writel(pcgcctl, hsotg->regs + PCGCTL); 5541 + dwc2_writel(hsotg, pcgcctl, PCGCTL); 5541 5542 udelay(10); 5542 5543 5543 - gpwrdn = dwc2_readl(hsotg->regs + GPWRDN); 5544 + gpwrdn = dwc2_readl(hsotg, GPWRDN); 5544 5545 gpwrdn |= GPWRDN_PMUACTV; 5545 - dwc2_writel(gpwrdn, hsotg->regs + GPWRDN); 5546 + dwc2_writel(hsotg, gpwrdn, GPWRDN); 5546 5547 udelay(10); 5547 5548 } else { 5548 5549 /* UTMI+ Interface */ 5549 - gpwrdn = dwc2_readl(hsotg->regs + GPWRDN); 5550 + gpwrdn = dwc2_readl(hsotg, GPWRDN); 5550 5551 gpwrdn |= GPWRDN_PMUACTV; 5551 - dwc2_writel(gpwrdn, hsotg->regs + GPWRDN); 5552 + dwc2_writel(hsotg, gpwrdn, GPWRDN); 5552 5553 udelay(10); 5553 5554 5554 - pcgcctl = dwc2_readl(hsotg->regs + PCGCTL); 5555 + pcgcctl = dwc2_readl(hsotg, PCGCTL); 5555 5556 pcgcctl |= PCGCTL_STOPPCLK; 5556 - dwc2_writel(pcgcctl, hsotg->regs + PCGCTL); 5557 + dwc2_writel(hsotg, pcgcctl, PCGCTL); 5557 5558 udelay(10); 5558 5559 } 5559 5560 5560 5561 /* Enable interrupts from wake up logic */ 5561 - gpwrdn = dwc2_readl(hsotg->regs + GPWRDN); 5562 + gpwrdn = dwc2_readl(hsotg, GPWRDN); 5562 5563 gpwrdn |= GPWRDN_PMUINTSEL; 5563 - dwc2_writel(gpwrdn, hsotg->regs + GPWRDN); 5564 + dwc2_writel(hsotg, gpwrdn, GPWRDN); 5564 5565 udelay(10); 5565 5566 5566 5567 /* Unmask host mode interrupts in GPWRDN */ 5567 - gpwrdn = dwc2_readl(hsotg->regs + GPWRDN); 5568 + gpwrdn = dwc2_readl(hsotg, GPWRDN); 5568 5569 gpwrdn |= GPWRDN_DISCONN_DET_MSK; 5569 5570 gpwrdn |= GPWRDN_LNSTSCHG_MSK; 5570 5571 gpwrdn |= GPWRDN_STS_CHGINT_MSK; 5571 - dwc2_writel(gpwrdn, hsotg->regs + GPWRDN); 5572 + dwc2_writel(hsotg, gpwrdn, GPWRDN); 5572 5573 udelay(10); 5573 5574 5574 5575 /* Enable Power Down Clamp */ 5575 - gpwrdn = dwc2_readl(hsotg->regs + GPWRDN); 5576 + gpwrdn = dwc2_readl(hsotg, GPWRDN); 5576 5577 gpwrdn |= GPWRDN_PWRDNCLMP; 5577 - dwc2_writel(gpwrdn, hsotg->regs + GPWRDN); 5578 + dwc2_writel(hsotg, gpwrdn, GPWRDN); 5578 5579 udelay(10); 5579 5580 5580 5581 /* Switch off VDD */ 5581 - gpwrdn = dwc2_readl(hsotg->regs + GPWRDN); 5582 + gpwrdn = dwc2_readl(hsotg, GPWRDN); 5582 5583 gpwrdn |= GPWRDN_PWRDNSWTCH; 5583 - dwc2_writel(gpwrdn, hsotg->regs + GPWRDN); 5584 + dwc2_writel(hsotg, gpwrdn, GPWRDN); 5584 5585 5585 5586 hsotg->hibernated = 1; 5586 5587 hsotg->bus_suspended = 1; ··· 5628 5629 mdelay(100); 5629 5630 5630 5631 /* Clear all pending interupts */ 5631 - dwc2_writel(0xffffffff, hsotg->regs + GINTSTS); 5632 + dwc2_writel(hsotg, 0xffffffff, GINTSTS); 5632 5633 5633 5634 /* De-assert Restore */ 5634 - gpwrdn = dwc2_readl(hsotg->regs + GPWRDN); 5635 + gpwrdn = dwc2_readl(hsotg, GPWRDN); 5635 5636 gpwrdn &= ~GPWRDN_RESTORE; 5636 - dwc2_writel(gpwrdn, hsotg->regs + GPWRDN); 5637 + dwc2_writel(hsotg, gpwrdn, GPWRDN); 5637 5638 udelay(10); 5638 5639 5639 5640 /* Restore GUSBCFG, HCFG */ 5640 - dwc2_writel(gr->gusbcfg, hsotg->regs + GUSBCFG); 5641 - dwc2_writel(hr->hcfg, hsotg->regs + HCFG); 5641 + dwc2_writel(hsotg, gr->gusbcfg, GUSBCFG); 5642 + dwc2_writel(hsotg, hr->hcfg, HCFG); 5642 5643 5643 5644 /* De-assert Wakeup Logic */ 5644 - gpwrdn = dwc2_readl(hsotg->regs + GPWRDN); 5645 + gpwrdn = dwc2_readl(hsotg, GPWRDN); 5645 5646 gpwrdn &= ~GPWRDN_PMUACTV; 5646 - dwc2_writel(gpwrdn, hsotg->regs + GPWRDN); 5647 + dwc2_writel(hsotg, gpwrdn, GPWRDN); 5647 5648 udelay(10); 5648 5649 5649 5650 hprt0 = hr->hprt0; 5650 5651 hprt0 |= HPRT0_PWR; 5651 5652 hprt0 &= ~HPRT0_ENA; 5652 5653 hprt0 &= ~HPRT0_SUSP; 5653 - dwc2_writel(hprt0, hsotg->regs + HPRT0); 5654 + dwc2_writel(hsotg, hprt0, HPRT0); 5654 5655 5655 5656 hprt0 = hr->hprt0; 5656 5657 hprt0 |= HPRT0_PWR; ··· 5659 5660 5660 5661 if (reset) { 5661 5662 hprt0 |= HPRT0_RST; 5662 - dwc2_writel(hprt0, hsotg->regs + HPRT0); 5663 + dwc2_writel(hsotg, hprt0, HPRT0); 5663 5664 5664 5665 /* Wait for Resume time and then program HPRT again */ 5665 5666 mdelay(60); 5666 5667 hprt0 &= ~HPRT0_RST; 5667 - dwc2_writel(hprt0, hsotg->regs + HPRT0); 5668 + dwc2_writel(hsotg, hprt0, HPRT0); 5668 5669 } else { 5669 5670 hprt0 |= HPRT0_RES; 5670 - dwc2_writel(hprt0, hsotg->regs + HPRT0); 5671 + dwc2_writel(hsotg, hprt0, HPRT0); 5671 5672 5672 5673 /* Wait for Resume time and then program HPRT again */ 5673 5674 mdelay(100); 5674 5675 hprt0 &= ~HPRT0_RES; 5675 - dwc2_writel(hprt0, hsotg->regs + HPRT0); 5676 + dwc2_writel(hsotg, hprt0, HPRT0); 5676 5677 } 5677 5678 /* Clear all interrupt status */ 5678 - hprt0 = dwc2_readl(hsotg->regs + HPRT0); 5679 + hprt0 = dwc2_readl(hsotg, HPRT0); 5679 5680 hprt0 |= HPRT0_CONNDET; 5680 5681 hprt0 |= HPRT0_ENACHG; 5681 5682 hprt0 &= ~HPRT0_ENA; 5682 - dwc2_writel(hprt0, hsotg->regs + HPRT0); 5683 + dwc2_writel(hsotg, hprt0, HPRT0); 5683 5684 5684 - hprt0 = dwc2_readl(hsotg->regs + HPRT0); 5685 + hprt0 = dwc2_readl(hsotg, HPRT0); 5685 5686 5686 5687 /* Clear all pending interupts */ 5687 - dwc2_writel(0xffffffff, hsotg->regs + GINTSTS); 5688 + dwc2_writel(hsotg, 0xffffffff, GINTSTS); 5688 5689 5689 5690 /* Restore global registers */ 5690 5691 ret = dwc2_restore_global_registers(hsotg);
+5 -5
drivers/usb/dwc2/hcd.h
··· 469 469 */ 470 470 static inline void disable_hc_int(struct dwc2_hsotg *hsotg, int chnum, u32 intr) 471 471 { 472 - u32 mask = dwc2_readl(hsotg->regs + HCINTMSK(chnum)); 472 + u32 mask = dwc2_readl(hsotg, HCINTMSK(chnum)); 473 473 474 474 mask &= ~intr; 475 - dwc2_writel(mask, hsotg->regs + HCINTMSK(chnum)); 475 + dwc2_writel(hsotg, mask, HCINTMSK(chnum)); 476 476 } 477 477 478 478 void dwc2_hc_cleanup(struct dwc2_hsotg *hsotg, struct dwc2_host_chan *chan); ··· 487 487 */ 488 488 static inline u32 dwc2_read_hprt0(struct dwc2_hsotg *hsotg) 489 489 { 490 - u32 hprt0 = dwc2_readl(hsotg->regs + HPRT0); 490 + u32 hprt0 = dwc2_readl(hsotg, HPRT0); 491 491 492 492 hprt0 &= ~(HPRT0_ENA | HPRT0_CONNDET | HPRT0_ENACHG | HPRT0_OVRCURRCHG); 493 493 return hprt0; ··· 690 690 */ 691 691 static inline u32 dwc2_read_core_intr(struct dwc2_hsotg *hsotg) 692 692 { 693 - return dwc2_readl(hsotg->regs + GINTSTS) & 694 - dwc2_readl(hsotg->regs + GINTMSK); 693 + return dwc2_readl(hsotg, GINTSTS) & 694 + dwc2_readl(hsotg, GINTMSK); 695 695 } 696 696 697 697 static inline u32 dwc2_hcd_urb_get_status(struct dwc2_hcd_urb *dwc2_urb)
+5 -5
drivers/usb/dwc2/hcd_ddma.c
··· 185 185 186 186 spin_lock_irqsave(&hsotg->lock, flags); 187 187 188 - hcfg = dwc2_readl(hsotg->regs + HCFG); 188 + hcfg = dwc2_readl(hsotg, HCFG); 189 189 if (hcfg & HCFG_PERSCHEDENA) { 190 190 /* already enabled */ 191 191 spin_unlock_irqrestore(&hsotg->lock, flags); 192 192 return; 193 193 } 194 194 195 - dwc2_writel(hsotg->frame_list_dma, hsotg->regs + HFLBADDR); 195 + dwc2_writel(hsotg, hsotg->frame_list_dma, HFLBADDR); 196 196 197 197 hcfg &= ~HCFG_FRLISTEN_MASK; 198 198 hcfg |= fr_list_en | HCFG_PERSCHEDENA; 199 199 dev_vdbg(hsotg->dev, "Enabling Periodic schedule\n"); 200 - dwc2_writel(hcfg, hsotg->regs + HCFG); 200 + dwc2_writel(hsotg, hcfg, HCFG); 201 201 202 202 spin_unlock_irqrestore(&hsotg->lock, flags); 203 203 } ··· 209 209 210 210 spin_lock_irqsave(&hsotg->lock, flags); 211 211 212 - hcfg = dwc2_readl(hsotg->regs + HCFG); 212 + hcfg = dwc2_readl(hsotg, HCFG); 213 213 if (!(hcfg & HCFG_PERSCHEDENA)) { 214 214 /* already disabled */ 215 215 spin_unlock_irqrestore(&hsotg->lock, flags); ··· 218 218 219 219 hcfg &= ~HCFG_PERSCHEDENA; 220 220 dev_vdbg(hsotg->dev, "Disabling Periodic schedule\n"); 221 - dwc2_writel(hcfg, hsotg->regs + HCFG); 221 + dwc2_writel(hsotg, hcfg, HCFG); 222 222 223 223 spin_unlock_irqrestore(&hsotg->lock, flags); 224 224 }
+48 -48
drivers/usb/dwc2/hcd_intr.c
··· 144 144 enum dwc2_transaction_type tr_type; 145 145 146 146 /* Clear interrupt */ 147 - dwc2_writel(GINTSTS_SOF, hsotg->regs + GINTSTS); 147 + dwc2_writel(hsotg, GINTSTS_SOF, GINTSTS); 148 148 149 149 #ifdef DEBUG_SOF 150 150 dev_vdbg(hsotg->dev, "--Start of Frame Interrupt--\n"); ··· 191 191 if (dbg_perio()) 192 192 dev_vdbg(hsotg->dev, "--RxFIFO Level Interrupt--\n"); 193 193 194 - grxsts = dwc2_readl(hsotg->regs + GRXSTSP); 194 + grxsts = dwc2_readl(hsotg, GRXSTSP); 195 195 chnum = (grxsts & GRXSTS_HCHNUM_MASK) >> GRXSTS_HCHNUM_SHIFT; 196 196 chan = hsotg->hc_ptr_array[chnum]; 197 197 if (!chan) { ··· 274 274 dev_vdbg(hsotg->dev, "%s(%p)\n", __func__, hsotg); 275 275 276 276 /* Every time when port enables calculate HFIR.FrInterval */ 277 - hfir = dwc2_readl(hsotg->regs + HFIR); 277 + hfir = dwc2_readl(hsotg, HFIR); 278 278 hfir &= ~HFIR_FRINT_MASK; 279 279 hfir |= dwc2_calc_frame_interval(hsotg) << HFIR_FRINT_SHIFT & 280 280 HFIR_FRINT_MASK; 281 - dwc2_writel(hfir, hsotg->regs + HFIR); 281 + dwc2_writel(hsotg, hfir, HFIR); 282 282 283 283 /* Check if we need to adjust the PHY clock speed for low power */ 284 284 if (!params->host_support_fs_ls_low_power) { ··· 287 287 return; 288 288 } 289 289 290 - usbcfg = dwc2_readl(hsotg->regs + GUSBCFG); 290 + usbcfg = dwc2_readl(hsotg, GUSBCFG); 291 291 prtspd = (hprt0 & HPRT0_SPD_MASK) >> HPRT0_SPD_SHIFT; 292 292 293 293 if (prtspd == HPRT0_SPD_LOW_SPEED || prtspd == HPRT0_SPD_FULL_SPEED) { ··· 295 295 if (!(usbcfg & GUSBCFG_PHY_LP_CLK_SEL)) { 296 296 /* Set PHY low power clock select for FS/LS devices */ 297 297 usbcfg |= GUSBCFG_PHY_LP_CLK_SEL; 298 - dwc2_writel(usbcfg, hsotg->regs + GUSBCFG); 298 + dwc2_writel(hsotg, usbcfg, GUSBCFG); 299 299 do_reset = 1; 300 300 } 301 301 302 - hcfg = dwc2_readl(hsotg->regs + HCFG); 302 + hcfg = dwc2_readl(hsotg, HCFG); 303 303 fslspclksel = (hcfg & HCFG_FSLSPCLKSEL_MASK) >> 304 304 HCFG_FSLSPCLKSEL_SHIFT; 305 305 ··· 312 312 fslspclksel = HCFG_FSLSPCLKSEL_6_MHZ; 313 313 hcfg &= ~HCFG_FSLSPCLKSEL_MASK; 314 314 hcfg |= fslspclksel << HCFG_FSLSPCLKSEL_SHIFT; 315 - dwc2_writel(hcfg, hsotg->regs + HCFG); 315 + dwc2_writel(hsotg, hcfg, HCFG); 316 316 do_reset = 1; 317 317 } 318 318 } else { ··· 323 323 fslspclksel = HCFG_FSLSPCLKSEL_48_MHZ; 324 324 hcfg &= ~HCFG_FSLSPCLKSEL_MASK; 325 325 hcfg |= fslspclksel << HCFG_FSLSPCLKSEL_SHIFT; 326 - dwc2_writel(hcfg, hsotg->regs + HCFG); 326 + dwc2_writel(hsotg, hcfg, HCFG); 327 327 do_reset = 1; 328 328 } 329 329 } ··· 331 331 /* Not low power */ 332 332 if (usbcfg & GUSBCFG_PHY_LP_CLK_SEL) { 333 333 usbcfg &= ~GUSBCFG_PHY_LP_CLK_SEL; 334 - dwc2_writel(usbcfg, hsotg->regs + GUSBCFG); 334 + dwc2_writel(hsotg, usbcfg, GUSBCFG); 335 335 do_reset = 1; 336 336 } 337 337 } 338 338 339 339 if (do_reset) { 340 340 *hprt0_modify |= HPRT0_RST; 341 - dwc2_writel(*hprt0_modify, hsotg->regs + HPRT0); 341 + dwc2_writel(hsotg, *hprt0_modify, HPRT0); 342 342 queue_delayed_work(hsotg->wq_otg, &hsotg->reset_work, 343 343 msecs_to_jiffies(60)); 344 344 } else { ··· 359 359 360 360 dev_vdbg(hsotg->dev, "--Port Interrupt--\n"); 361 361 362 - hprt0 = dwc2_readl(hsotg->regs + HPRT0); 362 + hprt0 = dwc2_readl(hsotg, HPRT0); 363 363 hprt0_modify = hprt0; 364 364 365 365 /* ··· 374 374 * Set flag and clear if detected 375 375 */ 376 376 if (hprt0 & HPRT0_CONNDET) { 377 - dwc2_writel(hprt0_modify | HPRT0_CONNDET, hsotg->regs + HPRT0); 377 + dwc2_writel(hsotg, hprt0_modify | HPRT0_CONNDET, HPRT0); 378 378 379 379 dev_vdbg(hsotg->dev, 380 380 "--Port Interrupt HPRT0=0x%08x Port Connect Detected--\n", ··· 392 392 * Clear if detected - Set internal flag if disabled 393 393 */ 394 394 if (hprt0 & HPRT0_ENACHG) { 395 - dwc2_writel(hprt0_modify | HPRT0_ENACHG, hsotg->regs + HPRT0); 395 + dwc2_writel(hsotg, hprt0_modify | HPRT0_ENACHG, HPRT0); 396 396 dev_vdbg(hsotg->dev, 397 397 " --Port Interrupt HPRT0=0x%08x Port Enable Changed (now %d)--\n", 398 398 hprt0, !!(hprt0 & HPRT0_ENA)); ··· 406 406 407 407 hsotg->params.dma_desc_enable = false; 408 408 hsotg->new_connection = false; 409 - hcfg = dwc2_readl(hsotg->regs + HCFG); 409 + hcfg = dwc2_readl(hsotg, HCFG); 410 410 hcfg &= ~HCFG_DESCDMA; 411 - dwc2_writel(hcfg, hsotg->regs + HCFG); 411 + dwc2_writel(hsotg, hcfg, HCFG); 412 412 } 413 413 } 414 414 } 415 415 416 416 /* Overcurrent Change Interrupt */ 417 417 if (hprt0 & HPRT0_OVRCURRCHG) { 418 - dwc2_writel(hprt0_modify | HPRT0_OVRCURRCHG, 419 - hsotg->regs + HPRT0); 418 + dwc2_writel(hsotg, hprt0_modify | HPRT0_OVRCURRCHG, 419 + HPRT0); 420 420 dev_vdbg(hsotg->dev, 421 421 " --Port Interrupt HPRT0=0x%08x Port Overcurrent Changed--\n", 422 422 hprt0); ··· 441 441 { 442 442 u32 hctsiz, count, length; 443 443 444 - hctsiz = dwc2_readl(hsotg->regs + HCTSIZ(chnum)); 444 + hctsiz = dwc2_readl(hsotg, HCTSIZ(chnum)); 445 445 446 446 if (halt_status == DWC2_HC_XFER_COMPLETE) { 447 447 if (chan->ep_is_in) { ··· 518 518 urb->status = 0; 519 519 } 520 520 521 - hctsiz = dwc2_readl(hsotg->regs + HCTSIZ(chnum)); 521 + hctsiz = dwc2_readl(hsotg, HCTSIZ(chnum)); 522 522 dev_vdbg(hsotg->dev, "DWC_otg: %s: %s, channel %d\n", 523 523 __func__, (chan->ep_is_in ? "IN" : "OUT"), chnum); 524 524 dev_vdbg(hsotg->dev, " chan->xfer_len %d\n", chan->xfer_len); ··· 541 541 struct dwc2_host_chan *chan, int chnum, 542 542 struct dwc2_qtd *qtd) 543 543 { 544 - u32 hctsiz = dwc2_readl(hsotg->regs + HCTSIZ(chnum)); 544 + u32 hctsiz = dwc2_readl(hsotg, HCTSIZ(chnum)); 545 545 u32 pid = (hctsiz & TSIZ_SC_MC_PID_MASK) >> TSIZ_SC_MC_PID_SHIFT; 546 546 547 547 if (chan->ep_type != USB_ENDPOINT_XFER_CONTROL) { ··· 780 780 } 781 781 } 782 782 783 - haintmsk = dwc2_readl(hsotg->regs + HAINTMSK); 783 + haintmsk = dwc2_readl(hsotg, HAINTMSK); 784 784 haintmsk &= ~(1 << chan->hc_num); 785 - dwc2_writel(haintmsk, hsotg->regs + HAINTMSK); 785 + dwc2_writel(hsotg, haintmsk, HAINTMSK); 786 786 787 787 /* Try to queue more transfers now that there's a free channel */ 788 788 tr_type = dwc2_hcd_select_transactions(hsotg); ··· 829 829 * is enabled so that the non-periodic schedule will 830 830 * be processed 831 831 */ 832 - gintmsk = dwc2_readl(hsotg->regs + GINTMSK); 832 + gintmsk = dwc2_readl(hsotg, GINTMSK); 833 833 gintmsk |= GINTSTS_NPTXFEMP; 834 - dwc2_writel(gintmsk, hsotg->regs + GINTMSK); 834 + dwc2_writel(hsotg, gintmsk, GINTMSK); 835 835 } else { 836 836 dev_vdbg(hsotg->dev, "isoc/intr\n"); 837 837 /* ··· 848 848 * enabled so that the periodic schedule will be 849 849 * processed 850 850 */ 851 - gintmsk = dwc2_readl(hsotg->regs + GINTMSK); 851 + gintmsk = dwc2_readl(hsotg, GINTMSK); 852 852 gintmsk |= GINTSTS_PTXFEMP; 853 - dwc2_writel(gintmsk, hsotg->regs + GINTMSK); 853 + dwc2_writel(hsotg, gintmsk, GINTMSK); 854 854 } 855 855 } 856 856 } ··· 915 915 struct dwc2_qtd *qtd, 916 916 enum dwc2_halt_status halt_status) 917 917 { 918 - u32 hctsiz = dwc2_readl(hsotg->regs + HCTSIZ(chnum)); 918 + u32 hctsiz = dwc2_readl(hsotg, HCTSIZ(chnum)); 919 919 920 920 qtd->error_count = 0; 921 921 ··· 959 959 960 960 qtd->isoc_split_offset += len; 961 961 962 - hctsiz = dwc2_readl(hsotg->regs + HCTSIZ(chnum)); 962 + hctsiz = dwc2_readl(hsotg, HCTSIZ(chnum)); 963 963 pid = (hctsiz & TSIZ_SC_MC_PID_MASK) >> TSIZ_SC_MC_PID_SHIFT; 964 964 965 965 if (frame_desc->actual_length >= frame_desc->length || pid == 0) { ··· 1185 1185 1186 1186 urb->actual_length += xfer_length; 1187 1187 1188 - hctsiz = dwc2_readl(hsotg->regs + HCTSIZ(chnum)); 1188 + hctsiz = dwc2_readl(hsotg, HCTSIZ(chnum)); 1189 1189 dev_vdbg(hsotg->dev, "DWC_otg: %s: %s, channel %d\n", 1190 1190 __func__, (chan->ep_is_in ? "IN" : "OUT"), chnum); 1191 1191 dev_vdbg(hsotg->dev, " chan->start_pkt_count %d\n", ··· 1566 1566 1567 1567 dwc2_hc_handle_tt_clear(hsotg, chan, qtd); 1568 1568 1569 - hcchar = dwc2_readl(hsotg->regs + HCCHAR(chnum)); 1570 - hcsplt = dwc2_readl(hsotg->regs + HCSPLT(chnum)); 1571 - hctsiz = dwc2_readl(hsotg->regs + HCTSIZ(chnum)); 1572 - hc_dma = dwc2_readl(hsotg->regs + HCDMA(chnum)); 1569 + hcchar = dwc2_readl(hsotg, HCCHAR(chnum)); 1570 + hcsplt = dwc2_readl(hsotg, HCSPLT(chnum)); 1571 + hctsiz = dwc2_readl(hsotg, HCTSIZ(chnum)); 1572 + hc_dma = dwc2_readl(hsotg, HCDMA(chnum)); 1573 1573 1574 1574 dev_err(hsotg->dev, "AHB ERROR, Channel %d\n", chnum); 1575 1575 dev_err(hsotg->dev, " hcchar 0x%08x, hcsplt 0x%08x\n", hcchar, hcsplt); ··· 1781 1781 * This code is here only as a check. This condition should 1782 1782 * never happen. Ignore the halt if it does occur. 1783 1783 */ 1784 - hcchar = dwc2_readl(hsotg->regs + HCCHAR(chnum)); 1785 - hctsiz = dwc2_readl(hsotg->regs + HCTSIZ(chnum)); 1786 - hcintmsk = dwc2_readl(hsotg->regs + HCINTMSK(chnum)); 1787 - hcsplt = dwc2_readl(hsotg->regs + HCSPLT(chnum)); 1784 + hcchar = dwc2_readl(hsotg, HCCHAR(chnum)); 1785 + hctsiz = dwc2_readl(hsotg, HCTSIZ(chnum)); 1786 + hcintmsk = dwc2_readl(hsotg, HCINTMSK(chnum)); 1787 + hcsplt = dwc2_readl(hsotg, HCSPLT(chnum)); 1788 1788 dev_dbg(hsotg->dev, 1789 1789 "%s: chan->halt_status DWC2_HC_XFER_NO_HALT_STATUS,\n", 1790 1790 __func__); ··· 1808 1808 * when the halt interrupt occurs. Halt the channel again if it does 1809 1809 * occur. 1810 1810 */ 1811 - hcchar = dwc2_readl(hsotg->regs + HCCHAR(chnum)); 1811 + hcchar = dwc2_readl(hsotg, HCCHAR(chnum)); 1812 1812 if (hcchar & HCCHAR_CHDIS) { 1813 1813 dev_warn(hsotg->dev, 1814 1814 "%s: hcchar.chdis set unexpectedly, hcchar 0x%08x, trying to halt again\n", ··· 1868 1868 return; 1869 1869 } 1870 1870 1871 - hcintmsk = dwc2_readl(hsotg->regs + HCINTMSK(chnum)); 1871 + hcintmsk = dwc2_readl(hsotg, HCINTMSK(chnum)); 1872 1872 1873 1873 if (chan->hcint & HCINTMSK_XFERCOMPL) { 1874 1874 /* ··· 1963 1963 dev_err(hsotg->dev, 1964 1964 "hcint 0x%08x, intsts 0x%08x\n", 1965 1965 chan->hcint, 1966 - dwc2_readl(hsotg->regs + GINTSTS)); 1966 + dwc2_readl(hsotg, GINTSTS)); 1967 1967 goto error; 1968 1968 } 1969 1969 } ··· 2036 2036 2037 2037 chan = hsotg->hc_ptr_array[chnum]; 2038 2038 2039 - hcint = dwc2_readl(hsotg->regs + HCINT(chnum)); 2040 - hcintmsk = dwc2_readl(hsotg->regs + HCINTMSK(chnum)); 2039 + hcint = dwc2_readl(hsotg, HCINT(chnum)); 2040 + hcintmsk = dwc2_readl(hsotg, HCINTMSK(chnum)); 2041 2041 if (!chan) { 2042 2042 dev_err(hsotg->dev, "## hc_ptr_array for channel is NULL ##\n"); 2043 - dwc2_writel(hcint, hsotg->regs + HCINT(chnum)); 2043 + dwc2_writel(hsotg, hcint, HCINT(chnum)); 2044 2044 return; 2045 2045 } 2046 2046 ··· 2052 2052 hcint, hcintmsk, hcint & hcintmsk); 2053 2053 } 2054 2054 2055 - dwc2_writel(hcint, hsotg->regs + HCINT(chnum)); 2055 + dwc2_writel(hsotg, hcint, HCINT(chnum)); 2056 2056 2057 2057 /* 2058 2058 * If we got an interrupt after someone called ··· 2187 2187 int i; 2188 2188 struct dwc2_host_chan *chan, *chan_tmp; 2189 2189 2190 - haint = dwc2_readl(hsotg->regs + HAINT); 2190 + haint = dwc2_readl(hsotg, HAINT); 2191 2191 if (dbg_perio()) { 2192 2192 dev_vdbg(hsotg->dev, "%s()\n", __func__); 2193 2193 ··· 2271 2271 "DWC OTG HCD Finished Servicing Interrupts\n"); 2272 2272 dev_vdbg(hsotg->dev, 2273 2273 "DWC OTG HCD gintsts=0x%08x gintmsk=0x%08x\n", 2274 - dwc2_readl(hsotg->regs + GINTSTS), 2275 - dwc2_readl(hsotg->regs + GINTMSK)); 2274 + dwc2_readl(hsotg, GINTSTS), 2275 + dwc2_readl(hsotg, GINTMSK)); 2276 2276 } 2277 2277 } 2278 2278
+5 -5
drivers/usb/dwc2/hcd_queue.c
··· 1510 1510 bool ep_is_in = !!dwc2_hcd_is_pipe_in(&urb->pipe_info); 1511 1511 bool ep_is_isoc = (ep_type == USB_ENDPOINT_XFER_ISOC); 1512 1512 bool ep_is_int = (ep_type == USB_ENDPOINT_XFER_INT); 1513 - u32 hprt = dwc2_readl(hsotg->regs + HPRT0); 1513 + u32 hprt = dwc2_readl(hsotg, HPRT0); 1514 1514 u32 prtspd = (hprt & HPRT0_SPD_MASK) >> HPRT0_SPD_SHIFT; 1515 1515 bool do_split = (prtspd == HPRT0_SPD_HIGH_SPEED && 1516 1516 dev_speed != USB_SPEED_HIGH); ··· 1747 1747 if (status) 1748 1748 return status; 1749 1749 if (!hsotg->periodic_qh_count) { 1750 - intr_mask = dwc2_readl(hsotg->regs + GINTMSK); 1750 + intr_mask = dwc2_readl(hsotg, GINTMSK); 1751 1751 intr_mask |= GINTSTS_SOF; 1752 - dwc2_writel(intr_mask, hsotg->regs + GINTMSK); 1752 + dwc2_writel(hsotg, intr_mask, GINTMSK); 1753 1753 } 1754 1754 hsotg->periodic_qh_count++; 1755 1755 ··· 1788 1788 hsotg->periodic_qh_count--; 1789 1789 if (!hsotg->periodic_qh_count && 1790 1790 !hsotg->params.dma_desc_enable) { 1791 - intr_mask = dwc2_readl(hsotg->regs + GINTMSK); 1791 + intr_mask = dwc2_readl(hsotg, GINTMSK); 1792 1792 intr_mask &= ~GINTSTS_SOF; 1793 - dwc2_writel(intr_mask, hsotg->regs + GINTMSK); 1793 + dwc2_writel(hsotg, intr_mask, GINTMSK); 1794 1794 } 1795 1795 } 1796 1796
+10 -14
drivers/usb/dwc2/params.c
··· 47 47 p->max_transfer_size = 65535; 48 48 p->max_packet_count = 511; 49 49 p->ahbcfg = 0x10; 50 - p->uframe_sched = false; 51 50 } 52 51 53 52 static void dwc2_set_his_params(struct dwc2_hsotg *hsotg) ··· 67 68 p->reload_ctl = false; 68 69 p->ahbcfg = GAHBCFG_HBSTLEN_INCR16 << 69 70 GAHBCFG_HBSTLEN_SHIFT; 70 - p->uframe_sched = false; 71 71 p->change_speed_quirk = true; 72 72 p->power_down = false; 73 73 } ··· 110 112 p->phy_type = DWC2_PHY_TYPE_PARAM_UTMI; 111 113 p->ahbcfg = GAHBCFG_HBSTLEN_INCR8 << 112 114 GAHBCFG_HBSTLEN_SHIFT; 113 - p->uframe_sched = false; 114 115 } 115 116 116 117 static void dwc2_set_amcc_params(struct dwc2_hsotg *hsotg) ··· 131 134 p->max_packet_count = 256; 132 135 p->phy_type = DWC2_PHY_TYPE_PARAM_FS; 133 136 p->i2c_enable = false; 134 - p->uframe_sched = false; 135 137 p->activate_stm_fs_transceiver = true; 136 138 } 137 139 ··· 650 654 651 655 dwc2_force_mode(hsotg, true); 652 656 653 - gnptxfsiz = dwc2_readl(hsotg->regs + GNPTXFSIZ); 654 - hptxfsiz = dwc2_readl(hsotg->regs + HPTXFSIZ); 657 + gnptxfsiz = dwc2_readl(hsotg, GNPTXFSIZ); 658 + hptxfsiz = dwc2_readl(hsotg, HPTXFSIZ); 655 659 656 660 hw->host_nperio_tx_fifo_size = (gnptxfsiz & FIFOSIZE_DEPTH_MASK) >> 657 661 FIFOSIZE_DEPTH_SHIFT; ··· 675 679 676 680 dwc2_force_mode(hsotg, false); 677 681 678 - gnptxfsiz = dwc2_readl(hsotg->regs + GNPTXFSIZ); 682 + gnptxfsiz = dwc2_readl(hsotg, GNPTXFSIZ); 679 683 680 684 fifo_count = dwc2_hsotg_tx_fifo_count(hsotg); 681 685 682 686 for (fifo = 1; fifo <= fifo_count; fifo++) { 683 687 hw->g_tx_fifo_size[fifo] = 684 - (dwc2_readl(hsotg->regs + DPTXFSIZN(fifo)) & 688 + (dwc2_readl(hsotg, DPTXFSIZN(fifo)) & 685 689 FIFOSIZE_DEPTH_MASK) >> FIFOSIZE_DEPTH_SHIFT; 686 690 } 687 691 ··· 709 713 * 0x45f4xxxx, 0x5531xxxx or 0x5532xxxx 710 714 */ 711 715 712 - hw->snpsid = dwc2_readl(hsotg->regs + GSNPSID); 716 + hw->snpsid = dwc2_readl(hsotg, GSNPSID); 713 717 if ((hw->snpsid & GSNPSID_ID_MASK) != DWC2_OTG_ID && 714 718 (hw->snpsid & GSNPSID_ID_MASK) != DWC2_FS_IOT_ID && 715 719 (hw->snpsid & GSNPSID_ID_MASK) != DWC2_HS_IOT_ID) { ··· 722 726 hw->snpsid >> 12 & 0xf, hw->snpsid >> 8 & 0xf, 723 727 hw->snpsid >> 4 & 0xf, hw->snpsid & 0xf, hw->snpsid); 724 728 725 - hwcfg1 = dwc2_readl(hsotg->regs + GHWCFG1); 726 - hwcfg2 = dwc2_readl(hsotg->regs + GHWCFG2); 727 - hwcfg3 = dwc2_readl(hsotg->regs + GHWCFG3); 728 - hwcfg4 = dwc2_readl(hsotg->regs + GHWCFG4); 729 - grxfsiz = dwc2_readl(hsotg->regs + GRXFSIZ); 729 + hwcfg1 = dwc2_readl(hsotg, GHWCFG1); 730 + hwcfg2 = dwc2_readl(hsotg, GHWCFG2); 731 + hwcfg3 = dwc2_readl(hsotg, GHWCFG3); 732 + hwcfg4 = dwc2_readl(hsotg, GHWCFG4); 733 + grxfsiz = dwc2_readl(hsotg, GRXFSIZ); 730 734 731 735 /* hwcfg1 */ 732 736 hw->dev_ep_dirs = hwcfg1;
+19
drivers/usb/dwc2/platform.c
··· 353 353 } 354 354 355 355 /** 356 + * dwc2_check_core_endianness() - Returns true if core and AHB have 357 + * opposite endianness. 358 + * @hsotg: Programming view of the DWC_otg controller. 359 + */ 360 + static bool dwc2_check_core_endianness(struct dwc2_hsotg *hsotg) 361 + { 362 + u32 snpsid; 363 + 364 + snpsid = ioread32(hsotg->regs + GSNPSID); 365 + if ((snpsid & GSNPSID_ID_MASK) == DWC2_OTG_ID || 366 + (snpsid & GSNPSID_ID_MASK) == DWC2_FS_IOT_ID || 367 + (snpsid & GSNPSID_ID_MASK) == DWC2_HS_IOT_ID) 368 + return false; 369 + return true; 370 + } 371 + 372 + /** 356 373 * dwc2_driver_probe() - Called when the DWC_otg core is bound to the DWC_otg 357 374 * driver 358 375 * ··· 411 394 412 395 dev_dbg(&dev->dev, "mapped PA %08lx to VA %p\n", 413 396 (unsigned long)res->start, hsotg->regs); 397 + 398 + hsotg->needs_byte_swap = dwc2_check_core_endianness(hsotg); 414 399 415 400 retval = dwc2_lowlevel_hw_init(hsotg); 416 401 if (retval)
+9 -4
drivers/usb/dwc3/Kconfig
··· 74 74 depends on USB_PCI && ACPI 75 75 default USB_DWC3 76 76 help 77 - If you're using the DesignWare Core IP with a PCIe, please say 78 - 'Y' or 'M' here. 77 + If you're using the DesignWare Core IP with a PCIe (but not HAPS 78 + platform), please say 'Y' or 'M' here. 79 79 80 - One such PCIe-based platform is Synopsys' PCIe HAPS model of 81 - this IP. 80 + config USB_DWC3_HAPS 81 + tristate "Synopsys PCIe-based HAPS Platforms" 82 + depends on USB_PCI 83 + default USB_DWC3 84 + help 85 + If you're using the DesignWare Core IP with a Synopsys PCIe HAPS 86 + platform, please say 'Y' or 'M' here. 82 87 83 88 config USB_DWC3_KEYSTONE 84 89 tristate "Texas Instruments Keystone2 Platforms"
+1
drivers/usb/dwc3/Makefile
··· 45 45 obj-$(CONFIG_USB_DWC3_OMAP) += dwc3-omap.o 46 46 obj-$(CONFIG_USB_DWC3_EXYNOS) += dwc3-exynos.o 47 47 obj-$(CONFIG_USB_DWC3_PCI) += dwc3-pci.o 48 + obj-$(CONFIG_USB_DWC3_HAPS) += dwc3-haps.o 48 49 obj-$(CONFIG_USB_DWC3_KEYSTONE) += dwc3-keystone.o 49 50 obj-$(CONFIG_USB_DWC3_OF_SIMPLE) += dwc3-of-simple.o 50 51 obj-$(CONFIG_USB_DWC3_ST) += dwc3-st.o
+118
drivers/usb/dwc3/core.c
··· 78 78 mode = USB_DR_MODE_HOST; 79 79 else if (IS_ENABLED(CONFIG_USB_DWC3_GADGET)) 80 80 mode = USB_DR_MODE_PERIPHERAL; 81 + 82 + /* 83 + * dwc_usb31 does not support OTG mode. If the controller 84 + * supports DRD but the dr_mode is not specified or set to OTG, 85 + * then set the mode to peripheral. 86 + */ 87 + if (mode == USB_DR_MODE_OTG && dwc3_is_usb31(dwc)) 88 + mode = USB_DR_MODE_PERIPHERAL; 81 89 } 82 90 83 91 if (mode != dwc->dr_mode) { ··· 786 778 static int dwc3_core_get_phy(struct dwc3 *dwc); 787 779 static int dwc3_core_ulpi_init(struct dwc3 *dwc); 788 780 781 + /* set global incr burst type configuration registers */ 782 + static void dwc3_set_incr_burst_type(struct dwc3 *dwc) 783 + { 784 + struct device *dev = dwc->dev; 785 + /* incrx_mode : for INCR burst type. */ 786 + bool incrx_mode; 787 + /* incrx_size : for size of INCRX burst. */ 788 + u32 incrx_size; 789 + u32 *vals; 790 + u32 cfg; 791 + int ntype; 792 + int ret; 793 + int i; 794 + 795 + cfg = dwc3_readl(dwc->regs, DWC3_GSBUSCFG0); 796 + 797 + /* 798 + * Handle property "snps,incr-burst-type-adjustment". 799 + * Get the number of value from this property: 800 + * result <= 0, means this property is not supported. 801 + * result = 1, means INCRx burst mode supported. 802 + * result > 1, means undefined length burst mode supported. 803 + */ 804 + ntype = device_property_read_u32_array(dev, 805 + "snps,incr-burst-type-adjustment", NULL, 0); 806 + if (ntype <= 0) 807 + return; 808 + 809 + vals = kcalloc(ntype, sizeof(u32), GFP_KERNEL); 810 + if (!vals) { 811 + dev_err(dev, "Error to get memory\n"); 812 + return; 813 + } 814 + 815 + /* Get INCR burst type, and parse it */ 816 + ret = device_property_read_u32_array(dev, 817 + "snps,incr-burst-type-adjustment", vals, ntype); 818 + if (ret) { 819 + dev_err(dev, "Error to get property\n"); 820 + return; 821 + } 822 + 823 + incrx_size = *vals; 824 + 825 + if (ntype > 1) { 826 + /* INCRX (undefined length) burst mode */ 827 + incrx_mode = INCRX_UNDEF_LENGTH_BURST_MODE; 828 + for (i = 1; i < ntype; i++) { 829 + if (vals[i] > incrx_size) 830 + incrx_size = vals[i]; 831 + } 832 + } else { 833 + /* INCRX burst mode */ 834 + incrx_mode = INCRX_BURST_MODE; 835 + } 836 + 837 + /* Enable Undefined Length INCR Burst and Enable INCRx Burst */ 838 + cfg &= ~DWC3_GSBUSCFG0_INCRBRST_MASK; 839 + if (incrx_mode) 840 + cfg |= DWC3_GSBUSCFG0_INCRBRSTENA; 841 + switch (incrx_size) { 842 + case 256: 843 + cfg |= DWC3_GSBUSCFG0_INCR256BRSTENA; 844 + break; 845 + case 128: 846 + cfg |= DWC3_GSBUSCFG0_INCR128BRSTENA; 847 + break; 848 + case 64: 849 + cfg |= DWC3_GSBUSCFG0_INCR64BRSTENA; 850 + break; 851 + case 32: 852 + cfg |= DWC3_GSBUSCFG0_INCR32BRSTENA; 853 + break; 854 + case 16: 855 + cfg |= DWC3_GSBUSCFG0_INCR16BRSTENA; 856 + break; 857 + case 8: 858 + cfg |= DWC3_GSBUSCFG0_INCR8BRSTENA; 859 + break; 860 + case 4: 861 + cfg |= DWC3_GSBUSCFG0_INCR4BRSTENA; 862 + break; 863 + case 1: 864 + break; 865 + default: 866 + dev_err(dev, "Invalid property\n"); 867 + break; 868 + } 869 + 870 + dwc3_writel(dwc->regs, DWC3_GSBUSCFG0, cfg); 871 + } 872 + 789 873 /** 790 874 * dwc3_core_init - Low-level initialization of DWC3 Core 791 875 * @dwc: Pointer to our controller context structure ··· 940 840 /* Adjust Frame Length */ 941 841 dwc3_frame_length_adjustment(dwc); 942 842 843 + dwc3_set_incr_burst_type(dwc); 844 + 943 845 usb_phy_set_suspend(dwc->usb2_phy, 0); 944 846 usb_phy_set_suspend(dwc->usb3_phy, 0); 945 847 ret = phy_power_on(dwc->usb2_generic_phy); ··· 983 881 reg |= DWC3_GUCTL1_TX_IPGAP_LINECHECK_DIS; 984 882 985 883 dwc3_writel(dwc->regs, DWC3_GUCTL1, reg); 884 + } 885 + 886 + if (dwc->dr_mode == USB_DR_MODE_HOST || 887 + dwc->dr_mode == USB_DR_MODE_OTG) { 888 + reg = dwc3_readl(dwc->regs, DWC3_GUCTL); 889 + 890 + /* 891 + * Enable Auto retry Feature to make the controller operating in 892 + * Host mode on seeing transaction errors(CRC errors or internal 893 + * overrun scenerios) on IN transfers to reply to the device 894 + * with a non-terminating retry ACK (i.e, an ACK transcation 895 + * packet with Retry=1 & Nump != 0) 896 + */ 897 + reg |= DWC3_GUCTL_HSTINAUTORETRY; 898 + 899 + dwc3_writel(dwc->regs, DWC3_GUCTL, reg); 986 900 } 987 901 988 902 /*
+17
drivers/usb/dwc3/core.h
··· 163 163 164 164 /* Bit fields */ 165 165 166 + /* Global SoC Bus Configuration INCRx Register 0 */ 167 + #define DWC3_GSBUSCFG0_INCR256BRSTENA (1 << 7) /* INCR256 burst */ 168 + #define DWC3_GSBUSCFG0_INCR128BRSTENA (1 << 6) /* INCR128 burst */ 169 + #define DWC3_GSBUSCFG0_INCR64BRSTENA (1 << 5) /* INCR64 burst */ 170 + #define DWC3_GSBUSCFG0_INCR32BRSTENA (1 << 4) /* INCR32 burst */ 171 + #define DWC3_GSBUSCFG0_INCR16BRSTENA (1 << 3) /* INCR16 burst */ 172 + #define DWC3_GSBUSCFG0_INCR8BRSTENA (1 << 2) /* INCR8 burst */ 173 + #define DWC3_GSBUSCFG0_INCR4BRSTENA (1 << 1) /* INCR4 burst */ 174 + #define DWC3_GSBUSCFG0_INCRBRSTENA (1 << 0) /* undefined length enable */ 175 + #define DWC3_GSBUSCFG0_INCRBRST_MASK 0xff 176 + 166 177 /* Global Debug Queue/FIFO Space Available Register */ 167 178 #define DWC3_GDBGFIFOSPACE_NUM(n) ((n) & 0x1f) 168 179 #define DWC3_GDBGFIFOSPACE_TYPE(n) (((n) << 5) & 0x1e0) ··· 237 226 #define DWC3_GCTL_U2EXIT_LFPS BIT(2) 238 227 #define DWC3_GCTL_GBLHIBERNATIONEN BIT(1) 239 228 #define DWC3_GCTL_DSBLCLKGTNG BIT(0) 229 + 230 + /* Global User Control Register */ 231 + #define DWC3_GUCTL_HSTINAUTORETRY BIT(14) 240 232 241 233 /* Global User Control 1 Register */ 242 234 #define DWC3_GUCTL1_TX_IPGAP_LINECHECK_DIS BIT(28) ··· 1170 1156 1171 1157 u16 imod_interval; 1172 1158 }; 1159 + 1160 + #define INCRX_BURST_MODE 0 1161 + #define INCRX_UNDEF_LENGTH_BURST_MODE 1 1173 1162 1174 1163 #define work_to_dwc(w) (container_of((w), struct dwc3, drd_work)) 1175 1164
+137
drivers/usb/dwc3/dwc3-haps.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /** 3 + * dwc3-haps.c - Synopsys HAPS PCI Specific glue layer 4 + * 5 + * Copyright (C) 2018 Synopsys, Inc. 6 + * 7 + * Authors: Thinh Nguyen <thinhn@synopsys.com>, 8 + * John Youn <johnyoun@synopsys.com> 9 + */ 10 + 11 + #include <linux/kernel.h> 12 + #include <linux/module.h> 13 + #include <linux/slab.h> 14 + #include <linux/pci.h> 15 + #include <linux/platform_device.h> 16 + #include <linux/property.h> 17 + 18 + #define PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3 0xabcd 19 + #define PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3_AXI 0xabce 20 + #define PCI_DEVICE_ID_SYNOPSYS_HAPSUSB31 0xabcf 21 + 22 + /** 23 + * struct dwc3_haps - Driver private structure 24 + * @dwc3: child dwc3 platform_device 25 + * @pci: our link to PCI bus 26 + */ 27 + struct dwc3_haps { 28 + struct platform_device *dwc3; 29 + struct pci_dev *pci; 30 + }; 31 + 32 + static const struct property_entry initial_properties[] = { 33 + PROPERTY_ENTRY_BOOL("snps,usb3_lpm_capable"), 34 + PROPERTY_ENTRY_BOOL("snps,has-lpm-erratum"), 35 + PROPERTY_ENTRY_BOOL("snps,dis_enblslpm_quirk"), 36 + PROPERTY_ENTRY_BOOL("linux,sysdev_is_parent"), 37 + { }, 38 + }; 39 + 40 + static int dwc3_haps_probe(struct pci_dev *pci, 41 + const struct pci_device_id *id) 42 + { 43 + struct dwc3_haps *dwc; 44 + struct device *dev = &pci->dev; 45 + struct resource res[2]; 46 + int ret; 47 + 48 + ret = pcim_enable_device(pci); 49 + if (ret) { 50 + dev_err(dev, "failed to enable pci device\n"); 51 + return -ENODEV; 52 + } 53 + 54 + pci_set_master(pci); 55 + 56 + dwc = devm_kzalloc(dev, sizeof(*dwc), GFP_KERNEL); 57 + if (!dwc) 58 + return -ENOMEM; 59 + 60 + dwc->dwc3 = platform_device_alloc("dwc3", PLATFORM_DEVID_AUTO); 61 + if (!dwc->dwc3) 62 + return -ENOMEM; 63 + 64 + memset(res, 0x00, sizeof(struct resource) * ARRAY_SIZE(res)); 65 + 66 + res[0].start = pci_resource_start(pci, 0); 67 + res[0].end = pci_resource_end(pci, 0); 68 + res[0].name = "dwc_usb3"; 69 + res[0].flags = IORESOURCE_MEM; 70 + 71 + res[1].start = pci->irq; 72 + res[1].name = "dwc_usb3"; 73 + res[1].flags = IORESOURCE_IRQ; 74 + 75 + ret = platform_device_add_resources(dwc->dwc3, res, ARRAY_SIZE(res)); 76 + if (ret) { 77 + dev_err(dev, "couldn't add resources to dwc3 device\n"); 78 + goto err; 79 + } 80 + 81 + dwc->pci = pci; 82 + dwc->dwc3->dev.parent = dev; 83 + 84 + ret = platform_device_add_properties(dwc->dwc3, initial_properties); 85 + if (ret) 86 + goto err; 87 + 88 + ret = platform_device_add(dwc->dwc3); 89 + if (ret) { 90 + dev_err(dev, "failed to register dwc3 device\n"); 91 + goto err; 92 + } 93 + 94 + pci_set_drvdata(pci, dwc); 95 + 96 + return 0; 97 + err: 98 + platform_device_put(dwc->dwc3); 99 + return ret; 100 + } 101 + 102 + static void dwc3_haps_remove(struct pci_dev *pci) 103 + { 104 + struct dwc3_haps *dwc = pci_get_drvdata(pci); 105 + 106 + platform_device_unregister(dwc->dwc3); 107 + } 108 + 109 + static const struct pci_device_id dwc3_haps_id_table[] = { 110 + { 111 + PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS, 112 + PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3), 113 + }, 114 + { 115 + PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS, 116 + PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3_AXI), 117 + }, 118 + { 119 + PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS, 120 + PCI_DEVICE_ID_SYNOPSYS_HAPSUSB31), 121 + }, 122 + { } /* Terminating Entry */ 123 + }; 124 + MODULE_DEVICE_TABLE(pci, dwc3_haps_id_table); 125 + 126 + static struct pci_driver dwc3_haps_driver = { 127 + .name = "dwc3-haps", 128 + .id_table = dwc3_haps_id_table, 129 + .probe = dwc3_haps_probe, 130 + .remove = dwc3_haps_remove, 131 + }; 132 + 133 + MODULE_AUTHOR("Thinh Nguyen <thinhn@synopsys.com>"); 134 + MODULE_LICENSE("GPL v2"); 135 + MODULE_DESCRIPTION("Synopsys HAPS PCI Glue Layer"); 136 + 137 + module_pci_driver(dwc3_haps_driver);
+29
drivers/usb/dwc3/dwc3-of-simple.c
··· 28 28 int num_clocks; 29 29 struct reset_control *resets; 30 30 bool pulse_resets; 31 + bool need_reset; 31 32 }; 32 33 33 34 static int dwc3_of_simple_clk_init(struct dwc3_of_simple *simple, int count) ··· 93 92 94 93 platform_set_drvdata(pdev, simple); 95 94 simple->dev = dev; 95 + 96 + /* 97 + * Some controllers need to toggle the usb3-otg reset before trying to 98 + * initialize the PHY, otherwise the PHY times out. 99 + */ 100 + if (of_device_is_compatible(np, "rockchip,rk3399-dwc3")) 101 + simple->need_reset = true; 96 102 97 103 if (of_device_is_compatible(np, "amlogic,meson-axg-dwc3") || 98 104 of_device_is_compatible(np, "amlogic,meson-gxl-dwc3")) { ··· 209 201 210 202 return 0; 211 203 } 204 + 205 + static int dwc3_of_simple_suspend(struct device *dev) 206 + { 207 + struct dwc3_of_simple *simple = dev_get_drvdata(dev); 208 + 209 + if (simple->need_reset) 210 + reset_control_assert(simple->resets); 211 + 212 + return 0; 213 + } 214 + 215 + static int dwc3_of_simple_resume(struct device *dev) 216 + { 217 + struct dwc3_of_simple *simple = dev_get_drvdata(dev); 218 + 219 + if (simple->need_reset) 220 + reset_control_deassert(simple->resets); 221 + 222 + return 0; 223 + } 212 224 #endif 213 225 214 226 static const struct dev_pm_ops dwc3_of_simple_dev_pm_ops = { 227 + SET_SYSTEM_SLEEP_PM_OPS(dwc3_of_simple_suspend, dwc3_of_simple_resume) 215 228 SET_RUNTIME_PM_OPS(dwc3_of_simple_runtime_suspend, 216 229 dwc3_of_simple_runtime_resume, NULL) 217 230 };
+134 -91
drivers/usb/dwc3/dwc3-pci.c
··· 16 16 #include <linux/pm_runtime.h> 17 17 #include <linux/platform_device.h> 18 18 #include <linux/gpio/consumer.h> 19 + #include <linux/gpio/machine.h> 19 20 #include <linux/acpi.h> 20 21 #include <linux/delay.h> 21 22 22 - #define PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3 0xabcd 23 - #define PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3_AXI 0xabce 24 - #define PCI_DEVICE_ID_SYNOPSYS_HAPSUSB31 0xabcf 25 23 #define PCI_DEVICE_ID_INTEL_BYT 0x0f37 26 24 #define PCI_DEVICE_ID_INTEL_MRFLD 0x119e 27 25 #define PCI_DEVICE_ID_INTEL_BSW 0x22b7 ··· 39 41 #define PCI_INTEL_BXT_STATE_D0 0 40 42 #define PCI_INTEL_BXT_STATE_D3 3 41 43 44 + #define GP_RWBAR 1 45 + #define GP_RWREG1 0xa0 46 + #define GP_RWREG1_ULPI_REFCLK_DISABLE (1 << 17) 47 + 42 48 /** 43 49 * struct dwc3_pci - Driver private structure 44 50 * @dwc3: child dwc3 platform_device 45 51 * @pci: our link to PCI bus 46 52 * @guid: _DSM GUID 47 53 * @has_dsm_for_pm: true for devices which need to run _DSM on runtime PM 54 + * @wakeup_work: work for asynchronous resume 48 55 */ 49 56 struct dwc3_pci { 50 57 struct platform_device *dwc3; ··· 70 67 { }, 71 68 }; 72 69 70 + static struct gpiod_lookup_table platform_bytcr_gpios = { 71 + .dev_id = "0000:00:16.0", 72 + .table = { 73 + GPIO_LOOKUP("INT33FC:00", 54, "reset", GPIO_ACTIVE_HIGH), 74 + GPIO_LOOKUP("INT33FC:02", 14, "cs", GPIO_ACTIVE_HIGH), 75 + {} 76 + }, 77 + }; 78 + 79 + static int dwc3_byt_enable_ulpi_refclock(struct pci_dev *pci) 80 + { 81 + void __iomem *reg; 82 + u32 value; 83 + 84 + reg = pcim_iomap(pci, GP_RWBAR, 0); 85 + if (IS_ERR(reg)) 86 + return PTR_ERR(reg); 87 + 88 + value = readl(reg + GP_RWREG1); 89 + if (!(value & GP_RWREG1_ULPI_REFCLK_DISABLE)) 90 + goto unmap; /* ULPI refclk already enabled */ 91 + 92 + value &= ~GP_RWREG1_ULPI_REFCLK_DISABLE; 93 + writel(value, reg + GP_RWREG1); 94 + /* This comes from the Intel Android x86 tree w/o any explanation */ 95 + msleep(100); 96 + unmap: 97 + pcim_iounmap(pci, reg); 98 + return 0; 99 + } 100 + 101 + static const struct property_entry dwc3_pci_intel_properties[] = { 102 + PROPERTY_ENTRY_STRING("dr_mode", "peripheral"), 103 + PROPERTY_ENTRY_BOOL("linux,sysdev_is_parent"), 104 + {} 105 + }; 106 + 107 + static const struct property_entry dwc3_pci_mrfld_properties[] = { 108 + PROPERTY_ENTRY_STRING("dr_mode", "otg"), 109 + PROPERTY_ENTRY_BOOL("linux,sysdev_is_parent"), 110 + {} 111 + }; 112 + 113 + static const struct property_entry dwc3_pci_amd_properties[] = { 114 + PROPERTY_ENTRY_BOOL("snps,has-lpm-erratum"), 115 + PROPERTY_ENTRY_U8("snps,lpm-nyet-threshold", 0xf), 116 + PROPERTY_ENTRY_BOOL("snps,u2exit_lfps_quirk"), 117 + PROPERTY_ENTRY_BOOL("snps,u2ss_inp3_quirk"), 118 + PROPERTY_ENTRY_BOOL("snps,req_p1p2p3_quirk"), 119 + PROPERTY_ENTRY_BOOL("snps,del_p1p2p3_quirk"), 120 + PROPERTY_ENTRY_BOOL("snps,del_phy_power_chg_quirk"), 121 + PROPERTY_ENTRY_BOOL("snps,lfps_filter_quirk"), 122 + PROPERTY_ENTRY_BOOL("snps,rx_detect_poll_quirk"), 123 + PROPERTY_ENTRY_BOOL("snps,tx_de_emphasis_quirk"), 124 + PROPERTY_ENTRY_U8("snps,tx_de_emphasis", 1), 125 + /* FIXME these quirks should be removed when AMD NL tapes out */ 126 + PROPERTY_ENTRY_BOOL("snps,disable_scramble_quirk"), 127 + PROPERTY_ENTRY_BOOL("snps,dis_u3_susphy_quirk"), 128 + PROPERTY_ENTRY_BOOL("snps,dis_u2_susphy_quirk"), 129 + PROPERTY_ENTRY_BOOL("linux,sysdev_is_parent"), 130 + {} 131 + }; 132 + 73 133 static int dwc3_pci_quirks(struct dwc3_pci *dwc) 74 134 { 75 - struct platform_device *dwc3 = dwc->dwc3; 76 135 struct pci_dev *pdev = dwc->pci; 77 136 78 - if (pdev->vendor == PCI_VENDOR_ID_AMD && 79 - pdev->device == PCI_DEVICE_ID_AMD_NL_USB) { 80 - struct property_entry properties[] = { 81 - PROPERTY_ENTRY_BOOL("snps,has-lpm-erratum"), 82 - PROPERTY_ENTRY_U8("snps,lpm-nyet-threshold", 0xf), 83 - PROPERTY_ENTRY_BOOL("snps,u2exit_lfps_quirk"), 84 - PROPERTY_ENTRY_BOOL("snps,u2ss_inp3_quirk"), 85 - PROPERTY_ENTRY_BOOL("snps,req_p1p2p3_quirk"), 86 - PROPERTY_ENTRY_BOOL("snps,del_p1p2p3_quirk"), 87 - PROPERTY_ENTRY_BOOL("snps,del_phy_power_chg_quirk"), 88 - PROPERTY_ENTRY_BOOL("snps,lfps_filter_quirk"), 89 - PROPERTY_ENTRY_BOOL("snps,rx_detect_poll_quirk"), 90 - PROPERTY_ENTRY_BOOL("snps,tx_de_emphasis_quirk"), 91 - PROPERTY_ENTRY_U8("snps,tx_de_emphasis", 1), 92 - /* 93 - * FIXME these quirks should be removed when AMD NL 94 - * tapes out 95 - */ 96 - PROPERTY_ENTRY_BOOL("snps,disable_scramble_quirk"), 97 - PROPERTY_ENTRY_BOOL("snps,dis_u3_susphy_quirk"), 98 - PROPERTY_ENTRY_BOOL("snps,dis_u2_susphy_quirk"), 99 - PROPERTY_ENTRY_BOOL("linux,sysdev_is_parent"), 100 - { }, 101 - }; 102 - 103 - return platform_device_add_properties(dwc3, properties); 104 - } 105 - 106 137 if (pdev->vendor == PCI_VENDOR_ID_INTEL) { 107 - int ret; 108 - 109 - struct property_entry properties[] = { 110 - PROPERTY_ENTRY_STRING("dr_mode", "peripheral"), 111 - PROPERTY_ENTRY_BOOL("linux,sysdev_is_parent"), 112 - { } 113 - }; 114 - 115 - ret = platform_device_add_properties(dwc3, properties); 116 - if (ret < 0) 117 - return ret; 118 - 119 138 if (pdev->device == PCI_DEVICE_ID_INTEL_BXT || 120 139 pdev->device == PCI_DEVICE_ID_INTEL_BXT_M) { 121 140 guid_parse(PCI_INTEL_BXT_DSM_GUID, &dwc->guid); ··· 146 121 147 122 if (pdev->device == PCI_DEVICE_ID_INTEL_BYT) { 148 123 struct gpio_desc *gpio; 124 + int ret; 125 + 126 + /* On BYT the FW does not always enable the refclock */ 127 + ret = dwc3_byt_enable_ulpi_refclock(pdev); 128 + if (ret) 129 + return ret; 149 130 150 131 ret = devm_acpi_dev_add_driver_gpios(&pdev->dev, 151 132 acpi_dwc3_byt_gpios); ··· 159 128 dev_dbg(&pdev->dev, "failed to add mapping table\n"); 160 129 161 130 /* 131 + * A lot of BYT devices lack ACPI resource entries for 132 + * the GPIOs, add a fallback mapping to the reference 133 + * design GPIOs which all boards seem to use. 134 + */ 135 + gpiod_add_lookup_table(&platform_bytcr_gpios); 136 + 137 + /* 162 138 * These GPIOs will turn on the USB2 PHY. Note that we have to 163 139 * put the gpio descriptors again here because the phy driver 164 140 * might want to grab them, too. 165 141 */ 166 - gpio = gpiod_get_optional(&pdev->dev, "cs", GPIOD_OUT_LOW); 142 + gpio = devm_gpiod_get_optional(&pdev->dev, "cs", 143 + GPIOD_OUT_LOW); 167 144 if (IS_ERR(gpio)) 168 145 return PTR_ERR(gpio); 169 146 170 147 gpiod_set_value_cansleep(gpio, 1); 171 - gpiod_put(gpio); 172 148 173 - gpio = gpiod_get_optional(&pdev->dev, "reset", GPIOD_OUT_LOW); 149 + gpio = devm_gpiod_get_optional(&pdev->dev, "reset", 150 + GPIOD_OUT_LOW); 174 151 if (IS_ERR(gpio)) 175 152 return PTR_ERR(gpio); 176 153 177 154 if (gpio) { 178 155 gpiod_set_value_cansleep(gpio, 1); 179 - gpiod_put(gpio); 180 156 usleep_range(10000, 11000); 181 157 } 182 158 } 183 - } 184 - 185 - if (pdev->vendor == PCI_VENDOR_ID_SYNOPSYS && 186 - (pdev->device == PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3 || 187 - pdev->device == PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3_AXI || 188 - pdev->device == PCI_DEVICE_ID_SYNOPSYS_HAPSUSB31)) { 189 - struct property_entry properties[] = { 190 - PROPERTY_ENTRY_BOOL("snps,usb3_lpm_capable"), 191 - PROPERTY_ENTRY_BOOL("snps,has-lpm-erratum"), 192 - PROPERTY_ENTRY_BOOL("snps,dis_enblslpm_quirk"), 193 - PROPERTY_ENTRY_BOOL("linux,sysdev_is_parent"), 194 - { }, 195 - }; 196 - 197 - return platform_device_add_properties(dwc3, properties); 198 159 } 199 160 200 161 return 0; ··· 208 185 } 209 186 #endif 210 187 211 - static int dwc3_pci_probe(struct pci_dev *pci, 212 - const struct pci_device_id *id) 188 + static int dwc3_pci_probe(struct pci_dev *pci, const struct pci_device_id *id) 213 189 { 190 + struct property_entry *p = (struct property_entry *)id->driver_data; 214 191 struct dwc3_pci *dwc; 215 192 struct resource res[2]; 216 193 int ret; ··· 253 230 dwc->dwc3->dev.parent = dev; 254 231 ACPI_COMPANION_SET(&dwc->dwc3->dev, ACPI_COMPANION(dev)); 255 232 233 + ret = platform_device_add_properties(dwc->dwc3, p); 234 + if (ret < 0) 235 + return ret; 236 + 256 237 ret = dwc3_pci_quirks(dwc); 257 238 if (ret) 258 239 goto err; ··· 284 257 { 285 258 struct dwc3_pci *dwc = pci_get_drvdata(pci); 286 259 260 + gpiod_remove_lookup_table(&platform_bytcr_gpios); 287 261 #ifdef CONFIG_PM 288 262 cancel_work_sync(&dwc->wakeup_work); 289 263 #endif ··· 294 266 } 295 267 296 268 static const struct pci_device_id dwc3_pci_id_table[] = { 297 - { 298 - PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS, 299 - PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3), 300 - }, 301 - { 302 - PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS, 303 - PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3_AXI), 304 - }, 305 - { 306 - PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS, 307 - PCI_DEVICE_ID_SYNOPSYS_HAPSUSB31), 308 - }, 309 - { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BSW), }, 310 - { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BYT), }, 311 - { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_MRFLD), }, 312 - { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SPTLP), }, 313 - { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SPTH), }, 314 - { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BXT), }, 315 - { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BXT_M), }, 316 - { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_APL), }, 317 - { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_KBP), }, 318 - { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_GLK), }, 319 - { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_CNPLP), }, 320 - { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_CNPH), }, 321 - { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICLLP), }, 322 - { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_NL_USB), }, 269 + { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_BSW), 270 + (kernel_ulong_t) &dwc3_pci_intel_properties }, 271 + 272 + { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_BYT), 273 + (kernel_ulong_t) &dwc3_pci_intel_properties, }, 274 + 275 + { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_MRFLD), 276 + (kernel_ulong_t) &dwc3_pci_mrfld_properties, }, 277 + 278 + { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_SPTLP), 279 + (kernel_ulong_t) &dwc3_pci_intel_properties, }, 280 + 281 + { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_SPTH), 282 + (kernel_ulong_t) &dwc3_pci_intel_properties, }, 283 + 284 + { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_BXT), 285 + (kernel_ulong_t) &dwc3_pci_intel_properties, }, 286 + 287 + { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_BXT_M), 288 + (kernel_ulong_t) &dwc3_pci_intel_properties, }, 289 + 290 + { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_APL), 291 + (kernel_ulong_t) &dwc3_pci_intel_properties, }, 292 + 293 + { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_KBP), 294 + (kernel_ulong_t) &dwc3_pci_intel_properties, }, 295 + 296 + { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_GLK), 297 + (kernel_ulong_t) &dwc3_pci_intel_properties, }, 298 + 299 + { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_CNPLP), 300 + (kernel_ulong_t) &dwc3_pci_intel_properties, }, 301 + 302 + { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_CNPH), 303 + (kernel_ulong_t) &dwc3_pci_intel_properties, }, 304 + 305 + { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_ICLLP), 306 + (kernel_ulong_t) &dwc3_pci_intel_properties, }, 307 + 308 + { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_NL_USB), 309 + (kernel_ulong_t) &dwc3_pci_amd_properties, }, 323 310 { } /* Terminating Entry */ 324 311 }; 325 312 MODULE_DEVICE_TABLE(pci, dwc3_pci_id_table);
+1 -1
drivers/usb/dwc3/gadget.c
··· 1121 1121 req->request.short_not_ok, 1122 1122 req->request.no_interrupt); 1123 1123 } else if (req->request.zero && req->request.length && 1124 - (IS_ALIGNED(req->request.length,dep->endpoint.maxpacket))) { 1124 + (IS_ALIGNED(req->request.length, maxp))) { 1125 1125 struct dwc3 *dwc = dep->dwc; 1126 1126 struct dwc3_trb *trb; 1127 1127
+1 -1
drivers/usb/dwc3/gadget.h
··· 25 25 #define DWC3_DEPCFG_XFER_IN_PROGRESS_EN BIT(9) 26 26 #define DWC3_DEPCFG_XFER_NOT_READY_EN BIT(10) 27 27 #define DWC3_DEPCFG_FIFO_ERROR_EN BIT(11) 28 - #define DWC3_DEPCFG_STREAM_EVENT_EN BIT(12) 28 + #define DWC3_DEPCFG_STREAM_EVENT_EN BIT(13) 29 29 #define DWC3_DEPCFG_BINTERVAL_M1(n) (((n) & 0xff) << 16) 30 30 #define DWC3_DEPCFG_STREAM_CAPABLE BIT(24) 31 31 #define DWC3_DEPCFG_EP_NUMBER(n) (((n) & 0x1f) << 25)
+2 -2
drivers/usb/gadget/configfs.c
··· 1217 1217 list_move_tail(&f->list, &cfg->func_list); 1218 1218 if (f->unbind) { 1219 1219 dev_dbg(&gi->cdev.gadget->dev, 1220 - "unbind function '%s'/%p\n", 1221 - f->name, f); 1220 + "unbind function '%s'/%p\n", 1221 + f->name, f); 1222 1222 f->unbind(c, f); 1223 1223 } 1224 1224 }
+8 -23
drivers/usb/gadget/function/f_mass_storage.c
··· 206 206 #include <linux/fcntl.h> 207 207 #include <linux/file.h> 208 208 #include <linux/fs.h> 209 - #include <linux/kref.h> 210 209 #include <linux/kthread.h> 211 210 #include <linux/sched/signal.h> 212 211 #include <linux/limits.h> ··· 311 312 void *private_data; 312 313 313 314 char inquiry_string[INQUIRY_STRING_LEN]; 314 - 315 - struct kref ref; 316 315 }; 317 316 318 317 struct fsg_dev { ··· 2548 2551 2549 2552 /****************************** FSG COMMON ******************************/ 2550 2553 2551 - static void fsg_common_release(struct kref *ref); 2552 - 2553 2554 static void fsg_lun_release(struct device *dev) 2554 2555 { 2555 2556 /* Nothing needs to be done */ 2556 2557 } 2557 - 2558 - void fsg_common_get(struct fsg_common *common) 2559 - { 2560 - kref_get(&common->ref); 2561 - } 2562 - EXPORT_SYMBOL_GPL(fsg_common_get); 2563 - 2564 - void fsg_common_put(struct fsg_common *common) 2565 - { 2566 - kref_put(&common->ref, fsg_common_release); 2567 - } 2568 - EXPORT_SYMBOL_GPL(fsg_common_put); 2569 2558 2570 2559 static struct fsg_common *fsg_common_setup(struct fsg_common *common) 2571 2560 { ··· 2565 2582 } 2566 2583 init_rwsem(&common->filesem); 2567 2584 spin_lock_init(&common->lock); 2568 - kref_init(&common->ref); 2569 2585 init_completion(&common->thread_notifier); 2570 2586 init_waitqueue_head(&common->io_wait); 2571 2587 init_waitqueue_head(&common->fsg_wait); ··· 2852 2870 } 2853 2871 EXPORT_SYMBOL_GPL(fsg_common_set_inquiry_string); 2854 2872 2855 - static void fsg_common_release(struct kref *ref) 2873 + static void fsg_common_release(struct fsg_common *common) 2856 2874 { 2857 - struct fsg_common *common = container_of(ref, struct fsg_common, ref); 2858 2875 int i; 2859 2876 2860 2877 /* If the thread isn't already dead, tell it to exit now */ ··· 3289 3308 if (ret) 3290 3309 goto end; 3291 3310 3292 - fsg_common_set_num_buffers(opts->common, num); 3311 + ret = fsg_common_set_num_buffers(opts->common, num); 3312 + if (ret) 3313 + goto end; 3293 3314 ret = len; 3294 3315 3295 3316 end: ··· 3327 3344 struct fsg_opts *opts; 3328 3345 3329 3346 opts = fsg_opts_from_func_inst(fi); 3330 - fsg_common_put(opts->common); 3347 + fsg_common_release(opts->common); 3331 3348 kfree(opts); 3332 3349 } 3333 3350 ··· 3351 3368 rc = fsg_common_set_num_buffers(opts->common, 3352 3369 CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS); 3353 3370 if (rc) 3354 - goto release_opts; 3371 + goto release_common; 3355 3372 3356 3373 pr_info(FSG_DRIVER_DESC ", version: " FSG_DRIVER_VERSION "\n"); 3357 3374 ··· 3374 3391 3375 3392 release_buffers: 3376 3393 fsg_common_free_buffers(opts->common); 3394 + release_common: 3395 + kfree(opts->common); 3377 3396 release_opts: 3378 3397 kfree(opts); 3379 3398 return ERR_PTR(rc);
-4
drivers/usb/gadget/function/f_mass_storage.h
··· 115 115 return container_of(fi, struct fsg_opts, func_inst); 116 116 } 117 117 118 - void fsg_common_get(struct fsg_common *common); 119 - 120 - void fsg_common_put(struct fsg_common *common); 121 - 122 118 void fsg_common_set_sysfs(struct fsg_common *common, bool sysfs); 123 119 124 120 int fsg_common_set_num_buffers(struct fsg_common *common, unsigned int n);
+28 -3
drivers/usb/gadget/function/f_uvc.c
··· 6 6 * Laurent Pinchart (laurent.pinchart@ideasonboard.com) 7 7 */ 8 8 9 - #include <linux/kernel.h> 10 - #include <linux/module.h> 11 9 #include <linux/device.h> 12 10 #include <linux/errno.h> 13 11 #include <linux/fs.h> 12 + #include <linux/kernel.h> 14 13 #include <linux/list.h> 14 + #include <linux/module.h> 15 15 #include <linux/mutex.h> 16 16 #include <linux/string.h> 17 17 #include <linux/usb/ch9.h> 18 18 #include <linux/usb/gadget.h> 19 + #include <linux/usb/g_uvc.h> 19 20 #include <linux/usb/video.h> 20 21 #include <linux/vmalloc.h> 21 22 #include <linux/wait.h> ··· 31 30 #include "uvc_video.h" 32 31 33 32 unsigned int uvc_gadget_trace_param; 33 + module_param_named(trace, uvc_gadget_trace_param, uint, 0644); 34 + MODULE_PARM_DESC(trace, "Trace level bitmask"); 34 35 35 36 /* -------------------------------------------------------------------------- 36 37 * Function descriptors ··· 413 410 * USB probe and disconnect 414 411 */ 415 412 413 + static ssize_t function_name_show(struct device *dev, 414 + struct device_attribute *attr, char *buf) 415 + { 416 + struct uvc_device *uvc = dev_get_drvdata(dev); 417 + 418 + return sprintf(buf, "%s\n", uvc->func.fi->group.cg_item.ci_name); 419 + } 420 + 421 + static DEVICE_ATTR_RO(function_name); 422 + 416 423 static int 417 424 uvc_register_video(struct uvc_device *uvc) 418 425 { 419 426 struct usb_composite_dev *cdev = uvc->func.config->cdev; 427 + int ret; 420 428 421 429 /* TODO reference counting. */ 422 430 uvc->vdev.v4l2_dev = &uvc->v4l2_dev; ··· 440 426 441 427 video_set_drvdata(&uvc->vdev, uvc); 442 428 443 - return video_register_device(&uvc->vdev, VFL_TYPE_GRABBER, -1); 429 + ret = video_register_device(&uvc->vdev, VFL_TYPE_GRABBER, -1); 430 + if (ret < 0) 431 + return ret; 432 + 433 + ret = device_create_file(&uvc->vdev.dev, &dev_attr_function_name); 434 + if (ret < 0) { 435 + video_unregister_device(&uvc->vdev); 436 + return ret; 437 + } 438 + 439 + return 0; 444 440 } 445 441 446 442 #define UVC_COPY_DESCRIPTOR(mem, dst, desc) \ ··· 888 864 889 865 INFO(cdev, "%s\n", __func__); 890 866 867 + device_remove_file(&uvc->vdev.dev, &dev_attr_function_name); 891 868 video_unregister_device(&uvc->vdev); 892 869 v4l2_device_unregister(&uvc->v4l2_dev); 893 870
+1 -5
drivers/usb/gadget/function/f_uvc.h
··· 9 9 #ifndef _F_UVC_H_ 10 10 #define _F_UVC_H_ 11 11 12 - #include <linux/usb/composite.h> 13 - #include <linux/usb/video.h> 14 - 15 - #include "uvc.h" 12 + struct uvc_device; 16 13 17 14 void uvc_function_setup_continue(struct uvc_device *uvc); 18 15 ··· 18 21 void uvc_function_disconnect(struct uvc_device *uvc); 19 22 20 23 #endif /* _F_UVC_H_ */ 21 -
+1 -4
drivers/usb/gadget/function/u_uvc.h
··· 13 13 #ifndef U_UVC_H 14 14 #define U_UVC_H 15 15 16 + #include <linux/mutex.h> 16 17 #include <linux/usb/composite.h> 17 18 #include <linux/usb/video.h> 18 19 ··· 21 20 22 21 struct f_uvc_opts { 23 22 struct usb_function_instance func_inst; 24 - unsigned int uvc_gadget_trace_param; 25 23 unsigned int streaming_interval; 26 24 unsigned int streaming_maxpacket; 27 25 unsigned int streaming_maxburst; ··· 80 80 int refcnt; 81 81 }; 82 82 83 - void uvc_set_trace_param(unsigned int trace); 84 - 85 83 #endif /* U_UVC_H */ 86 -
+12 -41
drivers/usb/gadget/function/uvc.h
··· 9 9 #ifndef _UVC_GADGET_H_ 10 10 #define _UVC_GADGET_H_ 11 11 12 - #include <linux/ioctl.h> 13 - #include <linux/types.h> 14 - #include <linux/usb/ch9.h> 12 + #include <linux/list.h> 13 + #include <linux/mutex.h> 14 + #include <linux/spinlock.h> 15 + #include <linux/usb/composite.h> 16 + #include <linux/videodev2.h> 15 17 16 - #define UVC_EVENT_FIRST (V4L2_EVENT_PRIVATE_START + 0) 17 - #define UVC_EVENT_CONNECT (V4L2_EVENT_PRIVATE_START + 0) 18 - #define UVC_EVENT_DISCONNECT (V4L2_EVENT_PRIVATE_START + 1) 19 - #define UVC_EVENT_STREAMON (V4L2_EVENT_PRIVATE_START + 2) 20 - #define UVC_EVENT_STREAMOFF (V4L2_EVENT_PRIVATE_START + 3) 21 - #define UVC_EVENT_SETUP (V4L2_EVENT_PRIVATE_START + 4) 22 - #define UVC_EVENT_DATA (V4L2_EVENT_PRIVATE_START + 5) 23 - #define UVC_EVENT_LAST (V4L2_EVENT_PRIVATE_START + 5) 18 + #include <media/v4l2-device.h> 19 + #include <media/v4l2-dev.h> 20 + #include <media/v4l2-fh.h> 24 21 25 - struct uvc_request_data { 26 - __s32 length; 27 - __u8 data[60]; 28 - }; 22 + #include "uvc_queue.h" 29 23 30 - struct uvc_event { 31 - union { 32 - enum usb_device_speed speed; 33 - struct usb_ctrlrequest req; 34 - struct uvc_request_data data; 35 - }; 36 - }; 37 - 38 - #define UVCIOC_SEND_RESPONSE _IOW('U', 1, struct uvc_request_data) 39 - 40 - #define UVC_INTF_CONTROL 0 41 - #define UVC_INTF_STREAMING 1 24 + struct usb_ep; 25 + struct usb_request; 26 + struct uvc_descriptor_header; 42 27 43 28 /* ------------------------------------------------------------------------ 44 29 * Debugging, printing and logging 45 30 */ 46 - 47 - #ifdef __KERNEL__ 48 - 49 - #include <linux/usb.h> /* For usb_endpoint_* */ 50 - #include <linux/usb/composite.h> 51 - #include <linux/usb/gadget.h> 52 - #include <linux/videodev2.h> 53 - #include <media/v4l2-fh.h> 54 - #include <media/v4l2-device.h> 55 - 56 - #include "uvc_queue.h" 57 31 58 32 #define UVC_TRACE_PROBE (1 << 0) 59 33 #define UVC_TRACE_DESCR (1 << 1) ··· 158 184 extern void uvc_function_connect(struct uvc_device *uvc); 159 185 extern void uvc_function_disconnect(struct uvc_device *uvc); 160 186 161 - #endif /* __KERNEL__ */ 162 - 163 187 #endif /* _UVC_GADGET_H_ */ 164 -
+5 -7
drivers/usb/gadget/function/uvc_configfs.c
··· 31 31 .show = prefix##cname##_show, \ 32 32 } 33 33 34 - static inline struct f_uvc_opts *to_f_uvc_opts(struct config_item *item); 34 + static inline struct f_uvc_opts *to_f_uvc_opts(struct config_item *item) 35 + { 36 + return container_of(to_config_group(item), struct f_uvc_opts, 37 + func_inst.group); 38 + } 35 39 36 40 /* control/header/<NAME> */ 37 41 DECLARE_UVC_HEADER_DESCRIPTOR(1); ··· 2108 2104 static const struct config_item_type uvcg_streaming_grp_type = { 2109 2105 .ct_owner = THIS_MODULE, 2110 2106 }; 2111 - 2112 - static inline struct f_uvc_opts *to_f_uvc_opts(struct config_item *item) 2113 - { 2114 - return container_of(to_config_group(item), struct f_uvc_opts, 2115 - func_inst.group); 2116 - } 2117 2107 2118 2108 static void uvc_attr_release(struct config_item *item) 2119 2109 {
+6 -6
drivers/usb/gadget/function/uvc_queue.h
··· 2 2 #ifndef _UVC_QUEUE_H_ 3 3 #define _UVC_QUEUE_H_ 4 4 5 - #ifdef __KERNEL__ 6 - 7 - #include <linux/kernel.h> 5 + #include <linux/list.h> 8 6 #include <linux/poll.h> 9 - #include <linux/videodev2.h> 7 + #include <linux/spinlock.h> 8 + 10 9 #include <media/videobuf2-v4l2.h> 10 + 11 + struct file; 12 + struct mutex; 11 13 12 14 /* Maximum frame size in bytes, for sanity checking. */ 13 15 #define UVC_MAX_FRAME_SIZE (16*1024*1024) ··· 92 90 struct uvc_buffer *buf); 93 91 94 92 struct uvc_buffer *uvcg_queue_head(struct uvc_video_queue *queue); 95 - 96 - #endif /* __KERNEL__ */ 97 93 98 94 #endif /* _UVC_QUEUE_H_ */ 99 95
+2 -1
drivers/usb/gadget/function/uvc_v4l2.c
··· 6 6 * Laurent Pinchart (laurent.pinchart@ideasonboard.com) 7 7 */ 8 8 9 - #include <linux/kernel.h> 10 9 #include <linux/device.h> 11 10 #include <linux/errno.h> 11 + #include <linux/kernel.h> 12 12 #include <linux/list.h> 13 + #include <linux/usb/g_uvc.h> 13 14 #include <linux/videodev2.h> 14 15 #include <linux/vmalloc.h> 15 16 #include <linux/wait.h>
+2
drivers/usb/gadget/function/uvc_video.h
··· 12 12 #ifndef __UVC_VIDEO_H__ 13 13 #define __UVC_VIDEO_H__ 14 14 15 + struct uvc_video; 16 + 15 17 int uvcg_video_pump(struct uvc_video *video); 16 18 17 19 int uvcg_video_enable(struct uvc_video *video, int enable);
+1 -1
drivers/usb/gadget/legacy/tcm_usb_gadget.c
··· 41 41 #define USB_G_STR_CONFIG USB_GADGET_FIRST_AVAIL_IDX 42 42 43 43 static struct usb_string usbg_us_strings[] = { 44 - [USB_GADGET_MANUFACTURER_IDX].s = "Target Manufactor", 44 + [USB_GADGET_MANUFACTURER_IDX].s = "Target Manufacturer", 45 45 [USB_GADGET_PRODUCT_IDX].s = "Target Product", 46 46 [USB_GADGET_SERIAL_IDX].s = "000000000001", 47 47 [USB_G_STR_CONFIG].s = "default config",
-4
drivers/usb/gadget/legacy/webcam.c
··· 30 30 module_param(streaming_maxburst, uint, S_IRUGO|S_IWUSR); 31 31 MODULE_PARM_DESC(streaming_maxburst, "0 - 15 (ss only)"); 32 32 33 - static unsigned int trace; 34 - module_param(trace, uint, S_IRUGO|S_IWUSR); 35 - MODULE_PARM_DESC(trace, "Trace level bitmask"); 36 33 /* -------------------------------------------------------------------------- 37 34 * Device descriptor 38 35 */ ··· 376 379 uvc_opts->streaming_interval = streaming_interval; 377 380 uvc_opts->streaming_maxpacket = streaming_maxpacket; 378 381 uvc_opts->streaming_maxburst = streaming_maxburst; 379 - uvc_set_trace_param(trace); 380 382 381 383 uvc_opts->fs_control = uvc_fs_control_cls; 382 384 uvc_opts->ss_control = uvc_ss_control_cls;
+1
drivers/usb/gadget/udc/Kconfig
··· 193 193 tristate 'Renesas USB3.0 Peripheral controller' 194 194 depends on ARCH_RENESAS || COMPILE_TEST 195 195 depends on EXTCON 196 + select USB_ROLE_SWITCH 196 197 help 197 198 Renesas USB3.0 Peripheral controller is a USB peripheral controller 198 199 that supports super, high, and full speed USB 3.0 data transfers.
+18
drivers/usb/gadget/udc/core.c
··· 87 87 * configurable, with more generic names like "ep-a". (remember that for 88 88 * USB, "in" means "towards the USB master".) 89 89 * 90 + * This routine must be called in process context. 91 + * 90 92 * returns zero, or a negative error code. 91 93 */ 92 94 int usb_ep_enable(struct usb_ep *ep) ··· 120 118 * indicating disconnect (-ESHUTDOWN) before this call returns. 121 119 * gadget drivers must call usb_ep_enable() again before queueing 122 120 * requests to the endpoint. 121 + * 122 + * This routine must be called in process context. 123 123 * 124 124 * returns zero, or a negative error code. 125 125 */ ··· 245 241 * Note that @req's ->complete() callback must never be called from 246 242 * within usb_ep_queue() as that can create deadlock situations. 247 243 * 244 + * This routine may be called in interrupt context. 245 + * 248 246 * Returns zero, or a negative error code. Endpoints that are not enabled 249 247 * report errors; errors will also be 250 248 * reported when the usb peripheral is disconnected. ··· 290 284 * at the head of the queue) except as part of disconnecting from usb. Such 291 285 * restrictions prevent drivers from supporting configuration changes, 292 286 * even to configuration zero (a "chapter 9" requirement). 287 + * 288 + * This routine may be called in interrupt context. 293 289 */ 294 290 int usb_ep_dequeue(struct usb_ep *ep, struct usb_request *req) 295 291 { ··· 319 311 * current altsetting, see usb_ep_clear_halt(). When switching altsettings, 320 312 * it's simplest to use usb_ep_enable() or usb_ep_disable() for the endpoints. 321 313 * 314 + * This routine may be called in interrupt context. 315 + * 322 316 * Returns zero, or a negative error code. On success, this call sets 323 317 * underlying hardware state that blocks data transfers. 324 318 * Attempts to halt IN endpoints will fail (returning -EAGAIN) if any ··· 346 336 * for endpoints that aren't reconfigured, after clearing any other state 347 337 * in the endpoint's i/o queue. 348 338 * 339 + * This routine may be called in interrupt context. 340 + * 349 341 * Returns zero, or a negative error code. On success, this call clears 350 342 * the underlying hardware state reflecting endpoint halt and data toggle. 351 343 * Note that some hardware can't support this request (like pxa2xx_udc), ··· 371 359 * Use this to stall an endpoint and ignore CLEAR_FEATURE(HALT_ENDPOINT) 372 360 * requests. If the gadget driver clears the halt status, it will 373 361 * automatically unwedge the endpoint. 362 + * 363 + * This routine may be called in interrupt context. 374 364 * 375 365 * Returns zero on success, else negative errno. 376 366 */ ··· 402 388 * written OUT to it by the host. Drivers that need precise handling for 403 389 * fault reporting or recovery may need to use this call. 404 390 * 391 + * This routine may be called in interrupt context. 392 + * 405 393 * This returns the number of such bytes in the fifo, or a negative 406 394 * errno if the endpoint doesn't use a FIFO or doesn't support such 407 395 * precise handling. ··· 431 415 * an endpoint fifo after abnormal transaction terminations. The call 432 416 * must never be used except when endpoint is not being used for any 433 417 * protocol translation. 418 + * 419 + * This routine may be called in interrupt context. 434 420 */ 435 421 void usb_ep_fifo_flush(struct usb_ep *ep) 436 422 {
+83 -1
drivers/usb/gadget/udc/renesas_usb3.c
··· 23 23 #include <linux/uaccess.h> 24 24 #include <linux/usb/ch9.h> 25 25 #include <linux/usb/gadget.h> 26 + #include <linux/usb/of.h> 27 + #include <linux/usb/role.h> 26 28 27 29 /* register definitions */ 28 30 #define USB3_AXI_INT_STA 0x008 ··· 336 334 struct work_struct extcon_work; 337 335 struct phy *phy; 338 336 struct dentry *dentry; 337 + 338 + struct usb_role_switch *role_sw; 339 + struct device *host_dev; 340 + struct work_struct role_work; 341 + enum usb_role role; 339 342 340 343 struct renesas_usb3_ep *usb3_ep; 341 344 int num_usb3_eps; ··· 658 651 } 659 652 } 660 653 654 + static void renesas_usb3_role_work(struct work_struct *work) 655 + { 656 + struct renesas_usb3 *usb3 = 657 + container_of(work, struct renesas_usb3, role_work); 658 + 659 + usb_role_switch_set_role(usb3->role_sw, usb3->role); 660 + } 661 + 661 662 static void usb3_set_mode(struct renesas_usb3 *usb3, bool host) 662 663 { 663 664 if (host) 664 665 usb3_clear_bit(usb3, DRD_CON_PERI_CON, USB3_DRD_CON); 665 666 else 666 667 usb3_set_bit(usb3, DRD_CON_PERI_CON, USB3_DRD_CON); 668 + } 669 + 670 + static void usb3_set_mode_by_role_sw(struct renesas_usb3 *usb3, bool host) 671 + { 672 + if (usb3->role_sw) { 673 + usb3->role = host ? USB_ROLE_HOST : USB_ROLE_DEVICE; 674 + schedule_work(&usb3->role_work); 675 + } else { 676 + usb3_set_mode(usb3, host); 677 + } 667 678 } 668 679 669 680 static void usb3_vbus_out(struct renesas_usb3 *usb3, bool enable) ··· 697 672 unsigned long flags; 698 673 699 674 spin_lock_irqsave(&usb3->lock, flags); 700 - usb3_set_mode(usb3, host); 675 + usb3_set_mode_by_role_sw(usb3, host); 701 676 usb3_vbus_out(usb3, a_dev); 702 677 /* for A-Peripheral or forced B-device mode */ 703 678 if ((!host && a_dev) || ··· 2327 2302 .set_selfpowered = renesas_usb3_set_selfpowered, 2328 2303 }; 2329 2304 2305 + static enum usb_role renesas_usb3_role_switch_get(struct device *dev) 2306 + { 2307 + struct renesas_usb3 *usb3 = dev_get_drvdata(dev); 2308 + enum usb_role cur_role; 2309 + 2310 + pm_runtime_get_sync(dev); 2311 + cur_role = usb3_is_host(usb3) ? USB_ROLE_HOST : USB_ROLE_DEVICE; 2312 + pm_runtime_put(dev); 2313 + 2314 + return cur_role; 2315 + } 2316 + 2317 + static int renesas_usb3_role_switch_set(struct device *dev, 2318 + enum usb_role role) 2319 + { 2320 + struct renesas_usb3 *usb3 = dev_get_drvdata(dev); 2321 + struct device *host = usb3->host_dev; 2322 + enum usb_role cur_role = renesas_usb3_role_switch_get(dev); 2323 + 2324 + pm_runtime_get_sync(dev); 2325 + if (cur_role == USB_ROLE_HOST && role == USB_ROLE_DEVICE) { 2326 + device_release_driver(host); 2327 + usb3_set_mode(usb3, false); 2328 + } else if (cur_role == USB_ROLE_DEVICE && role == USB_ROLE_HOST) { 2329 + /* Must set the mode before device_attach of the host */ 2330 + usb3_set_mode(usb3, true); 2331 + /* This device_attach() might sleep */ 2332 + if (device_attach(host) < 0) 2333 + dev_err(dev, "device_attach(host) failed\n"); 2334 + } 2335 + pm_runtime_put(dev); 2336 + 2337 + return 0; 2338 + } 2339 + 2330 2340 static ssize_t role_store(struct device *dev, struct device_attribute *attr, 2331 2341 const char *buf, size_t count) 2332 2342 { ··· 2464 2404 2465 2405 debugfs_remove_recursive(usb3->dentry); 2466 2406 device_remove_file(&pdev->dev, &dev_attr_role); 2407 + 2408 + usb_role_switch_unregister(usb3->role_sw); 2467 2409 2468 2410 usb_del_gadget_udc(&usb3->gadget); 2469 2411 renesas_usb3_dma_free_prd(usb3, &pdev->dev); ··· 2624 2562 EXTCON_NONE, 2625 2563 }; 2626 2564 2565 + static const struct usb_role_switch_desc renesas_usb3_role_switch_desc = { 2566 + .set = renesas_usb3_role_switch_set, 2567 + .get = renesas_usb3_role_switch_get, 2568 + .allow_userspace_control = true, 2569 + }; 2570 + 2627 2571 static int renesas_usb3_probe(struct platform_device *pdev) 2628 2572 { 2629 2573 struct renesas_usb3 *usb3; ··· 2714 2646 ret = device_create_file(&pdev->dev, &dev_attr_role); 2715 2647 if (ret < 0) 2716 2648 goto err_dev_create; 2649 + 2650 + INIT_WORK(&usb3->role_work, renesas_usb3_role_work); 2651 + usb3->role_sw = usb_role_switch_register(&pdev->dev, 2652 + &renesas_usb3_role_switch_desc); 2653 + if (!IS_ERR(usb3->role_sw)) { 2654 + usb3->host_dev = usb_of_get_companion_dev(&pdev->dev); 2655 + if (!usb3->host_dev) { 2656 + /* If not found, this driver will not use a role sw */ 2657 + usb_role_switch_unregister(usb3->role_sw); 2658 + usb3->role_sw = NULL; 2659 + } 2660 + } else { 2661 + usb3->role_sw = NULL; 2662 + } 2717 2663 2718 2664 usb3->workaround_for_vbus = priv->workaround_for_vbus; 2719 2665
+8
drivers/usb/host/Kconfig
··· 192 192 ---help--- 193 193 Variation of ARC USB block used in some Freescale chips. 194 194 195 + config USB_EHCI_HCD_NPCM7XX 196 + tristate "Support for Nuvoton NPCM7XX on-chip EHCI USB controller" 197 + depends on (USB_EHCI_HCD && ARCH_NPCM7XX) || COMPILE_TEST 198 + default y if (USB_EHCI_HCD && ARCH_NPCM7XX) 199 + help 200 + Enables support for the on-chip EHCI controller on 201 + Nuvoton NPCM7XX chips. 202 + 195 203 config USB_EHCI_HCD_OMAP 196 204 tristate "EHCI support for OMAP3 and later chips" 197 205 depends on ARCH_OMAP
+1
drivers/usb/host/Makefile
··· 43 43 obj-$(CONFIG_USB_EHCI_PCI) += ehci-pci.o 44 44 obj-$(CONFIG_USB_EHCI_HCD_PLATFORM) += ehci-platform.o 45 45 obj-$(CONFIG_USB_EHCI_MXC) += ehci-mxc.o 46 + obj-$(CONFIG_USB_EHCI_HCD_NPCM7XX) += ehci-npcm7xx.o 46 47 obj-$(CONFIG_USB_EHCI_HCD_OMAP) += ehci-omap.o 47 48 obj-$(CONFIG_USB_EHCI_HCD_ORION) += ehci-orion.o 48 49 obj-$(CONFIG_USB_EHCI_HCD_SPEAR) += ehci-spear.o
+1
drivers/usb/host/ehci-hcd.c
··· 1226 1226 .bus_resume = ehci_bus_resume, 1227 1227 .relinquish_port = ehci_relinquish_port, 1228 1228 .port_handed_over = ehci_port_handed_over, 1229 + .get_resuming_ports = ehci_get_resuming_ports, 1229 1230 1230 1231 /* 1231 1232 * device support
+8
drivers/usb/host/ehci-hub.c
··· 512 512 return -ESHUTDOWN; 513 513 } 514 514 515 + static unsigned long ehci_get_resuming_ports(struct usb_hcd *hcd) 516 + { 517 + struct ehci_hcd *ehci = hcd_to_ehci(hcd); 518 + 519 + return ehci->resuming_ports; 520 + } 521 + 515 522 #else 516 523 517 524 #define ehci_bus_suspend NULL 518 525 #define ehci_bus_resume NULL 526 + #define ehci_get_resuming_ports NULL 519 527 520 528 #endif /* CONFIG_PM */ 521 529
+212
drivers/usb/host/ehci-npcm7xx.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * Nuvoton NPCM7xx driver for EHCI HCD 4 + * 5 + * Copyright (C) 2018 Nuvoton Technologies, 6 + * Avi Fishman <avi.fishman@nuvoton.com> <avifishman70@gmail.com> 7 + * Tomer Maimon <tomer.maimon@nuvoton.com> <tmaimon77@gmail.com> 8 + * 9 + * Based on various ehci-spear.c driver 10 + */ 11 + 12 + 13 + #include <linux/dma-mapping.h> 14 + 15 + #include <linux/kernel.h> 16 + #include <linux/module.h> 17 + #include <linux/of.h> 18 + #include <linux/platform_device.h> 19 + #include <linux/pm.h> 20 + #include <linux/usb.h> 21 + #include <linux/usb/hcd.h> 22 + 23 + #include "ehci.h" 24 + 25 + #include <linux/regmap.h> 26 + #include <linux/mfd/syscon.h> 27 + 28 + #define DRIVER_DESC "EHCI npcm7xx driver" 29 + 30 + static const char hcd_name[] = "npcm7xx-ehci"; 31 + 32 + #define USB2PHYCTL_OFFSET 0x144 33 + 34 + #define IPSRST2_OFFSET 0x24 35 + #define IPSRST3_OFFSET 0x34 36 + 37 + 38 + static struct hc_driver __read_mostly ehci_npcm7xx_hc_driver; 39 + 40 + #ifdef CONFIG_PM_SLEEP 41 + static int ehci_npcm7xx_drv_suspend(struct device *dev) 42 + { 43 + struct usb_hcd *hcd = dev_get_drvdata(dev); 44 + bool do_wakeup = device_may_wakeup(dev); 45 + 46 + return ehci_suspend(hcd, do_wakeup); 47 + } 48 + 49 + static int ehci_npcm7xx_drv_resume(struct device *dev) 50 + { 51 + struct usb_hcd *hcd = dev_get_drvdata(dev); 52 + 53 + ehci_resume(hcd, false); 54 + return 0; 55 + } 56 + #endif /* CONFIG_PM_SLEEP */ 57 + 58 + static SIMPLE_DEV_PM_OPS(ehci_npcm7xx_pm_ops, ehci_npcm7xx_drv_suspend, 59 + ehci_npcm7xx_drv_resume); 60 + 61 + static int npcm7xx_ehci_hcd_drv_probe(struct platform_device *pdev) 62 + { 63 + struct usb_hcd *hcd; 64 + struct resource *res; 65 + struct regmap *gcr_regmap; 66 + struct regmap *rst_regmap; 67 + const struct hc_driver *driver = &ehci_npcm7xx_hc_driver; 68 + int irq; 69 + int retval; 70 + 71 + dev_dbg(&pdev->dev, "initializing npcm7xx ehci USB Controller\n"); 72 + 73 + gcr_regmap = syscon_regmap_lookup_by_compatible("nuvoton,npcm750-gcr"); 74 + if (IS_ERR(gcr_regmap)) { 75 + dev_err(&pdev->dev, "%s: failed to find nuvoton,npcm750-gcr\n", 76 + __func__); 77 + return PTR_ERR(gcr_regmap); 78 + } 79 + 80 + rst_regmap = syscon_regmap_lookup_by_compatible("nuvoton,npcm750-rst"); 81 + if (IS_ERR(rst_regmap)) { 82 + dev_err(&pdev->dev, "%s: failed to find nuvoton,npcm750-rst\n", 83 + __func__); 84 + return PTR_ERR(rst_regmap); 85 + } 86 + 87 + /********* phy init ******/ 88 + // reset usb host 89 + regmap_update_bits(rst_regmap, IPSRST2_OFFSET, 90 + (0x1 << 26), (0x1 << 26)); 91 + regmap_update_bits(rst_regmap, IPSRST3_OFFSET, 92 + (0x1 << 25), (0x1 << 25)); 93 + regmap_update_bits(gcr_regmap, USB2PHYCTL_OFFSET, 94 + (0x1 << 28), 0); 95 + 96 + udelay(1); 97 + 98 + // enable phy 99 + regmap_update_bits(rst_regmap, IPSRST3_OFFSET, 100 + (0x1 << 25), 0); 101 + 102 + udelay(50); // enable phy 103 + 104 + regmap_update_bits(gcr_regmap, USB2PHYCTL_OFFSET, 105 + (0x1 << 28), (0x1 << 28)); 106 + 107 + // enable host 108 + regmap_update_bits(rst_regmap, IPSRST2_OFFSET, 109 + (0x1 << 26), 0); 110 + 111 + if (usb_disabled()) 112 + return -ENODEV; 113 + 114 + irq = platform_get_irq(pdev, 0); 115 + if (irq < 0) { 116 + retval = irq; 117 + goto fail; 118 + } 119 + 120 + /* 121 + * Right now device-tree probed devices don't get dma_mask set. 122 + * Since shared usb code relies on it, set it here for now. 123 + * Once we have dma capability bindings this can go away. 124 + */ 125 + retval = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); 126 + if (retval) 127 + goto fail; 128 + 129 + hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev)); 130 + if (!hcd) { 131 + retval = -ENOMEM; 132 + goto fail; 133 + } 134 + 135 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 136 + hcd->regs = devm_ioremap_resource(&pdev->dev, res); 137 + if (IS_ERR(hcd->regs)) { 138 + retval = PTR_ERR(hcd->regs); 139 + goto err_put_hcd; 140 + } 141 + hcd->rsrc_start = res->start; 142 + hcd->rsrc_len = resource_size(res); 143 + 144 + /* registers start at offset 0x0 */ 145 + hcd_to_ehci(hcd)->caps = hcd->regs; 146 + 147 + retval = usb_add_hcd(hcd, irq, IRQF_SHARED); 148 + if (retval) 149 + goto err_put_hcd; 150 + 151 + device_wakeup_enable(hcd->self.controller); 152 + return retval; 153 + 154 + err_put_hcd: 155 + usb_put_hcd(hcd); 156 + fail: 157 + dev_err(&pdev->dev, "init fail, %d\n", retval); 158 + 159 + return retval; 160 + } 161 + 162 + static int npcm7xx_ehci_hcd_drv_remove(struct platform_device *pdev) 163 + { 164 + struct usb_hcd *hcd = platform_get_drvdata(pdev); 165 + 166 + usb_remove_hcd(hcd); 167 + 168 + usb_put_hcd(hcd); 169 + 170 + return 0; 171 + } 172 + 173 + static const struct of_device_id npcm7xx_ehci_id_table[] = { 174 + { .compatible = "nuvoton,npcm750-ehci" }, 175 + { }, 176 + }; 177 + MODULE_DEVICE_TABLE(of, npcm7xx_ehci_id_table); 178 + 179 + static struct platform_driver npcm7xx_ehci_hcd_driver = { 180 + .probe = npcm7xx_ehci_hcd_drv_probe, 181 + .remove = npcm7xx_ehci_hcd_drv_remove, 182 + .shutdown = usb_hcd_platform_shutdown, 183 + .driver = { 184 + .name = "npcm7xx-ehci", 185 + .bus = &platform_bus_type, 186 + .pm = &ehci_npcm7xx_pm_ops, 187 + .of_match_table = npcm7xx_ehci_id_table, 188 + } 189 + }; 190 + 191 + static int __init ehci_npcm7xx_init(void) 192 + { 193 + if (usb_disabled()) 194 + return -ENODEV; 195 + 196 + pr_info("%s: " DRIVER_DESC "\n", hcd_name); 197 + 198 + ehci_init_driver(&ehci_npcm7xx_hc_driver, NULL); 199 + return platform_driver_register(&npcm7xx_ehci_hcd_driver); 200 + } 201 + module_init(ehci_npcm7xx_init); 202 + 203 + static void __exit ehci_npcm7xx_cleanup(void) 204 + { 205 + platform_driver_unregister(&npcm7xx_ehci_hcd_driver); 206 + } 207 + module_exit(ehci_npcm7xx_cleanup); 208 + 209 + MODULE_DESCRIPTION(DRIVER_DESC); 210 + MODULE_ALIAS("platform:npcm7xx-ehci"); 211 + MODULE_AUTHOR("Avi Fishman"); 212 + MODULE_LICENSE("GPL v2");
-4
drivers/usb/host/ehci-sched.c
··· 1835 1835 unsigned uframe; 1836 1836 int urb_index = -1; 1837 1837 struct ehci_iso_stream *stream = itd->stream; 1838 - struct usb_device *dev; 1839 1838 bool retval = false; 1840 1839 1841 1840 /* for each uframe with a packet */ ··· 1885 1886 */ 1886 1887 1887 1888 /* give urb back to the driver; completion often (re)submits */ 1888 - dev = urb->dev; 1889 1889 ehci_urb_done(ehci, urb, 0); 1890 1890 retval = true; 1891 1891 urb = NULL; ··· 2228 2230 u32 t; 2229 2231 int urb_index; 2230 2232 struct ehci_iso_stream *stream = sitd->stream; 2231 - struct usb_device *dev; 2232 2233 bool retval = false; 2233 2234 2234 2235 urb_index = sitd->index; ··· 2265 2268 */ 2266 2269 2267 2270 /* give urb back to the driver; completion often (re)submits */ 2268 - dev = urb->dev; 2269 2271 ehci_urb_done(ehci, urb, 0); 2270 2272 retval = true; 2271 2273 urb = NULL;
-2
drivers/usb/host/u132-hcd.c
··· 3062 3062 int retval; 3063 3063 u32 control; 3064 3064 u32 rh_a = -1; 3065 - u32 num_ports; 3066 3065 3067 3066 msleep(100); 3068 3067 if (u132_exiting > 0) ··· 3076 3077 retval = ftdi_read_pcimem(pdev, roothub.a, &rh_a); 3077 3078 if (retval) 3078 3079 return retval; 3079 - num_ports = rh_a & RH_A_NDP; /* refuse to confuse usbcore */ 3080 3080 if (pdev->dev.dma_mask) 3081 3081 return -EINVAL; 3082 3082
-2
drivers/usb/host/whci/pzl.c
··· 96 96 97 97 while (qset->ntds) { 98 98 struct whc_qtd *td; 99 - int t; 100 99 101 - t = qset->td_start; 102 100 td = &qset->qtd[qset->td_start]; 103 101 status = le32_to_cpu(td->status); 104 102
-2
drivers/usb/host/xhci-dbgcap.c
··· 913 913 struct device_attribute *attr, 914 914 const char *buf, size_t count) 915 915 { 916 - struct xhci_dbc *dbc; 917 916 struct xhci_hcd *xhci; 918 917 919 918 xhci = hcd_to_xhci(dev_get_drvdata(dev)); 920 - dbc = xhci->dbc; 921 919 922 920 if (!strncmp(buf, "enable", 6)) 923 921 xhci_dbc_start(xhci);
+11
drivers/usb/host/xhci-hub.c
··· 1684 1684 return 0; 1685 1685 } 1686 1686 1687 + unsigned long xhci_get_resuming_ports(struct usb_hcd *hcd) 1688 + { 1689 + struct xhci_hcd *xhci = hcd_to_xhci(hcd); 1690 + struct xhci_bus_state *bus_state; 1691 + 1692 + bus_state = &xhci->bus_state[hcd_index(hcd)]; 1693 + 1694 + /* USB3 port wakeups are reported via usb_wakeup_notification() */ 1695 + return bus_state->resuming_ports; /* USB2 ports only */ 1696 + } 1697 + 1687 1698 #endif /* CONFIG_PM */
+1
drivers/usb/host/xhci-plat.c
··· 105 105 }; 106 106 107 107 static const struct xhci_plat_priv xhci_plat_renesas_rcar_gen3 = { 108 + .firmware_name = XHCI_RCAR_FIRMWARE_NAME_V3, 108 109 .init_quirk = xhci_rcar_init_quirk, 109 110 .plat_start = xhci_rcar_start, 110 111 .resume_quirk = xhci_rcar_resume_quirk,
+28 -15
drivers/usb/host/xhci-rcar.c
··· 17 17 #include "xhci-rcar.h" 18 18 19 19 /* 20 - * - The V3 firmware is for r8a7796 (with good performance) and r8a7795 es2.0 21 - * or later. 22 - * - The V2 firmware can be used on both r8a7795 (es1.x) and r8a7796. 20 + * - The V3 firmware is for almost all R-Car Gen3 (except r8a7795 ES1.x) 21 + * - The V2 firmware is for r8a7795 ES1.x. 23 22 * - The V2 firmware is possible to use on R-Car Gen2. However, the V2 causes 24 23 * performance degradation. So, this driver continues to use the V1 if R-Car 25 24 * Gen2. ··· 29 30 MODULE_FIRMWARE(XHCI_RCAR_FIRMWARE_NAME_V3); 30 31 31 32 /*** Register Offset ***/ 33 + #define RCAR_USB3_AXH_STA 0x104 /* AXI Host Control Status */ 32 34 #define RCAR_USB3_INT_ENA 0x224 /* Interrupt Enable */ 33 35 #define RCAR_USB3_DL_CTRL 0x250 /* FW Download Control & Status */ 34 36 #define RCAR_USB3_FW_DATA0 0x258 /* FW Data0 */ ··· 42 42 #define RCAR_USB3_TX_POL 0xab8 /* USB3.0 TX Polarity */ 43 43 44 44 /*** Register Settings ***/ 45 + /* AXI Host Control Status */ 46 + #define RCAR_USB3_AXH_STA_B3_PLL_ACTIVE 0x00010000 47 + #define RCAR_USB3_AXH_STA_B2_PLL_ACTIVE 0x00000001 48 + #define RCAR_USB3_AXH_STA_PLL_ACTIVE_MASK (RCAR_USB3_AXH_STA_B3_PLL_ACTIVE | \ 49 + RCAR_USB3_AXH_STA_B2_PLL_ACTIVE) 50 + 45 51 /* Interrupt Enable */ 46 52 #define RCAR_USB3_INT_XHC_ENA 0x00000001 47 53 #define RCAR_USB3_INT_PME_ENA 0x00000002 ··· 80 74 { 81 75 .soc_id = "r8a7795", .revision = "ES1.*", 82 76 .data = (void *)RCAR_XHCI_FIRMWARE_V2, 83 - }, 84 - { 85 - .soc_id = "r8a7795", 86 - .data = (void *)RCAR_XHCI_FIRMWARE_V3, 87 - }, 88 - { 89 - .soc_id = "r8a7796", 90 - .data = (void *)RCAR_XHCI_FIRMWARE_V3, 91 - }, 92 - { 93 - .soc_id = "r8a77965", 94 - .data = (void *)RCAR_XHCI_FIRMWARE_V3, 95 77 }, 96 78 { /* sentinel */ }, 97 79 }; ··· 207 213 return retval; 208 214 } 209 215 216 + static bool xhci_rcar_wait_for_pll_active(struct usb_hcd *hcd) 217 + { 218 + int timeout = 1000; 219 + u32 val, mask = RCAR_USB3_AXH_STA_PLL_ACTIVE_MASK; 220 + 221 + while (timeout > 0) { 222 + val = readl(hcd->regs + RCAR_USB3_AXH_STA); 223 + if ((val & mask) == mask) 224 + return true; 225 + udelay(1); 226 + timeout--; 227 + } 228 + 229 + return false; 230 + } 231 + 210 232 /* This function needs to initialize a "phy" of usb before */ 211 233 int xhci_rcar_init_quirk(struct usb_hcd *hcd) 212 234 { ··· 242 232 if (xhci_rcar_is_gen2(hcd->self.controller) || 243 233 xhci_rcar_is_gen3(hcd->self.controller)) 244 234 xhci->quirks |= XHCI_NO_64BIT_SUPPORT; 235 + 236 + if (!xhci_rcar_wait_for_pll_active(hcd)) 237 + return -ETIMEDOUT; 245 238 246 239 return xhci_rcar_download_firmware(hcd); 247 240 }
+1
drivers/usb/host/xhci.c
··· 5121 5121 .hub_status_data = xhci_hub_status_data, 5122 5122 .bus_suspend = xhci_bus_suspend, 5123 5123 .bus_resume = xhci_bus_resume, 5124 + .get_resuming_ports = xhci_get_resuming_ports, 5124 5125 5125 5126 /* 5126 5127 * call back when device connected and addressed
+2
drivers/usb/host/xhci.h
··· 2114 2114 #ifdef CONFIG_PM 2115 2115 int xhci_bus_suspend(struct usb_hcd *hcd); 2116 2116 int xhci_bus_resume(struct usb_hcd *hcd); 2117 + unsigned long xhci_get_resuming_ports(struct usb_hcd *hcd); 2117 2118 #else 2118 2119 #define xhci_bus_suspend NULL 2119 2120 #define xhci_bus_resume NULL 2121 + #define xhci_get_resuming_ports NULL 2120 2122 #endif /* CONFIG_PM */ 2121 2123 2122 2124 u32 xhci_port_state_to_neutral(u32 state);
-2
drivers/usb/isp1760/isp1760-hcd.c
··· 1817 1817 u32 temp, status; 1818 1818 unsigned long flags; 1819 1819 int retval = 0; 1820 - unsigned selector; 1821 1820 1822 1821 /* 1823 1822 * FIXME: support SetPortFeatures USB_PORT_FEAT_INDICATOR. ··· 2009 2010 } 2010 2011 break; 2011 2012 case SetPortFeature: 2012 - selector = wIndex >> 8; 2013 2013 wIndex &= 0xff; 2014 2014 if (!wIndex || wIndex > ports) 2015 2015 goto error;
+6 -4
drivers/usb/misc/adutux.c
··· 155 155 { 156 156 struct adu_device *dev = urb->context; 157 157 int status = urb->status; 158 + unsigned long flags; 158 159 159 160 adu_debug_data(&dev->udev->dev, __func__, 160 161 urb->actual_length, urb->transfer_buffer); 161 162 162 - spin_lock(&dev->buflock); 163 + spin_lock_irqsave(&dev->buflock, flags); 163 164 164 165 if (status != 0) { 165 166 if ((status != -ENOENT) && (status != -ECONNRESET) && ··· 191 190 192 191 exit: 193 192 dev->read_urb_finished = 1; 194 - spin_unlock(&dev->buflock); 193 + spin_unlock_irqrestore(&dev->buflock, flags); 195 194 /* always wake up so we recover from errors */ 196 195 wake_up_interruptible(&dev->read_wait); 197 196 } ··· 200 199 { 201 200 struct adu_device *dev = urb->context; 202 201 int status = urb->status; 202 + unsigned long flags; 203 203 204 204 adu_debug_data(&dev->udev->dev, __func__, 205 205 urb->actual_length, urb->transfer_buffer); ··· 215 213 return; 216 214 } 217 215 218 - spin_lock(&dev->buflock); 216 + spin_lock_irqsave(&dev->buflock, flags); 219 217 dev->out_urb_finished = 1; 220 218 wake_up(&dev->write_wait); 221 - spin_unlock(&dev->buflock); 219 + spin_unlock_irqrestore(&dev->buflock, flags); 222 220 } 223 221 224 222 static int adu_open(struct inode *inode, struct file *file)
+1
drivers/usb/misc/appledisplay.c
··· 89 89 dev_err(dev, 90 90 "OVERFLOW with data length %d, actual length is %d\n", 91 91 ACD_URB_BUFFER_LEN, pdata->urb->actual_length); 92 + /* fall through */ 92 93 case -ECONNRESET: 93 94 case -ENOENT: 94 95 case -ESHUTDOWN:
-5
drivers/usb/misc/iowarrior.c
··· 81 81 atomic_t write_busy; /* number of write-urbs submitted */ 82 82 atomic_t read_idx; 83 83 atomic_t intr_idx; 84 - spinlock_t intr_idx_lock; /* protects intr_idx */ 85 84 atomic_t overflow_flag; /* signals an index 'rollover' */ 86 85 int present; /* this is 1 as long as the device is connected */ 87 86 int opened; /* this is 1 if the device is currently open */ ··· 165 166 goto exit; 166 167 } 167 168 168 - spin_lock(&dev->intr_idx_lock); 169 169 intr_idx = atomic_read(&dev->intr_idx); 170 170 /* aux_idx become previous intr_idx */ 171 171 aux_idx = (intr_idx == 0) ? (MAX_INTERRUPT_BUFFER - 1) : (intr_idx - 1); ··· 179 181 (dev->read_queue + offset, urb->transfer_buffer, 180 182 dev->report_size)) { 181 183 /* equal values on interface 0 will be ignored */ 182 - spin_unlock(&dev->intr_idx_lock); 183 184 goto exit; 184 185 } 185 186 } ··· 199 202 *(dev->read_queue + offset + (dev->report_size)) = dev->serial_number++; 200 203 201 204 atomic_set(&dev->intr_idx, aux_idx); 202 - spin_unlock(&dev->intr_idx_lock); 203 205 /* tell the blocking read about the new data */ 204 206 wake_up_interruptible(&dev->read_wait); 205 207 ··· 758 762 759 763 atomic_set(&dev->intr_idx, 0); 760 764 atomic_set(&dev->read_idx, 0); 761 - spin_lock_init(&dev->intr_idx_lock); 762 765 atomic_set(&dev->overflow_flag, 0); 763 766 init_waitqueue_head(&dev->read_wait); 764 767 atomic_set(&dev->write_busy, 0);
+4 -3
drivers/usb/misc/ldusb.c
··· 225 225 size_t *actual_buffer; 226 226 unsigned int next_ring_head; 227 227 int status = urb->status; 228 + unsigned long flags; 228 229 int retval; 229 230 230 231 if (status) { ··· 237 236 dev_dbg(&dev->intf->dev, 238 237 "%s: nonzero status received: %d\n", __func__, 239 238 status); 240 - spin_lock(&dev->rbsl); 239 + spin_lock_irqsave(&dev->rbsl, flags); 241 240 goto resubmit; /* maybe we can recover */ 242 241 } 243 242 } 244 243 245 - spin_lock(&dev->rbsl); 244 + spin_lock_irqsave(&dev->rbsl, flags); 246 245 if (urb->actual_length > 0) { 247 246 next_ring_head = (dev->ring_head+1) % ring_buffer_size; 248 247 if (next_ring_head != dev->ring_tail) { ··· 271 270 dev->buffer_overflow = 1; 272 271 } 273 272 } 274 - spin_unlock(&dev->rbsl); 273 + spin_unlock_irqrestore(&dev->rbsl, flags); 275 274 exit: 276 275 dev->interrupt_in_done = 1; 277 276 wake_up_interruptible(&dev->read_wait);
+3 -2
drivers/usb/misc/legousbtower.c
··· 722 722 struct lego_usb_tower *dev = urb->context; 723 723 int status = urb->status; 724 724 int retval; 725 + unsigned long flags; 725 726 726 727 lego_usb_tower_debug_data(&dev->udev->dev, __func__, 727 728 urb->actual_length, urb->transfer_buffer); ··· 741 740 } 742 741 743 742 if (urb->actual_length > 0) { 744 - spin_lock (&dev->read_buffer_lock); 743 + spin_lock_irqsave(&dev->read_buffer_lock, flags); 745 744 if (dev->read_buffer_length + urb->actual_length < read_buffer_size) { 746 745 memcpy (dev->read_buffer + dev->read_buffer_length, 747 746 dev->interrupt_in_buffer, ··· 754 753 pr_warn("read_buffer overflow, %d bytes dropped\n", 755 754 urb->actual_length); 756 755 } 757 - spin_unlock (&dev->read_buffer_lock); 756 + spin_unlock_irqrestore(&dev->read_buffer_lock, flags); 758 757 } 759 758 760 759 resubmit:
+2 -2
drivers/usb/misc/sisusbvga/sisusb.c
··· 1750 1750 static int sisusb_set_default_mode(struct sisusb_usb_data *sisusb, 1751 1751 int touchengines) 1752 1752 { 1753 - int ret = 0, i, j, modex, modey, bpp, du; 1753 + int ret = 0, i, j, modex, bpp, du; 1754 1754 u8 sr31, cr63, tmp8; 1755 1755 static const char attrdata[] = { 1756 1756 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, ··· 1773 1773 0x00 1774 1774 }; 1775 1775 1776 - modex = 640; modey = 480; bpp = 2; 1776 + modex = 640; bpp = 2; 1777 1777 1778 1778 GETIREG(SISSR, 0x31, &sr31); 1779 1779 GETIREG(SISCR, 0x63, &cr63);
+6 -4
drivers/usb/misc/usbtest.c
··· 1082 1082 struct usb_ctrlrequest *reqp; 1083 1083 struct subcase *subcase; 1084 1084 int status = urb->status; 1085 + unsigned long flags; 1085 1086 1086 1087 reqp = (struct usb_ctrlrequest *)urb->setup_packet; 1087 1088 subcase = container_of(reqp, struct subcase, setup); 1088 1089 1089 - spin_lock(&ctx->lock); 1090 + spin_lock_irqsave(&ctx->lock, flags); 1090 1091 ctx->count--; 1091 1092 ctx->pending--; 1092 1093 ··· 1186 1185 /* signal completion when nothing's queued */ 1187 1186 if (ctx->pending == 0) 1188 1187 complete(&ctx->complete); 1189 - spin_unlock(&ctx->lock); 1188 + spin_unlock_irqrestore(&ctx->lock, flags); 1190 1189 } 1191 1190 1192 1191 static int ··· 1918 1917 static void complicated_callback(struct urb *urb) 1919 1918 { 1920 1919 struct transfer_context *ctx = urb->context; 1920 + unsigned long flags; 1921 1921 1922 - spin_lock(&ctx->lock); 1922 + spin_lock_irqsave(&ctx->lock, flags); 1923 1923 ctx->count--; 1924 1924 1925 1925 ctx->packet_count += urb->number_of_packets; ··· 1960 1958 complete(&ctx->done); 1961 1959 } 1962 1960 done: 1963 - spin_unlock(&ctx->lock); 1961 + spin_unlock_irqrestore(&ctx->lock, flags); 1964 1962 } 1965 1963 1966 1964 static struct urb *iso_alloc_urb(
-2
drivers/usb/misc/uss720.c
··· 748 748 { 749 749 struct parport *pp = usb_get_intfdata(intf); 750 750 struct parport_uss720_private *priv; 751 - struct usb_device *usbdev; 752 751 753 752 dev_dbg(&intf->dev, "disconnect\n"); 754 753 usb_set_intfdata(intf, NULL); 755 754 if (pp) { 756 755 priv = pp->private_data; 757 - usbdev = priv->usbdev; 758 756 priv->usbdev = NULL; 759 757 priv->pp = NULL; 760 758 dev_dbg(&intf->dev, "parport_remove_port\n");
+4 -4
drivers/usb/mon/mon_bin.c
··· 95 95 unsigned short busnum; /* Bus number */ 96 96 char flag_setup; 97 97 char flag_data; 98 - s64 ts_sec; /* getnstimeofday64 */ 99 - s32 ts_usec; /* getnstimeofday64 */ 98 + s64 ts_sec; /* ktime_get_real_ts64 */ 99 + s32 ts_usec; /* ktime_get_real_ts64 */ 100 100 int status; 101 101 unsigned int len_urb; /* Length of data (submitted or actual) */ 102 102 unsigned int len_cap; /* Delivered length */ ··· 497 497 struct mon_bin_hdr *ep; 498 498 char data_tag = 0; 499 499 500 - getnstimeofday64(&ts); 500 + ktime_get_real_ts64(&ts); 501 501 502 502 spin_lock_irqsave(&rp->b_lock, flags); 503 503 ··· 637 637 unsigned int offset; 638 638 struct mon_bin_hdr *ep; 639 639 640 - getnstimeofday64(&ts); 640 + ktime_get_real_ts64(&ts); 641 641 642 642 spin_lock_irqsave(&rp->b_lock, flags); 643 643
+1 -1
drivers/usb/musb/musb_dsps.c
··· 237 237 } 238 238 musb_writeb(musb->mregs, MUSB_DEVCTL, 0); 239 239 skip_session = 1; 240 - /* fall */ 240 + /* fall through */ 241 241 242 242 case OTG_STATE_A_IDLE: 243 243 case OTG_STATE_B_IDLE:
+1
drivers/usb/musb/musb_host.c
··· 378 378 qh = first_qh(head); 379 379 break; 380 380 } 381 + /* else: fall through */ 381 382 382 383 case USB_ENDPOINT_XFER_ISOC: 383 384 case USB_ENDPOINT_XFER_INT:
+1
drivers/usb/renesas_usbhs/Kconfig
··· 1 + # SPDX-License-Identifier: GPL-2.0 1 2 # 2 3 # Renesas USBHS Controller Drivers 3 4 #
+1
drivers/usb/renesas_usbhs/mod_gadget.c
··· 502 502 case READ_STATUS_STAGE: 503 503 case WRITE_STATUS_STAGE: 504 504 usbhs_dcp_control_transfer_done(pipe); 505 + /* fall through */ 505 506 default: 506 507 return ret; 507 508 }
+340 -81
drivers/usb/serial/cp210x.c
··· 239 239 struct cp210x_serial_private { 240 240 #ifdef CONFIG_GPIOLIB 241 241 struct gpio_chip gc; 242 - u8 config; 243 - u8 gpio_mode; 244 242 bool gpio_registered; 243 + u8 gpio_pushpull; 244 + u8 gpio_altfunc; 245 + u8 gpio_input; 245 246 #endif 246 247 u8 partnum; 248 + speed_t max_speed; 249 + bool use_actual_rate; 247 250 }; 248 251 249 252 struct cp210x_port_private { ··· 359 356 #define CONTROL_WRITE_RTS 0x0200 360 357 361 358 /* CP210X_VENDOR_SPECIFIC values */ 359 + #define CP210X_READ_2NCONFIG 0x000E 362 360 #define CP210X_READ_LATCH 0x00C2 363 361 #define CP210X_GET_PARTNUM 0x370B 364 362 #define CP210X_GET_PORTCONFIG 0x370C ··· 373 369 #define CP210X_PARTNUM_CP2104 0x04 374 370 #define CP210X_PARTNUM_CP2105 0x05 375 371 #define CP210X_PARTNUM_CP2108 0x08 372 + #define CP210X_PARTNUM_CP2102N_QFN28 0x20 373 + #define CP210X_PARTNUM_CP2102N_QFN24 0x21 374 + #define CP210X_PARTNUM_CP2102N_QFN20 0x22 376 375 #define CP210X_PARTNUM_UNKNOWN 0xFF 377 376 378 377 /* CP210X_GET_COMM_STATUS returns these 0x13 bytes */ ··· 468 461 #define CP2105_GPIO0_TXLED_MODE BIT(0) 469 462 #define CP2105_GPIO1_RXLED_MODE BIT(1) 470 463 #define CP2105_GPIO1_RS485_MODE BIT(2) 464 + 465 + /* CP2102N configuration array indices */ 466 + #define CP210X_2NCONFIG_CONFIG_VERSION_IDX 2 467 + #define CP210X_2NCONFIG_GPIO_MODE_IDX 581 468 + #define CP210X_2NCONFIG_GPIO_RSTLATCH_IDX 587 469 + #define CP210X_2NCONFIG_GPIO_CONTROL_IDX 600 471 470 472 471 /* CP210X_VENDOR_SPECIFIC, CP210X_WRITE_LATCH call writes these 0x2 bytes. */ 473 472 struct cp210x_gpio_write { ··· 780 767 return 0; 781 768 } 782 769 783 - /* 784 - * cp210x_quantise_baudrate 785 - * Quantises the baud rate as per AN205 Table 1 786 - */ 787 - static unsigned int cp210x_quantise_baudrate(unsigned int baud) 788 - { 789 - if (baud <= 300) 790 - baud = 300; 791 - else if (baud <= 600) baud = 600; 792 - else if (baud <= 1200) baud = 1200; 793 - else if (baud <= 1800) baud = 1800; 794 - else if (baud <= 2400) baud = 2400; 795 - else if (baud <= 4000) baud = 4000; 796 - else if (baud <= 4803) baud = 4800; 797 - else if (baud <= 7207) baud = 7200; 798 - else if (baud <= 9612) baud = 9600; 799 - else if (baud <= 14428) baud = 14400; 800 - else if (baud <= 16062) baud = 16000; 801 - else if (baud <= 19250) baud = 19200; 802 - else if (baud <= 28912) baud = 28800; 803 - else if (baud <= 38601) baud = 38400; 804 - else if (baud <= 51558) baud = 51200; 805 - else if (baud <= 56280) baud = 56000; 806 - else if (baud <= 58053) baud = 57600; 807 - else if (baud <= 64111) baud = 64000; 808 - else if (baud <= 77608) baud = 76800; 809 - else if (baud <= 117028) baud = 115200; 810 - else if (baud <= 129347) baud = 128000; 811 - else if (baud <= 156868) baud = 153600; 812 - else if (baud <= 237832) baud = 230400; 813 - else if (baud <= 254234) baud = 250000; 814 - else if (baud <= 273066) baud = 256000; 815 - else if (baud <= 491520) baud = 460800; 816 - else if (baud <= 567138) baud = 500000; 817 - else if (baud <= 670254) baud = 576000; 818 - else if (baud < 1000000) 819 - baud = 921600; 820 - else if (baud > 2000000) 821 - baud = 2000000; 822 - return baud; 823 - } 824 - 825 770 static int cp210x_open(struct tty_struct *tty, struct usb_serial_port *port) 826 771 { 827 772 int result; ··· 999 1028 *cflagp = cflag; 1000 1029 } 1001 1030 1031 + struct cp210x_rate { 1032 + speed_t rate; 1033 + speed_t high; 1034 + }; 1035 + 1036 + static const struct cp210x_rate cp210x_an205_table1[] = { 1037 + { 300, 300 }, 1038 + { 600, 600 }, 1039 + { 1200, 1200 }, 1040 + { 1800, 1800 }, 1041 + { 2400, 2400 }, 1042 + { 4000, 4000 }, 1043 + { 4800, 4803 }, 1044 + { 7200, 7207 }, 1045 + { 9600, 9612 }, 1046 + { 14400, 14428 }, 1047 + { 16000, 16062 }, 1048 + { 19200, 19250 }, 1049 + { 28800, 28912 }, 1050 + { 38400, 38601 }, 1051 + { 51200, 51558 }, 1052 + { 56000, 56280 }, 1053 + { 57600, 58053 }, 1054 + { 64000, 64111 }, 1055 + { 76800, 77608 }, 1056 + { 115200, 117028 }, 1057 + { 128000, 129347 }, 1058 + { 153600, 156868 }, 1059 + { 230400, 237832 }, 1060 + { 250000, 254234 }, 1061 + { 256000, 273066 }, 1062 + { 460800, 491520 }, 1063 + { 500000, 567138 }, 1064 + { 576000, 670254 }, 1065 + { 921600, UINT_MAX } 1066 + }; 1067 + 1068 + /* 1069 + * Quantises the baud rate as per AN205 Table 1 1070 + */ 1071 + static speed_t cp210x_get_an205_rate(speed_t baud) 1072 + { 1073 + int i; 1074 + 1075 + for (i = 0; i < ARRAY_SIZE(cp210x_an205_table1); ++i) { 1076 + if (baud <= cp210x_an205_table1[i].high) 1077 + break; 1078 + } 1079 + 1080 + return cp210x_an205_table1[i].rate; 1081 + } 1082 + 1083 + static speed_t cp210x_get_actual_rate(struct usb_serial *serial, speed_t baud) 1084 + { 1085 + struct cp210x_serial_private *priv = usb_get_serial_data(serial); 1086 + unsigned int prescale = 1; 1087 + unsigned int div; 1088 + 1089 + baud = clamp(baud, 300u, priv->max_speed); 1090 + 1091 + if (baud <= 365) 1092 + prescale = 4; 1093 + 1094 + div = DIV_ROUND_CLOSEST(48000000, 2 * prescale * baud); 1095 + baud = 48000000 / (2 * prescale * div); 1096 + 1097 + return baud; 1098 + } 1099 + 1002 1100 /* 1003 1101 * CP2101 supports the following baud rates: 1004 1102 * ··· 1097 1057 static void cp210x_change_speed(struct tty_struct *tty, 1098 1058 struct usb_serial_port *port, struct ktermios *old_termios) 1099 1059 { 1060 + struct usb_serial *serial = port->serial; 1061 + struct cp210x_serial_private *priv = usb_get_serial_data(serial); 1100 1062 u32 baud; 1101 1063 1102 1064 baud = tty->termios.c_ospeed; 1103 1065 1104 - /* This maps the requested rate to a rate valid on cp2102 or cp2103, 1105 - * or to an arbitrary rate in [1M,2M]. 1066 + /* 1067 + * This maps the requested rate to the actual rate, a valid rate on 1068 + * cp2102 or cp2103, or to an arbitrary rate in [1M, max_speed]. 1106 1069 * 1107 1070 * NOTE: B0 is not implemented. 1108 1071 */ 1109 - baud = cp210x_quantise_baudrate(baud); 1072 + if (priv->use_actual_rate) 1073 + baud = cp210x_get_actual_rate(serial, baud); 1074 + else if (baud < 1000000) 1075 + baud = cp210x_get_an205_rate(baud); 1076 + else if (baud > priv->max_speed) 1077 + baud = priv->max_speed; 1110 1078 1111 1079 dev_dbg(&port->dev, "%s - setting baud rate to %u\n", __func__, baud); 1112 1080 if (cp210x_write_u32_reg(port, CP210X_SET_BAUDRATE, baud)) { ··· 1336 1288 struct usb_serial *serial = gpiochip_get_data(gc); 1337 1289 struct cp210x_serial_private *priv = usb_get_serial_data(serial); 1338 1290 1339 - switch (offset) { 1340 - case 0: 1341 - if (priv->config & CP2105_GPIO0_TXLED_MODE) 1342 - return -ENODEV; 1343 - break; 1344 - case 1: 1345 - if (priv->config & (CP2105_GPIO1_RXLED_MODE | 1346 - CP2105_GPIO1_RS485_MODE)) 1347 - return -ENODEV; 1348 - break; 1349 - } 1291 + if (priv->gpio_altfunc & BIT(offset)) 1292 + return -ENODEV; 1350 1293 1351 1294 return 0; 1352 1295 } ··· 1345 1306 static int cp210x_gpio_get(struct gpio_chip *gc, unsigned int gpio) 1346 1307 { 1347 1308 struct usb_serial *serial = gpiochip_get_data(gc); 1309 + struct cp210x_serial_private *priv = usb_get_serial_data(serial); 1310 + u8 req_type = REQTYPE_DEVICE_TO_HOST; 1348 1311 int result; 1349 1312 u8 buf; 1350 1313 1351 - result = cp210x_read_vendor_block(serial, REQTYPE_INTERFACE_TO_HOST, 1314 + if (priv->partnum == CP210X_PARTNUM_CP2105) 1315 + req_type = REQTYPE_INTERFACE_TO_HOST; 1316 + 1317 + result = cp210x_read_vendor_block(serial, req_type, 1352 1318 CP210X_READ_LATCH, &buf, sizeof(buf)); 1353 1319 if (result < 0) 1354 1320 return result; ··· 1364 1320 static void cp210x_gpio_set(struct gpio_chip *gc, unsigned int gpio, int value) 1365 1321 { 1366 1322 struct usb_serial *serial = gpiochip_get_data(gc); 1323 + struct cp210x_serial_private *priv = usb_get_serial_data(serial); 1367 1324 struct cp210x_gpio_write buf; 1325 + int result; 1368 1326 1369 1327 if (value == 1) 1370 1328 buf.state = BIT(gpio); ··· 1375 1329 1376 1330 buf.mask = BIT(gpio); 1377 1331 1378 - cp210x_write_vendor_block(serial, REQTYPE_HOST_TO_INTERFACE, 1379 - CP210X_WRITE_LATCH, &buf, sizeof(buf)); 1332 + if (priv->partnum == CP210X_PARTNUM_CP2105) { 1333 + result = cp210x_write_vendor_block(serial, 1334 + REQTYPE_HOST_TO_INTERFACE, 1335 + CP210X_WRITE_LATCH, &buf, 1336 + sizeof(buf)); 1337 + } else { 1338 + u16 wIndex = buf.state << 8 | buf.mask; 1339 + 1340 + result = usb_control_msg(serial->dev, 1341 + usb_sndctrlpipe(serial->dev, 0), 1342 + CP210X_VENDOR_SPECIFIC, 1343 + REQTYPE_HOST_TO_DEVICE, 1344 + CP210X_WRITE_LATCH, 1345 + wIndex, 1346 + NULL, 0, USB_CTRL_SET_TIMEOUT); 1347 + } 1348 + 1349 + if (result < 0) { 1350 + dev_err(&serial->interface->dev, "failed to set GPIO value: %d\n", 1351 + result); 1352 + } 1380 1353 } 1381 1354 1382 1355 static int cp210x_gpio_direction_get(struct gpio_chip *gc, unsigned int gpio) 1383 1356 { 1384 - /* Hardware does not support an input mode */ 1385 - return 0; 1357 + struct usb_serial *serial = gpiochip_get_data(gc); 1358 + struct cp210x_serial_private *priv = usb_get_serial_data(serial); 1359 + 1360 + return priv->gpio_input & BIT(gpio); 1386 1361 } 1387 1362 1388 1363 static int cp210x_gpio_direction_input(struct gpio_chip *gc, unsigned int gpio) 1389 1364 { 1390 - /* Hardware does not support an input mode */ 1391 - return -ENOTSUPP; 1365 + struct usb_serial *serial = gpiochip_get_data(gc); 1366 + struct cp210x_serial_private *priv = usb_get_serial_data(serial); 1367 + 1368 + if (priv->partnum == CP210X_PARTNUM_CP2105) { 1369 + /* hardware does not support an input mode */ 1370 + return -ENOTSUPP; 1371 + } 1372 + 1373 + /* push-pull pins cannot be changed to be inputs */ 1374 + if (priv->gpio_pushpull & BIT(gpio)) 1375 + return -EINVAL; 1376 + 1377 + /* make sure to release pin if it is being driven low */ 1378 + cp210x_gpio_set(gc, gpio, 1); 1379 + 1380 + priv->gpio_input |= BIT(gpio); 1381 + 1382 + return 0; 1392 1383 } 1393 1384 1394 1385 static int cp210x_gpio_direction_output(struct gpio_chip *gc, unsigned int gpio, 1395 1386 int value) 1396 1387 { 1388 + struct usb_serial *serial = gpiochip_get_data(gc); 1389 + struct cp210x_serial_private *priv = usb_get_serial_data(serial); 1390 + 1391 + priv->gpio_input &= ~BIT(gpio); 1392 + cp210x_gpio_set(gc, gpio, value); 1393 + 1397 1394 return 0; 1398 1395 } 1399 1396 ··· 1449 1360 1450 1361 /* Succeed only if in correct mode (this can't be set at runtime) */ 1451 1362 if ((param == PIN_CONFIG_DRIVE_PUSH_PULL) && 1452 - (priv->gpio_mode & BIT(gpio))) 1363 + (priv->gpio_pushpull & BIT(gpio))) 1453 1364 return 0; 1454 1365 1455 1366 if ((param == PIN_CONFIG_DRIVE_OPEN_DRAIN) && 1456 - !(priv->gpio_mode & BIT(gpio))) 1367 + !(priv->gpio_pushpull & BIT(gpio))) 1457 1368 return 0; 1458 1369 1459 1370 return -ENOTSUPP; ··· 1466 1377 * this driver that provide GPIO do so in a way that does not impact other 1467 1378 * signals and are thus expected to have very different initialisation. 1468 1379 */ 1469 - static int cp2105_shared_gpio_init(struct usb_serial *serial) 1380 + static int cp2105_gpioconf_init(struct usb_serial *serial) 1470 1381 { 1471 1382 struct cp210x_serial_private *priv = usb_get_serial_data(serial); 1472 1383 struct cp210x_pin_mode mode; 1473 1384 struct cp210x_config config; 1474 1385 u8 intf_num = cp210x_interface_num(serial); 1386 + u8 iface_config; 1475 1387 int result; 1476 1388 1477 1389 result = cp210x_read_vendor_block(serial, REQTYPE_DEVICE_TO_HOST, ··· 1489 1399 1490 1400 /* 2 banks of GPIO - One for the pins taken from each serial port */ 1491 1401 if (intf_num == 0) { 1492 - if (mode.eci == CP210X_PIN_MODE_MODEM) 1402 + if (mode.eci == CP210X_PIN_MODE_MODEM) { 1403 + /* mark all GPIOs of this interface as reserved */ 1404 + priv->gpio_altfunc = 0xff; 1493 1405 return 0; 1406 + } 1494 1407 1495 - priv->config = config.eci_cfg; 1496 - priv->gpio_mode = (u8)((le16_to_cpu(config.gpio_mode) & 1408 + iface_config = config.eci_cfg; 1409 + priv->gpio_pushpull = (u8)((le16_to_cpu(config.gpio_mode) & 1497 1410 CP210X_ECI_GPIO_MODE_MASK) >> 1498 1411 CP210X_ECI_GPIO_MODE_OFFSET); 1499 1412 priv->gc.ngpio = 2; 1500 1413 } else if (intf_num == 1) { 1501 - if (mode.sci == CP210X_PIN_MODE_MODEM) 1414 + if (mode.sci == CP210X_PIN_MODE_MODEM) { 1415 + /* mark all GPIOs of this interface as reserved */ 1416 + priv->gpio_altfunc = 0xff; 1502 1417 return 0; 1418 + } 1503 1419 1504 - priv->config = config.sci_cfg; 1505 - priv->gpio_mode = (u8)((le16_to_cpu(config.gpio_mode) & 1420 + iface_config = config.sci_cfg; 1421 + priv->gpio_pushpull = (u8)((le16_to_cpu(config.gpio_mode) & 1506 1422 CP210X_SCI_GPIO_MODE_MASK) >> 1507 1423 CP210X_SCI_GPIO_MODE_OFFSET); 1508 1424 priv->gc.ngpio = 3; 1509 1425 } else { 1510 1426 return -ENODEV; 1511 1427 } 1428 + 1429 + /* mark all pins which are not in GPIO mode */ 1430 + if (iface_config & CP2105_GPIO0_TXLED_MODE) /* GPIO 0 */ 1431 + priv->gpio_altfunc |= BIT(0); 1432 + if (iface_config & (CP2105_GPIO1_RXLED_MODE | /* GPIO 1 */ 1433 + CP2105_GPIO1_RS485_MODE)) 1434 + priv->gpio_altfunc |= BIT(1); 1435 + 1436 + /* driver implementation for CP2105 only supports outputs */ 1437 + priv->gpio_input = 0; 1438 + 1439 + return 0; 1440 + } 1441 + 1442 + static int cp2102n_gpioconf_init(struct usb_serial *serial) 1443 + { 1444 + struct cp210x_serial_private *priv = usb_get_serial_data(serial); 1445 + const u16 config_size = 0x02a6; 1446 + u8 gpio_rst_latch; 1447 + u8 config_version; 1448 + u8 gpio_pushpull; 1449 + u8 *config_buf; 1450 + u8 gpio_latch; 1451 + u8 gpio_ctrl; 1452 + int result; 1453 + u8 i; 1454 + 1455 + /* 1456 + * Retrieve device configuration from the device. 1457 + * The array received contains all customization settings done at the 1458 + * factory/manufacturer. Format of the array is documented at the 1459 + * time of writing at: 1460 + * https://www.silabs.com/community/interface/knowledge-base.entry.html/2017/03/31/cp2102n_setconfig-xsfa 1461 + */ 1462 + config_buf = kmalloc(config_size, GFP_KERNEL); 1463 + if (!config_buf) 1464 + return -ENOMEM; 1465 + 1466 + result = cp210x_read_vendor_block(serial, 1467 + REQTYPE_DEVICE_TO_HOST, 1468 + CP210X_READ_2NCONFIG, 1469 + config_buf, 1470 + config_size); 1471 + if (result < 0) { 1472 + kfree(config_buf); 1473 + return result; 1474 + } 1475 + 1476 + config_version = config_buf[CP210X_2NCONFIG_CONFIG_VERSION_IDX]; 1477 + gpio_pushpull = config_buf[CP210X_2NCONFIG_GPIO_MODE_IDX]; 1478 + gpio_ctrl = config_buf[CP210X_2NCONFIG_GPIO_CONTROL_IDX]; 1479 + gpio_rst_latch = config_buf[CP210X_2NCONFIG_GPIO_RSTLATCH_IDX]; 1480 + 1481 + kfree(config_buf); 1482 + 1483 + /* Make sure this is a config format we understand. */ 1484 + if (config_version != 0x01) 1485 + return -ENOTSUPP; 1486 + 1487 + /* 1488 + * We only support 4 GPIOs even on the QFN28 package, because 1489 + * config locations of GPIOs 4-6 determined using reverse 1490 + * engineering revealed conflicting offsets with other 1491 + * documented functions. So we'll just play it safe for now. 1492 + */ 1493 + priv->gc.ngpio = 4; 1494 + 1495 + /* 1496 + * Get default pin states after reset. Needed so we can determine 1497 + * the direction of an open-drain pin. 1498 + */ 1499 + gpio_latch = (gpio_rst_latch >> 3) & 0x0f; 1500 + 1501 + /* 0 indicates open-drain mode, 1 is push-pull */ 1502 + priv->gpio_pushpull = (gpio_pushpull >> 3) & 0x0f; 1503 + 1504 + /* 0 indicates GPIO mode, 1 is alternate function */ 1505 + priv->gpio_altfunc = (gpio_ctrl >> 2) & 0x0f; 1506 + 1507 + /* 1508 + * The CP2102N does not strictly has input and output pin modes, 1509 + * it only knows open-drain and push-pull modes which is set at 1510 + * factory. An open-drain pin can function both as an 1511 + * input or an output. We emulate input mode for open-drain pins 1512 + * by making sure they are not driven low, and we do not allow 1513 + * push-pull pins to be set as an input. 1514 + */ 1515 + for (i = 0; i < priv->gc.ngpio; ++i) { 1516 + /* 1517 + * Set direction to "input" iff pin is open-drain and reset 1518 + * value is 1. 1519 + */ 1520 + if (!(priv->gpio_pushpull & BIT(i)) && (gpio_latch & BIT(i))) 1521 + priv->gpio_input |= BIT(i); 1522 + } 1523 + 1524 + return 0; 1525 + } 1526 + 1527 + static int cp210x_gpio_init(struct usb_serial *serial) 1528 + { 1529 + struct cp210x_serial_private *priv = usb_get_serial_data(serial); 1530 + int result; 1531 + 1532 + switch (priv->partnum) { 1533 + case CP210X_PARTNUM_CP2105: 1534 + result = cp2105_gpioconf_init(serial); 1535 + break; 1536 + case CP210X_PARTNUM_CP2102N_QFN28: 1537 + case CP210X_PARTNUM_CP2102N_QFN24: 1538 + case CP210X_PARTNUM_CP2102N_QFN20: 1539 + result = cp2102n_gpioconf_init(serial); 1540 + break; 1541 + default: 1542 + return 0; 1543 + } 1544 + 1545 + if (result < 0) 1546 + return result; 1512 1547 1513 1548 priv->gc.label = "cp210x"; 1514 1549 priv->gc.request = cp210x_gpio_request; ··· 1667 1452 1668 1453 #else 1669 1454 1670 - static int cp2105_shared_gpio_init(struct usb_serial *serial) 1455 + static int cp210x_gpio_init(struct usb_serial *serial) 1671 1456 { 1672 1457 return 0; 1673 1458 } ··· 1712 1497 return 0; 1713 1498 } 1714 1499 1500 + static void cp210x_init_max_speed(struct usb_serial *serial) 1501 + { 1502 + struct cp210x_serial_private *priv = usb_get_serial_data(serial); 1503 + bool use_actual_rate = false; 1504 + speed_t max; 1505 + 1506 + switch (priv->partnum) { 1507 + case CP210X_PARTNUM_CP2101: 1508 + max = 921600; 1509 + break; 1510 + case CP210X_PARTNUM_CP2102: 1511 + case CP210X_PARTNUM_CP2103: 1512 + max = 1000000; 1513 + break; 1514 + case CP210X_PARTNUM_CP2104: 1515 + use_actual_rate = true; 1516 + max = 2000000; 1517 + break; 1518 + case CP210X_PARTNUM_CP2108: 1519 + max = 2000000; 1520 + break; 1521 + case CP210X_PARTNUM_CP2105: 1522 + if (cp210x_interface_num(serial) == 0) { 1523 + use_actual_rate = true; 1524 + max = 2000000; /* ECI */ 1525 + } else { 1526 + max = 921600; /* SCI */ 1527 + } 1528 + break; 1529 + case CP210X_PARTNUM_CP2102N_QFN28: 1530 + case CP210X_PARTNUM_CP2102N_QFN24: 1531 + case CP210X_PARTNUM_CP2102N_QFN20: 1532 + use_actual_rate = true; 1533 + max = 3000000; 1534 + break; 1535 + default: 1536 + max = 2000000; 1537 + break; 1538 + } 1539 + 1540 + priv->max_speed = max; 1541 + priv->use_actual_rate = use_actual_rate; 1542 + } 1543 + 1715 1544 static int cp210x_attach(struct usb_serial *serial) 1716 1545 { 1717 1546 int result; ··· 1776 1517 1777 1518 usb_set_serial_data(serial, priv); 1778 1519 1779 - if (priv->partnum == CP210X_PARTNUM_CP2105) { 1780 - result = cp2105_shared_gpio_init(serial); 1781 - if (result < 0) { 1782 - dev_err(&serial->interface->dev, 1783 - "GPIO initialisation failed, continuing without GPIO support\n"); 1784 - } 1520 + cp210x_init_max_speed(serial); 1521 + 1522 + result = cp210x_gpio_init(serial); 1523 + if (result < 0) { 1524 + dev_err(&serial->interface->dev, "GPIO initialisation failed: %d\n", 1525 + result); 1785 1526 } 1786 1527 1787 1528 return 0;
+10 -7
drivers/usb/serial/cyberjack.c
··· 255 255 struct device *dev = &port->dev; 256 256 unsigned char *data = urb->transfer_buffer; 257 257 int status = urb->status; 258 + unsigned long flags; 258 259 int result; 259 260 260 261 /* the urb might have been killed. */ ··· 271 270 /* This is a announcement of coming bulk_ins. */ 272 271 unsigned short size = ((unsigned short)data[3]<<8)+data[2]+3; 273 272 274 - spin_lock(&priv->lock); 273 + spin_lock_irqsave(&priv->lock, flags); 275 274 276 275 old_rdtodo = priv->rdtodo; 277 276 278 277 if (old_rdtodo > SHRT_MAX - size) { 279 278 dev_dbg(dev, "To many bulk_in urbs to do.\n"); 280 - spin_unlock(&priv->lock); 279 + spin_unlock_irqrestore(&priv->lock, flags); 281 280 goto resubmit; 282 281 } 283 282 ··· 286 285 287 286 dev_dbg(dev, "%s - rdtodo: %d\n", __func__, priv->rdtodo); 288 287 289 - spin_unlock(&priv->lock); 288 + spin_unlock_irqrestore(&priv->lock, flags); 290 289 291 290 if (!old_rdtodo) { 292 291 result = usb_submit_urb(port->read_urb, GFP_ATOMIC); ··· 310 309 struct cyberjack_private *priv = usb_get_serial_port_data(port); 311 310 struct device *dev = &port->dev; 312 311 unsigned char *data = urb->transfer_buffer; 312 + unsigned long flags; 313 313 short todo; 314 314 int result; 315 315 int status = urb->status; ··· 327 325 tty_flip_buffer_push(&port->port); 328 326 } 329 327 330 - spin_lock(&priv->lock); 328 + spin_lock_irqsave(&priv->lock, flags); 331 329 332 330 /* Reduce urbs to do by one. */ 333 331 priv->rdtodo -= urb->actual_length; ··· 336 334 priv->rdtodo = 0; 337 335 todo = priv->rdtodo; 338 336 339 - spin_unlock(&priv->lock); 337 + spin_unlock_irqrestore(&priv->lock, flags); 340 338 341 339 dev_dbg(dev, "%s - rdtodo: %d\n", __func__, todo); 342 340 ··· 356 354 struct cyberjack_private *priv = usb_get_serial_port_data(port); 357 355 struct device *dev = &port->dev; 358 356 int status = urb->status; 357 + unsigned long flags; 359 358 360 359 set_bit(0, &port->write_urbs_free); 361 360 if (status) { ··· 365 362 return; 366 363 } 367 364 368 - spin_lock(&priv->lock); 365 + spin_lock_irqsave(&priv->lock, flags); 369 366 370 367 /* only do something if we have more data to send */ 371 368 if (priv->wrfilled) { ··· 409 406 } 410 407 411 408 exit: 412 - spin_unlock(&priv->lock); 409 + spin_unlock_irqrestore(&priv->lock, flags); 413 410 usb_serial_port_softint(port); 414 411 } 415 412
+19 -16
drivers/usb/serial/digi_acceleport.c
··· 984 984 struct usb_serial *serial; 985 985 struct digi_port *priv; 986 986 struct digi_serial *serial_priv; 987 + unsigned long flags; 987 988 int ret = 0; 988 989 int status = urb->status; 989 990 ··· 1005 1004 /* handle oob callback */ 1006 1005 if (priv->dp_port_num == serial_priv->ds_oob_port_num) { 1007 1006 dev_dbg(&port->dev, "digi_write_bulk_callback: oob callback\n"); 1008 - spin_lock(&priv->dp_port_lock); 1007 + spin_lock_irqsave(&priv->dp_port_lock, flags); 1009 1008 priv->dp_write_urb_in_use = 0; 1010 1009 wake_up_interruptible(&port->write_wait); 1011 - spin_unlock(&priv->dp_port_lock); 1010 + spin_unlock_irqrestore(&priv->dp_port_lock, flags); 1012 1011 return; 1013 1012 } 1014 1013 1015 1014 /* try to send any buffered data on this port */ 1016 - spin_lock(&priv->dp_port_lock); 1015 + spin_lock_irqsave(&priv->dp_port_lock, flags); 1017 1016 priv->dp_write_urb_in_use = 0; 1018 1017 if (priv->dp_out_buf_len > 0) { 1019 1018 *((unsigned char *)(port->write_urb->transfer_buffer)) ··· 1036 1035 /* lost the race in write_chan(). */ 1037 1036 schedule_work(&priv->dp_wakeup_work); 1038 1037 1039 - spin_unlock(&priv->dp_port_lock); 1038 + spin_unlock_irqrestore(&priv->dp_port_lock, flags); 1040 1039 if (ret && ret != -EPERM) 1041 1040 dev_err_console(port, 1042 1041 "%s: usb_submit_urb failed, ret=%d, port=%d\n", ··· 1382 1381 struct usb_serial_port *port = urb->context; 1383 1382 struct digi_port *priv = usb_get_serial_port_data(port); 1384 1383 unsigned char *buf = urb->transfer_buffer; 1384 + unsigned long flags; 1385 1385 int opcode; 1386 1386 int len; 1387 1387 int port_status; 1388 1388 unsigned char *data; 1389 - int flag, throttled; 1389 + int tty_flag, throttled; 1390 1390 1391 1391 /* short/multiple packet check */ 1392 1392 if (urb->actual_length < 2) { ··· 1409 1407 return -1; 1410 1408 } 1411 1409 1412 - spin_lock(&priv->dp_port_lock); 1410 + spin_lock_irqsave(&priv->dp_port_lock, flags); 1413 1411 1414 1412 /* check for throttle; if set, do not resubmit read urb */ 1415 1413 /* indicate the read chain needs to be restarted on unthrottle */ ··· 1423 1421 data = &buf[3]; 1424 1422 1425 1423 /* get flag from port_status */ 1426 - flag = 0; 1424 + tty_flag = 0; 1427 1425 1428 1426 /* overrun is special, not associated with a char */ 1429 1427 if (port_status & DIGI_OVERRUN_ERROR) ··· 1432 1430 /* break takes precedence over parity, */ 1433 1431 /* which takes precedence over framing errors */ 1434 1432 if (port_status & DIGI_BREAK_ERROR) 1435 - flag = TTY_BREAK; 1433 + tty_flag = TTY_BREAK; 1436 1434 else if (port_status & DIGI_PARITY_ERROR) 1437 - flag = TTY_PARITY; 1435 + tty_flag = TTY_PARITY; 1438 1436 else if (port_status & DIGI_FRAMING_ERROR) 1439 - flag = TTY_FRAME; 1437 + tty_flag = TTY_FRAME; 1440 1438 1441 1439 /* data length is len-1 (one byte of len is port_status) */ 1442 1440 --len; 1443 1441 if (len > 0) { 1444 1442 tty_insert_flip_string_fixed_flag(&port->port, data, 1445 - flag, len); 1443 + tty_flag, len); 1446 1444 tty_flip_buffer_push(&port->port); 1447 1445 } 1448 1446 } 1449 - spin_unlock(&priv->dp_port_lock); 1447 + spin_unlock_irqrestore(&priv->dp_port_lock, flags); 1450 1448 1451 1449 if (opcode == DIGI_CMD_RECEIVE_DISABLE) 1452 1450 dev_dbg(&port->dev, "%s: got RECEIVE_DISABLE\n", __func__); ··· 1476 1474 struct digi_port *priv = usb_get_serial_port_data(port); 1477 1475 unsigned char *buf = urb->transfer_buffer; 1478 1476 int opcode, line, status, val; 1477 + unsigned long flags; 1479 1478 int i; 1480 1479 unsigned int rts; 1481 1480 ··· 1509 1506 rts = C_CRTSCTS(tty); 1510 1507 1511 1508 if (tty && opcode == DIGI_CMD_READ_INPUT_SIGNALS) { 1512 - spin_lock(&priv->dp_port_lock); 1509 + spin_lock_irqsave(&priv->dp_port_lock, flags); 1513 1510 /* convert from digi flags to termiox flags */ 1514 1511 if (val & DIGI_READ_INPUT_SIGNALS_CTS) { 1515 1512 priv->dp_modem_signals |= TIOCM_CTS; ··· 1533 1530 else 1534 1531 priv->dp_modem_signals &= ~TIOCM_CD; 1535 1532 1536 - spin_unlock(&priv->dp_port_lock); 1533 + spin_unlock_irqrestore(&priv->dp_port_lock, flags); 1537 1534 } else if (opcode == DIGI_CMD_TRANSMIT_IDLE) { 1538 - spin_lock(&priv->dp_port_lock); 1535 + spin_lock_irqsave(&priv->dp_port_lock, flags); 1539 1536 priv->dp_transmit_idle = 1; 1540 1537 wake_up_interruptible(&priv->dp_transmit_idle_wait); 1541 - spin_unlock(&priv->dp_port_lock); 1538 + spin_unlock_irqrestore(&priv->dp_port_lock, flags); 1542 1539 } else if (opcode == DIGI_CMD_IFLUSH_FIFO) { 1543 1540 wake_up_interruptible(&priv->dp_flush_wait); 1544 1541 }
+11 -6
drivers/usb/serial/io_edgeport.c
··· 648 648 struct usb_serial_port *port; 649 649 unsigned char *data = urb->transfer_buffer; 650 650 int length = urb->actual_length; 651 + unsigned long flags; 651 652 int bytes_avail; 652 653 int position; 653 654 int txCredits; ··· 680 679 if (length > 1) { 681 680 bytes_avail = data[0] | (data[1] << 8); 682 681 if (bytes_avail) { 683 - spin_lock(&edge_serial->es_lock); 682 + spin_lock_irqsave(&edge_serial->es_lock, flags); 684 683 edge_serial->rxBytesAvail += bytes_avail; 685 684 dev_dbg(dev, 686 685 "%s - bytes_avail=%d, rxBytesAvail=%d, read_in_progress=%d\n", ··· 703 702 edge_serial->read_in_progress = false; 704 703 } 705 704 } 706 - spin_unlock(&edge_serial->es_lock); 705 + spin_unlock_irqrestore(&edge_serial->es_lock, 706 + flags); 707 707 } 708 708 } 709 709 /* grab the txcredits for the ports if available */ ··· 717 715 port = edge_serial->serial->port[portNumber]; 718 716 edge_port = usb_get_serial_port_data(port); 719 717 if (edge_port->open) { 720 - spin_lock(&edge_port->ep_lock); 718 + spin_lock_irqsave(&edge_port->ep_lock, 719 + flags); 721 720 edge_port->txCredits += txCredits; 722 - spin_unlock(&edge_port->ep_lock); 721 + spin_unlock_irqrestore(&edge_port->ep_lock, 722 + flags); 723 723 dev_dbg(dev, "%s - txcredits for port%d = %d\n", 724 724 __func__, portNumber, 725 725 edge_port->txCredits); ··· 762 758 int retval; 763 759 __u16 raw_data_length; 764 760 int status = urb->status; 761 + unsigned long flags; 765 762 766 763 if (status) { 767 764 dev_dbg(&urb->dev->dev, "%s - nonzero read bulk status received: %d\n", ··· 782 777 783 778 usb_serial_debug_data(dev, __func__, raw_data_length, data); 784 779 785 - spin_lock(&edge_serial->es_lock); 780 + spin_lock_irqsave(&edge_serial->es_lock, flags); 786 781 787 782 /* decrement our rxBytes available by the number that we just got */ 788 783 edge_serial->rxBytesAvail -= raw_data_length; ··· 806 801 edge_serial->read_in_progress = false; 807 802 } 808 803 809 - spin_unlock(&edge_serial->es_lock); 804 + spin_unlock_irqrestore(&edge_serial->es_lock, flags); 810 805 } 811 806 812 807
+3 -2
drivers/usb/serial/io_ti.c
··· 1729 1729 struct edgeport_port *edge_port = urb->context; 1730 1730 struct device *dev = &edge_port->port->dev; 1731 1731 unsigned char *data = urb->transfer_buffer; 1732 + unsigned long flags; 1732 1733 int retval = 0; 1733 1734 int port_number; 1734 1735 int status = urb->status; ··· 1781 1780 1782 1781 exit: 1783 1782 /* continue read unless stopped */ 1784 - spin_lock(&edge_port->ep_lock); 1783 + spin_lock_irqsave(&edge_port->ep_lock, flags); 1785 1784 if (edge_port->ep_read_urb_state == EDGE_READ_URB_RUNNING) 1786 1785 retval = usb_submit_urb(urb, GFP_ATOMIC); 1787 1786 else if (edge_port->ep_read_urb_state == EDGE_READ_URB_STOPPING) 1788 1787 edge_port->ep_read_urb_state = EDGE_READ_URB_STOPPED; 1789 1788 1790 - spin_unlock(&edge_port->ep_lock); 1789 + spin_unlock_irqrestore(&edge_port->ep_lock, flags); 1791 1790 if (retval) 1792 1791 dev_err(dev, "%s - usb_submit_urb failed with result %d\n", __func__, retval); 1793 1792 }
+1 -1
drivers/usb/serial/ir-usb.c
··· 132 132 0, ifnum, desc, sizeof(*desc), 1000); 133 133 134 134 dev_dbg(&serial->dev->dev, "%s - ret=%d\n", __func__, ret); 135 - if (ret < sizeof(*desc)) { 135 + if (ret < (int)sizeof(*desc)) { 136 136 dev_dbg(&serial->dev->dev, 137 137 "%s - class descriptor read %s (%d)\n", __func__, 138 138 (ret < 0) ? "failed" : "too short", ret);
-5
drivers/usb/serial/iuu_phoenix.c
··· 58 58 u8 *buf; /* used for initialize speed */ 59 59 u8 len; 60 60 int vcc; /* vcc (either 3 or 5 V) */ 61 - u32 baud; 62 61 u32 boost; 63 62 u32 clk; 64 63 }; ··· 962 963 struct iuu_private *priv = usb_get_serial_port_data(port); 963 964 964 965 baud = tty->termios.c_ospeed; 965 - tty->termios.c_ispeed = baud; 966 - /* Re-encode speed */ 967 - tty_encode_baud_rate(tty, baud, baud); 968 966 969 967 dev_dbg(dev, "%s - baud %d\n", __func__, baud); 970 968 usb_clear_halt(serial->dev, port->write_urb->pipe); ··· 987 991 if (boost < 100) 988 992 boost = 100; 989 993 priv->boost = boost; 990 - priv->baud = baud; 991 994 switch (clockmode) { 992 995 case 2: /* 3.680 Mhz */ 993 996 priv->clk = IUU_CLK_3680000;
-1
drivers/usb/serial/kl5kusb105.c
··· 67 67 */ 68 68 static const struct usb_device_id id_table[] = { 69 69 { USB_DEVICE(PALMCONNECT_VID, PALMCONNECT_PID) }, 70 - { USB_DEVICE(KLSI_VID, KLSI_KL5KUSB105D_PID) }, 71 70 { } /* Terminating entry */ 72 71 }; 73 72
-3
drivers/usb/serial/kl5kusb105.h
··· 7 7 #define PALMCONNECT_VID 0x0830 8 8 #define PALMCONNECT_PID 0x0080 9 9 10 - #define KLSI_VID 0x05e9 11 - #define KLSI_KL5KUSB105D_PID 0x00c0 12 - 13 10 /* Vendor commands: */ 14 11 15 12
+18 -6
drivers/usb/serial/kobil_sct.c
··· 190 190 KOBIL_TIMEOUT 191 191 ); 192 192 dev_dbg(dev, "%s - Send get_HW_version URB returns: %i\n", __func__, result); 193 - dev_dbg(dev, "Hardware version: %i.%i.%i\n", transfer_buffer[0], 194 - transfer_buffer[1], transfer_buffer[2]); 193 + if (result >= 3) { 194 + dev_dbg(dev, "Hardware version: %i.%i.%i\n", transfer_buffer[0], 195 + transfer_buffer[1], transfer_buffer[2]); 196 + } 195 197 196 198 /* get firmware version */ 197 199 result = usb_control_msg(port->serial->dev, ··· 207 205 KOBIL_TIMEOUT 208 206 ); 209 207 dev_dbg(dev, "%s - Send get_FW_version URB returns: %i\n", __func__, result); 210 - dev_dbg(dev, "Firmware version: %i.%i.%i\n", transfer_buffer[0], 211 - transfer_buffer[1], transfer_buffer[2]); 208 + if (result >= 3) { 209 + dev_dbg(dev, "Firmware version: %i.%i.%i\n", transfer_buffer[0], 210 + transfer_buffer[1], transfer_buffer[2]); 211 + } 212 212 213 213 if (priv->device_type == KOBIL_ADAPTER_B_PRODUCT_ID || 214 214 priv->device_type == KOBIL_ADAPTER_K_PRODUCT_ID) { ··· 397 393 transfer_buffer_length, 398 394 KOBIL_TIMEOUT); 399 395 400 - dev_dbg(&port->dev, "%s - Send get_status_line_state URB returns: %i. Statusline: %02x\n", 401 - __func__, result, transfer_buffer[0]); 396 + dev_dbg(&port->dev, "Send get_status_line_state URB returns: %i\n", 397 + result); 398 + if (result < 1) { 399 + if (result >= 0) 400 + result = -EIO; 401 + goto out_free; 402 + } 403 + 404 + dev_dbg(&port->dev, "Statusline: %02x\n", transfer_buffer[0]); 402 405 403 406 result = 0; 404 407 if ((transfer_buffer[0] & SUSBCR_GSL_DSR) != 0) 405 408 result = TIOCM_DSR; 409 + out_free: 406 410 kfree(transfer_buffer); 407 411 return result; 408 412 }
+3 -11
drivers/usb/serial/mos7720.c
··· 340 340 { 341 341 struct urbtracker *urbtrack = urb->context; 342 342 int status = urb->status; 343 + unsigned long flags; 343 344 344 345 if (unlikely(status)) 345 346 dev_dbg(&urb->dev->dev, "%s - nonzero urb status received: %d\n", __func__, status); 346 347 347 348 /* remove the urbtracker from the active_urbs list */ 348 - spin_lock(&urbtrack->mos_parport->listlock); 349 + spin_lock_irqsave(&urbtrack->mos_parport->listlock, flags); 349 350 list_del(&urbtrack->urblist_entry); 350 - spin_unlock(&urbtrack->mos_parport->listlock); 351 + spin_unlock_irqrestore(&urbtrack->mos_parport->listlock, flags); 351 352 kref_put(&urbtrack->ref_count, destroy_urbtracker); 352 353 } 353 354 ··· 1527 1526 struct usb_serial *serial; 1528 1527 int baud; 1529 1528 unsigned cflag; 1530 - unsigned iflag; 1531 - __u8 mask = 0xff; 1532 1529 __u8 lData; 1533 1530 __u8 lParity; 1534 1531 __u8 lStop; ··· 1550 1551 lParity = 0x00; /* No parity */ 1551 1552 1552 1553 cflag = tty->termios.c_cflag; 1553 - iflag = tty->termios.c_iflag; 1554 1554 1555 1555 /* Change the number of bits */ 1556 1556 switch (cflag & CSIZE) { 1557 1557 case CS5: 1558 1558 lData = UART_LCR_WLEN5; 1559 - mask = 0x1f; 1560 1559 break; 1561 1560 1562 1561 case CS6: 1563 1562 lData = UART_LCR_WLEN6; 1564 - mask = 0x3f; 1565 1563 break; 1566 1564 1567 1565 case CS7: 1568 1566 lData = UART_LCR_WLEN7; 1569 - mask = 0x7f; 1570 1567 break; 1571 1568 default: 1572 1569 case CS8: ··· 1680 1685 struct usb_serial_port *port, struct ktermios *old_termios) 1681 1686 { 1682 1687 int status; 1683 - struct usb_serial *serial; 1684 1688 struct moschip_port *mos7720_port; 1685 - 1686 - serial = port->serial; 1687 1689 1688 1690 mos7720_port = usb_get_serial_port_data(port); 1689 1691
+3 -2
drivers/usb/serial/mos7840.c
··· 805 805 struct moschip_port *mos7840_port; 806 806 struct usb_serial_port *port; 807 807 int status = urb->status; 808 + unsigned long flags; 808 809 int i; 809 810 810 811 mos7840_port = urb->context; 811 812 port = mos7840_port->port; 812 - spin_lock(&mos7840_port->pool_lock); 813 + spin_lock_irqsave(&mos7840_port->pool_lock, flags); 813 814 for (i = 0; i < NUM_URBS; i++) { 814 815 if (urb == mos7840_port->write_urb_pool[i]) { 815 816 mos7840_port->busy[i] = 0; 816 817 break; 817 818 } 818 819 } 819 - spin_unlock(&mos7840_port->pool_lock); 820 + spin_unlock_irqrestore(&mos7840_port->pool_lock, flags); 820 821 821 822 if (status) { 822 823 dev_dbg(&port->dev, "nonzero write bulk status received:%d\n", status);
+4
drivers/usb/serial/option.c
··· 196 196 #define DELL_PRODUCT_5800_V2_MINICARD_VZW 0x8196 /* Novatel E362 */ 197 197 #define DELL_PRODUCT_5804_MINICARD_ATT 0x819b /* Novatel E371 */ 198 198 199 + #define DELL_PRODUCT_5821E 0x81d7 200 + 199 201 #define KYOCERA_VENDOR_ID 0x0c88 200 202 #define KYOCERA_PRODUCT_KPC650 0x17da 201 203 #define KYOCERA_PRODUCT_KPC680 0x180a ··· 1032 1030 { USB_DEVICE_AND_INTERFACE_INFO(DELL_VENDOR_ID, DELL_PRODUCT_5800_MINICARD_VZW, 0xff, 0xff, 0xff) }, 1033 1031 { USB_DEVICE_AND_INTERFACE_INFO(DELL_VENDOR_ID, DELL_PRODUCT_5800_V2_MINICARD_VZW, 0xff, 0xff, 0xff) }, 1034 1032 { USB_DEVICE_AND_INTERFACE_INFO(DELL_VENDOR_ID, DELL_PRODUCT_5804_MINICARD_ATT, 0xff, 0xff, 0xff) }, 1033 + { USB_DEVICE(DELL_VENDOR_ID, DELL_PRODUCT_5821E), 1034 + .driver_info = RSVD(0) | RSVD(1) | RSVD(6) }, 1035 1035 { USB_DEVICE(ANYDATA_VENDOR_ID, ANYDATA_PRODUCT_ADU_E100A) }, /* ADU-E100, ADU-310 */ 1036 1036 { USB_DEVICE(ANYDATA_VENDOR_ID, ANYDATA_PRODUCT_ADU_500A) }, 1037 1037 { USB_DEVICE(ANYDATA_VENDOR_ID, ANYDATA_PRODUCT_ADU_620UW) },
+2
drivers/usb/serial/pl2303.c
··· 52 52 .driver_info = PL2303_QUIRK_ENDPOINT_HACK }, 53 53 { USB_DEVICE(ATEN_VENDOR_ID, ATEN_PRODUCT_UC485), 54 54 .driver_info = PL2303_QUIRK_ENDPOINT_HACK }, 55 + { USB_DEVICE(ATEN_VENDOR_ID, ATEN_PRODUCT_UC232B), 56 + .driver_info = PL2303_QUIRK_ENDPOINT_HACK }, 55 57 { USB_DEVICE(ATEN_VENDOR_ID, ATEN_PRODUCT_ID2) }, 56 58 { USB_DEVICE(ATEN_VENDOR_ID2, ATEN_PRODUCT_ID) }, 57 59 { USB_DEVICE(ELCOM_VENDOR_ID, ELCOM_PRODUCT_ID) },
+1
drivers/usb/serial/pl2303.h
··· 24 24 #define ATEN_VENDOR_ID2 0x0547 25 25 #define ATEN_PRODUCT_ID 0x2008 26 26 #define ATEN_PRODUCT_UC485 0x2021 27 + #define ATEN_PRODUCT_UC232B 0x2022 27 28 #define ATEN_PRODUCT_ID2 0x2118 28 29 29 30 #define IODATA_VENDOR_ID 0x04bb
+4 -3
drivers/usb/serial/quatech2.c
··· 194 194 ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), 195 195 QT_SET_GET_REGISTER, 0xc0, reg, 196 196 uart, data, sizeof(*data), QT2_USB_TIMEOUT); 197 - if (ret < sizeof(*data)) { 197 + if (ret < (int)sizeof(*data)) { 198 198 if (ret >= 0) 199 199 ret = -EIO; 200 200 } ··· 621 621 { 622 622 struct usb_serial_port *port; 623 623 struct qt2_port_private *port_priv; 624 + unsigned long flags; 624 625 625 626 port = urb->context; 626 627 port_priv = usb_get_serial_port_data(port); 627 628 628 - spin_lock(&port_priv->urb_lock); 629 + spin_lock_irqsave(&port_priv->urb_lock, flags); 629 630 630 631 port_priv->urb_in_use = false; 631 632 usb_serial_port_softint(port); 632 633 633 - spin_unlock(&port_priv->urb_lock); 634 + spin_unlock_irqrestore(&port_priv->urb_lock, flags); 634 635 635 636 } 636 637
+7 -6
drivers/usb/serial/sierra.c
··· 409 409 struct sierra_port_private *portdata = usb_get_serial_port_data(port); 410 410 struct sierra_intf_private *intfdata; 411 411 int status = urb->status; 412 + unsigned long flags; 412 413 413 414 intfdata = usb_get_serial_data(port->serial); 414 415 ··· 420 419 dev_dbg(&port->dev, "%s - nonzero write bulk status " 421 420 "received: %d\n", __func__, status); 422 421 423 - spin_lock(&portdata->lock); 422 + spin_lock_irqsave(&portdata->lock, flags); 424 423 --portdata->outstanding_urbs; 425 - spin_unlock(&portdata->lock); 426 - spin_lock(&intfdata->susp_lock); 424 + spin_unlock_irqrestore(&portdata->lock, flags); 425 + spin_lock_irqsave(&intfdata->susp_lock, flags); 427 426 --intfdata->in_flight; 428 - spin_unlock(&intfdata->susp_lock); 427 + spin_unlock_irqrestore(&intfdata->susp_lock, flags); 429 428 430 429 usb_serial_port_softint(port); 431 430 } ··· 771 770 kfree(urb->transfer_buffer); 772 771 usb_free_urb(urb); 773 772 usb_autopm_put_interface_async(serial->interface); 774 - spin_lock(&portdata->lock); 773 + spin_lock_irq(&portdata->lock); 775 774 portdata->outstanding_urbs--; 776 - spin_unlock(&portdata->lock); 775 + spin_unlock_irq(&portdata->lock); 777 776 } 778 777 779 778 sierra_stop_rx_urbs(port);
+1 -1
drivers/usb/serial/ssu100.c
··· 104 104 ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), 105 105 QT_SET_GET_REGISTER, 0xc0, reg, 106 106 uart, data, sizeof(*data), 300); 107 - if (ret < sizeof(*data)) { 107 + if (ret < (int)sizeof(*data)) { 108 108 if (ret >= 0) 109 109 ret = -EIO; 110 110 }
+3 -2
drivers/usb/serial/symbolserial.c
··· 35 35 struct symbol_private *priv = usb_get_serial_port_data(port); 36 36 unsigned char *data = urb->transfer_buffer; 37 37 int status = urb->status; 38 + unsigned long flags; 38 39 int result; 39 40 int data_length; 40 41 ··· 74 73 } 75 74 76 75 exit: 77 - spin_lock(&priv->lock); 76 + spin_lock_irqsave(&priv->lock, flags); 78 77 79 78 /* Continue trying to always read if we should */ 80 79 if (!priv->throttled) { ··· 85 84 __func__, result); 86 85 } else 87 86 priv->actually_throttled = true; 88 - spin_unlock(&priv->lock); 87 + spin_unlock_irqrestore(&priv->lock, flags); 89 88 } 90 89 91 90 static int symbol_open(struct tty_struct *tty, struct usb_serial_port *port)
+5 -4
drivers/usb/serial/ti_usb_3410_5052.c
··· 1215 1215 struct usb_serial_port *port = tport->tp_port; 1216 1216 struct device *dev = &urb->dev->dev; 1217 1217 int status = urb->status; 1218 + unsigned long flags; 1218 1219 int retval = 0; 1219 1220 1220 1221 switch (status) { ··· 1248 1247 __func__); 1249 1248 else 1250 1249 ti_recv(port, urb->transfer_buffer, urb->actual_length); 1251 - spin_lock(&tport->tp_lock); 1250 + spin_lock_irqsave(&tport->tp_lock, flags); 1252 1251 port->icount.rx += urb->actual_length; 1253 - spin_unlock(&tport->tp_lock); 1252 + spin_unlock_irqrestore(&tport->tp_lock, flags); 1254 1253 } 1255 1254 1256 1255 exit: 1257 1256 /* continue to read unless stopping */ 1258 - spin_lock(&tport->tp_lock); 1257 + spin_lock_irqsave(&tport->tp_lock, flags); 1259 1258 if (tport->tp_read_urb_state == TI_READ_URB_RUNNING) 1260 1259 retval = usb_submit_urb(urb, GFP_ATOMIC); 1261 1260 else if (tport->tp_read_urb_state == TI_READ_URB_STOPPING) 1262 1261 tport->tp_read_urb_state = TI_READ_URB_STOPPED; 1263 1262 1264 - spin_unlock(&tport->tp_lock); 1263 + spin_unlock_irqrestore(&tport->tp_lock, flags); 1265 1264 if (retval) 1266 1265 dev_err(dev, "%s - resubmit read urb failed, %d\n", 1267 1266 __func__, retval);
+3 -2
drivers/usb/serial/usb_wwan.c
··· 326 326 struct usb_serial_port *port; 327 327 struct usb_wwan_port_private *portdata; 328 328 struct usb_wwan_intf_private *intfdata; 329 + unsigned long flags; 329 330 int i; 330 331 331 332 port = urb->context; ··· 335 334 usb_serial_port_softint(port); 336 335 usb_autopm_put_interface_async(port->serial->interface); 337 336 portdata = usb_get_serial_port_data(port); 338 - spin_lock(&intfdata->susp_lock); 337 + spin_lock_irqsave(&intfdata->susp_lock, flags); 339 338 intfdata->in_flight--; 340 - spin_unlock(&intfdata->susp_lock); 339 + spin_unlock_irqrestore(&intfdata->susp_lock, flags); 341 340 342 341 for (i = 0; i < N_OUT_URB; ++i) { 343 342 if (portdata->out_urbs[i] == urb) {
+18
drivers/usb/typec/Kconfig
··· 56 56 57 57 if TYPEC_TCPM 58 58 59 + config TYPEC_TCPCI 60 + tristate "Type-C Port Controller Interface driver" 61 + depends on I2C 62 + select REGMAP_I2C 63 + help 64 + Type-C Port Controller driver for TCPCI-compliant controller. 65 + 66 + config TYPEC_RT1711H 67 + tristate "Richtek RT1711H Type-C chip driver" 68 + depends on I2C 69 + select TYPEC_TCPCI 70 + help 71 + Richtek RT1711H Type-C chip driver that works with 72 + Type-C Port Controller Manager to provide USB PD and USB 73 + Type-C functionalities. 74 + 59 75 source "drivers/usb/typec/fusb302/Kconfig" 60 76 61 77 config TYPEC_WCOVE ··· 103 87 module will be called tps6598x.ko. 104 88 105 89 source "drivers/usb/typec/mux/Kconfig" 90 + 91 + source "drivers/usb/typec/altmodes/Kconfig" 106 92 107 93 endif # TYPEC
+4 -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 3 + typec-y := class.o mux.o bus.o 4 + obj-$(CONFIG_TYPEC) += altmodes/ 4 5 obj-$(CONFIG_TYPEC_TCPM) += tcpm.o 5 6 obj-y += fusb302/ 6 7 obj-$(CONFIG_TYPEC_WCOVE) += typec_wcove.o 7 8 obj-$(CONFIG_TYPEC_UCSI) += ucsi/ 8 9 obj-$(CONFIG_TYPEC_TPS6598X) += tps6598x.o 9 10 obj-$(CONFIG_TYPEC) += mux/ 11 + obj-$(CONFIG_TYPEC_TCPCI) += tcpci.o 12 + obj-$(CONFIG_TYPEC_RT1711H) += tcpci_rt1711h.o
+14
drivers/usb/typec/altmodes/Kconfig
··· 1 + 2 + menu "USB Type-C Alternate Mode drivers" 3 + 4 + config TYPEC_DP_ALTMODE 5 + tristate "DisplayPort Alternate Mode driver" 6 + help 7 + DisplayPort USB Type-C Alternate Mode allows DisplayPort 8 + displays and adapters to be attached to the USB Type-C 9 + connectors on the system. 10 + 11 + To compile this driver as a module, choose M here: the 12 + module will be called typec_displayport. 13 + 14 + endmenu
+2
drivers/usb/typec/altmodes/Makefile
··· 1 + obj-$(CONFIG_TYPEC_DP_ALTMODE) += typec_displayport.o 2 + typec_displayport-y := displayport.o
+580
drivers/usb/typec/altmodes/displayport.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /** 3 + * USB Typec-C DisplayPort Alternate Mode driver 4 + * 5 + * Copyright (C) 2018 Intel Corporation 6 + * Author: Heikki Krogerus <heikki.krogerus@linux.intel.com> 7 + * 8 + * DisplayPort is trademark of VESA (www.vesa.org) 9 + */ 10 + 11 + #include <linux/delay.h> 12 + #include <linux/mutex.h> 13 + #include <linux/module.h> 14 + #include <linux/usb/pd_vdo.h> 15 + #include <linux/usb/typec_dp.h> 16 + 17 + #define DP_HEADER(cmd) (VDO(USB_TYPEC_DP_SID, 1, cmd) | \ 18 + VDO_OPOS(USB_TYPEC_DP_MODE)) 19 + 20 + enum { 21 + DP_CONF_USB, 22 + DP_CONF_DFP_D, 23 + DP_CONF_UFP_D, 24 + DP_CONF_DUAL_D, 25 + }; 26 + 27 + /* Helper for setting/getting the pin assignement value to the configuration */ 28 + #define DP_CONF_SET_PIN_ASSIGN(_a_) ((_a_) << 8) 29 + #define DP_CONF_GET_PIN_ASSIGN(_conf_) (((_conf_) & GENMASK(15, 8)) >> 8) 30 + 31 + /* Pin assignments that use USB3.1 Gen2 signaling to carry DP protocol */ 32 + #define DP_PIN_ASSIGN_GEN2_BR_MASK (BIT(DP_PIN_ASSIGN_A) | \ 33 + BIT(DP_PIN_ASSIGN_B)) 34 + 35 + /* Pin assignments that use DP v1.3 signaling to carry DP protocol */ 36 + #define DP_PIN_ASSIGN_DP_BR_MASK (BIT(DP_PIN_ASSIGN_C) | \ 37 + BIT(DP_PIN_ASSIGN_D) | \ 38 + BIT(DP_PIN_ASSIGN_E) | \ 39 + BIT(DP_PIN_ASSIGN_F)) 40 + 41 + /* DP only pin assignments */ 42 + #define DP_PIN_ASSIGN_DP_ONLY_MASK (BIT(DP_PIN_ASSIGN_A) | \ 43 + BIT(DP_PIN_ASSIGN_C) | \ 44 + BIT(DP_PIN_ASSIGN_E)) 45 + 46 + /* Pin assignments where one channel is for USB */ 47 + #define DP_PIN_ASSIGN_MULTI_FUNC_MASK (BIT(DP_PIN_ASSIGN_B) | \ 48 + BIT(DP_PIN_ASSIGN_D) | \ 49 + BIT(DP_PIN_ASSIGN_F)) 50 + 51 + enum dp_state { 52 + DP_STATE_IDLE, 53 + DP_STATE_ENTER, 54 + DP_STATE_UPDATE, 55 + DP_STATE_CONFIGURE, 56 + DP_STATE_EXIT, 57 + }; 58 + 59 + struct dp_altmode { 60 + struct typec_displayport_data data; 61 + 62 + enum dp_state state; 63 + 64 + struct mutex lock; /* device lock */ 65 + struct work_struct work; 66 + struct typec_altmode *alt; 67 + const struct typec_altmode *port; 68 + }; 69 + 70 + static int dp_altmode_notify(struct dp_altmode *dp) 71 + { 72 + u8 state = get_count_order(DP_CONF_GET_PIN_ASSIGN(dp->data.conf)); 73 + 74 + return typec_altmode_notify(dp->alt, TYPEC_MODAL_STATE(state), 75 + &dp->data); 76 + } 77 + 78 + static int dp_altmode_configure(struct dp_altmode *dp, u8 con) 79 + { 80 + u32 conf = DP_CONF_SIGNALING_DP; /* Only DP signaling supported */ 81 + u8 pin_assign = 0; 82 + 83 + switch (con) { 84 + case DP_STATUS_CON_DISABLED: 85 + return 0; 86 + case DP_STATUS_CON_DFP_D: 87 + conf |= DP_CONF_UFP_U_AS_DFP_D; 88 + pin_assign = DP_CAP_UFP_D_PIN_ASSIGN(dp->alt->vdo) & 89 + DP_CAP_DFP_D_PIN_ASSIGN(dp->port->vdo); 90 + break; 91 + case DP_STATUS_CON_UFP_D: 92 + case DP_STATUS_CON_BOTH: /* NOTE: First acting as DP source */ 93 + conf |= DP_CONF_UFP_U_AS_UFP_D; 94 + pin_assign = DP_CAP_DFP_D_PIN_ASSIGN(dp->alt->vdo) & 95 + DP_CAP_UFP_D_PIN_ASSIGN(dp->port->vdo); 96 + break; 97 + default: 98 + break; 99 + } 100 + 101 + /* Determining the initial pin assignment. */ 102 + if (!DP_CONF_GET_PIN_ASSIGN(dp->data.conf)) { 103 + /* Is USB together with DP preferred */ 104 + if (dp->data.status & DP_STATUS_PREFER_MULTI_FUNC && 105 + pin_assign & DP_PIN_ASSIGN_MULTI_FUNC_MASK) 106 + pin_assign &= DP_PIN_ASSIGN_MULTI_FUNC_MASK; 107 + else 108 + pin_assign &= DP_PIN_ASSIGN_DP_ONLY_MASK; 109 + 110 + if (!pin_assign) 111 + return -EINVAL; 112 + 113 + conf |= DP_CONF_SET_PIN_ASSIGN(pin_assign); 114 + } 115 + 116 + dp->data.conf = conf; 117 + 118 + return 0; 119 + } 120 + 121 + static int dp_altmode_status_update(struct dp_altmode *dp) 122 + { 123 + bool configured = !!DP_CONF_GET_PIN_ASSIGN(dp->data.conf); 124 + u8 con = DP_STATUS_CONNECTION(dp->data.status); 125 + int ret = 0; 126 + 127 + if (configured && (dp->data.status & DP_STATUS_SWITCH_TO_USB)) { 128 + dp->data.conf = 0; 129 + dp->state = DP_STATE_CONFIGURE; 130 + } else if (dp->data.status & DP_STATUS_EXIT_DP_MODE) { 131 + dp->state = DP_STATE_EXIT; 132 + } else if (!(con & DP_CONF_CURRENTLY(dp->data.conf))) { 133 + ret = dp_altmode_configure(dp, con); 134 + if (!ret) 135 + dp->state = DP_STATE_CONFIGURE; 136 + } 137 + 138 + return ret; 139 + } 140 + 141 + static int dp_altmode_configured(struct dp_altmode *dp) 142 + { 143 + int ret; 144 + 145 + sysfs_notify(&dp->alt->dev.kobj, "displayport", "configuration"); 146 + 147 + if (!dp->data.conf) 148 + return typec_altmode_notify(dp->alt, TYPEC_STATE_USB, 149 + &dp->data); 150 + 151 + ret = dp_altmode_notify(dp); 152 + if (ret) 153 + return ret; 154 + 155 + sysfs_notify(&dp->alt->dev.kobj, "displayport", "pin_assignment"); 156 + 157 + return 0; 158 + } 159 + 160 + static int dp_altmode_configure_vdm(struct dp_altmode *dp, u32 conf) 161 + { 162 + u32 header = DP_HEADER(DP_CMD_CONFIGURE); 163 + int ret; 164 + 165 + ret = typec_altmode_notify(dp->alt, TYPEC_STATE_SAFE, &dp->data); 166 + if (ret) { 167 + dev_err(&dp->alt->dev, 168 + "unable to put to connector to safe mode\n"); 169 + return ret; 170 + } 171 + 172 + ret = typec_altmode_vdm(dp->alt, header, &conf, 2); 173 + if (ret) { 174 + if (DP_CONF_GET_PIN_ASSIGN(dp->data.conf)) 175 + dp_altmode_notify(dp); 176 + else 177 + typec_altmode_notify(dp->alt, TYPEC_STATE_USB, 178 + &dp->data); 179 + } 180 + 181 + return ret; 182 + } 183 + 184 + static void dp_altmode_work(struct work_struct *work) 185 + { 186 + struct dp_altmode *dp = container_of(work, struct dp_altmode, work); 187 + u32 header; 188 + u32 vdo; 189 + int ret; 190 + 191 + mutex_lock(&dp->lock); 192 + 193 + switch (dp->state) { 194 + case DP_STATE_ENTER: 195 + ret = typec_altmode_enter(dp->alt); 196 + if (ret) 197 + dev_err(&dp->alt->dev, "failed to enter mode\n"); 198 + break; 199 + case DP_STATE_UPDATE: 200 + header = DP_HEADER(DP_CMD_STATUS_UPDATE); 201 + vdo = 1; 202 + ret = typec_altmode_vdm(dp->alt, header, &vdo, 2); 203 + if (ret) 204 + dev_err(&dp->alt->dev, 205 + "unable to send Status Update command (%d)\n", 206 + ret); 207 + break; 208 + case DP_STATE_CONFIGURE: 209 + ret = dp_altmode_configure_vdm(dp, dp->data.conf); 210 + if (ret) 211 + dev_err(&dp->alt->dev, 212 + "unable to send Configure command (%d)\n", ret); 213 + break; 214 + case DP_STATE_EXIT: 215 + if (typec_altmode_exit(dp->alt)) 216 + dev_err(&dp->alt->dev, "Exit Mode Failed!\n"); 217 + break; 218 + default: 219 + break; 220 + } 221 + 222 + dp->state = DP_STATE_IDLE; 223 + 224 + mutex_unlock(&dp->lock); 225 + } 226 + 227 + static void dp_altmode_attention(struct typec_altmode *alt, const u32 vdo) 228 + { 229 + struct dp_altmode *dp = typec_altmode_get_drvdata(alt); 230 + u8 old_state; 231 + 232 + mutex_lock(&dp->lock); 233 + 234 + old_state = dp->state; 235 + dp->data.status = vdo; 236 + 237 + if (old_state != DP_STATE_IDLE) 238 + dev_warn(&alt->dev, "ATTENTION while processing state %d\n", 239 + old_state); 240 + 241 + if (dp_altmode_status_update(dp)) 242 + dev_warn(&alt->dev, "%s: status update failed\n", __func__); 243 + 244 + if (dp_altmode_notify(dp)) 245 + dev_err(&alt->dev, "%s: notification failed\n", __func__); 246 + 247 + if (old_state == DP_STATE_IDLE && dp->state != DP_STATE_IDLE) 248 + schedule_work(&dp->work); 249 + 250 + mutex_unlock(&dp->lock); 251 + } 252 + 253 + static int dp_altmode_vdm(struct typec_altmode *alt, 254 + const u32 hdr, const u32 *vdo, int count) 255 + { 256 + struct dp_altmode *dp = typec_altmode_get_drvdata(alt); 257 + int cmd_type = PD_VDO_CMDT(hdr); 258 + int cmd = PD_VDO_CMD(hdr); 259 + int ret = 0; 260 + 261 + mutex_lock(&dp->lock); 262 + 263 + if (dp->state != DP_STATE_IDLE) { 264 + ret = -EBUSY; 265 + goto err_unlock; 266 + } 267 + 268 + switch (cmd_type) { 269 + case CMDT_RSP_ACK: 270 + switch (cmd) { 271 + case CMD_ENTER_MODE: 272 + dp->state = DP_STATE_UPDATE; 273 + break; 274 + case CMD_EXIT_MODE: 275 + dp->data.status = 0; 276 + dp->data.conf = 0; 277 + break; 278 + case DP_CMD_STATUS_UPDATE: 279 + dp->data.status = *vdo; 280 + ret = dp_altmode_status_update(dp); 281 + break; 282 + case DP_CMD_CONFIGURE: 283 + ret = dp_altmode_configured(dp); 284 + break; 285 + default: 286 + break; 287 + } 288 + break; 289 + case CMDT_RSP_NAK: 290 + switch (cmd) { 291 + case DP_CMD_CONFIGURE: 292 + dp->data.conf = 0; 293 + ret = dp_altmode_configured(dp); 294 + break; 295 + default: 296 + break; 297 + } 298 + break; 299 + default: 300 + break; 301 + } 302 + 303 + if (dp->state != DP_STATE_IDLE) 304 + schedule_work(&dp->work); 305 + 306 + err_unlock: 307 + mutex_unlock(&dp->lock); 308 + return ret; 309 + } 310 + 311 + static int dp_altmode_activate(struct typec_altmode *alt, int activate) 312 + { 313 + return activate ? typec_altmode_enter(alt) : typec_altmode_exit(alt); 314 + } 315 + 316 + static const struct typec_altmode_ops dp_altmode_ops = { 317 + .attention = dp_altmode_attention, 318 + .vdm = dp_altmode_vdm, 319 + .activate = dp_altmode_activate, 320 + }; 321 + 322 + static const char * const configurations[] = { 323 + [DP_CONF_USB] = "USB", 324 + [DP_CONF_DFP_D] = "source", 325 + [DP_CONF_UFP_D] = "sink", 326 + }; 327 + 328 + static ssize_t 329 + configuration_store(struct device *dev, struct device_attribute *attr, 330 + const char *buf, size_t size) 331 + { 332 + struct dp_altmode *dp = dev_get_drvdata(dev); 333 + u32 conf; 334 + u32 cap; 335 + int con; 336 + int ret = 0; 337 + 338 + con = sysfs_match_string(configurations, buf); 339 + if (con < 0) 340 + return con; 341 + 342 + mutex_lock(&dp->lock); 343 + 344 + if (dp->state != DP_STATE_IDLE) { 345 + ret = -EBUSY; 346 + goto err_unlock; 347 + } 348 + 349 + cap = DP_CAP_CAPABILITY(dp->alt->vdo); 350 + 351 + if ((con == DP_CONF_DFP_D && !(cap & DP_CAP_DFP_D)) || 352 + (con == DP_CONF_UFP_D && !(cap & DP_CAP_UFP_D))) { 353 + ret = -EINVAL; 354 + goto err_unlock; 355 + } 356 + 357 + conf = dp->data.conf & ~DP_CONF_DUAL_D; 358 + conf |= con; 359 + 360 + if (dp->alt->active) { 361 + ret = dp_altmode_configure_vdm(dp, conf); 362 + if (ret) 363 + goto err_unlock; 364 + } 365 + 366 + dp->data.conf = conf; 367 + 368 + err_unlock: 369 + mutex_unlock(&dp->lock); 370 + 371 + return ret ? ret : size; 372 + } 373 + 374 + static ssize_t configuration_show(struct device *dev, 375 + struct device_attribute *attr, char *buf) 376 + { 377 + struct dp_altmode *dp = dev_get_drvdata(dev); 378 + int len; 379 + u8 cap; 380 + u8 cur; 381 + int i; 382 + 383 + mutex_lock(&dp->lock); 384 + 385 + cap = DP_CAP_CAPABILITY(dp->alt->vdo); 386 + cur = DP_CONF_CURRENTLY(dp->data.conf); 387 + 388 + len = sprintf(buf, "%s ", cur ? "USB" : "[USB]"); 389 + 390 + for (i = 1; i < ARRAY_SIZE(configurations); i++) { 391 + if (i == cur) 392 + len += sprintf(buf + len, "[%s] ", configurations[i]); 393 + else if ((i == DP_CONF_DFP_D && cap & DP_CAP_DFP_D) || 394 + (i == DP_CONF_UFP_D && cap & DP_CAP_UFP_D)) 395 + len += sprintf(buf + len, "%s ", configurations[i]); 396 + } 397 + 398 + mutex_unlock(&dp->lock); 399 + 400 + buf[len - 1] = '\n'; 401 + return len; 402 + } 403 + static DEVICE_ATTR_RW(configuration); 404 + 405 + static const char * const pin_assignments[] = { 406 + [DP_PIN_ASSIGN_A] = "A", 407 + [DP_PIN_ASSIGN_B] = "B", 408 + [DP_PIN_ASSIGN_C] = "C", 409 + [DP_PIN_ASSIGN_D] = "D", 410 + [DP_PIN_ASSIGN_E] = "E", 411 + [DP_PIN_ASSIGN_F] = "F", 412 + }; 413 + 414 + static ssize_t 415 + pin_assignment_store(struct device *dev, struct device_attribute *attr, 416 + const char *buf, size_t size) 417 + { 418 + struct dp_altmode *dp = dev_get_drvdata(dev); 419 + u8 assignments; 420 + u32 conf; 421 + int ret; 422 + 423 + ret = sysfs_match_string(pin_assignments, buf); 424 + if (ret < 0) 425 + return ret; 426 + 427 + conf = DP_CONF_SET_PIN_ASSIGN(BIT(ret)); 428 + ret = 0; 429 + 430 + mutex_lock(&dp->lock); 431 + 432 + if (conf & dp->data.conf) 433 + goto out_unlock; 434 + 435 + if (dp->state != DP_STATE_IDLE) { 436 + ret = -EBUSY; 437 + goto out_unlock; 438 + } 439 + 440 + if (DP_CONF_CURRENTLY(dp->data.conf) == DP_CONF_DFP_D) 441 + assignments = DP_CAP_UFP_D_PIN_ASSIGN(dp->alt->vdo); 442 + else 443 + assignments = DP_CAP_DFP_D_PIN_ASSIGN(dp->alt->vdo); 444 + 445 + if (!(DP_CONF_GET_PIN_ASSIGN(conf) & assignments)) { 446 + ret = -EINVAL; 447 + goto out_unlock; 448 + } 449 + 450 + conf |= dp->data.conf & ~DP_CONF_PIN_ASSIGNEMENT_MASK; 451 + 452 + /* Only send Configure command if a configuration has been set */ 453 + if (dp->alt->active && DP_CONF_CURRENTLY(dp->data.conf)) { 454 + ret = dp_altmode_configure_vdm(dp, conf); 455 + if (ret) 456 + goto out_unlock; 457 + } 458 + 459 + dp->data.conf = conf; 460 + 461 + out_unlock: 462 + mutex_unlock(&dp->lock); 463 + 464 + return ret ? ret : size; 465 + } 466 + 467 + static ssize_t pin_assignment_show(struct device *dev, 468 + struct device_attribute *attr, char *buf) 469 + { 470 + struct dp_altmode *dp = dev_get_drvdata(dev); 471 + u8 assignments; 472 + int len = 0; 473 + u8 cur; 474 + int i; 475 + 476 + mutex_lock(&dp->lock); 477 + 478 + cur = get_count_order(DP_CONF_GET_PIN_ASSIGN(dp->data.conf)); 479 + 480 + if (DP_CONF_CURRENTLY(dp->data.conf) == DP_CONF_DFP_D) 481 + assignments = DP_CAP_UFP_D_PIN_ASSIGN(dp->alt->vdo); 482 + else 483 + assignments = DP_CAP_DFP_D_PIN_ASSIGN(dp->alt->vdo); 484 + 485 + for (i = 0; assignments; assignments >>= 1, i++) { 486 + if (assignments & 1) { 487 + if (i == cur) 488 + len += sprintf(buf + len, "[%s] ", 489 + pin_assignments[i]); 490 + else 491 + len += sprintf(buf + len, "%s ", 492 + pin_assignments[i]); 493 + } 494 + } 495 + 496 + mutex_unlock(&dp->lock); 497 + 498 + buf[len - 1] = '\n'; 499 + return len; 500 + } 501 + static DEVICE_ATTR_RW(pin_assignment); 502 + 503 + static struct attribute *dp_altmode_attrs[] = { 504 + &dev_attr_configuration.attr, 505 + &dev_attr_pin_assignment.attr, 506 + NULL 507 + }; 508 + 509 + static const struct attribute_group dp_altmode_group = { 510 + .name = "displayport", 511 + .attrs = dp_altmode_attrs, 512 + }; 513 + 514 + static int dp_altmode_probe(struct typec_altmode *alt) 515 + { 516 + const struct typec_altmode *port = typec_altmode_get_partner(alt); 517 + struct dp_altmode *dp; 518 + int ret; 519 + 520 + /* FIXME: Port can only be DFP_U. */ 521 + 522 + /* Make sure we have compatiple pin configurations */ 523 + if (!(DP_CAP_DFP_D_PIN_ASSIGN(port->vdo) & 524 + DP_CAP_UFP_D_PIN_ASSIGN(alt->vdo)) && 525 + !(DP_CAP_UFP_D_PIN_ASSIGN(port->vdo) & 526 + DP_CAP_DFP_D_PIN_ASSIGN(alt->vdo))) 527 + return -ENODEV; 528 + 529 + ret = sysfs_create_group(&alt->dev.kobj, &dp_altmode_group); 530 + if (ret) 531 + return ret; 532 + 533 + dp = devm_kzalloc(&alt->dev, sizeof(*dp), GFP_KERNEL); 534 + if (!dp) 535 + return -ENOMEM; 536 + 537 + INIT_WORK(&dp->work, dp_altmode_work); 538 + mutex_init(&dp->lock); 539 + dp->port = port; 540 + dp->alt = alt; 541 + 542 + alt->desc = "DisplayPort"; 543 + alt->ops = &dp_altmode_ops; 544 + 545 + typec_altmode_set_drvdata(alt, dp); 546 + 547 + dp->state = DP_STATE_ENTER; 548 + schedule_work(&dp->work); 549 + 550 + return 0; 551 + } 552 + 553 + static void dp_altmode_remove(struct typec_altmode *alt) 554 + { 555 + struct dp_altmode *dp = typec_altmode_get_drvdata(alt); 556 + 557 + sysfs_remove_group(&alt->dev.kobj, &dp_altmode_group); 558 + cancel_work_sync(&dp->work); 559 + } 560 + 561 + static const struct typec_device_id dp_typec_id[] = { 562 + { USB_TYPEC_DP_SID, USB_TYPEC_DP_MODE }, 563 + { }, 564 + }; 565 + MODULE_DEVICE_TABLE(typec, dp_typec_id); 566 + 567 + static struct typec_altmode_driver dp_altmode_driver = { 568 + .id_table = dp_typec_id, 569 + .probe = dp_altmode_probe, 570 + .remove = dp_altmode_remove, 571 + .driver = { 572 + .name = "typec_displayport", 573 + .owner = THIS_MODULE, 574 + }, 575 + }; 576 + module_typec_altmode_driver(dp_altmode_driver); 577 + 578 + MODULE_AUTHOR("Heikki Krogerus <heikki.krogerus@linux.intel.com>"); 579 + MODULE_LICENSE("GPL v2"); 580 + MODULE_DESCRIPTION("DisplayPort Alternate Mode");
+402
drivers/usb/typec/bus.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /** 3 + * Bus for USB Type-C Alternate Modes 4 + * 5 + * Copyright (C) 2018 Intel Corporation 6 + * Author: Heikki Krogerus <heikki.krogerus@linux.intel.com> 7 + */ 8 + 9 + #include <linux/usb/pd_vdo.h> 10 + 11 + #include "bus.h" 12 + 13 + static inline int typec_altmode_set_mux(struct altmode *alt, u8 state) 14 + { 15 + return alt->mux ? alt->mux->set(alt->mux, state) : 0; 16 + } 17 + 18 + static int typec_altmode_set_state(struct typec_altmode *adev, int state) 19 + { 20 + bool is_port = is_typec_port(adev->dev.parent); 21 + struct altmode *port_altmode; 22 + int ret; 23 + 24 + port_altmode = is_port ? to_altmode(adev) : to_altmode(adev)->partner; 25 + 26 + ret = typec_altmode_set_mux(port_altmode, state); 27 + if (ret) 28 + return ret; 29 + 30 + blocking_notifier_call_chain(&port_altmode->nh, state, NULL); 31 + 32 + return 0; 33 + } 34 + 35 + /* -------------------------------------------------------------------------- */ 36 + /* Common API */ 37 + 38 + /** 39 + * typec_altmode_notify - Communication between the OS and alternate mode driver 40 + * @adev: Handle to the alternate mode 41 + * @conf: Alternate mode specific configuration value 42 + * @data: Alternate mode specific data 43 + * 44 + * The primary purpose for this function is to allow the alternate mode drivers 45 + * to tell which pin configuration has been negotiated with the partner. That 46 + * information will then be used for example to configure the muxes. 47 + * Communication to the other direction is also possible, and low level device 48 + * drivers can also send notifications to the alternate mode drivers. The actual 49 + * communication will be specific for every SVID. 50 + */ 51 + int typec_altmode_notify(struct typec_altmode *adev, 52 + unsigned long conf, void *data) 53 + { 54 + bool is_port; 55 + struct altmode *altmode; 56 + struct altmode *partner; 57 + int ret; 58 + 59 + if (!adev) 60 + return 0; 61 + 62 + altmode = to_altmode(adev); 63 + 64 + if (!altmode->partner) 65 + return -ENODEV; 66 + 67 + is_port = is_typec_port(adev->dev.parent); 68 + partner = altmode->partner; 69 + 70 + ret = typec_altmode_set_mux(is_port ? altmode : partner, (u8)conf); 71 + if (ret) 72 + return ret; 73 + 74 + blocking_notifier_call_chain(is_port ? &altmode->nh : &partner->nh, 75 + conf, data); 76 + 77 + if (partner->adev.ops && partner->adev.ops->notify) 78 + return partner->adev.ops->notify(&partner->adev, conf, data); 79 + 80 + return 0; 81 + } 82 + EXPORT_SYMBOL_GPL(typec_altmode_notify); 83 + 84 + /** 85 + * typec_altmode_enter - Enter Mode 86 + * @adev: The alternate mode 87 + * 88 + * The alternate mode drivers use this function to enter mode. The port drivers 89 + * use this to inform the alternate mode drivers that the partner has initiated 90 + * Enter Mode command. 91 + */ 92 + int typec_altmode_enter(struct typec_altmode *adev) 93 + { 94 + struct altmode *partner = to_altmode(adev)->partner; 95 + struct typec_altmode *pdev = &partner->adev; 96 + int ret; 97 + 98 + if (!adev || adev->active) 99 + return 0; 100 + 101 + if (!pdev->ops || !pdev->ops->enter) 102 + return -EOPNOTSUPP; 103 + 104 + /* Moving to USB Safe State */ 105 + ret = typec_altmode_set_state(adev, TYPEC_STATE_SAFE); 106 + if (ret) 107 + return ret; 108 + 109 + /* Enter Mode */ 110 + return pdev->ops->enter(pdev); 111 + } 112 + EXPORT_SYMBOL_GPL(typec_altmode_enter); 113 + 114 + /** 115 + * typec_altmode_exit - Exit Mode 116 + * @adev: The alternate mode 117 + * 118 + * The partner of @adev has initiated Exit Mode command. 119 + */ 120 + int typec_altmode_exit(struct typec_altmode *adev) 121 + { 122 + struct altmode *partner = to_altmode(adev)->partner; 123 + struct typec_altmode *pdev = &partner->adev; 124 + int ret; 125 + 126 + if (!adev || !adev->active) 127 + return 0; 128 + 129 + if (!pdev->ops || !pdev->ops->enter) 130 + return -EOPNOTSUPP; 131 + 132 + /* Moving to USB Safe State */ 133 + ret = typec_altmode_set_state(adev, TYPEC_STATE_SAFE); 134 + if (ret) 135 + return ret; 136 + 137 + /* Exit Mode command */ 138 + return pdev->ops->exit(pdev); 139 + } 140 + EXPORT_SYMBOL_GPL(typec_altmode_exit); 141 + 142 + /** 143 + * typec_altmode_attention - Attention command 144 + * @adev: The alternate mode 145 + * @vdo: VDO for the Attention command 146 + * 147 + * Notifies the partner of @adev about Attention command. 148 + */ 149 + void typec_altmode_attention(struct typec_altmode *adev, u32 vdo) 150 + { 151 + struct typec_altmode *pdev = &to_altmode(adev)->partner->adev; 152 + 153 + if (pdev->ops && pdev->ops->attention) 154 + pdev->ops->attention(pdev, vdo); 155 + } 156 + EXPORT_SYMBOL_GPL(typec_altmode_attention); 157 + 158 + /** 159 + * typec_altmode_vdm - Send Vendor Defined Messages (VDM) to the partner 160 + * @adev: Alternate mode handle 161 + * @header: VDM Header 162 + * @vdo: Array of Vendor Defined Data Objects 163 + * @count: Number of Data Objects 164 + * 165 + * The alternate mode drivers use this function for SVID specific communication 166 + * with the partner. The port drivers use it to deliver the Structured VDMs 167 + * received from the partners to the alternate mode drivers. 168 + */ 169 + int typec_altmode_vdm(struct typec_altmode *adev, 170 + const u32 header, const u32 *vdo, int count) 171 + { 172 + struct typec_altmode *pdev; 173 + struct altmode *altmode; 174 + 175 + if (!adev) 176 + return 0; 177 + 178 + altmode = to_altmode(adev); 179 + 180 + if (!altmode->partner) 181 + return -ENODEV; 182 + 183 + pdev = &altmode->partner->adev; 184 + 185 + if (!pdev->ops || !pdev->ops->vdm) 186 + return -EOPNOTSUPP; 187 + 188 + return pdev->ops->vdm(pdev, header, vdo, count); 189 + } 190 + EXPORT_SYMBOL_GPL(typec_altmode_vdm); 191 + 192 + const struct typec_altmode * 193 + typec_altmode_get_partner(struct typec_altmode *adev) 194 + { 195 + return &to_altmode(adev)->partner->adev; 196 + } 197 + EXPORT_SYMBOL_GPL(typec_altmode_get_partner); 198 + 199 + /* -------------------------------------------------------------------------- */ 200 + /* API for the alternate mode drivers */ 201 + 202 + /** 203 + * typec_altmode_get_plug - Find cable plug alternate mode 204 + * @adev: Handle to partner alternate mode 205 + * @index: Cable plug index 206 + * 207 + * Increment reference count for cable plug alternate mode device. Returns 208 + * handle to the cable plug alternate mode, or NULL if none is found. 209 + */ 210 + struct typec_altmode *typec_altmode_get_plug(struct typec_altmode *adev, 211 + enum typec_plug_index index) 212 + { 213 + struct altmode *port = to_altmode(adev)->partner; 214 + 215 + if (port->plug[index]) { 216 + get_device(&port->plug[index]->adev.dev); 217 + return &port->plug[index]->adev; 218 + } 219 + 220 + return NULL; 221 + } 222 + EXPORT_SYMBOL_GPL(typec_altmode_get_plug); 223 + 224 + /** 225 + * typec_altmode_put_plug - Decrement cable plug alternate mode reference count 226 + * @plug: Handle to the cable plug alternate mode 227 + */ 228 + void typec_altmode_put_plug(struct typec_altmode *plug) 229 + { 230 + if (plug) 231 + put_device(&plug->dev); 232 + } 233 + EXPORT_SYMBOL_GPL(typec_altmode_put_plug); 234 + 235 + int __typec_altmode_register_driver(struct typec_altmode_driver *drv, 236 + struct module *module) 237 + { 238 + if (!drv->probe) 239 + return -EINVAL; 240 + 241 + drv->driver.owner = module; 242 + drv->driver.bus = &typec_bus; 243 + 244 + return driver_register(&drv->driver); 245 + } 246 + EXPORT_SYMBOL_GPL(__typec_altmode_register_driver); 247 + 248 + void typec_altmode_unregister_driver(struct typec_altmode_driver *drv) 249 + { 250 + driver_unregister(&drv->driver); 251 + } 252 + EXPORT_SYMBOL_GPL(typec_altmode_unregister_driver); 253 + 254 + /* -------------------------------------------------------------------------- */ 255 + /* API for the port drivers */ 256 + 257 + /** 258 + * typec_match_altmode - Match SVID to an array of alternate modes 259 + * @altmodes: Array of alternate modes 260 + * @n: Number of elements in the array, or -1 for NULL termiated arrays 261 + * @svid: Standard or Vendor ID to match with 262 + * 263 + * Return pointer to an alternate mode with SVID mathing @svid, or NULL when no 264 + * match is found. 265 + */ 266 + struct typec_altmode *typec_match_altmode(struct typec_altmode **altmodes, 267 + size_t n, u16 svid, u8 mode) 268 + { 269 + int i; 270 + 271 + for (i = 0; i < n; i++) { 272 + if (!altmodes[i]) 273 + break; 274 + if (altmodes[i]->svid == svid && altmodes[i]->mode == mode) 275 + return altmodes[i]; 276 + } 277 + 278 + return NULL; 279 + } 280 + EXPORT_SYMBOL_GPL(typec_match_altmode); 281 + 282 + /* -------------------------------------------------------------------------- */ 283 + 284 + static ssize_t 285 + description_show(struct device *dev, struct device_attribute *attr, char *buf) 286 + { 287 + struct typec_altmode *alt = to_typec_altmode(dev); 288 + 289 + return sprintf(buf, "%s\n", alt->desc ? alt->desc : ""); 290 + } 291 + static DEVICE_ATTR_RO(description); 292 + 293 + static struct attribute *typec_attrs[] = { 294 + &dev_attr_description.attr, 295 + NULL 296 + }; 297 + ATTRIBUTE_GROUPS(typec); 298 + 299 + static int typec_match(struct device *dev, struct device_driver *driver) 300 + { 301 + struct typec_altmode_driver *drv = to_altmode_driver(driver); 302 + struct typec_altmode *altmode = to_typec_altmode(dev); 303 + const struct typec_device_id *id; 304 + 305 + for (id = drv->id_table; id->svid; id++) 306 + if (id->svid == altmode->svid && 307 + (id->mode == TYPEC_ANY_MODE || id->mode == altmode->mode)) 308 + return 1; 309 + return 0; 310 + } 311 + 312 + static int typec_uevent(struct device *dev, struct kobj_uevent_env *env) 313 + { 314 + struct typec_altmode *altmode = to_typec_altmode(dev); 315 + 316 + if (add_uevent_var(env, "SVID=%04X", altmode->svid)) 317 + return -ENOMEM; 318 + 319 + if (add_uevent_var(env, "MODE=%u", altmode->mode)) 320 + return -ENOMEM; 321 + 322 + return add_uevent_var(env, "MODALIAS=typec:id%04Xm%02X", 323 + altmode->svid, altmode->mode); 324 + } 325 + 326 + static int typec_altmode_create_links(struct altmode *alt) 327 + { 328 + struct device *port_dev = &alt->partner->adev.dev; 329 + struct device *dev = &alt->adev.dev; 330 + int err; 331 + 332 + err = sysfs_create_link(&dev->kobj, &port_dev->kobj, "port"); 333 + if (err) 334 + return err; 335 + 336 + err = sysfs_create_link(&port_dev->kobj, &dev->kobj, "partner"); 337 + if (err) 338 + sysfs_remove_link(&dev->kobj, "port"); 339 + 340 + return err; 341 + } 342 + 343 + static void typec_altmode_remove_links(struct altmode *alt) 344 + { 345 + sysfs_remove_link(&alt->partner->adev.dev.kobj, "partner"); 346 + sysfs_remove_link(&alt->adev.dev.kobj, "port"); 347 + } 348 + 349 + static int typec_probe(struct device *dev) 350 + { 351 + struct typec_altmode_driver *drv = to_altmode_driver(dev->driver); 352 + struct typec_altmode *adev = to_typec_altmode(dev); 353 + struct altmode *altmode = to_altmode(adev); 354 + int ret; 355 + 356 + /* Fail if the port does not support the alternate mode */ 357 + if (!altmode->partner) 358 + return -ENODEV; 359 + 360 + ret = typec_altmode_create_links(altmode); 361 + if (ret) { 362 + dev_warn(dev, "failed to create symlinks\n"); 363 + return ret; 364 + } 365 + 366 + ret = drv->probe(adev); 367 + if (ret) 368 + typec_altmode_remove_links(altmode); 369 + 370 + return ret; 371 + } 372 + 373 + static int typec_remove(struct device *dev) 374 + { 375 + struct typec_altmode_driver *drv = to_altmode_driver(dev->driver); 376 + struct typec_altmode *adev = to_typec_altmode(dev); 377 + struct altmode *altmode = to_altmode(adev); 378 + 379 + typec_altmode_remove_links(altmode); 380 + 381 + if (drv->remove) 382 + drv->remove(to_typec_altmode(dev)); 383 + 384 + if (adev->active) { 385 + WARN_ON(typec_altmode_set_state(adev, TYPEC_STATE_SAFE)); 386 + typec_altmode_update_active(adev, false); 387 + } 388 + 389 + adev->desc = NULL; 390 + adev->ops = NULL; 391 + 392 + return 0; 393 + } 394 + 395 + struct bus_type typec_bus = { 396 + .name = "typec", 397 + .dev_groups = typec_groups, 398 + .match = typec_match, 399 + .uevent = typec_uevent, 400 + .probe = typec_probe, 401 + .remove = typec_remove, 402 + };
+38
drivers/usb/typec/bus.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + 3 + #ifndef __USB_TYPEC_ALTMODE_H__ 4 + #define __USB_TYPEC_ALTMODE_H__ 5 + 6 + #include <linux/usb/typec_altmode.h> 7 + #include <linux/usb/typec_mux.h> 8 + 9 + struct bus_type; 10 + 11 + struct altmode { 12 + unsigned int id; 13 + struct typec_altmode adev; 14 + struct typec_mux *mux; 15 + 16 + enum typec_port_data roles; 17 + 18 + struct attribute *attrs[5]; 19 + char group_name[8]; 20 + struct attribute_group group; 21 + const struct attribute_group *groups[2]; 22 + 23 + struct altmode *partner; 24 + struct altmode *plug[2]; 25 + 26 + struct blocking_notifier_head nh; 27 + }; 28 + 29 + #define to_altmode(d) container_of(d, struct altmode, adev) 30 + 31 + extern struct bus_type typec_bus; 32 + extern const struct device_type typec_altmode_dev_type; 33 + extern const struct device_type typec_port_dev_type; 34 + 35 + #define is_typec_altmode(_dev_) (_dev_->type == &typec_altmode_dev_type) 36 + #define is_typec_port(_dev_) (_dev_->type == &typec_port_dev_type) 37 + 38 + #endif /* __USB_TYPEC_ALTMODE_H__ */
+381 -165
drivers/usb/typec/class.c
··· 10 10 #include <linux/module.h> 11 11 #include <linux/mutex.h> 12 12 #include <linux/slab.h> 13 - #include <linux/usb/typec.h> 14 - #include <linux/usb/typec_mux.h> 15 13 16 - struct typec_mode { 17 - int index; 18 - u32 vdo; 19 - char *desc; 20 - enum typec_port_type roles; 21 - 22 - struct typec_altmode *alt_mode; 23 - 24 - unsigned int active:1; 25 - 26 - char group_name[6]; 27 - struct attribute_group group; 28 - struct attribute *attrs[5]; 29 - struct device_attribute vdo_attr; 30 - struct device_attribute desc_attr; 31 - struct device_attribute active_attr; 32 - struct device_attribute roles_attr; 33 - }; 34 - 35 - struct typec_altmode { 36 - struct device dev; 37 - u16 svid; 38 - int n_modes; 39 - struct typec_mode modes[ALTMODE_MAX_MODES]; 40 - const struct attribute_group *mode_groups[ALTMODE_MAX_MODES]; 41 - }; 14 + #include "bus.h" 42 15 43 16 struct typec_plug { 44 17 struct device dev; 45 18 enum typec_plug_index index; 19 + struct ida mode_ids; 46 20 }; 47 21 48 22 struct typec_cable { ··· 31 57 unsigned int usb_pd:1; 32 58 struct usb_pd_identity *identity; 33 59 enum typec_accessory accessory; 60 + struct ida mode_ids; 34 61 }; 35 62 36 63 struct typec_port { 37 64 unsigned int id; 38 65 struct device dev; 66 + struct ida mode_ids; 39 67 40 68 int prefer_role; 41 69 enum typec_data_role data_role; ··· 58 82 #define to_typec_plug(_dev_) container_of(_dev_, struct typec_plug, dev) 59 83 #define to_typec_cable(_dev_) container_of(_dev_, struct typec_cable, dev) 60 84 #define to_typec_partner(_dev_) container_of(_dev_, struct typec_partner, dev) 61 - #define to_altmode(_dev_) container_of(_dev_, struct typec_altmode, dev) 62 85 63 86 static const struct device_type typec_partner_dev_type; 64 87 static const struct device_type typec_cable_dev_type; 65 88 static const struct device_type typec_plug_dev_type; 66 - static const struct device_type typec_port_dev_type; 67 89 68 90 #define is_typec_partner(_dev_) (_dev_->type == &typec_partner_dev_type) 69 91 #define is_typec_cable(_dev_) (_dev_->type == &typec_cable_dev_type) 70 92 #define is_typec_plug(_dev_) (_dev_->type == &typec_plug_dev_type) 71 - #define is_typec_port(_dev_) (_dev_->type == &typec_port_dev_type) 72 93 73 94 static DEFINE_IDA(typec_index_ida); 74 95 static struct class *typec_class; ··· 147 174 /* ------------------------------------------------------------------------- */ 148 175 /* Alternate Modes */ 149 176 177 + static int altmode_match(struct device *dev, void *data) 178 + { 179 + struct typec_altmode *adev = to_typec_altmode(dev); 180 + struct typec_device_id *id = data; 181 + 182 + if (!is_typec_altmode(dev)) 183 + return 0; 184 + 185 + return ((adev->svid == id->svid) && (adev->mode == id->mode)); 186 + } 187 + 188 + static void typec_altmode_set_partner(struct altmode *altmode) 189 + { 190 + struct typec_altmode *adev = &altmode->adev; 191 + struct typec_device_id id = { adev->svid, adev->mode, }; 192 + struct typec_port *port = typec_altmode2port(adev); 193 + struct altmode *partner; 194 + struct device *dev; 195 + 196 + dev = device_find_child(&port->dev, &id, altmode_match); 197 + if (!dev) 198 + return; 199 + 200 + /* Bind the port alt mode to the partner/plug alt mode. */ 201 + partner = to_altmode(to_typec_altmode(dev)); 202 + altmode->partner = partner; 203 + 204 + /* Bind the partner/plug alt mode to the port alt mode. */ 205 + if (is_typec_plug(adev->dev.parent)) { 206 + struct typec_plug *plug = to_typec_plug(adev->dev.parent); 207 + 208 + partner->plug[plug->index] = altmode; 209 + } else { 210 + partner->partner = altmode; 211 + } 212 + } 213 + 214 + static void typec_altmode_put_partner(struct altmode *altmode) 215 + { 216 + struct altmode *partner = altmode->partner; 217 + struct typec_altmode *adev; 218 + 219 + if (!partner) 220 + return; 221 + 222 + adev = &partner->adev; 223 + 224 + if (is_typec_plug(adev->dev.parent)) { 225 + struct typec_plug *plug = to_typec_plug(adev->dev.parent); 226 + 227 + partner->plug[plug->index] = NULL; 228 + } else { 229 + partner->partner = NULL; 230 + } 231 + put_device(&adev->dev); 232 + } 233 + 234 + static int __typec_port_match(struct device *dev, const void *name) 235 + { 236 + return !strcmp((const char *)name, dev_name(dev)); 237 + } 238 + 239 + static void *typec_port_match(struct device_connection *con, int ep, void *data) 240 + { 241 + return class_find_device(typec_class, NULL, con->endpoint[ep], 242 + __typec_port_match); 243 + } 244 + 245 + struct typec_altmode * 246 + typec_altmode_register_notifier(struct device *dev, u16 svid, u8 mode, 247 + struct notifier_block *nb) 248 + { 249 + struct typec_device_id id = { svid, mode, }; 250 + struct device *altmode_dev; 251 + struct device *port_dev; 252 + struct altmode *altmode; 253 + int ret; 254 + 255 + /* Find the port linked to the caller */ 256 + port_dev = device_connection_find_match(dev, NULL, NULL, 257 + typec_port_match); 258 + if (IS_ERR_OR_NULL(port_dev)) 259 + return port_dev ? ERR_CAST(port_dev) : ERR_PTR(-ENODEV); 260 + 261 + /* Find the altmode with matching svid */ 262 + altmode_dev = device_find_child(port_dev, &id, altmode_match); 263 + 264 + put_device(port_dev); 265 + 266 + if (!altmode_dev) 267 + return ERR_PTR(-ENODEV); 268 + 269 + altmode = to_altmode(to_typec_altmode(altmode_dev)); 270 + 271 + /* Register notifier */ 272 + ret = blocking_notifier_chain_register(&altmode->nh, nb); 273 + if (ret) { 274 + put_device(altmode_dev); 275 + return ERR_PTR(ret); 276 + } 277 + 278 + return &altmode->adev; 279 + } 280 + EXPORT_SYMBOL_GPL(typec_altmode_register_notifier); 281 + 282 + void typec_altmode_unregister_notifier(struct typec_altmode *adev, 283 + struct notifier_block *nb) 284 + { 285 + struct altmode *altmode = to_altmode(adev); 286 + 287 + blocking_notifier_chain_unregister(&altmode->nh, nb); 288 + put_device(&adev->dev); 289 + } 290 + EXPORT_SYMBOL_GPL(typec_altmode_unregister_notifier); 291 + 150 292 /** 151 293 * typec_altmode_update_active - Report Enter/Exit mode 152 - * @alt: Handle to the alternate mode 153 - * @mode: Mode index 294 + * @adev: Handle to the alternate mode 154 295 * @active: True when the mode has been entered 155 296 * 156 297 * If a partner or cable plug executes Enter/Exit Mode command successfully, the 157 298 * drivers use this routine to report the updated state of the mode. 158 299 */ 159 - void typec_altmode_update_active(struct typec_altmode *alt, int mode, 160 - bool active) 300 + void typec_altmode_update_active(struct typec_altmode *adev, bool active) 161 301 { 162 - struct typec_mode *m = &alt->modes[mode]; 163 302 char dir[6]; 164 303 165 - if (m->active == active) 304 + if (adev->active == active) 166 305 return; 167 306 168 - m->active = active; 169 - snprintf(dir, sizeof(dir), "mode%d", mode); 170 - sysfs_notify(&alt->dev.kobj, dir, "active"); 171 - kobject_uevent(&alt->dev.kobj, KOBJ_CHANGE); 307 + if (!is_typec_port(adev->dev.parent)) { 308 + if (!active) 309 + module_put(adev->dev.driver->owner); 310 + else 311 + WARN_ON(!try_module_get(adev->dev.driver->owner)); 312 + } 313 + 314 + adev->active = active; 315 + snprintf(dir, sizeof(dir), "mode%d", adev->mode); 316 + sysfs_notify(&adev->dev.kobj, dir, "active"); 317 + sysfs_notify(&adev->dev.kobj, NULL, "active"); 318 + kobject_uevent(&adev->dev.kobj, KOBJ_CHANGE); 172 319 } 173 320 EXPORT_SYMBOL_GPL(typec_altmode_update_active); 174 321 ··· 313 220 EXPORT_SYMBOL_GPL(typec_altmode2port); 314 221 315 222 static ssize_t 316 - typec_altmode_vdo_show(struct device *dev, struct device_attribute *attr, 317 - char *buf) 223 + vdo_show(struct device *dev, struct device_attribute *attr, char *buf) 318 224 { 319 - struct typec_mode *mode = container_of(attr, struct typec_mode, 320 - vdo_attr); 225 + struct typec_altmode *alt = to_typec_altmode(dev); 321 226 322 - return sprintf(buf, "0x%08x\n", mode->vdo); 227 + return sprintf(buf, "0x%08x\n", alt->vdo); 323 228 } 229 + static DEVICE_ATTR_RO(vdo); 324 230 325 231 static ssize_t 326 - typec_altmode_desc_show(struct device *dev, struct device_attribute *attr, 327 - char *buf) 232 + description_show(struct device *dev, struct device_attribute *attr, char *buf) 328 233 { 329 - struct typec_mode *mode = container_of(attr, struct typec_mode, 330 - desc_attr); 234 + struct typec_altmode *alt = to_typec_altmode(dev); 331 235 332 - return sprintf(buf, "%s\n", mode->desc ? mode->desc : ""); 236 + return sprintf(buf, "%s\n", alt->desc ? alt->desc : ""); 333 237 } 238 + static DEVICE_ATTR_RO(description); 334 239 335 240 static ssize_t 336 - typec_altmode_active_show(struct device *dev, struct device_attribute *attr, 337 - char *buf) 241 + active_show(struct device *dev, struct device_attribute *attr, char *buf) 338 242 { 339 - struct typec_mode *mode = container_of(attr, struct typec_mode, 340 - active_attr); 243 + struct typec_altmode *alt = to_typec_altmode(dev); 341 244 342 - return sprintf(buf, "%s\n", mode->active ? "yes" : "no"); 245 + return sprintf(buf, "%s\n", alt->active ? "yes" : "no"); 343 246 } 344 247 345 - static ssize_t 346 - typec_altmode_active_store(struct device *dev, struct device_attribute *attr, 347 - const char *buf, size_t size) 248 + static ssize_t active_store(struct device *dev, struct device_attribute *attr, 249 + const char *buf, size_t size) 348 250 { 349 - struct typec_mode *mode = container_of(attr, struct typec_mode, 350 - active_attr); 351 - struct typec_port *port = typec_altmode2port(mode->alt_mode); 352 - bool activate; 251 + struct typec_altmode *adev = to_typec_altmode(dev); 252 + struct altmode *altmode = to_altmode(adev); 253 + bool enter; 353 254 int ret; 354 255 355 - if (!port->cap->activate_mode) 356 - return -EOPNOTSUPP; 357 - 358 - ret = kstrtobool(buf, &activate); 256 + ret = kstrtobool(buf, &enter); 359 257 if (ret) 360 258 return ret; 361 259 362 - ret = port->cap->activate_mode(port->cap, mode->index, activate); 363 - if (ret) 364 - return ret; 260 + if (adev->active == enter) 261 + return size; 262 + 263 + if (is_typec_port(adev->dev.parent)) { 264 + typec_altmode_update_active(adev, enter); 265 + 266 + /* Make sure that the partner exits the mode before disabling */ 267 + if (altmode->partner && !enter && altmode->partner->adev.active) 268 + typec_altmode_exit(&altmode->partner->adev); 269 + } else if (altmode->partner) { 270 + if (enter && !altmode->partner->adev.active) { 271 + dev_warn(dev, "port has the mode disabled\n"); 272 + return -EPERM; 273 + } 274 + } 275 + 276 + /* Note: If there is no driver, the mode will not be entered */ 277 + if (adev->ops && adev->ops->activate) { 278 + ret = adev->ops->activate(adev, enter); 279 + if (ret) 280 + return ret; 281 + } 365 282 366 283 return size; 367 284 } 285 + static DEVICE_ATTR_RW(active); 368 286 369 287 static ssize_t 370 - typec_altmode_roles_show(struct device *dev, struct device_attribute *attr, 371 - char *buf) 288 + supported_roles_show(struct device *dev, struct device_attribute *attr, 289 + char *buf) 372 290 { 373 - struct typec_mode *mode = container_of(attr, struct typec_mode, 374 - roles_attr); 291 + struct altmode *alt = to_altmode(to_typec_altmode(dev)); 375 292 ssize_t ret; 376 293 377 - switch (mode->roles) { 294 + switch (alt->roles) { 378 295 case TYPEC_PORT_SRC: 379 296 ret = sprintf(buf, "source\n"); 380 297 break; ··· 398 295 } 399 296 return ret; 400 297 } 298 + static DEVICE_ATTR_RO(supported_roles); 401 299 402 - static void typec_init_modes(struct typec_altmode *alt, 403 - const struct typec_mode_desc *desc, bool is_port) 300 + static ssize_t 301 + mode_show(struct device *dev, struct device_attribute *attr, char *buf) 404 302 { 405 - int i; 303 + struct typec_altmode *adev = to_typec_altmode(dev); 406 304 407 - for (i = 0; i < alt->n_modes; i++, desc++) { 408 - struct typec_mode *mode = &alt->modes[i]; 409 - 410 - /* Not considering the human readable description critical */ 411 - mode->desc = kstrdup(desc->desc, GFP_KERNEL); 412 - if (desc->desc && !mode->desc) 413 - dev_err(&alt->dev, "failed to copy mode%d desc\n", i); 414 - 415 - mode->alt_mode = alt; 416 - mode->vdo = desc->vdo; 417 - mode->roles = desc->roles; 418 - mode->index = desc->index; 419 - sprintf(mode->group_name, "mode%d", desc->index); 420 - 421 - sysfs_attr_init(&mode->vdo_attr.attr); 422 - mode->vdo_attr.attr.name = "vdo"; 423 - mode->vdo_attr.attr.mode = 0444; 424 - mode->vdo_attr.show = typec_altmode_vdo_show; 425 - 426 - sysfs_attr_init(&mode->desc_attr.attr); 427 - mode->desc_attr.attr.name = "description"; 428 - mode->desc_attr.attr.mode = 0444; 429 - mode->desc_attr.show = typec_altmode_desc_show; 430 - 431 - sysfs_attr_init(&mode->active_attr.attr); 432 - mode->active_attr.attr.name = "active"; 433 - mode->active_attr.attr.mode = 0644; 434 - mode->active_attr.show = typec_altmode_active_show; 435 - mode->active_attr.store = typec_altmode_active_store; 436 - 437 - mode->attrs[0] = &mode->vdo_attr.attr; 438 - mode->attrs[1] = &mode->desc_attr.attr; 439 - mode->attrs[2] = &mode->active_attr.attr; 440 - 441 - /* With ports, list the roles that the mode is supported with */ 442 - if (is_port) { 443 - sysfs_attr_init(&mode->roles_attr.attr); 444 - mode->roles_attr.attr.name = "supported_roles"; 445 - mode->roles_attr.attr.mode = 0444; 446 - mode->roles_attr.show = typec_altmode_roles_show; 447 - 448 - mode->attrs[3] = &mode->roles_attr.attr; 449 - } 450 - 451 - mode->group.attrs = mode->attrs; 452 - mode->group.name = mode->group_name; 453 - 454 - alt->mode_groups[i] = &mode->group; 455 - } 305 + return sprintf(buf, "%u\n", adev->mode); 456 306 } 307 + static DEVICE_ATTR_RO(mode); 457 308 458 - static ssize_t svid_show(struct device *dev, struct device_attribute *attr, 459 - char *buf) 309 + static ssize_t 310 + svid_show(struct device *dev, struct device_attribute *attr, char *buf) 460 311 { 461 - struct typec_altmode *alt = to_altmode(dev); 312 + struct typec_altmode *adev = to_typec_altmode(dev); 462 313 463 - return sprintf(buf, "%04x\n", alt->svid); 314 + return sprintf(buf, "%04x\n", adev->svid); 464 315 } 465 316 static DEVICE_ATTR_RO(svid); 466 317 467 318 static struct attribute *typec_altmode_attrs[] = { 319 + &dev_attr_active.attr, 320 + &dev_attr_mode.attr, 468 321 &dev_attr_svid.attr, 322 + &dev_attr_vdo.attr, 469 323 NULL 470 324 }; 471 325 ATTRIBUTE_GROUPS(typec_altmode); 472 326 327 + static int altmode_id_get(struct device *dev) 328 + { 329 + struct ida *ids; 330 + 331 + if (is_typec_partner(dev)) 332 + ids = &to_typec_partner(dev)->mode_ids; 333 + else if (is_typec_plug(dev)) 334 + ids = &to_typec_plug(dev)->mode_ids; 335 + else 336 + ids = &to_typec_port(dev)->mode_ids; 337 + 338 + return ida_simple_get(ids, 0, 0, GFP_KERNEL); 339 + } 340 + 341 + static void altmode_id_remove(struct device *dev, int id) 342 + { 343 + struct ida *ids; 344 + 345 + if (is_typec_partner(dev)) 346 + ids = &to_typec_partner(dev)->mode_ids; 347 + else if (is_typec_plug(dev)) 348 + ids = &to_typec_plug(dev)->mode_ids; 349 + else 350 + ids = &to_typec_port(dev)->mode_ids; 351 + 352 + ida_simple_remove(ids, id); 353 + } 354 + 473 355 static void typec_altmode_release(struct device *dev) 474 356 { 475 - struct typec_altmode *alt = to_altmode(dev); 476 - int i; 357 + struct altmode *alt = to_altmode(to_typec_altmode(dev)); 477 358 478 - for (i = 0; i < alt->n_modes; i++) 479 - kfree(alt->modes[i].desc); 359 + typec_altmode_put_partner(alt); 360 + 361 + altmode_id_remove(alt->adev.dev.parent, alt->id); 480 362 kfree(alt); 481 363 } 482 364 483 - static const struct device_type typec_altmode_dev_type = { 365 + const struct device_type typec_altmode_dev_type = { 484 366 .name = "typec_alternate_mode", 485 367 .groups = typec_altmode_groups, 486 368 .release = typec_altmode_release, ··· 475 387 typec_register_altmode(struct device *parent, 476 388 const struct typec_altmode_desc *desc) 477 389 { 478 - struct typec_altmode *alt; 390 + unsigned int id = altmode_id_get(parent); 391 + bool is_port = is_typec_port(parent); 392 + struct altmode *alt; 479 393 int ret; 480 394 481 395 alt = kzalloc(sizeof(*alt), GFP_KERNEL); 482 396 if (!alt) 483 397 return ERR_PTR(-ENOMEM); 484 398 485 - alt->svid = desc->svid; 486 - alt->n_modes = desc->n_modes; 487 - typec_init_modes(alt, desc->modes, is_typec_port(parent)); 399 + alt->adev.svid = desc->svid; 400 + alt->adev.mode = desc->mode; 401 + alt->adev.vdo = desc->vdo; 402 + alt->roles = desc->roles; 403 + alt->id = id; 488 404 489 - alt->dev.parent = parent; 490 - alt->dev.groups = alt->mode_groups; 491 - alt->dev.type = &typec_altmode_dev_type; 492 - dev_set_name(&alt->dev, "svid-%04x", alt->svid); 405 + alt->attrs[0] = &dev_attr_vdo.attr; 406 + alt->attrs[1] = &dev_attr_description.attr; 407 + alt->attrs[2] = &dev_attr_active.attr; 493 408 494 - ret = device_register(&alt->dev); 409 + if (is_port) { 410 + alt->attrs[3] = &dev_attr_supported_roles.attr; 411 + alt->adev.active = true; /* Enabled by default */ 412 + } 413 + 414 + sprintf(alt->group_name, "mode%d", desc->mode); 415 + alt->group.name = alt->group_name; 416 + alt->group.attrs = alt->attrs; 417 + alt->groups[0] = &alt->group; 418 + 419 + alt->adev.dev.parent = parent; 420 + alt->adev.dev.groups = alt->groups; 421 + alt->adev.dev.type = &typec_altmode_dev_type; 422 + dev_set_name(&alt->adev.dev, "%s.%u", dev_name(parent), id); 423 + 424 + /* Link partners and plugs with the ports */ 425 + if (is_port) 426 + BLOCKING_INIT_NOTIFIER_HEAD(&alt->nh); 427 + else 428 + typec_altmode_set_partner(alt); 429 + 430 + /* The partners are bind to drivers */ 431 + if (is_typec_partner(parent)) 432 + alt->adev.dev.bus = &typec_bus; 433 + 434 + ret = device_register(&alt->adev.dev); 495 435 if (ret) { 496 436 dev_err(parent, "failed to register alternate mode (%d)\n", 497 437 ret); 498 - put_device(&alt->dev); 438 + put_device(&alt->adev.dev); 499 439 return ERR_PTR(ret); 500 440 } 501 441 502 - return alt; 442 + return &alt->adev; 503 443 } 504 444 505 445 /** 506 446 * typec_unregister_altmode - Unregister Alternate Mode 507 - * @alt: The alternate mode to be unregistered 447 + * @adev: The alternate mode to be unregistered 508 448 * 509 449 * Unregister device created with typec_partner_register_altmode(), 510 450 * typec_plug_register_altmode() or typec_port_register_altmode(). 511 451 */ 512 - void typec_unregister_altmode(struct typec_altmode *alt) 452 + void typec_unregister_altmode(struct typec_altmode *adev) 513 453 { 514 - if (!IS_ERR_OR_NULL(alt)) 515 - device_unregister(&alt->dev); 454 + if (IS_ERR_OR_NULL(adev)) 455 + return; 456 + typec_mux_put(to_altmode(adev)->mux); 457 + device_unregister(&adev->dev); 516 458 } 517 459 EXPORT_SYMBOL_GPL(typec_unregister_altmode); 518 460 ··· 580 462 { 581 463 struct typec_partner *partner = to_typec_partner(dev); 582 464 465 + ida_destroy(&partner->mode_ids); 583 466 kfree(partner); 584 467 } 585 468 ··· 646 527 if (!partner) 647 528 return ERR_PTR(-ENOMEM); 648 529 530 + ida_init(&partner->mode_ids); 649 531 partner->usb_pd = desc->usb_pd; 650 532 partner->accessory = desc->accessory; 651 533 ··· 695 575 { 696 576 struct typec_plug *plug = to_typec_plug(dev); 697 577 578 + ida_destroy(&plug->mode_ids); 698 579 kfree(plug); 699 580 } 700 581 ··· 748 627 749 628 sprintf(name, "plug%d", desc->index); 750 629 630 + ida_init(&plug->mode_ids); 751 631 plug->index = desc->index; 752 632 plug->dev.class = typec_class; 753 633 plug->dev.parent = &cable->dev; ··· 918 796 [TYPEC_HOST] = "host", 919 797 }; 920 798 921 - static const char * const typec_port_types[] = { 799 + static const char * const typec_port_power_roles[] = { 922 800 [TYPEC_PORT_SRC] = "source", 923 801 [TYPEC_PORT_SNK] = "sink", 924 802 [TYPEC_PORT_DRP] = "dual", 803 + }; 804 + 805 + static const char * const typec_port_data_roles[] = { 806 + [TYPEC_PORT_DFP] = "host", 807 + [TYPEC_PORT_UFP] = "device", 808 + [TYPEC_PORT_DRD] = "dual", 925 809 }; 926 810 927 811 static const char * const typec_port_types_drp[] = { ··· 1060 932 mutex_lock(&port->port_type_lock); 1061 933 if (port->port_type != TYPEC_PORT_DRP) { 1062 934 dev_dbg(dev, "port type fixed at \"%s\"", 1063 - typec_port_types[port->port_type]); 935 + typec_port_power_roles[port->port_type]); 1064 936 ret = -EOPNOTSUPP; 1065 937 goto unlock_and_ret; 1066 938 } ··· 1101 973 return -EOPNOTSUPP; 1102 974 } 1103 975 1104 - ret = sysfs_match_string(typec_port_types, buf); 976 + ret = sysfs_match_string(typec_port_power_roles, buf); 1105 977 if (ret < 0) 1106 978 return ret; 1107 979 ··· 1135 1007 return sprintf(buf, "%s\n", 1136 1008 typec_port_types_drp[port->port_type]); 1137 1009 1138 - return sprintf(buf, "[%s]\n", typec_port_types[port->cap->type]); 1010 + return sprintf(buf, "[%s]\n", typec_port_power_roles[port->cap->type]); 1139 1011 } 1140 1012 static DEVICE_ATTR_RW(port_type); 1141 1013 ··· 1269 1141 struct typec_port *port = to_typec_port(dev); 1270 1142 1271 1143 ida_simple_remove(&typec_index_ida, port->id); 1144 + ida_destroy(&port->mode_ids); 1272 1145 typec_switch_put(port->sw); 1273 1146 typec_mux_put(port->mux); 1274 1147 kfree(port); 1275 1148 } 1276 1149 1277 - static const struct device_type typec_port_dev_type = { 1150 + const struct device_type typec_port_dev_type = { 1278 1151 .name = "typec_port", 1279 1152 .groups = typec_groups, 1280 1153 .uevent = typec_uevent, ··· 1381 1252 } 1382 1253 EXPORT_SYMBOL_GPL(typec_set_pwr_opmode); 1383 1254 1255 + /** 1256 + * typec_find_port_power_role - Get the typec port power capability 1257 + * @name: port power capability string 1258 + * 1259 + * This routine is used to find the typec_port_type by its string name. 1260 + * 1261 + * Returns typec_port_type if success, otherwise negative error code. 1262 + */ 1263 + int typec_find_port_power_role(const char *name) 1264 + { 1265 + return match_string(typec_port_power_roles, 1266 + ARRAY_SIZE(typec_port_power_roles), name); 1267 + } 1268 + EXPORT_SYMBOL_GPL(typec_find_port_power_role); 1269 + 1270 + /** 1271 + * typec_find_power_role - Find the typec one specific power role 1272 + * @name: power role string 1273 + * 1274 + * This routine is used to find the typec_role by its string name. 1275 + * 1276 + * Returns typec_role if success, otherwise negative error code. 1277 + */ 1278 + int typec_find_power_role(const char *name) 1279 + { 1280 + return match_string(typec_roles, ARRAY_SIZE(typec_roles), name); 1281 + } 1282 + EXPORT_SYMBOL_GPL(typec_find_power_role); 1283 + 1284 + /** 1285 + * typec_find_port_data_role - Get the typec port data capability 1286 + * @name: port data capability string 1287 + * 1288 + * This routine is used to find the typec_port_data by its string name. 1289 + * 1290 + * Returns typec_port_data if success, otherwise negative error code. 1291 + */ 1292 + int typec_find_port_data_role(const char *name) 1293 + { 1294 + return match_string(typec_port_data_roles, 1295 + ARRAY_SIZE(typec_port_data_roles), name); 1296 + } 1297 + EXPORT_SYMBOL_GPL(typec_find_port_data_role); 1298 + 1384 1299 /* ------------------------------------------ */ 1385 1300 /* API for Multiplexer/DeMultiplexer Switches */ 1386 1301 ··· 1453 1280 EXPORT_SYMBOL_GPL(typec_set_orientation); 1454 1281 1455 1282 /** 1456 - * typec_set_mode - Set mode of operation for USB Type-C connector 1457 - * @port: USB Type-C port for the connector 1458 - * @mode: Operation mode for the connector 1283 + * typec_get_orientation - Get USB Type-C cable plug orientation 1284 + * @port: USB Type-C Port 1459 1285 * 1460 - * Set mode @mode for @port. This function will configure the muxes needed to 1461 - * enter @mode. 1286 + * Get current cable plug orientation for @port. 1287 + */ 1288 + enum typec_orientation typec_get_orientation(struct typec_port *port) 1289 + { 1290 + return port->orientation; 1291 + } 1292 + EXPORT_SYMBOL_GPL(typec_get_orientation); 1293 + 1294 + /** 1295 + * typec_set_mode - Set mode of operation for USB Type-C connector 1296 + * @port: USB Type-C connector 1297 + * @mode: Accessory Mode, USB Operation or Safe State 1298 + * 1299 + * Configure @port for Accessory Mode @mode. This function will configure the 1300 + * muxes needed for @mode. 1462 1301 */ 1463 1302 int typec_set_mode(struct typec_port *port, int mode) 1464 1303 { ··· 1484 1299 * typec_port_register_altmode - Register USB Type-C Port Alternate Mode 1485 1300 * @port: USB Type-C Port that supports the alternate mode 1486 1301 * @desc: Description of the alternate mode 1302 + * @drvdata: Private pointer to driver specific info 1487 1303 * 1488 1304 * This routine is used to register an alternate mode that @port is capable of 1489 1305 * supporting. ··· 1495 1309 typec_port_register_altmode(struct typec_port *port, 1496 1310 const struct typec_altmode_desc *desc) 1497 1311 { 1498 - return typec_register_altmode(&port->dev, desc); 1312 + struct typec_altmode *adev; 1313 + struct typec_mux *mux; 1314 + char id[10]; 1315 + 1316 + sprintf(id, "id%04xm%02x", desc->svid, desc->mode); 1317 + 1318 + mux = typec_mux_get(port->dev.parent, id); 1319 + if (IS_ERR(mux)) 1320 + return ERR_CAST(mux); 1321 + 1322 + adev = typec_register_altmode(&port->dev, desc); 1323 + if (IS_ERR(adev)) 1324 + typec_mux_put(mux); 1325 + else 1326 + to_altmode(adev)->mux = mux; 1327 + 1328 + return adev; 1499 1329 } 1500 1330 EXPORT_SYMBOL_GPL(typec_port_register_altmode); 1501 1331 ··· 1547 1345 goto err_switch; 1548 1346 } 1549 1347 1550 - port->mux = typec_mux_get(cap->fwnode ? &port->dev : parent); 1348 + port->mux = typec_mux_get(parent, "typec-mux"); 1551 1349 if (IS_ERR(port->mux)) { 1552 1350 ret = PTR_ERR(port->mux); 1553 1351 goto err_mux; ··· 1585 1383 break; 1586 1384 } 1587 1385 1386 + ida_init(&port->mode_ids); 1387 + mutex_init(&port->port_type_lock); 1388 + 1588 1389 port->id = id; 1589 1390 port->cap = cap; 1590 1391 port->port_type = cap->type; 1591 - mutex_init(&port->port_type_lock); 1592 1392 port->prefer_role = cap->prefer_role; 1593 1393 1594 1394 port->dev.class = typec_class; ··· 1634 1430 1635 1431 static int __init typec_init(void) 1636 1432 { 1433 + int ret; 1434 + 1435 + ret = bus_register(&typec_bus); 1436 + if (ret) 1437 + return ret; 1438 + 1637 1439 typec_class = class_create(THIS_MODULE, "typec"); 1638 - return PTR_ERR_OR_ZERO(typec_class); 1440 + if (IS_ERR(typec_class)) { 1441 + bus_unregister(&typec_bus); 1442 + return PTR_ERR(typec_class); 1443 + } 1444 + 1445 + return 0; 1639 1446 } 1640 1447 subsys_initcall(typec_init); 1641 1448 ··· 1654 1439 { 1655 1440 class_destroy(typec_class); 1656 1441 ida_destroy(&typec_index_ida); 1442 + bus_unregister(&typec_bus); 1657 1443 } 1658 1444 module_exit(typec_exit); 1659 1445
-12
drivers/usb/typec/fusb302/fusb302.c
··· 864 864 return ret; 865 865 } 866 866 867 - static int tcpm_set_current_limit(struct tcpc_dev *dev, u32 max_ma, u32 mv) 868 - { 869 - struct fusb302_chip *chip = container_of(dev, struct fusb302_chip, 870 - tcpc_dev); 871 - 872 - fusb302_log(chip, "current limit: %d ma, %d mv (not implemented)", 873 - max_ma, mv); 874 - 875 - return 0; 876 - } 877 - 878 867 static int fusb302_pd_tx_flush(struct fusb302_chip *chip) 879 868 { 880 869 return fusb302_i2c_set_bits(chip, FUSB_REG_CONTROL0, ··· 1202 1213 fusb302_tcpc_dev->set_polarity = tcpm_set_polarity; 1203 1214 fusb302_tcpc_dev->set_vconn = tcpm_set_vconn; 1204 1215 fusb302_tcpc_dev->set_vbus = tcpm_set_vbus; 1205 - fusb302_tcpc_dev->set_current_limit = tcpm_set_current_limit; 1206 1216 fusb302_tcpc_dev->set_pd_rx = tcpm_set_pd_rx; 1207 1217 fusb302_tcpc_dev->set_roles = tcpm_set_roles; 1208 1218 fusb302_tcpc_dev->start_drp_toggling = tcpm_start_drp_toggling;
+3 -3
drivers/usb/typec/mux.c
··· 123 123 /** 124 124 * typec_mux_get - Find USB Type-C Multiplexer 125 125 * @dev: The caller device 126 + * @name: Mux identifier 126 127 * 127 128 * Finds a mux linked to the caller. This function is primarily meant for the 128 129 * Type-C drivers. Returns a reference to the mux on success, NULL if no 129 130 * matching connection was found, or ERR_PTR(-EPROBE_DEFER) when a connection 130 131 * was found but the mux has not been enumerated yet. 131 132 */ 132 - struct typec_mux *typec_mux_get(struct device *dev) 133 + struct typec_mux *typec_mux_get(struct device *dev, const char *name) 133 134 { 134 135 struct typec_mux *mux; 135 136 136 137 mutex_lock(&mux_lock); 137 - mux = device_connection_find_match(dev, "typec-mux", NULL, 138 - typec_mux_match); 138 + mux = device_connection_find_match(dev, name, NULL, typec_mux_match); 139 139 if (!IS_ERR_OR_NULL(mux)) 140 140 get_device(mux->dev); 141 141 mutex_unlock(&mux_lock);
+8 -5
drivers/usb/typec/mux/pi3usb30532.c
··· 9 9 #include <linux/kernel.h> 10 10 #include <linux/module.h> 11 11 #include <linux/mutex.h> 12 - #include <linux/usb/tcpm.h> 12 + #include <linux/usb/typec_dp.h> 13 13 #include <linux/usb/typec_mux.h> 14 14 15 15 #define PI3USB30532_CONF 0x00 ··· 83 83 new_conf = pi->conf; 84 84 85 85 switch (state) { 86 - case TYPEC_MUX_NONE: 86 + case TYPEC_STATE_SAFE: 87 87 new_conf = PI3USB30532_CONF_OPEN; 88 88 break; 89 - case TYPEC_MUX_USB: 89 + case TYPEC_STATE_USB: 90 90 new_conf = (new_conf & PI3USB30532_CONF_SWAP) | 91 91 PI3USB30532_CONF_USB3; 92 92 break; 93 - case TYPEC_MUX_DP: 93 + case TYPEC_DP_STATE_C: 94 + case TYPEC_DP_STATE_E: 94 95 new_conf = (new_conf & PI3USB30532_CONF_SWAP) | 95 96 PI3USB30532_CONF_4LANE_DP; 96 97 break; 97 - case TYPEC_MUX_DOCK: 98 + case TYPEC_DP_STATE_D: 98 99 new_conf = (new_conf & PI3USB30532_CONF_SWAP) | 99 100 PI3USB30532_CONF_USB3_AND_2LANE_DP; 101 + break; 102 + default: 100 103 break; 101 104 } 102 105
+258 -70
drivers/usb/typec/tcpm.c
··· 26 26 #include <linux/usb/pd_vdo.h> 27 27 #include <linux/usb/role.h> 28 28 #include <linux/usb/tcpm.h> 29 - #include <linux/usb/typec.h> 29 + #include <linux/usb/typec_altmode.h> 30 30 #include <linux/workqueue.h> 31 31 32 32 #define FOREACH_STATE(S) \ ··· 169 169 /* Alternate mode support */ 170 170 171 171 #define SVID_DISCOVERY_MAX 16 172 + #define ALTMODE_DISCOVERY_MAX (SVID_DISCOVERY_MAX * MODE_DISCOVERY_MAX) 172 173 173 174 struct pd_mode_data { 174 175 int svid_index; /* current SVID index */ 175 176 int nsvids; 176 177 u16 svids[SVID_DISCOVERY_MAX]; 177 178 int altmodes; /* number of alternate modes */ 178 - struct typec_altmode_desc altmode_desc[SVID_DISCOVERY_MAX]; 179 + struct typec_altmode_desc altmode_desc[ALTMODE_DISCOVERY_MAX]; 179 180 }; 180 181 181 182 struct pd_pps_data { ··· 311 310 312 311 /* Alternate mode data */ 313 312 struct pd_mode_data mode_data; 314 - struct typec_altmode *partner_altmode[SVID_DISCOVERY_MAX]; 315 - struct typec_altmode *port_altmode[SVID_DISCOVERY_MAX]; 313 + struct typec_altmode *partner_altmode[ALTMODE_DISCOVERY_MAX]; 314 + struct typec_altmode *port_altmode[ALTMODE_DISCOVERY_MAX]; 316 315 317 316 /* Deadline in jiffies to exit src_try_wait state */ 318 317 unsigned long max_wait; ··· 642 641 } 643 642 EXPORT_SYMBOL_GPL(tcpm_pd_transmit_complete); 644 643 645 - static int tcpm_mux_set(struct tcpm_port *port, enum tcpc_mux_mode mode, 644 + static int tcpm_mux_set(struct tcpm_port *port, int state, 646 645 enum usb_role usb_role, 647 646 enum typec_orientation orientation) 648 647 { 649 648 int ret; 650 649 651 - tcpm_log(port, "Requesting mux mode %d, usb-role %d, orientation %d", 652 - mode, usb_role, orientation); 650 + tcpm_log(port, "Requesting mux state %d, usb-role %d, orientation %d", 651 + state, usb_role, orientation); 653 652 654 653 ret = typec_set_orientation(port->typec_port, orientation); 655 654 if (ret) ··· 661 660 return ret; 662 661 } 663 662 664 - return typec_set_mode(port->typec_port, mode); 663 + return typec_set_mode(port->typec_port, state); 665 664 } 666 665 667 666 static int tcpm_set_polarity(struct tcpm_port *port, ··· 791 790 else 792 791 usb_role = USB_ROLE_DEVICE; 793 792 794 - ret = tcpm_mux_set(port, TYPEC_MUX_USB, usb_role, orientation); 793 + ret = tcpm_mux_set(port, TYPEC_STATE_USB, usb_role, orientation); 795 794 if (ret < 0) 796 795 return ret; 797 796 ··· 999 998 { 1000 999 struct pd_mode_data *pmdata = &port->mode_data; 1001 1000 struct typec_altmode_desc *paltmode; 1002 - struct typec_mode_desc *pmode; 1003 1001 int i; 1004 1002 1005 1003 if (pmdata->altmodes >= ARRAY_SIZE(port->partner_altmode)) { ··· 1006 1006 return; 1007 1007 } 1008 1008 1009 - paltmode = &pmdata->altmode_desc[pmdata->altmodes]; 1010 - memset(paltmode, 0, sizeof(*paltmode)); 1009 + for (i = 1; i < cnt; i++) { 1010 + paltmode = &pmdata->altmode_desc[pmdata->altmodes]; 1011 + memset(paltmode, 0, sizeof(*paltmode)); 1011 1012 1012 - paltmode->svid = pmdata->svids[pmdata->svid_index]; 1013 + paltmode->svid = pmdata->svids[pmdata->svid_index]; 1014 + paltmode->mode = i; 1015 + paltmode->vdo = le32_to_cpu(payload[i]); 1013 1016 1014 - tcpm_log(port, " Alternate mode %d: SVID 0x%04x", 1015 - pmdata->altmodes, paltmode->svid); 1017 + tcpm_log(port, " Alternate mode %d: SVID 0x%04x, VDO %d: 0x%08x", 1018 + pmdata->altmodes, paltmode->svid, 1019 + paltmode->mode, paltmode->vdo); 1016 1020 1017 - for (i = 1; i < cnt && paltmode->n_modes < ALTMODE_MAX_MODES; i++) { 1018 - pmode = &paltmode->modes[paltmode->n_modes]; 1019 - memset(pmode, 0, sizeof(*pmode)); 1020 - pmode->vdo = le32_to_cpu(payload[i]); 1021 - pmode->index = i - 1; 1022 - paltmode->n_modes++; 1023 - tcpm_log(port, " VDO %d: 0x%08x", 1024 - pmode->index, pmode->vdo); 1021 + pmdata->altmodes++; 1025 1022 } 1026 - port->partner_altmode[pmdata->altmodes] = 1027 - typec_partner_register_altmode(port->partner, paltmode); 1028 - if (!port->partner_altmode[pmdata->altmodes]) { 1029 - tcpm_log(port, 1030 - "Failed to register alternate modes for SVID 0x%04x", 1031 - paltmode->svid); 1032 - return; 1023 + } 1024 + 1025 + static void tcpm_register_partner_altmodes(struct tcpm_port *port) 1026 + { 1027 + struct pd_mode_data *modep = &port->mode_data; 1028 + struct typec_altmode *altmode; 1029 + int i; 1030 + 1031 + for (i = 0; i < modep->altmodes; i++) { 1032 + altmode = typec_partner_register_altmode(port->partner, 1033 + &modep->altmode_desc[i]); 1034 + if (!altmode) 1035 + tcpm_log(port, "Failed to register partner SVID 0x%04x", 1036 + modep->altmode_desc[i].svid); 1037 + port->partner_altmode[i] = altmode; 1033 1038 } 1034 - pmdata->altmodes++; 1035 1039 } 1036 1040 1037 1041 #define supports_modal(port) PD_IDH_MODAL_SUPP((port)->partner_ident.id_header) ··· 1043 1039 static int tcpm_pd_svdm(struct tcpm_port *port, const __le32 *payload, int cnt, 1044 1040 u32 *response) 1045 1041 { 1046 - u32 p0 = le32_to_cpu(payload[0]); 1047 - int cmd_type = PD_VDO_CMDT(p0); 1048 - int cmd = PD_VDO_CMD(p0); 1042 + struct typec_altmode *adev; 1043 + struct typec_altmode *pdev; 1049 1044 struct pd_mode_data *modep; 1045 + u32 p[PD_MAX_PAYLOAD]; 1050 1046 int rlen = 0; 1051 - u16 svid; 1047 + int cmd_type; 1048 + int cmd; 1052 1049 int i; 1053 1050 1051 + for (i = 0; i < cnt; i++) 1052 + p[i] = le32_to_cpu(payload[i]); 1053 + 1054 + cmd_type = PD_VDO_CMDT(p[0]); 1055 + cmd = PD_VDO_CMD(p[0]); 1056 + 1054 1057 tcpm_log(port, "Rx VDM cmd 0x%x type %d cmd %d len %d", 1055 - p0, cmd_type, cmd, cnt); 1058 + p[0], cmd_type, cmd, cnt); 1056 1059 1057 1060 modep = &port->mode_data; 1061 + 1062 + adev = typec_match_altmode(port->port_altmode, ALTMODE_DISCOVERY_MAX, 1063 + PD_VDO_VID(p[0]), PD_VDO_OPOS(p[0])); 1064 + 1065 + pdev = typec_match_altmode(port->partner_altmode, ALTMODE_DISCOVERY_MAX, 1066 + PD_VDO_VID(p[0]), PD_VDO_OPOS(p[0])); 1058 1067 1059 1068 switch (cmd_type) { 1060 1069 case CMDT_INIT: ··· 1090 1073 case CMD_EXIT_MODE: 1091 1074 break; 1092 1075 case CMD_ATTENTION: 1093 - break; 1076 + /* Attention command does not have response */ 1077 + typec_altmode_attention(adev, p[1]); 1078 + return 0; 1094 1079 default: 1095 1080 break; 1096 1081 } 1097 1082 if (rlen >= 1) { 1098 - response[0] = p0 | VDO_CMDT(CMDT_RSP_ACK); 1083 + response[0] = p[0] | VDO_CMDT(CMDT_RSP_ACK); 1099 1084 } else if (rlen == 0) { 1100 - response[0] = p0 | VDO_CMDT(CMDT_RSP_NAK); 1085 + response[0] = p[0] | VDO_CMDT(CMDT_RSP_NAK); 1101 1086 rlen = 1; 1102 1087 } else { 1103 - response[0] = p0 | VDO_CMDT(CMDT_RSP_BUSY); 1088 + response[0] = p[0] | VDO_CMDT(CMDT_RSP_BUSY); 1104 1089 rlen = 1; 1105 1090 } 1106 1091 break; ··· 1135 1116 svdm_consume_modes(port, payload, cnt); 1136 1117 modep->svid_index++; 1137 1118 if (modep->svid_index < modep->nsvids) { 1138 - svid = modep->svids[modep->svid_index]; 1119 + u16 svid = modep->svids[modep->svid_index]; 1139 1120 response[0] = VDO(svid, 1, CMD_DISCOVER_MODES); 1140 1121 rlen = 1; 1141 1122 } else { 1142 - /* enter alternate mode if/when implemented */ 1123 + tcpm_register_partner_altmodes(port); 1143 1124 } 1144 1125 break; 1145 1126 case CMD_ENTER_MODE: 1127 + typec_altmode_update_active(pdev, true); 1128 + 1129 + if (typec_altmode_vdm(adev, p[0], &p[1], cnt)) { 1130 + response[0] = VDO(adev->svid, 1, CMD_EXIT_MODE); 1131 + response[0] |= VDO_OPOS(adev->mode); 1132 + return 1; 1133 + } 1134 + return 0; 1135 + case CMD_EXIT_MODE: 1136 + typec_altmode_update_active(pdev, false); 1137 + 1138 + /* Back to USB Operation */ 1139 + WARN_ON(typec_altmode_notify(adev, TYPEC_STATE_USB, 1140 + NULL)); 1141 + break; 1142 + default: 1143 + break; 1144 + } 1145 + break; 1146 + case CMDT_RSP_NAK: 1147 + switch (cmd) { 1148 + case CMD_ENTER_MODE: 1149 + /* Back to USB Operation */ 1150 + WARN_ON(typec_altmode_notify(adev, TYPEC_STATE_USB, 1151 + NULL)); 1146 1152 break; 1147 1153 default: 1148 1154 break; ··· 1176 1132 default: 1177 1133 break; 1178 1134 } 1135 + 1136 + /* Informing the alternate mode drivers about everything */ 1137 + typec_altmode_vdm(adev, p[0], &p[1], cnt); 1179 1138 1180 1139 return rlen; 1181 1140 } ··· 1462 1415 1463 1416 return 0; 1464 1417 } 1418 + 1419 + static int tcpm_altmode_enter(struct typec_altmode *altmode) 1420 + { 1421 + struct tcpm_port *port = typec_altmode_get_drvdata(altmode); 1422 + u32 header; 1423 + 1424 + mutex_lock(&port->lock); 1425 + header = VDO(altmode->svid, 1, CMD_ENTER_MODE); 1426 + header |= VDO_OPOS(altmode->mode); 1427 + 1428 + tcpm_queue_vdm(port, header, NULL, 0); 1429 + mod_delayed_work(port->wq, &port->vdm_state_machine, 0); 1430 + mutex_unlock(&port->lock); 1431 + 1432 + return 0; 1433 + } 1434 + 1435 + static int tcpm_altmode_exit(struct typec_altmode *altmode) 1436 + { 1437 + struct tcpm_port *port = typec_altmode_get_drvdata(altmode); 1438 + u32 header; 1439 + 1440 + mutex_lock(&port->lock); 1441 + header = VDO(altmode->svid, 1, CMD_EXIT_MODE); 1442 + header |= VDO_OPOS(altmode->mode); 1443 + 1444 + tcpm_queue_vdm(port, header, NULL, 0); 1445 + mod_delayed_work(port->wq, &port->vdm_state_machine, 0); 1446 + mutex_unlock(&port->lock); 1447 + 1448 + return 0; 1449 + } 1450 + 1451 + static int tcpm_altmode_vdm(struct typec_altmode *altmode, 1452 + u32 header, const u32 *data, int count) 1453 + { 1454 + struct tcpm_port *port = typec_altmode_get_drvdata(altmode); 1455 + 1456 + mutex_lock(&port->lock); 1457 + tcpm_queue_vdm(port, header, data, count - 1); 1458 + mod_delayed_work(port->wq, &port->vdm_state_machine, 0); 1459 + mutex_unlock(&port->lock); 1460 + 1461 + return 0; 1462 + } 1463 + 1464 + static const struct typec_altmode_ops tcpm_altmode_ops = { 1465 + .enter = tcpm_altmode_enter, 1466 + .exit = tcpm_altmode_exit, 1467 + .vdm = tcpm_altmode_vdm, 1468 + }; 1465 1469 1466 1470 /* 1467 1471 * PD (data, control) command handling functions ··· 2533 2435 return 0; 2534 2436 } 2535 2437 2536 - static bool tcpm_start_drp_toggling(struct tcpm_port *port) 2438 + static bool tcpm_start_drp_toggling(struct tcpm_port *port, 2439 + enum typec_cc_status cc) 2537 2440 { 2538 2441 int ret; 2539 2442 2540 2443 if (port->tcpc->start_drp_toggling && 2541 2444 port->port_type == TYPEC_PORT_DRP) { 2542 2445 tcpm_log_force(port, "Start DRP toggling"); 2543 - ret = port->tcpc->start_drp_toggling(port->tcpc, 2544 - tcpm_rp_cc(port)); 2446 + ret = port->tcpc->start_drp_toggling(port->tcpc, cc); 2545 2447 if (!ret) 2546 2448 return true; 2547 2449 } ··· 2645 2547 out_disable_pd: 2646 2548 port->tcpc->set_pd_rx(port->tcpc, false); 2647 2549 out_disable_mux: 2648 - tcpm_mux_set(port, TYPEC_MUX_NONE, USB_ROLE_NONE, 2550 + tcpm_mux_set(port, TYPEC_STATE_SAFE, USB_ROLE_NONE, 2649 2551 TYPEC_ORIENTATION_NONE); 2650 2552 return ret; 2651 2553 } ··· 2691 2593 tcpm_init_vconn(port); 2692 2594 tcpm_set_current_limit(port, 0, 0); 2693 2595 tcpm_set_polarity(port, TYPEC_POLARITY_CC1); 2694 - tcpm_mux_set(port, TYPEC_MUX_NONE, USB_ROLE_NONE, 2596 + tcpm_mux_set(port, TYPEC_STATE_SAFE, USB_ROLE_NONE, 2695 2597 TYPEC_ORIENTATION_NONE); 2696 2598 tcpm_set_attached_state(port, false); 2697 2599 port->try_src_count = 0; ··· 2847 2749 if (!port->non_pd_role_swap) 2848 2750 tcpm_swap_complete(port, -ENOTCONN); 2849 2751 tcpm_src_detach(port); 2850 - if (tcpm_start_drp_toggling(port)) { 2752 + if (tcpm_start_drp_toggling(port, tcpm_rp_cc(port))) { 2851 2753 tcpm_set_state(port, DRP_TOGGLING, 0); 2852 2754 break; 2853 2755 } ··· 3022 2924 tcpm_swap_complete(port, -ENOTCONN); 3023 2925 tcpm_pps_complete(port, -ENOTCONN); 3024 2926 tcpm_snk_detach(port); 3025 - if (tcpm_start_drp_toggling(port)) { 2927 + if (tcpm_start_drp_toggling(port, TYPEC_CC_RD)) { 3026 2928 tcpm_set_state(port, DRP_TOGGLING, 0); 3027 2929 break; 3028 2930 } ··· 4337 4239 return nr_vdo; 4338 4240 } 4339 4241 4242 + static int tcpm_fw_get_caps(struct tcpm_port *port, 4243 + struct fwnode_handle *fwnode) 4244 + { 4245 + const char *cap_str; 4246 + int ret; 4247 + u32 mw; 4248 + 4249 + if (!fwnode) 4250 + return -EINVAL; 4251 + 4252 + /* USB data support is optional */ 4253 + ret = fwnode_property_read_string(fwnode, "data-role", &cap_str); 4254 + if (ret == 0) { 4255 + port->typec_caps.data = typec_find_port_data_role(cap_str); 4256 + if (port->typec_caps.data < 0) 4257 + return -EINVAL; 4258 + } 4259 + 4260 + ret = fwnode_property_read_string(fwnode, "power-role", &cap_str); 4261 + if (ret < 0) 4262 + return ret; 4263 + 4264 + port->typec_caps.type = typec_find_port_power_role(cap_str); 4265 + if (port->typec_caps.type < 0) 4266 + return -EINVAL; 4267 + port->port_type = port->typec_caps.type; 4268 + 4269 + if (port->port_type == TYPEC_PORT_SNK) 4270 + goto sink; 4271 + 4272 + /* Get source pdos */ 4273 + ret = fwnode_property_read_u32_array(fwnode, "source-pdos", 4274 + NULL, 0); 4275 + if (ret <= 0) 4276 + return -EINVAL; 4277 + 4278 + port->nr_src_pdo = min(ret, PDO_MAX_OBJECTS); 4279 + ret = fwnode_property_read_u32_array(fwnode, "source-pdos", 4280 + port->src_pdo, port->nr_src_pdo); 4281 + if ((ret < 0) || tcpm_validate_caps(port, port->src_pdo, 4282 + port->nr_src_pdo)) 4283 + return -EINVAL; 4284 + 4285 + if (port->port_type == TYPEC_PORT_SRC) 4286 + return 0; 4287 + 4288 + /* Get the preferred power role for DRP */ 4289 + ret = fwnode_property_read_string(fwnode, "try-power-role", &cap_str); 4290 + if (ret < 0) 4291 + return ret; 4292 + 4293 + port->typec_caps.prefer_role = typec_find_power_role(cap_str); 4294 + if (port->typec_caps.prefer_role < 0) 4295 + return -EINVAL; 4296 + sink: 4297 + /* Get sink pdos */ 4298 + ret = fwnode_property_read_u32_array(fwnode, "sink-pdos", 4299 + NULL, 0); 4300 + if (ret <= 0) 4301 + return -EINVAL; 4302 + 4303 + port->nr_snk_pdo = min(ret, PDO_MAX_OBJECTS); 4304 + ret = fwnode_property_read_u32_array(fwnode, "sink-pdos", 4305 + port->snk_pdo, port->nr_snk_pdo); 4306 + if ((ret < 0) || tcpm_validate_caps(port, port->snk_pdo, 4307 + port->nr_snk_pdo)) 4308 + return -EINVAL; 4309 + 4310 + if (fwnode_property_read_u32(fwnode, "op-sink-microwatt", &mw) < 0) 4311 + return -EINVAL; 4312 + port->operating_snk_mw = mw / 1000; 4313 + 4314 + return 0; 4315 + } 4316 + 4340 4317 int tcpm_update_source_capabilities(struct tcpm_port *port, const u32 *pdo, 4341 4318 unsigned int nr_pdo) 4342 4319 { ··· 4697 4524 return PTR_ERR_OR_ZERO(port->psy); 4698 4525 } 4699 4526 4527 + static int tcpm_copy_caps(struct tcpm_port *port, 4528 + const struct tcpc_config *tcfg) 4529 + { 4530 + if (tcpm_validate_caps(port, tcfg->src_pdo, tcfg->nr_src_pdo) || 4531 + tcpm_validate_caps(port, tcfg->snk_pdo, tcfg->nr_snk_pdo)) 4532 + return -EINVAL; 4533 + 4534 + port->nr_src_pdo = tcpm_copy_pdos(port->src_pdo, tcfg->src_pdo, 4535 + tcfg->nr_src_pdo); 4536 + port->nr_snk_pdo = tcpm_copy_pdos(port->snk_pdo, tcfg->snk_pdo, 4537 + tcfg->nr_snk_pdo); 4538 + 4539 + port->nr_snk_vdo = tcpm_copy_vdos(port->snk_vdo, tcfg->snk_vdo, 4540 + tcfg->nr_snk_vdo); 4541 + 4542 + port->operating_snk_mw = tcfg->operating_snk_mw; 4543 + 4544 + port->typec_caps.prefer_role = tcfg->default_role; 4545 + port->typec_caps.type = tcfg->type; 4546 + port->typec_caps.data = tcfg->data; 4547 + 4548 + return 0; 4549 + } 4550 + 4700 4551 struct tcpm_port *tcpm_register_port(struct device *dev, struct tcpc_dev *tcpc) 4701 4552 { 4702 4553 struct tcpm_port *port; 4703 4554 int i, err; 4704 4555 4705 - if (!dev || !tcpc || !tcpc->config || 4556 + if (!dev || !tcpc || 4706 4557 !tcpc->get_vbus || !tcpc->set_cc || !tcpc->get_cc || 4707 4558 !tcpc->set_polarity || !tcpc->set_vconn || !tcpc->set_vbus || 4708 4559 !tcpc->set_pd_rx || !tcpc->set_roles || !tcpc->pd_transmit) ··· 4756 4559 init_completion(&port->pps_complete); 4757 4560 tcpm_debugfs_init(port); 4758 4561 4759 - if (tcpm_validate_caps(port, tcpc->config->src_pdo, 4760 - tcpc->config->nr_src_pdo) || 4761 - tcpm_validate_caps(port, tcpc->config->snk_pdo, 4762 - tcpc->config->nr_snk_pdo)) { 4763 - err = -EINVAL; 4562 + err = tcpm_fw_get_caps(port, tcpc->fwnode); 4563 + if ((err < 0) && tcpc->config) 4564 + err = tcpm_copy_caps(port, tcpc->config); 4565 + if (err < 0) 4764 4566 goto out_destroy_wq; 4765 - } 4766 - port->nr_src_pdo = tcpm_copy_pdos(port->src_pdo, tcpc->config->src_pdo, 4767 - tcpc->config->nr_src_pdo); 4768 - port->nr_snk_pdo = tcpm_copy_pdos(port->snk_pdo, tcpc->config->snk_pdo, 4769 - tcpc->config->nr_snk_pdo); 4770 - port->nr_snk_vdo = tcpm_copy_vdos(port->snk_vdo, tcpc->config->snk_vdo, 4771 - tcpc->config->nr_snk_vdo); 4772 4567 4773 - port->operating_snk_mw = tcpc->config->operating_snk_mw; 4774 - if (!tcpc->config->try_role_hw) 4775 - port->try_role = tcpc->config->default_role; 4568 + if (!tcpc->config || !tcpc->config->try_role_hw) 4569 + port->try_role = port->typec_caps.prefer_role; 4776 4570 else 4777 4571 port->try_role = TYPEC_NO_PREFERRED_ROLE; 4778 4572 4779 - port->typec_caps.prefer_role = tcpc->config->default_role; 4780 - port->typec_caps.type = tcpc->config->type; 4781 - port->typec_caps.data = tcpc->config->data; 4573 + port->typec_caps.fwnode = tcpc->fwnode; 4782 4574 port->typec_caps.revision = 0x0120; /* Type-C spec release 1.2 */ 4783 4575 port->typec_caps.pd_revision = 0x0300; /* USB-PD spec release 3.0 */ 4784 4576 port->typec_caps.dr_set = tcpm_dr_set; ··· 4777 4591 port->typec_caps.port_type_set = tcpm_port_type_set; 4778 4592 4779 4593 port->partner_desc.identity = &port->partner_ident; 4780 - port->port_type = tcpc->config->type; 4594 + port->port_type = port->typec_caps.type; 4781 4595 4782 4596 port->role_sw = usb_role_switch_get(port->dev); 4783 4597 if (IS_ERR(port->role_sw)) { ··· 4795 4609 goto out_destroy_wq; 4796 4610 } 4797 4611 4798 - if (tcpc->config->alt_modes) { 4612 + if (tcpc->config && tcpc->config->alt_modes) { 4799 4613 const struct typec_altmode_desc *paltmode = tcpc->config->alt_modes; 4800 4614 4801 4615 i = 0; ··· 4810 4624 dev_name(dev), paltmode->svid); 4811 4625 break; 4812 4626 } 4627 + typec_altmode_set_drvdata(alt, port); 4628 + alt->ops = &tcpm_altmode_ops; 4813 4629 port->port_altmode[i] = alt; 4814 4630 i++; 4815 4631 paltmode++;
+10 -1
drivers/usb/typec/tps6598x.c
··· 81 81 struct typec_capability typec_cap; 82 82 }; 83 83 84 + /* 85 + * Max data bytes for Data1, Data2, and other registers. See ch 1.3.2: 86 + * http://www.ti.com/lit/ug/slvuan1a/slvuan1a.pdf 87 + */ 88 + #define TPS_MAX_LEN 64 89 + 84 90 static int 85 91 tps6598x_block_read(struct tps6598x *tps, u8 reg, void *val, size_t len) 86 92 { 87 - u8 data[len + 1]; 93 + u8 data[TPS_MAX_LEN + 1]; 88 94 int ret; 95 + 96 + if (WARN_ON(len + 1 > sizeof(data))) 97 + return -EINVAL; 89 98 90 99 if (!tps->i2c_protocol) 91 100 return regmap_raw_read(tps->regmap, reg, val, len);
+6 -4
drivers/usb/usb-skeleton.c
··· 159 159 static void skel_read_bulk_callback(struct urb *urb) 160 160 { 161 161 struct usb_skel *dev; 162 + unsigned long flags; 162 163 163 164 dev = urb->context; 164 165 165 - spin_lock(&dev->err_lock); 166 + spin_lock_irqsave(&dev->err_lock, flags); 166 167 /* sync/async unlink faults aren't errors */ 167 168 if (urb->status) { 168 169 if (!(urb->status == -ENOENT || ··· 178 177 dev->bulk_in_filled = urb->actual_length; 179 178 } 180 179 dev->ongoing_read = 0; 181 - spin_unlock(&dev->err_lock); 180 + spin_unlock_irqrestore(&dev->err_lock, flags); 182 181 183 182 wake_up_interruptible(&dev->bulk_in_wait); 184 183 } ··· 332 331 static void skel_write_bulk_callback(struct urb *urb) 333 332 { 334 333 struct usb_skel *dev; 334 + unsigned long flags; 335 335 336 336 dev = urb->context; 337 337 ··· 345 343 "%s - nonzero write bulk status received: %d\n", 346 344 __func__, urb->status); 347 345 348 - spin_lock(&dev->err_lock); 346 + spin_lock_irqsave(&dev->err_lock, flags); 349 347 dev->errors = urb->status; 350 - spin_unlock(&dev->err_lock); 348 + spin_unlock_irqrestore(&dev->err_lock, flags); 351 349 } 352 350 353 351 /* free up our allocated buffer */
-2
drivers/usb/usbip/vudc_dev.c
··· 279 279 static struct usb_request *vep_alloc_request(struct usb_ep *_ep, 280 280 gfp_t mem_flags) 281 281 { 282 - struct vep *ep; 283 282 struct vrequest *req; 284 283 285 284 if (!_ep) 286 285 return NULL; 287 - ep = to_vep(_ep); 288 286 289 287 req = kzalloc(sizeof(*req), mem_flags); 290 288 if (!req)
+1 -1
drivers/usb/wusbcore/security.c
··· 217 217 218 218 result = usb_get_descriptor(usb_dev, USB_DT_SECURITY, 219 219 0, secd, sizeof(*secd)); 220 - if (result < sizeof(*secd)) { 220 + if (result < (int)sizeof(*secd)) { 221 221 dev_err(dev, "Can't read security descriptor or " 222 222 "not enough data: %d\n", result); 223 223 goto out;
+4 -4
drivers/usb/wusbcore/wa-xfer.c
··· 1918 1918 */ 1919 1919 int wa_urb_dequeue(struct wahc *wa, struct urb *urb, int status) 1920 1920 { 1921 - unsigned long flags, flags2; 1921 + unsigned long flags; 1922 1922 struct wa_xfer *xfer; 1923 1923 struct wa_seg *seg; 1924 1924 struct wa_rpipe *rpipe; ··· 1964 1964 goto out_unlock; 1965 1965 } 1966 1966 /* Check the delayed list -> if there, release and complete */ 1967 - spin_lock_irqsave(&wa->xfer_list_lock, flags2); 1967 + spin_lock(&wa->xfer_list_lock); 1968 1968 if (!list_empty(&xfer->list_node) && xfer->seg == NULL) 1969 1969 goto dequeue_delayed; 1970 - spin_unlock_irqrestore(&wa->xfer_list_lock, flags2); 1970 + spin_unlock(&wa->xfer_list_lock); 1971 1971 if (xfer->seg == NULL) /* still hasn't reached */ 1972 1972 goto out_unlock; /* setup(), enqueue_b() completes */ 1973 1973 /* Ok, the xfer is in flight already, it's been setup and submitted.*/ ··· 2054 2054 2055 2055 dequeue_delayed: 2056 2056 list_del_init(&xfer->list_node); 2057 - spin_unlock_irqrestore(&wa->xfer_list_lock, flags2); 2057 + spin_unlock(&wa->xfer_list_lock); 2058 2058 xfer->result = urb->status; 2059 2059 spin_unlock_irqrestore(&xfer->lock, flags); 2060 2060 wa_xfer_giveback(xfer);
+1
drivers/uwb/hwa-rc.c
··· 873 873 error_rc_add: 874 874 usb_put_intf(iface); 875 875 usb_put_dev(hwarc->usb_dev); 876 + kfree(hwarc); 876 877 error_alloc: 877 878 uwb_rc_put(uwb_rc); 878 879 error_rc_alloc:
+62
include/dt-bindings/usb/pd.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + #ifndef __DT_POWER_DELIVERY_H 3 + #define __DT_POWER_DELIVERY_H 4 + 5 + /* Power delivery Power Data Object definitions */ 6 + #define PDO_TYPE_FIXED 0 7 + #define PDO_TYPE_BATT 1 8 + #define PDO_TYPE_VAR 2 9 + #define PDO_TYPE_APDO 3 10 + 11 + #define PDO_TYPE_SHIFT 30 12 + #define PDO_TYPE_MASK 0x3 13 + 14 + #define PDO_TYPE(t) ((t) << PDO_TYPE_SHIFT) 15 + 16 + #define PDO_VOLT_MASK 0x3ff 17 + #define PDO_CURR_MASK 0x3ff 18 + #define PDO_PWR_MASK 0x3ff 19 + 20 + #define PDO_FIXED_DUAL_ROLE (1 << 29) /* Power role swap supported */ 21 + #define PDO_FIXED_SUSPEND (1 << 28) /* USB Suspend supported (Source) */ 22 + #define PDO_FIXED_HIGHER_CAP (1 << 28) /* Requires more than vSafe5V (Sink) */ 23 + #define PDO_FIXED_EXTPOWER (1 << 27) /* Externally powered */ 24 + #define PDO_FIXED_USB_COMM (1 << 26) /* USB communications capable */ 25 + #define PDO_FIXED_DATA_SWAP (1 << 25) /* Data role swap supported */ 26 + #define PDO_FIXED_VOLT_SHIFT 10 /* 50mV units */ 27 + #define PDO_FIXED_CURR_SHIFT 0 /* 10mA units */ 28 + 29 + #define PDO_FIXED_VOLT(mv) ((((mv) / 50) & PDO_VOLT_MASK) << PDO_FIXED_VOLT_SHIFT) 30 + #define PDO_FIXED_CURR(ma) ((((ma) / 10) & PDO_CURR_MASK) << PDO_FIXED_CURR_SHIFT) 31 + 32 + #define PDO_FIXED(mv, ma, flags) \ 33 + (PDO_TYPE(PDO_TYPE_FIXED) | (flags) | \ 34 + PDO_FIXED_VOLT(mv) | PDO_FIXED_CURR(ma)) 35 + 36 + #define VSAFE5V 5000 /* mv units */ 37 + 38 + #define PDO_BATT_MAX_VOLT_SHIFT 20 /* 50mV units */ 39 + #define PDO_BATT_MIN_VOLT_SHIFT 10 /* 50mV units */ 40 + #define PDO_BATT_MAX_PWR_SHIFT 0 /* 250mW units */ 41 + 42 + #define PDO_BATT_MIN_VOLT(mv) ((((mv) / 50) & PDO_VOLT_MASK) << PDO_BATT_MIN_VOLT_SHIFT) 43 + #define PDO_BATT_MAX_VOLT(mv) ((((mv) / 50) & PDO_VOLT_MASK) << PDO_BATT_MAX_VOLT_SHIFT) 44 + #define PDO_BATT_MAX_POWER(mw) ((((mw) / 250) & PDO_PWR_MASK) << PDO_BATT_MAX_PWR_SHIFT) 45 + 46 + #define PDO_BATT(min_mv, max_mv, max_mw) \ 47 + (PDO_TYPE(PDO_TYPE_BATT) | PDO_BATT_MIN_VOLT(min_mv) | \ 48 + PDO_BATT_MAX_VOLT(max_mv) | PDO_BATT_MAX_POWER(max_mw)) 49 + 50 + #define PDO_VAR_MAX_VOLT_SHIFT 20 /* 50mV units */ 51 + #define PDO_VAR_MIN_VOLT_SHIFT 10 /* 50mV units */ 52 + #define PDO_VAR_MAX_CURR_SHIFT 0 /* 10mA units */ 53 + 54 + #define PDO_VAR_MIN_VOLT(mv) ((((mv) / 50) & PDO_VOLT_MASK) << PDO_VAR_MIN_VOLT_SHIFT) 55 + #define PDO_VAR_MAX_VOLT(mv) ((((mv) / 50) & PDO_VOLT_MASK) << PDO_VAR_MAX_VOLT_SHIFT) 56 + #define PDO_VAR_MAX_CURR(ma) ((((ma) / 10) & PDO_CURR_MASK) << PDO_VAR_MAX_CURR_SHIFT) 57 + 58 + #define PDO_VAR(min_mv, max_mv, max_ma) \ 59 + (PDO_TYPE(PDO_TYPE_VAR) | PDO_VAR_MIN_VOLT(min_mv) | \ 60 + PDO_VAR_MAX_VOLT(max_mv) | PDO_VAR_MAX_CURR(max_ma)) 61 + 62 + #endif /* __DT_POWER_DELIVERY_H */
+15
include/linux/mod_devicetable.h
··· 746 746 #define TBSVC_MATCH_PROTOCOL_VERSION 0x0004 747 747 #define TBSVC_MATCH_PROTOCOL_REVISION 0x0008 748 748 749 + /* USB Type-C Alternate Modes */ 750 + 751 + #define TYPEC_ANY_MODE 0x7 752 + 753 + /** 754 + * struct typec_device_id - USB Type-C alternate mode identifiers 755 + * @svid: Standard or Vendor ID 756 + * @mode: Mode index 757 + */ 758 + struct typec_device_id { 759 + __u16 svid; 760 + __u8 mode; 761 + kernel_ulong_t driver_data; 762 + }; 763 + 749 764 #endif /* LINUX_MOD_DEVICETABLE_H */
+1
include/linux/usb/hcd.h
··· 322 322 int (*bus_suspend)(struct usb_hcd *); 323 323 int (*bus_resume)(struct usb_hcd *); 324 324 int (*start_port_reset)(struct usb_hcd *, unsigned port_num); 325 + unsigned long (*get_resuming_ports)(struct usb_hcd *); 325 326 326 327 /* force handover of high-speed port to full-speed companion */ 327 328 void (*relinquish_port)(struct usb_hcd *, int);
+1
include/linux/usb/pd.h
··· 15 15 #ifndef __LINUX_USB_PD_H 16 16 #define __LINUX_USB_PD_H 17 17 18 + #include <linux/kernel.h> 18 19 #include <linux/types.h> 19 20 #include <linux/usb/typec.h> 20 21
+2 -9
include/linux/usb/tcpm.h
··· 98 98 #define TCPC_MUX_DP_ENABLED BIT(1) /* DP enabled */ 99 99 #define TCPC_MUX_POLARITY_INVERTED BIT(2) /* Polarity inverted */ 100 100 101 - /* Mux modes, decoded to attributes */ 102 - enum tcpc_mux_mode { 103 - TYPEC_MUX_NONE = 0, /* Open switch */ 104 - TYPEC_MUX_USB = TCPC_MUX_USB_ENABLED, /* USB only */ 105 - TYPEC_MUX_DP = TCPC_MUX_DP_ENABLED, /* DP only */ 106 - TYPEC_MUX_DOCK = TCPC_MUX_USB_ENABLED | /* Both USB and DP */ 107 - TCPC_MUX_DP_ENABLED, 108 - }; 109 - 110 101 /** 111 102 * struct tcpc_dev - Port configuration and callback functions 112 103 * @config: Pointer to port configuration 104 + * @fwnode: Pointer to port fwnode 113 105 * @get_vbus: Called to read current VBUS state 114 106 * @get_current_limit: 115 107 * Optional; called by the tcpm core when configured as a snk ··· 130 138 */ 131 139 struct tcpc_dev { 132 140 const struct tcpc_config *config; 141 + struct fwnode_handle *fwnode; 133 142 134 143 int (*init)(struct tcpc_dev *dev); 135 144 int (*get_vbus)(struct tcpc_dev *dev);
+16 -39
include/linux/usb/typec.h
··· 5 5 6 6 #include <linux/types.h> 7 7 8 - /* XXX: Once we have a header for USB Power Delivery, this belongs there */ 9 - #define ALTMODE_MAX_MODES 6 10 - 11 8 /* USB Type-C Specification releases */ 12 9 #define USB_TYPEC_REV_1_0 0x100 /* 1.0 */ 13 10 #define USB_TYPEC_REV_1_1 0x110 /* 1.1 */ 14 11 #define USB_TYPEC_REV_1_2 0x120 /* 1.2 */ 15 12 16 - struct typec_altmode; 17 13 struct typec_partner; 18 14 struct typec_cable; 19 15 struct typec_plug; 20 16 struct typec_port; 21 17 22 18 struct fwnode_handle; 19 + struct device; 23 20 24 21 enum typec_port_type { 25 22 TYPEC_PORT_SRC, ··· 90 93 int typec_cable_set_identity(struct typec_cable *cable); 91 94 92 95 /* 93 - * struct typec_mode_desc - Individual Mode of an Alternate Mode 94 - * @index: Index of the Mode within the SVID 95 - * @vdo: VDO returned by Discover Modes USB PD command 96 - * @desc: Optional human readable description of the mode 97 - * @roles: Only for ports. DRP if the mode is available in both roles 98 - * 99 - * Description of a mode of an Alternate Mode which a connector, cable plug or 100 - * partner supports. Every mode will have it's own sysfs group. The details are 101 - * the VDO returned by discover modes command, description for the mode and 102 - * active flag telling has the mode being entered or not. 103 - */ 104 - struct typec_mode_desc { 105 - int index; 106 - u32 vdo; 107 - char *desc; 108 - /* Only used with ports */ 109 - enum typec_port_type roles; 110 - }; 111 - 112 - /* 113 96 * struct typec_altmode_desc - USB Type-C Alternate Mode Descriptor 114 97 * @svid: Standard or Vendor ID 115 - * @n_modes: Number of modes 116 - * @modes: Array of modes supported by the Alternate Mode 98 + * @mode: Index of the Mode 99 + * @vdo: VDO returned by Discover Modes USB PD command 100 + * @roles: Only for ports. DRP if the mode is available in both roles 117 101 * 118 - * Representation of an Alternate Mode that has SVID assigned by USB-IF. The 119 - * array of modes will list the modes of a particular SVID that are supported by 120 - * a connector, partner of a cable plug. 102 + * Description of an Alternate Mode which a connector, cable plug or partner 103 + * supports. 121 104 */ 122 105 struct typec_altmode_desc { 123 106 u16 svid; 124 - int n_modes; 125 - struct typec_mode_desc modes[ALTMODE_MAX_MODES]; 107 + u8 mode; 108 + u32 vdo; 109 + /* Only used with ports */ 110 + enum typec_port_data roles; 126 111 }; 127 112 128 113 struct typec_altmode ··· 120 141 121 142 struct typec_port *typec_altmode2port(struct typec_altmode *alt); 122 143 123 - void typec_altmode_update_active(struct typec_altmode *alt, int mode, 124 - bool active); 144 + void typec_altmode_update_active(struct typec_altmode *alt, bool active); 125 145 126 146 enum typec_plug_index { 127 147 TYPEC_PLUG_SOP_P, ··· 183 205 * @dr_set: Set Data Role 184 206 * @pr_set: Set Power Role 185 207 * @vconn_set: Set VCONN Role 186 - * @activate_mode: Enter/exit given Alternate Mode 187 208 * @port_type_set: Set port type 188 209 * 189 210 * Static capabilities of a single USB Type-C port. ··· 208 231 enum typec_role); 209 232 int (*vconn_set)(const struct typec_capability *, 210 233 enum typec_role); 211 - 212 - int (*activate_mode)(const struct typec_capability *, 213 - int mode, int activate); 214 234 int (*port_type_set)(const struct typec_capability *, 215 - enum typec_port_type); 216 - 235 + enum typec_port_type); 217 236 }; 218 237 219 238 /* Specific to try_role(). Indicates the user want's to clear the preference. */ ··· 238 265 239 266 int typec_set_orientation(struct typec_port *port, 240 267 enum typec_orientation orientation); 268 + enum typec_orientation typec_get_orientation(struct typec_port *port); 241 269 int typec_set_mode(struct typec_port *port, int mode); 242 270 271 + int typec_find_port_power_role(const char *name); 272 + int typec_find_power_role(const char *name); 273 + int typec_find_port_data_role(const char *name); 243 274 #endif /* __LINUX_USB_TYPEC_H */
+160
include/linux/usb/typec_altmode.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + 3 + #ifndef __USB_TYPEC_ALTMODE_H 4 + #define __USB_TYPEC_ALTMODE_H 5 + 6 + #include <linux/mod_devicetable.h> 7 + #include <linux/usb/typec.h> 8 + #include <linux/device.h> 9 + 10 + #define MODE_DISCOVERY_MAX 6 11 + 12 + struct typec_altmode_ops; 13 + 14 + /** 15 + * struct typec_altmode - USB Type-C alternate mode device 16 + * @dev: Driver model's view of this device 17 + * @svid: Standard or Vendor ID (SVID) of the alternate mode 18 + * @mode: Index of the Mode 19 + * @vdo: VDO returned by Discover Modes USB PD command 20 + * @active: Tells has the mode been entered or not 21 + * @desc: Optional human readable description of the mode 22 + * @ops: Operations vector from the driver 23 + */ 24 + struct typec_altmode { 25 + struct device dev; 26 + u16 svid; 27 + int mode; 28 + u32 vdo; 29 + unsigned int active:1; 30 + 31 + char *desc; 32 + const struct typec_altmode_ops *ops; 33 + }; 34 + 35 + #define to_typec_altmode(d) container_of(d, struct typec_altmode, dev) 36 + 37 + static inline void typec_altmode_set_drvdata(struct typec_altmode *altmode, 38 + void *data) 39 + { 40 + dev_set_drvdata(&altmode->dev, data); 41 + } 42 + 43 + static inline void *typec_altmode_get_drvdata(struct typec_altmode *altmode) 44 + { 45 + return dev_get_drvdata(&altmode->dev); 46 + } 47 + 48 + /** 49 + * struct typec_altmode_ops - Alternate mode specific operations vector 50 + * @enter: Operations to be executed with Enter Mode Command 51 + * @exit: Operations to be executed with Exit Mode Command 52 + * @attention: Callback for Attention Command 53 + * @vdm: Callback for SVID specific commands 54 + * @notify: Communication channel for platform and the alternate mode 55 + * @activate: User callback for Enter/Exit Mode 56 + */ 57 + struct typec_altmode_ops { 58 + int (*enter)(struct typec_altmode *altmode); 59 + int (*exit)(struct typec_altmode *altmode); 60 + void (*attention)(struct typec_altmode *altmode, u32 vdo); 61 + int (*vdm)(struct typec_altmode *altmode, const u32 hdr, 62 + const u32 *vdo, int cnt); 63 + int (*notify)(struct typec_altmode *altmode, unsigned long conf, 64 + void *data); 65 + int (*activate)(struct typec_altmode *altmode, int activate); 66 + }; 67 + 68 + int typec_altmode_enter(struct typec_altmode *altmode); 69 + int typec_altmode_exit(struct typec_altmode *altmode); 70 + void typec_altmode_attention(struct typec_altmode *altmode, u32 vdo); 71 + int typec_altmode_vdm(struct typec_altmode *altmode, 72 + const u32 header, const u32 *vdo, int count); 73 + int typec_altmode_notify(struct typec_altmode *altmode, unsigned long conf, 74 + void *data); 75 + const struct typec_altmode * 76 + typec_altmode_get_partner(struct typec_altmode *altmode); 77 + 78 + /* 79 + * These are the connector states (USB, Safe and Alt Mode) defined in USB Type-C 80 + * Specification. SVID specific connector states are expected to follow and 81 + * start from the value TYPEC_STATE_MODAL. 82 + */ 83 + enum { 84 + TYPEC_STATE_SAFE, /* USB Safe State */ 85 + TYPEC_STATE_USB, /* USB Operation */ 86 + TYPEC_STATE_MODAL, /* Alternate Modes */ 87 + }; 88 + 89 + /* 90 + * For the muxes there is no difference between Accessory Modes and Alternate 91 + * Modes, so the Accessory Modes are supplied with specific modal state values 92 + * here. Unlike with Alternate Modes, where the mux will be linked with the 93 + * alternate mode device, the mux for Accessory Modes will be linked with the 94 + * port device instead. 95 + * 96 + * Port drivers can use TYPEC_MODE_AUDIO and TYPEC_MODE_DEBUG as the mode 97 + * value for typec_set_mode() when accessory modes are supported. 98 + */ 99 + enum { 100 + TYPEC_MODE_AUDIO = TYPEC_STATE_MODAL, /* Audio Accessory */ 101 + TYPEC_MODE_DEBUG, /* Debug Accessory */ 102 + }; 103 + 104 + #define TYPEC_MODAL_STATE(_state_) ((_state_) + TYPEC_STATE_MODAL) 105 + 106 + struct typec_altmode *typec_altmode_get_plug(struct typec_altmode *altmode, 107 + enum typec_plug_index index); 108 + void typec_altmode_put_plug(struct typec_altmode *plug); 109 + 110 + struct typec_altmode *typec_match_altmode(struct typec_altmode **altmodes, 111 + size_t n, u16 svid, u8 mode); 112 + 113 + struct typec_altmode * 114 + typec_altmode_register_notifier(struct device *dev, u16 svid, u8 mode, 115 + struct notifier_block *nb); 116 + 117 + void typec_altmode_unregister_notifier(struct typec_altmode *adev, 118 + struct notifier_block *nb); 119 + 120 + /** 121 + * typec_altmode_get_orientation - Get cable plug orientation 122 + * altmode: Handle to the alternate mode 123 + */ 124 + static inline enum typec_orientation 125 + typec_altmode_get_orientation(struct typec_altmode *altmode) 126 + { 127 + return typec_get_orientation(typec_altmode2port(altmode)); 128 + } 129 + 130 + /** 131 + * struct typec_altmode_driver - USB Type-C alternate mode device driver 132 + * @id_table: Null terminated array of SVIDs 133 + * @probe: Callback for device binding 134 + * @remove: Callback for device unbinding 135 + * @driver: Device driver model driver 136 + * 137 + * These drivers will be bind to the partner alternate mode devices. They will 138 + * handle all SVID specific communication. 139 + */ 140 + struct typec_altmode_driver { 141 + const struct typec_device_id *id_table; 142 + int (*probe)(struct typec_altmode *altmode); 143 + void (*remove)(struct typec_altmode *altmode); 144 + struct device_driver driver; 145 + }; 146 + 147 + #define to_altmode_driver(d) container_of(d, struct typec_altmode_driver, \ 148 + driver) 149 + 150 + #define typec_altmode_register_driver(drv) \ 151 + __typec_altmode_register_driver(drv, THIS_MODULE) 152 + int __typec_altmode_register_driver(struct typec_altmode_driver *drv, 153 + struct module *module); 154 + void typec_altmode_unregister_driver(struct typec_altmode_driver *drv); 155 + 156 + #define module_typec_altmode_driver(__typec_altmode_driver) \ 157 + module_driver(__typec_altmode_driver, typec_altmode_register_driver, \ 158 + typec_altmode_unregister_driver) 159 + 160 + #endif /* __USB_TYPEC_ALTMODE_H */
+95
include/linux/usb/typec_dp.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + #ifndef __USB_TYPEC_DP_H 3 + #define __USB_TYPEC_DP_H 4 + 5 + #include <linux/usb/typec_altmode.h> 6 + 7 + #define USB_TYPEC_DP_SID 0xff01 8 + #define USB_TYPEC_DP_MODE 1 9 + 10 + /* 11 + * Connector states matching the pin assignments in DisplayPort Alt Mode 12 + * Specification. 13 + * 14 + * These values are meant primarily to be used by the mux drivers, but they are 15 + * also used as the "value" part in the alternate mode notification chain, so 16 + * receivers of those notifications will always see them. 17 + * 18 + * Note. DisplayPort USB Type-C Alt Mode Specification version 1.0b deprecated 19 + * pin assignments A, B and F, but they are still defined here for legacy 20 + * purposes. 21 + */ 22 + enum { 23 + TYPEC_DP_STATE_A = TYPEC_STATE_MODAL, /* Not supported after v1.0b */ 24 + TYPEC_DP_STATE_B, /* Not supported after v1.0b */ 25 + TYPEC_DP_STATE_C, 26 + TYPEC_DP_STATE_D, 27 + TYPEC_DP_STATE_E, 28 + TYPEC_DP_STATE_F, /* Not supported after v1.0b */ 29 + }; 30 + 31 + /* 32 + * struct typec_displayport_data - DisplayPort Alt Mode specific data 33 + * @status: Status Update command VDO content 34 + * @conf: Configure command VDO content 35 + * 36 + * This structure is delivered as the data part with the notifications. It 37 + * contains the VDOs from the two DisplayPort Type-C alternate mode specific 38 + * commands: Status Update and Configure. 39 + * 40 + * @status will show for example the status of the HPD signal. 41 + */ 42 + struct typec_displayport_data { 43 + u32 status; 44 + u32 conf; 45 + }; 46 + 47 + enum { 48 + DP_PIN_ASSIGN_A, /* Not supported after v1.0b */ 49 + DP_PIN_ASSIGN_B, /* Not supported after v1.0b */ 50 + DP_PIN_ASSIGN_C, 51 + DP_PIN_ASSIGN_D, 52 + DP_PIN_ASSIGN_E, 53 + DP_PIN_ASSIGN_F, /* Not supported after v1.0b */ 54 + }; 55 + 56 + /* DisplayPort alt mode specific commands */ 57 + #define DP_CMD_STATUS_UPDATE VDO_CMD_VENDOR(0) 58 + #define DP_CMD_CONFIGURE VDO_CMD_VENDOR(1) 59 + 60 + /* DisplayPort Capabilities VDO bits (returned with Discover Modes) */ 61 + #define DP_CAP_CAPABILITY(_cap_) ((_cap_) & 3) 62 + #define DP_CAP_UFP_D 1 63 + #define DP_CAP_DFP_D 2 64 + #define DP_CAP_DFP_D_AND_UFP_D 3 65 + #define DP_CAP_DP_SIGNALING BIT(2) /* Always set */ 66 + #define DP_CAP_GEN2 BIT(3) /* Reserved after v1.0b */ 67 + #define DP_CAP_RECEPTACLE BIT(6) 68 + #define DP_CAP_USB BIT(7) 69 + #define DP_CAP_DFP_D_PIN_ASSIGN(_cap_) (((_cap_) & GENMASK(15, 8)) >> 8) 70 + #define DP_CAP_UFP_D_PIN_ASSIGN(_cap_) (((_cap_) & GENMASK(23, 16)) >> 16) 71 + 72 + /* DisplayPort Status Update VDO bits */ 73 + #define DP_STATUS_CONNECTION(_status_) ((_status_) & 3) 74 + #define DP_STATUS_CON_DISABLED 0 75 + #define DP_STATUS_CON_DFP_D 1 76 + #define DP_STATUS_CON_UFP_D 2 77 + #define DP_STATUS_CON_BOTH 3 78 + #define DP_STATUS_POWER_LOW BIT(2) 79 + #define DP_STATUS_ENABLED BIT(3) 80 + #define DP_STATUS_PREFER_MULTI_FUNC BIT(4) 81 + #define DP_STATUS_SWITCH_TO_USB BIT(5) 82 + #define DP_STATUS_EXIT_DP_MODE BIT(6) 83 + #define DP_STATUS_HPD_STATE BIT(7) /* 0 = HPD_Low, 1 = HPD_High */ 84 + #define DP_STATUS_IRQ_HPD BIT(8) 85 + 86 + /* DisplayPort Configurations VDO bits */ 87 + #define DP_CONF_CURRENTLY(_conf_) ((_conf_) & 3) 88 + #define DP_CONF_UFP_U_AS_DFP_D BIT(0) 89 + #define DP_CONF_UFP_U_AS_UFP_D BIT(1) 90 + #define DP_CONF_SIGNALING_DP BIT(2) 91 + #define DP_CONF_SIGNALING_GEN_2 BIT(3) /* Reserved after v1.0b */ 92 + #define DP_CONF_PIN_ASSIGNEMENT_SHIFT 8 93 + #define DP_CONF_PIN_ASSIGNEMENT_MASK GENMASK(15, 8) 94 + 95 + #endif /* __USB_TYPEC_DP_H */
+1 -1
include/linux/usb/typec_mux.h
··· 47 47 int typec_switch_register(struct typec_switch *sw); 48 48 void typec_switch_unregister(struct typec_switch *sw); 49 49 50 - struct typec_mux *typec_mux_get(struct device *dev); 50 + struct typec_mux *typec_mux_get(struct device *dev, const char *name); 51 51 void typec_mux_put(struct typec_mux *mux); 52 52 int typec_mux_register(struct typec_mux *mux); 53 53 void typec_mux_unregister(struct typec_mux *mux);
+39
include/uapi/linux/usb/g_uvc.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0+ */ 2 + /* 3 + * g_uvc.h -- USB Video Class Gadget driver API 4 + * 5 + * Copyright (C) 2009-2010 Laurent Pinchart <laurent.pinchart@ideasonboard.com> 6 + */ 7 + 8 + #ifndef __LINUX_USB_G_UVC_H 9 + #define __LINUX_USB_G_UVC_H 10 + 11 + #include <linux/ioctl.h> 12 + #include <linux/types.h> 13 + #include <linux/usb/ch9.h> 14 + 15 + #define UVC_EVENT_FIRST (V4L2_EVENT_PRIVATE_START + 0) 16 + #define UVC_EVENT_CONNECT (V4L2_EVENT_PRIVATE_START + 0) 17 + #define UVC_EVENT_DISCONNECT (V4L2_EVENT_PRIVATE_START + 1) 18 + #define UVC_EVENT_STREAMON (V4L2_EVENT_PRIVATE_START + 2) 19 + #define UVC_EVENT_STREAMOFF (V4L2_EVENT_PRIVATE_START + 3) 20 + #define UVC_EVENT_SETUP (V4L2_EVENT_PRIVATE_START + 4) 21 + #define UVC_EVENT_DATA (V4L2_EVENT_PRIVATE_START + 5) 22 + #define UVC_EVENT_LAST (V4L2_EVENT_PRIVATE_START + 5) 23 + 24 + struct uvc_request_data { 25 + __s32 length; 26 + __u8 data[60]; 27 + }; 28 + 29 + struct uvc_event { 30 + union { 31 + enum usb_device_speed speed; 32 + struct usb_ctrlrequest req; 33 + struct uvc_request_data data; 34 + }; 35 + }; 36 + 37 + #define UVCIOC_SEND_RESPONSE _IOW('U', 1, struct uvc_request_data) 38 + 39 + #endif /* __LINUX_USB_G_UVC_H */
+13
include/uapi/linux/usb/tmc.h
··· 16 16 #ifndef __LINUX_USB_TMC_H 17 17 #define __LINUX_USB_TMC_H 18 18 19 + #include <linux/types.h> /* __u8 etc */ 20 + 19 21 /* USB TMC status values */ 20 22 #define USBTMC_STATUS_SUCCESS 0x01 21 23 #define USBTMC_STATUS_PENDING 0x02 ··· 40 38 #define USBTMC488_REQUEST_GOTO_LOCAL 161 41 39 #define USBTMC488_REQUEST_LOCAL_LOCKOUT 162 42 40 41 + struct usbtmc_termchar { 42 + __u8 term_char; 43 + __u8 term_char_enabled; 44 + } __attribute__ ((packed)); 45 + 43 46 /* Request values for USBTMC driver's ioctl entry point */ 44 47 #define USBTMC_IOC_NR 91 45 48 #define USBTMC_IOCTL_INDICATOR_PULSE _IO(USBTMC_IOC_NR, 1) ··· 53 46 #define USBTMC_IOCTL_ABORT_BULK_IN _IO(USBTMC_IOC_NR, 4) 54 47 #define USBTMC_IOCTL_CLEAR_OUT_HALT _IO(USBTMC_IOC_NR, 6) 55 48 #define USBTMC_IOCTL_CLEAR_IN_HALT _IO(USBTMC_IOC_NR, 7) 49 + #define USBTMC_IOCTL_GET_TIMEOUT _IOR(USBTMC_IOC_NR, 9, __u32) 50 + #define USBTMC_IOCTL_SET_TIMEOUT _IOW(USBTMC_IOC_NR, 10, __u32) 51 + #define USBTMC_IOCTL_EOM_ENABLE _IOW(USBTMC_IOC_NR, 11, __u8) 52 + #define USBTMC_IOCTL_CONFIG_TERMCHAR _IOW(USBTMC_IOC_NR, 12, struct usbtmc_termchar) 53 + 56 54 #define USBTMC488_IOCTL_GET_CAPS _IOR(USBTMC_IOC_NR, 17, unsigned char) 57 55 #define USBTMC488_IOCTL_READ_STB _IOR(USBTMC_IOC_NR, 18, unsigned char) 58 56 #define USBTMC488_IOCTL_REN_CONTROL _IOW(USBTMC_IOC_NR, 19, unsigned char) 59 57 #define USBTMC488_IOCTL_GOTO_LOCAL _IO(USBTMC_IOC_NR, 20) 60 58 #define USBTMC488_IOCTL_LOCAL_LOCKOUT _IO(USBTMC_IOC_NR, 21) 59 + #define USBTMC488_IOCTL_TRIGGER _IO(USBTMC_IOC_NR, 22) 61 60 62 61 /* Driver encoded usb488 capabilities */ 63 62 #define USBTMC488_CAPABILITY_TRIGGER 1
+4
scripts/mod/devicetable-offsets.c
··· 221 221 DEVID_FIELD(tb_service_id, protocol_version); 222 222 DEVID_FIELD(tb_service_id, protocol_revision); 223 223 224 + DEVID(typec_device_id); 225 + DEVID_FIELD(typec_device_id, svid); 226 + DEVID_FIELD(typec_device_id, mode); 227 + 224 228 return 0; 225 229 }
+13
scripts/mod/file2alias.c
··· 1352 1352 } 1353 1353 ADD_TO_DEVTABLE("tbsvc", tb_service_id, do_tbsvc_entry); 1354 1354 1355 + /* Looks like: typec:idNmN */ 1356 + static int do_typec_entry(const char *filename, void *symval, char *alias) 1357 + { 1358 + DEF_FIELD(symval, typec_device_id, svid); 1359 + DEF_FIELD(symval, typec_device_id, mode); 1360 + 1361 + sprintf(alias, "typec:id%04X", svid); 1362 + ADD(alias, "m", mode != TYPEC_ANY_MODE, mode); 1363 + 1364 + return 1; 1365 + } 1366 + ADD_TO_DEVTABLE("typec", typec_device_id, do_typec_entry); 1367 + 1355 1368 /* Does namelen bytes of name exactly match the symbol? */ 1356 1369 static bool sym_is(const char *name, unsigned namelen, const char *symbol) 1357 1370 {
-2
tools/testing/selftests/drivers/usb/usbip/usbip_test.sh
··· 46 46 fi 47 47 48 48 if /sbin/modprobe -q usbip_host; then 49 - /sbin/modprobe -q -r test_bitmap 50 49 echo "usbip_test: module usbip_host is loaded [OK]" 51 50 else 52 51 echo "usbip_test: module usbip_host failed to load [FAIL]" ··· 55 56 56 57 echo "Load vhci_hcd module" 57 58 if /sbin/modprobe -q vhci_hcd; then 58 - /sbin/modprobe -q -r test_bitmap 59 59 echo "usbip_test: module vhci_hcd is loaded [OK]" 60 60 else 61 61 echo "usbip_test: module vhci_hcd failed to load [FAIL]"