xref: /openbmc/linux/drivers/usb/dwc2/core.h (revision 9f9f09b0)
1197ba5f4SPaul Zimmerman /*
2197ba5f4SPaul Zimmerman  * core.h - DesignWare HS OTG Controller common declarations
3197ba5f4SPaul Zimmerman  *
4197ba5f4SPaul Zimmerman  * Copyright (C) 2004-2013 Synopsys, Inc.
5197ba5f4SPaul Zimmerman  *
6197ba5f4SPaul Zimmerman  * Redistribution and use in source and binary forms, with or without
7197ba5f4SPaul Zimmerman  * modification, are permitted provided that the following conditions
8197ba5f4SPaul Zimmerman  * are met:
9197ba5f4SPaul Zimmerman  * 1. Redistributions of source code must retain the above copyright
10197ba5f4SPaul Zimmerman  *    notice, this list of conditions, and the following disclaimer,
11197ba5f4SPaul Zimmerman  *    without modification.
12197ba5f4SPaul Zimmerman  * 2. Redistributions in binary form must reproduce the above copyright
13197ba5f4SPaul Zimmerman  *    notice, this list of conditions and the following disclaimer in the
14197ba5f4SPaul Zimmerman  *    documentation and/or other materials provided with the distribution.
15197ba5f4SPaul Zimmerman  * 3. The names of the above-listed copyright holders may not be used
16197ba5f4SPaul Zimmerman  *    to endorse or promote products derived from this software without
17197ba5f4SPaul Zimmerman  *    specific prior written permission.
18197ba5f4SPaul Zimmerman  *
19197ba5f4SPaul Zimmerman  * ALTERNATIVELY, this software may be distributed under the terms of the
20197ba5f4SPaul Zimmerman  * GNU General Public License ("GPL") as published by the Free Software
21197ba5f4SPaul Zimmerman  * Foundation; either version 2 of the License, or (at your option) any
22197ba5f4SPaul Zimmerman  * later version.
23197ba5f4SPaul Zimmerman  *
24197ba5f4SPaul Zimmerman  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
25197ba5f4SPaul Zimmerman  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
26197ba5f4SPaul Zimmerman  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
27197ba5f4SPaul Zimmerman  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
28197ba5f4SPaul Zimmerman  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29197ba5f4SPaul Zimmerman  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30197ba5f4SPaul Zimmerman  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
31197ba5f4SPaul Zimmerman  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
32197ba5f4SPaul Zimmerman  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
33197ba5f4SPaul Zimmerman  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34197ba5f4SPaul Zimmerman  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35197ba5f4SPaul Zimmerman  */
36197ba5f4SPaul Zimmerman 
37197ba5f4SPaul Zimmerman #ifndef __DWC2_CORE_H__
38197ba5f4SPaul Zimmerman #define __DWC2_CORE_H__
39197ba5f4SPaul Zimmerman 
40f7c0b143SDinh Nguyen #include <linux/phy/phy.h>
41f7c0b143SDinh Nguyen #include <linux/regulator/consumer.h>
42f7c0b143SDinh Nguyen #include <linux/usb/gadget.h>
43f7c0b143SDinh Nguyen #include <linux/usb/otg.h>
44197ba5f4SPaul Zimmerman #include <linux/usb/phy.h>
45197ba5f4SPaul Zimmerman #include "hw.h"
46197ba5f4SPaul Zimmerman 
4774fc4a75SDouglas Anderson /*
4874fc4a75SDouglas Anderson  * Suggested defines for tracers:
4974fc4a75SDouglas Anderson  * - no_printk:    Disable tracing
5074fc4a75SDouglas Anderson  * - pr_info:      Print this info to the console
5174fc4a75SDouglas Anderson  * - trace_printk: Print this info to trace buffer (good for verbose logging)
5274fc4a75SDouglas Anderson  */
5374fc4a75SDouglas Anderson 
5474fc4a75SDouglas Anderson #define DWC2_TRACE_SCHEDULER		no_printk
5574fc4a75SDouglas Anderson #define DWC2_TRACE_SCHEDULER_VB		no_printk
5674fc4a75SDouglas Anderson 
5774fc4a75SDouglas Anderson /* Detailed scheduler tracing, but won't overwhelm console */
5874fc4a75SDouglas Anderson #define dwc2_sch_dbg(hsotg, fmt, ...)					\
5974fc4a75SDouglas Anderson 	DWC2_TRACE_SCHEDULER(pr_fmt("%s: SCH: " fmt),			\
6074fc4a75SDouglas Anderson 			     dev_name(hsotg->dev), ##__VA_ARGS__)
6174fc4a75SDouglas Anderson 
6274fc4a75SDouglas Anderson /* Verbose scheduler tracing */
6374fc4a75SDouglas Anderson #define dwc2_sch_vdbg(hsotg, fmt, ...)					\
6474fc4a75SDouglas Anderson 	DWC2_TRACE_SCHEDULER_VB(pr_fmt("%s: SCH: " fmt),		\
6574fc4a75SDouglas Anderson 				dev_name(hsotg->dev), ##__VA_ARGS__)
6674fc4a75SDouglas Anderson 
6795c8bc36SAntti Seppälä static inline u32 dwc2_readl(const void __iomem *addr)
68197ba5f4SPaul Zimmerman {
6995c8bc36SAntti Seppälä 	u32 value = __raw_readl(addr);
7095c8bc36SAntti Seppälä 
7195c8bc36SAntti Seppälä 	/* In order to preserve endianness __raw_* operation is used. Therefore
7295c8bc36SAntti Seppälä 	 * a barrier is needed to ensure IO access is not re-ordered across
7395c8bc36SAntti Seppälä 	 * reads or writes
7495c8bc36SAntti Seppälä 	 */
7595c8bc36SAntti Seppälä 	mb();
7695c8bc36SAntti Seppälä 	return value;
77197ba5f4SPaul Zimmerman }
78197ba5f4SPaul Zimmerman 
7995c8bc36SAntti Seppälä static inline void dwc2_writel(u32 value, void __iomem *addr)
8095c8bc36SAntti Seppälä {
8195c8bc36SAntti Seppälä 	__raw_writel(value, addr);
8295c8bc36SAntti Seppälä 
8395c8bc36SAntti Seppälä 	/*
8495c8bc36SAntti Seppälä 	 * In order to preserve endianness __raw_* operation is used. Therefore
8595c8bc36SAntti Seppälä 	 * a barrier is needed to ensure IO access is not re-ordered across
8695c8bc36SAntti Seppälä 	 * reads or writes
8795c8bc36SAntti Seppälä 	 */
8895c8bc36SAntti Seppälä 	mb();
8995c8bc36SAntti Seppälä #ifdef DWC2_LOG_WRITES
9095c8bc36SAntti Seppälä 	pr_info("INFO:: wrote %08x to %p\n", value, addr);
91197ba5f4SPaul Zimmerman #endif
9295c8bc36SAntti Seppälä }
93197ba5f4SPaul Zimmerman 
94197ba5f4SPaul Zimmerman /* Maximum number of Endpoints/HostChannels */
95197ba5f4SPaul Zimmerman #define MAX_EPS_CHANNELS	16
96197ba5f4SPaul Zimmerman 
971f91b4ccSFelipe Balbi /* dwc2-hsotg declarations */
981f91b4ccSFelipe Balbi static const char * const dwc2_hsotg_supply_names[] = {
99f7c0b143SDinh Nguyen 	"vusb_d",               /* digital USB supply, 1.2V */
100f7c0b143SDinh Nguyen 	"vusb_a",               /* analog USB supply, 1.1V */
101f7c0b143SDinh Nguyen };
102f7c0b143SDinh Nguyen 
103f7c0b143SDinh Nguyen /*
104f7c0b143SDinh Nguyen  * EP0_MPS_LIMIT
105f7c0b143SDinh Nguyen  *
106f7c0b143SDinh Nguyen  * Unfortunately there seems to be a limit of the amount of data that can
107f7c0b143SDinh Nguyen  * be transferred by IN transactions on EP0. This is either 127 bytes or 3
108f7c0b143SDinh Nguyen  * packets (which practically means 1 packet and 63 bytes of data) when the
109f7c0b143SDinh Nguyen  * MPS is set to 64.
110f7c0b143SDinh Nguyen  *
111f7c0b143SDinh Nguyen  * This means if we are wanting to move >127 bytes of data, we need to
112f7c0b143SDinh Nguyen  * split the transactions up, but just doing one packet at a time does
113f7c0b143SDinh Nguyen  * not work (this may be an implicit DATA0 PID on first packet of the
114f7c0b143SDinh Nguyen  * transaction) and doing 2 packets is outside the controller's limits.
115f7c0b143SDinh Nguyen  *
116f7c0b143SDinh Nguyen  * If we try to lower the MPS size for EP0, then no transfers work properly
117f7c0b143SDinh Nguyen  * for EP0, and the system will fail basic enumeration. As no cause for this
118f7c0b143SDinh Nguyen  * has currently been found, we cannot support any large IN transfers for
119f7c0b143SDinh Nguyen  * EP0.
120f7c0b143SDinh Nguyen  */
121f7c0b143SDinh Nguyen #define EP0_MPS_LIMIT   64
122f7c0b143SDinh Nguyen 
123941fcce4SDinh Nguyen struct dwc2_hsotg;
1241f91b4ccSFelipe Balbi struct dwc2_hsotg_req;
125f7c0b143SDinh Nguyen 
126f7c0b143SDinh Nguyen /**
1271f91b4ccSFelipe Balbi  * struct dwc2_hsotg_ep - driver endpoint definition.
128f7c0b143SDinh Nguyen  * @ep: The gadget layer representation of the endpoint.
129f7c0b143SDinh Nguyen  * @name: The driver generated name for the endpoint.
130f7c0b143SDinh Nguyen  * @queue: Queue of requests for this endpoint.
131f7c0b143SDinh Nguyen  * @parent: Reference back to the parent device structure.
132f7c0b143SDinh Nguyen  * @req: The current request that the endpoint is processing. This is
133f7c0b143SDinh Nguyen  *       used to indicate an request has been loaded onto the endpoint
134f7c0b143SDinh Nguyen  *       and has yet to be completed (maybe due to data move, or simply
135f7c0b143SDinh Nguyen  *       awaiting an ack from the core all the data has been completed).
136f7c0b143SDinh Nguyen  * @debugfs: File entry for debugfs file for this endpoint.
137f7c0b143SDinh Nguyen  * @lock: State lock to protect contents of endpoint.
138f7c0b143SDinh Nguyen  * @dir_in: Set to true if this endpoint is of the IN direction, which
139f7c0b143SDinh Nguyen  *          means that it is sending data to the Host.
140f7c0b143SDinh Nguyen  * @index: The index for the endpoint registers.
141f7c0b143SDinh Nguyen  * @mc: Multi Count - number of transactions per microframe
142f7c0b143SDinh Nguyen  * @interval - Interval for periodic endpoints
143f7c0b143SDinh Nguyen  * @name: The name array passed to the USB core.
144f7c0b143SDinh Nguyen  * @halted: Set if the endpoint has been halted.
145f7c0b143SDinh Nguyen  * @periodic: Set if this is a periodic ep, such as Interrupt
146f7c0b143SDinh Nguyen  * @isochronous: Set if this is a isochronous ep
1478a20fa45SMian Yousaf Kaukab  * @send_zlp: Set if we need to send a zero-length packet.
148f7c0b143SDinh Nguyen  * @total_data: The total number of data bytes done.
149f7c0b143SDinh Nguyen  * @fifo_size: The size of the FIFO (for periodic IN endpoints)
150f7c0b143SDinh Nguyen  * @fifo_load: The amount of data loaded into the FIFO (periodic IN)
151f7c0b143SDinh Nguyen  * @last_load: The offset of data for the last start of request.
152f7c0b143SDinh Nguyen  * @size_loaded: The last loaded size for DxEPTSIZE for periodic IN
153f7c0b143SDinh Nguyen  *
154f7c0b143SDinh Nguyen  * This is the driver's state for each registered enpoint, allowing it
155f7c0b143SDinh Nguyen  * to keep track of transactions that need doing. Each endpoint has a
156f7c0b143SDinh Nguyen  * lock to protect the state, to try and avoid using an overall lock
157f7c0b143SDinh Nguyen  * for the host controller as much as possible.
158f7c0b143SDinh Nguyen  *
159f7c0b143SDinh Nguyen  * For periodic IN endpoints, we have fifo_size and fifo_load to try
160f7c0b143SDinh Nguyen  * and keep track of the amount of data in the periodic FIFO for each
161f7c0b143SDinh Nguyen  * of these as we don't have a status register that tells us how much
162f7c0b143SDinh Nguyen  * is in each of them. (note, this may actually be useless information
163f7c0b143SDinh Nguyen  * as in shared-fifo mode periodic in acts like a single-frame packet
164f7c0b143SDinh Nguyen  * buffer than a fifo)
165f7c0b143SDinh Nguyen  */
1661f91b4ccSFelipe Balbi struct dwc2_hsotg_ep {
167f7c0b143SDinh Nguyen 	struct usb_ep           ep;
168f7c0b143SDinh Nguyen 	struct list_head        queue;
169941fcce4SDinh Nguyen 	struct dwc2_hsotg       *parent;
1701f91b4ccSFelipe Balbi 	struct dwc2_hsotg_req    *req;
171f7c0b143SDinh Nguyen 	struct dentry           *debugfs;
172f7c0b143SDinh Nguyen 
173f7c0b143SDinh Nguyen 	unsigned long           total_data;
174f7c0b143SDinh Nguyen 	unsigned int            size_loaded;
175f7c0b143SDinh Nguyen 	unsigned int            last_load;
176f7c0b143SDinh Nguyen 	unsigned int            fifo_load;
177f7c0b143SDinh Nguyen 	unsigned short          fifo_size;
178b203d0a2SRobert Baldyga 	unsigned short		fifo_index;
179f7c0b143SDinh Nguyen 
180f7c0b143SDinh Nguyen 	unsigned char           dir_in;
181f7c0b143SDinh Nguyen 	unsigned char           index;
182f7c0b143SDinh Nguyen 	unsigned char           mc;
183f7c0b143SDinh Nguyen 	unsigned char           interval;
184f7c0b143SDinh Nguyen 
185f7c0b143SDinh Nguyen 	unsigned int            halted:1;
186f7c0b143SDinh Nguyen 	unsigned int            periodic:1;
187f7c0b143SDinh Nguyen 	unsigned int            isochronous:1;
1888a20fa45SMian Yousaf Kaukab 	unsigned int            send_zlp:1;
189ec1f9d9fSRoman Bacik 	unsigned int            has_correct_parity:1;
190f7c0b143SDinh Nguyen 
191f7c0b143SDinh Nguyen 	char                    name[10];
192f7c0b143SDinh Nguyen };
193f7c0b143SDinh Nguyen 
194f7c0b143SDinh Nguyen /**
1951f91b4ccSFelipe Balbi  * struct dwc2_hsotg_req - data transfer request
196f7c0b143SDinh Nguyen  * @req: The USB gadget request
197f7c0b143SDinh Nguyen  * @queue: The list of requests for the endpoint this is queued for.
1987d24c1b5SMian Yousaf Kaukab  * @saved_req_buf: variable to save req.buf when bounce buffers are used.
199f7c0b143SDinh Nguyen  */
2001f91b4ccSFelipe Balbi struct dwc2_hsotg_req {
201f7c0b143SDinh Nguyen 	struct usb_request      req;
202f7c0b143SDinh Nguyen 	struct list_head        queue;
2037d24c1b5SMian Yousaf Kaukab 	void *saved_req_buf;
204f7c0b143SDinh Nguyen };
205f7c0b143SDinh Nguyen 
206941fcce4SDinh Nguyen #if IS_ENABLED(CONFIG_USB_DWC2_PERIPHERAL) || IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE)
207f7c0b143SDinh Nguyen #define call_gadget(_hs, _entry) \
208f7c0b143SDinh Nguyen do { \
209f7c0b143SDinh Nguyen 	if ((_hs)->gadget.speed != USB_SPEED_UNKNOWN && \
210f7c0b143SDinh Nguyen 		(_hs)->driver && (_hs)->driver->_entry) { \
211f7c0b143SDinh Nguyen 		spin_unlock(&_hs->lock); \
212f7c0b143SDinh Nguyen 		(_hs)->driver->_entry(&(_hs)->gadget); \
213f7c0b143SDinh Nguyen 		spin_lock(&_hs->lock); \
214f7c0b143SDinh Nguyen 	} \
215f7c0b143SDinh Nguyen } while (0)
216941fcce4SDinh Nguyen #else
217941fcce4SDinh Nguyen #define call_gadget(_hs, _entry)	do {} while (0)
218941fcce4SDinh Nguyen #endif
219f7c0b143SDinh Nguyen 
220197ba5f4SPaul Zimmerman struct dwc2_hsotg;
221197ba5f4SPaul Zimmerman struct dwc2_host_chan;
222197ba5f4SPaul Zimmerman 
223197ba5f4SPaul Zimmerman /* Device States */
224197ba5f4SPaul Zimmerman enum dwc2_lx_state {
225197ba5f4SPaul Zimmerman 	DWC2_L0,	/* On state */
226197ba5f4SPaul Zimmerman 	DWC2_L1,	/* LPM sleep state */
227197ba5f4SPaul Zimmerman 	DWC2_L2,	/* USB suspend state */
228197ba5f4SPaul Zimmerman 	DWC2_L3,	/* Off state */
229197ba5f4SPaul Zimmerman };
230197ba5f4SPaul Zimmerman 
2310a176279SGregory Herrero /*
2320a176279SGregory Herrero  * Gadget periodic tx fifo sizes as used by legacy driver
2330a176279SGregory Herrero  * EP0 is not included
2340a176279SGregory Herrero  */
2350a176279SGregory Herrero #define DWC2_G_P_LEGACY_TX_FIFO_SIZE {256, 256, 256, 256, 768, 768, 768, \
2360a176279SGregory Herrero 					   768, 0, 0, 0, 0, 0, 0, 0}
2370a176279SGregory Herrero 
238fe0b94abSMian Yousaf Kaukab /* Gadget ep0 states */
239fe0b94abSMian Yousaf Kaukab enum dwc2_ep0_state {
240fe0b94abSMian Yousaf Kaukab 	DWC2_EP0_SETUP,
241fe0b94abSMian Yousaf Kaukab 	DWC2_EP0_DATA_IN,
242fe0b94abSMian Yousaf Kaukab 	DWC2_EP0_DATA_OUT,
243fe0b94abSMian Yousaf Kaukab 	DWC2_EP0_STATUS_IN,
244fe0b94abSMian Yousaf Kaukab 	DWC2_EP0_STATUS_OUT,
245fe0b94abSMian Yousaf Kaukab };
246fe0b94abSMian Yousaf Kaukab 
247197ba5f4SPaul Zimmerman /**
248197ba5f4SPaul Zimmerman  * struct dwc2_core_params - Parameters for configuring the core
249197ba5f4SPaul Zimmerman  *
250197ba5f4SPaul Zimmerman  * @otg_cap:            Specifies the OTG capabilities.
251197ba5f4SPaul Zimmerman  *                       0 - HNP and SRP capable
252197ba5f4SPaul Zimmerman  *                       1 - SRP Only capable
253197ba5f4SPaul Zimmerman  *                       2 - No HNP/SRP capable (always available)
254197ba5f4SPaul Zimmerman  *                      Defaults to best available option (0, 1, then 2)
255197ba5f4SPaul Zimmerman  * @otg_ver:            OTG version supported
256197ba5f4SPaul Zimmerman  *                       0 - 1.3 (default)
257197ba5f4SPaul Zimmerman  *                       1 - 2.0
258197ba5f4SPaul Zimmerman  * @dma_enable:         Specifies whether to use slave or DMA mode for accessing
259197ba5f4SPaul Zimmerman  *                      the data FIFOs. The driver will automatically detect the
260197ba5f4SPaul Zimmerman  *                      value for this parameter if none is specified.
261197ba5f4SPaul Zimmerman  *                       0 - Slave (always available)
262197ba5f4SPaul Zimmerman  *                       1 - DMA (default, if available)
263197ba5f4SPaul Zimmerman  * @dma_desc_enable:    When DMA mode is enabled, specifies whether to use
264197ba5f4SPaul Zimmerman  *                      address DMA mode or descriptor DMA mode for accessing
265197ba5f4SPaul Zimmerman  *                      the data FIFOs. The driver will automatically detect the
266197ba5f4SPaul Zimmerman  *                      value for this if none is specified.
267197ba5f4SPaul Zimmerman  *                       0 - Address DMA
268197ba5f4SPaul Zimmerman  *                       1 - Descriptor DMA (default, if available)
269fbb9e22bSMian Yousaf Kaukab  * @dma_desc_fs_enable: When DMA mode is enabled, specifies whether to use
270fbb9e22bSMian Yousaf Kaukab  *                      address DMA mode or descriptor DMA mode for accessing
271fbb9e22bSMian Yousaf Kaukab  *                      the data FIFOs in Full Speed mode only. The driver
272fbb9e22bSMian Yousaf Kaukab  *                      will automatically detect the value for this if none is
273fbb9e22bSMian Yousaf Kaukab  *                      specified.
274fbb9e22bSMian Yousaf Kaukab  *                       0 - Address DMA
275fbb9e22bSMian Yousaf Kaukab  *                       1 - Descriptor DMA in FS (default, if available)
276197ba5f4SPaul Zimmerman  * @speed:              Specifies the maximum speed of operation in host and
277197ba5f4SPaul Zimmerman  *                      device mode. The actual speed depends on the speed of
278197ba5f4SPaul Zimmerman  *                      the attached device and the value of phy_type.
279197ba5f4SPaul Zimmerman  *                       0 - High Speed
280197ba5f4SPaul Zimmerman  *                           (default when phy_type is UTMI+ or ULPI)
281197ba5f4SPaul Zimmerman  *                       1 - Full Speed
282197ba5f4SPaul Zimmerman  *                           (default when phy_type is Full Speed)
283197ba5f4SPaul Zimmerman  * @enable_dynamic_fifo: 0 - Use coreConsultant-specified FIFO size parameters
284197ba5f4SPaul Zimmerman  *                       1 - Allow dynamic FIFO sizing (default, if available)
285197ba5f4SPaul Zimmerman  * @en_multiple_tx_fifo: Specifies whether dedicated per-endpoint transmit FIFOs
286197ba5f4SPaul Zimmerman  *                      are enabled
287197ba5f4SPaul Zimmerman  * @host_rx_fifo_size:  Number of 4-byte words in the Rx FIFO in host mode when
288197ba5f4SPaul Zimmerman  *                      dynamic FIFO sizing is enabled
289197ba5f4SPaul Zimmerman  *                       16 to 32768
290197ba5f4SPaul Zimmerman  *                      Actual maximum value is autodetected and also
291197ba5f4SPaul Zimmerman  *                      the default.
292197ba5f4SPaul Zimmerman  * @host_nperio_tx_fifo_size: Number of 4-byte words in the non-periodic Tx FIFO
293197ba5f4SPaul Zimmerman  *                      in host mode when dynamic FIFO sizing is enabled
294197ba5f4SPaul Zimmerman  *                       16 to 32768
295197ba5f4SPaul Zimmerman  *                      Actual maximum value is autodetected and also
296197ba5f4SPaul Zimmerman  *                      the default.
297197ba5f4SPaul Zimmerman  * @host_perio_tx_fifo_size: Number of 4-byte words in the periodic Tx FIFO in
298197ba5f4SPaul Zimmerman  *                      host mode when dynamic FIFO sizing is enabled
299197ba5f4SPaul Zimmerman  *                       16 to 32768
300197ba5f4SPaul Zimmerman  *                      Actual maximum value is autodetected and also
301197ba5f4SPaul Zimmerman  *                      the default.
302197ba5f4SPaul Zimmerman  * @max_transfer_size:  The maximum transfer size supported, in bytes
303197ba5f4SPaul Zimmerman  *                       2047 to 65,535
304197ba5f4SPaul Zimmerman  *                      Actual maximum value is autodetected and also
305197ba5f4SPaul Zimmerman  *                      the default.
306197ba5f4SPaul Zimmerman  * @max_packet_count:   The maximum number of packets in a transfer
307197ba5f4SPaul Zimmerman  *                       15 to 511
308197ba5f4SPaul Zimmerman  *                      Actual maximum value is autodetected and also
309197ba5f4SPaul Zimmerman  *                      the default.
310197ba5f4SPaul Zimmerman  * @host_channels:      The number of host channel registers to use
311197ba5f4SPaul Zimmerman  *                       1 to 16
312197ba5f4SPaul Zimmerman  *                      Actual maximum value is autodetected and also
313197ba5f4SPaul Zimmerman  *                      the default.
314197ba5f4SPaul Zimmerman  * @phy_type:           Specifies the type of PHY interface to use. By default,
315197ba5f4SPaul Zimmerman  *                      the driver will automatically detect the phy_type.
316197ba5f4SPaul Zimmerman  *                       0 - Full Speed Phy
317197ba5f4SPaul Zimmerman  *                       1 - UTMI+ Phy
318197ba5f4SPaul Zimmerman  *                       2 - ULPI Phy
319197ba5f4SPaul Zimmerman  *                      Defaults to best available option (2, 1, then 0)
320197ba5f4SPaul Zimmerman  * @phy_utmi_width:     Specifies the UTMI+ Data Width (in bits). This parameter
321197ba5f4SPaul Zimmerman  *                      is applicable for a phy_type of UTMI+ or ULPI. (For a
322197ba5f4SPaul Zimmerman  *                      ULPI phy_type, this parameter indicates the data width
323197ba5f4SPaul Zimmerman  *                      between the MAC and the ULPI Wrapper.) Also, this
324197ba5f4SPaul Zimmerman  *                      parameter is applicable only if the OTG_HSPHY_WIDTH cC
325197ba5f4SPaul Zimmerman  *                      parameter was set to "8 and 16 bits", meaning that the
326197ba5f4SPaul Zimmerman  *                      core has been configured to work at either data path
327197ba5f4SPaul Zimmerman  *                      width.
328197ba5f4SPaul Zimmerman  *                       8 or 16 (default 16 if available)
329197ba5f4SPaul Zimmerman  * @phy_ulpi_ddr:       Specifies whether the ULPI operates at double or single
330197ba5f4SPaul Zimmerman  *                      data rate. This parameter is only applicable if phy_type
331197ba5f4SPaul Zimmerman  *                      is ULPI.
332197ba5f4SPaul Zimmerman  *                       0 - single data rate ULPI interface with 8 bit wide
333197ba5f4SPaul Zimmerman  *                           data bus (default)
334197ba5f4SPaul Zimmerman  *                       1 - double data rate ULPI interface with 4 bit wide
335197ba5f4SPaul Zimmerman  *                           data bus
336197ba5f4SPaul Zimmerman  * @phy_ulpi_ext_vbus:  For a ULPI phy, specifies whether to use the internal or
337197ba5f4SPaul Zimmerman  *                      external supply to drive the VBus
338197ba5f4SPaul Zimmerman  *                       0 - Internal supply (default)
339197ba5f4SPaul Zimmerman  *                       1 - External supply
340197ba5f4SPaul Zimmerman  * @i2c_enable:         Specifies whether to use the I2Cinterface for a full
341197ba5f4SPaul Zimmerman  *                      speed PHY. This parameter is only applicable if phy_type
342197ba5f4SPaul Zimmerman  *                      is FS.
343197ba5f4SPaul Zimmerman  *                       0 - No (default)
344197ba5f4SPaul Zimmerman  *                       1 - Yes
345197ba5f4SPaul Zimmerman  * @ulpi_fs_ls:         Make ULPI phy operate in FS/LS mode only
346197ba5f4SPaul Zimmerman  *                       0 - No (default)
347197ba5f4SPaul Zimmerman  *                       1 - Yes
348197ba5f4SPaul Zimmerman  * @host_support_fs_ls_low_power: Specifies whether low power mode is supported
349197ba5f4SPaul Zimmerman  *                      when attached to a Full Speed or Low Speed device in
350197ba5f4SPaul Zimmerman  *                      host mode.
351197ba5f4SPaul Zimmerman  *                       0 - Don't support low power mode (default)
352197ba5f4SPaul Zimmerman  *                       1 - Support low power mode
353197ba5f4SPaul Zimmerman  * @host_ls_low_power_phy_clk: Specifies the PHY clock rate in low power mode
354197ba5f4SPaul Zimmerman  *                      when connected to a Low Speed device in host
355197ba5f4SPaul Zimmerman  *                      mode. This parameter is applicable only if
356197ba5f4SPaul Zimmerman  *                      host_support_fs_ls_low_power is enabled.
357197ba5f4SPaul Zimmerman  *                       0 - 48 MHz
358197ba5f4SPaul Zimmerman  *                           (default when phy_type is UTMI+ or ULPI)
359197ba5f4SPaul Zimmerman  *                       1 - 6 MHz
360197ba5f4SPaul Zimmerman  *                           (default when phy_type is Full Speed)
361197ba5f4SPaul Zimmerman  * @ts_dline:           Enable Term Select Dline pulsing
362197ba5f4SPaul Zimmerman  *                       0 - No (default)
363197ba5f4SPaul Zimmerman  *                       1 - Yes
364197ba5f4SPaul Zimmerman  * @reload_ctl:         Allow dynamic reloading of HFIR register during runtime
365197ba5f4SPaul Zimmerman  *                       0 - No (default for core < 2.92a)
366197ba5f4SPaul Zimmerman  *                       1 - Yes (default for core >= 2.92a)
367197ba5f4SPaul Zimmerman  * @ahbcfg:             This field allows the default value of the GAHBCFG
368197ba5f4SPaul Zimmerman  *                      register to be overridden
369197ba5f4SPaul Zimmerman  *                       -1         - GAHBCFG value will be set to 0x06
370197ba5f4SPaul Zimmerman  *                                    (INCR4, default)
371197ba5f4SPaul Zimmerman  *                       all others - GAHBCFG value will be overridden with
372197ba5f4SPaul Zimmerman  *                                    this value
373197ba5f4SPaul Zimmerman  *                      Not all bits can be controlled like this, the
374197ba5f4SPaul Zimmerman  *                      bits defined by GAHBCFG_CTRL_MASK are controlled
375197ba5f4SPaul Zimmerman  *                      by the driver and are ignored in this
376197ba5f4SPaul Zimmerman  *                      configuration value.
377197ba5f4SPaul Zimmerman  * @uframe_sched:       True to enable the microframe scheduler
378a6d249d8SGregory Herrero  * @external_id_pin_ctl: Specifies whether ID pin is handled externally.
379a6d249d8SGregory Herrero  *                      Disable CONIDSTSCHNG controller interrupt in such
380a6d249d8SGregory Herrero  *                      case.
381a6d249d8SGregory Herrero  *                      0 - No (default)
382a6d249d8SGregory Herrero  *                      1 - Yes
383285046aaSGregory Herrero  * @hibernation:	Specifies whether the controller support hibernation.
384285046aaSGregory Herrero  *			If hibernation is enabled, the controller will enter
385285046aaSGregory Herrero  *			hibernation in both peripheral and host mode when
386285046aaSGregory Herrero  *			needed.
387285046aaSGregory Herrero  *			0 - No (default)
388285046aaSGregory Herrero  *			1 - Yes
389197ba5f4SPaul Zimmerman  *
390197ba5f4SPaul Zimmerman  * The following parameters may be specified when starting the module. These
391197ba5f4SPaul Zimmerman  * parameters define how the DWC_otg controller should be configured. A
392197ba5f4SPaul Zimmerman  * value of -1 (or any other out of range value) for any parameter means
393197ba5f4SPaul Zimmerman  * to read the value from hardware (if possible) or use the builtin
394197ba5f4SPaul Zimmerman  * default described above.
395197ba5f4SPaul Zimmerman  */
396197ba5f4SPaul Zimmerman struct dwc2_core_params {
397197ba5f4SPaul Zimmerman 	/*
398197ba5f4SPaul Zimmerman 	 * Don't add any non-int members here, this will break
399197ba5f4SPaul Zimmerman 	 * dwc2_set_all_params!
400197ba5f4SPaul Zimmerman 	 */
401197ba5f4SPaul Zimmerman 	int otg_cap;
402197ba5f4SPaul Zimmerman 	int otg_ver;
403197ba5f4SPaul Zimmerman 	int dma_enable;
404197ba5f4SPaul Zimmerman 	int dma_desc_enable;
405fbb9e22bSMian Yousaf Kaukab 	int dma_desc_fs_enable;
406197ba5f4SPaul Zimmerman 	int speed;
407197ba5f4SPaul Zimmerman 	int enable_dynamic_fifo;
408197ba5f4SPaul Zimmerman 	int en_multiple_tx_fifo;
409197ba5f4SPaul Zimmerman 	int host_rx_fifo_size;
410197ba5f4SPaul Zimmerman 	int host_nperio_tx_fifo_size;
411197ba5f4SPaul Zimmerman 	int host_perio_tx_fifo_size;
412197ba5f4SPaul Zimmerman 	int max_transfer_size;
413197ba5f4SPaul Zimmerman 	int max_packet_count;
414197ba5f4SPaul Zimmerman 	int host_channels;
415197ba5f4SPaul Zimmerman 	int phy_type;
416197ba5f4SPaul Zimmerman 	int phy_utmi_width;
417197ba5f4SPaul Zimmerman 	int phy_ulpi_ddr;
418197ba5f4SPaul Zimmerman 	int phy_ulpi_ext_vbus;
419197ba5f4SPaul Zimmerman 	int i2c_enable;
420197ba5f4SPaul Zimmerman 	int ulpi_fs_ls;
421197ba5f4SPaul Zimmerman 	int host_support_fs_ls_low_power;
422197ba5f4SPaul Zimmerman 	int host_ls_low_power_phy_clk;
423197ba5f4SPaul Zimmerman 	int ts_dline;
424197ba5f4SPaul Zimmerman 	int reload_ctl;
425197ba5f4SPaul Zimmerman 	int ahbcfg;
426197ba5f4SPaul Zimmerman 	int uframe_sched;
427a6d249d8SGregory Herrero 	int external_id_pin_ctl;
428285046aaSGregory Herrero 	int hibernation;
429197ba5f4SPaul Zimmerman };
430197ba5f4SPaul Zimmerman 
431197ba5f4SPaul Zimmerman /**
432197ba5f4SPaul Zimmerman  * struct dwc2_hw_params - Autodetected parameters.
433197ba5f4SPaul Zimmerman  *
434197ba5f4SPaul Zimmerman  * These parameters are the various parameters read from hardware
435197ba5f4SPaul Zimmerman  * registers during initialization. They typically contain the best
436197ba5f4SPaul Zimmerman  * supported or maximum value that can be configured in the
437197ba5f4SPaul Zimmerman  * corresponding dwc2_core_params value.
438197ba5f4SPaul Zimmerman  *
439197ba5f4SPaul Zimmerman  * The values that are not in dwc2_core_params are documented below.
440197ba5f4SPaul Zimmerman  *
441197ba5f4SPaul Zimmerman  * @op_mode             Mode of Operation
442197ba5f4SPaul Zimmerman  *                       0 - HNP- and SRP-Capable OTG (Host & Device)
443197ba5f4SPaul Zimmerman  *                       1 - SRP-Capable OTG (Host & Device)
444197ba5f4SPaul Zimmerman  *                       2 - Non-HNP and Non-SRP Capable OTG (Host & Device)
445197ba5f4SPaul Zimmerman  *                       3 - SRP-Capable Device
446197ba5f4SPaul Zimmerman  *                       4 - Non-OTG Device
447197ba5f4SPaul Zimmerman  *                       5 - SRP-Capable Host
448197ba5f4SPaul Zimmerman  *                       6 - Non-OTG Host
449197ba5f4SPaul Zimmerman  * @arch                Architecture
450197ba5f4SPaul Zimmerman  *                       0 - Slave only
451197ba5f4SPaul Zimmerman  *                       1 - External DMA
452197ba5f4SPaul Zimmerman  *                       2 - Internal DMA
453197ba5f4SPaul Zimmerman  * @power_optimized     Are power optimizations enabled?
454197ba5f4SPaul Zimmerman  * @num_dev_ep          Number of device endpoints available
455197ba5f4SPaul Zimmerman  * @num_dev_perio_in_ep Number of device periodic IN endpoints
456997f4f81SMickael Maison  *                      available
457197ba5f4SPaul Zimmerman  * @dev_token_q_depth   Device Mode IN Token Sequence Learning Queue
458197ba5f4SPaul Zimmerman  *                      Depth
459197ba5f4SPaul Zimmerman  *                       0 to 30
460197ba5f4SPaul Zimmerman  * @host_perio_tx_q_depth
461197ba5f4SPaul Zimmerman  *                      Host Mode Periodic Request Queue Depth
462197ba5f4SPaul Zimmerman  *                       2, 4 or 8
463197ba5f4SPaul Zimmerman  * @nperio_tx_q_depth
464197ba5f4SPaul Zimmerman  *                      Non-Periodic Request Queue Depth
465197ba5f4SPaul Zimmerman  *                       2, 4 or 8
466197ba5f4SPaul Zimmerman  * @hs_phy_type         High-speed PHY interface type
467197ba5f4SPaul Zimmerman  *                       0 - High-speed interface not supported
468197ba5f4SPaul Zimmerman  *                       1 - UTMI+
469197ba5f4SPaul Zimmerman  *                       2 - ULPI
470197ba5f4SPaul Zimmerman  *                       3 - UTMI+ and ULPI
471197ba5f4SPaul Zimmerman  * @fs_phy_type         Full-speed PHY interface type
472197ba5f4SPaul Zimmerman  *                       0 - Full speed interface not supported
473197ba5f4SPaul Zimmerman  *                       1 - Dedicated full speed interface
474197ba5f4SPaul Zimmerman  *                       2 - FS pins shared with UTMI+ pins
475197ba5f4SPaul Zimmerman  *                       3 - FS pins shared with ULPI pins
476197ba5f4SPaul Zimmerman  * @total_fifo_size:    Total internal RAM for FIFOs (bytes)
477197ba5f4SPaul Zimmerman  * @utmi_phy_data_width UTMI+ PHY data width
478197ba5f4SPaul Zimmerman  *                       0 - 8 bits
479197ba5f4SPaul Zimmerman  *                       1 - 16 bits
480197ba5f4SPaul Zimmerman  *                       2 - 8 or 16 bits
481197ba5f4SPaul Zimmerman  * @snpsid:             Value from SNPSID register
48255e1040eSJohn Youn  * @dev_ep_dirs:        Direction of device endpoints (GHWCFG1)
483197ba5f4SPaul Zimmerman  */
484197ba5f4SPaul Zimmerman struct dwc2_hw_params {
485197ba5f4SPaul Zimmerman 	unsigned op_mode:3;
486197ba5f4SPaul Zimmerman 	unsigned arch:2;
487197ba5f4SPaul Zimmerman 	unsigned dma_desc_enable:1;
488fbb9e22bSMian Yousaf Kaukab 	unsigned dma_desc_fs_enable:1;
489197ba5f4SPaul Zimmerman 	unsigned enable_dynamic_fifo:1;
490197ba5f4SPaul Zimmerman 	unsigned en_multiple_tx_fifo:1;
491197ba5f4SPaul Zimmerman 	unsigned host_rx_fifo_size:16;
492197ba5f4SPaul Zimmerman 	unsigned host_nperio_tx_fifo_size:16;
49355e1040eSJohn Youn 	unsigned dev_nperio_tx_fifo_size:16;
494197ba5f4SPaul Zimmerman 	unsigned host_perio_tx_fifo_size:16;
495197ba5f4SPaul Zimmerman 	unsigned nperio_tx_q_depth:3;
496197ba5f4SPaul Zimmerman 	unsigned host_perio_tx_q_depth:3;
497197ba5f4SPaul Zimmerman 	unsigned dev_token_q_depth:5;
498197ba5f4SPaul Zimmerman 	unsigned max_transfer_size:26;
499197ba5f4SPaul Zimmerman 	unsigned max_packet_count:11;
500197ba5f4SPaul Zimmerman 	unsigned host_channels:5;
501197ba5f4SPaul Zimmerman 	unsigned hs_phy_type:2;
502197ba5f4SPaul Zimmerman 	unsigned fs_phy_type:2;
503197ba5f4SPaul Zimmerman 	unsigned i2c_enable:1;
504197ba5f4SPaul Zimmerman 	unsigned num_dev_ep:4;
505197ba5f4SPaul Zimmerman 	unsigned num_dev_perio_in_ep:4;
506197ba5f4SPaul Zimmerman 	unsigned total_fifo_size:16;
507197ba5f4SPaul Zimmerman 	unsigned power_optimized:1;
508197ba5f4SPaul Zimmerman 	unsigned utmi_phy_data_width:2;
509197ba5f4SPaul Zimmerman 	u32 snpsid;
51055e1040eSJohn Youn 	u32 dev_ep_dirs;
511197ba5f4SPaul Zimmerman };
512197ba5f4SPaul Zimmerman 
5133f95001dSMian Yousaf Kaukab /* Size of control and EP0 buffers */
5143f95001dSMian Yousaf Kaukab #define DWC2_CTRL_BUFF_SIZE 8
5153f95001dSMian Yousaf Kaukab 
516197ba5f4SPaul Zimmerman /**
517d17ee77bSGregory Herrero  * struct dwc2_gregs_backup - Holds global registers state before entering partial
518d17ee77bSGregory Herrero  * power down
519d17ee77bSGregory Herrero  * @gotgctl:		Backup of GOTGCTL register
520d17ee77bSGregory Herrero  * @gintmsk:		Backup of GINTMSK register
521d17ee77bSGregory Herrero  * @gahbcfg:		Backup of GAHBCFG register
522d17ee77bSGregory Herrero  * @gusbcfg:		Backup of GUSBCFG register
523d17ee77bSGregory Herrero  * @grxfsiz:		Backup of GRXFSIZ register
524d17ee77bSGregory Herrero  * @gnptxfsiz:		Backup of GNPTXFSIZ register
525d17ee77bSGregory Herrero  * @gi2cctl:		Backup of GI2CCTL register
526d17ee77bSGregory Herrero  * @hptxfsiz:		Backup of HPTXFSIZ register
527d17ee77bSGregory Herrero  * @gdfifocfg:		Backup of GDFIFOCFG register
528d17ee77bSGregory Herrero  * @dtxfsiz:		Backup of DTXFSIZ registers for each endpoint
529d17ee77bSGregory Herrero  * @gpwrdn:		Backup of GPWRDN register
530d17ee77bSGregory Herrero  */
531d17ee77bSGregory Herrero struct dwc2_gregs_backup {
532d17ee77bSGregory Herrero 	u32 gotgctl;
533d17ee77bSGregory Herrero 	u32 gintmsk;
534d17ee77bSGregory Herrero 	u32 gahbcfg;
535d17ee77bSGregory Herrero 	u32 gusbcfg;
536d17ee77bSGregory Herrero 	u32 grxfsiz;
537d17ee77bSGregory Herrero 	u32 gnptxfsiz;
538d17ee77bSGregory Herrero 	u32 gi2cctl;
539d17ee77bSGregory Herrero 	u32 hptxfsiz;
540d17ee77bSGregory Herrero 	u32 pcgcctl;
541d17ee77bSGregory Herrero 	u32 gdfifocfg;
542d17ee77bSGregory Herrero 	u32 dtxfsiz[MAX_EPS_CHANNELS];
543d17ee77bSGregory Herrero 	u32 gpwrdn;
544cc1e204cSMian Yousaf Kaukab 	bool valid;
545d17ee77bSGregory Herrero };
546d17ee77bSGregory Herrero 
547d17ee77bSGregory Herrero /**
548d17ee77bSGregory Herrero  * struct  dwc2_dregs_backup - Holds device registers state before entering partial
549d17ee77bSGregory Herrero  * power down
550d17ee77bSGregory Herrero  * @dcfg:		Backup of DCFG register
551d17ee77bSGregory Herrero  * @dctl:		Backup of DCTL register
552d17ee77bSGregory Herrero  * @daintmsk:		Backup of DAINTMSK register
553d17ee77bSGregory Herrero  * @diepmsk:		Backup of DIEPMSK register
554d17ee77bSGregory Herrero  * @doepmsk:		Backup of DOEPMSK register
555d17ee77bSGregory Herrero  * @diepctl:		Backup of DIEPCTL register
556d17ee77bSGregory Herrero  * @dieptsiz:		Backup of DIEPTSIZ register
557d17ee77bSGregory Herrero  * @diepdma:		Backup of DIEPDMA register
558d17ee77bSGregory Herrero  * @doepctl:		Backup of DOEPCTL register
559d17ee77bSGregory Herrero  * @doeptsiz:		Backup of DOEPTSIZ register
560d17ee77bSGregory Herrero  * @doepdma:		Backup of DOEPDMA register
561d17ee77bSGregory Herrero  */
562d17ee77bSGregory Herrero struct dwc2_dregs_backup {
563d17ee77bSGregory Herrero 	u32 dcfg;
564d17ee77bSGregory Herrero 	u32 dctl;
565d17ee77bSGregory Herrero 	u32 daintmsk;
566d17ee77bSGregory Herrero 	u32 diepmsk;
567d17ee77bSGregory Herrero 	u32 doepmsk;
568d17ee77bSGregory Herrero 	u32 diepctl[MAX_EPS_CHANNELS];
569d17ee77bSGregory Herrero 	u32 dieptsiz[MAX_EPS_CHANNELS];
570d17ee77bSGregory Herrero 	u32 diepdma[MAX_EPS_CHANNELS];
571d17ee77bSGregory Herrero 	u32 doepctl[MAX_EPS_CHANNELS];
572d17ee77bSGregory Herrero 	u32 doeptsiz[MAX_EPS_CHANNELS];
573d17ee77bSGregory Herrero 	u32 doepdma[MAX_EPS_CHANNELS];
574cc1e204cSMian Yousaf Kaukab 	bool valid;
575d17ee77bSGregory Herrero };
576d17ee77bSGregory Herrero 
577d17ee77bSGregory Herrero /**
578d17ee77bSGregory Herrero  * struct  dwc2_hregs_backup - Holds host registers state before entering partial
579d17ee77bSGregory Herrero  * power down
580d17ee77bSGregory Herrero  * @hcfg:		Backup of HCFG register
581d17ee77bSGregory Herrero  * @haintmsk:		Backup of HAINTMSK register
582d17ee77bSGregory Herrero  * @hcintmsk:		Backup of HCINTMSK register
583d17ee77bSGregory Herrero  * @hptr0:		Backup of HPTR0 register
584d17ee77bSGregory Herrero  * @hfir:		Backup of HFIR register
585d17ee77bSGregory Herrero  */
586d17ee77bSGregory Herrero struct dwc2_hregs_backup {
587d17ee77bSGregory Herrero 	u32 hcfg;
588d17ee77bSGregory Herrero 	u32 haintmsk;
589d17ee77bSGregory Herrero 	u32 hcintmsk[MAX_EPS_CHANNELS];
590d17ee77bSGregory Herrero 	u32 hprt0;
591d17ee77bSGregory Herrero 	u32 hfir;
592cc1e204cSMian Yousaf Kaukab 	bool valid;
593d17ee77bSGregory Herrero };
594d17ee77bSGregory Herrero 
5959f9f09b0SDouglas Anderson /*
5969f9f09b0SDouglas Anderson  * Constants related to high speed periodic scheduling
5979f9f09b0SDouglas Anderson  *
5989f9f09b0SDouglas Anderson  * We have a periodic schedule that is DWC2_HS_SCHEDULE_UFRAMES long.  From a
5999f9f09b0SDouglas Anderson  * reservation point of view it's assumed that the schedule goes right back to
6009f9f09b0SDouglas Anderson  * the beginning after the end of the schedule.
6019f9f09b0SDouglas Anderson  *
6029f9f09b0SDouglas Anderson  * What does that mean for scheduling things with a long interval?  It means
6039f9f09b0SDouglas Anderson  * we'll reserve time for them in every possible microframe that they could
6049f9f09b0SDouglas Anderson  * ever be scheduled in.  ...but we'll still only actually schedule them as
6059f9f09b0SDouglas Anderson  * often as they were requested.
6069f9f09b0SDouglas Anderson  *
6079f9f09b0SDouglas Anderson  * We keep our schedule in a "bitmap" structure.  This simplifies having
6089f9f09b0SDouglas Anderson  * to keep track of and merge intervals: we just let the bitmap code do most
6099f9f09b0SDouglas Anderson  * of the heavy lifting.  In a way scheduling is much like memory allocation.
6109f9f09b0SDouglas Anderson  *
6119f9f09b0SDouglas Anderson  * We schedule 100us per uframe or 80% of 125us (the maximum amount you're
6129f9f09b0SDouglas Anderson  * supposed to schedule for periodic transfers).  That's according to spec.
6139f9f09b0SDouglas Anderson  *
6149f9f09b0SDouglas Anderson  * Note that though we only schedule 80% of each microframe, the bitmap that we
6159f9f09b0SDouglas Anderson  * keep the schedule in is tightly packed (AKA it doesn't have 100us worth of
6169f9f09b0SDouglas Anderson  * space for each uFrame).
6179f9f09b0SDouglas Anderson  *
6189f9f09b0SDouglas Anderson  * Requirements:
6199f9f09b0SDouglas Anderson  * - DWC2_HS_SCHEDULE_UFRAMES must even divide 0x4000 (HFNUM_MAX_FRNUM + 1)
6209f9f09b0SDouglas Anderson  * - DWC2_HS_SCHEDULE_UFRAMES must be 8 times DWC2_LS_SCHEDULE_FRAMES (probably
6219f9f09b0SDouglas Anderson  *   could be any multiple of 8 times DWC2_LS_SCHEDULE_FRAMES, but there might
6229f9f09b0SDouglas Anderson  *   be bugs).  The 8 comes from the USB spec: number of microframes per frame.
6239f9f09b0SDouglas Anderson  */
6249f9f09b0SDouglas Anderson #define DWC2_US_PER_UFRAME		125
6259f9f09b0SDouglas Anderson #define DWC2_HS_PERIODIC_US_PER_UFRAME	100
6269f9f09b0SDouglas Anderson 
6279f9f09b0SDouglas Anderson #define DWC2_HS_SCHEDULE_UFRAMES	8
6289f9f09b0SDouglas Anderson #define DWC2_HS_SCHEDULE_US		(DWC2_HS_SCHEDULE_UFRAMES * \
6299f9f09b0SDouglas Anderson 					 DWC2_HS_PERIODIC_US_PER_UFRAME)
6309f9f09b0SDouglas Anderson 
6319f9f09b0SDouglas Anderson /*
6329f9f09b0SDouglas Anderson  * Constants related to low speed scheduling
6339f9f09b0SDouglas Anderson  *
6349f9f09b0SDouglas Anderson  * For high speed we schedule every 1us.  For low speed that's a bit overkill,
6359f9f09b0SDouglas Anderson  * so we make up a unit called a "slice" that's worth 25us.  There are 40
6369f9f09b0SDouglas Anderson  * slices in a full frame and we can schedule 36 of those (90%) for periodic
6379f9f09b0SDouglas Anderson  * transfers.
6389f9f09b0SDouglas Anderson  *
6399f9f09b0SDouglas Anderson  * Our low speed schedule can be as short as 1 frame or could be longer.  When
6409f9f09b0SDouglas Anderson  * we only schedule 1 frame it means that we'll need to reserve a time every
6419f9f09b0SDouglas Anderson  * frame even for things that only transfer very rarely, so something that runs
6429f9f09b0SDouglas Anderson  * every 2048 frames will get time reserved in every frame.  Our low speed
6439f9f09b0SDouglas Anderson  * schedule can be longer and we'll be able to handle more overlap, but that
6449f9f09b0SDouglas Anderson  * will come at increased memory cost and increased time to schedule.
6459f9f09b0SDouglas Anderson  *
6469f9f09b0SDouglas Anderson  * Note: one other advantage of a short low speed schedule is that if we mess
6479f9f09b0SDouglas Anderson  * up and miss scheduling we can jump in and use any of the slots that we
6489f9f09b0SDouglas Anderson  * happened to reserve.
6499f9f09b0SDouglas Anderson  *
6509f9f09b0SDouglas Anderson  * With 25 us per slice and 1 frame in the schedule, we only need 4 bytes for
6519f9f09b0SDouglas Anderson  * the schedule.  There will be one schedule per TT.
6529f9f09b0SDouglas Anderson  *
6539f9f09b0SDouglas Anderson  * Requirements:
6549f9f09b0SDouglas Anderson  * - DWC2_US_PER_SLICE must evenly divide DWC2_LS_PERIODIC_US_PER_FRAME.
6559f9f09b0SDouglas Anderson  */
6569f9f09b0SDouglas Anderson #define DWC2_US_PER_SLICE	25
6579f9f09b0SDouglas Anderson #define DWC2_SLICES_PER_UFRAME	(DWC2_US_PER_UFRAME / DWC2_US_PER_SLICE)
6589f9f09b0SDouglas Anderson 
6599f9f09b0SDouglas Anderson #define DWC2_ROUND_US_TO_SLICE(us) \
6609f9f09b0SDouglas Anderson 				(DIV_ROUND_UP((us), DWC2_US_PER_SLICE) * \
6619f9f09b0SDouglas Anderson 				 DWC2_US_PER_SLICE)
6629f9f09b0SDouglas Anderson 
6639f9f09b0SDouglas Anderson #define DWC2_LS_PERIODIC_US_PER_FRAME \
6649f9f09b0SDouglas Anderson 				900
6659f9f09b0SDouglas Anderson #define DWC2_LS_PERIODIC_SLICES_PER_FRAME \
6669f9f09b0SDouglas Anderson 				(DWC2_LS_PERIODIC_US_PER_FRAME / \
6679f9f09b0SDouglas Anderson 				 DWC2_US_PER_SLICE)
6689f9f09b0SDouglas Anderson 
6699f9f09b0SDouglas Anderson #define DWC2_LS_SCHEDULE_FRAMES	1
6709f9f09b0SDouglas Anderson #define DWC2_LS_SCHEDULE_SLICES	(DWC2_LS_SCHEDULE_FRAMES * \
6719f9f09b0SDouglas Anderson 				 DWC2_LS_PERIODIC_SLICES_PER_FRAME)
6729f9f09b0SDouglas Anderson 
673d17ee77bSGregory Herrero /**
674197ba5f4SPaul Zimmerman  * struct dwc2_hsotg - Holds the state of the driver, including the non-periodic
675197ba5f4SPaul Zimmerman  * and periodic schedules
676197ba5f4SPaul Zimmerman  *
677941fcce4SDinh Nguyen  * These are common for both host and peripheral modes:
678941fcce4SDinh Nguyen  *
679197ba5f4SPaul Zimmerman  * @dev:                The struct device pointer
680197ba5f4SPaul Zimmerman  * @regs:		Pointer to controller regs
681197ba5f4SPaul Zimmerman  * @hw_params:          Parameters that were autodetected from the
682197ba5f4SPaul Zimmerman  *                      hardware registers
683941fcce4SDinh Nguyen  * @core_params:	Parameters that define how the core should be configured
684197ba5f4SPaul Zimmerman  * @op_state:           The operational State, during transitions (a_host=>
685197ba5f4SPaul Zimmerman  *                      a_peripheral and b_device=>b_host) this may not match
686197ba5f4SPaul Zimmerman  *                      the core, but allows the software to determine
687197ba5f4SPaul Zimmerman  *                      transitions
688c0155b9dSKever Yang  * @dr_mode:            Requested mode of operation, one of following:
689c0155b9dSKever Yang  *                      - USB_DR_MODE_PERIPHERAL
690c0155b9dSKever Yang  *                      - USB_DR_MODE_HOST
691c0155b9dSKever Yang  *                      - USB_DR_MODE_OTG
69209a75e85SMarek Szyprowski  * @hcd_enabled		Host mode sub-driver initialization indicator.
69309a75e85SMarek Szyprowski  * @gadget_enabled	Peripheral mode sub-driver initialization indicator.
69409a75e85SMarek Szyprowski  * @ll_hw_enabled	Status of low-level hardware resources.
69509a75e85SMarek Szyprowski  * @phy:                The otg phy transceiver structure for phy control.
69609a75e85SMarek Szyprowski  * @uphy:               The otg phy transceiver structure for old USB phy control.
69709a75e85SMarek Szyprowski  * @plat:               The platform specific configuration data. This can be removed once
69809a75e85SMarek Szyprowski  *                      all SoCs support usb transceiver.
69909a75e85SMarek Szyprowski  * @supplies:           Definition of USB power supplies
70009a75e85SMarek Szyprowski  * @phyif:              PHY interface width
701941fcce4SDinh Nguyen  * @lock:		Spinlock that protects all the driver data structures
702941fcce4SDinh Nguyen  * @priv:		Stores a pointer to the struct usb_hcd
703197ba5f4SPaul Zimmerman  * @queuing_high_bandwidth: True if multiple packets of a high-bandwidth
704197ba5f4SPaul Zimmerman  *                      transfer are in process of being queued
705197ba5f4SPaul Zimmerman  * @srp_success:        Stores status of SRP request in the case of a FS PHY
706197ba5f4SPaul Zimmerman  *                      with an I2C interface
707197ba5f4SPaul Zimmerman  * @wq_otg:             Workqueue object used for handling of some interrupts
708197ba5f4SPaul Zimmerman  * @wf_otg:             Work object for handling Connector ID Status Change
709197ba5f4SPaul Zimmerman  *                      interrupt
710197ba5f4SPaul Zimmerman  * @wkp_timer:          Timer object for handling Wakeup Detected interrupt
711197ba5f4SPaul Zimmerman  * @lx_state:           Lx state of connected device
712d17ee77bSGregory Herrero  * @gregs_backup: Backup of global registers during suspend
713d17ee77bSGregory Herrero  * @dregs_backup: Backup of device registers during suspend
714d17ee77bSGregory Herrero  * @hregs_backup: Backup of host registers during suspend
715941fcce4SDinh Nguyen  *
716941fcce4SDinh Nguyen  * These are for host mode:
717941fcce4SDinh Nguyen  *
718197ba5f4SPaul Zimmerman  * @flags:              Flags for handling root port state changes
719197ba5f4SPaul Zimmerman  * @non_periodic_sched_inactive: Inactive QHs in the non-periodic schedule.
720197ba5f4SPaul Zimmerman  *                      Transfers associated with these QHs are not currently
721197ba5f4SPaul Zimmerman  *                      assigned to a host channel.
722197ba5f4SPaul Zimmerman  * @non_periodic_sched_active: Active QHs in the non-periodic schedule.
723197ba5f4SPaul Zimmerman  *                      Transfers associated with these QHs are currently
724197ba5f4SPaul Zimmerman  *                      assigned to a host channel.
725197ba5f4SPaul Zimmerman  * @non_periodic_qh_ptr: Pointer to next QH to process in the active
726197ba5f4SPaul Zimmerman  *                      non-periodic schedule
727197ba5f4SPaul Zimmerman  * @periodic_sched_inactive: Inactive QHs in the periodic schedule. This is a
728197ba5f4SPaul Zimmerman  *                      list of QHs for periodic transfers that are _not_
729197ba5f4SPaul Zimmerman  *                      scheduled for the next frame. Each QH in the list has an
730197ba5f4SPaul Zimmerman  *                      interval counter that determines when it needs to be
731197ba5f4SPaul Zimmerman  *                      scheduled for execution. This scheduling mechanism
732197ba5f4SPaul Zimmerman  *                      allows only a simple calculation for periodic bandwidth
733197ba5f4SPaul Zimmerman  *                      used (i.e. must assume that all periodic transfers may
734197ba5f4SPaul Zimmerman  *                      need to execute in the same frame). However, it greatly
735197ba5f4SPaul Zimmerman  *                      simplifies scheduling and should be sufficient for the
736197ba5f4SPaul Zimmerman  *                      vast majority of OTG hosts, which need to connect to a
737197ba5f4SPaul Zimmerman  *                      small number of peripherals at one time. Items move from
738197ba5f4SPaul Zimmerman  *                      this list to periodic_sched_ready when the QH interval
739197ba5f4SPaul Zimmerman  *                      counter is 0 at SOF.
740197ba5f4SPaul Zimmerman  * @periodic_sched_ready:  List of periodic QHs that are ready for execution in
741197ba5f4SPaul Zimmerman  *                      the next frame, but have not yet been assigned to host
742197ba5f4SPaul Zimmerman  *                      channels. Items move from this list to
743197ba5f4SPaul Zimmerman  *                      periodic_sched_assigned as host channels become
744197ba5f4SPaul Zimmerman  *                      available during the current frame.
745197ba5f4SPaul Zimmerman  * @periodic_sched_assigned: List of periodic QHs to be executed in the next
746197ba5f4SPaul Zimmerman  *                      frame that are assigned to host channels. Items move
747197ba5f4SPaul Zimmerman  *                      from this list to periodic_sched_queued as the
748197ba5f4SPaul Zimmerman  *                      transactions for the QH are queued to the DWC_otg
749197ba5f4SPaul Zimmerman  *                      controller.
750197ba5f4SPaul Zimmerman  * @periodic_sched_queued: List of periodic QHs that have been queued for
751197ba5f4SPaul Zimmerman  *                      execution. Items move from this list to either
752197ba5f4SPaul Zimmerman  *                      periodic_sched_inactive or periodic_sched_ready when the
753197ba5f4SPaul Zimmerman  *                      channel associated with the transfer is released. If the
754197ba5f4SPaul Zimmerman  *                      interval for the QH is 1, the item moves to
755197ba5f4SPaul Zimmerman  *                      periodic_sched_ready because it must be rescheduled for
756197ba5f4SPaul Zimmerman  *                      the next frame. Otherwise, the item moves to
757197ba5f4SPaul Zimmerman  *                      periodic_sched_inactive.
758c9c8ac01SDouglas Anderson  * @split_order:        List keeping track of channels doing splits, in order.
759197ba5f4SPaul Zimmerman  * @periodic_usecs:     Total bandwidth claimed so far for periodic transfers.
760197ba5f4SPaul Zimmerman  *                      This value is in microseconds per (micro)frame. The
761197ba5f4SPaul Zimmerman  *                      assumption is that all periodic transfers may occur in
762197ba5f4SPaul Zimmerman  *                      the same (micro)frame.
7639f9f09b0SDouglas Anderson  * @hs_periodic_bitmap: Bitmap used by the microframe scheduler any time the
7649f9f09b0SDouglas Anderson  *                      host is in high speed mode; low speed schedules are
7659f9f09b0SDouglas Anderson  *                      stored elsewhere since we need one per TT.
766197ba5f4SPaul Zimmerman  * @frame_number:       Frame number read from the core at SOF. The value ranges
767197ba5f4SPaul Zimmerman  *                      from 0 to HFNUM_MAX_FRNUM.
768197ba5f4SPaul Zimmerman  * @periodic_qh_count:  Count of periodic QHs, if using several eps. Used for
769197ba5f4SPaul Zimmerman  *                      SOF enable/disable.
770197ba5f4SPaul Zimmerman  * @free_hc_list:       Free host channels in the controller. This is a list of
771197ba5f4SPaul Zimmerman  *                      struct dwc2_host_chan items.
772197ba5f4SPaul Zimmerman  * @periodic_channels:  Number of host channels assigned to periodic transfers.
773197ba5f4SPaul Zimmerman  *                      Currently assuming that there is a dedicated host
774197ba5f4SPaul Zimmerman  *                      channel for each periodic transaction and at least one
775197ba5f4SPaul Zimmerman  *                      host channel is available for non-periodic transactions.
776197ba5f4SPaul Zimmerman  * @non_periodic_channels: Number of host channels assigned to non-periodic
777197ba5f4SPaul Zimmerman  *                      transfers
778197ba5f4SPaul Zimmerman  * @available_host_channels Number of host channels available for the microframe
779197ba5f4SPaul Zimmerman  *                      scheduler to use
780197ba5f4SPaul Zimmerman  * @hc_ptr_array:       Array of pointers to the host channel descriptors.
781197ba5f4SPaul Zimmerman  *                      Allows accessing a host channel descriptor given the
782197ba5f4SPaul Zimmerman  *                      host channel number. This is useful in interrupt
783197ba5f4SPaul Zimmerman  *                      handlers.
784197ba5f4SPaul Zimmerman  * @status_buf:         Buffer used for data received during the status phase of
785197ba5f4SPaul Zimmerman  *                      a control transfer.
786197ba5f4SPaul Zimmerman  * @status_buf_dma:     DMA address for status_buf
787197ba5f4SPaul Zimmerman  * @start_work:         Delayed work for handling host A-cable connection
788197ba5f4SPaul Zimmerman  * @reset_work:         Delayed work for handling a port reset
789197ba5f4SPaul Zimmerman  * @otg_port:           OTG port number
790197ba5f4SPaul Zimmerman  * @frame_list:         Frame list
791197ba5f4SPaul Zimmerman  * @frame_list_dma:     Frame list DMA address
79295105a99SGregory Herrero  * @frame_list_sz:      Frame list size
7933b5fcc9aSGregory Herrero  * @desc_gen_cache:     Kmem cache for generic descriptors
7943b5fcc9aSGregory Herrero  * @desc_hsisoc_cache:  Kmem cache for hs isochronous descriptors
795941fcce4SDinh Nguyen  *
796941fcce4SDinh Nguyen  * These are for peripheral mode:
797941fcce4SDinh Nguyen  *
798941fcce4SDinh Nguyen  * @driver:             USB gadget driver
799941fcce4SDinh Nguyen  * @dedicated_fifos:    Set if the hardware has dedicated IN-EP fifos.
800941fcce4SDinh Nguyen  * @num_of_eps:         Number of available EPs (excluding EP0)
801941fcce4SDinh Nguyen  * @debug_root:         Root directrory for debugfs.
802941fcce4SDinh Nguyen  * @debug_file:         Main status file for debugfs.
8039e14d0a5SGregory Herrero  * @debug_testmode:     Testmode status file for debugfs.
804941fcce4SDinh Nguyen  * @debug_fifo:         FIFO status file for debugfs.
805941fcce4SDinh Nguyen  * @ep0_reply:          Request used for ep0 reply.
806941fcce4SDinh Nguyen  * @ep0_buff:           Buffer for EP0 reply data, if needed.
807941fcce4SDinh Nguyen  * @ctrl_buff:          Buffer for EP0 control requests.
808941fcce4SDinh Nguyen  * @ctrl_req:           Request for EP0 control packets.
809fe0b94abSMian Yousaf Kaukab  * @ep0_state:          EP0 control transfers state
8109e14d0a5SGregory Herrero  * @test_mode:          USB test mode requested by the host
811941fcce4SDinh Nguyen  * @eps:                The endpoints being supplied to the gadget framework
812edd74be8SGregory Herrero  * @g_using_dma:          Indicate if dma usage is enabled
8130a176279SGregory Herrero  * @g_rx_fifo_sz:         Contains rx fifo size value
8140a176279SGregory Herrero  * @g_np_g_tx_fifo_sz:      Contains Non-Periodic tx fifo size value
8150a176279SGregory Herrero  * @g_tx_fifo_sz:         Contains tx fifo size value per endpoints
816197ba5f4SPaul Zimmerman  */
817197ba5f4SPaul Zimmerman struct dwc2_hsotg {
818197ba5f4SPaul Zimmerman 	struct device *dev;
819197ba5f4SPaul Zimmerman 	void __iomem *regs;
820197ba5f4SPaul Zimmerman 	/** Params detected from hardware */
821197ba5f4SPaul Zimmerman 	struct dwc2_hw_params hw_params;
822197ba5f4SPaul Zimmerman 	/** Params to actually use */
823197ba5f4SPaul Zimmerman 	struct dwc2_core_params *core_params;
824197ba5f4SPaul Zimmerman 	enum usb_otg_state op_state;
825c0155b9dSKever Yang 	enum usb_dr_mode dr_mode;
826e39af88fSMarek Szyprowski 	unsigned int hcd_enabled:1;
827e39af88fSMarek Szyprowski 	unsigned int gadget_enabled:1;
82809a75e85SMarek Szyprowski 	unsigned int ll_hw_enabled:1;
829197ba5f4SPaul Zimmerman 
830941fcce4SDinh Nguyen 	struct phy *phy;
831941fcce4SDinh Nguyen 	struct usb_phy *uphy;
83209a75e85SMarek Szyprowski 	struct dwc2_hsotg_plat *plat;
8331f91b4ccSFelipe Balbi 	struct regulator_bulk_data supplies[ARRAY_SIZE(dwc2_hsotg_supply_names)];
83409a75e85SMarek Szyprowski 	u32 phyif;
835941fcce4SDinh Nguyen 
836941fcce4SDinh Nguyen 	spinlock_t lock;
837941fcce4SDinh Nguyen 	void *priv;
838941fcce4SDinh Nguyen 	int     irq;
839941fcce4SDinh Nguyen 	struct clk *clk;
840941fcce4SDinh Nguyen 
841197ba5f4SPaul Zimmerman 	unsigned int queuing_high_bandwidth:1;
842197ba5f4SPaul Zimmerman 	unsigned int srp_success:1;
843197ba5f4SPaul Zimmerman 
844197ba5f4SPaul Zimmerman 	struct workqueue_struct *wq_otg;
845197ba5f4SPaul Zimmerman 	struct work_struct wf_otg;
846197ba5f4SPaul Zimmerman 	struct timer_list wkp_timer;
847197ba5f4SPaul Zimmerman 	enum dwc2_lx_state lx_state;
848cc1e204cSMian Yousaf Kaukab 	struct dwc2_gregs_backup gr_backup;
849cc1e204cSMian Yousaf Kaukab 	struct dwc2_dregs_backup dr_backup;
850cc1e204cSMian Yousaf Kaukab 	struct dwc2_hregs_backup hr_backup;
851197ba5f4SPaul Zimmerman 
852941fcce4SDinh Nguyen 	struct dentry *debug_root;
853563cf017SMian Yousaf Kaukab 	struct debugfs_regset32 *regset;
854941fcce4SDinh Nguyen 
855941fcce4SDinh Nguyen 	/* DWC OTG HW Release versions */
856941fcce4SDinh Nguyen #define DWC2_CORE_REV_2_71a	0x4f54271a
857941fcce4SDinh Nguyen #define DWC2_CORE_REV_2_90a	0x4f54290a
858941fcce4SDinh Nguyen #define DWC2_CORE_REV_2_92a	0x4f54292a
859941fcce4SDinh Nguyen #define DWC2_CORE_REV_2_94a	0x4f54294a
860941fcce4SDinh Nguyen #define DWC2_CORE_REV_3_00a	0x4f54300a
861941fcce4SDinh Nguyen 
862941fcce4SDinh Nguyen #if IS_ENABLED(CONFIG_USB_DWC2_HOST) || IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE)
863197ba5f4SPaul Zimmerman 	union dwc2_hcd_internal_flags {
864197ba5f4SPaul Zimmerman 		u32 d32;
865197ba5f4SPaul Zimmerman 		struct {
866197ba5f4SPaul Zimmerman 			unsigned port_connect_status_change:1;
867197ba5f4SPaul Zimmerman 			unsigned port_connect_status:1;
868197ba5f4SPaul Zimmerman 			unsigned port_reset_change:1;
869197ba5f4SPaul Zimmerman 			unsigned port_enable_change:1;
870197ba5f4SPaul Zimmerman 			unsigned port_suspend_change:1;
871197ba5f4SPaul Zimmerman 			unsigned port_over_current_change:1;
872197ba5f4SPaul Zimmerman 			unsigned port_l1_change:1;
873fd4850cfSCharles Manning 			unsigned reserved:25;
874197ba5f4SPaul Zimmerman 		} b;
875197ba5f4SPaul Zimmerman 	} flags;
876197ba5f4SPaul Zimmerman 
877197ba5f4SPaul Zimmerman 	struct list_head non_periodic_sched_inactive;
878197ba5f4SPaul Zimmerman 	struct list_head non_periodic_sched_active;
879197ba5f4SPaul Zimmerman 	struct list_head *non_periodic_qh_ptr;
880197ba5f4SPaul Zimmerman 	struct list_head periodic_sched_inactive;
881197ba5f4SPaul Zimmerman 	struct list_head periodic_sched_ready;
882197ba5f4SPaul Zimmerman 	struct list_head periodic_sched_assigned;
883197ba5f4SPaul Zimmerman 	struct list_head periodic_sched_queued;
884c9c8ac01SDouglas Anderson 	struct list_head split_order;
885197ba5f4SPaul Zimmerman 	u16 periodic_usecs;
8869f9f09b0SDouglas Anderson 	unsigned long hs_periodic_bitmap[
8879f9f09b0SDouglas Anderson 		DIV_ROUND_UP(DWC2_HS_SCHEDULE_US, BITS_PER_LONG)];
888197ba5f4SPaul Zimmerman 	u16 frame_number;
889197ba5f4SPaul Zimmerman 	u16 periodic_qh_count;
890734643dfSGregory Herrero 	bool bus_suspended;
891fbb9e22bSMian Yousaf Kaukab 	bool new_connection;
892197ba5f4SPaul Zimmerman 
893483bb254SDouglas Anderson 	u16 last_frame_num;
894483bb254SDouglas Anderson 
895197ba5f4SPaul Zimmerman #ifdef CONFIG_USB_DWC2_TRACK_MISSED_SOFS
896197ba5f4SPaul Zimmerman #define FRAME_NUM_ARRAY_SIZE 1000
897197ba5f4SPaul Zimmerman 	u16 *frame_num_array;
898197ba5f4SPaul Zimmerman 	u16 *last_frame_num_array;
899197ba5f4SPaul Zimmerman 	int frame_num_idx;
900197ba5f4SPaul Zimmerman 	int dumped_frame_num_array;
901197ba5f4SPaul Zimmerman #endif
902197ba5f4SPaul Zimmerman 
903197ba5f4SPaul Zimmerman 	struct list_head free_hc_list;
904197ba5f4SPaul Zimmerman 	int periodic_channels;
905197ba5f4SPaul Zimmerman 	int non_periodic_channels;
906197ba5f4SPaul Zimmerman 	int available_host_channels;
907197ba5f4SPaul Zimmerman 	struct dwc2_host_chan *hc_ptr_array[MAX_EPS_CHANNELS];
908197ba5f4SPaul Zimmerman 	u8 *status_buf;
909197ba5f4SPaul Zimmerman 	dma_addr_t status_buf_dma;
910197ba5f4SPaul Zimmerman #define DWC2_HCD_STATUS_BUF_SIZE 64
911197ba5f4SPaul Zimmerman 
912197ba5f4SPaul Zimmerman 	struct delayed_work start_work;
913197ba5f4SPaul Zimmerman 	struct delayed_work reset_work;
914197ba5f4SPaul Zimmerman 	u8 otg_port;
915197ba5f4SPaul Zimmerman 	u32 *frame_list;
916197ba5f4SPaul Zimmerman 	dma_addr_t frame_list_dma;
91795105a99SGregory Herrero 	u32 frame_list_sz;
9183b5fcc9aSGregory Herrero 	struct kmem_cache *desc_gen_cache;
9193b5fcc9aSGregory Herrero 	struct kmem_cache *desc_hsisoc_cache;
920197ba5f4SPaul Zimmerman 
921197ba5f4SPaul Zimmerman #ifdef DEBUG
922197ba5f4SPaul Zimmerman 	u32 frrem_samples;
923197ba5f4SPaul Zimmerman 	u64 frrem_accum;
924197ba5f4SPaul Zimmerman 
925197ba5f4SPaul Zimmerman 	u32 hfnum_7_samples_a;
926197ba5f4SPaul Zimmerman 	u64 hfnum_7_frrem_accum_a;
927197ba5f4SPaul Zimmerman 	u32 hfnum_0_samples_a;
928197ba5f4SPaul Zimmerman 	u64 hfnum_0_frrem_accum_a;
929197ba5f4SPaul Zimmerman 	u32 hfnum_other_samples_a;
930197ba5f4SPaul Zimmerman 	u64 hfnum_other_frrem_accum_a;
931197ba5f4SPaul Zimmerman 
932197ba5f4SPaul Zimmerman 	u32 hfnum_7_samples_b;
933197ba5f4SPaul Zimmerman 	u64 hfnum_7_frrem_accum_b;
934197ba5f4SPaul Zimmerman 	u32 hfnum_0_samples_b;
935197ba5f4SPaul Zimmerman 	u64 hfnum_0_frrem_accum_b;
936197ba5f4SPaul Zimmerman 	u32 hfnum_other_samples_b;
937197ba5f4SPaul Zimmerman 	u64 hfnum_other_frrem_accum_b;
938197ba5f4SPaul Zimmerman #endif
939941fcce4SDinh Nguyen #endif /* CONFIG_USB_DWC2_HOST || CONFIG_USB_DWC2_DUAL_ROLE */
940941fcce4SDinh Nguyen 
941941fcce4SDinh Nguyen #if IS_ENABLED(CONFIG_USB_DWC2_PERIPHERAL) || IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE)
942941fcce4SDinh Nguyen 	/* Gadget structures */
943941fcce4SDinh Nguyen 	struct usb_gadget_driver *driver;
944941fcce4SDinh Nguyen 	int fifo_mem;
945941fcce4SDinh Nguyen 	unsigned int dedicated_fifos:1;
946941fcce4SDinh Nguyen 	unsigned char num_of_eps;
947941fcce4SDinh Nguyen 	u32 fifo_map;
948941fcce4SDinh Nguyen 
949941fcce4SDinh Nguyen 	struct usb_request *ep0_reply;
950941fcce4SDinh Nguyen 	struct usb_request *ctrl_req;
9513f95001dSMian Yousaf Kaukab 	void *ep0_buff;
9523f95001dSMian Yousaf Kaukab 	void *ctrl_buff;
953fe0b94abSMian Yousaf Kaukab 	enum dwc2_ep0_state ep0_state;
9549e14d0a5SGregory Herrero 	u8 test_mode;
955941fcce4SDinh Nguyen 
956941fcce4SDinh Nguyen 	struct usb_gadget gadget;
957dc6e69e6SMarek Szyprowski 	unsigned int enabled:1;
9584ace06e8SMarek Szyprowski 	unsigned int connected:1;
9591f91b4ccSFelipe Balbi 	struct dwc2_hsotg_ep *eps_in[MAX_EPS_CHANNELS];
9601f91b4ccSFelipe Balbi 	struct dwc2_hsotg_ep *eps_out[MAX_EPS_CHANNELS];
961edd74be8SGregory Herrero 	u32 g_using_dma;
9620a176279SGregory Herrero 	u32 g_rx_fifo_sz;
9630a176279SGregory Herrero 	u32 g_np_g_tx_fifo_sz;
9640a176279SGregory Herrero 	u32 g_tx_fifo_sz[MAX_EPS_CHANNELS];
965941fcce4SDinh Nguyen #endif /* CONFIG_USB_DWC2_PERIPHERAL || CONFIG_USB_DWC2_DUAL_ROLE */
966197ba5f4SPaul Zimmerman };
967197ba5f4SPaul Zimmerman 
968197ba5f4SPaul Zimmerman /* Reasons for halting a host channel */
969197ba5f4SPaul Zimmerman enum dwc2_halt_status {
970197ba5f4SPaul Zimmerman 	DWC2_HC_XFER_NO_HALT_STATUS,
971197ba5f4SPaul Zimmerman 	DWC2_HC_XFER_COMPLETE,
972197ba5f4SPaul Zimmerman 	DWC2_HC_XFER_URB_COMPLETE,
973197ba5f4SPaul Zimmerman 	DWC2_HC_XFER_ACK,
974197ba5f4SPaul Zimmerman 	DWC2_HC_XFER_NAK,
975197ba5f4SPaul Zimmerman 	DWC2_HC_XFER_NYET,
976197ba5f4SPaul Zimmerman 	DWC2_HC_XFER_STALL,
977197ba5f4SPaul Zimmerman 	DWC2_HC_XFER_XACT_ERR,
978197ba5f4SPaul Zimmerman 	DWC2_HC_XFER_FRAME_OVERRUN,
979197ba5f4SPaul Zimmerman 	DWC2_HC_XFER_BABBLE_ERR,
980197ba5f4SPaul Zimmerman 	DWC2_HC_XFER_DATA_TOGGLE_ERR,
981197ba5f4SPaul Zimmerman 	DWC2_HC_XFER_AHB_ERR,
982197ba5f4SPaul Zimmerman 	DWC2_HC_XFER_PERIODIC_INCOMPLETE,
983197ba5f4SPaul Zimmerman 	DWC2_HC_XFER_URB_DEQUEUE,
984197ba5f4SPaul Zimmerman };
985197ba5f4SPaul Zimmerman 
986197ba5f4SPaul Zimmerman /*
987197ba5f4SPaul Zimmerman  * The following functions support initialization of the core driver component
988197ba5f4SPaul Zimmerman  * and the DWC_otg controller
989197ba5f4SPaul Zimmerman  */
990b5d308abSJohn Youn extern int dwc2_core_reset(struct dwc2_hsotg *hsotg);
9916d58f346SJohn Youn extern int dwc2_core_reset_and_force_dr_mode(struct dwc2_hsotg *hsotg);
992197ba5f4SPaul Zimmerman extern void dwc2_core_host_init(struct dwc2_hsotg *hsotg);
993d17ee77bSGregory Herrero extern int dwc2_enter_hibernation(struct dwc2_hsotg *hsotg);
994d17ee77bSGregory Herrero extern int dwc2_exit_hibernation(struct dwc2_hsotg *hsotg, bool restore);
995197ba5f4SPaul Zimmerman 
99609c96980SJohn Youn void dwc2_force_dr_mode(struct dwc2_hsotg *hsotg);
99709c96980SJohn Youn 
998197ba5f4SPaul Zimmerman /*
999197ba5f4SPaul Zimmerman  * Host core Functions.
1000197ba5f4SPaul Zimmerman  * The following functions support managing the DWC_otg controller in host
1001197ba5f4SPaul Zimmerman  * mode.
1002197ba5f4SPaul Zimmerman  */
1003197ba5f4SPaul Zimmerman extern void dwc2_hc_init(struct dwc2_hsotg *hsotg, struct dwc2_host_chan *chan);
1004197ba5f4SPaul Zimmerman extern void dwc2_hc_halt(struct dwc2_hsotg *hsotg, struct dwc2_host_chan *chan,
1005197ba5f4SPaul Zimmerman 			 enum dwc2_halt_status halt_status);
1006197ba5f4SPaul Zimmerman extern void dwc2_hc_cleanup(struct dwc2_hsotg *hsotg,
1007197ba5f4SPaul Zimmerman 			    struct dwc2_host_chan *chan);
1008197ba5f4SPaul Zimmerman extern void dwc2_hc_start_transfer(struct dwc2_hsotg *hsotg,
1009197ba5f4SPaul Zimmerman 				   struct dwc2_host_chan *chan);
1010197ba5f4SPaul Zimmerman extern void dwc2_hc_start_transfer_ddma(struct dwc2_hsotg *hsotg,
1011197ba5f4SPaul Zimmerman 					struct dwc2_host_chan *chan);
1012197ba5f4SPaul Zimmerman extern int dwc2_hc_continue_transfer(struct dwc2_hsotg *hsotg,
1013197ba5f4SPaul Zimmerman 				     struct dwc2_host_chan *chan);
1014197ba5f4SPaul Zimmerman extern void dwc2_hc_do_ping(struct dwc2_hsotg *hsotg,
1015197ba5f4SPaul Zimmerman 			    struct dwc2_host_chan *chan);
1016197ba5f4SPaul Zimmerman extern void dwc2_enable_host_interrupts(struct dwc2_hsotg *hsotg);
1017197ba5f4SPaul Zimmerman extern void dwc2_disable_host_interrupts(struct dwc2_hsotg *hsotg);
1018197ba5f4SPaul Zimmerman 
1019197ba5f4SPaul Zimmerman extern u32 dwc2_calc_frame_interval(struct dwc2_hsotg *hsotg);
1020197ba5f4SPaul Zimmerman extern bool dwc2_is_controller_alive(struct dwc2_hsotg *hsotg);
1021197ba5f4SPaul Zimmerman 
1022197ba5f4SPaul Zimmerman /*
1023197ba5f4SPaul Zimmerman  * Common core Functions.
1024197ba5f4SPaul Zimmerman  * The following functions support managing the DWC_otg controller in either
1025197ba5f4SPaul Zimmerman  * device or host mode.
1026197ba5f4SPaul Zimmerman  */
1027197ba5f4SPaul Zimmerman extern void dwc2_read_packet(struct dwc2_hsotg *hsotg, u8 *dest, u16 bytes);
1028197ba5f4SPaul Zimmerman extern void dwc2_flush_tx_fifo(struct dwc2_hsotg *hsotg, const int num);
1029197ba5f4SPaul Zimmerman extern void dwc2_flush_rx_fifo(struct dwc2_hsotg *hsotg);
1030197ba5f4SPaul Zimmerman 
10310fe239bcSDouglas Anderson extern int dwc2_core_init(struct dwc2_hsotg *hsotg, bool initial_setup);
1032197ba5f4SPaul Zimmerman extern void dwc2_enable_global_interrupts(struct dwc2_hsotg *hcd);
1033197ba5f4SPaul Zimmerman extern void dwc2_disable_global_interrupts(struct dwc2_hsotg *hcd);
1034197ba5f4SPaul Zimmerman 
1035197ba5f4SPaul Zimmerman /* This function should be called on every hardware interrupt. */
1036197ba5f4SPaul Zimmerman extern irqreturn_t dwc2_handle_common_intr(int irq, void *dev);
1037197ba5f4SPaul Zimmerman 
1038197ba5f4SPaul Zimmerman /* OTG Core Parameters */
1039197ba5f4SPaul Zimmerman 
1040197ba5f4SPaul Zimmerman /*
1041197ba5f4SPaul Zimmerman  * Specifies the OTG capabilities. The driver will automatically
1042197ba5f4SPaul Zimmerman  * detect the value for this parameter if none is specified.
1043197ba5f4SPaul Zimmerman  * 0 - HNP and SRP capable (default)
1044197ba5f4SPaul Zimmerman  * 1 - SRP Only capable
1045197ba5f4SPaul Zimmerman  * 2 - No HNP/SRP capable
1046197ba5f4SPaul Zimmerman  */
1047197ba5f4SPaul Zimmerman extern void dwc2_set_param_otg_cap(struct dwc2_hsotg *hsotg, int val);
1048197ba5f4SPaul Zimmerman #define DWC2_CAP_PARAM_HNP_SRP_CAPABLE		0
1049197ba5f4SPaul Zimmerman #define DWC2_CAP_PARAM_SRP_ONLY_CAPABLE		1
1050197ba5f4SPaul Zimmerman #define DWC2_CAP_PARAM_NO_HNP_SRP_CAPABLE	2
1051197ba5f4SPaul Zimmerman 
1052197ba5f4SPaul Zimmerman /*
1053197ba5f4SPaul Zimmerman  * Specifies whether to use slave or DMA mode for accessing the data
1054197ba5f4SPaul Zimmerman  * FIFOs. The driver will automatically detect the value for this
1055197ba5f4SPaul Zimmerman  * parameter if none is specified.
1056197ba5f4SPaul Zimmerman  * 0 - Slave
1057197ba5f4SPaul Zimmerman  * 1 - DMA (default, if available)
1058197ba5f4SPaul Zimmerman  */
1059197ba5f4SPaul Zimmerman extern void dwc2_set_param_dma_enable(struct dwc2_hsotg *hsotg, int val);
1060197ba5f4SPaul Zimmerman 
1061197ba5f4SPaul Zimmerman /*
1062197ba5f4SPaul Zimmerman  * When DMA mode is enabled specifies whether to use
1063197ba5f4SPaul Zimmerman  * address DMA or DMA Descritor mode for accessing the data
1064197ba5f4SPaul Zimmerman  * FIFOs in device mode. The driver will automatically detect
1065197ba5f4SPaul Zimmerman  * the value for this parameter if none is specified.
1066197ba5f4SPaul Zimmerman  * 0 - address DMA
1067197ba5f4SPaul Zimmerman  * 1 - DMA Descriptor(default, if available)
1068197ba5f4SPaul Zimmerman  */
1069197ba5f4SPaul Zimmerman extern void dwc2_set_param_dma_desc_enable(struct dwc2_hsotg *hsotg, int val);
1070197ba5f4SPaul Zimmerman 
1071197ba5f4SPaul Zimmerman /*
1072fbb9e22bSMian Yousaf Kaukab  * When DMA mode is enabled specifies whether to use
1073fbb9e22bSMian Yousaf Kaukab  * address DMA or DMA Descritor mode with full speed devices
1074fbb9e22bSMian Yousaf Kaukab  * for accessing the data FIFOs in host mode.
1075fbb9e22bSMian Yousaf Kaukab  * 0 - address DMA
1076fbb9e22bSMian Yousaf Kaukab  * 1 - FS DMA Descriptor(default, if available)
1077fbb9e22bSMian Yousaf Kaukab  */
1078fbb9e22bSMian Yousaf Kaukab extern void dwc2_set_param_dma_desc_fs_enable(struct dwc2_hsotg *hsotg,
1079fbb9e22bSMian Yousaf Kaukab 					      int val);
1080fbb9e22bSMian Yousaf Kaukab 
1081fbb9e22bSMian Yousaf Kaukab /*
1082197ba5f4SPaul Zimmerman  * Specifies the maximum speed of operation in host and device mode.
1083197ba5f4SPaul Zimmerman  * The actual speed depends on the speed of the attached device and
1084197ba5f4SPaul Zimmerman  * the value of phy_type. The actual speed depends on the speed of the
1085197ba5f4SPaul Zimmerman  * attached device.
1086197ba5f4SPaul Zimmerman  * 0 - High Speed (default)
1087197ba5f4SPaul Zimmerman  * 1 - Full Speed
1088197ba5f4SPaul Zimmerman  */
1089197ba5f4SPaul Zimmerman extern void dwc2_set_param_speed(struct dwc2_hsotg *hsotg, int val);
1090197ba5f4SPaul Zimmerman #define DWC2_SPEED_PARAM_HIGH	0
1091197ba5f4SPaul Zimmerman #define DWC2_SPEED_PARAM_FULL	1
1092197ba5f4SPaul Zimmerman 
1093197ba5f4SPaul Zimmerman /*
1094197ba5f4SPaul Zimmerman  * Specifies whether low power mode is supported when attached
1095197ba5f4SPaul Zimmerman  * to a Full Speed or Low Speed device in host mode.
1096197ba5f4SPaul Zimmerman  *
1097197ba5f4SPaul Zimmerman  * 0 - Don't support low power mode (default)
1098197ba5f4SPaul Zimmerman  * 1 - Support low power mode
1099197ba5f4SPaul Zimmerman  */
1100197ba5f4SPaul Zimmerman extern void dwc2_set_param_host_support_fs_ls_low_power(
1101197ba5f4SPaul Zimmerman 		struct dwc2_hsotg *hsotg, int val);
1102197ba5f4SPaul Zimmerman 
1103197ba5f4SPaul Zimmerman /*
1104197ba5f4SPaul Zimmerman  * Specifies the PHY clock rate in low power mode when connected to a
1105197ba5f4SPaul Zimmerman  * Low Speed device in host mode. This parameter is applicable only if
1106197ba5f4SPaul Zimmerman  * HOST_SUPPORT_FS_LS_LOW_POWER is enabled. If PHY_TYPE is set to FS
1107197ba5f4SPaul Zimmerman  * then defaults to 6 MHZ otherwise 48 MHZ.
1108197ba5f4SPaul Zimmerman  *
1109197ba5f4SPaul Zimmerman  * 0 - 48 MHz
1110197ba5f4SPaul Zimmerman  * 1 - 6 MHz
1111197ba5f4SPaul Zimmerman  */
1112197ba5f4SPaul Zimmerman extern void dwc2_set_param_host_ls_low_power_phy_clk(struct dwc2_hsotg *hsotg,
1113197ba5f4SPaul Zimmerman 						     int val);
1114197ba5f4SPaul Zimmerman #define DWC2_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ	0
1115197ba5f4SPaul Zimmerman #define DWC2_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ	1
1116197ba5f4SPaul Zimmerman 
1117197ba5f4SPaul Zimmerman /*
1118197ba5f4SPaul Zimmerman  * 0 - Use cC FIFO size parameters
1119197ba5f4SPaul Zimmerman  * 1 - Allow dynamic FIFO sizing (default)
1120197ba5f4SPaul Zimmerman  */
1121197ba5f4SPaul Zimmerman extern void dwc2_set_param_enable_dynamic_fifo(struct dwc2_hsotg *hsotg,
1122197ba5f4SPaul Zimmerman 					       int val);
1123197ba5f4SPaul Zimmerman 
1124197ba5f4SPaul Zimmerman /*
1125197ba5f4SPaul Zimmerman  * Number of 4-byte words in the Rx FIFO in host mode when dynamic
1126197ba5f4SPaul Zimmerman  * FIFO sizing is enabled.
1127197ba5f4SPaul Zimmerman  * 16 to 32768 (default 1024)
1128197ba5f4SPaul Zimmerman  */
1129197ba5f4SPaul Zimmerman extern void dwc2_set_param_host_rx_fifo_size(struct dwc2_hsotg *hsotg, int val);
1130197ba5f4SPaul Zimmerman 
1131197ba5f4SPaul Zimmerman /*
1132197ba5f4SPaul Zimmerman  * Number of 4-byte words in the non-periodic Tx FIFO in host mode
1133197ba5f4SPaul Zimmerman  * when Dynamic FIFO sizing is enabled in the core.
1134197ba5f4SPaul Zimmerman  * 16 to 32768 (default 256)
1135197ba5f4SPaul Zimmerman  */
1136197ba5f4SPaul Zimmerman extern void dwc2_set_param_host_nperio_tx_fifo_size(struct dwc2_hsotg *hsotg,
1137197ba5f4SPaul Zimmerman 						    int val);
1138197ba5f4SPaul Zimmerman 
1139197ba5f4SPaul Zimmerman /*
1140197ba5f4SPaul Zimmerman  * Number of 4-byte words in the host periodic Tx FIFO when dynamic
1141197ba5f4SPaul Zimmerman  * FIFO sizing is enabled.
1142197ba5f4SPaul Zimmerman  * 16 to 32768 (default 256)
1143197ba5f4SPaul Zimmerman  */
1144197ba5f4SPaul Zimmerman extern void dwc2_set_param_host_perio_tx_fifo_size(struct dwc2_hsotg *hsotg,
1145197ba5f4SPaul Zimmerman 						   int val);
1146197ba5f4SPaul Zimmerman 
1147197ba5f4SPaul Zimmerman /*
1148197ba5f4SPaul Zimmerman  * The maximum transfer size supported in bytes.
1149197ba5f4SPaul Zimmerman  * 2047 to 65,535  (default 65,535)
1150197ba5f4SPaul Zimmerman  */
1151197ba5f4SPaul Zimmerman extern void dwc2_set_param_max_transfer_size(struct dwc2_hsotg *hsotg, int val);
1152197ba5f4SPaul Zimmerman 
1153197ba5f4SPaul Zimmerman /*
1154197ba5f4SPaul Zimmerman  * The maximum number of packets in a transfer.
1155197ba5f4SPaul Zimmerman  * 15 to 511  (default 511)
1156197ba5f4SPaul Zimmerman  */
1157197ba5f4SPaul Zimmerman extern void dwc2_set_param_max_packet_count(struct dwc2_hsotg *hsotg, int val);
1158197ba5f4SPaul Zimmerman 
1159197ba5f4SPaul Zimmerman /*
1160197ba5f4SPaul Zimmerman  * The number of host channel registers to use.
1161197ba5f4SPaul Zimmerman  * 1 to 16 (default 11)
1162197ba5f4SPaul Zimmerman  * Note: The FPGA configuration supports a maximum of 11 host channels.
1163197ba5f4SPaul Zimmerman  */
1164197ba5f4SPaul Zimmerman extern void dwc2_set_param_host_channels(struct dwc2_hsotg *hsotg, int val);
1165197ba5f4SPaul Zimmerman 
1166197ba5f4SPaul Zimmerman /*
1167197ba5f4SPaul Zimmerman  * Specifies the type of PHY interface to use. By default, the driver
1168197ba5f4SPaul Zimmerman  * will automatically detect the phy_type.
1169197ba5f4SPaul Zimmerman  *
1170197ba5f4SPaul Zimmerman  * 0 - Full Speed PHY
1171197ba5f4SPaul Zimmerman  * 1 - UTMI+ (default)
1172197ba5f4SPaul Zimmerman  * 2 - ULPI
1173197ba5f4SPaul Zimmerman  */
1174197ba5f4SPaul Zimmerman extern void dwc2_set_param_phy_type(struct dwc2_hsotg *hsotg, int val);
1175197ba5f4SPaul Zimmerman #define DWC2_PHY_TYPE_PARAM_FS		0
1176197ba5f4SPaul Zimmerman #define DWC2_PHY_TYPE_PARAM_UTMI	1
1177197ba5f4SPaul Zimmerman #define DWC2_PHY_TYPE_PARAM_ULPI	2
1178197ba5f4SPaul Zimmerman 
1179197ba5f4SPaul Zimmerman /*
1180197ba5f4SPaul Zimmerman  * Specifies the UTMI+ Data Width. This parameter is
1181197ba5f4SPaul Zimmerman  * applicable for a PHY_TYPE of UTMI+ or ULPI. (For a ULPI
1182197ba5f4SPaul Zimmerman  * PHY_TYPE, this parameter indicates the data width between
1183197ba5f4SPaul Zimmerman  * the MAC and the ULPI Wrapper.) Also, this parameter is
1184197ba5f4SPaul Zimmerman  * applicable only if the OTG_HSPHY_WIDTH cC parameter was set
1185197ba5f4SPaul Zimmerman  * to "8 and 16 bits", meaning that the core has been
1186197ba5f4SPaul Zimmerman  * configured to work at either data path width.
1187197ba5f4SPaul Zimmerman  *
1188197ba5f4SPaul Zimmerman  * 8 or 16 bits (default 16)
1189197ba5f4SPaul Zimmerman  */
1190197ba5f4SPaul Zimmerman extern void dwc2_set_param_phy_utmi_width(struct dwc2_hsotg *hsotg, int val);
1191197ba5f4SPaul Zimmerman 
1192197ba5f4SPaul Zimmerman /*
1193197ba5f4SPaul Zimmerman  * Specifies whether the ULPI operates at double or single
1194197ba5f4SPaul Zimmerman  * data rate. This parameter is only applicable if PHY_TYPE is
1195197ba5f4SPaul Zimmerman  * ULPI.
1196197ba5f4SPaul Zimmerman  *
1197197ba5f4SPaul Zimmerman  * 0 - single data rate ULPI interface with 8 bit wide data
1198197ba5f4SPaul Zimmerman  * bus (default)
1199197ba5f4SPaul Zimmerman  * 1 - double data rate ULPI interface with 4 bit wide data
1200197ba5f4SPaul Zimmerman  * bus
1201197ba5f4SPaul Zimmerman  */
1202197ba5f4SPaul Zimmerman extern void dwc2_set_param_phy_ulpi_ddr(struct dwc2_hsotg *hsotg, int val);
1203197ba5f4SPaul Zimmerman 
1204197ba5f4SPaul Zimmerman /*
1205197ba5f4SPaul Zimmerman  * Specifies whether to use the internal or external supply to
1206197ba5f4SPaul Zimmerman  * drive the vbus with a ULPI phy.
1207197ba5f4SPaul Zimmerman  */
1208197ba5f4SPaul Zimmerman extern void dwc2_set_param_phy_ulpi_ext_vbus(struct dwc2_hsotg *hsotg, int val);
1209197ba5f4SPaul Zimmerman #define DWC2_PHY_ULPI_INTERNAL_VBUS	0
1210197ba5f4SPaul Zimmerman #define DWC2_PHY_ULPI_EXTERNAL_VBUS	1
1211197ba5f4SPaul Zimmerman 
1212197ba5f4SPaul Zimmerman /*
1213197ba5f4SPaul Zimmerman  * Specifies whether to use the I2Cinterface for full speed PHY. This
1214197ba5f4SPaul Zimmerman  * parameter is only applicable if PHY_TYPE is FS.
1215197ba5f4SPaul Zimmerman  * 0 - No (default)
1216197ba5f4SPaul Zimmerman  * 1 - Yes
1217197ba5f4SPaul Zimmerman  */
1218197ba5f4SPaul Zimmerman extern void dwc2_set_param_i2c_enable(struct dwc2_hsotg *hsotg, int val);
1219197ba5f4SPaul Zimmerman 
1220197ba5f4SPaul Zimmerman extern void dwc2_set_param_ulpi_fs_ls(struct dwc2_hsotg *hsotg, int val);
1221197ba5f4SPaul Zimmerman 
1222197ba5f4SPaul Zimmerman extern void dwc2_set_param_ts_dline(struct dwc2_hsotg *hsotg, int val);
1223197ba5f4SPaul Zimmerman 
1224197ba5f4SPaul Zimmerman /*
1225197ba5f4SPaul Zimmerman  * Specifies whether dedicated transmit FIFOs are
1226197ba5f4SPaul Zimmerman  * enabled for non periodic IN endpoints in device mode
1227197ba5f4SPaul Zimmerman  * 0 - No
1228197ba5f4SPaul Zimmerman  * 1 - Yes
1229197ba5f4SPaul Zimmerman  */
1230197ba5f4SPaul Zimmerman extern void dwc2_set_param_en_multiple_tx_fifo(struct dwc2_hsotg *hsotg,
1231197ba5f4SPaul Zimmerman 					       int val);
1232197ba5f4SPaul Zimmerman 
1233197ba5f4SPaul Zimmerman extern void dwc2_set_param_reload_ctl(struct dwc2_hsotg *hsotg, int val);
1234197ba5f4SPaul Zimmerman 
1235197ba5f4SPaul Zimmerman extern void dwc2_set_param_ahbcfg(struct dwc2_hsotg *hsotg, int val);
1236197ba5f4SPaul Zimmerman 
1237197ba5f4SPaul Zimmerman extern void dwc2_set_param_otg_ver(struct dwc2_hsotg *hsotg, int val);
1238197ba5f4SPaul Zimmerman 
1239ecb176c6SMian Yousaf Kaukab extern void dwc2_set_parameters(struct dwc2_hsotg *hsotg,
1240ecb176c6SMian Yousaf Kaukab 				const struct dwc2_core_params *params);
1241ecb176c6SMian Yousaf Kaukab 
1242ecb176c6SMian Yousaf Kaukab extern void dwc2_set_all_params(struct dwc2_core_params *params, int value);
1243ecb176c6SMian Yousaf Kaukab 
1244ecb176c6SMian Yousaf Kaukab extern int dwc2_get_hwparams(struct dwc2_hsotg *hsotg);
1245ecb176c6SMian Yousaf Kaukab 
124609a75e85SMarek Szyprowski extern int dwc2_lowlevel_hw_enable(struct dwc2_hsotg *hsotg);
124709a75e85SMarek Szyprowski extern int dwc2_lowlevel_hw_disable(struct dwc2_hsotg *hsotg);
1248ecb176c6SMian Yousaf Kaukab 
1249197ba5f4SPaul Zimmerman /*
12506bea9620SJohn Youn  * The following functions check the controller's OTG operation mode
12516bea9620SJohn Youn  * capability (GHWCFG2.OTG_MODE).
12526bea9620SJohn Youn  *
12536bea9620SJohn Youn  * These functions can be used before the internal hsotg->hw_params
12546bea9620SJohn Youn  * are read in and cached so they always read directly from the
12556bea9620SJohn Youn  * GHWCFG2 register.
12566bea9620SJohn Youn  */
12576bea9620SJohn Youn unsigned dwc2_op_mode(struct dwc2_hsotg *hsotg);
12586bea9620SJohn Youn bool dwc2_hw_is_otg(struct dwc2_hsotg *hsotg);
12596bea9620SJohn Youn bool dwc2_hw_is_host(struct dwc2_hsotg *hsotg);
12606bea9620SJohn Youn bool dwc2_hw_is_device(struct dwc2_hsotg *hsotg);
12616bea9620SJohn Youn 
12626bea9620SJohn Youn /*
12631696d5abSJohn Youn  * Returns the mode of operation, host or device
12641696d5abSJohn Youn  */
12651696d5abSJohn Youn static inline int dwc2_is_host_mode(struct dwc2_hsotg *hsotg)
12661696d5abSJohn Youn {
12671696d5abSJohn Youn 	return (dwc2_readl(hsotg->regs + GINTSTS) & GINTSTS_CURMODE_HOST) != 0;
12681696d5abSJohn Youn }
12691696d5abSJohn Youn static inline int dwc2_is_device_mode(struct dwc2_hsotg *hsotg)
12701696d5abSJohn Youn {
12711696d5abSJohn Youn 	return (dwc2_readl(hsotg->regs + GINTSTS) & GINTSTS_CURMODE_HOST) == 0;
12721696d5abSJohn Youn }
12731696d5abSJohn Youn 
12741696d5abSJohn Youn /*
1275197ba5f4SPaul Zimmerman  * Dump core registers and SPRAM
1276197ba5f4SPaul Zimmerman  */
1277197ba5f4SPaul Zimmerman extern void dwc2_dump_dev_registers(struct dwc2_hsotg *hsotg);
1278197ba5f4SPaul Zimmerman extern void dwc2_dump_host_registers(struct dwc2_hsotg *hsotg);
1279197ba5f4SPaul Zimmerman extern void dwc2_dump_global_registers(struct dwc2_hsotg *hsotg);
1280197ba5f4SPaul Zimmerman 
1281197ba5f4SPaul Zimmerman /*
1282197ba5f4SPaul Zimmerman  * Return OTG version - either 1.3 or 2.0
1283197ba5f4SPaul Zimmerman  */
1284197ba5f4SPaul Zimmerman extern u16 dwc2_get_otg_version(struct dwc2_hsotg *hsotg);
1285197ba5f4SPaul Zimmerman 
1286117777b2SDinh Nguyen /* Gadget defines */
1287117777b2SDinh Nguyen #if IS_ENABLED(CONFIG_USB_DWC2_PERIPHERAL) || IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE)
12881f91b4ccSFelipe Balbi extern int dwc2_hsotg_remove(struct dwc2_hsotg *hsotg);
12891f91b4ccSFelipe Balbi extern int dwc2_hsotg_suspend(struct dwc2_hsotg *dwc2);
12901f91b4ccSFelipe Balbi extern int dwc2_hsotg_resume(struct dwc2_hsotg *dwc2);
1291117777b2SDinh Nguyen extern int dwc2_gadget_init(struct dwc2_hsotg *hsotg, int irq);
12921f91b4ccSFelipe Balbi extern void dwc2_hsotg_core_init_disconnected(struct dwc2_hsotg *dwc2,
1293643cc4deSGregory Herrero 		bool reset);
12941f91b4ccSFelipe Balbi extern void dwc2_hsotg_core_connect(struct dwc2_hsotg *hsotg);
12951f91b4ccSFelipe Balbi extern void dwc2_hsotg_disconnect(struct dwc2_hsotg *dwc2);
12961f91b4ccSFelipe Balbi extern int dwc2_hsotg_set_test_mode(struct dwc2_hsotg *hsotg, int testmode);
1297f81f46e1SGregory Herrero #define dwc2_is_device_connected(hsotg) (hsotg->connected)
1298117777b2SDinh Nguyen #else
12991f91b4ccSFelipe Balbi static inline int dwc2_hsotg_remove(struct dwc2_hsotg *dwc2)
1300117777b2SDinh Nguyen { return 0; }
13011f91b4ccSFelipe Balbi static inline int dwc2_hsotg_suspend(struct dwc2_hsotg *dwc2)
1302117777b2SDinh Nguyen { return 0; }
13031f91b4ccSFelipe Balbi static inline int dwc2_hsotg_resume(struct dwc2_hsotg *dwc2)
1304117777b2SDinh Nguyen { return 0; }
1305117777b2SDinh Nguyen static inline int dwc2_gadget_init(struct dwc2_hsotg *hsotg, int irq)
1306117777b2SDinh Nguyen { return 0; }
13071f91b4ccSFelipe Balbi static inline void dwc2_hsotg_core_init_disconnected(struct dwc2_hsotg *dwc2,
1308643cc4deSGregory Herrero 		bool reset) {}
13091f91b4ccSFelipe Balbi static inline void dwc2_hsotg_core_connect(struct dwc2_hsotg *hsotg) {}
13101f91b4ccSFelipe Balbi static inline void dwc2_hsotg_disconnect(struct dwc2_hsotg *dwc2) {}
13111f91b4ccSFelipe Balbi static inline int dwc2_hsotg_set_test_mode(struct dwc2_hsotg *hsotg,
1312f91eea44SMian Yousaf Kaukab 							int testmode)
1313f91eea44SMian Yousaf Kaukab { return 0; }
1314f81f46e1SGregory Herrero #define dwc2_is_device_connected(hsotg) (0)
1315117777b2SDinh Nguyen #endif
1316117777b2SDinh Nguyen 
1317117777b2SDinh Nguyen #if IS_ENABLED(CONFIG_USB_DWC2_HOST) || IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE)
1318117777b2SDinh Nguyen extern int dwc2_hcd_get_frame_number(struct dwc2_hsotg *hsotg);
1319fae4e826SDouglas Anderson extern int dwc2_hcd_get_future_frame_number(struct dwc2_hsotg *hsotg, int us);
13206a659531SDouglas Anderson extern void dwc2_hcd_connect(struct dwc2_hsotg *hsotg);
13216a659531SDouglas Anderson extern void dwc2_hcd_disconnect(struct dwc2_hsotg *hsotg, bool force);
1322117777b2SDinh Nguyen extern void dwc2_hcd_start(struct dwc2_hsotg *hsotg);
1323117777b2SDinh Nguyen #else
1324117777b2SDinh Nguyen static inline int dwc2_hcd_get_frame_number(struct dwc2_hsotg *hsotg)
1325117777b2SDinh Nguyen { return 0; }
1326fae4e826SDouglas Anderson static inline int dwc2_hcd_get_future_frame_number(struct dwc2_hsotg *hsotg,
1327fae4e826SDouglas Anderson 						   int us)
1328fae4e826SDouglas Anderson { return 0; }
13296a659531SDouglas Anderson static inline void dwc2_hcd_connect(struct dwc2_hsotg *hsotg) {}
13306a659531SDouglas Anderson static inline void dwc2_hcd_disconnect(struct dwc2_hsotg *hsotg, bool force) {}
1331117777b2SDinh Nguyen static inline void dwc2_hcd_start(struct dwc2_hsotg *hsotg) {}
1332117777b2SDinh Nguyen static inline void dwc2_hcd_remove(struct dwc2_hsotg *hsotg) {}
1333ecb176c6SMian Yousaf Kaukab static inline int dwc2_hcd_init(struct dwc2_hsotg *hsotg, int irq)
1334117777b2SDinh Nguyen { return 0; }
1335117777b2SDinh Nguyen #endif
1336117777b2SDinh Nguyen 
1337197ba5f4SPaul Zimmerman #endif /* __DWC2_CORE_H__ */
1338