forked from Minki/linux
USB/PHY patches for 4.17-rc1
Here is the big set of USB and PHY driver patches for 4.17-rc1. Lots of USB typeC work happened this round, with code moving from the staging directory into the "real" part of the kernel, as well as new infrastructure being added to be able to handle the different types of "roles" that typeC requires. There is also the normal huge set of USB gadget controller and driver updates, along with XHCI changes, and a raft of other tiny fixes all over the USB tree. And the PHY driver updates are merged in here as well as they interacted with the USB drivers in some places. All of these have been in linux-next for a while with no reported issues. Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> -----BEGIN PGP SIGNATURE----- iG0EABECAC0WIQT0tgzFv3jCIUoxPcsxR9QN2y37KQUCWsSpJw8cZ3JlZ0Brcm9h aC5jb20ACgkQMUfUDdst+ylGawCdED2xS3HUxOIqfh81d8B1py8ji04AoJXdLAsH JgwXbdbibZBabYTVi5s5 =LrRH -----END PGP SIGNATURE----- Merge tag 'usb-4.17-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb Pull USB/PHY updates from Greg KH: "Here is the big set of USB and PHY driver patches for 4.17-rc1. Lots of USB typeC work happened this round, with code moving from the staging directory into the "real" part of the kernel, as well as new infrastructure being added to be able to handle the different types of "roles" that typeC requires. There is also the normal huge set of USB gadget controller and driver updates, along with XHCI changes, and a raft of other tiny fixes all over the USB tree. And the PHY driver updates are merged in here as well as they interacted with the USB drivers in some places. All of these have been in linux-next for a while with no reported issues" * tag 'usb-4.17-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb: (250 commits) Revert "USB: serial: ftdi_sio: add Id for Physik Instrumente E-870" usb: musb: gadget: misplaced out of bounds check usb: chipidea: imx: Fix ULPI on imx53 usb: chipidea: imx: Cleanup ci_hdrc_imx_platform_flag usb: chipidea: usbmisc: small clean up usb: chipidea: usbmisc: evdo can be set e/o reset usb: chipidea: usbmisc: evdo is only specific to OTG port USB: serial: ftdi_sio: add Id for Physik Instrumente E-870 usb: dwc3: gadget: never call ->complete() from ->ep_queue() usb: gadget: udc: core: update usb_ep_queue() documentation usb: host: Remove the deprecated ATH79 USB host config options usb: roles: Fix return value check in intel_xhci_usb_probe() USB: gadget: f_midi: fixing a possible double-free in f_midi usb: core: Add USB_QUIRK_DELAY_CTRL_MSG to usbcore quirks usb: core: Copy parameter string correctly and remove superfluous null check USB: announce bcdDevice as well as idVendor, idProduct. USB:fix USB3 devices behind USB3 hubs not resuming at hibernate thaw usb: hub: Reduce warning to notice on power loss USB: serial: ftdi_sio: add support for Harman FirmwareHubEmulator USB: serial: cp210x: add ELDAT Easywave RX09 id ...
This commit is contained in:
commit
ac9053d2dc
@ -189,6 +189,16 @@ Description:
|
||||
The file will read "hotplug", "wired" and "not used" if the
|
||||
information is available, and "unknown" otherwise.
|
||||
|
||||
What: /sys/bus/usb/devices/.../(hub interface)/portX/over_current_count
|
||||
Date: February 2018
|
||||
Contact: Richard Leitner <richard.leitner@skidata.com>
|
||||
Description:
|
||||
Most hubs are able to detect over-current situations on their
|
||||
ports and report them to the kernel. This attribute is to expose
|
||||
the number of over-current situation occurred on a specific port
|
||||
to user space. This file will contain an unsigned 32 bit value
|
||||
which wraps to 0 after its maximum is reached.
|
||||
|
||||
What: /sys/bus/usb/devices/.../(hub interface)/portX/usb3_lpm_permit
|
||||
Date: November 2015
|
||||
Contact: Lu Baolu <baolu.lu@linux.intel.com>
|
||||
|
21
Documentation/ABI/testing/sysfs-class-usb_role
Normal file
21
Documentation/ABI/testing/sysfs-class-usb_role
Normal file
@ -0,0 +1,21 @@
|
||||
What: /sys/class/usb_role/
|
||||
Date: Jan 2018
|
||||
Contact: Heikki Krogerus <heikki.krogerus@linux.intel.com>
|
||||
Description:
|
||||
Place in sysfs for USB Role Switches. USB Role Switch is a
|
||||
device that can select the data role (host or device) for USB
|
||||
port.
|
||||
|
||||
What: /sys/class/usb_role/<switch>/role
|
||||
Date: Jan 2018
|
||||
Contact: Heikki Krogerus <heikki.krogerus@linux.intel.com>
|
||||
Description:
|
||||
The current role of the switch. This attribute can be used for
|
||||
requesting role swapping with non-USB Type-C ports. With USB
|
||||
Type-C ports, the ABI defined for USB Type-C connector class
|
||||
must be used.
|
||||
|
||||
Valid values:
|
||||
- none
|
||||
- host
|
||||
- device
|
@ -4392,6 +4392,64 @@
|
||||
|
||||
usbcore.nousb [USB] Disable the USB subsystem
|
||||
|
||||
usbcore.quirks=
|
||||
[USB] A list of quirk entries to augment the built-in
|
||||
usb core quirk list. List entries are separated by
|
||||
commas. Each entry has the form
|
||||
VendorID:ProductID:Flags. The IDs are 4-digit hex
|
||||
numbers and Flags is a set of letters. Each letter
|
||||
will change the built-in quirk; setting it if it is
|
||||
clear and clearing it if it is set. The letters have
|
||||
the following meanings:
|
||||
a = USB_QUIRK_STRING_FETCH_255 (string
|
||||
descriptors must not be fetched using
|
||||
a 255-byte read);
|
||||
b = USB_QUIRK_RESET_RESUME (device can't resume
|
||||
correctly so reset it instead);
|
||||
c = USB_QUIRK_NO_SET_INTF (device can't handle
|
||||
Set-Interface requests);
|
||||
d = USB_QUIRK_CONFIG_INTF_STRINGS (device can't
|
||||
handle its Configuration or Interface
|
||||
strings);
|
||||
e = USB_QUIRK_RESET (device can't be reset
|
||||
(e.g morph devices), don't use reset);
|
||||
f = USB_QUIRK_HONOR_BNUMINTERFACES (device has
|
||||
more interface descriptions than the
|
||||
bNumInterfaces count, and can't handle
|
||||
talking to these interfaces);
|
||||
g = USB_QUIRK_DELAY_INIT (device needs a pause
|
||||
during initialization, after we read
|
||||
the device descriptor);
|
||||
h = USB_QUIRK_LINEAR_UFRAME_INTR_BINTERVAL (For
|
||||
high speed and super speed interrupt
|
||||
endpoints, the USB 2.0 and USB 3.0 spec
|
||||
require the interval in microframes (1
|
||||
microframe = 125 microseconds) to be
|
||||
calculated as interval = 2 ^
|
||||
(bInterval-1).
|
||||
Devices with this quirk report their
|
||||
bInterval as the result of this
|
||||
calculation instead of the exponent
|
||||
variable used in the calculation);
|
||||
i = USB_QUIRK_DEVICE_QUALIFIER (device can't
|
||||
handle device_qualifier descriptor
|
||||
requests);
|
||||
j = USB_QUIRK_IGNORE_REMOTE_WAKEUP (device
|
||||
generates spurious wakeup, ignore
|
||||
remote wakeup capability);
|
||||
k = USB_QUIRK_NO_LPM (device can't handle Link
|
||||
Power Management);
|
||||
l = USB_QUIRK_LINEAR_FRAME_INTR_BINTERVAL
|
||||
(Device reports its bInterval as linear
|
||||
frames instead of the USB 2.0
|
||||
calculation);
|
||||
m = USB_QUIRK_DISCONNECT_SUSPEND (Device needs
|
||||
to be disconnected before suspend to
|
||||
prevent spurious wakeup);
|
||||
n = USB_QUIRK_DELAY_CTRL_MSG (Device needs a
|
||||
pause after every control message);
|
||||
Example: quirks=0781:5580:bk,0a5c:5834:gij
|
||||
|
||||
usbhid.mousepoll=
|
||||
[USBHID] The interval which mice are to be polled at.
|
||||
|
||||
|
@ -74,6 +74,29 @@ Example:
|
||||
reboot-offset = <0x4>;
|
||||
};
|
||||
|
||||
-----------------------------------------------------------------------
|
||||
Hisilicon Hi3798CV200 Peripheral Controller
|
||||
|
||||
The Hi3798CV200 Peripheral Controller controls peripherals, queries
|
||||
their status, and configures some functions of peripherals.
|
||||
|
||||
Required properties:
|
||||
- compatible: Should contain "hisilicon,hi3798cv200-perictrl", "syscon"
|
||||
and "simple-mfd".
|
||||
- reg: Register address and size of Peripheral Controller.
|
||||
- #address-cells: Should be 1.
|
||||
- #size-cells: Should be 1.
|
||||
|
||||
Examples:
|
||||
|
||||
perictrl: peripheral-controller@8a20000 {
|
||||
compatible = "hisilicon,hi3798cv200-perictrl", "syscon",
|
||||
"simple-mfd";
|
||||
reg = <0x8a20000 0x1000>;
|
||||
#address-cells = <1>;
|
||||
#size-cells = <1>;
|
||||
};
|
||||
|
||||
-----------------------------------------------------------------------
|
||||
Hisilicon Hi6220 system controller
|
||||
|
||||
|
@ -6,6 +6,10 @@ Required properties:
|
||||
- #phys-cells: must be 0 (see phy-bindings.txt in this directory)
|
||||
|
||||
Optional properties:
|
||||
- clocks: a phandle to the clock of this PHY
|
||||
- clock-names: must be "phy"
|
||||
- resets: a phandle to the reset line of this PHY
|
||||
- reset-names: must be "phy"
|
||||
- phy-supply: see phy-bindings.txt in this directory
|
||||
|
||||
|
||||
|
31
Documentation/devicetree/bindings/phy/meson-gxl-usb3-phy.txt
Normal file
31
Documentation/devicetree/bindings/phy/meson-gxl-usb3-phy.txt
Normal file
@ -0,0 +1,31 @@
|
||||
* Amlogic Meson GXL and GXM USB3 PHY and OTG detection binding
|
||||
|
||||
Required properties:
|
||||
- compatible: Should be "amlogic,meson-gxl-usb3-phy"
|
||||
- #phys-cells: must be 0 (see phy-bindings.txt in this directory)
|
||||
- reg: The base address and length of the registers
|
||||
- interrupts: the interrupt specifier for the OTG detection
|
||||
- clocks: phandles to the clocks for
|
||||
- the USB3 PHY
|
||||
- and peripheral mode/OTG detection
|
||||
- clock-names: must contain "phy" and "peripheral"
|
||||
- resets: phandle to the reset lines for:
|
||||
- the USB3 PHY and
|
||||
- peripheral mode/OTG detection
|
||||
- reset-names: must contain "phy" and "peripheral"
|
||||
|
||||
Optional properties:
|
||||
- phy-supply: see phy-bindings.txt in this directory
|
||||
|
||||
|
||||
Example:
|
||||
usb3_phy0: phy@78080 {
|
||||
compatible = "amlogic,meson-gxl-usb3-phy";
|
||||
#phy-cells = <0>;
|
||||
reg = <0x0 0x78080 0x0 0x20>;
|
||||
interrupts = <GIC_SPI 16 IRQ_TYPE_LEVEL_HIGH>;
|
||||
clocks = <&clkc CLKID_USB_OTG>, <&clkc_AO CLKID_AO_CEC_32K>;
|
||||
clock-names = "phy", "peripheral";
|
||||
resets = <&reset RESET_USB_OTG>, <&reset RESET_USB_OTG>;
|
||||
reset-names = "phy", "peripheral";
|
||||
};
|
@ -0,0 +1,59 @@
|
||||
HiSilicon STB PCIE/SATA/USB3 PHY
|
||||
|
||||
Required properties:
|
||||
- compatible: Should be "hisilicon,hi3798cv200-combphy"
|
||||
- reg: Should be the address space for COMBPHY configuration and state
|
||||
registers in peripheral controller, e.g. PERI_COMBPHY0_CFG and
|
||||
PERI_COMBPHY0_STATE for COMBPHY0 Hi3798CV200 SoC.
|
||||
- #phy-cells: Should be 1. The cell number is used to select the phy mode
|
||||
as defined in <dt-bindings/phy/phy.h>.
|
||||
- clocks: The phandle to clock provider and clock specifier pair.
|
||||
- resets: The phandle to reset controller and reset specifier pair.
|
||||
|
||||
Refer to phy/phy-bindings.txt for the generic PHY binding properties.
|
||||
|
||||
Optional properties:
|
||||
- hisilicon,fixed-mode: If the phy device doesn't support mode select
|
||||
but a fixed mode setting, the property should be present to specify
|
||||
the particular mode.
|
||||
- hisilicon,mode-select-bits: If the phy device support mode select,
|
||||
this property should be present to specify the register bits in
|
||||
peripheral controller, as a 3 integers tuple:
|
||||
<register_offset bit_shift bit_mask>.
|
||||
|
||||
Notes:
|
||||
- Between hisilicon,fixed-mode and hisilicon,mode-select-bits, one and only
|
||||
one of them should be present.
|
||||
- The device node should be a child of peripheral controller that contains
|
||||
COMBPHY configuration/state and PERI_CTRL register used to select PHY mode.
|
||||
Refer to arm/hisilicon/hisilicon.txt for the parent peripheral controller
|
||||
bindings.
|
||||
|
||||
Examples:
|
||||
|
||||
perictrl: peripheral-controller@8a20000 {
|
||||
compatible = "hisilicon,hi3798cv200-perictrl", "syscon",
|
||||
"simple-mfd";
|
||||
reg = <0x8a20000 0x1000>;
|
||||
#address-cells = <1>;
|
||||
#size-cells = <1>;
|
||||
ranges = <0x0 0x8a20000 0x1000>;
|
||||
|
||||
combphy0: phy@850 {
|
||||
compatible = "hisilicon,hi3798cv200-combphy";
|
||||
reg = <0x850 0x8>;
|
||||
#phy-cells = <1>;
|
||||
clocks = <&crg HISTB_COMBPHY0_CLK>;
|
||||
resets = <&crg 0x188 4>;
|
||||
hisilicon,fixed-mode = <PHY_TYPE_USB3>;
|
||||
};
|
||||
|
||||
combphy1: phy@858 {
|
||||
compatible = "hisilicon,hi3798cv200-combphy";
|
||||
reg = <0x858 0x8>;
|
||||
#phy-cells = <1>;
|
||||
clocks = <&crg HISTB_COMBPHY1_CLK>;
|
||||
resets = <&crg 0x188 12>;
|
||||
hisilicon,mode-select-bits = <0x0008 11 (0x3 << 11)>;
|
||||
};
|
||||
};
|
71
Documentation/devicetree/bindings/phy/phy-hisi-inno-usb2.txt
Normal file
71
Documentation/devicetree/bindings/phy/phy-hisi-inno-usb2.txt
Normal file
@ -0,0 +1,71 @@
|
||||
Device tree bindings for HiSilicon INNO USB2 PHY
|
||||
|
||||
Required properties:
|
||||
- compatible: Should be one of the following strings:
|
||||
"hisilicon,inno-usb2-phy",
|
||||
"hisilicon,hi3798cv200-usb2-phy".
|
||||
- reg: Should be the address space for PHY configuration register in peripheral
|
||||
controller, e.g. PERI_USB0 for USB 2.0 PHY01 on Hi3798CV200 SoC.
|
||||
- clocks: The phandle and clock specifier pair for INNO USB2 PHY device
|
||||
reference clock.
|
||||
- resets: The phandle and reset specifier pair for INNO USB2 PHY device reset
|
||||
signal.
|
||||
- #address-cells: Must be 1.
|
||||
- #size-cells: Must be 0.
|
||||
|
||||
The INNO USB2 PHY device should be a child node of peripheral controller that
|
||||
contains the PHY configuration register, and each device suppports up to 2 PHY
|
||||
ports which are represented as child nodes of INNO USB2 PHY device.
|
||||
|
||||
Required properties for PHY port node:
|
||||
- reg: The PHY port instance number.
|
||||
- #phy-cells: Defined by generic PHY bindings. Must be 0.
|
||||
- resets: The phandle and reset specifier pair for PHY port reset signal.
|
||||
|
||||
Refer to phy/phy-bindings.txt for the generic PHY binding properties
|
||||
|
||||
Example:
|
||||
|
||||
perictrl: peripheral-controller@8a20000 {
|
||||
compatible = "hisilicon,hi3798cv200-perictrl", "simple-mfd";
|
||||
reg = <0x8a20000 0x1000>;
|
||||
#address-cells = <1>;
|
||||
#size-cells = <1>;
|
||||
ranges = <0x0 0x8a20000 0x1000>;
|
||||
|
||||
usb2_phy1: usb2-phy@120 {
|
||||
compatible = "hisilicon,hi3798cv200-usb2-phy";
|
||||
reg = <0x120 0x4>;
|
||||
clocks = <&crg HISTB_USB2_PHY1_REF_CLK>;
|
||||
resets = <&crg 0xbc 4>;
|
||||
#address-cells = <1>;
|
||||
#size-cells = <0>;
|
||||
|
||||
usb2_phy1_port0: phy@0 {
|
||||
reg = <0>;
|
||||
#phy-cells = <0>;
|
||||
resets = <&crg 0xbc 8>;
|
||||
};
|
||||
|
||||
usb2_phy1_port1: phy@1 {
|
||||
reg = <1>;
|
||||
#phy-cells = <0>;
|
||||
resets = <&crg 0xbc 9>;
|
||||
};
|
||||
};
|
||||
|
||||
usb2_phy2: usb2-phy@124 {
|
||||
compatible = "hisilicon,hi3798cv200-usb2-phy";
|
||||
reg = <0x124 0x4>;
|
||||
clocks = <&crg HISTB_USB2_PHY2_REF_CLK>;
|
||||
resets = <&crg 0xbc 6>;
|
||||
#address-cells = <1>;
|
||||
#size-cells = <0>;
|
||||
|
||||
usb2_phy2_port0: phy@0 {
|
||||
reg = <0>;
|
||||
#phy-cells = <0>;
|
||||
resets = <&crg 0xbc 10>;
|
||||
};
|
||||
};
|
||||
};
|
@ -0,0 +1,29 @@
|
||||
Device tree binding documentation for Motorola Mapphone MDM6600 USB PHY
|
||||
|
||||
Required properties:
|
||||
- compatible Must be "motorola,mapphone-mdm6600"
|
||||
- enable-gpios GPIO to enable the USB PHY
|
||||
- power-gpios GPIO to power on the device
|
||||
- reset-gpios GPIO to reset the device
|
||||
- motorola,mode-gpios Two GPIOs to configure MDM6600 USB start-up mode for
|
||||
normal mode versus USB flashing mode
|
||||
- motorola,cmd-gpios Three GPIOs to control the power state of the MDM6600
|
||||
- motorola,status-gpios Three GPIOs to read the power state of the MDM6600
|
||||
|
||||
Example:
|
||||
|
||||
usb-phy {
|
||||
compatible = "motorola,mapphone-mdm6600";
|
||||
enable-gpios = <&gpio3 31 GPIO_ACTIVE_LOW>;
|
||||
power-gpios = <&gpio2 22 GPIO_ACTIVE_HIGH>;
|
||||
reset-gpios = <&gpio2 17 GPIO_ACTIVE_HIGH>;
|
||||
motorola,mode-gpios = <&gpio5 20 GPIO_ACTIVE_HIGH>,
|
||||
<&gpio5 21 GPIO_ACTIVE_HIGH>;
|
||||
motorola,cmd-gpios = <&gpio4 7 GPIO_ACTIVE_HIGH>,
|
||||
<&gpio4 8 GPIO_ACTIVE_HIGH>,
|
||||
<&gpio5 14 GPIO_ACTIVE_HIGH>;
|
||||
motorola,status-gpios = <&gpio2 20 GPIO_ACTIVE_HIGH>,
|
||||
<&gpio2 21 GPIO_ACTIVE_HIGH>,
|
||||
<&gpio2 23 GPIO_ACTIVE_HIGH>;
|
||||
#phy-cells = <0>;
|
||||
};
|
@ -27,6 +27,10 @@ Optional properties (controller (parent) node):
|
||||
- reg : offset and length of register shared by multiple ports,
|
||||
exclude port's private register. It is needed on mt2701
|
||||
and mt8173, but not on mt2712.
|
||||
- mediatek,src-ref-clk-mhz : frequency of reference clock for slew rate
|
||||
calibrate
|
||||
- mediatek,src-coef : coefficient for slew rate calibrate, depends on
|
||||
SoC process
|
||||
|
||||
Required properties (port (child) node):
|
||||
- reg : address and length of the register set for the port.
|
||||
|
@ -14,25 +14,9 @@ Required properties:
|
||||
- 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>;
|
||||
Optional properties:
|
||||
- extcon : extcon specifier for the Power Delivery
|
||||
|
||||
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,
|
||||
@ -43,6 +27,13 @@ Required nodes : a sub-node is required for each port the phy provides.
|
||||
Required properties (port (child) node):
|
||||
- #phy-cells : must be 0, See ./phy-bindings.txt for details.
|
||||
|
||||
Deprecated properties, do not use in new device tree sources, these
|
||||
properties are determined by the compatible value:
|
||||
- rockchip,typec-conn-dir
|
||||
- rockchip,usb3tousb2-en
|
||||
- rockchip,external-psm
|
||||
- rockchip,pipe-status
|
||||
|
||||
Example:
|
||||
tcphy0: phy@ff7c0000 {
|
||||
compatible = "rockchip,rk3399-typec-phy";
|
||||
@ -58,10 +49,6 @@ Example:
|
||||
<&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>;
|
||||
@ -86,10 +73,6 @@ Example:
|
||||
<&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>;
|
||||
|
73
Documentation/devicetree/bindings/phy/phy-stm32-usbphyc.txt
Normal file
73
Documentation/devicetree/bindings/phy/phy-stm32-usbphyc.txt
Normal file
@ -0,0 +1,73 @@
|
||||
STMicroelectronics STM32 USB HS PHY controller
|
||||
|
||||
The STM32 USBPHYC block contains a dual port High Speed UTMI+ PHY and a UTMI
|
||||
switch. It controls PHY configuration and status, and the UTMI+ switch that
|
||||
selects either OTG or HOST controller for the second PHY port. It also sets
|
||||
PLL configuration.
|
||||
|
||||
USBPHYC
|
||||
|_ PLL
|
||||
|
|
||||
|_ PHY port#1 _________________ HOST controller
|
||||
| _ |
|
||||
| / 1|________________|
|
||||
|_ PHY port#2 ----| |________________
|
||||
| \_0| |
|
||||
|_ UTMI switch_______| OTG controller
|
||||
|
||||
|
||||
Phy provider node
|
||||
=================
|
||||
|
||||
Required properties:
|
||||
- compatible: must be "st,stm32mp1-usbphyc"
|
||||
- reg: address and length of the usb phy control register set
|
||||
- clocks: phandle + clock specifier for the PLL phy clock
|
||||
- #address-cells: number of address cells for phys sub-nodes, must be <1>
|
||||
- #size-cells: number of size cells for phys sub-nodes, must be <0>
|
||||
|
||||
Optional properties:
|
||||
- assigned-clocks: phandle + clock specifier for the PLL phy clock
|
||||
- assigned-clock-parents: the PLL phy clock parent
|
||||
- resets: phandle + reset specifier
|
||||
|
||||
Required nodes: one sub-node per port the controller provides.
|
||||
|
||||
Phy sub-nodes
|
||||
==============
|
||||
|
||||
Required properties:
|
||||
- reg: phy port index
|
||||
- phy-supply: phandle to the regulator providing 3V3 power to the PHY,
|
||||
see phy-bindings.txt in the same directory.
|
||||
- vdda1v1-supply: phandle to the regulator providing 1V1 power to the PHY
|
||||
- vdda1v8-supply: phandle to the regulator providing 1V8 power to the PHY
|
||||
- #phy-cells: see phy-bindings.txt in the same directory, must be <0> for PHY
|
||||
port#1 and must be <1> for PHY port#2, to select USB controller
|
||||
|
||||
|
||||
Example:
|
||||
usbphyc: usb-phy@5a006000 {
|
||||
compatible = "st,stm32mp1-usbphyc";
|
||||
reg = <0x5a006000 0x1000>;
|
||||
clocks = <&rcc_clk USBPHY_K>;
|
||||
resets = <&rcc_rst USBPHY_R>;
|
||||
#address-cells = <1>;
|
||||
#size-cells = <0>;
|
||||
|
||||
usbphyc_port0: usb-phy@0 {
|
||||
reg = <0>;
|
||||
phy-supply = <&vdd_usb>;
|
||||
vdda1v1-supply = <®11>;
|
||||
vdda1v8-supply = <®18>
|
||||
#phy-cells = <0>;
|
||||
};
|
||||
|
||||
usbphyc_port1: usb-phy@1 {
|
||||
reg = <1>;
|
||||
phy-supply = <&vdd_usb>;
|
||||
vdda1v1-supply = <®11>;
|
||||
vdda1v8-supply = <®18>
|
||||
#phy-cells = <1>;
|
||||
};
|
||||
};
|
@ -8,7 +8,8 @@ Required properties:
|
||||
- compatible: compatible list, contains:
|
||||
"qcom,ipq8074-qmp-pcie-phy" for PCIe phy on IPQ8074
|
||||
"qcom,msm8996-qmp-pcie-phy" for 14nm PCIe phy on msm8996,
|
||||
"qcom,msm8996-qmp-usb3-phy" for 14nm USB3 phy on msm8996.
|
||||
"qcom,msm8996-qmp-usb3-phy" for 14nm USB3 phy on msm8996,
|
||||
"qcom,qmp-v3-usb3-phy" for USB3 QMP V3 phy.
|
||||
|
||||
- reg: offset and length of register set for PHY's common serdes block.
|
||||
|
||||
@ -25,10 +26,13 @@ Required properties:
|
||||
- clock-names: "cfg_ahb" for phy config clock,
|
||||
"aux" for phy aux clock,
|
||||
"ref" for 19.2 MHz ref clk,
|
||||
"com_aux" for phy common block aux clock,
|
||||
For "qcom,msm8996-qmp-pcie-phy" must contain:
|
||||
"aux", "cfg_ahb", "ref".
|
||||
For "qcom,msm8996-qmp-usb3-phy" must contain:
|
||||
"aux", "cfg_ahb", "ref".
|
||||
For "qcom,qmp-v3-usb3-phy" must contain:
|
||||
"aux", "cfg_ahb", "ref", "com_aux".
|
||||
|
||||
- resets: a list of phandles and reset controller specifier pairs,
|
||||
one for each entry in reset-names.
|
||||
|
@ -4,7 +4,10 @@ Qualcomm QUSB2 phy controller
|
||||
QUSB2 controller supports LS/FS/HS usb connectivity on Qualcomm chipsets.
|
||||
|
||||
Required properties:
|
||||
- compatible: compatible list, contains "qcom,msm8996-qusb2-phy".
|
||||
- compatible: compatible list, contains
|
||||
"qcom,msm8996-qusb2-phy" for 14nm PHY on msm8996,
|
||||
"qcom,qusb2-v2-phy" for QUSB2 V2 PHY.
|
||||
|
||||
- reg: offset and length of the PHY register set.
|
||||
- #phy-cells: must be 0.
|
||||
|
||||
|
@ -8,6 +8,8 @@ Required properties:
|
||||
SoC.
|
||||
"renesas,usb2-phy-r8a7796" if the device is a part of an R8A7796
|
||||
SoC.
|
||||
"renesas,usb2-phy-r8a77965" if the device is a part of an
|
||||
R8A77965 SoC.
|
||||
"renesas,usb2-phy-r8a77995" if the device is a part of an
|
||||
R8A77995 SoC.
|
||||
"renesas,rcar-gen3-usb2-phy" for a generic R-Car Gen3 compatible device.
|
||||
|
@ -11,6 +11,8 @@ Required properties:
|
||||
SoC.
|
||||
"renesas,r8a7796-usb3-phy" if the device is a part of an R8A7796
|
||||
SoC.
|
||||
"renesas,r8a77965-usb3-phy" if the device is a part of an
|
||||
R8A77965 SoC.
|
||||
"renesas,rcar-gen3-usb3-phy" for a generic R-Car Gen3 compatible
|
||||
device.
|
||||
|
||||
|
@ -11,6 +11,7 @@ Required properties:
|
||||
* allwinner,sun8i-a33-usb-phy
|
||||
* allwinner,sun8i-a83t-usb-phy
|
||||
* allwinner,sun8i-h3-usb-phy
|
||||
* allwinner,sun8i-r40-usb-phy
|
||||
* allwinner,sun8i-v3s-usb-phy
|
||||
* allwinner,sun50i-a64-usb-phy
|
||||
- reg : a list of offset + length pairs
|
||||
|
42
Documentation/devicetree/bindings/usb/amlogic,dwc3.txt
Normal file
42
Documentation/devicetree/bindings/usb/amlogic,dwc3.txt
Normal file
@ -0,0 +1,42 @@
|
||||
Amlogic Meson GX DWC3 USB SoC controller
|
||||
|
||||
Required properties:
|
||||
- compatible: depending on the SoC this should contain one of:
|
||||
* amlogic,meson-axg-dwc3
|
||||
* amlogic,meson-gxl-dwc3
|
||||
- clocks: a handle for the "USB general" clock
|
||||
- clock-names: must be "usb_general"
|
||||
- resets: a handle for the shared "USB OTG" reset line
|
||||
- reset-names: must be "usb_otg"
|
||||
|
||||
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/meson-gxl-usb2-phy.txt
|
||||
- Documentation/devicetree/bindings/phy/meson-gxl-usb3-phy.txt
|
||||
|
||||
Example device nodes:
|
||||
usb0: usb@ff500000 {
|
||||
compatible = "amlogic,meson-axg-dwc3";
|
||||
#address-cells = <2>;
|
||||
#size-cells = <2>;
|
||||
ranges;
|
||||
|
||||
clocks = <&clkc CLKID_USB>;
|
||||
clock-names = "usb_general";
|
||||
resets = <&reset RESET_USB_OTG>;
|
||||
reset-names = "usb_otg";
|
||||
|
||||
dwc3: dwc3@ff500000 {
|
||||
compatible = "snps,dwc3";
|
||||
reg = <0x0 0xff500000 0x0 0x100000>;
|
||||
interrupts = <GIC_SPI 30 IRQ_TYPE_LEVEL_HIGH>;
|
||||
dr_mode = "host";
|
||||
maximum-speed = "high-speed";
|
||||
snps,dis_u2_susphy_quirk;
|
||||
phys = <&usb3_phy>, <&usb2_phy0>;
|
||||
phy-names = "usb2-phy", "usb3-phy";
|
||||
};
|
||||
};
|
@ -57,6 +57,22 @@ Optional properties:
|
||||
- snps,quirk-frame-length-adjustment: Value for GFLADJ_30MHZ field of GFLADJ
|
||||
register for post-silicon frame length adjustment when the
|
||||
fladj_30mhz_sdbnd signal is invalid or incorrect.
|
||||
- snps,rx-thr-num-pkt-prd: periodic ESS RX packet threshold count - host mode
|
||||
only. Set this and rx-max-burst-prd to a valid,
|
||||
non-zero value 1-16 (DWC_usb31 programming guide
|
||||
section 1.2.4) to enable periodic ESS RX threshold.
|
||||
- snps,rx-max-burst-prd: max periodic ESS RX burst size - host mode only. Set
|
||||
this and rx-thr-num-pkt-prd to a valid, non-zero value
|
||||
1-16 (DWC_usb31 programming guide section 1.2.4) to
|
||||
enable periodic ESS RX threshold.
|
||||
- snps,tx-thr-num-pkt-prd: periodic ESS TX packet threshold count - host mode
|
||||
only. Set this and tx-max-burst-prd to a valid,
|
||||
non-zero value 1-16 (DWC_usb31 programming guide
|
||||
section 1.2.3) to enable periodic ESS TX threshold.
|
||||
- snps,tx-max-burst-prd: max periodic ESS TX burst size - host mode only. Set
|
||||
this and tx-thr-num-pkt-prd to a valid, non-zero value
|
||||
1-16 (DWC_usb31 programming guide section 1.2.3) to
|
||||
enable periodic ESS TX threshold.
|
||||
|
||||
- <DEPRECATED> tx-fifo-resize: determines if the FIFO *has* to be reallocated.
|
||||
|
||||
|
@ -32,7 +32,7 @@ Required properties:
|
||||
"mcu_ck": mcu_bus clock for register access,
|
||||
"dma_ck": dma_bus clock for data transfer by DMA
|
||||
|
||||
- phys : a list of phandle + phy specifier pairs
|
||||
- phys : see usb-hcd.txt in the current directory
|
||||
|
||||
Optional properties:
|
||||
- wakeup-source : enable USB remote wakeup;
|
||||
@ -52,6 +52,9 @@ Optional properties:
|
||||
See: Documentation/devicetree/bindings/pinctrl/pinctrl-bindings.txt
|
||||
- imod-interval-ns: default interrupt moderation interval is 5000ns
|
||||
|
||||
additionally the properties from usb-hcd.txt (in the current directory) are
|
||||
supported.
|
||||
|
||||
Example:
|
||||
usb30: usb@11270000 {
|
||||
compatible = "mediatek,mt8173-xhci";
|
||||
|
@ -17,7 +17,7 @@ Required properties:
|
||||
- clock-names : must contain "sys_ck" for clock of controller,
|
||||
the following clocks are optional:
|
||||
"ref_ck", "mcu_ck" and "dam_ck";
|
||||
- phys : a list of phandle + phy specifier pairs
|
||||
- phys : see usb-hcd.txt in the current directory
|
||||
- dr_mode : should be one of "host", "peripheral" or "otg",
|
||||
refer to usb/generic.txt
|
||||
|
||||
@ -53,6 +53,9 @@ Optional properties:
|
||||
- mediatek,u3p-dis-msk : mask to disable u3ports, bit0 for u3port0,
|
||||
bit1 for u3port1, ... etc;
|
||||
|
||||
additionally the properties from usb-hcd.txt (in the current directory) are
|
||||
supported.
|
||||
|
||||
Sub-nodes:
|
||||
The xhci should be added as subnode to mtu3 as shown in the following example
|
||||
if host mode is enabled. The DT binding details of xhci can be found in:
|
||||
|
@ -16,10 +16,12 @@ Optional properties:
|
||||
- has-transaction-translator : boolean, set this if EHCI have a Transaction
|
||||
Translator built into the root hub.
|
||||
- clocks : a list of phandle + clock specifier pairs
|
||||
- phys : phandle + phy specifier pair
|
||||
- phy-names : "usb"
|
||||
- phys : see usb-hcd.txt in the current directory
|
||||
- resets : phandle + reset specifier pair
|
||||
|
||||
additionally the properties from usb-hcd.txt (in the current directory) are
|
||||
supported.
|
||||
|
||||
Example (Sequoia 440EPx):
|
||||
ehci@e0000300 {
|
||||
compatible = "ibm,usb-ehci-440epx", "usb-ehci";
|
||||
|
9
Documentation/devicetree/bindings/usb/usb-hcd.txt
Normal file
9
Documentation/devicetree/bindings/usb/usb-hcd.txt
Normal file
@ -0,0 +1,9 @@
|
||||
Generic USB HCD (Host Controller Device) Properties
|
||||
|
||||
Optional properties:
|
||||
- phys: a list of all USB PHYs on this HCD
|
||||
|
||||
Example:
|
||||
&usb1 {
|
||||
phys = <&usb2_phy1>, <&usb3_phy1>;
|
||||
};
|
@ -13,10 +13,12 @@ Optional properties:
|
||||
- remote-wakeup-connected: remote wakeup is wired on the platform
|
||||
- num-ports : u32, to override the detected port count
|
||||
- clocks : a list of phandle + clock specifier pairs
|
||||
- phys : phandle + phy specifier pair
|
||||
- phy-names : "usb"
|
||||
- phys : see usb-hcd.txt in the current directory
|
||||
- resets : a list of phandle + reset specifier pairs
|
||||
|
||||
additionally the properties from usb-hcd.txt (in the current directory) are
|
||||
supported.
|
||||
|
||||
Example:
|
||||
|
||||
ohci0: usb@1c14400 {
|
||||
|
@ -6,6 +6,9 @@ Required properties:
|
||||
- reg : Should contain 1 register ranges(address and length)
|
||||
- interrupts : UHCI controller interrupt
|
||||
|
||||
additionally the properties from usb-hcd.txt (in the current directory) are
|
||||
supported.
|
||||
|
||||
Example:
|
||||
|
||||
uhci@d8007b00 {
|
||||
|
@ -33,6 +33,11 @@ Optional properties:
|
||||
- usb3-lpm-capable: determines if platform is USB3 LPM capable
|
||||
- quirk-broken-port-ped: set if the controller has broken port disable mechanism
|
||||
- imod-interval-ns: default interrupt moderation interval is 5000ns
|
||||
- phys : see usb-hcd.txt in the current directory
|
||||
|
||||
additionally the properties from usb-hcd.txt (in the current directory) are
|
||||
supported.
|
||||
|
||||
|
||||
Example:
|
||||
usb@f0931000 {
|
||||
|
43
Documentation/driver-api/device_connection.rst
Normal file
43
Documentation/driver-api/device_connection.rst
Normal file
@ -0,0 +1,43 @@
|
||||
==================
|
||||
Device connections
|
||||
==================
|
||||
|
||||
Introduction
|
||||
------------
|
||||
|
||||
Devices often have connections to other devices that are outside of the direct
|
||||
child/parent relationship. A serial or network communication controller, which
|
||||
could be a PCI device, may need to be able to get a reference to its PHY
|
||||
component, which could be attached for example to the I2C bus. Some device
|
||||
drivers need to be able to control the clocks or the GPIOs for their devices,
|
||||
and so on.
|
||||
|
||||
Device connections are generic descriptions of any type of connection between
|
||||
two separate devices.
|
||||
|
||||
Device connections alone do not create a dependency between the two devices.
|
||||
They are only descriptions which are not tied to either of the devices directly.
|
||||
A dependency between the two devices exists only if one of the two endpoint
|
||||
devices requests a reference to the other. The descriptions themselves can be
|
||||
defined in firmware (not yet supported) or they can be built-in.
|
||||
|
||||
Usage
|
||||
-----
|
||||
|
||||
Device connections should exist before device ``->probe`` callback is called for
|
||||
either endpoint device in the description. If the connections are defined in
|
||||
firmware, this is not a problem. It should be considered if the connection
|
||||
descriptions are "built-in", and need to be added separately.
|
||||
|
||||
The connection description consists of the names of the two devices with the
|
||||
connection, i.e. the endpoints, and unique identifier for the connection which
|
||||
is needed if there are multiple connections between the two devices.
|
||||
|
||||
After a description exists, the devices in it can request reference to the other
|
||||
endpoint device, or they can request the description itself.
|
||||
|
||||
API
|
||||
---
|
||||
|
||||
.. kernel-doc:: drivers/base/devcon.c
|
||||
: functions: device_connection_find_match device_connection_find device_connection_add device_connection_remove
|
@ -61,7 +61,7 @@ Registering the ports
|
||||
The port drivers will describe every Type-C port they control with struct
|
||||
typec_capability data structure, and register them with the following API:
|
||||
|
||||
.. kernel-doc:: drivers/usb/typec/typec.c
|
||||
.. kernel-doc:: drivers/usb/typec/class.c
|
||||
:functions: typec_register_port typec_unregister_port
|
||||
|
||||
When registering the ports, the prefer_role member in struct typec_capability
|
||||
@ -80,7 +80,7 @@ typec_partner_desc. The class copies the details of the partner during
|
||||
registration. The class offers the following API for registering/unregistering
|
||||
partners.
|
||||
|
||||
.. kernel-doc:: drivers/usb/typec/typec.c
|
||||
.. kernel-doc:: drivers/usb/typec/class.c
|
||||
:functions: typec_register_partner typec_unregister_partner
|
||||
|
||||
The class will provide a handle to struct typec_partner if the registration was
|
||||
@ -92,7 +92,7 @@ should include handle to struct usb_pd_identity instance. The class will then
|
||||
create a sysfs directory for the identity under the partner device. The result
|
||||
of Discover Identity command can then be reported with the following API:
|
||||
|
||||
.. kernel-doc:: drivers/usb/typec/typec.c
|
||||
.. kernel-doc:: drivers/usb/typec/class.c
|
||||
:functions: typec_partner_set_identity
|
||||
|
||||
Registering Cables
|
||||
@ -113,7 +113,7 @@ typec_cable_desc and about a plug in struct typec_plug_desc. The class copies
|
||||
the details during registration. The class offers the following API for
|
||||
registering/unregistering cables and their plugs:
|
||||
|
||||
.. kernel-doc:: drivers/usb/typec/typec.c
|
||||
.. kernel-doc:: drivers/usb/typec/class.c
|
||||
:functions: typec_register_cable typec_unregister_cable typec_register_plug typec_unregister_plug
|
||||
|
||||
The class will provide a handle to struct typec_cable and struct typec_plug if
|
||||
@ -125,7 +125,7 @@ include handle to struct usb_pd_identity instance. The class will then create a
|
||||
sysfs directory for the identity under the cable device. The result of Discover
|
||||
Identity command can then be reported with the following API:
|
||||
|
||||
.. kernel-doc:: drivers/usb/typec/typec.c
|
||||
.. kernel-doc:: drivers/usb/typec/class.c
|
||||
:functions: typec_cable_set_identity
|
||||
|
||||
Notifications
|
||||
@ -135,7 +135,7 @@ When the partner has executed a role change, or when the default roles change
|
||||
during connection of a partner or cable, the port driver must use the following
|
||||
APIs to report it to the class:
|
||||
|
||||
.. kernel-doc:: drivers/usb/typec/typec.c
|
||||
.. kernel-doc:: drivers/usb/typec/class.c
|
||||
:functions: typec_set_data_role typec_set_pwr_role typec_set_vconn_role typec_set_pwr_opmode
|
||||
|
||||
Alternate Modes
|
||||
@ -150,7 +150,7 @@ and struct typec_altmode_desc which is a container for all the supported modes.
|
||||
Ports that support Alternate Modes need to register each SVID they support with
|
||||
the following API:
|
||||
|
||||
.. kernel-doc:: drivers/usb/typec/typec.c
|
||||
.. kernel-doc:: drivers/usb/typec/class.c
|
||||
:functions: typec_port_register_altmode
|
||||
|
||||
If a partner or cable plug provides a list of SVIDs as response to USB Power
|
||||
@ -159,12 +159,12 @@ registered.
|
||||
|
||||
API for the partners:
|
||||
|
||||
.. kernel-doc:: drivers/usb/typec/typec.c
|
||||
.. kernel-doc:: drivers/usb/typec/class.c
|
||||
:functions: typec_partner_register_altmode
|
||||
|
||||
API for the Cable Plugs:
|
||||
|
||||
.. kernel-doc:: drivers/usb/typec/typec.c
|
||||
.. kernel-doc:: drivers/usb/typec/class.c
|
||||
:functions: typec_plug_register_altmode
|
||||
|
||||
So ports, partners and cable plugs will register the alternate modes with their
|
||||
@ -172,11 +172,62 @@ own functions, but the registration will always return a handle to struct
|
||||
typec_altmode on success, or NULL. The unregistration will happen with the same
|
||||
function:
|
||||
|
||||
.. kernel-doc:: drivers/usb/typec/typec.c
|
||||
.. kernel-doc:: drivers/usb/typec/class.c
|
||||
:functions: typec_unregister_altmode
|
||||
|
||||
If a partner or cable plug enters or exits a mode, the port driver needs to
|
||||
notify the class with the following API:
|
||||
|
||||
.. kernel-doc:: drivers/usb/typec/typec.c
|
||||
.. kernel-doc:: drivers/usb/typec/class.c
|
||||
:functions: typec_altmode_update_active
|
||||
|
||||
Multiplexer/DeMultiplexer Switches
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
USB Type-C connectors may have one or more mux/demux switches behind them. Since
|
||||
the plugs can be inserted right-side-up or upside-down, a switch is needed to
|
||||
route the correct data pairs from the connector to the USB controllers. If
|
||||
Alternate or Accessory Modes are supported, another switch is needed that can
|
||||
route the pins on the connector to some other component besides USB. USB Type-C
|
||||
Connector Class supplies an API for registering those switches.
|
||||
|
||||
.. kernel-doc:: drivers/usb/typec/mux.c
|
||||
:functions: typec_switch_register typec_switch_unregister typec_mux_register typec_mux_unregister
|
||||
|
||||
In most cases the same physical mux will handle both the orientation and mode.
|
||||
However, as the port drivers will be responsible for the orientation, and the
|
||||
alternate mode drivers for the mode, the two are always separated into their
|
||||
own logical components: "mux" for the mode and "switch" for the orientation.
|
||||
|
||||
When a port is registered, USB Type-C Connector Class requests both the mux and
|
||||
the switch for the port. The drivers can then use the following API for
|
||||
controlling them:
|
||||
|
||||
.. kernel-doc:: drivers/usb/typec/class.c
|
||||
:functions: typec_set_orientation typec_set_mode
|
||||
|
||||
If the connector is dual-role capable, there may also be a switch for the data
|
||||
role. USB Type-C Connector Class does not supply separate API for them. The
|
||||
port drivers can use USB Role Class API with those.
|
||||
|
||||
Illustration of the muxes behind a connector that supports an alternate mode:
|
||||
|
||||
------------------------
|
||||
| Connector |
|
||||
------------------------
|
||||
| |
|
||||
------------------------
|
||||
\ Orientation /
|
||||
--------------------
|
||||
|
|
||||
--------------------
|
||||
/ Mode \
|
||||
------------------------
|
||||
/ \
|
||||
------------------------ --------------------
|
||||
| Alt Mode | / USB Role \
|
||||
------------------------ ------------------------
|
||||
/ \
|
||||
------------------------ ------------------------
|
||||
| USB Host | | USB Device |
|
||||
------------------------ ------------------------
|
||||
|
14
MAINTAINERS
14
MAINTAINERS
@ -4079,7 +4079,7 @@ S: Supported
|
||||
F: drivers/mtd/nand/denali*
|
||||
|
||||
DESIGNWARE USB2 DRD IP DRIVER
|
||||
M: John Youn <johnyoun@synopsys.com>
|
||||
M: Minas Harutyunyan <hminas@synopsys.com>
|
||||
L: linux-usb@vger.kernel.org
|
||||
T: git git://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb.git
|
||||
S: Maintained
|
||||
@ -14476,6 +14476,12 @@ S: Maintained
|
||||
F: Documentation/hid/hiddev.txt
|
||||
F: drivers/hid/usbhid/
|
||||
|
||||
USB INTEL XHCI ROLE MUX DRIVER
|
||||
M: Hans de Goede <hdegoede@redhat.com>
|
||||
L: linux-usb@vger.kernel.org
|
||||
S: Maintained
|
||||
F: drivers/usb/roles/intel-xhci-usb-role-switch.c
|
||||
|
||||
USB ISP116X DRIVER
|
||||
M: Olav Kongas <ok@artecdesign.ee>
|
||||
L: linux-usb@vger.kernel.org
|
||||
@ -14606,6 +14612,12 @@ F: drivers/usb/
|
||||
F: include/linux/usb.h
|
||||
F: include/linux/usb/
|
||||
|
||||
USB TYPEC PI3USB30532 MUX DRIVER
|
||||
M: Hans de Goede <hdegoede@redhat.com>
|
||||
L: linux-usb@vger.kernel.org
|
||||
S: Maintained
|
||||
F: drivers/usb/typec/mux/pi3usb30532.c
|
||||
|
||||
USB TYPEC SUBSYSTEM
|
||||
M: Heikki Krogerus <heikki.krogerus@linux.intel.com>
|
||||
L: linux-usb@vger.kernel.org
|
||||
|
@ -200,6 +200,7 @@ config ATH79
|
||||
select SYS_SUPPORTS_MIPS16
|
||||
select SYS_SUPPORTS_ZBOOT_UART_PROM
|
||||
select USE_OF
|
||||
select USB_EHCI_ROOT_HUB_TT if USB_EHCI_HCD_PLATFORM
|
||||
help
|
||||
Support for the Atheros AR71XX/AR724X/AR913X SoCs.
|
||||
|
||||
|
@ -5,7 +5,8 @@ obj-y := component.o core.o bus.o dd.o syscore.o \
|
||||
driver.o class.o platform.o \
|
||||
cpu.o firmware.o init.o map.o devres.o \
|
||||
attribute_container.o transport_class.o \
|
||||
topology.o container.o property.o cacheinfo.o
|
||||
topology.o container.o property.o cacheinfo.o \
|
||||
devcon.o
|
||||
obj-$(CONFIG_DEVTMPFS) += devtmpfs.o
|
||||
obj-$(CONFIG_DMA_CMA) += dma-contiguous.o
|
||||
obj-y += power/
|
||||
|
136
drivers/base/devcon.c
Normal file
136
drivers/base/devcon.c
Normal file
@ -0,0 +1,136 @@
|
||||
// SPDX-License-Identifier: GPL-2.0
|
||||
/**
|
||||
* Device connections
|
||||
*
|
||||
* Copyright (C) 2018 Intel Corporation
|
||||
* Author: Heikki Krogerus <heikki.krogerus@linux.intel.com>
|
||||
*/
|
||||
|
||||
#include <linux/device.h>
|
||||
|
||||
static DEFINE_MUTEX(devcon_lock);
|
||||
static LIST_HEAD(devcon_list);
|
||||
|
||||
/**
|
||||
* device_connection_find_match - Find physical connection to a device
|
||||
* @dev: Device with the connection
|
||||
* @con_id: Identifier for the connection
|
||||
* @data: Data for the match function
|
||||
* @match: Function to check and convert the connection description
|
||||
*
|
||||
* Find a connection with unique identifier @con_id between @dev and another
|
||||
* device. @match will be used to convert the connection description to data the
|
||||
* caller is expecting to be returned.
|
||||
*/
|
||||
void *device_connection_find_match(struct device *dev, const char *con_id,
|
||||
void *data,
|
||||
void *(*match)(struct device_connection *con,
|
||||
int ep, void *data))
|
||||
{
|
||||
const char *devname = dev_name(dev);
|
||||
struct device_connection *con;
|
||||
void *ret = NULL;
|
||||
int ep;
|
||||
|
||||
if (!match)
|
||||
return NULL;
|
||||
|
||||
mutex_lock(&devcon_lock);
|
||||
|
||||
list_for_each_entry(con, &devcon_list, list) {
|
||||
ep = match_string(con->endpoint, 2, devname);
|
||||
if (ep < 0)
|
||||
continue;
|
||||
|
||||
if (con_id && strcmp(con->id, con_id))
|
||||
continue;
|
||||
|
||||
ret = match(con, !ep, data);
|
||||
if (ret)
|
||||
break;
|
||||
}
|
||||
|
||||
mutex_unlock(&devcon_lock);
|
||||
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(device_connection_find_match);
|
||||
|
||||
extern struct bus_type platform_bus_type;
|
||||
extern struct bus_type pci_bus_type;
|
||||
extern struct bus_type i2c_bus_type;
|
||||
extern struct bus_type spi_bus_type;
|
||||
|
||||
static struct bus_type *generic_match_buses[] = {
|
||||
&platform_bus_type,
|
||||
#ifdef CONFIG_PCI
|
||||
&pci_bus_type,
|
||||
#endif
|
||||
#ifdef CONFIG_I2C
|
||||
&i2c_bus_type,
|
||||
#endif
|
||||
#ifdef CONFIG_SPI_MASTER
|
||||
&spi_bus_type,
|
||||
#endif
|
||||
NULL,
|
||||
};
|
||||
|
||||
/* This tries to find the device from the most common bus types by name. */
|
||||
static void *generic_match(struct device_connection *con, int ep, void *data)
|
||||
{
|
||||
struct bus_type *bus;
|
||||
struct device *dev;
|
||||
|
||||
for (bus = generic_match_buses[0]; bus; bus++) {
|
||||
dev = bus_find_device_by_name(bus, NULL, con->endpoint[ep]);
|
||||
if (dev)
|
||||
return dev;
|
||||
}
|
||||
|
||||
/*
|
||||
* We only get called if a connection was found, tell the caller to
|
||||
* wait for the other device to show up.
|
||||
*/
|
||||
return ERR_PTR(-EPROBE_DEFER);
|
||||
}
|
||||
|
||||
/**
|
||||
* device_connection_find - Find two devices connected together
|
||||
* @dev: Device with the connection
|
||||
* @con_id: Identifier for the connection
|
||||
*
|
||||
* Find a connection with unique identifier @con_id between @dev and
|
||||
* another device. On success returns handle to the device that is connected
|
||||
* to @dev, with the reference count for the found device incremented. Returns
|
||||
* NULL if no matching connection was found, or ERR_PTR(-EPROBE_DEFER) when a
|
||||
* connection was found but the other device has not been enumerated yet.
|
||||
*/
|
||||
struct device *device_connection_find(struct device *dev, const char *con_id)
|
||||
{
|
||||
return device_connection_find_match(dev, con_id, NULL, generic_match);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(device_connection_find);
|
||||
|
||||
/**
|
||||
* device_connection_add - Register a connection description
|
||||
* @con: The connection description to be registered
|
||||
*/
|
||||
void device_connection_add(struct device_connection *con)
|
||||
{
|
||||
mutex_lock(&devcon_lock);
|
||||
list_add_tail(&con->list, &devcon_list);
|
||||
mutex_unlock(&devcon_lock);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(device_connection_add);
|
||||
|
||||
/**
|
||||
* device_connections_remove - Unregister connection description
|
||||
* @con: The connection description to be unregistered
|
||||
*/
|
||||
void device_connection_remove(struct device_connection *con)
|
||||
{
|
||||
mutex_lock(&devcon_lock);
|
||||
list_del(&con->list);
|
||||
mutex_unlock(&devcon_lock);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(device_connection_remove);
|
@ -30,7 +30,8 @@ config EXTCON_ARIZONA
|
||||
|
||||
config EXTCON_AXP288
|
||||
tristate "X-Power AXP288 EXTCON support"
|
||||
depends on MFD_AXP20X && USB_PHY
|
||||
depends on MFD_AXP20X && USB_SUPPORT && X86
|
||||
select USB_ROLE_SWITCH
|
||||
help
|
||||
Say Y here to enable support for USB peripheral detection
|
||||
and USB MUX switching by X-Power AXP288 PMIC.
|
||||
|
@ -1,6 +1,7 @@
|
||||
/*
|
||||
* extcon-axp288.c - X-Power AXP288 PMIC extcon cable detection driver
|
||||
*
|
||||
* Copyright (c) 2017-2018 Hans de Goede <hdegoede@redhat.com>
|
||||
* Copyright (C) 2015 Intel Corporation
|
||||
* Author: Ramakrishna Pallala <ramakrishna.pallala@intel.com>
|
||||
*
|
||||
@ -14,6 +15,7 @@
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include <linux/acpi.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/io.h>
|
||||
@ -25,6 +27,11 @@
|
||||
#include <linux/extcon-provider.h>
|
||||
#include <linux/regmap.h>
|
||||
#include <linux/mfd/axp20x.h>
|
||||
#include <linux/usb/role.h>
|
||||
#include <linux/workqueue.h>
|
||||
|
||||
#include <asm/cpu_device_id.h>
|
||||
#include <asm/intel-family.h>
|
||||
|
||||
/* Power source status register */
|
||||
#define PS_STAT_VBUS_TRIGGER BIT(0)
|
||||
@ -97,9 +104,19 @@ struct axp288_extcon_info {
|
||||
struct device *dev;
|
||||
struct regmap *regmap;
|
||||
struct regmap_irq_chip_data *regmap_irqc;
|
||||
struct usb_role_switch *role_sw;
|
||||
struct work_struct role_work;
|
||||
int irq[EXTCON_IRQ_END];
|
||||
struct extcon_dev *edev;
|
||||
struct extcon_dev *id_extcon;
|
||||
struct notifier_block id_nb;
|
||||
unsigned int previous_cable;
|
||||
bool vbus_attach;
|
||||
};
|
||||
|
||||
static const struct x86_cpu_id cherry_trail_cpu_ids[] = {
|
||||
{ X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_AIRMONT, X86_FEATURE_ANY },
|
||||
{}
|
||||
};
|
||||
|
||||
/* Power up/down reason string array */
|
||||
@ -137,20 +154,74 @@ static void axp288_extcon_log_rsi(struct axp288_extcon_info *info)
|
||||
regmap_write(info->regmap, AXP288_PS_BOOT_REASON_REG, clear_mask);
|
||||
}
|
||||
|
||||
static int axp288_handle_chrg_det_event(struct axp288_extcon_info *info)
|
||||
/*
|
||||
* The below code to control the USB role-switch on devices with an AXP288
|
||||
* may seem out of place, but there are 2 reasons why this is the best place
|
||||
* to control the USB role-switch on such devices:
|
||||
* 1) On many devices the USB role is controlled by AML code, but the AML code
|
||||
* only switches between the host and none roles, because of Windows not
|
||||
* really using device mode. To make device mode work we need to toggle
|
||||
* between the none/device roles based on Vbus presence, and this driver
|
||||
* gets interrupts on Vbus insertion / removal.
|
||||
* 2) In order for our BC1.2 charger detection to work properly the role
|
||||
* mux must be properly set to device mode before we do the detection.
|
||||
*/
|
||||
|
||||
/* Returns the id-pin value, note pulled low / false == host-mode */
|
||||
static bool axp288_get_id_pin(struct axp288_extcon_info *info)
|
||||
{
|
||||
int ret, stat, cfg, pwr_stat;
|
||||
u8 chrg_type;
|
||||
unsigned int cable = info->previous_cable;
|
||||
bool vbus_attach = false;
|
||||
enum usb_role role;
|
||||
|
||||
if (info->id_extcon)
|
||||
return extcon_get_state(info->id_extcon, EXTCON_USB_HOST) <= 0;
|
||||
|
||||
/* We cannot access the id-pin, see what mode the AML code has set */
|
||||
role = usb_role_switch_get_role(info->role_sw);
|
||||
return role != USB_ROLE_HOST;
|
||||
}
|
||||
|
||||
static void axp288_usb_role_work(struct work_struct *work)
|
||||
{
|
||||
struct axp288_extcon_info *info =
|
||||
container_of(work, struct axp288_extcon_info, role_work);
|
||||
enum usb_role role;
|
||||
bool id_pin;
|
||||
int ret;
|
||||
|
||||
id_pin = axp288_get_id_pin(info);
|
||||
if (!id_pin)
|
||||
role = USB_ROLE_HOST;
|
||||
else if (info->vbus_attach)
|
||||
role = USB_ROLE_DEVICE;
|
||||
else
|
||||
role = USB_ROLE_NONE;
|
||||
|
||||
ret = usb_role_switch_set_role(info->role_sw, role);
|
||||
if (ret)
|
||||
dev_err(info->dev, "failed to set role: %d\n", ret);
|
||||
}
|
||||
|
||||
static bool axp288_get_vbus_attach(struct axp288_extcon_info *info)
|
||||
{
|
||||
int ret, pwr_stat;
|
||||
|
||||
ret = regmap_read(info->regmap, AXP288_PS_STAT_REG, &pwr_stat);
|
||||
if (ret < 0) {
|
||||
dev_err(info->dev, "failed to read vbus status\n");
|
||||
return ret;
|
||||
return false;
|
||||
}
|
||||
|
||||
vbus_attach = (pwr_stat & PS_STAT_VBUS_VALID);
|
||||
return !!(pwr_stat & PS_STAT_VBUS_VALID);
|
||||
}
|
||||
|
||||
static int axp288_handle_chrg_det_event(struct axp288_extcon_info *info)
|
||||
{
|
||||
int ret, stat, cfg;
|
||||
u8 chrg_type;
|
||||
unsigned int cable = info->previous_cable;
|
||||
bool vbus_attach = false;
|
||||
|
||||
vbus_attach = axp288_get_vbus_attach(info);
|
||||
if (!vbus_attach)
|
||||
goto no_vbus;
|
||||
|
||||
@ -201,6 +272,12 @@ no_vbus:
|
||||
info->previous_cable = cable;
|
||||
}
|
||||
|
||||
if (info->role_sw && info->vbus_attach != vbus_attach) {
|
||||
info->vbus_attach = vbus_attach;
|
||||
/* Setting the role can take a while */
|
||||
queue_work(system_long_wq, &info->role_work);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
dev_det_ret:
|
||||
@ -210,6 +287,18 @@ dev_det_ret:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int axp288_extcon_id_evt(struct notifier_block *nb,
|
||||
unsigned long event, void *param)
|
||||
{
|
||||
struct axp288_extcon_info *info =
|
||||
container_of(nb, struct axp288_extcon_info, id_nb);
|
||||
|
||||
/* We may not sleep and setting the role can take a while */
|
||||
queue_work(system_long_wq, &info->role_work);
|
||||
|
||||
return NOTIFY_OK;
|
||||
}
|
||||
|
||||
static irqreturn_t axp288_extcon_isr(int irq, void *data)
|
||||
{
|
||||
struct axp288_extcon_info *info = data;
|
||||
@ -231,10 +320,20 @@ static void axp288_extcon_enable(struct axp288_extcon_info *info)
|
||||
BC_GLOBAL_RUN, BC_GLOBAL_RUN);
|
||||
}
|
||||
|
||||
static void axp288_put_role_sw(void *data)
|
||||
{
|
||||
struct axp288_extcon_info *info = data;
|
||||
|
||||
cancel_work_sync(&info->role_work);
|
||||
usb_role_switch_put(info->role_sw);
|
||||
}
|
||||
|
||||
static int axp288_extcon_probe(struct platform_device *pdev)
|
||||
{
|
||||
struct axp288_extcon_info *info;
|
||||
struct axp20x_dev *axp20x = dev_get_drvdata(pdev->dev.parent);
|
||||
struct device *dev = &pdev->dev;
|
||||
const char *name;
|
||||
int ret, i, pirq;
|
||||
|
||||
info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL);
|
||||
@ -245,9 +344,33 @@ static int axp288_extcon_probe(struct platform_device *pdev)
|
||||
info->regmap = axp20x->regmap;
|
||||
info->regmap_irqc = axp20x->regmap_irqc;
|
||||
info->previous_cable = EXTCON_NONE;
|
||||
INIT_WORK(&info->role_work, axp288_usb_role_work);
|
||||
info->id_nb.notifier_call = axp288_extcon_id_evt;
|
||||
|
||||
platform_set_drvdata(pdev, info);
|
||||
|
||||
info->role_sw = usb_role_switch_get(dev);
|
||||
if (IS_ERR(info->role_sw))
|
||||
return PTR_ERR(info->role_sw);
|
||||
if (info->role_sw) {
|
||||
ret = devm_add_action_or_reset(dev, axp288_put_role_sw, info);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
name = acpi_dev_get_first_match_name("INT3496", NULL, -1);
|
||||
if (name) {
|
||||
info->id_extcon = extcon_get_extcon_dev(name);
|
||||
if (!info->id_extcon)
|
||||
return -EPROBE_DEFER;
|
||||
|
||||
dev_info(dev, "controlling USB role\n");
|
||||
} else {
|
||||
dev_info(dev, "controlling USB role based on Vbus presence\n");
|
||||
}
|
||||
}
|
||||
|
||||
info->vbus_attach = axp288_get_vbus_attach(info);
|
||||
|
||||
axp288_extcon_log_rsi(info);
|
||||
|
||||
/* Initialize extcon device */
|
||||
@ -289,6 +412,19 @@ static int axp288_extcon_probe(struct platform_device *pdev)
|
||||
}
|
||||
}
|
||||
|
||||
if (info->id_extcon) {
|
||||
ret = devm_extcon_register_notifier_all(dev, info->id_extcon,
|
||||
&info->id_nb);
|
||||
if (ret)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Make sure the role-sw is set correctly before doing BC detection */
|
||||
if (info->role_sw) {
|
||||
queue_work(system_long_wq, &info->role_work);
|
||||
flush_work(&info->role_work);
|
||||
}
|
||||
|
||||
/* Start charger cable type detection */
|
||||
axp288_extcon_enable(info);
|
||||
|
||||
@ -308,8 +444,32 @@ static struct platform_driver axp288_extcon_driver = {
|
||||
.name = "axp288_extcon",
|
||||
},
|
||||
};
|
||||
module_platform_driver(axp288_extcon_driver);
|
||||
|
||||
static struct device_connection axp288_extcon_role_sw_conn = {
|
||||
.endpoint[0] = "axp288_extcon",
|
||||
.endpoint[1] = "intel_xhci_usb_sw-role-switch",
|
||||
.id = "usb-role-switch",
|
||||
};
|
||||
|
||||
static int __init axp288_extcon_init(void)
|
||||
{
|
||||
if (x86_match_cpu(cherry_trail_cpu_ids))
|
||||
device_connection_add(&axp288_extcon_role_sw_conn);
|
||||
|
||||
return platform_driver_register(&axp288_extcon_driver);
|
||||
}
|
||||
module_init(axp288_extcon_init);
|
||||
|
||||
static void __exit axp288_extcon_exit(void)
|
||||
{
|
||||
if (x86_match_cpu(cherry_trail_cpu_ids))
|
||||
device_connection_remove(&axp288_extcon_role_sw_conn);
|
||||
|
||||
platform_driver_unregister(&axp288_extcon_driver);
|
||||
}
|
||||
module_exit(axp288_extcon_exit);
|
||||
|
||||
MODULE_AUTHOR("Ramakrishna Pallala <ramakrishna.pallala@intel.com>");
|
||||
MODULE_AUTHOR("Hans de Goede <hdegoede@redhat.com>");
|
||||
MODULE_DESCRIPTION("X-Powers AXP288 extcon driver");
|
||||
MODULE_LICENSE("GPL v2");
|
||||
|
@ -112,6 +112,7 @@ enum sun4i_usb_phy_type {
|
||||
sun8i_a33_phy,
|
||||
sun8i_a83t_phy,
|
||||
sun8i_h3_phy,
|
||||
sun8i_r40_phy,
|
||||
sun8i_v3s_phy,
|
||||
sun50i_a64_phy,
|
||||
};
|
||||
@ -410,11 +411,13 @@ static bool sun4i_usb_phy0_poll(struct sun4i_usb_phy_data *data)
|
||||
return true;
|
||||
|
||||
/*
|
||||
* The A31 companion pmic (axp221) does not generate vbus change
|
||||
* interrupts when the board is driving vbus, so we must poll
|
||||
* The A31/A23/A33 companion pmics (AXP221/AXP223) do not
|
||||
* generate vbus change interrupts when the board is driving
|
||||
* vbus using the N_VBUSEN pin on the pmic, so we must poll
|
||||
* when using the pmic for vbus-det _and_ we're driving vbus.
|
||||
*/
|
||||
if (data->cfg->type == sun6i_a31_phy &&
|
||||
if ((data->cfg->type == sun6i_a31_phy ||
|
||||
data->cfg->type == sun8i_a33_phy) &&
|
||||
data->vbus_power_supply && data->phys[0].regulator_on)
|
||||
return true;
|
||||
|
||||
@ -885,7 +888,7 @@ static const struct sun4i_usb_phy_cfg sun7i_a20_cfg = {
|
||||
|
||||
static const struct sun4i_usb_phy_cfg sun8i_a23_cfg = {
|
||||
.num_phys = 2,
|
||||
.type = sun4i_a10_phy,
|
||||
.type = sun6i_a31_phy,
|
||||
.disc_thresh = 3,
|
||||
.phyctl_offset = REG_PHYCTL_A10,
|
||||
.dedicated_clocks = true,
|
||||
@ -919,6 +922,16 @@ static const struct sun4i_usb_phy_cfg sun8i_h3_cfg = {
|
||||
.phy0_dual_route = true,
|
||||
};
|
||||
|
||||
static const struct sun4i_usb_phy_cfg sun8i_r40_cfg = {
|
||||
.num_phys = 3,
|
||||
.type = sun8i_r40_phy,
|
||||
.disc_thresh = 3,
|
||||
.phyctl_offset = REG_PHYCTL_A33,
|
||||
.dedicated_clocks = true,
|
||||
.enable_pmu_unk1 = true,
|
||||
.phy0_dual_route = true,
|
||||
};
|
||||
|
||||
static const struct sun4i_usb_phy_cfg sun8i_v3s_cfg = {
|
||||
.num_phys = 1,
|
||||
.type = sun8i_v3s_phy,
|
||||
@ -948,6 +961,7 @@ static const struct of_device_id sun4i_usb_phy_of_match[] = {
|
||||
{ .compatible = "allwinner,sun8i-a33-usb-phy", .data = &sun8i_a33_cfg },
|
||||
{ .compatible = "allwinner,sun8i-a83t-usb-phy", .data = &sun8i_a83t_cfg },
|
||||
{ .compatible = "allwinner,sun8i-h3-usb-phy", .data = &sun8i_h3_cfg },
|
||||
{ .compatible = "allwinner,sun8i-r40-usb-phy", .data = &sun8i_r40_cfg },
|
||||
{ .compatible = "allwinner,sun8i-v3s-usb-phy", .data = &sun8i_v3s_cfg },
|
||||
{ .compatible = "allwinner,sun50i-a64-usb-phy",
|
||||
.data = &sun50i_a64_cfg},
|
||||
|
@ -18,10 +18,21 @@ config PHY_MESON_GXL_USB2
|
||||
default ARCH_MESON
|
||||
depends on OF && (ARCH_MESON || COMPILE_TEST)
|
||||
depends on USB_SUPPORT
|
||||
select USB_COMMON
|
||||
select GENERIC_PHY
|
||||
select REGMAP_MMIO
|
||||
help
|
||||
Enable this to support the Meson USB2 PHYs found in Meson
|
||||
GXL and GXM SoCs.
|
||||
If unsure, say N.
|
||||
|
||||
config PHY_MESON_GXL_USB3
|
||||
tristate "Meson GXL and GXM USB3 PHY drivers"
|
||||
default ARCH_MESON
|
||||
depends on OF && (ARCH_MESON || COMPILE_TEST)
|
||||
depends on USB_SUPPORT
|
||||
select GENERIC_PHY
|
||||
select REGMAP_MMIO
|
||||
help
|
||||
Enable this to support the Meson USB3 PHY and OTG detection
|
||||
IP block found in Meson GXL and GXM SoCs.
|
||||
If unsure, say N.
|
||||
|
@ -1,2 +1,3 @@
|
||||
obj-$(CONFIG_PHY_MESON8B_USB2) += phy-meson8b-usb2.o
|
||||
obj-$(CONFIG_PHY_MESON_GXL_USB2) += phy-meson-gxl-usb2.o
|
||||
obj-$(CONFIG_PHY_MESON_GXL_USB3) += phy-meson-gxl-usb3.o
|
||||
|
@ -11,14 +11,15 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <linux/clk.h>
|
||||
#include <linux/delay.h>
|
||||
#include <linux/io.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/of_device.h>
|
||||
#include <linux/regmap.h>
|
||||
#include <linux/reset.h>
|
||||
#include <linux/phy/phy.h>
|
||||
#include <linux/platform_device.h>
|
||||
#include <linux/usb/of.h>
|
||||
|
||||
/* bits [31:27] are read-only */
|
||||
#define U2P_R0 0x0
|
||||
@ -70,12 +71,11 @@
|
||||
|
||||
/* bits [31:14] are read-only */
|
||||
#define U2P_R2 0x8
|
||||
#define U2P_R2_DATA_IN_MASK GENMASK(3, 0)
|
||||
#define U2P_R2_DATA_IN_EN_MASK GENMASK(7, 4)
|
||||
#define U2P_R2_ADDR_MASK GENMASK(11, 8)
|
||||
#define U2P_R2_DATA_OUT_SEL BIT(12)
|
||||
#define U2P_R2_CLK BIT(13)
|
||||
#define U2P_R2_DATA_OUT_MASK GENMASK(17, 14)
|
||||
#define U2P_R2_TESTDATA_IN_MASK GENMASK(7, 0)
|
||||
#define U2P_R2_TESTADDR_MASK GENMASK(11, 8)
|
||||
#define U2P_R2_TESTDATA_OUT_SEL BIT(12)
|
||||
#define U2P_R2_TESTCLK BIT(13)
|
||||
#define U2P_R2_TESTDATA_OUT_MASK GENMASK(17, 14)
|
||||
#define U2P_R2_ACA_PIN_RANGE_C BIT(18)
|
||||
#define U2P_R2_ACA_PIN_RANGE_B BIT(19)
|
||||
#define U2P_R2_ACA_PIN_RANGE_A BIT(20)
|
||||
@ -99,6 +99,8 @@ struct phy_meson_gxl_usb2_priv {
|
||||
struct regmap *regmap;
|
||||
enum phy_mode mode;
|
||||
int is_enabled;
|
||||
struct clk *clk;
|
||||
struct reset_control *reset;
|
||||
};
|
||||
|
||||
static const struct regmap_config phy_meson_gxl_usb2_regmap_conf = {
|
||||
@ -108,6 +110,31 @@ static const struct regmap_config phy_meson_gxl_usb2_regmap_conf = {
|
||||
.max_register = U2P_R3,
|
||||
};
|
||||
|
||||
static int phy_meson_gxl_usb2_init(struct phy *phy)
|
||||
{
|
||||
struct phy_meson_gxl_usb2_priv *priv = phy_get_drvdata(phy);
|
||||
int ret;
|
||||
|
||||
ret = reset_control_reset(priv->reset);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
ret = clk_prepare_enable(priv->clk);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int phy_meson_gxl_usb2_exit(struct phy *phy)
|
||||
{
|
||||
struct phy_meson_gxl_usb2_priv *priv = phy_get_drvdata(phy);
|
||||
|
||||
clk_disable_unprepare(priv->clk);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int phy_meson_gxl_usb2_reset(struct phy *phy)
|
||||
{
|
||||
struct phy_meson_gxl_usb2_priv *priv = phy_get_drvdata(phy);
|
||||
@ -195,6 +222,8 @@ static int phy_meson_gxl_usb2_power_on(struct phy *phy)
|
||||
}
|
||||
|
||||
static const struct phy_ops phy_meson_gxl_usb2_ops = {
|
||||
.init = phy_meson_gxl_usb2_init,
|
||||
.exit = phy_meson_gxl_usb2_exit,
|
||||
.power_on = phy_meson_gxl_usb2_power_on,
|
||||
.power_off = phy_meson_gxl_usb2_power_off,
|
||||
.set_mode = phy_meson_gxl_usb2_set_mode,
|
||||
@ -210,6 +239,7 @@ static int phy_meson_gxl_usb2_probe(struct platform_device *pdev)
|
||||
struct phy_meson_gxl_usb2_priv *priv;
|
||||
struct phy *phy;
|
||||
void __iomem *base;
|
||||
int ret;
|
||||
|
||||
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
|
||||
if (!priv)
|
||||
@ -222,28 +252,34 @@ static int phy_meson_gxl_usb2_probe(struct platform_device *pdev)
|
||||
if (IS_ERR(base))
|
||||
return PTR_ERR(base);
|
||||
|
||||
switch (of_usb_get_dr_mode_by_phy(dev->of_node, -1)) {
|
||||
case USB_DR_MODE_PERIPHERAL:
|
||||
priv->mode = PHY_MODE_USB_DEVICE;
|
||||
break;
|
||||
case USB_DR_MODE_OTG:
|
||||
priv->mode = PHY_MODE_USB_OTG;
|
||||
break;
|
||||
case USB_DR_MODE_HOST:
|
||||
default:
|
||||
priv->mode = PHY_MODE_USB_HOST;
|
||||
break;
|
||||
}
|
||||
/* start in host mode */
|
||||
priv->mode = PHY_MODE_USB_HOST;
|
||||
|
||||
priv->regmap = devm_regmap_init_mmio(dev, base,
|
||||
&phy_meson_gxl_usb2_regmap_conf);
|
||||
if (IS_ERR(priv->regmap))
|
||||
return PTR_ERR(priv->regmap);
|
||||
|
||||
priv->clk = devm_clk_get(dev, "phy");
|
||||
if (IS_ERR(priv->clk)) {
|
||||
ret = PTR_ERR(priv->clk);
|
||||
if (ret == -ENOENT)
|
||||
priv->clk = NULL;
|
||||
else
|
||||
return ret;
|
||||
}
|
||||
|
||||
priv->reset = devm_reset_control_get_optional_shared(dev, "phy");
|
||||
if (IS_ERR(priv->reset))
|
||||
return PTR_ERR(priv->reset);
|
||||
|
||||
phy = devm_phy_create(dev, NULL, &phy_meson_gxl_usb2_ops);
|
||||
if (IS_ERR(phy)) {
|
||||
dev_err(dev, "failed to create PHY\n");
|
||||
return PTR_ERR(phy);
|
||||
ret = PTR_ERR(phy);
|
||||
if (ret != -EPROBE_DEFER)
|
||||
dev_err(dev, "failed to create PHY\n");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
phy_set_drvdata(phy, priv);
|
||||
|
282
drivers/phy/amlogic/phy-meson-gxl-usb3.c
Normal file
282
drivers/phy/amlogic/phy-meson-gxl-usb3.c
Normal file
@ -0,0 +1,282 @@
|
||||
// SPDX-License-Identifier: GPL-2.0
|
||||
/*
|
||||
* Meson GXL USB3 PHY and OTG mode detection driver
|
||||
*
|
||||
* Copyright (C) 2018 Martin Blumenstingl <martin.blumenstingl@googlemail.com>
|
||||
*/
|
||||
|
||||
#include <linux/bitfield.h>
|
||||
#include <linux/bitops.h>
|
||||
#include <linux/clk.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/of_device.h>
|
||||
#include <linux/phy/phy.h>
|
||||
#include <linux/regmap.h>
|
||||
#include <linux/reset.h>
|
||||
#include <linux/platform_device.h>
|
||||
|
||||
#define USB_R0 0x00
|
||||
#define USB_R0_P30_FSEL_MASK GENMASK(5, 0)
|
||||
#define USB_R0_P30_PHY_RESET BIT(6)
|
||||
#define USB_R0_P30_TEST_POWERDOWN_HSP BIT(7)
|
||||
#define USB_R0_P30_TEST_POWERDOWN_SSP BIT(8)
|
||||
#define USB_R0_P30_ACJT_LEVEL_MASK GENMASK(13, 9)
|
||||
#define USB_R0_P30_TX_BOOST_LEVEL_MASK GENMASK(16, 14)
|
||||
#define USB_R0_P30_LANE0_TX2RX_LOOPBACK BIT(17)
|
||||
#define USB_R0_P30_LANE0_EXT_PCLK_REQ BIT(18)
|
||||
#define USB_R0_P30_PCS_RX_LOS_MASK_VAL_MASK GENMASK(28, 19)
|
||||
#define USB_R0_U2D_SS_SCALEDOWN_MODE_MASK GENMASK(30, 29)
|
||||
#define USB_R0_U2D_ACT BIT(31)
|
||||
|
||||
#define USB_R1 0x04
|
||||
#define USB_R1_U3H_BIGENDIAN_GS BIT(0)
|
||||
#define USB_R1_U3H_PME_ENABLE BIT(1)
|
||||
#define USB_R1_U3H_HUB_PORT_OVERCURRENT_MASK GENMASK(6, 2)
|
||||
#define USB_R1_U3H_HUB_PORT_PERM_ATTACH_MASK GENMASK(11, 7)
|
||||
#define USB_R1_U3H_HOST_U2_PORT_DISABLE_MASK GENMASK(15, 12)
|
||||
#define USB_R1_U3H_HOST_U3_PORT_DISABLE BIT(16)
|
||||
#define USB_R1_U3H_HOST_PORT_POWER_CONTROL_PRESENT BIT(17)
|
||||
#define USB_R1_U3H_HOST_MSI_ENABLE BIT(18)
|
||||
#define USB_R1_U3H_FLADJ_30MHZ_REG_MASK GENMASK(24, 19)
|
||||
#define USB_R1_P30_PCS_TX_SWING_FULL_MASK GENMASK(31, 25)
|
||||
|
||||
#define USB_R2 0x08
|
||||
#define USB_R2_P30_CR_DATA_IN_MASK GENMASK(15, 0)
|
||||
#define USB_R2_P30_CR_READ BIT(16)
|
||||
#define USB_R2_P30_CR_WRITE BIT(17)
|
||||
#define USB_R2_P30_CR_CAP_ADDR BIT(18)
|
||||
#define USB_R2_P30_CR_CAP_DATA BIT(19)
|
||||
#define USB_R2_P30_PCS_TX_DEEMPH_3P5DB_MASK GENMASK(25, 20)
|
||||
#define USB_R2_P30_PCS_TX_DEEMPH_6DB_MASK GENMASK(31, 26)
|
||||
|
||||
#define USB_R3 0x0c
|
||||
#define USB_R3_P30_SSC_ENABLE BIT(0)
|
||||
#define USB_R3_P30_SSC_RANGE_MASK GENMASK(3, 1)
|
||||
#define USB_R3_P30_SSC_REF_CLK_SEL_MASK GENMASK(12, 4)
|
||||
#define USB_R3_P30_REF_SSP_EN BIT(13)
|
||||
#define USB_R3_P30_LOS_BIAS_MASK GENMASK(18, 16)
|
||||
#define USB_R3_P30_LOS_LEVEL_MASK GENMASK(23, 19)
|
||||
#define USB_R3_P30_MPLL_MULTIPLIER_MASK GENMASK(30, 24)
|
||||
|
||||
#define USB_R4 0x10
|
||||
#define USB_R4_P21_PORT_RESET_0 BIT(0)
|
||||
#define USB_R4_P21_SLEEP_M0 BIT(1)
|
||||
#define USB_R4_MEM_PD_MASK GENMASK(3, 2)
|
||||
#define USB_R4_P21_ONLY BIT(4)
|
||||
|
||||
#define USB_R5 0x14
|
||||
#define USB_R5_ID_DIG_SYNC BIT(0)
|
||||
#define USB_R5_ID_DIG_REG BIT(1)
|
||||
#define USB_R5_ID_DIG_CFG_MASK GENMASK(3, 2)
|
||||
#define USB_R5_ID_DIG_EN_0 BIT(4)
|
||||
#define USB_R5_ID_DIG_EN_1 BIT(5)
|
||||
#define USB_R5_ID_DIG_CURR BIT(6)
|
||||
#define USB_R5_ID_DIG_IRQ BIT(7)
|
||||
#define USB_R5_ID_DIG_TH_MASK GENMASK(15, 8)
|
||||
#define USB_R5_ID_DIG_CNT_MASK GENMASK(23, 16)
|
||||
|
||||
/* read-only register */
|
||||
#define USB_R6 0x18
|
||||
#define USB_R6_P30_CR_DATA_OUT_MASK GENMASK(15, 0)
|
||||
#define USB_R6_P30_CR_ACK BIT(16)
|
||||
|
||||
struct phy_meson_gxl_usb3_priv {
|
||||
struct regmap *regmap;
|
||||
enum phy_mode mode;
|
||||
struct clk *clk_phy;
|
||||
struct clk *clk_peripheral;
|
||||
struct reset_control *reset;
|
||||
};
|
||||
|
||||
static const struct regmap_config phy_meson_gxl_usb3_regmap_conf = {
|
||||
.reg_bits = 8,
|
||||
.val_bits = 32,
|
||||
.reg_stride = 4,
|
||||
.max_register = USB_R6,
|
||||
};
|
||||
|
||||
static int phy_meson_gxl_usb3_power_on(struct phy *phy)
|
||||
{
|
||||
struct phy_meson_gxl_usb3_priv *priv = phy_get_drvdata(phy);
|
||||
|
||||
regmap_update_bits(priv->regmap, USB_R5, USB_R5_ID_DIG_EN_0,
|
||||
USB_R5_ID_DIG_EN_0);
|
||||
regmap_update_bits(priv->regmap, USB_R5, USB_R5_ID_DIG_EN_1,
|
||||
USB_R5_ID_DIG_EN_1);
|
||||
regmap_update_bits(priv->regmap, USB_R5, USB_R5_ID_DIG_TH_MASK,
|
||||
FIELD_PREP(USB_R5_ID_DIG_TH_MASK, 0xff));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int phy_meson_gxl_usb3_power_off(struct phy *phy)
|
||||
{
|
||||
struct phy_meson_gxl_usb3_priv *priv = phy_get_drvdata(phy);
|
||||
|
||||
regmap_update_bits(priv->regmap, USB_R5, USB_R5_ID_DIG_EN_0, 0);
|
||||
regmap_update_bits(priv->regmap, USB_R5, USB_R5_ID_DIG_EN_1, 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int phy_meson_gxl_usb3_set_mode(struct phy *phy, enum phy_mode mode)
|
||||
{
|
||||
struct phy_meson_gxl_usb3_priv *priv = phy_get_drvdata(phy);
|
||||
|
||||
switch (mode) {
|
||||
case PHY_MODE_USB_HOST:
|
||||
regmap_update_bits(priv->regmap, USB_R0, USB_R0_U2D_ACT, 0);
|
||||
regmap_update_bits(priv->regmap, USB_R4, USB_R4_P21_SLEEP_M0,
|
||||
0);
|
||||
break;
|
||||
|
||||
case PHY_MODE_USB_DEVICE:
|
||||
regmap_update_bits(priv->regmap, USB_R0, USB_R0_U2D_ACT,
|
||||
USB_R0_U2D_ACT);
|
||||
regmap_update_bits(priv->regmap, USB_R4, USB_R4_P21_SLEEP_M0,
|
||||
USB_R4_P21_SLEEP_M0);
|
||||
break;
|
||||
|
||||
default:
|
||||
dev_err(&phy->dev, "unsupported PHY mode %d\n", mode);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
priv->mode = mode;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int phy_meson_gxl_usb3_init(struct phy *phy)
|
||||
{
|
||||
struct phy_meson_gxl_usb3_priv *priv = phy_get_drvdata(phy);
|
||||
int ret;
|
||||
|
||||
ret = reset_control_reset(priv->reset);
|
||||
if (ret)
|
||||
goto err;
|
||||
|
||||
ret = clk_prepare_enable(priv->clk_phy);
|
||||
if (ret)
|
||||
goto err;
|
||||
|
||||
ret = clk_prepare_enable(priv->clk_peripheral);
|
||||
if (ret)
|
||||
goto err_disable_clk_phy;
|
||||
|
||||
ret = phy_meson_gxl_usb3_set_mode(phy, priv->mode);
|
||||
if (ret)
|
||||
goto err_disable_clk_peripheral;
|
||||
|
||||
regmap_update_bits(priv->regmap, USB_R1,
|
||||
USB_R1_U3H_FLADJ_30MHZ_REG_MASK,
|
||||
FIELD_PREP(USB_R1_U3H_FLADJ_30MHZ_REG_MASK, 0x20));
|
||||
|
||||
return 0;
|
||||
|
||||
err_disable_clk_peripheral:
|
||||
clk_disable_unprepare(priv->clk_peripheral);
|
||||
err_disable_clk_phy:
|
||||
clk_disable_unprepare(priv->clk_phy);
|
||||
err:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int phy_meson_gxl_usb3_exit(struct phy *phy)
|
||||
{
|
||||
struct phy_meson_gxl_usb3_priv *priv = phy_get_drvdata(phy);
|
||||
|
||||
clk_disable_unprepare(priv->clk_peripheral);
|
||||
clk_disable_unprepare(priv->clk_phy);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct phy_ops phy_meson_gxl_usb3_ops = {
|
||||
.power_on = phy_meson_gxl_usb3_power_on,
|
||||
.power_off = phy_meson_gxl_usb3_power_off,
|
||||
.set_mode = phy_meson_gxl_usb3_set_mode,
|
||||
.init = phy_meson_gxl_usb3_init,
|
||||
.exit = phy_meson_gxl_usb3_exit,
|
||||
.owner = THIS_MODULE,
|
||||
};
|
||||
|
||||
static int phy_meson_gxl_usb3_probe(struct platform_device *pdev)
|
||||
{
|
||||
struct device *dev = &pdev->dev;
|
||||
struct device_node *np = dev->of_node;
|
||||
struct phy_meson_gxl_usb3_priv *priv;
|
||||
struct resource *res;
|
||||
struct phy *phy;
|
||||
struct phy_provider *phy_provider;
|
||||
void __iomem *base;
|
||||
int ret;
|
||||
|
||||
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
|
||||
if (!priv)
|
||||
return -ENOMEM;
|
||||
|
||||
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
||||
base = devm_ioremap_resource(dev, res);
|
||||
if (IS_ERR(base))
|
||||
return PTR_ERR(base);
|
||||
|
||||
priv->regmap = devm_regmap_init_mmio(dev, base,
|
||||
&phy_meson_gxl_usb3_regmap_conf);
|
||||
if (IS_ERR(priv->regmap))
|
||||
return PTR_ERR(priv->regmap);
|
||||
|
||||
priv->clk_phy = devm_clk_get(dev, "phy");
|
||||
if (IS_ERR(priv->clk_phy))
|
||||
return PTR_ERR(priv->clk_phy);
|
||||
|
||||
priv->clk_peripheral = devm_clk_get(dev, "peripheral");
|
||||
if (IS_ERR(priv->clk_peripheral))
|
||||
return PTR_ERR(priv->clk_peripheral);
|
||||
|
||||
priv->reset = devm_reset_control_array_get_shared(dev);
|
||||
if (IS_ERR(priv->reset))
|
||||
return PTR_ERR(priv->reset);
|
||||
|
||||
/*
|
||||
* default to host mode as hardware defaults and/or boot-loader
|
||||
* behavior can result in this PHY starting up in device mode. this
|
||||
* default and the initialization in phy_meson_gxl_usb3_init ensure
|
||||
* that we reproducibly start in a known mode on all devices.
|
||||
*/
|
||||
priv->mode = PHY_MODE_USB_HOST;
|
||||
|
||||
phy = devm_phy_create(dev, np, &phy_meson_gxl_usb3_ops);
|
||||
if (IS_ERR(phy)) {
|
||||
ret = PTR_ERR(phy);
|
||||
if (ret != -EPROBE_DEFER)
|
||||
dev_err(dev, "failed to create PHY\n");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
phy_set_drvdata(phy, priv);
|
||||
|
||||
phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
|
||||
|
||||
return PTR_ERR_OR_ZERO(phy_provider);
|
||||
}
|
||||
|
||||
static const struct of_device_id phy_meson_gxl_usb3_of_match[] = {
|
||||
{ .compatible = "amlogic,meson-gxl-usb3-phy", },
|
||||
{ },
|
||||
};
|
||||
MODULE_DEVICE_TABLE(of, phy_meson_gxl_usb3_of_match);
|
||||
|
||||
static struct platform_driver phy_meson_gxl_usb3_driver = {
|
||||
.probe = phy_meson_gxl_usb3_probe,
|
||||
.driver = {
|
||||
.name = "phy-meson-gxl-usb3",
|
||||
.of_match_table = phy_meson_gxl_usb3_of_match,
|
||||
},
|
||||
};
|
||||
module_platform_driver(phy_meson_gxl_usb3_driver);
|
||||
|
||||
MODULE_AUTHOR("Martin Blumenstingl <martin.blumenstingl@googlemail.com>");
|
||||
MODULE_DESCRIPTION("Meson GXL USB3 PHY and OTG detection driver");
|
||||
MODULE_LICENSE("GPL v2");
|
@ -4,6 +4,7 @@
|
||||
config PHY_HI6220_USB
|
||||
tristate "hi6220 USB PHY support"
|
||||
depends on (ARCH_HISI && ARM64) || COMPILE_TEST
|
||||
depends on HAS_IOMEM
|
||||
select GENERIC_PHY
|
||||
select MFD_SYSCON
|
||||
help
|
||||
@ -11,6 +12,25 @@ config PHY_HI6220_USB
|
||||
|
||||
To compile this driver as a module, choose M here.
|
||||
|
||||
config PHY_HISTB_COMBPHY
|
||||
tristate "HiSilicon STB SoCs COMBPHY support"
|
||||
depends on (ARCH_HISI && ARM64) || COMPILE_TEST
|
||||
select GENERIC_PHY
|
||||
select MFD_SYSCON
|
||||
help
|
||||
Enable this to support the HISILICON STB SoCs COMBPHY.
|
||||
If unsure, say N.
|
||||
|
||||
config PHY_HISI_INNO_USB2
|
||||
tristate "HiSilicon INNO USB2 PHY support"
|
||||
depends on (ARCH_HISI && ARM64) || COMPILE_TEST
|
||||
select GENERIC_PHY
|
||||
select MFD_SYSCON
|
||||
help
|
||||
Support for INNO USB2 PHY on HiSilicon SoCs. This Phy supports
|
||||
USB 1.5Mb/s, USB 12Mb/s, USB 480Mb/s speeds. It supports one
|
||||
USB host port to accept one USB device.
|
||||
|
||||
config PHY_HIX5HD2_SATA
|
||||
tristate "HIX5HD2 SATA PHY Driver"
|
||||
depends on ARCH_HIX5HD2 && OF && HAS_IOMEM
|
||||
|
@ -1,2 +1,4 @@
|
||||
obj-$(CONFIG_PHY_HI6220_USB) += phy-hi6220-usb.o
|
||||
obj-$(CONFIG_PHY_HISTB_COMBPHY) += phy-histb-combphy.o
|
||||
obj-$(CONFIG_PHY_HISI_INNO_USB2) += phy-hisi-inno-usb2.o
|
||||
obj-$(CONFIG_PHY_HIX5HD2_SATA) += phy-hix5hd2-sata.o
|
||||
|
197
drivers/phy/hisilicon/phy-hisi-inno-usb2.c
Normal file
197
drivers/phy/hisilicon/phy-hisi-inno-usb2.c
Normal file
@ -0,0 +1,197 @@
|
||||
/*
|
||||
* HiSilicon INNO USB2 PHY Driver.
|
||||
*
|
||||
* Copyright (c) 2016-2017 HiSilicon Technologies 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.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <linux/clk.h>
|
||||
#include <linux/delay.h>
|
||||
#include <linux/io.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/platform_device.h>
|
||||
#include <linux/phy/phy.h>
|
||||
#include <linux/reset.h>
|
||||
|
||||
#define INNO_PHY_PORT_NUM 2
|
||||
#define REF_CLK_STABLE_TIME 100 /* unit:us */
|
||||
#define UTMI_CLK_STABLE_TIME 200 /* unit:us */
|
||||
#define TEST_CLK_STABLE_TIME 2 /* unit:ms */
|
||||
#define PHY_CLK_STABLE_TIME 2 /* unit:ms */
|
||||
#define UTMI_RST_COMPLETE_TIME 2 /* unit:ms */
|
||||
#define POR_RST_COMPLETE_TIME 300 /* unit:us */
|
||||
#define PHY_TEST_DATA GENMASK(7, 0)
|
||||
#define PHY_TEST_ADDR GENMASK(15, 8)
|
||||
#define PHY_TEST_PORT GENMASK(18, 16)
|
||||
#define PHY_TEST_WREN BIT(21)
|
||||
#define PHY_TEST_CLK BIT(22) /* rising edge active */
|
||||
#define PHY_TEST_RST BIT(23) /* low active */
|
||||
#define PHY_CLK_ENABLE BIT(2)
|
||||
|
||||
struct hisi_inno_phy_port {
|
||||
struct reset_control *utmi_rst;
|
||||
struct hisi_inno_phy_priv *priv;
|
||||
};
|
||||
|
||||
struct hisi_inno_phy_priv {
|
||||
void __iomem *mmio;
|
||||
struct clk *ref_clk;
|
||||
struct reset_control *por_rst;
|
||||
struct hisi_inno_phy_port ports[INNO_PHY_PORT_NUM];
|
||||
};
|
||||
|
||||
static void hisi_inno_phy_write_reg(struct hisi_inno_phy_priv *priv,
|
||||
u8 port, u32 addr, u32 data)
|
||||
{
|
||||
void __iomem *reg = priv->mmio;
|
||||
u32 val;
|
||||
|
||||
val = (data & PHY_TEST_DATA) |
|
||||
((addr << 8) & PHY_TEST_ADDR) |
|
||||
((port << 16) & PHY_TEST_PORT) |
|
||||
PHY_TEST_WREN | PHY_TEST_RST;
|
||||
writel(val, reg);
|
||||
|
||||
val |= PHY_TEST_CLK;
|
||||
writel(val, reg);
|
||||
|
||||
val &= ~PHY_TEST_CLK;
|
||||
writel(val, reg);
|
||||
}
|
||||
|
||||
static void hisi_inno_phy_setup(struct hisi_inno_phy_priv *priv)
|
||||
{
|
||||
/* The phy clk is controlled by the port0 register 0x06. */
|
||||
hisi_inno_phy_write_reg(priv, 0, 0x06, PHY_CLK_ENABLE);
|
||||
msleep(PHY_CLK_STABLE_TIME);
|
||||
}
|
||||
|
||||
static int hisi_inno_phy_init(struct phy *phy)
|
||||
{
|
||||
struct hisi_inno_phy_port *port = phy_get_drvdata(phy);
|
||||
struct hisi_inno_phy_priv *priv = port->priv;
|
||||
int ret;
|
||||
|
||||
ret = clk_prepare_enable(priv->ref_clk);
|
||||
if (ret)
|
||||
return ret;
|
||||
udelay(REF_CLK_STABLE_TIME);
|
||||
|
||||
reset_control_deassert(priv->por_rst);
|
||||
udelay(POR_RST_COMPLETE_TIME);
|
||||
|
||||
/* Set up phy registers */
|
||||
hisi_inno_phy_setup(priv);
|
||||
|
||||
reset_control_deassert(port->utmi_rst);
|
||||
udelay(UTMI_RST_COMPLETE_TIME);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int hisi_inno_phy_exit(struct phy *phy)
|
||||
{
|
||||
struct hisi_inno_phy_port *port = phy_get_drvdata(phy);
|
||||
struct hisi_inno_phy_priv *priv = port->priv;
|
||||
|
||||
reset_control_assert(port->utmi_rst);
|
||||
reset_control_assert(priv->por_rst);
|
||||
clk_disable_unprepare(priv->ref_clk);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct phy_ops hisi_inno_phy_ops = {
|
||||
.init = hisi_inno_phy_init,
|
||||
.exit = hisi_inno_phy_exit,
|
||||
.owner = THIS_MODULE,
|
||||
};
|
||||
|
||||
static int hisi_inno_phy_probe(struct platform_device *pdev)
|
||||
{
|
||||
struct device *dev = &pdev->dev;
|
||||
struct device_node *np = dev->of_node;
|
||||
struct hisi_inno_phy_priv *priv;
|
||||
struct phy_provider *provider;
|
||||
struct device_node *child;
|
||||
struct resource *res;
|
||||
int i = 0;
|
||||
int ret;
|
||||
|
||||
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
|
||||
if (!priv)
|
||||
return -ENOMEM;
|
||||
|
||||
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
||||
priv->mmio = devm_ioremap_resource(dev, res);
|
||||
if (IS_ERR(priv->mmio)) {
|
||||
ret = PTR_ERR(priv->mmio);
|
||||
return ret;
|
||||
}
|
||||
|
||||
priv->ref_clk = devm_clk_get(dev, NULL);
|
||||
if (IS_ERR(priv->ref_clk))
|
||||
return PTR_ERR(priv->ref_clk);
|
||||
|
||||
priv->por_rst = devm_reset_control_get_exclusive(dev, NULL);
|
||||
if (IS_ERR(priv->por_rst))
|
||||
return PTR_ERR(priv->por_rst);
|
||||
|
||||
for_each_child_of_node(np, child) {
|
||||
struct reset_control *rst;
|
||||
struct phy *phy;
|
||||
|
||||
rst = of_reset_control_get_exclusive(child, NULL);
|
||||
if (IS_ERR(rst))
|
||||
return PTR_ERR(rst);
|
||||
priv->ports[i].utmi_rst = rst;
|
||||
priv->ports[i].priv = priv;
|
||||
|
||||
phy = devm_phy_create(dev, child, &hisi_inno_phy_ops);
|
||||
if (IS_ERR(phy))
|
||||
return PTR_ERR(phy);
|
||||
|
||||
phy_set_bus_width(phy, 8);
|
||||
phy_set_drvdata(phy, &priv->ports[i]);
|
||||
i++;
|
||||
|
||||
if (i > INNO_PHY_PORT_NUM) {
|
||||
dev_warn(dev, "Support %d ports in maximum\n", i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
|
||||
return PTR_ERR_OR_ZERO(provider);
|
||||
}
|
||||
|
||||
static const struct of_device_id hisi_inno_phy_of_match[] = {
|
||||
{ .compatible = "hisilicon,inno-usb2-phy", },
|
||||
{ .compatible = "hisilicon,hi3798cv200-usb2-phy", },
|
||||
{ },
|
||||
};
|
||||
MODULE_DEVICE_TABLE(of, hisi_inno_phy_of_match);
|
||||
|
||||
static struct platform_driver hisi_inno_phy_driver = {
|
||||
.probe = hisi_inno_phy_probe,
|
||||
.driver = {
|
||||
.name = "hisi-inno-phy",
|
||||
.of_match_table = hisi_inno_phy_of_match,
|
||||
}
|
||||
};
|
||||
module_platform_driver(hisi_inno_phy_driver);
|
||||
|
||||
MODULE_DESCRIPTION("HiSilicon INNO USB2 PHY Driver");
|
||||
MODULE_LICENSE("GPL v2");
|
289
drivers/phy/hisilicon/phy-histb-combphy.c
Normal file
289
drivers/phy/hisilicon/phy-histb-combphy.c
Normal file
@ -0,0 +1,289 @@
|
||||
/*
|
||||
* COMBPHY driver for HiSilicon STB SoCs
|
||||
*
|
||||
* Copyright (C) 2016-2017 HiSilicon Co., Ltd. http://www.hisilicon.com
|
||||
*
|
||||
* Authors: Jianguo Sun <sunjianguo1@huawei.com>
|
||||
*
|
||||
* 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/clk.h>
|
||||
#include <linux/delay.h>
|
||||
#include <linux/io.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/mfd/syscon.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/of_device.h>
|
||||
#include <linux/phy/phy.h>
|
||||
#include <linux/regmap.h>
|
||||
#include <linux/reset.h>
|
||||
#include <dt-bindings/phy/phy.h>
|
||||
|
||||
#define COMBPHY_MODE_PCIE 0
|
||||
#define COMBPHY_MODE_USB3 1
|
||||
#define COMBPHY_MODE_SATA 2
|
||||
|
||||
#define COMBPHY_CFG_REG 0x0
|
||||
#define COMBPHY_BYPASS_CODEC BIT(31)
|
||||
#define COMBPHY_TEST_WRITE BIT(24)
|
||||
#define COMBPHY_TEST_DATA_SHIFT 20
|
||||
#define COMBPHY_TEST_DATA_MASK GENMASK(23, 20)
|
||||
#define COMBPHY_TEST_ADDR_SHIFT 12
|
||||
#define COMBPHY_TEST_ADDR_MASK GENMASK(16, 12)
|
||||
#define COMBPHY_CLKREF_OUT_OEN BIT(0)
|
||||
|
||||
struct histb_combphy_mode {
|
||||
int fixed;
|
||||
int select;
|
||||
u32 reg;
|
||||
u32 shift;
|
||||
u32 mask;
|
||||
};
|
||||
|
||||
struct histb_combphy_priv {
|
||||
void __iomem *mmio;
|
||||
struct regmap *syscon;
|
||||
struct reset_control *por_rst;
|
||||
struct clk *ref_clk;
|
||||
struct phy *phy;
|
||||
struct histb_combphy_mode mode;
|
||||
};
|
||||
|
||||
static void nano_register_write(struct histb_combphy_priv *priv,
|
||||
u32 addr, u32 data)
|
||||
{
|
||||
void __iomem *reg = priv->mmio + COMBPHY_CFG_REG;
|
||||
u32 val;
|
||||
|
||||
/* Set up address and data for the write */
|
||||
val = readl(reg);
|
||||
val &= ~COMBPHY_TEST_ADDR_MASK;
|
||||
val |= addr << COMBPHY_TEST_ADDR_SHIFT;
|
||||
val &= ~COMBPHY_TEST_DATA_MASK;
|
||||
val |= data << COMBPHY_TEST_DATA_SHIFT;
|
||||
writel(val, reg);
|
||||
|
||||
/* Flip strobe control to trigger the write */
|
||||
val &= ~COMBPHY_TEST_WRITE;
|
||||
writel(val, reg);
|
||||
val |= COMBPHY_TEST_WRITE;
|
||||
writel(val, reg);
|
||||
}
|
||||
|
||||
static int is_mode_fixed(struct histb_combphy_mode *mode)
|
||||
{
|
||||
return (mode->fixed != PHY_NONE) ? true : false;
|
||||
}
|
||||
|
||||
static int histb_combphy_set_mode(struct histb_combphy_priv *priv)
|
||||
{
|
||||
struct histb_combphy_mode *mode = &priv->mode;
|
||||
struct regmap *syscon = priv->syscon;
|
||||
u32 hw_sel;
|
||||
|
||||
if (is_mode_fixed(mode))
|
||||
return 0;
|
||||
|
||||
switch (mode->select) {
|
||||
case PHY_TYPE_SATA:
|
||||
hw_sel = COMBPHY_MODE_SATA;
|
||||
break;
|
||||
case PHY_TYPE_PCIE:
|
||||
hw_sel = COMBPHY_MODE_PCIE;
|
||||
break;
|
||||
case PHY_TYPE_USB3:
|
||||
hw_sel = COMBPHY_MODE_USB3;
|
||||
break;
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return regmap_update_bits(syscon, mode->reg, mode->mask,
|
||||
hw_sel << mode->shift);
|
||||
}
|
||||
|
||||
static int histb_combphy_init(struct phy *phy)
|
||||
{
|
||||
struct histb_combphy_priv *priv = phy_get_drvdata(phy);
|
||||
u32 val;
|
||||
int ret;
|
||||
|
||||
ret = histb_combphy_set_mode(priv);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
/* Clear bypass bit to enable encoding/decoding */
|
||||
val = readl(priv->mmio + COMBPHY_CFG_REG);
|
||||
val &= ~COMBPHY_BYPASS_CODEC;
|
||||
writel(val, priv->mmio + COMBPHY_CFG_REG);
|
||||
|
||||
ret = clk_prepare_enable(priv->ref_clk);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
reset_control_deassert(priv->por_rst);
|
||||
|
||||
/* Enable EP clock */
|
||||
val = readl(priv->mmio + COMBPHY_CFG_REG);
|
||||
val |= COMBPHY_CLKREF_OUT_OEN;
|
||||
writel(val, priv->mmio + COMBPHY_CFG_REG);
|
||||
|
||||
/* Need to wait for EP clock stable */
|
||||
mdelay(5);
|
||||
|
||||
/* Configure nano phy registers as suggested by vendor */
|
||||
nano_register_write(priv, 0x1, 0x8);
|
||||
nano_register_write(priv, 0xc, 0x9);
|
||||
nano_register_write(priv, 0x1a, 0x4);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int histb_combphy_exit(struct phy *phy)
|
||||
{
|
||||
struct histb_combphy_priv *priv = phy_get_drvdata(phy);
|
||||
u32 val;
|
||||
|
||||
/* Disable EP clock */
|
||||
val = readl(priv->mmio + COMBPHY_CFG_REG);
|
||||
val &= ~COMBPHY_CLKREF_OUT_OEN;
|
||||
writel(val, priv->mmio + COMBPHY_CFG_REG);
|
||||
|
||||
reset_control_assert(priv->por_rst);
|
||||
clk_disable_unprepare(priv->ref_clk);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct phy_ops histb_combphy_ops = {
|
||||
.init = histb_combphy_init,
|
||||
.exit = histb_combphy_exit,
|
||||
.owner = THIS_MODULE,
|
||||
};
|
||||
|
||||
static struct phy *histb_combphy_xlate(struct device *dev,
|
||||
struct of_phandle_args *args)
|
||||
{
|
||||
struct histb_combphy_priv *priv = dev_get_drvdata(dev);
|
||||
struct histb_combphy_mode *mode = &priv->mode;
|
||||
|
||||
if (args->args_count < 1) {
|
||||
dev_err(dev, "invalid number of arguments\n");
|
||||
return ERR_PTR(-EINVAL);
|
||||
}
|
||||
|
||||
mode->select = args->args[0];
|
||||
|
||||
if (mode->select < PHY_TYPE_SATA || mode->select > PHY_TYPE_USB3) {
|
||||
dev_err(dev, "invalid phy mode select argument\n");
|
||||
return ERR_PTR(-EINVAL);
|
||||
}
|
||||
|
||||
if (is_mode_fixed(mode) && mode->select != mode->fixed) {
|
||||
dev_err(dev, "mode select %d mismatch fixed phy mode %d\n",
|
||||
mode->select, mode->fixed);
|
||||
return ERR_PTR(-EINVAL);
|
||||
}
|
||||
|
||||
return priv->phy;
|
||||
}
|
||||
|
||||
static int histb_combphy_probe(struct platform_device *pdev)
|
||||
{
|
||||
struct phy_provider *phy_provider;
|
||||
struct device *dev = &pdev->dev;
|
||||
struct histb_combphy_priv *priv;
|
||||
struct device_node *np = dev->of_node;
|
||||
struct histb_combphy_mode *mode;
|
||||
struct resource *res;
|
||||
u32 vals[3];
|
||||
int ret;
|
||||
|
||||
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
|
||||
if (!priv)
|
||||
return -ENOMEM;
|
||||
|
||||
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
||||
priv->mmio = devm_ioremap_resource(dev, res);
|
||||
if (IS_ERR(priv->mmio)) {
|
||||
ret = PTR_ERR(priv->mmio);
|
||||
return ret;
|
||||
}
|
||||
|
||||
priv->syscon = syscon_node_to_regmap(np->parent);
|
||||
if (IS_ERR(priv->syscon)) {
|
||||
dev_err(dev, "failed to find peri_ctrl syscon regmap\n");
|
||||
return PTR_ERR(priv->syscon);
|
||||
}
|
||||
|
||||
mode = &priv->mode;
|
||||
mode->fixed = PHY_NONE;
|
||||
|
||||
ret = of_property_read_u32(np, "hisilicon,fixed-mode", &mode->fixed);
|
||||
if (ret == 0)
|
||||
dev_dbg(dev, "found fixed phy mode %d\n", mode->fixed);
|
||||
|
||||
ret = of_property_read_u32_array(np, "hisilicon,mode-select-bits",
|
||||
vals, ARRAY_SIZE(vals));
|
||||
if (ret == 0) {
|
||||
if (is_mode_fixed(mode)) {
|
||||
dev_err(dev, "found select bits for fixed mode phy\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
mode->reg = vals[0];
|
||||
mode->shift = vals[1];
|
||||
mode->mask = vals[2];
|
||||
dev_dbg(dev, "found mode select bits\n");
|
||||
} else {
|
||||
if (!is_mode_fixed(mode)) {
|
||||
dev_err(dev, "no valid select bits found for non-fixed phy\n");
|
||||
return -ENODEV;
|
||||
}
|
||||
}
|
||||
|
||||
priv->ref_clk = devm_clk_get(dev, NULL);
|
||||
if (IS_ERR(priv->ref_clk)) {
|
||||
dev_err(dev, "failed to find ref clock\n");
|
||||
return PTR_ERR(priv->ref_clk);
|
||||
}
|
||||
|
||||
priv->por_rst = devm_reset_control_get(dev, NULL);
|
||||
if (IS_ERR(priv->por_rst)) {
|
||||
dev_err(dev, "failed to get poweron reset\n");
|
||||
return PTR_ERR(priv->por_rst);
|
||||
}
|
||||
|
||||
priv->phy = devm_phy_create(dev, NULL, &histb_combphy_ops);
|
||||
if (IS_ERR(priv->phy)) {
|
||||
dev_err(dev, "failed to create combphy\n");
|
||||
return PTR_ERR(priv->phy);
|
||||
}
|
||||
|
||||
dev_set_drvdata(dev, priv);
|
||||
phy_set_drvdata(priv->phy, priv);
|
||||
|
||||
phy_provider = devm_of_phy_provider_register(dev, histb_combphy_xlate);
|
||||
return PTR_ERR_OR_ZERO(phy_provider);
|
||||
}
|
||||
|
||||
static const struct of_device_id histb_combphy_of_match[] = {
|
||||
{ .compatible = "hisilicon,hi3798cv200-combphy" },
|
||||
{ },
|
||||
};
|
||||
MODULE_DEVICE_TABLE(of, histb_combphy_of_match);
|
||||
|
||||
static struct platform_driver histb_combphy_driver = {
|
||||
.probe = histb_combphy_probe,
|
||||
.driver = {
|
||||
.name = "combphy",
|
||||
.of_match_table = histb_combphy_of_match,
|
||||
},
|
||||
};
|
||||
module_platform_driver(histb_combphy_driver);
|
||||
|
||||
MODULE_DESCRIPTION("HiSilicon STB COMBPHY driver");
|
||||
MODULE_LICENSE("GPL v2");
|
@ -127,7 +127,7 @@ static int phy_berlin_usb_power_on(struct phy *phy)
|
||||
writel(V2I_VCO_RATIO(0x5) | R_ROTATE_0 | ANA_TEST_DC_CTRL(0x5),
|
||||
priv->base + USB_PHY_ANALOG);
|
||||
writel(PHASE_FREEZE_DLY_4_CL | ACK_LENGTH_16_CL | SQ_LENGTH_12 |
|
||||
DISCON_THRESHOLD_260 | SQ_THRESHOLD(0xa) | LPF_COEF(0x2) |
|
||||
DISCON_THRESHOLD_270 | SQ_THRESHOLD(0xa) | LPF_COEF(0x2) |
|
||||
INTPL_CUR_30, priv->base + USB_PHY_RX_CTRL);
|
||||
|
||||
writel(TX_VDD12_13 | TX_OUT_AMP(0x3), priv->base + USB_PHY_TX_CTRL1);
|
||||
|
@ -306,6 +306,8 @@ struct mtk_tphy {
|
||||
const struct mtk_phy_pdata *pdata;
|
||||
struct mtk_phy_instance **phys;
|
||||
int nphys;
|
||||
int src_ref_clk; /* MHZ, reference clock for slew rate calibrate */
|
||||
int src_coef; /* coefficient for slew rate calibrate */
|
||||
};
|
||||
|
||||
static void hs_slew_rate_calibrate(struct mtk_tphy *tphy,
|
||||
@ -360,16 +362,17 @@ static void hs_slew_rate_calibrate(struct mtk_tphy *tphy,
|
||||
writel(tmp, fmreg + U3P_U2FREQ_FMMONR1);
|
||||
|
||||
if (fm_out) {
|
||||
/* ( 1024 / FM_OUT ) x reference clock frequency x 0.028 */
|
||||
tmp = U3P_FM_DET_CYCLE_CNT * U3P_REF_CLK * U3P_SLEW_RATE_COEF;
|
||||
tmp /= fm_out;
|
||||
/* ( 1024 / FM_OUT ) x reference clock frequency x coef */
|
||||
tmp = tphy->src_ref_clk * tphy->src_coef;
|
||||
tmp = (tmp * U3P_FM_DET_CYCLE_CNT) / fm_out;
|
||||
calibration_val = DIV_ROUND_CLOSEST(tmp, U3P_SR_COEF_DIVISOR);
|
||||
} else {
|
||||
/* if FM detection fail, set default value */
|
||||
calibration_val = 4;
|
||||
}
|
||||
dev_dbg(tphy->dev, "phy:%d, fm_out:%d, calib:%d\n",
|
||||
instance->index, fm_out, calibration_val);
|
||||
dev_dbg(tphy->dev, "phy:%d, fm_out:%d, calib:%d (clk:%d, coef:%d)\n",
|
||||
instance->index, fm_out, calibration_val,
|
||||
tphy->src_ref_clk, tphy->src_coef);
|
||||
|
||||
/* set HS slew rate */
|
||||
tmp = readl(com + U3P_USBPHYACR5);
|
||||
@ -688,8 +691,7 @@ static void pcie_phy_instance_power_on(struct mtk_tphy *tphy,
|
||||
u32 tmp;
|
||||
|
||||
tmp = readl(bank->chip + U3P_U3_CHIP_GPIO_CTLD);
|
||||
tmp &= ~(P3C_FORCE_IP_SW_RST | P3C_MCU_BUS_CK_GATE_EN |
|
||||
P3C_REG_IP_SW_RST);
|
||||
tmp &= ~(P3C_FORCE_IP_SW_RST | P3C_REG_IP_SW_RST);
|
||||
writel(tmp, bank->chip + U3P_U3_CHIP_GPIO_CTLD);
|
||||
|
||||
tmp = readl(bank->chip + U3P_U3_CHIP_GPIO_CTLE);
|
||||
@ -1042,6 +1044,13 @@ static int mtk_tphy_probe(struct platform_device *pdev)
|
||||
tphy->u3phya_ref = NULL;
|
||||
}
|
||||
|
||||
tphy->src_ref_clk = U3P_REF_CLK;
|
||||
tphy->src_coef = U3P_SLEW_RATE_COEF;
|
||||
/* update parameters of slew rate calibrate if exist */
|
||||
device_property_read_u32(dev, "mediatek,src-ref-clk-mhz",
|
||||
&tphy->src_ref_clk);
|
||||
device_property_read_u32(dev, "mediatek,src-coef", &tphy->src_coef);
|
||||
|
||||
port = 0;
|
||||
for_each_child_of_node(np, child_np) {
|
||||
struct mtk_phy_instance *instance;
|
||||
|
@ -10,3 +10,11 @@ config PHY_CPCAP_USB
|
||||
help
|
||||
Enable this for USB to work on Motorola phones and tablets
|
||||
such as Droid 4.
|
||||
|
||||
config PHY_MAPPHONE_MDM6600
|
||||
tristate "Motorola Mapphone MDM6600 modem USB PHY driver"
|
||||
depends on OF && USB_SUPPORT
|
||||
select GENERIC_PHY
|
||||
help
|
||||
Enable this for MDM6600 USB modem to work on Motorola phones
|
||||
and tablets such as Droid 4.
|
||||
|
@ -3,3 +3,4 @@
|
||||
#
|
||||
|
||||
obj-$(CONFIG_PHY_CPCAP_USB) += phy-cpcap-usb.o
|
||||
obj-$(CONFIG_PHY_MAPPHONE_MDM6600) += phy-mapphone-mdm6600.o
|
||||
|
542
drivers/phy/motorola/phy-mapphone-mdm6600.c
Normal file
542
drivers/phy/motorola/phy-mapphone-mdm6600.c
Normal file
@ -0,0 +1,542 @@
|
||||
// SPDX-License-Identifier: GPL-2.0
|
||||
/*
|
||||
* Motorola Mapphone MDM6600 modem GPIO controlled USB PHY driver
|
||||
* Copyright (C) 2018 Tony Lindgren <tony@atomide.com>
|
||||
*/
|
||||
|
||||
#include <linux/delay.h>
|
||||
#include <linux/err.h>
|
||||
#include <linux/io.h>
|
||||
#include <linux/interrupt.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/of.h>
|
||||
#include <linux/platform_device.h>
|
||||
#include <linux/slab.h>
|
||||
|
||||
#include <linux/gpio/consumer.h>
|
||||
#include <linux/of_platform.h>
|
||||
#include <linux/phy/phy.h>
|
||||
|
||||
#define PHY_MDM6600_PHY_DELAY_MS 4000 /* PHY enable 2.2s to 3.5s */
|
||||
#define PHY_MDM6600_ENABLED_DELAY_MS 8000 /* 8s more total for MDM6600 */
|
||||
|
||||
enum phy_mdm6600_ctrl_lines {
|
||||
PHY_MDM6600_ENABLE, /* USB PHY enable */
|
||||
PHY_MDM6600_POWER, /* Device power */
|
||||
PHY_MDM6600_RESET, /* Device reset */
|
||||
PHY_MDM6600_NR_CTRL_LINES,
|
||||
};
|
||||
|
||||
enum phy_mdm6600_bootmode_lines {
|
||||
PHY_MDM6600_MODE0, /* out USB mode0 and OOB wake */
|
||||
PHY_MDM6600_MODE1, /* out USB mode1, in OOB wake */
|
||||
PHY_MDM6600_NR_MODE_LINES,
|
||||
};
|
||||
|
||||
enum phy_mdm6600_cmd_lines {
|
||||
PHY_MDM6600_CMD0,
|
||||
PHY_MDM6600_CMD1,
|
||||
PHY_MDM6600_CMD2,
|
||||
PHY_MDM6600_NR_CMD_LINES,
|
||||
};
|
||||
|
||||
enum phy_mdm6600_status_lines {
|
||||
PHY_MDM6600_STATUS0,
|
||||
PHY_MDM6600_STATUS1,
|
||||
PHY_MDM6600_STATUS2,
|
||||
PHY_MDM6600_NR_STATUS_LINES,
|
||||
};
|
||||
|
||||
/*
|
||||
* MDM6600 command codes. These are based on Motorola Mapphone Linux
|
||||
* kernel tree.
|
||||
*/
|
||||
enum phy_mdm6600_cmd {
|
||||
PHY_MDM6600_CMD_BP_PANIC_ACK,
|
||||
PHY_MDM6600_CMD_DATA_ONLY_BYPASS, /* Reroute USB to CPCAP PHY */
|
||||
PHY_MDM6600_CMD_FULL_BYPASS, /* Reroute USB to CPCAP PHY */
|
||||
PHY_MDM6600_CMD_NO_BYPASS, /* Request normal USB mode */
|
||||
PHY_MDM6600_CMD_BP_SHUTDOWN_REQ, /* Request device power off */
|
||||
PHY_MDM6600_CMD_BP_UNKNOWN_5,
|
||||
PHY_MDM6600_CMD_BP_UNKNOWN_6,
|
||||
PHY_MDM6600_CMD_UNDEFINED,
|
||||
};
|
||||
|
||||
/*
|
||||
* MDM6600 status codes. These are based on Motorola Mapphone Linux
|
||||
* kernel tree.
|
||||
*/
|
||||
enum phy_mdm6600_status {
|
||||
PHY_MDM6600_STATUS_PANIC, /* Seems to be really off */
|
||||
PHY_MDM6600_STATUS_PANIC_BUSY_WAIT,
|
||||
PHY_MDM6600_STATUS_QC_DLOAD,
|
||||
PHY_MDM6600_STATUS_RAM_DOWNLOADER, /* MDM6600 USB flashing mode */
|
||||
PHY_MDM6600_STATUS_PHONE_CODE_AWAKE, /* MDM6600 normal USB mode */
|
||||
PHY_MDM6600_STATUS_PHONE_CODE_ASLEEP,
|
||||
PHY_MDM6600_STATUS_SHUTDOWN_ACK,
|
||||
PHY_MDM6600_STATUS_UNDEFINED,
|
||||
};
|
||||
|
||||
static const char * const
|
||||
phy_mdm6600_status_name[] = {
|
||||
"off", "busy", "qc_dl", "ram_dl", "awake",
|
||||
"asleep", "shutdown", "undefined",
|
||||
};
|
||||
|
||||
struct phy_mdm6600 {
|
||||
struct device *dev;
|
||||
struct phy *generic_phy;
|
||||
struct phy_provider *phy_provider;
|
||||
struct gpio_desc *ctrl_gpios[PHY_MDM6600_NR_CTRL_LINES];
|
||||
struct gpio_descs *mode_gpios;
|
||||
struct gpio_descs *status_gpios;
|
||||
struct gpio_descs *cmd_gpios;
|
||||
struct delayed_work bootup_work;
|
||||
struct delayed_work status_work;
|
||||
struct completion ack;
|
||||
bool enabled; /* mdm6600 phy enabled */
|
||||
bool running; /* mdm6600 boot done */
|
||||
int status;
|
||||
};
|
||||
|
||||
static int phy_mdm6600_init(struct phy *x)
|
||||
{
|
||||
struct phy_mdm6600 *ddata = phy_get_drvdata(x);
|
||||
struct gpio_desc *enable_gpio = ddata->ctrl_gpios[PHY_MDM6600_ENABLE];
|
||||
|
||||
if (!ddata->enabled)
|
||||
return -EPROBE_DEFER;
|
||||
|
||||
gpiod_set_value_cansleep(enable_gpio, 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int phy_mdm6600_power_on(struct phy *x)
|
||||
{
|
||||
struct phy_mdm6600 *ddata = phy_get_drvdata(x);
|
||||
struct gpio_desc *enable_gpio = ddata->ctrl_gpios[PHY_MDM6600_ENABLE];
|
||||
|
||||
if (!ddata->enabled)
|
||||
return -ENODEV;
|
||||
|
||||
gpiod_set_value_cansleep(enable_gpio, 1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int phy_mdm6600_power_off(struct phy *x)
|
||||
{
|
||||
struct phy_mdm6600 *ddata = phy_get_drvdata(x);
|
||||
struct gpio_desc *enable_gpio = ddata->ctrl_gpios[PHY_MDM6600_ENABLE];
|
||||
|
||||
if (!ddata->enabled)
|
||||
return -ENODEV;
|
||||
|
||||
gpiod_set_value_cansleep(enable_gpio, 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct phy_ops gpio_usb_ops = {
|
||||
.init = phy_mdm6600_init,
|
||||
.power_on = phy_mdm6600_power_on,
|
||||
.power_off = phy_mdm6600_power_off,
|
||||
.owner = THIS_MODULE,
|
||||
};
|
||||
|
||||
/**
|
||||
* phy_mdm6600_cmd() - send a command request to mdm6600
|
||||
* @ddata: device driver data
|
||||
*
|
||||
* Configures the three command request GPIOs to the specified value.
|
||||
*/
|
||||
static void phy_mdm6600_cmd(struct phy_mdm6600 *ddata, int val)
|
||||
{
|
||||
int values[PHY_MDM6600_NR_CMD_LINES];
|
||||
int i;
|
||||
|
||||
val &= (1 << PHY_MDM6600_NR_CMD_LINES) - 1;
|
||||
for (i = 0; i < PHY_MDM6600_NR_CMD_LINES; i++)
|
||||
values[i] = (val & BIT(i)) >> i;
|
||||
|
||||
gpiod_set_array_value_cansleep(PHY_MDM6600_NR_CMD_LINES,
|
||||
ddata->cmd_gpios->desc, values);
|
||||
}
|
||||
|
||||
/**
|
||||
* phy_mdm6600_status() - read mdm6600 status lines
|
||||
* @ddata: device driver data
|
||||
*/
|
||||
static void phy_mdm6600_status(struct work_struct *work)
|
||||
{
|
||||
struct phy_mdm6600 *ddata;
|
||||
struct device *dev;
|
||||
int values[PHY_MDM6600_NR_STATUS_LINES];
|
||||
int error, i, val = 0;
|
||||
|
||||
ddata = container_of(work, struct phy_mdm6600, status_work.work);
|
||||
dev = ddata->dev;
|
||||
|
||||
error = gpiod_get_array_value_cansleep(PHY_MDM6600_NR_CMD_LINES,
|
||||
ddata->status_gpios->desc,
|
||||
values);
|
||||
if (error)
|
||||
return;
|
||||
|
||||
for (i = 0; i < PHY_MDM6600_NR_CMD_LINES; i++) {
|
||||
val |= values[i] << i;
|
||||
dev_dbg(ddata->dev, "XXX %s: i: %i values[i]: %i val: %i\n",
|
||||
__func__, i, values[i], val);
|
||||
}
|
||||
ddata->status = val;
|
||||
|
||||
dev_info(dev, "modem status: %i %s\n",
|
||||
ddata->status,
|
||||
phy_mdm6600_status_name[ddata->status & 7]);
|
||||
complete(&ddata->ack);
|
||||
}
|
||||
|
||||
static irqreturn_t phy_mdm6600_irq_thread(int irq, void *data)
|
||||
{
|
||||
struct phy_mdm6600 *ddata = data;
|
||||
|
||||
schedule_delayed_work(&ddata->status_work, msecs_to_jiffies(10));
|
||||
|
||||
return IRQ_HANDLED;
|
||||
}
|
||||
|
||||
/**
|
||||
* phy_mdm6600_wakeirq_thread - handle mode1 line OOB wake after booting
|
||||
* @irq: interrupt
|
||||
* @data: interrupt handler data
|
||||
*
|
||||
* GPIO mode1 is used initially as output to configure the USB boot
|
||||
* mode for mdm6600. After booting it is used as input for OOB wake
|
||||
* signal from mdm6600 to the SoC. Just use it for debug info only
|
||||
* for now.
|
||||
*/
|
||||
static irqreturn_t phy_mdm6600_wakeirq_thread(int irq, void *data)
|
||||
{
|
||||
struct phy_mdm6600 *ddata = data;
|
||||
struct gpio_desc *mode_gpio1;
|
||||
|
||||
mode_gpio1 = ddata->mode_gpios->desc[PHY_MDM6600_MODE1];
|
||||
dev_dbg(ddata->dev, "OOB wake on mode_gpio1: %i\n",
|
||||
gpiod_get_value(mode_gpio1));
|
||||
|
||||
return IRQ_HANDLED;
|
||||
}
|
||||
|
||||
/**
|
||||
* phy_mdm6600_init_irq() - initialize mdm6600 status IRQ lines
|
||||
* @ddata: device driver data
|
||||
*/
|
||||
static void phy_mdm6600_init_irq(struct phy_mdm6600 *ddata)
|
||||
{
|
||||
struct device *dev = ddata->dev;
|
||||
int i, error, irq;
|
||||
|
||||
for (i = PHY_MDM6600_STATUS0;
|
||||
i <= PHY_MDM6600_STATUS2; i++) {
|
||||
struct gpio_desc *gpio = ddata->status_gpios->desc[i];
|
||||
|
||||
irq = gpiod_to_irq(gpio);
|
||||
if (irq <= 0)
|
||||
continue;
|
||||
|
||||
error = devm_request_threaded_irq(dev, irq, NULL,
|
||||
phy_mdm6600_irq_thread,
|
||||
IRQF_TRIGGER_RISING |
|
||||
IRQF_TRIGGER_FALLING |
|
||||
IRQF_ONESHOT,
|
||||
"mdm6600",
|
||||
ddata);
|
||||
if (error)
|
||||
dev_warn(dev, "no modem status irq%i: %i\n",
|
||||
irq, error);
|
||||
}
|
||||
}
|
||||
|
||||
struct phy_mdm6600_map {
|
||||
const char *name;
|
||||
int direction;
|
||||
};
|
||||
|
||||
static const struct phy_mdm6600_map
|
||||
phy_mdm6600_ctrl_gpio_map[PHY_MDM6600_NR_CTRL_LINES] = {
|
||||
{ "enable", GPIOD_OUT_LOW, }, /* low = phy disabled */
|
||||
{ "power", GPIOD_OUT_LOW, }, /* low = off */
|
||||
{ "reset", GPIOD_OUT_HIGH, }, /* high = reset */
|
||||
};
|
||||
|
||||
/**
|
||||
* phy_mdm6600_init_lines() - initialize mdm6600 GPIO lines
|
||||
* @ddata: device driver data
|
||||
*/
|
||||
static int phy_mdm6600_init_lines(struct phy_mdm6600 *ddata)
|
||||
{
|
||||
struct device *dev = ddata->dev;
|
||||
int i;
|
||||
|
||||
/* MDM6600 control lines */
|
||||
for (i = 0; i < ARRAY_SIZE(phy_mdm6600_ctrl_gpio_map); i++) {
|
||||
const struct phy_mdm6600_map *map =
|
||||
&phy_mdm6600_ctrl_gpio_map[i];
|
||||
struct gpio_desc **gpio = &ddata->ctrl_gpios[i];
|
||||
|
||||
*gpio = devm_gpiod_get(dev, map->name, map->direction);
|
||||
if (IS_ERR(*gpio)) {
|
||||
dev_info(dev, "gpio %s error %li\n",
|
||||
map->name, PTR_ERR(*gpio));
|
||||
return PTR_ERR(*gpio);
|
||||
}
|
||||
}
|
||||
|
||||
/* MDM6600 USB start-up mode output lines */
|
||||
ddata->mode_gpios = devm_gpiod_get_array(dev, "motorola,mode",
|
||||
GPIOD_OUT_LOW);
|
||||
if (IS_ERR(ddata->mode_gpios))
|
||||
return PTR_ERR(ddata->mode_gpios);
|
||||
|
||||
if (ddata->mode_gpios->ndescs != PHY_MDM6600_NR_MODE_LINES)
|
||||
return -EINVAL;
|
||||
|
||||
/* MDM6600 status input lines */
|
||||
ddata->status_gpios = devm_gpiod_get_array(dev, "motorola,status",
|
||||
GPIOD_IN);
|
||||
if (IS_ERR(ddata->status_gpios))
|
||||
return PTR_ERR(ddata->status_gpios);
|
||||
|
||||
if (ddata->status_gpios->ndescs != PHY_MDM6600_NR_STATUS_LINES)
|
||||
return -EINVAL;
|
||||
|
||||
/* MDM6600 cmd output lines */
|
||||
ddata->cmd_gpios = devm_gpiod_get_array(dev, "motorola,cmd",
|
||||
GPIOD_OUT_LOW);
|
||||
if (IS_ERR(ddata->cmd_gpios))
|
||||
return PTR_ERR(ddata->cmd_gpios);
|
||||
|
||||
if (ddata->cmd_gpios->ndescs != PHY_MDM6600_NR_CMD_LINES)
|
||||
return -EINVAL;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* phy_mdm6600_device_power_on() - power on mdm6600 device
|
||||
* @ddata: device driver data
|
||||
*
|
||||
* To get the integrated USB phy in MDM6600 takes some hoops. We must ensure
|
||||
* the shared USB bootmode GPIOs are configured, then request modem start-up,
|
||||
* reset and power-up.. And then we need to recycle the shared USB bootmode
|
||||
* GPIOs as they are also used for Out of Band (OOB) wake for the USB and
|
||||
* TS 27.010 serial mux.
|
||||
*/
|
||||
static int phy_mdm6600_device_power_on(struct phy_mdm6600 *ddata)
|
||||
{
|
||||
struct gpio_desc *mode_gpio0, *mode_gpio1, *reset_gpio, *power_gpio;
|
||||
int error = 0, wakeirq;
|
||||
|
||||
mode_gpio0 = ddata->mode_gpios->desc[PHY_MDM6600_MODE0];
|
||||
mode_gpio1 = ddata->mode_gpios->desc[PHY_MDM6600_MODE1];
|
||||
reset_gpio = ddata->ctrl_gpios[PHY_MDM6600_RESET];
|
||||
power_gpio = ddata->ctrl_gpios[PHY_MDM6600_POWER];
|
||||
|
||||
/*
|
||||
* Shared GPIOs must be low for normal USB mode. After booting
|
||||
* they are used for OOB wake signaling. These can be also used
|
||||
* to configure USB flashing mode later on based on a module
|
||||
* parameter.
|
||||
*/
|
||||
gpiod_set_value_cansleep(mode_gpio0, 0);
|
||||
gpiod_set_value_cansleep(mode_gpio1, 0);
|
||||
|
||||
/* Request start-up mode */
|
||||
phy_mdm6600_cmd(ddata, PHY_MDM6600_CMD_NO_BYPASS);
|
||||
|
||||
/* Request a reset first */
|
||||
gpiod_set_value_cansleep(reset_gpio, 0);
|
||||
msleep(100);
|
||||
|
||||
/* Toggle power GPIO to request mdm6600 to start */
|
||||
gpiod_set_value_cansleep(power_gpio, 1);
|
||||
msleep(100);
|
||||
gpiod_set_value_cansleep(power_gpio, 0);
|
||||
|
||||
/*
|
||||
* Looks like the USB PHY needs between 2.2 to 4 seconds.
|
||||
* If we try to use it before that, we will get L3 errors
|
||||
* from omap-usb-host trying to access the PHY. See also
|
||||
* phy_mdm6600_init() for -EPROBE_DEFER.
|
||||
*/
|
||||
msleep(PHY_MDM6600_PHY_DELAY_MS);
|
||||
ddata->enabled = true;
|
||||
|
||||
/* Booting up the rest of MDM6600 will take total about 8 seconds */
|
||||
dev_info(ddata->dev, "Waiting for power up request to complete..\n");
|
||||
if (wait_for_completion_timeout(&ddata->ack,
|
||||
msecs_to_jiffies(PHY_MDM6600_ENABLED_DELAY_MS))) {
|
||||
if (ddata->status > PHY_MDM6600_STATUS_PANIC &&
|
||||
ddata->status < PHY_MDM6600_STATUS_SHUTDOWN_ACK)
|
||||
dev_info(ddata->dev, "Powered up OK\n");
|
||||
} else {
|
||||
ddata->enabled = false;
|
||||
error = -ETIMEDOUT;
|
||||
dev_err(ddata->dev, "Timed out powering up\n");
|
||||
}
|
||||
|
||||
/* Reconfigure mode1 GPIO as input for OOB wake */
|
||||
gpiod_direction_input(mode_gpio1);
|
||||
|
||||
wakeirq = gpiod_to_irq(mode_gpio1);
|
||||
if (wakeirq <= 0)
|
||||
return wakeirq;
|
||||
|
||||
error = devm_request_threaded_irq(ddata->dev, wakeirq, NULL,
|
||||
phy_mdm6600_wakeirq_thread,
|
||||
IRQF_TRIGGER_RISING |
|
||||
IRQF_TRIGGER_FALLING |
|
||||
IRQF_ONESHOT,
|
||||
"mdm6600-wake",
|
||||
ddata);
|
||||
if (error)
|
||||
dev_warn(ddata->dev, "no modem wakeirq irq%i: %i\n",
|
||||
wakeirq, error);
|
||||
|
||||
ddata->running = true;
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
/**
|
||||
* phy_mdm6600_device_power_off() - power off mdm6600 device
|
||||
* @ddata: device driver data
|
||||
*/
|
||||
static void phy_mdm6600_device_power_off(struct phy_mdm6600 *ddata)
|
||||
{
|
||||
struct gpio_desc *reset_gpio =
|
||||
ddata->ctrl_gpios[PHY_MDM6600_RESET];
|
||||
|
||||
ddata->enabled = false;
|
||||
phy_mdm6600_cmd(ddata, PHY_MDM6600_CMD_BP_SHUTDOWN_REQ);
|
||||
msleep(100);
|
||||
|
||||
gpiod_set_value_cansleep(reset_gpio, 1);
|
||||
|
||||
dev_info(ddata->dev, "Waiting for power down request to complete.. ");
|
||||
if (wait_for_completion_timeout(&ddata->ack,
|
||||
msecs_to_jiffies(5000))) {
|
||||
if (ddata->status == PHY_MDM6600_STATUS_PANIC)
|
||||
dev_info(ddata->dev, "Powered down OK\n");
|
||||
} else {
|
||||
dev_err(ddata->dev, "Timed out powering down\n");
|
||||
}
|
||||
}
|
||||
|
||||
static void phy_mdm6600_deferred_power_on(struct work_struct *work)
|
||||
{
|
||||
struct phy_mdm6600 *ddata;
|
||||
int error;
|
||||
|
||||
ddata = container_of(work, struct phy_mdm6600, bootup_work.work);
|
||||
|
||||
error = phy_mdm6600_device_power_on(ddata);
|
||||
if (error)
|
||||
dev_err(ddata->dev, "Device not functional\n");
|
||||
}
|
||||
|
||||
static const struct of_device_id phy_mdm6600_id_table[] = {
|
||||
{ .compatible = "motorola,mapphone-mdm6600", },
|
||||
{},
|
||||
};
|
||||
MODULE_DEVICE_TABLE(of, phy_mdm6600_id_table);
|
||||
|
||||
static int phy_mdm6600_probe(struct platform_device *pdev)
|
||||
{
|
||||
struct phy_mdm6600 *ddata;
|
||||
int error;
|
||||
|
||||
ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
|
||||
if (!ddata)
|
||||
return -ENOMEM;
|
||||
|
||||
INIT_DELAYED_WORK(&ddata->bootup_work,
|
||||
phy_mdm6600_deferred_power_on);
|
||||
INIT_DELAYED_WORK(&ddata->status_work, phy_mdm6600_status);
|
||||
init_completion(&ddata->ack);
|
||||
|
||||
ddata->dev = &pdev->dev;
|
||||
platform_set_drvdata(pdev, ddata);
|
||||
|
||||
error = phy_mdm6600_init_lines(ddata);
|
||||
if (error)
|
||||
return error;
|
||||
|
||||
phy_mdm6600_init_irq(ddata);
|
||||
|
||||
ddata->generic_phy = devm_phy_create(ddata->dev, NULL, &gpio_usb_ops);
|
||||
if (IS_ERR(ddata->generic_phy)) {
|
||||
error = PTR_ERR(ddata->generic_phy);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
phy_set_drvdata(ddata->generic_phy, ddata);
|
||||
|
||||
ddata->phy_provider =
|
||||
devm_of_phy_provider_register(ddata->dev,
|
||||
of_phy_simple_xlate);
|
||||
if (IS_ERR(ddata->phy_provider)) {
|
||||
error = PTR_ERR(ddata->phy_provider);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
schedule_delayed_work(&ddata->bootup_work, 0);
|
||||
|
||||
/*
|
||||
* See phy_mdm6600_device_power_on(). We should be able
|
||||
* to remove this eventually when ohci-platform can deal
|
||||
* with -EPROBE_DEFER.
|
||||
*/
|
||||
msleep(PHY_MDM6600_PHY_DELAY_MS + 500);
|
||||
|
||||
return 0;
|
||||
|
||||
cleanup:
|
||||
phy_mdm6600_device_power_off(ddata);
|
||||
return error;
|
||||
}
|
||||
|
||||
static int phy_mdm6600_remove(struct platform_device *pdev)
|
||||
{
|
||||
struct phy_mdm6600 *ddata = platform_get_drvdata(pdev);
|
||||
struct gpio_desc *reset_gpio = ddata->ctrl_gpios[PHY_MDM6600_RESET];
|
||||
|
||||
if (!ddata->running)
|
||||
wait_for_completion_timeout(&ddata->ack,
|
||||
msecs_to_jiffies(PHY_MDM6600_ENABLED_DELAY_MS));
|
||||
|
||||
gpiod_set_value_cansleep(reset_gpio, 1);
|
||||
phy_mdm6600_device_power_off(ddata);
|
||||
|
||||
cancel_delayed_work_sync(&ddata->bootup_work);
|
||||
cancel_delayed_work_sync(&ddata->status_work);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct platform_driver phy_mdm6600_driver = {
|
||||
.probe = phy_mdm6600_probe,
|
||||
.remove = phy_mdm6600_remove,
|
||||
.driver = {
|
||||
.name = "phy-mapphone-mdm6600",
|
||||
.of_match_table = of_match_ptr(phy_mdm6600_id_table),
|
||||
},
|
||||
};
|
||||
|
||||
module_platform_driver(phy_mdm6600_driver);
|
||||
|
||||
MODULE_ALIAS("platform:gpio_usb");
|
||||
MODULE_AUTHOR("Tony Lindgren <tony@atomide.com>");
|
||||
MODULE_DESCRIPTION("mdm6600 gpio usb phy driver");
|
||||
MODULE_LICENSE("GPL v2");
|
@ -351,6 +351,8 @@ int phy_set_mode(struct phy *phy, enum phy_mode mode)
|
||||
|
||||
mutex_lock(&phy->mutex);
|
||||
ret = phy->ops->set_mode(phy, mode);
|
||||
if (!ret)
|
||||
phy->attrs.mode = mode;
|
||||
mutex_unlock(&phy->mutex);
|
||||
|
||||
return ret;
|
||||
|
@ -60,8 +60,14 @@ static int lpc18xx_usb_otg_phy_power_on(struct phy *phy)
|
||||
return ret;
|
||||
|
||||
/* The bit in CREG is cleared to enable the PHY */
|
||||
return regmap_update_bits(lpc->reg, LPC18XX_CREG_CREG0,
|
||||
ret = regmap_update_bits(lpc->reg, LPC18XX_CREG_CREG0,
|
||||
LPC18XX_CREG_CREG0_USB0PHY, 0);
|
||||
if (ret) {
|
||||
clk_disable(lpc->clk);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int lpc18xx_usb_otg_phy_power_off(struct phy *phy)
|
||||
|
@ -1,15 +1,6 @@
|
||||
// SPDX-License-Identifier: GPL-2.0
|
||||
/*
|
||||
* Copyright (c) 2017, The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 and
|
||||
* only 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/clk.h>
|
||||
@ -31,124 +22,7 @@
|
||||
|
||||
#include <dt-bindings/phy/phy.h>
|
||||
|
||||
/* QMP PHY QSERDES COM registers */
|
||||
#define QSERDES_COM_BG_TIMER 0x00c
|
||||
#define QSERDES_COM_SSC_EN_CENTER 0x010
|
||||
#define QSERDES_COM_SSC_ADJ_PER1 0x014
|
||||
#define QSERDES_COM_SSC_ADJ_PER2 0x018
|
||||
#define QSERDES_COM_SSC_PER1 0x01c
|
||||
#define QSERDES_COM_SSC_PER2 0x020
|
||||
#define QSERDES_COM_SSC_STEP_SIZE1 0x024
|
||||
#define QSERDES_COM_SSC_STEP_SIZE2 0x028
|
||||
#define QSERDES_COM_BIAS_EN_CLKBUFLR_EN 0x034
|
||||
#define QSERDES_COM_CLK_ENABLE1 0x038
|
||||
#define QSERDES_COM_SYS_CLK_CTRL 0x03c
|
||||
#define QSERDES_COM_SYSCLK_BUF_ENABLE 0x040
|
||||
#define QSERDES_COM_PLL_IVCO 0x048
|
||||
#define QSERDES_COM_LOCK_CMP1_MODE0 0x04c
|
||||
#define QSERDES_COM_LOCK_CMP2_MODE0 0x050
|
||||
#define QSERDES_COM_LOCK_CMP3_MODE0 0x054
|
||||
#define QSERDES_COM_LOCK_CMP1_MODE1 0x058
|
||||
#define QSERDES_COM_LOCK_CMP2_MODE1 0x05c
|
||||
#define QSERDES_COM_LOCK_CMP3_MODE1 0x060
|
||||
#define QSERDES_COM_BG_TRIM 0x070
|
||||
#define QSERDES_COM_CLK_EP_DIV 0x074
|
||||
#define QSERDES_COM_CP_CTRL_MODE0 0x078
|
||||
#define QSERDES_COM_CP_CTRL_MODE1 0x07c
|
||||
#define QSERDES_COM_PLL_RCTRL_MODE0 0x084
|
||||
#define QSERDES_COM_PLL_RCTRL_MODE1 0x088
|
||||
#define QSERDES_COM_PLL_CCTRL_MODE0 0x090
|
||||
#define QSERDES_COM_PLL_CCTRL_MODE1 0x094
|
||||
#define QSERDES_COM_BIAS_EN_CTRL_BY_PSM 0x0a8
|
||||
#define QSERDES_COM_SYSCLK_EN_SEL 0x0ac
|
||||
#define QSERDES_COM_RESETSM_CNTRL 0x0b4
|
||||
#define QSERDES_COM_RESTRIM_CTRL 0x0bc
|
||||
#define QSERDES_COM_RESCODE_DIV_NUM 0x0c4
|
||||
#define QSERDES_COM_LOCK_CMP_EN 0x0c8
|
||||
#define QSERDES_COM_LOCK_CMP_CFG 0x0cc
|
||||
#define QSERDES_COM_DEC_START_MODE0 0x0d0
|
||||
#define QSERDES_COM_DEC_START_MODE1 0x0d4
|
||||
#define QSERDES_COM_DIV_FRAC_START1_MODE0 0x0dc
|
||||
#define QSERDES_COM_DIV_FRAC_START2_MODE0 0x0e0
|
||||
#define QSERDES_COM_DIV_FRAC_START3_MODE0 0x0e4
|
||||
#define QSERDES_COM_DIV_FRAC_START1_MODE1 0x0e8
|
||||
#define QSERDES_COM_DIV_FRAC_START2_MODE1 0x0ec
|
||||
#define QSERDES_COM_DIV_FRAC_START3_MODE1 0x0f0
|
||||
#define QSERDES_COM_INTEGLOOP_GAIN0_MODE0 0x108
|
||||
#define QSERDES_COM_INTEGLOOP_GAIN1_MODE0 0x10c
|
||||
#define QSERDES_COM_INTEGLOOP_GAIN0_MODE1 0x110
|
||||
#define QSERDES_COM_INTEGLOOP_GAIN1_MODE1 0x114
|
||||
#define QSERDES_COM_VCO_TUNE_CTRL 0x124
|
||||
#define QSERDES_COM_VCO_TUNE_MAP 0x128
|
||||
#define QSERDES_COM_VCO_TUNE1_MODE0 0x12c
|
||||
#define QSERDES_COM_VCO_TUNE2_MODE0 0x130
|
||||
#define QSERDES_COM_VCO_TUNE1_MODE1 0x134
|
||||
#define QSERDES_COM_VCO_TUNE2_MODE1 0x138
|
||||
#define QSERDES_COM_VCO_TUNE_TIMER1 0x144
|
||||
#define QSERDES_COM_VCO_TUNE_TIMER2 0x148
|
||||
#define QSERDES_COM_BG_CTRL 0x170
|
||||
#define QSERDES_COM_CLK_SELECT 0x174
|
||||
#define QSERDES_COM_HSCLK_SEL 0x178
|
||||
#define QSERDES_COM_CORECLK_DIV 0x184
|
||||
#define QSERDES_COM_CORE_CLK_EN 0x18c
|
||||
#define QSERDES_COM_C_READY_STATUS 0x190
|
||||
#define QSERDES_COM_CMN_CONFIG 0x194
|
||||
#define QSERDES_COM_SVS_MODE_CLK_SEL 0x19c
|
||||
#define QSERDES_COM_DEBUG_BUS0 0x1a0
|
||||
#define QSERDES_COM_DEBUG_BUS1 0x1a4
|
||||
#define QSERDES_COM_DEBUG_BUS2 0x1a8
|
||||
#define QSERDES_COM_DEBUG_BUS3 0x1ac
|
||||
#define QSERDES_COM_DEBUG_BUS_SEL 0x1b0
|
||||
#define QSERDES_COM_CORECLK_DIV_MODE1 0x1bc
|
||||
|
||||
/* QMP PHY TX registers */
|
||||
#define QSERDES_TX_RES_CODE_LANE_OFFSET 0x054
|
||||
#define QSERDES_TX_DEBUG_BUS_SEL 0x064
|
||||
#define QSERDES_TX_HIGHZ_TRANSCEIVEREN_BIAS_DRVR_EN 0x068
|
||||
#define QSERDES_TX_LANE_MODE 0x094
|
||||
#define QSERDES_TX_RCV_DETECT_LVL_2 0x0ac
|
||||
|
||||
/* QMP PHY RX registers */
|
||||
#define QSERDES_RX_UCDR_SO_GAIN_HALF 0x010
|
||||
#define QSERDES_RX_UCDR_SO_GAIN 0x01c
|
||||
#define QSERDES_RX_UCDR_FASTLOCK_FO_GAIN 0x040
|
||||
#define QSERDES_RX_UCDR_SO_SATURATION_AND_ENABLE 0x048
|
||||
#define QSERDES_RX_RX_TERM_BW 0x090
|
||||
#define QSERDES_RX_RX_EQ_GAIN1_LSB 0x0c4
|
||||
#define QSERDES_RX_RX_EQ_GAIN1_MSB 0x0c8
|
||||
#define QSERDES_RX_RX_EQ_GAIN2_LSB 0x0cc
|
||||
#define QSERDES_RX_RX_EQ_GAIN2_MSB 0x0d0
|
||||
#define QSERDES_RX_RX_EQU_ADAPTOR_CNTRL2 0x0d8
|
||||
#define QSERDES_RX_RX_EQU_ADAPTOR_CNTRL3 0x0dc
|
||||
#define QSERDES_RX_RX_EQU_ADAPTOR_CNTRL4 0x0e0
|
||||
#define QSERDES_RX_RX_EQ_OFFSET_ADAPTOR_CNTRL1 0x108
|
||||
#define QSERDES_RX_RX_OFFSET_ADAPTOR_CNTRL2 0x10c
|
||||
#define QSERDES_RX_SIGDET_ENABLES 0x110
|
||||
#define QSERDES_RX_SIGDET_CNTRL 0x114
|
||||
#define QSERDES_RX_SIGDET_LVL 0x118
|
||||
#define QSERDES_RX_SIGDET_DEGLITCH_CNTRL 0x11c
|
||||
#define QSERDES_RX_RX_BAND 0x120
|
||||
#define QSERDES_RX_RX_INTERFACE_MODE 0x12c
|
||||
|
||||
/* QMP PHY PCS registers */
|
||||
#define QPHY_POWER_DOWN_CONTROL 0x04
|
||||
#define QPHY_TXDEEMPH_M6DB_V0 0x24
|
||||
#define QPHY_TXDEEMPH_M3P5DB_V0 0x28
|
||||
#define QPHY_ENDPOINT_REFCLK_DRIVE 0x54
|
||||
#define QPHY_RX_IDLE_DTCT_CNTRL 0x58
|
||||
#define QPHY_POWER_STATE_CONFIG1 0x60
|
||||
#define QPHY_POWER_STATE_CONFIG2 0x64
|
||||
#define QPHY_POWER_STATE_CONFIG4 0x6c
|
||||
#define QPHY_LOCK_DETECT_CONFIG1 0x80
|
||||
#define QPHY_LOCK_DETECT_CONFIG2 0x84
|
||||
#define QPHY_LOCK_DETECT_CONFIG3 0x88
|
||||
#define QPHY_PWRUP_RESET_DLY_TIME_AUXCLK 0xa0
|
||||
#define QPHY_LP_WAKEUP_DLY_TIME_AUXCLK 0xa4
|
||||
#define QPHY_PLL_LOCK_CHK_DLY_TIME_AUXCLK_LSB 0x1A8
|
||||
#define QPHY_OSC_DTCT_ACTIONS 0x1AC
|
||||
#define QPHY_RX_SIGDET_LVL 0x1D8
|
||||
#define QPHY_L1SS_WAKEUP_DLY_TIME_AUXCLK_LSB 0x1DC
|
||||
#define QPHY_L1SS_WAKEUP_DLY_TIME_AUXCLK_MSB 0x1E0
|
||||
#include "phy-qcom-qmp.h"
|
||||
|
||||
/* QPHY_SW_RESET bit */
|
||||
#define SW_RESET BIT(0)
|
||||
@ -164,6 +38,34 @@
|
||||
/* QPHY_COM_PCS_READY_STATUS bit */
|
||||
#define PCS_READY BIT(0)
|
||||
|
||||
/* QPHY_V3_DP_COM_RESET_OVRD_CTRL register bits */
|
||||
/* DP PHY soft reset */
|
||||
#define SW_DPPHY_RESET BIT(0)
|
||||
/* mux to select DP PHY reset control, 0:HW control, 1: software reset */
|
||||
#define SW_DPPHY_RESET_MUX BIT(1)
|
||||
/* USB3 PHY soft reset */
|
||||
#define SW_USB3PHY_RESET BIT(2)
|
||||
/* mux to select USB3 PHY reset control, 0:HW control, 1: software reset */
|
||||
#define SW_USB3PHY_RESET_MUX BIT(3)
|
||||
|
||||
/* QPHY_V3_DP_COM_PHY_MODE_CTRL register bits */
|
||||
#define USB3_MODE BIT(0) /* enables USB3 mode */
|
||||
#define DP_MODE BIT(1) /* enables DP mode */
|
||||
|
||||
/* QPHY_PCS_AUTONOMOUS_MODE_CTRL register bits */
|
||||
#define ARCVR_DTCT_EN BIT(0)
|
||||
#define ALFPS_DTCT_EN BIT(1)
|
||||
#define ARCVR_DTCT_EVENT_SEL BIT(4)
|
||||
|
||||
/* QPHY_PCS_LFPS_RXTERM_IRQ_CLEAR register bits */
|
||||
#define IRQ_CLEAR BIT(0)
|
||||
|
||||
/* QPHY_PCS_LFPS_RXTERM_IRQ_STATUS register bits */
|
||||
#define RCVR_DETECT BIT(0)
|
||||
|
||||
/* QPHY_V3_PCS_MISC_CLAMP_ENABLE register bits */
|
||||
#define CLAMP_EN BIT(0) /* enables i/o clamp_n */
|
||||
|
||||
#define PHY_INIT_COMPLETE_TIMEOUT 1000
|
||||
#define POWER_DOWN_DELAY_US_MIN 10
|
||||
#define POWER_DOWN_DELAY_US_MAX 11
|
||||
@ -210,6 +112,9 @@ enum qphy_reg_layout {
|
||||
QPHY_SW_RESET,
|
||||
QPHY_START_CTRL,
|
||||
QPHY_PCS_READY_STATUS,
|
||||
QPHY_PCS_AUTONOMOUS_MODE_CTRL,
|
||||
QPHY_PCS_LFPS_RXTERM_IRQ_CLEAR,
|
||||
QPHY_PCS_LFPS_RXTERM_IRQ_STATUS,
|
||||
};
|
||||
|
||||
static const unsigned int pciephy_regs_layout[] = {
|
||||
@ -237,6 +142,18 @@ static const unsigned int usb3phy_regs_layout[] = {
|
||||
[QPHY_SW_RESET] = 0x00,
|
||||
[QPHY_START_CTRL] = 0x08,
|
||||
[QPHY_PCS_READY_STATUS] = 0x17c,
|
||||
[QPHY_PCS_AUTONOMOUS_MODE_CTRL] = 0x0d4,
|
||||
[QPHY_PCS_LFPS_RXTERM_IRQ_CLEAR] = 0x0d8,
|
||||
[QPHY_PCS_LFPS_RXTERM_IRQ_STATUS] = 0x178,
|
||||
};
|
||||
|
||||
static const unsigned int qmp_v3_usb3phy_regs_layout[] = {
|
||||
[QPHY_SW_RESET] = 0x00,
|
||||
[QPHY_START_CTRL] = 0x08,
|
||||
[QPHY_PCS_READY_STATUS] = 0x174,
|
||||
[QPHY_PCS_AUTONOMOUS_MODE_CTRL] = 0x0d8,
|
||||
[QPHY_PCS_LFPS_RXTERM_IRQ_CLEAR] = 0x0dc,
|
||||
[QPHY_PCS_LFPS_RXTERM_IRQ_STATUS] = 0x170,
|
||||
};
|
||||
|
||||
static const struct qmp_phy_init_tbl msm8996_pcie_serdes_tbl[] = {
|
||||
@ -467,6 +384,112 @@ static const struct qmp_phy_init_tbl ipq8074_pcie_pcs_tbl[] = {
|
||||
QMP_PHY_INIT_CFG_L(QPHY_START_CTRL, 0x3),
|
||||
};
|
||||
|
||||
static const struct qmp_phy_init_tbl qmp_v3_usb3_serdes_tbl[] = {
|
||||
QMP_PHY_INIT_CFG(QSERDES_V3_COM_PLL_IVCO, 0x07),
|
||||
QMP_PHY_INIT_CFG(QSERDES_V3_COM_SYSCLK_EN_SEL, 0x14),
|
||||
QMP_PHY_INIT_CFG(QSERDES_V3_COM_BIAS_EN_CLKBUFLR_EN, 0x08),
|
||||
QMP_PHY_INIT_CFG(QSERDES_V3_COM_CLK_SELECT, 0x30),
|
||||
QMP_PHY_INIT_CFG(QSERDES_V3_COM_SYS_CLK_CTRL, 0x02),
|
||||
QMP_PHY_INIT_CFG(QSERDES_V3_COM_RESETSM_CNTRL2, 0x08),
|
||||
QMP_PHY_INIT_CFG(QSERDES_V3_COM_CMN_CONFIG, 0x16),
|
||||
QMP_PHY_INIT_CFG(QSERDES_V3_COM_SVS_MODE_CLK_SEL, 0x01),
|
||||
QMP_PHY_INIT_CFG(QSERDES_V3_COM_HSCLK_SEL, 0x80),
|
||||
QMP_PHY_INIT_CFG(QSERDES_V3_COM_DEC_START_MODE0, 0x82),
|
||||
QMP_PHY_INIT_CFG(QSERDES_V3_COM_DIV_FRAC_START1_MODE0, 0xab),
|
||||
QMP_PHY_INIT_CFG(QSERDES_V3_COM_DIV_FRAC_START2_MODE0, 0xea),
|
||||
QMP_PHY_INIT_CFG(QSERDES_V3_COM_DIV_FRAC_START3_MODE0, 0x02),
|
||||
QMP_PHY_INIT_CFG(QSERDES_V3_COM_CP_CTRL_MODE0, 0x06),
|
||||
QMP_PHY_INIT_CFG(QSERDES_V3_COM_PLL_RCTRL_MODE0, 0x16),
|
||||
QMP_PHY_INIT_CFG(QSERDES_V3_COM_PLL_CCTRL_MODE0, 0x36),
|
||||
QMP_PHY_INIT_CFG(QSERDES_V3_COM_INTEGLOOP_GAIN1_MODE0, 0x00),
|
||||
QMP_PHY_INIT_CFG(QSERDES_V3_COM_INTEGLOOP_GAIN0_MODE0, 0x3f),
|
||||
QMP_PHY_INIT_CFG(QSERDES_V3_COM_VCO_TUNE2_MODE0, 0x01),
|
||||
QMP_PHY_INIT_CFG(QSERDES_V3_COM_VCO_TUNE1_MODE0, 0xc9),
|
||||
QMP_PHY_INIT_CFG(QSERDES_V3_COM_CORECLK_DIV_MODE0, 0x0a),
|
||||
QMP_PHY_INIT_CFG(QSERDES_V3_COM_LOCK_CMP3_MODE0, 0x00),
|
||||
QMP_PHY_INIT_CFG(QSERDES_V3_COM_LOCK_CMP2_MODE0, 0x34),
|
||||
QMP_PHY_INIT_CFG(QSERDES_V3_COM_LOCK_CMP1_MODE0, 0x15),
|
||||
QMP_PHY_INIT_CFG(QSERDES_V3_COM_LOCK_CMP_EN, 0x04),
|
||||
QMP_PHY_INIT_CFG(QSERDES_V3_COM_CORE_CLK_EN, 0x00),
|
||||
QMP_PHY_INIT_CFG(QSERDES_V3_COM_LOCK_CMP_CFG, 0x00),
|
||||
QMP_PHY_INIT_CFG(QSERDES_V3_COM_VCO_TUNE_MAP, 0x00),
|
||||
QMP_PHY_INIT_CFG(QSERDES_V3_COM_SYSCLK_BUF_ENABLE, 0x0a),
|
||||
QMP_PHY_INIT_CFG(QSERDES_V3_COM_SSC_EN_CENTER, 0x01),
|
||||
QMP_PHY_INIT_CFG(QSERDES_V3_COM_SSC_PER1, 0x31),
|
||||
QMP_PHY_INIT_CFG(QSERDES_V3_COM_SSC_PER2, 0x01),
|
||||
QMP_PHY_INIT_CFG(QSERDES_V3_COM_SSC_ADJ_PER1, 0x00),
|
||||
QMP_PHY_INIT_CFG(QSERDES_V3_COM_SSC_ADJ_PER2, 0x00),
|
||||
QMP_PHY_INIT_CFG(QSERDES_V3_COM_SSC_STEP_SIZE1, 0x85),
|
||||
QMP_PHY_INIT_CFG(QSERDES_V3_COM_SSC_STEP_SIZE2, 0x07),
|
||||
};
|
||||
|
||||
static const struct qmp_phy_init_tbl qmp_v3_usb3_tx_tbl[] = {
|
||||
QMP_PHY_INIT_CFG(QSERDES_V3_TX_HIGHZ_DRVR_EN, 0x10),
|
||||
QMP_PHY_INIT_CFG(QSERDES_V3_TX_RCV_DETECT_LVL_2, 0x12),
|
||||
QMP_PHY_INIT_CFG(QSERDES_V3_TX_LANE_MODE_1, 0x16),
|
||||
QMP_PHY_INIT_CFG(QSERDES_V3_TX_RES_CODE_LANE_OFFSET_RX, 0x09),
|
||||
QMP_PHY_INIT_CFG(QSERDES_V3_TX_RES_CODE_LANE_OFFSET_TX, 0x06),
|
||||
};
|
||||
|
||||
static const struct qmp_phy_init_tbl qmp_v3_usb3_rx_tbl[] = {
|
||||
QMP_PHY_INIT_CFG(QSERDES_V3_RX_UCDR_FASTLOCK_FO_GAIN, 0x0b),
|
||||
QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_EQU_ADAPTOR_CNTRL2, 0x0f),
|
||||
QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_EQU_ADAPTOR_CNTRL3, 0x4e),
|
||||
QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_EQU_ADAPTOR_CNTRL4, 0x18),
|
||||
QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_EQ_OFFSET_ADAPTOR_CNTRL1, 0x77),
|
||||
QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_OFFSET_ADAPTOR_CNTRL2, 0x80),
|
||||
QMP_PHY_INIT_CFG(QSERDES_V3_RX_SIGDET_CNTRL, 0x03),
|
||||
QMP_PHY_INIT_CFG(QSERDES_V3_RX_SIGDET_DEGLITCH_CNTRL, 0x16),
|
||||
QMP_PHY_INIT_CFG(QSERDES_V3_RX_UCDR_SO_SATURATION_AND_ENABLE, 0x75),
|
||||
};
|
||||
|
||||
static const struct qmp_phy_init_tbl qmp_v3_usb3_pcs_tbl[] = {
|
||||
/* FLL settings */
|
||||
QMP_PHY_INIT_CFG(QPHY_V3_PCS_FLL_CNTRL2, 0x83),
|
||||
QMP_PHY_INIT_CFG(QPHY_V3_PCS_FLL_CNT_VAL_L, 0x09),
|
||||
QMP_PHY_INIT_CFG(QPHY_V3_PCS_FLL_CNT_VAL_H_TOL, 0xa2),
|
||||
QMP_PHY_INIT_CFG(QPHY_V3_PCS_FLL_MAN_CODE, 0x40),
|
||||
QMP_PHY_INIT_CFG(QPHY_V3_PCS_FLL_CNTRL1, 0x02),
|
||||
|
||||
/* Lock Det settings */
|
||||
QMP_PHY_INIT_CFG(QPHY_V3_PCS_LOCK_DETECT_CONFIG1, 0xd1),
|
||||
QMP_PHY_INIT_CFG(QPHY_V3_PCS_LOCK_DETECT_CONFIG2, 0x1f),
|
||||
QMP_PHY_INIT_CFG(QPHY_V3_PCS_LOCK_DETECT_CONFIG3, 0x47),
|
||||
QMP_PHY_INIT_CFG(QPHY_V3_PCS_POWER_STATE_CONFIG2, 0x1b),
|
||||
|
||||
QMP_PHY_INIT_CFG(QPHY_V3_PCS_RX_SIGDET_LVL, 0xba),
|
||||
QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXMGN_V0, 0x9f),
|
||||
QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXMGN_V1, 0x9f),
|
||||
QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXMGN_V2, 0xb7),
|
||||
QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXMGN_V3, 0x4e),
|
||||
QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXMGN_V4, 0x65),
|
||||
QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXMGN_LS, 0x6b),
|
||||
QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M6DB_V0, 0x15),
|
||||
QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M3P5DB_V0, 0x0d),
|
||||
QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M6DB_V1, 0x15),
|
||||
QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M3P5DB_V1, 0x0d),
|
||||
QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M6DB_V2, 0x15),
|
||||
QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M3P5DB_V2, 0x0d),
|
||||
QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M6DB_V3, 0x15),
|
||||
QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M3P5DB_V3, 0x1d),
|
||||
QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M6DB_V4, 0x15),
|
||||
QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M3P5DB_V4, 0x0d),
|
||||
QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M6DB_LS, 0x15),
|
||||
QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M3P5DB_LS, 0x0d),
|
||||
|
||||
QMP_PHY_INIT_CFG(QPHY_V3_PCS_RATE_SLEW_CNTRL, 0x02),
|
||||
QMP_PHY_INIT_CFG(QPHY_V3_PCS_PWRUP_RESET_DLY_TIME_AUXCLK, 0x04),
|
||||
QMP_PHY_INIT_CFG(QPHY_V3_PCS_TSYNC_RSYNC_TIME, 0x44),
|
||||
QMP_PHY_INIT_CFG(QPHY_V3_PCS_PWRUP_RESET_DLY_TIME_AUXCLK, 0x04),
|
||||
QMP_PHY_INIT_CFG(QPHY_V3_PCS_RCVR_DTCT_DLY_P1U2_L, 0xe7),
|
||||
QMP_PHY_INIT_CFG(QPHY_V3_PCS_RCVR_DTCT_DLY_P1U2_H, 0x03),
|
||||
QMP_PHY_INIT_CFG(QPHY_V3_PCS_RCVR_DTCT_DLY_U3_L, 0x40),
|
||||
QMP_PHY_INIT_CFG(QPHY_V3_PCS_RCVR_DTCT_DLY_U3_H, 0x00),
|
||||
QMP_PHY_INIT_CFG(QPHY_V3_PCS_RXEQTRAINING_WAIT_TIME, 0x75),
|
||||
QMP_PHY_INIT_CFG(QPHY_V3_PCS_LFPS_TX_ECSTART_EQTLOCK, 0x86),
|
||||
QMP_PHY_INIT_CFG(QPHY_V3_PCS_RXEQTRAINING_RUN_TIME, 0x13),
|
||||
};
|
||||
|
||||
/* struct qmp_phy_cfg - per-PHY initialization config */
|
||||
struct qmp_phy_cfg {
|
||||
/* phy-type - PCIE/UFS/USB */
|
||||
@ -511,6 +534,12 @@ struct qmp_phy_cfg {
|
||||
/* power_down delay in usec */
|
||||
int pwrdn_delay_min;
|
||||
int pwrdn_delay_max;
|
||||
|
||||
/* true, if PHY has a separate DP_COM control block */
|
||||
bool has_phy_dp_com_ctrl;
|
||||
/* Register offset of secondary tx/rx lanes for USB DP combo PHY */
|
||||
unsigned int tx_b_lane_offset;
|
||||
unsigned int rx_b_lane_offset;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -520,6 +549,7 @@ struct qmp_phy_cfg {
|
||||
* @tx: iomapped memory space for lane's tx
|
||||
* @rx: iomapped memory space for lane's rx
|
||||
* @pcs: iomapped memory space for lane's pcs
|
||||
* @pcs_misc: iomapped memory space for lane's pcs_misc
|
||||
* @pipe_clk: pipe lock
|
||||
* @index: lane index
|
||||
* @qmp: QMP phy to which this lane belongs
|
||||
@ -530,6 +560,7 @@ struct qmp_phy {
|
||||
void __iomem *tx;
|
||||
void __iomem *rx;
|
||||
void __iomem *pcs;
|
||||
void __iomem *pcs_misc;
|
||||
struct clk *pipe_clk;
|
||||
unsigned int index;
|
||||
struct qcom_qmp *qmp;
|
||||
@ -541,6 +572,7 @@ struct qmp_phy {
|
||||
*
|
||||
* @dev: device
|
||||
* @serdes: iomapped memory space for phy's serdes
|
||||
* @dp_com: iomapped memory space for phy's dp_com control block
|
||||
*
|
||||
* @clks: array of clocks required by phy
|
||||
* @resets: array of resets required by phy
|
||||
@ -550,12 +582,15 @@ struct qmp_phy {
|
||||
* @phys: array of per-lane phy descriptors
|
||||
* @phy_mutex: mutex lock for PHY common block initialization
|
||||
* @init_count: phy common block initialization count
|
||||
* @phy_initialized: indicate if PHY has been initialized
|
||||
* @mode: current PHY mode
|
||||
*/
|
||||
struct qcom_qmp {
|
||||
struct device *dev;
|
||||
void __iomem *serdes;
|
||||
void __iomem *dp_com;
|
||||
|
||||
struct clk **clks;
|
||||
struct clk_bulk_data *clks;
|
||||
struct reset_control **resets;
|
||||
struct regulator_bulk_data *vregs;
|
||||
|
||||
@ -564,6 +599,8 @@ struct qcom_qmp {
|
||||
|
||||
struct mutex phy_mutex;
|
||||
int init_count;
|
||||
bool phy_initialized;
|
||||
enum phy_mode mode;
|
||||
};
|
||||
|
||||
static inline void qphy_setbits(void __iomem *base, u32 offset, u32 val)
|
||||
@ -595,6 +632,10 @@ static const char * const msm8996_phy_clk_l[] = {
|
||||
"aux", "cfg_ahb", "ref",
|
||||
};
|
||||
|
||||
static const char * const qmp_v3_phy_clk_l[] = {
|
||||
"aux", "cfg_ahb", "ref", "com_aux",
|
||||
};
|
||||
|
||||
/* list of resets */
|
||||
static const char * const msm8996_pciephy_reset_l[] = {
|
||||
"phy", "common", "cfg",
|
||||
@ -701,6 +742,38 @@ static const struct qmp_phy_cfg ipq8074_pciephy_cfg = {
|
||||
.pwrdn_delay_max = 1005, /* us */
|
||||
};
|
||||
|
||||
static const struct qmp_phy_cfg qmp_v3_usb3phy_cfg = {
|
||||
.type = PHY_TYPE_USB3,
|
||||
.nlanes = 1,
|
||||
|
||||
.serdes_tbl = qmp_v3_usb3_serdes_tbl,
|
||||
.serdes_tbl_num = ARRAY_SIZE(qmp_v3_usb3_serdes_tbl),
|
||||
.tx_tbl = qmp_v3_usb3_tx_tbl,
|
||||
.tx_tbl_num = ARRAY_SIZE(qmp_v3_usb3_tx_tbl),
|
||||
.rx_tbl = qmp_v3_usb3_rx_tbl,
|
||||
.rx_tbl_num = ARRAY_SIZE(qmp_v3_usb3_rx_tbl),
|
||||
.pcs_tbl = qmp_v3_usb3_pcs_tbl,
|
||||
.pcs_tbl_num = ARRAY_SIZE(qmp_v3_usb3_pcs_tbl),
|
||||
.clk_list = qmp_v3_phy_clk_l,
|
||||
.num_clks = ARRAY_SIZE(qmp_v3_phy_clk_l),
|
||||
.reset_list = msm8996_usb3phy_reset_l,
|
||||
.num_resets = ARRAY_SIZE(msm8996_usb3phy_reset_l),
|
||||
.vreg_list = msm8996_phy_vreg_l,
|
||||
.num_vregs = ARRAY_SIZE(msm8996_phy_vreg_l),
|
||||
.regs = qmp_v3_usb3phy_regs_layout,
|
||||
|
||||
.start_ctrl = SERDES_START | PCS_START,
|
||||
.pwrdn_ctrl = SW_PWRDN,
|
||||
.mask_pcs_ready = PHYSTATUS,
|
||||
|
||||
.pwrdn_delay_min = POWER_DOWN_DELAY_US_MIN,
|
||||
.pwrdn_delay_max = POWER_DOWN_DELAY_US_MAX,
|
||||
|
||||
.has_phy_dp_com_ctrl = true,
|
||||
.tx_b_lane_offset = 0x400,
|
||||
.rx_b_lane_offset = 0x400,
|
||||
};
|
||||
|
||||
static void qcom_qmp_phy_configure(void __iomem *base,
|
||||
const unsigned int *regs,
|
||||
const struct qmp_phy_init_tbl tbl[],
|
||||
@ -724,44 +797,20 @@ static int qcom_qmp_phy_poweron(struct phy *phy)
|
||||
{
|
||||
struct qmp_phy *qphy = phy_get_drvdata(phy);
|
||||
struct qcom_qmp *qmp = qphy->qmp;
|
||||
int num = qmp->cfg->num_vregs;
|
||||
int ret;
|
||||
|
||||
dev_vdbg(&phy->dev, "Powering on QMP phy\n");
|
||||
|
||||
/* turn on regulator supplies */
|
||||
ret = regulator_bulk_enable(num, qmp->vregs);
|
||||
if (ret) {
|
||||
dev_err(qmp->dev, "failed to enable regulators, err=%d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = clk_prepare_enable(qphy->pipe_clk);
|
||||
if (ret) {
|
||||
if (ret)
|
||||
dev_err(qmp->dev, "pipe_clk enable failed, err=%d\n", ret);
|
||||
regulator_bulk_disable(num, qmp->vregs);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int qcom_qmp_phy_poweroff(struct phy *phy)
|
||||
{
|
||||
struct qmp_phy *qphy = phy_get_drvdata(phy);
|
||||
struct qcom_qmp *qmp = qphy->qmp;
|
||||
|
||||
clk_disable_unprepare(qphy->pipe_clk);
|
||||
|
||||
regulator_bulk_disable(qmp->cfg->num_vregs, qmp->vregs);
|
||||
|
||||
return 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int qcom_qmp_phy_com_init(struct qcom_qmp *qmp)
|
||||
{
|
||||
const struct qmp_phy_cfg *cfg = qmp->cfg;
|
||||
void __iomem *serdes = qmp->serdes;
|
||||
void __iomem *dp_com = qmp->dp_com;
|
||||
int ret, i;
|
||||
|
||||
mutex_lock(&qmp->phy_mutex);
|
||||
@ -770,7 +819,23 @@ static int qcom_qmp_phy_com_init(struct qcom_qmp *qmp)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* turn on regulator supplies */
|
||||
ret = regulator_bulk_enable(cfg->num_vregs, qmp->vregs);
|
||||
if (ret) {
|
||||
dev_err(qmp->dev, "failed to enable regulators, err=%d\n", ret);
|
||||
goto err_reg_enable;
|
||||
}
|
||||
|
||||
for (i = 0; i < cfg->num_resets; i++) {
|
||||
ret = reset_control_assert(qmp->resets[i]);
|
||||
if (ret) {
|
||||
dev_err(qmp->dev, "%s reset assert failed\n",
|
||||
cfg->reset_list[i]);
|
||||
goto err_rst_assert;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = cfg->num_resets - 1; i >= 0; i--) {
|
||||
ret = reset_control_deassert(qmp->resets[i]);
|
||||
if (ret) {
|
||||
dev_err(qmp->dev, "%s reset deassert failed\n",
|
||||
@ -779,10 +844,33 @@ static int qcom_qmp_phy_com_init(struct qcom_qmp *qmp)
|
||||
}
|
||||
}
|
||||
|
||||
ret = clk_bulk_prepare_enable(cfg->num_clks, qmp->clks);
|
||||
if (ret) {
|
||||
dev_err(qmp->dev, "failed to enable clks, err=%d\n", ret);
|
||||
goto err_rst;
|
||||
}
|
||||
|
||||
if (cfg->has_phy_com_ctrl)
|
||||
qphy_setbits(serdes, cfg->regs[QPHY_COM_POWER_DOWN_CONTROL],
|
||||
SW_PWRDN);
|
||||
|
||||
if (cfg->has_phy_dp_com_ctrl) {
|
||||
qphy_setbits(dp_com, QPHY_V3_DP_COM_POWER_DOWN_CTRL,
|
||||
SW_PWRDN);
|
||||
/* override hardware control for reset of qmp phy */
|
||||
qphy_setbits(dp_com, QPHY_V3_DP_COM_RESET_OVRD_CTRL,
|
||||
SW_DPPHY_RESET_MUX | SW_DPPHY_RESET |
|
||||
SW_USB3PHY_RESET_MUX | SW_USB3PHY_RESET);
|
||||
|
||||
qphy_setbits(dp_com, QPHY_V3_DP_COM_PHY_MODE_CTRL,
|
||||
USB3_MODE | DP_MODE);
|
||||
|
||||
/* bring both QMP USB and QMP DP PHYs PCS block out of reset */
|
||||
qphy_clrbits(dp_com, QPHY_V3_DP_COM_RESET_OVRD_CTRL,
|
||||
SW_DPPHY_RESET_MUX | SW_DPPHY_RESET |
|
||||
SW_USB3PHY_RESET_MUX | SW_USB3PHY_RESET);
|
||||
}
|
||||
|
||||
/* Serdes configuration */
|
||||
qcom_qmp_phy_configure(serdes, cfg->regs, cfg->serdes_tbl,
|
||||
cfg->serdes_tbl_num);
|
||||
@ -803,7 +891,7 @@ static int qcom_qmp_phy_com_init(struct qcom_qmp *qmp)
|
||||
if (ret) {
|
||||
dev_err(qmp->dev,
|
||||
"phy common block init timed-out\n");
|
||||
goto err_rst;
|
||||
goto err_com_init;
|
||||
}
|
||||
}
|
||||
|
||||
@ -811,9 +899,14 @@ static int qcom_qmp_phy_com_init(struct qcom_qmp *qmp)
|
||||
|
||||
return 0;
|
||||
|
||||
err_com_init:
|
||||
clk_bulk_disable_unprepare(cfg->num_clks, qmp->clks);
|
||||
err_rst:
|
||||
while (--i >= 0)
|
||||
while (++i < cfg->num_resets)
|
||||
reset_control_assert(qmp->resets[i]);
|
||||
err_rst_assert:
|
||||
regulator_bulk_disable(cfg->num_vregs, qmp->vregs);
|
||||
err_reg_enable:
|
||||
mutex_unlock(&qmp->phy_mutex);
|
||||
|
||||
return ret;
|
||||
@ -843,6 +936,10 @@ static int qcom_qmp_phy_com_exit(struct qcom_qmp *qmp)
|
||||
while (--i >= 0)
|
||||
reset_control_assert(qmp->resets[i]);
|
||||
|
||||
clk_bulk_disable_unprepare(cfg->num_clks, qmp->clks);
|
||||
|
||||
regulator_bulk_disable(cfg->num_vregs, qmp->vregs);
|
||||
|
||||
mutex_unlock(&qmp->phy_mutex);
|
||||
|
||||
return 0;
|
||||
@ -857,24 +954,16 @@ static int qcom_qmp_phy_init(struct phy *phy)
|
||||
void __iomem *tx = qphy->tx;
|
||||
void __iomem *rx = qphy->rx;
|
||||
void __iomem *pcs = qphy->pcs;
|
||||
void __iomem *dp_com = qmp->dp_com;
|
||||
void __iomem *status;
|
||||
unsigned int mask, val;
|
||||
int ret, i;
|
||||
int ret;
|
||||
|
||||
dev_vdbg(qmp->dev, "Initializing QMP phy\n");
|
||||
|
||||
for (i = 0; i < qmp->cfg->num_clks; i++) {
|
||||
ret = clk_prepare_enable(qmp->clks[i]);
|
||||
if (ret) {
|
||||
dev_err(qmp->dev, "failed to enable %s clk, err=%d\n",
|
||||
qmp->cfg->clk_list[i], ret);
|
||||
goto err_clk;
|
||||
}
|
||||
}
|
||||
|
||||
ret = qcom_qmp_phy_com_init(qmp);
|
||||
if (ret)
|
||||
goto err_clk;
|
||||
return ret;
|
||||
|
||||
if (cfg->has_lane_rst) {
|
||||
ret = reset_control_deassert(qphy->lane_rst);
|
||||
@ -887,7 +976,16 @@ static int qcom_qmp_phy_init(struct phy *phy)
|
||||
|
||||
/* Tx, Rx, and PCS configurations */
|
||||
qcom_qmp_phy_configure(tx, cfg->regs, cfg->tx_tbl, cfg->tx_tbl_num);
|
||||
/* Configuration for other LANE for USB-DP combo PHY */
|
||||
if (cfg->has_phy_dp_com_ctrl)
|
||||
qcom_qmp_phy_configure(tx + cfg->tx_b_lane_offset, cfg->regs,
|
||||
cfg->tx_tbl, cfg->tx_tbl_num);
|
||||
|
||||
qcom_qmp_phy_configure(rx, cfg->regs, cfg->rx_tbl, cfg->rx_tbl_num);
|
||||
if (cfg->has_phy_dp_com_ctrl)
|
||||
qcom_qmp_phy_configure(rx + cfg->rx_b_lane_offset, cfg->regs,
|
||||
cfg->rx_tbl, cfg->rx_tbl_num);
|
||||
|
||||
qcom_qmp_phy_configure(pcs, cfg->regs, cfg->pcs_tbl, cfg->pcs_tbl_num);
|
||||
|
||||
/*
|
||||
@ -899,11 +997,13 @@ static int qcom_qmp_phy_init(struct phy *phy)
|
||||
if (cfg->has_pwrdn_delay)
|
||||
usleep_range(cfg->pwrdn_delay_min, cfg->pwrdn_delay_max);
|
||||
|
||||
/* start SerDes and Phy-Coding-Sublayer */
|
||||
qphy_setbits(pcs, cfg->regs[QPHY_START_CTRL], cfg->start_ctrl);
|
||||
|
||||
/* Pull PHY out of reset state */
|
||||
qphy_clrbits(pcs, cfg->regs[QPHY_SW_RESET], SW_RESET);
|
||||
if (cfg->has_phy_dp_com_ctrl)
|
||||
qphy_clrbits(dp_com, QPHY_V3_DP_COM_SW_RESET, SW_RESET);
|
||||
|
||||
/* start SerDes and Phy-Coding-Sublayer */
|
||||
qphy_setbits(pcs, cfg->regs[QPHY_START_CTRL], cfg->start_ctrl);
|
||||
|
||||
status = pcs + cfg->regs[QPHY_PCS_READY_STATUS];
|
||||
mask = cfg->mask_pcs_ready;
|
||||
@ -914,6 +1014,7 @@ static int qcom_qmp_phy_init(struct phy *phy)
|
||||
dev_err(qmp->dev, "phy initialization timed-out\n");
|
||||
goto err_pcs_ready;
|
||||
}
|
||||
qmp->phy_initialized = true;
|
||||
|
||||
return ret;
|
||||
|
||||
@ -922,9 +1023,6 @@ err_pcs_ready:
|
||||
reset_control_assert(qphy->lane_rst);
|
||||
err_lane_rst:
|
||||
qcom_qmp_phy_com_exit(qmp);
|
||||
err_clk:
|
||||
while (--i >= 0)
|
||||
clk_disable_unprepare(qmp->clks[i]);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@ -934,7 +1032,8 @@ static int qcom_qmp_phy_exit(struct phy *phy)
|
||||
struct qmp_phy *qphy = phy_get_drvdata(phy);
|
||||
struct qcom_qmp *qmp = qphy->qmp;
|
||||
const struct qmp_phy_cfg *cfg = qmp->cfg;
|
||||
int i = cfg->num_clks;
|
||||
|
||||
clk_disable_unprepare(qphy->pipe_clk);
|
||||
|
||||
/* PHY reset */
|
||||
qphy_setbits(qphy->pcs, cfg->regs[QPHY_SW_RESET], SW_RESET);
|
||||
@ -950,8 +1049,127 @@ static int qcom_qmp_phy_exit(struct phy *phy)
|
||||
|
||||
qcom_qmp_phy_com_exit(qmp);
|
||||
|
||||
while (--i >= 0)
|
||||
clk_disable_unprepare(qmp->clks[i]);
|
||||
qmp->phy_initialized = false;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int qcom_qmp_phy_set_mode(struct phy *phy, enum phy_mode mode)
|
||||
{
|
||||
struct qmp_phy *qphy = phy_get_drvdata(phy);
|
||||
struct qcom_qmp *qmp = qphy->qmp;
|
||||
|
||||
qmp->mode = mode;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void qcom_qmp_phy_enable_autonomous_mode(struct qmp_phy *qphy)
|
||||
{
|
||||
struct qcom_qmp *qmp = qphy->qmp;
|
||||
const struct qmp_phy_cfg *cfg = qmp->cfg;
|
||||
void __iomem *pcs = qphy->pcs;
|
||||
void __iomem *pcs_misc = qphy->pcs_misc;
|
||||
u32 intr_mask;
|
||||
|
||||
if (qmp->mode == PHY_MODE_USB_HOST_SS ||
|
||||
qmp->mode == PHY_MODE_USB_DEVICE_SS)
|
||||
intr_mask = ARCVR_DTCT_EN | ALFPS_DTCT_EN;
|
||||
else
|
||||
intr_mask = ARCVR_DTCT_EN | ARCVR_DTCT_EVENT_SEL;
|
||||
|
||||
/* Clear any pending interrupts status */
|
||||
qphy_setbits(pcs, cfg->regs[QPHY_PCS_LFPS_RXTERM_IRQ_CLEAR], IRQ_CLEAR);
|
||||
/* Writing 1 followed by 0 clears the interrupt */
|
||||
qphy_clrbits(pcs, cfg->regs[QPHY_PCS_LFPS_RXTERM_IRQ_CLEAR], IRQ_CLEAR);
|
||||
|
||||
qphy_clrbits(pcs, cfg->regs[QPHY_PCS_AUTONOMOUS_MODE_CTRL],
|
||||
ARCVR_DTCT_EN | ALFPS_DTCT_EN | ARCVR_DTCT_EVENT_SEL);
|
||||
|
||||
/* Enable required PHY autonomous mode interrupts */
|
||||
qphy_setbits(pcs, cfg->regs[QPHY_PCS_AUTONOMOUS_MODE_CTRL], intr_mask);
|
||||
|
||||
/* Enable i/o clamp_n for autonomous mode */
|
||||
if (pcs_misc)
|
||||
qphy_clrbits(pcs_misc, QPHY_V3_PCS_MISC_CLAMP_ENABLE, CLAMP_EN);
|
||||
}
|
||||
|
||||
static void qcom_qmp_phy_disable_autonomous_mode(struct qmp_phy *qphy)
|
||||
{
|
||||
struct qcom_qmp *qmp = qphy->qmp;
|
||||
const struct qmp_phy_cfg *cfg = qmp->cfg;
|
||||
void __iomem *pcs = qphy->pcs;
|
||||
void __iomem *pcs_misc = qphy->pcs_misc;
|
||||
|
||||
/* Disable i/o clamp_n on resume for normal mode */
|
||||
if (pcs_misc)
|
||||
qphy_setbits(pcs_misc, QPHY_V3_PCS_MISC_CLAMP_ENABLE, CLAMP_EN);
|
||||
|
||||
qphy_clrbits(pcs, cfg->regs[QPHY_PCS_AUTONOMOUS_MODE_CTRL],
|
||||
ARCVR_DTCT_EN | ARCVR_DTCT_EVENT_SEL | ALFPS_DTCT_EN);
|
||||
|
||||
qphy_setbits(pcs, cfg->regs[QPHY_PCS_LFPS_RXTERM_IRQ_CLEAR], IRQ_CLEAR);
|
||||
/* Writing 1 followed by 0 clears the interrupt */
|
||||
qphy_clrbits(pcs, cfg->regs[QPHY_PCS_LFPS_RXTERM_IRQ_CLEAR], IRQ_CLEAR);
|
||||
}
|
||||
|
||||
static int __maybe_unused qcom_qmp_phy_runtime_suspend(struct device *dev)
|
||||
{
|
||||
struct qcom_qmp *qmp = dev_get_drvdata(dev);
|
||||
struct qmp_phy *qphy = qmp->phys[0];
|
||||
const struct qmp_phy_cfg *cfg = qmp->cfg;
|
||||
|
||||
dev_vdbg(dev, "Suspending QMP phy, mode:%d\n", qmp->mode);
|
||||
|
||||
/* Supported only for USB3 PHY */
|
||||
if (cfg->type != PHY_TYPE_USB3)
|
||||
return 0;
|
||||
|
||||
if (!qmp->phy_initialized) {
|
||||
dev_vdbg(dev, "PHY not initialized, bailing out\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
qcom_qmp_phy_enable_autonomous_mode(qphy);
|
||||
|
||||
clk_disable_unprepare(qphy->pipe_clk);
|
||||
clk_bulk_disable_unprepare(cfg->num_clks, qmp->clks);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int __maybe_unused qcom_qmp_phy_runtime_resume(struct device *dev)
|
||||
{
|
||||
struct qcom_qmp *qmp = dev_get_drvdata(dev);
|
||||
struct qmp_phy *qphy = qmp->phys[0];
|
||||
const struct qmp_phy_cfg *cfg = qmp->cfg;
|
||||
int ret = 0;
|
||||
|
||||
dev_vdbg(dev, "Resuming QMP phy, mode:%d\n", qmp->mode);
|
||||
|
||||
/* Supported only for USB3 PHY */
|
||||
if (cfg->type != PHY_TYPE_USB3)
|
||||
return 0;
|
||||
|
||||
if (!qmp->phy_initialized) {
|
||||
dev_vdbg(dev, "PHY not initialized, bailing out\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
ret = clk_bulk_prepare_enable(cfg->num_clks, qmp->clks);
|
||||
if (ret) {
|
||||
dev_err(qmp->dev, "failed to enable clks, err=%d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = clk_prepare_enable(qphy->pipe_clk);
|
||||
if (ret) {
|
||||
dev_err(dev, "pipe_clk enable failed, err=%d\n", ret);
|
||||
clk_bulk_disable_unprepare(cfg->num_clks, qmp->clks);
|
||||
return ret;
|
||||
}
|
||||
|
||||
qcom_qmp_phy_disable_autonomous_mode(qphy);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -1000,29 +1218,17 @@ static int qcom_qmp_phy_reset_init(struct device *dev)
|
||||
static int qcom_qmp_phy_clk_init(struct device *dev)
|
||||
{
|
||||
struct qcom_qmp *qmp = dev_get_drvdata(dev);
|
||||
int ret, i;
|
||||
int num = qmp->cfg->num_clks;
|
||||
int i;
|
||||
|
||||
qmp->clks = devm_kcalloc(dev, qmp->cfg->num_clks,
|
||||
sizeof(*qmp->clks), GFP_KERNEL);
|
||||
qmp->clks = devm_kcalloc(dev, num, sizeof(*qmp->clks), GFP_KERNEL);
|
||||
if (!qmp->clks)
|
||||
return -ENOMEM;
|
||||
|
||||
for (i = 0; i < qmp->cfg->num_clks; i++) {
|
||||
struct clk *_clk;
|
||||
const char *name = qmp->cfg->clk_list[i];
|
||||
for (i = 0; i < num; i++)
|
||||
qmp->clks[i].id = qmp->cfg->clk_list[i];
|
||||
|
||||
_clk = devm_clk_get(dev, name);
|
||||
if (IS_ERR(_clk)) {
|
||||
ret = PTR_ERR(_clk);
|
||||
if (ret != -EPROBE_DEFER)
|
||||
dev_err(dev, "failed to get %s clk, %d\n",
|
||||
name, ret);
|
||||
return ret;
|
||||
}
|
||||
qmp->clks[i] = _clk;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return devm_clk_bulk_get(dev, num, qmp->clks);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -1078,7 +1284,7 @@ static const struct phy_ops qcom_qmp_phy_gen_ops = {
|
||||
.init = qcom_qmp_phy_init,
|
||||
.exit = qcom_qmp_phy_exit,
|
||||
.power_on = qcom_qmp_phy_poweron,
|
||||
.power_off = qcom_qmp_phy_poweroff,
|
||||
.set_mode = qcom_qmp_phy_set_mode,
|
||||
.owner = THIS_MODULE,
|
||||
};
|
||||
|
||||
@ -1097,7 +1303,8 @@ int qcom_qmp_phy_create(struct device *dev, struct device_node *np, int id)
|
||||
|
||||
/*
|
||||
* Get memory resources for each phy lane:
|
||||
* Resources are indexed as: tx -> 0; rx -> 1; pcs -> 2.
|
||||
* Resources are indexed as: tx -> 0; rx -> 1; pcs -> 2; and
|
||||
* pcs_misc (optional) -> 3.
|
||||
*/
|
||||
qphy->tx = of_iomap(np, 0);
|
||||
if (!qphy->tx)
|
||||
@ -1111,6 +1318,10 @@ int qcom_qmp_phy_create(struct device *dev, struct device_node *np, int id)
|
||||
if (!qphy->pcs)
|
||||
return -ENOMEM;
|
||||
|
||||
qphy->pcs_misc = of_iomap(np, 3);
|
||||
if (!qphy->pcs_misc)
|
||||
dev_vdbg(dev, "PHY pcs_misc-reg not used\n");
|
||||
|
||||
/*
|
||||
* Get PHY's Pipe clock, if any. USB3 and PCIe are PIPE3
|
||||
* based phys, so they essentially have pipe clock. So,
|
||||
@ -1169,11 +1380,19 @@ static const struct of_device_id qcom_qmp_phy_of_match_table[] = {
|
||||
}, {
|
||||
.compatible = "qcom,ipq8074-qmp-pcie-phy",
|
||||
.data = &ipq8074_pciephy_cfg,
|
||||
}, {
|
||||
.compatible = "qcom,qmp-v3-usb3-phy",
|
||||
.data = &qmp_v3_usb3phy_cfg,
|
||||
},
|
||||
{ },
|
||||
};
|
||||
MODULE_DEVICE_TABLE(of, qcom_qmp_phy_of_match_table);
|
||||
|
||||
static const struct dev_pm_ops qcom_qmp_phy_pm_ops = {
|
||||
SET_RUNTIME_PM_OPS(qcom_qmp_phy_runtime_suspend,
|
||||
qcom_qmp_phy_runtime_resume, NULL)
|
||||
};
|
||||
|
||||
static int qcom_qmp_phy_probe(struct platform_device *pdev)
|
||||
{
|
||||
struct qcom_qmp *qmp;
|
||||
@ -1192,6 +1411,11 @@ static int qcom_qmp_phy_probe(struct platform_device *pdev)
|
||||
qmp->dev = dev;
|
||||
dev_set_drvdata(dev, qmp);
|
||||
|
||||
/* Get the specific init parameters of QMP phy */
|
||||
qmp->cfg = of_device_get_match_data(dev);
|
||||
if (!qmp->cfg)
|
||||
return -EINVAL;
|
||||
|
||||
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
||||
base = devm_ioremap_resource(dev, res);
|
||||
if (IS_ERR(base))
|
||||
@ -1200,10 +1424,18 @@ static int qcom_qmp_phy_probe(struct platform_device *pdev)
|
||||
/* per PHY serdes; usually located at base address */
|
||||
qmp->serdes = base;
|
||||
|
||||
mutex_init(&qmp->phy_mutex);
|
||||
/* per PHY dp_com; if PHY has dp_com control block */
|
||||
if (qmp->cfg->has_phy_dp_com_ctrl) {
|
||||
res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
|
||||
"dp_com");
|
||||
base = devm_ioremap_resource(dev, res);
|
||||
if (IS_ERR(base))
|
||||
return PTR_ERR(base);
|
||||
|
||||
/* Get the specific init parameters of QMP phy */
|
||||
qmp->cfg = of_device_get_match_data(dev);
|
||||
qmp->dp_com = base;
|
||||
}
|
||||
|
||||
mutex_init(&qmp->phy_mutex);
|
||||
|
||||
ret = qcom_qmp_phy_clk_init(dev);
|
||||
if (ret)
|
||||
@ -1229,12 +1461,21 @@ static int qcom_qmp_phy_probe(struct platform_device *pdev)
|
||||
return -ENOMEM;
|
||||
|
||||
id = 0;
|
||||
pm_runtime_set_active(dev);
|
||||
pm_runtime_enable(dev);
|
||||
/*
|
||||
* Prevent runtime pm from being ON by default. Users can enable
|
||||
* it using power/control in sysfs.
|
||||
*/
|
||||
pm_runtime_forbid(dev);
|
||||
|
||||
for_each_available_child_of_node(dev->of_node, child) {
|
||||
/* Create per-lane phy */
|
||||
ret = qcom_qmp_phy_create(dev, child, id);
|
||||
if (ret) {
|
||||
dev_err(dev, "failed to create lane%d phy, %d\n",
|
||||
id, ret);
|
||||
pm_runtime_disable(dev);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -1246,6 +1487,7 @@ static int qcom_qmp_phy_probe(struct platform_device *pdev)
|
||||
if (ret) {
|
||||
dev_err(qmp->dev,
|
||||
"failed to register pipe clock source\n");
|
||||
pm_runtime_disable(dev);
|
||||
return ret;
|
||||
}
|
||||
id++;
|
||||
@ -1254,6 +1496,8 @@ static int qcom_qmp_phy_probe(struct platform_device *pdev)
|
||||
phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
|
||||
if (!IS_ERR(phy_provider))
|
||||
dev_info(dev, "Registered Qcom-QMP phy\n");
|
||||
else
|
||||
pm_runtime_disable(dev);
|
||||
|
||||
return PTR_ERR_OR_ZERO(phy_provider);
|
||||
}
|
||||
@ -1262,6 +1506,7 @@ static struct platform_driver qcom_qmp_phy_driver = {
|
||||
.probe = qcom_qmp_phy_probe,
|
||||
.driver = {
|
||||
.name = "qcom-qmp-phy",
|
||||
.pm = &qcom_qmp_phy_pm_ops,
|
||||
.of_match_table = qcom_qmp_phy_of_match_table,
|
||||
},
|
||||
};
|
||||
|
280
drivers/phy/qualcomm/phy-qcom-qmp.h
Normal file
280
drivers/phy/qualcomm/phy-qcom-qmp.h
Normal file
@ -0,0 +1,280 @@
|
||||
// SPDX-License-Identifier: GPL-2.0
|
||||
/*
|
||||
* Copyright (c) 2017, The Linux Foundation. All rights reserved.
|
||||
*/
|
||||
|
||||
#ifndef QCOM_PHY_QMP_H_
|
||||
#define QCOM_PHY_QMP_H_
|
||||
|
||||
/* Only for QMP V2 PHY - QSERDES COM registers */
|
||||
#define QSERDES_COM_BG_TIMER 0x00c
|
||||
#define QSERDES_COM_SSC_EN_CENTER 0x010
|
||||
#define QSERDES_COM_SSC_ADJ_PER1 0x014
|
||||
#define QSERDES_COM_SSC_ADJ_PER2 0x018
|
||||
#define QSERDES_COM_SSC_PER1 0x01c
|
||||
#define QSERDES_COM_SSC_PER2 0x020
|
||||
#define QSERDES_COM_SSC_STEP_SIZE1 0x024
|
||||
#define QSERDES_COM_SSC_STEP_SIZE2 0x028
|
||||
#define QSERDES_COM_BIAS_EN_CLKBUFLR_EN 0x034
|
||||
#define QSERDES_COM_CLK_ENABLE1 0x038
|
||||
#define QSERDES_COM_SYS_CLK_CTRL 0x03c
|
||||
#define QSERDES_COM_SYSCLK_BUF_ENABLE 0x040
|
||||
#define QSERDES_COM_PLL_IVCO 0x048
|
||||
#define QSERDES_COM_LOCK_CMP1_MODE0 0x04c
|
||||
#define QSERDES_COM_LOCK_CMP2_MODE0 0x050
|
||||
#define QSERDES_COM_LOCK_CMP3_MODE0 0x054
|
||||
#define QSERDES_COM_LOCK_CMP1_MODE1 0x058
|
||||
#define QSERDES_COM_LOCK_CMP2_MODE1 0x05c
|
||||
#define QSERDES_COM_LOCK_CMP3_MODE1 0x060
|
||||
#define QSERDES_COM_BG_TRIM 0x070
|
||||
#define QSERDES_COM_CLK_EP_DIV 0x074
|
||||
#define QSERDES_COM_CP_CTRL_MODE0 0x078
|
||||
#define QSERDES_COM_CP_CTRL_MODE1 0x07c
|
||||
#define QSERDES_COM_PLL_RCTRL_MODE0 0x084
|
||||
#define QSERDES_COM_PLL_RCTRL_MODE1 0x088
|
||||
#define QSERDES_COM_PLL_CCTRL_MODE0 0x090
|
||||
#define QSERDES_COM_PLL_CCTRL_MODE1 0x094
|
||||
#define QSERDES_COM_BIAS_EN_CTRL_BY_PSM 0x0a8
|
||||
#define QSERDES_COM_SYSCLK_EN_SEL 0x0ac
|
||||
#define QSERDES_COM_RESETSM_CNTRL 0x0b4
|
||||
#define QSERDES_COM_RESTRIM_CTRL 0x0bc
|
||||
#define QSERDES_COM_RESCODE_DIV_NUM 0x0c4
|
||||
#define QSERDES_COM_LOCK_CMP_EN 0x0c8
|
||||
#define QSERDES_COM_LOCK_CMP_CFG 0x0cc
|
||||
#define QSERDES_COM_DEC_START_MODE0 0x0d0
|
||||
#define QSERDES_COM_DEC_START_MODE1 0x0d4
|
||||
#define QSERDES_COM_DIV_FRAC_START1_MODE0 0x0dc
|
||||
#define QSERDES_COM_DIV_FRAC_START2_MODE0 0x0e0
|
||||
#define QSERDES_COM_DIV_FRAC_START3_MODE0 0x0e4
|
||||
#define QSERDES_COM_DIV_FRAC_START1_MODE1 0x0e8
|
||||
#define QSERDES_COM_DIV_FRAC_START2_MODE1 0x0ec
|
||||
#define QSERDES_COM_DIV_FRAC_START3_MODE1 0x0f0
|
||||
#define QSERDES_COM_INTEGLOOP_GAIN0_MODE0 0x108
|
||||
#define QSERDES_COM_INTEGLOOP_GAIN1_MODE0 0x10c
|
||||
#define QSERDES_COM_INTEGLOOP_GAIN0_MODE1 0x110
|
||||
#define QSERDES_COM_INTEGLOOP_GAIN1_MODE1 0x114
|
||||
#define QSERDES_COM_VCO_TUNE_CTRL 0x124
|
||||
#define QSERDES_COM_VCO_TUNE_MAP 0x128
|
||||
#define QSERDES_COM_VCO_TUNE1_MODE0 0x12c
|
||||
#define QSERDES_COM_VCO_TUNE2_MODE0 0x130
|
||||
#define QSERDES_COM_VCO_TUNE1_MODE1 0x134
|
||||
#define QSERDES_COM_VCO_TUNE2_MODE1 0x138
|
||||
#define QSERDES_COM_VCO_TUNE_TIMER1 0x144
|
||||
#define QSERDES_COM_VCO_TUNE_TIMER2 0x148
|
||||
#define QSERDES_COM_BG_CTRL 0x170
|
||||
#define QSERDES_COM_CLK_SELECT 0x174
|
||||
#define QSERDES_COM_HSCLK_SEL 0x178
|
||||
#define QSERDES_COM_CORECLK_DIV 0x184
|
||||
#define QSERDES_COM_CORE_CLK_EN 0x18c
|
||||
#define QSERDES_COM_C_READY_STATUS 0x190
|
||||
#define QSERDES_COM_CMN_CONFIG 0x194
|
||||
#define QSERDES_COM_SVS_MODE_CLK_SEL 0x19c
|
||||
#define QSERDES_COM_DEBUG_BUS0 0x1a0
|
||||
#define QSERDES_COM_DEBUG_BUS1 0x1a4
|
||||
#define QSERDES_COM_DEBUG_BUS2 0x1a8
|
||||
#define QSERDES_COM_DEBUG_BUS3 0x1ac
|
||||
#define QSERDES_COM_DEBUG_BUS_SEL 0x1b0
|
||||
#define QSERDES_COM_CORECLK_DIV_MODE1 0x1bc
|
||||
|
||||
/* Only for QMP V2 PHY - TX registers */
|
||||
#define QSERDES_TX_RES_CODE_LANE_OFFSET 0x054
|
||||
#define QSERDES_TX_DEBUG_BUS_SEL 0x064
|
||||
#define QSERDES_TX_HIGHZ_TRANSCEIVEREN_BIAS_DRVR_EN 0x068
|
||||
#define QSERDES_TX_LANE_MODE 0x094
|
||||
#define QSERDES_TX_RCV_DETECT_LVL_2 0x0ac
|
||||
|
||||
/* Only for QMP V2 PHY - RX registers */
|
||||
#define QSERDES_RX_UCDR_SO_GAIN_HALF 0x010
|
||||
#define QSERDES_RX_UCDR_SO_GAIN 0x01c
|
||||
#define QSERDES_RX_UCDR_FASTLOCK_FO_GAIN 0x040
|
||||
#define QSERDES_RX_UCDR_SO_SATURATION_AND_ENABLE 0x048
|
||||
#define QSERDES_RX_RX_TERM_BW 0x090
|
||||
#define QSERDES_RX_RX_EQ_GAIN1_LSB 0x0c4
|
||||
#define QSERDES_RX_RX_EQ_GAIN1_MSB 0x0c8
|
||||
#define QSERDES_RX_RX_EQ_GAIN2_LSB 0x0cc
|
||||
#define QSERDES_RX_RX_EQ_GAIN2_MSB 0x0d0
|
||||
#define QSERDES_RX_RX_EQU_ADAPTOR_CNTRL2 0x0d8
|
||||
#define QSERDES_RX_RX_EQU_ADAPTOR_CNTRL3 0x0dc
|
||||
#define QSERDES_RX_RX_EQU_ADAPTOR_CNTRL4 0x0e0
|
||||
#define QSERDES_RX_RX_EQ_OFFSET_ADAPTOR_CNTRL1 0x108
|
||||
#define QSERDES_RX_RX_OFFSET_ADAPTOR_CNTRL2 0x10c
|
||||
#define QSERDES_RX_SIGDET_ENABLES 0x110
|
||||
#define QSERDES_RX_SIGDET_CNTRL 0x114
|
||||
#define QSERDES_RX_SIGDET_LVL 0x118
|
||||
#define QSERDES_RX_SIGDET_DEGLITCH_CNTRL 0x11c
|
||||
#define QSERDES_RX_RX_BAND 0x120
|
||||
#define QSERDES_RX_RX_INTERFACE_MODE 0x12c
|
||||
|
||||
/* Only for QMP V2 PHY - PCS registers */
|
||||
#define QPHY_POWER_DOWN_CONTROL 0x04
|
||||
#define QPHY_TXDEEMPH_M6DB_V0 0x24
|
||||
#define QPHY_TXDEEMPH_M3P5DB_V0 0x28
|
||||
#define QPHY_ENDPOINT_REFCLK_DRIVE 0x54
|
||||
#define QPHY_RX_IDLE_DTCT_CNTRL 0x58
|
||||
#define QPHY_POWER_STATE_CONFIG1 0x60
|
||||
#define QPHY_POWER_STATE_CONFIG2 0x64
|
||||
#define QPHY_POWER_STATE_CONFIG4 0x6c
|
||||
#define QPHY_LOCK_DETECT_CONFIG1 0x80
|
||||
#define QPHY_LOCK_DETECT_CONFIG2 0x84
|
||||
#define QPHY_LOCK_DETECT_CONFIG3 0x88
|
||||
#define QPHY_PWRUP_RESET_DLY_TIME_AUXCLK 0xa0
|
||||
#define QPHY_LP_WAKEUP_DLY_TIME_AUXCLK 0xa4
|
||||
#define QPHY_PLL_LOCK_CHK_DLY_TIME_AUXCLK_LSB 0x1A8
|
||||
#define QPHY_OSC_DTCT_ACTIONS 0x1AC
|
||||
#define QPHY_RX_SIGDET_LVL 0x1D8
|
||||
#define QPHY_L1SS_WAKEUP_DLY_TIME_AUXCLK_LSB 0x1DC
|
||||
#define QPHY_L1SS_WAKEUP_DLY_TIME_AUXCLK_MSB 0x1E0
|
||||
|
||||
/* Only for QMP V3 PHY - DP COM registers */
|
||||
#define QPHY_V3_DP_COM_PHY_MODE_CTRL 0x00
|
||||
#define QPHY_V3_DP_COM_SW_RESET 0x04
|
||||
#define QPHY_V3_DP_COM_POWER_DOWN_CTRL 0x08
|
||||
#define QPHY_V3_DP_COM_SWI_CTRL 0x0c
|
||||
#define QPHY_V3_DP_COM_TYPEC_CTRL 0x10
|
||||
#define QPHY_V3_DP_COM_TYPEC_PWRDN_CTRL 0x14
|
||||
#define QPHY_V3_DP_COM_RESET_OVRD_CTRL 0x1c
|
||||
|
||||
/* Only for QMP V3 PHY - QSERDES COM registers */
|
||||
#define QSERDES_V3_COM_BG_TIMER 0x00c
|
||||
#define QSERDES_V3_COM_SSC_EN_CENTER 0x010
|
||||
#define QSERDES_V3_COM_SSC_ADJ_PER1 0x014
|
||||
#define QSERDES_V3_COM_SSC_ADJ_PER2 0x018
|
||||
#define QSERDES_V3_COM_SSC_PER1 0x01c
|
||||
#define QSERDES_V3_COM_SSC_PER2 0x020
|
||||
#define QSERDES_V3_COM_SSC_STEP_SIZE1 0x024
|
||||
#define QSERDES_V3_COM_SSC_STEP_SIZE2 0x028
|
||||
#define QSERDES_V3_COM_BIAS_EN_CLKBUFLR_EN 0x034
|
||||
#define QSERDES_V3_COM_CLK_ENABLE1 0x038
|
||||
#define QSERDES_V3_COM_SYS_CLK_CTRL 0x03c
|
||||
#define QSERDES_V3_COM_SYSCLK_BUF_ENABLE 0x040
|
||||
#define QSERDES_V3_COM_PLL_IVCO 0x048
|
||||
#define QSERDES_V3_COM_LOCK_CMP1_MODE0 0x098
|
||||
#define QSERDES_V3_COM_LOCK_CMP2_MODE0 0x09c
|
||||
#define QSERDES_V3_COM_LOCK_CMP3_MODE0 0x0a0
|
||||
#define QSERDES_V3_COM_LOCK_CMP1_MODE1 0x0a4
|
||||
#define QSERDES_V3_COM_LOCK_CMP2_MODE1 0x0a8
|
||||
#define QSERDES_V3_COM_LOCK_CMP3_MODE1 0x0ac
|
||||
#define QSERDES_V3_COM_CLK_EP_DIV 0x05c
|
||||
#define QSERDES_V3_COM_CP_CTRL_MODE0 0x060
|
||||
#define QSERDES_V3_COM_CP_CTRL_MODE1 0x064
|
||||
#define QSERDES_V3_COM_PLL_RCTRL_MODE0 0x068
|
||||
#define QSERDES_V3_COM_PLL_RCTRL_MODE1 0x06c
|
||||
#define QSERDES_V3_COM_PLL_CCTRL_MODE0 0x070
|
||||
#define QSERDES_V3_COM_PLL_CCTRL_MODE1 0x074
|
||||
#define QSERDES_V3_COM_SYSCLK_EN_SEL 0x080
|
||||
#define QSERDES_V3_COM_RESETSM_CNTRL 0x088
|
||||
#define QSERDES_V3_COM_RESETSM_CNTRL2 0x08c
|
||||
#define QSERDES_V3_COM_LOCK_CMP_EN 0x090
|
||||
#define QSERDES_V3_COM_LOCK_CMP_CFG 0x094
|
||||
#define QSERDES_V3_COM_DEC_START_MODE0 0x0b0
|
||||
#define QSERDES_V3_COM_DEC_START_MODE1 0x0b4
|
||||
#define QSERDES_V3_COM_DIV_FRAC_START1_MODE0 0x0b8
|
||||
#define QSERDES_V3_COM_DIV_FRAC_START2_MODE0 0x0bc
|
||||
#define QSERDES_V3_COM_DIV_FRAC_START3_MODE0 0x0c0
|
||||
#define QSERDES_V3_COM_DIV_FRAC_START1_MODE1 0x0c4
|
||||
#define QSERDES_V3_COM_DIV_FRAC_START2_MODE1 0x0c8
|
||||
#define QSERDES_V3_COM_DIV_FRAC_START3_MODE1 0x0cc
|
||||
#define QSERDES_V3_COM_INTEGLOOP_GAIN0_MODE0 0x0d8
|
||||
#define QSERDES_V3_COM_INTEGLOOP_GAIN1_MODE0 0x0dc
|
||||
#define QSERDES_V3_COM_INTEGLOOP_GAIN0_MODE1 0x0e0
|
||||
#define QSERDES_V3_COM_INTEGLOOP_GAIN1_MODE1 0x0e4
|
||||
#define QSERDES_V3_COM_VCO_TUNE_CTRL 0x0ec
|
||||
#define QSERDES_V3_COM_VCO_TUNE_MAP 0x0f0
|
||||
#define QSERDES_V3_COM_VCO_TUNE1_MODE0 0x0f4
|
||||
#define QSERDES_V3_COM_VCO_TUNE2_MODE0 0x0f8
|
||||
#define QSERDES_V3_COM_VCO_TUNE1_MODE1 0x0fc
|
||||
#define QSERDES_V3_COM_VCO_TUNE2_MODE1 0x100
|
||||
#define QSERDES_V3_COM_VCO_TUNE_TIMER1 0x11c
|
||||
#define QSERDES_V3_COM_VCO_TUNE_TIMER2 0x120
|
||||
#define QSERDES_V3_COM_CLK_SELECT 0x138
|
||||
#define QSERDES_V3_COM_HSCLK_SEL 0x13c
|
||||
#define QSERDES_V3_COM_CORECLK_DIV_MODE0 0x148
|
||||
#define QSERDES_V3_COM_CORECLK_DIV_MODE1 0x14c
|
||||
#define QSERDES_V3_COM_CORE_CLK_EN 0x154
|
||||
#define QSERDES_V3_COM_C_READY_STATUS 0x158
|
||||
#define QSERDES_V3_COM_CMN_CONFIG 0x15c
|
||||
#define QSERDES_V3_COM_SVS_MODE_CLK_SEL 0x164
|
||||
#define QSERDES_V3_COM_DEBUG_BUS0 0x168
|
||||
#define QSERDES_V3_COM_DEBUG_BUS1 0x16c
|
||||
#define QSERDES_V3_COM_DEBUG_BUS2 0x170
|
||||
#define QSERDES_V3_COM_DEBUG_BUS3 0x174
|
||||
#define QSERDES_V3_COM_DEBUG_BUS_SEL 0x178
|
||||
|
||||
/* Only for QMP V3 PHY - TX registers */
|
||||
#define QSERDES_V3_TX_RES_CODE_LANE_OFFSET_TX 0x044
|
||||
#define QSERDES_V3_TX_RES_CODE_LANE_OFFSET_RX 0x048
|
||||
#define QSERDES_V3_TX_DEBUG_BUS_SEL 0x058
|
||||
#define QSERDES_V3_TX_HIGHZ_DRVR_EN 0x060
|
||||
#define QSERDES_V3_TX_LANE_MODE_1 0x08c
|
||||
#define QSERDES_V3_TX_RCV_DETECT_LVL_2 0x0a4
|
||||
|
||||
/* Only for QMP V3 PHY - RX registers */
|
||||
#define QSERDES_V3_RX_UCDR_SO_GAIN_HALF 0x00c
|
||||
#define QSERDES_V3_RX_UCDR_SO_GAIN 0x014
|
||||
#define QSERDES_V3_RX_UCDR_FASTLOCK_FO_GAIN 0x030
|
||||
#define QSERDES_V3_RX_UCDR_SO_SATURATION_AND_ENABLE 0x034
|
||||
#define QSERDES_V3_RX_RX_TERM_BW 0x07c
|
||||
#define QSERDES_V3_RX_RX_EQ_GAIN2_LSB 0x0c8
|
||||
#define QSERDES_V3_RX_RX_EQ_GAIN2_MSB 0x0cc
|
||||
#define QSERDES_V3_RX_RX_EQU_ADAPTOR_CNTRL2 0x0d4
|
||||
#define QSERDES_V3_RX_RX_EQU_ADAPTOR_CNTRL3 0x0d8
|
||||
#define QSERDES_V3_RX_RX_EQU_ADAPTOR_CNTRL4 0x0dc
|
||||
#define QSERDES_V3_RX_RX_EQ_OFFSET_ADAPTOR_CNTRL1 0x0f8
|
||||
#define QSERDES_V3_RX_RX_OFFSET_ADAPTOR_CNTRL2 0x0fc
|
||||
#define QSERDES_V3_RX_SIGDET_ENABLES 0x100
|
||||
#define QSERDES_V3_RX_SIGDET_CNTRL 0x104
|
||||
#define QSERDES_V3_RX_SIGDET_LVL 0x108
|
||||
#define QSERDES_V3_RX_SIGDET_DEGLITCH_CNTRL 0x10c
|
||||
#define QSERDES_V3_RX_RX_BAND 0x110
|
||||
#define QSERDES_V3_RX_RX_INTERFACE_MODE 0x11c
|
||||
|
||||
/* Only for QMP V3 PHY - PCS registers */
|
||||
#define QPHY_V3_PCS_POWER_DOWN_CONTROL 0x004
|
||||
#define QPHY_V3_PCS_TXMGN_V0 0x00c
|
||||
#define QPHY_V3_PCS_TXMGN_V1 0x010
|
||||
#define QPHY_V3_PCS_TXMGN_V2 0x014
|
||||
#define QPHY_V3_PCS_TXMGN_V3 0x018
|
||||
#define QPHY_V3_PCS_TXMGN_V4 0x01c
|
||||
#define QPHY_V3_PCS_TXMGN_LS 0x020
|
||||
#define QPHY_V3_PCS_TXDEEMPH_M6DB_V0 0x024
|
||||
#define QPHY_V3_PCS_TXDEEMPH_M3P5DB_V0 0x028
|
||||
#define QPHY_V3_PCS_TXDEEMPH_M6DB_V1 0x02c
|
||||
#define QPHY_V3_PCS_TXDEEMPH_M3P5DB_V1 0x030
|
||||
#define QPHY_V3_PCS_TXDEEMPH_M6DB_V2 0x034
|
||||
#define QPHY_V3_PCS_TXDEEMPH_M3P5DB_V2 0x038
|
||||
#define QPHY_V3_PCS_TXDEEMPH_M6DB_V3 0x03c
|
||||
#define QPHY_V3_PCS_TXDEEMPH_M3P5DB_V3 0x040
|
||||
#define QPHY_V3_PCS_TXDEEMPH_M6DB_V4 0x044
|
||||
#define QPHY_V3_PCS_TXDEEMPH_M3P5DB_V4 0x048
|
||||
#define QPHY_V3_PCS_TXDEEMPH_M6DB_LS 0x04c
|
||||
#define QPHY_V3_PCS_TXDEEMPH_M3P5DB_LS 0x050
|
||||
#define QPHY_V3_PCS_ENDPOINT_REFCLK_DRIVE 0x054
|
||||
#define QPHY_V3_PCS_RX_IDLE_DTCT_CNTRL 0x058
|
||||
#define QPHY_V3_PCS_RATE_SLEW_CNTRL 0x05c
|
||||
#define QPHY_V3_PCS_POWER_STATE_CONFIG1 0x060
|
||||
#define QPHY_V3_PCS_POWER_STATE_CONFIG2 0x064
|
||||
#define QPHY_V3_PCS_POWER_STATE_CONFIG4 0x06c
|
||||
#define QPHY_V3_PCS_RCVR_DTCT_DLY_P1U2_L 0x070
|
||||
#define QPHY_V3_PCS_RCVR_DTCT_DLY_P1U2_H 0x074
|
||||
#define QPHY_V3_PCS_RCVR_DTCT_DLY_U3_L 0x078
|
||||
#define QPHY_V3_PCS_RCVR_DTCT_DLY_U3_H 0x07c
|
||||
#define QPHY_V3_PCS_LOCK_DETECT_CONFIG1 0x080
|
||||
#define QPHY_V3_PCS_LOCK_DETECT_CONFIG2 0x084
|
||||
#define QPHY_V3_PCS_LOCK_DETECT_CONFIG3 0x088
|
||||
#define QPHY_V3_PCS_TSYNC_RSYNC_TIME 0x08c
|
||||
#define QPHY_V3_PCS_PWRUP_RESET_DLY_TIME_AUXCLK 0x0a0
|
||||
#define QPHY_V3_PCS_LP_WAKEUP_DLY_TIME_AUXCLK 0x0a4
|
||||
#define QPHY_V3_PCS_LFPS_TX_ECSTART_EQTLOCK 0x0b0
|
||||
#define QPHY_V3_PCS_RXEQTRAINING_WAIT_TIME 0x0b8
|
||||
#define QPHY_V3_PCS_RXEQTRAINING_RUN_TIME 0x0bc
|
||||
#define QPHY_V3_PCS_FLL_CNTRL1 0x0c4
|
||||
#define QPHY_V3_PCS_FLL_CNTRL2 0x0c8
|
||||
#define QPHY_V3_PCS_FLL_CNT_VAL_L 0x0cc
|
||||
#define QPHY_V3_PCS_FLL_CNT_VAL_H_TOL 0x0d0
|
||||
#define QPHY_V3_PCS_FLL_MAN_CODE 0x0d4
|
||||
#define QPHY_V3_PCS_RX_SIGDET_LVL 0x1d8
|
||||
|
||||
/* Only for QMP V3 PHY - PCS_MISC registers */
|
||||
#define QPHY_V3_PCS_MISC_CLAMP_ENABLE 0x0c
|
||||
|
||||
#endif
|
@ -1,14 +1,6 @@
|
||||
// SPDX-License-Identifier: GPL-2.0
|
||||
/*
|
||||
* Copyright (c) 2017, The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 and
|
||||
* only 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/clk.h>
|
||||
@ -37,28 +29,57 @@
|
||||
#define QUSB2PHY_PLL_AUTOPGM_CTL1 0x1c
|
||||
#define QUSB2PHY_PLL_PWR_CTRL 0x18
|
||||
|
||||
#define QUSB2PHY_PLL_STATUS 0x38
|
||||
/* QUSB2PHY_PLL_STATUS register bits */
|
||||
#define PLL_LOCKED BIT(5)
|
||||
|
||||
#define QUSB2PHY_PORT_TUNE1 0x80
|
||||
#define QUSB2PHY_PORT_TUNE2 0x84
|
||||
#define QUSB2PHY_PORT_TUNE3 0x88
|
||||
#define QUSB2PHY_PORT_TUNE4 0x8c
|
||||
#define QUSB2PHY_PORT_TUNE5 0x90
|
||||
#define QUSB2PHY_PORT_TEST2 0x9c
|
||||
/* QUSB2PHY_PLL_COMMON_STATUS_ONE register bits */
|
||||
#define CORE_READY_STATUS BIT(0)
|
||||
|
||||
#define QUSB2PHY_PORT_POWERDOWN 0xb4
|
||||
/* QUSB2PHY_PORT_POWERDOWN register bits */
|
||||
#define CLAMP_N_EN BIT(5)
|
||||
#define FREEZIO_N BIT(1)
|
||||
#define POWER_DOWN BIT(0)
|
||||
|
||||
/* QUSB2PHY_PWR_CTRL1 register bits */
|
||||
#define PWR_CTRL1_VREF_SUPPLY_TRIM BIT(5)
|
||||
#define PWR_CTRL1_CLAMP_N_EN BIT(1)
|
||||
|
||||
#define QUSB2PHY_REFCLK_ENABLE BIT(0)
|
||||
|
||||
#define PHY_CLK_SCHEME_SEL BIT(0)
|
||||
|
||||
/* QUSB2PHY_INTR_CTRL register bits */
|
||||
#define DMSE_INTR_HIGH_SEL BIT(4)
|
||||
#define DPSE_INTR_HIGH_SEL BIT(3)
|
||||
#define CHG_DET_INTR_EN BIT(2)
|
||||
#define DMSE_INTR_EN BIT(1)
|
||||
#define DPSE_INTR_EN BIT(0)
|
||||
|
||||
/* QUSB2PHY_PLL_CORE_INPUT_OVERRIDE register bits */
|
||||
#define CORE_PLL_EN_FROM_RESET BIT(4)
|
||||
#define CORE_RESET BIT(5)
|
||||
#define CORE_RESET_MUX BIT(6)
|
||||
|
||||
#define QUSB2PHY_PLL_ANALOG_CONTROLS_TWO 0x04
|
||||
#define QUSB2PHY_PLL_CLOCK_INVERTERS 0x18c
|
||||
#define QUSB2PHY_PLL_CMODE 0x2c
|
||||
#define QUSB2PHY_PLL_LOCK_DELAY 0x184
|
||||
#define QUSB2PHY_PLL_DIGITAL_TIMERS_TWO 0xb4
|
||||
#define QUSB2PHY_PLL_BIAS_CONTROL_1 0x194
|
||||
#define QUSB2PHY_PLL_BIAS_CONTROL_2 0x198
|
||||
#define QUSB2PHY_PWR_CTRL2 0x214
|
||||
#define QUSB2PHY_IMP_CTRL1 0x220
|
||||
#define QUSB2PHY_IMP_CTRL2 0x224
|
||||
#define QUSB2PHY_CHG_CTRL2 0x23c
|
||||
|
||||
struct qusb2_phy_init_tbl {
|
||||
unsigned int offset;
|
||||
unsigned int val;
|
||||
/*
|
||||
* register part of layout ?
|
||||
* if yes, then offset gives index in the reg-layout
|
||||
*/
|
||||
int in_layout;
|
||||
};
|
||||
|
||||
#define QUSB2_PHY_INIT_CFG(o, v) \
|
||||
@ -67,30 +88,136 @@ struct qusb2_phy_init_tbl {
|
||||
.val = v, \
|
||||
}
|
||||
|
||||
#define QUSB2_PHY_INIT_CFG_L(o, v) \
|
||||
{ \
|
||||
.offset = o, \
|
||||
.val = v, \
|
||||
.in_layout = 1, \
|
||||
}
|
||||
|
||||
/* set of registers with offsets different per-PHY */
|
||||
enum qusb2phy_reg_layout {
|
||||
QUSB2PHY_PLL_CORE_INPUT_OVERRIDE,
|
||||
QUSB2PHY_PLL_STATUS,
|
||||
QUSB2PHY_PORT_TUNE1,
|
||||
QUSB2PHY_PORT_TUNE2,
|
||||
QUSB2PHY_PORT_TUNE3,
|
||||
QUSB2PHY_PORT_TUNE4,
|
||||
QUSB2PHY_PORT_TUNE5,
|
||||
QUSB2PHY_PORT_TEST1,
|
||||
QUSB2PHY_PORT_TEST2,
|
||||
QUSB2PHY_PORT_POWERDOWN,
|
||||
QUSB2PHY_INTR_CTRL,
|
||||
};
|
||||
|
||||
static const unsigned int msm8996_regs_layout[] = {
|
||||
[QUSB2PHY_PLL_STATUS] = 0x38,
|
||||
[QUSB2PHY_PORT_TUNE1] = 0x80,
|
||||
[QUSB2PHY_PORT_TUNE2] = 0x84,
|
||||
[QUSB2PHY_PORT_TUNE3] = 0x88,
|
||||
[QUSB2PHY_PORT_TUNE4] = 0x8c,
|
||||
[QUSB2PHY_PORT_TUNE5] = 0x90,
|
||||
[QUSB2PHY_PORT_TEST1] = 0xb8,
|
||||
[QUSB2PHY_PORT_TEST2] = 0x9c,
|
||||
[QUSB2PHY_PORT_POWERDOWN] = 0xb4,
|
||||
[QUSB2PHY_INTR_CTRL] = 0xbc,
|
||||
};
|
||||
|
||||
static const struct qusb2_phy_init_tbl msm8996_init_tbl[] = {
|
||||
QUSB2_PHY_INIT_CFG(QUSB2PHY_PORT_TUNE1, 0xf8),
|
||||
QUSB2_PHY_INIT_CFG(QUSB2PHY_PORT_TUNE2, 0xb3),
|
||||
QUSB2_PHY_INIT_CFG(QUSB2PHY_PORT_TUNE3, 0x83),
|
||||
QUSB2_PHY_INIT_CFG(QUSB2PHY_PORT_TUNE4, 0xc0),
|
||||
QUSB2_PHY_INIT_CFG_L(QUSB2PHY_PORT_TUNE1, 0xf8),
|
||||
QUSB2_PHY_INIT_CFG_L(QUSB2PHY_PORT_TUNE2, 0xb3),
|
||||
QUSB2_PHY_INIT_CFG_L(QUSB2PHY_PORT_TUNE3, 0x83),
|
||||
QUSB2_PHY_INIT_CFG_L(QUSB2PHY_PORT_TUNE4, 0xc0),
|
||||
|
||||
QUSB2_PHY_INIT_CFG(QUSB2PHY_PLL_TUNE, 0x30),
|
||||
QUSB2_PHY_INIT_CFG(QUSB2PHY_PLL_USER_CTL1, 0x79),
|
||||
QUSB2_PHY_INIT_CFG(QUSB2PHY_PLL_USER_CTL2, 0x21),
|
||||
QUSB2_PHY_INIT_CFG(QUSB2PHY_PORT_TEST2, 0x14),
|
||||
|
||||
QUSB2_PHY_INIT_CFG_L(QUSB2PHY_PORT_TEST2, 0x14),
|
||||
|
||||
QUSB2_PHY_INIT_CFG(QUSB2PHY_PLL_AUTOPGM_CTL1, 0x9f),
|
||||
QUSB2_PHY_INIT_CFG(QUSB2PHY_PLL_PWR_CTRL, 0x00),
|
||||
};
|
||||
|
||||
static const unsigned int qusb2_v2_regs_layout[] = {
|
||||
[QUSB2PHY_PLL_CORE_INPUT_OVERRIDE] = 0xa8,
|
||||
[QUSB2PHY_PLL_STATUS] = 0x1a0,
|
||||
[QUSB2PHY_PORT_TUNE1] = 0x240,
|
||||
[QUSB2PHY_PORT_TUNE2] = 0x244,
|
||||
[QUSB2PHY_PORT_TUNE3] = 0x248,
|
||||
[QUSB2PHY_PORT_TUNE4] = 0x24c,
|
||||
[QUSB2PHY_PORT_TUNE5] = 0x250,
|
||||
[QUSB2PHY_PORT_TEST1] = 0x254,
|
||||
[QUSB2PHY_PORT_TEST2] = 0x258,
|
||||
[QUSB2PHY_PORT_POWERDOWN] = 0x210,
|
||||
[QUSB2PHY_INTR_CTRL] = 0x230,
|
||||
};
|
||||
|
||||
static const struct qusb2_phy_init_tbl qusb2_v2_init_tbl[] = {
|
||||
QUSB2_PHY_INIT_CFG(QUSB2PHY_PLL_ANALOG_CONTROLS_TWO, 0x03),
|
||||
QUSB2_PHY_INIT_CFG(QUSB2PHY_PLL_CLOCK_INVERTERS, 0x7c),
|
||||
QUSB2_PHY_INIT_CFG(QUSB2PHY_PLL_CMODE, 0x80),
|
||||
QUSB2_PHY_INIT_CFG(QUSB2PHY_PLL_LOCK_DELAY, 0x0a),
|
||||
QUSB2_PHY_INIT_CFG(QUSB2PHY_PLL_DIGITAL_TIMERS_TWO, 0x19),
|
||||
QUSB2_PHY_INIT_CFG(QUSB2PHY_PLL_BIAS_CONTROL_1, 0x40),
|
||||
QUSB2_PHY_INIT_CFG(QUSB2PHY_PLL_BIAS_CONTROL_2, 0x20),
|
||||
QUSB2_PHY_INIT_CFG(QUSB2PHY_PWR_CTRL2, 0x21),
|
||||
QUSB2_PHY_INIT_CFG(QUSB2PHY_IMP_CTRL1, 0x0),
|
||||
QUSB2_PHY_INIT_CFG(QUSB2PHY_IMP_CTRL2, 0x58),
|
||||
|
||||
QUSB2_PHY_INIT_CFG_L(QUSB2PHY_PORT_TUNE1, 0x30),
|
||||
QUSB2_PHY_INIT_CFG_L(QUSB2PHY_PORT_TUNE2, 0x29),
|
||||
QUSB2_PHY_INIT_CFG_L(QUSB2PHY_PORT_TUNE3, 0xca),
|
||||
QUSB2_PHY_INIT_CFG_L(QUSB2PHY_PORT_TUNE4, 0x04),
|
||||
QUSB2_PHY_INIT_CFG_L(QUSB2PHY_PORT_TUNE5, 0x03),
|
||||
|
||||
QUSB2_PHY_INIT_CFG(QUSB2PHY_CHG_CTRL2, 0x0),
|
||||
};
|
||||
|
||||
struct qusb2_phy_cfg {
|
||||
const struct qusb2_phy_init_tbl *tbl;
|
||||
/* number of entries in the table */
|
||||
unsigned int tbl_num;
|
||||
/* offset to PHY_CLK_SCHEME register in TCSR map */
|
||||
unsigned int clk_scheme_offset;
|
||||
|
||||
/* array of registers with different offsets */
|
||||
const unsigned int *regs;
|
||||
unsigned int mask_core_ready;
|
||||
unsigned int disable_ctrl;
|
||||
unsigned int autoresume_en;
|
||||
|
||||
/* true if PHY has PLL_TEST register to select clk_scheme */
|
||||
bool has_pll_test;
|
||||
|
||||
/* true if TUNE1 register must be updated by fused value, else TUNE2 */
|
||||
bool update_tune1_with_efuse;
|
||||
|
||||
/* true if PHY has PLL_CORE_INPUT_OVERRIDE register to reset PLL */
|
||||
bool has_pll_override;
|
||||
};
|
||||
|
||||
static const struct qusb2_phy_cfg msm8996_phy_cfg = {
|
||||
.tbl = msm8996_init_tbl,
|
||||
.tbl_num = ARRAY_SIZE(msm8996_init_tbl),
|
||||
.tbl = msm8996_init_tbl,
|
||||
.tbl_num = ARRAY_SIZE(msm8996_init_tbl),
|
||||
.regs = msm8996_regs_layout,
|
||||
|
||||
.has_pll_test = true,
|
||||
.disable_ctrl = (CLAMP_N_EN | FREEZIO_N | POWER_DOWN),
|
||||
.mask_core_ready = PLL_LOCKED,
|
||||
.autoresume_en = BIT(3),
|
||||
};
|
||||
|
||||
static const struct qusb2_phy_cfg qusb2_v2_phy_cfg = {
|
||||
.tbl = qusb2_v2_init_tbl,
|
||||
.tbl_num = ARRAY_SIZE(qusb2_v2_init_tbl),
|
||||
.regs = qusb2_v2_regs_layout,
|
||||
|
||||
.disable_ctrl = (PWR_CTRL1_VREF_SUPPLY_TRIM | PWR_CTRL1_CLAMP_N_EN |
|
||||
POWER_DOWN),
|
||||
.mask_core_ready = CORE_READY_STATUS,
|
||||
.has_pll_override = true,
|
||||
.autoresume_en = BIT(0),
|
||||
};
|
||||
|
||||
static const char * const qusb2_phy_vreg_names[] = {
|
||||
@ -116,6 +243,8 @@ static const char * const qusb2_phy_vreg_names[] = {
|
||||
*
|
||||
* @cfg: phy config data
|
||||
* @has_se_clk_scheme: indicate if PHY has single-ended ref clock scheme
|
||||
* @phy_initialized: indicate if PHY has been initialized
|
||||
* @mode: current PHY mode
|
||||
*/
|
||||
struct qusb2_phy {
|
||||
struct phy *phy;
|
||||
@ -132,6 +261,8 @@ struct qusb2_phy {
|
||||
|
||||
const struct qusb2_phy_cfg *cfg;
|
||||
bool has_se_clk_scheme;
|
||||
bool phy_initialized;
|
||||
enum phy_mode mode;
|
||||
};
|
||||
|
||||
static inline void qusb2_setbits(void __iomem *base, u32 offset, u32 val)
|
||||
@ -160,26 +291,32 @@ static inline void qusb2_clrbits(void __iomem *base, u32 offset, u32 val)
|
||||
|
||||
static inline
|
||||
void qcom_qusb2_phy_configure(void __iomem *base,
|
||||
const unsigned int *regs,
|
||||
const struct qusb2_phy_init_tbl tbl[], int num)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < num; i++)
|
||||
writel(tbl[i].val, base + tbl[i].offset);
|
||||
for (i = 0; i < num; i++) {
|
||||
if (tbl[i].in_layout)
|
||||
writel(tbl[i].val, base + regs[tbl[i].offset]);
|
||||
else
|
||||
writel(tbl[i].val, base + tbl[i].offset);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Fetches HS Tx tuning value from nvmem and sets the
|
||||
* QUSB2PHY_PORT_TUNE2 register.
|
||||
* QUSB2PHY_PORT_TUNE1/2 register.
|
||||
* For error case, skip setting the value and use the default value.
|
||||
*/
|
||||
static void qusb2_phy_set_tune2_param(struct qusb2_phy *qphy)
|
||||
{
|
||||
struct device *dev = &qphy->phy->dev;
|
||||
const struct qusb2_phy_cfg *cfg = qphy->cfg;
|
||||
u8 *val;
|
||||
|
||||
/*
|
||||
* Read efuse register having TUNE2 parameter's high nibble.
|
||||
* Read efuse register having TUNE2/1 parameter's high nibble.
|
||||
* If efuse register shows value as 0x0, or if we fail to find
|
||||
* a valid efuse register settings, then use default value
|
||||
* as 0xB for high nibble that we have already set while
|
||||
@ -191,58 +328,169 @@ static void qusb2_phy_set_tune2_param(struct qusb2_phy *qphy)
|
||||
return;
|
||||
}
|
||||
|
||||
/* Fused TUNE2 value is the higher nibble only */
|
||||
qusb2_setbits(qphy->base, QUSB2PHY_PORT_TUNE2, val[0] << 0x4);
|
||||
/* Fused TUNE1/2 value is the higher nibble only */
|
||||
if (cfg->update_tune1_with_efuse)
|
||||
qusb2_setbits(qphy->base, cfg->regs[QUSB2PHY_PORT_TUNE1],
|
||||
val[0] << 0x4);
|
||||
else
|
||||
qusb2_setbits(qphy->base, cfg->regs[QUSB2PHY_PORT_TUNE2],
|
||||
val[0] << 0x4);
|
||||
|
||||
}
|
||||
|
||||
static int qusb2_phy_poweron(struct phy *phy)
|
||||
static int qusb2_phy_set_mode(struct phy *phy, enum phy_mode mode)
|
||||
{
|
||||
struct qusb2_phy *qphy = phy_get_drvdata(phy);
|
||||
int num = ARRAY_SIZE(qphy->vregs);
|
||||
|
||||
qphy->mode = mode;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int __maybe_unused qusb2_phy_runtime_suspend(struct device *dev)
|
||||
{
|
||||
struct qusb2_phy *qphy = dev_get_drvdata(dev);
|
||||
const struct qusb2_phy_cfg *cfg = qphy->cfg;
|
||||
u32 intr_mask;
|
||||
|
||||
dev_vdbg(dev, "Suspending QUSB2 Phy, mode:%d\n", qphy->mode);
|
||||
|
||||
if (!qphy->phy_initialized) {
|
||||
dev_vdbg(dev, "PHY not initialized, bailing out\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Enable DP/DM interrupts to detect line state changes based on current
|
||||
* speed. In other words, enable the triggers _opposite_ of what the
|
||||
* current D+/D- levels are e.g. if currently D+ high, D- low
|
||||
* (HS 'J'/Suspend), configure the mask to trigger on D+ low OR D- high
|
||||
*/
|
||||
intr_mask = DPSE_INTR_EN | DMSE_INTR_EN;
|
||||
switch (qphy->mode) {
|
||||
case PHY_MODE_USB_HOST_HS:
|
||||
case PHY_MODE_USB_HOST_FS:
|
||||
case PHY_MODE_USB_DEVICE_HS:
|
||||
case PHY_MODE_USB_DEVICE_FS:
|
||||
intr_mask |= DMSE_INTR_HIGH_SEL;
|
||||
break;
|
||||
case PHY_MODE_USB_HOST_LS:
|
||||
case PHY_MODE_USB_DEVICE_LS:
|
||||
intr_mask |= DPSE_INTR_HIGH_SEL;
|
||||
break;
|
||||
default:
|
||||
/* No device connected, enable both DP/DM high interrupt */
|
||||
intr_mask |= DMSE_INTR_HIGH_SEL;
|
||||
intr_mask |= DPSE_INTR_HIGH_SEL;
|
||||
break;
|
||||
}
|
||||
|
||||
writel(intr_mask, qphy->base + cfg->regs[QUSB2PHY_INTR_CTRL]);
|
||||
|
||||
/* hold core PLL into reset */
|
||||
if (cfg->has_pll_override) {
|
||||
qusb2_setbits(qphy->base,
|
||||
cfg->regs[QUSB2PHY_PLL_CORE_INPUT_OVERRIDE],
|
||||
CORE_PLL_EN_FROM_RESET | CORE_RESET |
|
||||
CORE_RESET_MUX);
|
||||
}
|
||||
|
||||
/* enable phy auto-resume only if device is connected on bus */
|
||||
if (qphy->mode != PHY_MODE_INVALID) {
|
||||
qusb2_setbits(qphy->base, cfg->regs[QUSB2PHY_PORT_TEST1],
|
||||
cfg->autoresume_en);
|
||||
/* Autoresume bit has to be toggled in order to enable it */
|
||||
qusb2_clrbits(qphy->base, cfg->regs[QUSB2PHY_PORT_TEST1],
|
||||
cfg->autoresume_en);
|
||||
}
|
||||
|
||||
if (!qphy->has_se_clk_scheme)
|
||||
clk_disable_unprepare(qphy->ref_clk);
|
||||
|
||||
clk_disable_unprepare(qphy->cfg_ahb_clk);
|
||||
clk_disable_unprepare(qphy->iface_clk);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int __maybe_unused qusb2_phy_runtime_resume(struct device *dev)
|
||||
{
|
||||
struct qusb2_phy *qphy = dev_get_drvdata(dev);
|
||||
const struct qusb2_phy_cfg *cfg = qphy->cfg;
|
||||
int ret;
|
||||
|
||||
dev_vdbg(&phy->dev, "%s(): Powering-on QUSB2 phy\n", __func__);
|
||||
dev_vdbg(dev, "Resuming QUSB2 phy, mode:%d\n", qphy->mode);
|
||||
|
||||
if (!qphy->phy_initialized) {
|
||||
dev_vdbg(dev, "PHY not initialized, bailing out\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
ret = clk_prepare_enable(qphy->iface_clk);
|
||||
if (ret) {
|
||||
dev_err(dev, "failed to enable iface_clk, %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = clk_prepare_enable(qphy->cfg_ahb_clk);
|
||||
if (ret) {
|
||||
dev_err(dev, "failed to enable cfg ahb clock, %d\n", ret);
|
||||
goto disable_iface_clk;
|
||||
}
|
||||
|
||||
if (!qphy->has_se_clk_scheme) {
|
||||
clk_prepare_enable(qphy->ref_clk);
|
||||
if (ret) {
|
||||
dev_err(dev, "failed to enable ref clk, %d\n", ret);
|
||||
goto disable_ahb_clk;
|
||||
}
|
||||
}
|
||||
|
||||
writel(0x0, qphy->base + cfg->regs[QUSB2PHY_INTR_CTRL]);
|
||||
|
||||
/* bring core PLL out of reset */
|
||||
if (cfg->has_pll_override) {
|
||||
qusb2_clrbits(qphy->base,
|
||||
cfg->regs[QUSB2PHY_PLL_CORE_INPUT_OVERRIDE],
|
||||
CORE_RESET | CORE_RESET_MUX);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
disable_ahb_clk:
|
||||
clk_disable_unprepare(qphy->cfg_ahb_clk);
|
||||
disable_iface_clk:
|
||||
clk_disable_unprepare(qphy->iface_clk);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int qusb2_phy_init(struct phy *phy)
|
||||
{
|
||||
struct qusb2_phy *qphy = phy_get_drvdata(phy);
|
||||
const struct qusb2_phy_cfg *cfg = qphy->cfg;
|
||||
unsigned int val = 0;
|
||||
unsigned int clk_scheme;
|
||||
int ret;
|
||||
|
||||
dev_vdbg(&phy->dev, "%s(): Initializing QUSB2 phy\n", __func__);
|
||||
|
||||
/* turn on regulator supplies */
|
||||
ret = regulator_bulk_enable(num, qphy->vregs);
|
||||
ret = regulator_bulk_enable(ARRAY_SIZE(qphy->vregs), qphy->vregs);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
ret = clk_prepare_enable(qphy->iface_clk);
|
||||
if (ret) {
|
||||
dev_err(&phy->dev, "failed to enable iface_clk, %d\n", ret);
|
||||
regulator_bulk_disable(num, qphy->vregs);
|
||||
return ret;
|
||||
goto poweroff_phy;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int qusb2_phy_poweroff(struct phy *phy)
|
||||
{
|
||||
struct qusb2_phy *qphy = phy_get_drvdata(phy);
|
||||
|
||||
clk_disable_unprepare(qphy->iface_clk);
|
||||
|
||||
regulator_bulk_disable(ARRAY_SIZE(qphy->vregs), qphy->vregs);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int qusb2_phy_init(struct phy *phy)
|
||||
{
|
||||
struct qusb2_phy *qphy = phy_get_drvdata(phy);
|
||||
unsigned int val;
|
||||
unsigned int clk_scheme;
|
||||
int ret;
|
||||
|
||||
dev_vdbg(&phy->dev, "%s(): Initializing QUSB2 phy\n", __func__);
|
||||
|
||||
/* enable ahb interface clock to program phy */
|
||||
ret = clk_prepare_enable(qphy->cfg_ahb_clk);
|
||||
if (ret) {
|
||||
dev_err(&phy->dev, "failed to enable cfg ahb clock, %d\n", ret);
|
||||
return ret;
|
||||
goto disable_iface_clk;
|
||||
}
|
||||
|
||||
/* Perform phy reset */
|
||||
@ -262,20 +510,23 @@ static int qusb2_phy_init(struct phy *phy)
|
||||
}
|
||||
|
||||
/* Disable the PHY */
|
||||
qusb2_setbits(qphy->base, QUSB2PHY_PORT_POWERDOWN,
|
||||
CLAMP_N_EN | FREEZIO_N | POWER_DOWN);
|
||||
qusb2_setbits(qphy->base, cfg->regs[QUSB2PHY_PORT_POWERDOWN],
|
||||
qphy->cfg->disable_ctrl);
|
||||
|
||||
/* save reset value to override reference clock scheme later */
|
||||
val = readl(qphy->base + QUSB2PHY_PLL_TEST);
|
||||
if (cfg->has_pll_test) {
|
||||
/* save reset value to override reference clock scheme later */
|
||||
val = readl(qphy->base + QUSB2PHY_PLL_TEST);
|
||||
}
|
||||
|
||||
qcom_qusb2_phy_configure(qphy->base, qphy->cfg->tbl,
|
||||
qphy->cfg->tbl_num);
|
||||
qcom_qusb2_phy_configure(qphy->base, cfg->regs, cfg->tbl,
|
||||
cfg->tbl_num);
|
||||
|
||||
/* Set efuse value for tuning the PHY */
|
||||
qusb2_phy_set_tune2_param(qphy);
|
||||
|
||||
/* Enable the PHY */
|
||||
qusb2_clrbits(qphy->base, QUSB2PHY_PORT_POWERDOWN, POWER_DOWN);
|
||||
qusb2_clrbits(qphy->base, cfg->regs[QUSB2PHY_PORT_POWERDOWN],
|
||||
POWER_DOWN);
|
||||
|
||||
/* Required to get phy pll lock successfully */
|
||||
usleep_range(150, 160);
|
||||
@ -308,32 +559,37 @@ static int qusb2_phy_init(struct phy *phy)
|
||||
}
|
||||
|
||||
if (!qphy->has_se_clk_scheme) {
|
||||
val &= ~CLK_REF_SEL;
|
||||
ret = clk_prepare_enable(qphy->ref_clk);
|
||||
if (ret) {
|
||||
dev_err(&phy->dev, "failed to enable ref clk, %d\n",
|
||||
ret);
|
||||
goto assert_phy_reset;
|
||||
}
|
||||
} else {
|
||||
val |= CLK_REF_SEL;
|
||||
}
|
||||
|
||||
writel(val, qphy->base + QUSB2PHY_PLL_TEST);
|
||||
if (cfg->has_pll_test) {
|
||||
if (!qphy->has_se_clk_scheme)
|
||||
val &= ~CLK_REF_SEL;
|
||||
else
|
||||
val |= CLK_REF_SEL;
|
||||
|
||||
/* ensure above write is through */
|
||||
readl(qphy->base + QUSB2PHY_PLL_TEST);
|
||||
writel(val, qphy->base + QUSB2PHY_PLL_TEST);
|
||||
|
||||
/* ensure above write is through */
|
||||
readl(qphy->base + QUSB2PHY_PLL_TEST);
|
||||
}
|
||||
|
||||
/* Required to get phy pll lock successfully */
|
||||
usleep_range(100, 110);
|
||||
|
||||
val = readb(qphy->base + QUSB2PHY_PLL_STATUS);
|
||||
if (!(val & PLL_LOCKED)) {
|
||||
val = readb(qphy->base + cfg->regs[QUSB2PHY_PLL_STATUS]);
|
||||
if (!(val & cfg->mask_core_ready)) {
|
||||
dev_err(&phy->dev,
|
||||
"QUSB2PHY pll lock failed: status reg = %x\n", val);
|
||||
ret = -EBUSY;
|
||||
goto disable_ref_clk;
|
||||
}
|
||||
qphy->phy_initialized = true;
|
||||
|
||||
return 0;
|
||||
|
||||
@ -344,6 +600,11 @@ assert_phy_reset:
|
||||
reset_control_assert(qphy->phy_reset);
|
||||
disable_ahb_clk:
|
||||
clk_disable_unprepare(qphy->cfg_ahb_clk);
|
||||
disable_iface_clk:
|
||||
clk_disable_unprepare(qphy->iface_clk);
|
||||
poweroff_phy:
|
||||
regulator_bulk_disable(ARRAY_SIZE(qphy->vregs), qphy->vregs);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -352,8 +613,8 @@ static int qusb2_phy_exit(struct phy *phy)
|
||||
struct qusb2_phy *qphy = phy_get_drvdata(phy);
|
||||
|
||||
/* Disable the PHY */
|
||||
qusb2_setbits(qphy->base, QUSB2PHY_PORT_POWERDOWN,
|
||||
CLAMP_N_EN | FREEZIO_N | POWER_DOWN);
|
||||
qusb2_setbits(qphy->base, qphy->cfg->regs[QUSB2PHY_PORT_POWERDOWN],
|
||||
qphy->cfg->disable_ctrl);
|
||||
|
||||
if (!qphy->has_se_clk_scheme)
|
||||
clk_disable_unprepare(qphy->ref_clk);
|
||||
@ -361,6 +622,11 @@ static int qusb2_phy_exit(struct phy *phy)
|
||||
reset_control_assert(qphy->phy_reset);
|
||||
|
||||
clk_disable_unprepare(qphy->cfg_ahb_clk);
|
||||
clk_disable_unprepare(qphy->iface_clk);
|
||||
|
||||
regulator_bulk_disable(ARRAY_SIZE(qphy->vregs), qphy->vregs);
|
||||
|
||||
qphy->phy_initialized = false;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -368,8 +634,7 @@ static int qusb2_phy_exit(struct phy *phy)
|
||||
static const struct phy_ops qusb2_phy_gen_ops = {
|
||||
.init = qusb2_phy_init,
|
||||
.exit = qusb2_phy_exit,
|
||||
.power_on = qusb2_phy_poweron,
|
||||
.power_off = qusb2_phy_poweroff,
|
||||
.set_mode = qusb2_phy_set_mode,
|
||||
.owner = THIS_MODULE,
|
||||
};
|
||||
|
||||
@ -377,11 +642,19 @@ static const struct of_device_id qusb2_phy_of_match_table[] = {
|
||||
{
|
||||
.compatible = "qcom,msm8996-qusb2-phy",
|
||||
.data = &msm8996_phy_cfg,
|
||||
}, {
|
||||
.compatible = "qcom,qusb2-v2-phy",
|
||||
.data = &qusb2_v2_phy_cfg,
|
||||
},
|
||||
{ },
|
||||
};
|
||||
MODULE_DEVICE_TABLE(of, qusb2_phy_of_match_table);
|
||||
|
||||
static const struct dev_pm_ops qusb2_phy_pm_ops = {
|
||||
SET_RUNTIME_PM_OPS(qusb2_phy_runtime_suspend,
|
||||
qusb2_phy_runtime_resume, NULL)
|
||||
};
|
||||
|
||||
static int qusb2_phy_probe(struct platform_device *pdev)
|
||||
{
|
||||
struct device *dev = &pdev->dev;
|
||||
@ -459,11 +732,19 @@ static int qusb2_phy_probe(struct platform_device *pdev)
|
||||
qphy->cell = NULL;
|
||||
dev_dbg(dev, "failed to lookup tune2 hstx trim value\n");
|
||||
}
|
||||
pm_runtime_set_active(dev);
|
||||
pm_runtime_enable(dev);
|
||||
/*
|
||||
* Prevent runtime pm from being ON by default. Users can enable
|
||||
* it using power/control in sysfs.
|
||||
*/
|
||||
pm_runtime_forbid(dev);
|
||||
|
||||
generic_phy = devm_phy_create(dev, NULL, &qusb2_phy_gen_ops);
|
||||
if (IS_ERR(generic_phy)) {
|
||||
ret = PTR_ERR(generic_phy);
|
||||
dev_err(dev, "failed to create phy, %d\n", ret);
|
||||
pm_runtime_disable(dev);
|
||||
return ret;
|
||||
}
|
||||
qphy->phy = generic_phy;
|
||||
@ -474,6 +755,8 @@ static int qusb2_phy_probe(struct platform_device *pdev)
|
||||
phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
|
||||
if (!IS_ERR(phy_provider))
|
||||
dev_info(dev, "Registered Qcom-QUSB2 phy\n");
|
||||
else
|
||||
pm_runtime_disable(dev);
|
||||
|
||||
return PTR_ERR_OR_ZERO(phy_provider);
|
||||
}
|
||||
@ -482,6 +765,7 @@ static struct platform_driver qusb2_phy_driver = {
|
||||
.probe = qusb2_phy_probe,
|
||||
.driver = {
|
||||
.name = "qcom-qusb2-phy",
|
||||
.pm = &qusb2_phy_pm_ops,
|
||||
.of_match_table = qusb2_phy_of_match_table,
|
||||
},
|
||||
};
|
||||
|
@ -4,6 +4,7 @@
|
||||
config PHY_RALINK_USB
|
||||
tristate "Ralink USB PHY driver"
|
||||
depends on RALINK || COMPILE_TEST
|
||||
depends on HAS_IOMEM
|
||||
select GENERIC_PHY
|
||||
select MFD_SYSCON
|
||||
help
|
||||
|
@ -396,6 +396,10 @@ static const struct of_device_id rcar_gen3_phy_usb2_match_table[] = {
|
||||
.compatible = "renesas,usb2-phy-r8a7796",
|
||||
.data = (void *)RCAR_GEN3_PHY_HAS_DEDICATED_PINS,
|
||||
},
|
||||
{
|
||||
.compatible = "renesas,usb2-phy-r8a77965",
|
||||
.data = (void *)RCAR_GEN3_PHY_HAS_DEDICATED_PINS,
|
||||
},
|
||||
{
|
||||
.compatible = "renesas,rcar-gen3-usb2-phy",
|
||||
},
|
||||
|
@ -29,6 +29,7 @@ config PHY_ROCKCHIP_INNO_USB2
|
||||
config PHY_ROCKCHIP_PCIE
|
||||
tristate "Rockchip PCIe PHY Driver"
|
||||
depends on (ARCH_ROCKCHIP && OF) || COMPILE_TEST
|
||||
depends on HAS_IOMEM
|
||||
select GENERIC_PHY
|
||||
select MFD_SYSCON
|
||||
help
|
||||
|
@ -76,6 +76,13 @@
|
||||
#define PHYCTRL_OTAPDLYSEL_MASK 0xf
|
||||
#define PHYCTRL_OTAPDLYSEL_SHIFT 0x7
|
||||
|
||||
#define PHYCTRL_IS_CALDONE(x) \
|
||||
((((x) >> PHYCTRL_CALDONE_SHIFT) & \
|
||||
PHYCTRL_CALDONE_MASK) == PHYCTRL_CALDONE_DONE)
|
||||
#define PHYCTRL_IS_DLLRDY(x) \
|
||||
((((x) >> PHYCTRL_DLLRDY_SHIFT) & \
|
||||
PHYCTRL_DLLRDY_MASK) == PHYCTRL_DLLRDY_DONE)
|
||||
|
||||
struct rockchip_emmc_phy {
|
||||
unsigned int reg_offset;
|
||||
struct regmap *reg_base;
|
||||
@ -89,7 +96,7 @@ static int rockchip_emmc_phy_power(struct phy *phy, bool on_off)
|
||||
unsigned int dllrdy;
|
||||
unsigned int freqsel = PHYCTRL_FREQSEL_200M;
|
||||
unsigned long rate;
|
||||
unsigned long timeout;
|
||||
int ret;
|
||||
|
||||
/*
|
||||
* Keep phyctrl_pdb and phyctrl_endll low to allow
|
||||
@ -160,17 +167,19 @@ static int rockchip_emmc_phy_power(struct phy *phy, bool on_off)
|
||||
PHYCTRL_PDB_SHIFT));
|
||||
|
||||
/*
|
||||
* According to the user manual, it asks driver to
|
||||
* wait 5us for calpad busy trimming
|
||||
* According to the user manual, it asks driver to wait 5us for
|
||||
* calpad busy trimming. However it is documented that this value is
|
||||
* PVT(A.K.A process,voltage and temperature) relevant, so some
|
||||
* failure cases are found which indicates we should be more tolerant
|
||||
* to calpad busy trimming.
|
||||
*/
|
||||
udelay(5);
|
||||
regmap_read(rk_phy->reg_base,
|
||||
rk_phy->reg_offset + GRF_EMMCPHY_STATUS,
|
||||
&caldone);
|
||||
caldone = (caldone >> PHYCTRL_CALDONE_SHIFT) & PHYCTRL_CALDONE_MASK;
|
||||
if (caldone != PHYCTRL_CALDONE_DONE) {
|
||||
pr_err("rockchip_emmc_phy_power: caldone timeout.\n");
|
||||
return -ETIMEDOUT;
|
||||
ret = regmap_read_poll_timeout(rk_phy->reg_base,
|
||||
rk_phy->reg_offset + GRF_EMMCPHY_STATUS,
|
||||
caldone, PHYCTRL_IS_CALDONE(caldone),
|
||||
0, 50);
|
||||
if (ret) {
|
||||
pr_err("%s: caldone failed, ret=%d\n", __func__, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Set the frequency of the DLL operation */
|
||||
@ -210,28 +219,15 @@ static int rockchip_emmc_phy_power(struct phy *phy, bool on_off)
|
||||
* NOTE: There appear to be corner cases where the DLL seems to take
|
||||
* extra long to lock for reasons that aren't understood. In some
|
||||
* extreme cases we've seen it take up to over 10ms (!). We'll be
|
||||
* generous and give it 50ms. We still busy wait here because:
|
||||
* - In most cases it should be super fast.
|
||||
* - This is not called lots during normal operation so it shouldn't
|
||||
* be a power or performance problem to busy wait. We expect it
|
||||
* only at boot / resume. In both cases, eMMC is probably on the
|
||||
* critical path so busy waiting a little extra time should be OK.
|
||||
* generous and give it 50ms.
|
||||
*/
|
||||
timeout = jiffies + msecs_to_jiffies(50);
|
||||
do {
|
||||
udelay(1);
|
||||
|
||||
regmap_read(rk_phy->reg_base,
|
||||
rk_phy->reg_offset + GRF_EMMCPHY_STATUS,
|
||||
&dllrdy);
|
||||
dllrdy = (dllrdy >> PHYCTRL_DLLRDY_SHIFT) & PHYCTRL_DLLRDY_MASK;
|
||||
if (dllrdy == PHYCTRL_DLLRDY_DONE)
|
||||
break;
|
||||
} while (!time_after(jiffies, timeout));
|
||||
|
||||
if (dllrdy != PHYCTRL_DLLRDY_DONE) {
|
||||
pr_err("rockchip_emmc_phy_power: dllrdy timeout.\n");
|
||||
return -ETIMEDOUT;
|
||||
ret = regmap_read_poll_timeout(rk_phy->reg_base,
|
||||
rk_phy->reg_offset + GRF_EMMCPHY_STATUS,
|
||||
dllrdy, PHYCTRL_IS_DLLRDY(dllrdy),
|
||||
0, 50 * USEC_PER_MSEC);
|
||||
if (ret) {
|
||||
pr_err("%s: dllrdy failed. ret=%d\n", __func__, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -355,11 +355,26 @@ struct usb3phy_reg {
|
||||
u32 write_enable;
|
||||
};
|
||||
|
||||
/**
|
||||
* struct rockchip_usb3phy_port_cfg: usb3-phy port configuration.
|
||||
* @reg: the base address for usb3-phy config.
|
||||
* @typec_conn_dir: the register of type-c connector direction.
|
||||
* @usb3tousb2_en: the register of type-c force usb2 to usb2 enable.
|
||||
* @external_psm: the register of type-c phy external psm clock.
|
||||
* @pipe_status: the register of type-c phy pipe status.
|
||||
* @usb3_host_disable: the register of type-c usb3 host disable.
|
||||
* @usb3_host_port: the register of type-c usb3 host port.
|
||||
* @uphy_dp_sel: the register of type-c phy DP select control.
|
||||
*/
|
||||
struct rockchip_usb3phy_port_cfg {
|
||||
unsigned int reg;
|
||||
struct usb3phy_reg typec_conn_dir;
|
||||
struct usb3phy_reg usb3tousb2_en;
|
||||
struct usb3phy_reg external_psm;
|
||||
struct usb3phy_reg pipe_status;
|
||||
struct usb3phy_reg usb3_host_disable;
|
||||
struct usb3phy_reg usb3_host_port;
|
||||
struct usb3phy_reg uphy_dp_sel;
|
||||
};
|
||||
|
||||
struct rockchip_typec_phy {
|
||||
@ -372,7 +387,7 @@ struct rockchip_typec_phy {
|
||||
struct reset_control *uphy_rst;
|
||||
struct reset_control *pipe_rst;
|
||||
struct reset_control *tcphy_rst;
|
||||
struct rockchip_usb3phy_port_cfg port_cfgs;
|
||||
const struct rockchip_usb3phy_port_cfg *port_cfgs;
|
||||
/* mutex to protect access to individual PHYs */
|
||||
struct mutex lock;
|
||||
|
||||
@ -424,6 +439,30 @@ struct phy_reg dp_pll_cfg[] = {
|
||||
{ 0x4, CMN_DIAG_PLL1_INCLK_CTRL },
|
||||
};
|
||||
|
||||
static const struct rockchip_usb3phy_port_cfg rk3399_usb3phy_port_cfgs[] = {
|
||||
{
|
||||
.reg = 0xff7c0000,
|
||||
.typec_conn_dir = { 0xe580, 0, 16 },
|
||||
.usb3tousb2_en = { 0xe580, 3, 19 },
|
||||
.external_psm = { 0xe588, 14, 30 },
|
||||
.pipe_status = { 0xe5c0, 0, 0 },
|
||||
.usb3_host_disable = { 0x2434, 0, 16 },
|
||||
.usb3_host_port = { 0x2434, 12, 28 },
|
||||
.uphy_dp_sel = { 0x6268, 19, 19 },
|
||||
},
|
||||
{
|
||||
.reg = 0xff800000,
|
||||
.typec_conn_dir = { 0xe58c, 0, 16 },
|
||||
.usb3tousb2_en = { 0xe58c, 3, 19 },
|
||||
.external_psm = { 0xe594, 14, 30 },
|
||||
.pipe_status = { 0xe5c0, 16, 16 },
|
||||
.usb3_host_disable = { 0x2444, 0, 16 },
|
||||
.usb3_host_port = { 0x2444, 12, 28 },
|
||||
.uphy_dp_sel = { 0x6268, 3, 19 },
|
||||
},
|
||||
{ /* sentinel */ }
|
||||
};
|
||||
|
||||
static void tcphy_cfg_24m(struct rockchip_typec_phy *tcphy)
|
||||
{
|
||||
u32 i, rdata;
|
||||
@ -691,7 +730,7 @@ static void tcphy_dp_aux_calibration(struct rockchip_typec_phy *tcphy)
|
||||
|
||||
static int tcphy_phy_init(struct rockchip_typec_phy *tcphy, u8 mode)
|
||||
{
|
||||
struct rockchip_usb3phy_port_cfg *cfg = &tcphy->port_cfgs;
|
||||
const struct rockchip_usb3phy_port_cfg *cfg = tcphy->port_cfgs;
|
||||
int ret, i;
|
||||
u32 val;
|
||||
|
||||
@ -782,6 +821,9 @@ static int tcphy_get_mode(struct rockchip_typec_phy *tcphy)
|
||||
u8 mode;
|
||||
int ret;
|
||||
|
||||
if (!edev)
|
||||
return MODE_DFP_USB;
|
||||
|
||||
ufp = extcon_get_state(edev, EXTCON_USB);
|
||||
dp = extcon_get_state(edev, EXTCON_DISP_DP);
|
||||
|
||||
@ -818,10 +860,22 @@ static int tcphy_get_mode(struct rockchip_typec_phy *tcphy)
|
||||
return mode;
|
||||
}
|
||||
|
||||
static int tcphy_cfg_usb3_to_usb2_only(struct rockchip_typec_phy *tcphy,
|
||||
bool value)
|
||||
{
|
||||
const struct rockchip_usb3phy_port_cfg *cfg = tcphy->port_cfgs;
|
||||
|
||||
property_enable(tcphy, &cfg->usb3tousb2_en, value);
|
||||
property_enable(tcphy, &cfg->usb3_host_disable, value);
|
||||
property_enable(tcphy, &cfg->usb3_host_port, !value);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rockchip_usb3_phy_power_on(struct phy *phy)
|
||||
{
|
||||
struct rockchip_typec_phy *tcphy = phy_get_drvdata(phy);
|
||||
struct rockchip_usb3phy_port_cfg *cfg = &tcphy->port_cfgs;
|
||||
const struct rockchip_usb3phy_port_cfg *cfg = tcphy->port_cfgs;
|
||||
const struct usb3phy_reg *reg = &cfg->pipe_status;
|
||||
int timeout, new_mode, ret = 0;
|
||||
u32 val;
|
||||
@ -835,8 +889,10 @@ static int rockchip_usb3_phy_power_on(struct phy *phy)
|
||||
}
|
||||
|
||||
/* DP-only mode; fall back to USB2 */
|
||||
if (!(new_mode & (MODE_DFP_USB | MODE_UFP_USB)))
|
||||
if (!(new_mode & (MODE_DFP_USB | MODE_UFP_USB))) {
|
||||
tcphy_cfg_usb3_to_usb2_only(tcphy, true);
|
||||
goto unlock_ret;
|
||||
}
|
||||
|
||||
if (tcphy->mode == new_mode)
|
||||
goto unlock_ret;
|
||||
@ -852,6 +908,9 @@ static int rockchip_usb3_phy_power_on(struct phy *phy)
|
||||
regmap_read(tcphy->grf_regs, reg->offset, &val);
|
||||
if (!(val & BIT(reg->enable_bit))) {
|
||||
tcphy->mode |= new_mode & (MODE_DFP_USB | MODE_UFP_USB);
|
||||
|
||||
/* enable usb3 host */
|
||||
tcphy_cfg_usb3_to_usb2_only(tcphy, false);
|
||||
goto unlock_ret;
|
||||
}
|
||||
usleep_range(10, 20);
|
||||
@ -872,6 +931,7 @@ static int rockchip_usb3_phy_power_off(struct phy *phy)
|
||||
struct rockchip_typec_phy *tcphy = phy_get_drvdata(phy);
|
||||
|
||||
mutex_lock(&tcphy->lock);
|
||||
tcphy_cfg_usb3_to_usb2_only(tcphy, false);
|
||||
|
||||
if (tcphy->mode == MODE_DISCONNECT)
|
||||
goto unlock;
|
||||
@ -894,6 +954,7 @@ static const struct phy_ops rockchip_usb3_phy_ops = {
|
||||
static int rockchip_dp_phy_power_on(struct phy *phy)
|
||||
{
|
||||
struct rockchip_typec_phy *tcphy = phy_get_drvdata(phy);
|
||||
const struct rockchip_usb3phy_port_cfg *cfg = tcphy->port_cfgs;
|
||||
int new_mode, ret = 0;
|
||||
u32 val;
|
||||
|
||||
@ -926,6 +987,8 @@ static int rockchip_dp_phy_power_on(struct phy *phy)
|
||||
if (ret)
|
||||
goto unlock_ret;
|
||||
|
||||
property_enable(tcphy, &cfg->uphy_dp_sel, 1);
|
||||
|
||||
ret = readx_poll_timeout(readl, tcphy->base + DP_MODE_CTL,
|
||||
val, val & DP_MODE_A2, 1000,
|
||||
PHY_MODE_SET_TIMEOUT);
|
||||
@ -984,51 +1047,9 @@ static const struct phy_ops rockchip_dp_phy_ops = {
|
||||
.owner = THIS_MODULE,
|
||||
};
|
||||
|
||||
static int tcphy_get_param(struct device *dev,
|
||||
struct usb3phy_reg *reg,
|
||||
const char *name)
|
||||
{
|
||||
u32 buffer[3];
|
||||
int ret;
|
||||
|
||||
ret = of_property_read_u32_array(dev->of_node, name, buffer, 3);
|
||||
if (ret) {
|
||||
dev_err(dev, "Can not parse %s\n", name);
|
||||
return ret;
|
||||
}
|
||||
|
||||
reg->offset = buffer[0];
|
||||
reg->enable_bit = buffer[1];
|
||||
reg->write_enable = buffer[2];
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tcphy_parse_dt(struct rockchip_typec_phy *tcphy,
|
||||
struct device *dev)
|
||||
{
|
||||
struct rockchip_usb3phy_port_cfg *cfg = &tcphy->port_cfgs;
|
||||
int ret;
|
||||
|
||||
ret = tcphy_get_param(dev, &cfg->typec_conn_dir,
|
||||
"rockchip,typec-conn-dir");
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
ret = tcphy_get_param(dev, &cfg->usb3tousb2_en,
|
||||
"rockchip,usb3tousb2-en");
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
ret = tcphy_get_param(dev, &cfg->external_psm,
|
||||
"rockchip,external-psm");
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
ret = tcphy_get_param(dev, &cfg->pipe_status,
|
||||
"rockchip,pipe-status");
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
tcphy->grf_regs = syscon_regmap_lookup_by_phandle(dev->of_node,
|
||||
"rockchip,grf");
|
||||
if (IS_ERR(tcphy->grf_regs)) {
|
||||
@ -1071,7 +1092,7 @@ static int tcphy_parse_dt(struct rockchip_typec_phy *tcphy,
|
||||
|
||||
static void typec_phy_pre_init(struct rockchip_typec_phy *tcphy)
|
||||
{
|
||||
struct rockchip_usb3phy_port_cfg *cfg = &tcphy->port_cfgs;
|
||||
const struct rockchip_usb3phy_port_cfg *cfg = tcphy->port_cfgs;
|
||||
|
||||
reset_control_assert(tcphy->tcphy_rst);
|
||||
reset_control_assert(tcphy->uphy_rst);
|
||||
@ -1092,17 +1113,43 @@ static int rockchip_typec_phy_probe(struct platform_device *pdev)
|
||||
struct rockchip_typec_phy *tcphy;
|
||||
struct phy_provider *phy_provider;
|
||||
struct resource *res;
|
||||
int ret;
|
||||
const struct rockchip_usb3phy_port_cfg *phy_cfgs;
|
||||
const struct of_device_id *match;
|
||||
int index, ret;
|
||||
|
||||
tcphy = devm_kzalloc(dev, sizeof(*tcphy), GFP_KERNEL);
|
||||
if (!tcphy)
|
||||
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;
|
||||
}
|
||||
|
||||
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
||||
tcphy->base = devm_ioremap_resource(dev, res);
|
||||
if (IS_ERR(tcphy->base))
|
||||
return PTR_ERR(tcphy->base);
|
||||
|
||||
phy_cfgs = match->data;
|
||||
/* find out a proper config which can be matched with dt. */
|
||||
index = 0;
|
||||
while (phy_cfgs[index].reg) {
|
||||
if (phy_cfgs[index].reg == res->start) {
|
||||
tcphy->port_cfgs = &phy_cfgs[index];
|
||||
break;
|
||||
}
|
||||
|
||||
++index;
|
||||
}
|
||||
|
||||
if (!tcphy->port_cfgs) {
|
||||
dev_err(dev, "no phy-config can be matched with %s node\n",
|
||||
np->name);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ret = tcphy_parse_dt(tcphy, dev);
|
||||
if (ret)
|
||||
return ret;
|
||||
@ -1115,9 +1162,13 @@ static int rockchip_typec_phy_probe(struct platform_device *pdev)
|
||||
|
||||
tcphy->extcon = extcon_get_edev_by_phandle(dev, 0);
|
||||
if (IS_ERR(tcphy->extcon)) {
|
||||
if (PTR_ERR(tcphy->extcon) != -EPROBE_DEFER)
|
||||
dev_err(dev, "Invalid or missing extcon\n");
|
||||
return PTR_ERR(tcphy->extcon);
|
||||
if (PTR_ERR(tcphy->extcon) == -ENODEV) {
|
||||
tcphy->extcon = NULL;
|
||||
} else {
|
||||
if (PTR_ERR(tcphy->extcon) != -EPROBE_DEFER)
|
||||
dev_err(dev, "Invalid or missing extcon\n");
|
||||
return PTR_ERR(tcphy->extcon);
|
||||
}
|
||||
}
|
||||
|
||||
pm_runtime_enable(dev);
|
||||
@ -1162,8 +1213,11 @@ static int rockchip_typec_phy_remove(struct platform_device *pdev)
|
||||
}
|
||||
|
||||
static const struct of_device_id rockchip_typec_phy_dt_ids[] = {
|
||||
{ .compatible = "rockchip,rk3399-typec-phy" },
|
||||
{}
|
||||
{
|
||||
.compatible = "rockchip,rk3399-typec-phy",
|
||||
.data = &rk3399_usb3phy_port_cfgs
|
||||
},
|
||||
{ /* sentinel */ }
|
||||
};
|
||||
|
||||
MODULE_DEVICE_TABLE(of, rockchip_typec_phy_dt_ids);
|
||||
|
@ -49,7 +49,7 @@ config PHY_EXYNOS4210_USB2
|
||||
config PHY_EXYNOS4X12_USB2
|
||||
bool
|
||||
depends on PHY_SAMSUNG_USB2
|
||||
default SOC_EXYNOS3250 || SOC_EXYNOS4212 || SOC_EXYNOS4412
|
||||
default SOC_EXYNOS3250 || SOC_EXYNOS4412
|
||||
|
||||
config PHY_EXYNOS5250_USB2
|
||||
bool
|
||||
|
@ -31,3 +31,17 @@ config PHY_STIH407_USB
|
||||
help
|
||||
Enable this support to enable the picoPHY device used by USB2
|
||||
and USB3 controllers on STMicroelectronics STiH407 SoC families.
|
||||
|
||||
config PHY_STM32_USBPHYC
|
||||
tristate "STMicroelectronics STM32 USB HS PHY Controller driver"
|
||||
depends on ARCH_STM32 || COMPILE_TEST
|
||||
select GENERIC_PHY
|
||||
help
|
||||
Enable this to support the High-Speed USB transceivers that are part
|
||||
of some STMicroelectronics STM32 SoCs.
|
||||
|
||||
This driver controls the entire USB PHY block: the USB PHY controller
|
||||
(USBPHYC) and the two 8-bit wide UTMI+ interfaces. First interface is
|
||||
used by an HS USB Host controller, and the second one is shared
|
||||
between an HS USB OTG controller and an HS USB Host controller,
|
||||
selected by a USB switch.
|
||||
|
@ -2,3 +2,4 @@ obj-$(CONFIG_PHY_MIPHY28LP) += phy-miphy28lp.o
|
||||
obj-$(CONFIG_PHY_ST_SPEAR1310_MIPHY) += phy-spear1310-miphy.o
|
||||
obj-$(CONFIG_PHY_ST_SPEAR1340_MIPHY) += phy-spear1340-miphy.o
|
||||
obj-$(CONFIG_PHY_STIH407_USB) += phy-stih407-usb.o
|
||||
obj-$(CONFIG_PHY_STM32_USBPHYC) += phy-stm32-usbphyc.o
|
||||
|
461
drivers/phy/st/phy-stm32-usbphyc.c
Normal file
461
drivers/phy/st/phy-stm32-usbphyc.c
Normal file
@ -0,0 +1,461 @@
|
||||
// SPDX-Licence-Identifier: GPL-2.0
|
||||
/*
|
||||
* STMicroelectronics STM32 USB PHY Controller driver
|
||||
*
|
||||
* Copyright (C) 2018 STMicroelectronics
|
||||
* Author(s): Amelie Delaunay <amelie.delaunay@st.com>.
|
||||
*/
|
||||
#include <linux/bitfield.h>
|
||||
#include <linux/clk.h>
|
||||
#include <linux/delay.h>
|
||||
#include <linux/io.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/of_platform.h>
|
||||
#include <linux/phy/phy.h>
|
||||
#include <linux/reset.h>
|
||||
|
||||
#define STM32_USBPHYC_PLL 0x0
|
||||
#define STM32_USBPHYC_MISC 0x8
|
||||
#define STM32_USBPHYC_VERSION 0x3F4
|
||||
|
||||
/* STM32_USBPHYC_PLL bit fields */
|
||||
#define PLLNDIV GENMASK(6, 0)
|
||||
#define PLLFRACIN GENMASK(25, 10)
|
||||
#define PLLEN BIT(26)
|
||||
#define PLLSTRB BIT(27)
|
||||
#define PLLSTRBYP BIT(28)
|
||||
#define PLLFRACCTL BIT(29)
|
||||
#define PLLDITHEN0 BIT(30)
|
||||
#define PLLDITHEN1 BIT(31)
|
||||
|
||||
/* STM32_USBPHYC_MISC bit fields */
|
||||
#define SWITHOST BIT(0)
|
||||
|
||||
/* STM32_USBPHYC_VERSION bit fields */
|
||||
#define MINREV GENMASK(3, 0)
|
||||
#define MAJREV GENMASK(7, 4)
|
||||
|
||||
static const char * const supplies_names[] = {
|
||||
"vdda1v1", /* 1V1 */
|
||||
"vdda1v8", /* 1V8 */
|
||||
};
|
||||
|
||||
#define NUM_SUPPLIES ARRAY_SIZE(supplies_names)
|
||||
|
||||
#define PLL_LOCK_TIME_US 100
|
||||
#define PLL_PWR_DOWN_TIME_US 5
|
||||
#define PLL_FVCO_MHZ 2880
|
||||
#define PLL_INFF_MIN_RATE_HZ 19200000
|
||||
#define PLL_INFF_MAX_RATE_HZ 38400000
|
||||
#define HZ_PER_MHZ 1000000L
|
||||
|
||||
struct pll_params {
|
||||
u8 ndiv;
|
||||
u16 frac;
|
||||
};
|
||||
|
||||
struct stm32_usbphyc_phy {
|
||||
struct phy *phy;
|
||||
struct stm32_usbphyc *usbphyc;
|
||||
struct regulator_bulk_data supplies[NUM_SUPPLIES];
|
||||
u32 index;
|
||||
bool active;
|
||||
};
|
||||
|
||||
struct stm32_usbphyc {
|
||||
struct device *dev;
|
||||
void __iomem *base;
|
||||
struct clk *clk;
|
||||
struct reset_control *rst;
|
||||
struct stm32_usbphyc_phy **phys;
|
||||
int nphys;
|
||||
int switch_setup;
|
||||
bool pll_enabled;
|
||||
};
|
||||
|
||||
static inline void stm32_usbphyc_set_bits(void __iomem *reg, u32 bits)
|
||||
{
|
||||
writel_relaxed(readl_relaxed(reg) | bits, reg);
|
||||
}
|
||||
|
||||
static inline void stm32_usbphyc_clr_bits(void __iomem *reg, u32 bits)
|
||||
{
|
||||
writel_relaxed(readl_relaxed(reg) & ~bits, reg);
|
||||
}
|
||||
|
||||
static void stm32_usbphyc_get_pll_params(u32 clk_rate, struct pll_params *pll_params)
|
||||
{
|
||||
unsigned long long fvco, ndiv, frac;
|
||||
|
||||
/* _
|
||||
* | FVCO = INFF*2*(NDIV + FRACT/2^16) when DITHER_DISABLE[1] = 1
|
||||
* | FVCO = 2880MHz
|
||||
* <
|
||||
* | NDIV = integer part of input bits to set the LDF
|
||||
* |_FRACT = fractional part of input bits to set the LDF
|
||||
* => PLLNDIV = integer part of (FVCO / (INFF*2))
|
||||
* => PLLFRACIN = fractional part of(FVCO / INFF*2) * 2^16
|
||||
* <=> PLLFRACIN = ((FVCO / (INFF*2)) - PLLNDIV) * 2^16
|
||||
*/
|
||||
fvco = (unsigned long long)PLL_FVCO_MHZ * HZ_PER_MHZ;
|
||||
|
||||
ndiv = fvco;
|
||||
do_div(ndiv, (clk_rate * 2));
|
||||
pll_params->ndiv = (u8)ndiv;
|
||||
|
||||
frac = fvco * (1 << 16);
|
||||
do_div(frac, (clk_rate * 2));
|
||||
frac = frac - (ndiv * (1 << 16));
|
||||
pll_params->frac = (u16)frac;
|
||||
}
|
||||
|
||||
static int stm32_usbphyc_pll_init(struct stm32_usbphyc *usbphyc)
|
||||
{
|
||||
struct pll_params pll_params;
|
||||
u32 clk_rate = clk_get_rate(usbphyc->clk);
|
||||
u32 ndiv, frac;
|
||||
u32 usbphyc_pll;
|
||||
|
||||
if ((clk_rate < PLL_INFF_MIN_RATE_HZ) ||
|
||||
(clk_rate > PLL_INFF_MAX_RATE_HZ)) {
|
||||
dev_err(usbphyc->dev, "input clk freq (%dHz) out of range\n",
|
||||
clk_rate);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
stm32_usbphyc_get_pll_params(clk_rate, &pll_params);
|
||||
ndiv = FIELD_PREP(PLLNDIV, pll_params.ndiv);
|
||||
frac = FIELD_PREP(PLLFRACIN, pll_params.frac);
|
||||
|
||||
usbphyc_pll = PLLDITHEN1 | PLLDITHEN0 | PLLSTRBYP | ndiv;
|
||||
|
||||
if (pll_params.frac)
|
||||
usbphyc_pll |= PLLFRACCTL | frac;
|
||||
|
||||
writel_relaxed(usbphyc_pll, usbphyc->base + STM32_USBPHYC_PLL);
|
||||
|
||||
dev_dbg(usbphyc->dev, "input clk freq=%dHz, ndiv=%lu, frac=%lu\n",
|
||||
clk_rate, FIELD_GET(PLLNDIV, usbphyc_pll),
|
||||
FIELD_GET(PLLFRACIN, usbphyc_pll));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static bool stm32_usbphyc_has_one_phy_active(struct stm32_usbphyc *usbphyc)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < usbphyc->nphys; i++)
|
||||
if (usbphyc->phys[i]->active)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static int stm32_usbphyc_pll_enable(struct stm32_usbphyc *usbphyc)
|
||||
{
|
||||
void __iomem *pll_reg = usbphyc->base + STM32_USBPHYC_PLL;
|
||||
bool pllen = (readl_relaxed(pll_reg) & PLLEN);
|
||||
int ret;
|
||||
|
||||
/* Check if one phy port has already configured the pll */
|
||||
if (pllen && stm32_usbphyc_has_one_phy_active(usbphyc))
|
||||
return 0;
|
||||
|
||||
if (pllen) {
|
||||
stm32_usbphyc_clr_bits(pll_reg, PLLEN);
|
||||
/* Wait for minimum width of powerdown pulse (ENABLE = Low) */
|
||||
udelay(PLL_PWR_DOWN_TIME_US);
|
||||
}
|
||||
|
||||
ret = stm32_usbphyc_pll_init(usbphyc);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
stm32_usbphyc_set_bits(pll_reg, PLLEN);
|
||||
|
||||
/* Wait for maximum lock time */
|
||||
udelay(PLL_LOCK_TIME_US);
|
||||
|
||||
if (!(readl_relaxed(pll_reg) & PLLEN)) {
|
||||
dev_err(usbphyc->dev, "PLLEN not set\n");
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int stm32_usbphyc_pll_disable(struct stm32_usbphyc *usbphyc)
|
||||
{
|
||||
void __iomem *pll_reg = usbphyc->base + STM32_USBPHYC_PLL;
|
||||
|
||||
/* Check if other phy port active */
|
||||
if (stm32_usbphyc_has_one_phy_active(usbphyc))
|
||||
return 0;
|
||||
|
||||
stm32_usbphyc_clr_bits(pll_reg, PLLEN);
|
||||
/* Wait for minimum width of powerdown pulse (ENABLE = Low) */
|
||||
udelay(PLL_PWR_DOWN_TIME_US);
|
||||
|
||||
if (readl_relaxed(pll_reg) & PLLEN) {
|
||||
dev_err(usbphyc->dev, "PLL not reset\n");
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int stm32_usbphyc_phy_init(struct phy *phy)
|
||||
{
|
||||
struct stm32_usbphyc_phy *usbphyc_phy = phy_get_drvdata(phy);
|
||||
struct stm32_usbphyc *usbphyc = usbphyc_phy->usbphyc;
|
||||
int ret;
|
||||
|
||||
ret = stm32_usbphyc_pll_enable(usbphyc);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
usbphyc_phy->active = true;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int stm32_usbphyc_phy_exit(struct phy *phy)
|
||||
{
|
||||
struct stm32_usbphyc_phy *usbphyc_phy = phy_get_drvdata(phy);
|
||||
struct stm32_usbphyc *usbphyc = usbphyc_phy->usbphyc;
|
||||
|
||||
usbphyc_phy->active = false;
|
||||
|
||||
return stm32_usbphyc_pll_disable(usbphyc);
|
||||
}
|
||||
|
||||
static int stm32_usbphyc_phy_power_on(struct phy *phy)
|
||||
{
|
||||
struct stm32_usbphyc_phy *usbphyc_phy = phy_get_drvdata(phy);
|
||||
|
||||
return regulator_bulk_enable(NUM_SUPPLIES, usbphyc_phy->supplies);
|
||||
}
|
||||
|
||||
static int stm32_usbphyc_phy_power_off(struct phy *phy)
|
||||
{
|
||||
struct stm32_usbphyc_phy *usbphyc_phy = phy_get_drvdata(phy);
|
||||
|
||||
return regulator_bulk_disable(NUM_SUPPLIES, usbphyc_phy->supplies);
|
||||
}
|
||||
|
||||
static const struct phy_ops stm32_usbphyc_phy_ops = {
|
||||
.init = stm32_usbphyc_phy_init,
|
||||
.exit = stm32_usbphyc_phy_exit,
|
||||
.power_on = stm32_usbphyc_phy_power_on,
|
||||
.power_off = stm32_usbphyc_phy_power_off,
|
||||
.owner = THIS_MODULE,
|
||||
};
|
||||
|
||||
static void stm32_usbphyc_switch_setup(struct stm32_usbphyc *usbphyc,
|
||||
u32 utmi_switch)
|
||||
{
|
||||
if (!utmi_switch)
|
||||
stm32_usbphyc_clr_bits(usbphyc->base + STM32_USBPHYC_MISC,
|
||||
SWITHOST);
|
||||
else
|
||||
stm32_usbphyc_set_bits(usbphyc->base + STM32_USBPHYC_MISC,
|
||||
SWITHOST);
|
||||
usbphyc->switch_setup = utmi_switch;
|
||||
}
|
||||
|
||||
static struct phy *stm32_usbphyc_of_xlate(struct device *dev,
|
||||
struct of_phandle_args *args)
|
||||
{
|
||||
struct stm32_usbphyc *usbphyc = dev_get_drvdata(dev);
|
||||
struct stm32_usbphyc_phy *usbphyc_phy = NULL;
|
||||
struct device_node *phynode = args->np;
|
||||
|
||||
int port = 0;
|
||||
|
||||
for (port = 0; port < usbphyc->nphys; port++) {
|
||||
if (phynode == usbphyc->phys[port]->phy->dev.of_node) {
|
||||
usbphyc_phy = usbphyc->phys[port];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!usbphyc_phy) {
|
||||
dev_err(dev, "failed to find phy\n");
|
||||
return ERR_PTR(-EINVAL);
|
||||
}
|
||||
|
||||
if (((usbphyc_phy->index == 0) && (args->args_count != 0)) ||
|
||||
((usbphyc_phy->index == 1) && (args->args_count != 1))) {
|
||||
dev_err(dev, "invalid number of cells for phy port%d\n",
|
||||
usbphyc_phy->index);
|
||||
return ERR_PTR(-EINVAL);
|
||||
}
|
||||
|
||||
/* Configure the UTMI switch for PHY port#2 */
|
||||
if (usbphyc_phy->index == 1) {
|
||||
if (usbphyc->switch_setup < 0) {
|
||||
stm32_usbphyc_switch_setup(usbphyc, args->args[0]);
|
||||
} else {
|
||||
if (args->args[0] != usbphyc->switch_setup) {
|
||||
dev_err(dev, "phy port1 already used\n");
|
||||
return ERR_PTR(-EBUSY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return usbphyc_phy->phy;
|
||||
}
|
||||
|
||||
static int stm32_usbphyc_probe(struct platform_device *pdev)
|
||||
{
|
||||
struct stm32_usbphyc *usbphyc;
|
||||
struct device *dev = &pdev->dev;
|
||||
struct device_node *child, *np = dev->of_node;
|
||||
struct resource *res;
|
||||
struct phy_provider *phy_provider;
|
||||
u32 version;
|
||||
int ret, port = 0;
|
||||
|
||||
usbphyc = devm_kzalloc(dev, sizeof(*usbphyc), GFP_KERNEL);
|
||||
if (!usbphyc)
|
||||
return -ENOMEM;
|
||||
usbphyc->dev = dev;
|
||||
dev_set_drvdata(dev, usbphyc);
|
||||
|
||||
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
||||
usbphyc->base = devm_ioremap_resource(dev, res);
|
||||
if (IS_ERR(usbphyc->base))
|
||||
return PTR_ERR(usbphyc->base);
|
||||
|
||||
usbphyc->clk = devm_clk_get(dev, 0);
|
||||
if (IS_ERR(usbphyc->clk)) {
|
||||
ret = PTR_ERR(usbphyc->clk);
|
||||
dev_err(dev, "clk get failed: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = clk_prepare_enable(usbphyc->clk);
|
||||
if (ret) {
|
||||
dev_err(dev, "clk enable failed: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
usbphyc->rst = devm_reset_control_get(dev, 0);
|
||||
if (!IS_ERR(usbphyc->rst)) {
|
||||
reset_control_assert(usbphyc->rst);
|
||||
udelay(2);
|
||||
reset_control_deassert(usbphyc->rst);
|
||||
}
|
||||
|
||||
usbphyc->switch_setup = -EINVAL;
|
||||
usbphyc->nphys = of_get_child_count(np);
|
||||
usbphyc->phys = devm_kcalloc(dev, usbphyc->nphys,
|
||||
sizeof(*usbphyc->phys), GFP_KERNEL);
|
||||
if (!usbphyc->phys) {
|
||||
ret = -ENOMEM;
|
||||
goto clk_disable;
|
||||
}
|
||||
|
||||
for_each_child_of_node(np, child) {
|
||||
struct stm32_usbphyc_phy *usbphyc_phy;
|
||||
struct phy *phy;
|
||||
u32 index;
|
||||
int i;
|
||||
|
||||
phy = devm_phy_create(dev, child, &stm32_usbphyc_phy_ops);
|
||||
if (IS_ERR(phy)) {
|
||||
ret = PTR_ERR(phy);
|
||||
if (ret != -EPROBE_DEFER)
|
||||
dev_err(dev,
|
||||
"failed to create phy%d: %d\n", i, ret);
|
||||
goto put_child;
|
||||
}
|
||||
|
||||
usbphyc_phy = devm_kzalloc(dev, sizeof(*usbphyc_phy),
|
||||
GFP_KERNEL);
|
||||
if (!usbphyc_phy) {
|
||||
ret = -ENOMEM;
|
||||
goto put_child;
|
||||
}
|
||||
|
||||
for (i = 0; i < NUM_SUPPLIES; i++)
|
||||
usbphyc_phy->supplies[i].supply = supplies_names[i];
|
||||
|
||||
ret = devm_regulator_bulk_get(&phy->dev, NUM_SUPPLIES,
|
||||
usbphyc_phy->supplies);
|
||||
if (ret) {
|
||||
if (ret != -EPROBE_DEFER)
|
||||
dev_err(&phy->dev,
|
||||
"failed to get regulators: %d\n", ret);
|
||||
goto put_child;
|
||||
}
|
||||
|
||||
ret = of_property_read_u32(child, "reg", &index);
|
||||
if (ret || index > usbphyc->nphys) {
|
||||
dev_err(&phy->dev, "invalid reg property: %d\n", ret);
|
||||
goto put_child;
|
||||
}
|
||||
|
||||
usbphyc->phys[port] = usbphyc_phy;
|
||||
phy_set_bus_width(phy, 8);
|
||||
phy_set_drvdata(phy, usbphyc_phy);
|
||||
|
||||
usbphyc->phys[port]->phy = phy;
|
||||
usbphyc->phys[port]->usbphyc = usbphyc;
|
||||
usbphyc->phys[port]->index = index;
|
||||
usbphyc->phys[port]->active = false;
|
||||
|
||||
port++;
|
||||
}
|
||||
|
||||
phy_provider = devm_of_phy_provider_register(dev,
|
||||
stm32_usbphyc_of_xlate);
|
||||
if (IS_ERR(phy_provider)) {
|
||||
ret = PTR_ERR(phy_provider);
|
||||
dev_err(dev, "failed to register phy provider: %d\n", ret);
|
||||
goto clk_disable;
|
||||
}
|
||||
|
||||
version = readl_relaxed(usbphyc->base + STM32_USBPHYC_VERSION);
|
||||
dev_info(dev, "registered rev:%lu.%lu\n",
|
||||
FIELD_GET(MAJREV, version), FIELD_GET(MINREV, version));
|
||||
|
||||
return 0;
|
||||
|
||||
put_child:
|
||||
of_node_put(child);
|
||||
clk_disable:
|
||||
clk_disable_unprepare(usbphyc->clk);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int stm32_usbphyc_remove(struct platform_device *pdev)
|
||||
{
|
||||
struct stm32_usbphyc *usbphyc = dev_get_drvdata(&pdev->dev);
|
||||
|
||||
clk_disable_unprepare(usbphyc->clk);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct of_device_id stm32_usbphyc_of_match[] = {
|
||||
{ .compatible = "st,stm32mp1-usbphyc", },
|
||||
{ },
|
||||
};
|
||||
MODULE_DEVICE_TABLE(of, stm32_usbphyc_of_match);
|
||||
|
||||
static struct platform_driver stm32_usbphyc_driver = {
|
||||
.probe = stm32_usbphyc_probe,
|
||||
.remove = stm32_usbphyc_remove,
|
||||
.driver = {
|
||||
.of_match_table = stm32_usbphyc_of_match,
|
||||
.name = "stm32-usbphyc",
|
||||
}
|
||||
};
|
||||
module_platform_driver(stm32_usbphyc_driver);
|
||||
|
||||
MODULE_DESCRIPTION("STMicroelectronics STM32 USBPHYC driver");
|
||||
MODULE_AUTHOR("Amelie Delaunay <amelie.delaunay@st.com>");
|
||||
MODULE_LICENSE("GPL v2");
|
@ -169,6 +169,7 @@
|
||||
#define XUSB_PADCTL_UPHY_PLL_CTL2_CAL_EN (1 << 0)
|
||||
|
||||
#define XUSB_PADCTL_UPHY_PLL_P0_CTL4 0x36c
|
||||
#define XUSB_PADCTL_UPHY_PLL_CTL4_XDIGCLK_EN (1 << 19)
|
||||
#define XUSB_PADCTL_UPHY_PLL_CTL4_TXCLKREF_EN (1 << 15)
|
||||
#define XUSB_PADCTL_UPHY_PLL_CTL4_TXCLKREF_SEL_SHIFT 12
|
||||
#define XUSB_PADCTL_UPHY_PLL_CTL4_TXCLKREF_SEL_MASK 0x3
|
||||
@ -537,11 +538,8 @@ static int tegra210_sata_uphy_enable(struct tegra_xusb_padctl *padctl, bool usb)
|
||||
value |= (XUSB_PADCTL_UPHY_PLL_CTL4_TXCLKREF_SEL_SATA_VAL <<
|
||||
XUSB_PADCTL_UPHY_PLL_CTL4_TXCLKREF_SEL_SHIFT);
|
||||
|
||||
/* XXX PLL0_XDIGCLK_EN */
|
||||
/*
|
||||
value &= ~(1 << 19);
|
||||
value &= ~XUSB_PADCTL_UPHY_PLL_CTL4_XDIGCLK_EN;
|
||||
padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_S0_CTL4);
|
||||
*/
|
||||
|
||||
value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_S0_CTL1);
|
||||
value &= ~((XUSB_PADCTL_UPHY_PLL_CTL1_FREQ_MDIV_MASK <<
|
||||
|
@ -418,7 +418,7 @@ tegra_xusb_port_find_lane(struct tegra_xusb_port *port,
|
||||
{
|
||||
struct tegra_xusb_lane *lane, *match = ERR_PTR(-ENODEV);
|
||||
|
||||
for (map = map; map->type; map++) {
|
||||
for (; map->type; map++) {
|
||||
if (port->index != map->port)
|
||||
continue;
|
||||
|
||||
|
@ -33,6 +33,8 @@ struct cht_int33fe_data {
|
||||
struct i2c_client *max17047;
|
||||
struct i2c_client *fusb302;
|
||||
struct i2c_client *pi3usb30532;
|
||||
/* Contain a list-head must be per device */
|
||||
struct device_connection connections[3];
|
||||
};
|
||||
|
||||
/*
|
||||
@ -172,6 +174,20 @@ static int cht_int33fe_probe(struct i2c_client *client)
|
||||
return -EPROBE_DEFER; /* Wait for i2c-adapter to load */
|
||||
}
|
||||
|
||||
data->connections[0].endpoint[0] = "i2c-fusb302";
|
||||
data->connections[0].endpoint[1] = "i2c-pi3usb30532";
|
||||
data->connections[0].id = "typec-switch";
|
||||
data->connections[1].endpoint[0] = "i2c-fusb302";
|
||||
data->connections[1].endpoint[1] = "i2c-pi3usb30532";
|
||||
data->connections[1].id = "typec-mux";
|
||||
data->connections[2].endpoint[0] = "i2c-fusb302";
|
||||
data->connections[2].endpoint[1] = "intel_xhci_usb_sw-role-switch";
|
||||
data->connections[2].id = "usb-role-switch";
|
||||
|
||||
device_connection_add(&data->connections[0]);
|
||||
device_connection_add(&data->connections[1]);
|
||||
device_connection_add(&data->connections[2]);
|
||||
|
||||
memset(&board_info, 0, sizeof(board_info));
|
||||
strlcpy(board_info.type, "typec_fusb302", I2C_NAME_SIZE);
|
||||
board_info.dev_name = "fusb302";
|
||||
@ -201,6 +217,10 @@ out_unregister_max17047:
|
||||
if (data->max17047)
|
||||
i2c_unregister_device(data->max17047);
|
||||
|
||||
device_connection_remove(&data->connections[2]);
|
||||
device_connection_remove(&data->connections[1]);
|
||||
device_connection_remove(&data->connections[0]);
|
||||
|
||||
return -EPROBE_DEFER; /* Wait for the i2c-adapter to load */
|
||||
}
|
||||
|
||||
@ -213,6 +233,10 @@ static int cht_int33fe_remove(struct i2c_client *i2c)
|
||||
if (data->max17047)
|
||||
i2c_unregister_device(data->max17047);
|
||||
|
||||
device_connection_remove(&data->connections[2]);
|
||||
device_connection_remove(&data->connections[1]);
|
||||
device_connection_remove(&data->connections[0]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,6 @@
|
||||
|
||||
struct tcpci {
|
||||
struct device *dev;
|
||||
struct i2c_client *client;
|
||||
|
||||
struct tcpm_port *port;
|
||||
|
||||
@ -30,6 +29,12 @@ struct tcpci {
|
||||
bool controls_vbus;
|
||||
|
||||
struct tcpc_dev tcpc;
|
||||
struct tcpci_data *data;
|
||||
};
|
||||
|
||||
struct tcpci_chip {
|
||||
struct tcpci *tcpci;
|
||||
struct tcpci_data data;
|
||||
};
|
||||
|
||||
static inline struct tcpci *tcpc_to_tcpci(struct tcpc_dev *tcpc)
|
||||
@ -37,8 +42,7 @@ static inline struct tcpci *tcpc_to_tcpci(struct tcpc_dev *tcpc)
|
||||
return container_of(tcpc, struct tcpci, tcpc);
|
||||
}
|
||||
|
||||
static int tcpci_read16(struct tcpci *tcpci, unsigned int reg,
|
||||
u16 *val)
|
||||
static int tcpci_read16(struct tcpci *tcpci, unsigned int reg, u16 *val)
|
||||
{
|
||||
return regmap_raw_read(tcpci->regmap, reg, val, sizeof(u16));
|
||||
}
|
||||
@ -98,9 +102,17 @@ static int tcpci_set_cc(struct tcpc_dev *tcpc, enum typec_cc_status cc)
|
||||
static int tcpci_start_drp_toggling(struct tcpc_dev *tcpc,
|
||||
enum typec_cc_status cc)
|
||||
{
|
||||
int ret;
|
||||
struct tcpci *tcpci = tcpc_to_tcpci(tcpc);
|
||||
unsigned int reg = TCPC_ROLE_CTRL_DRP;
|
||||
|
||||
/* Handle vendor drp toggling */
|
||||
if (tcpci->data->start_drp_toggling) {
|
||||
ret = tcpci->data->start_drp_toggling(tcpci, tcpci->data, cc);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
}
|
||||
|
||||
switch (cc) {
|
||||
default:
|
||||
case TYPEC_CC_RP_DEF:
|
||||
@ -117,7 +129,17 @@ static int tcpci_start_drp_toggling(struct tcpc_dev *tcpc,
|
||||
break;
|
||||
}
|
||||
|
||||
return regmap_write(tcpci->regmap, TCPC_ROLE_CTRL, reg);
|
||||
if (cc == TYPEC_CC_RD)
|
||||
reg |= (TCPC_ROLE_CTRL_CC_RD << TCPC_ROLE_CTRL_CC1_SHIFT) |
|
||||
(TCPC_ROLE_CTRL_CC_RD << TCPC_ROLE_CTRL_CC2_SHIFT);
|
||||
else
|
||||
reg |= (TCPC_ROLE_CTRL_CC_RP << TCPC_ROLE_CTRL_CC1_SHIFT) |
|
||||
(TCPC_ROLE_CTRL_CC_RP << TCPC_ROLE_CTRL_CC2_SHIFT);
|
||||
ret = regmap_write(tcpci->regmap, TCPC_ROLE_CTRL, reg);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
return regmap_write(tcpci->regmap, TCPC_COMMAND,
|
||||
TCPC_CMD_LOOK4CONNECTION);
|
||||
}
|
||||
|
||||
static enum typec_cc_status tcpci_to_typec_cc(unsigned int cc, bool sink)
|
||||
@ -178,6 +200,13 @@ static int tcpci_set_vconn(struct tcpc_dev *tcpc, bool enable)
|
||||
struct tcpci *tcpci = tcpc_to_tcpci(tcpc);
|
||||
int ret;
|
||||
|
||||
/* Handle vendor set vconn */
|
||||
if (tcpci->data->set_vconn) {
|
||||
ret = tcpci->data->set_vconn(tcpci, tcpci->data, enable);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = regmap_write(tcpci->regmap, TCPC_POWER_CTRL,
|
||||
enable ? TCPC_POWER_CTRL_VCONN_ENABLE : 0);
|
||||
if (ret < 0)
|
||||
@ -323,6 +352,13 @@ static int tcpci_init(struct tcpc_dev *tcpc)
|
||||
if (time_after(jiffies, timeout))
|
||||
return -ETIMEDOUT;
|
||||
|
||||
/* Handle vendor init */
|
||||
if (tcpci->data->init) {
|
||||
ret = tcpci->data->init(tcpci, tcpci->data);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Clear all events */
|
||||
ret = tcpci_write16(tcpci, TCPC_ALERT, 0xffff);
|
||||
if (ret < 0)
|
||||
@ -344,9 +380,8 @@ static int tcpci_init(struct tcpc_dev *tcpc)
|
||||
return tcpci_write16(tcpci, TCPC_ALERT_MASK, reg);
|
||||
}
|
||||
|
||||
static irqreturn_t tcpci_irq(int irq, void *dev_id)
|
||||
irqreturn_t tcpci_irq(struct tcpci *tcpci)
|
||||
{
|
||||
struct tcpci *tcpci = dev_id;
|
||||
u16 status;
|
||||
|
||||
tcpci_read16(tcpci, TCPC_ALERT, &status);
|
||||
@ -412,6 +447,14 @@ static irqreturn_t tcpci_irq(int irq, void *dev_id)
|
||||
|
||||
return IRQ_HANDLED;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(tcpci_irq);
|
||||
|
||||
static irqreturn_t _tcpci_irq(int irq, void *dev_id)
|
||||
{
|
||||
struct tcpci_chip *chip = dev_id;
|
||||
|
||||
return tcpci_irq(chip->tcpci);
|
||||
}
|
||||
|
||||
static const struct regmap_config tcpci_regmap_config = {
|
||||
.reg_bits = 8,
|
||||
@ -435,22 +478,18 @@ static int tcpci_parse_config(struct tcpci *tcpci)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tcpci_probe(struct i2c_client *client,
|
||||
const struct i2c_device_id *i2c_id)
|
||||
struct tcpci *tcpci_register_port(struct device *dev, struct tcpci_data *data)
|
||||
{
|
||||
struct tcpci *tcpci;
|
||||
int err;
|
||||
|
||||
tcpci = devm_kzalloc(&client->dev, sizeof(*tcpci), GFP_KERNEL);
|
||||
tcpci = devm_kzalloc(dev, sizeof(*tcpci), GFP_KERNEL);
|
||||
if (!tcpci)
|
||||
return -ENOMEM;
|
||||
return ERR_PTR(-ENOMEM);
|
||||
|
||||
tcpci->client = client;
|
||||
tcpci->dev = &client->dev;
|
||||
i2c_set_clientdata(client, tcpci);
|
||||
tcpci->regmap = devm_regmap_init_i2c(client, &tcpci_regmap_config);
|
||||
if (IS_ERR(tcpci->regmap))
|
||||
return PTR_ERR(tcpci->regmap);
|
||||
tcpci->dev = dev;
|
||||
tcpci->data = data;
|
||||
tcpci->regmap = data->regmap;
|
||||
|
||||
tcpci->tcpc.init = tcpci_init;
|
||||
tcpci->tcpc.get_vbus = tcpci_get_vbus;
|
||||
@ -467,27 +506,63 @@ static int tcpci_probe(struct i2c_client *client,
|
||||
|
||||
err = tcpci_parse_config(tcpci);
|
||||
if (err < 0)
|
||||
return err;
|
||||
return ERR_PTR(err);
|
||||
|
||||
/* Disable chip interrupts */
|
||||
tcpci_write16(tcpci, TCPC_ALERT_MASK, 0);
|
||||
tcpci->port = tcpm_register_port(tcpci->dev, &tcpci->tcpc);
|
||||
if (PTR_ERR_OR_ZERO(tcpci->port))
|
||||
return ERR_CAST(tcpci->port);
|
||||
|
||||
err = devm_request_threaded_irq(tcpci->dev, client->irq, NULL,
|
||||
tcpci_irq,
|
||||
IRQF_ONESHOT | IRQF_TRIGGER_LOW,
|
||||
dev_name(tcpci->dev), tcpci);
|
||||
return tcpci;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(tcpci_register_port);
|
||||
|
||||
void tcpci_unregister_port(struct tcpci *tcpci)
|
||||
{
|
||||
tcpm_unregister_port(tcpci->port);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(tcpci_unregister_port);
|
||||
|
||||
static int tcpci_probe(struct i2c_client *client,
|
||||
const struct i2c_device_id *i2c_id)
|
||||
{
|
||||
struct tcpci_chip *chip;
|
||||
int err;
|
||||
u16 val = 0;
|
||||
|
||||
chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL);
|
||||
if (!chip)
|
||||
return -ENOMEM;
|
||||
|
||||
chip->data.regmap = devm_regmap_init_i2c(client, &tcpci_regmap_config);
|
||||
if (IS_ERR(chip->data.regmap))
|
||||
return PTR_ERR(chip->data.regmap);
|
||||
|
||||
/* Disable chip interrupts before requesting irq */
|
||||
err = regmap_raw_write(chip->data.regmap, TCPC_ALERT_MASK, &val,
|
||||
sizeof(u16));
|
||||
if (err < 0)
|
||||
return err;
|
||||
|
||||
tcpci->port = tcpm_register_port(tcpci->dev, &tcpci->tcpc);
|
||||
return PTR_ERR_OR_ZERO(tcpci->port);
|
||||
err = devm_request_threaded_irq(&client->dev, client->irq, NULL,
|
||||
_tcpci_irq,
|
||||
IRQF_ONESHOT | IRQF_TRIGGER_LOW,
|
||||
dev_name(&client->dev), chip);
|
||||
if (err < 0)
|
||||
return err;
|
||||
|
||||
chip->tcpci = tcpci_register_port(&client->dev, &chip->data);
|
||||
if (PTR_ERR_OR_ZERO(chip->tcpci))
|
||||
return PTR_ERR(chip->tcpci);
|
||||
|
||||
i2c_set_clientdata(client, chip);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tcpci_remove(struct i2c_client *client)
|
||||
{
|
||||
struct tcpci *tcpci = i2c_get_clientdata(client);
|
||||
struct tcpci_chip *chip = i2c_get_clientdata(client);
|
||||
|
||||
tcpm_unregister_port(tcpci->port);
|
||||
tcpci_unregister_port(chip->tcpci);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -121,4 +121,18 @@
|
||||
#define TCPC_VBUS_VOLTAGE_ALARM_HI_CFG 0x76
|
||||
#define TCPC_VBUS_VOLTAGE_ALARM_LO_CFG 0x78
|
||||
|
||||
struct tcpci;
|
||||
struct tcpci_data {
|
||||
struct regmap *regmap;
|
||||
int (*init)(struct tcpci *tcpci, struct tcpci_data *data);
|
||||
int (*set_vconn)(struct tcpci *tcpci, struct tcpci_data *data,
|
||||
bool enable);
|
||||
int (*start_drp_toggling)(struct tcpci *tcpci, struct tcpci_data *data,
|
||||
enum typec_cc_status cc);
|
||||
};
|
||||
|
||||
struct tcpci *tcpci_register_port(struct device *dev, struct tcpci_data *data);
|
||||
void tcpci_unregister_port(struct tcpci *tcpci);
|
||||
irqreturn_t tcpci_irq(struct tcpci *tcpci);
|
||||
|
||||
#endif /* __LINUX_USB_TCPCI_H */
|
||||
|
@ -171,6 +171,8 @@ source "drivers/usb/gadget/Kconfig"
|
||||
|
||||
source "drivers/usb/typec/Kconfig"
|
||||
|
||||
source "drivers/usb/roles/Kconfig"
|
||||
|
||||
config USB_LED_TRIG
|
||||
bool "USB LED Triggers"
|
||||
depends on LEDS_CLASS && LEDS_TRIGGERS
|
||||
@ -203,4 +205,7 @@ config USB_ULPI_BUS
|
||||
To compile this driver as a module, choose M here: the module will
|
||||
be called ulpi.
|
||||
|
||||
config USB_ROLE_SWITCH
|
||||
tristate
|
||||
|
||||
endif # USB_SUPPORT
|
||||
|
@ -65,3 +65,5 @@ obj-$(CONFIG_USB_COMMON) += common/
|
||||
obj-$(CONFIG_USBIP_CORE) += usbip/
|
||||
|
||||
obj-$(CONFIG_TYPEC) += typec/
|
||||
|
||||
obj-$(CONFIG_USB_ROLE_SWITCH) += roles/
|
||||
|
@ -20,7 +20,6 @@
|
||||
|
||||
struct ci_hdrc_imx_platform_flag {
|
||||
unsigned int flags;
|
||||
bool runtime_pm;
|
||||
};
|
||||
|
||||
static const struct ci_hdrc_imx_platform_flag imx23_usb_data = {
|
||||
@ -29,7 +28,7 @@ static const struct ci_hdrc_imx_platform_flag imx23_usb_data = {
|
||||
};
|
||||
|
||||
static const struct ci_hdrc_imx_platform_flag imx27_usb_data = {
|
||||
CI_HDRC_DISABLE_STREAMING,
|
||||
.flags = CI_HDRC_DISABLE_STREAMING,
|
||||
};
|
||||
|
||||
static const struct ci_hdrc_imx_platform_flag imx28_usb_data = {
|
||||
@ -84,6 +83,7 @@ struct ci_hdrc_imx_data {
|
||||
struct clk *clk;
|
||||
struct imx_usbmisc_data *usbmisc_data;
|
||||
bool supports_runtime_pm;
|
||||
bool override_phy_control;
|
||||
bool in_lpm;
|
||||
/* SoC before i.mx6 (except imx23/imx28) needs three clks */
|
||||
bool need_three_clks;
|
||||
@ -255,6 +255,7 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev)
|
||||
int ret;
|
||||
const struct of_device_id *of_id;
|
||||
const struct ci_hdrc_imx_platform_flag *imx_platform_flag;
|
||||
struct device_node *np = pdev->dev.of_node;
|
||||
|
||||
of_id = of_match_device(ci_hdrc_imx_dt_ids, &pdev->dev);
|
||||
if (!of_id)
|
||||
@ -289,6 +290,14 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev)
|
||||
}
|
||||
|
||||
pdata.usb_phy = data->phy;
|
||||
|
||||
if (of_device_is_compatible(np, "fsl,imx53-usb") && pdata.usb_phy &&
|
||||
of_usb_get_phy_mode(np) == USBPHY_INTERFACE_MODE_ULPI) {
|
||||
pdata.flags |= CI_HDRC_OVERRIDE_PHY_CONTROL;
|
||||
data->override_phy_control = true;
|
||||
usb_phy_init(pdata.usb_phy);
|
||||
}
|
||||
|
||||
pdata.flags |= imx_platform_flag->flags;
|
||||
if (pdata.flags & CI_HDRC_SUPPORTS_RUNTIME_PM)
|
||||
data->supports_runtime_pm = true;
|
||||
@ -342,6 +351,8 @@ static int ci_hdrc_imx_remove(struct platform_device *pdev)
|
||||
pm_runtime_put_noidle(&pdev->dev);
|
||||
}
|
||||
ci_hdrc_remove_device(data->ci_pdev);
|
||||
if (data->override_phy_control)
|
||||
usb_phy_shutdown(data->phy);
|
||||
imx_disable_unprepare_clks(&pdev->dev);
|
||||
|
||||
return 0;
|
||||
|
@ -45,18 +45,7 @@ static int ci_device_show(struct seq_file *s, void *data)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ci_device_open(struct inode *inode, struct file *file)
|
||||
{
|
||||
return single_open(file, ci_device_show, inode->i_private);
|
||||
}
|
||||
|
||||
static const struct file_operations ci_device_fops = {
|
||||
.open = ci_device_open,
|
||||
.read = seq_read,
|
||||
.llseek = seq_lseek,
|
||||
.release = single_release,
|
||||
};
|
||||
DEFINE_SHOW_ATTRIBUTE(ci_device);
|
||||
|
||||
/**
|
||||
* ci_port_test_show: reads port test mode
|
||||
@ -156,18 +145,7 @@ static int ci_qheads_show(struct seq_file *s, void *data)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ci_qheads_open(struct inode *inode, struct file *file)
|
||||
{
|
||||
return single_open(file, ci_qheads_show, inode->i_private);
|
||||
}
|
||||
|
||||
static const struct file_operations ci_qheads_fops = {
|
||||
.open = ci_qheads_open,
|
||||
.read = seq_read,
|
||||
.llseek = seq_lseek,
|
||||
.release = single_release,
|
||||
};
|
||||
DEFINE_SHOW_ATTRIBUTE(ci_qheads);
|
||||
|
||||
/**
|
||||
* ci_requests_show: DMA contents of all requests currently queued (all endpts)
|
||||
@ -204,18 +182,7 @@ static int ci_requests_show(struct seq_file *s, void *data)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ci_requests_open(struct inode *inode, struct file *file)
|
||||
{
|
||||
return single_open(file, ci_requests_show, inode->i_private);
|
||||
}
|
||||
|
||||
static const struct file_operations ci_requests_fops = {
|
||||
.open = ci_requests_open,
|
||||
.read = seq_read,
|
||||
.llseek = seq_lseek,
|
||||
.release = single_release,
|
||||
};
|
||||
DEFINE_SHOW_ATTRIBUTE(ci_requests);
|
||||
|
||||
static int ci_otg_show(struct seq_file *s, void *unused)
|
||||
{
|
||||
@ -278,18 +245,7 @@ static int ci_otg_show(struct seq_file *s, void *unused)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ci_otg_open(struct inode *inode, struct file *file)
|
||||
{
|
||||
return single_open(file, ci_otg_show, inode->i_private);
|
||||
}
|
||||
|
||||
static const struct file_operations ci_otg_fops = {
|
||||
.open = ci_otg_open,
|
||||
.read = seq_read,
|
||||
.llseek = seq_lseek,
|
||||
.release = single_release,
|
||||
};
|
||||
DEFINE_SHOW_ATTRIBUTE(ci_otg);
|
||||
|
||||
static int ci_role_show(struct seq_file *s, void *data)
|
||||
{
|
||||
@ -376,18 +332,7 @@ static int ci_registers_show(struct seq_file *s, void *unused)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ci_registers_open(struct inode *inode, struct file *file)
|
||||
{
|
||||
return single_open(file, ci_registers_show, inode->i_private);
|
||||
}
|
||||
|
||||
static const struct file_operations ci_registers_fops = {
|
||||
.open = ci_registers_open,
|
||||
.read = seq_read,
|
||||
.llseek = seq_lseek,
|
||||
.release = single_release,
|
||||
};
|
||||
DEFINE_SHOW_ATTRIBUTE(ci_registers);
|
||||
|
||||
/**
|
||||
* dbg_create_files: initializes the attribute interface
|
||||
|
@ -124,10 +124,8 @@ static int host_start(struct ci_hdrc *ci)
|
||||
|
||||
hcd->power_budget = ci->platdata->power_budget;
|
||||
hcd->tpl_support = ci->platdata->tpl_support;
|
||||
if (ci->phy)
|
||||
hcd->phy = ci->phy;
|
||||
else
|
||||
hcd->usb_phy = ci->usb_phy;
|
||||
if (ci->phy || ci->usb_phy)
|
||||
hcd->skip_phy_initialization = 1;
|
||||
|
||||
ehci = hcd_to_ehci(hcd);
|
||||
ehci->caps = ci->hw_bank.cap;
|
||||
|
@ -148,14 +148,21 @@ static int usbmisc_imx25_post(struct imx_usbmisc_data *data)
|
||||
if (data->index > 2)
|
||||
return -EINVAL;
|
||||
|
||||
if (data->evdo) {
|
||||
spin_lock_irqsave(&usbmisc->lock, flags);
|
||||
reg = usbmisc->base + MX25_USB_PHY_CTRL_OFFSET;
|
||||
val = readl(reg);
|
||||
writel(val | MX25_BM_EXTERNAL_VBUS_DIVIDER, reg);
|
||||
spin_unlock_irqrestore(&usbmisc->lock, flags);
|
||||
usleep_range(5000, 10000); /* needed to stabilize voltage */
|
||||
}
|
||||
if (data->index)
|
||||
return 0;
|
||||
|
||||
spin_lock_irqsave(&usbmisc->lock, flags);
|
||||
reg = usbmisc->base + MX25_USB_PHY_CTRL_OFFSET;
|
||||
val = readl(reg);
|
||||
|
||||
if (data->evdo)
|
||||
val |= MX25_BM_EXTERNAL_VBUS_DIVIDER;
|
||||
else
|
||||
val &= ~MX25_BM_EXTERNAL_VBUS_DIVIDER;
|
||||
|
||||
writel(val, reg);
|
||||
spin_unlock_irqrestore(&usbmisc->lock, flags);
|
||||
usleep_range(5000, 10000); /* needed to stabilize voltage */
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -308,13 +315,12 @@ static int usbmisc_imx6q_set_wakeup
|
||||
val = readl(usbmisc->base + data->index * 4);
|
||||
if (enabled) {
|
||||
val |= wakeup_setting;
|
||||
writel(val, usbmisc->base + data->index * 4);
|
||||
} else {
|
||||
if (val & MX6_BM_WAKEUP_INTR)
|
||||
pr_debug("wakeup int at ci_hdrc.%d\n", data->index);
|
||||
val &= ~wakeup_setting;
|
||||
writel(val, usbmisc->base + data->index * 4);
|
||||
}
|
||||
writel(val, usbmisc->base + data->index * 4);
|
||||
spin_unlock_irqrestore(&usbmisc->lock, flags);
|
||||
|
||||
return ret;
|
||||
|
@ -9,3 +9,4 @@ usb-common-$(CONFIG_USB_LED_TRIG) += led.o
|
||||
|
||||
obj-$(CONFIG_USB_OTG_FSM) += usb-otg-fsm.o
|
||||
obj-$(CONFIG_USB_ULPI_BUS) += ulpi.o
|
||||
obj-$(CONFIG_USB_ROLE_SWITCH) += roles.o
|
||||
|
305
drivers/usb/common/roles.c
Normal file
305
drivers/usb/common/roles.c
Normal file
@ -0,0 +1,305 @@
|
||||
// SPDX-License-Identifier: GPL-2.0
|
||||
/*
|
||||
* USB Role Switch Support
|
||||
*
|
||||
* Copyright (C) 2018 Intel Corporation
|
||||
* Author: Heikki Krogerus <heikki.krogerus@linux.intel.com>
|
||||
* Hans de Goede <hdegoede@redhat.com>
|
||||
*/
|
||||
|
||||
#include <linux/usb/role.h>
|
||||
#include <linux/device.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/mutex.h>
|
||||
#include <linux/slab.h>
|
||||
|
||||
static struct class *role_class;
|
||||
|
||||
struct usb_role_switch {
|
||||
struct device dev;
|
||||
struct mutex lock; /* device lock*/
|
||||
enum usb_role role;
|
||||
|
||||
/* From descriptor */
|
||||
struct device *usb2_port;
|
||||
struct device *usb3_port;
|
||||
struct device *udc;
|
||||
usb_role_switch_set_t set;
|
||||
usb_role_switch_get_t get;
|
||||
bool allow_userspace_control;
|
||||
};
|
||||
|
||||
#define to_role_switch(d) container_of(d, struct usb_role_switch, dev)
|
||||
|
||||
/**
|
||||
* usb_role_switch_set_role - Set USB role for a switch
|
||||
* @sw: USB role switch
|
||||
* @role: USB role to be switched to
|
||||
*
|
||||
* Set USB role @role for @sw.
|
||||
*/
|
||||
int usb_role_switch_set_role(struct usb_role_switch *sw, enum usb_role role)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (IS_ERR_OR_NULL(sw))
|
||||
return 0;
|
||||
|
||||
mutex_lock(&sw->lock);
|
||||
|
||||
ret = sw->set(sw->dev.parent, role);
|
||||
if (!ret)
|
||||
sw->role = role;
|
||||
|
||||
mutex_unlock(&sw->lock);
|
||||
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(usb_role_switch_set_role);
|
||||
|
||||
/**
|
||||
* usb_role_switch_get_role - Get the USB role for a switch
|
||||
* @sw: USB role switch
|
||||
*
|
||||
* Depending on the role-switch-driver this function returns either a cached
|
||||
* value of the last set role, or reads back the actual value from the hardware.
|
||||
*/
|
||||
enum usb_role usb_role_switch_get_role(struct usb_role_switch *sw)
|
||||
{
|
||||
enum usb_role role;
|
||||
|
||||
if (IS_ERR_OR_NULL(sw))
|
||||
return USB_ROLE_NONE;
|
||||
|
||||
mutex_lock(&sw->lock);
|
||||
|
||||
if (sw->get)
|
||||
role = sw->get(sw->dev.parent);
|
||||
else
|
||||
role = sw->role;
|
||||
|
||||
mutex_unlock(&sw->lock);
|
||||
|
||||
return role;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(usb_role_switch_get_role);
|
||||
|
||||
static int __switch_match(struct device *dev, const void *name)
|
||||
{
|
||||
return !strcmp((const char *)name, dev_name(dev));
|
||||
}
|
||||
|
||||
static void *usb_role_switch_match(struct device_connection *con, int ep,
|
||||
void *data)
|
||||
{
|
||||
struct device *dev;
|
||||
|
||||
dev = class_find_device(role_class, NULL, con->endpoint[ep],
|
||||
__switch_match);
|
||||
|
||||
return dev ? to_role_switch(dev) : ERR_PTR(-EPROBE_DEFER);
|
||||
}
|
||||
|
||||
/**
|
||||
* usb_role_switch_get - Find USB role switch linked with the caller
|
||||
* @dev: The caller device
|
||||
*
|
||||
* Finds and returns role switch linked with @dev. The reference count for the
|
||||
* found switch is incremented.
|
||||
*/
|
||||
struct usb_role_switch *usb_role_switch_get(struct device *dev)
|
||||
{
|
||||
return device_connection_find_match(dev, "usb-role-switch", NULL,
|
||||
usb_role_switch_match);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(usb_role_switch_get);
|
||||
|
||||
/**
|
||||
* usb_role_switch_put - Release handle to a switch
|
||||
* @sw: USB Role Switch
|
||||
*
|
||||
* Decrement reference count for @sw.
|
||||
*/
|
||||
void usb_role_switch_put(struct usb_role_switch *sw)
|
||||
{
|
||||
if (!IS_ERR_OR_NULL(sw))
|
||||
put_device(&sw->dev);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(usb_role_switch_put);
|
||||
|
||||
static umode_t
|
||||
usb_role_switch_is_visible(struct kobject *kobj, struct attribute *attr, int n)
|
||||
{
|
||||
struct device *dev = container_of(kobj, typeof(*dev), kobj);
|
||||
struct usb_role_switch *sw = to_role_switch(dev);
|
||||
|
||||
if (sw->allow_userspace_control)
|
||||
return attr->mode;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const char * const usb_roles[] = {
|
||||
[USB_ROLE_NONE] = "none",
|
||||
[USB_ROLE_HOST] = "host",
|
||||
[USB_ROLE_DEVICE] = "device",
|
||||
};
|
||||
|
||||
static ssize_t
|
||||
role_show(struct device *dev, struct device_attribute *attr, char *buf)
|
||||
{
|
||||
struct usb_role_switch *sw = to_role_switch(dev);
|
||||
enum usb_role role = usb_role_switch_get_role(sw);
|
||||
|
||||
return sprintf(buf, "%s\n", usb_roles[role]);
|
||||
}
|
||||
|
||||
static ssize_t role_store(struct device *dev, struct device_attribute *attr,
|
||||
const char *buf, size_t size)
|
||||
{
|
||||
struct usb_role_switch *sw = to_role_switch(dev);
|
||||
int ret;
|
||||
|
||||
ret = sysfs_match_string(usb_roles, buf);
|
||||
if (ret < 0) {
|
||||
bool res;
|
||||
|
||||
/* Extra check if the user wants to disable the switch */
|
||||
ret = kstrtobool(buf, &res);
|
||||
if (ret || res)
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ret = usb_role_switch_set_role(sw, ret);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
return size;
|
||||
}
|
||||
static DEVICE_ATTR_RW(role);
|
||||
|
||||
static struct attribute *usb_role_switch_attrs[] = {
|
||||
&dev_attr_role.attr,
|
||||
NULL,
|
||||
};
|
||||
|
||||
static const struct attribute_group usb_role_switch_group = {
|
||||
.is_visible = usb_role_switch_is_visible,
|
||||
.attrs = usb_role_switch_attrs,
|
||||
};
|
||||
|
||||
static const struct attribute_group *usb_role_switch_groups[] = {
|
||||
&usb_role_switch_group,
|
||||
NULL,
|
||||
};
|
||||
|
||||
static int
|
||||
usb_role_switch_uevent(struct device *dev, struct kobj_uevent_env *env)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = add_uevent_var(env, "USB_ROLE_SWITCH=%s", dev_name(dev));
|
||||
if (ret)
|
||||
dev_err(dev, "failed to add uevent USB_ROLE_SWITCH\n");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void usb_role_switch_release(struct device *dev)
|
||||
{
|
||||
struct usb_role_switch *sw = to_role_switch(dev);
|
||||
|
||||
kfree(sw);
|
||||
}
|
||||
|
||||
static const struct device_type usb_role_dev_type = {
|
||||
.name = "usb_role_switch",
|
||||
.groups = usb_role_switch_groups,
|
||||
.uevent = usb_role_switch_uevent,
|
||||
.release = usb_role_switch_release,
|
||||
};
|
||||
|
||||
/**
|
||||
* usb_role_switch_register - Register USB Role Switch
|
||||
* @parent: Parent device for the switch
|
||||
* @desc: Description of the switch
|
||||
*
|
||||
* USB Role Switch is a device capable or choosing the role for USB connector.
|
||||
* On platforms where the USB controller is dual-role capable, the controller
|
||||
* driver will need to register the switch. On platforms where the USB host and
|
||||
* USB device controllers behind the connector are separate, there will be a
|
||||
* mux, and the driver for that mux will need to register the switch.
|
||||
*
|
||||
* Returns handle to a new role switch or ERR_PTR. The content of @desc is
|
||||
* copied.
|
||||
*/
|
||||
struct usb_role_switch *
|
||||
usb_role_switch_register(struct device *parent,
|
||||
const struct usb_role_switch_desc *desc)
|
||||
{
|
||||
struct usb_role_switch *sw;
|
||||
int ret;
|
||||
|
||||
if (!desc || !desc->set)
|
||||
return ERR_PTR(-EINVAL);
|
||||
|
||||
sw = kzalloc(sizeof(*sw), GFP_KERNEL);
|
||||
if (!sw)
|
||||
return ERR_PTR(-ENOMEM);
|
||||
|
||||
mutex_init(&sw->lock);
|
||||
|
||||
sw->allow_userspace_control = desc->allow_userspace_control;
|
||||
sw->usb2_port = desc->usb2_port;
|
||||
sw->usb3_port = desc->usb3_port;
|
||||
sw->udc = desc->udc;
|
||||
sw->set = desc->set;
|
||||
sw->get = desc->get;
|
||||
|
||||
sw->dev.parent = parent;
|
||||
sw->dev.class = role_class;
|
||||
sw->dev.type = &usb_role_dev_type;
|
||||
dev_set_name(&sw->dev, "%s-role-switch", dev_name(parent));
|
||||
|
||||
ret = device_register(&sw->dev);
|
||||
if (ret) {
|
||||
put_device(&sw->dev);
|
||||
return ERR_PTR(ret);
|
||||
}
|
||||
|
||||
/* TODO: Symlinks for the host port and the device controller. */
|
||||
|
||||
return sw;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(usb_role_switch_register);
|
||||
|
||||
/**
|
||||
* usb_role_switch_unregister - Unregsiter USB Role Switch
|
||||
* @sw: USB Role Switch
|
||||
*
|
||||
* Unregister switch that was registered with usb_role_switch_register().
|
||||
*/
|
||||
void usb_role_switch_unregister(struct usb_role_switch *sw)
|
||||
{
|
||||
if (!IS_ERR_OR_NULL(sw))
|
||||
device_unregister(&sw->dev);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(usb_role_switch_unregister);
|
||||
|
||||
static int __init usb_roles_init(void)
|
||||
{
|
||||
role_class = class_create(THIS_MODULE, "usb_role");
|
||||
return PTR_ERR_OR_ZERO(role_class);
|
||||
}
|
||||
subsys_initcall(usb_roles_init);
|
||||
|
||||
static void __exit usb_roles_exit(void)
|
||||
{
|
||||
class_destroy(role_class);
|
||||
}
|
||||
module_exit(usb_roles_exit);
|
||||
|
||||
MODULE_AUTHOR("Heikki Krogerus <heikki.krogerus@linux.intel.com>");
|
||||
MODULE_AUTHOR("Hans de Goede <hdegoede@redhat.com>");
|
||||
MODULE_LICENSE("GPL v2");
|
||||
MODULE_DESCRIPTION("USB Role Class");
|
@ -6,7 +6,7 @@
|
||||
usbcore-y := usb.o hub.o hcd.o urb.o message.o driver.o
|
||||
usbcore-y += config.o file.o buffer.o sysfs.o endpoint.o
|
||||
usbcore-y += devio.o notify.o generic.o quirks.o devices.o
|
||||
usbcore-y += port.o
|
||||
usbcore-y += phy.o port.o
|
||||
|
||||
usbcore-$(CONFIG_OF) += of.o
|
||||
usbcore-$(CONFIG_USB_PCI) += hcd-pci.o
|
||||
|
@ -210,8 +210,13 @@ static int generic_suspend(struct usb_device *udev, pm_message_t msg)
|
||||
if (!udev->parent)
|
||||
rc = hcd_bus_suspend(udev, msg);
|
||||
|
||||
/* Non-root devices don't need to do anything for FREEZE or PRETHAW */
|
||||
else if (msg.event == PM_EVENT_FREEZE || msg.event == PM_EVENT_PRETHAW)
|
||||
/*
|
||||
* Non-root USB2 devices don't need to do anything for FREEZE
|
||||
* or PRETHAW. USB3 devices don't support global suspend and
|
||||
* needs to be selectively suspended.
|
||||
*/
|
||||
else if ((msg.event == PM_EVENT_FREEZE || msg.event == PM_EVENT_PRETHAW)
|
||||
&& (udev->speed < USB_SPEED_SUPER))
|
||||
rc = 0;
|
||||
else
|
||||
rc = usb_port_suspend(udev, msg);
|
||||
|
@ -37,6 +37,7 @@
|
||||
#include <linux/usb/otg.h>
|
||||
|
||||
#include "usb.h"
|
||||
#include "phy.h"
|
||||
|
||||
|
||||
/*-------------------------------------------------------------------------*/
|
||||
@ -2260,6 +2261,9 @@ int hcd_bus_suspend(struct usb_device *rhdev, pm_message_t msg)
|
||||
usb_set_device_state(rhdev, USB_STATE_SUSPENDED);
|
||||
hcd->state = HC_STATE_SUSPENDED;
|
||||
|
||||
if (!PMSG_IS_AUTO(msg))
|
||||
usb_phy_roothub_power_off(hcd->phy_roothub);
|
||||
|
||||
/* Did we race with a root-hub wakeup event? */
|
||||
if (rhdev->do_remote_wakeup) {
|
||||
char buffer[6];
|
||||
@ -2296,6 +2300,13 @@ int hcd_bus_resume(struct usb_device *rhdev, pm_message_t msg)
|
||||
dev_dbg(&rhdev->dev, "skipped %s of dead bus\n", "resume");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!PMSG_IS_AUTO(msg)) {
|
||||
status = usb_phy_roothub_power_on(hcd->phy_roothub);
|
||||
if (status)
|
||||
return status;
|
||||
}
|
||||
|
||||
if (!hcd->driver->bus_resume)
|
||||
return -ENOENT;
|
||||
if (HCD_RH_RUNNING(hcd))
|
||||
@ -2333,6 +2344,7 @@ int hcd_bus_resume(struct usb_device *rhdev, pm_message_t msg)
|
||||
}
|
||||
} else {
|
||||
hcd->state = old_state;
|
||||
usb_phy_roothub_power_off(hcd->phy_roothub);
|
||||
dev_dbg(&rhdev->dev, "bus %s fail, err %d\n",
|
||||
"resume", status);
|
||||
if (status != -ESHUTDOWN)
|
||||
@ -2727,7 +2739,7 @@ int usb_add_hcd(struct usb_hcd *hcd,
|
||||
int retval;
|
||||
struct usb_device *rhdev;
|
||||
|
||||
if (IS_ENABLED(CONFIG_USB_PHY) && !hcd->usb_phy) {
|
||||
if (IS_ENABLED(CONFIG_USB_PHY) && !hcd->skip_phy_initialization) {
|
||||
struct usb_phy *phy = usb_get_phy_dev(hcd->self.sysdev, 0);
|
||||
|
||||
if (IS_ERR(phy)) {
|
||||
@ -2745,28 +2757,16 @@ int usb_add_hcd(struct usb_hcd *hcd,
|
||||
}
|
||||
}
|
||||
|
||||
if (IS_ENABLED(CONFIG_GENERIC_PHY) && !hcd->phy) {
|
||||
struct phy *phy = phy_get(hcd->self.sysdev, "usb");
|
||||
|
||||
if (IS_ERR(phy)) {
|
||||
retval = PTR_ERR(phy);
|
||||
if (retval == -EPROBE_DEFER)
|
||||
goto err_phy;
|
||||
} else {
|
||||
retval = phy_init(phy);
|
||||
if (retval) {
|
||||
phy_put(phy);
|
||||
goto err_phy;
|
||||
}
|
||||
retval = phy_power_on(phy);
|
||||
if (retval) {
|
||||
phy_exit(phy);
|
||||
phy_put(phy);
|
||||
goto err_phy;
|
||||
}
|
||||
hcd->phy = phy;
|
||||
hcd->remove_phy = 1;
|
||||
if (!hcd->skip_phy_initialization && usb_hcd_is_primary_hcd(hcd)) {
|
||||
hcd->phy_roothub = usb_phy_roothub_init(hcd->self.sysdev);
|
||||
if (IS_ERR(hcd->phy_roothub)) {
|
||||
retval = PTR_ERR(hcd->phy_roothub);
|
||||
goto err_phy_roothub_init;
|
||||
}
|
||||
|
||||
retval = usb_phy_roothub_power_on(hcd->phy_roothub);
|
||||
if (retval)
|
||||
goto err_usb_phy_roothub_power_on;
|
||||
}
|
||||
|
||||
dev_info(hcd->self.controller, "%s\n", hcd->product_desc);
|
||||
@ -2933,13 +2933,10 @@ err_allocate_root_hub:
|
||||
err_register_bus:
|
||||
hcd_buffer_destroy(hcd);
|
||||
err_create_buf:
|
||||
if (IS_ENABLED(CONFIG_GENERIC_PHY) && hcd->remove_phy && hcd->phy) {
|
||||
phy_power_off(hcd->phy);
|
||||
phy_exit(hcd->phy);
|
||||
phy_put(hcd->phy);
|
||||
hcd->phy = NULL;
|
||||
}
|
||||
err_phy:
|
||||
usb_phy_roothub_power_off(hcd->phy_roothub);
|
||||
err_usb_phy_roothub_power_on:
|
||||
usb_phy_roothub_exit(hcd->phy_roothub);
|
||||
err_phy_roothub_init:
|
||||
if (hcd->remove_phy && hcd->usb_phy) {
|
||||
usb_phy_shutdown(hcd->usb_phy);
|
||||
usb_put_phy(hcd->usb_phy);
|
||||
@ -3017,12 +3014,9 @@ void usb_remove_hcd(struct usb_hcd *hcd)
|
||||
usb_deregister_bus(&hcd->self);
|
||||
hcd_buffer_destroy(hcd);
|
||||
|
||||
if (IS_ENABLED(CONFIG_GENERIC_PHY) && hcd->remove_phy && hcd->phy) {
|
||||
phy_power_off(hcd->phy);
|
||||
phy_exit(hcd->phy);
|
||||
phy_put(hcd->phy);
|
||||
hcd->phy = NULL;
|
||||
}
|
||||
usb_phy_roothub_power_off(hcd->phy_roothub);
|
||||
usb_phy_roothub_exit(hcd->phy_roothub);
|
||||
|
||||
if (hcd->remove_phy && hcd->usb_phy) {
|
||||
usb_phy_shutdown(hcd->usb_phy);
|
||||
usb_put_phy(hcd->usb_phy);
|
||||
|
@ -2192,9 +2192,13 @@ static void show_string(struct usb_device *udev, char *id, char *string)
|
||||
|
||||
static void announce_device(struct usb_device *udev)
|
||||
{
|
||||
dev_info(&udev->dev, "New USB device found, idVendor=%04x, idProduct=%04x\n",
|
||||
u16 bcdDevice = le16_to_cpu(udev->descriptor.bcdDevice);
|
||||
|
||||
dev_info(&udev->dev,
|
||||
"New USB device found, idVendor=%04x, idProduct=%04x, bcdDevice=%2x.%02x\n",
|
||||
le16_to_cpu(udev->descriptor.idVendor),
|
||||
le16_to_cpu(udev->descriptor.idProduct));
|
||||
le16_to_cpu(udev->descriptor.idProduct),
|
||||
bcdDevice >> 8, bcdDevice & 0xff);
|
||||
dev_info(&udev->dev,
|
||||
"New USB device strings: Mfr=%d, Product=%d, SerialNumber=%d\n",
|
||||
udev->descriptor.iManufacturer,
|
||||
@ -3655,7 +3659,7 @@ static int hub_reset_resume(struct usb_interface *intf)
|
||||
*/
|
||||
void usb_root_hub_lost_power(struct usb_device *rhdev)
|
||||
{
|
||||
dev_warn(&rhdev->dev, "root hub lost power or was reset\n");
|
||||
dev_notice(&rhdev->dev, "root hub lost power or was reset\n");
|
||||
rhdev->reset_resume = 1;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(usb_root_hub_lost_power);
|
||||
@ -5104,8 +5108,10 @@ static void port_event(struct usb_hub *hub, int port1)
|
||||
|
||||
if (portchange & USB_PORT_STAT_C_OVERCURRENT) {
|
||||
u16 status = 0, unused;
|
||||
port_dev->over_current_count++;
|
||||
|
||||
dev_dbg(&port_dev->dev, "over-current change\n");
|
||||
dev_dbg(&port_dev->dev, "over-current change #%u\n",
|
||||
port_dev->over_current_count);
|
||||
usb_clear_port_feature(hdev, port1,
|
||||
USB_PORT_FEAT_C_OVER_CURRENT);
|
||||
msleep(100); /* Cool down */
|
||||
@ -5505,21 +5511,15 @@ static int usb_reset_and_verify_device(struct usb_device *udev)
|
||||
if (udev->usb2_hw_lpm_enabled == 1)
|
||||
usb_set_usb2_hardware_lpm(udev, 0);
|
||||
|
||||
/* Disable LPM and LTM while we reset the device and reinstall the alt
|
||||
* settings. Device-initiated LPM settings, and system exit latency
|
||||
* settings are cleared when the device is reset, so we have to set
|
||||
* them up again.
|
||||
/* Disable LPM while we reset the device and reinstall the alt settings.
|
||||
* Device-initiated LPM, and system exit latency settings are cleared
|
||||
* when the device is reset, so we have to set them up again.
|
||||
*/
|
||||
ret = usb_unlocked_disable_lpm(udev);
|
||||
if (ret) {
|
||||
dev_err(&udev->dev, "%s Failed to disable LPM\n", __func__);
|
||||
goto re_enumerate_no_bos;
|
||||
}
|
||||
ret = usb_disable_ltm(udev);
|
||||
if (ret) {
|
||||
dev_err(&udev->dev, "%s Failed to disable LTM\n", __func__);
|
||||
goto re_enumerate_no_bos;
|
||||
}
|
||||
|
||||
bos = udev->bos;
|
||||
udev->bos = NULL;
|
||||
|
@ -96,6 +96,7 @@ struct usb_port {
|
||||
enum usb_port_connect_type connect_type;
|
||||
usb_port_location_t location;
|
||||
struct mutex status_lock;
|
||||
u32 over_current_count;
|
||||
u8 portnum;
|
||||
unsigned int is_superspeed:1;
|
||||
unsigned int usb3_lpm_u1_permit:1;
|
||||
|
158
drivers/usb/core/phy.c
Normal file
158
drivers/usb/core/phy.c
Normal file
@ -0,0 +1,158 @@
|
||||
// SPDX-License-Identifier: GPL-2.0+
|
||||
/*
|
||||
* A wrapper for multiple PHYs which passes all phy_* function calls to
|
||||
* multiple (actual) PHY devices. This is comes handy when initializing
|
||||
* all PHYs on a HCD and to keep them all in the same state.
|
||||
*
|
||||
* Copyright (C) 2018 Martin Blumenstingl <martin.blumenstingl@googlemail.com>
|
||||
*/
|
||||
|
||||
#include <linux/device.h>
|
||||
#include <linux/list.h>
|
||||
#include <linux/phy/phy.h>
|
||||
#include <linux/of.h>
|
||||
|
||||
#include "phy.h"
|
||||
|
||||
struct usb_phy_roothub {
|
||||
struct phy *phy;
|
||||
struct list_head list;
|
||||
};
|
||||
|
||||
static struct usb_phy_roothub *usb_phy_roothub_alloc(struct device *dev)
|
||||
{
|
||||
struct usb_phy_roothub *roothub_entry;
|
||||
|
||||
roothub_entry = devm_kzalloc(dev, sizeof(*roothub_entry), GFP_KERNEL);
|
||||
if (!roothub_entry)
|
||||
return ERR_PTR(-ENOMEM);
|
||||
|
||||
INIT_LIST_HEAD(&roothub_entry->list);
|
||||
|
||||
return roothub_entry;
|
||||
}
|
||||
|
||||
static int usb_phy_roothub_add_phy(struct device *dev, int index,
|
||||
struct list_head *list)
|
||||
{
|
||||
struct usb_phy_roothub *roothub_entry;
|
||||
struct phy *phy = devm_of_phy_get_by_index(dev, dev->of_node, index);
|
||||
|
||||
if (IS_ERR_OR_NULL(phy)) {
|
||||
if (!phy || PTR_ERR(phy) == -ENODEV)
|
||||
return 0;
|
||||
else
|
||||
return PTR_ERR(phy);
|
||||
}
|
||||
|
||||
roothub_entry = usb_phy_roothub_alloc(dev);
|
||||
if (IS_ERR(roothub_entry))
|
||||
return PTR_ERR(roothub_entry);
|
||||
|
||||
roothub_entry->phy = phy;
|
||||
|
||||
list_add_tail(&roothub_entry->list, list);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct usb_phy_roothub *usb_phy_roothub_init(struct device *dev)
|
||||
{
|
||||
struct usb_phy_roothub *phy_roothub;
|
||||
struct usb_phy_roothub *roothub_entry;
|
||||
struct list_head *head;
|
||||
int i, num_phys, err;
|
||||
|
||||
num_phys = of_count_phandle_with_args(dev->of_node, "phys",
|
||||
"#phy-cells");
|
||||
if (num_phys <= 0)
|
||||
return NULL;
|
||||
|
||||
phy_roothub = usb_phy_roothub_alloc(dev);
|
||||
if (IS_ERR(phy_roothub))
|
||||
return phy_roothub;
|
||||
|
||||
for (i = 0; i < num_phys; i++) {
|
||||
err = usb_phy_roothub_add_phy(dev, i, &phy_roothub->list);
|
||||
if (err)
|
||||
goto err_out;
|
||||
}
|
||||
|
||||
head = &phy_roothub->list;
|
||||
|
||||
list_for_each_entry(roothub_entry, head, list) {
|
||||
err = phy_init(roothub_entry->phy);
|
||||
if (err)
|
||||
goto err_exit_phys;
|
||||
}
|
||||
|
||||
return phy_roothub;
|
||||
|
||||
err_exit_phys:
|
||||
list_for_each_entry_continue_reverse(roothub_entry, head, list)
|
||||
phy_exit(roothub_entry->phy);
|
||||
|
||||
err_out:
|
||||
return ERR_PTR(err);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(usb_phy_roothub_init);
|
||||
|
||||
int usb_phy_roothub_exit(struct usb_phy_roothub *phy_roothub)
|
||||
{
|
||||
struct usb_phy_roothub *roothub_entry;
|
||||
struct list_head *head;
|
||||
int err, ret = 0;
|
||||
|
||||
if (!phy_roothub)
|
||||
return 0;
|
||||
|
||||
head = &phy_roothub->list;
|
||||
|
||||
list_for_each_entry(roothub_entry, head, list) {
|
||||
err = phy_exit(roothub_entry->phy);
|
||||
if (err)
|
||||
ret = ret;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(usb_phy_roothub_exit);
|
||||
|
||||
int usb_phy_roothub_power_on(struct usb_phy_roothub *phy_roothub)
|
||||
{
|
||||
struct usb_phy_roothub *roothub_entry;
|
||||
struct list_head *head;
|
||||
int err;
|
||||
|
||||
if (!phy_roothub)
|
||||
return 0;
|
||||
|
||||
head = &phy_roothub->list;
|
||||
|
||||
list_for_each_entry(roothub_entry, head, list) {
|
||||
err = phy_power_on(roothub_entry->phy);
|
||||
if (err)
|
||||
goto err_out;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
err_out:
|
||||
list_for_each_entry_continue_reverse(roothub_entry, head, list)
|
||||
phy_power_off(roothub_entry->phy);
|
||||
|
||||
return err;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(usb_phy_roothub_power_on);
|
||||
|
||||
void usb_phy_roothub_power_off(struct usb_phy_roothub *phy_roothub)
|
||||
{
|
||||
struct usb_phy_roothub *roothub_entry;
|
||||
|
||||
if (!phy_roothub)
|
||||
return;
|
||||
|
||||
list_for_each_entry_reverse(roothub_entry, &phy_roothub->list, list)
|
||||
phy_power_off(roothub_entry->phy);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(usb_phy_roothub_power_off);
|
7
drivers/usb/core/phy.h
Normal file
7
drivers/usb/core/phy.h
Normal file
@ -0,0 +1,7 @@
|
||||
struct usb_phy_roothub;
|
||||
|
||||
struct usb_phy_roothub *usb_phy_roothub_init(struct device *dev);
|
||||
int usb_phy_roothub_exit(struct usb_phy_roothub *phy_roothub);
|
||||
|
||||
int usb_phy_roothub_power_on(struct usb_phy_roothub *phy_roothub);
|
||||
void usb_phy_roothub_power_off(struct usb_phy_roothub *phy_roothub);
|
@ -41,6 +41,15 @@ static ssize_t connect_type_show(struct device *dev,
|
||||
}
|
||||
static DEVICE_ATTR_RO(connect_type);
|
||||
|
||||
static ssize_t over_current_count_show(struct device *dev,
|
||||
struct device_attribute *attr, char *buf)
|
||||
{
|
||||
struct usb_port *port_dev = to_usb_port(dev);
|
||||
|
||||
return sprintf(buf, "%u\n", port_dev->over_current_count);
|
||||
}
|
||||
static DEVICE_ATTR_RO(over_current_count);
|
||||
|
||||
static ssize_t usb3_lpm_permit_show(struct device *dev,
|
||||
struct device_attribute *attr, char *buf)
|
||||
{
|
||||
@ -109,6 +118,7 @@ static DEVICE_ATTR_RW(usb3_lpm_permit);
|
||||
|
||||
static struct attribute *port_dev_attrs[] = {
|
||||
&dev_attr_connect_type.attr,
|
||||
&dev_attr_over_current_count.attr,
|
||||
NULL,
|
||||
};
|
||||
|
||||
|
@ -6,11 +6,157 @@
|
||||
* Copyright (c) 2007 Greg Kroah-Hartman <gregkh@suse.de>
|
||||
*/
|
||||
|
||||
#include <linux/moduleparam.h>
|
||||
#include <linux/usb.h>
|
||||
#include <linux/usb/quirks.h>
|
||||
#include <linux/usb/hcd.h>
|
||||
#include "usb.h"
|
||||
|
||||
struct quirk_entry {
|
||||
u16 vid;
|
||||
u16 pid;
|
||||
u32 flags;
|
||||
};
|
||||
|
||||
static DEFINE_MUTEX(quirk_mutex);
|
||||
|
||||
static struct quirk_entry *quirk_list;
|
||||
static unsigned int quirk_count;
|
||||
|
||||
static char quirks_param[128];
|
||||
|
||||
static int quirks_param_set(const char *val, const struct kernel_param *kp)
|
||||
{
|
||||
char *p, *field;
|
||||
u16 vid, pid;
|
||||
u32 flags;
|
||||
size_t i;
|
||||
int err;
|
||||
|
||||
err = param_set_copystring(val, kp);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
mutex_lock(&quirk_mutex);
|
||||
|
||||
if (!*val) {
|
||||
quirk_count = 0;
|
||||
kfree(quirk_list);
|
||||
quirk_list = NULL;
|
||||
goto unlock;
|
||||
}
|
||||
|
||||
for (quirk_count = 1, i = 0; val[i]; i++)
|
||||
if (val[i] == ',')
|
||||
quirk_count++;
|
||||
|
||||
if (quirk_list) {
|
||||
kfree(quirk_list);
|
||||
quirk_list = NULL;
|
||||
}
|
||||
|
||||
quirk_list = kcalloc(quirk_count, sizeof(struct quirk_entry),
|
||||
GFP_KERNEL);
|
||||
if (!quirk_list) {
|
||||
mutex_unlock(&quirk_mutex);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
for (i = 0, p = (char *)val; p && *p;) {
|
||||
/* Each entry consists of VID:PID:flags */
|
||||
field = strsep(&p, ":");
|
||||
if (!field)
|
||||
break;
|
||||
|
||||
if (kstrtou16(field, 16, &vid))
|
||||
break;
|
||||
|
||||
field = strsep(&p, ":");
|
||||
if (!field)
|
||||
break;
|
||||
|
||||
if (kstrtou16(field, 16, &pid))
|
||||
break;
|
||||
|
||||
field = strsep(&p, ",");
|
||||
if (!field || !*field)
|
||||
break;
|
||||
|
||||
/* Collect the flags */
|
||||
for (flags = 0; *field; field++) {
|
||||
switch (*field) {
|
||||
case 'a':
|
||||
flags |= USB_QUIRK_STRING_FETCH_255;
|
||||
break;
|
||||
case 'b':
|
||||
flags |= USB_QUIRK_RESET_RESUME;
|
||||
break;
|
||||
case 'c':
|
||||
flags |= USB_QUIRK_NO_SET_INTF;
|
||||
break;
|
||||
case 'd':
|
||||
flags |= USB_QUIRK_CONFIG_INTF_STRINGS;
|
||||
break;
|
||||
case 'e':
|
||||
flags |= USB_QUIRK_RESET;
|
||||
break;
|
||||
case 'f':
|
||||
flags |= USB_QUIRK_HONOR_BNUMINTERFACES;
|
||||
break;
|
||||
case 'g':
|
||||
flags |= USB_QUIRK_DELAY_INIT;
|
||||
break;
|
||||
case 'h':
|
||||
flags |= USB_QUIRK_LINEAR_UFRAME_INTR_BINTERVAL;
|
||||
break;
|
||||
case 'i':
|
||||
flags |= USB_QUIRK_DEVICE_QUALIFIER;
|
||||
break;
|
||||
case 'j':
|
||||
flags |= USB_QUIRK_IGNORE_REMOTE_WAKEUP;
|
||||
break;
|
||||
case 'k':
|
||||
flags |= USB_QUIRK_NO_LPM;
|
||||
break;
|
||||
case 'l':
|
||||
flags |= USB_QUIRK_LINEAR_FRAME_INTR_BINTERVAL;
|
||||
break;
|
||||
case 'm':
|
||||
flags |= USB_QUIRK_DISCONNECT_SUSPEND;
|
||||
break;
|
||||
case 'n':
|
||||
flags |= USB_QUIRK_DELAY_CTRL_MSG;
|
||||
break;
|
||||
/* Ignore unrecognized flag characters */
|
||||
}
|
||||
}
|
||||
|
||||
quirk_list[i++] = (struct quirk_entry)
|
||||
{ .vid = vid, .pid = pid, .flags = flags };
|
||||
}
|
||||
|
||||
if (i < quirk_count)
|
||||
quirk_count = i;
|
||||
|
||||
unlock:
|
||||
mutex_unlock(&quirk_mutex);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct kernel_param_ops quirks_param_ops = {
|
||||
.set = quirks_param_set,
|
||||
.get = param_get_string,
|
||||
};
|
||||
|
||||
static struct kparam_string quirks_param_string = {
|
||||
.maxlen = sizeof(quirks_param),
|
||||
.string = quirks_param,
|
||||
};
|
||||
|
||||
module_param_cb(quirks, &quirks_param_ops, &quirks_param_string, 0644);
|
||||
MODULE_PARM_DESC(quirks, "Add/modify USB quirks by specifying quirks=vendorID:productID:quirks");
|
||||
|
||||
/* Lists of quirky USB devices, split in device quirks and interface quirks.
|
||||
* Device quirks are applied at the very beginning of the enumeration process,
|
||||
* right after reading the device descriptor. They can thus only match on device
|
||||
@ -321,8 +467,8 @@ static int usb_amd_resume_quirk(struct usb_device *udev)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static u32 __usb_detect_quirks(struct usb_device *udev,
|
||||
const struct usb_device_id *id)
|
||||
static u32 usb_detect_static_quirks(struct usb_device *udev,
|
||||
const struct usb_device_id *id)
|
||||
{
|
||||
u32 quirks = 0;
|
||||
|
||||
@ -340,21 +486,43 @@ static u32 __usb_detect_quirks(struct usb_device *udev,
|
||||
return quirks;
|
||||
}
|
||||
|
||||
static u32 usb_detect_dynamic_quirks(struct usb_device *udev)
|
||||
{
|
||||
u16 vid = le16_to_cpu(udev->descriptor.idVendor);
|
||||
u16 pid = le16_to_cpu(udev->descriptor.idProduct);
|
||||
int i, flags = 0;
|
||||
|
||||
mutex_lock(&quirk_mutex);
|
||||
|
||||
for (i = 0; i < quirk_count; i++) {
|
||||
if (vid == quirk_list[i].vid && pid == quirk_list[i].pid) {
|
||||
flags = quirk_list[i].flags;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
mutex_unlock(&quirk_mutex);
|
||||
|
||||
return flags;
|
||||
}
|
||||
|
||||
/*
|
||||
* Detect any quirks the device has, and do any housekeeping for it if needed.
|
||||
*/
|
||||
void usb_detect_quirks(struct usb_device *udev)
|
||||
{
|
||||
udev->quirks = __usb_detect_quirks(udev, usb_quirk_list);
|
||||
udev->quirks = usb_detect_static_quirks(udev, usb_quirk_list);
|
||||
|
||||
/*
|
||||
* Pixart-based mice would trigger remote wakeup issue on AMD
|
||||
* Yangtze chipset, so set them as RESET_RESUME flag.
|
||||
*/
|
||||
if (usb_amd_resume_quirk(udev))
|
||||
udev->quirks |= __usb_detect_quirks(udev,
|
||||
udev->quirks |= usb_detect_static_quirks(udev,
|
||||
usb_amd_resume_quirk_list);
|
||||
|
||||
udev->quirks ^= usb_detect_dynamic_quirks(udev);
|
||||
|
||||
if (udev->quirks)
|
||||
dev_dbg(&udev->dev, "USB quirks for this device: %x\n",
|
||||
udev->quirks);
|
||||
@ -373,7 +541,7 @@ void usb_detect_interface_quirks(struct usb_device *udev)
|
||||
{
|
||||
u32 quirks;
|
||||
|
||||
quirks = __usb_detect_quirks(udev, usb_interface_quirk_list);
|
||||
quirks = usb_detect_static_quirks(udev, usb_interface_quirk_list);
|
||||
if (quirks == 0)
|
||||
return;
|
||||
|
||||
@ -381,3 +549,11 @@ void usb_detect_interface_quirks(struct usb_device *udev)
|
||||
quirks);
|
||||
udev->quirks |= quirks;
|
||||
}
|
||||
|
||||
void usb_release_quirk_list(void)
|
||||
{
|
||||
mutex_lock(&quirk_mutex);
|
||||
kfree(quirk_list);
|
||||
quirk_list = NULL;
|
||||
mutex_unlock(&quirk_mutex);
|
||||
}
|
||||
|
@ -433,6 +433,14 @@ int usb_submit_urb(struct urb *urb, gfp_t mem_flags)
|
||||
max *= mult;
|
||||
}
|
||||
|
||||
if (dev->speed == USB_SPEED_SUPER_PLUS &&
|
||||
USB_SS_SSP_ISOC_COMP(ep->ss_ep_comp.bmAttributes)) {
|
||||
struct usb_ssp_isoc_ep_comp_descriptor *isoc_ep_comp;
|
||||
|
||||
isoc_ep_comp = &ep->ssp_isoc_ep_comp;
|
||||
max = le32_to_cpu(isoc_ep_comp->dwBytesPerInterval);
|
||||
}
|
||||
|
||||
/* "high bandwidth" mode, 1-3 packets/uframe? */
|
||||
if (dev->speed == USB_SPEED_HIGH)
|
||||
max *= usb_endpoint_maxp_mult(&ep->desc);
|
||||
|
@ -90,8 +90,8 @@ static enum usb_port_connect_type usb_acpi_get_connect_type(acpi_handle handle,
|
||||
acpi_status status;
|
||||
|
||||
/*
|
||||
* According to ACPI Spec 9.13. PLD indicates whether usb port is
|
||||
* user visible and _UPC indicates whether it is connectable. If
|
||||
* According to 9.14 in ACPI Spec 6.2. _PLD indicates whether usb port
|
||||
* is user visible and _UPC indicates whether it is connectable. If
|
||||
* the port was visible and connectable, it could be freely connected
|
||||
* and disconnected with USB devices. If no visible and connectable,
|
||||
* a usb device is directly hard-wired to the port. If no visible and
|
||||
|
@ -1259,6 +1259,7 @@ static void __exit usb_exit(void)
|
||||
if (usb_disabled())
|
||||
return;
|
||||
|
||||
usb_release_quirk_list();
|
||||
usb_deregister_device_driver(&usb_generic_driver);
|
||||
usb_major_cleanup();
|
||||
usb_deregister(&usbfs_driver);
|
||||
|
@ -36,6 +36,7 @@ extern void usb_deauthorize_interface(struct usb_interface *);
|
||||
extern void usb_authorize_interface(struct usb_interface *);
|
||||
extern void usb_detect_quirks(struct usb_device *udev);
|
||||
extern void usb_detect_interface_quirks(struct usb_device *udev);
|
||||
extern void usb_release_quirk_list(void);
|
||||
extern int usb_remove_device(struct usb_device *udev);
|
||||
|
||||
extern int usb_get_device_descriptor(struct usb_device *dev,
|
||||
|
@ -64,10 +64,11 @@
|
||||
*
|
||||
* @hsotg: Programming view of the DWC_otg controller
|
||||
*/
|
||||
static int dwc2_backup_global_registers(struct dwc2_hsotg *hsotg)
|
||||
int dwc2_backup_global_registers(struct dwc2_hsotg *hsotg)
|
||||
{
|
||||
struct dwc2_gregs_backup *gr;
|
||||
int i;
|
||||
|
||||
dev_dbg(hsotg->dev, "%s\n", __func__);
|
||||
|
||||
/* Backup global regs */
|
||||
gr = &hsotg->gr_backup;
|
||||
@ -78,10 +79,11 @@ static int dwc2_backup_global_registers(struct dwc2_hsotg *hsotg)
|
||||
gr->gusbcfg = dwc2_readl(hsotg->regs + GUSBCFG);
|
||||
gr->grxfsiz = dwc2_readl(hsotg->regs + GRXFSIZ);
|
||||
gr->gnptxfsiz = dwc2_readl(hsotg->regs + GNPTXFSIZ);
|
||||
gr->hptxfsiz = dwc2_readl(hsotg->regs + HPTXFSIZ);
|
||||
gr->gdfifocfg = dwc2_readl(hsotg->regs + GDFIFOCFG);
|
||||
for (i = 0; i < MAX_EPS_CHANNELS; i++)
|
||||
gr->dtxfsiz[i] = dwc2_readl(hsotg->regs + DPTXFSIZN(i));
|
||||
gr->pcgcctl1 = dwc2_readl(hsotg->regs + PCGCCTL1);
|
||||
gr->glpmcfg = dwc2_readl(hsotg->regs + GLPMCFG);
|
||||
gr->gi2cctl = dwc2_readl(hsotg->regs + GI2CCTL);
|
||||
gr->pcgcctl = dwc2_readl(hsotg->regs + PCGCTL);
|
||||
|
||||
gr->valid = true;
|
||||
return 0;
|
||||
@ -94,10 +96,9 @@ static int dwc2_backup_global_registers(struct dwc2_hsotg *hsotg)
|
||||
*
|
||||
* @hsotg: Programming view of the DWC_otg controller
|
||||
*/
|
||||
static int dwc2_restore_global_registers(struct dwc2_hsotg *hsotg)
|
||||
int dwc2_restore_global_registers(struct dwc2_hsotg *hsotg)
|
||||
{
|
||||
struct dwc2_gregs_backup *gr;
|
||||
int i;
|
||||
|
||||
dev_dbg(hsotg->dev, "%s\n", __func__);
|
||||
|
||||
@ -117,26 +118,27 @@ static int dwc2_restore_global_registers(struct dwc2_hsotg *hsotg)
|
||||
dwc2_writel(gr->gahbcfg, hsotg->regs + GAHBCFG);
|
||||
dwc2_writel(gr->grxfsiz, hsotg->regs + GRXFSIZ);
|
||||
dwc2_writel(gr->gnptxfsiz, hsotg->regs + GNPTXFSIZ);
|
||||
dwc2_writel(gr->hptxfsiz, hsotg->regs + HPTXFSIZ);
|
||||
dwc2_writel(gr->gdfifocfg, hsotg->regs + GDFIFOCFG);
|
||||
for (i = 0; i < MAX_EPS_CHANNELS; i++)
|
||||
dwc2_writel(gr->dtxfsiz[i], hsotg->regs + DPTXFSIZN(i));
|
||||
dwc2_writel(gr->pcgcctl1, hsotg->regs + PCGCCTL1);
|
||||
dwc2_writel(gr->glpmcfg, hsotg->regs + GLPMCFG);
|
||||
dwc2_writel(gr->pcgcctl, hsotg->regs + PCGCTL);
|
||||
dwc2_writel(gr->gi2cctl, hsotg->regs + GI2CCTL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* dwc2_exit_hibernation() - Exit controller from Partial Power Down.
|
||||
* dwc2_exit_partial_power_down() - Exit controller from Partial Power Down.
|
||||
*
|
||||
* @hsotg: Programming view of the DWC_otg controller
|
||||
* @restore: Controller registers need to be restored
|
||||
*/
|
||||
int dwc2_exit_hibernation(struct dwc2_hsotg *hsotg, bool restore)
|
||||
int dwc2_exit_partial_power_down(struct dwc2_hsotg *hsotg, bool restore)
|
||||
{
|
||||
u32 pcgcctl;
|
||||
int ret = 0;
|
||||
|
||||
if (!hsotg->params.hibernation)
|
||||
if (hsotg->params.power_down != DWC2_POWER_DOWN_PARAM_PARTIAL)
|
||||
return -ENOTSUPP;
|
||||
|
||||
pcgcctl = dwc2_readl(hsotg->regs + PCGCTL);
|
||||
@ -167,7 +169,7 @@ int dwc2_exit_hibernation(struct dwc2_hsotg *hsotg, bool restore)
|
||||
return ret;
|
||||
}
|
||||
} else {
|
||||
ret = dwc2_restore_device_registers(hsotg);
|
||||
ret = dwc2_restore_device_registers(hsotg, 0);
|
||||
if (ret) {
|
||||
dev_err(hsotg->dev, "%s: failed to restore device registers\n",
|
||||
__func__);
|
||||
@ -180,16 +182,16 @@ int dwc2_exit_hibernation(struct dwc2_hsotg *hsotg, bool restore)
|
||||
}
|
||||
|
||||
/**
|
||||
* dwc2_enter_hibernation() - Put controller in Partial Power Down.
|
||||
* dwc2_enter_partial_power_down() - Put controller in Partial Power Down.
|
||||
*
|
||||
* @hsotg: Programming view of the DWC_otg controller
|
||||
*/
|
||||
int dwc2_enter_hibernation(struct dwc2_hsotg *hsotg)
|
||||
int dwc2_enter_partial_power_down(struct dwc2_hsotg *hsotg)
|
||||
{
|
||||
u32 pcgcctl;
|
||||
int ret = 0;
|
||||
|
||||
if (!hsotg->params.hibernation)
|
||||
if (!hsotg->params.power_down)
|
||||
return -ENOTSUPP;
|
||||
|
||||
/* Backup all registers */
|
||||
@ -218,7 +220,7 @@ int dwc2_enter_hibernation(struct dwc2_hsotg *hsotg)
|
||||
|
||||
/*
|
||||
* Clear any pending interrupts since dwc2 will not be able to
|
||||
* clear them after entering hibernation.
|
||||
* clear them after entering partial_power_down.
|
||||
*/
|
||||
dwc2_writel(0xffffffff, hsotg->regs + GINTSTS);
|
||||
|
||||
@ -239,6 +241,142 @@ int dwc2_enter_hibernation(struct dwc2_hsotg *hsotg)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* dwc2_restore_essential_regs() - Restore essiential regs of core.
|
||||
*
|
||||
* @hsotg: Programming view of the DWC_otg controller
|
||||
* @rmode: Restore mode, enabled in case of remote-wakeup.
|
||||
* @is_host: Host or device mode.
|
||||
*/
|
||||
static void dwc2_restore_essential_regs(struct dwc2_hsotg *hsotg, int rmode,
|
||||
int is_host)
|
||||
{
|
||||
u32 pcgcctl;
|
||||
struct dwc2_gregs_backup *gr;
|
||||
struct dwc2_dregs_backup *dr;
|
||||
struct dwc2_hregs_backup *hr;
|
||||
|
||||
gr = &hsotg->gr_backup;
|
||||
dr = &hsotg->dr_backup;
|
||||
hr = &hsotg->hr_backup;
|
||||
|
||||
dev_dbg(hsotg->dev, "%s: restoring essential regs\n", __func__);
|
||||
|
||||
/* Load restore values for [31:14] bits */
|
||||
pcgcctl = (gr->pcgcctl & 0xffffc000);
|
||||
/* If High Speed */
|
||||
if (is_host) {
|
||||
if (!(pcgcctl & PCGCTL_P2HD_PRT_SPD_MASK))
|
||||
pcgcctl |= BIT(17);
|
||||
} else {
|
||||
if (!(pcgcctl & PCGCTL_P2HD_DEV_ENUM_SPD_MASK))
|
||||
pcgcctl |= BIT(17);
|
||||
}
|
||||
dwc2_writel(pcgcctl, hsotg->regs + PCGCTL);
|
||||
|
||||
/* Umnask global Interrupt in GAHBCFG and restore it */
|
||||
dwc2_writel(gr->gahbcfg | GAHBCFG_GLBL_INTR_EN, hsotg->regs + GAHBCFG);
|
||||
|
||||
/* Clear all pending interupts */
|
||||
dwc2_writel(0xffffffff, hsotg->regs + GINTSTS);
|
||||
|
||||
/* Unmask restore done interrupt */
|
||||
dwc2_writel(GINTSTS_RESTOREDONE, hsotg->regs + GINTMSK);
|
||||
|
||||
/* Restore GUSBCFG and HCFG/DCFG */
|
||||
dwc2_writel(gr->gusbcfg, hsotg->regs + GUSBCFG);
|
||||
|
||||
if (is_host) {
|
||||
dwc2_writel(hr->hcfg, hsotg->regs + HCFG);
|
||||
if (rmode)
|
||||
pcgcctl |= PCGCTL_RESTOREMODE;
|
||||
dwc2_writel(pcgcctl, hsotg->regs + PCGCTL);
|
||||
udelay(10);
|
||||
|
||||
pcgcctl |= PCGCTL_ESS_REG_RESTORED;
|
||||
dwc2_writel(pcgcctl, hsotg->regs + PCGCTL);
|
||||
udelay(10);
|
||||
} else {
|
||||
dwc2_writel(dr->dcfg, hsotg->regs + DCFG);
|
||||
if (!rmode)
|
||||
pcgcctl |= PCGCTL_RESTOREMODE | PCGCTL_RSTPDWNMODULE;
|
||||
dwc2_writel(pcgcctl, hsotg->regs + PCGCTL);
|
||||
udelay(10);
|
||||
|
||||
pcgcctl |= PCGCTL_ESS_REG_RESTORED;
|
||||
dwc2_writel(pcgcctl, hsotg->regs + PCGCTL);
|
||||
udelay(10);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* dwc2_hib_restore_common() - Common part of restore routine.
|
||||
*
|
||||
* @hsotg: Programming view of the DWC_otg controller
|
||||
* @rem_wakeup: Remote-wakeup, enabled in case of remote-wakeup.
|
||||
* @is_host: Host or device mode.
|
||||
*/
|
||||
void dwc2_hib_restore_common(struct dwc2_hsotg *hsotg, int rem_wakeup,
|
||||
int is_host)
|
||||
{
|
||||
u32 gpwrdn;
|
||||
|
||||
/* Switch-on voltage to the core */
|
||||
gpwrdn = dwc2_readl(hsotg->regs + GPWRDN);
|
||||
gpwrdn &= ~GPWRDN_PWRDNSWTCH;
|
||||
dwc2_writel(gpwrdn, hsotg->regs + GPWRDN);
|
||||
udelay(10);
|
||||
|
||||
/* Reset core */
|
||||
gpwrdn = dwc2_readl(hsotg->regs + GPWRDN);
|
||||
gpwrdn &= ~GPWRDN_PWRDNRSTN;
|
||||
dwc2_writel(gpwrdn, hsotg->regs + GPWRDN);
|
||||
udelay(10);
|
||||
|
||||
/* Enable restore from PMU */
|
||||
gpwrdn = dwc2_readl(hsotg->regs + GPWRDN);
|
||||
gpwrdn |= GPWRDN_RESTORE;
|
||||
dwc2_writel(gpwrdn, hsotg->regs + GPWRDN);
|
||||
udelay(10);
|
||||
|
||||
/* Disable Power Down Clamp */
|
||||
gpwrdn = dwc2_readl(hsotg->regs + GPWRDN);
|
||||
gpwrdn &= ~GPWRDN_PWRDNCLMP;
|
||||
dwc2_writel(gpwrdn, hsotg->regs + GPWRDN);
|
||||
udelay(50);
|
||||
|
||||
if (!is_host && rem_wakeup)
|
||||
udelay(70);
|
||||
|
||||
/* Deassert reset core */
|
||||
gpwrdn = dwc2_readl(hsotg->regs + GPWRDN);
|
||||
gpwrdn |= GPWRDN_PWRDNRSTN;
|
||||
dwc2_writel(gpwrdn, hsotg->regs + GPWRDN);
|
||||
udelay(10);
|
||||
|
||||
/* Disable PMU interrupt */
|
||||
gpwrdn = dwc2_readl(hsotg->regs + GPWRDN);
|
||||
gpwrdn &= ~GPWRDN_PMUINTSEL;
|
||||
dwc2_writel(gpwrdn, hsotg->regs + GPWRDN);
|
||||
udelay(10);
|
||||
|
||||
/* Set Restore Essential Regs bit in PCGCCTL register */
|
||||
dwc2_restore_essential_regs(hsotg, rem_wakeup, is_host);
|
||||
|
||||
/*
|
||||
* Wait For Restore_done Interrupt. This mechanism of polling the
|
||||
* interrupt is introduced to avoid any possible race conditions
|
||||
*/
|
||||
if (dwc2_hsotg_wait_bit_set(hsotg, GINTSTS, GINTSTS_RESTOREDONE,
|
||||
20000)) {
|
||||
dev_dbg(hsotg->dev,
|
||||
"%s: Restore Done wan't generated here\n",
|
||||
__func__);
|
||||
} else {
|
||||
dev_dbg(hsotg->dev, "restore done generated here\n");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* dwc2_wait_for_mode() - Waits for the controller mode.
|
||||
* @hsotg: Programming view of the DWC_otg controller.
|
||||
@ -310,6 +448,44 @@ static bool dwc2_iddig_filter_enabled(struct dwc2_hsotg *hsotg)
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* dwc2_enter_hibernation() - Common function to enter hibernation.
|
||||
*
|
||||
* @hsotg: Programming view of the DWC_otg controller
|
||||
* @is_host: True if core is in host mode.
|
||||
*
|
||||
* Return: 0 if successful, negative error code otherwise
|
||||
*/
|
||||
int dwc2_enter_hibernation(struct dwc2_hsotg *hsotg, int is_host)
|
||||
{
|
||||
if (hsotg->params.power_down != DWC2_POWER_DOWN_PARAM_HIBERNATION)
|
||||
return -ENOTSUPP;
|
||||
|
||||
if (is_host)
|
||||
return dwc2_host_enter_hibernation(hsotg);
|
||||
else
|
||||
return dwc2_gadget_enter_hibernation(hsotg);
|
||||
}
|
||||
|
||||
/*
|
||||
* dwc2_exit_hibernation() - Common function to exit from hibernation.
|
||||
*
|
||||
* @hsotg: Programming view of the DWC_otg controller
|
||||
* @rem_wakeup: Remote-wakeup, enabled in case of remote-wakeup.
|
||||
* @reset: Enabled in case of restore with reset.
|
||||
* @is_host: True if core is in host mode.
|
||||
*
|
||||
* Return: 0 if successful, negative error code otherwise
|
||||
*/
|
||||
int dwc2_exit_hibernation(struct dwc2_hsotg *hsotg, int rem_wakeup,
|
||||
int reset, int is_host)
|
||||
{
|
||||
if (is_host)
|
||||
return dwc2_host_exit_hibernation(hsotg, rem_wakeup, reset);
|
||||
else
|
||||
return dwc2_gadget_exit_hibernation(hsotg, rem_wakeup, reset);
|
||||
}
|
||||
|
||||
/*
|
||||
* Do core a soft reset of the core. Be careful with this because it
|
||||
* resets all the internal state machines of the core.
|
||||
@ -317,7 +493,6 @@ static bool dwc2_iddig_filter_enabled(struct dwc2_hsotg *hsotg)
|
||||
int dwc2_core_reset(struct dwc2_hsotg *hsotg, bool skip_wait)
|
||||
{
|
||||
u32 greset;
|
||||
int count = 0;
|
||||
bool wait_for_host_mode = false;
|
||||
|
||||
dev_vdbg(hsotg->dev, "%s()\n", __func__);
|
||||
@ -346,29 +521,19 @@ int dwc2_core_reset(struct dwc2_hsotg *hsotg, bool skip_wait)
|
||||
greset = dwc2_readl(hsotg->regs + GRSTCTL);
|
||||
greset |= GRSTCTL_CSFTRST;
|
||||
dwc2_writel(greset, hsotg->regs + GRSTCTL);
|
||||
do {
|
||||
udelay(1);
|
||||
greset = dwc2_readl(hsotg->regs + GRSTCTL);
|
||||
if (++count > 50) {
|
||||
dev_warn(hsotg->dev,
|
||||
"%s() HANG! Soft Reset GRSTCTL=%0x\n",
|
||||
__func__, greset);
|
||||
return -EBUSY;
|
||||
}
|
||||
} while (greset & GRSTCTL_CSFTRST);
|
||||
|
||||
if (dwc2_hsotg_wait_bit_clear(hsotg, GRSTCTL, GRSTCTL_CSFTRST, 50)) {
|
||||
dev_warn(hsotg->dev, "%s: HANG! Soft Reset timeout GRSTCTL GRSTCTL_CSFTRST\n",
|
||||
__func__);
|
||||
return -EBUSY;
|
||||
}
|
||||
|
||||
/* Wait for AHB master IDLE state */
|
||||
count = 0;
|
||||
do {
|
||||
udelay(1);
|
||||
greset = dwc2_readl(hsotg->regs + GRSTCTL);
|
||||
if (++count > 50) {
|
||||
dev_warn(hsotg->dev,
|
||||
"%s() HANG! AHB Idle GRSTCTL=%0x\n",
|
||||
__func__, greset);
|
||||
return -EBUSY;
|
||||
}
|
||||
} while (!(greset & GRSTCTL_AHBIDLE));
|
||||
if (dwc2_hsotg_wait_bit_set(hsotg, GRSTCTL, GRSTCTL_AHBIDLE, 50)) {
|
||||
dev_warn(hsotg->dev, "%s: HANG! AHB Idle timeout GRSTCTL GRSTCTL_AHBIDLE\n",
|
||||
__func__);
|
||||
return -EBUSY;
|
||||
}
|
||||
|
||||
if (wait_for_host_mode && !skip_wait)
|
||||
dwc2_wait_for_mode(hsotg, true);
|
||||
@ -376,14 +541,14 @@ int dwc2_core_reset(struct dwc2_hsotg *hsotg, bool skip_wait)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Force the mode of the controller.
|
||||
/**
|
||||
* dwc2_force_mode() - Force the mode of the controller.
|
||||
*
|
||||
* Forcing the mode is needed for two cases:
|
||||
*
|
||||
* 1) If the dr_mode is set to either HOST or PERIPHERAL we force the
|
||||
* controller to stay in a particular mode regardless of ID pin
|
||||
* changes. We do this usually after a core reset.
|
||||
* changes. We do this once during probe.
|
||||
*
|
||||
* 2) During probe we want to read reset values of the hw
|
||||
* configuration registers that are only available in either host or
|
||||
@ -400,7 +565,7 @@ int dwc2_core_reset(struct dwc2_hsotg *hsotg, bool skip_wait)
|
||||
* the filter is configured and enabled. We poll the current mode of
|
||||
* the controller to account for this delay.
|
||||
*/
|
||||
static bool dwc2_force_mode(struct dwc2_hsotg *hsotg, bool host)
|
||||
void dwc2_force_mode(struct dwc2_hsotg *hsotg, bool host)
|
||||
{
|
||||
u32 gusbcfg;
|
||||
u32 set;
|
||||
@ -412,17 +577,17 @@ static bool dwc2_force_mode(struct dwc2_hsotg *hsotg, bool host)
|
||||
* Force mode has no effect if the hardware is not OTG.
|
||||
*/
|
||||
if (!dwc2_hw_is_otg(hsotg))
|
||||
return false;
|
||||
return;
|
||||
|
||||
/*
|
||||
* If dr_mode is either peripheral or host only, there is no
|
||||
* need to ever force the mode to the opposite mode.
|
||||
*/
|
||||
if (WARN_ON(host && hsotg->dr_mode == USB_DR_MODE_PERIPHERAL))
|
||||
return false;
|
||||
return;
|
||||
|
||||
if (WARN_ON(!host && hsotg->dr_mode == USB_DR_MODE_HOST))
|
||||
return false;
|
||||
return;
|
||||
|
||||
gusbcfg = dwc2_readl(hsotg->regs + GUSBCFG);
|
||||
|
||||
@ -434,7 +599,7 @@ static bool dwc2_force_mode(struct dwc2_hsotg *hsotg, bool host)
|
||||
dwc2_writel(gusbcfg, hsotg->regs + GUSBCFG);
|
||||
|
||||
dwc2_wait_for_mode(hsotg, host);
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -446,10 +611,15 @@ static bool dwc2_force_mode(struct dwc2_hsotg *hsotg, bool host)
|
||||
* the force mode. We only need to call this once during probe if
|
||||
* dr_mode == OTG.
|
||||
*/
|
||||
void dwc2_clear_force_mode(struct dwc2_hsotg *hsotg)
|
||||
static void dwc2_clear_force_mode(struct dwc2_hsotg *hsotg)
|
||||
{
|
||||
u32 gusbcfg;
|
||||
|
||||
if (!dwc2_hw_is_otg(hsotg))
|
||||
return;
|
||||
|
||||
dev_dbg(hsotg->dev, "Clearing force mode bits\n");
|
||||
|
||||
gusbcfg = dwc2_readl(hsotg->regs + GUSBCFG);
|
||||
gusbcfg &= ~GUSBCFG_FORCEHOSTMODE;
|
||||
gusbcfg &= ~GUSBCFG_FORCEDEVMODE;
|
||||
@ -464,16 +634,13 @@ void dwc2_clear_force_mode(struct dwc2_hsotg *hsotg)
|
||||
*/
|
||||
void dwc2_force_dr_mode(struct dwc2_hsotg *hsotg)
|
||||
{
|
||||
bool ret;
|
||||
|
||||
switch (hsotg->dr_mode) {
|
||||
case USB_DR_MODE_HOST:
|
||||
ret = dwc2_force_mode(hsotg, true);
|
||||
/*
|
||||
* NOTE: This is required for some rockchip soc based
|
||||
* platforms on their host-only dwc2.
|
||||
*/
|
||||
if (!ret)
|
||||
if (!dwc2_hw_is_otg(hsotg))
|
||||
msleep(50);
|
||||
|
||||
break;
|
||||
@ -491,22 +658,17 @@ void dwc2_force_dr_mode(struct dwc2_hsotg *hsotg)
|
||||
}
|
||||
|
||||
/*
|
||||
* Do core a soft reset of the core. Be careful with this because it
|
||||
* resets all the internal state machines of the core.
|
||||
*
|
||||
* Additionally this will apply force mode as per the hsotg->dr_mode
|
||||
* parameter.
|
||||
* dwc2_enable_acg - enable active clock gating feature
|
||||
*/
|
||||
int dwc2_core_reset_and_force_dr_mode(struct dwc2_hsotg *hsotg)
|
||||
void dwc2_enable_acg(struct dwc2_hsotg *hsotg)
|
||||
{
|
||||
int retval;
|
||||
if (hsotg->params.acg_enable) {
|
||||
u32 pcgcctl1 = dwc2_readl(hsotg->regs + PCGCCTL1);
|
||||
|
||||
retval = dwc2_core_reset(hsotg, false);
|
||||
if (retval)
|
||||
return retval;
|
||||
|
||||
dwc2_force_dr_mode(hsotg);
|
||||
return 0;
|
||||
dev_dbg(hsotg->dev, "Enabling Active Clock Gating\n");
|
||||
pcgcctl1 |= PCGCCTL1_GATEEN;
|
||||
dwc2_writel(pcgcctl1, hsotg->regs + PCGCCTL1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -683,25 +845,21 @@ void dwc2_dump_global_registers(struct dwc2_hsotg *hsotg)
|
||||
void dwc2_flush_tx_fifo(struct dwc2_hsotg *hsotg, const int num)
|
||||
{
|
||||
u32 greset;
|
||||
int count = 0;
|
||||
|
||||
dev_vdbg(hsotg->dev, "Flush Tx FIFO %d\n", num);
|
||||
|
||||
/* Wait for AHB master IDLE state */
|
||||
if (dwc2_hsotg_wait_bit_set(hsotg, GRSTCTL, GRSTCTL_AHBIDLE, 10000))
|
||||
dev_warn(hsotg->dev, "%s: HANG! AHB Idle GRSCTL\n",
|
||||
__func__);
|
||||
|
||||
greset = GRSTCTL_TXFFLSH;
|
||||
greset |= num << GRSTCTL_TXFNUM_SHIFT & GRSTCTL_TXFNUM_MASK;
|
||||
dwc2_writel(greset, hsotg->regs + GRSTCTL);
|
||||
|
||||
do {
|
||||
greset = dwc2_readl(hsotg->regs + GRSTCTL);
|
||||
if (++count > 10000) {
|
||||
dev_warn(hsotg->dev,
|
||||
"%s() HANG! GRSTCTL=%0x GNPTXSTS=0x%08x\n",
|
||||
__func__, greset,
|
||||
dwc2_readl(hsotg->regs + GNPTXSTS));
|
||||
break;
|
||||
}
|
||||
udelay(1);
|
||||
} while (greset & GRSTCTL_TXFFLSH);
|
||||
if (dwc2_hsotg_wait_bit_clear(hsotg, GRSTCTL, GRSTCTL_TXFFLSH, 10000))
|
||||
dev_warn(hsotg->dev, "%s: HANG! timeout GRSTCTL GRSTCTL_TXFFLSH\n",
|
||||
__func__);
|
||||
|
||||
/* Wait for at least 3 PHY Clocks */
|
||||
udelay(1);
|
||||
@ -715,43 +873,26 @@ void dwc2_flush_tx_fifo(struct dwc2_hsotg *hsotg, const int num)
|
||||
void dwc2_flush_rx_fifo(struct dwc2_hsotg *hsotg)
|
||||
{
|
||||
u32 greset;
|
||||
int count = 0;
|
||||
|
||||
dev_vdbg(hsotg->dev, "%s()\n", __func__);
|
||||
|
||||
/* Wait for AHB master IDLE state */
|
||||
if (dwc2_hsotg_wait_bit_set(hsotg, GRSTCTL, GRSTCTL_AHBIDLE, 10000))
|
||||
dev_warn(hsotg->dev, "%s: HANG! AHB Idle GRSCTL\n",
|
||||
__func__);
|
||||
|
||||
greset = GRSTCTL_RXFFLSH;
|
||||
dwc2_writel(greset, hsotg->regs + GRSTCTL);
|
||||
|
||||
do {
|
||||
greset = dwc2_readl(hsotg->regs + GRSTCTL);
|
||||
if (++count > 10000) {
|
||||
dev_warn(hsotg->dev, "%s() HANG! GRSTCTL=%0x\n",
|
||||
__func__, greset);
|
||||
break;
|
||||
}
|
||||
udelay(1);
|
||||
} while (greset & GRSTCTL_RXFFLSH);
|
||||
/* Wait for RxFIFO flush done */
|
||||
if (dwc2_hsotg_wait_bit_clear(hsotg, GRSTCTL, GRSTCTL_RXFFLSH, 10000))
|
||||
dev_warn(hsotg->dev, "%s: HANG! timeout GRSTCTL GRSTCTL_RXFFLSH\n",
|
||||
__func__);
|
||||
|
||||
/* Wait for at least 3 PHY Clocks */
|
||||
udelay(1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Forces either host or device mode if the controller is not
|
||||
* currently in that mode.
|
||||
*
|
||||
* Returns true if the mode was forced.
|
||||
*/
|
||||
bool dwc2_force_mode_if_needed(struct dwc2_hsotg *hsotg, bool host)
|
||||
{
|
||||
if (host && dwc2_is_host_mode(hsotg))
|
||||
return false;
|
||||
else if (!host && dwc2_is_device_mode(hsotg))
|
||||
return false;
|
||||
|
||||
return dwc2_force_mode(hsotg, host);
|
||||
}
|
||||
|
||||
bool dwc2_is_controller_alive(struct dwc2_hsotg *hsotg)
|
||||
{
|
||||
if (dwc2_readl(hsotg->regs + GSNPSID) == 0xffffffff)
|
||||
@ -825,6 +966,52 @@ bool dwc2_hw_is_device(struct dwc2_hsotg *hsotg)
|
||||
(op_mode == GHWCFG2_OP_MODE_NO_SRP_CAPABLE_DEVICE);
|
||||
}
|
||||
|
||||
/**
|
||||
* dwc2_hsotg_wait_bit_set - Waits for bit to be set.
|
||||
* @hsotg: Programming view of DWC_otg controller.
|
||||
* @offset: Register's offset where bit/bits must be set.
|
||||
* @mask: Mask of the bit/bits which must be set.
|
||||
* @timeout: Timeout to wait.
|
||||
*
|
||||
* Return: 0 if bit/bits are set or -ETIMEDOUT in case of timeout.
|
||||
*/
|
||||
int dwc2_hsotg_wait_bit_set(struct dwc2_hsotg *hsotg, u32 offset, u32 mask,
|
||||
u32 timeout)
|
||||
{
|
||||
u32 i;
|
||||
|
||||
for (i = 0; i < timeout; i++) {
|
||||
if (dwc2_readl(hsotg->regs + offset) & mask)
|
||||
return 0;
|
||||
udelay(1);
|
||||
}
|
||||
|
||||
return -ETIMEDOUT;
|
||||
}
|
||||
|
||||
/**
|
||||
* dwc2_hsotg_wait_bit_clear - Waits for bit to be clear.
|
||||
* @hsotg: Programming view of DWC_otg controller.
|
||||
* @offset: Register's offset where bit/bits must be set.
|
||||
* @mask: Mask of the bit/bits which must be set.
|
||||
* @timeout: Timeout to wait.
|
||||
*
|
||||
* Return: 0 if bit/bits are set or -ETIMEDOUT in case of timeout.
|
||||
*/
|
||||
int dwc2_hsotg_wait_bit_clear(struct dwc2_hsotg *hsotg, u32 offset, u32 mask,
|
||||
u32 timeout)
|
||||
{
|
||||
u32 i;
|
||||
|
||||
for (i = 0; i < timeout; i++) {
|
||||
if (!(dwc2_readl(hsotg->regs + offset) & mask))
|
||||
return 0;
|
||||
udelay(1);
|
||||
}
|
||||
|
||||
return -ETIMEDOUT;
|
||||
}
|
||||
|
||||
MODULE_DESCRIPTION("DESIGNWARE HS OTG Core");
|
||||
MODULE_AUTHOR("Synopsys, Inc.");
|
||||
MODULE_LICENSE("Dual BSD/GPL");
|
||||
|
@ -217,7 +217,7 @@ struct dwc2_hsotg_ep {
|
||||
unsigned char dir_in;
|
||||
unsigned char index;
|
||||
unsigned char mc;
|
||||
unsigned char interval;
|
||||
u16 interval;
|
||||
|
||||
unsigned int halted:1;
|
||||
unsigned int periodic:1;
|
||||
@ -408,7 +408,7 @@ enum dwc2_ep0_state {
|
||||
* @ahbcfg: This field allows the default value of the GAHBCFG
|
||||
* register to be overridden
|
||||
* -1 - GAHBCFG value will be set to 0x06
|
||||
* (INCR4, default)
|
||||
* (INCR, default)
|
||||
* all others - GAHBCFG value will be overridden with
|
||||
* this value
|
||||
* Not all bits can be controlled like this, the
|
||||
@ -421,12 +421,26 @@ enum dwc2_ep0_state {
|
||||
* case.
|
||||
* 0 - No (default)
|
||||
* 1 - Yes
|
||||
* @hibernation: Specifies whether the controller support hibernation.
|
||||
* If hibernation is enabled, the controller will enter
|
||||
* hibernation in both peripheral and host mode when
|
||||
* @power_down: Specifies whether the controller support power_down.
|
||||
* If power_down is enabled, the controller will enter
|
||||
* power_down in both peripheral and host mode when
|
||||
* needed.
|
||||
* 0 - No (default)
|
||||
* 1 - Partial power down
|
||||
* 2 - Hibernation
|
||||
* @lpm: Enable LPM support.
|
||||
* 0 - No
|
||||
* 1 - Yes
|
||||
* @lpm_clock_gating: Enable core PHY clock gating.
|
||||
* 0 - No
|
||||
* 1 - Yes
|
||||
* @besl: Enable LPM Errata support.
|
||||
* 0 - No
|
||||
* 1 - Yes
|
||||
* @hird_threshold_en: HIRD or HIRD Threshold enable.
|
||||
* 0 - No
|
||||
* 1 - Yes
|
||||
* @hird_threshold: Value of BESL or HIRD Threshold.
|
||||
* @activate_stm_fs_transceiver: Activate internal transceiver using GGPIO
|
||||
* register.
|
||||
* 0 - Deactivate the transceiver (default)
|
||||
@ -479,12 +493,23 @@ struct dwc2_core_params {
|
||||
bool enable_dynamic_fifo;
|
||||
bool en_multiple_tx_fifo;
|
||||
bool i2c_enable;
|
||||
bool acg_enable;
|
||||
bool ulpi_fs_ls;
|
||||
bool ts_dline;
|
||||
bool reload_ctl;
|
||||
bool uframe_sched;
|
||||
bool external_id_pin_ctl;
|
||||
bool hibernation;
|
||||
|
||||
int power_down;
|
||||
#define DWC2_POWER_DOWN_PARAM_NONE 0
|
||||
#define DWC2_POWER_DOWN_PARAM_PARTIAL 1
|
||||
#define DWC2_POWER_DOWN_PARAM_HIBERNATION 2
|
||||
|
||||
bool lpm;
|
||||
bool lpm_clock_gating;
|
||||
bool besl;
|
||||
bool hird_threshold_en;
|
||||
u8 hird_threshold;
|
||||
bool activate_stm_fs_transceiver;
|
||||
u16 max_packet_count;
|
||||
u32 max_transfer_size;
|
||||
@ -560,6 +585,7 @@ struct dwc2_core_params {
|
||||
* 2 - FS pins shared with UTMI+ pins
|
||||
* 3 - FS pins shared with ULPI pins
|
||||
* @total_fifo_size: Total internal RAM for FIFOs (bytes)
|
||||
* @hibernation Is hibernation enabled?
|
||||
* @utmi_phy_data_width UTMI+ PHY data width
|
||||
* 0 - 8 bits
|
||||
* 1 - 16 bits
|
||||
@ -587,12 +613,15 @@ struct dwc2_hw_params {
|
||||
unsigned hs_phy_type:2;
|
||||
unsigned fs_phy_type:2;
|
||||
unsigned i2c_enable:1;
|
||||
unsigned acg_enable:1;
|
||||
unsigned num_dev_ep:4;
|
||||
unsigned num_dev_in_eps : 4;
|
||||
unsigned num_dev_perio_in_ep:4;
|
||||
unsigned total_fifo_size:16;
|
||||
unsigned power_optimized:1;
|
||||
unsigned hibernation:1;
|
||||
unsigned utmi_phy_data_width:2;
|
||||
unsigned lpm_mode:1;
|
||||
u32 snpsid;
|
||||
u32 dev_ep_dirs;
|
||||
u32 g_tx_fifo_size[MAX_EPS_CHANNELS];
|
||||
@ -611,9 +640,8 @@ struct dwc2_hw_params {
|
||||
* @grxfsiz: Backup of GRXFSIZ register
|
||||
* @gnptxfsiz: Backup of GNPTXFSIZ register
|
||||
* @gi2cctl: Backup of GI2CCTL register
|
||||
* @hptxfsiz: Backup of HPTXFSIZ register
|
||||
* @glpmcfg: Backup of GLPMCFG register
|
||||
* @gdfifocfg: Backup of GDFIFOCFG register
|
||||
* @dtxfsiz: Backup of DTXFSIZ registers for each endpoint
|
||||
* @gpwrdn: Backup of GPWRDN register
|
||||
*/
|
||||
struct dwc2_gregs_backup {
|
||||
@ -624,10 +652,10 @@ struct dwc2_gregs_backup {
|
||||
u32 grxfsiz;
|
||||
u32 gnptxfsiz;
|
||||
u32 gi2cctl;
|
||||
u32 hptxfsiz;
|
||||
u32 glpmcfg;
|
||||
u32 pcgcctl;
|
||||
u32 pcgcctl1;
|
||||
u32 gdfifocfg;
|
||||
u32 dtxfsiz[MAX_EPS_CHANNELS];
|
||||
u32 gpwrdn;
|
||||
bool valid;
|
||||
};
|
||||
@ -646,6 +674,7 @@ struct dwc2_gregs_backup {
|
||||
* @doepctl: Backup of DOEPCTL register
|
||||
* @doeptsiz: Backup of DOEPTSIZ register
|
||||
* @doepdma: Backup of DOEPDMA register
|
||||
* @dtxfsiz: Backup of DTXFSIZ registers for each endpoint
|
||||
*/
|
||||
struct dwc2_dregs_backup {
|
||||
u32 dcfg;
|
||||
@ -659,6 +688,7 @@ struct dwc2_dregs_backup {
|
||||
u32 doepctl[MAX_EPS_CHANNELS];
|
||||
u32 doeptsiz[MAX_EPS_CHANNELS];
|
||||
u32 doepdma[MAX_EPS_CHANNELS];
|
||||
u32 dtxfsiz[MAX_EPS_CHANNELS];
|
||||
bool valid;
|
||||
};
|
||||
|
||||
@ -670,6 +700,7 @@ struct dwc2_dregs_backup {
|
||||
* @hcintmsk: Backup of HCINTMSK register
|
||||
* @hptr0: Backup of HPTR0 register
|
||||
* @hfir: Backup of HFIR register
|
||||
* @hptxfsiz: Backup of HPTXFSIZ register
|
||||
*/
|
||||
struct dwc2_hregs_backup {
|
||||
u32 hcfg;
|
||||
@ -677,6 +708,7 @@ struct dwc2_hregs_backup {
|
||||
u32 hcintmsk[MAX_EPS_CHANNELS];
|
||||
u32 hprt0;
|
||||
u32 hfir;
|
||||
u32 hptxfsiz;
|
||||
bool valid;
|
||||
};
|
||||
|
||||
@ -780,12 +812,14 @@ struct dwc2_hregs_backup {
|
||||
* @hcd_enabled Host mode sub-driver initialization indicator.
|
||||
* @gadget_enabled Peripheral mode sub-driver initialization indicator.
|
||||
* @ll_hw_enabled Status of low-level hardware resources.
|
||||
* @hibernated: True if core is hibernated
|
||||
* @phy: The otg phy transceiver structure for phy control.
|
||||
* @uphy: The otg phy transceiver structure for old USB phy
|
||||
* control.
|
||||
* @plat: The platform specific configuration data. This can be
|
||||
* removed once all SoCs support usb transceiver.
|
||||
* @supplies: Definition of USB power supplies
|
||||
* @vbus_supply: Regulator supplying vbus.
|
||||
* @phyif: PHY interface width
|
||||
* @lock: Spinlock that protects all the driver data structures
|
||||
* @priv: Stores a pointer to the struct usb_hcd
|
||||
@ -897,6 +931,8 @@ struct dwc2_hregs_backup {
|
||||
* @ctrl_req: Request for EP0 control packets.
|
||||
* @ep0_state: EP0 control transfers state
|
||||
* @test_mode: USB test mode requested by the host
|
||||
* @remote_wakeup_allowed: True if device is allowed to wake-up host by
|
||||
* remote-wakeup signalling
|
||||
* @setup_desc_dma: EP0 setup stage desc chain DMA address
|
||||
* @setup_desc: EP0 setup stage desc chain pointer
|
||||
* @ctrl_in_desc_dma: EP0 IN data phase desc chain DMA address
|
||||
@ -917,11 +953,13 @@ struct dwc2_hsotg {
|
||||
unsigned int hcd_enabled:1;
|
||||
unsigned int gadget_enabled:1;
|
||||
unsigned int ll_hw_enabled:1;
|
||||
unsigned int hibernated:1;
|
||||
|
||||
struct phy *phy;
|
||||
struct usb_phy *uphy;
|
||||
struct dwc2_hsotg_plat *plat;
|
||||
struct regulator_bulk_data supplies[DWC2_NUM_SUPPLIES];
|
||||
struct regulator *vbus_supply;
|
||||
u32 phyif;
|
||||
|
||||
spinlock_t lock;
|
||||
@ -947,6 +985,7 @@ struct dwc2_hsotg {
|
||||
|
||||
/* DWC OTG HW Release versions */
|
||||
#define DWC2_CORE_REV_2_71a 0x4f54271a
|
||||
#define DWC2_CORE_REV_2_80a 0x4f54280a
|
||||
#define DWC2_CORE_REV_2_90a 0x4f54290a
|
||||
#define DWC2_CORE_REV_2_91a 0x4f54291a
|
||||
#define DWC2_CORE_REV_2_92a 0x4f54292a
|
||||
@ -956,6 +995,11 @@ struct dwc2_hsotg {
|
||||
#define DWC2_FS_IOT_REV_1_00a 0x5531100a
|
||||
#define DWC2_HS_IOT_REV_1_00a 0x5532100a
|
||||
|
||||
/* DWC OTG HW Core ID */
|
||||
#define DWC2_OTG_ID 0x4f540000
|
||||
#define DWC2_FS_IOT_ID 0x55310000
|
||||
#define DWC2_HS_IOT_ID 0x55320000
|
||||
|
||||
#if IS_ENABLED(CONFIG_USB_DWC2_HOST) || IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE)
|
||||
union dwc2_hcd_internal_flags {
|
||||
u32 d32;
|
||||
@ -1016,24 +1060,6 @@ struct dwc2_hsotg {
|
||||
struct kmem_cache *desc_gen_cache;
|
||||
struct kmem_cache *desc_hsisoc_cache;
|
||||
|
||||
#ifdef DEBUG
|
||||
u32 frrem_samples;
|
||||
u64 frrem_accum;
|
||||
|
||||
u32 hfnum_7_samples_a;
|
||||
u64 hfnum_7_frrem_accum_a;
|
||||
u32 hfnum_0_samples_a;
|
||||
u64 hfnum_0_frrem_accum_a;
|
||||
u32 hfnum_other_samples_a;
|
||||
u64 hfnum_other_frrem_accum_a;
|
||||
|
||||
u32 hfnum_7_samples_b;
|
||||
u64 hfnum_7_frrem_accum_b;
|
||||
u32 hfnum_0_samples_b;
|
||||
u64 hfnum_0_frrem_accum_b;
|
||||
u32 hfnum_other_samples_b;
|
||||
u64 hfnum_other_frrem_accum_b;
|
||||
#endif
|
||||
#endif /* CONFIG_USB_DWC2_HOST || CONFIG_USB_DWC2_DUAL_ROLE */
|
||||
|
||||
#if IS_ENABLED(CONFIG_USB_DWC2_PERIPHERAL) || \
|
||||
@ -1062,6 +1088,7 @@ struct dwc2_hsotg {
|
||||
struct usb_gadget gadget;
|
||||
unsigned int enabled:1;
|
||||
unsigned int connected:1;
|
||||
unsigned int remote_wakeup_allowed:1;
|
||||
struct dwc2_hsotg_ep *eps_in[MAX_EPS_CHANNELS];
|
||||
struct dwc2_hsotg_ep *eps_out[MAX_EPS_CHANNELS];
|
||||
#endif /* CONFIG_USB_DWC2_PERIPHERAL || CONFIG_USB_DWC2_DUAL_ROLE */
|
||||
@ -1106,12 +1133,13 @@ static inline bool dwc2_is_hs_iot(struct dwc2_hsotg *hsotg)
|
||||
* and the DWC_otg controller
|
||||
*/
|
||||
int dwc2_core_reset(struct dwc2_hsotg *hsotg, bool skip_wait);
|
||||
int dwc2_core_reset_and_force_dr_mode(struct dwc2_hsotg *hsotg);
|
||||
int dwc2_enter_hibernation(struct dwc2_hsotg *hsotg);
|
||||
int dwc2_exit_hibernation(struct dwc2_hsotg *hsotg, bool restore);
|
||||
int dwc2_enter_partial_power_down(struct dwc2_hsotg *hsotg);
|
||||
int dwc2_exit_partial_power_down(struct dwc2_hsotg *hsotg, bool restore);
|
||||
int dwc2_enter_hibernation(struct dwc2_hsotg *hsotg, int is_host);
|
||||
int dwc2_exit_hibernation(struct dwc2_hsotg *hsotg, int rem_wakeup,
|
||||
int reset, int is_host);
|
||||
|
||||
bool dwc2_force_mode_if_needed(struct dwc2_hsotg *hsotg, bool host);
|
||||
void dwc2_clear_force_mode(struct dwc2_hsotg *hsotg);
|
||||
void dwc2_force_mode(struct dwc2_hsotg *hsotg, bool host);
|
||||
void dwc2_force_dr_mode(struct dwc2_hsotg *hsotg);
|
||||
|
||||
bool dwc2_is_controller_alive(struct dwc2_hsotg *hsotg);
|
||||
@ -1128,6 +1156,13 @@ void dwc2_flush_rx_fifo(struct dwc2_hsotg *hsotg);
|
||||
void dwc2_enable_global_interrupts(struct dwc2_hsotg *hcd);
|
||||
void dwc2_disable_global_interrupts(struct dwc2_hsotg *hcd);
|
||||
|
||||
void dwc2_hib_restore_common(struct dwc2_hsotg *hsotg, int rem_wakeup,
|
||||
int is_host);
|
||||
int dwc2_backup_global_registers(struct dwc2_hsotg *hsotg);
|
||||
int dwc2_restore_global_registers(struct dwc2_hsotg *hsotg);
|
||||
|
||||
void dwc2_enable_acg(struct dwc2_hsotg *hsotg);
|
||||
|
||||
/* This function should be called on every hardware interrupt. */
|
||||
irqreturn_t dwc2_handle_common_intr(int irq, void *dev);
|
||||
|
||||
@ -1137,6 +1172,11 @@ extern const struct of_device_id dwc2_of_match_table[];
|
||||
int dwc2_lowlevel_hw_enable(struct dwc2_hsotg *hsotg);
|
||||
int dwc2_lowlevel_hw_disable(struct dwc2_hsotg *hsotg);
|
||||
|
||||
/* Common polling functions */
|
||||
int dwc2_hsotg_wait_bit_set(struct dwc2_hsotg *hs_otg, u32 reg, u32 bit,
|
||||
u32 timeout);
|
||||
int dwc2_hsotg_wait_bit_clear(struct dwc2_hsotg *hs_otg, u32 reg, u32 bit,
|
||||
u32 timeout);
|
||||
/* Parameters */
|
||||
int dwc2_get_hwparams(struct dwc2_hsotg *hsotg);
|
||||
int dwc2_init_params(struct dwc2_hsotg *hsotg);
|
||||
@ -1180,7 +1220,7 @@ void dwc2_dump_global_registers(struct dwc2_hsotg *hsotg);
|
||||
int dwc2_hsotg_remove(struct dwc2_hsotg *hsotg);
|
||||
int dwc2_hsotg_suspend(struct dwc2_hsotg *dwc2);
|
||||
int dwc2_hsotg_resume(struct dwc2_hsotg *dwc2);
|
||||
int dwc2_gadget_init(struct dwc2_hsotg *hsotg, int irq);
|
||||
int dwc2_gadget_init(struct dwc2_hsotg *hsotg);
|
||||
void dwc2_hsotg_core_init_disconnected(struct dwc2_hsotg *dwc2,
|
||||
bool reset);
|
||||
void dwc2_hsotg_core_connect(struct dwc2_hsotg *hsotg);
|
||||
@ -1188,10 +1228,14 @@ void dwc2_hsotg_disconnect(struct dwc2_hsotg *dwc2);
|
||||
int dwc2_hsotg_set_test_mode(struct dwc2_hsotg *hsotg, int testmode);
|
||||
#define dwc2_is_device_connected(hsotg) (hsotg->connected)
|
||||
int dwc2_backup_device_registers(struct dwc2_hsotg *hsotg);
|
||||
int dwc2_restore_device_registers(struct dwc2_hsotg *hsotg);
|
||||
int dwc2_restore_device_registers(struct dwc2_hsotg *hsotg, int remote_wakeup);
|
||||
int dwc2_gadget_enter_hibernation(struct dwc2_hsotg *hsotg);
|
||||
int dwc2_gadget_exit_hibernation(struct dwc2_hsotg *hsotg,
|
||||
int rem_wakeup, int reset);
|
||||
int dwc2_hsotg_tx_fifo_count(struct dwc2_hsotg *hsotg);
|
||||
int dwc2_hsotg_tx_fifo_total_depth(struct dwc2_hsotg *hsotg);
|
||||
int dwc2_hsotg_tx_fifo_average_depth(struct dwc2_hsotg *hsotg);
|
||||
void dwc2_gadget_init_lpm(struct dwc2_hsotg *hsotg);
|
||||
#else
|
||||
static inline int dwc2_hsotg_remove(struct dwc2_hsotg *dwc2)
|
||||
{ return 0; }
|
||||
@ -1199,7 +1243,7 @@ static inline int dwc2_hsotg_suspend(struct dwc2_hsotg *dwc2)
|
||||
{ return 0; }
|
||||
static inline int dwc2_hsotg_resume(struct dwc2_hsotg *dwc2)
|
||||
{ return 0; }
|
||||
static inline int dwc2_gadget_init(struct dwc2_hsotg *hsotg, int irq)
|
||||
static inline int dwc2_gadget_init(struct dwc2_hsotg *hsotg)
|
||||
{ return 0; }
|
||||
static inline void dwc2_hsotg_core_init_disconnected(struct dwc2_hsotg *dwc2,
|
||||
bool reset) {}
|
||||
@ -1211,7 +1255,13 @@ static inline int dwc2_hsotg_set_test_mode(struct dwc2_hsotg *hsotg,
|
||||
#define dwc2_is_device_connected(hsotg) (0)
|
||||
static inline int dwc2_backup_device_registers(struct dwc2_hsotg *hsotg)
|
||||
{ return 0; }
|
||||
static inline int dwc2_restore_device_registers(struct dwc2_hsotg *hsotg)
|
||||
static inline int dwc2_restore_device_registers(struct dwc2_hsotg *hsotg,
|
||||
int remote_wakeup)
|
||||
{ return 0; }
|
||||
static inline int dwc2_gadget_enter_hibernation(struct dwc2_hsotg *hsotg)
|
||||
{ return 0; }
|
||||
static inline int dwc2_gadget_exit_hibernation(struct dwc2_hsotg *hsotg,
|
||||
int rem_wakeup, int reset)
|
||||
{ return 0; }
|
||||
static inline int dwc2_hsotg_tx_fifo_count(struct dwc2_hsotg *hsotg)
|
||||
{ return 0; }
|
||||
@ -1219,6 +1269,7 @@ static inline int dwc2_hsotg_tx_fifo_total_depth(struct dwc2_hsotg *hsotg)
|
||||
{ return 0; }
|
||||
static inline int dwc2_hsotg_tx_fifo_average_depth(struct dwc2_hsotg *hsotg)
|
||||
{ return 0; }
|
||||
static inline void dwc2_gadget_init_lpm(struct dwc2_hsotg *hsotg) {}
|
||||
#endif
|
||||
|
||||
#if IS_ENABLED(CONFIG_USB_DWC2_HOST) || IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE)
|
||||
@ -1227,8 +1278,12 @@ int dwc2_hcd_get_future_frame_number(struct dwc2_hsotg *hsotg, int us);
|
||||
void dwc2_hcd_connect(struct dwc2_hsotg *hsotg);
|
||||
void dwc2_hcd_disconnect(struct dwc2_hsotg *hsotg, bool force);
|
||||
void dwc2_hcd_start(struct dwc2_hsotg *hsotg);
|
||||
int dwc2_core_init(struct dwc2_hsotg *hsotg, bool initial_setup);
|
||||
int dwc2_backup_host_registers(struct dwc2_hsotg *hsotg);
|
||||
int dwc2_restore_host_registers(struct dwc2_hsotg *hsotg);
|
||||
int dwc2_host_enter_hibernation(struct dwc2_hsotg *hsotg);
|
||||
int dwc2_host_exit_hibernation(struct dwc2_hsotg *hsotg,
|
||||
int rem_wakeup, int reset);
|
||||
#else
|
||||
static inline int dwc2_hcd_get_frame_number(struct dwc2_hsotg *hsotg)
|
||||
{ return 0; }
|
||||
@ -1239,12 +1294,19 @@ static inline void dwc2_hcd_connect(struct dwc2_hsotg *hsotg) {}
|
||||
static inline void dwc2_hcd_disconnect(struct dwc2_hsotg *hsotg, bool force) {}
|
||||
static inline void dwc2_hcd_start(struct dwc2_hsotg *hsotg) {}
|
||||
static inline void dwc2_hcd_remove(struct dwc2_hsotg *hsotg) {}
|
||||
static inline int dwc2_core_init(struct dwc2_hsotg *hsotg, bool initial_setup)
|
||||
{ return 0; }
|
||||
static inline int dwc2_hcd_init(struct dwc2_hsotg *hsotg)
|
||||
{ return 0; }
|
||||
static inline int dwc2_backup_host_registers(struct dwc2_hsotg *hsotg)
|
||||
{ return 0; }
|
||||
static inline int dwc2_restore_host_registers(struct dwc2_hsotg *hsotg)
|
||||
{ return 0; }
|
||||
static inline int dwc2_host_enter_hibernation(struct dwc2_hsotg *hsotg)
|
||||
{ return 0; }
|
||||
static inline int dwc2_host_exit_hibernation(struct dwc2_hsotg *hsotg,
|
||||
int rem_wakeup, int reset)
|
||||
{ return 0; }
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -321,10 +321,10 @@ static void dwc2_handle_session_req_intr(struct dwc2_hsotg *hsotg)
|
||||
|
||||
if (dwc2_is_device_mode(hsotg)) {
|
||||
if (hsotg->lx_state == DWC2_L2) {
|
||||
ret = dwc2_exit_hibernation(hsotg, true);
|
||||
ret = dwc2_exit_partial_power_down(hsotg, true);
|
||||
if (ret && (ret != -ENOTSUPP))
|
||||
dev_err(hsotg->dev,
|
||||
"exit hibernation failed\n");
|
||||
"exit power_down failed\n");
|
||||
}
|
||||
|
||||
/*
|
||||
@ -335,6 +335,57 @@ static void dwc2_handle_session_req_intr(struct dwc2_hsotg *hsotg)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* dwc2_wakeup_from_lpm_l1 - Exit the device from LPM L1 state
|
||||
*
|
||||
* @hsotg: Programming view of DWC_otg controller
|
||||
*
|
||||
*/
|
||||
static void dwc2_wakeup_from_lpm_l1(struct dwc2_hsotg *hsotg)
|
||||
{
|
||||
u32 glpmcfg;
|
||||
u32 i = 0;
|
||||
|
||||
if (hsotg->lx_state != DWC2_L1) {
|
||||
dev_err(hsotg->dev, "Core isn't in DWC2_L1 state\n");
|
||||
return;
|
||||
}
|
||||
|
||||
glpmcfg = dwc2_readl(hsotg->regs + GLPMCFG);
|
||||
if (dwc2_is_device_mode(hsotg)) {
|
||||
dev_dbg(hsotg->dev, "Exit from L1 state\n");
|
||||
glpmcfg &= ~GLPMCFG_ENBLSLPM;
|
||||
glpmcfg &= ~GLPMCFG_HIRD_THRES_EN;
|
||||
dwc2_writel(glpmcfg, hsotg->regs + GLPMCFG);
|
||||
|
||||
do {
|
||||
glpmcfg = dwc2_readl(hsotg->regs + GLPMCFG);
|
||||
|
||||
if (!(glpmcfg & (GLPMCFG_COREL1RES_MASK |
|
||||
GLPMCFG_L1RESUMEOK | GLPMCFG_SLPSTS)))
|
||||
break;
|
||||
|
||||
udelay(1);
|
||||
} while (++i < 200);
|
||||
|
||||
if (i == 200) {
|
||||
dev_err(hsotg->dev, "Failed to exit L1 sleep state in 200us.\n");
|
||||
return;
|
||||
}
|
||||
dwc2_gadget_init_lpm(hsotg);
|
||||
} else {
|
||||
/* TODO */
|
||||
dev_err(hsotg->dev, "Host side LPM is not supported.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
/* Change to L0 state */
|
||||
hsotg->lx_state = DWC2_L0;
|
||||
|
||||
/* Inform gadget to exit from L1 */
|
||||
call_gadget(hsotg, resume);
|
||||
}
|
||||
|
||||
/*
|
||||
* This interrupt indicates that the DWC_otg controller has detected a
|
||||
* resume or remote wakeup sequence. If the DWC_otg controller is in
|
||||
@ -352,6 +403,11 @@ static void dwc2_handle_wakeup_detected_intr(struct dwc2_hsotg *hsotg)
|
||||
dev_dbg(hsotg->dev, "++Resume or Remote Wakeup Detected Interrupt++\n");
|
||||
dev_dbg(hsotg->dev, "%s lxstate = %d\n", __func__, hsotg->lx_state);
|
||||
|
||||
if (hsotg->lx_state == DWC2_L1) {
|
||||
dwc2_wakeup_from_lpm_l1(hsotg);
|
||||
return;
|
||||
}
|
||||
|
||||
if (dwc2_is_device_mode(hsotg)) {
|
||||
dev_dbg(hsotg->dev, "DSTS=0x%0x\n",
|
||||
dwc2_readl(hsotg->regs + DSTS));
|
||||
@ -361,16 +417,16 @@ static void dwc2_handle_wakeup_detected_intr(struct dwc2_hsotg *hsotg)
|
||||
/* Clear Remote Wakeup Signaling */
|
||||
dctl &= ~DCTL_RMTWKUPSIG;
|
||||
dwc2_writel(dctl, hsotg->regs + DCTL);
|
||||
ret = dwc2_exit_hibernation(hsotg, true);
|
||||
ret = dwc2_exit_partial_power_down(hsotg, true);
|
||||
if (ret && (ret != -ENOTSUPP))
|
||||
dev_err(hsotg->dev, "exit hibernation failed\n");
|
||||
dev_err(hsotg->dev, "exit power_down failed\n");
|
||||
|
||||
call_gadget(hsotg, resume);
|
||||
}
|
||||
/* Change to L0 state */
|
||||
hsotg->lx_state = DWC2_L0;
|
||||
} else {
|
||||
if (hsotg->params.hibernation)
|
||||
if (hsotg->params.power_down)
|
||||
return;
|
||||
|
||||
if (hsotg->lx_state != DWC2_L1) {
|
||||
@ -428,32 +484,44 @@ static void dwc2_handle_usb_suspend_intr(struct dwc2_hsotg *hsotg)
|
||||
* state is active
|
||||
*/
|
||||
dsts = dwc2_readl(hsotg->regs + DSTS);
|
||||
dev_dbg(hsotg->dev, "DSTS=0x%0x\n", dsts);
|
||||
dev_dbg(hsotg->dev, "%s: DSTS=0x%0x\n", __func__, dsts);
|
||||
dev_dbg(hsotg->dev,
|
||||
"DSTS.Suspend Status=%d HWCFG4.Power Optimize=%d\n",
|
||||
"DSTS.Suspend Status=%d HWCFG4.Power Optimize=%d HWCFG4.Hibernation=%d\n",
|
||||
!!(dsts & DSTS_SUSPSTS),
|
||||
hsotg->hw_params.power_optimized);
|
||||
if ((dsts & DSTS_SUSPSTS) && hsotg->hw_params.power_optimized) {
|
||||
/* Ignore suspend request before enumeration */
|
||||
if (!dwc2_is_device_connected(hsotg)) {
|
||||
dev_dbg(hsotg->dev,
|
||||
"ignore suspend request before enumeration\n");
|
||||
return;
|
||||
hsotg->hw_params.power_optimized,
|
||||
hsotg->hw_params.hibernation);
|
||||
|
||||
/* Ignore suspend request before enumeration */
|
||||
if (!dwc2_is_device_connected(hsotg)) {
|
||||
dev_dbg(hsotg->dev,
|
||||
"ignore suspend request before enumeration\n");
|
||||
return;
|
||||
}
|
||||
if (dsts & DSTS_SUSPSTS) {
|
||||
if (hsotg->hw_params.power_optimized) {
|
||||
ret = dwc2_enter_partial_power_down(hsotg);
|
||||
if (ret) {
|
||||
if (ret != -ENOTSUPP)
|
||||
dev_err(hsotg->dev,
|
||||
"%s: enter partial_power_down failed\n",
|
||||
__func__);
|
||||
goto skip_power_saving;
|
||||
}
|
||||
|
||||
udelay(100);
|
||||
|
||||
/* Ask phy to be suspended */
|
||||
if (!IS_ERR_OR_NULL(hsotg->uphy))
|
||||
usb_phy_set_suspend(hsotg->uphy, true);
|
||||
}
|
||||
|
||||
ret = dwc2_enter_hibernation(hsotg);
|
||||
if (ret) {
|
||||
if (ret != -ENOTSUPP)
|
||||
if (hsotg->hw_params.hibernation) {
|
||||
ret = dwc2_enter_hibernation(hsotg, 0);
|
||||
if (ret && ret != -ENOTSUPP)
|
||||
dev_err(hsotg->dev,
|
||||
"enter hibernation failed\n");
|
||||
goto skip_power_saving;
|
||||
"%s: enter hibernation failed\n",
|
||||
__func__);
|
||||
}
|
||||
|
||||
udelay(100);
|
||||
|
||||
/* Ask phy to be suspended */
|
||||
if (!IS_ERR_OR_NULL(hsotg->uphy))
|
||||
usb_phy_set_suspend(hsotg->uphy, true);
|
||||
skip_power_saving:
|
||||
/*
|
||||
* Change to L2 (suspend) state before releasing
|
||||
@ -479,10 +547,75 @@ skip_power_saving:
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* dwc2_handle_lpm_intr - GINTSTS_LPMTRANRCVD Interrupt handler
|
||||
*
|
||||
* @hsotg: Programming view of DWC_otg controller
|
||||
*
|
||||
*/
|
||||
static void dwc2_handle_lpm_intr(struct dwc2_hsotg *hsotg)
|
||||
{
|
||||
u32 glpmcfg;
|
||||
u32 pcgcctl;
|
||||
u32 hird;
|
||||
u32 hird_thres;
|
||||
u32 hird_thres_en;
|
||||
u32 enslpm;
|
||||
|
||||
/* Clear interrupt */
|
||||
dwc2_writel(GINTSTS_LPMTRANRCVD, hsotg->regs + GINTSTS);
|
||||
|
||||
glpmcfg = dwc2_readl(hsotg->regs + GLPMCFG);
|
||||
|
||||
if (!(glpmcfg & GLPMCFG_LPMCAP)) {
|
||||
dev_err(hsotg->dev, "Unexpected LPM interrupt\n");
|
||||
return;
|
||||
}
|
||||
|
||||
hird = (glpmcfg & GLPMCFG_HIRD_MASK) >> GLPMCFG_HIRD_SHIFT;
|
||||
hird_thres = (glpmcfg & GLPMCFG_HIRD_THRES_MASK &
|
||||
~GLPMCFG_HIRD_THRES_EN) >> GLPMCFG_HIRD_THRES_SHIFT;
|
||||
hird_thres_en = glpmcfg & GLPMCFG_HIRD_THRES_EN;
|
||||
enslpm = glpmcfg & GLPMCFG_ENBLSLPM;
|
||||
|
||||
if (dwc2_is_device_mode(hsotg)) {
|
||||
dev_dbg(hsotg->dev, "HIRD_THRES_EN = %d\n", hird_thres_en);
|
||||
|
||||
if (hird_thres_en && hird >= hird_thres) {
|
||||
dev_dbg(hsotg->dev, "L1 with utmi_l1_suspend_n\n");
|
||||
} else if (enslpm) {
|
||||
dev_dbg(hsotg->dev, "L1 with utmi_sleep_n\n");
|
||||
} else {
|
||||
dev_dbg(hsotg->dev, "Entering Sleep with L1 Gating\n");
|
||||
|
||||
pcgcctl = dwc2_readl(hsotg->regs + PCGCTL);
|
||||
pcgcctl |= PCGCTL_ENBL_SLEEP_GATING;
|
||||
dwc2_writel(pcgcctl, hsotg->regs + PCGCTL);
|
||||
}
|
||||
/**
|
||||
* Examine prt_sleep_sts after TL1TokenTetry period max (10 us)
|
||||
*/
|
||||
udelay(10);
|
||||
|
||||
glpmcfg = dwc2_readl(hsotg->regs + GLPMCFG);
|
||||
|
||||
if (glpmcfg & GLPMCFG_SLPSTS) {
|
||||
/* Save the current state */
|
||||
hsotg->lx_state = DWC2_L1;
|
||||
dev_dbg(hsotg->dev,
|
||||
"Core is in L1 sleep glpmcfg=%08x\n", glpmcfg);
|
||||
|
||||
/* Inform gadget that we are in L1 state */
|
||||
call_gadget(hsotg, suspend);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#define GINTMSK_COMMON (GINTSTS_WKUPINT | GINTSTS_SESSREQINT | \
|
||||
GINTSTS_CONIDSTSCHNG | GINTSTS_OTGINT | \
|
||||
GINTSTS_MODEMIS | GINTSTS_DISCONNINT | \
|
||||
GINTSTS_USBSUSP | GINTSTS_PRTINT)
|
||||
GINTSTS_USBSUSP | GINTSTS_PRTINT | \
|
||||
GINTSTS_LPMTRANRCVD)
|
||||
|
||||
/*
|
||||
* This function returns the Core Interrupt register
|
||||
@ -509,6 +642,116 @@ static u32 dwc2_read_common_intr(struct dwc2_hsotg *hsotg)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* GPWRDN interrupt handler.
|
||||
*
|
||||
* The GPWRDN interrupts are those that occur in both Host and
|
||||
* Device mode while core is in hibernated state.
|
||||
*/
|
||||
static void dwc2_handle_gpwrdn_intr(struct dwc2_hsotg *hsotg)
|
||||
{
|
||||
u32 gpwrdn;
|
||||
int linestate;
|
||||
|
||||
gpwrdn = dwc2_readl(hsotg->regs + GPWRDN);
|
||||
/* clear all interrupt */
|
||||
dwc2_writel(gpwrdn, hsotg->regs + GPWRDN);
|
||||
linestate = (gpwrdn & GPWRDN_LINESTATE_MASK) >> GPWRDN_LINESTATE_SHIFT;
|
||||
dev_dbg(hsotg->dev,
|
||||
"%s: dwc2_handle_gpwrdwn_intr called gpwrdn= %08x\n", __func__,
|
||||
gpwrdn);
|
||||
|
||||
if ((gpwrdn & GPWRDN_DISCONN_DET) &&
|
||||
(gpwrdn & GPWRDN_DISCONN_DET_MSK) && !linestate) {
|
||||
u32 gpwrdn_tmp;
|
||||
|
||||
dev_dbg(hsotg->dev, "%s: GPWRDN_DISCONN_DET\n", __func__);
|
||||
|
||||
/* Switch-on voltage to the core */
|
||||
gpwrdn_tmp = dwc2_readl(hsotg->regs + GPWRDN);
|
||||
gpwrdn_tmp &= ~GPWRDN_PWRDNSWTCH;
|
||||
dwc2_writel(gpwrdn_tmp, hsotg->regs + GPWRDN);
|
||||
udelay(10);
|
||||
|
||||
/* Reset core */
|
||||
gpwrdn_tmp = dwc2_readl(hsotg->regs + GPWRDN);
|
||||
gpwrdn_tmp &= ~GPWRDN_PWRDNRSTN;
|
||||
dwc2_writel(gpwrdn_tmp, hsotg->regs + GPWRDN);
|
||||
udelay(10);
|
||||
|
||||
/* Disable Power Down Clamp */
|
||||
gpwrdn_tmp = dwc2_readl(hsotg->regs + GPWRDN);
|
||||
gpwrdn_tmp &= ~GPWRDN_PWRDNCLMP;
|
||||
dwc2_writel(gpwrdn_tmp, hsotg->regs + GPWRDN);
|
||||
udelay(10);
|
||||
|
||||
/* Deassert reset core */
|
||||
gpwrdn_tmp = dwc2_readl(hsotg->regs + GPWRDN);
|
||||
gpwrdn_tmp |= GPWRDN_PWRDNRSTN;
|
||||
dwc2_writel(gpwrdn_tmp, hsotg->regs + GPWRDN);
|
||||
udelay(10);
|
||||
|
||||
/* Disable PMU interrupt */
|
||||
gpwrdn_tmp = dwc2_readl(hsotg->regs + GPWRDN);
|
||||
gpwrdn_tmp &= ~GPWRDN_PMUINTSEL;
|
||||
dwc2_writel(gpwrdn_tmp, hsotg->regs + GPWRDN);
|
||||
|
||||
/* De-assert Wakeup Logic */
|
||||
gpwrdn_tmp = dwc2_readl(hsotg->regs + GPWRDN);
|
||||
gpwrdn_tmp &= ~GPWRDN_PMUACTV;
|
||||
dwc2_writel(gpwrdn_tmp, hsotg->regs + GPWRDN);
|
||||
|
||||
hsotg->hibernated = 0;
|
||||
|
||||
if (gpwrdn & GPWRDN_IDSTS) {
|
||||
hsotg->op_state = OTG_STATE_B_PERIPHERAL;
|
||||
dwc2_core_init(hsotg, false);
|
||||
dwc2_enable_global_interrupts(hsotg);
|
||||
dwc2_hsotg_core_init_disconnected(hsotg, false);
|
||||
dwc2_hsotg_core_connect(hsotg);
|
||||
} else {
|
||||
hsotg->op_state = OTG_STATE_A_HOST;
|
||||
|
||||
/* Initialize the Core for Host mode */
|
||||
dwc2_core_init(hsotg, false);
|
||||
dwc2_enable_global_interrupts(hsotg);
|
||||
dwc2_hcd_start(hsotg);
|
||||
}
|
||||
}
|
||||
|
||||
if ((gpwrdn & GPWRDN_LNSTSCHG) &&
|
||||
(gpwrdn & GPWRDN_LNSTSCHG_MSK) && linestate) {
|
||||
dev_dbg(hsotg->dev, "%s: GPWRDN_LNSTSCHG\n", __func__);
|
||||
if (hsotg->hw_params.hibernation &&
|
||||
hsotg->hibernated) {
|
||||
if (gpwrdn & GPWRDN_IDSTS) {
|
||||
dwc2_exit_hibernation(hsotg, 0, 0, 0);
|
||||
call_gadget(hsotg, resume);
|
||||
} else {
|
||||
dwc2_exit_hibernation(hsotg, 1, 0, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
if ((gpwrdn & GPWRDN_RST_DET) && (gpwrdn & GPWRDN_RST_DET_MSK)) {
|
||||
dev_dbg(hsotg->dev, "%s: GPWRDN_RST_DET\n", __func__);
|
||||
if (!linestate && (gpwrdn & GPWRDN_BSESSVLD))
|
||||
dwc2_exit_hibernation(hsotg, 0, 1, 0);
|
||||
}
|
||||
if ((gpwrdn & GPWRDN_STS_CHGINT) &&
|
||||
(gpwrdn & GPWRDN_STS_CHGINT_MSK) && linestate) {
|
||||
dev_dbg(hsotg->dev, "%s: GPWRDN_STS_CHGINT\n", __func__);
|
||||
if (hsotg->hw_params.hibernation &&
|
||||
hsotg->hibernated) {
|
||||
if (gpwrdn & GPWRDN_IDSTS) {
|
||||
dwc2_exit_hibernation(hsotg, 0, 0, 0);
|
||||
call_gadget(hsotg, resume);
|
||||
} else {
|
||||
dwc2_exit_hibernation(hsotg, 1, 0, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Common interrupt handler
|
||||
*
|
||||
@ -539,6 +782,13 @@ irqreturn_t dwc2_handle_common_intr(int irq, void *dev)
|
||||
if (gintsts & ~GINTSTS_PRTINT)
|
||||
retval = IRQ_HANDLED;
|
||||
|
||||
/* In case of hibernated state gintsts must not work */
|
||||
if (hsotg->hibernated) {
|
||||
dwc2_handle_gpwrdn_intr(hsotg);
|
||||
retval = IRQ_HANDLED;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (gintsts & GINTSTS_MODEMIS)
|
||||
dwc2_handle_mode_mismatch_intr(hsotg);
|
||||
if (gintsts & GINTSTS_OTGINT)
|
||||
@ -553,6 +803,8 @@ irqreturn_t dwc2_handle_common_intr(int irq, void *dev)
|
||||
dwc2_handle_wakeup_detected_intr(hsotg);
|
||||
if (gintsts & GINTSTS_USBSUSP)
|
||||
dwc2_handle_usb_suspend_intr(hsotg);
|
||||
if (gintsts & GINTSTS_LPMTRANRCVD)
|
||||
dwc2_handle_lpm_intr(hsotg);
|
||||
|
||||
if (gintsts & GINTSTS_PRTINT) {
|
||||
/*
|
||||
|
@ -170,19 +170,7 @@ static int state_show(struct seq_file *seq, void *v)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int state_open(struct inode *inode, struct file *file)
|
||||
{
|
||||
return single_open(file, state_show, inode->i_private);
|
||||
}
|
||||
|
||||
static const struct file_operations state_fops = {
|
||||
.owner = THIS_MODULE,
|
||||
.open = state_open,
|
||||
.read = seq_read,
|
||||
.llseek = seq_lseek,
|
||||
.release = single_release,
|
||||
};
|
||||
DEFINE_SHOW_ATTRIBUTE(state);
|
||||
|
||||
/**
|
||||
* fifo_show - debugfs: show the fifo information
|
||||
@ -219,19 +207,7 @@ static int fifo_show(struct seq_file *seq, void *v)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int fifo_open(struct inode *inode, struct file *file)
|
||||
{
|
||||
return single_open(file, fifo_show, inode->i_private);
|
||||
}
|
||||
|
||||
static const struct file_operations fifo_fops = {
|
||||
.owner = THIS_MODULE,
|
||||
.open = fifo_open,
|
||||
.read = seq_read,
|
||||
.llseek = seq_lseek,
|
||||
.release = single_release,
|
||||
};
|
||||
DEFINE_SHOW_ATTRIBUTE(fifo);
|
||||
|
||||
static const char *decode_direction(int is_in)
|
||||
{
|
||||
@ -303,19 +279,7 @@ static int ep_show(struct seq_file *seq, void *v)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ep_open(struct inode *inode, struct file *file)
|
||||
{
|
||||
return single_open(file, ep_show, inode->i_private);
|
||||
}
|
||||
|
||||
static const struct file_operations ep_fops = {
|
||||
.owner = THIS_MODULE,
|
||||
.open = ep_open,
|
||||
.read = seq_read,
|
||||
.llseek = seq_lseek,
|
||||
.release = single_release,
|
||||
};
|
||||
DEFINE_SHOW_ATTRIBUTE(ep);
|
||||
|
||||
/**
|
||||
* dwc2_hsotg_create_debug - create debugfs directory and files
|
||||
@ -754,7 +718,12 @@ static int params_show(struct seq_file *seq, void *v)
|
||||
print_param_hex(seq, p, ahbcfg);
|
||||
print_param(seq, p, uframe_sched);
|
||||
print_param(seq, p, external_id_pin_ctl);
|
||||
print_param(seq, p, hibernation);
|
||||
print_param(seq, p, power_down);
|
||||
print_param(seq, p, lpm);
|
||||
print_param(seq, p, lpm_clock_gating);
|
||||
print_param(seq, p, besl);
|
||||
print_param(seq, p, hird_threshold_en);
|
||||
print_param(seq, p, hird_threshold);
|
||||
print_param(seq, p, host_dma);
|
||||
print_param(seq, p, g_dma);
|
||||
print_param(seq, p, g_dma_desc);
|
||||
@ -770,19 +739,7 @@ static int params_show(struct seq_file *seq, void *v)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int params_open(struct inode *inode, struct file *file)
|
||||
{
|
||||
return single_open(file, params_show, inode->i_private);
|
||||
}
|
||||
|
||||
static const struct file_operations params_fops = {
|
||||
.owner = THIS_MODULE,
|
||||
.open = params_open,
|
||||
.read = seq_read,
|
||||
.llseek = seq_lseek,
|
||||
.release = single_release,
|
||||
};
|
||||
DEFINE_SHOW_ATTRIBUTE(params);
|
||||
|
||||
static int hw_params_show(struct seq_file *seq, void *v)
|
||||
{
|
||||
@ -817,19 +774,7 @@ static int hw_params_show(struct seq_file *seq, void *v)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int hw_params_open(struct inode *inode, struct file *file)
|
||||
{
|
||||
return single_open(file, hw_params_show, inode->i_private);
|
||||
}
|
||||
|
||||
static const struct file_operations hw_params_fops = {
|
||||
.owner = THIS_MODULE,
|
||||
.open = hw_params_open,
|
||||
.read = seq_read,
|
||||
.llseek = seq_lseek,
|
||||
.release = single_release,
|
||||
};
|
||||
DEFINE_SHOW_ATTRIBUTE(hw_params);
|
||||
|
||||
static int dr_mode_show(struct seq_file *seq, void *v)
|
||||
{
|
||||
@ -840,19 +785,7 @@ static int dr_mode_show(struct seq_file *seq, void *v)
|
||||
seq_printf(seq, "%s\n", dr_mode);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int dr_mode_open(struct inode *inode, struct file *file)
|
||||
{
|
||||
return single_open(file, dr_mode_show, inode->i_private);
|
||||
}
|
||||
|
||||
static const struct file_operations dr_mode_fops = {
|
||||
.owner = THIS_MODULE,
|
||||
.open = dr_mode_open,
|
||||
.read = seq_read,
|
||||
.llseek = seq_lseek,
|
||||
.release = single_release,
|
||||
};
|
||||
DEFINE_SHOW_ATTRIBUTE(dr_mode);
|
||||
|
||||
int dwc2_debugfs_init(struct dwc2_hsotg *hsotg)
|
||||
{
|
||||
|
@ -47,12 +47,12 @@ static inline struct dwc2_hsotg *to_hsotg(struct usb_gadget *gadget)
|
||||
return container_of(gadget, struct dwc2_hsotg, gadget);
|
||||
}
|
||||
|
||||
static inline void __orr32(void __iomem *ptr, u32 val)
|
||||
static inline void dwc2_set_bit(void __iomem *ptr, u32 val)
|
||||
{
|
||||
dwc2_writel(dwc2_readl(ptr) | val, ptr);
|
||||
}
|
||||
|
||||
static inline void __bic32(void __iomem *ptr, u32 val)
|
||||
static inline void dwc2_clear_bit(void __iomem *ptr, u32 val)
|
||||
{
|
||||
dwc2_writel(dwc2_readl(ptr) & ~val, ptr);
|
||||
}
|
||||
@ -116,10 +116,10 @@ static inline void dwc2_gadget_incr_frame_num(struct dwc2_hsotg_ep *hs_ep)
|
||||
{
|
||||
hs_ep->target_frame += hs_ep->interval;
|
||||
if (hs_ep->target_frame > DSTS_SOFFN_LIMIT) {
|
||||
hs_ep->frame_overrun = 1;
|
||||
hs_ep->frame_overrun = true;
|
||||
hs_ep->target_frame &= DSTS_SOFFN_LIMIT;
|
||||
} else {
|
||||
hs_ep->frame_overrun = 0;
|
||||
hs_ep->frame_overrun = false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -252,6 +252,7 @@ static void dwc2_hsotg_init_fifo(struct dwc2_hsotg *hsotg)
|
||||
unsigned int ep;
|
||||
unsigned int addr;
|
||||
int timeout;
|
||||
|
||||
u32 val;
|
||||
u32 *txfsz = hsotg->params.g_tx_fifo_size;
|
||||
|
||||
@ -1296,8 +1297,8 @@ static int dwc2_hsotg_ep_queue(struct usb_ep *ep, struct usb_request *req,
|
||||
req->zero, req->short_not_ok);
|
||||
|
||||
/* Prevent new request submission when controller is suspended */
|
||||
if (hs->lx_state == DWC2_L2) {
|
||||
dev_dbg(hs->dev, "%s: don't submit request while suspended\n",
|
||||
if (hs->lx_state != DWC2_L0) {
|
||||
dev_dbg(hs->dev, "%s: submit request only in active state\n",
|
||||
__func__);
|
||||
return -EAGAIN;
|
||||
}
|
||||
@ -1639,6 +1640,10 @@ static int dwc2_hsotg_process_req_feature(struct dwc2_hsotg *hsotg,
|
||||
switch (recip) {
|
||||
case USB_RECIP_DEVICE:
|
||||
switch (wValue) {
|
||||
case USB_DEVICE_REMOTE_WAKEUP:
|
||||
hsotg->remote_wakeup_allowed = 1;
|
||||
break;
|
||||
|
||||
case USB_DEVICE_TEST_MODE:
|
||||
if ((wIndex & 0xff) != 0)
|
||||
return -EINVAL;
|
||||
@ -2495,30 +2500,13 @@ bad_mps:
|
||||
*/
|
||||
static void dwc2_hsotg_txfifo_flush(struct dwc2_hsotg *hsotg, unsigned int idx)
|
||||
{
|
||||
int timeout;
|
||||
int val;
|
||||
|
||||
dwc2_writel(GRSTCTL_TXFNUM(idx) | GRSTCTL_TXFFLSH,
|
||||
hsotg->regs + GRSTCTL);
|
||||
|
||||
/* wait until the fifo is flushed */
|
||||
timeout = 100;
|
||||
|
||||
while (1) {
|
||||
val = dwc2_readl(hsotg->regs + GRSTCTL);
|
||||
|
||||
if ((val & (GRSTCTL_TXFFLSH)) == 0)
|
||||
break;
|
||||
|
||||
if (--timeout == 0) {
|
||||
dev_err(hsotg->dev,
|
||||
"%s: timeout flushing fifo (GRSTCTL=%08x)\n",
|
||||
__func__, val);
|
||||
break;
|
||||
}
|
||||
|
||||
udelay(1);
|
||||
}
|
||||
if (dwc2_hsotg_wait_bit_clear(hsotg, GRSTCTL, GRSTCTL_TXFFLSH, 100))
|
||||
dev_warn(hsotg->dev, "%s: timeout flushing fifo GRSTCTL_TXFFLSH\n",
|
||||
__func__);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -3253,7 +3241,7 @@ void dwc2_hsotg_core_init_disconnected(struct dwc2_hsotg *hsotg,
|
||||
dwc2_hsotg_init_fifo(hsotg);
|
||||
|
||||
if (!is_usb_reset)
|
||||
__orr32(hsotg->regs + DCTL, DCTL_SFTDISCON);
|
||||
dwc2_set_bit(hsotg->regs + DCTL, DCTL_SFTDISCON);
|
||||
|
||||
dcfg |= DCFG_EPMISCNT(1);
|
||||
|
||||
@ -3282,7 +3270,8 @@ void dwc2_hsotg_core_init_disconnected(struct dwc2_hsotg *hsotg,
|
||||
GINTSTS_GOUTNAKEFF | GINTSTS_GINNAKEFF |
|
||||
GINTSTS_USBRST | GINTSTS_RESETDET |
|
||||
GINTSTS_ENUMDONE | GINTSTS_OTGINT |
|
||||
GINTSTS_USBSUSP | GINTSTS_WKUPINT;
|
||||
GINTSTS_USBSUSP | GINTSTS_WKUPINT |
|
||||
GINTSTS_LPMTRANRCVD;
|
||||
|
||||
if (!using_desc_dma(hsotg))
|
||||
intmsk |= GINTSTS_INCOMPL_SOIN | GINTSTS_INCOMPL_SOOUT;
|
||||
@ -3294,12 +3283,12 @@ void dwc2_hsotg_core_init_disconnected(struct dwc2_hsotg *hsotg,
|
||||
|
||||
if (using_dma(hsotg)) {
|
||||
dwc2_writel(GAHBCFG_GLBL_INTR_EN | GAHBCFG_DMA_EN |
|
||||
(GAHBCFG_HBSTLEN_INCR4 << GAHBCFG_HBSTLEN_SHIFT),
|
||||
hsotg->params.ahbcfg,
|
||||
hsotg->regs + GAHBCFG);
|
||||
|
||||
/* Set DDMA mode support in the core if needed */
|
||||
if (using_desc_dma(hsotg))
|
||||
__orr32(hsotg->regs + DCFG, DCFG_DESCDMA_EN);
|
||||
dwc2_set_bit(hsotg->regs + DCFG, DCFG_DESCDMA_EN);
|
||||
|
||||
} else {
|
||||
dwc2_writel(((hsotg->dedicated_fifos) ?
|
||||
@ -3332,7 +3321,7 @@ void dwc2_hsotg_core_init_disconnected(struct dwc2_hsotg *hsotg,
|
||||
|
||||
/* Enable BNA interrupt for DDMA */
|
||||
if (using_desc_dma(hsotg))
|
||||
__orr32(hsotg->regs + DOEPMSK, DOEPMSK_BNAMSK);
|
||||
dwc2_set_bit(hsotg->regs + DOEPMSK, DOEPMSK_BNAMSK);
|
||||
|
||||
dwc2_writel(0, hsotg->regs + DAINTMSK);
|
||||
|
||||
@ -3356,9 +3345,9 @@ void dwc2_hsotg_core_init_disconnected(struct dwc2_hsotg *hsotg,
|
||||
dwc2_hsotg_ctrl_epint(hsotg, 0, 1, 1);
|
||||
|
||||
if (!is_usb_reset) {
|
||||
__orr32(hsotg->regs + DCTL, DCTL_PWRONPRGDONE);
|
||||
dwc2_set_bit(hsotg->regs + DCTL, DCTL_PWRONPRGDONE);
|
||||
udelay(10); /* see openiboot */
|
||||
__bic32(hsotg->regs + DCTL, DCTL_PWRONPRGDONE);
|
||||
dwc2_clear_bit(hsotg->regs + DCTL, DCTL_PWRONPRGDONE);
|
||||
}
|
||||
|
||||
dev_dbg(hsotg->dev, "DCTL=0x%08x\n", dwc2_readl(hsotg->regs + DCTL));
|
||||
@ -3385,7 +3374,10 @@ void dwc2_hsotg_core_init_disconnected(struct dwc2_hsotg *hsotg,
|
||||
val = DCTL_CGOUTNAK | DCTL_CGNPINNAK;
|
||||
if (!is_usb_reset)
|
||||
val |= DCTL_SFTDISCON;
|
||||
__orr32(hsotg->regs + DCTL, val);
|
||||
dwc2_set_bit(hsotg->regs + DCTL, val);
|
||||
|
||||
/* configure the core to support LPM */
|
||||
dwc2_gadget_init_lpm(hsotg);
|
||||
|
||||
/* must be at-least 3ms to allow bus to see disconnect */
|
||||
mdelay(3);
|
||||
@ -3402,13 +3394,13 @@ void dwc2_hsotg_core_init_disconnected(struct dwc2_hsotg *hsotg,
|
||||
static void dwc2_hsotg_core_disconnect(struct dwc2_hsotg *hsotg)
|
||||
{
|
||||
/* set the soft-disconnect bit */
|
||||
__orr32(hsotg->regs + DCTL, DCTL_SFTDISCON);
|
||||
dwc2_set_bit(hsotg->regs + DCTL, DCTL_SFTDISCON);
|
||||
}
|
||||
|
||||
void dwc2_hsotg_core_connect(struct dwc2_hsotg *hsotg)
|
||||
{
|
||||
/* remove the soft-disconnect and let's go */
|
||||
__bic32(hsotg->regs + DCTL, DCTL_SFTDISCON);
|
||||
dwc2_clear_bit(hsotg->regs + DCTL, DCTL_SFTDISCON);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -3428,14 +3420,21 @@ static void dwc2_gadget_handle_incomplete_isoc_in(struct dwc2_hsotg *hsotg)
|
||||
{
|
||||
struct dwc2_hsotg_ep *hs_ep;
|
||||
u32 epctrl;
|
||||
u32 daintmsk;
|
||||
u32 idx;
|
||||
|
||||
dev_dbg(hsotg->dev, "Incomplete isoc in interrupt received:\n");
|
||||
|
||||
daintmsk = dwc2_readl(hsotg->regs + DAINTMSK);
|
||||
|
||||
for (idx = 1; idx <= hsotg->num_of_eps; idx++) {
|
||||
hs_ep = hsotg->eps_in[idx];
|
||||
/* Proceed only unmasked ISOC EPs */
|
||||
if (!hs_ep->isochronous || (BIT(idx) & ~daintmsk))
|
||||
continue;
|
||||
|
||||
epctrl = dwc2_readl(hsotg->regs + DIEPCTL(idx));
|
||||
if ((epctrl & DXEPCTL_EPENA) && hs_ep->isochronous &&
|
||||
if ((epctrl & DXEPCTL_EPENA) &&
|
||||
dwc2_gadget_target_frame_elapsed(hs_ep)) {
|
||||
epctrl |= DXEPCTL_SNAK;
|
||||
epctrl |= DXEPCTL_EPDIS;
|
||||
@ -3464,16 +3463,24 @@ static void dwc2_gadget_handle_incomplete_isoc_out(struct dwc2_hsotg *hsotg)
|
||||
{
|
||||
u32 gintsts;
|
||||
u32 gintmsk;
|
||||
u32 daintmsk;
|
||||
u32 epctrl;
|
||||
struct dwc2_hsotg_ep *hs_ep;
|
||||
int idx;
|
||||
|
||||
dev_dbg(hsotg->dev, "%s: GINTSTS_INCOMPL_SOOUT\n", __func__);
|
||||
|
||||
daintmsk = dwc2_readl(hsotg->regs + DAINTMSK);
|
||||
daintmsk >>= DAINT_OUTEP_SHIFT;
|
||||
|
||||
for (idx = 1; idx <= hsotg->num_of_eps; idx++) {
|
||||
hs_ep = hsotg->eps_out[idx];
|
||||
/* Proceed only unmasked ISOC EPs */
|
||||
if (!hs_ep->isochronous || (BIT(idx) & ~daintmsk))
|
||||
continue;
|
||||
|
||||
epctrl = dwc2_readl(hsotg->regs + DOEPCTL(idx));
|
||||
if ((epctrl & DXEPCTL_EPENA) && hs_ep->isochronous &&
|
||||
if ((epctrl & DXEPCTL_EPENA) &&
|
||||
dwc2_gadget_target_frame_elapsed(hs_ep)) {
|
||||
/* Unmask GOUTNAKEFF interrupt */
|
||||
gintmsk = dwc2_readl(hsotg->regs + GINTMSK);
|
||||
@ -3481,8 +3488,10 @@ static void dwc2_gadget_handle_incomplete_isoc_out(struct dwc2_hsotg *hsotg)
|
||||
dwc2_writel(gintmsk, hsotg->regs + GINTMSK);
|
||||
|
||||
gintsts = dwc2_readl(hsotg->regs + GINTSTS);
|
||||
if (!(gintsts & GINTSTS_GOUTNAKEFF))
|
||||
__orr32(hsotg->regs + DCTL, DCTL_SGOUTNAK);
|
||||
if (!(gintsts & GINTSTS_GOUTNAKEFF)) {
|
||||
dwc2_set_bit(hsotg->regs + DCTL, DCTL_SGOUTNAK);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -3522,7 +3531,7 @@ irq_retry:
|
||||
|
||||
/* This event must be used only if controller is suspended */
|
||||
if (hsotg->lx_state == DWC2_L2) {
|
||||
dwc2_exit_hibernation(hsotg, true);
|
||||
dwc2_exit_partial_power_down(hsotg, true);
|
||||
hsotg->lx_state = DWC2_L0;
|
||||
}
|
||||
}
|
||||
@ -3541,7 +3550,7 @@ irq_retry:
|
||||
dwc2_hsotg_disconnect(hsotg);
|
||||
|
||||
/* Reset device address to zero */
|
||||
__bic32(hsotg->regs + DCFG, DCFG_DEVADDR_MASK);
|
||||
dwc2_clear_bit(hsotg->regs + DCFG, DCFG_DEVADDR_MASK);
|
||||
|
||||
if (usb_status & GOTGCTL_BSESVLD && connected)
|
||||
dwc2_hsotg_core_init_disconnected(hsotg, true);
|
||||
@ -3627,8 +3636,11 @@ irq_retry:
|
||||
u8 idx;
|
||||
u32 epctrl;
|
||||
u32 gintmsk;
|
||||
u32 daintmsk;
|
||||
struct dwc2_hsotg_ep *hs_ep;
|
||||
|
||||
daintmsk = dwc2_readl(hsotg->regs + DAINTMSK);
|
||||
daintmsk >>= DAINT_OUTEP_SHIFT;
|
||||
/* Mask this interrupt */
|
||||
gintmsk = dwc2_readl(hsotg->regs + GINTMSK);
|
||||
gintmsk &= ~GINTSTS_GOUTNAKEFF;
|
||||
@ -3637,9 +3649,13 @@ irq_retry:
|
||||
dev_dbg(hsotg->dev, "GOUTNakEff triggered\n");
|
||||
for (idx = 1; idx <= hsotg->num_of_eps; idx++) {
|
||||
hs_ep = hsotg->eps_out[idx];
|
||||
/* Proceed only unmasked ISOC EPs */
|
||||
if (!hs_ep->isochronous || (BIT(idx) & ~daintmsk))
|
||||
continue;
|
||||
|
||||
epctrl = dwc2_readl(hsotg->regs + DOEPCTL(idx));
|
||||
|
||||
if ((epctrl & DXEPCTL_EPENA) && hs_ep->isochronous) {
|
||||
if (epctrl & DXEPCTL_EPENA) {
|
||||
epctrl |= DXEPCTL_SNAK;
|
||||
epctrl |= DXEPCTL_EPDIS;
|
||||
dwc2_writel(epctrl, hsotg->regs + DOEPCTL(idx));
|
||||
@ -3652,7 +3668,7 @@ irq_retry:
|
||||
if (gintsts & GINTSTS_GINNAKEFF) {
|
||||
dev_info(hsotg->dev, "GINNakEff triggered\n");
|
||||
|
||||
__orr32(hsotg->regs + DCTL, DCTL_CGNPINNAK);
|
||||
dwc2_set_bit(hsotg->regs + DCTL, DCTL_CGNPINNAK);
|
||||
|
||||
dwc2_hsotg_dump(hsotg);
|
||||
}
|
||||
@ -3676,20 +3692,6 @@ irq_retry:
|
||||
return IRQ_HANDLED;
|
||||
}
|
||||
|
||||
static int dwc2_hsotg_wait_bit_set(struct dwc2_hsotg *hs_otg, u32 reg,
|
||||
u32 bit, u32 timeout)
|
||||
{
|
||||
u32 i;
|
||||
|
||||
for (i = 0; i < timeout; i++) {
|
||||
if (dwc2_readl(hs_otg->regs + reg) & bit)
|
||||
return 0;
|
||||
udelay(1);
|
||||
}
|
||||
|
||||
return -ETIMEDOUT;
|
||||
}
|
||||
|
||||
static void dwc2_hsotg_ep_stop_xfr(struct dwc2_hsotg *hsotg,
|
||||
struct dwc2_hsotg_ep *hs_ep)
|
||||
{
|
||||
@ -3706,7 +3708,7 @@ static void dwc2_hsotg_ep_stop_xfr(struct dwc2_hsotg *hsotg,
|
||||
|
||||
if (hs_ep->dir_in) {
|
||||
if (hsotg->dedicated_fifos || hs_ep->periodic) {
|
||||
__orr32(hsotg->regs + epctrl_reg, DXEPCTL_SNAK);
|
||||
dwc2_set_bit(hsotg->regs + epctrl_reg, DXEPCTL_SNAK);
|
||||
/* Wait for Nak effect */
|
||||
if (dwc2_hsotg_wait_bit_set(hsotg, epint_reg,
|
||||
DXEPINT_INEPNAKEFF, 100))
|
||||
@ -3714,7 +3716,7 @@ static void dwc2_hsotg_ep_stop_xfr(struct dwc2_hsotg *hsotg,
|
||||
"%s: timeout DIEPINT.NAKEFF\n",
|
||||
__func__);
|
||||
} else {
|
||||
__orr32(hsotg->regs + DCTL, DCTL_SGNPINNAK);
|
||||
dwc2_set_bit(hsotg->regs + DCTL, DCTL_SGNPINNAK);
|
||||
/* Wait for Nak effect */
|
||||
if (dwc2_hsotg_wait_bit_set(hsotg, GINTSTS,
|
||||
GINTSTS_GINNAKEFF, 100))
|
||||
@ -3724,7 +3726,7 @@ static void dwc2_hsotg_ep_stop_xfr(struct dwc2_hsotg *hsotg,
|
||||
}
|
||||
} else {
|
||||
if (!(dwc2_readl(hsotg->regs + GINTSTS) & GINTSTS_GOUTNAKEFF))
|
||||
__orr32(hsotg->regs + DCTL, DCTL_SGOUTNAK);
|
||||
dwc2_set_bit(hsotg->regs + DCTL, DCTL_SGOUTNAK);
|
||||
|
||||
/* Wait for global nak to take effect */
|
||||
if (dwc2_hsotg_wait_bit_set(hsotg, GINTSTS,
|
||||
@ -3734,7 +3736,7 @@ static void dwc2_hsotg_ep_stop_xfr(struct dwc2_hsotg *hsotg,
|
||||
}
|
||||
|
||||
/* Disable ep */
|
||||
__orr32(hsotg->regs + epctrl_reg, DXEPCTL_EPDIS | DXEPCTL_SNAK);
|
||||
dwc2_set_bit(hsotg->regs + epctrl_reg, DXEPCTL_EPDIS | DXEPCTL_SNAK);
|
||||
|
||||
/* Wait for ep to be disabled */
|
||||
if (dwc2_hsotg_wait_bit_set(hsotg, epint_reg, DXEPINT_EPDISBLD, 100))
|
||||
@ -3742,7 +3744,7 @@ static void dwc2_hsotg_ep_stop_xfr(struct dwc2_hsotg *hsotg,
|
||||
"%s: timeout DOEPCTL.EPDisable\n", __func__);
|
||||
|
||||
/* Clear EPDISBLD interrupt */
|
||||
__orr32(hsotg->regs + epint_reg, DXEPINT_EPDISBLD);
|
||||
dwc2_set_bit(hsotg->regs + epint_reg, DXEPINT_EPDISBLD);
|
||||
|
||||
if (hs_ep->dir_in) {
|
||||
unsigned short fifo_index;
|
||||
@ -3757,11 +3759,11 @@ static void dwc2_hsotg_ep_stop_xfr(struct dwc2_hsotg *hsotg,
|
||||
|
||||
/* Clear Global In NP NAK in Shared FIFO for non periodic ep */
|
||||
if (!hsotg->dedicated_fifos && !hs_ep->periodic)
|
||||
__orr32(hsotg->regs + DCTL, DCTL_CGNPINNAK);
|
||||
dwc2_set_bit(hsotg->regs + DCTL, DCTL_CGNPINNAK);
|
||||
|
||||
} else {
|
||||
/* Remove global NAKs */
|
||||
__orr32(hsotg->regs + DCTL, DCTL_CGOUTNAK);
|
||||
dwc2_set_bit(hsotg->regs + DCTL, DCTL_CGOUTNAK);
|
||||
}
|
||||
}
|
||||
|
||||
@ -4183,7 +4185,7 @@ static void dwc2_hsotg_init(struct dwc2_hsotg *hsotg)
|
||||
dwc2_writel(0, hsotg->regs + DAINTMSK);
|
||||
|
||||
/* Be in disconnected state until gadget is registered */
|
||||
__orr32(hsotg->regs + DCTL, DCTL_SFTDISCON);
|
||||
dwc2_set_bit(hsotg->regs + DCTL, DCTL_SFTDISCON);
|
||||
|
||||
/* setup fifos */
|
||||
|
||||
@ -4205,7 +4207,7 @@ static void dwc2_hsotg_init(struct dwc2_hsotg *hsotg)
|
||||
dwc2_writel(usbcfg, hsotg->regs + GUSBCFG);
|
||||
|
||||
if (using_dma(hsotg))
|
||||
__orr32(hsotg->regs + GAHBCFG, GAHBCFG_DMA_EN);
|
||||
dwc2_set_bit(hsotg->regs + GAHBCFG, GAHBCFG_DMA_EN);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -4352,6 +4354,8 @@ static int dwc2_hsotg_pullup(struct usb_gadget *gadget, int is_on)
|
||||
if (is_on) {
|
||||
hsotg->enabled = 1;
|
||||
dwc2_hsotg_core_init_disconnected(hsotg, false);
|
||||
/* Enable ACG feature in device mode,if supported */
|
||||
dwc2_enable_acg(hsotg);
|
||||
dwc2_hsotg_core_connect(hsotg);
|
||||
} else {
|
||||
dwc2_hsotg_core_disconnect(hsotg);
|
||||
@ -4374,18 +4378,21 @@ static int dwc2_hsotg_vbus_session(struct usb_gadget *gadget, int is_active)
|
||||
spin_lock_irqsave(&hsotg->lock, flags);
|
||||
|
||||
/*
|
||||
* If controller is hibernated, it must exit from hibernation
|
||||
* If controller is hibernated, it must exit from power_down
|
||||
* before being initialized / de-initialized
|
||||
*/
|
||||
if (hsotg->lx_state == DWC2_L2)
|
||||
dwc2_exit_hibernation(hsotg, false);
|
||||
dwc2_exit_partial_power_down(hsotg, false);
|
||||
|
||||
if (is_active) {
|
||||
hsotg->op_state = OTG_STATE_B_PERIPHERAL;
|
||||
|
||||
dwc2_hsotg_core_init_disconnected(hsotg, false);
|
||||
if (hsotg->enabled)
|
||||
if (hsotg->enabled) {
|
||||
/* Enable ACG feature in device mode,if supported */
|
||||
dwc2_enable_acg(hsotg);
|
||||
dwc2_hsotg_core_connect(hsotg);
|
||||
}
|
||||
} else {
|
||||
dwc2_hsotg_core_disconnect(hsotg);
|
||||
dwc2_hsotg_disconnect(hsotg);
|
||||
@ -4606,9 +4613,8 @@ static void dwc2_hsotg_dump(struct dwc2_hsotg *hsotg)
|
||||
/**
|
||||
* dwc2_gadget_init - init function for gadget
|
||||
* @dwc2: The data structure for the DWC2 driver.
|
||||
* @irq: The IRQ number for the controller.
|
||||
*/
|
||||
int dwc2_gadget_init(struct dwc2_hsotg *hsotg, int irq)
|
||||
int dwc2_gadget_init(struct dwc2_hsotg *hsotg)
|
||||
{
|
||||
struct device *dev = hsotg->dev;
|
||||
int epnum;
|
||||
@ -4622,6 +4628,11 @@ int dwc2_gadget_init(struct dwc2_hsotg *hsotg, int irq)
|
||||
hsotg->gadget.max_speed = USB_SPEED_HIGH;
|
||||
hsotg->gadget.ops = &dwc2_hsotg_gadget_ops;
|
||||
hsotg->gadget.name = dev_name(dev);
|
||||
hsotg->remote_wakeup_allowed = 0;
|
||||
|
||||
if (hsotg->params.lpm)
|
||||
hsotg->gadget.lpm_capable = true;
|
||||
|
||||
if (hsotg->dr_mode == USB_DR_MODE_OTG)
|
||||
hsotg->gadget.is_otg = 1;
|
||||
else if (hsotg->dr_mode == USB_DR_MODE_PERIPHERAL)
|
||||
@ -4649,8 +4660,8 @@ int dwc2_gadget_init(struct dwc2_hsotg *hsotg, int irq)
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = devm_request_irq(hsotg->dev, irq, dwc2_hsotg_irq, IRQF_SHARED,
|
||||
dev_name(hsotg->dev), hsotg);
|
||||
ret = devm_request_irq(hsotg->dev, hsotg->irq, dwc2_hsotg_irq,
|
||||
IRQF_SHARED, dev_name(hsotg->dev), hsotg);
|
||||
if (ret < 0) {
|
||||
dev_err(dev, "cannot claim IRQ for gadget\n");
|
||||
return ret;
|
||||
@ -4751,8 +4762,11 @@ int dwc2_hsotg_resume(struct dwc2_hsotg *hsotg)
|
||||
|
||||
spin_lock_irqsave(&hsotg->lock, flags);
|
||||
dwc2_hsotg_core_init_disconnected(hsotg, false);
|
||||
if (hsotg->enabled)
|
||||
if (hsotg->enabled) {
|
||||
/* Enable ACG feature in device mode,if supported */
|
||||
dwc2_enable_acg(hsotg);
|
||||
dwc2_hsotg_core_connect(hsotg);
|
||||
}
|
||||
spin_unlock_irqrestore(&hsotg->lock, flags);
|
||||
}
|
||||
|
||||
@ -4806,6 +4820,7 @@ int dwc2_backup_device_registers(struct dwc2_hsotg *hsotg)
|
||||
|
||||
dr->doeptsiz[i] = dwc2_readl(hsotg->regs + DOEPTSIZ(i));
|
||||
dr->doepdma[i] = dwc2_readl(hsotg->regs + DOEPDMA(i));
|
||||
dr->dtxfsiz[i] = dwc2_readl(hsotg->regs + DPTXFSIZN(i));
|
||||
}
|
||||
dr->valid = true;
|
||||
return 0;
|
||||
@ -4817,11 +4832,13 @@ int dwc2_backup_device_registers(struct dwc2_hsotg *hsotg)
|
||||
* if controller power were disabled.
|
||||
*
|
||||
* @hsotg: Programming view of the DWC_otg controller
|
||||
* @remote_wakeup: Indicates whether resume is initiated by Device or Host.
|
||||
*
|
||||
* Return: 0 if successful, negative error code otherwise
|
||||
*/
|
||||
int dwc2_restore_device_registers(struct dwc2_hsotg *hsotg)
|
||||
int dwc2_restore_device_registers(struct dwc2_hsotg *hsotg, int remote_wakeup)
|
||||
{
|
||||
struct dwc2_dregs_backup *dr;
|
||||
u32 dctl;
|
||||
int i;
|
||||
|
||||
dev_dbg(hsotg->dev, "%s\n", __func__);
|
||||
@ -4835,28 +4852,240 @@ int dwc2_restore_device_registers(struct dwc2_hsotg *hsotg)
|
||||
}
|
||||
dr->valid = false;
|
||||
|
||||
dwc2_writel(dr->dcfg, hsotg->regs + DCFG);
|
||||
dwc2_writel(dr->dctl, hsotg->regs + DCTL);
|
||||
if (!remote_wakeup)
|
||||
dwc2_writel(dr->dctl, hsotg->regs + DCTL);
|
||||
|
||||
dwc2_writel(dr->daintmsk, hsotg->regs + DAINTMSK);
|
||||
dwc2_writel(dr->diepmsk, hsotg->regs + DIEPMSK);
|
||||
dwc2_writel(dr->doepmsk, hsotg->regs + DOEPMSK);
|
||||
|
||||
for (i = 0; i < hsotg->num_of_eps; i++) {
|
||||
/* Restore IN EPs */
|
||||
dwc2_writel(dr->diepctl[i], hsotg->regs + DIEPCTL(i));
|
||||
dwc2_writel(dr->dieptsiz[i], hsotg->regs + DIEPTSIZ(i));
|
||||
dwc2_writel(dr->diepdma[i], hsotg->regs + DIEPDMA(i));
|
||||
|
||||
/* Restore OUT EPs */
|
||||
dwc2_writel(dr->doepctl[i], hsotg->regs + DOEPCTL(i));
|
||||
dwc2_writel(dr->doeptsiz[i], hsotg->regs + DOEPTSIZ(i));
|
||||
/** WA for enabled EPx's IN in DDMA mode. On entering to
|
||||
* hibernation wrong value read and saved from DIEPDMAx,
|
||||
* as result BNA interrupt asserted on hibernation exit
|
||||
* by restoring from saved area.
|
||||
*/
|
||||
if (hsotg->params.g_dma_desc &&
|
||||
(dr->diepctl[i] & DXEPCTL_EPENA))
|
||||
dr->diepdma[i] = hsotg->eps_in[i]->desc_list_dma;
|
||||
dwc2_writel(dr->dtxfsiz[i], hsotg->regs + DPTXFSIZN(i));
|
||||
dwc2_writel(dr->diepctl[i], hsotg->regs + DIEPCTL(i));
|
||||
/* Restore OUT EPs */
|
||||
dwc2_writel(dr->doeptsiz[i], hsotg->regs + DOEPTSIZ(i));
|
||||
/* WA for enabled EPx's OUT in DDMA mode. On entering to
|
||||
* hibernation wrong value read and saved from DOEPDMAx,
|
||||
* as result BNA interrupt asserted on hibernation exit
|
||||
* by restoring from saved area.
|
||||
*/
|
||||
if (hsotg->params.g_dma_desc &&
|
||||
(dr->doepctl[i] & DXEPCTL_EPENA))
|
||||
dr->doepdma[i] = hsotg->eps_out[i]->desc_list_dma;
|
||||
dwc2_writel(dr->doepdma[i], hsotg->regs + DOEPDMA(i));
|
||||
dwc2_writel(dr->doepctl[i], hsotg->regs + DOEPCTL(i));
|
||||
}
|
||||
|
||||
/* Set the Power-On Programming done bit */
|
||||
dctl = dwc2_readl(hsotg->regs + DCTL);
|
||||
dctl |= DCTL_PWRONPRGDONE;
|
||||
dwc2_writel(dctl, hsotg->regs + DCTL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* dwc2_gadget_init_lpm - Configure the core to support LPM in device mode
|
||||
*
|
||||
* @hsotg: Programming view of DWC_otg controller
|
||||
*
|
||||
*/
|
||||
void dwc2_gadget_init_lpm(struct dwc2_hsotg *hsotg)
|
||||
{
|
||||
u32 val;
|
||||
|
||||
if (!hsotg->params.lpm)
|
||||
return;
|
||||
|
||||
val = GLPMCFG_LPMCAP | GLPMCFG_APPL1RES;
|
||||
val |= hsotg->params.hird_threshold_en ? GLPMCFG_HIRD_THRES_EN : 0;
|
||||
val |= hsotg->params.lpm_clock_gating ? GLPMCFG_ENBLSLPM : 0;
|
||||
val |= hsotg->params.hird_threshold << GLPMCFG_HIRD_THRES_SHIFT;
|
||||
val |= hsotg->params.besl ? GLPMCFG_ENBESL : 0;
|
||||
dwc2_writel(val, hsotg->regs + GLPMCFG);
|
||||
dev_dbg(hsotg->dev, "GLPMCFG=0x%08x\n", dwc2_readl(hsotg->regs
|
||||
+ GLPMCFG));
|
||||
}
|
||||
|
||||
/**
|
||||
* dwc2_gadget_enter_hibernation() - Put controller in Hibernation.
|
||||
*
|
||||
* @hsotg: Programming view of the DWC_otg controller
|
||||
*
|
||||
* Return non-zero if failed to enter to hibernation.
|
||||
*/
|
||||
int dwc2_gadget_enter_hibernation(struct dwc2_hsotg *hsotg)
|
||||
{
|
||||
u32 gpwrdn;
|
||||
int ret = 0;
|
||||
|
||||
/* Change to L2(suspend) state */
|
||||
hsotg->lx_state = DWC2_L2;
|
||||
dev_dbg(hsotg->dev, "Start of hibernation completed\n");
|
||||
ret = dwc2_backup_global_registers(hsotg);
|
||||
if (ret) {
|
||||
dev_err(hsotg->dev, "%s: failed to backup global registers\n",
|
||||
__func__);
|
||||
return ret;
|
||||
}
|
||||
ret = dwc2_backup_device_registers(hsotg);
|
||||
if (ret) {
|
||||
dev_err(hsotg->dev, "%s: failed to backup device registers\n",
|
||||
__func__);
|
||||
return ret;
|
||||
}
|
||||
|
||||
gpwrdn = GPWRDN_PWRDNRSTN;
|
||||
gpwrdn |= GPWRDN_PMUACTV;
|
||||
dwc2_writel(gpwrdn, hsotg->regs + GPWRDN);
|
||||
udelay(10);
|
||||
|
||||
/* Set flag to indicate that we are in hibernation */
|
||||
hsotg->hibernated = 1;
|
||||
|
||||
/* Enable interrupts from wake up logic */
|
||||
gpwrdn = dwc2_readl(hsotg->regs + GPWRDN);
|
||||
gpwrdn |= GPWRDN_PMUINTSEL;
|
||||
dwc2_writel(gpwrdn, hsotg->regs + GPWRDN);
|
||||
udelay(10);
|
||||
|
||||
/* Unmask device mode interrupts in GPWRDN */
|
||||
gpwrdn = dwc2_readl(hsotg->regs + GPWRDN);
|
||||
gpwrdn |= GPWRDN_RST_DET_MSK;
|
||||
gpwrdn |= GPWRDN_LNSTSCHG_MSK;
|
||||
gpwrdn |= GPWRDN_STS_CHGINT_MSK;
|
||||
dwc2_writel(gpwrdn, hsotg->regs + GPWRDN);
|
||||
udelay(10);
|
||||
|
||||
/* Enable Power Down Clamp */
|
||||
gpwrdn = dwc2_readl(hsotg->regs + GPWRDN);
|
||||
gpwrdn |= GPWRDN_PWRDNCLMP;
|
||||
dwc2_writel(gpwrdn, hsotg->regs + GPWRDN);
|
||||
udelay(10);
|
||||
|
||||
/* Switch off VDD */
|
||||
gpwrdn = dwc2_readl(hsotg->regs + GPWRDN);
|
||||
gpwrdn |= GPWRDN_PWRDNSWTCH;
|
||||
dwc2_writel(gpwrdn, hsotg->regs + GPWRDN);
|
||||
udelay(10);
|
||||
|
||||
/* Save gpwrdn register for further usage if stschng interrupt */
|
||||
hsotg->gr_backup.gpwrdn = dwc2_readl(hsotg->regs + GPWRDN);
|
||||
dev_dbg(hsotg->dev, "Hibernation completed\n");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* dwc2_gadget_exit_hibernation()
|
||||
* This function is for exiting from Device mode hibernation by host initiated
|
||||
* resume/reset and device initiated remote-wakeup.
|
||||
*
|
||||
* @hsotg: Programming view of the DWC_otg controller
|
||||
* @rem_wakeup: indicates whether resume is initiated by Device or Host.
|
||||
* @param reset: indicates whether resume is initiated by Reset.
|
||||
*
|
||||
* Return non-zero if failed to exit from hibernation.
|
||||
*/
|
||||
int dwc2_gadget_exit_hibernation(struct dwc2_hsotg *hsotg,
|
||||
int rem_wakeup, int reset)
|
||||
{
|
||||
u32 pcgcctl;
|
||||
u32 gpwrdn;
|
||||
u32 dctl;
|
||||
int ret = 0;
|
||||
struct dwc2_gregs_backup *gr;
|
||||
struct dwc2_dregs_backup *dr;
|
||||
|
||||
gr = &hsotg->gr_backup;
|
||||
dr = &hsotg->dr_backup;
|
||||
|
||||
if (!hsotg->hibernated) {
|
||||
dev_dbg(hsotg->dev, "Already exited from Hibernation\n");
|
||||
return 1;
|
||||
}
|
||||
dev_dbg(hsotg->dev,
|
||||
"%s: called with rem_wakeup = %d reset = %d\n",
|
||||
__func__, rem_wakeup, reset);
|
||||
|
||||
dwc2_hib_restore_common(hsotg, rem_wakeup, 0);
|
||||
|
||||
if (!reset) {
|
||||
/* Clear all pending interupts */
|
||||
dwc2_writel(0xffffffff, hsotg->regs + GINTSTS);
|
||||
}
|
||||
|
||||
/* De-assert Restore */
|
||||
gpwrdn = dwc2_readl(hsotg->regs + GPWRDN);
|
||||
gpwrdn &= ~GPWRDN_RESTORE;
|
||||
dwc2_writel(gpwrdn, hsotg->regs + GPWRDN);
|
||||
udelay(10);
|
||||
|
||||
if (!rem_wakeup) {
|
||||
pcgcctl = dwc2_readl(hsotg->regs + PCGCTL);
|
||||
pcgcctl &= ~PCGCTL_RSTPDWNMODULE;
|
||||
dwc2_writel(pcgcctl, hsotg->regs + PCGCTL);
|
||||
}
|
||||
|
||||
/* Restore GUSBCFG, DCFG and DCTL */
|
||||
dwc2_writel(gr->gusbcfg, hsotg->regs + GUSBCFG);
|
||||
dwc2_writel(dr->dcfg, hsotg->regs + DCFG);
|
||||
dwc2_writel(dr->dctl, hsotg->regs + DCTL);
|
||||
|
||||
/* De-assert Wakeup Logic */
|
||||
gpwrdn = dwc2_readl(hsotg->regs + GPWRDN);
|
||||
gpwrdn &= ~GPWRDN_PMUACTV;
|
||||
dwc2_writel(gpwrdn, hsotg->regs + GPWRDN);
|
||||
|
||||
if (rem_wakeup) {
|
||||
udelay(10);
|
||||
/* Start Remote Wakeup Signaling */
|
||||
dwc2_writel(dr->dctl | DCTL_RMTWKUPSIG, hsotg->regs + DCTL);
|
||||
} else {
|
||||
udelay(50);
|
||||
/* Set Device programming done bit */
|
||||
dctl = dwc2_readl(hsotg->regs + DCTL);
|
||||
dctl |= DCTL_PWRONPRGDONE;
|
||||
dwc2_writel(dctl, hsotg->regs + DCTL);
|
||||
}
|
||||
/* Wait for interrupts which must be cleared */
|
||||
mdelay(2);
|
||||
/* Clear all pending interupts */
|
||||
dwc2_writel(0xffffffff, hsotg->regs + GINTSTS);
|
||||
|
||||
/* Restore global registers */
|
||||
ret = dwc2_restore_global_registers(hsotg);
|
||||
if (ret) {
|
||||
dev_err(hsotg->dev, "%s: failed to restore registers\n",
|
||||
__func__);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Restore device registers */
|
||||
ret = dwc2_restore_device_registers(hsotg, rem_wakeup);
|
||||
if (ret) {
|
||||
dev_err(hsotg->dev, "%s: failed to restore device registers\n",
|
||||
__func__);
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (rem_wakeup) {
|
||||
mdelay(10);
|
||||
dctl = dwc2_readl(hsotg->regs + DCTL);
|
||||
dctl &= ~DCTL_RMTWKUPSIG;
|
||||
dwc2_writel(dctl, hsotg->regs + DCTL);
|
||||
}
|
||||
|
||||
hsotg->hibernated = 0;
|
||||
hsotg->lx_state = DWC2_L0;
|
||||
dev_dbg(hsotg->dev, "Hibernation recovery completes here\n");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -91,6 +91,9 @@ static void dwc2_enable_common_interrupts(struct dwc2_hsotg *hsotg)
|
||||
intmsk |= GINTSTS_WKUPINT | GINTSTS_USBSUSP |
|
||||
GINTSTS_SESSREQINT;
|
||||
|
||||
if (dwc2_is_device_mode(hsotg) && hsotg->params.lpm)
|
||||
intmsk |= GINTSTS_LPMTRANRCVD;
|
||||
|
||||
dwc2_writel(intmsk, hsotg->regs + GINTMSK);
|
||||
}
|
||||
|
||||
@ -138,7 +141,7 @@ static int dwc2_fs_phy_init(struct dwc2_hsotg *hsotg, bool select_phy)
|
||||
dwc2_writel(usbcfg, hsotg->regs + GUSBCFG);
|
||||
|
||||
/* Reset after a PHY select */
|
||||
retval = dwc2_core_reset_and_force_dr_mode(hsotg);
|
||||
retval = dwc2_core_reset(hsotg, false);
|
||||
|
||||
if (retval) {
|
||||
dev_err(hsotg->dev,
|
||||
@ -236,7 +239,7 @@ static int dwc2_hs_phy_init(struct dwc2_hsotg *hsotg, bool select_phy)
|
||||
dwc2_writel(usbcfg, hsotg->regs + GUSBCFG);
|
||||
|
||||
/* Reset after setting the PHY parameters */
|
||||
retval = dwc2_core_reset_and_force_dr_mode(hsotg);
|
||||
retval = dwc2_core_reset(hsotg, false);
|
||||
if (retval) {
|
||||
dev_err(hsotg->dev,
|
||||
"%s: Reset failed, aborting", __func__);
|
||||
@ -308,22 +311,10 @@ static int dwc2_gahbcfg_init(struct dwc2_hsotg *hsotg)
|
||||
break;
|
||||
}
|
||||
|
||||
dev_dbg(hsotg->dev, "host_dma:%d dma_desc_enable:%d\n",
|
||||
hsotg->params.host_dma,
|
||||
hsotg->params.dma_desc_enable);
|
||||
|
||||
if (hsotg->params.host_dma) {
|
||||
if (hsotg->params.dma_desc_enable)
|
||||
dev_dbg(hsotg->dev, "Using Descriptor DMA mode\n");
|
||||
else
|
||||
dev_dbg(hsotg->dev, "Using Buffer DMA mode\n");
|
||||
} else {
|
||||
dev_dbg(hsotg->dev, "Using Slave mode\n");
|
||||
hsotg->params.dma_desc_enable = false;
|
||||
}
|
||||
|
||||
if (hsotg->params.host_dma)
|
||||
ahbcfg |= GAHBCFG_DMA_EN;
|
||||
else
|
||||
hsotg->params.dma_desc_enable = false;
|
||||
|
||||
dwc2_writel(ahbcfg, hsotg->regs + GAHBCFG);
|
||||
|
||||
@ -365,6 +356,23 @@ static void dwc2_gusbcfg_init(struct dwc2_hsotg *hsotg)
|
||||
dwc2_writel(usbcfg, hsotg->regs + GUSBCFG);
|
||||
}
|
||||
|
||||
static int dwc2_vbus_supply_init(struct dwc2_hsotg *hsotg)
|
||||
{
|
||||
hsotg->vbus_supply = devm_regulator_get_optional(hsotg->dev, "vbus");
|
||||
if (IS_ERR(hsotg->vbus_supply))
|
||||
return 0;
|
||||
|
||||
return regulator_enable(hsotg->vbus_supply);
|
||||
}
|
||||
|
||||
static int dwc2_vbus_supply_exit(struct dwc2_hsotg *hsotg)
|
||||
{
|
||||
if (hsotg->vbus_supply)
|
||||
return regulator_disable(hsotg->vbus_supply);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* dwc2_enable_host_interrupts() - Enables the Host mode interrupts
|
||||
*
|
||||
@ -989,6 +997,24 @@ void dwc2_hc_halt(struct dwc2_hsotg *hsotg, struct dwc2_host_chan *chan,
|
||||
|
||||
if (dbg_hc(chan))
|
||||
dev_vdbg(hsotg->dev, "%s()\n", __func__);
|
||||
|
||||
/*
|
||||
* In buffer DMA or external DMA mode channel can't be halted
|
||||
* for non-split periodic channels. At the end of the next
|
||||
* uframe/frame (in the worst case), the core generates a channel
|
||||
* halted and disables the channel automatically.
|
||||
*/
|
||||
if ((hsotg->params.g_dma && !hsotg->params.g_dma_desc) ||
|
||||
hsotg->hw_params.arch == GHWCFG2_EXT_DMA_ARCH) {
|
||||
if (!chan->do_split &&
|
||||
(chan->ep_type == USB_ENDPOINT_XFER_ISOC ||
|
||||
chan->ep_type == USB_ENDPOINT_XFER_INT)) {
|
||||
dev_err(hsotg->dev, "%s() Channel can't be halted\n",
|
||||
__func__);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (halt_status == DWC2_HC_XFER_NO_HALT_STATUS)
|
||||
dev_err(hsotg->dev, "!!! halt_status = %d !!!\n", halt_status);
|
||||
|
||||
@ -2232,7 +2258,7 @@ static int dwc2_hcd_endpoint_reset(struct dwc2_hsotg *hsotg,
|
||||
* @hsotg: Programming view of the DWC_otg controller
|
||||
* @initial_setup: If true then this is the first init for this instance.
|
||||
*/
|
||||
static int dwc2_core_init(struct dwc2_hsotg *hsotg, bool initial_setup)
|
||||
int dwc2_core_init(struct dwc2_hsotg *hsotg, bool initial_setup)
|
||||
{
|
||||
u32 usbcfg, otgctl;
|
||||
int retval;
|
||||
@ -2261,7 +2287,7 @@ static int dwc2_core_init(struct dwc2_hsotg *hsotg, bool initial_setup)
|
||||
* needed to in order to properly detect various parameters).
|
||||
*/
|
||||
if (!initial_setup) {
|
||||
retval = dwc2_core_reset_and_force_dr_mode(hsotg);
|
||||
retval = dwc2_core_reset(hsotg, false);
|
||||
if (retval) {
|
||||
dev_err(hsotg->dev, "%s(): Reset failed, aborting\n",
|
||||
__func__);
|
||||
@ -2322,10 +2348,22 @@ static int dwc2_core_init(struct dwc2_hsotg *hsotg, bool initial_setup)
|
||||
*/
|
||||
static void dwc2_core_host_init(struct dwc2_hsotg *hsotg)
|
||||
{
|
||||
u32 hcfg, hfir, otgctl;
|
||||
u32 hcfg, hfir, otgctl, usbcfg;
|
||||
|
||||
dev_dbg(hsotg->dev, "%s(%p)\n", __func__, hsotg);
|
||||
|
||||
/* Set HS/FS Timeout Calibration to 7 (max available value).
|
||||
* The number of PHY clocks that the application programs in
|
||||
* this field is added to the high/full speed interpacket timeout
|
||||
* duration in the core to account for any additional delays
|
||||
* introduced by the PHY. This can be required, because the delay
|
||||
* introduced by the PHY in generating the linestate condition
|
||||
* can vary from one PHY to another.
|
||||
*/
|
||||
usbcfg = dwc2_readl(hsotg->regs + GUSBCFG);
|
||||
usbcfg |= GUSBCFG_TOUTCAL(7);
|
||||
dwc2_writel(usbcfg, hsotg->regs + GUSBCFG);
|
||||
|
||||
/* Restart the Phy Clock */
|
||||
dwc2_writel(0, hsotg->regs + PCGCTL);
|
||||
|
||||
@ -2403,27 +2441,24 @@ static void dwc2_core_host_init(struct dwc2_hsotg *hsotg)
|
||||
|
||||
/* Halt all channels to put them into a known state */
|
||||
for (i = 0; i < num_channels; i++) {
|
||||
int count = 0;
|
||||
|
||||
hcchar = dwc2_readl(hsotg->regs + HCCHAR(i));
|
||||
hcchar |= HCCHAR_CHENA | HCCHAR_CHDIS;
|
||||
hcchar &= ~HCCHAR_EPDIR;
|
||||
dwc2_writel(hcchar, hsotg->regs + HCCHAR(i));
|
||||
dev_dbg(hsotg->dev, "%s: Halt channel %d\n",
|
||||
__func__, i);
|
||||
do {
|
||||
hcchar = dwc2_readl(hsotg->regs + HCCHAR(i));
|
||||
if (++count > 1000) {
|
||||
dev_err(hsotg->dev,
|
||||
"Unable to clear enable on channel %d\n",
|
||||
i);
|
||||
break;
|
||||
}
|
||||
udelay(1);
|
||||
} while (hcchar & HCCHAR_CHENA);
|
||||
|
||||
if (dwc2_hsotg_wait_bit_clear(hsotg, HCCHAR(i),
|
||||
HCCHAR_CHENA, 1000)) {
|
||||
dev_warn(hsotg->dev, "Unable to clear enable on channel %d\n",
|
||||
i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Enable ACG feature in host mode, if supported */
|
||||
dwc2_enable_acg(hsotg);
|
||||
|
||||
/* Turn on the vbus power */
|
||||
dev_dbg(hsotg->dev, "Init: Port Power? op_state=%d\n", hsotg->op_state);
|
||||
if (hsotg->op_state == OTG_STATE_A_HOST) {
|
||||
@ -3257,6 +3292,7 @@ static void dwc2_conn_id_status_change(struct work_struct *work)
|
||||
|
||||
/* B-Device connector (Device Mode) */
|
||||
if (gotgctl & GOTGCTL_CONID_B) {
|
||||
dwc2_vbus_supply_exit(hsotg);
|
||||
/* Wait for switch to device mode */
|
||||
dev_dbg(hsotg->dev, "connId B\n");
|
||||
if (hsotg->bus_suspended) {
|
||||
@ -3290,6 +3326,8 @@ static void dwc2_conn_id_status_change(struct work_struct *work)
|
||||
spin_lock_irqsave(&hsotg->lock, flags);
|
||||
dwc2_hsotg_core_init_disconnected(hsotg, false);
|
||||
spin_unlock_irqrestore(&hsotg->lock, flags);
|
||||
/* Enable ACG feature in device mode,if supported */
|
||||
dwc2_enable_acg(hsotg);
|
||||
dwc2_hsotg_core_connect(hsotg);
|
||||
} else {
|
||||
host:
|
||||
@ -3377,10 +3415,10 @@ static void dwc2_port_suspend(struct dwc2_hsotg *hsotg, u16 windex)
|
||||
hsotg->bus_suspended = true;
|
||||
|
||||
/*
|
||||
* If hibernation is supported, Phy clock will be suspended
|
||||
* If power_down is supported, Phy clock will be suspended
|
||||
* after registers are backuped.
|
||||
*/
|
||||
if (!hsotg->params.hibernation) {
|
||||
if (!hsotg->params.power_down) {
|
||||
/* Suspend the Phy Clock */
|
||||
pcgctl = dwc2_readl(hsotg->regs + PCGCTL);
|
||||
pcgctl |= PCGCTL_STOPPCLK;
|
||||
@ -3412,10 +3450,10 @@ static void dwc2_port_resume(struct dwc2_hsotg *hsotg)
|
||||
spin_lock_irqsave(&hsotg->lock, flags);
|
||||
|
||||
/*
|
||||
* If hibernation is supported, Phy clock is already resumed
|
||||
* If power_down is supported, Phy clock is already resumed
|
||||
* after registers restore.
|
||||
*/
|
||||
if (!hsotg->params.hibernation) {
|
||||
if (!hsotg->params.power_down) {
|
||||
pcgctl = dwc2_readl(hsotg->regs + PCGCTL);
|
||||
pcgctl &= ~PCGCTL_STOPPCLK;
|
||||
dwc2_writel(pcgctl, hsotg->regs + PCGCTL);
|
||||
@ -3486,8 +3524,12 @@ static int dwc2_hcd_hub_control(struct dwc2_hsotg *hsotg, u16 typereq,
|
||||
dev_dbg(hsotg->dev,
|
||||
"ClearPortFeature USB_PORT_FEAT_SUSPEND\n");
|
||||
|
||||
if (hsotg->bus_suspended)
|
||||
dwc2_port_resume(hsotg);
|
||||
if (hsotg->bus_suspended) {
|
||||
if (hsotg->hibernated)
|
||||
dwc2_exit_hibernation(hsotg, 0, 0, 1);
|
||||
else
|
||||
dwc2_port_resume(hsotg);
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_PORT_FEAT_POWER:
|
||||
@ -3695,7 +3737,10 @@ static int dwc2_hcd_hub_control(struct dwc2_hsotg *hsotg, u16 typereq,
|
||||
"SetPortFeature - USB_PORT_FEAT_SUSPEND\n");
|
||||
if (windex != hsotg->otg_port)
|
||||
goto error;
|
||||
dwc2_port_suspend(hsotg, windex);
|
||||
if (hsotg->params.power_down == 2)
|
||||
dwc2_enter_hibernation(hsotg, 1);
|
||||
else
|
||||
dwc2_port_suspend(hsotg, windex);
|
||||
break;
|
||||
|
||||
case USB_PORT_FEAT_POWER:
|
||||
@ -3707,6 +3752,9 @@ static int dwc2_hcd_hub_control(struct dwc2_hsotg *hsotg, u16 typereq,
|
||||
break;
|
||||
|
||||
case USB_PORT_FEAT_RESET:
|
||||
if (hsotg->params.power_down == 2 &&
|
||||
hsotg->hibernated)
|
||||
dwc2_exit_hibernation(hsotg, 0, 1, 1);
|
||||
hprt0 = dwc2_read_hprt0(hsotg);
|
||||
dev_dbg(hsotg->dev,
|
||||
"SetPortFeature - USB_PORT_FEAT_RESET\n");
|
||||
@ -4002,7 +4050,6 @@ void dwc2_hcd_dump_state(struct dwc2_hsotg *hsotg)
|
||||
(p_tx_status & TXSTS_QSPCAVAIL_MASK) >> TXSTS_QSPCAVAIL_SHIFT);
|
||||
dev_dbg(hsotg->dev, " P Tx FIFO Space Avail: %d\n",
|
||||
(p_tx_status & TXSTS_FSPCAVAIL_MASK) >> TXSTS_FSPCAVAIL_SHIFT);
|
||||
dwc2_hcd_dump_frrem(hsotg);
|
||||
dwc2_dump_global_registers(hsotg);
|
||||
dwc2_dump_host_registers(hsotg);
|
||||
dev_dbg(hsotg->dev,
|
||||
@ -4011,75 +4058,6 @@ void dwc2_hcd_dump_state(struct dwc2_hsotg *hsotg)
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* NOTE: This function will be removed once the peripheral controller code
|
||||
* is integrated and the driver is stable
|
||||
*/
|
||||
void dwc2_hcd_dump_frrem(struct dwc2_hsotg *hsotg)
|
||||
{
|
||||
#ifdef DWC2_DUMP_FRREM
|
||||
dev_dbg(hsotg->dev, "Frame remaining at SOF:\n");
|
||||
dev_dbg(hsotg->dev, " samples %u, accum %llu, avg %llu\n",
|
||||
hsotg->frrem_samples, hsotg->frrem_accum,
|
||||
hsotg->frrem_samples > 0 ?
|
||||
hsotg->frrem_accum / hsotg->frrem_samples : 0);
|
||||
dev_dbg(hsotg->dev, "\n");
|
||||
dev_dbg(hsotg->dev, "Frame remaining at start_transfer (uframe 7):\n");
|
||||
dev_dbg(hsotg->dev, " samples %u, accum %llu, avg %llu\n",
|
||||
hsotg->hfnum_7_samples,
|
||||
hsotg->hfnum_7_frrem_accum,
|
||||
hsotg->hfnum_7_samples > 0 ?
|
||||
hsotg->hfnum_7_frrem_accum / hsotg->hfnum_7_samples : 0);
|
||||
dev_dbg(hsotg->dev, "Frame remaining at start_transfer (uframe 0):\n");
|
||||
dev_dbg(hsotg->dev, " samples %u, accum %llu, avg %llu\n",
|
||||
hsotg->hfnum_0_samples,
|
||||
hsotg->hfnum_0_frrem_accum,
|
||||
hsotg->hfnum_0_samples > 0 ?
|
||||
hsotg->hfnum_0_frrem_accum / hsotg->hfnum_0_samples : 0);
|
||||
dev_dbg(hsotg->dev, "Frame remaining at start_transfer (uframe 1-6):\n");
|
||||
dev_dbg(hsotg->dev, " samples %u, accum %llu, avg %llu\n",
|
||||
hsotg->hfnum_other_samples,
|
||||
hsotg->hfnum_other_frrem_accum,
|
||||
hsotg->hfnum_other_samples > 0 ?
|
||||
hsotg->hfnum_other_frrem_accum / hsotg->hfnum_other_samples :
|
||||
0);
|
||||
dev_dbg(hsotg->dev, "\n");
|
||||
dev_dbg(hsotg->dev, "Frame remaining at sample point A (uframe 7):\n");
|
||||
dev_dbg(hsotg->dev, " samples %u, accum %llu, avg %llu\n",
|
||||
hsotg->hfnum_7_samples_a, hsotg->hfnum_7_frrem_accum_a,
|
||||
hsotg->hfnum_7_samples_a > 0 ?
|
||||
hsotg->hfnum_7_frrem_accum_a / hsotg->hfnum_7_samples_a : 0);
|
||||
dev_dbg(hsotg->dev, "Frame remaining at sample point A (uframe 0):\n");
|
||||
dev_dbg(hsotg->dev, " samples %u, accum %llu, avg %llu\n",
|
||||
hsotg->hfnum_0_samples_a, hsotg->hfnum_0_frrem_accum_a,
|
||||
hsotg->hfnum_0_samples_a > 0 ?
|
||||
hsotg->hfnum_0_frrem_accum_a / hsotg->hfnum_0_samples_a : 0);
|
||||
dev_dbg(hsotg->dev, "Frame remaining at sample point A (uframe 1-6):\n");
|
||||
dev_dbg(hsotg->dev, " samples %u, accum %llu, avg %llu\n",
|
||||
hsotg->hfnum_other_samples_a, hsotg->hfnum_other_frrem_accum_a,
|
||||
hsotg->hfnum_other_samples_a > 0 ?
|
||||
hsotg->hfnum_other_frrem_accum_a / hsotg->hfnum_other_samples_a
|
||||
: 0);
|
||||
dev_dbg(hsotg->dev, "\n");
|
||||
dev_dbg(hsotg->dev, "Frame remaining at sample point B (uframe 7):\n");
|
||||
dev_dbg(hsotg->dev, " samples %u, accum %llu, avg %llu\n",
|
||||
hsotg->hfnum_7_samples_b, hsotg->hfnum_7_frrem_accum_b,
|
||||
hsotg->hfnum_7_samples_b > 0 ?
|
||||
hsotg->hfnum_7_frrem_accum_b / hsotg->hfnum_7_samples_b : 0);
|
||||
dev_dbg(hsotg->dev, "Frame remaining at sample point B (uframe 0):\n");
|
||||
dev_dbg(hsotg->dev, " samples %u, accum %llu, avg %llu\n",
|
||||
hsotg->hfnum_0_samples_b, hsotg->hfnum_0_frrem_accum_b,
|
||||
(hsotg->hfnum_0_samples_b > 0) ?
|
||||
hsotg->hfnum_0_frrem_accum_b / hsotg->hfnum_0_samples_b : 0);
|
||||
dev_dbg(hsotg->dev, "Frame remaining at sample point B (uframe 1-6):\n");
|
||||
dev_dbg(hsotg->dev, " samples %u, accum %llu, avg %llu\n",
|
||||
hsotg->hfnum_other_samples_b, hsotg->hfnum_other_frrem_accum_b,
|
||||
(hsotg->hfnum_other_samples_b > 0) ?
|
||||
hsotg->hfnum_other_frrem_accum_b / hsotg->hfnum_other_samples_b
|
||||
: 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
struct wrapper_priv_data {
|
||||
struct dwc2_hsotg *hsotg;
|
||||
};
|
||||
@ -4363,6 +4341,9 @@ static int _dwc2_hcd_start(struct usb_hcd *hcd)
|
||||
}
|
||||
|
||||
spin_unlock_irqrestore(&hsotg->lock, flags);
|
||||
|
||||
dwc2_vbus_supply_init(hsotg);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -4390,6 +4371,8 @@ static void _dwc2_hcd_stop(struct usb_hcd *hcd)
|
||||
clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
|
||||
spin_unlock_irqrestore(&hsotg->lock, flags);
|
||||
|
||||
dwc2_vbus_supply_exit(hsotg);
|
||||
|
||||
usleep_range(1000, 3000);
|
||||
}
|
||||
|
||||
@ -4414,7 +4397,7 @@ static int _dwc2_hcd_suspend(struct usb_hcd *hcd)
|
||||
if (hsotg->op_state == OTG_STATE_B_PERIPHERAL)
|
||||
goto unlock;
|
||||
|
||||
if (!hsotg->params.hibernation)
|
||||
if (hsotg->params.power_down != DWC2_POWER_DOWN_PARAM_PARTIAL)
|
||||
goto skip_power_saving;
|
||||
|
||||
/*
|
||||
@ -4426,14 +4409,15 @@ static int _dwc2_hcd_suspend(struct usb_hcd *hcd)
|
||||
hprt0 |= HPRT0_SUSP;
|
||||
hprt0 &= ~HPRT0_PWR;
|
||||
dwc2_writel(hprt0, hsotg->regs + HPRT0);
|
||||
dwc2_vbus_supply_exit(hsotg);
|
||||
}
|
||||
|
||||
/* Enter hibernation */
|
||||
ret = dwc2_enter_hibernation(hsotg);
|
||||
/* Enter partial_power_down */
|
||||
ret = dwc2_enter_partial_power_down(hsotg);
|
||||
if (ret) {
|
||||
if (ret != -ENOTSUPP)
|
||||
dev_err(hsotg->dev,
|
||||
"enter hibernation failed\n");
|
||||
"enter partial_power_down failed\n");
|
||||
goto skip_power_saving;
|
||||
}
|
||||
|
||||
@ -4444,7 +4428,7 @@ static int _dwc2_hcd_suspend(struct usb_hcd *hcd)
|
||||
spin_lock_irqsave(&hsotg->lock, flags);
|
||||
}
|
||||
|
||||
/* After entering hibernation, hardware is no more accessible */
|
||||
/* After entering partial_power_down, hardware is no more accessible */
|
||||
clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
|
||||
|
||||
skip_power_saving:
|
||||
@ -4469,7 +4453,7 @@ static int _dwc2_hcd_resume(struct usb_hcd *hcd)
|
||||
if (hsotg->lx_state != DWC2_L2)
|
||||
goto unlock;
|
||||
|
||||
if (!hsotg->params.hibernation) {
|
||||
if (hsotg->params.power_down != DWC2_POWER_DOWN_PARAM_PARTIAL) {
|
||||
hsotg->lx_state = DWC2_L0;
|
||||
goto unlock;
|
||||
}
|
||||
@ -4491,10 +4475,10 @@ static int _dwc2_hcd_resume(struct usb_hcd *hcd)
|
||||
spin_lock_irqsave(&hsotg->lock, flags);
|
||||
}
|
||||
|
||||
/* Exit hibernation */
|
||||
ret = dwc2_exit_hibernation(hsotg, true);
|
||||
/* Exit partial_power_down */
|
||||
ret = dwc2_exit_partial_power_down(hsotg, true);
|
||||
if (ret && (ret != -ENOTSUPP))
|
||||
dev_err(hsotg->dev, "exit hibernation failed\n");
|
||||
dev_err(hsotg->dev, "exit partial_power_down failed\n");
|
||||
|
||||
hsotg->lx_state = DWC2_L0;
|
||||
|
||||
@ -4506,6 +4490,8 @@ static int _dwc2_hcd_resume(struct usb_hcd *hcd)
|
||||
spin_unlock_irqrestore(&hsotg->lock, flags);
|
||||
dwc2_port_resume(hsotg);
|
||||
} else {
|
||||
dwc2_vbus_supply_init(hsotg);
|
||||
|
||||
/* Wait for controller to correctly update D+/D- level */
|
||||
usleep_range(3000, 5000);
|
||||
|
||||
@ -5368,6 +5354,7 @@ int dwc2_backup_host_registers(struct dwc2_hsotg *hsotg)
|
||||
|
||||
hr->hprt0 = dwc2_read_hprt0(hsotg);
|
||||
hr->hfir = dwc2_readl(hsotg->regs + HFIR);
|
||||
hr->hptxfsiz = dwc2_readl(hsotg->regs + HPTXFSIZ);
|
||||
hr->valid = true;
|
||||
|
||||
return 0;
|
||||
@ -5404,7 +5391,231 @@ int dwc2_restore_host_registers(struct dwc2_hsotg *hsotg)
|
||||
|
||||
dwc2_writel(hr->hprt0, hsotg->regs + HPRT0);
|
||||
dwc2_writel(hr->hfir, hsotg->regs + HFIR);
|
||||
dwc2_writel(hr->hptxfsiz, hsotg->regs + HPTXFSIZ);
|
||||
hsotg->frame_number = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* dwc2_host_enter_hibernation() - Put controller in Hibernation.
|
||||
*
|
||||
* @hsotg: Programming view of the DWC_otg controller
|
||||
*/
|
||||
int dwc2_host_enter_hibernation(struct dwc2_hsotg *hsotg)
|
||||
{
|
||||
unsigned long flags;
|
||||
int ret = 0;
|
||||
u32 hprt0;
|
||||
u32 pcgcctl;
|
||||
u32 gusbcfg;
|
||||
u32 gpwrdn;
|
||||
|
||||
dev_dbg(hsotg->dev, "Preparing host for hibernation\n");
|
||||
ret = dwc2_backup_global_registers(hsotg);
|
||||
if (ret) {
|
||||
dev_err(hsotg->dev, "%s: failed to backup global registers\n",
|
||||
__func__);
|
||||
return ret;
|
||||
}
|
||||
ret = dwc2_backup_host_registers(hsotg);
|
||||
if (ret) {
|
||||
dev_err(hsotg->dev, "%s: failed to backup host registers\n",
|
||||
__func__);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Enter USB Suspend Mode */
|
||||
hprt0 = dwc2_readl(hsotg->regs + HPRT0);
|
||||
hprt0 |= HPRT0_SUSP;
|
||||
hprt0 &= ~HPRT0_ENA;
|
||||
dwc2_writel(hprt0, hsotg->regs + HPRT0);
|
||||
|
||||
/* Wait for the HPRT0.PrtSusp register field to be set */
|
||||
if (dwc2_hsotg_wait_bit_set(hsotg, HPRT0, HPRT0_SUSP, 300))
|
||||
dev_warn(hsotg->dev, "Suspend wasn't generated\n");
|
||||
|
||||
/*
|
||||
* We need to disable interrupts to prevent servicing of any IRQ
|
||||
* during going to hibernation
|
||||
*/
|
||||
spin_lock_irqsave(&hsotg->lock, flags);
|
||||
hsotg->lx_state = DWC2_L2;
|
||||
|
||||
gusbcfg = dwc2_readl(hsotg->regs + GUSBCFG);
|
||||
if (gusbcfg & GUSBCFG_ULPI_UTMI_SEL) {
|
||||
/* ULPI interface */
|
||||
/* Suspend the Phy Clock */
|
||||
pcgcctl = dwc2_readl(hsotg->regs + PCGCTL);
|
||||
pcgcctl |= PCGCTL_STOPPCLK;
|
||||
dwc2_writel(pcgcctl, hsotg->regs + PCGCTL);
|
||||
udelay(10);
|
||||
|
||||
gpwrdn = dwc2_readl(hsotg->regs + GPWRDN);
|
||||
gpwrdn |= GPWRDN_PMUACTV;
|
||||
dwc2_writel(gpwrdn, hsotg->regs + GPWRDN);
|
||||
udelay(10);
|
||||
} else {
|
||||
/* UTMI+ Interface */
|
||||
gpwrdn = dwc2_readl(hsotg->regs + GPWRDN);
|
||||
gpwrdn |= GPWRDN_PMUACTV;
|
||||
dwc2_writel(gpwrdn, hsotg->regs + GPWRDN);
|
||||
udelay(10);
|
||||
|
||||
pcgcctl = dwc2_readl(hsotg->regs + PCGCTL);
|
||||
pcgcctl |= PCGCTL_STOPPCLK;
|
||||
dwc2_writel(pcgcctl, hsotg->regs + PCGCTL);
|
||||
udelay(10);
|
||||
}
|
||||
|
||||
/* Enable interrupts from wake up logic */
|
||||
gpwrdn = dwc2_readl(hsotg->regs + GPWRDN);
|
||||
gpwrdn |= GPWRDN_PMUINTSEL;
|
||||
dwc2_writel(gpwrdn, hsotg->regs + GPWRDN);
|
||||
udelay(10);
|
||||
|
||||
/* Unmask host mode interrupts in GPWRDN */
|
||||
gpwrdn = dwc2_readl(hsotg->regs + GPWRDN);
|
||||
gpwrdn |= GPWRDN_DISCONN_DET_MSK;
|
||||
gpwrdn |= GPWRDN_LNSTSCHG_MSK;
|
||||
gpwrdn |= GPWRDN_STS_CHGINT_MSK;
|
||||
dwc2_writel(gpwrdn, hsotg->regs + GPWRDN);
|
||||
udelay(10);
|
||||
|
||||
/* Enable Power Down Clamp */
|
||||
gpwrdn = dwc2_readl(hsotg->regs + GPWRDN);
|
||||
gpwrdn |= GPWRDN_PWRDNCLMP;
|
||||
dwc2_writel(gpwrdn, hsotg->regs + GPWRDN);
|
||||
udelay(10);
|
||||
|
||||
/* Switch off VDD */
|
||||
gpwrdn = dwc2_readl(hsotg->regs + GPWRDN);
|
||||
gpwrdn |= GPWRDN_PWRDNSWTCH;
|
||||
dwc2_writel(gpwrdn, hsotg->regs + GPWRDN);
|
||||
|
||||
hsotg->hibernated = 1;
|
||||
hsotg->bus_suspended = 1;
|
||||
dev_dbg(hsotg->dev, "Host hibernation completed\n");
|
||||
spin_unlock_irqrestore(&hsotg->lock, flags);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* dwc2_host_exit_hibernation()
|
||||
*
|
||||
* @hsotg: Programming view of the DWC_otg controller
|
||||
* @rem_wakeup: indicates whether resume is initiated by Device or Host.
|
||||
* @param reset: indicates whether resume is initiated by Reset.
|
||||
*
|
||||
* Return: non-zero if failed to enter to hibernation.
|
||||
*
|
||||
* This function is for exiting from Host mode hibernation by
|
||||
* Host Initiated Resume/Reset and Device Initiated Remote-Wakeup.
|
||||
*/
|
||||
int dwc2_host_exit_hibernation(struct dwc2_hsotg *hsotg, int rem_wakeup,
|
||||
int reset)
|
||||
{
|
||||
u32 gpwrdn;
|
||||
u32 hprt0;
|
||||
int ret = 0;
|
||||
struct dwc2_gregs_backup *gr;
|
||||
struct dwc2_hregs_backup *hr;
|
||||
|
||||
gr = &hsotg->gr_backup;
|
||||
hr = &hsotg->hr_backup;
|
||||
|
||||
dev_dbg(hsotg->dev,
|
||||
"%s: called with rem_wakeup = %d reset = %d\n",
|
||||
__func__, rem_wakeup, reset);
|
||||
|
||||
dwc2_hib_restore_common(hsotg, rem_wakeup, 1);
|
||||
hsotg->hibernated = 0;
|
||||
|
||||
/*
|
||||
* This step is not described in functional spec but if not wait for
|
||||
* this delay, mismatch interrupts occurred because just after restore
|
||||
* core is in Device mode(gintsts.curmode == 0)
|
||||
*/
|
||||
mdelay(100);
|
||||
|
||||
/* Clear all pending interupts */
|
||||
dwc2_writel(0xffffffff, hsotg->regs + GINTSTS);
|
||||
|
||||
/* De-assert Restore */
|
||||
gpwrdn = dwc2_readl(hsotg->regs + GPWRDN);
|
||||
gpwrdn &= ~GPWRDN_RESTORE;
|
||||
dwc2_writel(gpwrdn, hsotg->regs + GPWRDN);
|
||||
udelay(10);
|
||||
|
||||
/* Restore GUSBCFG, HCFG */
|
||||
dwc2_writel(gr->gusbcfg, hsotg->regs + GUSBCFG);
|
||||
dwc2_writel(hr->hcfg, hsotg->regs + HCFG);
|
||||
|
||||
/* De-assert Wakeup Logic */
|
||||
gpwrdn = dwc2_readl(hsotg->regs + GPWRDN);
|
||||
gpwrdn &= ~GPWRDN_PMUACTV;
|
||||
dwc2_writel(gpwrdn, hsotg->regs + GPWRDN);
|
||||
udelay(10);
|
||||
|
||||
hprt0 = hr->hprt0;
|
||||
hprt0 |= HPRT0_PWR;
|
||||
hprt0 &= ~HPRT0_ENA;
|
||||
hprt0 &= ~HPRT0_SUSP;
|
||||
dwc2_writel(hprt0, hsotg->regs + HPRT0);
|
||||
|
||||
hprt0 = hr->hprt0;
|
||||
hprt0 |= HPRT0_PWR;
|
||||
hprt0 &= ~HPRT0_ENA;
|
||||
hprt0 &= ~HPRT0_SUSP;
|
||||
|
||||
if (reset) {
|
||||
hprt0 |= HPRT0_RST;
|
||||
dwc2_writel(hprt0, hsotg->regs + HPRT0);
|
||||
|
||||
/* Wait for Resume time and then program HPRT again */
|
||||
mdelay(60);
|
||||
hprt0 &= ~HPRT0_RST;
|
||||
dwc2_writel(hprt0, hsotg->regs + HPRT0);
|
||||
} else {
|
||||
hprt0 |= HPRT0_RES;
|
||||
dwc2_writel(hprt0, hsotg->regs + HPRT0);
|
||||
|
||||
/* Wait for Resume time and then program HPRT again */
|
||||
mdelay(100);
|
||||
hprt0 &= ~HPRT0_RES;
|
||||
dwc2_writel(hprt0, hsotg->regs + HPRT0);
|
||||
}
|
||||
/* Clear all interrupt status */
|
||||
hprt0 = dwc2_readl(hsotg->regs + HPRT0);
|
||||
hprt0 |= HPRT0_CONNDET;
|
||||
hprt0 |= HPRT0_ENACHG;
|
||||
hprt0 &= ~HPRT0_ENA;
|
||||
dwc2_writel(hprt0, hsotg->regs + HPRT0);
|
||||
|
||||
hprt0 = dwc2_readl(hsotg->regs + HPRT0);
|
||||
|
||||
/* Clear all pending interupts */
|
||||
dwc2_writel(0xffffffff, hsotg->regs + GINTSTS);
|
||||
|
||||
/* Restore global registers */
|
||||
ret = dwc2_restore_global_registers(hsotg);
|
||||
if (ret) {
|
||||
dev_err(hsotg->dev, "%s: failed to restore registers\n",
|
||||
__func__);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Restore host registers */
|
||||
ret = dwc2_restore_host_registers(hsotg);
|
||||
if (ret) {
|
||||
dev_err(hsotg->dev, "%s: failed to restore host registers\n",
|
||||
__func__);
|
||||
return ret;
|
||||
}
|
||||
|
||||
hsotg->hibernated = 0;
|
||||
hsotg->bus_suspended = 0;
|
||||
hsotg->lx_state = DWC2_L0;
|
||||
dev_dbg(hsotg->dev, "Host hibernation restore complete\n");
|
||||
return ret;
|
||||
}
|
||||
|
@ -783,19 +783,6 @@ int dwc2_hcd_is_b_host(struct dwc2_hsotg *hsotg);
|
||||
*/
|
||||
void dwc2_hcd_dump_state(struct dwc2_hsotg *hsotg);
|
||||
|
||||
/**
|
||||
* dwc2_hcd_dump_frrem() - Dumps the average frame remaining at SOF
|
||||
*
|
||||
* @hsotg: The DWC2 HCD
|
||||
*
|
||||
* This can be used to determine average interrupt latency. Frame remaining is
|
||||
* also shown for start transfer and two additional sample points.
|
||||
*
|
||||
* NOTE: This function will be removed once the peripheral controller code
|
||||
* is integrated and the driver is stable
|
||||
*/
|
||||
void dwc2_hcd_dump_frrem(struct dwc2_hsotg *hsotg);
|
||||
|
||||
/* URB interface */
|
||||
|
||||
/* Transfer flags */
|
||||
@ -813,47 +800,4 @@ int dwc2_host_get_speed(struct dwc2_hsotg *hsotg, void *context);
|
||||
void dwc2_host_complete(struct dwc2_hsotg *hsotg, struct dwc2_qtd *qtd,
|
||||
int status);
|
||||
|
||||
#ifdef DEBUG
|
||||
/*
|
||||
* Macro to sample the remaining PHY clocks left in the current frame. This
|
||||
* may be used during debugging to determine the average time it takes to
|
||||
* execute sections of code. There are two possible sample points, "a" and
|
||||
* "b", so the _letter_ argument must be one of these values.
|
||||
*
|
||||
* To dump the average sample times, read the "hcd_frrem" sysfs attribute. For
|
||||
* example, "cat /sys/devices/lm0/hcd_frrem".
|
||||
*/
|
||||
#define dwc2_sample_frrem(_hcd_, _qh_, _letter_) \
|
||||
do { \
|
||||
struct hfnum_data _hfnum_; \
|
||||
struct dwc2_qtd *_qtd_; \
|
||||
\
|
||||
_qtd_ = list_entry((_qh_)->qtd_list.next, struct dwc2_qtd, \
|
||||
qtd_list_entry); \
|
||||
if (usb_pipeint(_qtd_->urb->pipe) && \
|
||||
(_qh_)->start_active_frame != 0 && !_qtd_->complete_split) { \
|
||||
_hfnum_.d32 = dwc2_readl((_hcd_)->regs + HFNUM); \
|
||||
switch (_hfnum_.b.frnum & 0x7) { \
|
||||
case 7: \
|
||||
(_hcd_)->hfnum_7_samples_##_letter_++; \
|
||||
(_hcd_)->hfnum_7_frrem_accum_##_letter_ += \
|
||||
_hfnum_.b.frrem; \
|
||||
break; \
|
||||
case 0: \
|
||||
(_hcd_)->hfnum_0_samples_##_letter_++; \
|
||||
(_hcd_)->hfnum_0_frrem_accum_##_letter_ += \
|
||||
_hfnum_.b.frrem; \
|
||||
break; \
|
||||
default: \
|
||||
(_hcd_)->hfnum_other_samples_##_letter_++; \
|
||||
(_hcd_)->hfnum_other_frrem_accum_##_letter_ += \
|
||||
_hfnum_.b.frrem; \
|
||||
break; \
|
||||
} \
|
||||
} \
|
||||
} while (0)
|
||||
#else
|
||||
#define dwc2_sample_frrem(_hcd_, _qh_, _letter_) do {} while (0)
|
||||
#endif
|
||||
|
||||
#endif /* __DWC2_HCD_H__ */
|
||||
|
@ -231,6 +231,7 @@
|
||||
#define GUID HSOTG_REG(0x003c)
|
||||
#define GSNPSID HSOTG_REG(0x0040)
|
||||
#define GHWCFG1 HSOTG_REG(0x0044)
|
||||
#define GSNPSID_ID_MASK GENMASK(31, 16)
|
||||
|
||||
#define GHWCFG2 HSOTG_REG(0x0048)
|
||||
#define GHWCFG2_OTG_ENABLE_IC_USB BIT(31)
|
||||
@ -309,6 +310,7 @@
|
||||
#define GHWCFG4_NUM_DEV_MODE_CTRL_EP_SHIFT 16
|
||||
#define GHWCFG4_UTMI_PHY_DATA_WIDTH_MASK (0x3 << 14)
|
||||
#define GHWCFG4_UTMI_PHY_DATA_WIDTH_SHIFT 14
|
||||
#define GHWCFG4_ACG_SUPPORTED BIT(12)
|
||||
#define GHWCFG4_UTMI_PHY_DATA_WIDTH_8 0
|
||||
#define GHWCFG4_UTMI_PHY_DATA_WIDTH_16 1
|
||||
#define GHWCFG4_UTMI_PHY_DATA_WIDTH_8_OR_16 2
|
||||
@ -320,28 +322,30 @@
|
||||
#define GHWCFG4_NUM_DEV_PERIO_IN_EP_SHIFT 0
|
||||
|
||||
#define GLPMCFG HSOTG_REG(0x0054)
|
||||
#define GLPMCFG_INV_SEL_HSIC BIT(31)
|
||||
#define GLPMCFG_HSIC_CONNECT BIT(30)
|
||||
#define GLPMCFG_RETRY_COUNT_STS_MASK (0x7 << 25)
|
||||
#define GLPMCFG_RETRY_COUNT_STS_SHIFT 25
|
||||
#define GLPMCFG_SEND_LPM BIT(24)
|
||||
#define GLPMCFG_RETRY_COUNT_MASK (0x7 << 21)
|
||||
#define GLPMCFG_RETRY_COUNT_SHIFT 21
|
||||
#define GLPMCFG_LPM_CHAN_INDEX_MASK (0xf << 17)
|
||||
#define GLPMCFG_LPM_CHAN_INDEX_SHIFT 17
|
||||
#define GLPMCFG_SLEEP_STATE_RESUMEOK BIT(16)
|
||||
#define GLPMCFG_PRT_SLEEP_STS BIT(15)
|
||||
#define GLPMCFG_LPM_RESP_MASK (0x3 << 13)
|
||||
#define GLPMCFG_LPM_RESP_SHIFT 13
|
||||
#define GLPMCFG_INVSELHSIC BIT(31)
|
||||
#define GLPMCFG_HSICCON BIT(30)
|
||||
#define GLPMCFG_RSTRSLPSTS BIT(29)
|
||||
#define GLPMCFG_ENBESL BIT(28)
|
||||
#define GLPMCFG_LPM_RETRYCNT_STS_MASK (0x7 << 25)
|
||||
#define GLPMCFG_LPM_RETRYCNT_STS_SHIFT 25
|
||||
#define GLPMCFG_SNDLPM BIT(24)
|
||||
#define GLPMCFG_RETRY_CNT_MASK (0x7 << 21)
|
||||
#define GLPMCFG_RETRY_CNT_SHIFT 21
|
||||
#define GLPMCFG_LPM_CHNL_INDX_MASK (0xf << 17)
|
||||
#define GLPMCFG_LPM_CHNL_INDX_SHIFT 17
|
||||
#define GLPMCFG_L1RESUMEOK BIT(16)
|
||||
#define GLPMCFG_SLPSTS BIT(15)
|
||||
#define GLPMCFG_COREL1RES_MASK (0x3 << 13)
|
||||
#define GLPMCFG_COREL1RES_SHIFT 13
|
||||
#define GLPMCFG_HIRD_THRES_MASK (0x1f << 8)
|
||||
#define GLPMCFG_HIRD_THRES_SHIFT 8
|
||||
#define GLPMCFG_HIRD_THRES_EN (0x10 << 8)
|
||||
#define GLPMCFG_EN_UTMI_SLEEP BIT(7)
|
||||
#define GLPMCFG_REM_WKUP_EN BIT(6)
|
||||
#define GLPMCFG_HIRD_THRES_EN (0x10 << 8)
|
||||
#define GLPMCFG_ENBLSLPM BIT(7)
|
||||
#define GLPMCFG_BREMOTEWAKE BIT(6)
|
||||
#define GLPMCFG_HIRD_MASK (0xf << 2)
|
||||
#define GLPMCFG_HIRD_SHIFT 2
|
||||
#define GLPMCFG_APPL_RESP BIT(1)
|
||||
#define GLPMCFG_LPM_CAP_EN BIT(0)
|
||||
#define GLPMCFG_APPL1RES BIT(1)
|
||||
#define GLPMCFG_LPMCAP BIT(0)
|
||||
|
||||
#define GPWRDN HSOTG_REG(0x0058)
|
||||
#define GPWRDN_MULT_VAL_ID_BC_MASK (0x1f << 24)
|
||||
@ -644,6 +648,10 @@
|
||||
#define PCGCTL_GATEHCLK BIT(1)
|
||||
#define PCGCTL_STOPPCLK BIT(0)
|
||||
|
||||
#define PCGCCTL1 HSOTG_REG(0xe04)
|
||||
#define PCGCCTL1_TIMER (0x3 << 1)
|
||||
#define PCGCCTL1_GATEEN BIT(0)
|
||||
|
||||
#define EPFIFO(_a) HSOTG_REG(0x1000 + ((_a) * 0x1000))
|
||||
|
||||
/* Host Mode Registers */
|
||||
|
@ -252,6 +252,20 @@ static void dwc2_set_param_tx_fifo_sizes(struct dwc2_hsotg *hsotg)
|
||||
p->g_tx_fifo_size[i] = depth_average;
|
||||
}
|
||||
|
||||
static void dwc2_set_param_power_down(struct dwc2_hsotg *hsotg)
|
||||
{
|
||||
int val;
|
||||
|
||||
if (hsotg->hw_params.hibernation)
|
||||
val = 2;
|
||||
else if (hsotg->hw_params.power_optimized)
|
||||
val = 1;
|
||||
else
|
||||
val = 0;
|
||||
|
||||
hsotg->params.power_down = val;
|
||||
}
|
||||
|
||||
/**
|
||||
* dwc2_set_default_params() - Set all core parameters to their
|
||||
* auto-detected default values.
|
||||
@ -266,21 +280,27 @@ static void dwc2_set_default_params(struct dwc2_hsotg *hsotg)
|
||||
dwc2_set_param_phy_type(hsotg);
|
||||
dwc2_set_param_speed(hsotg);
|
||||
dwc2_set_param_phy_utmi_width(hsotg);
|
||||
dwc2_set_param_power_down(hsotg);
|
||||
p->phy_ulpi_ddr = false;
|
||||
p->phy_ulpi_ext_vbus = false;
|
||||
|
||||
p->enable_dynamic_fifo = hw->enable_dynamic_fifo;
|
||||
p->en_multiple_tx_fifo = hw->en_multiple_tx_fifo;
|
||||
p->i2c_enable = hw->i2c_enable;
|
||||
p->acg_enable = hw->acg_enable;
|
||||
p->ulpi_fs_ls = false;
|
||||
p->ts_dline = false;
|
||||
p->reload_ctl = (hw->snpsid >= DWC2_CORE_REV_2_92a);
|
||||
p->uframe_sched = true;
|
||||
p->external_id_pin_ctl = false;
|
||||
p->hibernation = false;
|
||||
p->lpm = true;
|
||||
p->lpm_clock_gating = true;
|
||||
p->besl = true;
|
||||
p->hird_threshold_en = true;
|
||||
p->hird_threshold = 4;
|
||||
p->max_packet_count = hw->max_packet_count;
|
||||
p->max_transfer_size = hw->max_transfer_size;
|
||||
p->ahbcfg = GAHBCFG_HBSTLEN_INCR4 << GAHBCFG_HBSTLEN_SHIFT;
|
||||
p->ahbcfg = GAHBCFG_HBSTLEN_INCR << GAHBCFG_HBSTLEN_SHIFT;
|
||||
|
||||
if ((hsotg->dr_mode == USB_DR_MODE_HOST) ||
|
||||
(hsotg->dr_mode == USB_DR_MODE_OTG)) {
|
||||
@ -463,6 +483,38 @@ static void dwc2_check_param_phy_utmi_width(struct dwc2_hsotg *hsotg)
|
||||
dwc2_set_param_phy_utmi_width(hsotg);
|
||||
}
|
||||
|
||||
static void dwc2_check_param_power_down(struct dwc2_hsotg *hsotg)
|
||||
{
|
||||
int param = hsotg->params.power_down;
|
||||
|
||||
switch (param) {
|
||||
case DWC2_POWER_DOWN_PARAM_NONE:
|
||||
break;
|
||||
case DWC2_POWER_DOWN_PARAM_PARTIAL:
|
||||
if (hsotg->hw_params.power_optimized)
|
||||
break;
|
||||
dev_dbg(hsotg->dev,
|
||||
"Partial power down isn't supported by HW\n");
|
||||
param = DWC2_POWER_DOWN_PARAM_NONE;
|
||||
break;
|
||||
case DWC2_POWER_DOWN_PARAM_HIBERNATION:
|
||||
if (hsotg->hw_params.hibernation)
|
||||
break;
|
||||
dev_dbg(hsotg->dev,
|
||||
"Hibernation isn't supported by HW\n");
|
||||
param = DWC2_POWER_DOWN_PARAM_NONE;
|
||||
break;
|
||||
default:
|
||||
dev_err(hsotg->dev,
|
||||
"%s: Invalid parameter power_down=%d\n",
|
||||
__func__, param);
|
||||
param = DWC2_POWER_DOWN_PARAM_NONE;
|
||||
break;
|
||||
}
|
||||
|
||||
hsotg->params.power_down = param;
|
||||
}
|
||||
|
||||
static void dwc2_check_param_tx_fifo_sizes(struct dwc2_hsotg *hsotg)
|
||||
{
|
||||
int fifo_count;
|
||||
@ -523,10 +575,19 @@ static void dwc2_check_params(struct dwc2_hsotg *hsotg)
|
||||
dwc2_check_param_phy_type(hsotg);
|
||||
dwc2_check_param_speed(hsotg);
|
||||
dwc2_check_param_phy_utmi_width(hsotg);
|
||||
dwc2_check_param_power_down(hsotg);
|
||||
CHECK_BOOL(enable_dynamic_fifo, hw->enable_dynamic_fifo);
|
||||
CHECK_BOOL(en_multiple_tx_fifo, hw->en_multiple_tx_fifo);
|
||||
CHECK_BOOL(i2c_enable, hw->i2c_enable);
|
||||
CHECK_BOOL(acg_enable, hw->acg_enable);
|
||||
CHECK_BOOL(reload_ctl, (hsotg->hw_params.snpsid > DWC2_CORE_REV_2_92a));
|
||||
CHECK_BOOL(lpm, (hsotg->hw_params.snpsid >= DWC2_CORE_REV_2_80a));
|
||||
CHECK_BOOL(lpm, hw->lpm_mode);
|
||||
CHECK_BOOL(lpm_clock_gating, hsotg->params.lpm);
|
||||
CHECK_BOOL(besl, hsotg->params.lpm);
|
||||
CHECK_BOOL(besl, (hsotg->hw_params.snpsid >= DWC2_CORE_REV_3_00a));
|
||||
CHECK_BOOL(hird_threshold_en, hsotg->params.lpm);
|
||||
CHECK_RANGE(hird_threshold, 0, hsotg->params.besl ? 12 : 7, 0);
|
||||
CHECK_RANGE(max_packet_count,
|
||||
15, hw->max_packet_count,
|
||||
hw->max_packet_count);
|
||||
@ -579,19 +640,15 @@ static void dwc2_get_host_hwparams(struct dwc2_hsotg *hsotg)
|
||||
struct dwc2_hw_params *hw = &hsotg->hw_params;
|
||||
u32 gnptxfsiz;
|
||||
u32 hptxfsiz;
|
||||
bool forced;
|
||||
|
||||
if (hsotg->dr_mode == USB_DR_MODE_PERIPHERAL)
|
||||
return;
|
||||
|
||||
forced = dwc2_force_mode_if_needed(hsotg, true);
|
||||
dwc2_force_mode(hsotg, true);
|
||||
|
||||
gnptxfsiz = dwc2_readl(hsotg->regs + GNPTXFSIZ);
|
||||
hptxfsiz = dwc2_readl(hsotg->regs + HPTXFSIZ);
|
||||
|
||||
if (forced)
|
||||
dwc2_clear_force_mode(hsotg);
|
||||
|
||||
hw->host_nperio_tx_fifo_size = (gnptxfsiz & FIFOSIZE_DEPTH_MASK) >>
|
||||
FIFOSIZE_DEPTH_SHIFT;
|
||||
hw->host_perio_tx_fifo_size = (hptxfsiz & FIFOSIZE_DEPTH_MASK) >>
|
||||
@ -606,14 +663,13 @@ static void dwc2_get_host_hwparams(struct dwc2_hsotg *hsotg)
|
||||
static void dwc2_get_dev_hwparams(struct dwc2_hsotg *hsotg)
|
||||
{
|
||||
struct dwc2_hw_params *hw = &hsotg->hw_params;
|
||||
bool forced;
|
||||
u32 gnptxfsiz;
|
||||
int fifo, fifo_count;
|
||||
|
||||
if (hsotg->dr_mode == USB_DR_MODE_HOST)
|
||||
return;
|
||||
|
||||
forced = dwc2_force_mode_if_needed(hsotg, false);
|
||||
dwc2_force_mode(hsotg, false);
|
||||
|
||||
gnptxfsiz = dwc2_readl(hsotg->regs + GNPTXFSIZ);
|
||||
|
||||
@ -625,9 +681,6 @@ static void dwc2_get_dev_hwparams(struct dwc2_hsotg *hsotg)
|
||||
FIFOSIZE_DEPTH_MASK) >> FIFOSIZE_DEPTH_SHIFT;
|
||||
}
|
||||
|
||||
if (forced)
|
||||
dwc2_clear_force_mode(hsotg);
|
||||
|
||||
hw->dev_nperio_tx_fifo_size = (gnptxfsiz & FIFOSIZE_DEPTH_MASK) >>
|
||||
FIFOSIZE_DEPTH_SHIFT;
|
||||
}
|
||||
@ -646,14 +699,13 @@ int dwc2_get_hwparams(struct dwc2_hsotg *hsotg)
|
||||
/*
|
||||
* Attempt to ensure this device is really a DWC_otg Controller.
|
||||
* Read and verify the GSNPSID register contents. The value should be
|
||||
* 0x45f42xxx or 0x45f43xxx, which corresponds to either "OT2" or "OT3",
|
||||
* as in "OTG version 2.xx" or "OTG version 3.xx".
|
||||
* 0x45f4xxxx, 0x5531xxxx or 0x5532xxxx
|
||||
*/
|
||||
|
||||
hw->snpsid = dwc2_readl(hsotg->regs + GSNPSID);
|
||||
if ((hw->snpsid & 0xfffff000) != 0x4f542000 &&
|
||||
(hw->snpsid & 0xfffff000) != 0x4f543000 &&
|
||||
(hw->snpsid & 0xffff0000) != 0x55310000 &&
|
||||
(hw->snpsid & 0xffff0000) != 0x55320000) {
|
||||
if ((hw->snpsid & GSNPSID_ID_MASK) != DWC2_OTG_ID &&
|
||||
(hw->snpsid & GSNPSID_ID_MASK) != DWC2_FS_IOT_ID &&
|
||||
(hw->snpsid & GSNPSID_ID_MASK) != DWC2_HS_IOT_ID) {
|
||||
dev_err(hsotg->dev, "Bad value for GSNPSID: 0x%08x\n",
|
||||
hw->snpsid);
|
||||
return -ENODEV;
|
||||
@ -706,6 +758,7 @@ int dwc2_get_hwparams(struct dwc2_hsotg *hsotg)
|
||||
hw->i2c_enable = !!(hwcfg3 & GHWCFG3_I2C);
|
||||
hw->total_fifo_size = (hwcfg3 & GHWCFG3_DFIFO_DEPTH_MASK) >>
|
||||
GHWCFG3_DFIFO_DEPTH_SHIFT;
|
||||
hw->lpm_mode = !!(hwcfg3 & GHWCFG3_OTG_LPM_EN);
|
||||
|
||||
/* hwcfg4 */
|
||||
hw->en_multiple_tx_fifo = !!(hwcfg4 & GHWCFG4_DED_FIFO_EN);
|
||||
@ -715,8 +768,10 @@ int dwc2_get_hwparams(struct dwc2_hsotg *hsotg)
|
||||
GHWCFG4_NUM_IN_EPS_SHIFT;
|
||||
hw->dma_desc_enable = !!(hwcfg4 & GHWCFG4_DESC_DMA);
|
||||
hw->power_optimized = !!(hwcfg4 & GHWCFG4_POWER_OPTIMIZ);
|
||||
hw->hibernation = !!(hwcfg4 & GHWCFG4_HIBER);
|
||||
hw->utmi_phy_data_width = (hwcfg4 & GHWCFG4_UTMI_PHY_DATA_WIDTH_MASK) >>
|
||||
GHWCFG4_UTMI_PHY_DATA_WIDTH_SHIFT;
|
||||
hw->acg_enable = !!(hwcfg4 & GHWCFG4_ACG_SUPPORTED);
|
||||
|
||||
/* fifo sizes */
|
||||
hw->rx_fifo_size = (grxfsiz & GRXFSIZ_DEPTH_MASK) >>
|
||||
|
@ -83,7 +83,6 @@ static void dwc2_pci_remove(struct pci_dev *pci)
|
||||
|
||||
platform_device_unregister(glue->dwc2);
|
||||
usb_phy_generic_unregister(glue->phy);
|
||||
kfree(glue);
|
||||
pci_set_drvdata(pci, NULL);
|
||||
}
|
||||
|
||||
@ -105,10 +104,17 @@ static int dwc2_pci_probe(struct pci_dev *pci,
|
||||
|
||||
pci_set_master(pci);
|
||||
|
||||
phy = usb_phy_generic_register();
|
||||
if (IS_ERR(phy)) {
|
||||
dev_err(dev, "error registering generic PHY (%ld)\n",
|
||||
PTR_ERR(phy));
|
||||
return PTR_ERR(phy);
|
||||
}
|
||||
|
||||
dwc2 = platform_device_alloc("dwc2", PLATFORM_DEVID_AUTO);
|
||||
if (!dwc2) {
|
||||
dev_err(dev, "couldn't allocate dwc2 device\n");
|
||||
return -ENOMEM;
|
||||
goto err;
|
||||
}
|
||||
|
||||
memset(res, 0x00, sizeof(struct resource) * ARRAY_SIZE(res));
|
||||
@ -125,32 +131,25 @@ static int dwc2_pci_probe(struct pci_dev *pci,
|
||||
ret = platform_device_add_resources(dwc2, res, ARRAY_SIZE(res));
|
||||
if (ret) {
|
||||
dev_err(dev, "couldn't add resources to dwc2 device\n");
|
||||
return ret;
|
||||
goto err;
|
||||
}
|
||||
|
||||
dwc2->dev.parent = dev;
|
||||
|
||||
phy = usb_phy_generic_register();
|
||||
if (IS_ERR(phy)) {
|
||||
dev_err(dev, "error registering generic PHY (%ld)\n",
|
||||
PTR_ERR(phy));
|
||||
return PTR_ERR(phy);
|
||||
}
|
||||
|
||||
ret = dwc2_pci_quirks(pci, dwc2);
|
||||
if (ret)
|
||||
goto err;
|
||||
|
||||
glue = devm_kzalloc(dev, sizeof(*glue), GFP_KERNEL);
|
||||
if (!glue)
|
||||
goto err;
|
||||
|
||||
ret = platform_device_add(dwc2);
|
||||
if (ret) {
|
||||
dev_err(dev, "failed to register dwc2 device\n");
|
||||
goto err;
|
||||
}
|
||||
|
||||
glue = kzalloc(sizeof(*glue), GFP_KERNEL);
|
||||
if (!glue)
|
||||
return -ENOMEM;
|
||||
|
||||
glue->phy = phy;
|
||||
glue->dwc2 = dwc2;
|
||||
pci_set_drvdata(pci, glue);
|
||||
|
@ -382,8 +382,10 @@ static int dwc2_driver_probe(struct platform_device *dev)
|
||||
if (!dev->dev.dma_mask)
|
||||
dev->dev.dma_mask = &dev->dev.coherent_dma_mask;
|
||||
retval = dma_set_coherent_mask(&dev->dev, DMA_BIT_MASK(32));
|
||||
if (retval)
|
||||
if (retval) {
|
||||
dev_err(&dev->dev, "can't set coherent DMA mask: %d\n", retval);
|
||||
return retval;
|
||||
}
|
||||
|
||||
res = platform_get_resource(dev, IORESOURCE_MEM, 0);
|
||||
hsotg->regs = devm_ioremap_resource(&dev->dev, res);
|
||||
@ -425,13 +427,20 @@ static int dwc2_driver_probe(struct platform_device *dev)
|
||||
* Reset before dwc2_get_hwparams() then it could get power-on real
|
||||
* reset value form registers.
|
||||
*/
|
||||
dwc2_core_reset_and_force_dr_mode(hsotg);
|
||||
retval = dwc2_core_reset(hsotg, false);
|
||||
if (retval)
|
||||
goto error;
|
||||
|
||||
/* Detect config values from hardware */
|
||||
retval = dwc2_get_hwparams(hsotg);
|
||||
if (retval)
|
||||
goto error;
|
||||
|
||||
/*
|
||||
* For OTG cores, set the force mode bits to reflect the value
|
||||
* of dr_mode. Force mode bits should not be touched at any
|
||||
* other time after this.
|
||||
*/
|
||||
dwc2_force_dr_mode(hsotg);
|
||||
|
||||
retval = dwc2_init_params(hsotg);
|
||||
@ -439,7 +448,7 @@ static int dwc2_driver_probe(struct platform_device *dev)
|
||||
goto error;
|
||||
|
||||
if (hsotg->dr_mode != USB_DR_MODE_HOST) {
|
||||
retval = dwc2_gadget_init(hsotg, hsotg->irq);
|
||||
retval = dwc2_gadget_init(hsotg);
|
||||
if (retval)
|
||||
goto error;
|
||||
hsotg->gadget_enabled = 1;
|
||||
@ -456,6 +465,7 @@ static int dwc2_driver_probe(struct platform_device *dev)
|
||||
}
|
||||
|
||||
platform_set_drvdata(dev, hsotg);
|
||||
hsotg->hibernated = 0;
|
||||
|
||||
dwc2_debugfs_init(hsotg);
|
||||
|
||||
|
@ -6,7 +6,7 @@ obj-$(CONFIG_USB_DWC3) += dwc3.o
|
||||
|
||||
dwc3-y := core.o
|
||||
|
||||
ifneq ($(CONFIG_FTRACE),)
|
||||
ifneq ($(CONFIG_TRACING),)
|
||||
dwc3-y += trace.o
|
||||
endif
|
||||
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user