Move DWC2 driver out of staging
The DWC2 driver should now be in good enough shape to move out of staging. I have stress tested it overnight on RPI running mass storage and Ethernet transfers in parallel, and for several days on our proprietary PCI-based platform. Signed-off-by: Paul Zimmerman <paulz@synopsys.com> Cc: Felipe Balbi <balbi@ti.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:

committed by
Greg Kroah-Hartman

parent
276d30eab9
commit
197ba5f406
53
drivers/usb/dwc2/Kconfig
Normal file
53
drivers/usb/dwc2/Kconfig
Normal file
@@ -0,0 +1,53 @@
|
||||
config USB_DWC2
|
||||
tristate "DesignWare USB2 DRD Core Support"
|
||||
depends on USB
|
||||
help
|
||||
Say Y or M here if your system has a Dual Role HighSpeed
|
||||
USB controller based on the DesignWare HSOTG IP Core.
|
||||
|
||||
If you choose to build this driver as dynamically linked
|
||||
modules, the core module will be called dwc2.ko, the
|
||||
PCI bus interface module (if you have a PCI bus system)
|
||||
will be called dwc2_pci.ko and the platform interface module
|
||||
(for controllers directly connected to the CPU) will be called
|
||||
dwc2_platform.ko.
|
||||
|
||||
NOTE: This driver at present only implements the Host mode
|
||||
of the controller. The existing s3c-hsotg driver supports
|
||||
Peripheral mode, but only for the Samsung S3C platforms.
|
||||
There are plans to merge the s3c-hsotg driver with this
|
||||
driver in the near future to create a dual-role driver.
|
||||
|
||||
if USB_DWC2
|
||||
|
||||
config USB_DWC2_DEBUG
|
||||
bool "Enable Debugging Messages"
|
||||
help
|
||||
Say Y here to enable debugging messages in the DWC2 Driver.
|
||||
|
||||
config USB_DWC2_VERBOSE
|
||||
bool "Enable Verbose Debugging Messages"
|
||||
depends on USB_DWC2_DEBUG
|
||||
help
|
||||
Say Y here to enable verbose debugging messages in the DWC2 Driver.
|
||||
WARNING: Enabling this will quickly fill your message log.
|
||||
If in doubt, say N.
|
||||
|
||||
config USB_DWC2_TRACK_MISSED_SOFS
|
||||
bool "Enable Missed SOF Tracking"
|
||||
help
|
||||
Say Y here to enable logging of missed SOF events to the dmesg log.
|
||||
WARNING: This feature is still experimental.
|
||||
If in doubt, say N.
|
||||
|
||||
config USB_DWC2_DEBUG_PERIODIC
|
||||
bool "Enable Debugging Messages For Periodic Transfers"
|
||||
depends on USB_DWC2_DEBUG || USB_DWC2_VERBOSE
|
||||
default y
|
||||
help
|
||||
Say N here to disable (verbose) debugging messages to be
|
||||
logged for periodic transfers. This allows better debugging of
|
||||
non-periodic transfers, but of course the debug logs will be
|
||||
incomplete. Note that this also disables some debug messages
|
||||
for which the transfer type cannot be deduced.
|
||||
endif
|
25
drivers/usb/dwc2/Makefile
Normal file
25
drivers/usb/dwc2/Makefile
Normal file
@@ -0,0 +1,25 @@
|
||||
ccflags-$(CONFIG_USB_DWC2_DEBUG) += -DDEBUG
|
||||
ccflags-$(CONFIG_USB_DWC2_VERBOSE) += -DVERBOSE_DEBUG
|
||||
|
||||
obj-$(CONFIG_USB_DWC2) += dwc2.o
|
||||
|
||||
dwc2-y += core.o core_intr.o
|
||||
|
||||
# NOTE: This driver at present only implements the Host mode
|
||||
# of the controller. The existing s3c-hsotg driver supports
|
||||
# Peripheral mode, but only for the Samsung S3C platforms.
|
||||
# There are plans to merge the s3c-hsotg driver with this
|
||||
# driver in the near future to create a dual-role driver. Once
|
||||
# that is done, Host mode will become an optional feature that
|
||||
# is selected with a config option.
|
||||
|
||||
dwc2-y += hcd.o hcd_intr.o
|
||||
dwc2-y += hcd_queue.o hcd_ddma.o
|
||||
|
||||
ifneq ($(CONFIG_PCI),)
|
||||
obj-$(CONFIG_USB_DWC2) += dwc2_pci.o
|
||||
endif
|
||||
obj-$(CONFIG_USB_DWC2) += dwc2_platform.o
|
||||
|
||||
dwc2_pci-y += pci.o
|
||||
dwc2_platform-y += platform.o
|
2777
drivers/usb/dwc2/core.c
Normal file
2777
drivers/usb/dwc2/core.c
Normal file
File diff suppressed because it is too large
Load Diff
768
drivers/usb/dwc2/core.h
Normal file
768
drivers/usb/dwc2/core.h
Normal file
@@ -0,0 +1,768 @@
|
||||
/*
|
||||
* core.h - DesignWare HS OTG Controller common declarations
|
||||
*
|
||||
* Copyright (C) 2004-2013 Synopsys, Inc.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions, and the following disclaimer,
|
||||
* without modification.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. The names of the above-listed copyright holders may not be used
|
||||
* to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* ALTERNATIVELY, this software may be distributed under the terms of the
|
||||
* GNU General Public License ("GPL") as published by the Free Software
|
||||
* Foundation; either version 2 of the License, or (at your option) any
|
||||
* later version.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef __DWC2_CORE_H__
|
||||
#define __DWC2_CORE_H__
|
||||
|
||||
#include <linux/usb/phy.h>
|
||||
#include "hw.h"
|
||||
|
||||
#ifdef DWC2_LOG_WRITES
|
||||
static inline void do_write(u32 value, void *addr)
|
||||
{
|
||||
writel(value, addr);
|
||||
pr_info("INFO:: wrote %08x to %p\n", value, addr);
|
||||
}
|
||||
|
||||
#undef writel
|
||||
#define writel(v, a) do_write(v, a)
|
||||
#endif
|
||||
|
||||
/* Maximum number of Endpoints/HostChannels */
|
||||
#define MAX_EPS_CHANNELS 16
|
||||
|
||||
struct dwc2_hsotg;
|
||||
struct dwc2_host_chan;
|
||||
|
||||
/* Device States */
|
||||
enum dwc2_lx_state {
|
||||
DWC2_L0, /* On state */
|
||||
DWC2_L1, /* LPM sleep state */
|
||||
DWC2_L2, /* USB suspend state */
|
||||
DWC2_L3, /* Off state */
|
||||
};
|
||||
|
||||
/**
|
||||
* struct dwc2_core_params - Parameters for configuring the core
|
||||
*
|
||||
* @otg_cap: Specifies the OTG capabilities.
|
||||
* 0 - HNP and SRP capable
|
||||
* 1 - SRP Only capable
|
||||
* 2 - No HNP/SRP capable (always available)
|
||||
* Defaults to best available option (0, 1, then 2)
|
||||
* @otg_ver: OTG version supported
|
||||
* 0 - 1.3 (default)
|
||||
* 1 - 2.0
|
||||
* @dma_enable: Specifies whether to use slave or DMA mode for accessing
|
||||
* the data FIFOs. The driver will automatically detect the
|
||||
* value for this parameter if none is specified.
|
||||
* 0 - Slave (always available)
|
||||
* 1 - DMA (default, if available)
|
||||
* @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)
|
||||
* @speed: Specifies the maximum speed of operation in host and
|
||||
* device mode. The actual speed depends on the speed of
|
||||
* the attached device and the value of phy_type.
|
||||
* 0 - High Speed
|
||||
* (default when phy_type is UTMI+ or ULPI)
|
||||
* 1 - Full Speed
|
||||
* (default when phy_type is Full Speed)
|
||||
* @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
|
||||
* @host_rx_fifo_size: Number of 4-byte words in the Rx FIFO in host mode when
|
||||
* dynamic FIFO sizing is enabled
|
||||
* 16 to 32768
|
||||
* Actual maximum value is autodetected and also
|
||||
* the default.
|
||||
* @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.
|
||||
* @phy_type: Specifies the type of PHY interface to use. By default,
|
||||
* the driver will automatically detect the phy_type.
|
||||
* 0 - Full Speed Phy
|
||||
* 1 - UTMI+ Phy
|
||||
* 2 - ULPI Phy
|
||||
* Defaults to best available option (2, 1, then 0)
|
||||
* @phy_utmi_width: Specifies the UTMI+ Data Width (in bits). This parameter
|
||||
* is applicable for a phy_type of UTMI+ or ULPI. (For a
|
||||
* ULPI phy_type, this parameter indicates the data width
|
||||
* between the MAC and the ULPI Wrapper.) Also, this
|
||||
* parameter is applicable only if the OTG_HSPHY_WIDTH cC
|
||||
* parameter was set to "8 and 16 bits", meaning that the
|
||||
* core has been configured to work at either data path
|
||||
* width.
|
||||
* 8 or 16 (default 16 if available)
|
||||
* @phy_ulpi_ddr: Specifies whether the ULPI operates at double or single
|
||||
* data rate. This parameter is only applicable if phy_type
|
||||
* is ULPI.
|
||||
* 0 - single data rate ULPI interface with 8 bit wide
|
||||
* data bus (default)
|
||||
* 1 - double data rate ULPI interface with 4 bit wide
|
||||
* data bus
|
||||
* @phy_ulpi_ext_vbus: For a ULPI phy, specifies whether to use the internal or
|
||||
* external supply to drive the VBus
|
||||
* 0 - Internal supply (default)
|
||||
* 1 - External supply
|
||||
* @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
|
||||
* @ulpi_fs_ls: Make ULPI phy operate in FS/LS mode only
|
||||
* 0 - No (default)
|
||||
* 1 - Yes
|
||||
* @host_support_fs_ls_low_power: Specifies whether low power mode is supported
|
||||
* when attached to a Full Speed or Low Speed device in
|
||||
* host mode.
|
||||
* 0 - Don't support low power mode (default)
|
||||
* 1 - Support low power mode
|
||||
* @host_ls_low_power_phy_clk: Specifies the PHY clock rate in low power mode
|
||||
* when connected to a Low Speed device in host
|
||||
* mode. This parameter is applicable only if
|
||||
* host_support_fs_ls_low_power is enabled.
|
||||
* 0 - 48 MHz
|
||||
* (default when phy_type is UTMI+ or ULPI)
|
||||
* 1 - 6 MHz
|
||||
* (default when phy_type is Full Speed)
|
||||
* @ts_dline: Enable Term Select Dline pulsing
|
||||
* 0 - No (default)
|
||||
* 1 - Yes
|
||||
* @reload_ctl: Allow dynamic reloading of HFIR register during runtime
|
||||
* 0 - No (default for core < 2.92a)
|
||||
* 1 - Yes (default for core >= 2.92a)
|
||||
* @ahbcfg: This field allows the default value of the GAHBCFG
|
||||
* register to be overridden
|
||||
* -1 - GAHBCFG value will be set to 0x06
|
||||
* (INCR4, default)
|
||||
* all others - GAHBCFG value will be overridden with
|
||||
* this value
|
||||
* Not all bits can be controlled like this, the
|
||||
* bits defined by GAHBCFG_CTRL_MASK are controlled
|
||||
* by the driver and are ignored in this
|
||||
* configuration value.
|
||||
* @uframe_sched: True to enable the microframe scheduler
|
||||
*
|
||||
* The following parameters may be specified when starting the module. These
|
||||
* parameters define how the DWC_otg controller should be configured. A
|
||||
* value of -1 (or any other out of range value) for any parameter means
|
||||
* to read the value from hardware (if possible) or use the builtin
|
||||
* default described above.
|
||||
*/
|
||||
struct dwc2_core_params {
|
||||
/*
|
||||
* Don't add any non-int members here, this will break
|
||||
* dwc2_set_all_params!
|
||||
*/
|
||||
int otg_cap;
|
||||
int otg_ver;
|
||||
int dma_enable;
|
||||
int dma_desc_enable;
|
||||
int speed;
|
||||
int enable_dynamic_fifo;
|
||||
int en_multiple_tx_fifo;
|
||||
int host_rx_fifo_size;
|
||||
int host_nperio_tx_fifo_size;
|
||||
int host_perio_tx_fifo_size;
|
||||
int max_transfer_size;
|
||||
int max_packet_count;
|
||||
int host_channels;
|
||||
int phy_type;
|
||||
int phy_utmi_width;
|
||||
int phy_ulpi_ddr;
|
||||
int phy_ulpi_ext_vbus;
|
||||
int i2c_enable;
|
||||
int ulpi_fs_ls;
|
||||
int host_support_fs_ls_low_power;
|
||||
int host_ls_low_power_phy_clk;
|
||||
int ts_dline;
|
||||
int reload_ctl;
|
||||
int ahbcfg;
|
||||
int uframe_sched;
|
||||
};
|
||||
|
||||
/**
|
||||
* struct dwc2_hw_params - Autodetected parameters.
|
||||
*
|
||||
* These parameters are the various parameters read from hardware
|
||||
* registers during initialization. They typically contain the best
|
||||
* supported or maximum value that can be configured in the
|
||||
* corresponding dwc2_core_params value.
|
||||
*
|
||||
* The values that are not in dwc2_core_params are documented below.
|
||||
*
|
||||
* @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)
|
||||
* 3 - SRP-Capable Device
|
||||
* 4 - Non-OTG Device
|
||||
* 5 - SRP-Capable Host
|
||||
* 6 - Non-OTG Host
|
||||
* @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_perio_in_ep Number of device periodic IN endpoints
|
||||
* avaialable
|
||||
* @dev_token_q_depth Device Mode IN Token Sequence Learning Queue
|
||||
* Depth
|
||||
* 0 to 30
|
||||
* @host_perio_tx_q_depth
|
||||
* Host Mode Periodic Request Queue Depth
|
||||
* 2, 4 or 8
|
||||
* @nperio_tx_q_depth
|
||||
* Non-Periodic Request Queue Depth
|
||||
* 2, 4 or 8
|
||||
* @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
|
||||
* 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)
|
||||
* @utmi_phy_data_width UTMI+ PHY data width
|
||||
* 0 - 8 bits
|
||||
* 1 - 16 bits
|
||||
* 2 - 8 or 16 bits
|
||||
* @snpsid: Value from SNPSID register
|
||||
*/
|
||||
struct dwc2_hw_params {
|
||||
unsigned op_mode:3;
|
||||
unsigned arch:2;
|
||||
unsigned dma_desc_enable:1;
|
||||
unsigned enable_dynamic_fifo:1;
|
||||
unsigned en_multiple_tx_fifo:1;
|
||||
unsigned host_rx_fifo_size:16;
|
||||
unsigned host_nperio_tx_fifo_size:16;
|
||||
unsigned host_perio_tx_fifo_size:16;
|
||||
unsigned nperio_tx_q_depth:3;
|
||||
unsigned host_perio_tx_q_depth:3;
|
||||
unsigned dev_token_q_depth:5;
|
||||
unsigned max_transfer_size:26;
|
||||
unsigned max_packet_count:11;
|
||||
unsigned host_channels:5;
|
||||
unsigned hs_phy_type:2;
|
||||
unsigned fs_phy_type:2;
|
||||
unsigned i2c_enable:1;
|
||||
unsigned num_dev_ep:4;
|
||||
unsigned num_dev_perio_in_ep:4;
|
||||
unsigned total_fifo_size:16;
|
||||
unsigned power_optimized:1;
|
||||
unsigned utmi_phy_data_width:2;
|
||||
u32 snpsid;
|
||||
};
|
||||
|
||||
/**
|
||||
* struct dwc2_hsotg - Holds the state of the driver, including the non-periodic
|
||||
* and periodic schedules
|
||||
*
|
||||
* @dev: The struct device pointer
|
||||
* @regs: Pointer to controller regs
|
||||
* @core_params: Parameters that define how the core should be configured
|
||||
* @hw_params: Parameters that were autodetected from the
|
||||
* hardware registers
|
||||
* @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
|
||||
* transitions
|
||||
* @queuing_high_bandwidth: True if multiple packets of a high-bandwidth
|
||||
* transfer are in process of being queued
|
||||
* @srp_success: Stores status of SRP request in the case of a FS PHY
|
||||
* with an I2C interface
|
||||
* @wq_otg: Workqueue object used for handling of some interrupts
|
||||
* @wf_otg: Work object for handling Connector ID Status Change
|
||||
* interrupt
|
||||
* @wkp_timer: Timer object for handling Wakeup Detected interrupt
|
||||
* @lx_state: Lx state of connected device
|
||||
* @flags: Flags for handling root port state changes
|
||||
* @non_periodic_sched_inactive: Inactive QHs in the non-periodic schedule.
|
||||
* Transfers associated with these QHs are not currently
|
||||
* assigned to a host channel.
|
||||
* @non_periodic_sched_active: Active QHs in the non-periodic schedule.
|
||||
* Transfers associated with these QHs are currently
|
||||
* assigned to a host channel.
|
||||
* @non_periodic_qh_ptr: Pointer to next QH to process in the active
|
||||
* non-periodic schedule
|
||||
* @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
|
||||
* interval counter that determines when it needs to be
|
||||
* scheduled for execution. This scheduling mechanism
|
||||
* allows only a simple calculation for periodic bandwidth
|
||||
* used (i.e. must assume that all periodic transfers may
|
||||
* need to execute in the same frame). However, it greatly
|
||||
* simplifies scheduling and should be sufficient for the
|
||||
* vast majority of OTG hosts, which need to connect to a
|
||||
* small number of peripherals at one time. Items move from
|
||||
* this list to periodic_sched_ready when the QH interval
|
||||
* counter is 0 at SOF.
|
||||
* @periodic_sched_ready: List of periodic QHs that are ready for execution in
|
||||
* the next frame, but have not yet been assigned to host
|
||||
* channels. Items move from this list to
|
||||
* periodic_sched_assigned as host channels become
|
||||
* available during the current frame.
|
||||
* @periodic_sched_assigned: List of periodic QHs to be executed in the next
|
||||
* frame that are assigned to host channels. Items move
|
||||
* from this list to periodic_sched_queued as the
|
||||
* transactions for the QH are queued to the DWC_otg
|
||||
* controller.
|
||||
* @periodic_sched_queued: List of periodic QHs that have been queued for
|
||||
* execution. Items move from this list to either
|
||||
* periodic_sched_inactive or periodic_sched_ready when the
|
||||
* channel associated with the transfer is released. If the
|
||||
* interval for the QH is 1, the item moves to
|
||||
* periodic_sched_ready because it must be rescheduled for
|
||||
* the next frame. Otherwise, the item moves to
|
||||
* periodic_sched_inactive.
|
||||
* @periodic_usecs: Total bandwidth claimed so far for periodic transfers.
|
||||
* This value is in microseconds per (micro)frame. The
|
||||
* assumption is that all periodic transfers may occur in
|
||||
* the same (micro)frame.
|
||||
* @frame_usecs: Internal variable used by the microframe scheduler
|
||||
* @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
|
||||
* struct dwc2_host_chan items.
|
||||
* @periodic_channels: Number of host channels assigned to periodic transfers.
|
||||
* Currently assuming that there is a dedicated host
|
||||
* channel for each periodic transaction and at least one
|
||||
* 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
|
||||
* @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
|
||||
* handlers.
|
||||
* @status_buf: Buffer used for data received during the status phase of
|
||||
* a control transfer.
|
||||
* @status_buf_dma: DMA address for status_buf
|
||||
* @start_work: Delayed work for handling host A-cable connection
|
||||
* @reset_work: Delayed work for handling a port reset
|
||||
* @lock: Spinlock that protects all the driver data structures
|
||||
* @priv: Stores a pointer to the struct usb_hcd
|
||||
* @otg_port: OTG port number
|
||||
* @frame_list: Frame list
|
||||
* @frame_list_dma: Frame list DMA address
|
||||
*/
|
||||
struct dwc2_hsotg {
|
||||
struct device *dev;
|
||||
void __iomem *regs;
|
||||
/** Params detected from hardware */
|
||||
struct dwc2_hw_params hw_params;
|
||||
/** Params to actually use */
|
||||
struct dwc2_core_params *core_params;
|
||||
enum usb_otg_state op_state;
|
||||
|
||||
unsigned int queuing_high_bandwidth:1;
|
||||
unsigned int srp_success:1;
|
||||
|
||||
struct workqueue_struct *wq_otg;
|
||||
struct work_struct wf_otg;
|
||||
struct timer_list wkp_timer;
|
||||
enum dwc2_lx_state lx_state;
|
||||
|
||||
union dwc2_hcd_internal_flags {
|
||||
u32 d32;
|
||||
struct {
|
||||
unsigned port_connect_status_change:1;
|
||||
unsigned port_connect_status:1;
|
||||
unsigned port_reset_change:1;
|
||||
unsigned port_enable_change:1;
|
||||
unsigned port_suspend_change:1;
|
||||
unsigned port_over_current_change:1;
|
||||
unsigned port_l1_change:1;
|
||||
unsigned reserved:26;
|
||||
} b;
|
||||
} flags;
|
||||
|
||||
struct list_head non_periodic_sched_inactive;
|
||||
struct list_head non_periodic_sched_active;
|
||||
struct list_head *non_periodic_qh_ptr;
|
||||
struct list_head periodic_sched_inactive;
|
||||
struct list_head periodic_sched_ready;
|
||||
struct list_head periodic_sched_assigned;
|
||||
struct list_head periodic_sched_queued;
|
||||
u16 periodic_usecs;
|
||||
u16 frame_usecs[8];
|
||||
u16 frame_number;
|
||||
u16 periodic_qh_count;
|
||||
|
||||
#ifdef CONFIG_USB_DWC2_TRACK_MISSED_SOFS
|
||||
#define FRAME_NUM_ARRAY_SIZE 1000
|
||||
u16 last_frame_num;
|
||||
u16 *frame_num_array;
|
||||
u16 *last_frame_num_array;
|
||||
int frame_num_idx;
|
||||
int dumped_frame_num_array;
|
||||
#endif
|
||||
|
||||
struct list_head free_hc_list;
|
||||
int periodic_channels;
|
||||
int non_periodic_channels;
|
||||
int available_host_channels;
|
||||
struct dwc2_host_chan *hc_ptr_array[MAX_EPS_CHANNELS];
|
||||
u8 *status_buf;
|
||||
dma_addr_t status_buf_dma;
|
||||
#define DWC2_HCD_STATUS_BUF_SIZE 64
|
||||
|
||||
struct delayed_work start_work;
|
||||
struct delayed_work reset_work;
|
||||
spinlock_t lock;
|
||||
void *priv;
|
||||
u8 otg_port;
|
||||
u32 *frame_list;
|
||||
dma_addr_t frame_list_dma;
|
||||
|
||||
/* DWC OTG HW Release versions */
|
||||
#define DWC2_CORE_REV_2_71a 0x4f54271a
|
||||
#define DWC2_CORE_REV_2_90a 0x4f54290a
|
||||
#define DWC2_CORE_REV_2_92a 0x4f54292a
|
||||
#define DWC2_CORE_REV_2_94a 0x4f54294a
|
||||
#define DWC2_CORE_REV_3_00a 0x4f54300a
|
||||
|
||||
#ifdef DEBUG
|
||||
u32 frrem_samples;
|
||||
u64 frrem_accum;
|
||||
|
||||
u32 hfnum_7_samples_a;
|
||||
u64 hfnum_7_frrem_accum_a;
|
||||
u32 hfnum_0_samples_a;
|
||||
u64 hfnum_0_frrem_accum_a;
|
||||
u32 hfnum_other_samples_a;
|
||||
u64 hfnum_other_frrem_accum_a;
|
||||
|
||||
u32 hfnum_7_samples_b;
|
||||
u64 hfnum_7_frrem_accum_b;
|
||||
u32 hfnum_0_samples_b;
|
||||
u64 hfnum_0_frrem_accum_b;
|
||||
u32 hfnum_other_samples_b;
|
||||
u64 hfnum_other_frrem_accum_b;
|
||||
#endif
|
||||
};
|
||||
|
||||
/* Reasons for halting a host channel */
|
||||
enum dwc2_halt_status {
|
||||
DWC2_HC_XFER_NO_HALT_STATUS,
|
||||
DWC2_HC_XFER_COMPLETE,
|
||||
DWC2_HC_XFER_URB_COMPLETE,
|
||||
DWC2_HC_XFER_ACK,
|
||||
DWC2_HC_XFER_NAK,
|
||||
DWC2_HC_XFER_NYET,
|
||||
DWC2_HC_XFER_STALL,
|
||||
DWC2_HC_XFER_XACT_ERR,
|
||||
DWC2_HC_XFER_FRAME_OVERRUN,
|
||||
DWC2_HC_XFER_BABBLE_ERR,
|
||||
DWC2_HC_XFER_DATA_TOGGLE_ERR,
|
||||
DWC2_HC_XFER_AHB_ERR,
|
||||
DWC2_HC_XFER_PERIODIC_INCOMPLETE,
|
||||
DWC2_HC_XFER_URB_DEQUEUE,
|
||||
};
|
||||
|
||||
/*
|
||||
* The following functions support initialization of the core driver component
|
||||
* and the DWC_otg controller
|
||||
*/
|
||||
extern void dwc2_core_host_init(struct dwc2_hsotg *hsotg);
|
||||
|
||||
/*
|
||||
* Host core Functions.
|
||||
* The following functions support managing the DWC_otg controller in host
|
||||
* mode.
|
||||
*/
|
||||
extern void dwc2_hc_init(struct dwc2_hsotg *hsotg, struct dwc2_host_chan *chan);
|
||||
extern void dwc2_hc_halt(struct dwc2_hsotg *hsotg, struct dwc2_host_chan *chan,
|
||||
enum dwc2_halt_status halt_status);
|
||||
extern void dwc2_hc_cleanup(struct dwc2_hsotg *hsotg,
|
||||
struct dwc2_host_chan *chan);
|
||||
extern void dwc2_hc_start_transfer(struct dwc2_hsotg *hsotg,
|
||||
struct dwc2_host_chan *chan);
|
||||
extern void dwc2_hc_start_transfer_ddma(struct dwc2_hsotg *hsotg,
|
||||
struct dwc2_host_chan *chan);
|
||||
extern int dwc2_hc_continue_transfer(struct dwc2_hsotg *hsotg,
|
||||
struct dwc2_host_chan *chan);
|
||||
extern void dwc2_hc_do_ping(struct dwc2_hsotg *hsotg,
|
||||
struct dwc2_host_chan *chan);
|
||||
extern void dwc2_enable_host_interrupts(struct dwc2_hsotg *hsotg);
|
||||
extern void dwc2_disable_host_interrupts(struct dwc2_hsotg *hsotg);
|
||||
|
||||
extern u32 dwc2_calc_frame_interval(struct dwc2_hsotg *hsotg);
|
||||
extern bool dwc2_is_controller_alive(struct dwc2_hsotg *hsotg);
|
||||
|
||||
/*
|
||||
* Common core Functions.
|
||||
* The following functions support managing the DWC_otg controller in either
|
||||
* device or host mode.
|
||||
*/
|
||||
extern void dwc2_read_packet(struct dwc2_hsotg *hsotg, u8 *dest, u16 bytes);
|
||||
extern void dwc2_flush_tx_fifo(struct dwc2_hsotg *hsotg, const int num);
|
||||
extern void dwc2_flush_rx_fifo(struct dwc2_hsotg *hsotg);
|
||||
|
||||
extern int dwc2_core_init(struct dwc2_hsotg *hsotg, bool select_phy, int irq);
|
||||
extern void dwc2_enable_global_interrupts(struct dwc2_hsotg *hcd);
|
||||
extern void dwc2_disable_global_interrupts(struct dwc2_hsotg *hcd);
|
||||
|
||||
/* This function should be called on every hardware interrupt. */
|
||||
extern irqreturn_t dwc2_handle_common_intr(int irq, void *dev);
|
||||
|
||||
/* OTG Core Parameters */
|
||||
|
||||
/*
|
||||
* Specifies the OTG capabilities. The driver will automatically
|
||||
* detect the value for this parameter if none is specified.
|
||||
* 0 - HNP and SRP capable (default)
|
||||
* 1 - SRP Only capable
|
||||
* 2 - No HNP/SRP capable
|
||||
*/
|
||||
extern void dwc2_set_param_otg_cap(struct dwc2_hsotg *hsotg, int val);
|
||||
#define DWC2_CAP_PARAM_HNP_SRP_CAPABLE 0
|
||||
#define DWC2_CAP_PARAM_SRP_ONLY_CAPABLE 1
|
||||
#define DWC2_CAP_PARAM_NO_HNP_SRP_CAPABLE 2
|
||||
|
||||
/*
|
||||
* Specifies whether to use slave or DMA mode for accessing the data
|
||||
* FIFOs. The driver will automatically detect the value for this
|
||||
* parameter if none is specified.
|
||||
* 0 - Slave
|
||||
* 1 - DMA (default, if available)
|
||||
*/
|
||||
extern void dwc2_set_param_dma_enable(struct dwc2_hsotg *hsotg, int val);
|
||||
|
||||
/*
|
||||
* When DMA mode is enabled specifies whether to use
|
||||
* address DMA or DMA Descritor mode for accessing the data
|
||||
* FIFOs in device mode. The driver will automatically detect
|
||||
* the value for this parameter if none is specified.
|
||||
* 0 - address DMA
|
||||
* 1 - DMA Descriptor(default, if available)
|
||||
*/
|
||||
extern void dwc2_set_param_dma_desc_enable(struct dwc2_hsotg *hsotg, int val);
|
||||
|
||||
/*
|
||||
* Specifies the maximum speed of operation in host and device mode.
|
||||
* The actual speed depends on the speed of the attached device and
|
||||
* the value of phy_type. The actual speed depends on the speed of the
|
||||
* attached device.
|
||||
* 0 - High Speed (default)
|
||||
* 1 - Full Speed
|
||||
*/
|
||||
extern void dwc2_set_param_speed(struct dwc2_hsotg *hsotg, int val);
|
||||
#define DWC2_SPEED_PARAM_HIGH 0
|
||||
#define DWC2_SPEED_PARAM_FULL 1
|
||||
|
||||
/*
|
||||
* Specifies whether low power mode is supported when attached
|
||||
* to a Full Speed or Low Speed device in host mode.
|
||||
*
|
||||
* 0 - Don't support low power mode (default)
|
||||
* 1 - Support low power mode
|
||||
*/
|
||||
extern void dwc2_set_param_host_support_fs_ls_low_power(
|
||||
struct dwc2_hsotg *hsotg, int val);
|
||||
|
||||
/*
|
||||
* Specifies the PHY clock rate in low power mode when connected to a
|
||||
* Low Speed device in host mode. This parameter is applicable only if
|
||||
* HOST_SUPPORT_FS_LS_LOW_POWER is enabled. If PHY_TYPE is set to FS
|
||||
* then defaults to 6 MHZ otherwise 48 MHZ.
|
||||
*
|
||||
* 0 - 48 MHz
|
||||
* 1 - 6 MHz
|
||||
*/
|
||||
extern void dwc2_set_param_host_ls_low_power_phy_clk(struct dwc2_hsotg *hsotg,
|
||||
int val);
|
||||
#define DWC2_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ 0
|
||||
#define DWC2_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ 1
|
||||
|
||||
/*
|
||||
* 0 - Use cC FIFO size parameters
|
||||
* 1 - Allow dynamic FIFO sizing (default)
|
||||
*/
|
||||
extern void dwc2_set_param_enable_dynamic_fifo(struct dwc2_hsotg *hsotg,
|
||||
int val);
|
||||
|
||||
/*
|
||||
* Number of 4-byte words in the Rx FIFO in host mode when dynamic
|
||||
* FIFO sizing is enabled.
|
||||
* 16 to 32768 (default 1024)
|
||||
*/
|
||||
extern void dwc2_set_param_host_rx_fifo_size(struct dwc2_hsotg *hsotg, int val);
|
||||
|
||||
/*
|
||||
* Number of 4-byte words in the non-periodic Tx FIFO in host mode
|
||||
* when Dynamic FIFO sizing is enabled in the core.
|
||||
* 16 to 32768 (default 256)
|
||||
*/
|
||||
extern void dwc2_set_param_host_nperio_tx_fifo_size(struct dwc2_hsotg *hsotg,
|
||||
int val);
|
||||
|
||||
/*
|
||||
* Number of 4-byte words in the host periodic Tx FIFO when dynamic
|
||||
* FIFO sizing is enabled.
|
||||
* 16 to 32768 (default 256)
|
||||
*/
|
||||
extern void dwc2_set_param_host_perio_tx_fifo_size(struct dwc2_hsotg *hsotg,
|
||||
int val);
|
||||
|
||||
/*
|
||||
* The maximum transfer size supported in bytes.
|
||||
* 2047 to 65,535 (default 65,535)
|
||||
*/
|
||||
extern void dwc2_set_param_max_transfer_size(struct dwc2_hsotg *hsotg, int val);
|
||||
|
||||
/*
|
||||
* The maximum number of packets in a transfer.
|
||||
* 15 to 511 (default 511)
|
||||
*/
|
||||
extern void dwc2_set_param_max_packet_count(struct dwc2_hsotg *hsotg, int val);
|
||||
|
||||
/*
|
||||
* The number of host channel registers to use.
|
||||
* 1 to 16 (default 11)
|
||||
* Note: The FPGA configuration supports a maximum of 11 host channels.
|
||||
*/
|
||||
extern void dwc2_set_param_host_channels(struct dwc2_hsotg *hsotg, int val);
|
||||
|
||||
/*
|
||||
* Specifies the type of PHY interface to use. By default, the driver
|
||||
* will automatically detect the phy_type.
|
||||
*
|
||||
* 0 - Full Speed PHY
|
||||
* 1 - UTMI+ (default)
|
||||
* 2 - ULPI
|
||||
*/
|
||||
extern void dwc2_set_param_phy_type(struct dwc2_hsotg *hsotg, int val);
|
||||
#define DWC2_PHY_TYPE_PARAM_FS 0
|
||||
#define DWC2_PHY_TYPE_PARAM_UTMI 1
|
||||
#define DWC2_PHY_TYPE_PARAM_ULPI 2
|
||||
|
||||
/*
|
||||
* Specifies the UTMI+ Data Width. This parameter is
|
||||
* applicable for a PHY_TYPE of UTMI+ or ULPI. (For a ULPI
|
||||
* PHY_TYPE, this parameter indicates the data width between
|
||||
* the MAC and the ULPI Wrapper.) Also, this parameter is
|
||||
* applicable only if the OTG_HSPHY_WIDTH cC parameter was set
|
||||
* to "8 and 16 bits", meaning that the core has been
|
||||
* configured to work at either data path width.
|
||||
*
|
||||
* 8 or 16 bits (default 16)
|
||||
*/
|
||||
extern void dwc2_set_param_phy_utmi_width(struct dwc2_hsotg *hsotg, int val);
|
||||
|
||||
/*
|
||||
* Specifies whether the ULPI operates at double or single
|
||||
* data rate. This parameter is only applicable if PHY_TYPE is
|
||||
* ULPI.
|
||||
*
|
||||
* 0 - single data rate ULPI interface with 8 bit wide data
|
||||
* bus (default)
|
||||
* 1 - double data rate ULPI interface with 4 bit wide data
|
||||
* bus
|
||||
*/
|
||||
extern void dwc2_set_param_phy_ulpi_ddr(struct dwc2_hsotg *hsotg, int val);
|
||||
|
||||
/*
|
||||
* Specifies whether to use the internal or external supply to
|
||||
* drive the vbus with a ULPI phy.
|
||||
*/
|
||||
extern void dwc2_set_param_phy_ulpi_ext_vbus(struct dwc2_hsotg *hsotg, int val);
|
||||
#define DWC2_PHY_ULPI_INTERNAL_VBUS 0
|
||||
#define DWC2_PHY_ULPI_EXTERNAL_VBUS 1
|
||||
|
||||
/*
|
||||
* Specifies whether to use the I2Cinterface for full speed PHY. This
|
||||
* parameter is only applicable if PHY_TYPE is FS.
|
||||
* 0 - No (default)
|
||||
* 1 - Yes
|
||||
*/
|
||||
extern void dwc2_set_param_i2c_enable(struct dwc2_hsotg *hsotg, int val);
|
||||
|
||||
extern void dwc2_set_param_ulpi_fs_ls(struct dwc2_hsotg *hsotg, int val);
|
||||
|
||||
extern void dwc2_set_param_ts_dline(struct dwc2_hsotg *hsotg, int val);
|
||||
|
||||
/*
|
||||
* Specifies whether dedicated transmit FIFOs are
|
||||
* enabled for non periodic IN endpoints in device mode
|
||||
* 0 - No
|
||||
* 1 - Yes
|
||||
*/
|
||||
extern void dwc2_set_param_en_multiple_tx_fifo(struct dwc2_hsotg *hsotg,
|
||||
int val);
|
||||
|
||||
extern void dwc2_set_param_reload_ctl(struct dwc2_hsotg *hsotg, int val);
|
||||
|
||||
extern void dwc2_set_param_ahbcfg(struct dwc2_hsotg *hsotg, int val);
|
||||
|
||||
extern void dwc2_set_param_otg_ver(struct dwc2_hsotg *hsotg, int val);
|
||||
|
||||
/*
|
||||
* Dump core registers and SPRAM
|
||||
*/
|
||||
extern void dwc2_dump_dev_registers(struct dwc2_hsotg *hsotg);
|
||||
extern void dwc2_dump_host_registers(struct dwc2_hsotg *hsotg);
|
||||
extern void dwc2_dump_global_registers(struct dwc2_hsotg *hsotg);
|
||||
|
||||
/*
|
||||
* Return OTG version - either 1.3 or 2.0
|
||||
*/
|
||||
extern u16 dwc2_get_otg_version(struct dwc2_hsotg *hsotg);
|
||||
|
||||
#endif /* __DWC2_CORE_H__ */
|
492
drivers/usb/dwc2/core_intr.c
Normal file
492
drivers/usb/dwc2/core_intr.c
Normal file
@@ -0,0 +1,492 @@
|
||||
/*
|
||||
* core_intr.c - DesignWare HS OTG Controller common interrupt handling
|
||||
*
|
||||
* Copyright (C) 2004-2013 Synopsys, Inc.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions, and the following disclaimer,
|
||||
* without modification.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. The names of the above-listed copyright holders may not be used
|
||||
* to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* ALTERNATIVELY, this software may be distributed under the terms of the
|
||||
* GNU General Public License ("GPL") as published by the Free Software
|
||||
* Foundation; either version 2 of the License, or (at your option) any
|
||||
* later version.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This file contains the common interrupt handlers
|
||||
*/
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/moduleparam.h>
|
||||
#include <linux/spinlock.h>
|
||||
#include <linux/interrupt.h>
|
||||
#include <linux/dma-mapping.h>
|
||||
#include <linux/io.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/usb.h>
|
||||
|
||||
#include <linux/usb/hcd.h>
|
||||
#include <linux/usb/ch11.h>
|
||||
|
||||
#include "core.h"
|
||||
#include "hcd.h"
|
||||
|
||||
static const char *dwc2_op_state_str(struct dwc2_hsotg *hsotg)
|
||||
{
|
||||
switch (hsotg->op_state) {
|
||||
case OTG_STATE_A_HOST:
|
||||
return "a_host";
|
||||
case OTG_STATE_A_SUSPEND:
|
||||
return "a_suspend";
|
||||
case OTG_STATE_A_PERIPHERAL:
|
||||
return "a_peripheral";
|
||||
case OTG_STATE_B_PERIPHERAL:
|
||||
return "b_peripheral";
|
||||
case OTG_STATE_B_HOST:
|
||||
return "b_host";
|
||||
default:
|
||||
return "unknown";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* dwc2_handle_mode_mismatch_intr() - Logs a mode mismatch warning message
|
||||
*
|
||||
* @hsotg: Programming view of DWC_otg controller
|
||||
*/
|
||||
static void dwc2_handle_mode_mismatch_intr(struct dwc2_hsotg *hsotg)
|
||||
{
|
||||
dev_warn(hsotg->dev, "Mode Mismatch Interrupt: currently in %s mode\n",
|
||||
dwc2_is_host_mode(hsotg) ? "Host" : "Device");
|
||||
|
||||
/* Clear interrupt */
|
||||
writel(GINTSTS_MODEMIS, hsotg->regs + GINTSTS);
|
||||
}
|
||||
|
||||
/**
|
||||
* dwc2_handle_otg_intr() - Handles the OTG Interrupts. It reads the OTG
|
||||
* Interrupt Register (GOTGINT) to determine what interrupt has occurred.
|
||||
*
|
||||
* @hsotg: Programming view of DWC_otg controller
|
||||
*/
|
||||
static void dwc2_handle_otg_intr(struct dwc2_hsotg *hsotg)
|
||||
{
|
||||
u32 gotgint;
|
||||
u32 gotgctl;
|
||||
u32 gintmsk;
|
||||
|
||||
gotgint = readl(hsotg->regs + GOTGINT);
|
||||
gotgctl = readl(hsotg->regs + GOTGCTL);
|
||||
dev_dbg(hsotg->dev, "++OTG Interrupt gotgint=%0x [%s]\n", gotgint,
|
||||
dwc2_op_state_str(hsotg));
|
||||
|
||||
if (gotgint & GOTGINT_SES_END_DET) {
|
||||
dev_dbg(hsotg->dev,
|
||||
" ++OTG Interrupt: Session End Detected++ (%s)\n",
|
||||
dwc2_op_state_str(hsotg));
|
||||
gotgctl = readl(hsotg->regs + GOTGCTL);
|
||||
|
||||
if (hsotg->op_state == OTG_STATE_B_HOST) {
|
||||
hsotg->op_state = OTG_STATE_B_PERIPHERAL;
|
||||
} else {
|
||||
/*
|
||||
* If not B_HOST and Device HNP still set, HNP did
|
||||
* not succeed!
|
||||
*/
|
||||
if (gotgctl & GOTGCTL_DEVHNPEN) {
|
||||
dev_dbg(hsotg->dev, "Session End Detected\n");
|
||||
dev_err(hsotg->dev,
|
||||
"Device Not Connected/Responding!\n");
|
||||
}
|
||||
|
||||
/*
|
||||
* If Session End Detected the B-Cable has been
|
||||
* disconnected
|
||||
*/
|
||||
/* Reset to a clean state */
|
||||
hsotg->lx_state = DWC2_L0;
|
||||
}
|
||||
|
||||
gotgctl = readl(hsotg->regs + GOTGCTL);
|
||||
gotgctl &= ~GOTGCTL_DEVHNPEN;
|
||||
writel(gotgctl, hsotg->regs + GOTGCTL);
|
||||
}
|
||||
|
||||
if (gotgint & GOTGINT_SES_REQ_SUC_STS_CHNG) {
|
||||
dev_dbg(hsotg->dev,
|
||||
" ++OTG Interrupt: Session Request Success Status Change++\n");
|
||||
gotgctl = readl(hsotg->regs + GOTGCTL);
|
||||
if (gotgctl & GOTGCTL_SESREQSCS) {
|
||||
if (hsotg->core_params->phy_type ==
|
||||
DWC2_PHY_TYPE_PARAM_FS
|
||||
&& hsotg->core_params->i2c_enable > 0) {
|
||||
hsotg->srp_success = 1;
|
||||
} else {
|
||||
/* Clear Session Request */
|
||||
gotgctl = readl(hsotg->regs + GOTGCTL);
|
||||
gotgctl &= ~GOTGCTL_SESREQ;
|
||||
writel(gotgctl, hsotg->regs + GOTGCTL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (gotgint & GOTGINT_HST_NEG_SUC_STS_CHNG) {
|
||||
/*
|
||||
* Print statements during the HNP interrupt handling
|
||||
* can cause it to fail
|
||||
*/
|
||||
gotgctl = readl(hsotg->regs + GOTGCTL);
|
||||
/*
|
||||
* WA for 3.00a- HW is not setting cur_mode, even sometimes
|
||||
* this does not help
|
||||
*/
|
||||
if (hsotg->hw_params.snpsid >= DWC2_CORE_REV_3_00a)
|
||||
udelay(100);
|
||||
if (gotgctl & GOTGCTL_HSTNEGSCS) {
|
||||
if (dwc2_is_host_mode(hsotg)) {
|
||||
hsotg->op_state = OTG_STATE_B_HOST;
|
||||
/*
|
||||
* Need to disable SOF interrupt immediately.
|
||||
* When switching from device to host, the PCD
|
||||
* interrupt handler won't handle the interrupt
|
||||
* if host mode is already set. The HCD
|
||||
* interrupt handler won't get called if the
|
||||
* HCD state is HALT. This means that the
|
||||
* interrupt does not get handled and Linux
|
||||
* complains loudly.
|
||||
*/
|
||||
gintmsk = readl(hsotg->regs + GINTMSK);
|
||||
gintmsk &= ~GINTSTS_SOF;
|
||||
writel(gintmsk, hsotg->regs + GINTMSK);
|
||||
|
||||
/*
|
||||
* Call callback function with spin lock
|
||||
* released
|
||||
*/
|
||||
spin_unlock(&hsotg->lock);
|
||||
|
||||
/* Initialize the Core for Host mode */
|
||||
dwc2_hcd_start(hsotg);
|
||||
spin_lock(&hsotg->lock);
|
||||
hsotg->op_state = OTG_STATE_B_HOST;
|
||||
}
|
||||
} else {
|
||||
gotgctl = readl(hsotg->regs + GOTGCTL);
|
||||
gotgctl &= ~(GOTGCTL_HNPREQ | GOTGCTL_DEVHNPEN);
|
||||
writel(gotgctl, hsotg->regs + GOTGCTL);
|
||||
dev_dbg(hsotg->dev, "HNP Failed\n");
|
||||
dev_err(hsotg->dev,
|
||||
"Device Not Connected/Responding\n");
|
||||
}
|
||||
}
|
||||
|
||||
if (gotgint & GOTGINT_HST_NEG_DET) {
|
||||
/*
|
||||
* The disconnect interrupt is set at the same time as
|
||||
* Host Negotiation Detected. During the mode switch all
|
||||
* interrupts are cleared so the disconnect interrupt
|
||||
* handler will not get executed.
|
||||
*/
|
||||
dev_dbg(hsotg->dev,
|
||||
" ++OTG Interrupt: Host Negotiation Detected++ (%s)\n",
|
||||
(dwc2_is_host_mode(hsotg) ? "Host" : "Device"));
|
||||
if (dwc2_is_device_mode(hsotg)) {
|
||||
dev_dbg(hsotg->dev, "a_suspend->a_peripheral (%d)\n",
|
||||
hsotg->op_state);
|
||||
spin_unlock(&hsotg->lock);
|
||||
dwc2_hcd_disconnect(hsotg);
|
||||
spin_lock(&hsotg->lock);
|
||||
hsotg->op_state = OTG_STATE_A_PERIPHERAL;
|
||||
} else {
|
||||
/* Need to disable SOF interrupt immediately */
|
||||
gintmsk = readl(hsotg->regs + GINTMSK);
|
||||
gintmsk &= ~GINTSTS_SOF;
|
||||
writel(gintmsk, hsotg->regs + GINTMSK);
|
||||
spin_unlock(&hsotg->lock);
|
||||
dwc2_hcd_start(hsotg);
|
||||
spin_lock(&hsotg->lock);
|
||||
hsotg->op_state = OTG_STATE_A_HOST;
|
||||
}
|
||||
}
|
||||
|
||||
if (gotgint & GOTGINT_A_DEV_TOUT_CHG)
|
||||
dev_dbg(hsotg->dev,
|
||||
" ++OTG Interrupt: A-Device Timeout Change++\n");
|
||||
if (gotgint & GOTGINT_DBNCE_DONE)
|
||||
dev_dbg(hsotg->dev, " ++OTG Interrupt: Debounce Done++\n");
|
||||
|
||||
/* Clear GOTGINT */
|
||||
writel(gotgint, hsotg->regs + GOTGINT);
|
||||
}
|
||||
|
||||
/**
|
||||
* dwc2_handle_conn_id_status_change_intr() - Handles the Connector ID Status
|
||||
* Change Interrupt
|
||||
*
|
||||
* @hsotg: Programming view of DWC_otg controller
|
||||
*
|
||||
* Reads the OTG Interrupt Register (GOTCTL) to determine whether this is a
|
||||
* Device to Host Mode transition or a Host to Device Mode transition. This only
|
||||
* occurs when the cable is connected/removed from the PHY connector.
|
||||
*/
|
||||
static void dwc2_handle_conn_id_status_change_intr(struct dwc2_hsotg *hsotg)
|
||||
{
|
||||
u32 gintmsk = readl(hsotg->regs + GINTMSK);
|
||||
|
||||
/* Need to disable SOF interrupt immediately */
|
||||
gintmsk &= ~GINTSTS_SOF;
|
||||
writel(gintmsk, hsotg->regs + GINTMSK);
|
||||
|
||||
dev_dbg(hsotg->dev, " ++Connector ID Status Change Interrupt++ (%s)\n",
|
||||
dwc2_is_host_mode(hsotg) ? "Host" : "Device");
|
||||
|
||||
/*
|
||||
* Need to schedule a work, as there are possible DELAY function calls.
|
||||
* Release lock before scheduling workq as it holds spinlock during
|
||||
* scheduling.
|
||||
*/
|
||||
spin_unlock(&hsotg->lock);
|
||||
queue_work(hsotg->wq_otg, &hsotg->wf_otg);
|
||||
spin_lock(&hsotg->lock);
|
||||
|
||||
/* Clear interrupt */
|
||||
writel(GINTSTS_CONIDSTSCHNG, hsotg->regs + GINTSTS);
|
||||
}
|
||||
|
||||
/**
|
||||
* dwc2_handle_session_req_intr() - This interrupt indicates that a device is
|
||||
* initiating the Session Request Protocol to request the host to turn on bus
|
||||
* power so a new session can begin
|
||||
*
|
||||
* @hsotg: Programming view of DWC_otg controller
|
||||
*
|
||||
* This handler responds by turning on bus power. If the DWC_otg controller is
|
||||
* in low power mode, this handler brings the controller out of low power mode
|
||||
* before turning on bus power.
|
||||
*/
|
||||
static void dwc2_handle_session_req_intr(struct dwc2_hsotg *hsotg)
|
||||
{
|
||||
dev_dbg(hsotg->dev, "++Session Request Interrupt++\n");
|
||||
|
||||
/* Clear interrupt */
|
||||
writel(GINTSTS_SESSREQINT, hsotg->regs + GINTSTS);
|
||||
}
|
||||
|
||||
/*
|
||||
* This interrupt indicates that the DWC_otg controller has detected a
|
||||
* resume or remote wakeup sequence. If the DWC_otg controller is in
|
||||
* low power mode, the handler must brings the controller out of low
|
||||
* power mode. The controller automatically begins resume signaling.
|
||||
* The handler schedules a time to stop resume signaling.
|
||||
*/
|
||||
static void dwc2_handle_wakeup_detected_intr(struct dwc2_hsotg *hsotg)
|
||||
{
|
||||
dev_dbg(hsotg->dev, "++Resume or Remote Wakeup Detected Interrupt++\n");
|
||||
dev_dbg(hsotg->dev, "%s lxstate = %d\n", __func__, hsotg->lx_state);
|
||||
|
||||
if (dwc2_is_device_mode(hsotg)) {
|
||||
dev_dbg(hsotg->dev, "DSTS=0x%0x\n", readl(hsotg->regs + DSTS));
|
||||
if (hsotg->lx_state == DWC2_L2) {
|
||||
u32 dctl = readl(hsotg->regs + DCTL);
|
||||
|
||||
/* Clear Remote Wakeup Signaling */
|
||||
dctl &= ~DCTL_RMTWKUPSIG;
|
||||
writel(dctl, hsotg->regs + DCTL);
|
||||
}
|
||||
/* Change to L0 state */
|
||||
hsotg->lx_state = DWC2_L0;
|
||||
} else {
|
||||
if (hsotg->lx_state != DWC2_L1) {
|
||||
u32 pcgcctl = readl(hsotg->regs + PCGCTL);
|
||||
|
||||
/* Restart the Phy Clock */
|
||||
pcgcctl &= ~PCGCTL_STOPPCLK;
|
||||
writel(pcgcctl, hsotg->regs + PCGCTL);
|
||||
mod_timer(&hsotg->wkp_timer,
|
||||
jiffies + msecs_to_jiffies(71));
|
||||
} else {
|
||||
/* Change to L0 state */
|
||||
hsotg->lx_state = DWC2_L0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Clear interrupt */
|
||||
writel(GINTSTS_WKUPINT, hsotg->regs + GINTSTS);
|
||||
}
|
||||
|
||||
/*
|
||||
* This interrupt indicates that a device has been disconnected from the
|
||||
* root port
|
||||
*/
|
||||
static void dwc2_handle_disconnect_intr(struct dwc2_hsotg *hsotg)
|
||||
{
|
||||
dev_dbg(hsotg->dev, "++Disconnect Detected Interrupt++ (%s) %s\n",
|
||||
dwc2_is_host_mode(hsotg) ? "Host" : "Device",
|
||||
dwc2_op_state_str(hsotg));
|
||||
|
||||
/* Change to L3 (OFF) state */
|
||||
hsotg->lx_state = DWC2_L3;
|
||||
|
||||
writel(GINTSTS_DISCONNINT, hsotg->regs + GINTSTS);
|
||||
}
|
||||
|
||||
/*
|
||||
* This interrupt indicates that SUSPEND state has been detected on the USB.
|
||||
*
|
||||
* For HNP the USB Suspend interrupt signals the change from "a_peripheral"
|
||||
* to "a_host".
|
||||
*
|
||||
* When power management is enabled the core will be put in low power mode.
|
||||
*/
|
||||
static void dwc2_handle_usb_suspend_intr(struct dwc2_hsotg *hsotg)
|
||||
{
|
||||
u32 dsts;
|
||||
|
||||
dev_dbg(hsotg->dev, "USB SUSPEND\n");
|
||||
|
||||
if (dwc2_is_device_mode(hsotg)) {
|
||||
/*
|
||||
* Check the Device status register to determine if the Suspend
|
||||
* state is active
|
||||
*/
|
||||
dsts = readl(hsotg->regs + DSTS);
|
||||
dev_dbg(hsotg->dev, "DSTS=0x%0x\n", dsts);
|
||||
dev_dbg(hsotg->dev,
|
||||
"DSTS.Suspend Status=%d HWCFG4.Power Optimize=%d\n",
|
||||
!!(dsts & DSTS_SUSPSTS),
|
||||
hsotg->hw_params.power_optimized);
|
||||
} else {
|
||||
if (hsotg->op_state == OTG_STATE_A_PERIPHERAL) {
|
||||
dev_dbg(hsotg->dev, "a_peripheral->a_host\n");
|
||||
|
||||
/* Clear the a_peripheral flag, back to a_host */
|
||||
spin_unlock(&hsotg->lock);
|
||||
dwc2_hcd_start(hsotg);
|
||||
spin_lock(&hsotg->lock);
|
||||
hsotg->op_state = OTG_STATE_A_HOST;
|
||||
}
|
||||
}
|
||||
|
||||
/* Change to L2 (suspend) state */
|
||||
hsotg->lx_state = DWC2_L2;
|
||||
|
||||
/* Clear interrupt */
|
||||
writel(GINTSTS_USBSUSP, hsotg->regs + GINTSTS);
|
||||
}
|
||||
|
||||
#define GINTMSK_COMMON (GINTSTS_WKUPINT | GINTSTS_SESSREQINT | \
|
||||
GINTSTS_CONIDSTSCHNG | GINTSTS_OTGINT | \
|
||||
GINTSTS_MODEMIS | GINTSTS_DISCONNINT | \
|
||||
GINTSTS_USBSUSP | GINTSTS_PRTINT)
|
||||
|
||||
/*
|
||||
* This function returns the Core Interrupt register
|
||||
*/
|
||||
static u32 dwc2_read_common_intr(struct dwc2_hsotg *hsotg)
|
||||
{
|
||||
u32 gintsts;
|
||||
u32 gintmsk;
|
||||
u32 gahbcfg;
|
||||
u32 gintmsk_common = GINTMSK_COMMON;
|
||||
|
||||
gintsts = readl(hsotg->regs + GINTSTS);
|
||||
gintmsk = readl(hsotg->regs + GINTMSK);
|
||||
gahbcfg = readl(hsotg->regs + GAHBCFG);
|
||||
|
||||
/* If any common interrupts set */
|
||||
if (gintsts & gintmsk_common)
|
||||
dev_dbg(hsotg->dev, "gintsts=%08x gintmsk=%08x\n",
|
||||
gintsts, gintmsk);
|
||||
|
||||
if (gahbcfg & GAHBCFG_GLBL_INTR_EN)
|
||||
return gintsts & gintmsk & gintmsk_common;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Common interrupt handler
|
||||
*
|
||||
* The common interrupts are those that occur in both Host and Device mode.
|
||||
* This handler handles the following interrupts:
|
||||
* - Mode Mismatch Interrupt
|
||||
* - OTG Interrupt
|
||||
* - Connector ID Status Change Interrupt
|
||||
* - Disconnect Interrupt
|
||||
* - Session Request Interrupt
|
||||
* - Resume / Remote Wakeup Detected Interrupt
|
||||
* - Suspend Interrupt
|
||||
*/
|
||||
irqreturn_t dwc2_handle_common_intr(int irq, void *dev)
|
||||
{
|
||||
struct dwc2_hsotg *hsotg = dev;
|
||||
u32 gintsts;
|
||||
irqreturn_t retval = IRQ_NONE;
|
||||
|
||||
if (!dwc2_is_controller_alive(hsotg)) {
|
||||
dev_warn(hsotg->dev, "Controller is dead\n");
|
||||
goto out;
|
||||
}
|
||||
|
||||
spin_lock(&hsotg->lock);
|
||||
|
||||
gintsts = dwc2_read_common_intr(hsotg);
|
||||
if (gintsts & ~GINTSTS_PRTINT)
|
||||
retval = IRQ_HANDLED;
|
||||
|
||||
if (gintsts & GINTSTS_MODEMIS)
|
||||
dwc2_handle_mode_mismatch_intr(hsotg);
|
||||
if (gintsts & GINTSTS_OTGINT)
|
||||
dwc2_handle_otg_intr(hsotg);
|
||||
if (gintsts & GINTSTS_CONIDSTSCHNG)
|
||||
dwc2_handle_conn_id_status_change_intr(hsotg);
|
||||
if (gintsts & GINTSTS_DISCONNINT)
|
||||
dwc2_handle_disconnect_intr(hsotg);
|
||||
if (gintsts & GINTSTS_SESSREQINT)
|
||||
dwc2_handle_session_req_intr(hsotg);
|
||||
if (gintsts & GINTSTS_WKUPINT)
|
||||
dwc2_handle_wakeup_detected_intr(hsotg);
|
||||
if (gintsts & GINTSTS_USBSUSP)
|
||||
dwc2_handle_usb_suspend_intr(hsotg);
|
||||
|
||||
if (gintsts & GINTSTS_PRTINT) {
|
||||
/*
|
||||
* The port interrupt occurs while in device mode with HPRT0
|
||||
* Port Enable/Disable
|
||||
*/
|
||||
if (dwc2_is_device_mode(hsotg)) {
|
||||
dev_dbg(hsotg->dev,
|
||||
" --Port interrupt received in Device mode--\n");
|
||||
gintsts = GINTSTS_PRTINT;
|
||||
writel(gintsts, hsotg->regs + GINTSTS);
|
||||
retval = 1;
|
||||
}
|
||||
}
|
||||
|
||||
spin_unlock(&hsotg->lock);
|
||||
out:
|
||||
return retval;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(dwc2_handle_common_intr);
|
2990
drivers/usb/dwc2/hcd.c
Normal file
2990
drivers/usb/dwc2/hcd.c
Normal file
File diff suppressed because it is too large
Load Diff
769
drivers/usb/dwc2/hcd.h
Normal file
769
drivers/usb/dwc2/hcd.h
Normal file
@@ -0,0 +1,769 @@
|
||||
/*
|
||||
* hcd.h - DesignWare HS OTG Controller host-mode declarations
|
||||
*
|
||||
* Copyright (C) 2004-2013 Synopsys, Inc.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions, and the following disclaimer,
|
||||
* without modification.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. The names of the above-listed copyright holders may not be used
|
||||
* to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* ALTERNATIVELY, this software may be distributed under the terms of the
|
||||
* GNU General Public License ("GPL") as published by the Free Software
|
||||
* Foundation; either version 2 of the License, or (at your option) any
|
||||
* later version.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef __DWC2_HCD_H__
|
||||
#define __DWC2_HCD_H__
|
||||
|
||||
/*
|
||||
* This file contains the structures, constants, and interfaces for the
|
||||
* Host Contoller Driver (HCD)
|
||||
*
|
||||
* The Host Controller Driver (HCD) is responsible for translating requests
|
||||
* from the USB Driver into the appropriate actions on the DWC_otg controller.
|
||||
* It isolates the USBD from the specifics of the controller by providing an
|
||||
* API to the USBD.
|
||||
*/
|
||||
|
||||
struct dwc2_qh;
|
||||
|
||||
/**
|
||||
* struct dwc2_host_chan - Software host channel descriptor
|
||||
*
|
||||
* @hc_num: Host channel number, used for register address lookup
|
||||
* @dev_addr: Address of the device
|
||||
* @ep_num: Endpoint of the device
|
||||
* @ep_is_in: Endpoint direction
|
||||
* @speed: Device speed. One of the following values:
|
||||
* - USB_SPEED_LOW
|
||||
* - USB_SPEED_FULL
|
||||
* - USB_SPEED_HIGH
|
||||
* @ep_type: Endpoint type. One of the following values:
|
||||
* - USB_ENDPOINT_XFER_CONTROL: 0
|
||||
* - USB_ENDPOINT_XFER_ISOC: 1
|
||||
* - USB_ENDPOINT_XFER_BULK: 2
|
||||
* - USB_ENDPOINT_XFER_INTR: 3
|
||||
* @max_packet: Max packet size in bytes
|
||||
* @data_pid_start: PID for initial transaction.
|
||||
* 0: DATA0
|
||||
* 1: DATA2
|
||||
* 2: DATA1
|
||||
* 3: MDATA (non-Control EP),
|
||||
* SETUP (Control EP)
|
||||
* @multi_count: Number of additional periodic transactions per
|
||||
* (micro)frame
|
||||
* @xfer_buf: Pointer to current transfer buffer position
|
||||
* @xfer_dma: DMA address of xfer_buf
|
||||
* @align_buf: In Buffer DMA mode this will be used if xfer_buf is not
|
||||
* DWORD aligned
|
||||
* @xfer_len: Total number of bytes to transfer
|
||||
* @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
|
||||
* @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
|
||||
* slave mode if no request queue space is available when
|
||||
* an attempt is made to halt the channel.
|
||||
* @halt_pending: True if the host channel has been halted, but the core
|
||||
* is not finished flushing queued requests
|
||||
* @do_split: Enable split for the channel
|
||||
* @complete_split: Enable complete split
|
||||
* @hub_addr: Address of high speed hub for the split
|
||||
* @hub_port: Port of the low/full speed device for the split
|
||||
* @xact_pos: Split transaction position. One of the following values:
|
||||
* - DWC2_HCSPLT_XACTPOS_MID
|
||||
* - DWC2_HCSPLT_XACTPOS_BEGIN
|
||||
* - DWC2_HCSPLT_XACTPOS_END
|
||||
* - DWC2_HCSPLT_XACTPOS_ALL
|
||||
* @requests: Number of requests issued for this channel since it was
|
||||
* assigned to the current transfer (not counting PINGs)
|
||||
* @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
|
||||
* @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
|
||||
*
|
||||
* This structure represents the state of a single host channel when acting in
|
||||
* host mode. It contains the data items needed to transfer packets to an
|
||||
* endpoint via a host channel.
|
||||
*/
|
||||
struct dwc2_host_chan {
|
||||
u8 hc_num;
|
||||
|
||||
unsigned dev_addr:7;
|
||||
unsigned ep_num:4;
|
||||
unsigned ep_is_in:1;
|
||||
unsigned speed:4;
|
||||
unsigned ep_type:2;
|
||||
unsigned max_packet:11;
|
||||
unsigned data_pid_start:2;
|
||||
#define DWC2_HC_PID_DATA0 TSIZ_SC_MC_PID_DATA0
|
||||
#define DWC2_HC_PID_DATA2 TSIZ_SC_MC_PID_DATA2
|
||||
#define DWC2_HC_PID_DATA1 TSIZ_SC_MC_PID_DATA1
|
||||
#define DWC2_HC_PID_MDATA TSIZ_SC_MC_PID_MDATA
|
||||
#define DWC2_HC_PID_SETUP TSIZ_SC_MC_PID_SETUP
|
||||
|
||||
unsigned multi_count:2;
|
||||
|
||||
u8 *xfer_buf;
|
||||
dma_addr_t xfer_dma;
|
||||
dma_addr_t align_buf;
|
||||
u32 xfer_len;
|
||||
u32 xfer_count;
|
||||
u16 start_pkt_count;
|
||||
u8 xfer_started;
|
||||
u8 do_ping;
|
||||
u8 error_state;
|
||||
u8 halt_on_queue;
|
||||
u8 halt_pending;
|
||||
u8 do_split;
|
||||
u8 complete_split;
|
||||
u8 hub_addr;
|
||||
u8 hub_port;
|
||||
u8 xact_pos;
|
||||
#define DWC2_HCSPLT_XACTPOS_MID HCSPLT_XACTPOS_MID
|
||||
#define DWC2_HCSPLT_XACTPOS_END HCSPLT_XACTPOS_END
|
||||
#define DWC2_HCSPLT_XACTPOS_BEGIN HCSPLT_XACTPOS_BEGIN
|
||||
#define DWC2_HCSPLT_XACTPOS_ALL HCSPLT_XACTPOS_ALL
|
||||
|
||||
u8 requests;
|
||||
u8 schinfo;
|
||||
u16 ntd;
|
||||
enum dwc2_halt_status halt_status;
|
||||
u32 hcint;
|
||||
struct dwc2_qh *qh;
|
||||
struct list_head hc_list_entry;
|
||||
dma_addr_t desc_list_addr;
|
||||
};
|
||||
|
||||
struct dwc2_hcd_pipe_info {
|
||||
u8 dev_addr;
|
||||
u8 ep_num;
|
||||
u8 pipe_type;
|
||||
u8 pipe_dir;
|
||||
u16 mps;
|
||||
};
|
||||
|
||||
struct dwc2_hcd_iso_packet_desc {
|
||||
u32 offset;
|
||||
u32 length;
|
||||
u32 actual_length;
|
||||
u32 status;
|
||||
};
|
||||
|
||||
struct dwc2_qtd;
|
||||
|
||||
struct dwc2_hcd_urb {
|
||||
void *priv;
|
||||
struct dwc2_qtd *qtd;
|
||||
void *buf;
|
||||
dma_addr_t dma;
|
||||
void *setup_packet;
|
||||
dma_addr_t setup_dma;
|
||||
u32 length;
|
||||
u32 actual_length;
|
||||
u32 status;
|
||||
u32 error_count;
|
||||
u32 packet_count;
|
||||
u32 flags;
|
||||
u16 interval;
|
||||
struct dwc2_hcd_pipe_info pipe_info;
|
||||
struct dwc2_hcd_iso_packet_desc iso_descs[0];
|
||||
};
|
||||
|
||||
/* Phases for control transfers */
|
||||
enum dwc2_control_phase {
|
||||
DWC2_CONTROL_SETUP,
|
||||
DWC2_CONTROL_DATA,
|
||||
DWC2_CONTROL_STATUS,
|
||||
};
|
||||
|
||||
/* Transaction types */
|
||||
enum dwc2_transaction_type {
|
||||
DWC2_TRANSACTION_NONE,
|
||||
DWC2_TRANSACTION_PERIODIC,
|
||||
DWC2_TRANSACTION_NON_PERIODIC,
|
||||
DWC2_TRANSACTION_ALL,
|
||||
};
|
||||
|
||||
/**
|
||||
* struct dwc2_qh - Software queue head structure
|
||||
*
|
||||
* @ep_type: Endpoint type. One of the following values:
|
||||
* - USB_ENDPOINT_XFER_CONTROL
|
||||
* - USB_ENDPOINT_XFER_BULK
|
||||
* - USB_ENDPOINT_XFER_INT
|
||||
* - USB_ENDPOINT_XFER_ISOC
|
||||
* @ep_is_in: Endpoint direction
|
||||
* @maxp: Value from wMaxPacketSize field of Endpoint Descriptor
|
||||
* @dev_speed: Device speed. One of the following values:
|
||||
* - USB_SPEED_LOW
|
||||
* - USB_SPEED_FULL
|
||||
* - USB_SPEED_HIGH
|
||||
* @data_toggle: Determines the PID of the next data packet for
|
||||
* non-controltransfers. Ignored for control transfers.
|
||||
* One of the following values:
|
||||
* - DWC2_HC_PID_DATA0
|
||||
* - DWC2_HC_PID_DATA1
|
||||
* @ping_state: Ping state
|
||||
* @do_split: Full/low speed endpoint on high-speed hub requires split
|
||||
* @td_first: Index of first activated isochronous transfer descriptor
|
||||
* @td_last: Index of last activated isochronous transfer descriptor
|
||||
* @usecs: Bandwidth in microseconds per (micro)frame
|
||||
* @interval: Interval between transfers in (micro)frames
|
||||
* @sched_frame: (Micro)frame to initialize a periodic transfer.
|
||||
* The transfer executes in the following (micro)frame.
|
||||
* @frame_usecs: Internal variable used by the microframe scheduler
|
||||
* @start_split_frame: (Micro)frame at which last start split was initialized
|
||||
* @ntd: Actual number of transfer descriptors in a list
|
||||
* @dw_align_buf: Used instead of original buffer if its physical address
|
||||
* is not dword-aligned
|
||||
* @dw_align_buf_dma: DMA address for align_buf
|
||||
* @qtd_list: List of QTDs for this QH
|
||||
* @channel: Host channel currently processing transfers for this QH
|
||||
* @qh_list_entry: Entry for QH in either the periodic or non-periodic
|
||||
* schedule
|
||||
* @desc_list: List of transfer descriptors
|
||||
* @desc_list_dma: Physical address of desc_list
|
||||
* @n_bytes: Xfer Bytes array. Each element corresponds to a transfer
|
||||
* descriptor and indicates original XferSize value for the
|
||||
* descriptor
|
||||
* @tt_buffer_dirty True if clear_tt_buffer_complete is pending
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
struct dwc2_qh {
|
||||
u8 ep_type;
|
||||
u8 ep_is_in;
|
||||
u16 maxp;
|
||||
u8 dev_speed;
|
||||
u8 data_toggle;
|
||||
u8 ping_state;
|
||||
u8 do_split;
|
||||
u8 td_first;
|
||||
u8 td_last;
|
||||
u16 usecs;
|
||||
u16 interval;
|
||||
u16 sched_frame;
|
||||
u16 frame_usecs[8];
|
||||
u16 start_split_frame;
|
||||
u16 ntd;
|
||||
u8 *dw_align_buf;
|
||||
dma_addr_t dw_align_buf_dma;
|
||||
struct list_head qtd_list;
|
||||
struct dwc2_host_chan *channel;
|
||||
struct list_head qh_list_entry;
|
||||
struct dwc2_hcd_dma_desc *desc_list;
|
||||
dma_addr_t desc_list_dma;
|
||||
u32 *n_bytes;
|
||||
unsigned tt_buffer_dirty:1;
|
||||
};
|
||||
|
||||
/**
|
||||
* struct dwc2_qtd - Software queue transfer descriptor (QTD)
|
||||
*
|
||||
* @control_phase: Current phase for control transfers (Setup, Data, or
|
||||
* Status)
|
||||
* @in_process: Indicates if this QTD is currently processed by HW
|
||||
* @data_toggle: Determines the PID of the next data packet for the
|
||||
* data phase of control transfers. Ignored for other
|
||||
* transfer types. One of the following values:
|
||||
* - DWC2_HC_PID_DATA0
|
||||
* - DWC2_HC_PID_DATA1
|
||||
* @complete_split: Keeps track of the current split type for FS/LS
|
||||
* endpoints on a HS Hub
|
||||
* @isoc_split_pos: Position of the ISOC split in full/low speed
|
||||
* @isoc_frame_index: Index of the next frame descriptor for an isochronous
|
||||
* transfer. A frame descriptor describes the buffer
|
||||
* position and length of the data to be transferred in the
|
||||
* next scheduled (micro)frame of an isochronous transfer.
|
||||
* It also holds status for that transaction. The frame
|
||||
* index starts at 0.
|
||||
* @isoc_split_offset: Position of the ISOC split in the buffer for the
|
||||
* current frame
|
||||
* @ssplit_out_xfer_count: How many bytes transferred during SSPLIT OUT
|
||||
* @error_count: Holds the number of bus errors that have occurred for
|
||||
* a transaction within this transfer
|
||||
* @n_desc: Number of DMA descriptors for this QTD
|
||||
* @isoc_frame_index_last: Last activated frame (packet) index, used in
|
||||
* descriptor DMA mode only
|
||||
* @urb: URB for this transfer
|
||||
* @qh: Queue head for this QTD
|
||||
* @qtd_list_entry: For linking to the QH's list of QTDs
|
||||
*
|
||||
* A Queue Transfer Descriptor (QTD) holds the state of a bulk, control,
|
||||
* interrupt, or isochronous transfer. A single QTD is created for each URB
|
||||
* (of one of these types) submitted to the HCD. The transfer associated with
|
||||
* a QTD may require one or multiple transactions.
|
||||
*
|
||||
* A QTD is linked to a Queue Head, which is entered in either the
|
||||
* non-periodic or periodic schedule for execution. When a QTD is chosen for
|
||||
* execution, some or all of its transactions may be executed. After
|
||||
* execution, the state of the QTD is updated. The QTD may be retired if all
|
||||
* its transactions are complete or if an error occurred. Otherwise, it
|
||||
* remains in the schedule so more transactions can be executed later.
|
||||
*/
|
||||
struct dwc2_qtd {
|
||||
enum dwc2_control_phase control_phase;
|
||||
u8 in_process;
|
||||
u8 data_toggle;
|
||||
u8 complete_split;
|
||||
u8 isoc_split_pos;
|
||||
u16 isoc_frame_index;
|
||||
u16 isoc_split_offset;
|
||||
u32 ssplit_out_xfer_count;
|
||||
u8 error_count;
|
||||
u8 n_desc;
|
||||
u16 isoc_frame_index_last;
|
||||
struct dwc2_hcd_urb *urb;
|
||||
struct dwc2_qh *qh;
|
||||
struct list_head qtd_list_entry;
|
||||
};
|
||||
|
||||
#ifdef DEBUG
|
||||
struct hc_xfer_info {
|
||||
struct dwc2_hsotg *hsotg;
|
||||
struct dwc2_host_chan *chan;
|
||||
};
|
||||
#endif
|
||||
|
||||
/* Gets the struct usb_hcd that contains a struct dwc2_hsotg */
|
||||
static inline struct usb_hcd *dwc2_hsotg_to_hcd(struct dwc2_hsotg *hsotg)
|
||||
{
|
||||
return (struct usb_hcd *)hsotg->priv;
|
||||
}
|
||||
|
||||
/*
|
||||
* Inline used to disable one channel interrupt. Channel interrupts are
|
||||
* disabled when the channel is halted or released by the interrupt handler.
|
||||
* There is no need to handle further interrupts of that type until the
|
||||
* channel is re-assigned. In fact, subsequent handling may cause crashes
|
||||
* because the channel structures are cleaned up when the channel is released.
|
||||
*/
|
||||
static inline void disable_hc_int(struct dwc2_hsotg *hsotg, int chnum, u32 intr)
|
||||
{
|
||||
u32 mask = readl(hsotg->regs + HCINTMSK(chnum));
|
||||
|
||||
mask &= ~intr;
|
||||
writel(mask, hsotg->regs + HCINTMSK(chnum));
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns the mode of operation, host or device
|
||||
*/
|
||||
static inline int dwc2_is_host_mode(struct dwc2_hsotg *hsotg)
|
||||
{
|
||||
return (readl(hsotg->regs + GINTSTS) & GINTSTS_CURMODE_HOST) != 0;
|
||||
}
|
||||
static inline int dwc2_is_device_mode(struct dwc2_hsotg *hsotg)
|
||||
{
|
||||
return (readl(hsotg->regs + GINTSTS) & GINTSTS_CURMODE_HOST) == 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Reads HPRT0 in preparation to modify. It keeps the WC bits 0 so that if they
|
||||
* are read as 1, they won't clear when written back.
|
||||
*/
|
||||
static inline u32 dwc2_read_hprt0(struct dwc2_hsotg *hsotg)
|
||||
{
|
||||
u32 hprt0 = readl(hsotg->regs + HPRT0);
|
||||
|
||||
hprt0 &= ~(HPRT0_ENA | HPRT0_CONNDET | HPRT0_ENACHG | HPRT0_OVRCURRCHG);
|
||||
return hprt0;
|
||||
}
|
||||
|
||||
static inline u8 dwc2_hcd_get_ep_num(struct dwc2_hcd_pipe_info *pipe)
|
||||
{
|
||||
return pipe->ep_num;
|
||||
}
|
||||
|
||||
static inline u8 dwc2_hcd_get_pipe_type(struct dwc2_hcd_pipe_info *pipe)
|
||||
{
|
||||
return pipe->pipe_type;
|
||||
}
|
||||
|
||||
static inline u16 dwc2_hcd_get_mps(struct dwc2_hcd_pipe_info *pipe)
|
||||
{
|
||||
return pipe->mps;
|
||||
}
|
||||
|
||||
static inline u8 dwc2_hcd_get_dev_addr(struct dwc2_hcd_pipe_info *pipe)
|
||||
{
|
||||
return pipe->dev_addr;
|
||||
}
|
||||
|
||||
static inline u8 dwc2_hcd_is_pipe_isoc(struct dwc2_hcd_pipe_info *pipe)
|
||||
{
|
||||
return pipe->pipe_type == USB_ENDPOINT_XFER_ISOC;
|
||||
}
|
||||
|
||||
static inline u8 dwc2_hcd_is_pipe_int(struct dwc2_hcd_pipe_info *pipe)
|
||||
{
|
||||
return pipe->pipe_type == USB_ENDPOINT_XFER_INT;
|
||||
}
|
||||
|
||||
static inline u8 dwc2_hcd_is_pipe_bulk(struct dwc2_hcd_pipe_info *pipe)
|
||||
{
|
||||
return pipe->pipe_type == USB_ENDPOINT_XFER_BULK;
|
||||
}
|
||||
|
||||
static inline u8 dwc2_hcd_is_pipe_control(struct dwc2_hcd_pipe_info *pipe)
|
||||
{
|
||||
return pipe->pipe_type == USB_ENDPOINT_XFER_CONTROL;
|
||||
}
|
||||
|
||||
static inline u8 dwc2_hcd_is_pipe_in(struct dwc2_hcd_pipe_info *pipe)
|
||||
{
|
||||
return pipe->pipe_dir == USB_DIR_IN;
|
||||
}
|
||||
|
||||
static inline u8 dwc2_hcd_is_pipe_out(struct dwc2_hcd_pipe_info *pipe)
|
||||
{
|
||||
return !dwc2_hcd_is_pipe_in(pipe);
|
||||
}
|
||||
|
||||
extern int dwc2_hcd_init(struct dwc2_hsotg *hsotg, int irq,
|
||||
const struct dwc2_core_params *params);
|
||||
extern void dwc2_hcd_remove(struct dwc2_hsotg *hsotg);
|
||||
extern void dwc2_set_parameters(struct dwc2_hsotg *hsotg,
|
||||
const struct dwc2_core_params *params);
|
||||
extern void dwc2_set_all_params(struct dwc2_core_params *params, int value);
|
||||
extern int dwc2_get_hwparams(struct dwc2_hsotg *hsotg);
|
||||
|
||||
/* Transaction Execution Functions */
|
||||
extern enum dwc2_transaction_type dwc2_hcd_select_transactions(
|
||||
struct dwc2_hsotg *hsotg);
|
||||
extern void dwc2_hcd_queue_transactions(struct dwc2_hsotg *hsotg,
|
||||
enum dwc2_transaction_type tr_type);
|
||||
|
||||
/* Schedule Queue Functions */
|
||||
/* Implemented in hcd_queue.c */
|
||||
extern void dwc2_hcd_init_usecs(struct dwc2_hsotg *hsotg);
|
||||
extern void dwc2_hcd_qh_free(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh);
|
||||
extern int dwc2_hcd_qh_add(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh);
|
||||
extern void dwc2_hcd_qh_unlink(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh);
|
||||
extern void dwc2_hcd_qh_deactivate(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh,
|
||||
int sched_csplit);
|
||||
|
||||
extern void dwc2_hcd_qtd_init(struct dwc2_qtd *qtd, struct dwc2_hcd_urb *urb);
|
||||
extern int dwc2_hcd_qtd_add(struct dwc2_hsotg *hsotg, struct dwc2_qtd *qtd,
|
||||
struct dwc2_qh **qh, gfp_t mem_flags);
|
||||
|
||||
/* Unlinks and frees a QTD */
|
||||
static inline void dwc2_hcd_qtd_unlink_and_free(struct dwc2_hsotg *hsotg,
|
||||
struct dwc2_qtd *qtd,
|
||||
struct dwc2_qh *qh)
|
||||
{
|
||||
list_del(&qtd->qtd_list_entry);
|
||||
kfree(qtd);
|
||||
}
|
||||
|
||||
/* Descriptor DMA support functions */
|
||||
extern void dwc2_hcd_start_xfer_ddma(struct dwc2_hsotg *hsotg,
|
||||
struct dwc2_qh *qh);
|
||||
extern void dwc2_hcd_complete_xfer_ddma(struct dwc2_hsotg *hsotg,
|
||||
struct dwc2_host_chan *chan, int chnum,
|
||||
enum dwc2_halt_status halt_status);
|
||||
|
||||
extern int dwc2_hcd_qh_init_ddma(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh,
|
||||
gfp_t mem_flags);
|
||||
extern void dwc2_hcd_qh_free_ddma(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh);
|
||||
|
||||
/* Check if QH is non-periodic */
|
||||
#define dwc2_qh_is_non_per(_qh_ptr_) \
|
||||
((_qh_ptr_)->ep_type == USB_ENDPOINT_XFER_BULK || \
|
||||
(_qh_ptr_)->ep_type == USB_ENDPOINT_XFER_CONTROL)
|
||||
|
||||
#ifdef CONFIG_USB_DWC2_DEBUG_PERIODIC
|
||||
static inline bool dbg_hc(struct dwc2_host_chan *hc) { return true; }
|
||||
static inline bool dbg_qh(struct dwc2_qh *qh) { return true; }
|
||||
static inline bool dbg_urb(struct urb *urb) { return true; }
|
||||
static inline bool dbg_perio(void) { return true; }
|
||||
#else /* !CONFIG_USB_DWC2_DEBUG_PERIODIC */
|
||||
static inline bool dbg_hc(struct dwc2_host_chan *hc)
|
||||
{
|
||||
return hc->ep_type == USB_ENDPOINT_XFER_BULK ||
|
||||
hc->ep_type == USB_ENDPOINT_XFER_CONTROL;
|
||||
}
|
||||
|
||||
static inline bool dbg_qh(struct dwc2_qh *qh)
|
||||
{
|
||||
return qh->ep_type == USB_ENDPOINT_XFER_BULK ||
|
||||
qh->ep_type == USB_ENDPOINT_XFER_CONTROL;
|
||||
}
|
||||
|
||||
static inline bool dbg_urb(struct urb *urb)
|
||||
{
|
||||
return usb_pipetype(urb->pipe) == PIPE_BULK ||
|
||||
usb_pipetype(urb->pipe) == PIPE_CONTROL;
|
||||
}
|
||||
|
||||
static inline bool dbg_perio(void) { return false; }
|
||||
#endif
|
||||
|
||||
/* High bandwidth multiplier as encoded in highspeed endpoint descriptors */
|
||||
#define dwc2_hb_mult(wmaxpacketsize) (1 + (((wmaxpacketsize) >> 11) & 0x03))
|
||||
|
||||
/* Packet size for any kind of endpoint descriptor */
|
||||
#define dwc2_max_packet(wmaxpacketsize) ((wmaxpacketsize) & 0x07ff)
|
||||
|
||||
/*
|
||||
* Returns true if frame1 is less than or equal to frame2. The comparison is
|
||||
* done modulo HFNUM_MAX_FRNUM. This accounts for the rollover of the
|
||||
* frame number when the max frame number is reached.
|
||||
*/
|
||||
static inline int dwc2_frame_num_le(u16 frame1, u16 frame2)
|
||||
{
|
||||
return ((frame2 - frame1) & HFNUM_MAX_FRNUM) <= (HFNUM_MAX_FRNUM >> 1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns true if frame1 is greater than frame2. The comparison is done
|
||||
* modulo HFNUM_MAX_FRNUM. This accounts for the rollover of the frame
|
||||
* number when the max frame number is reached.
|
||||
*/
|
||||
static inline int dwc2_frame_num_gt(u16 frame1, u16 frame2)
|
||||
{
|
||||
return (frame1 != frame2) &&
|
||||
((frame1 - frame2) & HFNUM_MAX_FRNUM) < (HFNUM_MAX_FRNUM >> 1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Increments frame by the amount specified by inc. The addition is done
|
||||
* modulo HFNUM_MAX_FRNUM. Returns the incremented value.
|
||||
*/
|
||||
static inline u16 dwc2_frame_num_inc(u16 frame, u16 inc)
|
||||
{
|
||||
return (frame + inc) & HFNUM_MAX_FRNUM;
|
||||
}
|
||||
|
||||
static inline u16 dwc2_full_frame_num(u16 frame)
|
||||
{
|
||||
return (frame & HFNUM_MAX_FRNUM) >> 3;
|
||||
}
|
||||
|
||||
static inline u16 dwc2_micro_frame_num(u16 frame)
|
||||
{
|
||||
return frame & 0x7;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns the Core Interrupt Status register contents, ANDed with the Core
|
||||
* Interrupt Mask register contents
|
||||
*/
|
||||
static inline u32 dwc2_read_core_intr(struct dwc2_hsotg *hsotg)
|
||||
{
|
||||
return readl(hsotg->regs + GINTSTS) & readl(hsotg->regs + GINTMSK);
|
||||
}
|
||||
|
||||
static inline u32 dwc2_hcd_urb_get_status(struct dwc2_hcd_urb *dwc2_urb)
|
||||
{
|
||||
return dwc2_urb->status;
|
||||
}
|
||||
|
||||
static inline u32 dwc2_hcd_urb_get_actual_length(
|
||||
struct dwc2_hcd_urb *dwc2_urb)
|
||||
{
|
||||
return dwc2_urb->actual_length;
|
||||
}
|
||||
|
||||
static inline u32 dwc2_hcd_urb_get_error_count(struct dwc2_hcd_urb *dwc2_urb)
|
||||
{
|
||||
return dwc2_urb->error_count;
|
||||
}
|
||||
|
||||
static inline void dwc2_hcd_urb_set_iso_desc_params(
|
||||
struct dwc2_hcd_urb *dwc2_urb, int desc_num, u32 offset,
|
||||
u32 length)
|
||||
{
|
||||
dwc2_urb->iso_descs[desc_num].offset = offset;
|
||||
dwc2_urb->iso_descs[desc_num].length = length;
|
||||
}
|
||||
|
||||
static inline u32 dwc2_hcd_urb_get_iso_desc_status(
|
||||
struct dwc2_hcd_urb *dwc2_urb, int desc_num)
|
||||
{
|
||||
return dwc2_urb->iso_descs[desc_num].status;
|
||||
}
|
||||
|
||||
static inline u32 dwc2_hcd_urb_get_iso_desc_actual_length(
|
||||
struct dwc2_hcd_urb *dwc2_urb, int desc_num)
|
||||
{
|
||||
return dwc2_urb->iso_descs[desc_num].actual_length;
|
||||
}
|
||||
|
||||
static inline int dwc2_hcd_is_bandwidth_allocated(struct dwc2_hsotg *hsotg,
|
||||
struct usb_host_endpoint *ep)
|
||||
{
|
||||
struct dwc2_qh *qh = ep->hcpriv;
|
||||
|
||||
if (qh && !list_empty(&qh->qh_list_entry))
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline u16 dwc2_hcd_get_ep_bandwidth(struct dwc2_hsotg *hsotg,
|
||||
struct usb_host_endpoint *ep)
|
||||
{
|
||||
struct dwc2_qh *qh = ep->hcpriv;
|
||||
|
||||
if (!qh) {
|
||||
WARN_ON(1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return qh->usecs;
|
||||
}
|
||||
|
||||
extern void dwc2_hcd_save_data_toggle(struct dwc2_hsotg *hsotg,
|
||||
struct dwc2_host_chan *chan, int chnum,
|
||||
struct dwc2_qtd *qtd);
|
||||
|
||||
/* HCD Core API */
|
||||
|
||||
/**
|
||||
* dwc2_handle_hcd_intr() - Called on every hardware interrupt
|
||||
*
|
||||
* @hsotg: The DWC2 HCD
|
||||
*
|
||||
* Returns IRQ_HANDLED if interrupt is handled
|
||||
* Return IRQ_NONE if interrupt is not handled
|
||||
*/
|
||||
extern irqreturn_t dwc2_handle_hcd_intr(struct dwc2_hsotg *hsotg);
|
||||
|
||||
/**
|
||||
* dwc2_hcd_stop() - Halts the DWC_otg host mode operation
|
||||
*
|
||||
* @hsotg: The DWC2 HCD
|
||||
*/
|
||||
extern void dwc2_hcd_stop(struct dwc2_hsotg *hsotg);
|
||||
|
||||
extern void dwc2_hcd_start(struct dwc2_hsotg *hsotg);
|
||||
extern void dwc2_hcd_disconnect(struct dwc2_hsotg *hsotg);
|
||||
|
||||
/**
|
||||
* dwc2_hcd_is_b_host() - Returns 1 if core currently is acting as B host,
|
||||
* and 0 otherwise
|
||||
*
|
||||
* @hsotg: The DWC2 HCD
|
||||
*/
|
||||
extern int dwc2_hcd_is_b_host(struct dwc2_hsotg *hsotg);
|
||||
|
||||
/**
|
||||
* dwc2_hcd_get_frame_number() - Returns current frame number
|
||||
*
|
||||
* @hsotg: The DWC2 HCD
|
||||
*/
|
||||
extern int dwc2_hcd_get_frame_number(struct dwc2_hsotg *hsotg);
|
||||
|
||||
/**
|
||||
* dwc2_hcd_dump_state() - Dumps hsotg state
|
||||
*
|
||||
* @hsotg: The DWC2 HCD
|
||||
*
|
||||
* NOTE: This function will be removed once the peripheral controller code
|
||||
* is integrated and the driver is stable
|
||||
*/
|
||||
extern void dwc2_hcd_dump_state(struct dwc2_hsotg *hsotg);
|
||||
|
||||
/**
|
||||
* dwc2_hcd_dump_frrem() - Dumps the average frame remaining at SOF
|
||||
*
|
||||
* @hsotg: The DWC2 HCD
|
||||
*
|
||||
* This can be used to determine average interrupt latency. Frame remaining is
|
||||
* also shown for start transfer and two additional sample points.
|
||||
*
|
||||
* NOTE: This function will be removed once the peripheral controller code
|
||||
* is integrated and the driver is stable
|
||||
*/
|
||||
extern void dwc2_hcd_dump_frrem(struct dwc2_hsotg *hsotg);
|
||||
|
||||
/* URB interface */
|
||||
|
||||
/* Transfer flags */
|
||||
#define URB_GIVEBACK_ASAP 0x1
|
||||
#define URB_SEND_ZERO_PACKET 0x2
|
||||
|
||||
/* Host driver callbacks */
|
||||
|
||||
extern void dwc2_host_start(struct dwc2_hsotg *hsotg);
|
||||
extern void dwc2_host_disconnect(struct dwc2_hsotg *hsotg);
|
||||
extern void dwc2_host_hub_info(struct dwc2_hsotg *hsotg, void *context,
|
||||
int *hub_addr, int *hub_port);
|
||||
extern int dwc2_host_get_speed(struct dwc2_hsotg *hsotg, void *context);
|
||||
extern void dwc2_host_complete(struct dwc2_hsotg *hsotg, struct dwc2_qtd *qtd,
|
||||
int status);
|
||||
|
||||
#ifdef DEBUG
|
||||
/*
|
||||
* Macro to sample the remaining PHY clocks left in the current frame. This
|
||||
* may be used during debugging to determine the average time it takes to
|
||||
* execute sections of code. There are two possible sample points, "a" and
|
||||
* "b", so the _letter_ argument must be one of these values.
|
||||
*
|
||||
* To dump the average sample times, read the "hcd_frrem" sysfs attribute. For
|
||||
* example, "cat /sys/devices/lm0/hcd_frrem".
|
||||
*/
|
||||
#define dwc2_sample_frrem(_hcd_, _qh_, _letter_) \
|
||||
do { \
|
||||
struct hfnum_data _hfnum_; \
|
||||
struct dwc2_qtd *_qtd_; \
|
||||
\
|
||||
_qtd_ = list_entry((_qh_)->qtd_list.next, struct dwc2_qtd, \
|
||||
qtd_list_entry); \
|
||||
if (usb_pipeint(_qtd_->urb->pipe) && \
|
||||
(_qh_)->start_split_frame != 0 && !_qtd_->complete_split) { \
|
||||
_hfnum_.d32 = readl((_hcd_)->regs + HFNUM); \
|
||||
switch (_hfnum_.b.frnum & 0x7) { \
|
||||
case 7: \
|
||||
(_hcd_)->hfnum_7_samples_##_letter_++; \
|
||||
(_hcd_)->hfnum_7_frrem_accum_##_letter_ += \
|
||||
_hfnum_.b.frrem; \
|
||||
break; \
|
||||
case 0: \
|
||||
(_hcd_)->hfnum_0_samples_##_letter_++; \
|
||||
(_hcd_)->hfnum_0_frrem_accum_##_letter_ += \
|
||||
_hfnum_.b.frrem; \
|
||||
break; \
|
||||
default: \
|
||||
(_hcd_)->hfnum_other_samples_##_letter_++; \
|
||||
(_hcd_)->hfnum_other_frrem_accum_##_letter_ += \
|
||||
_hfnum_.b.frrem; \
|
||||
break; \
|
||||
} \
|
||||
} \
|
||||
} while (0)
|
||||
#else
|
||||
#define dwc2_sample_frrem(_hcd_, _qh_, _letter_) do {} while (0)
|
||||
#endif
|
||||
|
||||
#endif /* __DWC2_HCD_H__ */
|
1212
drivers/usb/dwc2/hcd_ddma.c
Normal file
1212
drivers/usb/dwc2/hcd_ddma.c
Normal file
File diff suppressed because it is too large
Load Diff
2119
drivers/usb/dwc2/hcd_intr.c
Normal file
2119
drivers/usb/dwc2/hcd_intr.c
Normal file
File diff suppressed because it is too large
Load Diff
835
drivers/usb/dwc2/hcd_queue.c
Normal file
835
drivers/usb/dwc2/hcd_queue.c
Normal file
@@ -0,0 +1,835 @@
|
||||
/*
|
||||
* hcd_queue.c - DesignWare HS OTG Controller host queuing routines
|
||||
*
|
||||
* Copyright (C) 2004-2013 Synopsys, Inc.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions, and the following disclaimer,
|
||||
* without modification.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. The names of the above-listed copyright holders may not be used
|
||||
* to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* ALTERNATIVELY, this software may be distributed under the terms of the
|
||||
* GNU General Public License ("GPL") as published by the Free Software
|
||||
* Foundation; either version 2 of the License, or (at your option) any
|
||||
* later version.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This file contains the functions to manage Queue Heads and Queue
|
||||
* Transfer Descriptors for Host mode
|
||||
*/
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/spinlock.h>
|
||||
#include <linux/interrupt.h>
|
||||
#include <linux/dma-mapping.h>
|
||||
#include <linux/io.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/usb.h>
|
||||
|
||||
#include <linux/usb/hcd.h>
|
||||
#include <linux/usb/ch11.h>
|
||||
|
||||
#include "core.h"
|
||||
#include "hcd.h"
|
||||
|
||||
/**
|
||||
* dwc2_qh_init() - Initializes a QH structure
|
||||
*
|
||||
* @hsotg: The HCD state structure for the DWC OTG controller
|
||||
* @qh: The QH to init
|
||||
* @urb: Holds the information about the device/endpoint needed to initialize
|
||||
* the QH
|
||||
*/
|
||||
#define SCHEDULE_SLOP 10
|
||||
static void dwc2_qh_init(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh,
|
||||
struct dwc2_hcd_urb *urb)
|
||||
{
|
||||
int dev_speed, hub_addr, hub_port;
|
||||
char *speed, *type;
|
||||
|
||||
dev_vdbg(hsotg->dev, "%s()\n", __func__);
|
||||
|
||||
/* Initialize QH */
|
||||
qh->ep_type = dwc2_hcd_get_pipe_type(&urb->pipe_info);
|
||||
qh->ep_is_in = dwc2_hcd_is_pipe_in(&urb->pipe_info) ? 1 : 0;
|
||||
|
||||
qh->data_toggle = DWC2_HC_PID_DATA0;
|
||||
qh->maxp = dwc2_hcd_get_mps(&urb->pipe_info);
|
||||
INIT_LIST_HEAD(&qh->qtd_list);
|
||||
INIT_LIST_HEAD(&qh->qh_list_entry);
|
||||
|
||||
/* FS/LS Endpoint on HS Hub, NOT virtual root hub */
|
||||
dev_speed = dwc2_host_get_speed(hsotg, urb->priv);
|
||||
|
||||
dwc2_host_hub_info(hsotg, urb->priv, &hub_addr, &hub_port);
|
||||
|
||||
if ((dev_speed == USB_SPEED_LOW || dev_speed == USB_SPEED_FULL) &&
|
||||
hub_addr != 0 && hub_addr != 1) {
|
||||
dev_vdbg(hsotg->dev,
|
||||
"QH init: EP %d: TT found at hub addr %d, for port %d\n",
|
||||
dwc2_hcd_get_ep_num(&urb->pipe_info), hub_addr,
|
||||
hub_port);
|
||||
qh->do_split = 1;
|
||||
}
|
||||
|
||||
if (qh->ep_type == USB_ENDPOINT_XFER_INT ||
|
||||
qh->ep_type == USB_ENDPOINT_XFER_ISOC) {
|
||||
/* Compute scheduling parameters once and save them */
|
||||
u32 hprt, prtspd;
|
||||
|
||||
/* Todo: Account for split transfers in the bus time */
|
||||
int bytecount =
|
||||
dwc2_hb_mult(qh->maxp) * dwc2_max_packet(qh->maxp);
|
||||
|
||||
qh->usecs = NS_TO_US(usb_calc_bus_time(qh->do_split ?
|
||||
USB_SPEED_HIGH : dev_speed, qh->ep_is_in,
|
||||
qh->ep_type == USB_ENDPOINT_XFER_ISOC,
|
||||
bytecount));
|
||||
/* Start in a slightly future (micro)frame */
|
||||
qh->sched_frame = dwc2_frame_num_inc(hsotg->frame_number,
|
||||
SCHEDULE_SLOP);
|
||||
qh->interval = urb->interval;
|
||||
#if 0
|
||||
/* Increase interrupt polling rate for debugging */
|
||||
if (qh->ep_type == USB_ENDPOINT_XFER_INT)
|
||||
qh->interval = 8;
|
||||
#endif
|
||||
hprt = readl(hsotg->regs + HPRT0);
|
||||
prtspd = (hprt & HPRT0_SPD_MASK) >> HPRT0_SPD_SHIFT;
|
||||
if (prtspd == HPRT0_SPD_HIGH_SPEED &&
|
||||
(dev_speed == USB_SPEED_LOW ||
|
||||
dev_speed == USB_SPEED_FULL)) {
|
||||
qh->interval *= 8;
|
||||
qh->sched_frame |= 0x7;
|
||||
qh->start_split_frame = qh->sched_frame;
|
||||
}
|
||||
dev_dbg(hsotg->dev, "interval=%d\n", qh->interval);
|
||||
}
|
||||
|
||||
dev_vdbg(hsotg->dev, "DWC OTG HCD QH Initialized\n");
|
||||
dev_vdbg(hsotg->dev, "DWC OTG HCD QH - qh = %p\n", qh);
|
||||
dev_vdbg(hsotg->dev, "DWC OTG HCD QH - Device Address = %d\n",
|
||||
dwc2_hcd_get_dev_addr(&urb->pipe_info));
|
||||
dev_vdbg(hsotg->dev, "DWC OTG HCD QH - Endpoint %d, %s\n",
|
||||
dwc2_hcd_get_ep_num(&urb->pipe_info),
|
||||
dwc2_hcd_is_pipe_in(&urb->pipe_info) ? "IN" : "OUT");
|
||||
|
||||
qh->dev_speed = dev_speed;
|
||||
|
||||
switch (dev_speed) {
|
||||
case USB_SPEED_LOW:
|
||||
speed = "low";
|
||||
break;
|
||||
case USB_SPEED_FULL:
|
||||
speed = "full";
|
||||
break;
|
||||
case USB_SPEED_HIGH:
|
||||
speed = "high";
|
||||
break;
|
||||
default:
|
||||
speed = "?";
|
||||
break;
|
||||
}
|
||||
dev_vdbg(hsotg->dev, "DWC OTG HCD QH - Speed = %s\n", speed);
|
||||
|
||||
switch (qh->ep_type) {
|
||||
case USB_ENDPOINT_XFER_ISOC:
|
||||
type = "isochronous";
|
||||
break;
|
||||
case USB_ENDPOINT_XFER_INT:
|
||||
type = "interrupt";
|
||||
break;
|
||||
case USB_ENDPOINT_XFER_CONTROL:
|
||||
type = "control";
|
||||
break;
|
||||
case USB_ENDPOINT_XFER_BULK:
|
||||
type = "bulk";
|
||||
break;
|
||||
default:
|
||||
type = "?";
|
||||
break;
|
||||
}
|
||||
|
||||
dev_vdbg(hsotg->dev, "DWC OTG HCD QH - Type = %s\n", type);
|
||||
|
||||
if (qh->ep_type == USB_ENDPOINT_XFER_INT) {
|
||||
dev_vdbg(hsotg->dev, "DWC OTG HCD QH - usecs = %d\n",
|
||||
qh->usecs);
|
||||
dev_vdbg(hsotg->dev, "DWC OTG HCD QH - interval = %d\n",
|
||||
qh->interval);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* dwc2_hcd_qh_create() - Allocates and initializes a 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
|
||||
*
|
||||
* Return: Pointer to the newly allocated QH, or NULL on error
|
||||
*/
|
||||
static struct dwc2_qh *dwc2_hcd_qh_create(struct dwc2_hsotg *hsotg,
|
||||
struct dwc2_hcd_urb *urb,
|
||||
gfp_t mem_flags)
|
||||
{
|
||||
struct dwc2_qh *qh;
|
||||
|
||||
if (!urb->priv)
|
||||
return NULL;
|
||||
|
||||
/* Allocate memory */
|
||||
qh = kzalloc(sizeof(*qh), mem_flags);
|
||||
if (!qh)
|
||||
return NULL;
|
||||
|
||||
dwc2_qh_init(hsotg, qh, urb);
|
||||
|
||||
if (hsotg->core_params->dma_desc_enable > 0 &&
|
||||
dwc2_hcd_qh_init_ddma(hsotg, qh, mem_flags) < 0) {
|
||||
dwc2_hcd_qh_free(hsotg, qh);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return qh;
|
||||
}
|
||||
|
||||
/**
|
||||
* dwc2_hcd_qh_free() - Frees the QH
|
||||
*
|
||||
* @hsotg: HCD instance
|
||||
* @qh: The QH to free
|
||||
*
|
||||
* QH should already be removed from the list. QTD list should already be empty
|
||||
* if called from URB Dequeue.
|
||||
*
|
||||
* Must NOT be called with interrupt disabled or spinlock held
|
||||
*/
|
||||
void dwc2_hcd_qh_free(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh)
|
||||
{
|
||||
u32 buf_size;
|
||||
|
||||
if (hsotg->core_params->dma_desc_enable > 0) {
|
||||
dwc2_hcd_qh_free_ddma(hsotg, qh);
|
||||
} else if (qh->dw_align_buf) {
|
||||
if (qh->ep_type == USB_ENDPOINT_XFER_ISOC)
|
||||
buf_size = 4096;
|
||||
else
|
||||
buf_size = hsotg->core_params->max_transfer_size;
|
||||
dma_free_coherent(hsotg->dev, buf_size, qh->dw_align_buf,
|
||||
qh->dw_align_buf_dma);
|
||||
}
|
||||
|
||||
kfree(qh);
|
||||
}
|
||||
|
||||
/**
|
||||
* dwc2_periodic_channel_available() - Checks that a channel is available for a
|
||||
* periodic transfer
|
||||
*
|
||||
* @hsotg: The HCD state structure for the DWC OTG controller
|
||||
*
|
||||
* Return: 0 if successful, negative error code otherwise
|
||||
*/
|
||||
static int dwc2_periodic_channel_available(struct dwc2_hsotg *hsotg)
|
||||
{
|
||||
/*
|
||||
* Currently assuming that there is a dedicated host channel for
|
||||
* each periodic transaction plus at least one host channel for
|
||||
* non-periodic transactions
|
||||
*/
|
||||
int status;
|
||||
int num_channels;
|
||||
|
||||
num_channels = hsotg->core_params->host_channels;
|
||||
if (hsotg->periodic_channels + hsotg->non_periodic_channels <
|
||||
num_channels
|
||||
&& hsotg->periodic_channels < num_channels - 1) {
|
||||
status = 0;
|
||||
} else {
|
||||
dev_dbg(hsotg->dev,
|
||||
"%s: Total channels: %d, Periodic: %d, "
|
||||
"Non-periodic: %d\n", __func__, num_channels,
|
||||
hsotg->periodic_channels, hsotg->non_periodic_channels);
|
||||
status = -ENOSPC;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* dwc2_check_periodic_bandwidth() - Checks that there is sufficient bandwidth
|
||||
* for the specified QH in the periodic schedule
|
||||
*
|
||||
* @hsotg: The HCD state structure for the DWC OTG controller
|
||||
* @qh: QH containing periodic bandwidth required
|
||||
*
|
||||
* Return: 0 if successful, negative error code otherwise
|
||||
*
|
||||
* For simplicity, this calculation assumes that all the transfers in the
|
||||
* periodic schedule may occur in the same (micro)frame
|
||||
*/
|
||||
static int dwc2_check_periodic_bandwidth(struct dwc2_hsotg *hsotg,
|
||||
struct dwc2_qh *qh)
|
||||
{
|
||||
int status;
|
||||
s16 max_claimed_usecs;
|
||||
|
||||
status = 0;
|
||||
|
||||
if (qh->dev_speed == USB_SPEED_HIGH || qh->do_split) {
|
||||
/*
|
||||
* High speed mode
|
||||
* Max periodic usecs is 80% x 125 usec = 100 usec
|
||||
*/
|
||||
max_claimed_usecs = 100 - qh->usecs;
|
||||
} else {
|
||||
/*
|
||||
* Full speed mode
|
||||
* Max periodic usecs is 90% x 1000 usec = 900 usec
|
||||
*/
|
||||
max_claimed_usecs = 900 - qh->usecs;
|
||||
}
|
||||
|
||||
if (hsotg->periodic_usecs > max_claimed_usecs) {
|
||||
dev_err(hsotg->dev,
|
||||
"%s: already claimed usecs %d, required usecs %d\n",
|
||||
__func__, hsotg->periodic_usecs, qh->usecs);
|
||||
status = -ENOSPC;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Microframe scheduler
|
||||
* track the total use in hsotg->frame_usecs
|
||||
* keep each qh use in qh->frame_usecs
|
||||
* when surrendering the qh then donate the time back
|
||||
*/
|
||||
static const unsigned short max_uframe_usecs[] = {
|
||||
100, 100, 100, 100, 100, 100, 30, 0
|
||||
};
|
||||
|
||||
void dwc2_hcd_init_usecs(struct dwc2_hsotg *hsotg)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 8; i++)
|
||||
hsotg->frame_usecs[i] = max_uframe_usecs[i];
|
||||
}
|
||||
|
||||
static int dwc2_find_single_uframe(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh)
|
||||
{
|
||||
unsigned short utime = qh->usecs;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 8; i++) {
|
||||
/* At the start hsotg->frame_usecs[i] = max_uframe_usecs[i] */
|
||||
if (utime <= hsotg->frame_usecs[i]) {
|
||||
hsotg->frame_usecs[i] -= utime;
|
||||
qh->frame_usecs[i] += utime;
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -ENOSPC;
|
||||
}
|
||||
|
||||
/*
|
||||
* use this for FS apps that can span multiple uframes
|
||||
*/
|
||||
static int dwc2_find_multi_uframe(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh)
|
||||
{
|
||||
unsigned short utime = qh->usecs;
|
||||
unsigned short xtime;
|
||||
int t_left;
|
||||
int i;
|
||||
int j;
|
||||
int k;
|
||||
|
||||
for (i = 0; i < 8; i++) {
|
||||
if (hsotg->frame_usecs[i] <= 0)
|
||||
continue;
|
||||
|
||||
/*
|
||||
* we need n consecutive slots so use j as a start slot
|
||||
* j plus j+1 must be enough time (for now)
|
||||
*/
|
||||
xtime = hsotg->frame_usecs[i];
|
||||
for (j = i + 1; j < 8; j++) {
|
||||
/*
|
||||
* if we add this frame remaining time to xtime we may
|
||||
* be OK, if not we need to test j for a complete frame
|
||||
*/
|
||||
if (xtime + hsotg->frame_usecs[j] < utime) {
|
||||
if (hsotg->frame_usecs[j] <
|
||||
max_uframe_usecs[j])
|
||||
continue;
|
||||
}
|
||||
if (xtime >= utime) {
|
||||
t_left = utime;
|
||||
for (k = i; k < 8; k++) {
|
||||
t_left -= hsotg->frame_usecs[k];
|
||||
if (t_left <= 0) {
|
||||
qh->frame_usecs[k] +=
|
||||
hsotg->frame_usecs[k]
|
||||
+ t_left;
|
||||
hsotg->frame_usecs[k] = -t_left;
|
||||
return i;
|
||||
} else {
|
||||
qh->frame_usecs[k] +=
|
||||
hsotg->frame_usecs[k];
|
||||
hsotg->frame_usecs[k] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* add the frame time to x time */
|
||||
xtime += hsotg->frame_usecs[j];
|
||||
/* we must have a fully available next frame or break */
|
||||
if (xtime < utime &&
|
||||
hsotg->frame_usecs[j] == max_uframe_usecs[j])
|
||||
continue;
|
||||
}
|
||||
}
|
||||
return -ENOSPC;
|
||||
}
|
||||
|
||||
static int dwc2_find_uframe(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (qh->dev_speed == USB_SPEED_HIGH) {
|
||||
/* if this is a hs transaction we need a full frame */
|
||||
ret = dwc2_find_single_uframe(hsotg, qh);
|
||||
} else {
|
||||
/*
|
||||
* if this is a fs transaction we may need a sequence
|
||||
* of frames
|
||||
*/
|
||||
ret = dwc2_find_multi_uframe(hsotg, qh);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* dwc2_check_max_xfer_size() - Checks that the max transfer size allowed in a
|
||||
* host channel is large enough to handle the maximum data transfer in a single
|
||||
* (micro)frame for a periodic transfer
|
||||
*
|
||||
* @hsotg: The HCD state structure for the DWC OTG controller
|
||||
* @qh: QH for a periodic endpoint
|
||||
*
|
||||
* Return: 0 if successful, negative error code otherwise
|
||||
*/
|
||||
static int dwc2_check_max_xfer_size(struct dwc2_hsotg *hsotg,
|
||||
struct dwc2_qh *qh)
|
||||
{
|
||||
u32 max_xfer_size;
|
||||
u32 max_channel_xfer_size;
|
||||
int status = 0;
|
||||
|
||||
max_xfer_size = dwc2_max_packet(qh->maxp) * dwc2_hb_mult(qh->maxp);
|
||||
max_channel_xfer_size = hsotg->core_params->max_transfer_size;
|
||||
|
||||
if (max_xfer_size > max_channel_xfer_size) {
|
||||
dev_err(hsotg->dev,
|
||||
"%s: Periodic xfer length %d > max xfer length for channel %d\n",
|
||||
__func__, max_xfer_size, max_channel_xfer_size);
|
||||
status = -ENOSPC;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* dwc2_schedule_periodic() - Schedules an interrupt or isochronous transfer in
|
||||
* the periodic schedule
|
||||
*
|
||||
* @hsotg: The HCD state structure for the DWC OTG controller
|
||||
* @qh: QH for the periodic transfer. The QH should already contain the
|
||||
* scheduling information.
|
||||
*
|
||||
* Return: 0 if successful, negative error code otherwise
|
||||
*/
|
||||
static int dwc2_schedule_periodic(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh)
|
||||
{
|
||||
int status;
|
||||
|
||||
if (hsotg->core_params->uframe_sched > 0) {
|
||||
int frame = -1;
|
||||
|
||||
status = dwc2_find_uframe(hsotg, qh);
|
||||
if (status == 0)
|
||||
frame = 7;
|
||||
else if (status > 0)
|
||||
frame = status - 1;
|
||||
|
||||
/* Set the new frame up */
|
||||
if (frame >= 0) {
|
||||
qh->sched_frame &= ~0x7;
|
||||
qh->sched_frame |= (frame & 7);
|
||||
}
|
||||
|
||||
if (status > 0)
|
||||
status = 0;
|
||||
} else {
|
||||
status = dwc2_periodic_channel_available(hsotg);
|
||||
if (status) {
|
||||
dev_info(hsotg->dev,
|
||||
"%s: No host channel available for periodic transfer\n",
|
||||
__func__);
|
||||
return status;
|
||||
}
|
||||
|
||||
status = dwc2_check_periodic_bandwidth(hsotg, qh);
|
||||
}
|
||||
|
||||
if (status) {
|
||||
dev_dbg(hsotg->dev,
|
||||
"%s: Insufficient periodic bandwidth for periodic transfer\n",
|
||||
__func__);
|
||||
return status;
|
||||
}
|
||||
|
||||
status = dwc2_check_max_xfer_size(hsotg, qh);
|
||||
if (status) {
|
||||
dev_dbg(hsotg->dev,
|
||||
"%s: Channel max transfer size too small for periodic transfer\n",
|
||||
__func__);
|
||||
return status;
|
||||
}
|
||||
|
||||
if (hsotg->core_params->dma_desc_enable > 0)
|
||||
/* Don't rely on SOF and start in ready schedule */
|
||||
list_add_tail(&qh->qh_list_entry, &hsotg->periodic_sched_ready);
|
||||
else
|
||||
/* Always start in inactive schedule */
|
||||
list_add_tail(&qh->qh_list_entry,
|
||||
&hsotg->periodic_sched_inactive);
|
||||
|
||||
if (hsotg->core_params->uframe_sched <= 0)
|
||||
/* Reserve periodic channel */
|
||||
hsotg->periodic_channels++;
|
||||
|
||||
/* Update claimed usecs per (micro)frame */
|
||||
hsotg->periodic_usecs += qh->usecs;
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* dwc2_deschedule_periodic() - Removes an interrupt or isochronous transfer
|
||||
* from the periodic schedule
|
||||
*
|
||||
* @hsotg: The HCD state structure for the DWC OTG controller
|
||||
* @qh: QH for the periodic transfer
|
||||
*/
|
||||
static void dwc2_deschedule_periodic(struct dwc2_hsotg *hsotg,
|
||||
struct dwc2_qh *qh)
|
||||
{
|
||||
int i;
|
||||
|
||||
list_del_init(&qh->qh_list_entry);
|
||||
|
||||
/* Update claimed usecs per (micro)frame */
|
||||
hsotg->periodic_usecs -= qh->usecs;
|
||||
|
||||
if (hsotg->core_params->uframe_sched > 0) {
|
||||
for (i = 0; i < 8; i++) {
|
||||
hsotg->frame_usecs[i] += qh->frame_usecs[i];
|
||||
qh->frame_usecs[i] = 0;
|
||||
}
|
||||
} else {
|
||||
/* Release periodic channel reservation */
|
||||
hsotg->periodic_channels--;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* dwc2_hcd_qh_add() - Adds a QH to either the non periodic or periodic
|
||||
* schedule if it is not already in the schedule. If the QH is already in
|
||||
* the schedule, no action is taken.
|
||||
*
|
||||
* @hsotg: The HCD state structure for the DWC OTG controller
|
||||
* @qh: The QH to add
|
||||
*
|
||||
* Return: 0 if successful, negative error code otherwise
|
||||
*/
|
||||
int dwc2_hcd_qh_add(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh)
|
||||
{
|
||||
int status;
|
||||
u32 intr_mask;
|
||||
|
||||
if (dbg_qh(qh))
|
||||
dev_vdbg(hsotg->dev, "%s()\n", __func__);
|
||||
|
||||
if (!list_empty(&qh->qh_list_entry))
|
||||
/* QH already in a schedule */
|
||||
return 0;
|
||||
|
||||
/* Add the new QH to the appropriate schedule */
|
||||
if (dwc2_qh_is_non_per(qh)) {
|
||||
/* Always start in inactive schedule */
|
||||
list_add_tail(&qh->qh_list_entry,
|
||||
&hsotg->non_periodic_sched_inactive);
|
||||
return 0;
|
||||
}
|
||||
|
||||
status = dwc2_schedule_periodic(hsotg, qh);
|
||||
if (status)
|
||||
return status;
|
||||
if (!hsotg->periodic_qh_count) {
|
||||
intr_mask = readl(hsotg->regs + GINTMSK);
|
||||
intr_mask |= GINTSTS_SOF;
|
||||
writel(intr_mask, hsotg->regs + GINTMSK);
|
||||
}
|
||||
hsotg->periodic_qh_count++;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* dwc2_hcd_qh_unlink() - Removes a QH from either the non-periodic or periodic
|
||||
* schedule. Memory is not freed.
|
||||
*
|
||||
* @hsotg: The HCD state structure
|
||||
* @qh: QH to remove from schedule
|
||||
*/
|
||||
void dwc2_hcd_qh_unlink(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh)
|
||||
{
|
||||
u32 intr_mask;
|
||||
|
||||
dev_vdbg(hsotg->dev, "%s()\n", __func__);
|
||||
|
||||
if (list_empty(&qh->qh_list_entry))
|
||||
/* QH is not in a schedule */
|
||||
return;
|
||||
|
||||
if (dwc2_qh_is_non_per(qh)) {
|
||||
if (hsotg->non_periodic_qh_ptr == &qh->qh_list_entry)
|
||||
hsotg->non_periodic_qh_ptr =
|
||||
hsotg->non_periodic_qh_ptr->next;
|
||||
list_del_init(&qh->qh_list_entry);
|
||||
return;
|
||||
}
|
||||
|
||||
dwc2_deschedule_periodic(hsotg, qh);
|
||||
hsotg->periodic_qh_count--;
|
||||
if (!hsotg->periodic_qh_count) {
|
||||
intr_mask = readl(hsotg->regs + GINTMSK);
|
||||
intr_mask &= ~GINTSTS_SOF;
|
||||
writel(intr_mask, hsotg->regs + GINTMSK);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Schedule the next continuing periodic split transfer
|
||||
*/
|
||||
static void dwc2_sched_periodic_split(struct dwc2_hsotg *hsotg,
|
||||
struct dwc2_qh *qh, u16 frame_number,
|
||||
int sched_next_periodic_split)
|
||||
{
|
||||
u16 incr;
|
||||
|
||||
if (sched_next_periodic_split) {
|
||||
qh->sched_frame = frame_number;
|
||||
incr = dwc2_frame_num_inc(qh->start_split_frame, 1);
|
||||
if (dwc2_frame_num_le(frame_number, incr)) {
|
||||
/*
|
||||
* Allow one frame to elapse after start split
|
||||
* microframe before scheduling complete split, but
|
||||
* DON'T if we are doing the next start split in the
|
||||
* same frame for an ISOC out
|
||||
*/
|
||||
if (qh->ep_type != USB_ENDPOINT_XFER_ISOC ||
|
||||
qh->ep_is_in != 0) {
|
||||
qh->sched_frame =
|
||||
dwc2_frame_num_inc(qh->sched_frame, 1);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
qh->sched_frame = dwc2_frame_num_inc(qh->start_split_frame,
|
||||
qh->interval);
|
||||
if (dwc2_frame_num_le(qh->sched_frame, frame_number))
|
||||
qh->sched_frame = frame_number;
|
||||
qh->sched_frame |= 0x7;
|
||||
qh->start_split_frame = qh->sched_frame;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Deactivates a QH. For non-periodic QHs, removes the QH from the active
|
||||
* non-periodic schedule. The QH is added to the inactive non-periodic
|
||||
* schedule if any QTDs are still attached to the QH.
|
||||
*
|
||||
* For periodic QHs, the QH is removed from the periodic queued schedule. If
|
||||
* there are any QTDs still attached to the QH, the QH is added to either the
|
||||
* periodic inactive schedule or the periodic ready schedule and its next
|
||||
* scheduled frame is calculated. The QH is placed in the ready schedule if
|
||||
* the scheduled frame has been reached already. Otherwise it's placed in the
|
||||
* inactive schedule. If there are no QTDs attached to the QH, the QH is
|
||||
* completely removed from the periodic schedule.
|
||||
*/
|
||||
void dwc2_hcd_qh_deactivate(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh,
|
||||
int sched_next_periodic_split)
|
||||
{
|
||||
u16 frame_number;
|
||||
|
||||
if (dbg_qh(qh))
|
||||
dev_vdbg(hsotg->dev, "%s()\n", __func__);
|
||||
|
||||
if (dwc2_qh_is_non_per(qh)) {
|
||||
dwc2_hcd_qh_unlink(hsotg, qh);
|
||||
if (!list_empty(&qh->qtd_list))
|
||||
/* Add back to inactive non-periodic schedule */
|
||||
dwc2_hcd_qh_add(hsotg, qh);
|
||||
return;
|
||||
}
|
||||
|
||||
frame_number = dwc2_hcd_get_frame_number(hsotg);
|
||||
|
||||
if (qh->do_split) {
|
||||
dwc2_sched_periodic_split(hsotg, qh, frame_number,
|
||||
sched_next_periodic_split);
|
||||
} else {
|
||||
qh->sched_frame = dwc2_frame_num_inc(qh->sched_frame,
|
||||
qh->interval);
|
||||
if (dwc2_frame_num_le(qh->sched_frame, frame_number))
|
||||
qh->sched_frame = frame_number;
|
||||
}
|
||||
|
||||
if (list_empty(&qh->qtd_list)) {
|
||||
dwc2_hcd_qh_unlink(hsotg, qh);
|
||||
return;
|
||||
}
|
||||
/*
|
||||
* Remove from periodic_sched_queued and move to
|
||||
* appropriate queue
|
||||
*/
|
||||
if ((hsotg->core_params->uframe_sched > 0 &&
|
||||
dwc2_frame_num_le(qh->sched_frame, frame_number)) ||
|
||||
(hsotg->core_params->uframe_sched <= 0 &&
|
||||
qh->sched_frame == frame_number))
|
||||
list_move(&qh->qh_list_entry, &hsotg->periodic_sched_ready);
|
||||
else
|
||||
list_move(&qh->qh_list_entry, &hsotg->periodic_sched_inactive);
|
||||
}
|
||||
|
||||
/**
|
||||
* dwc2_hcd_qtd_init() - Initializes a QTD structure
|
||||
*
|
||||
* @qtd: The QTD to initialize
|
||||
* @urb: The associated URB
|
||||
*/
|
||||
void dwc2_hcd_qtd_init(struct dwc2_qtd *qtd, struct dwc2_hcd_urb *urb)
|
||||
{
|
||||
qtd->urb = urb;
|
||||
if (dwc2_hcd_get_pipe_type(&urb->pipe_info) ==
|
||||
USB_ENDPOINT_XFER_CONTROL) {
|
||||
/*
|
||||
* The only time the QTD data toggle is used is on the data
|
||||
* phase of control transfers. This phase always starts with
|
||||
* DATA1.
|
||||
*/
|
||||
qtd->data_toggle = DWC2_HC_PID_DATA1;
|
||||
qtd->control_phase = DWC2_CONTROL_SETUP;
|
||||
}
|
||||
|
||||
/* Start split */
|
||||
qtd->complete_split = 0;
|
||||
qtd->isoc_split_pos = DWC2_HCSPLT_XACTPOS_ALL;
|
||||
qtd->isoc_split_offset = 0;
|
||||
qtd->in_process = 0;
|
||||
|
||||
/* Store the qtd ptr in the urb to reference the QTD */
|
||||
urb->qtd = qtd;
|
||||
}
|
||||
|
||||
/**
|
||||
* dwc2_hcd_qtd_add() - Adds a QTD to the QTD-list of a QH
|
||||
*
|
||||
* @hsotg: The DWC HCD structure
|
||||
* @qtd: The QTD to add
|
||||
* @qh: Out parameter to return queue head
|
||||
* @atomic_alloc: Flag to do atomic alloc if needed
|
||||
*
|
||||
* Return: 0 if successful, negative error code otherwise
|
||||
*
|
||||
* Finds the correct QH to place the QTD into. If it does not find a QH, it
|
||||
* will create a new QH. If the QH to which the QTD is added is not currently
|
||||
* scheduled, it is placed into the proper schedule based on its EP type.
|
||||
*/
|
||||
int dwc2_hcd_qtd_add(struct dwc2_hsotg *hsotg, struct dwc2_qtd *qtd,
|
||||
struct dwc2_qh **qh, gfp_t mem_flags)
|
||||
{
|
||||
struct dwc2_hcd_urb *urb = qtd->urb;
|
||||
unsigned long flags;
|
||||
int allocated = 0;
|
||||
int retval;
|
||||
|
||||
/*
|
||||
* Get the QH which holds the QTD-list to insert to. Create QH if it
|
||||
* doesn't exist.
|
||||
*/
|
||||
if (*qh == NULL) {
|
||||
*qh = dwc2_hcd_qh_create(hsotg, urb, mem_flags);
|
||||
if (*qh == NULL)
|
||||
return -ENOMEM;
|
||||
allocated = 1;
|
||||
}
|
||||
|
||||
spin_lock_irqsave(&hsotg->lock, flags);
|
||||
|
||||
retval = dwc2_hcd_qh_add(hsotg, *qh);
|
||||
if (retval)
|
||||
goto fail;
|
||||
|
||||
qtd->qh = *qh;
|
||||
list_add_tail(&qtd->qtd_list_entry, &(*qh)->qtd_list);
|
||||
spin_unlock_irqrestore(&hsotg->lock, flags);
|
||||
|
||||
return 0;
|
||||
|
||||
fail:
|
||||
if (allocated) {
|
||||
struct dwc2_qtd *qtd2, *qtd2_tmp;
|
||||
struct dwc2_qh *qh_tmp = *qh;
|
||||
|
||||
*qh = NULL;
|
||||
dwc2_hcd_qh_unlink(hsotg, qh_tmp);
|
||||
|
||||
/* Free each QTD in the QH's QTD list */
|
||||
list_for_each_entry_safe(qtd2, qtd2_tmp, &qh_tmp->qtd_list,
|
||||
qtd_list_entry)
|
||||
dwc2_hcd_qtd_unlink_and_free(hsotg, qtd2, qh_tmp);
|
||||
|
||||
spin_unlock_irqrestore(&hsotg->lock, flags);
|
||||
dwc2_hcd_qh_free(hsotg, qh_tmp);
|
||||
} else {
|
||||
spin_unlock_irqrestore(&hsotg->lock, flags);
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
809
drivers/usb/dwc2/hw.h
Normal file
809
drivers/usb/dwc2/hw.h
Normal file
@@ -0,0 +1,809 @@
|
||||
/*
|
||||
* hw.h - DesignWare HS OTG Controller hardware definitions
|
||||
*
|
||||
* Copyright 2004-2013 Synopsys, Inc.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions, and the following disclaimer,
|
||||
* without modification.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. The names of the above-listed copyright holders may not be used
|
||||
* to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* ALTERNATIVELY, this software may be distributed under the terms of the
|
||||
* GNU General Public License ("GPL") as published by the Free Software
|
||||
* Foundation; either version 2 of the License, or (at your option) any
|
||||
* later version.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef __DWC2_HW_H__
|
||||
#define __DWC2_HW_H__
|
||||
|
||||
#define HSOTG_REG(x) (x)
|
||||
|
||||
#define GOTGCTL HSOTG_REG(0x000)
|
||||
#define GOTGCTL_CHIRPEN (1 << 27)
|
||||
#define GOTGCTL_MULT_VALID_BC_MASK (0x1f << 22)
|
||||
#define GOTGCTL_MULT_VALID_BC_SHIFT 22
|
||||
#define GOTGCTL_OTGVER (1 << 20)
|
||||
#define GOTGCTL_BSESVLD (1 << 19)
|
||||
#define GOTGCTL_ASESVLD (1 << 18)
|
||||
#define GOTGCTL_DBNC_SHORT (1 << 17)
|
||||
#define GOTGCTL_CONID_B (1 << 16)
|
||||
#define GOTGCTL_DEVHNPEN (1 << 11)
|
||||
#define GOTGCTL_HSTSETHNPEN (1 << 10)
|
||||
#define GOTGCTL_HNPREQ (1 << 9)
|
||||
#define GOTGCTL_HSTNEGSCS (1 << 8)
|
||||
#define GOTGCTL_SESREQ (1 << 1)
|
||||
#define GOTGCTL_SESREQSCS (1 << 0)
|
||||
|
||||
#define GOTGINT HSOTG_REG(0x004)
|
||||
#define GOTGINT_DBNCE_DONE (1 << 19)
|
||||
#define GOTGINT_A_DEV_TOUT_CHG (1 << 18)
|
||||
#define GOTGINT_HST_NEG_DET (1 << 17)
|
||||
#define GOTGINT_HST_NEG_SUC_STS_CHNG (1 << 9)
|
||||
#define GOTGINT_SES_REQ_SUC_STS_CHNG (1 << 8)
|
||||
#define GOTGINT_SES_END_DET (1 << 2)
|
||||
|
||||
#define GAHBCFG HSOTG_REG(0x008)
|
||||
#define GAHBCFG_AHB_SINGLE (1 << 23)
|
||||
#define GAHBCFG_NOTI_ALL_DMA_WRIT (1 << 22)
|
||||
#define GAHBCFG_REM_MEM_SUPP (1 << 21)
|
||||
#define GAHBCFG_P_TXF_EMP_LVL (1 << 8)
|
||||
#define GAHBCFG_NP_TXF_EMP_LVL (1 << 7)
|
||||
#define GAHBCFG_DMA_EN (1 << 5)
|
||||
#define GAHBCFG_HBSTLEN_MASK (0xf << 1)
|
||||
#define GAHBCFG_HBSTLEN_SHIFT 1
|
||||
#define GAHBCFG_HBSTLEN_SINGLE 0
|
||||
#define GAHBCFG_HBSTLEN_INCR 1
|
||||
#define GAHBCFG_HBSTLEN_INCR4 3
|
||||
#define GAHBCFG_HBSTLEN_INCR8 5
|
||||
#define GAHBCFG_HBSTLEN_INCR16 7
|
||||
#define GAHBCFG_GLBL_INTR_EN (1 << 0)
|
||||
#define GAHBCFG_CTRL_MASK (GAHBCFG_P_TXF_EMP_LVL | \
|
||||
GAHBCFG_NP_TXF_EMP_LVL | \
|
||||
GAHBCFG_DMA_EN | \
|
||||
GAHBCFG_GLBL_INTR_EN)
|
||||
|
||||
#define GUSBCFG HSOTG_REG(0x00C)
|
||||
#define GUSBCFG_FORCEDEVMODE (1 << 30)
|
||||
#define GUSBCFG_FORCEHOSTMODE (1 << 29)
|
||||
#define GUSBCFG_TXENDDELAY (1 << 28)
|
||||
#define GUSBCFG_ICTRAFFICPULLREMOVE (1 << 27)
|
||||
#define GUSBCFG_ICUSBCAP (1 << 26)
|
||||
#define GUSBCFG_ULPI_INT_PROT_DIS (1 << 25)
|
||||
#define GUSBCFG_INDICATORPASSTHROUGH (1 << 24)
|
||||
#define GUSBCFG_INDICATORCOMPLEMENT (1 << 23)
|
||||
#define GUSBCFG_TERMSELDLPULSE (1 << 22)
|
||||
#define GUSBCFG_ULPI_INT_VBUS_IND (1 << 21)
|
||||
#define GUSBCFG_ULPI_EXT_VBUS_DRV (1 << 20)
|
||||
#define GUSBCFG_ULPI_CLK_SUSP_M (1 << 19)
|
||||
#define GUSBCFG_ULPI_AUTO_RES (1 << 18)
|
||||
#define GUSBCFG_ULPI_FS_LS (1 << 17)
|
||||
#define GUSBCFG_OTG_UTMI_FS_SEL (1 << 16)
|
||||
#define GUSBCFG_PHY_LP_CLK_SEL (1 << 15)
|
||||
#define GUSBCFG_USBTRDTIM_MASK (0xf << 10)
|
||||
#define GUSBCFG_USBTRDTIM_SHIFT 10
|
||||
#define GUSBCFG_HNPCAP (1 << 9)
|
||||
#define GUSBCFG_SRPCAP (1 << 8)
|
||||
#define GUSBCFG_DDRSEL (1 << 7)
|
||||
#define GUSBCFG_PHYSEL (1 << 6)
|
||||
#define GUSBCFG_FSINTF (1 << 5)
|
||||
#define GUSBCFG_ULPI_UTMI_SEL (1 << 4)
|
||||
#define GUSBCFG_PHYIF16 (1 << 3)
|
||||
#define GUSBCFG_TOUTCAL_MASK (0x7 << 0)
|
||||
#define GUSBCFG_TOUTCAL_SHIFT 0
|
||||
#define GUSBCFG_TOUTCAL_LIMIT 0x7
|
||||
#define GUSBCFG_TOUTCAL(_x) ((_x) << 0)
|
||||
|
||||
#define GRSTCTL HSOTG_REG(0x010)
|
||||
#define GRSTCTL_AHBIDLE (1 << 31)
|
||||
#define GRSTCTL_DMAREQ (1 << 30)
|
||||
#define GRSTCTL_TXFNUM_MASK (0x1f << 6)
|
||||
#define GRSTCTL_TXFNUM_SHIFT 6
|
||||
#define GRSTCTL_TXFNUM_LIMIT 0x1f
|
||||
#define GRSTCTL_TXFNUM(_x) ((_x) << 6)
|
||||
#define GRSTCTL_TXFFLSH (1 << 5)
|
||||
#define GRSTCTL_RXFFLSH (1 << 4)
|
||||
#define GRSTCTL_IN_TKNQ_FLSH (1 << 3)
|
||||
#define GRSTCTL_FRMCNTRRST (1 << 2)
|
||||
#define GRSTCTL_HSFTRST (1 << 1)
|
||||
#define GRSTCTL_CSFTRST (1 << 0)
|
||||
|
||||
#define GINTSTS HSOTG_REG(0x014)
|
||||
#define GINTMSK HSOTG_REG(0x018)
|
||||
#define GINTSTS_WKUPINT (1 << 31)
|
||||
#define GINTSTS_SESSREQINT (1 << 30)
|
||||
#define GINTSTS_DISCONNINT (1 << 29)
|
||||
#define GINTSTS_CONIDSTSCHNG (1 << 28)
|
||||
#define GINTSTS_LPMTRANRCVD (1 << 27)
|
||||
#define GINTSTS_PTXFEMP (1 << 26)
|
||||
#define GINTSTS_HCHINT (1 << 25)
|
||||
#define GINTSTS_PRTINT (1 << 24)
|
||||
#define GINTSTS_RESETDET (1 << 23)
|
||||
#define GINTSTS_FET_SUSP (1 << 22)
|
||||
#define GINTSTS_INCOMPL_IP (1 << 21)
|
||||
#define GINTSTS_INCOMPL_SOIN (1 << 20)
|
||||
#define GINTSTS_OEPINT (1 << 19)
|
||||
#define GINTSTS_IEPINT (1 << 18)
|
||||
#define GINTSTS_EPMIS (1 << 17)
|
||||
#define GINTSTS_RESTOREDONE (1 << 16)
|
||||
#define GINTSTS_EOPF (1 << 15)
|
||||
#define GINTSTS_ISOUTDROP (1 << 14)
|
||||
#define GINTSTS_ENUMDONE (1 << 13)
|
||||
#define GINTSTS_USBRST (1 << 12)
|
||||
#define GINTSTS_USBSUSP (1 << 11)
|
||||
#define GINTSTS_ERLYSUSP (1 << 10)
|
||||
#define GINTSTS_I2CINT (1 << 9)
|
||||
#define GINTSTS_ULPI_CK_INT (1 << 8)
|
||||
#define GINTSTS_GOUTNAKEFF (1 << 7)
|
||||
#define GINTSTS_GINNAKEFF (1 << 6)
|
||||
#define GINTSTS_NPTXFEMP (1 << 5)
|
||||
#define GINTSTS_RXFLVL (1 << 4)
|
||||
#define GINTSTS_SOF (1 << 3)
|
||||
#define GINTSTS_OTGINT (1 << 2)
|
||||
#define GINTSTS_MODEMIS (1 << 1)
|
||||
#define GINTSTS_CURMODE_HOST (1 << 0)
|
||||
|
||||
#define GRXSTSR HSOTG_REG(0x01C)
|
||||
#define GRXSTSP HSOTG_REG(0x020)
|
||||
#define GRXSTS_FN_MASK (0x7f << 25)
|
||||
#define GRXSTS_FN_SHIFT 25
|
||||
#define GRXSTS_PKTSTS_MASK (0xf << 17)
|
||||
#define GRXSTS_PKTSTS_SHIFT 17
|
||||
#define GRXSTS_PKTSTS_GLOBALOUTNAK 1
|
||||
#define GRXSTS_PKTSTS_OUTRX 2
|
||||
#define GRXSTS_PKTSTS_HCHIN 2
|
||||
#define GRXSTS_PKTSTS_OUTDONE 3
|
||||
#define GRXSTS_PKTSTS_HCHIN_XFER_COMP 3
|
||||
#define GRXSTS_PKTSTS_SETUPDONE 4
|
||||
#define GRXSTS_PKTSTS_DATATOGGLEERR 5
|
||||
#define GRXSTS_PKTSTS_SETUPRX 6
|
||||
#define GRXSTS_PKTSTS_HCHHALTED 7
|
||||
#define GRXSTS_HCHNUM_MASK (0xf << 0)
|
||||
#define GRXSTS_HCHNUM_SHIFT 0
|
||||
#define GRXSTS_DPID_MASK (0x3 << 15)
|
||||
#define GRXSTS_DPID_SHIFT 15
|
||||
#define GRXSTS_BYTECNT_MASK (0x7ff << 4)
|
||||
#define GRXSTS_BYTECNT_SHIFT 4
|
||||
#define GRXSTS_EPNUM_MASK (0xf << 0)
|
||||
#define GRXSTS_EPNUM_SHIFT 0
|
||||
|
||||
#define GRXFSIZ HSOTG_REG(0x024)
|
||||
#define GRXFSIZ_DEPTH_MASK (0xffff << 0)
|
||||
#define GRXFSIZ_DEPTH_SHIFT 0
|
||||
|
||||
#define GNPTXFSIZ HSOTG_REG(0x028)
|
||||
/* Use FIFOSIZE_* constants to access this register */
|
||||
|
||||
#define GNPTXSTS HSOTG_REG(0x02C)
|
||||
#define GNPTXSTS_NP_TXQ_TOP_MASK (0x7f << 24)
|
||||
#define GNPTXSTS_NP_TXQ_TOP_SHIFT 24
|
||||
#define GNPTXSTS_NP_TXQ_SPC_AVAIL_MASK (0xff << 16)
|
||||
#define GNPTXSTS_NP_TXQ_SPC_AVAIL_SHIFT 16
|
||||
#define GNPTXSTS_NP_TXQ_SPC_AVAIL_GET(_v) (((_v) >> 16) & 0xff)
|
||||
#define GNPTXSTS_NP_TXF_SPC_AVAIL_MASK (0xffff << 0)
|
||||
#define GNPTXSTS_NP_TXF_SPC_AVAIL_SHIFT 0
|
||||
#define GNPTXSTS_NP_TXF_SPC_AVAIL_GET(_v) (((_v) >> 0) & 0xffff)
|
||||
|
||||
#define GI2CCTL HSOTG_REG(0x0030)
|
||||
#define GI2CCTL_BSYDNE (1 << 31)
|
||||
#define GI2CCTL_RW (1 << 30)
|
||||
#define GI2CCTL_I2CDATSE0 (1 << 28)
|
||||
#define GI2CCTL_I2CDEVADDR_MASK (0x3 << 26)
|
||||
#define GI2CCTL_I2CDEVADDR_SHIFT 26
|
||||
#define GI2CCTL_I2CSUSPCTL (1 << 25)
|
||||
#define GI2CCTL_ACK (1 << 24)
|
||||
#define GI2CCTL_I2CEN (1 << 23)
|
||||
#define GI2CCTL_ADDR_MASK (0x7f << 16)
|
||||
#define GI2CCTL_ADDR_SHIFT 16
|
||||
#define GI2CCTL_REGADDR_MASK (0xff << 8)
|
||||
#define GI2CCTL_REGADDR_SHIFT 8
|
||||
#define GI2CCTL_RWDATA_MASK (0xff << 0)
|
||||
#define GI2CCTL_RWDATA_SHIFT 0
|
||||
|
||||
#define GPVNDCTL HSOTG_REG(0x0034)
|
||||
#define GGPIO HSOTG_REG(0x0038)
|
||||
#define GUID HSOTG_REG(0x003c)
|
||||
#define GSNPSID HSOTG_REG(0x0040)
|
||||
#define GHWCFG1 HSOTG_REG(0x0044)
|
||||
|
||||
#define GHWCFG2 HSOTG_REG(0x0048)
|
||||
#define GHWCFG2_OTG_ENABLE_IC_USB (1 << 31)
|
||||
#define GHWCFG2_DEV_TOKEN_Q_DEPTH_MASK (0x1f << 26)
|
||||
#define GHWCFG2_DEV_TOKEN_Q_DEPTH_SHIFT 26
|
||||
#define GHWCFG2_HOST_PERIO_TX_Q_DEPTH_MASK (0x3 << 24)
|
||||
#define GHWCFG2_HOST_PERIO_TX_Q_DEPTH_SHIFT 24
|
||||
#define GHWCFG2_NONPERIO_TX_Q_DEPTH_MASK (0x3 << 22)
|
||||
#define GHWCFG2_NONPERIO_TX_Q_DEPTH_SHIFT 22
|
||||
#define GHWCFG2_MULTI_PROC_INT (1 << 20)
|
||||
#define GHWCFG2_DYNAMIC_FIFO (1 << 19)
|
||||
#define GHWCFG2_PERIO_EP_SUPPORTED (1 << 18)
|
||||
#define GHWCFG2_NUM_HOST_CHAN_MASK (0xf << 14)
|
||||
#define GHWCFG2_NUM_HOST_CHAN_SHIFT 14
|
||||
#define GHWCFG2_NUM_DEV_EP_MASK (0xf << 10)
|
||||
#define GHWCFG2_NUM_DEV_EP_SHIFT 10
|
||||
#define GHWCFG2_FS_PHY_TYPE_MASK (0x3 << 8)
|
||||
#define GHWCFG2_FS_PHY_TYPE_SHIFT 8
|
||||
#define GHWCFG2_FS_PHY_TYPE_NOT_SUPPORTED 0
|
||||
#define GHWCFG2_FS_PHY_TYPE_DEDICATED 1
|
||||
#define GHWCFG2_FS_PHY_TYPE_SHARED_UTMI 2
|
||||
#define GHWCFG2_FS_PHY_TYPE_SHARED_ULPI 3
|
||||
#define GHWCFG2_HS_PHY_TYPE_MASK (0x3 << 6)
|
||||
#define GHWCFG2_HS_PHY_TYPE_SHIFT 6
|
||||
#define GHWCFG2_HS_PHY_TYPE_NOT_SUPPORTED 0
|
||||
#define GHWCFG2_HS_PHY_TYPE_UTMI 1
|
||||
#define GHWCFG2_HS_PHY_TYPE_ULPI 2
|
||||
#define GHWCFG2_HS_PHY_TYPE_UTMI_ULPI 3
|
||||
#define GHWCFG2_POINT2POINT (1 << 5)
|
||||
#define GHWCFG2_ARCHITECTURE_MASK (0x3 << 3)
|
||||
#define GHWCFG2_ARCHITECTURE_SHIFT 3
|
||||
#define GHWCFG2_SLAVE_ONLY_ARCH 0
|
||||
#define GHWCFG2_EXT_DMA_ARCH 1
|
||||
#define GHWCFG2_INT_DMA_ARCH 2
|
||||
#define GHWCFG2_OP_MODE_MASK (0x7 << 0)
|
||||
#define GHWCFG2_OP_MODE_SHIFT 0
|
||||
#define GHWCFG2_OP_MODE_HNP_SRP_CAPABLE 0
|
||||
#define GHWCFG2_OP_MODE_SRP_ONLY_CAPABLE 1
|
||||
#define GHWCFG2_OP_MODE_NO_HNP_SRP_CAPABLE 2
|
||||
#define GHWCFG2_OP_MODE_SRP_CAPABLE_DEVICE 3
|
||||
#define GHWCFG2_OP_MODE_NO_SRP_CAPABLE_DEVICE 4
|
||||
#define GHWCFG2_OP_MODE_SRP_CAPABLE_HOST 5
|
||||
#define GHWCFG2_OP_MODE_NO_SRP_CAPABLE_HOST 6
|
||||
#define GHWCFG2_OP_MODE_UNDEFINED 7
|
||||
|
||||
#define GHWCFG3 HSOTG_REG(0x004c)
|
||||
#define GHWCFG3_DFIFO_DEPTH_MASK (0xffff << 16)
|
||||
#define GHWCFG3_DFIFO_DEPTH_SHIFT 16
|
||||
#define GHWCFG3_OTG_LPM_EN (1 << 15)
|
||||
#define GHWCFG3_BC_SUPPORT (1 << 14)
|
||||
#define GHWCFG3_OTG_ENABLE_HSIC (1 << 13)
|
||||
#define GHWCFG3_ADP_SUPP (1 << 12)
|
||||
#define GHWCFG3_SYNCH_RESET_TYPE (1 << 11)
|
||||
#define GHWCFG3_OPTIONAL_FEATURES (1 << 10)
|
||||
#define GHWCFG3_VENDOR_CTRL_IF (1 << 9)
|
||||
#define GHWCFG3_I2C (1 << 8)
|
||||
#define GHWCFG3_OTG_FUNC (1 << 7)
|
||||
#define GHWCFG3_PACKET_SIZE_CNTR_WIDTH_MASK (0x7 << 4)
|
||||
#define GHWCFG3_PACKET_SIZE_CNTR_WIDTH_SHIFT 4
|
||||
#define GHWCFG3_XFER_SIZE_CNTR_WIDTH_MASK (0xf << 0)
|
||||
#define GHWCFG3_XFER_SIZE_CNTR_WIDTH_SHIFT 0
|
||||
|
||||
#define GHWCFG4 HSOTG_REG(0x0050)
|
||||
#define GHWCFG4_DESC_DMA_DYN (1 << 31)
|
||||
#define GHWCFG4_DESC_DMA (1 << 30)
|
||||
#define GHWCFG4_NUM_IN_EPS_MASK (0xf << 26)
|
||||
#define GHWCFG4_NUM_IN_EPS_SHIFT 26
|
||||
#define GHWCFG4_DED_FIFO_EN (1 << 25)
|
||||
#define GHWCFG4_SESSION_END_FILT_EN (1 << 24)
|
||||
#define GHWCFG4_B_VALID_FILT_EN (1 << 23)
|
||||
#define GHWCFG4_A_VALID_FILT_EN (1 << 22)
|
||||
#define GHWCFG4_VBUS_VALID_FILT_EN (1 << 21)
|
||||
#define GHWCFG4_IDDIG_FILT_EN (1 << 20)
|
||||
#define GHWCFG4_NUM_DEV_MODE_CTRL_EP_MASK (0xf << 16)
|
||||
#define GHWCFG4_NUM_DEV_MODE_CTRL_EP_SHIFT 16
|
||||
#define GHWCFG4_UTMI_PHY_DATA_WIDTH_MASK (0x3 << 14)
|
||||
#define GHWCFG4_UTMI_PHY_DATA_WIDTH_SHIFT 14
|
||||
#define GHWCFG4_UTMI_PHY_DATA_WIDTH_8 0
|
||||
#define GHWCFG4_UTMI_PHY_DATA_WIDTH_16 1
|
||||
#define GHWCFG4_UTMI_PHY_DATA_WIDTH_8_OR_16 2
|
||||
#define GHWCFG4_XHIBER (1 << 7)
|
||||
#define GHWCFG4_HIBER (1 << 6)
|
||||
#define GHWCFG4_MIN_AHB_FREQ (1 << 5)
|
||||
#define GHWCFG4_POWER_OPTIMIZ (1 << 4)
|
||||
#define GHWCFG4_NUM_DEV_PERIO_IN_EP_MASK (0xf << 0)
|
||||
#define GHWCFG4_NUM_DEV_PERIO_IN_EP_SHIFT 0
|
||||
|
||||
#define GLPMCFG HSOTG_REG(0x0054)
|
||||
#define GLPMCFG_INV_SEL_HSIC (1 << 31)
|
||||
#define GLPMCFG_HSIC_CONNECT (1 << 30)
|
||||
#define GLPMCFG_RETRY_COUNT_STS_MASK (0x7 << 25)
|
||||
#define GLPMCFG_RETRY_COUNT_STS_SHIFT 25
|
||||
#define GLPMCFG_SEND_LPM (1 << 24)
|
||||
#define GLPMCFG_RETRY_COUNT_MASK (0x7 << 21)
|
||||
#define GLPMCFG_RETRY_COUNT_SHIFT 21
|
||||
#define GLPMCFG_LPM_CHAN_INDEX_MASK (0xf << 17)
|
||||
#define GLPMCFG_LPM_CHAN_INDEX_SHIFT 17
|
||||
#define GLPMCFG_SLEEP_STATE_RESUMEOK (1 << 16)
|
||||
#define GLPMCFG_PRT_SLEEP_STS (1 << 15)
|
||||
#define GLPMCFG_LPM_RESP_MASK (0x3 << 13)
|
||||
#define GLPMCFG_LPM_RESP_SHIFT 13
|
||||
#define GLPMCFG_HIRD_THRES_MASK (0x1f << 8)
|
||||
#define GLPMCFG_HIRD_THRES_SHIFT 8
|
||||
#define GLPMCFG_HIRD_THRES_EN (0x10 << 8)
|
||||
#define GLPMCFG_EN_UTMI_SLEEP (1 << 7)
|
||||
#define GLPMCFG_REM_WKUP_EN (1 << 6)
|
||||
#define GLPMCFG_HIRD_MASK (0xf << 2)
|
||||
#define GLPMCFG_HIRD_SHIFT 2
|
||||
#define GLPMCFG_APPL_RESP (1 << 1)
|
||||
#define GLPMCFG_LPM_CAP_EN (1 << 0)
|
||||
|
||||
#define GPWRDN HSOTG_REG(0x0058)
|
||||
#define GPWRDN_MULT_VAL_ID_BC_MASK (0x1f << 24)
|
||||
#define GPWRDN_MULT_VAL_ID_BC_SHIFT 24
|
||||
#define GPWRDN_ADP_INT (1 << 23)
|
||||
#define GPWRDN_BSESSVLD (1 << 22)
|
||||
#define GPWRDN_IDSTS (1 << 21)
|
||||
#define GPWRDN_LINESTATE_MASK (0x3 << 19)
|
||||
#define GPWRDN_LINESTATE_SHIFT 19
|
||||
#define GPWRDN_STS_CHGINT_MSK (1 << 18)
|
||||
#define GPWRDN_STS_CHGINT (1 << 17)
|
||||
#define GPWRDN_SRP_DET_MSK (1 << 16)
|
||||
#define GPWRDN_SRP_DET (1 << 15)
|
||||
#define GPWRDN_CONNECT_DET_MSK (1 << 14)
|
||||
#define GPWRDN_CONNECT_DET (1 << 13)
|
||||
#define GPWRDN_DISCONN_DET_MSK (1 << 12)
|
||||
#define GPWRDN_DISCONN_DET (1 << 11)
|
||||
#define GPWRDN_RST_DET_MSK (1 << 10)
|
||||
#define GPWRDN_RST_DET (1 << 9)
|
||||
#define GPWRDN_LNSTSCHG_MSK (1 << 8)
|
||||
#define GPWRDN_LNSTSCHG (1 << 7)
|
||||
#define GPWRDN_DIS_VBUS (1 << 6)
|
||||
#define GPWRDN_PWRDNSWTCH (1 << 5)
|
||||
#define GPWRDN_PWRDNRSTN (1 << 4)
|
||||
#define GPWRDN_PWRDNCLMP (1 << 3)
|
||||
#define GPWRDN_RESTORE (1 << 2)
|
||||
#define GPWRDN_PMUACTV (1 << 1)
|
||||
#define GPWRDN_PMUINTSEL (1 << 0)
|
||||
|
||||
#define GDFIFOCFG HSOTG_REG(0x005c)
|
||||
#define GDFIFOCFG_EPINFOBASE_MASK (0xffff << 16)
|
||||
#define GDFIFOCFG_EPINFOBASE_SHIFT 16
|
||||
#define GDFIFOCFG_GDFIFOCFG_MASK (0xffff << 0)
|
||||
#define GDFIFOCFG_GDFIFOCFG_SHIFT 0
|
||||
|
||||
#define ADPCTL HSOTG_REG(0x0060)
|
||||
#define ADPCTL_AR_MASK (0x3 << 27)
|
||||
#define ADPCTL_AR_SHIFT 27
|
||||
#define ADPCTL_ADP_TMOUT_INT_MSK (1 << 26)
|
||||
#define ADPCTL_ADP_SNS_INT_MSK (1 << 25)
|
||||
#define ADPCTL_ADP_PRB_INT_MSK (1 << 24)
|
||||
#define ADPCTL_ADP_TMOUT_INT (1 << 23)
|
||||
#define ADPCTL_ADP_SNS_INT (1 << 22)
|
||||
#define ADPCTL_ADP_PRB_INT (1 << 21)
|
||||
#define ADPCTL_ADPENA (1 << 20)
|
||||
#define ADPCTL_ADPRES (1 << 19)
|
||||
#define ADPCTL_ENASNS (1 << 18)
|
||||
#define ADPCTL_ENAPRB (1 << 17)
|
||||
#define ADPCTL_RTIM_MASK (0x7ff << 6)
|
||||
#define ADPCTL_RTIM_SHIFT 6
|
||||
#define ADPCTL_PRB_PER_MASK (0x3 << 4)
|
||||
#define ADPCTL_PRB_PER_SHIFT 4
|
||||
#define ADPCTL_PRB_DELTA_MASK (0x3 << 2)
|
||||
#define ADPCTL_PRB_DELTA_SHIFT 2
|
||||
#define ADPCTL_PRB_DSCHRG_MASK (0x3 << 0)
|
||||
#define ADPCTL_PRB_DSCHRG_SHIFT 0
|
||||
|
||||
#define HPTXFSIZ HSOTG_REG(0x100)
|
||||
/* Use FIFOSIZE_* constants to access this register */
|
||||
|
||||
#define DPTXFSIZN(_a) HSOTG_REG(0x104 + (((_a) - 1) * 4))
|
||||
/* Use FIFOSIZE_* constants to access this register */
|
||||
|
||||
/* These apply to the GNPTXFSIZ, HPTXFSIZ and DPTXFSIZN registers */
|
||||
#define FIFOSIZE_DEPTH_MASK (0xffff << 16)
|
||||
#define FIFOSIZE_DEPTH_SHIFT 16
|
||||
#define FIFOSIZE_STARTADDR_MASK (0xffff << 0)
|
||||
#define FIFOSIZE_STARTADDR_SHIFT 0
|
||||
|
||||
/* Device mode registers */
|
||||
|
||||
#define DCFG HSOTG_REG(0x800)
|
||||
#define DCFG_EPMISCNT_MASK (0x1f << 18)
|
||||
#define DCFG_EPMISCNT_SHIFT 18
|
||||
#define DCFG_EPMISCNT_LIMIT 0x1f
|
||||
#define DCFG_EPMISCNT(_x) ((_x) << 18)
|
||||
#define DCFG_PERFRINT_MASK (0x3 << 11)
|
||||
#define DCFG_PERFRINT_SHIFT 11
|
||||
#define DCFG_PERFRINT_LIMIT 0x3
|
||||
#define DCFG_PERFRINT(_x) ((_x) << 11)
|
||||
#define DCFG_DEVADDR_MASK (0x7f << 4)
|
||||
#define DCFG_DEVADDR_SHIFT 4
|
||||
#define DCFG_DEVADDR_LIMIT 0x7f
|
||||
#define DCFG_DEVADDR(_x) ((_x) << 4)
|
||||
#define DCFG_NZ_STS_OUT_HSHK (1 << 2)
|
||||
#define DCFG_DEVSPD_MASK (0x3 << 0)
|
||||
#define DCFG_DEVSPD_SHIFT 0
|
||||
#define DCFG_DEVSPD_HS 0
|
||||
#define DCFG_DEVSPD_FS 1
|
||||
#define DCFG_DEVSPD_LS 2
|
||||
#define DCFG_DEVSPD_FS48 3
|
||||
|
||||
#define DCTL HSOTG_REG(0x804)
|
||||
#define DCTL_PWRONPRGDONE (1 << 11)
|
||||
#define DCTL_CGOUTNAK (1 << 10)
|
||||
#define DCTL_SGOUTNAK (1 << 9)
|
||||
#define DCTL_CGNPINNAK (1 << 8)
|
||||
#define DCTL_SGNPINNAK (1 << 7)
|
||||
#define DCTL_TSTCTL_MASK (0x7 << 4)
|
||||
#define DCTL_TSTCTL_SHIFT 4
|
||||
#define DCTL_GOUTNAKSTS (1 << 3)
|
||||
#define DCTL_GNPINNAKSTS (1 << 2)
|
||||
#define DCTL_SFTDISCON (1 << 1)
|
||||
#define DCTL_RMTWKUPSIG (1 << 0)
|
||||
|
||||
#define DSTS HSOTG_REG(0x808)
|
||||
#define DSTS_SOFFN_MASK (0x3fff << 8)
|
||||
#define DSTS_SOFFN_SHIFT 8
|
||||
#define DSTS_SOFFN_LIMIT 0x3fff
|
||||
#define DSTS_SOFFN(_x) ((_x) << 8)
|
||||
#define DSTS_ERRATICERR (1 << 3)
|
||||
#define DSTS_ENUMSPD_MASK (0x3 << 1)
|
||||
#define DSTS_ENUMSPD_SHIFT 1
|
||||
#define DSTS_ENUMSPD_HS 0
|
||||
#define DSTS_ENUMSPD_FS 1
|
||||
#define DSTS_ENUMSPD_LS 2
|
||||
#define DSTS_ENUMSPD_FS48 3
|
||||
#define DSTS_SUSPSTS (1 << 0)
|
||||
|
||||
#define DIEPMSK HSOTG_REG(0x810)
|
||||
#define DIEPMSK_TXFIFOEMPTY (1 << 7)
|
||||
#define DIEPMSK_INEPNAKEFFMSK (1 << 6)
|
||||
#define DIEPMSK_INTKNEPMISMSK (1 << 5)
|
||||
#define DIEPMSK_INTKNTXFEMPMSK (1 << 4)
|
||||
#define DIEPMSK_TIMEOUTMSK (1 << 3)
|
||||
#define DIEPMSK_AHBERRMSK (1 << 2)
|
||||
#define DIEPMSK_EPDISBLDMSK (1 << 1)
|
||||
#define DIEPMSK_XFERCOMPLMSK (1 << 0)
|
||||
|
||||
#define DOEPMSK HSOTG_REG(0x814)
|
||||
#define DOEPMSK_BACK2BACKSETUP (1 << 6)
|
||||
#define DOEPMSK_OUTTKNEPDISMSK (1 << 4)
|
||||
#define DOEPMSK_SETUPMSK (1 << 3)
|
||||
#define DOEPMSK_AHBERRMSK (1 << 2)
|
||||
#define DOEPMSK_EPDISBLDMSK (1 << 1)
|
||||
#define DOEPMSK_XFERCOMPLMSK (1 << 0)
|
||||
|
||||
#define DAINT HSOTG_REG(0x818)
|
||||
#define DAINTMSK HSOTG_REG(0x81C)
|
||||
#define DAINT_OUTEP_SHIFT 16
|
||||
#define DAINT_OUTEP(_x) (1 << ((_x) + 16))
|
||||
#define DAINT_INEP(_x) (1 << (_x))
|
||||
|
||||
#define DTKNQR1 HSOTG_REG(0x820)
|
||||
#define DTKNQR2 HSOTG_REG(0x824)
|
||||
#define DTKNQR3 HSOTG_REG(0x830)
|
||||
#define DTKNQR4 HSOTG_REG(0x834)
|
||||
|
||||
#define DVBUSDIS HSOTG_REG(0x828)
|
||||
#define DVBUSPULSE HSOTG_REG(0x82C)
|
||||
|
||||
#define DIEPCTL0 HSOTG_REG(0x900)
|
||||
#define DIEPCTL(_a) HSOTG_REG(0x900 + ((_a) * 0x20))
|
||||
|
||||
#define DOEPCTL0 HSOTG_REG(0xB00)
|
||||
#define DOEPCTL(_a) HSOTG_REG(0xB00 + ((_a) * 0x20))
|
||||
|
||||
/* EP0 specialness:
|
||||
* bits[29..28] - reserved (no SetD0PID, SetD1PID)
|
||||
* bits[25..22] - should always be zero, this isn't a periodic endpoint
|
||||
* bits[10..0] - MPS setting different for EP0
|
||||
*/
|
||||
#define D0EPCTL_MPS_MASK (0x3 << 0)
|
||||
#define D0EPCTL_MPS_SHIFT 0
|
||||
#define D0EPCTL_MPS_64 0
|
||||
#define D0EPCTL_MPS_32 1
|
||||
#define D0EPCTL_MPS_16 2
|
||||
#define D0EPCTL_MPS_8 3
|
||||
|
||||
#define DXEPCTL_EPENA (1 << 31)
|
||||
#define DXEPCTL_EPDIS (1 << 30)
|
||||
#define DXEPCTL_SETD1PID (1 << 29)
|
||||
#define DXEPCTL_SETODDFR (1 << 29)
|
||||
#define DXEPCTL_SETD0PID (1 << 28)
|
||||
#define DXEPCTL_SETEVENFR (1 << 28)
|
||||
#define DXEPCTL_SNAK (1 << 27)
|
||||
#define DXEPCTL_CNAK (1 << 26)
|
||||
#define DXEPCTL_TXFNUM_MASK (0xf << 22)
|
||||
#define DXEPCTL_TXFNUM_SHIFT 22
|
||||
#define DXEPCTL_TXFNUM_LIMIT 0xf
|
||||
#define DXEPCTL_TXFNUM(_x) ((_x) << 22)
|
||||
#define DXEPCTL_STALL (1 << 21)
|
||||
#define DXEPCTL_SNP (1 << 20)
|
||||
#define DXEPCTL_EPTYPE_MASK (0x3 << 18)
|
||||
#define DXEPCTL_EPTYPE_SHIFT 18
|
||||
#define DXEPCTL_EPTYPE_CONTROL 0
|
||||
#define DXEPCTL_EPTYPE_ISO 1
|
||||
#define DXEPCTL_EPTYPE_BULK 2
|
||||
#define DXEPCTL_EPTYPE_INTTERUPT 3
|
||||
#define DXEPCTL_NAKSTS (1 << 17)
|
||||
#define DXEPCTL_DPID (1 << 16)
|
||||
#define DXEPCTL_EOFRNUM (1 << 16)
|
||||
#define DXEPCTL_USBACTEP (1 << 15)
|
||||
#define DXEPCTL_NEXTEP_MASK (0xf << 11)
|
||||
#define DXEPCTL_NEXTEP_SHIFT 11
|
||||
#define DXEPCTL_NEXTEP_LIMIT 0xf
|
||||
#define DXEPCTL_NEXTEP(_x) ((_x) << 11)
|
||||
#define DXEPCTL_MPS_MASK (0x7ff << 0)
|
||||
#define DXEPCTL_MPS_SHIFT 0
|
||||
#define DXEPCTL_MPS_LIMIT 0x7ff
|
||||
#define DXEPCTL_MPS(_x) ((_x) << 0)
|
||||
|
||||
#define DIEPINT(_a) HSOTG_REG(0x908 + ((_a) * 0x20))
|
||||
#define DOEPINT(_a) HSOTG_REG(0xB08 + ((_a) * 0x20))
|
||||
#define DXEPINT_INEPNAKEFF (1 << 6)
|
||||
#define DXEPINT_BACK2BACKSETUP (1 << 6)
|
||||
#define DXEPINT_INTKNEPMIS (1 << 5)
|
||||
#define DXEPINT_INTKNTXFEMP (1 << 4)
|
||||
#define DXEPINT_OUTTKNEPDIS (1 << 4)
|
||||
#define DXEPINT_TIMEOUT (1 << 3)
|
||||
#define DXEPINT_SETUP (1 << 3)
|
||||
#define DXEPINT_AHBERR (1 << 2)
|
||||
#define DXEPINT_EPDISBLD (1 << 1)
|
||||
#define DXEPINT_XFERCOMPL (1 << 0)
|
||||
|
||||
#define DIEPTSIZ0 HSOTG_REG(0x910)
|
||||
#define DIEPTSIZ0_PKTCNT_MASK (0x3 << 19)
|
||||
#define DIEPTSIZ0_PKTCNT_SHIFT 19
|
||||
#define DIEPTSIZ0_PKTCNT_LIMIT 0x3
|
||||
#define DIEPTSIZ0_PKTCNT(_x) ((_x) << 19)
|
||||
#define DIEPTSIZ0_XFERSIZE_MASK (0x7f << 0)
|
||||
#define DIEPTSIZ0_XFERSIZE_SHIFT 0
|
||||
#define DIEPTSIZ0_XFERSIZE_LIMIT 0x7f
|
||||
#define DIEPTSIZ0_XFERSIZE(_x) ((_x) << 0)
|
||||
|
||||
#define DOEPTSIZ0 HSOTG_REG(0xB10)
|
||||
#define DOEPTSIZ0_SUPCNT_MASK (0x3 << 29)
|
||||
#define DOEPTSIZ0_SUPCNT_SHIFT 29
|
||||
#define DOEPTSIZ0_SUPCNT_LIMIT 0x3
|
||||
#define DOEPTSIZ0_SUPCNT(_x) ((_x) << 29)
|
||||
#define DOEPTSIZ0_PKTCNT (1 << 19)
|
||||
#define DOEPTSIZ0_XFERSIZE_MASK (0x7f << 0)
|
||||
#define DOEPTSIZ0_XFERSIZE_SHIFT 0
|
||||
|
||||
#define DIEPTSIZ(_a) HSOTG_REG(0x910 + ((_a) * 0x20))
|
||||
#define DOEPTSIZ(_a) HSOTG_REG(0xB10 + ((_a) * 0x20))
|
||||
#define DXEPTSIZ_MC_MASK (0x3 << 29)
|
||||
#define DXEPTSIZ_MC_SHIFT 29
|
||||
#define DXEPTSIZ_MC_LIMIT 0x3
|
||||
#define DXEPTSIZ_MC(_x) ((_x) << 29)
|
||||
#define DXEPTSIZ_PKTCNT_MASK (0x3ff << 19)
|
||||
#define DXEPTSIZ_PKTCNT_SHIFT 19
|
||||
#define DXEPTSIZ_PKTCNT_LIMIT 0x3ff
|
||||
#define DXEPTSIZ_PKTCNT_GET(_v) (((_v) >> 19) & 0x3ff)
|
||||
#define DXEPTSIZ_PKTCNT(_x) ((_x) << 19)
|
||||
#define DXEPTSIZ_XFERSIZE_MASK (0x7ffff << 0)
|
||||
#define DXEPTSIZ_XFERSIZE_SHIFT 0
|
||||
#define DXEPTSIZ_XFERSIZE_LIMIT 0x7ffff
|
||||
#define DXEPTSIZ_XFERSIZE_GET(_v) (((_v) >> 0) & 0x7ffff)
|
||||
#define DXEPTSIZ_XFERSIZE(_x) ((_x) << 0)
|
||||
|
||||
#define DIEPDMA(_a) HSOTG_REG(0x914 + ((_a) * 0x20))
|
||||
#define DOEPDMA(_a) HSOTG_REG(0xB14 + ((_a) * 0x20))
|
||||
|
||||
#define DTXFSTS(_a) HSOTG_REG(0x918 + ((_a) * 0x20))
|
||||
|
||||
#define PCGCTL HSOTG_REG(0x0e00)
|
||||
#define PCGCTL_IF_DEV_MODE (1 << 31)
|
||||
#define PCGCTL_P2HD_PRT_SPD_MASK (0x3 << 29)
|
||||
#define PCGCTL_P2HD_PRT_SPD_SHIFT 29
|
||||
#define PCGCTL_P2HD_DEV_ENUM_SPD_MASK (0x3 << 27)
|
||||
#define PCGCTL_P2HD_DEV_ENUM_SPD_SHIFT 27
|
||||
#define PCGCTL_MAC_DEV_ADDR_MASK (0x7f << 20)
|
||||
#define PCGCTL_MAC_DEV_ADDR_SHIFT 20
|
||||
#define PCGCTL_MAX_TERMSEL (1 << 19)
|
||||
#define PCGCTL_MAX_XCVRSELECT_MASK (0x3 << 17)
|
||||
#define PCGCTL_MAX_XCVRSELECT_SHIFT 17
|
||||
#define PCGCTL_PORT_POWER (1 << 16)
|
||||
#define PCGCTL_PRT_CLK_SEL_MASK (0x3 << 14)
|
||||
#define PCGCTL_PRT_CLK_SEL_SHIFT 14
|
||||
#define PCGCTL_ESS_REG_RESTORED (1 << 13)
|
||||
#define PCGCTL_EXTND_HIBER_SWITCH (1 << 12)
|
||||
#define PCGCTL_EXTND_HIBER_PWRCLMP (1 << 11)
|
||||
#define PCGCTL_ENBL_EXTND_HIBER (1 << 10)
|
||||
#define PCGCTL_RESTOREMODE (1 << 9)
|
||||
#define PCGCTL_RESETAFTSUSP (1 << 8)
|
||||
#define PCGCTL_DEEP_SLEEP (1 << 7)
|
||||
#define PCGCTL_PHY_IN_SLEEP (1 << 6)
|
||||
#define PCGCTL_ENBL_SLEEP_GATING (1 << 5)
|
||||
#define PCGCTL_RSTPDWNMODULE (1 << 3)
|
||||
#define PCGCTL_PWRCLMP (1 << 2)
|
||||
#define PCGCTL_GATEHCLK (1 << 1)
|
||||
#define PCGCTL_STOPPCLK (1 << 0)
|
||||
|
||||
#define EPFIFO(_a) HSOTG_REG(0x1000 + ((_a) * 0x1000))
|
||||
|
||||
/* Host Mode Registers */
|
||||
|
||||
#define HCFG HSOTG_REG(0x0400)
|
||||
#define HCFG_MODECHTIMEN (1 << 31)
|
||||
#define HCFG_PERSCHEDENA (1 << 26)
|
||||
#define HCFG_FRLISTEN_MASK (0x3 << 24)
|
||||
#define HCFG_FRLISTEN_SHIFT 24
|
||||
#define HCFG_FRLISTEN_8 (0 << 24)
|
||||
#define FRLISTEN_8_SIZE 8
|
||||
#define HCFG_FRLISTEN_16 (1 << 24)
|
||||
#define FRLISTEN_16_SIZE 16
|
||||
#define HCFG_FRLISTEN_32 (2 << 24)
|
||||
#define FRLISTEN_32_SIZE 32
|
||||
#define HCFG_FRLISTEN_64 (3 << 24)
|
||||
#define FRLISTEN_64_SIZE 64
|
||||
#define HCFG_DESCDMA (1 << 23)
|
||||
#define HCFG_RESVALID_MASK (0xff << 8)
|
||||
#define HCFG_RESVALID_SHIFT 8
|
||||
#define HCFG_ENA32KHZ (1 << 7)
|
||||
#define HCFG_FSLSSUPP (1 << 2)
|
||||
#define HCFG_FSLSPCLKSEL_MASK (0x3 << 0)
|
||||
#define HCFG_FSLSPCLKSEL_SHIFT 0
|
||||
#define HCFG_FSLSPCLKSEL_30_60_MHZ 0
|
||||
#define HCFG_FSLSPCLKSEL_48_MHZ 1
|
||||
#define HCFG_FSLSPCLKSEL_6_MHZ 2
|
||||
|
||||
#define HFIR HSOTG_REG(0x0404)
|
||||
#define HFIR_FRINT_MASK (0xffff << 0)
|
||||
#define HFIR_FRINT_SHIFT 0
|
||||
#define HFIR_RLDCTRL (1 << 16)
|
||||
|
||||
#define HFNUM HSOTG_REG(0x0408)
|
||||
#define HFNUM_FRREM_MASK (0xffff << 16)
|
||||
#define HFNUM_FRREM_SHIFT 16
|
||||
#define HFNUM_FRNUM_MASK (0xffff << 0)
|
||||
#define HFNUM_FRNUM_SHIFT 0
|
||||
#define HFNUM_MAX_FRNUM 0x3fff
|
||||
|
||||
#define HPTXSTS HSOTG_REG(0x0410)
|
||||
#define TXSTS_QTOP_ODD (1 << 31)
|
||||
#define TXSTS_QTOP_CHNEP_MASK (0xf << 27)
|
||||
#define TXSTS_QTOP_CHNEP_SHIFT 27
|
||||
#define TXSTS_QTOP_TOKEN_MASK (0x3 << 25)
|
||||
#define TXSTS_QTOP_TOKEN_SHIFT 25
|
||||
#define TXSTS_QTOP_TERMINATE (1 << 24)
|
||||
#define TXSTS_QSPCAVAIL_MASK (0xff << 16)
|
||||
#define TXSTS_QSPCAVAIL_SHIFT 16
|
||||
#define TXSTS_FSPCAVAIL_MASK (0xffff << 0)
|
||||
#define TXSTS_FSPCAVAIL_SHIFT 0
|
||||
|
||||
#define HAINT HSOTG_REG(0x0414)
|
||||
#define HAINTMSK HSOTG_REG(0x0418)
|
||||
#define HFLBADDR HSOTG_REG(0x041c)
|
||||
|
||||
#define HPRT0 HSOTG_REG(0x0440)
|
||||
#define HPRT0_SPD_MASK (0x3 << 17)
|
||||
#define HPRT0_SPD_SHIFT 17
|
||||
#define HPRT0_SPD_HIGH_SPEED 0
|
||||
#define HPRT0_SPD_FULL_SPEED 1
|
||||
#define HPRT0_SPD_LOW_SPEED 2
|
||||
#define HPRT0_TSTCTL_MASK (0xf << 13)
|
||||
#define HPRT0_TSTCTL_SHIFT 13
|
||||
#define HPRT0_PWR (1 << 12)
|
||||
#define HPRT0_LNSTS_MASK (0x3 << 10)
|
||||
#define HPRT0_LNSTS_SHIFT 10
|
||||
#define HPRT0_RST (1 << 8)
|
||||
#define HPRT0_SUSP (1 << 7)
|
||||
#define HPRT0_RES (1 << 6)
|
||||
#define HPRT0_OVRCURRCHG (1 << 5)
|
||||
#define HPRT0_OVRCURRACT (1 << 4)
|
||||
#define HPRT0_ENACHG (1 << 3)
|
||||
#define HPRT0_ENA (1 << 2)
|
||||
#define HPRT0_CONNDET (1 << 1)
|
||||
#define HPRT0_CONNSTS (1 << 0)
|
||||
|
||||
#define HCCHAR(_ch) HSOTG_REG(0x0500 + 0x20 * (_ch))
|
||||
#define HCCHAR_CHENA (1 << 31)
|
||||
#define HCCHAR_CHDIS (1 << 30)
|
||||
#define HCCHAR_ODDFRM (1 << 29)
|
||||
#define HCCHAR_DEVADDR_MASK (0x7f << 22)
|
||||
#define HCCHAR_DEVADDR_SHIFT 22
|
||||
#define HCCHAR_MULTICNT_MASK (0x3 << 20)
|
||||
#define HCCHAR_MULTICNT_SHIFT 20
|
||||
#define HCCHAR_EPTYPE_MASK (0x3 << 18)
|
||||
#define HCCHAR_EPTYPE_SHIFT 18
|
||||
#define HCCHAR_LSPDDEV (1 << 17)
|
||||
#define HCCHAR_EPDIR (1 << 15)
|
||||
#define HCCHAR_EPNUM_MASK (0xf << 11)
|
||||
#define HCCHAR_EPNUM_SHIFT 11
|
||||
#define HCCHAR_MPS_MASK (0x7ff << 0)
|
||||
#define HCCHAR_MPS_SHIFT 0
|
||||
|
||||
#define HCSPLT(_ch) HSOTG_REG(0x0504 + 0x20 * (_ch))
|
||||
#define HCSPLT_SPLTENA (1 << 31)
|
||||
#define HCSPLT_COMPSPLT (1 << 16)
|
||||
#define HCSPLT_XACTPOS_MASK (0x3 << 14)
|
||||
#define HCSPLT_XACTPOS_SHIFT 14
|
||||
#define HCSPLT_XACTPOS_MID 0
|
||||
#define HCSPLT_XACTPOS_END 1
|
||||
#define HCSPLT_XACTPOS_BEGIN 2
|
||||
#define HCSPLT_XACTPOS_ALL 3
|
||||
#define HCSPLT_HUBADDR_MASK (0x7f << 7)
|
||||
#define HCSPLT_HUBADDR_SHIFT 7
|
||||
#define HCSPLT_PRTADDR_MASK (0x7f << 0)
|
||||
#define HCSPLT_PRTADDR_SHIFT 0
|
||||
|
||||
#define HCINT(_ch) HSOTG_REG(0x0508 + 0x20 * (_ch))
|
||||
#define HCINTMSK(_ch) HSOTG_REG(0x050c + 0x20 * (_ch))
|
||||
#define HCINTMSK_RESERVED14_31 (0x3ffff << 14)
|
||||
#define HCINTMSK_FRM_LIST_ROLL (1 << 13)
|
||||
#define HCINTMSK_XCS_XACT (1 << 12)
|
||||
#define HCINTMSK_BNA (1 << 11)
|
||||
#define HCINTMSK_DATATGLERR (1 << 10)
|
||||
#define HCINTMSK_FRMOVRUN (1 << 9)
|
||||
#define HCINTMSK_BBLERR (1 << 8)
|
||||
#define HCINTMSK_XACTERR (1 << 7)
|
||||
#define HCINTMSK_NYET (1 << 6)
|
||||
#define HCINTMSK_ACK (1 << 5)
|
||||
#define HCINTMSK_NAK (1 << 4)
|
||||
#define HCINTMSK_STALL (1 << 3)
|
||||
#define HCINTMSK_AHBERR (1 << 2)
|
||||
#define HCINTMSK_CHHLTD (1 << 1)
|
||||
#define HCINTMSK_XFERCOMPL (1 << 0)
|
||||
|
||||
#define HCTSIZ(_ch) HSOTG_REG(0x0510 + 0x20 * (_ch))
|
||||
#define TSIZ_DOPNG (1 << 31)
|
||||
#define TSIZ_SC_MC_PID_MASK (0x3 << 29)
|
||||
#define TSIZ_SC_MC_PID_SHIFT 29
|
||||
#define TSIZ_SC_MC_PID_DATA0 0
|
||||
#define TSIZ_SC_MC_PID_DATA2 1
|
||||
#define TSIZ_SC_MC_PID_DATA1 2
|
||||
#define TSIZ_SC_MC_PID_MDATA 3
|
||||
#define TSIZ_SC_MC_PID_SETUP 3
|
||||
#define TSIZ_PKTCNT_MASK (0x3ff << 19)
|
||||
#define TSIZ_PKTCNT_SHIFT 19
|
||||
#define TSIZ_NTD_MASK (0xff << 8)
|
||||
#define TSIZ_NTD_SHIFT 8
|
||||
#define TSIZ_SCHINFO_MASK (0xff << 0)
|
||||
#define TSIZ_SCHINFO_SHIFT 0
|
||||
#define TSIZ_XFERSIZE_MASK (0x7ffff << 0)
|
||||
#define TSIZ_XFERSIZE_SHIFT 0
|
||||
|
||||
#define HCDMA(_ch) HSOTG_REG(0x0514 + 0x20 * (_ch))
|
||||
#define HCDMA_DMA_ADDR_MASK (0x1fffff << 11)
|
||||
#define HCDMA_DMA_ADDR_SHIFT 11
|
||||
#define HCDMA_CTD_MASK (0xff << 3)
|
||||
#define HCDMA_CTD_SHIFT 3
|
||||
|
||||
#define HCDMAB(_ch) HSOTG_REG(0x051c + 0x20 * (_ch))
|
||||
|
||||
#define HCFIFO(_ch) HSOTG_REG(0x1000 + 0x1000 * (_ch))
|
||||
|
||||
/**
|
||||
* struct dwc2_hcd_dma_desc - Host-mode DMA descriptor structure
|
||||
*
|
||||
* @status: DMA descriptor status quadlet
|
||||
* @buf: DMA descriptor data buffer pointer
|
||||
*
|
||||
* DMA Descriptor structure contains two quadlets:
|
||||
* Status quadlet and Data buffer pointer.
|
||||
*/
|
||||
struct dwc2_hcd_dma_desc {
|
||||
u32 status;
|
||||
u32 buf;
|
||||
};
|
||||
|
||||
#define HOST_DMA_A (1 << 31)
|
||||
#define HOST_DMA_STS_MASK (0x3 << 28)
|
||||
#define HOST_DMA_STS_SHIFT 28
|
||||
#define HOST_DMA_STS_PKTERR (1 << 28)
|
||||
#define HOST_DMA_EOL (1 << 26)
|
||||
#define HOST_DMA_IOC (1 << 25)
|
||||
#define HOST_DMA_SUP (1 << 24)
|
||||
#define HOST_DMA_ALT_QTD (1 << 23)
|
||||
#define HOST_DMA_QTD_OFFSET_MASK (0x3f << 17)
|
||||
#define HOST_DMA_QTD_OFFSET_SHIFT 17
|
||||
#define HOST_DMA_ISOC_NBYTES_MASK (0xfff << 0)
|
||||
#define HOST_DMA_ISOC_NBYTES_SHIFT 0
|
||||
#define HOST_DMA_NBYTES_MASK (0x1ffff << 0)
|
||||
#define HOST_DMA_NBYTES_SHIFT 0
|
||||
|
||||
#define MAX_DMA_DESC_SIZE 131071
|
||||
#define MAX_DMA_DESC_NUM_GENERIC 64
|
||||
#define MAX_DMA_DESC_NUM_HS_ISOC 256
|
||||
|
||||
#endif /* __DWC2_HW_H__ */
|
178
drivers/usb/dwc2/pci.c
Normal file
178
drivers/usb/dwc2/pci.c
Normal file
@@ -0,0 +1,178 @@
|
||||
/*
|
||||
* pci.c - DesignWare HS OTG Controller PCI driver
|
||||
*
|
||||
* Copyright (C) 2004-2013 Synopsys, Inc.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions, and the following disclaimer,
|
||||
* without modification.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. The names of the above-listed copyright holders may not be used
|
||||
* to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* ALTERNATIVELY, this software may be distributed under the terms of the
|
||||
* GNU General Public License ("GPL") as published by the Free Software
|
||||
* Foundation; either version 2 of the License, or (at your option) any
|
||||
* later version.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Provides the initialization and cleanup entry points for the DWC_otg PCI
|
||||
* driver
|
||||
*/
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/moduleparam.h>
|
||||
#include <linux/spinlock.h>
|
||||
#include <linux/interrupt.h>
|
||||
#include <linux/io.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/pci.h>
|
||||
#include <linux/usb.h>
|
||||
|
||||
#include <linux/usb/hcd.h>
|
||||
#include <linux/usb/ch11.h>
|
||||
|
||||
#include "core.h"
|
||||
#include "hcd.h"
|
||||
|
||||
#define PCI_VENDOR_ID_SYNOPSYS 0x16c3
|
||||
#define PCI_PRODUCT_ID_HAPS_HSOTG 0xabc0
|
||||
|
||||
static const char dwc2_driver_name[] = "dwc2";
|
||||
|
||||
static const struct dwc2_core_params dwc2_module_params = {
|
||||
.otg_cap = -1,
|
||||
.otg_ver = -1,
|
||||
.dma_enable = -1,
|
||||
.dma_desc_enable = 0,
|
||||
.speed = -1,
|
||||
.enable_dynamic_fifo = -1,
|
||||
.en_multiple_tx_fifo = -1,
|
||||
.host_rx_fifo_size = 1024,
|
||||
.host_nperio_tx_fifo_size = 256,
|
||||
.host_perio_tx_fifo_size = 1024,
|
||||
.max_transfer_size = 65535,
|
||||
.max_packet_count = 511,
|
||||
.host_channels = -1,
|
||||
.phy_type = -1,
|
||||
.phy_utmi_width = -1,
|
||||
.phy_ulpi_ddr = -1,
|
||||
.phy_ulpi_ext_vbus = -1,
|
||||
.i2c_enable = -1,
|
||||
.ulpi_fs_ls = -1,
|
||||
.host_support_fs_ls_low_power = -1,
|
||||
.host_ls_low_power_phy_clk = -1,
|
||||
.ts_dline = -1,
|
||||
.reload_ctl = -1,
|
||||
.ahbcfg = -1,
|
||||
.uframe_sched = -1,
|
||||
};
|
||||
|
||||
/**
|
||||
* dwc2_driver_remove() - Called when the DWC_otg core is unregistered with the
|
||||
* DWC_otg driver
|
||||
*
|
||||
* @dev: Bus device
|
||||
*
|
||||
* This routine is called, for example, when the rmmod command is executed. The
|
||||
* device may or may not be electrically present. If it is present, the driver
|
||||
* stops device processing. Any resources used on behalf of this device are
|
||||
* freed.
|
||||
*/
|
||||
static void dwc2_driver_remove(struct pci_dev *dev)
|
||||
{
|
||||
struct dwc2_hsotg *hsotg = pci_get_drvdata(dev);
|
||||
|
||||
dwc2_hcd_remove(hsotg);
|
||||
pci_disable_device(dev);
|
||||
}
|
||||
|
||||
/**
|
||||
* dwc2_driver_probe() - Called when the DWC_otg core is bound to the DWC_otg
|
||||
* driver
|
||||
*
|
||||
* @dev: Bus device
|
||||
*
|
||||
* This routine creates the driver components required to control the device
|
||||
* (core, HCD, and PCD) and initializes the device. The driver components are
|
||||
* stored in a dwc2_hsotg structure. A reference to the dwc2_hsotg is saved
|
||||
* in the device private data. This allows the driver to access the dwc2_hsotg
|
||||
* structure on subsequent calls to driver methods for this device.
|
||||
*/
|
||||
static int dwc2_driver_probe(struct pci_dev *dev,
|
||||
const struct pci_device_id *id)
|
||||
{
|
||||
struct dwc2_hsotg *hsotg;
|
||||
int retval;
|
||||
|
||||
hsotg = devm_kzalloc(&dev->dev, sizeof(*hsotg), GFP_KERNEL);
|
||||
if (!hsotg)
|
||||
return -ENOMEM;
|
||||
|
||||
hsotg->dev = &dev->dev;
|
||||
hsotg->regs = devm_ioremap_resource(&dev->dev, &dev->resource[0]);
|
||||
if (IS_ERR(hsotg->regs))
|
||||
return PTR_ERR(hsotg->regs);
|
||||
|
||||
dev_dbg(&dev->dev, "mapped PA %08lx to VA %p\n",
|
||||
(unsigned long)pci_resource_start(dev, 0), hsotg->regs);
|
||||
|
||||
if (pci_enable_device(dev) < 0)
|
||||
return -ENODEV;
|
||||
|
||||
pci_set_master(dev);
|
||||
|
||||
retval = dwc2_hcd_init(hsotg, dev->irq, &dwc2_module_params);
|
||||
if (retval) {
|
||||
pci_disable_device(dev);
|
||||
return retval;
|
||||
}
|
||||
|
||||
pci_set_drvdata(dev, hsotg);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
static const struct pci_device_id dwc2_pci_ids[] = {
|
||||
{
|
||||
PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS, PCI_PRODUCT_ID_HAPS_HSOTG),
|
||||
},
|
||||
{
|
||||
PCI_DEVICE(PCI_VENDOR_ID_STMICRO,
|
||||
PCI_DEVICE_ID_STMICRO_USB_OTG),
|
||||
},
|
||||
{ /* end: all zeroes */ }
|
||||
};
|
||||
MODULE_DEVICE_TABLE(pci, dwc2_pci_ids);
|
||||
|
||||
static struct pci_driver dwc2_pci_driver = {
|
||||
.name = dwc2_driver_name,
|
||||
.id_table = dwc2_pci_ids,
|
||||
.probe = dwc2_driver_probe,
|
||||
.remove = dwc2_driver_remove,
|
||||
};
|
||||
|
||||
module_pci_driver(dwc2_pci_driver);
|
||||
|
||||
MODULE_DESCRIPTION("DESIGNWARE HS OTG PCI Bus Glue");
|
||||
MODULE_AUTHOR("Synopsys, Inc.");
|
||||
MODULE_LICENSE("Dual BSD/GPL");
|
187
drivers/usb/dwc2/platform.c
Normal file
187
drivers/usb/dwc2/platform.c
Normal file
@@ -0,0 +1,187 @@
|
||||
/*
|
||||
* platform.c - DesignWare HS OTG Controller platform driver
|
||||
*
|
||||
* Copyright (C) Matthijs Kooijman <matthijs@stdin.nl>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions, and the following disclaimer,
|
||||
* without modification.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. The names of the above-listed copyright holders may not be used
|
||||
* to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* ALTERNATIVELY, this software may be distributed under the terms of the
|
||||
* GNU General Public License ("GPL") as published by the Free Software
|
||||
* Foundation; either version 2 of the License, or (at your option) any
|
||||
* later version.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/device.h>
|
||||
#include <linux/dma-mapping.h>
|
||||
#include <linux/of_device.h>
|
||||
#include <linux/platform_device.h>
|
||||
|
||||
#include "core.h"
|
||||
#include "hcd.h"
|
||||
|
||||
static const char dwc2_driver_name[] = "dwc2";
|
||||
|
||||
static const struct dwc2_core_params params_bcm2835 = {
|
||||
.otg_cap = 0, /* HNP/SRP capable */
|
||||
.otg_ver = 0, /* 1.3 */
|
||||
.dma_enable = 1,
|
||||
.dma_desc_enable = 0,
|
||||
.speed = 0, /* High Speed */
|
||||
.enable_dynamic_fifo = 1,
|
||||
.en_multiple_tx_fifo = 1,
|
||||
.host_rx_fifo_size = 774, /* 774 DWORDs */
|
||||
.host_nperio_tx_fifo_size = 256, /* 256 DWORDs */
|
||||
.host_perio_tx_fifo_size = 512, /* 512 DWORDs */
|
||||
.max_transfer_size = 65535,
|
||||
.max_packet_count = 511,
|
||||
.host_channels = 8,
|
||||
.phy_type = 1, /* UTMI */
|
||||
.phy_utmi_width = 8, /* 8 bits */
|
||||
.phy_ulpi_ddr = 0, /* Single */
|
||||
.phy_ulpi_ext_vbus = 0,
|
||||
.i2c_enable = 0,
|
||||
.ulpi_fs_ls = 0,
|
||||
.host_support_fs_ls_low_power = 0,
|
||||
.host_ls_low_power_phy_clk = 0, /* 48 MHz */
|
||||
.ts_dline = 0,
|
||||
.reload_ctl = 0,
|
||||
.ahbcfg = 0x10,
|
||||
.uframe_sched = 0,
|
||||
};
|
||||
|
||||
/**
|
||||
* dwc2_driver_remove() - Called when the DWC_otg core is unregistered with the
|
||||
* DWC_otg driver
|
||||
*
|
||||
* @dev: Platform device
|
||||
*
|
||||
* This routine is called, for example, when the rmmod command is executed. The
|
||||
* device may or may not be electrically present. If it is present, the driver
|
||||
* stops device processing. Any resources used on behalf of this device are
|
||||
* freed.
|
||||
*/
|
||||
static int dwc2_driver_remove(struct platform_device *dev)
|
||||
{
|
||||
struct dwc2_hsotg *hsotg = platform_get_drvdata(dev);
|
||||
|
||||
dwc2_hcd_remove(hsotg);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct of_device_id dwc2_of_match_table[] = {
|
||||
{ .compatible = "brcm,bcm2835-usb", .data = ¶ms_bcm2835 },
|
||||
{ .compatible = "snps,dwc2", .data = NULL },
|
||||
{},
|
||||
};
|
||||
MODULE_DEVICE_TABLE(of, dwc2_of_match_table);
|
||||
|
||||
/**
|
||||
* dwc2_driver_probe() - Called when the DWC_otg core is bound to the DWC_otg
|
||||
* driver
|
||||
*
|
||||
* @dev: Platform device
|
||||
*
|
||||
* This routine creates the driver components required to control the device
|
||||
* (core, HCD, and PCD) and initializes the device. The driver components are
|
||||
* stored in a dwc2_hsotg structure. A reference to the dwc2_hsotg is saved
|
||||
* in the device private data. This allows the driver to access the dwc2_hsotg
|
||||
* structure on subsequent calls to driver methods for this device.
|
||||
*/
|
||||
static int dwc2_driver_probe(struct platform_device *dev)
|
||||
{
|
||||
const struct of_device_id *match;
|
||||
const struct dwc2_core_params *params;
|
||||
struct dwc2_core_params defparams;
|
||||
struct dwc2_hsotg *hsotg;
|
||||
struct resource *res;
|
||||
int retval;
|
||||
int irq;
|
||||
|
||||
match = of_match_device(dwc2_of_match_table, &dev->dev);
|
||||
if (match && match->data) {
|
||||
params = match->data;
|
||||
} else {
|
||||
/* Default all params to autodetect */
|
||||
dwc2_set_all_params(&defparams, -1);
|
||||
params = &defparams;
|
||||
}
|
||||
|
||||
hsotg = devm_kzalloc(&dev->dev, sizeof(*hsotg), GFP_KERNEL);
|
||||
if (!hsotg)
|
||||
return -ENOMEM;
|
||||
|
||||
hsotg->dev = &dev->dev;
|
||||
|
||||
/*
|
||||
* Use reasonable defaults so platforms don't have to provide these.
|
||||
*/
|
||||
if (!dev->dev.dma_mask)
|
||||
dev->dev.dma_mask = &dev->dev.coherent_dma_mask;
|
||||
retval = dma_set_coherent_mask(&dev->dev, DMA_BIT_MASK(32));
|
||||
if (retval)
|
||||
return retval;
|
||||
|
||||
irq = platform_get_irq(dev, 0);
|
||||
if (irq < 0) {
|
||||
dev_err(&dev->dev, "missing IRQ resource\n");
|
||||
return irq;
|
||||
}
|
||||
|
||||
res = platform_get_resource(dev, IORESOURCE_MEM, 0);
|
||||
hsotg->regs = devm_ioremap_resource(&dev->dev, res);
|
||||
if (IS_ERR(hsotg->regs))
|
||||
return PTR_ERR(hsotg->regs);
|
||||
|
||||
dev_dbg(&dev->dev, "mapped PA %08lx to VA %p\n",
|
||||
(unsigned long)res->start, hsotg->regs);
|
||||
|
||||
retval = dwc2_hcd_init(hsotg, irq, params);
|
||||
if (retval)
|
||||
return retval;
|
||||
|
||||
platform_set_drvdata(dev, hsotg);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
static struct platform_driver dwc2_platform_driver = {
|
||||
.driver = {
|
||||
.name = dwc2_driver_name,
|
||||
.of_match_table = dwc2_of_match_table,
|
||||
},
|
||||
.probe = dwc2_driver_probe,
|
||||
.remove = dwc2_driver_remove,
|
||||
};
|
||||
|
||||
module_platform_driver(dwc2_platform_driver);
|
||||
|
||||
MODULE_DESCRIPTION("DESIGNWARE HS OTG Platform Glue");
|
||||
MODULE_AUTHOR("Matthijs Kooijman <matthijs@stdin.nl>");
|
||||
MODULE_LICENSE("Dual BSD/GPL");
|
Reference in New Issue
Block a user