mirror of
https://github.com/torvalds/linux.git
synced 2024-11-23 12:42:02 +00:00
USB/PHY/EXTCON patches for 4.9-rc1
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. Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> -----BEGIN PGP SIGNATURE----- iFYEABECABYFAlfyNTEPHGdyZWdAa3JvYWguY29tAAoJEDFH1A3bLfspbuUAoJAn XD6k9A+0QgnJ/iLiT8pztawNAKCCVYZOzgdFRGsnaZ2p7lb9IHpPCA== =QUj+ -----END PGP SIGNATURE----- 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 ...
This commit is contained in:
commit
e6445f52d9
12
Documentation/ABI/testing/sysfs-class-led-trigger-usbport
Normal file
12
Documentation/ABI/testing/sysfs-class-led-trigger-usbport
Normal file
@ -0,0 +1,12 @@
|
||||
What: /sys/class/leds/<led>/ports/<port>
|
||||
Date: September 2016
|
||||
KernelVersion: 4.9
|
||||
Contact: linux-leds@vger.kernel.org
|
||||
linux-usb@vger.kernel.org
|
||||
Description:
|
||||
Every dir entry represents a single USB port that can be
|
||||
selected for the USB port trigger. Selecting ports makes trigger
|
||||
observing them for any connected devices and lighting on LED if
|
||||
there are any.
|
||||
Echoing "1" value selects USB port. Echoing "0" unselects it.
|
||||
Current state can be also read.
|
@ -0,0 +1,41 @@
|
||||
Qualcomm's PM8941 USB ID Extcon device
|
||||
|
||||
Some Qualcomm PMICs have a "misc" module that can be used to detect when
|
||||
the USB ID pin has been pulled low or high.
|
||||
|
||||
PROPERTIES
|
||||
|
||||
- compatible:
|
||||
Usage: required
|
||||
Value type: <string>
|
||||
Definition: Should contain "qcom,pm8941-misc";
|
||||
|
||||
- reg:
|
||||
Usage: required
|
||||
Value type: <u32>
|
||||
Definition: Should contain the offset to the misc address space
|
||||
|
||||
- interrupts:
|
||||
Usage: required
|
||||
Value type: <prop-encoded-array>
|
||||
Definition: Should contain the usb id interrupt
|
||||
|
||||
- interrupt-names:
|
||||
Usage: required
|
||||
Value type: <stringlist>
|
||||
Definition: Should contain the string "usb_id" for the usb id interrupt
|
||||
|
||||
Example:
|
||||
|
||||
pmic {
|
||||
usb_id: misc@900 {
|
||||
compatible = "qcom,pm8941-misc";
|
||||
reg = <0x900>;
|
||||
interrupts = <0x0 0x9 0 IRQ_TYPE_EDGE_BOTH>;
|
||||
interrupt-names = "usb_id";
|
||||
};
|
||||
}
|
||||
|
||||
usb-controller {
|
||||
extcon = <&usb_id>;
|
||||
};
|
23
Documentation/devicetree/bindings/phy/bcm-ns-usb3-phy.txt
Normal file
23
Documentation/devicetree/bindings/phy/bcm-ns-usb3-phy.txt
Normal file
@ -0,0 +1,23 @@
|
||||
Driver for Broadcom Northstar USB 3.0 PHY
|
||||
|
||||
Required properties:
|
||||
|
||||
- compatible: one of: "brcm,ns-ax-usb3-phy", "brcm,ns-bx-usb3-phy".
|
||||
- reg: register mappings for DMP (Device Management Plugin) and ChipCommon B
|
||||
MMI.
|
||||
- reg-names: "dmp" and "ccb-mii"
|
||||
|
||||
Initialization of USB 3.0 PHY depends on Northstar version. There are currently
|
||||
three known series: Ax, Bx and Cx.
|
||||
Known A0: BCM4707 rev 0
|
||||
Known B0: BCM4707 rev 4, BCM53573 rev 2
|
||||
Known B1: BCM4707 rev 6
|
||||
Known C0: BCM47094 rev 0
|
||||
|
||||
Example:
|
||||
usb3-phy {
|
||||
compatible = "brcm,ns-ax-usb3-phy";
|
||||
reg = <0x18105000 0x1000>, <0x18003000 0x1000>;
|
||||
reg-names = "dmp", "ccb-mii";
|
||||
#phy-cells = <0>;
|
||||
};
|
@ -12,6 +12,16 @@ Required properties:
|
||||
- interrupts: Should contain phy interrupt
|
||||
- fsl,anatop: phandle for anatop register, it is only for imx6 SoC series
|
||||
|
||||
Optional properties:
|
||||
- fsl,tx-cal-45-dn-ohms: Integer [30-55]. Resistance (in ohms) of switchable
|
||||
high-speed trimming resistor connected in parallel with the 45 ohm resistor
|
||||
that terminates the DN output signal. Default: 45
|
||||
- fsl,tx-cal-45-dp-ohms: Integer [30-55]. Resistance (in ohms) of switchable
|
||||
high-speed trimming resistor connected in parallel with the 45 ohm resistor
|
||||
that terminates the DP output signal. Default: 45
|
||||
- fsl,tx-d-cal: Integer [79-119]. Current trimming value (as a percentage) of
|
||||
the 17.78mA TX reference current. Default: 100
|
||||
|
||||
Example:
|
||||
usbphy1: usbphy@020c9000 {
|
||||
compatible = "fsl,imx6q-usbphy", "fsl,imx23-usbphy";
|
||||
|
@ -0,0 +1,64 @@
|
||||
ROCKCHIP USB2.0 PHY WITH INNO IP BLOCK
|
||||
|
||||
Required properties (phy (parent) node):
|
||||
- compatible : should be one of the listed compatibles:
|
||||
* "rockchip,rk3366-usb2phy"
|
||||
* "rockchip,rk3399-usb2phy"
|
||||
- reg : the address offset of grf for usb-phy configuration.
|
||||
- #clock-cells : should be 0.
|
||||
- clock-output-names : specify the 480m output clock name.
|
||||
|
||||
Optional properties:
|
||||
- clocks : phandle + phy specifier pair, for the input clock of phy.
|
||||
- clock-names : input clock name of phy, must be "phyclk".
|
||||
|
||||
Required nodes : a sub-node is required for each port the phy provides.
|
||||
The sub-node name is used to identify host or otg port,
|
||||
and shall be the following entries:
|
||||
* "otg-port" : the name of otg port.
|
||||
* "host-port" : the name of host port.
|
||||
|
||||
Required properties (port (child) node):
|
||||
- #phy-cells : must be 0. See ./phy-bindings.txt for details.
|
||||
- interrupts : specify an interrupt for each entry in interrupt-names.
|
||||
- interrupt-names : a list which shall be the following entries:
|
||||
* "otg-id" : for the otg id interrupt.
|
||||
* "otg-bvalid" : for the otg vbus interrupt.
|
||||
* "linestate" : for the host/otg linestate interrupt.
|
||||
|
||||
Optional properties:
|
||||
- phy-supply : phandle to a regulator that provides power to VBUS.
|
||||
See ./phy-bindings.txt for details.
|
||||
|
||||
Example:
|
||||
|
||||
grf: syscon@ff770000 {
|
||||
compatible = "rockchip,rk3366-grf", "syscon", "simple-mfd";
|
||||
#address-cells = <1>;
|
||||
#size-cells = <1>;
|
||||
|
||||
...
|
||||
|
||||
u2phy: usb2-phy@700 {
|
||||
compatible = "rockchip,rk3366-usb2phy";
|
||||
reg = <0x700 0x2c>;
|
||||
#clock-cells = <0>;
|
||||
clock-output-names = "sclk_otgphy0_480m";
|
||||
|
||||
u2phy_otg: otg-port {
|
||||
#phy-cells = <0>;
|
||||
interrupts = <GIC_SPI 93 IRQ_TYPE_LEVEL_HIGH>,
|
||||
<GIC_SPI 94 IRQ_TYPE_LEVEL_HIGH>,
|
||||
<GIC_SPI 95 IRQ_TYPE_LEVEL_HIGH>;
|
||||
interrupt-names = "otg-id", "otg-bvalid", "linestate";
|
||||
status = "okay";
|
||||
};
|
||||
|
||||
u2phy_host: host-port {
|
||||
#phy-cells = <0>;
|
||||
interrupts = <GIC_SPI 96 IRQ_TYPE_LEVEL_HIGH>;
|
||||
interrupt-names = "linestate";
|
||||
status = "okay";
|
||||
};
|
||||
};
|
||||
};
|
101
Documentation/devicetree/bindings/phy/phy-rockchip-typec.txt
Normal file
101
Documentation/devicetree/bindings/phy/phy-rockchip-typec.txt
Normal file
@ -0,0 +1,101 @@
|
||||
* ROCKCHIP type-c PHY
|
||||
---------------------
|
||||
|
||||
Required properties:
|
||||
- compatible : must be "rockchip,rk3399-typec-phy"
|
||||
- reg: Address and length of the usb phy control register set
|
||||
- rockchip,grf : phandle to the syscon managing the "general
|
||||
register files"
|
||||
- clocks : phandle + clock specifier for the phy clocks
|
||||
- clock-names : string, clock name, must be "tcpdcore", "tcpdphy-ref";
|
||||
- assigned-clocks: main clock, should be <&cru SCLK_UPHY0_TCPDCORE> or
|
||||
<&cru SCLK_UPHY1_TCPDCORE>;
|
||||
- assigned-clock-rates : the phy core clk frequency, shall be: 50000000
|
||||
- resets : a list of phandle + reset specifier pairs
|
||||
- reset-names : string reset name, must be:
|
||||
"uphy", "uphy-pipe", "uphy-tcphy"
|
||||
- extcon : extcon specifier for the Power Delivery
|
||||
|
||||
Note, there are 2 type-c phys for RK3399, and they are almost identical, except
|
||||
these registers(description below), every register node contains 3 sections:
|
||||
offset, enable bit, write mask bit.
|
||||
- rockchip,typec-conn-dir : the register of type-c connector direction,
|
||||
for type-c phy0, it must be <0xe580 0 16>;
|
||||
for type-c phy1, it must be <0xe58c 0 16>;
|
||||
- rockchip,usb3tousb2-en : the register of type-c force usb3 to usb2 enable
|
||||
control.
|
||||
for type-c phy0, it must be <0xe580 3 19>;
|
||||
for type-c phy1, it must be <0xe58c 3 19>;
|
||||
- rockchip,external-psm : the register of type-c phy external psm clock
|
||||
selection.
|
||||
for type-c phy0, it must be <0xe588 14 30>;
|
||||
for type-c phy1, it must be <0xe594 14 30>;
|
||||
- rockchip,pipe-status : the register of type-c phy pipe status.
|
||||
for type-c phy0, it must be <0xe5c0 0 0>;
|
||||
for type-c phy1, it must be <0xe5c0 16 16>;
|
||||
|
||||
Required nodes : a sub-node is required for each port the phy provides.
|
||||
The sub-node name is used to identify dp or usb3 port,
|
||||
and shall be the following entries:
|
||||
* "dp-port" : the name of DP port.
|
||||
* "usb3-port" : the name of USB3 port.
|
||||
|
||||
Required properties (port (child) node):
|
||||
- #phy-cells : must be 0, See ./phy-bindings.txt for details.
|
||||
|
||||
Example:
|
||||
tcphy0: phy@ff7c0000 {
|
||||
compatible = "rockchip,rk3399-typec-phy";
|
||||
reg = <0x0 0xff7c0000 0x0 0x40000>;
|
||||
rockchip,grf = <&grf>;
|
||||
extcon = <&fusb0>;
|
||||
clocks = <&cru SCLK_UPHY0_TCPDCORE>,
|
||||
<&cru SCLK_UPHY0_TCPDPHY_REF>;
|
||||
clock-names = "tcpdcore", "tcpdphy-ref";
|
||||
assigned-clocks = <&cru SCLK_UPHY0_TCPDCORE>;
|
||||
assigned-clock-rates = <50000000>;
|
||||
resets = <&cru SRST_UPHY0>,
|
||||
<&cru SRST_UPHY0_PIPE_L00>,
|
||||
<&cru SRST_P_UPHY0_TCPHY>;
|
||||
reset-names = "uphy", "uphy-pipe", "uphy-tcphy";
|
||||
rockchip,typec-conn-dir = <0xe580 0 16>;
|
||||
rockchip,usb3tousb2-en = <0xe580 3 19>;
|
||||
rockchip,external-psm = <0xe588 14 30>;
|
||||
rockchip,pipe-status = <0xe5c0 0 0>;
|
||||
|
||||
tcphy0_dp: dp-port {
|
||||
#phy-cells = <0>;
|
||||
};
|
||||
|
||||
tcphy0_usb3: usb3-port {
|
||||
#phy-cells = <0>;
|
||||
};
|
||||
};
|
||||
|
||||
tcphy1: phy@ff800000 {
|
||||
compatible = "rockchip,rk3399-typec-phy";
|
||||
reg = <0x0 0xff800000 0x0 0x40000>;
|
||||
rockchip,grf = <&grf>;
|
||||
extcon = <&fusb1>;
|
||||
clocks = <&cru SCLK_UPHY1_TCPDCORE>,
|
||||
<&cru SCLK_UPHY1_TCPDPHY_REF>;
|
||||
clock-names = "tcpdcore", "tcpdphy-ref";
|
||||
assigned-clocks = <&cru SCLK_UPHY1_TCPDCORE>;
|
||||
assigned-clock-rates = <50000000>;
|
||||
resets = <&cru SRST_UPHY1>,
|
||||
<&cru SRST_UPHY1_PIPE_L00>,
|
||||
<&cru SRST_P_UPHY1_TCPHY>;
|
||||
reset-names = "uphy", "uphy-pipe", "uphy-tcphy";
|
||||
rockchip,typec-conn-dir = <0xe58c 0 16>;
|
||||
rockchip,usb3tousb2-en = <0xe58c 3 19>;
|
||||
rockchip,external-psm = <0xe594 14 30>;
|
||||
rockchip,pipe-status = <0xe5c0 16 16>;
|
||||
|
||||
tcphy1_dp: dp-port {
|
||||
#phy-cells = <0>;
|
||||
};
|
||||
|
||||
tcphy1_usb3: usb3-port {
|
||||
#phy-cells = <0>;
|
||||
};
|
||||
};
|
@ -5,6 +5,8 @@ This file provides information on what the device node for the R-Car generation
|
||||
|
||||
Required properties:
|
||||
- compatible: "renesas,usb2-phy-r8a7795" if the device is a part of an R8A7795
|
||||
SoC.
|
||||
"renesas,usb2-phy-r8a7796" if the device is a part of an R8A7796
|
||||
SoC.
|
||||
"renesas,rcar-gen3-usb2-phy" for a generic R-Car Gen3 compatible device.
|
||||
|
||||
@ -30,11 +32,11 @@ Example (R-Car H3):
|
||||
compatible = "renesas,usb2-phy-r8a7795", "renesas,rcar-gen3-usb2-phy";
|
||||
reg = <0 0xee080200 0 0x700>;
|
||||
interrupts = <GIC_SPI 108 IRQ_TYPE_LEVEL_HIGH>;
|
||||
clocks = <&mstp7_clks R8A7795_CLK_EHCI0>;
|
||||
clocks = <&cpg CPG_MOD 703>;
|
||||
};
|
||||
|
||||
usb-phy@ee0a0200 {
|
||||
compatible = "renesas,usb2-phy-r8a7795", "renesas,rcar-gen3-usb2-phy";
|
||||
reg = <0 0xee0a0200 0 0x700>;
|
||||
clocks = <&mstp7_clks R8A7795_CLK_EHCI0>;
|
||||
clocks = <&cpg CPG_MOD 702>;
|
||||
};
|
||||
|
31
Documentation/devicetree/bindings/phy/rockchip-pcie-phy.txt
Normal file
31
Documentation/devicetree/bindings/phy/rockchip-pcie-phy.txt
Normal file
@ -0,0 +1,31 @@
|
||||
Rockchip PCIE PHY
|
||||
-----------------------
|
||||
|
||||
Required properties:
|
||||
- compatible: rockchip,rk3399-pcie-phy
|
||||
- #phy-cells: must be 0
|
||||
- clocks: Must contain an entry in clock-names.
|
||||
See ../clocks/clock-bindings.txt for details.
|
||||
- clock-names: Must be "refclk"
|
||||
- resets: Must contain an entry in reset-names.
|
||||
See ../reset/reset.txt for details.
|
||||
- reset-names: Must be "phy"
|
||||
|
||||
Example:
|
||||
|
||||
grf: syscon@ff770000 {
|
||||
compatible = "rockchip,rk3399-grf", "syscon", "simple-mfd";
|
||||
#address-cells = <1>;
|
||||
#size-cells = <1>;
|
||||
|
||||
...
|
||||
|
||||
pcie_phy: pcie-phy {
|
||||
compatible = "rockchip,rk3399-pcie-phy";
|
||||
#phy-cells = <0>;
|
||||
clocks = <&cru SCLK_PCIEPHY_REF>;
|
||||
clock-names = "refclk";
|
||||
resets = <&cru SRST_PCIEPHY>;
|
||||
reset-names = "phy";
|
||||
};
|
||||
};
|
@ -27,6 +27,9 @@ Optional Properties:
|
||||
- clocks : phandle + clock specifier for the phy clocks
|
||||
- clock-names: string, clock name, must be "phyclk"
|
||||
- #clock-cells: for users of the phy-pll, should be 0
|
||||
- reset-names: Only allow the following entries:
|
||||
- phy-reset
|
||||
- resets: Must contain an entry for each entry in reset-names.
|
||||
|
||||
Example:
|
||||
|
||||
|
@ -10,6 +10,7 @@ Required properties:
|
||||
* allwinner,sun8i-a23-usb-phy
|
||||
* allwinner,sun8i-a33-usb-phy
|
||||
* allwinner,sun8i-h3-usb-phy
|
||||
* allwinner,sun50i-a64-usb-phy
|
||||
- reg : a list of offset + length pairs
|
||||
- reg-names :
|
||||
* "phy_ctrl"
|
||||
|
@ -31,6 +31,8 @@ OMAP USB2 PHY
|
||||
|
||||
Required properties:
|
||||
- compatible: Should be "ti,omap-usb2"
|
||||
Should be "ti,dra7x-usb2" for the 1st instance of USB2 PHY on
|
||||
DRA7x
|
||||
Should be "ti,dra7x-usb2-phy2" for the 2nd instance of USB2 PHY
|
||||
in DRA7x
|
||||
- reg : Address and length of the register set for the device.
|
||||
|
@ -81,6 +81,8 @@ i.mx specific properties
|
||||
- fsl,usbmisc: phandler of non-core register device, with one
|
||||
argument that indicate usb controller index
|
||||
- disable-over-current: disable over current detect
|
||||
- over-current-active-high: over current signal polarity is high active,
|
||||
typically over current signal polarity is low active.
|
||||
- external-vbus-divider: enables off-chip resistor divider for Vbus
|
||||
|
||||
Example:
|
||||
|
@ -26,7 +26,10 @@ Refer to phy/phy-bindings.txt for generic phy consumer properties
|
||||
- g-use-dma: enable dma usage in gadget driver.
|
||||
- g-rx-fifo-size: size of rx fifo size in gadget mode.
|
||||
- g-np-tx-fifo-size: size of non-periodic tx fifo size in gadget mode.
|
||||
- g-tx-fifo-size: size of periodic tx fifo per endpoint (except ep0) in gadget mode.
|
||||
|
||||
Deprecated properties:
|
||||
- g-tx-fifo-size: size of periodic tx fifo per endpoint (except ep0)
|
||||
in gadget mode.
|
||||
|
||||
Example:
|
||||
|
||||
|
28
Documentation/devicetree/bindings/usb/dwc3-cavium.txt
Normal file
28
Documentation/devicetree/bindings/usb/dwc3-cavium.txt
Normal file
@ -0,0 +1,28 @@
|
||||
Cavium SuperSpeed DWC3 USB SoC controller
|
||||
|
||||
Required properties:
|
||||
- compatible: Should contain "cavium,octeon-7130-usb-uctl"
|
||||
|
||||
Required child node:
|
||||
A child node must exist to represent the core DWC3 IP block. The name of
|
||||
the node is not important. The content of the node is defined in dwc3.txt.
|
||||
|
||||
Example device node:
|
||||
|
||||
uctl@1180069000000 {
|
||||
compatible = "cavium,octeon-7130-usb-uctl";
|
||||
reg = <0x00011800 0x69000000 0x00000000 0x00000100>;
|
||||
ranges;
|
||||
#address-cells = <0x00000002>;
|
||||
#size-cells = <0x00000002>;
|
||||
refclk-frequency = <0x05f5e100>;
|
||||
refclk-type-ss = "dlmc_ref_clk0";
|
||||
refclk-type-hs = "dlmc_ref_clk0";
|
||||
power = <0x00000002 0x00000002 0x00000001>;
|
||||
xhci@1690000000000 {
|
||||
compatible = "cavium,octeon-7130-xhci", "synopsys,dwc3";
|
||||
reg = <0x00016900 0x00000000 0x00000010 0x00000000>;
|
||||
interrupt-parent = <0x00000010>;
|
||||
interrupts = <0x00000009 0x00000004>;
|
||||
};
|
||||
};
|
@ -13,7 +13,8 @@ Optional properties:
|
||||
in the array is expected to be a handle to the USB2/HS PHY and
|
||||
the second element is expected to be a handle to the USB3/SS PHY
|
||||
- phys: from the *Generic PHY* bindings
|
||||
- phy-names: from the *Generic PHY* bindings
|
||||
- phy-names: from the *Generic PHY* bindings; supported names are "usb2-phy"
|
||||
or "usb3-phy".
|
||||
- snps,usb3_lpm_capable: determines if platform is USB3 LPM capable
|
||||
- snps,disable_scramble_quirk: true when SW should disable data scrambling.
|
||||
Only really useful for FPGA builds.
|
||||
@ -39,6 +40,11 @@ Optional properties:
|
||||
disabling the suspend signal to the PHY.
|
||||
- snps,dis_rxdet_inp3_quirk: when set core will disable receiver detection
|
||||
in PHY P3 power state.
|
||||
- snps,dis-u2-freeclk-exists-quirk: when set, clear the u2_freeclk_exists
|
||||
in GUSB2PHYCFG, specify that USB2 PHY doesn't provide
|
||||
a free-running PHY clock.
|
||||
- snps,dis-del-phy-power-chg-quirk: when set core will change PHY power
|
||||
from P0 to P1/P2/P3 without delay.
|
||||
- snps,is-utmi-l1-suspend: true when DWC3 asserts output signal
|
||||
utmi_l1_suspend_n, false when asserts utmi_sleep_n
|
||||
- snps,hird-threshold: HIRD threshold
|
||||
|
@ -11,6 +11,11 @@ Optional properties:
|
||||
"peripheral" and "otg". In case this attribute isn't
|
||||
passed via DT, USB DRD controllers should default to
|
||||
OTG.
|
||||
- phy_type: tells USB controllers that we want to configure the core to support
|
||||
a UTMI+ PHY with an 8- or 16-bit interface if UTMI+ is
|
||||
selected. Valid arguments are "utmi" and "utmi_wide".
|
||||
In case this isn't passed via DT, USB controllers should
|
||||
default to HW capability.
|
||||
- otg-rev: tells usb driver the release number of the OTG and EH supplement
|
||||
with which the device and its descriptors are compliant,
|
||||
in binary-coded decimal (i.e. 2.0 is 0200H). This
|
||||
@ -34,6 +39,7 @@ dwc3@4a030000 {
|
||||
usb-phy = <&usb2_phy>, <&usb3,phy>;
|
||||
maximum-speed = "super-speed";
|
||||
dr_mode = "otg";
|
||||
phy_type = "utmi_wide";
|
||||
otg-rev = <0x0200>;
|
||||
adp-disable;
|
||||
};
|
||||
|
@ -9,6 +9,7 @@ Required properties:
|
||||
- "renesas,usbhs-r8a7793" for r8a7793 (R-Car M2-N) compatible device
|
||||
- "renesas,usbhs-r8a7794" for r8a7794 (R-Car E2) compatible device
|
||||
- "renesas,usbhs-r8a7795" for r8a7795 (R-Car H3) compatible device
|
||||
- "renesas,usbhs-r8a7796" for r8a7796 (R-Car M3-W) compatible device
|
||||
- "renesas,rcar-gen2-usbhs" for R-Car Gen2 compatible device
|
||||
- "renesas,rcar-gen3-usbhs" for R-Car Gen3 compatible device
|
||||
|
||||
|
59
Documentation/devicetree/bindings/usb/rockchip,dwc3.txt
Normal file
59
Documentation/devicetree/bindings/usb/rockchip,dwc3.txt
Normal file
@ -0,0 +1,59 @@
|
||||
Rockchip SuperSpeed DWC3 USB SoC controller
|
||||
|
||||
Required properties:
|
||||
- compatible: should contain "rockchip,rk3399-dwc3" for rk3399 SoC
|
||||
- clocks: A list of phandle + clock-specifier pairs for the
|
||||
clocks listed in clock-names
|
||||
- clock-names: Should contain the following:
|
||||
"ref_clk" Controller reference clk, have to be 24 MHz
|
||||
"suspend_clk" Controller suspend clk, have to be 24 MHz or 32 KHz
|
||||
"bus_clk" Master/Core clock, have to be >= 62.5 MHz for SS
|
||||
operation and >= 30MHz for HS operation
|
||||
"grf_clk" Controller grf clk
|
||||
|
||||
Required child node:
|
||||
A child node must exist to represent the core DWC3 IP block. The name of
|
||||
the node is not important. The content of the node is defined in dwc3.txt.
|
||||
|
||||
Phy documentation is provided in the following places:
|
||||
Documentation/devicetree/bindings/phy/rockchip,dwc3-usb-phy.txt
|
||||
|
||||
Example device nodes:
|
||||
|
||||
usbdrd3_0: usb@fe800000 {
|
||||
compatible = "rockchip,rk3399-dwc3";
|
||||
clocks = <&cru SCLK_USB3OTG0_REF>, <&cru SCLK_USB3OTG0_SUSPEND>,
|
||||
<&cru ACLK_USB3OTG0>, <&cru ACLK_USB3_GRF>;
|
||||
clock-names = "ref_clk", "suspend_clk",
|
||||
"bus_clk", "grf_clk";
|
||||
#address-cells = <2>;
|
||||
#size-cells = <2>;
|
||||
ranges;
|
||||
status = "disabled";
|
||||
usbdrd_dwc3_0: dwc3@fe800000 {
|
||||
compatible = "snps,dwc3";
|
||||
reg = <0x0 0xfe800000 0x0 0x100000>;
|
||||
interrupts = <GIC_SPI 105 IRQ_TYPE_LEVEL_HIGH>;
|
||||
dr_mode = "otg";
|
||||
status = "disabled";
|
||||
};
|
||||
};
|
||||
|
||||
usbdrd3_1: usb@fe900000 {
|
||||
compatible = "rockchip,rk3399-dwc3";
|
||||
clocks = <&cru SCLK_USB3OTG1_REF>, <&cru SCLK_USB3OTG1_SUSPEND>,
|
||||
<&cru ACLK_USB3OTG1>, <&cru ACLK_USB3_GRF>;
|
||||
clock-names = "ref_clk", "suspend_clk",
|
||||
"bus_clk", "grf_clk";
|
||||
#address-cells = <2>;
|
||||
#size-cells = <2>;
|
||||
ranges;
|
||||
status = "disabled";
|
||||
usbdrd_dwc3_1: dwc3@fe900000 {
|
||||
compatible = "snps,dwc3";
|
||||
reg = <0x0 0xfe900000 0x0 0x100000>;
|
||||
interrupts = <GIC_SPI 110 IRQ_TYPE_LEVEL_HIGH>;
|
||||
dr_mode = "otg";
|
||||
status = "disabled";
|
||||
};
|
||||
};
|
19
Documentation/devicetree/bindings/usb/usb4604.txt
Normal file
19
Documentation/devicetree/bindings/usb/usb4604.txt
Normal file
@ -0,0 +1,19 @@
|
||||
SMSC USB4604 High-Speed Hub Controller
|
||||
|
||||
Required properties:
|
||||
- compatible: Should be "smsc,usb4604"
|
||||
|
||||
Optional properties:
|
||||
- reg: Specifies the i2c slave address, it is required and should be 0x2d
|
||||
if I2C is used.
|
||||
- reset-gpios: Should specify GPIO for reset.
|
||||
- initial-mode: Should specify initial mode.
|
||||
(1 for HUB mode, 2 for STANDBY mode)
|
||||
|
||||
Examples:
|
||||
usb-hub@2d {
|
||||
compatible = "smsc,usb4604";
|
||||
reg = <0x2d>;
|
||||
reset-gpios = <&gpx3 5 1>;
|
||||
initial-mode = <1>;
|
||||
};
|
@ -6,6 +6,7 @@ Required properties:
|
||||
"fsl,imx6q-usbmisc" for imx6q
|
||||
"fsl,vf610-usbmisc" for Vybrid vf610
|
||||
"fsl,imx6sx-usbmisc" for imx6sx
|
||||
"fsl,imx7d-usbmisc" for imx7d
|
||||
- reg: Should contain registers location and length
|
||||
|
||||
Examples:
|
||||
|
@ -4248,6 +4248,8 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
|
||||
u = IGNORE_UAS (don't bind to the uas driver);
|
||||
w = NO_WP_DETECT (don't test whether the
|
||||
medium is write-protected).
|
||||
y = ALWAYS_SYNC (issue a SYNCHRONIZE_CACHE
|
||||
even if the device claims no cache)
|
||||
Example: quirks=0419:aaf5:rl,0421:0433:rc
|
||||
|
||||
user_debug= [KNL,ARM]
|
||||
|
41
Documentation/leds/ledtrig-usbport.txt
Normal file
41
Documentation/leds/ledtrig-usbport.txt
Normal file
@ -0,0 +1,41 @@
|
||||
USB port LED trigger
|
||||
====================
|
||||
|
||||
This LED trigger can be used for signalling to the user a presence of USB device
|
||||
in a given port. It simply turns on LED when device appears and turns it off
|
||||
when it disappears.
|
||||
|
||||
It requires selecting USB ports that should be observed. All available ones are
|
||||
listed as separated entries in a "ports" subdirectory. Selecting is handled by
|
||||
echoing "1" to a chosen port.
|
||||
|
||||
Please note that this trigger allows selecting multiple USB ports for a single
|
||||
LED. This can be useful in two cases:
|
||||
|
||||
1) Device with single USB LED and few physical ports
|
||||
|
||||
In such a case LED will be turned on as long as there is at least one connected
|
||||
USB device.
|
||||
|
||||
2) Device with a physical port handled by few controllers
|
||||
|
||||
Some devices may have one controller per PHY standard. E.g. USB 3.0 physical
|
||||
port may be handled by ohci-platform, ehci-platform and xhci-hcd. If there is
|
||||
only one LED user will most likely want to assign ports from all 3 hubs.
|
||||
|
||||
|
||||
This trigger can be activated from user space on led class devices as shown
|
||||
below:
|
||||
|
||||
echo usbport > trigger
|
||||
|
||||
This adds sysfs attributes to the LED that are documented in:
|
||||
Documentation/ABI/testing/sysfs-class-led-trigger-usbport
|
||||
|
||||
Example use-case:
|
||||
|
||||
echo usbport > trigger
|
||||
echo 1 > ports/usb1-port1
|
||||
echo 1 > ports/usb2-port1
|
||||
cat ports/usb1-port1
|
||||
echo 0 > ports/usb1-port1
|
@ -12216,7 +12216,7 @@ S: Maintained
|
||||
F: drivers/net/usb/lan78xx.*
|
||||
|
||||
USB MASS STORAGE DRIVER
|
||||
M: Matthew Dharm <mdharm-usb@one-eyed-alien.net>
|
||||
M: Alan Stern <stern@rowland.harvard.edu>
|
||||
L: linux-usb@vger.kernel.org
|
||||
L: usb-storage@lists.one-eyed-alien.net
|
||||
S: Maintained
|
||||
@ -12300,6 +12300,7 @@ F: drivers/net/usb/rtl8150.c
|
||||
USB SERIAL SUBSYSTEM
|
||||
M: Johan Hovold <johan@kernel.org>
|
||||
L: linux-usb@vger.kernel.org
|
||||
T: git git://git.kernel.org/pub/scm/linux/kernel/git/johan/usb-serial.git
|
||||
S: Maintained
|
||||
F: Documentation/usb/usb-serial.txt
|
||||
F: drivers/usb/serial/
|
||||
|
@ -185,10 +185,8 @@ static int bcm203x_probe(struct usb_interface *intf, const struct usb_device_id
|
||||
data->state = BCM203X_LOAD_MINIDRV;
|
||||
|
||||
data->urb = usb_alloc_urb(0, GFP_KERNEL);
|
||||
if (!data->urb) {
|
||||
BT_ERR("Can't allocate URB");
|
||||
if (!data->urb)
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
if (request_firmware(&firmware, "BCM2033-MD.hex", &udev->dev) < 0) {
|
||||
BT_ERR("Mini driver request failed");
|
||||
|
@ -96,6 +96,12 @@ config EXTCON_PALMAS
|
||||
Say Y here to enable support for USB peripheral and USB host
|
||||
detection by palmas usb.
|
||||
|
||||
config EXTCON_QCOM_SPMI_MISC
|
||||
tristate "Qualcomm USB extcon support"
|
||||
help
|
||||
Say Y here to enable SPMI PMIC based USB cable detection
|
||||
support on Qualcomm PMICs such as PM8941.
|
||||
|
||||
config EXTCON_RT8973A
|
||||
tristate "Richtek RT8973A EXTCON support"
|
||||
depends on I2C
|
||||
|
@ -14,6 +14,7 @@ obj-$(CONFIG_EXTCON_MAX77693) += extcon-max77693.o
|
||||
obj-$(CONFIG_EXTCON_MAX77843) += extcon-max77843.o
|
||||
obj-$(CONFIG_EXTCON_MAX8997) += extcon-max8997.o
|
||||
obj-$(CONFIG_EXTCON_PALMAS) += extcon-palmas.o
|
||||
obj-$(CONFIG_EXTCON_QCOM_SPMI_MISC) += extcon-qcom-spmi-misc.o
|
||||
obj-$(CONFIG_EXTCON_RT8973A) += extcon-rt8973a.o
|
||||
obj-$(CONFIG_EXTCON_SM5502) += extcon-sm5502.o
|
||||
obj-$(CONFIG_EXTCON_USB_GPIO) += extcon-usb-gpio.o
|
||||
|
@ -3,6 +3,9 @@
|
||||
*
|
||||
* Analog Jack extcon driver with ADC-based detection capability.
|
||||
*
|
||||
* Copyright (C) 2016 Samsung Electronics
|
||||
* Chanwoo Choi <cw00.choi@samsung.com>
|
||||
*
|
||||
* Copyright (C) 2012 Samsung Electronics
|
||||
* MyungJoo Ham <myungjoo.ham@samsung.com>
|
||||
*
|
||||
@ -58,7 +61,7 @@ static void adc_jack_handler(struct work_struct *work)
|
||||
struct adc_jack_data *data = container_of(to_delayed_work(work),
|
||||
struct adc_jack_data,
|
||||
handler);
|
||||
u32 state = 0;
|
||||
struct adc_jack_cond *def;
|
||||
int ret, adc_val;
|
||||
int i;
|
||||
|
||||
@ -70,17 +73,18 @@ static void adc_jack_handler(struct work_struct *work)
|
||||
|
||||
/* Get state from adc value with adc_conditions */
|
||||
for (i = 0; i < data->num_conditions; i++) {
|
||||
struct adc_jack_cond *def = &data->adc_conditions[i];
|
||||
if (!def->state)
|
||||
break;
|
||||
def = &data->adc_conditions[i];
|
||||
if (def->min_adc <= adc_val && def->max_adc >= adc_val) {
|
||||
state = def->state;
|
||||
break;
|
||||
extcon_set_state_sync(data->edev, def->id, true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
/* if no def has met, it means state = 0 (no cables attached) */
|
||||
|
||||
extcon_set_state(data->edev, state);
|
||||
/* Set the detached state if adc value is not included in the range */
|
||||
for (i = 0; i < data->num_conditions; i++) {
|
||||
def = &data->adc_conditions[i];
|
||||
extcon_set_state_sync(data->edev, def->id, false);
|
||||
}
|
||||
}
|
||||
|
||||
static irqreturn_t adc_jack_irq_thread(int irq, void *_data)
|
||||
@ -114,16 +118,14 @@ static int adc_jack_probe(struct platform_device *pdev)
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
if (!pdata->adc_conditions ||
|
||||
!pdata->adc_conditions[0].state) {
|
||||
if (!pdata->adc_conditions) {
|
||||
dev_err(&pdev->dev, "error: adc_conditions not defined.\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
data->adc_conditions = pdata->adc_conditions;
|
||||
|
||||
/* Check the length of array and set num_conditions */
|
||||
for (i = 0; data->adc_conditions[i].state; i++)
|
||||
;
|
||||
for (i = 0; data->adc_conditions[i].id != EXTCON_NONE; i++);
|
||||
data->num_conditions = i;
|
||||
|
||||
data->chan = iio_channel_get(&pdev->dev, pdata->consumer_channel);
|
||||
@ -158,6 +160,7 @@ static int adc_jack_probe(struct platform_device *pdev)
|
||||
if (data->wakeup_source)
|
||||
device_init_wakeup(&pdev->dev, 1);
|
||||
|
||||
adc_jack_handler(&data->handler.work);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -183,7 +183,7 @@ static void arizona_extcon_hp_clamp(struct arizona_extcon_info *info,
|
||||
if (clamp)
|
||||
val = ARIZONA_RMV_SHRT_HP1L;
|
||||
break;
|
||||
};
|
||||
}
|
||||
|
||||
snd_soc_dapm_mutex_lock(arizona->dapm);
|
||||
|
||||
@ -614,7 +614,7 @@ static irqreturn_t arizona_hpdet_irq(int irq, void *data)
|
||||
}
|
||||
|
||||
/* If the cable was removed while measuring ignore the result */
|
||||
ret = extcon_get_cable_state_(info->edev, EXTCON_MECHANICAL);
|
||||
ret = extcon_get_state(info->edev, EXTCON_MECHANICAL);
|
||||
if (ret < 0) {
|
||||
dev_err(arizona->dev, "Failed to check cable state: %d\n",
|
||||
ret);
|
||||
@ -649,7 +649,7 @@ static irqreturn_t arizona_hpdet_irq(int irq, void *data)
|
||||
else
|
||||
report = EXTCON_JACK_HEADPHONE;
|
||||
|
||||
ret = extcon_set_cable_state_(info->edev, report, true);
|
||||
ret = extcon_set_state_sync(info->edev, report, true);
|
||||
if (ret != 0)
|
||||
dev_err(arizona->dev, "Failed to report HP/line: %d\n",
|
||||
ret);
|
||||
@ -732,7 +732,7 @@ err:
|
||||
ARIZONA_ACCDET_MODE_MASK, ARIZONA_ACCDET_MODE_MIC);
|
||||
|
||||
/* Just report headphone */
|
||||
ret = extcon_set_cable_state_(info->edev, EXTCON_JACK_HEADPHONE, true);
|
||||
ret = extcon_set_state_sync(info->edev, EXTCON_JACK_HEADPHONE, true);
|
||||
if (ret != 0)
|
||||
dev_err(arizona->dev, "Failed to report headphone: %d\n", ret);
|
||||
|
||||
@ -789,7 +789,7 @@ err:
|
||||
ARIZONA_ACCDET_MODE_MASK, ARIZONA_ACCDET_MODE_MIC);
|
||||
|
||||
/* Just report headphone */
|
||||
ret = extcon_set_cable_state_(info->edev, EXTCON_JACK_HEADPHONE, true);
|
||||
ret = extcon_set_state_sync(info->edev, EXTCON_JACK_HEADPHONE, true);
|
||||
if (ret != 0)
|
||||
dev_err(arizona->dev, "Failed to report headphone: %d\n", ret);
|
||||
|
||||
@ -829,7 +829,7 @@ static void arizona_micd_detect(struct work_struct *work)
|
||||
mutex_lock(&info->lock);
|
||||
|
||||
/* If the cable was removed while measuring ignore the result */
|
||||
ret = extcon_get_cable_state_(info->edev, EXTCON_MECHANICAL);
|
||||
ret = extcon_get_state(info->edev, EXTCON_MECHANICAL);
|
||||
if (ret < 0) {
|
||||
dev_err(arizona->dev, "Failed to check cable state: %d\n",
|
||||
ret);
|
||||
@ -914,7 +914,7 @@ static void arizona_micd_detect(struct work_struct *work)
|
||||
|
||||
arizona_identify_headphone(info);
|
||||
|
||||
ret = extcon_set_cable_state_(info->edev,
|
||||
ret = extcon_set_state_sync(info->edev,
|
||||
EXTCON_JACK_MICROPHONE, true);
|
||||
if (ret != 0)
|
||||
dev_err(arizona->dev, "Headset report failed: %d\n",
|
||||
@ -1108,7 +1108,7 @@ static irqreturn_t arizona_jackdet(int irq, void *data)
|
||||
|
||||
if (info->last_jackdet == present) {
|
||||
dev_dbg(arizona->dev, "Detected jack\n");
|
||||
ret = extcon_set_cable_state_(info->edev,
|
||||
ret = extcon_set_state_sync(info->edev,
|
||||
EXTCON_MECHANICAL, true);
|
||||
|
||||
if (ret != 0)
|
||||
@ -1149,10 +1149,13 @@ static irqreturn_t arizona_jackdet(int irq, void *data)
|
||||
info->micd_ranges[i].key, 0);
|
||||
input_sync(info->input);
|
||||
|
||||
ret = extcon_update_state(info->edev, 0xffffffff, 0);
|
||||
if (ret != 0)
|
||||
dev_err(arizona->dev, "Removal report failed: %d\n",
|
||||
ret);
|
||||
for (i = 0; i < ARRAY_SIZE(arizona_cable) - 1; i++) {
|
||||
ret = extcon_set_state_sync(info->edev,
|
||||
arizona_cable[i], false);
|
||||
if (ret != 0)
|
||||
dev_err(arizona->dev,
|
||||
"Removal report failed: %d\n", ret);
|
||||
}
|
||||
|
||||
regmap_update_bits(arizona->regmap,
|
||||
ARIZONA_JACK_DETECT_DEBOUNCE,
|
||||
|
@ -189,19 +189,19 @@ static int axp288_handle_chrg_det_event(struct axp288_extcon_info *info)
|
||||
|
||||
switch (chrg_type) {
|
||||
case DET_STAT_SDP:
|
||||
dev_dbg(info->dev, "sdp cable is connecetd\n");
|
||||
dev_dbg(info->dev, "sdp cable is connected\n");
|
||||
notify_otg = true;
|
||||
notify_charger = true;
|
||||
cable = EXTCON_CHG_USB_SDP;
|
||||
break;
|
||||
case DET_STAT_CDP:
|
||||
dev_dbg(info->dev, "cdp cable is connecetd\n");
|
||||
dev_dbg(info->dev, "cdp cable is connected\n");
|
||||
notify_otg = true;
|
||||
notify_charger = true;
|
||||
cable = EXTCON_CHG_USB_CDP;
|
||||
break;
|
||||
case DET_STAT_DCP:
|
||||
dev_dbg(info->dev, "dcp cable is connecetd\n");
|
||||
dev_dbg(info->dev, "dcp cable is connected\n");
|
||||
notify_charger = true;
|
||||
cable = EXTCON_CHG_USB_DCP;
|
||||
break;
|
||||
@ -226,7 +226,7 @@ notify_otg:
|
||||
}
|
||||
|
||||
if (notify_charger)
|
||||
extcon_set_cable_state_(info->edev, cable, vbus_attach);
|
||||
extcon_set_state_sync(info->edev, cable, vbus_attach);
|
||||
|
||||
/* Clear the flags on disconnect event */
|
||||
if (!vbus_attach)
|
||||
|
@ -49,7 +49,8 @@ static void gpio_extcon_work(struct work_struct *work)
|
||||
state = gpiod_get_value_cansleep(data->id_gpiod);
|
||||
if (data->pdata->gpio_active_low)
|
||||
state = !state;
|
||||
extcon_set_state(data->edev, state);
|
||||
|
||||
extcon_set_state_sync(data->edev, data->pdata->extcon_id, state);
|
||||
}
|
||||
|
||||
static irqreturn_t gpio_irq_handler(int irq, void *dev_id)
|
||||
|
@ -3,7 +3,7 @@
|
||||
*
|
||||
* Copyright (C) 2013,2014 Samsung Electronics
|
||||
* Chanwoo Choi <cw00.choi@samsung.com>
|
||||
* Krzysztof Kozlowski <k.kozlowski@samsung.com>
|
||||
* Krzysztof Kozlowski <krzk@kernel.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -357,7 +357,7 @@ static int max14577_muic_jig_handler(struct max14577_muic_info *info,
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
extcon_set_cable_state_(info->edev, EXTCON_JIG, attached);
|
||||
extcon_set_state_sync(info->edev, EXTCON_JIG, attached);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -454,24 +454,24 @@ static int max14577_muic_chg_handler(struct max14577_muic_info *info)
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
extcon_set_cable_state_(info->edev, EXTCON_USB, attached);
|
||||
extcon_set_cable_state_(info->edev, EXTCON_CHG_USB_SDP,
|
||||
extcon_set_state_sync(info->edev, EXTCON_USB, attached);
|
||||
extcon_set_state_sync(info->edev, EXTCON_CHG_USB_SDP,
|
||||
attached);
|
||||
break;
|
||||
case MAX14577_CHARGER_TYPE_DEDICATED_CHG:
|
||||
extcon_set_cable_state_(info->edev, EXTCON_CHG_USB_DCP,
|
||||
extcon_set_state_sync(info->edev, EXTCON_CHG_USB_DCP,
|
||||
attached);
|
||||
break;
|
||||
case MAX14577_CHARGER_TYPE_DOWNSTREAM_PORT:
|
||||
extcon_set_cable_state_(info->edev, EXTCON_CHG_USB_CDP,
|
||||
extcon_set_state_sync(info->edev, EXTCON_CHG_USB_CDP,
|
||||
attached);
|
||||
break;
|
||||
case MAX14577_CHARGER_TYPE_SPECIAL_500MA:
|
||||
extcon_set_cable_state_(info->edev, EXTCON_CHG_USB_SLOW,
|
||||
extcon_set_state_sync(info->edev, EXTCON_CHG_USB_SLOW,
|
||||
attached);
|
||||
break;
|
||||
case MAX14577_CHARGER_TYPE_SPECIAL_1A:
|
||||
extcon_set_cable_state_(info->edev, EXTCON_CHG_USB_FAST,
|
||||
extcon_set_state_sync(info->edev, EXTCON_CHG_USB_FAST,
|
||||
attached);
|
||||
break;
|
||||
case MAX14577_CHARGER_TYPE_NONE:
|
||||
@ -791,6 +791,6 @@ static struct platform_driver max14577_muic_driver = {
|
||||
module_platform_driver(max14577_muic_driver);
|
||||
|
||||
MODULE_DESCRIPTION("Maxim 14577/77836 Extcon driver");
|
||||
MODULE_AUTHOR("Chanwoo Choi <cw00.choi@samsung.com>, Krzysztof Kozlowski <k.kozlowski@samsung.com>");
|
||||
MODULE_AUTHOR("Chanwoo Choi <cw00.choi@samsung.com>, Krzysztof Kozlowski <krzk@kernel.org>");
|
||||
MODULE_LICENSE("GPL");
|
||||
MODULE_ALIAS("platform:extcon-max14577");
|
||||
|
@ -39,16 +39,16 @@ static irqreturn_t max3355_id_irq(int irq, void *dev_id)
|
||||
* As we don't have event for USB peripheral cable attached,
|
||||
* we simulate USB peripheral attach here.
|
||||
*/
|
||||
extcon_set_cable_state_(data->edev, EXTCON_USB_HOST, false);
|
||||
extcon_set_cable_state_(data->edev, EXTCON_USB, true);
|
||||
extcon_set_state_sync(data->edev, EXTCON_USB_HOST, false);
|
||||
extcon_set_state_sync(data->edev, EXTCON_USB, true);
|
||||
} else {
|
||||
/*
|
||||
* ID = 0 means USB HOST cable attached.
|
||||
* As we don't have event for USB peripheral cable detached,
|
||||
* we simulate USB peripheral detach here.
|
||||
*/
|
||||
extcon_set_cable_state_(data->edev, EXTCON_USB, false);
|
||||
extcon_set_cable_state_(data->edev, EXTCON_USB_HOST, true);
|
||||
extcon_set_state_sync(data->edev, EXTCON_USB, false);
|
||||
extcon_set_state_sync(data->edev, EXTCON_USB_HOST, true);
|
||||
}
|
||||
|
||||
return IRQ_HANDLED;
|
||||
|
@ -505,8 +505,8 @@ static int max77693_muic_dock_handler(struct max77693_muic_info *info,
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
extcon_set_cable_state_(info->edev, EXTCON_DOCK, attached);
|
||||
extcon_set_cable_state_(info->edev, EXTCON_DISP_MHL, attached);
|
||||
extcon_set_state_sync(info->edev, EXTCON_DOCK, attached);
|
||||
extcon_set_state_sync(info->edev, EXTCON_DISP_MHL, attached);
|
||||
goto out;
|
||||
case MAX77693_MUIC_ADC_AUDIO_MODE_REMOTE: /* Dock-Desk */
|
||||
dock_id = EXTCON_DOCK;
|
||||
@ -514,8 +514,8 @@ static int max77693_muic_dock_handler(struct max77693_muic_info *info,
|
||||
case MAX77693_MUIC_ADC_AV_CABLE_NOLOAD: /* Dock-Audio */
|
||||
dock_id = EXTCON_DOCK;
|
||||
if (!attached) {
|
||||
extcon_set_cable_state_(info->edev, EXTCON_USB, false);
|
||||
extcon_set_cable_state_(info->edev, EXTCON_CHG_USB_SDP,
|
||||
extcon_set_state_sync(info->edev, EXTCON_USB, false);
|
||||
extcon_set_state_sync(info->edev, EXTCON_CHG_USB_SDP,
|
||||
false);
|
||||
}
|
||||
break;
|
||||
@ -530,7 +530,7 @@ static int max77693_muic_dock_handler(struct max77693_muic_info *info,
|
||||
attached);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
extcon_set_cable_state_(info->edev, dock_id, attached);
|
||||
extcon_set_state_sync(info->edev, dock_id, attached);
|
||||
|
||||
out:
|
||||
return 0;
|
||||
@ -596,7 +596,7 @@ static int max77693_muic_adc_ground_handler(struct max77693_muic_info *info)
|
||||
attached);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
extcon_set_cable_state_(info->edev, EXTCON_USB_HOST, attached);
|
||||
extcon_set_state_sync(info->edev, EXTCON_USB_HOST, attached);
|
||||
break;
|
||||
case MAX77693_MUIC_GND_AV_CABLE_LOAD:
|
||||
/* Audio Video Cable with load, PATH:AUDIO */
|
||||
@ -604,14 +604,14 @@ static int max77693_muic_adc_ground_handler(struct max77693_muic_info *info)
|
||||
attached);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
extcon_set_cable_state_(info->edev, EXTCON_USB, attached);
|
||||
extcon_set_cable_state_(info->edev, EXTCON_CHG_USB_SDP,
|
||||
extcon_set_state_sync(info->edev, EXTCON_USB, attached);
|
||||
extcon_set_state_sync(info->edev, EXTCON_CHG_USB_SDP,
|
||||
attached);
|
||||
break;
|
||||
case MAX77693_MUIC_GND_MHL:
|
||||
case MAX77693_MUIC_GND_MHL_VB:
|
||||
/* MHL or MHL with USB/TA cable */
|
||||
extcon_set_cable_state_(info->edev, EXTCON_DISP_MHL, attached);
|
||||
extcon_set_state_sync(info->edev, EXTCON_DISP_MHL, attached);
|
||||
break;
|
||||
default:
|
||||
dev_err(info->dev, "failed to detect %s cable of gnd type\n",
|
||||
@ -653,7 +653,7 @@ static int max77693_muic_jig_handler(struct max77693_muic_info *info,
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
extcon_set_cable_state_(info->edev, EXTCON_JIG, attached);
|
||||
extcon_set_state_sync(info->edev, EXTCON_JIG, attached);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -807,10 +807,10 @@ static int max77693_muic_chg_handler(struct max77693_muic_info *info)
|
||||
* - Support charging through micro-usb port without
|
||||
* data connection
|
||||
*/
|
||||
extcon_set_cable_state_(info->edev, EXTCON_CHG_USB_DCP,
|
||||
extcon_set_state_sync(info->edev, EXTCON_CHG_USB_DCP,
|
||||
attached);
|
||||
if (!cable_attached)
|
||||
extcon_set_cable_state_(info->edev,
|
||||
extcon_set_state_sync(info->edev,
|
||||
EXTCON_DISP_MHL, cable_attached);
|
||||
break;
|
||||
}
|
||||
@ -834,13 +834,13 @@ static int max77693_muic_chg_handler(struct max77693_muic_info *info)
|
||||
* - Support charging through micro-usb port without
|
||||
* data connection.
|
||||
*/
|
||||
extcon_set_cable_state_(info->edev, EXTCON_USB,
|
||||
extcon_set_state_sync(info->edev, EXTCON_USB,
|
||||
attached);
|
||||
extcon_set_cable_state_(info->edev, EXTCON_CHG_USB_SDP,
|
||||
extcon_set_state_sync(info->edev, EXTCON_CHG_USB_SDP,
|
||||
attached);
|
||||
|
||||
if (!cable_attached)
|
||||
extcon_set_cable_state_(info->edev, EXTCON_DOCK,
|
||||
extcon_set_state_sync(info->edev, EXTCON_DOCK,
|
||||
cable_attached);
|
||||
break;
|
||||
case MAX77693_MUIC_ADC_RESERVED_ACC_3: /* Dock-Smart */
|
||||
@ -869,9 +869,9 @@ static int max77693_muic_chg_handler(struct max77693_muic_info *info)
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
extcon_set_cable_state_(info->edev, EXTCON_DOCK,
|
||||
extcon_set_state_sync(info->edev, EXTCON_DOCK,
|
||||
attached);
|
||||
extcon_set_cable_state_(info->edev, EXTCON_DISP_MHL,
|
||||
extcon_set_state_sync(info->edev, EXTCON_DISP_MHL,
|
||||
attached);
|
||||
break;
|
||||
}
|
||||
@ -905,28 +905,28 @@ static int max77693_muic_chg_handler(struct max77693_muic_info *info)
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
extcon_set_cable_state_(info->edev, EXTCON_USB,
|
||||
extcon_set_state_sync(info->edev, EXTCON_USB,
|
||||
attached);
|
||||
extcon_set_cable_state_(info->edev, EXTCON_CHG_USB_SDP,
|
||||
extcon_set_state_sync(info->edev, EXTCON_CHG_USB_SDP,
|
||||
attached);
|
||||
break;
|
||||
case MAX77693_CHARGER_TYPE_DEDICATED_CHG:
|
||||
/* Only TA cable */
|
||||
extcon_set_cable_state_(info->edev, EXTCON_CHG_USB_DCP,
|
||||
extcon_set_state_sync(info->edev, EXTCON_CHG_USB_DCP,
|
||||
attached);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case MAX77693_CHARGER_TYPE_DOWNSTREAM_PORT:
|
||||
extcon_set_cable_state_(info->edev, EXTCON_CHG_USB_CDP,
|
||||
extcon_set_state_sync(info->edev, EXTCON_CHG_USB_CDP,
|
||||
attached);
|
||||
break;
|
||||
case MAX77693_CHARGER_TYPE_APPLE_500MA:
|
||||
extcon_set_cable_state_(info->edev, EXTCON_CHG_USB_SLOW,
|
||||
extcon_set_state_sync(info->edev, EXTCON_CHG_USB_SLOW,
|
||||
attached);
|
||||
break;
|
||||
case MAX77693_CHARGER_TYPE_APPLE_1A_2A:
|
||||
extcon_set_cable_state_(info->edev, EXTCON_CHG_USB_FAST,
|
||||
extcon_set_state_sync(info->edev, EXTCON_CHG_USB_FAST,
|
||||
attached);
|
||||
break;
|
||||
case MAX77693_CHARGER_TYPE_DEAD_BATTERY:
|
||||
|
@ -346,7 +346,7 @@ static int max77843_muic_adc_gnd_handler(struct max77843_muic_info *info)
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
extcon_set_cable_state_(info->edev, EXTCON_USB_HOST, attached);
|
||||
extcon_set_state_sync(info->edev, EXTCON_USB_HOST, attached);
|
||||
break;
|
||||
case MAX77843_MUIC_GND_MHL_VB:
|
||||
case MAX77843_MUIC_GND_MHL:
|
||||
@ -356,7 +356,7 @@ static int max77843_muic_adc_gnd_handler(struct max77843_muic_info *info)
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
extcon_set_cable_state_(info->edev, EXTCON_DISP_MHL, attached);
|
||||
extcon_set_state_sync(info->edev, EXTCON_DISP_MHL, attached);
|
||||
break;
|
||||
default:
|
||||
dev_err(info->dev, "failed to detect %s accessory(gnd:0x%x)\n",
|
||||
@ -392,7 +392,7 @@ static int max77843_muic_jig_handler(struct max77843_muic_info *info,
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
extcon_set_cable_state_(info->edev, EXTCON_JIG, attached);
|
||||
extcon_set_state_sync(info->edev, EXTCON_JIG, attached);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -486,8 +486,8 @@ static int max77843_muic_chg_handler(struct max77843_muic_info *info)
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
extcon_set_cable_state_(info->edev, EXTCON_USB, attached);
|
||||
extcon_set_cable_state_(info->edev, EXTCON_CHG_USB_SDP,
|
||||
extcon_set_state_sync(info->edev, EXTCON_USB, attached);
|
||||
extcon_set_state_sync(info->edev, EXTCON_CHG_USB_SDP,
|
||||
attached);
|
||||
break;
|
||||
case MAX77843_MUIC_CHG_DOWNSTREAM:
|
||||
@ -497,7 +497,7 @@ static int max77843_muic_chg_handler(struct max77843_muic_info *info)
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
extcon_set_cable_state_(info->edev, EXTCON_CHG_USB_CDP,
|
||||
extcon_set_state_sync(info->edev, EXTCON_CHG_USB_CDP,
|
||||
attached);
|
||||
break;
|
||||
case MAX77843_MUIC_CHG_DEDICATED:
|
||||
@ -507,7 +507,7 @@ static int max77843_muic_chg_handler(struct max77843_muic_info *info)
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
extcon_set_cable_state_(info->edev, EXTCON_CHG_USB_DCP,
|
||||
extcon_set_state_sync(info->edev, EXTCON_CHG_USB_DCP,
|
||||
attached);
|
||||
break;
|
||||
case MAX77843_MUIC_CHG_SPECIAL_500MA:
|
||||
@ -517,7 +517,7 @@ static int max77843_muic_chg_handler(struct max77843_muic_info *info)
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
extcon_set_cable_state_(info->edev, EXTCON_CHG_USB_SLOW,
|
||||
extcon_set_state_sync(info->edev, EXTCON_CHG_USB_SLOW,
|
||||
attached);
|
||||
break;
|
||||
case MAX77843_MUIC_CHG_SPECIAL_1A:
|
||||
@ -527,7 +527,7 @@ static int max77843_muic_chg_handler(struct max77843_muic_info *info)
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
extcon_set_cable_state_(info->edev, EXTCON_CHG_USB_FAST,
|
||||
extcon_set_state_sync(info->edev, EXTCON_CHG_USB_FAST,
|
||||
attached);
|
||||
break;
|
||||
case MAX77843_MUIC_CHG_GND:
|
||||
@ -536,10 +536,10 @@ static int max77843_muic_chg_handler(struct max77843_muic_info *info)
|
||||
|
||||
/* Charger cable on MHL accessory is attach or detach */
|
||||
if (gnd_type == MAX77843_MUIC_GND_MHL_VB)
|
||||
extcon_set_cable_state_(info->edev, EXTCON_CHG_USB_DCP,
|
||||
extcon_set_state_sync(info->edev, EXTCON_CHG_USB_DCP,
|
||||
true);
|
||||
else if (gnd_type == MAX77843_MUIC_GND_MHL)
|
||||
extcon_set_cable_state_(info->edev, EXTCON_CHG_USB_DCP,
|
||||
extcon_set_state_sync(info->edev, EXTCON_CHG_USB_DCP,
|
||||
false);
|
||||
break;
|
||||
case MAX77843_MUIC_CHG_NONE:
|
||||
|
@ -331,11 +331,11 @@ static int max8997_muic_handle_usb(struct max8997_muic_info *info,
|
||||
|
||||
switch (usb_type) {
|
||||
case MAX8997_USB_HOST:
|
||||
extcon_set_cable_state_(info->edev, EXTCON_USB_HOST, attached);
|
||||
extcon_set_state_sync(info->edev, EXTCON_USB_HOST, attached);
|
||||
break;
|
||||
case MAX8997_USB_DEVICE:
|
||||
extcon_set_cable_state_(info->edev, EXTCON_USB, attached);
|
||||
extcon_set_cable_state_(info->edev, EXTCON_CHG_USB_SDP,
|
||||
extcon_set_state_sync(info->edev, EXTCON_USB, attached);
|
||||
extcon_set_state_sync(info->edev, EXTCON_CHG_USB_SDP,
|
||||
attached);
|
||||
break;
|
||||
default:
|
||||
@ -361,7 +361,7 @@ static int max8997_muic_handle_dock(struct max8997_muic_info *info,
|
||||
switch (cable_type) {
|
||||
case MAX8997_MUIC_ADC_AV_CABLE_NOLOAD:
|
||||
case MAX8997_MUIC_ADC_FACTORY_MODE_UART_ON:
|
||||
extcon_set_cable_state_(info->edev, EXTCON_DOCK, attached);
|
||||
extcon_set_state_sync(info->edev, EXTCON_DOCK, attached);
|
||||
break;
|
||||
default:
|
||||
dev_err(info->dev, "failed to detect %s dock device\n",
|
||||
@ -384,7 +384,7 @@ static int max8997_muic_handle_jig_uart(struct max8997_muic_info *info,
|
||||
return ret;
|
||||
}
|
||||
|
||||
extcon_set_cable_state_(info->edev, EXTCON_JIG, attached);
|
||||
extcon_set_state_sync(info->edev, EXTCON_JIG, attached);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -406,7 +406,7 @@ static int max8997_muic_adc_handler(struct max8997_muic_info *info)
|
||||
return ret;
|
||||
break;
|
||||
case MAX8997_MUIC_ADC_MHL:
|
||||
extcon_set_cable_state_(info->edev, EXTCON_DISP_MHL, attached);
|
||||
extcon_set_state_sync(info->edev, EXTCON_DISP_MHL, attached);
|
||||
break;
|
||||
case MAX8997_MUIC_ADC_FACTORY_MODE_USB_OFF:
|
||||
case MAX8997_MUIC_ADC_FACTORY_MODE_USB_ON:
|
||||
@ -489,19 +489,19 @@ static int max8997_muic_chg_handler(struct max8997_muic_info *info)
|
||||
}
|
||||
break;
|
||||
case MAX8997_CHARGER_TYPE_DOWNSTREAM_PORT:
|
||||
extcon_set_cable_state_(info->edev, EXTCON_CHG_USB_CDP,
|
||||
extcon_set_state_sync(info->edev, EXTCON_CHG_USB_CDP,
|
||||
attached);
|
||||
break;
|
||||
case MAX8997_CHARGER_TYPE_DEDICATED_CHG:
|
||||
extcon_set_cable_state_(info->edev, EXTCON_CHG_USB_DCP,
|
||||
extcon_set_state_sync(info->edev, EXTCON_CHG_USB_DCP,
|
||||
attached);
|
||||
break;
|
||||
case MAX8997_CHARGER_TYPE_500MA:
|
||||
extcon_set_cable_state_(info->edev, EXTCON_CHG_USB_SLOW,
|
||||
extcon_set_state_sync(info->edev, EXTCON_CHG_USB_SLOW,
|
||||
attached);
|
||||
break;
|
||||
case MAX8997_CHARGER_TYPE_1A:
|
||||
extcon_set_cable_state_(info->edev, EXTCON_CHG_USB_FAST,
|
||||
extcon_set_state_sync(info->edev, EXTCON_CHG_USB_FAST,
|
||||
attached);
|
||||
break;
|
||||
default:
|
||||
|
@ -61,7 +61,7 @@ static irqreturn_t palmas_vbus_irq_handler(int irq, void *_palmas_usb)
|
||||
if (vbus_line_state & PALMAS_INT3_LINE_STATE_VBUS) {
|
||||
if (palmas_usb->linkstat != PALMAS_USB_STATE_VBUS) {
|
||||
palmas_usb->linkstat = PALMAS_USB_STATE_VBUS;
|
||||
extcon_set_cable_state_(edev, EXTCON_USB, true);
|
||||
extcon_set_state_sync(edev, EXTCON_USB, true);
|
||||
dev_info(palmas_usb->dev, "USB cable is attached\n");
|
||||
} else {
|
||||
dev_dbg(palmas_usb->dev,
|
||||
@ -70,7 +70,7 @@ static irqreturn_t palmas_vbus_irq_handler(int irq, void *_palmas_usb)
|
||||
} else if (!(vbus_line_state & PALMAS_INT3_LINE_STATE_VBUS)) {
|
||||
if (palmas_usb->linkstat == PALMAS_USB_STATE_VBUS) {
|
||||
palmas_usb->linkstat = PALMAS_USB_STATE_DISCONNECT;
|
||||
extcon_set_cable_state_(edev, EXTCON_USB, false);
|
||||
extcon_set_state_sync(edev, EXTCON_USB, false);
|
||||
dev_info(palmas_usb->dev, "USB cable is detached\n");
|
||||
} else {
|
||||
dev_dbg(palmas_usb->dev,
|
||||
@ -98,7 +98,7 @@ static irqreturn_t palmas_id_irq_handler(int irq, void *_palmas_usb)
|
||||
PALMAS_USB_ID_INT_LATCH_CLR,
|
||||
PALMAS_USB_ID_INT_EN_HI_CLR_ID_GND);
|
||||
palmas_usb->linkstat = PALMAS_USB_STATE_ID;
|
||||
extcon_set_cable_state_(edev, EXTCON_USB_HOST, true);
|
||||
extcon_set_state_sync(edev, EXTCON_USB_HOST, true);
|
||||
dev_info(palmas_usb->dev, "USB-HOST cable is attached\n");
|
||||
} else if ((set & PALMAS_USB_ID_INT_SRC_ID_FLOAT) &&
|
||||
(id_src & PALMAS_USB_ID_INT_SRC_ID_FLOAT)) {
|
||||
@ -106,17 +106,17 @@ static irqreturn_t palmas_id_irq_handler(int irq, void *_palmas_usb)
|
||||
PALMAS_USB_ID_INT_LATCH_CLR,
|
||||
PALMAS_USB_ID_INT_EN_HI_CLR_ID_FLOAT);
|
||||
palmas_usb->linkstat = PALMAS_USB_STATE_DISCONNECT;
|
||||
extcon_set_cable_state_(edev, EXTCON_USB_HOST, false);
|
||||
extcon_set_state_sync(edev, EXTCON_USB_HOST, false);
|
||||
dev_info(palmas_usb->dev, "USB-HOST cable is detached\n");
|
||||
} else if ((palmas_usb->linkstat == PALMAS_USB_STATE_ID) &&
|
||||
(!(set & PALMAS_USB_ID_INT_SRC_ID_GND))) {
|
||||
palmas_usb->linkstat = PALMAS_USB_STATE_DISCONNECT;
|
||||
extcon_set_cable_state_(edev, EXTCON_USB_HOST, false);
|
||||
extcon_set_state_sync(edev, EXTCON_USB_HOST, false);
|
||||
dev_info(palmas_usb->dev, "USB-HOST cable is detached\n");
|
||||
} else if ((palmas_usb->linkstat == PALMAS_USB_STATE_DISCONNECT) &&
|
||||
(id_src & PALMAS_USB_ID_INT_SRC_ID_GND)) {
|
||||
palmas_usb->linkstat = PALMAS_USB_STATE_ID;
|
||||
extcon_set_cable_state_(edev, EXTCON_USB_HOST, true);
|
||||
extcon_set_state_sync(edev, EXTCON_USB_HOST, true);
|
||||
dev_info(palmas_usb->dev, " USB-HOST cable is attached\n");
|
||||
}
|
||||
|
||||
@ -137,10 +137,10 @@ static void palmas_gpio_id_detect(struct work_struct *work)
|
||||
id = gpiod_get_value_cansleep(palmas_usb->id_gpiod);
|
||||
|
||||
if (id) {
|
||||
extcon_set_cable_state_(edev, EXTCON_USB_HOST, false);
|
||||
extcon_set_state_sync(edev, EXTCON_USB_HOST, false);
|
||||
dev_info(palmas_usb->dev, "USB-HOST cable is detached\n");
|
||||
} else {
|
||||
extcon_set_cable_state_(edev, EXTCON_USB_HOST, true);
|
||||
extcon_set_state_sync(edev, EXTCON_USB_HOST, true);
|
||||
dev_info(palmas_usb->dev, "USB-HOST cable is attached\n");
|
||||
}
|
||||
}
|
||||
|
170
drivers/extcon/extcon-qcom-spmi-misc.c
Normal file
170
drivers/extcon/extcon-qcom-spmi-misc.c
Normal file
@ -0,0 +1,170 @@
|
||||
/**
|
||||
* extcon-qcom-spmi-misc.c - Qualcomm USB extcon driver to support USB ID
|
||||
* detection based on extcon-usb-gpio.c.
|
||||
*
|
||||
* Copyright (C) 2016 Linaro, Ltd.
|
||||
* Stephen Boyd <stephen.boyd@linaro.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include <linux/extcon.h>
|
||||
#include <linux/init.h>
|
||||
#include <linux/interrupt.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/platform_device.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/workqueue.h>
|
||||
|
||||
#define USB_ID_DEBOUNCE_MS 5 /* ms */
|
||||
|
||||
struct qcom_usb_extcon_info {
|
||||
struct extcon_dev *edev;
|
||||
int irq;
|
||||
struct delayed_work wq_detcable;
|
||||
unsigned long debounce_jiffies;
|
||||
};
|
||||
|
||||
static const unsigned int qcom_usb_extcon_cable[] = {
|
||||
EXTCON_USB_HOST,
|
||||
EXTCON_NONE,
|
||||
};
|
||||
|
||||
static void qcom_usb_extcon_detect_cable(struct work_struct *work)
|
||||
{
|
||||
bool id;
|
||||
int ret;
|
||||
struct qcom_usb_extcon_info *info = container_of(to_delayed_work(work),
|
||||
struct qcom_usb_extcon_info,
|
||||
wq_detcable);
|
||||
|
||||
/* check ID and update cable state */
|
||||
ret = irq_get_irqchip_state(info->irq, IRQCHIP_STATE_LINE_LEVEL, &id);
|
||||
if (ret)
|
||||
return;
|
||||
|
||||
extcon_set_state(info->edev, EXTCON_USB_HOST, !id);
|
||||
}
|
||||
|
||||
static irqreturn_t qcom_usb_irq_handler(int irq, void *dev_id)
|
||||
{
|
||||
struct qcom_usb_extcon_info *info = dev_id;
|
||||
|
||||
queue_delayed_work(system_power_efficient_wq, &info->wq_detcable,
|
||||
info->debounce_jiffies);
|
||||
|
||||
return IRQ_HANDLED;
|
||||
}
|
||||
|
||||
static int qcom_usb_extcon_probe(struct platform_device *pdev)
|
||||
{
|
||||
struct device *dev = &pdev->dev;
|
||||
struct qcom_usb_extcon_info *info;
|
||||
int ret;
|
||||
|
||||
info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL);
|
||||
if (!info)
|
||||
return -ENOMEM;
|
||||
|
||||
info->edev = devm_extcon_dev_allocate(dev, qcom_usb_extcon_cable);
|
||||
if (IS_ERR(info->edev)) {
|
||||
dev_err(dev, "failed to allocate extcon device\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
ret = devm_extcon_dev_register(dev, info->edev);
|
||||
if (ret < 0) {
|
||||
dev_err(dev, "failed to register extcon device\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
info->debounce_jiffies = msecs_to_jiffies(USB_ID_DEBOUNCE_MS);
|
||||
INIT_DELAYED_WORK(&info->wq_detcable, qcom_usb_extcon_detect_cable);
|
||||
|
||||
info->irq = platform_get_irq_byname(pdev, "usb_id");
|
||||
if (info->irq < 0)
|
||||
return info->irq;
|
||||
|
||||
ret = devm_request_threaded_irq(dev, info->irq, NULL,
|
||||
qcom_usb_irq_handler,
|
||||
IRQF_TRIGGER_RISING |
|
||||
IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
|
||||
pdev->name, info);
|
||||
if (ret < 0) {
|
||||
dev_err(dev, "failed to request handler for ID IRQ\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
platform_set_drvdata(pdev, info);
|
||||
device_init_wakeup(dev, 1);
|
||||
|
||||
/* Perform initial detection */
|
||||
qcom_usb_extcon_detect_cable(&info->wq_detcable.work);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int qcom_usb_extcon_remove(struct platform_device *pdev)
|
||||
{
|
||||
struct qcom_usb_extcon_info *info = platform_get_drvdata(pdev);
|
||||
|
||||
cancel_delayed_work_sync(&info->wq_detcable);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_PM_SLEEP
|
||||
static int qcom_usb_extcon_suspend(struct device *dev)
|
||||
{
|
||||
struct qcom_usb_extcon_info *info = dev_get_drvdata(dev);
|
||||
int ret = 0;
|
||||
|
||||
if (device_may_wakeup(dev))
|
||||
ret = enable_irq_wake(info->irq);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int qcom_usb_extcon_resume(struct device *dev)
|
||||
{
|
||||
struct qcom_usb_extcon_info *info = dev_get_drvdata(dev);
|
||||
int ret = 0;
|
||||
|
||||
if (device_may_wakeup(dev))
|
||||
ret = disable_irq_wake(info->irq);
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
static SIMPLE_DEV_PM_OPS(qcom_usb_extcon_pm_ops,
|
||||
qcom_usb_extcon_suspend, qcom_usb_extcon_resume);
|
||||
|
||||
static const struct of_device_id qcom_usb_extcon_dt_match[] = {
|
||||
{ .compatible = "qcom,pm8941-misc", },
|
||||
{ }
|
||||
};
|
||||
MODULE_DEVICE_TABLE(of, qcom_usb_extcon_dt_match);
|
||||
|
||||
static struct platform_driver qcom_usb_extcon_driver = {
|
||||
.probe = qcom_usb_extcon_probe,
|
||||
.remove = qcom_usb_extcon_remove,
|
||||
.driver = {
|
||||
.name = "extcon-pm8941-misc",
|
||||
.pm = &qcom_usb_extcon_pm_ops,
|
||||
.of_match_table = qcom_usb_extcon_dt_match,
|
||||
},
|
||||
};
|
||||
module_platform_driver(qcom_usb_extcon_driver);
|
||||
|
||||
MODULE_DESCRIPTION("QCOM USB ID extcon driver");
|
||||
MODULE_AUTHOR("Stephen Boyd <stephen.boyd@linaro.org>");
|
||||
MODULE_LICENSE("GPL v2");
|
@ -398,9 +398,9 @@ static int rt8973a_muic_cable_handler(struct rt8973a_muic_info *info,
|
||||
return ret;
|
||||
|
||||
/* Change the state of external accessory */
|
||||
extcon_set_cable_state_(info->edev, id, attached);
|
||||
extcon_set_state_sync(info->edev, id, attached);
|
||||
if (id == EXTCON_USB)
|
||||
extcon_set_cable_state_(info->edev, EXTCON_CHG_USB_SDP,
|
||||
extcon_set_state_sync(info->edev, EXTCON_CHG_USB_SDP,
|
||||
attached);
|
||||
|
||||
return 0;
|
||||
|
@ -411,9 +411,9 @@ static int sm5502_muic_cable_handler(struct sm5502_muic_info *info,
|
||||
return ret;
|
||||
|
||||
/* Change the state of external accessory */
|
||||
extcon_set_cable_state_(info->edev, id, attached);
|
||||
extcon_set_state_sync(info->edev, id, attached);
|
||||
if (id == EXTCON_USB)
|
||||
extcon_set_cable_state_(info->edev, EXTCON_CHG_USB_SDP,
|
||||
extcon_set_state_sync(info->edev, EXTCON_CHG_USB_SDP,
|
||||
attached);
|
||||
|
||||
return 0;
|
||||
|
@ -63,16 +63,16 @@ static void usb_extcon_detect_cable(struct work_struct *work)
|
||||
* As we don't have event for USB peripheral cable attached,
|
||||
* we simulate USB peripheral attach here.
|
||||
*/
|
||||
extcon_set_cable_state_(info->edev, EXTCON_USB_HOST, false);
|
||||
extcon_set_cable_state_(info->edev, EXTCON_USB, true);
|
||||
extcon_set_state_sync(info->edev, EXTCON_USB_HOST, false);
|
||||
extcon_set_state_sync(info->edev, EXTCON_USB, true);
|
||||
} else {
|
||||
/*
|
||||
* ID = 0 means USB HOST cable attached.
|
||||
* As we don't have event for USB peripheral cable detached,
|
||||
* we simulate USB peripheral detach here.
|
||||
*/
|
||||
extcon_set_cable_state_(info->edev, EXTCON_USB, false);
|
||||
extcon_set_cable_state_(info->edev, EXTCON_USB_HOST, true);
|
||||
extcon_set_state_sync(info->edev, EXTCON_USB, false);
|
||||
extcon_set_state_sync(info->edev, EXTCON_USB_HOST, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -38,43 +38,159 @@
|
||||
#define SUPPORTED_CABLE_MAX 32
|
||||
#define CABLE_NAME_MAX 30
|
||||
|
||||
static const char *extcon_name[] = {
|
||||
[EXTCON_NONE] = "NONE",
|
||||
struct __extcon_info {
|
||||
unsigned int type;
|
||||
unsigned int id;
|
||||
const char *name;
|
||||
|
||||
} extcon_info[] = {
|
||||
[EXTCON_NONE] = {
|
||||
.type = EXTCON_TYPE_MISC,
|
||||
.id = EXTCON_NONE,
|
||||
.name = "NONE",
|
||||
},
|
||||
|
||||
/* USB external connector */
|
||||
[EXTCON_USB] = "USB",
|
||||
[EXTCON_USB_HOST] = "USB-HOST",
|
||||
[EXTCON_USB] = {
|
||||
.type = EXTCON_TYPE_USB,
|
||||
.id = EXTCON_USB,
|
||||
.name = "USB",
|
||||
},
|
||||
[EXTCON_USB_HOST] = {
|
||||
.type = EXTCON_TYPE_USB,
|
||||
.id = EXTCON_USB_HOST,
|
||||
.name = "USB_HOST",
|
||||
},
|
||||
|
||||
/* Charging external connector */
|
||||
[EXTCON_CHG_USB_SDP] = "SDP",
|
||||
[EXTCON_CHG_USB_DCP] = "DCP",
|
||||
[EXTCON_CHG_USB_CDP] = "CDP",
|
||||
[EXTCON_CHG_USB_ACA] = "ACA",
|
||||
[EXTCON_CHG_USB_FAST] = "FAST-CHARGER",
|
||||
[EXTCON_CHG_USB_SLOW] = "SLOW-CHARGER",
|
||||
[EXTCON_CHG_USB_SDP] = {
|
||||
.type = EXTCON_TYPE_CHG | EXTCON_TYPE_USB,
|
||||
.id = EXTCON_CHG_USB_SDP,
|
||||
.name = "SDP",
|
||||
},
|
||||
[EXTCON_CHG_USB_DCP] = {
|
||||
.type = EXTCON_TYPE_CHG | EXTCON_TYPE_USB,
|
||||
.id = EXTCON_CHG_USB_DCP,
|
||||
.name = "DCP",
|
||||
},
|
||||
[EXTCON_CHG_USB_CDP] = {
|
||||
.type = EXTCON_TYPE_CHG | EXTCON_TYPE_USB,
|
||||
.id = EXTCON_CHG_USB_CDP,
|
||||
.name = "CDP",
|
||||
},
|
||||
[EXTCON_CHG_USB_ACA] = {
|
||||
.type = EXTCON_TYPE_CHG | EXTCON_TYPE_USB,
|
||||
.id = EXTCON_CHG_USB_ACA,
|
||||
.name = "ACA",
|
||||
},
|
||||
[EXTCON_CHG_USB_FAST] = {
|
||||
.type = EXTCON_TYPE_CHG | EXTCON_TYPE_USB,
|
||||
.id = EXTCON_CHG_USB_FAST,
|
||||
.name = "FAST-CHARGER",
|
||||
},
|
||||
[EXTCON_CHG_USB_SLOW] = {
|
||||
.type = EXTCON_TYPE_CHG | EXTCON_TYPE_USB,
|
||||
.id = EXTCON_CHG_USB_SLOW,
|
||||
.name = "SLOW-CHARGER",
|
||||
},
|
||||
[EXTCON_CHG_WPT] = {
|
||||
.type = EXTCON_TYPE_CHG,
|
||||
.id = EXTCON_CHG_WPT,
|
||||
.name = "WPT",
|
||||
},
|
||||
|
||||
/* Jack external connector */
|
||||
[EXTCON_JACK_MICROPHONE] = "MICROPHONE",
|
||||
[EXTCON_JACK_HEADPHONE] = "HEADPHONE",
|
||||
[EXTCON_JACK_LINE_IN] = "LINE-IN",
|
||||
[EXTCON_JACK_LINE_OUT] = "LINE-OUT",
|
||||
[EXTCON_JACK_VIDEO_IN] = "VIDEO-IN",
|
||||
[EXTCON_JACK_VIDEO_OUT] = "VIDEO-OUT",
|
||||
[EXTCON_JACK_SPDIF_IN] = "SPDIF-IN",
|
||||
[EXTCON_JACK_SPDIF_OUT] = "SPDIF-OUT",
|
||||
[EXTCON_JACK_MICROPHONE] = {
|
||||
.type = EXTCON_TYPE_JACK,
|
||||
.id = EXTCON_JACK_MICROPHONE,
|
||||
.name = "MICROPHONE",
|
||||
},
|
||||
[EXTCON_JACK_HEADPHONE] = {
|
||||
.type = EXTCON_TYPE_JACK,
|
||||
.id = EXTCON_JACK_HEADPHONE,
|
||||
.name = "HEADPHONE",
|
||||
},
|
||||
[EXTCON_JACK_LINE_IN] = {
|
||||
.type = EXTCON_TYPE_JACK,
|
||||
.id = EXTCON_JACK_LINE_IN,
|
||||
.name = "LINE-IN",
|
||||
},
|
||||
[EXTCON_JACK_LINE_OUT] = {
|
||||
.type = EXTCON_TYPE_JACK,
|
||||
.id = EXTCON_JACK_LINE_OUT,
|
||||
.name = "LINE-OUT",
|
||||
},
|
||||
[EXTCON_JACK_VIDEO_IN] = {
|
||||
.type = EXTCON_TYPE_JACK,
|
||||
.id = EXTCON_JACK_VIDEO_IN,
|
||||
.name = "VIDEO-IN",
|
||||
},
|
||||
[EXTCON_JACK_VIDEO_OUT] = {
|
||||
.type = EXTCON_TYPE_JACK,
|
||||
.id = EXTCON_JACK_VIDEO_OUT,
|
||||
.name = "VIDEO-OUT",
|
||||
},
|
||||
[EXTCON_JACK_SPDIF_IN] = {
|
||||
.type = EXTCON_TYPE_JACK,
|
||||
.id = EXTCON_JACK_SPDIF_IN,
|
||||
.name = "SPDIF-IN",
|
||||
},
|
||||
[EXTCON_JACK_SPDIF_OUT] = {
|
||||
.type = EXTCON_TYPE_JACK,
|
||||
.id = EXTCON_JACK_SPDIF_OUT,
|
||||
.name = "SPDIF-OUT",
|
||||
},
|
||||
|
||||
/* Display external connector */
|
||||
[EXTCON_DISP_HDMI] = "HDMI",
|
||||
[EXTCON_DISP_MHL] = "MHL",
|
||||
[EXTCON_DISP_DVI] = "DVI",
|
||||
[EXTCON_DISP_VGA] = "VGA",
|
||||
[EXTCON_DISP_HDMI] = {
|
||||
.type = EXTCON_TYPE_DISP,
|
||||
.id = EXTCON_DISP_HDMI,
|
||||
.name = "HDMI",
|
||||
},
|
||||
[EXTCON_DISP_MHL] = {
|
||||
.type = EXTCON_TYPE_DISP,
|
||||
.id = EXTCON_DISP_MHL,
|
||||
.name = "MHL",
|
||||
},
|
||||
[EXTCON_DISP_DVI] = {
|
||||
.type = EXTCON_TYPE_DISP,
|
||||
.id = EXTCON_DISP_DVI,
|
||||
.name = "DVI",
|
||||
},
|
||||
[EXTCON_DISP_VGA] = {
|
||||
.type = EXTCON_TYPE_DISP,
|
||||
.id = EXTCON_DISP_VGA,
|
||||
.name = "VGA",
|
||||
},
|
||||
[EXTCON_DISP_DP] = {
|
||||
.type = EXTCON_TYPE_DISP | EXTCON_TYPE_USB,
|
||||
.id = EXTCON_DISP_DP,
|
||||
.name = "DP",
|
||||
},
|
||||
[EXTCON_DISP_HMD] = {
|
||||
.type = EXTCON_TYPE_DISP | EXTCON_TYPE_USB,
|
||||
.id = EXTCON_DISP_HMD,
|
||||
.name = "HMD",
|
||||
},
|
||||
|
||||
/* Miscellaneous external connector */
|
||||
[EXTCON_DOCK] = "DOCK",
|
||||
[EXTCON_JIG] = "JIG",
|
||||
[EXTCON_MECHANICAL] = "MECHANICAL",
|
||||
[EXTCON_DOCK] = {
|
||||
.type = EXTCON_TYPE_MISC,
|
||||
.id = EXTCON_DOCK,
|
||||
.name = "DOCK",
|
||||
},
|
||||
[EXTCON_JIG] = {
|
||||
.type = EXTCON_TYPE_MISC,
|
||||
.id = EXTCON_JIG,
|
||||
.name = "JIG",
|
||||
},
|
||||
[EXTCON_MECHANICAL] = {
|
||||
.type = EXTCON_TYPE_MISC,
|
||||
.id = EXTCON_MECHANICAL,
|
||||
.name = "MECHANICAL",
|
||||
},
|
||||
|
||||
NULL,
|
||||
{ /* sentinel */ }
|
||||
};
|
||||
|
||||
/**
|
||||
@ -95,6 +211,16 @@ struct extcon_cable {
|
||||
struct device_attribute attr_state;
|
||||
|
||||
struct attribute *attrs[3]; /* to be fed to attr_g.attrs */
|
||||
|
||||
union extcon_property_value usb_propval[EXTCON_PROP_USB_CNT];
|
||||
union extcon_property_value chg_propval[EXTCON_PROP_CHG_CNT];
|
||||
union extcon_property_value jack_propval[EXTCON_PROP_JACK_CNT];
|
||||
union extcon_property_value disp_propval[EXTCON_PROP_DISP_CNT];
|
||||
|
||||
unsigned long usb_bits[BITS_TO_LONGS(EXTCON_PROP_USB_CNT)];
|
||||
unsigned long chg_bits[BITS_TO_LONGS(EXTCON_PROP_CHG_CNT)];
|
||||
unsigned long jack_bits[BITS_TO_LONGS(EXTCON_PROP_JACK_CNT)];
|
||||
unsigned long disp_bits[BITS_TO_LONGS(EXTCON_PROP_DISP_CNT)];
|
||||
};
|
||||
|
||||
static struct class *extcon_class;
|
||||
@ -147,14 +273,93 @@ static int find_cable_index_by_id(struct extcon_dev *edev, const unsigned int id
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
static bool is_extcon_changed(u32 prev, u32 new, int idx, bool *attached)
|
||||
static int get_extcon_type(unsigned int prop)
|
||||
{
|
||||
if (((prev >> idx) & 0x1) != ((new >> idx) & 0x1)) {
|
||||
*attached = ((new >> idx) & 0x1) ? true : false;
|
||||
return true;
|
||||
switch (prop) {
|
||||
case EXTCON_PROP_USB_MIN ... EXTCON_PROP_USB_MAX:
|
||||
return EXTCON_TYPE_USB;
|
||||
case EXTCON_PROP_CHG_MIN ... EXTCON_PROP_CHG_MAX:
|
||||
return EXTCON_TYPE_CHG;
|
||||
case EXTCON_PROP_JACK_MIN ... EXTCON_PROP_JACK_MAX:
|
||||
return EXTCON_TYPE_JACK;
|
||||
case EXTCON_PROP_DISP_MIN ... EXTCON_PROP_DISP_MAX:
|
||||
return EXTCON_TYPE_DISP;
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
|
||||
static bool is_extcon_attached(struct extcon_dev *edev, unsigned int index)
|
||||
{
|
||||
return !!(edev->state & BIT(index));
|
||||
}
|
||||
|
||||
static bool is_extcon_changed(struct extcon_dev *edev, int index,
|
||||
bool new_state)
|
||||
{
|
||||
int state = !!(edev->state & BIT(index));
|
||||
return (state != new_state);
|
||||
}
|
||||
|
||||
static bool is_extcon_property_supported(unsigned int id, unsigned int prop)
|
||||
{
|
||||
int type;
|
||||
|
||||
/* Check whether the property is supported or not. */
|
||||
type = get_extcon_type(prop);
|
||||
if (type < 0)
|
||||
return false;
|
||||
|
||||
/* Check whether a specific extcon id supports the property or not. */
|
||||
return !!(extcon_info[id].type & type);
|
||||
}
|
||||
|
||||
static int is_extcon_property_capability(struct extcon_dev *edev,
|
||||
unsigned int id, int index,unsigned int prop)
|
||||
{
|
||||
struct extcon_cable *cable;
|
||||
int type, ret;
|
||||
|
||||
/* Check whether the property is supported or not. */
|
||||
type = get_extcon_type(prop);
|
||||
if (type < 0)
|
||||
return type;
|
||||
|
||||
cable = &edev->cables[index];
|
||||
|
||||
switch (type) {
|
||||
case EXTCON_TYPE_USB:
|
||||
ret = test_bit(prop - EXTCON_PROP_USB_MIN, cable->usb_bits);
|
||||
break;
|
||||
case EXTCON_TYPE_CHG:
|
||||
ret = test_bit(prop - EXTCON_PROP_CHG_MIN, cable->chg_bits);
|
||||
break;
|
||||
case EXTCON_TYPE_JACK:
|
||||
ret = test_bit(prop - EXTCON_PROP_JACK_MIN, cable->jack_bits);
|
||||
break;
|
||||
case EXTCON_TYPE_DISP:
|
||||
ret = test_bit(prop - EXTCON_PROP_DISP_MIN, cable->disp_bits);
|
||||
break;
|
||||
default:
|
||||
ret = -EINVAL;
|
||||
}
|
||||
|
||||
return false;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void init_property(struct extcon_dev *edev, unsigned int id, int index)
|
||||
{
|
||||
unsigned int type = extcon_info[id].type;
|
||||
struct extcon_cable *cable = &edev->cables[index];
|
||||
|
||||
if (EXTCON_TYPE_USB & type)
|
||||
memset(cable->usb_propval, 0, sizeof(cable->usb_propval));
|
||||
if (EXTCON_TYPE_CHG & type)
|
||||
memset(cable->chg_propval, 0, sizeof(cable->chg_propval));
|
||||
if (EXTCON_TYPE_JACK & type)
|
||||
memset(cable->jack_propval, 0, sizeof(cable->jack_propval));
|
||||
if (EXTCON_TYPE_DISP & type)
|
||||
memset(cable->disp_propval, 0, sizeof(cable->disp_propval));
|
||||
}
|
||||
|
||||
static ssize_t state_show(struct device *dev, struct device_attribute *attr,
|
||||
@ -168,32 +373,13 @@ static ssize_t state_show(struct device *dev, struct device_attribute *attr,
|
||||
|
||||
for (i = 0; i < edev->max_supported; i++) {
|
||||
count += sprintf(buf + count, "%s=%d\n",
|
||||
extcon_name[edev->supported_cable[i]],
|
||||
extcon_info[edev->supported_cable[i]].name,
|
||||
!!(edev->state & (1 << i)));
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
static ssize_t state_store(struct device *dev, struct device_attribute *attr,
|
||||
const char *buf, size_t count)
|
||||
{
|
||||
u32 state;
|
||||
ssize_t ret = 0;
|
||||
struct extcon_dev *edev = dev_get_drvdata(dev);
|
||||
|
||||
ret = sscanf(buf, "0x%x", &state);
|
||||
if (ret == 0)
|
||||
ret = -EINVAL;
|
||||
else
|
||||
ret = extcon_set_state(edev, state);
|
||||
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
return count;
|
||||
}
|
||||
static DEVICE_ATTR_RW(state);
|
||||
static DEVICE_ATTR_RO(state);
|
||||
|
||||
static ssize_t name_show(struct device *dev, struct device_attribute *attr,
|
||||
char *buf)
|
||||
@ -212,7 +398,7 @@ static ssize_t cable_name_show(struct device *dev,
|
||||
int i = cable->cable_index;
|
||||
|
||||
return sprintf(buf, "%s\n",
|
||||
extcon_name[cable->edev->supported_cable[i]]);
|
||||
extcon_info[cable->edev->supported_cable[i]].name);
|
||||
}
|
||||
|
||||
static ssize_t cable_state_show(struct device *dev,
|
||||
@ -224,26 +410,17 @@ static ssize_t cable_state_show(struct device *dev,
|
||||
int i = cable->cable_index;
|
||||
|
||||
return sprintf(buf, "%d\n",
|
||||
extcon_get_cable_state_(cable->edev,
|
||||
cable->edev->supported_cable[i]));
|
||||
extcon_get_state(cable->edev, cable->edev->supported_cable[i]));
|
||||
}
|
||||
|
||||
/**
|
||||
* extcon_update_state() - Update the cable attach states of the extcon device
|
||||
* only for the masked bits.
|
||||
* @edev: the extcon device
|
||||
* @mask: the bit mask to designate updated bits.
|
||||
* @state: new cable attach status for @edev
|
||||
* extcon_sync() - Synchronize the states for both the attached/detached
|
||||
* @edev: the extcon device that has the cable.
|
||||
*
|
||||
* Changing the state sends uevent with environment variable containing
|
||||
* the name of extcon device (envp[0]) and the state output (envp[1]).
|
||||
* Tizen uses this format for extcon device to get events from ports.
|
||||
* Android uses this format as well.
|
||||
*
|
||||
* Note that the notifier provides which bits are changed in the state
|
||||
* variable with the val parameter (second) to the callback.
|
||||
* This function send a notification to synchronize the all states of a
|
||||
* specific external connector
|
||||
*/
|
||||
int extcon_update_state(struct extcon_dev *edev, u32 mask, u32 state)
|
||||
int extcon_sync(struct extcon_dev *edev, unsigned int id)
|
||||
{
|
||||
char name_buf[120];
|
||||
char state_buf[120];
|
||||
@ -252,100 +429,8 @@ int extcon_update_state(struct extcon_dev *edev, u32 mask, u32 state)
|
||||
int env_offset = 0;
|
||||
int length;
|
||||
int index;
|
||||
int state;
|
||||
unsigned long flags;
|
||||
bool attached;
|
||||
|
||||
if (!edev)
|
||||
return -EINVAL;
|
||||
|
||||
spin_lock_irqsave(&edev->lock, flags);
|
||||
|
||||
if (edev->state != ((edev->state & ~mask) | (state & mask))) {
|
||||
u32 old_state;
|
||||
|
||||
if (check_mutually_exclusive(edev, (edev->state & ~mask) |
|
||||
(state & mask))) {
|
||||
spin_unlock_irqrestore(&edev->lock, flags);
|
||||
return -EPERM;
|
||||
}
|
||||
|
||||
old_state = edev->state;
|
||||
edev->state &= ~mask;
|
||||
edev->state |= state & mask;
|
||||
|
||||
for (index = 0; index < edev->max_supported; index++) {
|
||||
if (is_extcon_changed(old_state, edev->state, index,
|
||||
&attached))
|
||||
raw_notifier_call_chain(&edev->nh[index],
|
||||
attached, edev);
|
||||
}
|
||||
|
||||
/* This could be in interrupt handler */
|
||||
prop_buf = (char *)get_zeroed_page(GFP_ATOMIC);
|
||||
if (prop_buf) {
|
||||
length = name_show(&edev->dev, NULL, prop_buf);
|
||||
if (length > 0) {
|
||||
if (prop_buf[length - 1] == '\n')
|
||||
prop_buf[length - 1] = 0;
|
||||
snprintf(name_buf, sizeof(name_buf),
|
||||
"NAME=%s", prop_buf);
|
||||
envp[env_offset++] = name_buf;
|
||||
}
|
||||
length = state_show(&edev->dev, NULL, prop_buf);
|
||||
if (length > 0) {
|
||||
if (prop_buf[length - 1] == '\n')
|
||||
prop_buf[length - 1] = 0;
|
||||
snprintf(state_buf, sizeof(state_buf),
|
||||
"STATE=%s", prop_buf);
|
||||
envp[env_offset++] = state_buf;
|
||||
}
|
||||
envp[env_offset] = NULL;
|
||||
/* Unlock early before uevent */
|
||||
spin_unlock_irqrestore(&edev->lock, flags);
|
||||
|
||||
kobject_uevent_env(&edev->dev.kobj, KOBJ_CHANGE, envp);
|
||||
free_page((unsigned long)prop_buf);
|
||||
} else {
|
||||
/* Unlock early before uevent */
|
||||
spin_unlock_irqrestore(&edev->lock, flags);
|
||||
|
||||
dev_err(&edev->dev, "out of memory in extcon_set_state\n");
|
||||
kobject_uevent(&edev->dev.kobj, KOBJ_CHANGE);
|
||||
}
|
||||
} else {
|
||||
/* No changes */
|
||||
spin_unlock_irqrestore(&edev->lock, flags);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(extcon_update_state);
|
||||
|
||||
/**
|
||||
* extcon_set_state() - Set the cable attach states of the extcon device.
|
||||
* @edev: the extcon device
|
||||
* @state: new cable attach status for @edev
|
||||
*
|
||||
* Note that notifier provides which bits are changed in the state
|
||||
* variable with the val parameter (second) to the callback.
|
||||
*/
|
||||
int extcon_set_state(struct extcon_dev *edev, u32 state)
|
||||
{
|
||||
if (!edev)
|
||||
return -EINVAL;
|
||||
|
||||
return extcon_update_state(edev, 0xffffffff, state);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(extcon_set_state);
|
||||
|
||||
/**
|
||||
* extcon_get_cable_state_() - Get the status of a specific cable.
|
||||
* @edev: the extcon device that has the cable.
|
||||
* @id: the unique id of each external connector in extcon enumeration.
|
||||
*/
|
||||
int extcon_get_cable_state_(struct extcon_dev *edev, const unsigned int id)
|
||||
{
|
||||
int index;
|
||||
|
||||
if (!edev)
|
||||
return -EINVAL;
|
||||
@ -354,26 +439,92 @@ int extcon_get_cable_state_(struct extcon_dev *edev, const unsigned int id)
|
||||
if (index < 0)
|
||||
return index;
|
||||
|
||||
if (edev->max_supported && edev->max_supported <= index)
|
||||
return -EINVAL;
|
||||
spin_lock_irqsave(&edev->lock, flags);
|
||||
|
||||
return !!(edev->state & (1 << index));
|
||||
state = !!(edev->state & BIT(index));
|
||||
raw_notifier_call_chain(&edev->nh[index], state, edev);
|
||||
|
||||
/* This could be in interrupt handler */
|
||||
prop_buf = (char *)get_zeroed_page(GFP_ATOMIC);
|
||||
if (!prop_buf) {
|
||||
/* Unlock early before uevent */
|
||||
spin_unlock_irqrestore(&edev->lock, flags);
|
||||
|
||||
dev_err(&edev->dev, "out of memory in extcon_set_state\n");
|
||||
kobject_uevent(&edev->dev.kobj, KOBJ_CHANGE);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
length = name_show(&edev->dev, NULL, prop_buf);
|
||||
if (length > 0) {
|
||||
if (prop_buf[length - 1] == '\n')
|
||||
prop_buf[length - 1] = 0;
|
||||
snprintf(name_buf, sizeof(name_buf), "NAME=%s", prop_buf);
|
||||
envp[env_offset++] = name_buf;
|
||||
}
|
||||
|
||||
length = state_show(&edev->dev, NULL, prop_buf);
|
||||
if (length > 0) {
|
||||
if (prop_buf[length - 1] == '\n')
|
||||
prop_buf[length - 1] = 0;
|
||||
snprintf(state_buf, sizeof(state_buf), "STATE=%s", prop_buf);
|
||||
envp[env_offset++] = state_buf;
|
||||
}
|
||||
envp[env_offset] = NULL;
|
||||
|
||||
/* Unlock early before uevent */
|
||||
spin_unlock_irqrestore(&edev->lock, flags);
|
||||
kobject_uevent_env(&edev->dev.kobj, KOBJ_CHANGE, envp);
|
||||
free_page((unsigned long)prop_buf);
|
||||
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(extcon_get_cable_state_);
|
||||
EXPORT_SYMBOL_GPL(extcon_sync);
|
||||
|
||||
/**
|
||||
* extcon_set_cable_state_() - Set the status of a specific cable.
|
||||
* extcon_get_state() - Get the state of a external connector.
|
||||
* @edev: the extcon device that has the cable.
|
||||
* @id: the unique id of each external connector in extcon enumeration.
|
||||
*/
|
||||
int extcon_get_state(struct extcon_dev *edev, const unsigned int id)
|
||||
{
|
||||
int index, state;
|
||||
unsigned long flags;
|
||||
|
||||
if (!edev)
|
||||
return -EINVAL;
|
||||
|
||||
index = find_cable_index_by_id(edev, id);
|
||||
if (index < 0)
|
||||
return index;
|
||||
|
||||
spin_lock_irqsave(&edev->lock, flags);
|
||||
state = is_extcon_attached(edev, index);
|
||||
spin_unlock_irqrestore(&edev->lock, flags);
|
||||
|
||||
return state;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(extcon_get_state);
|
||||
|
||||
/**
|
||||
* extcon_set_state() - Set the state of a external connector.
|
||||
* without a notification.
|
||||
* @edev: the extcon device that has the cable.
|
||||
* @id: the unique id of each external connector
|
||||
* in extcon enumeration.
|
||||
* @state: the new cable status. The default semantics is
|
||||
* true: attached / false: detached.
|
||||
*
|
||||
* This function only set the state of a external connector without
|
||||
* a notification. To synchronize the data of a external connector,
|
||||
* use extcon_set_state_sync() and extcon_sync().
|
||||
*/
|
||||
int extcon_set_cable_state_(struct extcon_dev *edev, unsigned int id,
|
||||
int extcon_set_state(struct extcon_dev *edev, unsigned int id,
|
||||
bool cable_state)
|
||||
{
|
||||
u32 state;
|
||||
int index;
|
||||
unsigned long flags;
|
||||
int index, ret = 0;
|
||||
|
||||
if (!edev)
|
||||
return -EINVAL;
|
||||
@ -382,13 +533,338 @@ int extcon_set_cable_state_(struct extcon_dev *edev, unsigned int id,
|
||||
if (index < 0)
|
||||
return index;
|
||||
|
||||
if (edev->max_supported && edev->max_supported <= index)
|
||||
spin_lock_irqsave(&edev->lock, flags);
|
||||
|
||||
/* Check whether the external connector's state is changed. */
|
||||
if (!is_extcon_changed(edev, index, cable_state))
|
||||
goto out;
|
||||
|
||||
if (check_mutually_exclusive(edev,
|
||||
(edev->state & ~BIT(index)) | (cable_state & BIT(index)))) {
|
||||
ret = -EPERM;
|
||||
goto out;
|
||||
}
|
||||
|
||||
/*
|
||||
* Initialize the value of extcon property before setting
|
||||
* the detached state for an external connector.
|
||||
*/
|
||||
if (!cable_state)
|
||||
init_property(edev, id, index);
|
||||
|
||||
/* Update the state for a external connector. */
|
||||
if (cable_state)
|
||||
edev->state |= BIT(index);
|
||||
else
|
||||
edev->state &= ~(BIT(index));
|
||||
out:
|
||||
spin_unlock_irqrestore(&edev->lock, flags);
|
||||
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(extcon_set_state);
|
||||
|
||||
/**
|
||||
* extcon_set_state_sync() - Set the state of a external connector
|
||||
* with a notification.
|
||||
* @edev: the extcon device that has the cable.
|
||||
* @id: the unique id of each external connector
|
||||
* in extcon enumeration.
|
||||
* @state: the new cable status. The default semantics is
|
||||
* true: attached / false: detached.
|
||||
*
|
||||
* This function set the state of external connector and synchronize the data
|
||||
* by usning a notification.
|
||||
*/
|
||||
int extcon_set_state_sync(struct extcon_dev *edev, unsigned int id,
|
||||
bool cable_state)
|
||||
{
|
||||
int ret, index;
|
||||
unsigned long flags;
|
||||
|
||||
index = find_cable_index_by_id(edev, id);
|
||||
if (index < 0)
|
||||
return index;
|
||||
|
||||
/* Check whether the external connector's state is changed. */
|
||||
spin_lock_irqsave(&edev->lock, flags);
|
||||
ret = is_extcon_changed(edev, index, cable_state);
|
||||
spin_unlock_irqrestore(&edev->lock, flags);
|
||||
if (!ret)
|
||||
return 0;
|
||||
|
||||
ret = extcon_set_state(edev, id, cable_state);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
return extcon_sync(edev, id);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(extcon_set_state_sync);
|
||||
|
||||
/**
|
||||
* extcon_get_property() - Get the property value of a specific cable.
|
||||
* @edev: the extcon device that has the cable.
|
||||
* @id: the unique id of each external connector
|
||||
* in extcon enumeration.
|
||||
* @prop: the property id among enum extcon_property.
|
||||
* @prop_val: the pointer which store the value of property.
|
||||
*
|
||||
* When getting the property value of external connector, the external connector
|
||||
* should be attached. If detached state, function just return 0 without
|
||||
* property value. Also, the each property should be included in the list of
|
||||
* supported properties according to the type of external connectors.
|
||||
*
|
||||
* Returns 0 if success or error number if fail
|
||||
*/
|
||||
int extcon_get_property(struct extcon_dev *edev, unsigned int id,
|
||||
unsigned int prop,
|
||||
union extcon_property_value *prop_val)
|
||||
{
|
||||
struct extcon_cable *cable;
|
||||
unsigned long flags;
|
||||
int index, ret = 0;
|
||||
|
||||
*prop_val = (union extcon_property_value)(0);
|
||||
|
||||
if (!edev)
|
||||
return -EINVAL;
|
||||
|
||||
state = cable_state ? (1 << index) : 0;
|
||||
return extcon_update_state(edev, 1 << index, state);
|
||||
/* Check whether the property is supported or not */
|
||||
if (!is_extcon_property_supported(id, prop))
|
||||
return -EINVAL;
|
||||
|
||||
/* Find the cable index of external connector by using id */
|
||||
index = find_cable_index_by_id(edev, id);
|
||||
if (index < 0)
|
||||
return index;
|
||||
|
||||
spin_lock_irqsave(&edev->lock, flags);
|
||||
|
||||
/* Check whether the property is available or not. */
|
||||
if (!is_extcon_property_capability(edev, id, index, prop)) {
|
||||
spin_unlock_irqrestore(&edev->lock, flags);
|
||||
return -EPERM;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check whether the external connector is attached.
|
||||
* If external connector is detached, the user can not
|
||||
* get the property value.
|
||||
*/
|
||||
if (!is_extcon_attached(edev, index)) {
|
||||
spin_unlock_irqrestore(&edev->lock, flags);
|
||||
return 0;
|
||||
}
|
||||
|
||||
cable = &edev->cables[index];
|
||||
|
||||
/* Get the property value according to extcon type */
|
||||
switch (prop) {
|
||||
case EXTCON_PROP_USB_MIN ... EXTCON_PROP_USB_MAX:
|
||||
*prop_val = cable->usb_propval[prop - EXTCON_PROP_USB_MIN];
|
||||
break;
|
||||
case EXTCON_PROP_CHG_MIN ... EXTCON_PROP_CHG_MAX:
|
||||
*prop_val = cable->chg_propval[prop - EXTCON_PROP_CHG_MIN];
|
||||
break;
|
||||
case EXTCON_PROP_JACK_MIN ... EXTCON_PROP_JACK_MAX:
|
||||
*prop_val = cable->jack_propval[prop - EXTCON_PROP_JACK_MIN];
|
||||
break;
|
||||
case EXTCON_PROP_DISP_MIN ... EXTCON_PROP_DISP_MAX:
|
||||
*prop_val = cable->disp_propval[prop - EXTCON_PROP_DISP_MIN];
|
||||
break;
|
||||
default:
|
||||
ret = -EINVAL;
|
||||
break;
|
||||
}
|
||||
|
||||
spin_unlock_irqrestore(&edev->lock, flags);
|
||||
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(extcon_set_cable_state_);
|
||||
EXPORT_SYMBOL_GPL(extcon_get_property);
|
||||
|
||||
/**
|
||||
* extcon_set_property() - Set the property value of a specific cable.
|
||||
* @edev: the extcon device that has the cable.
|
||||
* @id: the unique id of each external connector
|
||||
* in extcon enumeration.
|
||||
* @prop: the property id among enum extcon_property.
|
||||
* @prop_val: the pointer including the new value of property.
|
||||
*
|
||||
* The each property should be included in the list of supported properties
|
||||
* according to the type of external connectors.
|
||||
*
|
||||
* Returns 0 if success or error number if fail
|
||||
*/
|
||||
int extcon_set_property(struct extcon_dev *edev, unsigned int id,
|
||||
unsigned int prop,
|
||||
union extcon_property_value prop_val)
|
||||
{
|
||||
struct extcon_cable *cable;
|
||||
unsigned long flags;
|
||||
int index, ret = 0;
|
||||
|
||||
if (!edev)
|
||||
return -EINVAL;
|
||||
|
||||
/* Check whether the property is supported or not */
|
||||
if (!is_extcon_property_supported(id, prop))
|
||||
return -EINVAL;
|
||||
|
||||
/* Find the cable index of external connector by using id */
|
||||
index = find_cable_index_by_id(edev, id);
|
||||
if (index < 0)
|
||||
return index;
|
||||
|
||||
spin_lock_irqsave(&edev->lock, flags);
|
||||
|
||||
/* Check whether the property is available or not. */
|
||||
if (!is_extcon_property_capability(edev, id, index, prop)) {
|
||||
spin_unlock_irqrestore(&edev->lock, flags);
|
||||
return -EPERM;
|
||||
}
|
||||
|
||||
cable = &edev->cables[index];
|
||||
|
||||
/* Set the property value according to extcon type */
|
||||
switch (prop) {
|
||||
case EXTCON_PROP_USB_MIN ... EXTCON_PROP_USB_MAX:
|
||||
cable->usb_propval[prop - EXTCON_PROP_USB_MIN] = prop_val;
|
||||
break;
|
||||
case EXTCON_PROP_CHG_MIN ... EXTCON_PROP_CHG_MAX:
|
||||
cable->chg_propval[prop - EXTCON_PROP_CHG_MIN] = prop_val;
|
||||
break;
|
||||
case EXTCON_PROP_JACK_MIN ... EXTCON_PROP_JACK_MAX:
|
||||
cable->jack_propval[prop - EXTCON_PROP_JACK_MIN] = prop_val;
|
||||
break;
|
||||
case EXTCON_PROP_DISP_MIN ... EXTCON_PROP_DISP_MAX:
|
||||
cable->disp_propval[prop - EXTCON_PROP_DISP_MIN] = prop_val;
|
||||
break;
|
||||
default:
|
||||
ret = -EINVAL;
|
||||
break;
|
||||
}
|
||||
|
||||
spin_unlock_irqrestore(&edev->lock, flags);
|
||||
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(extcon_set_property);
|
||||
|
||||
/**
|
||||
* extcon_set_property_sync() - Set the property value of a specific cable
|
||||
with a notification.
|
||||
* @prop_val: the pointer including the new value of property.
|
||||
*
|
||||
* When setting the property value of external connector, the external connector
|
||||
* should be attached. The each property should be included in the list of
|
||||
* supported properties according to the type of external connectors.
|
||||
*
|
||||
* Returns 0 if success or error number if fail
|
||||
*/
|
||||
int extcon_set_property_sync(struct extcon_dev *edev, unsigned int id,
|
||||
unsigned int prop,
|
||||
union extcon_property_value prop_val)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = extcon_set_property(edev, id, prop, prop_val);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
return extcon_sync(edev, id);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(extcon_set_property_sync);
|
||||
|
||||
/**
|
||||
* extcon_get_property_capability() - Get the capability of property
|
||||
* of an external connector.
|
||||
* @edev: the extcon device that has the cable.
|
||||
* @id: the unique id of each external connector
|
||||
* in extcon enumeration.
|
||||
* @prop: the property id among enum extcon_property.
|
||||
*
|
||||
* Returns 1 if the property is available or 0 if not available.
|
||||
*/
|
||||
int extcon_get_property_capability(struct extcon_dev *edev, unsigned int id,
|
||||
unsigned int prop)
|
||||
{
|
||||
int index;
|
||||
|
||||
if (!edev)
|
||||
return -EINVAL;
|
||||
|
||||
/* Check whether the property is supported or not */
|
||||
if (!is_extcon_property_supported(id, prop))
|
||||
return -EINVAL;
|
||||
|
||||
/* Find the cable index of external connector by using id */
|
||||
index = find_cable_index_by_id(edev, id);
|
||||
if (index < 0)
|
||||
return index;
|
||||
|
||||
return is_extcon_property_capability(edev, id, index, prop);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(extcon_get_property_capability);
|
||||
|
||||
/**
|
||||
* extcon_set_property_capability() - Set the capability of a property
|
||||
* of an external connector.
|
||||
* @edev: the extcon device that has the cable.
|
||||
* @id: the unique id of each external connector
|
||||
* in extcon enumeration.
|
||||
* @prop: the property id among enum extcon_property.
|
||||
*
|
||||
* This function set the capability of a property for an external connector
|
||||
* to mark the bit in capability bitmap which mean the available state of
|
||||
* a property.
|
||||
*
|
||||
* Returns 0 if success or error number if fail
|
||||
*/
|
||||
int extcon_set_property_capability(struct extcon_dev *edev, unsigned int id,
|
||||
unsigned int prop)
|
||||
{
|
||||
struct extcon_cable *cable;
|
||||
int index, type, ret = 0;
|
||||
|
||||
if (!edev)
|
||||
return -EINVAL;
|
||||
|
||||
/* Check whether the property is supported or not. */
|
||||
if (!is_extcon_property_supported(id, prop))
|
||||
return -EINVAL;
|
||||
|
||||
/* Find the cable index of external connector by using id. */
|
||||
index = find_cable_index_by_id(edev, id);
|
||||
if (index < 0)
|
||||
return index;
|
||||
|
||||
type = get_extcon_type(prop);
|
||||
if (type < 0)
|
||||
return type;
|
||||
|
||||
cable = &edev->cables[index];
|
||||
|
||||
switch (type) {
|
||||
case EXTCON_TYPE_USB:
|
||||
__set_bit(prop - EXTCON_PROP_USB_MIN, cable->usb_bits);
|
||||
break;
|
||||
case EXTCON_TYPE_CHG:
|
||||
__set_bit(prop - EXTCON_PROP_CHG_MIN, cable->chg_bits);
|
||||
break;
|
||||
case EXTCON_TYPE_JACK:
|
||||
__set_bit(prop - EXTCON_PROP_JACK_MIN, cable->jack_bits);
|
||||
break;
|
||||
case EXTCON_TYPE_DISP:
|
||||
__set_bit(prop - EXTCON_PROP_DISP_MIN, cable->disp_bits);
|
||||
break;
|
||||
default:
|
||||
ret = -EINVAL;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(extcon_set_property_capability);
|
||||
|
||||
/**
|
||||
* extcon_get_extcon_dev() - Get the extcon device instance from the name
|
||||
@ -428,7 +904,7 @@ int extcon_register_notifier(struct extcon_dev *edev, unsigned int id,
|
||||
struct notifier_block *nb)
|
||||
{
|
||||
unsigned long flags;
|
||||
int ret, idx;
|
||||
int ret, idx = -EINVAL;
|
||||
|
||||
if (!nb)
|
||||
return -EINVAL;
|
||||
@ -846,13 +1322,13 @@ struct extcon_dev *extcon_get_edev_by_phandle(struct device *dev, int index)
|
||||
return ERR_PTR(-EINVAL);
|
||||
|
||||
if (!dev->of_node) {
|
||||
dev_err(dev, "device does not have a device node entry\n");
|
||||
dev_dbg(dev, "device does not have a device node entry\n");
|
||||
return ERR_PTR(-EINVAL);
|
||||
}
|
||||
|
||||
node = of_parse_phandle(dev->of_node, "extcon", index);
|
||||
if (!node) {
|
||||
dev_err(dev, "failed to get phandle in %s node\n",
|
||||
dev_dbg(dev, "failed to get phandle in %s node\n",
|
||||
dev->of_node->full_name);
|
||||
return ERR_PTR(-ENODEV);
|
||||
}
|
||||
|
@ -392,7 +392,6 @@ static int rtl2832_sdr_alloc_urbs(struct rtl2832_sdr_dev *dev)
|
||||
dev_dbg(&pdev->dev, "alloc urb=%d\n", i);
|
||||
dev->urb_list[i] = usb_alloc_urb(0, GFP_ATOMIC);
|
||||
if (!dev->urb_list[i]) {
|
||||
dev_dbg(&pdev->dev, "failed\n");
|
||||
for (j = 0; j < i; j++)
|
||||
usb_free_urb(dev->urb_list[j]);
|
||||
return -ENOMEM;
|
||||
|
@ -627,7 +627,6 @@ static int si470x_usb_driver_probe(struct usb_interface *intf,
|
||||
|
||||
radio->int_in_urb = usb_alloc_urb(0, GFP_KERNEL);
|
||||
if (!radio->int_in_urb) {
|
||||
dev_info(&intf->dev, "could not allocate int_in_urb");
|
||||
retval = -ENOMEM;
|
||||
goto err_intbuffer;
|
||||
}
|
||||
|
@ -2211,16 +2211,11 @@ static struct imon_context *imon_init_intf0(struct usb_interface *intf,
|
||||
goto exit;
|
||||
}
|
||||
rx_urb = usb_alloc_urb(0, GFP_KERNEL);
|
||||
if (!rx_urb) {
|
||||
dev_err(dev, "%s: usb_alloc_urb failed for IR urb", __func__);
|
||||
if (!rx_urb)
|
||||
goto rx_urb_alloc_failed;
|
||||
}
|
||||
tx_urb = usb_alloc_urb(0, GFP_KERNEL);
|
||||
if (!tx_urb) {
|
||||
dev_err(dev, "%s: usb_alloc_urb failed for display urb",
|
||||
__func__);
|
||||
if (!tx_urb)
|
||||
goto tx_urb_alloc_failed;
|
||||
}
|
||||
|
||||
mutex_init(&ictx->lock);
|
||||
spin_lock_init(&ictx->kc_lock);
|
||||
@ -2305,10 +2300,8 @@ static struct imon_context *imon_init_intf1(struct usb_interface *intf,
|
||||
int ret = -ENOMEM;
|
||||
|
||||
rx_urb = usb_alloc_urb(0, GFP_KERNEL);
|
||||
if (!rx_urb) {
|
||||
pr_err("usb_alloc_urb failed for IR urb\n");
|
||||
if (!rx_urb)
|
||||
goto rx_urb_alloc_failed;
|
||||
}
|
||||
|
||||
mutex_lock(&ictx->lock);
|
||||
|
||||
|
@ -970,10 +970,8 @@ static int redrat3_dev_probe(struct usb_interface *intf,
|
||||
|
||||
/* set up bulk-in endpoint */
|
||||
rr3->read_urb = usb_alloc_urb(0, GFP_KERNEL);
|
||||
if (!rr3->read_urb) {
|
||||
dev_err(dev, "Read urb allocation failure\n");
|
||||
if (!rr3->read_urb)
|
||||
goto error;
|
||||
}
|
||||
|
||||
rr3->ep_in = ep_in;
|
||||
rr3->bulk_in_buf = usb_alloc_coherent(udev,
|
||||
|
@ -426,7 +426,6 @@ static int airspy_alloc_urbs(struct airspy *s)
|
||||
dev_dbg(s->dev, "alloc urb=%d\n", i);
|
||||
s->urb_list[i] = usb_alloc_urb(0, GFP_ATOMIC);
|
||||
if (!s->urb_list[i]) {
|
||||
dev_dbg(s->dev, "failed\n");
|
||||
for (j = 0; j < i; j++)
|
||||
usb_free_urb(s->urb_list[j]);
|
||||
return -ENOMEM;
|
||||
|
@ -270,8 +270,6 @@ static int as102_alloc_usb_stream_buffer(struct as102_dev_t *dev)
|
||||
|
||||
urb = usb_alloc_urb(0, GFP_ATOMIC);
|
||||
if (urb == NULL) {
|
||||
dev_dbg(&dev->bus_adap.usb_dev->dev,
|
||||
"%s: usb_alloc_urb failed\n", __func__);
|
||||
as102_free_usb_stream_buffer(dev);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
@ -245,7 +245,6 @@ static int au0828_init_isoc(struct au0828_dev *dev, int max_packets,
|
||||
for (i = 0; i < dev->isoc_ctl.num_bufs; i++) {
|
||||
urb = usb_alloc_urb(max_packets, GFP_KERNEL);
|
||||
if (!urb) {
|
||||
au0828_isocdbg("cannot alloc isoc_ctl.urb %i\n", i);
|
||||
au0828_uninit_isoc(dev);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
@ -662,7 +662,6 @@ static int submit_urbs(struct camera_data *cam)
|
||||
}
|
||||
urb = usb_alloc_urb(FRAMES_PER_DESC, GFP_KERNEL);
|
||||
if (!urb) {
|
||||
ERR("%s: usb_alloc_urb error!\n", __func__);
|
||||
for (j = 0; j < i; j++)
|
||||
usb_free_urb(cam->sbuf[j].urb);
|
||||
return -ENOMEM;
|
||||
|
@ -293,7 +293,6 @@ static int cx231xx_init_audio_isoc(struct cx231xx *dev)
|
||||
memset(dev->adev.transfer_buffer[i], 0x80, sb_size);
|
||||
urb = usb_alloc_urb(CX231XX_ISO_NUM_AUDIO_PACKETS, GFP_ATOMIC);
|
||||
if (!urb) {
|
||||
dev_err(dev->dev, "usb_alloc_urb failed!\n");
|
||||
for (j = 0; j < i; j++) {
|
||||
usb_free_urb(dev->adev.urb[j]);
|
||||
kfree(dev->adev.transfer_buffer[j]);
|
||||
@ -355,7 +354,6 @@ static int cx231xx_init_audio_bulk(struct cx231xx *dev)
|
||||
memset(dev->adev.transfer_buffer[i], 0x80, sb_size);
|
||||
urb = usb_alloc_urb(CX231XX_NUM_AUDIO_PACKETS, GFP_ATOMIC);
|
||||
if (!urb) {
|
||||
dev_err(dev->dev, "usb_alloc_urb failed!\n");
|
||||
for (j = 0; j < i; j++) {
|
||||
usb_free_urb(dev->adev.urb[j]);
|
||||
kfree(dev->adev.transfer_buffer[j]);
|
||||
|
@ -1035,8 +1035,6 @@ int cx231xx_init_isoc(struct cx231xx *dev, int max_packets,
|
||||
for (i = 0; i < dev->video_mode.isoc_ctl.num_bufs; i++) {
|
||||
urb = usb_alloc_urb(max_packets, GFP_KERNEL);
|
||||
if (!urb) {
|
||||
dev_err(dev->dev,
|
||||
"cannot alloc isoc_ctl.urb %i\n", i);
|
||||
cx231xx_uninit_isoc(dev);
|
||||
return -ENOMEM;
|
||||
}
|
||||
@ -1172,8 +1170,6 @@ int cx231xx_init_bulk(struct cx231xx *dev, int max_packets,
|
||||
for (i = 0; i < dev->video_mode.bulk_ctl.num_bufs; i++) {
|
||||
urb = usb_alloc_urb(0, GFP_KERNEL);
|
||||
if (!urb) {
|
||||
dev_err(dev->dev,
|
||||
"cannot alloc bulk_ctl.urb %i\n", i);
|
||||
cx231xx_uninit_bulk(dev);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
@ -442,8 +442,6 @@ int cx231xx_init_vbi_isoc(struct cx231xx *dev, int max_packets,
|
||||
|
||||
urb = usb_alloc_urb(0, GFP_KERNEL);
|
||||
if (!urb) {
|
||||
dev_err(dev->dev,
|
||||
"cannot alloc bulk_ctl.urb %i\n", i);
|
||||
cx231xx_uninit_vbi_isoc(dev);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
@ -783,10 +783,8 @@ int dib0700_rc_setup(struct dvb_usb_device *d, struct usb_interface *intf)
|
||||
/* Starting in firmware 1.20, the RC info is provided on a bulk pipe */
|
||||
|
||||
purb = usb_alloc_urb(0, GFP_KERNEL);
|
||||
if (purb == NULL) {
|
||||
err("rc usb alloc urb failed");
|
||||
if (purb == NULL)
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
purb->transfer_buffer = kzalloc(RC_MSG_SIZE_V1_20, GFP_KERNEL);
|
||||
if (purb->transfer_buffer == NULL) {
|
||||
|
@ -850,7 +850,6 @@ static int em28xx_audio_urb_init(struct em28xx *dev)
|
||||
|
||||
urb = usb_alloc_urb(npackets, GFP_ATOMIC);
|
||||
if (!urb) {
|
||||
em28xx_errdev("usb_alloc_urb failed!\n");
|
||||
em28xx_audio_free_urb(dev);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
@ -934,7 +934,6 @@ int em28xx_alloc_urbs(struct em28xx *dev, enum em28xx_mode mode, int xfer_bulk,
|
||||
for (i = 0; i < usb_bufs->num_bufs; i++) {
|
||||
urb = usb_alloc_urb(usb_bufs->num_packets, GFP_KERNEL);
|
||||
if (!urb) {
|
||||
em28xx_err("cannot alloc usb_ctl.urb %i\n", i);
|
||||
em28xx_uninit_usb_xfer(dev, mode);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
@ -95,10 +95,8 @@ static int sd_start(struct gspca_dev *gspca_dev)
|
||||
#define SD_NPKT 32
|
||||
for (n = 0; n < 4; n++) {
|
||||
urb = usb_alloc_urb(SD_NPKT, GFP_KERNEL);
|
||||
if (!urb) {
|
||||
pr_err("usb_alloc_urb failed\n");
|
||||
if (!urb)
|
||||
return -ENOMEM;
|
||||
}
|
||||
gspca_dev->urb[n] = urb;
|
||||
urb->transfer_buffer = usb_alloc_coherent(gspca_dev->dev,
|
||||
SD_PKT_SZ * SD_NPKT,
|
||||
|
@ -795,10 +795,8 @@ static int create_urbs(struct gspca_dev *gspca_dev,
|
||||
|
||||
for (n = 0; n < nurbs; n++) {
|
||||
urb = usb_alloc_urb(npkt, GFP_KERNEL);
|
||||
if (!urb) {
|
||||
pr_err("usb_alloc_urb failed\n");
|
||||
if (!urb)
|
||||
return -ENOMEM;
|
||||
}
|
||||
gspca_dev->urb[n] = urb;
|
||||
urb->transfer_buffer = usb_alloc_coherent(gspca_dev->dev,
|
||||
bsize,
|
||||
|
@ -208,10 +208,8 @@ static int sd_start(struct gspca_dev *gspca_dev)
|
||||
packet_size =
|
||||
le16_to_cpu(alt->endpoint[i].desc.wMaxPacketSize);
|
||||
urb = usb_alloc_urb(SD_NPKT, GFP_KERNEL);
|
||||
if (!urb) {
|
||||
pr_err("usb_alloc_urb failed\n");
|
||||
if (!urb)
|
||||
return -ENOMEM;
|
||||
}
|
||||
gspca_dev->urb[n] = urb;
|
||||
urb->transfer_buffer = usb_alloc_coherent(gspca_dev->dev,
|
||||
packet_size * SD_NPKT,
|
||||
|
@ -691,7 +691,6 @@ static int hackrf_alloc_urbs(struct hackrf_dev *dev, bool rcv)
|
||||
dev_dbg(dev->dev, "alloc urb=%d\n", i);
|
||||
dev->urb_list[i] = usb_alloc_urb(0, GFP_ATOMIC);
|
||||
if (!dev->urb_list[i]) {
|
||||
dev_dbg(dev->dev, "failed\n");
|
||||
for (j = 0; j < i; j++)
|
||||
usb_free_urb(dev->urb_list[j]);
|
||||
return -ENOMEM;
|
||||
|
@ -155,10 +155,8 @@ int hdpvr_alloc_buffers(struct hdpvr_device *dev, uint count)
|
||||
buf->dev = dev;
|
||||
|
||||
urb = usb_alloc_urb(0, GFP_KERNEL);
|
||||
if (!urb) {
|
||||
v4l2_err(&dev->v4l2_dev, "cannot allocate urb\n");
|
||||
if (!urb)
|
||||
goto exit_urb;
|
||||
}
|
||||
buf->urb = urb;
|
||||
|
||||
mem = usb_alloc_coherent(dev->udev, dev->bulk_in_size, GFP_KERNEL,
|
||||
|
@ -509,7 +509,6 @@ static int msi2500_isoc_init(struct msi2500_dev *dev)
|
||||
for (i = 0; i < MAX_ISO_BUFS; i++) {
|
||||
urb = usb_alloc_urb(ISO_FRAMES_PER_DESC, GFP_KERNEL);
|
||||
if (urb == NULL) {
|
||||
dev_err(dev->dev, "Failed to allocate urb %d\n", i);
|
||||
msi2500_isoc_cleanup(dev);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
@ -410,7 +410,6 @@ retry:
|
||||
for (i = 0; i < MAX_ISO_BUFS; i++) {
|
||||
urb = usb_alloc_urb(ISO_FRAMES_PER_DESC, GFP_KERNEL);
|
||||
if (urb == NULL) {
|
||||
PWC_ERROR("Failed to allocate urb %d\n", i);
|
||||
pwc_isoc_cleanup(pdev);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
@ -2113,11 +2113,8 @@ static int s2255_start_readpipe(struct s2255_dev *dev)
|
||||
pipe_info->state = 1;
|
||||
pipe_info->err_count = 0;
|
||||
pipe_info->stream_urb = usb_alloc_urb(0, GFP_KERNEL);
|
||||
if (!pipe_info->stream_urb) {
|
||||
dev_err(&dev->udev->dev,
|
||||
"ReadStream: Unable to alloc URB\n");
|
||||
if (!pipe_info->stream_urb)
|
||||
return -ENOMEM;
|
||||
}
|
||||
/* transfer buffer allocated in board_init */
|
||||
usb_fill_bulk_urb(pipe_info->stream_urb, dev->udev,
|
||||
pipe,
|
||||
@ -2290,10 +2287,8 @@ static int s2255_probe(struct usb_interface *interface,
|
||||
}
|
||||
|
||||
dev->fw_data->fw_urb = usb_alloc_urb(0, GFP_KERNEL);
|
||||
if (!dev->fw_data->fw_urb) {
|
||||
dev_err(&interface->dev, "out of memory!\n");
|
||||
if (!dev->fw_data->fw_urb)
|
||||
goto errorFWURB;
|
||||
}
|
||||
|
||||
dev->fw_data->pfw_data = kzalloc(CHUNK_SIZE, GFP_KERNEL);
|
||||
if (!dev->fw_data->pfw_data) {
|
||||
|
@ -457,10 +457,8 @@ int stk1160_alloc_isoc(struct stk1160 *dev)
|
||||
for (i = 0; i < num_bufs; i++) {
|
||||
|
||||
urb = usb_alloc_urb(max_packets, GFP_KERNEL);
|
||||
if (!urb) {
|
||||
stk1160_err("cannot alloc urb[%d]\n", i);
|
||||
if (!urb)
|
||||
goto free_i_bufs;
|
||||
}
|
||||
dev->isoc_ctl.urb[i] = urb;
|
||||
|
||||
#ifndef CONFIG_DMA_NONCOHERENT
|
||||
|
@ -452,10 +452,8 @@ static int stk_prepare_iso(struct stk_camera *dev)
|
||||
STK_ERROR("isobuf data already allocated\n");
|
||||
if (dev->isobufs[i].urb == NULL) {
|
||||
urb = usb_alloc_urb(ISO_FRAMES_PER_DESC, GFP_KERNEL);
|
||||
if (urb == NULL) {
|
||||
STK_ERROR("Failed to allocate URB %d\n", i);
|
||||
if (urb == NULL)
|
||||
goto isobufs_out;
|
||||
}
|
||||
dev->isobufs[i].urb = urb;
|
||||
} else {
|
||||
STK_ERROR("Killing URB\n");
|
||||
|
@ -129,10 +129,8 @@ static int tm6000_start_stream(struct tm6000_core *dev)
|
||||
}
|
||||
|
||||
dvb->bulk_urb = usb_alloc_urb(0, GFP_KERNEL);
|
||||
if (dvb->bulk_urb == NULL) {
|
||||
printk(KERN_ERR "tm6000: couldn't allocate urb\n");
|
||||
if (dvb->bulk_urb == NULL)
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
pipe = usb_rcvbulkpipe(dev->udev, dev->bulk_in.endp->desc.bEndpointAddress
|
||||
& USB_ENDPOINT_NUMBER_MASK);
|
||||
|
@ -635,7 +635,6 @@ static int tm6000_prepare_isoc(struct tm6000_core *dev)
|
||||
for (i = 0; i < dev->isoc_ctl.num_bufs; i++) {
|
||||
urb = usb_alloc_urb(max_packets, GFP_KERNEL);
|
||||
if (!urb) {
|
||||
tm6000_err("cannot alloc isoc_ctl.urb %i\n", i);
|
||||
tm6000_uninit_isoc(dev);
|
||||
usb_free_urb(urb);
|
||||
return -ENOMEM;
|
||||
|
@ -2303,11 +2303,8 @@ int usbvision_init_isoc(struct usb_usbvision *usbvision)
|
||||
struct urb *urb;
|
||||
|
||||
urb = usb_alloc_urb(USBVISION_URB_FRAMES, GFP_KERNEL);
|
||||
if (urb == NULL) {
|
||||
dev_err(&usbvision->dev->dev,
|
||||
"%s: usb_alloc_urb() failed\n", __func__);
|
||||
if (urb == NULL)
|
||||
return -ENOMEM;
|
||||
}
|
||||
usbvision->sbuf[buf_idx].urb = urb;
|
||||
usbvision->sbuf[buf_idx].data =
|
||||
usb_alloc_coherent(usbvision->dev,
|
||||
|
@ -1045,10 +1045,8 @@ static int zr364xx_start_readpipe(struct zr364xx_camera *cam)
|
||||
pipe_info->state = 1;
|
||||
pipe_info->err_count = 0;
|
||||
pipe_info->stream_urb = usb_alloc_urb(0, GFP_KERNEL);
|
||||
if (!pipe_info->stream_urb) {
|
||||
dev_err(&cam->udev->dev, "ReadStream: Unable to alloc URB\n");
|
||||
if (!pipe_info->stream_urb)
|
||||
return -ENOMEM;
|
||||
}
|
||||
/* transfer buffer allocated in board_init */
|
||||
usb_fill_bulk_urb(pipe_info->stream_urb, cam->udev,
|
||||
pipe,
|
||||
|
@ -2116,13 +2116,11 @@ static int vub300_probe(struct usb_interface *interface,
|
||||
command_out_urb = usb_alloc_urb(0, GFP_KERNEL);
|
||||
if (!command_out_urb) {
|
||||
retval = -ENOMEM;
|
||||
dev_err(&udev->dev, "not enough memory for command_out_urb\n");
|
||||
goto error0;
|
||||
}
|
||||
command_res_urb = usb_alloc_urb(0, GFP_KERNEL);
|
||||
if (!command_res_urb) {
|
||||
retval = -ENOMEM;
|
||||
dev_err(&udev->dev, "not enough memory for command_res_urb\n");
|
||||
goto error1;
|
||||
}
|
||||
/* this also allocates memory for our VUB300 mmc host device */
|
||||
|
@ -24,6 +24,15 @@ config PHY_BCM_NS_USB2
|
||||
Enable this to support Broadcom USB 2.0 PHY connected to the USB
|
||||
controller on Northstar family.
|
||||
|
||||
config PHY_BCM_NS_USB3
|
||||
tristate "Broadcom Northstar USB 3.0 PHY Driver"
|
||||
depends on ARCH_BCM_IPROC || COMPILE_TEST
|
||||
depends on HAS_IOMEM && OF
|
||||
select GENERIC_PHY
|
||||
help
|
||||
Enable this to support Broadcom USB 3.0 PHY connected to the USB
|
||||
controller on Northstar family.
|
||||
|
||||
config PHY_BERLIN_USB
|
||||
tristate "Marvell Berlin USB PHY Driver"
|
||||
depends on ARCH_BERLIN && RESET_CONTROLLER && HAS_IOMEM && OF
|
||||
@ -258,7 +267,9 @@ config PHY_SUN4I_USB
|
||||
depends on RESET_CONTROLLER
|
||||
depends on EXTCON
|
||||
depends on POWER_SUPPLY
|
||||
depends on USB_SUPPORT
|
||||
select GENERIC_PHY
|
||||
select USB_COMMON
|
||||
help
|
||||
Enable this to support the transceiver that is part of Allwinner
|
||||
sunxi SoCs.
|
||||
@ -358,6 +369,14 @@ config PHY_ROCKCHIP_USB
|
||||
help
|
||||
Enable this to support the Rockchip USB 2.0 PHY.
|
||||
|
||||
config PHY_ROCKCHIP_INNO_USB2
|
||||
tristate "Rockchip INNO USB2PHY Driver"
|
||||
depends on (ARCH_ROCKCHIP || COMPILE_TEST) && OF
|
||||
depends on COMMON_CLK
|
||||
select GENERIC_PHY
|
||||
help
|
||||
Support for Rockchip USB2.0 PHY with Innosilicon IP block.
|
||||
|
||||
config PHY_ROCKCHIP_EMMC
|
||||
tristate "Rockchip EMMC PHY Driver"
|
||||
depends on ARCH_ROCKCHIP && OF
|
||||
@ -372,6 +391,23 @@ config PHY_ROCKCHIP_DP
|
||||
help
|
||||
Enable this to support the Rockchip Display Port PHY.
|
||||
|
||||
config PHY_ROCKCHIP_PCIE
|
||||
tristate "Rockchip PCIe PHY Driver"
|
||||
depends on (ARCH_ROCKCHIP && OF) || COMPILE_TEST
|
||||
select GENERIC_PHY
|
||||
select MFD_SYSCON
|
||||
help
|
||||
Enable this to support the Rockchip PCIe PHY.
|
||||
|
||||
config PHY_ROCKCHIP_TYPEC
|
||||
tristate "Rockchip TYPEC PHY Driver"
|
||||
depends on OF && (ARCH_ROCKCHIP || COMPILE_TEST)
|
||||
select EXTCON
|
||||
select GENERIC_PHY
|
||||
select RESET_CONTROLLER
|
||||
help
|
||||
Enable this to support the Rockchip USB TYPEC PHY.
|
||||
|
||||
config PHY_ST_SPEAR1310_MIPHY
|
||||
tristate "ST SPEAR1310-MIPHY driver"
|
||||
select GENERIC_PHY
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
obj-$(CONFIG_GENERIC_PHY) += phy-core.o
|
||||
obj-$(CONFIG_PHY_BCM_NS_USB2) += phy-bcm-ns-usb2.o
|
||||
obj-$(CONFIG_PHY_BCM_NS_USB3) += phy-bcm-ns-usb3.o
|
||||
obj-$(CONFIG_PHY_BERLIN_USB) += phy-berlin-usb.o
|
||||
obj-$(CONFIG_PHY_BERLIN_SATA) += phy-berlin-sata.o
|
||||
obj-$(CONFIG_PHY_DA8XX_USB) += phy-da8xx-usb.o
|
||||
@ -39,8 +40,11 @@ phy-exynos-usb2-$(CONFIG_PHY_S5PV210_USB2) += phy-s5pv210-usb2.o
|
||||
obj-$(CONFIG_PHY_EXYNOS5_USBDRD) += phy-exynos5-usbdrd.o
|
||||
obj-$(CONFIG_PHY_QCOM_APQ8064_SATA) += phy-qcom-apq8064-sata.o
|
||||
obj-$(CONFIG_PHY_ROCKCHIP_USB) += phy-rockchip-usb.o
|
||||
obj-$(CONFIG_PHY_ROCKCHIP_INNO_USB2) += phy-rockchip-inno-usb2.o
|
||||
obj-$(CONFIG_PHY_ROCKCHIP_EMMC) += phy-rockchip-emmc.o
|
||||
obj-$(CONFIG_PHY_ROCKCHIP_PCIE) += phy-rockchip-pcie.o
|
||||
obj-$(CONFIG_PHY_ROCKCHIP_DP) += phy-rockchip-dp.o
|
||||
obj-$(CONFIG_PHY_ROCKCHIP_TYPEC) += phy-rockchip-typec.o
|
||||
obj-$(CONFIG_PHY_QCOM_IPQ806X_SATA) += phy-qcom-ipq806x-sata.o
|
||||
obj-$(CONFIG_PHY_ST_SPEAR1310_MIPHY) += phy-spear1310-miphy.o
|
||||
obj-$(CONFIG_PHY_ST_SPEAR1340_MIPHY) += phy-spear1340-miphy.o
|
||||
|
274
drivers/phy/phy-bcm-ns-usb3.c
Normal file
274
drivers/phy/phy-bcm-ns-usb3.c
Normal file
@ -0,0 +1,274 @@
|
||||
/*
|
||||
* Broadcom Northstar USB 3.0 PHY Driver
|
||||
*
|
||||
* Copyright (C) 2016 Rafał Miłecki <rafal@milecki.pl>
|
||||
*
|
||||
* All magic values used for initialization (and related comments) were obtained
|
||||
* from Broadcom's SDK:
|
||||
* Copyright (c) Broadcom Corp, 2012
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*/
|
||||
|
||||
#include <linux/bcma/bcma.h>
|
||||
#include <linux/delay.h>
|
||||
#include <linux/err.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/of_platform.h>
|
||||
#include <linux/platform_device.h>
|
||||
#include <linux/phy/phy.h>
|
||||
#include <linux/slab.h>
|
||||
|
||||
#define BCM_NS_USB3_MII_MNG_TIMEOUT_US 1000 /* usecs */
|
||||
|
||||
enum bcm_ns_family {
|
||||
BCM_NS_UNKNOWN,
|
||||
BCM_NS_AX,
|
||||
BCM_NS_BX,
|
||||
};
|
||||
|
||||
struct bcm_ns_usb3 {
|
||||
struct device *dev;
|
||||
enum bcm_ns_family family;
|
||||
void __iomem *dmp;
|
||||
void __iomem *ccb_mii;
|
||||
struct phy *phy;
|
||||
};
|
||||
|
||||
static const struct of_device_id bcm_ns_usb3_id_table[] = {
|
||||
{
|
||||
.compatible = "brcm,ns-ax-usb3-phy",
|
||||
.data = (int *)BCM_NS_AX,
|
||||
},
|
||||
{
|
||||
.compatible = "brcm,ns-bx-usb3-phy",
|
||||
.data = (int *)BCM_NS_BX,
|
||||
},
|
||||
{},
|
||||
};
|
||||
MODULE_DEVICE_TABLE(of, bcm_ns_usb3_id_table);
|
||||
|
||||
static int bcm_ns_usb3_wait_reg(struct bcm_ns_usb3 *usb3, void __iomem *addr,
|
||||
u32 mask, u32 value, unsigned long timeout)
|
||||
{
|
||||
unsigned long deadline = jiffies + timeout;
|
||||
u32 val;
|
||||
|
||||
do {
|
||||
val = readl(addr);
|
||||
if ((val & mask) == value)
|
||||
return 0;
|
||||
cpu_relax();
|
||||
udelay(10);
|
||||
} while (!time_after_eq(jiffies, deadline));
|
||||
|
||||
dev_err(usb3->dev, "Timeout waiting for register %p\n", addr);
|
||||
|
||||
return -EBUSY;
|
||||
}
|
||||
|
||||
static inline int bcm_ns_usb3_mii_mng_wait_idle(struct bcm_ns_usb3 *usb3)
|
||||
{
|
||||
return bcm_ns_usb3_wait_reg(usb3, usb3->ccb_mii + BCMA_CCB_MII_MNG_CTL,
|
||||
0x0100, 0x0000,
|
||||
usecs_to_jiffies(BCM_NS_USB3_MII_MNG_TIMEOUT_US));
|
||||
}
|
||||
|
||||
static int bcm_ns_usb3_mii_mng_write32(struct bcm_ns_usb3 *usb3, u32 value)
|
||||
{
|
||||
int err;
|
||||
|
||||
err = bcm_ns_usb3_mii_mng_wait_idle(usb3);
|
||||
if (err < 0) {
|
||||
dev_err(usb3->dev, "Couldn't write 0x%08x value\n", value);
|
||||
return err;
|
||||
}
|
||||
|
||||
writel(value, usb3->ccb_mii + BCMA_CCB_MII_MNG_CMD_DATA);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int bcm_ns_usb3_phy_init_ns_bx(struct bcm_ns_usb3 *usb3)
|
||||
{
|
||||
int err;
|
||||
|
||||
/* Enable MDIO. Setting MDCDIV as 26 */
|
||||
writel(0x0000009a, usb3->ccb_mii + BCMA_CCB_MII_MNG_CTL);
|
||||
|
||||
/* Wait for MDIO? */
|
||||
udelay(2);
|
||||
|
||||
/* USB3 PLL Block */
|
||||
err = bcm_ns_usb3_mii_mng_write32(usb3, 0x587e8000);
|
||||
if (err < 0)
|
||||
return err;
|
||||
|
||||
/* Assert Ana_Pllseq start */
|
||||
bcm_ns_usb3_mii_mng_write32(usb3, 0x58061000);
|
||||
|
||||
/* Assert CML Divider ratio to 26 */
|
||||
bcm_ns_usb3_mii_mng_write32(usb3, 0x582a6400);
|
||||
|
||||
/* Asserting PLL Reset */
|
||||
bcm_ns_usb3_mii_mng_write32(usb3, 0x582ec000);
|
||||
|
||||
/* Deaaserting PLL Reset */
|
||||
bcm_ns_usb3_mii_mng_write32(usb3, 0x582e8000);
|
||||
|
||||
/* Waiting MII Mgt interface idle */
|
||||
bcm_ns_usb3_mii_mng_wait_idle(usb3);
|
||||
|
||||
/* Deasserting USB3 system reset */
|
||||
writel(0, usb3->dmp + BCMA_RESET_CTL);
|
||||
|
||||
/* PLL frequency monitor enable */
|
||||
bcm_ns_usb3_mii_mng_write32(usb3, 0x58069000);
|
||||
|
||||
/* PIPE Block */
|
||||
bcm_ns_usb3_mii_mng_write32(usb3, 0x587e8060);
|
||||
|
||||
/* CMPMAX & CMPMINTH setting */
|
||||
bcm_ns_usb3_mii_mng_write32(usb3, 0x580af30d);
|
||||
|
||||
/* DEGLITCH MIN & MAX setting */
|
||||
bcm_ns_usb3_mii_mng_write32(usb3, 0x580e6302);
|
||||
|
||||
/* TXPMD block */
|
||||
bcm_ns_usb3_mii_mng_write32(usb3, 0x587e8040);
|
||||
|
||||
/* Enabling SSC */
|
||||
bcm_ns_usb3_mii_mng_write32(usb3, 0x58061003);
|
||||
|
||||
/* Waiting MII Mgt interface idle */
|
||||
bcm_ns_usb3_mii_mng_wait_idle(usb3);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int bcm_ns_usb3_phy_init_ns_ax(struct bcm_ns_usb3 *usb3)
|
||||
{
|
||||
int err;
|
||||
|
||||
/* Enable MDIO. Setting MDCDIV as 26 */
|
||||
writel(0x0000009a, usb3->ccb_mii + BCMA_CCB_MII_MNG_CTL);
|
||||
|
||||
/* Wait for MDIO? */
|
||||
udelay(2);
|
||||
|
||||
/* PLL30 block */
|
||||
err = bcm_ns_usb3_mii_mng_write32(usb3, 0x587e8000);
|
||||
if (err < 0)
|
||||
return err;
|
||||
|
||||
bcm_ns_usb3_mii_mng_write32(usb3, 0x582a6400);
|
||||
|
||||
bcm_ns_usb3_mii_mng_write32(usb3, 0x587e80e0);
|
||||
|
||||
bcm_ns_usb3_mii_mng_write32(usb3, 0x580a009c);
|
||||
|
||||
/* Enable SSC */
|
||||
bcm_ns_usb3_mii_mng_write32(usb3, 0x587e8040);
|
||||
|
||||
bcm_ns_usb3_mii_mng_write32(usb3, 0x580a21d3);
|
||||
|
||||
bcm_ns_usb3_mii_mng_write32(usb3, 0x58061003);
|
||||
|
||||
/* Waiting MII Mgt interface idle */
|
||||
bcm_ns_usb3_mii_mng_wait_idle(usb3);
|
||||
|
||||
/* Deasserting USB3 system reset */
|
||||
writel(0, usb3->dmp + BCMA_RESET_CTL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int bcm_ns_usb3_phy_init(struct phy *phy)
|
||||
{
|
||||
struct bcm_ns_usb3 *usb3 = phy_get_drvdata(phy);
|
||||
int err;
|
||||
|
||||
/* Perform USB3 system soft reset */
|
||||
writel(BCMA_RESET_CTL_RESET, usb3->dmp + BCMA_RESET_CTL);
|
||||
|
||||
switch (usb3->family) {
|
||||
case BCM_NS_AX:
|
||||
err = bcm_ns_usb3_phy_init_ns_ax(usb3);
|
||||
break;
|
||||
case BCM_NS_BX:
|
||||
err = bcm_ns_usb3_phy_init_ns_bx(usb3);
|
||||
break;
|
||||
default:
|
||||
WARN_ON(1);
|
||||
err = -ENOTSUPP;
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
static const struct phy_ops ops = {
|
||||
.init = bcm_ns_usb3_phy_init,
|
||||
.owner = THIS_MODULE,
|
||||
};
|
||||
|
||||
static int bcm_ns_usb3_probe(struct platform_device *pdev)
|
||||
{
|
||||
struct device *dev = &pdev->dev;
|
||||
const struct of_device_id *of_id;
|
||||
struct bcm_ns_usb3 *usb3;
|
||||
struct resource *res;
|
||||
struct phy_provider *phy_provider;
|
||||
|
||||
usb3 = devm_kzalloc(dev, sizeof(*usb3), GFP_KERNEL);
|
||||
if (!usb3)
|
||||
return -ENOMEM;
|
||||
|
||||
usb3->dev = dev;
|
||||
|
||||
of_id = of_match_device(bcm_ns_usb3_id_table, dev);
|
||||
if (!of_id)
|
||||
return -EINVAL;
|
||||
usb3->family = (enum bcm_ns_family)of_id->data;
|
||||
|
||||
res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dmp");
|
||||
usb3->dmp = devm_ioremap_resource(dev, res);
|
||||
if (IS_ERR(usb3->dmp)) {
|
||||
dev_err(dev, "Failed to map DMP regs\n");
|
||||
return PTR_ERR(usb3->dmp);
|
||||
}
|
||||
|
||||
res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "ccb-mii");
|
||||
usb3->ccb_mii = devm_ioremap_resource(dev, res);
|
||||
if (IS_ERR(usb3->ccb_mii)) {
|
||||
dev_err(dev, "Failed to map ChipCommon B MII regs\n");
|
||||
return PTR_ERR(usb3->ccb_mii);
|
||||
}
|
||||
|
||||
usb3->phy = devm_phy_create(dev, NULL, &ops);
|
||||
if (IS_ERR(usb3->phy)) {
|
||||
dev_err(dev, "Failed to create PHY\n");
|
||||
return PTR_ERR(usb3->phy);
|
||||
}
|
||||
|
||||
phy_set_drvdata(usb3->phy, usb3);
|
||||
platform_set_drvdata(pdev, usb3);
|
||||
|
||||
phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
|
||||
if (!IS_ERR(phy_provider))
|
||||
dev_info(dev, "Registered Broadcom Northstar USB 3.0 PHY driver\n");
|
||||
|
||||
return PTR_ERR_OR_ZERO(phy_provider);
|
||||
}
|
||||
|
||||
static struct platform_driver bcm_ns_usb3_driver = {
|
||||
.probe = bcm_ns_usb3_probe,
|
||||
.driver = {
|
||||
.name = "bcm_ns_usb3",
|
||||
.of_match_table = bcm_ns_usb3_id_table,
|
||||
},
|
||||
};
|
||||
module_platform_driver(bcm_ns_usb3_driver);
|
||||
|
||||
MODULE_LICENSE("GPL v2");
|
@ -18,11 +18,6 @@
|
||||
#include <linux/phy.h>
|
||||
#include <linux/phy/phy.h>
|
||||
|
||||
struct ns2_pci_phy {
|
||||
struct mdio_device *mdiodev;
|
||||
struct phy *phy;
|
||||
};
|
||||
|
||||
#define BLK_ADDR_REG_OFFSET 0x1f
|
||||
#define PLL_AFE1_100MHZ_BLK 0x2100
|
||||
#define PLL_CLK_AMP_OFFSET 0x03
|
||||
@ -30,17 +25,17 @@ struct ns2_pci_phy {
|
||||
|
||||
static int ns2_pci_phy_init(struct phy *p)
|
||||
{
|
||||
struct ns2_pci_phy *phy = phy_get_drvdata(p);
|
||||
struct mdio_device *mdiodev = phy_get_drvdata(p);
|
||||
int rc;
|
||||
|
||||
/* select the AFE 100MHz block page */
|
||||
rc = mdiobus_write(phy->mdiodev->bus, phy->mdiodev->addr,
|
||||
rc = mdiobus_write(mdiodev->bus, mdiodev->addr,
|
||||
BLK_ADDR_REG_OFFSET, PLL_AFE1_100MHZ_BLK);
|
||||
if (rc)
|
||||
goto err;
|
||||
|
||||
/* set the 100 MHz reference clock amplitude to 2.05 v */
|
||||
rc = mdiobus_write(phy->mdiodev->bus, phy->mdiodev->addr,
|
||||
rc = mdiobus_write(mdiodev->bus, mdiodev->addr,
|
||||
PLL_CLK_AMP_OFFSET, PLL_CLK_AMP_2P05V);
|
||||
if (rc)
|
||||
goto err;
|
||||
@ -48,19 +43,19 @@ static int ns2_pci_phy_init(struct phy *p)
|
||||
return 0;
|
||||
|
||||
err:
|
||||
dev_err(&phy->mdiodev->dev, "Error %d writing to phy\n", rc);
|
||||
dev_err(&mdiodev->dev, "Error %d writing to phy\n", rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
static struct phy_ops ns2_pci_phy_ops = {
|
||||
static const struct phy_ops ns2_pci_phy_ops = {
|
||||
.init = ns2_pci_phy_init,
|
||||
.owner = THIS_MODULE,
|
||||
};
|
||||
|
||||
static int ns2_pci_phy_probe(struct mdio_device *mdiodev)
|
||||
{
|
||||
struct device *dev = &mdiodev->dev;
|
||||
struct phy_provider *provider;
|
||||
struct ns2_pci_phy *p;
|
||||
struct phy *phy;
|
||||
|
||||
phy = devm_phy_create(dev, dev->of_node, &ns2_pci_phy_ops);
|
||||
@ -69,16 +64,7 @@ static int ns2_pci_phy_probe(struct mdio_device *mdiodev)
|
||||
return PTR_ERR(phy);
|
||||
}
|
||||
|
||||
p = devm_kmalloc(dev, sizeof(struct ns2_pci_phy),
|
||||
GFP_KERNEL);
|
||||
if (!p)
|
||||
return -ENOMEM;
|
||||
|
||||
p->mdiodev = mdiodev;
|
||||
dev_set_drvdata(dev, p);
|
||||
|
||||
p->phy = phy;
|
||||
phy_set_drvdata(phy, p);
|
||||
phy_set_drvdata(phy, mdiodev);
|
||||
|
||||
provider = devm_of_phy_provider_register(&phy->dev,
|
||||
of_phy_simple_xlate);
|
||||
|
@ -357,6 +357,21 @@ int phy_set_mode(struct phy *phy, enum phy_mode mode)
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(phy_set_mode);
|
||||
|
||||
int phy_reset(struct phy *phy)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (!phy || !phy->ops->reset)
|
||||
return 0;
|
||||
|
||||
mutex_lock(&phy->mutex);
|
||||
ret = phy->ops->reset(phy);
|
||||
mutex_unlock(&phy->mutex);
|
||||
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(phy_reset);
|
||||
|
||||
/**
|
||||
* _of_phy_get() - lookup and obtain a reference to a phy by phandle
|
||||
* @np: device_node for which to get the phy
|
||||
|
@ -154,7 +154,7 @@ static int da8xx_usb_phy_probe(struct platform_device *pdev)
|
||||
d_phy->regmap = syscon_regmap_lookup_by_compatible(
|
||||
"ti,da830-cfgchip");
|
||||
else
|
||||
d_phy->regmap = syscon_regmap_lookup_by_pdevname("syscon.0");
|
||||
d_phy->regmap = syscon_regmap_lookup_by_pdevname("syscon");
|
||||
if (IS_ERR(d_phy->regmap)) {
|
||||
dev_err(dev, "Failed to get syscon\n");
|
||||
return PTR_ERR(d_phy->regmap);
|
||||
|
@ -249,7 +249,7 @@ static void exynos5_usbdrd_phy_isol(struct phy_usb_instance *inst,
|
||||
static unsigned int
|
||||
exynos5_usbdrd_pipe3_set_refclk(struct phy_usb_instance *inst)
|
||||
{
|
||||
static u32 reg;
|
||||
u32 reg;
|
||||
struct exynos5_usbdrd_phy *phy_drd = to_usbdrd_phy(inst);
|
||||
|
||||
/* restore any previous reference clock settings */
|
||||
@ -295,7 +295,7 @@ exynos5_usbdrd_pipe3_set_refclk(struct phy_usb_instance *inst)
|
||||
static unsigned int
|
||||
exynos5_usbdrd_utmi_set_refclk(struct phy_usb_instance *inst)
|
||||
{
|
||||
static u32 reg;
|
||||
u32 reg;
|
||||
struct exynos5_usbdrd_phy *phy_drd = to_usbdrd_phy(inst);
|
||||
|
||||
/* restore any previous reference clock settings */
|
||||
|
@ -133,11 +133,49 @@ static int omap_usb_power_on(struct phy *x)
|
||||
return omap_usb_phy_power(phy, true);
|
||||
}
|
||||
|
||||
static int omap_usb2_disable_clocks(struct omap_usb *phy)
|
||||
{
|
||||
clk_disable(phy->wkupclk);
|
||||
if (!IS_ERR(phy->optclk))
|
||||
clk_disable(phy->optclk);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int omap_usb2_enable_clocks(struct omap_usb *phy)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = clk_enable(phy->wkupclk);
|
||||
if (ret < 0) {
|
||||
dev_err(phy->dev, "Failed to enable wkupclk %d\n", ret);
|
||||
goto err0;
|
||||
}
|
||||
|
||||
if (!IS_ERR(phy->optclk)) {
|
||||
ret = clk_enable(phy->optclk);
|
||||
if (ret < 0) {
|
||||
dev_err(phy->dev, "Failed to enable optclk %d\n", ret);
|
||||
goto err1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
err1:
|
||||
clk_disable(phy->wkupclk);
|
||||
|
||||
err0:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int omap_usb_init(struct phy *x)
|
||||
{
|
||||
struct omap_usb *phy = phy_get_drvdata(x);
|
||||
u32 val;
|
||||
|
||||
omap_usb2_enable_clocks(phy);
|
||||
|
||||
if (phy->flags & OMAP_USB2_CALIBRATE_FALSE_DISCONNECT) {
|
||||
/*
|
||||
*
|
||||
@ -155,8 +193,16 @@ static int omap_usb_init(struct phy *x)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int omap_usb_exit(struct phy *x)
|
||||
{
|
||||
struct omap_usb *phy = phy_get_drvdata(x);
|
||||
|
||||
return omap_usb2_disable_clocks(phy);
|
||||
}
|
||||
|
||||
static const struct phy_ops ops = {
|
||||
.init = omap_usb_init,
|
||||
.exit = omap_usb_exit,
|
||||
.power_on = omap_usb_power_on,
|
||||
.power_off = omap_usb_power_off,
|
||||
.owner = THIS_MODULE,
|
||||
@ -376,65 +422,11 @@ static int omap_usb2_remove(struct platform_device *pdev)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_PM
|
||||
|
||||
static int omap_usb2_runtime_suspend(struct device *dev)
|
||||
{
|
||||
struct platform_device *pdev = to_platform_device(dev);
|
||||
struct omap_usb *phy = platform_get_drvdata(pdev);
|
||||
|
||||
clk_disable(phy->wkupclk);
|
||||
if (!IS_ERR(phy->optclk))
|
||||
clk_disable(phy->optclk);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int omap_usb2_runtime_resume(struct device *dev)
|
||||
{
|
||||
struct platform_device *pdev = to_platform_device(dev);
|
||||
struct omap_usb *phy = platform_get_drvdata(pdev);
|
||||
int ret;
|
||||
|
||||
ret = clk_enable(phy->wkupclk);
|
||||
if (ret < 0) {
|
||||
dev_err(phy->dev, "Failed to enable wkupclk %d\n", ret);
|
||||
goto err0;
|
||||
}
|
||||
|
||||
if (!IS_ERR(phy->optclk)) {
|
||||
ret = clk_enable(phy->optclk);
|
||||
if (ret < 0) {
|
||||
dev_err(phy->dev, "Failed to enable optclk %d\n", ret);
|
||||
goto err1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
err1:
|
||||
clk_disable(phy->wkupclk);
|
||||
|
||||
err0:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static const struct dev_pm_ops omap_usb2_pm_ops = {
|
||||
SET_RUNTIME_PM_OPS(omap_usb2_runtime_suspend, omap_usb2_runtime_resume,
|
||||
NULL)
|
||||
};
|
||||
|
||||
#define DEV_PM_OPS (&omap_usb2_pm_ops)
|
||||
#else
|
||||
#define DEV_PM_OPS NULL
|
||||
#endif
|
||||
|
||||
static struct platform_driver omap_usb2_driver = {
|
||||
.probe = omap_usb2_probe,
|
||||
.remove = omap_usb2_remove,
|
||||
.driver = {
|
||||
.name = "omap-usb2",
|
||||
.pm = DEV_PM_OPS,
|
||||
.of_match_table = omap_usb2_id_table,
|
||||
},
|
||||
};
|
||||
|
@ -283,10 +283,8 @@ static int __ufs_qcom_phy_init_vreg(struct phy *phy,
|
||||
err = 0;
|
||||
}
|
||||
snprintf(prop_name, MAX_PROP_NAME, "%s-always-on", name);
|
||||
if (of_get_property(dev->of_node, prop_name, NULL))
|
||||
vreg->is_always_on = true;
|
||||
else
|
||||
vreg->is_always_on = false;
|
||||
vreg->is_always_on = of_property_read_bool(dev->of_node,
|
||||
prop_name);
|
||||
}
|
||||
|
||||
if (!strcmp(name, "vdda-pll")) {
|
||||
|
@ -280,6 +280,7 @@ static irqreturn_t rcar_gen3_phy_usb2_irq(int irq, void *_ch)
|
||||
|
||||
static const struct of_device_id rcar_gen3_phy_usb2_match_table[] = {
|
||||
{ .compatible = "renesas,usb2-phy-r8a7795" },
|
||||
{ .compatible = "renesas,usb2-phy-r8a7796" },
|
||||
{ .compatible = "renesas,rcar-gen3-usb2-phy" },
|
||||
{ }
|
||||
};
|
||||
|
707
drivers/phy/phy-rockchip-inno-usb2.c
Normal file
707
drivers/phy/phy-rockchip-inno-usb2.c
Normal file
@ -0,0 +1,707 @@
|
||||
/*
|
||||
* Rockchip USB2.0 PHY with Innosilicon IP block driver
|
||||
*
|
||||
* Copyright (C) 2016 Fuzhou Rockchip Electronics Co., Ltd
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include <linux/clk.h>
|
||||
#include <linux/clk-provider.h>
|
||||
#include <linux/delay.h>
|
||||
#include <linux/interrupt.h>
|
||||
#include <linux/io.h>
|
||||
#include <linux/gpio/consumer.h>
|
||||
#include <linux/jiffies.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/mutex.h>
|
||||
#include <linux/of.h>
|
||||
#include <linux/of_address.h>
|
||||
#include <linux/of_irq.h>
|
||||
#include <linux/of_platform.h>
|
||||
#include <linux/phy/phy.h>
|
||||
#include <linux/platform_device.h>
|
||||
#include <linux/regmap.h>
|
||||
#include <linux/mfd/syscon.h>
|
||||
|
||||
#define BIT_WRITEABLE_SHIFT 16
|
||||
#define SCHEDULE_DELAY (60 * HZ)
|
||||
|
||||
enum rockchip_usb2phy_port_id {
|
||||
USB2PHY_PORT_OTG,
|
||||
USB2PHY_PORT_HOST,
|
||||
USB2PHY_NUM_PORTS,
|
||||
};
|
||||
|
||||
enum rockchip_usb2phy_host_state {
|
||||
PHY_STATE_HS_ONLINE = 0,
|
||||
PHY_STATE_DISCONNECT = 1,
|
||||
PHY_STATE_CONNECT = 2,
|
||||
PHY_STATE_FS_LS_ONLINE = 4,
|
||||
};
|
||||
|
||||
struct usb2phy_reg {
|
||||
unsigned int offset;
|
||||
unsigned int bitend;
|
||||
unsigned int bitstart;
|
||||
unsigned int disable;
|
||||
unsigned int enable;
|
||||
};
|
||||
|
||||
/**
|
||||
* struct rockchip_usb2phy_port_cfg: usb-phy port configuration.
|
||||
* @phy_sus: phy suspend register.
|
||||
* @ls_det_en: linestate detection enable register.
|
||||
* @ls_det_st: linestate detection state register.
|
||||
* @ls_det_clr: linestate detection clear register.
|
||||
* @utmi_ls: utmi linestate state register.
|
||||
* @utmi_hstdet: utmi host disconnect register.
|
||||
*/
|
||||
struct rockchip_usb2phy_port_cfg {
|
||||
struct usb2phy_reg phy_sus;
|
||||
struct usb2phy_reg ls_det_en;
|
||||
struct usb2phy_reg ls_det_st;
|
||||
struct usb2phy_reg ls_det_clr;
|
||||
struct usb2phy_reg utmi_ls;
|
||||
struct usb2phy_reg utmi_hstdet;
|
||||
};
|
||||
|
||||
/**
|
||||
* struct rockchip_usb2phy_cfg: usb-phy configuration.
|
||||
* @reg: the address offset of grf for usb-phy config.
|
||||
* @num_ports: specify how many ports that the phy has.
|
||||
* @clkout_ctl: keep on/turn off output clk of phy.
|
||||
*/
|
||||
struct rockchip_usb2phy_cfg {
|
||||
unsigned int reg;
|
||||
unsigned int num_ports;
|
||||
struct usb2phy_reg clkout_ctl;
|
||||
const struct rockchip_usb2phy_port_cfg port_cfgs[USB2PHY_NUM_PORTS];
|
||||
};
|
||||
|
||||
/**
|
||||
* struct rockchip_usb2phy_port: usb-phy port data.
|
||||
* @port_id: flag for otg port or host port.
|
||||
* @suspended: phy suspended flag.
|
||||
* @ls_irq: IRQ number assigned for linestate detection.
|
||||
* @mutex: for register updating in sm_work.
|
||||
* @sm_work: OTG state machine work.
|
||||
* @phy_cfg: port register configuration, assigned by driver data.
|
||||
*/
|
||||
struct rockchip_usb2phy_port {
|
||||
struct phy *phy;
|
||||
unsigned int port_id;
|
||||
bool suspended;
|
||||
int ls_irq;
|
||||
struct mutex mutex;
|
||||
struct delayed_work sm_work;
|
||||
const struct rockchip_usb2phy_port_cfg *port_cfg;
|
||||
};
|
||||
|
||||
/**
|
||||
* struct rockchip_usb2phy: usb2.0 phy driver data.
|
||||
* @grf: General Register Files regmap.
|
||||
* @clk: clock struct of phy input clk.
|
||||
* @clk480m: clock struct of phy output clk.
|
||||
* @clk_hw: clock struct of phy output clk management.
|
||||
* @phy_cfg: phy register configuration, assigned by driver data.
|
||||
* @ports: phy port instance.
|
||||
*/
|
||||
struct rockchip_usb2phy {
|
||||
struct device *dev;
|
||||
struct regmap *grf;
|
||||
struct clk *clk;
|
||||
struct clk *clk480m;
|
||||
struct clk_hw clk480m_hw;
|
||||
const struct rockchip_usb2phy_cfg *phy_cfg;
|
||||
struct rockchip_usb2phy_port ports[USB2PHY_NUM_PORTS];
|
||||
};
|
||||
|
||||
static inline int property_enable(struct rockchip_usb2phy *rphy,
|
||||
const struct usb2phy_reg *reg, bool en)
|
||||
{
|
||||
unsigned int val, mask, tmp;
|
||||
|
||||
tmp = en ? reg->enable : reg->disable;
|
||||
mask = GENMASK(reg->bitend, reg->bitstart);
|
||||
val = (tmp << reg->bitstart) | (mask << BIT_WRITEABLE_SHIFT);
|
||||
|
||||
return regmap_write(rphy->grf, reg->offset, val);
|
||||
}
|
||||
|
||||
static inline bool property_enabled(struct rockchip_usb2phy *rphy,
|
||||
const struct usb2phy_reg *reg)
|
||||
{
|
||||
int ret;
|
||||
unsigned int tmp, orig;
|
||||
unsigned int mask = GENMASK(reg->bitend, reg->bitstart);
|
||||
|
||||
ret = regmap_read(rphy->grf, reg->offset, &orig);
|
||||
if (ret)
|
||||
return false;
|
||||
|
||||
tmp = (orig & mask) >> reg->bitstart;
|
||||
return tmp == reg->enable;
|
||||
}
|
||||
|
||||
static int rockchip_usb2phy_clk480m_enable(struct clk_hw *hw)
|
||||
{
|
||||
struct rockchip_usb2phy *rphy =
|
||||
container_of(hw, struct rockchip_usb2phy, clk480m_hw);
|
||||
int ret;
|
||||
|
||||
/* turn on 480m clk output if it is off */
|
||||
if (!property_enabled(rphy, &rphy->phy_cfg->clkout_ctl)) {
|
||||
ret = property_enable(rphy, &rphy->phy_cfg->clkout_ctl, true);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
/* waitting for the clk become stable */
|
||||
mdelay(1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void rockchip_usb2phy_clk480m_disable(struct clk_hw *hw)
|
||||
{
|
||||
struct rockchip_usb2phy *rphy =
|
||||
container_of(hw, struct rockchip_usb2phy, clk480m_hw);
|
||||
|
||||
/* turn off 480m clk output */
|
||||
property_enable(rphy, &rphy->phy_cfg->clkout_ctl, false);
|
||||
}
|
||||
|
||||
static int rockchip_usb2phy_clk480m_enabled(struct clk_hw *hw)
|
||||
{
|
||||
struct rockchip_usb2phy *rphy =
|
||||
container_of(hw, struct rockchip_usb2phy, clk480m_hw);
|
||||
|
||||
return property_enabled(rphy, &rphy->phy_cfg->clkout_ctl);
|
||||
}
|
||||
|
||||
static unsigned long
|
||||
rockchip_usb2phy_clk480m_recalc_rate(struct clk_hw *hw,
|
||||
unsigned long parent_rate)
|
||||
{
|
||||
return 480000000;
|
||||
}
|
||||
|
||||
static const struct clk_ops rockchip_usb2phy_clkout_ops = {
|
||||
.enable = rockchip_usb2phy_clk480m_enable,
|
||||
.disable = rockchip_usb2phy_clk480m_disable,
|
||||
.is_enabled = rockchip_usb2phy_clk480m_enabled,
|
||||
.recalc_rate = rockchip_usb2phy_clk480m_recalc_rate,
|
||||
};
|
||||
|
||||
static void rockchip_usb2phy_clk480m_unregister(void *data)
|
||||
{
|
||||
struct rockchip_usb2phy *rphy = data;
|
||||
|
||||
of_clk_del_provider(rphy->dev->of_node);
|
||||
clk_unregister(rphy->clk480m);
|
||||
}
|
||||
|
||||
static int
|
||||
rockchip_usb2phy_clk480m_register(struct rockchip_usb2phy *rphy)
|
||||
{
|
||||
struct device_node *node = rphy->dev->of_node;
|
||||
struct clk_init_data init;
|
||||
const char *clk_name;
|
||||
int ret;
|
||||
|
||||
init.flags = 0;
|
||||
init.name = "clk_usbphy_480m";
|
||||
init.ops = &rockchip_usb2phy_clkout_ops;
|
||||
|
||||
/* optional override of the clockname */
|
||||
of_property_read_string(node, "clock-output-names", &init.name);
|
||||
|
||||
if (rphy->clk) {
|
||||
clk_name = __clk_get_name(rphy->clk);
|
||||
init.parent_names = &clk_name;
|
||||
init.num_parents = 1;
|
||||
} else {
|
||||
init.parent_names = NULL;
|
||||
init.num_parents = 0;
|
||||
}
|
||||
|
||||
rphy->clk480m_hw.init = &init;
|
||||
|
||||
/* register the clock */
|
||||
rphy->clk480m = clk_register(rphy->dev, &rphy->clk480m_hw);
|
||||
if (IS_ERR(rphy->clk480m)) {
|
||||
ret = PTR_ERR(rphy->clk480m);
|
||||
goto err_ret;
|
||||
}
|
||||
|
||||
ret = of_clk_add_provider(node, of_clk_src_simple_get, rphy->clk480m);
|
||||
if (ret < 0)
|
||||
goto err_clk_provider;
|
||||
|
||||
ret = devm_add_action(rphy->dev, rockchip_usb2phy_clk480m_unregister,
|
||||
rphy);
|
||||
if (ret < 0)
|
||||
goto err_unreg_action;
|
||||
|
||||
return 0;
|
||||
|
||||
err_unreg_action:
|
||||
of_clk_del_provider(node);
|
||||
err_clk_provider:
|
||||
clk_unregister(rphy->clk480m);
|
||||
err_ret:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int rockchip_usb2phy_init(struct phy *phy)
|
||||
{
|
||||
struct rockchip_usb2phy_port *rport = phy_get_drvdata(phy);
|
||||
struct rockchip_usb2phy *rphy = dev_get_drvdata(phy->dev.parent);
|
||||
int ret;
|
||||
|
||||
if (rport->port_id == USB2PHY_PORT_HOST) {
|
||||
/* clear linestate and enable linestate detect irq */
|
||||
mutex_lock(&rport->mutex);
|
||||
|
||||
ret = property_enable(rphy, &rport->port_cfg->ls_det_clr, true);
|
||||
if (ret) {
|
||||
mutex_unlock(&rport->mutex);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = property_enable(rphy, &rport->port_cfg->ls_det_en, true);
|
||||
if (ret) {
|
||||
mutex_unlock(&rport->mutex);
|
||||
return ret;
|
||||
}
|
||||
|
||||
mutex_unlock(&rport->mutex);
|
||||
schedule_delayed_work(&rport->sm_work, SCHEDULE_DELAY);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rockchip_usb2phy_power_on(struct phy *phy)
|
||||
{
|
||||
struct rockchip_usb2phy_port *rport = phy_get_drvdata(phy);
|
||||
struct rockchip_usb2phy *rphy = dev_get_drvdata(phy->dev.parent);
|
||||
int ret;
|
||||
|
||||
dev_dbg(&rport->phy->dev, "port power on\n");
|
||||
|
||||
if (!rport->suspended)
|
||||
return 0;
|
||||
|
||||
ret = clk_prepare_enable(rphy->clk480m);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
ret = property_enable(rphy, &rport->port_cfg->phy_sus, false);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
rport->suspended = false;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rockchip_usb2phy_power_off(struct phy *phy)
|
||||
{
|
||||
struct rockchip_usb2phy_port *rport = phy_get_drvdata(phy);
|
||||
struct rockchip_usb2phy *rphy = dev_get_drvdata(phy->dev.parent);
|
||||
int ret;
|
||||
|
||||
dev_dbg(&rport->phy->dev, "port power off\n");
|
||||
|
||||
if (rport->suspended)
|
||||
return 0;
|
||||
|
||||
ret = property_enable(rphy, &rport->port_cfg->phy_sus, true);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
rport->suspended = true;
|
||||
clk_disable_unprepare(rphy->clk480m);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rockchip_usb2phy_exit(struct phy *phy)
|
||||
{
|
||||
struct rockchip_usb2phy_port *rport = phy_get_drvdata(phy);
|
||||
|
||||
if (rport->port_id == USB2PHY_PORT_HOST)
|
||||
cancel_delayed_work_sync(&rport->sm_work);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct phy_ops rockchip_usb2phy_ops = {
|
||||
.init = rockchip_usb2phy_init,
|
||||
.exit = rockchip_usb2phy_exit,
|
||||
.power_on = rockchip_usb2phy_power_on,
|
||||
.power_off = rockchip_usb2phy_power_off,
|
||||
.owner = THIS_MODULE,
|
||||
};
|
||||
|
||||
/*
|
||||
* The function manage host-phy port state and suspend/resume phy port
|
||||
* to save power.
|
||||
*
|
||||
* we rely on utmi_linestate and utmi_hostdisconnect to identify whether
|
||||
* devices is disconnect or not. Besides, we do not need care it is FS/LS
|
||||
* disconnected or HS disconnected, actually, we just only need get the
|
||||
* device is disconnected at last through rearm the delayed work,
|
||||
* to suspend the phy port in _PHY_STATE_DISCONNECT_ case.
|
||||
*
|
||||
* NOTE: It may invoke *phy_powr_off or *phy_power_on which will invoke
|
||||
* some clk related APIs, so do not invoke it from interrupt context directly.
|
||||
*/
|
||||
static void rockchip_usb2phy_sm_work(struct work_struct *work)
|
||||
{
|
||||
struct rockchip_usb2phy_port *rport =
|
||||
container_of(work, struct rockchip_usb2phy_port, sm_work.work);
|
||||
struct rockchip_usb2phy *rphy = dev_get_drvdata(rport->phy->dev.parent);
|
||||
unsigned int sh = rport->port_cfg->utmi_hstdet.bitend -
|
||||
rport->port_cfg->utmi_hstdet.bitstart + 1;
|
||||
unsigned int ul, uhd, state;
|
||||
unsigned int ul_mask, uhd_mask;
|
||||
int ret;
|
||||
|
||||
mutex_lock(&rport->mutex);
|
||||
|
||||
ret = regmap_read(rphy->grf, rport->port_cfg->utmi_ls.offset, &ul);
|
||||
if (ret < 0)
|
||||
goto next_schedule;
|
||||
|
||||
ret = regmap_read(rphy->grf, rport->port_cfg->utmi_hstdet.offset,
|
||||
&uhd);
|
||||
if (ret < 0)
|
||||
goto next_schedule;
|
||||
|
||||
uhd_mask = GENMASK(rport->port_cfg->utmi_hstdet.bitend,
|
||||
rport->port_cfg->utmi_hstdet.bitstart);
|
||||
ul_mask = GENMASK(rport->port_cfg->utmi_ls.bitend,
|
||||
rport->port_cfg->utmi_ls.bitstart);
|
||||
|
||||
/* stitch on utmi_ls and utmi_hstdet as phy state */
|
||||
state = ((uhd & uhd_mask) >> rport->port_cfg->utmi_hstdet.bitstart) |
|
||||
(((ul & ul_mask) >> rport->port_cfg->utmi_ls.bitstart) << sh);
|
||||
|
||||
switch (state) {
|
||||
case PHY_STATE_HS_ONLINE:
|
||||
dev_dbg(&rport->phy->dev, "HS online\n");
|
||||
break;
|
||||
case PHY_STATE_FS_LS_ONLINE:
|
||||
/*
|
||||
* For FS/LS device, the online state share with connect state
|
||||
* from utmi_ls and utmi_hstdet register, so we distinguish
|
||||
* them via suspended flag.
|
||||
*
|
||||
* Plus, there are two cases, one is D- Line pull-up, and D+
|
||||
* line pull-down, the state is 4; another is D+ line pull-up,
|
||||
* and D- line pull-down, the state is 2.
|
||||
*/
|
||||
if (!rport->suspended) {
|
||||
/* D- line pull-up, D+ line pull-down */
|
||||
dev_dbg(&rport->phy->dev, "FS/LS online\n");
|
||||
break;
|
||||
}
|
||||
/* fall through */
|
||||
case PHY_STATE_CONNECT:
|
||||
if (rport->suspended) {
|
||||
dev_dbg(&rport->phy->dev, "Connected\n");
|
||||
rockchip_usb2phy_power_on(rport->phy);
|
||||
rport->suspended = false;
|
||||
} else {
|
||||
/* D+ line pull-up, D- line pull-down */
|
||||
dev_dbg(&rport->phy->dev, "FS/LS online\n");
|
||||
}
|
||||
break;
|
||||
case PHY_STATE_DISCONNECT:
|
||||
if (!rport->suspended) {
|
||||
dev_dbg(&rport->phy->dev, "Disconnected\n");
|
||||
rockchip_usb2phy_power_off(rport->phy);
|
||||
rport->suspended = true;
|
||||
}
|
||||
|
||||
/*
|
||||
* activate the linestate detection to get the next device
|
||||
* plug-in irq.
|
||||
*/
|
||||
property_enable(rphy, &rport->port_cfg->ls_det_clr, true);
|
||||
property_enable(rphy, &rport->port_cfg->ls_det_en, true);
|
||||
|
||||
/*
|
||||
* we don't need to rearm the delayed work when the phy port
|
||||
* is suspended.
|
||||
*/
|
||||
mutex_unlock(&rport->mutex);
|
||||
return;
|
||||
default:
|
||||
dev_dbg(&rport->phy->dev, "unknown phy state\n");
|
||||
break;
|
||||
}
|
||||
|
||||
next_schedule:
|
||||
mutex_unlock(&rport->mutex);
|
||||
schedule_delayed_work(&rport->sm_work, SCHEDULE_DELAY);
|
||||
}
|
||||
|
||||
static irqreturn_t rockchip_usb2phy_linestate_irq(int irq, void *data)
|
||||
{
|
||||
struct rockchip_usb2phy_port *rport = data;
|
||||
struct rockchip_usb2phy *rphy = dev_get_drvdata(rport->phy->dev.parent);
|
||||
|
||||
if (!property_enabled(rphy, &rport->port_cfg->ls_det_st))
|
||||
return IRQ_NONE;
|
||||
|
||||
mutex_lock(&rport->mutex);
|
||||
|
||||
/* disable linestate detect irq and clear its status */
|
||||
property_enable(rphy, &rport->port_cfg->ls_det_en, false);
|
||||
property_enable(rphy, &rport->port_cfg->ls_det_clr, true);
|
||||
|
||||
mutex_unlock(&rport->mutex);
|
||||
|
||||
/*
|
||||
* In this case for host phy port, a new device is plugged in,
|
||||
* meanwhile, if the phy port is suspended, we need rearm the work to
|
||||
* resume it and mange its states; otherwise, we do nothing about that.
|
||||
*/
|
||||
if (rport->suspended && rport->port_id == USB2PHY_PORT_HOST)
|
||||
rockchip_usb2phy_sm_work(&rport->sm_work.work);
|
||||
|
||||
return IRQ_HANDLED;
|
||||
}
|
||||
|
||||
static int rockchip_usb2phy_host_port_init(struct rockchip_usb2phy *rphy,
|
||||
struct rockchip_usb2phy_port *rport,
|
||||
struct device_node *child_np)
|
||||
{
|
||||
int ret;
|
||||
|
||||
rport->port_id = USB2PHY_PORT_HOST;
|
||||
rport->port_cfg = &rphy->phy_cfg->port_cfgs[USB2PHY_PORT_HOST];
|
||||
rport->suspended = true;
|
||||
|
||||
mutex_init(&rport->mutex);
|
||||
INIT_DELAYED_WORK(&rport->sm_work, rockchip_usb2phy_sm_work);
|
||||
|
||||
rport->ls_irq = of_irq_get_byname(child_np, "linestate");
|
||||
if (rport->ls_irq < 0) {
|
||||
dev_err(rphy->dev, "no linestate irq provided\n");
|
||||
return rport->ls_irq;
|
||||
}
|
||||
|
||||
ret = devm_request_threaded_irq(rphy->dev, rport->ls_irq, NULL,
|
||||
rockchip_usb2phy_linestate_irq,
|
||||
IRQF_ONESHOT,
|
||||
"rockchip_usb2phy", rport);
|
||||
if (ret) {
|
||||
dev_err(rphy->dev, "failed to request irq handle\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rockchip_usb2phy_probe(struct platform_device *pdev)
|
||||
{
|
||||
struct device *dev = &pdev->dev;
|
||||
struct device_node *np = dev->of_node;
|
||||
struct device_node *child_np;
|
||||
struct phy_provider *provider;
|
||||
struct rockchip_usb2phy *rphy;
|
||||
const struct rockchip_usb2phy_cfg *phy_cfgs;
|
||||
const struct of_device_id *match;
|
||||
unsigned int reg;
|
||||
int index, ret;
|
||||
|
||||
rphy = devm_kzalloc(dev, sizeof(*rphy), GFP_KERNEL);
|
||||
if (!rphy)
|
||||
return -ENOMEM;
|
||||
|
||||
match = of_match_device(dev->driver->of_match_table, dev);
|
||||
if (!match || !match->data) {
|
||||
dev_err(dev, "phy configs are not assigned!\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (!dev->parent || !dev->parent->of_node)
|
||||
return -EINVAL;
|
||||
|
||||
rphy->grf = syscon_node_to_regmap(dev->parent->of_node);
|
||||
if (IS_ERR(rphy->grf))
|
||||
return PTR_ERR(rphy->grf);
|
||||
|
||||
if (of_property_read_u32(np, "reg", ®)) {
|
||||
dev_err(dev, "the reg property is not assigned in %s node\n",
|
||||
np->name);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
rphy->dev = dev;
|
||||
phy_cfgs = match->data;
|
||||
platform_set_drvdata(pdev, rphy);
|
||||
|
||||
/* find out a proper config which can be matched with dt. */
|
||||
index = 0;
|
||||
while (phy_cfgs[index].reg) {
|
||||
if (phy_cfgs[index].reg == reg) {
|
||||
rphy->phy_cfg = &phy_cfgs[index];
|
||||
break;
|
||||
}
|
||||
|
||||
++index;
|
||||
}
|
||||
|
||||
if (!rphy->phy_cfg) {
|
||||
dev_err(dev, "no phy-config can be matched with %s node\n",
|
||||
np->name);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
rphy->clk = of_clk_get_by_name(np, "phyclk");
|
||||
if (!IS_ERR(rphy->clk)) {
|
||||
clk_prepare_enable(rphy->clk);
|
||||
} else {
|
||||
dev_info(&pdev->dev, "no phyclk specified\n");
|
||||
rphy->clk = NULL;
|
||||
}
|
||||
|
||||
ret = rockchip_usb2phy_clk480m_register(rphy);
|
||||
if (ret) {
|
||||
dev_err(dev, "failed to register 480m output clock\n");
|
||||
goto disable_clks;
|
||||
}
|
||||
|
||||
index = 0;
|
||||
for_each_available_child_of_node(np, child_np) {
|
||||
struct rockchip_usb2phy_port *rport = &rphy->ports[index];
|
||||
struct phy *phy;
|
||||
|
||||
/*
|
||||
* This driver aim to support both otg-port and host-port,
|
||||
* but unfortunately, the otg part is not ready in current,
|
||||
* so this comments and below codes are interim, which should
|
||||
* be changed after otg-port is supplied soon.
|
||||
*/
|
||||
if (of_node_cmp(child_np->name, "host-port"))
|
||||
goto next_child;
|
||||
|
||||
phy = devm_phy_create(dev, child_np, &rockchip_usb2phy_ops);
|
||||
if (IS_ERR(phy)) {
|
||||
dev_err(dev, "failed to create phy\n");
|
||||
ret = PTR_ERR(phy);
|
||||
goto put_child;
|
||||
}
|
||||
|
||||
rport->phy = phy;
|
||||
phy_set_drvdata(rport->phy, rport);
|
||||
|
||||
ret = rockchip_usb2phy_host_port_init(rphy, rport, child_np);
|
||||
if (ret)
|
||||
goto put_child;
|
||||
|
||||
next_child:
|
||||
/* to prevent out of boundary */
|
||||
if (++index >= rphy->phy_cfg->num_ports)
|
||||
break;
|
||||
}
|
||||
|
||||
provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
|
||||
return PTR_ERR_OR_ZERO(provider);
|
||||
|
||||
put_child:
|
||||
of_node_put(child_np);
|
||||
disable_clks:
|
||||
if (rphy->clk) {
|
||||
clk_disable_unprepare(rphy->clk);
|
||||
clk_put(rphy->clk);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static const struct rockchip_usb2phy_cfg rk3366_phy_cfgs[] = {
|
||||
{
|
||||
.reg = 0x700,
|
||||
.num_ports = 2,
|
||||
.clkout_ctl = { 0x0724, 15, 15, 1, 0 },
|
||||
.port_cfgs = {
|
||||
[USB2PHY_PORT_HOST] = {
|
||||
.phy_sus = { 0x0728, 15, 0, 0, 0x1d1 },
|
||||
.ls_det_en = { 0x0680, 4, 4, 0, 1 },
|
||||
.ls_det_st = { 0x0690, 4, 4, 0, 1 },
|
||||
.ls_det_clr = { 0x06a0, 4, 4, 0, 1 },
|
||||
.utmi_ls = { 0x049c, 14, 13, 0, 1 },
|
||||
.utmi_hstdet = { 0x049c, 12, 12, 0, 1 }
|
||||
}
|
||||
},
|
||||
},
|
||||
{ /* sentinel */ }
|
||||
};
|
||||
|
||||
static const struct rockchip_usb2phy_cfg rk3399_phy_cfgs[] = {
|
||||
{
|
||||
.reg = 0xe450,
|
||||
.num_ports = 2,
|
||||
.clkout_ctl = { 0xe450, 4, 4, 1, 0 },
|
||||
.port_cfgs = {
|
||||
[USB2PHY_PORT_HOST] = {
|
||||
.phy_sus = { 0xe458, 1, 0, 0x2, 0x1 },
|
||||
.ls_det_en = { 0xe3c0, 6, 6, 0, 1 },
|
||||
.ls_det_st = { 0xe3e0, 6, 6, 0, 1 },
|
||||
.ls_det_clr = { 0xe3d0, 6, 6, 0, 1 },
|
||||
.utmi_ls = { 0xe2ac, 22, 21, 0, 1 },
|
||||
.utmi_hstdet = { 0xe2ac, 23, 23, 0, 1 }
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
.reg = 0xe460,
|
||||
.num_ports = 2,
|
||||
.clkout_ctl = { 0xe460, 4, 4, 1, 0 },
|
||||
.port_cfgs = {
|
||||
[USB2PHY_PORT_HOST] = {
|
||||
.phy_sus = { 0xe468, 1, 0, 0x2, 0x1 },
|
||||
.ls_det_en = { 0xe3c0, 11, 11, 0, 1 },
|
||||
.ls_det_st = { 0xe3e0, 11, 11, 0, 1 },
|
||||
.ls_det_clr = { 0xe3d0, 11, 11, 0, 1 },
|
||||
.utmi_ls = { 0xe2ac, 26, 25, 0, 1 },
|
||||
.utmi_hstdet = { 0xe2ac, 27, 27, 0, 1 }
|
||||
}
|
||||
},
|
||||
},
|
||||
{ /* sentinel */ }
|
||||
};
|
||||
|
||||
static const struct of_device_id rockchip_usb2phy_dt_match[] = {
|
||||
{ .compatible = "rockchip,rk3366-usb2phy", .data = &rk3366_phy_cfgs },
|
||||
{ .compatible = "rockchip,rk3399-usb2phy", .data = &rk3399_phy_cfgs },
|
||||
{}
|
||||
};
|
||||
MODULE_DEVICE_TABLE(of, rockchip_usb2phy_dt_match);
|
||||
|
||||
static struct platform_driver rockchip_usb2phy_driver = {
|
||||
.probe = rockchip_usb2phy_probe,
|
||||
.driver = {
|
||||
.name = "rockchip-usb2phy",
|
||||
.of_match_table = rockchip_usb2phy_dt_match,
|
||||
},
|
||||
};
|
||||
module_platform_driver(rockchip_usb2phy_driver);
|
||||
|
||||
MODULE_AUTHOR("Frank Wang <frank.wang@rock-chips.com>");
|
||||
MODULE_DESCRIPTION("Rockchip USB2.0 PHY driver");
|
||||
MODULE_LICENSE("GPL v2");
|
357
drivers/phy/phy-rockchip-pcie.c
Normal file
357
drivers/phy/phy-rockchip-pcie.c
Normal file
@ -0,0 +1,357 @@
|
||||
/*
|
||||
* Rockchip PCIe PHY driver
|
||||
*
|
||||
* Copyright (C) 2016 Shawn Lin <shawn.lin@rock-chips.com>
|
||||
* Copyright (C) 2016 ROCKCHIP, Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include <linux/clk.h>
|
||||
#include <linux/delay.h>
|
||||
#include <linux/io.h>
|
||||
#include <linux/mfd/syscon.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/of.h>
|
||||
#include <linux/of_address.h>
|
||||
#include <linux/of_platform.h>
|
||||
#include <linux/phy/phy.h>
|
||||
#include <linux/platform_device.h>
|
||||
#include <linux/regmap.h>
|
||||
#include <linux/reset.h>
|
||||
|
||||
/*
|
||||
* The higher 16-bit of this register is used for write protection
|
||||
* only if BIT(x + 16) set to 1 the BIT(x) can be written.
|
||||
*/
|
||||
#define HIWORD_UPDATE(val, mask, shift) \
|
||||
((val) << (shift) | (mask) << ((shift) + 16))
|
||||
|
||||
#define PHY_MAX_LANE_NUM 4
|
||||
#define PHY_CFG_DATA_SHIFT 7
|
||||
#define PHY_CFG_ADDR_SHIFT 1
|
||||
#define PHY_CFG_DATA_MASK 0xf
|
||||
#define PHY_CFG_ADDR_MASK 0x3f
|
||||
#define PHY_CFG_RD_MASK 0x3ff
|
||||
#define PHY_CFG_WR_ENABLE 1
|
||||
#define PHY_CFG_WR_DISABLE 1
|
||||
#define PHY_CFG_WR_SHIFT 0
|
||||
#define PHY_CFG_WR_MASK 1
|
||||
#define PHY_CFG_PLL_LOCK 0x10
|
||||
#define PHY_CFG_CLK_TEST 0x10
|
||||
#define PHY_CFG_CLK_SCC 0x12
|
||||
#define PHY_CFG_SEPE_RATE BIT(3)
|
||||
#define PHY_CFG_PLL_100M BIT(3)
|
||||
#define PHY_PLL_LOCKED BIT(9)
|
||||
#define PHY_PLL_OUTPUT BIT(10)
|
||||
#define PHY_LANE_A_STATUS 0x30
|
||||
#define PHY_LANE_B_STATUS 0x31
|
||||
#define PHY_LANE_C_STATUS 0x32
|
||||
#define PHY_LANE_D_STATUS 0x33
|
||||
#define PHY_LANE_RX_DET_SHIFT 11
|
||||
#define PHY_LANE_RX_DET_TH 0x1
|
||||
#define PHY_LANE_IDLE_OFF 0x1
|
||||
#define PHY_LANE_IDLE_MASK 0x1
|
||||
#define PHY_LANE_IDLE_A_SHIFT 3
|
||||
#define PHY_LANE_IDLE_B_SHIFT 4
|
||||
#define PHY_LANE_IDLE_C_SHIFT 5
|
||||
#define PHY_LANE_IDLE_D_SHIFT 6
|
||||
|
||||
struct rockchip_pcie_data {
|
||||
unsigned int pcie_conf;
|
||||
unsigned int pcie_status;
|
||||
unsigned int pcie_laneoff;
|
||||
};
|
||||
|
||||
struct rockchip_pcie_phy {
|
||||
struct rockchip_pcie_data *phy_data;
|
||||
struct regmap *reg_base;
|
||||
struct reset_control *phy_rst;
|
||||
struct clk *clk_pciephy_ref;
|
||||
};
|
||||
|
||||
static inline void phy_wr_cfg(struct rockchip_pcie_phy *rk_phy,
|
||||
u32 addr, u32 data)
|
||||
{
|
||||
regmap_write(rk_phy->reg_base, rk_phy->phy_data->pcie_conf,
|
||||
HIWORD_UPDATE(data,
|
||||
PHY_CFG_DATA_MASK,
|
||||
PHY_CFG_DATA_SHIFT) |
|
||||
HIWORD_UPDATE(addr,
|
||||
PHY_CFG_ADDR_MASK,
|
||||
PHY_CFG_ADDR_SHIFT));
|
||||
udelay(1);
|
||||
regmap_write(rk_phy->reg_base, rk_phy->phy_data->pcie_conf,
|
||||
HIWORD_UPDATE(PHY_CFG_WR_ENABLE,
|
||||
PHY_CFG_WR_MASK,
|
||||
PHY_CFG_WR_SHIFT));
|
||||
udelay(1);
|
||||
regmap_write(rk_phy->reg_base, rk_phy->phy_data->pcie_conf,
|
||||
HIWORD_UPDATE(PHY_CFG_WR_DISABLE,
|
||||
PHY_CFG_WR_MASK,
|
||||
PHY_CFG_WR_SHIFT));
|
||||
}
|
||||
|
||||
static inline u32 phy_rd_cfg(struct rockchip_pcie_phy *rk_phy,
|
||||
u32 addr)
|
||||
{
|
||||
u32 val;
|
||||
|
||||
regmap_write(rk_phy->reg_base, rk_phy->phy_data->pcie_conf,
|
||||
HIWORD_UPDATE(addr,
|
||||
PHY_CFG_RD_MASK,
|
||||
PHY_CFG_ADDR_SHIFT));
|
||||
regmap_read(rk_phy->reg_base,
|
||||
rk_phy->phy_data->pcie_status,
|
||||
&val);
|
||||
return val;
|
||||
}
|
||||
|
||||
static int rockchip_pcie_phy_power_off(struct phy *phy)
|
||||
{
|
||||
struct rockchip_pcie_phy *rk_phy = phy_get_drvdata(phy);
|
||||
int err = 0;
|
||||
|
||||
err = reset_control_assert(rk_phy->phy_rst);
|
||||
if (err) {
|
||||
dev_err(&phy->dev, "assert phy_rst err %d\n", err);
|
||||
return err;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rockchip_pcie_phy_power_on(struct phy *phy)
|
||||
{
|
||||
struct rockchip_pcie_phy *rk_phy = phy_get_drvdata(phy);
|
||||
int err = 0;
|
||||
u32 status;
|
||||
unsigned long timeout;
|
||||
|
||||
err = reset_control_deassert(rk_phy->phy_rst);
|
||||
if (err) {
|
||||
dev_err(&phy->dev, "deassert phy_rst err %d\n", err);
|
||||
return err;
|
||||
}
|
||||
|
||||
regmap_write(rk_phy->reg_base, rk_phy->phy_data->pcie_conf,
|
||||
HIWORD_UPDATE(PHY_CFG_PLL_LOCK,
|
||||
PHY_CFG_ADDR_MASK,
|
||||
PHY_CFG_ADDR_SHIFT));
|
||||
|
||||
/*
|
||||
* No documented timeout value for phy operation below,
|
||||
* so we make it large enough here. And we use loop-break
|
||||
* method which should not be harmful.
|
||||
*/
|
||||
timeout = jiffies + msecs_to_jiffies(1000);
|
||||
|
||||
err = -EINVAL;
|
||||
while (time_before(jiffies, timeout)) {
|
||||
regmap_read(rk_phy->reg_base,
|
||||
rk_phy->phy_data->pcie_status,
|
||||
&status);
|
||||
if (status & PHY_PLL_LOCKED) {
|
||||
dev_dbg(&phy->dev, "pll locked!\n");
|
||||
err = 0;
|
||||
break;
|
||||
}
|
||||
msleep(20);
|
||||
}
|
||||
|
||||
if (err) {
|
||||
dev_err(&phy->dev, "pll lock timeout!\n");
|
||||
goto err_pll_lock;
|
||||
}
|
||||
|
||||
phy_wr_cfg(rk_phy, PHY_CFG_CLK_TEST, PHY_CFG_SEPE_RATE);
|
||||
phy_wr_cfg(rk_phy, PHY_CFG_CLK_SCC, PHY_CFG_PLL_100M);
|
||||
|
||||
err = -ETIMEDOUT;
|
||||
while (time_before(jiffies, timeout)) {
|
||||
regmap_read(rk_phy->reg_base,
|
||||
rk_phy->phy_data->pcie_status,
|
||||
&status);
|
||||
if (!(status & PHY_PLL_OUTPUT)) {
|
||||
dev_dbg(&phy->dev, "pll output enable done!\n");
|
||||
err = 0;
|
||||
break;
|
||||
}
|
||||
msleep(20);
|
||||
}
|
||||
|
||||
if (err) {
|
||||
dev_err(&phy->dev, "pll output enable timeout!\n");
|
||||
goto err_pll_lock;
|
||||
}
|
||||
|
||||
regmap_write(rk_phy->reg_base, rk_phy->phy_data->pcie_conf,
|
||||
HIWORD_UPDATE(PHY_CFG_PLL_LOCK,
|
||||
PHY_CFG_ADDR_MASK,
|
||||
PHY_CFG_ADDR_SHIFT));
|
||||
err = -EINVAL;
|
||||
while (time_before(jiffies, timeout)) {
|
||||
regmap_read(rk_phy->reg_base,
|
||||
rk_phy->phy_data->pcie_status,
|
||||
&status);
|
||||
if (status & PHY_PLL_LOCKED) {
|
||||
dev_dbg(&phy->dev, "pll relocked!\n");
|
||||
err = 0;
|
||||
break;
|
||||
}
|
||||
msleep(20);
|
||||
}
|
||||
|
||||
if (err) {
|
||||
dev_err(&phy->dev, "pll relock timeout!\n");
|
||||
goto err_pll_lock;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
err_pll_lock:
|
||||
reset_control_assert(rk_phy->phy_rst);
|
||||
return err;
|
||||
}
|
||||
|
||||
static int rockchip_pcie_phy_init(struct phy *phy)
|
||||
{
|
||||
struct rockchip_pcie_phy *rk_phy = phy_get_drvdata(phy);
|
||||
int err = 0;
|
||||
|
||||
err = clk_prepare_enable(rk_phy->clk_pciephy_ref);
|
||||
if (err) {
|
||||
dev_err(&phy->dev, "Fail to enable pcie ref clock.\n");
|
||||
goto err_refclk;
|
||||
}
|
||||
|
||||
err = reset_control_assert(rk_phy->phy_rst);
|
||||
if (err) {
|
||||
dev_err(&phy->dev, "assert phy_rst err %d\n", err);
|
||||
goto err_reset;
|
||||
}
|
||||
|
||||
return err;
|
||||
|
||||
err_reset:
|
||||
clk_disable_unprepare(rk_phy->clk_pciephy_ref);
|
||||
err_refclk:
|
||||
return err;
|
||||
}
|
||||
|
||||
static int rockchip_pcie_phy_exit(struct phy *phy)
|
||||
{
|
||||
struct rockchip_pcie_phy *rk_phy = phy_get_drvdata(phy);
|
||||
int err = 0;
|
||||
|
||||
clk_disable_unprepare(rk_phy->clk_pciephy_ref);
|
||||
|
||||
err = reset_control_deassert(rk_phy->phy_rst);
|
||||
if (err) {
|
||||
dev_err(&phy->dev, "deassert phy_rst err %d\n", err);
|
||||
goto err_reset;
|
||||
}
|
||||
|
||||
return err;
|
||||
|
||||
err_reset:
|
||||
clk_prepare_enable(rk_phy->clk_pciephy_ref);
|
||||
return err;
|
||||
}
|
||||
|
||||
static const struct phy_ops ops = {
|
||||
.init = rockchip_pcie_phy_init,
|
||||
.exit = rockchip_pcie_phy_exit,
|
||||
.power_on = rockchip_pcie_phy_power_on,
|
||||
.power_off = rockchip_pcie_phy_power_off,
|
||||
.owner = THIS_MODULE,
|
||||
};
|
||||
|
||||
static const struct rockchip_pcie_data rk3399_pcie_data = {
|
||||
.pcie_conf = 0xe220,
|
||||
.pcie_status = 0xe2a4,
|
||||
.pcie_laneoff = 0xe214,
|
||||
};
|
||||
|
||||
static const struct of_device_id rockchip_pcie_phy_dt_ids[] = {
|
||||
{
|
||||
.compatible = "rockchip,rk3399-pcie-phy",
|
||||
.data = &rk3399_pcie_data,
|
||||
},
|
||||
{}
|
||||
};
|
||||
|
||||
MODULE_DEVICE_TABLE(of, rockchip_pcie_phy_dt_ids);
|
||||
|
||||
static int rockchip_pcie_phy_probe(struct platform_device *pdev)
|
||||
{
|
||||
struct device *dev = &pdev->dev;
|
||||
struct rockchip_pcie_phy *rk_phy;
|
||||
struct phy *generic_phy;
|
||||
struct phy_provider *phy_provider;
|
||||
struct regmap *grf;
|
||||
const struct of_device_id *of_id;
|
||||
|
||||
grf = syscon_node_to_regmap(dev->parent->of_node);
|
||||
if (IS_ERR(grf)) {
|
||||
dev_err(dev, "Cannot find GRF syscon\n");
|
||||
return PTR_ERR(grf);
|
||||
}
|
||||
|
||||
rk_phy = devm_kzalloc(dev, sizeof(*rk_phy), GFP_KERNEL);
|
||||
if (!rk_phy)
|
||||
return -ENOMEM;
|
||||
|
||||
of_id = of_match_device(rockchip_pcie_phy_dt_ids, &pdev->dev);
|
||||
if (!of_id)
|
||||
return -EINVAL;
|
||||
|
||||
rk_phy->phy_data = (struct rockchip_pcie_data *)of_id->data;
|
||||
rk_phy->reg_base = grf;
|
||||
|
||||
rk_phy->phy_rst = devm_reset_control_get(dev, "phy");
|
||||
if (IS_ERR(rk_phy->phy_rst)) {
|
||||
if (PTR_ERR(rk_phy->phy_rst) != -EPROBE_DEFER)
|
||||
dev_err(dev,
|
||||
"missing phy property for reset controller\n");
|
||||
return PTR_ERR(rk_phy->phy_rst);
|
||||
}
|
||||
|
||||
rk_phy->clk_pciephy_ref = devm_clk_get(dev, "refclk");
|
||||
if (IS_ERR(rk_phy->clk_pciephy_ref)) {
|
||||
dev_err(dev, "refclk not found.\n");
|
||||
return PTR_ERR(rk_phy->clk_pciephy_ref);
|
||||
}
|
||||
|
||||
generic_phy = devm_phy_create(dev, dev->of_node, &ops);
|
||||
if (IS_ERR(generic_phy)) {
|
||||
dev_err(dev, "failed to create PHY\n");
|
||||
return PTR_ERR(generic_phy);
|
||||
}
|
||||
|
||||
phy_set_drvdata(generic_phy, rk_phy);
|
||||
phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
|
||||
|
||||
return PTR_ERR_OR_ZERO(phy_provider);
|
||||
}
|
||||
|
||||
static struct platform_driver rockchip_pcie_driver = {
|
||||
.probe = rockchip_pcie_phy_probe,
|
||||
.driver = {
|
||||
.name = "rockchip-pcie-phy",
|
||||
.of_match_table = rockchip_pcie_phy_dt_ids,
|
||||
},
|
||||
};
|
||||
|
||||
module_platform_driver(rockchip_pcie_driver);
|
||||
|
||||
MODULE_AUTHOR("Shawn Lin <shawn.lin@rock-chips.com>");
|
||||
MODULE_DESCRIPTION("Rockchip PCIe PHY driver");
|
||||
MODULE_LICENSE("GPL v2");
|
1023
drivers/phy/phy-rockchip-typec.c
Normal file
1023
drivers/phy/phy-rockchip-typec.c
Normal file
File diff suppressed because it is too large
Load Diff
@ -29,6 +29,7 @@
|
||||
#include <linux/reset.h>
|
||||
#include <linux/regmap.h>
|
||||
#include <linux/mfd/syscon.h>
|
||||
#include <linux/delay.h>
|
||||
|
||||
static int enable_usb_uart;
|
||||
|
||||
@ -64,6 +65,7 @@ struct rockchip_usb_phy {
|
||||
struct clk_hw clk480m_hw;
|
||||
struct phy *phy;
|
||||
bool uart_enabled;
|
||||
struct reset_control *reset;
|
||||
};
|
||||
|
||||
static int rockchip_usb_phy_power(struct rockchip_usb_phy *phy,
|
||||
@ -144,9 +146,23 @@ static int rockchip_usb_phy_power_on(struct phy *_phy)
|
||||
return clk_prepare_enable(phy->clk480m);
|
||||
}
|
||||
|
||||
static int rockchip_usb_phy_reset(struct phy *_phy)
|
||||
{
|
||||
struct rockchip_usb_phy *phy = phy_get_drvdata(_phy);
|
||||
|
||||
if (phy->reset) {
|
||||
reset_control_assert(phy->reset);
|
||||
udelay(10);
|
||||
reset_control_deassert(phy->reset);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct phy_ops ops = {
|
||||
.power_on = rockchip_usb_phy_power_on,
|
||||
.power_off = rockchip_usb_phy_power_off,
|
||||
.reset = rockchip_usb_phy_reset,
|
||||
.owner = THIS_MODULE,
|
||||
};
|
||||
|
||||
@ -185,6 +201,10 @@ static int rockchip_usb_phy_init(struct rockchip_usb_phy_base *base,
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
rk_phy->reset = of_reset_control_get(child, "phy-reset");
|
||||
if (IS_ERR(rk_phy->reset))
|
||||
rk_phy->reset = NULL;
|
||||
|
||||
rk_phy->reg_offset = reg_offset;
|
||||
|
||||
rk_phy->clk = of_clk_get_by_name(child, "phyclk");
|
||||
|
@ -40,6 +40,7 @@
|
||||
#include <linux/power_supply.h>
|
||||
#include <linux/regulator/consumer.h>
|
||||
#include <linux/reset.h>
|
||||
#include <linux/spinlock.h>
|
||||
#include <linux/usb/of.h>
|
||||
#include <linux/workqueue.h>
|
||||
|
||||
@ -50,7 +51,7 @@
|
||||
#define REG_PHYCTL_A33 0x10
|
||||
#define REG_PHY_UNK_H3 0x20
|
||||
|
||||
#define REG_PMU_UNK_H3 0x10
|
||||
#define REG_PMU_UNK1 0x10
|
||||
|
||||
#define PHYCTL_DATA BIT(7)
|
||||
|
||||
@ -98,6 +99,7 @@ enum sun4i_usb_phy_type {
|
||||
sun6i_a31_phy,
|
||||
sun8i_a33_phy,
|
||||
sun8i_h3_phy,
|
||||
sun50i_a64_phy,
|
||||
};
|
||||
|
||||
struct sun4i_usb_phy_cfg {
|
||||
@ -106,13 +108,14 @@ struct sun4i_usb_phy_cfg {
|
||||
u32 disc_thresh;
|
||||
u8 phyctl_offset;
|
||||
bool dedicated_clocks;
|
||||
bool enable_pmu_unk1;
|
||||
};
|
||||
|
||||
struct sun4i_usb_phy_data {
|
||||
void __iomem *base;
|
||||
const struct sun4i_usb_phy_cfg *cfg;
|
||||
enum usb_dr_mode dr_mode;
|
||||
struct mutex mutex;
|
||||
spinlock_t reg_lock; /* guard access to phyctl reg */
|
||||
struct sun4i_usb_phy {
|
||||
struct phy *phy;
|
||||
void __iomem *pmu;
|
||||
@ -122,7 +125,6 @@ struct sun4i_usb_phy_data {
|
||||
bool regulator_on;
|
||||
int index;
|
||||
} phys[MAX_PHYS];
|
||||
int first_phy;
|
||||
/* phy0 / otg related variables */
|
||||
struct extcon_dev *extcon;
|
||||
bool phy0_init;
|
||||
@ -131,6 +133,7 @@ struct sun4i_usb_phy_data {
|
||||
struct power_supply *vbus_power_supply;
|
||||
struct notifier_block vbus_power_nb;
|
||||
bool vbus_power_nb_registered;
|
||||
bool force_session_end;
|
||||
int id_det_irq;
|
||||
int vbus_det_irq;
|
||||
int id_det;
|
||||
@ -179,12 +182,14 @@ static void sun4i_usb_phy_write(struct sun4i_usb_phy *phy, u32 addr, u32 data,
|
||||
struct sun4i_usb_phy_data *phy_data = to_sun4i_usb_phy_data(phy);
|
||||
u32 temp, usbc_bit = BIT(phy->index * 2);
|
||||
void __iomem *phyctl = phy_data->base + phy_data->cfg->phyctl_offset;
|
||||
unsigned long flags;
|
||||
int i;
|
||||
|
||||
mutex_lock(&phy_data->mutex);
|
||||
spin_lock_irqsave(&phy_data->reg_lock, flags);
|
||||
|
||||
if (phy_data->cfg->type == sun8i_a33_phy) {
|
||||
/* A33 needs us to set phyctl to 0 explicitly */
|
||||
if (phy_data->cfg->type == sun8i_a33_phy ||
|
||||
phy_data->cfg->type == sun50i_a64_phy) {
|
||||
/* A33 or A64 needs us to set phyctl to 0 explicitly */
|
||||
writel(0, phyctl);
|
||||
}
|
||||
|
||||
@ -218,7 +223,8 @@ static void sun4i_usb_phy_write(struct sun4i_usb_phy *phy, u32 addr, u32 data,
|
||||
|
||||
data >>= 1;
|
||||
}
|
||||
mutex_unlock(&phy_data->mutex);
|
||||
|
||||
spin_unlock_irqrestore(&phy_data->reg_lock, flags);
|
||||
}
|
||||
|
||||
static void sun4i_usb_phy_passby(struct sun4i_usb_phy *phy, int enable)
|
||||
@ -258,14 +264,16 @@ static int sun4i_usb_phy_init(struct phy *_phy)
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (data->cfg->enable_pmu_unk1) {
|
||||
val = readl(phy->pmu + REG_PMU_UNK1);
|
||||
writel(val & ~2, phy->pmu + REG_PMU_UNK1);
|
||||
}
|
||||
|
||||
if (data->cfg->type == sun8i_h3_phy) {
|
||||
if (phy->index == 0) {
|
||||
val = readl(data->base + REG_PHY_UNK_H3);
|
||||
writel(val & ~1, data->base + REG_PHY_UNK_H3);
|
||||
}
|
||||
|
||||
val = readl(phy->pmu + REG_PMU_UNK_H3);
|
||||
writel(val & ~2, phy->pmu + REG_PMU_UNK_H3);
|
||||
} else {
|
||||
/* Enable USB 45 Ohm resistor calibration */
|
||||
if (phy->index == 0)
|
||||
@ -320,7 +328,10 @@ static int sun4i_usb_phy0_get_id_det(struct sun4i_usb_phy_data *data)
|
||||
{
|
||||
switch (data->dr_mode) {
|
||||
case USB_DR_MODE_OTG:
|
||||
return gpiod_get_value_cansleep(data->id_det_gpio);
|
||||
if (data->id_det_gpio)
|
||||
return gpiod_get_value_cansleep(data->id_det_gpio);
|
||||
else
|
||||
return 1; /* Fallback to peripheral mode */
|
||||
case USB_DR_MODE_HOST:
|
||||
return 0;
|
||||
case USB_DR_MODE_PERIPHERAL:
|
||||
@ -382,8 +393,10 @@ static int sun4i_usb_phy_power_on(struct phy *_phy)
|
||||
|
||||
/* For phy0 only turn on Vbus if we don't have an ext. Vbus */
|
||||
if (phy->index == 0 && sun4i_usb_phy0_have_vbus_det(data) &&
|
||||
data->vbus_det)
|
||||
data->vbus_det) {
|
||||
dev_warn(&_phy->dev, "External vbus detected, not enabling our own vbus\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
ret = regulator_enable(phy->vbus);
|
||||
if (ret)
|
||||
@ -419,6 +432,35 @@ static int sun4i_usb_phy_power_off(struct phy *_phy)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int sun4i_usb_phy_set_mode(struct phy *_phy, enum phy_mode mode)
|
||||
{
|
||||
struct sun4i_usb_phy *phy = phy_get_drvdata(_phy);
|
||||
struct sun4i_usb_phy_data *data = to_sun4i_usb_phy_data(phy);
|
||||
|
||||
if (phy->index != 0)
|
||||
return -EINVAL;
|
||||
|
||||
switch (mode) {
|
||||
case PHY_MODE_USB_HOST:
|
||||
data->dr_mode = USB_DR_MODE_HOST;
|
||||
break;
|
||||
case PHY_MODE_USB_DEVICE:
|
||||
data->dr_mode = USB_DR_MODE_PERIPHERAL;
|
||||
break;
|
||||
case PHY_MODE_USB_OTG:
|
||||
data->dr_mode = USB_DR_MODE_OTG;
|
||||
break;
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
dev_info(&_phy->dev, "Changing dr_mode to %d\n", (int)data->dr_mode);
|
||||
data->force_session_end = true;
|
||||
queue_delayed_work(system_wq, &data->detect, 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void sun4i_usb_phy_set_squelch_detect(struct phy *_phy, bool enabled)
|
||||
{
|
||||
struct sun4i_usb_phy *phy = phy_get_drvdata(_phy);
|
||||
@ -432,6 +474,7 @@ static const struct phy_ops sun4i_usb_phy_ops = {
|
||||
.exit = sun4i_usb_phy_exit,
|
||||
.power_on = sun4i_usb_phy_power_on,
|
||||
.power_off = sun4i_usb_phy_power_off,
|
||||
.set_mode = sun4i_usb_phy_set_mode,
|
||||
.owner = THIS_MODULE,
|
||||
};
|
||||
|
||||
@ -440,7 +483,8 @@ static void sun4i_usb_phy0_id_vbus_det_scan(struct work_struct *work)
|
||||
struct sun4i_usb_phy_data *data =
|
||||
container_of(work, struct sun4i_usb_phy_data, detect.work);
|
||||
struct phy *phy0 = data->phys[0].phy;
|
||||
int id_det, vbus_det, id_notify = 0, vbus_notify = 0;
|
||||
bool force_session_end, id_notify = false, vbus_notify = false;
|
||||
int id_det, vbus_det;
|
||||
|
||||
if (phy0 == NULL)
|
||||
return;
|
||||
@ -455,27 +499,30 @@ static void sun4i_usb_phy0_id_vbus_det_scan(struct work_struct *work)
|
||||
return;
|
||||
}
|
||||
|
||||
force_session_end = data->force_session_end;
|
||||
data->force_session_end = false;
|
||||
|
||||
if (id_det != data->id_det) {
|
||||
/*
|
||||
* When a host cable (id == 0) gets plugged in on systems
|
||||
* without vbus detection report vbus low for long enough for
|
||||
* the musb-ip to end the current device session.
|
||||
*/
|
||||
/* id-change, force session end if we've no vbus detection */
|
||||
if (data->dr_mode == USB_DR_MODE_OTG &&
|
||||
!sun4i_usb_phy0_have_vbus_det(data) && id_det == 0) {
|
||||
!sun4i_usb_phy0_have_vbus_det(data))
|
||||
force_session_end = true;
|
||||
|
||||
/* When entering host mode (id = 0) force end the session now */
|
||||
if (force_session_end && id_det == 0) {
|
||||
sun4i_usb_phy0_set_vbus_detect(phy0, 0);
|
||||
msleep(200);
|
||||
sun4i_usb_phy0_set_vbus_detect(phy0, 1);
|
||||
}
|
||||
sun4i_usb_phy0_set_id_detect(phy0, id_det);
|
||||
data->id_det = id_det;
|
||||
id_notify = 1;
|
||||
id_notify = true;
|
||||
}
|
||||
|
||||
if (vbus_det != data->vbus_det) {
|
||||
sun4i_usb_phy0_set_vbus_detect(phy0, vbus_det);
|
||||
data->vbus_det = vbus_det;
|
||||
vbus_notify = 1;
|
||||
vbus_notify = true;
|
||||
}
|
||||
|
||||
mutex_unlock(&phy0->mutex);
|
||||
@ -483,13 +530,8 @@ static void sun4i_usb_phy0_id_vbus_det_scan(struct work_struct *work)
|
||||
if (id_notify) {
|
||||
extcon_set_cable_state_(data->extcon, EXTCON_USB_HOST,
|
||||
!id_det);
|
||||
/*
|
||||
* When a host cable gets unplugged (id == 1) on systems
|
||||
* without vbus detection report vbus low for long enough to
|
||||
* the musb-ip to end the current host session.
|
||||
*/
|
||||
if (data->dr_mode == USB_DR_MODE_OTG &&
|
||||
!sun4i_usb_phy0_have_vbus_det(data) && id_det == 1) {
|
||||
/* When leaving host mode force end the session here */
|
||||
if (force_session_end && id_det == 1) {
|
||||
mutex_lock(&phy0->mutex);
|
||||
sun4i_usb_phy0_set_vbus_detect(phy0, 0);
|
||||
msleep(1000);
|
||||
@ -534,8 +576,7 @@ static struct phy *sun4i_usb_phy_xlate(struct device *dev,
|
||||
{
|
||||
struct sun4i_usb_phy_data *data = dev_get_drvdata(dev);
|
||||
|
||||
if (args->args[0] < data->first_phy ||
|
||||
args->args[0] >= data->cfg->num_phys)
|
||||
if (args->args[0] >= data->cfg->num_phys)
|
||||
return ERR_PTR(-ENODEV);
|
||||
|
||||
return data->phys[args->args[0]].phy;
|
||||
@ -577,7 +618,7 @@ static int sun4i_usb_phy_probe(struct platform_device *pdev)
|
||||
if (!data)
|
||||
return -ENOMEM;
|
||||
|
||||
mutex_init(&data->mutex);
|
||||
spin_lock_init(&data->reg_lock);
|
||||
INIT_DELAYED_WORK(&data->detect, sun4i_usb_phy0_id_vbus_det_scan);
|
||||
dev_set_drvdata(dev, data);
|
||||
data->cfg = of_device_get_match_data(dev);
|
||||
@ -610,33 +651,18 @@ static int sun4i_usb_phy_probe(struct platform_device *pdev)
|
||||
}
|
||||
|
||||
data->dr_mode = of_usb_get_dr_mode_by_phy(np, 0);
|
||||
switch (data->dr_mode) {
|
||||
case USB_DR_MODE_OTG:
|
||||
/* otg without id_det makes no sense, and is not supported */
|
||||
if (!data->id_det_gpio) {
|
||||
dev_err(dev, "usb0_id_det missing or invalid\n");
|
||||
return -ENODEV;
|
||||
}
|
||||
/* fall through */
|
||||
case USB_DR_MODE_HOST:
|
||||
case USB_DR_MODE_PERIPHERAL:
|
||||
data->extcon = devm_extcon_dev_allocate(dev,
|
||||
sun4i_usb_phy0_cable);
|
||||
if (IS_ERR(data->extcon))
|
||||
return PTR_ERR(data->extcon);
|
||||
|
||||
ret = devm_extcon_dev_register(dev, data->extcon);
|
||||
if (ret) {
|
||||
dev_err(dev, "failed to register extcon: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
dev_info(dev, "dr_mode unknown, not registering usb phy0\n");
|
||||
data->first_phy = 1;
|
||||
data->extcon = devm_extcon_dev_allocate(dev, sun4i_usb_phy0_cable);
|
||||
if (IS_ERR(data->extcon))
|
||||
return PTR_ERR(data->extcon);
|
||||
|
||||
ret = devm_extcon_dev_register(dev, data->extcon);
|
||||
if (ret) {
|
||||
dev_err(dev, "failed to register extcon: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
for (i = data->first_phy; i < data->cfg->num_phys; i++) {
|
||||
for (i = 0; i < data->cfg->num_phys; i++) {
|
||||
struct sun4i_usb_phy *phy = data->phys + i;
|
||||
char name[16];
|
||||
|
||||
@ -737,6 +763,7 @@ static const struct sun4i_usb_phy_cfg sun4i_a10_cfg = {
|
||||
.disc_thresh = 3,
|
||||
.phyctl_offset = REG_PHYCTL_A10,
|
||||
.dedicated_clocks = false,
|
||||
.enable_pmu_unk1 = false,
|
||||
};
|
||||
|
||||
static const struct sun4i_usb_phy_cfg sun5i_a13_cfg = {
|
||||
@ -745,6 +772,7 @@ static const struct sun4i_usb_phy_cfg sun5i_a13_cfg = {
|
||||
.disc_thresh = 2,
|
||||
.phyctl_offset = REG_PHYCTL_A10,
|
||||
.dedicated_clocks = false,
|
||||
.enable_pmu_unk1 = false,
|
||||
};
|
||||
|
||||
static const struct sun4i_usb_phy_cfg sun6i_a31_cfg = {
|
||||
@ -753,6 +781,7 @@ static const struct sun4i_usb_phy_cfg sun6i_a31_cfg = {
|
||||
.disc_thresh = 3,
|
||||
.phyctl_offset = REG_PHYCTL_A10,
|
||||
.dedicated_clocks = true,
|
||||
.enable_pmu_unk1 = false,
|
||||
};
|
||||
|
||||
static const struct sun4i_usb_phy_cfg sun7i_a20_cfg = {
|
||||
@ -761,6 +790,7 @@ static const struct sun4i_usb_phy_cfg sun7i_a20_cfg = {
|
||||
.disc_thresh = 2,
|
||||
.phyctl_offset = REG_PHYCTL_A10,
|
||||
.dedicated_clocks = false,
|
||||
.enable_pmu_unk1 = false,
|
||||
};
|
||||
|
||||
static const struct sun4i_usb_phy_cfg sun8i_a23_cfg = {
|
||||
@ -769,6 +799,7 @@ static const struct sun4i_usb_phy_cfg sun8i_a23_cfg = {
|
||||
.disc_thresh = 3,
|
||||
.phyctl_offset = REG_PHYCTL_A10,
|
||||
.dedicated_clocks = true,
|
||||
.enable_pmu_unk1 = false,
|
||||
};
|
||||
|
||||
static const struct sun4i_usb_phy_cfg sun8i_a33_cfg = {
|
||||
@ -777,6 +808,7 @@ static const struct sun4i_usb_phy_cfg sun8i_a33_cfg = {
|
||||
.disc_thresh = 3,
|
||||
.phyctl_offset = REG_PHYCTL_A33,
|
||||
.dedicated_clocks = true,
|
||||
.enable_pmu_unk1 = false,
|
||||
};
|
||||
|
||||
static const struct sun4i_usb_phy_cfg sun8i_h3_cfg = {
|
||||
@ -784,6 +816,16 @@ static const struct sun4i_usb_phy_cfg sun8i_h3_cfg = {
|
||||
.type = sun8i_h3_phy,
|
||||
.disc_thresh = 3,
|
||||
.dedicated_clocks = true,
|
||||
.enable_pmu_unk1 = true,
|
||||
};
|
||||
|
||||
static const struct sun4i_usb_phy_cfg sun50i_a64_cfg = {
|
||||
.num_phys = 2,
|
||||
.type = sun50i_a64_phy,
|
||||
.disc_thresh = 3,
|
||||
.phyctl_offset = REG_PHYCTL_A33,
|
||||
.dedicated_clocks = true,
|
||||
.enable_pmu_unk1 = true,
|
||||
};
|
||||
|
||||
static const struct of_device_id sun4i_usb_phy_of_match[] = {
|
||||
@ -794,6 +836,8 @@ static const struct of_device_id sun4i_usb_phy_of_match[] = {
|
||||
{ .compatible = "allwinner,sun8i-a23-usb-phy", .data = &sun8i_a23_cfg },
|
||||
{ .compatible = "allwinner,sun8i-a33-usb-phy", .data = &sun8i_a33_cfg },
|
||||
{ .compatible = "allwinner,sun8i-h3-usb-phy", .data = &sun8i_h3_cfg },
|
||||
{ .compatible = "allwinner,sun50i-a64-usb-phy",
|
||||
.data = &sun50i_a64_cfg},
|
||||
{ },
|
||||
};
|
||||
MODULE_DEVICE_TABLE(of, sun4i_usb_phy_of_match);
|
||||
|
@ -172,6 +172,7 @@ struct twl4030_usb {
|
||||
int irq;
|
||||
enum musb_vbus_id_status linkstat;
|
||||
bool vbus_supplied;
|
||||
bool musb_mailbox_pending;
|
||||
|
||||
struct delayed_work id_workaround_work;
|
||||
};
|
||||
@ -439,6 +440,17 @@ static int __maybe_unused twl4030_usb_runtime_resume(struct device *dev)
|
||||
(PHY_CLK_CTRL_CLOCKGATING_EN |
|
||||
PHY_CLK_CTRL_CLK32K_EN));
|
||||
|
||||
twl4030_i2c_access(twl, 1);
|
||||
twl4030_usb_set_mode(twl, twl->usb_mode);
|
||||
if (twl->usb_mode == T2_USB_MODE_ULPI)
|
||||
twl4030_i2c_access(twl, 0);
|
||||
/*
|
||||
* According to the TPS65950 TRM, there has to be at least 50ms
|
||||
* delay between setting POWER_CTRL_OTG_ENAB and enabling charging
|
||||
* so wait here so that a fully enabled phy can be expected after
|
||||
* resume
|
||||
*/
|
||||
msleep(50);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -459,11 +471,6 @@ static int twl4030_phy_power_on(struct phy *phy)
|
||||
|
||||
dev_dbg(twl->dev, "%s\n", __func__);
|
||||
pm_runtime_get_sync(twl->dev);
|
||||
twl4030_i2c_access(twl, 1);
|
||||
twl4030_usb_set_mode(twl, twl->usb_mode);
|
||||
if (twl->usb_mode == T2_USB_MODE_ULPI)
|
||||
twl4030_i2c_access(twl, 0);
|
||||
twl->linkstat = MUSB_UNKNOWN;
|
||||
schedule_delayed_work(&twl->id_workaround_work, HZ);
|
||||
|
||||
return 0;
|
||||
@ -569,9 +576,12 @@ static irqreturn_t twl4030_usb_irq(int irq, void *_twl)
|
||||
pm_runtime_mark_last_busy(twl->dev);
|
||||
pm_runtime_put_autosuspend(twl->dev);
|
||||
}
|
||||
twl->musb_mailbox_pending = true;
|
||||
}
|
||||
if (twl->musb_mailbox_pending) {
|
||||
err = musb_mailbox(status);
|
||||
if (err)
|
||||
twl->linkstat = MUSB_UNKNOWN;
|
||||
if (!err)
|
||||
twl->musb_mailbox_pending = false;
|
||||
}
|
||||
|
||||
/* don't schedule during sleep - irq works right then */
|
||||
@ -676,6 +686,7 @@ static int twl4030_usb_probe(struct platform_device *pdev)
|
||||
twl->irq = platform_get_irq(pdev, 0);
|
||||
twl->vbus_supplied = false;
|
||||
twl->linkstat = MUSB_UNKNOWN;
|
||||
twl->musb_mailbox_pending = false;
|
||||
|
||||
twl->phy.dev = twl->dev;
|
||||
twl->phy.label = "twl4030";
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include <linux/of.h>
|
||||
#include <linux/of_device.h>
|
||||
#include <linux/phy/phy.h>
|
||||
#include <linux/phy/tegra/xusb.h>
|
||||
#include <linux/platform_device.h>
|
||||
#include <linux/regulator/consumer.h>
|
||||
#include <linux/reset.h>
|
||||
@ -101,7 +102,8 @@ tegra_xusb_pad_find_phy_node(struct tegra_xusb_pad *pad, unsigned int index)
|
||||
return of_find_node_by_name(np, pad->soc->lanes[index].name);
|
||||
}
|
||||
|
||||
int tegra_xusb_lane_lookup_function(struct tegra_xusb_lane *lane,
|
||||
static int
|
||||
tegra_xusb_lane_lookup_function(struct tegra_xusb_lane *lane,
|
||||
const char *function)
|
||||
{
|
||||
unsigned int i;
|
||||
|
@ -152,7 +152,8 @@ source "drivers/usb/gadget/Kconfig"
|
||||
|
||||
config USB_LED_TRIG
|
||||
bool "USB LED Triggers"
|
||||
depends on LEDS_CLASS && USB_COMMON && LEDS_TRIGGERS
|
||||
depends on LEDS_CLASS && LEDS_TRIGGERS
|
||||
select USB_COMMON
|
||||
help
|
||||
This option adds LED triggers for USB host and/or gadget activity.
|
||||
|
||||
@ -160,4 +161,25 @@ config USB_LED_TRIG
|
||||
LEDs and you want to use them as activity indicators for USB host or
|
||||
gadget.
|
||||
|
||||
config USB_ULPI_BUS
|
||||
tristate "USB ULPI PHY interface support"
|
||||
select USB_COMMON
|
||||
help
|
||||
UTMI+ Low Pin Interface (ULPI) is specification for a commonly used
|
||||
USB 2.0 PHY interface. The ULPI specification defines a standard set
|
||||
of registers that can be used to detect the vendor and product which
|
||||
allows ULPI to be handled as a bus. This module is the driver for that
|
||||
bus.
|
||||
|
||||
The ULPI interfaces (the buses) are registered by the drivers for USB
|
||||
controllers which support ULPI register access and have ULPI PHY
|
||||
attached to them. The ULPI PHY drivers themselves are normal PHY
|
||||
drivers.
|
||||
|
||||
ULPI PHYs provide often functions such as ADP sensing/probing (OTG
|
||||
protocol) and USB charger detection.
|
||||
|
||||
To compile this driver as a module, choose M here: the module will
|
||||
be called ulpi.
|
||||
|
||||
endif # USB_SUPPORT
|
||||
|
@ -1139,10 +1139,8 @@ static int cxacru_bind(struct usbatm_data *usbatm_instance,
|
||||
|
||||
/* instance init */
|
||||
instance = kzalloc(sizeof(*instance), GFP_KERNEL);
|
||||
if (!instance) {
|
||||
usb_dbg(usbatm_instance, "cxacru_bind: no memory for instance data\n");
|
||||
if (!instance)
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
instance->usbatm = usbatm_instance;
|
||||
instance->modem_type = (struct cxacru_modem_type *) id->driver_info;
|
||||
@ -1168,13 +1166,11 @@ static int cxacru_bind(struct usbatm_data *usbatm_instance,
|
||||
}
|
||||
instance->rcv_urb = usb_alloc_urb(0, GFP_KERNEL);
|
||||
if (!instance->rcv_urb) {
|
||||
usb_dbg(usbatm_instance, "cxacru_bind: no memory for rcv_urb\n");
|
||||
ret = -ENOMEM;
|
||||
goto fail;
|
||||
}
|
||||
instance->snd_urb = usb_alloc_urb(0, GFP_KERNEL);
|
||||
if (!instance->snd_urb) {
|
||||
usb_dbg(usbatm_instance, "cxacru_bind: no memory for snd_urb\n");
|
||||
ret = -ENOMEM;
|
||||
goto fail;
|
||||
}
|
||||
|
@ -817,7 +817,6 @@ static int speedtch_bind(struct usbatm_data *usbatm,
|
||||
instance = kzalloc(sizeof(*instance), GFP_KERNEL);
|
||||
|
||||
if (!instance) {
|
||||
usb_err(usbatm, "%s: no memory for instance data!\n", __func__);
|
||||
ret = -ENOMEM;
|
||||
goto fail_release;
|
||||
}
|
||||
|
@ -2196,17 +2196,12 @@ static int uea_boot(struct uea_softc *sc)
|
||||
load_XILINX_firmware(sc);
|
||||
|
||||
intr = kmalloc(size, GFP_KERNEL);
|
||||
if (!intr) {
|
||||
uea_err(INS_TO_USBDEV(sc),
|
||||
"cannot allocate interrupt package\n");
|
||||
if (!intr)
|
||||
goto err0;
|
||||
}
|
||||
|
||||
sc->urb_int = usb_alloc_urb(0, GFP_KERNEL);
|
||||
if (!sc->urb_int) {
|
||||
uea_err(INS_TO_USBDEV(sc), "cannot allocate interrupt URB\n");
|
||||
if (!sc->urb_int)
|
||||
goto err1;
|
||||
}
|
||||
|
||||
usb_fill_int_urb(sc->urb_int, sc->usb_dev,
|
||||
usb_rcvintpipe(sc->usb_dev, UEA_INTR_PIPE),
|
||||
@ -2561,10 +2556,8 @@ static int uea_bind(struct usbatm_data *usbatm, struct usb_interface *intf,
|
||||
}
|
||||
|
||||
sc = kzalloc(sizeof(struct uea_softc), GFP_KERNEL);
|
||||
if (!sc) {
|
||||
uea_err(usb, "uea_init: not enough memory !\n");
|
||||
if (!sc)
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
sc->usb_dev = usb;
|
||||
usbatm->driver_data = sc;
|
||||
|
@ -819,7 +819,6 @@ static int usbatm_atm_open(struct atm_vcc *vcc)
|
||||
|
||||
new = kzalloc(sizeof(struct usbatm_vcc_data), GFP_KERNEL);
|
||||
if (!new) {
|
||||
atm_err(instance, "%s: no memory for vcc_data!\n", __func__);
|
||||
ret = -ENOMEM;
|
||||
goto fail;
|
||||
}
|
||||
@ -1032,10 +1031,8 @@ int usbatm_usb_probe(struct usb_interface *intf, const struct usb_device_id *id,
|
||||
|
||||
/* instance init */
|
||||
instance = kzalloc(sizeof(*instance) + sizeof(struct urb *) * (num_rcv_urbs + num_snd_urbs), GFP_KERNEL);
|
||||
if (!instance) {
|
||||
dev_err(dev, "%s: no memory for instance data!\n", __func__);
|
||||
if (!instance)
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
/* public fields */
|
||||
|
||||
@ -1141,7 +1138,6 @@ int usbatm_usb_probe(struct usb_interface *intf, const struct usb_device_id *id,
|
||||
|
||||
urb = usb_alloc_urb(iso_packets, GFP_KERNEL);
|
||||
if (!urb) {
|
||||
dev_err(dev, "%s: no memory for urb %d!\n", __func__, i);
|
||||
error = -ENOMEM;
|
||||
goto fail_unbind;
|
||||
}
|
||||
@ -1151,7 +1147,6 @@ int usbatm_usb_probe(struct usb_interface *intf, const struct usb_device_id *id,
|
||||
/* zero the tx padding to avoid leaking information */
|
||||
buffer = kzalloc(channel->buf_size, GFP_KERNEL);
|
||||
if (!buffer) {
|
||||
dev_err(dev, "%s: no memory for buffer %d!\n", __func__, i);
|
||||
error = -ENOMEM;
|
||||
goto fail_unbind;
|
||||
}
|
||||
@ -1182,7 +1177,6 @@ int usbatm_usb_probe(struct usb_interface *intf, const struct usb_device_id *id,
|
||||
instance->cell_buf = kmalloc(instance->rx_channel.stride, GFP_KERNEL);
|
||||
|
||||
if (!instance->cell_buf) {
|
||||
dev_err(dev, "%s: no memory for cell buffer!\n", __func__);
|
||||
error = -ENOMEM;
|
||||
goto fail_unbind;
|
||||
}
|
||||
|
@ -140,6 +140,9 @@ static struct imx_usbmisc_data *usbmisc_get_init_data(struct device *dev)
|
||||
if (of_find_property(np, "disable-over-current", NULL))
|
||||
data->disable_oc = 1;
|
||||
|
||||
if (of_find_property(np, "over-current-active-high", NULL))
|
||||
data->oc_polarity = 1;
|
||||
|
||||
if (of_find_property(np, "external-vbus-divider", NULL))
|
||||
data->evdo = 1;
|
||||
|
||||
|
@ -17,6 +17,7 @@ struct imx_usbmisc_data {
|
||||
int index;
|
||||
|
||||
unsigned int disable_oc:1; /* over current detect disabled */
|
||||
unsigned int oc_polarity:1; /* over current polarity if oc enabled */
|
||||
unsigned int evdo:1; /* set external vbus divider option */
|
||||
};
|
||||
|
||||
|
@ -81,12 +81,15 @@ static int ehci_ci_reset(struct usb_hcd *hcd)
|
||||
{
|
||||
struct device *dev = hcd->self.controller;
|
||||
struct ci_hdrc *ci = dev_get_drvdata(dev);
|
||||
struct ehci_hcd *ehci = hcd_to_ehci(hcd);
|
||||
int ret;
|
||||
|
||||
ret = ehci_setup(hcd);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
ehci->need_io_watchdog = 0;
|
||||
|
||||
ci_platform_configure(ci);
|
||||
|
||||
return ret;
|
||||
|
@ -59,7 +59,7 @@ ctrl_endpt_in_desc = {
|
||||
*/
|
||||
static inline int hw_ep_bit(int num, int dir)
|
||||
{
|
||||
return num + (dir ? 16 : 0);
|
||||
return num + ((dir == TX) ? 16 : 0);
|
||||
}
|
||||
|
||||
static inline int ep_to_bit(struct ci_hdrc *ci, int n)
|
||||
@ -121,9 +121,8 @@ static int hw_ep_flush(struct ci_hdrc *ci, int num, int dir)
|
||||
*/
|
||||
static int hw_ep_disable(struct ci_hdrc *ci, int num, int dir)
|
||||
{
|
||||
hw_ep_flush(ci, num, dir);
|
||||
hw_write(ci, OP_ENDPTCTRL + num,
|
||||
dir ? ENDPTCTRL_TXE : ENDPTCTRL_RXE, 0);
|
||||
(dir == TX) ? ENDPTCTRL_TXE : ENDPTCTRL_RXE, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -139,7 +138,7 @@ static int hw_ep_enable(struct ci_hdrc *ci, int num, int dir, int type)
|
||||
{
|
||||
u32 mask, data;
|
||||
|
||||
if (dir) {
|
||||
if (dir == TX) {
|
||||
mask = ENDPTCTRL_TXT; /* type */
|
||||
data = type << __ffs(mask);
|
||||
|
||||
@ -171,7 +170,7 @@ static int hw_ep_enable(struct ci_hdrc *ci, int num, int dir, int type)
|
||||
*/
|
||||
static int hw_ep_get_halt(struct ci_hdrc *ci, int num, int dir)
|
||||
{
|
||||
u32 mask = dir ? ENDPTCTRL_TXS : ENDPTCTRL_RXS;
|
||||
u32 mask = (dir == TX) ? ENDPTCTRL_TXS : ENDPTCTRL_RXS;
|
||||
|
||||
return hw_read(ci, OP_ENDPTCTRL + num, mask) ? 1 : 0;
|
||||
}
|
||||
@ -188,6 +187,9 @@ static int hw_ep_prime(struct ci_hdrc *ci, int num, int dir, int is_ctrl)
|
||||
{
|
||||
int n = hw_ep_bit(num, dir);
|
||||
|
||||
/* Synchronize before ep prime */
|
||||
wmb();
|
||||
|
||||
if (is_ctrl && dir == RX && hw_read(ci, OP_ENDPTSETUPSTAT, BIT(num)))
|
||||
return -EAGAIN;
|
||||
|
||||
@ -218,8 +220,8 @@ static int hw_ep_set_halt(struct ci_hdrc *ci, int num, int dir, int value)
|
||||
|
||||
do {
|
||||
enum ci_hw_regs reg = OP_ENDPTCTRL + num;
|
||||
u32 mask_xs = dir ? ENDPTCTRL_TXS : ENDPTCTRL_RXS;
|
||||
u32 mask_xr = dir ? ENDPTCTRL_TXR : ENDPTCTRL_RXR;
|
||||
u32 mask_xs = (dir == TX) ? ENDPTCTRL_TXS : ENDPTCTRL_RXS;
|
||||
u32 mask_xr = (dir == TX) ? ENDPTCTRL_TXR : ENDPTCTRL_RXR;
|
||||
|
||||
/* data toggle - reserved for EP0 but it's in ESS */
|
||||
hw_write(ci, reg, mask_xs|mask_xr,
|
||||
@ -348,8 +350,7 @@ static int add_td_to_list(struct ci_hw_ep *hwep, struct ci_hw_req *hwreq,
|
||||
if (node == NULL)
|
||||
return -ENOMEM;
|
||||
|
||||
node->ptr = dma_pool_zalloc(hwep->td_pool, GFP_ATOMIC,
|
||||
&node->dma);
|
||||
node->ptr = dma_pool_zalloc(hwep->td_pool, GFP_ATOMIC, &node->dma);
|
||||
if (node->ptr == NULL) {
|
||||
kfree(node);
|
||||
return -ENOMEM;
|
||||
@ -506,8 +507,6 @@ static int _hardware_enqueue(struct ci_hw_ep *hwep, struct ci_hw_req *hwreq)
|
||||
hwep->qh.ptr->cap |= mul << __ffs(QH_MULT);
|
||||
}
|
||||
|
||||
wmb(); /* synchronize before ep prime */
|
||||
|
||||
ret = hw_ep_prime(ci, hwep->num, hwep->dir,
|
||||
hwep->type == USB_ENDPOINT_XFER_CONTROL);
|
||||
done:
|
||||
@ -534,9 +533,6 @@ static int reprime_dtd(struct ci_hdrc *ci, struct ci_hw_ep *hwep,
|
||||
hwep->qh.ptr->td.token &=
|
||||
cpu_to_le32(~(TD_STATUS_HALTED | TD_STATUS_ACTIVE));
|
||||
|
||||
/* Synchronize before ep prime */
|
||||
wmb();
|
||||
|
||||
return hw_ep_prime(ci, hwep->num, hwep->dir,
|
||||
hwep->type == USB_ENDPOINT_XFER_CONTROL);
|
||||
}
|
||||
@ -590,7 +586,7 @@ static int _hardware_dequeue(struct ci_hw_ep *hwep, struct ci_hw_req *hwreq)
|
||||
}
|
||||
|
||||
if (remaining_length) {
|
||||
if (hwep->dir) {
|
||||
if (hwep->dir == TX) {
|
||||
hwreq->req.status = -EPROTO;
|
||||
break;
|
||||
}
|
||||
@ -1051,9 +1047,9 @@ __acquires(ci->lock)
|
||||
if (req.wLength != 0)
|
||||
break;
|
||||
num = le16_to_cpu(req.wIndex);
|
||||
dir = num & USB_ENDPOINT_DIR_MASK;
|
||||
dir = (num & USB_ENDPOINT_DIR_MASK) ? TX : RX;
|
||||
num &= USB_ENDPOINT_NUMBER_MASK;
|
||||
if (dir) /* TX */
|
||||
if (dir == TX)
|
||||
num += ci->hw_ep_max / 2;
|
||||
if (!ci->ci_hw_ep[num].wedge) {
|
||||
spin_unlock(&ci->lock);
|
||||
@ -1103,9 +1099,9 @@ __acquires(ci->lock)
|
||||
if (req.wLength != 0)
|
||||
break;
|
||||
num = le16_to_cpu(req.wIndex);
|
||||
dir = num & USB_ENDPOINT_DIR_MASK;
|
||||
dir = (num & USB_ENDPOINT_DIR_MASK) ? TX : RX;
|
||||
num &= USB_ENDPOINT_NUMBER_MASK;
|
||||
if (dir) /* TX */
|
||||
if (dir == TX)
|
||||
num += ci->hw_ep_max / 2;
|
||||
|
||||
spin_unlock(&ci->lock);
|
||||
@ -1680,12 +1676,10 @@ static int init_eps(struct ci_hdrc *ci)
|
||||
usb_ep_set_maxpacket_limit(&hwep->ep, (unsigned short)~0);
|
||||
|
||||
INIT_LIST_HEAD(&hwep->qh.queue);
|
||||
hwep->qh.ptr = dma_pool_alloc(ci->qh_pool, GFP_KERNEL,
|
||||
&hwep->qh.dma);
|
||||
hwep->qh.ptr = dma_pool_zalloc(ci->qh_pool, GFP_KERNEL,
|
||||
&hwep->qh.dma);
|
||||
if (hwep->qh.ptr == NULL)
|
||||
retval = -ENOMEM;
|
||||
else
|
||||
memset(hwep->qh.ptr, 0, sizeof(*hwep->qh.ptr));
|
||||
|
||||
/*
|
||||
* set up shorthands for ep0 out and in endpoints,
|
||||
@ -1999,7 +1993,7 @@ int ci_hdrc_gadget_init(struct ci_hdrc *ci)
|
||||
if (!hw_read(ci, CAP_DCCPARAMS, DCCPARAMS_DC))
|
||||
return -ENXIO;
|
||||
|
||||
rdrv = devm_kzalloc(ci->dev, sizeof(struct ci_role_driver), GFP_KERNEL);
|
||||
rdrv = devm_kzalloc(ci->dev, sizeof(*rdrv), GFP_KERNEL);
|
||||
if (!rdrv)
|
||||
return -ENOMEM;
|
||||
|
||||
|
@ -56,6 +56,7 @@
|
||||
|
||||
#define MX6_BM_NON_BURST_SETTING BIT(1)
|
||||
#define MX6_BM_OVER_CUR_DIS BIT(7)
|
||||
#define MX6_BM_OVER_CUR_POLARITY BIT(8)
|
||||
#define MX6_BM_WAKEUP_ENABLE BIT(10)
|
||||
#define MX6_BM_ID_WAKEUP BIT(16)
|
||||
#define MX6_BM_VBUS_WAKEUP BIT(17)
|
||||
@ -266,11 +267,14 @@ static int usbmisc_imx6q_init(struct imx_usbmisc_data *data)
|
||||
|
||||
spin_lock_irqsave(&usbmisc->lock, flags);
|
||||
|
||||
reg = readl(usbmisc->base + data->index * 4);
|
||||
if (data->disable_oc) {
|
||||
reg = readl(usbmisc->base + data->index * 4);
|
||||
writel(reg | MX6_BM_OVER_CUR_DIS,
|
||||
usbmisc->base + data->index * 4);
|
||||
reg |= MX6_BM_OVER_CUR_DIS;
|
||||
} else if (data->oc_polarity == 1) {
|
||||
/* High active */
|
||||
reg &= ~(MX6_BM_OVER_CUR_DIS | MX6_BM_OVER_CUR_POLARITY);
|
||||
}
|
||||
writel(reg, usbmisc->base + data->index * 4);
|
||||
|
||||
/* SoC non-burst setting */
|
||||
reg = readl(usbmisc->base + data->index * 4);
|
||||
@ -365,10 +369,14 @@ static int usbmisc_imx7d_init(struct imx_usbmisc_data *data)
|
||||
return -EINVAL;
|
||||
|
||||
spin_lock_irqsave(&usbmisc->lock, flags);
|
||||
reg = readl(usbmisc->base);
|
||||
if (data->disable_oc) {
|
||||
reg = readl(usbmisc->base);
|
||||
writel(reg | MX6_BM_OVER_CUR_DIS, usbmisc->base);
|
||||
reg |= MX6_BM_OVER_CUR_DIS;
|
||||
} else if (data->oc_polarity == 1) {
|
||||
/* High active */
|
||||
reg &= ~(MX6_BM_OVER_CUR_DIS | MX6_BM_OVER_CUR_POLARITY);
|
||||
}
|
||||
writel(reg, usbmisc->base);
|
||||
|
||||
reg = readl(usbmisc->base + MX7D_USBNC_USB_CTRL2);
|
||||
reg &= ~MX7D_USB_VBUS_WAKEUP_SOURCE_MASK;
|
||||
@ -492,6 +500,10 @@ static const struct of_device_id usbmisc_imx_dt_ids[] = {
|
||||
.compatible = "fsl,imx6ul-usbmisc",
|
||||
.data = &imx6sx_usbmisc_ops,
|
||||
},
|
||||
{
|
||||
.compatible = "fsl,imx7d-usbmisc",
|
||||
.data = &imx7d_usbmisc_ops,
|
||||
},
|
||||
{ /* sentinel */ }
|
||||
};
|
||||
MODULE_DEVICE_TABLE(of, usbmisc_imx_dt_ids);
|
||||
|
@ -368,17 +368,17 @@ static int acm_submit_read_urb(struct acm *acm, int index, gfp_t mem_flags)
|
||||
if (!test_and_clear_bit(index, &acm->read_urbs_free))
|
||||
return 0;
|
||||
|
||||
dev_vdbg(&acm->data->dev, "%s - urb %d\n", __func__, index);
|
||||
|
||||
res = usb_submit_urb(acm->read_urbs[index], mem_flags);
|
||||
if (res) {
|
||||
if (res != -EPERM) {
|
||||
dev_err(&acm->data->dev,
|
||||
"%s - usb_submit_urb failed: %d\n",
|
||||
__func__, res);
|
||||
"urb %d failed submission with %d\n",
|
||||
index, res);
|
||||
}
|
||||
set_bit(index, &acm->read_urbs_free);
|
||||
return res;
|
||||
} else {
|
||||
dev_vdbg(&acm->data->dev, "submitted urb %d\n", index);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -415,8 +415,9 @@ static void acm_read_bulk_callback(struct urb *urb)
|
||||
unsigned long flags;
|
||||
int status = urb->status;
|
||||
|
||||
dev_vdbg(&acm->data->dev, "%s - urb %d, len %d\n", __func__,
|
||||
rb->index, urb->actual_length);
|
||||
dev_vdbg(&acm->data->dev, "got urb %d, len %d, status %d\n",
|
||||
rb->index, urb->actual_length,
|
||||
status);
|
||||
|
||||
if (!acm->dev) {
|
||||
set_bit(rb->index, &acm->read_urbs_free);
|
||||
@ -426,8 +427,6 @@ static void acm_read_bulk_callback(struct urb *urb)
|
||||
|
||||
if (status) {
|
||||
set_bit(rb->index, &acm->read_urbs_free);
|
||||
dev_dbg(&acm->data->dev, "%s - non-zero urb status: %d\n",
|
||||
__func__, status);
|
||||
if ((status != -ENOENT) || (urb->actual_length == 0))
|
||||
return;
|
||||
}
|
||||
@ -462,8 +461,7 @@ static void acm_write_bulk(struct urb *urb)
|
||||
int status = urb->status;
|
||||
|
||||
if (status || (urb->actual_length != urb->transfer_buffer_length))
|
||||
dev_vdbg(&acm->data->dev, "%s - len %d/%d, status %d\n",
|
||||
__func__,
|
||||
dev_vdbg(&acm->data->dev, "wrote len %d/%d, status %d\n",
|
||||
urb->actual_length,
|
||||
urb->transfer_buffer_length,
|
||||
status);
|
||||
@ -478,8 +476,6 @@ static void acm_softint(struct work_struct *work)
|
||||
{
|
||||
struct acm *acm = container_of(work, struct acm, work);
|
||||
|
||||
dev_vdbg(&acm->data->dev, "%s\n", __func__);
|
||||
|
||||
tty_port_tty_wakeup(&acm->port);
|
||||
}
|
||||
|
||||
@ -492,8 +488,6 @@ static int acm_tty_install(struct tty_driver *driver, struct tty_struct *tty)
|
||||
struct acm *acm;
|
||||
int retval;
|
||||
|
||||
dev_dbg(tty->dev, "%s\n", __func__);
|
||||
|
||||
acm = acm_get_by_minor(tty->index);
|
||||
if (!acm)
|
||||
return -ENODEV;
|
||||
@ -515,8 +509,6 @@ static int acm_tty_open(struct tty_struct *tty, struct file *filp)
|
||||
{
|
||||
struct acm *acm = tty->driver_data;
|
||||
|
||||
dev_dbg(tty->dev, "%s\n", __func__);
|
||||
|
||||
return tty_port_open(&acm->port, tty, filp);
|
||||
}
|
||||
|
||||
@ -545,8 +537,6 @@ static int acm_port_activate(struct tty_port *port, struct tty_struct *tty)
|
||||
int retval = -ENODEV;
|
||||
int i;
|
||||
|
||||
dev_dbg(&acm->control->dev, "%s\n", __func__);
|
||||
|
||||
mutex_lock(&acm->mutex);
|
||||
if (acm->disconnected)
|
||||
goto disconnected;
|
||||
@ -607,8 +597,6 @@ static void acm_port_destruct(struct tty_port *port)
|
||||
{
|
||||
struct acm *acm = container_of(port, struct acm, port);
|
||||
|
||||
dev_dbg(&acm->control->dev, "%s\n", __func__);
|
||||
|
||||
acm_release_minor(acm);
|
||||
usb_put_intf(acm->control);
|
||||
kfree(acm->country_codes);
|
||||
@ -622,8 +610,6 @@ static void acm_port_shutdown(struct tty_port *port)
|
||||
struct acm_wb *wb;
|
||||
int i;
|
||||
|
||||
dev_dbg(&acm->control->dev, "%s\n", __func__);
|
||||
|
||||
/*
|
||||
* Need to grab write_lock to prevent race with resume, but no need to
|
||||
* hold it due to the tty-port initialised flag.
|
||||
@ -654,21 +640,21 @@ static void acm_port_shutdown(struct tty_port *port)
|
||||
static void acm_tty_cleanup(struct tty_struct *tty)
|
||||
{
|
||||
struct acm *acm = tty->driver_data;
|
||||
dev_dbg(&acm->control->dev, "%s\n", __func__);
|
||||
|
||||
tty_port_put(&acm->port);
|
||||
}
|
||||
|
||||
static void acm_tty_hangup(struct tty_struct *tty)
|
||||
{
|
||||
struct acm *acm = tty->driver_data;
|
||||
dev_dbg(&acm->control->dev, "%s\n", __func__);
|
||||
|
||||
tty_port_hangup(&acm->port);
|
||||
}
|
||||
|
||||
static void acm_tty_close(struct tty_struct *tty, struct file *filp)
|
||||
{
|
||||
struct acm *acm = tty->driver_data;
|
||||
dev_dbg(&acm->control->dev, "%s\n", __func__);
|
||||
|
||||
tty_port_close(&acm->port, tty, filp);
|
||||
}
|
||||
|
||||
@ -684,7 +670,7 @@ static int acm_tty_write(struct tty_struct *tty,
|
||||
if (!count)
|
||||
return 0;
|
||||
|
||||
dev_vdbg(&acm->data->dev, "%s - count %d\n", __func__, count);
|
||||
dev_vdbg(&acm->data->dev, "%d bytes from tty layer\n", count);
|
||||
|
||||
spin_lock_irqsave(&acm->write_lock, flags);
|
||||
wbn = acm_wb_alloc(acm);
|
||||
@ -701,7 +687,7 @@ static int acm_tty_write(struct tty_struct *tty,
|
||||
}
|
||||
|
||||
count = (count > acm->writesize) ? acm->writesize : count;
|
||||
dev_vdbg(&acm->data->dev, "%s - write %d\n", __func__, count);
|
||||
dev_vdbg(&acm->data->dev, "writing %d bytes\n", count);
|
||||
memcpy(wb->buf, buf, count);
|
||||
wb->len = count;
|
||||
|
||||
@ -1193,6 +1179,9 @@ static int acm_probe(struct usb_interface *intf,
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (!intf->cur_altsetting)
|
||||
return -EINVAL;
|
||||
|
||||
if (!buflen) {
|
||||
if (intf->cur_altsetting->endpoint &&
|
||||
intf->cur_altsetting->endpoint->extralen &&
|
||||
@ -1246,6 +1235,8 @@ static int acm_probe(struct usb_interface *intf,
|
||||
dev_dbg(&intf->dev, "no interfaces\n");
|
||||
return -ENODEV;
|
||||
}
|
||||
if (!data_interface->cur_altsetting || !control_interface->cur_altsetting)
|
||||
return -ENODEV;
|
||||
|
||||
if (data_intf_num != call_intf_num)
|
||||
dev_dbg(&intf->dev, "Separate call control interface. That is not fully supported.\n");
|
||||
@ -1533,8 +1524,6 @@ static void stop_data_traffic(struct acm *acm)
|
||||
{
|
||||
int i;
|
||||
|
||||
dev_dbg(&acm->control->dev, "%s\n", __func__);
|
||||
|
||||
usb_kill_urb(acm->ctrlurb);
|
||||
for (i = 0; i < ACM_NW; i++)
|
||||
usb_kill_urb(acm->wb[i].urb);
|
||||
@ -1551,8 +1540,6 @@ static void acm_disconnect(struct usb_interface *intf)
|
||||
struct tty_struct *tty;
|
||||
int i;
|
||||
|
||||
dev_dbg(&intf->dev, "%s\n", __func__);
|
||||
|
||||
/* sibling interface is already cleaning up */
|
||||
if (!acm)
|
||||
return;
|
||||
|
@ -58,6 +58,7 @@ MODULE_DEVICE_TABLE (usb, wdm_ids);
|
||||
#define WDM_SUSPENDING 8
|
||||
#define WDM_RESETTING 9
|
||||
#define WDM_OVERFLOW 10
|
||||
#define WDM_DRAIN_ON_OPEN 11
|
||||
|
||||
#define WDM_MAX 16
|
||||
|
||||
@ -154,6 +155,9 @@ static void wdm_out_callback(struct urb *urb)
|
||||
wake_up(&desc->wait);
|
||||
}
|
||||
|
||||
/* forward declaration */
|
||||
static int service_outstanding_interrupt(struct wdm_device *desc);
|
||||
|
||||
static void wdm_in_callback(struct urb *urb)
|
||||
{
|
||||
struct wdm_device *desc = urb->context;
|
||||
@ -167,18 +171,18 @@ static void wdm_in_callback(struct urb *urb)
|
||||
switch (status) {
|
||||
case -ENOENT:
|
||||
dev_dbg(&desc->intf->dev,
|
||||
"nonzero urb status received: -ENOENT");
|
||||
"nonzero urb status received: -ENOENT\n");
|
||||
goto skip_error;
|
||||
case -ECONNRESET:
|
||||
dev_dbg(&desc->intf->dev,
|
||||
"nonzero urb status received: -ECONNRESET");
|
||||
"nonzero urb status received: -ECONNRESET\n");
|
||||
goto skip_error;
|
||||
case -ESHUTDOWN:
|
||||
dev_dbg(&desc->intf->dev,
|
||||
"nonzero urb status received: -ESHUTDOWN");
|
||||
"nonzero urb status received: -ESHUTDOWN\n");
|
||||
goto skip_error;
|
||||
case -EPIPE:
|
||||
dev_err(&desc->intf->dev,
|
||||
dev_dbg(&desc->intf->dev,
|
||||
"nonzero urb status received: -EPIPE\n");
|
||||
break;
|
||||
default:
|
||||
@ -188,7 +192,13 @@ static void wdm_in_callback(struct urb *urb)
|
||||
}
|
||||
}
|
||||
|
||||
desc->rerr = status;
|
||||
/*
|
||||
* only set a new error if there is no previous error.
|
||||
* Errors are only cleared during read/open
|
||||
*/
|
||||
if (desc->rerr == 0)
|
||||
desc->rerr = status;
|
||||
|
||||
if (length + desc->length > desc->wMaxCommand) {
|
||||
/* The buffer would overflow */
|
||||
set_bit(WDM_OVERFLOW, &desc->flags);
|
||||
@ -200,10 +210,40 @@ static void wdm_in_callback(struct urb *urb)
|
||||
desc->reslength = length;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Handling devices with the WDM_DRAIN_ON_OPEN flag set:
|
||||
* If desc->resp_count is unset, then the urb was submitted
|
||||
* without a prior notification. If the device returned any
|
||||
* data, then this implies that it had messages queued without
|
||||
* notifying us. Continue reading until that queue is flushed.
|
||||
*/
|
||||
if (!desc->resp_count) {
|
||||
if (!length) {
|
||||
/* do not propagate the expected -EPIPE */
|
||||
desc->rerr = 0;
|
||||
goto unlock;
|
||||
}
|
||||
dev_dbg(&desc->intf->dev, "got %d bytes without notification\n", length);
|
||||
set_bit(WDM_RESPONDING, &desc->flags);
|
||||
usb_submit_urb(desc->response, GFP_ATOMIC);
|
||||
}
|
||||
|
||||
skip_error:
|
||||
set_bit(WDM_READ, &desc->flags);
|
||||
wake_up(&desc->wait);
|
||||
|
||||
set_bit(WDM_READ, &desc->flags);
|
||||
if (desc->rerr) {
|
||||
/*
|
||||
* Since there was an error, userspace may decide to not read
|
||||
* any data after poll'ing.
|
||||
* We should respond to further attempts from the device to send
|
||||
* data, so that we can get unstuck.
|
||||
*/
|
||||
service_outstanding_interrupt(desc);
|
||||
}
|
||||
|
||||
unlock:
|
||||
spin_unlock(&desc->iuspin);
|
||||
}
|
||||
|
||||
@ -244,18 +284,18 @@ static void wdm_int_callback(struct urb *urb)
|
||||
switch (dr->bNotificationType) {
|
||||
case USB_CDC_NOTIFY_RESPONSE_AVAILABLE:
|
||||
dev_dbg(&desc->intf->dev,
|
||||
"NOTIFY_RESPONSE_AVAILABLE received: index %d len %d",
|
||||
"NOTIFY_RESPONSE_AVAILABLE received: index %d len %d\n",
|
||||
le16_to_cpu(dr->wIndex), le16_to_cpu(dr->wLength));
|
||||
break;
|
||||
|
||||
case USB_CDC_NOTIFY_NETWORK_CONNECTION:
|
||||
|
||||
dev_dbg(&desc->intf->dev,
|
||||
"NOTIFY_NETWORK_CONNECTION %s network",
|
||||
"NOTIFY_NETWORK_CONNECTION %s network\n",
|
||||
dr->wValue ? "connected to" : "disconnected from");
|
||||
goto exit;
|
||||
case USB_CDC_NOTIFY_SPEED_CHANGE:
|
||||
dev_dbg(&desc->intf->dev, "SPEED_CHANGE received (len %u)",
|
||||
dev_dbg(&desc->intf->dev, "SPEED_CHANGE received (len %u)\n",
|
||||
urb->actual_length);
|
||||
goto exit;
|
||||
default:
|
||||
@ -274,8 +314,7 @@ static void wdm_int_callback(struct urb *urb)
|
||||
&& !test_bit(WDM_DISCONNECTING, &desc->flags)
|
||||
&& !test_bit(WDM_SUSPENDING, &desc->flags)) {
|
||||
rv = usb_submit_urb(desc->response, GFP_ATOMIC);
|
||||
dev_dbg(&desc->intf->dev, "%s: usb_submit_urb %d",
|
||||
__func__, rv);
|
||||
dev_dbg(&desc->intf->dev, "submit response URB %d\n", rv);
|
||||
}
|
||||
spin_unlock(&desc->iuspin);
|
||||
if (rv < 0) {
|
||||
@ -417,7 +456,7 @@ static ssize_t wdm_write
|
||||
rv = usb_translate_errors(rv);
|
||||
goto out_free_mem_pm;
|
||||
} else {
|
||||
dev_dbg(&desc->intf->dev, "Tx URB has been submitted index=%d",
|
||||
dev_dbg(&desc->intf->dev, "Tx URB has been submitted index=%d\n",
|
||||
le16_to_cpu(req->wIndex));
|
||||
}
|
||||
|
||||
@ -436,17 +475,14 @@ out_free_mem:
|
||||
}
|
||||
|
||||
/*
|
||||
* clear WDM_READ flag and possibly submit the read urb if resp_count
|
||||
* is non-zero.
|
||||
* Submit the read urb if resp_count is non-zero.
|
||||
*
|
||||
* Called with desc->iuspin locked
|
||||
*/
|
||||
static int clear_wdm_read_flag(struct wdm_device *desc)
|
||||
static int service_outstanding_interrupt(struct wdm_device *desc)
|
||||
{
|
||||
int rv = 0;
|
||||
|
||||
clear_bit(WDM_READ, &desc->flags);
|
||||
|
||||
/* submit read urb only if the device is waiting for it */
|
||||
if (!desc->resp_count || !--desc->resp_count)
|
||||
goto out;
|
||||
@ -537,8 +573,9 @@ retry:
|
||||
}
|
||||
|
||||
if (!desc->reslength) { /* zero length read */
|
||||
dev_dbg(&desc->intf->dev, "%s: zero length - clearing WDM_READ\n", __func__);
|
||||
rv = clear_wdm_read_flag(desc);
|
||||
dev_dbg(&desc->intf->dev, "zero length - clearing WDM_READ\n");
|
||||
clear_bit(WDM_READ, &desc->flags);
|
||||
rv = service_outstanding_interrupt(desc);
|
||||
spin_unlock_irq(&desc->iuspin);
|
||||
if (rv < 0)
|
||||
goto err;
|
||||
@ -563,8 +600,10 @@ retry:
|
||||
|
||||
desc->length -= cntr;
|
||||
/* in case we had outstanding data */
|
||||
if (!desc->length)
|
||||
clear_wdm_read_flag(desc);
|
||||
if (!desc->length) {
|
||||
clear_bit(WDM_READ, &desc->flags);
|
||||
service_outstanding_interrupt(desc);
|
||||
}
|
||||
spin_unlock_irq(&desc->iuspin);
|
||||
rv = cntr;
|
||||
|
||||
@ -647,6 +686,17 @@ static int wdm_open(struct inode *inode, struct file *file)
|
||||
dev_err(&desc->intf->dev,
|
||||
"Error submitting int urb - %d\n", rv);
|
||||
rv = usb_translate_errors(rv);
|
||||
} else if (test_bit(WDM_DRAIN_ON_OPEN, &desc->flags)) {
|
||||
/*
|
||||
* Some devices keep pending messages queued
|
||||
* without resending notifications. We must
|
||||
* flush the message queue before we can
|
||||
* assume a one-to-one relationship between
|
||||
* notifications and messages in the queue
|
||||
*/
|
||||
dev_dbg(&desc->intf->dev, "draining queued data\n");
|
||||
set_bit(WDM_RESPONDING, &desc->flags);
|
||||
rv = usb_submit_urb(desc->response, GFP_KERNEL);
|
||||
}
|
||||
} else {
|
||||
rv = 0;
|
||||
@ -673,7 +723,7 @@ static int wdm_release(struct inode *inode, struct file *file)
|
||||
|
||||
if (!desc->count) {
|
||||
if (!test_bit(WDM_DISCONNECTING, &desc->flags)) {
|
||||
dev_dbg(&desc->intf->dev, "wdm_release: cleanup");
|
||||
dev_dbg(&desc->intf->dev, "wdm_release: cleanup\n");
|
||||
kill_urbs(desc);
|
||||
spin_lock_irq(&desc->iuspin);
|
||||
desc->resp_count = 0;
|
||||
@ -753,7 +803,8 @@ static void wdm_rxwork(struct work_struct *work)
|
||||
/* --- hotplug --- */
|
||||
|
||||
static int wdm_create(struct usb_interface *intf, struct usb_endpoint_descriptor *ep,
|
||||
u16 bufsize, int (*manage_power)(struct usb_interface *, int))
|
||||
u16 bufsize, int (*manage_power)(struct usb_interface *, int),
|
||||
bool drain_on_open)
|
||||
{
|
||||
int rv = -ENOMEM;
|
||||
struct wdm_device *desc;
|
||||
@ -840,6 +891,68 @@ static int wdm_create(struct usb_interface *intf, struct usb_endpoint_descriptor
|
||||
|
||||
desc->manage_power = manage_power;
|
||||
|
||||
/*
|
||||
* "drain_on_open" enables a hack to work around a firmware
|
||||
* issue observed on network functions, in particular MBIM
|
||||
* functions.
|
||||
*
|
||||
* Quoting section 7 of the CDC-WMC r1.1 specification:
|
||||
*
|
||||
* "The firmware shall interpret GetEncapsulatedResponse as a
|
||||
* request to read response bytes. The firmware shall send
|
||||
* the next wLength bytes from the response. The firmware
|
||||
* shall allow the host to retrieve data using any number of
|
||||
* GetEncapsulatedResponse requests. The firmware shall
|
||||
* return a zero- length reply if there are no data bytes
|
||||
* available.
|
||||
*
|
||||
* The firmware shall send ResponseAvailable notifications
|
||||
* periodically, using any appropriate algorithm, to inform
|
||||
* the host that there is data available in the reply
|
||||
* buffer. The firmware is allowed to send ResponseAvailable
|
||||
* notifications even if there is no data available, but
|
||||
* this will obviously reduce overall performance."
|
||||
*
|
||||
* These requirements, although they make equally sense, are
|
||||
* often not implemented by network functions. Some firmwares
|
||||
* will queue data indefinitely, without ever resending a
|
||||
* notification. The result is that the driver and firmware
|
||||
* loses "syncronization" if the driver ever fails to respond
|
||||
* to a single notification, something which easily can happen
|
||||
* on release(). When this happens, the driver will appear to
|
||||
* never receive notifications for the most current data. Each
|
||||
* notification will only cause a single read, which returns
|
||||
* the oldest data in the firmware's queue.
|
||||
*
|
||||
* The "drain_on_open" hack resolves the situation by draining
|
||||
* data from the firmware until none is returned, without a
|
||||
* prior notification.
|
||||
*
|
||||
* This will inevitably race with the firmware, risking that
|
||||
* we read data from the device before handling the associated
|
||||
* notification. To make things worse, some of the devices
|
||||
* needing the hack do not implement the "return zero if no
|
||||
* data is available" requirement either. Instead they return
|
||||
* an error on the subsequent read in this case. This means
|
||||
* that "winning" the race can cause an unexpected EIO to
|
||||
* userspace.
|
||||
*
|
||||
* "winning" the race is more likely on resume() than on
|
||||
* open(), and the unexpected error is more harmful in the
|
||||
* middle of an open session. The hack is therefore only
|
||||
* applied on open(), and not on resume() where it logically
|
||||
* would be equally necessary. So we define open() as the only
|
||||
* driver <-> device "syncronization point". Should we happen
|
||||
* to lose a notification after open(), then syncronization
|
||||
* will be lost until release()
|
||||
*
|
||||
* The hack should not be enabled for CDC WDM devices
|
||||
* conforming to the CDC-WMC r1.1 specification. This is
|
||||
* ensured by setting drain_on_open to false in wdm_probe().
|
||||
*/
|
||||
if (drain_on_open)
|
||||
set_bit(WDM_DRAIN_ON_OPEN, &desc->flags);
|
||||
|
||||
spin_lock(&wdm_device_list_lock);
|
||||
list_add(&desc->device_list, &wdm_device_list);
|
||||
spin_unlock(&wdm_device_list_lock);
|
||||
@ -893,7 +1006,7 @@ static int wdm_probe(struct usb_interface *intf, const struct usb_device_id *id)
|
||||
goto err;
|
||||
ep = &iface->endpoint[0].desc;
|
||||
|
||||
rv = wdm_create(intf, ep, maxcom, &wdm_manage_power);
|
||||
rv = wdm_create(intf, ep, maxcom, &wdm_manage_power, false);
|
||||
|
||||
err:
|
||||
return rv;
|
||||
@ -925,7 +1038,7 @@ struct usb_driver *usb_cdc_wdm_register(struct usb_interface *intf,
|
||||
{
|
||||
int rv = -EINVAL;
|
||||
|
||||
rv = wdm_create(intf, ep, bufsize, manage_power);
|
||||
rv = wdm_create(intf, ep, bufsize, manage_power, true);
|
||||
if (rv < 0)
|
||||
goto err;
|
||||
|
||||
@ -967,7 +1080,7 @@ static void wdm_disconnect(struct usb_interface *intf)
|
||||
if (!desc->count)
|
||||
cleanup(desc);
|
||||
else
|
||||
dev_dbg(&intf->dev, "%s: %d open files - postponing cleanup\n", __func__, desc->count);
|
||||
dev_dbg(&intf->dev, "%d open files - postponing cleanup\n", desc->count);
|
||||
mutex_unlock(&wdm_mutex);
|
||||
}
|
||||
|
||||
|
@ -141,6 +141,7 @@ static void usbtmc_delete(struct kref *kref)
|
||||
struct usbtmc_device_data *data = to_usbtmc_data(kref);
|
||||
|
||||
usb_put_dev(data->usb_dev);
|
||||
kfree(data);
|
||||
}
|
||||
|
||||
static int usbtmc_open(struct inode *inode, struct file *filp)
|
||||
@ -1379,7 +1380,7 @@ static int usbtmc_probe(struct usb_interface *intf,
|
||||
|
||||
dev_dbg(&intf->dev, "%s called\n", __func__);
|
||||
|
||||
data = devm_kzalloc(&intf->dev, sizeof(*data), GFP_KERNEL);
|
||||
data = kmalloc(sizeof(*data), GFP_KERNEL);
|
||||
if (!data)
|
||||
return -ENOMEM;
|
||||
|
||||
@ -1467,10 +1468,8 @@ static int usbtmc_probe(struct usb_interface *intf,
|
||||
if (data->iin_ep_present) {
|
||||
/* allocate int urb */
|
||||
data->iin_urb = usb_alloc_urb(0, GFP_KERNEL);
|
||||
if (!data->iin_urb) {
|
||||
dev_err(&intf->dev, "Failed to allocate int urb\n");
|
||||
if (!data->iin_urb)
|
||||
goto error_register;
|
||||
}
|
||||
|
||||
/* will reference data in int urb */
|
||||
kref_get(&data->kref);
|
||||
@ -1478,10 +1477,8 @@ static int usbtmc_probe(struct usb_interface *intf,
|
||||
/* allocate buffer for interrupt in */
|
||||
data->iin_buffer = kmalloc(data->iin_wMaxPacketSize,
|
||||
GFP_KERNEL);
|
||||
if (!data->iin_buffer) {
|
||||
dev_err(&intf->dev, "Failed to allocate int buf\n");
|
||||
if (!data->iin_buffer)
|
||||
goto error_register;
|
||||
}
|
||||
|
||||
/* fill interrupt urb */
|
||||
usb_fill_int_urb(data->iin_urb, data->usb_dev,
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user