xref: /openbmc/linux/drivers/usb/dwc2/core.h (revision c40cf770)
15fd54aceSGreg Kroah-Hartman // SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
2197ba5f4SPaul Zimmerman /*
3197ba5f4SPaul Zimmerman  * core.h - DesignWare HS OTG Controller common declarations
4197ba5f4SPaul Zimmerman  *
5197ba5f4SPaul Zimmerman  * Copyright (C) 2004-2013 Synopsys, Inc.
6197ba5f4SPaul Zimmerman  *
7197ba5f4SPaul Zimmerman  * Redistribution and use in source and binary forms, with or without
8197ba5f4SPaul Zimmerman  * modification, are permitted provided that the following conditions
9197ba5f4SPaul Zimmerman  * are met:
10197ba5f4SPaul Zimmerman  * 1. Redistributions of source code must retain the above copyright
11197ba5f4SPaul Zimmerman  *    notice, this list of conditions, and the following disclaimer,
12197ba5f4SPaul Zimmerman  *    without modification.
13197ba5f4SPaul Zimmerman  * 2. Redistributions in binary form must reproduce the above copyright
14197ba5f4SPaul Zimmerman  *    notice, this list of conditions and the following disclaimer in the
15197ba5f4SPaul Zimmerman  *    documentation and/or other materials provided with the distribution.
16197ba5f4SPaul Zimmerman  * 3. The names of the above-listed copyright holders may not be used
17197ba5f4SPaul Zimmerman  *    to endorse or promote products derived from this software without
18197ba5f4SPaul Zimmerman  *    specific prior written permission.
19197ba5f4SPaul Zimmerman  *
20197ba5f4SPaul Zimmerman  * ALTERNATIVELY, this software may be distributed under the terms of the
21197ba5f4SPaul Zimmerman  * GNU General Public License ("GPL") as published by the Free Software
22197ba5f4SPaul Zimmerman  * Foundation; either version 2 of the License, or (at your option) any
23197ba5f4SPaul Zimmerman  * later version.
24197ba5f4SPaul Zimmerman  *
25197ba5f4SPaul Zimmerman  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
26197ba5f4SPaul Zimmerman  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
27197ba5f4SPaul Zimmerman  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28197ba5f4SPaul Zimmerman  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
29197ba5f4SPaul Zimmerman  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30197ba5f4SPaul Zimmerman  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31197ba5f4SPaul Zimmerman  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32197ba5f4SPaul Zimmerman  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33197ba5f4SPaul Zimmerman  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34197ba5f4SPaul Zimmerman  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35197ba5f4SPaul Zimmerman  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36197ba5f4SPaul Zimmerman  */
37197ba5f4SPaul Zimmerman 
38197ba5f4SPaul Zimmerman #ifndef __DWC2_CORE_H__
39197ba5f4SPaul Zimmerman #define __DWC2_CORE_H__
40197ba5f4SPaul Zimmerman 
41f7c0b143SDinh Nguyen #include <linux/phy/phy.h>
42f7c0b143SDinh Nguyen #include <linux/regulator/consumer.h>
43f7c0b143SDinh Nguyen #include <linux/usb/gadget.h>
44f7c0b143SDinh Nguyen #include <linux/usb/otg.h>
45197ba5f4SPaul Zimmerman #include <linux/usb/phy.h>
46197ba5f4SPaul Zimmerman #include "hw.h"
47197ba5f4SPaul Zimmerman 
4874fc4a75SDouglas Anderson /*
4974fc4a75SDouglas Anderson  * Suggested defines for tracers:
5074fc4a75SDouglas Anderson  * - no_printk:    Disable tracing
5174fc4a75SDouglas Anderson  * - pr_info:      Print this info to the console
5274fc4a75SDouglas Anderson  * - trace_printk: Print this info to trace buffer (good for verbose logging)
5374fc4a75SDouglas Anderson  */
5474fc4a75SDouglas Anderson 
5574fc4a75SDouglas Anderson #define DWC2_TRACE_SCHEDULER		no_printk
5674fc4a75SDouglas Anderson #define DWC2_TRACE_SCHEDULER_VB		no_printk
5774fc4a75SDouglas Anderson 
5874fc4a75SDouglas Anderson /* Detailed scheduler tracing, but won't overwhelm console */
5974fc4a75SDouglas Anderson #define dwc2_sch_dbg(hsotg, fmt, ...)					\
6074fc4a75SDouglas Anderson 	DWC2_TRACE_SCHEDULER(pr_fmt("%s: SCH: " fmt),			\
6174fc4a75SDouglas Anderson 			     dev_name(hsotg->dev), ##__VA_ARGS__)
6274fc4a75SDouglas Anderson 
6374fc4a75SDouglas Anderson /* Verbose scheduler tracing */
6474fc4a75SDouglas Anderson #define dwc2_sch_vdbg(hsotg, fmt, ...)					\
6574fc4a75SDouglas Anderson 	DWC2_TRACE_SCHEDULER_VB(pr_fmt("%s: SCH: " fmt),		\
6674fc4a75SDouglas Anderson 				dev_name(hsotg->dev), ##__VA_ARGS__)
6774fc4a75SDouglas Anderson 
68197ba5f4SPaul Zimmerman /* Maximum number of Endpoints/HostChannels */
69197ba5f4SPaul Zimmerman #define MAX_EPS_CHANNELS	16
70197ba5f4SPaul Zimmerman 
711f91b4ccSFelipe Balbi /* dwc2-hsotg declarations */
721f91b4ccSFelipe Balbi static const char * const dwc2_hsotg_supply_names[] = {
73f7c0b143SDinh Nguyen 	"vusb_d",               /* digital USB supply, 1.2V */
74f7c0b143SDinh Nguyen 	"vusb_a",               /* analog USB supply, 1.1V */
75f7c0b143SDinh Nguyen };
76f7c0b143SDinh Nguyen 
77b98866c2SJohn Youn #define DWC2_NUM_SUPPLIES ARRAY_SIZE(dwc2_hsotg_supply_names)
78b98866c2SJohn Youn 
79f7c0b143SDinh Nguyen /*
80f7c0b143SDinh Nguyen  * EP0_MPS_LIMIT
81f7c0b143SDinh Nguyen  *
82f7c0b143SDinh Nguyen  * Unfortunately there seems to be a limit of the amount of data that can
83f7c0b143SDinh Nguyen  * be transferred by IN transactions on EP0. This is either 127 bytes or 3
84f7c0b143SDinh Nguyen  * packets (which practically means 1 packet and 63 bytes of data) when the
85f7c0b143SDinh Nguyen  * MPS is set to 64.
86f7c0b143SDinh Nguyen  *
87f7c0b143SDinh Nguyen  * This means if we are wanting to move >127 bytes of data, we need to
88f7c0b143SDinh Nguyen  * split the transactions up, but just doing one packet at a time does
89f7c0b143SDinh Nguyen  * not work (this may be an implicit DATA0 PID on first packet of the
90f7c0b143SDinh Nguyen  * transaction) and doing 2 packets is outside the controller's limits.
91f7c0b143SDinh Nguyen  *
92f7c0b143SDinh Nguyen  * If we try to lower the MPS size for EP0, then no transfers work properly
93f7c0b143SDinh Nguyen  * for EP0, and the system will fail basic enumeration. As no cause for this
94f7c0b143SDinh Nguyen  * has currently been found, we cannot support any large IN transfers for
95f7c0b143SDinh Nguyen  * EP0.
96f7c0b143SDinh Nguyen  */
97f7c0b143SDinh Nguyen #define EP0_MPS_LIMIT   64
98f7c0b143SDinh Nguyen 
99941fcce4SDinh Nguyen struct dwc2_hsotg;
1001f91b4ccSFelipe Balbi struct dwc2_hsotg_req;
101f7c0b143SDinh Nguyen 
102f7c0b143SDinh Nguyen /**
1031f91b4ccSFelipe Balbi  * struct dwc2_hsotg_ep - driver endpoint definition.
104f7c0b143SDinh Nguyen  * @ep: The gadget layer representation of the endpoint.
105f7c0b143SDinh Nguyen  * @name: The driver generated name for the endpoint.
106f7c0b143SDinh Nguyen  * @queue: Queue of requests for this endpoint.
107f7c0b143SDinh Nguyen  * @parent: Reference back to the parent device structure.
108f7c0b143SDinh Nguyen  * @req: The current request that the endpoint is processing. This is
109f7c0b143SDinh Nguyen  *       used to indicate an request has been loaded onto the endpoint
110f7c0b143SDinh Nguyen  *       and has yet to be completed (maybe due to data move, or simply
111f7c0b143SDinh Nguyen  *       awaiting an ack from the core all the data has been completed).
112f7c0b143SDinh Nguyen  * @debugfs: File entry for debugfs file for this endpoint.
113f7c0b143SDinh Nguyen  * @dir_in: Set to true if this endpoint is of the IN direction, which
114f7c0b143SDinh Nguyen  *          means that it is sending data to the Host.
115f7c0b143SDinh Nguyen  * @index: The index for the endpoint registers.
116f7c0b143SDinh Nguyen  * @mc: Multi Count - number of transactions per microframe
1176fb914d7SGrigor Tovmasyan  * @interval: Interval for periodic endpoints, in frames or microframes.
118f7c0b143SDinh Nguyen  * @name: The name array passed to the USB core.
119f7c0b143SDinh Nguyen  * @halted: Set if the endpoint has been halted.
120f7c0b143SDinh Nguyen  * @periodic: Set if this is a periodic ep, such as Interrupt
121f7c0b143SDinh Nguyen  * @isochronous: Set if this is a isochronous ep
1228a20fa45SMian Yousaf Kaukab  * @send_zlp: Set if we need to send a zero-length packet.
1235f54c54bSVahram Aharonyan  * @desc_list_dma: The DMA address of descriptor chain currently in use.
1245f54c54bSVahram Aharonyan  * @desc_list: Pointer to descriptor DMA chain head currently in use.
1255f54c54bSVahram Aharonyan  * @desc_count: Count of entries within the DMA descriptor chain of EP.
126ab7d2192SVahram Aharonyan  * @next_desc: index of next free descriptor in the ISOC chain under SW control.
127729cac69SMinas Harutyunyan  * @compl_desc: index of next descriptor to be completed by xFerComplete
128f7c0b143SDinh Nguyen  * @total_data: The total number of data bytes done.
129f7c0b143SDinh Nguyen  * @fifo_size: The size of the FIFO (for periodic IN endpoints)
1306fb914d7SGrigor Tovmasyan  * @fifo_index: For Dedicated FIFO operation, only FIFO0 can be used for EP0.
131f7c0b143SDinh Nguyen  * @fifo_load: The amount of data loaded into the FIFO (periodic IN)
132f7c0b143SDinh Nguyen  * @last_load: The offset of data for the last start of request.
133f7c0b143SDinh Nguyen  * @size_loaded: The last loaded size for DxEPTSIZE for periodic IN
13492d1635dSVardan Mikayelyan  * @target_frame: Targeted frame num to setup next ISOC transfer
13592d1635dSVardan Mikayelyan  * @frame_overrun: Indicates SOF number overrun in DSTS
136f7c0b143SDinh Nguyen  *
137f7c0b143SDinh Nguyen  * This is the driver's state for each registered enpoint, allowing it
138f7c0b143SDinh Nguyen  * to keep track of transactions that need doing. Each endpoint has a
139f7c0b143SDinh Nguyen  * lock to protect the state, to try and avoid using an overall lock
140f7c0b143SDinh Nguyen  * for the host controller as much as possible.
141f7c0b143SDinh Nguyen  *
142f7c0b143SDinh Nguyen  * For periodic IN endpoints, we have fifo_size and fifo_load to try
143f7c0b143SDinh Nguyen  * and keep track of the amount of data in the periodic FIFO for each
144f7c0b143SDinh Nguyen  * of these as we don't have a status register that tells us how much
145f7c0b143SDinh Nguyen  * is in each of them. (note, this may actually be useless information
146f7c0b143SDinh Nguyen  * as in shared-fifo mode periodic in acts like a single-frame packet
147f7c0b143SDinh Nguyen  * buffer than a fifo)
148f7c0b143SDinh Nguyen  */
1491f91b4ccSFelipe Balbi struct dwc2_hsotg_ep {
150f7c0b143SDinh Nguyen 	struct usb_ep           ep;
151f7c0b143SDinh Nguyen 	struct list_head        queue;
152941fcce4SDinh Nguyen 	struct dwc2_hsotg       *parent;
1531f91b4ccSFelipe Balbi 	struct dwc2_hsotg_req    *req;
154f7c0b143SDinh Nguyen 	struct dentry           *debugfs;
155f7c0b143SDinh Nguyen 
156f7c0b143SDinh Nguyen 	unsigned long           total_data;
157f7c0b143SDinh Nguyen 	unsigned int            size_loaded;
158f7c0b143SDinh Nguyen 	unsigned int            last_load;
159f7c0b143SDinh Nguyen 	unsigned int            fifo_load;
160f7c0b143SDinh Nguyen 	unsigned short          fifo_size;
161b203d0a2SRobert Baldyga 	unsigned short		fifo_index;
162f7c0b143SDinh Nguyen 
163f7c0b143SDinh Nguyen 	unsigned char           dir_in;
164f7c0b143SDinh Nguyen 	unsigned char           index;
165f7c0b143SDinh Nguyen 	unsigned char           mc;
16612814a3fSGrigor Tovmasyan 	u16                     interval;
167f7c0b143SDinh Nguyen 
168f7c0b143SDinh Nguyen 	unsigned int            halted:1;
169f7c0b143SDinh Nguyen 	unsigned int            periodic:1;
170f7c0b143SDinh Nguyen 	unsigned int            isochronous:1;
1718a20fa45SMian Yousaf Kaukab 	unsigned int            send_zlp:1;
17292d1635dSVardan Mikayelyan 	unsigned int            target_frame;
17392d1635dSVardan Mikayelyan #define TARGET_FRAME_INITIAL   0xFFFFFFFF
17492d1635dSVardan Mikayelyan 	bool			frame_overrun;
175f7c0b143SDinh Nguyen 
1765f54c54bSVahram Aharonyan 	dma_addr_t		desc_list_dma;
1775f54c54bSVahram Aharonyan 	struct dwc2_dma_desc	*desc_list;
1785f54c54bSVahram Aharonyan 	u8			desc_count;
1795f54c54bSVahram Aharonyan 
180ab7d2192SVahram Aharonyan 	unsigned int		next_desc;
181729cac69SMinas Harutyunyan 	unsigned int		compl_desc;
182ab7d2192SVahram Aharonyan 
183f7c0b143SDinh Nguyen 	char                    name[10];
184f7c0b143SDinh Nguyen };
185f7c0b143SDinh Nguyen 
186f7c0b143SDinh Nguyen /**
1871f91b4ccSFelipe Balbi  * struct dwc2_hsotg_req - data transfer request
188f7c0b143SDinh Nguyen  * @req: The USB gadget request
189f7c0b143SDinh Nguyen  * @queue: The list of requests for the endpoint this is queued for.
1907d24c1b5SMian Yousaf Kaukab  * @saved_req_buf: variable to save req.buf when bounce buffers are used.
191f7c0b143SDinh Nguyen  */
1921f91b4ccSFelipe Balbi struct dwc2_hsotg_req {
193f7c0b143SDinh Nguyen 	struct usb_request      req;
194f7c0b143SDinh Nguyen 	struct list_head        queue;
1957d24c1b5SMian Yousaf Kaukab 	void *saved_req_buf;
196f7c0b143SDinh Nguyen };
197f7c0b143SDinh Nguyen 
198b98866c2SJohn Youn #if IS_ENABLED(CONFIG_USB_DWC2_PERIPHERAL) || \
199b98866c2SJohn Youn 	IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE)
200f7c0b143SDinh Nguyen #define call_gadget(_hs, _entry) \
201f7c0b143SDinh Nguyen do { \
202f7c0b143SDinh Nguyen 	if ((_hs)->gadget.speed != USB_SPEED_UNKNOWN && \
203f7c0b143SDinh Nguyen 		(_hs)->driver && (_hs)->driver->_entry) { \
204f7c0b143SDinh Nguyen 		spin_unlock(&_hs->lock); \
205f7c0b143SDinh Nguyen 		(_hs)->driver->_entry(&(_hs)->gadget); \
206f7c0b143SDinh Nguyen 		spin_lock(&_hs->lock); \
207f7c0b143SDinh Nguyen 	} \
208f7c0b143SDinh Nguyen } while (0)
209941fcce4SDinh Nguyen #else
210941fcce4SDinh Nguyen #define call_gadget(_hs, _entry)	do {} while (0)
211941fcce4SDinh Nguyen #endif
212f7c0b143SDinh Nguyen 
213197ba5f4SPaul Zimmerman struct dwc2_hsotg;
214197ba5f4SPaul Zimmerman struct dwc2_host_chan;
215197ba5f4SPaul Zimmerman 
216197ba5f4SPaul Zimmerman /* Device States */
217197ba5f4SPaul Zimmerman enum dwc2_lx_state {
218197ba5f4SPaul Zimmerman 	DWC2_L0,	/* On state */
219197ba5f4SPaul Zimmerman 	DWC2_L1,	/* LPM sleep state */
220197ba5f4SPaul Zimmerman 	DWC2_L2,	/* USB suspend state */
221197ba5f4SPaul Zimmerman 	DWC2_L3,	/* Off state */
222197ba5f4SPaul Zimmerman };
223197ba5f4SPaul Zimmerman 
224fe0b94abSMian Yousaf Kaukab /* Gadget ep0 states */
225fe0b94abSMian Yousaf Kaukab enum dwc2_ep0_state {
226fe0b94abSMian Yousaf Kaukab 	DWC2_EP0_SETUP,
227fe0b94abSMian Yousaf Kaukab 	DWC2_EP0_DATA_IN,
228fe0b94abSMian Yousaf Kaukab 	DWC2_EP0_DATA_OUT,
229fe0b94abSMian Yousaf Kaukab 	DWC2_EP0_STATUS_IN,
230fe0b94abSMian Yousaf Kaukab 	DWC2_EP0_STATUS_OUT,
231fe0b94abSMian Yousaf Kaukab };
232fe0b94abSMian Yousaf Kaukab 
233197ba5f4SPaul Zimmerman /**
234197ba5f4SPaul Zimmerman  * struct dwc2_core_params - Parameters for configuring the core
235197ba5f4SPaul Zimmerman  *
236197ba5f4SPaul Zimmerman  * @otg_cap:            Specifies the OTG capabilities.
237197ba5f4SPaul Zimmerman  *                       0 - HNP and SRP capable
238197ba5f4SPaul Zimmerman  *                       1 - SRP Only capable
239197ba5f4SPaul Zimmerman  *                       2 - No HNP/SRP capable (always available)
240197ba5f4SPaul Zimmerman  *                      Defaults to best available option (0, 1, then 2)
241e7839f99SJohn Youn  * @host_dma:           Specifies whether to use slave or DMA mode for accessing
242197ba5f4SPaul Zimmerman  *                      the data FIFOs. The driver will automatically detect the
243197ba5f4SPaul Zimmerman  *                      value for this parameter if none is specified.
244197ba5f4SPaul Zimmerman  *                       0 - Slave (always available)
245197ba5f4SPaul Zimmerman  *                       1 - DMA (default, if available)
246197ba5f4SPaul Zimmerman  * @dma_desc_enable:    When DMA mode is enabled, specifies whether to use
247197ba5f4SPaul Zimmerman  *                      address DMA mode or descriptor DMA mode for accessing
248197ba5f4SPaul Zimmerman  *                      the data FIFOs. The driver will automatically detect the
249197ba5f4SPaul Zimmerman  *                      value for this if none is specified.
250197ba5f4SPaul Zimmerman  *                       0 - Address DMA
251197ba5f4SPaul Zimmerman  *                       1 - Descriptor DMA (default, if available)
252fbb9e22bSMian Yousaf Kaukab  * @dma_desc_fs_enable: When DMA mode is enabled, specifies whether to use
253fbb9e22bSMian Yousaf Kaukab  *                      address DMA mode or descriptor DMA mode for accessing
254fbb9e22bSMian Yousaf Kaukab  *                      the data FIFOs in Full Speed mode only. The driver
255fbb9e22bSMian Yousaf Kaukab  *                      will automatically detect the value for this if none is
256fbb9e22bSMian Yousaf Kaukab  *                      specified.
257fbb9e22bSMian Yousaf Kaukab  *                       0 - Address DMA
258fbb9e22bSMian Yousaf Kaukab  *                       1 - Descriptor DMA in FS (default, if available)
259197ba5f4SPaul Zimmerman  * @speed:              Specifies the maximum speed of operation in host and
260197ba5f4SPaul Zimmerman  *                      device mode. The actual speed depends on the speed of
261197ba5f4SPaul Zimmerman  *                      the attached device and the value of phy_type.
262197ba5f4SPaul Zimmerman  *                       0 - High Speed
263197ba5f4SPaul Zimmerman  *                           (default when phy_type is UTMI+ or ULPI)
264197ba5f4SPaul Zimmerman  *                       1 - Full Speed
265197ba5f4SPaul Zimmerman  *                           (default when phy_type is Full Speed)
266197ba5f4SPaul Zimmerman  * @enable_dynamic_fifo: 0 - Use coreConsultant-specified FIFO size parameters
267197ba5f4SPaul Zimmerman  *                       1 - Allow dynamic FIFO sizing (default, if available)
268197ba5f4SPaul Zimmerman  * @en_multiple_tx_fifo: Specifies whether dedicated per-endpoint transmit FIFOs
269c1d286cfSJohn Youn  *                      are enabled for non-periodic IN endpoints in device
270c1d286cfSJohn Youn  *                      mode.
271197ba5f4SPaul Zimmerman  * @host_rx_fifo_size:  Number of 4-byte words in the Rx FIFO in host mode when
272197ba5f4SPaul Zimmerman  *                      dynamic FIFO sizing is enabled
273197ba5f4SPaul Zimmerman  *                       16 to 32768
274197ba5f4SPaul Zimmerman  *                      Actual maximum value is autodetected and also
275197ba5f4SPaul Zimmerman  *                      the default.
276197ba5f4SPaul Zimmerman  * @host_nperio_tx_fifo_size: Number of 4-byte words in the non-periodic Tx FIFO
277197ba5f4SPaul Zimmerman  *                      in host mode when dynamic FIFO sizing is enabled
278197ba5f4SPaul Zimmerman  *                       16 to 32768
279197ba5f4SPaul Zimmerman  *                      Actual maximum value is autodetected and also
280197ba5f4SPaul Zimmerman  *                      the default.
281197ba5f4SPaul Zimmerman  * @host_perio_tx_fifo_size: Number of 4-byte words in the periodic Tx FIFO in
282197ba5f4SPaul Zimmerman  *                      host mode when dynamic FIFO sizing is enabled
283197ba5f4SPaul Zimmerman  *                       16 to 32768
284197ba5f4SPaul Zimmerman  *                      Actual maximum value is autodetected and also
285197ba5f4SPaul Zimmerman  *                      the default.
286197ba5f4SPaul Zimmerman  * @max_transfer_size:  The maximum transfer size supported, in bytes
287197ba5f4SPaul Zimmerman  *                       2047 to 65,535
288197ba5f4SPaul Zimmerman  *                      Actual maximum value is autodetected and also
289197ba5f4SPaul Zimmerman  *                      the default.
290197ba5f4SPaul Zimmerman  * @max_packet_count:   The maximum number of packets in a transfer
291197ba5f4SPaul Zimmerman  *                       15 to 511
292197ba5f4SPaul Zimmerman  *                      Actual maximum value is autodetected and also
293197ba5f4SPaul Zimmerman  *                      the default.
294197ba5f4SPaul Zimmerman  * @host_channels:      The number of host channel registers to use
295197ba5f4SPaul Zimmerman  *                       1 to 16
296197ba5f4SPaul Zimmerman  *                      Actual maximum value is autodetected and also
297197ba5f4SPaul Zimmerman  *                      the default.
298197ba5f4SPaul Zimmerman  * @phy_type:           Specifies the type of PHY interface to use. By default,
299197ba5f4SPaul Zimmerman  *                      the driver will automatically detect the phy_type.
300197ba5f4SPaul Zimmerman  *                       0 - Full Speed Phy
301197ba5f4SPaul Zimmerman  *                       1 - UTMI+ Phy
302197ba5f4SPaul Zimmerman  *                       2 - ULPI Phy
303197ba5f4SPaul Zimmerman  *                      Defaults to best available option (2, 1, then 0)
304197ba5f4SPaul Zimmerman  * @phy_utmi_width:     Specifies the UTMI+ Data Width (in bits). This parameter
305197ba5f4SPaul Zimmerman  *                      is applicable for a phy_type of UTMI+ or ULPI. (For a
306197ba5f4SPaul Zimmerman  *                      ULPI phy_type, this parameter indicates the data width
307197ba5f4SPaul Zimmerman  *                      between the MAC and the ULPI Wrapper.) Also, this
308197ba5f4SPaul Zimmerman  *                      parameter is applicable only if the OTG_HSPHY_WIDTH cC
309197ba5f4SPaul Zimmerman  *                      parameter was set to "8 and 16 bits", meaning that the
310197ba5f4SPaul Zimmerman  *                      core has been configured to work at either data path
311197ba5f4SPaul Zimmerman  *                      width.
312197ba5f4SPaul Zimmerman  *                       8 or 16 (default 16 if available)
313197ba5f4SPaul Zimmerman  * @phy_ulpi_ddr:       Specifies whether the ULPI operates at double or single
314197ba5f4SPaul Zimmerman  *                      data rate. This parameter is only applicable if phy_type
315197ba5f4SPaul Zimmerman  *                      is ULPI.
316197ba5f4SPaul Zimmerman  *                       0 - single data rate ULPI interface with 8 bit wide
317197ba5f4SPaul Zimmerman  *                           data bus (default)
318197ba5f4SPaul Zimmerman  *                       1 - double data rate ULPI interface with 4 bit wide
319197ba5f4SPaul Zimmerman  *                           data bus
320197ba5f4SPaul Zimmerman  * @phy_ulpi_ext_vbus:  For a ULPI phy, specifies whether to use the internal or
321197ba5f4SPaul Zimmerman  *                      external supply to drive the VBus
322197ba5f4SPaul Zimmerman  *                       0 - Internal supply (default)
323197ba5f4SPaul Zimmerman  *                       1 - External supply
324197ba5f4SPaul Zimmerman  * @i2c_enable:         Specifies whether to use the I2Cinterface for a full
325197ba5f4SPaul Zimmerman  *                      speed PHY. This parameter is only applicable if phy_type
326197ba5f4SPaul Zimmerman  *                      is FS.
327197ba5f4SPaul Zimmerman  *                       0 - No (default)
328197ba5f4SPaul Zimmerman  *                       1 - Yes
3296fb914d7SGrigor Tovmasyan  * @ipg_isoc_en:        Indicates the IPG supports is enabled or disabled.
330b43ebc96SGrigor Tovmasyan  *                       0 - Disable (default)
331b43ebc96SGrigor Tovmasyan  *                       1 - Enable
3326fb914d7SGrigor Tovmasyan  * @acg_enable:		For enabling Active Clock Gating in the controller
3336fb914d7SGrigor Tovmasyan  *                       0 - No
3346fb914d7SGrigor Tovmasyan  *                       1 - Yes
335197ba5f4SPaul Zimmerman  * @ulpi_fs_ls:         Make ULPI phy operate in FS/LS mode only
336197ba5f4SPaul Zimmerman  *                       0 - No (default)
337197ba5f4SPaul Zimmerman  *                       1 - Yes
338197ba5f4SPaul Zimmerman  * @host_support_fs_ls_low_power: Specifies whether low power mode is supported
339197ba5f4SPaul Zimmerman  *                      when attached to a Full Speed or Low Speed device in
340197ba5f4SPaul Zimmerman  *                      host mode.
341197ba5f4SPaul Zimmerman  *                       0 - Don't support low power mode (default)
342197ba5f4SPaul Zimmerman  *                       1 - Support low power mode
343197ba5f4SPaul Zimmerman  * @host_ls_low_power_phy_clk: Specifies the PHY clock rate in low power mode
344197ba5f4SPaul Zimmerman  *                      when connected to a Low Speed device in host
345197ba5f4SPaul Zimmerman  *                      mode. This parameter is applicable only if
346197ba5f4SPaul Zimmerman  *                      host_support_fs_ls_low_power is enabled.
347197ba5f4SPaul Zimmerman  *                       0 - 48 MHz
348197ba5f4SPaul Zimmerman  *                           (default when phy_type is UTMI+ or ULPI)
349197ba5f4SPaul Zimmerman  *                       1 - 6 MHz
350197ba5f4SPaul Zimmerman  *                           (default when phy_type is Full Speed)
351b11633c4SDinh Nguyen  * @oc_disable:		Flag to disable overcurrent condition.
352b11633c4SDinh Nguyen  *			0 - Allow overcurrent condition to get detected
353b11633c4SDinh Nguyen  *			1 - Disable overcurrent condtion to get detected
354197ba5f4SPaul Zimmerman  * @ts_dline:           Enable Term Select Dline pulsing
355197ba5f4SPaul Zimmerman  *                       0 - No (default)
356197ba5f4SPaul Zimmerman  *                       1 - Yes
357197ba5f4SPaul Zimmerman  * @reload_ctl:         Allow dynamic reloading of HFIR register during runtime
358197ba5f4SPaul Zimmerman  *                       0 - No (default for core < 2.92a)
359197ba5f4SPaul Zimmerman  *                       1 - Yes (default for core >= 2.92a)
360197ba5f4SPaul Zimmerman  * @ahbcfg:             This field allows the default value of the GAHBCFG
361197ba5f4SPaul Zimmerman  *                      register to be overridden
362197ba5f4SPaul Zimmerman  *                       -1         - GAHBCFG value will be set to 0x06
3631b52d2faSRazmik Karapetyan  *                                    (INCR, default)
364197ba5f4SPaul Zimmerman  *                       all others - GAHBCFG value will be overridden with
365197ba5f4SPaul Zimmerman  *                                    this value
366197ba5f4SPaul Zimmerman  *                      Not all bits can be controlled like this, the
367197ba5f4SPaul Zimmerman  *                      bits defined by GAHBCFG_CTRL_MASK are controlled
368197ba5f4SPaul Zimmerman  *                      by the driver and are ignored in this
369197ba5f4SPaul Zimmerman  *                      configuration value.
370197ba5f4SPaul Zimmerman  * @uframe_sched:       True to enable the microframe scheduler
371a6d249d8SGregory Herrero  * @external_id_pin_ctl: Specifies whether ID pin is handled externally.
372a6d249d8SGregory Herrero  *                      Disable CONIDSTSCHNG controller interrupt in such
373a6d249d8SGregory Herrero  *                      case.
374a6d249d8SGregory Herrero  *                      0 - No (default)
375a6d249d8SGregory Herrero  *                      1 - Yes
37641ba9b9bSVardan Mikayelyan  * @power_down:         Specifies whether the controller support power_down.
37741ba9b9bSVardan Mikayelyan  *			If power_down is enabled, the controller will enter
37841ba9b9bSVardan Mikayelyan  *			power_down in both peripheral and host mode when
379285046aaSGregory Herrero  *			needed.
380285046aaSGregory Herrero  *			0 - No (default)
381631a2310SVardan Mikayelyan  *			1 - Partial power down
382631a2310SVardan Mikayelyan  *			2 - Hibernation
3836f80b6deSSevak Arakelyan  * @lpm:		Enable LPM support.
3846f80b6deSSevak Arakelyan  *			0 - No
3856f80b6deSSevak Arakelyan  *			1 - Yes
3866f80b6deSSevak Arakelyan  * @lpm_clock_gating:		Enable core PHY clock gating.
3876f80b6deSSevak Arakelyan  *			0 - No
3886f80b6deSSevak Arakelyan  *			1 - Yes
3896f80b6deSSevak Arakelyan  * @besl:		Enable LPM Errata support.
3906f80b6deSSevak Arakelyan  *			0 - No
3916f80b6deSSevak Arakelyan  *			1 - Yes
3926f80b6deSSevak Arakelyan  * @hird_threshold_en:	HIRD or HIRD Threshold enable.
3936f80b6deSSevak Arakelyan  *			0 - No
3946f80b6deSSevak Arakelyan  *			1 - Yes
3956f80b6deSSevak Arakelyan  * @hird_threshold:	Value of BESL or HIRD Threshold.
396f3a61e4eSGrigor Tovmasyan  * @ref_clk_per:        Indicates in terms of pico seconds the period
397f3a61e4eSGrigor Tovmasyan  *                      of ref_clk.
398f3a61e4eSGrigor Tovmasyan  *			62500 - 16MHz
399f3a61e4eSGrigor Tovmasyan  *                      58823 - 17MHz
400f3a61e4eSGrigor Tovmasyan  *                      52083 - 19.2MHz
401f3a61e4eSGrigor Tovmasyan  *			50000 - 20MHz
402f3a61e4eSGrigor Tovmasyan  *			41666 - 24MHz
403f3a61e4eSGrigor Tovmasyan  *			33333 - 30MHz (default)
404f3a61e4eSGrigor Tovmasyan  *			25000 - 40MHz
405f3a61e4eSGrigor Tovmasyan  * @sof_cnt_wkup_alert: Indicates in term of number of SOF's after which
406f3a61e4eSGrigor Tovmasyan  *                      the controller should generate an interrupt if the
407f3a61e4eSGrigor Tovmasyan  *                      device had been in L1 state until that period.
408f3a61e4eSGrigor Tovmasyan  *                      This is used by SW to initiate Remote WakeUp in the
409f3a61e4eSGrigor Tovmasyan  *                      controller so as to sync to the uF number from the host.
410e35b1350SBruno Herrera  * @activate_stm_fs_transceiver: Activate internal transceiver using GGPIO
411e35b1350SBruno Herrera  *			register.
412e35b1350SBruno Herrera  *			0 - Deactivate the transceiver (default)
413e35b1350SBruno Herrera  *			1 - Activate the transceiver
4149962b62fSJohn Youn  * @g_dma:              Enables gadget dma usage (default: autodetect).
415dec4b556SVahram Aharonyan  * @g_dma_desc:         Enables gadget descriptor DMA (default: autodetect).
41605ee799fSJohn Youn  * @g_rx_fifo_size:	The periodic rx fifo size for the device, in
41705ee799fSJohn Youn  *			DWORDS from 16-32768 (default: 2048 if
41805ee799fSJohn Youn  *			possible, otherwise autodetect).
41905ee799fSJohn Youn  * @g_np_tx_fifo_size:	The non-periodic tx fifo size for the device in
42005ee799fSJohn Youn  *			DWORDS from 16-32768 (default: 1024 if
42105ee799fSJohn Youn  *			possible, otherwise autodetect).
42205ee799fSJohn Youn  * @g_tx_fifo_size:	An array of TX fifo sizes in dedicated fifo
42305ee799fSJohn Youn  *			mode. Each value corresponds to one EP
42405ee799fSJohn Youn  *			starting from EP1 (max 15 values). Sizes are
42505ee799fSJohn Youn  *			in DWORDS with possible values from from
42605ee799fSJohn Youn  *			16-32768 (default: 256, 256, 256, 256, 768,
42705ee799fSJohn Youn  *			768, 768, 768, 0, 0, 0, 0, 0, 0, 0).
428ca8b0332SChen Yu  * @change_speed_quirk: Change speed configuration to DWC2_SPEED_PARAM_FULL
429ca8b0332SChen Yu  *                      while full&low speed device connect. And change speed
430ca8b0332SChen Yu  *                      back to DWC2_SPEED_PARAM_HIGH while device is gone.
431ca8b0332SChen Yu  *			0 - No (default)
432ca8b0332SChen Yu  *			1 - Yes
433ca531bc2SGrigor Tovmasyan  * @service_interval:   Enable service interval based scheduling.
434ca531bc2SGrigor Tovmasyan  *                      0 - No
435ca531bc2SGrigor Tovmasyan  *                      1 - Yes
436197ba5f4SPaul Zimmerman  *
437197ba5f4SPaul Zimmerman  * The following parameters may be specified when starting the module. These
438197ba5f4SPaul Zimmerman  * parameters define how the DWC_otg controller should be configured. A
439197ba5f4SPaul Zimmerman  * value of -1 (or any other out of range value) for any parameter means
440197ba5f4SPaul Zimmerman  * to read the value from hardware (if possible) or use the builtin
441197ba5f4SPaul Zimmerman  * default described above.
442197ba5f4SPaul Zimmerman  */
443197ba5f4SPaul Zimmerman struct dwc2_core_params {
444d21bcc3fSJohn Youn 	u8 otg_cap;
445c1d286cfSJohn Youn #define DWC2_CAP_PARAM_HNP_SRP_CAPABLE		0
446c1d286cfSJohn Youn #define DWC2_CAP_PARAM_SRP_ONLY_CAPABLE		1
447c1d286cfSJohn Youn #define DWC2_CAP_PARAM_NO_HNP_SRP_CAPABLE	2
448c1d286cfSJohn Youn 
449d21bcc3fSJohn Youn 	u8 phy_type;
450c1d286cfSJohn Youn #define DWC2_PHY_TYPE_PARAM_FS		0
451c1d286cfSJohn Youn #define DWC2_PHY_TYPE_PARAM_UTMI	1
452c1d286cfSJohn Youn #define DWC2_PHY_TYPE_PARAM_ULPI	2
453c1d286cfSJohn Youn 
45457b8e235SJohn Youn 	u8 speed;
45557b8e235SJohn Youn #define DWC2_SPEED_PARAM_HIGH	0
45657b8e235SJohn Youn #define DWC2_SPEED_PARAM_FULL	1
45757b8e235SJohn Youn #define DWC2_SPEED_PARAM_LOW	2
45857b8e235SJohn Youn 
459d21bcc3fSJohn Youn 	u8 phy_utmi_width;
460d21bcc3fSJohn Youn 	bool phy_ulpi_ddr;
461d21bcc3fSJohn Youn 	bool phy_ulpi_ext_vbus;
46257b8e235SJohn Youn 	bool enable_dynamic_fifo;
46357b8e235SJohn Youn 	bool en_multiple_tx_fifo;
464d21bcc3fSJohn Youn 	bool i2c_enable;
46566e77a24SRazmik Karapetyan 	bool acg_enable;
466d21bcc3fSJohn Youn 	bool ulpi_fs_ls;
46757b8e235SJohn Youn 	bool ts_dline;
46857b8e235SJohn Youn 	bool reload_ctl;
46957b8e235SJohn Youn 	bool uframe_sched;
47057b8e235SJohn Youn 	bool external_id_pin_ctl;
471631a2310SVardan Mikayelyan 
472631a2310SVardan Mikayelyan 	int power_down;
473631a2310SVardan Mikayelyan #define DWC2_POWER_DOWN_PARAM_NONE		0
474631a2310SVardan Mikayelyan #define DWC2_POWER_DOWN_PARAM_PARTIAL		1
475631a2310SVardan Mikayelyan #define DWC2_POWER_DOWN_PARAM_HIBERNATION	2
476631a2310SVardan Mikayelyan 
4776f80b6deSSevak Arakelyan 	bool lpm;
4786f80b6deSSevak Arakelyan 	bool lpm_clock_gating;
4796f80b6deSSevak Arakelyan 	bool besl;
4806f80b6deSSevak Arakelyan 	bool hird_threshold_en;
481ca531bc2SGrigor Tovmasyan 	bool service_interval;
4826f80b6deSSevak Arakelyan 	u8 hird_threshold;
483e35b1350SBruno Herrera 	bool activate_stm_fs_transceiver;
484b43ebc96SGrigor Tovmasyan 	bool ipg_isoc_en;
48557b8e235SJohn Youn 	u16 max_packet_count;
48657b8e235SJohn Youn 	u32 max_transfer_size;
48757b8e235SJohn Youn 	u32 ahbcfg;
48857b8e235SJohn Youn 
489f3a61e4eSGrigor Tovmasyan 	/* GREFCLK parameters */
490f3a61e4eSGrigor Tovmasyan 	u32 ref_clk_per;
491f3a61e4eSGrigor Tovmasyan 	u16 sof_cnt_wkup_alert;
492f3a61e4eSGrigor Tovmasyan 
49357b8e235SJohn Youn 	/* Host parameters */
49457b8e235SJohn Youn 	bool host_dma;
49557b8e235SJohn Youn 	bool dma_desc_enable;
49657b8e235SJohn Youn 	bool dma_desc_fs_enable;
497d21bcc3fSJohn Youn 	bool host_support_fs_ls_low_power;
498d21bcc3fSJohn Youn 	bool host_ls_low_power_phy_clk;
499b11633c4SDinh Nguyen 	bool oc_disable;
500c1d286cfSJohn Youn 
50157b8e235SJohn Youn 	u8 host_channels;
50257b8e235SJohn Youn 	u16 host_rx_fifo_size;
50357b8e235SJohn Youn 	u16 host_nperio_tx_fifo_size;
50457b8e235SJohn Youn 	u16 host_perio_tx_fifo_size;
5056b66ce51SJohn Youn 
5066b66ce51SJohn Youn 	/* Gadget parameters */
50705ee799fSJohn Youn 	bool g_dma;
508dec4b556SVahram Aharonyan 	bool g_dma_desc;
50900c704ccSLeo Yan 	u32 g_rx_fifo_size;
51000c704ccSLeo Yan 	u32 g_np_tx_fifo_size;
51105ee799fSJohn Youn 	u32 g_tx_fifo_size[MAX_EPS_CHANNELS];
512ca8b0332SChen Yu 
513ca8b0332SChen Yu 	bool change_speed_quirk;
514197ba5f4SPaul Zimmerman };
515197ba5f4SPaul Zimmerman 
516197ba5f4SPaul Zimmerman /**
517197ba5f4SPaul Zimmerman  * struct dwc2_hw_params - Autodetected parameters.
518197ba5f4SPaul Zimmerman  *
519197ba5f4SPaul Zimmerman  * These parameters are the various parameters read from hardware
520197ba5f4SPaul Zimmerman  * registers during initialization. They typically contain the best
521197ba5f4SPaul Zimmerman  * supported or maximum value that can be configured in the
522197ba5f4SPaul Zimmerman  * corresponding dwc2_core_params value.
523197ba5f4SPaul Zimmerman  *
524197ba5f4SPaul Zimmerman  * The values that are not in dwc2_core_params are documented below.
525197ba5f4SPaul Zimmerman  *
5266fb914d7SGrigor Tovmasyan  * @op_mode:             Mode of Operation
527197ba5f4SPaul Zimmerman  *                       0 - HNP- and SRP-Capable OTG (Host & Device)
528197ba5f4SPaul Zimmerman  *                       1 - SRP-Capable OTG (Host & Device)
529197ba5f4SPaul Zimmerman  *                       2 - Non-HNP and Non-SRP Capable OTG (Host & Device)
530197ba5f4SPaul Zimmerman  *                       3 - SRP-Capable Device
531197ba5f4SPaul Zimmerman  *                       4 - Non-OTG Device
532197ba5f4SPaul Zimmerman  *                       5 - SRP-Capable Host
533197ba5f4SPaul Zimmerman  *                       6 - Non-OTG Host
5346fb914d7SGrigor Tovmasyan  * @arch:                Architecture
535197ba5f4SPaul Zimmerman  *                       0 - Slave only
536197ba5f4SPaul Zimmerman  *                       1 - External DMA
537197ba5f4SPaul Zimmerman  *                       2 - Internal DMA
5386fb914d7SGrigor Tovmasyan  * @ipg_isoc_en:        This feature indicates that the controller supports
539b43ebc96SGrigor Tovmasyan  *                      the worst-case scenario of Rx followed by Rx
540b43ebc96SGrigor Tovmasyan  *                      Interpacket Gap (IPG) (32 bitTimes) as per the utmi
541b43ebc96SGrigor Tovmasyan  *                      specification for any token following ISOC OUT token.
542b43ebc96SGrigor Tovmasyan  *                       0 - Don't support
543b43ebc96SGrigor Tovmasyan  *                       1 - Support
5446fb914d7SGrigor Tovmasyan  * @power_optimized:    Are power optimizations enabled?
5456fb914d7SGrigor Tovmasyan  * @num_dev_ep:         Number of device endpoints available
5466fb914d7SGrigor Tovmasyan  * @num_dev_in_eps:     Number of device IN endpoints available
5476fb914d7SGrigor Tovmasyan  * @num_dev_perio_in_ep: Number of device periodic IN endpoints
548997f4f81SMickael Maison  *                       available
5496fb914d7SGrigor Tovmasyan  * @dev_token_q_depth:  Device Mode IN Token Sequence Learning Queue
550197ba5f4SPaul Zimmerman  *                      Depth
551197ba5f4SPaul Zimmerman  *                       0 to 30
5526fb914d7SGrigor Tovmasyan  * @host_perio_tx_q_depth:
553197ba5f4SPaul Zimmerman  *                      Host Mode Periodic Request Queue Depth
554197ba5f4SPaul Zimmerman  *                       2, 4 or 8
5556fb914d7SGrigor Tovmasyan  * @nperio_tx_q_depth:
556197ba5f4SPaul Zimmerman  *                      Non-Periodic Request Queue Depth
557197ba5f4SPaul Zimmerman  *                       2, 4 or 8
5586fb914d7SGrigor Tovmasyan  * @hs_phy_type:         High-speed PHY interface type
559197ba5f4SPaul Zimmerman  *                       0 - High-speed interface not supported
560197ba5f4SPaul Zimmerman  *                       1 - UTMI+
561197ba5f4SPaul Zimmerman  *                       2 - ULPI
562197ba5f4SPaul Zimmerman  *                       3 - UTMI+ and ULPI
5636fb914d7SGrigor Tovmasyan  * @fs_phy_type:         Full-speed PHY interface type
564197ba5f4SPaul Zimmerman  *                       0 - Full speed interface not supported
565197ba5f4SPaul Zimmerman  *                       1 - Dedicated full speed interface
566197ba5f4SPaul Zimmerman  *                       2 - FS pins shared with UTMI+ pins
567197ba5f4SPaul Zimmerman  *                       3 - FS pins shared with ULPI pins
568197ba5f4SPaul Zimmerman  * @total_fifo_size:    Total internal RAM for FIFOs (bytes)
5696fb914d7SGrigor Tovmasyan  * @hibernation:	Is hibernation enabled?
5706fb914d7SGrigor Tovmasyan  * @utmi_phy_data_width: UTMI+ PHY data width
571197ba5f4SPaul Zimmerman  *                       0 - 8 bits
572197ba5f4SPaul Zimmerman  *                       1 - 16 bits
573197ba5f4SPaul Zimmerman  *                       2 - 8 or 16 bits
574197ba5f4SPaul Zimmerman  * @snpsid:             Value from SNPSID register
57555e1040eSJohn Youn  * @dev_ep_dirs:        Direction of device endpoints (GHWCFG1)
5766fb914d7SGrigor Tovmasyan  * @g_tx_fifo_size:	Power-on values of TxFIFO sizes
5776fb914d7SGrigor Tovmasyan  * @dma_desc_enable:    When DMA mode is enabled, specifies whether to use
5786fb914d7SGrigor Tovmasyan  *                      address DMA mode or descriptor DMA mode for accessing
5796fb914d7SGrigor Tovmasyan  *                      the data FIFOs. The driver will automatically detect the
5806fb914d7SGrigor Tovmasyan  *                      value for this if none is specified.
5816fb914d7SGrigor Tovmasyan  *                       0 - Address DMA
5826fb914d7SGrigor Tovmasyan  *                       1 - Descriptor DMA (default, if available)
5836fb914d7SGrigor Tovmasyan  * @enable_dynamic_fifo: 0 - Use coreConsultant-specified FIFO size parameters
5846fb914d7SGrigor Tovmasyan  *                       1 - Allow dynamic FIFO sizing (default, if available)
5856fb914d7SGrigor Tovmasyan  * @en_multiple_tx_fifo: Specifies whether dedicated per-endpoint transmit FIFOs
5866fb914d7SGrigor Tovmasyan  *                      are enabled for non-periodic IN endpoints in device
5876fb914d7SGrigor Tovmasyan  *                      mode.
5886fb914d7SGrigor Tovmasyan  * @host_nperio_tx_fifo_size: Number of 4-byte words in the non-periodic Tx FIFO
5896fb914d7SGrigor Tovmasyan  *                      in host mode when dynamic FIFO sizing is enabled
5906fb914d7SGrigor Tovmasyan  *                       16 to 32768
5916fb914d7SGrigor Tovmasyan  *                      Actual maximum value is autodetected and also
5926fb914d7SGrigor Tovmasyan  *                      the default.
5936fb914d7SGrigor Tovmasyan  * @host_perio_tx_fifo_size: Number of 4-byte words in the periodic Tx FIFO in
5946fb914d7SGrigor Tovmasyan  *                      host mode when dynamic FIFO sizing is enabled
5956fb914d7SGrigor Tovmasyan  *                       16 to 32768
5966fb914d7SGrigor Tovmasyan  *                      Actual maximum value is autodetected and also
5976fb914d7SGrigor Tovmasyan  *                      the default.
5986fb914d7SGrigor Tovmasyan  * @max_transfer_size:  The maximum transfer size supported, in bytes
5996fb914d7SGrigor Tovmasyan  *                       2047 to 65,535
6006fb914d7SGrigor Tovmasyan  *                      Actual maximum value is autodetected and also
6016fb914d7SGrigor Tovmasyan  *                      the default.
6026fb914d7SGrigor Tovmasyan  * @max_packet_count:   The maximum number of packets in a transfer
6036fb914d7SGrigor Tovmasyan  *                       15 to 511
6046fb914d7SGrigor Tovmasyan  *                      Actual maximum value is autodetected and also
6056fb914d7SGrigor Tovmasyan  *                      the default.
6066fb914d7SGrigor Tovmasyan  * @host_channels:      The number of host channel registers to use
6076fb914d7SGrigor Tovmasyan  *                       1 to 16
6086fb914d7SGrigor Tovmasyan  *                      Actual maximum value is autodetected and also
6096fb914d7SGrigor Tovmasyan  *                      the default.
6106fb914d7SGrigor Tovmasyan  * @dev_nperio_tx_fifo_size: Number of 4-byte words in the non-periodic Tx FIFO
6116fb914d7SGrigor Tovmasyan  *			     in device mode when dynamic FIFO sizing is enabled
6126fb914d7SGrigor Tovmasyan  *			     16 to 32768
6136fb914d7SGrigor Tovmasyan  *			     Actual maximum value is autodetected and also
6146fb914d7SGrigor Tovmasyan  *			     the default.
6156fb914d7SGrigor Tovmasyan  * @i2c_enable:         Specifies whether to use the I2Cinterface for a full
6166fb914d7SGrigor Tovmasyan  *                      speed PHY. This parameter is only applicable if phy_type
6176fb914d7SGrigor Tovmasyan  *                      is FS.
6186fb914d7SGrigor Tovmasyan  *                       0 - No (default)
6196fb914d7SGrigor Tovmasyan  *                       1 - Yes
6206fb914d7SGrigor Tovmasyan  * @acg_enable:		For enabling Active Clock Gating in the controller
6216fb914d7SGrigor Tovmasyan  *                       0 - Disable
6226fb914d7SGrigor Tovmasyan  *                       1 - Enable
6236fb914d7SGrigor Tovmasyan  * @lpm_mode:		For enabling Link Power Management in the controller
6246fb914d7SGrigor Tovmasyan  *                       0 - Disable
6256fb914d7SGrigor Tovmasyan  *                       1 - Enable
6266fb914d7SGrigor Tovmasyan  * @rx_fifo_size:	Number of 4-byte words in the  Rx FIFO when dynamic
6276fb914d7SGrigor Tovmasyan  *			FIFO sizing is enabled 16 to 32768
6286fb914d7SGrigor Tovmasyan  *			Actual maximum value is autodetected and also
6296fb914d7SGrigor Tovmasyan  *			the default.
630ca531bc2SGrigor Tovmasyan  * @service_interval_mode: For enabling service interval based scheduling in the
631ca531bc2SGrigor Tovmasyan  *                         controller.
632ca531bc2SGrigor Tovmasyan  *                           0 - Disable
633ca531bc2SGrigor Tovmasyan  *                           1 - Enable
634197ba5f4SPaul Zimmerman  */
635197ba5f4SPaul Zimmerman struct dwc2_hw_params {
636197ba5f4SPaul Zimmerman 	unsigned op_mode:3;
637197ba5f4SPaul Zimmerman 	unsigned arch:2;
638197ba5f4SPaul Zimmerman 	unsigned dma_desc_enable:1;
639197ba5f4SPaul Zimmerman 	unsigned enable_dynamic_fifo:1;
640197ba5f4SPaul Zimmerman 	unsigned en_multiple_tx_fifo:1;
641d1531319SJohn Youn 	unsigned rx_fifo_size:16;
642197ba5f4SPaul Zimmerman 	unsigned host_nperio_tx_fifo_size:16;
64355e1040eSJohn Youn 	unsigned dev_nperio_tx_fifo_size:16;
644197ba5f4SPaul Zimmerman 	unsigned host_perio_tx_fifo_size:16;
645197ba5f4SPaul Zimmerman 	unsigned nperio_tx_q_depth:3;
646197ba5f4SPaul Zimmerman 	unsigned host_perio_tx_q_depth:3;
647197ba5f4SPaul Zimmerman 	unsigned dev_token_q_depth:5;
648197ba5f4SPaul Zimmerman 	unsigned max_transfer_size:26;
649197ba5f4SPaul Zimmerman 	unsigned max_packet_count:11;
650197ba5f4SPaul Zimmerman 	unsigned host_channels:5;
651197ba5f4SPaul Zimmerman 	unsigned hs_phy_type:2;
652197ba5f4SPaul Zimmerman 	unsigned fs_phy_type:2;
653197ba5f4SPaul Zimmerman 	unsigned i2c_enable:1;
65466e77a24SRazmik Karapetyan 	unsigned acg_enable:1;
655197ba5f4SPaul Zimmerman 	unsigned num_dev_ep:4;
6569273083aSMinas Harutyunyan 	unsigned num_dev_in_eps : 4;
657197ba5f4SPaul Zimmerman 	unsigned num_dev_perio_in_ep:4;
658197ba5f4SPaul Zimmerman 	unsigned total_fifo_size:16;
659197ba5f4SPaul Zimmerman 	unsigned power_optimized:1;
660631a2310SVardan Mikayelyan 	unsigned hibernation:1;
661197ba5f4SPaul Zimmerman 	unsigned utmi_phy_data_width:2;
6626f80b6deSSevak Arakelyan 	unsigned lpm_mode:1;
663b43ebc96SGrigor Tovmasyan 	unsigned ipg_isoc_en:1;
664ca531bc2SGrigor Tovmasyan 	unsigned service_interval_mode:1;
665197ba5f4SPaul Zimmerman 	u32 snpsid;
66655e1040eSJohn Youn 	u32 dev_ep_dirs;
6679273083aSMinas Harutyunyan 	u32 g_tx_fifo_size[MAX_EPS_CHANNELS];
668197ba5f4SPaul Zimmerman };
669197ba5f4SPaul Zimmerman 
6703f95001dSMian Yousaf Kaukab /* Size of control and EP0 buffers */
6713f95001dSMian Yousaf Kaukab #define DWC2_CTRL_BUFF_SIZE 8
6723f95001dSMian Yousaf Kaukab 
673197ba5f4SPaul Zimmerman /**
67438beaec6SJohn Youn  * struct dwc2_gregs_backup - Holds global registers state before
67538beaec6SJohn Youn  * entering partial power down
676d17ee77bSGregory Herrero  * @gotgctl:		Backup of GOTGCTL register
677d17ee77bSGregory Herrero  * @gintmsk:		Backup of GINTMSK register
678d17ee77bSGregory Herrero  * @gahbcfg:		Backup of GAHBCFG register
679d17ee77bSGregory Herrero  * @gusbcfg:		Backup of GUSBCFG register
680d17ee77bSGregory Herrero  * @grxfsiz:		Backup of GRXFSIZ register
681d17ee77bSGregory Herrero  * @gnptxfsiz:		Backup of GNPTXFSIZ register
682d17ee77bSGregory Herrero  * @gi2cctl:		Backup of GI2CCTL register
68366a36096SVardan Mikayelyan  * @glpmcfg:		Backup of GLPMCFG register
684d17ee77bSGregory Herrero  * @gdfifocfg:		Backup of GDFIFOCFG register
6856fb914d7SGrigor Tovmasyan  * @pcgcctl:		Backup of PCGCCTL register
6866fb914d7SGrigor Tovmasyan  * @pcgcctl1:		Backup of PCGCCTL1 register
6876fb914d7SGrigor Tovmasyan  * @dtxfsiz:		Backup of DTXFSIZ registers for each endpoint
688d17ee77bSGregory Herrero  * @gpwrdn:		Backup of GPWRDN register
6896fb914d7SGrigor Tovmasyan  * @valid:		True if registers values backuped.
690d17ee77bSGregory Herrero  */
691d17ee77bSGregory Herrero struct dwc2_gregs_backup {
692d17ee77bSGregory Herrero 	u32 gotgctl;
693d17ee77bSGregory Herrero 	u32 gintmsk;
694d17ee77bSGregory Herrero 	u32 gahbcfg;
695d17ee77bSGregory Herrero 	u32 gusbcfg;
696d17ee77bSGregory Herrero 	u32 grxfsiz;
697d17ee77bSGregory Herrero 	u32 gnptxfsiz;
698d17ee77bSGregory Herrero 	u32 gi2cctl;
69966a36096SVardan Mikayelyan 	u32 glpmcfg;
700d17ee77bSGregory Herrero 	u32 pcgcctl;
701600a490eSRazmik Karapetyan 	u32 pcgcctl1;
702d17ee77bSGregory Herrero 	u32 gdfifocfg;
703d17ee77bSGregory Herrero 	u32 gpwrdn;
704cc1e204cSMian Yousaf Kaukab 	bool valid;
705d17ee77bSGregory Herrero };
706d17ee77bSGregory Herrero 
707d17ee77bSGregory Herrero /**
70838beaec6SJohn Youn  * struct dwc2_dregs_backup - Holds device registers state before
70938beaec6SJohn Youn  * entering partial power down
710d17ee77bSGregory Herrero  * @dcfg:		Backup of DCFG register
711d17ee77bSGregory Herrero  * @dctl:		Backup of DCTL register
712d17ee77bSGregory Herrero  * @daintmsk:		Backup of DAINTMSK register
713d17ee77bSGregory Herrero  * @diepmsk:		Backup of DIEPMSK register
714d17ee77bSGregory Herrero  * @doepmsk:		Backup of DOEPMSK register
715d17ee77bSGregory Herrero  * @diepctl:		Backup of DIEPCTL register
716d17ee77bSGregory Herrero  * @dieptsiz:		Backup of DIEPTSIZ register
717d17ee77bSGregory Herrero  * @diepdma:		Backup of DIEPDMA register
718d17ee77bSGregory Herrero  * @doepctl:		Backup of DOEPCTL register
719d17ee77bSGregory Herrero  * @doeptsiz:		Backup of DOEPTSIZ register
720d17ee77bSGregory Herrero  * @doepdma:		Backup of DOEPDMA register
721af7c2bd3SVardan Mikayelyan  * @dtxfsiz:		Backup of DTXFSIZ registers for each endpoint
7226fb914d7SGrigor Tovmasyan  * @valid:      True if registers values backuped.
723d17ee77bSGregory Herrero  */
724d17ee77bSGregory Herrero struct dwc2_dregs_backup {
725d17ee77bSGregory Herrero 	u32 dcfg;
726d17ee77bSGregory Herrero 	u32 dctl;
727d17ee77bSGregory Herrero 	u32 daintmsk;
728d17ee77bSGregory Herrero 	u32 diepmsk;
729d17ee77bSGregory Herrero 	u32 doepmsk;
730d17ee77bSGregory Herrero 	u32 diepctl[MAX_EPS_CHANNELS];
731d17ee77bSGregory Herrero 	u32 dieptsiz[MAX_EPS_CHANNELS];
732d17ee77bSGregory Herrero 	u32 diepdma[MAX_EPS_CHANNELS];
733d17ee77bSGregory Herrero 	u32 doepctl[MAX_EPS_CHANNELS];
734d17ee77bSGregory Herrero 	u32 doeptsiz[MAX_EPS_CHANNELS];
735d17ee77bSGregory Herrero 	u32 doepdma[MAX_EPS_CHANNELS];
736af7c2bd3SVardan Mikayelyan 	u32 dtxfsiz[MAX_EPS_CHANNELS];
737cc1e204cSMian Yousaf Kaukab 	bool valid;
738d17ee77bSGregory Herrero };
739d17ee77bSGregory Herrero 
740d17ee77bSGregory Herrero /**
74138beaec6SJohn Youn  * struct dwc2_hregs_backup - Holds host registers state before
74238beaec6SJohn Youn  * entering partial power down
743d17ee77bSGregory Herrero  * @hcfg:		Backup of HCFG register
744d17ee77bSGregory Herrero  * @haintmsk:		Backup of HAINTMSK register
745d17ee77bSGregory Herrero  * @hcintmsk:		Backup of HCINTMSK register
7466fb914d7SGrigor Tovmasyan  * @hprt0:		Backup of HPTR0 register
747d17ee77bSGregory Herrero  * @hfir:		Backup of HFIR register
74866a36096SVardan Mikayelyan  * @hptxfsiz:		Backup of HPTXFSIZ register
7496fb914d7SGrigor Tovmasyan  * @valid:      True if registers values backuped.
750d17ee77bSGregory Herrero  */
751d17ee77bSGregory Herrero struct dwc2_hregs_backup {
752d17ee77bSGregory Herrero 	u32 hcfg;
753d17ee77bSGregory Herrero 	u32 haintmsk;
754d17ee77bSGregory Herrero 	u32 hcintmsk[MAX_EPS_CHANNELS];
755d17ee77bSGregory Herrero 	u32 hprt0;
756d17ee77bSGregory Herrero 	u32 hfir;
75766a36096SVardan Mikayelyan 	u32 hptxfsiz;
758cc1e204cSMian Yousaf Kaukab 	bool valid;
759d17ee77bSGregory Herrero };
760d17ee77bSGregory Herrero 
7619f9f09b0SDouglas Anderson /*
7629f9f09b0SDouglas Anderson  * Constants related to high speed periodic scheduling
7639f9f09b0SDouglas Anderson  *
7649f9f09b0SDouglas Anderson  * We have a periodic schedule that is DWC2_HS_SCHEDULE_UFRAMES long.  From a
7659f9f09b0SDouglas Anderson  * reservation point of view it's assumed that the schedule goes right back to
7669f9f09b0SDouglas Anderson  * the beginning after the end of the schedule.
7679f9f09b0SDouglas Anderson  *
7689f9f09b0SDouglas Anderson  * What does that mean for scheduling things with a long interval?  It means
7699f9f09b0SDouglas Anderson  * we'll reserve time for them in every possible microframe that they could
7709f9f09b0SDouglas Anderson  * ever be scheduled in.  ...but we'll still only actually schedule them as
7719f9f09b0SDouglas Anderson  * often as they were requested.
7729f9f09b0SDouglas Anderson  *
7739f9f09b0SDouglas Anderson  * We keep our schedule in a "bitmap" structure.  This simplifies having
7749f9f09b0SDouglas Anderson  * to keep track of and merge intervals: we just let the bitmap code do most
7759f9f09b0SDouglas Anderson  * of the heavy lifting.  In a way scheduling is much like memory allocation.
7769f9f09b0SDouglas Anderson  *
7779f9f09b0SDouglas Anderson  * We schedule 100us per uframe or 80% of 125us (the maximum amount you're
7789f9f09b0SDouglas Anderson  * supposed to schedule for periodic transfers).  That's according to spec.
7799f9f09b0SDouglas Anderson  *
7809f9f09b0SDouglas Anderson  * Note that though we only schedule 80% of each microframe, the bitmap that we
7819f9f09b0SDouglas Anderson  * keep the schedule in is tightly packed (AKA it doesn't have 100us worth of
7829f9f09b0SDouglas Anderson  * space for each uFrame).
7839f9f09b0SDouglas Anderson  *
7849f9f09b0SDouglas Anderson  * Requirements:
7859f9f09b0SDouglas Anderson  * - DWC2_HS_SCHEDULE_UFRAMES must even divide 0x4000 (HFNUM_MAX_FRNUM + 1)
7869f9f09b0SDouglas Anderson  * - DWC2_HS_SCHEDULE_UFRAMES must be 8 times DWC2_LS_SCHEDULE_FRAMES (probably
7879f9f09b0SDouglas Anderson  *   could be any multiple of 8 times DWC2_LS_SCHEDULE_FRAMES, but there might
7889f9f09b0SDouglas Anderson  *   be bugs).  The 8 comes from the USB spec: number of microframes per frame.
7899f9f09b0SDouglas Anderson  */
7909f9f09b0SDouglas Anderson #define DWC2_US_PER_UFRAME		125
7919f9f09b0SDouglas Anderson #define DWC2_HS_PERIODIC_US_PER_UFRAME	100
7929f9f09b0SDouglas Anderson 
7939f9f09b0SDouglas Anderson #define DWC2_HS_SCHEDULE_UFRAMES	8
7949f9f09b0SDouglas Anderson #define DWC2_HS_SCHEDULE_US		(DWC2_HS_SCHEDULE_UFRAMES * \
7959f9f09b0SDouglas Anderson 					 DWC2_HS_PERIODIC_US_PER_UFRAME)
7969f9f09b0SDouglas Anderson 
7979f9f09b0SDouglas Anderson /*
7989f9f09b0SDouglas Anderson  * Constants related to low speed scheduling
7999f9f09b0SDouglas Anderson  *
8009f9f09b0SDouglas Anderson  * For high speed we schedule every 1us.  For low speed that's a bit overkill,
8019f9f09b0SDouglas Anderson  * so we make up a unit called a "slice" that's worth 25us.  There are 40
8029f9f09b0SDouglas Anderson  * slices in a full frame and we can schedule 36 of those (90%) for periodic
8039f9f09b0SDouglas Anderson  * transfers.
8049f9f09b0SDouglas Anderson  *
8059f9f09b0SDouglas Anderson  * Our low speed schedule can be as short as 1 frame or could be longer.  When
8069f9f09b0SDouglas Anderson  * we only schedule 1 frame it means that we'll need to reserve a time every
8079f9f09b0SDouglas Anderson  * frame even for things that only transfer very rarely, so something that runs
8089f9f09b0SDouglas Anderson  * every 2048 frames will get time reserved in every frame.  Our low speed
8099f9f09b0SDouglas Anderson  * schedule can be longer and we'll be able to handle more overlap, but that
8109f9f09b0SDouglas Anderson  * will come at increased memory cost and increased time to schedule.
8119f9f09b0SDouglas Anderson  *
8129f9f09b0SDouglas Anderson  * Note: one other advantage of a short low speed schedule is that if we mess
8139f9f09b0SDouglas Anderson  * up and miss scheduling we can jump in and use any of the slots that we
8149f9f09b0SDouglas Anderson  * happened to reserve.
8159f9f09b0SDouglas Anderson  *
8169f9f09b0SDouglas Anderson  * With 25 us per slice and 1 frame in the schedule, we only need 4 bytes for
8179f9f09b0SDouglas Anderson  * the schedule.  There will be one schedule per TT.
8189f9f09b0SDouglas Anderson  *
8199f9f09b0SDouglas Anderson  * Requirements:
8209f9f09b0SDouglas Anderson  * - DWC2_US_PER_SLICE must evenly divide DWC2_LS_PERIODIC_US_PER_FRAME.
8219f9f09b0SDouglas Anderson  */
8229f9f09b0SDouglas Anderson #define DWC2_US_PER_SLICE	25
8239f9f09b0SDouglas Anderson #define DWC2_SLICES_PER_UFRAME	(DWC2_US_PER_UFRAME / DWC2_US_PER_SLICE)
8249f9f09b0SDouglas Anderson 
8259f9f09b0SDouglas Anderson #define DWC2_ROUND_US_TO_SLICE(us) \
8269f9f09b0SDouglas Anderson 				(DIV_ROUND_UP((us), DWC2_US_PER_SLICE) * \
8279f9f09b0SDouglas Anderson 				 DWC2_US_PER_SLICE)
8289f9f09b0SDouglas Anderson 
8299f9f09b0SDouglas Anderson #define DWC2_LS_PERIODIC_US_PER_FRAME \
8309f9f09b0SDouglas Anderson 				900
8319f9f09b0SDouglas Anderson #define DWC2_LS_PERIODIC_SLICES_PER_FRAME \
8329f9f09b0SDouglas Anderson 				(DWC2_LS_PERIODIC_US_PER_FRAME / \
8339f9f09b0SDouglas Anderson 				 DWC2_US_PER_SLICE)
8349f9f09b0SDouglas Anderson 
8359f9f09b0SDouglas Anderson #define DWC2_LS_SCHEDULE_FRAMES	1
8369f9f09b0SDouglas Anderson #define DWC2_LS_SCHEDULE_SLICES	(DWC2_LS_SCHEDULE_FRAMES * \
8379f9f09b0SDouglas Anderson 				 DWC2_LS_PERIODIC_SLICES_PER_FRAME)
8389f9f09b0SDouglas Anderson 
839d17ee77bSGregory Herrero /**
840197ba5f4SPaul Zimmerman  * struct dwc2_hsotg - Holds the state of the driver, including the non-periodic
841197ba5f4SPaul Zimmerman  * and periodic schedules
842197ba5f4SPaul Zimmerman  *
843941fcce4SDinh Nguyen  * These are common for both host and peripheral modes:
844941fcce4SDinh Nguyen  *
845197ba5f4SPaul Zimmerman  * @dev:                The struct device pointer
846197ba5f4SPaul Zimmerman  * @regs:		Pointer to controller regs
847197ba5f4SPaul Zimmerman  * @hw_params:          Parameters that were autodetected from the
848197ba5f4SPaul Zimmerman  *                      hardware registers
8496fb914d7SGrigor Tovmasyan  * @params:	Parameters that define how the core should be configured
850197ba5f4SPaul Zimmerman  * @op_state:           The operational State, during transitions (a_host=>
851197ba5f4SPaul Zimmerman  *                      a_peripheral and b_device=>b_host) this may not match
852197ba5f4SPaul Zimmerman  *                      the core, but allows the software to determine
853197ba5f4SPaul Zimmerman  *                      transitions
854c0155b9dSKever Yang  * @dr_mode:            Requested mode of operation, one of following:
855c0155b9dSKever Yang  *                      - USB_DR_MODE_PERIPHERAL
856c0155b9dSKever Yang  *                      - USB_DR_MODE_HOST
857c0155b9dSKever Yang  *                      - USB_DR_MODE_OTG
8586fb914d7SGrigor Tovmasyan  * @hcd_enabled:	Host mode sub-driver initialization indicator.
8596fb914d7SGrigor Tovmasyan  * @gadget_enabled:	Peripheral mode sub-driver initialization indicator.
8606fb914d7SGrigor Tovmasyan  * @ll_hw_enabled:	Status of low-level hardware resources.
86120fe4409SVardan Mikayelyan  * @hibernated:		True if core is hibernated
862c40cf770SDouglas Anderson  * @reset_phy_on_wake:	Quirk saying that we should assert PHY reset on a
863c40cf770SDouglas Anderson  *			remote wakeup.
864c7c24e7aSArtur Petrosyan  * @frame_number:       Frame number read from the core. For both device
865c7c24e7aSArtur Petrosyan  *			and host modes. The value ranges are from 0
866c7c24e7aSArtur Petrosyan  *			to HFNUM_MAX_FRNUM.
86709a75e85SMarek Szyprowski  * @phy:                The otg phy transceiver structure for phy control.
86838beaec6SJohn Youn  * @uphy:               The otg phy transceiver structure for old USB phy
86938beaec6SJohn Youn  *                      control.
87038beaec6SJohn Youn  * @plat:               The platform specific configuration data. This can be
87138beaec6SJohn Youn  *                      removed once all SoCs support usb transceiver.
87209a75e85SMarek Szyprowski  * @supplies:           Definition of USB power supplies
873531ef5ebSAmelie Delaunay  * @vbus_supply:        Regulator supplying vbus.
87409a75e85SMarek Szyprowski  * @phyif:              PHY interface width
875941fcce4SDinh Nguyen  * @lock:		Spinlock that protects all the driver data structures
876941fcce4SDinh Nguyen  * @priv:		Stores a pointer to the struct usb_hcd
877197ba5f4SPaul Zimmerman  * @queuing_high_bandwidth: True if multiple packets of a high-bandwidth
878197ba5f4SPaul Zimmerman  *                      transfer are in process of being queued
879197ba5f4SPaul Zimmerman  * @srp_success:        Stores status of SRP request in the case of a FS PHY
880197ba5f4SPaul Zimmerman  *                      with an I2C interface
881197ba5f4SPaul Zimmerman  * @wq_otg:             Workqueue object used for handling of some interrupts
882197ba5f4SPaul Zimmerman  * @wf_otg:             Work object for handling Connector ID Status Change
883197ba5f4SPaul Zimmerman  *                      interrupt
884197ba5f4SPaul Zimmerman  * @wkp_timer:          Timer object for handling Wakeup Detected interrupt
885197ba5f4SPaul Zimmerman  * @lx_state:           Lx state of connected device
8866fb914d7SGrigor Tovmasyan  * @gr_backup: Backup of global registers during suspend
8876fb914d7SGrigor Tovmasyan  * @dr_backup: Backup of device registers during suspend
8886fb914d7SGrigor Tovmasyan  * @hr_backup: Backup of host registers during suspend
889fe369e18SGevorg Sahakyan  * @needs_byte_swap:		Specifies whether the opposite endianness.
890941fcce4SDinh Nguyen  *
891941fcce4SDinh Nguyen  * These are for host mode:
892941fcce4SDinh Nguyen  *
893197ba5f4SPaul Zimmerman  * @flags:              Flags for handling root port state changes
8946fb914d7SGrigor Tovmasyan  * @flags.d32:          Contain all root port flags
8956fb914d7SGrigor Tovmasyan  * @flags.b:            Separate root port flags from each other
8966fb914d7SGrigor Tovmasyan  * @flags.b.port_connect_status_change: True if root port connect status
8976fb914d7SGrigor Tovmasyan  *                      changed
8986fb914d7SGrigor Tovmasyan  * @flags.b.port_connect_status: True if device connected to root port
8996fb914d7SGrigor Tovmasyan  * @flags.b.port_reset_change: True if root port reset status changed
9006fb914d7SGrigor Tovmasyan  * @flags.b.port_enable_change: True if root port enable status changed
9016fb914d7SGrigor Tovmasyan  * @flags.b.port_suspend_change: True if root port suspend status changed
9026fb914d7SGrigor Tovmasyan  * @flags.b.port_over_current_change: True if root port over current state
9036fb914d7SGrigor Tovmasyan  *                       changed.
9046fb914d7SGrigor Tovmasyan  * @flags.b.port_l1_change: True if root port l1 status changed
9056fb914d7SGrigor Tovmasyan  * @flags.b.reserved:   Reserved bits of root port register
906197ba5f4SPaul Zimmerman  * @non_periodic_sched_inactive: Inactive QHs in the non-periodic schedule.
907197ba5f4SPaul Zimmerman  *                      Transfers associated with these QHs are not currently
908197ba5f4SPaul Zimmerman  *                      assigned to a host channel.
909197ba5f4SPaul Zimmerman  * @non_periodic_sched_active: Active QHs in the non-periodic schedule.
910197ba5f4SPaul Zimmerman  *                      Transfers associated with these QHs are currently
911197ba5f4SPaul Zimmerman  *                      assigned to a host channel.
912197ba5f4SPaul Zimmerman  * @non_periodic_qh_ptr: Pointer to next QH to process in the active
913197ba5f4SPaul Zimmerman  *                      non-periodic schedule
9146fb914d7SGrigor Tovmasyan  * @non_periodic_sched_waiting: Waiting QHs in the non-periodic schedule.
9156fb914d7SGrigor Tovmasyan  *                      Transfers associated with these QHs are not currently
9166fb914d7SGrigor Tovmasyan  *                      assigned to a host channel.
917197ba5f4SPaul Zimmerman  * @periodic_sched_inactive: Inactive QHs in the periodic schedule. This is a
918197ba5f4SPaul Zimmerman  *                      list of QHs for periodic transfers that are _not_
919197ba5f4SPaul Zimmerman  *                      scheduled for the next frame. Each QH in the list has an
920197ba5f4SPaul Zimmerman  *                      interval counter that determines when it needs to be
921197ba5f4SPaul Zimmerman  *                      scheduled for execution. This scheduling mechanism
922197ba5f4SPaul Zimmerman  *                      allows only a simple calculation for periodic bandwidth
923197ba5f4SPaul Zimmerman  *                      used (i.e. must assume that all periodic transfers may
924197ba5f4SPaul Zimmerman  *                      need to execute in the same frame). However, it greatly
925197ba5f4SPaul Zimmerman  *                      simplifies scheduling and should be sufficient for the
926197ba5f4SPaul Zimmerman  *                      vast majority of OTG hosts, which need to connect to a
927197ba5f4SPaul Zimmerman  *                      small number of peripherals at one time. Items move from
928197ba5f4SPaul Zimmerman  *                      this list to periodic_sched_ready when the QH interval
929197ba5f4SPaul Zimmerman  *                      counter is 0 at SOF.
930197ba5f4SPaul Zimmerman  * @periodic_sched_ready:  List of periodic QHs that are ready for execution in
931197ba5f4SPaul Zimmerman  *                      the next frame, but have not yet been assigned to host
932197ba5f4SPaul Zimmerman  *                      channels. Items move from this list to
933197ba5f4SPaul Zimmerman  *                      periodic_sched_assigned as host channels become
934197ba5f4SPaul Zimmerman  *                      available during the current frame.
935197ba5f4SPaul Zimmerman  * @periodic_sched_assigned: List of periodic QHs to be executed in the next
936197ba5f4SPaul Zimmerman  *                      frame that are assigned to host channels. Items move
937197ba5f4SPaul Zimmerman  *                      from this list to periodic_sched_queued as the
938197ba5f4SPaul Zimmerman  *                      transactions for the QH are queued to the DWC_otg
939197ba5f4SPaul Zimmerman  *                      controller.
940197ba5f4SPaul Zimmerman  * @periodic_sched_queued: List of periodic QHs that have been queued for
941197ba5f4SPaul Zimmerman  *                      execution. Items move from this list to either
942197ba5f4SPaul Zimmerman  *                      periodic_sched_inactive or periodic_sched_ready when the
943197ba5f4SPaul Zimmerman  *                      channel associated with the transfer is released. If the
944197ba5f4SPaul Zimmerman  *                      interval for the QH is 1, the item moves to
945197ba5f4SPaul Zimmerman  *                      periodic_sched_ready because it must be rescheduled for
946197ba5f4SPaul Zimmerman  *                      the next frame. Otherwise, the item moves to
947197ba5f4SPaul Zimmerman  *                      periodic_sched_inactive.
948c9c8ac01SDouglas Anderson  * @split_order:        List keeping track of channels doing splits, in order.
949197ba5f4SPaul Zimmerman  * @periodic_usecs:     Total bandwidth claimed so far for periodic transfers.
950197ba5f4SPaul Zimmerman  *                      This value is in microseconds per (micro)frame. The
951197ba5f4SPaul Zimmerman  *                      assumption is that all periodic transfers may occur in
952197ba5f4SPaul Zimmerman  *                      the same (micro)frame.
9539f9f09b0SDouglas Anderson  * @hs_periodic_bitmap: Bitmap used by the microframe scheduler any time the
9549f9f09b0SDouglas Anderson  *                      host is in high speed mode; low speed schedules are
9559f9f09b0SDouglas Anderson  *                      stored elsewhere since we need one per TT.
956197ba5f4SPaul Zimmerman  * @periodic_qh_count:  Count of periodic QHs, if using several eps. Used for
957197ba5f4SPaul Zimmerman  *                      SOF enable/disable.
958197ba5f4SPaul Zimmerman  * @free_hc_list:       Free host channels in the controller. This is a list of
959197ba5f4SPaul Zimmerman  *                      struct dwc2_host_chan items.
960197ba5f4SPaul Zimmerman  * @periodic_channels:  Number of host channels assigned to periodic transfers.
961197ba5f4SPaul Zimmerman  *                      Currently assuming that there is a dedicated host
962197ba5f4SPaul Zimmerman  *                      channel for each periodic transaction and at least one
963197ba5f4SPaul Zimmerman  *                      host channel is available for non-periodic transactions.
964197ba5f4SPaul Zimmerman  * @non_periodic_channels: Number of host channels assigned to non-periodic
965197ba5f4SPaul Zimmerman  *                      transfers
9666fb914d7SGrigor Tovmasyan  * @available_host_channels: Number of host channels available for the
9676fb914d7SGrigor Tovmasyan  *			     microframe scheduler to use
968197ba5f4SPaul Zimmerman  * @hc_ptr_array:       Array of pointers to the host channel descriptors.
969197ba5f4SPaul Zimmerman  *                      Allows accessing a host channel descriptor given the
970197ba5f4SPaul Zimmerman  *                      host channel number. This is useful in interrupt
971197ba5f4SPaul Zimmerman  *                      handlers.
972197ba5f4SPaul Zimmerman  * @status_buf:         Buffer used for data received during the status phase of
973197ba5f4SPaul Zimmerman  *                      a control transfer.
974197ba5f4SPaul Zimmerman  * @status_buf_dma:     DMA address for status_buf
975197ba5f4SPaul Zimmerman  * @start_work:         Delayed work for handling host A-cable connection
976197ba5f4SPaul Zimmerman  * @reset_work:         Delayed work for handling a port reset
977c40cf770SDouglas Anderson  * @phy_reset_work:     Work structure for doing a PHY reset
978197ba5f4SPaul Zimmerman  * @otg_port:           OTG port number
979197ba5f4SPaul Zimmerman  * @frame_list:         Frame list
980197ba5f4SPaul Zimmerman  * @frame_list_dma:     Frame list DMA address
98195105a99SGregory Herrero  * @frame_list_sz:      Frame list size
9823b5fcc9aSGregory Herrero  * @desc_gen_cache:     Kmem cache for generic descriptors
9833b5fcc9aSGregory Herrero  * @desc_hsisoc_cache:  Kmem cache for hs isochronous descriptors
984af424a41SWilliam Wu  * @unaligned_cache:    Kmem cache for DMA mode to handle non-aligned buf
985941fcce4SDinh Nguyen  *
986941fcce4SDinh Nguyen  * These are for peripheral mode:
987941fcce4SDinh Nguyen  *
988941fcce4SDinh Nguyen  * @driver:             USB gadget driver
989941fcce4SDinh Nguyen  * @dedicated_fifos:    Set if the hardware has dedicated IN-EP fifos.
990941fcce4SDinh Nguyen  * @num_of_eps:         Number of available EPs (excluding EP0)
991941fcce4SDinh Nguyen  * @debug_root:         Root directrory for debugfs.
992941fcce4SDinh Nguyen  * @ep0_reply:          Request used for ep0 reply.
993941fcce4SDinh Nguyen  * @ep0_buff:           Buffer for EP0 reply data, if needed.
994941fcce4SDinh Nguyen  * @ctrl_buff:          Buffer for EP0 control requests.
995941fcce4SDinh Nguyen  * @ctrl_req:           Request for EP0 control packets.
996fe0b94abSMian Yousaf Kaukab  * @ep0_state:          EP0 control transfers state
9979e14d0a5SGregory Herrero  * @test_mode:          USB test mode requested by the host
998fa389a6dSVardan Mikayelyan  * @remote_wakeup_allowed: True if device is allowed to wake-up host by
999fa389a6dSVardan Mikayelyan  *                      remote-wakeup signalling
10000f6b80c0SVahram Aharonyan  * @setup_desc_dma:	EP0 setup stage desc chain DMA address
10010f6b80c0SVahram Aharonyan  * @setup_desc:		EP0 setup stage desc chain pointer
10020f6b80c0SVahram Aharonyan  * @ctrl_in_desc_dma:	EP0 IN data phase desc chain DMA address
10030f6b80c0SVahram Aharonyan  * @ctrl_in_desc:	EP0 IN data phase desc chain pointer
10040f6b80c0SVahram Aharonyan  * @ctrl_out_desc_dma:	EP0 OUT data phase desc chain DMA address
10050f6b80c0SVahram Aharonyan  * @ctrl_out_desc:	EP0 OUT data phase desc chain pointer
10066fb914d7SGrigor Tovmasyan  * @irq:		Interrupt request line number
10076fb914d7SGrigor Tovmasyan  * @clk:		Pointer to otg clock
10086fb914d7SGrigor Tovmasyan  * @reset:		Pointer to dwc2 reset controller
10096fb914d7SGrigor Tovmasyan  * @reset_ecc:          Pointer to dwc2 optional reset controller in Stratix10.
10106fb914d7SGrigor Tovmasyan  * @regset:		A pointer to a struct debugfs_regset32, which contains
10116fb914d7SGrigor Tovmasyan  *			a pointer to an array of register definitions, the
10126fb914d7SGrigor Tovmasyan  *			array size and the base address where the register bank
10136fb914d7SGrigor Tovmasyan  *			is to be found.
10146fb914d7SGrigor Tovmasyan  * @bus_suspended:	True if bus is suspended
10156fb914d7SGrigor Tovmasyan  * @last_frame_num:	Number of last frame. Range from 0 to  32768
10166fb914d7SGrigor Tovmasyan  * @frame_num_array:    Used only  if CONFIG_USB_DWC2_TRACK_MISSED_SOFS is
10176fb914d7SGrigor Tovmasyan  *			defined, for missed SOFs tracking. Array holds that
10186fb914d7SGrigor Tovmasyan  *			frame numbers, which not equal to last_frame_num +1
10196fb914d7SGrigor Tovmasyan  * @last_frame_num_array:   Used only  if CONFIG_USB_DWC2_TRACK_MISSED_SOFS is
10206fb914d7SGrigor Tovmasyan  *			    defined, for missed SOFs tracking.
10216fb914d7SGrigor Tovmasyan  *			    If current_frame_number != last_frame_num+1
10226fb914d7SGrigor Tovmasyan  *			    then last_frame_num added to this array
10236fb914d7SGrigor Tovmasyan  * @frame_num_idx:	Actual size of frame_num_array and last_frame_num_array
10246fb914d7SGrigor Tovmasyan  * @dumped_frame_num_array:	1 - if missed SOFs frame numbers dumbed
10256fb914d7SGrigor Tovmasyan  *				0 - if missed SOFs frame numbers not dumbed
10266fb914d7SGrigor Tovmasyan  * @fifo_mem:			Total internal RAM for FIFOs (bytes)
10276fb914d7SGrigor Tovmasyan  * @fifo_map:		Each bit intend for concrete fifo. If that bit is set,
10286fb914d7SGrigor Tovmasyan  *			then that fifo is used
10296fb914d7SGrigor Tovmasyan  * @gadget:		Represents a usb slave device
10306fb914d7SGrigor Tovmasyan  * @connected:		Used in slave mode. True if device connected with host
10316fb914d7SGrigor Tovmasyan  * @eps_in:		The IN endpoints being supplied to the gadget framework
10326fb914d7SGrigor Tovmasyan  * @eps_out:		The OUT endpoints being supplied to the gadget framework
10336fb914d7SGrigor Tovmasyan  * @new_connection:	Used in host mode. True if there are new connected
10346fb914d7SGrigor Tovmasyan  *			device
10356fb914d7SGrigor Tovmasyan  * @enabled:		Indicates the enabling state of controller
10366fb914d7SGrigor Tovmasyan  *
1037197ba5f4SPaul Zimmerman  */
1038197ba5f4SPaul Zimmerman struct dwc2_hsotg {
1039197ba5f4SPaul Zimmerman 	struct device *dev;
1040197ba5f4SPaul Zimmerman 	void __iomem *regs;
1041197ba5f4SPaul Zimmerman 	/** Params detected from hardware */
1042197ba5f4SPaul Zimmerman 	struct dwc2_hw_params hw_params;
1043197ba5f4SPaul Zimmerman 	/** Params to actually use */
1044bea8e86cSJohn Youn 	struct dwc2_core_params params;
1045197ba5f4SPaul Zimmerman 	enum usb_otg_state op_state;
1046c0155b9dSKever Yang 	enum usb_dr_mode dr_mode;
1047e39af88fSMarek Szyprowski 	unsigned int hcd_enabled:1;
1048e39af88fSMarek Szyprowski 	unsigned int gadget_enabled:1;
104909a75e85SMarek Szyprowski 	unsigned int ll_hw_enabled:1;
105020fe4409SVardan Mikayelyan 	unsigned int hibernated:1;
1051c40cf770SDouglas Anderson 	unsigned int reset_phy_on_wake:1;
1052c7c24e7aSArtur Petrosyan 	u16 frame_number;
1053197ba5f4SPaul Zimmerman 
1054941fcce4SDinh Nguyen 	struct phy *phy;
1055941fcce4SDinh Nguyen 	struct usb_phy *uphy;
105609a75e85SMarek Szyprowski 	struct dwc2_hsotg_plat *plat;
1057b98866c2SJohn Youn 	struct regulator_bulk_data supplies[DWC2_NUM_SUPPLIES];
1058531ef5ebSAmelie Delaunay 	struct regulator *vbus_supply;
105909a75e85SMarek Szyprowski 	u32 phyif;
1060941fcce4SDinh Nguyen 
1061941fcce4SDinh Nguyen 	spinlock_t lock;
1062941fcce4SDinh Nguyen 	void *priv;
1063941fcce4SDinh Nguyen 	int     irq;
1064941fcce4SDinh Nguyen 	struct clk *clk;
106583f8da56SDinh Nguyen 	struct reset_control *reset;
1066f2830ad4SDinh Nguyen 	struct reset_control *reset_ecc;
1067941fcce4SDinh Nguyen 
1068197ba5f4SPaul Zimmerman 	unsigned int queuing_high_bandwidth:1;
1069197ba5f4SPaul Zimmerman 	unsigned int srp_success:1;
1070197ba5f4SPaul Zimmerman 
1071197ba5f4SPaul Zimmerman 	struct workqueue_struct *wq_otg;
1072197ba5f4SPaul Zimmerman 	struct work_struct wf_otg;
1073197ba5f4SPaul Zimmerman 	struct timer_list wkp_timer;
1074197ba5f4SPaul Zimmerman 	enum dwc2_lx_state lx_state;
1075cc1e204cSMian Yousaf Kaukab 	struct dwc2_gregs_backup gr_backup;
1076cc1e204cSMian Yousaf Kaukab 	struct dwc2_dregs_backup dr_backup;
1077cc1e204cSMian Yousaf Kaukab 	struct dwc2_hregs_backup hr_backup;
1078197ba5f4SPaul Zimmerman 
1079941fcce4SDinh Nguyen 	struct dentry *debug_root;
1080563cf017SMian Yousaf Kaukab 	struct debugfs_regset32 *regset;
1081fe369e18SGevorg Sahakyan 	bool needs_byte_swap;
1082941fcce4SDinh Nguyen 
1083941fcce4SDinh Nguyen 	/* DWC OTG HW Release versions */
1084941fcce4SDinh Nguyen #define DWC2_CORE_REV_2_71a	0x4f54271a
10855295322aSArtur Petrosyan #define DWC2_CORE_REV_2_72a     0x4f54272a
10866f80b6deSSevak Arakelyan #define DWC2_CORE_REV_2_80a	0x4f54280a
1087941fcce4SDinh Nguyen #define DWC2_CORE_REV_2_90a	0x4f54290a
1088e1f411d1SSevak Arakelyan #define DWC2_CORE_REV_2_91a	0x4f54291a
1089941fcce4SDinh Nguyen #define DWC2_CORE_REV_2_92a	0x4f54292a
1090941fcce4SDinh Nguyen #define DWC2_CORE_REV_2_94a	0x4f54294a
1091941fcce4SDinh Nguyen #define DWC2_CORE_REV_3_00a	0x4f54300a
1092fef6bc37SJohn Youn #define DWC2_CORE_REV_3_10a	0x4f54310a
10935295322aSArtur Petrosyan #define DWC2_CORE_REV_4_00a	0x4f54400a
10941e6b98ebSVardan Mikayelyan #define DWC2_FS_IOT_REV_1_00a	0x5531100a
10951e6b98ebSVardan Mikayelyan #define DWC2_HS_IOT_REV_1_00a	0x5532100a
1096941fcce4SDinh Nguyen 
1097d14ccabaSGevorg Sahakyan 	/* DWC OTG HW Core ID */
1098d14ccabaSGevorg Sahakyan #define DWC2_OTG_ID		0x4f540000
1099d14ccabaSGevorg Sahakyan #define DWC2_FS_IOT_ID		0x55310000
1100d14ccabaSGevorg Sahakyan #define DWC2_HS_IOT_ID		0x55320000
1101d14ccabaSGevorg Sahakyan 
1102941fcce4SDinh Nguyen #if IS_ENABLED(CONFIG_USB_DWC2_HOST) || IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE)
1103197ba5f4SPaul Zimmerman 	union dwc2_hcd_internal_flags {
1104197ba5f4SPaul Zimmerman 		u32 d32;
1105197ba5f4SPaul Zimmerman 		struct {
1106197ba5f4SPaul Zimmerman 			unsigned port_connect_status_change:1;
1107197ba5f4SPaul Zimmerman 			unsigned port_connect_status:1;
1108197ba5f4SPaul Zimmerman 			unsigned port_reset_change:1;
1109197ba5f4SPaul Zimmerman 			unsigned port_enable_change:1;
1110197ba5f4SPaul Zimmerman 			unsigned port_suspend_change:1;
1111197ba5f4SPaul Zimmerman 			unsigned port_over_current_change:1;
1112197ba5f4SPaul Zimmerman 			unsigned port_l1_change:1;
1113fd4850cfSCharles Manning 			unsigned reserved:25;
1114197ba5f4SPaul Zimmerman 		} b;
1115197ba5f4SPaul Zimmerman 	} flags;
1116197ba5f4SPaul Zimmerman 
1117197ba5f4SPaul Zimmerman 	struct list_head non_periodic_sched_inactive;
111838d2b5fbSDouglas Anderson 	struct list_head non_periodic_sched_waiting;
1119197ba5f4SPaul Zimmerman 	struct list_head non_periodic_sched_active;
1120197ba5f4SPaul Zimmerman 	struct list_head *non_periodic_qh_ptr;
1121197ba5f4SPaul Zimmerman 	struct list_head periodic_sched_inactive;
1122197ba5f4SPaul Zimmerman 	struct list_head periodic_sched_ready;
1123197ba5f4SPaul Zimmerman 	struct list_head periodic_sched_assigned;
1124197ba5f4SPaul Zimmerman 	struct list_head periodic_sched_queued;
1125c9c8ac01SDouglas Anderson 	struct list_head split_order;
1126197ba5f4SPaul Zimmerman 	u16 periodic_usecs;
11279f9f09b0SDouglas Anderson 	unsigned long hs_periodic_bitmap[
11289f9f09b0SDouglas Anderson 		DIV_ROUND_UP(DWC2_HS_SCHEDULE_US, BITS_PER_LONG)];
1129197ba5f4SPaul Zimmerman 	u16 periodic_qh_count;
1130734643dfSGregory Herrero 	bool bus_suspended;
1131fbb9e22bSMian Yousaf Kaukab 	bool new_connection;
1132197ba5f4SPaul Zimmerman 
1133483bb254SDouglas Anderson 	u16 last_frame_num;
1134483bb254SDouglas Anderson 
1135197ba5f4SPaul Zimmerman #ifdef CONFIG_USB_DWC2_TRACK_MISSED_SOFS
1136197ba5f4SPaul Zimmerman #define FRAME_NUM_ARRAY_SIZE 1000
1137197ba5f4SPaul Zimmerman 	u16 *frame_num_array;
1138197ba5f4SPaul Zimmerman 	u16 *last_frame_num_array;
1139197ba5f4SPaul Zimmerman 	int frame_num_idx;
1140197ba5f4SPaul Zimmerman 	int dumped_frame_num_array;
1141197ba5f4SPaul Zimmerman #endif
1142197ba5f4SPaul Zimmerman 
1143197ba5f4SPaul Zimmerman 	struct list_head free_hc_list;
1144197ba5f4SPaul Zimmerman 	int periodic_channels;
1145197ba5f4SPaul Zimmerman 	int non_periodic_channels;
1146197ba5f4SPaul Zimmerman 	int available_host_channels;
1147197ba5f4SPaul Zimmerman 	struct dwc2_host_chan *hc_ptr_array[MAX_EPS_CHANNELS];
1148197ba5f4SPaul Zimmerman 	u8 *status_buf;
1149197ba5f4SPaul Zimmerman 	dma_addr_t status_buf_dma;
1150197ba5f4SPaul Zimmerman #define DWC2_HCD_STATUS_BUF_SIZE 64
1151197ba5f4SPaul Zimmerman 
1152197ba5f4SPaul Zimmerman 	struct delayed_work start_work;
1153197ba5f4SPaul Zimmerman 	struct delayed_work reset_work;
1154c40cf770SDouglas Anderson 	struct work_struct phy_reset_work;
1155197ba5f4SPaul Zimmerman 	u8 otg_port;
1156197ba5f4SPaul Zimmerman 	u32 *frame_list;
1157197ba5f4SPaul Zimmerman 	dma_addr_t frame_list_dma;
115895105a99SGregory Herrero 	u32 frame_list_sz;
11593b5fcc9aSGregory Herrero 	struct kmem_cache *desc_gen_cache;
11603b5fcc9aSGregory Herrero 	struct kmem_cache *desc_hsisoc_cache;
1161af424a41SWilliam Wu 	struct kmem_cache *unaligned_cache;
1162af424a41SWilliam Wu #define DWC2_KMEM_UNALIGNED_BUF_SIZE 1024
1163197ba5f4SPaul Zimmerman 
1164941fcce4SDinh Nguyen #endif /* CONFIG_USB_DWC2_HOST || CONFIG_USB_DWC2_DUAL_ROLE */
1165941fcce4SDinh Nguyen 
1166b98866c2SJohn Youn #if IS_ENABLED(CONFIG_USB_DWC2_PERIPHERAL) || \
1167b98866c2SJohn Youn 	IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE)
1168941fcce4SDinh Nguyen 	/* Gadget structures */
1169941fcce4SDinh Nguyen 	struct usb_gadget_driver *driver;
1170941fcce4SDinh Nguyen 	int fifo_mem;
1171941fcce4SDinh Nguyen 	unsigned int dedicated_fifos:1;
1172941fcce4SDinh Nguyen 	unsigned char num_of_eps;
1173941fcce4SDinh Nguyen 	u32 fifo_map;
1174941fcce4SDinh Nguyen 
1175941fcce4SDinh Nguyen 	struct usb_request *ep0_reply;
1176941fcce4SDinh Nguyen 	struct usb_request *ctrl_req;
11773f95001dSMian Yousaf Kaukab 	void *ep0_buff;
11783f95001dSMian Yousaf Kaukab 	void *ctrl_buff;
1179fe0b94abSMian Yousaf Kaukab 	enum dwc2_ep0_state ep0_state;
11809e14d0a5SGregory Herrero 	u8 test_mode;
1181941fcce4SDinh Nguyen 
11820f6b80c0SVahram Aharonyan 	dma_addr_t setup_desc_dma[2];
11830f6b80c0SVahram Aharonyan 	struct dwc2_dma_desc *setup_desc[2];
11840f6b80c0SVahram Aharonyan 	dma_addr_t ctrl_in_desc_dma;
11850f6b80c0SVahram Aharonyan 	struct dwc2_dma_desc *ctrl_in_desc;
11860f6b80c0SVahram Aharonyan 	dma_addr_t ctrl_out_desc_dma;
11870f6b80c0SVahram Aharonyan 	struct dwc2_dma_desc *ctrl_out_desc;
11880f6b80c0SVahram Aharonyan 
1189941fcce4SDinh Nguyen 	struct usb_gadget gadget;
1190dc6e69e6SMarek Szyprowski 	unsigned int enabled:1;
11914ace06e8SMarek Szyprowski 	unsigned int connected:1;
1192fa389a6dSVardan Mikayelyan 	unsigned int remote_wakeup_allowed:1;
11931f91b4ccSFelipe Balbi 	struct dwc2_hsotg_ep *eps_in[MAX_EPS_CHANNELS];
11941f91b4ccSFelipe Balbi 	struct dwc2_hsotg_ep *eps_out[MAX_EPS_CHANNELS];
1195941fcce4SDinh Nguyen #endif /* CONFIG_USB_DWC2_PERIPHERAL || CONFIG_USB_DWC2_DUAL_ROLE */
1196197ba5f4SPaul Zimmerman };
1197197ba5f4SPaul Zimmerman 
11980f548098SGevorg Sahakyan /* Normal architectures just use readl/write */
1199f25c42b8SGevorg Sahakyan static inline u32 dwc2_readl(struct dwc2_hsotg *hsotg, u32 offset)
12000f548098SGevorg Sahakyan {
1201fe369e18SGevorg Sahakyan 	u32 val;
1202fe369e18SGevorg Sahakyan 
1203fe369e18SGevorg Sahakyan 	val = readl(hsotg->regs + offset);
1204fe369e18SGevorg Sahakyan 	if (hsotg->needs_byte_swap)
1205fe369e18SGevorg Sahakyan 		return swab32(val);
1206fe369e18SGevorg Sahakyan 	else
1207fe369e18SGevorg Sahakyan 		return val;
12080f548098SGevorg Sahakyan }
12090f548098SGevorg Sahakyan 
1210f25c42b8SGevorg Sahakyan static inline void dwc2_writel(struct dwc2_hsotg *hsotg, u32 value, u32 offset)
12110f548098SGevorg Sahakyan {
1212fe369e18SGevorg Sahakyan 	if (hsotg->needs_byte_swap)
1213fe369e18SGevorg Sahakyan 		writel(swab32(value), hsotg->regs + offset);
1214fe369e18SGevorg Sahakyan 	else
1215f25c42b8SGevorg Sahakyan 		writel(value, hsotg->regs + offset);
12160f548098SGevorg Sahakyan 
12170f548098SGevorg Sahakyan #ifdef DWC2_LOG_WRITES
1218f25c42b8SGevorg Sahakyan 	pr_info("info:: wrote %08x to %p\n", value, hsotg->regs + offset);
12190f548098SGevorg Sahakyan #endif
12200f548098SGevorg Sahakyan }
1221342ccce1SGevorg Sahakyan 
1222342ccce1SGevorg Sahakyan static inline void dwc2_readl_rep(struct dwc2_hsotg *hsotg, u32 offset,
1223342ccce1SGevorg Sahakyan 				  void *buffer, unsigned int count)
1224342ccce1SGevorg Sahakyan {
1225342ccce1SGevorg Sahakyan 	if (count) {
1226342ccce1SGevorg Sahakyan 		u32 *buf = buffer;
1227342ccce1SGevorg Sahakyan 
1228342ccce1SGevorg Sahakyan 		do {
1229342ccce1SGevorg Sahakyan 			u32 x = dwc2_readl(hsotg, offset);
1230342ccce1SGevorg Sahakyan 			*buf++ = x;
1231342ccce1SGevorg Sahakyan 		} while (--count);
1232342ccce1SGevorg Sahakyan 	}
1233342ccce1SGevorg Sahakyan }
1234342ccce1SGevorg Sahakyan 
1235342ccce1SGevorg Sahakyan static inline void dwc2_writel_rep(struct dwc2_hsotg *hsotg, u32 offset,
1236342ccce1SGevorg Sahakyan 				   const void *buffer, unsigned int count)
1237342ccce1SGevorg Sahakyan {
1238342ccce1SGevorg Sahakyan 	if (count) {
1239342ccce1SGevorg Sahakyan 		const u32 *buf = buffer;
1240342ccce1SGevorg Sahakyan 
1241342ccce1SGevorg Sahakyan 		do {
1242342ccce1SGevorg Sahakyan 			dwc2_writel(hsotg, *buf++, offset);
1243342ccce1SGevorg Sahakyan 		} while (--count);
1244342ccce1SGevorg Sahakyan 	}
1245342ccce1SGevorg Sahakyan }
12460f548098SGevorg Sahakyan 
1247197ba5f4SPaul Zimmerman /* Reasons for halting a host channel */
1248197ba5f4SPaul Zimmerman enum dwc2_halt_status {
1249197ba5f4SPaul Zimmerman 	DWC2_HC_XFER_NO_HALT_STATUS,
1250197ba5f4SPaul Zimmerman 	DWC2_HC_XFER_COMPLETE,
1251197ba5f4SPaul Zimmerman 	DWC2_HC_XFER_URB_COMPLETE,
1252197ba5f4SPaul Zimmerman 	DWC2_HC_XFER_ACK,
1253197ba5f4SPaul Zimmerman 	DWC2_HC_XFER_NAK,
1254197ba5f4SPaul Zimmerman 	DWC2_HC_XFER_NYET,
1255197ba5f4SPaul Zimmerman 	DWC2_HC_XFER_STALL,
1256197ba5f4SPaul Zimmerman 	DWC2_HC_XFER_XACT_ERR,
1257197ba5f4SPaul Zimmerman 	DWC2_HC_XFER_FRAME_OVERRUN,
1258197ba5f4SPaul Zimmerman 	DWC2_HC_XFER_BABBLE_ERR,
1259197ba5f4SPaul Zimmerman 	DWC2_HC_XFER_DATA_TOGGLE_ERR,
1260197ba5f4SPaul Zimmerman 	DWC2_HC_XFER_AHB_ERR,
1261197ba5f4SPaul Zimmerman 	DWC2_HC_XFER_PERIODIC_INCOMPLETE,
1262197ba5f4SPaul Zimmerman 	DWC2_HC_XFER_URB_DEQUEUE,
1263197ba5f4SPaul Zimmerman };
1264197ba5f4SPaul Zimmerman 
12651e6b98ebSVardan Mikayelyan /* Core version information */
12661e6b98ebSVardan Mikayelyan static inline bool dwc2_is_iot(struct dwc2_hsotg *hsotg)
12671e6b98ebSVardan Mikayelyan {
12681e6b98ebSVardan Mikayelyan 	return (hsotg->hw_params.snpsid & 0xfff00000) == 0x55300000;
12691e6b98ebSVardan Mikayelyan }
12701e6b98ebSVardan Mikayelyan 
12711e6b98ebSVardan Mikayelyan static inline bool dwc2_is_fs_iot(struct dwc2_hsotg *hsotg)
12721e6b98ebSVardan Mikayelyan {
12731e6b98ebSVardan Mikayelyan 	return (hsotg->hw_params.snpsid & 0xffff0000) == 0x55310000;
12741e6b98ebSVardan Mikayelyan }
12751e6b98ebSVardan Mikayelyan 
12761e6b98ebSVardan Mikayelyan static inline bool dwc2_is_hs_iot(struct dwc2_hsotg *hsotg)
12771e6b98ebSVardan Mikayelyan {
12781e6b98ebSVardan Mikayelyan 	return (hsotg->hw_params.snpsid & 0xffff0000) == 0x55320000;
12791e6b98ebSVardan Mikayelyan }
12801e6b98ebSVardan Mikayelyan 
1281197ba5f4SPaul Zimmerman /*
1282197ba5f4SPaul Zimmerman  * The following functions support initialization of the core driver component
1283197ba5f4SPaul Zimmerman  * and the DWC_otg controller
1284197ba5f4SPaul Zimmerman  */
12856e6360b6SJohn Stultz int dwc2_core_reset(struct dwc2_hsotg *hsotg, bool skip_wait);
128641ba9b9bSVardan Mikayelyan int dwc2_enter_partial_power_down(struct dwc2_hsotg *hsotg);
128741ba9b9bSVardan Mikayelyan int dwc2_exit_partial_power_down(struct dwc2_hsotg *hsotg, bool restore);
1288624815ceSVardan Mikayelyan int dwc2_enter_hibernation(struct dwc2_hsotg *hsotg, int is_host);
1289624815ceSVardan Mikayelyan int dwc2_exit_hibernation(struct dwc2_hsotg *hsotg, int rem_wakeup,
1290624815ceSVardan Mikayelyan 		int reset, int is_host);
1291197ba5f4SPaul Zimmerman 
129213b1f8e2SVardan Mikayelyan void dwc2_force_mode(struct dwc2_hsotg *hsotg, bool host);
129309c96980SJohn Youn void dwc2_force_dr_mode(struct dwc2_hsotg *hsotg);
129409c96980SJohn Youn 
12959da51974SJohn Youn bool dwc2_is_controller_alive(struct dwc2_hsotg *hsotg);
1296197ba5f4SPaul Zimmerman 
1297197ba5f4SPaul Zimmerman /*
1298197ba5f4SPaul Zimmerman  * Common core Functions.
1299197ba5f4SPaul Zimmerman  * The following functions support managing the DWC_otg controller in either
1300197ba5f4SPaul Zimmerman  * device or host mode.
1301197ba5f4SPaul Zimmerman  */
13029da51974SJohn Youn void dwc2_read_packet(struct dwc2_hsotg *hsotg, u8 *dest, u16 bytes);
13039da51974SJohn Youn void dwc2_flush_tx_fifo(struct dwc2_hsotg *hsotg, const int num);
13049da51974SJohn Youn void dwc2_flush_rx_fifo(struct dwc2_hsotg *hsotg);
1305197ba5f4SPaul Zimmerman 
13069da51974SJohn Youn void dwc2_enable_global_interrupts(struct dwc2_hsotg *hcd);
13079da51974SJohn Youn void dwc2_disable_global_interrupts(struct dwc2_hsotg *hcd);
1308197ba5f4SPaul Zimmerman 
130994d2666cSVardan Mikayelyan void dwc2_hib_restore_common(struct dwc2_hsotg *hsotg, int rem_wakeup,
131094d2666cSVardan Mikayelyan 			     int is_host);
1311c5c403dcSVardan Mikayelyan int dwc2_backup_global_registers(struct dwc2_hsotg *hsotg);
1312c5c403dcSVardan Mikayelyan int dwc2_restore_global_registers(struct dwc2_hsotg *hsotg);
131394d2666cSVardan Mikayelyan 
131466e77a24SRazmik Karapetyan void dwc2_enable_acg(struct dwc2_hsotg *hsotg);
131566e77a24SRazmik Karapetyan 
1316197ba5f4SPaul Zimmerman /* This function should be called on every hardware interrupt. */
13179da51974SJohn Youn irqreturn_t dwc2_handle_common_intr(int irq, void *dev);
1318197ba5f4SPaul Zimmerman 
1319323230efSJohn Youn /* The device ID match table */
1320323230efSJohn Youn extern const struct of_device_id dwc2_of_match_table[];
1321323230efSJohn Youn 
13229da51974SJohn Youn int dwc2_lowlevel_hw_enable(struct dwc2_hsotg *hsotg);
13239da51974SJohn Youn int dwc2_lowlevel_hw_disable(struct dwc2_hsotg *hsotg);
1324ecb176c6SMian Yousaf Kaukab 
132579d6b8c5SSevak Arakelyan /* Common polling functions */
132679d6b8c5SSevak Arakelyan int dwc2_hsotg_wait_bit_set(struct dwc2_hsotg *hs_otg, u32 reg, u32 bit,
132779d6b8c5SSevak Arakelyan 			    u32 timeout);
132879d6b8c5SSevak Arakelyan int dwc2_hsotg_wait_bit_clear(struct dwc2_hsotg *hs_otg, u32 reg, u32 bit,
132979d6b8c5SSevak Arakelyan 			      u32 timeout);
1330334bbd4eSJohn Youn /* Parameters */
1331c1d286cfSJohn Youn int dwc2_get_hwparams(struct dwc2_hsotg *hsotg);
1332334bbd4eSJohn Youn int dwc2_init_params(struct dwc2_hsotg *hsotg);
1333334bbd4eSJohn Youn 
1334197ba5f4SPaul Zimmerman /*
13356bea9620SJohn Youn  * The following functions check the controller's OTG operation mode
13366bea9620SJohn Youn  * capability (GHWCFG2.OTG_MODE).
13376bea9620SJohn Youn  *
13386bea9620SJohn Youn  * These functions can be used before the internal hsotg->hw_params
13396bea9620SJohn Youn  * are read in and cached so they always read directly from the
13406bea9620SJohn Youn  * GHWCFG2 register.
13416bea9620SJohn Youn  */
13429da51974SJohn Youn unsigned int dwc2_op_mode(struct dwc2_hsotg *hsotg);
13436bea9620SJohn Youn bool dwc2_hw_is_otg(struct dwc2_hsotg *hsotg);
13446bea9620SJohn Youn bool dwc2_hw_is_host(struct dwc2_hsotg *hsotg);
13456bea9620SJohn Youn bool dwc2_hw_is_device(struct dwc2_hsotg *hsotg);
13466bea9620SJohn Youn 
13476bea9620SJohn Youn /*
13481696d5abSJohn Youn  * Returns the mode of operation, host or device
13491696d5abSJohn Youn  */
13501696d5abSJohn Youn static inline int dwc2_is_host_mode(struct dwc2_hsotg *hsotg)
13511696d5abSJohn Youn {
1352f25c42b8SGevorg Sahakyan 	return (dwc2_readl(hsotg, GINTSTS) & GINTSTS_CURMODE_HOST) != 0;
13531696d5abSJohn Youn }
13549da51974SJohn Youn 
13551696d5abSJohn Youn static inline int dwc2_is_device_mode(struct dwc2_hsotg *hsotg)
13561696d5abSJohn Youn {
1357f25c42b8SGevorg Sahakyan 	return (dwc2_readl(hsotg, GINTSTS) & GINTSTS_CURMODE_HOST) == 0;
13581696d5abSJohn Youn }
13591696d5abSJohn Youn 
13601696d5abSJohn Youn /*
1361197ba5f4SPaul Zimmerman  * Dump core registers and SPRAM
1362197ba5f4SPaul Zimmerman  */
13639da51974SJohn Youn void dwc2_dump_dev_registers(struct dwc2_hsotg *hsotg);
13649da51974SJohn Youn void dwc2_dump_host_registers(struct dwc2_hsotg *hsotg);
13659da51974SJohn Youn void dwc2_dump_global_registers(struct dwc2_hsotg *hsotg);
1366197ba5f4SPaul Zimmerman 
1367117777b2SDinh Nguyen /* Gadget defines */
1368b98866c2SJohn Youn #if IS_ENABLED(CONFIG_USB_DWC2_PERIPHERAL) || \
1369b98866c2SJohn Youn 	IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE)
13709da51974SJohn Youn int dwc2_hsotg_remove(struct dwc2_hsotg *hsotg);
13719da51974SJohn Youn int dwc2_hsotg_suspend(struct dwc2_hsotg *dwc2);
13729da51974SJohn Youn int dwc2_hsotg_resume(struct dwc2_hsotg *dwc2);
1373f3768997SVardan Mikayelyan int dwc2_gadget_init(struct dwc2_hsotg *hsotg);
13749da51974SJohn Youn void dwc2_hsotg_core_init_disconnected(struct dwc2_hsotg *dwc2,
1375643cc4deSGregory Herrero 				       bool reset);
13769da51974SJohn Youn void dwc2_hsotg_core_connect(struct dwc2_hsotg *hsotg);
13779da51974SJohn Youn void dwc2_hsotg_disconnect(struct dwc2_hsotg *dwc2);
13789da51974SJohn Youn int dwc2_hsotg_set_test_mode(struct dwc2_hsotg *hsotg, int testmode);
1379f81f46e1SGregory Herrero #define dwc2_is_device_connected(hsotg) (hsotg->connected)
138058e52ff6SJohn Youn int dwc2_backup_device_registers(struct dwc2_hsotg *hsotg);
13819a5d2816SVardan Mikayelyan int dwc2_restore_device_registers(struct dwc2_hsotg *hsotg, int remote_wakeup);
1382c5c403dcSVardan Mikayelyan int dwc2_gadget_enter_hibernation(struct dwc2_hsotg *hsotg);
1383c5c403dcSVardan Mikayelyan int dwc2_gadget_exit_hibernation(struct dwc2_hsotg *hsotg,
1384c5c403dcSVardan Mikayelyan 				 int rem_wakeup, int reset);
1385c138ecfaSSevak Arakelyan int dwc2_hsotg_tx_fifo_count(struct dwc2_hsotg *hsotg);
1386c138ecfaSSevak Arakelyan int dwc2_hsotg_tx_fifo_total_depth(struct dwc2_hsotg *hsotg);
1387c138ecfaSSevak Arakelyan int dwc2_hsotg_tx_fifo_average_depth(struct dwc2_hsotg *hsotg);
138821b03405SSevak Arakelyan void dwc2_gadget_init_lpm(struct dwc2_hsotg *hsotg);
138915d9dbf8SGrigor Tovmasyan void dwc2_gadget_program_ref_clk(struct dwc2_hsotg *hsotg);
1390117777b2SDinh Nguyen #else
13911f91b4ccSFelipe Balbi static inline int dwc2_hsotg_remove(struct dwc2_hsotg *dwc2)
1392117777b2SDinh Nguyen { return 0; }
13931f91b4ccSFelipe Balbi static inline int dwc2_hsotg_suspend(struct dwc2_hsotg *dwc2)
1394117777b2SDinh Nguyen { return 0; }
13951f91b4ccSFelipe Balbi static inline int dwc2_hsotg_resume(struct dwc2_hsotg *dwc2)
1396117777b2SDinh Nguyen { return 0; }
1397f3768997SVardan Mikayelyan static inline int dwc2_gadget_init(struct dwc2_hsotg *hsotg)
1398117777b2SDinh Nguyen { return 0; }
13991f91b4ccSFelipe Balbi static inline void dwc2_hsotg_core_init_disconnected(struct dwc2_hsotg *dwc2,
1400643cc4deSGregory Herrero 						     bool reset) {}
14011f91b4ccSFelipe Balbi static inline void dwc2_hsotg_core_connect(struct dwc2_hsotg *hsotg) {}
14021f91b4ccSFelipe Balbi static inline void dwc2_hsotg_disconnect(struct dwc2_hsotg *dwc2) {}
14031f91b4ccSFelipe Balbi static inline int dwc2_hsotg_set_test_mode(struct dwc2_hsotg *hsotg,
1404f91eea44SMian Yousaf Kaukab 					   int testmode)
1405f91eea44SMian Yousaf Kaukab { return 0; }
1406f81f46e1SGregory Herrero #define dwc2_is_device_connected(hsotg) (0)
140758e52ff6SJohn Youn static inline int dwc2_backup_device_registers(struct dwc2_hsotg *hsotg)
140858e52ff6SJohn Youn { return 0; }
14099a5d2816SVardan Mikayelyan static inline int dwc2_restore_device_registers(struct dwc2_hsotg *hsotg,
14109a5d2816SVardan Mikayelyan 						int remote_wakeup)
141158e52ff6SJohn Youn { return 0; }
1412c5c403dcSVardan Mikayelyan static inline int dwc2_gadget_enter_hibernation(struct dwc2_hsotg *hsotg)
1413c5c403dcSVardan Mikayelyan { return 0; }
1414c5c403dcSVardan Mikayelyan static inline int dwc2_gadget_exit_hibernation(struct dwc2_hsotg *hsotg,
1415c5c403dcSVardan Mikayelyan 					       int rem_wakeup, int reset)
1416c5c403dcSVardan Mikayelyan { return 0; }
1417c138ecfaSSevak Arakelyan static inline int dwc2_hsotg_tx_fifo_count(struct dwc2_hsotg *hsotg)
1418c138ecfaSSevak Arakelyan { return 0; }
1419c138ecfaSSevak Arakelyan static inline int dwc2_hsotg_tx_fifo_total_depth(struct dwc2_hsotg *hsotg)
1420c138ecfaSSevak Arakelyan { return 0; }
1421c138ecfaSSevak Arakelyan static inline int dwc2_hsotg_tx_fifo_average_depth(struct dwc2_hsotg *hsotg)
1422c138ecfaSSevak Arakelyan { return 0; }
142321b03405SSevak Arakelyan static inline void dwc2_gadget_init_lpm(struct dwc2_hsotg *hsotg) {}
142415d9dbf8SGrigor Tovmasyan static inline void dwc2_gadget_program_ref_clk(struct dwc2_hsotg *hsotg) {}
1425117777b2SDinh Nguyen #endif
1426117777b2SDinh Nguyen 
1427117777b2SDinh Nguyen #if IS_ENABLED(CONFIG_USB_DWC2_HOST) || IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE)
14289da51974SJohn Youn int dwc2_hcd_get_frame_number(struct dwc2_hsotg *hsotg);
14299da51974SJohn Youn int dwc2_hcd_get_future_frame_number(struct dwc2_hsotg *hsotg, int us);
14309da51974SJohn Youn void dwc2_hcd_connect(struct dwc2_hsotg *hsotg);
14319da51974SJohn Youn void dwc2_hcd_disconnect(struct dwc2_hsotg *hsotg, bool force);
14329da51974SJohn Youn void dwc2_hcd_start(struct dwc2_hsotg *hsotg);
143365c9c4c6SVardan Mikayelyan int dwc2_core_init(struct dwc2_hsotg *hsotg, bool initial_setup);
143458e52ff6SJohn Youn int dwc2_backup_host_registers(struct dwc2_hsotg *hsotg);
143558e52ff6SJohn Youn int dwc2_restore_host_registers(struct dwc2_hsotg *hsotg);
1436c5c403dcSVardan Mikayelyan int dwc2_host_enter_hibernation(struct dwc2_hsotg *hsotg);
1437c5c403dcSVardan Mikayelyan int dwc2_host_exit_hibernation(struct dwc2_hsotg *hsotg,
1438c5c403dcSVardan Mikayelyan 			       int rem_wakeup, int reset);
1439c40cf770SDouglas Anderson static inline void dwc2_host_schedule_phy_reset(struct dwc2_hsotg *hsotg)
1440c40cf770SDouglas Anderson { schedule_work(&hsotg->phy_reset_work); }
1441117777b2SDinh Nguyen #else
1442117777b2SDinh Nguyen static inline int dwc2_hcd_get_frame_number(struct dwc2_hsotg *hsotg)
1443117777b2SDinh Nguyen { return 0; }
1444fae4e826SDouglas Anderson static inline int dwc2_hcd_get_future_frame_number(struct dwc2_hsotg *hsotg,
1445fae4e826SDouglas Anderson 						   int us)
1446fae4e826SDouglas Anderson { return 0; }
14476a659531SDouglas Anderson static inline void dwc2_hcd_connect(struct dwc2_hsotg *hsotg) {}
14486a659531SDouglas Anderson static inline void dwc2_hcd_disconnect(struct dwc2_hsotg *hsotg, bool force) {}
1449117777b2SDinh Nguyen static inline void dwc2_hcd_start(struct dwc2_hsotg *hsotg) {}
1450117777b2SDinh Nguyen static inline void dwc2_hcd_remove(struct dwc2_hsotg *hsotg) {}
145165c9c4c6SVardan Mikayelyan static inline int dwc2_core_init(struct dwc2_hsotg *hsotg, bool initial_setup)
145265c9c4c6SVardan Mikayelyan { return 0; }
14534fe160d5SHeiner Kallweit static inline int dwc2_hcd_init(struct dwc2_hsotg *hsotg)
1454117777b2SDinh Nguyen { return 0; }
145558e52ff6SJohn Youn static inline int dwc2_backup_host_registers(struct dwc2_hsotg *hsotg)
145658e52ff6SJohn Youn { return 0; }
145758e52ff6SJohn Youn static inline int dwc2_restore_host_registers(struct dwc2_hsotg *hsotg)
145858e52ff6SJohn Youn { return 0; }
1459c5c403dcSVardan Mikayelyan static inline int dwc2_host_enter_hibernation(struct dwc2_hsotg *hsotg)
1460c5c403dcSVardan Mikayelyan { return 0; }
1461c5c403dcSVardan Mikayelyan static inline int dwc2_host_exit_hibernation(struct dwc2_hsotg *hsotg,
1462c5c403dcSVardan Mikayelyan 					     int rem_wakeup, int reset)
1463c5c403dcSVardan Mikayelyan { return 0; }
1464c40cf770SDouglas Anderson static inline void dwc2_host_schedule_phy_reset(struct dwc2_hsotg *hsotg) {}
146558e52ff6SJohn Youn 
1466117777b2SDinh Nguyen #endif
1467117777b2SDinh Nguyen 
1468197ba5f4SPaul Zimmerman #endif /* __DWC2_CORE_H__ */
1469