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

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

Pull usb/phy/extcon updates from Greg KH:
"Here is the big USB, and PHY, and extcon, patchsets for 4.9-rc1.

Full details are in the shortlog, but generally a lot of new hardware
support, usb gadget updates, and Wolfram's great cleanup of USB error
message handling, making the kernel image a tad bit smaller.

All of this has been in linux-next with no reported issues"

* tag 'usb-4.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb: (343 commits)
Revert "usbtmc: convert to devm_kzalloc"
USB: serial: cp210x: Add ID for a Juniper console
usb: Kconfig: using select for USB_COMMON dependency
bluetooth: bcm203x: don't print error when allocating urb fails
mmc: host: vub300: don't print error when allocating urb fails
usb: hub: change CLEAR_FEATURE to SET_FEATURE
usb: core: Introduce a USB port LED trigger
USB: bcma: drop Northstar PHY 2.0 initialization code
usb: core: hcd: add missing header dependencies
usb: musb: da8xx: fix error handling message in probe
usb: musb: Fix session based PM for first invalid VBUS
usb: musb: Fix PM runtime for disconnect after unconfigure
musb: Export musb_root_disconnect for use in modules
usb: misc: legousbtower: Fix NULL pointer deference
cdc-acm: hardening against malicious devices
Revert "usb: gadget: NCM: Protect dev->port_usb using dev->lock"
include: extcon: Fix compilation error caused because of incomplete merge
MAINTAINERS: add tree entry for USB Serial
phy-twl4030-usb: initialize charging-related stuff via pm_runtime
phy-twl4030-usb: better handle musb_mailbox() failure
...

+7222 -2147
+12
Documentation/ABI/testing/sysfs-class-led-trigger-usbport
··· 1 + What: /sys/class/leds/<led>/ports/<port> 2 + Date: September 2016 3 + KernelVersion: 4.9 4 + Contact: linux-leds@vger.kernel.org 5 + linux-usb@vger.kernel.org 6 + Description: 7 + Every dir entry represents a single USB port that can be 8 + selected for the USB port trigger. Selecting ports makes trigger 9 + observing them for any connected devices and lighting on LED if 10 + there are any. 11 + Echoing "1" value selects USB port. Echoing "0" unselects it. 12 + Current state can be also read.
+41
Documentation/devicetree/bindings/extcon/qcom,pm8941-misc.txt
··· 1 + Qualcomm's PM8941 USB ID Extcon device 2 + 3 + Some Qualcomm PMICs have a "misc" module that can be used to detect when 4 + the USB ID pin has been pulled low or high. 5 + 6 + PROPERTIES 7 + 8 + - compatible: 9 + Usage: required 10 + Value type: <string> 11 + Definition: Should contain "qcom,pm8941-misc"; 12 + 13 + - reg: 14 + Usage: required 15 + Value type: <u32> 16 + Definition: Should contain the offset to the misc address space 17 + 18 + - interrupts: 19 + Usage: required 20 + Value type: <prop-encoded-array> 21 + Definition: Should contain the usb id interrupt 22 + 23 + - interrupt-names: 24 + Usage: required 25 + Value type: <stringlist> 26 + Definition: Should contain the string "usb_id" for the usb id interrupt 27 + 28 + Example: 29 + 30 + pmic { 31 + usb_id: misc@900 { 32 + compatible = "qcom,pm8941-misc"; 33 + reg = <0x900>; 34 + interrupts = <0x0 0x9 0 IRQ_TYPE_EDGE_BOTH>; 35 + interrupt-names = "usb_id"; 36 + }; 37 + } 38 + 39 + usb-controller { 40 + extcon = <&usb_id>; 41 + };
+23
Documentation/devicetree/bindings/phy/bcm-ns-usb3-phy.txt
··· 1 + Driver for Broadcom Northstar USB 3.0 PHY 2 + 3 + Required properties: 4 + 5 + - compatible: one of: "brcm,ns-ax-usb3-phy", "brcm,ns-bx-usb3-phy". 6 + - reg: register mappings for DMP (Device Management Plugin) and ChipCommon B 7 + MMI. 8 + - reg-names: "dmp" and "ccb-mii" 9 + 10 + Initialization of USB 3.0 PHY depends on Northstar version. There are currently 11 + three known series: Ax, Bx and Cx. 12 + Known A0: BCM4707 rev 0 13 + Known B0: BCM4707 rev 4, BCM53573 rev 2 14 + Known B1: BCM4707 rev 6 15 + Known C0: BCM47094 rev 0 16 + 17 + Example: 18 + usb3-phy { 19 + compatible = "brcm,ns-ax-usb3-phy"; 20 + reg = <0x18105000 0x1000>, <0x18003000 0x1000>; 21 + reg-names = "dmp", "ccb-mii"; 22 + #phy-cells = <0>; 23 + };
+10
Documentation/devicetree/bindings/phy/mxs-usb-phy.txt
··· 12 12 - interrupts: Should contain phy interrupt 13 13 - fsl,anatop: phandle for anatop register, it is only for imx6 SoC series 14 14 15 + Optional properties: 16 + - fsl,tx-cal-45-dn-ohms: Integer [30-55]. Resistance (in ohms) of switchable 17 + high-speed trimming resistor connected in parallel with the 45 ohm resistor 18 + that terminates the DN output signal. Default: 45 19 + - fsl,tx-cal-45-dp-ohms: Integer [30-55]. Resistance (in ohms) of switchable 20 + high-speed trimming resistor connected in parallel with the 45 ohm resistor 21 + that terminates the DP output signal. Default: 45 22 + - fsl,tx-d-cal: Integer [79-119]. Current trimming value (as a percentage) of 23 + the 17.78mA TX reference current. Default: 100 24 + 15 25 Example: 16 26 usbphy1: usbphy@020c9000 { 17 27 compatible = "fsl,imx6q-usbphy", "fsl,imx23-usbphy";
+64
Documentation/devicetree/bindings/phy/phy-rockchip-inno-usb2.txt
··· 1 + ROCKCHIP USB2.0 PHY WITH INNO IP BLOCK 2 + 3 + Required properties (phy (parent) node): 4 + - compatible : should be one of the listed compatibles: 5 + * "rockchip,rk3366-usb2phy" 6 + * "rockchip,rk3399-usb2phy" 7 + - reg : the address offset of grf for usb-phy configuration. 8 + - #clock-cells : should be 0. 9 + - clock-output-names : specify the 480m output clock name. 10 + 11 + Optional properties: 12 + - clocks : phandle + phy specifier pair, for the input clock of phy. 13 + - clock-names : input clock name of phy, must be "phyclk". 14 + 15 + Required nodes : a sub-node is required for each port the phy provides. 16 + The sub-node name is used to identify host or otg port, 17 + and shall be the following entries: 18 + * "otg-port" : the name of otg port. 19 + * "host-port" : the name of host port. 20 + 21 + Required properties (port (child) node): 22 + - #phy-cells : must be 0. See ./phy-bindings.txt for details. 23 + - interrupts : specify an interrupt for each entry in interrupt-names. 24 + - interrupt-names : a list which shall be the following entries: 25 + * "otg-id" : for the otg id interrupt. 26 + * "otg-bvalid" : for the otg vbus interrupt. 27 + * "linestate" : for the host/otg linestate interrupt. 28 + 29 + Optional properties: 30 + - phy-supply : phandle to a regulator that provides power to VBUS. 31 + See ./phy-bindings.txt for details. 32 + 33 + Example: 34 + 35 + grf: syscon@ff770000 { 36 + compatible = "rockchip,rk3366-grf", "syscon", "simple-mfd"; 37 + #address-cells = <1>; 38 + #size-cells = <1>; 39 + 40 + ... 41 + 42 + u2phy: usb2-phy@700 { 43 + compatible = "rockchip,rk3366-usb2phy"; 44 + reg = <0x700 0x2c>; 45 + #clock-cells = <0>; 46 + clock-output-names = "sclk_otgphy0_480m"; 47 + 48 + u2phy_otg: otg-port { 49 + #phy-cells = <0>; 50 + interrupts = <GIC_SPI 93 IRQ_TYPE_LEVEL_HIGH>, 51 + <GIC_SPI 94 IRQ_TYPE_LEVEL_HIGH>, 52 + <GIC_SPI 95 IRQ_TYPE_LEVEL_HIGH>; 53 + interrupt-names = "otg-id", "otg-bvalid", "linestate"; 54 + status = "okay"; 55 + }; 56 + 57 + u2phy_host: host-port { 58 + #phy-cells = <0>; 59 + interrupts = <GIC_SPI 96 IRQ_TYPE_LEVEL_HIGH>; 60 + interrupt-names = "linestate"; 61 + status = "okay"; 62 + }; 63 + }; 64 + };
+101
Documentation/devicetree/bindings/phy/phy-rockchip-typec.txt
··· 1 + * ROCKCHIP type-c PHY 2 + --------------------- 3 + 4 + Required properties: 5 + - compatible : must be "rockchip,rk3399-typec-phy" 6 + - reg: Address and length of the usb phy control register set 7 + - rockchip,grf : phandle to the syscon managing the "general 8 + register files" 9 + - clocks : phandle + clock specifier for the phy clocks 10 + - clock-names : string, clock name, must be "tcpdcore", "tcpdphy-ref"; 11 + - assigned-clocks: main clock, should be <&cru SCLK_UPHY0_TCPDCORE> or 12 + <&cru SCLK_UPHY1_TCPDCORE>; 13 + - assigned-clock-rates : the phy core clk frequency, shall be: 50000000 14 + - resets : a list of phandle + reset specifier pairs 15 + - reset-names : string reset name, must be: 16 + "uphy", "uphy-pipe", "uphy-tcphy" 17 + - extcon : extcon specifier for the Power Delivery 18 + 19 + Note, there are 2 type-c phys for RK3399, and they are almost identical, except 20 + these registers(description below), every register node contains 3 sections: 21 + offset, enable bit, write mask bit. 22 + - rockchip,typec-conn-dir : the register of type-c connector direction, 23 + for type-c phy0, it must be <0xe580 0 16>; 24 + for type-c phy1, it must be <0xe58c 0 16>; 25 + - rockchip,usb3tousb2-en : the register of type-c force usb3 to usb2 enable 26 + control. 27 + for type-c phy0, it must be <0xe580 3 19>; 28 + for type-c phy1, it must be <0xe58c 3 19>; 29 + - rockchip,external-psm : the register of type-c phy external psm clock 30 + selection. 31 + for type-c phy0, it must be <0xe588 14 30>; 32 + for type-c phy1, it must be <0xe594 14 30>; 33 + - rockchip,pipe-status : the register of type-c phy pipe status. 34 + for type-c phy0, it must be <0xe5c0 0 0>; 35 + for type-c phy1, it must be <0xe5c0 16 16>; 36 + 37 + Required nodes : a sub-node is required for each port the phy provides. 38 + The sub-node name is used to identify dp or usb3 port, 39 + and shall be the following entries: 40 + * "dp-port" : the name of DP port. 41 + * "usb3-port" : the name of USB3 port. 42 + 43 + Required properties (port (child) node): 44 + - #phy-cells : must be 0, See ./phy-bindings.txt for details. 45 + 46 + Example: 47 + tcphy0: phy@ff7c0000 { 48 + compatible = "rockchip,rk3399-typec-phy"; 49 + reg = <0x0 0xff7c0000 0x0 0x40000>; 50 + rockchip,grf = <&grf>; 51 + extcon = <&fusb0>; 52 + clocks = <&cru SCLK_UPHY0_TCPDCORE>, 53 + <&cru SCLK_UPHY0_TCPDPHY_REF>; 54 + clock-names = "tcpdcore", "tcpdphy-ref"; 55 + assigned-clocks = <&cru SCLK_UPHY0_TCPDCORE>; 56 + assigned-clock-rates = <50000000>; 57 + resets = <&cru SRST_UPHY0>, 58 + <&cru SRST_UPHY0_PIPE_L00>, 59 + <&cru SRST_P_UPHY0_TCPHY>; 60 + reset-names = "uphy", "uphy-pipe", "uphy-tcphy"; 61 + rockchip,typec-conn-dir = <0xe580 0 16>; 62 + rockchip,usb3tousb2-en = <0xe580 3 19>; 63 + rockchip,external-psm = <0xe588 14 30>; 64 + rockchip,pipe-status = <0xe5c0 0 0>; 65 + 66 + tcphy0_dp: dp-port { 67 + #phy-cells = <0>; 68 + }; 69 + 70 + tcphy0_usb3: usb3-port { 71 + #phy-cells = <0>; 72 + }; 73 + }; 74 + 75 + tcphy1: phy@ff800000 { 76 + compatible = "rockchip,rk3399-typec-phy"; 77 + reg = <0x0 0xff800000 0x0 0x40000>; 78 + rockchip,grf = <&grf>; 79 + extcon = <&fusb1>; 80 + clocks = <&cru SCLK_UPHY1_TCPDCORE>, 81 + <&cru SCLK_UPHY1_TCPDPHY_REF>; 82 + clock-names = "tcpdcore", "tcpdphy-ref"; 83 + assigned-clocks = <&cru SCLK_UPHY1_TCPDCORE>; 84 + assigned-clock-rates = <50000000>; 85 + resets = <&cru SRST_UPHY1>, 86 + <&cru SRST_UPHY1_PIPE_L00>, 87 + <&cru SRST_P_UPHY1_TCPHY>; 88 + reset-names = "uphy", "uphy-pipe", "uphy-tcphy"; 89 + rockchip,typec-conn-dir = <0xe58c 0 16>; 90 + rockchip,usb3tousb2-en = <0xe58c 3 19>; 91 + rockchip,external-psm = <0xe594 14 30>; 92 + rockchip,pipe-status = <0xe5c0 16 16>; 93 + 94 + tcphy1_dp: dp-port { 95 + #phy-cells = <0>; 96 + }; 97 + 98 + tcphy1_usb3: usb3-port { 99 + #phy-cells = <0>; 100 + }; 101 + };
+4 -2
Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt
··· 6 6 Required properties: 7 7 - compatible: "renesas,usb2-phy-r8a7795" if the device is a part of an R8A7795 8 8 SoC. 9 + "renesas,usb2-phy-r8a7796" if the device is a part of an R8A7796 10 + SoC. 9 11 "renesas,rcar-gen3-usb2-phy" for a generic R-Car Gen3 compatible device. 10 12 11 13 When compatible with the generic version, nodes must list the ··· 32 30 compatible = "renesas,usb2-phy-r8a7795", "renesas,rcar-gen3-usb2-phy"; 33 31 reg = <0 0xee080200 0 0x700>; 34 32 interrupts = <GIC_SPI 108 IRQ_TYPE_LEVEL_HIGH>; 35 - clocks = <&mstp7_clks R8A7795_CLK_EHCI0>; 33 + clocks = <&cpg CPG_MOD 703>; 36 34 }; 37 35 38 36 usb-phy@ee0a0200 { 39 37 compatible = "renesas,usb2-phy-r8a7795", "renesas,rcar-gen3-usb2-phy"; 40 38 reg = <0 0xee0a0200 0 0x700>; 41 - clocks = <&mstp7_clks R8A7795_CLK_EHCI0>; 39 + clocks = <&cpg CPG_MOD 702>; 42 40 };
+31
Documentation/devicetree/bindings/phy/rockchip-pcie-phy.txt
··· 1 + Rockchip PCIE PHY 2 + ----------------------- 3 + 4 + Required properties: 5 + - compatible: rockchip,rk3399-pcie-phy 6 + - #phy-cells: must be 0 7 + - clocks: Must contain an entry in clock-names. 8 + See ../clocks/clock-bindings.txt for details. 9 + - clock-names: Must be "refclk" 10 + - resets: Must contain an entry in reset-names. 11 + See ../reset/reset.txt for details. 12 + - reset-names: Must be "phy" 13 + 14 + Example: 15 + 16 + grf: syscon@ff770000 { 17 + compatible = "rockchip,rk3399-grf", "syscon", "simple-mfd"; 18 + #address-cells = <1>; 19 + #size-cells = <1>; 20 + 21 + ... 22 + 23 + pcie_phy: pcie-phy { 24 + compatible = "rockchip,rk3399-pcie-phy"; 25 + #phy-cells = <0>; 26 + clocks = <&cru SCLK_PCIEPHY_REF>; 27 + clock-names = "refclk"; 28 + resets = <&cru SRST_PCIEPHY>; 29 + reset-names = "phy"; 30 + }; 31 + };
+3
Documentation/devicetree/bindings/phy/rockchip-usb-phy.txt
··· 27 27 - clocks : phandle + clock specifier for the phy clocks 28 28 - clock-names: string, clock name, must be "phyclk" 29 29 - #clock-cells: for users of the phy-pll, should be 0 30 + - reset-names: Only allow the following entries: 31 + - phy-reset 32 + - resets: Must contain an entry for each entry in reset-names. 30 33 31 34 Example: 32 35
+1
Documentation/devicetree/bindings/phy/sun4i-usb-phy.txt
··· 10 10 * allwinner,sun8i-a23-usb-phy 11 11 * allwinner,sun8i-a33-usb-phy 12 12 * allwinner,sun8i-h3-usb-phy 13 + * allwinner,sun50i-a64-usb-phy 13 14 - reg : a list of offset + length pairs 14 15 - reg-names : 15 16 * "phy_ctrl"
+2
Documentation/devicetree/bindings/phy/ti-phy.txt
··· 31 31 32 32 Required properties: 33 33 - compatible: Should be "ti,omap-usb2" 34 + Should be "ti,dra7x-usb2" for the 1st instance of USB2 PHY on 35 + DRA7x 34 36 Should be "ti,dra7x-usb2-phy2" for the 2nd instance of USB2 PHY 35 37 in DRA7x 36 38 - reg : Address and length of the register set for the device.
+2
Documentation/devicetree/bindings/usb/ci-hdrc-usb2.txt
··· 81 81 - fsl,usbmisc: phandler of non-core register device, with one 82 82 argument that indicate usb controller index 83 83 - disable-over-current: disable over current detect 84 + - over-current-active-high: over current signal polarity is high active, 85 + typically over current signal polarity is low active. 84 86 - external-vbus-divider: enables off-chip resistor divider for Vbus 85 87 86 88 Example:
+4 -1
Documentation/devicetree/bindings/usb/dwc2.txt
··· 26 26 - g-use-dma: enable dma usage in gadget driver. 27 27 - g-rx-fifo-size: size of rx fifo size in gadget mode. 28 28 - g-np-tx-fifo-size: size of non-periodic tx fifo size in gadget mode. 29 - - g-tx-fifo-size: size of periodic tx fifo per endpoint (except ep0) in gadget mode. 29 + 30 + Deprecated properties: 31 + - g-tx-fifo-size: size of periodic tx fifo per endpoint (except ep0) 32 + in gadget mode. 30 33 31 34 Example: 32 35
+28
Documentation/devicetree/bindings/usb/dwc3-cavium.txt
··· 1 + Cavium SuperSpeed DWC3 USB SoC controller 2 + 3 + Required properties: 4 + - compatible: Should contain "cavium,octeon-7130-usb-uctl" 5 + 6 + Required child node: 7 + A child node must exist to represent the core DWC3 IP block. The name of 8 + the node is not important. The content of the node is defined in dwc3.txt. 9 + 10 + Example device node: 11 + 12 + uctl@1180069000000 { 13 + compatible = "cavium,octeon-7130-usb-uctl"; 14 + reg = <0x00011800 0x69000000 0x00000000 0x00000100>; 15 + ranges; 16 + #address-cells = <0x00000002>; 17 + #size-cells = <0x00000002>; 18 + refclk-frequency = <0x05f5e100>; 19 + refclk-type-ss = "dlmc_ref_clk0"; 20 + refclk-type-hs = "dlmc_ref_clk0"; 21 + power = <0x00000002 0x00000002 0x00000001>; 22 + xhci@1690000000000 { 23 + compatible = "cavium,octeon-7130-xhci", "synopsys,dwc3"; 24 + reg = <0x00016900 0x00000000 0x00000010 0x00000000>; 25 + interrupt-parent = <0x00000010>; 26 + interrupts = <0x00000009 0x00000004>; 27 + }; 28 + };
+7 -1
Documentation/devicetree/bindings/usb/dwc3.txt
··· 13 13 in the array is expected to be a handle to the USB2/HS PHY and 14 14 the second element is expected to be a handle to the USB3/SS PHY 15 15 - phys: from the *Generic PHY* bindings 16 - - phy-names: from the *Generic PHY* bindings 16 + - phy-names: from the *Generic PHY* bindings; supported names are "usb2-phy" 17 + or "usb3-phy". 17 18 - snps,usb3_lpm_capable: determines if platform is USB3 LPM capable 18 19 - snps,disable_scramble_quirk: true when SW should disable data scrambling. 19 20 Only really useful for FPGA builds. ··· 40 39 disabling the suspend signal to the PHY. 41 40 - snps,dis_rxdet_inp3_quirk: when set core will disable receiver detection 42 41 in PHY P3 power state. 42 + - snps,dis-u2-freeclk-exists-quirk: when set, clear the u2_freeclk_exists 43 + in GUSB2PHYCFG, specify that USB2 PHY doesn't provide 44 + a free-running PHY clock. 45 + - snps,dis-del-phy-power-chg-quirk: when set core will change PHY power 46 + from P0 to P1/P2/P3 without delay. 43 47 - snps,is-utmi-l1-suspend: true when DWC3 asserts output signal 44 48 utmi_l1_suspend_n, false when asserts utmi_sleep_n 45 49 - snps,hird-threshold: HIRD threshold
+6
Documentation/devicetree/bindings/usb/generic.txt
··· 11 11 "peripheral" and "otg". In case this attribute isn't 12 12 passed via DT, USB DRD controllers should default to 13 13 OTG. 14 + - phy_type: tells USB controllers that we want to configure the core to support 15 + a UTMI+ PHY with an 8- or 16-bit interface if UTMI+ is 16 + selected. Valid arguments are "utmi" and "utmi_wide". 17 + In case this isn't passed via DT, USB controllers should 18 + default to HW capability. 14 19 - otg-rev: tells usb driver the release number of the OTG and EH supplement 15 20 with which the device and its descriptors are compliant, 16 21 in binary-coded decimal (i.e. 2.0 is 0200H). This ··· 39 34 usb-phy = <&usb2_phy>, <&usb3,phy>; 40 35 maximum-speed = "super-speed"; 41 36 dr_mode = "otg"; 37 + phy_type = "utmi_wide"; 42 38 otg-rev = <0x0200>; 43 39 adp-disable; 44 40 };
+1
Documentation/devicetree/bindings/usb/renesas_usbhs.txt
··· 9 9 - "renesas,usbhs-r8a7793" for r8a7793 (R-Car M2-N) compatible device 10 10 - "renesas,usbhs-r8a7794" for r8a7794 (R-Car E2) compatible device 11 11 - "renesas,usbhs-r8a7795" for r8a7795 (R-Car H3) compatible device 12 + - "renesas,usbhs-r8a7796" for r8a7796 (R-Car M3-W) compatible device 12 13 - "renesas,rcar-gen2-usbhs" for R-Car Gen2 compatible device 13 14 - "renesas,rcar-gen3-usbhs" for R-Car Gen3 compatible device 14 15
+59
Documentation/devicetree/bindings/usb/rockchip,dwc3.txt
··· 1 + Rockchip SuperSpeed DWC3 USB SoC controller 2 + 3 + Required properties: 4 + - compatible: should contain "rockchip,rk3399-dwc3" for rk3399 SoC 5 + - clocks: A list of phandle + clock-specifier pairs for the 6 + clocks listed in clock-names 7 + - clock-names: Should contain the following: 8 + "ref_clk" Controller reference clk, have to be 24 MHz 9 + "suspend_clk" Controller suspend clk, have to be 24 MHz or 32 KHz 10 + "bus_clk" Master/Core clock, have to be >= 62.5 MHz for SS 11 + operation and >= 30MHz for HS operation 12 + "grf_clk" Controller grf clk 13 + 14 + Required child node: 15 + A child node must exist to represent the core DWC3 IP block. The name of 16 + the node is not important. The content of the node is defined in dwc3.txt. 17 + 18 + Phy documentation is provided in the following places: 19 + Documentation/devicetree/bindings/phy/rockchip,dwc3-usb-phy.txt 20 + 21 + Example device nodes: 22 + 23 + usbdrd3_0: usb@fe800000 { 24 + compatible = "rockchip,rk3399-dwc3"; 25 + clocks = <&cru SCLK_USB3OTG0_REF>, <&cru SCLK_USB3OTG0_SUSPEND>, 26 + <&cru ACLK_USB3OTG0>, <&cru ACLK_USB3_GRF>; 27 + clock-names = "ref_clk", "suspend_clk", 28 + "bus_clk", "grf_clk"; 29 + #address-cells = <2>; 30 + #size-cells = <2>; 31 + ranges; 32 + status = "disabled"; 33 + usbdrd_dwc3_0: dwc3@fe800000 { 34 + compatible = "snps,dwc3"; 35 + reg = <0x0 0xfe800000 0x0 0x100000>; 36 + interrupts = <GIC_SPI 105 IRQ_TYPE_LEVEL_HIGH>; 37 + dr_mode = "otg"; 38 + status = "disabled"; 39 + }; 40 + }; 41 + 42 + usbdrd3_1: usb@fe900000 { 43 + compatible = "rockchip,rk3399-dwc3"; 44 + clocks = <&cru SCLK_USB3OTG1_REF>, <&cru SCLK_USB3OTG1_SUSPEND>, 45 + <&cru ACLK_USB3OTG1>, <&cru ACLK_USB3_GRF>; 46 + clock-names = "ref_clk", "suspend_clk", 47 + "bus_clk", "grf_clk"; 48 + #address-cells = <2>; 49 + #size-cells = <2>; 50 + ranges; 51 + status = "disabled"; 52 + usbdrd_dwc3_1: dwc3@fe900000 { 53 + compatible = "snps,dwc3"; 54 + reg = <0x0 0xfe900000 0x0 0x100000>; 55 + interrupts = <GIC_SPI 110 IRQ_TYPE_LEVEL_HIGH>; 56 + dr_mode = "otg"; 57 + status = "disabled"; 58 + }; 59 + };
+19
Documentation/devicetree/bindings/usb/usb4604.txt
··· 1 + SMSC USB4604 High-Speed Hub Controller 2 + 3 + Required properties: 4 + - compatible: Should be "smsc,usb4604" 5 + 6 + Optional properties: 7 + - reg: Specifies the i2c slave address, it is required and should be 0x2d 8 + if I2C is used. 9 + - reset-gpios: Should specify GPIO for reset. 10 + - initial-mode: Should specify initial mode. 11 + (1 for HUB mode, 2 for STANDBY mode) 12 + 13 + Examples: 14 + usb-hub@2d { 15 + compatible = "smsc,usb4604"; 16 + reg = <0x2d>; 17 + reset-gpios = <&gpx3 5 1>; 18 + initial-mode = <1>; 19 + };
+1
Documentation/devicetree/bindings/usb/usbmisc-imx.txt
··· 6 6 "fsl,imx6q-usbmisc" for imx6q 7 7 "fsl,vf610-usbmisc" for Vybrid vf610 8 8 "fsl,imx6sx-usbmisc" for imx6sx 9 + "fsl,imx7d-usbmisc" for imx7d 9 10 - reg: Should contain registers location and length 10 11 11 12 Examples:
+2
Documentation/kernel-parameters.txt
··· 4248 4248 u = IGNORE_UAS (don't bind to the uas driver); 4249 4249 w = NO_WP_DETECT (don't test whether the 4250 4250 medium is write-protected). 4251 + y = ALWAYS_SYNC (issue a SYNCHRONIZE_CACHE 4252 + even if the device claims no cache) 4251 4253 Example: quirks=0419:aaf5:rl,0421:0433:rc 4252 4254 4253 4255 user_debug= [KNL,ARM]
+41
Documentation/leds/ledtrig-usbport.txt
··· 1 + USB port LED trigger 2 + ==================== 3 + 4 + This LED trigger can be used for signalling to the user a presence of USB device 5 + in a given port. It simply turns on LED when device appears and turns it off 6 + when it disappears. 7 + 8 + It requires selecting USB ports that should be observed. All available ones are 9 + listed as separated entries in a "ports" subdirectory. Selecting is handled by 10 + echoing "1" to a chosen port. 11 + 12 + Please note that this trigger allows selecting multiple USB ports for a single 13 + LED. This can be useful in two cases: 14 + 15 + 1) Device with single USB LED and few physical ports 16 + 17 + In such a case LED will be turned on as long as there is at least one connected 18 + USB device. 19 + 20 + 2) Device with a physical port handled by few controllers 21 + 22 + Some devices may have one controller per PHY standard. E.g. USB 3.0 physical 23 + port may be handled by ohci-platform, ehci-platform and xhci-hcd. If there is 24 + only one LED user will most likely want to assign ports from all 3 hubs. 25 + 26 + 27 + This trigger can be activated from user space on led class devices as shown 28 + below: 29 + 30 + echo usbport > trigger 31 + 32 + This adds sysfs attributes to the LED that are documented in: 33 + Documentation/ABI/testing/sysfs-class-led-trigger-usbport 34 + 35 + Example use-case: 36 + 37 + echo usbport > trigger 38 + echo 1 > ports/usb1-port1 39 + echo 1 > ports/usb2-port1 40 + cat ports/usb1-port1 41 + echo 0 > ports/usb1-port1
+2 -1
MAINTAINERS
··· 12216 12216 F: drivers/net/usb/lan78xx.* 12217 12217 12218 12218 USB MASS STORAGE DRIVER 12219 - M: Matthew Dharm <mdharm-usb@one-eyed-alien.net> 12219 + M: Alan Stern <stern@rowland.harvard.edu> 12220 12220 L: linux-usb@vger.kernel.org 12221 12221 L: usb-storage@lists.one-eyed-alien.net 12222 12222 S: Maintained ··· 12300 12300 USB SERIAL SUBSYSTEM 12301 12301 M: Johan Hovold <johan@kernel.org> 12302 12302 L: linux-usb@vger.kernel.org 12303 + T: git git://git.kernel.org/pub/scm/linux/kernel/git/johan/usb-serial.git 12303 12304 S: Maintained 12304 12305 F: Documentation/usb/usb-serial.txt 12305 12306 F: drivers/usb/serial/
+1 -3
drivers/bluetooth/bcm203x.c
··· 185 185 data->state = BCM203X_LOAD_MINIDRV; 186 186 187 187 data->urb = usb_alloc_urb(0, GFP_KERNEL); 188 - if (!data->urb) { 189 - BT_ERR("Can't allocate URB"); 188 + if (!data->urb) 190 189 return -ENOMEM; 191 - } 192 190 193 191 if (request_firmware(&firmware, "BCM2033-MD.hex", &udev->dev) < 0) { 194 192 BT_ERR("Mini driver request failed");
+6
drivers/extcon/Kconfig
··· 96 96 Say Y here to enable support for USB peripheral and USB host 97 97 detection by palmas usb. 98 98 99 + config EXTCON_QCOM_SPMI_MISC 100 + tristate "Qualcomm USB extcon support" 101 + help 102 + Say Y here to enable SPMI PMIC based USB cable detection 103 + support on Qualcomm PMICs such as PM8941. 104 + 99 105 config EXTCON_RT8973A 100 106 tristate "Richtek RT8973A EXTCON support" 101 107 depends on I2C
+1
drivers/extcon/Makefile
··· 14 14 obj-$(CONFIG_EXTCON_MAX77843) += extcon-max77843.o 15 15 obj-$(CONFIG_EXTCON_MAX8997) += extcon-max8997.o 16 16 obj-$(CONFIG_EXTCON_PALMAS) += extcon-palmas.o 17 + obj-$(CONFIG_EXTCON_QCOM_SPMI_MISC) += extcon-qcom-spmi-misc.o 17 18 obj-$(CONFIG_EXTCON_RT8973A) += extcon-rt8973a.o 18 19 obj-$(CONFIG_EXTCON_SM5502) += extcon-sm5502.o 19 20 obj-$(CONFIG_EXTCON_USB_GPIO) += extcon-usb-gpio.o
+15 -12
drivers/extcon/extcon-adc-jack.c
··· 3 3 * 4 4 * Analog Jack extcon driver with ADC-based detection capability. 5 5 * 6 + * Copyright (C) 2016 Samsung Electronics 7 + * Chanwoo Choi <cw00.choi@samsung.com> 8 + * 6 9 * Copyright (C) 2012 Samsung Electronics 7 10 * MyungJoo Ham <myungjoo.ham@samsung.com> 8 11 * ··· 61 58 struct adc_jack_data *data = container_of(to_delayed_work(work), 62 59 struct adc_jack_data, 63 60 handler); 64 - u32 state = 0; 61 + struct adc_jack_cond *def; 65 62 int ret, adc_val; 66 63 int i; 67 64 ··· 73 70 74 71 /* Get state from adc value with adc_conditions */ 75 72 for (i = 0; i < data->num_conditions; i++) { 76 - struct adc_jack_cond *def = &data->adc_conditions[i]; 77 - if (!def->state) 78 - break; 73 + def = &data->adc_conditions[i]; 79 74 if (def->min_adc <= adc_val && def->max_adc >= adc_val) { 80 - state = def->state; 81 - break; 75 + extcon_set_state_sync(data->edev, def->id, true); 76 + return; 82 77 } 83 78 } 84 - /* if no def has met, it means state = 0 (no cables attached) */ 85 79 86 - extcon_set_state(data->edev, state); 80 + /* Set the detached state if adc value is not included in the range */ 81 + for (i = 0; i < data->num_conditions; i++) { 82 + def = &data->adc_conditions[i]; 83 + extcon_set_state_sync(data->edev, def->id, false); 84 + } 87 85 } 88 86 89 87 static irqreturn_t adc_jack_irq_thread(int irq, void *_data) ··· 118 114 return -ENOMEM; 119 115 } 120 116 121 - if (!pdata->adc_conditions || 122 - !pdata->adc_conditions[0].state) { 117 + if (!pdata->adc_conditions) { 123 118 dev_err(&pdev->dev, "error: adc_conditions not defined.\n"); 124 119 return -EINVAL; 125 120 } 126 121 data->adc_conditions = pdata->adc_conditions; 127 122 128 123 /* Check the length of array and set num_conditions */ 129 - for (i = 0; data->adc_conditions[i].state; i++) 130 - ; 124 + for (i = 0; data->adc_conditions[i].id != EXTCON_NONE; i++); 131 125 data->num_conditions = i; 132 126 133 127 data->chan = iio_channel_get(&pdev->dev, pdata->consumer_channel); ··· 160 158 if (data->wakeup_source) 161 159 device_init_wakeup(&pdev->dev, 1); 162 160 161 + adc_jack_handler(&data->handler.work); 163 162 return 0; 164 163 } 165 164
+15 -12
drivers/extcon/extcon-arizona.c
··· 183 183 if (clamp) 184 184 val = ARIZONA_RMV_SHRT_HP1L; 185 185 break; 186 - }; 186 + } 187 187 188 188 snd_soc_dapm_mutex_lock(arizona->dapm); 189 189 ··· 614 614 } 615 615 616 616 /* If the cable was removed while measuring ignore the result */ 617 - ret = extcon_get_cable_state_(info->edev, EXTCON_MECHANICAL); 617 + ret = extcon_get_state(info->edev, EXTCON_MECHANICAL); 618 618 if (ret < 0) { 619 619 dev_err(arizona->dev, "Failed to check cable state: %d\n", 620 620 ret); ··· 649 649 else 650 650 report = EXTCON_JACK_HEADPHONE; 651 651 652 - ret = extcon_set_cable_state_(info->edev, report, true); 652 + ret = extcon_set_state_sync(info->edev, report, true); 653 653 if (ret != 0) 654 654 dev_err(arizona->dev, "Failed to report HP/line: %d\n", 655 655 ret); ··· 732 732 ARIZONA_ACCDET_MODE_MASK, ARIZONA_ACCDET_MODE_MIC); 733 733 734 734 /* Just report headphone */ 735 - ret = extcon_set_cable_state_(info->edev, EXTCON_JACK_HEADPHONE, true); 735 + ret = extcon_set_state_sync(info->edev, EXTCON_JACK_HEADPHONE, true); 736 736 if (ret != 0) 737 737 dev_err(arizona->dev, "Failed to report headphone: %d\n", ret); 738 738 ··· 789 789 ARIZONA_ACCDET_MODE_MASK, ARIZONA_ACCDET_MODE_MIC); 790 790 791 791 /* Just report headphone */ 792 - ret = extcon_set_cable_state_(info->edev, EXTCON_JACK_HEADPHONE, true); 792 + ret = extcon_set_state_sync(info->edev, EXTCON_JACK_HEADPHONE, true); 793 793 if (ret != 0) 794 794 dev_err(arizona->dev, "Failed to report headphone: %d\n", ret); 795 795 ··· 829 829 mutex_lock(&info->lock); 830 830 831 831 /* If the cable was removed while measuring ignore the result */ 832 - ret = extcon_get_cable_state_(info->edev, EXTCON_MECHANICAL); 832 + ret = extcon_get_state(info->edev, EXTCON_MECHANICAL); 833 833 if (ret < 0) { 834 834 dev_err(arizona->dev, "Failed to check cable state: %d\n", 835 835 ret); ··· 914 914 915 915 arizona_identify_headphone(info); 916 916 917 - ret = extcon_set_cable_state_(info->edev, 917 + ret = extcon_set_state_sync(info->edev, 918 918 EXTCON_JACK_MICROPHONE, true); 919 919 if (ret != 0) 920 920 dev_err(arizona->dev, "Headset report failed: %d\n", ··· 1108 1108 1109 1109 if (info->last_jackdet == present) { 1110 1110 dev_dbg(arizona->dev, "Detected jack\n"); 1111 - ret = extcon_set_cable_state_(info->edev, 1111 + ret = extcon_set_state_sync(info->edev, 1112 1112 EXTCON_MECHANICAL, true); 1113 1113 1114 1114 if (ret != 0) ··· 1149 1149 info->micd_ranges[i].key, 0); 1150 1150 input_sync(info->input); 1151 1151 1152 - ret = extcon_update_state(info->edev, 0xffffffff, 0); 1153 - if (ret != 0) 1154 - dev_err(arizona->dev, "Removal report failed: %d\n", 1155 - ret); 1152 + for (i = 0; i < ARRAY_SIZE(arizona_cable) - 1; i++) { 1153 + ret = extcon_set_state_sync(info->edev, 1154 + arizona_cable[i], false); 1155 + if (ret != 0) 1156 + dev_err(arizona->dev, 1157 + "Removal report failed: %d\n", ret); 1158 + } 1156 1159 1157 1160 regmap_update_bits(arizona->regmap, 1158 1161 ARIZONA_JACK_DETECT_DEBOUNCE,
+4 -4
drivers/extcon/extcon-axp288.c
··· 189 189 190 190 switch (chrg_type) { 191 191 case DET_STAT_SDP: 192 - dev_dbg(info->dev, "sdp cable is connecetd\n"); 192 + dev_dbg(info->dev, "sdp cable is connected\n"); 193 193 notify_otg = true; 194 194 notify_charger = true; 195 195 cable = EXTCON_CHG_USB_SDP; 196 196 break; 197 197 case DET_STAT_CDP: 198 - dev_dbg(info->dev, "cdp cable is connecetd\n"); 198 + dev_dbg(info->dev, "cdp cable is connected\n"); 199 199 notify_otg = true; 200 200 notify_charger = true; 201 201 cable = EXTCON_CHG_USB_CDP; 202 202 break; 203 203 case DET_STAT_DCP: 204 - dev_dbg(info->dev, "dcp cable is connecetd\n"); 204 + dev_dbg(info->dev, "dcp cable is connected\n"); 205 205 notify_charger = true; 206 206 cable = EXTCON_CHG_USB_DCP; 207 207 break; ··· 226 226 } 227 227 228 228 if (notify_charger) 229 - extcon_set_cable_state_(info->edev, cable, vbus_attach); 229 + extcon_set_state_sync(info->edev, cable, vbus_attach); 230 230 231 231 /* Clear the flags on disconnect event */ 232 232 if (!vbus_attach)
+2 -1
drivers/extcon/extcon-gpio.c
··· 49 49 state = gpiod_get_value_cansleep(data->id_gpiod); 50 50 if (data->pdata->gpio_active_low) 51 51 state = !state; 52 - extcon_set_state(data->edev, state); 52 + 53 + extcon_set_state_sync(data->edev, data->pdata->extcon_id, state); 53 54 } 54 55 55 56 static irqreturn_t gpio_irq_handler(int irq, void *dev_id)
+9 -9
drivers/extcon/extcon-max14577.c
··· 3 3 * 4 4 * Copyright (C) 2013,2014 Samsung Electronics 5 5 * Chanwoo Choi <cw00.choi@samsung.com> 6 - * Krzysztof Kozlowski <k.kozlowski@samsung.com> 6 + * Krzysztof Kozlowski <krzk@kernel.org> 7 7 * 8 8 * This program is free software; you can redistribute it and/or modify 9 9 * it under the terms of the GNU General Public License as published by ··· 357 357 if (ret < 0) 358 358 return ret; 359 359 360 - extcon_set_cable_state_(info->edev, EXTCON_JIG, attached); 360 + extcon_set_state_sync(info->edev, EXTCON_JIG, attached); 361 361 362 362 return 0; 363 363 } ··· 454 454 if (ret < 0) 455 455 return ret; 456 456 457 - extcon_set_cable_state_(info->edev, EXTCON_USB, attached); 458 - extcon_set_cable_state_(info->edev, EXTCON_CHG_USB_SDP, 457 + extcon_set_state_sync(info->edev, EXTCON_USB, attached); 458 + extcon_set_state_sync(info->edev, EXTCON_CHG_USB_SDP, 459 459 attached); 460 460 break; 461 461 case MAX14577_CHARGER_TYPE_DEDICATED_CHG: 462 - extcon_set_cable_state_(info->edev, EXTCON_CHG_USB_DCP, 462 + extcon_set_state_sync(info->edev, EXTCON_CHG_USB_DCP, 463 463 attached); 464 464 break; 465 465 case MAX14577_CHARGER_TYPE_DOWNSTREAM_PORT: 466 - extcon_set_cable_state_(info->edev, EXTCON_CHG_USB_CDP, 466 + extcon_set_state_sync(info->edev, EXTCON_CHG_USB_CDP, 467 467 attached); 468 468 break; 469 469 case MAX14577_CHARGER_TYPE_SPECIAL_500MA: 470 - extcon_set_cable_state_(info->edev, EXTCON_CHG_USB_SLOW, 470 + extcon_set_state_sync(info->edev, EXTCON_CHG_USB_SLOW, 471 471 attached); 472 472 break; 473 473 case MAX14577_CHARGER_TYPE_SPECIAL_1A: 474 - extcon_set_cable_state_(info->edev, EXTCON_CHG_USB_FAST, 474 + extcon_set_state_sync(info->edev, EXTCON_CHG_USB_FAST, 475 475 attached); 476 476 break; 477 477 case MAX14577_CHARGER_TYPE_NONE: ··· 791 791 module_platform_driver(max14577_muic_driver); 792 792 793 793 MODULE_DESCRIPTION("Maxim 14577/77836 Extcon driver"); 794 - MODULE_AUTHOR("Chanwoo Choi <cw00.choi@samsung.com>, Krzysztof Kozlowski <k.kozlowski@samsung.com>"); 794 + MODULE_AUTHOR("Chanwoo Choi <cw00.choi@samsung.com>, Krzysztof Kozlowski <krzk@kernel.org>"); 795 795 MODULE_LICENSE("GPL"); 796 796 MODULE_ALIAS("platform:extcon-max14577");
+4 -4
drivers/extcon/extcon-max3355.c
··· 39 39 * As we don't have event for USB peripheral cable attached, 40 40 * we simulate USB peripheral attach here. 41 41 */ 42 - extcon_set_cable_state_(data->edev, EXTCON_USB_HOST, false); 43 - extcon_set_cable_state_(data->edev, EXTCON_USB, true); 42 + extcon_set_state_sync(data->edev, EXTCON_USB_HOST, false); 43 + extcon_set_state_sync(data->edev, EXTCON_USB, true); 44 44 } else { 45 45 /* 46 46 * ID = 0 means USB HOST cable attached. 47 47 * As we don't have event for USB peripheral cable detached, 48 48 * we simulate USB peripheral detach here. 49 49 */ 50 - extcon_set_cable_state_(data->edev, EXTCON_USB, false); 51 - extcon_set_cable_state_(data->edev, EXTCON_USB_HOST, true); 50 + extcon_set_state_sync(data->edev, EXTCON_USB, false); 51 + extcon_set_state_sync(data->edev, EXTCON_USB_HOST, true); 52 52 } 53 53 54 54 return IRQ_HANDLED;
+23 -23
drivers/extcon/extcon-max77693.c
··· 505 505 if (ret < 0) 506 506 return ret; 507 507 508 - extcon_set_cable_state_(info->edev, EXTCON_DOCK, attached); 509 - extcon_set_cable_state_(info->edev, EXTCON_DISP_MHL, attached); 508 + extcon_set_state_sync(info->edev, EXTCON_DOCK, attached); 509 + extcon_set_state_sync(info->edev, EXTCON_DISP_MHL, attached); 510 510 goto out; 511 511 case MAX77693_MUIC_ADC_AUDIO_MODE_REMOTE: /* Dock-Desk */ 512 512 dock_id = EXTCON_DOCK; ··· 514 514 case MAX77693_MUIC_ADC_AV_CABLE_NOLOAD: /* Dock-Audio */ 515 515 dock_id = EXTCON_DOCK; 516 516 if (!attached) { 517 - extcon_set_cable_state_(info->edev, EXTCON_USB, false); 518 - extcon_set_cable_state_(info->edev, EXTCON_CHG_USB_SDP, 517 + extcon_set_state_sync(info->edev, EXTCON_USB, false); 518 + extcon_set_state_sync(info->edev, EXTCON_CHG_USB_SDP, 519 519 false); 520 520 } 521 521 break; ··· 530 530 attached); 531 531 if (ret < 0) 532 532 return ret; 533 - extcon_set_cable_state_(info->edev, dock_id, attached); 533 + extcon_set_state_sync(info->edev, dock_id, attached); 534 534 535 535 out: 536 536 return 0; ··· 596 596 attached); 597 597 if (ret < 0) 598 598 return ret; 599 - extcon_set_cable_state_(info->edev, EXTCON_USB_HOST, attached); 599 + extcon_set_state_sync(info->edev, EXTCON_USB_HOST, attached); 600 600 break; 601 601 case MAX77693_MUIC_GND_AV_CABLE_LOAD: 602 602 /* Audio Video Cable with load, PATH:AUDIO */ ··· 604 604 attached); 605 605 if (ret < 0) 606 606 return ret; 607 - extcon_set_cable_state_(info->edev, EXTCON_USB, attached); 608 - extcon_set_cable_state_(info->edev, EXTCON_CHG_USB_SDP, 607 + extcon_set_state_sync(info->edev, EXTCON_USB, attached); 608 + extcon_set_state_sync(info->edev, EXTCON_CHG_USB_SDP, 609 609 attached); 610 610 break; 611 611 case MAX77693_MUIC_GND_MHL: 612 612 case MAX77693_MUIC_GND_MHL_VB: 613 613 /* MHL or MHL with USB/TA cable */ 614 - extcon_set_cable_state_(info->edev, EXTCON_DISP_MHL, attached); 614 + extcon_set_state_sync(info->edev, EXTCON_DISP_MHL, attached); 615 615 break; 616 616 default: 617 617 dev_err(info->dev, "failed to detect %s cable of gnd type\n", ··· 653 653 if (ret < 0) 654 654 return ret; 655 655 656 - extcon_set_cable_state_(info->edev, EXTCON_JIG, attached); 656 + extcon_set_state_sync(info->edev, EXTCON_JIG, attached); 657 657 658 658 return 0; 659 659 } ··· 807 807 * - Support charging through micro-usb port without 808 808 * data connection 809 809 */ 810 - extcon_set_cable_state_(info->edev, EXTCON_CHG_USB_DCP, 810 + extcon_set_state_sync(info->edev, EXTCON_CHG_USB_DCP, 811 811 attached); 812 812 if (!cable_attached) 813 - extcon_set_cable_state_(info->edev, 813 + extcon_set_state_sync(info->edev, 814 814 EXTCON_DISP_MHL, cable_attached); 815 815 break; 816 816 } ··· 834 834 * - Support charging through micro-usb port without 835 835 * data connection. 836 836 */ 837 - extcon_set_cable_state_(info->edev, EXTCON_USB, 837 + extcon_set_state_sync(info->edev, EXTCON_USB, 838 838 attached); 839 - extcon_set_cable_state_(info->edev, EXTCON_CHG_USB_SDP, 839 + extcon_set_state_sync(info->edev, EXTCON_CHG_USB_SDP, 840 840 attached); 841 841 842 842 if (!cable_attached) 843 - extcon_set_cable_state_(info->edev, EXTCON_DOCK, 843 + extcon_set_state_sync(info->edev, EXTCON_DOCK, 844 844 cable_attached); 845 845 break; 846 846 case MAX77693_MUIC_ADC_RESERVED_ACC_3: /* Dock-Smart */ ··· 869 869 if (ret < 0) 870 870 return ret; 871 871 872 - extcon_set_cable_state_(info->edev, EXTCON_DOCK, 872 + extcon_set_state_sync(info->edev, EXTCON_DOCK, 873 873 attached); 874 - extcon_set_cable_state_(info->edev, EXTCON_DISP_MHL, 874 + extcon_set_state_sync(info->edev, EXTCON_DISP_MHL, 875 875 attached); 876 876 break; 877 877 } ··· 905 905 if (ret < 0) 906 906 return ret; 907 907 908 - extcon_set_cable_state_(info->edev, EXTCON_USB, 908 + extcon_set_state_sync(info->edev, EXTCON_USB, 909 909 attached); 910 - extcon_set_cable_state_(info->edev, EXTCON_CHG_USB_SDP, 910 + extcon_set_state_sync(info->edev, EXTCON_CHG_USB_SDP, 911 911 attached); 912 912 break; 913 913 case MAX77693_CHARGER_TYPE_DEDICATED_CHG: 914 914 /* Only TA cable */ 915 - extcon_set_cable_state_(info->edev, EXTCON_CHG_USB_DCP, 915 + extcon_set_state_sync(info->edev, EXTCON_CHG_USB_DCP, 916 916 attached); 917 917 break; 918 918 } 919 919 break; 920 920 case MAX77693_CHARGER_TYPE_DOWNSTREAM_PORT: 921 - extcon_set_cable_state_(info->edev, EXTCON_CHG_USB_CDP, 921 + extcon_set_state_sync(info->edev, EXTCON_CHG_USB_CDP, 922 922 attached); 923 923 break; 924 924 case MAX77693_CHARGER_TYPE_APPLE_500MA: 925 - extcon_set_cable_state_(info->edev, EXTCON_CHG_USB_SLOW, 925 + extcon_set_state_sync(info->edev, EXTCON_CHG_USB_SLOW, 926 926 attached); 927 927 break; 928 928 case MAX77693_CHARGER_TYPE_APPLE_1A_2A: 929 - extcon_set_cable_state_(info->edev, EXTCON_CHG_USB_FAST, 929 + extcon_set_state_sync(info->edev, EXTCON_CHG_USB_FAST, 930 930 attached); 931 931 break; 932 932 case MAX77693_CHARGER_TYPE_DEAD_BATTERY:
+11 -11
drivers/extcon/extcon-max77843.c
··· 346 346 if (ret < 0) 347 347 return ret; 348 348 349 - extcon_set_cable_state_(info->edev, EXTCON_USB_HOST, attached); 349 + extcon_set_state_sync(info->edev, EXTCON_USB_HOST, attached); 350 350 break; 351 351 case MAX77843_MUIC_GND_MHL_VB: 352 352 case MAX77843_MUIC_GND_MHL: ··· 356 356 if (ret < 0) 357 357 return ret; 358 358 359 - extcon_set_cable_state_(info->edev, EXTCON_DISP_MHL, attached); 359 + extcon_set_state_sync(info->edev, EXTCON_DISP_MHL, attached); 360 360 break; 361 361 default: 362 362 dev_err(info->dev, "failed to detect %s accessory(gnd:0x%x)\n", ··· 392 392 if (ret < 0) 393 393 return ret; 394 394 395 - extcon_set_cable_state_(info->edev, EXTCON_JIG, attached); 395 + extcon_set_state_sync(info->edev, EXTCON_JIG, attached); 396 396 397 397 return 0; 398 398 } ··· 486 486 if (ret < 0) 487 487 return ret; 488 488 489 - extcon_set_cable_state_(info->edev, EXTCON_USB, attached); 490 - extcon_set_cable_state_(info->edev, EXTCON_CHG_USB_SDP, 489 + extcon_set_state_sync(info->edev, EXTCON_USB, attached); 490 + extcon_set_state_sync(info->edev, EXTCON_CHG_USB_SDP, 491 491 attached); 492 492 break; 493 493 case MAX77843_MUIC_CHG_DOWNSTREAM: ··· 497 497 if (ret < 0) 498 498 return ret; 499 499 500 - extcon_set_cable_state_(info->edev, EXTCON_CHG_USB_CDP, 500 + extcon_set_state_sync(info->edev, EXTCON_CHG_USB_CDP, 501 501 attached); 502 502 break; 503 503 case MAX77843_MUIC_CHG_DEDICATED: ··· 507 507 if (ret < 0) 508 508 return ret; 509 509 510 - extcon_set_cable_state_(info->edev, EXTCON_CHG_USB_DCP, 510 + extcon_set_state_sync(info->edev, EXTCON_CHG_USB_DCP, 511 511 attached); 512 512 break; 513 513 case MAX77843_MUIC_CHG_SPECIAL_500MA: ··· 517 517 if (ret < 0) 518 518 return ret; 519 519 520 - extcon_set_cable_state_(info->edev, EXTCON_CHG_USB_SLOW, 520 + extcon_set_state_sync(info->edev, EXTCON_CHG_USB_SLOW, 521 521 attached); 522 522 break; 523 523 case MAX77843_MUIC_CHG_SPECIAL_1A: ··· 527 527 if (ret < 0) 528 528 return ret; 529 529 530 - extcon_set_cable_state_(info->edev, EXTCON_CHG_USB_FAST, 530 + extcon_set_state_sync(info->edev, EXTCON_CHG_USB_FAST, 531 531 attached); 532 532 break; 533 533 case MAX77843_MUIC_CHG_GND: ··· 536 536 537 537 /* Charger cable on MHL accessory is attach or detach */ 538 538 if (gnd_type == MAX77843_MUIC_GND_MHL_VB) 539 - extcon_set_cable_state_(info->edev, EXTCON_CHG_USB_DCP, 539 + extcon_set_state_sync(info->edev, EXTCON_CHG_USB_DCP, 540 540 true); 541 541 else if (gnd_type == MAX77843_MUIC_GND_MHL) 542 - extcon_set_cable_state_(info->edev, EXTCON_CHG_USB_DCP, 542 + extcon_set_state_sync(info->edev, EXTCON_CHG_USB_DCP, 543 543 false); 544 544 break; 545 545 case MAX77843_MUIC_CHG_NONE:
+10 -10
drivers/extcon/extcon-max8997.c
··· 331 331 332 332 switch (usb_type) { 333 333 case MAX8997_USB_HOST: 334 - extcon_set_cable_state_(info->edev, EXTCON_USB_HOST, attached); 334 + extcon_set_state_sync(info->edev, EXTCON_USB_HOST, attached); 335 335 break; 336 336 case MAX8997_USB_DEVICE: 337 - extcon_set_cable_state_(info->edev, EXTCON_USB, attached); 338 - extcon_set_cable_state_(info->edev, EXTCON_CHG_USB_SDP, 337 + extcon_set_state_sync(info->edev, EXTCON_USB, attached); 338 + extcon_set_state_sync(info->edev, EXTCON_CHG_USB_SDP, 339 339 attached); 340 340 break; 341 341 default: ··· 361 361 switch (cable_type) { 362 362 case MAX8997_MUIC_ADC_AV_CABLE_NOLOAD: 363 363 case MAX8997_MUIC_ADC_FACTORY_MODE_UART_ON: 364 - extcon_set_cable_state_(info->edev, EXTCON_DOCK, attached); 364 + extcon_set_state_sync(info->edev, EXTCON_DOCK, attached); 365 365 break; 366 366 default: 367 367 dev_err(info->dev, "failed to detect %s dock device\n", ··· 384 384 return ret; 385 385 } 386 386 387 - extcon_set_cable_state_(info->edev, EXTCON_JIG, attached); 387 + extcon_set_state_sync(info->edev, EXTCON_JIG, attached); 388 388 389 389 return 0; 390 390 } ··· 406 406 return ret; 407 407 break; 408 408 case MAX8997_MUIC_ADC_MHL: 409 - extcon_set_cable_state_(info->edev, EXTCON_DISP_MHL, attached); 409 + extcon_set_state_sync(info->edev, EXTCON_DISP_MHL, attached); 410 410 break; 411 411 case MAX8997_MUIC_ADC_FACTORY_MODE_USB_OFF: 412 412 case MAX8997_MUIC_ADC_FACTORY_MODE_USB_ON: ··· 489 489 } 490 490 break; 491 491 case MAX8997_CHARGER_TYPE_DOWNSTREAM_PORT: 492 - extcon_set_cable_state_(info->edev, EXTCON_CHG_USB_CDP, 492 + extcon_set_state_sync(info->edev, EXTCON_CHG_USB_CDP, 493 493 attached); 494 494 break; 495 495 case MAX8997_CHARGER_TYPE_DEDICATED_CHG: 496 - extcon_set_cable_state_(info->edev, EXTCON_CHG_USB_DCP, 496 + extcon_set_state_sync(info->edev, EXTCON_CHG_USB_DCP, 497 497 attached); 498 498 break; 499 499 case MAX8997_CHARGER_TYPE_500MA: 500 - extcon_set_cable_state_(info->edev, EXTCON_CHG_USB_SLOW, 500 + extcon_set_state_sync(info->edev, EXTCON_CHG_USB_SLOW, 501 501 attached); 502 502 break; 503 503 case MAX8997_CHARGER_TYPE_1A: 504 - extcon_set_cable_state_(info->edev, EXTCON_CHG_USB_FAST, 504 + extcon_set_state_sync(info->edev, EXTCON_CHG_USB_FAST, 505 505 attached); 506 506 break; 507 507 default:
+8 -8
drivers/extcon/extcon-palmas.c
··· 61 61 if (vbus_line_state & PALMAS_INT3_LINE_STATE_VBUS) { 62 62 if (palmas_usb->linkstat != PALMAS_USB_STATE_VBUS) { 63 63 palmas_usb->linkstat = PALMAS_USB_STATE_VBUS; 64 - extcon_set_cable_state_(edev, EXTCON_USB, true); 64 + extcon_set_state_sync(edev, EXTCON_USB, true); 65 65 dev_info(palmas_usb->dev, "USB cable is attached\n"); 66 66 } else { 67 67 dev_dbg(palmas_usb->dev, ··· 70 70 } else if (!(vbus_line_state & PALMAS_INT3_LINE_STATE_VBUS)) { 71 71 if (palmas_usb->linkstat == PALMAS_USB_STATE_VBUS) { 72 72 palmas_usb->linkstat = PALMAS_USB_STATE_DISCONNECT; 73 - extcon_set_cable_state_(edev, EXTCON_USB, false); 73 + extcon_set_state_sync(edev, EXTCON_USB, false); 74 74 dev_info(palmas_usb->dev, "USB cable is detached\n"); 75 75 } else { 76 76 dev_dbg(palmas_usb->dev, ··· 98 98 PALMAS_USB_ID_INT_LATCH_CLR, 99 99 PALMAS_USB_ID_INT_EN_HI_CLR_ID_GND); 100 100 palmas_usb->linkstat = PALMAS_USB_STATE_ID; 101 - extcon_set_cable_state_(edev, EXTCON_USB_HOST, true); 101 + extcon_set_state_sync(edev, EXTCON_USB_HOST, true); 102 102 dev_info(palmas_usb->dev, "USB-HOST cable is attached\n"); 103 103 } else if ((set & PALMAS_USB_ID_INT_SRC_ID_FLOAT) && 104 104 (id_src & PALMAS_USB_ID_INT_SRC_ID_FLOAT)) { ··· 106 106 PALMAS_USB_ID_INT_LATCH_CLR, 107 107 PALMAS_USB_ID_INT_EN_HI_CLR_ID_FLOAT); 108 108 palmas_usb->linkstat = PALMAS_USB_STATE_DISCONNECT; 109 - extcon_set_cable_state_(edev, EXTCON_USB_HOST, false); 109 + extcon_set_state_sync(edev, EXTCON_USB_HOST, false); 110 110 dev_info(palmas_usb->dev, "USB-HOST cable is detached\n"); 111 111 } else if ((palmas_usb->linkstat == PALMAS_USB_STATE_ID) && 112 112 (!(set & PALMAS_USB_ID_INT_SRC_ID_GND))) { 113 113 palmas_usb->linkstat = PALMAS_USB_STATE_DISCONNECT; 114 - extcon_set_cable_state_(edev, EXTCON_USB_HOST, false); 114 + extcon_set_state_sync(edev, EXTCON_USB_HOST, false); 115 115 dev_info(palmas_usb->dev, "USB-HOST cable is detached\n"); 116 116 } else if ((palmas_usb->linkstat == PALMAS_USB_STATE_DISCONNECT) && 117 117 (id_src & PALMAS_USB_ID_INT_SRC_ID_GND)) { 118 118 palmas_usb->linkstat = PALMAS_USB_STATE_ID; 119 - extcon_set_cable_state_(edev, EXTCON_USB_HOST, true); 119 + extcon_set_state_sync(edev, EXTCON_USB_HOST, true); 120 120 dev_info(palmas_usb->dev, " USB-HOST cable is attached\n"); 121 121 } 122 122 ··· 137 137 id = gpiod_get_value_cansleep(palmas_usb->id_gpiod); 138 138 139 139 if (id) { 140 - extcon_set_cable_state_(edev, EXTCON_USB_HOST, false); 140 + extcon_set_state_sync(edev, EXTCON_USB_HOST, false); 141 141 dev_info(palmas_usb->dev, "USB-HOST cable is detached\n"); 142 142 } else { 143 - extcon_set_cable_state_(edev, EXTCON_USB_HOST, true); 143 + extcon_set_state_sync(edev, EXTCON_USB_HOST, true); 144 144 dev_info(palmas_usb->dev, "USB-HOST cable is attached\n"); 145 145 } 146 146 }
+170
drivers/extcon/extcon-qcom-spmi-misc.c
··· 1 + /** 2 + * extcon-qcom-spmi-misc.c - Qualcomm USB extcon driver to support USB ID 3 + * detection based on extcon-usb-gpio.c. 4 + * 5 + * Copyright (C) 2016 Linaro, Ltd. 6 + * Stephen Boyd <stephen.boyd@linaro.org> 7 + * 8 + * This program is free software; you can redistribute it and/or modify 9 + * it under the terms of the GNU General Public License version 2 as 10 + * published by the Free Software Foundation. 11 + * 12 + * This program is distributed in the hope that it will be useful, 13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 + * GNU General Public License for more details. 16 + */ 17 + 18 + #include <linux/extcon.h> 19 + #include <linux/init.h> 20 + #include <linux/interrupt.h> 21 + #include <linux/kernel.h> 22 + #include <linux/module.h> 23 + #include <linux/platform_device.h> 24 + #include <linux/slab.h> 25 + #include <linux/workqueue.h> 26 + 27 + #define USB_ID_DEBOUNCE_MS 5 /* ms */ 28 + 29 + struct qcom_usb_extcon_info { 30 + struct extcon_dev *edev; 31 + int irq; 32 + struct delayed_work wq_detcable; 33 + unsigned long debounce_jiffies; 34 + }; 35 + 36 + static const unsigned int qcom_usb_extcon_cable[] = { 37 + EXTCON_USB_HOST, 38 + EXTCON_NONE, 39 + }; 40 + 41 + static void qcom_usb_extcon_detect_cable(struct work_struct *work) 42 + { 43 + bool id; 44 + int ret; 45 + struct qcom_usb_extcon_info *info = container_of(to_delayed_work(work), 46 + struct qcom_usb_extcon_info, 47 + wq_detcable); 48 + 49 + /* check ID and update cable state */ 50 + ret = irq_get_irqchip_state(info->irq, IRQCHIP_STATE_LINE_LEVEL, &id); 51 + if (ret) 52 + return; 53 + 54 + extcon_set_state(info->edev, EXTCON_USB_HOST, !id); 55 + } 56 + 57 + static irqreturn_t qcom_usb_irq_handler(int irq, void *dev_id) 58 + { 59 + struct qcom_usb_extcon_info *info = dev_id; 60 + 61 + queue_delayed_work(system_power_efficient_wq, &info->wq_detcable, 62 + info->debounce_jiffies); 63 + 64 + return IRQ_HANDLED; 65 + } 66 + 67 + static int qcom_usb_extcon_probe(struct platform_device *pdev) 68 + { 69 + struct device *dev = &pdev->dev; 70 + struct qcom_usb_extcon_info *info; 71 + int ret; 72 + 73 + info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL); 74 + if (!info) 75 + return -ENOMEM; 76 + 77 + info->edev = devm_extcon_dev_allocate(dev, qcom_usb_extcon_cable); 78 + if (IS_ERR(info->edev)) { 79 + dev_err(dev, "failed to allocate extcon device\n"); 80 + return -ENOMEM; 81 + } 82 + 83 + ret = devm_extcon_dev_register(dev, info->edev); 84 + if (ret < 0) { 85 + dev_err(dev, "failed to register extcon device\n"); 86 + return ret; 87 + } 88 + 89 + info->debounce_jiffies = msecs_to_jiffies(USB_ID_DEBOUNCE_MS); 90 + INIT_DELAYED_WORK(&info->wq_detcable, qcom_usb_extcon_detect_cable); 91 + 92 + info->irq = platform_get_irq_byname(pdev, "usb_id"); 93 + if (info->irq < 0) 94 + return info->irq; 95 + 96 + ret = devm_request_threaded_irq(dev, info->irq, NULL, 97 + qcom_usb_irq_handler, 98 + IRQF_TRIGGER_RISING | 99 + IRQF_TRIGGER_FALLING | IRQF_ONESHOT, 100 + pdev->name, info); 101 + if (ret < 0) { 102 + dev_err(dev, "failed to request handler for ID IRQ\n"); 103 + return ret; 104 + } 105 + 106 + platform_set_drvdata(pdev, info); 107 + device_init_wakeup(dev, 1); 108 + 109 + /* Perform initial detection */ 110 + qcom_usb_extcon_detect_cable(&info->wq_detcable.work); 111 + 112 + return 0; 113 + } 114 + 115 + static int qcom_usb_extcon_remove(struct platform_device *pdev) 116 + { 117 + struct qcom_usb_extcon_info *info = platform_get_drvdata(pdev); 118 + 119 + cancel_delayed_work_sync(&info->wq_detcable); 120 + 121 + return 0; 122 + } 123 + 124 + #ifdef CONFIG_PM_SLEEP 125 + static int qcom_usb_extcon_suspend(struct device *dev) 126 + { 127 + struct qcom_usb_extcon_info *info = dev_get_drvdata(dev); 128 + int ret = 0; 129 + 130 + if (device_may_wakeup(dev)) 131 + ret = enable_irq_wake(info->irq); 132 + 133 + return ret; 134 + } 135 + 136 + static int qcom_usb_extcon_resume(struct device *dev) 137 + { 138 + struct qcom_usb_extcon_info *info = dev_get_drvdata(dev); 139 + int ret = 0; 140 + 141 + if (device_may_wakeup(dev)) 142 + ret = disable_irq_wake(info->irq); 143 + 144 + return ret; 145 + } 146 + #endif 147 + 148 + static SIMPLE_DEV_PM_OPS(qcom_usb_extcon_pm_ops, 149 + qcom_usb_extcon_suspend, qcom_usb_extcon_resume); 150 + 151 + static const struct of_device_id qcom_usb_extcon_dt_match[] = { 152 + { .compatible = "qcom,pm8941-misc", }, 153 + { } 154 + }; 155 + MODULE_DEVICE_TABLE(of, qcom_usb_extcon_dt_match); 156 + 157 + static struct platform_driver qcom_usb_extcon_driver = { 158 + .probe = qcom_usb_extcon_probe, 159 + .remove = qcom_usb_extcon_remove, 160 + .driver = { 161 + .name = "extcon-pm8941-misc", 162 + .pm = &qcom_usb_extcon_pm_ops, 163 + .of_match_table = qcom_usb_extcon_dt_match, 164 + }, 165 + }; 166 + module_platform_driver(qcom_usb_extcon_driver); 167 + 168 + MODULE_DESCRIPTION("QCOM USB ID extcon driver"); 169 + MODULE_AUTHOR("Stephen Boyd <stephen.boyd@linaro.org>"); 170 + MODULE_LICENSE("GPL v2");
+2 -2
drivers/extcon/extcon-rt8973a.c
··· 398 398 return ret; 399 399 400 400 /* Change the state of external accessory */ 401 - extcon_set_cable_state_(info->edev, id, attached); 401 + extcon_set_state_sync(info->edev, id, attached); 402 402 if (id == EXTCON_USB) 403 - extcon_set_cable_state_(info->edev, EXTCON_CHG_USB_SDP, 403 + extcon_set_state_sync(info->edev, EXTCON_CHG_USB_SDP, 404 404 attached); 405 405 406 406 return 0;
+2 -2
drivers/extcon/extcon-sm5502.c
··· 411 411 return ret; 412 412 413 413 /* Change the state of external accessory */ 414 - extcon_set_cable_state_(info->edev, id, attached); 414 + extcon_set_state_sync(info->edev, id, attached); 415 415 if (id == EXTCON_USB) 416 - extcon_set_cable_state_(info->edev, EXTCON_CHG_USB_SDP, 416 + extcon_set_state_sync(info->edev, EXTCON_CHG_USB_SDP, 417 417 attached); 418 418 419 419 return 0;
+4 -4
drivers/extcon/extcon-usb-gpio.c
··· 63 63 * As we don't have event for USB peripheral cable attached, 64 64 * we simulate USB peripheral attach here. 65 65 */ 66 - extcon_set_cable_state_(info->edev, EXTCON_USB_HOST, false); 67 - extcon_set_cable_state_(info->edev, EXTCON_USB, true); 66 + extcon_set_state_sync(info->edev, EXTCON_USB_HOST, false); 67 + extcon_set_state_sync(info->edev, EXTCON_USB, true); 68 68 } else { 69 69 /* 70 70 * ID = 0 means USB HOST cable attached. 71 71 * As we don't have event for USB peripheral cable detached, 72 72 * we simulate USB peripheral detach here. 73 73 */ 74 - extcon_set_cable_state_(info->edev, EXTCON_USB, false); 75 - extcon_set_cable_state_(info->edev, EXTCON_USB_HOST, true); 74 + extcon_set_state_sync(info->edev, EXTCON_USB, false); 75 + extcon_set_state_sync(info->edev, EXTCON_USB_HOST, true); 76 76 } 77 77 } 78 78
+652 -176
drivers/extcon/extcon.c
··· 38 38 #define SUPPORTED_CABLE_MAX 32 39 39 #define CABLE_NAME_MAX 30 40 40 41 - static const char *extcon_name[] = { 42 - [EXTCON_NONE] = "NONE", 41 + struct __extcon_info { 42 + unsigned int type; 43 + unsigned int id; 44 + const char *name; 45 + 46 + } extcon_info[] = { 47 + [EXTCON_NONE] = { 48 + .type = EXTCON_TYPE_MISC, 49 + .id = EXTCON_NONE, 50 + .name = "NONE", 51 + }, 43 52 44 53 /* USB external connector */ 45 - [EXTCON_USB] = "USB", 46 - [EXTCON_USB_HOST] = "USB-HOST", 54 + [EXTCON_USB] = { 55 + .type = EXTCON_TYPE_USB, 56 + .id = EXTCON_USB, 57 + .name = "USB", 58 + }, 59 + [EXTCON_USB_HOST] = { 60 + .type = EXTCON_TYPE_USB, 61 + .id = EXTCON_USB_HOST, 62 + .name = "USB_HOST", 63 + }, 47 64 48 65 /* Charging external connector */ 49 - [EXTCON_CHG_USB_SDP] = "SDP", 50 - [EXTCON_CHG_USB_DCP] = "DCP", 51 - [EXTCON_CHG_USB_CDP] = "CDP", 52 - [EXTCON_CHG_USB_ACA] = "ACA", 53 - [EXTCON_CHG_USB_FAST] = "FAST-CHARGER", 54 - [EXTCON_CHG_USB_SLOW] = "SLOW-CHARGER", 66 + [EXTCON_CHG_USB_SDP] = { 67 + .type = EXTCON_TYPE_CHG | EXTCON_TYPE_USB, 68 + .id = EXTCON_CHG_USB_SDP, 69 + .name = "SDP", 70 + }, 71 + [EXTCON_CHG_USB_DCP] = { 72 + .type = EXTCON_TYPE_CHG | EXTCON_TYPE_USB, 73 + .id = EXTCON_CHG_USB_DCP, 74 + .name = "DCP", 75 + }, 76 + [EXTCON_CHG_USB_CDP] = { 77 + .type = EXTCON_TYPE_CHG | EXTCON_TYPE_USB, 78 + .id = EXTCON_CHG_USB_CDP, 79 + .name = "CDP", 80 + }, 81 + [EXTCON_CHG_USB_ACA] = { 82 + .type = EXTCON_TYPE_CHG | EXTCON_TYPE_USB, 83 + .id = EXTCON_CHG_USB_ACA, 84 + .name = "ACA", 85 + }, 86 + [EXTCON_CHG_USB_FAST] = { 87 + .type = EXTCON_TYPE_CHG | EXTCON_TYPE_USB, 88 + .id = EXTCON_CHG_USB_FAST, 89 + .name = "FAST-CHARGER", 90 + }, 91 + [EXTCON_CHG_USB_SLOW] = { 92 + .type = EXTCON_TYPE_CHG | EXTCON_TYPE_USB, 93 + .id = EXTCON_CHG_USB_SLOW, 94 + .name = "SLOW-CHARGER", 95 + }, 96 + [EXTCON_CHG_WPT] = { 97 + .type = EXTCON_TYPE_CHG, 98 + .id = EXTCON_CHG_WPT, 99 + .name = "WPT", 100 + }, 55 101 56 102 /* Jack external connector */ 57 - [EXTCON_JACK_MICROPHONE] = "MICROPHONE", 58 - [EXTCON_JACK_HEADPHONE] = "HEADPHONE", 59 - [EXTCON_JACK_LINE_IN] = "LINE-IN", 60 - [EXTCON_JACK_LINE_OUT] = "LINE-OUT", 61 - [EXTCON_JACK_VIDEO_IN] = "VIDEO-IN", 62 - [EXTCON_JACK_VIDEO_OUT] = "VIDEO-OUT", 63 - [EXTCON_JACK_SPDIF_IN] = "SPDIF-IN", 64 - [EXTCON_JACK_SPDIF_OUT] = "SPDIF-OUT", 103 + [EXTCON_JACK_MICROPHONE] = { 104 + .type = EXTCON_TYPE_JACK, 105 + .id = EXTCON_JACK_MICROPHONE, 106 + .name = "MICROPHONE", 107 + }, 108 + [EXTCON_JACK_HEADPHONE] = { 109 + .type = EXTCON_TYPE_JACK, 110 + .id = EXTCON_JACK_HEADPHONE, 111 + .name = "HEADPHONE", 112 + }, 113 + [EXTCON_JACK_LINE_IN] = { 114 + .type = EXTCON_TYPE_JACK, 115 + .id = EXTCON_JACK_LINE_IN, 116 + .name = "LINE-IN", 117 + }, 118 + [EXTCON_JACK_LINE_OUT] = { 119 + .type = EXTCON_TYPE_JACK, 120 + .id = EXTCON_JACK_LINE_OUT, 121 + .name = "LINE-OUT", 122 + }, 123 + [EXTCON_JACK_VIDEO_IN] = { 124 + .type = EXTCON_TYPE_JACK, 125 + .id = EXTCON_JACK_VIDEO_IN, 126 + .name = "VIDEO-IN", 127 + }, 128 + [EXTCON_JACK_VIDEO_OUT] = { 129 + .type = EXTCON_TYPE_JACK, 130 + .id = EXTCON_JACK_VIDEO_OUT, 131 + .name = "VIDEO-OUT", 132 + }, 133 + [EXTCON_JACK_SPDIF_IN] = { 134 + .type = EXTCON_TYPE_JACK, 135 + .id = EXTCON_JACK_SPDIF_IN, 136 + .name = "SPDIF-IN", 137 + }, 138 + [EXTCON_JACK_SPDIF_OUT] = { 139 + .type = EXTCON_TYPE_JACK, 140 + .id = EXTCON_JACK_SPDIF_OUT, 141 + .name = "SPDIF-OUT", 142 + }, 65 143 66 144 /* Display external connector */ 67 - [EXTCON_DISP_HDMI] = "HDMI", 68 - [EXTCON_DISP_MHL] = "MHL", 69 - [EXTCON_DISP_DVI] = "DVI", 70 - [EXTCON_DISP_VGA] = "VGA", 145 + [EXTCON_DISP_HDMI] = { 146 + .type = EXTCON_TYPE_DISP, 147 + .id = EXTCON_DISP_HDMI, 148 + .name = "HDMI", 149 + }, 150 + [EXTCON_DISP_MHL] = { 151 + .type = EXTCON_TYPE_DISP, 152 + .id = EXTCON_DISP_MHL, 153 + .name = "MHL", 154 + }, 155 + [EXTCON_DISP_DVI] = { 156 + .type = EXTCON_TYPE_DISP, 157 + .id = EXTCON_DISP_DVI, 158 + .name = "DVI", 159 + }, 160 + [EXTCON_DISP_VGA] = { 161 + .type = EXTCON_TYPE_DISP, 162 + .id = EXTCON_DISP_VGA, 163 + .name = "VGA", 164 + }, 165 + [EXTCON_DISP_DP] = { 166 + .type = EXTCON_TYPE_DISP | EXTCON_TYPE_USB, 167 + .id = EXTCON_DISP_DP, 168 + .name = "DP", 169 + }, 170 + [EXTCON_DISP_HMD] = { 171 + .type = EXTCON_TYPE_DISP | EXTCON_TYPE_USB, 172 + .id = EXTCON_DISP_HMD, 173 + .name = "HMD", 174 + }, 71 175 72 176 /* Miscellaneous external connector */ 73 - [EXTCON_DOCK] = "DOCK", 74 - [EXTCON_JIG] = "JIG", 75 - [EXTCON_MECHANICAL] = "MECHANICAL", 177 + [EXTCON_DOCK] = { 178 + .type = EXTCON_TYPE_MISC, 179 + .id = EXTCON_DOCK, 180 + .name = "DOCK", 181 + }, 182 + [EXTCON_JIG] = { 183 + .type = EXTCON_TYPE_MISC, 184 + .id = EXTCON_JIG, 185 + .name = "JIG", 186 + }, 187 + [EXTCON_MECHANICAL] = { 188 + .type = EXTCON_TYPE_MISC, 189 + .id = EXTCON_MECHANICAL, 190 + .name = "MECHANICAL", 191 + }, 76 192 77 - NULL, 193 + { /* sentinel */ } 78 194 }; 79 195 80 196 /** ··· 211 95 struct device_attribute attr_state; 212 96 213 97 struct attribute *attrs[3]; /* to be fed to attr_g.attrs */ 98 + 99 + union extcon_property_value usb_propval[EXTCON_PROP_USB_CNT]; 100 + union extcon_property_value chg_propval[EXTCON_PROP_CHG_CNT]; 101 + union extcon_property_value jack_propval[EXTCON_PROP_JACK_CNT]; 102 + union extcon_property_value disp_propval[EXTCON_PROP_DISP_CNT]; 103 + 104 + unsigned long usb_bits[BITS_TO_LONGS(EXTCON_PROP_USB_CNT)]; 105 + unsigned long chg_bits[BITS_TO_LONGS(EXTCON_PROP_CHG_CNT)]; 106 + unsigned long jack_bits[BITS_TO_LONGS(EXTCON_PROP_JACK_CNT)]; 107 + unsigned long disp_bits[BITS_TO_LONGS(EXTCON_PROP_DISP_CNT)]; 214 108 }; 215 109 216 110 static struct class *extcon_class; ··· 273 147 return -EINVAL; 274 148 } 275 149 276 - static bool is_extcon_changed(u32 prev, u32 new, int idx, bool *attached) 150 + static int get_extcon_type(unsigned int prop) 277 151 { 278 - if (((prev >> idx) & 0x1) != ((new >> idx) & 0x1)) { 279 - *attached = ((new >> idx) & 0x1) ? true : false; 280 - return true; 152 + switch (prop) { 153 + case EXTCON_PROP_USB_MIN ... EXTCON_PROP_USB_MAX: 154 + return EXTCON_TYPE_USB; 155 + case EXTCON_PROP_CHG_MIN ... EXTCON_PROP_CHG_MAX: 156 + return EXTCON_TYPE_CHG; 157 + case EXTCON_PROP_JACK_MIN ... EXTCON_PROP_JACK_MAX: 158 + return EXTCON_TYPE_JACK; 159 + case EXTCON_PROP_DISP_MIN ... EXTCON_PROP_DISP_MAX: 160 + return EXTCON_TYPE_DISP; 161 + default: 162 + return -EINVAL; 163 + } 164 + } 165 + 166 + static bool is_extcon_attached(struct extcon_dev *edev, unsigned int index) 167 + { 168 + return !!(edev->state & BIT(index)); 169 + } 170 + 171 + static bool is_extcon_changed(struct extcon_dev *edev, int index, 172 + bool new_state) 173 + { 174 + int state = !!(edev->state & BIT(index)); 175 + return (state != new_state); 176 + } 177 + 178 + static bool is_extcon_property_supported(unsigned int id, unsigned int prop) 179 + { 180 + int type; 181 + 182 + /* Check whether the property is supported or not. */ 183 + type = get_extcon_type(prop); 184 + if (type < 0) 185 + return false; 186 + 187 + /* Check whether a specific extcon id supports the property or not. */ 188 + return !!(extcon_info[id].type & type); 189 + } 190 + 191 + static int is_extcon_property_capability(struct extcon_dev *edev, 192 + unsigned int id, int index,unsigned int prop) 193 + { 194 + struct extcon_cable *cable; 195 + int type, ret; 196 + 197 + /* Check whether the property is supported or not. */ 198 + type = get_extcon_type(prop); 199 + if (type < 0) 200 + return type; 201 + 202 + cable = &edev->cables[index]; 203 + 204 + switch (type) { 205 + case EXTCON_TYPE_USB: 206 + ret = test_bit(prop - EXTCON_PROP_USB_MIN, cable->usb_bits); 207 + break; 208 + case EXTCON_TYPE_CHG: 209 + ret = test_bit(prop - EXTCON_PROP_CHG_MIN, cable->chg_bits); 210 + break; 211 + case EXTCON_TYPE_JACK: 212 + ret = test_bit(prop - EXTCON_PROP_JACK_MIN, cable->jack_bits); 213 + break; 214 + case EXTCON_TYPE_DISP: 215 + ret = test_bit(prop - EXTCON_PROP_DISP_MIN, cable->disp_bits); 216 + break; 217 + default: 218 + ret = -EINVAL; 281 219 } 282 220 283 - return false; 221 + return ret; 222 + } 223 + 224 + static void init_property(struct extcon_dev *edev, unsigned int id, int index) 225 + { 226 + unsigned int type = extcon_info[id].type; 227 + struct extcon_cable *cable = &edev->cables[index]; 228 + 229 + if (EXTCON_TYPE_USB & type) 230 + memset(cable->usb_propval, 0, sizeof(cable->usb_propval)); 231 + if (EXTCON_TYPE_CHG & type) 232 + memset(cable->chg_propval, 0, sizeof(cable->chg_propval)); 233 + if (EXTCON_TYPE_JACK & type) 234 + memset(cable->jack_propval, 0, sizeof(cable->jack_propval)); 235 + if (EXTCON_TYPE_DISP & type) 236 + memset(cable->disp_propval, 0, sizeof(cable->disp_propval)); 284 237 } 285 238 286 239 static ssize_t state_show(struct device *dev, struct device_attribute *attr, ··· 373 168 374 169 for (i = 0; i < edev->max_supported; i++) { 375 170 count += sprintf(buf + count, "%s=%d\n", 376 - extcon_name[edev->supported_cable[i]], 171 + extcon_info[edev->supported_cable[i]].name, 377 172 !!(edev->state & (1 << i))); 378 173 } 379 174 380 175 return count; 381 176 } 382 - 383 - static ssize_t state_store(struct device *dev, struct device_attribute *attr, 384 - const char *buf, size_t count) 385 - { 386 - u32 state; 387 - ssize_t ret = 0; 388 - struct extcon_dev *edev = dev_get_drvdata(dev); 389 - 390 - ret = sscanf(buf, "0x%x", &state); 391 - if (ret == 0) 392 - ret = -EINVAL; 393 - else 394 - ret = extcon_set_state(edev, state); 395 - 396 - if (ret < 0) 397 - return ret; 398 - 399 - return count; 400 - } 401 - static DEVICE_ATTR_RW(state); 177 + static DEVICE_ATTR_RO(state); 402 178 403 179 static ssize_t name_show(struct device *dev, struct device_attribute *attr, 404 180 char *buf) ··· 398 212 int i = cable->cable_index; 399 213 400 214 return sprintf(buf, "%s\n", 401 - extcon_name[cable->edev->supported_cable[i]]); 215 + extcon_info[cable->edev->supported_cable[i]].name); 402 216 } 403 217 404 218 static ssize_t cable_state_show(struct device *dev, ··· 410 224 int i = cable->cable_index; 411 225 412 226 return sprintf(buf, "%d\n", 413 - extcon_get_cable_state_(cable->edev, 414 - cable->edev->supported_cable[i])); 227 + extcon_get_state(cable->edev, cable->edev->supported_cable[i])); 415 228 } 416 229 417 230 /** 418 - * extcon_update_state() - Update the cable attach states of the extcon device 419 - * only for the masked bits. 420 - * @edev: the extcon device 421 - * @mask: the bit mask to designate updated bits. 422 - * @state: new cable attach status for @edev 231 + * extcon_sync() - Synchronize the states for both the attached/detached 232 + * @edev: the extcon device that has the cable. 423 233 * 424 - * Changing the state sends uevent with environment variable containing 425 - * the name of extcon device (envp[0]) and the state output (envp[1]). 426 - * Tizen uses this format for extcon device to get events from ports. 427 - * Android uses this format as well. 428 - * 429 - * Note that the notifier provides which bits are changed in the state 430 - * variable with the val parameter (second) to the callback. 234 + * This function send a notification to synchronize the all states of a 235 + * specific external connector 431 236 */ 432 - int extcon_update_state(struct extcon_dev *edev, u32 mask, u32 state) 237 + int extcon_sync(struct extcon_dev *edev, unsigned int id) 433 238 { 434 239 char name_buf[120]; 435 240 char state_buf[120]; ··· 429 252 int env_offset = 0; 430 253 int length; 431 254 int index; 255 + int state; 432 256 unsigned long flags; 433 - bool attached; 434 - 435 - if (!edev) 436 - return -EINVAL; 437 - 438 - spin_lock_irqsave(&edev->lock, flags); 439 - 440 - if (edev->state != ((edev->state & ~mask) | (state & mask))) { 441 - u32 old_state; 442 - 443 - if (check_mutually_exclusive(edev, (edev->state & ~mask) | 444 - (state & mask))) { 445 - spin_unlock_irqrestore(&edev->lock, flags); 446 - return -EPERM; 447 - } 448 - 449 - old_state = edev->state; 450 - edev->state &= ~mask; 451 - edev->state |= state & mask; 452 - 453 - for (index = 0; index < edev->max_supported; index++) { 454 - if (is_extcon_changed(old_state, edev->state, index, 455 - &attached)) 456 - raw_notifier_call_chain(&edev->nh[index], 457 - attached, edev); 458 - } 459 - 460 - /* This could be in interrupt handler */ 461 - prop_buf = (char *)get_zeroed_page(GFP_ATOMIC); 462 - if (prop_buf) { 463 - length = name_show(&edev->dev, NULL, prop_buf); 464 - if (length > 0) { 465 - if (prop_buf[length - 1] == '\n') 466 - prop_buf[length - 1] = 0; 467 - snprintf(name_buf, sizeof(name_buf), 468 - "NAME=%s", prop_buf); 469 - envp[env_offset++] = name_buf; 470 - } 471 - length = state_show(&edev->dev, NULL, prop_buf); 472 - if (length > 0) { 473 - if (prop_buf[length - 1] == '\n') 474 - prop_buf[length - 1] = 0; 475 - snprintf(state_buf, sizeof(state_buf), 476 - "STATE=%s", prop_buf); 477 - envp[env_offset++] = state_buf; 478 - } 479 - envp[env_offset] = NULL; 480 - /* Unlock early before uevent */ 481 - spin_unlock_irqrestore(&edev->lock, flags); 482 - 483 - kobject_uevent_env(&edev->dev.kobj, KOBJ_CHANGE, envp); 484 - free_page((unsigned long)prop_buf); 485 - } else { 486 - /* Unlock early before uevent */ 487 - spin_unlock_irqrestore(&edev->lock, flags); 488 - 489 - dev_err(&edev->dev, "out of memory in extcon_set_state\n"); 490 - kobject_uevent(&edev->dev.kobj, KOBJ_CHANGE); 491 - } 492 - } else { 493 - /* No changes */ 494 - spin_unlock_irqrestore(&edev->lock, flags); 495 - } 496 - 497 - return 0; 498 - } 499 - EXPORT_SYMBOL_GPL(extcon_update_state); 500 - 501 - /** 502 - * extcon_set_state() - Set the cable attach states of the extcon device. 503 - * @edev: the extcon device 504 - * @state: new cable attach status for @edev 505 - * 506 - * Note that notifier provides which bits are changed in the state 507 - * variable with the val parameter (second) to the callback. 508 - */ 509 - int extcon_set_state(struct extcon_dev *edev, u32 state) 510 - { 511 - if (!edev) 512 - return -EINVAL; 513 - 514 - return extcon_update_state(edev, 0xffffffff, state); 515 - } 516 - EXPORT_SYMBOL_GPL(extcon_set_state); 517 - 518 - /** 519 - * extcon_get_cable_state_() - Get the status of a specific cable. 520 - * @edev: the extcon device that has the cable. 521 - * @id: the unique id of each external connector in extcon enumeration. 522 - */ 523 - int extcon_get_cable_state_(struct extcon_dev *edev, const unsigned int id) 524 - { 525 - int index; 526 257 527 258 if (!edev) 528 259 return -EINVAL; ··· 439 354 if (index < 0) 440 355 return index; 441 356 442 - if (edev->max_supported && edev->max_supported <= index) 443 - return -EINVAL; 357 + spin_lock_irqsave(&edev->lock, flags); 444 358 445 - return !!(edev->state & (1 << index)); 359 + state = !!(edev->state & BIT(index)); 360 + raw_notifier_call_chain(&edev->nh[index], state, edev); 361 + 362 + /* This could be in interrupt handler */ 363 + prop_buf = (char *)get_zeroed_page(GFP_ATOMIC); 364 + if (!prop_buf) { 365 + /* Unlock early before uevent */ 366 + spin_unlock_irqrestore(&edev->lock, flags); 367 + 368 + dev_err(&edev->dev, "out of memory in extcon_set_state\n"); 369 + kobject_uevent(&edev->dev.kobj, KOBJ_CHANGE); 370 + 371 + return 0; 372 + } 373 + 374 + length = name_show(&edev->dev, NULL, prop_buf); 375 + if (length > 0) { 376 + if (prop_buf[length - 1] == '\n') 377 + prop_buf[length - 1] = 0; 378 + snprintf(name_buf, sizeof(name_buf), "NAME=%s", prop_buf); 379 + envp[env_offset++] = name_buf; 380 + } 381 + 382 + length = state_show(&edev->dev, NULL, prop_buf); 383 + if (length > 0) { 384 + if (prop_buf[length - 1] == '\n') 385 + prop_buf[length - 1] = 0; 386 + snprintf(state_buf, sizeof(state_buf), "STATE=%s", prop_buf); 387 + envp[env_offset++] = state_buf; 388 + } 389 + envp[env_offset] = NULL; 390 + 391 + /* Unlock early before uevent */ 392 + spin_unlock_irqrestore(&edev->lock, flags); 393 + kobject_uevent_env(&edev->dev.kobj, KOBJ_CHANGE, envp); 394 + free_page((unsigned long)prop_buf); 395 + 396 + return 0; 446 397 } 447 - EXPORT_SYMBOL_GPL(extcon_get_cable_state_); 398 + EXPORT_SYMBOL_GPL(extcon_sync); 448 399 449 400 /** 450 - * extcon_set_cable_state_() - Set the status of a specific cable. 401 + * extcon_get_state() - Get the state of a external connector. 402 + * @edev: the extcon device that has the cable. 403 + * @id: the unique id of each external connector in extcon enumeration. 404 + */ 405 + int extcon_get_state(struct extcon_dev *edev, const unsigned int id) 406 + { 407 + int index, state; 408 + unsigned long flags; 409 + 410 + if (!edev) 411 + return -EINVAL; 412 + 413 + index = find_cable_index_by_id(edev, id); 414 + if (index < 0) 415 + return index; 416 + 417 + spin_lock_irqsave(&edev->lock, flags); 418 + state = is_extcon_attached(edev, index); 419 + spin_unlock_irqrestore(&edev->lock, flags); 420 + 421 + return state; 422 + } 423 + EXPORT_SYMBOL_GPL(extcon_get_state); 424 + 425 + /** 426 + * extcon_set_state() - Set the state of a external connector. 427 + * without a notification. 451 428 * @edev: the extcon device that has the cable. 452 429 * @id: the unique id of each external connector 453 430 * in extcon enumeration. 454 431 * @state: the new cable status. The default semantics is 455 432 * true: attached / false: detached. 433 + * 434 + * This function only set the state of a external connector without 435 + * a notification. To synchronize the data of a external connector, 436 + * use extcon_set_state_sync() and extcon_sync(). 456 437 */ 457 - int extcon_set_cable_state_(struct extcon_dev *edev, unsigned int id, 438 + int extcon_set_state(struct extcon_dev *edev, unsigned int id, 458 439 bool cable_state) 459 440 { 460 - u32 state; 461 - int index; 441 + unsigned long flags; 442 + int index, ret = 0; 462 443 463 444 if (!edev) 464 445 return -EINVAL; ··· 533 382 if (index < 0) 534 383 return index; 535 384 536 - if (edev->max_supported && edev->max_supported <= index) 385 + spin_lock_irqsave(&edev->lock, flags); 386 + 387 + /* Check whether the external connector's state is changed. */ 388 + if (!is_extcon_changed(edev, index, cable_state)) 389 + goto out; 390 + 391 + if (check_mutually_exclusive(edev, 392 + (edev->state & ~BIT(index)) | (cable_state & BIT(index)))) { 393 + ret = -EPERM; 394 + goto out; 395 + } 396 + 397 + /* 398 + * Initialize the value of extcon property before setting 399 + * the detached state for an external connector. 400 + */ 401 + if (!cable_state) 402 + init_property(edev, id, index); 403 + 404 + /* Update the state for a external connector. */ 405 + if (cable_state) 406 + edev->state |= BIT(index); 407 + else 408 + edev->state &= ~(BIT(index)); 409 + out: 410 + spin_unlock_irqrestore(&edev->lock, flags); 411 + 412 + return ret; 413 + } 414 + EXPORT_SYMBOL_GPL(extcon_set_state); 415 + 416 + /** 417 + * extcon_set_state_sync() - Set the state of a external connector 418 + * with a notification. 419 + * @edev: the extcon device that has the cable. 420 + * @id: the unique id of each external connector 421 + * in extcon enumeration. 422 + * @state: the new cable status. The default semantics is 423 + * true: attached / false: detached. 424 + * 425 + * This function set the state of external connector and synchronize the data 426 + * by usning a notification. 427 + */ 428 + int extcon_set_state_sync(struct extcon_dev *edev, unsigned int id, 429 + bool cable_state) 430 + { 431 + int ret, index; 432 + unsigned long flags; 433 + 434 + index = find_cable_index_by_id(edev, id); 435 + if (index < 0) 436 + return index; 437 + 438 + /* Check whether the external connector's state is changed. */ 439 + spin_lock_irqsave(&edev->lock, flags); 440 + ret = is_extcon_changed(edev, index, cable_state); 441 + spin_unlock_irqrestore(&edev->lock, flags); 442 + if (!ret) 443 + return 0; 444 + 445 + ret = extcon_set_state(edev, id, cable_state); 446 + if (ret < 0) 447 + return ret; 448 + 449 + return extcon_sync(edev, id); 450 + } 451 + EXPORT_SYMBOL_GPL(extcon_set_state_sync); 452 + 453 + /** 454 + * extcon_get_property() - Get the property value of a specific cable. 455 + * @edev: the extcon device that has the cable. 456 + * @id: the unique id of each external connector 457 + * in extcon enumeration. 458 + * @prop: the property id among enum extcon_property. 459 + * @prop_val: the pointer which store the value of property. 460 + * 461 + * When getting the property value of external connector, the external connector 462 + * should be attached. If detached state, function just return 0 without 463 + * property value. Also, the each property should be included in the list of 464 + * supported properties according to the type of external connectors. 465 + * 466 + * Returns 0 if success or error number if fail 467 + */ 468 + int extcon_get_property(struct extcon_dev *edev, unsigned int id, 469 + unsigned int prop, 470 + union extcon_property_value *prop_val) 471 + { 472 + struct extcon_cable *cable; 473 + unsigned long flags; 474 + int index, ret = 0; 475 + 476 + *prop_val = (union extcon_property_value)(0); 477 + 478 + if (!edev) 537 479 return -EINVAL; 538 480 539 - state = cable_state ? (1 << index) : 0; 540 - return extcon_update_state(edev, 1 << index, state); 481 + /* Check whether the property is supported or not */ 482 + if (!is_extcon_property_supported(id, prop)) 483 + return -EINVAL; 484 + 485 + /* Find the cable index of external connector by using id */ 486 + index = find_cable_index_by_id(edev, id); 487 + if (index < 0) 488 + return index; 489 + 490 + spin_lock_irqsave(&edev->lock, flags); 491 + 492 + /* Check whether the property is available or not. */ 493 + if (!is_extcon_property_capability(edev, id, index, prop)) { 494 + spin_unlock_irqrestore(&edev->lock, flags); 495 + return -EPERM; 496 + } 497 + 498 + /* 499 + * Check whether the external connector is attached. 500 + * If external connector is detached, the user can not 501 + * get the property value. 502 + */ 503 + if (!is_extcon_attached(edev, index)) { 504 + spin_unlock_irqrestore(&edev->lock, flags); 505 + return 0; 506 + } 507 + 508 + cable = &edev->cables[index]; 509 + 510 + /* Get the property value according to extcon type */ 511 + switch (prop) { 512 + case EXTCON_PROP_USB_MIN ... EXTCON_PROP_USB_MAX: 513 + *prop_val = cable->usb_propval[prop - EXTCON_PROP_USB_MIN]; 514 + break; 515 + case EXTCON_PROP_CHG_MIN ... EXTCON_PROP_CHG_MAX: 516 + *prop_val = cable->chg_propval[prop - EXTCON_PROP_CHG_MIN]; 517 + break; 518 + case EXTCON_PROP_JACK_MIN ... EXTCON_PROP_JACK_MAX: 519 + *prop_val = cable->jack_propval[prop - EXTCON_PROP_JACK_MIN]; 520 + break; 521 + case EXTCON_PROP_DISP_MIN ... EXTCON_PROP_DISP_MAX: 522 + *prop_val = cable->disp_propval[prop - EXTCON_PROP_DISP_MIN]; 523 + break; 524 + default: 525 + ret = -EINVAL; 526 + break; 527 + } 528 + 529 + spin_unlock_irqrestore(&edev->lock, flags); 530 + 531 + return ret; 541 532 } 542 - EXPORT_SYMBOL_GPL(extcon_set_cable_state_); 533 + EXPORT_SYMBOL_GPL(extcon_get_property); 534 + 535 + /** 536 + * extcon_set_property() - Set the property value of a specific cable. 537 + * @edev: the extcon device that has the cable. 538 + * @id: the unique id of each external connector 539 + * in extcon enumeration. 540 + * @prop: the property id among enum extcon_property. 541 + * @prop_val: the pointer including the new value of property. 542 + * 543 + * The each property should be included in the list of supported properties 544 + * according to the type of external connectors. 545 + * 546 + * Returns 0 if success or error number if fail 547 + */ 548 + int extcon_set_property(struct extcon_dev *edev, unsigned int id, 549 + unsigned int prop, 550 + union extcon_property_value prop_val) 551 + { 552 + struct extcon_cable *cable; 553 + unsigned long flags; 554 + int index, ret = 0; 555 + 556 + if (!edev) 557 + return -EINVAL; 558 + 559 + /* Check whether the property is supported or not */ 560 + if (!is_extcon_property_supported(id, prop)) 561 + return -EINVAL; 562 + 563 + /* Find the cable index of external connector by using id */ 564 + index = find_cable_index_by_id(edev, id); 565 + if (index < 0) 566 + return index; 567 + 568 + spin_lock_irqsave(&edev->lock, flags); 569 + 570 + /* Check whether the property is available or not. */ 571 + if (!is_extcon_property_capability(edev, id, index, prop)) { 572 + spin_unlock_irqrestore(&edev->lock, flags); 573 + return -EPERM; 574 + } 575 + 576 + cable = &edev->cables[index]; 577 + 578 + /* Set the property value according to extcon type */ 579 + switch (prop) { 580 + case EXTCON_PROP_USB_MIN ... EXTCON_PROP_USB_MAX: 581 + cable->usb_propval[prop - EXTCON_PROP_USB_MIN] = prop_val; 582 + break; 583 + case EXTCON_PROP_CHG_MIN ... EXTCON_PROP_CHG_MAX: 584 + cable->chg_propval[prop - EXTCON_PROP_CHG_MIN] = prop_val; 585 + break; 586 + case EXTCON_PROP_JACK_MIN ... EXTCON_PROP_JACK_MAX: 587 + cable->jack_propval[prop - EXTCON_PROP_JACK_MIN] = prop_val; 588 + break; 589 + case EXTCON_PROP_DISP_MIN ... EXTCON_PROP_DISP_MAX: 590 + cable->disp_propval[prop - EXTCON_PROP_DISP_MIN] = prop_val; 591 + break; 592 + default: 593 + ret = -EINVAL; 594 + break; 595 + } 596 + 597 + spin_unlock_irqrestore(&edev->lock, flags); 598 + 599 + return ret; 600 + } 601 + EXPORT_SYMBOL_GPL(extcon_set_property); 602 + 603 + /** 604 + * extcon_set_property_sync() - Set the property value of a specific cable 605 + with a notification. 606 + * @prop_val: the pointer including the new value of property. 607 + * 608 + * When setting the property value of external connector, the external connector 609 + * should be attached. The each property should be included in the list of 610 + * supported properties according to the type of external connectors. 611 + * 612 + * Returns 0 if success or error number if fail 613 + */ 614 + int extcon_set_property_sync(struct extcon_dev *edev, unsigned int id, 615 + unsigned int prop, 616 + union extcon_property_value prop_val) 617 + { 618 + int ret; 619 + 620 + ret = extcon_set_property(edev, id, prop, prop_val); 621 + if (ret < 0) 622 + return ret; 623 + 624 + return extcon_sync(edev, id); 625 + } 626 + EXPORT_SYMBOL_GPL(extcon_set_property_sync); 627 + 628 + /** 629 + * extcon_get_property_capability() - Get the capability of property 630 + * of an external connector. 631 + * @edev: the extcon device that has the cable. 632 + * @id: the unique id of each external connector 633 + * in extcon enumeration. 634 + * @prop: the property id among enum extcon_property. 635 + * 636 + * Returns 1 if the property is available or 0 if not available. 637 + */ 638 + int extcon_get_property_capability(struct extcon_dev *edev, unsigned int id, 639 + unsigned int prop) 640 + { 641 + int index; 642 + 643 + if (!edev) 644 + return -EINVAL; 645 + 646 + /* Check whether the property is supported or not */ 647 + if (!is_extcon_property_supported(id, prop)) 648 + return -EINVAL; 649 + 650 + /* Find the cable index of external connector by using id */ 651 + index = find_cable_index_by_id(edev, id); 652 + if (index < 0) 653 + return index; 654 + 655 + return is_extcon_property_capability(edev, id, index, prop); 656 + } 657 + EXPORT_SYMBOL_GPL(extcon_get_property_capability); 658 + 659 + /** 660 + * extcon_set_property_capability() - Set the capability of a property 661 + * of an external connector. 662 + * @edev: the extcon device that has the cable. 663 + * @id: the unique id of each external connector 664 + * in extcon enumeration. 665 + * @prop: the property id among enum extcon_property. 666 + * 667 + * This function set the capability of a property for an external connector 668 + * to mark the bit in capability bitmap which mean the available state of 669 + * a property. 670 + * 671 + * Returns 0 if success or error number if fail 672 + */ 673 + int extcon_set_property_capability(struct extcon_dev *edev, unsigned int id, 674 + unsigned int prop) 675 + { 676 + struct extcon_cable *cable; 677 + int index, type, ret = 0; 678 + 679 + if (!edev) 680 + return -EINVAL; 681 + 682 + /* Check whether the property is supported or not. */ 683 + if (!is_extcon_property_supported(id, prop)) 684 + return -EINVAL; 685 + 686 + /* Find the cable index of external connector by using id. */ 687 + index = find_cable_index_by_id(edev, id); 688 + if (index < 0) 689 + return index; 690 + 691 + type = get_extcon_type(prop); 692 + if (type < 0) 693 + return type; 694 + 695 + cable = &edev->cables[index]; 696 + 697 + switch (type) { 698 + case EXTCON_TYPE_USB: 699 + __set_bit(prop - EXTCON_PROP_USB_MIN, cable->usb_bits); 700 + break; 701 + case EXTCON_TYPE_CHG: 702 + __set_bit(prop - EXTCON_PROP_CHG_MIN, cable->chg_bits); 703 + break; 704 + case EXTCON_TYPE_JACK: 705 + __set_bit(prop - EXTCON_PROP_JACK_MIN, cable->jack_bits); 706 + break; 707 + case EXTCON_TYPE_DISP: 708 + __set_bit(prop - EXTCON_PROP_DISP_MIN, cable->disp_bits); 709 + break; 710 + default: 711 + ret = -EINVAL; 712 + } 713 + 714 + return ret; 715 + } 716 + EXPORT_SYMBOL_GPL(extcon_set_property_capability); 543 717 544 718 /** 545 719 * extcon_get_extcon_dev() - Get the extcon device instance from the name ··· 904 428 struct notifier_block *nb) 905 429 { 906 430 unsigned long flags; 907 - int ret, idx; 431 + int ret, idx = -EINVAL; 908 432 909 433 if (!nb) 910 434 return -EINVAL; ··· 1322 846 return ERR_PTR(-EINVAL); 1323 847 1324 848 if (!dev->of_node) { 1325 - dev_err(dev, "device does not have a device node entry\n"); 849 + dev_dbg(dev, "device does not have a device node entry\n"); 1326 850 return ERR_PTR(-EINVAL); 1327 851 } 1328 852 1329 853 node = of_parse_phandle(dev->of_node, "extcon", index); 1330 854 if (!node) { 1331 - dev_err(dev, "failed to get phandle in %s node\n", 855 + dev_dbg(dev, "failed to get phandle in %s node\n", 1332 856 dev->of_node->full_name); 1333 857 return ERR_PTR(-ENODEV); 1334 858 }
-1
drivers/media/dvb-frontends/rtl2832_sdr.c
··· 392 392 dev_dbg(&pdev->dev, "alloc urb=%d\n", i); 393 393 dev->urb_list[i] = usb_alloc_urb(0, GFP_ATOMIC); 394 394 if (!dev->urb_list[i]) { 395 - dev_dbg(&pdev->dev, "failed\n"); 396 395 for (j = 0; j < i; j++) 397 396 usb_free_urb(dev->urb_list[j]); 398 397 return -ENOMEM;
-1
drivers/media/radio/si470x/radio-si470x-usb.c
··· 627 627 628 628 radio->int_in_urb = usb_alloc_urb(0, GFP_KERNEL); 629 629 if (!radio->int_in_urb) { 630 - dev_info(&intf->dev, "could not allocate int_in_urb"); 631 630 retval = -ENOMEM; 632 631 goto err_intbuffer; 633 632 }
+3 -10
drivers/media/rc/imon.c
··· 2211 2211 goto exit; 2212 2212 } 2213 2213 rx_urb = usb_alloc_urb(0, GFP_KERNEL); 2214 - if (!rx_urb) { 2215 - dev_err(dev, "%s: usb_alloc_urb failed for IR urb", __func__); 2214 + if (!rx_urb) 2216 2215 goto rx_urb_alloc_failed; 2217 - } 2218 2216 tx_urb = usb_alloc_urb(0, GFP_KERNEL); 2219 - if (!tx_urb) { 2220 - dev_err(dev, "%s: usb_alloc_urb failed for display urb", 2221 - __func__); 2217 + if (!tx_urb) 2222 2218 goto tx_urb_alloc_failed; 2223 - } 2224 2219 2225 2220 mutex_init(&ictx->lock); 2226 2221 spin_lock_init(&ictx->kc_lock); ··· 2300 2305 int ret = -ENOMEM; 2301 2306 2302 2307 rx_urb = usb_alloc_urb(0, GFP_KERNEL); 2303 - if (!rx_urb) { 2304 - pr_err("usb_alloc_urb failed for IR urb\n"); 2308 + if (!rx_urb) 2305 2309 goto rx_urb_alloc_failed; 2306 - } 2307 2310 2308 2311 mutex_lock(&ictx->lock); 2309 2312
+1 -3
drivers/media/rc/redrat3.c
··· 970 970 971 971 /* set up bulk-in endpoint */ 972 972 rr3->read_urb = usb_alloc_urb(0, GFP_KERNEL); 973 - if (!rr3->read_urb) { 974 - dev_err(dev, "Read urb allocation failure\n"); 973 + if (!rr3->read_urb) 975 974 goto error; 976 - } 977 975 978 976 rr3->ep_in = ep_in; 979 977 rr3->bulk_in_buf = usb_alloc_coherent(udev,
-1
drivers/media/usb/airspy/airspy.c
··· 426 426 dev_dbg(s->dev, "alloc urb=%d\n", i); 427 427 s->urb_list[i] = usb_alloc_urb(0, GFP_ATOMIC); 428 428 if (!s->urb_list[i]) { 429 - dev_dbg(s->dev, "failed\n"); 430 429 for (j = 0; j < i; j++) 431 430 usb_free_urb(s->urb_list[j]); 432 431 return -ENOMEM;
-2
drivers/media/usb/as102/as102_usb_drv.c
··· 270 270 271 271 urb = usb_alloc_urb(0, GFP_ATOMIC); 272 272 if (urb == NULL) { 273 - dev_dbg(&dev->bus_adap.usb_dev->dev, 274 - "%s: usb_alloc_urb failed\n", __func__); 275 273 as102_free_usb_stream_buffer(dev); 276 274 return -ENOMEM; 277 275 }
-1
drivers/media/usb/au0828/au0828-video.c
··· 245 245 for (i = 0; i < dev->isoc_ctl.num_bufs; i++) { 246 246 urb = usb_alloc_urb(max_packets, GFP_KERNEL); 247 247 if (!urb) { 248 - au0828_isocdbg("cannot alloc isoc_ctl.urb %i\n", i); 249 248 au0828_uninit_isoc(dev); 250 249 return -ENOMEM; 251 250 }
-1
drivers/media/usb/cpia2/cpia2_usb.c
··· 662 662 } 663 663 urb = usb_alloc_urb(FRAMES_PER_DESC, GFP_KERNEL); 664 664 if (!urb) { 665 - ERR("%s: usb_alloc_urb error!\n", __func__); 666 665 for (j = 0; j < i; j++) 667 666 usb_free_urb(cam->sbuf[j].urb); 668 667 return -ENOMEM;
-2
drivers/media/usb/cx231xx/cx231xx-audio.c
··· 293 293 memset(dev->adev.transfer_buffer[i], 0x80, sb_size); 294 294 urb = usb_alloc_urb(CX231XX_ISO_NUM_AUDIO_PACKETS, GFP_ATOMIC); 295 295 if (!urb) { 296 - dev_err(dev->dev, "usb_alloc_urb failed!\n"); 297 296 for (j = 0; j < i; j++) { 298 297 usb_free_urb(dev->adev.urb[j]); 299 298 kfree(dev->adev.transfer_buffer[j]); ··· 354 355 memset(dev->adev.transfer_buffer[i], 0x80, sb_size); 355 356 urb = usb_alloc_urb(CX231XX_NUM_AUDIO_PACKETS, GFP_ATOMIC); 356 357 if (!urb) { 357 - dev_err(dev->dev, "usb_alloc_urb failed!\n"); 358 358 for (j = 0; j < i; j++) { 359 359 usb_free_urb(dev->adev.urb[j]); 360 360 kfree(dev->adev.transfer_buffer[j]);
-4
drivers/media/usb/cx231xx/cx231xx-core.c
··· 1035 1035 for (i = 0; i < dev->video_mode.isoc_ctl.num_bufs; i++) { 1036 1036 urb = usb_alloc_urb(max_packets, GFP_KERNEL); 1037 1037 if (!urb) { 1038 - dev_err(dev->dev, 1039 - "cannot alloc isoc_ctl.urb %i\n", i); 1040 1038 cx231xx_uninit_isoc(dev); 1041 1039 return -ENOMEM; 1042 1040 } ··· 1170 1172 for (i = 0; i < dev->video_mode.bulk_ctl.num_bufs; i++) { 1171 1173 urb = usb_alloc_urb(0, GFP_KERNEL); 1172 1174 if (!urb) { 1173 - dev_err(dev->dev, 1174 - "cannot alloc bulk_ctl.urb %i\n", i); 1175 1175 cx231xx_uninit_bulk(dev); 1176 1176 return -ENOMEM; 1177 1177 }
-2
drivers/media/usb/cx231xx/cx231xx-vbi.c
··· 442 442 443 443 urb = usb_alloc_urb(0, GFP_KERNEL); 444 444 if (!urb) { 445 - dev_err(dev->dev, 446 - "cannot alloc bulk_ctl.urb %i\n", i); 447 445 cx231xx_uninit_vbi_isoc(dev); 448 446 return -ENOMEM; 449 447 }
+1 -3
drivers/media/usb/dvb-usb/dib0700_core.c
··· 783 783 /* Starting in firmware 1.20, the RC info is provided on a bulk pipe */ 784 784 785 785 purb = usb_alloc_urb(0, GFP_KERNEL); 786 - if (purb == NULL) { 787 - err("rc usb alloc urb failed"); 786 + if (purb == NULL) 788 787 return -ENOMEM; 789 - } 790 788 791 789 purb->transfer_buffer = kzalloc(RC_MSG_SIZE_V1_20, GFP_KERNEL); 792 790 if (purb->transfer_buffer == NULL) {
-1
drivers/media/usb/em28xx/em28xx-audio.c
··· 850 850 851 851 urb = usb_alloc_urb(npackets, GFP_ATOMIC); 852 852 if (!urb) { 853 - em28xx_errdev("usb_alloc_urb failed!\n"); 854 853 em28xx_audio_free_urb(dev); 855 854 return -ENOMEM; 856 855 }
-1
drivers/media/usb/em28xx/em28xx-core.c
··· 934 934 for (i = 0; i < usb_bufs->num_bufs; i++) { 935 935 urb = usb_alloc_urb(usb_bufs->num_packets, GFP_KERNEL); 936 936 if (!urb) { 937 - em28xx_err("cannot alloc usb_ctl.urb %i\n", i); 938 937 em28xx_uninit_usb_xfer(dev, mode); 939 938 return -ENOMEM; 940 939 }
+1 -3
drivers/media/usb/gspca/benq.c
··· 95 95 #define SD_NPKT 32 96 96 for (n = 0; n < 4; n++) { 97 97 urb = usb_alloc_urb(SD_NPKT, GFP_KERNEL); 98 - if (!urb) { 99 - pr_err("usb_alloc_urb failed\n"); 98 + if (!urb) 100 99 return -ENOMEM; 101 - } 102 100 gspca_dev->urb[n] = urb; 103 101 urb->transfer_buffer = usb_alloc_coherent(gspca_dev->dev, 104 102 SD_PKT_SZ * SD_NPKT,
+1 -3
drivers/media/usb/gspca/gspca.c
··· 795 795 796 796 for (n = 0; n < nurbs; n++) { 797 797 urb = usb_alloc_urb(npkt, GFP_KERNEL); 798 - if (!urb) { 799 - pr_err("usb_alloc_urb failed\n"); 798 + if (!urb) 800 799 return -ENOMEM; 801 - } 802 800 gspca_dev->urb[n] = urb; 803 801 urb->transfer_buffer = usb_alloc_coherent(gspca_dev->dev, 804 802 bsize,
+1 -3
drivers/media/usb/gspca/konica.c
··· 208 208 packet_size = 209 209 le16_to_cpu(alt->endpoint[i].desc.wMaxPacketSize); 210 210 urb = usb_alloc_urb(SD_NPKT, GFP_KERNEL); 211 - if (!urb) { 212 - pr_err("usb_alloc_urb failed\n"); 211 + if (!urb) 213 212 return -ENOMEM; 214 - } 215 213 gspca_dev->urb[n] = urb; 216 214 urb->transfer_buffer = usb_alloc_coherent(gspca_dev->dev, 217 215 packet_size * SD_NPKT,
-1
drivers/media/usb/hackrf/hackrf.c
··· 691 691 dev_dbg(dev->dev, "alloc urb=%d\n", i); 692 692 dev->urb_list[i] = usb_alloc_urb(0, GFP_ATOMIC); 693 693 if (!dev->urb_list[i]) { 694 - dev_dbg(dev->dev, "failed\n"); 695 694 for (j = 0; j < i; j++) 696 695 usb_free_urb(dev->urb_list[j]); 697 696 return -ENOMEM;
+1 -3
drivers/media/usb/hdpvr/hdpvr-video.c
··· 155 155 buf->dev = dev; 156 156 157 157 urb = usb_alloc_urb(0, GFP_KERNEL); 158 - if (!urb) { 159 - v4l2_err(&dev->v4l2_dev, "cannot allocate urb\n"); 158 + if (!urb) 160 159 goto exit_urb; 161 - } 162 160 buf->urb = urb; 163 161 164 162 mem = usb_alloc_coherent(dev->udev, dev->bulk_in_size, GFP_KERNEL,
-1
drivers/media/usb/msi2500/msi2500.c
··· 509 509 for (i = 0; i < MAX_ISO_BUFS; i++) { 510 510 urb = usb_alloc_urb(ISO_FRAMES_PER_DESC, GFP_KERNEL); 511 511 if (urb == NULL) { 512 - dev_err(dev->dev, "Failed to allocate urb %d\n", i); 513 512 msi2500_isoc_cleanup(dev); 514 513 return -ENOMEM; 515 514 }
-1
drivers/media/usb/pwc/pwc-if.c
··· 410 410 for (i = 0; i < MAX_ISO_BUFS; i++) { 411 411 urb = usb_alloc_urb(ISO_FRAMES_PER_DESC, GFP_KERNEL); 412 412 if (urb == NULL) { 413 - PWC_ERROR("Failed to allocate urb %d\n", i); 414 413 pwc_isoc_cleanup(pdev); 415 414 return -ENOMEM; 416 415 }
+2 -7
drivers/media/usb/s2255/s2255drv.c
··· 2113 2113 pipe_info->state = 1; 2114 2114 pipe_info->err_count = 0; 2115 2115 pipe_info->stream_urb = usb_alloc_urb(0, GFP_KERNEL); 2116 - if (!pipe_info->stream_urb) { 2117 - dev_err(&dev->udev->dev, 2118 - "ReadStream: Unable to alloc URB\n"); 2116 + if (!pipe_info->stream_urb) 2119 2117 return -ENOMEM; 2120 - } 2121 2118 /* transfer buffer allocated in board_init */ 2122 2119 usb_fill_bulk_urb(pipe_info->stream_urb, dev->udev, 2123 2120 pipe, ··· 2287 2290 } 2288 2291 2289 2292 dev->fw_data->fw_urb = usb_alloc_urb(0, GFP_KERNEL); 2290 - if (!dev->fw_data->fw_urb) { 2291 - dev_err(&interface->dev, "out of memory!\n"); 2293 + if (!dev->fw_data->fw_urb) 2292 2294 goto errorFWURB; 2293 - } 2294 2295 2295 2296 dev->fw_data->pfw_data = kzalloc(CHUNK_SIZE, GFP_KERNEL); 2296 2297 if (!dev->fw_data->pfw_data) {
+1 -3
drivers/media/usb/stk1160/stk1160-video.c
··· 457 457 for (i = 0; i < num_bufs; i++) { 458 458 459 459 urb = usb_alloc_urb(max_packets, GFP_KERNEL); 460 - if (!urb) { 461 - stk1160_err("cannot alloc urb[%d]\n", i); 460 + if (!urb) 462 461 goto free_i_bufs; 463 - } 464 462 dev->isoc_ctl.urb[i] = urb; 465 463 466 464 #ifndef CONFIG_DMA_NONCOHERENT
+1 -3
drivers/media/usb/stkwebcam/stk-webcam.c
··· 452 452 STK_ERROR("isobuf data already allocated\n"); 453 453 if (dev->isobufs[i].urb == NULL) { 454 454 urb = usb_alloc_urb(ISO_FRAMES_PER_DESC, GFP_KERNEL); 455 - if (urb == NULL) { 456 - STK_ERROR("Failed to allocate URB %d\n", i); 455 + if (urb == NULL) 457 456 goto isobufs_out; 458 - } 459 457 dev->isobufs[i].urb = urb; 460 458 } else { 461 459 STK_ERROR("Killing URB\n");
+1 -3
drivers/media/usb/tm6000/tm6000-dvb.c
··· 129 129 } 130 130 131 131 dvb->bulk_urb = usb_alloc_urb(0, GFP_KERNEL); 132 - if (dvb->bulk_urb == NULL) { 133 - printk(KERN_ERR "tm6000: couldn't allocate urb\n"); 132 + if (dvb->bulk_urb == NULL) 134 133 return -ENOMEM; 135 - } 136 134 137 135 pipe = usb_rcvbulkpipe(dev->udev, dev->bulk_in.endp->desc.bEndpointAddress 138 136 & USB_ENDPOINT_NUMBER_MASK);
-1
drivers/media/usb/tm6000/tm6000-video.c
··· 635 635 for (i = 0; i < dev->isoc_ctl.num_bufs; i++) { 636 636 urb = usb_alloc_urb(max_packets, GFP_KERNEL); 637 637 if (!urb) { 638 - tm6000_err("cannot alloc isoc_ctl.urb %i\n", i); 639 638 tm6000_uninit_isoc(dev); 640 639 usb_free_urb(urb); 641 640 return -ENOMEM;
+1 -4
drivers/media/usb/usbvision/usbvision-core.c
··· 2303 2303 struct urb *urb; 2304 2304 2305 2305 urb = usb_alloc_urb(USBVISION_URB_FRAMES, GFP_KERNEL); 2306 - if (urb == NULL) { 2307 - dev_err(&usbvision->dev->dev, 2308 - "%s: usb_alloc_urb() failed\n", __func__); 2306 + if (urb == NULL) 2309 2307 return -ENOMEM; 2310 - } 2311 2308 usbvision->sbuf[buf_idx].urb = urb; 2312 2309 usbvision->sbuf[buf_idx].data = 2313 2310 usb_alloc_coherent(usbvision->dev,
+1 -3
drivers/media/usb/zr364xx/zr364xx.c
··· 1045 1045 pipe_info->state = 1; 1046 1046 pipe_info->err_count = 0; 1047 1047 pipe_info->stream_urb = usb_alloc_urb(0, GFP_KERNEL); 1048 - if (!pipe_info->stream_urb) { 1049 - dev_err(&cam->udev->dev, "ReadStream: Unable to alloc URB\n"); 1048 + if (!pipe_info->stream_urb) 1050 1049 return -ENOMEM; 1051 - } 1052 1050 /* transfer buffer allocated in board_init */ 1053 1051 usb_fill_bulk_urb(pipe_info->stream_urb, cam->udev, 1054 1052 pipe,
-2
drivers/mmc/host/vub300.c
··· 2116 2116 command_out_urb = usb_alloc_urb(0, GFP_KERNEL); 2117 2117 if (!command_out_urb) { 2118 2118 retval = -ENOMEM; 2119 - dev_err(&udev->dev, "not enough memory for command_out_urb\n"); 2120 2119 goto error0; 2121 2120 } 2122 2121 command_res_urb = usb_alloc_urb(0, GFP_KERNEL); 2123 2122 if (!command_res_urb) { 2124 2123 retval = -ENOMEM; 2125 - dev_err(&udev->dev, "not enough memory for command_res_urb\n"); 2126 2124 goto error1; 2127 2125 } 2128 2126 /* this also allocates memory for our VUB300 mmc host device */
+36
drivers/phy/Kconfig
··· 24 24 Enable this to support Broadcom USB 2.0 PHY connected to the USB 25 25 controller on Northstar family. 26 26 27 + config PHY_BCM_NS_USB3 28 + tristate "Broadcom Northstar USB 3.0 PHY Driver" 29 + depends on ARCH_BCM_IPROC || COMPILE_TEST 30 + depends on HAS_IOMEM && OF 31 + select GENERIC_PHY 32 + help 33 + Enable this to support Broadcom USB 3.0 PHY connected to the USB 34 + controller on Northstar family. 35 + 27 36 config PHY_BERLIN_USB 28 37 tristate "Marvell Berlin USB PHY Driver" 29 38 depends on ARCH_BERLIN && RESET_CONTROLLER && HAS_IOMEM && OF ··· 267 258 depends on RESET_CONTROLLER 268 259 depends on EXTCON 269 260 depends on POWER_SUPPLY 261 + depends on USB_SUPPORT 270 262 select GENERIC_PHY 263 + select USB_COMMON 271 264 help 272 265 Enable this to support the transceiver that is part of Allwinner 273 266 sunxi SoCs. ··· 369 358 help 370 359 Enable this to support the Rockchip USB 2.0 PHY. 371 360 361 + config PHY_ROCKCHIP_INNO_USB2 362 + tristate "Rockchip INNO USB2PHY Driver" 363 + depends on (ARCH_ROCKCHIP || COMPILE_TEST) && OF 364 + depends on COMMON_CLK 365 + select GENERIC_PHY 366 + help 367 + Support for Rockchip USB2.0 PHY with Innosilicon IP block. 368 + 372 369 config PHY_ROCKCHIP_EMMC 373 370 tristate "Rockchip EMMC PHY Driver" 374 371 depends on ARCH_ROCKCHIP && OF ··· 390 371 select GENERIC_PHY 391 372 help 392 373 Enable this to support the Rockchip Display Port PHY. 374 + 375 + config PHY_ROCKCHIP_PCIE 376 + tristate "Rockchip PCIe PHY Driver" 377 + depends on (ARCH_ROCKCHIP && OF) || COMPILE_TEST 378 + select GENERIC_PHY 379 + select MFD_SYSCON 380 + help 381 + Enable this to support the Rockchip PCIe PHY. 382 + 383 + config PHY_ROCKCHIP_TYPEC 384 + tristate "Rockchip TYPEC PHY Driver" 385 + depends on OF && (ARCH_ROCKCHIP || COMPILE_TEST) 386 + select EXTCON 387 + select GENERIC_PHY 388 + select RESET_CONTROLLER 389 + help 390 + Enable this to support the Rockchip USB TYPEC PHY. 393 391 394 392 config PHY_ST_SPEAR1310_MIPHY 395 393 tristate "ST SPEAR1310-MIPHY driver"
+4
drivers/phy/Makefile
··· 4 4 5 5 obj-$(CONFIG_GENERIC_PHY) += phy-core.o 6 6 obj-$(CONFIG_PHY_BCM_NS_USB2) += phy-bcm-ns-usb2.o 7 + obj-$(CONFIG_PHY_BCM_NS_USB3) += phy-bcm-ns-usb3.o 7 8 obj-$(CONFIG_PHY_BERLIN_USB) += phy-berlin-usb.o 8 9 obj-$(CONFIG_PHY_BERLIN_SATA) += phy-berlin-sata.o 9 10 obj-$(CONFIG_PHY_DA8XX_USB) += phy-da8xx-usb.o ··· 40 39 obj-$(CONFIG_PHY_EXYNOS5_USBDRD) += phy-exynos5-usbdrd.o 41 40 obj-$(CONFIG_PHY_QCOM_APQ8064_SATA) += phy-qcom-apq8064-sata.o 42 41 obj-$(CONFIG_PHY_ROCKCHIP_USB) += phy-rockchip-usb.o 42 + obj-$(CONFIG_PHY_ROCKCHIP_INNO_USB2) += phy-rockchip-inno-usb2.o 43 43 obj-$(CONFIG_PHY_ROCKCHIP_EMMC) += phy-rockchip-emmc.o 44 + obj-$(CONFIG_PHY_ROCKCHIP_PCIE) += phy-rockchip-pcie.o 44 45 obj-$(CONFIG_PHY_ROCKCHIP_DP) += phy-rockchip-dp.o 46 + obj-$(CONFIG_PHY_ROCKCHIP_TYPEC) += phy-rockchip-typec.o 45 47 obj-$(CONFIG_PHY_QCOM_IPQ806X_SATA) += phy-qcom-ipq806x-sata.o 46 48 obj-$(CONFIG_PHY_ST_SPEAR1310_MIPHY) += phy-spear1310-miphy.o 47 49 obj-$(CONFIG_PHY_ST_SPEAR1340_MIPHY) += phy-spear1340-miphy.o
+274
drivers/phy/phy-bcm-ns-usb3.c
··· 1 + /* 2 + * Broadcom Northstar USB 3.0 PHY Driver 3 + * 4 + * Copyright (C) 2016 Rafał Miłecki <rafal@milecki.pl> 5 + * 6 + * All magic values used for initialization (and related comments) were obtained 7 + * from Broadcom's SDK: 8 + * Copyright (c) Broadcom Corp, 2012 9 + * 10 + * This program is free software; you can redistribute it and/or modify 11 + * it under the terms of the GNU General Public License version 2 as 12 + * published by the Free Software Foundation. 13 + */ 14 + 15 + #include <linux/bcma/bcma.h> 16 + #include <linux/delay.h> 17 + #include <linux/err.h> 18 + #include <linux/module.h> 19 + #include <linux/of_platform.h> 20 + #include <linux/platform_device.h> 21 + #include <linux/phy/phy.h> 22 + #include <linux/slab.h> 23 + 24 + #define BCM_NS_USB3_MII_MNG_TIMEOUT_US 1000 /* usecs */ 25 + 26 + enum bcm_ns_family { 27 + BCM_NS_UNKNOWN, 28 + BCM_NS_AX, 29 + BCM_NS_BX, 30 + }; 31 + 32 + struct bcm_ns_usb3 { 33 + struct device *dev; 34 + enum bcm_ns_family family; 35 + void __iomem *dmp; 36 + void __iomem *ccb_mii; 37 + struct phy *phy; 38 + }; 39 + 40 + static const struct of_device_id bcm_ns_usb3_id_table[] = { 41 + { 42 + .compatible = "brcm,ns-ax-usb3-phy", 43 + .data = (int *)BCM_NS_AX, 44 + }, 45 + { 46 + .compatible = "brcm,ns-bx-usb3-phy", 47 + .data = (int *)BCM_NS_BX, 48 + }, 49 + {}, 50 + }; 51 + MODULE_DEVICE_TABLE(of, bcm_ns_usb3_id_table); 52 + 53 + static int bcm_ns_usb3_wait_reg(struct bcm_ns_usb3 *usb3, void __iomem *addr, 54 + u32 mask, u32 value, unsigned long timeout) 55 + { 56 + unsigned long deadline = jiffies + timeout; 57 + u32 val; 58 + 59 + do { 60 + val = readl(addr); 61 + if ((val & mask) == value) 62 + return 0; 63 + cpu_relax(); 64 + udelay(10); 65 + } while (!time_after_eq(jiffies, deadline)); 66 + 67 + dev_err(usb3->dev, "Timeout waiting for register %p\n", addr); 68 + 69 + return -EBUSY; 70 + } 71 + 72 + static inline int bcm_ns_usb3_mii_mng_wait_idle(struct bcm_ns_usb3 *usb3) 73 + { 74 + return bcm_ns_usb3_wait_reg(usb3, usb3->ccb_mii + BCMA_CCB_MII_MNG_CTL, 75 + 0x0100, 0x0000, 76 + usecs_to_jiffies(BCM_NS_USB3_MII_MNG_TIMEOUT_US)); 77 + } 78 + 79 + static int bcm_ns_usb3_mii_mng_write32(struct bcm_ns_usb3 *usb3, u32 value) 80 + { 81 + int err; 82 + 83 + err = bcm_ns_usb3_mii_mng_wait_idle(usb3); 84 + if (err < 0) { 85 + dev_err(usb3->dev, "Couldn't write 0x%08x value\n", value); 86 + return err; 87 + } 88 + 89 + writel(value, usb3->ccb_mii + BCMA_CCB_MII_MNG_CMD_DATA); 90 + 91 + return 0; 92 + } 93 + 94 + static int bcm_ns_usb3_phy_init_ns_bx(struct bcm_ns_usb3 *usb3) 95 + { 96 + int err; 97 + 98 + /* Enable MDIO. Setting MDCDIV as 26 */ 99 + writel(0x0000009a, usb3->ccb_mii + BCMA_CCB_MII_MNG_CTL); 100 + 101 + /* Wait for MDIO? */ 102 + udelay(2); 103 + 104 + /* USB3 PLL Block */ 105 + err = bcm_ns_usb3_mii_mng_write32(usb3, 0x587e8000); 106 + if (err < 0) 107 + return err; 108 + 109 + /* Assert Ana_Pllseq start */ 110 + bcm_ns_usb3_mii_mng_write32(usb3, 0x58061000); 111 + 112 + /* Assert CML Divider ratio to 26 */ 113 + bcm_ns_usb3_mii_mng_write32(usb3, 0x582a6400); 114 + 115 + /* Asserting PLL Reset */ 116 + bcm_ns_usb3_mii_mng_write32(usb3, 0x582ec000); 117 + 118 + /* Deaaserting PLL Reset */ 119 + bcm_ns_usb3_mii_mng_write32(usb3, 0x582e8000); 120 + 121 + /* Waiting MII Mgt interface idle */ 122 + bcm_ns_usb3_mii_mng_wait_idle(usb3); 123 + 124 + /* Deasserting USB3 system reset */ 125 + writel(0, usb3->dmp + BCMA_RESET_CTL); 126 + 127 + /* PLL frequency monitor enable */ 128 + bcm_ns_usb3_mii_mng_write32(usb3, 0x58069000); 129 + 130 + /* PIPE Block */ 131 + bcm_ns_usb3_mii_mng_write32(usb3, 0x587e8060); 132 + 133 + /* CMPMAX & CMPMINTH setting */ 134 + bcm_ns_usb3_mii_mng_write32(usb3, 0x580af30d); 135 + 136 + /* DEGLITCH MIN & MAX setting */ 137 + bcm_ns_usb3_mii_mng_write32(usb3, 0x580e6302); 138 + 139 + /* TXPMD block */ 140 + bcm_ns_usb3_mii_mng_write32(usb3, 0x587e8040); 141 + 142 + /* Enabling SSC */ 143 + bcm_ns_usb3_mii_mng_write32(usb3, 0x58061003); 144 + 145 + /* Waiting MII Mgt interface idle */ 146 + bcm_ns_usb3_mii_mng_wait_idle(usb3); 147 + 148 + return 0; 149 + } 150 + 151 + static int bcm_ns_usb3_phy_init_ns_ax(struct bcm_ns_usb3 *usb3) 152 + { 153 + int err; 154 + 155 + /* Enable MDIO. Setting MDCDIV as 26 */ 156 + writel(0x0000009a, usb3->ccb_mii + BCMA_CCB_MII_MNG_CTL); 157 + 158 + /* Wait for MDIO? */ 159 + udelay(2); 160 + 161 + /* PLL30 block */ 162 + err = bcm_ns_usb3_mii_mng_write32(usb3, 0x587e8000); 163 + if (err < 0) 164 + return err; 165 + 166 + bcm_ns_usb3_mii_mng_write32(usb3, 0x582a6400); 167 + 168 + bcm_ns_usb3_mii_mng_write32(usb3, 0x587e80e0); 169 + 170 + bcm_ns_usb3_mii_mng_write32(usb3, 0x580a009c); 171 + 172 + /* Enable SSC */ 173 + bcm_ns_usb3_mii_mng_write32(usb3, 0x587e8040); 174 + 175 + bcm_ns_usb3_mii_mng_write32(usb3, 0x580a21d3); 176 + 177 + bcm_ns_usb3_mii_mng_write32(usb3, 0x58061003); 178 + 179 + /* Waiting MII Mgt interface idle */ 180 + bcm_ns_usb3_mii_mng_wait_idle(usb3); 181 + 182 + /* Deasserting USB3 system reset */ 183 + writel(0, usb3->dmp + BCMA_RESET_CTL); 184 + 185 + return 0; 186 + } 187 + 188 + static int bcm_ns_usb3_phy_init(struct phy *phy) 189 + { 190 + struct bcm_ns_usb3 *usb3 = phy_get_drvdata(phy); 191 + int err; 192 + 193 + /* Perform USB3 system soft reset */ 194 + writel(BCMA_RESET_CTL_RESET, usb3->dmp + BCMA_RESET_CTL); 195 + 196 + switch (usb3->family) { 197 + case BCM_NS_AX: 198 + err = bcm_ns_usb3_phy_init_ns_ax(usb3); 199 + break; 200 + case BCM_NS_BX: 201 + err = bcm_ns_usb3_phy_init_ns_bx(usb3); 202 + break; 203 + default: 204 + WARN_ON(1); 205 + err = -ENOTSUPP; 206 + } 207 + 208 + return err; 209 + } 210 + 211 + static const struct phy_ops ops = { 212 + .init = bcm_ns_usb3_phy_init, 213 + .owner = THIS_MODULE, 214 + }; 215 + 216 + static int bcm_ns_usb3_probe(struct platform_device *pdev) 217 + { 218 + struct device *dev = &pdev->dev; 219 + const struct of_device_id *of_id; 220 + struct bcm_ns_usb3 *usb3; 221 + struct resource *res; 222 + struct phy_provider *phy_provider; 223 + 224 + usb3 = devm_kzalloc(dev, sizeof(*usb3), GFP_KERNEL); 225 + if (!usb3) 226 + return -ENOMEM; 227 + 228 + usb3->dev = dev; 229 + 230 + of_id = of_match_device(bcm_ns_usb3_id_table, dev); 231 + if (!of_id) 232 + return -EINVAL; 233 + usb3->family = (enum bcm_ns_family)of_id->data; 234 + 235 + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dmp"); 236 + usb3->dmp = devm_ioremap_resource(dev, res); 237 + if (IS_ERR(usb3->dmp)) { 238 + dev_err(dev, "Failed to map DMP regs\n"); 239 + return PTR_ERR(usb3->dmp); 240 + } 241 + 242 + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "ccb-mii"); 243 + usb3->ccb_mii = devm_ioremap_resource(dev, res); 244 + if (IS_ERR(usb3->ccb_mii)) { 245 + dev_err(dev, "Failed to map ChipCommon B MII regs\n"); 246 + return PTR_ERR(usb3->ccb_mii); 247 + } 248 + 249 + usb3->phy = devm_phy_create(dev, NULL, &ops); 250 + if (IS_ERR(usb3->phy)) { 251 + dev_err(dev, "Failed to create PHY\n"); 252 + return PTR_ERR(usb3->phy); 253 + } 254 + 255 + phy_set_drvdata(usb3->phy, usb3); 256 + platform_set_drvdata(pdev, usb3); 257 + 258 + phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate); 259 + if (!IS_ERR(phy_provider)) 260 + dev_info(dev, "Registered Broadcom Northstar USB 3.0 PHY driver\n"); 261 + 262 + return PTR_ERR_OR_ZERO(phy_provider); 263 + } 264 + 265 + static struct platform_driver bcm_ns_usb3_driver = { 266 + .probe = bcm_ns_usb3_probe, 267 + .driver = { 268 + .name = "bcm_ns_usb3", 269 + .of_match_table = bcm_ns_usb3_id_table, 270 + }, 271 + }; 272 + module_platform_driver(bcm_ns_usb3_driver); 273 + 274 + MODULE_LICENSE("GPL v2");
+7 -21
drivers/phy/phy-bcm-ns2-pcie.c
··· 18 18 #include <linux/phy.h> 19 19 #include <linux/phy/phy.h> 20 20 21 - struct ns2_pci_phy { 22 - struct mdio_device *mdiodev; 23 - struct phy *phy; 24 - }; 25 - 26 21 #define BLK_ADDR_REG_OFFSET 0x1f 27 22 #define PLL_AFE1_100MHZ_BLK 0x2100 28 23 #define PLL_CLK_AMP_OFFSET 0x03 ··· 25 30 26 31 static int ns2_pci_phy_init(struct phy *p) 27 32 { 28 - struct ns2_pci_phy *phy = phy_get_drvdata(p); 33 + struct mdio_device *mdiodev = phy_get_drvdata(p); 29 34 int rc; 30 35 31 36 /* select the AFE 100MHz block page */ 32 - rc = mdiobus_write(phy->mdiodev->bus, phy->mdiodev->addr, 37 + rc = mdiobus_write(mdiodev->bus, mdiodev->addr, 33 38 BLK_ADDR_REG_OFFSET, PLL_AFE1_100MHZ_BLK); 34 39 if (rc) 35 40 goto err; 36 41 37 42 /* set the 100 MHz reference clock amplitude to 2.05 v */ 38 - rc = mdiobus_write(phy->mdiodev->bus, phy->mdiodev->addr, 43 + rc = mdiobus_write(mdiodev->bus, mdiodev->addr, 39 44 PLL_CLK_AMP_OFFSET, PLL_CLK_AMP_2P05V); 40 45 if (rc) 41 46 goto err; ··· 43 48 return 0; 44 49 45 50 err: 46 - dev_err(&phy->mdiodev->dev, "Error %d writing to phy\n", rc); 51 + dev_err(&mdiodev->dev, "Error %d writing to phy\n", rc); 47 52 return rc; 48 53 } 49 54 50 - static struct phy_ops ns2_pci_phy_ops = { 55 + static const struct phy_ops ns2_pci_phy_ops = { 51 56 .init = ns2_pci_phy_init, 57 + .owner = THIS_MODULE, 52 58 }; 53 59 54 60 static int ns2_pci_phy_probe(struct mdio_device *mdiodev) 55 61 { 56 62 struct device *dev = &mdiodev->dev; 57 63 struct phy_provider *provider; 58 - struct ns2_pci_phy *p; 59 64 struct phy *phy; 60 65 61 66 phy = devm_phy_create(dev, dev->of_node, &ns2_pci_phy_ops); ··· 64 69 return PTR_ERR(phy); 65 70 } 66 71 67 - p = devm_kmalloc(dev, sizeof(struct ns2_pci_phy), 68 - GFP_KERNEL); 69 - if (!p) 70 - return -ENOMEM; 71 - 72 - p->mdiodev = mdiodev; 73 - dev_set_drvdata(dev, p); 74 - 75 - p->phy = phy; 76 - phy_set_drvdata(phy, p); 72 + phy_set_drvdata(phy, mdiodev); 77 73 78 74 provider = devm_of_phy_provider_register(&phy->dev, 79 75 of_phy_simple_xlate);
+15
drivers/phy/phy-core.c
··· 357 357 } 358 358 EXPORT_SYMBOL_GPL(phy_set_mode); 359 359 360 + int phy_reset(struct phy *phy) 361 + { 362 + int ret; 363 + 364 + if (!phy || !phy->ops->reset) 365 + return 0; 366 + 367 + mutex_lock(&phy->mutex); 368 + ret = phy->ops->reset(phy); 369 + mutex_unlock(&phy->mutex); 370 + 371 + return ret; 372 + } 373 + EXPORT_SYMBOL_GPL(phy_reset); 374 + 360 375 /** 361 376 * _of_phy_get() - lookup and obtain a reference to a phy by phandle 362 377 * @np: device_node for which to get the phy
+1 -1
drivers/phy/phy-da8xx-usb.c
··· 154 154 d_phy->regmap = syscon_regmap_lookup_by_compatible( 155 155 "ti,da830-cfgchip"); 156 156 else 157 - d_phy->regmap = syscon_regmap_lookup_by_pdevname("syscon.0"); 157 + d_phy->regmap = syscon_regmap_lookup_by_pdevname("syscon"); 158 158 if (IS_ERR(d_phy->regmap)) { 159 159 dev_err(dev, "Failed to get syscon\n"); 160 160 return PTR_ERR(d_phy->regmap);
+2 -2
drivers/phy/phy-exynos5-usbdrd.c
··· 249 249 static unsigned int 250 250 exynos5_usbdrd_pipe3_set_refclk(struct phy_usb_instance *inst) 251 251 { 252 - static u32 reg; 252 + u32 reg; 253 253 struct exynos5_usbdrd_phy *phy_drd = to_usbdrd_phy(inst); 254 254 255 255 /* restore any previous reference clock settings */ ··· 295 295 static unsigned int 296 296 exynos5_usbdrd_utmi_set_refclk(struct phy_usb_instance *inst) 297 297 { 298 - static u32 reg; 298 + u32 reg; 299 299 struct exynos5_usbdrd_phy *phy_drd = to_usbdrd_phy(inst); 300 300 301 301 /* restore any previous reference clock settings */
+46 -54
drivers/phy/phy-omap-usb2.c
··· 133 133 return omap_usb_phy_power(phy, true); 134 134 } 135 135 136 + static int omap_usb2_disable_clocks(struct omap_usb *phy) 137 + { 138 + clk_disable(phy->wkupclk); 139 + if (!IS_ERR(phy->optclk)) 140 + clk_disable(phy->optclk); 141 + 142 + return 0; 143 + } 144 + 145 + static int omap_usb2_enable_clocks(struct omap_usb *phy) 146 + { 147 + int ret; 148 + 149 + ret = clk_enable(phy->wkupclk); 150 + if (ret < 0) { 151 + dev_err(phy->dev, "Failed to enable wkupclk %d\n", ret); 152 + goto err0; 153 + } 154 + 155 + if (!IS_ERR(phy->optclk)) { 156 + ret = clk_enable(phy->optclk); 157 + if (ret < 0) { 158 + dev_err(phy->dev, "Failed to enable optclk %d\n", ret); 159 + goto err1; 160 + } 161 + } 162 + 163 + return 0; 164 + 165 + err1: 166 + clk_disable(phy->wkupclk); 167 + 168 + err0: 169 + return ret; 170 + } 171 + 136 172 static int omap_usb_init(struct phy *x) 137 173 { 138 174 struct omap_usb *phy = phy_get_drvdata(x); 139 175 u32 val; 176 + 177 + omap_usb2_enable_clocks(phy); 140 178 141 179 if (phy->flags & OMAP_USB2_CALIBRATE_FALSE_DISCONNECT) { 142 180 /* ··· 193 155 return 0; 194 156 } 195 157 158 + static int omap_usb_exit(struct phy *x) 159 + { 160 + struct omap_usb *phy = phy_get_drvdata(x); 161 + 162 + return omap_usb2_disable_clocks(phy); 163 + } 164 + 196 165 static const struct phy_ops ops = { 197 166 .init = omap_usb_init, 167 + .exit = omap_usb_exit, 198 168 .power_on = omap_usb_power_on, 199 169 .power_off = omap_usb_power_off, 200 170 .owner = THIS_MODULE, ··· 422 376 return 0; 423 377 } 424 378 425 - #ifdef CONFIG_PM 426 - 427 - static int omap_usb2_runtime_suspend(struct device *dev) 428 - { 429 - struct platform_device *pdev = to_platform_device(dev); 430 - struct omap_usb *phy = platform_get_drvdata(pdev); 431 - 432 - clk_disable(phy->wkupclk); 433 - if (!IS_ERR(phy->optclk)) 434 - clk_disable(phy->optclk); 435 - 436 - return 0; 437 - } 438 - 439 - static int omap_usb2_runtime_resume(struct device *dev) 440 - { 441 - struct platform_device *pdev = to_platform_device(dev); 442 - struct omap_usb *phy = platform_get_drvdata(pdev); 443 - int ret; 444 - 445 - ret = clk_enable(phy->wkupclk); 446 - if (ret < 0) { 447 - dev_err(phy->dev, "Failed to enable wkupclk %d\n", ret); 448 - goto err0; 449 - } 450 - 451 - if (!IS_ERR(phy->optclk)) { 452 - ret = clk_enable(phy->optclk); 453 - if (ret < 0) { 454 - dev_err(phy->dev, "Failed to enable optclk %d\n", ret); 455 - goto err1; 456 - } 457 - } 458 - 459 - return 0; 460 - 461 - err1: 462 - clk_disable(phy->wkupclk); 463 - 464 - err0: 465 - return ret; 466 - } 467 - 468 - static const struct dev_pm_ops omap_usb2_pm_ops = { 469 - SET_RUNTIME_PM_OPS(omap_usb2_runtime_suspend, omap_usb2_runtime_resume, 470 - NULL) 471 - }; 472 - 473 - #define DEV_PM_OPS (&omap_usb2_pm_ops) 474 - #else 475 - #define DEV_PM_OPS NULL 476 - #endif 477 - 478 379 static struct platform_driver omap_usb2_driver = { 479 380 .probe = omap_usb2_probe, 480 381 .remove = omap_usb2_remove, 481 382 .driver = { 482 383 .name = "omap-usb2", 483 - .pm = DEV_PM_OPS, 484 384 .of_match_table = omap_usb2_id_table, 485 385 }, 486 386 };
+2 -4
drivers/phy/phy-qcom-ufs.c
··· 283 283 err = 0; 284 284 } 285 285 snprintf(prop_name, MAX_PROP_NAME, "%s-always-on", name); 286 - if (of_get_property(dev->of_node, prop_name, NULL)) 287 - vreg->is_always_on = true; 288 - else 289 - vreg->is_always_on = false; 286 + vreg->is_always_on = of_property_read_bool(dev->of_node, 287 + prop_name); 290 288 } 291 289 292 290 if (!strcmp(name, "vdda-pll")) {
+1
drivers/phy/phy-rcar-gen3-usb2.c
··· 280 280 281 281 static const struct of_device_id rcar_gen3_phy_usb2_match_table[] = { 282 282 { .compatible = "renesas,usb2-phy-r8a7795" }, 283 + { .compatible = "renesas,usb2-phy-r8a7796" }, 283 284 { .compatible = "renesas,rcar-gen3-usb2-phy" }, 284 285 { } 285 286 };
+707
drivers/phy/phy-rockchip-inno-usb2.c
··· 1 + /* 2 + * Rockchip USB2.0 PHY with Innosilicon IP block driver 3 + * 4 + * Copyright (C) 2016 Fuzhou Rockchip Electronics Co., Ltd 5 + * 6 + * This program is free software; you can redistribute it and/or modify 7 + * it under the terms of the GNU General Public License as published by 8 + * the Free Software Foundation; either version 2 of the License, or 9 + * (at your option) any later version. 10 + * 11 + * This program is distributed in the hope that it will be useful, 12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + * GNU General Public License for more details. 15 + */ 16 + 17 + #include <linux/clk.h> 18 + #include <linux/clk-provider.h> 19 + #include <linux/delay.h> 20 + #include <linux/interrupt.h> 21 + #include <linux/io.h> 22 + #include <linux/gpio/consumer.h> 23 + #include <linux/jiffies.h> 24 + #include <linux/kernel.h> 25 + #include <linux/module.h> 26 + #include <linux/mutex.h> 27 + #include <linux/of.h> 28 + #include <linux/of_address.h> 29 + #include <linux/of_irq.h> 30 + #include <linux/of_platform.h> 31 + #include <linux/phy/phy.h> 32 + #include <linux/platform_device.h> 33 + #include <linux/regmap.h> 34 + #include <linux/mfd/syscon.h> 35 + 36 + #define BIT_WRITEABLE_SHIFT 16 37 + #define SCHEDULE_DELAY (60 * HZ) 38 + 39 + enum rockchip_usb2phy_port_id { 40 + USB2PHY_PORT_OTG, 41 + USB2PHY_PORT_HOST, 42 + USB2PHY_NUM_PORTS, 43 + }; 44 + 45 + enum rockchip_usb2phy_host_state { 46 + PHY_STATE_HS_ONLINE = 0, 47 + PHY_STATE_DISCONNECT = 1, 48 + PHY_STATE_CONNECT = 2, 49 + PHY_STATE_FS_LS_ONLINE = 4, 50 + }; 51 + 52 + struct usb2phy_reg { 53 + unsigned int offset; 54 + unsigned int bitend; 55 + unsigned int bitstart; 56 + unsigned int disable; 57 + unsigned int enable; 58 + }; 59 + 60 + /** 61 + * struct rockchip_usb2phy_port_cfg: usb-phy port configuration. 62 + * @phy_sus: phy suspend register. 63 + * @ls_det_en: linestate detection enable register. 64 + * @ls_det_st: linestate detection state register. 65 + * @ls_det_clr: linestate detection clear register. 66 + * @utmi_ls: utmi linestate state register. 67 + * @utmi_hstdet: utmi host disconnect register. 68 + */ 69 + struct rockchip_usb2phy_port_cfg { 70 + struct usb2phy_reg phy_sus; 71 + struct usb2phy_reg ls_det_en; 72 + struct usb2phy_reg ls_det_st; 73 + struct usb2phy_reg ls_det_clr; 74 + struct usb2phy_reg utmi_ls; 75 + struct usb2phy_reg utmi_hstdet; 76 + }; 77 + 78 + /** 79 + * struct rockchip_usb2phy_cfg: usb-phy configuration. 80 + * @reg: the address offset of grf for usb-phy config. 81 + * @num_ports: specify how many ports that the phy has. 82 + * @clkout_ctl: keep on/turn off output clk of phy. 83 + */ 84 + struct rockchip_usb2phy_cfg { 85 + unsigned int reg; 86 + unsigned int num_ports; 87 + struct usb2phy_reg clkout_ctl; 88 + const struct rockchip_usb2phy_port_cfg port_cfgs[USB2PHY_NUM_PORTS]; 89 + }; 90 + 91 + /** 92 + * struct rockchip_usb2phy_port: usb-phy port data. 93 + * @port_id: flag for otg port or host port. 94 + * @suspended: phy suspended flag. 95 + * @ls_irq: IRQ number assigned for linestate detection. 96 + * @mutex: for register updating in sm_work. 97 + * @sm_work: OTG state machine work. 98 + * @phy_cfg: port register configuration, assigned by driver data. 99 + */ 100 + struct rockchip_usb2phy_port { 101 + struct phy *phy; 102 + unsigned int port_id; 103 + bool suspended; 104 + int ls_irq; 105 + struct mutex mutex; 106 + struct delayed_work sm_work; 107 + const struct rockchip_usb2phy_port_cfg *port_cfg; 108 + }; 109 + 110 + /** 111 + * struct rockchip_usb2phy: usb2.0 phy driver data. 112 + * @grf: General Register Files regmap. 113 + * @clk: clock struct of phy input clk. 114 + * @clk480m: clock struct of phy output clk. 115 + * @clk_hw: clock struct of phy output clk management. 116 + * @phy_cfg: phy register configuration, assigned by driver data. 117 + * @ports: phy port instance. 118 + */ 119 + struct rockchip_usb2phy { 120 + struct device *dev; 121 + struct regmap *grf; 122 + struct clk *clk; 123 + struct clk *clk480m; 124 + struct clk_hw clk480m_hw; 125 + const struct rockchip_usb2phy_cfg *phy_cfg; 126 + struct rockchip_usb2phy_port ports[USB2PHY_NUM_PORTS]; 127 + }; 128 + 129 + static inline int property_enable(struct rockchip_usb2phy *rphy, 130 + const struct usb2phy_reg *reg, bool en) 131 + { 132 + unsigned int val, mask, tmp; 133 + 134 + tmp = en ? reg->enable : reg->disable; 135 + mask = GENMASK(reg->bitend, reg->bitstart); 136 + val = (tmp << reg->bitstart) | (mask << BIT_WRITEABLE_SHIFT); 137 + 138 + return regmap_write(rphy->grf, reg->offset, val); 139 + } 140 + 141 + static inline bool property_enabled(struct rockchip_usb2phy *rphy, 142 + const struct usb2phy_reg *reg) 143 + { 144 + int ret; 145 + unsigned int tmp, orig; 146 + unsigned int mask = GENMASK(reg->bitend, reg->bitstart); 147 + 148 + ret = regmap_read(rphy->grf, reg->offset, &orig); 149 + if (ret) 150 + return false; 151 + 152 + tmp = (orig & mask) >> reg->bitstart; 153 + return tmp == reg->enable; 154 + } 155 + 156 + static int rockchip_usb2phy_clk480m_enable(struct clk_hw *hw) 157 + { 158 + struct rockchip_usb2phy *rphy = 159 + container_of(hw, struct rockchip_usb2phy, clk480m_hw); 160 + int ret; 161 + 162 + /* turn on 480m clk output if it is off */ 163 + if (!property_enabled(rphy, &rphy->phy_cfg->clkout_ctl)) { 164 + ret = property_enable(rphy, &rphy->phy_cfg->clkout_ctl, true); 165 + if (ret) 166 + return ret; 167 + 168 + /* waitting for the clk become stable */ 169 + mdelay(1); 170 + } 171 + 172 + return 0; 173 + } 174 + 175 + static void rockchip_usb2phy_clk480m_disable(struct clk_hw *hw) 176 + { 177 + struct rockchip_usb2phy *rphy = 178 + container_of(hw, struct rockchip_usb2phy, clk480m_hw); 179 + 180 + /* turn off 480m clk output */ 181 + property_enable(rphy, &rphy->phy_cfg->clkout_ctl, false); 182 + } 183 + 184 + static int rockchip_usb2phy_clk480m_enabled(struct clk_hw *hw) 185 + { 186 + struct rockchip_usb2phy *rphy = 187 + container_of(hw, struct rockchip_usb2phy, clk480m_hw); 188 + 189 + return property_enabled(rphy, &rphy->phy_cfg->clkout_ctl); 190 + } 191 + 192 + static unsigned long 193 + rockchip_usb2phy_clk480m_recalc_rate(struct clk_hw *hw, 194 + unsigned long parent_rate) 195 + { 196 + return 480000000; 197 + } 198 + 199 + static const struct clk_ops rockchip_usb2phy_clkout_ops = { 200 + .enable = rockchip_usb2phy_clk480m_enable, 201 + .disable = rockchip_usb2phy_clk480m_disable, 202 + .is_enabled = rockchip_usb2phy_clk480m_enabled, 203 + .recalc_rate = rockchip_usb2phy_clk480m_recalc_rate, 204 + }; 205 + 206 + static void rockchip_usb2phy_clk480m_unregister(void *data) 207 + { 208 + struct rockchip_usb2phy *rphy = data; 209 + 210 + of_clk_del_provider(rphy->dev->of_node); 211 + clk_unregister(rphy->clk480m); 212 + } 213 + 214 + static int 215 + rockchip_usb2phy_clk480m_register(struct rockchip_usb2phy *rphy) 216 + { 217 + struct device_node *node = rphy->dev->of_node; 218 + struct clk_init_data init; 219 + const char *clk_name; 220 + int ret; 221 + 222 + init.flags = 0; 223 + init.name = "clk_usbphy_480m"; 224 + init.ops = &rockchip_usb2phy_clkout_ops; 225 + 226 + /* optional override of the clockname */ 227 + of_property_read_string(node, "clock-output-names", &init.name); 228 + 229 + if (rphy->clk) { 230 + clk_name = __clk_get_name(rphy->clk); 231 + init.parent_names = &clk_name; 232 + init.num_parents = 1; 233 + } else { 234 + init.parent_names = NULL; 235 + init.num_parents = 0; 236 + } 237 + 238 + rphy->clk480m_hw.init = &init; 239 + 240 + /* register the clock */ 241 + rphy->clk480m = clk_register(rphy->dev, &rphy->clk480m_hw); 242 + if (IS_ERR(rphy->clk480m)) { 243 + ret = PTR_ERR(rphy->clk480m); 244 + goto err_ret; 245 + } 246 + 247 + ret = of_clk_add_provider(node, of_clk_src_simple_get, rphy->clk480m); 248 + if (ret < 0) 249 + goto err_clk_provider; 250 + 251 + ret = devm_add_action(rphy->dev, rockchip_usb2phy_clk480m_unregister, 252 + rphy); 253 + if (ret < 0) 254 + goto err_unreg_action; 255 + 256 + return 0; 257 + 258 + err_unreg_action: 259 + of_clk_del_provider(node); 260 + err_clk_provider: 261 + clk_unregister(rphy->clk480m); 262 + err_ret: 263 + return ret; 264 + } 265 + 266 + static int rockchip_usb2phy_init(struct phy *phy) 267 + { 268 + struct rockchip_usb2phy_port *rport = phy_get_drvdata(phy); 269 + struct rockchip_usb2phy *rphy = dev_get_drvdata(phy->dev.parent); 270 + int ret; 271 + 272 + if (rport->port_id == USB2PHY_PORT_HOST) { 273 + /* clear linestate and enable linestate detect irq */ 274 + mutex_lock(&rport->mutex); 275 + 276 + ret = property_enable(rphy, &rport->port_cfg->ls_det_clr, true); 277 + if (ret) { 278 + mutex_unlock(&rport->mutex); 279 + return ret; 280 + } 281 + 282 + ret = property_enable(rphy, &rport->port_cfg->ls_det_en, true); 283 + if (ret) { 284 + mutex_unlock(&rport->mutex); 285 + return ret; 286 + } 287 + 288 + mutex_unlock(&rport->mutex); 289 + schedule_delayed_work(&rport->sm_work, SCHEDULE_DELAY); 290 + } 291 + 292 + return 0; 293 + } 294 + 295 + static int rockchip_usb2phy_power_on(struct phy *phy) 296 + { 297 + struct rockchip_usb2phy_port *rport = phy_get_drvdata(phy); 298 + struct rockchip_usb2phy *rphy = dev_get_drvdata(phy->dev.parent); 299 + int ret; 300 + 301 + dev_dbg(&rport->phy->dev, "port power on\n"); 302 + 303 + if (!rport->suspended) 304 + return 0; 305 + 306 + ret = clk_prepare_enable(rphy->clk480m); 307 + if (ret) 308 + return ret; 309 + 310 + ret = property_enable(rphy, &rport->port_cfg->phy_sus, false); 311 + if (ret) 312 + return ret; 313 + 314 + rport->suspended = false; 315 + return 0; 316 + } 317 + 318 + static int rockchip_usb2phy_power_off(struct phy *phy) 319 + { 320 + struct rockchip_usb2phy_port *rport = phy_get_drvdata(phy); 321 + struct rockchip_usb2phy *rphy = dev_get_drvdata(phy->dev.parent); 322 + int ret; 323 + 324 + dev_dbg(&rport->phy->dev, "port power off\n"); 325 + 326 + if (rport->suspended) 327 + return 0; 328 + 329 + ret = property_enable(rphy, &rport->port_cfg->phy_sus, true); 330 + if (ret) 331 + return ret; 332 + 333 + rport->suspended = true; 334 + clk_disable_unprepare(rphy->clk480m); 335 + 336 + return 0; 337 + } 338 + 339 + static int rockchip_usb2phy_exit(struct phy *phy) 340 + { 341 + struct rockchip_usb2phy_port *rport = phy_get_drvdata(phy); 342 + 343 + if (rport->port_id == USB2PHY_PORT_HOST) 344 + cancel_delayed_work_sync(&rport->sm_work); 345 + 346 + return 0; 347 + } 348 + 349 + static const struct phy_ops rockchip_usb2phy_ops = { 350 + .init = rockchip_usb2phy_init, 351 + .exit = rockchip_usb2phy_exit, 352 + .power_on = rockchip_usb2phy_power_on, 353 + .power_off = rockchip_usb2phy_power_off, 354 + .owner = THIS_MODULE, 355 + }; 356 + 357 + /* 358 + * The function manage host-phy port state and suspend/resume phy port 359 + * to save power. 360 + * 361 + * we rely on utmi_linestate and utmi_hostdisconnect to identify whether 362 + * devices is disconnect or not. Besides, we do not need care it is FS/LS 363 + * disconnected or HS disconnected, actually, we just only need get the 364 + * device is disconnected at last through rearm the delayed work, 365 + * to suspend the phy port in _PHY_STATE_DISCONNECT_ case. 366 + * 367 + * NOTE: It may invoke *phy_powr_off or *phy_power_on which will invoke 368 + * some clk related APIs, so do not invoke it from interrupt context directly. 369 + */ 370 + static void rockchip_usb2phy_sm_work(struct work_struct *work) 371 + { 372 + struct rockchip_usb2phy_port *rport = 373 + container_of(work, struct rockchip_usb2phy_port, sm_work.work); 374 + struct rockchip_usb2phy *rphy = dev_get_drvdata(rport->phy->dev.parent); 375 + unsigned int sh = rport->port_cfg->utmi_hstdet.bitend - 376 + rport->port_cfg->utmi_hstdet.bitstart + 1; 377 + unsigned int ul, uhd, state; 378 + unsigned int ul_mask, uhd_mask; 379 + int ret; 380 + 381 + mutex_lock(&rport->mutex); 382 + 383 + ret = regmap_read(rphy->grf, rport->port_cfg->utmi_ls.offset, &ul); 384 + if (ret < 0) 385 + goto next_schedule; 386 + 387 + ret = regmap_read(rphy->grf, rport->port_cfg->utmi_hstdet.offset, 388 + &uhd); 389 + if (ret < 0) 390 + goto next_schedule; 391 + 392 + uhd_mask = GENMASK(rport->port_cfg->utmi_hstdet.bitend, 393 + rport->port_cfg->utmi_hstdet.bitstart); 394 + ul_mask = GENMASK(rport->port_cfg->utmi_ls.bitend, 395 + rport->port_cfg->utmi_ls.bitstart); 396 + 397 + /* stitch on utmi_ls and utmi_hstdet as phy state */ 398 + state = ((uhd & uhd_mask) >> rport->port_cfg->utmi_hstdet.bitstart) | 399 + (((ul & ul_mask) >> rport->port_cfg->utmi_ls.bitstart) << sh); 400 + 401 + switch (state) { 402 + case PHY_STATE_HS_ONLINE: 403 + dev_dbg(&rport->phy->dev, "HS online\n"); 404 + break; 405 + case PHY_STATE_FS_LS_ONLINE: 406 + /* 407 + * For FS/LS device, the online state share with connect state 408 + * from utmi_ls and utmi_hstdet register, so we distinguish 409 + * them via suspended flag. 410 + * 411 + * Plus, there are two cases, one is D- Line pull-up, and D+ 412 + * line pull-down, the state is 4; another is D+ line pull-up, 413 + * and D- line pull-down, the state is 2. 414 + */ 415 + if (!rport->suspended) { 416 + /* D- line pull-up, D+ line pull-down */ 417 + dev_dbg(&rport->phy->dev, "FS/LS online\n"); 418 + break; 419 + } 420 + /* fall through */ 421 + case PHY_STATE_CONNECT: 422 + if (rport->suspended) { 423 + dev_dbg(&rport->phy->dev, "Connected\n"); 424 + rockchip_usb2phy_power_on(rport->phy); 425 + rport->suspended = false; 426 + } else { 427 + /* D+ line pull-up, D- line pull-down */ 428 + dev_dbg(&rport->phy->dev, "FS/LS online\n"); 429 + } 430 + break; 431 + case PHY_STATE_DISCONNECT: 432 + if (!rport->suspended) { 433 + dev_dbg(&rport->phy->dev, "Disconnected\n"); 434 + rockchip_usb2phy_power_off(rport->phy); 435 + rport->suspended = true; 436 + } 437 + 438 + /* 439 + * activate the linestate detection to get the next device 440 + * plug-in irq. 441 + */ 442 + property_enable(rphy, &rport->port_cfg->ls_det_clr, true); 443 + property_enable(rphy, &rport->port_cfg->ls_det_en, true); 444 + 445 + /* 446 + * we don't need to rearm the delayed work when the phy port 447 + * is suspended. 448 + */ 449 + mutex_unlock(&rport->mutex); 450 + return; 451 + default: 452 + dev_dbg(&rport->phy->dev, "unknown phy state\n"); 453 + break; 454 + } 455 + 456 + next_schedule: 457 + mutex_unlock(&rport->mutex); 458 + schedule_delayed_work(&rport->sm_work, SCHEDULE_DELAY); 459 + } 460 + 461 + static irqreturn_t rockchip_usb2phy_linestate_irq(int irq, void *data) 462 + { 463 + struct rockchip_usb2phy_port *rport = data; 464 + struct rockchip_usb2phy *rphy = dev_get_drvdata(rport->phy->dev.parent); 465 + 466 + if (!property_enabled(rphy, &rport->port_cfg->ls_det_st)) 467 + return IRQ_NONE; 468 + 469 + mutex_lock(&rport->mutex); 470 + 471 + /* disable linestate detect irq and clear its status */ 472 + property_enable(rphy, &rport->port_cfg->ls_det_en, false); 473 + property_enable(rphy, &rport->port_cfg->ls_det_clr, true); 474 + 475 + mutex_unlock(&rport->mutex); 476 + 477 + /* 478 + * In this case for host phy port, a new device is plugged in, 479 + * meanwhile, if the phy port is suspended, we need rearm the work to 480 + * resume it and mange its states; otherwise, we do nothing about that. 481 + */ 482 + if (rport->suspended && rport->port_id == USB2PHY_PORT_HOST) 483 + rockchip_usb2phy_sm_work(&rport->sm_work.work); 484 + 485 + return IRQ_HANDLED; 486 + } 487 + 488 + static int rockchip_usb2phy_host_port_init(struct rockchip_usb2phy *rphy, 489 + struct rockchip_usb2phy_port *rport, 490 + struct device_node *child_np) 491 + { 492 + int ret; 493 + 494 + rport->port_id = USB2PHY_PORT_HOST; 495 + rport->port_cfg = &rphy->phy_cfg->port_cfgs[USB2PHY_PORT_HOST]; 496 + rport->suspended = true; 497 + 498 + mutex_init(&rport->mutex); 499 + INIT_DELAYED_WORK(&rport->sm_work, rockchip_usb2phy_sm_work); 500 + 501 + rport->ls_irq = of_irq_get_byname(child_np, "linestate"); 502 + if (rport->ls_irq < 0) { 503 + dev_err(rphy->dev, "no linestate irq provided\n"); 504 + return rport->ls_irq; 505 + } 506 + 507 + ret = devm_request_threaded_irq(rphy->dev, rport->ls_irq, NULL, 508 + rockchip_usb2phy_linestate_irq, 509 + IRQF_ONESHOT, 510 + "rockchip_usb2phy", rport); 511 + if (ret) { 512 + dev_err(rphy->dev, "failed to request irq handle\n"); 513 + return ret; 514 + } 515 + 516 + return 0; 517 + } 518 + 519 + static int rockchip_usb2phy_probe(struct platform_device *pdev) 520 + { 521 + struct device *dev = &pdev->dev; 522 + struct device_node *np = dev->of_node; 523 + struct device_node *child_np; 524 + struct phy_provider *provider; 525 + struct rockchip_usb2phy *rphy; 526 + const struct rockchip_usb2phy_cfg *phy_cfgs; 527 + const struct of_device_id *match; 528 + unsigned int reg; 529 + int index, ret; 530 + 531 + rphy = devm_kzalloc(dev, sizeof(*rphy), GFP_KERNEL); 532 + if (!rphy) 533 + return -ENOMEM; 534 + 535 + match = of_match_device(dev->driver->of_match_table, dev); 536 + if (!match || !match->data) { 537 + dev_err(dev, "phy configs are not assigned!\n"); 538 + return -EINVAL; 539 + } 540 + 541 + if (!dev->parent || !dev->parent->of_node) 542 + return -EINVAL; 543 + 544 + rphy->grf = syscon_node_to_regmap(dev->parent->of_node); 545 + if (IS_ERR(rphy->grf)) 546 + return PTR_ERR(rphy->grf); 547 + 548 + if (of_property_read_u32(np, "reg", &reg)) { 549 + dev_err(dev, "the reg property is not assigned in %s node\n", 550 + np->name); 551 + return -EINVAL; 552 + } 553 + 554 + rphy->dev = dev; 555 + phy_cfgs = match->data; 556 + platform_set_drvdata(pdev, rphy); 557 + 558 + /* find out a proper config which can be matched with dt. */ 559 + index = 0; 560 + while (phy_cfgs[index].reg) { 561 + if (phy_cfgs[index].reg == reg) { 562 + rphy->phy_cfg = &phy_cfgs[index]; 563 + break; 564 + } 565 + 566 + ++index; 567 + } 568 + 569 + if (!rphy->phy_cfg) { 570 + dev_err(dev, "no phy-config can be matched with %s node\n", 571 + np->name); 572 + return -EINVAL; 573 + } 574 + 575 + rphy->clk = of_clk_get_by_name(np, "phyclk"); 576 + if (!IS_ERR(rphy->clk)) { 577 + clk_prepare_enable(rphy->clk); 578 + } else { 579 + dev_info(&pdev->dev, "no phyclk specified\n"); 580 + rphy->clk = NULL; 581 + } 582 + 583 + ret = rockchip_usb2phy_clk480m_register(rphy); 584 + if (ret) { 585 + dev_err(dev, "failed to register 480m output clock\n"); 586 + goto disable_clks; 587 + } 588 + 589 + index = 0; 590 + for_each_available_child_of_node(np, child_np) { 591 + struct rockchip_usb2phy_port *rport = &rphy->ports[index]; 592 + struct phy *phy; 593 + 594 + /* 595 + * This driver aim to support both otg-port and host-port, 596 + * but unfortunately, the otg part is not ready in current, 597 + * so this comments and below codes are interim, which should 598 + * be changed after otg-port is supplied soon. 599 + */ 600 + if (of_node_cmp(child_np->name, "host-port")) 601 + goto next_child; 602 + 603 + phy = devm_phy_create(dev, child_np, &rockchip_usb2phy_ops); 604 + if (IS_ERR(phy)) { 605 + dev_err(dev, "failed to create phy\n"); 606 + ret = PTR_ERR(phy); 607 + goto put_child; 608 + } 609 + 610 + rport->phy = phy; 611 + phy_set_drvdata(rport->phy, rport); 612 + 613 + ret = rockchip_usb2phy_host_port_init(rphy, rport, child_np); 614 + if (ret) 615 + goto put_child; 616 + 617 + next_child: 618 + /* to prevent out of boundary */ 619 + if (++index >= rphy->phy_cfg->num_ports) 620 + break; 621 + } 622 + 623 + provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate); 624 + return PTR_ERR_OR_ZERO(provider); 625 + 626 + put_child: 627 + of_node_put(child_np); 628 + disable_clks: 629 + if (rphy->clk) { 630 + clk_disable_unprepare(rphy->clk); 631 + clk_put(rphy->clk); 632 + } 633 + return ret; 634 + } 635 + 636 + static const struct rockchip_usb2phy_cfg rk3366_phy_cfgs[] = { 637 + { 638 + .reg = 0x700, 639 + .num_ports = 2, 640 + .clkout_ctl = { 0x0724, 15, 15, 1, 0 }, 641 + .port_cfgs = { 642 + [USB2PHY_PORT_HOST] = { 643 + .phy_sus = { 0x0728, 15, 0, 0, 0x1d1 }, 644 + .ls_det_en = { 0x0680, 4, 4, 0, 1 }, 645 + .ls_det_st = { 0x0690, 4, 4, 0, 1 }, 646 + .ls_det_clr = { 0x06a0, 4, 4, 0, 1 }, 647 + .utmi_ls = { 0x049c, 14, 13, 0, 1 }, 648 + .utmi_hstdet = { 0x049c, 12, 12, 0, 1 } 649 + } 650 + }, 651 + }, 652 + { /* sentinel */ } 653 + }; 654 + 655 + static const struct rockchip_usb2phy_cfg rk3399_phy_cfgs[] = { 656 + { 657 + .reg = 0xe450, 658 + .num_ports = 2, 659 + .clkout_ctl = { 0xe450, 4, 4, 1, 0 }, 660 + .port_cfgs = { 661 + [USB2PHY_PORT_HOST] = { 662 + .phy_sus = { 0xe458, 1, 0, 0x2, 0x1 }, 663 + .ls_det_en = { 0xe3c0, 6, 6, 0, 1 }, 664 + .ls_det_st = { 0xe3e0, 6, 6, 0, 1 }, 665 + .ls_det_clr = { 0xe3d0, 6, 6, 0, 1 }, 666 + .utmi_ls = { 0xe2ac, 22, 21, 0, 1 }, 667 + .utmi_hstdet = { 0xe2ac, 23, 23, 0, 1 } 668 + } 669 + }, 670 + }, 671 + { 672 + .reg = 0xe460, 673 + .num_ports = 2, 674 + .clkout_ctl = { 0xe460, 4, 4, 1, 0 }, 675 + .port_cfgs = { 676 + [USB2PHY_PORT_HOST] = { 677 + .phy_sus = { 0xe468, 1, 0, 0x2, 0x1 }, 678 + .ls_det_en = { 0xe3c0, 11, 11, 0, 1 }, 679 + .ls_det_st = { 0xe3e0, 11, 11, 0, 1 }, 680 + .ls_det_clr = { 0xe3d0, 11, 11, 0, 1 }, 681 + .utmi_ls = { 0xe2ac, 26, 25, 0, 1 }, 682 + .utmi_hstdet = { 0xe2ac, 27, 27, 0, 1 } 683 + } 684 + }, 685 + }, 686 + { /* sentinel */ } 687 + }; 688 + 689 + static const struct of_device_id rockchip_usb2phy_dt_match[] = { 690 + { .compatible = "rockchip,rk3366-usb2phy", .data = &rk3366_phy_cfgs }, 691 + { .compatible = "rockchip,rk3399-usb2phy", .data = &rk3399_phy_cfgs }, 692 + {} 693 + }; 694 + MODULE_DEVICE_TABLE(of, rockchip_usb2phy_dt_match); 695 + 696 + static struct platform_driver rockchip_usb2phy_driver = { 697 + .probe = rockchip_usb2phy_probe, 698 + .driver = { 699 + .name = "rockchip-usb2phy", 700 + .of_match_table = rockchip_usb2phy_dt_match, 701 + }, 702 + }; 703 + module_platform_driver(rockchip_usb2phy_driver); 704 + 705 + MODULE_AUTHOR("Frank Wang <frank.wang@rock-chips.com>"); 706 + MODULE_DESCRIPTION("Rockchip USB2.0 PHY driver"); 707 + MODULE_LICENSE("GPL v2");
+357
drivers/phy/phy-rockchip-pcie.c
··· 1 + /* 2 + * Rockchip PCIe PHY driver 3 + * 4 + * Copyright (C) 2016 Shawn Lin <shawn.lin@rock-chips.com> 5 + * Copyright (C) 2016 ROCKCHIP, Inc. 6 + * 7 + * This program is free software; you can redistribute it and/or modify 8 + * it under the terms of the GNU General Public License as published by 9 + * the Free Software Foundation; either version 2 of the License. 10 + * 11 + * This program is distributed in the hope that it will be useful, 12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + * GNU General Public License for more details. 15 + */ 16 + 17 + #include <linux/clk.h> 18 + #include <linux/delay.h> 19 + #include <linux/io.h> 20 + #include <linux/mfd/syscon.h> 21 + #include <linux/module.h> 22 + #include <linux/of.h> 23 + #include <linux/of_address.h> 24 + #include <linux/of_platform.h> 25 + #include <linux/phy/phy.h> 26 + #include <linux/platform_device.h> 27 + #include <linux/regmap.h> 28 + #include <linux/reset.h> 29 + 30 + /* 31 + * The higher 16-bit of this register is used for write protection 32 + * only if BIT(x + 16) set to 1 the BIT(x) can be written. 33 + */ 34 + #define HIWORD_UPDATE(val, mask, shift) \ 35 + ((val) << (shift) | (mask) << ((shift) + 16)) 36 + 37 + #define PHY_MAX_LANE_NUM 4 38 + #define PHY_CFG_DATA_SHIFT 7 39 + #define PHY_CFG_ADDR_SHIFT 1 40 + #define PHY_CFG_DATA_MASK 0xf 41 + #define PHY_CFG_ADDR_MASK 0x3f 42 + #define PHY_CFG_RD_MASK 0x3ff 43 + #define PHY_CFG_WR_ENABLE 1 44 + #define PHY_CFG_WR_DISABLE 1 45 + #define PHY_CFG_WR_SHIFT 0 46 + #define PHY_CFG_WR_MASK 1 47 + #define PHY_CFG_PLL_LOCK 0x10 48 + #define PHY_CFG_CLK_TEST 0x10 49 + #define PHY_CFG_CLK_SCC 0x12 50 + #define PHY_CFG_SEPE_RATE BIT(3) 51 + #define PHY_CFG_PLL_100M BIT(3) 52 + #define PHY_PLL_LOCKED BIT(9) 53 + #define PHY_PLL_OUTPUT BIT(10) 54 + #define PHY_LANE_A_STATUS 0x30 55 + #define PHY_LANE_B_STATUS 0x31 56 + #define PHY_LANE_C_STATUS 0x32 57 + #define PHY_LANE_D_STATUS 0x33 58 + #define PHY_LANE_RX_DET_SHIFT 11 59 + #define PHY_LANE_RX_DET_TH 0x1 60 + #define PHY_LANE_IDLE_OFF 0x1 61 + #define PHY_LANE_IDLE_MASK 0x1 62 + #define PHY_LANE_IDLE_A_SHIFT 3 63 + #define PHY_LANE_IDLE_B_SHIFT 4 64 + #define PHY_LANE_IDLE_C_SHIFT 5 65 + #define PHY_LANE_IDLE_D_SHIFT 6 66 + 67 + struct rockchip_pcie_data { 68 + unsigned int pcie_conf; 69 + unsigned int pcie_status; 70 + unsigned int pcie_laneoff; 71 + }; 72 + 73 + struct rockchip_pcie_phy { 74 + struct rockchip_pcie_data *phy_data; 75 + struct regmap *reg_base; 76 + struct reset_control *phy_rst; 77 + struct clk *clk_pciephy_ref; 78 + }; 79 + 80 + static inline void phy_wr_cfg(struct rockchip_pcie_phy *rk_phy, 81 + u32 addr, u32 data) 82 + { 83 + regmap_write(rk_phy->reg_base, rk_phy->phy_data->pcie_conf, 84 + HIWORD_UPDATE(data, 85 + PHY_CFG_DATA_MASK, 86 + PHY_CFG_DATA_SHIFT) | 87 + HIWORD_UPDATE(addr, 88 + PHY_CFG_ADDR_MASK, 89 + PHY_CFG_ADDR_SHIFT)); 90 + udelay(1); 91 + regmap_write(rk_phy->reg_base, rk_phy->phy_data->pcie_conf, 92 + HIWORD_UPDATE(PHY_CFG_WR_ENABLE, 93 + PHY_CFG_WR_MASK, 94 + PHY_CFG_WR_SHIFT)); 95 + udelay(1); 96 + regmap_write(rk_phy->reg_base, rk_phy->phy_data->pcie_conf, 97 + HIWORD_UPDATE(PHY_CFG_WR_DISABLE, 98 + PHY_CFG_WR_MASK, 99 + PHY_CFG_WR_SHIFT)); 100 + } 101 + 102 + static inline u32 phy_rd_cfg(struct rockchip_pcie_phy *rk_phy, 103 + u32 addr) 104 + { 105 + u32 val; 106 + 107 + regmap_write(rk_phy->reg_base, rk_phy->phy_data->pcie_conf, 108 + HIWORD_UPDATE(addr, 109 + PHY_CFG_RD_MASK, 110 + PHY_CFG_ADDR_SHIFT)); 111 + regmap_read(rk_phy->reg_base, 112 + rk_phy->phy_data->pcie_status, 113 + &val); 114 + return val; 115 + } 116 + 117 + static int rockchip_pcie_phy_power_off(struct phy *phy) 118 + { 119 + struct rockchip_pcie_phy *rk_phy = phy_get_drvdata(phy); 120 + int err = 0; 121 + 122 + err = reset_control_assert(rk_phy->phy_rst); 123 + if (err) { 124 + dev_err(&phy->dev, "assert phy_rst err %d\n", err); 125 + return err; 126 + } 127 + 128 + return 0; 129 + } 130 + 131 + static int rockchip_pcie_phy_power_on(struct phy *phy) 132 + { 133 + struct rockchip_pcie_phy *rk_phy = phy_get_drvdata(phy); 134 + int err = 0; 135 + u32 status; 136 + unsigned long timeout; 137 + 138 + err = reset_control_deassert(rk_phy->phy_rst); 139 + if (err) { 140 + dev_err(&phy->dev, "deassert phy_rst err %d\n", err); 141 + return err; 142 + } 143 + 144 + regmap_write(rk_phy->reg_base, rk_phy->phy_data->pcie_conf, 145 + HIWORD_UPDATE(PHY_CFG_PLL_LOCK, 146 + PHY_CFG_ADDR_MASK, 147 + PHY_CFG_ADDR_SHIFT)); 148 + 149 + /* 150 + * No documented timeout value for phy operation below, 151 + * so we make it large enough here. And we use loop-break 152 + * method which should not be harmful. 153 + */ 154 + timeout = jiffies + msecs_to_jiffies(1000); 155 + 156 + err = -EINVAL; 157 + while (time_before(jiffies, timeout)) { 158 + regmap_read(rk_phy->reg_base, 159 + rk_phy->phy_data->pcie_status, 160 + &status); 161 + if (status & PHY_PLL_LOCKED) { 162 + dev_dbg(&phy->dev, "pll locked!\n"); 163 + err = 0; 164 + break; 165 + } 166 + msleep(20); 167 + } 168 + 169 + if (err) { 170 + dev_err(&phy->dev, "pll lock timeout!\n"); 171 + goto err_pll_lock; 172 + } 173 + 174 + phy_wr_cfg(rk_phy, PHY_CFG_CLK_TEST, PHY_CFG_SEPE_RATE); 175 + phy_wr_cfg(rk_phy, PHY_CFG_CLK_SCC, PHY_CFG_PLL_100M); 176 + 177 + err = -ETIMEDOUT; 178 + while (time_before(jiffies, timeout)) { 179 + regmap_read(rk_phy->reg_base, 180 + rk_phy->phy_data->pcie_status, 181 + &status); 182 + if (!(status & PHY_PLL_OUTPUT)) { 183 + dev_dbg(&phy->dev, "pll output enable done!\n"); 184 + err = 0; 185 + break; 186 + } 187 + msleep(20); 188 + } 189 + 190 + if (err) { 191 + dev_err(&phy->dev, "pll output enable timeout!\n"); 192 + goto err_pll_lock; 193 + } 194 + 195 + regmap_write(rk_phy->reg_base, rk_phy->phy_data->pcie_conf, 196 + HIWORD_UPDATE(PHY_CFG_PLL_LOCK, 197 + PHY_CFG_ADDR_MASK, 198 + PHY_CFG_ADDR_SHIFT)); 199 + err = -EINVAL; 200 + while (time_before(jiffies, timeout)) { 201 + regmap_read(rk_phy->reg_base, 202 + rk_phy->phy_data->pcie_status, 203 + &status); 204 + if (status & PHY_PLL_LOCKED) { 205 + dev_dbg(&phy->dev, "pll relocked!\n"); 206 + err = 0; 207 + break; 208 + } 209 + msleep(20); 210 + } 211 + 212 + if (err) { 213 + dev_err(&phy->dev, "pll relock timeout!\n"); 214 + goto err_pll_lock; 215 + } 216 + 217 + return 0; 218 + 219 + err_pll_lock: 220 + reset_control_assert(rk_phy->phy_rst); 221 + return err; 222 + } 223 + 224 + static int rockchip_pcie_phy_init(struct phy *phy) 225 + { 226 + struct rockchip_pcie_phy *rk_phy = phy_get_drvdata(phy); 227 + int err = 0; 228 + 229 + err = clk_prepare_enable(rk_phy->clk_pciephy_ref); 230 + if (err) { 231 + dev_err(&phy->dev, "Fail to enable pcie ref clock.\n"); 232 + goto err_refclk; 233 + } 234 + 235 + err = reset_control_assert(rk_phy->phy_rst); 236 + if (err) { 237 + dev_err(&phy->dev, "assert phy_rst err %d\n", err); 238 + goto err_reset; 239 + } 240 + 241 + return err; 242 + 243 + err_reset: 244 + clk_disable_unprepare(rk_phy->clk_pciephy_ref); 245 + err_refclk: 246 + return err; 247 + } 248 + 249 + static int rockchip_pcie_phy_exit(struct phy *phy) 250 + { 251 + struct rockchip_pcie_phy *rk_phy = phy_get_drvdata(phy); 252 + int err = 0; 253 + 254 + clk_disable_unprepare(rk_phy->clk_pciephy_ref); 255 + 256 + err = reset_control_deassert(rk_phy->phy_rst); 257 + if (err) { 258 + dev_err(&phy->dev, "deassert phy_rst err %d\n", err); 259 + goto err_reset; 260 + } 261 + 262 + return err; 263 + 264 + err_reset: 265 + clk_prepare_enable(rk_phy->clk_pciephy_ref); 266 + return err; 267 + } 268 + 269 + static const struct phy_ops ops = { 270 + .init = rockchip_pcie_phy_init, 271 + .exit = rockchip_pcie_phy_exit, 272 + .power_on = rockchip_pcie_phy_power_on, 273 + .power_off = rockchip_pcie_phy_power_off, 274 + .owner = THIS_MODULE, 275 + }; 276 + 277 + static const struct rockchip_pcie_data rk3399_pcie_data = { 278 + .pcie_conf = 0xe220, 279 + .pcie_status = 0xe2a4, 280 + .pcie_laneoff = 0xe214, 281 + }; 282 + 283 + static const struct of_device_id rockchip_pcie_phy_dt_ids[] = { 284 + { 285 + .compatible = "rockchip,rk3399-pcie-phy", 286 + .data = &rk3399_pcie_data, 287 + }, 288 + {} 289 + }; 290 + 291 + MODULE_DEVICE_TABLE(of, rockchip_pcie_phy_dt_ids); 292 + 293 + static int rockchip_pcie_phy_probe(struct platform_device *pdev) 294 + { 295 + struct device *dev = &pdev->dev; 296 + struct rockchip_pcie_phy *rk_phy; 297 + struct phy *generic_phy; 298 + struct phy_provider *phy_provider; 299 + struct regmap *grf; 300 + const struct of_device_id *of_id; 301 + 302 + grf = syscon_node_to_regmap(dev->parent->of_node); 303 + if (IS_ERR(grf)) { 304 + dev_err(dev, "Cannot find GRF syscon\n"); 305 + return PTR_ERR(grf); 306 + } 307 + 308 + rk_phy = devm_kzalloc(dev, sizeof(*rk_phy), GFP_KERNEL); 309 + if (!rk_phy) 310 + return -ENOMEM; 311 + 312 + of_id = of_match_device(rockchip_pcie_phy_dt_ids, &pdev->dev); 313 + if (!of_id) 314 + return -EINVAL; 315 + 316 + rk_phy->phy_data = (struct rockchip_pcie_data *)of_id->data; 317 + rk_phy->reg_base = grf; 318 + 319 + rk_phy->phy_rst = devm_reset_control_get(dev, "phy"); 320 + if (IS_ERR(rk_phy->phy_rst)) { 321 + if (PTR_ERR(rk_phy->phy_rst) != -EPROBE_DEFER) 322 + dev_err(dev, 323 + "missing phy property for reset controller\n"); 324 + return PTR_ERR(rk_phy->phy_rst); 325 + } 326 + 327 + rk_phy->clk_pciephy_ref = devm_clk_get(dev, "refclk"); 328 + if (IS_ERR(rk_phy->clk_pciephy_ref)) { 329 + dev_err(dev, "refclk not found.\n"); 330 + return PTR_ERR(rk_phy->clk_pciephy_ref); 331 + } 332 + 333 + generic_phy = devm_phy_create(dev, dev->of_node, &ops); 334 + if (IS_ERR(generic_phy)) { 335 + dev_err(dev, "failed to create PHY\n"); 336 + return PTR_ERR(generic_phy); 337 + } 338 + 339 + phy_set_drvdata(generic_phy, rk_phy); 340 + phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate); 341 + 342 + return PTR_ERR_OR_ZERO(phy_provider); 343 + } 344 + 345 + static struct platform_driver rockchip_pcie_driver = { 346 + .probe = rockchip_pcie_phy_probe, 347 + .driver = { 348 + .name = "rockchip-pcie-phy", 349 + .of_match_table = rockchip_pcie_phy_dt_ids, 350 + }, 351 + }; 352 + 353 + module_platform_driver(rockchip_pcie_driver); 354 + 355 + MODULE_AUTHOR("Shawn Lin <shawn.lin@rock-chips.com>"); 356 + MODULE_DESCRIPTION("Rockchip PCIe PHY driver"); 357 + MODULE_LICENSE("GPL v2");
+1023
drivers/phy/phy-rockchip-typec.c
··· 1 + /* 2 + * Copyright (C) Fuzhou Rockchip Electronics Co.Ltd 3 + * Author: Chris Zhong <zyw@rock-chips.com> 4 + * Kever Yang <kever.yang@rock-chips.com> 5 + * 6 + * This software is licensed under the terms of the GNU General Public 7 + * License version 2, as published by the Free Software Foundation, and 8 + * may be copied, distributed, and modified under those terms. 9 + * 10 + * This program is distributed in the hope that it will be useful, 11 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 + * GNU General Public License for more details. 14 + * 15 + * The ROCKCHIP Type-C PHY has two PLL clocks. The first PLL clock 16 + * is used for USB3, the second PLL clock is used for DP. This Type-C PHY has 17 + * 3 working modes: USB3 only mode, DP only mode, and USB3+DP mode. 18 + * At USB3 only mode, both PLL clocks need to be initialized, this allows the 19 + * PHY to switch mode between USB3 and USB3+DP, without disconnecting the USB 20 + * device. 21 + * In The DP only mode, only the DP PLL needs to be powered on, and the 4 lanes 22 + * are all used for DP. 23 + * 24 + * This driver gets extcon cable state and property, then decides which mode to 25 + * select: 26 + * 27 + * 1. USB3 only mode: 28 + * EXTCON_USB or EXTCON_USB_HOST state is true, and 29 + * EXTCON_PROP_USB_SS property is true. 30 + * EXTCON_DISP_DP state is false. 31 + * 32 + * 2. DP only mode: 33 + * EXTCON_DISP_DP state is true, and 34 + * EXTCON_PROP_USB_SS property is false. 35 + * If EXTCON_USB_HOST state is true, it is DP + USB2 mode, since the USB2 phy 36 + * is a separate phy, so this case is still DP only mode. 37 + * 38 + * 3. USB3+DP mode: 39 + * EXTCON_USB_HOST and EXTCON_DISP_DP are both true, and 40 + * EXTCON_PROP_USB_SS property is true. 41 + * 42 + * This Type-C PHY driver supports normal and flip orientation. The orientation 43 + * is reported by the EXTCON_PROP_USB_TYPEC_POLARITY property: true is flip 44 + * orientation, false is normal orientation. 45 + * 46 + */ 47 + 48 + #include <linux/clk.h> 49 + #include <linux/clk-provider.h> 50 + #include <linux/delay.h> 51 + #include <linux/extcon.h> 52 + #include <linux/io.h> 53 + #include <linux/iopoll.h> 54 + #include <linux/kernel.h> 55 + #include <linux/module.h> 56 + #include <linux/mutex.h> 57 + #include <linux/of.h> 58 + #include <linux/of_address.h> 59 + #include <linux/of_platform.h> 60 + #include <linux/platform_device.h> 61 + #include <linux/regmap.h> 62 + #include <linux/reset.h> 63 + 64 + #include <linux/mfd/syscon.h> 65 + #include <linux/phy/phy.h> 66 + 67 + #define CMN_SSM_BANDGAP (0x21 << 2) 68 + #define CMN_SSM_BIAS (0x22 << 2) 69 + #define CMN_PLLSM0_PLLEN (0x29 << 2) 70 + #define CMN_PLLSM0_PLLPRE (0x2a << 2) 71 + #define CMN_PLLSM0_PLLVREF (0x2b << 2) 72 + #define CMN_PLLSM0_PLLLOCK (0x2c << 2) 73 + #define CMN_PLLSM1_PLLEN (0x31 << 2) 74 + #define CMN_PLLSM1_PLLPRE (0x32 << 2) 75 + #define CMN_PLLSM1_PLLVREF (0x33 << 2) 76 + #define CMN_PLLSM1_PLLLOCK (0x34 << 2) 77 + #define CMN_PLLSM1_USER_DEF_CTRL (0x37 << 2) 78 + #define CMN_ICAL_OVRD (0xc1 << 2) 79 + #define CMN_PLL0_VCOCAL_OVRD (0x83 << 2) 80 + #define CMN_PLL0_VCOCAL_INIT (0x84 << 2) 81 + #define CMN_PLL0_VCOCAL_ITER (0x85 << 2) 82 + #define CMN_PLL0_LOCK_REFCNT_START (0x90 << 2) 83 + #define CMN_PLL0_LOCK_PLLCNT_START (0x92 << 2) 84 + #define CMN_PLL0_LOCK_PLLCNT_THR (0x93 << 2) 85 + #define CMN_PLL0_INTDIV (0x94 << 2) 86 + #define CMN_PLL0_FRACDIV (0x95 << 2) 87 + #define CMN_PLL0_HIGH_THR (0x96 << 2) 88 + #define CMN_PLL0_DSM_DIAG (0x97 << 2) 89 + #define CMN_PLL0_SS_CTRL1 (0x98 << 2) 90 + #define CMN_PLL0_SS_CTRL2 (0x99 << 2) 91 + #define CMN_PLL1_VCOCAL_START (0xa1 << 2) 92 + #define CMN_PLL1_VCOCAL_OVRD (0xa3 << 2) 93 + #define CMN_PLL1_VCOCAL_INIT (0xa4 << 2) 94 + #define CMN_PLL1_VCOCAL_ITER (0xa5 << 2) 95 + #define CMN_PLL1_LOCK_REFCNT_START (0xb0 << 2) 96 + #define CMN_PLL1_LOCK_PLLCNT_START (0xb2 << 2) 97 + #define CMN_PLL1_LOCK_PLLCNT_THR (0xb3 << 2) 98 + #define CMN_PLL1_INTDIV (0xb4 << 2) 99 + #define CMN_PLL1_FRACDIV (0xb5 << 2) 100 + #define CMN_PLL1_HIGH_THR (0xb6 << 2) 101 + #define CMN_PLL1_DSM_DIAG (0xb7 << 2) 102 + #define CMN_PLL1_SS_CTRL1 (0xb8 << 2) 103 + #define CMN_PLL1_SS_CTRL2 (0xb9 << 2) 104 + #define CMN_RXCAL_OVRD (0xd1 << 2) 105 + #define CMN_TXPUCAL_CTRL (0xe0 << 2) 106 + #define CMN_TXPUCAL_OVRD (0xe1 << 2) 107 + #define CMN_TXPDCAL_OVRD (0xf1 << 2) 108 + #define CMN_DIAG_PLL0_FBH_OVRD (0x1c0 << 2) 109 + #define CMN_DIAG_PLL0_FBL_OVRD (0x1c1 << 2) 110 + #define CMN_DIAG_PLL0_OVRD (0x1c2 << 2) 111 + #define CMN_DIAG_PLL0_V2I_TUNE (0x1c5 << 2) 112 + #define CMN_DIAG_PLL0_CP_TUNE (0x1c6 << 2) 113 + #define CMN_DIAG_PLL0_LF_PROG (0x1c7 << 2) 114 + #define CMN_DIAG_PLL1_FBH_OVRD (0x1d0 << 2) 115 + #define CMN_DIAG_PLL1_FBL_OVRD (0x1d1 << 2) 116 + #define CMN_DIAG_PLL1_OVRD (0x1d2 << 2) 117 + #define CMN_DIAG_PLL1_V2I_TUNE (0x1d5 << 2) 118 + #define CMN_DIAG_PLL1_CP_TUNE (0x1d6 << 2) 119 + #define CMN_DIAG_PLL1_LF_PROG (0x1d7 << 2) 120 + #define CMN_DIAG_PLL1_PTATIS_TUNE1 (0x1d8 << 2) 121 + #define CMN_DIAG_PLL1_PTATIS_TUNE2 (0x1d9 << 2) 122 + #define CMN_DIAG_PLL1_INCLK_CTRL (0x1da << 2) 123 + #define CMN_DIAG_HSCLK_SEL (0x1e0 << 2) 124 + 125 + #define XCVR_PSM_RCTRL(n) ((0x4001 | ((n) << 9)) << 2) 126 + #define XCVR_PSM_CAL_TMR(n) ((0x4002 | ((n) << 9)) << 2) 127 + #define XCVR_PSM_A0IN_TMR(n) ((0x4003 | ((n) << 9)) << 2) 128 + #define TX_TXCC_CAL_SCLR_MULT(n) ((0x4047 | ((n) << 9)) << 2) 129 + #define TX_TXCC_CPOST_MULT_00(n) ((0x404c | ((n) << 9)) << 2) 130 + #define TX_TXCC_CPOST_MULT_01(n) ((0x404d | ((n) << 9)) << 2) 131 + #define TX_TXCC_CPOST_MULT_10(n) ((0x404e | ((n) << 9)) << 2) 132 + #define TX_TXCC_CPOST_MULT_11(n) ((0x404f | ((n) << 9)) << 2) 133 + #define TX_TXCC_MGNFS_MULT_000(n) ((0x4050 | ((n) << 9)) << 2) 134 + #define TX_TXCC_MGNFS_MULT_001(n) ((0x4051 | ((n) << 9)) << 2) 135 + #define TX_TXCC_MGNFS_MULT_010(n) ((0x4052 | ((n) << 9)) << 2) 136 + #define TX_TXCC_MGNFS_MULT_011(n) ((0x4053 | ((n) << 9)) << 2) 137 + #define TX_TXCC_MGNFS_MULT_100(n) ((0x4054 | ((n) << 9)) << 2) 138 + #define TX_TXCC_MGNFS_MULT_101(n) ((0x4055 | ((n) << 9)) << 2) 139 + #define TX_TXCC_MGNFS_MULT_110(n) ((0x4056 | ((n) << 9)) << 2) 140 + #define TX_TXCC_MGNFS_MULT_111(n) ((0x4057 | ((n) << 9)) << 2) 141 + #define XCVR_DIAG_PLLDRC_CTRL(n) ((0x40e0 | ((n) << 9)) << 2) 142 + #define XCVR_DIAG_BIDI_CTRL(n) ((0x40e8 | ((n) << 9)) << 2) 143 + #define XCVR_DIAG_LANE_FCM_EN_MGN(n) ((0x40f2 | ((n) << 9)) << 2) 144 + #define TX_PSC_A0(n) ((0x4100 | ((n) << 9)) << 2) 145 + #define TX_PSC_A1(n) ((0x4101 | ((n) << 9)) << 2) 146 + #define TX_PSC_A2(n) ((0x4102 | ((n) << 9)) << 2) 147 + #define TX_PSC_A3(n) ((0x4103 | ((n) << 9)) << 2) 148 + #define TX_RCVDET_CTRL(n) ((0x4120 | ((n) << 9)) << 2) 149 + #define TX_RCVDET_EN_TMR(n) ((0x4122 | ((n) << 9)) << 2) 150 + #define TX_RCVDET_ST_TMR(n) ((0x4123 | ((n) << 9)) << 2) 151 + #define TX_DIAG_TX_DRV(n) ((0x41e1 | ((n) << 9)) << 2) 152 + #define TX_DIAG_BGREF_PREDRV_DELAY (0x41e7 << 2) 153 + #define TX_ANA_CTRL_REG_1 (0x5020 << 2) 154 + #define TX_ANA_CTRL_REG_2 (0x5021 << 2) 155 + #define TXDA_COEFF_CALC_CTRL (0x5022 << 2) 156 + #define TX_DIG_CTRL_REG_2 (0x5024 << 2) 157 + #define TXDA_CYA_AUXDA_CYA (0x5025 << 2) 158 + #define TX_ANA_CTRL_REG_3 (0x5026 << 2) 159 + #define TX_ANA_CTRL_REG_4 (0x5027 << 2) 160 + #define TX_ANA_CTRL_REG_5 (0x5029 << 2) 161 + 162 + #define RX_PSC_A0(n) ((0x8000 | ((n) << 9)) << 2) 163 + #define RX_PSC_A1(n) ((0x8001 | ((n) << 9)) << 2) 164 + #define RX_PSC_A2(n) ((0x8002 | ((n) << 9)) << 2) 165 + #define RX_PSC_A3(n) ((0x8003 | ((n) << 9)) << 2) 166 + #define RX_PSC_CAL(n) ((0x8006 | ((n) << 9)) << 2) 167 + #define RX_PSC_RDY(n) ((0x8007 | ((n) << 9)) << 2) 168 + #define RX_IQPI_ILL_CAL_OVRD (0x8023 << 2) 169 + #define RX_EPI_ILL_CAL_OVRD (0x8033 << 2) 170 + #define RX_SDCAL0_OVRD (0x8041 << 2) 171 + #define RX_SDCAL1_OVRD (0x8049 << 2) 172 + #define RX_SLC_INIT (0x806d << 2) 173 + #define RX_SLC_RUN (0x806e << 2) 174 + #define RX_CDRLF_CNFG2 (0x8081 << 2) 175 + #define RX_SIGDET_HL_FILT_TMR(n) ((0x8090 | ((n) << 9)) << 2) 176 + #define RX_SLC_IOP0_OVRD (0x8101 << 2) 177 + #define RX_SLC_IOP1_OVRD (0x8105 << 2) 178 + #define RX_SLC_QOP0_OVRD (0x8109 << 2) 179 + #define RX_SLC_QOP1_OVRD (0x810d << 2) 180 + #define RX_SLC_EOP0_OVRD (0x8111 << 2) 181 + #define RX_SLC_EOP1_OVRD (0x8115 << 2) 182 + #define RX_SLC_ION0_OVRD (0x8119 << 2) 183 + #define RX_SLC_ION1_OVRD (0x811d << 2) 184 + #define RX_SLC_QON0_OVRD (0x8121 << 2) 185 + #define RX_SLC_QON1_OVRD (0x8125 << 2) 186 + #define RX_SLC_EON0_OVRD (0x8129 << 2) 187 + #define RX_SLC_EON1_OVRD (0x812d << 2) 188 + #define RX_SLC_IEP0_OVRD (0x8131 << 2) 189 + #define RX_SLC_IEP1_OVRD (0x8135 << 2) 190 + #define RX_SLC_QEP0_OVRD (0x8139 << 2) 191 + #define RX_SLC_QEP1_OVRD (0x813d << 2) 192 + #define RX_SLC_EEP0_OVRD (0x8141 << 2) 193 + #define RX_SLC_EEP1_OVRD (0x8145 << 2) 194 + #define RX_SLC_IEN0_OVRD (0x8149 << 2) 195 + #define RX_SLC_IEN1_OVRD (0x814d << 2) 196 + #define RX_SLC_QEN0_OVRD (0x8151 << 2) 197 + #define RX_SLC_QEN1_OVRD (0x8155 << 2) 198 + #define RX_SLC_EEN0_OVRD (0x8159 << 2) 199 + #define RX_SLC_EEN1_OVRD (0x815d << 2) 200 + #define RX_REE_CTRL_DATA_MASK(n) ((0x81bb | ((n) << 9)) << 2) 201 + #define RX_DIAG_SIGDET_TUNE(n) ((0x81dc | ((n) << 9)) << 2) 202 + #define RX_DIAG_SC2C_DELAY (0x81e1 << 2) 203 + 204 + #define PMA_LANE_CFG (0xc000 << 2) 205 + #define PIPE_CMN_CTRL1 (0xc001 << 2) 206 + #define PIPE_CMN_CTRL2 (0xc002 << 2) 207 + #define PIPE_COM_LOCK_CFG1 (0xc003 << 2) 208 + #define PIPE_COM_LOCK_CFG2 (0xc004 << 2) 209 + #define PIPE_RCV_DET_INH (0xc005 << 2) 210 + #define DP_MODE_CTL (0xc008 << 2) 211 + #define DP_CLK_CTL (0xc009 << 2) 212 + #define STS (0xc00F << 2) 213 + #define PHY_ISO_CMN_CTRL (0xc010 << 2) 214 + #define PHY_DP_TX_CTL (0xc408 << 2) 215 + #define PMA_CMN_CTRL1 (0xc800 << 2) 216 + #define PHY_PMA_ISO_CMN_CTRL (0xc810 << 2) 217 + #define PHY_ISOLATION_CTRL (0xc81f << 2) 218 + #define PHY_PMA_ISO_XCVR_CTRL(n) ((0xcc11 | ((n) << 6)) << 2) 219 + #define PHY_PMA_ISO_LINK_MODE(n) ((0xcc12 | ((n) << 6)) << 2) 220 + #define PHY_PMA_ISO_PWRST_CTRL(n) ((0xcc13 | ((n) << 6)) << 2) 221 + #define PHY_PMA_ISO_TX_DATA_LO(n) ((0xcc14 | ((n) << 6)) << 2) 222 + #define PHY_PMA_ISO_TX_DATA_HI(n) ((0xcc15 | ((n) << 6)) << 2) 223 + #define PHY_PMA_ISO_RX_DATA_LO(n) ((0xcc16 | ((n) << 6)) << 2) 224 + #define PHY_PMA_ISO_RX_DATA_HI(n) ((0xcc17 | ((n) << 6)) << 2) 225 + #define TX_BIST_CTRL(n) ((0x4140 | ((n) << 9)) << 2) 226 + #define TX_BIST_UDDWR(n) ((0x4141 | ((n) << 9)) << 2) 227 + 228 + /* 229 + * Selects which PLL clock will be driven on the analog high speed 230 + * clock 0: PLL 0 div 1 231 + * clock 1: PLL 1 div 2 232 + */ 233 + #define CLK_PLL_CONFIG 0X30 234 + #define CLK_PLL_MASK 0x33 235 + 236 + #define CMN_READY BIT(0) 237 + 238 + #define DP_PLL_CLOCK_ENABLE BIT(2) 239 + #define DP_PLL_ENABLE BIT(0) 240 + #define DP_PLL_DATA_RATE_RBR ((2 << 12) | (4 << 8)) 241 + #define DP_PLL_DATA_RATE_HBR ((2 << 12) | (4 << 8)) 242 + #define DP_PLL_DATA_RATE_HBR2 ((1 << 12) | (2 << 8)) 243 + 244 + #define DP_MODE_A0 BIT(4) 245 + #define DP_MODE_A2 BIT(6) 246 + #define DP_MODE_ENTER_A0 0xc101 247 + #define DP_MODE_ENTER_A2 0xc104 248 + 249 + #define PHY_MODE_SET_TIMEOUT 100000 250 + 251 + #define PIN_ASSIGN_C_E 0x51d9 252 + #define PIN_ASSIGN_D_F 0x5100 253 + 254 + #define MODE_DISCONNECT 0 255 + #define MODE_UFP_USB BIT(0) 256 + #define MODE_DFP_USB BIT(1) 257 + #define MODE_DFP_DP BIT(2) 258 + 259 + struct usb3phy_reg { 260 + u32 offset; 261 + u32 enable_bit; 262 + u32 write_enable; 263 + }; 264 + 265 + struct rockchip_usb3phy_port_cfg { 266 + struct usb3phy_reg typec_conn_dir; 267 + struct usb3phy_reg usb3tousb2_en; 268 + struct usb3phy_reg external_psm; 269 + struct usb3phy_reg pipe_status; 270 + }; 271 + 272 + struct rockchip_typec_phy { 273 + struct device *dev; 274 + void __iomem *base; 275 + struct extcon_dev *extcon; 276 + struct regmap *grf_regs; 277 + struct clk *clk_core; 278 + struct clk *clk_ref; 279 + struct reset_control *uphy_rst; 280 + struct reset_control *pipe_rst; 281 + struct reset_control *tcphy_rst; 282 + struct rockchip_usb3phy_port_cfg port_cfgs; 283 + /* mutex to protect access to individual PHYs */ 284 + struct mutex lock; 285 + 286 + bool flip; 287 + u8 mode; 288 + }; 289 + 290 + struct phy_reg { 291 + u16 value; 292 + u32 addr; 293 + }; 294 + 295 + struct phy_reg usb3_pll_cfg[] = { 296 + { 0xf0, CMN_PLL0_VCOCAL_INIT }, 297 + { 0x18, CMN_PLL0_VCOCAL_ITER }, 298 + { 0xd0, CMN_PLL0_INTDIV }, 299 + { 0x4a4a, CMN_PLL0_FRACDIV }, 300 + { 0x34, CMN_PLL0_HIGH_THR }, 301 + { 0x1ee, CMN_PLL0_SS_CTRL1 }, 302 + { 0x7f03, CMN_PLL0_SS_CTRL2 }, 303 + { 0x20, CMN_PLL0_DSM_DIAG }, 304 + { 0, CMN_DIAG_PLL0_OVRD }, 305 + { 0, CMN_DIAG_PLL0_FBH_OVRD }, 306 + { 0, CMN_DIAG_PLL0_FBL_OVRD }, 307 + { 0x7, CMN_DIAG_PLL0_V2I_TUNE }, 308 + { 0x45, CMN_DIAG_PLL0_CP_TUNE }, 309 + { 0x8, CMN_DIAG_PLL0_LF_PROG }, 310 + }; 311 + 312 + struct phy_reg dp_pll_cfg[] = { 313 + { 0xf0, CMN_PLL1_VCOCAL_INIT }, 314 + { 0x18, CMN_PLL1_VCOCAL_ITER }, 315 + { 0x30b9, CMN_PLL1_VCOCAL_START }, 316 + { 0x21c, CMN_PLL1_INTDIV }, 317 + { 0, CMN_PLL1_FRACDIV }, 318 + { 0x5, CMN_PLL1_HIGH_THR }, 319 + { 0x35, CMN_PLL1_SS_CTRL1 }, 320 + { 0x7f1e, CMN_PLL1_SS_CTRL2 }, 321 + { 0x20, CMN_PLL1_DSM_DIAG }, 322 + { 0, CMN_PLLSM1_USER_DEF_CTRL }, 323 + { 0, CMN_DIAG_PLL1_OVRD }, 324 + { 0, CMN_DIAG_PLL1_FBH_OVRD }, 325 + { 0, CMN_DIAG_PLL1_FBL_OVRD }, 326 + { 0x6, CMN_DIAG_PLL1_V2I_TUNE }, 327 + { 0x45, CMN_DIAG_PLL1_CP_TUNE }, 328 + { 0x8, CMN_DIAG_PLL1_LF_PROG }, 329 + { 0x100, CMN_DIAG_PLL1_PTATIS_TUNE1 }, 330 + { 0x7, CMN_DIAG_PLL1_PTATIS_TUNE2 }, 331 + { 0x4, CMN_DIAG_PLL1_INCLK_CTRL }, 332 + }; 333 + 334 + static void tcphy_cfg_24m(struct rockchip_typec_phy *tcphy) 335 + { 336 + u32 i, rdata; 337 + 338 + /* 339 + * cmn_ref_clk_sel = 3, select the 24Mhz for clk parent 340 + * cmn_psm_clk_dig_div = 2, set the clk division to 2 341 + */ 342 + writel(0x830, tcphy->base + PMA_CMN_CTRL1); 343 + for (i = 0; i < 4; i++) { 344 + /* 345 + * The following PHY configuration assumes a 24 MHz reference 346 + * clock. 347 + */ 348 + writel(0x90, tcphy->base + XCVR_DIAG_LANE_FCM_EN_MGN(i)); 349 + writel(0x960, tcphy->base + TX_RCVDET_EN_TMR(i)); 350 + writel(0x30, tcphy->base + TX_RCVDET_ST_TMR(i)); 351 + } 352 + 353 + rdata = readl(tcphy->base + CMN_DIAG_HSCLK_SEL); 354 + rdata &= ~CLK_PLL_MASK; 355 + rdata |= CLK_PLL_CONFIG; 356 + writel(rdata, tcphy->base + CMN_DIAG_HSCLK_SEL); 357 + } 358 + 359 + static void tcphy_cfg_usb3_pll(struct rockchip_typec_phy *tcphy) 360 + { 361 + u32 i; 362 + 363 + /* load the configuration of PLL0 */ 364 + for (i = 0; i < ARRAY_SIZE(usb3_pll_cfg); i++) 365 + writel(usb3_pll_cfg[i].value, 366 + tcphy->base + usb3_pll_cfg[i].addr); 367 + } 368 + 369 + static void tcphy_cfg_dp_pll(struct rockchip_typec_phy *tcphy) 370 + { 371 + u32 i; 372 + 373 + /* set the default mode to RBR */ 374 + writel(DP_PLL_CLOCK_ENABLE | DP_PLL_ENABLE | DP_PLL_DATA_RATE_RBR, 375 + tcphy->base + DP_CLK_CTL); 376 + 377 + /* load the configuration of PLL1 */ 378 + for (i = 0; i < ARRAY_SIZE(dp_pll_cfg); i++) 379 + writel(dp_pll_cfg[i].value, tcphy->base + dp_pll_cfg[i].addr); 380 + } 381 + 382 + static void tcphy_tx_usb3_cfg_lane(struct rockchip_typec_phy *tcphy, u32 lane) 383 + { 384 + writel(0x7799, tcphy->base + TX_PSC_A0(lane)); 385 + writel(0x7798, tcphy->base + TX_PSC_A1(lane)); 386 + writel(0x5098, tcphy->base + TX_PSC_A2(lane)); 387 + writel(0x5098, tcphy->base + TX_PSC_A3(lane)); 388 + writel(0, tcphy->base + TX_TXCC_MGNFS_MULT_000(lane)); 389 + writel(0xbf, tcphy->base + XCVR_DIAG_BIDI_CTRL(lane)); 390 + } 391 + 392 + static void tcphy_rx_usb3_cfg_lane(struct rockchip_typec_phy *tcphy, u32 lane) 393 + { 394 + writel(0xa6fd, tcphy->base + RX_PSC_A0(lane)); 395 + writel(0xa6fd, tcphy->base + RX_PSC_A1(lane)); 396 + writel(0xa410, tcphy->base + RX_PSC_A2(lane)); 397 + writel(0x2410, tcphy->base + RX_PSC_A3(lane)); 398 + writel(0x23ff, tcphy->base + RX_PSC_CAL(lane)); 399 + writel(0x13, tcphy->base + RX_SIGDET_HL_FILT_TMR(lane)); 400 + writel(0x03e7, tcphy->base + RX_REE_CTRL_DATA_MASK(lane)); 401 + writel(0x1004, tcphy->base + RX_DIAG_SIGDET_TUNE(lane)); 402 + writel(0x2010, tcphy->base + RX_PSC_RDY(lane)); 403 + writel(0xfb, tcphy->base + XCVR_DIAG_BIDI_CTRL(lane)); 404 + } 405 + 406 + static void tcphy_dp_cfg_lane(struct rockchip_typec_phy *tcphy, u32 lane) 407 + { 408 + u16 rdata; 409 + 410 + writel(0xbefc, tcphy->base + XCVR_PSM_RCTRL(lane)); 411 + writel(0x6799, tcphy->base + TX_PSC_A0(lane)); 412 + writel(0x6798, tcphy->base + TX_PSC_A1(lane)); 413 + writel(0x98, tcphy->base + TX_PSC_A2(lane)); 414 + writel(0x98, tcphy->base + TX_PSC_A3(lane)); 415 + 416 + writel(0, tcphy->base + TX_TXCC_MGNFS_MULT_000(lane)); 417 + writel(0, tcphy->base + TX_TXCC_MGNFS_MULT_001(lane)); 418 + writel(0, tcphy->base + TX_TXCC_MGNFS_MULT_010(lane)); 419 + writel(0, tcphy->base + TX_TXCC_MGNFS_MULT_011(lane)); 420 + writel(0, tcphy->base + TX_TXCC_MGNFS_MULT_100(lane)); 421 + writel(0, tcphy->base + TX_TXCC_MGNFS_MULT_101(lane)); 422 + writel(0, tcphy->base + TX_TXCC_MGNFS_MULT_110(lane)); 423 + writel(0, tcphy->base + TX_TXCC_MGNFS_MULT_111(lane)); 424 + writel(0, tcphy->base + TX_TXCC_CPOST_MULT_10(lane)); 425 + writel(0, tcphy->base + TX_TXCC_CPOST_MULT_01(lane)); 426 + writel(0, tcphy->base + TX_TXCC_CPOST_MULT_00(lane)); 427 + writel(0, tcphy->base + TX_TXCC_CPOST_MULT_11(lane)); 428 + 429 + writel(0x128, tcphy->base + TX_TXCC_CAL_SCLR_MULT(lane)); 430 + writel(0x400, tcphy->base + TX_DIAG_TX_DRV(lane)); 431 + 432 + rdata = readl(tcphy->base + XCVR_DIAG_PLLDRC_CTRL(lane)); 433 + rdata = (rdata & 0x8fff) | 0x6000; 434 + writel(rdata, tcphy->base + XCVR_DIAG_PLLDRC_CTRL(lane)); 435 + } 436 + 437 + static inline int property_enable(struct rockchip_typec_phy *tcphy, 438 + const struct usb3phy_reg *reg, bool en) 439 + { 440 + u32 mask = 1 << reg->write_enable; 441 + u32 val = en << reg->enable_bit; 442 + 443 + return regmap_write(tcphy->grf_regs, reg->offset, val | mask); 444 + } 445 + 446 + static void tcphy_dp_aux_calibration(struct rockchip_typec_phy *tcphy) 447 + { 448 + u16 rdata, rdata2, val; 449 + 450 + /* disable txda_cal_latch_en for rewrite the calibration values */ 451 + rdata = readl(tcphy->base + TX_ANA_CTRL_REG_1); 452 + val = rdata & 0xdfff; 453 + writel(val, tcphy->base + TX_ANA_CTRL_REG_1); 454 + 455 + /* 456 + * read a resistor calibration code from CMN_TXPUCAL_CTRL[6:0] and 457 + * write it to TX_DIG_CTRL_REG_2[6:0], and delay 1ms to make sure it 458 + * works. 459 + */ 460 + rdata = readl(tcphy->base + TX_DIG_CTRL_REG_2); 461 + rdata = rdata & 0xffc0; 462 + 463 + rdata2 = readl(tcphy->base + CMN_TXPUCAL_CTRL); 464 + rdata2 = rdata2 & 0x3f; 465 + 466 + val = rdata | rdata2; 467 + writel(val, tcphy->base + TX_DIG_CTRL_REG_2); 468 + usleep_range(1000, 1050); 469 + 470 + /* 471 + * Enable signal for latch that sample and holds calibration values. 472 + * Activate this signal for 1 clock cycle to sample new calibration 473 + * values. 474 + */ 475 + rdata = readl(tcphy->base + TX_ANA_CTRL_REG_1); 476 + val = rdata | 0x2000; 477 + writel(val, tcphy->base + TX_ANA_CTRL_REG_1); 478 + usleep_range(150, 200); 479 + 480 + /* set TX Voltage Level and TX Deemphasis to 0 */ 481 + writel(0, tcphy->base + PHY_DP_TX_CTL); 482 + /* re-enable decap */ 483 + writel(0x100, tcphy->base + TX_ANA_CTRL_REG_2); 484 + writel(0x300, tcphy->base + TX_ANA_CTRL_REG_2); 485 + writel(0x2008, tcphy->base + TX_ANA_CTRL_REG_1); 486 + writel(0x2018, tcphy->base + TX_ANA_CTRL_REG_1); 487 + 488 + writel(0, tcphy->base + TX_ANA_CTRL_REG_5); 489 + 490 + /* 491 + * Programs txda_drv_ldo_prog[15:0], Sets driver LDO 492 + * voltage 16'h1001 for DP-AUX-TX and RX 493 + */ 494 + writel(0x1001, tcphy->base + TX_ANA_CTRL_REG_4); 495 + 496 + /* re-enables Bandgap reference for LDO */ 497 + writel(0x2098, tcphy->base + TX_ANA_CTRL_REG_1); 498 + writel(0x2198, tcphy->base + TX_ANA_CTRL_REG_1); 499 + 500 + /* 501 + * re-enables the transmitter pre-driver, driver data selection MUX, 502 + * and receiver detect circuits. 503 + */ 504 + writel(0x301, tcphy->base + TX_ANA_CTRL_REG_2); 505 + writel(0x303, tcphy->base + TX_ANA_CTRL_REG_2); 506 + 507 + /* 508 + * BIT 12: Controls auxda_polarity, which selects the polarity of the 509 + * xcvr: 510 + * 1, Reverses the polarity (If TYPEC, Pulls ups aux_p and pull 511 + * down aux_m) 512 + * 0, Normal polarity (if TYPE_C, pulls up aux_m and pulls down 513 + * aux_p) 514 + */ 515 + val = 0xa078; 516 + if (!tcphy->flip) 517 + val |= BIT(12); 518 + writel(val, tcphy->base + TX_ANA_CTRL_REG_1); 519 + 520 + writel(0, tcphy->base + TX_ANA_CTRL_REG_3); 521 + writel(0, tcphy->base + TX_ANA_CTRL_REG_4); 522 + writel(0, tcphy->base + TX_ANA_CTRL_REG_5); 523 + 524 + /* 525 + * Controls low_power_swing_en, set the voltage swing of the driver 526 + * to 400mv. The values below are peak to peak (differential) values. 527 + */ 528 + writel(4, tcphy->base + TXDA_COEFF_CALC_CTRL); 529 + writel(0, tcphy->base + TXDA_CYA_AUXDA_CYA); 530 + 531 + /* Controls tx_high_z_tm_en */ 532 + val = readl(tcphy->base + TX_DIG_CTRL_REG_2); 533 + val |= BIT(15); 534 + writel(val, tcphy->base + TX_DIG_CTRL_REG_2); 535 + } 536 + 537 + static int tcphy_phy_init(struct rockchip_typec_phy *tcphy, u8 mode) 538 + { 539 + struct rockchip_usb3phy_port_cfg *cfg = &tcphy->port_cfgs; 540 + int ret, i; 541 + u32 val; 542 + 543 + ret = clk_prepare_enable(tcphy->clk_core); 544 + if (ret) { 545 + dev_err(tcphy->dev, "Failed to prepare_enable core clock\n"); 546 + return ret; 547 + } 548 + 549 + ret = clk_prepare_enable(tcphy->clk_ref); 550 + if (ret) { 551 + dev_err(tcphy->dev, "Failed to prepare_enable ref clock\n"); 552 + goto err_clk_core; 553 + } 554 + 555 + reset_control_deassert(tcphy->tcphy_rst); 556 + 557 + property_enable(tcphy, &cfg->typec_conn_dir, tcphy->flip); 558 + 559 + tcphy_cfg_24m(tcphy); 560 + 561 + if (mode == MODE_DFP_DP) { 562 + tcphy_cfg_dp_pll(tcphy); 563 + for (i = 0; i < 4; i++) 564 + tcphy_dp_cfg_lane(tcphy, i); 565 + 566 + writel(PIN_ASSIGN_C_E, tcphy->base + PMA_LANE_CFG); 567 + } else { 568 + tcphy_cfg_usb3_pll(tcphy); 569 + tcphy_cfg_dp_pll(tcphy); 570 + if (tcphy->flip) { 571 + tcphy_tx_usb3_cfg_lane(tcphy, 3); 572 + tcphy_rx_usb3_cfg_lane(tcphy, 2); 573 + tcphy_dp_cfg_lane(tcphy, 0); 574 + tcphy_dp_cfg_lane(tcphy, 1); 575 + } else { 576 + tcphy_tx_usb3_cfg_lane(tcphy, 0); 577 + tcphy_rx_usb3_cfg_lane(tcphy, 1); 578 + tcphy_dp_cfg_lane(tcphy, 2); 579 + tcphy_dp_cfg_lane(tcphy, 3); 580 + } 581 + 582 + writel(PIN_ASSIGN_D_F, tcphy->base + PMA_LANE_CFG); 583 + } 584 + 585 + writel(DP_MODE_ENTER_A2, tcphy->base + DP_MODE_CTL); 586 + 587 + reset_control_deassert(tcphy->uphy_rst); 588 + 589 + ret = readx_poll_timeout(readl, tcphy->base + PMA_CMN_CTRL1, 590 + val, val & CMN_READY, 10, 591 + PHY_MODE_SET_TIMEOUT); 592 + if (ret < 0) { 593 + dev_err(tcphy->dev, "wait pma ready timeout\n"); 594 + ret = -ETIMEDOUT; 595 + goto err_wait_pma; 596 + } 597 + 598 + reset_control_deassert(tcphy->pipe_rst); 599 + 600 + return 0; 601 + 602 + err_wait_pma: 603 + reset_control_assert(tcphy->uphy_rst); 604 + reset_control_assert(tcphy->tcphy_rst); 605 + clk_disable_unprepare(tcphy->clk_ref); 606 + err_clk_core: 607 + clk_disable_unprepare(tcphy->clk_core); 608 + return ret; 609 + } 610 + 611 + static void tcphy_phy_deinit(struct rockchip_typec_phy *tcphy) 612 + { 613 + reset_control_assert(tcphy->tcphy_rst); 614 + reset_control_assert(tcphy->uphy_rst); 615 + reset_control_assert(tcphy->pipe_rst); 616 + clk_disable_unprepare(tcphy->clk_core); 617 + clk_disable_unprepare(tcphy->clk_ref); 618 + } 619 + 620 + static int tcphy_get_mode(struct rockchip_typec_phy *tcphy) 621 + { 622 + struct extcon_dev *edev = tcphy->extcon; 623 + union extcon_property_value property; 624 + unsigned int id; 625 + bool dfp, ufp, dp; 626 + u8 mode; 627 + int ret; 628 + 629 + ufp = extcon_get_state(edev, EXTCON_USB); 630 + dfp = extcon_get_state(edev, EXTCON_USB_HOST); 631 + dp = extcon_get_state(edev, EXTCON_DISP_DP); 632 + 633 + mode = MODE_DFP_USB; 634 + id = EXTCON_USB_HOST; 635 + 636 + if (ufp) { 637 + mode = MODE_UFP_USB; 638 + id = EXTCON_USB; 639 + } else if (dp) { 640 + mode = MODE_DFP_DP; 641 + id = EXTCON_DISP_DP; 642 + 643 + ret = extcon_get_property(edev, id, EXTCON_PROP_USB_SS, 644 + &property); 645 + if (ret) { 646 + dev_err(tcphy->dev, "get superspeed property failed\n"); 647 + return ret; 648 + } 649 + 650 + if (property.intval) 651 + mode |= MODE_DFP_USB; 652 + } 653 + 654 + ret = extcon_get_property(edev, id, EXTCON_PROP_USB_TYPEC_POLARITY, 655 + &property); 656 + if (ret) { 657 + dev_err(tcphy->dev, "get polarity property failed\n"); 658 + return ret; 659 + } 660 + 661 + tcphy->flip = property.intval ? 1 : 0; 662 + 663 + return mode; 664 + } 665 + 666 + static int rockchip_usb3_phy_power_on(struct phy *phy) 667 + { 668 + struct rockchip_typec_phy *tcphy = phy_get_drvdata(phy); 669 + struct rockchip_usb3phy_port_cfg *cfg = &tcphy->port_cfgs; 670 + const struct usb3phy_reg *reg = &cfg->pipe_status; 671 + int timeout, new_mode, ret = 0; 672 + u32 val; 673 + 674 + mutex_lock(&tcphy->lock); 675 + 676 + new_mode = tcphy_get_mode(tcphy); 677 + if (new_mode < 0) { 678 + ret = new_mode; 679 + goto unlock_ret; 680 + } 681 + 682 + /* DP-only mode; fall back to USB2 */ 683 + if (!(new_mode & (MODE_DFP_USB | MODE_UFP_USB))) 684 + goto unlock_ret; 685 + 686 + if (tcphy->mode == new_mode) 687 + goto unlock_ret; 688 + 689 + if (tcphy->mode == MODE_DISCONNECT) 690 + tcphy_phy_init(tcphy, new_mode); 691 + 692 + /* wait TCPHY for pipe ready */ 693 + for (timeout = 0; timeout < 100; timeout++) { 694 + regmap_read(tcphy->grf_regs, reg->offset, &val); 695 + if (!(val & BIT(reg->enable_bit))) { 696 + tcphy->mode |= new_mode & (MODE_DFP_USB | MODE_UFP_USB); 697 + goto unlock_ret; 698 + } 699 + usleep_range(10, 20); 700 + } 701 + 702 + if (tcphy->mode == MODE_DISCONNECT) 703 + tcphy_phy_deinit(tcphy); 704 + 705 + ret = -ETIMEDOUT; 706 + 707 + unlock_ret: 708 + mutex_unlock(&tcphy->lock); 709 + return ret; 710 + } 711 + 712 + static int rockchip_usb3_phy_power_off(struct phy *phy) 713 + { 714 + struct rockchip_typec_phy *tcphy = phy_get_drvdata(phy); 715 + 716 + mutex_lock(&tcphy->lock); 717 + 718 + if (tcphy->mode == MODE_DISCONNECT) 719 + goto unlock; 720 + 721 + tcphy->mode &= ~(MODE_UFP_USB | MODE_DFP_USB); 722 + if (tcphy->mode == MODE_DISCONNECT) 723 + tcphy_phy_deinit(tcphy); 724 + 725 + unlock: 726 + mutex_unlock(&tcphy->lock); 727 + return 0; 728 + } 729 + 730 + static const struct phy_ops rockchip_usb3_phy_ops = { 731 + .power_on = rockchip_usb3_phy_power_on, 732 + .power_off = rockchip_usb3_phy_power_off, 733 + .owner = THIS_MODULE, 734 + }; 735 + 736 + static int rockchip_dp_phy_power_on(struct phy *phy) 737 + { 738 + struct rockchip_typec_phy *tcphy = phy_get_drvdata(phy); 739 + int new_mode, ret = 0; 740 + u32 val; 741 + 742 + mutex_lock(&tcphy->lock); 743 + 744 + new_mode = tcphy_get_mode(tcphy); 745 + if (new_mode < 0) { 746 + ret = new_mode; 747 + goto unlock_ret; 748 + } 749 + 750 + if (!(new_mode & MODE_DFP_DP)) { 751 + ret = -ENODEV; 752 + goto unlock_ret; 753 + } 754 + 755 + if (tcphy->mode == new_mode) 756 + goto unlock_ret; 757 + 758 + /* 759 + * If the PHY has been power on, but the mode is not DP only mode, 760 + * re-init the PHY for setting all of 4 lanes to DP. 761 + */ 762 + if (new_mode == MODE_DFP_DP && tcphy->mode != MODE_DISCONNECT) { 763 + tcphy_phy_deinit(tcphy); 764 + tcphy_phy_init(tcphy, new_mode); 765 + } else if (tcphy->mode == MODE_DISCONNECT) { 766 + tcphy_phy_init(tcphy, new_mode); 767 + } 768 + 769 + ret = readx_poll_timeout(readl, tcphy->base + DP_MODE_CTL, 770 + val, val & DP_MODE_A2, 1000, 771 + PHY_MODE_SET_TIMEOUT); 772 + if (ret < 0) { 773 + dev_err(tcphy->dev, "failed to wait TCPHY enter A2\n"); 774 + goto power_on_finish; 775 + } 776 + 777 + tcphy_dp_aux_calibration(tcphy); 778 + 779 + writel(DP_MODE_ENTER_A0, tcphy->base + DP_MODE_CTL); 780 + 781 + ret = readx_poll_timeout(readl, tcphy->base + DP_MODE_CTL, 782 + val, val & DP_MODE_A0, 1000, 783 + PHY_MODE_SET_TIMEOUT); 784 + if (ret < 0) { 785 + writel(DP_MODE_ENTER_A2, tcphy->base + DP_MODE_CTL); 786 + dev_err(tcphy->dev, "failed to wait TCPHY enter A0\n"); 787 + goto power_on_finish; 788 + } 789 + 790 + tcphy->mode |= MODE_DFP_DP; 791 + 792 + power_on_finish: 793 + if (tcphy->mode == MODE_DISCONNECT) 794 + tcphy_phy_deinit(tcphy); 795 + unlock_ret: 796 + mutex_unlock(&tcphy->lock); 797 + return ret; 798 + } 799 + 800 + static int rockchip_dp_phy_power_off(struct phy *phy) 801 + { 802 + struct rockchip_typec_phy *tcphy = phy_get_drvdata(phy); 803 + 804 + mutex_lock(&tcphy->lock); 805 + 806 + if (tcphy->mode == MODE_DISCONNECT) 807 + goto unlock; 808 + 809 + tcphy->mode &= ~MODE_DFP_DP; 810 + 811 + writel(DP_MODE_ENTER_A2, tcphy->base + DP_MODE_CTL); 812 + 813 + if (tcphy->mode == MODE_DISCONNECT) 814 + tcphy_phy_deinit(tcphy); 815 + 816 + unlock: 817 + mutex_unlock(&tcphy->lock); 818 + return 0; 819 + } 820 + 821 + static const struct phy_ops rockchip_dp_phy_ops = { 822 + .power_on = rockchip_dp_phy_power_on, 823 + .power_off = rockchip_dp_phy_power_off, 824 + .owner = THIS_MODULE, 825 + }; 826 + 827 + static int tcphy_get_param(struct device *dev, 828 + struct usb3phy_reg *reg, 829 + const char *name) 830 + { 831 + u32 buffer[3]; 832 + int ret; 833 + 834 + ret = of_property_read_u32_array(dev->of_node, name, buffer, 3); 835 + if (ret) { 836 + dev_err(dev, "Can not parse %s\n", name); 837 + return ret; 838 + } 839 + 840 + reg->offset = buffer[0]; 841 + reg->enable_bit = buffer[1]; 842 + reg->write_enable = buffer[2]; 843 + return 0; 844 + } 845 + 846 + static int tcphy_parse_dt(struct rockchip_typec_phy *tcphy, 847 + struct device *dev) 848 + { 849 + struct rockchip_usb3phy_port_cfg *cfg = &tcphy->port_cfgs; 850 + int ret; 851 + 852 + ret = tcphy_get_param(dev, &cfg->typec_conn_dir, 853 + "rockchip,typec-conn-dir"); 854 + if (ret) 855 + return ret; 856 + 857 + ret = tcphy_get_param(dev, &cfg->usb3tousb2_en, 858 + "rockchip,usb3tousb2-en"); 859 + if (ret) 860 + return ret; 861 + 862 + ret = tcphy_get_param(dev, &cfg->external_psm, 863 + "rockchip,external-psm"); 864 + if (ret) 865 + return ret; 866 + 867 + ret = tcphy_get_param(dev, &cfg->pipe_status, 868 + "rockchip,pipe-status"); 869 + if (ret) 870 + return ret; 871 + 872 + tcphy->grf_regs = syscon_regmap_lookup_by_phandle(dev->of_node, 873 + "rockchip,grf"); 874 + if (IS_ERR(tcphy->grf_regs)) { 875 + dev_err(dev, "could not find grf dt node\n"); 876 + return PTR_ERR(tcphy->grf_regs); 877 + } 878 + 879 + tcphy->clk_core = devm_clk_get(dev, "tcpdcore"); 880 + if (IS_ERR(tcphy->clk_core)) { 881 + dev_err(dev, "could not get uphy core clock\n"); 882 + return PTR_ERR(tcphy->clk_core); 883 + } 884 + 885 + tcphy->clk_ref = devm_clk_get(dev, "tcpdphy-ref"); 886 + if (IS_ERR(tcphy->clk_ref)) { 887 + dev_err(dev, "could not get uphy ref clock\n"); 888 + return PTR_ERR(tcphy->clk_ref); 889 + } 890 + 891 + tcphy->uphy_rst = devm_reset_control_get(dev, "uphy"); 892 + if (IS_ERR(tcphy->uphy_rst)) { 893 + dev_err(dev, "no uphy_rst reset control found\n"); 894 + return PTR_ERR(tcphy->uphy_rst); 895 + } 896 + 897 + tcphy->pipe_rst = devm_reset_control_get(dev, "uphy-pipe"); 898 + if (IS_ERR(tcphy->pipe_rst)) { 899 + dev_err(dev, "no pipe_rst reset control found\n"); 900 + return PTR_ERR(tcphy->pipe_rst); 901 + } 902 + 903 + tcphy->tcphy_rst = devm_reset_control_get(dev, "uphy-tcphy"); 904 + if (IS_ERR(tcphy->tcphy_rst)) { 905 + dev_err(dev, "no tcphy_rst reset control found\n"); 906 + return PTR_ERR(tcphy->tcphy_rst); 907 + } 908 + 909 + return 0; 910 + } 911 + 912 + static void typec_phy_pre_init(struct rockchip_typec_phy *tcphy) 913 + { 914 + struct rockchip_usb3phy_port_cfg *cfg = &tcphy->port_cfgs; 915 + 916 + reset_control_assert(tcphy->tcphy_rst); 917 + reset_control_assert(tcphy->uphy_rst); 918 + reset_control_assert(tcphy->pipe_rst); 919 + 920 + /* select external psm clock */ 921 + property_enable(tcphy, &cfg->external_psm, 1); 922 + property_enable(tcphy, &cfg->usb3tousb2_en, 0); 923 + 924 + tcphy->mode = MODE_DISCONNECT; 925 + } 926 + 927 + static int rockchip_typec_phy_probe(struct platform_device *pdev) 928 + { 929 + struct device *dev = &pdev->dev; 930 + struct device_node *np = dev->of_node; 931 + struct device_node *child_np; 932 + struct rockchip_typec_phy *tcphy; 933 + struct phy_provider *phy_provider; 934 + struct resource *res; 935 + int ret; 936 + 937 + tcphy = devm_kzalloc(dev, sizeof(*tcphy), GFP_KERNEL); 938 + if (!tcphy) 939 + return -ENOMEM; 940 + 941 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 942 + tcphy->base = devm_ioremap_resource(dev, res); 943 + if (IS_ERR(tcphy->base)) 944 + return PTR_ERR(tcphy->base); 945 + 946 + ret = tcphy_parse_dt(tcphy, dev); 947 + if (ret) 948 + return ret; 949 + 950 + tcphy->dev = dev; 951 + platform_set_drvdata(pdev, tcphy); 952 + mutex_init(&tcphy->lock); 953 + 954 + typec_phy_pre_init(tcphy); 955 + 956 + tcphy->extcon = extcon_get_edev_by_phandle(dev, 0); 957 + if (IS_ERR(tcphy->extcon)) { 958 + if (PTR_ERR(tcphy->extcon) != -EPROBE_DEFER) 959 + dev_err(dev, "Invalid or missing extcon\n"); 960 + return PTR_ERR(tcphy->extcon); 961 + } 962 + 963 + pm_runtime_enable(dev); 964 + 965 + for_each_available_child_of_node(np, child_np) { 966 + struct phy *phy; 967 + 968 + if (!of_node_cmp(child_np->name, "dp-port")) 969 + phy = devm_phy_create(dev, child_np, 970 + &rockchip_dp_phy_ops); 971 + else if (!of_node_cmp(child_np->name, "usb3-port")) 972 + phy = devm_phy_create(dev, child_np, 973 + &rockchip_usb3_phy_ops); 974 + else 975 + continue; 976 + 977 + if (IS_ERR(phy)) { 978 + dev_err(dev, "failed to create phy: %s\n", 979 + child_np->name); 980 + return PTR_ERR(phy); 981 + } 982 + 983 + phy_set_drvdata(phy, tcphy); 984 + } 985 + 986 + phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate); 987 + if (IS_ERR(phy_provider)) { 988 + dev_err(dev, "Failed to register phy provider\n"); 989 + return PTR_ERR(phy_provider); 990 + } 991 + 992 + return 0; 993 + } 994 + 995 + static int rockchip_typec_phy_remove(struct platform_device *pdev) 996 + { 997 + pm_runtime_disable(&pdev->dev); 998 + 999 + return 0; 1000 + } 1001 + 1002 + static const struct of_device_id rockchip_typec_phy_dt_ids[] = { 1003 + { .compatible = "rockchip,rk3399-typec-phy" }, 1004 + {} 1005 + }; 1006 + 1007 + MODULE_DEVICE_TABLE(of, rockchip_typec_phy_dt_ids); 1008 + 1009 + static struct platform_driver rockchip_typec_phy_driver = { 1010 + .probe = rockchip_typec_phy_probe, 1011 + .remove = rockchip_typec_phy_remove, 1012 + .driver = { 1013 + .name = "rockchip-typec-phy", 1014 + .of_match_table = rockchip_typec_phy_dt_ids, 1015 + }, 1016 + }; 1017 + 1018 + module_platform_driver(rockchip_typec_phy_driver); 1019 + 1020 + MODULE_AUTHOR("Chris Zhong <zyw@rock-chips.com>"); 1021 + MODULE_AUTHOR("Kever Yang <kever.yang@rock-chips.com>"); 1022 + MODULE_DESCRIPTION("Rockchip USB TYPE-C PHY driver"); 1023 + MODULE_LICENSE("GPL v2");
+20
drivers/phy/phy-rockchip-usb.c
··· 29 29 #include <linux/reset.h> 30 30 #include <linux/regmap.h> 31 31 #include <linux/mfd/syscon.h> 32 + #include <linux/delay.h> 32 33 33 34 static int enable_usb_uart; 34 35 ··· 65 64 struct clk_hw clk480m_hw; 66 65 struct phy *phy; 67 66 bool uart_enabled; 67 + struct reset_control *reset; 68 68 }; 69 69 70 70 static int rockchip_usb_phy_power(struct rockchip_usb_phy *phy, ··· 146 144 return clk_prepare_enable(phy->clk480m); 147 145 } 148 146 147 + static int rockchip_usb_phy_reset(struct phy *_phy) 148 + { 149 + struct rockchip_usb_phy *phy = phy_get_drvdata(_phy); 150 + 151 + if (phy->reset) { 152 + reset_control_assert(phy->reset); 153 + udelay(10); 154 + reset_control_deassert(phy->reset); 155 + } 156 + 157 + return 0; 158 + } 159 + 149 160 static const struct phy_ops ops = { 150 161 .power_on = rockchip_usb_phy_power_on, 151 162 .power_off = rockchip_usb_phy_power_off, 163 + .reset = rockchip_usb_phy_reset, 152 164 .owner = THIS_MODULE, 153 165 }; 154 166 ··· 200 184 child->name); 201 185 return -EINVAL; 202 186 } 187 + 188 + rk_phy->reset = of_reset_control_get(child, "phy-reset"); 189 + if (IS_ERR(rk_phy->reset)) 190 + rk_phy->reset = NULL; 203 191 204 192 rk_phy->reg_offset = reg_offset; 205 193
+99 -55
drivers/phy/phy-sun4i-usb.c
··· 40 40 #include <linux/power_supply.h> 41 41 #include <linux/regulator/consumer.h> 42 42 #include <linux/reset.h> 43 + #include <linux/spinlock.h> 43 44 #include <linux/usb/of.h> 44 45 #include <linux/workqueue.h> 45 46 ··· 51 50 #define REG_PHYCTL_A33 0x10 52 51 #define REG_PHY_UNK_H3 0x20 53 52 54 - #define REG_PMU_UNK_H3 0x10 53 + #define REG_PMU_UNK1 0x10 55 54 56 55 #define PHYCTL_DATA BIT(7) 57 56 ··· 99 98 sun6i_a31_phy, 100 99 sun8i_a33_phy, 101 100 sun8i_h3_phy, 101 + sun50i_a64_phy, 102 102 }; 103 103 104 104 struct sun4i_usb_phy_cfg { ··· 108 106 u32 disc_thresh; 109 107 u8 phyctl_offset; 110 108 bool dedicated_clocks; 109 + bool enable_pmu_unk1; 111 110 }; 112 111 113 112 struct sun4i_usb_phy_data { 114 113 void __iomem *base; 115 114 const struct sun4i_usb_phy_cfg *cfg; 116 115 enum usb_dr_mode dr_mode; 117 - struct mutex mutex; 116 + spinlock_t reg_lock; /* guard access to phyctl reg */ 118 117 struct sun4i_usb_phy { 119 118 struct phy *phy; 120 119 void __iomem *pmu; ··· 125 122 bool regulator_on; 126 123 int index; 127 124 } phys[MAX_PHYS]; 128 - int first_phy; 129 125 /* phy0 / otg related variables */ 130 126 struct extcon_dev *extcon; 131 127 bool phy0_init; ··· 133 131 struct power_supply *vbus_power_supply; 134 132 struct notifier_block vbus_power_nb; 135 133 bool vbus_power_nb_registered; 134 + bool force_session_end; 136 135 int id_det_irq; 137 136 int vbus_det_irq; 138 137 int id_det; ··· 182 179 struct sun4i_usb_phy_data *phy_data = to_sun4i_usb_phy_data(phy); 183 180 u32 temp, usbc_bit = BIT(phy->index * 2); 184 181 void __iomem *phyctl = phy_data->base + phy_data->cfg->phyctl_offset; 182 + unsigned long flags; 185 183 int i; 186 184 187 - mutex_lock(&phy_data->mutex); 185 + spin_lock_irqsave(&phy_data->reg_lock, flags); 188 186 189 - if (phy_data->cfg->type == sun8i_a33_phy) { 190 - /* A33 needs us to set phyctl to 0 explicitly */ 187 + if (phy_data->cfg->type == sun8i_a33_phy || 188 + phy_data->cfg->type == sun50i_a64_phy) { 189 + /* A33 or A64 needs us to set phyctl to 0 explicitly */ 191 190 writel(0, phyctl); 192 191 } 193 192 ··· 223 218 224 219 data >>= 1; 225 220 } 226 - mutex_unlock(&phy_data->mutex); 221 + 222 + spin_unlock_irqrestore(&phy_data->reg_lock, flags); 227 223 } 228 224 229 225 static void sun4i_usb_phy_passby(struct sun4i_usb_phy *phy, int enable) ··· 264 258 return ret; 265 259 } 266 260 261 + if (data->cfg->enable_pmu_unk1) { 262 + val = readl(phy->pmu + REG_PMU_UNK1); 263 + writel(val & ~2, phy->pmu + REG_PMU_UNK1); 264 + } 265 + 267 266 if (data->cfg->type == sun8i_h3_phy) { 268 267 if (phy->index == 0) { 269 268 val = readl(data->base + REG_PHY_UNK_H3); 270 269 writel(val & ~1, data->base + REG_PHY_UNK_H3); 271 270 } 272 - 273 - val = readl(phy->pmu + REG_PMU_UNK_H3); 274 - writel(val & ~2, phy->pmu + REG_PMU_UNK_H3); 275 271 } else { 276 272 /* Enable USB 45 Ohm resistor calibration */ 277 273 if (phy->index == 0) ··· 328 320 { 329 321 switch (data->dr_mode) { 330 322 case USB_DR_MODE_OTG: 331 - return gpiod_get_value_cansleep(data->id_det_gpio); 323 + if (data->id_det_gpio) 324 + return gpiod_get_value_cansleep(data->id_det_gpio); 325 + else 326 + return 1; /* Fallback to peripheral mode */ 332 327 case USB_DR_MODE_HOST: 333 328 return 0; 334 329 case USB_DR_MODE_PERIPHERAL: ··· 393 382 394 383 /* For phy0 only turn on Vbus if we don't have an ext. Vbus */ 395 384 if (phy->index == 0 && sun4i_usb_phy0_have_vbus_det(data) && 396 - data->vbus_det) 385 + data->vbus_det) { 386 + dev_warn(&_phy->dev, "External vbus detected, not enabling our own vbus\n"); 397 387 return 0; 388 + } 398 389 399 390 ret = regulator_enable(phy->vbus); 400 391 if (ret) ··· 432 419 return 0; 433 420 } 434 421 422 + static int sun4i_usb_phy_set_mode(struct phy *_phy, enum phy_mode mode) 423 + { 424 + struct sun4i_usb_phy *phy = phy_get_drvdata(_phy); 425 + struct sun4i_usb_phy_data *data = to_sun4i_usb_phy_data(phy); 426 + 427 + if (phy->index != 0) 428 + return -EINVAL; 429 + 430 + switch (mode) { 431 + case PHY_MODE_USB_HOST: 432 + data->dr_mode = USB_DR_MODE_HOST; 433 + break; 434 + case PHY_MODE_USB_DEVICE: 435 + data->dr_mode = USB_DR_MODE_PERIPHERAL; 436 + break; 437 + case PHY_MODE_USB_OTG: 438 + data->dr_mode = USB_DR_MODE_OTG; 439 + break; 440 + default: 441 + return -EINVAL; 442 + } 443 + 444 + dev_info(&_phy->dev, "Changing dr_mode to %d\n", (int)data->dr_mode); 445 + data->force_session_end = true; 446 + queue_delayed_work(system_wq, &data->detect, 0); 447 + 448 + return 0; 449 + } 450 + 435 451 void sun4i_usb_phy_set_squelch_detect(struct phy *_phy, bool enabled) 436 452 { 437 453 struct sun4i_usb_phy *phy = phy_get_drvdata(_phy); ··· 474 432 .exit = sun4i_usb_phy_exit, 475 433 .power_on = sun4i_usb_phy_power_on, 476 434 .power_off = sun4i_usb_phy_power_off, 435 + .set_mode = sun4i_usb_phy_set_mode, 477 436 .owner = THIS_MODULE, 478 437 }; 479 438 ··· 483 440 struct sun4i_usb_phy_data *data = 484 441 container_of(work, struct sun4i_usb_phy_data, detect.work); 485 442 struct phy *phy0 = data->phys[0].phy; 486 - int id_det, vbus_det, id_notify = 0, vbus_notify = 0; 443 + bool force_session_end, id_notify = false, vbus_notify = false; 444 + int id_det, vbus_det; 487 445 488 446 if (phy0 == NULL) 489 447 return; ··· 499 455 return; 500 456 } 501 457 458 + force_session_end = data->force_session_end; 459 + data->force_session_end = false; 460 + 502 461 if (id_det != data->id_det) { 503 - /* 504 - * When a host cable (id == 0) gets plugged in on systems 505 - * without vbus detection report vbus low for long enough for 506 - * the musb-ip to end the current device session. 507 - */ 462 + /* id-change, force session end if we've no vbus detection */ 508 463 if (data->dr_mode == USB_DR_MODE_OTG && 509 - !sun4i_usb_phy0_have_vbus_det(data) && id_det == 0) { 464 + !sun4i_usb_phy0_have_vbus_det(data)) 465 + force_session_end = true; 466 + 467 + /* When entering host mode (id = 0) force end the session now */ 468 + if (force_session_end && id_det == 0) { 510 469 sun4i_usb_phy0_set_vbus_detect(phy0, 0); 511 470 msleep(200); 512 471 sun4i_usb_phy0_set_vbus_detect(phy0, 1); 513 472 } 514 473 sun4i_usb_phy0_set_id_detect(phy0, id_det); 515 474 data->id_det = id_det; 516 - id_notify = 1; 475 + id_notify = true; 517 476 } 518 477 519 478 if (vbus_det != data->vbus_det) { 520 479 sun4i_usb_phy0_set_vbus_detect(phy0, vbus_det); 521 480 data->vbus_det = vbus_det; 522 - vbus_notify = 1; 481 + vbus_notify = true; 523 482 } 524 483 525 484 mutex_unlock(&phy0->mutex); ··· 530 483 if (id_notify) { 531 484 extcon_set_cable_state_(data->extcon, EXTCON_USB_HOST, 532 485 !id_det); 533 - /* 534 - * When a host cable gets unplugged (id == 1) on systems 535 - * without vbus detection report vbus low for long enough to 536 - * the musb-ip to end the current host session. 537 - */ 538 - if (data->dr_mode == USB_DR_MODE_OTG && 539 - !sun4i_usb_phy0_have_vbus_det(data) && id_det == 1) { 486 + /* When leaving host mode force end the session here */ 487 + if (force_session_end && id_det == 1) { 540 488 mutex_lock(&phy0->mutex); 541 489 sun4i_usb_phy0_set_vbus_detect(phy0, 0); 542 490 msleep(1000); ··· 576 534 { 577 535 struct sun4i_usb_phy_data *data = dev_get_drvdata(dev); 578 536 579 - if (args->args[0] < data->first_phy || 580 - args->args[0] >= data->cfg->num_phys) 537 + if (args->args[0] >= data->cfg->num_phys) 581 538 return ERR_PTR(-ENODEV); 582 539 583 540 return data->phys[args->args[0]].phy; ··· 618 577 if (!data) 619 578 return -ENOMEM; 620 579 621 - mutex_init(&data->mutex); 580 + spin_lock_init(&data->reg_lock); 622 581 INIT_DELAYED_WORK(&data->detect, sun4i_usb_phy0_id_vbus_det_scan); 623 582 dev_set_drvdata(dev, data); 624 583 data->cfg = of_device_get_match_data(dev); ··· 651 610 } 652 611 653 612 data->dr_mode = of_usb_get_dr_mode_by_phy(np, 0); 654 - switch (data->dr_mode) { 655 - case USB_DR_MODE_OTG: 656 - /* otg without id_det makes no sense, and is not supported */ 657 - if (!data->id_det_gpio) { 658 - dev_err(dev, "usb0_id_det missing or invalid\n"); 659 - return -ENODEV; 660 - } 661 - /* fall through */ 662 - case USB_DR_MODE_HOST: 663 - case USB_DR_MODE_PERIPHERAL: 664 - data->extcon = devm_extcon_dev_allocate(dev, 665 - sun4i_usb_phy0_cable); 666 - if (IS_ERR(data->extcon)) 667 - return PTR_ERR(data->extcon); 668 613 669 - ret = devm_extcon_dev_register(dev, data->extcon); 670 - if (ret) { 671 - dev_err(dev, "failed to register extcon: %d\n", ret); 672 - return ret; 673 - } 674 - break; 675 - default: 676 - dev_info(dev, "dr_mode unknown, not registering usb phy0\n"); 677 - data->first_phy = 1; 614 + data->extcon = devm_extcon_dev_allocate(dev, sun4i_usb_phy0_cable); 615 + if (IS_ERR(data->extcon)) 616 + return PTR_ERR(data->extcon); 617 + 618 + ret = devm_extcon_dev_register(dev, data->extcon); 619 + if (ret) { 620 + dev_err(dev, "failed to register extcon: %d\n", ret); 621 + return ret; 678 622 } 679 623 680 - for (i = data->first_phy; i < data->cfg->num_phys; i++) { 624 + for (i = 0; i < data->cfg->num_phys; i++) { 681 625 struct sun4i_usb_phy *phy = data->phys + i; 682 626 char name[16]; 683 627 ··· 763 737 .disc_thresh = 3, 764 738 .phyctl_offset = REG_PHYCTL_A10, 765 739 .dedicated_clocks = false, 740 + .enable_pmu_unk1 = false, 766 741 }; 767 742 768 743 static const struct sun4i_usb_phy_cfg sun5i_a13_cfg = { ··· 772 745 .disc_thresh = 2, 773 746 .phyctl_offset = REG_PHYCTL_A10, 774 747 .dedicated_clocks = false, 748 + .enable_pmu_unk1 = false, 775 749 }; 776 750 777 751 static const struct sun4i_usb_phy_cfg sun6i_a31_cfg = { ··· 781 753 .disc_thresh = 3, 782 754 .phyctl_offset = REG_PHYCTL_A10, 783 755 .dedicated_clocks = true, 756 + .enable_pmu_unk1 = false, 784 757 }; 785 758 786 759 static const struct sun4i_usb_phy_cfg sun7i_a20_cfg = { ··· 790 761 .disc_thresh = 2, 791 762 .phyctl_offset = REG_PHYCTL_A10, 792 763 .dedicated_clocks = false, 764 + .enable_pmu_unk1 = false, 793 765 }; 794 766 795 767 static const struct sun4i_usb_phy_cfg sun8i_a23_cfg = { ··· 799 769 .disc_thresh = 3, 800 770 .phyctl_offset = REG_PHYCTL_A10, 801 771 .dedicated_clocks = true, 772 + .enable_pmu_unk1 = false, 802 773 }; 803 774 804 775 static const struct sun4i_usb_phy_cfg sun8i_a33_cfg = { ··· 808 777 .disc_thresh = 3, 809 778 .phyctl_offset = REG_PHYCTL_A33, 810 779 .dedicated_clocks = true, 780 + .enable_pmu_unk1 = false, 811 781 }; 812 782 813 783 static const struct sun4i_usb_phy_cfg sun8i_h3_cfg = { ··· 816 784 .type = sun8i_h3_phy, 817 785 .disc_thresh = 3, 818 786 .dedicated_clocks = true, 787 + .enable_pmu_unk1 = true, 788 + }; 789 + 790 + static const struct sun4i_usb_phy_cfg sun50i_a64_cfg = { 791 + .num_phys = 2, 792 + .type = sun50i_a64_phy, 793 + .disc_thresh = 3, 794 + .phyctl_offset = REG_PHYCTL_A33, 795 + .dedicated_clocks = true, 796 + .enable_pmu_unk1 = true, 819 797 }; 820 798 821 799 static const struct of_device_id sun4i_usb_phy_of_match[] = { ··· 836 794 { .compatible = "allwinner,sun8i-a23-usb-phy", .data = &sun8i_a23_cfg }, 837 795 { .compatible = "allwinner,sun8i-a33-usb-phy", .data = &sun8i_a33_cfg }, 838 796 { .compatible = "allwinner,sun8i-h3-usb-phy", .data = &sun8i_h3_cfg }, 797 + { .compatible = "allwinner,sun50i-a64-usb-phy", 798 + .data = &sun50i_a64_cfg}, 839 799 { }, 840 800 }; 841 801 MODULE_DEVICE_TABLE(of, sun4i_usb_phy_of_match);
+18 -7
drivers/phy/phy-twl4030-usb.c
··· 172 172 int irq; 173 173 enum musb_vbus_id_status linkstat; 174 174 bool vbus_supplied; 175 + bool musb_mailbox_pending; 175 176 176 177 struct delayed_work id_workaround_work; 177 178 }; ··· 440 439 (PHY_CLK_CTRL_CLOCKGATING_EN | 441 440 PHY_CLK_CTRL_CLK32K_EN)); 442 441 442 + twl4030_i2c_access(twl, 1); 443 + twl4030_usb_set_mode(twl, twl->usb_mode); 444 + if (twl->usb_mode == T2_USB_MODE_ULPI) 445 + twl4030_i2c_access(twl, 0); 446 + /* 447 + * According to the TPS65950 TRM, there has to be at least 50ms 448 + * delay between setting POWER_CTRL_OTG_ENAB and enabling charging 449 + * so wait here so that a fully enabled phy can be expected after 450 + * resume 451 + */ 452 + msleep(50); 443 453 return 0; 444 454 } 445 455 ··· 471 459 472 460 dev_dbg(twl->dev, "%s\n", __func__); 473 461 pm_runtime_get_sync(twl->dev); 474 - twl4030_i2c_access(twl, 1); 475 - twl4030_usb_set_mode(twl, twl->usb_mode); 476 - if (twl->usb_mode == T2_USB_MODE_ULPI) 477 - twl4030_i2c_access(twl, 0); 478 - twl->linkstat = MUSB_UNKNOWN; 479 462 schedule_delayed_work(&twl->id_workaround_work, HZ); 480 463 481 464 return 0; ··· 576 569 pm_runtime_mark_last_busy(twl->dev); 577 570 pm_runtime_put_autosuspend(twl->dev); 578 571 } 572 + twl->musb_mailbox_pending = true; 573 + } 574 + if (twl->musb_mailbox_pending) { 579 575 err = musb_mailbox(status); 580 - if (err) 581 - twl->linkstat = MUSB_UNKNOWN; 576 + if (!err) 577 + twl->musb_mailbox_pending = false; 582 578 } 583 579 584 580 /* don't schedule during sleep - irq works right then */ ··· 686 676 twl->irq = platform_get_irq(pdev, 0); 687 677 twl->vbus_supplied = false; 688 678 twl->linkstat = MUSB_UNKNOWN; 679 + twl->musb_mailbox_pending = false; 689 680 690 681 twl->phy.dev = twl->dev; 691 682 twl->phy.label = "twl4030";
+3 -1
drivers/phy/tegra/xusb.c
··· 18 18 #include <linux/of.h> 19 19 #include <linux/of_device.h> 20 20 #include <linux/phy/phy.h> 21 + #include <linux/phy/tegra/xusb.h> 21 22 #include <linux/platform_device.h> 22 23 #include <linux/regulator/consumer.h> 23 24 #include <linux/reset.h> ··· 102 101 return of_find_node_by_name(np, pad->soc->lanes[index].name); 103 102 } 104 103 105 - int tegra_xusb_lane_lookup_function(struct tegra_xusb_lane *lane, 104 + static int 105 + tegra_xusb_lane_lookup_function(struct tegra_xusb_lane *lane, 106 106 const char *function) 107 107 { 108 108 unsigned int i;
+23 -1
drivers/usb/Kconfig
··· 152 152 153 153 config USB_LED_TRIG 154 154 bool "USB LED Triggers" 155 - depends on LEDS_CLASS && USB_COMMON && LEDS_TRIGGERS 155 + depends on LEDS_CLASS && LEDS_TRIGGERS 156 + select USB_COMMON 156 157 help 157 158 This option adds LED triggers for USB host and/or gadget activity. 158 159 159 160 Say Y here if you are working on a system with led-class supported 160 161 LEDs and you want to use them as activity indicators for USB host or 161 162 gadget. 163 + 164 + config USB_ULPI_BUS 165 + tristate "USB ULPI PHY interface support" 166 + select USB_COMMON 167 + help 168 + UTMI+ Low Pin Interface (ULPI) is specification for a commonly used 169 + USB 2.0 PHY interface. The ULPI specification defines a standard set 170 + of registers that can be used to detect the vendor and product which 171 + allows ULPI to be handled as a bus. This module is the driver for that 172 + bus. 173 + 174 + The ULPI interfaces (the buses) are registered by the drivers for USB 175 + controllers which support ULPI register access and have ULPI PHY 176 + attached to them. The ULPI PHY drivers themselves are normal PHY 177 + drivers. 178 + 179 + ULPI PHYs provide often functions such as ADP sensing/probing (OTG 180 + protocol) and USB charger detection. 181 + 182 + To compile this driver as a module, choose M here: the module will 183 + be called ulpi. 162 184 163 185 endif # USB_SUPPORT
+1 -5
drivers/usb/atm/cxacru.c
··· 1139 1139 1140 1140 /* instance init */ 1141 1141 instance = kzalloc(sizeof(*instance), GFP_KERNEL); 1142 - if (!instance) { 1143 - usb_dbg(usbatm_instance, "cxacru_bind: no memory for instance data\n"); 1142 + if (!instance) 1144 1143 return -ENOMEM; 1145 - } 1146 1144 1147 1145 instance->usbatm = usbatm_instance; 1148 1146 instance->modem_type = (struct cxacru_modem_type *) id->driver_info; ··· 1166 1168 } 1167 1169 instance->rcv_urb = usb_alloc_urb(0, GFP_KERNEL); 1168 1170 if (!instance->rcv_urb) { 1169 - usb_dbg(usbatm_instance, "cxacru_bind: no memory for rcv_urb\n"); 1170 1171 ret = -ENOMEM; 1171 1172 goto fail; 1172 1173 } 1173 1174 instance->snd_urb = usb_alloc_urb(0, GFP_KERNEL); 1174 1175 if (!instance->snd_urb) { 1175 - usb_dbg(usbatm_instance, "cxacru_bind: no memory for snd_urb\n"); 1176 1176 ret = -ENOMEM; 1177 1177 goto fail; 1178 1178 }
-1
drivers/usb/atm/speedtch.c
··· 817 817 instance = kzalloc(sizeof(*instance), GFP_KERNEL); 818 818 819 819 if (!instance) { 820 - usb_err(usbatm, "%s: no memory for instance data!\n", __func__); 821 820 ret = -ENOMEM; 822 821 goto fail_release; 823 822 }
+3 -10
drivers/usb/atm/ueagle-atm.c
··· 2196 2196 load_XILINX_firmware(sc); 2197 2197 2198 2198 intr = kmalloc(size, GFP_KERNEL); 2199 - if (!intr) { 2200 - uea_err(INS_TO_USBDEV(sc), 2201 - "cannot allocate interrupt package\n"); 2199 + if (!intr) 2202 2200 goto err0; 2203 - } 2204 2201 2205 2202 sc->urb_int = usb_alloc_urb(0, GFP_KERNEL); 2206 - if (!sc->urb_int) { 2207 - uea_err(INS_TO_USBDEV(sc), "cannot allocate interrupt URB\n"); 2203 + if (!sc->urb_int) 2208 2204 goto err1; 2209 - } 2210 2205 2211 2206 usb_fill_int_urb(sc->urb_int, sc->usb_dev, 2212 2207 usb_rcvintpipe(sc->usb_dev, UEA_INTR_PIPE), ··· 2556 2561 } 2557 2562 2558 2563 sc = kzalloc(sizeof(struct uea_softc), GFP_KERNEL); 2559 - if (!sc) { 2560 - uea_err(usb, "uea_init: not enough memory !\n"); 2564 + if (!sc) 2561 2565 return -ENOMEM; 2562 - } 2563 2566 2564 2567 sc->usb_dev = usb; 2565 2568 usbatm->driver_data = sc;
+1 -7
drivers/usb/atm/usbatm.c
··· 819 819 820 820 new = kzalloc(sizeof(struct usbatm_vcc_data), GFP_KERNEL); 821 821 if (!new) { 822 - atm_err(instance, "%s: no memory for vcc_data!\n", __func__); 823 822 ret = -ENOMEM; 824 823 goto fail; 825 824 } ··· 1031 1032 1032 1033 /* instance init */ 1033 1034 instance = kzalloc(sizeof(*instance) + sizeof(struct urb *) * (num_rcv_urbs + num_snd_urbs), GFP_KERNEL); 1034 - if (!instance) { 1035 - dev_err(dev, "%s: no memory for instance data!\n", __func__); 1035 + if (!instance) 1036 1036 return -ENOMEM; 1037 - } 1038 1037 1039 1038 /* public fields */ 1040 1039 ··· 1138 1141 1139 1142 urb = usb_alloc_urb(iso_packets, GFP_KERNEL); 1140 1143 if (!urb) { 1141 - dev_err(dev, "%s: no memory for urb %d!\n", __func__, i); 1142 1144 error = -ENOMEM; 1143 1145 goto fail_unbind; 1144 1146 } ··· 1147 1151 /* zero the tx padding to avoid leaking information */ 1148 1152 buffer = kzalloc(channel->buf_size, GFP_KERNEL); 1149 1153 if (!buffer) { 1150 - dev_err(dev, "%s: no memory for buffer %d!\n", __func__, i); 1151 1154 error = -ENOMEM; 1152 1155 goto fail_unbind; 1153 1156 } ··· 1177 1182 instance->cell_buf = kmalloc(instance->rx_channel.stride, GFP_KERNEL); 1178 1183 1179 1184 if (!instance->cell_buf) { 1180 - dev_err(dev, "%s: no memory for cell buffer!\n", __func__); 1181 1185 error = -ENOMEM; 1182 1186 goto fail_unbind; 1183 1187 }
+3
drivers/usb/chipidea/ci_hdrc_imx.c
··· 140 140 if (of_find_property(np, "disable-over-current", NULL)) 141 141 data->disable_oc = 1; 142 142 143 + if (of_find_property(np, "over-current-active-high", NULL)) 144 + data->oc_polarity = 1; 145 + 143 146 if (of_find_property(np, "external-vbus-divider", NULL)) 144 147 data->evdo = 1; 145 148
+1
drivers/usb/chipidea/ci_hdrc_imx.h
··· 17 17 int index; 18 18 19 19 unsigned int disable_oc:1; /* over current detect disabled */ 20 + unsigned int oc_polarity:1; /* over current polarity if oc enabled */ 20 21 unsigned int evdo:1; /* set external vbus divider option */ 21 22 }; 22 23
+3
drivers/usb/chipidea/host.c
··· 81 81 { 82 82 struct device *dev = hcd->self.controller; 83 83 struct ci_hdrc *ci = dev_get_drvdata(dev); 84 + struct ehci_hcd *ehci = hcd_to_ehci(hcd); 84 85 int ret; 85 86 86 87 ret = ehci_setup(hcd); 87 88 if (ret) 88 89 return ret; 90 + 91 + ehci->need_io_watchdog = 0; 89 92 90 93 ci_platform_configure(ci); 91 94
+18 -24
drivers/usb/chipidea/udc.c
··· 59 59 */ 60 60 static inline int hw_ep_bit(int num, int dir) 61 61 { 62 - return num + (dir ? 16 : 0); 62 + return num + ((dir == TX) ? 16 : 0); 63 63 } 64 64 65 65 static inline int ep_to_bit(struct ci_hdrc *ci, int n) ··· 121 121 */ 122 122 static int hw_ep_disable(struct ci_hdrc *ci, int num, int dir) 123 123 { 124 - hw_ep_flush(ci, num, dir); 125 124 hw_write(ci, OP_ENDPTCTRL + num, 126 - dir ? ENDPTCTRL_TXE : ENDPTCTRL_RXE, 0); 125 + (dir == TX) ? ENDPTCTRL_TXE : ENDPTCTRL_RXE, 0); 127 126 return 0; 128 127 } 129 128 ··· 138 139 { 139 140 u32 mask, data; 140 141 141 - if (dir) { 142 + if (dir == TX) { 142 143 mask = ENDPTCTRL_TXT; /* type */ 143 144 data = type << __ffs(mask); 144 145 ··· 170 171 */ 171 172 static int hw_ep_get_halt(struct ci_hdrc *ci, int num, int dir) 172 173 { 173 - u32 mask = dir ? ENDPTCTRL_TXS : ENDPTCTRL_RXS; 174 + u32 mask = (dir == TX) ? ENDPTCTRL_TXS : ENDPTCTRL_RXS; 174 175 175 176 return hw_read(ci, OP_ENDPTCTRL + num, mask) ? 1 : 0; 176 177 } ··· 186 187 static int hw_ep_prime(struct ci_hdrc *ci, int num, int dir, int is_ctrl) 187 188 { 188 189 int n = hw_ep_bit(num, dir); 190 + 191 + /* Synchronize before ep prime */ 192 + wmb(); 189 193 190 194 if (is_ctrl && dir == RX && hw_read(ci, OP_ENDPTSETUPSTAT, BIT(num))) 191 195 return -EAGAIN; ··· 220 218 221 219 do { 222 220 enum ci_hw_regs reg = OP_ENDPTCTRL + num; 223 - u32 mask_xs = dir ? ENDPTCTRL_TXS : ENDPTCTRL_RXS; 224 - u32 mask_xr = dir ? ENDPTCTRL_TXR : ENDPTCTRL_RXR; 221 + u32 mask_xs = (dir == TX) ? ENDPTCTRL_TXS : ENDPTCTRL_RXS; 222 + u32 mask_xr = (dir == TX) ? ENDPTCTRL_TXR : ENDPTCTRL_RXR; 225 223 226 224 /* data toggle - reserved for EP0 but it's in ESS */ 227 225 hw_write(ci, reg, mask_xs|mask_xr, ··· 350 348 if (node == NULL) 351 349 return -ENOMEM; 352 350 353 - node->ptr = dma_pool_zalloc(hwep->td_pool, GFP_ATOMIC, 354 - &node->dma); 351 + node->ptr = dma_pool_zalloc(hwep->td_pool, GFP_ATOMIC, &node->dma); 355 352 if (node->ptr == NULL) { 356 353 kfree(node); 357 354 return -ENOMEM; ··· 507 506 hwep->qh.ptr->cap |= mul << __ffs(QH_MULT); 508 507 } 509 508 510 - wmb(); /* synchronize before ep prime */ 511 - 512 509 ret = hw_ep_prime(ci, hwep->num, hwep->dir, 513 510 hwep->type == USB_ENDPOINT_XFER_CONTROL); 514 511 done: ··· 532 533 hwep->qh.ptr->td.next = node->dma; 533 534 hwep->qh.ptr->td.token &= 534 535 cpu_to_le32(~(TD_STATUS_HALTED | TD_STATUS_ACTIVE)); 535 - 536 - /* Synchronize before ep prime */ 537 - wmb(); 538 536 539 537 return hw_ep_prime(ci, hwep->num, hwep->dir, 540 538 hwep->type == USB_ENDPOINT_XFER_CONTROL); ··· 586 590 } 587 591 588 592 if (remaining_length) { 589 - if (hwep->dir) { 593 + if (hwep->dir == TX) { 590 594 hwreq->req.status = -EPROTO; 591 595 break; 592 596 } ··· 1047 1051 if (req.wLength != 0) 1048 1052 break; 1049 1053 num = le16_to_cpu(req.wIndex); 1050 - dir = num & USB_ENDPOINT_DIR_MASK; 1054 + dir = (num & USB_ENDPOINT_DIR_MASK) ? TX : RX; 1051 1055 num &= USB_ENDPOINT_NUMBER_MASK; 1052 - if (dir) /* TX */ 1056 + if (dir == TX) 1053 1057 num += ci->hw_ep_max / 2; 1054 1058 if (!ci->ci_hw_ep[num].wedge) { 1055 1059 spin_unlock(&ci->lock); ··· 1099 1103 if (req.wLength != 0) 1100 1104 break; 1101 1105 num = le16_to_cpu(req.wIndex); 1102 - dir = num & USB_ENDPOINT_DIR_MASK; 1106 + dir = (num & USB_ENDPOINT_DIR_MASK) ? TX : RX; 1103 1107 num &= USB_ENDPOINT_NUMBER_MASK; 1104 - if (dir) /* TX */ 1108 + if (dir == TX) 1105 1109 num += ci->hw_ep_max / 2; 1106 1110 1107 1111 spin_unlock(&ci->lock); ··· 1676 1680 usb_ep_set_maxpacket_limit(&hwep->ep, (unsigned short)~0); 1677 1681 1678 1682 INIT_LIST_HEAD(&hwep->qh.queue); 1679 - hwep->qh.ptr = dma_pool_alloc(ci->qh_pool, GFP_KERNEL, 1680 - &hwep->qh.dma); 1683 + hwep->qh.ptr = dma_pool_zalloc(ci->qh_pool, GFP_KERNEL, 1684 + &hwep->qh.dma); 1681 1685 if (hwep->qh.ptr == NULL) 1682 1686 retval = -ENOMEM; 1683 - else 1684 - memset(hwep->qh.ptr, 0, sizeof(*hwep->qh.ptr)); 1685 1687 1686 1688 /* 1687 1689 * set up shorthands for ep0 out and in endpoints, ··· 1993 1999 if (!hw_read(ci, CAP_DCCPARAMS, DCCPARAMS_DC)) 1994 2000 return -ENXIO; 1995 2001 1996 - rdrv = devm_kzalloc(ci->dev, sizeof(struct ci_role_driver), GFP_KERNEL); 2002 + rdrv = devm_kzalloc(ci->dev, sizeof(*rdrv), GFP_KERNEL); 1997 2003 if (!rdrv) 1998 2004 return -ENOMEM; 1999 2005
+17 -5
drivers/usb/chipidea/usbmisc_imx.c
··· 56 56 57 57 #define MX6_BM_NON_BURST_SETTING BIT(1) 58 58 #define MX6_BM_OVER_CUR_DIS BIT(7) 59 + #define MX6_BM_OVER_CUR_POLARITY BIT(8) 59 60 #define MX6_BM_WAKEUP_ENABLE BIT(10) 60 61 #define MX6_BM_ID_WAKEUP BIT(16) 61 62 #define MX6_BM_VBUS_WAKEUP BIT(17) ··· 267 266 268 267 spin_lock_irqsave(&usbmisc->lock, flags); 269 268 269 + reg = readl(usbmisc->base + data->index * 4); 270 270 if (data->disable_oc) { 271 - reg = readl(usbmisc->base + data->index * 4); 272 - writel(reg | MX6_BM_OVER_CUR_DIS, 273 - usbmisc->base + data->index * 4); 271 + reg |= MX6_BM_OVER_CUR_DIS; 272 + } else if (data->oc_polarity == 1) { 273 + /* High active */ 274 + reg &= ~(MX6_BM_OVER_CUR_DIS | MX6_BM_OVER_CUR_POLARITY); 274 275 } 276 + writel(reg, usbmisc->base + data->index * 4); 275 277 276 278 /* SoC non-burst setting */ 277 279 reg = readl(usbmisc->base + data->index * 4); ··· 369 365 return -EINVAL; 370 366 371 367 spin_lock_irqsave(&usbmisc->lock, flags); 368 + reg = readl(usbmisc->base); 372 369 if (data->disable_oc) { 373 - reg = readl(usbmisc->base); 374 - writel(reg | MX6_BM_OVER_CUR_DIS, usbmisc->base); 370 + reg |= MX6_BM_OVER_CUR_DIS; 371 + } else if (data->oc_polarity == 1) { 372 + /* High active */ 373 + reg &= ~(MX6_BM_OVER_CUR_DIS | MX6_BM_OVER_CUR_POLARITY); 375 374 } 375 + writel(reg, usbmisc->base); 376 376 377 377 reg = readl(usbmisc->base + MX7D_USBNC_USB_CTRL2); 378 378 reg &= ~MX7D_USB_VBUS_WAKEUP_SOURCE_MASK; ··· 499 491 { 500 492 .compatible = "fsl,imx6ul-usbmisc", 501 493 .data = &imx6sx_usbmisc_ops, 494 + }, 495 + { 496 + .compatible = "fsl,imx7d-usbmisc", 497 + .data = &imx7d_usbmisc_ops, 502 498 }, 503 499 { /* sentinel */ } 504 500 };
+18 -31
drivers/usb/class/cdc-acm.c
··· 368 368 if (!test_and_clear_bit(index, &acm->read_urbs_free)) 369 369 return 0; 370 370 371 - dev_vdbg(&acm->data->dev, "%s - urb %d\n", __func__, index); 372 - 373 371 res = usb_submit_urb(acm->read_urbs[index], mem_flags); 374 372 if (res) { 375 373 if (res != -EPERM) { 376 374 dev_err(&acm->data->dev, 377 - "%s - usb_submit_urb failed: %d\n", 378 - __func__, res); 375 + "urb %d failed submission with %d\n", 376 + index, res); 379 377 } 380 378 set_bit(index, &acm->read_urbs_free); 381 379 return res; 380 + } else { 381 + dev_vdbg(&acm->data->dev, "submitted urb %d\n", index); 382 382 } 383 383 384 384 return 0; ··· 415 415 unsigned long flags; 416 416 int status = urb->status; 417 417 418 - dev_vdbg(&acm->data->dev, "%s - urb %d, len %d\n", __func__, 419 - rb->index, urb->actual_length); 418 + dev_vdbg(&acm->data->dev, "got urb %d, len %d, status %d\n", 419 + rb->index, urb->actual_length, 420 + status); 420 421 421 422 if (!acm->dev) { 422 423 set_bit(rb->index, &acm->read_urbs_free); ··· 427 426 428 427 if (status) { 429 428 set_bit(rb->index, &acm->read_urbs_free); 430 - dev_dbg(&acm->data->dev, "%s - non-zero urb status: %d\n", 431 - __func__, status); 432 429 if ((status != -ENOENT) || (urb->actual_length == 0)) 433 430 return; 434 431 } ··· 461 462 int status = urb->status; 462 463 463 464 if (status || (urb->actual_length != urb->transfer_buffer_length)) 464 - dev_vdbg(&acm->data->dev, "%s - len %d/%d, status %d\n", 465 - __func__, 465 + dev_vdbg(&acm->data->dev, "wrote len %d/%d, status %d\n", 466 466 urb->actual_length, 467 467 urb->transfer_buffer_length, 468 468 status); ··· 476 478 { 477 479 struct acm *acm = container_of(work, struct acm, work); 478 480 479 - dev_vdbg(&acm->data->dev, "%s\n", __func__); 480 - 481 481 tty_port_tty_wakeup(&acm->port); 482 482 } 483 483 ··· 487 491 { 488 492 struct acm *acm; 489 493 int retval; 490 - 491 - dev_dbg(tty->dev, "%s\n", __func__); 492 494 493 495 acm = acm_get_by_minor(tty->index); 494 496 if (!acm) ··· 508 514 static int acm_tty_open(struct tty_struct *tty, struct file *filp) 509 515 { 510 516 struct acm *acm = tty->driver_data; 511 - 512 - dev_dbg(tty->dev, "%s\n", __func__); 513 517 514 518 return tty_port_open(&acm->port, tty, filp); 515 519 } ··· 536 544 struct acm *acm = container_of(port, struct acm, port); 537 545 int retval = -ENODEV; 538 546 int i; 539 - 540 - dev_dbg(&acm->control->dev, "%s\n", __func__); 541 547 542 548 mutex_lock(&acm->mutex); 543 549 if (acm->disconnected) ··· 597 607 { 598 608 struct acm *acm = container_of(port, struct acm, port); 599 609 600 - dev_dbg(&acm->control->dev, "%s\n", __func__); 601 - 602 610 acm_release_minor(acm); 603 611 usb_put_intf(acm->control); 604 612 kfree(acm->country_codes); ··· 609 621 struct urb *urb; 610 622 struct acm_wb *wb; 611 623 int i; 612 - 613 - dev_dbg(&acm->control->dev, "%s\n", __func__); 614 624 615 625 /* 616 626 * Need to grab write_lock to prevent race with resume, but no need to ··· 640 654 static void acm_tty_cleanup(struct tty_struct *tty) 641 655 { 642 656 struct acm *acm = tty->driver_data; 643 - dev_dbg(&acm->control->dev, "%s\n", __func__); 657 + 644 658 tty_port_put(&acm->port); 645 659 } 646 660 647 661 static void acm_tty_hangup(struct tty_struct *tty) 648 662 { 649 663 struct acm *acm = tty->driver_data; 650 - dev_dbg(&acm->control->dev, "%s\n", __func__); 664 + 651 665 tty_port_hangup(&acm->port); 652 666 } 653 667 654 668 static void acm_tty_close(struct tty_struct *tty, struct file *filp) 655 669 { 656 670 struct acm *acm = tty->driver_data; 657 - dev_dbg(&acm->control->dev, "%s\n", __func__); 671 + 658 672 tty_port_close(&acm->port, tty, filp); 659 673 } 660 674 ··· 670 684 if (!count) 671 685 return 0; 672 686 673 - dev_vdbg(&acm->data->dev, "%s - count %d\n", __func__, count); 687 + dev_vdbg(&acm->data->dev, "%d bytes from tty layer\n", count); 674 688 675 689 spin_lock_irqsave(&acm->write_lock, flags); 676 690 wbn = acm_wb_alloc(acm); ··· 687 701 } 688 702 689 703 count = (count > acm->writesize) ? acm->writesize : count; 690 - dev_vdbg(&acm->data->dev, "%s - write %d\n", __func__, count); 704 + dev_vdbg(&acm->data->dev, "writing %d bytes\n", count); 691 705 memcpy(wb->buf, buf, count); 692 706 wb->len = count; 693 707 ··· 1179 1193 return -EINVAL; 1180 1194 } 1181 1195 1196 + if (!intf->cur_altsetting) 1197 + return -EINVAL; 1198 + 1182 1199 if (!buflen) { 1183 1200 if (intf->cur_altsetting->endpoint && 1184 1201 intf->cur_altsetting->endpoint->extralen && ··· 1235 1246 dev_dbg(&intf->dev, "no interfaces\n"); 1236 1247 return -ENODEV; 1237 1248 } 1249 + if (!data_interface->cur_altsetting || !control_interface->cur_altsetting) 1250 + return -ENODEV; 1238 1251 1239 1252 if (data_intf_num != call_intf_num) 1240 1253 dev_dbg(&intf->dev, "Separate call control interface. That is not fully supported.\n"); ··· 1524 1533 { 1525 1534 int i; 1526 1535 1527 - dev_dbg(&acm->control->dev, "%s\n", __func__); 1528 - 1529 1536 usb_kill_urb(acm->ctrlurb); 1530 1537 for (i = 0; i < ACM_NW; i++) 1531 1538 usb_kill_urb(acm->wb[i].urb); ··· 1539 1550 struct usb_device *usb_dev = interface_to_usbdev(intf); 1540 1551 struct tty_struct *tty; 1541 1552 int i; 1542 - 1543 - dev_dbg(&intf->dev, "%s\n", __func__); 1544 1553 1545 1554 /* sibling interface is already cleaning up */ 1546 1555 if (!acm)
+139 -26
drivers/usb/class/cdc-wdm.c
··· 58 58 #define WDM_SUSPENDING 8 59 59 #define WDM_RESETTING 9 60 60 #define WDM_OVERFLOW 10 61 + #define WDM_DRAIN_ON_OPEN 11 61 62 62 63 #define WDM_MAX 16 63 64 ··· 155 154 wake_up(&desc->wait); 156 155 } 157 156 157 + /* forward declaration */ 158 + static int service_outstanding_interrupt(struct wdm_device *desc); 159 + 158 160 static void wdm_in_callback(struct urb *urb) 159 161 { 160 162 struct wdm_device *desc = urb->context; ··· 171 167 switch (status) { 172 168 case -ENOENT: 173 169 dev_dbg(&desc->intf->dev, 174 - "nonzero urb status received: -ENOENT"); 170 + "nonzero urb status received: -ENOENT\n"); 175 171 goto skip_error; 176 172 case -ECONNRESET: 177 173 dev_dbg(&desc->intf->dev, 178 - "nonzero urb status received: -ECONNRESET"); 174 + "nonzero urb status received: -ECONNRESET\n"); 179 175 goto skip_error; 180 176 case -ESHUTDOWN: 181 177 dev_dbg(&desc->intf->dev, 182 - "nonzero urb status received: -ESHUTDOWN"); 178 + "nonzero urb status received: -ESHUTDOWN\n"); 183 179 goto skip_error; 184 180 case -EPIPE: 185 - dev_err(&desc->intf->dev, 181 + dev_dbg(&desc->intf->dev, 186 182 "nonzero urb status received: -EPIPE\n"); 187 183 break; 188 184 default: ··· 192 188 } 193 189 } 194 190 195 - desc->rerr = status; 191 + /* 192 + * only set a new error if there is no previous error. 193 + * Errors are only cleared during read/open 194 + */ 195 + if (desc->rerr == 0) 196 + desc->rerr = status; 197 + 196 198 if (length + desc->length > desc->wMaxCommand) { 197 199 /* The buffer would overflow */ 198 200 set_bit(WDM_OVERFLOW, &desc->flags); ··· 210 200 desc->reslength = length; 211 201 } 212 202 } 203 + 204 + /* 205 + * Handling devices with the WDM_DRAIN_ON_OPEN flag set: 206 + * If desc->resp_count is unset, then the urb was submitted 207 + * without a prior notification. If the device returned any 208 + * data, then this implies that it had messages queued without 209 + * notifying us. Continue reading until that queue is flushed. 210 + */ 211 + if (!desc->resp_count) { 212 + if (!length) { 213 + /* do not propagate the expected -EPIPE */ 214 + desc->rerr = 0; 215 + goto unlock; 216 + } 217 + dev_dbg(&desc->intf->dev, "got %d bytes without notification\n", length); 218 + set_bit(WDM_RESPONDING, &desc->flags); 219 + usb_submit_urb(desc->response, GFP_ATOMIC); 220 + } 221 + 213 222 skip_error: 223 + set_bit(WDM_READ, &desc->flags); 214 224 wake_up(&desc->wait); 215 225 216 - set_bit(WDM_READ, &desc->flags); 226 + if (desc->rerr) { 227 + /* 228 + * Since there was an error, userspace may decide to not read 229 + * any data after poll'ing. 230 + * We should respond to further attempts from the device to send 231 + * data, so that we can get unstuck. 232 + */ 233 + service_outstanding_interrupt(desc); 234 + } 235 + 236 + unlock: 217 237 spin_unlock(&desc->iuspin); 218 238 } 219 239 ··· 284 244 switch (dr->bNotificationType) { 285 245 case USB_CDC_NOTIFY_RESPONSE_AVAILABLE: 286 246 dev_dbg(&desc->intf->dev, 287 - "NOTIFY_RESPONSE_AVAILABLE received: index %d len %d", 247 + "NOTIFY_RESPONSE_AVAILABLE received: index %d len %d\n", 288 248 le16_to_cpu(dr->wIndex), le16_to_cpu(dr->wLength)); 289 249 break; 290 250 291 251 case USB_CDC_NOTIFY_NETWORK_CONNECTION: 292 252 293 253 dev_dbg(&desc->intf->dev, 294 - "NOTIFY_NETWORK_CONNECTION %s network", 254 + "NOTIFY_NETWORK_CONNECTION %s network\n", 295 255 dr->wValue ? "connected to" : "disconnected from"); 296 256 goto exit; 297 257 case USB_CDC_NOTIFY_SPEED_CHANGE: 298 - dev_dbg(&desc->intf->dev, "SPEED_CHANGE received (len %u)", 258 + dev_dbg(&desc->intf->dev, "SPEED_CHANGE received (len %u)\n", 299 259 urb->actual_length); 300 260 goto exit; 301 261 default: ··· 314 274 && !test_bit(WDM_DISCONNECTING, &desc->flags) 315 275 && !test_bit(WDM_SUSPENDING, &desc->flags)) { 316 276 rv = usb_submit_urb(desc->response, GFP_ATOMIC); 317 - dev_dbg(&desc->intf->dev, "%s: usb_submit_urb %d", 318 - __func__, rv); 277 + dev_dbg(&desc->intf->dev, "submit response URB %d\n", rv); 319 278 } 320 279 spin_unlock(&desc->iuspin); 321 280 if (rv < 0) { ··· 456 417 rv = usb_translate_errors(rv); 457 418 goto out_free_mem_pm; 458 419 } else { 459 - dev_dbg(&desc->intf->dev, "Tx URB has been submitted index=%d", 420 + dev_dbg(&desc->intf->dev, "Tx URB has been submitted index=%d\n", 460 421 le16_to_cpu(req->wIndex)); 461 422 } 462 423 ··· 475 436 } 476 437 477 438 /* 478 - * clear WDM_READ flag and possibly submit the read urb if resp_count 479 - * is non-zero. 439 + * Submit the read urb if resp_count is non-zero. 480 440 * 481 441 * Called with desc->iuspin locked 482 442 */ 483 - static int clear_wdm_read_flag(struct wdm_device *desc) 443 + static int service_outstanding_interrupt(struct wdm_device *desc) 484 444 { 485 445 int rv = 0; 486 - 487 - clear_bit(WDM_READ, &desc->flags); 488 446 489 447 /* submit read urb only if the device is waiting for it */ 490 448 if (!desc->resp_count || !--desc->resp_count) ··· 573 537 } 574 538 575 539 if (!desc->reslength) { /* zero length read */ 576 - dev_dbg(&desc->intf->dev, "%s: zero length - clearing WDM_READ\n", __func__); 577 - rv = clear_wdm_read_flag(desc); 540 + dev_dbg(&desc->intf->dev, "zero length - clearing WDM_READ\n"); 541 + clear_bit(WDM_READ, &desc->flags); 542 + rv = service_outstanding_interrupt(desc); 578 543 spin_unlock_irq(&desc->iuspin); 579 544 if (rv < 0) 580 545 goto err; ··· 600 563 601 564 desc->length -= cntr; 602 565 /* in case we had outstanding data */ 603 - if (!desc->length) 604 - clear_wdm_read_flag(desc); 566 + if (!desc->length) { 567 + clear_bit(WDM_READ, &desc->flags); 568 + service_outstanding_interrupt(desc); 569 + } 605 570 spin_unlock_irq(&desc->iuspin); 606 571 rv = cntr; 607 572 ··· 686 647 dev_err(&desc->intf->dev, 687 648 "Error submitting int urb - %d\n", rv); 688 649 rv = usb_translate_errors(rv); 650 + } else if (test_bit(WDM_DRAIN_ON_OPEN, &desc->flags)) { 651 + /* 652 + * Some devices keep pending messages queued 653 + * without resending notifications. We must 654 + * flush the message queue before we can 655 + * assume a one-to-one relationship between 656 + * notifications and messages in the queue 657 + */ 658 + dev_dbg(&desc->intf->dev, "draining queued data\n"); 659 + set_bit(WDM_RESPONDING, &desc->flags); 660 + rv = usb_submit_urb(desc->response, GFP_KERNEL); 689 661 } 690 662 } else { 691 663 rv = 0; ··· 723 673 724 674 if (!desc->count) { 725 675 if (!test_bit(WDM_DISCONNECTING, &desc->flags)) { 726 - dev_dbg(&desc->intf->dev, "wdm_release: cleanup"); 676 + dev_dbg(&desc->intf->dev, "wdm_release: cleanup\n"); 727 677 kill_urbs(desc); 728 678 spin_lock_irq(&desc->iuspin); 729 679 desc->resp_count = 0; ··· 803 753 /* --- hotplug --- */ 804 754 805 755 static int wdm_create(struct usb_interface *intf, struct usb_endpoint_descriptor *ep, 806 - u16 bufsize, int (*manage_power)(struct usb_interface *, int)) 756 + u16 bufsize, int (*manage_power)(struct usb_interface *, int), 757 + bool drain_on_open) 807 758 { 808 759 int rv = -ENOMEM; 809 760 struct wdm_device *desc; ··· 891 840 892 841 desc->manage_power = manage_power; 893 842 843 + /* 844 + * "drain_on_open" enables a hack to work around a firmware 845 + * issue observed on network functions, in particular MBIM 846 + * functions. 847 + * 848 + * Quoting section 7 of the CDC-WMC r1.1 specification: 849 + * 850 + * "The firmware shall interpret GetEncapsulatedResponse as a 851 + * request to read response bytes. The firmware shall send 852 + * the next wLength bytes from the response. The firmware 853 + * shall allow the host to retrieve data using any number of 854 + * GetEncapsulatedResponse requests. The firmware shall 855 + * return a zero- length reply if there are no data bytes 856 + * available. 857 + * 858 + * The firmware shall send ResponseAvailable notifications 859 + * periodically, using any appropriate algorithm, to inform 860 + * the host that there is data available in the reply 861 + * buffer. The firmware is allowed to send ResponseAvailable 862 + * notifications even if there is no data available, but 863 + * this will obviously reduce overall performance." 864 + * 865 + * These requirements, although they make equally sense, are 866 + * often not implemented by network functions. Some firmwares 867 + * will queue data indefinitely, without ever resending a 868 + * notification. The result is that the driver and firmware 869 + * loses "syncronization" if the driver ever fails to respond 870 + * to a single notification, something which easily can happen 871 + * on release(). When this happens, the driver will appear to 872 + * never receive notifications for the most current data. Each 873 + * notification will only cause a single read, which returns 874 + * the oldest data in the firmware's queue. 875 + * 876 + * The "drain_on_open" hack resolves the situation by draining 877 + * data from the firmware until none is returned, without a 878 + * prior notification. 879 + * 880 + * This will inevitably race with the firmware, risking that 881 + * we read data from the device before handling the associated 882 + * notification. To make things worse, some of the devices 883 + * needing the hack do not implement the "return zero if no 884 + * data is available" requirement either. Instead they return 885 + * an error on the subsequent read in this case. This means 886 + * that "winning" the race can cause an unexpected EIO to 887 + * userspace. 888 + * 889 + * "winning" the race is more likely on resume() than on 890 + * open(), and the unexpected error is more harmful in the 891 + * middle of an open session. The hack is therefore only 892 + * applied on open(), and not on resume() where it logically 893 + * would be equally necessary. So we define open() as the only 894 + * driver <-> device "syncronization point". Should we happen 895 + * to lose a notification after open(), then syncronization 896 + * will be lost until release() 897 + * 898 + * The hack should not be enabled for CDC WDM devices 899 + * conforming to the CDC-WMC r1.1 specification. This is 900 + * ensured by setting drain_on_open to false in wdm_probe(). 901 + */ 902 + if (drain_on_open) 903 + set_bit(WDM_DRAIN_ON_OPEN, &desc->flags); 904 + 894 905 spin_lock(&wdm_device_list_lock); 895 906 list_add(&desc->device_list, &wdm_device_list); 896 907 spin_unlock(&wdm_device_list_lock); ··· 1006 893 goto err; 1007 894 ep = &iface->endpoint[0].desc; 1008 895 1009 - rv = wdm_create(intf, ep, maxcom, &wdm_manage_power); 896 + rv = wdm_create(intf, ep, maxcom, &wdm_manage_power, false); 1010 897 1011 898 err: 1012 899 return rv; ··· 1038 925 { 1039 926 int rv = -EINVAL; 1040 927 1041 - rv = wdm_create(intf, ep, bufsize, manage_power); 928 + rv = wdm_create(intf, ep, bufsize, manage_power, true); 1042 929 if (rv < 0) 1043 930 goto err; 1044 931 ··· 1080 967 if (!desc->count) 1081 968 cleanup(desc); 1082 969 else 1083 - dev_dbg(&intf->dev, "%s: %d open files - postponing cleanup\n", __func__, desc->count); 970 + dev_dbg(&intf->dev, "%d open files - postponing cleanup\n", desc->count); 1084 971 mutex_unlock(&wdm_mutex); 1085 972 } 1086 973
+4 -7
drivers/usb/class/usbtmc.c
··· 141 141 struct usbtmc_device_data *data = to_usbtmc_data(kref); 142 142 143 143 usb_put_dev(data->usb_dev); 144 + kfree(data); 144 145 } 145 146 146 147 static int usbtmc_open(struct inode *inode, struct file *filp) ··· 1380 1379 1381 1380 dev_dbg(&intf->dev, "%s called\n", __func__); 1382 1381 1383 - data = devm_kzalloc(&intf->dev, sizeof(*data), GFP_KERNEL); 1382 + data = kmalloc(sizeof(*data), GFP_KERNEL); 1384 1383 if (!data) 1385 1384 return -ENOMEM; 1386 1385 ··· 1468 1467 if (data->iin_ep_present) { 1469 1468 /* allocate int urb */ 1470 1469 data->iin_urb = usb_alloc_urb(0, GFP_KERNEL); 1471 - if (!data->iin_urb) { 1472 - dev_err(&intf->dev, "Failed to allocate int urb\n"); 1470 + if (!data->iin_urb) 1473 1471 goto error_register; 1474 - } 1475 1472 1476 1473 /* will reference data in int urb */ 1477 1474 kref_get(&data->kref); ··· 1477 1478 /* allocate buffer for interrupt in */ 1478 1479 data->iin_buffer = kmalloc(data->iin_wMaxPacketSize, 1479 1480 GFP_KERNEL); 1480 - if (!data->iin_buffer) { 1481 - dev_err(&intf->dev, "Failed to allocate int buf\n"); 1481 + if (!data->iin_buffer) 1482 1482 goto error_register; 1483 - } 1484 1483 1485 1484 /* fill interrupt urb */ 1486 1485 usb_fill_int_urb(data->iin_urb, data->usb_dev,
+9 -7
drivers/usb/common/ulpi.c
··· 21 21 22 22 int ulpi_read(struct ulpi *ulpi, u8 addr) 23 23 { 24 - return ulpi->ops->read(ulpi->ops, addr); 24 + return ulpi->ops->read(ulpi->dev.parent, addr); 25 25 } 26 26 EXPORT_SYMBOL_GPL(ulpi_read); 27 27 28 28 int ulpi_write(struct ulpi *ulpi, u8 addr, u8 val) 29 29 { 30 - return ulpi->ops->write(ulpi->ops, addr, val); 30 + return ulpi->ops->write(ulpi->dev.parent, addr, val); 31 31 } 32 32 EXPORT_SYMBOL_GPL(ulpi_write); 33 33 ··· 127 127 * 128 128 * Registers a driver with the ULPI bus. 129 129 */ 130 - int ulpi_register_driver(struct ulpi_driver *drv) 130 + int __ulpi_register_driver(struct ulpi_driver *drv, struct module *module) 131 131 { 132 132 if (!drv->probe) 133 133 return -EINVAL; 134 134 135 + drv->driver.owner = module; 135 136 drv->driver.bus = &ulpi_bus; 136 137 137 138 return driver_register(&drv->driver); 138 139 } 139 - EXPORT_SYMBOL_GPL(ulpi_register_driver); 140 + EXPORT_SYMBOL_GPL(__ulpi_register_driver); 140 141 141 142 /** 142 143 * ulpi_unregister_driver - unregister a driver with the ULPI bus ··· 157 156 { 158 157 int ret; 159 158 159 + ulpi->dev.parent = dev; /* needed early for ops */ 160 + 160 161 /* Test the interface */ 161 162 ret = ulpi_write(ulpi, ULPI_SCRATCH, 0xaa); 162 163 if (ret < 0) ··· 177 174 ulpi->id.product = ulpi_read(ulpi, ULPI_PRODUCT_ID_LOW); 178 175 ulpi->id.product |= ulpi_read(ulpi, ULPI_PRODUCT_ID_HIGH) << 8; 179 176 180 - ulpi->dev.parent = dev; 181 177 ulpi->dev.bus = &ulpi_bus; 182 178 ulpi->dev.type = &ulpi_dev_type; 183 179 dev_set_name(&ulpi->dev, "%s.ulpi", dev_name(dev)); ··· 203 201 * Allocates and registers a ULPI device and an interface for it. Called from 204 202 * the USB controller that provides the ULPI interface. 205 203 */ 206 - struct ulpi *ulpi_register_interface(struct device *dev, struct ulpi_ops *ops) 204 + struct ulpi *ulpi_register_interface(struct device *dev, 205 + const struct ulpi_ops *ops) 207 206 { 208 207 struct ulpi *ulpi; 209 208 int ret; ··· 214 211 return ERR_PTR(-ENOMEM); 215 212 216 213 ulpi->ops = ops; 217 - ops->dev = dev; 218 214 219 215 ret = ulpi_register(dev, ulpi); 220 216 if (ret) {
+6 -19
drivers/usb/core/Kconfig
··· 83 83 Implements OTG Finite State Machine as specified in On-The-Go 84 84 and Embedded Host Supplement to the USB Revision 2.0 Specification. 85 85 86 - config USB_ULPI_BUS 87 - tristate "USB ULPI PHY interface support" 88 - depends on USB_SUPPORT 86 + config USB_LEDS_TRIGGER_USBPORT 87 + tristate "USB port LED trigger" 88 + depends on USB && LEDS_TRIGGERS 89 89 help 90 - UTMI+ Low Pin Interface (ULPI) is specification for a commonly used 91 - USB 2.0 PHY interface. The ULPI specification defines a standard set 92 - of registers that can be used to detect the vendor and product which 93 - allows ULPI to be handled as a bus. This module is the driver for that 94 - bus. 95 - 96 - The ULPI interfaces (the buses) are registered by the drivers for USB 97 - controllers which support ULPI register access and have ULPI PHY 98 - attached to them. The ULPI PHY drivers themselves are normal PHY 99 - drivers. 100 - 101 - ULPI PHYs provide often functions such as ADP sensing/probing (OTG 102 - protocol) and USB charger detection. 103 - 104 - To compile this driver as a module, choose M here: the module will 105 - be called ulpi. 90 + This driver allows LEDs to be controlled by USB events. Enabling this 91 + trigger allows specifying list of USB ports that should turn on LED 92 + when some USB device gets connected.
+4 -1
drivers/usb/core/Makefile
··· 5 5 usbcore-y := usb.o hub.o hcd.o urb.o message.o driver.o 6 6 usbcore-y += config.o file.o buffer.o sysfs.o endpoint.o 7 7 usbcore-y += devio.o notify.o generic.o quirks.o devices.o 8 - usbcore-y += port.o of.o 8 + usbcore-y += port.o 9 9 10 + usbcore-$(CONFIG_OF) += of.o 10 11 usbcore-$(CONFIG_PCI) += hcd-pci.o 11 12 usbcore-$(CONFIG_ACPI) += usb-acpi.o 12 13 13 14 obj-$(CONFIG_USB) += usbcore.o 15 + 16 + obj-$(CONFIG_USB_LEDS_TRIGGER_USBPORT) += ledtrig-usbport.o
+3 -4
drivers/usb/core/hcd.c
··· 46 46 #include <linux/usb.h> 47 47 #include <linux/usb/hcd.h> 48 48 #include <linux/usb/phy.h> 49 + #include <linux/usb/otg.h> 49 50 50 51 #include "usb.h" 51 52 ··· 2518 2517 struct usb_hcd *hcd; 2519 2518 2520 2519 hcd = kzalloc(sizeof(*hcd) + driver->hcd_priv_size, GFP_KERNEL); 2521 - if (!hcd) { 2522 - dev_dbg (dev, "hcd alloc failed\n"); 2520 + if (!hcd) 2523 2521 return NULL; 2524 - } 2525 2522 if (primary_hcd == NULL) { 2526 2523 hcd->address0_mutex = kmalloc(sizeof(*hcd->address0_mutex), 2527 2524 GFP_KERNEL); ··· 3032 3033 3033 3034 /*-------------------------------------------------------------------------*/ 3034 3035 3035 - #if defined(CONFIG_USB_MON) || defined(CONFIG_USB_MON_MODULE) 3036 + #if IS_ENABLED(CONFIG_USB_MON) 3036 3037 3037 3038 const struct usb_mon_operations *mon_ops; 3038 3039
+4 -7
drivers/usb/core/hub.c
··· 1823 1823 dev_info(&intf->dev, "USB hub found\n"); 1824 1824 1825 1825 hub = kzalloc(sizeof(*hub), GFP_KERNEL); 1826 - if (!hub) { 1827 - dev_dbg(&intf->dev, "couldn't kmalloc hub struct\n"); 1826 + if (!hub) 1828 1827 return -ENOMEM; 1829 - } 1830 1828 1831 1829 kref_init(&hub->kref); 1832 1830 hub->intfdev = &intf->dev; ··· 3104 3106 USB_CTRL_SET_TIMEOUT); 3105 3107 else 3106 3108 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 3107 - USB_REQ_CLEAR_FEATURE, USB_RECIP_INTERFACE, 3109 + USB_REQ_SET_FEATURE, USB_RECIP_INTERFACE, 3108 3110 USB_INTRF_FUNC_SUSPEND, 0, NULL, 0, 3109 3111 USB_CTRL_SET_TIMEOUT); 3110 3112 } ··· 5335 5337 } 5336 5338 5337 5339 buf = kmalloc(len, GFP_NOIO); 5338 - if (buf == NULL) { 5339 - dev_err(&udev->dev, "no mem to re-read configs after reset\n"); 5340 + if (!buf) 5340 5341 /* assume the worst */ 5341 5342 return 1; 5342 - } 5343 + 5343 5344 for (index = 0; index < udev->descriptor.bNumConfigurations; index++) { 5344 5345 old_length = le16_to_cpu(udev->config[index].desc.wTotalLength); 5345 5346 length = usb_get_descriptor(udev, USB_DT_CONFIG, index, buf,
+314
drivers/usb/core/ledtrig-usbport.c
··· 1 + /* 2 + * USB port LED trigger 3 + * 4 + * Copyright (C) 2016 Rafał Miłecki <rafal@milecki.pl> 5 + * 6 + * This program is free software; you can redistribute it and/or modify 7 + * it under the terms of the GNU General Public License version 2 as 8 + * published by the Free Software Foundation. 9 + */ 10 + 11 + #include <linux/device.h> 12 + #include <linux/leds.h> 13 + #include <linux/module.h> 14 + #include <linux/slab.h> 15 + #include <linux/usb.h> 16 + 17 + struct usbport_trig_data { 18 + struct led_classdev *led_cdev; 19 + struct list_head ports; 20 + struct notifier_block nb; 21 + int count; /* Amount of connected matching devices */ 22 + }; 23 + 24 + struct usbport_trig_port { 25 + struct usbport_trig_data *data; 26 + struct usb_device *hub; 27 + int portnum; 28 + char *port_name; 29 + bool observed; 30 + struct device_attribute attr; 31 + struct list_head list; 32 + }; 33 + 34 + /*************************************** 35 + * Helpers 36 + ***************************************/ 37 + 38 + /** 39 + * usbport_trig_usb_dev_observed - Check if dev is connected to observed port 40 + */ 41 + static bool usbport_trig_usb_dev_observed(struct usbport_trig_data *usbport_data, 42 + struct usb_device *usb_dev) 43 + { 44 + struct usbport_trig_port *port; 45 + 46 + if (!usb_dev->parent) 47 + return false; 48 + 49 + list_for_each_entry(port, &usbport_data->ports, list) { 50 + if (usb_dev->parent == port->hub && 51 + usb_dev->portnum == port->portnum) 52 + return port->observed; 53 + } 54 + 55 + return false; 56 + } 57 + 58 + static int usbport_trig_usb_dev_check(struct usb_device *usb_dev, void *data) 59 + { 60 + struct usbport_trig_data *usbport_data = data; 61 + 62 + if (usbport_trig_usb_dev_observed(usbport_data, usb_dev)) 63 + usbport_data->count++; 64 + 65 + return 0; 66 + } 67 + 68 + /** 69 + * usbport_trig_update_count - Recalculate amount of connected matching devices 70 + */ 71 + static void usbport_trig_update_count(struct usbport_trig_data *usbport_data) 72 + { 73 + struct led_classdev *led_cdev = usbport_data->led_cdev; 74 + 75 + usbport_data->count = 0; 76 + usb_for_each_dev(usbport_data, usbport_trig_usb_dev_check); 77 + led_cdev->brightness_set(led_cdev, 78 + usbport_data->count ? LED_FULL : LED_OFF); 79 + } 80 + 81 + /*************************************** 82 + * Device attr 83 + ***************************************/ 84 + 85 + static ssize_t usbport_trig_port_show(struct device *dev, 86 + struct device_attribute *attr, char *buf) 87 + { 88 + struct usbport_trig_port *port = container_of(attr, 89 + struct usbport_trig_port, 90 + attr); 91 + 92 + return sprintf(buf, "%d\n", port->observed) + 1; 93 + } 94 + 95 + static ssize_t usbport_trig_port_store(struct device *dev, 96 + struct device_attribute *attr, 97 + const char *buf, size_t size) 98 + { 99 + struct usbport_trig_port *port = container_of(attr, 100 + struct usbport_trig_port, 101 + attr); 102 + 103 + if (!strcmp(buf, "0") || !strcmp(buf, "0\n")) 104 + port->observed = 0; 105 + else if (!strcmp(buf, "1") || !strcmp(buf, "1\n")) 106 + port->observed = 1; 107 + else 108 + return -EINVAL; 109 + 110 + usbport_trig_update_count(port->data); 111 + 112 + return size; 113 + } 114 + 115 + static struct attribute *ports_attrs[] = { 116 + NULL, 117 + }; 118 + static const struct attribute_group ports_group = { 119 + .name = "ports", 120 + .attrs = ports_attrs, 121 + }; 122 + 123 + /*************************************** 124 + * Adding & removing ports 125 + ***************************************/ 126 + 127 + static int usbport_trig_add_port(struct usbport_trig_data *usbport_data, 128 + struct usb_device *usb_dev, 129 + const char *hub_name, int portnum) 130 + { 131 + struct led_classdev *led_cdev = usbport_data->led_cdev; 132 + struct usbport_trig_port *port; 133 + size_t len; 134 + int err; 135 + 136 + port = kzalloc(sizeof(*port), GFP_KERNEL); 137 + if (!port) { 138 + err = -ENOMEM; 139 + goto err_out; 140 + } 141 + 142 + port->data = usbport_data; 143 + port->hub = usb_dev; 144 + port->portnum = portnum; 145 + 146 + len = strlen(hub_name) + 8; 147 + port->port_name = kzalloc(len, GFP_KERNEL); 148 + if (!port->port_name) { 149 + err = -ENOMEM; 150 + goto err_free_port; 151 + } 152 + snprintf(port->port_name, len, "%s-port%d", hub_name, portnum); 153 + 154 + port->attr.attr.name = port->port_name; 155 + port->attr.attr.mode = S_IRUSR | S_IWUSR; 156 + port->attr.show = usbport_trig_port_show; 157 + port->attr.store = usbport_trig_port_store; 158 + 159 + err = sysfs_add_file_to_group(&led_cdev->dev->kobj, &port->attr.attr, 160 + ports_group.name); 161 + if (err) 162 + goto err_free_port_name; 163 + 164 + list_add_tail(&port->list, &usbport_data->ports); 165 + 166 + return 0; 167 + 168 + err_free_port_name: 169 + kfree(port->port_name); 170 + err_free_port: 171 + kfree(port); 172 + err_out: 173 + return err; 174 + } 175 + 176 + static int usbport_trig_add_usb_dev_ports(struct usb_device *usb_dev, 177 + void *data) 178 + { 179 + struct usbport_trig_data *usbport_data = data; 180 + int i; 181 + 182 + for (i = 1; i <= usb_dev->maxchild; i++) 183 + usbport_trig_add_port(usbport_data, usb_dev, 184 + dev_name(&usb_dev->dev), i); 185 + 186 + return 0; 187 + } 188 + 189 + static void usbport_trig_remove_port(struct usbport_trig_data *usbport_data, 190 + struct usbport_trig_port *port) 191 + { 192 + struct led_classdev *led_cdev = usbport_data->led_cdev; 193 + 194 + list_del(&port->list); 195 + sysfs_remove_file_from_group(&led_cdev->dev->kobj, &port->attr.attr, 196 + ports_group.name); 197 + kfree(port->port_name); 198 + kfree(port); 199 + } 200 + 201 + static void usbport_trig_remove_usb_dev_ports(struct usbport_trig_data *usbport_data, 202 + struct usb_device *usb_dev) 203 + { 204 + struct usbport_trig_port *port, *tmp; 205 + 206 + list_for_each_entry_safe(port, tmp, &usbport_data->ports, list) { 207 + if (port->hub == usb_dev) 208 + usbport_trig_remove_port(usbport_data, port); 209 + } 210 + } 211 + 212 + /*************************************** 213 + * Init, exit, etc. 214 + ***************************************/ 215 + 216 + static int usbport_trig_notify(struct notifier_block *nb, unsigned long action, 217 + void *data) 218 + { 219 + struct usbport_trig_data *usbport_data = 220 + container_of(nb, struct usbport_trig_data, nb); 221 + struct led_classdev *led_cdev = usbport_data->led_cdev; 222 + struct usb_device *usb_dev = data; 223 + bool observed; 224 + 225 + observed = usbport_trig_usb_dev_observed(usbport_data, usb_dev); 226 + 227 + switch (action) { 228 + case USB_DEVICE_ADD: 229 + usbport_trig_add_usb_dev_ports(usb_dev, usbport_data); 230 + if (observed && usbport_data->count++ == 0) 231 + led_cdev->brightness_set(led_cdev, LED_FULL); 232 + return NOTIFY_OK; 233 + case USB_DEVICE_REMOVE: 234 + usbport_trig_remove_usb_dev_ports(usbport_data, usb_dev); 235 + if (observed && --usbport_data->count == 0) 236 + led_cdev->brightness_set(led_cdev, LED_OFF); 237 + return NOTIFY_OK; 238 + } 239 + 240 + return NOTIFY_DONE; 241 + } 242 + 243 + static void usbport_trig_activate(struct led_classdev *led_cdev) 244 + { 245 + struct usbport_trig_data *usbport_data; 246 + int err; 247 + 248 + usbport_data = kzalloc(sizeof(*usbport_data), GFP_KERNEL); 249 + if (!usbport_data) 250 + return; 251 + usbport_data->led_cdev = led_cdev; 252 + 253 + /* List of ports */ 254 + INIT_LIST_HEAD(&usbport_data->ports); 255 + err = sysfs_create_group(&led_cdev->dev->kobj, &ports_group); 256 + if (err) 257 + goto err_free; 258 + usb_for_each_dev(usbport_data, usbport_trig_add_usb_dev_ports); 259 + 260 + /* Notifications */ 261 + usbport_data->nb.notifier_call = usbport_trig_notify, 262 + led_cdev->trigger_data = usbport_data; 263 + usb_register_notify(&usbport_data->nb); 264 + 265 + led_cdev->activated = true; 266 + return; 267 + 268 + err_free: 269 + kfree(usbport_data); 270 + } 271 + 272 + static void usbport_trig_deactivate(struct led_classdev *led_cdev) 273 + { 274 + struct usbport_trig_data *usbport_data = led_cdev->trigger_data; 275 + struct usbport_trig_port *port, *tmp; 276 + 277 + if (!led_cdev->activated) 278 + return; 279 + 280 + list_for_each_entry_safe(port, tmp, &usbport_data->ports, list) { 281 + usbport_trig_remove_port(usbport_data, port); 282 + } 283 + 284 + usb_unregister_notify(&usbport_data->nb); 285 + 286 + sysfs_remove_group(&led_cdev->dev->kobj, &ports_group); 287 + 288 + kfree(usbport_data); 289 + 290 + led_cdev->activated = false; 291 + } 292 + 293 + static struct led_trigger usbport_led_trigger = { 294 + .name = "usbport", 295 + .activate = usbport_trig_activate, 296 + .deactivate = usbport_trig_deactivate, 297 + }; 298 + 299 + static int __init usbport_trig_init(void) 300 + { 301 + return led_trigger_register(&usbport_led_trigger); 302 + } 303 + 304 + static void __exit usbport_trig_exit(void) 305 + { 306 + led_trigger_unregister(&usbport_led_trigger); 307 + } 308 + 309 + module_init(usbport_trig_init); 310 + module_exit(usbport_trig_exit); 311 + 312 + MODULE_AUTHOR("Rafał Miłecki <rafal@milecki.pl>"); 313 + MODULE_DESCRIPTION("USB port trigger"); 314 + MODULE_LICENSE("GPL v2");
+6 -4
drivers/usb/core/message.c
··· 1760 1760 nintf = cp->desc.bNumInterfaces; 1761 1761 new_interfaces = kmalloc(nintf * sizeof(*new_interfaces), 1762 1762 GFP_NOIO); 1763 - if (!new_interfaces) { 1764 - dev_err(&dev->dev, "Out of memory\n"); 1763 + if (!new_interfaces) 1765 1764 return -ENOMEM; 1766 - } 1767 1765 1768 1766 for (; n < nintf; ++n) { 1769 1767 new_interfaces[n] = kzalloc( 1770 1768 sizeof(struct usb_interface), 1771 1769 GFP_NOIO); 1772 1770 if (!new_interfaces[n]) { 1773 - dev_err(&dev->dev, "Out of memory\n"); 1774 1771 ret = -ENOMEM; 1775 1772 free_interfaces: 1776 1773 while (--n >= 0) ··· 1859 1862 intf->dev.bus = &usb_bus_type; 1860 1863 intf->dev.type = &usb_if_device_type; 1861 1864 intf->dev.groups = usb_interface_groups; 1865 + /* 1866 + * Please refer to usb_alloc_dev() to see why we set 1867 + * dma_mask and dma_pfn_offset. 1868 + */ 1862 1869 intf->dev.dma_mask = dev->dev.dma_mask; 1870 + intf->dev.dma_pfn_offset = dev->dev.dma_pfn_offset; 1863 1871 INIT_WORK(&intf->reset_ws, __usb_queue_reset_device); 1864 1872 intf->minor = -1; 1865 1873 device_initialize(&intf->dev);
+1
drivers/usb/core/of.c
··· 18 18 */ 19 19 20 20 #include <linux/of.h> 21 + #include <linux/usb/of.h> 21 22 22 23 /** 23 24 * usb_of_get_child_node - Find the device node match port number
+1 -1
drivers/usb/core/otg_whitelist.h
··· 38 38 { USB_DEVICE(0x0525, 0xa4a2), }, 39 39 #endif 40 40 41 - #if defined(CONFIG_USB_TEST) || defined(CONFIG_USB_TEST_MODULE) 41 + #if IS_ENABLED(CONFIG_USB_TEST) 42 42 /* gadget zero, for testing */ 43 43 { USB_DEVICE(0x0525, 0xa4a0), }, 44 44 #endif
+1 -3
drivers/usb/core/urb.c
··· 68 68 urb = kmalloc(sizeof(struct urb) + 69 69 iso_packets * sizeof(struct usb_iso_packet_descriptor), 70 70 mem_flags); 71 - if (!urb) { 72 - printk(KERN_ERR "alloc_urb: kmalloc failed\n"); 71 + if (!urb) 73 72 return NULL; 74 - } 75 73 usb_init_urb(urb); 76 74 return urb; 77 75 }
+11
drivers/usb/core/usb.c
··· 440 440 dev->dev.bus = &usb_bus_type; 441 441 dev->dev.type = &usb_device_type; 442 442 dev->dev.groups = usb_device_groups; 443 + /* 444 + * Fake a dma_mask/offset for the USB device: 445 + * We cannot really use the dma-mapping API (dma_alloc_* and 446 + * dma_map_*) for USB devices but instead need to use 447 + * usb_alloc_coherent and pass data in 'urb's, but some subsystems 448 + * manually look into the mask/offset pair to determine whether 449 + * they need bounce buffers. 450 + * Note: calling dma_set_mask() on a USB device would set the 451 + * mask for the entire HCD, so don't do that. 452 + */ 443 453 dev->dev.dma_mask = bus->controller->dma_mask; 454 + dev->dev.dma_pfn_offset = bus->controller->dma_pfn_offset; 444 455 set_dev_node(&dev->dev, dev_to_node(bus->controller)); 445 456 dev->state = USB_STATE_ATTACHED; 446 457 dev->lpm_disable_count = 1;
+109 -17
drivers/usb/dwc2/core.c
··· 238 238 return ret; 239 239 } 240 240 241 + /** 242 + * dwc2_wait_for_mode() - Waits for the controller mode. 243 + * @hsotg: Programming view of the DWC_otg controller. 244 + * @host_mode: If true, waits for host mode, otherwise device mode. 245 + */ 246 + static void dwc2_wait_for_mode(struct dwc2_hsotg *hsotg, 247 + bool host_mode) 248 + { 249 + ktime_t start; 250 + ktime_t end; 251 + unsigned int timeout = 110; 252 + 253 + dev_vdbg(hsotg->dev, "Waiting for %s mode\n", 254 + host_mode ? "host" : "device"); 255 + 256 + start = ktime_get(); 257 + 258 + while (1) { 259 + s64 ms; 260 + 261 + if (dwc2_is_host_mode(hsotg) == host_mode) { 262 + dev_vdbg(hsotg->dev, "%s mode set\n", 263 + host_mode ? "Host" : "Device"); 264 + break; 265 + } 266 + 267 + end = ktime_get(); 268 + ms = ktime_to_ms(ktime_sub(end, start)); 269 + 270 + if (ms >= (s64)timeout) { 271 + dev_warn(hsotg->dev, "%s: Couldn't set %s mode\n", 272 + __func__, host_mode ? "host" : "device"); 273 + break; 274 + } 275 + 276 + usleep_range(1000, 2000); 277 + } 278 + } 279 + 280 + /** 281 + * dwc2_iddig_filter_enabled() - Returns true if the IDDIG debounce 282 + * filter is enabled. 283 + */ 284 + static bool dwc2_iddig_filter_enabled(struct dwc2_hsotg *hsotg) 285 + { 286 + u32 gsnpsid; 287 + u32 ghwcfg4; 288 + 289 + if (!dwc2_hw_is_otg(hsotg)) 290 + return false; 291 + 292 + /* Check if core configuration includes the IDDIG filter. */ 293 + ghwcfg4 = dwc2_readl(hsotg->regs + GHWCFG4); 294 + if (!(ghwcfg4 & GHWCFG4_IDDIG_FILT_EN)) 295 + return false; 296 + 297 + /* 298 + * Check if the IDDIG debounce filter is bypassed. Available 299 + * in core version >= 3.10a. 300 + */ 301 + gsnpsid = dwc2_readl(hsotg->regs + GSNPSID); 302 + if (gsnpsid >= DWC2_CORE_REV_3_10a) { 303 + u32 gotgctl = dwc2_readl(hsotg->regs + GOTGCTL); 304 + 305 + if (gotgctl & GOTGCTL_DBNCE_FLTR_BYPASS) 306 + return false; 307 + } 308 + 309 + return true; 310 + } 311 + 241 312 /* 242 313 * Do core a soft reset of the core. Be careful with this because it 243 314 * resets all the internal state machines of the core. ··· 317 246 { 318 247 u32 greset; 319 248 int count = 0; 249 + bool wait_for_host_mode = false; 320 250 321 251 dev_vdbg(hsotg->dev, "%s()\n", __func__); 252 + 253 + /* 254 + * If the current mode is host, either due to the force mode 255 + * bit being set (which persists after core reset) or the 256 + * connector id pin, a core soft reset will temporarily reset 257 + * the mode to device. A delay from the IDDIG debounce filter 258 + * will occur before going back to host mode. 259 + * 260 + * Determine whether we will go back into host mode after a 261 + * reset and account for this delay after the reset. 262 + */ 263 + if (dwc2_iddig_filter_enabled(hsotg)) { 264 + u32 gotgctl = dwc2_readl(hsotg->regs + GOTGCTL); 265 + u32 gusbcfg = dwc2_readl(hsotg->regs + GUSBCFG); 266 + 267 + if (!(gotgctl & GOTGCTL_CONID_B) || 268 + (gusbcfg & GUSBCFG_FORCEHOSTMODE)) { 269 + wait_for_host_mode = true; 270 + } 271 + } 322 272 323 273 /* Core Soft Reset */ 324 274 greset = dwc2_readl(hsotg->regs + GRSTCTL); ··· 369 277 } 370 278 } while (!(greset & GRSTCTL_AHBIDLE)); 371 279 280 + if (wait_for_host_mode) 281 + dwc2_wait_for_mode(hsotg, true); 282 + 372 283 return 0; 373 284 } 374 285 ··· 395 300 * Checks are done in this function to determine whether doing a force 396 301 * would be valid or not. 397 302 * 398 - * If a force is done, it requires a 25ms delay to take effect. 399 - * 400 - * Returns true if the mode was forced. 303 + * If a force is done, it requires a IDDIG debounce filter delay if 304 + * the filter is configured and enabled. We poll the current mode of 305 + * the controller to account for this delay. 401 306 */ 402 307 static bool dwc2_force_mode(struct dwc2_hsotg *hsotg, bool host) 403 308 { ··· 432 337 gusbcfg |= set; 433 338 dwc2_writel(gusbcfg, hsotg->regs + GUSBCFG); 434 339 435 - msleep(25); 340 + dwc2_wait_for_mode(hsotg, host); 436 341 return true; 437 342 } 438 343 439 - /* 440 - * Clears the force mode bits. 344 + /** 345 + * dwc2_clear_force_mode() - Clears the force mode bits. 346 + * 347 + * After clearing the bits, wait up to 100 ms to account for any 348 + * potential IDDIG filter delay. We can't know if we expect this delay 349 + * or not because the value of the connector ID status is affected by 350 + * the force mode. We only need to call this once during probe if 351 + * dr_mode == OTG. 441 352 */ 442 353 static void dwc2_clear_force_mode(struct dwc2_hsotg *hsotg) 443 354 { ··· 454 353 gusbcfg &= ~GUSBCFG_FORCEDEVMODE; 455 354 dwc2_writel(gusbcfg, hsotg->regs + GUSBCFG); 456 355 457 - /* 458 - * NOTE: This long sleep is _very_ important, otherwise the core will 459 - * not stay in host mode after a connector ID change! 460 - */ 461 - msleep(25); 356 + if (dwc2_iddig_filter_enabled(hsotg)) 357 + usleep_range(100000, 110000); 462 358 } 463 359 464 360 /* ··· 478 380 __func__, hsotg->dr_mode); 479 381 break; 480 382 } 481 - 482 - /* 483 - * NOTE: This is required for some rockchip soc based 484 - * platforms. 485 - */ 486 - msleep(50); 487 383 } 488 384 489 385 /*
+1 -7
drivers/usb/dwc2/core.h
··· 259 259 DWC2_L3, /* Off state */ 260 260 }; 261 261 262 - /* 263 - * Gadget periodic tx fifo sizes as used by legacy driver 264 - * EP0 is not included 265 - */ 266 - #define DWC2_G_P_LEGACY_TX_FIFO_SIZE {256, 256, 256, 256, 768, 768, 768, \ 267 - 768, 0, 0, 0, 0, 0, 0, 0} 268 - 269 262 /* Gadget ep0 states */ 270 263 enum dwc2_ep0_state { 271 264 DWC2_EP0_SETUP, ··· 883 890 #define DWC2_CORE_REV_2_92a 0x4f54292a 884 891 #define DWC2_CORE_REV_2_94a 0x4f54294a 885 892 #define DWC2_CORE_REV_3_00a 0x4f54300a 893 + #define DWC2_CORE_REV_3_10a 0x4f54310a 886 894 887 895 #if IS_ENABLED(CONFIG_USB_DWC2_HOST) || IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE) 888 896 union dwc2_hcd_internal_flags {
+26 -68
drivers/usb/dwc2/gadget.c
··· 186 186 */ 187 187 static void dwc2_hsotg_init_fifo(struct dwc2_hsotg *hsotg) 188 188 { 189 - unsigned int ep; 189 + unsigned int fifo; 190 190 unsigned int addr; 191 191 int timeout; 192 + u32 dptxfsizn; 192 193 u32 val; 193 194 194 195 /* Reset fifo map if not correctly cleared during previous session */ ··· 217 216 * them to endpoints dynamically according to maxpacket size value of 218 217 * given endpoint. 219 218 */ 220 - for (ep = 1; ep < MAX_EPS_CHANNELS; ep++) { 221 - if (!hsotg->g_tx_fifo_sz[ep]) 222 - continue; 223 - val = addr; 224 - val |= hsotg->g_tx_fifo_sz[ep] << FIFOSIZE_DEPTH_SHIFT; 225 - WARN_ONCE(addr + hsotg->g_tx_fifo_sz[ep] > hsotg->fifo_mem, 226 - "insufficient fifo memory"); 227 - addr += hsotg->g_tx_fifo_sz[ep]; 219 + for (fifo = 1; fifo < MAX_EPS_CHANNELS; fifo++) { 220 + dptxfsizn = dwc2_readl(hsotg->regs + DPTXFSIZN(fifo)); 228 221 229 - dwc2_writel(val, hsotg->regs + DPTXFSIZN(ep)); 222 + val = (dptxfsizn & FIFOSIZE_DEPTH_MASK) | addr; 223 + addr += dptxfsizn >> FIFOSIZE_DEPTH_SHIFT; 224 + 225 + if (addr > hsotg->fifo_mem) 226 + break; 227 + 228 + dwc2_writel(val, hsotg->regs + DPTXFSIZN(fifo)); 230 229 } 231 230 232 231 /* ··· 389 388 return -ENOSPC; 390 389 } 391 390 } else if (hsotg->dedicated_fifos && hs_ep->index != 0) { 392 - can_write = dwc2_readl(hsotg->regs + DTXFSTS(hs_ep->index)); 391 + can_write = dwc2_readl(hsotg->regs + 392 + DTXFSTS(hs_ep->fifo_index)); 393 393 394 394 can_write &= 0xffff; 395 395 can_write *= 4; ··· 2434 2432 2435 2433 if (!hsotg->dedicated_fifos) 2436 2434 return; 2437 - size = (dwc2_readl(hsotg->regs + DTXFSTS(ep->index)) & 0xffff) * 4; 2435 + size = (dwc2_readl(hsotg->regs + DTXFSTS(ep->fifo_index)) & 0xffff) * 4; 2438 2436 if (size < ep->fifo_size) 2439 2437 dwc2_hsotg_txfifo_flush(hsotg, ep->fifo_index); 2440 2438 } ··· 3043 3041 break; 3044 3042 } 3045 3043 3046 - /* If fifo is already allocated for this ep */ 3047 - if (hs_ep->fifo_index) { 3048 - size = hs_ep->ep.maxpacket * hs_ep->mc; 3049 - /* If bigger fifo is required deallocate current one */ 3050 - if (size > hs_ep->fifo_size) { 3051 - hsotg->fifo_map &= ~(1 << hs_ep->fifo_index); 3052 - hs_ep->fifo_index = 0; 3053 - hs_ep->fifo_size = 0; 3054 - } 3055 - } 3056 - 3057 3044 /* 3058 3045 * if the hardware has dedicated fifos, we must give each IN EP 3059 3046 * a unique tx-fifo even if it is non-periodic. 3060 3047 */ 3061 - if (dir_in && hsotg->dedicated_fifos && !hs_ep->fifo_index) { 3048 + if (dir_in && hsotg->dedicated_fifos) { 3062 3049 u32 fifo_index = 0; 3063 3050 u32 fifo_size = UINT_MAX; 3064 3051 size = hs_ep->ep.maxpacket*hs_ep->mc; ··· 3120 3129 3121 3130 spin_lock_irqsave(&hsotg->lock, flags); 3122 3131 3123 - hsotg->fifo_map &= ~(1<<hs_ep->fifo_index); 3124 - hs_ep->fifo_index = 0; 3125 - hs_ep->fifo_size = 0; 3126 - 3127 3132 ctrl = dwc2_readl(hsotg->regs + epctrl_reg); 3128 3133 ctrl &= ~DXEPCTL_EPENA; 3129 3134 ctrl &= ~DXEPCTL_USBACTEP; ··· 3133 3146 3134 3147 /* terminate all requests with shutdown */ 3135 3148 kill_all_requests(hsotg, hs_ep, -ESHUTDOWN); 3149 + 3150 + hsotg->fifo_map &= ~(1 << hs_ep->fifo_index); 3151 + hs_ep->fifo_index = 0; 3152 + hs_ep->fifo_size = 0; 3136 3153 3137 3154 spin_unlock_irqrestore(&hsotg->lock, flags); 3138 3155 return 0; ··· 3466 3475 otg_set_peripheral(hsotg->uphy->otg, &hsotg->gadget); 3467 3476 3468 3477 spin_lock_irqsave(&hsotg->lock, flags); 3469 - dwc2_hsotg_init(hsotg); 3470 - dwc2_hsotg_core_init_disconnected(hsotg, false); 3478 + if (dwc2_hw_is_device(hsotg)) { 3479 + dwc2_hsotg_init(hsotg); 3480 + dwc2_hsotg_core_init_disconnected(hsotg, false); 3481 + } 3482 + 3471 3483 hsotg->enabled = 0; 3472 3484 spin_unlock_irqrestore(&hsotg->lock, flags); 3473 3485 ··· 3807 3813 static void dwc2_hsotg_of_probe(struct dwc2_hsotg *hsotg) 3808 3814 { 3809 3815 struct device_node *np = hsotg->dev->of_node; 3810 - u32 len = 0; 3811 - u32 i = 0; 3812 3816 3813 3817 /* Enable dma if requested in device tree */ 3814 3818 hsotg->g_using_dma = of_property_read_bool(np, "g-use-dma"); 3815 3819 3816 - /* 3817 - * Register TX periodic fifo size per endpoint. 3818 - * EP0 is excluded since it has no fifo configuration. 3819 - */ 3820 - if (!of_find_property(np, "g-tx-fifo-size", &len)) 3821 - goto rx_fifo; 3822 - 3823 - len /= sizeof(u32); 3824 - 3825 - /* Read tx fifo sizes other than ep0 */ 3826 - if (of_property_read_u32_array(np, "g-tx-fifo-size", 3827 - &hsotg->g_tx_fifo_sz[1], len)) 3828 - goto rx_fifo; 3829 - 3830 - /* Add ep0 */ 3831 - len++; 3832 - 3833 - /* Make remaining TX fifos unavailable */ 3834 - if (len < MAX_EPS_CHANNELS) { 3835 - for (i = len; i < MAX_EPS_CHANNELS; i++) 3836 - hsotg->g_tx_fifo_sz[i] = 0; 3837 - } 3838 - 3839 - rx_fifo: 3840 3820 /* Register RX fifo size */ 3841 3821 of_property_read_u32(np, "g-rx-fifo-size", &hsotg->g_rx_fifo_sz); 3842 3822 ··· 3832 3864 struct device *dev = hsotg->dev; 3833 3865 int epnum; 3834 3866 int ret; 3835 - int i; 3836 - u32 p_tx_fifo[] = DWC2_G_P_LEGACY_TX_FIFO_SIZE; 3837 3867 3838 3868 /* Initialize to legacy fifo configuration values */ 3839 3869 hsotg->g_rx_fifo_sz = 2048; 3840 3870 hsotg->g_np_g_tx_fifo_sz = 1024; 3841 - memcpy(&hsotg->g_tx_fifo_sz[1], p_tx_fifo, sizeof(p_tx_fifo)); 3842 3871 /* Device tree specific probe */ 3843 3872 dwc2_hsotg_of_probe(hsotg); 3844 3873 ··· 3853 3888 dev_dbg(dev, "NonPeriodic TXFIFO size: %d\n", 3854 3889 hsotg->g_np_g_tx_fifo_sz); 3855 3890 dev_dbg(dev, "RXFIFO size: %d\n", hsotg->g_rx_fifo_sz); 3856 - for (i = 0; i < MAX_EPS_CHANNELS; i++) 3857 - dev_dbg(dev, "Periodic TXFIFO%2d size: %d\n", i, 3858 - hsotg->g_tx_fifo_sz[i]); 3859 3891 3860 3892 hsotg->gadget.max_speed = USB_SPEED_HIGH; 3861 3893 hsotg->gadget.ops = &dwc2_hsotg_gadget_ops; ··· 3870 3908 3871 3909 hsotg->ctrl_buff = devm_kzalloc(hsotg->dev, 3872 3910 DWC2_CTRL_BUFF_SIZE, GFP_KERNEL); 3873 - if (!hsotg->ctrl_buff) { 3874 - dev_err(dev, "failed to allocate ctrl request buff\n"); 3911 + if (!hsotg->ctrl_buff) 3875 3912 return -ENOMEM; 3876 - } 3877 3913 3878 3914 hsotg->ep0_buff = devm_kzalloc(hsotg->dev, 3879 3915 DWC2_CTRL_BUFF_SIZE, GFP_KERNEL); 3880 - if (!hsotg->ep0_buff) { 3881 - dev_err(dev, "failed to allocate ctrl reply buff\n"); 3916 + if (!hsotg->ep0_buff) 3882 3917 return -ENOMEM; 3883 - } 3884 3918 3885 3919 ret = devm_request_irq(hsotg->dev, irq, dwc2_hsotg_irq, IRQF_SHARED, 3886 3920 dev_name(hsotg->dev), hsotg);
+1 -1
drivers/usb/dwc2/hcd.c
··· 5040 5040 5041 5041 /* Create new workqueue and init work */ 5042 5042 retval = -ENOMEM; 5043 - hsotg->wq_otg = create_singlethread_workqueue("dwc2"); 5043 + hsotg->wq_otg = alloc_ordered_workqueue("dwc2", 0); 5044 5044 if (!hsotg->wq_otg) { 5045 5045 dev_err(hsotg->dev, "Failed to create workqueue\n"); 5046 5046 goto error2;
+1
drivers/usb/dwc2/hw.h
··· 48 48 #define GOTGCTL_ASESVLD (1 << 18) 49 49 #define GOTGCTL_DBNC_SHORT (1 << 17) 50 50 #define GOTGCTL_CONID_B (1 << 16) 51 + #define GOTGCTL_DBNCE_FLTR_BYPASS (1 << 15) 51 52 #define GOTGCTL_DEVHNPEN (1 << 11) 52 53 #define GOTGCTL_HSTSETHNPEN (1 << 10) 53 54 #define GOTGCTL_HNPREQ (1 << 9)
+1 -1
drivers/usb/dwc3/Kconfig
··· 1 1 config USB_DWC3 2 2 tristate "DesignWare USB3 DRD Core Support" 3 3 depends on (USB || USB_GADGET) && HAS_DMA 4 - select USB_XHCI_PLATFORM if USB_SUPPORT && USB_XHCI_HCD 4 + select USB_XHCI_PLATFORM if USB_XHCI_HCD 5 5 help 6 6 Say Y or M here if your system has a Dual Role SuperSpeed 7 7 USB controller based on the DesignWare USB3 IP Core.
+108 -14
drivers/usb/dwc3/core.c
··· 49 49 50 50 #define DWC3_DEFAULT_AUTOSUSPEND_DELAY 5000 /* ms */ 51 51 52 + /** 53 + * dwc3_get_dr_mode - Validates and sets dr_mode 54 + * @dwc: pointer to our context structure 55 + */ 56 + static int dwc3_get_dr_mode(struct dwc3 *dwc) 57 + { 58 + enum usb_dr_mode mode; 59 + struct device *dev = dwc->dev; 60 + unsigned int hw_mode; 61 + 62 + if (dwc->dr_mode == USB_DR_MODE_UNKNOWN) 63 + dwc->dr_mode = USB_DR_MODE_OTG; 64 + 65 + mode = dwc->dr_mode; 66 + hw_mode = DWC3_GHWPARAMS0_MODE(dwc->hwparams.hwparams0); 67 + 68 + switch (hw_mode) { 69 + case DWC3_GHWPARAMS0_MODE_GADGET: 70 + if (IS_ENABLED(CONFIG_USB_DWC3_HOST)) { 71 + dev_err(dev, 72 + "Controller does not support host mode.\n"); 73 + return -EINVAL; 74 + } 75 + mode = USB_DR_MODE_PERIPHERAL; 76 + break; 77 + case DWC3_GHWPARAMS0_MODE_HOST: 78 + if (IS_ENABLED(CONFIG_USB_DWC3_GADGET)) { 79 + dev_err(dev, 80 + "Controller does not support device mode.\n"); 81 + return -EINVAL; 82 + } 83 + mode = USB_DR_MODE_HOST; 84 + break; 85 + default: 86 + if (IS_ENABLED(CONFIG_USB_DWC3_HOST)) 87 + mode = USB_DR_MODE_HOST; 88 + else if (IS_ENABLED(CONFIG_USB_DWC3_GADGET)) 89 + mode = USB_DR_MODE_PERIPHERAL; 90 + } 91 + 92 + if (mode != dwc->dr_mode) { 93 + dev_warn(dev, 94 + "Configuration mismatch. dr_mode forced to %s\n", 95 + mode == USB_DR_MODE_HOST ? "host" : "gadget"); 96 + 97 + dwc->dr_mode = mode; 98 + } 99 + 100 + return 0; 101 + } 102 + 52 103 void dwc3_set_mode(struct dwc3 *dwc, u32 mode) 53 104 { 54 105 u32 reg; ··· 499 448 if (dwc->dis_u3_susphy_quirk) 500 449 reg &= ~DWC3_GUSB3PIPECTL_SUSPHY; 501 450 451 + if (dwc->dis_del_phy_power_chg_quirk) 452 + reg &= ~DWC3_GUSB3PIPECTL_DEPOCHANGE; 453 + 502 454 dwc3_writel(dwc->regs, DWC3_GUSB3PIPECTL(0), reg); 503 455 504 456 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)); ··· 539 485 break; 540 486 } 541 487 488 + switch (dwc->hsphy_mode) { 489 + case USBPHY_INTERFACE_MODE_UTMI: 490 + reg &= ~(DWC3_GUSB2PHYCFG_PHYIF_MASK | 491 + DWC3_GUSB2PHYCFG_USBTRDTIM_MASK); 492 + reg |= DWC3_GUSB2PHYCFG_PHYIF(UTMI_PHYIF_8_BIT) | 493 + DWC3_GUSB2PHYCFG_USBTRDTIM(USBTRDTIM_UTMI_8_BIT); 494 + break; 495 + case USBPHY_INTERFACE_MODE_UTMIW: 496 + reg &= ~(DWC3_GUSB2PHYCFG_PHYIF_MASK | 497 + DWC3_GUSB2PHYCFG_USBTRDTIM_MASK); 498 + reg |= DWC3_GUSB2PHYCFG_PHYIF(UTMI_PHYIF_16_BIT) | 499 + DWC3_GUSB2PHYCFG_USBTRDTIM(USBTRDTIM_UTMI_16_BIT); 500 + break; 501 + default: 502 + break; 503 + } 504 + 542 505 /* 543 506 * Above 1.94a, it is recommended to set DWC3_GUSB2PHYCFG_SUSPHY to 544 507 * '0' during coreConsultant configuration. So default value will ··· 570 499 571 500 if (dwc->dis_enblslpm_quirk) 572 501 reg &= ~DWC3_GUSB2PHYCFG_ENBLSLPM; 502 + 503 + if (dwc->dis_u2_freeclk_exists_quirk) 504 + reg &= ~DWC3_GUSB2PHYCFG_U2_FREECLK_EXISTS; 573 505 574 506 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); 575 507 ··· 740 666 goto err4; 741 667 } 742 668 669 + switch (dwc->dr_mode) { 670 + case USB_DR_MODE_PERIPHERAL: 671 + dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_DEVICE); 672 + break; 673 + case USB_DR_MODE_HOST: 674 + dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_HOST); 675 + break; 676 + case USB_DR_MODE_OTG: 677 + dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_OTG); 678 + break; 679 + default: 680 + dev_warn(dwc->dev, "Unsupported mode %d\n", dwc->dr_mode); 681 + break; 682 + } 683 + 684 + /* 685 + * ENDXFER polling is available on version 3.10a and later of 686 + * the DWC_usb3 controller. It is NOT available in the 687 + * DWC_usb31 controller. 688 + */ 689 + if (!dwc3_is_usb31(dwc) && dwc->revision >= DWC3_REVISION_310A) { 690 + reg = dwc3_readl(dwc->regs, DWC3_GUCTL2); 691 + reg |= DWC3_GUCTL2_RST_ACTBITLATER; 692 + dwc3_writel(dwc->regs, DWC3_GUCTL2, reg); 693 + } 694 + 743 695 return 0; 744 696 745 697 err4: ··· 863 763 864 764 switch (dwc->dr_mode) { 865 765 case USB_DR_MODE_PERIPHERAL: 866 - dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_DEVICE); 867 766 ret = dwc3_gadget_init(dwc); 868 767 if (ret) { 869 768 if (ret != -EPROBE_DEFER) ··· 871 772 } 872 773 break; 873 774 case USB_DR_MODE_HOST: 874 - dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_HOST); 875 775 ret = dwc3_host_init(dwc); 876 776 if (ret) { 877 777 if (ret != -EPROBE_DEFER) ··· 879 781 } 880 782 break; 881 783 case USB_DR_MODE_OTG: 882 - dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_OTG); 883 784 ret = dwc3_host_init(dwc); 884 785 if (ret) { 885 786 if (ret != -EPROBE_DEFER) ··· 985 888 986 889 dwc->maximum_speed = usb_get_maximum_speed(dev); 987 890 dwc->dr_mode = usb_get_dr_mode(dev); 891 + dwc->hsphy_mode = of_usb_get_phy_mode(dev->of_node); 988 892 989 893 dwc->has_lpm_erratum = device_property_read_bool(dev, 990 894 "snps,has-lpm-erratum"); ··· 1022 924 "snps,dis_enblslpm_quirk"); 1023 925 dwc->dis_rxdet_inp3_quirk = device_property_read_bool(dev, 1024 926 "snps,dis_rxdet_inp3_quirk"); 927 + dwc->dis_u2_freeclk_exists_quirk = device_property_read_bool(dev, 928 + "snps,dis-u2-freeclk-exists-quirk"); 929 + dwc->dis_del_phy_power_chg_quirk = device_property_read_bool(dev, 930 + "snps,dis-del-phy-power-chg-quirk"); 1025 931 1026 932 dwc->tx_de_emphasis_quirk = device_property_read_bool(dev, 1027 933 "snps,tx_de_emphasis_quirk"); ··· 1074 972 goto err2; 1075 973 } 1076 974 1077 - if (IS_ENABLED(CONFIG_USB_DWC3_HOST) && 1078 - (dwc->dr_mode == USB_DR_MODE_OTG || 1079 - dwc->dr_mode == USB_DR_MODE_UNKNOWN)) 1080 - dwc->dr_mode = USB_DR_MODE_HOST; 1081 - else if (IS_ENABLED(CONFIG_USB_DWC3_GADGET) && 1082 - (dwc->dr_mode == USB_DR_MODE_OTG || 1083 - dwc->dr_mode == USB_DR_MODE_UNKNOWN)) 1084 - dwc->dr_mode = USB_DR_MODE_PERIPHERAL; 1085 - 1086 - if (dwc->dr_mode == USB_DR_MODE_UNKNOWN) 1087 - dwc->dr_mode = USB_DR_MODE_OTG; 975 + ret = dwc3_get_dr_mode(dwc); 976 + if (ret) 977 + goto err3; 1088 978 1089 979 ret = dwc3_alloc_scratch_buffers(dwc); 1090 980 if (ret)
+34 -1
drivers/usb/dwc3/core.h
··· 109 109 #define DWC3_GPRTBIMAP_HS1 0xc184 110 110 #define DWC3_GPRTBIMAP_FS0 0xc188 111 111 #define DWC3_GPRTBIMAP_FS1 0xc18c 112 + #define DWC3_GUCTL2 0xc19c 112 113 113 114 #define DWC3_VER_NUMBER 0xc1a0 114 115 #define DWC3_VER_TYPE 0xc1a4 ··· 200 199 201 200 /* Global USB2 PHY Configuration Register */ 202 201 #define DWC3_GUSB2PHYCFG_PHYSOFTRST (1 << 31) 202 + #define DWC3_GUSB2PHYCFG_U2_FREECLK_EXISTS (1 << 30) 203 203 #define DWC3_GUSB2PHYCFG_SUSPHY (1 << 6) 204 204 #define DWC3_GUSB2PHYCFG_ULPI_UTMI (1 << 4) 205 205 #define DWC3_GUSB2PHYCFG_ENBLSLPM (1 << 8) 206 + #define DWC3_GUSB2PHYCFG_PHYIF(n) (n << 3) 207 + #define DWC3_GUSB2PHYCFG_PHYIF_MASK DWC3_GUSB2PHYCFG_PHYIF(1) 208 + #define DWC3_GUSB2PHYCFG_USBTRDTIM(n) (n << 10) 209 + #define DWC3_GUSB2PHYCFG_USBTRDTIM_MASK DWC3_GUSB2PHYCFG_USBTRDTIM(0xf) 210 + #define USBTRDTIM_UTMI_8_BIT 9 211 + #define USBTRDTIM_UTMI_16_BIT 5 212 + #define UTMI_PHYIF_16_BIT 1 213 + #define UTMI_PHYIF_8_BIT 0 206 214 207 215 /* Global USB2 PHY Vendor Control Register */ 208 216 #define DWC3_GUSB2PHYACC_NEWREGREQ (1 << 25) ··· 245 235 #define DWC3_GEVNTSIZ_SIZE(n) ((n) & 0xffff) 246 236 247 237 /* Global HWPARAMS0 Register */ 248 - #define DWC3_GHWPARAMS0_USB3_MODE(n) ((n) & 0x3) 238 + #define DWC3_GHWPARAMS0_MODE(n) ((n) & 0x3) 239 + #define DWC3_GHWPARAMS0_MODE_GADGET 0 240 + #define DWC3_GHWPARAMS0_MODE_HOST 1 241 + #define DWC3_GHWPARAMS0_MODE_DRD 2 249 242 #define DWC3_GHWPARAMS0_MBUS_TYPE(n) (((n) >> 3) & 0x7) 250 243 #define DWC3_GHWPARAMS0_SBUS_TYPE(n) (((n) >> 6) & 0x3) 251 244 #define DWC3_GHWPARAMS0_MDWIDTH(n) (((n) >> 8) & 0xff) ··· 291 278 /* Global Frame Length Adjustment Register */ 292 279 #define DWC3_GFLADJ_30MHZ_SDBND_SEL (1 << 7) 293 280 #define DWC3_GFLADJ_30MHZ_MASK 0x3f 281 + 282 + /* Global User Control Register 2 */ 283 + #define DWC3_GUCTL2_RST_ACTBITLATER (1 << 14) 294 284 295 285 /* Device Configuration Register */ 296 286 #define DWC3_DCFG_DEVADDR(addr) ((addr) << 3) ··· 701 685 * @request: struct usb_request to be transferred 702 686 * @list: a list_head used for request queueing 703 687 * @dep: struct dwc3_ep owning this request 688 + * @sg: pointer to first incomplete sg 689 + * @num_pending_sgs: counter to pending sgs 704 690 * @first_trb_index: index to first trb used by this request 705 691 * @epnum: endpoint number to which this request refers 706 692 * @trb: pointer to struct dwc3_trb ··· 715 697 struct usb_request request; 716 698 struct list_head list; 717 699 struct dwc3_ep *dep; 700 + struct scatterlist *sg; 718 701 702 + unsigned num_pending_sgs; 719 703 u8 first_trb_index; 720 704 u8 epnum; 721 705 struct dwc3_trb *trb; ··· 763 743 * @maximum_speed: maximum speed requested (mainly for testing purposes) 764 744 * @revision: revision register contents 765 745 * @dr_mode: requested mode of operation 746 + * @hsphy_mode: UTMI phy mode, one of following: 747 + * - USBPHY_INTERFACE_MODE_UTMI 748 + * - USBPHY_INTERFACE_MODE_UTMIW 766 749 * @usb2_phy: pointer to USB2 PHY 767 750 * @usb3_phy: pointer to USB3 PHY 768 751 * @usb2_generic_phy: pointer to USB2 PHY ··· 822 799 * @dis_u2_susphy_quirk: set if we disable usb2 suspend phy 823 800 * @dis_enblslpm_quirk: set if we clear enblslpm in GUSB2PHYCFG, 824 801 * disabling the suspend signal to the PHY. 802 + * @dis_u2_freeclk_exists_quirk : set if we clear u2_freeclk_exists 803 + * in GUSB2PHYCFG, specify that USB2 PHY doesn't 804 + * provide a free-running PHY clock. 805 + * @dis_del_phy_power_chg_quirk: set if we disable delay phy power 806 + * change quirk. 825 807 * @tx_de_emphasis_quirk: set if we enable Tx de-emphasis quirk 826 808 * @tx_de_emphasis: Tx de-emphasis value 827 809 * 0 - -6dB de-emphasis ··· 873 845 size_t regs_size; 874 846 875 847 enum usb_dr_mode dr_mode; 848 + enum usb_phy_interface hsphy_mode; 876 849 877 850 u32 fladj; 878 851 u32 irq_gadget; ··· 909 880 #define DWC3_REVISION_260A 0x5533260a 910 881 #define DWC3_REVISION_270A 0x5533270a 911 882 #define DWC3_REVISION_280A 0x5533280a 883 + #define DWC3_REVISION_300A 0x5533300a 884 + #define DWC3_REVISION_310A 0x5533310a 912 885 913 886 /* 914 887 * NOTICE: we're using bit 31 as a "is usb 3.1" flag. This is really ··· 973 942 unsigned dis_u2_susphy_quirk:1; 974 943 unsigned dis_enblslpm_quirk:1; 975 944 unsigned dis_rxdet_inp3_quirk:1; 945 + unsigned dis_u2_freeclk_exists_quirk:1; 946 + unsigned dis_del_phy_power_chg_quirk:1; 976 947 977 948 unsigned tx_de_emphasis_quirk:1; 978 949 unsigned tx_de_emphasis:2;
+32 -18
drivers/usb/dwc3/dwc3-of-simple.c
··· 36 36 int num_clocks; 37 37 }; 38 38 39 - static int dwc3_of_simple_probe(struct platform_device *pdev) 39 + static int dwc3_of_simple_clk_init(struct dwc3_of_simple *simple, int count) 40 40 { 41 - struct dwc3_of_simple *simple; 42 - struct device *dev = &pdev->dev; 41 + struct device *dev = simple->dev; 43 42 struct device_node *np = dev->of_node; 44 - 45 - unsigned int count; 46 - int ret; 47 43 int i; 48 44 49 - simple = devm_kzalloc(dev, sizeof(*simple), GFP_KERNEL); 50 - if (!simple) 51 - return -ENOMEM; 52 - 53 - count = of_clk_get_parent_count(np); 54 - if (!count) 55 - return -ENOENT; 56 - 57 45 simple->num_clocks = count; 46 + 47 + if (!count) 48 + return 0; 58 49 59 50 simple->clks = devm_kcalloc(dev, simple->num_clocks, 60 51 sizeof(struct clk *), GFP_KERNEL); 61 52 if (!simple->clks) 62 53 return -ENOMEM; 63 54 64 - platform_set_drvdata(pdev, simple); 65 - simple->dev = dev; 66 - 67 55 for (i = 0; i < simple->num_clocks; i++) { 68 56 struct clk *clk; 57 + int ret; 69 58 70 59 clk = of_clk_get(np, i); 71 60 if (IS_ERR(clk)) { ··· 76 87 77 88 simple->clks[i] = clk; 78 89 } 90 + 91 + return 0; 92 + } 93 + 94 + static int dwc3_of_simple_probe(struct platform_device *pdev) 95 + { 96 + struct dwc3_of_simple *simple; 97 + struct device *dev = &pdev->dev; 98 + struct device_node *np = dev->of_node; 99 + 100 + int ret; 101 + int i; 102 + 103 + simple = devm_kzalloc(dev, sizeof(*simple), GFP_KERNEL); 104 + if (!simple) 105 + return -ENOMEM; 106 + 107 + platform_set_drvdata(pdev, simple); 108 + simple->dev = dev; 109 + 110 + ret = dwc3_of_simple_clk_init(simple, of_clk_get_parent_count(np)); 111 + if (ret) 112 + return ret; 79 113 80 114 ret = of_platform_populate(np, NULL, NULL, dev); 81 115 if (ret) { ··· 124 112 int i; 125 113 126 114 for (i = 0; i < simple->num_clocks; i++) { 127 - clk_unprepare(simple->clks[i]); 115 + clk_disable_unprepare(simple->clks[i]); 128 116 clk_put(simple->clks[i]); 129 117 } 130 118 ··· 174 162 175 163 static const struct of_device_id of_dwc3_simple_match[] = { 176 164 { .compatible = "qcom,dwc3" }, 165 + { .compatible = "rockchip,rk3399-dwc3" }, 177 166 { .compatible = "xlnx,zynqmp-dwc3" }, 167 + { .compatible = "cavium,octeon-7130-usb-uctl" }, 178 168 { /* Sentinel */ } 179 169 }; 180 170 MODULE_DEVICE_TABLE(of, of_dwc3_simple_match);
+101 -175
drivers/usb/dwc3/gadget.c
··· 174 174 int status) 175 175 { 176 176 struct dwc3 *dwc = dep->dwc; 177 - int i; 178 177 179 - if (req->started) { 180 - i = 0; 181 - do { 182 - dwc3_ep_inc_deq(dep); 183 - } while(++i < req->request.num_mapped_sgs); 184 - req->started = false; 185 - } 178 + req->started = false; 186 179 list_del(&req->list); 187 180 req->trb = NULL; 188 181 ··· 341 348 * IN transfers due to a mishandled error condition. Synopsys 342 349 * STAR 9000614252. 343 350 */ 344 - if (dep->direction && (dwc->revision >= DWC3_REVISION_260A)) 351 + if (dep->direction && (dwc->revision >= DWC3_REVISION_260A) && 352 + (dwc->gadget.speed >= USB_SPEED_SUPER)) 345 353 cmd |= DWC3_DEPCMD_CLEARPENDIN; 346 354 347 355 memset(&params, 0, sizeof(params)); ··· 484 490 params.param0 |= DWC3_DEPCFG_ACTION_INIT; 485 491 } 486 492 487 - params.param1 = DWC3_DEPCFG_XFER_COMPLETE_EN; 493 + if (usb_endpoint_xfer_control(desc)) 494 + params.param1 = DWC3_DEPCFG_XFER_COMPLETE_EN; 488 495 489 496 if (dep->number <= 1 || usb_endpoint_xfer_isoc(desc)) 490 497 params.param1 |= DWC3_DEPCFG_XFER_NOT_READY_EN; ··· 759 764 kfree(req); 760 765 } 761 766 767 + static u32 dwc3_calc_trbs_left(struct dwc3_ep *dep); 768 + 762 769 /** 763 770 * dwc3_prepare_one_trb - setup one TRB from one request 764 771 * @dep: endpoint for which this request is prepared ··· 768 771 */ 769 772 static void dwc3_prepare_one_trb(struct dwc3_ep *dep, 770 773 struct dwc3_request *req, dma_addr_t dma, 771 - unsigned length, unsigned last, unsigned chain, unsigned node) 774 + unsigned length, unsigned chain, unsigned node) 772 775 { 773 776 struct dwc3_trb *trb; 774 777 775 - dwc3_trace(trace_dwc3_gadget, "%s: req %p dma %08llx length %d%s%s", 778 + dwc3_trace(trace_dwc3_gadget, "%s: req %p dma %08llx length %d%s", 776 779 dep->name, req, (unsigned long long) dma, 777 - length, last ? " last" : "", 778 - chain ? " chain" : ""); 779 - 780 + length, chain ? " chain" : ""); 780 781 781 782 trb = &dep->trb_pool[dep->trb_enqueue]; 782 783 ··· 821 826 /* always enable Continue on Short Packet */ 822 827 trb->ctrl |= DWC3_TRB_CTRL_CSP; 823 828 824 - if (!req->request.no_interrupt && !chain) 829 + if ((!req->request.no_interrupt && !chain) || 830 + (dwc3_calc_trbs_left(dep) == 0)) 825 831 trb->ctrl |= DWC3_TRB_CTRL_IOC | DWC3_TRB_CTRL_ISP_IMI; 826 - 827 - if (last && !usb_endpoint_xfer_isoc(dep->endpoint.desc)) 828 - trb->ctrl |= DWC3_TRB_CTRL_LST; 829 832 830 833 if (chain) 831 834 trb->ctrl |= DWC3_TRB_CTRL_CHN; ··· 849 856 */ 850 857 static struct dwc3_trb *dwc3_ep_prev_trb(struct dwc3_ep *dep, u8 index) 851 858 { 852 - if (!index) 853 - index = DWC3_TRB_NUM - 2; 854 - else 855 - index = dep->trb_enqueue - 1; 859 + u8 tmp = index; 856 860 857 - return &dep->trb_pool[index]; 861 + if (!tmp) 862 + tmp = DWC3_TRB_NUM - 1; 863 + 864 + return &dep->trb_pool[tmp - 1]; 858 865 } 859 866 860 867 static u32 dwc3_calc_trbs_left(struct dwc3_ep *dep) ··· 887 894 } 888 895 889 896 static void dwc3_prepare_one_trb_sg(struct dwc3_ep *dep, 890 - struct dwc3_request *req, unsigned int trbs_left, 891 - unsigned int more_coming) 897 + struct dwc3_request *req) 892 898 { 893 - struct usb_request *request = &req->request; 894 - struct scatterlist *sg = request->sg; 899 + struct scatterlist *sg = req->sg; 895 900 struct scatterlist *s; 896 - unsigned int last = false; 897 901 unsigned int length; 898 902 dma_addr_t dma; 899 903 int i; 900 904 901 - for_each_sg(sg, s, request->num_mapped_sgs, i) { 905 + for_each_sg(sg, s, req->num_pending_sgs, i) { 902 906 unsigned chain = true; 903 907 904 908 length = sg_dma_len(s); 905 909 dma = sg_dma_address(s); 906 910 907 - if (sg_is_last(s)) { 908 - if (usb_endpoint_xfer_int(dep->endpoint.desc) || 909 - !more_coming) 910 - last = true; 911 - 912 - chain = false; 913 - } 914 - 915 - if (!trbs_left--) 916 - last = true; 917 - 918 - if (last) 911 + if (sg_is_last(s)) 919 912 chain = false; 920 913 921 914 dwc3_prepare_one_trb(dep, req, dma, length, 922 - last, chain, i); 915 + chain, i); 923 916 924 - if (last) 917 + if (!dwc3_calc_trbs_left(dep)) 925 918 break; 926 919 } 927 920 } 928 921 929 922 static void dwc3_prepare_one_trb_linear(struct dwc3_ep *dep, 930 - struct dwc3_request *req, unsigned int trbs_left, 931 - unsigned int more_coming) 923 + struct dwc3_request *req) 932 924 { 933 - unsigned int last = false; 934 925 unsigned int length; 935 926 dma_addr_t dma; 936 927 937 928 dma = req->request.dma; 938 929 length = req->request.length; 939 930 940 - if (!trbs_left) 941 - last = true; 942 - 943 - /* Is this the last request? */ 944 - if (usb_endpoint_xfer_int(dep->endpoint.desc) || !more_coming) 945 - last = true; 946 - 947 931 dwc3_prepare_one_trb(dep, req, dma, length, 948 - last, false, 0); 932 + false, 0); 949 933 } 950 934 951 935 /* ··· 936 966 static void dwc3_prepare_trbs(struct dwc3_ep *dep) 937 967 { 938 968 struct dwc3_request *req, *n; 939 - unsigned int more_coming; 940 - u32 trbs_left; 941 969 942 970 BUILD_BUG_ON_NOT_POWER_OF_2(DWC3_TRB_NUM); 943 971 944 - trbs_left = dwc3_calc_trbs_left(dep); 945 - if (!trbs_left) 972 + if (!dwc3_calc_trbs_left(dep)) 946 973 return; 947 974 948 - more_coming = dep->allocated_requests - dep->queued_requests; 949 - 950 975 list_for_each_entry_safe(req, n, &dep->pending_list, list) { 951 - if (req->request.num_mapped_sgs > 0) 952 - dwc3_prepare_one_trb_sg(dep, req, trbs_left--, 953 - more_coming); 976 + if (req->num_pending_sgs > 0) 977 + dwc3_prepare_one_trb_sg(dep, req); 954 978 else 955 - dwc3_prepare_one_trb_linear(dep, req, trbs_left--, 956 - more_coming); 979 + dwc3_prepare_one_trb_linear(dep, req); 957 980 958 - if (!trbs_left) 981 + if (!dwc3_calc_trbs_left(dep)) 959 982 return; 960 983 } 961 984 } ··· 1064 1101 1065 1102 trace_dwc3_ep_queue(req); 1066 1103 1067 - /* 1068 - * We only add to our list of requests now and 1069 - * start consuming the list once we get XferNotReady 1070 - * IRQ. 1071 - * 1072 - * That way, we avoid doing anything that we don't need 1073 - * to do now and defer it until the point we receive a 1074 - * particular token from the Host side. 1075 - * 1076 - * This will also avoid Host cancelling URBs due to too 1077 - * many NAKs. 1078 - */ 1079 1104 ret = usb_gadget_map_request(&dwc->gadget, &req->request, 1080 1105 dep->direction); 1081 1106 if (ret) 1082 1107 return ret; 1083 1108 1109 + req->sg = req->request.sg; 1110 + req->num_pending_sgs = req->request.num_mapped_sgs; 1111 + 1084 1112 list_add_tail(&req->list, &dep->pending_list); 1085 1113 1086 - /* 1087 - * If there are no pending requests and the endpoint isn't already 1088 - * busy, we will just start the request straight away. 1089 - * 1090 - * This will save one IRQ (XFER_NOT_READY) and possibly make it a 1091 - * little bit faster. 1092 - */ 1093 - if (!usb_endpoint_xfer_isoc(dep->endpoint.desc) && 1094 - !usb_endpoint_xfer_int(dep->endpoint.desc)) { 1095 - ret = __dwc3_gadget_kick_transfer(dep, 0); 1096 - goto out; 1097 - } 1098 - 1099 - /* 1100 - * There are a few special cases: 1101 - * 1102 - * 1. XferNotReady with empty list of requests. We need to kick the 1103 - * transfer here in that situation, otherwise we will be NAKing 1104 - * forever. If we get XferNotReady before gadget driver has a 1105 - * chance to queue a request, we will ACK the IRQ but won't be 1106 - * able to receive the data until the next request is queued. 1107 - * The following code is handling exactly that. 1108 - * 1109 - */ 1110 - if (dep->flags & DWC3_EP_PENDING_REQUEST) { 1111 - /* 1112 - * If xfernotready is already elapsed and it is a case 1113 - * of isoc transfer, then issue END TRANSFER, so that 1114 - * you can receive xfernotready again and can have 1115 - * notion of current microframe. 1116 - */ 1117 - if (usb_endpoint_xfer_isoc(dep->endpoint.desc)) { 1118 - if (list_empty(&dep->started_list)) { 1119 - dwc3_stop_active_transfer(dwc, dep->number, true); 1120 - dep->flags = DWC3_EP_ENABLED; 1121 - } 1122 - return 0; 1123 - } 1124 - 1125 - ret = __dwc3_gadget_kick_transfer(dep, 0); 1126 - if (!ret) 1127 - dep->flags &= ~DWC3_EP_PENDING_REQUEST; 1128 - 1129 - goto out; 1130 - } 1131 - 1132 - /* 1133 - * 2. XferInProgress on Isoc EP with an active transfer. We need to 1134 - * kick the transfer here after queuing a request, otherwise the 1135 - * core may not see the modified TRB(s). 1136 - */ 1137 1114 if (usb_endpoint_xfer_isoc(dep->endpoint.desc) && 1138 - (dep->flags & DWC3_EP_BUSY) && 1139 - !(dep->flags & DWC3_EP_MISSED_ISOC)) { 1140 - WARN_ON_ONCE(!dep->resource_index); 1141 - ret = __dwc3_gadget_kick_transfer(dep, dep->resource_index); 1142 - goto out; 1115 + dep->flags & DWC3_EP_PENDING_REQUEST) { 1116 + if (list_empty(&dep->started_list)) { 1117 + dwc3_stop_active_transfer(dwc, dep->number, true); 1118 + dep->flags = DWC3_EP_ENABLED; 1119 + } 1120 + return 0; 1143 1121 } 1144 1122 1145 - /* 1146 - * 4. Stream Capable Bulk Endpoints. We need to start the transfer 1147 - * right away, otherwise host will not know we have streams to be 1148 - * handled. 1149 - */ 1150 - if (dep->stream_capable) 1151 - ret = __dwc3_gadget_kick_transfer(dep, 0); 1123 + if (!dwc3_calc_trbs_left(dep)) 1124 + return 0; 1152 1125 1153 - out: 1126 + ret = __dwc3_gadget_kick_transfer(dep, 0); 1154 1127 if (ret && ret != -EBUSY) 1155 1128 dwc3_trace(trace_dwc3_gadget, 1156 1129 "%s: failed to kick transfers", ··· 1862 1963 unsigned int trb_status; 1863 1964 1864 1965 dep->queued_requests--; 1966 + dwc3_ep_inc_deq(dep); 1865 1967 trace_dwc3_complete_trb(dep, trb); 1866 1968 1867 1969 /* ··· 1882 1982 return 1; 1883 1983 1884 1984 count = trb->size & DWC3_TRB_SIZE_MASK; 1985 + req->request.actual += count; 1885 1986 1886 1987 if (dep->direction) { 1887 1988 if (count) { ··· 1922 2021 1923 2022 if (s_pkt && !chain) 1924 2023 return 1; 1925 - if ((event->status & DEPEVT_STATUS_LST) && 1926 - (trb->ctrl & (DWC3_TRB_CTRL_LST | 1927 - DWC3_TRB_CTRL_HWO))) 1928 - return 1; 2024 + 1929 2025 if ((event->status & DEPEVT_STATUS_IOC) && 1930 2026 (trb->ctrl & DWC3_TRB_CTRL_IOC)) 1931 2027 return 1; 2028 + 1932 2029 return 0; 1933 2030 } 1934 2031 1935 2032 static int dwc3_cleanup_done_reqs(struct dwc3 *dwc, struct dwc3_ep *dep, 1936 2033 const struct dwc3_event_depevt *event, int status) 1937 2034 { 1938 - struct dwc3_request *req; 2035 + struct dwc3_request *req, *n; 1939 2036 struct dwc3_trb *trb; 1940 - unsigned int slot; 1941 - unsigned int i; 1942 - int count = 0; 2037 + bool ioc = false; 1943 2038 int ret; 1944 2039 1945 - do { 2040 + list_for_each_entry_safe(req, n, &dep->started_list, list) { 2041 + unsigned length; 2042 + unsigned actual; 1946 2043 int chain; 1947 2044 1948 - req = next_request(&dep->started_list); 1949 - if (WARN_ON_ONCE(!req)) 1950 - return 1; 2045 + length = req->request.length; 2046 + chain = req->num_pending_sgs > 0; 2047 + if (chain) { 2048 + struct scatterlist *sg = req->sg; 2049 + struct scatterlist *s; 2050 + unsigned int pending = req->num_pending_sgs; 2051 + unsigned int i; 1951 2052 1952 - chain = req->request.num_mapped_sgs > 0; 1953 - i = 0; 1954 - do { 1955 - slot = req->first_trb_index + i; 1956 - if (slot == DWC3_TRB_NUM - 1) 1957 - slot++; 1958 - slot %= DWC3_TRB_NUM; 1959 - trb = &dep->trb_pool[slot]; 1960 - count += trb->size & DWC3_TRB_SIZE_MASK; 2053 + for_each_sg(sg, s, pending, i) { 2054 + trb = &dep->trb_pool[dep->trb_dequeue]; 1961 2055 2056 + req->sg = sg_next(s); 2057 + req->num_pending_sgs--; 2058 + 2059 + ret = __dwc3_cleanup_done_trbs(dwc, dep, req, trb, 2060 + event, status, chain); 2061 + if (ret) 2062 + break; 2063 + } 2064 + } else { 2065 + trb = &dep->trb_pool[dep->trb_dequeue]; 1962 2066 ret = __dwc3_cleanup_done_trbs(dwc, dep, req, trb, 1963 2067 event, status, chain); 1964 - if (ret) 1965 - break; 1966 - } while (++i < req->request.num_mapped_sgs); 2068 + } 1967 2069 1968 2070 /* 1969 2071 * We assume here we will always receive the entire data block ··· 1975 2071 * should receive and we simply bounce the request back to the 1976 2072 * gadget driver for further processing. 1977 2073 */ 1978 - req->request.actual += req->request.length - count; 2074 + actual = length - req->request.actual; 2075 + req->request.actual = actual; 2076 + 2077 + if (ret && chain && (actual < length) && req->num_pending_sgs) 2078 + return __dwc3_gadget_kick_transfer(dep, 0); 2079 + 1979 2080 dwc3_gadget_giveback(dep, req, status); 1980 2081 1981 - if (ret) 2082 + if (ret) { 2083 + if ((event->status & DEPEVT_STATUS_IOC) && 2084 + (trb->ctrl & DWC3_TRB_CTRL_IOC)) 2085 + ioc = true; 1982 2086 break; 1983 - } while (1); 2087 + } 2088 + } 1984 2089 1985 2090 /* 1986 2091 * Our endpoint might get disabled by another thread during ··· 2016 2103 return 1; 2017 2104 } 2018 2105 2019 - if (usb_endpoint_xfer_isoc(dep->endpoint.desc)) 2020 - if ((event->status & DEPEVT_STATUS_IOC) && 2021 - (trb->ctrl & DWC3_TRB_CTRL_IOC)) 2022 - return 0; 2106 + if (usb_endpoint_xfer_isoc(dep->endpoint.desc) && ioc) 2107 + return 0; 2108 + 2023 2109 return 1; 2024 2110 } 2025 2111 ··· 2234 2322 * 2235 2323 * - Issue EndTransfer WITH CMDIOC bit set 2236 2324 * - Wait 100us 2325 + * 2326 + * As of IP version 3.10a of the DWC_usb3 IP, the controller 2327 + * supports a mode to work around the above limitation. The 2328 + * software can poll the CMDACT bit in the DEPCMD register 2329 + * after issuing a EndTransfer command. This mode is enabled 2330 + * by writing GUCTL2[14]. This polling is already done in the 2331 + * dwc3_send_gadget_ep_cmd() function so if the mode is 2332 + * enabled, the EndTransfer command will have completed upon 2333 + * returning from this function and we don't need to delay for 2334 + * 100us. 2335 + * 2336 + * This mode is NOT available on the DWC_usb31 IP. 2237 2337 */ 2238 2338 2239 2339 cmd = DWC3_DEPCMD_ENDTRANSFER; ··· 2257 2333 WARN_ON_ONCE(ret); 2258 2334 dep->resource_index = 0; 2259 2335 dep->flags &= ~DWC3_EP_BUSY; 2260 - udelay(100); 2336 + 2337 + if (dwc3_is_usb31(dwc) || dwc->revision < DWC3_REVISION_310A) 2338 + udelay(100); 2261 2339 } 2262 2340 2263 2341 static void dwc3_stop_active_transfers(struct dwc3 *dwc)
+5 -5
drivers/usb/dwc3/ulpi.c
··· 35 35 return -ETIMEDOUT; 36 36 } 37 37 38 - static int dwc3_ulpi_read(struct ulpi_ops *ops, u8 addr) 38 + static int dwc3_ulpi_read(struct device *dev, u8 addr) 39 39 { 40 - struct dwc3 *dwc = dev_get_drvdata(ops->dev); 40 + struct dwc3 *dwc = dev_get_drvdata(dev); 41 41 u32 reg; 42 42 int ret; 43 43 ··· 53 53 return DWC3_GUSB2PHYACC_DATA(reg); 54 54 } 55 55 56 - static int dwc3_ulpi_write(struct ulpi_ops *ops, u8 addr, u8 val) 56 + static int dwc3_ulpi_write(struct device *dev, u8 addr, u8 val) 57 57 { 58 - struct dwc3 *dwc = dev_get_drvdata(ops->dev); 58 + struct dwc3 *dwc = dev_get_drvdata(dev); 59 59 u32 reg; 60 60 61 61 reg = DWC3_GUSB2PHYACC_NEWREGREQ | DWC3_ULPI_ADDR(addr); ··· 65 65 return dwc3_ulpi_busyloop(dwc); 66 66 } 67 67 68 - static struct ulpi_ops dwc3_ulpi_ops = { 68 + static const struct ulpi_ops dwc3_ulpi_ops = { 69 69 .read = dwc3_ulpi_read, 70 70 .write = dwc3_ulpi_write, 71 71 };
+20 -19
drivers/usb/gadget/Kconfig
··· 209 209 config USB_F_TCM 210 210 tristate 211 211 212 - choice 213 - tristate "USB Gadget Drivers" 214 - default USB_ETH 215 - help 216 - A Linux "Gadget Driver" talks to the USB Peripheral Controller 217 - driver through the abstract "gadget" API. Some other operating 218 - systems call these "client" drivers, of which "class drivers" 219 - are a subset (implementing a USB device class specification). 220 - A gadget driver implements one or more USB functions using 221 - the peripheral hardware. 222 - 223 - Gadget drivers are hardware-neutral, or "platform independent", 224 - except that they sometimes must understand quirks or limitations 225 - of the particular controllers they work with. For example, when 226 - a controller doesn't support alternate configurations or provide 227 - enough of the right types of endpoints, the gadget driver might 228 - not be able work with that controller, or might need to implement 229 - a less common variant of a device class protocol. 230 - 231 212 # this first set of drivers all depend on bulk-capable hardware. 232 213 233 214 config USB_CONFIGFS ··· 420 439 config USB_CONFIGFS_F_UVC 421 440 bool "USB Webcam function" 422 441 depends on USB_CONFIGFS 442 + depends on VIDEO_V4L2 423 443 depends on VIDEO_DEV 424 444 select VIDEOBUF2_VMALLOC 425 445 select USB_F_UVC ··· 456 474 interface 0 (primary) and UAS is on alternative interface 1. 457 475 Both protocols can work on USB2.0 and USB3.0. 458 476 UAS utilizes the USB 3.0 feature called streams support. 477 + 478 + choice 479 + tristate "USB Gadget Drivers" 480 + default USB_ETH 481 + help 482 + A Linux "Gadget Driver" talks to the USB Peripheral Controller 483 + driver through the abstract "gadget" API. Some other operating 484 + systems call these "client" drivers, of which "class drivers" 485 + are a subset (implementing a USB device class specification). 486 + A gadget driver implements one or more USB functions using 487 + the peripheral hardware. 488 + 489 + Gadget drivers are hardware-neutral, or "platform independent", 490 + except that they sometimes must understand quirks or limitations 491 + of the particular controllers they work with. For example, when 492 + a controller doesn't support alternate configurations or provide 493 + enough of the right types of endpoints, the gadget driver might 494 + not be able work with that controller, or might need to implement 495 + a less common variant of a device class protocol. 459 496 460 497 source "drivers/usb/gadget/legacy/Kconfig" 461 498
+10 -6
drivers/usb/gadget/composite.c
··· 1893 1893 /* functions always handle their interfaces and endpoints... 1894 1894 * punt other recipients (other, WUSB, ...) to the current 1895 1895 * configuration code. 1896 - * 1897 - * REVISIT it could make sense to let the composite device 1898 - * take such requests too, if that's ever needed: to work 1899 - * in config 0, etc. 1900 1896 */ 1901 1897 if (cdev->config) { 1902 1898 list_for_each_entry(f, &cdev->config->functions, list) 1903 - if (f->req_match && f->req_match(f, ctrl)) 1899 + if (f->req_match && 1900 + f->req_match(f, ctrl, false)) 1904 1901 goto try_fun_setup; 1905 - f = NULL; 1902 + } else { 1903 + struct usb_configuration *c; 1904 + list_for_each_entry(c, &cdev->configs, list) 1905 + list_for_each_entry(f, &c->functions, list) 1906 + if (f->req_match && 1907 + f->req_match(f, ctrl, true)) 1908 + goto try_fun_setup; 1906 1909 } 1910 + f = NULL; 1907 1911 1908 1912 switch (ctrl->bRequestType & USB_RECIP_MASK) { 1909 1913 case USB_RECIP_INTERFACE:
+3 -2
drivers/usb/gadget/configfs.c
··· 1211 1211 1212 1212 list_move_tail(&f->list, &cfg->func_list); 1213 1213 if (f->unbind) { 1214 - dev_err(&gi->cdev.gadget->dev, "unbind function" 1215 - " '%s'/%p\n", f->name, f); 1214 + dev_dbg(&gi->cdev.gadget->dev, 1215 + "unbind function '%s'/%p\n", 1216 + f->name, f); 1216 1217 f->unbind(c, f); 1217 1218 } 1218 1219 }
+41 -4
drivers/usb/gadget/function/f_fs.c
··· 98 98 static void ffs_func_disable(struct usb_function *); 99 99 static int ffs_func_setup(struct usb_function *, 100 100 const struct usb_ctrlrequest *); 101 + static bool ffs_func_req_match(struct usb_function *, 102 + const struct usb_ctrlrequest *, 103 + bool config0); 101 104 static void ffs_func_suspend(struct usb_function *); 102 105 static void ffs_func_resume(struct usb_function *); 103 106 ··· 2246 2243 FUNCTIONFS_HAS_SS_DESC | 2247 2244 FUNCTIONFS_HAS_MS_OS_DESC | 2248 2245 FUNCTIONFS_VIRTUAL_ADDR | 2249 - FUNCTIONFS_EVENTFD)) { 2246 + FUNCTIONFS_EVENTFD | 2247 + FUNCTIONFS_ALL_CTRL_RECIP | 2248 + FUNCTIONFS_CONFIG0_SETUP)) { 2250 2249 ret = -ENOSYS; 2251 2250 goto error; 2252 2251 } ··· 3099 3094 * handle them. All other either handled by composite or 3100 3095 * passed to usb_configuration->setup() (if one is set). No 3101 3096 * matter, we will handle requests directed to endpoint here 3102 - * as well (as it's straightforward) but what to do with any 3103 - * other request? 3097 + * as well (as it's straightforward). Other request recipient 3098 + * types are only handled when the user flag FUNCTIONFS_ALL_CTRL_RECIP 3099 + * is being used. 3104 3100 */ 3105 3101 if (ffs->state != FFS_ACTIVE) 3106 3102 return -ENODEV; ··· 3122 3116 break; 3123 3117 3124 3118 default: 3125 - return -EOPNOTSUPP; 3119 + if (func->ffs->user_flags & FUNCTIONFS_ALL_CTRL_RECIP) 3120 + ret = le16_to_cpu(creq->wIndex); 3121 + else 3122 + return -EOPNOTSUPP; 3126 3123 } 3127 3124 3128 3125 spin_lock_irqsave(&ffs->ev.waitq.lock, flags); ··· 3135 3126 spin_unlock_irqrestore(&ffs->ev.waitq.lock, flags); 3136 3127 3137 3128 return 0; 3129 + } 3130 + 3131 + static bool ffs_func_req_match(struct usb_function *f, 3132 + const struct usb_ctrlrequest *creq, 3133 + bool config0) 3134 + { 3135 + struct ffs_function *func = ffs_func_from_usb(f); 3136 + 3137 + if (config0 && !(func->ffs->user_flags & FUNCTIONFS_CONFIG0_SETUP)) 3138 + return false; 3139 + 3140 + switch (creq->bRequestType & USB_RECIP_MASK) { 3141 + case USB_RECIP_INTERFACE: 3142 + return ffs_func_revmap_intf(func, 3143 + le16_to_cpu(creq->wIndex) >= 0); 3144 + case USB_RECIP_ENDPOINT: 3145 + return ffs_func_revmap_ep(func, 3146 + le16_to_cpu(creq->wIndex) >= 0); 3147 + default: 3148 + return (bool) (func->ffs->user_flags & 3149 + FUNCTIONFS_ALL_CTRL_RECIP); 3150 + } 3138 3151 } 3139 3152 3140 3153 static void ffs_func_suspend(struct usb_function *f) ··· 3409 3378 func->function.set_alt = ffs_func_set_alt; 3410 3379 func->function.disable = ffs_func_disable; 3411 3380 func->function.setup = ffs_func_setup; 3381 + func->function.req_match = ffs_func_req_match; 3412 3382 func->function.suspend = ffs_func_suspend; 3413 3383 func->function.resume = ffs_func_resume; 3414 3384 func->function.free_func = ffs_free; ··· 3502 3470 list_del(&dev->entry); 3503 3471 if (dev->name_allocated) 3504 3472 kfree(dev->name); 3473 + 3474 + /* Clear the private_data pointer to stop incorrect dev access */ 3475 + if (dev->ffs_data) 3476 + dev->ffs_data->private_data = NULL; 3477 + 3505 3478 kfree(dev); 3506 3479 if (list_empty(&ffs_devices)) 3507 3480 functionfs_cleanup();
+15 -13
drivers/usb/gadget/function/f_hid.c
··· 365 365 static inline struct usb_request *hidg_alloc_ep_req(struct usb_ep *ep, 366 366 unsigned length) 367 367 { 368 - return alloc_ep_req(ep, length, length); 368 + return alloc_ep_req(ep, length); 369 369 } 370 370 371 371 static void hidg_set_report_complete(struct usb_ep *ep, struct usb_request *req) ··· 617 617 618 618 /* preallocate request and buffer */ 619 619 status = -ENOMEM; 620 - hidg->req = usb_ep_alloc_request(hidg->in_ep, GFP_KERNEL); 620 + hidg->req = alloc_ep_req(hidg->in_ep, hidg->report_length); 621 621 if (!hidg->req) 622 - goto fail; 623 - 624 - hidg->req->buf = kmalloc(hidg->report_length, GFP_KERNEL); 625 - if (!hidg->req->buf) 626 622 goto fail; 627 623 628 624 /* set descriptor dynamic values */ ··· 673 677 usb_free_all_descriptors(f); 674 678 fail: 675 679 ERROR(f->config->cdev, "hidg_bind FAILED\n"); 676 - if (hidg->req != NULL) { 677 - kfree(hidg->req->buf); 678 - if (hidg->in_ep != NULL) 679 - usb_ep_free_request(hidg->in_ep, hidg->req); 680 - } 680 + if (hidg->req != NULL) 681 + free_ep_req(hidg->in_ep, hidg->req); 681 682 682 683 return status; 683 684 } ··· 802 809 803 810 CONFIGFS_ATTR(f_hid_opts_, report_desc); 804 811 812 + static ssize_t f_hid_opts_dev_show(struct config_item *item, char *page) 813 + { 814 + struct f_hid_opts *opts = to_f_hid_opts(item); 815 + 816 + return sprintf(page, "%d:%d\n", major, opts->minor); 817 + } 818 + 819 + CONFIGFS_ATTR_RO(f_hid_opts_, dev); 820 + 805 821 static struct configfs_attribute *hid_attrs[] = { 806 822 &f_hid_opts_attr_subclass, 807 823 &f_hid_opts_attr_protocol, 808 824 &f_hid_opts_attr_report_length, 809 825 &f_hid_opts_attr_report_desc, 826 + &f_hid_opts_attr_dev, 810 827 NULL, 811 828 }; 812 829 ··· 913 910 914 911 /* disable/free request and end point */ 915 912 usb_ep_disable(hidg->in_ep); 916 - kfree(hidg->req->buf); 917 - usb_ep_free_request(hidg->in_ep, hidg->req); 913 + free_ep_req(hidg->in_ep, hidg->req); 918 914 919 915 usb_free_all_descriptors(f); 920 916 }
+4 -10
drivers/usb/gadget/function/f_loopback.c
··· 308 308 309 309 static inline struct usb_request *lb_alloc_ep_req(struct usb_ep *ep, int len) 310 310 { 311 - struct f_loopback *loop = ep->driver_data; 312 - 313 - return alloc_ep_req(ep, len, loop->buflen); 311 + return alloc_ep_req(ep, len); 314 312 } 315 313 316 314 static int alloc_requests(struct usb_composite_dev *cdev, ··· 331 333 if (!in_req) 332 334 goto fail; 333 335 334 - out_req = lb_alloc_ep_req(loop->out_ep, 0); 336 + out_req = lb_alloc_ep_req(loop->out_ep, loop->buflen); 335 337 if (!out_req) 336 338 goto fail_in; 337 339 ··· 591 593 592 594 int __init lb_modinit(void) 593 595 { 594 - int ret; 595 - 596 - ret = usb_function_register(&Loopbackusb_func); 597 - if (ret) 598 - return ret; 599 - return ret; 596 + return usb_function_register(&Loopbackusb_func); 600 597 } 598 + 601 599 void __exit lb_modexit(void) 602 600 { 603 601 usb_function_unregister(&Loopbackusb_func);
+22 -6
drivers/usb/gadget/function/f_mass_storage.c
··· 311 311 /* Gadget's private data. */ 312 312 void *private_data; 313 313 314 - /* 315 - * Vendor (8 chars), product (16 chars), release (4 316 - * hexadecimal digits) and NUL byte 317 - */ 318 - char inquiry_string[8 + 16 + 4 + 1]; 314 + char inquiry_string[INQUIRY_STRING_LEN]; 319 315 320 316 struct kref ref; 321 317 }; ··· 1103 1107 buf[5] = 0; /* No special options */ 1104 1108 buf[6] = 0; 1105 1109 buf[7] = 0; 1106 - memcpy(buf + 8, common->inquiry_string, sizeof common->inquiry_string); 1110 + if (curlun->inquiry_string[0]) 1111 + memcpy(buf + 8, curlun->inquiry_string, 1112 + sizeof(curlun->inquiry_string)); 1113 + else 1114 + memcpy(buf + 8, common->inquiry_string, 1115 + sizeof(common->inquiry_string)); 1107 1116 return 36; 1108 1117 } 1109 1118 ··· 3210 3209 3211 3210 CONFIGFS_ATTR(fsg_lun_opts_, nofua); 3212 3211 3212 + static ssize_t fsg_lun_opts_inquiry_string_show(struct config_item *item, 3213 + char *page) 3214 + { 3215 + return fsg_show_inquiry_string(to_fsg_lun_opts(item)->lun, page); 3216 + } 3217 + 3218 + static ssize_t fsg_lun_opts_inquiry_string_store(struct config_item *item, 3219 + const char *page, size_t len) 3220 + { 3221 + return fsg_store_inquiry_string(to_fsg_lun_opts(item)->lun, page, len); 3222 + } 3223 + 3224 + CONFIGFS_ATTR(fsg_lun_opts_, inquiry_string); 3225 + 3213 3226 static struct configfs_attribute *fsg_lun_attrs[] = { 3214 3227 &fsg_lun_opts_attr_file, 3215 3228 &fsg_lun_opts_attr_ro, 3216 3229 &fsg_lun_opts_attr_removable, 3217 3230 &fsg_lun_opts_attr_cdrom, 3218 3231 &fsg_lun_opts_attr_nofua, 3232 + &fsg_lun_opts_attr_inquiry_string, 3219 3233 NULL, 3220 3234 }; 3221 3235
+1
drivers/usb/gadget/function/f_mass_storage.h
··· 100 100 char removable; 101 101 char cdrom; 102 102 char nofua; 103 + char inquiry_string[INQUIRY_STRING_LEN]; 103 104 }; 104 105 105 106 struct fsg_config {
+145 -89
drivers/usb/gadget/function/f_midi.c
··· 51 51 */ 52 52 #define MAX_PORTS 16 53 53 54 + /* MIDI message states */ 55 + enum { 56 + STATE_INITIAL = 0, /* pseudo state */ 57 + STATE_1PARAM, 58 + STATE_2PARAM_1, 59 + STATE_2PARAM_2, 60 + STATE_SYSEX_0, 61 + STATE_SYSEX_1, 62 + STATE_SYSEX_2, 63 + STATE_REAL_TIME, 64 + STATE_FINISHED, /* pseudo state */ 65 + }; 66 + 54 67 /* 55 68 * This is a gadget, and the IN/OUT naming is from the host's perspective. 56 69 * USB -> OUT endpoint -> rawmidi ··· 74 61 int active; 75 62 uint8_t cable; 76 63 uint8_t state; 77 - #define STATE_UNKNOWN 0 78 - #define STATE_1PARAM 1 79 - #define STATE_2PARAM_1 2 80 - #define STATE_2PARAM_2 3 81 - #define STATE_SYSEX_0 4 82 - #define STATE_SYSEX_1 5 83 - #define STATE_SYSEX_2 6 84 64 uint8_t data[2]; 85 65 }; 86 66 ··· 211 205 static inline struct usb_request *midi_alloc_ep_req(struct usb_ep *ep, 212 206 unsigned length) 213 207 { 214 - return alloc_ep_req(ep, length, length); 208 + return alloc_ep_req(ep, length); 215 209 } 216 210 217 211 static const uint8_t f_midi_cin_length[] = { ··· 305 299 } 306 300 } 307 301 302 + static void f_midi_drop_out_substreams(struct f_midi *midi) 303 + { 304 + unsigned int i; 305 + 306 + for (i = 0; i < midi->in_ports; i++) { 307 + struct gmidi_in_port *port = midi->in_ports_array + i; 308 + struct snd_rawmidi_substream *substream = port->substream; 309 + 310 + if (port->active && substream) 311 + snd_rawmidi_drop_output(substream); 312 + } 313 + } 314 + 308 315 static int f_midi_start_ep(struct f_midi *midi, 309 316 struct usb_function *f, 310 317 struct usb_ep *ep) ··· 379 360 /* allocate a bunch of read buffers and queue them all at once. */ 380 361 for (i = 0; i < midi->qlen && err == 0; i++) { 381 362 struct usb_request *req = 382 - midi_alloc_ep_req(midi->out_ep, 383 - max_t(unsigned, midi->buflen, 384 - bulk_out_desc.wMaxPacketSize)); 363 + midi_alloc_ep_req(midi->out_ep, midi->buflen); 364 + 385 365 if (req == NULL) 386 366 return -ENOMEM; 387 367 ··· 415 397 /* release IN requests */ 416 398 while (kfifo_get(&midi->in_req_fifo, &req)) 417 399 free_ep_req(midi->in_ep, req); 400 + 401 + f_midi_drop_out_substreams(midi); 418 402 } 419 403 420 404 static int f_midi_snd_free(struct snd_device *device) 421 405 { 422 406 return 0; 423 - } 424 - 425 - static void f_midi_transmit_packet(struct usb_request *req, uint8_t p0, 426 - uint8_t p1, uint8_t p2, uint8_t p3) 427 - { 428 - unsigned length = req->length; 429 - u8 *buf = (u8 *)req->buf + length; 430 - 431 - buf[0] = p0; 432 - buf[1] = p1; 433 - buf[2] = p2; 434 - buf[3] = p3; 435 - req->length = length + 4; 436 407 } 437 408 438 409 /* ··· 430 423 static void f_midi_transmit_byte(struct usb_request *req, 431 424 struct gmidi_in_port *port, uint8_t b) 432 425 { 433 - uint8_t p0 = port->cable << 4; 426 + uint8_t p[4] = { port->cable << 4, 0, 0, 0 }; 427 + uint8_t next_state = STATE_INITIAL; 434 428 435 - if (b >= 0xf8) { 436 - f_midi_transmit_packet(req, p0 | 0x0f, b, 0, 0); 437 - } else if (b >= 0xf0) { 429 + switch (b) { 430 + case 0xf8 ... 0xff: 431 + /* System Real-Time Messages */ 432 + p[0] |= 0x0f; 433 + p[1] = b; 434 + next_state = port->state; 435 + port->state = STATE_REAL_TIME; 436 + break; 437 + 438 + case 0xf7: 439 + /* End of SysEx */ 440 + switch (port->state) { 441 + case STATE_SYSEX_0: 442 + p[0] |= 0x05; 443 + p[1] = 0xf7; 444 + next_state = STATE_FINISHED; 445 + break; 446 + case STATE_SYSEX_1: 447 + p[0] |= 0x06; 448 + p[1] = port->data[0]; 449 + p[2] = 0xf7; 450 + next_state = STATE_FINISHED; 451 + break; 452 + case STATE_SYSEX_2: 453 + p[0] |= 0x07; 454 + p[1] = port->data[0]; 455 + p[2] = port->data[1]; 456 + p[3] = 0xf7; 457 + next_state = STATE_FINISHED; 458 + break; 459 + default: 460 + /* Ignore byte */ 461 + next_state = port->state; 462 + port->state = STATE_INITIAL; 463 + } 464 + break; 465 + 466 + case 0xf0 ... 0xf6: 467 + /* System Common Messages */ 468 + port->data[0] = port->data[1] = 0; 469 + port->state = STATE_INITIAL; 438 470 switch (b) { 439 471 case 0xf0: 440 472 port->data[0] = b; 441 - port->state = STATE_SYSEX_1; 473 + port->data[1] = 0; 474 + next_state = STATE_SYSEX_1; 442 475 break; 443 476 case 0xf1: 444 477 case 0xf3: 445 478 port->data[0] = b; 446 - port->state = STATE_1PARAM; 479 + next_state = STATE_1PARAM; 447 480 break; 448 481 case 0xf2: 449 482 port->data[0] = b; 450 - port->state = STATE_2PARAM_1; 483 + next_state = STATE_2PARAM_1; 451 484 break; 452 485 case 0xf4: 453 486 case 0xf5: 454 - port->state = STATE_UNKNOWN; 487 + next_state = STATE_INITIAL; 455 488 break; 456 489 case 0xf6: 457 - f_midi_transmit_packet(req, p0 | 0x05, 0xf6, 0, 0); 458 - port->state = STATE_UNKNOWN; 459 - break; 460 - case 0xf7: 461 - switch (port->state) { 462 - case STATE_SYSEX_0: 463 - f_midi_transmit_packet(req, 464 - p0 | 0x05, 0xf7, 0, 0); 465 - break; 466 - case STATE_SYSEX_1: 467 - f_midi_transmit_packet(req, 468 - p0 | 0x06, port->data[0], 0xf7, 0); 469 - break; 470 - case STATE_SYSEX_2: 471 - f_midi_transmit_packet(req, 472 - p0 | 0x07, port->data[0], 473 - port->data[1], 0xf7); 474 - break; 475 - } 476 - port->state = STATE_UNKNOWN; 490 + p[0] |= 0x05; 491 + p[1] = 0xf6; 492 + next_state = STATE_FINISHED; 477 493 break; 478 494 } 479 - } else if (b >= 0x80) { 495 + break; 496 + 497 + case 0x80 ... 0xef: 498 + /* 499 + * Channel Voice Messages, Channel Mode Messages 500 + * and Control Change Messages. 501 + */ 480 502 port->data[0] = b; 503 + port->data[1] = 0; 504 + port->state = STATE_INITIAL; 481 505 if (b >= 0xc0 && b <= 0xdf) 482 - port->state = STATE_1PARAM; 506 + next_state = STATE_1PARAM; 483 507 else 484 - port->state = STATE_2PARAM_1; 485 - } else { /* b < 0x80 */ 508 + next_state = STATE_2PARAM_1; 509 + break; 510 + 511 + case 0x00 ... 0x7f: 512 + /* Message parameters */ 486 513 switch (port->state) { 487 514 case STATE_1PARAM: 488 - if (port->data[0] < 0xf0) { 489 - p0 |= port->data[0] >> 4; 490 - } else { 491 - p0 |= 0x02; 492 - port->state = STATE_UNKNOWN; 493 - } 494 - f_midi_transmit_packet(req, p0, port->data[0], b, 0); 515 + if (port->data[0] < 0xf0) 516 + p[0] |= port->data[0] >> 4; 517 + else 518 + p[0] |= 0x02; 519 + 520 + p[1] = port->data[0]; 521 + p[2] = b; 522 + /* This is to allow Running State Messages */ 523 + next_state = STATE_1PARAM; 495 524 break; 496 525 case STATE_2PARAM_1: 497 526 port->data[1] = b; 498 - port->state = STATE_2PARAM_2; 527 + next_state = STATE_2PARAM_2; 499 528 break; 500 529 case STATE_2PARAM_2: 501 - if (port->data[0] < 0xf0) { 502 - p0 |= port->data[0] >> 4; 503 - port->state = STATE_2PARAM_1; 504 - } else { 505 - p0 |= 0x03; 506 - port->state = STATE_UNKNOWN; 507 - } 508 - f_midi_transmit_packet(req, 509 - p0, port->data[0], port->data[1], b); 530 + if (port->data[0] < 0xf0) 531 + p[0] |= port->data[0] >> 4; 532 + else 533 + p[0] |= 0x03; 534 + 535 + p[1] = port->data[0]; 536 + p[2] = port->data[1]; 537 + p[3] = b; 538 + /* This is to allow Running State Messages */ 539 + next_state = STATE_2PARAM_1; 510 540 break; 511 541 case STATE_SYSEX_0: 512 542 port->data[0] = b; 513 - port->state = STATE_SYSEX_1; 543 + next_state = STATE_SYSEX_1; 514 544 break; 515 545 case STATE_SYSEX_1: 516 546 port->data[1] = b; 517 - port->state = STATE_SYSEX_2; 547 + next_state = STATE_SYSEX_2; 518 548 break; 519 549 case STATE_SYSEX_2: 520 - f_midi_transmit_packet(req, 521 - p0 | 0x04, port->data[0], port->data[1], b); 522 - port->state = STATE_SYSEX_0; 550 + p[0] |= 0x04; 551 + p[1] = port->data[0]; 552 + p[2] = port->data[1]; 553 + p[3] = b; 554 + next_state = STATE_SYSEX_0; 523 555 break; 524 556 } 557 + break; 525 558 } 526 - } 527 559 528 - static void f_midi_drop_out_substreams(struct f_midi *midi) 529 - { 530 - unsigned int i; 560 + /* States where we have to write into the USB request */ 561 + if (next_state == STATE_FINISHED || 562 + port->state == STATE_SYSEX_2 || 563 + port->state == STATE_1PARAM || 564 + port->state == STATE_2PARAM_2 || 565 + port->state == STATE_REAL_TIME) { 531 566 532 - for (i = 0; i < midi->in_ports; i++) { 533 - struct gmidi_in_port *port = midi->in_ports_array + i; 534 - struct snd_rawmidi_substream *substream = port->substream; 535 - if (port->active && substream) 536 - snd_rawmidi_drop_output(substream); 567 + unsigned int length = req->length; 568 + u8 *buf = (u8 *)req->buf + length; 569 + 570 + memcpy(buf, p, sizeof(p)); 571 + req->length = length + sizeof(p); 572 + 573 + if (next_state == STATE_FINISHED) { 574 + next_state = STATE_INITIAL; 575 + port->data[0] = port->data[1] = 0; 576 + } 537 577 } 578 + 579 + port->state = next_state; 538 580 } 539 581 540 582 static int f_midi_do_transmit(struct f_midi *midi, struct usb_ep *ep) ··· 698 642 VDBG(midi, "%s()\n", __func__); 699 643 port = midi->in_ports_array + substream->number; 700 644 port->substream = substream; 701 - port->state = STATE_UNKNOWN; 645 + port->state = STATE_INITIAL; 702 646 return 0; 703 647 } 704 648 ··· 1179 1123 opts->func_inst.free_func_inst = f_midi_free_inst; 1180 1124 opts->index = SNDRV_DEFAULT_IDX1; 1181 1125 opts->id = SNDRV_DEFAULT_STR1; 1182 - opts->buflen = 256; 1126 + opts->buflen = 512; 1183 1127 opts->qlen = 32; 1184 1128 opts->in_ports = 1; 1185 1129 opts->out_ports = 1;
+82 -2
drivers/usb/gadget/function/f_ncm.c
··· 90 90 /* peak (theoretical) bulk transfer rate in bits-per-second */ 91 91 static inline unsigned ncm_bitrate(struct usb_gadget *g) 92 92 { 93 - if (gadget_is_dualspeed(g) && g->speed == USB_SPEED_HIGH) 93 + if (gadget_is_superspeed(g) && g->speed == USB_SPEED_SUPER) 94 + return 13 * 1024 * 8 * 1000 * 8; 95 + else if (gadget_is_dualspeed(g) && g->speed == USB_SPEED_HIGH) 94 96 return 13 * 512 * 8 * 1000 * 8; 95 97 else 96 98 return 19 * 64 * 1 * 1000 * 8; ··· 332 330 (struct usb_descriptor_header *) &ncm_data_intf, 333 331 (struct usb_descriptor_header *) &hs_ncm_in_desc, 334 332 (struct usb_descriptor_header *) &hs_ncm_out_desc, 333 + NULL, 334 + }; 335 + 336 + 337 + /* super speed support: */ 338 + 339 + static struct usb_endpoint_descriptor ss_ncm_notify_desc = { 340 + .bLength = USB_DT_ENDPOINT_SIZE, 341 + .bDescriptorType = USB_DT_ENDPOINT, 342 + 343 + .bEndpointAddress = USB_DIR_IN, 344 + .bmAttributes = USB_ENDPOINT_XFER_INT, 345 + .wMaxPacketSize = cpu_to_le16(NCM_STATUS_BYTECOUNT), 346 + .bInterval = USB_MS_TO_HS_INTERVAL(NCM_STATUS_INTERVAL_MS) 347 + }; 348 + 349 + static struct usb_ss_ep_comp_descriptor ss_ncm_notify_comp_desc = { 350 + .bLength = sizeof(ss_ncm_notify_comp_desc), 351 + .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, 352 + 353 + /* the following 3 values can be tweaked if necessary */ 354 + /* .bMaxBurst = 0, */ 355 + /* .bmAttributes = 0, */ 356 + .wBytesPerInterval = cpu_to_le16(NCM_STATUS_BYTECOUNT), 357 + }; 358 + 359 + static struct usb_endpoint_descriptor ss_ncm_in_desc = { 360 + .bLength = USB_DT_ENDPOINT_SIZE, 361 + .bDescriptorType = USB_DT_ENDPOINT, 362 + 363 + .bEndpointAddress = USB_DIR_IN, 364 + .bmAttributes = USB_ENDPOINT_XFER_BULK, 365 + .wMaxPacketSize = cpu_to_le16(1024), 366 + }; 367 + 368 + static struct usb_endpoint_descriptor ss_ncm_out_desc = { 369 + .bLength = USB_DT_ENDPOINT_SIZE, 370 + .bDescriptorType = USB_DT_ENDPOINT, 371 + 372 + .bEndpointAddress = USB_DIR_OUT, 373 + .bmAttributes = USB_ENDPOINT_XFER_BULK, 374 + .wMaxPacketSize = cpu_to_le16(1024), 375 + }; 376 + 377 + static struct usb_ss_ep_comp_descriptor ss_ncm_bulk_comp_desc = { 378 + .bLength = sizeof(ss_ncm_bulk_comp_desc), 379 + .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, 380 + 381 + /* the following 2 values can be tweaked if necessary */ 382 + /* .bMaxBurst = 0, */ 383 + /* .bmAttributes = 0, */ 384 + }; 385 + 386 + static struct usb_descriptor_header *ncm_ss_function[] = { 387 + (struct usb_descriptor_header *) &ncm_iad_desc, 388 + /* CDC NCM control descriptors */ 389 + (struct usb_descriptor_header *) &ncm_control_intf, 390 + (struct usb_descriptor_header *) &ncm_header_desc, 391 + (struct usb_descriptor_header *) &ncm_union_desc, 392 + (struct usb_descriptor_header *) &ecm_desc, 393 + (struct usb_descriptor_header *) &ncm_desc, 394 + (struct usb_descriptor_header *) &ss_ncm_notify_desc, 395 + (struct usb_descriptor_header *) &ss_ncm_notify_comp_desc, 396 + /* data interface, altsettings 0 and 1 */ 397 + (struct usb_descriptor_header *) &ncm_data_nop_intf, 398 + (struct usb_descriptor_header *) &ncm_data_intf, 399 + (struct usb_descriptor_header *) &ss_ncm_in_desc, 400 + (struct usb_descriptor_header *) &ss_ncm_bulk_comp_desc, 401 + (struct usb_descriptor_header *) &ss_ncm_out_desc, 402 + (struct usb_descriptor_header *) &ss_ncm_bulk_comp_desc, 335 403 NULL, 336 404 }; 337 405 ··· 924 852 */ 925 853 ncm->port.is_zlp_ok = 926 854 gadget_is_zlp_supported(cdev->gadget); 855 + ncm->port.no_skb_reserve = 856 + gadget_avoids_skb_reserve(cdev->gadget); 927 857 ncm->port.cdc_filter = DEFAULT_FILTER; 928 858 DBG(cdev, "activate ncm\n"); 929 859 net = gether_connect(&ncm->port); ··· 1505 1431 hs_ncm_notify_desc.bEndpointAddress = 1506 1432 fs_ncm_notify_desc.bEndpointAddress; 1507 1433 1434 + ss_ncm_in_desc.bEndpointAddress = fs_ncm_in_desc.bEndpointAddress; 1435 + ss_ncm_out_desc.bEndpointAddress = fs_ncm_out_desc.bEndpointAddress; 1436 + ss_ncm_notify_desc.bEndpointAddress = 1437 + fs_ncm_notify_desc.bEndpointAddress; 1438 + 1508 1439 status = usb_assign_descriptors(f, ncm_fs_function, ncm_hs_function, 1509 - NULL, NULL); 1440 + ncm_ss_function, NULL); 1510 1441 if (status) 1511 1442 goto fail; 1512 1443 ··· 1529 1450 ncm->task_timer.function = ncm_tx_timeout; 1530 1451 1531 1452 DBG(cdev, "CDC Network: %s speed IN/%s OUT/%s NOTIFY/%s\n", 1453 + gadget_is_superspeed(c->cdev->gadget) ? "super" : 1532 1454 gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full", 1533 1455 ncm->port.in_ep->name, ncm->port.out_ep->name, 1534 1456 ncm->notify->name);
+5 -1
drivers/usb/gadget/function/f_printer.c
··· 889 889 /*-------------------------------------------------------------------------*/ 890 890 891 891 static bool gprinter_req_match(struct usb_function *f, 892 - const struct usb_ctrlrequest *ctrl) 892 + const struct usb_ctrlrequest *ctrl, 893 + bool config0) 893 894 { 894 895 struct printer_dev *dev = func_to_printer(f); 895 896 u16 w_index = le16_to_cpu(ctrl->wIndex); 896 897 u16 w_value = le16_to_cpu(ctrl->wValue); 897 898 u16 w_length = le16_to_cpu(ctrl->wLength); 899 + 900 + if (config0) 901 + return false; 898 902 899 903 if ((ctrl->bRequestType & USB_RECIP_MASK) != USB_RECIP_INTERFACE || 900 904 (ctrl->bRequestType & USB_TYPE_MASK) != USB_TYPE_CLASS)
+2 -4
drivers/usb/gadget/function/f_sourcesink.c
··· 293 293 294 294 static inline struct usb_request *ss_alloc_ep_req(struct usb_ep *ep, int len) 295 295 { 296 - struct f_sourcesink *ss = ep->driver_data; 297 - 298 - return alloc_ep_req(ep, len, ss->buflen); 296 + return alloc_ep_req(ep, len); 299 297 } 300 298 301 299 static void disable_ep(struct usb_composite_dev *cdev, struct usb_ep *ep) ··· 604 606 } else { 605 607 ep = is_in ? ss->in_ep : ss->out_ep; 606 608 qlen = ss->bulk_qlen; 607 - size = 0; 609 + size = ss->buflen; 608 610 } 609 611 610 612 for (i = 0; i < qlen; i++) {
+7
drivers/usb/gadget/function/f_uvc.c
··· 258 258 memcpy(&uvc_event->req, ctrl, sizeof(uvc_event->req)); 259 259 v4l2_event_queue(&uvc->vdev, &v4l2_event); 260 260 261 + /* Pass additional setup data to userspace */ 262 + if (uvc->event_setup_out && uvc->event_length) { 263 + uvc->control_req->length = uvc->event_length; 264 + return usb_ep_queue(uvc->func.config->cdev->gadget->ep0, 265 + uvc->control_req, GFP_ATOMIC); 266 + } 267 + 261 268 return 0; 262 269 } 263 270
+24
drivers/usb/gadget/function/storage_common.c
··· 369 369 } 370 370 EXPORT_SYMBOL_GPL(fsg_show_removable); 371 371 372 + ssize_t fsg_show_inquiry_string(struct fsg_lun *curlun, char *buf) 373 + { 374 + return sprintf(buf, "%s\n", curlun->inquiry_string); 375 + } 376 + EXPORT_SYMBOL_GPL(fsg_show_inquiry_string); 377 + 372 378 /* 373 379 * The caller must hold fsg->filesem for reading when calling this function. 374 380 */ ··· 504 498 return count; 505 499 } 506 500 EXPORT_SYMBOL_GPL(fsg_store_removable); 501 + 502 + ssize_t fsg_store_inquiry_string(struct fsg_lun *curlun, const char *buf, 503 + size_t count) 504 + { 505 + const size_t len = min(count, sizeof(curlun->inquiry_string)); 506 + 507 + if (len == 0 || buf[0] == '\n') { 508 + curlun->inquiry_string[0] = 0; 509 + } else { 510 + snprintf(curlun->inquiry_string, 511 + sizeof(curlun->inquiry_string), "%-28s", buf); 512 + if (curlun->inquiry_string[len-1] == '\n') 513 + curlun->inquiry_string[len-1] = ' '; 514 + } 515 + 516 + return count; 517 + } 518 + EXPORT_SYMBOL_GPL(fsg_store_inquiry_string); 507 519 508 520 MODULE_LICENSE("GPL");
+10
drivers/usb/gadget/function/storage_common.h
··· 88 88 #define ASC(x) ((u8) ((x) >> 8)) 89 89 #define ASCQ(x) ((u8) (x)) 90 90 91 + /* 92 + * Vendor (8 chars), product (16 chars), release (4 hexadecimal digits) and NUL 93 + * byte 94 + */ 95 + #define INQUIRY_STRING_LEN ((size_t) (8 + 16 + 4 + 1)) 96 + 91 97 struct fsg_lun { 92 98 struct file *filp; 93 99 loff_t file_length; ··· 118 112 struct device dev; 119 113 const char *name; /* "lun.name" */ 120 114 const char **name_pfx; /* "function.name" */ 115 + char inquiry_string[INQUIRY_STRING_LEN]; 121 116 }; 122 117 123 118 static inline bool fsg_lun_is_open(struct fsg_lun *curlun) ··· 217 210 ssize_t fsg_show_nofua(struct fsg_lun *curlun, char *buf); 218 211 ssize_t fsg_show_file(struct fsg_lun *curlun, struct rw_semaphore *filesem, 219 212 char *buf); 213 + ssize_t fsg_show_inquiry_string(struct fsg_lun *curlun, char *buf); 220 214 ssize_t fsg_show_cdrom(struct fsg_lun *curlun, char *buf); 221 215 ssize_t fsg_show_removable(struct fsg_lun *curlun, char *buf); 222 216 ssize_t fsg_store_ro(struct fsg_lun *curlun, struct rw_semaphore *filesem, ··· 229 221 const char *buf, size_t count); 230 222 ssize_t fsg_store_removable(struct fsg_lun *curlun, const char *buf, 231 223 size_t count); 224 + ssize_t fsg_store_inquiry_string(struct fsg_lun *curlun, const char *buf, 225 + size_t count); 232 226 233 227 #endif /* USB_STORAGE_COMMON_H */
+6 -2
drivers/usb/gadget/function/u_ether.c
··· 82 82 #define WORK_RX_MEMORY 0 83 83 84 84 bool zlp; 85 + bool no_skb_reserve; 85 86 u8 host_mac[ETH_ALEN]; 86 87 u8 dev_mac[ETH_ALEN]; 87 88 }; ··· 234 233 * but on at least one, checksumming fails otherwise. Note: 235 234 * RNDIS headers involve variable numbers of LE32 values. 236 235 */ 237 - skb_reserve(skb, NET_IP_ALIGN); 236 + if (likely(!dev->no_skb_reserve)) 237 + skb_reserve(skb, NET_IP_ALIGN); 238 238 239 239 req->buf = skb->data; 240 240 req->length = size; ··· 571 569 req->complete = tx_complete; 572 570 573 571 /* NCM requires no zlp if transfer is dwNtbInMaxSize */ 574 - if (dev->port_usb->is_fixed && 572 + if (dev->port_usb && 573 + dev->port_usb->is_fixed && 575 574 length == dev->port_usb->fixed_in_len && 576 575 (length % in->maxpacket) == 0) 577 576 req->zero = 0; ··· 1066 1063 1067 1064 if (result == 0) { 1068 1065 dev->zlp = link->is_zlp_ok; 1066 + dev->no_skb_reserve = link->no_skb_reserve; 1069 1067 DBG(dev, "qlen %d\n", qlen(dev->gadget, dev->qmult)); 1070 1068 1071 1069 dev->header_len = link->header_len;
+1
drivers/usb/gadget/function/u_ether.h
··· 64 64 struct usb_ep *out_ep; 65 65 66 66 bool is_zlp_ok; 67 + bool no_skb_reserve; 67 68 68 69 u16 cdc_filter; 69 70
+1 -1
drivers/usb/gadget/legacy/gmidi.c
··· 47 47 module_param(id, charp, S_IRUGO); 48 48 MODULE_PARM_DESC(id, "ID string for the USB MIDI Gadget adapter."); 49 49 50 - static unsigned int buflen = 256; 50 + static unsigned int buflen = 512; 51 51 module_param(buflen, uint, S_IRUGO); 52 52 MODULE_PARM_DESC(buflen, "MIDI buffer length"); 53 53
+4 -2
drivers/usb/gadget/u_f.c
··· 12 12 */ 13 13 14 14 #include "u_f.h" 15 + #include <linux/usb/ch9.h> 15 16 16 - struct usb_request *alloc_ep_req(struct usb_ep *ep, int len, int default_len) 17 + struct usb_request *alloc_ep_req(struct usb_ep *ep, size_t len) 17 18 { 18 19 struct usb_request *req; 19 20 20 21 req = usb_ep_alloc_request(ep, GFP_ATOMIC); 21 22 if (req) { 22 - req->length = len ?: default_len; 23 + req->length = usb_endpoint_dir_out(ep->desc) ? 24 + usb_ep_align(ep, len) : len; 23 25 req->buf = kmalloc(req->length, GFP_ATOMIC); 24 26 if (!req->buf) { 25 27 usb_ep_free_request(ep, req);
+15 -2
drivers/usb/gadget/u_f.h
··· 47 47 struct usb_ep; 48 48 struct usb_request; 49 49 50 - /* Requests allocated via alloc_ep_req() must be freed by free_ep_req(). */ 51 - struct usb_request *alloc_ep_req(struct usb_ep *ep, int len, int default_len); 50 + /** 51 + * alloc_ep_req - returns a usb_request allocated by the gadget driver and 52 + * allocates the request's buffer. 53 + * 54 + * @ep: the endpoint to allocate a usb_request 55 + * @len: usb_requests's buffer suggested size 56 + * 57 + * In case @ep direction is OUT, the @len will be aligned to ep's 58 + * wMaxPacketSize. In order to avoid memory leaks or drops, *always* use 59 + * usb_requests's length (req->length) to refer to the allocated buffer size. 60 + * Requests allocated via alloc_ep_req() *must* be freed by free_ep_req(). 61 + */ 62 + struct usb_request *alloc_ep_req(struct usb_ep *ep, size_t len); 63 + 64 + /* Frees a usb_request previously allocated by alloc_ep_req() */ 52 65 static inline void free_ep_req(struct usb_ep *ep, struct usb_request *req) 53 66 { 54 67 kfree(req->buf);
+1 -3
drivers/usb/gadget/udc/core.c
··· 107 107 goto out; 108 108 109 109 ret = ep->ops->enable(ep, ep->desc); 110 - if (ret) { 111 - ret = ret; 110 + if (ret) 112 111 goto out; 113 - } 114 112 115 113 ep->enabled = true; 116 114
+4 -12
drivers/usb/gadget/udc/fsl_qe_udc.c
··· 421 421 bd = ep->rxbase; 422 422 423 423 ep->rxframe = kmalloc(sizeof(*ep->rxframe), GFP_ATOMIC); 424 - if (ep->rxframe == NULL) { 425 - dev_err(ep->udc->dev, "malloc rxframe failed\n"); 424 + if (!ep->rxframe) 426 425 return -ENOMEM; 427 - } 428 426 429 427 qe_frame_init(ep->rxframe); 430 428 ··· 433 435 434 436 size = (ep->ep.maxpacket + USB_CRC_SIZE + 2) * (bdring_len + 1); 435 437 ep->rxbuffer = kzalloc(size, GFP_ATOMIC); 436 - if (ep->rxbuffer == NULL) { 437 - dev_err(ep->udc->dev, "malloc rxbuffer failed,size=%d\n", 438 - size); 438 + if (!ep->rxbuffer) { 439 439 kfree(ep->rxframe); 440 440 return -ENOMEM; 441 441 } ··· 664 668 665 669 if ((ep->tm == USBP_TM_CTL) || (ep->dir == USB_DIR_IN)) { 666 670 ep->txframe = kmalloc(sizeof(*ep->txframe), GFP_ATOMIC); 667 - if (ep->txframe == NULL) { 668 - dev_err(udc->dev, "malloc txframe failed\n"); 671 + if (!ep->txframe) 669 672 goto en_done2; 670 - } 671 673 qe_frame_init(ep->txframe); 672 674 } 673 675 ··· 2338 2344 u32 offset; 2339 2345 2340 2346 udc = kzalloc(sizeof(*udc), GFP_KERNEL); 2341 - if (udc == NULL) { 2342 - dev_err(&ofdev->dev, "malloc udc failed\n"); 2347 + if (!udc) 2343 2348 goto cleanup; 2344 - } 2345 2349 2346 2350 udc->dev = &ofdev->dev; 2347 2351
+3 -2
drivers/usb/gadget/udc/goku_udc.c
··· 1767 1767 1768 1768 /* alloc, and start init */ 1769 1769 dev = kzalloc (sizeof *dev, GFP_KERNEL); 1770 - if (dev == NULL){ 1771 - pr_debug("enomem %s\n", pci_name(pdev)); 1770 + if (!dev) { 1772 1771 retval = -ENOMEM; 1773 1772 goto err; 1774 1773 } ··· 1838 1839 err: 1839 1840 if (dev) 1840 1841 goku_remove (pdev); 1842 + /* gadget_release is not registered yet, kfree explicitly */ 1843 + kfree(dev); 1841 1844 return retval; 1842 1845 } 1843 1846
+76 -4
drivers/usb/gadget/udc/net2280.c
··· 589 589 590 590 ep = container_of(_ep, struct net2280_ep, ep); 591 591 if (!_ep || !_req) { 592 - dev_err(&ep->dev->pdev->dev, "%s: Inavlid ep=%p or req=%p\n", 592 + dev_err(&ep->dev->pdev->dev, "%s: Invalid ep=%p or req=%p\n", 593 593 __func__, _ep, _req); 594 594 return; 595 595 } ··· 1137 1137 done(ep, req, status); 1138 1138 } 1139 1139 1140 - static void scan_dma_completions(struct net2280_ep *ep) 1140 + static int scan_dma_completions(struct net2280_ep *ep) 1141 1141 { 1142 + int num_completed = 0; 1143 + 1142 1144 /* only look at descriptors that were "naturally" retired, 1143 1145 * so fifo and list head state won't matter 1144 1146 */ ··· 1168 1166 break; 1169 1167 /* single transfer mode */ 1170 1168 dma_done(ep, req, tmp, 0); 1169 + num_completed++; 1171 1170 break; 1172 1171 } else if (!ep->is_in && 1173 1172 (req->req.length % ep->ep.maxpacket) && ··· 1197 1194 } 1198 1195 } 1199 1196 dma_done(ep, req, tmp, 0); 1197 + num_completed++; 1200 1198 } 1199 + 1200 + return num_completed; 1201 1201 } 1202 1202 1203 1203 static void restart_dma(struct net2280_ep *ep) ··· 1569 1563 if (ep && usb_gadget_ep_match_desc(_gadget, ep, desc, ep_comp)) 1570 1564 return ep; 1571 1565 ep = gadget_find_ep_by_name(_gadget, "ep-f"); 1566 + if (ep && usb_gadget_ep_match_desc(_gadget, ep, desc, ep_comp)) 1567 + return ep; 1568 + } 1569 + 1570 + /* USB3380: Only first four endpoints have DMA channels. Allocate 1571 + * slower interrupt endpoints from PIO hw endpoints, to allow bulk/isoc 1572 + * endpoints use DMA hw endpoints. 1573 + */ 1574 + if (usb_endpoint_type(desc) == USB_ENDPOINT_XFER_INT && 1575 + usb_endpoint_dir_in(desc)) { 1576 + ep = gadget_find_ep_by_name(_gadget, "ep2in"); 1577 + if (ep && usb_gadget_ep_match_desc(_gadget, ep, desc, ep_comp)) 1578 + return ep; 1579 + ep = gadget_find_ep_by_name(_gadget, "ep4in"); 1580 + if (ep && usb_gadget_ep_match_desc(_gadget, ep, desc, ep_comp)) 1581 + return ep; 1582 + } else if (usb_endpoint_type(desc) == USB_ENDPOINT_XFER_INT && 1583 + !usb_endpoint_dir_in(desc)) { 1584 + ep = gadget_find_ep_by_name(_gadget, "ep1out"); 1585 + if (ep && usb_gadget_ep_match_desc(_gadget, ep, desc, ep_comp)) 1586 + return ep; 1587 + ep = gadget_find_ep_by_name(_gadget, "ep3out"); 1588 + if (ep && usb_gadget_ep_match_desc(_gadget, ep, desc, ep_comp)) 1589 + return ep; 1590 + } else if (usb_endpoint_type(desc) != USB_ENDPOINT_XFER_BULK && 1591 + usb_endpoint_dir_in(desc)) { 1592 + ep = gadget_find_ep_by_name(_gadget, "ep1in"); 1593 + if (ep && usb_gadget_ep_match_desc(_gadget, ep, desc, ep_comp)) 1594 + return ep; 1595 + ep = gadget_find_ep_by_name(_gadget, "ep3in"); 1596 + if (ep && usb_gadget_ep_match_desc(_gadget, ep, desc, ep_comp)) 1597 + return ep; 1598 + } else if (usb_endpoint_type(desc) != USB_ENDPOINT_XFER_BULK && 1599 + !usb_endpoint_dir_in(desc)) { 1600 + ep = gadget_find_ep_by_name(_gadget, "ep2out"); 1601 + if (ep && usb_gadget_ep_match_desc(_gadget, ep, desc, ep_comp)) 1602 + return ep; 1603 + ep = gadget_find_ep_by_name(_gadget, "ep4out"); 1572 1604 if (ep && usb_gadget_ep_match_desc(_gadget, ep, desc, ep_comp)) 1573 1605 return ep; 1574 1606 } ··· 2591 2547 /* manual DMA queue advance after short OUT */ 2592 2548 if (likely(ep->dma)) { 2593 2549 if (t & BIT(SHORT_PACKET_TRANSFERRED_INTERRUPT)) { 2594 - u32 count; 2550 + struct net2280_request *stuck_req = NULL; 2595 2551 int stopped = ep->stopped; 2552 + int num_completed; 2553 + int stuck = 0; 2554 + u32 count; 2596 2555 2597 2556 /* TRANSFERRED works around OUT_DONE erratum 0112. 2598 2557 * we expect (N <= maxpacket) bytes; host wrote M. ··· 2607 2560 /* any preceding dma transfers must finish. 2608 2561 * dma handles (M >= N), may empty the queue 2609 2562 */ 2610 - scan_dma_completions(ep); 2563 + num_completed = scan_dma_completions(ep); 2611 2564 if (unlikely(list_empty(&ep->queue) || 2612 2565 ep->out_overflow)) { 2613 2566 req = NULL; ··· 2627 2580 req = NULL; 2628 2581 break; 2629 2582 } 2583 + 2584 + /* Escape loop if no dma transfers completed 2585 + * after few retries. 2586 + */ 2587 + if (num_completed == 0) { 2588 + if (stuck_req == req && 2589 + readl(&ep->dma->dmadesc) != 2590 + req->td_dma && stuck++ > 5) { 2591 + count = readl( 2592 + &ep->dma->dmacount); 2593 + count &= DMA_BYTE_COUNT_MASK; 2594 + req = NULL; 2595 + ep_dbg(ep->dev, "%s escape stuck %d, count %u\n", 2596 + ep->ep.name, stuck, 2597 + count); 2598 + break; 2599 + } else if (stuck_req != req) { 2600 + stuck_req = req; 2601 + stuck = 0; 2602 + } 2603 + } else { 2604 + stuck_req = NULL; 2605 + stuck = 0; 2606 + } 2607 + 2630 2608 udelay(1); 2631 2609 } 2632 2610
+1 -1
drivers/usb/gadget/udc/omap_udc.c
··· 2875 2875 xceiv = NULL; 2876 2876 /* "udc" is now valid */ 2877 2877 pullup_disable(udc); 2878 - #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE) 2878 + #if IS_ENABLED(CONFIG_USB_OHCI_HCD) 2879 2879 udc->gadget.is_otg = (config->otg != 0); 2880 2880 #endif 2881 2881
+49 -2
drivers/usb/gadget/udc/pxa27x_udc.c
··· 33 33 #include <linux/usb.h> 34 34 #include <linux/usb/ch9.h> 35 35 #include <linux/usb/gadget.h> 36 + #include <linux/usb/phy.h> 36 37 37 38 #include "pxa27x_udc.h" 38 39 ··· 1656 1655 return -EOPNOTSUPP; 1657 1656 } 1658 1657 1658 + /** 1659 + * pxa_udc_phy_event - Called by phy upon VBus event 1660 + * @nb: notifier block 1661 + * @action: phy action, is vbus connect or disconnect 1662 + * @data: the usb_gadget structure in pxa_udc 1663 + * 1664 + * Called by the USB Phy when a cable connect or disconnect is sensed. 1665 + * 1666 + * Returns 0 1667 + */ 1668 + static int pxa_udc_phy_event(struct notifier_block *nb, unsigned long action, 1669 + void *data) 1670 + { 1671 + struct usb_gadget *gadget = data; 1672 + 1673 + switch (action) { 1674 + case USB_EVENT_VBUS: 1675 + usb_gadget_vbus_connect(gadget); 1676 + return NOTIFY_OK; 1677 + case USB_EVENT_NONE: 1678 + usb_gadget_vbus_disconnect(gadget); 1679 + return NOTIFY_OK; 1680 + default: 1681 + return NOTIFY_DONE; 1682 + } 1683 + } 1684 + 1685 + static struct notifier_block pxa27x_udc_phy = { 1686 + .notifier_call = pxa_udc_phy_event, 1687 + }; 1688 + 1659 1689 static int pxa27x_udc_start(struct usb_gadget *g, 1660 1690 struct usb_gadget_driver *driver); 1661 1691 static int pxa27x_udc_stop(struct usb_gadget *g); ··· 2464 2432 return udc->irq; 2465 2433 2466 2434 udc->dev = &pdev->dev; 2467 - udc->transceiver = usb_get_phy(USB_PHY_TYPE_USB2); 2435 + if (of_have_populated_dt()) { 2436 + udc->transceiver = 2437 + devm_usb_get_phy_by_phandle(udc->dev, "phys", 0); 2438 + if (IS_ERR(udc->transceiver)) 2439 + return PTR_ERR(udc->transceiver); 2440 + } else { 2441 + udc->transceiver = usb_get_phy(USB_PHY_TYPE_USB2); 2442 + } 2468 2443 2469 2444 if (IS_ERR(udc->gpiod)) { 2470 2445 dev_err(&pdev->dev, "Couldn't find or request D+ gpio : %ld\n", ··· 2504 2465 goto err; 2505 2466 } 2506 2467 2468 + if (!IS_ERR_OR_NULL(udc->transceiver)) 2469 + usb_register_notifier(udc->transceiver, &pxa27x_udc_phy); 2507 2470 retval = usb_add_gadget_udc(&pdev->dev, &udc->gadget); 2508 2471 if (retval) 2509 - goto err; 2472 + goto err_add_gadget; 2510 2473 2511 2474 pxa_init_debugfs(udc); 2512 2475 if (should_enable_udc(udc)) 2513 2476 udc_enable(udc); 2514 2477 return 0; 2478 + 2479 + err_add_gadget: 2480 + if (!IS_ERR_OR_NULL(udc->transceiver)) 2481 + usb_unregister_notifier(udc->transceiver, &pxa27x_udc_phy); 2515 2482 err: 2516 2483 clk_unprepare(udc->clk); 2517 2484 return retval; ··· 2534 2489 usb_del_gadget_udc(&udc->gadget); 2535 2490 pxa_cleanup_debugfs(udc); 2536 2491 2492 + if (!IS_ERR_OR_NULL(udc->transceiver)) 2493 + usb_unregister_notifier(udc->transceiver, &pxa27x_udc_phy); 2537 2494 usb_put_phy(udc->transceiver); 2538 2495 2539 2496 udc->transceiver = NULL;
+1 -3
drivers/usb/gadget/udc/udc-xilinx.c
··· 973 973 974 974 udc = ep->udc; 975 975 req = kzalloc(sizeof(*req), gfp_flags); 976 - if (!req) { 977 - dev_err(udc->dev, "%s:not enough memory", __func__); 976 + if (!req) 978 977 return NULL; 979 - } 980 978 981 979 req->ep = ep; 982 980 INIT_LIST_HEAD(&req->queue);
+1 -1
drivers/usb/host/Kconfig
··· 472 472 473 473 config USB_OHCI_HCD_OMAP3 474 474 tristate "OHCI support for OMAP3 and later chips" 475 - depends on (ARCH_OMAP3 || ARCH_OMAP4) 475 + depends on (ARCH_OMAP3 || ARCH_OMAP4 || SOC_OMAP5) 476 476 default y 477 477 ---help--- 478 478 Enables support for the on-chip OHCI controller on
+114 -47
drivers/usb/host/bcma-hcd.c
··· 27 27 #include <linux/slab.h> 28 28 #include <linux/of.h> 29 29 #include <linux/of_gpio.h> 30 + #include <linux/of_platform.h> 30 31 #include <linux/usb/ehci_pdriver.h> 31 32 #include <linux/usb/ohci_pdriver.h> 32 33 33 34 MODULE_AUTHOR("Hauke Mehrtens"); 34 35 MODULE_DESCRIPTION("Common USB driver for BCMA Bus"); 35 36 MODULE_LICENSE("GPL"); 37 + 38 + /* See BCMA_CLKCTLST_EXTRESREQ and BCMA_CLKCTLST_EXTRESST */ 39 + #define USB_BCMA_CLKCTLST_USB_CLK_REQ 0x00000100 36 40 37 41 struct bcma_hcd_device { 38 42 struct bcma_device *core; ··· 169 165 } 170 166 } 171 167 172 - static void bcma_hcd_init_chip_arm_phy(struct bcma_device *dev) 168 + /** 169 + * bcma_hcd_usb20_old_arm_init - Initialize old USB 2.0 controller on ARM 170 + * 171 + * Old USB 2.0 core is identified as BCMA_CORE_USB20_HOST and was introduced 172 + * long before Northstar devices. It seems some cheaper chipsets like BCM53573 173 + * still use it. 174 + * Initialization of this old core differs between MIPS and ARM. 175 + */ 176 + static int bcma_hcd_usb20_old_arm_init(struct bcma_hcd_device *usb_dev) 173 177 { 174 - struct bcma_device *arm_core; 175 - void __iomem *dmu; 178 + struct bcma_device *core = usb_dev->core; 179 + struct device *dev = &core->dev; 180 + struct bcma_device *pmu_core; 176 181 177 - arm_core = bcma_find_core(dev->bus, BCMA_CORE_ARMCA9); 178 - if (!arm_core) { 179 - dev_err(&dev->dev, "can not find ARM Cortex A9 ihost core\n"); 180 - return; 182 + usleep_range(10000, 20000); 183 + if (core->id.rev < 5) 184 + return 0; 185 + 186 + pmu_core = bcma_find_core(core->bus, BCMA_CORE_PMU); 187 + if (!pmu_core) { 188 + dev_err(dev, "Could not find PMU core\n"); 189 + return -ENOENT; 181 190 } 182 191 183 - dmu = ioremap_nocache(arm_core->addr_s[0], 0x1000); 184 - if (!dmu) { 185 - dev_err(&dev->dev, "can not map ARM Cortex A9 ihost core\n"); 186 - return; 187 - } 192 + /* Take USB core out of reset */ 193 + bcma_awrite32(core, BCMA_IOCTL, BCMA_IOCTL_CLK | BCMA_IOCTL_FGC); 194 + usleep_range(100, 200); 195 + bcma_awrite32(core, BCMA_RESET_CTL, BCMA_RESET_CTL_RESET); 196 + usleep_range(100, 200); 197 + bcma_awrite32(core, BCMA_RESET_CTL, 0); 198 + usleep_range(100, 200); 199 + bcma_awrite32(core, BCMA_IOCTL, BCMA_IOCTL_CLK); 200 + usleep_range(100, 200); 188 201 189 - /* Unlock DMU PLL settings */ 190 - iowrite32(0x0000ea68, dmu + 0x180); 202 + /* Enable Misc PLL */ 203 + bcma_write32(core, BCMA_CLKCTLST, BCMA_CLKCTLST_FORCEHT | 204 + BCMA_CLKCTLST_HQCLKREQ | 205 + USB_BCMA_CLKCTLST_USB_CLK_REQ); 206 + usleep_range(100, 200); 191 207 192 - /* Write USB 2.0 PLL control setting */ 193 - iowrite32(0x00dd10c3, dmu + 0x164); 208 + bcma_write32(core, 0x510, 0xc7f85000); 209 + bcma_write32(core, 0x510, 0xc7f85003); 210 + usleep_range(300, 600); 194 211 195 - /* Lock DMU PLL settings */ 196 - iowrite32(0x00000000, dmu + 0x180); 212 + /* Program USB PHY PLL parameters */ 213 + bcma_write32(pmu_core, BCMA_CC_PMU_PLLCTL_ADDR, 0x6); 214 + bcma_write32(pmu_core, BCMA_CC_PMU_PLLCTL_DATA, 0x005360c1); 215 + usleep_range(100, 200); 216 + bcma_write32(pmu_core, BCMA_CC_PMU_PLLCTL_ADDR, 0x7); 217 + bcma_write32(pmu_core, BCMA_CC_PMU_PLLCTL_DATA, 0x0); 218 + usleep_range(100, 200); 219 + bcma_set32(pmu_core, BCMA_CC_PMU_CTL, BCMA_CC_PMU_CTL_PLL_UPD); 220 + usleep_range(100, 200); 197 221 198 - iounmap(dmu); 222 + bcma_write32(core, 0x510, 0x7f8d007); 223 + udelay(1000); 224 + 225 + /* Take controller out of reset */ 226 + bcma_write32(core, 0x200, 0x4ff); 227 + usleep_range(25, 50); 228 + bcma_write32(core, 0x200, 0x6ff); 229 + usleep_range(25, 50); 230 + bcma_write32(core, 0x200, 0x7ff); 231 + usleep_range(25, 50); 232 + 233 + of_platform_default_populate(dev->of_node, NULL, dev); 234 + 235 + return 0; 199 236 } 200 237 201 - static void bcma_hcd_init_chip_arm_hc(struct bcma_device *dev) 238 + static void bcma_hcd_usb20_ns_init_hc(struct bcma_device *dev) 202 239 { 203 240 u32 val; 204 - 205 - /* 206 - * Delay after PHY initialized to ensure HC is ready to be configured 207 - */ 208 - usleep_range(1000, 2000); 209 241 210 242 /* Set packet buffer OUT threshold */ 211 243 val = bcma_read32(dev, 0x94); ··· 253 213 val = bcma_read32(dev, 0x9c); 254 214 val |= 1; 255 215 bcma_write32(dev, 0x9c, val); 216 + 217 + /* 218 + * Broadcom initializes PHY and then waits to ensure HC is ready to be 219 + * configured. In our case the order is reversed. We just initialized 220 + * controller and we let HCD initialize PHY, so let's wait (sleep) now. 221 + */ 222 + usleep_range(1000, 2000); 256 223 } 257 224 258 - static void bcma_hcd_init_chip_arm(struct bcma_device *dev) 225 + /** 226 + * bcma_hcd_usb20_ns_init - Initialize Northstar USB 2.0 controller 227 + */ 228 + static int bcma_hcd_usb20_ns_init(struct bcma_hcd_device *bcma_hcd) 259 229 { 260 - bcma_core_enable(dev, 0); 230 + struct bcma_device *core = bcma_hcd->core; 231 + struct bcma_chipinfo *ci = &core->bus->chipinfo; 232 + struct device *dev = &core->dev; 261 233 262 - if (dev->bus->chipinfo.id == BCMA_CHIP_ID_BCM4707 || 263 - dev->bus->chipinfo.id == BCMA_CHIP_ID_BCM53018) { 264 - if (dev->bus->chipinfo.pkg == BCMA_PKG_ID_BCM4707 || 265 - dev->bus->chipinfo.pkg == BCMA_PKG_ID_BCM4708) 266 - bcma_hcd_init_chip_arm_phy(dev); 234 + bcma_core_enable(core, 0); 267 235 268 - bcma_hcd_init_chip_arm_hc(dev); 269 - } 236 + if (ci->id == BCMA_CHIP_ID_BCM4707 || 237 + ci->id == BCMA_CHIP_ID_BCM53018) 238 + bcma_hcd_usb20_ns_init_hc(core); 239 + 240 + of_platform_default_populate(dev->of_node, NULL, dev); 241 + 242 + return 0; 270 243 } 271 244 272 245 static void bcma_hci_platform_power_gpio(struct bcma_device *dev, bool val) ··· 352 299 if (dma_set_mask_and_coherent(dev->dma_dev, DMA_BIT_MASK(32))) 353 300 return -EOPNOTSUPP; 354 301 355 - switch (dev->id.id) { 356 - case BCMA_CORE_NS_USB20: 357 - bcma_hcd_init_chip_arm(dev); 358 - break; 359 - case BCMA_CORE_USB20_HOST: 360 - bcma_hcd_init_chip_mips(dev); 361 - break; 362 - default: 363 - return -ENODEV; 364 - } 302 + bcma_hcd_init_chip_mips(dev); 365 303 366 304 /* In AI chips EHCI is addrspace 0, OHCI is 1 */ 367 305 ohci_addr = dev->addr_s[0]; ··· 382 338 return err; 383 339 } 384 340 341 + static int bcma_hcd_usb30_init(struct bcma_hcd_device *bcma_hcd) 342 + { 343 + struct bcma_device *core = bcma_hcd->core; 344 + struct device *dev = &core->dev; 345 + 346 + bcma_core_enable(core, 0); 347 + 348 + of_platform_default_populate(dev->of_node, NULL, dev); 349 + 350 + return 0; 351 + } 352 + 385 353 static int bcma_hcd_probe(struct bcma_device *core) 386 354 { 387 355 int err; ··· 413 357 414 358 switch (core->id.id) { 415 359 case BCMA_CORE_USB20_HOST: 360 + if (IS_ENABLED(CONFIG_ARM)) 361 + err = bcma_hcd_usb20_old_arm_init(usb_dev); 362 + else if (IS_ENABLED(CONFIG_MIPS)) 363 + err = bcma_hcd_usb20_init(usb_dev); 364 + else 365 + err = -ENOTSUPP; 366 + break; 416 367 case BCMA_CORE_NS_USB20: 417 - err = bcma_hcd_usb20_init(usb_dev); 418 - if (err) 419 - return err; 368 + err = bcma_hcd_usb20_ns_init(usb_dev); 369 + break; 370 + case BCMA_CORE_NS_USB30: 371 + err = bcma_hcd_usb30_init(usb_dev); 420 372 break; 421 373 default: 422 374 return -ENODEV; 423 375 } 376 + if (err) 377 + return err; 424 378 425 379 bcma_set_drvdata(core, usb_dev); 426 380 return 0; ··· 482 416 static const struct bcma_device_id bcma_hcd_table[] = { 483 417 BCMA_CORE(BCMA_MANUF_BCM, BCMA_CORE_USB20_HOST, BCMA_ANY_REV, BCMA_ANY_CLASS), 484 418 BCMA_CORE(BCMA_MANUF_BCM, BCMA_CORE_NS_USB20, BCMA_ANY_REV, BCMA_ANY_CLASS), 419 + BCMA_CORE(BCMA_MANUF_BCM, BCMA_CORE_NS_USB30, BCMA_ANY_REV, BCMA_ANY_CLASS), 485 420 {}, 486 421 }; 487 422 MODULE_DEVICE_TABLE(bcma, bcma_hcd_table);
+1 -1
drivers/usb/host/ehci-platform.c
··· 38 38 #include "ehci.h" 39 39 40 40 #define DRIVER_DESC "EHCI generic platform driver" 41 - #define EHCI_MAX_CLKS 3 41 + #define EHCI_MAX_CLKS 4 42 42 #define EHCI_MAX_RSTS 3 43 43 #define hcd_to_ehci_priv(h) ((struct ehci_platform_priv *)hcd_to_ehci(h)->priv) 44 44
+1 -3
drivers/usb/host/fhci-hcd.c
··· 310 310 311 311 /* allocate memory for SCC data structure */ 312 312 usb = kzalloc(sizeof(*usb), GFP_KERNEL); 313 - if (!usb) { 314 - fhci_err(fhci, "no memory for SCC data struct\n"); 313 + if (!usb) 315 314 return NULL; 316 - } 317 315 318 316 usb->fhci = fhci; 319 317 usb->hc_list = fhci->hc_list;
+6 -12
drivers/usb/host/fsl-mph-dr-of.c
··· 222 222 pdata->controller_ver = usb_get_ver_info(np); 223 223 224 224 /* Activate Erratum by reading property in device tree */ 225 - if (of_get_property(np, "fsl,usb-erratum-a007792", NULL)) 226 - pdata->has_fsl_erratum_a007792 = 1; 227 - else 228 - pdata->has_fsl_erratum_a007792 = 0; 229 - if (of_get_property(np, "fsl,usb-erratum-a005275", NULL)) 230 - pdata->has_fsl_erratum_a005275 = 1; 231 - else 232 - pdata->has_fsl_erratum_a005275 = 0; 225 + pdata->has_fsl_erratum_a007792 = 226 + of_property_read_bool(np, "fsl,usb-erratum-a007792"); 227 + pdata->has_fsl_erratum_a005275 = 228 + of_property_read_bool(np, "fsl,usb-erratum-a005275"); 233 229 234 230 /* 235 231 * Determine whether phy_clk_valid needs to be checked 236 232 * by reading property in device tree 237 233 */ 238 - if (of_get_property(np, "phy-clk-valid", NULL)) 239 - pdata->check_phy_clk_valid = 1; 240 - else 241 - pdata->check_phy_clk_valid = 0; 234 + pdata->check_phy_clk_valid = 235 + of_property_read_bool(np, "phy-clk-valid"); 242 236 243 237 if (pdata->have_sysif_regs) { 244 238 if (pdata->controller_ver == FSL_USB_VER_NONE) {
+2 -6
drivers/usb/host/max3421-hcd.c
··· 1856 1856 INIT_LIST_HEAD(&max3421_hcd->ep_list); 1857 1857 1858 1858 max3421_hcd->tx = kmalloc(sizeof(*max3421_hcd->tx), GFP_KERNEL); 1859 - if (!max3421_hcd->tx) { 1860 - dev_err(&spi->dev, "failed to kmalloc tx buffer\n"); 1859 + if (!max3421_hcd->tx) 1861 1860 goto error; 1862 - } 1863 1861 max3421_hcd->rx = kmalloc(sizeof(*max3421_hcd->rx), GFP_KERNEL); 1864 - if (!max3421_hcd->rx) { 1865 - dev_err(&spi->dev, "failed to kmalloc rx buffer\n"); 1862 + if (!max3421_hcd->rx) 1866 1863 goto error; 1867 - } 1868 1864 1869 1865 max3421_hcd->spi_thread = kthread_run(max3421_spi_thread, hcd, 1870 1866 "max3421_spi_thread");
+68 -1
drivers/usb/host/ohci-at91.c
··· 21 21 #include <linux/io.h> 22 22 #include <linux/kernel.h> 23 23 #include <linux/module.h> 24 + #include <linux/mfd/syscon.h> 25 + #include <linux/regmap.h> 24 26 #include <linux/usb.h> 25 27 #include <linux/usb/hcd.h> 28 + #include <soc/at91/atmel-sfr.h> 26 29 27 30 #include "ohci.h" 28 31 ··· 54 51 struct clk *hclk; 55 52 bool clocked; 56 53 bool wakeup; /* Saved wake-up state for resume */ 54 + struct regmap *sfr_regmap; 57 55 }; 58 56 /* interface and function clocks; sometimes also an AHB clock */ 59 57 ··· 138 134 139 135 static void usb_hcd_at91_remove (struct usb_hcd *, struct platform_device *); 140 136 137 + static struct regmap *at91_dt_syscon_sfr(void) 138 + { 139 + struct regmap *regmap; 140 + 141 + regmap = syscon_regmap_lookup_by_compatible("atmel,sama5d2-sfr"); 142 + if (IS_ERR(regmap)) 143 + regmap = NULL; 144 + 145 + return regmap; 146 + } 147 + 141 148 /* configure so an HC device and id are always provided */ 142 149 /* always called with process context; sleeping is OK */ 143 150 ··· 211 196 retval = PTR_ERR(ohci_at91->hclk); 212 197 goto err; 213 198 } 199 + 200 + ohci_at91->sfr_regmap = at91_dt_syscon_sfr(); 201 + if (!ohci_at91->sfr_regmap) 202 + dev_warn(dev, "failed to find sfr node\n"); 214 203 215 204 board = hcd->self.controller->platform_data; 216 205 ohci = hcd_to_ohci(hcd); ··· 301 282 return length; 302 283 } 303 284 285 + static int ohci_at91_port_suspend(struct regmap *regmap, u8 set) 286 + { 287 + u32 regval; 288 + int ret; 289 + 290 + if (!regmap) 291 + return 0; 292 + 293 + ret = regmap_read(regmap, AT91_SFR_OHCIICR, &regval); 294 + if (ret) 295 + return ret; 296 + 297 + if (set) 298 + regval |= AT91_OHCIICR_USB_SUSPEND; 299 + else 300 + regval &= ~AT91_OHCIICR_USB_SUSPEND; 301 + 302 + regmap_write(regmap, AT91_SFR_OHCIICR, regval); 303 + 304 + return 0; 305 + } 306 + 304 307 /* 305 308 * Look at the control requests to the root hub and see if we need to override. 306 309 */ ··· 330 289 u16 wIndex, char *buf, u16 wLength) 331 290 { 332 291 struct at91_usbh_data *pdata = dev_get_platdata(hcd->self.controller); 292 + struct ohci_at91_priv *ohci_at91 = hcd_to_ohci_at91_priv(hcd); 333 293 struct usb_hub_descriptor *desc; 334 294 int ret = -EINVAL; 335 295 u32 *data = (u32 *)buf; ··· 343 301 344 302 switch (typeReq) { 345 303 case SetPortFeature: 346 - if (wValue == USB_PORT_FEAT_POWER) { 304 + switch (wValue) { 305 + case USB_PORT_FEAT_POWER: 347 306 dev_dbg(hcd->self.controller, "SetPortFeat: POWER\n"); 348 307 if (valid_port(wIndex)) { 349 308 ohci_at91_usb_set_power(pdata, wIndex, 1); ··· 352 309 } 353 310 354 311 goto out; 312 + 313 + case USB_PORT_FEAT_SUSPEND: 314 + dev_dbg(hcd->self.controller, "SetPortFeat: SUSPEND\n"); 315 + if (valid_port(wIndex)) { 316 + ohci_at91_port_suspend(ohci_at91->sfr_regmap, 317 + 1); 318 + return 0; 319 + } 320 + break; 355 321 } 356 322 break; 357 323 ··· 394 342 ohci_at91_usb_set_power(pdata, wIndex, 0); 395 343 return 0; 396 344 } 345 + break; 346 + 347 + case USB_PORT_FEAT_SUSPEND: 348 + dev_dbg(hcd->self.controller, "ClearPortFeature: SUSPEND\n"); 349 + if (valid_port(wIndex)) { 350 + ohci_at91_port_suspend(ohci_at91->sfr_regmap, 351 + 0); 352 + return 0; 353 + } 354 + break; 397 355 } 398 356 break; 399 357 } ··· 661 599 if (ohci_at91->wakeup) 662 600 enable_irq_wake(hcd->irq); 663 601 602 + ohci_at91_port_suspend(ohci_at91->sfr_regmap, 1); 603 + 664 604 ret = ohci_suspend(hcd, ohci_at91->wakeup); 665 605 if (ret) { 666 606 if (ohci_at91->wakeup) ··· 702 638 at91_start_clock(ohci_at91); 703 639 704 640 ohci_resume(hcd, false); 641 + 642 + ohci_at91_port_suspend(ohci_at91->sfr_regmap, 0); 643 + 705 644 return 0; 706 645 } 707 646
-1
drivers/usb/host/ohci-omap.c
··· 36 36 #include <mach/mux.h> 37 37 38 38 #include <mach/hardware.h> 39 - #include <mach/irqs.h> 40 39 #include <mach/usb.h> 41 40 42 41
+1 -3
drivers/usb/host/ohci-sa1111.c
··· 13 13 * This file is licenced under the GPL. 14 14 */ 15 15 16 - #include <mach/hardware.h> 17 16 #include <asm/mach-types.h> 18 - #include <mach/assabet.h> 19 17 #include <asm/hardware/sa1111.h> 20 18 21 19 #ifndef CONFIG_SA1111 ··· 125 127 dev_dbg(&dev->dev, "starting SA-1111 OHCI USB Controller\n"); 126 128 127 129 if (machine_is_xp860() || 128 - machine_has_neponset() || 130 + machine_is_assabet() || 129 131 machine_is_pfs168() || 130 132 machine_is_badge4()) 131 133 usb_rst = USB_RESET_PWRSENSELOW | USB_RESET_PWRCTRLLOW;
+1 -4
drivers/usb/host/uhci-hcd.c
··· 601 601 602 602 uhci->frame_cpu = kcalloc(UHCI_NUMFRAMES, sizeof(*uhci->frame_cpu), 603 603 GFP_KERNEL); 604 - if (!uhci->frame_cpu) { 605 - dev_err(uhci_dev(uhci), 606 - "unable to allocate memory for frame pointers\n"); 604 + if (!uhci->frame_cpu) 607 605 goto err_alloc_frame_cpu; 608 - } 609 606 610 607 uhci->td_pool = dma_pool_create("uhci_td", uhci_dev(uhci), 611 608 sizeof(struct uhci_td), 16, 0);
+1 -1
drivers/usb/host/whci/init.c
··· 65 65 init_waitqueue_head(&whc->cmd_wq); 66 66 init_waitqueue_head(&whc->async_list_wq); 67 67 init_waitqueue_head(&whc->periodic_list_wq); 68 - whc->workqueue = create_singlethread_workqueue(dev_name(&whc->umc->dev)); 68 + whc->workqueue = alloc_ordered_workqueue(dev_name(&whc->umc->dev), 0); 69 69 if (whc->workqueue == NULL) { 70 70 ret = -ENOMEM; 71 71 goto error;
+1 -1
drivers/usb/host/xhci-tegra.c
··· 1033 1033 tegra->phys = devm_kcalloc(&pdev->dev, tegra->num_phys, 1034 1034 sizeof(*tegra->phys), GFP_KERNEL); 1035 1035 if (!tegra->phys) { 1036 - dev_err(&pdev->dev, "failed to allocate PHY array\n"); 1037 1036 err = -ENOMEM; 1038 1037 goto put_padctl; 1039 1038 } ··· 1116 1117 tegra->hcd); 1117 1118 if (!xhci->shared_hcd) { 1118 1119 dev_err(&pdev->dev, "failed to create shared HCD\n"); 1120 + err = -ENOMEM; 1119 1121 goto remove_usb2; 1120 1122 } 1121 1123
+1 -3
drivers/usb/host/xhci.c
··· 295 295 xhci->msix_entries = 296 296 kmalloc((sizeof(struct msix_entry))*xhci->msix_count, 297 297 GFP_KERNEL); 298 - if (!xhci->msix_entries) { 299 - xhci_err(xhci, "Failed to allocate MSI-X entries\n"); 298 + if (!xhci->msix_entries) 300 299 return -ENOMEM; 301 - } 302 300 303 301 for (i = 0; i < xhci->msix_count; i++) { 304 302 xhci->msix_entries[i].entry = i;
+6
drivers/usb/misc/Kconfig
··· 240 240 help 241 241 This option enables support for SMSC USB3503 HSIC to USB 2.0 Driver. 242 242 243 + config USB_HSIC_USB4604 244 + tristate "USB4604 HSIC to USB20 Driver" 245 + depends on I2C 246 + help 247 + This option enables support for SMSC USB4604 HSIC to USB 2.0 Driver. 248 + 243 249 config USB_LINK_LAYER_TEST 244 250 tristate "USB Link Layer Test driver" 245 251 help
+1
drivers/usb/misc/Makefile
··· 24 24 obj-$(CONFIG_USB_SEVSEG) += usbsevseg.o 25 25 obj-$(CONFIG_USB_YUREX) += yurex.o 26 26 obj-$(CONFIG_USB_HSIC_USB3503) += usb3503.o 27 + obj-$(CONFIG_USB_HSIC_USB4604) += usb4604.o 27 28 obj-$(CONFIG_USB_CHAOSKEY) += chaoskey.o 28 29 obj-$(CONFIG_UCSI) += ucsi.o 29 30
+5 -16
drivers/usb/misc/adutux.c
··· 672 672 673 673 /* allocate memory for our device state and initialize it */ 674 674 dev = kzalloc(sizeof(struct adu_device), GFP_KERNEL); 675 - if (dev == NULL) { 676 - dev_err(&interface->dev, "Out of memory\n"); 675 + if (!dev) { 677 676 retval = -ENOMEM; 678 677 goto exit; 679 678 } ··· 709 710 710 711 dev->read_buffer_primary = kmalloc((4 * in_end_size), GFP_KERNEL); 711 712 if (!dev->read_buffer_primary) { 712 - dev_err(&interface->dev, "Couldn't allocate read_buffer_primary\n"); 713 713 retval = -ENOMEM; 714 714 goto error; 715 715 } ··· 721 723 722 724 dev->read_buffer_secondary = kmalloc((4 * in_end_size), GFP_KERNEL); 723 725 if (!dev->read_buffer_secondary) { 724 - dev_err(&interface->dev, "Couldn't allocate read_buffer_secondary\n"); 725 726 retval = -ENOMEM; 726 727 goto error; 727 728 } ··· 732 735 memset(dev->read_buffer_secondary + (3 * in_end_size), 'h', in_end_size); 733 736 734 737 dev->interrupt_in_buffer = kmalloc(in_end_size, GFP_KERNEL); 735 - if (!dev->interrupt_in_buffer) { 736 - dev_err(&interface->dev, "Couldn't allocate interrupt_in_buffer\n"); 738 + if (!dev->interrupt_in_buffer) 737 739 goto error; 738 - } 739 740 740 741 /* debug code prime the buffer */ 741 742 memset(dev->interrupt_in_buffer, 'i', in_end_size); 742 743 743 744 dev->interrupt_in_urb = usb_alloc_urb(0, GFP_KERNEL); 744 - if (!dev->interrupt_in_urb) { 745 - dev_err(&interface->dev, "Couldn't allocate interrupt_in_urb\n"); 745 + if (!dev->interrupt_in_urb) 746 746 goto error; 747 - } 748 747 dev->interrupt_out_buffer = kmalloc(out_end_size, GFP_KERNEL); 749 - if (!dev->interrupt_out_buffer) { 750 - dev_err(&interface->dev, "Couldn't allocate interrupt_out_buffer\n"); 748 + if (!dev->interrupt_out_buffer) 751 749 goto error; 752 - } 753 750 dev->interrupt_out_urb = usb_alloc_urb(0, GFP_KERNEL); 754 - if (!dev->interrupt_out_urb) { 755 - dev_err(&interface->dev, "Couldn't allocate interrupt_out_urb\n"); 751 + if (!dev->interrupt_out_urb) 756 752 goto error; 757 - } 758 753 759 754 if (!usb_string(udev, udev->descriptor.iSerialNumber, dev->serial_number, 760 755 sizeof(dev->serial_number))) {
+2 -15
drivers/usb/misc/appledisplay.c
··· 85 85 }; 86 86 87 87 static atomic_t count_displays = ATOMIC_INIT(0); 88 - static struct workqueue_struct *wq; 89 88 90 89 static void appledisplay_complete(struct urb *urb) 91 90 { ··· 121 122 case ACD_BTN_BRIGHT_UP: 122 123 case ACD_BTN_BRIGHT_DOWN: 123 124 pdata->button_pressed = 1; 124 - queue_delayed_work(wq, &pdata->work, 0); 125 + schedule_delayed_work(&pdata->work, 0); 125 126 break; 126 127 case ACD_BTN_NONE: 127 128 default: ··· 238 239 pdata = kzalloc(sizeof(struct appledisplay), GFP_KERNEL); 239 240 if (!pdata) { 240 241 retval = -ENOMEM; 241 - dev_err(&iface->dev, "Out of memory\n"); 242 242 goto error; 243 243 } 244 244 ··· 251 253 pdata->msgdata = kmalloc(ACD_MSG_BUFFER_LEN, GFP_KERNEL); 252 254 if (!pdata->msgdata) { 253 255 retval = -ENOMEM; 254 - dev_err(&iface->dev, 255 - "Allocating buffer for control messages failed\n"); 256 256 goto error; 257 257 } 258 258 ··· 258 262 pdata->urb = usb_alloc_urb(0, GFP_KERNEL); 259 263 if (!pdata->urb) { 260 264 retval = -ENOMEM; 261 - dev_err(&iface->dev, "Allocating URB failed\n"); 262 265 goto error; 263 266 } 264 267 ··· 339 344 340 345 if (pdata) { 341 346 usb_kill_urb(pdata->urb); 342 - cancel_delayed_work(&pdata->work); 347 + cancel_delayed_work_sync(&pdata->work); 343 348 backlight_device_unregister(pdata->bd); 344 349 usb_free_coherent(pdata->udev, ACD_URB_BUFFER_LEN, 345 350 pdata->urbdata, pdata->urb->transfer_dma); ··· 360 365 361 366 static int __init appledisplay_init(void) 362 367 { 363 - wq = create_singlethread_workqueue("appledisplay"); 364 - if (!wq) { 365 - printk(KERN_ERR "appledisplay: Could not create work queue\n"); 366 - return -ENOMEM; 367 - } 368 - 369 368 return usb_register(&appledisplay_driver); 370 369 } 371 370 372 371 static void __exit appledisplay_exit(void) 373 372 { 374 - flush_workqueue(wq); 375 - destroy_workqueue(wq); 376 373 usb_deregister(&appledisplay_driver); 377 374 } 378 375
+1 -4
drivers/usb/misc/cypress_cy7c63.c
··· 79 79 /* allocate some memory for the i/o buffer*/ 80 80 iobuf = kzalloc(CYPRESS_MAX_REQSIZE, GFP_KERNEL); 81 81 if (!iobuf) { 82 - dev_err(&dev->udev->dev, "Out of memory!\n"); 83 82 retval = -ENOMEM; 84 83 goto error; 85 84 } ··· 207 208 208 209 /* allocate memory for our device state and initialize it */ 209 210 dev = kzalloc(sizeof(*dev), GFP_KERNEL); 210 - if (dev == NULL) { 211 - dev_err(&interface->dev, "Out of memory!\n"); 211 + if (!dev) 212 212 goto error_mem; 213 - } 214 213 215 214 dev->udev = usb_get_dev(interface_to_usbdev(interface)); 216 215
+8 -24
drivers/usb/misc/cytherm.c
··· 101 101 int retval; 102 102 103 103 buffer = kmalloc(8, GFP_KERNEL); 104 - if (!buffer) { 105 - dev_err(&cytherm->udev->dev, "out of memory\n"); 104 + if (!buffer) 106 105 return 0; 107 - } 108 106 109 107 cytherm->brightness = simple_strtoul(buf, NULL, 10); 110 108 ··· 146 148 int temp, sign; 147 149 148 150 buffer = kmalloc(8, GFP_KERNEL); 149 - if (!buffer) { 150 - dev_err(&cytherm->udev->dev, "out of memory\n"); 151 + if (!buffer) 151 152 return 0; 152 - } 153 153 154 154 /* read temperature */ 155 155 retval = vendor_command(cytherm->udev, READ_RAM, TEMP, 0, buffer, 8); ··· 188 192 unsigned char *buffer; 189 193 190 194 buffer = kmalloc(8, GFP_KERNEL); 191 - if (!buffer) { 192 - dev_err(&cytherm->udev->dev, "out of memory\n"); 195 + if (!buffer) 193 196 return 0; 194 - } 195 197 196 198 /* check button */ 197 199 retval = vendor_command(cytherm->udev, READ_RAM, BUTTON, 0, buffer, 8); ··· 224 230 unsigned char *buffer; 225 231 226 232 buffer = kmalloc(8, GFP_KERNEL); 227 - if (!buffer) { 228 - dev_err(&cytherm->udev->dev, "out of memory\n"); 233 + if (!buffer) 229 234 return 0; 230 - } 231 235 232 236 retval = vendor_command(cytherm->udev, READ_PORT, 0, 0, buffer, 8); 233 237 if (retval) ··· 249 257 int tmp; 250 258 251 259 buffer = kmalloc(8, GFP_KERNEL); 252 - if (!buffer) { 253 - dev_err(&cytherm->udev->dev, "out of memory\n"); 260 + if (!buffer) 254 261 return 0; 255 - } 256 262 257 263 tmp = simple_strtoul(buf, NULL, 10); 258 264 ··· 280 290 unsigned char *buffer; 281 291 282 292 buffer = kmalloc(8, GFP_KERNEL); 283 - if (!buffer) { 284 - dev_err(&cytherm->udev->dev, "out of memory\n"); 293 + if (!buffer) 285 294 return 0; 286 - } 287 295 288 296 retval = vendor_command(cytherm->udev, READ_PORT, 1, 0, buffer, 8); 289 297 if (retval) ··· 305 317 int tmp; 306 318 307 319 buffer = kmalloc(8, GFP_KERNEL); 308 - if (!buffer) { 309 - dev_err(&cytherm->udev->dev, "out of memory\n"); 320 + if (!buffer) 310 321 return 0; 311 - } 312 322 313 323 tmp = simple_strtoul(buf, NULL, 10); 314 324 ··· 337 351 int retval = -ENOMEM; 338 352 339 353 dev = kzalloc (sizeof(struct usb_cytherm), GFP_KERNEL); 340 - if (dev == NULL) { 341 - dev_err (&interface->dev, "Out of memory\n"); 354 + if (!dev) 342 355 goto error_mem; 343 - } 344 356 345 357 dev->udev = usb_get_dev(udev); 346 358
+1 -1
drivers/usb/misc/ezusb.c
··· 22 22 unsigned short max_internal_adress; 23 23 }; 24 24 25 - static struct ezusb_fx_type ezusb_fx1 = { 25 + static const struct ezusb_fx_type ezusb_fx1 = { 26 26 .cpucs_reg = 0x7F92, 27 27 .max_internal_adress = 0x1B3F, 28 28 };
+13 -54
drivers/usb/misc/ftdi-elan.c
··· 61 61 MODULE_PARM_DESC(distrust_firmware, 62 62 "true to distrust firmware power/overcurrent setup"); 63 63 extern struct platform_driver u132_platform_driver; 64 - static struct workqueue_struct *status_queue; 65 - static struct workqueue_struct *command_queue; 66 - static struct workqueue_struct *respond_queue; 67 64 /* 68 65 * ftdi_module_lock exists to protect access to global variables 69 66 * ··· 225 228 226 229 static void ftdi_status_requeue_work(struct usb_ftdi *ftdi, unsigned int delta) 227 230 { 228 - if (!queue_delayed_work(status_queue, &ftdi->status_work, delta)) 231 + if (!schedule_delayed_work(&ftdi->status_work, delta)) 229 232 kref_put(&ftdi->kref, ftdi_elan_delete); 230 233 } 231 234 232 235 static void ftdi_status_queue_work(struct usb_ftdi *ftdi, unsigned int delta) 233 236 { 234 - if (queue_delayed_work(status_queue, &ftdi->status_work, delta)) 237 + if (schedule_delayed_work(&ftdi->status_work, delta)) 235 238 kref_get(&ftdi->kref); 236 239 } 237 240 238 241 static void ftdi_status_cancel_work(struct usb_ftdi *ftdi) 239 242 { 240 - if (cancel_delayed_work(&ftdi->status_work)) 243 + if (cancel_delayed_work_sync(&ftdi->status_work)) 241 244 kref_put(&ftdi->kref, ftdi_elan_delete); 242 245 } 243 246 244 247 static void ftdi_command_requeue_work(struct usb_ftdi *ftdi, unsigned int delta) 245 248 { 246 - if (!queue_delayed_work(command_queue, &ftdi->command_work, delta)) 249 + if (!schedule_delayed_work(&ftdi->command_work, delta)) 247 250 kref_put(&ftdi->kref, ftdi_elan_delete); 248 251 } 249 252 250 253 static void ftdi_command_queue_work(struct usb_ftdi *ftdi, unsigned int delta) 251 254 { 252 - if (queue_delayed_work(command_queue, &ftdi->command_work, delta)) 255 + if (schedule_delayed_work(&ftdi->command_work, delta)) 253 256 kref_get(&ftdi->kref); 254 257 } 255 258 256 259 static void ftdi_command_cancel_work(struct usb_ftdi *ftdi) 257 260 { 258 - if (cancel_delayed_work(&ftdi->command_work)) 261 + if (cancel_delayed_work_sync(&ftdi->command_work)) 259 262 kref_put(&ftdi->kref, ftdi_elan_delete); 260 263 } 261 264 262 265 static void ftdi_response_requeue_work(struct usb_ftdi *ftdi, 263 266 unsigned int delta) 264 267 { 265 - if (!queue_delayed_work(respond_queue, &ftdi->respond_work, delta)) 268 + if (!schedule_delayed_work(&ftdi->respond_work, delta)) 266 269 kref_put(&ftdi->kref, ftdi_elan_delete); 267 270 } 268 271 269 272 static void ftdi_respond_queue_work(struct usb_ftdi *ftdi, unsigned int delta) 270 273 { 271 - if (queue_delayed_work(respond_queue, &ftdi->respond_work, delta)) 274 + if (schedule_delayed_work(&ftdi->respond_work, delta)) 272 275 kref_get(&ftdi->kref); 273 276 } 274 277 275 278 static void ftdi_response_cancel_work(struct usb_ftdi *ftdi) 276 279 { 277 - if (cancel_delayed_work(&ftdi->respond_work)) 280 + if (cancel_delayed_work_sync(&ftdi->respond_work)) 278 281 kref_put(&ftdi->kref, ftdi_elan_delete); 279 282 } 280 283 ··· 782 785 return 0; 783 786 total_size = ftdi_elan_total_command_size(ftdi, command_size); 784 787 urb = usb_alloc_urb(0, GFP_KERNEL); 785 - if (!urb) { 786 - dev_err(&ftdi->udev->dev, "could not get a urb to write %d commands totaling %d bytes to the Uxxx\n", 787 - command_size, total_size); 788 + if (!urb) 788 789 return -ENOMEM; 789 - } 790 790 buf = usb_alloc_coherent(ftdi->udev, total_size, GFP_KERNEL, 791 791 &urb->transfer_dma); 792 792 if (!buf) { ··· 1942 1948 int I = 257; 1943 1949 int i = 0; 1944 1950 urb = usb_alloc_urb(0, GFP_KERNEL); 1945 - if (!urb) { 1946 - dev_err(&ftdi->udev->dev, "could not alloc a urb for flush sequence\n"); 1951 + if (!urb) 1947 1952 return -ENOMEM; 1948 - } 1949 1953 buf = usb_alloc_coherent(ftdi->udev, I, GFP_KERNEL, &urb->transfer_dma); 1950 1954 if (!buf) { 1951 1955 dev_err(&ftdi->udev->dev, "could not get a buffer for flush sequence\n"); ··· 1980 1988 int I = 4; 1981 1989 int i = 0; 1982 1990 urb = usb_alloc_urb(0, GFP_KERNEL); 1983 - if (!urb) { 1984 - dev_err(&ftdi->udev->dev, "could not get a urb for the reset sequence\n"); 1991 + if (!urb) 1985 1992 return -ENOMEM; 1986 - } 1987 1993 buf = usb_alloc_coherent(ftdi->udev, I, GFP_KERNEL, &urb->transfer_dma); 1988 1994 if (!buf) { 1989 1995 dev_err(&ftdi->udev->dev, "could not get a buffer for the reset sequence\n"); ··· 2730 2740 ftdi->bulk_in_endpointAddr = endpoint->bEndpointAddress; 2731 2741 ftdi->bulk_in_buffer = kmalloc(buffer_size, GFP_KERNEL); 2732 2742 if (!ftdi->bulk_in_buffer) { 2733 - dev_err(&ftdi->udev->dev, "Could not allocate bulk_in_buffer\n"); 2734 2743 retval = -ENOMEM; 2735 2744 goto error; 2736 2745 } ··· 2812 2823 ftdi->initialized = 0; 2813 2824 ftdi->registered = 0; 2814 2825 } 2815 - flush_workqueue(status_queue); 2816 - flush_workqueue(command_queue); 2817 - flush_workqueue(respond_queue); 2818 2826 ftdi->disconnected += 1; 2819 2827 usb_set_intfdata(interface, NULL); 2820 2828 dev_info(&ftdi->udev->dev, "USB FTDI U132 host controller interface now disconnected\n"); ··· 2831 2845 pr_info("driver %s\n", ftdi_elan_driver.name); 2832 2846 mutex_init(&ftdi_module_lock); 2833 2847 INIT_LIST_HEAD(&ftdi_static_list); 2834 - status_queue = create_singlethread_workqueue("ftdi-status-control"); 2835 - if (!status_queue) 2836 - goto err_status_queue; 2837 - command_queue = create_singlethread_workqueue("ftdi-command-engine"); 2838 - if (!command_queue) 2839 - goto err_command_queue; 2840 - respond_queue = create_singlethread_workqueue("ftdi-respond-engine"); 2841 - if (!respond_queue) 2842 - goto err_respond_queue; 2843 2848 result = usb_register(&ftdi_elan_driver); 2844 2849 if (result) { 2845 - destroy_workqueue(status_queue); 2846 - destroy_workqueue(command_queue); 2847 - destroy_workqueue(respond_queue); 2848 2850 pr_err("usb_register failed. Error number %d\n", result); 2849 2851 } 2850 2852 return result; 2851 2853 2852 - err_respond_queue: 2853 - destroy_workqueue(command_queue); 2854 - err_command_queue: 2855 - destroy_workqueue(status_queue); 2856 - err_status_queue: 2857 - pr_err("%s couldn't create workqueue\n", ftdi_elan_driver.name); 2858 - return -ENOMEM; 2859 2854 } 2860 2855 2861 2856 static void __exit ftdi_elan_exit(void) ··· 2849 2882 ftdi_status_cancel_work(ftdi); 2850 2883 ftdi_command_cancel_work(ftdi); 2851 2884 ftdi_response_cancel_work(ftdi); 2852 - } flush_workqueue(status_queue); 2853 - destroy_workqueue(status_queue); 2854 - status_queue = NULL; 2855 - flush_workqueue(command_queue); 2856 - destroy_workqueue(command_queue); 2857 - command_queue = NULL; 2858 - flush_workqueue(respond_queue); 2859 - destroy_workqueue(respond_queue); 2860 - respond_queue = NULL; 2885 + } 2861 2886 } 2862 2887 2863 2888
-1
drivers/usb/misc/idmouse.c
··· 366 366 kmalloc(IMGSIZE + dev->bulk_in_size, GFP_KERNEL); 367 367 368 368 if (!dev->bulk_in_buffer) { 369 - dev_err(&interface->dev, "Unable to allocate input buffer.\n"); 370 369 idmouse_delete(dev); 371 370 return -ENOMEM; 372 371 }
+7 -19
drivers/usb/misc/iowarrior.c
··· 278 278 dev = file->private_data; 279 279 280 280 /* verify that the device wasn't unplugged */ 281 - if (dev == NULL || !dev->present) 281 + if (!dev || !dev->present) 282 282 return -ENODEV; 283 283 284 284 dev_dbg(&dev->interface->dev, "minor %d, count = %zd\n", ··· 413 413 int_out_urb = usb_alloc_urb(0, GFP_KERNEL); 414 414 if (!int_out_urb) { 415 415 retval = -ENOMEM; 416 - dev_dbg(&dev->interface->dev, 417 - "Unable to allocate urb\n"); 418 416 goto error_no_urb; 419 417 } 420 418 buf = usb_alloc_coherent(dev->udev, dev->report_size, ··· 480 482 int io_res; /* checks for bytes read/written and copy_to/from_user results */ 481 483 482 484 dev = file->private_data; 483 - if (dev == NULL) { 485 + if (!dev) 484 486 return -ENODEV; 485 - } 486 487 487 488 buffer = kzalloc(dev->report_size, GFP_KERNEL); 488 489 if (!buffer) ··· 651 654 int retval = 0; 652 655 653 656 dev = file->private_data; 654 - if (dev == NULL) { 657 + if (!dev) 655 658 return -ENODEV; 656 - } 657 659 658 660 dev_dbg(&dev->interface->dev, "minor %d\n", dev->minor); 659 661 ··· 762 766 763 767 /* allocate memory for our device state and initialize it */ 764 768 dev = kzalloc(sizeof(struct iowarrior), GFP_KERNEL); 765 - if (dev == NULL) { 766 - dev_err(&interface->dev, "Out of memory\n"); 769 + if (!dev) 767 770 return retval; 768 - } 769 771 770 772 mutex_init(&dev->mutex); 771 773 ··· 806 812 807 813 /* create the urb and buffer for reading */ 808 814 dev->int_in_urb = usb_alloc_urb(0, GFP_KERNEL); 809 - if (!dev->int_in_urb) { 810 - dev_err(&interface->dev, "Couldn't allocate interrupt_in_urb\n"); 815 + if (!dev->int_in_urb) 811 816 goto error; 812 - } 813 817 dev->int_in_buffer = kmalloc(dev->report_size, GFP_KERNEL); 814 - if (!dev->int_in_buffer) { 815 - dev_err(&interface->dev, "Couldn't allocate int_in_buffer\n"); 818 + if (!dev->int_in_buffer) 816 819 goto error; 817 - } 818 820 usb_fill_int_urb(dev->int_in_urb, dev->udev, 819 821 usb_rcvintpipe(dev->udev, 820 822 dev->int_in_endpoint->bEndpointAddress), ··· 821 831 dev->read_queue = 822 832 kmalloc(((dev->report_size + 1) * MAX_INTERRUPT_BUFFER), 823 833 GFP_KERNEL); 824 - if (!dev->read_queue) { 825 - dev_err(&interface->dev, "Couldn't allocate read_queue\n"); 834 + if (!dev->read_queue) 826 835 goto error; 827 - } 828 836 /* Get the serial-number of the chip */ 829 837 memset(dev->chip_serial, 0x00, sizeof(dev->chip_serial)); 830 838 usb_string(udev, udev->descriptor.iSerialNumber, dev->chip_serial,
+7 -21
drivers/usb/misc/ldusb.c
··· 658 658 /* allocate memory for our device state and initialize it */ 659 659 660 660 dev = kzalloc(sizeof(*dev), GFP_KERNEL); 661 - if (dev == NULL) { 662 - dev_err(&intf->dev, "Out of memory\n"); 661 + if (!dev) 663 662 goto exit; 664 - } 665 663 mutex_init(&dev->mutex); 666 664 spin_lock_init(&dev->rbsl); 667 665 dev->intf = intf; ··· 672 674 (le16_to_cpu(udev->descriptor.idProduct) == USB_DEVICE_ID_LD_COM3LAB)) && 673 675 (le16_to_cpu(udev->descriptor.bcdDevice) <= 0x103)) { 674 676 buffer = kmalloc(256, GFP_KERNEL); 675 - if (buffer == NULL) { 676 - dev_err(&intf->dev, "Couldn't allocate string buffer\n"); 677 + if (!buffer) 677 678 goto error; 678 - } 679 679 /* usb_string makes SETUP+STALL to leave always ControlReadLoop */ 680 680 usb_string(udev, 255, buffer, 256); 681 681 kfree(buffer); ··· 700 704 701 705 dev->interrupt_in_endpoint_size = usb_endpoint_maxp(dev->interrupt_in_endpoint); 702 706 dev->ring_buffer = kmalloc(ring_buffer_size*(sizeof(size_t)+dev->interrupt_in_endpoint_size), GFP_KERNEL); 703 - if (!dev->ring_buffer) { 704 - dev_err(&intf->dev, "Couldn't allocate ring_buffer\n"); 707 + if (!dev->ring_buffer) 705 708 goto error; 706 - } 707 709 dev->interrupt_in_buffer = kmalloc(dev->interrupt_in_endpoint_size, GFP_KERNEL); 708 - if (!dev->interrupt_in_buffer) { 709 - dev_err(&intf->dev, "Couldn't allocate interrupt_in_buffer\n"); 710 + if (!dev->interrupt_in_buffer) 710 711 goto error; 711 - } 712 712 dev->interrupt_in_urb = usb_alloc_urb(0, GFP_KERNEL); 713 - if (!dev->interrupt_in_urb) { 714 - dev_err(&intf->dev, "Couldn't allocate interrupt_in_urb\n"); 713 + if (!dev->interrupt_in_urb) 715 714 goto error; 716 - } 717 715 dev->interrupt_out_endpoint_size = dev->interrupt_out_endpoint ? usb_endpoint_maxp(dev->interrupt_out_endpoint) : 718 716 udev->descriptor.bMaxPacketSize0; 719 717 dev->interrupt_out_buffer = kmalloc(write_buffer_size*dev->interrupt_out_endpoint_size, GFP_KERNEL); 720 - if (!dev->interrupt_out_buffer) { 721 - dev_err(&intf->dev, "Couldn't allocate interrupt_out_buffer\n"); 718 + if (!dev->interrupt_out_buffer) 722 719 goto error; 723 - } 724 720 dev->interrupt_out_urb = usb_alloc_urb(0, GFP_KERNEL); 725 - if (!dev->interrupt_out_urb) { 726 - dev_err(&intf->dev, "Couldn't allocate interrupt_out_urb\n"); 721 + if (!dev->interrupt_out_urb) 727 722 goto error; 728 - } 729 723 dev->interrupt_in_interval = min_interrupt_in_interval > dev->interrupt_in_endpoint->bInterval ? min_interrupt_in_interval : dev->interrupt_in_endpoint->bInterval; 730 724 if (dev->interrupt_out_endpoint) 731 725 dev->interrupt_out_interval = min_interrupt_out_interval > dev->interrupt_out_endpoint->bInterval ? min_interrupt_out_interval : dev->interrupt_out_endpoint->bInterval;
+23 -36
drivers/usb/misc/legousbtower.c
··· 817 817 818 818 dev = kmalloc (sizeof(struct lego_usb_tower), GFP_KERNEL); 819 819 820 - if (dev == NULL) { 821 - dev_err(idev, "Out of memory\n"); 820 + if (!dev) 822 821 goto exit; 823 - } 824 822 825 823 mutex_init(&dev->lock); 826 824 ··· 869 871 } 870 872 871 873 dev->read_buffer = kmalloc (read_buffer_size, GFP_KERNEL); 872 - if (!dev->read_buffer) { 873 - dev_err(idev, "Couldn't allocate read_buffer\n"); 874 + if (!dev->read_buffer) 874 875 goto error; 875 - } 876 876 dev->interrupt_in_buffer = kmalloc (usb_endpoint_maxp(dev->interrupt_in_endpoint), GFP_KERNEL); 877 - if (!dev->interrupt_in_buffer) { 878 - dev_err(idev, "Couldn't allocate interrupt_in_buffer\n"); 877 + if (!dev->interrupt_in_buffer) 879 878 goto error; 880 - } 881 879 dev->interrupt_in_urb = usb_alloc_urb(0, GFP_KERNEL); 882 - if (!dev->interrupt_in_urb) { 883 - dev_err(idev, "Couldn't allocate interrupt_in_urb\n"); 880 + if (!dev->interrupt_in_urb) 884 881 goto error; 885 - } 886 882 dev->interrupt_out_buffer = kmalloc (write_buffer_size, GFP_KERNEL); 887 - if (!dev->interrupt_out_buffer) { 888 - dev_err(idev, "Couldn't allocate interrupt_out_buffer\n"); 883 + if (!dev->interrupt_out_buffer) 889 884 goto error; 890 - } 891 885 dev->interrupt_out_urb = usb_alloc_urb(0, GFP_KERNEL); 892 - if (!dev->interrupt_out_urb) { 893 - dev_err(idev, "Couldn't allocate interrupt_out_urb\n"); 886 + if (!dev->interrupt_out_urb) 894 887 goto error; 895 - } 896 888 dev->interrupt_in_interval = interrupt_in_interval ? interrupt_in_interval : dev->interrupt_in_endpoint->bInterval; 897 889 dev->interrupt_out_interval = interrupt_out_interval ? interrupt_out_interval : dev->interrupt_out_endpoint->bInterval; 898 - 899 - /* we can register the device now, as it is ready */ 900 - usb_set_intfdata (interface, dev); 901 - 902 - retval = usb_register_dev (interface, &tower_class); 903 - 904 - if (retval) { 905 - /* something prevented us from registering this driver */ 906 - dev_err(idev, "Not able to get a minor for this device.\n"); 907 - usb_set_intfdata (interface, NULL); 908 - goto error; 909 - } 910 - dev->minor = interface->minor; 911 - 912 - /* let the user know what node this device is now attached to */ 913 - dev_info(&interface->dev, "LEGO USB Tower #%d now attached to major " 914 - "%d minor %d\n", (dev->minor - LEGO_USB_TOWER_MINOR_BASE), 915 - USB_MAJOR, dev->minor); 916 890 917 891 /* get the firmware version and log it */ 918 892 result = usb_control_msg (udev, ··· 906 936 get_version_reply.minor, 907 937 le16_to_cpu(get_version_reply.build_no)); 908 938 939 + /* we can register the device now, as it is ready */ 940 + usb_set_intfdata (interface, dev); 941 + 942 + retval = usb_register_dev (interface, &tower_class); 943 + 944 + if (retval) { 945 + /* something prevented us from registering this driver */ 946 + dev_err(idev, "Not able to get a minor for this device.\n"); 947 + usb_set_intfdata (interface, NULL); 948 + goto error; 949 + } 950 + dev->minor = interface->minor; 951 + 952 + /* let the user know what node this device is now attached to */ 953 + dev_info(&interface->dev, "LEGO USB Tower #%d now attached to major " 954 + "%d minor %d\n", (dev->minor - LEGO_USB_TOWER_MINOR_BASE), 955 + USB_MAJOR, dev->minor); 909 956 910 957 exit: 911 958 return retval;
+5 -20
drivers/usb/misc/lvstest.c
··· 34 34 struct usb_hub_descriptor descriptor; 35 35 /* urb for polling interrupt pipe */ 36 36 struct urb *urb; 37 - /* LVS RH work queue */ 38 - struct workqueue_struct *rh_queue; 39 37 /* LVH RH work */ 40 38 struct work_struct rh_work; 41 39 /* RH port status */ ··· 245 247 int ret; 246 248 247 249 descriptor = kmalloc(sizeof(*descriptor), GFP_KERNEL); 248 - if (!descriptor) { 249 - dev_err(dev, "failed to allocate descriptor memory\n"); 250 + if (!descriptor) 250 251 return -ENOMEM; 251 - } 252 252 253 253 udev = create_lvs_device(intf); 254 254 if (!udev) { ··· 351 355 { 352 356 struct lvs_rh *lvs = urb->context; 353 357 354 - queue_work(lvs->rh_queue, &lvs->rh_work); 358 + schedule_work(&lvs->rh_work); 355 359 } 356 360 357 361 static int lvs_rh_probe(struct usb_interface *intf, ··· 393 397 394 398 /* submit urb to poll interrupt endpoint */ 395 399 lvs->urb = usb_alloc_urb(0, GFP_KERNEL); 396 - if (!lvs->urb) { 397 - dev_err(&intf->dev, "couldn't allocate lvs urb\n"); 400 + if (!lvs->urb) 398 401 return -ENOMEM; 399 - } 400 - 401 - lvs->rh_queue = create_singlethread_workqueue("lvs_rh_queue"); 402 - if (!lvs->rh_queue) { 403 - dev_err(&intf->dev, "couldn't create workqueue\n"); 404 - ret = -ENOMEM; 405 - goto free_urb; 406 - } 407 402 408 403 INIT_WORK(&lvs->rh_work, lvs_rh_work); 409 404 410 405 ret = sysfs_create_group(&intf->dev.kobj, &lvs_attr_group); 411 406 if (ret < 0) { 412 407 dev_err(&intf->dev, "Failed to create sysfs node %d\n", ret); 413 - goto destroy_queue; 408 + goto free_urb; 414 409 } 415 410 416 411 pipe = usb_rcvintpipe(hdev, endpoint->bEndpointAddress); ··· 419 432 420 433 sysfs_remove: 421 434 sysfs_remove_group(&intf->dev.kobj, &lvs_attr_group); 422 - destroy_queue: 423 - destroy_workqueue(lvs->rh_queue); 424 435 free_urb: 425 436 usb_free_urb(lvs->urb); 426 437 return ret; ··· 429 444 struct lvs_rh *lvs = usb_get_intfdata(intf); 430 445 431 446 sysfs_remove_group(&intf->dev.kobj, &lvs_attr_group); 432 - destroy_workqueue(lvs->rh_queue); 447 + flush_work(&lvs->rh_work); 433 448 usb_free_urb(lvs->urb); 434 449 } 435 450
-3
drivers/usb/misc/sisusbvga/sisusb.c
··· 3084 3084 /* Allocate URBs */ 3085 3085 sisusb->sisurbin = usb_alloc_urb(0, GFP_KERNEL); 3086 3086 if (!sisusb->sisurbin) { 3087 - dev_err(&sisusb->sisusb_dev->dev, "Failed to allocate URBs\n"); 3088 3087 retval = -ENOMEM; 3089 3088 goto error_3; 3090 3089 } ··· 3092 3093 for (i = 0; i < sisusb->numobufs; i++) { 3093 3094 sisusb->sisurbout[i] = usb_alloc_urb(0, GFP_KERNEL); 3094 3095 if (!sisusb->sisurbout[i]) { 3095 - dev_err(&sisusb->sisusb_dev->dev, 3096 - "Failed to allocate URBs\n"); 3097 3096 retval = -ENOMEM; 3098 3097 goto error_4; 3099 3098 }
+1 -2
drivers/usb/misc/trancevibrator.c
··· 95 95 int retval; 96 96 97 97 dev = kzalloc(sizeof(struct trancevibrator), GFP_KERNEL); 98 - if (dev == NULL) { 99 - dev_err(&interface->dev, "Out of memory\n"); 98 + if (!dev) { 100 99 retval = -ENOMEM; 101 100 goto error; 102 101 }
+175
drivers/usb/misc/usb4604.c
··· 1 + /* 2 + * Driver for SMSC USB4604 USB HSIC 4-port 2.0 hub controller driver 3 + * Based on usb3503 driver 4 + * 5 + * Copyright (c) 2012-2013 Dongjin Kim (tobetter@gmail.com) 6 + * Copyright (c) 2016 Linaro Ltd. 7 + * 8 + * This program is free software; you can redistribute it and/or modify 9 + * it under the terms of the GNU General Public License as published by 10 + * the Free Software Foundation; either version 2 of the License, or 11 + * (at your option) any later version. 12 + * 13 + * This program is distributed in the hope that it will be useful, 14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 + * GNU General Public License for more details. 17 + */ 18 + 19 + #include <linux/i2c.h> 20 + #include <linux/delay.h> 21 + #include <linux/slab.h> 22 + #include <linux/module.h> 23 + #include <linux/gpio/consumer.h> 24 + 25 + enum usb4604_mode { 26 + USB4604_MODE_UNKNOWN, 27 + USB4604_MODE_HUB, 28 + USB4604_MODE_STANDBY, 29 + }; 30 + 31 + struct usb4604 { 32 + enum usb4604_mode mode; 33 + struct device *dev; 34 + struct gpio_desc *gpio_reset; 35 + }; 36 + 37 + static void usb4604_reset(struct usb4604 *hub, int state) 38 + { 39 + gpiod_set_value_cansleep(hub->gpio_reset, state); 40 + 41 + /* Wait for i2c logic to come up */ 42 + if (state) 43 + msleep(250); 44 + } 45 + 46 + static int usb4604_connect(struct usb4604 *hub) 47 + { 48 + struct device *dev = hub->dev; 49 + struct i2c_client *client = to_i2c_client(dev); 50 + int err; 51 + u8 connect_cmd[] = { 0xaa, 0x55, 0x00 }; 52 + 53 + usb4604_reset(hub, 1); 54 + 55 + err = i2c_master_send(client, connect_cmd, ARRAY_SIZE(connect_cmd)); 56 + if (err < 0) { 57 + usb4604_reset(hub, 0); 58 + return err; 59 + } 60 + 61 + hub->mode = USB4604_MODE_HUB; 62 + dev_dbg(dev, "switched to HUB mode\n"); 63 + 64 + return 0; 65 + } 66 + 67 + static int usb4604_switch_mode(struct usb4604 *hub, enum usb4604_mode mode) 68 + { 69 + struct device *dev = hub->dev; 70 + int err = 0; 71 + 72 + switch (mode) { 73 + case USB4604_MODE_HUB: 74 + err = usb4604_connect(hub); 75 + break; 76 + 77 + case USB4604_MODE_STANDBY: 78 + usb4604_reset(hub, 0); 79 + dev_dbg(dev, "switched to STANDBY mode\n"); 80 + break; 81 + 82 + default: 83 + dev_err(dev, "unknown mode is requested\n"); 84 + err = -EINVAL; 85 + break; 86 + } 87 + 88 + return err; 89 + } 90 + 91 + static int usb4604_probe(struct usb4604 *hub) 92 + { 93 + struct device *dev = hub->dev; 94 + struct device_node *np = dev->of_node; 95 + struct gpio_desc *gpio; 96 + u32 mode = USB4604_MODE_HUB; 97 + 98 + gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW); 99 + if (IS_ERR(gpio)) 100 + return PTR_ERR(gpio); 101 + hub->gpio_reset = gpio; 102 + 103 + if (of_property_read_u32(np, "initial-mode", &hub->mode)) 104 + hub->mode = mode; 105 + 106 + return usb4604_switch_mode(hub, hub->mode); 107 + } 108 + 109 + static int usb4604_i2c_probe(struct i2c_client *i2c, 110 + const struct i2c_device_id *id) 111 + { 112 + struct usb4604 *hub; 113 + 114 + hub = devm_kzalloc(&i2c->dev, sizeof(*hub), GFP_KERNEL); 115 + if (!hub) 116 + return -ENOMEM; 117 + 118 + i2c_set_clientdata(i2c, hub); 119 + hub->dev = &i2c->dev; 120 + 121 + return usb4604_probe(hub); 122 + } 123 + 124 + #ifdef CONFIG_PM_SLEEP 125 + static int usb4604_i2c_suspend(struct device *dev) 126 + { 127 + struct i2c_client *client = to_i2c_client(dev); 128 + struct usb4604 *hub = i2c_get_clientdata(client); 129 + 130 + usb4604_switch_mode(hub, USB4604_MODE_STANDBY); 131 + 132 + return 0; 133 + } 134 + 135 + static int usb4604_i2c_resume(struct device *dev) 136 + { 137 + struct i2c_client *client = to_i2c_client(dev); 138 + struct usb4604 *hub = i2c_get_clientdata(client); 139 + 140 + usb4604_switch_mode(hub, hub->mode); 141 + 142 + return 0; 143 + } 144 + #endif 145 + 146 + static SIMPLE_DEV_PM_OPS(usb4604_i2c_pm_ops, usb4604_i2c_suspend, 147 + usb4604_i2c_resume); 148 + 149 + static const struct i2c_device_id usb4604_id[] = { 150 + { "usb4604", 0 }, 151 + { } 152 + }; 153 + MODULE_DEVICE_TABLE(i2c, usb4604_id); 154 + 155 + #ifdef CONFIG_OF 156 + static const struct of_device_id usb4604_of_match[] = { 157 + { .compatible = "smsc,usb4604" }, 158 + {} 159 + }; 160 + MODULE_DEVICE_TABLE(of, usb4604_of_match); 161 + #endif 162 + 163 + static struct i2c_driver usb4604_i2c_driver = { 164 + .driver = { 165 + .name = "usb4604", 166 + .pm = &usb4604_i2c_pm_ops, 167 + .of_match_table = of_match_ptr(usb4604_of_match), 168 + }, 169 + .probe = usb4604_i2c_probe, 170 + .id_table = usb4604_id, 171 + }; 172 + module_i2c_driver(usb4604_i2c_driver); 173 + 174 + MODULE_DESCRIPTION("USB4604 USB HUB driver"); 175 + MODULE_LICENSE("GPL v2");
+2 -7
drivers/usb/misc/usblcd.c
··· 321 321 322 322 /* allocate memory for our device state and initialize it */ 323 323 dev = kzalloc(sizeof(*dev), GFP_KERNEL); 324 - if (dev == NULL) { 325 - dev_err(&interface->dev, "Out of memory\n"); 324 + if (!dev) 326 325 goto error; 327 - } 328 326 kref_init(&dev->kref); 329 327 sema_init(&dev->limit_sem, USB_LCD_CONCURRENT_WRITES); 330 328 init_usb_anchor(&dev->submitted); ··· 349 351 dev->bulk_in_size = buffer_size; 350 352 dev->bulk_in_endpointAddr = endpoint->bEndpointAddress; 351 353 dev->bulk_in_buffer = kmalloc(buffer_size, GFP_KERNEL); 352 - if (!dev->bulk_in_buffer) { 353 - dev_err(&interface->dev, 354 - "Could not allocate bulk_in_buffer\n"); 354 + if (!dev->bulk_in_buffer) 355 355 goto error; 356 - } 357 356 } 358 357 359 358 if (!dev->bulk_out_endpointAddr &&
+2 -6
drivers/usb/misc/usbsevseg.c
··· 128 128 return; 129 129 130 130 buffer = kzalloc(MAXLEN, mf); 131 - if (!buffer) { 132 - dev_err(&mydev->udev->dev, "out of memory\n"); 131 + if (!buffer) 133 132 return; 134 - } 135 133 136 134 /* The device is right to left, where as you write left to right */ 137 135 for (i = 0; i < mydev->textlength; i++) ··· 344 346 int rc = -ENOMEM; 345 347 346 348 mydev = kzalloc(sizeof(struct usb_sevsegdev), GFP_KERNEL); 347 - if (mydev == NULL) { 348 - dev_err(&interface->dev, "Out of memory\n"); 349 + if (!mydev) 349 350 goto error_mem; 350 - } 351 351 352 352 mydev->udev = usb_get_dev(udev); 353 353 mydev->intf = interface;
+1 -4
drivers/usb/misc/uss720.c
··· 150 150 if (!usbdev) 151 151 return NULL; 152 152 rq = kzalloc(sizeof(struct uss720_async_request), mem_flags); 153 - if (!rq) { 154 - dev_err(&usbdev->dev, "submit_async_request out of memory\n"); 153 + if (!rq) 155 154 return NULL; 156 - } 157 155 kref_init(&rq->ref_count); 158 156 INIT_LIST_HEAD(&rq->asynclist); 159 157 init_completion(&rq->compl); ··· 160 162 rq->urb = usb_alloc_urb(0, mem_flags); 161 163 if (!rq->urb) { 162 164 kref_put(&rq->ref_count, destroy_async); 163 - dev_err(&usbdev->dev, "submit_async_request out of memory\n"); 164 165 return NULL; 165 166 } 166 167 rq->dr = kmalloc(sizeof(*rq->dr), mem_flags);
+4 -12
drivers/usb/misc/yurex.c
··· 200 200 201 201 /* allocate memory for our device state and initialize it */ 202 202 dev = kzalloc(sizeof(*dev), GFP_KERNEL); 203 - if (!dev) { 204 - dev_err(&interface->dev, "Out of memory\n"); 203 + if (!dev) 205 204 goto error; 206 - } 207 205 kref_init(&dev->kref); 208 206 mutex_init(&dev->io_mutex); 209 207 spin_lock_init(&dev->lock); ··· 229 231 230 232 /* allocate control URB */ 231 233 dev->cntl_urb = usb_alloc_urb(0, GFP_KERNEL); 232 - if (!dev->cntl_urb) { 233 - dev_err(&interface->dev, "Could not allocate control URB\n"); 234 + if (!dev->cntl_urb) 234 235 goto error; 235 - } 236 236 237 237 /* allocate buffer for control req */ 238 238 dev->cntl_req = kmalloc(YUREX_BUF_SIZE, GFP_KERNEL); 239 - if (!dev->cntl_req) { 240 - dev_err(&interface->dev, "Could not allocate cntl_req\n"); 239 + if (!dev->cntl_req) 241 240 goto error; 242 - } 243 241 244 242 /* allocate buffer for control msg */ 245 243 dev->cntl_buffer = usb_alloc_coherent(dev->udev, YUREX_BUF_SIZE, ··· 263 269 264 270 /* allocate interrupt URB */ 265 271 dev->urb = usb_alloc_urb(0, GFP_KERNEL); 266 - if (!dev->urb) { 267 - dev_err(&interface->dev, "Could not allocate URB\n"); 272 + if (!dev->urb) 268 273 goto error; 269 - } 270 274 271 275 /* allocate buffer for interrupt in */ 272 276 dev->int_buffer = usb_alloc_coherent(dev->udev, YUREX_BUF_SIZE,
+1 -1
drivers/usb/musb/Kconfig
··· 82 82 tristate "DA8xx/OMAP-L1x" 83 83 depends on ARCH_DAVINCI_DA8XX 84 84 depends on NOP_USB_XCEIV 85 - depends on BROKEN 85 + select PHY_DA8XX_USB 86 86 87 87 config USB_MUSB_TUSB6010 88 88 tristate "TUSB6010"
+4 -4
drivers/usb/musb/am35x.c
··· 474 474 int ret = -ENOMEM; 475 475 476 476 glue = kzalloc(sizeof(*glue), GFP_KERNEL); 477 - if (!glue) { 478 - dev_err(&pdev->dev, "failed to allocate glue context\n"); 477 + if (!glue) 479 478 goto err0; 480 - } 481 479 482 480 phy_clk = clk_get(&pdev->dev, "fck"); 483 481 if (IS_ERR(phy_clk)) { ··· 510 512 pdata->platform_ops = &am35x_ops; 511 513 512 514 glue->phy = usb_phy_generic_register(); 513 - if (IS_ERR(glue->phy)) 515 + if (IS_ERR(glue->phy)) { 516 + ret = PTR_ERR(glue->phy); 514 517 goto err7; 518 + } 515 519 platform_set_drvdata(pdev, glue); 516 520 517 521 pinfo = am35x_dev_info;
+59 -105
drivers/usb/musb/da8xx.c
··· 30 30 #include <linux/clk.h> 31 31 #include <linux/err.h> 32 32 #include <linux/io.h> 33 + #include <linux/phy/phy.h> 33 34 #include <linux/platform_device.h> 34 35 #include <linux/dma-mapping.h> 35 36 #include <linux/usb/usb_phy_generic.h> 36 - 37 - #include <mach/da8xx.h> 38 - #include <linux/platform_data/usb-davinci.h> 39 37 40 38 #include "musb_core.h" 41 39 ··· 78 80 79 81 #define DA8XX_MENTOR_CORE_OFFSET 0x400 80 82 81 - #define CFGCHIP2 IO_ADDRESS(DA8XX_SYSCFG0_BASE + DA8XX_CFGCHIP2_REG) 82 - 83 83 struct da8xx_glue { 84 84 struct device *dev; 85 85 struct platform_device *musb; 86 - struct platform_device *phy; 86 + struct platform_device *usb_phy; 87 87 struct clk *clk; 88 + struct phy *phy; 88 89 }; 89 - 90 - /* 91 - * REVISIT (PM): we should be able to keep the PHY in low power mode most 92 - * of the time (24 MHz oscillator and PLL off, etc.) by setting POWER.D0 93 - * and, when in host mode, autosuspending idle root ports... PHY_PLLON 94 - * (overriding SUSPENDM?) then likely needs to stay off. 95 - */ 96 - 97 - static inline void phy_on(void) 98 - { 99 - u32 cfgchip2 = __raw_readl(CFGCHIP2); 100 - 101 - /* 102 - * Start the on-chip PHY and its PLL. 103 - */ 104 - cfgchip2 &= ~(CFGCHIP2_RESET | CFGCHIP2_PHYPWRDN | CFGCHIP2_OTGPWRDN); 105 - cfgchip2 |= CFGCHIP2_PHY_PLLON; 106 - __raw_writel(cfgchip2, CFGCHIP2); 107 - 108 - pr_info("Waiting for USB PHY clock good...\n"); 109 - while (!(__raw_readl(CFGCHIP2) & CFGCHIP2_PHYCLKGD)) 110 - cpu_relax(); 111 - } 112 - 113 - static inline void phy_off(void) 114 - { 115 - u32 cfgchip2 = __raw_readl(CFGCHIP2); 116 - 117 - /* 118 - * Ensure that USB 1.1 reference clock is not being sourced from 119 - * USB 2.0 PHY. Otherwise do not power down the PHY. 120 - */ 121 - if (!(cfgchip2 & CFGCHIP2_USB1PHYCLKMUX) && 122 - (cfgchip2 & CFGCHIP2_USB1SUSPENDM)) { 123 - pr_warning("USB 1.1 clocked from USB 2.0 PHY -- " 124 - "can't power it down\n"); 125 - return; 126 - } 127 - 128 - /* 129 - * Power down the on-chip PHY. 130 - */ 131 - cfgchip2 |= CFGCHIP2_PHYPWRDN | CFGCHIP2_OTGPWRDN; 132 - __raw_writel(cfgchip2, CFGCHIP2); 133 - } 134 90 135 91 /* 136 92 * Because we don't set CTRL.UINT, it's "important" to: ··· 337 385 338 386 static int da8xx_musb_set_mode(struct musb *musb, u8 musb_mode) 339 387 { 340 - u32 cfgchip2 = __raw_readl(CFGCHIP2); 388 + struct da8xx_glue *glue = dev_get_drvdata(musb->controller->parent); 389 + enum phy_mode phy_mode; 341 390 342 - cfgchip2 &= ~CFGCHIP2_OTGMODE; 343 391 switch (musb_mode) { 344 392 case MUSB_HOST: /* Force VBUS valid, ID = 0 */ 345 - cfgchip2 |= CFGCHIP2_FORCE_HOST; 393 + phy_mode = PHY_MODE_USB_HOST; 346 394 break; 347 395 case MUSB_PERIPHERAL: /* Force VBUS valid, ID = 1 */ 348 - cfgchip2 |= CFGCHIP2_FORCE_DEVICE; 396 + phy_mode = PHY_MODE_USB_DEVICE; 349 397 break; 350 398 case MUSB_OTG: /* Don't override the VBUS/ID comparators */ 351 - cfgchip2 |= CFGCHIP2_NO_OVERRIDE; 399 + phy_mode = PHY_MODE_USB_OTG; 352 400 break; 353 401 default: 354 - dev_dbg(musb->controller, "Trying to set unsupported mode %u\n", musb_mode); 402 + return -EINVAL; 355 403 } 356 404 357 - __raw_writel(cfgchip2, CFGCHIP2); 358 - return 0; 405 + return phy_set_mode(glue->phy, phy_mode); 359 406 } 360 407 361 408 static int da8xx_musb_init(struct musb *musb) 362 409 { 410 + struct da8xx_glue *glue = dev_get_drvdata(musb->controller->parent); 363 411 void __iomem *reg_base = musb->ctrl_base; 364 412 u32 rev; 365 413 int ret = -ENODEV; ··· 377 425 goto fail; 378 426 } 379 427 428 + ret = clk_prepare_enable(glue->clk); 429 + if (ret) { 430 + dev_err(glue->dev, "failed to enable clock\n"); 431 + goto fail; 432 + } 433 + 380 434 setup_timer(&otg_workaround, otg_timer, (unsigned long)musb); 381 435 382 436 /* Reset the controller */ 383 437 musb_writel(reg_base, DA8XX_USB_CTRL_REG, DA8XX_SOFT_RESET_MASK); 384 438 385 439 /* Start the on-chip PHY and its PLL. */ 386 - phy_on(); 440 + ret = phy_init(glue->phy); 441 + if (ret) { 442 + dev_err(glue->dev, "Failed to init phy.\n"); 443 + goto err_phy_init; 444 + } 445 + 446 + ret = phy_power_on(glue->phy); 447 + if (ret) { 448 + dev_err(glue->dev, "Failed to power on phy.\n"); 449 + goto err_phy_power_on; 450 + } 387 451 388 452 msleep(5); 389 453 390 454 /* NOTE: IRQs are in mixed mode, not bypass to pure MUSB */ 391 - pr_debug("DA8xx OTG revision %08x, PHY %03x, control %02x\n", 392 - rev, __raw_readl(CFGCHIP2), 455 + pr_debug("DA8xx OTG revision %08x, control %02x\n", rev, 393 456 musb_readb(reg_base, DA8XX_USB_CTRL_REG)); 394 457 395 458 musb->isr = da8xx_musb_interrupt; 396 459 return 0; 460 + 461 + err_phy_power_on: 462 + phy_exit(glue->phy); 463 + err_phy_init: 464 + clk_disable_unprepare(glue->clk); 397 465 fail: 398 466 return ret; 399 467 } 400 468 401 469 static int da8xx_musb_exit(struct musb *musb) 402 470 { 471 + struct da8xx_glue *glue = dev_get_drvdata(musb->controller->parent); 472 + 403 473 del_timer_sync(&otg_workaround); 404 474 405 - phy_off(); 475 + phy_power_off(glue->phy); 476 + phy_exit(glue->phy); 477 + clk_disable_unprepare(glue->clk); 406 478 407 479 usb_put_phy(musb->xceiv); 408 480 ··· 462 486 { 463 487 struct resource musb_resources[2]; 464 488 struct musb_hdrc_platform_data *pdata = dev_get_platdata(&pdev->dev); 465 - struct platform_device *musb; 466 489 struct da8xx_glue *glue; 467 490 struct platform_device_info pinfo; 468 491 struct clk *clk; 492 + int ret; 469 493 470 - int ret = -ENOMEM; 494 + glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL); 495 + if (!glue) 496 + return -ENOMEM; 471 497 472 - glue = kzalloc(sizeof(*glue), GFP_KERNEL); 473 - if (!glue) { 474 - dev_err(&pdev->dev, "failed to allocate glue context\n"); 475 - goto err0; 476 - } 477 - 478 - clk = clk_get(&pdev->dev, "usb20"); 498 + clk = devm_clk_get(&pdev->dev, "usb20"); 479 499 if (IS_ERR(clk)) { 480 500 dev_err(&pdev->dev, "failed to get clock\n"); 481 - ret = PTR_ERR(clk); 482 - goto err3; 501 + return PTR_ERR(clk); 483 502 } 484 503 485 - ret = clk_enable(clk); 486 - if (ret) { 487 - dev_err(&pdev->dev, "failed to enable clock\n"); 488 - goto err4; 504 + glue->phy = devm_phy_get(&pdev->dev, "usb-phy"); 505 + if (IS_ERR(glue->phy)) { 506 + dev_err(&pdev->dev, "failed to get phy\n"); 507 + return PTR_ERR(glue->phy); 489 508 } 490 509 491 510 glue->dev = &pdev->dev; ··· 488 517 489 518 pdata->platform_ops = &da8xx_ops; 490 519 491 - glue->phy = usb_phy_generic_register(); 492 - if (IS_ERR(glue->phy)) { 493 - ret = PTR_ERR(glue->phy); 494 - goto err5; 520 + glue->usb_phy = usb_phy_generic_register(); 521 + ret = PTR_ERR_OR_ZERO(glue->usb_phy); 522 + if (ret) { 523 + dev_err(&pdev->dev, "failed to register usb_phy\n"); 524 + return ret; 495 525 } 496 526 platform_set_drvdata(pdev, glue); 497 527 ··· 516 544 pinfo.data = pdata; 517 545 pinfo.size_data = sizeof(*pdata); 518 546 519 - glue->musb = musb = platform_device_register_full(&pinfo); 520 - if (IS_ERR(musb)) { 521 - ret = PTR_ERR(musb); 547 + glue->musb = platform_device_register_full(&pinfo); 548 + ret = PTR_ERR_OR_ZERO(glue->musb); 549 + if (ret) { 522 550 dev_err(&pdev->dev, "failed to register musb device: %d\n", ret); 523 - goto err6; 551 + usb_phy_generic_unregister(glue->usb_phy); 524 552 } 525 553 526 - return 0; 527 - 528 - err6: 529 - usb_phy_generic_unregister(glue->phy); 530 - 531 - err5: 532 - clk_disable(clk); 533 - 534 - err4: 535 - clk_put(clk); 536 - 537 - err3: 538 - kfree(glue); 539 - 540 - err0: 541 554 return ret; 542 555 } 543 556 ··· 531 574 struct da8xx_glue *glue = platform_get_drvdata(pdev); 532 575 533 576 platform_device_unregister(glue->musb); 534 - usb_phy_generic_unregister(glue->phy); 535 - clk_disable(glue->clk); 536 - clk_put(glue->clk); 537 - kfree(glue); 577 + usb_phy_generic_unregister(glue->usb_phy); 538 578 539 579 return 0; 540 580 }
+74 -7
drivers/usb/musb/musb_core.c
··· 1448 1448 { 1449 1449 u8 reg; 1450 1450 char *type; 1451 - char aInfo[90], aRevision[32], aDate[12]; 1451 + char aInfo[90]; 1452 1452 void __iomem *mbase = musb->mregs; 1453 1453 int status = 0; 1454 1454 int i; ··· 1482 1482 1483 1483 pr_debug("%s: ConfigData=0x%02x (%s)\n", musb_driver_name, reg, aInfo); 1484 1484 1485 - aDate[0] = 0; 1486 1485 if (MUSB_CONTROLLER_MHDRC == musb_type) { 1487 1486 musb->is_multipoint = 1; 1488 1487 type = "M"; ··· 1496 1497 1497 1498 /* log release info */ 1498 1499 musb->hwvers = musb_read_hwvers(mbase); 1499 - snprintf(aRevision, 32, "%d.%d%s", MUSB_HWVERS_MAJOR(musb->hwvers), 1500 - MUSB_HWVERS_MINOR(musb->hwvers), 1501 - (musb->hwvers & MUSB_HWVERS_RC) ? "RC" : ""); 1502 - pr_debug("%s: %sHDRC RTL version %s %s\n", 1503 - musb_driver_name, type, aRevision, aDate); 1500 + pr_debug("%s: %sHDRC RTL version %d.%d%s\n", 1501 + musb_driver_name, type, MUSB_HWVERS_MAJOR(musb->hwvers), 1502 + MUSB_HWVERS_MINOR(musb->hwvers), 1503 + (musb->hwvers & MUSB_HWVERS_RC) ? "RC" : ""); 1504 1504 1505 1505 /* configure ep0 */ 1506 1506 musb_configure_ep0(musb); ··· 1829 1831 .attrs = musb_attributes, 1830 1832 }; 1831 1833 1834 + #define MUSB_QUIRK_B_INVALID_VBUS_91 (MUSB_DEVCTL_BDEVICE | \ 1835 + (2 << MUSB_DEVCTL_VBUS_SHIFT) | \ 1836 + MUSB_DEVCTL_SESSION) 1837 + #define MUSB_QUIRK_A_DISCONNECT_19 ((3 << MUSB_DEVCTL_VBUS_SHIFT) | \ 1838 + MUSB_DEVCTL_SESSION) 1839 + 1840 + /* 1841 + * Check the musb devctl session bit to determine if we want to 1842 + * allow PM runtime for the device. In general, we want to keep things 1843 + * active when the session bit is set except after host disconnect. 1844 + * 1845 + * Only called from musb_irq_work. If this ever needs to get called 1846 + * elsewhere, proper locking must be implemented for musb->session. 1847 + */ 1848 + static void musb_pm_runtime_check_session(struct musb *musb) 1849 + { 1850 + u8 devctl, s; 1851 + int error; 1852 + 1853 + devctl = musb_readb(musb->mregs, MUSB_DEVCTL); 1854 + 1855 + /* Handle session status quirks first */ 1856 + s = MUSB_DEVCTL_FSDEV | MUSB_DEVCTL_LSDEV | 1857 + MUSB_DEVCTL_HR; 1858 + switch (devctl & ~s) { 1859 + case MUSB_QUIRK_B_INVALID_VBUS_91: 1860 + if (!musb->session && !musb->quirk_invalid_vbus) { 1861 + musb->quirk_invalid_vbus = true; 1862 + musb_dbg(musb, 1863 + "First invalid vbus, assume no session"); 1864 + return; 1865 + } 1866 + break; 1867 + case MUSB_QUIRK_A_DISCONNECT_19: 1868 + if (!musb->session) 1869 + break; 1870 + musb_dbg(musb, "Allow PM on possible host mode disconnect"); 1871 + pm_runtime_mark_last_busy(musb->controller); 1872 + pm_runtime_put_autosuspend(musb->controller); 1873 + musb->session = false; 1874 + return; 1875 + default: 1876 + break; 1877 + } 1878 + 1879 + /* No need to do anything if session has not changed */ 1880 + s = devctl & MUSB_DEVCTL_SESSION; 1881 + if (s == musb->session) 1882 + return; 1883 + 1884 + /* Block PM or allow PM? */ 1885 + if (s) { 1886 + musb_dbg(musb, "Block PM on active session: %02x", devctl); 1887 + error = pm_runtime_get_sync(musb->controller); 1888 + if (error < 0) 1889 + dev_err(musb->controller, "Could not enable: %i\n", 1890 + error); 1891 + } else { 1892 + musb_dbg(musb, "Allow PM with no session: %02x", devctl); 1893 + musb->quirk_invalid_vbus = false; 1894 + pm_runtime_mark_last_busy(musb->controller); 1895 + pm_runtime_put_autosuspend(musb->controller); 1896 + } 1897 + 1898 + musb->session = s; 1899 + } 1900 + 1832 1901 /* Only used to provide driver mode change events */ 1833 1902 static void musb_irq_work(struct work_struct *data) 1834 1903 { 1835 1904 struct musb *musb = container_of(data, struct musb, irq_work); 1905 + 1906 + musb_pm_runtime_check_session(musb); 1836 1907 1837 1908 if (musb->xceiv->otg->state != musb->xceiv_old_state) { 1838 1909 musb->xceiv_old_state = musb->xceiv->otg->state;
+2
drivers/usb/musb/musb_core.h
··· 378 378 u8 min_power; /* vbus for periph, in mA/2 */ 379 379 380 380 int port_mode; /* MUSB_PORT_MODE_* */ 381 + bool session; 382 + bool quirk_invalid_vbus; 381 383 bool is_host; 382 384 383 385 int a_wait_bcon; /* VBUS timeout in msecs */
+35 -45
drivers/usb/musb/musb_dsps.c
··· 145 145 { "mode", 0xe8 }, 146 146 }; 147 147 148 - static void dsps_musb_try_idle(struct musb *musb, unsigned long timeout) 149 - { 150 - struct device *dev = musb->controller; 151 - struct dsps_glue *glue = dev_get_drvdata(dev->parent); 152 - 153 - if (timeout == 0) 154 - timeout = jiffies + msecs_to_jiffies(3); 155 - 156 - /* Never idle if active, or when VBUS timeout is not set as host */ 157 - if (musb->is_active || (musb->a_wait_bcon == 0 && 158 - musb->xceiv->otg->state == OTG_STATE_A_WAIT_BCON)) { 159 - dev_dbg(musb->controller, "%s active, deleting timer\n", 160 - usb_otg_state_string(musb->xceiv->otg->state)); 161 - del_timer(&glue->timer); 162 - glue->last_timer = jiffies; 163 - return; 164 - } 165 - if (musb->port_mode != MUSB_PORT_MODE_DUAL_ROLE) 166 - return; 167 - 168 - if (!musb->g.dev.driver) 169 - return; 170 - 171 - if (time_after(glue->last_timer, timeout) && 172 - timer_pending(&glue->timer)) { 173 - dev_dbg(musb->controller, 174 - "Longer idle timer already pending, ignoring...\n"); 175 - return; 176 - } 177 - glue->last_timer = timeout; 178 - 179 - dev_dbg(musb->controller, "%s inactive, starting idle timer for %u ms\n", 180 - usb_otg_state_string(musb->xceiv->otg->state), 181 - jiffies_to_msecs(timeout - jiffies)); 182 - mod_timer(&glue->timer, timeout); 183 - } 184 - 185 148 /** 186 149 * dsps_musb_enable - enable interrupts 187 150 */ ··· 169 206 musb->port_mode == MUSB_PORT_MODE_DUAL_ROLE) 170 207 mod_timer(&glue->timer, jiffies + 171 208 msecs_to_jiffies(wrp->poll_timeout)); 172 - dsps_musb_try_idle(musb, 0); 173 209 } 174 210 175 211 /** ··· 198 236 u8 devctl; 199 237 unsigned long flags; 200 238 int skip_session = 0; 239 + int err; 240 + 241 + err = pm_runtime_get_sync(dev); 242 + if (err < 0) 243 + dev_err(dev, "Poll could not pm_runtime_get: %i\n", err); 201 244 202 245 /* 203 246 * We poll because DSPS IP's won't expose several OTG-critical ··· 214 247 215 248 spin_lock_irqsave(&musb->lock, flags); 216 249 switch (musb->xceiv->otg->state) { 250 + case OTG_STATE_A_WAIT_VRISE: 251 + mod_timer(&glue->timer, jiffies + 252 + msecs_to_jiffies(wrp->poll_timeout)); 253 + break; 217 254 case OTG_STATE_A_WAIT_BCON: 218 255 musb_writeb(musb->mregs, MUSB_DEVCTL, 0); 219 256 skip_session = 1; ··· 246 275 break; 247 276 } 248 277 spin_unlock_irqrestore(&musb->lock, flags); 278 + 279 + pm_runtime_mark_last_busy(dev); 280 + pm_runtime_put_autosuspend(dev); 249 281 } 250 282 251 283 static irqreturn_t dsps_interrupt(int irq, void *hci) ··· 312 338 MUSB_HST_MODE(musb); 313 339 musb->xceiv->otg->default_a = 1; 314 340 musb->xceiv->otg->state = OTG_STATE_A_WAIT_VRISE; 315 - del_timer(&glue->timer); 341 + mod_timer(&glue->timer, jiffies + 342 + msecs_to_jiffies(wrp->poll_timeout)); 316 343 } else { 317 344 musb->is_active = 0; 318 345 MUSB_DEV_MODE(musb); ··· 333 358 if (musb->int_tx || musb->int_rx || musb->int_usb) 334 359 ret |= musb_interrupt(musb); 335 360 336 - /* Poll for ID change in OTG port mode */ 337 - if (musb->xceiv->otg->state == OTG_STATE_B_IDLE && 338 - musb->port_mode == MUSB_PORT_MODE_DUAL_ROLE) 361 + /* Poll for ID change and connect */ 362 + switch (musb->xceiv->otg->state) { 363 + case OTG_STATE_B_IDLE: 364 + case OTG_STATE_A_WAIT_BCON: 339 365 mod_timer(&glue->timer, jiffies + 340 366 msecs_to_jiffies(wrp->poll_timeout)); 367 + break; 368 + default: 369 + break; 370 + } 371 + 341 372 out: 342 373 spin_unlock_irqrestore(&musb->lock, flags); 343 374 ··· 441 460 val |= MUSB_BABBLE_SW_SESSION_CTRL; 442 461 musb_writeb(musb->mregs, MUSB_BABBLE_CTL, val); 443 462 } 463 + 464 + mod_timer(&glue->timer, jiffies + 465 + msecs_to_jiffies(glue->wrp->poll_timeout)); 444 466 445 467 return dsps_musb_dbg_init(musb, glue); 446 468 } ··· 604 620 .enable = dsps_musb_enable, 605 621 .disable = dsps_musb_disable, 606 622 607 - .try_idle = dsps_musb_try_idle, 608 623 .set_mode = dsps_musb_set_mode, 609 624 .recover = dsps_musb_recover, 610 625 }; ··· 767 784 768 785 platform_set_drvdata(pdev, glue); 769 786 pm_runtime_enable(&pdev->dev); 787 + pm_runtime_use_autosuspend(&pdev->dev); 788 + pm_runtime_set_autosuspend_delay(&pdev->dev, 200); 770 789 771 790 ret = pm_runtime_get_sync(&pdev->dev); 772 791 if (ret < 0) { ··· 780 795 if (ret) 781 796 goto err3; 782 797 798 + pm_runtime_mark_last_busy(&pdev->dev); 799 + pm_runtime_put_autosuspend(&pdev->dev); 800 + 783 801 return 0; 784 802 785 803 err3: 786 - pm_runtime_put(&pdev->dev); 804 + pm_runtime_put_sync(&pdev->dev); 787 805 err2: 806 + pm_runtime_dont_use_autosuspend(&pdev->dev); 788 807 pm_runtime_disable(&pdev->dev); 789 808 return ret; 790 809 } ··· 800 811 platform_device_unregister(glue->musb); 801 812 802 813 /* disable usbss clocks */ 803 - pm_runtime_put(&pdev->dev); 814 + pm_runtime_dont_use_autosuspend(&pdev->dev); 815 + pm_runtime_put_sync(&pdev->dev); 804 816 pm_runtime_disable(&pdev->dev); 805 817 806 818 return 0;
+3
drivers/usb/musb/musb_gadget.c
··· 1964 1964 * that currently misbehaves. 1965 1965 */ 1966 1966 1967 + /* Force check of devctl register for PM runtime */ 1968 + schedule_work(&musb->irq_work); 1969 + 1967 1970 pm_runtime_mark_last_busy(musb->controller); 1968 1971 pm_runtime_put_autosuspend(musb->controller); 1969 1972
+1
drivers/usb/musb/musb_virthub.c
··· 245 245 usb_otg_state_string(musb->xceiv->otg->state)); 246 246 } 247 247 } 248 + EXPORT_SYMBOL_GPL(musb_root_disconnect); 248 249 249 250 250 251 /*---------------------------------------------------------------------*/
+10 -66
drivers/usb/musb/omap2430.c
··· 49 49 enum musb_vbus_id_status status; 50 50 struct work_struct omap_musb_mailbox_work; 51 51 struct device *control_otghs; 52 - bool cable_connected; 53 - bool enabled; 54 - bool powered; 55 52 }; 56 53 #define glue_to_musb(g) platform_get_drvdata(g->musb) 57 54 ··· 138 141 musb_writel(musb->mregs, OTG_FORCESTDBY, l); 139 142 } 140 143 141 - /* 142 - * We can get multiple cable events so we need to keep track 143 - * of the power state. Only keep power enabled if USB cable is 144 - * connected and a gadget is started. 145 - */ 146 - static void omap2430_set_power(struct musb *musb, bool enabled, bool cable) 147 - { 148 - struct device *dev = musb->controller; 149 - struct omap2430_glue *glue = dev_get_drvdata(dev->parent); 150 - bool power_up; 151 - int res; 152 - 153 - if (glue->enabled != enabled) 154 - glue->enabled = enabled; 155 - 156 - if (glue->cable_connected != cable) 157 - glue->cable_connected = cable; 158 - 159 - power_up = glue->enabled && glue->cable_connected; 160 - if (power_up == glue->powered) { 161 - dev_warn(musb->controller, "power state already %i\n", 162 - power_up); 163 - return; 164 - } 165 - 166 - glue->powered = power_up; 167 - 168 - if (power_up) { 169 - res = pm_runtime_get_sync(musb->controller); 170 - if (res < 0) { 171 - dev_err(musb->controller, "could not enable: %i", res); 172 - glue->powered = false; 173 - } 174 - } else { 175 - pm_runtime_mark_last_busy(musb->controller); 176 - pm_runtime_put_autosuspend(musb->controller); 177 - } 178 - } 179 - 180 144 static int omap2430_musb_mailbox(enum musb_vbus_id_status status) 181 145 { 182 146 struct omap2430_glue *glue = _glue; ··· 161 203 static void omap_musb_set_mailbox(struct omap2430_glue *glue) 162 204 { 163 205 struct musb *musb = glue_to_musb(glue); 164 - struct device *dev = musb->controller; 165 - struct musb_hdrc_platform_data *pdata = dev_get_platdata(dev); 206 + struct musb_hdrc_platform_data *pdata = 207 + dev_get_platdata(musb->controller); 166 208 struct omap_musb_board_data *data = pdata->board_data; 167 209 struct usb_otg *otg = musb->xceiv->otg; 168 - bool cable_connected; 169 210 170 - cable_connected = ((glue->status == MUSB_ID_GROUND) || 171 - (glue->status == MUSB_VBUS_VALID)); 172 - 173 - if (cable_connected) 174 - omap2430_set_power(musb, glue->enabled, cable_connected); 175 - 211 + pm_runtime_get_sync(musb->controller); 176 212 switch (glue->status) { 177 213 case MUSB_ID_GROUND: 178 - dev_dbg(dev, "ID GND\n"); 214 + dev_dbg(musb->controller, "ID GND\n"); 179 215 180 216 otg->default_a = true; 181 217 musb->xceiv->otg->state = OTG_STATE_A_IDLE; ··· 182 230 break; 183 231 184 232 case MUSB_VBUS_VALID: 185 - dev_dbg(dev, "VBUS Connect\n"); 233 + dev_dbg(musb->controller, "VBUS Connect\n"); 186 234 187 235 otg->default_a = false; 188 236 musb->xceiv->otg->state = OTG_STATE_B_IDLE; ··· 192 240 193 241 case MUSB_ID_FLOAT: 194 242 case MUSB_VBUS_OFF: 195 - dev_dbg(dev, "VBUS Disconnect\n"); 243 + dev_dbg(musb->controller, "VBUS Disconnect\n"); 196 244 197 245 musb->xceiv->last_event = USB_EVENT_NONE; 198 246 if (musb->gadget_driver) ··· 205 253 USB_MODE_DISCONNECT); 206 254 break; 207 255 default: 208 - dev_dbg(dev, "ID float\n"); 256 + dev_dbg(musb->controller, "ID float\n"); 209 257 } 210 - 211 - if (!cable_connected) 212 - omap2430_set_power(musb, glue->enabled, cable_connected); 213 - 258 + pm_runtime_mark_last_busy(musb->controller); 259 + pm_runtime_put_autosuspend(musb->controller); 214 260 atomic_notifier_call_chain(&musb->xceiv->notifier, 215 261 musb->xceiv->last_event, NULL); 216 262 } ··· 326 376 if (!WARN_ON(!musb->phy)) 327 377 phy_power_on(musb->phy); 328 378 329 - omap2430_set_power(musb, true, glue->cable_connected); 330 - 331 379 switch (glue->status) { 332 380 333 381 case MUSB_ID_GROUND: ··· 367 419 if (glue->status != MUSB_UNKNOWN) 368 420 omap_control_usb_set_mode(glue->control_otghs, 369 421 USB_MODE_DISCONNECT); 370 - 371 - omap2430_set_power(musb, false, glue->cable_connected); 372 422 } 373 423 374 424 static int omap2430_musb_exit(struct musb *musb) ··· 517 571 518 572 pm_runtime_enable(glue->dev); 519 573 pm_runtime_use_autosuspend(glue->dev); 520 - pm_runtime_set_autosuspend_delay(glue->dev, 500); 574 + pm_runtime_set_autosuspend_delay(glue->dev, 100); 521 575 522 576 ret = platform_device_add(musb); 523 577 if (ret) { ··· 537 591 static int omap2430_remove(struct platform_device *pdev) 538 592 { 539 593 struct omap2430_glue *glue = platform_get_drvdata(pdev); 540 - struct musb *musb = glue_to_musb(glue); 541 594 542 595 pm_runtime_get_sync(glue->dev); 543 596 platform_device_unregister(glue->musb); 544 - omap2430_set_power(musb, false, false); 545 597 pm_runtime_put_sync(glue->dev); 546 598 pm_runtime_dont_use_autosuspend(glue->dev); 547 599 pm_runtime_disable(glue->dev);
+57 -4
drivers/usb/musb/sunxi.c
··· 74 74 #define SUNXI_MUSB_FL_HAS_SRAM 5 75 75 #define SUNXI_MUSB_FL_HAS_RESET 6 76 76 #define SUNXI_MUSB_FL_NO_CONFIGDATA 7 77 + #define SUNXI_MUSB_FL_PHY_MODE_PEND 8 77 78 78 79 /* Our read/write methods need access and do not get passed in a musb ref :| */ 79 80 static struct musb *sunxi_musb; ··· 88 87 struct phy *phy; 89 88 struct platform_device *usb_phy; 90 89 struct usb_phy *xceiv; 90 + enum phy_mode phy_mode; 91 91 unsigned long flags; 92 92 struct work_struct work; 93 93 struct extcon_dev *extcon; ··· 142 140 clear_bit(SUNXI_MUSB_FL_PHY_ON, &glue->flags); 143 141 } 144 142 } 143 + 144 + if (test_and_clear_bit(SUNXI_MUSB_FL_PHY_MODE_PEND, &glue->flags)) 145 + phy_set_mode(glue->phy, glue->phy_mode); 145 146 } 146 147 147 148 static void sunxi_musb_set_vbus(struct musb *musb, int is_on) ··· 344 339 345 340 static void sunxi_musb_dma_controller_destroy(struct dma_controller *c) 346 341 { 342 + } 343 + 344 + static int sunxi_musb_set_mode(struct musb *musb, u8 mode) 345 + { 346 + struct sunxi_glue *glue = dev_get_drvdata(musb->controller->parent); 347 + enum phy_mode new_mode; 348 + 349 + switch (mode) { 350 + case MUSB_HOST: 351 + new_mode = PHY_MODE_USB_HOST; 352 + break; 353 + case MUSB_PERIPHERAL: 354 + new_mode = PHY_MODE_USB_DEVICE; 355 + break; 356 + case MUSB_OTG: 357 + new_mode = PHY_MODE_USB_OTG; 358 + break; 359 + default: 360 + dev_err(musb->controller->parent, 361 + "Error requested mode not supported by this kernel\n"); 362 + return -EINVAL; 363 + } 364 + 365 + if (glue->phy_mode == new_mode) 366 + return 0; 367 + 368 + if (musb->port_mode != MUSB_PORT_MODE_DUAL_ROLE) { 369 + dev_err(musb->controller->parent, 370 + "Error changing modes is only supported in dual role mode\n"); 371 + return -EINVAL; 372 + } 373 + 374 + if (musb->port1_status & USB_PORT_STAT_ENABLE) 375 + musb_root_disconnect(musb); 376 + 377 + /* 378 + * phy_set_mode may sleep, and we're called with a spinlock held, 379 + * so let sunxi_musb_work deal with it. 380 + */ 381 + glue->phy_mode = new_mode; 382 + set_bit(SUNXI_MUSB_FL_PHY_MODE_PEND, &glue->flags); 383 + schedule_work(&glue->work); 384 + 385 + return 0; 347 386 } 348 387 349 388 /* ··· 617 568 .writew = sunxi_musb_writew, 618 569 .dma_init = sunxi_musb_dma_controller_create, 619 570 .dma_exit = sunxi_musb_dma_controller_destroy, 571 + .set_mode = sunxi_musb_set_mode, 620 572 .set_vbus = sunxi_musb_set_vbus, 621 573 .pre_root_reset_end = sunxi_musb_pre_root_reset_end, 622 574 .post_root_reset_end = sunxi_musb_post_root_reset_end, ··· 664 614 return -EINVAL; 665 615 } 666 616 617 + glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL); 618 + if (!glue) 619 + return -ENOMEM; 620 + 667 621 memset(&pdata, 0, sizeof(pdata)); 668 622 switch (usb_get_dr_mode(&pdev->dev)) { 669 623 #if defined CONFIG_USB_MUSB_DUAL_ROLE || defined CONFIG_USB_MUSB_HOST 670 624 case USB_DR_MODE_HOST: 671 625 pdata.mode = MUSB_PORT_MODE_HOST; 626 + glue->phy_mode = PHY_MODE_USB_HOST; 672 627 break; 673 628 #endif 674 629 #if defined CONFIG_USB_MUSB_DUAL_ROLE || defined CONFIG_USB_MUSB_GADGET 675 630 case USB_DR_MODE_PERIPHERAL: 676 631 pdata.mode = MUSB_PORT_MODE_GADGET; 632 + glue->phy_mode = PHY_MODE_USB_DEVICE; 677 633 break; 678 634 #endif 679 635 #ifdef CONFIG_USB_MUSB_DUAL_ROLE 680 636 case USB_DR_MODE_OTG: 681 637 pdata.mode = MUSB_PORT_MODE_DUAL_ROLE; 638 + glue->phy_mode = PHY_MODE_USB_OTG; 682 639 break; 683 640 #endif 684 641 default: ··· 694 637 } 695 638 pdata.platform_ops = &sunxi_musb_ops; 696 639 pdata.config = &sunxi_musb_hdrc_config; 697 - 698 - glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL); 699 - if (!glue) 700 - return -ENOMEM; 701 640 702 641 glue->dev = &pdev->dev; 703 642 INIT_WORK(&glue->work, sunxi_musb_work);
+4 -4
drivers/usb/phy/phy-ab8500-usb.c
··· 1248 1248 err = abx500_set_register_interruptible(ab->dev, 1249 1249 AB8500_DEBUG, AB8500_USB_PHY_TUNE3, 0x78); 1250 1250 if (err < 0) 1251 - dev_err(ab->dev, "Failed to set PHY_TUNE3 regester err=%d\n", 1251 + dev_err(ab->dev, "Failed to set PHY_TUNE3 register err=%d\n", 1252 1252 err); 1253 1253 1254 1254 /* Switch to normal mode/disable Bank 0x12 access */ ··· 1290 1290 0xFC, 0x80); 1291 1291 1292 1292 if (err < 0) 1293 - dev_err(ab->dev, "Failed to set PHY_TUNE3 regester err=%d\n", 1293 + dev_err(ab->dev, "Failed to set PHY_TUNE3 register err=%d\n", 1294 1294 err); 1295 1295 1296 1296 /* Switch to normal mode/disable Bank 0x12 access */ ··· 1321 1321 err = abx500_set_register_interruptible(ab->dev, 1322 1322 AB8540_DEBUG, AB8500_USB_PHY_TUNE3, 0x90); 1323 1323 if (err < 0) 1324 - dev_err(ab->dev, "Failed to set PHY_TUNE3 regester ret=%d\n", 1324 + dev_err(ab->dev, "Failed to set PHY_TUNE3 register ret=%d\n", 1325 1325 err); 1326 1326 } 1327 1327 ··· 1351 1351 err = abx500_set_register_interruptible(ab->dev, 1352 1352 AB8500_DEBUG, AB8500_USB_PHY_TUNE3, 0x80); 1353 1353 if (err < 0) 1354 - dev_err(ab->dev, "Failed to set PHY_TUNE3 regester err=%d\n", 1354 + dev_err(ab->dev, "Failed to set PHY_TUNE3 register err=%d\n", 1355 1355 err); 1356 1356 1357 1357 /* Switch to normal mode/disable Bank 0x12 access */
+4 -5
drivers/usb/phy/phy-generic.c
··· 118 118 status = USB_EVENT_VBUS; 119 119 otg->state = OTG_STATE_B_PERIPHERAL; 120 120 nop->phy.last_event = status; 121 - if (otg->gadget) 122 - usb_gadget_vbus_connect(otg->gadget); 123 121 124 122 /* drawing a "unit load" is *always* OK, except for OTG */ 125 123 nop_set_vbus_draw(nop, 100); ··· 127 129 } else { 128 130 nop_set_vbus_draw(nop, 0); 129 131 130 - if (otg->gadget) 131 - usb_gadget_vbus_disconnect(otg->gadget); 132 132 status = USB_EVENT_NONE; 133 133 otg->state = OTG_STATE_B_IDLE; 134 134 nop->phy.last_event = status; ··· 187 191 188 192 otg->gadget = gadget; 189 193 if (otg->state == OTG_STATE_B_PERIPHERAL) 190 - usb_gadget_vbus_connect(gadget); 194 + atomic_notifier_call_chain(&otg->usb_phy->notifier, 195 + USB_EVENT_VBUS, otg->gadget); 191 196 else 192 197 otg->state = OTG_STATE_B_IDLE; 193 198 return 0; ··· 323 326 gpiod_to_irq(nop->gpiod_vbus), err); 324 327 return err; 325 328 } 329 + nop->phy.otg->state = gpiod_get_value(nop->gpiod_vbus) ? 330 + OTG_STATE_B_PERIPHERAL : OTG_STATE_B_IDLE; 326 331 } 327 332 328 333 nop->phy.init = usb_gen_phy_init;
+61
drivers/usb/phy/phy-mxs-usb.c
··· 27 27 #define DRIVER_NAME "mxs_phy" 28 28 29 29 #define HW_USBPHY_PWD 0x00 30 + #define HW_USBPHY_TX 0x10 30 31 #define HW_USBPHY_CTRL 0x30 31 32 #define HW_USBPHY_CTRL_SET 0x34 32 33 #define HW_USBPHY_CTRL_CLR 0x38 ··· 38 37 #define HW_USBPHY_IP 0x90 39 38 #define HW_USBPHY_IP_SET 0x94 40 39 #define HW_USBPHY_IP_CLR 0x98 40 + 41 + #define GM_USBPHY_TX_TXCAL45DP(x) (((x) & 0xf) << 16) 42 + #define GM_USBPHY_TX_TXCAL45DN(x) (((x) & 0xf) << 8) 43 + #define GM_USBPHY_TX_D_CAL(x) (((x) & 0xf) << 0) 41 44 42 45 #define BM_USBPHY_CTRL_SFTRST BIT(31) 43 46 #define BM_USBPHY_CTRL_CLKGATE BIT(30) ··· 120 115 */ 121 116 #define MXS_PHY_NEED_IP_FIX BIT(3) 122 117 118 + /* Minimum and maximum values for device tree entries */ 119 + #define MXS_PHY_TX_CAL45_MIN 30 120 + #define MXS_PHY_TX_CAL45_MAX 55 121 + #define MXS_PHY_TX_D_CAL_MIN 79 122 + #define MXS_PHY_TX_D_CAL_MAX 119 123 + 123 124 struct mxs_phy_data { 124 125 unsigned int flags; 125 126 }; ··· 175 164 const struct mxs_phy_data *data; 176 165 struct regmap *regmap_anatop; 177 166 int port_id; 167 + u32 tx_reg_set; 168 + u32 tx_reg_mask; 178 169 }; 179 170 180 171 static inline bool is_imx6q_phy(struct mxs_phy *mxs_phy) ··· 196 183 static void mxs_phy_clock_switch_delay(void) 197 184 { 198 185 usleep_range(300, 400); 186 + } 187 + 188 + static void mxs_phy_tx_init(struct mxs_phy *mxs_phy) 189 + { 190 + void __iomem *base = mxs_phy->phy.io_priv; 191 + u32 phytx; 192 + 193 + /* Update TX register if there is anything to write */ 194 + if (mxs_phy->tx_reg_mask) { 195 + phytx = readl(base + HW_USBPHY_TX); 196 + phytx &= ~mxs_phy->tx_reg_mask; 197 + phytx |= mxs_phy->tx_reg_set; 198 + writel(phytx, base + HW_USBPHY_TX); 199 + } 199 200 } 200 201 201 202 static int mxs_phy_hw_init(struct mxs_phy *mxs_phy) ··· 240 213 241 214 if (mxs_phy->data->flags & MXS_PHY_NEED_IP_FIX) 242 215 writel(BM_USBPHY_IP_FIX, base + HW_USBPHY_IP_SET); 216 + 217 + mxs_phy_tx_init(mxs_phy); 243 218 244 219 return 0; 245 220 } ··· 488 459 int ret; 489 460 const struct of_device_id *of_id; 490 461 struct device_node *np = pdev->dev.of_node; 462 + u32 val; 491 463 492 464 of_id = of_match_device(mxs_phy_dt_ids, &pdev->dev); 493 465 if (!of_id) ··· 519 489 "failed to find regmap for anatop\n"); 520 490 return PTR_ERR(mxs_phy->regmap_anatop); 521 491 } 492 + } 493 + 494 + /* Precompute which bits of the TX register are to be updated, if any */ 495 + if (!of_property_read_u32(np, "fsl,tx-cal-45-dn-ohms", &val) && 496 + val >= MXS_PHY_TX_CAL45_MIN && val <= MXS_PHY_TX_CAL45_MAX) { 497 + /* Scale to a 4-bit value */ 498 + val = (MXS_PHY_TX_CAL45_MAX - val) * 0xF 499 + / (MXS_PHY_TX_CAL45_MAX - MXS_PHY_TX_CAL45_MIN); 500 + mxs_phy->tx_reg_mask |= GM_USBPHY_TX_TXCAL45DN(~0); 501 + mxs_phy->tx_reg_set |= GM_USBPHY_TX_TXCAL45DN(val); 502 + } 503 + 504 + if (!of_property_read_u32(np, "fsl,tx-cal-45-dp-ohms", &val) && 505 + val >= MXS_PHY_TX_CAL45_MIN && val <= MXS_PHY_TX_CAL45_MAX) { 506 + /* Scale to a 4-bit value. */ 507 + val = (MXS_PHY_TX_CAL45_MAX - val) * 0xF 508 + / (MXS_PHY_TX_CAL45_MAX - MXS_PHY_TX_CAL45_MIN); 509 + mxs_phy->tx_reg_mask |= GM_USBPHY_TX_TXCAL45DP(~0); 510 + mxs_phy->tx_reg_set |= GM_USBPHY_TX_TXCAL45DP(val); 511 + } 512 + 513 + if (!of_property_read_u32(np, "fsl,tx-d-cal", &val) && 514 + val >= MXS_PHY_TX_D_CAL_MIN && val <= MXS_PHY_TX_D_CAL_MAX) { 515 + /* Scale to a 4-bit value. Round up the values and heavily 516 + * weight the rounding by adding 2/3 of the denominator. 517 + */ 518 + val = ((MXS_PHY_TX_D_CAL_MAX - val) * 0xF 519 + + (MXS_PHY_TX_D_CAL_MAX - MXS_PHY_TX_D_CAL_MIN) * 2/3) 520 + / (MXS_PHY_TX_D_CAL_MAX - MXS_PHY_TX_D_CAL_MIN); 521 + mxs_phy->tx_reg_mask |= GM_USBPHY_TX_D_CAL(~0); 522 + mxs_phy->tx_reg_set |= GM_USBPHY_TX_D_CAL(val); 522 523 } 523 524 524 525 ret = of_alias_get_id(np, "usbphy");
+4
drivers/usb/renesas_usbhs/common.c
··· 482 482 .data = (void *)USBHS_TYPE_RCAR_GEN3, 483 483 }, 484 484 { 485 + .compatible = "renesas,usbhs-r8a7796", 486 + .data = (void *)USBHS_TYPE_RCAR_GEN3, 487 + }, 488 + { 485 489 .compatible = "renesas,rcar-gen2-usbhs", 486 490 .data = (void *)USBHS_TYPE_RCAR_GEN2, 487 491 },
+3 -5
drivers/usb/renesas_usbhs/mod_gadget.c
··· 335 335 buf = kmalloc(sizeof(*buf), GFP_ATOMIC); 336 336 if (!buf) { 337 337 usb_ep_free_request(&dcp->ep, req); 338 - dev_err(dev, "recip data allocation fail\n"); 339 338 return; 340 339 } 341 340 ··· 1061 1062 int ret; 1062 1063 1063 1064 gpriv = kzalloc(sizeof(struct usbhsg_gpriv), GFP_KERNEL); 1064 - if (!gpriv) { 1065 - dev_err(dev, "Could not allocate gadget priv\n"); 1065 + if (!gpriv) 1066 1066 return -ENOMEM; 1067 - } 1068 1067 1069 1068 uep = kzalloc(sizeof(struct usbhsg_uep) * pipe_size, GFP_KERNEL); 1070 1069 if (!uep) { 1071 - dev_err(dev, "Could not allocate ep\n"); 1072 1070 ret = -ENOMEM; 1073 1071 goto usbhs_mod_gadget_probe_err_gpriv; 1074 1072 } ··· 1102 1106 gpriv->gadget.name = "renesas_usbhs_udc"; 1103 1107 gpriv->gadget.ops = &usbhsg_gadget_ops; 1104 1108 gpriv->gadget.max_speed = USB_SPEED_HIGH; 1109 + gpriv->gadget.quirk_avoids_skb_reserve = usbhs_get_dparam(priv, 1110 + has_usb_dmac); 1105 1111 1106 1112 INIT_LIST_HEAD(&gpriv->gadget.ep_list); 1107 1113
+2 -8
drivers/usb/renesas_usbhs/mod_host.c
··· 166 166 gfp_t mem_flags) 167 167 { 168 168 struct usbhsh_request *ureq; 169 - struct usbhs_priv *priv = usbhsh_hpriv_to_priv(hpriv); 170 - struct device *dev = usbhs_priv_to_dev(priv); 171 169 172 170 ureq = kzalloc(sizeof(struct usbhsh_request), mem_flags); 173 - if (!ureq) { 174 - dev_err(dev, "ureq alloc fail\n"); 171 + if (!ureq) 175 172 return NULL; 176 - } 177 173 178 174 usbhs_pkt_init(&ureq->pkt); 179 175 ureq->urb = urb; ··· 384 388 unsigned long flags; 385 389 386 390 uep = kzalloc(sizeof(struct usbhsh_ep), mem_flags); 387 - if (!uep) { 388 - dev_err(dev, "usbhsh_ep alloc fail\n"); 391 + if (!uep) 389 392 return -ENOMEM; 390 - } 391 393 392 394 /******************** spin lock ********************/ 393 395 usbhs_lock(priv, flags);
+1 -3
drivers/usb/renesas_usbhs/pipe.c
··· 804 804 } 805 805 806 806 info->pipe = kzalloc(sizeof(struct usbhs_pipe) * pipe_size, GFP_KERNEL); 807 - if (!info->pipe) { 808 - dev_err(dev, "Could not allocate pipe\n"); 807 + if (!info->pipe) 809 808 return -ENOMEM; 810 - } 811 809 812 810 info->size = pipe_size; 813 811
+1
drivers/usb/serial/cp210x.c
··· 118 118 { USB_DEVICE(0x10C4, 0x8411) }, /* Kyocera GPS Module */ 119 119 { USB_DEVICE(0x10C4, 0x8418) }, /* IRZ Automation Teleport SG-10 GSM/GPRS Modem */ 120 120 { USB_DEVICE(0x10C4, 0x846E) }, /* BEI USB Sensor Interface (VCP) */ 121 + { USB_DEVICE(0x10C4, 0x8470) }, /* Juniper Networks BX Series System Console */ 121 122 { USB_DEVICE(0x10C4, 0x8477) }, /* Balluff RFID */ 122 123 { USB_DEVICE(0x10C4, 0x84B6) }, /* Starizona Hyperion */ 123 124 { USB_DEVICE(0x10C4, 0x85EA) }, /* AC-Services IBUS-IF */
+2 -2
drivers/usb/serial/keyspan_pda.c
··· 30 30 #include <linux/usb/ezusb.h> 31 31 32 32 /* make a simple define to handle if we are compiling keyspan_pda or xircom support */ 33 - #if defined(CONFIG_USB_SERIAL_KEYSPAN_PDA) || defined(CONFIG_USB_SERIAL_KEYSPAN_PDA_MODULE) 33 + #if IS_ENABLED(CONFIG_USB_SERIAL_KEYSPAN_PDA) 34 34 #define KEYSPAN 35 35 #else 36 36 #undef KEYSPAN 37 37 #endif 38 - #if defined(CONFIG_USB_SERIAL_XIRCOM) || defined(CONFIG_USB_SERIAL_XIRCOM_MODULE) 38 + #if IS_ENABLED(CONFIG_USB_SERIAL_XIRCOM) 39 39 #define XIRCOM 40 40 #else 41 41 #undef XIRCOM
+58 -113
drivers/usb/serial/ti_usb_3410_5052.c
··· 179 179 180 180 /* Config struct */ 181 181 struct ti_uart_config { 182 - __u16 wBaudRate; 183 - __u16 wFlags; 184 - __u8 bDataBits; 185 - __u8 bParity; 186 - __u8 bStopBits; 182 + __be16 wBaudRate; 183 + __be16 wFlags; 184 + u8 bDataBits; 185 + u8 bParity; 186 + u8 bStopBits; 187 187 char cXon; 188 188 char cXoff; 189 - __u8 bUartMode; 189 + u8 bUartMode; 190 190 } __packed; 191 191 192 192 /* Get port status */ 193 193 struct ti_port_status { 194 - __u8 bCmdCode; 195 - __u8 bModuleId; 196 - __u8 bErrorCode; 197 - __u8 bMSR; 198 - __u8 bLSR; 194 + u8 bCmdCode; 195 + u8 bModuleId; 196 + u8 bErrorCode; 197 + u8 bMSR; 198 + u8 bLSR; 199 199 } __packed; 200 200 201 201 /* Purge modes */ ··· 218 218 #define TI_RW_DATA_DOUBLE_WORD 0x04 219 219 220 220 struct ti_write_data_bytes { 221 - __u8 bAddrType; 222 - __u8 bDataType; 223 - __u8 bDataCounter; 221 + u8 bAddrType; 222 + u8 bDataType; 223 + u8 bDataCounter; 224 224 __be16 wBaseAddrHi; 225 225 __be16 wBaseAddrLo; 226 - __u8 bData[0]; 226 + u8 bData[0]; 227 227 } __packed; 228 228 229 229 struct ti_read_data_request { ··· 258 258 /* Firmware image header */ 259 259 struct ti_firmware_header { 260 260 __le16 wLength; 261 - __u8 bCheckSum; 261 + u8 bCheckSum; 262 262 } __packed; 263 263 264 264 /* UART addresses */ ··· 276 276 277 277 #define TI_DEFAULT_CLOSING_WAIT 4000 /* in .01 secs */ 278 278 279 - /* supported setserial flags */ 280 - #define TI_SET_SERIAL_FLAGS 0 281 - 282 279 /* read urb states */ 283 280 #define TI_READ_URB_RUNNING 0 284 281 #define TI_READ_URB_STOPPING 1 ··· 285 288 286 289 struct ti_port { 287 290 int tp_is_open; 288 - __u8 tp_msr; 289 - __u8 tp_shadow_mcr; 290 - __u8 tp_uart_mode; /* 232 or 485 modes */ 291 + u8 tp_msr; 292 + u8 tp_shadow_mcr; 293 + u8 tp_uart_mode; /* 232 or 485 modes */ 291 294 unsigned int tp_uart_base_addr; 292 - int tp_flags; 293 295 struct ti_device *tp_tdev; 294 296 struct usb_serial_port *tp_port; 295 297 spinlock_t tp_lock; ··· 302 306 struct usb_serial *td_serial; 303 307 int td_is_3410; 304 308 bool td_rs485_only; 305 - int td_urb_error; 306 309 }; 307 310 308 311 static int ti_startup(struct usb_serial *serial); ··· 338 343 struct serial_struct __user *ret_arg); 339 344 static int ti_set_serial_info(struct tty_struct *tty, struct ti_port *tport, 340 345 struct serial_struct __user *new_arg); 341 - static void ti_handle_new_msr(struct ti_port *tport, __u8 msr); 346 + static void ti_handle_new_msr(struct ti_port *tport, u8 msr); 342 347 343 348 static void ti_stop_read(struct ti_port *tport, struct tty_struct *tty); 344 349 static int ti_restart_read(struct ti_port *tport, struct tty_struct *tty); ··· 349 354 __u16 moduleid, __u16 value, __u8 *data, int size); 350 355 351 356 static int ti_write_byte(struct usb_serial_port *port, struct ti_device *tdev, 352 - unsigned long addr, __u8 mask, __u8 byte); 357 + unsigned long addr, u8 mask, u8 byte); 353 358 354 359 static int ti_download_firmware(struct ti_device *tdev); 355 360 ··· 642 647 struct urb *urb; 643 648 int port_number; 644 649 int status; 645 - __u16 open_settings = (__u8)(TI_PIPE_MODE_CONTINUOUS | 646 - TI_PIPE_TIMEOUT_ENABLE | 647 - (TI_TRANSFER_TIMEOUT << 2)); 650 + u16 open_settings; 648 651 649 - if (tport == NULL) 650 - return -ENODEV; 652 + open_settings = (TI_PIPE_MODE_CONTINUOUS | 653 + TI_PIPE_TIMEOUT_ENABLE | 654 + (TI_TRANSFER_TIMEOUT << 2)); 651 655 652 656 dev = port->serial->dev; 653 657 tdev = tport->tp_tdev; ··· 680 686 if (tty) 681 687 ti_set_termios(tty, port, &tty->termios); 682 688 683 - dev_dbg(&port->dev, "%s - sending TI_OPEN_PORT\n", __func__); 684 689 status = ti_command_out_sync(tdev, TI_OPEN_PORT, 685 690 (__u8)(TI_UART1_PORT + port_number), open_settings, NULL, 0); 686 691 if (status) { ··· 688 695 goto unlink_int_urb; 689 696 } 690 697 691 - dev_dbg(&port->dev, "%s - sending TI_START_PORT\n", __func__); 692 698 status = ti_command_out_sync(tdev, TI_START_PORT, 693 699 (__u8)(TI_UART1_PORT + port_number), 0, NULL, 0); 694 700 if (status) { ··· 696 704 goto unlink_int_urb; 697 705 } 698 706 699 - dev_dbg(&port->dev, "%s - sending TI_PURGE_PORT\n", __func__); 700 707 status = ti_command_out_sync(tdev, TI_PURGE_PORT, 701 708 (__u8)(TI_UART1_PORT + port_number), TI_PURGE_INPUT, NULL, 0); 702 709 if (status) { ··· 719 728 if (tty) 720 729 ti_set_termios(tty, port, &tty->termios); 721 730 722 - dev_dbg(&port->dev, "%s - sending TI_OPEN_PORT (2)\n", __func__); 723 731 status = ti_command_out_sync(tdev, TI_OPEN_PORT, 724 732 (__u8)(TI_UART1_PORT + port_number), open_settings, NULL, 0); 725 733 if (status) { ··· 727 737 goto unlink_int_urb; 728 738 } 729 739 730 - dev_dbg(&port->dev, "%s - sending TI_START_PORT (2)\n", __func__); 731 740 status = ti_command_out_sync(tdev, TI_START_PORT, 732 741 (__u8)(TI_UART1_PORT + port_number), 0, NULL, 0); 733 742 if (status) { ··· 736 747 } 737 748 738 749 /* start read urb */ 739 - dev_dbg(&port->dev, "%s - start read urb\n", __func__); 740 750 urb = port->read_urb; 741 751 if (!urb) { 742 752 dev_err(&port->dev, "%s - no read urb\n", __func__); ··· 761 773 usb_kill_urb(port->serial->port[0]->interrupt_in_urb); 762 774 release_lock: 763 775 mutex_unlock(&tdev->td_open_close_lock); 764 - dev_dbg(&port->dev, "%s - exit %d\n", __func__, status); 765 776 return status; 766 777 } 767 778 ··· 776 789 777 790 tdev = usb_get_serial_data(port->serial); 778 791 tport = usb_get_serial_port_data(port); 779 - if (tdev == NULL || tport == NULL) 780 - return; 781 792 782 793 tport->tp_is_open = 0; 783 794 ··· 788 803 789 804 port_number = port->port_number; 790 805 791 - dev_dbg(&port->dev, "%s - sending TI_CLOSE_PORT\n", __func__); 792 806 status = ti_command_out_sync(tdev, TI_CLOSE_PORT, 793 807 (__u8)(TI_UART1_PORT + port_number), 0, NULL, 0); 794 808 if (status) ··· 814 830 struct ti_port *tport = usb_get_serial_port_data(port); 815 831 816 832 if (count == 0) { 817 - dev_dbg(&port->dev, "%s - write request of 0 bytes\n", __func__); 818 833 return 0; 819 834 } 820 835 821 - if (tport == NULL || !tport->tp_is_open) 836 + if (!tport->tp_is_open) 822 837 return -ENODEV; 823 838 824 839 count = kfifo_in_locked(&port->write_fifo, data, count, ··· 835 852 int room = 0; 836 853 unsigned long flags; 837 854 838 - if (tport == NULL) 839 - return 0; 840 - 841 855 spin_lock_irqsave(&tport->tp_lock, flags); 842 856 room = kfifo_avail(&port->write_fifo); 843 857 spin_unlock_irqrestore(&tport->tp_lock, flags); ··· 850 870 struct ti_port *tport = usb_get_serial_port_data(port); 851 871 int chars = 0; 852 872 unsigned long flags; 853 - 854 - if (tport == NULL) 855 - return 0; 856 873 857 874 spin_lock_irqsave(&tport->tp_lock, flags); 858 875 chars = kfifo_len(&port->write_fifo); ··· 877 900 struct usb_serial_port *port = tty->driver_data; 878 901 struct ti_port *tport = usb_get_serial_port_data(port); 879 902 880 - if (tport == NULL) 881 - return; 882 - 883 903 if (I_IXOFF(tty) || C_CRTSCTS(tty)) 884 904 ti_stop_read(tport, tty); 885 905 ··· 888 914 struct usb_serial_port *port = tty->driver_data; 889 915 struct ti_port *tport = usb_get_serial_port_data(port); 890 916 int status; 891 - 892 - if (tport == NULL) 893 - return; 894 917 895 918 if (I_IXOFF(tty) || C_CRTSCTS(tty)) { 896 919 status = ti_restart_read(tport, tty); ··· 903 932 struct usb_serial_port *port = tty->driver_data; 904 933 struct ti_port *tport = usb_get_serial_port_data(port); 905 934 906 - if (tport == NULL) 907 - return -ENODEV; 908 - 909 935 switch (cmd) { 910 936 case TIOCGSERIAL: 911 - dev_dbg(&port->dev, "%s - TIOCGSERIAL\n", __func__); 912 937 return ti_get_serial_info(tport, 913 938 (struct serial_struct __user *)arg); 914 939 case TIOCSSERIAL: 915 - dev_dbg(&port->dev, "%s - TIOCSSERIAL\n", __func__); 916 940 return ti_set_serial_info(tty, tport, 917 941 (struct serial_struct __user *)arg); 918 942 } ··· 925 959 int status; 926 960 int port_number = port->port_number; 927 961 unsigned int mcr; 962 + u16 wbaudrate; 963 + u16 wflags = 0; 928 964 929 965 cflag = tty->termios.c_cflag; 930 966 iflag = tty->termios.c_iflag; ··· 935 967 dev_dbg(&port->dev, "%s - old clfag %08x, old iflag %08x\n", __func__, 936 968 old_termios->c_cflag, old_termios->c_iflag); 937 969 938 - if (tport == NULL) 939 - return; 940 - 941 970 config = kmalloc(sizeof(*config), GFP_KERNEL); 942 971 if (!config) 943 972 return; 944 973 945 - config->wFlags = 0; 946 - 947 974 /* these flags must be set */ 948 - config->wFlags |= TI_UART_ENABLE_MS_INTS; 949 - config->wFlags |= TI_UART_ENABLE_AUTO_START_DMA; 950 - config->bUartMode = (__u8)(tport->tp_uart_mode); 975 + wflags |= TI_UART_ENABLE_MS_INTS; 976 + wflags |= TI_UART_ENABLE_AUTO_START_DMA; 977 + config->bUartMode = tport->tp_uart_mode; 951 978 952 - switch (cflag & CSIZE) { 979 + switch (C_CSIZE(tty)) { 953 980 case CS5: 954 981 config->bDataBits = TI_UART_5_DATA_BITS; 955 982 break; ··· 963 1000 /* CMSPAR isn't supported by this driver */ 964 1001 tty->termios.c_cflag &= ~CMSPAR; 965 1002 966 - if (cflag & PARENB) { 967 - if (cflag & PARODD) { 968 - config->wFlags |= TI_UART_ENABLE_PARITY_CHECKING; 1003 + if (C_PARENB(tty)) { 1004 + if (C_PARODD(tty)) { 1005 + wflags |= TI_UART_ENABLE_PARITY_CHECKING; 969 1006 config->bParity = TI_UART_ODD_PARITY; 970 1007 } else { 971 - config->wFlags |= TI_UART_ENABLE_PARITY_CHECKING; 1008 + wflags |= TI_UART_ENABLE_PARITY_CHECKING; 972 1009 config->bParity = TI_UART_EVEN_PARITY; 973 1010 } 974 1011 } else { 975 - config->wFlags &= ~TI_UART_ENABLE_PARITY_CHECKING; 1012 + wflags &= ~TI_UART_ENABLE_PARITY_CHECKING; 976 1013 config->bParity = TI_UART_NO_PARITY; 977 1014 } 978 1015 979 - if (cflag & CSTOPB) 1016 + if (C_CSTOPB(tty)) 980 1017 config->bStopBits = TI_UART_2_STOP_BITS; 981 1018 else 982 1019 config->bStopBits = TI_UART_1_STOP_BITS; 983 1020 984 - if (cflag & CRTSCTS) { 1021 + if (C_CRTSCTS(tty)) { 985 1022 /* RTS flow control must be off to drop RTS for baud rate B0 */ 986 - if ((cflag & CBAUD) != B0) 987 - config->wFlags |= TI_UART_ENABLE_RTS_IN; 988 - config->wFlags |= TI_UART_ENABLE_CTS_OUT; 1023 + if ((C_BAUD(tty)) != B0) 1024 + wflags |= TI_UART_ENABLE_RTS_IN; 1025 + wflags |= TI_UART_ENABLE_CTS_OUT; 989 1026 } else { 990 1027 ti_restart_read(tport, tty); 991 1028 } ··· 995 1032 config->cXoff = STOP_CHAR(tty); 996 1033 997 1034 if (I_IXOFF(tty)) 998 - config->wFlags |= TI_UART_ENABLE_X_IN; 1035 + wflags |= TI_UART_ENABLE_X_IN; 999 1036 else 1000 1037 ti_restart_read(tport, tty); 1001 1038 1002 1039 if (I_IXON(tty)) 1003 - config->wFlags |= TI_UART_ENABLE_X_OUT; 1040 + wflags |= TI_UART_ENABLE_X_OUT; 1004 1041 } 1005 1042 1006 1043 baud = tty_get_baud_rate(tty); 1007 1044 if (!baud) 1008 1045 baud = 9600; 1009 1046 if (tport->tp_tdev->td_is_3410) 1010 - config->wBaudRate = (__u16)((923077 + baud/2) / baud); 1047 + wbaudrate = (923077 + baud/2) / baud; 1011 1048 else 1012 - config->wBaudRate = (__u16)((461538 + baud/2) / baud); 1049 + wbaudrate = (461538 + baud/2) / baud; 1013 1050 1014 1051 /* FIXME: Should calculate resulting baud here and report it back */ 1015 - if ((cflag & CBAUD) != B0) 1052 + if ((C_BAUD(tty)) != B0) 1016 1053 tty_encode_baud_rate(tty, baud, baud); 1017 1054 1018 1055 dev_dbg(&port->dev, 1019 1056 "%s - BaudRate=%d, wBaudRate=%d, wFlags=0x%04X, bDataBits=%d, bParity=%d, bStopBits=%d, cXon=%d, cXoff=%d, bUartMode=%d\n", 1020 - __func__, baud, config->wBaudRate, config->wFlags, 1057 + __func__, baud, wbaudrate, wflags, 1021 1058 config->bDataBits, config->bParity, config->bStopBits, 1022 1059 config->cXon, config->cXoff, config->bUartMode); 1023 1060 1024 - cpu_to_be16s(&config->wBaudRate); 1025 - cpu_to_be16s(&config->wFlags); 1061 + config->wBaudRate = cpu_to_be16(wbaudrate); 1062 + config->wFlags = cpu_to_be16(wflags); 1026 1063 1027 1064 status = ti_command_out_sync(tport->tp_tdev, TI_SET_CONFIG, 1028 1065 (__u8)(TI_UART1_PORT + port_number), 0, (__u8 *)config, ··· 1034 1071 /* SET_CONFIG asserts RTS and DTR, reset them correctly */ 1035 1072 mcr = tport->tp_shadow_mcr; 1036 1073 /* if baud rate is B0, clear RTS and DTR */ 1037 - if ((cflag & CBAUD) == B0) 1074 + if (C_BAUD(tty) == B0) 1038 1075 mcr &= ~(TI_MCR_DTR | TI_MCR_RTS); 1039 1076 status = ti_set_mcr(tport, mcr); 1040 1077 if (status) ··· 1054 1091 unsigned int msr; 1055 1092 unsigned int mcr; 1056 1093 unsigned long flags; 1057 - 1058 - if (tport == NULL) 1059 - return -ENODEV; 1060 1094 1061 1095 spin_lock_irqsave(&tport->tp_lock, flags); 1062 1096 msr = tport->tp_msr; ··· 1081 1121 struct ti_port *tport = usb_get_serial_port_data(port); 1082 1122 unsigned int mcr; 1083 1123 unsigned long flags; 1084 - 1085 - if (tport == NULL) 1086 - return -ENODEV; 1087 1124 1088 1125 spin_lock_irqsave(&tport->tp_lock, flags); 1089 1126 mcr = tport->tp_shadow_mcr; ··· 1111 1154 int status; 1112 1155 1113 1156 dev_dbg(&port->dev, "%s - state = %d\n", __func__, break_state); 1114 - 1115 - if (tport == NULL) 1116 - return; 1117 1157 1118 1158 status = ti_write_byte(port, tport->tp_tdev, 1119 1159 tport->tp_uart_base_addr + TI_UART_OFFSET_LCR, ··· 1143 1189 int function; 1144 1190 int status = urb->status; 1145 1191 int retval; 1146 - __u8 msr; 1192 + u8 msr; 1147 1193 1148 1194 switch (status) { 1149 1195 case 0: ··· 1152 1198 case -ENOENT: 1153 1199 case -ESHUTDOWN: 1154 1200 dev_dbg(dev, "%s - urb shutting down, %d\n", __func__, status); 1155 - tdev->td_urb_error = 1; 1156 1201 return; 1157 1202 default: 1158 1203 dev_err(dev, "%s - nonzero urb status, %d\n", __func__, status); 1159 - tdev->td_urb_error = 1; 1160 1204 goto exit; 1161 1205 } 1162 1206 ··· 1227 1275 case -ENOENT: 1228 1276 case -ESHUTDOWN: 1229 1277 dev_dbg(dev, "%s - urb shutting down, %d\n", __func__, status); 1230 - tport->tp_tdev->td_urb_error = 1; 1231 1278 return; 1232 1279 default: 1233 1280 dev_err(dev, "%s - nonzero urb status, %d\n", 1234 1281 __func__, status); 1235 - tport->tp_tdev->td_urb_error = 1; 1236 1282 } 1237 1283 1238 1284 if (status == -EPIPE) ··· 1285 1335 case -ENOENT: 1286 1336 case -ESHUTDOWN: 1287 1337 dev_dbg(&port->dev, "%s - urb shutting down, %d\n", __func__, status); 1288 - tport->tp_tdev->td_urb_error = 1; 1289 1338 return; 1290 1339 default: 1291 1340 dev_err_console(port, "%s - nonzero urb status, %d\n", 1292 1341 __func__, status); 1293 - tport->tp_tdev->td_urb_error = 1; 1294 1342 } 1295 1343 1296 1344 /* send any buffered data */ ··· 1438 1490 ret_serial.type = PORT_16550A; 1439 1491 ret_serial.line = port->minor; 1440 1492 ret_serial.port = port->port_number; 1441 - ret_serial.flags = tport->tp_flags; 1442 1493 ret_serial.xmit_fifo_size = kfifo_size(&port->write_fifo); 1443 1494 ret_serial.baud_base = tport->tp_tdev->td_is_3410 ? 921600 : 460800; 1444 1495 ret_serial.closing_wait = cwait; ··· 1462 1515 if (cwait != ASYNC_CLOSING_WAIT_NONE) 1463 1516 cwait = msecs_to_jiffies(10 * new_serial.closing_wait); 1464 1517 1465 - tport->tp_flags = new_serial.flags & TI_SET_SERIAL_FLAGS; 1466 1518 tport->tp_port->port.closing_wait = cwait; 1467 1519 1468 1520 return 0; 1469 1521 } 1470 1522 1471 1523 1472 - static void ti_handle_new_msr(struct ti_port *tport, __u8 msr) 1524 + static void ti_handle_new_msr(struct ti_port *tport, u8 msr) 1473 1525 { 1474 1526 struct async_icount *icount; 1475 1527 struct tty_struct *tty; ··· 1580 1634 1581 1635 1582 1636 static int ti_write_byte(struct usb_serial_port *port, 1583 - struct ti_device *tdev, unsigned long addr, 1584 - __u8 mask, __u8 byte) 1637 + struct ti_device *tdev, unsigned long addr, 1638 + u8 mask, u8 byte) 1585 1639 { 1586 1640 int status; 1587 1641 unsigned int size; ··· 1625 1679 int len; 1626 1680 1627 1681 for (pos = sizeof(struct ti_firmware_header); pos < size; pos++) 1628 - cs = (__u8)(cs + buffer[pos]); 1682 + cs = (u8)(cs + buffer[pos]); 1629 1683 1630 1684 header = (struct ti_firmware_header *)buffer; 1631 - header->wLength = cpu_to_le16((__u16)(size 1632 - - sizeof(struct ti_firmware_header))); 1685 + header->wLength = cpu_to_le16(size - sizeof(*header)); 1633 1686 header->bCheckSum = cs; 1634 1687 1635 1688 dev_dbg(&dev->dev, "%s - downloading firmware\n", __func__); ··· 1646 1701 { 1647 1702 int status; 1648 1703 int buffer_size; 1649 - __u8 *buffer; 1704 + u8 *buffer; 1650 1705 struct usb_device *dev = tdev->td_serial->dev; 1651 1706 unsigned int pipe = usb_sndbulkpipe(dev, 1652 1707 tdev->td_serial->port[0]->bulk_out_endpointAddress);
+3 -8
drivers/usb/storage/alauda.c
··· 939 939 940 940 len = min(sectors, blocksize) * (pagesize + 64); 941 941 buffer = kmalloc(len, GFP_NOIO); 942 - if (buffer == NULL) { 943 - printk(KERN_WARNING "alauda_read_data: Out of memory\n"); 942 + if (!buffer) 944 943 return USB_STOR_TRANSPORT_ERROR; 945 - } 946 944 947 945 /* Figure out the initial LBA and page */ 948 946 lba = address >> blockshift; ··· 1031 1033 1032 1034 len = min(sectors, blocksize) * pagesize; 1033 1035 buffer = kmalloc(len, GFP_NOIO); 1034 - if (buffer == NULL) { 1035 - printk(KERN_WARNING "alauda_write_data: Out of memory\n"); 1036 + if (!buffer) 1036 1037 return USB_STOR_TRANSPORT_ERROR; 1037 - } 1038 1038 1039 1039 /* 1040 1040 * We also need a temporary block buffer, where we read in the old data, 1041 1041 * overwrite parts with the new data, and manipulate the redundancy data 1042 1042 */ 1043 1043 blockbuffer = kmalloc((pagesize + 64) * blocksize, GFP_NOIO); 1044 - if (blockbuffer == NULL) { 1045 - printk(KERN_WARNING "alauda_write_data: Out of memory\n"); 1044 + if (!blockbuffer) { 1046 1045 kfree(buffer); 1047 1046 return USB_STOR_TRANSPORT_ERROR; 1048 1047 }
+8
drivers/usb/storage/scsiglue.c
··· 296 296 if (us->fflags & US_FL_BROKEN_FUA) 297 297 sdev->broken_fua = 1; 298 298 299 + /* Some even totally fail to indicate a cache */ 300 + if (us->fflags & US_FL_ALWAYS_SYNC) { 301 + /* don't read caching information */ 302 + sdev->skip_ms_page_8 = 1; 303 + sdev->skip_ms_page_3f = 1; 304 + /* assume sync is needed */ 305 + sdev->wce_default_on = 1; 306 + } 299 307 } else { 300 308 301 309 /*
+4 -10
drivers/usb/storage/sddr09.c
··· 766 766 767 767 len = min(sectors, (unsigned int) info->blocksize) * info->pagesize; 768 768 buffer = kmalloc(len, GFP_NOIO); 769 - if (buffer == NULL) { 770 - printk(KERN_WARNING "sddr09_read_data: Out of memory\n"); 769 + if (!buffer) 771 770 return -ENOMEM; 772 - } 773 771 774 772 // This could be made much more efficient by checking for 775 773 // contiguous LBA's. Another exercise left to the student. ··· 1002 1004 pagelen = (1 << info->pageshift) + (1 << CONTROL_SHIFT); 1003 1005 blocklen = (pagelen << info->blockshift); 1004 1006 blockbuffer = kmalloc(blocklen, GFP_NOIO); 1005 - if (!blockbuffer) { 1006 - printk(KERN_WARNING "sddr09_write_data: Out of memory\n"); 1007 + if (!blockbuffer) 1007 1008 return -ENOMEM; 1008 - } 1009 1009 1010 1010 /* 1011 1011 * Since we don't write the user data directly to the device, ··· 1013 1017 1014 1018 len = min(sectors, (unsigned int) info->blocksize) * info->pagesize; 1015 1019 buffer = kmalloc(len, GFP_NOIO); 1016 - if (buffer == NULL) { 1017 - printk(KERN_WARNING "sddr09_write_data: Out of memory\n"); 1020 + if (!buffer) { 1018 1021 kfree(blockbuffer); 1019 1022 return -ENOMEM; 1020 1023 } ··· 1236 1241 alloc_blocks = min(numblocks, SDDR09_READ_MAP_BUFSZ >> CONTROL_SHIFT); 1237 1242 alloc_len = (alloc_blocks << CONTROL_SHIFT); 1238 1243 buffer = kmalloc(alloc_len, GFP_NOIO); 1239 - if (buffer == NULL) { 1240 - printk(KERN_WARNING "sddr09_read_map: out of memory\n"); 1244 + if (!buffer) { 1241 1245 result = -1; 1242 1246 goto done; 1243 1247 }
+7
drivers/usb/storage/unusual_devs.h
··· 338 338 USB_SC_DEVICE, USB_PR_DEVICE, NULL, 339 339 US_FL_NO_WP_DETECT), 340 340 341 + /* Reported by Egbert Eich <eich@suse.com> */ 342 + UNUSUAL_DEV( 0x0480, 0xd010, 0x0100, 0x9999, 343 + "Toshiba", 344 + "External USB 3.0", 345 + USB_SC_DEVICE, USB_PR_DEVICE, NULL, 346 + US_FL_ALWAYS_SYNC), 347 + 341 348 /* Patch submitted by Philipp Friedrich <philipp@void.at> */ 342 349 UNUSUAL_DEV( 0x0482, 0x0100, 0x0100, 0x0100, 343 350 "Kyocera",
+10 -6
drivers/usb/storage/usb.c
··· 498 498 US_FL_NO_READ_DISC_INFO | US_FL_NO_READ_CAPACITY_16 | 499 499 US_FL_INITIAL_READ10 | US_FL_WRITE_CACHE | 500 500 US_FL_NO_ATA_1X | US_FL_NO_REPORT_OPCODES | 501 - US_FL_MAX_SECTORS_240 | US_FL_NO_REPORT_LUNS); 501 + US_FL_MAX_SECTORS_240 | US_FL_NO_REPORT_LUNS | 502 + US_FL_ALWAYS_SYNC); 502 503 503 504 p = quirks; 504 505 while (*p) { ··· 581 580 break; 582 581 case 'w': 583 582 f |= US_FL_NO_WP_DETECT; 583 + break; 584 + case 'y': 585 + f |= US_FL_ALWAYS_SYNC; 584 586 break; 585 587 /* Ignore unrecognized flag characters */ 586 588 } ··· 798 794 struct task_struct *th; 799 795 800 796 us->current_urb = usb_alloc_urb(0, GFP_KERNEL); 801 - if (!us->current_urb) { 802 - usb_stor_dbg(us, "URB allocation failed\n"); 797 + if (!us->current_urb) 803 798 return -ENOMEM; 804 - } 805 799 806 800 /* 807 801 * Just before we start our control thread, initialize ··· 1072 1070 result = usb_stor_acquire_resources(us); 1073 1071 if (result) 1074 1072 goto BadDevice; 1073 + usb_autopm_get_interface_no_resume(us->pusb_intf); 1075 1074 snprintf(us->scsi_name, sizeof(us->scsi_name), "usb-storage %s", 1076 1075 dev_name(&us->pusb_intf->dev)); 1077 1076 result = scsi_add_host(us_to_host(us), dev); 1078 1077 if (result) { 1079 1078 dev_warn(dev, 1080 1079 "Unable to add the scsi host\n"); 1081 - goto BadDevice; 1080 + goto HostAddErr; 1082 1081 } 1083 1082 1084 1083 /* Submit the delayed_work for SCSI-device scanning */ 1085 - usb_autopm_get_interface_no_resume(us->pusb_intf); 1086 1084 set_bit(US_FLIDX_SCAN_PENDING, &us->dflags); 1087 1085 1088 1086 if (delay_use > 0) ··· 1092 1090 return 0; 1093 1091 1094 1092 /* We come here if there are any problems */ 1093 + HostAddErr: 1094 + usb_autopm_put_interface_no_suspend(us->pusb_intf); 1095 1095 BadDevice: 1096 1096 usb_stor_dbg(us, "storage_probe() failed\n"); 1097 1097 release_everything(us);
+3 -11
drivers/usb/usb-skeleton.c
··· 499 499 500 500 /* allocate memory for our device state and initialize it */ 501 501 dev = kzalloc(sizeof(*dev), GFP_KERNEL); 502 - if (!dev) { 503 - dev_err(&interface->dev, "Out of memory\n"); 502 + if (!dev) 504 503 goto error; 505 - } 506 504 kref_init(&dev->kref); 507 505 sema_init(&dev->limit_sem, WRITES_IN_FLIGHT); 508 506 mutex_init(&dev->io_mutex); ··· 524 526 dev->bulk_in_size = buffer_size; 525 527 dev->bulk_in_endpointAddr = endpoint->bEndpointAddress; 526 528 dev->bulk_in_buffer = kmalloc(buffer_size, GFP_KERNEL); 527 - if (!dev->bulk_in_buffer) { 528 - dev_err(&interface->dev, 529 - "Could not allocate bulk_in_buffer\n"); 529 + if (!dev->bulk_in_buffer) 530 530 goto error; 531 - } 532 531 dev->bulk_in_urb = usb_alloc_urb(0, GFP_KERNEL); 533 - if (!dev->bulk_in_urb) { 534 - dev_err(&interface->dev, 535 - "Could not allocate bulk_in_urb\n"); 532 + if (!dev->bulk_in_urb) 536 533 goto error; 537 - } 538 534 } 539 535 540 536 if (!dev->bulk_out_endpointAddr &&
+23 -1
drivers/usb/usbip/Kconfig
··· 1 1 config USBIP_CORE 2 2 tristate "USB/IP support" 3 - depends on USB_COMMON && NET 3 + depends on NET 4 + select USB_COMMON 4 5 ---help--- 5 6 This enables pushing USB packets over IP to allow remote 6 7 machines direct access to USB devices. It provides the ··· 24 23 25 24 To compile this driver as a module, choose M here: the 26 25 module will be called vhci-hcd. 26 + 27 + config USBIP_VHCI_HC_PORTS 28 + int "Number of ports per USB/IP virtual host controller" 29 + range 1 31 30 + default 8 31 + depends on USBIP_VHCI_HCD 32 + ---help--- 33 + To increase number of ports available for USB/IP virtual 34 + host controller driver, this defines number of ports per 35 + USB/IP virtual host controller. 36 + 37 + config USBIP_VHCI_NR_HCS 38 + int "Number of USB/IP virtual host controllers" 39 + range 1 128 40 + default 1 41 + depends on USBIP_VHCI_HCD 42 + ---help--- 43 + To increase number of ports available for USB/IP virtual 44 + host controller driver, this defines number of USB/IP 45 + virtual host controllers as if adding physical host 46 + controllers. 27 47 28 48 config USBIP_HOST 29 49 tristate "Host driver"
-1
drivers/usb/usbip/stub_rx.c
··· 461 461 priv->urb = usb_alloc_urb(0, GFP_KERNEL); 462 462 463 463 if (!priv->urb) { 464 - dev_err(&udev->dev, "malloc urb\n"); 465 464 usbip_event_add(ud, SDEV_EVENT_ERROR_MALLOC); 466 465 return; 467 466 }
+44 -10
drivers/usb/usbip/vhci.h
··· 1 1 /* 2 2 * Copyright (C) 2003-2008 Takahiro Hirofuchi 3 + * Copyright (C) 2015 Nobuo Iwata 3 4 * 4 5 * This is free software; you can redistribute it and/or modify 5 6 * it under the terms of the GNU General Public License as published by ··· 73 72 }; 74 73 75 74 /* Number of supported ports. Value has an upperbound of USB_MAXCHILDREN */ 76 - #define VHCI_NPORTS 8 75 + #ifdef CONFIG_USBIP_VHCI_HC_PORTS 76 + #define VHCI_HC_PORTS CONFIG_USBIP_VHCI_HC_PORTS 77 + #else 78 + #define VHCI_HC_PORTS 8 79 + #endif 80 + 81 + #ifdef CONFIG_USBIP_VHCI_NR_HCS 82 + #define VHCI_NR_HCS CONFIG_USBIP_VHCI_NR_HCS 83 + #else 84 + #define VHCI_NR_HCS 1 85 + #endif 86 + 87 + #define MAX_STATUS_NAME 16 77 88 78 89 /* for usb_bus.hcpriv */ 79 90 struct vhci_hcd { 80 91 spinlock_t lock; 81 92 82 - u32 port_status[VHCI_NPORTS]; 93 + u32 port_status[VHCI_HC_PORTS]; 83 94 84 95 unsigned resuming:1; 85 96 unsigned long re_timeout; ··· 103 90 * wIndex shows the port number and begins from 1. 104 91 * But, the index of this array begins from 0. 105 92 */ 106 - struct vhci_device vdev[VHCI_NPORTS]; 93 + struct vhci_device vdev[VHCI_HC_PORTS]; 107 94 }; 108 95 109 - extern struct vhci_hcd *the_controller; 110 - extern const struct attribute_group dev_attr_group; 96 + extern int vhci_num_controllers; 97 + extern struct platform_device **vhci_pdevs; 98 + extern struct attribute_group vhci_attr_group; 111 99 112 100 /* vhci_hcd.c */ 113 - void rh_port_connect(int rhport, enum usb_device_speed speed); 101 + void rh_port_connect(struct vhci_device *vdev, enum usb_device_speed speed); 102 + 103 + /* vhci_sysfs.c */ 104 + int vhci_init_attr_group(void); 105 + void vhci_finish_attr_group(void); 114 106 115 107 /* vhci_rx.c */ 116 108 struct urb *pickup_urb_and_free_priv(struct vhci_device *vdev, __u32 seqnum); ··· 124 106 /* vhci_tx.c */ 125 107 int vhci_tx_loop(void *data); 126 108 127 - static inline struct vhci_device *port_to_vdev(__u32 port) 109 + static inline __u32 port_to_rhport(__u32 port) 128 110 { 129 - return &the_controller->vdev[port]; 111 + return port % VHCI_HC_PORTS; 112 + } 113 + 114 + static inline int port_to_pdev_nr(__u32 port) 115 + { 116 + return port / VHCI_HC_PORTS; 130 117 } 131 118 132 119 static inline struct vhci_hcd *hcd_to_vhci(struct usb_hcd *hcd) ··· 139 116 return (struct vhci_hcd *) (hcd->hcd_priv); 140 117 } 141 118 119 + static inline struct device *hcd_dev(struct usb_hcd *hcd) 120 + { 121 + return (hcd)->self.controller; 122 + } 123 + 124 + static inline const char *hcd_name(struct usb_hcd *hcd) 125 + { 126 + return (hcd)->self.bus_name; 127 + } 128 + 142 129 static inline struct usb_hcd *vhci_to_hcd(struct vhci_hcd *vhci) 143 130 { 144 131 return container_of((void *) vhci, struct usb_hcd, hcd_priv); 145 132 } 146 133 147 - static inline struct device *vhci_dev(struct vhci_hcd *vhci) 134 + static inline struct vhci_hcd *vdev_to_vhci(struct vhci_device *vdev) 148 135 { 149 - return vhci_to_hcd(vhci)->self.controller; 136 + return container_of( 137 + (void *)(vdev - vdev->rhport), struct vhci_hcd, vdev); 150 138 } 151 139 152 140 #endif /* __USBIP_VHCI_H */
+191 -94
drivers/usb/usbip/vhci_hcd.c
··· 1 1 /* 2 2 * Copyright (C) 2003-2008 Takahiro Hirofuchi 3 + * Copyright (C) 2015-2016 Nobuo Iwata 3 4 * 4 5 * This is free software; you can redistribute it and/or modify 5 6 * it under the terms of the GNU General Public License as published by ··· 57 56 static const char driver_name[] = "vhci_hcd"; 58 57 static const char driver_desc[] = "USB/IP Virtual Host Controller"; 59 58 60 - struct vhci_hcd *the_controller; 59 + int vhci_num_controllers = VHCI_NR_HCS; 60 + 61 + struct platform_device **vhci_pdevs; 61 62 62 63 static const char * const bit_desc[] = { 63 64 "CONNECTION", /*0*/ ··· 122 119 pr_debug("\n"); 123 120 } 124 121 125 - void rh_port_connect(int rhport, enum usb_device_speed speed) 122 + void rh_port_connect(struct vhci_device *vdev, enum usb_device_speed speed) 126 123 { 124 + struct vhci_hcd *vhci = vdev_to_vhci(vdev); 125 + int rhport = vdev->rhport; 126 + u32 status; 127 127 unsigned long flags; 128 128 129 129 usbip_dbg_vhci_rh("rh_port_connect %d\n", rhport); 130 130 131 - spin_lock_irqsave(&the_controller->lock, flags); 131 + spin_lock_irqsave(&vhci->lock, flags); 132 132 133 - the_controller->port_status[rhport] |= USB_PORT_STAT_CONNECTION 134 - | (1 << USB_PORT_FEAT_C_CONNECTION); 133 + status = vhci->port_status[rhport]; 134 + 135 + status |= USB_PORT_STAT_CONNECTION | (1 << USB_PORT_FEAT_C_CONNECTION); 135 136 136 137 switch (speed) { 137 138 case USB_SPEED_HIGH: 138 - the_controller->port_status[rhport] |= USB_PORT_STAT_HIGH_SPEED; 139 + status |= USB_PORT_STAT_HIGH_SPEED; 139 140 break; 140 141 case USB_SPEED_LOW: 141 - the_controller->port_status[rhport] |= USB_PORT_STAT_LOW_SPEED; 142 + status |= USB_PORT_STAT_LOW_SPEED; 142 143 break; 143 144 default: 144 145 break; 145 146 } 146 147 147 - spin_unlock_irqrestore(&the_controller->lock, flags); 148 + vhci->port_status[rhport] = status; 148 149 149 - usb_hcd_poll_rh_status(vhci_to_hcd(the_controller)); 150 + spin_unlock_irqrestore(&vhci->lock, flags); 151 + 152 + usb_hcd_poll_rh_status(vhci_to_hcd(vhci)); 150 153 } 151 154 152 - static void rh_port_disconnect(int rhport) 155 + static void rh_port_disconnect(struct vhci_device *vdev) 153 156 { 157 + struct vhci_hcd *vhci = vdev_to_vhci(vdev); 158 + int rhport = vdev->rhport; 159 + u32 status; 154 160 unsigned long flags; 155 161 156 162 usbip_dbg_vhci_rh("rh_port_disconnect %d\n", rhport); 157 163 158 - spin_lock_irqsave(&the_controller->lock, flags); 164 + spin_lock_irqsave(&vhci->lock, flags); 159 165 160 - the_controller->port_status[rhport] &= ~USB_PORT_STAT_CONNECTION; 161 - the_controller->port_status[rhport] |= 162 - (1 << USB_PORT_FEAT_C_CONNECTION); 166 + status = vhci->port_status[rhport]; 163 167 164 - spin_unlock_irqrestore(&the_controller->lock, flags); 165 - usb_hcd_poll_rh_status(vhci_to_hcd(the_controller)); 168 + status &= ~USB_PORT_STAT_CONNECTION; 169 + status |= (1 << USB_PORT_FEAT_C_CONNECTION); 170 + 171 + vhci->port_status[rhport] = status; 172 + 173 + spin_unlock_irqrestore(&vhci->lock, flags); 174 + usb_hcd_poll_rh_status(vhci_to_hcd(vhci)); 166 175 } 167 176 168 177 #define PORT_C_MASK \ ··· 203 188 int changed = 0; 204 189 unsigned long flags; 205 190 206 - retval = DIV_ROUND_UP(VHCI_NPORTS + 1, 8); 191 + retval = DIV_ROUND_UP(VHCI_HC_PORTS + 1, 8); 207 192 memset(buf, 0, retval); 208 193 209 194 vhci = hcd_to_vhci(hcd); ··· 215 200 } 216 201 217 202 /* check pseudo status register for each port */ 218 - for (rhport = 0; rhport < VHCI_NPORTS; rhport++) { 203 + for (rhport = 0; rhport < VHCI_HC_PORTS; rhport++) { 219 204 if ((vhci->port_status[rhport] & PORT_C_MASK)) { 220 205 /* The status of a port has been changed, */ 221 206 usbip_dbg_vhci_rh("port %d status changed\n", rhport); ··· 240 225 desc->bDescLength = 9; 241 226 desc->wHubCharacteristics = cpu_to_le16( 242 227 HUB_CHAR_INDV_PORT_LPSM | HUB_CHAR_COMMON_OCPM); 243 - desc->bNbrPorts = VHCI_NPORTS; 228 + desc->bNbrPorts = VHCI_HC_PORTS; 244 229 desc->u.hs.DeviceRemovable[0] = 0xff; 245 230 desc->u.hs.DeviceRemovable[1] = 0xff; 246 231 } ··· 253 238 int rhport; 254 239 unsigned long flags; 255 240 256 - u32 prev_port_status[VHCI_NPORTS]; 241 + u32 prev_port_status[VHCI_HC_PORTS]; 257 242 258 243 if (!HCD_HW_ACCESSIBLE(hcd)) 259 244 return -ETIMEDOUT; ··· 264 249 */ 265 250 usbip_dbg_vhci_rh("typeReq %x wValue %x wIndex %x\n", typeReq, wValue, 266 251 wIndex); 267 - if (wIndex > VHCI_NPORTS) 252 + if (wIndex > VHCI_HC_PORTS) 268 253 pr_err("invalid port number %d\n", wIndex); 269 254 rhport = ((__u8)(wIndex & 0x00ff)) - 1; 270 255 ··· 330 315 break; 331 316 case GetPortStatus: 332 317 usbip_dbg_vhci_rh(" GetPortStatus port %x\n", wIndex); 333 - if (wIndex > VHCI_NPORTS || wIndex < 1) { 318 + if (wIndex > VHCI_HC_PORTS || wIndex < 1) { 334 319 pr_err("invalid port number %d\n", wIndex); 335 320 retval = -EPIPE; 336 321 } ··· 431 416 432 417 static struct vhci_device *get_vdev(struct usb_device *udev) 433 418 { 434 - int i; 419 + struct platform_device *pdev; 420 + struct usb_hcd *hcd; 421 + struct vhci_hcd *vhci; 422 + int pdev_nr, rhport; 435 423 436 424 if (!udev) 437 425 return NULL; 438 426 439 - for (i = 0; i < VHCI_NPORTS; i++) 440 - if (the_controller->vdev[i].udev == udev) 441 - return port_to_vdev(i); 427 + for (pdev_nr = 0; pdev_nr < vhci_num_controllers; pdev_nr++) { 428 + pdev = *(vhci_pdevs + pdev_nr); 429 + if (pdev == NULL) 430 + continue; 431 + hcd = platform_get_drvdata(pdev); 432 + if (hcd == NULL) 433 + continue; 434 + vhci = hcd_to_vhci(hcd); 435 + for (rhport = 0; rhport < VHCI_HC_PORTS; rhport++) { 436 + if (vhci->vdev[rhport].udev == udev) 437 + return &vhci->vdev[rhport]; 438 + } 439 + } 442 440 443 441 return NULL; 444 442 } ··· 460 432 { 461 433 struct vhci_device *vdev = get_vdev(urb->dev); 462 434 struct vhci_priv *priv; 435 + struct vhci_hcd *vhci = vdev_to_vhci(vdev); 463 436 unsigned long flags; 464 437 465 438 if (!vdev) { ··· 476 447 477 448 spin_lock_irqsave(&vdev->priv_lock, flags); 478 449 479 - priv->seqnum = atomic_inc_return(&the_controller->seqnum); 450 + priv->seqnum = atomic_inc_return(&vhci->seqnum); 480 451 if (priv->seqnum == 0xffff) 481 452 dev_info(&urb->dev->dev, "seqnum max\n"); 482 453 ··· 494 465 static int vhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, 495 466 gfp_t mem_flags) 496 467 { 468 + struct vhci_hcd *vhci = hcd_to_vhci(hcd); 497 469 struct device *dev = &urb->dev->dev; 470 + u8 portnum = urb->dev->portnum; 498 471 int ret = 0; 499 472 struct vhci_device *vdev; 500 473 unsigned long flags; ··· 504 473 usbip_dbg_vhci_hc("enter, usb_hcd %p urb %p mem_flags %d\n", 505 474 hcd, urb, mem_flags); 506 475 476 + if (portnum > VHCI_HC_PORTS) { 477 + pr_err("invalid port number %d\n", portnum); 478 + return -ENODEV; 479 + } 480 + vdev = &vhci->vdev[portnum-1]; 481 + 507 482 /* patch to usb_sg_init() is in 2.5.60 */ 508 483 BUG_ON(!urb->transfer_buffer && urb->transfer_buffer_length); 509 484 510 - spin_lock_irqsave(&the_controller->lock, flags); 485 + spin_lock_irqsave(&vhci->lock, flags); 511 486 512 487 if (urb->status != -EINPROGRESS) { 513 488 dev_err(dev, "URB already unlinked!, status %d\n", urb->status); 514 - spin_unlock_irqrestore(&the_controller->lock, flags); 489 + spin_unlock_irqrestore(&vhci->lock, flags); 515 490 return urb->status; 516 491 } 517 - 518 - vdev = port_to_vdev(urb->dev->portnum-1); 519 492 520 493 /* refuse enqueue for dead connection */ 521 494 spin_lock(&vdev->ud.lock); ··· 527 492 vdev->ud.status == VDEV_ST_ERROR) { 528 493 dev_err(dev, "enqueue for inactive port %d\n", vdev->rhport); 529 494 spin_unlock(&vdev->ud.lock); 530 - spin_unlock_irqrestore(&the_controller->lock, flags); 495 + spin_unlock_irqrestore(&vhci->lock, flags); 531 496 return -ENODEV; 532 497 } 533 498 spin_unlock(&vdev->ud.lock); ··· 600 565 601 566 out: 602 567 vhci_tx_urb(urb); 603 - spin_unlock_irqrestore(&the_controller->lock, flags); 568 + spin_unlock_irqrestore(&vhci->lock, flags); 604 569 605 570 return 0; 606 571 607 572 no_need_xmit: 608 573 usb_hcd_unlink_urb_from_ep(hcd, urb); 609 574 no_need_unlink: 610 - spin_unlock_irqrestore(&the_controller->lock, flags); 575 + spin_unlock_irqrestore(&vhci->lock, flags); 611 576 if (!ret) 612 - usb_hcd_giveback_urb(vhci_to_hcd(the_controller), 613 - urb, urb->status); 577 + usb_hcd_giveback_urb(hcd, urb, urb->status); 614 578 return ret; 615 579 } 616 580 ··· 661 627 */ 662 628 static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status) 663 629 { 630 + struct vhci_hcd *vhci = hcd_to_vhci(hcd); 664 631 struct vhci_priv *priv; 665 632 struct vhci_device *vdev; 666 633 unsigned long flags; 667 634 668 635 pr_info("dequeue a urb %p\n", urb); 669 636 670 - spin_lock_irqsave(&the_controller->lock, flags); 637 + spin_lock_irqsave(&vhci->lock, flags); 671 638 672 639 priv = urb->hcpriv; 673 640 if (!priv) { 674 641 /* URB was never linked! or will be soon given back by 675 642 * vhci_rx. */ 676 - spin_unlock_irqrestore(&the_controller->lock, flags); 643 + spin_unlock_irqrestore(&vhci->lock, flags); 677 644 return -EIDRM; 678 645 } 679 646 ··· 683 648 684 649 ret = usb_hcd_check_unlink_urb(hcd, urb, status); 685 650 if (ret) { 686 - spin_unlock_irqrestore(&the_controller->lock, flags); 651 + spin_unlock_irqrestore(&vhci->lock, flags); 687 652 return ret; 688 653 } 689 654 } ··· 711 676 712 677 usb_hcd_unlink_urb_from_ep(hcd, urb); 713 678 714 - spin_unlock_irqrestore(&the_controller->lock, flags); 715 - usb_hcd_giveback_urb(vhci_to_hcd(the_controller), urb, 716 - urb->status); 717 - spin_lock_irqsave(&the_controller->lock, flags); 679 + spin_unlock_irqrestore(&vhci->lock, flags); 680 + usb_hcd_giveback_urb(vhci_to_hcd(vhci), urb, urb->status); 681 + spin_lock_irqsave(&vhci->lock, flags); 718 682 719 683 } else { 720 684 /* tcp connection is alive */ ··· 725 691 unlink = kzalloc(sizeof(struct vhci_unlink), GFP_ATOMIC); 726 692 if (!unlink) { 727 693 spin_unlock(&vdev->priv_lock); 728 - spin_unlock_irqrestore(&the_controller->lock, flags); 694 + spin_unlock_irqrestore(&vhci->lock, flags); 729 695 usbip_event_add(&vdev->ud, VDEV_EVENT_ERROR_MALLOC); 730 696 return -ENOMEM; 731 697 } 732 698 733 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum); 699 + unlink->seqnum = atomic_inc_return(&vhci->seqnum); 734 700 if (unlink->seqnum == 0xffff) 735 701 pr_info("seqnum max\n"); 736 702 ··· 746 712 spin_unlock(&vdev->priv_lock); 747 713 } 748 714 749 - spin_unlock_irqrestore(&the_controller->lock, flags); 715 + spin_unlock_irqrestore(&vhci->lock, flags); 750 716 751 717 usbip_dbg_vhci_hc("leave\n"); 752 718 return 0; ··· 754 720 755 721 static void vhci_device_unlink_cleanup(struct vhci_device *vdev) 756 722 { 723 + struct vhci_hcd *vhci = vdev_to_vhci(vdev); 724 + struct usb_hcd *hcd = vhci_to_hcd(vhci); 757 725 struct vhci_unlink *unlink, *tmp; 758 726 unsigned long flags; 759 727 760 - spin_lock_irqsave(&the_controller->lock, flags); 728 + spin_lock_irqsave(&vhci->lock, flags); 761 729 spin_lock(&vdev->priv_lock); 762 730 763 731 list_for_each_entry_safe(unlink, tmp, &vdev->unlink_tx, list) { ··· 788 752 789 753 urb->status = -ENODEV; 790 754 791 - usb_hcd_unlink_urb_from_ep(vhci_to_hcd(the_controller), urb); 755 + usb_hcd_unlink_urb_from_ep(hcd, urb); 792 756 793 757 list_del(&unlink->list); 794 758 795 759 spin_unlock(&vdev->priv_lock); 796 - spin_unlock_irqrestore(&the_controller->lock, flags); 760 + spin_unlock_irqrestore(&vhci->lock, flags); 797 761 798 - usb_hcd_giveback_urb(vhci_to_hcd(the_controller), urb, 799 - urb->status); 762 + usb_hcd_giveback_urb(hcd, urb, urb->status); 800 763 801 - spin_lock_irqsave(&the_controller->lock, flags); 764 + spin_lock_irqsave(&vhci->lock, flags); 802 765 spin_lock(&vdev->priv_lock); 803 766 804 767 kfree(unlink); 805 768 } 806 769 807 770 spin_unlock(&vdev->priv_lock); 808 - spin_unlock_irqrestore(&the_controller->lock, flags); 771 + spin_unlock_irqrestore(&vhci->lock, flags); 809 772 } 810 773 811 774 /* ··· 862 827 * is actually given back by vhci_rx after receiving its return pdu. 863 828 * 864 829 */ 865 - rh_port_disconnect(vdev->rhport); 830 + rh_port_disconnect(vdev); 866 831 867 832 pr_info("disconnect device\n"); 868 833 } ··· 901 866 902 867 static void vhci_device_init(struct vhci_device *vdev) 903 868 { 904 - memset(vdev, 0, sizeof(*vdev)); 869 + memset(vdev, 0, sizeof(struct vhci_device)); 905 870 906 871 vdev->ud.side = USBIP_VHCI; 907 872 vdev->ud.status = VDEV_ST_NULL; ··· 922 887 usbip_start_eh(&vdev->ud); 923 888 } 924 889 890 + static int hcd_name_to_id(const char *name) 891 + { 892 + char *c; 893 + long val; 894 + int ret; 895 + 896 + c = strchr(name, '.'); 897 + if (c == NULL) 898 + return 0; 899 + 900 + ret = kstrtol(c+1, 10, &val); 901 + if (ret < 0) 902 + return ret; 903 + 904 + return val; 905 + } 906 + 925 907 static int vhci_start(struct usb_hcd *hcd) 926 908 { 927 909 struct vhci_hcd *vhci = hcd_to_vhci(hcd); 928 - int rhport; 910 + int id, rhport; 929 911 int err = 0; 930 912 931 913 usbip_dbg_vhci_hc("enter vhci_start\n"); 932 914 933 915 /* initialize private data of usb_hcd */ 934 916 935 - for (rhport = 0; rhport < VHCI_NPORTS; rhport++) { 917 + for (rhport = 0; rhport < VHCI_HC_PORTS; rhport++) { 936 918 struct vhci_device *vdev = &vhci->vdev[rhport]; 937 919 938 920 vhci_device_init(vdev); ··· 962 910 hcd->power_budget = 0; /* no limit */ 963 911 hcd->uses_new_polling = 1; 964 912 913 + id = hcd_name_to_id(hcd_name(hcd)); 914 + if (id < 0) { 915 + pr_err("invalid vhci name %s\n", hcd_name(hcd)); 916 + return -EINVAL; 917 + } 918 + 965 919 /* vhci_hcd is now ready to be controlled through sysfs */ 966 - err = sysfs_create_group(&vhci_dev(vhci)->kobj, &dev_attr_group); 967 - if (err) { 968 - pr_err("create sysfs files\n"); 969 - return err; 920 + if (id == 0) { 921 + err = vhci_init_attr_group(); 922 + if (err) { 923 + pr_err("init attr group\n"); 924 + return err; 925 + } 926 + err = sysfs_create_group(&hcd_dev(hcd)->kobj, &vhci_attr_group); 927 + if (err) { 928 + pr_err("create sysfs files\n"); 929 + vhci_finish_attr_group(); 930 + return err; 931 + } 932 + pr_info("created sysfs %s\n", hcd_name(hcd)); 970 933 } 971 934 972 935 return 0; ··· 990 923 static void vhci_stop(struct usb_hcd *hcd) 991 924 { 992 925 struct vhci_hcd *vhci = hcd_to_vhci(hcd); 993 - int rhport = 0; 926 + int id, rhport; 994 927 995 928 usbip_dbg_vhci_hc("stop VHCI controller\n"); 996 929 997 930 /* 1. remove the userland interface of vhci_hcd */ 998 - sysfs_remove_group(&vhci_dev(vhci)->kobj, &dev_attr_group); 931 + id = hcd_name_to_id(hcd_name(hcd)); 932 + if (id == 0) { 933 + sysfs_remove_group(&hcd_dev(hcd)->kobj, &vhci_attr_group); 934 + vhci_finish_attr_group(); 935 + } 999 936 1000 937 /* 2. shutdown all the ports of vhci_hcd */ 1001 - for (rhport = 0; rhport < VHCI_NPORTS; rhport++) { 938 + for (rhport = 0; rhport < VHCI_HC_PORTS; rhport++) { 1002 939 struct vhci_device *vdev = &vhci->vdev[rhport]; 1003 940 1004 941 usbip_event_add(&vdev->ud, VDEV_EVENT_REMOVED); ··· 1096 1025 } 1097 1026 hcd->has_tt = 1; 1098 1027 1099 - /* this is private data for vhci_hcd */ 1100 - the_controller = hcd_to_vhci(hcd); 1101 - 1102 1028 /* 1103 1029 * Finish generic HCD structure initialization and register. 1104 1030 * Call the driver's reset() and start() routines. ··· 1104 1036 if (ret != 0) { 1105 1037 pr_err("usb_add_hcd failed %d\n", ret); 1106 1038 usb_put_hcd(hcd); 1107 - the_controller = NULL; 1108 1039 return ret; 1109 1040 } 1110 1041 ··· 1126 1059 */ 1127 1060 usb_remove_hcd(hcd); 1128 1061 usb_put_hcd(hcd); 1129 - the_controller = NULL; 1130 1062 1131 1063 return 0; 1132 1064 } ··· 1136 1070 static int vhci_hcd_suspend(struct platform_device *pdev, pm_message_t state) 1137 1071 { 1138 1072 struct usb_hcd *hcd; 1139 - int rhport = 0; 1073 + struct vhci_hcd *vhci; 1074 + int rhport; 1140 1075 int connected = 0; 1141 1076 int ret = 0; 1142 1077 unsigned long flags; 1143 1078 1144 1079 hcd = platform_get_drvdata(pdev); 1080 + if (!hcd) 1081 + return 0; 1082 + vhci = hcd_to_vhci(hcd); 1145 1083 1146 - spin_lock_irqsave(&the_controller->lock, flags); 1084 + spin_lock_irqsave(&vhci->lock, flags); 1147 1085 1148 - for (rhport = 0; rhport < VHCI_NPORTS; rhport++) 1149 - if (the_controller->port_status[rhport] & 1150 - USB_PORT_STAT_CONNECTION) 1086 + for (rhport = 0; rhport < VHCI_HC_PORTS; rhport++) 1087 + if (vhci->port_status[rhport] & USB_PORT_STAT_CONNECTION) 1151 1088 connected += 1; 1152 1089 1153 - spin_unlock_irqrestore(&the_controller->lock, flags); 1090 + spin_unlock_irqrestore(&vhci->lock, flags); 1154 1091 1155 1092 if (connected > 0) { 1156 1093 dev_info(&pdev->dev, ··· 1175 1106 dev_dbg(&pdev->dev, "%s\n", __func__); 1176 1107 1177 1108 hcd = platform_get_drvdata(pdev); 1109 + if (!hcd) 1110 + return 0; 1178 1111 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); 1179 1112 usb_hcd_poll_rh_status(hcd); 1180 1113 ··· 1200 1129 }, 1201 1130 }; 1202 1131 1203 - /* 1204 - * The VHCI 'device' is 'virtual'; not a real plug&play hardware. 1205 - * We need to add this virtual device as a platform device arbitrarily: 1206 - * 1. platform_device_register() 1207 - */ 1208 - static void the_pdev_release(struct device *dev) 1132 + static int add_platform_device(int id) 1209 1133 { 1134 + struct platform_device *pdev; 1135 + int dev_nr; 1136 + 1137 + if (id == 0) 1138 + dev_nr = -1; 1139 + else 1140 + dev_nr = id; 1141 + 1142 + pdev = platform_device_register_simple(driver_name, dev_nr, NULL, 0); 1143 + if (IS_ERR(pdev)) 1144 + return PTR_ERR(pdev); 1145 + 1146 + *(vhci_pdevs + id) = pdev; 1147 + return 0; 1210 1148 } 1211 1149 1212 - static struct platform_device the_pdev = { 1213 - /* should be the same name as driver_name */ 1214 - .name = driver_name, 1215 - .id = -1, 1216 - .dev = { 1217 - .release = the_pdev_release, 1218 - }, 1219 - }; 1150 + static void del_platform_devices(void) 1151 + { 1152 + struct platform_device *pdev; 1153 + int i; 1154 + 1155 + for (i = 0; i < vhci_num_controllers; i++) { 1156 + pdev = *(vhci_pdevs + i); 1157 + if (pdev != NULL) 1158 + platform_device_unregister(pdev); 1159 + *(vhci_pdevs + i) = NULL; 1160 + } 1161 + sysfs_remove_link(&platform_bus.kobj, driver_name); 1162 + } 1220 1163 1221 1164 static int __init vhci_hcd_init(void) 1222 1165 { 1223 - int ret; 1166 + int i, ret; 1224 1167 1225 1168 if (usb_disabled()) 1226 1169 return -ENODEV; 1170 + 1171 + if (vhci_num_controllers < 1) 1172 + vhci_num_controllers = 1; 1173 + 1174 + vhci_pdevs = kcalloc(vhci_num_controllers, sizeof(void *), GFP_KERNEL); 1175 + if (vhci_pdevs == NULL) 1176 + return -ENOMEM; 1227 1177 1228 1178 ret = platform_driver_register(&vhci_driver); 1229 1179 if (ret) 1230 1180 goto err_driver_register; 1231 1181 1232 - ret = platform_device_register(&the_pdev); 1233 - if (ret) 1234 - goto err_platform_device_register; 1182 + for (i = 0; i < vhci_num_controllers; i++) { 1183 + ret = add_platform_device(i); 1184 + if (ret) 1185 + goto err_platform_device_register; 1186 + } 1235 1187 1236 1188 pr_info(DRIVER_DESC " v" USBIP_VERSION "\n"); 1237 1189 return ret; 1238 1190 1239 1191 err_platform_device_register: 1192 + del_platform_devices(); 1240 1193 platform_driver_unregister(&vhci_driver); 1241 1194 err_driver_register: 1195 + kfree(vhci_pdevs); 1242 1196 return ret; 1243 1197 } 1244 1198 1245 1199 static void __exit vhci_hcd_exit(void) 1246 1200 { 1247 - platform_device_unregister(&the_pdev); 1201 + del_platform_devices(); 1248 1202 platform_driver_unregister(&vhci_driver); 1203 + kfree(vhci_pdevs); 1249 1204 } 1250 1205 1251 1206 module_init(vhci_hcd_init);
+11 -10
drivers/usb/usbip/vhci_rx.c
··· 70 70 static void vhci_recv_ret_submit(struct vhci_device *vdev, 71 71 struct usbip_header *pdu) 72 72 { 73 + struct vhci_hcd *vhci = vdev_to_vhci(vdev); 73 74 struct usbip_device *ud = &vdev->ud; 74 75 struct urb *urb; 75 76 unsigned long flags; ··· 82 81 if (!urb) { 83 82 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum); 84 83 pr_info("max seqnum %d\n", 85 - atomic_read(&the_controller->seqnum)); 84 + atomic_read(&vhci->seqnum)); 86 85 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP); 87 86 return; 88 87 } ··· 106 105 107 106 usbip_dbg_vhci_rx("now giveback urb %p\n", urb); 108 107 109 - spin_lock_irqsave(&the_controller->lock, flags); 110 - usb_hcd_unlink_urb_from_ep(vhci_to_hcd(the_controller), urb); 111 - spin_unlock_irqrestore(&the_controller->lock, flags); 108 + spin_lock_irqsave(&vhci->lock, flags); 109 + usb_hcd_unlink_urb_from_ep(vhci_to_hcd(vhci), urb); 110 + spin_unlock_irqrestore(&vhci->lock, flags); 112 111 113 - usb_hcd_giveback_urb(vhci_to_hcd(the_controller), urb, urb->status); 112 + usb_hcd_giveback_urb(vhci_to_hcd(vhci), urb, urb->status); 114 113 115 114 usbip_dbg_vhci_rx("Leave\n"); 116 115 } ··· 143 142 static void vhci_recv_ret_unlink(struct vhci_device *vdev, 144 143 struct usbip_header *pdu) 145 144 { 145 + struct vhci_hcd *vhci = vdev_to_vhci(vdev); 146 146 struct vhci_unlink *unlink; 147 147 struct urb *urb; 148 148 unsigned long flags; ··· 176 174 urb->status = pdu->u.ret_unlink.status; 177 175 pr_info("urb->status %d\n", urb->status); 178 176 179 - spin_lock_irqsave(&the_controller->lock, flags); 180 - usb_hcd_unlink_urb_from_ep(vhci_to_hcd(the_controller), urb); 181 - spin_unlock_irqrestore(&the_controller->lock, flags); 177 + spin_lock_irqsave(&vhci->lock, flags); 178 + usb_hcd_unlink_urb_from_ep(vhci_to_hcd(vhci), urb); 179 + spin_unlock_irqrestore(&vhci->lock, flags); 182 180 183 - usb_hcd_giveback_urb(vhci_to_hcd(the_controller), urb, 184 - urb->status); 181 + usb_hcd_giveback_urb(vhci_to_hcd(vhci), urb, urb->status); 185 182 } 186 183 187 184 kfree(unlink);
+230 -66
drivers/usb/usbip/vhci_sysfs.c
··· 1 1 /* 2 2 * Copyright (C) 2003-2008 Takahiro Hirofuchi 3 + * Copyright (C) 2015-2016 Nobuo Iwata 3 4 * 4 5 * This is free software; you can redistribute it and/or modify 5 6 * it under the terms of the GNU General Public License as published by ··· 21 20 #include <linux/kthread.h> 22 21 #include <linux/file.h> 23 22 #include <linux/net.h> 23 + #include <linux/platform_device.h> 24 + #include <linux/slab.h> 24 25 25 26 #include "usbip_common.h" 26 27 #include "vhci.h" ··· 30 27 /* TODO: refine locking ?*/ 31 28 32 29 /* Sysfs entry to show port status */ 33 - static ssize_t status_show(struct device *dev, struct device_attribute *attr, 34 - char *out) 30 + static ssize_t status_show_vhci(int pdev_nr, char *out) 35 31 { 32 + struct platform_device *pdev = *(vhci_pdevs + pdev_nr); 33 + struct vhci_hcd *vhci; 36 34 char *s = out; 37 35 int i = 0; 38 36 unsigned long flags; 39 37 40 - BUG_ON(!the_controller || !out); 38 + if (!pdev || !out) { 39 + usbip_dbg_vhci_sysfs("show status error\n"); 40 + return 0; 41 + } 41 42 42 - spin_lock_irqsave(&the_controller->lock, flags); 43 + vhci = hcd_to_vhci(platform_get_drvdata(pdev)); 44 + 45 + spin_lock_irqsave(&vhci->lock, flags); 43 46 44 47 /* 45 48 * output example: 46 - * prt sta spd dev socket local_busid 47 - * 000 004 000 000 c5a7bb80 1-2.3 48 - * 001 004 000 000 d8cee980 2-3.4 49 + * port sta spd dev socket local_busid 50 + * 0000 004 000 00000000 c5a7bb80 1-2.3 51 + * 0001 004 000 00000000 d8cee980 2-3.4 49 52 * 50 53 * IP address can be retrieved from a socket pointer address by looking 51 54 * up /proc/net/{tcp,tcp6}. Also, a userland program may remember a 52 55 * port number and its peer IP address. 53 56 */ 54 - out += sprintf(out, 55 - "prt sta spd bus dev socket local_busid\n"); 56 - 57 - for (i = 0; i < VHCI_NPORTS; i++) { 58 - struct vhci_device *vdev = port_to_vdev(i); 57 + for (i = 0; i < VHCI_HC_PORTS; i++) { 58 + struct vhci_device *vdev = &vhci->vdev[i]; 59 59 60 60 spin_lock(&vdev->ud.lock); 61 - out += sprintf(out, "%03u %03u ", i, vdev->ud.status); 61 + out += sprintf(out, "%04u %03u ", 62 + (pdev_nr * VHCI_HC_PORTS) + i, 63 + vdev->ud.status); 62 64 63 65 if (vdev->ud.status == VDEV_ST_USED) { 64 66 out += sprintf(out, "%03u %08x ", 65 - vdev->speed, vdev->devid); 66 - out += sprintf(out, "%16p ", vdev->ud.tcp_socket); 67 - out += sprintf(out, "%s", dev_name(&vdev->udev->dev)); 67 + vdev->speed, vdev->devid); 68 + out += sprintf(out, "%16p %s", 69 + vdev->ud.tcp_socket, 70 + dev_name(&vdev->udev->dev)); 68 71 69 72 } else { 70 - out += sprintf(out, "000 000 000 0000000000000000 0-0"); 73 + out += sprintf(out, "000 00000000 "); 74 + out += sprintf(out, "0000000000000000 0-0"); 71 75 } 72 76 73 77 out += sprintf(out, "\n"); 74 78 spin_unlock(&vdev->ud.lock); 75 79 } 76 80 77 - spin_unlock_irqrestore(&the_controller->lock, flags); 81 + spin_unlock_irqrestore(&vhci->lock, flags); 78 82 79 83 return out - s; 80 84 } 81 - static DEVICE_ATTR_RO(status); 85 + 86 + static ssize_t status_show_not_ready(int pdev_nr, char *out) 87 + { 88 + char *s = out; 89 + int i = 0; 90 + 91 + for (i = 0; i < VHCI_HC_PORTS; i++) { 92 + out += sprintf(out, "%04u %03u ", 93 + (pdev_nr * VHCI_HC_PORTS) + i, 94 + VDEV_ST_NOTASSIGNED); 95 + out += sprintf(out, "000 00000000 0000000000000000 0-0"); 96 + out += sprintf(out, "\n"); 97 + } 98 + return out - s; 99 + } 100 + 101 + static int status_name_to_id(const char *name) 102 + { 103 + char *c; 104 + long val; 105 + int ret; 106 + 107 + c = strchr(name, '.'); 108 + if (c == NULL) 109 + return 0; 110 + 111 + ret = kstrtol(c+1, 10, &val); 112 + if (ret < 0) 113 + return ret; 114 + 115 + return val; 116 + } 117 + 118 + static ssize_t status_show(struct device *dev, 119 + struct device_attribute *attr, char *out) 120 + { 121 + char *s = out; 122 + int pdev_nr; 123 + 124 + out += sprintf(out, 125 + "port sta spd dev socket local_busid\n"); 126 + 127 + pdev_nr = status_name_to_id(attr->attr.name); 128 + if (pdev_nr < 0) 129 + out += status_show_not_ready(pdev_nr, out); 130 + else 131 + out += status_show_vhci(pdev_nr, out); 132 + 133 + return out - s; 134 + } 135 + 136 + static ssize_t nports_show(struct device *dev, struct device_attribute *attr, 137 + char *out) 138 + { 139 + char *s = out; 140 + 141 + out += sprintf(out, "%d\n", VHCI_HC_PORTS * vhci_num_controllers); 142 + return out - s; 143 + } 144 + static DEVICE_ATTR_RO(nports); 82 145 83 146 /* Sysfs entry to shutdown a virtual connection */ 84 - static int vhci_port_disconnect(__u32 rhport) 147 + static int vhci_port_disconnect(struct vhci_hcd *vhci, __u32 rhport) 85 148 { 86 - struct vhci_device *vdev; 149 + struct vhci_device *vdev = &vhci->vdev[rhport]; 87 150 unsigned long flags; 88 151 89 152 usbip_dbg_vhci_sysfs("enter\n"); 90 153 91 154 /* lock */ 92 - spin_lock_irqsave(&the_controller->lock, flags); 93 - 94 - vdev = port_to_vdev(rhport); 95 - 155 + spin_lock_irqsave(&vhci->lock, flags); 96 156 spin_lock(&vdev->ud.lock); 157 + 97 158 if (vdev->ud.status == VDEV_ST_NULL) { 98 159 pr_err("not connected %d\n", vdev->ud.status); 99 160 100 161 /* unlock */ 101 162 spin_unlock(&vdev->ud.lock); 102 - spin_unlock_irqrestore(&the_controller->lock, flags); 163 + spin_unlock_irqrestore(&vhci->lock, flags); 103 164 104 165 return -EINVAL; 105 166 } 106 167 107 168 /* unlock */ 108 169 spin_unlock(&vdev->ud.lock); 109 - spin_unlock_irqrestore(&the_controller->lock, flags); 170 + spin_unlock_irqrestore(&vhci->lock, flags); 110 171 111 172 usbip_event_add(&vdev->ud, VDEV_EVENT_DOWN); 112 173 113 174 return 0; 114 175 } 115 176 177 + static int valid_port(__u32 pdev_nr, __u32 rhport) 178 + { 179 + if (pdev_nr >= vhci_num_controllers) { 180 + pr_err("pdev %u\n", pdev_nr); 181 + return 0; 182 + } 183 + if (rhport >= VHCI_HC_PORTS) { 184 + pr_err("rhport %u\n", rhport); 185 + return 0; 186 + } 187 + return 1; 188 + } 189 + 116 190 static ssize_t store_detach(struct device *dev, struct device_attribute *attr, 117 191 const char *buf, size_t count) 118 192 { 119 - int err; 120 - __u32 rhport = 0; 193 + __u32 port = 0, pdev_nr = 0, rhport = 0; 194 + struct usb_hcd *hcd; 195 + int ret; 121 196 122 - if (sscanf(buf, "%u", &rhport) != 1) 197 + if (kstrtoint(buf, 10, &port) < 0) 123 198 return -EINVAL; 124 199 125 - /* check rhport */ 126 - if (rhport >= VHCI_NPORTS) { 127 - dev_err(dev, "invalid port %u\n", rhport); 200 + pdev_nr = port_to_pdev_nr(port); 201 + rhport = port_to_rhport(port); 202 + 203 + if (!valid_port(pdev_nr, rhport)) 128 204 return -EINVAL; 205 + 206 + hcd = platform_get_drvdata(*(vhci_pdevs + pdev_nr)); 207 + if (hcd == NULL) { 208 + dev_err(dev, "port is not ready %u\n", port); 209 + return -EAGAIN; 129 210 } 130 211 131 - err = vhci_port_disconnect(rhport); 132 - if (err < 0) 212 + ret = vhci_port_disconnect(hcd_to_vhci(hcd), rhport); 213 + if (ret < 0) 133 214 return -EINVAL; 134 215 135 216 usbip_dbg_vhci_sysfs("Leave\n"); ··· 222 135 } 223 136 static DEVICE_ATTR(detach, S_IWUSR, NULL, store_detach); 224 137 225 - /* Sysfs entry to establish a virtual connection */ 226 - static int valid_args(__u32 rhport, enum usb_device_speed speed) 138 + static int valid_args(__u32 pdev_nr, __u32 rhport, enum usb_device_speed speed) 227 139 { 228 - /* check rhport */ 229 - if (rhport >= VHCI_NPORTS) { 230 - pr_err("port %u\n", rhport); 231 - return -EINVAL; 140 + if (!valid_port(pdev_nr, rhport)) { 141 + return 0; 232 142 } 233 143 234 - /* check speed */ 235 144 switch (speed) { 236 145 case USB_SPEED_LOW: 237 146 case USB_SPEED_FULL: ··· 237 154 default: 238 155 pr_err("Failed attach request for unsupported USB speed: %s\n", 239 156 usb_speed_string(speed)); 240 - return -EINVAL; 157 + return 0; 241 158 } 242 159 243 - return 0; 160 + return 1; 244 161 } 245 162 163 + /* Sysfs entry to establish a virtual connection */ 246 164 /* 247 165 * To start a new USB/IP attachment, a userland program needs to setup a TCP 248 166 * connection and then write its socket descriptor with remote device ··· 258 174 static ssize_t store_attach(struct device *dev, struct device_attribute *attr, 259 175 const char *buf, size_t count) 260 176 { 261 - struct vhci_device *vdev; 262 177 struct socket *socket; 263 178 int sockfd = 0; 264 - __u32 rhport = 0, devid = 0, speed = 0; 179 + __u32 port = 0, pdev_nr = 0, rhport = 0, devid = 0, speed = 0; 180 + struct usb_hcd *hcd; 181 + struct vhci_hcd *vhci; 182 + struct vhci_device *vdev; 265 183 int err; 266 184 unsigned long flags; 267 185 ··· 273 187 * @devid: unique device identifier in a remote host 274 188 * @speed: usb device speed in a remote host 275 189 */ 276 - if (sscanf(buf, "%u %u %u %u", &rhport, &sockfd, &devid, &speed) != 4) 190 + if (sscanf(buf, "%u %u %u %u", &port, &sockfd, &devid, &speed) != 4) 277 191 return -EINVAL; 192 + pdev_nr = port_to_pdev_nr(port); 193 + rhport = port_to_rhport(port); 278 194 279 - usbip_dbg_vhci_sysfs("rhport(%u) sockfd(%u) devid(%u) speed(%u)\n", 280 - rhport, sockfd, devid, speed); 195 + usbip_dbg_vhci_sysfs("port(%u) pdev(%d) rhport(%u)\n", 196 + port, pdev_nr, rhport); 197 + usbip_dbg_vhci_sysfs("sockfd(%u) devid(%u) speed(%u)\n", 198 + sockfd, devid, speed); 281 199 282 200 /* check received parameters */ 283 - if (valid_args(rhport, speed) < 0) 201 + if (!valid_args(pdev_nr, rhport, speed)) 284 202 return -EINVAL; 203 + 204 + hcd = platform_get_drvdata(*(vhci_pdevs + pdev_nr)); 205 + if (hcd == NULL) { 206 + dev_err(dev, "port %d is not ready\n", port); 207 + return -EAGAIN; 208 + } 209 + vhci = hcd_to_vhci(hcd); 210 + vdev = &vhci->vdev[rhport]; 285 211 286 212 /* Extract socket from fd. */ 287 213 socket = sockfd_lookup(sockfd, &err); ··· 303 205 /* now need lock until setting vdev status as used */ 304 206 305 207 /* begin a lock */ 306 - spin_lock_irqsave(&the_controller->lock, flags); 307 - vdev = port_to_vdev(rhport); 208 + spin_lock_irqsave(&vhci->lock, flags); 308 209 spin_lock(&vdev->ud.lock); 309 210 310 211 if (vdev->ud.status != VDEV_ST_NULL) { 311 212 /* end of the lock */ 312 213 spin_unlock(&vdev->ud.lock); 313 - spin_unlock_irqrestore(&the_controller->lock, flags); 214 + spin_unlock_irqrestore(&vhci->lock, flags); 314 215 315 216 sockfd_put(socket); 316 217 ··· 317 220 return -EINVAL; 318 221 } 319 222 320 - dev_info(dev, 321 - "rhport(%u) sockfd(%d) devid(%u) speed(%u) speed_str(%s)\n", 322 - rhport, sockfd, devid, speed, usb_speed_string(speed)); 223 + dev_info(dev, "pdev(%u) rhport(%u) sockfd(%d)\n", 224 + pdev_nr, rhport, sockfd); 225 + dev_info(dev, "devid(%u) speed(%u) speed_str(%s)\n", 226 + devid, speed, usb_speed_string(speed)); 323 227 324 228 vdev->devid = devid; 325 229 vdev->speed = speed; ··· 328 230 vdev->ud.status = VDEV_ST_NOTASSIGNED; 329 231 330 232 spin_unlock(&vdev->ud.lock); 331 - spin_unlock_irqrestore(&the_controller->lock, flags); 233 + spin_unlock_irqrestore(&vhci->lock, flags); 332 234 /* end the lock */ 333 235 334 236 vdev->ud.tcp_rx = kthread_get_run(vhci_rx_loop, &vdev->ud, "vhci_rx"); 335 237 vdev->ud.tcp_tx = kthread_get_run(vhci_tx_loop, &vdev->ud, "vhci_tx"); 336 238 337 - rh_port_connect(rhport, speed); 239 + rh_port_connect(vdev, speed); 338 240 339 241 return count; 340 242 } 341 243 static DEVICE_ATTR(attach, S_IWUSR, NULL, store_attach); 342 244 343 - static struct attribute *dev_attrs[] = { 344 - &dev_attr_status.attr, 345 - &dev_attr_detach.attr, 346 - &dev_attr_attach.attr, 347 - &dev_attr_usbip_debug.attr, 348 - NULL, 245 + #define MAX_STATUS_NAME 16 246 + 247 + struct status_attr { 248 + struct device_attribute attr; 249 + char name[MAX_STATUS_NAME+1]; 349 250 }; 350 251 351 - const struct attribute_group dev_attr_group = { 352 - .attrs = dev_attrs, 252 + static struct status_attr *status_attrs; 253 + 254 + static void set_status_attr(int id) 255 + { 256 + struct status_attr *status; 257 + 258 + status = status_attrs + id; 259 + if (id == 0) 260 + strcpy(status->name, "status"); 261 + else 262 + snprintf(status->name, MAX_STATUS_NAME+1, "status.%d", id); 263 + status->attr.attr.name = status->name; 264 + status->attr.attr.mode = S_IRUGO; 265 + status->attr.show = status_show; 266 + } 267 + 268 + static int init_status_attrs(void) 269 + { 270 + int id; 271 + 272 + status_attrs = kcalloc(vhci_num_controllers, sizeof(struct status_attr), 273 + GFP_KERNEL); 274 + if (status_attrs == NULL) 275 + return -ENOMEM; 276 + 277 + for (id = 0; id < vhci_num_controllers; id++) 278 + set_status_attr(id); 279 + 280 + return 0; 281 + } 282 + 283 + static void finish_status_attrs(void) 284 + { 285 + kfree(status_attrs); 286 + } 287 + 288 + struct attribute_group vhci_attr_group = { 289 + .attrs = NULL, 353 290 }; 291 + 292 + int vhci_init_attr_group(void) 293 + { 294 + struct attribute **attrs; 295 + int ret, i; 296 + 297 + attrs = kcalloc((vhci_num_controllers + 5), sizeof(struct attribute *), 298 + GFP_KERNEL); 299 + if (attrs == NULL) 300 + return -ENOMEM; 301 + 302 + ret = init_status_attrs(); 303 + if (ret) { 304 + kfree(attrs); 305 + return ret; 306 + } 307 + *attrs = &dev_attr_nports.attr; 308 + *(attrs + 1) = &dev_attr_detach.attr; 309 + *(attrs + 2) = &dev_attr_attach.attr; 310 + *(attrs + 3) = &dev_attr_usbip_debug.attr; 311 + for (i = 0; i < vhci_num_controllers; i++) 312 + *(attrs + i + 4) = &((status_attrs + i)->attr.attr); 313 + vhci_attr_group.attrs = attrs; 314 + return 0; 315 + } 316 + 317 + void vhci_finish_attr_group(void) 318 + { 319 + finish_status_attrs(); 320 + kfree(vhci_attr_group.attrs); 321 + }
+1 -1
drivers/usb/usbip/vudc_dev.c
··· 450 450 if (ud->tcp_socket) 451 451 kernel_sock_shutdown(ud->tcp_socket, SHUT_RDWR); 452 452 453 - if (ud->tcp_tx) { 453 + if (ud->tcp_rx) { 454 454 kthread_stop_put(ud->tcp_rx); 455 455 ud->tcp_rx = NULL; 456 456 }
+1 -1
drivers/usb/usbip/vudc_rx.c
··· 142 142 urb_p->urb->status = -EINPROGRESS; 143 143 144 144 /* FIXME: more pipe setup to please usbip_common */ 145 - urb_p->urb->pipe &= ~(11 << 30); 145 + urb_p->urb->pipe &= ~(3 << 30); 146 146 switch (urb_p->ep->type) { 147 147 case USB_ENDPOINT_XFER_BULK: 148 148 urb_p->urb->pipe |= (PIPE_BULK << 30);
+1 -2
drivers/usb/wusbcore/cbaf.c
··· 610 610 cbaf->usb_iface = usb_get_intf(iface); 611 611 result = cbaf_check(cbaf); 612 612 if (result < 0) { 613 - dev_err(dev, "This device is not WUSB-CBAF compliant" 614 - "and is not supported yet.\n"); 613 + dev_err(dev, "This device is not WUSB-CBAF compliant and is not supported yet.\n"); 615 614 goto error_check; 616 615 } 617 616
+1 -3
drivers/usb/wusbcore/crypto.c
··· 229 229 zero_padding = sizeof(struct aes_ccm_block) - zero_padding; 230 230 dst_size = blen + sizeof(b0) + sizeof(b1) + zero_padding; 231 231 dst_buf = kzalloc(dst_size, GFP_KERNEL); 232 - if (dst_buf == NULL) { 233 - printk(KERN_ERR "E: can't alloc destination buffer\n"); 232 + if (!dst_buf) 234 233 goto error_dst_buf; 235 - } 236 234 237 235 memset(iv, 0, sizeof(iv)); 238 236
+1 -3
drivers/usb/wusbcore/security.c
··· 374 374 struct wusb_keydvt_out keydvt_out; 375 375 376 376 hs = kcalloc(3, sizeof(hs[0]), GFP_KERNEL); 377 - if (hs == NULL) { 378 - dev_err(dev, "can't allocate handshake data\n"); 377 + if (!hs) 379 378 goto error_kzalloc; 380 - } 381 379 382 380 /* We need to turn encryption before beginning the 4way 383 381 * hshake (WUSB1.0[.3.2.2]) */
+2 -7
drivers/usb/wusbcore/wa-nep.c
··· 271 271 epd = &iface->cur_altsetting->endpoint[0].desc; 272 272 wa->nep_buffer_size = 1024; 273 273 wa->nep_buffer = kmalloc(wa->nep_buffer_size, GFP_KERNEL); 274 - if (wa->nep_buffer == NULL) { 275 - dev_err(dev, 276 - "Unable to allocate notification's read buffer\n"); 274 + if (!wa->nep_buffer) 277 275 goto error_nep_buffer; 278 - } 279 276 wa->nep_urb = usb_alloc_urb(0, GFP_KERNEL); 280 - if (wa->nep_urb == NULL) { 281 - dev_err(dev, "Unable to allocate notification URB\n"); 277 + if (wa->nep_urb == NULL) 282 278 goto error_urb_alloc; 283 - } 284 279 usb_fill_int_urb(wa->nep_urb, usb_dev, 285 280 usb_rcvintpipe(usb_dev, epd->bEndpointAddress), 286 281 wa->nep_buffer, wa->nep_buffer_size,
+1 -3
drivers/usb/wusbcore/wa-xfer.c
··· 2865 2865 goto out; 2866 2866 2867 2867 wa->dti_urb = usb_alloc_urb(0, GFP_KERNEL); 2868 - if (wa->dti_urb == NULL) { 2869 - dev_err(dev, "Can't allocate DTI URB\n"); 2868 + if (wa->dti_urb == NULL) 2870 2869 goto error_dti_urb_alloc; 2871 - } 2872 2870 usb_fill_bulk_urb( 2873 2871 wa->dti_urb, wa->usb_dev, 2874 2872 usb_rcvbulkpipe(wa->usb_dev, 0x80 | dti_epd->bEndpointAddress),
+1 -3
drivers/uwb/hwa-rc.c
··· 701 701 goto error_rd_buffer; 702 702 } 703 703 hwarc->neep_urb = usb_alloc_urb(0, GFP_KERNEL); 704 - if (hwarc->neep_urb == NULL) { 705 - dev_err(dev, "Unable to allocate notification URB\n"); 704 + if (hwarc->neep_urb == NULL) 706 705 goto error_urb_alloc; 707 - } 708 706 usb_fill_int_urb(hwarc->neep_urb, usb_dev, 709 707 usb_rcvintpipe(usb_dev, epd->bEndpointAddress), 710 708 hwarc->rd_buffer, PAGE_SIZE,
+1 -3
drivers/watchdog/pcwd_usb.c
··· 666 666 667 667 /* allocate the urb's */ 668 668 usb_pcwd->intr_urb = usb_alloc_urb(0, GFP_KERNEL); 669 - if (!usb_pcwd->intr_urb) { 670 - pr_err("Out of memory\n"); 669 + if (!usb_pcwd->intr_urb) 671 670 goto error; 672 - } 673 671 674 672 /* initialise the intr urb's */ 675 673 usb_fill_int_urb(usb_pcwd->intr_urb, udev, pipe,
+1
include/linux/bcma/bcma_regs.h
··· 10 10 #define BCMA_CLKCTLST_HAVEALPREQ 0x00000008 /* ALP available request */ 11 11 #define BCMA_CLKCTLST_HAVEHTREQ 0x00000010 /* HT available request */ 12 12 #define BCMA_CLKCTLST_HWCROFF 0x00000020 /* Force HW clock request off */ 13 + #define BCMA_CLKCTLST_HQCLKREQ 0x00000040 /* HQ Clock */ 13 14 #define BCMA_CLKCTLST_EXTRESREQ 0x00000700 /* Mask of external resource requests */ 14 15 #define BCMA_CLKCTLST_EXTRESREQ_SHIFT 8 15 16 #define BCMA_CLKCTLST_HAVEALP 0x00010000 /* ALP available */
+170 -25
include/linux/extcon.h
··· 29 29 #include <linux/device.h> 30 30 31 31 /* 32 + * Define the type of supported external connectors 33 + */ 34 + #define EXTCON_TYPE_USB BIT(0) /* USB connector */ 35 + #define EXTCON_TYPE_CHG BIT(1) /* Charger connector */ 36 + #define EXTCON_TYPE_JACK BIT(2) /* Jack connector */ 37 + #define EXTCON_TYPE_DISP BIT(3) /* Display connector */ 38 + #define EXTCON_TYPE_MISC BIT(4) /* Miscellaneous connector */ 39 + 40 + /* 32 41 * Define the unique id of supported external connectors 33 42 */ 34 43 #define EXTCON_NONE 0 ··· 53 44 #define EXTCON_CHG_USB_ACA 8 /* Accessory Charger Adapter */ 54 45 #define EXTCON_CHG_USB_FAST 9 55 46 #define EXTCON_CHG_USB_SLOW 10 47 + #define EXTCON_CHG_WPT 11 /* Wireless Power Transfer */ 56 48 57 49 /* Jack external connector */ 58 50 #define EXTCON_JACK_MICROPHONE 20 ··· 70 60 #define EXTCON_DISP_MHL 41 /* Mobile High-Definition Link */ 71 61 #define EXTCON_DISP_DVI 42 /* Digital Visual Interface */ 72 62 #define EXTCON_DISP_VGA 43 /* Video Graphics Array */ 63 + #define EXTCON_DISP_DP 44 /* Display Port */ 64 + #define EXTCON_DISP_HMD 45 /* Head-Mounted Display */ 73 65 74 66 /* Miscellaneous external connector */ 75 67 #define EXTCON_DOCK 60 ··· 79 67 #define EXTCON_MECHANICAL 62 80 68 81 69 #define EXTCON_NUM 63 70 + 71 + /* 72 + * Define the property of supported external connectors. 73 + * 74 + * When adding the new extcon property, they *must* have 75 + * the type/value/default information. Also, you *have to* 76 + * modify the EXTCON_PROP_[type]_START/END definitions 77 + * which mean the range of the supported properties 78 + * for each extcon type. 79 + * 80 + * The naming style of property 81 + * : EXTCON_PROP_[type]_[property name] 82 + * 83 + * EXTCON_PROP_USB_[property name] : USB property 84 + * EXTCON_PROP_CHG_[property name] : Charger property 85 + * EXTCON_PROP_JACK_[property name] : Jack property 86 + * EXTCON_PROP_DISP_[property name] : Display property 87 + */ 88 + 89 + /* 90 + * Properties of EXTCON_TYPE_USB. 91 + * 92 + * - EXTCON_PROP_USB_VBUS 93 + * @type: integer (intval) 94 + * @value: 0 (low) or 1 (high) 95 + * @default: 0 (low) 96 + * - EXTCON_PROP_USB_TYPEC_POLARITY 97 + * @type: integer (intval) 98 + * @value: 0 (normal) or 1 (flip) 99 + * @default: 0 (normal) 100 + * - EXTCON_PROP_USB_SS (SuperSpeed) 101 + * @type: integer (intval) 102 + * @value: 0 (USB/USB2) or 1 (USB3) 103 + * @default: 0 (USB/USB2) 104 + * 105 + */ 106 + #define EXTCON_PROP_USB_VBUS 0 107 + #define EXTCON_PROP_USB_TYPEC_POLARITY 1 108 + #define EXTCON_PROP_USB_SS 2 109 + 110 + #define EXTCON_PROP_USB_MIN 0 111 + #define EXTCON_PROP_USB_MAX 2 112 + #define EXTCON_PROP_USB_CNT (EXTCON_PROP_USB_MAX - EXTCON_PROP_USB_MIN + 1) 113 + 114 + /* Properties of EXTCON_TYPE_CHG. */ 115 + #define EXTCON_PROP_CHG_MIN 50 116 + #define EXTCON_PROP_CHG_MAX 50 117 + #define EXTCON_PROP_CHG_CNT (EXTCON_PROP_CHG_MAX - EXTCON_PROP_CHG_MIN + 1) 118 + 119 + /* Properties of EXTCON_TYPE_JACK. */ 120 + #define EXTCON_PROP_JACK_MIN 100 121 + #define EXTCON_PROP_JACK_MAX 100 122 + #define EXTCON_PROP_JACK_CNT (EXTCON_PROP_JACK_MAX - EXTCON_PROP_JACK_MIN + 1) 123 + 124 + /* 125 + * Properties of EXTCON_TYPE_DISP. 126 + * 127 + * - EXTCON_PROP_DISP_HPD (Hot Plug Detect) 128 + * @type: integer (intval) 129 + * @value: 0 (no hpd) or 1 (hpd) 130 + * @default: 0 (no hpd) 131 + * 132 + */ 133 + #define EXTCON_PROP_DISP_HPD 150 134 + 135 + /* Properties of EXTCON_TYPE_DISP. */ 136 + #define EXTCON_PROP_DISP_MIN 150 137 + #define EXTCON_PROP_DISP_MAX 151 138 + #define EXTCON_PROP_DISP_CNT (EXTCON_PROP_DISP_MAX - EXTCON_PROP_DISP_MIN + 1) 139 + 140 + /* 141 + * Define the type of property's value. 142 + * 143 + * Define the property's value as union type. Because each property 144 + * would need the different data type to store it. 145 + */ 146 + union extcon_property_value { 147 + int intval; /* type : integer (intval) */ 148 + }; 82 149 83 150 struct extcon_cable; 84 151 ··· 241 150 extern void devm_extcon_dev_free(struct device *dev, struct extcon_dev *edev); 242 151 243 152 /* 244 - * get/set/update_state access the 32b encoded state value, which represents 245 - * states of all possible cables of the multistate port. For example, if one 246 - * calls extcon_set_state(edev, 0x7), it may mean that all the three cables 247 - * are attached to the port. 248 - */ 249 - static inline u32 extcon_get_state(struct extcon_dev *edev) 250 - { 251 - return edev->state; 252 - } 253 - 254 - extern int extcon_set_state(struct extcon_dev *edev, u32 state); 255 - extern int extcon_update_state(struct extcon_dev *edev, u32 mask, u32 state); 256 - 257 - /* 258 - * get/set_cable_state access each bit of the 32b encoded state value. 153 + * get/set_state access each bit of the 32b encoded state value. 259 154 * They are used to access the status of each cable based on the cable id. 260 155 */ 261 - extern int extcon_get_cable_state_(struct extcon_dev *edev, unsigned int id); 262 - extern int extcon_set_cable_state_(struct extcon_dev *edev, unsigned int id, 156 + extern int extcon_get_state(struct extcon_dev *edev, unsigned int id); 157 + extern int extcon_set_state(struct extcon_dev *edev, unsigned int id, 263 158 bool cable_state); 159 + extern int extcon_set_state_sync(struct extcon_dev *edev, unsigned int id, 160 + bool cable_state); 161 + /* 162 + * Synchronize the state and property data for a specific external connector. 163 + */ 164 + extern int extcon_sync(struct extcon_dev *edev, unsigned int id); 165 + 166 + /* 167 + * get/set_property access the property value of each external connector. 168 + * They are used to access the property of each cable based on the property id. 169 + */ 170 + extern int extcon_get_property(struct extcon_dev *edev, unsigned int id, 171 + unsigned int prop, 172 + union extcon_property_value *prop_val); 173 + extern int extcon_set_property(struct extcon_dev *edev, unsigned int id, 174 + unsigned int prop, 175 + union extcon_property_value prop_val); 176 + extern int extcon_set_property_sync(struct extcon_dev *edev, unsigned int id, 177 + unsigned int prop, 178 + union extcon_property_value prop_val); 179 + 180 + /* 181 + * get/set_property_capability set the capability of the property for each 182 + * external connector. They are used to set the capability of the property 183 + * of each external connector based on the id and property. 184 + */ 185 + extern int extcon_get_property_capability(struct extcon_dev *edev, 186 + unsigned int id, unsigned int prop); 187 + extern int extcon_set_property_capability(struct extcon_dev *edev, 188 + unsigned int id, unsigned int prop); 264 189 265 190 /* 266 191 * Following APIs are to monitor every action of a notifier. ··· 339 232 340 233 static inline void devm_extcon_dev_free(struct extcon_dev *edev) { } 341 234 342 - static inline u32 extcon_get_state(struct extcon_dev *edev) 235 + 236 + static inline int extcon_get_state(struct extcon_dev *edev, unsigned int id) 343 237 { 344 238 return 0; 345 239 } 346 240 347 - static inline int extcon_set_state(struct extcon_dev *edev, u32 state) 241 + static inline int extcon_set_state(struct extcon_dev *edev, unsigned int id, 242 + bool cable_state) 348 243 { 349 244 return 0; 350 245 } 351 246 352 - static inline int extcon_update_state(struct extcon_dev *edev, u32 mask, 353 - u32 state) 247 + static inline int extcon_set_state_sync(struct extcon_dev *edev, unsigned int id, 248 + bool cable_state) 354 249 { 355 250 return 0; 356 251 } 357 252 358 - static inline int extcon_get_cable_state_(struct extcon_dev *edev, 359 - unsigned int id) 253 + static inline int extcon_sync(struct extcon_dev *edev, unsigned int id) 360 254 { 361 255 return 0; 362 256 } 363 257 364 - static inline int extcon_set_cable_state_(struct extcon_dev *edev, 365 - unsigned int id, bool cable_state) 258 + static inline int extcon_get_property(struct extcon_dev *edev, unsigned int id, 259 + unsigned int prop, 260 + union extcon_property_value *prop_val) 261 + { 262 + return 0; 263 + } 264 + static inline int extcon_set_property(struct extcon_dev *edev, unsigned int id, 265 + unsigned int prop, 266 + union extcon_property_value prop_val) 267 + { 268 + return 0; 269 + } 270 + 271 + static inline int extcon_set_property_sync(struct extcon_dev *edev, 272 + unsigned int id, unsigned int prop, 273 + union extcon_property_value prop_val) 274 + { 275 + return 0; 276 + } 277 + 278 + static inline int extcon_get_property_capability(struct extcon_dev *edev, 279 + unsigned int id, unsigned int prop) 280 + { 281 + return 0; 282 + } 283 + 284 + static inline int extcon_set_property_capability(struct extcon_dev *edev, 285 + unsigned int id, unsigned int prop) 366 286 { 367 287 return 0; 368 288 } ··· 453 319 *obj) 454 320 { 455 321 return -EINVAL; 322 + } 323 + 324 + static inline int extcon_get_cable_state_(struct extcon_dev *edev, unsigned int id) 325 + { 326 + return extcon_get_state(edev, id); 327 + } 328 + 329 + static inline int extcon_set_cable_state_(struct extcon_dev *edev, unsigned int id, 330 + bool cable_state) 331 + { 332 + return extcon_set_state_sync(edev, id, cable_state); 456 333 } 457 334 #endif /* __LINUX_EXTCON_H__ */
+2 -2
include/linux/extcon/extcon-adc-jack.h
··· 20 20 21 21 /** 22 22 * struct adc_jack_cond - condition to use an extcon state 23 - * @state: the corresponding extcon state (if 0, this struct 24 23 * denotes the last adc_jack_cond element among the array) 24 + * @id: the unique id of each external connector 25 25 * @min_adc: min adc value for this condition 26 26 * @max_adc: max adc value for this condition 27 27 * ··· 33 33 * because when no adc_jack_cond is met, state = 0 is automatically chosen. 34 34 */ 35 35 struct adc_jack_cond { 36 - u32 state; /* extcon state value. 0 if invalid */ 36 + unsigned int id; 37 37 u32 min_adc; 38 38 u32 max_adc; 39 39 };
+3
include/linux/phy/phy.h
··· 36 36 * @power_on: powering on the phy 37 37 * @power_off: powering off the phy 38 38 * @set_mode: set the mode of the phy 39 + * @reset: resetting the phy 39 40 * @owner: the module owner containing the ops 40 41 */ 41 42 struct phy_ops { ··· 45 44 int (*power_on)(struct phy *phy); 46 45 int (*power_off)(struct phy *phy); 47 46 int (*set_mode)(struct phy *phy, enum phy_mode mode); 47 + int (*reset)(struct phy *phy); 48 48 struct module *owner; 49 49 }; 50 50 ··· 138 136 int phy_power_on(struct phy *phy); 139 137 int phy_power_off(struct phy *phy); 140 138 int phy_set_mode(struct phy *phy, enum phy_mode mode); 139 + int phy_reset(struct phy *phy); 141 140 static inline int phy_get_bus_width(struct phy *phy) 142 141 { 143 142 return phy->attrs.bus_width;
+6 -2
include/linux/ulpi/driver.h
··· 15 15 */ 16 16 struct ulpi { 17 17 struct ulpi_device_id id; 18 - struct ulpi_ops *ops; 18 + const struct ulpi_ops *ops; 19 19 struct device dev; 20 20 }; 21 21 ··· 47 47 48 48 #define to_ulpi_driver(d) container_of(d, struct ulpi_driver, driver) 49 49 50 - int ulpi_register_driver(struct ulpi_driver *drv); 50 + /* 51 + * use a macro to avoid include chaining to get THIS_MODULE 52 + */ 53 + #define ulpi_register_driver(drv) __ulpi_register_driver(drv, THIS_MODULE) 54 + int __ulpi_register_driver(struct ulpi_driver *drv, struct module *module); 51 55 void ulpi_unregister_driver(struct ulpi_driver *drv); 52 56 53 57 #define module_ulpi_driver(__ulpi_driver) \
+4 -5
include/linux/ulpi/interface.h
··· 4 4 #include <linux/types.h> 5 5 6 6 struct ulpi; 7 + struct device; 7 8 8 9 /** 9 10 * struct ulpi_ops - ULPI register access 10 - * @dev: the interface provider 11 11 * @read: read operation for ULPI register access 12 12 * @write: write operation for ULPI register access 13 13 */ 14 14 struct ulpi_ops { 15 - struct device *dev; 16 - int (*read)(struct ulpi_ops *ops, u8 addr); 17 - int (*write)(struct ulpi_ops *ops, u8 addr, u8 val); 15 + int (*read)(struct device *dev, u8 addr); 16 + int (*write)(struct device *dev, u8 addr, u8 val); 18 17 }; 19 18 20 - struct ulpi *ulpi_register_interface(struct device *, struct ulpi_ops *); 19 + struct ulpi *ulpi_register_interface(struct device *, const struct ulpi_ops *); 21 20 void ulpi_unregister_interface(struct ulpi *); 22 21 23 22 #endif /* __LINUX_ULPI_INTERFACE_H */
+2 -1
include/linux/usb/composite.h
··· 220 220 int (*setup)(struct usb_function *, 221 221 const struct usb_ctrlrequest *); 222 222 bool (*req_match)(struct usb_function *, 223 - const struct usb_ctrlrequest *); 223 + const struct usb_ctrlrequest *, 224 + bool config0); 224 225 void (*suspend)(struct usb_function *); 225 226 void (*resume)(struct usb_function *); 226 227
+27 -3
include/linux/usb/gadget.h
··· 346 346 * or B-Peripheral wants to take host role. 347 347 * @quirk_ep_out_aligned_size: epout requires buffer size to be aligned to 348 348 * MaxPacketSize. 349 + * @quirk_avoids_skb_reserve: udc/platform wants to avoid skb_reserve() in 350 + * u_ether.c to improve performance. 349 351 * @is_selfpowered: if the gadget is self-powered. 350 352 * @deactivated: True if gadget is deactivated - in deactivated state it cannot 351 353 * be connected. ··· 400 398 unsigned quirk_altset_not_supp:1; 401 399 unsigned quirk_stall_not_supp:1; 402 400 unsigned quirk_zlp_not_supp:1; 401 + unsigned quirk_avoids_skb_reserve:1; 403 402 unsigned is_selfpowered:1; 404 403 unsigned deactivated:1; 405 404 unsigned connected:1; ··· 421 418 list_for_each_entry(tmp, &(gadget)->ep_list, ep_list) 422 419 423 420 /** 421 + * usb_ep_align - returns @len aligned to ep's maxpacketsize. 422 + * @ep: the endpoint whose maxpacketsize is used to align @len 423 + * @len: buffer size's length to align to @ep's maxpacketsize 424 + * 425 + * This helper is used to align buffer's size to an ep's maxpacketsize. 426 + */ 427 + static inline size_t usb_ep_align(struct usb_ep *ep, size_t len) 428 + { 429 + return round_up(len, (size_t)le16_to_cpu(ep->desc->wMaxPacketSize)); 430 + } 431 + 432 + /** 424 433 * usb_ep_align_maybe - returns @len aligned to ep's maxpacketsize if gadget 425 - * requires quirk_ep_out_aligned_size, otherwise reguens len. 434 + * requires quirk_ep_out_aligned_size, otherwise returns len. 426 435 * @g: controller to check for quirk 427 436 * @ep: the endpoint whose maxpacketsize is used to align @len 428 437 * @len: buffer size's length to align to @ep's maxpacketsize ··· 445 430 static inline size_t 446 431 usb_ep_align_maybe(struct usb_gadget *g, struct usb_ep *ep, size_t len) 447 432 { 448 - return !g->quirk_ep_out_aligned_size ? len : 449 - round_up(len, (size_t)ep->desc->wMaxPacketSize); 433 + return g->quirk_ep_out_aligned_size ? usb_ep_align(ep, len) : len; 450 434 } 451 435 452 436 /** ··· 474 460 static inline int gadget_is_zlp_supported(struct usb_gadget *g) 475 461 { 476 462 return !g->quirk_zlp_not_supp; 463 + } 464 + 465 + /** 466 + * gadget_avoids_skb_reserve - return true iff the hardware would like to avoid 467 + * skb_reserve to improve performance. 468 + * @g: controller to check for quirk 469 + */ 470 + static inline int gadget_avoids_skb_reserve(struct usb_gadget *g) 471 + { 472 + return g->quirk_avoids_skb_reserve; 477 473 } 478 474 479 475 /**
+2
include/linux/usb_usual.h
··· 81 81 /* Sets max_sectors to 240 */ \ 82 82 US_FLAG(NO_REPORT_LUNS, 0x10000000) \ 83 83 /* Cannot handle REPORT_LUNS */ \ 84 + US_FLAG(ALWAYS_SYNC, 0x20000000) \ 85 + /* lies about caching, so always sync */ \ 84 86 85 87 #define US_FLAG(name, value) US_FL_##name = value , 86 88 enum { US_DO_ALL_FLAGS };
+14
include/soc/at91/atmel-sfr.h
··· 13 13 #ifndef _LINUX_MFD_SYSCON_ATMEL_SFR_H 14 14 #define _LINUX_MFD_SYSCON_ATMEL_SFR_H 15 15 16 + #define AT91_SFR_DDRCFG 0x04 /* DDR Configuration Register */ 17 + /* 0x08 ~ 0x0c: Reserved */ 18 + #define AT91_SFR_OHCIICR 0x10 /* OHCI INT Configuration Register */ 19 + #define AT91_SFR_OHCIISR 0x14 /* OHCI INT Status Register */ 16 20 #define AT91_SFR_I2SCLKSEL 0x90 /* I2SC Register */ 21 + 22 + /* Field definitions */ 23 + #define AT91_OHCIICR_SUSPEND_A BIT(8) 24 + #define AT91_OHCIICR_SUSPEND_B BIT(9) 25 + #define AT91_OHCIICR_SUSPEND_C BIT(10) 26 + 27 + #define AT91_OHCIICR_USB_SUSPEND (AT91_OHCIICR_SUSPEND_A | \ 28 + AT91_OHCIICR_SUSPEND_B | \ 29 + AT91_OHCIICR_SUSPEND_C) 30 + 17 31 18 32 #endif /* _LINUX_MFD_SYSCON_ATMEL_SFR_H */
+2
include/uapi/linux/usb/functionfs.h
··· 21 21 FUNCTIONFS_HAS_MS_OS_DESC = 8, 22 22 FUNCTIONFS_VIRTUAL_ADDR = 16, 23 23 FUNCTIONFS_EVENTFD = 32, 24 + FUNCTIONFS_ALL_CTRL_RECIP = 64, 25 + FUNCTIONFS_CONFIG0_SETUP = 128, 24 26 }; 25 27 26 28 /* Descriptor of an non-audio endpoint */