USB/PHY patches for 4.18-rc1
Here is the big USB pull request for 4.18-rc1. Lots of stuff here, the highlights are: - phy driver updates and new additions - usual set of xhci driver updates - normal set of musb updates - gadget driver updates and new controllers - typec work, it's getting closer to getting fully out of the staging portion of the tree. - lots of minor cleanups and bugfixes. 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----- iG0EABECAC0WIQT0tgzFv3jCIUoxPcsxR9QN2y37KQUCWxba6w8cZ3JlZ0Brcm9h aC5jb20ACgkQMUfUDdst+ykumQCg2abWE5LijR0SNJIwX8xk64HLUAMAnAxBZDG3 aB0GyOQd54L+09q4LAdn =ZCEx -----END PGP SIGNATURE----- Merge tag 'usb-4.18-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb Pull USB and PHY updates from Greg KH: "Here is the big USB pull request for 4.18-rc1. Lots of stuff here, the highlights are: - phy driver updates and new additions - usual set of xhci driver updates - normal set of musb updates - gadget driver updates and new controllers - typec work, it's getting closer to getting fully out of the staging portion of the tree. - lots of minor cleanups and bugfixes. All of these have been in linux-next for a while with no reported issues" * tag 'usb-4.18-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb: (263 commits) Revert "xhci: Reset Renesas uPD72020x USB controller for 32-bit DMA issue" xhci: Add quirk to zero 64bit registers on Renesas PCIe controllers xhci: Allow more than 32 quirks usb: xhci: force all memory allocations to node selftests: add test for USB over IP driver USB: typec: fsusb302: no need to check return value of debugfs_create_dir() USB: gadget: udc: s3c2410_udc: no need to check return value of debugfs_create functions USB: gadget: udc: renesas_usb3: no need to check return value of debugfs_create functions USB: gadget: udc: pxa27x_udc: no need to check return value of debugfs_create functions USB: gadget: udc: gr_udc: no need to check return value of debugfs_create functions USB: gadget: udc: bcm63xx_udc: no need to check return value of debugfs_create functions USB: udc: atmel_usba_udc: no need to check return value of debugfs_create functions USB: dwc3: no need to check return value of debugfs_create functions USB: dwc2: no need to check return value of debugfs_create functions USB: core: no need to check return value of debugfs_create functions USB: chipidea: no need to check return value of debugfs_create functions USB: ehci-hcd: no need to check return value of debugfs_create functions USB: fhci-hcd: no need to check return value of debugfs_create functions USB: fotg210-hcd: no need to check return value of debugfs_create functions USB: imx21-hcd: no need to check return value of debugfs_create functions ...
This commit is contained in:
commit
07c4dd3435
|
@ -189,6 +189,28 @@ 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/quirks
|
||||
Date: May 2018
|
||||
Contact: Nicolas Boichat <drinkcat@chromium.org>
|
||||
Description:
|
||||
In some cases, we care about time-to-active for devices
|
||||
connected on a specific port (e.g. non-standard USB port like
|
||||
pogo pins), where the device to be connected is known in
|
||||
advance, and behaves well according to the specification.
|
||||
This attribute is a bit-field that controls the behavior of
|
||||
a specific port:
|
||||
- Bit 0 of this field selects the "old" enumeration scheme,
|
||||
as it is considerably faster (it only causes one USB reset
|
||||
instead of 2).
|
||||
The old enumeration scheme can also be selected globally
|
||||
using /sys/module/usbcore/parameters/old_scheme_first, but
|
||||
it is often not desirable as the new scheme was introduced to
|
||||
increase compatibility with more devices.
|
||||
- Bit 1 reduces TRSTRCY to the 10 ms that are required by the
|
||||
USB 2.0 specification, instead of the 50 ms that are normally
|
||||
used to help make enumeration work better on some high speed
|
||||
devices.
|
||||
|
||||
What: /sys/bus/usb/devices/.../(hub interface)/portX/over_current_count
|
||||
Date: February 2018
|
||||
Contact: Richard Leitner <richard.leitner@skidata.com>
|
||||
|
@ -236,3 +258,21 @@ Description:
|
|||
Supported values are 0 - 15.
|
||||
More information on how besl values map to microseconds can be found in
|
||||
USB 2.0 ECN Errata for Link Power Management, section 4.10)
|
||||
|
||||
What: /sys/bus/usb/devices/.../rx_lanes
|
||||
Date: March 2018
|
||||
Contact: Mathias Nyman <mathias.nyman@linux.intel.com>
|
||||
Description:
|
||||
Number of rx lanes the device is using.
|
||||
USB 3.2 adds Dual-lane support, 2 rx and 2 tx lanes over Type-C.
|
||||
Inter-Chip SSIC devices support asymmetric lanes up to 4 lanes per
|
||||
direction. Devices before USB 3.2 are single lane (rx_lanes = 1)
|
||||
|
||||
What: /sys/bus/usb/devices/.../tx_lanes
|
||||
Date: March 2018
|
||||
Contact: Mathias Nyman <mathias.nyman@linux.intel.com>
|
||||
Description:
|
||||
Number of tx lanes the device is using.
|
||||
USB 3.2 adds Dual-lane support, 2 rx and 2 tx -lanes over Type-C.
|
||||
Inter-Chip SSIC devices support asymmetric lanes up to 4 lanes per
|
||||
direction. Devices before USB 3.2 are single lane (tx_lanes = 1)
|
||||
|
|
|
@ -1,3 +1,458 @@
|
|||
===== General Properties =====
|
||||
|
||||
What: /sys/class/power_supply/<supply_name>/manufacturer
|
||||
Date: May 2007
|
||||
Contact: linux-pm@vger.kernel.org
|
||||
Description:
|
||||
Reports the name of the device manufacturer.
|
||||
|
||||
Access: Read
|
||||
Valid values: Represented as string
|
||||
|
||||
What: /sys/class/power_supply/<supply_name>/model_name
|
||||
Date: May 2007
|
||||
Contact: linux-pm@vger.kernel.org
|
||||
Description:
|
||||
Reports the name of the device model.
|
||||
|
||||
Access: Read
|
||||
Valid values: Represented as string
|
||||
|
||||
What: /sys/class/power_supply/<supply_name>/serial_number
|
||||
Date: January 2008
|
||||
Contact: linux-pm@vger.kernel.org
|
||||
Description:
|
||||
Reports the serial number of the device.
|
||||
|
||||
Access: Read
|
||||
Valid values: Represented as string
|
||||
|
||||
What: /sys/class/power_supply/<supply_name>/type
|
||||
Date: May 2010
|
||||
Contact: linux-pm@vger.kernel.org
|
||||
Description:
|
||||
Describes the main type of the supply.
|
||||
|
||||
Access: Read
|
||||
Valid values: "Battery", "UPS", "Mains", "USB"
|
||||
|
||||
===== Battery Properties =====
|
||||
|
||||
What: /sys/class/power_supply/<supply_name>/capacity
|
||||
Date: May 2007
|
||||
Contact: linux-pm@vger.kernel.org
|
||||
Description:
|
||||
Fine grain representation of battery capacity.
|
||||
Access: Read
|
||||
Valid values: 0 - 100 (percent)
|
||||
|
||||
What: /sys/class/power_supply/<supply_name>/capacity_alert_max
|
||||
Date: July 2012
|
||||
Contact: linux-pm@vger.kernel.org
|
||||
Description:
|
||||
Maximum battery capacity trip-wire value where the supply will
|
||||
notify user-space of the event. This is normally used for the
|
||||
battery discharging scenario where user-space needs to know the
|
||||
battery has dropped to an upper level so it can take
|
||||
appropriate action (e.g. warning user that battery level is
|
||||
low).
|
||||
|
||||
Access: Read, Write
|
||||
Valid values: 0 - 100 (percent)
|
||||
|
||||
What: /sys/class/power_supply/<supply_name>/capacity_alert_min
|
||||
Date: July 2012
|
||||
Contact: linux-pm@vger.kernel.org
|
||||
Description:
|
||||
Minimum battery capacity trip-wire value where the supply will
|
||||
notify user-space of the event. This is normally used for the
|
||||
battery discharging scenario where user-space needs to know the
|
||||
battery has dropped to a lower level so it can take
|
||||
appropriate action (e.g. warning user that battery level is
|
||||
critically low).
|
||||
|
||||
Access: Read, Write
|
||||
Valid values: 0 - 100 (percent)
|
||||
|
||||
What: /sys/class/power_supply/<supply_name>/capacity_level
|
||||
Date: June 2009
|
||||
Contact: linux-pm@vger.kernel.org
|
||||
Description:
|
||||
Coarse representation of battery capacity.
|
||||
|
||||
Access: Read
|
||||
Valid values: "Unknown", "Critical", "Low", "Normal", "High",
|
||||
"Full"
|
||||
|
||||
What: /sys/class/power_supply/<supply_name>/current_avg
|
||||
Date: May 2007
|
||||
Contact: linux-pm@vger.kernel.org
|
||||
Description:
|
||||
Reports an average IBAT current reading for the battery, over a
|
||||
fixed period. Normally devices will provide a fixed interval in
|
||||
which they average readings to smooth out the reported value.
|
||||
|
||||
Access: Read
|
||||
Valid values: Represented in microamps
|
||||
|
||||
What: /sys/class/power_supply/<supply_name>/current_max
|
||||
Date: October 2010
|
||||
Contact: linux-pm@vger.kernel.org
|
||||
Description:
|
||||
Reports the maximum IBAT current allowed into the battery.
|
||||
|
||||
Access: Read
|
||||
Valid values: Represented in microamps
|
||||
|
||||
What: /sys/class/power_supply/<supply_name>/current_now
|
||||
Date: May 2007
|
||||
Contact: linux-pm@vger.kernel.org
|
||||
Description:
|
||||
Reports an instant, single IBAT current reading for the battery.
|
||||
This value is not averaged/smoothed.
|
||||
|
||||
Access: Read
|
||||
Valid values: Represented in microamps
|
||||
|
||||
What: /sys/class/power_supply/<supply_name>/charge_type
|
||||
Date: July 2009
|
||||
Contact: linux-pm@vger.kernel.org
|
||||
Description:
|
||||
Represents the type of charging currently being applied to the
|
||||
battery.
|
||||
|
||||
Access: Read
|
||||
Valid values: "Unknown", "N/A", "Trickle", "Fast"
|
||||
|
||||
What: /sys/class/power_supply/<supply_name>/charge_term_current
|
||||
Date: July 2014
|
||||
Contact: linux-pm@vger.kernel.org
|
||||
Description:
|
||||
Reports the charging current value which is used to determine
|
||||
when the battery is considered full and charging should end.
|
||||
|
||||
Access: Read
|
||||
Valid values: Represented in microamps
|
||||
|
||||
What: /sys/class/power_supply/<supply_name>/health
|
||||
Date: May 2007
|
||||
Contact: linux-pm@vger.kernel.org
|
||||
Description:
|
||||
Reports the health of the battery or battery side of charger
|
||||
functionality.
|
||||
|
||||
Access: Read
|
||||
Valid values: "Unknown", "Good", "Overheat", "Dead",
|
||||
"Over voltage", "Unspecified failure", "Cold",
|
||||
"Watchdog timer expire", "Safety timer expire"
|
||||
|
||||
What: /sys/class/power_supply/<supply_name>/precharge_current
|
||||
Date: June 2017
|
||||
Contact: linux-pm@vger.kernel.org
|
||||
Description:
|
||||
Reports the charging current applied during pre-charging phase
|
||||
for a battery charge cycle.
|
||||
|
||||
Access: Read
|
||||
Valid values: Represented in microamps
|
||||
|
||||
What: /sys/class/power_supply/<supply_name>/present
|
||||
Date: May 2007
|
||||
Contact: linux-pm@vger.kernel.org
|
||||
Description:
|
||||
Reports whether a battery is present or not in the system.
|
||||
|
||||
Access: Read
|
||||
Valid values:
|
||||
0: Absent
|
||||
1: Present
|
||||
|
||||
What: /sys/class/power_supply/<supply_name>/status
|
||||
Date: May 2007
|
||||
Contact: linux-pm@vger.kernel.org
|
||||
Description:
|
||||
Represents the charging status of the battery. Normally this
|
||||
is read-only reporting although for some supplies this can be
|
||||
used to enable/disable charging to the battery.
|
||||
|
||||
Access: Read, Write
|
||||
Valid values: "Unknown", "Charging", "Discharging",
|
||||
"Not charging", "Full"
|
||||
|
||||
What: /sys/class/power_supply/<supply_name>/technology
|
||||
Date: May 2007
|
||||
Contact: linux-pm@vger.kernel.org
|
||||
Description:
|
||||
Describes the battery technology supported by the supply.
|
||||
|
||||
Access: Read
|
||||
Valid values: "Unknown", "NiMH", "Li-ion", "Li-poly", "LiFe",
|
||||
"NiCd", "LiMn"
|
||||
|
||||
What: /sys/class/power_supply/<supply_name>/temp
|
||||
Date: May 2007
|
||||
Contact: linux-pm@vger.kernel.org
|
||||
Description:
|
||||
Reports the current TBAT battery temperature reading.
|
||||
|
||||
Access: Read
|
||||
Valid values: Represented in 1/10 Degrees Celsius
|
||||
|
||||
What: /sys/class/power_supply/<supply_name>/temp_alert_max
|
||||
Date: July 2012
|
||||
Contact: linux-pm@vger.kernel.org
|
||||
Description:
|
||||
Maximum TBAT temperature trip-wire value where the supply will
|
||||
notify user-space of the event. This is normally used for the
|
||||
battery charging scenario where user-space needs to know the
|
||||
battery temperature has crossed an upper threshold so it can
|
||||
take appropriate action (e.g. warning user that battery level is
|
||||
critically high, and charging has stopped).
|
||||
|
||||
Access: Read
|
||||
Valid values: Represented in 1/10 Degrees Celsius
|
||||
|
||||
What: /sys/class/power_supply/<supply_name>/temp_alert_min
|
||||
Date: July 2012
|
||||
Contact: linux-pm@vger.kernel.org
|
||||
Description:
|
||||
Minimum TBAT temperature trip-wire value where the supply will
|
||||
notify user-space of the event. This is normally used for the
|
||||
battery charging scenario where user-space needs to know the
|
||||
battery temperature has crossed a lower threshold so it can take
|
||||
appropriate action (e.g. warning user that battery level is
|
||||
high, and charging current has been reduced accordingly to
|
||||
remedy the situation).
|
||||
|
||||
Access: Read
|
||||
Valid values: Represented in 1/10 Degrees Celsius
|
||||
|
||||
What: /sys/class/power_supply/<supply_name>/temp_max
|
||||
Date: July 2014
|
||||
Contact: linux-pm@vger.kernel.org
|
||||
Description:
|
||||
Reports the maximum allowed TBAT battery temperature for
|
||||
charging.
|
||||
|
||||
Access: Read
|
||||
Valid values: Represented in 1/10 Degrees Celsius
|
||||
|
||||
What: /sys/class/power_supply/<supply_name>/temp_min
|
||||
Date: July 2014
|
||||
Contact: linux-pm@vger.kernel.org
|
||||
Description:
|
||||
Reports the minimum allowed TBAT battery temperature for
|
||||
charging.
|
||||
|
||||
Access: Read
|
||||
Valid values: Represented in 1/10 Degrees Celsius
|
||||
|
||||
What: /sys/class/power_supply/<supply_name>/voltage_avg,
|
||||
Date: May 2007
|
||||
Contact: linux-pm@vger.kernel.org
|
||||
Description:
|
||||
Reports an average VBAT voltage reading for the battery, over a
|
||||
fixed period. Normally devices will provide a fixed interval in
|
||||
which they average readings to smooth out the reported value.
|
||||
|
||||
Access: Read
|
||||
Valid values: Represented in microvolts
|
||||
|
||||
What: /sys/class/power_supply/<supply_name>/voltage_max,
|
||||
Date: January 2008
|
||||
Contact: linux-pm@vger.kernel.org
|
||||
Description:
|
||||
Reports the maximum safe VBAT voltage permitted for the battery,
|
||||
during charging.
|
||||
|
||||
Access: Read
|
||||
Valid values: Represented in microvolts
|
||||
|
||||
What: /sys/class/power_supply/<supply_name>/voltage_min,
|
||||
Date: January 2008
|
||||
Contact: linux-pm@vger.kernel.org
|
||||
Description:
|
||||
Reports the minimum safe VBAT voltage permitted for the battery,
|
||||
during discharging.
|
||||
|
||||
Access: Read
|
||||
Valid values: Represented in microvolts
|
||||
|
||||
What: /sys/class/power_supply/<supply_name>/voltage_now,
|
||||
Date: May 2007
|
||||
Contact: linux-pm@vger.kernel.org
|
||||
Description:
|
||||
Reports an instant, single VBAT voltage reading for the battery.
|
||||
This value is not averaged/smoothed.
|
||||
|
||||
Access: Read
|
||||
Valid values: Represented in microvolts
|
||||
|
||||
===== USB Properties =====
|
||||
|
||||
What: /sys/class/power_supply/<supply_name>/current_avg
|
||||
Date: May 2007
|
||||
Contact: linux-pm@vger.kernel.org
|
||||
Description:
|
||||
Reports an average IBUS current reading over a fixed period.
|
||||
Normally devices will provide a fixed interval in which they
|
||||
average readings to smooth out the reported value.
|
||||
|
||||
Access: Read
|
||||
Valid values: Represented in microamps
|
||||
|
||||
|
||||
What: /sys/class/power_supply/<supply_name>/current_max
|
||||
Date: October 2010
|
||||
Contact: linux-pm@vger.kernel.org
|
||||
Description:
|
||||
Reports the maximum IBUS current the supply can support.
|
||||
|
||||
Access: Read
|
||||
Valid values: Represented in microamps
|
||||
|
||||
What: /sys/class/power_supply/<supply_name>/current_now
|
||||
Date: May 2007
|
||||
Contact: linux-pm@vger.kernel.org
|
||||
Description:
|
||||
Reports the IBUS current supplied now. This value is generally
|
||||
read-only reporting, unless the 'online' state of the supply
|
||||
is set to be programmable, in which case this value can be set
|
||||
within the reported min/max range.
|
||||
|
||||
Access: Read, Write
|
||||
Valid values: Represented in microamps
|
||||
|
||||
What: /sys/class/power_supply/<supply_name>/input_current_limit
|
||||
Date: July 2014
|
||||
Contact: linux-pm@vger.kernel.org
|
||||
Description:
|
||||
Details the incoming IBUS current limit currently set in the
|
||||
supply. Normally this is configured based on the type of
|
||||
connection made (e.g. A configured SDP should output a maximum
|
||||
of 500mA so the input current limit is set to the same value).
|
||||
|
||||
Access: Read, Write
|
||||
Valid values: Represented in microamps
|
||||
|
||||
What: /sys/class/power_supply/<supply_name>/online,
|
||||
Date: May 2007
|
||||
Contact: linux-pm@vger.kernel.org
|
||||
Description:
|
||||
Indicates if VBUS is present for the supply. When the supply is
|
||||
online, and the supply allows it, then it's possible to switch
|
||||
between online states (e.g. Fixed -> Programmable for a PD_PPS
|
||||
USB supply so voltage and current can be controlled).
|
||||
|
||||
Access: Read, Write
|
||||
Valid values:
|
||||
0: Offline
|
||||
1: Online Fixed - Fixed Voltage Supply
|
||||
2: Online Programmable - Programmable Voltage Supply
|
||||
|
||||
What: /sys/class/power_supply/<supply_name>/temp
|
||||
Date: May 2007
|
||||
Contact: linux-pm@vger.kernel.org
|
||||
Description:
|
||||
Reports the current supply temperature reading. This would
|
||||
normally be the internal temperature of the device itself (e.g
|
||||
TJUNC temperature of an IC)
|
||||
|
||||
Access: Read
|
||||
Valid values: Represented in 1/10 Degrees Celsius
|
||||
|
||||
What: /sys/class/power_supply/<supply_name>/temp_alert_max
|
||||
Date: July 2012
|
||||
Contact: linux-pm@vger.kernel.org
|
||||
Description:
|
||||
Maximum supply temperature trip-wire value where the supply will
|
||||
notify user-space of the event. This is normally used for the
|
||||
charging scenario where user-space needs to know the supply
|
||||
temperature has crossed an upper threshold so it can take
|
||||
appropriate action (e.g. warning user that the supply
|
||||
temperature is critically high, and charging has stopped to
|
||||
remedy the situation).
|
||||
|
||||
Access: Read
|
||||
Valid values: Represented in 1/10 Degrees Celsius
|
||||
|
||||
What: /sys/class/power_supply/<supply_name>/temp_alert_min
|
||||
Date: July 2012
|
||||
Contact: linux-pm@vger.kernel.org
|
||||
Description:
|
||||
Minimum supply temperature trip-wire value where the supply will
|
||||
notify user-space of the event. This is normally used for the
|
||||
charging scenario where user-space needs to know the supply
|
||||
temperature has crossed a lower threshold so it can take
|
||||
appropriate action (e.g. warning user that the supply
|
||||
temperature is high, and charging current has been reduced
|
||||
accordingly to remedy the situation).
|
||||
|
||||
Access: Read
|
||||
Valid values: Represented in 1/10 Degrees Celsius
|
||||
|
||||
What: /sys/class/power_supply/<supply_name>/temp_max
|
||||
Date: July 2014
|
||||
Contact: linux-pm@vger.kernel.org
|
||||
Description:
|
||||
Reports the maximum allowed supply temperature for operation.
|
||||
|
||||
Access: Read
|
||||
Valid values: Represented in 1/10 Degrees Celsius
|
||||
|
||||
What: /sys/class/power_supply/<supply_name>/temp_min
|
||||
Date: July 2014
|
||||
Contact: linux-pm@vger.kernel.org
|
||||
Description:
|
||||
Reports the mainimum allowed supply temperature for operation.
|
||||
|
||||
Access: Read
|
||||
Valid values: Represented in 1/10 Degrees Celsius
|
||||
|
||||
What: /sys/class/power_supply/<supply_name>/usb_type
|
||||
Date: March 2018
|
||||
Contact: linux-pm@vger.kernel.org
|
||||
Description:
|
||||
Reports what type of USB connection is currently active for
|
||||
the supply, for example it can show if USB-PD capable source
|
||||
is attached.
|
||||
|
||||
Access: Read-Only
|
||||
Valid values: "Unknown", "SDP", "DCP", "CDP", "ACA", "C", "PD",
|
||||
"PD_DRP", "PD_PPS", "BrickID"
|
||||
|
||||
What: /sys/class/power_supply/<supply_name>/voltage_max
|
||||
Date: January 2008
|
||||
Contact: linux-pm@vger.kernel.org
|
||||
Description:
|
||||
Reports the maximum VBUS voltage the supply can support.
|
||||
|
||||
Access: Read
|
||||
Valid values: Represented in microvolts
|
||||
|
||||
What: /sys/class/power_supply/<supply_name>/voltage_min
|
||||
Date: January 2008
|
||||
Contact: linux-pm@vger.kernel.org
|
||||
Description:
|
||||
Reports the minimum VBUS voltage the supply can support.
|
||||
|
||||
Access: Read
|
||||
Valid values: Represented in microvolts
|
||||
|
||||
What: /sys/class/power_supply/<supply_name>/voltage_now
|
||||
Date: May 2007
|
||||
Contact: linux-pm@vger.kernel.org
|
||||
Description:
|
||||
Reports the VBUS voltage supplied now. This value is generally
|
||||
read-only reporting, unless the 'online' state of the supply
|
||||
is set to be programmable, in which case this value can be set
|
||||
within the reported min/max range.
|
||||
|
||||
Access: Read, Write
|
||||
Valid values: Represented in microvolts
|
||||
|
||||
===== Device Specific Properties =====
|
||||
|
||||
What: /sys/class/power/ds2760-battery.*/charge_now
|
||||
Date: May 2010
|
||||
KernelVersion: 2.6.35
|
||||
|
|
109
Documentation/devicetree/bindings/phy/phy-mtk-xsphy.txt
Normal file
109
Documentation/devicetree/bindings/phy/phy-mtk-xsphy.txt
Normal file
|
@ -0,0 +1,109 @@
|
|||
MediaTek XS-PHY binding
|
||||
--------------------------
|
||||
|
||||
The XS-PHY controller supports physical layer functionality for USB3.1
|
||||
GEN2 controller on MediaTek SoCs.
|
||||
|
||||
Required properties (controller (parent) node):
|
||||
- compatible : should be "mediatek,<soc-model>-xsphy", "mediatek,xsphy",
|
||||
soc-model is the name of SoC, such as mt3611 etc;
|
||||
when using "mediatek,xsphy" compatible string, you need SoC specific
|
||||
ones in addition, one of:
|
||||
- "mediatek,mt3611-xsphy"
|
||||
|
||||
- #address-cells, #size-cells : should use the same values as the root node
|
||||
- ranges: must be present
|
||||
|
||||
Optional properties (controller (parent) node):
|
||||
- reg : offset and length of register shared by multiple U3 ports,
|
||||
exclude port's private register, if only U2 ports provided,
|
||||
shouldn't use the property.
|
||||
- mediatek,src-ref-clk-mhz : u32, frequency of reference clock for slew rate
|
||||
calibrate
|
||||
- mediatek,src-coef : u32, coefficient for slew rate calibrate, depends on
|
||||
SoC process
|
||||
|
||||
Required nodes : a sub-node is required for each port the controller
|
||||
provides. Address range information including the usual
|
||||
'reg' property is used inside these nodes to describe
|
||||
the controller's topology.
|
||||
|
||||
Required properties (port (child) node):
|
||||
- reg : address and length of the register set for the port.
|
||||
- clocks : a list of phandle + clock-specifier pairs, one for each
|
||||
entry in clock-names
|
||||
- clock-names : must contain
|
||||
"ref": 48M reference clock for HighSpeed analog phy; and 26M
|
||||
reference clock for SuperSpeedPlus analog phy, sometimes is
|
||||
24M, 25M or 27M, depended on platform.
|
||||
- #phy-cells : should be 1
|
||||
cell after port phandle is phy type from:
|
||||
- PHY_TYPE_USB2
|
||||
- PHY_TYPE_USB3
|
||||
|
||||
The following optional properties are only for debug or HQA test
|
||||
Optional properties (PHY_TYPE_USB2 port (child) node):
|
||||
- mediatek,eye-src : u32, the value of slew rate calibrate
|
||||
- mediatek,eye-vrt : u32, the selection of VRT reference voltage
|
||||
- mediatek,eye-term : u32, the selection of HS_TX TERM reference voltage
|
||||
- mediatek,efuse-intr : u32, the selection of Internal Resistor
|
||||
|
||||
Optional properties (PHY_TYPE_USB3 port (child) node):
|
||||
- mediatek,efuse-intr : u32, the selection of Internal Resistor
|
||||
- mediatek,efuse-tx-imp : u32, the selection of TX Impedance
|
||||
- mediatek,efuse-rx-imp : u32, the selection of RX Impedance
|
||||
|
||||
Banks layout of xsphy
|
||||
-------------------------------------------------------------
|
||||
port offset bank
|
||||
u2 port0 0x0000 MISC
|
||||
0x0100 FMREG
|
||||
0x0300 U2PHY_COM
|
||||
u2 port1 0x1000 MISC
|
||||
0x1100 FMREG
|
||||
0x1300 U2PHY_COM
|
||||
u2 port2 0x2000 MISC
|
||||
...
|
||||
u31 common 0x3000 DIG_GLB
|
||||
0x3100 PHYA_GLB
|
||||
u31 port0 0x3400 DIG_LN_TOP
|
||||
0x3500 DIG_LN_TX0
|
||||
0x3600 DIG_LN_RX0
|
||||
0x3700 DIG_LN_DAIF
|
||||
0x3800 PHYA_LN
|
||||
u31 port1 0x3a00 DIG_LN_TOP
|
||||
0x3b00 DIG_LN_TX0
|
||||
0x3c00 DIG_LN_RX0
|
||||
0x3d00 DIG_LN_DAIF
|
||||
0x3e00 PHYA_LN
|
||||
...
|
||||
|
||||
DIG_GLB & PHYA_GLB are shared by U31 ports.
|
||||
|
||||
Example:
|
||||
|
||||
u3phy: usb-phy@11c40000 {
|
||||
compatible = "mediatek,mt3611-xsphy", "mediatek,xsphy";
|
||||
reg = <0 0x11c43000 0 0x0200>;
|
||||
mediatek,src-ref-clk-mhz = <26>;
|
||||
mediatek,src-coef = <17>;
|
||||
#address-cells = <2>;
|
||||
#size-cells = <2>;
|
||||
ranges;
|
||||
|
||||
u2port0: usb-phy@11c40000 {
|
||||
reg = <0 0x11c40000 0 0x0400>;
|
||||
clocks = <&clk48m>;
|
||||
clock-names = "ref";
|
||||
mediatek,eye-src = <4>;
|
||||
#phy-cells = <1>;
|
||||
};
|
||||
|
||||
u3port0: usb-phy@11c43000 {
|
||||
reg = <0 0x11c43400 0 0x0500>;
|
||||
clocks = <&clk26m>;
|
||||
clock-names = "ref";
|
||||
mediatek,efuse-intr = <28>;
|
||||
#phy-cells = <1>;
|
||||
};
|
||||
};
|
|
@ -9,7 +9,8 @@ Required properties:
|
|||
"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,qmp-v3-usb3-phy" for USB3 QMP V3 phy.
|
||||
"qcom,sdm845-qmp-usb3-phy" for USB3 QMP V3 phy on sdm845,
|
||||
"qcom,sdm845-qmp-usb3-uni-phy" for USB3 QMP V3 UNI phy on sdm845.
|
||||
|
||||
- reg: offset and length of register set for PHY's common serdes block.
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ QUSB2 controller supports LS/FS/HS usb connectivity on Qualcomm chipsets.
|
|||
Required properties:
|
||||
- compatible: compatible list, contains
|
||||
"qcom,msm8996-qusb2-phy" for 14nm PHY on msm8996,
|
||||
"qcom,qusb2-v2-phy" for QUSB2 V2 PHY.
|
||||
"qcom,sdm845-qusb2-phy" for 10nm PHY on sdm845.
|
||||
|
||||
- reg: offset and length of the PHY register set.
|
||||
- #phy-cells: must be 0.
|
||||
|
@ -27,6 +27,27 @@ Optional properties:
|
|||
tuning parameter value for qusb2 phy.
|
||||
|
||||
- qcom,tcsr-syscon: Phandle to TCSR syscon register region.
|
||||
- qcom,imp-res-offset-value: It is a 6 bit value that specifies offset to be
|
||||
added to PHY refgen RESCODE via IMP_CTRL1 register. It is a PHY
|
||||
tuning parameter that may vary for different boards of same SOC.
|
||||
This property is applicable to only QUSB2 v2 PHY (sdm845).
|
||||
- qcom,hstx-trim-value: It is a 4 bit value that specifies tuning for HSTX
|
||||
output current.
|
||||
Possible range is - 15mA to 24mA (stepsize of 600 uA).
|
||||
See dt-bindings/phy/phy-qcom-qusb2.h for applicable values.
|
||||
This property is applicable to only QUSB2 v2 PHY (sdm845).
|
||||
Default value is 22.2mA for sdm845.
|
||||
- qcom,preemphasis-level: It is a 2 bit value that specifies pre-emphasis level.
|
||||
Possible range is 0 to 15% (stepsize of 5%).
|
||||
See dt-bindings/phy/phy-qcom-qusb2.h for applicable values.
|
||||
This property is applicable to only QUSB2 v2 PHY (sdm845).
|
||||
Default value is 10% for sdm845.
|
||||
- qcom,preemphasis-width: It is a 1 bit value that specifies how long the HSTX
|
||||
pre-emphasis (specified using qcom,preemphasis-level) must be in
|
||||
effect. Duration could be half-bit of full-bit.
|
||||
See dt-bindings/phy/phy-qcom-qusb2.h for applicable values.
|
||||
This property is applicable to only QUSB2 v2 PHY (sdm845).
|
||||
Default value is full-bit width for sdm845.
|
||||
|
||||
Example:
|
||||
hsusb_phy: phy@7411000 {
|
||||
|
|
|
@ -76,6 +76,10 @@ Optional properties:
|
|||
needs to make sure it does not send more than 90%
|
||||
maximum_periodic_data_per_frame. The use case is multiple transactions, but
|
||||
less frame rate.
|
||||
- mux-controls: The mux control for toggling host/device output of this
|
||||
controller. It's expected that a mux state of 0 indicates device mode and a
|
||||
mux state of 1 indicates host mode.
|
||||
- mux-control-names: Shall be "usb_switch" if mux-controls is specified.
|
||||
|
||||
i.mx specific properties
|
||||
- fsl,usbmisc: phandler of non-core register device, with one
|
||||
|
@ -102,4 +106,6 @@ Example:
|
|||
rx-burst-size-dword = <0x10>;
|
||||
extcon = <0>, <&usb_id>;
|
||||
phy-clkgate-delay-us = <400>;
|
||||
mux-controls = <&usb_switch>;
|
||||
mux-control-names = "usb_switch";
|
||||
};
|
||||
|
|
|
@ -7,6 +7,26 @@ Required properties:
|
|||
- compatible: must be "snps,dwc3"
|
||||
- reg : Address and length of the register set for the device
|
||||
- interrupts: Interrupts used by the dwc3 controller.
|
||||
- clock-names: should contain "ref", "bus_early", "suspend"
|
||||
- clocks: list of phandle and clock specifier pairs corresponding to
|
||||
entries in the clock-names property.
|
||||
|
||||
Exception for clocks:
|
||||
clocks are optional if the parent node (i.e. glue-layer) is compatible to
|
||||
one of the following:
|
||||
"amlogic,meson-axg-dwc3"
|
||||
"amlogic,meson-gxl-dwc3"
|
||||
"cavium,octeon-7130-usb-uctl"
|
||||
"qcom,dwc3"
|
||||
"samsung,exynos5250-dwusb3"
|
||||
"samsung,exynos7-dwusb3"
|
||||
"sprd,sc9860-dwc3"
|
||||
"st,stih407-dwc3"
|
||||
"ti,am437x-dwc3"
|
||||
"ti,dwc3"
|
||||
"ti,keystone-dwc3"
|
||||
"rockchip,rk3399-dwc3"
|
||||
"xlnx,zynqmp-dwc3"
|
||||
|
||||
Optional properties:
|
||||
- usb-phy : array of phandle for the PHY device. The first element
|
||||
|
@ -15,6 +35,7 @@ Optional properties:
|
|||
- phys: from the *Generic PHY* bindings
|
||||
- phy-names: from the *Generic PHY* bindings; supported names are "usb2-phy"
|
||||
or "usb3-phy".
|
||||
- resets: a single pair of phandle and reset specifier
|
||||
- snps,usb3_lpm_capable: determines if platform is USB3 LPM capable
|
||||
- snps,disable_scramble_quirk: true when SW should disable data scrambling.
|
||||
Only really useful for FPGA builds.
|
||||
|
|
|
@ -6,12 +6,6 @@ Required properties :
|
|||
- interrupts : Interrupt specifier
|
||||
|
||||
Optional properties :
|
||||
- fcs,max-sink-microvolt : Maximum voltage to negotiate when configured as sink
|
||||
- fcs,max-sink-microamp : Maximum current to negotiate when configured as sink
|
||||
- fcs,max-sink-microwatt : Maximum power to negotiate when configured as sink
|
||||
If this is less then max-sink-microvolt *
|
||||
max-sink-microamp then the configured current will
|
||||
be clamped.
|
||||
- fcs,operating-sink-microwatt :
|
||||
Minimum amount of power accepted from a sink
|
||||
when negotiating
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
HiSilicon STB xHCI
|
||||
|
||||
The device node for HiSilicon STB xHCI host controller
|
||||
|
||||
Required properties:
|
||||
- compatible: should be "hisilicon,hi3798cv200-xhci"
|
||||
- reg: specifies physical base address and size of the registers
|
||||
- interrupts : interrupt used by the controller
|
||||
- clocks: a list of phandle + clock-specifier pairs, one for each
|
||||
entry in clock-names
|
||||
- clock-names: must contain
|
||||
"bus": for bus clock
|
||||
"utmi": for utmi clock
|
||||
"pipe": for pipe clock
|
||||
"suspend": for suspend clock
|
||||
- resets: a list of phandle and reset specifier pairs as listed in
|
||||
reset-names property.
|
||||
- reset-names: must contain
|
||||
"soft": for soft reset
|
||||
- phys: a list of phandle + phy specifier pairs
|
||||
- phy-names: must contain at least one of following:
|
||||
"inno": for inno phy
|
||||
"combo": for combo phy
|
||||
|
||||
Optional properties:
|
||||
- usb2-lpm-disable: indicate if we don't want to enable USB2 HW LPM
|
||||
- usb3-lpm-capable: determines if platform is USB3 LPM capable
|
||||
- imod-interval-ns: default interrupt moderation interval is 40000ns
|
||||
|
||||
Example:
|
||||
|
||||
xhci0: xchi@f98a0000 {
|
||||
compatible = "hisilicon,hi3798cv200-xhci";
|
||||
reg = <0xf98a0000 0x10000>;
|
||||
interrupts = <GIC_SPI 69 IRQ_TYPE_LEVEL_HIGH>;
|
||||
clocks = <&crg HISTB_USB3_BUS_CLK>,
|
||||
<&crg HISTB_USB3_UTMI_CLK>,
|
||||
<&crg HISTB_USB3_PIPE_CLK>,
|
||||
<&crg HISTB_USB3_SUSPEND_CLK>;
|
||||
clock-names = "bus", "utmi", "pipe", "suspend";
|
||||
resets = <&crg 0xb0 12>;
|
||||
reset-names = "soft";
|
||||
phys = <&usb2_phy1_port1 0>, <&combphy0 PHY_TYPE_USB3>;
|
||||
phy-names = "inno", "combo";
|
||||
};
|
|
@ -1,54 +1,95 @@
|
|||
Qualcomm SuperSpeed DWC3 USB SoC controller
|
||||
|
||||
Required properties:
|
||||
- compatible: should contain "qcom,dwc3"
|
||||
- compatible: Compatible list, contains
|
||||
"qcom,dwc3"
|
||||
"qcom,msm8996-dwc3" for msm8996 SOC.
|
||||
"qcom,sdm845-dwc3" for sdm845 SOC.
|
||||
- reg: Offset and length of register set for QSCRATCH wrapper
|
||||
- power-domains: specifies a phandle to PM domain provider node
|
||||
- clocks: A list of phandle + clock-specifier pairs for the
|
||||
clocks listed in clock-names
|
||||
- clock-names: Should contain the following:
|
||||
"core" Master/Core clock, have to be >= 125 MHz for SS
|
||||
operation and >= 60MHz for HS operation
|
||||
"mock_utmi" Mock utmi clock needed for ITP/SOF generation in
|
||||
host mode. Its frequency should be 19.2MHz.
|
||||
"sleep" Sleep clock, used for wakeup when USB3 core goes
|
||||
into low power mode (U3).
|
||||
|
||||
Optional clocks:
|
||||
"iface" System bus AXI clock. Not present on all platforms
|
||||
"sleep" Sleep clock, used when USB3 core goes into low
|
||||
power mode (U3).
|
||||
"iface" System bus AXI clock.
|
||||
Not present on "qcom,msm8996-dwc3" compatible.
|
||||
"cfg_noc" System Config NOC clock.
|
||||
Not present on "qcom,msm8996-dwc3" compatible.
|
||||
- assigned-clocks: Should be:
|
||||
MOCK_UTMI_CLK
|
||||
MASTER_CLK
|
||||
- assigned-clock-rates: Should be:
|
||||
19.2Mhz (192000000) for MOCK_UTMI_CLK
|
||||
>=125Mhz (125000000) for MASTER_CLK in SS mode
|
||||
>=60Mhz (60000000) for MASTER_CLK in HS mode
|
||||
|
||||
Optional properties:
|
||||
- resets: Phandle to reset control that resets core and wrapper.
|
||||
- interrupts: specifies interrupts from controller wrapper used
|
||||
to wakeup from low power/susepnd state. Must contain
|
||||
one or more entry for interrupt-names property
|
||||
- interrupt-names: Must include the following entries:
|
||||
- "hs_phy_irq": The interrupt that is asserted when a
|
||||
wakeup event is received on USB2 bus
|
||||
- "ss_phy_irq": The interrupt that is asserted when a
|
||||
wakeup event is received on USB3 bus
|
||||
- "dm_hs_phy_irq" and "dp_hs_phy_irq": Separate
|
||||
interrupts for any wakeup event on DM and DP lines
|
||||
- qcom,select-utmi-as-pipe-clk: if present, disable USB3 pipe_clk requirement.
|
||||
Used when dwc3 operates without SSPHY and only
|
||||
HS/FS/LS modes are supported.
|
||||
|
||||
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/qcom-dwc3-usb-phy.txt
|
||||
Documentation/devicetree/bindings/phy/qcom-qmp-phy.txt - USB3 QMP PHY
|
||||
Documentation/devicetree/bindings/phy/qcom-qusb2-phy.txt - USB2 QUSB2 PHY
|
||||
|
||||
Example device nodes:
|
||||
|
||||
hs_phy: phy@100f8800 {
|
||||
compatible = "qcom,dwc3-hs-usb-phy";
|
||||
reg = <0x100f8800 0x30>;
|
||||
clocks = <&gcc USB30_0_UTMI_CLK>;
|
||||
clock-names = "ref";
|
||||
#phy-cells = <0>;
|
||||
|
||||
compatible = "qcom,qusb2-v2-phy";
|
||||
...
|
||||
};
|
||||
|
||||
ss_phy: phy@100f8830 {
|
||||
compatible = "qcom,dwc3-ss-usb-phy";
|
||||
reg = <0x100f8830 0x30>;
|
||||
clocks = <&gcc USB30_0_MASTER_CLK>;
|
||||
clock-names = "ref";
|
||||
#phy-cells = <0>;
|
||||
|
||||
compatible = "qcom,qmp-v3-usb3-phy";
|
||||
...
|
||||
};
|
||||
|
||||
usb3_0: usb30@0 {
|
||||
usb3_0: usb30@a6f8800 {
|
||||
compatible = "qcom,dwc3";
|
||||
reg = <0xa6f8800 0x400>;
|
||||
#address-cells = <1>;
|
||||
#size-cells = <1>;
|
||||
clocks = <&gcc USB30_0_MASTER_CLK>;
|
||||
clock-names = "core";
|
||||
|
||||
ranges;
|
||||
|
||||
interrupts = <0 131 0>, <0 486 0>, <0 488 0>, <0 489 0>;
|
||||
interrupt-names = "hs_phy_irq", "ss_phy_irq",
|
||||
"dm_hs_phy_irq", "dp_hs_phy_irq";
|
||||
|
||||
clocks = <&gcc GCC_USB30_PRIM_MASTER_CLK>,
|
||||
<&gcc GCC_USB30_PRIM_MOCK_UTMI_CLK>,
|
||||
<&gcc GCC_USB30_PRIM_SLEEP_CLK>;
|
||||
clock-names = "core", "mock_utmi", "sleep";
|
||||
|
||||
assigned-clocks = <&gcc GCC_USB30_PRIM_MOCK_UTMI_CLK>,
|
||||
<&gcc GCC_USB30_PRIM_MASTER_CLK>;
|
||||
assigned-clock-rates = <19200000>, <133000000>;
|
||||
|
||||
resets = <&gcc GCC_USB30_PRIM_BCR>;
|
||||
reset-names = "core_reset";
|
||||
power-domains = <&gcc USB30_PRIM_GDSC>;
|
||||
qcom,select-utmi-as-pipe-clk;
|
||||
|
||||
dwc3@10000000 {
|
||||
compatible = "snps,dwc3";
|
||||
|
|
17
Documentation/devicetree/bindings/usb/richtek,rt1711h.txt
Normal file
17
Documentation/devicetree/bindings/usb/richtek,rt1711h.txt
Normal file
|
@ -0,0 +1,17 @@
|
|||
Richtek RT1711H TypeC PD Controller.
|
||||
|
||||
Required properties:
|
||||
- compatible : Must be "richtek,rt1711h".
|
||||
- reg : Must be 0x4e, it's slave address of RT1711H.
|
||||
- interrupt-parent : the phandle for the interrupt controller that
|
||||
provides interrupts for this device.
|
||||
- interrupts : <a b> where a is the interrupt number and b represents an
|
||||
encoding of the sense and level information for the interrupt.
|
||||
|
||||
Example :
|
||||
rt1711h@4e {
|
||||
compatible = "richtek,rt1711h";
|
||||
reg = <0x4e>;
|
||||
interrupt-parent = <&gpio26>;
|
||||
interrupts = <0 IRQ_TYPE_LEVEL_LOW>;
|
||||
};
|
|
@ -674,9 +674,8 @@ operations, both of which can be traced. Format is::
|
|||
__entry->flags & DWC3_EP_ENABLED ? 'E' : 'e',
|
||||
__entry->flags & DWC3_EP_STALL ? 'S' : 's',
|
||||
__entry->flags & DWC3_EP_WEDGE ? 'W' : 'w',
|
||||
__entry->flags & DWC3_EP_BUSY ? 'B' : 'b',
|
||||
__entry->flags & DWC3_EP_TRANSFER_STARTED ? 'B' : 'b',
|
||||
__entry->flags & DWC3_EP_PENDING_REQUEST ? 'P' : 'p',
|
||||
__entry->flags & DWC3_EP_MISSED_ISOC ? 'M' : 'm',
|
||||
__entry->flags & DWC3_EP_END_TRANSFER_PENDING ? 'E' : 'e',
|
||||
__entry->direction ? '<' : '>'
|
||||
)
|
||||
|
|
10
MAINTAINERS
10
MAINTAINERS
|
@ -2331,6 +2331,14 @@ S: Maintained
|
|||
F: drivers/gpio/gpio-ath79.c
|
||||
F: Documentation/devicetree/bindings/gpio/gpio-ath79.txt
|
||||
|
||||
ATHEROS 71XX/9XXX USB PHY DRIVER
|
||||
M: Alban Bedel <albeu@free.fr>
|
||||
W: https://github.com/AlbanBedel/linux
|
||||
T: git git://github.com/AlbanBedel/linux
|
||||
S: Maintained
|
||||
F: drivers/phy/qualcomm/phy-ath79-usb.c
|
||||
F: Documentation/devicetree/bindings/phy/phy-ath79-usb.txt
|
||||
|
||||
ATHEROS ATH GENERIC UTILITIES
|
||||
M: Kalle Valo <kvalo@codeaurora.org>
|
||||
L: linux-wireless@vger.kernel.org
|
||||
|
@ -11267,6 +11275,7 @@ M: Sebastian Reichel <sre@kernel.org>
|
|||
L: linux-pm@vger.kernel.org
|
||||
T: git git://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-power-supply.git
|
||||
S: Maintained
|
||||
F: Documentation/ABI/testing/sysfs-class-power
|
||||
F: Documentation/devicetree/bindings/power/supply/
|
||||
F: include/linux/power_supply.h
|
||||
F: drivers/power/supply/
|
||||
|
@ -14692,6 +14701,7 @@ S: Maintained
|
|||
F: Documentation/usb/usbip_protocol.txt
|
||||
F: drivers/usb/usbip/
|
||||
F: tools/usb/usbip/
|
||||
F: tools/testing/selftests/drivers/usb/usbip/
|
||||
|
||||
USB PEGASUS DRIVER
|
||||
M: Petko Manolov <petkan@nucleusys.com>
|
||||
|
|
|
@ -202,8 +202,7 @@ config I2C_CHT_WC
|
|||
|
||||
Note this controller is hooked up to a TI bq24292i charger-IC,
|
||||
combined with a FUSB302 Type-C port-controller as such it is advised
|
||||
to also select CONFIG_CHARGER_BQ24190=m and CONFIG_TYPEC_FUSB302=m
|
||||
(the fusb302 driver currently is in drivers/staging).
|
||||
to also select CONFIG_TYPEC_FUSB302=m.
|
||||
|
||||
config I2C_NFORCE2
|
||||
tristate "Nvidia nForce2, nForce3 and nForce4"
|
||||
|
|
|
@ -62,6 +62,9 @@ struct pn533_usb_phy {
|
|||
struct urb *out_urb;
|
||||
struct urb *in_urb;
|
||||
|
||||
struct urb *ack_urb;
|
||||
u8 *ack_buffer;
|
||||
|
||||
struct pn533 *priv;
|
||||
};
|
||||
|
||||
|
@ -150,13 +153,16 @@ static int pn533_usb_send_ack(struct pn533 *dev, gfp_t flags)
|
|||
struct pn533_usb_phy *phy = dev->phy;
|
||||
static const u8 ack[6] = {0x00, 0x00, 0xff, 0x00, 0xff, 0x00};
|
||||
/* spec 7.1.1.3: Preamble, SoPC (2), ACK Code (2), Postamble */
|
||||
int rc;
|
||||
|
||||
phy->out_urb->transfer_buffer = (u8 *)ack;
|
||||
phy->out_urb->transfer_buffer_length = sizeof(ack);
|
||||
rc = usb_submit_urb(phy->out_urb, flags);
|
||||
if (!phy->ack_buffer) {
|
||||
phy->ack_buffer = kmemdup(ack, sizeof(ack), flags);
|
||||
if (!phy->ack_buffer)
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
return rc;
|
||||
phy->ack_urb->transfer_buffer = phy->ack_buffer;
|
||||
phy->ack_urb->transfer_buffer_length = sizeof(ack);
|
||||
return usb_submit_urb(phy->ack_urb, flags);
|
||||
}
|
||||
|
||||
static int pn533_usb_send_frame(struct pn533 *dev,
|
||||
|
@ -375,26 +381,31 @@ static int pn533_acr122_poweron_rdr(struct pn533_usb_phy *phy)
|
|||
/* Power on th reader (CCID cmd) */
|
||||
u8 cmd[10] = {PN533_ACR122_PC_TO_RDR_ICCPOWERON,
|
||||
0, 0, 0, 0, 0, 0, 3, 0, 0};
|
||||
char *buffer;
|
||||
int transferred;
|
||||
int rc;
|
||||
void *cntx;
|
||||
struct pn533_acr122_poweron_rdr_arg arg;
|
||||
|
||||
dev_dbg(&phy->udev->dev, "%s\n", __func__);
|
||||
|
||||
buffer = kmemdup(cmd, sizeof(cmd), GFP_KERNEL);
|
||||
if (!buffer)
|
||||
return -ENOMEM;
|
||||
|
||||
init_completion(&arg.done);
|
||||
cntx = phy->in_urb->context; /* backup context */
|
||||
|
||||
phy->in_urb->complete = pn533_acr122_poweron_rdr_resp;
|
||||
phy->in_urb->context = &arg;
|
||||
|
||||
phy->out_urb->transfer_buffer = cmd;
|
||||
phy->out_urb->transfer_buffer_length = sizeof(cmd);
|
||||
|
||||
print_hex_dump_debug("ACR122 TX: ", DUMP_PREFIX_NONE, 16, 1,
|
||||
cmd, sizeof(cmd), false);
|
||||
|
||||
rc = usb_submit_urb(phy->out_urb, GFP_KERNEL);
|
||||
if (rc) {
|
||||
rc = usb_bulk_msg(phy->udev, phy->out_urb->pipe, buffer, sizeof(cmd),
|
||||
&transferred, 0);
|
||||
kfree(buffer);
|
||||
if (rc || (transferred != sizeof(cmd))) {
|
||||
nfc_err(&phy->udev->dev,
|
||||
"Reader power on cmd error %d\n", rc);
|
||||
return rc;
|
||||
|
@ -490,8 +501,9 @@ static int pn533_usb_probe(struct usb_interface *interface,
|
|||
|
||||
phy->in_urb = usb_alloc_urb(0, GFP_KERNEL);
|
||||
phy->out_urb = usb_alloc_urb(0, GFP_KERNEL);
|
||||
phy->ack_urb = usb_alloc_urb(0, GFP_KERNEL);
|
||||
|
||||
if (!phy->in_urb || !phy->out_urb)
|
||||
if (!phy->in_urb || !phy->out_urb || !phy->ack_urb)
|
||||
goto error;
|
||||
|
||||
usb_fill_bulk_urb(phy->in_urb, phy->udev,
|
||||
|
@ -501,7 +513,9 @@ static int pn533_usb_probe(struct usb_interface *interface,
|
|||
usb_fill_bulk_urb(phy->out_urb, phy->udev,
|
||||
usb_sndbulkpipe(phy->udev, out_endpoint),
|
||||
NULL, 0, pn533_send_complete, phy);
|
||||
|
||||
usb_fill_bulk_urb(phy->ack_urb, phy->udev,
|
||||
usb_sndbulkpipe(phy->udev, out_endpoint),
|
||||
NULL, 0, pn533_send_complete, phy);
|
||||
|
||||
switch (id->driver_info) {
|
||||
case PN533_DEVICE_STD:
|
||||
|
@ -554,6 +568,7 @@ static int pn533_usb_probe(struct usb_interface *interface,
|
|||
error:
|
||||
usb_free_urb(phy->in_urb);
|
||||
usb_free_urb(phy->out_urb);
|
||||
usb_free_urb(phy->ack_urb);
|
||||
usb_put_dev(phy->udev);
|
||||
kfree(in_buf);
|
||||
|
||||
|
@ -573,10 +588,13 @@ static void pn533_usb_disconnect(struct usb_interface *interface)
|
|||
|
||||
usb_kill_urb(phy->in_urb);
|
||||
usb_kill_urb(phy->out_urb);
|
||||
usb_kill_urb(phy->ack_urb);
|
||||
|
||||
kfree(phy->in_urb->transfer_buffer);
|
||||
usb_free_urb(phy->in_urb);
|
||||
usb_free_urb(phy->out_urb);
|
||||
usb_free_urb(phy->ack_urb);
|
||||
kfree(phy->ack_buffer);
|
||||
|
||||
nfc_info(&interface->dev, "NXP PN533 NFC device disconnected\n");
|
||||
}
|
||||
|
|
|
@ -12,3 +12,12 @@ config PHY_MTK_TPHY
|
|||
different banks layout, the T-PHY with shared banks between
|
||||
multi-ports is first version, otherwise is second veriosn,
|
||||
so you can easily distinguish them by banks layout.
|
||||
|
||||
config PHY_MTK_XSPHY
|
||||
tristate "MediaTek XS-PHY Driver"
|
||||
depends on ARCH_MEDIATEK && OF
|
||||
select GENERIC_PHY
|
||||
help
|
||||
Enable this to support the SuperSpeedPlus XS-PHY transceiver for
|
||||
USB3.1 GEN2 controllers on MediaTek chips. The driver supports
|
||||
multiple USB2.0, USB3.1 GEN2 ports.
|
||||
|
|
|
@ -3,3 +3,4 @@
|
|||
#
|
||||
|
||||
obj-$(CONFIG_PHY_MTK_TPHY) += phy-mtk-tphy.o
|
||||
obj-$(CONFIG_PHY_MTK_XSPHY) += phy-mtk-xsphy.o
|
||||
|
|
600
drivers/phy/mediatek/phy-mtk-xsphy.c
Normal file
600
drivers/phy/mediatek/phy-mtk-xsphy.c
Normal file
|
@ -0,0 +1,600 @@
|
|||
// SPDX-License-Identifier: GPL-2.0
|
||||
/*
|
||||
* MediaTek USB3.1 gen2 xsphy Driver
|
||||
*
|
||||
* Copyright (c) 2018 MediaTek Inc.
|
||||
* Author: Chunfeng Yun <chunfeng.yun@mediatek.com>
|
||||
*
|
||||
*/
|
||||
|
||||
#include <dt-bindings/phy/phy.h>
|
||||
#include <linux/clk.h>
|
||||
#include <linux/delay.h>
|
||||
#include <linux/io.h>
|
||||
#include <linux/iopoll.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/of_address.h>
|
||||
#include <linux/phy/phy.h>
|
||||
#include <linux/platform_device.h>
|
||||
|
||||
/* u2 phy banks */
|
||||
#define SSUSB_SIFSLV_MISC 0x000
|
||||
#define SSUSB_SIFSLV_U2FREQ 0x100
|
||||
#define SSUSB_SIFSLV_U2PHY_COM 0x300
|
||||
|
||||
/* u3 phy shared banks */
|
||||
#define SSPXTP_SIFSLV_DIG_GLB 0x000
|
||||
#define SSPXTP_SIFSLV_PHYA_GLB 0x100
|
||||
|
||||
/* u3 phy banks */
|
||||
#define SSPXTP_SIFSLV_DIG_LN_TOP 0x000
|
||||
#define SSPXTP_SIFSLV_DIG_LN_TX0 0x100
|
||||
#define SSPXTP_SIFSLV_DIG_LN_RX0 0x200
|
||||
#define SSPXTP_SIFSLV_DIG_LN_DAIF 0x300
|
||||
#define SSPXTP_SIFSLV_PHYA_LN 0x400
|
||||
|
||||
#define XSP_U2FREQ_FMCR0 ((SSUSB_SIFSLV_U2FREQ) + 0x00)
|
||||
#define P2F_RG_FREQDET_EN BIT(24)
|
||||
#define P2F_RG_CYCLECNT GENMASK(23, 0)
|
||||
#define P2F_RG_CYCLECNT_VAL(x) ((P2F_RG_CYCLECNT) & (x))
|
||||
|
||||
#define XSP_U2FREQ_MMONR0 ((SSUSB_SIFSLV_U2FREQ) + 0x0c)
|
||||
|
||||
#define XSP_U2FREQ_FMMONR1 ((SSUSB_SIFSLV_U2FREQ) + 0x10)
|
||||
#define P2F_RG_FRCK_EN BIT(8)
|
||||
#define P2F_USB_FM_VALID BIT(0)
|
||||
|
||||
#define XSP_USBPHYACR0 ((SSUSB_SIFSLV_U2PHY_COM) + 0x00)
|
||||
#define P2A0_RG_INTR_EN BIT(5)
|
||||
|
||||
#define XSP_USBPHYACR1 ((SSUSB_SIFSLV_U2PHY_COM) + 0x04)
|
||||
#define P2A1_RG_INTR_CAL GENMASK(23, 19)
|
||||
#define P2A1_RG_INTR_CAL_VAL(x) ((0x1f & (x)) << 19)
|
||||
#define P2A1_RG_VRT_SEL GENMASK(14, 12)
|
||||
#define P2A1_RG_VRT_SEL_VAL(x) ((0x7 & (x)) << 12)
|
||||
#define P2A1_RG_TERM_SEL GENMASK(10, 8)
|
||||
#define P2A1_RG_TERM_SEL_VAL(x) ((0x7 & (x)) << 8)
|
||||
|
||||
#define XSP_USBPHYACR5 ((SSUSB_SIFSLV_U2PHY_COM) + 0x014)
|
||||
#define P2A5_RG_HSTX_SRCAL_EN BIT(15)
|
||||
#define P2A5_RG_HSTX_SRCTRL GENMASK(14, 12)
|
||||
#define P2A5_RG_HSTX_SRCTRL_VAL(x) ((0x7 & (x)) << 12)
|
||||
|
||||
#define XSP_USBPHYACR6 ((SSUSB_SIFSLV_U2PHY_COM) + 0x018)
|
||||
#define P2A6_RG_BC11_SW_EN BIT(23)
|
||||
#define P2A6_RG_OTG_VBUSCMP_EN BIT(20)
|
||||
|
||||
#define XSP_U2PHYDTM1 ((SSUSB_SIFSLV_U2PHY_COM) + 0x06C)
|
||||
#define P2D_FORCE_IDDIG BIT(9)
|
||||
#define P2D_RG_VBUSVALID BIT(5)
|
||||
#define P2D_RG_SESSEND BIT(4)
|
||||
#define P2D_RG_AVALID BIT(2)
|
||||
#define P2D_RG_IDDIG BIT(1)
|
||||
|
||||
#define SSPXTP_PHYA_GLB_00 ((SSPXTP_SIFSLV_PHYA_GLB) + 0x00)
|
||||
#define RG_XTP_GLB_BIAS_INTR_CTRL GENMASK(21, 16)
|
||||
#define RG_XTP_GLB_BIAS_INTR_CTRL_VAL(x) ((0x3f & (x)) << 16)
|
||||
|
||||
#define SSPXTP_PHYA_LN_04 ((SSPXTP_SIFSLV_PHYA_LN) + 0x04)
|
||||
#define RG_XTP_LN0_TX_IMPSEL GENMASK(4, 0)
|
||||
#define RG_XTP_LN0_TX_IMPSEL_VAL(x) (0x1f & (x))
|
||||
|
||||
#define SSPXTP_PHYA_LN_14 ((SSPXTP_SIFSLV_PHYA_LN) + 0x014)
|
||||
#define RG_XTP_LN0_RX_IMPSEL GENMASK(4, 0)
|
||||
#define RG_XTP_LN0_RX_IMPSEL_VAL(x) (0x1f & (x))
|
||||
|
||||
#define XSP_REF_CLK 26 /* MHZ */
|
||||
#define XSP_SLEW_RATE_COEF 17
|
||||
#define XSP_SR_COEF_DIVISOR 1000
|
||||
#define XSP_FM_DET_CYCLE_CNT 1024
|
||||
|
||||
struct xsphy_instance {
|
||||
struct phy *phy;
|
||||
void __iomem *port_base;
|
||||
struct clk *ref_clk; /* reference clock of anolog phy */
|
||||
u32 index;
|
||||
u32 type;
|
||||
/* only for HQA test */
|
||||
int efuse_intr;
|
||||
int efuse_tx_imp;
|
||||
int efuse_rx_imp;
|
||||
/* u2 eye diagram */
|
||||
int eye_src;
|
||||
int eye_vrt;
|
||||
int eye_term;
|
||||
};
|
||||
|
||||
struct mtk_xsphy {
|
||||
struct device *dev;
|
||||
void __iomem *glb_base; /* only shared u3 sif */
|
||||
struct xsphy_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 u2_phy_slew_rate_calibrate(struct mtk_xsphy *xsphy,
|
||||
struct xsphy_instance *inst)
|
||||
{
|
||||
void __iomem *pbase = inst->port_base;
|
||||
int calib_val;
|
||||
int fm_out;
|
||||
u32 tmp;
|
||||
|
||||
/* use force value */
|
||||
if (inst->eye_src)
|
||||
return;
|
||||
|
||||
/* enable USB ring oscillator */
|
||||
tmp = readl(pbase + XSP_USBPHYACR5);
|
||||
tmp |= P2A5_RG_HSTX_SRCAL_EN;
|
||||
writel(tmp, pbase + XSP_USBPHYACR5);
|
||||
udelay(1); /* wait clock stable */
|
||||
|
||||
/* enable free run clock */
|
||||
tmp = readl(pbase + XSP_U2FREQ_FMMONR1);
|
||||
tmp |= P2F_RG_FRCK_EN;
|
||||
writel(tmp, pbase + XSP_U2FREQ_FMMONR1);
|
||||
|
||||
/* set cycle count as 1024 */
|
||||
tmp = readl(pbase + XSP_U2FREQ_FMCR0);
|
||||
tmp &= ~(P2F_RG_CYCLECNT);
|
||||
tmp |= P2F_RG_CYCLECNT_VAL(XSP_FM_DET_CYCLE_CNT);
|
||||
writel(tmp, pbase + XSP_U2FREQ_FMCR0);
|
||||
|
||||
/* enable frequency meter */
|
||||
tmp = readl(pbase + XSP_U2FREQ_FMCR0);
|
||||
tmp |= P2F_RG_FREQDET_EN;
|
||||
writel(tmp, pbase + XSP_U2FREQ_FMCR0);
|
||||
|
||||
/* ignore return value */
|
||||
readl_poll_timeout(pbase + XSP_U2FREQ_FMMONR1, tmp,
|
||||
(tmp & P2F_USB_FM_VALID), 10, 200);
|
||||
|
||||
fm_out = readl(pbase + XSP_U2FREQ_MMONR0);
|
||||
|
||||
/* disable frequency meter */
|
||||
tmp = readl(pbase + XSP_U2FREQ_FMCR0);
|
||||
tmp &= ~P2F_RG_FREQDET_EN;
|
||||
writel(tmp, pbase + XSP_U2FREQ_FMCR0);
|
||||
|
||||
/* disable free run clock */
|
||||
tmp = readl(pbase + XSP_U2FREQ_FMMONR1);
|
||||
tmp &= ~P2F_RG_FRCK_EN;
|
||||
writel(tmp, pbase + XSP_U2FREQ_FMMONR1);
|
||||
|
||||
if (fm_out) {
|
||||
/* (1024 / FM_OUT) x reference clock frequency x coefficient */
|
||||
tmp = xsphy->src_ref_clk * xsphy->src_coef;
|
||||
tmp = (tmp * XSP_FM_DET_CYCLE_CNT) / fm_out;
|
||||
calib_val = DIV_ROUND_CLOSEST(tmp, XSP_SR_COEF_DIVISOR);
|
||||
} else {
|
||||
/* if FM detection fail, set default value */
|
||||
calib_val = 3;
|
||||
}
|
||||
dev_dbg(xsphy->dev, "phy.%d, fm_out:%d, calib:%d (clk:%d, coef:%d)\n",
|
||||
inst->index, fm_out, calib_val,
|
||||
xsphy->src_ref_clk, xsphy->src_coef);
|
||||
|
||||
/* set HS slew rate */
|
||||
tmp = readl(pbase + XSP_USBPHYACR5);
|
||||
tmp &= ~P2A5_RG_HSTX_SRCTRL;
|
||||
tmp |= P2A5_RG_HSTX_SRCTRL_VAL(calib_val);
|
||||
writel(tmp, pbase + XSP_USBPHYACR5);
|
||||
|
||||
/* disable USB ring oscillator */
|
||||
tmp = readl(pbase + XSP_USBPHYACR5);
|
||||
tmp &= ~P2A5_RG_HSTX_SRCAL_EN;
|
||||
writel(tmp, pbase + XSP_USBPHYACR5);
|
||||
}
|
||||
|
||||
static void u2_phy_instance_init(struct mtk_xsphy *xsphy,
|
||||
struct xsphy_instance *inst)
|
||||
{
|
||||
void __iomem *pbase = inst->port_base;
|
||||
u32 tmp;
|
||||
|
||||
/* DP/DM BC1.1 path Disable */
|
||||
tmp = readl(pbase + XSP_USBPHYACR6);
|
||||
tmp &= ~P2A6_RG_BC11_SW_EN;
|
||||
writel(tmp, pbase + XSP_USBPHYACR6);
|
||||
|
||||
tmp = readl(pbase + XSP_USBPHYACR0);
|
||||
tmp |= P2A0_RG_INTR_EN;
|
||||
writel(tmp, pbase + XSP_USBPHYACR0);
|
||||
}
|
||||
|
||||
static void u2_phy_instance_power_on(struct mtk_xsphy *xsphy,
|
||||
struct xsphy_instance *inst)
|
||||
{
|
||||
void __iomem *pbase = inst->port_base;
|
||||
u32 index = inst->index;
|
||||
u32 tmp;
|
||||
|
||||
tmp = readl(pbase + XSP_USBPHYACR6);
|
||||
tmp |= P2A6_RG_OTG_VBUSCMP_EN;
|
||||
writel(tmp, pbase + XSP_USBPHYACR6);
|
||||
|
||||
tmp = readl(pbase + XSP_U2PHYDTM1);
|
||||
tmp |= P2D_RG_VBUSVALID | P2D_RG_AVALID;
|
||||
tmp &= ~P2D_RG_SESSEND;
|
||||
writel(tmp, pbase + XSP_U2PHYDTM1);
|
||||
|
||||
dev_dbg(xsphy->dev, "%s(%d)\n", __func__, index);
|
||||
}
|
||||
|
||||
static void u2_phy_instance_power_off(struct mtk_xsphy *xsphy,
|
||||
struct xsphy_instance *inst)
|
||||
{
|
||||
void __iomem *pbase = inst->port_base;
|
||||
u32 index = inst->index;
|
||||
u32 tmp;
|
||||
|
||||
tmp = readl(pbase + XSP_USBPHYACR6);
|
||||
tmp &= ~P2A6_RG_OTG_VBUSCMP_EN;
|
||||
writel(tmp, pbase + XSP_USBPHYACR6);
|
||||
|
||||
tmp = readl(pbase + XSP_U2PHYDTM1);
|
||||
tmp &= ~(P2D_RG_VBUSVALID | P2D_RG_AVALID);
|
||||
tmp |= P2D_RG_SESSEND;
|
||||
writel(tmp, pbase + XSP_U2PHYDTM1);
|
||||
|
||||
dev_dbg(xsphy->dev, "%s(%d)\n", __func__, index);
|
||||
}
|
||||
|
||||
static void u2_phy_instance_set_mode(struct mtk_xsphy *xsphy,
|
||||
struct xsphy_instance *inst,
|
||||
enum phy_mode mode)
|
||||
{
|
||||
u32 tmp;
|
||||
|
||||
tmp = readl(inst->port_base + XSP_U2PHYDTM1);
|
||||
switch (mode) {
|
||||
case PHY_MODE_USB_DEVICE:
|
||||
tmp |= P2D_FORCE_IDDIG | P2D_RG_IDDIG;
|
||||
break;
|
||||
case PHY_MODE_USB_HOST:
|
||||
tmp |= P2D_FORCE_IDDIG;
|
||||
tmp &= ~P2D_RG_IDDIG;
|
||||
break;
|
||||
case PHY_MODE_USB_OTG:
|
||||
tmp &= ~(P2D_FORCE_IDDIG | P2D_RG_IDDIG);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
writel(tmp, inst->port_base + XSP_U2PHYDTM1);
|
||||
}
|
||||
|
||||
static void phy_parse_property(struct mtk_xsphy *xsphy,
|
||||
struct xsphy_instance *inst)
|
||||
{
|
||||
struct device *dev = &inst->phy->dev;
|
||||
|
||||
switch (inst->type) {
|
||||
case PHY_TYPE_USB2:
|
||||
device_property_read_u32(dev, "mediatek,efuse-intr",
|
||||
&inst->efuse_intr);
|
||||
device_property_read_u32(dev, "mediatek,eye-src",
|
||||
&inst->eye_src);
|
||||
device_property_read_u32(dev, "mediatek,eye-vrt",
|
||||
&inst->eye_vrt);
|
||||
device_property_read_u32(dev, "mediatek,eye-term",
|
||||
&inst->eye_term);
|
||||
dev_dbg(dev, "intr:%d, src:%d, vrt:%d, term:%d\n",
|
||||
inst->efuse_intr, inst->eye_src,
|
||||
inst->eye_vrt, inst->eye_term);
|
||||
break;
|
||||
case PHY_TYPE_USB3:
|
||||
device_property_read_u32(dev, "mediatek,efuse-intr",
|
||||
&inst->efuse_intr);
|
||||
device_property_read_u32(dev, "mediatek,efuse-tx-imp",
|
||||
&inst->efuse_tx_imp);
|
||||
device_property_read_u32(dev, "mediatek,efuse-rx-imp",
|
||||
&inst->efuse_rx_imp);
|
||||
dev_dbg(dev, "intr:%d, tx-imp:%d, rx-imp:%d\n",
|
||||
inst->efuse_intr, inst->efuse_tx_imp,
|
||||
inst->efuse_rx_imp);
|
||||
break;
|
||||
default:
|
||||
dev_err(xsphy->dev, "incompatible phy type\n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
static void u2_phy_props_set(struct mtk_xsphy *xsphy,
|
||||
struct xsphy_instance *inst)
|
||||
{
|
||||
void __iomem *pbase = inst->port_base;
|
||||
u32 tmp;
|
||||
|
||||
if (inst->efuse_intr) {
|
||||
tmp = readl(pbase + XSP_USBPHYACR1);
|
||||
tmp &= ~P2A1_RG_INTR_CAL;
|
||||
tmp |= P2A1_RG_INTR_CAL_VAL(inst->efuse_intr);
|
||||
writel(tmp, pbase + XSP_USBPHYACR1);
|
||||
}
|
||||
|
||||
if (inst->eye_src) {
|
||||
tmp = readl(pbase + XSP_USBPHYACR5);
|
||||
tmp &= ~P2A5_RG_HSTX_SRCTRL;
|
||||
tmp |= P2A5_RG_HSTX_SRCTRL_VAL(inst->eye_src);
|
||||
writel(tmp, pbase + XSP_USBPHYACR5);
|
||||
}
|
||||
|
||||
if (inst->eye_vrt) {
|
||||
tmp = readl(pbase + XSP_USBPHYACR1);
|
||||
tmp &= ~P2A1_RG_VRT_SEL;
|
||||
tmp |= P2A1_RG_VRT_SEL_VAL(inst->eye_vrt);
|
||||
writel(tmp, pbase + XSP_USBPHYACR1);
|
||||
}
|
||||
|
||||
if (inst->eye_term) {
|
||||
tmp = readl(pbase + XSP_USBPHYACR1);
|
||||
tmp &= ~P2A1_RG_TERM_SEL;
|
||||
tmp |= P2A1_RG_TERM_SEL_VAL(inst->eye_term);
|
||||
writel(tmp, pbase + XSP_USBPHYACR1);
|
||||
}
|
||||
}
|
||||
|
||||
static void u3_phy_props_set(struct mtk_xsphy *xsphy,
|
||||
struct xsphy_instance *inst)
|
||||
{
|
||||
void __iomem *pbase = inst->port_base;
|
||||
u32 tmp;
|
||||
|
||||
if (inst->efuse_intr) {
|
||||
tmp = readl(xsphy->glb_base + SSPXTP_PHYA_GLB_00);
|
||||
tmp &= ~RG_XTP_GLB_BIAS_INTR_CTRL;
|
||||
tmp |= RG_XTP_GLB_BIAS_INTR_CTRL_VAL(inst->efuse_intr);
|
||||
writel(tmp, xsphy->glb_base + SSPXTP_PHYA_GLB_00);
|
||||
}
|
||||
|
||||
if (inst->efuse_tx_imp) {
|
||||
tmp = readl(pbase + SSPXTP_PHYA_LN_04);
|
||||
tmp &= ~RG_XTP_LN0_TX_IMPSEL;
|
||||
tmp |= RG_XTP_LN0_TX_IMPSEL_VAL(inst->efuse_tx_imp);
|
||||
writel(tmp, pbase + SSPXTP_PHYA_LN_04);
|
||||
}
|
||||
|
||||
if (inst->efuse_rx_imp) {
|
||||
tmp = readl(pbase + SSPXTP_PHYA_LN_14);
|
||||
tmp &= ~RG_XTP_LN0_RX_IMPSEL;
|
||||
tmp |= RG_XTP_LN0_RX_IMPSEL_VAL(inst->efuse_rx_imp);
|
||||
writel(tmp, pbase + SSPXTP_PHYA_LN_14);
|
||||
}
|
||||
}
|
||||
|
||||
static int mtk_phy_init(struct phy *phy)
|
||||
{
|
||||
struct xsphy_instance *inst = phy_get_drvdata(phy);
|
||||
struct mtk_xsphy *xsphy = dev_get_drvdata(phy->dev.parent);
|
||||
int ret;
|
||||
|
||||
ret = clk_prepare_enable(inst->ref_clk);
|
||||
if (ret) {
|
||||
dev_err(xsphy->dev, "failed to enable ref_clk\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
switch (inst->type) {
|
||||
case PHY_TYPE_USB2:
|
||||
u2_phy_instance_init(xsphy, inst);
|
||||
u2_phy_props_set(xsphy, inst);
|
||||
break;
|
||||
case PHY_TYPE_USB3:
|
||||
u3_phy_props_set(xsphy, inst);
|
||||
break;
|
||||
default:
|
||||
dev_err(xsphy->dev, "incompatible phy type\n");
|
||||
clk_disable_unprepare(inst->ref_clk);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int mtk_phy_power_on(struct phy *phy)
|
||||
{
|
||||
struct xsphy_instance *inst = phy_get_drvdata(phy);
|
||||
struct mtk_xsphy *xsphy = dev_get_drvdata(phy->dev.parent);
|
||||
|
||||
if (inst->type == PHY_TYPE_USB2) {
|
||||
u2_phy_instance_power_on(xsphy, inst);
|
||||
u2_phy_slew_rate_calibrate(xsphy, inst);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int mtk_phy_power_off(struct phy *phy)
|
||||
{
|
||||
struct xsphy_instance *inst = phy_get_drvdata(phy);
|
||||
struct mtk_xsphy *xsphy = dev_get_drvdata(phy->dev.parent);
|
||||
|
||||
if (inst->type == PHY_TYPE_USB2)
|
||||
u2_phy_instance_power_off(xsphy, inst);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int mtk_phy_exit(struct phy *phy)
|
||||
{
|
||||
struct xsphy_instance *inst = phy_get_drvdata(phy);
|
||||
|
||||
clk_disable_unprepare(inst->ref_clk);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int mtk_phy_set_mode(struct phy *phy, enum phy_mode mode)
|
||||
{
|
||||
struct xsphy_instance *inst = phy_get_drvdata(phy);
|
||||
struct mtk_xsphy *xsphy = dev_get_drvdata(phy->dev.parent);
|
||||
|
||||
if (inst->type == PHY_TYPE_USB2)
|
||||
u2_phy_instance_set_mode(xsphy, inst, mode);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct phy *mtk_phy_xlate(struct device *dev,
|
||||
struct of_phandle_args *args)
|
||||
{
|
||||
struct mtk_xsphy *xsphy = dev_get_drvdata(dev);
|
||||
struct xsphy_instance *inst = NULL;
|
||||
struct device_node *phy_np = args->np;
|
||||
int index;
|
||||
|
||||
if (args->args_count != 1) {
|
||||
dev_err(dev, "invalid number of cells in 'phy' property\n");
|
||||
return ERR_PTR(-EINVAL);
|
||||
}
|
||||
|
||||
for (index = 0; index < xsphy->nphys; index++)
|
||||
if (phy_np == xsphy->phys[index]->phy->dev.of_node) {
|
||||
inst = xsphy->phys[index];
|
||||
break;
|
||||
}
|
||||
|
||||
if (!inst) {
|
||||
dev_err(dev, "failed to find appropriate phy\n");
|
||||
return ERR_PTR(-EINVAL);
|
||||
}
|
||||
|
||||
inst->type = args->args[0];
|
||||
if (!(inst->type == PHY_TYPE_USB2 ||
|
||||
inst->type == PHY_TYPE_USB3)) {
|
||||
dev_err(dev, "unsupported phy type: %d\n", inst->type);
|
||||
return ERR_PTR(-EINVAL);
|
||||
}
|
||||
|
||||
phy_parse_property(xsphy, inst);
|
||||
|
||||
return inst->phy;
|
||||
}
|
||||
|
||||
static const struct phy_ops mtk_xsphy_ops = {
|
||||
.init = mtk_phy_init,
|
||||
.exit = mtk_phy_exit,
|
||||
.power_on = mtk_phy_power_on,
|
||||
.power_off = mtk_phy_power_off,
|
||||
.set_mode = mtk_phy_set_mode,
|
||||
.owner = THIS_MODULE,
|
||||
};
|
||||
|
||||
static const struct of_device_id mtk_xsphy_id_table[] = {
|
||||
{ .compatible = "mediatek,xsphy", },
|
||||
{ },
|
||||
};
|
||||
MODULE_DEVICE_TABLE(of, mtk_xsphy_id_table);
|
||||
|
||||
static int mtk_xsphy_probe(struct platform_device *pdev)
|
||||
{
|
||||
struct device *dev = &pdev->dev;
|
||||
struct device_node *np = dev->of_node;
|
||||
struct device_node *child_np;
|
||||
struct phy_provider *provider;
|
||||
struct resource *glb_res;
|
||||
struct mtk_xsphy *xsphy;
|
||||
struct resource res;
|
||||
int port, retval;
|
||||
|
||||
xsphy = devm_kzalloc(dev, sizeof(*xsphy), GFP_KERNEL);
|
||||
if (!xsphy)
|
||||
return -ENOMEM;
|
||||
|
||||
xsphy->nphys = of_get_child_count(np);
|
||||
xsphy->phys = devm_kcalloc(dev, xsphy->nphys,
|
||||
sizeof(*xsphy->phys), GFP_KERNEL);
|
||||
if (!xsphy->phys)
|
||||
return -ENOMEM;
|
||||
|
||||
xsphy->dev = dev;
|
||||
platform_set_drvdata(pdev, xsphy);
|
||||
|
||||
glb_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
||||
/* optional, may not exist if no u3 phys */
|
||||
if (glb_res) {
|
||||
/* get banks shared by multiple u3 phys */
|
||||
xsphy->glb_base = devm_ioremap_resource(dev, glb_res);
|
||||
if (IS_ERR(xsphy->glb_base)) {
|
||||
dev_err(dev, "failed to remap glb regs\n");
|
||||
return PTR_ERR(xsphy->glb_base);
|
||||
}
|
||||
}
|
||||
|
||||
xsphy->src_ref_clk = XSP_REF_CLK;
|
||||
xsphy->src_coef = XSP_SLEW_RATE_COEF;
|
||||
/* update parameters of slew rate calibrate if exist */
|
||||
device_property_read_u32(dev, "mediatek,src-ref-clk-mhz",
|
||||
&xsphy->src_ref_clk);
|
||||
device_property_read_u32(dev, "mediatek,src-coef", &xsphy->src_coef);
|
||||
|
||||
port = 0;
|
||||
for_each_child_of_node(np, child_np) {
|
||||
struct xsphy_instance *inst;
|
||||
struct phy *phy;
|
||||
|
||||
inst = devm_kzalloc(dev, sizeof(*inst), GFP_KERNEL);
|
||||
if (!inst) {
|
||||
retval = -ENOMEM;
|
||||
goto put_child;
|
||||
}
|
||||
|
||||
xsphy->phys[port] = inst;
|
||||
|
||||
phy = devm_phy_create(dev, child_np, &mtk_xsphy_ops);
|
||||
if (IS_ERR(phy)) {
|
||||
dev_err(dev, "failed to create phy\n");
|
||||
retval = PTR_ERR(phy);
|
||||
goto put_child;
|
||||
}
|
||||
|
||||
retval = of_address_to_resource(child_np, 0, &res);
|
||||
if (retval) {
|
||||
dev_err(dev, "failed to get address resource(id-%d)\n",
|
||||
port);
|
||||
goto put_child;
|
||||
}
|
||||
|
||||
inst->port_base = devm_ioremap_resource(&phy->dev, &res);
|
||||
if (IS_ERR(inst->port_base)) {
|
||||
dev_err(dev, "failed to remap phy regs\n");
|
||||
retval = PTR_ERR(inst->port_base);
|
||||
goto put_child;
|
||||
}
|
||||
|
||||
inst->phy = phy;
|
||||
inst->index = port;
|
||||
phy_set_drvdata(phy, inst);
|
||||
port++;
|
||||
|
||||
inst->ref_clk = devm_clk_get(&phy->dev, "ref");
|
||||
if (IS_ERR(inst->ref_clk)) {
|
||||
dev_err(dev, "failed to get ref_clk(id-%d)\n", port);
|
||||
retval = PTR_ERR(inst->ref_clk);
|
||||
goto put_child;
|
||||
}
|
||||
}
|
||||
|
||||
provider = devm_of_phy_provider_register(dev, mtk_phy_xlate);
|
||||
return PTR_ERR_OR_ZERO(provider);
|
||||
|
||||
put_child:
|
||||
of_node_put(child_np);
|
||||
return retval;
|
||||
}
|
||||
|
||||
static struct platform_driver mtk_xsphy_driver = {
|
||||
.probe = mtk_xsphy_probe,
|
||||
.driver = {
|
||||
.name = "mtk-xsphy",
|
||||
.of_match_table = mtk_xsphy_id_table,
|
||||
},
|
||||
};
|
||||
|
||||
module_platform_driver(mtk_xsphy_driver);
|
||||
|
||||
MODULE_AUTHOR("Chunfeng Yun <chunfeng.yun@mediatek.com>");
|
||||
MODULE_DESCRIPTION("MediaTek USB XS-PHY driver");
|
||||
MODULE_LICENSE("GPL v2");
|
|
@ -19,6 +19,8 @@
|
|||
|
||||
#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 */
|
||||
#define MDM6600_MODEM_IDLE_DELAY_MS 1000 /* modem after USB suspend */
|
||||
#define MDM6600_MODEM_WAKE_DELAY_MS 200 /* modem response after idle */
|
||||
|
||||
enum phy_mdm6600_ctrl_lines {
|
||||
PHY_MDM6600_ENABLE, /* USB PHY enable */
|
||||
|
@ -93,9 +95,11 @@ struct phy_mdm6600 {
|
|||
struct gpio_descs *cmd_gpios;
|
||||
struct delayed_work bootup_work;
|
||||
struct delayed_work status_work;
|
||||
struct delayed_work modem_wake_work;
|
||||
struct completion ack;
|
||||
bool enabled; /* mdm6600 phy enabled */
|
||||
bool running; /* mdm6600 boot done */
|
||||
bool awake; /* mdm6600 respnds on n_gsm */
|
||||
int status;
|
||||
};
|
||||
|
||||
|
@ -446,6 +450,62 @@ static void phy_mdm6600_deferred_power_on(struct work_struct *work)
|
|||
dev_err(ddata->dev, "Device not functional\n");
|
||||
}
|
||||
|
||||
/*
|
||||
* USB suspend puts mdm6600 into low power mode. For any n_gsm using apps,
|
||||
* we need to keep the modem awake by kicking it's mode0 GPIO. This will
|
||||
* keep the modem awake for about 1.2 seconds. When no n_gsm apps are using
|
||||
* the modem, runtime PM auto mode can be enabled so modem can enter low
|
||||
* power mode.
|
||||
*/
|
||||
static void phy_mdm6600_wake_modem(struct phy_mdm6600 *ddata)
|
||||
{
|
||||
struct gpio_desc *mode_gpio0;
|
||||
|
||||
mode_gpio0 = ddata->mode_gpios->desc[PHY_MDM6600_MODE0];
|
||||
gpiod_set_value_cansleep(mode_gpio0, 1);
|
||||
usleep_range(5, 15);
|
||||
gpiod_set_value_cansleep(mode_gpio0, 0);
|
||||
if (ddata->awake)
|
||||
usleep_range(5, 15);
|
||||
else
|
||||
msleep(MDM6600_MODEM_WAKE_DELAY_MS);
|
||||
}
|
||||
|
||||
static void phy_mdm6600_modem_wake(struct work_struct *work)
|
||||
{
|
||||
struct phy_mdm6600 *ddata;
|
||||
|
||||
ddata = container_of(work, struct phy_mdm6600, modem_wake_work.work);
|
||||
phy_mdm6600_wake_modem(ddata);
|
||||
schedule_delayed_work(&ddata->modem_wake_work,
|
||||
msecs_to_jiffies(MDM6600_MODEM_IDLE_DELAY_MS));
|
||||
}
|
||||
|
||||
static int __maybe_unused phy_mdm6600_runtime_suspend(struct device *dev)
|
||||
{
|
||||
struct phy_mdm6600 *ddata = dev_get_drvdata(dev);
|
||||
|
||||
cancel_delayed_work_sync(&ddata->modem_wake_work);
|
||||
ddata->awake = false;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int __maybe_unused phy_mdm6600_runtime_resume(struct device *dev)
|
||||
{
|
||||
struct phy_mdm6600 *ddata = dev_get_drvdata(dev);
|
||||
|
||||
phy_mdm6600_modem_wake(&ddata->modem_wake_work.work);
|
||||
ddata->awake = true;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct dev_pm_ops phy_mdm6600_pm_ops = {
|
||||
SET_RUNTIME_PM_OPS(phy_mdm6600_runtime_suspend,
|
||||
phy_mdm6600_runtime_resume, NULL)
|
||||
};
|
||||
|
||||
static const struct of_device_id phy_mdm6600_id_table[] = {
|
||||
{ .compatible = "motorola,mapphone-mdm6600", },
|
||||
{},
|
||||
|
@ -464,6 +524,7 @@ static int phy_mdm6600_probe(struct platform_device *pdev)
|
|||
INIT_DELAYED_WORK(&ddata->bootup_work,
|
||||
phy_mdm6600_deferred_power_on);
|
||||
INIT_DELAYED_WORK(&ddata->status_work, phy_mdm6600_status);
|
||||
INIT_DELAYED_WORK(&ddata->modem_wake_work, phy_mdm6600_modem_wake);
|
||||
init_completion(&ddata->ack);
|
||||
|
||||
ddata->dev = &pdev->dev;
|
||||
|
@ -500,6 +561,24 @@ static int phy_mdm6600_probe(struct platform_device *pdev)
|
|||
*/
|
||||
msleep(PHY_MDM6600_PHY_DELAY_MS + 500);
|
||||
|
||||
/*
|
||||
* Enable PM runtime only after PHY has been powered up properly.
|
||||
* It is currently only needed after USB suspends mdm6600 and n_gsm
|
||||
* needs to access the device. We don't want to do this earlier as
|
||||
* gpio mode0 pin doubles as mdm6600 wake-up gpio.
|
||||
*/
|
||||
pm_runtime_use_autosuspend(ddata->dev);
|
||||
pm_runtime_set_autosuspend_delay(ddata->dev,
|
||||
MDM6600_MODEM_IDLE_DELAY_MS);
|
||||
pm_runtime_enable(ddata->dev);
|
||||
error = pm_runtime_get_sync(ddata->dev);
|
||||
if (error < 0) {
|
||||
dev_warn(ddata->dev, "failed to wake modem: %i\n", error);
|
||||
pm_runtime_put_noidle(ddata->dev);
|
||||
}
|
||||
pm_runtime_mark_last_busy(ddata->dev);
|
||||
pm_runtime_put_autosuspend(ddata->dev);
|
||||
|
||||
return 0;
|
||||
|
||||
cleanup:
|
||||
|
@ -512,6 +591,10 @@ 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];
|
||||
|
||||
pm_runtime_dont_use_autosuspend(ddata->dev);
|
||||
pm_runtime_put_sync(ddata->dev);
|
||||
pm_runtime_disable(ddata->dev);
|
||||
|
||||
if (!ddata->running)
|
||||
wait_for_completion_timeout(&ddata->ack,
|
||||
msecs_to_jiffies(PHY_MDM6600_ENABLED_DELAY_MS));
|
||||
|
@ -519,6 +602,7 @@ static int phy_mdm6600_remove(struct platform_device *pdev)
|
|||
gpiod_set_value_cansleep(reset_gpio, 1);
|
||||
phy_mdm6600_device_power_off(ddata);
|
||||
|
||||
cancel_delayed_work_sync(&ddata->modem_wake_work);
|
||||
cancel_delayed_work_sync(&ddata->bootup_work);
|
||||
cancel_delayed_work_sync(&ddata->status_work);
|
||||
|
||||
|
@ -530,6 +614,7 @@ static struct platform_driver phy_mdm6600_driver = {
|
|||
.remove = phy_mdm6600_remove,
|
||||
.driver = {
|
||||
.name = "phy-mapphone-mdm6600",
|
||||
.pm = &phy_mdm6600_pm_ops,
|
||||
.of_match_table = of_match_ptr(phy_mdm6600_id_table),
|
||||
},
|
||||
};
|
||||
|
|
|
@ -153,6 +153,9 @@ int phy_pm_runtime_get(struct phy *phy)
|
|||
{
|
||||
int ret;
|
||||
|
||||
if (!phy)
|
||||
return 0;
|
||||
|
||||
if (!pm_runtime_enabled(&phy->dev))
|
||||
return -ENOTSUPP;
|
||||
|
||||
|
@ -168,6 +171,9 @@ int phy_pm_runtime_get_sync(struct phy *phy)
|
|||
{
|
||||
int ret;
|
||||
|
||||
if (!phy)
|
||||
return 0;
|
||||
|
||||
if (!pm_runtime_enabled(&phy->dev))
|
||||
return -ENOTSUPP;
|
||||
|
||||
|
@ -181,6 +187,9 @@ EXPORT_SYMBOL_GPL(phy_pm_runtime_get_sync);
|
|||
|
||||
int phy_pm_runtime_put(struct phy *phy)
|
||||
{
|
||||
if (!phy)
|
||||
return 0;
|
||||
|
||||
if (!pm_runtime_enabled(&phy->dev))
|
||||
return -ENOTSUPP;
|
||||
|
||||
|
@ -190,6 +199,9 @@ EXPORT_SYMBOL_GPL(phy_pm_runtime_put);
|
|||
|
||||
int phy_pm_runtime_put_sync(struct phy *phy)
|
||||
{
|
||||
if (!phy)
|
||||
return 0;
|
||||
|
||||
if (!pm_runtime_enabled(&phy->dev))
|
||||
return -ENOTSUPP;
|
||||
|
||||
|
@ -199,6 +211,9 @@ EXPORT_SYMBOL_GPL(phy_pm_runtime_put_sync);
|
|||
|
||||
void phy_pm_runtime_allow(struct phy *phy)
|
||||
{
|
||||
if (!phy)
|
||||
return;
|
||||
|
||||
if (!pm_runtime_enabled(&phy->dev))
|
||||
return;
|
||||
|
||||
|
@ -208,6 +223,9 @@ EXPORT_SYMBOL_GPL(phy_pm_runtime_allow);
|
|||
|
||||
void phy_pm_runtime_forbid(struct phy *phy)
|
||||
{
|
||||
if (!phy)
|
||||
return;
|
||||
|
||||
if (!pm_runtime_enabled(&phy->dev))
|
||||
return;
|
||||
|
||||
|
|
|
@ -1,6 +1,15 @@
|
|||
#
|
||||
# Phy drivers for Qualcomm platforms
|
||||
# Phy drivers for Qualcomm and Atheros platforms
|
||||
#
|
||||
config PHY_ATH79_USB
|
||||
tristate "Atheros AR71XX/9XXX USB PHY driver"
|
||||
depends on OF && (ATH79 || COMPILE_TEST)
|
||||
default y if USB_EHCI_HCD_PLATFORM || USB_OHCI_HCD_PLATFORM
|
||||
select RESET_CONTROLLER
|
||||
select GENERIC_PHY
|
||||
help
|
||||
Enable this to support the USB PHY on Atheros AR71XX/9XXX SoCs.
|
||||
|
||||
config PHY_QCOM_APQ8064_SATA
|
||||
tristate "Qualcomm APQ8064 SATA SerDes/PHY driver"
|
||||
depends on ARCH_QCOM
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
# SPDX-License-Identifier: GPL-2.0
|
||||
obj-$(CONFIG_PHY_ATH79_USB) += phy-ath79-usb.o
|
||||
obj-$(CONFIG_PHY_QCOM_APQ8064_SATA) += phy-qcom-apq8064-sata.o
|
||||
obj-$(CONFIG_PHY_QCOM_IPQ806X_SATA) += phy-qcom-ipq806x-sata.o
|
||||
obj-$(CONFIG_PHY_QCOM_QMP) += phy-qcom-qmp.o
|
||||
|
|
108
drivers/phy/qualcomm/phy-ath79-usb.c
Normal file
108
drivers/phy/qualcomm/phy-ath79-usb.c
Normal file
|
@ -0,0 +1,108 @@
|
|||
// SPDX-License-Identifier: GPL-2.0+
|
||||
/*
|
||||
* Atheros AR71XX/9XXX USB PHY driver
|
||||
*
|
||||
* Copyright (C) 2015-2018 Alban Bedel <albeu@free.fr>
|
||||
*/
|
||||
|
||||
#include <linux/module.h>
|
||||
#include <linux/platform_device.h>
|
||||
#include <linux/phy/phy.h>
|
||||
#include <linux/reset.h>
|
||||
|
||||
struct ath79_usb_phy {
|
||||
struct reset_control *reset;
|
||||
/* The suspend override logic is inverted, hence the no prefix
|
||||
* to make the code a bit easier to understand.
|
||||
*/
|
||||
struct reset_control *no_suspend_override;
|
||||
};
|
||||
|
||||
static int ath79_usb_phy_power_on(struct phy *phy)
|
||||
{
|
||||
struct ath79_usb_phy *priv = phy_get_drvdata(phy);
|
||||
int err = 0;
|
||||
|
||||
if (priv->no_suspend_override) {
|
||||
err = reset_control_assert(priv->no_suspend_override);
|
||||
if (err)
|
||||
return err;
|
||||
}
|
||||
|
||||
err = reset_control_deassert(priv->reset);
|
||||
if (err && priv->no_suspend_override)
|
||||
reset_control_assert(priv->no_suspend_override);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
static int ath79_usb_phy_power_off(struct phy *phy)
|
||||
{
|
||||
struct ath79_usb_phy *priv = phy_get_drvdata(phy);
|
||||
int err = 0;
|
||||
|
||||
err = reset_control_assert(priv->reset);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
if (priv->no_suspend_override) {
|
||||
err = reset_control_deassert(priv->no_suspend_override);
|
||||
if (err)
|
||||
reset_control_deassert(priv->reset);
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
static const struct phy_ops ath79_usb_phy_ops = {
|
||||
.power_on = ath79_usb_phy_power_on,
|
||||
.power_off = ath79_usb_phy_power_off,
|
||||
.owner = THIS_MODULE,
|
||||
};
|
||||
|
||||
static int ath79_usb_phy_probe(struct platform_device *pdev)
|
||||
{
|
||||
struct ath79_usb_phy *priv;
|
||||
struct phy *phy;
|
||||
|
||||
priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
|
||||
if (!priv)
|
||||
return -ENOMEM;
|
||||
|
||||
priv->reset = devm_reset_control_get(&pdev->dev, "usb-phy");
|
||||
if (IS_ERR(priv->reset))
|
||||
return PTR_ERR(priv->reset);
|
||||
|
||||
priv->no_suspend_override = devm_reset_control_get_optional(
|
||||
&pdev->dev, "usb-suspend-override");
|
||||
if (IS_ERR(priv->no_suspend_override))
|
||||
return PTR_ERR(priv->no_suspend_override);
|
||||
|
||||
phy = devm_phy_create(&pdev->dev, NULL, &ath79_usb_phy_ops);
|
||||
if (IS_ERR(phy))
|
||||
return PTR_ERR(phy);
|
||||
|
||||
phy_set_drvdata(phy, priv);
|
||||
|
||||
return PTR_ERR_OR_ZERO(devm_of_phy_provider_register(
|
||||
&pdev->dev, of_phy_simple_xlate));
|
||||
}
|
||||
|
||||
static const struct of_device_id ath79_usb_phy_of_match[] = {
|
||||
{ .compatible = "qca,ar7100-usb-phy" },
|
||||
{}
|
||||
};
|
||||
MODULE_DEVICE_TABLE(of, ath79_usb_phy_of_match);
|
||||
|
||||
static struct platform_driver ath79_usb_phy_driver = {
|
||||
.probe = ath79_usb_phy_probe,
|
||||
.driver = {
|
||||
.of_match_table = ath79_usb_phy_of_match,
|
||||
.name = "ath79-usb-phy",
|
||||
}
|
||||
};
|
||||
module_platform_driver(ath79_usb_phy_driver);
|
||||
|
||||
MODULE_DESCRIPTION("ATH79 USB PHY driver");
|
||||
MODULE_AUTHOR("Alban Bedel <albeu@free.fr>");
|
||||
MODULE_LICENSE("GPL");
|
|
@ -490,6 +490,118 @@ static const struct qmp_phy_init_tbl qmp_v3_usb3_pcs_tbl[] = {
|
|||
QMP_PHY_INIT_CFG(QPHY_V3_PCS_RXEQTRAINING_RUN_TIME, 0x13),
|
||||
};
|
||||
|
||||
static const struct qmp_phy_init_tbl qmp_v3_usb3_uniphy_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, 0x04),
|
||||
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, 0x06),
|
||||
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_uniphy_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, 0xc6),
|
||||
QMP_PHY_INIT_CFG(QSERDES_V3_TX_RES_CODE_LANE_OFFSET_RX, 0x06),
|
||||
QMP_PHY_INIT_CFG(QSERDES_V3_TX_RES_CODE_LANE_OFFSET_TX, 0x06),
|
||||
};
|
||||
|
||||
static const struct qmp_phy_init_tbl qmp_v3_usb3_uniphy_rx_tbl[] = {
|
||||
QMP_PHY_INIT_CFG(QSERDES_V3_RX_VGA_CAL_CNTRL2, 0x0c),
|
||||
QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_MODE_00, 0x50),
|
||||
QMP_PHY_INIT_CFG(QSERDES_V3_RX_UCDR_FASTLOCK_FO_GAIN, 0x0b),
|
||||
QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_EQU_ADAPTOR_CNTRL2, 0x0e),
|
||||
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, 0x1c),
|
||||
QMP_PHY_INIT_CFG(QSERDES_V3_RX_UCDR_SO_SATURATION_AND_ENABLE, 0x75),
|
||||
};
|
||||
|
||||
static const struct qmp_phy_init_tbl qmp_v3_usb3_uniphy_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, 0xb5),
|
||||
QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXMGN_V3, 0x4c),
|
||||
QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXMGN_V4, 0x64),
|
||||
QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXMGN_LS, 0x6a),
|
||||
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),
|
||||
|
||||
QMP_PHY_INIT_CFG(QPHY_V3_PCS_REFGEN_REQ_CONFIG1, 0x21),
|
||||
QMP_PHY_INIT_CFG(QPHY_V3_PCS_REFGEN_REQ_CONFIG2, 0x60),
|
||||
};
|
||||
|
||||
|
||||
/* struct qmp_phy_cfg - per-PHY initialization config */
|
||||
struct qmp_phy_cfg {
|
||||
/* phy-type - PCIE/UFS/USB */
|
||||
|
@ -766,6 +878,7 @@ static const struct qmp_phy_cfg qmp_v3_usb3phy_cfg = {
|
|||
.pwrdn_ctrl = SW_PWRDN,
|
||||
.mask_pcs_ready = PHYSTATUS,
|
||||
|
||||
.has_pwrdn_delay = true,
|
||||
.pwrdn_delay_min = POWER_DOWN_DELAY_US_MIN,
|
||||
.pwrdn_delay_max = POWER_DOWN_DELAY_US_MAX,
|
||||
|
||||
|
@ -774,6 +887,35 @@ static const struct qmp_phy_cfg qmp_v3_usb3phy_cfg = {
|
|||
.rx_b_lane_offset = 0x400,
|
||||
};
|
||||
|
||||
static const struct qmp_phy_cfg qmp_v3_usb3_uniphy_cfg = {
|
||||
.type = PHY_TYPE_USB3,
|
||||
.nlanes = 1,
|
||||
|
||||
.serdes_tbl = qmp_v3_usb3_uniphy_serdes_tbl,
|
||||
.serdes_tbl_num = ARRAY_SIZE(qmp_v3_usb3_uniphy_serdes_tbl),
|
||||
.tx_tbl = qmp_v3_usb3_uniphy_tx_tbl,
|
||||
.tx_tbl_num = ARRAY_SIZE(qmp_v3_usb3_uniphy_tx_tbl),
|
||||
.rx_tbl = qmp_v3_usb3_uniphy_rx_tbl,
|
||||
.rx_tbl_num = ARRAY_SIZE(qmp_v3_usb3_uniphy_rx_tbl),
|
||||
.pcs_tbl = qmp_v3_usb3_uniphy_pcs_tbl,
|
||||
.pcs_tbl_num = ARRAY_SIZE(qmp_v3_usb3_uniphy_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,
|
||||
|
||||
.has_pwrdn_delay = true,
|
||||
.pwrdn_delay_min = POWER_DOWN_DELAY_US_MIN,
|
||||
.pwrdn_delay_max = POWER_DOWN_DELAY_US_MAX,
|
||||
};
|
||||
|
||||
static void qcom_qmp_phy_configure(void __iomem *base,
|
||||
const unsigned int *regs,
|
||||
const struct qmp_phy_init_tbl tbl[],
|
||||
|
@ -793,19 +935,6 @@ static void qcom_qmp_phy_configure(void __iomem *base,
|
|||
}
|
||||
}
|
||||
|
||||
static int qcom_qmp_phy_poweron(struct phy *phy)
|
||||
{
|
||||
struct qmp_phy *qphy = phy_get_drvdata(phy);
|
||||
struct qcom_qmp *qmp = qphy->qmp;
|
||||
int ret;
|
||||
|
||||
ret = clk_prepare_enable(qphy->pipe_clk);
|
||||
if (ret)
|
||||
dev_err(qmp->dev, "pipe_clk enable failed, err=%d\n", ret);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int qcom_qmp_phy_com_init(struct qcom_qmp *qmp)
|
||||
{
|
||||
const struct qmp_phy_cfg *cfg = qmp->cfg;
|
||||
|
@ -974,6 +1103,12 @@ static int qcom_qmp_phy_init(struct phy *phy)
|
|||
}
|
||||
}
|
||||
|
||||
ret = clk_prepare_enable(qphy->pipe_clk);
|
||||
if (ret) {
|
||||
dev_err(qmp->dev, "pipe_clk enable failed err=%d\n", ret);
|
||||
goto err_clk_enable;
|
||||
}
|
||||
|
||||
/* 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 */
|
||||
|
@ -1019,6 +1154,8 @@ static int qcom_qmp_phy_init(struct phy *phy)
|
|||
return ret;
|
||||
|
||||
err_pcs_ready:
|
||||
clk_disable_unprepare(qphy->pipe_clk);
|
||||
err_clk_enable:
|
||||
if (cfg->has_lane_rst)
|
||||
reset_control_assert(qphy->lane_rst);
|
||||
err_lane_rst:
|
||||
|
@ -1283,7 +1420,6 @@ static int phy_pipe_clk_register(struct qcom_qmp *qmp, struct device_node *np)
|
|||
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,
|
||||
.set_mode = qcom_qmp_phy_set_mode,
|
||||
.owner = THIS_MODULE,
|
||||
};
|
||||
|
@ -1381,8 +1517,11 @@ 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",
|
||||
.compatible = "qcom,sdm845-qmp-usb3-phy",
|
||||
.data = &qmp_v3_usb3phy_cfg,
|
||||
}, {
|
||||
.compatible = "qcom,sdm845-qmp-usb3-uni-phy",
|
||||
.data = &qmp_v3_usb3_uniphy_cfg,
|
||||
},
|
||||
{ },
|
||||
};
|
||||
|
|
|
@ -214,6 +214,8 @@
|
|||
#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_VGA_CAL_CNTRL1 0x0bc
|
||||
#define QSERDES_V3_RX_VGA_CAL_CNTRL2 0x0c0
|
||||
#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
|
||||
|
@ -227,6 +229,7 @@
|
|||
#define QSERDES_V3_RX_SIGDET_DEGLITCH_CNTRL 0x10c
|
||||
#define QSERDES_V3_RX_RX_BAND 0x110
|
||||
#define QSERDES_V3_RX_RX_INTERFACE_MODE 0x11c
|
||||
#define QSERDES_V3_RX_RX_MODE_00 0x164
|
||||
|
||||
/* Only for QMP V3 PHY - PCS registers */
|
||||
#define QPHY_V3_PCS_POWER_DOWN_CONTROL 0x004
|
||||
|
@ -273,6 +276,8 @@
|
|||
#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
|
||||
#define QPHY_V3_PCS_REFGEN_REQ_CONFIG1 0x20c
|
||||
#define QPHY_V3_PCS_REFGEN_REQ_CONFIG2 0x210
|
||||
|
||||
/* Only for QMP V3 PHY - PCS_MISC registers */
|
||||
#define QPHY_V3_PCS_MISC_CLAMP_ENABLE 0x0c
|
||||
|
|
|
@ -20,6 +20,8 @@
|
|||
#include <linux/reset.h>
|
||||
#include <linux/slab.h>
|
||||
|
||||
#include <dt-bindings/phy/phy-qcom-qusb2.h>
|
||||
|
||||
#define QUSB2PHY_PLL_TEST 0x04
|
||||
#define CLK_REF_SEL BIT(7)
|
||||
|
||||
|
@ -60,6 +62,17 @@
|
|||
#define CORE_RESET BIT(5)
|
||||
#define CORE_RESET_MUX BIT(6)
|
||||
|
||||
/* QUSB2PHY_IMP_CTRL1 register bits */
|
||||
#define IMP_RES_OFFSET_MASK GENMASK(5, 0)
|
||||
#define IMP_RES_OFFSET_SHIFT 0x0
|
||||
|
||||
/* QUSB2PHY_PORT_TUNE1 register bits */
|
||||
#define HSTX_TRIM_MASK GENMASK(7, 4)
|
||||
#define HSTX_TRIM_SHIFT 0x4
|
||||
#define PREEMPH_WIDTH_HALF_BIT BIT(2)
|
||||
#define PREEMPHASIS_EN_MASK GENMASK(1, 0)
|
||||
#define PREEMPHASIS_EN_SHIFT 0x0
|
||||
|
||||
#define QUSB2PHY_PLL_ANALOG_CONTROLS_TWO 0x04
|
||||
#define QUSB2PHY_PLL_CLOCK_INVERTERS 0x18c
|
||||
#define QUSB2PHY_PLL_CMODE 0x2c
|
||||
|
@ -139,7 +152,7 @@ static const struct qusb2_phy_init_tbl msm8996_init_tbl[] = {
|
|||
QUSB2_PHY_INIT_CFG(QUSB2PHY_PLL_PWR_CTRL, 0x00),
|
||||
};
|
||||
|
||||
static const unsigned int qusb2_v2_regs_layout[] = {
|
||||
static const unsigned int sdm845_regs_layout[] = {
|
||||
[QUSB2PHY_PLL_CORE_INPUT_OVERRIDE] = 0xa8,
|
||||
[QUSB2PHY_PLL_STATUS] = 0x1a0,
|
||||
[QUSB2PHY_PORT_TUNE1] = 0x240,
|
||||
|
@ -153,7 +166,7 @@ static const unsigned int qusb2_v2_regs_layout[] = {
|
|||
[QUSB2PHY_INTR_CTRL] = 0x230,
|
||||
};
|
||||
|
||||
static const struct qusb2_phy_init_tbl qusb2_v2_init_tbl[] = {
|
||||
static const struct qusb2_phy_init_tbl sdm845_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),
|
||||
|
@ -208,10 +221,10 @@ static const struct qusb2_phy_cfg msm8996_phy_cfg = {
|
|||
.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,
|
||||
static const struct qusb2_phy_cfg sdm845_phy_cfg = {
|
||||
.tbl = sdm845_init_tbl,
|
||||
.tbl_num = ARRAY_SIZE(sdm845_init_tbl),
|
||||
.regs = sdm845_regs_layout,
|
||||
|
||||
.disable_ctrl = (PWR_CTRL1_VREF_SUPPLY_TRIM | PWR_CTRL1_CLAMP_N_EN |
|
||||
POWER_DOWN),
|
||||
|
@ -241,6 +254,15 @@ static const char * const qusb2_phy_vreg_names[] = {
|
|||
* @tcsr: TCSR syscon register map
|
||||
* @cell: nvmem cell containing phy tuning value
|
||||
*
|
||||
* @override_imp_res_offset: PHY should use different rescode offset
|
||||
* @imp_res_offset_value: rescode offset to be updated in IMP_CTRL1 register
|
||||
* @override_hstx_trim: PHY should use different HSTX o/p current value
|
||||
* @hstx_trim_value: HSTX_TRIM value to be updated in TUNE1 register
|
||||
* @override_preemphasis: PHY should use different pre-amphasis amplitude
|
||||
* @preemphasis_level: Amplitude Pre-Emphasis to be updated in TUNE1 register
|
||||
* @override_preemphasis_width: PHY should use different pre-emphasis duration
|
||||
* @preemphasis_width: half/full-width Pre-Emphasis updated via TUNE1
|
||||
*
|
||||
* @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
|
||||
|
@ -259,12 +281,35 @@ struct qusb2_phy {
|
|||
struct regmap *tcsr;
|
||||
struct nvmem_cell *cell;
|
||||
|
||||
bool override_imp_res_offset;
|
||||
u8 imp_res_offset_value;
|
||||
bool override_hstx_trim;
|
||||
u8 hstx_trim_value;
|
||||
bool override_preemphasis;
|
||||
u8 preemphasis_level;
|
||||
bool override_preemphasis_width;
|
||||
u8 preemphasis_width;
|
||||
|
||||
const struct qusb2_phy_cfg *cfg;
|
||||
bool has_se_clk_scheme;
|
||||
bool phy_initialized;
|
||||
enum phy_mode mode;
|
||||
};
|
||||
|
||||
static inline void qusb2_write_mask(void __iomem *base, u32 offset,
|
||||
u32 val, u32 mask)
|
||||
{
|
||||
u32 reg;
|
||||
|
||||
reg = readl(base + offset);
|
||||
reg &= ~mask;
|
||||
reg |= val & mask;
|
||||
writel(reg, base + offset);
|
||||
|
||||
/* Ensure above write is completed */
|
||||
readl(base + offset);
|
||||
}
|
||||
|
||||
static inline void qusb2_setbits(void __iomem *base, u32 offset, u32 val)
|
||||
{
|
||||
u32 reg;
|
||||
|
@ -304,6 +349,42 @@ void qcom_qusb2_phy_configure(void __iomem *base,
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Update board specific PHY tuning override values if specified from
|
||||
* device tree.
|
||||
*/
|
||||
static void qusb2_phy_override_phy_params(struct qusb2_phy *qphy)
|
||||
{
|
||||
const struct qusb2_phy_cfg *cfg = qphy->cfg;
|
||||
|
||||
if (qphy->override_imp_res_offset)
|
||||
qusb2_write_mask(qphy->base, QUSB2PHY_IMP_CTRL1,
|
||||
qphy->imp_res_offset_value << IMP_RES_OFFSET_SHIFT,
|
||||
IMP_RES_OFFSET_MASK);
|
||||
|
||||
if (qphy->override_hstx_trim)
|
||||
qusb2_write_mask(qphy->base, cfg->regs[QUSB2PHY_PORT_TUNE1],
|
||||
qphy->hstx_trim_value << HSTX_TRIM_SHIFT,
|
||||
HSTX_TRIM_MASK);
|
||||
|
||||
if (qphy->override_preemphasis)
|
||||
qusb2_write_mask(qphy->base, cfg->regs[QUSB2PHY_PORT_TUNE1],
|
||||
qphy->preemphasis_level << PREEMPHASIS_EN_SHIFT,
|
||||
PREEMPHASIS_EN_MASK);
|
||||
|
||||
if (qphy->override_preemphasis_width) {
|
||||
if (qphy->preemphasis_width ==
|
||||
QUSB2_V2_PREEMPHASIS_WIDTH_HALF_BIT)
|
||||
qusb2_setbits(qphy->base,
|
||||
cfg->regs[QUSB2PHY_PORT_TUNE1],
|
||||
PREEMPH_WIDTH_HALF_BIT);
|
||||
else
|
||||
qusb2_clrbits(qphy->base,
|
||||
cfg->regs[QUSB2PHY_PORT_TUNE1],
|
||||
PREEMPH_WIDTH_HALF_BIT);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Fetches HS Tx tuning value from nvmem and sets the
|
||||
* QUSB2PHY_PORT_TUNE1/2 register.
|
||||
|
@ -315,6 +396,10 @@ static void qusb2_phy_set_tune2_param(struct qusb2_phy *qphy)
|
|||
const struct qusb2_phy_cfg *cfg = qphy->cfg;
|
||||
u8 *val;
|
||||
|
||||
/* efuse register is optional */
|
||||
if (!qphy->cell)
|
||||
return;
|
||||
|
||||
/*
|
||||
* Read efuse register having TUNE2/1 parameter's high nibble.
|
||||
* If efuse register shows value as 0x0, or if we fail to find
|
||||
|
@ -521,6 +606,9 @@ static int qusb2_phy_init(struct phy *phy)
|
|||
qcom_qusb2_phy_configure(qphy->base, cfg->regs, cfg->tbl,
|
||||
cfg->tbl_num);
|
||||
|
||||
/* Override board specific PHY tuning values */
|
||||
qusb2_phy_override_phy_params(qphy);
|
||||
|
||||
/* Set efuse value for tuning the PHY */
|
||||
qusb2_phy_set_tune2_param(qphy);
|
||||
|
||||
|
@ -643,8 +731,8 @@ 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,
|
||||
.compatible = "qcom,sdm845-qusb2-phy",
|
||||
.data = &sdm845_phy_cfg,
|
||||
},
|
||||
{ },
|
||||
};
|
||||
|
@ -664,6 +752,7 @@ static int qusb2_phy_probe(struct platform_device *pdev)
|
|||
struct resource *res;
|
||||
int ret, i;
|
||||
int num;
|
||||
u32 value;
|
||||
|
||||
qphy = devm_kzalloc(dev, sizeof(*qphy), GFP_KERNEL);
|
||||
if (!qphy)
|
||||
|
@ -732,6 +821,31 @@ static int qusb2_phy_probe(struct platform_device *pdev)
|
|||
qphy->cell = NULL;
|
||||
dev_dbg(dev, "failed to lookup tune2 hstx trim value\n");
|
||||
}
|
||||
|
||||
if (!of_property_read_u32(dev->of_node, "qcom,imp-res-offset-value",
|
||||
&value)) {
|
||||
qphy->imp_res_offset_value = (u8)value;
|
||||
qphy->override_imp_res_offset = true;
|
||||
}
|
||||
|
||||
if (!of_property_read_u32(dev->of_node, "qcom,hstx-trim-value",
|
||||
&value)) {
|
||||
qphy->hstx_trim_value = (u8)value;
|
||||
qphy->override_hstx_trim = true;
|
||||
}
|
||||
|
||||
if (!of_property_read_u32(dev->of_node, "qcom,preemphasis-level",
|
||||
&value)) {
|
||||
qphy->preemphasis_level = (u8)value;
|
||||
qphy->override_preemphasis = true;
|
||||
}
|
||||
|
||||
if (!of_property_read_u32(dev->of_node, "qcom,preemphasis-width",
|
||||
&value)) {
|
||||
qphy->preemphasis_width = (u8)value;
|
||||
qphy->override_preemphasis_width = true;
|
||||
}
|
||||
|
||||
pm_runtime_set_active(dev);
|
||||
pm_runtime_enable(dev);
|
||||
/*
|
||||
|
|
|
@ -231,33 +231,27 @@ struct exynos_mipi_video_phy {
|
|||
static int __set_phy_state(const struct exynos_mipi_phy_desc *data,
|
||||
struct exynos_mipi_video_phy *state, unsigned int on)
|
||||
{
|
||||
u32 val;
|
||||
struct regmap *enable_map = state->regmaps[data->enable_map];
|
||||
struct regmap *resetn_map = state->regmaps[data->resetn_map];
|
||||
|
||||
spin_lock(&state->slock);
|
||||
|
||||
/* disable in PMU sysreg */
|
||||
if (!on && data->coupled_phy_id >= 0 &&
|
||||
state->phys[data->coupled_phy_id].phy->power_count == 0) {
|
||||
regmap_read(state->regmaps[data->enable_map], data->enable_reg,
|
||||
&val);
|
||||
val &= ~data->enable_val;
|
||||
regmap_write(state->regmaps[data->enable_map], data->enable_reg,
|
||||
val);
|
||||
}
|
||||
|
||||
state->phys[data->coupled_phy_id].phy->power_count == 0)
|
||||
regmap_update_bits(enable_map, data->enable_reg,
|
||||
data->enable_val, 0);
|
||||
/* PHY reset */
|
||||
regmap_read(state->regmaps[data->resetn_map], data->resetn_reg, &val);
|
||||
val = on ? (val | data->resetn_val) : (val & ~data->resetn_val);
|
||||
regmap_write(state->regmaps[data->resetn_map], data->resetn_reg, val);
|
||||
|
||||
if (on)
|
||||
regmap_update_bits(resetn_map, data->resetn_reg,
|
||||
data->resetn_val, data->resetn_val);
|
||||
else
|
||||
regmap_update_bits(resetn_map, data->resetn_reg,
|
||||
data->resetn_val, 0);
|
||||
/* enable in PMU sysreg */
|
||||
if (on) {
|
||||
regmap_read(state->regmaps[data->enable_map], data->enable_reg,
|
||||
&val);
|
||||
val |= data->enable_val;
|
||||
regmap_write(state->regmaps[data->enable_map], data->enable_reg,
|
||||
val);
|
||||
}
|
||||
if (on)
|
||||
regmap_update_bits(enable_map, data->enable_reg,
|
||||
data->enable_val, data->enable_val);
|
||||
|
||||
spin_unlock(&state->slock);
|
||||
|
||||
|
|
|
@ -71,7 +71,6 @@ struct stm32_usbphyc {
|
|||
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)
|
||||
|
@ -84,7 +83,8 @@ 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)
|
||||
static void stm32_usbphyc_get_pll_params(u32 clk_rate,
|
||||
struct pll_params *pll_params)
|
||||
{
|
||||
unsigned long long fvco, ndiv, frac;
|
||||
|
||||
|
@ -271,7 +271,6 @@ static struct phy *stm32_usbphyc_of_xlate(struct device *dev,
|
|||
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++) {
|
||||
|
@ -367,8 +366,8 @@ static int stm32_usbphyc_probe(struct platform_device *pdev)
|
|||
if (IS_ERR(phy)) {
|
||||
ret = PTR_ERR(phy);
|
||||
if (ret != -EPROBE_DEFER)
|
||||
dev_err(dev,
|
||||
"failed to create phy%d: %d\n", i, ret);
|
||||
dev_err(dev, "failed to create phy%d: %d\n",
|
||||
port, ret);
|
||||
goto put_child;
|
||||
}
|
||||
|
||||
|
|
|
@ -102,19 +102,6 @@ tegra_xusb_pad_find_phy_node(struct tegra_xusb_pad *pad, unsigned int index)
|
|||
return np;
|
||||
}
|
||||
|
||||
static int
|
||||
tegra_xusb_lane_lookup_function(struct tegra_xusb_lane *lane,
|
||||
const char *function)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < lane->soc->num_funcs; i++)
|
||||
if (strcmp(function, lane->soc->funcs[i]) == 0)
|
||||
return i;
|
||||
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
int tegra_xusb_lane_parse_dt(struct tegra_xusb_lane *lane,
|
||||
struct device_node *np)
|
||||
{
|
||||
|
@ -126,7 +113,7 @@ int tegra_xusb_lane_parse_dt(struct tegra_xusb_lane *lane,
|
|||
if (err < 0)
|
||||
return err;
|
||||
|
||||
err = tegra_xusb_lane_lookup_function(lane, function);
|
||||
err = match_string(lane->soc->funcs, lane->soc->num_funcs, function);
|
||||
if (err < 0) {
|
||||
dev_err(dev, "invalid function \"%s\" for lane \"%s\"\n",
|
||||
function, np->name);
|
||||
|
|
|
@ -866,6 +866,7 @@ config ACPI_CMPC
|
|||
config INTEL_CHT_INT33FE
|
||||
tristate "Intel Cherry Trail ACPI INT33FE Driver"
|
||||
depends on X86 && ACPI && I2C && REGULATOR
|
||||
depends on CHARGER_BQ24190=y || (CHARGER_BQ24190=m && m)
|
||||
---help---
|
||||
This driver add support for the INT33FE ACPI device found on
|
||||
some Intel Cherry Trail devices.
|
||||
|
@ -877,8 +878,7 @@ config INTEL_CHT_INT33FE
|
|||
i2c drivers for these chips can bind to the them.
|
||||
|
||||
If you enable this driver it is advised to also select
|
||||
CONFIG_TYPEC_FUSB302=m, CONFIG_CHARGER_BQ24190=m and
|
||||
CONFIG_BATTERY_MAX17042=m.
|
||||
CONFIG_TYPEC_FUSB302=m and CONFIG_BATTERY_MAX17042=m.
|
||||
|
||||
config INTEL_INT0002_VGPIO
|
||||
tristate "Intel ACPI INT0002 Virtual GPIO driver"
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include <linux/err.h>
|
||||
#include <linux/of.h>
|
||||
#include <linux/power_supply.h>
|
||||
#include <linux/property.h>
|
||||
#include <linux/thermal.h>
|
||||
#include "power_supply.h"
|
||||
|
||||
|
@ -843,12 +844,21 @@ __power_supply_register(struct device *parent,
|
|||
{
|
||||
struct device *dev;
|
||||
struct power_supply *psy;
|
||||
int rc;
|
||||
int i, rc;
|
||||
|
||||
if (!parent)
|
||||
pr_warn("%s: Expected proper parent device for '%s'\n",
|
||||
__func__, desc->name);
|
||||
|
||||
if (!desc || !desc->name || !desc->properties || !desc->num_properties)
|
||||
return ERR_PTR(-EINVAL);
|
||||
|
||||
for (i = 0; i < desc->num_properties; ++i) {
|
||||
if ((desc->properties[i] == POWER_SUPPLY_PROP_USB_TYPE) &&
|
||||
(!desc->usb_types || !desc->num_usb_types))
|
||||
return ERR_PTR(-EINVAL);
|
||||
}
|
||||
|
||||
psy = kzalloc(sizeof(*psy), GFP_KERNEL);
|
||||
if (!psy)
|
||||
return ERR_PTR(-ENOMEM);
|
||||
|
@ -865,7 +875,8 @@ __power_supply_register(struct device *parent,
|
|||
psy->desc = desc;
|
||||
if (cfg) {
|
||||
psy->drv_data = cfg->drv_data;
|
||||
psy->of_node = cfg->of_node;
|
||||
psy->of_node =
|
||||
cfg->fwnode ? to_of_node(cfg->fwnode) : cfg->of_node;
|
||||
psy->supplied_to = cfg->supplied_to;
|
||||
psy->num_supplicants = cfg->num_supplicants;
|
||||
}
|
||||
|
|
|
@ -46,6 +46,11 @@ static const char * const power_supply_type_text[] = {
|
|||
"USB_PD", "USB_PD_DRP", "BrickID"
|
||||
};
|
||||
|
||||
static const char * const power_supply_usb_type_text[] = {
|
||||
"Unknown", "SDP", "DCP", "CDP", "ACA", "C",
|
||||
"PD", "PD_DRP", "PD_PPS", "BrickID"
|
||||
};
|
||||
|
||||
static const char * const power_supply_status_text[] = {
|
||||
"Unknown", "Charging", "Discharging", "Not charging", "Full"
|
||||
};
|
||||
|
@ -73,6 +78,41 @@ static const char * const power_supply_scope_text[] = {
|
|||
"Unknown", "System", "Device"
|
||||
};
|
||||
|
||||
static ssize_t power_supply_show_usb_type(struct device *dev,
|
||||
enum power_supply_usb_type *usb_types,
|
||||
ssize_t num_usb_types,
|
||||
union power_supply_propval *value,
|
||||
char *buf)
|
||||
{
|
||||
enum power_supply_usb_type usb_type;
|
||||
ssize_t count = 0;
|
||||
bool match = false;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < num_usb_types; ++i) {
|
||||
usb_type = usb_types[i];
|
||||
|
||||
if (value->intval == usb_type) {
|
||||
count += sprintf(buf + count, "[%s] ",
|
||||
power_supply_usb_type_text[usb_type]);
|
||||
match = true;
|
||||
} else {
|
||||
count += sprintf(buf + count, "%s ",
|
||||
power_supply_usb_type_text[usb_type]);
|
||||
}
|
||||
}
|
||||
|
||||
if (!match) {
|
||||
dev_warn(dev, "driver reporting unsupported connected type\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (count)
|
||||
buf[count - 1] = '\n';
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
static ssize_t power_supply_show_property(struct device *dev,
|
||||
struct device_attribute *attr,
|
||||
char *buf) {
|
||||
|
@ -115,6 +155,10 @@ static ssize_t power_supply_show_property(struct device *dev,
|
|||
else if (off == POWER_SUPPLY_PROP_TYPE)
|
||||
return sprintf(buf, "%s\n",
|
||||
power_supply_type_text[value.intval]);
|
||||
else if (off == POWER_SUPPLY_PROP_USB_TYPE)
|
||||
return power_supply_show_usb_type(dev, psy->desc->usb_types,
|
||||
psy->desc->num_usb_types,
|
||||
&value, buf);
|
||||
else if (off == POWER_SUPPLY_PROP_SCOPE)
|
||||
return sprintf(buf, "%s\n",
|
||||
power_supply_scope_text[value.intval]);
|
||||
|
@ -241,6 +285,7 @@ static struct device_attribute power_supply_attrs[] = {
|
|||
POWER_SUPPLY_ATTR(time_to_full_now),
|
||||
POWER_SUPPLY_ATTR(time_to_full_avg),
|
||||
POWER_SUPPLY_ATTR(type),
|
||||
POWER_SUPPLY_ATTR(usb_type),
|
||||
POWER_SUPPLY_ATTR(scope),
|
||||
POWER_SUPPLY_ATTR(precharge_current),
|
||||
POWER_SUPPLY_ATTR(charge_term_current),
|
||||
|
|
|
@ -9,6 +9,14 @@ config TYPEC_TCPCI
|
|||
help
|
||||
Type-C Port Controller driver for TCPCI-compliant controller.
|
||||
|
||||
config TYPEC_RT1711H
|
||||
tristate "Richtek RT1711H Type-C chip driver"
|
||||
select TYPEC_TCPCI
|
||||
help
|
||||
Richtek RT1711H Type-C chip driver that works with
|
||||
Type-C Port Controller Manager to provide USB PD and USB
|
||||
Type-C functionalities.
|
||||
|
||||
endif
|
||||
|
||||
endmenu
|
||||
|
|
|
@ -1 +1,2 @@
|
|||
obj-$(CONFIG_TYPEC_TCPCI) += tcpci.o
|
||||
obj-$(CONFIG_TYPEC_RT1711H) += tcpci_rt1711h.o
|
||||
|
|
|
@ -59,6 +59,7 @@
|
|||
#define TCPC_POWER_CTRL_VCONN_ENABLE BIT(0)
|
||||
|
||||
#define TCPC_CC_STATUS 0x1d
|
||||
#define TCPC_CC_STATUS_TOGGLING BIT(5)
|
||||
#define TCPC_CC_STATUS_TERM BIT(4)
|
||||
#define TCPC_CC_STATUS_CC2_SHIFT 2
|
||||
#define TCPC_CC_STATUS_CC2_MASK 0x3
|
||||
|
|
312
drivers/staging/typec/tcpci_rt1711h.c
Normal file
312
drivers/staging/typec/tcpci_rt1711h.c
Normal file
|
@ -0,0 +1,312 @@
|
|||
// SPDX-License-Identifier: GPL-2.0+
|
||||
/*
|
||||
* Copyright (C) 2018, Richtek Technology Corporation
|
||||
*
|
||||
* Richtek RT1711H Type-C Chip Driver
|
||||
*/
|
||||
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/i2c.h>
|
||||
#include <linux/interrupt.h>
|
||||
#include <linux/gpio/consumer.h>
|
||||
#include <linux/usb/tcpm.h>
|
||||
#include <linux/regmap.h>
|
||||
#include "tcpci.h"
|
||||
|
||||
#define RT1711H_VID 0x29CF
|
||||
#define RT1711H_PID 0x1711
|
||||
|
||||
#define RT1711H_RTCTRL8 0x9B
|
||||
|
||||
/* Autoidle timeout = (tout * 2 + 1) * 6.4ms */
|
||||
#define RT1711H_RTCTRL8_SET(ck300, ship_off, auto_idle, tout) \
|
||||
(((ck300) << 7) | ((ship_off) << 5) | \
|
||||
((auto_idle) << 3) | ((tout) & 0x07))
|
||||
|
||||
#define RT1711H_RTCTRL11 0x9E
|
||||
|
||||
/* I2C timeout = (tout + 1) * 12.5ms */
|
||||
#define RT1711H_RTCTRL11_SET(en, tout) \
|
||||
(((en) << 7) | ((tout) & 0x0F))
|
||||
|
||||
#define RT1711H_RTCTRL13 0xA0
|
||||
#define RT1711H_RTCTRL14 0xA1
|
||||
#define RT1711H_RTCTRL15 0xA2
|
||||
#define RT1711H_RTCTRL16 0xA3
|
||||
|
||||
struct rt1711h_chip {
|
||||
struct tcpci_data data;
|
||||
struct tcpci *tcpci;
|
||||
struct device *dev;
|
||||
};
|
||||
|
||||
static int rt1711h_read16(struct rt1711h_chip *chip, unsigned int reg, u16 *val)
|
||||
{
|
||||
return regmap_raw_read(chip->data.regmap, reg, val, sizeof(u16));
|
||||
}
|
||||
|
||||
static int rt1711h_write16(struct rt1711h_chip *chip, unsigned int reg, u16 val)
|
||||
{
|
||||
return regmap_raw_write(chip->data.regmap, reg, &val, sizeof(u16));
|
||||
}
|
||||
|
||||
static int rt1711h_read8(struct rt1711h_chip *chip, unsigned int reg, u8 *val)
|
||||
{
|
||||
return regmap_raw_read(chip->data.regmap, reg, val, sizeof(u8));
|
||||
}
|
||||
|
||||
static int rt1711h_write8(struct rt1711h_chip *chip, unsigned int reg, u8 val)
|
||||
{
|
||||
return regmap_raw_write(chip->data.regmap, reg, &val, sizeof(u8));
|
||||
}
|
||||
|
||||
static const struct regmap_config rt1711h_regmap_config = {
|
||||
.reg_bits = 8,
|
||||
.val_bits = 8,
|
||||
|
||||
.max_register = 0xFF, /* 0x80 .. 0xFF are vendor defined */
|
||||
};
|
||||
|
||||
static struct rt1711h_chip *tdata_to_rt1711h(struct tcpci_data *tdata)
|
||||
{
|
||||
return container_of(tdata, struct rt1711h_chip, data);
|
||||
}
|
||||
|
||||
static int rt1711h_init(struct tcpci *tcpci, struct tcpci_data *tdata)
|
||||
{
|
||||
int ret;
|
||||
struct rt1711h_chip *chip = tdata_to_rt1711h(tdata);
|
||||
|
||||
/* CK 300K from 320K, shipping off, auto_idle enable, tout = 32ms */
|
||||
ret = rt1711h_write8(chip, RT1711H_RTCTRL8,
|
||||
RT1711H_RTCTRL8_SET(0, 1, 1, 2));
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
/* I2C reset : (val + 1) * 12.5ms */
|
||||
ret = rt1711h_write8(chip, RT1711H_RTCTRL11,
|
||||
RT1711H_RTCTRL11_SET(1, 0x0F));
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
/* tTCPCfilter : (26.7 * val) us */
|
||||
ret = rt1711h_write8(chip, RT1711H_RTCTRL14, 0x0F);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
/* tDRP : (51.2 + 6.4 * val) ms */
|
||||
ret = rt1711h_write8(chip, RT1711H_RTCTRL15, 0x04);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
/* dcSRC.DRP : 33% */
|
||||
return rt1711h_write16(chip, RT1711H_RTCTRL16, 330);
|
||||
}
|
||||
|
||||
static int rt1711h_set_vconn(struct tcpci *tcpci, struct tcpci_data *tdata,
|
||||
bool enable)
|
||||
{
|
||||
struct rt1711h_chip *chip = tdata_to_rt1711h(tdata);
|
||||
|
||||
return rt1711h_write8(chip, RT1711H_RTCTRL8,
|
||||
RT1711H_RTCTRL8_SET(0, 1, !enable, 2));
|
||||
}
|
||||
|
||||
static int rt1711h_start_drp_toggling(struct tcpci *tcpci,
|
||||
struct tcpci_data *tdata,
|
||||
enum typec_cc_status cc)
|
||||
{
|
||||
struct rt1711h_chip *chip = tdata_to_rt1711h(tdata);
|
||||
int ret;
|
||||
unsigned int reg = 0;
|
||||
|
||||
switch (cc) {
|
||||
default:
|
||||
case TYPEC_CC_RP_DEF:
|
||||
reg |= (TCPC_ROLE_CTRL_RP_VAL_DEF <<
|
||||
TCPC_ROLE_CTRL_RP_VAL_SHIFT);
|
||||
break;
|
||||
case TYPEC_CC_RP_1_5:
|
||||
reg |= (TCPC_ROLE_CTRL_RP_VAL_1_5 <<
|
||||
TCPC_ROLE_CTRL_RP_VAL_SHIFT);
|
||||
break;
|
||||
case TYPEC_CC_RP_3_0:
|
||||
reg |= (TCPC_ROLE_CTRL_RP_VAL_3_0 <<
|
||||
TCPC_ROLE_CTRL_RP_VAL_SHIFT);
|
||||
break;
|
||||
}
|
||||
|
||||
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 = rt1711h_write8(chip, TCPC_ROLE_CTRL, reg);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
usleep_range(500, 1000);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static irqreturn_t rt1711h_irq(int irq, void *dev_id)
|
||||
{
|
||||
int ret;
|
||||
u16 alert;
|
||||
u8 status;
|
||||
struct rt1711h_chip *chip = dev_id;
|
||||
|
||||
if (!chip->tcpci)
|
||||
return IRQ_HANDLED;
|
||||
|
||||
ret = rt1711h_read16(chip, TCPC_ALERT, &alert);
|
||||
if (ret < 0)
|
||||
goto out;
|
||||
|
||||
if (alert & TCPC_ALERT_CC_STATUS) {
|
||||
ret = rt1711h_read8(chip, TCPC_CC_STATUS, &status);
|
||||
if (ret < 0)
|
||||
goto out;
|
||||
/* Clear cc change event triggered by starting toggling */
|
||||
if (status & TCPC_CC_STATUS_TOGGLING)
|
||||
rt1711h_write8(chip, TCPC_ALERT, TCPC_ALERT_CC_STATUS);
|
||||
}
|
||||
|
||||
out:
|
||||
return tcpci_irq(chip->tcpci);
|
||||
}
|
||||
|
||||
static int rt1711h_init_alert(struct rt1711h_chip *chip,
|
||||
struct i2c_client *client)
|
||||
{
|
||||
int ret;
|
||||
|
||||
/* Disable chip interrupts before requesting irq */
|
||||
ret = rt1711h_write16(chip, TCPC_ALERT_MASK, 0);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
ret = devm_request_threaded_irq(chip->dev, client->irq, NULL,
|
||||
rt1711h_irq,
|
||||
IRQF_ONESHOT | IRQF_TRIGGER_LOW,
|
||||
dev_name(chip->dev), chip);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
enable_irq_wake(client->irq);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rt1711h_sw_reset(struct rt1711h_chip *chip)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = rt1711h_write8(chip, RT1711H_RTCTRL13, 0x01);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
usleep_range(1000, 2000);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rt1711h_check_revision(struct i2c_client *i2c)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = i2c_smbus_read_word_data(i2c, TCPC_VENDOR_ID);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
if (ret != RT1711H_VID) {
|
||||
dev_err(&i2c->dev, "vid is not correct, 0x%04x\n", ret);
|
||||
return -ENODEV;
|
||||
}
|
||||
ret = i2c_smbus_read_word_data(i2c, TCPC_PRODUCT_ID);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
if (ret != RT1711H_PID) {
|
||||
dev_err(&i2c->dev, "pid is not correct, 0x%04x\n", ret);
|
||||
return -ENODEV;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rt1711h_probe(struct i2c_client *client,
|
||||
const struct i2c_device_id *i2c_id)
|
||||
{
|
||||
int ret;
|
||||
struct rt1711h_chip *chip;
|
||||
|
||||
ret = rt1711h_check_revision(client);
|
||||
if (ret < 0) {
|
||||
dev_err(&client->dev, "check vid/pid fail\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL);
|
||||
if (!chip)
|
||||
return -ENOMEM;
|
||||
|
||||
chip->data.regmap = devm_regmap_init_i2c(client,
|
||||
&rt1711h_regmap_config);
|
||||
if (IS_ERR(chip->data.regmap))
|
||||
return PTR_ERR(chip->data.regmap);
|
||||
|
||||
chip->dev = &client->dev;
|
||||
i2c_set_clientdata(client, chip);
|
||||
|
||||
ret = rt1711h_sw_reset(chip);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
ret = rt1711h_init_alert(chip, client);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
chip->data.init = rt1711h_init;
|
||||
chip->data.set_vconn = rt1711h_set_vconn;
|
||||
chip->data.start_drp_toggling = rt1711h_start_drp_toggling;
|
||||
chip->tcpci = tcpci_register_port(chip->dev, &chip->data);
|
||||
if (IS_ERR_OR_NULL(chip->tcpci))
|
||||
return PTR_ERR(chip->tcpci);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rt1711h_remove(struct i2c_client *client)
|
||||
{
|
||||
struct rt1711h_chip *chip = i2c_get_clientdata(client);
|
||||
|
||||
tcpci_unregister_port(chip->tcpci);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct i2c_device_id rt1711h_id[] = {
|
||||
{ "rt1711h", 0 },
|
||||
{ }
|
||||
};
|
||||
MODULE_DEVICE_TABLE(i2c, rt1711h_id);
|
||||
|
||||
#ifdef CONFIG_OF
|
||||
static const struct of_device_id rt1711h_of_match[] = {
|
||||
{ .compatible = "richtek,rt1711h", },
|
||||
{},
|
||||
};
|
||||
MODULE_DEVICE_TABLE(of, rt1711h_of_match);
|
||||
#endif
|
||||
|
||||
static struct i2c_driver rt1711h_i2c_driver = {
|
||||
.driver = {
|
||||
.name = "rt1711h",
|
||||
.of_match_table = of_match_ptr(rt1711h_of_match),
|
||||
},
|
||||
.probe = rt1711h_probe,
|
||||
.remove = rt1711h_remove,
|
||||
.id_table = rt1711h_id,
|
||||
};
|
||||
module_i2c_driver(rt1711h_i2c_driver);
|
||||
|
||||
MODULE_AUTHOR("ShuFan Lee <shufan_lee@richtek.com>");
|
||||
MODULE_DESCRIPTION("RT1711H USB Type-C Port Controller Interface Driver");
|
||||
MODULE_LICENSE("GPL");
|
|
@ -290,7 +290,7 @@ EXPORT_SYMBOL(tty_termios_copy_hw);
|
|||
* between the two termios structures, or a speed change is needed.
|
||||
*/
|
||||
|
||||
int tty_termios_hw_change(struct ktermios *a, struct ktermios *b)
|
||||
int tty_termios_hw_change(const struct ktermios *a, const struct ktermios *b)
|
||||
{
|
||||
if (a->c_ispeed != b->c_ispeed || a->c_ospeed != b->c_ospeed)
|
||||
return 1;
|
||||
|
|
|
@ -450,7 +450,7 @@ void hw_phymode_configure(struct ci_hdrc *ci);
|
|||
|
||||
void ci_platform_configure(struct ci_hdrc *ci);
|
||||
|
||||
int dbg_create_files(struct ci_hdrc *ci);
|
||||
void dbg_create_files(struct ci_hdrc *ci);
|
||||
|
||||
void dbg_remove_files(struct ci_hdrc *ci);
|
||||
#endif /* __DRIVERS_USB_CHIPIDEA_CI_H */
|
||||
|
|
|
@ -291,7 +291,8 @@ 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 &&
|
||||
if ((of_device_is_compatible(np, "fsl,imx53-usb") ||
|
||||
of_device_is_compatible(np, "fsl,imx51-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;
|
||||
|
|
|
@ -1062,9 +1062,7 @@ static int ci_hdrc_probe(struct platform_device *pdev)
|
|||
ci_hdrc_otg_fsm_start(ci);
|
||||
|
||||
device_set_wakeup_capable(&pdev->dev, true);
|
||||
ret = dbg_create_files(ci);
|
||||
if (ret)
|
||||
goto stop;
|
||||
dbg_create_files(ci);
|
||||
|
||||
ret = sysfs_create_group(&dev->kobj, &ci_attr_group);
|
||||
if (ret)
|
||||
|
|
|
@ -340,54 +340,28 @@ DEFINE_SHOW_ATTRIBUTE(ci_registers);
|
|||
*
|
||||
* This function returns an error code
|
||||
*/
|
||||
int dbg_create_files(struct ci_hdrc *ci)
|
||||
void dbg_create_files(struct ci_hdrc *ci)
|
||||
{
|
||||
struct dentry *dent;
|
||||
|
||||
ci->debugfs = debugfs_create_dir(dev_name(ci->dev), NULL);
|
||||
if (!ci->debugfs)
|
||||
return -ENOMEM;
|
||||
|
||||
dent = debugfs_create_file("device", S_IRUGO, ci->debugfs, ci,
|
||||
debugfs_create_file("device", S_IRUGO, ci->debugfs, ci,
|
||||
&ci_device_fops);
|
||||
if (!dent)
|
||||
goto err;
|
||||
|
||||
dent = debugfs_create_file("port_test", S_IRUGO | S_IWUSR, ci->debugfs,
|
||||
ci, &ci_port_test_fops);
|
||||
if (!dent)
|
||||
goto err;
|
||||
|
||||
dent = debugfs_create_file("qheads", S_IRUGO, ci->debugfs, ci,
|
||||
debugfs_create_file("port_test", S_IRUGO | S_IWUSR, ci->debugfs, ci,
|
||||
&ci_port_test_fops);
|
||||
debugfs_create_file("qheads", S_IRUGO, ci->debugfs, ci,
|
||||
&ci_qheads_fops);
|
||||
if (!dent)
|
||||
goto err;
|
||||
|
||||
dent = debugfs_create_file("requests", S_IRUGO, ci->debugfs, ci,
|
||||
debugfs_create_file("requests", S_IRUGO, ci->debugfs, ci,
|
||||
&ci_requests_fops);
|
||||
if (!dent)
|
||||
goto err;
|
||||
|
||||
if (ci_otg_is_fsm_mode(ci)) {
|
||||
dent = debugfs_create_file("otg", S_IRUGO, ci->debugfs, ci,
|
||||
debugfs_create_file("otg", S_IRUGO, ci->debugfs, ci,
|
||||
&ci_otg_fops);
|
||||
if (!dent)
|
||||
goto err;
|
||||
}
|
||||
|
||||
dent = debugfs_create_file("role", S_IRUGO | S_IWUSR, ci->debugfs, ci,
|
||||
debugfs_create_file("role", S_IRUGO | S_IWUSR, ci->debugfs, ci,
|
||||
&ci_role_fops);
|
||||
if (!dent)
|
||||
goto err;
|
||||
|
||||
dent = debugfs_create_file("registers", S_IRUGO, ci->debugfs, ci,
|
||||
debugfs_create_file("registers", S_IRUGO, ci->debugfs, ci,
|
||||
&ci_registers_fops);
|
||||
|
||||
if (dent)
|
||||
return 0;
|
||||
err:
|
||||
debugfs_remove_recursive(ci->debugfs);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
#include <linux/usb/tmc.h>
|
||||
|
||||
|
||||
#define RIGOL 1
|
||||
#define USBTMC_HEADER_SIZE 12
|
||||
#define USBTMC_MINOR_BASE 176
|
||||
|
||||
|
@ -93,8 +92,6 @@ struct usbtmc_device_data {
|
|||
/* coalesced usb488_caps from usbtmc_dev_capabilities */
|
||||
__u8 usb488_caps;
|
||||
|
||||
u8 rigol_quirk;
|
||||
|
||||
/* attributes from the USB TMC spec for this device */
|
||||
u8 TermChar;
|
||||
bool TermCharEnabled;
|
||||
|
@ -110,17 +107,6 @@ struct usbtmc_device_data {
|
|||
};
|
||||
#define to_usbtmc_data(d) container_of(d, struct usbtmc_device_data, kref)
|
||||
|
||||
struct usbtmc_ID_rigol_quirk {
|
||||
__u16 idVendor;
|
||||
__u16 idProduct;
|
||||
};
|
||||
|
||||
static const struct usbtmc_ID_rigol_quirk usbtmc_id_quirk[] = {
|
||||
{ 0x1ab1, 0x0588 },
|
||||
{ 0x1ab1, 0x04b0 },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
/* Forward declarations */
|
||||
static struct usb_driver usbtmc_driver;
|
||||
|
||||
|
@ -603,7 +589,6 @@ static ssize_t usbtmc_read(struct file *filp, char __user *buf,
|
|||
goto exit;
|
||||
}
|
||||
|
||||
if (data->rigol_quirk) {
|
||||
dev_dbg(dev, "usb_bulk_msg_in: count(%zu)\n", count);
|
||||
|
||||
retval = send_request_dev_dep_msg_in(data, count);
|
||||
|
@ -613,7 +598,6 @@ static ssize_t usbtmc_read(struct file *filp, char __user *buf,
|
|||
usbtmc_ioctl_abort_bulk_out(data);
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
|
||||
/* Loop until we have fetched everything we requested */
|
||||
remaining = count;
|
||||
|
@ -621,23 +605,6 @@ static ssize_t usbtmc_read(struct file *filp, char __user *buf,
|
|||
done = 0;
|
||||
|
||||
while (remaining > 0) {
|
||||
if (!data->rigol_quirk) {
|
||||
dev_dbg(dev, "usb_bulk_msg_in: remaining(%zu), count(%zu)\n", remaining, count);
|
||||
|
||||
if (remaining > USBTMC_SIZE_IOBUFFER - USBTMC_HEADER_SIZE - 3)
|
||||
this_part = USBTMC_SIZE_IOBUFFER - USBTMC_HEADER_SIZE - 3;
|
||||
else
|
||||
this_part = remaining;
|
||||
|
||||
retval = send_request_dev_dep_msg_in(data, this_part);
|
||||
if (retval < 0) {
|
||||
dev_err(dev, "usb_bulk_msg returned %d\n", retval);
|
||||
if (data->auto_abort)
|
||||
usbtmc_ioctl_abort_bulk_out(data);
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
|
||||
/* Send bulk URB */
|
||||
retval = usb_bulk_msg(data->usb_dev,
|
||||
usb_rcvbulkpipe(data->usb_dev,
|
||||
|
@ -658,7 +625,7 @@ static ssize_t usbtmc_read(struct file *filp, char __user *buf,
|
|||
}
|
||||
|
||||
/* Parse header in first packet */
|
||||
if ((done == 0) || !data->rigol_quirk) {
|
||||
if (done == 0) {
|
||||
/* Sanity checks for the header */
|
||||
if (actual < USBTMC_HEADER_SIZE) {
|
||||
dev_err(dev, "Device sent too small first packet: %u < %u\n", actual, USBTMC_HEADER_SIZE);
|
||||
|
@ -698,20 +665,11 @@ static ssize_t usbtmc_read(struct file *filp, char __user *buf,
|
|||
actual -= USBTMC_HEADER_SIZE;
|
||||
|
||||
/* Check if the message is smaller than requested */
|
||||
if (data->rigol_quirk) {
|
||||
if (remaining > n_characters)
|
||||
remaining = n_characters;
|
||||
/* Remove padding if it exists */
|
||||
if (actual > remaining)
|
||||
actual = remaining;
|
||||
}
|
||||
else {
|
||||
if (this_part > n_characters)
|
||||
this_part = n_characters;
|
||||
/* Remove padding if it exists */
|
||||
if (actual > this_part)
|
||||
actual = this_part;
|
||||
}
|
||||
|
||||
dev_dbg(dev, "Bulk-IN header: N_characters(%u), bTransAttr(%u)\n", n_characters, buffer[8]);
|
||||
|
||||
|
@ -1365,7 +1323,6 @@ static int usbtmc_probe(struct usb_interface *intf,
|
|||
struct usbtmc_device_data *data;
|
||||
struct usb_host_interface *iface_desc;
|
||||
struct usb_endpoint_descriptor *bulk_in, *bulk_out, *int_in;
|
||||
int n;
|
||||
int retcode;
|
||||
|
||||
dev_dbg(&intf->dev, "%s called\n", __func__);
|
||||
|
@ -1385,20 +1342,6 @@ static int usbtmc_probe(struct usb_interface *intf,
|
|||
atomic_set(&data->srq_asserted, 0);
|
||||
data->zombie = 0;
|
||||
|
||||
/* Determine if it is a Rigol or not */
|
||||
data->rigol_quirk = 0;
|
||||
dev_dbg(&intf->dev, "Trying to find if device Vendor 0x%04X Product 0x%04X has the RIGOL quirk\n",
|
||||
le16_to_cpu(data->usb_dev->descriptor.idVendor),
|
||||
le16_to_cpu(data->usb_dev->descriptor.idProduct));
|
||||
for(n = 0; usbtmc_id_quirk[n].idVendor > 0; n++) {
|
||||
if ((usbtmc_id_quirk[n].idVendor == le16_to_cpu(data->usb_dev->descriptor.idVendor)) &&
|
||||
(usbtmc_id_quirk[n].idProduct == le16_to_cpu(data->usb_dev->descriptor.idProduct))) {
|
||||
dev_dbg(&intf->dev, "Setting this device as having the RIGOL quirk\n");
|
||||
data->rigol_quirk = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Initialize USBTMC bTag and other fields */
|
||||
data->bTag = 1;
|
||||
data->TermCharEnabled = 0;
|
||||
|
|
|
@ -33,7 +33,6 @@
|
|||
#include <linux/phy/phy.h>
|
||||
#include <linux/usb.h>
|
||||
#include <linux/usb/hcd.h>
|
||||
#include <linux/usb/phy.h>
|
||||
#include <linux/usb/otg.h>
|
||||
|
||||
#include "usb.h"
|
||||
|
@ -568,6 +567,7 @@ static int rh_call_control (struct usb_hcd *hcd, struct urb *urb)
|
|||
switch (wValue & 0xff00) {
|
||||
case USB_DT_DEVICE << 8:
|
||||
switch (hcd->speed) {
|
||||
case HCD_USB32:
|
||||
case HCD_USB31:
|
||||
bufp = usb31_rh_dev_descriptor;
|
||||
break;
|
||||
|
@ -592,6 +592,7 @@ static int rh_call_control (struct usb_hcd *hcd, struct urb *urb)
|
|||
break;
|
||||
case USB_DT_CONFIG << 8:
|
||||
switch (hcd->speed) {
|
||||
case HCD_USB32:
|
||||
case HCD_USB31:
|
||||
case HCD_USB3:
|
||||
bufp = ss_rh_config_descriptor;
|
||||
|
@ -2742,34 +2743,14 @@ int usb_add_hcd(struct usb_hcd *hcd,
|
|||
int retval;
|
||||
struct usb_device *rhdev;
|
||||
|
||||
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)) {
|
||||
retval = PTR_ERR(phy);
|
||||
if (retval == -EPROBE_DEFER)
|
||||
return retval;
|
||||
} else {
|
||||
retval = usb_phy_init(phy);
|
||||
if (retval) {
|
||||
usb_put_phy(phy);
|
||||
return retval;
|
||||
}
|
||||
hcd->usb_phy = phy;
|
||||
hcd->remove_phy = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (!hcd->skip_phy_initialization && usb_hcd_is_primary_hcd(hcd)) {
|
||||
hcd->phy_roothub = usb_phy_roothub_alloc(hcd->self.sysdev);
|
||||
if (IS_ERR(hcd->phy_roothub)) {
|
||||
retval = PTR_ERR(hcd->phy_roothub);
|
||||
goto err_phy_roothub_alloc;
|
||||
}
|
||||
if (IS_ERR(hcd->phy_roothub))
|
||||
return PTR_ERR(hcd->phy_roothub);
|
||||
|
||||
retval = usb_phy_roothub_init(hcd->phy_roothub);
|
||||
if (retval)
|
||||
goto err_phy_roothub_alloc;
|
||||
return retval;
|
||||
|
||||
retval = usb_phy_roothub_power_on(hcd->phy_roothub);
|
||||
if (retval)
|
||||
|
@ -2819,6 +2800,9 @@ int usb_add_hcd(struct usb_hcd *hcd,
|
|||
hcd->self.root_hub = rhdev;
|
||||
mutex_unlock(&usb_port_peer_mutex);
|
||||
|
||||
rhdev->rx_lanes = 1;
|
||||
rhdev->tx_lanes = 1;
|
||||
|
||||
switch (hcd->speed) {
|
||||
case HCD_USB11:
|
||||
rhdev->speed = USB_SPEED_FULL;
|
||||
|
@ -2832,6 +2816,10 @@ int usb_add_hcd(struct usb_hcd *hcd,
|
|||
case HCD_USB3:
|
||||
rhdev->speed = USB_SPEED_SUPER;
|
||||
break;
|
||||
case HCD_USB32:
|
||||
rhdev->rx_lanes = 2;
|
||||
rhdev->tx_lanes = 2;
|
||||
/* fall through */
|
||||
case HCD_USB31:
|
||||
rhdev->speed = USB_SPEED_SUPER_PLUS;
|
||||
break;
|
||||
|
@ -2943,12 +2931,7 @@ err_create_buf:
|
|||
usb_phy_roothub_power_off(hcd->phy_roothub);
|
||||
err_usb_phy_roothub_power_on:
|
||||
usb_phy_roothub_exit(hcd->phy_roothub);
|
||||
err_phy_roothub_alloc:
|
||||
if (hcd->remove_phy && hcd->usb_phy) {
|
||||
usb_phy_shutdown(hcd->usb_phy);
|
||||
usb_put_phy(hcd->usb_phy);
|
||||
hcd->usb_phy = NULL;
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(usb_add_hcd);
|
||||
|
@ -3024,12 +3007,6 @@ void usb_remove_hcd(struct usb_hcd *hcd)
|
|||
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);
|
||||
hcd->usb_phy = NULL;
|
||||
}
|
||||
|
||||
usb_put_invalidate_rhdev(hcd);
|
||||
hcd->flags = 0;
|
||||
}
|
||||
|
|
|
@ -2636,7 +2636,7 @@ static unsigned hub_is_wusb(struct usb_hub *hub)
|
|||
#define SET_ADDRESS_TRIES 2
|
||||
#define GET_DESCRIPTOR_TRIES 2
|
||||
#define SET_CONFIG_TRIES (2 * (use_both_schemes + 1))
|
||||
#define USE_NEW_SCHEME(i) ((i) / 2 == (int)old_scheme_first)
|
||||
#define USE_NEW_SCHEME(i, scheme) ((i) / 2 == (int)scheme)
|
||||
|
||||
#define HUB_ROOT_RESET_TIME 60 /* times are in msec */
|
||||
#define HUB_SHORT_RESET_TIME 10
|
||||
|
@ -2651,12 +2651,16 @@ static unsigned hub_is_wusb(struct usb_hub *hub)
|
|||
* enumeration failures, so disable this enumeration scheme for USB3
|
||||
* devices.
|
||||
*/
|
||||
static bool use_new_scheme(struct usb_device *udev, int retry)
|
||||
static bool use_new_scheme(struct usb_device *udev, int retry,
|
||||
struct usb_port *port_dev)
|
||||
{
|
||||
int old_scheme_first_port =
|
||||
port_dev->quirks & USB_PORT_QUIRK_OLD_SCHEME;
|
||||
|
||||
if (udev->speed >= USB_SPEED_SUPER)
|
||||
return false;
|
||||
|
||||
return USE_NEW_SCHEME(retry);
|
||||
return USE_NEW_SCHEME(retry, old_scheme_first_port || old_scheme_first);
|
||||
}
|
||||
|
||||
/* Is a USB 3.0 port in the Inactive or Compliance Mode state?
|
||||
|
@ -2751,6 +2755,14 @@ static int hub_port_wait_reset(struct usb_hub *hub, int port1,
|
|||
if (!udev)
|
||||
return 0;
|
||||
|
||||
if (hub_is_superspeedplus(hub->hdev)) {
|
||||
/* extended portstatus Rx and Tx lane count are zero based */
|
||||
udev->rx_lanes = USB_EXT_PORT_RX_LANES(ext_portstatus) + 1;
|
||||
udev->tx_lanes = USB_EXT_PORT_TX_LANES(ext_portstatus) + 1;
|
||||
} else {
|
||||
udev->rx_lanes = 1;
|
||||
udev->tx_lanes = 1;
|
||||
}
|
||||
if (hub_is_wusb(hub))
|
||||
udev->speed = USB_SPEED_WIRELESS;
|
||||
else if (hub_is_superspeedplus(hub->hdev) &&
|
||||
|
@ -2867,7 +2879,11 @@ static int hub_port_reset(struct usb_hub *hub, int port1,
|
|||
done:
|
||||
if (status == 0) {
|
||||
/* TRSTRCY = 10 ms; plus some extra */
|
||||
if (port_dev->quirks & USB_PORT_QUIRK_FAST_ENUM)
|
||||
usleep_range(10000, 12000);
|
||||
else
|
||||
msleep(10 + 40);
|
||||
|
||||
if (udev) {
|
||||
struct usb_hcd *hcd = bus_to_hcd(udev->bus);
|
||||
|
||||
|
@ -3376,6 +3392,10 @@ static int wait_for_connected(struct usb_device *udev,
|
|||
while (delay_ms < 2000) {
|
||||
if (status || *portstatus & USB_PORT_STAT_CONNECTION)
|
||||
break;
|
||||
if (!port_is_power_on(hub, *portstatus)) {
|
||||
status = -ENODEV;
|
||||
break;
|
||||
}
|
||||
msleep(20);
|
||||
delay_ms += 20;
|
||||
status = hub_port_status(hub, *port1, portstatus, portchange);
|
||||
|
@ -4380,6 +4400,7 @@ hub_port_init(struct usb_hub *hub, struct usb_device *udev, int port1,
|
|||
{
|
||||
struct usb_device *hdev = hub->hdev;
|
||||
struct usb_hcd *hcd = bus_to_hcd(hdev->bus);
|
||||
struct usb_port *port_dev = hub->ports[port1 - 1];
|
||||
int retries, operations, retval, i;
|
||||
unsigned delay = HUB_SHORT_RESET_TIME;
|
||||
enum usb_device_speed oldspeed = udev->speed;
|
||||
|
@ -4501,7 +4522,7 @@ hub_port_init(struct usb_hub *hub, struct usb_device *udev, int port1,
|
|||
for (retries = 0; retries < GET_DESCRIPTOR_TRIES; (++retries, msleep(100))) {
|
||||
bool did_new_scheme = false;
|
||||
|
||||
if (use_new_scheme(udev, retry_counter)) {
|
||||
if (use_new_scheme(udev, retry_counter, port_dev)) {
|
||||
struct usb_device_descriptor *buf;
|
||||
int r = 0;
|
||||
|
||||
|
@ -4551,7 +4572,9 @@ hub_port_init(struct usb_hub *hub, struct usb_device *udev, int port1,
|
|||
* reset. But only on the first attempt,
|
||||
* lest we get into a time out/reset loop
|
||||
*/
|
||||
if (r == 0 || (r == -ETIMEDOUT && retries == 0))
|
||||
if (r == 0 || (r == -ETIMEDOUT &&
|
||||
retries == 0 &&
|
||||
udev->speed > USB_SPEED_FULL))
|
||||
break;
|
||||
}
|
||||
udev->descriptor.bMaxPacketSize0 =
|
||||
|
@ -4598,9 +4621,12 @@ hub_port_init(struct usb_hub *hub, struct usb_device *udev, int port1,
|
|||
if (udev->speed >= USB_SPEED_SUPER) {
|
||||
devnum = udev->devnum;
|
||||
dev_info(&udev->dev,
|
||||
"%s SuperSpeed%s USB device number %d using %s\n",
|
||||
"%s SuperSpeed%s%s USB device number %d using %s\n",
|
||||
(udev->config) ? "reset" : "new",
|
||||
(udev->speed == USB_SPEED_SUPER_PLUS) ? "Plus" : "",
|
||||
(udev->speed == USB_SPEED_SUPER_PLUS) ?
|
||||
"Plus Gen 2" : " Gen 1",
|
||||
(udev->rx_lanes == 2 && udev->tx_lanes == 2) ?
|
||||
"x2" : "",
|
||||
devnum, driver_name);
|
||||
}
|
||||
|
||||
|
|
|
@ -98,6 +98,7 @@ struct usb_port {
|
|||
struct mutex status_lock;
|
||||
u32 over_current_count;
|
||||
u8 portnum;
|
||||
u32 quirks;
|
||||
unsigned int is_superspeed:1;
|
||||
unsigned int usb3_lpm_u1_permit:1;
|
||||
unsigned int usb3_lpm_u2_permit:1;
|
||||
|
|
|
@ -940,7 +940,7 @@ int usb_set_isoch_delay(struct usb_device *dev)
|
|||
return usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
|
||||
USB_REQ_SET_ISOCH_DELAY,
|
||||
USB_DIR_OUT | USB_TYPE_STANDARD | USB_RECIP_DEVICE,
|
||||
cpu_to_le16(dev->hub_delay), 0, NULL, 0,
|
||||
dev->hub_delay, 0, NULL, 0,
|
||||
USB_CTRL_SET_TIMEOUT);
|
||||
}
|
||||
|
||||
|
|
|
@ -50,6 +50,28 @@ static ssize_t over_current_count_show(struct device *dev,
|
|||
}
|
||||
static DEVICE_ATTR_RO(over_current_count);
|
||||
|
||||
static ssize_t quirks_show(struct device *dev,
|
||||
struct device_attribute *attr, char *buf)
|
||||
{
|
||||
struct usb_port *port_dev = to_usb_port(dev);
|
||||
|
||||
return sprintf(buf, "%08x\n", port_dev->quirks);
|
||||
}
|
||||
|
||||
static ssize_t quirks_store(struct device *dev, struct device_attribute *attr,
|
||||
const char *buf, size_t count)
|
||||
{
|
||||
struct usb_port *port_dev = to_usb_port(dev);
|
||||
u32 value;
|
||||
|
||||
if (kstrtou32(buf, 16, &value))
|
||||
return -EINVAL;
|
||||
|
||||
port_dev->quirks = value;
|
||||
return count;
|
||||
}
|
||||
static DEVICE_ATTR_RW(quirks);
|
||||
|
||||
static ssize_t usb3_lpm_permit_show(struct device *dev,
|
||||
struct device_attribute *attr, char *buf)
|
||||
{
|
||||
|
@ -118,6 +140,7 @@ static DEVICE_ATTR_RW(usb3_lpm_permit);
|
|||
|
||||
static struct attribute *port_dev_attrs[] = {
|
||||
&dev_attr_connect_type.attr,
|
||||
&dev_attr_quirks.attr,
|
||||
&dev_attr_over_current_count.attr,
|
||||
NULL,
|
||||
};
|
||||
|
|
|
@ -175,6 +175,26 @@ static ssize_t speed_show(struct device *dev, struct device_attribute *attr,
|
|||
}
|
||||
static DEVICE_ATTR_RO(speed);
|
||||
|
||||
static ssize_t rx_lanes_show(struct device *dev, struct device_attribute *attr,
|
||||
char *buf)
|
||||
{
|
||||
struct usb_device *udev;
|
||||
|
||||
udev = to_usb_device(dev);
|
||||
return sprintf(buf, "%d\n", udev->rx_lanes);
|
||||
}
|
||||
static DEVICE_ATTR_RO(rx_lanes);
|
||||
|
||||
static ssize_t tx_lanes_show(struct device *dev, struct device_attribute *attr,
|
||||
char *buf)
|
||||
{
|
||||
struct usb_device *udev;
|
||||
|
||||
udev = to_usb_device(dev);
|
||||
return sprintf(buf, "%d\n", udev->tx_lanes);
|
||||
}
|
||||
static DEVICE_ATTR_RO(tx_lanes);
|
||||
|
||||
static ssize_t busnum_show(struct device *dev, struct device_attribute *attr,
|
||||
char *buf)
|
||||
{
|
||||
|
@ -790,6 +810,8 @@ static struct attribute *dev_attrs[] = {
|
|||
&dev_attr_bNumConfigurations.attr,
|
||||
&dev_attr_bMaxPacketSize0.attr,
|
||||
&dev_attr_speed.attr,
|
||||
&dev_attr_rx_lanes.attr,
|
||||
&dev_attr_tx_lanes.attr,
|
||||
&dev_attr_busnum.attr,
|
||||
&dev_attr_devnum.attr,
|
||||
&dev_attr_devpath.attr,
|
||||
|
|
|
@ -1167,30 +1167,16 @@ static struct notifier_block usb_bus_nb = {
|
|||
struct dentry *usb_debug_root;
|
||||
EXPORT_SYMBOL_GPL(usb_debug_root);
|
||||
|
||||
static struct dentry *usb_debug_devices;
|
||||
|
||||
static int usb_debugfs_init(void)
|
||||
static void usb_debugfs_init(void)
|
||||
{
|
||||
usb_debug_root = debugfs_create_dir("usb", NULL);
|
||||
if (!usb_debug_root)
|
||||
return -ENOENT;
|
||||
|
||||
usb_debug_devices = debugfs_create_file("devices", 0444,
|
||||
usb_debug_root, NULL,
|
||||
debugfs_create_file("devices", 0444, usb_debug_root, NULL,
|
||||
&usbfs_devices_fops);
|
||||
if (!usb_debug_devices) {
|
||||
debugfs_remove(usb_debug_root);
|
||||
usb_debug_root = NULL;
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void usb_debugfs_cleanup(void)
|
||||
{
|
||||
debugfs_remove(usb_debug_devices);
|
||||
debugfs_remove(usb_debug_root);
|
||||
debugfs_remove_recursive(usb_debug_root);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -1205,9 +1191,7 @@ static int __init usb_init(void)
|
|||
}
|
||||
usb_init_pool_max();
|
||||
|
||||
retval = usb_debugfs_init();
|
||||
if (retval)
|
||||
goto out;
|
||||
usb_debugfs_init();
|
||||
|
||||
usb_acpi_register();
|
||||
retval = bus_register(&usb_bus_type);
|
||||
|
|
|
@ -419,6 +419,8 @@ static void dwc2_wait_for_mode(struct dwc2_hsotg *hsotg,
|
|||
/**
|
||||
* dwc2_iddig_filter_enabled() - Returns true if the IDDIG debounce
|
||||
* filter is enabled.
|
||||
*
|
||||
* @hsotg: Programming view of DWC_otg controller
|
||||
*/
|
||||
static bool dwc2_iddig_filter_enabled(struct dwc2_hsotg *hsotg)
|
||||
{
|
||||
|
@ -564,6 +566,9 @@ int dwc2_core_reset(struct dwc2_hsotg *hsotg, bool skip_wait)
|
|||
* If a force is done, it requires a IDDIG debounce filter delay if
|
||||
* the filter is configured and enabled. We poll the current mode of
|
||||
* the controller to account for this delay.
|
||||
*
|
||||
* @hsotg: Programming view of DWC_otg controller
|
||||
* @host: Host mode flag
|
||||
*/
|
||||
void dwc2_force_mode(struct dwc2_hsotg *hsotg, bool host)
|
||||
{
|
||||
|
@ -610,6 +615,8 @@ void dwc2_force_mode(struct dwc2_hsotg *hsotg, bool host)
|
|||
* or not because the value of the connector ID status is affected by
|
||||
* the force mode. We only need to call this once during probe if
|
||||
* dr_mode == OTG.
|
||||
*
|
||||
* @hsotg: Programming view of DWC_otg controller
|
||||
*/
|
||||
static void dwc2_clear_force_mode(struct dwc2_hsotg *hsotg)
|
||||
{
|
||||
|
|
|
@ -164,12 +164,11 @@ struct dwc2_hsotg_req;
|
|||
* and has yet to be completed (maybe due to data move, or simply
|
||||
* awaiting an ack from the core all the data has been completed).
|
||||
* @debugfs: File entry for debugfs file for this endpoint.
|
||||
* @lock: State lock to protect contents of endpoint.
|
||||
* @dir_in: Set to true if this endpoint is of the IN direction, which
|
||||
* means that it is sending data to the Host.
|
||||
* @index: The index for the endpoint registers.
|
||||
* @mc: Multi Count - number of transactions per microframe
|
||||
* @interval - Interval for periodic endpoints, in frames or microframes.
|
||||
* @interval: Interval for periodic endpoints, in frames or microframes.
|
||||
* @name: The name array passed to the USB core.
|
||||
* @halted: Set if the endpoint has been halted.
|
||||
* @periodic: Set if this is a periodic ep, such as Interrupt
|
||||
|
@ -178,10 +177,11 @@ struct dwc2_hsotg_req;
|
|||
* @desc_list_dma: The DMA address of descriptor chain currently in use.
|
||||
* @desc_list: Pointer to descriptor DMA chain head currently in use.
|
||||
* @desc_count: Count of entries within the DMA descriptor chain of EP.
|
||||
* @isoc_chain_num: Number of ISOC chain currently in use - either 0 or 1.
|
||||
* @next_desc: index of next free descriptor in the ISOC chain under SW control.
|
||||
* @compl_desc: index of next descriptor to be completed by xFerComplete
|
||||
* @total_data: The total number of data bytes done.
|
||||
* @fifo_size: The size of the FIFO (for periodic IN endpoints)
|
||||
* @fifo_index: For Dedicated FIFO operation, only FIFO0 can be used for EP0.
|
||||
* @fifo_load: The amount of data loaded into the FIFO (periodic IN)
|
||||
* @last_load: The offset of data for the last start of request.
|
||||
* @size_loaded: The last loaded size for DxEPTSIZE for periodic IN
|
||||
|
@ -231,8 +231,8 @@ struct dwc2_hsotg_ep {
|
|||
struct dwc2_dma_desc *desc_list;
|
||||
u8 desc_count;
|
||||
|
||||
unsigned char isoc_chain_num;
|
||||
unsigned int next_desc;
|
||||
unsigned int compl_desc;
|
||||
|
||||
char name[10];
|
||||
};
|
||||
|
@ -380,6 +380,12 @@ enum dwc2_ep0_state {
|
|||
* is FS.
|
||||
* 0 - No (default)
|
||||
* 1 - Yes
|
||||
* @ipg_isoc_en: Indicates the IPG supports is enabled or disabled.
|
||||
* 0 - Disable (default)
|
||||
* 1 - Enable
|
||||
* @acg_enable: For enabling Active Clock Gating in the controller
|
||||
* 0 - No
|
||||
* 1 - Yes
|
||||
* @ulpi_fs_ls: Make ULPI phy operate in FS/LS mode only
|
||||
* 0 - No (default)
|
||||
* 1 - Yes
|
||||
|
@ -511,6 +517,7 @@ struct dwc2_core_params {
|
|||
bool hird_threshold_en;
|
||||
u8 hird_threshold;
|
||||
bool activate_stm_fs_transceiver;
|
||||
bool ipg_isoc_en;
|
||||
u16 max_packet_count;
|
||||
u32 max_transfer_size;
|
||||
u32 ahbcfg;
|
||||
|
@ -548,7 +555,7 @@ struct dwc2_core_params {
|
|||
*
|
||||
* The values that are not in dwc2_core_params are documented below.
|
||||
*
|
||||
* @op_mode Mode of Operation
|
||||
* @op_mode: Mode of Operation
|
||||
* 0 - HNP- and SRP-Capable OTG (Host & Device)
|
||||
* 1 - SRP-Capable OTG (Host & Device)
|
||||
* 2 - Non-HNP and Non-SRP Capable OTG (Host & Device)
|
||||
|
@ -556,43 +563,102 @@ struct dwc2_core_params {
|
|||
* 4 - Non-OTG Device
|
||||
* 5 - SRP-Capable Host
|
||||
* 6 - Non-OTG Host
|
||||
* @arch Architecture
|
||||
* @arch: Architecture
|
||||
* 0 - Slave only
|
||||
* 1 - External DMA
|
||||
* 2 - Internal DMA
|
||||
* @power_optimized Are power optimizations enabled?
|
||||
* @num_dev_ep Number of device endpoints available
|
||||
* @num_dev_in_eps Number of device IN endpoints available
|
||||
* @num_dev_perio_in_ep Number of device periodic IN endpoints
|
||||
* @ipg_isoc_en: This feature indicates that the controller supports
|
||||
* the worst-case scenario of Rx followed by Rx
|
||||
* Interpacket Gap (IPG) (32 bitTimes) as per the utmi
|
||||
* specification for any token following ISOC OUT token.
|
||||
* 0 - Don't support
|
||||
* 1 - Support
|
||||
* @power_optimized: Are power optimizations enabled?
|
||||
* @num_dev_ep: Number of device endpoints available
|
||||
* @num_dev_in_eps: Number of device IN endpoints available
|
||||
* @num_dev_perio_in_ep: Number of device periodic IN endpoints
|
||||
* available
|
||||
* @dev_token_q_depth Device Mode IN Token Sequence Learning Queue
|
||||
* @dev_token_q_depth: Device Mode IN Token Sequence Learning Queue
|
||||
* Depth
|
||||
* 0 to 30
|
||||
* @host_perio_tx_q_depth
|
||||
* @host_perio_tx_q_depth:
|
||||
* Host Mode Periodic Request Queue Depth
|
||||
* 2, 4 or 8
|
||||
* @nperio_tx_q_depth
|
||||
* @nperio_tx_q_depth:
|
||||
* Non-Periodic Request Queue Depth
|
||||
* 2, 4 or 8
|
||||
* @hs_phy_type High-speed PHY interface type
|
||||
* @hs_phy_type: High-speed PHY interface type
|
||||
* 0 - High-speed interface not supported
|
||||
* 1 - UTMI+
|
||||
* 2 - ULPI
|
||||
* 3 - UTMI+ and ULPI
|
||||
* @fs_phy_type Full-speed PHY interface type
|
||||
* @fs_phy_type: Full-speed PHY interface type
|
||||
* 0 - Full speed interface not supported
|
||||
* 1 - Dedicated full speed interface
|
||||
* 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
|
||||
* @hibernation: Is hibernation enabled?
|
||||
* @utmi_phy_data_width: UTMI+ PHY data width
|
||||
* 0 - 8 bits
|
||||
* 1 - 16 bits
|
||||
* 2 - 8 or 16 bits
|
||||
* @snpsid: Value from SNPSID register
|
||||
* @dev_ep_dirs: Direction of device endpoints (GHWCFG1)
|
||||
* @g_tx_fifo_size[] Power-on values of TxFIFO sizes
|
||||
* @g_tx_fifo_size: Power-on values of TxFIFO sizes
|
||||
* @dma_desc_enable: When DMA mode is enabled, specifies whether to use
|
||||
* address DMA mode or descriptor DMA mode for accessing
|
||||
* the data FIFOs. The driver will automatically detect the
|
||||
* value for this if none is specified.
|
||||
* 0 - Address DMA
|
||||
* 1 - Descriptor DMA (default, if available)
|
||||
* @enable_dynamic_fifo: 0 - Use coreConsultant-specified FIFO size parameters
|
||||
* 1 - Allow dynamic FIFO sizing (default, if available)
|
||||
* @en_multiple_tx_fifo: Specifies whether dedicated per-endpoint transmit FIFOs
|
||||
* are enabled for non-periodic IN endpoints in device
|
||||
* mode.
|
||||
* @host_nperio_tx_fifo_size: Number of 4-byte words in the non-periodic Tx FIFO
|
||||
* in host mode when dynamic FIFO sizing is enabled
|
||||
* 16 to 32768
|
||||
* Actual maximum value is autodetected and also
|
||||
* the default.
|
||||
* @host_perio_tx_fifo_size: Number of 4-byte words in the periodic Tx FIFO in
|
||||
* host mode when dynamic FIFO sizing is enabled
|
||||
* 16 to 32768
|
||||
* Actual maximum value is autodetected and also
|
||||
* the default.
|
||||
* @max_transfer_size: The maximum transfer size supported, in bytes
|
||||
* 2047 to 65,535
|
||||
* Actual maximum value is autodetected and also
|
||||
* the default.
|
||||
* @max_packet_count: The maximum number of packets in a transfer
|
||||
* 15 to 511
|
||||
* Actual maximum value is autodetected and also
|
||||
* the default.
|
||||
* @host_channels: The number of host channel registers to use
|
||||
* 1 to 16
|
||||
* Actual maximum value is autodetected and also
|
||||
* the default.
|
||||
* @dev_nperio_tx_fifo_size: Number of 4-byte words in the non-periodic Tx FIFO
|
||||
* in device mode when dynamic FIFO sizing is enabled
|
||||
* 16 to 32768
|
||||
* Actual maximum value is autodetected and also
|
||||
* the default.
|
||||
* @i2c_enable: Specifies whether to use the I2Cinterface for a full
|
||||
* speed PHY. This parameter is only applicable if phy_type
|
||||
* is FS.
|
||||
* 0 - No (default)
|
||||
* 1 - Yes
|
||||
* @acg_enable: For enabling Active Clock Gating in the controller
|
||||
* 0 - Disable
|
||||
* 1 - Enable
|
||||
* @lpm_mode: For enabling Link Power Management in the controller
|
||||
* 0 - Disable
|
||||
* 1 - Enable
|
||||
* @rx_fifo_size: Number of 4-byte words in the Rx FIFO when dynamic
|
||||
* FIFO sizing is enabled 16 to 32768
|
||||
* Actual maximum value is autodetected and also
|
||||
* the default.
|
||||
*/
|
||||
struct dwc2_hw_params {
|
||||
unsigned op_mode:3;
|
||||
|
@ -622,6 +688,7 @@ struct dwc2_hw_params {
|
|||
unsigned hibernation:1;
|
||||
unsigned utmi_phy_data_width:2;
|
||||
unsigned lpm_mode:1;
|
||||
unsigned ipg_isoc_en:1;
|
||||
u32 snpsid;
|
||||
u32 dev_ep_dirs;
|
||||
u32 g_tx_fifo_size[MAX_EPS_CHANNELS];
|
||||
|
@ -642,7 +709,11 @@ struct dwc2_hw_params {
|
|||
* @gi2cctl: Backup of GI2CCTL register
|
||||
* @glpmcfg: Backup of GLPMCFG register
|
||||
* @gdfifocfg: Backup of GDFIFOCFG register
|
||||
* @pcgcctl: Backup of PCGCCTL register
|
||||
* @pcgcctl1: Backup of PCGCCTL1 register
|
||||
* @dtxfsiz: Backup of DTXFSIZ registers for each endpoint
|
||||
* @gpwrdn: Backup of GPWRDN register
|
||||
* @valid: True if registers values backuped.
|
||||
*/
|
||||
struct dwc2_gregs_backup {
|
||||
u32 gotgctl;
|
||||
|
@ -675,6 +746,7 @@ struct dwc2_gregs_backup {
|
|||
* @doeptsiz: Backup of DOEPTSIZ register
|
||||
* @doepdma: Backup of DOEPDMA register
|
||||
* @dtxfsiz: Backup of DTXFSIZ registers for each endpoint
|
||||
* @valid: True if registers values backuped.
|
||||
*/
|
||||
struct dwc2_dregs_backup {
|
||||
u32 dcfg;
|
||||
|
@ -698,9 +770,10 @@ struct dwc2_dregs_backup {
|
|||
* @hcfg: Backup of HCFG register
|
||||
* @haintmsk: Backup of HAINTMSK register
|
||||
* @hcintmsk: Backup of HCINTMSK register
|
||||
* @hptr0: Backup of HPTR0 register
|
||||
* @hprt0: Backup of HPTR0 register
|
||||
* @hfir: Backup of HFIR register
|
||||
* @hptxfsiz: Backup of HPTXFSIZ register
|
||||
* @valid: True if registers values backuped.
|
||||
*/
|
||||
struct dwc2_hregs_backup {
|
||||
u32 hcfg;
|
||||
|
@ -800,7 +873,7 @@ struct dwc2_hregs_backup {
|
|||
* @regs: Pointer to controller regs
|
||||
* @hw_params: Parameters that were autodetected from the
|
||||
* hardware registers
|
||||
* @core_params: Parameters that define how the core should be configured
|
||||
* @params: Parameters that define how the core should be configured
|
||||
* @op_state: The operational State, during transitions (a_host=>
|
||||
* a_peripheral and b_device=>b_host) this may not match
|
||||
* the core, but allows the software to determine
|
||||
|
@ -809,10 +882,13 @@ struct dwc2_hregs_backup {
|
|||
* - USB_DR_MODE_PERIPHERAL
|
||||
* - USB_DR_MODE_HOST
|
||||
* - USB_DR_MODE_OTG
|
||||
* @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.
|
||||
* @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
|
||||
* @frame_number: Frame number read from the core. For both device
|
||||
* and host modes. The value ranges are from 0
|
||||
* to HFNUM_MAX_FRNUM.
|
||||
* @phy: The otg phy transceiver structure for phy control.
|
||||
* @uphy: The otg phy transceiver structure for old USB phy
|
||||
* control.
|
||||
|
@ -832,13 +908,25 @@ struct dwc2_hregs_backup {
|
|||
* interrupt
|
||||
* @wkp_timer: Timer object for handling Wakeup Detected interrupt
|
||||
* @lx_state: Lx state of connected device
|
||||
* @gregs_backup: Backup of global registers during suspend
|
||||
* @dregs_backup: Backup of device registers during suspend
|
||||
* @hregs_backup: Backup of host registers during suspend
|
||||
* @gr_backup: Backup of global registers during suspend
|
||||
* @dr_backup: Backup of device registers during suspend
|
||||
* @hr_backup: Backup of host registers during suspend
|
||||
*
|
||||
* These are for host mode:
|
||||
*
|
||||
* @flags: Flags for handling root port state changes
|
||||
* @flags.d32: Contain all root port flags
|
||||
* @flags.b: Separate root port flags from each other
|
||||
* @flags.b.port_connect_status_change: True if root port connect status
|
||||
* changed
|
||||
* @flags.b.port_connect_status: True if device connected to root port
|
||||
* @flags.b.port_reset_change: True if root port reset status changed
|
||||
* @flags.b.port_enable_change: True if root port enable status changed
|
||||
* @flags.b.port_suspend_change: True if root port suspend status changed
|
||||
* @flags.b.port_over_current_change: True if root port over current state
|
||||
* changed.
|
||||
* @flags.b.port_l1_change: True if root port l1 status changed
|
||||
* @flags.b.reserved: Reserved bits of root port register
|
||||
* @non_periodic_sched_inactive: Inactive QHs in the non-periodic schedule.
|
||||
* Transfers associated with these QHs are not currently
|
||||
* assigned to a host channel.
|
||||
|
@ -847,6 +935,9 @@ struct dwc2_hregs_backup {
|
|||
* assigned to a host channel.
|
||||
* @non_periodic_qh_ptr: Pointer to next QH to process in the active
|
||||
* non-periodic schedule
|
||||
* @non_periodic_sched_waiting: Waiting QHs in the non-periodic schedule.
|
||||
* Transfers associated with these QHs are not currently
|
||||
* assigned to a host channel.
|
||||
* @periodic_sched_inactive: Inactive QHs in the periodic schedule. This is a
|
||||
* list of QHs for periodic transfers that are _not_
|
||||
* scheduled for the next frame. Each QH in the list has an
|
||||
|
@ -886,8 +977,6 @@ struct dwc2_hregs_backup {
|
|||
* @hs_periodic_bitmap: Bitmap used by the microframe scheduler any time the
|
||||
* host is in high speed mode; low speed schedules are
|
||||
* stored elsewhere since we need one per TT.
|
||||
* @frame_number: Frame number read from the core at SOF. The value ranges
|
||||
* from 0 to HFNUM_MAX_FRNUM.
|
||||
* @periodic_qh_count: Count of periodic QHs, if using several eps. Used for
|
||||
* SOF enable/disable.
|
||||
* @free_hc_list: Free host channels in the controller. This is a list of
|
||||
|
@ -898,8 +987,8 @@ struct dwc2_hregs_backup {
|
|||
* host channel is available for non-periodic transactions.
|
||||
* @non_periodic_channels: Number of host channels assigned to non-periodic
|
||||
* transfers
|
||||
* @available_host_channels Number of host channels available for the microframe
|
||||
* scheduler to use
|
||||
* @available_host_channels: Number of host channels available for the
|
||||
* microframe scheduler to use
|
||||
* @hc_ptr_array: Array of pointers to the host channel descriptors.
|
||||
* Allows accessing a host channel descriptor given the
|
||||
* host channel number. This is useful in interrupt
|
||||
|
@ -922,9 +1011,6 @@ struct dwc2_hregs_backup {
|
|||
* @dedicated_fifos: Set if the hardware has dedicated IN-EP fifos.
|
||||
* @num_of_eps: Number of available EPs (excluding EP0)
|
||||
* @debug_root: Root directrory for debugfs.
|
||||
* @debug_file: Main status file for debugfs.
|
||||
* @debug_testmode: Testmode status file for debugfs.
|
||||
* @debug_fifo: FIFO status file for debugfs.
|
||||
* @ep0_reply: Request used for ep0 reply.
|
||||
* @ep0_buff: Buffer for EP0 reply data, if needed.
|
||||
* @ctrl_buff: Buffer for EP0 control requests.
|
||||
|
@ -939,7 +1025,37 @@ struct dwc2_hregs_backup {
|
|||
* @ctrl_in_desc: EP0 IN data phase desc chain pointer
|
||||
* @ctrl_out_desc_dma: EP0 OUT data phase desc chain DMA address
|
||||
* @ctrl_out_desc: EP0 OUT data phase desc chain pointer
|
||||
* @eps: The endpoints being supplied to the gadget framework
|
||||
* @irq: Interrupt request line number
|
||||
* @clk: Pointer to otg clock
|
||||
* @reset: Pointer to dwc2 reset controller
|
||||
* @reset_ecc: Pointer to dwc2 optional reset controller in Stratix10.
|
||||
* @regset: A pointer to a struct debugfs_regset32, which contains
|
||||
* a pointer to an array of register definitions, the
|
||||
* array size and the base address where the register bank
|
||||
* is to be found.
|
||||
* @bus_suspended: True if bus is suspended
|
||||
* @last_frame_num: Number of last frame. Range from 0 to 32768
|
||||
* @frame_num_array: Used only if CONFIG_USB_DWC2_TRACK_MISSED_SOFS is
|
||||
* defined, for missed SOFs tracking. Array holds that
|
||||
* frame numbers, which not equal to last_frame_num +1
|
||||
* @last_frame_num_array: Used only if CONFIG_USB_DWC2_TRACK_MISSED_SOFS is
|
||||
* defined, for missed SOFs tracking.
|
||||
* If current_frame_number != last_frame_num+1
|
||||
* then last_frame_num added to this array
|
||||
* @frame_num_idx: Actual size of frame_num_array and last_frame_num_array
|
||||
* @dumped_frame_num_array: 1 - if missed SOFs frame numbers dumbed
|
||||
* 0 - if missed SOFs frame numbers not dumbed
|
||||
* @fifo_mem: Total internal RAM for FIFOs (bytes)
|
||||
* @fifo_map: Each bit intend for concrete fifo. If that bit is set,
|
||||
* then that fifo is used
|
||||
* @gadget: Represents a usb slave device
|
||||
* @connected: Used in slave mode. True if device connected with host
|
||||
* @eps_in: The IN endpoints being supplied to the gadget framework
|
||||
* @eps_out: The OUT endpoints being supplied to the gadget framework
|
||||
* @new_connection: Used in host mode. True if there are new connected
|
||||
* device
|
||||
* @enabled: Indicates the enabling state of controller
|
||||
*
|
||||
*/
|
||||
struct dwc2_hsotg {
|
||||
struct device *dev;
|
||||
|
@ -954,6 +1070,7 @@ struct dwc2_hsotg {
|
|||
unsigned int gadget_enabled:1;
|
||||
unsigned int ll_hw_enabled:1;
|
||||
unsigned int hibernated:1;
|
||||
u16 frame_number;
|
||||
|
||||
struct phy *phy;
|
||||
struct usb_phy *uphy;
|
||||
|
@ -1029,7 +1146,6 @@ struct dwc2_hsotg {
|
|||
u16 periodic_usecs;
|
||||
unsigned long hs_periodic_bitmap[
|
||||
DIV_ROUND_UP(DWC2_HS_SCHEDULE_US, BITS_PER_LONG)];
|
||||
u16 frame_number;
|
||||
u16 periodic_qh_count;
|
||||
bool bus_suspended;
|
||||
bool new_connection;
|
||||
|
|
|
@ -778,6 +778,14 @@ irqreturn_t dwc2_handle_common_intr(int irq, void *dev)
|
|||
goto out;
|
||||
}
|
||||
|
||||
/* Reading current frame number value in device or host modes. */
|
||||
if (dwc2_is_device_mode(hsotg))
|
||||
hsotg->frame_number = (dwc2_readl(hsotg->regs + DSTS)
|
||||
& DSTS_SOFFN_MASK) >> DSTS_SOFFN_SHIFT;
|
||||
else
|
||||
hsotg->frame_number = (dwc2_readl(hsotg->regs + HFNUM)
|
||||
& HFNUM_FRNUM_MASK) >> HFNUM_FRNUM_SHIFT;
|
||||
|
||||
gintsts = dwc2_read_common_intr(hsotg);
|
||||
if (gintsts & ~GINTSTS_PRTINT)
|
||||
retval = IRQ_HANDLED;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// SPDX-License-Identifier: GPL-2.0
|
||||
/**
|
||||
/*
|
||||
* debug.h - Designware USB2 DRD controller debug header
|
||||
*
|
||||
* Copyright (C) 2015 Intel Corporation
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// SPDX-License-Identifier: GPL-2.0
|
||||
/**
|
||||
/*
|
||||
* debugfs.c - Designware USB2 DRD controller debugfs
|
||||
*
|
||||
* Copyright (C) 2015 Intel Corporation
|
||||
|
@ -16,12 +16,13 @@
|
|||
|
||||
#if IS_ENABLED(CONFIG_USB_DWC2_PERIPHERAL) || \
|
||||
IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE)
|
||||
|
||||
/**
|
||||
* testmode_write - debugfs: change usb test mode
|
||||
* @seq: The seq file to write to.
|
||||
* @v: Unused parameter.
|
||||
*
|
||||
* This debugfs entry modify the current usb test mode.
|
||||
* testmode_write() - change usb test mode state.
|
||||
* @file: The file to write to.
|
||||
* @ubuf: The buffer where user wrote.
|
||||
* @count: The ubuf size.
|
||||
* @ppos: Unused parameter.
|
||||
*/
|
||||
static ssize_t testmode_write(struct file *file, const char __user *ubuf, size_t
|
||||
count, loff_t *ppos)
|
||||
|
@ -55,9 +56,9 @@ static ssize_t testmode_write(struct file *file, const char __user *ubuf, size_t
|
|||
}
|
||||
|
||||
/**
|
||||
* testmode_show - debugfs: show usb test mode state
|
||||
* @seq: The seq file to write to.
|
||||
* @v: Unused parameter.
|
||||
* testmode_show() - debugfs: show usb test mode state
|
||||
* @s: The seq file to write to.
|
||||
* @unused: Unused parameter.
|
||||
*
|
||||
* This debugfs entry shows which usb test mode is currently enabled.
|
||||
*/
|
||||
|
@ -293,52 +294,30 @@ DEFINE_SHOW_ATTRIBUTE(ep);
|
|||
static void dwc2_hsotg_create_debug(struct dwc2_hsotg *hsotg)
|
||||
{
|
||||
struct dentry *root;
|
||||
struct dentry *file;
|
||||
unsigned int epidx;
|
||||
|
||||
root = hsotg->debug_root;
|
||||
|
||||
/* create general state file */
|
||||
|
||||
file = debugfs_create_file("state", 0444, root, hsotg, &state_fops);
|
||||
if (IS_ERR(file))
|
||||
dev_err(hsotg->dev, "%s: failed to create state\n", __func__);
|
||||
|
||||
file = debugfs_create_file("testmode", 0644, root, hsotg,
|
||||
&testmode_fops);
|
||||
if (IS_ERR(file))
|
||||
dev_err(hsotg->dev, "%s: failed to create testmode\n",
|
||||
__func__);
|
||||
|
||||
file = debugfs_create_file("fifo", 0444, root, hsotg, &fifo_fops);
|
||||
if (IS_ERR(file))
|
||||
dev_err(hsotg->dev, "%s: failed to create fifo\n", __func__);
|
||||
debugfs_create_file("state", 0444, root, hsotg, &state_fops);
|
||||
debugfs_create_file("testmode", 0644, root, hsotg, &testmode_fops);
|
||||
debugfs_create_file("fifo", 0444, root, hsotg, &fifo_fops);
|
||||
|
||||
/* Create one file for each out endpoint */
|
||||
for (epidx = 0; epidx < hsotg->num_of_eps; epidx++) {
|
||||
struct dwc2_hsotg_ep *ep;
|
||||
|
||||
ep = hsotg->eps_out[epidx];
|
||||
if (ep) {
|
||||
file = debugfs_create_file(ep->name, 0444,
|
||||
root, ep, &ep_fops);
|
||||
if (IS_ERR(file))
|
||||
dev_err(hsotg->dev, "failed to create %s debug file\n",
|
||||
ep->name);
|
||||
}
|
||||
if (ep)
|
||||
debugfs_create_file(ep->name, 0444, root, ep, &ep_fops);
|
||||
}
|
||||
/* Create one file for each in endpoint. EP0 is handled with out eps */
|
||||
for (epidx = 1; epidx < hsotg->num_of_eps; epidx++) {
|
||||
struct dwc2_hsotg_ep *ep;
|
||||
|
||||
ep = hsotg->eps_in[epidx];
|
||||
if (ep) {
|
||||
file = debugfs_create_file(ep->name, 0444,
|
||||
root, ep, &ep_fops);
|
||||
if (IS_ERR(file))
|
||||
dev_err(hsotg->dev, "failed to create %s debug file\n",
|
||||
ep->name);
|
||||
}
|
||||
if (ep)
|
||||
debugfs_create_file(ep->name, 0444, root, ep, &ep_fops);
|
||||
}
|
||||
}
|
||||
#else
|
||||
|
@ -368,7 +347,7 @@ static const struct debugfs_reg32 dwc2_regs[] = {
|
|||
dump_register(GINTSTS),
|
||||
dump_register(GINTMSK),
|
||||
dump_register(GRXSTSR),
|
||||
dump_register(GRXSTSP),
|
||||
/* Omit GRXSTSP */
|
||||
dump_register(GRXFSIZ),
|
||||
dump_register(GNPTXFSIZ),
|
||||
dump_register(GNPTXSTS),
|
||||
|
@ -710,6 +689,7 @@ static int params_show(struct seq_file *seq, void *v)
|
|||
print_param(seq, p, phy_ulpi_ddr);
|
||||
print_param(seq, p, phy_ulpi_ext_vbus);
|
||||
print_param(seq, p, i2c_enable);
|
||||
print_param(seq, p, ipg_isoc_en);
|
||||
print_param(seq, p, ulpi_fs_ls);
|
||||
print_param(seq, p, host_support_fs_ls_low_power);
|
||||
print_param(seq, p, host_ls_low_power_phy_clk);
|
||||
|
@ -790,32 +770,14 @@ DEFINE_SHOW_ATTRIBUTE(dr_mode);
|
|||
int dwc2_debugfs_init(struct dwc2_hsotg *hsotg)
|
||||
{
|
||||
int ret;
|
||||
struct dentry *file;
|
||||
struct dentry *root;
|
||||
|
||||
hsotg->debug_root = debugfs_create_dir(dev_name(hsotg->dev), NULL);
|
||||
if (!hsotg->debug_root) {
|
||||
ret = -ENOMEM;
|
||||
goto err0;
|
||||
}
|
||||
root = debugfs_create_dir(dev_name(hsotg->dev), NULL);
|
||||
hsotg->debug_root = root;
|
||||
|
||||
file = debugfs_create_file("params", 0444,
|
||||
hsotg->debug_root,
|
||||
hsotg, ¶ms_fops);
|
||||
if (IS_ERR(file))
|
||||
dev_err(hsotg->dev, "%s: failed to create params\n", __func__);
|
||||
|
||||
file = debugfs_create_file("hw_params", 0444,
|
||||
hsotg->debug_root,
|
||||
hsotg, &hw_params_fops);
|
||||
if (IS_ERR(file))
|
||||
dev_err(hsotg->dev, "%s: failed to create hw_params\n",
|
||||
__func__);
|
||||
|
||||
file = debugfs_create_file("dr_mode", 0444,
|
||||
hsotg->debug_root,
|
||||
hsotg, &dr_mode_fops);
|
||||
if (IS_ERR(file))
|
||||
dev_err(hsotg->dev, "%s: failed to create dr_mode\n", __func__);
|
||||
debugfs_create_file("params", 0444, root, hsotg, ¶ms_fops);
|
||||
debugfs_create_file("hw_params", 0444, root, hsotg, &hw_params_fops);
|
||||
debugfs_create_file("dr_mode", 0444, root, hsotg, &dr_mode_fops);
|
||||
|
||||
/* Add gadget debugfs nodes */
|
||||
dwc2_hsotg_create_debug(hsotg);
|
||||
|
@ -824,24 +786,18 @@ int dwc2_debugfs_init(struct dwc2_hsotg *hsotg)
|
|||
GFP_KERNEL);
|
||||
if (!hsotg->regset) {
|
||||
ret = -ENOMEM;
|
||||
goto err1;
|
||||
goto err;
|
||||
}
|
||||
|
||||
hsotg->regset->regs = dwc2_regs;
|
||||
hsotg->regset->nregs = ARRAY_SIZE(dwc2_regs);
|
||||
hsotg->regset->base = hsotg->regs;
|
||||
|
||||
file = debugfs_create_regset32("regdump", 0444, hsotg->debug_root,
|
||||
hsotg->regset);
|
||||
if (!file) {
|
||||
ret = -ENOMEM;
|
||||
goto err1;
|
||||
}
|
||||
debugfs_create_regset32("regdump", 0444, root, hsotg->regset);
|
||||
|
||||
return 0;
|
||||
err1:
|
||||
err:
|
||||
debugfs_remove_recursive(hsotg->debug_root);
|
||||
err0:
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// SPDX-License-Identifier: GPL-2.0
|
||||
/**
|
||||
/*
|
||||
* Copyright (c) 2011 Samsung Electronics Co., Ltd.
|
||||
* http://www.samsung.com
|
||||
*
|
||||
|
@ -107,7 +107,6 @@ static inline bool using_desc_dma(struct dwc2_hsotg *hsotg)
|
|||
/**
|
||||
* dwc2_gadget_incr_frame_num - Increments the targeted frame number.
|
||||
* @hs_ep: The endpoint
|
||||
* @increment: The value to increment by
|
||||
*
|
||||
* This function will also check if the frame number overruns DSTS_SOFFN_LIMIT.
|
||||
* If an overrun occurs it will wrap the value and set the frame_overrun flag.
|
||||
|
@ -190,6 +189,8 @@ static void dwc2_hsotg_ctrl_epint(struct dwc2_hsotg *hsotg,
|
|||
|
||||
/**
|
||||
* dwc2_hsotg_tx_fifo_count - return count of TX FIFOs in device mode
|
||||
*
|
||||
* @hsotg: Programming view of the DWC_otg controller
|
||||
*/
|
||||
int dwc2_hsotg_tx_fifo_count(struct dwc2_hsotg *hsotg)
|
||||
{
|
||||
|
@ -204,6 +205,8 @@ int dwc2_hsotg_tx_fifo_count(struct dwc2_hsotg *hsotg)
|
|||
/**
|
||||
* dwc2_hsotg_tx_fifo_total_depth - return total FIFO depth available for
|
||||
* device mode TX FIFOs
|
||||
*
|
||||
* @hsotg: Programming view of the DWC_otg controller
|
||||
*/
|
||||
int dwc2_hsotg_tx_fifo_total_depth(struct dwc2_hsotg *hsotg)
|
||||
{
|
||||
|
@ -227,6 +230,8 @@ int dwc2_hsotg_tx_fifo_total_depth(struct dwc2_hsotg *hsotg)
|
|||
/**
|
||||
* dwc2_hsotg_tx_fifo_average_depth - returns average depth of device mode
|
||||
* TX FIFOs
|
||||
*
|
||||
* @hsotg: Programming view of the DWC_otg controller
|
||||
*/
|
||||
int dwc2_hsotg_tx_fifo_average_depth(struct dwc2_hsotg *hsotg)
|
||||
{
|
||||
|
@ -327,6 +332,7 @@ static void dwc2_hsotg_init_fifo(struct dwc2_hsotg *hsotg)
|
|||
}
|
||||
|
||||
/**
|
||||
* dwc2_hsotg_ep_alloc_request - allocate USB rerequest structure
|
||||
* @ep: USB endpoint to allocate request for.
|
||||
* @flags: Allocation flags
|
||||
*
|
||||
|
@ -793,9 +799,7 @@ static void dwc2_gadget_config_nonisoc_xfer_ddma(struct dwc2_hsotg_ep *hs_ep,
|
|||
* @dma_buff: usb requests dma buffer.
|
||||
* @len: usb request transfer length.
|
||||
*
|
||||
* Finds out index of first free entry either in the bottom or up half of
|
||||
* descriptor chain depend on which is under SW control and not processed
|
||||
* by HW. Then fills that descriptor with the data of the arrived usb request,
|
||||
* Fills next free descriptor with the data of the arrived usb request,
|
||||
* frame info, sets Last and IOC bits increments next_desc. If filled
|
||||
* descriptor is not the first one, removes L bit from the previous descriptor
|
||||
* status.
|
||||
|
@ -810,34 +814,17 @@ static int dwc2_gadget_fill_isoc_desc(struct dwc2_hsotg_ep *hs_ep,
|
|||
u32 mask = 0;
|
||||
|
||||
maxsize = dwc2_gadget_get_desc_params(hs_ep, &mask);
|
||||
if (len > maxsize) {
|
||||
dev_err(hsotg->dev, "wrong len %d\n", len);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/*
|
||||
* If SW has already filled half of chain, then return and wait for
|
||||
* the other chain to be processed by HW.
|
||||
*/
|
||||
if (hs_ep->next_desc == MAX_DMA_DESC_NUM_GENERIC / 2)
|
||||
return -EBUSY;
|
||||
|
||||
/* Increment frame number by interval for IN */
|
||||
if (hs_ep->dir_in)
|
||||
dwc2_gadget_incr_frame_num(hs_ep);
|
||||
|
||||
index = (MAX_DMA_DESC_NUM_GENERIC / 2) * hs_ep->isoc_chain_num +
|
||||
hs_ep->next_desc;
|
||||
|
||||
/* Sanity check of calculated index */
|
||||
if ((hs_ep->isoc_chain_num && index > MAX_DMA_DESC_NUM_GENERIC) ||
|
||||
(!hs_ep->isoc_chain_num && index > MAX_DMA_DESC_NUM_GENERIC / 2)) {
|
||||
dev_err(hsotg->dev, "wrong index %d for iso chain\n", index);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
index = hs_ep->next_desc;
|
||||
desc = &hs_ep->desc_list[index];
|
||||
|
||||
/* Check if descriptor chain full */
|
||||
if ((desc->status >> DEV_DMA_BUFF_STS_SHIFT) ==
|
||||
DEV_DMA_BUFF_STS_HREADY) {
|
||||
dev_dbg(hsotg->dev, "%s: desc chain full\n", __func__);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Clear L bit of previous desc if more than one entries in the chain */
|
||||
if (hs_ep->next_desc)
|
||||
hs_ep->desc_list[index - 1].status &= ~DEV_DMA_L;
|
||||
|
@ -865,8 +852,14 @@ static int dwc2_gadget_fill_isoc_desc(struct dwc2_hsotg_ep *hs_ep,
|
|||
desc->status &= ~DEV_DMA_BUFF_STS_MASK;
|
||||
desc->status |= (DEV_DMA_BUFF_STS_HREADY << DEV_DMA_BUFF_STS_SHIFT);
|
||||
|
||||
/* Increment frame number by interval for IN */
|
||||
if (hs_ep->dir_in)
|
||||
dwc2_gadget_incr_frame_num(hs_ep);
|
||||
|
||||
/* Update index of last configured entry in the chain */
|
||||
hs_ep->next_desc++;
|
||||
if (hs_ep->next_desc >= MAX_DMA_DESC_NUM_GENERIC)
|
||||
hs_ep->next_desc = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -875,11 +868,8 @@ static int dwc2_gadget_fill_isoc_desc(struct dwc2_hsotg_ep *hs_ep,
|
|||
* dwc2_gadget_start_isoc_ddma - start isochronous transfer in DDMA
|
||||
* @hs_ep: The isochronous endpoint.
|
||||
*
|
||||
* Prepare first descriptor chain for isochronous endpoints. Afterwards
|
||||
* Prepare descriptor chain for isochronous endpoints. Afterwards
|
||||
* write DMA address to HW and enable the endpoint.
|
||||
*
|
||||
* Switch between descriptor chains via isoc_chain_num to give SW opportunity
|
||||
* to prepare second descriptor chain while first one is being processed by HW.
|
||||
*/
|
||||
static void dwc2_gadget_start_isoc_ddma(struct dwc2_hsotg_ep *hs_ep)
|
||||
{
|
||||
|
@ -887,24 +877,34 @@ static void dwc2_gadget_start_isoc_ddma(struct dwc2_hsotg_ep *hs_ep)
|
|||
struct dwc2_hsotg_req *hs_req, *treq;
|
||||
int index = hs_ep->index;
|
||||
int ret;
|
||||
int i;
|
||||
u32 dma_reg;
|
||||
u32 depctl;
|
||||
u32 ctrl;
|
||||
struct dwc2_dma_desc *desc;
|
||||
|
||||
if (list_empty(&hs_ep->queue)) {
|
||||
dev_dbg(hsotg->dev, "%s: No requests in queue\n", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Initialize descriptor chain by Host Busy status */
|
||||
for (i = 0; i < MAX_DMA_DESC_NUM_GENERIC; i++) {
|
||||
desc = &hs_ep->desc_list[i];
|
||||
desc->status = 0;
|
||||
desc->status |= (DEV_DMA_BUFF_STS_HBUSY
|
||||
<< DEV_DMA_BUFF_STS_SHIFT);
|
||||
}
|
||||
|
||||
hs_ep->next_desc = 0;
|
||||
list_for_each_entry_safe(hs_req, treq, &hs_ep->queue, queue) {
|
||||
ret = dwc2_gadget_fill_isoc_desc(hs_ep, hs_req->req.dma,
|
||||
hs_req->req.length);
|
||||
if (ret) {
|
||||
dev_dbg(hsotg->dev, "%s: desc chain full\n", __func__);
|
||||
if (ret)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
hs_ep->compl_desc = 0;
|
||||
depctl = hs_ep->dir_in ? DIEPCTL(index) : DOEPCTL(index);
|
||||
dma_reg = hs_ep->dir_in ? DIEPDMA(index) : DOEPDMA(index);
|
||||
|
||||
|
@ -914,10 +914,6 @@ static void dwc2_gadget_start_isoc_ddma(struct dwc2_hsotg_ep *hs_ep)
|
|||
ctrl = dwc2_readl(hsotg->regs + depctl);
|
||||
ctrl |= DXEPCTL_EPENA | DXEPCTL_CNAK;
|
||||
dwc2_writel(ctrl, hsotg->regs + depctl);
|
||||
|
||||
/* Switch ISOC descriptor chain number being processed by SW*/
|
||||
hs_ep->isoc_chain_num = (hs_ep->isoc_chain_num ^ 1) & 0x1;
|
||||
hs_ep->next_desc = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1235,7 +1231,7 @@ static bool dwc2_gadget_target_frame_elapsed(struct dwc2_hsotg_ep *hs_ep)
|
|||
{
|
||||
struct dwc2_hsotg *hsotg = hs_ep->parent;
|
||||
u32 target_frame = hs_ep->target_frame;
|
||||
u32 current_frame = dwc2_hsotg_read_frameno(hsotg);
|
||||
u32 current_frame = hsotg->frame_number;
|
||||
bool frame_overrun = hs_ep->frame_overrun;
|
||||
|
||||
if (!frame_overrun && current_frame >= target_frame)
|
||||
|
@ -1291,6 +1287,9 @@ static int dwc2_hsotg_ep_queue(struct usb_ep *ep, struct usb_request *req,
|
|||
struct dwc2_hsotg *hs = hs_ep->parent;
|
||||
bool first;
|
||||
int ret;
|
||||
u32 maxsize = 0;
|
||||
u32 mask = 0;
|
||||
|
||||
|
||||
dev_dbg(hs->dev, "%s: req %p: %d@%p, noi=%d, zero=%d, snok=%d\n",
|
||||
ep->name, req, req->length, req->buf, req->no_interrupt,
|
||||
|
@ -1308,6 +1307,24 @@ static int dwc2_hsotg_ep_queue(struct usb_ep *ep, struct usb_request *req,
|
|||
req->actual = 0;
|
||||
req->status = -EINPROGRESS;
|
||||
|
||||
/* In DDMA mode for ISOC's don't queue request if length greater
|
||||
* than descriptor limits.
|
||||
*/
|
||||
if (using_desc_dma(hs) && hs_ep->isochronous) {
|
||||
maxsize = dwc2_gadget_get_desc_params(hs_ep, &mask);
|
||||
if (hs_ep->dir_in && req->length > maxsize) {
|
||||
dev_err(hs->dev, "wrong length %d (maxsize=%d)\n",
|
||||
req->length, maxsize);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (!hs_ep->dir_in && req->length > hs_ep->ep.maxpacket) {
|
||||
dev_err(hs->dev, "ISOC OUT: wrong length %d (mps=%d)\n",
|
||||
req->length, hs_ep->ep.maxpacket);
|
||||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
|
||||
ret = dwc2_hsotg_handle_unaligned_buf_start(hs, hs_ep, hs_req);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
@ -1330,17 +1347,15 @@ static int dwc2_hsotg_ep_queue(struct usb_ep *ep, struct usb_request *req,
|
|||
|
||||
/*
|
||||
* Handle DDMA isochronous transfers separately - just add new entry
|
||||
* to the half of descriptor chain that is not processed by HW.
|
||||
* to the descriptor chain.
|
||||
* Transfer will be started once SW gets either one of NAK or
|
||||
* OutTknEpDis interrupts.
|
||||
*/
|
||||
if (using_desc_dma(hs) && hs_ep->isochronous &&
|
||||
hs_ep->target_frame != TARGET_FRAME_INITIAL) {
|
||||
ret = dwc2_gadget_fill_isoc_desc(hs_ep, hs_req->req.dma,
|
||||
if (using_desc_dma(hs) && hs_ep->isochronous) {
|
||||
if (hs_ep->target_frame != TARGET_FRAME_INITIAL) {
|
||||
dwc2_gadget_fill_isoc_desc(hs_ep, hs_req->req.dma,
|
||||
hs_req->req.length);
|
||||
if (ret)
|
||||
dev_dbg(hs->dev, "%s: ISO desc chain full\n", __func__);
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1350,8 +1365,15 @@ static int dwc2_hsotg_ep_queue(struct usb_ep *ep, struct usb_request *req,
|
|||
return 0;
|
||||
}
|
||||
|
||||
while (dwc2_gadget_target_frame_elapsed(hs_ep))
|
||||
/* Update current frame number value. */
|
||||
hs->frame_number = dwc2_hsotg_read_frameno(hs);
|
||||
while (dwc2_gadget_target_frame_elapsed(hs_ep)) {
|
||||
dwc2_gadget_incr_frame_num(hs_ep);
|
||||
/* Update current frame number value once more as it
|
||||
* changes here.
|
||||
*/
|
||||
hs->frame_number = dwc2_hsotg_read_frameno(hs);
|
||||
}
|
||||
|
||||
if (hs_ep->target_frame != TARGET_FRAME_INITIAL)
|
||||
dwc2_hsotg_start_req(hs, hs_ep, hs_req, false);
|
||||
|
@ -2011,23 +2033,24 @@ static void dwc2_hsotg_complete_request(struct dwc2_hsotg *hsotg,
|
|||
* @hs_ep: The endpoint the request was on.
|
||||
*
|
||||
* Get first request from the ep queue, determine descriptor on which complete
|
||||
* happened. SW based on isoc_chain_num discovers which half of the descriptor
|
||||
* chain is currently in use by HW, adjusts dma_address and calculates index
|
||||
* of completed descriptor based on the value of DEPDMA register. Update actual
|
||||
* length of request, giveback to gadget.
|
||||
* happened. SW discovers which descriptor currently in use by HW, adjusts
|
||||
* dma_address and calculates index of completed descriptor based on the value
|
||||
* of DEPDMA register. Update actual length of request, giveback to gadget.
|
||||
*/
|
||||
static void dwc2_gadget_complete_isoc_request_ddma(struct dwc2_hsotg_ep *hs_ep)
|
||||
{
|
||||
struct dwc2_hsotg *hsotg = hs_ep->parent;
|
||||
struct dwc2_hsotg_req *hs_req;
|
||||
struct usb_request *ureq;
|
||||
int index;
|
||||
dma_addr_t dma_addr;
|
||||
u32 dma_reg;
|
||||
u32 depdma;
|
||||
u32 desc_sts;
|
||||
u32 mask;
|
||||
|
||||
desc_sts = hs_ep->desc_list[hs_ep->compl_desc].status;
|
||||
|
||||
/* Process only descriptors with buffer status set to DMA done */
|
||||
while ((desc_sts & DEV_DMA_BUFF_STS_MASK) >>
|
||||
DEV_DMA_BUFF_STS_SHIFT == DEV_DMA_BUFF_STS_DMADONE) {
|
||||
|
||||
hs_req = get_ep_head(hs_ep);
|
||||
if (!hs_req) {
|
||||
dev_warn(hsotg->dev, "%s: ISOC EP queue empty\n", __func__);
|
||||
|
@ -2035,84 +2058,50 @@ static void dwc2_gadget_complete_isoc_request_ddma(struct dwc2_hsotg_ep *hs_ep)
|
|||
}
|
||||
ureq = &hs_req->req;
|
||||
|
||||
dma_addr = hs_ep->desc_list_dma;
|
||||
|
||||
/*
|
||||
* If lower half of descriptor chain is currently use by SW,
|
||||
* that means higher half is being processed by HW, so shift
|
||||
* DMA address to higher half of descriptor chain.
|
||||
*/
|
||||
if (!hs_ep->isoc_chain_num)
|
||||
dma_addr += sizeof(struct dwc2_dma_desc) *
|
||||
(MAX_DMA_DESC_NUM_GENERIC / 2);
|
||||
|
||||
dma_reg = hs_ep->dir_in ? DIEPDMA(hs_ep->index) : DOEPDMA(hs_ep->index);
|
||||
depdma = dwc2_readl(hsotg->regs + dma_reg);
|
||||
|
||||
index = (depdma - dma_addr) / sizeof(struct dwc2_dma_desc) - 1;
|
||||
desc_sts = hs_ep->desc_list[index].status;
|
||||
|
||||
/* Check completion status */
|
||||
if ((desc_sts & DEV_DMA_STS_MASK) >> DEV_DMA_STS_SHIFT ==
|
||||
DEV_DMA_STS_SUCC) {
|
||||
mask = hs_ep->dir_in ? DEV_DMA_ISOC_TX_NBYTES_MASK :
|
||||
DEV_DMA_ISOC_RX_NBYTES_MASK;
|
||||
ureq->actual = ureq->length -
|
||||
((desc_sts & mask) >> DEV_DMA_ISOC_NBYTES_SHIFT);
|
||||
ureq->actual = ureq->length - ((desc_sts & mask) >>
|
||||
DEV_DMA_ISOC_NBYTES_SHIFT);
|
||||
|
||||
/* Adjust actual length for ISOC Out if length is not align of 4 */
|
||||
/* Adjust actual len for ISOC Out if len is
|
||||
* not align of 4
|
||||
*/
|
||||
if (!hs_ep->dir_in && ureq->length & 0x3)
|
||||
ureq->actual += 4 - (ureq->length & 0x3);
|
||||
}
|
||||
|
||||
dwc2_hsotg_complete_request(hsotg, hs_ep, hs_req, 0);
|
||||
|
||||
hs_ep->compl_desc++;
|
||||
if (hs_ep->compl_desc > (MAX_DMA_DESC_NUM_GENERIC - 1))
|
||||
hs_ep->compl_desc = 0;
|
||||
desc_sts = hs_ep->desc_list[hs_ep->compl_desc].status;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* dwc2_gadget_start_next_isoc_ddma - start next isoc request, if any.
|
||||
* @hs_ep: The isochronous endpoint to be re-enabled.
|
||||
* dwc2_gadget_handle_isoc_bna - handle BNA interrupt for ISOC.
|
||||
* @hs_ep: The isochronous endpoint.
|
||||
*
|
||||
* If ep has been disabled due to last descriptor servicing (IN endpoint) or
|
||||
* BNA (OUT endpoint) check the status of other half of descriptor chain that
|
||||
* was under SW control till HW was busy and restart the endpoint if needed.
|
||||
* If EP ISOC OUT then need to flush RX FIFO to remove source of BNA
|
||||
* interrupt. Reset target frame and next_desc to allow to start
|
||||
* ISOC's on NAK interrupt for IN direction or on OUTTKNEPDIS
|
||||
* interrupt for OUT direction.
|
||||
*/
|
||||
static void dwc2_gadget_start_next_isoc_ddma(struct dwc2_hsotg_ep *hs_ep)
|
||||
static void dwc2_gadget_handle_isoc_bna(struct dwc2_hsotg_ep *hs_ep)
|
||||
{
|
||||
struct dwc2_hsotg *hsotg = hs_ep->parent;
|
||||
u32 depctl;
|
||||
u32 dma_reg;
|
||||
u32 ctrl;
|
||||
u32 dma_addr = hs_ep->desc_list_dma;
|
||||
unsigned char index = hs_ep->index;
|
||||
|
||||
dma_reg = hs_ep->dir_in ? DIEPDMA(index) : DOEPDMA(index);
|
||||
depctl = hs_ep->dir_in ? DIEPCTL(index) : DOEPCTL(index);
|
||||
if (!hs_ep->dir_in)
|
||||
dwc2_flush_rx_fifo(hsotg);
|
||||
dwc2_hsotg_complete_request(hsotg, hs_ep, get_ep_head(hs_ep), 0);
|
||||
|
||||
ctrl = dwc2_readl(hsotg->regs + depctl);
|
||||
|
||||
/*
|
||||
* EP was disabled if HW has processed last descriptor or BNA was set.
|
||||
* So restart ep if SW has prepared new descriptor chain in ep_queue
|
||||
* routine while HW was busy.
|
||||
*/
|
||||
if (!(ctrl & DXEPCTL_EPENA)) {
|
||||
if (!hs_ep->next_desc) {
|
||||
dev_dbg(hsotg->dev, "%s: No more ISOC requests\n",
|
||||
__func__);
|
||||
return;
|
||||
}
|
||||
|
||||
dma_addr += sizeof(struct dwc2_dma_desc) *
|
||||
(MAX_DMA_DESC_NUM_GENERIC / 2) *
|
||||
hs_ep->isoc_chain_num;
|
||||
dwc2_writel(dma_addr, hsotg->regs + dma_reg);
|
||||
|
||||
ctrl |= DXEPCTL_EPENA | DXEPCTL_CNAK;
|
||||
dwc2_writel(ctrl, hsotg->regs + depctl);
|
||||
|
||||
/* Switch ISOC descriptor chain number being processed by SW*/
|
||||
hs_ep->isoc_chain_num = (hs_ep->isoc_chain_num ^ 1) & 0x1;
|
||||
hs_ep->target_frame = TARGET_FRAME_INITIAL;
|
||||
hs_ep->next_desc = 0;
|
||||
|
||||
dev_dbg(hsotg->dev, "%s: Restarted isochronous endpoint\n",
|
||||
__func__);
|
||||
}
|
||||
hs_ep->compl_desc = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2441,6 +2430,7 @@ static u32 dwc2_hsotg_ep0_mps(unsigned int mps)
|
|||
* @ep: The index number of the endpoint
|
||||
* @mps: The maximum packet size in bytes
|
||||
* @mc: The multicount value
|
||||
* @dir_in: True if direction is in.
|
||||
*
|
||||
* Configure the maximum packet size for the given endpoint, updating
|
||||
* the hardware control registers to reflect this.
|
||||
|
@ -2731,6 +2721,8 @@ static void dwc2_gadget_handle_ep_disabled(struct dwc2_hsotg_ep *hs_ep)
|
|||
dwc2_hsotg_complete_request(hsotg, hs_ep, hs_req,
|
||||
-ENODATA);
|
||||
dwc2_gadget_incr_frame_num(hs_ep);
|
||||
/* Update current frame number value. */
|
||||
hsotg->frame_number = dwc2_hsotg_read_frameno(hsotg);
|
||||
} while (dwc2_gadget_target_frame_elapsed(hs_ep));
|
||||
|
||||
dwc2_gadget_start_next_request(hs_ep);
|
||||
|
@ -2738,7 +2730,7 @@ static void dwc2_gadget_handle_ep_disabled(struct dwc2_hsotg_ep *hs_ep)
|
|||
|
||||
/**
|
||||
* dwc2_gadget_handle_out_token_ep_disabled - handle DXEPINT_OUTTKNEPDIS
|
||||
* @hs_ep: The endpoint on which interrupt is asserted.
|
||||
* @ep: The endpoint on which interrupt is asserted.
|
||||
*
|
||||
* This is starting point for ISOC-OUT transfer, synchronization done with
|
||||
* first out token received from host while corresponding EP is disabled.
|
||||
|
@ -2763,7 +2755,7 @@ static void dwc2_gadget_handle_out_token_ep_disabled(struct dwc2_hsotg_ep *ep)
|
|||
*/
|
||||
tmp = dwc2_hsotg_read_frameno(hsotg);
|
||||
|
||||
dwc2_hsotg_complete_request(hsotg, ep, get_ep_head(ep), -ENODATA);
|
||||
dwc2_hsotg_complete_request(hsotg, ep, get_ep_head(ep), 0);
|
||||
|
||||
if (using_desc_dma(hsotg)) {
|
||||
if (ep->target_frame == TARGET_FRAME_INITIAL) {
|
||||
|
@ -2816,18 +2808,25 @@ static void dwc2_gadget_handle_nak(struct dwc2_hsotg_ep *hs_ep)
|
|||
{
|
||||
struct dwc2_hsotg *hsotg = hs_ep->parent;
|
||||
int dir_in = hs_ep->dir_in;
|
||||
u32 tmp;
|
||||
|
||||
if (!dir_in || !hs_ep->isochronous)
|
||||
return;
|
||||
|
||||
if (hs_ep->target_frame == TARGET_FRAME_INITIAL) {
|
||||
hs_ep->target_frame = dwc2_hsotg_read_frameno(hsotg);
|
||||
|
||||
tmp = dwc2_hsotg_read_frameno(hsotg);
|
||||
if (using_desc_dma(hsotg)) {
|
||||
dwc2_hsotg_complete_request(hsotg, hs_ep,
|
||||
get_ep_head(hs_ep), 0);
|
||||
|
||||
hs_ep->target_frame = tmp;
|
||||
dwc2_gadget_incr_frame_num(hs_ep);
|
||||
dwc2_gadget_start_isoc_ddma(hs_ep);
|
||||
return;
|
||||
}
|
||||
|
||||
hs_ep->target_frame = tmp;
|
||||
if (hs_ep->interval > 1) {
|
||||
u32 ctrl = dwc2_readl(hsotg->regs +
|
||||
DIEPCTL(hs_ep->index));
|
||||
|
@ -2843,6 +2842,7 @@ static void dwc2_gadget_handle_nak(struct dwc2_hsotg_ep *hs_ep)
|
|||
get_ep_head(hs_ep), 0);
|
||||
}
|
||||
|
||||
if (!using_desc_dma(hsotg))
|
||||
dwc2_gadget_incr_frame_num(hs_ep);
|
||||
}
|
||||
|
||||
|
@ -2901,9 +2901,9 @@ static void dwc2_hsotg_epint(struct dwc2_hsotg *hsotg, unsigned int idx,
|
|||
|
||||
/* In DDMA handle isochronous requests separately */
|
||||
if (using_desc_dma(hsotg) && hs_ep->isochronous) {
|
||||
/* XferCompl set along with BNA */
|
||||
if (!(ints & DXEPINT_BNAINTR))
|
||||
dwc2_gadget_complete_isoc_request_ddma(hs_ep);
|
||||
/* Try to start next isoc request */
|
||||
dwc2_gadget_start_next_isoc_ddma(hs_ep);
|
||||
} else if (dir_in) {
|
||||
/*
|
||||
* We get OutDone from the FIFO, so we only
|
||||
|
@ -2978,15 +2978,8 @@ static void dwc2_hsotg_epint(struct dwc2_hsotg *hsotg, unsigned int idx,
|
|||
|
||||
if (ints & DXEPINT_BNAINTR) {
|
||||
dev_dbg(hsotg->dev, "%s: BNA interrupt\n", __func__);
|
||||
|
||||
/*
|
||||
* Try to start next isoc request, if any.
|
||||
* Sometimes the endpoint remains enabled after BNA interrupt
|
||||
* assertion, which is not expected, hence we can enter here
|
||||
* couple of times.
|
||||
*/
|
||||
if (hs_ep->isochronous)
|
||||
dwc2_gadget_start_next_isoc_ddma(hs_ep);
|
||||
dwc2_gadget_handle_isoc_bna(hs_ep);
|
||||
}
|
||||
|
||||
if (dir_in && !hs_ep->isochronous) {
|
||||
|
@ -3197,6 +3190,7 @@ static void dwc2_hsotg_irq_fifoempty(struct dwc2_hsotg *hsotg, bool periodic)
|
|||
/**
|
||||
* dwc2_hsotg_core_init - issue softreset to the core
|
||||
* @hsotg: The device state
|
||||
* @is_usb_reset: Usb resetting flag
|
||||
*
|
||||
* Issue a soft reset to the core, and await the core finishing it.
|
||||
*/
|
||||
|
@ -3259,6 +3253,9 @@ void dwc2_hsotg_core_init_disconnected(struct dwc2_hsotg *hsotg,
|
|||
dcfg |= DCFG_DEVSPD_HS;
|
||||
}
|
||||
|
||||
if (hsotg->params.ipg_isoc_en)
|
||||
dcfg |= DCFG_IPG_ISOC_SUPPORDED;
|
||||
|
||||
dwc2_writel(dcfg, hsotg->regs + DCFG);
|
||||
|
||||
/* Clear any pending OTG interrupts */
|
||||
|
@ -3320,8 +3317,10 @@ void dwc2_hsotg_core_init_disconnected(struct dwc2_hsotg *hsotg,
|
|||
hsotg->regs + DOEPMSK);
|
||||
|
||||
/* Enable BNA interrupt for DDMA */
|
||||
if (using_desc_dma(hsotg))
|
||||
if (using_desc_dma(hsotg)) {
|
||||
dwc2_set_bit(hsotg->regs + DOEPMSK, DOEPMSK_BNAMSK);
|
||||
dwc2_set_bit(hsotg->regs + DIEPMSK, DIEPMSK_BNAININTRMSK);
|
||||
}
|
||||
|
||||
dwc2_writel(0, hsotg->regs + DAINTMSK);
|
||||
|
||||
|
@ -3427,7 +3426,7 @@ static void dwc2_gadget_handle_incomplete_isoc_in(struct dwc2_hsotg *hsotg)
|
|||
|
||||
daintmsk = dwc2_readl(hsotg->regs + DAINTMSK);
|
||||
|
||||
for (idx = 1; idx <= hsotg->num_of_eps; idx++) {
|
||||
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))
|
||||
|
@ -3473,7 +3472,7 @@ static void dwc2_gadget_handle_incomplete_isoc_out(struct dwc2_hsotg *hsotg)
|
|||
daintmsk = dwc2_readl(hsotg->regs + DAINTMSK);
|
||||
daintmsk >>= DAINT_OUTEP_SHIFT;
|
||||
|
||||
for (idx = 1; idx <= hsotg->num_of_eps; idx++) {
|
||||
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))
|
||||
|
@ -3647,7 +3646,7 @@ irq_retry:
|
|||
dwc2_writel(gintmsk, hsotg->regs + GINTMSK);
|
||||
|
||||
dev_dbg(hsotg->dev, "GOUTNakEff triggered\n");
|
||||
for (idx = 1; idx <= hsotg->num_of_eps; idx++) {
|
||||
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))
|
||||
|
@ -3789,6 +3788,7 @@ static int dwc2_hsotg_ep_enable(struct usb_ep *ep,
|
|||
unsigned int dir_in;
|
||||
unsigned int i, val, size;
|
||||
int ret = 0;
|
||||
unsigned char ep_type;
|
||||
|
||||
dev_dbg(hsotg->dev,
|
||||
"%s: ep %s: a 0x%02x, attr 0x%02x, mps 0x%04x, intr %d\n",
|
||||
|
@ -3807,9 +3807,26 @@ static int dwc2_hsotg_ep_enable(struct usb_ep *ep,
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
ep_type = desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK;
|
||||
mps = usb_endpoint_maxp(desc);
|
||||
mc = usb_endpoint_maxp_mult(desc);
|
||||
|
||||
/* ISOC IN in DDMA supported bInterval up to 10 */
|
||||
if (using_desc_dma(hsotg) && ep_type == USB_ENDPOINT_XFER_ISOC &&
|
||||
dir_in && desc->bInterval > 10) {
|
||||
dev_err(hsotg->dev,
|
||||
"%s: ISOC IN, DDMA: bInterval>10 not supported!\n", __func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* High bandwidth ISOC OUT in DDMA not supported */
|
||||
if (using_desc_dma(hsotg) && ep_type == USB_ENDPOINT_XFER_ISOC &&
|
||||
!dir_in && mc > 1) {
|
||||
dev_err(hsotg->dev,
|
||||
"%s: ISOC OUT, DDMA: HB not supported!\n", __func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* note, we handle this here instead of dwc2_hsotg_set_ep_maxpacket */
|
||||
|
||||
epctrl_reg = dir_in ? DIEPCTL(index) : DOEPCTL(index);
|
||||
|
@ -3850,15 +3867,15 @@ static int dwc2_hsotg_ep_enable(struct usb_ep *ep,
|
|||
hs_ep->halted = 0;
|
||||
hs_ep->interval = desc->bInterval;
|
||||
|
||||
switch (desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) {
|
||||
switch (ep_type) {
|
||||
case USB_ENDPOINT_XFER_ISOC:
|
||||
epctrl |= DXEPCTL_EPTYPE_ISO;
|
||||
epctrl |= DXEPCTL_SETEVENFR;
|
||||
hs_ep->isochronous = 1;
|
||||
hs_ep->interval = 1 << (desc->bInterval - 1);
|
||||
hs_ep->target_frame = TARGET_FRAME_INITIAL;
|
||||
hs_ep->isoc_chain_num = 0;
|
||||
hs_ep->next_desc = 0;
|
||||
hs_ep->compl_desc = 0;
|
||||
if (dir_in) {
|
||||
hs_ep->periodic = 1;
|
||||
mask = dwc2_readl(hsotg->regs + DIEPMSK);
|
||||
|
@ -4301,7 +4318,6 @@ err:
|
|||
/**
|
||||
* dwc2_hsotg_udc_stop - stop the udc
|
||||
* @gadget: The usb gadget state
|
||||
* @driver: The usb gadget driver
|
||||
*
|
||||
* Stop udc hw block and stay tunned for future transmissions
|
||||
*/
|
||||
|
@ -4453,6 +4469,7 @@ static const struct usb_gadget_ops dwc2_hsotg_gadget_ops = {
|
|||
* @hsotg: The device state.
|
||||
* @hs_ep: The endpoint to be initialised.
|
||||
* @epnum: The endpoint number
|
||||
* @dir_in: True if direction is in.
|
||||
*
|
||||
* Initialise the given endpoint (as part of the probe and device state
|
||||
* creation) to give to the gadget driver. Setup the endpoint name, any
|
||||
|
@ -4526,7 +4543,7 @@ static void dwc2_hsotg_initep(struct dwc2_hsotg *hsotg,
|
|||
|
||||
/**
|
||||
* dwc2_hsotg_hw_cfg - read HW configuration registers
|
||||
* @param: The device state
|
||||
* @hsotg: Programming view of the DWC_otg controller
|
||||
*
|
||||
* Read the USB core HW configuration registers
|
||||
*/
|
||||
|
@ -4582,7 +4599,8 @@ static int dwc2_hsotg_hw_cfg(struct dwc2_hsotg *hsotg)
|
|||
|
||||
/**
|
||||
* dwc2_hsotg_dump - dump state of the udc
|
||||
* @param: The device state
|
||||
* @hsotg: Programming view of the DWC_otg controller
|
||||
*
|
||||
*/
|
||||
static void dwc2_hsotg_dump(struct dwc2_hsotg *hsotg)
|
||||
{
|
||||
|
@ -4633,7 +4651,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.
|
||||
* @hsotg: Programming view of the DWC_otg controller
|
||||
*
|
||||
*/
|
||||
int dwc2_gadget_init(struct dwc2_hsotg *hsotg)
|
||||
{
|
||||
|
@ -4730,7 +4749,8 @@ int dwc2_gadget_init(struct dwc2_hsotg *hsotg)
|
|||
|
||||
/**
|
||||
* dwc2_hsotg_remove - remove function for hsotg driver
|
||||
* @pdev: The platform information for the driver
|
||||
* @hsotg: Programming view of the DWC_otg controller
|
||||
*
|
||||
*/
|
||||
int dwc2_hsotg_remove(struct dwc2_hsotg *hsotg)
|
||||
{
|
||||
|
@ -5011,7 +5031,7 @@ int dwc2_gadget_enter_hibernation(struct dwc2_hsotg *hsotg)
|
|||
*
|
||||
* @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.
|
||||
* @reset: indicates whether resume is initiated by Reset.
|
||||
*
|
||||
* Return non-zero if failed to exit from hibernation.
|
||||
*/
|
||||
|
|
|
@ -597,7 +597,7 @@ u32 dwc2_calc_frame_interval(struct dwc2_hsotg *hsotg)
|
|||
* dwc2_read_packet() - Reads a packet from the Rx FIFO into the destination
|
||||
* buffer
|
||||
*
|
||||
* @core_if: Programming view of DWC_otg controller
|
||||
* @hsotg: Programming view of DWC_otg controller
|
||||
* @dest: Destination buffer for the packet
|
||||
* @bytes: Number of bytes to copy to the destination
|
||||
*/
|
||||
|
@ -4087,7 +4087,6 @@ static struct dwc2_hsotg *dwc2_hcd_to_hsotg(struct usb_hcd *hcd)
|
|||
* then the refcount for the structure will go to 0 and we'll free it.
|
||||
*
|
||||
* @hsotg: The HCD state structure for the DWC OTG controller.
|
||||
* @qh: The QH structure.
|
||||
* @context: The priv pointer from a struct dwc2_hcd_urb.
|
||||
* @mem_flags: Flags for allocating memory.
|
||||
* @ttport: We'll return this device's port number here. That's used to
|
||||
|
|
|
@ -80,7 +80,7 @@ struct dwc2_qh;
|
|||
* @xfer_count: Number of bytes transferred so far
|
||||
* @start_pkt_count: Packet count at start of transfer
|
||||
* @xfer_started: True if the transfer has been started
|
||||
* @ping: True if a PING request should be issued on this channel
|
||||
* @do_ping: True if a PING request should be issued on this channel
|
||||
* @error_state: True if the error count for this transaction is non-zero
|
||||
* @halt_on_queue: True if this channel should be halted the next time a
|
||||
* request is queued for the channel. This is necessary in
|
||||
|
@ -102,7 +102,7 @@ struct dwc2_qh;
|
|||
* @schinfo: Scheduling micro-frame bitmap
|
||||
* @ntd: Number of transfer descriptors for the transfer
|
||||
* @halt_status: Reason for halting the host channel
|
||||
* @hcint Contents of the HCINT register when the interrupt came
|
||||
* @hcint: Contents of the HCINT register when the interrupt came
|
||||
* @qh: QH for the transfer being processed by this channel
|
||||
* @hc_list_entry: For linking to list of host channels
|
||||
* @desc_list_addr: Current QH's descriptor list DMA address
|
||||
|
@ -237,7 +237,7 @@ struct dwc2_tt {
|
|||
/**
|
||||
* struct dwc2_hs_transfer_time - Info about a transfer on the high speed bus.
|
||||
*
|
||||
* @start_schedule_usecs: The start time on the main bus schedule. Note that
|
||||
* @start_schedule_us: The start time on the main bus schedule. Note that
|
||||
* the main bus schedule is tightly packed and this
|
||||
* time should be interpreted as tightly packed (so
|
||||
* uFrame 0 starts at 0 us, uFrame 1 starts at 100 us
|
||||
|
@ -301,7 +301,6 @@ struct dwc2_hs_transfer_time {
|
|||
* "struct dwc2_tt". Not used if this device is high
|
||||
* speed. Note that this is in "schedule slice" which
|
||||
* is tightly packed.
|
||||
* @ls_duration_us: Duration on the low speed bus schedule.
|
||||
* @ntd: Actual number of transfer descriptors in a list
|
||||
* @qtd_list: List of QTDs for this QH
|
||||
* @channel: Host channel currently processing transfers for this QH
|
||||
|
@ -315,7 +314,7 @@ struct dwc2_hs_transfer_time {
|
|||
* descriptor
|
||||
* @unreserve_timer: Timer for releasing periodic reservation.
|
||||
* @wait_timer: Timer used to wait before re-queuing.
|
||||
* @dwc2_tt: Pointer to our tt info (or NULL if no tt).
|
||||
* @dwc_tt: Pointer to our tt info (or NULL if no tt).
|
||||
* @ttport: Port number within our tt.
|
||||
* @tt_buffer_dirty True if clear_tt_buffer_complete is pending
|
||||
* @unreserve_pending: True if we planned to unreserve but haven't yet.
|
||||
|
@ -325,6 +324,7 @@ struct dwc2_hs_transfer_time {
|
|||
* periodic transfers and is ignored for periodic ones.
|
||||
* @wait_timer_cancel: Set to true to cancel the wait_timer.
|
||||
*
|
||||
* @tt_buffer_dirty: True if EP's TT buffer is not clean.
|
||||
* A Queue Head (QH) holds the static characteristics of an endpoint and
|
||||
* maintains a list of transfers (QTDs) for that endpoint. A QH structure may
|
||||
* be entered in either the non-periodic or periodic schedule.
|
||||
|
@ -400,6 +400,10 @@ struct dwc2_qh {
|
|||
* @urb: URB for this transfer
|
||||
* @qh: Queue head for this QTD
|
||||
* @qtd_list_entry: For linking to the QH's list of QTDs
|
||||
* @isoc_td_first: Index of first activated isochronous transfer
|
||||
* descriptor in Descriptor DMA mode
|
||||
* @isoc_td_last: Index of last activated isochronous transfer
|
||||
* descriptor in Descriptor DMA mode
|
||||
*
|
||||
* A Queue Transfer Descriptor (QTD) holds the state of a bulk, control,
|
||||
* interrupt, or isochronous transfer. A single QTD is created for each URB
|
||||
|
|
|
@ -332,6 +332,7 @@ static void dwc2_release_channel_ddma(struct dwc2_hsotg *hsotg,
|
|||
*
|
||||
* @hsotg: The HCD state structure for the DWC OTG controller
|
||||
* @qh: The QH to init
|
||||
* @mem_flags: Indicates the type of memory allocation
|
||||
*
|
||||
* Return: 0 if successful, negative error code otherwise
|
||||
*
|
||||
|
|
|
@ -478,6 +478,12 @@ static u32 dwc2_get_actual_xfer_length(struct dwc2_hsotg *hsotg,
|
|||
* of the URB based on the number of bytes transferred via the host channel.
|
||||
* Sets the URB status if the data transfer is finished.
|
||||
*
|
||||
* @hsotg: Programming view of the DWC_otg controller
|
||||
* @chan: Programming view of host channel
|
||||
* @chnum: Channel number
|
||||
* @urb: Processing URB
|
||||
* @qtd: Queue transfer descriptor
|
||||
*
|
||||
* Return: 1 if the data transfer specified by the URB is completely finished,
|
||||
* 0 otherwise
|
||||
*/
|
||||
|
@ -566,6 +572,12 @@ void dwc2_hcd_save_data_toggle(struct dwc2_hsotg *hsotg,
|
|||
* halt_status. Completes the Isochronous URB if all the URB frames have been
|
||||
* completed.
|
||||
*
|
||||
* @hsotg: Programming view of the DWC_otg controller
|
||||
* @chan: Programming view of host channel
|
||||
* @chnum: Channel number
|
||||
* @halt_status: Reason for halting a host channel
|
||||
* @qtd: Queue transfer descriptor
|
||||
*
|
||||
* Return: DWC2_HC_XFER_COMPLETE if there are more frames remaining to be
|
||||
* transferred in the URB. Otherwise return DWC2_HC_XFER_URB_COMPLETE.
|
||||
*/
|
||||
|
|
|
@ -679,6 +679,7 @@ static int dwc2_hs_pmap_schedule(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh,
|
|||
*
|
||||
* @hsotg: The HCD state structure for the DWC OTG controller.
|
||||
* @qh: QH for the periodic transfer.
|
||||
* @index: Transfer index
|
||||
*/
|
||||
static void dwc2_hs_pmap_unschedule(struct dwc2_hsotg *hsotg,
|
||||
struct dwc2_qh *qh, int index)
|
||||
|
@ -1276,7 +1277,7 @@ static void dwc2_do_unreserve(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh)
|
|||
* release the reservation. This worker is called after the appropriate
|
||||
* delay.
|
||||
*
|
||||
* @work: Pointer to a qh unreserve_work.
|
||||
* @t: Address to a qh unreserve_work.
|
||||
*/
|
||||
static void dwc2_unreserve_timer_fn(struct timer_list *t)
|
||||
{
|
||||
|
@ -1631,7 +1632,7 @@ static void dwc2_qh_init(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh,
|
|||
* @hsotg: The HCD state structure for the DWC OTG controller
|
||||
* @urb: Holds the information about the device/endpoint needed
|
||||
* to initialize the QH
|
||||
* @atomic_alloc: Flag to do atomic allocation if needed
|
||||
* @mem_flags: Flags for allocating memory.
|
||||
*
|
||||
* Return: Pointer to the newly allocated QH, or NULL on error
|
||||
*/
|
||||
|
|
|
@ -311,6 +311,7 @@
|
|||
#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_IPG_ISOC_SUPPORTED BIT(11)
|
||||
#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
|
||||
|
@ -424,6 +425,7 @@
|
|||
#define DCFG_EPMISCNT_SHIFT 18
|
||||
#define DCFG_EPMISCNT_LIMIT 0x1f
|
||||
#define DCFG_EPMISCNT(_x) ((_x) << 18)
|
||||
#define DCFG_IPG_ISOC_SUPPORDED BIT(17)
|
||||
#define DCFG_PERFRINT_MASK (0x3 << 11)
|
||||
#define DCFG_PERFRINT_SHIFT 11
|
||||
#define DCFG_PERFRINT_LIMIT 0x3
|
||||
|
|
|
@ -70,6 +70,7 @@ static void dwc2_set_his_params(struct dwc2_hsotg *hsotg)
|
|||
GAHBCFG_HBSTLEN_SHIFT;
|
||||
p->uframe_sched = false;
|
||||
p->change_speed_quirk = true;
|
||||
p->power_down = false;
|
||||
}
|
||||
|
||||
static void dwc2_set_rk_params(struct dwc2_hsotg *hsotg)
|
||||
|
@ -269,6 +270,9 @@ static void dwc2_set_param_power_down(struct dwc2_hsotg *hsotg)
|
|||
/**
|
||||
* dwc2_set_default_params() - Set all core parameters to their
|
||||
* auto-detected default values.
|
||||
*
|
||||
* @hsotg: Programming view of the DWC_otg controller
|
||||
*
|
||||
*/
|
||||
static void dwc2_set_default_params(struct dwc2_hsotg *hsotg)
|
||||
{
|
||||
|
@ -298,6 +302,7 @@ static void dwc2_set_default_params(struct dwc2_hsotg *hsotg)
|
|||
p->besl = true;
|
||||
p->hird_threshold_en = true;
|
||||
p->hird_threshold = 4;
|
||||
p->ipg_isoc_en = false;
|
||||
p->max_packet_count = hw->max_packet_count;
|
||||
p->max_transfer_size = hw->max_transfer_size;
|
||||
p->ahbcfg = GAHBCFG_HBSTLEN_INCR << GAHBCFG_HBSTLEN_SHIFT;
|
||||
|
@ -338,6 +343,8 @@ static void dwc2_set_default_params(struct dwc2_hsotg *hsotg)
|
|||
/**
|
||||
* dwc2_get_device_properties() - Read in device properties.
|
||||
*
|
||||
* @hsotg: Programming view of the DWC_otg controller
|
||||
*
|
||||
* Read in the device properties and adjust core parameters if needed.
|
||||
*/
|
||||
static void dwc2_get_device_properties(struct dwc2_hsotg *hsotg)
|
||||
|
@ -549,7 +556,7 @@ static void dwc2_check_param_tx_fifo_sizes(struct dwc2_hsotg *hsotg)
|
|||
}
|
||||
|
||||
#define CHECK_RANGE(_param, _min, _max, _def) do { \
|
||||
if ((hsotg->params._param) < (_min) || \
|
||||
if ((int)(hsotg->params._param) < (_min) || \
|
||||
(hsotg->params._param) > (_max)) { \
|
||||
dev_warn(hsotg->dev, "%s: Invalid parameter %s=%d\n", \
|
||||
__func__, #_param, hsotg->params._param); \
|
||||
|
@ -579,6 +586,7 @@ static void dwc2_check_params(struct dwc2_hsotg *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(ipg_isoc_en, hw->ipg_isoc_en);
|
||||
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));
|
||||
|
@ -688,6 +696,9 @@ static void dwc2_get_dev_hwparams(struct dwc2_hsotg *hsotg)
|
|||
/**
|
||||
* During device initialization, read various hardware configuration
|
||||
* registers and interpret the contents.
|
||||
*
|
||||
* @hsotg: Programming view of the DWC_otg controller
|
||||
*
|
||||
*/
|
||||
int dwc2_get_hwparams(struct dwc2_hsotg *hsotg)
|
||||
{
|
||||
|
@ -772,6 +783,7 @@ int dwc2_get_hwparams(struct dwc2_hsotg *hsotg)
|
|||
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);
|
||||
hw->ipg_isoc_en = !!(hwcfg4 & GHWCFG4_IPG_ISOC_SUPPORTED);
|
||||
|
||||
/* fifo sizes */
|
||||
hw->rx_fifo_size = (grxfsiz & GRXFSIZ_DEPTH_MASK) >>
|
||||
|
|
|
@ -77,6 +77,12 @@ static int dwc2_pci_quirks(struct pci_dev *pdev, struct platform_device *dwc2)
|
|||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* dwc2_pci_probe() - Provides the cleanup entry points for the DWC_otg PCI
|
||||
* driver
|
||||
*
|
||||
* @pci: The programming view of DWC_otg PCI
|
||||
*/
|
||||
static void dwc2_pci_remove(struct pci_dev *pci)
|
||||
{
|
||||
struct dwc2_pci_glue *glue = pci_get_drvdata(pci);
|
||||
|
|
|
@ -106,4 +106,16 @@ config USB_DWC3_ST
|
|||
inside (i.e. STiH407).
|
||||
Say 'Y' or 'M' if you have one such device.
|
||||
|
||||
config USB_DWC3_QCOM
|
||||
tristate "Qualcomm Platform"
|
||||
depends on ARCH_QCOM || COMPILE_TEST
|
||||
depends on OF
|
||||
default USB_DWC3
|
||||
help
|
||||
Some Qualcomm SoCs use DesignWare Core IP for USB2/3
|
||||
functionality.
|
||||
This driver also handles Qscratch wrapper which is needed
|
||||
for peripheral mode support.
|
||||
Say 'Y' or 'M' if you have one such device.
|
||||
|
||||
endif
|
||||
|
|
|
@ -48,3 +48,4 @@ obj-$(CONFIG_USB_DWC3_PCI) += dwc3-pci.o
|
|||
obj-$(CONFIG_USB_DWC3_KEYSTONE) += dwc3-keystone.o
|
||||
obj-$(CONFIG_USB_DWC3_OF_SIMPLE) += dwc3-of-simple.o
|
||||
obj-$(CONFIG_USB_DWC3_ST) += dwc3-st.o
|
||||
obj-$(CONFIG_USB_DWC3_QCOM) += dwc3-qcom.o
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
* Sebastian Andrzej Siewior <bigeasy@linutronix.de>
|
||||
*/
|
||||
|
||||
#include <linux/clk.h>
|
||||
#include <linux/version.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/kernel.h>
|
||||
|
@ -24,6 +25,7 @@
|
|||
#include <linux/of.h>
|
||||
#include <linux/acpi.h>
|
||||
#include <linux/pinctrl/consumer.h>
|
||||
#include <linux/reset.h>
|
||||
|
||||
#include <linux/usb/ch9.h>
|
||||
#include <linux/usb/gadget.h>
|
||||
|
@ -266,6 +268,12 @@ done:
|
|||
return 0;
|
||||
}
|
||||
|
||||
static const struct clk_bulk_data dwc3_core_clks[] = {
|
||||
{ .id = "ref" },
|
||||
{ .id = "bus_early" },
|
||||
{ .id = "suspend" },
|
||||
};
|
||||
|
||||
/*
|
||||
* dwc3_frame_length_adjustment - Adjusts frame length if required
|
||||
* @dwc3: Pointer to our controller context structure
|
||||
|
@ -667,6 +675,9 @@ static void dwc3_core_exit(struct dwc3 *dwc)
|
|||
usb_phy_set_suspend(dwc->usb3_phy, 1);
|
||||
phy_power_off(dwc->usb2_generic_phy);
|
||||
phy_power_off(dwc->usb3_generic_phy);
|
||||
clk_bulk_disable(dwc->num_clks, dwc->clks);
|
||||
clk_bulk_unprepare(dwc->num_clks, dwc->clks);
|
||||
reset_control_assert(dwc->reset);
|
||||
}
|
||||
|
||||
static bool dwc3_core_is_valid(struct dwc3 *dwc)
|
||||
|
@ -1245,7 +1256,7 @@ static void dwc3_check_params(struct dwc3 *dwc)
|
|||
static int dwc3_probe(struct platform_device *pdev)
|
||||
{
|
||||
struct device *dev = &pdev->dev;
|
||||
struct resource *res;
|
||||
struct resource *res, dwc_res;
|
||||
struct dwc3 *dwc;
|
||||
|
||||
int ret;
|
||||
|
@ -1256,6 +1267,12 @@ static int dwc3_probe(struct platform_device *pdev)
|
|||
if (!dwc)
|
||||
return -ENOMEM;
|
||||
|
||||
dwc->clks = devm_kmemdup(dev, dwc3_core_clks, sizeof(dwc3_core_clks),
|
||||
GFP_KERNEL);
|
||||
if (!dwc->clks)
|
||||
return -ENOMEM;
|
||||
|
||||
dwc->num_clks = ARRAY_SIZE(dwc3_core_clks);
|
||||
dwc->dev = dev;
|
||||
|
||||
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
||||
|
@ -1270,23 +1287,48 @@ static int dwc3_probe(struct platform_device *pdev)
|
|||
dwc->xhci_resources[0].flags = res->flags;
|
||||
dwc->xhci_resources[0].name = res->name;
|
||||
|
||||
res->start += DWC3_GLOBALS_REGS_START;
|
||||
|
||||
/*
|
||||
* Request memory region but exclude xHCI regs,
|
||||
* since it will be requested by the xhci-plat driver.
|
||||
*/
|
||||
regs = devm_ioremap_resource(dev, res);
|
||||
if (IS_ERR(regs)) {
|
||||
ret = PTR_ERR(regs);
|
||||
goto err0;
|
||||
}
|
||||
dwc_res = *res;
|
||||
dwc_res.start += DWC3_GLOBALS_REGS_START;
|
||||
|
||||
regs = devm_ioremap_resource(dev, &dwc_res);
|
||||
if (IS_ERR(regs))
|
||||
return PTR_ERR(regs);
|
||||
|
||||
dwc->regs = regs;
|
||||
dwc->regs_size = resource_size(res);
|
||||
dwc->regs_size = resource_size(&dwc_res);
|
||||
|
||||
dwc3_get_properties(dwc);
|
||||
|
||||
dwc->reset = devm_reset_control_get_optional_shared(dev, NULL);
|
||||
if (IS_ERR(dwc->reset))
|
||||
return PTR_ERR(dwc->reset);
|
||||
|
||||
ret = clk_bulk_get(dev, dwc->num_clks, dwc->clks);
|
||||
if (ret == -EPROBE_DEFER)
|
||||
return ret;
|
||||
/*
|
||||
* Clocks are optional, but new DT platforms should support all clocks
|
||||
* as required by the DT-binding.
|
||||
*/
|
||||
if (ret)
|
||||
dwc->num_clks = 0;
|
||||
|
||||
ret = reset_control_deassert(dwc->reset);
|
||||
if (ret)
|
||||
goto put_clks;
|
||||
|
||||
ret = clk_bulk_prepare(dwc->num_clks, dwc->clks);
|
||||
if (ret)
|
||||
goto assert_reset;
|
||||
|
||||
ret = clk_bulk_enable(dwc->num_clks, dwc->clks);
|
||||
if (ret)
|
||||
goto unprepare_clks;
|
||||
|
||||
platform_set_drvdata(pdev, dwc);
|
||||
dwc3_cache_hwparams(dwc);
|
||||
|
||||
|
@ -1350,13 +1392,13 @@ err1:
|
|||
pm_runtime_put_sync(&pdev->dev);
|
||||
pm_runtime_disable(&pdev->dev);
|
||||
|
||||
err0:
|
||||
/*
|
||||
* restore res->start back to its original value so that, in case the
|
||||
* probe is deferred, we don't end up getting error in request the
|
||||
* memory region the next time probe is called.
|
||||
*/
|
||||
res->start -= DWC3_GLOBALS_REGS_START;
|
||||
clk_bulk_disable(dwc->num_clks, dwc->clks);
|
||||
unprepare_clks:
|
||||
clk_bulk_unprepare(dwc->num_clks, dwc->clks);
|
||||
assert_reset:
|
||||
reset_control_assert(dwc->reset);
|
||||
put_clks:
|
||||
clk_bulk_put(dwc->num_clks, dwc->clks);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -1364,15 +1406,8 @@ err0:
|
|||
static int dwc3_remove(struct platform_device *pdev)
|
||||
{
|
||||
struct dwc3 *dwc = platform_get_drvdata(pdev);
|
||||
struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
||||
|
||||
pm_runtime_get_sync(&pdev->dev);
|
||||
/*
|
||||
* restore res->start back to its original value so that, in case the
|
||||
* probe is deferred, we don't end up getting error in request the
|
||||
* memory region the next time probe is called.
|
||||
*/
|
||||
res->start -= DWC3_GLOBALS_REGS_START;
|
||||
|
||||
dwc3_debugfs_exit(dwc);
|
||||
dwc3_core_exit_mode(dwc);
|
||||
|
@ -1386,14 +1421,48 @@ static int dwc3_remove(struct platform_device *pdev)
|
|||
|
||||
dwc3_free_event_buffers(dwc);
|
||||
dwc3_free_scratch_buffers(dwc);
|
||||
clk_bulk_put(dwc->num_clks, dwc->clks);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_PM
|
||||
static int dwc3_core_init_for_resume(struct dwc3 *dwc)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = reset_control_deassert(dwc->reset);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
ret = clk_bulk_prepare(dwc->num_clks, dwc->clks);
|
||||
if (ret)
|
||||
goto assert_reset;
|
||||
|
||||
ret = clk_bulk_enable(dwc->num_clks, dwc->clks);
|
||||
if (ret)
|
||||
goto unprepare_clks;
|
||||
|
||||
ret = dwc3_core_init(dwc);
|
||||
if (ret)
|
||||
goto disable_clks;
|
||||
|
||||
return 0;
|
||||
|
||||
disable_clks:
|
||||
clk_bulk_disable(dwc->num_clks, dwc->clks);
|
||||
unprepare_clks:
|
||||
clk_bulk_unprepare(dwc->num_clks, dwc->clks);
|
||||
assert_reset:
|
||||
reset_control_assert(dwc->reset);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg)
|
||||
{
|
||||
unsigned long flags;
|
||||
u32 reg;
|
||||
|
||||
switch (dwc->current_dr_role) {
|
||||
case DWC3_GCTL_PRTCAP_DEVICE:
|
||||
|
@ -1403,10 +1472,26 @@ static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg)
|
|||
dwc3_core_exit(dwc);
|
||||
break;
|
||||
case DWC3_GCTL_PRTCAP_HOST:
|
||||
/* do nothing during host runtime_suspend */
|
||||
if (!PMSG_IS_AUTO(msg))
|
||||
if (!PMSG_IS_AUTO(msg)) {
|
||||
dwc3_core_exit(dwc);
|
||||
break;
|
||||
}
|
||||
|
||||
/* Let controller to suspend HSPHY before PHY driver suspends */
|
||||
if (dwc->dis_u2_susphy_quirk ||
|
||||
dwc->dis_enblslpm_quirk) {
|
||||
reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0));
|
||||
reg |= DWC3_GUSB2PHYCFG_ENBLSLPM |
|
||||
DWC3_GUSB2PHYCFG_SUSPHY;
|
||||
dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg);
|
||||
|
||||
/* Give some time for USB2 PHY to suspend */
|
||||
usleep_range(5000, 6000);
|
||||
}
|
||||
|
||||
phy_pm_runtime_put_sync(dwc->usb2_generic_phy);
|
||||
phy_pm_runtime_put_sync(dwc->usb3_generic_phy);
|
||||
break;
|
||||
case DWC3_GCTL_PRTCAP_OTG:
|
||||
/* do nothing during runtime_suspend */
|
||||
if (PMSG_IS_AUTO(msg))
|
||||
|
@ -1433,10 +1518,11 @@ static int dwc3_resume_common(struct dwc3 *dwc, pm_message_t msg)
|
|||
{
|
||||
unsigned long flags;
|
||||
int ret;
|
||||
u32 reg;
|
||||
|
||||
switch (dwc->current_dr_role) {
|
||||
case DWC3_GCTL_PRTCAP_DEVICE:
|
||||
ret = dwc3_core_init(dwc);
|
||||
ret = dwc3_core_init_for_resume(dwc);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
|
@ -1446,13 +1532,25 @@ static int dwc3_resume_common(struct dwc3 *dwc, pm_message_t msg)
|
|||
spin_unlock_irqrestore(&dwc->lock, flags);
|
||||
break;
|
||||
case DWC3_GCTL_PRTCAP_HOST:
|
||||
/* nothing to do on host runtime_resume */
|
||||
if (!PMSG_IS_AUTO(msg)) {
|
||||
ret = dwc3_core_init(dwc);
|
||||
ret = dwc3_core_init_for_resume(dwc);
|
||||
if (ret)
|
||||
return ret;
|
||||
dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_HOST);
|
||||
break;
|
||||
}
|
||||
/* Restore GUSB2PHYCFG bits that were modified in suspend */
|
||||
reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0));
|
||||
if (dwc->dis_u2_susphy_quirk)
|
||||
reg &= ~DWC3_GUSB2PHYCFG_SUSPHY;
|
||||
|
||||
if (dwc->dis_enblslpm_quirk)
|
||||
reg &= ~DWC3_GUSB2PHYCFG_ENBLSLPM;
|
||||
|
||||
dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg);
|
||||
|
||||
phy_pm_runtime_get_sync(dwc->usb2_generic_phy);
|
||||
phy_pm_runtime_get_sync(dwc->usb3_generic_phy);
|
||||
break;
|
||||
case DWC3_GCTL_PRTCAP_OTG:
|
||||
/* nothing to do on runtime_resume */
|
||||
|
|
|
@ -639,8 +639,6 @@ struct dwc3_event_buffer {
|
|||
* @resource_index: Resource transfer index
|
||||
* @frame_number: set to the frame number we want this transfer to start (ISOC)
|
||||
* @interval: the interval on which the ISOC transfer is started
|
||||
* @allocated_requests: number of requests allocated
|
||||
* @queued_requests: number of requests queued for transfer
|
||||
* @name: a human readable name e.g. ep1out-bulk
|
||||
* @direction: true for TX, false for RX
|
||||
* @stream_capable: true when streams are enabled
|
||||
|
@ -664,11 +662,9 @@ struct dwc3_ep {
|
|||
#define DWC3_EP_ENABLED BIT(0)
|
||||
#define DWC3_EP_STALL BIT(1)
|
||||
#define DWC3_EP_WEDGE BIT(2)
|
||||
#define DWC3_EP_BUSY BIT(4)
|
||||
#define DWC3_EP_TRANSFER_STARTED BIT(3)
|
||||
#define DWC3_EP_PENDING_REQUEST BIT(5)
|
||||
#define DWC3_EP_MISSED_ISOC BIT(6)
|
||||
#define DWC3_EP_END_TRANSFER_PENDING BIT(7)
|
||||
#define DWC3_EP_TRANSFER_STARTED BIT(8)
|
||||
|
||||
/* This last one is specific to EP0 */
|
||||
#define DWC3_EP0_DIR_IN BIT(31)
|
||||
|
@ -688,8 +684,6 @@ struct dwc3_ep {
|
|||
u8 number;
|
||||
u8 type;
|
||||
u8 resource_index;
|
||||
u32 allocated_requests;
|
||||
u32 queued_requests;
|
||||
u32 frame_number;
|
||||
u32 interval;
|
||||
|
||||
|
@ -832,7 +826,9 @@ struct dwc3_hwparams {
|
|||
* @list: a list_head used for request queueing
|
||||
* @dep: struct dwc3_ep owning this request
|
||||
* @sg: pointer to first incomplete sg
|
||||
* @start_sg: pointer to the sg which should be queued next
|
||||
* @num_pending_sgs: counter to pending sgs
|
||||
* @num_queued_sgs: counter to the number of sgs which already got queued
|
||||
* @remaining: amount of data remaining
|
||||
* @epnum: endpoint number to which this request refers
|
||||
* @trb: pointer to struct dwc3_trb
|
||||
|
@ -848,8 +844,10 @@ struct dwc3_request {
|
|||
struct list_head list;
|
||||
struct dwc3_ep *dep;
|
||||
struct scatterlist *sg;
|
||||
struct scatterlist *start_sg;
|
||||
|
||||
unsigned num_pending_sgs;
|
||||
unsigned int num_queued_sgs;
|
||||
unsigned remaining;
|
||||
u8 epnum;
|
||||
struct dwc3_trb *trb;
|
||||
|
@ -891,6 +889,9 @@ struct dwc3_scratchpad_array {
|
|||
* @eps: endpoint array
|
||||
* @gadget: device side representation of the peripheral controller
|
||||
* @gadget_driver: pointer to the gadget driver
|
||||
* @clks: array of clocks
|
||||
* @num_clks: number of clocks
|
||||
* @reset: reset control
|
||||
* @regs: base address for our registers
|
||||
* @regs_size: address space size
|
||||
* @fladj: frame length adjustment
|
||||
|
@ -1013,6 +1014,11 @@ struct dwc3 {
|
|||
struct usb_gadget gadget;
|
||||
struct usb_gadget_driver *gadget_driver;
|
||||
|
||||
struct clk_bulk_data *clks;
|
||||
int num_clks;
|
||||
|
||||
struct reset_control *reset;
|
||||
|
||||
struct usb_phy *usb2_phy;
|
||||
struct usb_phy *usb3_phy;
|
||||
|
||||
|
@ -1197,11 +1203,12 @@ struct dwc3_event_depevt {
|
|||
/* Within XferNotReady */
|
||||
#define DEPEVT_STATUS_TRANSFER_ACTIVE BIT(3)
|
||||
|
||||
/* Within XferComplete */
|
||||
/* Within XferComplete or XferInProgress */
|
||||
#define DEPEVT_STATUS_BUSERR BIT(0)
|
||||
#define DEPEVT_STATUS_SHORT BIT(1)
|
||||
#define DEPEVT_STATUS_IOC BIT(2)
|
||||
#define DEPEVT_STATUS_LST BIT(3)
|
||||
#define DEPEVT_STATUS_LST BIT(3) /* XferComplete */
|
||||
#define DEPEVT_STATUS_MISSED_ISOC BIT(3) /* XferInProgress */
|
||||
|
||||
/* Stream event only */
|
||||
#define DEPEVT_STREAMEVT_FOUND 1
|
||||
|
|
|
@ -475,21 +475,37 @@ dwc3_ep_event_string(char *str, const struct dwc3_event_depevt *event,
|
|||
if (ret < 0)
|
||||
return "UNKNOWN";
|
||||
|
||||
status = event->status;
|
||||
|
||||
switch (event->endpoint_event) {
|
||||
case DWC3_DEPEVT_XFERCOMPLETE:
|
||||
strcat(str, "Transfer Complete");
|
||||
len = strlen(str);
|
||||
sprintf(str + len, "Transfer Complete (%c%c%c)",
|
||||
status & DEPEVT_STATUS_SHORT ? 'S' : 's',
|
||||
status & DEPEVT_STATUS_IOC ? 'I' : 'i',
|
||||
status & DEPEVT_STATUS_LST ? 'L' : 'l');
|
||||
|
||||
len = strlen(str);
|
||||
|
||||
if (epnum <= 1)
|
||||
sprintf(str + len, " [%s]", dwc3_ep0_state_string(ep0state));
|
||||
break;
|
||||
case DWC3_DEPEVT_XFERINPROGRESS:
|
||||
strcat(str, "Transfer In-Progress");
|
||||
len = strlen(str);
|
||||
|
||||
sprintf(str + len, "Transfer In Progress [%d] (%c%c%c)",
|
||||
event->parameters,
|
||||
status & DEPEVT_STATUS_SHORT ? 'S' : 's',
|
||||
status & DEPEVT_STATUS_IOC ? 'I' : 'i',
|
||||
status & DEPEVT_STATUS_LST ? 'M' : 'm');
|
||||
break;
|
||||
case DWC3_DEPEVT_XFERNOTREADY:
|
||||
strcat(str, "Transfer Not Ready");
|
||||
status = event->status & DEPEVT_STATUS_TRANSFER_ACTIVE;
|
||||
strcat(str, status ? " (Active)" : " (Not Active)");
|
||||
len = strlen(str);
|
||||
|
||||
sprintf(str + len, "Transfer Not Ready [%d]%s",
|
||||
event->parameters,
|
||||
status & DEPEVT_STATUS_TRANSFER_ACTIVE ?
|
||||
" (Active)" : " (Not Active)");
|
||||
|
||||
/* Control Endpoints */
|
||||
if (epnum <= 1) {
|
||||
|
|
|
@ -716,9 +716,6 @@ static void dwc3_debugfs_create_endpoint_dir(struct dwc3_ep *dep,
|
|||
struct dentry *dir;
|
||||
|
||||
dir = debugfs_create_dir(dep->name, parent);
|
||||
if (IS_ERR_OR_NULL(dir))
|
||||
return;
|
||||
|
||||
dwc3_debugfs_create_endpoint_files(dep, dir);
|
||||
}
|
||||
|
||||
|
@ -740,49 +737,31 @@ static void dwc3_debugfs_create_endpoint_dirs(struct dwc3 *dwc,
|
|||
void dwc3_debugfs_init(struct dwc3 *dwc)
|
||||
{
|
||||
struct dentry *root;
|
||||
struct dentry *file;
|
||||
|
||||
root = debugfs_create_dir(dev_name(dwc->dev), NULL);
|
||||
if (IS_ERR_OR_NULL(root)) {
|
||||
if (!root)
|
||||
dev_err(dwc->dev, "Can't create debugfs root\n");
|
||||
return;
|
||||
}
|
||||
dwc->root = root;
|
||||
|
||||
dwc->regset = kzalloc(sizeof(*dwc->regset), GFP_KERNEL);
|
||||
if (!dwc->regset) {
|
||||
debugfs_remove_recursive(root);
|
||||
if (!dwc->regset)
|
||||
return;
|
||||
}
|
||||
|
||||
dwc->regset->regs = dwc3_regs;
|
||||
dwc->regset->nregs = ARRAY_SIZE(dwc3_regs);
|
||||
dwc->regset->base = dwc->regs - DWC3_GLOBALS_REGS_START;
|
||||
|
||||
file = debugfs_create_regset32("regdump", S_IRUGO, root, dwc->regset);
|
||||
if (!file)
|
||||
dev_dbg(dwc->dev, "Can't create debugfs regdump\n");
|
||||
root = debugfs_create_dir(dev_name(dwc->dev), NULL);
|
||||
dwc->root = root;
|
||||
|
||||
debugfs_create_regset32("regdump", S_IRUGO, root, dwc->regset);
|
||||
|
||||
if (IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE)) {
|
||||
file = debugfs_create_file("mode", S_IRUGO | S_IWUSR, root,
|
||||
dwc, &dwc3_mode_fops);
|
||||
if (!file)
|
||||
dev_dbg(dwc->dev, "Can't create debugfs mode\n");
|
||||
debugfs_create_file("mode", S_IRUGO | S_IWUSR, root, dwc,
|
||||
&dwc3_mode_fops);
|
||||
}
|
||||
|
||||
if (IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE) ||
|
||||
IS_ENABLED(CONFIG_USB_DWC3_GADGET)) {
|
||||
file = debugfs_create_file("testmode", S_IRUGO | S_IWUSR, root,
|
||||
dwc, &dwc3_testmode_fops);
|
||||
if (!file)
|
||||
dev_dbg(dwc->dev, "Can't create debugfs testmode\n");
|
||||
|
||||
file = debugfs_create_file("link_state", S_IRUGO | S_IWUSR,
|
||||
root, dwc, &dwc3_link_state_fops);
|
||||
if (!file)
|
||||
dev_dbg(dwc->dev, "Can't create debugfs link_state\n");
|
||||
|
||||
debugfs_create_file("testmode", S_IRUGO | S_IWUSR, root, dwc,
|
||||
&dwc3_testmode_fops);
|
||||
debugfs_create_file("link_state", S_IRUGO | S_IWUSR, root, dwc,
|
||||
&dwc3_link_state_fops);
|
||||
dwc3_debugfs_create_endpoint_dirs(dwc, root);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
*/
|
||||
|
||||
#include <linux/extcon.h>
|
||||
#include <linux/of_graph.h>
|
||||
#include <linux/platform_device.h>
|
||||
|
||||
#include "debug.h"
|
||||
|
@ -439,17 +440,38 @@ static int dwc3_drd_notifier(struct notifier_block *nb,
|
|||
return NOTIFY_DONE;
|
||||
}
|
||||
|
||||
static struct extcon_dev *dwc3_get_extcon(struct dwc3 *dwc)
|
||||
{
|
||||
struct device *dev = dwc->dev;
|
||||
struct device_node *np_phy, *np_conn;
|
||||
struct extcon_dev *edev;
|
||||
|
||||
if (of_property_read_bool(dev->of_node, "extcon"))
|
||||
return extcon_get_edev_by_phandle(dwc->dev, 0);
|
||||
|
||||
np_phy = of_parse_phandle(dev->of_node, "phys", 0);
|
||||
np_conn = of_graph_get_remote_node(np_phy, -1, -1);
|
||||
|
||||
if (np_conn)
|
||||
edev = extcon_find_edev_by_node(np_conn);
|
||||
else
|
||||
edev = NULL;
|
||||
|
||||
of_node_put(np_conn);
|
||||
of_node_put(np_phy);
|
||||
|
||||
return edev;
|
||||
}
|
||||
|
||||
int dwc3_drd_init(struct dwc3 *dwc)
|
||||
{
|
||||
int ret, irq;
|
||||
|
||||
if (dwc->dev->of_node &&
|
||||
of_property_read_bool(dwc->dev->of_node, "extcon")) {
|
||||
dwc->edev = extcon_get_edev_by_phandle(dwc->dev, 0);
|
||||
|
||||
dwc->edev = dwc3_get_extcon(dwc);
|
||||
if (IS_ERR(dwc->edev))
|
||||
return PTR_ERR(dwc->edev);
|
||||
|
||||
if (dwc->edev) {
|
||||
dwc->edev_nb.notifier_call = dwc3_drd_notifier;
|
||||
ret = extcon_register_notifier(dwc->edev, EXTCON_USB_HOST,
|
||||
&dwc->edev_nb);
|
||||
|
|
|
@ -208,13 +208,13 @@ static const struct dev_pm_ops dwc3_of_simple_dev_pm_ops = {
|
|||
};
|
||||
|
||||
static const struct of_device_id of_dwc3_simple_match[] = {
|
||||
{ .compatible = "qcom,dwc3" },
|
||||
{ .compatible = "rockchip,rk3399-dwc3" },
|
||||
{ .compatible = "xlnx,zynqmp-dwc3" },
|
||||
{ .compatible = "cavium,octeon-7130-usb-uctl" },
|
||||
{ .compatible = "sprd,sc9860-dwc3" },
|
||||
{ .compatible = "amlogic,meson-axg-dwc3" },
|
||||
{ .compatible = "amlogic,meson-gxl-dwc3" },
|
||||
{ .compatible = "allwinner,sun50i-h6-dwc3" },
|
||||
{ /* Sentinel */ }
|
||||
};
|
||||
MODULE_DEVICE_TABLE(of, of_dwc3_simple_match);
|
||||
|
|
619
drivers/usb/dwc3/dwc3-qcom.c
Normal file
619
drivers/usb/dwc3/dwc3-qcom.c
Normal file
|
@ -0,0 +1,619 @@
|
|||
// SPDX-License-Identifier: GPL-2.0
|
||||
/* Copyright (c) 2018, The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Inspired by dwc3-of-simple.c
|
||||
*/
|
||||
|
||||
#include <linux/io.h>
|
||||
#include <linux/of.h>
|
||||
#include <linux/clk.h>
|
||||
#include <linux/irq.h>
|
||||
#include <linux/clk-provider.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/extcon.h>
|
||||
#include <linux/of_platform.h>
|
||||
#include <linux/platform_device.h>
|
||||
#include <linux/phy/phy.h>
|
||||
#include <linux/usb/of.h>
|
||||
#include <linux/reset.h>
|
||||
#include <linux/iopoll.h>
|
||||
|
||||
#include "core.h"
|
||||
|
||||
/* USB QSCRATCH Hardware registers */
|
||||
#define QSCRATCH_HS_PHY_CTRL 0x10
|
||||
#define UTMI_OTG_VBUS_VALID BIT(20)
|
||||
#define SW_SESSVLD_SEL BIT(28)
|
||||
|
||||
#define QSCRATCH_SS_PHY_CTRL 0x30
|
||||
#define LANE0_PWR_PRESENT BIT(24)
|
||||
|
||||
#define QSCRATCH_GENERAL_CFG 0x08
|
||||
#define PIPE_UTMI_CLK_SEL BIT(0)
|
||||
#define PIPE3_PHYSTATUS_SW BIT(3)
|
||||
#define PIPE_UTMI_CLK_DIS BIT(8)
|
||||
|
||||
#define PWR_EVNT_IRQ_STAT_REG 0x58
|
||||
#define PWR_EVNT_LPM_IN_L2_MASK BIT(4)
|
||||
#define PWR_EVNT_LPM_OUT_L2_MASK BIT(5)
|
||||
|
||||
struct dwc3_qcom {
|
||||
struct device *dev;
|
||||
void __iomem *qscratch_base;
|
||||
struct platform_device *dwc3;
|
||||
struct clk **clks;
|
||||
int num_clocks;
|
||||
struct reset_control *resets;
|
||||
|
||||
int hs_phy_irq;
|
||||
int dp_hs_phy_irq;
|
||||
int dm_hs_phy_irq;
|
||||
int ss_phy_irq;
|
||||
|
||||
struct extcon_dev *edev;
|
||||
struct extcon_dev *host_edev;
|
||||
struct notifier_block vbus_nb;
|
||||
struct notifier_block host_nb;
|
||||
|
||||
enum usb_dr_mode mode;
|
||||
bool is_suspended;
|
||||
bool pm_suspended;
|
||||
};
|
||||
|
||||
static inline void dwc3_qcom_setbits(void __iomem *base, u32 offset, u32 val)
|
||||
{
|
||||
u32 reg;
|
||||
|
||||
reg = readl(base + offset);
|
||||
reg |= val;
|
||||
writel(reg, base + offset);
|
||||
|
||||
/* ensure that above write is through */
|
||||
readl(base + offset);
|
||||
}
|
||||
|
||||
static inline void dwc3_qcom_clrbits(void __iomem *base, u32 offset, u32 val)
|
||||
{
|
||||
u32 reg;
|
||||
|
||||
reg = readl(base + offset);
|
||||
reg &= ~val;
|
||||
writel(reg, base + offset);
|
||||
|
||||
/* ensure that above write is through */
|
||||
readl(base + offset);
|
||||
}
|
||||
|
||||
static void dwc3_qcom_vbus_overrride_enable(struct dwc3_qcom *qcom, bool enable)
|
||||
{
|
||||
if (enable) {
|
||||
dwc3_qcom_setbits(qcom->qscratch_base, QSCRATCH_SS_PHY_CTRL,
|
||||
LANE0_PWR_PRESENT);
|
||||
dwc3_qcom_setbits(qcom->qscratch_base, QSCRATCH_HS_PHY_CTRL,
|
||||
UTMI_OTG_VBUS_VALID | SW_SESSVLD_SEL);
|
||||
} else {
|
||||
dwc3_qcom_clrbits(qcom->qscratch_base, QSCRATCH_SS_PHY_CTRL,
|
||||
LANE0_PWR_PRESENT);
|
||||
dwc3_qcom_clrbits(qcom->qscratch_base, QSCRATCH_HS_PHY_CTRL,
|
||||
UTMI_OTG_VBUS_VALID | SW_SESSVLD_SEL);
|
||||
}
|
||||
}
|
||||
|
||||
static int dwc3_qcom_vbus_notifier(struct notifier_block *nb,
|
||||
unsigned long event, void *ptr)
|
||||
{
|
||||
struct dwc3_qcom *qcom = container_of(nb, struct dwc3_qcom, vbus_nb);
|
||||
|
||||
/* enable vbus override for device mode */
|
||||
dwc3_qcom_vbus_overrride_enable(qcom, event);
|
||||
qcom->mode = event ? USB_DR_MODE_PERIPHERAL : USB_DR_MODE_HOST;
|
||||
|
||||
return NOTIFY_DONE;
|
||||
}
|
||||
|
||||
static int dwc3_qcom_host_notifier(struct notifier_block *nb,
|
||||
unsigned long event, void *ptr)
|
||||
{
|
||||
struct dwc3_qcom *qcom = container_of(nb, struct dwc3_qcom, host_nb);
|
||||
|
||||
/* disable vbus override in host mode */
|
||||
dwc3_qcom_vbus_overrride_enable(qcom, !event);
|
||||
qcom->mode = event ? USB_DR_MODE_HOST : USB_DR_MODE_PERIPHERAL;
|
||||
|
||||
return NOTIFY_DONE;
|
||||
}
|
||||
|
||||
static int dwc3_qcom_register_extcon(struct dwc3_qcom *qcom)
|
||||
{
|
||||
struct device *dev = qcom->dev;
|
||||
struct extcon_dev *host_edev;
|
||||
int ret;
|
||||
|
||||
if (!of_property_read_bool(dev->of_node, "extcon"))
|
||||
return 0;
|
||||
|
||||
qcom->edev = extcon_get_edev_by_phandle(dev, 0);
|
||||
if (IS_ERR(qcom->edev))
|
||||
return PTR_ERR(qcom->edev);
|
||||
|
||||
qcom->vbus_nb.notifier_call = dwc3_qcom_vbus_notifier;
|
||||
|
||||
qcom->host_edev = extcon_get_edev_by_phandle(dev, 1);
|
||||
if (IS_ERR(qcom->host_edev))
|
||||
qcom->host_edev = NULL;
|
||||
|
||||
ret = devm_extcon_register_notifier(dev, qcom->edev, EXTCON_USB,
|
||||
&qcom->vbus_nb);
|
||||
if (ret < 0) {
|
||||
dev_err(dev, "VBUS notifier register failed\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (qcom->host_edev)
|
||||
host_edev = qcom->host_edev;
|
||||
else
|
||||
host_edev = qcom->edev;
|
||||
|
||||
qcom->host_nb.notifier_call = dwc3_qcom_host_notifier;
|
||||
ret = devm_extcon_register_notifier(dev, host_edev, EXTCON_USB_HOST,
|
||||
&qcom->host_nb);
|
||||
if (ret < 0) {
|
||||
dev_err(dev, "Host notifier register failed\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Update initial VBUS override based on extcon state */
|
||||
if (extcon_get_state(qcom->edev, EXTCON_USB) ||
|
||||
!extcon_get_state(host_edev, EXTCON_USB_HOST))
|
||||
dwc3_qcom_vbus_notifier(&qcom->vbus_nb, true, qcom->edev);
|
||||
else
|
||||
dwc3_qcom_vbus_notifier(&qcom->vbus_nb, false, qcom->edev);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dwc3_qcom_disable_interrupts(struct dwc3_qcom *qcom)
|
||||
{
|
||||
if (qcom->hs_phy_irq) {
|
||||
disable_irq_wake(qcom->hs_phy_irq);
|
||||
disable_irq_nosync(qcom->hs_phy_irq);
|
||||
}
|
||||
|
||||
if (qcom->dp_hs_phy_irq) {
|
||||
disable_irq_wake(qcom->dp_hs_phy_irq);
|
||||
disable_irq_nosync(qcom->dp_hs_phy_irq);
|
||||
}
|
||||
|
||||
if (qcom->dm_hs_phy_irq) {
|
||||
disable_irq_wake(qcom->dm_hs_phy_irq);
|
||||
disable_irq_nosync(qcom->dm_hs_phy_irq);
|
||||
}
|
||||
|
||||
if (qcom->ss_phy_irq) {
|
||||
disable_irq_wake(qcom->ss_phy_irq);
|
||||
disable_irq_nosync(qcom->ss_phy_irq);
|
||||
}
|
||||
}
|
||||
|
||||
static void dwc3_qcom_enable_interrupts(struct dwc3_qcom *qcom)
|
||||
{
|
||||
if (qcom->hs_phy_irq) {
|
||||
enable_irq(qcom->hs_phy_irq);
|
||||
enable_irq_wake(qcom->hs_phy_irq);
|
||||
}
|
||||
|
||||
if (qcom->dp_hs_phy_irq) {
|
||||
enable_irq(qcom->dp_hs_phy_irq);
|
||||
enable_irq_wake(qcom->dp_hs_phy_irq);
|
||||
}
|
||||
|
||||
if (qcom->dm_hs_phy_irq) {
|
||||
enable_irq(qcom->dm_hs_phy_irq);
|
||||
enable_irq_wake(qcom->dm_hs_phy_irq);
|
||||
}
|
||||
|
||||
if (qcom->ss_phy_irq) {
|
||||
enable_irq(qcom->ss_phy_irq);
|
||||
enable_irq_wake(qcom->ss_phy_irq);
|
||||
}
|
||||
}
|
||||
|
||||
static int dwc3_qcom_suspend(struct dwc3_qcom *qcom)
|
||||
{
|
||||
u32 val;
|
||||
int i;
|
||||
|
||||
if (qcom->is_suspended)
|
||||
return 0;
|
||||
|
||||
val = readl(qcom->qscratch_base + PWR_EVNT_IRQ_STAT_REG);
|
||||
if (!(val & PWR_EVNT_LPM_IN_L2_MASK))
|
||||
dev_err(qcom->dev, "HS-PHY not in L2\n");
|
||||
|
||||
for (i = qcom->num_clocks - 1; i >= 0; i--)
|
||||
clk_disable_unprepare(qcom->clks[i]);
|
||||
|
||||
qcom->is_suspended = true;
|
||||
dwc3_qcom_enable_interrupts(qcom);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int dwc3_qcom_resume(struct dwc3_qcom *qcom)
|
||||
{
|
||||
int ret;
|
||||
int i;
|
||||
|
||||
if (!qcom->is_suspended)
|
||||
return 0;
|
||||
|
||||
dwc3_qcom_disable_interrupts(qcom);
|
||||
|
||||
for (i = 0; i < qcom->num_clocks; i++) {
|
||||
ret = clk_prepare_enable(qcom->clks[i]);
|
||||
if (ret < 0) {
|
||||
while (--i >= 0)
|
||||
clk_disable_unprepare(qcom->clks[i]);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
/* Clear existing events from PHY related to L2 in/out */
|
||||
dwc3_qcom_setbits(qcom->qscratch_base, PWR_EVNT_IRQ_STAT_REG,
|
||||
PWR_EVNT_LPM_IN_L2_MASK | PWR_EVNT_LPM_OUT_L2_MASK);
|
||||
|
||||
qcom->is_suspended = false;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static irqreturn_t qcom_dwc3_resume_irq(int irq, void *data)
|
||||
{
|
||||
struct dwc3_qcom *qcom = data;
|
||||
struct dwc3 *dwc = platform_get_drvdata(qcom->dwc3);
|
||||
|
||||
/* If pm_suspended then let pm_resume take care of resuming h/w */
|
||||
if (qcom->pm_suspended)
|
||||
return IRQ_HANDLED;
|
||||
|
||||
if (dwc->xhci)
|
||||
pm_runtime_resume(&dwc->xhci->dev);
|
||||
|
||||
return IRQ_HANDLED;
|
||||
}
|
||||
|
||||
static void dwc3_qcom_select_utmi_clk(struct dwc3_qcom *qcom)
|
||||
{
|
||||
/* Configure dwc3 to use UTMI clock as PIPE clock not present */
|
||||
dwc3_qcom_setbits(qcom->qscratch_base, QSCRATCH_GENERAL_CFG,
|
||||
PIPE_UTMI_CLK_DIS);
|
||||
|
||||
usleep_range(100, 1000);
|
||||
|
||||
dwc3_qcom_setbits(qcom->qscratch_base, QSCRATCH_GENERAL_CFG,
|
||||
PIPE_UTMI_CLK_SEL | PIPE3_PHYSTATUS_SW);
|
||||
|
||||
usleep_range(100, 1000);
|
||||
|
||||
dwc3_qcom_clrbits(qcom->qscratch_base, QSCRATCH_GENERAL_CFG,
|
||||
PIPE_UTMI_CLK_DIS);
|
||||
}
|
||||
|
||||
static int dwc3_qcom_setup_irq(struct platform_device *pdev)
|
||||
{
|
||||
struct dwc3_qcom *qcom = platform_get_drvdata(pdev);
|
||||
int irq, ret;
|
||||
|
||||
irq = platform_get_irq_byname(pdev, "hs_phy_irq");
|
||||
if (irq > 0) {
|
||||
/* Keep wakeup interrupts disabled until suspend */
|
||||
irq_set_status_flags(irq, IRQ_NOAUTOEN);
|
||||
ret = devm_request_threaded_irq(qcom->dev, irq, NULL,
|
||||
qcom_dwc3_resume_irq,
|
||||
IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
|
||||
"qcom_dwc3 HS", qcom);
|
||||
if (ret) {
|
||||
dev_err(qcom->dev, "hs_phy_irq failed: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
qcom->hs_phy_irq = irq;
|
||||
}
|
||||
|
||||
irq = platform_get_irq_byname(pdev, "dp_hs_phy_irq");
|
||||
if (irq > 0) {
|
||||
irq_set_status_flags(irq, IRQ_NOAUTOEN);
|
||||
ret = devm_request_threaded_irq(qcom->dev, irq, NULL,
|
||||
qcom_dwc3_resume_irq,
|
||||
IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
|
||||
"qcom_dwc3 DP_HS", qcom);
|
||||
if (ret) {
|
||||
dev_err(qcom->dev, "dp_hs_phy_irq failed: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
qcom->dp_hs_phy_irq = irq;
|
||||
}
|
||||
|
||||
irq = platform_get_irq_byname(pdev, "dm_hs_phy_irq");
|
||||
if (irq > 0) {
|
||||
irq_set_status_flags(irq, IRQ_NOAUTOEN);
|
||||
ret = devm_request_threaded_irq(qcom->dev, irq, NULL,
|
||||
qcom_dwc3_resume_irq,
|
||||
IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
|
||||
"qcom_dwc3 DM_HS", qcom);
|
||||
if (ret) {
|
||||
dev_err(qcom->dev, "dm_hs_phy_irq failed: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
qcom->dm_hs_phy_irq = irq;
|
||||
}
|
||||
|
||||
irq = platform_get_irq_byname(pdev, "ss_phy_irq");
|
||||
if (irq > 0) {
|
||||
irq_set_status_flags(irq, IRQ_NOAUTOEN);
|
||||
ret = devm_request_threaded_irq(qcom->dev, irq, NULL,
|
||||
qcom_dwc3_resume_irq,
|
||||
IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
|
||||
"qcom_dwc3 SS", qcom);
|
||||
if (ret) {
|
||||
dev_err(qcom->dev, "ss_phy_irq failed: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
qcom->ss_phy_irq = irq;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int dwc3_qcom_clk_init(struct dwc3_qcom *qcom, int count)
|
||||
{
|
||||
struct device *dev = qcom->dev;
|
||||
struct device_node *np = dev->of_node;
|
||||
int i;
|
||||
|
||||
qcom->num_clocks = count;
|
||||
|
||||
if (!count)
|
||||
return 0;
|
||||
|
||||
qcom->clks = devm_kcalloc(dev, qcom->num_clocks,
|
||||
sizeof(struct clk *), GFP_KERNEL);
|
||||
if (!qcom->clks)
|
||||
return -ENOMEM;
|
||||
|
||||
for (i = 0; i < qcom->num_clocks; i++) {
|
||||
struct clk *clk;
|
||||
int ret;
|
||||
|
||||
clk = of_clk_get(np, i);
|
||||
if (IS_ERR(clk)) {
|
||||
while (--i >= 0)
|
||||
clk_put(qcom->clks[i]);
|
||||
return PTR_ERR(clk);
|
||||
}
|
||||
|
||||
ret = clk_prepare_enable(clk);
|
||||
if (ret < 0) {
|
||||
while (--i >= 0) {
|
||||
clk_disable_unprepare(qcom->clks[i]);
|
||||
clk_put(qcom->clks[i]);
|
||||
}
|
||||
clk_put(clk);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
qcom->clks[i] = clk;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int dwc3_qcom_probe(struct platform_device *pdev)
|
||||
{
|
||||
struct device_node *np = pdev->dev.of_node, *dwc3_np;
|
||||
struct device *dev = &pdev->dev;
|
||||
struct dwc3_qcom *qcom;
|
||||
struct resource *res;
|
||||
int ret, i;
|
||||
bool ignore_pipe_clk;
|
||||
|
||||
qcom = devm_kzalloc(&pdev->dev, sizeof(*qcom), GFP_KERNEL);
|
||||
if (!qcom)
|
||||
return -ENOMEM;
|
||||
|
||||
platform_set_drvdata(pdev, qcom);
|
||||
qcom->dev = &pdev->dev;
|
||||
|
||||
qcom->resets = devm_reset_control_array_get_optional_exclusive(dev);
|
||||
if (IS_ERR(qcom->resets)) {
|
||||
ret = PTR_ERR(qcom->resets);
|
||||
dev_err(&pdev->dev, "failed to get resets, err=%d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = reset_control_assert(qcom->resets);
|
||||
if (ret) {
|
||||
dev_err(&pdev->dev, "failed to assert resets, err=%d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
usleep_range(10, 1000);
|
||||
|
||||
ret = reset_control_deassert(qcom->resets);
|
||||
if (ret) {
|
||||
dev_err(&pdev->dev, "failed to deassert resets, err=%d\n", ret);
|
||||
goto reset_assert;
|
||||
}
|
||||
|
||||
ret = dwc3_qcom_clk_init(qcom, of_count_phandle_with_args(np,
|
||||
"clocks", "#clock-cells"));
|
||||
if (ret) {
|
||||
dev_err(dev, "failed to get clocks\n");
|
||||
goto reset_assert;
|
||||
}
|
||||
|
||||
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
||||
qcom->qscratch_base = devm_ioremap_resource(dev, res);
|
||||
if (IS_ERR(qcom->qscratch_base)) {
|
||||
dev_err(dev, "failed to map qscratch, err=%d\n", ret);
|
||||
ret = PTR_ERR(qcom->qscratch_base);
|
||||
goto clk_disable;
|
||||
}
|
||||
|
||||
ret = dwc3_qcom_setup_irq(pdev);
|
||||
if (ret)
|
||||
goto clk_disable;
|
||||
|
||||
dwc3_np = of_get_child_by_name(np, "dwc3");
|
||||
if (!dwc3_np) {
|
||||
dev_err(dev, "failed to find dwc3 core child\n");
|
||||
ret = -ENODEV;
|
||||
goto clk_disable;
|
||||
}
|
||||
|
||||
/*
|
||||
* Disable pipe_clk requirement if specified. Used when dwc3
|
||||
* operates without SSPHY and only HS/FS/LS modes are supported.
|
||||
*/
|
||||
ignore_pipe_clk = device_property_read_bool(dev,
|
||||
"qcom,select-utmi-as-pipe-clk");
|
||||
if (ignore_pipe_clk)
|
||||
dwc3_qcom_select_utmi_clk(qcom);
|
||||
|
||||
ret = of_platform_populate(np, NULL, NULL, dev);
|
||||
if (ret) {
|
||||
dev_err(dev, "failed to register dwc3 core - %d\n", ret);
|
||||
goto clk_disable;
|
||||
}
|
||||
|
||||
qcom->dwc3 = of_find_device_by_node(dwc3_np);
|
||||
if (!qcom->dwc3) {
|
||||
dev_err(&pdev->dev, "failed to get dwc3 platform device\n");
|
||||
goto depopulate;
|
||||
}
|
||||
|
||||
qcom->mode = usb_get_dr_mode(&qcom->dwc3->dev);
|
||||
|
||||
/* enable vbus override for device mode */
|
||||
if (qcom->mode == USB_DR_MODE_PERIPHERAL)
|
||||
dwc3_qcom_vbus_overrride_enable(qcom, true);
|
||||
|
||||
/* register extcon to override sw_vbus on Vbus change later */
|
||||
ret = dwc3_qcom_register_extcon(qcom);
|
||||
if (ret)
|
||||
goto depopulate;
|
||||
|
||||
device_init_wakeup(&pdev->dev, 1);
|
||||
qcom->is_suspended = false;
|
||||
pm_runtime_set_active(dev);
|
||||
pm_runtime_enable(dev);
|
||||
pm_runtime_forbid(dev);
|
||||
|
||||
return 0;
|
||||
|
||||
depopulate:
|
||||
of_platform_depopulate(&pdev->dev);
|
||||
clk_disable:
|
||||
for (i = qcom->num_clocks - 1; i >= 0; i--) {
|
||||
clk_disable_unprepare(qcom->clks[i]);
|
||||
clk_put(qcom->clks[i]);
|
||||
}
|
||||
reset_assert:
|
||||
reset_control_assert(qcom->resets);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int dwc3_qcom_remove(struct platform_device *pdev)
|
||||
{
|
||||
struct dwc3_qcom *qcom = platform_get_drvdata(pdev);
|
||||
struct device *dev = &pdev->dev;
|
||||
int i;
|
||||
|
||||
of_platform_depopulate(dev);
|
||||
|
||||
for (i = qcom->num_clocks - 1; i >= 0; i--) {
|
||||
clk_disable_unprepare(qcom->clks[i]);
|
||||
clk_put(qcom->clks[i]);
|
||||
}
|
||||
qcom->num_clocks = 0;
|
||||
|
||||
reset_control_assert(qcom->resets);
|
||||
|
||||
pm_runtime_allow(dev);
|
||||
pm_runtime_disable(dev);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_PM_SLEEP
|
||||
static int dwc3_qcom_pm_suspend(struct device *dev)
|
||||
{
|
||||
struct dwc3_qcom *qcom = dev_get_drvdata(dev);
|
||||
int ret = 0;
|
||||
|
||||
ret = dwc3_qcom_suspend(qcom);
|
||||
if (!ret)
|
||||
qcom->pm_suspended = true;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int dwc3_qcom_pm_resume(struct device *dev)
|
||||
{
|
||||
struct dwc3_qcom *qcom = dev_get_drvdata(dev);
|
||||
int ret;
|
||||
|
||||
ret = dwc3_qcom_resume(qcom);
|
||||
if (!ret)
|
||||
qcom->pm_suspended = false;
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_PM
|
||||
static int dwc3_qcom_runtime_suspend(struct device *dev)
|
||||
{
|
||||
struct dwc3_qcom *qcom = dev_get_drvdata(dev);
|
||||
|
||||
return dwc3_qcom_suspend(qcom);
|
||||
}
|
||||
|
||||
static int dwc3_qcom_runtime_resume(struct device *dev)
|
||||
{
|
||||
struct dwc3_qcom *qcom = dev_get_drvdata(dev);
|
||||
|
||||
return dwc3_qcom_resume(qcom);
|
||||
}
|
||||
#endif
|
||||
|
||||
static const struct dev_pm_ops dwc3_qcom_dev_pm_ops = {
|
||||
SET_SYSTEM_SLEEP_PM_OPS(dwc3_qcom_pm_suspend, dwc3_qcom_pm_resume)
|
||||
SET_RUNTIME_PM_OPS(dwc3_qcom_runtime_suspend, dwc3_qcom_runtime_resume,
|
||||
NULL)
|
||||
};
|
||||
|
||||
static const struct of_device_id dwc3_qcom_of_match[] = {
|
||||
{ .compatible = "qcom,dwc3" },
|
||||
{ .compatible = "qcom,msm8996-dwc3" },
|
||||
{ .compatible = "qcom,sdm845-dwc3" },
|
||||
{ }
|
||||
};
|
||||
MODULE_DEVICE_TABLE(of, dwc3_qcom_of_match);
|
||||
|
||||
static struct platform_driver dwc3_qcom_driver = {
|
||||
.probe = dwc3_qcom_probe,
|
||||
.remove = dwc3_qcom_remove,
|
||||
.driver = {
|
||||
.name = "dwc3-qcom",
|
||||
.pm = &dwc3_qcom_dev_pm_ops,
|
||||
.of_match_table = dwc3_qcom_of_match,
|
||||
},
|
||||
};
|
||||
|
||||
module_platform_driver(dwc3_qcom_driver);
|
||||
|
||||
MODULE_LICENSE("GPL v2");
|
||||
MODULE_DESCRIPTION("DesignWare DWC3 QCOM Glue Driver");
|
|
@ -66,7 +66,7 @@ static int dwc3_ep0_start_trans(struct dwc3_ep *dep)
|
|||
struct dwc3 *dwc;
|
||||
int ret;
|
||||
|
||||
if (dep->flags & DWC3_EP_BUSY)
|
||||
if (dep->flags & DWC3_EP_TRANSFER_STARTED)
|
||||
return 0;
|
||||
|
||||
dwc = dep->dwc;
|
||||
|
@ -79,8 +79,6 @@ static int dwc3_ep0_start_trans(struct dwc3_ep *dep)
|
|||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
dep->flags |= DWC3_EP_BUSY;
|
||||
dep->resource_index = dwc3_gadget_ep_get_transfer_index(dep);
|
||||
dwc->ep0_next_event = DWC3_EP0_COMPLETE;
|
||||
|
||||
return 0;
|
||||
|
@ -913,7 +911,7 @@ static void dwc3_ep0_xfer_complete(struct dwc3 *dwc,
|
|||
{
|
||||
struct dwc3_ep *dep = dwc->eps[event->endpoint_number];
|
||||
|
||||
dep->flags &= ~DWC3_EP_BUSY;
|
||||
dep->flags &= ~DWC3_EP_TRANSFER_STARTED;
|
||||
dep->resource_index = 0;
|
||||
dwc->setup_packet_pending = false;
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -98,13 +98,12 @@ int __dwc3_gadget_ep_set_halt(struct dwc3_ep *dep, int value, int protocol);
|
|||
* Caller should take care of locking. Returns the transfer resource
|
||||
* index for a given endpoint.
|
||||
*/
|
||||
static inline u32 dwc3_gadget_ep_get_transfer_index(struct dwc3_ep *dep)
|
||||
static inline void dwc3_gadget_ep_get_transfer_index(struct dwc3_ep *dep)
|
||||
{
|
||||
u32 res_id;
|
||||
|
||||
res_id = dwc3_readl(dep->regs, DWC3_DEPCMD);
|
||||
|
||||
return DWC3_DEPCMD_GET_RSC_IDX(res_id);
|
||||
dep->resource_index = DWC3_DEPCMD_GET_RSC_IDX(res_id);
|
||||
}
|
||||
|
||||
#endif /* __DRIVERS_USB_DWC3_GADGET_H */
|
||||
|
|
|
@ -230,17 +230,14 @@ DECLARE_EVENT_CLASS(dwc3_log_trb,
|
|||
TP_fast_assign(
|
||||
__assign_str(name, dep->name);
|
||||
__entry->trb = trb;
|
||||
__entry->allocated = dep->allocated_requests;
|
||||
__entry->queued = dep->queued_requests;
|
||||
__entry->bpl = trb->bpl;
|
||||
__entry->bph = trb->bph;
|
||||
__entry->size = trb->size;
|
||||
__entry->ctrl = trb->ctrl;
|
||||
__entry->type = usb_endpoint_type(dep->endpoint.desc);
|
||||
),
|
||||
TP_printk("%s: %d/%d trb %p buf %08x%08x size %s%d ctrl %08x (%c%c%c%c:%c%c:%s)",
|
||||
__get_str(name), __entry->queued, __entry->allocated,
|
||||
__entry->trb, __entry->bph, __entry->bpl,
|
||||
TP_printk("%s: trb %p buf %08x%08x size %s%d ctrl %08x (%c%c%c%c:%c%c:%s)",
|
||||
__get_str(name), __entry->trb, __entry->bph, __entry->bpl,
|
||||
({char *s;
|
||||
int pcm = ((__entry->size >> 24) & 3) + 1;
|
||||
switch (__entry->type) {
|
||||
|
@ -306,7 +303,7 @@ DECLARE_EVENT_CLASS(dwc3_log_ep,
|
|||
__entry->trb_enqueue = dep->trb_enqueue;
|
||||
__entry->trb_dequeue = dep->trb_dequeue;
|
||||
),
|
||||
TP_printk("%s: mps %d/%d streams %d burst %d ring %d/%d flags %c:%c%c%c%c%c:%c:%c",
|
||||
TP_printk("%s: mps %d/%d streams %d burst %d ring %d/%d flags %c:%c%c%c%c:%c:%c",
|
||||
__get_str(name), __entry->maxpacket,
|
||||
__entry->maxpacket_limit, __entry->max_streams,
|
||||
__entry->maxburst, __entry->trb_enqueue,
|
||||
|
@ -314,9 +311,8 @@ DECLARE_EVENT_CLASS(dwc3_log_ep,
|
|||
__entry->flags & DWC3_EP_ENABLED ? 'E' : 'e',
|
||||
__entry->flags & DWC3_EP_STALL ? 'S' : 's',
|
||||
__entry->flags & DWC3_EP_WEDGE ? 'W' : 'w',
|
||||
__entry->flags & DWC3_EP_BUSY ? 'B' : 'b',
|
||||
__entry->flags & DWC3_EP_TRANSFER_STARTED ? 'B' : 'b',
|
||||
__entry->flags & DWC3_EP_PENDING_REQUEST ? 'P' : 'p',
|
||||
__entry->flags & DWC3_EP_MISSED_ISOC ? 'M' : 'm',
|
||||
__entry->flags & DWC3_EP_END_TRANSFER_PENDING ? 'E' : 'e',
|
||||
__entry->direction ? '<' : '>'
|
||||
)
|
||||
|
|
|
@ -1601,7 +1601,7 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
|
|||
cdev->gadget->ep0->maxpacket;
|
||||
if (gadget_is_superspeed(gadget)) {
|
||||
if (gadget->speed >= USB_SPEED_SUPER) {
|
||||
cdev->desc.bcdUSB = cpu_to_le16(0x0310);
|
||||
cdev->desc.bcdUSB = cpu_to_le16(0x0320);
|
||||
cdev->desc.bMaxPacketSize0 = 9;
|
||||
} else {
|
||||
cdev->desc.bcdUSB = cpu_to_le16(0x0210);
|
||||
|
|
|
@ -705,6 +705,8 @@ ecm_bind(struct usb_configuration *c, struct usb_function *f)
|
|||
ecm_opts->bound = true;
|
||||
}
|
||||
|
||||
ecm_string_defs[1].s = ecm->ethaddr;
|
||||
|
||||
us = usb_gstrings_attach(cdev, ecm_strings,
|
||||
ARRAY_SIZE(ecm_string_defs));
|
||||
if (IS_ERR(us))
|
||||
|
@ -928,7 +930,6 @@ static struct usb_function *ecm_alloc(struct usb_function_instance *fi)
|
|||
mutex_unlock(&opts->lock);
|
||||
return ERR_PTR(-EINVAL);
|
||||
}
|
||||
ecm_string_defs[1].s = ecm->ethaddr;
|
||||
|
||||
ecm->port.ioport = netdev_priv(opts->net);
|
||||
mutex_unlock(&opts->lock);
|
||||
|
|
|
@ -1266,6 +1266,14 @@ static long ffs_epfile_ioctl(struct file *file, unsigned code,
|
|||
return ret;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_COMPAT
|
||||
static long ffs_epfile_compat_ioctl(struct file *file, unsigned code,
|
||||
unsigned long value)
|
||||
{
|
||||
return ffs_epfile_ioctl(file, code, value);
|
||||
}
|
||||
#endif
|
||||
|
||||
static const struct file_operations ffs_epfile_operations = {
|
||||
.llseek = no_llseek,
|
||||
|
||||
|
@ -1274,6 +1282,9 @@ static const struct file_operations ffs_epfile_operations = {
|
|||
.read_iter = ffs_epfile_read_iter,
|
||||
.release = ffs_epfile_release,
|
||||
.unlocked_ioctl = ffs_epfile_ioctl,
|
||||
#ifdef CONFIG_COMPAT
|
||||
.compat_ioctl = ffs_epfile_compat_ioctl,
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -109,6 +109,7 @@ static inline struct f_midi *func_to_midi(struct usb_function *f)
|
|||
|
||||
static void f_midi_transmit(struct f_midi *midi);
|
||||
static void f_midi_rmidi_free(struct snd_rawmidi *rmidi);
|
||||
static void f_midi_free_inst(struct usb_function_instance *f);
|
||||
|
||||
DECLARE_UAC_AC_HEADER_DESCRIPTOR(1);
|
||||
DECLARE_USB_MIDI_OUT_JACK_DESCRIPTOR(1);
|
||||
|
@ -1102,7 +1103,7 @@ static ssize_t f_midi_opts_##name##_store(struct config_item *item, \
|
|||
u32 num; \
|
||||
\
|
||||
mutex_lock(&opts->lock); \
|
||||
if (opts->refcnt) { \
|
||||
if (opts->refcnt > 1) { \
|
||||
ret = -EBUSY; \
|
||||
goto end; \
|
||||
} \
|
||||
|
@ -1157,7 +1158,7 @@ static ssize_t f_midi_opts_id_store(struct config_item *item,
|
|||
char *c;
|
||||
|
||||
mutex_lock(&opts->lock);
|
||||
if (opts->refcnt) {
|
||||
if (opts->refcnt > 1) {
|
||||
ret = -EBUSY;
|
||||
goto end;
|
||||
}
|
||||
|
@ -1198,13 +1199,21 @@ static const struct config_item_type midi_func_type = {
|
|||
static void f_midi_free_inst(struct usb_function_instance *f)
|
||||
{
|
||||
struct f_midi_opts *opts;
|
||||
bool free = false;
|
||||
|
||||
opts = container_of(f, struct f_midi_opts, func_inst);
|
||||
|
||||
mutex_lock(&opts->lock);
|
||||
if (!--opts->refcnt) {
|
||||
free = true;
|
||||
}
|
||||
mutex_unlock(&opts->lock);
|
||||
|
||||
if (free) {
|
||||
if (opts->id_allocated)
|
||||
kfree(opts->id);
|
||||
|
||||
kfree(opts);
|
||||
}
|
||||
}
|
||||
|
||||
static struct usb_function_instance *f_midi_alloc_inst(void)
|
||||
|
@ -1223,6 +1232,7 @@ static struct usb_function_instance *f_midi_alloc_inst(void)
|
|||
opts->qlen = 32;
|
||||
opts->in_ports = 1;
|
||||
opts->out_ports = 1;
|
||||
opts->refcnt = 1;
|
||||
|
||||
config_group_init_type_name(&opts->func_inst.group, "",
|
||||
&midi_func_type);
|
||||
|
@ -1234,6 +1244,7 @@ static void f_midi_free(struct usb_function *f)
|
|||
{
|
||||
struct f_midi *midi;
|
||||
struct f_midi_opts *opts;
|
||||
bool free = false;
|
||||
|
||||
midi = func_to_midi(f);
|
||||
opts = container_of(f->fi, struct f_midi_opts, func_inst);
|
||||
|
@ -1242,9 +1253,12 @@ static void f_midi_free(struct usb_function *f)
|
|||
kfree(midi->id);
|
||||
kfifo_free(&midi->in_req_fifo);
|
||||
kfree(midi);
|
||||
--opts->refcnt;
|
||||
free = true;
|
||||
}
|
||||
mutex_unlock(&opts->lock);
|
||||
|
||||
if (free)
|
||||
f_midi_free_inst(&opts->func_inst);
|
||||
}
|
||||
|
||||
static void f_midi_rmidi_free(struct snd_rawmidi *rmidi)
|
||||
|
|
|
@ -631,19 +631,19 @@ printer_write(struct file *fd, const char __user *buf, size_t len, loff_t *ptr)
|
|||
return -EAGAIN;
|
||||
}
|
||||
|
||||
list_add(&req->list, &dev->tx_reqs_active);
|
||||
|
||||
/* here, we unlock, and only unlock, to avoid deadlock. */
|
||||
spin_unlock(&dev->lock);
|
||||
value = usb_ep_queue(dev->in_ep, req, GFP_ATOMIC);
|
||||
spin_lock(&dev->lock);
|
||||
if (value) {
|
||||
list_del(&req->list);
|
||||
list_add(&req->list, &dev->tx_reqs);
|
||||
spin_unlock_irqrestore(&dev->lock, flags);
|
||||
mutex_unlock(&dev->lock_printer_io);
|
||||
return -EAGAIN;
|
||||
}
|
||||
|
||||
list_add(&req->list, &dev->tx_reqs_active);
|
||||
|
||||
}
|
||||
|
||||
spin_unlock_irqrestore(&dev->lock, flags);
|
||||
|
|
|
@ -851,6 +851,9 @@ int rndis_msg_parser(struct rndis_params *params, u8 *buf)
|
|||
*/
|
||||
pr_warn("%s: unknown RNDIS message 0x%08X len %d\n",
|
||||
__func__, MsgType, MsgLength);
|
||||
/* Garbled message can be huge, so limit what we display */
|
||||
if (MsgLength > 16)
|
||||
MsgLength = 16;
|
||||
print_hex_dump_bytes(__func__, DUMP_PREFIX_OFFSET,
|
||||
buf, MsgLength);
|
||||
break;
|
||||
|
|
|
@ -844,6 +844,10 @@ struct net_device *gether_setup_name_default(const char *netname)
|
|||
net->ethtool_ops = &ops;
|
||||
SET_NETDEV_DEVTYPE(net, &gadget_type);
|
||||
|
||||
/* MTU range: 14 - 15412 */
|
||||
net->min_mtu = ETH_HLEN;
|
||||
net->max_mtu = GETHER_MAX_ETH_FRAME_LEN;
|
||||
|
||||
return net;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(gether_setup_name_default);
|
||||
|
|
|
@ -179,7 +179,7 @@ config USB_R8A66597
|
|||
|
||||
config USB_RENESAS_USBHS_UDC
|
||||
tristate 'Renesas USBHS controller'
|
||||
depends on USB_RENESAS_USBHS && HAS_DMA
|
||||
depends on USB_RENESAS_USBHS
|
||||
help
|
||||
Renesas USBHS is a discrete USB host and peripheral controller chip
|
||||
that supports both full and high speed USB 2.0 data transfers.
|
||||
|
@ -192,7 +192,7 @@ config USB_RENESAS_USBHS_UDC
|
|||
config USB_RENESAS_USB3
|
||||
tristate 'Renesas USB3.0 Peripheral controller'
|
||||
depends on ARCH_RENESAS || COMPILE_TEST
|
||||
depends on EXTCON && HAS_DMA
|
||||
depends on EXTCON
|
||||
help
|
||||
Renesas USB3.0 Peripheral controller is a USB peripheral controller
|
||||
that supports super, high, and full speed USB 3.0 data transfers.
|
||||
|
@ -438,6 +438,8 @@ config USB_GADGET_XILINX
|
|||
dynamically linked module called "udc-xilinx" and force all
|
||||
gadget drivers to also be dynamically linked.
|
||||
|
||||
source "drivers/usb/gadget/udc/aspeed-vhub/Kconfig"
|
||||
|
||||
#
|
||||
# LAST -- dummy/emulated controller
|
||||
#
|
||||
|
|
|
@ -39,4 +39,5 @@ obj-$(CONFIG_USB_MV_U3D) += mv_u3d_core.o
|
|||
obj-$(CONFIG_USB_GR_UDC) += gr_udc.o
|
||||
obj-$(CONFIG_USB_GADGET_XILINX) += udc-xilinx.o
|
||||
obj-$(CONFIG_USB_SNP_UDC_PLAT) += snps_udc_plat.o
|
||||
obj-$(CONFIG_USB_ASPEED_VHUB) += aspeed-vhub/
|
||||
obj-$(CONFIG_USB_BDC_UDC) += bdc/
|
||||
|
|
7
drivers/usb/gadget/udc/aspeed-vhub/Kconfig
Normal file
7
drivers/usb/gadget/udc/aspeed-vhub/Kconfig
Normal file
|
@ -0,0 +1,7 @@
|
|||
# SPDX-License-Identifier: GPL-2.0+
|
||||
config USB_ASPEED_VHUB
|
||||
tristate "Aspeed vHub UDC driver"
|
||||
depends on ARCH_ASPEED || COMPILE_TEST
|
||||
help
|
||||
USB peripheral controller for the Aspeed AST2500 family
|
||||
SoCs supporting the "vHub" functionality and USB2.0
|
4
drivers/usb/gadget/udc/aspeed-vhub/Makefile
Normal file
4
drivers/usb/gadget/udc/aspeed-vhub/Makefile
Normal file
|
@ -0,0 +1,4 @@
|
|||
# SPDX-License-Identifier: GPL-2.0+
|
||||
obj-$(CONFIG_USB_ASPEED_VHUB) += aspeed-vhub.o
|
||||
aspeed-vhub-y := core.o ep0.o epn.o dev.o hub.o
|
||||
|
425
drivers/usb/gadget/udc/aspeed-vhub/core.c
Normal file
425
drivers/usb/gadget/udc/aspeed-vhub/core.c
Normal file
|
@ -0,0 +1,425 @@
|
|||
// SPDX-License-Identifier: GPL-2.0+
|
||||
/*
|
||||
* aspeed-vhub -- Driver for Aspeed SoC "vHub" USB gadget
|
||||
*
|
||||
* core.c - Top level support
|
||||
*
|
||||
* Copyright 2017 IBM Corporation
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/platform_device.h>
|
||||
#include <linux/delay.h>
|
||||
#include <linux/ioport.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/errno.h>
|
||||
#include <linux/list.h>
|
||||
#include <linux/interrupt.h>
|
||||
#include <linux/proc_fs.h>
|
||||
#include <linux/prefetch.h>
|
||||
#include <linux/clk.h>
|
||||
#include <linux/usb/gadget.h>
|
||||
#include <linux/of.h>
|
||||
#include <linux/of_gpio.h>
|
||||
#include <linux/regmap.h>
|
||||
#include <linux/dma-mapping.h>
|
||||
|
||||
#include "vhub.h"
|
||||
|
||||
void ast_vhub_done(struct ast_vhub_ep *ep, struct ast_vhub_req *req,
|
||||
int status)
|
||||
{
|
||||
bool internal = req->internal;
|
||||
|
||||
EPVDBG(ep, "completing request @%p, status %d\n", req, status);
|
||||
|
||||
list_del_init(&req->queue);
|
||||
|
||||
if (req->req.status == -EINPROGRESS)
|
||||
req->req.status = status;
|
||||
|
||||
if (req->req.dma) {
|
||||
if (!WARN_ON(!ep->dev))
|
||||
usb_gadget_unmap_request(&ep->dev->gadget,
|
||||
&req->req, ep->epn.is_in);
|
||||
req->req.dma = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* If this isn't an internal EP0 request, call the core
|
||||
* to call the gadget completion.
|
||||
*/
|
||||
if (!internal) {
|
||||
spin_unlock(&ep->vhub->lock);
|
||||
usb_gadget_giveback_request(&ep->ep, &req->req);
|
||||
spin_lock(&ep->vhub->lock);
|
||||
}
|
||||
}
|
||||
|
||||
void ast_vhub_nuke(struct ast_vhub_ep *ep, int status)
|
||||
{
|
||||
struct ast_vhub_req *req;
|
||||
|
||||
EPDBG(ep, "Nuking\n");
|
||||
|
||||
/* Beware, lock will be dropped & req-acquired by done() */
|
||||
while (!list_empty(&ep->queue)) {
|
||||
req = list_first_entry(&ep->queue, struct ast_vhub_req, queue);
|
||||
ast_vhub_done(ep, req, status);
|
||||
}
|
||||
}
|
||||
|
||||
struct usb_request *ast_vhub_alloc_request(struct usb_ep *u_ep,
|
||||
gfp_t gfp_flags)
|
||||
{
|
||||
struct ast_vhub_req *req;
|
||||
|
||||
req = kzalloc(sizeof(*req), gfp_flags);
|
||||
if (!req)
|
||||
return NULL;
|
||||
return &req->req;
|
||||
}
|
||||
|
||||
void ast_vhub_free_request(struct usb_ep *u_ep, struct usb_request *u_req)
|
||||
{
|
||||
struct ast_vhub_req *req = to_ast_req(u_req);
|
||||
|
||||
kfree(req);
|
||||
}
|
||||
|
||||
static irqreturn_t ast_vhub_irq(int irq, void *data)
|
||||
{
|
||||
struct ast_vhub *vhub = data;
|
||||
irqreturn_t iret = IRQ_NONE;
|
||||
u32 istat;
|
||||
|
||||
/* Stale interrupt while tearing down */
|
||||
if (!vhub->ep0_bufs)
|
||||
return IRQ_NONE;
|
||||
|
||||
spin_lock(&vhub->lock);
|
||||
|
||||
/* Read and ACK interrupts */
|
||||
istat = readl(vhub->regs + AST_VHUB_ISR);
|
||||
if (!istat)
|
||||
goto bail;
|
||||
writel(istat, vhub->regs + AST_VHUB_ISR);
|
||||
iret = IRQ_HANDLED;
|
||||
|
||||
UDCVDBG(vhub, "irq status=%08x, ep_acks=%08x ep_nacks=%08x\n",
|
||||
istat,
|
||||
readl(vhub->regs + AST_VHUB_EP_ACK_ISR),
|
||||
readl(vhub->regs + AST_VHUB_EP_NACK_ISR));
|
||||
|
||||
/* Handle generic EPs first */
|
||||
if (istat & VHUB_IRQ_EP_POOL_ACK_STALL) {
|
||||
u32 i, ep_acks = readl(vhub->regs + AST_VHUB_EP_ACK_ISR);
|
||||
writel(ep_acks, vhub->regs + AST_VHUB_EP_ACK_ISR);
|
||||
|
||||
for (i = 0; ep_acks && i < AST_VHUB_NUM_GEN_EPs; i++) {
|
||||
u32 mask = VHUB_EP_IRQ(i);
|
||||
if (ep_acks & mask) {
|
||||
ast_vhub_epn_ack_irq(&vhub->epns[i]);
|
||||
ep_acks &= ~mask;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Handle device interrupts */
|
||||
if (istat & (VHUB_IRQ_DEVICE1 |
|
||||
VHUB_IRQ_DEVICE2 |
|
||||
VHUB_IRQ_DEVICE3 |
|
||||
VHUB_IRQ_DEVICE4 |
|
||||
VHUB_IRQ_DEVICE5)) {
|
||||
if (istat & VHUB_IRQ_DEVICE1)
|
||||
ast_vhub_dev_irq(&vhub->ports[0].dev);
|
||||
if (istat & VHUB_IRQ_DEVICE2)
|
||||
ast_vhub_dev_irq(&vhub->ports[1].dev);
|
||||
if (istat & VHUB_IRQ_DEVICE3)
|
||||
ast_vhub_dev_irq(&vhub->ports[2].dev);
|
||||
if (istat & VHUB_IRQ_DEVICE4)
|
||||
ast_vhub_dev_irq(&vhub->ports[3].dev);
|
||||
if (istat & VHUB_IRQ_DEVICE5)
|
||||
ast_vhub_dev_irq(&vhub->ports[4].dev);
|
||||
}
|
||||
|
||||
/* Handle top-level vHub EP0 interrupts */
|
||||
if (istat & (VHUB_IRQ_HUB_EP0_OUT_ACK_STALL |
|
||||
VHUB_IRQ_HUB_EP0_IN_ACK_STALL |
|
||||
VHUB_IRQ_HUB_EP0_SETUP)) {
|
||||
if (istat & VHUB_IRQ_HUB_EP0_IN_ACK_STALL)
|
||||
ast_vhub_ep0_handle_ack(&vhub->ep0, true);
|
||||
if (istat & VHUB_IRQ_HUB_EP0_OUT_ACK_STALL)
|
||||
ast_vhub_ep0_handle_ack(&vhub->ep0, false);
|
||||
if (istat & VHUB_IRQ_HUB_EP0_SETUP)
|
||||
ast_vhub_ep0_handle_setup(&vhub->ep0);
|
||||
}
|
||||
|
||||
/* Various top level bus events */
|
||||
if (istat & (VHUB_IRQ_BUS_RESUME |
|
||||
VHUB_IRQ_BUS_SUSPEND |
|
||||
VHUB_IRQ_BUS_RESET)) {
|
||||
if (istat & VHUB_IRQ_BUS_RESUME)
|
||||
ast_vhub_hub_resume(vhub);
|
||||
if (istat & VHUB_IRQ_BUS_SUSPEND)
|
||||
ast_vhub_hub_suspend(vhub);
|
||||
if (istat & VHUB_IRQ_BUS_RESET)
|
||||
ast_vhub_hub_reset(vhub);
|
||||
}
|
||||
|
||||
bail:
|
||||
spin_unlock(&vhub->lock);
|
||||
return iret;
|
||||
}
|
||||
|
||||
void ast_vhub_init_hw(struct ast_vhub *vhub)
|
||||
{
|
||||
u32 ctrl;
|
||||
|
||||
UDCDBG(vhub,"(Re)Starting HW ...\n");
|
||||
|
||||
/* Enable PHY */
|
||||
ctrl = VHUB_CTRL_PHY_CLK |
|
||||
VHUB_CTRL_PHY_RESET_DIS;
|
||||
|
||||
/*
|
||||
* We do *NOT* set the VHUB_CTRL_CLK_STOP_SUSPEND bit
|
||||
* to stop the logic clock during suspend because
|
||||
* it causes the registers to become inaccessible and
|
||||
* we haven't yet figured out a good wayt to bring the
|
||||
* controller back into life to issue a wakeup.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Set some ISO & split control bits according to Aspeed
|
||||
* recommendation
|
||||
*
|
||||
* VHUB_CTRL_ISO_RSP_CTRL: When set tells the HW to respond
|
||||
* with 0 bytes data packet to ISO IN endpoints when no data
|
||||
* is available.
|
||||
*
|
||||
* VHUB_CTRL_SPLIT_IN: This makes a SOF complete a split IN
|
||||
* transaction.
|
||||
*/
|
||||
ctrl |= VHUB_CTRL_ISO_RSP_CTRL | VHUB_CTRL_SPLIT_IN;
|
||||
writel(ctrl, vhub->regs + AST_VHUB_CTRL);
|
||||
udelay(1);
|
||||
|
||||
/* Set descriptor ring size */
|
||||
if (AST_VHUB_DESCS_COUNT == 256) {
|
||||
ctrl |= VHUB_CTRL_LONG_DESC;
|
||||
writel(ctrl, vhub->regs + AST_VHUB_CTRL);
|
||||
} else {
|
||||
BUILD_BUG_ON(AST_VHUB_DESCS_COUNT != 32);
|
||||
}
|
||||
|
||||
/* Reset all devices */
|
||||
writel(VHUB_SW_RESET_ALL, vhub->regs + AST_VHUB_SW_RESET);
|
||||
udelay(1);
|
||||
writel(0, vhub->regs + AST_VHUB_SW_RESET);
|
||||
|
||||
/* Disable and cleanup EP ACK/NACK interrupts */
|
||||
writel(0, vhub->regs + AST_VHUB_EP_ACK_IER);
|
||||
writel(0, vhub->regs + AST_VHUB_EP_NACK_IER);
|
||||
writel(VHUB_EP_IRQ_ALL, vhub->regs + AST_VHUB_EP_ACK_ISR);
|
||||
writel(VHUB_EP_IRQ_ALL, vhub->regs + AST_VHUB_EP_NACK_ISR);
|
||||
|
||||
/* Default settings for EP0, enable HW hub EP1 */
|
||||
writel(0, vhub->regs + AST_VHUB_EP0_CTRL);
|
||||
writel(VHUB_EP1_CTRL_RESET_TOGGLE |
|
||||
VHUB_EP1_CTRL_ENABLE,
|
||||
vhub->regs + AST_VHUB_EP1_CTRL);
|
||||
writel(0, vhub->regs + AST_VHUB_EP1_STS_CHG);
|
||||
|
||||
/* Configure EP0 DMA buffer */
|
||||
writel(vhub->ep0.buf_dma, vhub->regs + AST_VHUB_EP0_DATA);
|
||||
|
||||
/* Clear address */
|
||||
writel(0, vhub->regs + AST_VHUB_CONF);
|
||||
|
||||
/* Pullup hub (activate on host) */
|
||||
if (vhub->force_usb1)
|
||||
ctrl |= VHUB_CTRL_FULL_SPEED_ONLY;
|
||||
|
||||
ctrl |= VHUB_CTRL_UPSTREAM_CONNECT;
|
||||
writel(ctrl, vhub->regs + AST_VHUB_CTRL);
|
||||
|
||||
/* Enable some interrupts */
|
||||
writel(VHUB_IRQ_HUB_EP0_IN_ACK_STALL |
|
||||
VHUB_IRQ_HUB_EP0_OUT_ACK_STALL |
|
||||
VHUB_IRQ_HUB_EP0_SETUP |
|
||||
VHUB_IRQ_EP_POOL_ACK_STALL |
|
||||
VHUB_IRQ_BUS_RESUME |
|
||||
VHUB_IRQ_BUS_SUSPEND |
|
||||
VHUB_IRQ_BUS_RESET,
|
||||
vhub->regs + AST_VHUB_IER);
|
||||
}
|
||||
|
||||
static int ast_vhub_remove(struct platform_device *pdev)
|
||||
{
|
||||
struct ast_vhub *vhub = platform_get_drvdata(pdev);
|
||||
unsigned long flags;
|
||||
int i;
|
||||
|
||||
if (!vhub || !vhub->regs)
|
||||
return 0;
|
||||
|
||||
/* Remove devices */
|
||||
for (i = 0; i < AST_VHUB_NUM_PORTS; i++)
|
||||
ast_vhub_del_dev(&vhub->ports[i].dev);
|
||||
|
||||
spin_lock_irqsave(&vhub->lock, flags);
|
||||
|
||||
/* Mask & ack all interrupts */
|
||||
writel(0, vhub->regs + AST_VHUB_IER);
|
||||
writel(VHUB_IRQ_ACK_ALL, vhub->regs + AST_VHUB_ISR);
|
||||
|
||||
/* Pull device, leave PHY enabled */
|
||||
writel(VHUB_CTRL_PHY_CLK |
|
||||
VHUB_CTRL_PHY_RESET_DIS,
|
||||
vhub->regs + AST_VHUB_CTRL);
|
||||
|
||||
if (vhub->clk)
|
||||
clk_disable_unprepare(vhub->clk);
|
||||
|
||||
spin_unlock_irqrestore(&vhub->lock, flags);
|
||||
|
||||
if (vhub->ep0_bufs)
|
||||
dma_free_coherent(&pdev->dev,
|
||||
AST_VHUB_EP0_MAX_PACKET *
|
||||
(AST_VHUB_NUM_PORTS + 1),
|
||||
vhub->ep0_bufs,
|
||||
vhub->ep0_bufs_dma);
|
||||
vhub->ep0_bufs = NULL;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ast_vhub_probe(struct platform_device *pdev)
|
||||
{
|
||||
enum usb_device_speed max_speed;
|
||||
struct ast_vhub *vhub;
|
||||
struct resource *res;
|
||||
int i, rc = 0;
|
||||
|
||||
vhub = devm_kzalloc(&pdev->dev, sizeof(*vhub), GFP_KERNEL);
|
||||
if (!vhub)
|
||||
return -ENOMEM;
|
||||
|
||||
spin_lock_init(&vhub->lock);
|
||||
vhub->pdev = pdev;
|
||||
|
||||
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
||||
vhub->regs = devm_ioremap_resource(&pdev->dev, res);
|
||||
if (IS_ERR(vhub->regs)) {
|
||||
dev_err(&pdev->dev, "Failed to map resources\n");
|
||||
return PTR_ERR(vhub->regs);
|
||||
}
|
||||
UDCDBG(vhub, "vHub@%pR mapped @%p\n", res, vhub->regs);
|
||||
|
||||
platform_set_drvdata(pdev, vhub);
|
||||
|
||||
vhub->clk = devm_clk_get(&pdev->dev, NULL);
|
||||
if (IS_ERR(vhub->clk)) {
|
||||
rc = PTR_ERR(vhub->clk);
|
||||
goto err;
|
||||
}
|
||||
rc = clk_prepare_enable(vhub->clk);
|
||||
if (rc) {
|
||||
dev_err(&pdev->dev, "Error couldn't enable clock (%d)\n", rc);
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* Check if we need to limit the HW to USB1 */
|
||||
max_speed = usb_get_maximum_speed(&pdev->dev);
|
||||
if (max_speed != USB_SPEED_UNKNOWN && max_speed < USB_SPEED_HIGH)
|
||||
vhub->force_usb1 = true;
|
||||
|
||||
/* Mask & ack all interrupts before installing the handler */
|
||||
writel(0, vhub->regs + AST_VHUB_IER);
|
||||
writel(VHUB_IRQ_ACK_ALL, vhub->regs + AST_VHUB_ISR);
|
||||
|
||||
/* Find interrupt and install handler */
|
||||
vhub->irq = platform_get_irq(pdev, 0);
|
||||
if (vhub->irq < 0) {
|
||||
dev_err(&pdev->dev, "Failed to get interrupt\n");
|
||||
rc = vhub->irq;
|
||||
goto err;
|
||||
}
|
||||
rc = devm_request_irq(&pdev->dev, vhub->irq, ast_vhub_irq, 0,
|
||||
KBUILD_MODNAME, vhub);
|
||||
if (rc) {
|
||||
dev_err(&pdev->dev, "Failed to request interrupt\n");
|
||||
goto err;
|
||||
}
|
||||
|
||||
/*
|
||||
* Allocate DMA buffers for all EP0s in one chunk,
|
||||
* one per port and one for the vHub itself
|
||||
*/
|
||||
vhub->ep0_bufs = dma_alloc_coherent(&pdev->dev,
|
||||
AST_VHUB_EP0_MAX_PACKET *
|
||||
(AST_VHUB_NUM_PORTS + 1),
|
||||
&vhub->ep0_bufs_dma, GFP_KERNEL);
|
||||
if (!vhub->ep0_bufs) {
|
||||
dev_err(&pdev->dev, "Failed to allocate EP0 DMA buffers\n");
|
||||
rc = -ENOMEM;
|
||||
goto err;
|
||||
}
|
||||
UDCVDBG(vhub, "EP0 DMA buffers @%p (DMA 0x%08x)\n",
|
||||
vhub->ep0_bufs, (u32)vhub->ep0_bufs_dma);
|
||||
|
||||
/* Init vHub EP0 */
|
||||
ast_vhub_init_ep0(vhub, &vhub->ep0, NULL);
|
||||
|
||||
/* Init devices */
|
||||
for (i = 0; i < AST_VHUB_NUM_PORTS && rc == 0; i++)
|
||||
rc = ast_vhub_init_dev(vhub, i);
|
||||
if (rc)
|
||||
goto err;
|
||||
|
||||
/* Init hub emulation */
|
||||
ast_vhub_init_hub(vhub);
|
||||
|
||||
/* Initialize HW */
|
||||
ast_vhub_init_hw(vhub);
|
||||
|
||||
dev_info(&pdev->dev, "Initialized virtual hub in USB%d mode\n",
|
||||
vhub->force_usb1 ? 1 : 2);
|
||||
|
||||
return 0;
|
||||
err:
|
||||
ast_vhub_remove(pdev);
|
||||
return rc;
|
||||
}
|
||||
|
||||
static const struct of_device_id ast_vhub_dt_ids[] = {
|
||||
{
|
||||
.compatible = "aspeed,ast2400-usb-vhub",
|
||||
},
|
||||
{
|
||||
.compatible = "aspeed,ast2500-usb-vhub",
|
||||
},
|
||||
{ }
|
||||
};
|
||||
MODULE_DEVICE_TABLE(of, ast_vhub_dt_ids);
|
||||
|
||||
static struct platform_driver ast_vhub_driver = {
|
||||
.probe = ast_vhub_probe,
|
||||
.remove = ast_vhub_remove,
|
||||
.driver = {
|
||||
.name = KBUILD_MODNAME,
|
||||
.of_match_table = ast_vhub_dt_ids,
|
||||
},
|
||||
};
|
||||
module_platform_driver(ast_vhub_driver);
|
||||
|
||||
MODULE_DESCRIPTION("Aspeed vHub udc driver");
|
||||
MODULE_AUTHOR("Benjamin Herrenschmidt <benh@kernel.crashing.org>");
|
||||
MODULE_LICENSE("GPL");
|
589
drivers/usb/gadget/udc/aspeed-vhub/dev.c
Normal file
589
drivers/usb/gadget/udc/aspeed-vhub/dev.c
Normal file
|
@ -0,0 +1,589 @@
|
|||
// SPDX-License-Identifier: GPL-2.0+
|
||||
/*
|
||||
* aspeed-vhub -- Driver for Aspeed SoC "vHub" USB gadget
|
||||
*
|
||||
* dev.c - Individual device/gadget management (ie, a port = a gadget)
|
||||
*
|
||||
* Copyright 2017 IBM Corporation
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/platform_device.h>
|
||||
#include <linux/delay.h>
|
||||
#include <linux/ioport.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/errno.h>
|
||||
#include <linux/list.h>
|
||||
#include <linux/interrupt.h>
|
||||
#include <linux/proc_fs.h>
|
||||
#include <linux/prefetch.h>
|
||||
#include <linux/clk.h>
|
||||
#include <linux/usb/gadget.h>
|
||||
#include <linux/of.h>
|
||||
#include <linux/of_gpio.h>
|
||||
#include <linux/regmap.h>
|
||||
#include <linux/dma-mapping.h>
|
||||
#include <linux/usb.h>
|
||||
#include <linux/usb/hcd.h>
|
||||
|
||||
#include "vhub.h"
|
||||
|
||||
void ast_vhub_dev_irq(struct ast_vhub_dev *d)
|
||||
{
|
||||
u32 istat = readl(d->regs + AST_VHUB_DEV_ISR);
|
||||
|
||||
writel(istat, d->regs + AST_VHUB_DEV_ISR);
|
||||
|
||||
if (istat & VHUV_DEV_IRQ_EP0_IN_ACK_STALL)
|
||||
ast_vhub_ep0_handle_ack(&d->ep0, true);
|
||||
if (istat & VHUV_DEV_IRQ_EP0_OUT_ACK_STALL)
|
||||
ast_vhub_ep0_handle_ack(&d->ep0, false);
|
||||
if (istat & VHUV_DEV_IRQ_EP0_SETUP)
|
||||
ast_vhub_ep0_handle_setup(&d->ep0);
|
||||
}
|
||||
|
||||
static void ast_vhub_dev_enable(struct ast_vhub_dev *d)
|
||||
{
|
||||
u32 reg, hmsk;
|
||||
|
||||
if (d->enabled)
|
||||
return;
|
||||
|
||||
/* Enable device and its EP0 interrupts */
|
||||
reg = VHUB_DEV_EN_ENABLE_PORT |
|
||||
VHUB_DEV_EN_EP0_IN_ACK_IRQEN |
|
||||
VHUB_DEV_EN_EP0_OUT_ACK_IRQEN |
|
||||
VHUB_DEV_EN_EP0_SETUP_IRQEN;
|
||||
if (d->gadget.speed == USB_SPEED_HIGH)
|
||||
reg |= VHUB_DEV_EN_SPEED_SEL_HIGH;
|
||||
writel(reg, d->regs + AST_VHUB_DEV_EN_CTRL);
|
||||
|
||||
/* Enable device interrupt in the hub as well */
|
||||
hmsk = VHUB_IRQ_DEVICE1 << d->index;
|
||||
reg = readl(d->vhub->regs + AST_VHUB_IER);
|
||||
reg |= hmsk;
|
||||
writel(reg, d->vhub->regs + AST_VHUB_IER);
|
||||
|
||||
/* Set EP0 DMA buffer address */
|
||||
writel(d->ep0.buf_dma, d->regs + AST_VHUB_DEV_EP0_DATA);
|
||||
|
||||
d->enabled = true;
|
||||
}
|
||||
|
||||
static void ast_vhub_dev_disable(struct ast_vhub_dev *d)
|
||||
{
|
||||
u32 reg, hmsk;
|
||||
|
||||
if (!d->enabled)
|
||||
return;
|
||||
|
||||
/* Disable device interrupt in the hub */
|
||||
hmsk = VHUB_IRQ_DEVICE1 << d->index;
|
||||
reg = readl(d->vhub->regs + AST_VHUB_IER);
|
||||
reg &= ~hmsk;
|
||||
writel(reg, d->vhub->regs + AST_VHUB_IER);
|
||||
|
||||
/* Then disable device */
|
||||
writel(0, d->regs + AST_VHUB_DEV_EN_CTRL);
|
||||
d->gadget.speed = USB_SPEED_UNKNOWN;
|
||||
d->enabled = false;
|
||||
d->suspended = false;
|
||||
}
|
||||
|
||||
static int ast_vhub_dev_feature(struct ast_vhub_dev *d,
|
||||
u16 wIndex, u16 wValue,
|
||||
bool is_set)
|
||||
{
|
||||
DDBG(d, "%s_FEATURE(dev val=%02x)\n",
|
||||
is_set ? "SET" : "CLEAR", wValue);
|
||||
|
||||
if (wValue != USB_DEVICE_REMOTE_WAKEUP)
|
||||
return std_req_driver;
|
||||
|
||||
d->wakeup_en = is_set;
|
||||
|
||||
return std_req_complete;
|
||||
}
|
||||
|
||||
static int ast_vhub_ep_feature(struct ast_vhub_dev *d,
|
||||
u16 wIndex, u16 wValue, bool is_set)
|
||||
{
|
||||
struct ast_vhub_ep *ep;
|
||||
int ep_num;
|
||||
|
||||
ep_num = wIndex & USB_ENDPOINT_NUMBER_MASK;
|
||||
DDBG(d, "%s_FEATURE(ep%d val=%02x)\n",
|
||||
is_set ? "SET" : "CLEAR", ep_num, wValue);
|
||||
if (ep_num == 0)
|
||||
return std_req_complete;
|
||||
if (ep_num >= AST_VHUB_NUM_GEN_EPs || !d->epns[ep_num - 1])
|
||||
return std_req_stall;
|
||||
if (wValue != USB_ENDPOINT_HALT)
|
||||
return std_req_driver;
|
||||
|
||||
ep = d->epns[ep_num - 1];
|
||||
if (WARN_ON(!ep))
|
||||
return std_req_stall;
|
||||
|
||||
if (!ep->epn.enabled || !ep->ep.desc || ep->epn.is_iso ||
|
||||
ep->epn.is_in != !!(wIndex & USB_DIR_IN))
|
||||
return std_req_stall;
|
||||
|
||||
DDBG(d, "%s stall on EP %d\n",
|
||||
is_set ? "setting" : "clearing", ep_num);
|
||||
ep->epn.stalled = is_set;
|
||||
ast_vhub_update_epn_stall(ep);
|
||||
|
||||
return std_req_complete;
|
||||
}
|
||||
|
||||
static int ast_vhub_dev_status(struct ast_vhub_dev *d,
|
||||
u16 wIndex, u16 wValue)
|
||||
{
|
||||
u8 st0;
|
||||
|
||||
DDBG(d, "GET_STATUS(dev)\n");
|
||||
|
||||
st0 = d->gadget.is_selfpowered << USB_DEVICE_SELF_POWERED;
|
||||
if (d->wakeup_en)
|
||||
st0 |= 1 << USB_DEVICE_REMOTE_WAKEUP;
|
||||
|
||||
return ast_vhub_simple_reply(&d->ep0, st0, 0);
|
||||
}
|
||||
|
||||
static int ast_vhub_ep_status(struct ast_vhub_dev *d,
|
||||
u16 wIndex, u16 wValue)
|
||||
{
|
||||
int ep_num = wIndex & USB_ENDPOINT_NUMBER_MASK;
|
||||
struct ast_vhub_ep *ep;
|
||||
u8 st0 = 0;
|
||||
|
||||
DDBG(d, "GET_STATUS(ep%d)\n", ep_num);
|
||||
|
||||
if (ep_num >= AST_VHUB_NUM_GEN_EPs)
|
||||
return std_req_stall;
|
||||
if (ep_num != 0) {
|
||||
ep = d->epns[ep_num - 1];
|
||||
if (!ep)
|
||||
return std_req_stall;
|
||||
if (!ep->epn.enabled || !ep->ep.desc || ep->epn.is_iso ||
|
||||
ep->epn.is_in != !!(wIndex & USB_DIR_IN))
|
||||
return std_req_stall;
|
||||
if (ep->epn.stalled)
|
||||
st0 |= 1 << USB_ENDPOINT_HALT;
|
||||
}
|
||||
|
||||
return ast_vhub_simple_reply(&d->ep0, st0, 0);
|
||||
}
|
||||
|
||||
static void ast_vhub_dev_set_address(struct ast_vhub_dev *d, u8 addr)
|
||||
{
|
||||
u32 reg;
|
||||
|
||||
DDBG(d, "SET_ADDRESS: Got address %x\n", addr);
|
||||
|
||||
reg = readl(d->regs + AST_VHUB_DEV_EN_CTRL);
|
||||
reg &= ~VHUB_DEV_EN_ADDR_MASK;
|
||||
reg |= VHUB_DEV_EN_SET_ADDR(addr);
|
||||
writel(reg, d->regs + AST_VHUB_DEV_EN_CTRL);
|
||||
}
|
||||
|
||||
int ast_vhub_std_dev_request(struct ast_vhub_ep *ep,
|
||||
struct usb_ctrlrequest *crq)
|
||||
{
|
||||
struct ast_vhub_dev *d = ep->dev;
|
||||
u16 wValue, wIndex;
|
||||
|
||||
/* No driver, we shouldn't be enabled ... */
|
||||
if (!d->driver || !d->enabled || d->suspended) {
|
||||
EPDBG(ep,
|
||||
"Device is wrong state driver=%p enabled=%d"
|
||||
" suspended=%d\n",
|
||||
d->driver, d->enabled, d->suspended);
|
||||
return std_req_stall;
|
||||
}
|
||||
|
||||
/* First packet, grab speed */
|
||||
if (d->gadget.speed == USB_SPEED_UNKNOWN) {
|
||||
d->gadget.speed = ep->vhub->speed;
|
||||
if (d->gadget.speed > d->driver->max_speed)
|
||||
d->gadget.speed = d->driver->max_speed;
|
||||
DDBG(d, "fist packet, captured speed %d\n",
|
||||
d->gadget.speed);
|
||||
}
|
||||
|
||||
wValue = le16_to_cpu(crq->wValue);
|
||||
wIndex = le16_to_cpu(crq->wIndex);
|
||||
|
||||
switch ((crq->bRequestType << 8) | crq->bRequest) {
|
||||
/* SET_ADDRESS */
|
||||
case DeviceOutRequest | USB_REQ_SET_ADDRESS:
|
||||
ast_vhub_dev_set_address(d, wValue);
|
||||
return std_req_complete;
|
||||
|
||||
/* GET_STATUS */
|
||||
case DeviceRequest | USB_REQ_GET_STATUS:
|
||||
return ast_vhub_dev_status(d, wIndex, wValue);
|
||||
case InterfaceRequest | USB_REQ_GET_STATUS:
|
||||
return ast_vhub_simple_reply(ep, 0, 0);
|
||||
case EndpointRequest | USB_REQ_GET_STATUS:
|
||||
return ast_vhub_ep_status(d, wIndex, wValue);
|
||||
|
||||
/* SET/CLEAR_FEATURE */
|
||||
case DeviceOutRequest | USB_REQ_SET_FEATURE:
|
||||
return ast_vhub_dev_feature(d, wIndex, wValue, true);
|
||||
case DeviceOutRequest | USB_REQ_CLEAR_FEATURE:
|
||||
return ast_vhub_dev_feature(d, wIndex, wValue, false);
|
||||
case EndpointOutRequest | USB_REQ_SET_FEATURE:
|
||||
return ast_vhub_ep_feature(d, wIndex, wValue, true);
|
||||
case EndpointOutRequest | USB_REQ_CLEAR_FEATURE:
|
||||
return ast_vhub_ep_feature(d, wIndex, wValue, false);
|
||||
}
|
||||
return std_req_driver;
|
||||
}
|
||||
|
||||
static int ast_vhub_udc_wakeup(struct usb_gadget* gadget)
|
||||
{
|
||||
struct ast_vhub_dev *d = to_ast_dev(gadget);
|
||||
unsigned long flags;
|
||||
int rc = -EINVAL;
|
||||
|
||||
spin_lock_irqsave(&d->vhub->lock, flags);
|
||||
if (!d->wakeup_en)
|
||||
goto err;
|
||||
|
||||
DDBG(d, "Device initiated wakeup\n");
|
||||
|
||||
/* Wakeup the host */
|
||||
ast_vhub_hub_wake_all(d->vhub);
|
||||
rc = 0;
|
||||
err:
|
||||
spin_unlock_irqrestore(&d->vhub->lock, flags);
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int ast_vhub_udc_get_frame(struct usb_gadget* gadget)
|
||||
{
|
||||
struct ast_vhub_dev *d = to_ast_dev(gadget);
|
||||
|
||||
return (readl(d->vhub->regs + AST_VHUB_USBSTS) >> 16) & 0x7ff;
|
||||
}
|
||||
|
||||
static void ast_vhub_dev_nuke(struct ast_vhub_dev *d)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < AST_VHUB_NUM_GEN_EPs; i++) {
|
||||
if (!d->epns[i])
|
||||
continue;
|
||||
ast_vhub_nuke(d->epns[i], -ESHUTDOWN);
|
||||
}
|
||||
}
|
||||
|
||||
static int ast_vhub_udc_pullup(struct usb_gadget* gadget, int on)
|
||||
{
|
||||
struct ast_vhub_dev *d = to_ast_dev(gadget);
|
||||
unsigned long flags;
|
||||
|
||||
spin_lock_irqsave(&d->vhub->lock, flags);
|
||||
|
||||
DDBG(d, "pullup(%d)\n", on);
|
||||
|
||||
/* Mark disconnected in the hub */
|
||||
ast_vhub_device_connect(d->vhub, d->index, on);
|
||||
|
||||
/*
|
||||
* If enabled, nuke all requests if any (there shouldn't be)
|
||||
* and disable the port. This will clear the address too.
|
||||
*/
|
||||
if (d->enabled) {
|
||||
ast_vhub_dev_nuke(d);
|
||||
ast_vhub_dev_disable(d);
|
||||
}
|
||||
|
||||
spin_unlock_irqrestore(&d->vhub->lock, flags);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ast_vhub_udc_start(struct usb_gadget *gadget,
|
||||
struct usb_gadget_driver *driver)
|
||||
{
|
||||
struct ast_vhub_dev *d = to_ast_dev(gadget);
|
||||
unsigned long flags;
|
||||
|
||||
spin_lock_irqsave(&d->vhub->lock, flags);
|
||||
|
||||
DDBG(d, "start\n");
|
||||
|
||||
/* We don't do much more until the hub enables us */
|
||||
d->driver = driver;
|
||||
d->gadget.is_selfpowered = 1;
|
||||
|
||||
spin_unlock_irqrestore(&d->vhub->lock, flags);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct usb_ep *ast_vhub_udc_match_ep(struct usb_gadget *gadget,
|
||||
struct usb_endpoint_descriptor *desc,
|
||||
struct usb_ss_ep_comp_descriptor *ss)
|
||||
{
|
||||
struct ast_vhub_dev *d = to_ast_dev(gadget);
|
||||
struct ast_vhub_ep *ep;
|
||||
struct usb_ep *u_ep;
|
||||
unsigned int max, addr, i;
|
||||
|
||||
DDBG(d, "Match EP type %d\n", usb_endpoint_type(desc));
|
||||
|
||||
/*
|
||||
* First we need to look for an existing unclaimed EP as another
|
||||
* configuration may have already associated a bunch of EPs with
|
||||
* this gadget. This duplicates the code in usb_ep_autoconfig_ss()
|
||||
* unfortunately.
|
||||
*/
|
||||
list_for_each_entry(u_ep, &gadget->ep_list, ep_list) {
|
||||
if (usb_gadget_ep_match_desc(gadget, u_ep, desc, ss)) {
|
||||
DDBG(d, " -> using existing EP%d\n",
|
||||
to_ast_ep(u_ep)->d_idx);
|
||||
return u_ep;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* We didn't find one, we need to grab one from the pool.
|
||||
*
|
||||
* First let's do some sanity checking
|
||||
*/
|
||||
switch(usb_endpoint_type(desc)) {
|
||||
case USB_ENDPOINT_XFER_CONTROL:
|
||||
/* Only EP0 can be a control endpoint */
|
||||
return NULL;
|
||||
case USB_ENDPOINT_XFER_ISOC:
|
||||
/* ISO: limit 1023 bytes full speed, 1024 high/super speed */
|
||||
if (gadget_is_dualspeed(gadget))
|
||||
max = 1024;
|
||||
else
|
||||
max = 1023;
|
||||
break;
|
||||
case USB_ENDPOINT_XFER_BULK:
|
||||
if (gadget_is_dualspeed(gadget))
|
||||
max = 512;
|
||||
else
|
||||
max = 64;
|
||||
break;
|
||||
case USB_ENDPOINT_XFER_INT:
|
||||
if (gadget_is_dualspeed(gadget))
|
||||
max = 1024;
|
||||
else
|
||||
max = 64;
|
||||
break;
|
||||
}
|
||||
if (usb_endpoint_maxp(desc) > max)
|
||||
return NULL;
|
||||
|
||||
/*
|
||||
* Find a free EP address for that device. We can't
|
||||
* let the generic code assign these as it would
|
||||
* create overlapping numbers for IN and OUT which
|
||||
* we don't support, so also create a suitable name
|
||||
* that will allow the generic code to use our
|
||||
* assigned address.
|
||||
*/
|
||||
for (i = 0; i < AST_VHUB_NUM_GEN_EPs; i++)
|
||||
if (d->epns[i] == NULL)
|
||||
break;
|
||||
if (i >= AST_VHUB_NUM_GEN_EPs)
|
||||
return NULL;
|
||||
addr = i + 1;
|
||||
|
||||
/*
|
||||
* Now grab an EP from the shared pool and associate
|
||||
* it with our device
|
||||
*/
|
||||
ep = ast_vhub_alloc_epn(d, addr);
|
||||
if (!ep)
|
||||
return NULL;
|
||||
DDBG(d, "Allocated epn#%d for port EP%d\n",
|
||||
ep->epn.g_idx, addr);
|
||||
|
||||
return &ep->ep;
|
||||
}
|
||||
|
||||
static int ast_vhub_udc_stop(struct usb_gadget *gadget)
|
||||
{
|
||||
struct ast_vhub_dev *d = to_ast_dev(gadget);
|
||||
unsigned long flags;
|
||||
|
||||
spin_lock_irqsave(&d->vhub->lock, flags);
|
||||
|
||||
DDBG(d, "stop\n");
|
||||
|
||||
d->driver = NULL;
|
||||
d->gadget.speed = USB_SPEED_UNKNOWN;
|
||||
|
||||
ast_vhub_dev_nuke(d);
|
||||
|
||||
if (d->enabled)
|
||||
ast_vhub_dev_disable(d);
|
||||
|
||||
spin_unlock_irqrestore(&d->vhub->lock, flags);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct usb_gadget_ops ast_vhub_udc_ops = {
|
||||
.get_frame = ast_vhub_udc_get_frame,
|
||||
.wakeup = ast_vhub_udc_wakeup,
|
||||
.pullup = ast_vhub_udc_pullup,
|
||||
.udc_start = ast_vhub_udc_start,
|
||||
.udc_stop = ast_vhub_udc_stop,
|
||||
.match_ep = ast_vhub_udc_match_ep,
|
||||
};
|
||||
|
||||
void ast_vhub_dev_suspend(struct ast_vhub_dev *d)
|
||||
{
|
||||
d->suspended = true;
|
||||
if (d->driver) {
|
||||
spin_unlock(&d->vhub->lock);
|
||||
d->driver->suspend(&d->gadget);
|
||||
spin_lock(&d->vhub->lock);
|
||||
}
|
||||
}
|
||||
|
||||
void ast_vhub_dev_resume(struct ast_vhub_dev *d)
|
||||
{
|
||||
d->suspended = false;
|
||||
if (d->driver) {
|
||||
spin_unlock(&d->vhub->lock);
|
||||
d->driver->resume(&d->gadget);
|
||||
spin_lock(&d->vhub->lock);
|
||||
}
|
||||
}
|
||||
|
||||
void ast_vhub_dev_reset(struct ast_vhub_dev *d)
|
||||
{
|
||||
/*
|
||||
* If speed is not set, we enable the port. If it is,
|
||||
* send reset to the gadget and reset "speed".
|
||||
*
|
||||
* Speed is an indication that we have got the first
|
||||
* setup packet to the device.
|
||||
*/
|
||||
if (d->gadget.speed == USB_SPEED_UNKNOWN && !d->enabled) {
|
||||
DDBG(d, "Reset at unknown speed of disabled device, enabling...\n");
|
||||
ast_vhub_dev_enable(d);
|
||||
d->suspended = false;
|
||||
}
|
||||
if (d->gadget.speed != USB_SPEED_UNKNOWN && d->driver) {
|
||||
unsigned int i;
|
||||
|
||||
DDBG(d, "Reset at known speed of bound device, resetting...\n");
|
||||
spin_unlock(&d->vhub->lock);
|
||||
d->driver->reset(&d->gadget);
|
||||
spin_lock(&d->vhub->lock);
|
||||
|
||||
/*
|
||||
* Disable/re-enable HW, this will clear the address
|
||||
* and speed setting.
|
||||
*/
|
||||
ast_vhub_dev_disable(d);
|
||||
ast_vhub_dev_enable(d);
|
||||
|
||||
/* Clear stall on all EPs */
|
||||
for (i = 0; i < AST_VHUB_NUM_GEN_EPs; i++) {
|
||||
struct ast_vhub_ep *ep = d->epns[i];
|
||||
|
||||
if (ep && ep->epn.stalled) {
|
||||
ep->epn.stalled = false;
|
||||
ast_vhub_update_epn_stall(ep);
|
||||
}
|
||||
}
|
||||
|
||||
/* Additional cleanups */
|
||||
d->wakeup_en = false;
|
||||
d->suspended = false;
|
||||
}
|
||||
}
|
||||
|
||||
void ast_vhub_del_dev(struct ast_vhub_dev *d)
|
||||
{
|
||||
unsigned long flags;
|
||||
|
||||
spin_lock_irqsave(&d->vhub->lock, flags);
|
||||
if (!d->registered) {
|
||||
spin_unlock_irqrestore(&d->vhub->lock, flags);
|
||||
return;
|
||||
}
|
||||
d->registered = false;
|
||||
spin_unlock_irqrestore(&d->vhub->lock, flags);
|
||||
|
||||
usb_del_gadget_udc(&d->gadget);
|
||||
device_unregister(d->port_dev);
|
||||
}
|
||||
|
||||
static void ast_vhub_dev_release(struct device *dev)
|
||||
{
|
||||
kfree(dev);
|
||||
}
|
||||
|
||||
int ast_vhub_init_dev(struct ast_vhub *vhub, unsigned int idx)
|
||||
{
|
||||
struct ast_vhub_dev *d = &vhub->ports[idx].dev;
|
||||
struct device *parent = &vhub->pdev->dev;
|
||||
int rc;
|
||||
|
||||
d->vhub = vhub;
|
||||
d->index = idx;
|
||||
d->name = devm_kasprintf(parent, GFP_KERNEL, "port%d", idx+1);
|
||||
d->regs = vhub->regs + 0x100 + 0x10 * idx;
|
||||
|
||||
ast_vhub_init_ep0(vhub, &d->ep0, d);
|
||||
|
||||
/*
|
||||
* The UDC core really needs us to have separate and uniquely
|
||||
* named "parent" devices for each port so we create a sub device
|
||||
* here for that purpose
|
||||
*/
|
||||
d->port_dev = kzalloc(sizeof(struct device), GFP_KERNEL);
|
||||
if (!d->port_dev)
|
||||
return -ENOMEM;
|
||||
device_initialize(d->port_dev);
|
||||
d->port_dev->release = ast_vhub_dev_release;
|
||||
d->port_dev->parent = parent;
|
||||
dev_set_name(d->port_dev, "%s:p%d", dev_name(parent), idx + 1);
|
||||
rc = device_add(d->port_dev);
|
||||
if (rc)
|
||||
goto fail_add;
|
||||
|
||||
/* Populate gadget */
|
||||
INIT_LIST_HEAD(&d->gadget.ep_list);
|
||||
d->gadget.ops = &ast_vhub_udc_ops;
|
||||
d->gadget.ep0 = &d->ep0.ep;
|
||||
d->gadget.name = KBUILD_MODNAME;
|
||||
if (vhub->force_usb1)
|
||||
d->gadget.max_speed = USB_SPEED_FULL;
|
||||
else
|
||||
d->gadget.max_speed = USB_SPEED_HIGH;
|
||||
d->gadget.speed = USB_SPEED_UNKNOWN;
|
||||
d->gadget.dev.of_node = vhub->pdev->dev.of_node;
|
||||
|
||||
rc = usb_add_gadget_udc(d->port_dev, &d->gadget);
|
||||
if (rc != 0)
|
||||
goto fail_udc;
|
||||
d->registered = true;
|
||||
|
||||
return 0;
|
||||
fail_udc:
|
||||
device_del(d->port_dev);
|
||||
fail_add:
|
||||
put_device(d->port_dev);
|
||||
|
||||
return rc;
|
||||
}
|
486
drivers/usb/gadget/udc/aspeed-vhub/ep0.c
Normal file
486
drivers/usb/gadget/udc/aspeed-vhub/ep0.c
Normal file
|
@ -0,0 +1,486 @@
|
|||
// SPDX-License-Identifier: GPL-2.0+
|
||||
/*
|
||||
* aspeed-vhub -- Driver for Aspeed SoC "vHub" USB gadget
|
||||
*
|
||||
* ep0.c - Endpoint 0 handling
|
||||
*
|
||||
* Copyright 2017 IBM Corporation
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/platform_device.h>
|
||||
#include <linux/delay.h>
|
||||
#include <linux/ioport.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/errno.h>
|
||||
#include <linux/list.h>
|
||||
#include <linux/interrupt.h>
|
||||
#include <linux/proc_fs.h>
|
||||
#include <linux/prefetch.h>
|
||||
#include <linux/clk.h>
|
||||
#include <linux/usb/gadget.h>
|
||||
#include <linux/of.h>
|
||||
#include <linux/of_gpio.h>
|
||||
#include <linux/regmap.h>
|
||||
#include <linux/dma-mapping.h>
|
||||
|
||||
#include "vhub.h"
|
||||
|
||||
int ast_vhub_reply(struct ast_vhub_ep *ep, char *ptr, int len)
|
||||
{
|
||||
struct usb_request *req = &ep->ep0.req.req;
|
||||
int rc;
|
||||
|
||||
if (WARN_ON(ep->d_idx != 0))
|
||||
return std_req_stall;
|
||||
if (WARN_ON(!ep->ep0.dir_in))
|
||||
return std_req_stall;
|
||||
if (WARN_ON(len > AST_VHUB_EP0_MAX_PACKET))
|
||||
return std_req_stall;
|
||||
if (WARN_ON(req->status == -EINPROGRESS))
|
||||
return std_req_stall;
|
||||
|
||||
req->buf = ptr;
|
||||
req->length = len;
|
||||
req->complete = NULL;
|
||||
req->zero = true;
|
||||
|
||||
/*
|
||||
* Call internal queue directly after dropping the lock. This is
|
||||
* safe to do as the reply is always the last thing done when
|
||||
* processing a SETUP packet, usually as a tail call
|
||||
*/
|
||||
spin_unlock(&ep->vhub->lock);
|
||||
if (ep->ep.ops->queue(&ep->ep, req, GFP_ATOMIC))
|
||||
rc = std_req_stall;
|
||||
else
|
||||
rc = std_req_data;
|
||||
spin_lock(&ep->vhub->lock);
|
||||
return rc;
|
||||
}
|
||||
|
||||
int __ast_vhub_simple_reply(struct ast_vhub_ep *ep, int len, ...)
|
||||
{
|
||||
u8 *buffer = ep->buf;
|
||||
unsigned int i;
|
||||
va_list args;
|
||||
|
||||
va_start(args, len);
|
||||
|
||||
/* Copy data directly into EP buffer */
|
||||
for (i = 0; i < len; i++)
|
||||
buffer[i] = va_arg(args, int);
|
||||
va_end(args);
|
||||
|
||||
/* req->buf NULL means data is already there */
|
||||
return ast_vhub_reply(ep, NULL, len);
|
||||
}
|
||||
|
||||
void ast_vhub_ep0_handle_setup(struct ast_vhub_ep *ep)
|
||||
{
|
||||
struct usb_ctrlrequest crq;
|
||||
enum std_req_rc std_req_rc;
|
||||
int rc = -ENODEV;
|
||||
|
||||
if (WARN_ON(ep->d_idx != 0))
|
||||
return;
|
||||
|
||||
/*
|
||||
* Grab the setup packet from the chip and byteswap
|
||||
* interesting fields
|
||||
*/
|
||||
memcpy_fromio(&crq, ep->ep0.setup, sizeof(crq));
|
||||
|
||||
EPDBG(ep, "SETUP packet %02x/%02x/%04x/%04x/%04x [%s] st=%d\n",
|
||||
crq.bRequestType, crq.bRequest,
|
||||
le16_to_cpu(crq.wValue),
|
||||
le16_to_cpu(crq.wIndex),
|
||||
le16_to_cpu(crq.wLength),
|
||||
(crq.bRequestType & USB_DIR_IN) ? "in" : "out",
|
||||
ep->ep0.state);
|
||||
|
||||
/* Check our state, cancel pending requests if needed */
|
||||
if (ep->ep0.state != ep0_state_token) {
|
||||
EPDBG(ep, "wrong state\n");
|
||||
ast_vhub_nuke(ep, 0);
|
||||
goto stall;
|
||||
}
|
||||
|
||||
/* Calculate next state for EP0 */
|
||||
ep->ep0.state = ep0_state_data;
|
||||
ep->ep0.dir_in = !!(crq.bRequestType & USB_DIR_IN);
|
||||
|
||||
/* If this is the vHub, we handle requests differently */
|
||||
std_req_rc = std_req_driver;
|
||||
if (ep->dev == NULL) {
|
||||
if ((crq.bRequestType & USB_TYPE_MASK) == USB_TYPE_STANDARD)
|
||||
std_req_rc = ast_vhub_std_hub_request(ep, &crq);
|
||||
else if ((crq.bRequestType & USB_TYPE_MASK) == USB_TYPE_CLASS)
|
||||
std_req_rc = ast_vhub_class_hub_request(ep, &crq);
|
||||
else
|
||||
std_req_rc = std_req_stall;
|
||||
} else if ((crq.bRequestType & USB_TYPE_MASK) == USB_TYPE_STANDARD)
|
||||
std_req_rc = ast_vhub_std_dev_request(ep, &crq);
|
||||
|
||||
/* Act upon result */
|
||||
switch(std_req_rc) {
|
||||
case std_req_complete:
|
||||
goto complete;
|
||||
case std_req_stall:
|
||||
goto stall;
|
||||
case std_req_driver:
|
||||
break;
|
||||
case std_req_data:
|
||||
return;
|
||||
}
|
||||
|
||||
/* Pass request up to the gadget driver */
|
||||
if (WARN_ON(!ep->dev))
|
||||
goto stall;
|
||||
if (ep->dev->driver) {
|
||||
EPDBG(ep, "forwarding to gadget...\n");
|
||||
spin_unlock(&ep->vhub->lock);
|
||||
rc = ep->dev->driver->setup(&ep->dev->gadget, &crq);
|
||||
spin_lock(&ep->vhub->lock);
|
||||
EPDBG(ep, "driver returned %d\n", rc);
|
||||
} else {
|
||||
EPDBG(ep, "no gadget for request !\n");
|
||||
}
|
||||
if (rc >= 0)
|
||||
return;
|
||||
|
||||
stall:
|
||||
EPDBG(ep, "stalling\n");
|
||||
writel(VHUB_EP0_CTRL_STALL, ep->ep0.ctlstat);
|
||||
ep->ep0.state = ep0_state_status;
|
||||
ep->ep0.dir_in = false;
|
||||
return;
|
||||
|
||||
complete:
|
||||
EPVDBG(ep, "sending [in] status with no data\n");
|
||||
writel(VHUB_EP0_TX_BUFF_RDY, ep->ep0.ctlstat);
|
||||
ep->ep0.state = ep0_state_status;
|
||||
ep->ep0.dir_in = false;
|
||||
}
|
||||
|
||||
|
||||
static void ast_vhub_ep0_do_send(struct ast_vhub_ep *ep,
|
||||
struct ast_vhub_req *req)
|
||||
{
|
||||
unsigned int chunk;
|
||||
u32 reg;
|
||||
|
||||
/* If this is a 0-length request, it's the gadget trying to
|
||||
* send a status on our behalf. We take it from here.
|
||||
*/
|
||||
if (req->req.length == 0)
|
||||
req->last_desc = 1;
|
||||
|
||||
/* Are we done ? Complete request, otherwise wait for next interrupt */
|
||||
if (req->last_desc >= 0) {
|
||||
EPVDBG(ep, "complete send %d/%d\n",
|
||||
req->req.actual, req->req.length);
|
||||
ep->ep0.state = ep0_state_status;
|
||||
writel(VHUB_EP0_RX_BUFF_RDY, ep->ep0.ctlstat);
|
||||
ast_vhub_done(ep, req, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Next chunk cropped to max packet size. Also check if this
|
||||
* is the last packet
|
||||
*/
|
||||
chunk = req->req.length - req->req.actual;
|
||||
if (chunk > ep->ep.maxpacket)
|
||||
chunk = ep->ep.maxpacket;
|
||||
else if ((chunk < ep->ep.maxpacket) || !req->req.zero)
|
||||
req->last_desc = 1;
|
||||
|
||||
EPVDBG(ep, "send chunk=%d last=%d, req->act=%d mp=%d\n",
|
||||
chunk, req->last_desc, req->req.actual, ep->ep.maxpacket);
|
||||
|
||||
/*
|
||||
* Copy data if any (internal requests already have data
|
||||
* in the EP buffer)
|
||||
*/
|
||||
if (chunk && req->req.buf)
|
||||
memcpy(ep->buf, req->req.buf + req->req.actual, chunk);
|
||||
|
||||
/* Remember chunk size and trigger send */
|
||||
reg = VHUB_EP0_SET_TX_LEN(chunk);
|
||||
writel(reg, ep->ep0.ctlstat);
|
||||
writel(reg | VHUB_EP0_TX_BUFF_RDY, ep->ep0.ctlstat);
|
||||
req->req.actual += chunk;
|
||||
}
|
||||
|
||||
static void ast_vhub_ep0_rx_prime(struct ast_vhub_ep *ep)
|
||||
{
|
||||
EPVDBG(ep, "rx prime\n");
|
||||
|
||||
/* Prime endpoint for receiving data */
|
||||
writel(VHUB_EP0_RX_BUFF_RDY, ep->ep0.ctlstat + AST_VHUB_EP0_CTRL);
|
||||
}
|
||||
|
||||
static void ast_vhub_ep0_do_receive(struct ast_vhub_ep *ep, struct ast_vhub_req *req,
|
||||
unsigned int len)
|
||||
{
|
||||
unsigned int remain;
|
||||
int rc = 0;
|
||||
|
||||
/* We are receiving... grab request */
|
||||
remain = req->req.length - req->req.actual;
|
||||
|
||||
EPVDBG(ep, "receive got=%d remain=%d\n", len, remain);
|
||||
|
||||
/* Are we getting more than asked ? */
|
||||
if (len > remain) {
|
||||
EPDBG(ep, "receiving too much (ovf: %d) !\n",
|
||||
len - remain);
|
||||
len = remain;
|
||||
rc = -EOVERFLOW;
|
||||
}
|
||||
if (len && req->req.buf)
|
||||
memcpy(req->req.buf + req->req.actual, ep->buf, len);
|
||||
req->req.actual += len;
|
||||
|
||||
/* Done ? */
|
||||
if (len < ep->ep.maxpacket || len == remain) {
|
||||
ep->ep0.state = ep0_state_status;
|
||||
writel(VHUB_EP0_TX_BUFF_RDY, ep->ep0.ctlstat);
|
||||
ast_vhub_done(ep, req, rc);
|
||||
} else
|
||||
ast_vhub_ep0_rx_prime(ep);
|
||||
}
|
||||
|
||||
void ast_vhub_ep0_handle_ack(struct ast_vhub_ep *ep, bool in_ack)
|
||||
{
|
||||
struct ast_vhub_req *req;
|
||||
struct ast_vhub *vhub = ep->vhub;
|
||||
struct device *dev = &vhub->pdev->dev;
|
||||
bool stall = false;
|
||||
u32 stat;
|
||||
|
||||
/* Read EP0 status */
|
||||
stat = readl(ep->ep0.ctlstat);
|
||||
|
||||
/* Grab current request if any */
|
||||
req = list_first_entry_or_null(&ep->queue, struct ast_vhub_req, queue);
|
||||
|
||||
EPVDBG(ep, "ACK status=%08x,state=%d is_in=%d in_ack=%d req=%p\n",
|
||||
stat, ep->ep0.state, ep->ep0.dir_in, in_ack, req);
|
||||
|
||||
switch(ep->ep0.state) {
|
||||
case ep0_state_token:
|
||||
/* There should be no request queued in that state... */
|
||||
if (req) {
|
||||
dev_warn(dev, "request present while in TOKEN state\n");
|
||||
ast_vhub_nuke(ep, -EINVAL);
|
||||
}
|
||||
dev_warn(dev, "ack while in TOKEN state\n");
|
||||
stall = true;
|
||||
break;
|
||||
case ep0_state_data:
|
||||
/* Check the state bits corresponding to our direction */
|
||||
if ((ep->ep0.dir_in && (stat & VHUB_EP0_TX_BUFF_RDY)) ||
|
||||
(!ep->ep0.dir_in && (stat & VHUB_EP0_RX_BUFF_RDY)) ||
|
||||
(ep->ep0.dir_in != in_ack)) {
|
||||
dev_warn(dev, "irq state mismatch");
|
||||
stall = true;
|
||||
break;
|
||||
}
|
||||
/*
|
||||
* We are in data phase and there's no request, something is
|
||||
* wrong, stall
|
||||
*/
|
||||
if (!req) {
|
||||
dev_warn(dev, "data phase, no request\n");
|
||||
stall = true;
|
||||
break;
|
||||
}
|
||||
|
||||
/* We have a request, handle data transfers */
|
||||
if (ep->ep0.dir_in)
|
||||
ast_vhub_ep0_do_send(ep, req);
|
||||
else
|
||||
ast_vhub_ep0_do_receive(ep, req, VHUB_EP0_RX_LEN(stat));
|
||||
return;
|
||||
case ep0_state_status:
|
||||
/* Nuke stale requests */
|
||||
if (req) {
|
||||
dev_warn(dev, "request present while in STATUS state\n");
|
||||
ast_vhub_nuke(ep, -EINVAL);
|
||||
}
|
||||
|
||||
/*
|
||||
* If the status phase completes with the wrong ack, stall
|
||||
* the endpoint just in case, to abort whatever the host
|
||||
* was doing.
|
||||
*/
|
||||
if (ep->ep0.dir_in == in_ack) {
|
||||
dev_warn(dev, "status direction mismatch\n");
|
||||
stall = true;
|
||||
}
|
||||
}
|
||||
|
||||
/* Reset to token state */
|
||||
ep->ep0.state = ep0_state_token;
|
||||
if (stall)
|
||||
writel(VHUB_EP0_CTRL_STALL, ep->ep0.ctlstat);
|
||||
}
|
||||
|
||||
static int ast_vhub_ep0_queue(struct usb_ep* u_ep, struct usb_request *u_req,
|
||||
gfp_t gfp_flags)
|
||||
{
|
||||
struct ast_vhub_req *req = to_ast_req(u_req);
|
||||
struct ast_vhub_ep *ep = to_ast_ep(u_ep);
|
||||
struct ast_vhub *vhub = ep->vhub;
|
||||
struct device *dev = &vhub->pdev->dev;
|
||||
unsigned long flags;
|
||||
|
||||
/* Paranoid cheks */
|
||||
if (!u_req || (!u_req->complete && !req->internal)) {
|
||||
dev_warn(dev, "Bogus EP0 request ! u_req=%p\n", u_req);
|
||||
if (u_req) {
|
||||
dev_warn(dev, "complete=%p internal=%d\n",
|
||||
u_req->complete, req->internal);
|
||||
}
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* Not endpoint 0 ? */
|
||||
if (WARN_ON(ep->d_idx != 0))
|
||||
return -EINVAL;
|
||||
|
||||
/* Disabled device */
|
||||
if (ep->dev && (!ep->dev->enabled || ep->dev->suspended))
|
||||
return -ESHUTDOWN;
|
||||
|
||||
/* Data, no buffer and not internal ? */
|
||||
if (u_req->length && !u_req->buf && !req->internal) {
|
||||
dev_warn(dev, "Request with no buffer !\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
EPVDBG(ep, "enqueue req @%p\n", req);
|
||||
EPVDBG(ep, " l=%d zero=%d noshort=%d is_in=%d\n",
|
||||
u_req->length, u_req->zero,
|
||||
u_req->short_not_ok, ep->ep0.dir_in);
|
||||
|
||||
/* Initialize request progress fields */
|
||||
u_req->status = -EINPROGRESS;
|
||||
u_req->actual = 0;
|
||||
req->last_desc = -1;
|
||||
req->active = false;
|
||||
|
||||
spin_lock_irqsave(&vhub->lock, flags);
|
||||
|
||||
/* EP0 can only support a single request at a time */
|
||||
if (!list_empty(&ep->queue) || ep->ep0.state == ep0_state_token) {
|
||||
dev_warn(dev, "EP0: Request in wrong state\n");
|
||||
spin_unlock_irqrestore(&vhub->lock, flags);
|
||||
return -EBUSY;
|
||||
}
|
||||
|
||||
/* Add request to list and kick processing if empty */
|
||||
list_add_tail(&req->queue, &ep->queue);
|
||||
|
||||
if (ep->ep0.dir_in) {
|
||||
/* IN request, send data */
|
||||
ast_vhub_ep0_do_send(ep, req);
|
||||
} else if (u_req->length == 0) {
|
||||
/* 0-len request, send completion as rx */
|
||||
EPVDBG(ep, "0-length rx completion\n");
|
||||
ep->ep0.state = ep0_state_status;
|
||||
writel(VHUB_EP0_TX_BUFF_RDY, ep->ep0.ctlstat);
|
||||
ast_vhub_done(ep, req, 0);
|
||||
} else {
|
||||
/* OUT request, start receiver */
|
||||
ast_vhub_ep0_rx_prime(ep);
|
||||
}
|
||||
|
||||
spin_unlock_irqrestore(&vhub->lock, flags);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ast_vhub_ep0_dequeue(struct usb_ep* u_ep, struct usb_request *u_req)
|
||||
{
|
||||
struct ast_vhub_ep *ep = to_ast_ep(u_ep);
|
||||
struct ast_vhub *vhub = ep->vhub;
|
||||
struct ast_vhub_req *req;
|
||||
unsigned long flags;
|
||||
int rc = -EINVAL;
|
||||
|
||||
spin_lock_irqsave(&vhub->lock, flags);
|
||||
|
||||
/* Only one request can be in the queue */
|
||||
req = list_first_entry_or_null(&ep->queue, struct ast_vhub_req, queue);
|
||||
|
||||
/* Is it ours ? */
|
||||
if (req && u_req == &req->req) {
|
||||
EPVDBG(ep, "dequeue req @%p\n", req);
|
||||
|
||||
/*
|
||||
* We don't have to deal with "active" as all
|
||||
* DMAs go to the EP buffers, not the request.
|
||||
*/
|
||||
ast_vhub_done(ep, req, -ECONNRESET);
|
||||
|
||||
/* We do stall the EP to clean things up in HW */
|
||||
writel(VHUB_EP0_CTRL_STALL, ep->ep0.ctlstat);
|
||||
ep->ep0.state = ep0_state_status;
|
||||
ep->ep0.dir_in = false;
|
||||
rc = 0;
|
||||
}
|
||||
spin_unlock_irqrestore(&vhub->lock, flags);
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
static const struct usb_ep_ops ast_vhub_ep0_ops = {
|
||||
.queue = ast_vhub_ep0_queue,
|
||||
.dequeue = ast_vhub_ep0_dequeue,
|
||||
.alloc_request = ast_vhub_alloc_request,
|
||||
.free_request = ast_vhub_free_request,
|
||||
};
|
||||
|
||||
void ast_vhub_init_ep0(struct ast_vhub *vhub, struct ast_vhub_ep *ep,
|
||||
struct ast_vhub_dev *dev)
|
||||
{
|
||||
memset(ep, 0, sizeof(*ep));
|
||||
|
||||
INIT_LIST_HEAD(&ep->ep.ep_list);
|
||||
INIT_LIST_HEAD(&ep->queue);
|
||||
ep->ep.ops = &ast_vhub_ep0_ops;
|
||||
ep->ep.name = "ep0";
|
||||
ep->ep.caps.type_control = true;
|
||||
usb_ep_set_maxpacket_limit(&ep->ep, AST_VHUB_EP0_MAX_PACKET);
|
||||
ep->d_idx = 0;
|
||||
ep->dev = dev;
|
||||
ep->vhub = vhub;
|
||||
ep->ep0.state = ep0_state_token;
|
||||
INIT_LIST_HEAD(&ep->ep0.req.queue);
|
||||
ep->ep0.req.internal = true;
|
||||
|
||||
/* Small difference between vHub and devices */
|
||||
if (dev) {
|
||||
ep->ep0.ctlstat = dev->regs + AST_VHUB_DEV_EP0_CTRL;
|
||||
ep->ep0.setup = vhub->regs +
|
||||
AST_VHUB_SETUP0 + 8 * (dev->index + 1);
|
||||
ep->buf = vhub->ep0_bufs +
|
||||
AST_VHUB_EP0_MAX_PACKET * (dev->index + 1);
|
||||
ep->buf_dma = vhub->ep0_bufs_dma +
|
||||
AST_VHUB_EP0_MAX_PACKET * (dev->index + 1);
|
||||
} else {
|
||||
ep->ep0.ctlstat = vhub->regs + AST_VHUB_EP0_CTRL;
|
||||
ep->ep0.setup = vhub->regs + AST_VHUB_SETUP0;
|
||||
ep->buf = vhub->ep0_bufs;
|
||||
ep->buf_dma = vhub->ep0_bufs_dma;
|
||||
}
|
||||
}
|
843
drivers/usb/gadget/udc/aspeed-vhub/epn.c
Normal file
843
drivers/usb/gadget/udc/aspeed-vhub/epn.c
Normal file
|
@ -0,0 +1,843 @@
|
|||
// SPDX-License-Identifier: GPL-2.0+
|
||||
/*
|
||||
* aspeed-vhub -- Driver for Aspeed SoC "vHub" USB gadget
|
||||
*
|
||||
* epn.c - Generic endpoints management
|
||||
*
|
||||
* Copyright 2017 IBM Corporation
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/platform_device.h>
|
||||
#include <linux/delay.h>
|
||||
#include <linux/ioport.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/errno.h>
|
||||
#include <linux/list.h>
|
||||
#include <linux/interrupt.h>
|
||||
#include <linux/proc_fs.h>
|
||||
#include <linux/prefetch.h>
|
||||
#include <linux/clk.h>
|
||||
#include <linux/usb/gadget.h>
|
||||
#include <linux/of.h>
|
||||
#include <linux/of_gpio.h>
|
||||
#include <linux/regmap.h>
|
||||
#include <linux/dma-mapping.h>
|
||||
|
||||
#include "vhub.h"
|
||||
|
||||
#define EXTRA_CHECKS
|
||||
|
||||
#ifdef EXTRA_CHECKS
|
||||
#define CHECK(ep, expr, fmt...) \
|
||||
do { \
|
||||
if (!(expr)) EPDBG(ep, "CHECK:" fmt); \
|
||||
} while(0)
|
||||
#else
|
||||
#define CHECK(ep, expr, fmt...) do { } while(0)
|
||||
#endif
|
||||
|
||||
static void ast_vhub_epn_kick(struct ast_vhub_ep *ep, struct ast_vhub_req *req)
|
||||
{
|
||||
unsigned int act = req->req.actual;
|
||||
unsigned int len = req->req.length;
|
||||
unsigned int chunk;
|
||||
|
||||
/* There should be no DMA ongoing */
|
||||
WARN_ON(req->active);
|
||||
|
||||
/* Calculate next chunk size */
|
||||
chunk = len - act;
|
||||
if (chunk > ep->ep.maxpacket)
|
||||
chunk = ep->ep.maxpacket;
|
||||
else if ((chunk < ep->ep.maxpacket) || !req->req.zero)
|
||||
req->last_desc = 1;
|
||||
|
||||
EPVDBG(ep, "kick req %p act=%d/%d chunk=%d last=%d\n",
|
||||
req, act, len, chunk, req->last_desc);
|
||||
|
||||
/* If DMA unavailable, using staging EP buffer */
|
||||
if (!req->req.dma) {
|
||||
|
||||
/* For IN transfers, copy data over first */
|
||||
if (ep->epn.is_in)
|
||||
memcpy(ep->buf, req->req.buf + act, chunk);
|
||||
writel(ep->buf_dma, ep->epn.regs + AST_VHUB_EP_DESC_BASE);
|
||||
} else
|
||||
writel(req->req.dma + act, ep->epn.regs + AST_VHUB_EP_DESC_BASE);
|
||||
|
||||
/* Start DMA */
|
||||
req->active = true;
|
||||
writel(VHUB_EP_DMA_SET_TX_SIZE(chunk),
|
||||
ep->epn.regs + AST_VHUB_EP_DESC_STATUS);
|
||||
writel(VHUB_EP_DMA_SET_TX_SIZE(chunk) | VHUB_EP_DMA_SINGLE_KICK,
|
||||
ep->epn.regs + AST_VHUB_EP_DESC_STATUS);
|
||||
}
|
||||
|
||||
static void ast_vhub_epn_handle_ack(struct ast_vhub_ep *ep)
|
||||
{
|
||||
struct ast_vhub_req *req;
|
||||
unsigned int len;
|
||||
u32 stat;
|
||||
|
||||
/* Read EP status */
|
||||
stat = readl(ep->epn.regs + AST_VHUB_EP_DESC_STATUS);
|
||||
|
||||
/* Grab current request if any */
|
||||
req = list_first_entry_or_null(&ep->queue, struct ast_vhub_req, queue);
|
||||
|
||||
EPVDBG(ep, "ACK status=%08x is_in=%d, req=%p (active=%d)\n",
|
||||
stat, ep->epn.is_in, req, req ? req->active : 0);
|
||||
|
||||
/* In absence of a request, bail out, must have been dequeued */
|
||||
if (!req)
|
||||
return;
|
||||
|
||||
/*
|
||||
* Request not active, move on to processing queue, active request
|
||||
* was probably dequeued
|
||||
*/
|
||||
if (!req->active)
|
||||
goto next_chunk;
|
||||
|
||||
/* Check if HW has moved on */
|
||||
if (VHUB_EP_DMA_RPTR(stat) != 0) {
|
||||
EPDBG(ep, "DMA read pointer not 0 !\n");
|
||||
return;
|
||||
}
|
||||
|
||||
/* No current DMA ongoing */
|
||||
req->active = false;
|
||||
|
||||
/* Grab lenght out of HW */
|
||||
len = VHUB_EP_DMA_TX_SIZE(stat);
|
||||
|
||||
/* If not using DMA, copy data out if needed */
|
||||
if (!req->req.dma && !ep->epn.is_in && len)
|
||||
memcpy(req->req.buf + req->req.actual, ep->buf, len);
|
||||
|
||||
/* Adjust size */
|
||||
req->req.actual += len;
|
||||
|
||||
/* Check for short packet */
|
||||
if (len < ep->ep.maxpacket)
|
||||
req->last_desc = 1;
|
||||
|
||||
/* That's it ? complete the request and pick a new one */
|
||||
if (req->last_desc >= 0) {
|
||||
ast_vhub_done(ep, req, 0);
|
||||
req = list_first_entry_or_null(&ep->queue, struct ast_vhub_req,
|
||||
queue);
|
||||
|
||||
/*
|
||||
* Due to lock dropping inside "done" the next request could
|
||||
* already be active, so check for that and bail if needed.
|
||||
*/
|
||||
if (!req || req->active)
|
||||
return;
|
||||
}
|
||||
|
||||
next_chunk:
|
||||
ast_vhub_epn_kick(ep, req);
|
||||
}
|
||||
|
||||
static inline unsigned int ast_vhub_count_free_descs(struct ast_vhub_ep *ep)
|
||||
{
|
||||
/*
|
||||
* d_next == d_last means descriptor list empty to HW,
|
||||
* thus we can only have AST_VHUB_DESCS_COUNT-1 descriptors
|
||||
* in the list
|
||||
*/
|
||||
return (ep->epn.d_last + AST_VHUB_DESCS_COUNT - ep->epn.d_next - 1) &
|
||||
(AST_VHUB_DESCS_COUNT - 1);
|
||||
}
|
||||
|
||||
static void ast_vhub_epn_kick_desc(struct ast_vhub_ep *ep,
|
||||
struct ast_vhub_req *req)
|
||||
{
|
||||
unsigned int act = req->act_count;
|
||||
unsigned int len = req->req.length;
|
||||
unsigned int chunk;
|
||||
|
||||
/* Mark request active if not already */
|
||||
req->active = true;
|
||||
|
||||
/* If the request was already completely written, do nothing */
|
||||
if (req->last_desc >= 0)
|
||||
return;
|
||||
|
||||
EPVDBG(ep, "kick act=%d/%d chunk_max=%d free_descs=%d\n",
|
||||
act, len, ep->epn.chunk_max, ast_vhub_count_free_descs(ep));
|
||||
|
||||
/* While we can create descriptors */
|
||||
while (ast_vhub_count_free_descs(ep) && req->last_desc < 0) {
|
||||
struct ast_vhub_desc *desc;
|
||||
unsigned int d_num;
|
||||
|
||||
/* Grab next free descriptor */
|
||||
d_num = ep->epn.d_next;
|
||||
desc = &ep->epn.descs[d_num];
|
||||
ep->epn.d_next = (d_num + 1) & (AST_VHUB_DESCS_COUNT - 1);
|
||||
|
||||
/* Calculate next chunk size */
|
||||
chunk = len - act;
|
||||
if (chunk <= ep->epn.chunk_max) {
|
||||
/*
|
||||
* Is this the last packet ? Because of having up to 8
|
||||
* packets in a descriptor we can't just compare "chunk"
|
||||
* with ep.maxpacket. We have to see if it's a multiple
|
||||
* of it to know if we have to send a zero packet.
|
||||
* Sadly that involves a modulo which is a bit expensive
|
||||
* but probably still better than not doing it.
|
||||
*/
|
||||
if (!chunk || !req->req.zero || (chunk % ep->ep.maxpacket) != 0)
|
||||
req->last_desc = d_num;
|
||||
} else {
|
||||
chunk = ep->epn.chunk_max;
|
||||
}
|
||||
|
||||
EPVDBG(ep, " chunk: act=%d/%d chunk=%d last=%d desc=%d free=%d\n",
|
||||
act, len, chunk, req->last_desc, d_num,
|
||||
ast_vhub_count_free_descs(ep));
|
||||
|
||||
/* Populate descriptor */
|
||||
desc->w0 = cpu_to_le32(req->req.dma + act);
|
||||
|
||||
/* Interrupt if end of request or no more descriptors */
|
||||
|
||||
/*
|
||||
* TODO: Be smarter about it, if we don't have enough
|
||||
* descriptors request an interrupt before queue empty
|
||||
* or so in order to be able to populate more before
|
||||
* the HW runs out. This isn't a problem at the moment
|
||||
* as we use 256 descriptors and only put at most one
|
||||
* request in the ring.
|
||||
*/
|
||||
desc->w1 = cpu_to_le32(VHUB_DSC1_IN_SET_LEN(chunk));
|
||||
if (req->last_desc >= 0 || !ast_vhub_count_free_descs(ep))
|
||||
desc->w1 |= cpu_to_le32(VHUB_DSC1_IN_INTERRUPT);
|
||||
|
||||
/* Account packet */
|
||||
req->act_count = act = act + chunk;
|
||||
}
|
||||
|
||||
/* Tell HW about new descriptors */
|
||||
writel(VHUB_EP_DMA_SET_CPU_WPTR(ep->epn.d_next),
|
||||
ep->epn.regs + AST_VHUB_EP_DESC_STATUS);
|
||||
|
||||
EPVDBG(ep, "HW kicked, d_next=%d dstat=%08x\n",
|
||||
ep->epn.d_next, readl(ep->epn.regs + AST_VHUB_EP_DESC_STATUS));
|
||||
}
|
||||
|
||||
static void ast_vhub_epn_handle_ack_desc(struct ast_vhub_ep *ep)
|
||||
{
|
||||
struct ast_vhub_req *req;
|
||||
unsigned int len, d_last;
|
||||
u32 stat, stat1;
|
||||
|
||||
/* Read EP status, workaround HW race */
|
||||
do {
|
||||
stat = readl(ep->epn.regs + AST_VHUB_EP_DESC_STATUS);
|
||||
stat1 = readl(ep->epn.regs + AST_VHUB_EP_DESC_STATUS);
|
||||
} while(stat != stat1);
|
||||
|
||||
/* Extract RPTR */
|
||||
d_last = VHUB_EP_DMA_RPTR(stat);
|
||||
|
||||
/* Grab current request if any */
|
||||
req = list_first_entry_or_null(&ep->queue, struct ast_vhub_req, queue);
|
||||
|
||||
EPVDBG(ep, "ACK status=%08x is_in=%d ep->d_last=%d..%d\n",
|
||||
stat, ep->epn.is_in, ep->epn.d_last, d_last);
|
||||
|
||||
/* Check all completed descriptors */
|
||||
while (ep->epn.d_last != d_last) {
|
||||
struct ast_vhub_desc *desc;
|
||||
unsigned int d_num;
|
||||
bool is_last_desc;
|
||||
|
||||
/* Grab next completed descriptor */
|
||||
d_num = ep->epn.d_last;
|
||||
desc = &ep->epn.descs[d_num];
|
||||
ep->epn.d_last = (d_num + 1) & (AST_VHUB_DESCS_COUNT - 1);
|
||||
|
||||
/* Grab len out of descriptor */
|
||||
len = VHUB_DSC1_IN_LEN(le32_to_cpu(desc->w1));
|
||||
|
||||
EPVDBG(ep, " desc %d len=%d req=%p (act=%d)\n",
|
||||
d_num, len, req, req ? req->active : 0);
|
||||
|
||||
/* If no active request pending, move on */
|
||||
if (!req || !req->active)
|
||||
continue;
|
||||
|
||||
/* Adjust size */
|
||||
req->req.actual += len;
|
||||
|
||||
/* Is that the last chunk ? */
|
||||
is_last_desc = req->last_desc == d_num;
|
||||
CHECK(ep, is_last_desc == (len < ep->ep.maxpacket ||
|
||||
(req->req.actual >= req->req.length &&
|
||||
!req->req.zero)),
|
||||
"Last packet discrepancy: last_desc=%d len=%d r.act=%d "
|
||||
"r.len=%d r.zero=%d mp=%d\n",
|
||||
is_last_desc, len, req->req.actual, req->req.length,
|
||||
req->req.zero, ep->ep.maxpacket);
|
||||
|
||||
if (is_last_desc) {
|
||||
/*
|
||||
* Because we can only have one request at a time
|
||||
* in our descriptor list in this implementation,
|
||||
* d_last and ep->d_last should now be equal
|
||||
*/
|
||||
CHECK(ep, d_last == ep->epn.d_last,
|
||||
"DMA read ptr mismatch %d vs %d\n",
|
||||
d_last, ep->epn.d_last);
|
||||
|
||||
/* Note: done will drop and re-acquire the lock */
|
||||
ast_vhub_done(ep, req, 0);
|
||||
req = list_first_entry_or_null(&ep->queue,
|
||||
struct ast_vhub_req,
|
||||
queue);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* More work ? */
|
||||
if (req)
|
||||
ast_vhub_epn_kick_desc(ep, req);
|
||||
}
|
||||
|
||||
void ast_vhub_epn_ack_irq(struct ast_vhub_ep *ep)
|
||||
{
|
||||
if (ep->epn.desc_mode)
|
||||
ast_vhub_epn_handle_ack_desc(ep);
|
||||
else
|
||||
ast_vhub_epn_handle_ack(ep);
|
||||
}
|
||||
|
||||
static int ast_vhub_epn_queue(struct usb_ep* u_ep, struct usb_request *u_req,
|
||||
gfp_t gfp_flags)
|
||||
{
|
||||
struct ast_vhub_req *req = to_ast_req(u_req);
|
||||
struct ast_vhub_ep *ep = to_ast_ep(u_ep);
|
||||
struct ast_vhub *vhub = ep->vhub;
|
||||
unsigned long flags;
|
||||
bool empty;
|
||||
int rc;
|
||||
|
||||
/* Paranoid checks */
|
||||
if (!u_req || !u_req->complete || !u_req->buf) {
|
||||
dev_warn(&vhub->pdev->dev, "Bogus EPn request ! u_req=%p\n", u_req);
|
||||
if (u_req) {
|
||||
dev_warn(&vhub->pdev->dev, "complete=%p internal=%d\n",
|
||||
u_req->complete, req->internal);
|
||||
}
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* Endpoint enabled ? */
|
||||
if (!ep->epn.enabled || !u_ep->desc || !ep->dev || !ep->d_idx ||
|
||||
!ep->dev->enabled || ep->dev->suspended) {
|
||||
EPDBG(ep,"Enqueing request on wrong or disabled EP\n");
|
||||
return -ESHUTDOWN;
|
||||
}
|
||||
|
||||
/* Map request for DMA if possible. For now, the rule for DMA is
|
||||
* that:
|
||||
*
|
||||
* * For single stage mode (no descriptors):
|
||||
*
|
||||
* - The buffer is aligned to a 8 bytes boundary (HW requirement)
|
||||
* - For a OUT endpoint, the request size is a multiple of the EP
|
||||
* packet size (otherwise the controller will DMA past the end
|
||||
* of the buffer if the host is sending a too long packet).
|
||||
*
|
||||
* * For descriptor mode (tx only for now), always.
|
||||
*
|
||||
* We could relax the latter by making the decision to use the bounce
|
||||
* buffer based on the size of a given *segment* of the request rather
|
||||
* than the whole request.
|
||||
*/
|
||||
if (ep->epn.desc_mode ||
|
||||
((((unsigned long)u_req->buf & 7) == 0) &&
|
||||
(ep->epn.is_in || !(u_req->length & (u_ep->maxpacket - 1))))) {
|
||||
rc = usb_gadget_map_request(&ep->dev->gadget, u_req,
|
||||
ep->epn.is_in);
|
||||
if (rc) {
|
||||
dev_warn(&vhub->pdev->dev,
|
||||
"Request mapping failure %d\n", rc);
|
||||
return rc;
|
||||
}
|
||||
} else
|
||||
u_req->dma = 0;
|
||||
|
||||
EPVDBG(ep, "enqueue req @%p\n", req);
|
||||
EPVDBG(ep, " l=%d dma=0x%x zero=%d noshort=%d noirq=%d is_in=%d\n",
|
||||
u_req->length, (u32)u_req->dma, u_req->zero,
|
||||
u_req->short_not_ok, u_req->no_interrupt,
|
||||
ep->epn.is_in);
|
||||
|
||||
/* Initialize request progress fields */
|
||||
u_req->status = -EINPROGRESS;
|
||||
u_req->actual = 0;
|
||||
req->act_count = 0;
|
||||
req->active = false;
|
||||
req->last_desc = -1;
|
||||
spin_lock_irqsave(&vhub->lock, flags);
|
||||
empty = list_empty(&ep->queue);
|
||||
|
||||
/* Add request to list and kick processing if empty */
|
||||
list_add_tail(&req->queue, &ep->queue);
|
||||
if (empty) {
|
||||
if (ep->epn.desc_mode)
|
||||
ast_vhub_epn_kick_desc(ep, req);
|
||||
else
|
||||
ast_vhub_epn_kick(ep, req);
|
||||
}
|
||||
spin_unlock_irqrestore(&vhub->lock, flags);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void ast_vhub_stop_active_req(struct ast_vhub_ep *ep,
|
||||
bool restart_ep)
|
||||
{
|
||||
u32 state, reg, loops;
|
||||
|
||||
/* Stop DMA activity */
|
||||
writel(0, ep->epn.regs + AST_VHUB_EP_DMA_CTLSTAT);
|
||||
|
||||
/* Wait for it to complete */
|
||||
for (loops = 0; loops < 1000; loops++) {
|
||||
state = readl(ep->epn.regs + AST_VHUB_EP_DMA_CTLSTAT);
|
||||
state = VHUB_EP_DMA_PROC_STATUS(state);
|
||||
if (state == EP_DMA_PROC_RX_IDLE ||
|
||||
state == EP_DMA_PROC_TX_IDLE)
|
||||
break;
|
||||
udelay(1);
|
||||
}
|
||||
if (loops >= 1000)
|
||||
dev_warn(&ep->vhub->pdev->dev, "Timeout waiting for DMA\n");
|
||||
|
||||
/* If we don't have to restart the endpoint, that's it */
|
||||
if (!restart_ep)
|
||||
return;
|
||||
|
||||
/* Restart the endpoint */
|
||||
if (ep->epn.desc_mode) {
|
||||
/*
|
||||
* Take out descriptors by resetting the DMA read
|
||||
* pointer to be equal to the CPU write pointer.
|
||||
*
|
||||
* Note: If we ever support creating descriptors for
|
||||
* requests that aren't the head of the queue, we
|
||||
* may have to do something more complex here,
|
||||
* especially if the request being taken out is
|
||||
* not the current head descriptors.
|
||||
*/
|
||||
reg = VHUB_EP_DMA_SET_RPTR(ep->epn.d_next) |
|
||||
VHUB_EP_DMA_SET_CPU_WPTR(ep->epn.d_next);
|
||||
writel(reg, ep->epn.regs + AST_VHUB_EP_DESC_STATUS);
|
||||
|
||||
/* Then turn it back on */
|
||||
writel(ep->epn.dma_conf,
|
||||
ep->epn.regs + AST_VHUB_EP_DMA_CTLSTAT);
|
||||
} else {
|
||||
/* Single mode: just turn it back on */
|
||||
writel(ep->epn.dma_conf,
|
||||
ep->epn.regs + AST_VHUB_EP_DMA_CTLSTAT);
|
||||
}
|
||||
}
|
||||
|
||||
static int ast_vhub_epn_dequeue(struct usb_ep* u_ep, struct usb_request *u_req)
|
||||
{
|
||||
struct ast_vhub_ep *ep = to_ast_ep(u_ep);
|
||||
struct ast_vhub *vhub = ep->vhub;
|
||||
struct ast_vhub_req *req;
|
||||
unsigned long flags;
|
||||
int rc = -EINVAL;
|
||||
|
||||
spin_lock_irqsave(&vhub->lock, flags);
|
||||
|
||||
/* Make sure it's actually queued on this endpoint */
|
||||
list_for_each_entry (req, &ep->queue, queue) {
|
||||
if (&req->req == u_req)
|
||||
break;
|
||||
}
|
||||
|
||||
if (&req->req == u_req) {
|
||||
EPVDBG(ep, "dequeue req @%p active=%d\n",
|
||||
req, req->active);
|
||||
if (req->active)
|
||||
ast_vhub_stop_active_req(ep, true);
|
||||
ast_vhub_done(ep, req, -ECONNRESET);
|
||||
rc = 0;
|
||||
}
|
||||
|
||||
spin_unlock_irqrestore(&vhub->lock, flags);
|
||||
return rc;
|
||||
}
|
||||
|
||||
void ast_vhub_update_epn_stall(struct ast_vhub_ep *ep)
|
||||
{
|
||||
u32 reg;
|
||||
|
||||
if (WARN_ON(ep->d_idx == 0))
|
||||
return;
|
||||
reg = readl(ep->epn.regs + AST_VHUB_EP_CONFIG);
|
||||
if (ep->epn.stalled || ep->epn.wedged)
|
||||
reg |= VHUB_EP_CFG_STALL_CTRL;
|
||||
else
|
||||
reg &= ~VHUB_EP_CFG_STALL_CTRL;
|
||||
writel(reg, ep->epn.regs + AST_VHUB_EP_CONFIG);
|
||||
|
||||
if (!ep->epn.stalled && !ep->epn.wedged)
|
||||
writel(VHUB_EP_TOGGLE_SET_EPNUM(ep->epn.g_idx),
|
||||
ep->vhub->regs + AST_VHUB_EP_TOGGLE);
|
||||
}
|
||||
|
||||
static int ast_vhub_set_halt_and_wedge(struct usb_ep* u_ep, bool halt,
|
||||
bool wedge)
|
||||
{
|
||||
struct ast_vhub_ep *ep = to_ast_ep(u_ep);
|
||||
struct ast_vhub *vhub = ep->vhub;
|
||||
unsigned long flags;
|
||||
|
||||
EPDBG(ep, "Set halt (%d) & wedge (%d)\n", halt, wedge);
|
||||
|
||||
if (!u_ep || !u_ep->desc)
|
||||
return -EINVAL;
|
||||
if (ep->d_idx == 0)
|
||||
return 0;
|
||||
if (ep->epn.is_iso)
|
||||
return -EOPNOTSUPP;
|
||||
|
||||
spin_lock_irqsave(&vhub->lock, flags);
|
||||
|
||||
/* Fail with still-busy IN endpoints */
|
||||
if (halt && ep->epn.is_in && !list_empty(&ep->queue)) {
|
||||
spin_unlock_irqrestore(&vhub->lock, flags);
|
||||
return -EAGAIN;
|
||||
}
|
||||
ep->epn.stalled = halt;
|
||||
ep->epn.wedged = wedge;
|
||||
ast_vhub_update_epn_stall(ep);
|
||||
|
||||
spin_unlock_irqrestore(&vhub->lock, flags);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ast_vhub_epn_set_halt(struct usb_ep *u_ep, int value)
|
||||
{
|
||||
return ast_vhub_set_halt_and_wedge(u_ep, value != 0, false);
|
||||
}
|
||||
|
||||
static int ast_vhub_epn_set_wedge(struct usb_ep *u_ep)
|
||||
{
|
||||
return ast_vhub_set_halt_and_wedge(u_ep, true, true);
|
||||
}
|
||||
|
||||
static int ast_vhub_epn_disable(struct usb_ep* u_ep)
|
||||
{
|
||||
struct ast_vhub_ep *ep = to_ast_ep(u_ep);
|
||||
struct ast_vhub *vhub = ep->vhub;
|
||||
unsigned long flags;
|
||||
u32 imask, ep_ier;
|
||||
|
||||
EPDBG(ep, "Disabling !\n");
|
||||
|
||||
spin_lock_irqsave(&vhub->lock, flags);
|
||||
|
||||
ep->epn.enabled = false;
|
||||
|
||||
/* Stop active DMA if any */
|
||||
ast_vhub_stop_active_req(ep, false);
|
||||
|
||||
/* Disable endpoint */
|
||||
writel(0, ep->epn.regs + AST_VHUB_EP_CONFIG);
|
||||
|
||||
/* Disable ACK interrupt */
|
||||
imask = VHUB_EP_IRQ(ep->epn.g_idx);
|
||||
ep_ier = readl(vhub->regs + AST_VHUB_EP_ACK_IER);
|
||||
ep_ier &= ~imask;
|
||||
writel(ep_ier, vhub->regs + AST_VHUB_EP_ACK_IER);
|
||||
writel(imask, vhub->regs + AST_VHUB_EP_ACK_ISR);
|
||||
|
||||
/* Nuke all pending requests */
|
||||
ast_vhub_nuke(ep, -ESHUTDOWN);
|
||||
|
||||
/* No more descriptor associated with request */
|
||||
ep->ep.desc = NULL;
|
||||
|
||||
spin_unlock_irqrestore(&vhub->lock, flags);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ast_vhub_epn_enable(struct usb_ep* u_ep,
|
||||
const struct usb_endpoint_descriptor *desc)
|
||||
{
|
||||
static const char *ep_type_string[] __maybe_unused = { "ctrl",
|
||||
"isoc",
|
||||
"bulk",
|
||||
"intr" };
|
||||
struct ast_vhub_ep *ep = to_ast_ep(u_ep);
|
||||
struct ast_vhub_dev *dev;
|
||||
struct ast_vhub *vhub;
|
||||
u16 maxpacket, type;
|
||||
unsigned long flags;
|
||||
u32 ep_conf, ep_ier, imask;
|
||||
|
||||
/* Check arguments */
|
||||
if (!u_ep || !desc)
|
||||
return -EINVAL;
|
||||
|
||||
maxpacket = usb_endpoint_maxp(desc);
|
||||
if (!ep->d_idx || !ep->dev ||
|
||||
desc->bDescriptorType != USB_DT_ENDPOINT ||
|
||||
maxpacket == 0 || maxpacket > ep->ep.maxpacket) {
|
||||
EPDBG(ep, "Invalid EP enable,d_idx=%d,dev=%p,type=%d,mp=%d/%d\n",
|
||||
ep->d_idx, ep->dev, desc->bDescriptorType,
|
||||
maxpacket, ep->ep.maxpacket);
|
||||
return -EINVAL;
|
||||
}
|
||||
if (ep->d_idx != usb_endpoint_num(desc)) {
|
||||
EPDBG(ep, "EP number mismatch !\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (ep->epn.enabled) {
|
||||
EPDBG(ep, "Already enabled\n");
|
||||
return -EBUSY;
|
||||
}
|
||||
dev = ep->dev;
|
||||
vhub = ep->vhub;
|
||||
|
||||
/* Check device state */
|
||||
if (!dev->driver) {
|
||||
EPDBG(ep, "Bogus device state: driver=%p speed=%d\n",
|
||||
dev->driver, dev->gadget.speed);
|
||||
return -ESHUTDOWN;
|
||||
}
|
||||
|
||||
/* Grab some info from the descriptor */
|
||||
ep->epn.is_in = usb_endpoint_dir_in(desc);
|
||||
ep->ep.maxpacket = maxpacket;
|
||||
type = usb_endpoint_type(desc);
|
||||
ep->epn.d_next = ep->epn.d_last = 0;
|
||||
ep->epn.is_iso = false;
|
||||
ep->epn.stalled = false;
|
||||
ep->epn.wedged = false;
|
||||
|
||||
EPDBG(ep, "Enabling [%s] %s num %d maxpacket=%d\n",
|
||||
ep->epn.is_in ? "in" : "out", ep_type_string[type],
|
||||
usb_endpoint_num(desc), maxpacket);
|
||||
|
||||
/* Can we use DMA descriptor mode ? */
|
||||
ep->epn.desc_mode = ep->epn.descs && ep->epn.is_in;
|
||||
if (ep->epn.desc_mode)
|
||||
memset(ep->epn.descs, 0, 8 * AST_VHUB_DESCS_COUNT);
|
||||
|
||||
/*
|
||||
* Large send function can send up to 8 packets from
|
||||
* one descriptor with a limit of 4095 bytes.
|
||||
*/
|
||||
ep->epn.chunk_max = ep->ep.maxpacket;
|
||||
if (ep->epn.is_in) {
|
||||
ep->epn.chunk_max <<= 3;
|
||||
while (ep->epn.chunk_max > 4095)
|
||||
ep->epn.chunk_max -= ep->ep.maxpacket;
|
||||
}
|
||||
|
||||
switch(type) {
|
||||
case USB_ENDPOINT_XFER_CONTROL:
|
||||
EPDBG(ep, "Only one control endpoint\n");
|
||||
return -EINVAL;
|
||||
case USB_ENDPOINT_XFER_INT:
|
||||
ep_conf = VHUB_EP_CFG_SET_TYPE(EP_TYPE_INT);
|
||||
break;
|
||||
case USB_ENDPOINT_XFER_BULK:
|
||||
ep_conf = VHUB_EP_CFG_SET_TYPE(EP_TYPE_BULK);
|
||||
break;
|
||||
case USB_ENDPOINT_XFER_ISOC:
|
||||
ep_conf = VHUB_EP_CFG_SET_TYPE(EP_TYPE_ISO);
|
||||
ep->epn.is_iso = true;
|
||||
break;
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* Encode the rest of the EP config register */
|
||||
if (maxpacket < 1024)
|
||||
ep_conf |= VHUB_EP_CFG_SET_MAX_PKT(maxpacket);
|
||||
if (!ep->epn.is_in)
|
||||
ep_conf |= VHUB_EP_CFG_DIR_OUT;
|
||||
ep_conf |= VHUB_EP_CFG_SET_EP_NUM(usb_endpoint_num(desc));
|
||||
ep_conf |= VHUB_EP_CFG_ENABLE;
|
||||
ep_conf |= VHUB_EP_CFG_SET_DEV(dev->index + 1);
|
||||
EPVDBG(ep, "config=%08x\n", ep_conf);
|
||||
|
||||
spin_lock_irqsave(&vhub->lock, flags);
|
||||
|
||||
/* Disable HW and reset DMA */
|
||||
writel(0, ep->epn.regs + AST_VHUB_EP_CONFIG);
|
||||
writel(VHUB_EP_DMA_CTRL_RESET,
|
||||
ep->epn.regs + AST_VHUB_EP_DMA_CTLSTAT);
|
||||
|
||||
/* Configure and enable */
|
||||
writel(ep_conf, ep->epn.regs + AST_VHUB_EP_CONFIG);
|
||||
|
||||
if (ep->epn.desc_mode) {
|
||||
/* Clear DMA status, including the DMA read ptr */
|
||||
writel(0, ep->epn.regs + AST_VHUB_EP_DESC_STATUS);
|
||||
|
||||
/* Set descriptor base */
|
||||
writel(ep->epn.descs_dma,
|
||||
ep->epn.regs + AST_VHUB_EP_DESC_BASE);
|
||||
|
||||
/* Set base DMA config value */
|
||||
ep->epn.dma_conf = VHUB_EP_DMA_DESC_MODE;
|
||||
if (ep->epn.is_in)
|
||||
ep->epn.dma_conf |= VHUB_EP_DMA_IN_LONG_MODE;
|
||||
|
||||
/* First reset and disable all operations */
|
||||
writel(ep->epn.dma_conf | VHUB_EP_DMA_CTRL_RESET,
|
||||
ep->epn.regs + AST_VHUB_EP_DMA_CTLSTAT);
|
||||
|
||||
/* Enable descriptor mode */
|
||||
writel(ep->epn.dma_conf,
|
||||
ep->epn.regs + AST_VHUB_EP_DMA_CTLSTAT);
|
||||
} else {
|
||||
/* Set base DMA config value */
|
||||
ep->epn.dma_conf = VHUB_EP_DMA_SINGLE_STAGE;
|
||||
|
||||
/* Reset and switch to single stage mode */
|
||||
writel(ep->epn.dma_conf | VHUB_EP_DMA_CTRL_RESET,
|
||||
ep->epn.regs + AST_VHUB_EP_DMA_CTLSTAT);
|
||||
writel(ep->epn.dma_conf,
|
||||
ep->epn.regs + AST_VHUB_EP_DMA_CTLSTAT);
|
||||
writel(0, ep->epn.regs + AST_VHUB_EP_DESC_STATUS);
|
||||
}
|
||||
|
||||
/* Cleanup data toggle just in case */
|
||||
writel(VHUB_EP_TOGGLE_SET_EPNUM(ep->epn.g_idx),
|
||||
vhub->regs + AST_VHUB_EP_TOGGLE);
|
||||
|
||||
/* Cleanup and enable ACK interrupt */
|
||||
imask = VHUB_EP_IRQ(ep->epn.g_idx);
|
||||
writel(imask, vhub->regs + AST_VHUB_EP_ACK_ISR);
|
||||
ep_ier = readl(vhub->regs + AST_VHUB_EP_ACK_IER);
|
||||
ep_ier |= imask;
|
||||
writel(ep_ier, vhub->regs + AST_VHUB_EP_ACK_IER);
|
||||
|
||||
/* Woot, we are online ! */
|
||||
ep->epn.enabled = true;
|
||||
|
||||
spin_unlock_irqrestore(&vhub->lock, flags);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void ast_vhub_epn_dispose(struct usb_ep *u_ep)
|
||||
{
|
||||
struct ast_vhub_ep *ep = to_ast_ep(u_ep);
|
||||
|
||||
if (WARN_ON(!ep->dev || !ep->d_idx))
|
||||
return;
|
||||
|
||||
EPDBG(ep, "Releasing endpoint\n");
|
||||
|
||||
/* Take it out of the EP list */
|
||||
list_del_init(&ep->ep.ep_list);
|
||||
|
||||
/* Mark the address free in the device */
|
||||
ep->dev->epns[ep->d_idx - 1] = NULL;
|
||||
|
||||
/* Free name & DMA buffers */
|
||||
kfree(ep->ep.name);
|
||||
ep->ep.name = NULL;
|
||||
dma_free_coherent(&ep->vhub->pdev->dev,
|
||||
AST_VHUB_EPn_MAX_PACKET +
|
||||
8 * AST_VHUB_DESCS_COUNT,
|
||||
ep->buf, ep->buf_dma);
|
||||
ep->buf = NULL;
|
||||
ep->epn.descs = NULL;
|
||||
|
||||
/* Mark free */
|
||||
ep->dev = NULL;
|
||||
}
|
||||
|
||||
static const struct usb_ep_ops ast_vhub_epn_ops = {
|
||||
.enable = ast_vhub_epn_enable,
|
||||
.disable = ast_vhub_epn_disable,
|
||||
.dispose = ast_vhub_epn_dispose,
|
||||
.queue = ast_vhub_epn_queue,
|
||||
.dequeue = ast_vhub_epn_dequeue,
|
||||
.set_halt = ast_vhub_epn_set_halt,
|
||||
.set_wedge = ast_vhub_epn_set_wedge,
|
||||
.alloc_request = ast_vhub_alloc_request,
|
||||
.free_request = ast_vhub_free_request,
|
||||
};
|
||||
|
||||
struct ast_vhub_ep *ast_vhub_alloc_epn(struct ast_vhub_dev *d, u8 addr)
|
||||
{
|
||||
struct ast_vhub *vhub = d->vhub;
|
||||
struct ast_vhub_ep *ep;
|
||||
unsigned long flags;
|
||||
int i;
|
||||
|
||||
/* Find a free one (no device) */
|
||||
spin_lock_irqsave(&vhub->lock, flags);
|
||||
for (i = 0; i < AST_VHUB_NUM_GEN_EPs; i++)
|
||||
if (vhub->epns[i].dev == NULL)
|
||||
break;
|
||||
if (i >= AST_VHUB_NUM_GEN_EPs) {
|
||||
spin_unlock_irqrestore(&vhub->lock, flags);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Set it up */
|
||||
ep = &vhub->epns[i];
|
||||
ep->dev = d;
|
||||
spin_unlock_irqrestore(&vhub->lock, flags);
|
||||
|
||||
DDBG(d, "Allocating gen EP %d for addr %d\n", i, addr);
|
||||
INIT_LIST_HEAD(&ep->queue);
|
||||
ep->d_idx = addr;
|
||||
ep->vhub = vhub;
|
||||
ep->ep.ops = &ast_vhub_epn_ops;
|
||||
ep->ep.name = kasprintf(GFP_KERNEL, "ep%d", addr);
|
||||
d->epns[addr-1] = ep;
|
||||
ep->epn.g_idx = i;
|
||||
ep->epn.regs = vhub->regs + 0x200 + (i * 0x10);
|
||||
|
||||
ep->buf = dma_alloc_coherent(&vhub->pdev->dev,
|
||||
AST_VHUB_EPn_MAX_PACKET +
|
||||
8 * AST_VHUB_DESCS_COUNT,
|
||||
&ep->buf_dma, GFP_KERNEL);
|
||||
if (!ep->buf) {
|
||||
kfree(ep->ep.name);
|
||||
ep->ep.name = NULL;
|
||||
return NULL;
|
||||
}
|
||||
ep->epn.descs = ep->buf + AST_VHUB_EPn_MAX_PACKET;
|
||||
ep->epn.descs_dma = ep->buf_dma + AST_VHUB_EPn_MAX_PACKET;
|
||||
|
||||
usb_ep_set_maxpacket_limit(&ep->ep, AST_VHUB_EPn_MAX_PACKET);
|
||||
list_add_tail(&ep->ep.ep_list, &d->gadget.ep_list);
|
||||
ep->ep.caps.type_iso = true;
|
||||
ep->ep.caps.type_bulk = true;
|
||||
ep->ep.caps.type_int = true;
|
||||
ep->ep.caps.dir_in = true;
|
||||
ep->ep.caps.dir_out = true;
|
||||
|
||||
return ep;
|
||||
}
|
829
drivers/usb/gadget/udc/aspeed-vhub/hub.c
Normal file
829
drivers/usb/gadget/udc/aspeed-vhub/hub.c
Normal file
|
@ -0,0 +1,829 @@
|
|||
// SPDX-License-Identifier: GPL-2.0+
|
||||
/*
|
||||
* aspeed-vhub -- Driver for Aspeed SoC "vHub" USB gadget
|
||||
*
|
||||
* hub.c - virtual hub handling
|
||||
*
|
||||
* Copyright 2017 IBM Corporation
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/platform_device.h>
|
||||
#include <linux/delay.h>
|
||||
#include <linux/ioport.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/errno.h>
|
||||
#include <linux/list.h>
|
||||
#include <linux/interrupt.h>
|
||||
#include <linux/proc_fs.h>
|
||||
#include <linux/prefetch.h>
|
||||
#include <linux/clk.h>
|
||||
#include <linux/usb/gadget.h>
|
||||
#include <linux/of.h>
|
||||
#include <linux/of_gpio.h>
|
||||
#include <linux/regmap.h>
|
||||
#include <linux/dma-mapping.h>
|
||||
#include <linux/bcd.h>
|
||||
#include <linux/version.h>
|
||||
#include <linux/usb.h>
|
||||
#include <linux/usb/hcd.h>
|
||||
|
||||
#include "vhub.h"
|
||||
|
||||
/* usb 2.0 hub device descriptor
|
||||
*
|
||||
* A few things we may want to improve here:
|
||||
*
|
||||
* - We may need to indicate TT support
|
||||
* - We may need a device qualifier descriptor
|
||||
* as devices can pretend to be usb1 or 2
|
||||
* - Make vid/did overridable
|
||||
* - make it look like usb1 if usb1 mode forced
|
||||
*/
|
||||
#define KERNEL_REL bin2bcd(((LINUX_VERSION_CODE >> 16) & 0x0ff))
|
||||
#define KERNEL_VER bin2bcd(((LINUX_VERSION_CODE >> 8) & 0x0ff))
|
||||
|
||||
enum {
|
||||
AST_VHUB_STR_MANUF = 3,
|
||||
AST_VHUB_STR_PRODUCT = 2,
|
||||
AST_VHUB_STR_SERIAL = 1,
|
||||
};
|
||||
|
||||
static const struct usb_device_descriptor ast_vhub_dev_desc = {
|
||||
.bLength = USB_DT_DEVICE_SIZE,
|
||||
.bDescriptorType = USB_DT_DEVICE,
|
||||
.bcdUSB = cpu_to_le16(0x0200),
|
||||
.bDeviceClass = USB_CLASS_HUB,
|
||||
.bDeviceSubClass = 0,
|
||||
.bDeviceProtocol = 1,
|
||||
.bMaxPacketSize0 = 64,
|
||||
.idVendor = cpu_to_le16(0x1d6b),
|
||||
.idProduct = cpu_to_le16(0x0107),
|
||||
.bcdDevice = cpu_to_le16(0x0100),
|
||||
.iManufacturer = AST_VHUB_STR_MANUF,
|
||||
.iProduct = AST_VHUB_STR_PRODUCT,
|
||||
.iSerialNumber = AST_VHUB_STR_SERIAL,
|
||||
.bNumConfigurations = 1,
|
||||
};
|
||||
|
||||
/* Patches to the above when forcing USB1 mode */
|
||||
static void ast_vhub_patch_dev_desc_usb1(struct usb_device_descriptor *desc)
|
||||
{
|
||||
desc->bcdUSB = cpu_to_le16(0x0100);
|
||||
desc->bDeviceProtocol = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Configuration descriptor: same comments as above
|
||||
* regarding handling USB1 mode.
|
||||
*/
|
||||
|
||||
/*
|
||||
* We don't use sizeof() as Linux definition of
|
||||
* struct usb_endpoint_descriptor contains 2
|
||||
* extra bytes
|
||||
*/
|
||||
#define AST_VHUB_CONF_DESC_SIZE (USB_DT_CONFIG_SIZE + \
|
||||
USB_DT_INTERFACE_SIZE + \
|
||||
USB_DT_ENDPOINT_SIZE)
|
||||
|
||||
static const struct ast_vhub_full_cdesc {
|
||||
struct usb_config_descriptor cfg;
|
||||
struct usb_interface_descriptor intf;
|
||||
struct usb_endpoint_descriptor ep;
|
||||
} __attribute__ ((packed)) ast_vhub_conf_desc = {
|
||||
.cfg = {
|
||||
.bLength = USB_DT_CONFIG_SIZE,
|
||||
.bDescriptorType = USB_DT_CONFIG,
|
||||
.wTotalLength = cpu_to_le16(AST_VHUB_CONF_DESC_SIZE),
|
||||
.bNumInterfaces = 1,
|
||||
.bConfigurationValue = 1,
|
||||
.iConfiguration = 0,
|
||||
.bmAttributes = USB_CONFIG_ATT_ONE |
|
||||
USB_CONFIG_ATT_SELFPOWER |
|
||||
USB_CONFIG_ATT_WAKEUP,
|
||||
.bMaxPower = 0,
|
||||
},
|
||||
.intf = {
|
||||
.bLength = USB_DT_INTERFACE_SIZE,
|
||||
.bDescriptorType = USB_DT_INTERFACE,
|
||||
.bInterfaceNumber = 0,
|
||||
.bAlternateSetting = 0,
|
||||
.bNumEndpoints = 1,
|
||||
.bInterfaceClass = USB_CLASS_HUB,
|
||||
.bInterfaceSubClass = 0,
|
||||
.bInterfaceProtocol = 0,
|
||||
.iInterface = 0,
|
||||
},
|
||||
.ep = {
|
||||
.bLength = USB_DT_ENDPOINT_SIZE,
|
||||
.bDescriptorType = USB_DT_ENDPOINT,
|
||||
.bEndpointAddress = 0x81,
|
||||
.bmAttributes = USB_ENDPOINT_XFER_INT,
|
||||
.wMaxPacketSize = cpu_to_le16(1),
|
||||
.bInterval = 0x0c,
|
||||
},
|
||||
};
|
||||
|
||||
#define AST_VHUB_HUB_DESC_SIZE (USB_DT_HUB_NONVAR_SIZE + 2)
|
||||
|
||||
static const struct usb_hub_descriptor ast_vhub_hub_desc = {
|
||||
.bDescLength = AST_VHUB_HUB_DESC_SIZE,
|
||||
.bDescriptorType = USB_DT_HUB,
|
||||
.bNbrPorts = AST_VHUB_NUM_PORTS,
|
||||
.wHubCharacteristics = cpu_to_le16(HUB_CHAR_NO_LPSM),
|
||||
.bPwrOn2PwrGood = 10,
|
||||
.bHubContrCurrent = 0,
|
||||
.u.hs.DeviceRemovable[0] = 0,
|
||||
.u.hs.DeviceRemovable[1] = 0xff,
|
||||
};
|
||||
|
||||
/*
|
||||
* These strings converted to UTF-16 must be smaller than
|
||||
* our EP0 buffer.
|
||||
*/
|
||||
static const struct usb_string ast_vhub_str_array[] = {
|
||||
{
|
||||
.id = AST_VHUB_STR_SERIAL,
|
||||
.s = "00000000"
|
||||
},
|
||||
{
|
||||
.id = AST_VHUB_STR_PRODUCT,
|
||||
.s = "USB Virtual Hub"
|
||||
},
|
||||
{
|
||||
.id = AST_VHUB_STR_MANUF,
|
||||
.s = "Aspeed"
|
||||
},
|
||||
{ }
|
||||
};
|
||||
|
||||
static const struct usb_gadget_strings ast_vhub_strings = {
|
||||
.language = 0x0409,
|
||||
.strings = (struct usb_string *)ast_vhub_str_array
|
||||
};
|
||||
|
||||
static int ast_vhub_hub_dev_status(struct ast_vhub_ep *ep,
|
||||
u16 wIndex, u16 wValue)
|
||||
{
|
||||
u8 st0;
|
||||
|
||||
EPDBG(ep, "GET_STATUS(dev)\n");
|
||||
|
||||
/*
|
||||
* Mark it as self-powered, I doubt the BMC is powered off
|
||||
* the USB bus ...
|
||||
*/
|
||||
st0 = 1 << USB_DEVICE_SELF_POWERED;
|
||||
|
||||
/*
|
||||
* Need to double check how remote wakeup actually works
|
||||
* on that chip and what triggers it.
|
||||
*/
|
||||
if (ep->vhub->wakeup_en)
|
||||
st0 |= 1 << USB_DEVICE_REMOTE_WAKEUP;
|
||||
|
||||
return ast_vhub_simple_reply(ep, st0, 0);
|
||||
}
|
||||
|
||||
static int ast_vhub_hub_ep_status(struct ast_vhub_ep *ep,
|
||||
u16 wIndex, u16 wValue)
|
||||
{
|
||||
int ep_num;
|
||||
u8 st0 = 0;
|
||||
|
||||
ep_num = wIndex & USB_ENDPOINT_NUMBER_MASK;
|
||||
EPDBG(ep, "GET_STATUS(ep%d)\n", ep_num);
|
||||
|
||||
/* On the hub we have only EP 0 and 1 */
|
||||
if (ep_num == 1) {
|
||||
if (ep->vhub->ep1_stalled)
|
||||
st0 |= 1 << USB_ENDPOINT_HALT;
|
||||
} else if (ep_num != 0)
|
||||
return std_req_stall;
|
||||
|
||||
return ast_vhub_simple_reply(ep, st0, 0);
|
||||
}
|
||||
|
||||
static int ast_vhub_hub_dev_feature(struct ast_vhub_ep *ep,
|
||||
u16 wIndex, u16 wValue,
|
||||
bool is_set)
|
||||
{
|
||||
EPDBG(ep, "%s_FEATURE(dev val=%02x)\n",
|
||||
is_set ? "SET" : "CLEAR", wValue);
|
||||
|
||||
if (wValue != USB_DEVICE_REMOTE_WAKEUP)
|
||||
return std_req_stall;
|
||||
|
||||
ep->vhub->wakeup_en = is_set;
|
||||
EPDBG(ep, "Hub remote wakeup %s\n",
|
||||
is_set ? "enabled" : "disabled");
|
||||
|
||||
return std_req_complete;
|
||||
}
|
||||
|
||||
static int ast_vhub_hub_ep_feature(struct ast_vhub_ep *ep,
|
||||
u16 wIndex, u16 wValue,
|
||||
bool is_set)
|
||||
{
|
||||
int ep_num;
|
||||
u32 reg;
|
||||
|
||||
ep_num = wIndex & USB_ENDPOINT_NUMBER_MASK;
|
||||
EPDBG(ep, "%s_FEATURE(ep%d val=%02x)\n",
|
||||
is_set ? "SET" : "CLEAR", ep_num, wValue);
|
||||
|
||||
if (ep_num > 1)
|
||||
return std_req_stall;
|
||||
if (wValue != USB_ENDPOINT_HALT)
|
||||
return std_req_stall;
|
||||
if (ep_num == 0)
|
||||
return std_req_complete;
|
||||
|
||||
EPDBG(ep, "%s stall on EP 1\n",
|
||||
is_set ? "setting" : "clearing");
|
||||
|
||||
ep->vhub->ep1_stalled = is_set;
|
||||
reg = readl(ep->vhub->regs + AST_VHUB_EP1_CTRL);
|
||||
if (is_set) {
|
||||
reg |= VHUB_EP1_CTRL_STALL;
|
||||
} else {
|
||||
reg &= ~VHUB_EP1_CTRL_STALL;
|
||||
reg |= VHUB_EP1_CTRL_RESET_TOGGLE;
|
||||
}
|
||||
writel(reg, ep->vhub->regs + AST_VHUB_EP1_CTRL);
|
||||
|
||||
return std_req_complete;
|
||||
}
|
||||
|
||||
static int ast_vhub_rep_desc(struct ast_vhub_ep *ep,
|
||||
u8 desc_type, u16 len)
|
||||
{
|
||||
size_t dsize;
|
||||
|
||||
EPDBG(ep, "GET_DESCRIPTOR(type:%d)\n", desc_type);
|
||||
|
||||
/*
|
||||
* Copy first to EP buffer and send from there, so
|
||||
* we can do some in-place patching if needed. We know
|
||||
* the EP buffer is big enough but ensure that doesn't
|
||||
* change. We do that now rather than later after we
|
||||
* have checked sizes etc... to avoid a gcc bug where
|
||||
* it thinks len is constant and barfs about read
|
||||
* overflows in memcpy.
|
||||
*/
|
||||
switch(desc_type) {
|
||||
case USB_DT_DEVICE:
|
||||
dsize = USB_DT_DEVICE_SIZE;
|
||||
memcpy(ep->buf, &ast_vhub_dev_desc, dsize);
|
||||
BUILD_BUG_ON(dsize > sizeof(ast_vhub_dev_desc));
|
||||
BUILD_BUG_ON(USB_DT_DEVICE_SIZE >= AST_VHUB_EP0_MAX_PACKET);
|
||||
break;
|
||||
case USB_DT_CONFIG:
|
||||
dsize = AST_VHUB_CONF_DESC_SIZE;
|
||||
memcpy(ep->buf, &ast_vhub_conf_desc, dsize);
|
||||
BUILD_BUG_ON(dsize > sizeof(ast_vhub_conf_desc));
|
||||
BUILD_BUG_ON(AST_VHUB_CONF_DESC_SIZE >= AST_VHUB_EP0_MAX_PACKET);
|
||||
break;
|
||||
case USB_DT_HUB:
|
||||
dsize = AST_VHUB_HUB_DESC_SIZE;
|
||||
memcpy(ep->buf, &ast_vhub_hub_desc, dsize);
|
||||
BUILD_BUG_ON(dsize > sizeof(ast_vhub_hub_desc));
|
||||
BUILD_BUG_ON(AST_VHUB_HUB_DESC_SIZE >= AST_VHUB_EP0_MAX_PACKET);
|
||||
break;
|
||||
default:
|
||||
return std_req_stall;
|
||||
}
|
||||
|
||||
/* Crop requested length */
|
||||
if (len > dsize)
|
||||
len = dsize;
|
||||
|
||||
/* Patch it if forcing USB1 */
|
||||
if (desc_type == USB_DT_DEVICE && ep->vhub->force_usb1)
|
||||
ast_vhub_patch_dev_desc_usb1(ep->buf);
|
||||
|
||||
/* Shoot it from the EP buffer */
|
||||
return ast_vhub_reply(ep, NULL, len);
|
||||
}
|
||||
|
||||
static int ast_vhub_rep_string(struct ast_vhub_ep *ep,
|
||||
u8 string_id, u16 lang_id,
|
||||
u16 len)
|
||||
{
|
||||
int rc = usb_gadget_get_string (&ast_vhub_strings, string_id, ep->buf);
|
||||
|
||||
/*
|
||||
* This should never happen unless we put too big strings in
|
||||
* the array above
|
||||
*/
|
||||
BUG_ON(rc >= AST_VHUB_EP0_MAX_PACKET);
|
||||
|
||||
if (rc < 0)
|
||||
return std_req_stall;
|
||||
|
||||
/* Shoot it from the EP buffer */
|
||||
return ast_vhub_reply(ep, NULL, min_t(u16, rc, len));
|
||||
}
|
||||
|
||||
enum std_req_rc ast_vhub_std_hub_request(struct ast_vhub_ep *ep,
|
||||
struct usb_ctrlrequest *crq)
|
||||
{
|
||||
struct ast_vhub *vhub = ep->vhub;
|
||||
u16 wValue, wIndex, wLength;
|
||||
|
||||
wValue = le16_to_cpu(crq->wValue);
|
||||
wIndex = le16_to_cpu(crq->wIndex);
|
||||
wLength = le16_to_cpu(crq->wLength);
|
||||
|
||||
/* First packet, grab speed */
|
||||
if (vhub->speed == USB_SPEED_UNKNOWN) {
|
||||
u32 ustat = readl(vhub->regs + AST_VHUB_USBSTS);
|
||||
if (ustat & VHUB_USBSTS_HISPEED)
|
||||
vhub->speed = USB_SPEED_HIGH;
|
||||
else
|
||||
vhub->speed = USB_SPEED_FULL;
|
||||
UDCDBG(vhub, "USB status=%08x speed=%s\n", ustat,
|
||||
vhub->speed == USB_SPEED_HIGH ? "high" : "full");
|
||||
}
|
||||
|
||||
switch ((crq->bRequestType << 8) | crq->bRequest) {
|
||||
/* SET_ADDRESS */
|
||||
case DeviceOutRequest | USB_REQ_SET_ADDRESS:
|
||||
EPDBG(ep, "SET_ADDRESS: Got address %x\n", wValue);
|
||||
writel(wValue, vhub->regs + AST_VHUB_CONF);
|
||||
return std_req_complete;
|
||||
|
||||
/* GET_STATUS */
|
||||
case DeviceRequest | USB_REQ_GET_STATUS:
|
||||
return ast_vhub_hub_dev_status(ep, wIndex, wValue);
|
||||
case InterfaceRequest | USB_REQ_GET_STATUS:
|
||||
return ast_vhub_simple_reply(ep, 0, 0);
|
||||
case EndpointRequest | USB_REQ_GET_STATUS:
|
||||
return ast_vhub_hub_ep_status(ep, wIndex, wValue);
|
||||
|
||||
/* SET/CLEAR_FEATURE */
|
||||
case DeviceOutRequest | USB_REQ_SET_FEATURE:
|
||||
return ast_vhub_hub_dev_feature(ep, wIndex, wValue, true);
|
||||
case DeviceOutRequest | USB_REQ_CLEAR_FEATURE:
|
||||
return ast_vhub_hub_dev_feature(ep, wIndex, wValue, false);
|
||||
case EndpointOutRequest | USB_REQ_SET_FEATURE:
|
||||
return ast_vhub_hub_ep_feature(ep, wIndex, wValue, true);
|
||||
case EndpointOutRequest | USB_REQ_CLEAR_FEATURE:
|
||||
return ast_vhub_hub_ep_feature(ep, wIndex, wValue, false);
|
||||
|
||||
/* GET/SET_CONFIGURATION */
|
||||
case DeviceRequest | USB_REQ_GET_CONFIGURATION:
|
||||
return ast_vhub_simple_reply(ep, 1);
|
||||
case DeviceOutRequest | USB_REQ_SET_CONFIGURATION:
|
||||
if (wValue != 1)
|
||||
return std_req_stall;
|
||||
return std_req_complete;
|
||||
|
||||
/* GET_DESCRIPTOR */
|
||||
case DeviceRequest | USB_REQ_GET_DESCRIPTOR:
|
||||
switch (wValue >> 8) {
|
||||
case USB_DT_DEVICE:
|
||||
case USB_DT_CONFIG:
|
||||
return ast_vhub_rep_desc(ep, wValue >> 8,
|
||||
wLength);
|
||||
case USB_DT_STRING:
|
||||
return ast_vhub_rep_string(ep, wValue & 0xff,
|
||||
wIndex, wLength);
|
||||
}
|
||||
return std_req_stall;
|
||||
|
||||
/* GET/SET_INTERFACE */
|
||||
case DeviceRequest | USB_REQ_GET_INTERFACE:
|
||||
return ast_vhub_simple_reply(ep, 0);
|
||||
case DeviceOutRequest | USB_REQ_SET_INTERFACE:
|
||||
if (wValue != 0 || wIndex != 0)
|
||||
return std_req_stall;
|
||||
return std_req_complete;
|
||||
}
|
||||
return std_req_stall;
|
||||
}
|
||||
|
||||
static void ast_vhub_update_hub_ep1(struct ast_vhub *vhub,
|
||||
unsigned int port)
|
||||
{
|
||||
/* Update HW EP1 response */
|
||||
u32 reg = readl(vhub->regs + AST_VHUB_EP1_STS_CHG);
|
||||
u32 pmask = (1 << (port + 1));
|
||||
if (vhub->ports[port].change)
|
||||
reg |= pmask;
|
||||
else
|
||||
reg &= ~pmask;
|
||||
writel(reg, vhub->regs + AST_VHUB_EP1_STS_CHG);
|
||||
}
|
||||
|
||||
static void ast_vhub_change_port_stat(struct ast_vhub *vhub,
|
||||
unsigned int port,
|
||||
u16 clr_flags,
|
||||
u16 set_flags,
|
||||
bool set_c)
|
||||
{
|
||||
struct ast_vhub_port *p = &vhub->ports[port];
|
||||
u16 prev;
|
||||
|
||||
/* Update port status */
|
||||
prev = p->status;
|
||||
p->status = (prev & ~clr_flags) | set_flags;
|
||||
DDBG(&p->dev, "port %d status %04x -> %04x (C=%d)\n",
|
||||
port + 1, prev, p->status, set_c);
|
||||
|
||||
/* Update change bits if needed */
|
||||
if (set_c) {
|
||||
u16 chg = p->status ^ prev;
|
||||
|
||||
/* Only these are relevant for change */
|
||||
chg &= USB_PORT_STAT_C_CONNECTION |
|
||||
USB_PORT_STAT_C_ENABLE |
|
||||
USB_PORT_STAT_C_SUSPEND |
|
||||
USB_PORT_STAT_C_OVERCURRENT |
|
||||
USB_PORT_STAT_C_RESET |
|
||||
USB_PORT_STAT_C_L1;
|
||||
p->change |= chg;
|
||||
|
||||
ast_vhub_update_hub_ep1(vhub, port);
|
||||
}
|
||||
}
|
||||
|
||||
static void ast_vhub_send_host_wakeup(struct ast_vhub *vhub)
|
||||
{
|
||||
u32 reg = readl(vhub->regs + AST_VHUB_CTRL);
|
||||
UDCDBG(vhub, "Waking up host !\n");
|
||||
reg |= VHUB_CTRL_MANUAL_REMOTE_WAKEUP;
|
||||
writel(reg, vhub->regs + AST_VHUB_CTRL);
|
||||
}
|
||||
|
||||
void ast_vhub_device_connect(struct ast_vhub *vhub,
|
||||
unsigned int port, bool on)
|
||||
{
|
||||
if (on)
|
||||
ast_vhub_change_port_stat(vhub, port, 0,
|
||||
USB_PORT_STAT_CONNECTION, true);
|
||||
else
|
||||
ast_vhub_change_port_stat(vhub, port,
|
||||
USB_PORT_STAT_CONNECTION |
|
||||
USB_PORT_STAT_ENABLE,
|
||||
0, true);
|
||||
|
||||
/*
|
||||
* If the hub is set to wakup the host on connection events
|
||||
* then send a wakeup.
|
||||
*/
|
||||
if (vhub->wakeup_en)
|
||||
ast_vhub_send_host_wakeup(vhub);
|
||||
}
|
||||
|
||||
static void ast_vhub_wake_work(struct work_struct *work)
|
||||
{
|
||||
struct ast_vhub *vhub = container_of(work,
|
||||
struct ast_vhub,
|
||||
wake_work);
|
||||
unsigned long flags;
|
||||
unsigned int i;
|
||||
|
||||
/*
|
||||
* Wake all sleeping ports. If a port is suspended by
|
||||
* the host suspend (without explicit state suspend),
|
||||
* we let the normal host wake path deal with it later.
|
||||
*/
|
||||
spin_lock_irqsave(&vhub->lock, flags);
|
||||
for (i = 0; i < AST_VHUB_NUM_PORTS; i++) {
|
||||
struct ast_vhub_port *p = &vhub->ports[i];
|
||||
|
||||
if (!(p->status & USB_PORT_STAT_SUSPEND))
|
||||
continue;
|
||||
ast_vhub_change_port_stat(vhub, i,
|
||||
USB_PORT_STAT_SUSPEND,
|
||||
0, true);
|
||||
ast_vhub_dev_resume(&p->dev);
|
||||
}
|
||||
ast_vhub_send_host_wakeup(vhub);
|
||||
spin_unlock_irqrestore(&vhub->lock, flags);
|
||||
}
|
||||
|
||||
void ast_vhub_hub_wake_all(struct ast_vhub *vhub)
|
||||
{
|
||||
/*
|
||||
* A device is trying to wake the world, because this
|
||||
* can recurse into the device, we break the call chain
|
||||
* using a work queue
|
||||
*/
|
||||
schedule_work(&vhub->wake_work);
|
||||
}
|
||||
|
||||
static void ast_vhub_port_reset(struct ast_vhub *vhub, u8 port)
|
||||
{
|
||||
struct ast_vhub_port *p = &vhub->ports[port];
|
||||
u16 set, clr, speed;
|
||||
|
||||
/* First mark disabled */
|
||||
ast_vhub_change_port_stat(vhub, port,
|
||||
USB_PORT_STAT_ENABLE |
|
||||
USB_PORT_STAT_SUSPEND,
|
||||
USB_PORT_STAT_RESET,
|
||||
false);
|
||||
|
||||
if (!p->dev.driver)
|
||||
return;
|
||||
|
||||
/*
|
||||
* This will either "start" the port or reset the
|
||||
* device if already started...
|
||||
*/
|
||||
ast_vhub_dev_reset(&p->dev);
|
||||
|
||||
/* Grab the right speed */
|
||||
speed = p->dev.driver->max_speed;
|
||||
if (speed == USB_SPEED_UNKNOWN || speed > vhub->speed)
|
||||
speed = vhub->speed;
|
||||
|
||||
switch (speed) {
|
||||
case USB_SPEED_LOW:
|
||||
set = USB_PORT_STAT_LOW_SPEED;
|
||||
clr = USB_PORT_STAT_HIGH_SPEED;
|
||||
break;
|
||||
case USB_SPEED_FULL:
|
||||
set = 0;
|
||||
clr = USB_PORT_STAT_LOW_SPEED |
|
||||
USB_PORT_STAT_HIGH_SPEED;
|
||||
break;
|
||||
case USB_SPEED_HIGH:
|
||||
set = USB_PORT_STAT_HIGH_SPEED;
|
||||
clr = USB_PORT_STAT_LOW_SPEED;
|
||||
break;
|
||||
default:
|
||||
UDCDBG(vhub, "Unsupported speed %d when"
|
||||
" connecting device\n",
|
||||
speed);
|
||||
return;
|
||||
}
|
||||
clr |= USB_PORT_STAT_RESET;
|
||||
set |= USB_PORT_STAT_ENABLE;
|
||||
|
||||
/* This should ideally be delayed ... */
|
||||
ast_vhub_change_port_stat(vhub, port, clr, set, true);
|
||||
}
|
||||
|
||||
static enum std_req_rc ast_vhub_set_port_feature(struct ast_vhub_ep *ep,
|
||||
u8 port, u16 feat)
|
||||
{
|
||||
struct ast_vhub *vhub = ep->vhub;
|
||||
struct ast_vhub_port *p;
|
||||
|
||||
if (port == 0 || port > AST_VHUB_NUM_PORTS)
|
||||
return std_req_stall;
|
||||
port--;
|
||||
p = &vhub->ports[port];
|
||||
|
||||
switch(feat) {
|
||||
case USB_PORT_FEAT_SUSPEND:
|
||||
if (!(p->status & USB_PORT_STAT_ENABLE))
|
||||
return std_req_complete;
|
||||
ast_vhub_change_port_stat(vhub, port,
|
||||
0, USB_PORT_STAT_SUSPEND,
|
||||
false);
|
||||
ast_vhub_dev_suspend(&p->dev);
|
||||
return std_req_complete;
|
||||
case USB_PORT_FEAT_RESET:
|
||||
EPDBG(ep, "Port reset !\n");
|
||||
ast_vhub_port_reset(vhub, port);
|
||||
return std_req_complete;
|
||||
case USB_PORT_FEAT_POWER:
|
||||
/*
|
||||
* On Power-on, we mark the connected flag changed,
|
||||
* if there's a connected device, some hosts will
|
||||
* otherwise fail to detect it.
|
||||
*/
|
||||
if (p->status & USB_PORT_STAT_CONNECTION) {
|
||||
p->change |= USB_PORT_STAT_C_CONNECTION;
|
||||
ast_vhub_update_hub_ep1(vhub, port);
|
||||
}
|
||||
return std_req_complete;
|
||||
case USB_PORT_FEAT_TEST:
|
||||
case USB_PORT_FEAT_INDICATOR:
|
||||
/* We don't do anything with these */
|
||||
return std_req_complete;
|
||||
}
|
||||
return std_req_stall;
|
||||
}
|
||||
|
||||
static enum std_req_rc ast_vhub_clr_port_feature(struct ast_vhub_ep *ep,
|
||||
u8 port, u16 feat)
|
||||
{
|
||||
struct ast_vhub *vhub = ep->vhub;
|
||||
struct ast_vhub_port *p;
|
||||
|
||||
if (port == 0 || port > AST_VHUB_NUM_PORTS)
|
||||
return std_req_stall;
|
||||
port--;
|
||||
p = &vhub->ports[port];
|
||||
|
||||
switch(feat) {
|
||||
case USB_PORT_FEAT_ENABLE:
|
||||
ast_vhub_change_port_stat(vhub, port,
|
||||
USB_PORT_STAT_ENABLE |
|
||||
USB_PORT_STAT_SUSPEND, 0,
|
||||
false);
|
||||
ast_vhub_dev_suspend(&p->dev);
|
||||
return std_req_complete;
|
||||
case USB_PORT_FEAT_SUSPEND:
|
||||
if (!(p->status & USB_PORT_STAT_SUSPEND))
|
||||
return std_req_complete;
|
||||
ast_vhub_change_port_stat(vhub, port,
|
||||
USB_PORT_STAT_SUSPEND, 0,
|
||||
false);
|
||||
ast_vhub_dev_resume(&p->dev);
|
||||
return std_req_complete;
|
||||
case USB_PORT_FEAT_POWER:
|
||||
/* We don't do power control */
|
||||
return std_req_complete;
|
||||
case USB_PORT_FEAT_INDICATOR:
|
||||
/* We don't have indicators */
|
||||
return std_req_complete;
|
||||
case USB_PORT_FEAT_C_CONNECTION:
|
||||
case USB_PORT_FEAT_C_ENABLE:
|
||||
case USB_PORT_FEAT_C_SUSPEND:
|
||||
case USB_PORT_FEAT_C_OVER_CURRENT:
|
||||
case USB_PORT_FEAT_C_RESET:
|
||||
/* Clear state-change feature */
|
||||
p->change &= ~(1u << (feat - 16));
|
||||
ast_vhub_update_hub_ep1(vhub, port);
|
||||
return std_req_complete;
|
||||
}
|
||||
return std_req_stall;
|
||||
}
|
||||
|
||||
static enum std_req_rc ast_vhub_get_port_stat(struct ast_vhub_ep *ep,
|
||||
u8 port)
|
||||
{
|
||||
struct ast_vhub *vhub = ep->vhub;
|
||||
u16 stat, chg;
|
||||
|
||||
if (port == 0 || port > AST_VHUB_NUM_PORTS)
|
||||
return std_req_stall;
|
||||
port--;
|
||||
|
||||
stat = vhub->ports[port].status;
|
||||
chg = vhub->ports[port].change;
|
||||
|
||||
/* We always have power */
|
||||
stat |= USB_PORT_STAT_POWER;
|
||||
|
||||
EPDBG(ep, " port status=%04x change=%04x\n", stat, chg);
|
||||
|
||||
return ast_vhub_simple_reply(ep,
|
||||
stat & 0xff,
|
||||
stat >> 8,
|
||||
chg & 0xff,
|
||||
chg >> 8);
|
||||
}
|
||||
|
||||
enum std_req_rc ast_vhub_class_hub_request(struct ast_vhub_ep *ep,
|
||||
struct usb_ctrlrequest *crq)
|
||||
{
|
||||
u16 wValue, wIndex, wLength;
|
||||
|
||||
wValue = le16_to_cpu(crq->wValue);
|
||||
wIndex = le16_to_cpu(crq->wIndex);
|
||||
wLength = le16_to_cpu(crq->wLength);
|
||||
|
||||
switch ((crq->bRequestType << 8) | crq->bRequest) {
|
||||
case GetHubStatus:
|
||||
EPDBG(ep, "GetHubStatus\n");
|
||||
return ast_vhub_simple_reply(ep, 0, 0, 0, 0);
|
||||
case GetPortStatus:
|
||||
EPDBG(ep, "GetPortStatus(%d)\n", wIndex & 0xff);
|
||||
return ast_vhub_get_port_stat(ep, wIndex & 0xf);
|
||||
case GetHubDescriptor:
|
||||
if (wValue != (USB_DT_HUB << 8))
|
||||
return std_req_stall;
|
||||
EPDBG(ep, "GetHubDescriptor(%d)\n", wIndex & 0xff);
|
||||
return ast_vhub_rep_desc(ep, USB_DT_HUB, wLength);
|
||||
case SetHubFeature:
|
||||
case ClearHubFeature:
|
||||
EPDBG(ep, "Get/SetHubFeature(%d)\n", wValue);
|
||||
/* No feature, just complete the requests */
|
||||
if (wValue == C_HUB_LOCAL_POWER ||
|
||||
wValue == C_HUB_OVER_CURRENT)
|
||||
return std_req_complete;
|
||||
return std_req_stall;
|
||||
case SetPortFeature:
|
||||
EPDBG(ep, "SetPortFeature(%d,%d)\n", wIndex & 0xf, wValue);
|
||||
return ast_vhub_set_port_feature(ep, wIndex & 0xf, wValue);
|
||||
case ClearPortFeature:
|
||||
EPDBG(ep, "ClearPortFeature(%d,%d)\n", wIndex & 0xf, wValue);
|
||||
return ast_vhub_clr_port_feature(ep, wIndex & 0xf, wValue);
|
||||
default:
|
||||
EPDBG(ep, "Unknown class request\n");
|
||||
}
|
||||
return std_req_stall;
|
||||
}
|
||||
|
||||
void ast_vhub_hub_suspend(struct ast_vhub *vhub)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
UDCDBG(vhub, "USB bus suspend\n");
|
||||
|
||||
if (vhub->suspended)
|
||||
return;
|
||||
|
||||
vhub->suspended = true;
|
||||
|
||||
/*
|
||||
* Forward to unsuspended ports without changing
|
||||
* their connection status.
|
||||
*/
|
||||
for (i = 0; i < AST_VHUB_NUM_PORTS; i++) {
|
||||
struct ast_vhub_port *p = &vhub->ports[i];
|
||||
|
||||
if (!(p->status & USB_PORT_STAT_SUSPEND))
|
||||
ast_vhub_dev_suspend(&p->dev);
|
||||
}
|
||||
}
|
||||
|
||||
void ast_vhub_hub_resume(struct ast_vhub *vhub)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
UDCDBG(vhub, "USB bus resume\n");
|
||||
|
||||
if (!vhub->suspended)
|
||||
return;
|
||||
|
||||
vhub->suspended = false;
|
||||
|
||||
/*
|
||||
* Forward to unsuspended ports without changing
|
||||
* their connection status.
|
||||
*/
|
||||
for (i = 0; i < AST_VHUB_NUM_PORTS; i++) {
|
||||
struct ast_vhub_port *p = &vhub->ports[i];
|
||||
|
||||
if (!(p->status & USB_PORT_STAT_SUSPEND))
|
||||
ast_vhub_dev_resume(&p->dev);
|
||||
}
|
||||
}
|
||||
|
||||
void ast_vhub_hub_reset(struct ast_vhub *vhub)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
UDCDBG(vhub, "USB bus reset\n");
|
||||
|
||||
/*
|
||||
* Is the speed known ? If not we don't care, we aren't
|
||||
* initialized yet and ports haven't been enabled.
|
||||
*/
|
||||
if (vhub->speed == USB_SPEED_UNKNOWN)
|
||||
return;
|
||||
|
||||
/* We aren't suspended anymore obviously */
|
||||
vhub->suspended = false;
|
||||
|
||||
/* No speed set */
|
||||
vhub->speed = USB_SPEED_UNKNOWN;
|
||||
|
||||
/* Wakeup not enabled anymore */
|
||||
vhub->wakeup_en = false;
|
||||
|
||||
/*
|
||||
* Clear all port status, disable gadgets and "suspend"
|
||||
* them. They will be woken up by a port reset.
|
||||
*/
|
||||
for (i = 0; i < AST_VHUB_NUM_PORTS; i++) {
|
||||
struct ast_vhub_port *p = &vhub->ports[i];
|
||||
|
||||
/* Only keep the connected flag */
|
||||
p->status &= USB_PORT_STAT_CONNECTION;
|
||||
p->change = 0;
|
||||
|
||||
/* Suspend the gadget if any */
|
||||
ast_vhub_dev_suspend(&p->dev);
|
||||
}
|
||||
|
||||
/* Cleanup HW */
|
||||
writel(0, vhub->regs + AST_VHUB_CONF);
|
||||
writel(0, vhub->regs + AST_VHUB_EP0_CTRL);
|
||||
writel(VHUB_EP1_CTRL_RESET_TOGGLE |
|
||||
VHUB_EP1_CTRL_ENABLE,
|
||||
vhub->regs + AST_VHUB_EP1_CTRL);
|
||||
writel(0, vhub->regs + AST_VHUB_EP1_STS_CHG);
|
||||
}
|
||||
|
||||
void ast_vhub_init_hub(struct ast_vhub *vhub)
|
||||
{
|
||||
vhub->speed = USB_SPEED_UNKNOWN;
|
||||
INIT_WORK(&vhub->wake_work, ast_vhub_wake_work);
|
||||
}
|
||||
|
514
drivers/usb/gadget/udc/aspeed-vhub/vhub.h
Normal file
514
drivers/usb/gadget/udc/aspeed-vhub/vhub.h
Normal file
|
@ -0,0 +1,514 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0+ */
|
||||
#ifndef __ASPEED_VHUB_H
|
||||
#define __ASPEED_VHUB_H
|
||||
|
||||
/*****************************
|
||||
* *
|
||||
* VHUB register definitions *
|
||||
* *
|
||||
*****************************/
|
||||
|
||||
#define AST_VHUB_CTRL 0x00 /* Root Function Control & Status Register */
|
||||
#define AST_VHUB_CONF 0x04 /* Root Configuration Setting Register */
|
||||
#define AST_VHUB_IER 0x08 /* Interrupt Ctrl Register */
|
||||
#define AST_VHUB_ISR 0x0C /* Interrupt Status Register */
|
||||
#define AST_VHUB_EP_ACK_IER 0x10 /* Programmable Endpoint Pool ACK Interrupt Enable Register */
|
||||
#define AST_VHUB_EP_NACK_IER 0x14 /* Programmable Endpoint Pool NACK Interrupt Enable Register */
|
||||
#define AST_VHUB_EP_ACK_ISR 0x18 /* Programmable Endpoint Pool ACK Interrupt Status Register */
|
||||
#define AST_VHUB_EP_NACK_ISR 0x1C /* Programmable Endpoint Pool NACK Interrupt Status Register */
|
||||
#define AST_VHUB_SW_RESET 0x20 /* Device Controller Soft Reset Enable Register */
|
||||
#define AST_VHUB_USBSTS 0x24 /* USB Status Register */
|
||||
#define AST_VHUB_EP_TOGGLE 0x28 /* Programmable Endpoint Pool Data Toggle Value Set */
|
||||
#define AST_VHUB_ISO_FAIL_ACC 0x2C /* Isochronous Transaction Fail Accumulator */
|
||||
#define AST_VHUB_EP0_CTRL 0x30 /* Endpoint 0 Contrl/Status Register */
|
||||
#define AST_VHUB_EP0_DATA 0x34 /* Base Address of Endpoint 0 In/OUT Data Buffer Register */
|
||||
#define AST_VHUB_EP1_CTRL 0x38 /* Endpoint 1 Contrl/Status Register */
|
||||
#define AST_VHUB_EP1_STS_CHG 0x3C /* Endpoint 1 Status Change Bitmap Data */
|
||||
#define AST_VHUB_SETUP0 0x80 /* Root Device Setup Data Buffer0 */
|
||||
#define AST_VHUB_SETUP1 0x84 /* Root Device Setup Data Buffer1 */
|
||||
|
||||
/* Main control reg */
|
||||
#define VHUB_CTRL_PHY_CLK (1 << 31)
|
||||
#define VHUB_CTRL_PHY_LOOP_TEST (1 << 25)
|
||||
#define VHUB_CTRL_DN_PWN (1 << 24)
|
||||
#define VHUB_CTRL_DP_PWN (1 << 23)
|
||||
#define VHUB_CTRL_LONG_DESC (1 << 18)
|
||||
#define VHUB_CTRL_ISO_RSP_CTRL (1 << 17)
|
||||
#define VHUB_CTRL_SPLIT_IN (1 << 16)
|
||||
#define VHUB_CTRL_LOOP_T_RESULT (1 << 15)
|
||||
#define VHUB_CTRL_LOOP_T_STS (1 << 14)
|
||||
#define VHUB_CTRL_PHY_BIST_RESULT (1 << 13)
|
||||
#define VHUB_CTRL_PHY_BIST_CTRL (1 << 12)
|
||||
#define VHUB_CTRL_PHY_RESET_DIS (1 << 11)
|
||||
#define VHUB_CTRL_SET_TEST_MODE(x) ((x) << 8)
|
||||
#define VHUB_CTRL_MANUAL_REMOTE_WAKEUP (1 << 4)
|
||||
#define VHUB_CTRL_AUTO_REMOTE_WAKEUP (1 << 3)
|
||||
#define VHUB_CTRL_CLK_STOP_SUSPEND (1 << 2)
|
||||
#define VHUB_CTRL_FULL_SPEED_ONLY (1 << 1)
|
||||
#define VHUB_CTRL_UPSTREAM_CONNECT (1 << 0)
|
||||
|
||||
/* IER & ISR */
|
||||
#define VHUB_IRQ_USB_CMD_DEADLOCK (1 << 18)
|
||||
#define VHUB_IRQ_EP_POOL_NAK (1 << 17)
|
||||
#define VHUB_IRQ_EP_POOL_ACK_STALL (1 << 16)
|
||||
#define VHUB_IRQ_DEVICE5 (1 << 13)
|
||||
#define VHUB_IRQ_DEVICE4 (1 << 12)
|
||||
#define VHUB_IRQ_DEVICE3 (1 << 11)
|
||||
#define VHUB_IRQ_DEVICE2 (1 << 10)
|
||||
#define VHUB_IRQ_DEVICE1 (1 << 9)
|
||||
#define VHUB_IRQ_BUS_RESUME (1 << 8)
|
||||
#define VHUB_IRQ_BUS_SUSPEND (1 << 7)
|
||||
#define VHUB_IRQ_BUS_RESET (1 << 6)
|
||||
#define VHUB_IRQ_HUB_EP1_IN_DATA_ACK (1 << 5)
|
||||
#define VHUB_IRQ_HUB_EP0_IN_DATA_NAK (1 << 4)
|
||||
#define VHUB_IRQ_HUB_EP0_IN_ACK_STALL (1 << 3)
|
||||
#define VHUB_IRQ_HUB_EP0_OUT_NAK (1 << 2)
|
||||
#define VHUB_IRQ_HUB_EP0_OUT_ACK_STALL (1 << 1)
|
||||
#define VHUB_IRQ_HUB_EP0_SETUP (1 << 0)
|
||||
#define VHUB_IRQ_ACK_ALL 0x1ff
|
||||
|
||||
/* SW reset reg */
|
||||
#define VHUB_SW_RESET_EP_POOL (1 << 9)
|
||||
#define VHUB_SW_RESET_DMA_CONTROLLER (1 << 8)
|
||||
#define VHUB_SW_RESET_DEVICE5 (1 << 5)
|
||||
#define VHUB_SW_RESET_DEVICE4 (1 << 4)
|
||||
#define VHUB_SW_RESET_DEVICE3 (1 << 3)
|
||||
#define VHUB_SW_RESET_DEVICE2 (1 << 2)
|
||||
#define VHUB_SW_RESET_DEVICE1 (1 << 1)
|
||||
#define VHUB_SW_RESET_ROOT_HUB (1 << 0)
|
||||
#define VHUB_SW_RESET_ALL (VHUB_SW_RESET_EP_POOL | \
|
||||
VHUB_SW_RESET_DMA_CONTROLLER | \
|
||||
VHUB_SW_RESET_DEVICE5 | \
|
||||
VHUB_SW_RESET_DEVICE4 | \
|
||||
VHUB_SW_RESET_DEVICE3 | \
|
||||
VHUB_SW_RESET_DEVICE2 | \
|
||||
VHUB_SW_RESET_DEVICE1 | \
|
||||
VHUB_SW_RESET_ROOT_HUB)
|
||||
/* EP ACK/NACK IRQ masks */
|
||||
#define VHUB_EP_IRQ(n) (1 << (n))
|
||||
#define VHUB_EP_IRQ_ALL 0x7fff /* 15 EPs */
|
||||
|
||||
/* USB status reg */
|
||||
#define VHUB_USBSTS_HISPEED (1 << 27)
|
||||
|
||||
/* EP toggle */
|
||||
#define VHUB_EP_TOGGLE_VALUE (1 << 8)
|
||||
#define VHUB_EP_TOGGLE_SET_EPNUM(x) ((x) & 0x1f)
|
||||
|
||||
/* HUB EP0 control */
|
||||
#define VHUB_EP0_CTRL_STALL (1 << 0)
|
||||
#define VHUB_EP0_TX_BUFF_RDY (1 << 1)
|
||||
#define VHUB_EP0_RX_BUFF_RDY (1 << 2)
|
||||
#define VHUB_EP0_RX_LEN(x) (((x) >> 16) & 0x7f)
|
||||
#define VHUB_EP0_SET_TX_LEN(x) (((x) & 0x7f) << 8)
|
||||
|
||||
/* HUB EP1 control */
|
||||
#define VHUB_EP1_CTRL_RESET_TOGGLE (1 << 2)
|
||||
#define VHUB_EP1_CTRL_STALL (1 << 1)
|
||||
#define VHUB_EP1_CTRL_ENABLE (1 << 0)
|
||||
|
||||
/***********************************
|
||||
* *
|
||||
* per-device register definitions *
|
||||
* *
|
||||
***********************************/
|
||||
#define AST_VHUB_DEV_EN_CTRL 0x00
|
||||
#define AST_VHUB_DEV_ISR 0x04
|
||||
#define AST_VHUB_DEV_EP0_CTRL 0x08
|
||||
#define AST_VHUB_DEV_EP0_DATA 0x0c
|
||||
|
||||
/* Device enable control */
|
||||
#define VHUB_DEV_EN_SET_ADDR(x) ((x) << 8)
|
||||
#define VHUB_DEV_EN_ADDR_MASK ((0xff) << 8)
|
||||
#define VHUB_DEV_EN_EP0_NAK_IRQEN (1 << 6)
|
||||
#define VHUB_DEV_EN_EP0_IN_ACK_IRQEN (1 << 5)
|
||||
#define VHUB_DEV_EN_EP0_OUT_NAK_IRQEN (1 << 4)
|
||||
#define VHUB_DEV_EN_EP0_OUT_ACK_IRQEN (1 << 3)
|
||||
#define VHUB_DEV_EN_EP0_SETUP_IRQEN (1 << 2)
|
||||
#define VHUB_DEV_EN_SPEED_SEL_HIGH (1 << 1)
|
||||
#define VHUB_DEV_EN_ENABLE_PORT (1 << 0)
|
||||
|
||||
/* Interrupt status */
|
||||
#define VHUV_DEV_IRQ_EP0_IN_DATA_NACK (1 << 4)
|
||||
#define VHUV_DEV_IRQ_EP0_IN_ACK_STALL (1 << 3)
|
||||
#define VHUV_DEV_IRQ_EP0_OUT_DATA_NACK (1 << 2)
|
||||
#define VHUV_DEV_IRQ_EP0_OUT_ACK_STALL (1 << 1)
|
||||
#define VHUV_DEV_IRQ_EP0_SETUP (1 << 0)
|
||||
|
||||
/* Control bits.
|
||||
*
|
||||
* Note: The driver relies on the bulk of those bits
|
||||
* matching corresponding vHub EP0 control bits
|
||||
*/
|
||||
#define VHUB_DEV_EP0_CTRL_STALL VHUB_EP0_CTRL_STALL
|
||||
#define VHUB_DEV_EP0_TX_BUFF_RDY VHUB_EP0_TX_BUFF_RDY
|
||||
#define VHUB_DEV_EP0_RX_BUFF_RDY VHUB_EP0_RX_BUFF_RDY
|
||||
#define VHUB_DEV_EP0_RX_LEN(x) VHUB_EP0_RX_LEN(x)
|
||||
#define VHUB_DEV_EP0_SET_TX_LEN(x) VHUB_EP0_SET_TX_LEN(x)
|
||||
|
||||
/*************************************
|
||||
* *
|
||||
* per-endpoint register definitions *
|
||||
* *
|
||||
*************************************/
|
||||
|
||||
#define AST_VHUB_EP_CONFIG 0x00
|
||||
#define AST_VHUB_EP_DMA_CTLSTAT 0x04
|
||||
#define AST_VHUB_EP_DESC_BASE 0x08
|
||||
#define AST_VHUB_EP_DESC_STATUS 0x0C
|
||||
|
||||
/* EP config reg */
|
||||
#define VHUB_EP_CFG_SET_MAX_PKT(x) (((x) & 0x3ff) << 16)
|
||||
#define VHUB_EP_CFG_AUTO_DATA_DISABLE (1 << 13)
|
||||
#define VHUB_EP_CFG_STALL_CTRL (1 << 12)
|
||||
#define VHUB_EP_CFG_SET_EP_NUM(x) (((x) & 0xf) << 8)
|
||||
#define VHUB_EP_CFG_SET_TYPE(x) ((x) << 5)
|
||||
#define EP_TYPE_OFF 0
|
||||
#define EP_TYPE_BULK 1
|
||||
#define EP_TYPE_INT 2
|
||||
#define EP_TYPE_ISO 3
|
||||
#define VHUB_EP_CFG_DIR_OUT (1 << 4)
|
||||
#define VHUB_EP_CFG_SET_DEV(x) ((x) << 1)
|
||||
#define VHUB_EP_CFG_ENABLE (1 << 0)
|
||||
|
||||
/* EP DMA control */
|
||||
#define VHUB_EP_DMA_PROC_STATUS(x) (((x) >> 4) & 0xf)
|
||||
#define EP_DMA_PROC_RX_IDLE 0
|
||||
#define EP_DMA_PROC_TX_IDLE 8
|
||||
#define VHUB_EP_DMA_IN_LONG_MODE (1 << 3)
|
||||
#define VHUB_EP_DMA_OUT_CONTIG_MODE (1 << 3)
|
||||
#define VHUB_EP_DMA_CTRL_RESET (1 << 2)
|
||||
#define VHUB_EP_DMA_SINGLE_STAGE (1 << 1)
|
||||
#define VHUB_EP_DMA_DESC_MODE (1 << 0)
|
||||
|
||||
/* EP DMA status */
|
||||
#define VHUB_EP_DMA_SET_TX_SIZE(x) ((x) << 16)
|
||||
#define VHUB_EP_DMA_TX_SIZE(x) (((x) >> 16) & 0x7ff)
|
||||
#define VHUB_EP_DMA_RPTR(x) (((x) >> 8) & 0xff)
|
||||
#define VHUB_EP_DMA_SET_RPTR(x) (((x) & 0xff) << 8)
|
||||
#define VHUB_EP_DMA_SET_CPU_WPTR(x) (x)
|
||||
#define VHUB_EP_DMA_SINGLE_KICK (1 << 0) /* WPTR = 1 for single mode */
|
||||
|
||||
/*******************************
|
||||
* *
|
||||
* DMA descriptors definitions *
|
||||
* *
|
||||
*******************************/
|
||||
|
||||
/* Desc W1 IN */
|
||||
#define VHUB_DSC1_IN_INTERRUPT (1 << 31)
|
||||
#define VHUB_DSC1_IN_SPID_DATA0 (0 << 14)
|
||||
#define VHUB_DSC1_IN_SPID_DATA2 (1 << 14)
|
||||
#define VHUB_DSC1_IN_SPID_DATA1 (2 << 14)
|
||||
#define VHUB_DSC1_IN_SPID_MDATA (3 << 14)
|
||||
#define VHUB_DSC1_IN_SET_LEN(x) ((x) & 0xfff)
|
||||
#define VHUB_DSC1_IN_LEN(x) ((x) & 0xfff)
|
||||
|
||||
/****************************************
|
||||
* *
|
||||
* Data structures and misc definitions *
|
||||
* *
|
||||
****************************************/
|
||||
|
||||
#define AST_VHUB_NUM_GEN_EPs 15 /* Generic non-0 EPs */
|
||||
#define AST_VHUB_NUM_PORTS 5 /* vHub ports */
|
||||
#define AST_VHUB_EP0_MAX_PACKET 64 /* EP0's max packet size */
|
||||
#define AST_VHUB_EPn_MAX_PACKET 1024 /* Generic EPs max packet size */
|
||||
#define AST_VHUB_DESCS_COUNT 256 /* Use 256 descriptor mode (valid
|
||||
* values are 256 and 32)
|
||||
*/
|
||||
|
||||
struct ast_vhub;
|
||||
struct ast_vhub_dev;
|
||||
|
||||
/*
|
||||
* DMA descriptor (generic EPs only, currently only used
|
||||
* for IN endpoints
|
||||
*/
|
||||
struct ast_vhub_desc {
|
||||
__le32 w0;
|
||||
__le32 w1;
|
||||
};
|
||||
|
||||
/* A transfer request, either core-originated or internal */
|
||||
struct ast_vhub_req {
|
||||
struct usb_request req;
|
||||
struct list_head queue;
|
||||
|
||||
/* Actual count written to descriptors (desc mode only) */
|
||||
unsigned int act_count;
|
||||
|
||||
/*
|
||||
* Desc number of the final packet or -1. For non-desc
|
||||
* mode (or ep0), any >= 0 value means "last packet"
|
||||
*/
|
||||
int last_desc;
|
||||
|
||||
/* Request active (pending DMAs) */
|
||||
bool active : 1;
|
||||
|
||||
/* Internal request (don't call back core) */
|
||||
bool internal : 1;
|
||||
};
|
||||
#define to_ast_req(__ureq) container_of(__ureq, struct ast_vhub_req, req)
|
||||
|
||||
/* Current state of an EP0 */
|
||||
enum ep0_state {
|
||||
ep0_state_token,
|
||||
ep0_state_data,
|
||||
ep0_state_status,
|
||||
};
|
||||
|
||||
/*
|
||||
* An endpoint, either generic, ep0, actual gadget EP
|
||||
* or internal use vhub EP0. vhub EP1 doesn't have an
|
||||
* associated structure as it's mostly HW managed.
|
||||
*/
|
||||
struct ast_vhub_ep {
|
||||
struct usb_ep ep;
|
||||
|
||||
/* Request queue */
|
||||
struct list_head queue;
|
||||
|
||||
/* EP index in the device, 0 means this is an EP0 */
|
||||
unsigned int d_idx;
|
||||
|
||||
/* Dev pointer or NULL for vHub EP0 */
|
||||
struct ast_vhub_dev *dev;
|
||||
|
||||
/* vHub itself */
|
||||
struct ast_vhub *vhub;
|
||||
|
||||
/*
|
||||
* DMA buffer for EP0, fallback DMA buffer for misaligned
|
||||
* OUT transfers for generic EPs
|
||||
*/
|
||||
void *buf;
|
||||
dma_addr_t buf_dma;
|
||||
|
||||
/* The rest depends on the EP type */
|
||||
union {
|
||||
/* EP0 (either device or vhub) */
|
||||
struct {
|
||||
/*
|
||||
* EP0 registers are "similar" for
|
||||
* vHub and devices but located in
|
||||
* different places.
|
||||
*/
|
||||
void __iomem *ctlstat;
|
||||
void __iomem *setup;
|
||||
|
||||
/* Current state & direction */
|
||||
enum ep0_state state;
|
||||
bool dir_in;
|
||||
|
||||
/* Internal use request */
|
||||
struct ast_vhub_req req;
|
||||
} ep0;
|
||||
|
||||
/* Generic endpoint (aka EPn) */
|
||||
struct {
|
||||
/* Registers */
|
||||
void __iomem *regs;
|
||||
|
||||
/* Index in global pool (0..14) */
|
||||
unsigned int g_idx;
|
||||
|
||||
/* DMA Descriptors */
|
||||
struct ast_vhub_desc *descs;
|
||||
dma_addr_t descs_dma;
|
||||
unsigned int d_next;
|
||||
unsigned int d_last;
|
||||
unsigned int dma_conf;
|
||||
|
||||
/* Max chunk size for IN EPs */
|
||||
unsigned int chunk_max;
|
||||
|
||||
/* State flags */
|
||||
bool is_in : 1;
|
||||
bool is_iso : 1;
|
||||
bool stalled : 1;
|
||||
bool wedged : 1;
|
||||
bool enabled : 1;
|
||||
bool desc_mode : 1;
|
||||
} epn;
|
||||
};
|
||||
};
|
||||
#define to_ast_ep(__uep) container_of(__uep, struct ast_vhub_ep, ep)
|
||||
|
||||
/* A device attached to a vHub port */
|
||||
struct ast_vhub_dev {
|
||||
struct ast_vhub *vhub;
|
||||
void __iomem *regs;
|
||||
|
||||
/* Device index (0...4) and name string */
|
||||
unsigned int index;
|
||||
const char *name;
|
||||
|
||||
/* sysfs enclosure for the gadget gunk */
|
||||
struct device *port_dev;
|
||||
|
||||
/* Link to gadget core */
|
||||
struct usb_gadget gadget;
|
||||
struct usb_gadget_driver *driver;
|
||||
bool registered : 1;
|
||||
bool wakeup_en : 1;
|
||||
bool suspended : 1;
|
||||
bool enabled : 1;
|
||||
|
||||
/* Endpoint structures */
|
||||
struct ast_vhub_ep ep0;
|
||||
struct ast_vhub_ep *epns[AST_VHUB_NUM_GEN_EPs];
|
||||
|
||||
};
|
||||
#define to_ast_dev(__g) container_of(__g, struct ast_vhub_dev, gadget)
|
||||
|
||||
/* Per vhub port stateinfo structure */
|
||||
struct ast_vhub_port {
|
||||
/* Port status & status change registers */
|
||||
u16 status;
|
||||
u16 change;
|
||||
|
||||
/* Associated device slot */
|
||||
struct ast_vhub_dev dev;
|
||||
};
|
||||
|
||||
/* Global vhub structure */
|
||||
struct ast_vhub {
|
||||
struct platform_device *pdev;
|
||||
void __iomem *regs;
|
||||
int irq;
|
||||
spinlock_t lock;
|
||||
struct work_struct wake_work;
|
||||
struct clk *clk;
|
||||
|
||||
/* EP0 DMA buffers allocated in one chunk */
|
||||
void *ep0_bufs;
|
||||
dma_addr_t ep0_bufs_dma;
|
||||
|
||||
/* EP0 of the vhub itself */
|
||||
struct ast_vhub_ep ep0;
|
||||
|
||||
/* State of vhub ep1 */
|
||||
bool ep1_stalled : 1;
|
||||
|
||||
/* Per-port info */
|
||||
struct ast_vhub_port ports[AST_VHUB_NUM_PORTS];
|
||||
|
||||
/* Generic EP data structures */
|
||||
struct ast_vhub_ep epns[AST_VHUB_NUM_GEN_EPs];
|
||||
|
||||
/* Upstream bus is suspended ? */
|
||||
bool suspended : 1;
|
||||
|
||||
/* Hub itself can signal remote wakeup */
|
||||
bool wakeup_en : 1;
|
||||
|
||||
/* Force full speed only */
|
||||
bool force_usb1 : 1;
|
||||
|
||||
/* Upstream bus speed captured at bus reset */
|
||||
unsigned int speed;
|
||||
};
|
||||
|
||||
/* Standard request handlers result codes */
|
||||
enum std_req_rc {
|
||||
std_req_stall = -1, /* Stall requested */
|
||||
std_req_complete = 0, /* Request completed with no data */
|
||||
std_req_data = 1, /* Request completed with data */
|
||||
std_req_driver = 2, /* Pass to driver pls */
|
||||
};
|
||||
|
||||
#ifdef CONFIG_USB_GADGET_VERBOSE
|
||||
#define UDCVDBG(u, fmt...) dev_dbg(&(u)->pdev->dev, fmt)
|
||||
|
||||
#define EPVDBG(ep, fmt, ...) do { \
|
||||
dev_dbg(&(ep)->vhub->pdev->dev, \
|
||||
"%s:EP%d " fmt, \
|
||||
(ep)->dev ? (ep)->dev->name : "hub", \
|
||||
(ep)->d_idx, ##__VA_ARGS__); \
|
||||
} while(0)
|
||||
|
||||
#define DVDBG(d, fmt, ...) do { \
|
||||
dev_dbg(&(d)->vhub->pdev->dev, \
|
||||
"%s " fmt, (d)->name, \
|
||||
##__VA_ARGS__); \
|
||||
} while(0)
|
||||
|
||||
#else
|
||||
#define UDCVDBG(u, fmt...) do { } while(0)
|
||||
#define EPVDBG(ep, fmt, ...) do { } while(0)
|
||||
#define DVDBG(d, fmt, ...) do { } while(0)
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_USB_GADGET_DEBUG
|
||||
#define UDCDBG(u, fmt...) dev_dbg(&(u)->pdev->dev, fmt)
|
||||
|
||||
#define EPDBG(ep, fmt, ...) do { \
|
||||
dev_dbg(&(ep)->vhub->pdev->dev, \
|
||||
"%s:EP%d " fmt, \
|
||||
(ep)->dev ? (ep)->dev->name : "hub", \
|
||||
(ep)->d_idx, ##__VA_ARGS__); \
|
||||
} while(0)
|
||||
|
||||
#define DDBG(d, fmt, ...) do { \
|
||||
dev_dbg(&(d)->vhub->pdev->dev, \
|
||||
"%s " fmt, (d)->name, \
|
||||
##__VA_ARGS__); \
|
||||
} while(0)
|
||||
#else
|
||||
#define UDCDBG(u, fmt...) do { } while(0)
|
||||
#define EPDBG(ep, fmt, ...) do { } while(0)
|
||||
#define DDBG(d, fmt, ...) do { } while(0)
|
||||
#endif
|
||||
|
||||
/* core.c */
|
||||
void ast_vhub_done(struct ast_vhub_ep *ep, struct ast_vhub_req *req,
|
||||
int status);
|
||||
void ast_vhub_nuke(struct ast_vhub_ep *ep, int status);
|
||||
struct usb_request *ast_vhub_alloc_request(struct usb_ep *u_ep,
|
||||
gfp_t gfp_flags);
|
||||
void ast_vhub_free_request(struct usb_ep *u_ep, struct usb_request *u_req);
|
||||
void ast_vhub_init_hw(struct ast_vhub *vhub);
|
||||
|
||||
/* ep0.c */
|
||||
void ast_vhub_ep0_handle_ack(struct ast_vhub_ep *ep, bool in_ack);
|
||||
void ast_vhub_ep0_handle_setup(struct ast_vhub_ep *ep);
|
||||
void ast_vhub_init_ep0(struct ast_vhub *vhub, struct ast_vhub_ep *ep,
|
||||
struct ast_vhub_dev *dev);
|
||||
int ast_vhub_reply(struct ast_vhub_ep *ep, char *ptr, int len);
|
||||
int __ast_vhub_simple_reply(struct ast_vhub_ep *ep, int len, ...);
|
||||
#define ast_vhub_simple_reply(udc, ...) \
|
||||
__ast_vhub_simple_reply((udc), \
|
||||
sizeof((u8[]) { __VA_ARGS__ })/sizeof(u8), \
|
||||
__VA_ARGS__)
|
||||
|
||||
/* hub.c */
|
||||
void ast_vhub_init_hub(struct ast_vhub *vhub);
|
||||
enum std_req_rc ast_vhub_std_hub_request(struct ast_vhub_ep *ep,
|
||||
struct usb_ctrlrequest *crq);
|
||||
enum std_req_rc ast_vhub_class_hub_request(struct ast_vhub_ep *ep,
|
||||
struct usb_ctrlrequest *crq);
|
||||
void ast_vhub_device_connect(struct ast_vhub *vhub, unsigned int port,
|
||||
bool on);
|
||||
void ast_vhub_hub_suspend(struct ast_vhub *vhub);
|
||||
void ast_vhub_hub_resume(struct ast_vhub *vhub);
|
||||
void ast_vhub_hub_reset(struct ast_vhub *vhub);
|
||||
void ast_vhub_hub_wake_all(struct ast_vhub *vhub);
|
||||
|
||||
/* dev.c */
|
||||
int ast_vhub_init_dev(struct ast_vhub *vhub, unsigned int idx);
|
||||
void ast_vhub_del_dev(struct ast_vhub_dev *d);
|
||||
void ast_vhub_dev_irq(struct ast_vhub_dev *d);
|
||||
int ast_vhub_std_dev_request(struct ast_vhub_ep *ep,
|
||||
struct usb_ctrlrequest *crq);
|
||||
|
||||
/* epn.c */
|
||||
void ast_vhub_epn_ack_irq(struct ast_vhub_ep *ep);
|
||||
void ast_vhub_update_epn_stall(struct ast_vhub_ep *ep);
|
||||
struct ast_vhub_ep *ast_vhub_alloc_epn(struct ast_vhub_dev *d, u8 addr);
|
||||
void ast_vhub_dev_suspend(struct ast_vhub_dev *d);
|
||||
void ast_vhub_dev_resume(struct ast_vhub_dev *d);
|
||||
void ast_vhub_dev_reset(struct ast_vhub_dev *d);
|
||||
|
||||
#endif /* __ASPEED_VHUB_H */
|
|
@ -20,7 +20,6 @@
|
|||
#include <linux/ctype.h>
|
||||
#include <linux/usb/ch9.h>
|
||||
#include <linux/usb/gadget.h>
|
||||
#include <linux/usb/atmel_usba_udc.h>
|
||||
#include <linux/delay.h>
|
||||
#include <linux/of.h>
|
||||
#include <linux/irq.h>
|
||||
|
@ -207,94 +206,45 @@ static void usba_ep_init_debugfs(struct usba_udc *udc,
|
|||
struct dentry *ep_root;
|
||||
|
||||
ep_root = debugfs_create_dir(ep->ep.name, udc->debugfs_root);
|
||||
if (!ep_root)
|
||||
goto err_root;
|
||||
ep->debugfs_dir = ep_root;
|
||||
|
||||
ep->debugfs_queue = debugfs_create_file("queue", 0400, ep_root,
|
||||
ep, &queue_dbg_fops);
|
||||
if (!ep->debugfs_queue)
|
||||
goto err_queue;
|
||||
|
||||
if (ep->can_dma) {
|
||||
ep->debugfs_dma_status
|
||||
= debugfs_create_u32("dma_status", 0400, ep_root,
|
||||
&ep->last_dma_status);
|
||||
if (!ep->debugfs_dma_status)
|
||||
goto err_dma_status;
|
||||
}
|
||||
if (ep_is_control(ep)) {
|
||||
ep->debugfs_state
|
||||
= debugfs_create_u32("state", 0400, ep_root,
|
||||
&ep->state);
|
||||
if (!ep->debugfs_state)
|
||||
goto err_state;
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
err_state:
|
||||
debugfs_create_file("queue", 0400, ep_root, ep, &queue_dbg_fops);
|
||||
if (ep->can_dma)
|
||||
debugfs_remove(ep->debugfs_dma_status);
|
||||
err_dma_status:
|
||||
debugfs_remove(ep->debugfs_queue);
|
||||
err_queue:
|
||||
debugfs_remove(ep_root);
|
||||
err_root:
|
||||
dev_err(&ep->udc->pdev->dev,
|
||||
"failed to create debugfs directory for %s\n", ep->ep.name);
|
||||
debugfs_create_u32("dma_status", 0400, ep_root,
|
||||
&ep->last_dma_status);
|
||||
if (ep_is_control(ep))
|
||||
debugfs_create_u32("state", 0400, ep_root, &ep->state);
|
||||
}
|
||||
|
||||
static void usba_ep_cleanup_debugfs(struct usba_ep *ep)
|
||||
{
|
||||
debugfs_remove(ep->debugfs_queue);
|
||||
debugfs_remove(ep->debugfs_dma_status);
|
||||
debugfs_remove(ep->debugfs_state);
|
||||
debugfs_remove(ep->debugfs_dir);
|
||||
ep->debugfs_dma_status = NULL;
|
||||
ep->debugfs_dir = NULL;
|
||||
debugfs_remove_recursive(ep->debugfs_dir);
|
||||
}
|
||||
|
||||
static void usba_init_debugfs(struct usba_udc *udc)
|
||||
{
|
||||
struct dentry *root, *regs;
|
||||
struct dentry *root;
|
||||
struct resource *regs_resource;
|
||||
|
||||
root = debugfs_create_dir(udc->gadget.name, NULL);
|
||||
if (IS_ERR(root) || !root)
|
||||
goto err_root;
|
||||
udc->debugfs_root = root;
|
||||
|
||||
regs_resource = platform_get_resource(udc->pdev, IORESOURCE_MEM,
|
||||
CTRL_IOMEM_ID);
|
||||
|
||||
if (regs_resource) {
|
||||
regs = debugfs_create_file_size("regs", 0400, root, udc,
|
||||
debugfs_create_file_size("regs", 0400, root, udc,
|
||||
®s_dbg_fops,
|
||||
resource_size(regs_resource));
|
||||
if (!regs)
|
||||
goto err_regs;
|
||||
udc->debugfs_regs = regs;
|
||||
}
|
||||
|
||||
usba_ep_init_debugfs(udc, to_usba_ep(udc->gadget.ep0));
|
||||
|
||||
return;
|
||||
|
||||
err_regs:
|
||||
debugfs_remove(root);
|
||||
err_root:
|
||||
udc->debugfs_root = NULL;
|
||||
dev_err(&udc->pdev->dev, "debugfs is not available\n");
|
||||
}
|
||||
|
||||
static void usba_cleanup_debugfs(struct usba_udc *udc)
|
||||
{
|
||||
usba_ep_cleanup_debugfs(to_usba_ep(udc->gadget.ep0));
|
||||
debugfs_remove(udc->debugfs_regs);
|
||||
debugfs_remove(udc->debugfs_root);
|
||||
udc->debugfs_regs = NULL;
|
||||
udc->debugfs_root = NULL;
|
||||
debugfs_remove_recursive(udc->debugfs_root);
|
||||
}
|
||||
#else
|
||||
static inline void usba_ep_init_debugfs(struct usba_udc *udc,
|
||||
|
@ -417,7 +367,7 @@ static inline void usba_int_enb_set(struct usba_udc *udc, u32 val)
|
|||
static int vbus_is_present(struct usba_udc *udc)
|
||||
{
|
||||
if (udc->vbus_pin)
|
||||
return gpiod_get_value(udc->vbus_pin) ^ udc->vbus_pin_inverted;
|
||||
return gpiod_get_value(udc->vbus_pin);
|
||||
|
||||
/* No Vbus detection: Assume always present */
|
||||
return 1;
|
||||
|
@ -2076,7 +2026,6 @@ static struct usba_ep * atmel_udc_of_init(struct platform_device *pdev,
|
|||
|
||||
udc->vbus_pin = devm_gpiod_get_optional(&pdev->dev, "atmel,vbus",
|
||||
GPIOD_IN);
|
||||
udc->vbus_pin_inverted = gpiod_is_active_low(udc->vbus_pin);
|
||||
|
||||
if (fifo_mode == 0) {
|
||||
pp = NULL;
|
||||
|
|
|
@ -287,9 +287,6 @@ struct usba_ep {
|
|||
#ifdef CONFIG_USB_GADGET_DEBUG_FS
|
||||
u32 last_dma_status;
|
||||
struct dentry *debugfs_dir;
|
||||
struct dentry *debugfs_queue;
|
||||
struct dentry *debugfs_dma_status;
|
||||
struct dentry *debugfs_state;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
@ -326,7 +323,6 @@ struct usba_udc {
|
|||
const struct usba_udc_errata *errata;
|
||||
int irq;
|
||||
struct gpio_desc *vbus_pin;
|
||||
int vbus_pin_inverted;
|
||||
int num_ep;
|
||||
int configured_ep;
|
||||
struct usba_fifo_cfg *fifo_cfg;
|
||||
|
@ -345,7 +341,6 @@ struct usba_udc {
|
|||
|
||||
#ifdef CONFIG_USB_GADGET_DEBUG_FS
|
||||
struct dentry *debugfs_root;
|
||||
struct dentry *debugfs_regs;
|
||||
#endif
|
||||
|
||||
struct regmap *pmc;
|
||||
|
|
|
@ -288,8 +288,6 @@ struct bcm63xx_req {
|
|||
* @ep0_reply: Pending reply from gadget driver.
|
||||
* @ep0_request: Outstanding ep0 request.
|
||||
* @debugfs_root: debugfs directory: /sys/kernel/debug/<DRV_MODULE_NAME>.
|
||||
* @debugfs_usbd: debugfs file "usbd" for controller state.
|
||||
* @debugfs_iudma: debugfs file "usbd" for IUDMA state.
|
||||
*/
|
||||
struct bcm63xx_udc {
|
||||
spinlock_t lock;
|
||||
|
@ -330,8 +328,6 @@ struct bcm63xx_udc {
|
|||
struct usb_request *ep0_request;
|
||||
|
||||
struct dentry *debugfs_root;
|
||||
struct dentry *debugfs_usbd;
|
||||
struct dentry *debugfs_iudma;
|
||||
};
|
||||
|
||||
static const struct usb_ep_ops bcm63xx_udc_ep_ops;
|
||||
|
@ -2247,34 +2243,16 @@ DEFINE_SHOW_ATTRIBUTE(bcm63xx_iudma_dbg);
|
|||
*/
|
||||
static void bcm63xx_udc_init_debugfs(struct bcm63xx_udc *udc)
|
||||
{
|
||||
struct dentry *root, *usbd, *iudma;
|
||||
struct dentry *root;
|
||||
|
||||
if (!IS_ENABLED(CONFIG_USB_GADGET_DEBUG_FS))
|
||||
return;
|
||||
|
||||
root = debugfs_create_dir(udc->gadget.name, NULL);
|
||||
if (IS_ERR(root) || !root)
|
||||
goto err_root;
|
||||
|
||||
usbd = debugfs_create_file("usbd", 0400, root, udc,
|
||||
&bcm63xx_usbd_dbg_fops);
|
||||
if (!usbd)
|
||||
goto err_usbd;
|
||||
iudma = debugfs_create_file("iudma", 0400, root, udc,
|
||||
&bcm63xx_iudma_dbg_fops);
|
||||
if (!iudma)
|
||||
goto err_iudma;
|
||||
|
||||
udc->debugfs_root = root;
|
||||
udc->debugfs_usbd = usbd;
|
||||
udc->debugfs_iudma = iudma;
|
||||
return;
|
||||
err_iudma:
|
||||
debugfs_remove(usbd);
|
||||
err_usbd:
|
||||
debugfs_remove(root);
|
||||
err_root:
|
||||
dev_err(udc->dev, "debugfs is not available\n");
|
||||
|
||||
debugfs_create_file("usbd", 0400, root, udc, &bcm63xx_usbd_dbg_fops);
|
||||
debugfs_create_file("iudma", 0400, root, udc, &bcm63xx_iudma_dbg_fops);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2285,12 +2263,7 @@ err_root:
|
|||
*/
|
||||
static void bcm63xx_udc_cleanup_debugfs(struct bcm63xx_udc *udc)
|
||||
{
|
||||
debugfs_remove(udc->debugfs_iudma);
|
||||
debugfs_remove(udc->debugfs_usbd);
|
||||
debugfs_remove(udc->debugfs_root);
|
||||
udc->debugfs_iudma = NULL;
|
||||
udc->debugfs_usbd = NULL;
|
||||
udc->debugfs_root = NULL;
|
||||
debugfs_remove_recursive(udc->debugfs_root);
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
|
|
|
@ -244,6 +244,12 @@ EXPORT_SYMBOL_GPL(usb_ep_free_request);
|
|||
* Returns zero, or a negative error code. Endpoints that are not enabled
|
||||
* report errors; errors will also be
|
||||
* reported when the usb peripheral is disconnected.
|
||||
*
|
||||
* If and only if @req is successfully queued (the return value is zero),
|
||||
* @req->complete() will be called exactly once, when the Gadget core and
|
||||
* UDC are finished with the request. When the completion function is called,
|
||||
* control of the request is returned to the device driver which submitted it.
|
||||
* The completion handler may then immediately free or reuse @req.
|
||||
*/
|
||||
int usb_ep_queue(struct usb_ep *ep,
|
||||
struct usb_request *req, gfp_t gfp_flags)
|
||||
|
|
|
@ -253,6 +253,7 @@ static int dr_controller_setup(struct fsl_udc *udc)
|
|||
portctrl |= PORTSCX_PTW_16BIT;
|
||||
/* fall through */
|
||||
case FSL_USB2_PHY_UTMI:
|
||||
case FSL_USB2_PHY_UTMI_DUAL:
|
||||
if (udc->pdata->have_sysif_regs) {
|
||||
if (udc->pdata->controller_ver) {
|
||||
/* controller version 1.6 or above */
|
||||
|
|
|
@ -209,15 +209,12 @@ static void gr_dfs_create(struct gr_udc *dev)
|
|||
const char *name = "gr_udc_state";
|
||||
|
||||
dev->dfs_root = debugfs_create_dir(dev_name(dev->dev), NULL);
|
||||
dev->dfs_state = debugfs_create_file(name, 0444, dev->dfs_root, dev,
|
||||
&gr_dfs_fops);
|
||||
debugfs_create_file(name, 0444, dev->dfs_root, dev, &gr_dfs_fops);
|
||||
}
|
||||
|
||||
static void gr_dfs_delete(struct gr_udc *dev)
|
||||
{
|
||||
/* Handles NULL and ERR pointers internally */
|
||||
debugfs_remove(dev->dfs_state);
|
||||
debugfs_remove(dev->dfs_root);
|
||||
debugfs_remove_recursive(dev->dfs_root);
|
||||
}
|
||||
|
||||
#else /* !CONFIG_USB_GADGET_DEBUG_FS */
|
||||
|
|
|
@ -217,7 +217,6 @@ struct gr_udc {
|
|||
spinlock_t lock; /* General lock, a.k.a. "dev->lock" in comments */
|
||||
|
||||
struct dentry *dfs_root;
|
||||
struct dentry *dfs_state;
|
||||
};
|
||||
|
||||
#define to_gr_udc(gadget) (container_of((gadget), struct gr_udc, gadget))
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue