xref: /linux/drivers/usb/dwc2/core.h (revision 36ec807b627b4c0a0a382f0ae48eac7187d14b2b)
1bdefa3baSNishad Kamdar /* 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 
8197ba5f4SPaul Zimmerman #ifndef __DWC2_CORE_H__
9197ba5f4SPaul Zimmerman #define __DWC2_CORE_H__
10197ba5f4SPaul Zimmerman 
112e5db2c0SJeremy Linton #include <linux/acpi.h>
12f7c0b143SDinh Nguyen #include <linux/phy/phy.h>
13f7c0b143SDinh Nguyen #include <linux/regulator/consumer.h>
14f7c0b143SDinh Nguyen #include <linux/usb/gadget.h>
15f7c0b143SDinh Nguyen #include <linux/usb/otg.h>
16197ba5f4SPaul Zimmerman #include <linux/usb/phy.h>
17197ba5f4SPaul Zimmerman #include "hw.h"
18197ba5f4SPaul Zimmerman 
1974fc4a75SDouglas Anderson /*
2074fc4a75SDouglas Anderson  * Suggested defines for tracers:
2174fc4a75SDouglas Anderson  * - no_printk:    Disable tracing
2274fc4a75SDouglas Anderson  * - pr_info:      Print this info to the console
2374fc4a75SDouglas Anderson  * - trace_printk: Print this info to trace buffer (good for verbose logging)
2474fc4a75SDouglas Anderson  */
2574fc4a75SDouglas Anderson 
2674fc4a75SDouglas Anderson #define DWC2_TRACE_SCHEDULER		no_printk
2774fc4a75SDouglas Anderson #define DWC2_TRACE_SCHEDULER_VB		no_printk
2874fc4a75SDouglas Anderson 
2974fc4a75SDouglas Anderson /* Detailed scheduler tracing, but won't overwhelm console */
3074fc4a75SDouglas Anderson #define dwc2_sch_dbg(hsotg, fmt, ...)					\
3174fc4a75SDouglas Anderson 	DWC2_TRACE_SCHEDULER(pr_fmt("%s: SCH: " fmt),			\
3274fc4a75SDouglas Anderson 			     dev_name(hsotg->dev), ##__VA_ARGS__)
3374fc4a75SDouglas Anderson 
3474fc4a75SDouglas Anderson /* Verbose scheduler tracing */
3574fc4a75SDouglas Anderson #define dwc2_sch_vdbg(hsotg, fmt, ...)					\
3674fc4a75SDouglas Anderson 	DWC2_TRACE_SCHEDULER_VB(pr_fmt("%s: SCH: " fmt),		\
3774fc4a75SDouglas Anderson 				dev_name(hsotg->dev), ##__VA_ARGS__)
3874fc4a75SDouglas Anderson 
39197ba5f4SPaul Zimmerman /* Maximum number of Endpoints/HostChannels */
40197ba5f4SPaul Zimmerman #define MAX_EPS_CHANNELS	16
41197ba5f4SPaul Zimmerman 
421f91b4ccSFelipe Balbi /* dwc2-hsotg declarations */
431f91b4ccSFelipe Balbi static const char * const dwc2_hsotg_supply_names[] = {
44f7c0b143SDinh Nguyen 	"vusb_d",               /* digital USB supply, 1.2V */
45f7c0b143SDinh Nguyen 	"vusb_a",               /* analog USB supply, 1.1V */
46f7c0b143SDinh Nguyen };
47f7c0b143SDinh Nguyen 
48b98866c2SJohn Youn #define DWC2_NUM_SUPPLIES ARRAY_SIZE(dwc2_hsotg_supply_names)
49b98866c2SJohn Youn 
50f7c0b143SDinh Nguyen /*
51f7c0b143SDinh Nguyen  * EP0_MPS_LIMIT
52f7c0b143SDinh Nguyen  *
53f7c0b143SDinh Nguyen  * Unfortunately there seems to be a limit of the amount of data that can
54f7c0b143SDinh Nguyen  * be transferred by IN transactions on EP0. This is either 127 bytes or 3
55f7c0b143SDinh Nguyen  * packets (which practically means 1 packet and 63 bytes of data) when the
56f7c0b143SDinh Nguyen  * MPS is set to 64.
57f7c0b143SDinh Nguyen  *
58f7c0b143SDinh Nguyen  * This means if we are wanting to move >127 bytes of data, we need to
59f7c0b143SDinh Nguyen  * split the transactions up, but just doing one packet at a time does
60f7c0b143SDinh Nguyen  * not work (this may be an implicit DATA0 PID on first packet of the
61f7c0b143SDinh Nguyen  * transaction) and doing 2 packets is outside the controller's limits.
62f7c0b143SDinh Nguyen  *
63f7c0b143SDinh Nguyen  * If we try to lower the MPS size for EP0, then no transfers work properly
64f7c0b143SDinh Nguyen  * for EP0, and the system will fail basic enumeration. As no cause for this
65f7c0b143SDinh Nguyen  * has currently been found, we cannot support any large IN transfers for
66f7c0b143SDinh Nguyen  * EP0.
67f7c0b143SDinh Nguyen  */
68f7c0b143SDinh Nguyen #define EP0_MPS_LIMIT   64
69f7c0b143SDinh Nguyen 
70941fcce4SDinh Nguyen struct dwc2_hsotg;
711f91b4ccSFelipe Balbi struct dwc2_hsotg_req;
72f7c0b143SDinh Nguyen 
73f7c0b143SDinh Nguyen /**
741f91b4ccSFelipe Balbi  * struct dwc2_hsotg_ep - driver endpoint definition.
75f7c0b143SDinh Nguyen  * @ep: The gadget layer representation of the endpoint.
76f7c0b143SDinh Nguyen  * @name: The driver generated name for the endpoint.
77f7c0b143SDinh Nguyen  * @queue: Queue of requests for this endpoint.
78f7c0b143SDinh Nguyen  * @parent: Reference back to the parent device structure.
79f7c0b143SDinh Nguyen  * @req: The current request that the endpoint is processing. This is
80f7c0b143SDinh Nguyen  *       used to indicate an request has been loaded onto the endpoint
81f7c0b143SDinh Nguyen  *       and has yet to be completed (maybe due to data move, or simply
82f7c0b143SDinh Nguyen  *       awaiting an ack from the core all the data has been completed).
83f7c0b143SDinh Nguyen  * @debugfs: File entry for debugfs file for this endpoint.
84f7c0b143SDinh Nguyen  * @dir_in: Set to true if this endpoint is of the IN direction, which
85f7c0b143SDinh Nguyen  *          means that it is sending data to the Host.
8675a41ce4SPhil Elwell  * @map_dir: Set to the value of dir_in when the DMA buffer is mapped.
87f7c0b143SDinh Nguyen  * @index: The index for the endpoint registers.
88f7c0b143SDinh Nguyen  * @mc: Multi Count - number of transactions per microframe
896fb914d7SGrigor Tovmasyan  * @interval: Interval for periodic endpoints, in frames or microframes.
90f7c0b143SDinh Nguyen  * @name: The name array passed to the USB core.
91f7c0b143SDinh Nguyen  * @halted: Set if the endpoint has been halted.
92f7c0b143SDinh Nguyen  * @periodic: Set if this is a periodic ep, such as Interrupt
93f7c0b143SDinh Nguyen  * @isochronous: Set if this is a isochronous ep
948a20fa45SMian Yousaf Kaukab  * @send_zlp: Set if we need to send a zero-length packet.
95b833ce15SMinas Harutyunyan  * @wedged: Set if ep is wedged.
965f54c54bSVahram Aharonyan  * @desc_list_dma: The DMA address of descriptor chain currently in use.
975f54c54bSVahram Aharonyan  * @desc_list: Pointer to descriptor DMA chain head currently in use.
985f54c54bSVahram Aharonyan  * @desc_count: Count of entries within the DMA descriptor chain of EP.
99ab7d2192SVahram Aharonyan  * @next_desc: index of next free descriptor in the ISOC chain under SW control.
100729cac69SMinas Harutyunyan  * @compl_desc: index of next descriptor to be completed by xFerComplete
101f7c0b143SDinh Nguyen  * @total_data: The total number of data bytes done.
102f7c0b143SDinh Nguyen  * @fifo_size: The size of the FIFO (for periodic IN endpoints)
1036fb914d7SGrigor Tovmasyan  * @fifo_index: For Dedicated FIFO operation, only FIFO0 can be used for EP0.
104f7c0b143SDinh Nguyen  * @fifo_load: The amount of data loaded into the FIFO (periodic IN)
105f7c0b143SDinh Nguyen  * @last_load: The offset of data for the last start of request.
106f7c0b143SDinh Nguyen  * @size_loaded: The last loaded size for DxEPTSIZE for periodic IN
10792d1635dSVardan Mikayelyan  * @target_frame: Targeted frame num to setup next ISOC transfer
10892d1635dSVardan Mikayelyan  * @frame_overrun: Indicates SOF number overrun in DSTS
109f7c0b143SDinh Nguyen  *
110c1aa81daSGeert Uytterhoeven  * This is the driver's state for each registered endpoint, allowing it
111f7c0b143SDinh Nguyen  * to keep track of transactions that need doing. Each endpoint has a
112f7c0b143SDinh Nguyen  * lock to protect the state, to try and avoid using an overall lock
113f7c0b143SDinh Nguyen  * for the host controller as much as possible.
114f7c0b143SDinh Nguyen  *
115f7c0b143SDinh Nguyen  * For periodic IN endpoints, we have fifo_size and fifo_load to try
116f7c0b143SDinh Nguyen  * and keep track of the amount of data in the periodic FIFO for each
117f7c0b143SDinh Nguyen  * of these as we don't have a status register that tells us how much
118f7c0b143SDinh Nguyen  * is in each of them. (note, this may actually be useless information
119f7c0b143SDinh Nguyen  * as in shared-fifo mode periodic in acts like a single-frame packet
120f7c0b143SDinh Nguyen  * buffer than a fifo)
121f7c0b143SDinh Nguyen  */
1221f91b4ccSFelipe Balbi struct dwc2_hsotg_ep {
123f7c0b143SDinh Nguyen 	struct usb_ep           ep;
124f7c0b143SDinh Nguyen 	struct list_head        queue;
125941fcce4SDinh Nguyen 	struct dwc2_hsotg       *parent;
1261f91b4ccSFelipe Balbi 	struct dwc2_hsotg_req    *req;
127f7c0b143SDinh Nguyen 	struct dentry           *debugfs;
128f7c0b143SDinh Nguyen 
129f7c0b143SDinh Nguyen 	unsigned long           total_data;
130f7c0b143SDinh Nguyen 	unsigned int            size_loaded;
131f7c0b143SDinh Nguyen 	unsigned int            last_load;
132f7c0b143SDinh Nguyen 	unsigned int            fifo_load;
133f7c0b143SDinh Nguyen 	unsigned short          fifo_size;
134b203d0a2SRobert Baldyga 	unsigned short		fifo_index;
135f7c0b143SDinh Nguyen 
136f7c0b143SDinh Nguyen 	unsigned char           dir_in;
13775a41ce4SPhil Elwell 	unsigned char           map_dir;
138f7c0b143SDinh Nguyen 	unsigned char           index;
139f7c0b143SDinh Nguyen 	unsigned char           mc;
14012814a3fSGrigor Tovmasyan 	u16                     interval;
141f7c0b143SDinh Nguyen 
142f7c0b143SDinh Nguyen 	unsigned int            halted:1;
143f7c0b143SDinh Nguyen 	unsigned int            periodic:1;
144f7c0b143SDinh Nguyen 	unsigned int            isochronous:1;
1458a20fa45SMian Yousaf Kaukab 	unsigned int            send_zlp:1;
146b833ce15SMinas Harutyunyan 	unsigned int            wedged:1;
14792d1635dSVardan Mikayelyan 	unsigned int            target_frame;
14892d1635dSVardan Mikayelyan #define TARGET_FRAME_INITIAL   0xFFFFFFFF
14992d1635dSVardan Mikayelyan 	bool			frame_overrun;
150f7c0b143SDinh Nguyen 
1515f54c54bSVahram Aharonyan 	dma_addr_t		desc_list_dma;
1525f54c54bSVahram Aharonyan 	struct dwc2_dma_desc	*desc_list;
1535f54c54bSVahram Aharonyan 	u8			desc_count;
1545f54c54bSVahram Aharonyan 
155ab7d2192SVahram Aharonyan 	unsigned int		next_desc;
156729cac69SMinas Harutyunyan 	unsigned int		compl_desc;
157ab7d2192SVahram Aharonyan 
158f7c0b143SDinh Nguyen 	char                    name[10];
159f7c0b143SDinh Nguyen };
160f7c0b143SDinh Nguyen 
161f7c0b143SDinh Nguyen /**
1621f91b4ccSFelipe Balbi  * struct dwc2_hsotg_req - data transfer request
163f7c0b143SDinh Nguyen  * @req: The USB gadget request
164f7c0b143SDinh Nguyen  * @queue: The list of requests for the endpoint this is queued for.
1657d24c1b5SMian Yousaf Kaukab  * @saved_req_buf: variable to save req.buf when bounce buffers are used.
166f7c0b143SDinh Nguyen  */
1671f91b4ccSFelipe Balbi struct dwc2_hsotg_req {
168f7c0b143SDinh Nguyen 	struct usb_request      req;
169f7c0b143SDinh Nguyen 	struct list_head        queue;
1707d24c1b5SMian Yousaf Kaukab 	void *saved_req_buf;
171f7c0b143SDinh Nguyen };
172f7c0b143SDinh Nguyen 
173b98866c2SJohn Youn #if IS_ENABLED(CONFIG_USB_DWC2_PERIPHERAL) || \
174b98866c2SJohn Youn 	IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE)
175f7c0b143SDinh Nguyen #define call_gadget(_hs, _entry) \
176f7c0b143SDinh Nguyen do { \
177f7c0b143SDinh Nguyen 	if ((_hs)->gadget.speed != USB_SPEED_UNKNOWN && \
178f7c0b143SDinh Nguyen 		(_hs)->driver && (_hs)->driver->_entry) { \
179f7c0b143SDinh Nguyen 		spin_unlock(&_hs->lock); \
180f7c0b143SDinh Nguyen 		(_hs)->driver->_entry(&(_hs)->gadget); \
181f7c0b143SDinh Nguyen 		spin_lock(&_hs->lock); \
182f7c0b143SDinh Nguyen 	} \
183f7c0b143SDinh Nguyen } while (0)
184941fcce4SDinh Nguyen #else
185941fcce4SDinh Nguyen #define call_gadget(_hs, _entry)	do {} while (0)
186941fcce4SDinh Nguyen #endif
187f7c0b143SDinh Nguyen 
188197ba5f4SPaul Zimmerman struct dwc2_hsotg;
189197ba5f4SPaul Zimmerman struct dwc2_host_chan;
190197ba5f4SPaul Zimmerman 
191197ba5f4SPaul Zimmerman /* Device States */
192197ba5f4SPaul Zimmerman enum dwc2_lx_state {
193197ba5f4SPaul Zimmerman 	DWC2_L0,	/* On state */
194197ba5f4SPaul Zimmerman 	DWC2_L1,	/* LPM sleep state */
195197ba5f4SPaul Zimmerman 	DWC2_L2,	/* USB suspend state */
196197ba5f4SPaul Zimmerman 	DWC2_L3,	/* Off state */
197197ba5f4SPaul Zimmerman };
198197ba5f4SPaul Zimmerman 
199fe0b94abSMian Yousaf Kaukab /* Gadget ep0 states */
200fe0b94abSMian Yousaf Kaukab enum dwc2_ep0_state {
201fe0b94abSMian Yousaf Kaukab 	DWC2_EP0_SETUP,
202fe0b94abSMian Yousaf Kaukab 	DWC2_EP0_DATA_IN,
203fe0b94abSMian Yousaf Kaukab 	DWC2_EP0_DATA_OUT,
204fe0b94abSMian Yousaf Kaukab 	DWC2_EP0_STATUS_IN,
205fe0b94abSMian Yousaf Kaukab 	DWC2_EP0_STATUS_OUT,
206fe0b94abSMian Yousaf Kaukab };
207fe0b94abSMian Yousaf Kaukab 
208197ba5f4SPaul Zimmerman /**
209197ba5f4SPaul Zimmerman  * struct dwc2_core_params - Parameters for configuring the core
210197ba5f4SPaul Zimmerman  *
211f5c8a6cbSFabrice Gasnier  * @otg_caps:           Specifies the OTG capabilities. OTG caps from the platform parameters,
212f5c8a6cbSFabrice Gasnier  *                      used to setup the:
213f5c8a6cbSFabrice Gasnier  *                       - HNP and SRP capable
214f5c8a6cbSFabrice Gasnier  *                       - SRP Only capable
215f5c8a6cbSFabrice Gasnier  *                       - No HNP/SRP capable (always available)
216f5c8a6cbSFabrice Gasnier  *                       Defaults to best available option
217f5c8a6cbSFabrice Gasnier  *                       - OTG revision number the device is compliant with, in binary-coded
218f5c8a6cbSFabrice Gasnier  *                         decimal (i.e. 2.0 is 0200H). (see struct usb_otg_caps)
219e7839f99SJohn Youn  * @host_dma:           Specifies whether to use slave or DMA mode for accessing
220197ba5f4SPaul Zimmerman  *                      the data FIFOs. The driver will automatically detect the
221197ba5f4SPaul Zimmerman  *                      value for this parameter if none is specified.
222197ba5f4SPaul Zimmerman  *                       0 - Slave (always available)
223197ba5f4SPaul Zimmerman  *                       1 - DMA (default, if available)
224197ba5f4SPaul Zimmerman  * @dma_desc_enable:    When DMA mode is enabled, specifies whether to use
225197ba5f4SPaul Zimmerman  *                      address DMA mode or descriptor DMA mode for accessing
226197ba5f4SPaul Zimmerman  *                      the data FIFOs. The driver will automatically detect the
227197ba5f4SPaul Zimmerman  *                      value for this if none is specified.
228197ba5f4SPaul Zimmerman  *                       0 - Address DMA
229197ba5f4SPaul Zimmerman  *                       1 - Descriptor DMA (default, if available)
230fbb9e22bSMian Yousaf Kaukab  * @dma_desc_fs_enable: When DMA mode is enabled, specifies whether to use
231fbb9e22bSMian Yousaf Kaukab  *                      address DMA mode or descriptor DMA mode for accessing
232fbb9e22bSMian Yousaf Kaukab  *                      the data FIFOs in Full Speed mode only. The driver
233fbb9e22bSMian Yousaf Kaukab  *                      will automatically detect the value for this if none is
234fbb9e22bSMian Yousaf Kaukab  *                      specified.
235fbb9e22bSMian Yousaf Kaukab  *                       0 - Address DMA
236fbb9e22bSMian Yousaf Kaukab  *                       1 - Descriptor DMA in FS (default, if available)
237197ba5f4SPaul Zimmerman  * @speed:              Specifies the maximum speed of operation in host and
238197ba5f4SPaul Zimmerman  *                      device mode. The actual speed depends on the speed of
239197ba5f4SPaul Zimmerman  *                      the attached device and the value of phy_type.
240197ba5f4SPaul Zimmerman  *                       0 - High Speed
241197ba5f4SPaul Zimmerman  *                           (default when phy_type is UTMI+ or ULPI)
242197ba5f4SPaul Zimmerman  *                       1 - Full Speed
243197ba5f4SPaul Zimmerman  *                           (default when phy_type is Full Speed)
244197ba5f4SPaul Zimmerman  * @enable_dynamic_fifo: 0 - Use coreConsultant-specified FIFO size parameters
245197ba5f4SPaul Zimmerman  *                       1 - Allow dynamic FIFO sizing (default, if available)
246197ba5f4SPaul Zimmerman  * @en_multiple_tx_fifo: Specifies whether dedicated per-endpoint transmit FIFOs
247c1d286cfSJohn Youn  *                      are enabled for non-periodic IN endpoints in device
248c1d286cfSJohn Youn  *                      mode.
249197ba5f4SPaul Zimmerman  * @host_rx_fifo_size:  Number of 4-byte words in the Rx FIFO in host mode when
250197ba5f4SPaul Zimmerman  *                      dynamic FIFO sizing is enabled
251197ba5f4SPaul Zimmerman  *                       16 to 32768
252197ba5f4SPaul Zimmerman  *                      Actual maximum value is autodetected and also
253197ba5f4SPaul Zimmerman  *                      the default.
254197ba5f4SPaul Zimmerman  * @host_nperio_tx_fifo_size: Number of 4-byte words in the non-periodic Tx FIFO
255197ba5f4SPaul Zimmerman  *                      in host mode when dynamic FIFO sizing is enabled
256197ba5f4SPaul Zimmerman  *                       16 to 32768
257197ba5f4SPaul Zimmerman  *                      Actual maximum value is autodetected and also
258197ba5f4SPaul Zimmerman  *                      the default.
259197ba5f4SPaul Zimmerman  * @host_perio_tx_fifo_size: Number of 4-byte words in the periodic Tx FIFO in
260197ba5f4SPaul Zimmerman  *                      host mode when dynamic FIFO sizing is enabled
261197ba5f4SPaul Zimmerman  *                       16 to 32768
262197ba5f4SPaul Zimmerman  *                      Actual maximum value is autodetected and also
263197ba5f4SPaul Zimmerman  *                      the default.
264197ba5f4SPaul Zimmerman  * @max_transfer_size:  The maximum transfer size supported, in bytes
265197ba5f4SPaul Zimmerman  *                       2047 to 65,535
266197ba5f4SPaul Zimmerman  *                      Actual maximum value is autodetected and also
267197ba5f4SPaul Zimmerman  *                      the default.
268197ba5f4SPaul Zimmerman  * @max_packet_count:   The maximum number of packets in a transfer
269197ba5f4SPaul Zimmerman  *                       15 to 511
270197ba5f4SPaul Zimmerman  *                      Actual maximum value is autodetected and also
271197ba5f4SPaul Zimmerman  *                      the default.
272197ba5f4SPaul Zimmerman  * @host_channels:      The number of host channel registers to use
273197ba5f4SPaul Zimmerman  *                       1 to 16
274197ba5f4SPaul Zimmerman  *                      Actual maximum value is autodetected and also
275197ba5f4SPaul Zimmerman  *                      the default.
276197ba5f4SPaul Zimmerman  * @phy_type:           Specifies the type of PHY interface to use. By default,
277197ba5f4SPaul Zimmerman  *                      the driver will automatically detect the phy_type.
278197ba5f4SPaul Zimmerman  *                       0 - Full Speed Phy
279197ba5f4SPaul Zimmerman  *                       1 - UTMI+ Phy
280197ba5f4SPaul Zimmerman  *                       2 - ULPI Phy
281197ba5f4SPaul Zimmerman  *                      Defaults to best available option (2, 1, then 0)
282197ba5f4SPaul Zimmerman  * @phy_utmi_width:     Specifies the UTMI+ Data Width (in bits). This parameter
283197ba5f4SPaul Zimmerman  *                      is applicable for a phy_type of UTMI+ or ULPI. (For a
284197ba5f4SPaul Zimmerman  *                      ULPI phy_type, this parameter indicates the data width
285197ba5f4SPaul Zimmerman  *                      between the MAC and the ULPI Wrapper.) Also, this
286197ba5f4SPaul Zimmerman  *                      parameter is applicable only if the OTG_HSPHY_WIDTH cC
287197ba5f4SPaul Zimmerman  *                      parameter was set to "8 and 16 bits", meaning that the
288197ba5f4SPaul Zimmerman  *                      core has been configured to work at either data path
289197ba5f4SPaul Zimmerman  *                      width.
290197ba5f4SPaul Zimmerman  *                       8 or 16 (default 16 if available)
291*bc5d81b8SMinas Harutyunyan  * @eusb2_disc:         Specifies whether eUSB2 PHY disconnect support flow
292*bc5d81b8SMinas Harutyunyan  *                      applicable or no. Applicable in device mode of HSOTG
293*bc5d81b8SMinas Harutyunyan  *                      and HS IOT cores v5.00 or higher.
294*bc5d81b8SMinas Harutyunyan  *                       0 - eUSB2 PHY disconnect support flow not applicable
295*bc5d81b8SMinas Harutyunyan  *                       1 - eUSB2 PHY disconnect support flow applicable
296197ba5f4SPaul Zimmerman  * @phy_ulpi_ddr:       Specifies whether the ULPI operates at double or single
297197ba5f4SPaul Zimmerman  *                      data rate. This parameter is only applicable if phy_type
298197ba5f4SPaul Zimmerman  *                      is ULPI.
299197ba5f4SPaul Zimmerman  *                       0 - single data rate ULPI interface with 8 bit wide
300197ba5f4SPaul Zimmerman  *                           data bus (default)
301197ba5f4SPaul Zimmerman  *                       1 - double data rate ULPI interface with 4 bit wide
302197ba5f4SPaul Zimmerman  *                           data bus
303197ba5f4SPaul Zimmerman  * @phy_ulpi_ext_vbus:  For a ULPI phy, specifies whether to use the internal or
304197ba5f4SPaul Zimmerman  *                      external supply to drive the VBus
305197ba5f4SPaul Zimmerman  *                       0 - Internal supply (default)
306197ba5f4SPaul Zimmerman  *                       1 - External supply
307197ba5f4SPaul Zimmerman  * @i2c_enable:         Specifies whether to use the I2Cinterface for a full
308197ba5f4SPaul Zimmerman  *                      speed PHY. This parameter is only applicable if phy_type
309197ba5f4SPaul Zimmerman  *                      is FS.
310197ba5f4SPaul Zimmerman  *                       0 - No (default)
311197ba5f4SPaul Zimmerman  *                       1 - Yes
3126fb914d7SGrigor Tovmasyan  * @ipg_isoc_en:        Indicates the IPG supports is enabled or disabled.
313b43ebc96SGrigor Tovmasyan  *                       0 - Disable (default)
314b43ebc96SGrigor Tovmasyan  *                       1 - Enable
3156fb914d7SGrigor Tovmasyan  * @acg_enable:		For enabling Active Clock Gating in the controller
3166fb914d7SGrigor Tovmasyan  *                       0 - No
3176fb914d7SGrigor Tovmasyan  *                       1 - Yes
318197ba5f4SPaul Zimmerman  * @ulpi_fs_ls:         Make ULPI phy operate in FS/LS mode only
319197ba5f4SPaul Zimmerman  *                       0 - No (default)
320197ba5f4SPaul Zimmerman  *                       1 - Yes
321197ba5f4SPaul Zimmerman  * @host_support_fs_ls_low_power: Specifies whether low power mode is supported
322197ba5f4SPaul Zimmerman  *                      when attached to a Full Speed or Low Speed device in
323197ba5f4SPaul Zimmerman  *                      host mode.
324197ba5f4SPaul Zimmerman  *                       0 - Don't support low power mode (default)
325197ba5f4SPaul Zimmerman  *                       1 - Support low power mode
326197ba5f4SPaul Zimmerman  * @host_ls_low_power_phy_clk: Specifies the PHY clock rate in low power mode
327197ba5f4SPaul Zimmerman  *                      when connected to a Low Speed device in host
328197ba5f4SPaul Zimmerman  *                      mode. This parameter is applicable only if
329197ba5f4SPaul Zimmerman  *                      host_support_fs_ls_low_power is enabled.
330197ba5f4SPaul Zimmerman  *                       0 - 48 MHz
331197ba5f4SPaul Zimmerman  *                           (default when phy_type is UTMI+ or ULPI)
332197ba5f4SPaul Zimmerman  *                       1 - 6 MHz
333197ba5f4SPaul Zimmerman  *                           (default when phy_type is Full Speed)
334b11633c4SDinh Nguyen  * @oc_disable:		Flag to disable overcurrent condition.
335b11633c4SDinh Nguyen  *			0 - Allow overcurrent condition to get detected
336b11633c4SDinh Nguyen  *			1 - Disable overcurrent condtion to get detected
337197ba5f4SPaul Zimmerman  * @ts_dline:           Enable Term Select Dline pulsing
338197ba5f4SPaul Zimmerman  *                       0 - No (default)
339197ba5f4SPaul Zimmerman  *                       1 - Yes
340197ba5f4SPaul Zimmerman  * @reload_ctl:         Allow dynamic reloading of HFIR register during runtime
341197ba5f4SPaul Zimmerman  *                       0 - No (default for core < 2.92a)
342197ba5f4SPaul Zimmerman  *                       1 - Yes (default for core >= 2.92a)
343197ba5f4SPaul Zimmerman  * @ahbcfg:             This field allows the default value of the GAHBCFG
344197ba5f4SPaul Zimmerman  *                      register to be overridden
345197ba5f4SPaul Zimmerman  *                       -1         - GAHBCFG value will be set to 0x06
3461b52d2faSRazmik Karapetyan  *                                    (INCR, default)
347197ba5f4SPaul Zimmerman  *                       all others - GAHBCFG value will be overridden with
348197ba5f4SPaul Zimmerman  *                                    this value
349197ba5f4SPaul Zimmerman  *                      Not all bits can be controlled like this, the
350197ba5f4SPaul Zimmerman  *                      bits defined by GAHBCFG_CTRL_MASK are controlled
351197ba5f4SPaul Zimmerman  *                      by the driver and are ignored in this
352197ba5f4SPaul Zimmerman  *                      configuration value.
353197ba5f4SPaul Zimmerman  * @uframe_sched:       True to enable the microframe scheduler
354a6d249d8SGregory Herrero  * @external_id_pin_ctl: Specifies whether ID pin is handled externally.
355a6d249d8SGregory Herrero  *                      Disable CONIDSTSCHNG controller interrupt in such
356a6d249d8SGregory Herrero  *                      case.
357a6d249d8SGregory Herrero  *                      0 - No (default)
358a6d249d8SGregory Herrero  *                      1 - Yes
35941ba9b9bSVardan Mikayelyan  * @power_down:         Specifies whether the controller support power_down.
36041ba9b9bSVardan Mikayelyan  *			If power_down is enabled, the controller will enter
36141ba9b9bSVardan Mikayelyan  *			power_down in both peripheral and host mode when
362285046aaSGregory Herrero  *			needed.
363285046aaSGregory Herrero  *			0 - No (default)
364631a2310SVardan Mikayelyan  *			1 - Partial power down
365631a2310SVardan Mikayelyan  *			2 - Hibernation
366c4a0f7a6SMarek Szyprowski  * @no_clock_gating:	Specifies whether to avoid clock gating feature.
367c4a0f7a6SMarek Szyprowski  *			0 - No (use clock gating)
368c4a0f7a6SMarek Szyprowski  *			1 - Yes (avoid it)
3696f80b6deSSevak Arakelyan  * @lpm:		Enable LPM support.
3706f80b6deSSevak Arakelyan  *			0 - No
3716f80b6deSSevak Arakelyan  *			1 - Yes
3726f80b6deSSevak Arakelyan  * @lpm_clock_gating:		Enable core PHY clock gating.
3736f80b6deSSevak Arakelyan  *			0 - No
3746f80b6deSSevak Arakelyan  *			1 - Yes
3756f80b6deSSevak Arakelyan  * @besl:		Enable LPM Errata support.
3766f80b6deSSevak Arakelyan  *			0 - No
3776f80b6deSSevak Arakelyan  *			1 - Yes
3786f80b6deSSevak Arakelyan  * @hird_threshold_en:	HIRD or HIRD Threshold enable.
3796f80b6deSSevak Arakelyan  *			0 - No
3806f80b6deSSevak Arakelyan  *			1 - Yes
3816f80b6deSSevak Arakelyan  * @hird_threshold:	Value of BESL or HIRD Threshold.
382f3a61e4eSGrigor Tovmasyan  * @ref_clk_per:        Indicates in terms of pico seconds the period
383f3a61e4eSGrigor Tovmasyan  *                      of ref_clk.
384f3a61e4eSGrigor Tovmasyan  *			62500 - 16MHz
385f3a61e4eSGrigor Tovmasyan  *                      58823 - 17MHz
386f3a61e4eSGrigor Tovmasyan  *                      52083 - 19.2MHz
387f3a61e4eSGrigor Tovmasyan  *			50000 - 20MHz
388f3a61e4eSGrigor Tovmasyan  *			41666 - 24MHz
389f3a61e4eSGrigor Tovmasyan  *			33333 - 30MHz (default)
390f3a61e4eSGrigor Tovmasyan  *			25000 - 40MHz
391f3a61e4eSGrigor Tovmasyan  * @sof_cnt_wkup_alert: Indicates in term of number of SOF's after which
392f3a61e4eSGrigor Tovmasyan  *                      the controller should generate an interrupt if the
393f3a61e4eSGrigor Tovmasyan  *                      device had been in L1 state until that period.
394f3a61e4eSGrigor Tovmasyan  *                      This is used by SW to initiate Remote WakeUp in the
395f3a61e4eSGrigor Tovmasyan  *                      controller so as to sync to the uF number from the host.
396e35b1350SBruno Herrera  * @activate_stm_fs_transceiver: Activate internal transceiver using GGPIO
397e35b1350SBruno Herrera  *			register.
398e35b1350SBruno Herrera  *			0 - Deactivate the transceiver (default)
399e35b1350SBruno Herrera  *			1 - Activate the transceiver
400a415083aSAmelie Delaunay  * @activate_stm_id_vb_detection: Activate external ID pin and Vbus level
401a415083aSAmelie Delaunay  *			detection using GGPIO register.
402a415083aSAmelie Delaunay  *			0 - Deactivate the external level detection (default)
403a415083aSAmelie Delaunay  *			1 - Activate the external level detection
404d712b725S周琰杰 (Zhou Yanjie)  * @activate_ingenic_overcurrent_detection: Activate Ingenic overcurrent
405d712b725S周琰杰 (Zhou Yanjie)  *			detection.
406d712b725S周琰杰 (Zhou Yanjie)  *			0 - Deactivate the overcurrent detection
407d712b725S周琰杰 (Zhou Yanjie)  *			1 - Activate the overcurrent detection (default)
4089962b62fSJohn Youn  * @g_dma:              Enables gadget dma usage (default: autodetect).
409dec4b556SVahram Aharonyan  * @g_dma_desc:         Enables gadget descriptor DMA (default: autodetect).
41005ee799fSJohn Youn  * @g_rx_fifo_size:	The periodic rx fifo size for the device, in
41105ee799fSJohn Youn  *			DWORDS from 16-32768 (default: 2048 if
41205ee799fSJohn Youn  *			possible, otherwise autodetect).
41305ee799fSJohn Youn  * @g_np_tx_fifo_size:	The non-periodic tx fifo size for the device in
41405ee799fSJohn Youn  *			DWORDS from 16-32768 (default: 1024 if
41505ee799fSJohn Youn  *			possible, otherwise autodetect).
41605ee799fSJohn Youn  * @g_tx_fifo_size:	An array of TX fifo sizes in dedicated fifo
41705ee799fSJohn Youn  *			mode. Each value corresponds to one EP
41805ee799fSJohn Youn  *			starting from EP1 (max 15 values). Sizes are
419f8590006STian Tao  *			in DWORDS with possible values from
42005ee799fSJohn Youn  *			16-32768 (default: 256, 256, 256, 256, 768,
42105ee799fSJohn Youn  *			768, 768, 768, 0, 0, 0, 0, 0, 0, 0).
422ca8b0332SChen Yu  * @change_speed_quirk: Change speed configuration to DWC2_SPEED_PARAM_FULL
423ca8b0332SChen Yu  *                      while full&low speed device connect. And change speed
424ca8b0332SChen Yu  *                      back to DWC2_SPEED_PARAM_HIGH while device is gone.
425ca8b0332SChen Yu  *			0 - No (default)
426ca8b0332SChen Yu  *			1 - Yes
427ca531bc2SGrigor Tovmasyan  * @service_interval:   Enable service interval based scheduling.
428ca531bc2SGrigor Tovmasyan  *                      0 - No
429ca531bc2SGrigor Tovmasyan  *                      1 - Yes
430197ba5f4SPaul Zimmerman  *
431197ba5f4SPaul Zimmerman  * The following parameters may be specified when starting the module. These
432197ba5f4SPaul Zimmerman  * parameters define how the DWC_otg controller should be configured. A
433197ba5f4SPaul Zimmerman  * value of -1 (or any other out of range value) for any parameter means
434197ba5f4SPaul Zimmerman  * to read the value from hardware (if possible) or use the builtin
435197ba5f4SPaul Zimmerman  * default described above.
436197ba5f4SPaul Zimmerman  */
437197ba5f4SPaul Zimmerman struct dwc2_core_params {
438f5c8a6cbSFabrice Gasnier 	struct usb_otg_caps otg_caps;
439d21bcc3fSJohn Youn 	u8 phy_type;
440c1d286cfSJohn Youn #define DWC2_PHY_TYPE_PARAM_FS		0
441c1d286cfSJohn Youn #define DWC2_PHY_TYPE_PARAM_UTMI	1
442c1d286cfSJohn Youn #define DWC2_PHY_TYPE_PARAM_ULPI	2
443c1d286cfSJohn Youn 
44457b8e235SJohn Youn 	u8 speed;
44557b8e235SJohn Youn #define DWC2_SPEED_PARAM_HIGH	0
44657b8e235SJohn Youn #define DWC2_SPEED_PARAM_FULL	1
44757b8e235SJohn Youn #define DWC2_SPEED_PARAM_LOW	2
44857b8e235SJohn Youn 
449d21bcc3fSJohn Youn 	u8 phy_utmi_width;
450*bc5d81b8SMinas Harutyunyan 	bool eusb2_disc;
451d21bcc3fSJohn Youn 	bool phy_ulpi_ddr;
452d21bcc3fSJohn Youn 	bool phy_ulpi_ext_vbus;
45357b8e235SJohn Youn 	bool enable_dynamic_fifo;
45457b8e235SJohn Youn 	bool en_multiple_tx_fifo;
455d21bcc3fSJohn Youn 	bool i2c_enable;
45666e77a24SRazmik Karapetyan 	bool acg_enable;
457d21bcc3fSJohn Youn 	bool ulpi_fs_ls;
45857b8e235SJohn Youn 	bool ts_dline;
45957b8e235SJohn Youn 	bool reload_ctl;
46057b8e235SJohn Youn 	bool uframe_sched;
46157b8e235SJohn Youn 	bool external_id_pin_ctl;
462631a2310SVardan Mikayelyan 
463631a2310SVardan Mikayelyan 	int power_down;
464631a2310SVardan Mikayelyan #define DWC2_POWER_DOWN_PARAM_NONE		0
465631a2310SVardan Mikayelyan #define DWC2_POWER_DOWN_PARAM_PARTIAL		1
466631a2310SVardan Mikayelyan #define DWC2_POWER_DOWN_PARAM_HIBERNATION	2
467c4a0f7a6SMarek Szyprowski 	bool no_clock_gating;
468631a2310SVardan Mikayelyan 
4696f80b6deSSevak Arakelyan 	bool lpm;
4706f80b6deSSevak Arakelyan 	bool lpm_clock_gating;
4716f80b6deSSevak Arakelyan 	bool besl;
4726f80b6deSSevak Arakelyan 	bool hird_threshold_en;
473ca531bc2SGrigor Tovmasyan 	bool service_interval;
4746f80b6deSSevak Arakelyan 	u8 hird_threshold;
475e35b1350SBruno Herrera 	bool activate_stm_fs_transceiver;
476a415083aSAmelie Delaunay 	bool activate_stm_id_vb_detection;
477d712b725S周琰杰 (Zhou Yanjie) 	bool activate_ingenic_overcurrent_detection;
478b43ebc96SGrigor Tovmasyan 	bool ipg_isoc_en;
47957b8e235SJohn Youn 	u16 max_packet_count;
48057b8e235SJohn Youn 	u32 max_transfer_size;
48157b8e235SJohn Youn 	u32 ahbcfg;
48257b8e235SJohn Youn 
483f3a61e4eSGrigor Tovmasyan 	/* GREFCLK parameters */
484f3a61e4eSGrigor Tovmasyan 	u32 ref_clk_per;
485f3a61e4eSGrigor Tovmasyan 	u16 sof_cnt_wkup_alert;
486f3a61e4eSGrigor Tovmasyan 
48757b8e235SJohn Youn 	/* Host parameters */
48857b8e235SJohn Youn 	bool host_dma;
48957b8e235SJohn Youn 	bool dma_desc_enable;
49057b8e235SJohn Youn 	bool dma_desc_fs_enable;
491d21bcc3fSJohn Youn 	bool host_support_fs_ls_low_power;
492d21bcc3fSJohn Youn 	bool host_ls_low_power_phy_clk;
493b11633c4SDinh Nguyen 	bool oc_disable;
494c1d286cfSJohn Youn 
49557b8e235SJohn Youn 	u8 host_channels;
49657b8e235SJohn Youn 	u16 host_rx_fifo_size;
49757b8e235SJohn Youn 	u16 host_nperio_tx_fifo_size;
49857b8e235SJohn Youn 	u16 host_perio_tx_fifo_size;
4996b66ce51SJohn Youn 
5006b66ce51SJohn Youn 	/* Gadget parameters */
50105ee799fSJohn Youn 	bool g_dma;
502dec4b556SVahram Aharonyan 	bool g_dma_desc;
50300c704ccSLeo Yan 	u32 g_rx_fifo_size;
50400c704ccSLeo Yan 	u32 g_np_tx_fifo_size;
50505ee799fSJohn Youn 	u32 g_tx_fifo_size[MAX_EPS_CHANNELS];
506ca8b0332SChen Yu 
507ca8b0332SChen Yu 	bool change_speed_quirk;
508197ba5f4SPaul Zimmerman };
509197ba5f4SPaul Zimmerman 
510197ba5f4SPaul Zimmerman /**
511197ba5f4SPaul Zimmerman  * struct dwc2_hw_params - Autodetected parameters.
512197ba5f4SPaul Zimmerman  *
513197ba5f4SPaul Zimmerman  * These parameters are the various parameters read from hardware
514197ba5f4SPaul Zimmerman  * registers during initialization. They typically contain the best
515197ba5f4SPaul Zimmerman  * supported or maximum value that can be configured in the
516197ba5f4SPaul Zimmerman  * corresponding dwc2_core_params value.
517197ba5f4SPaul Zimmerman  *
518197ba5f4SPaul Zimmerman  * The values that are not in dwc2_core_params are documented below.
519197ba5f4SPaul Zimmerman  *
5206fb914d7SGrigor Tovmasyan  * @op_mode:             Mode of Operation
521197ba5f4SPaul Zimmerman  *                       0 - HNP- and SRP-Capable OTG (Host & Device)
522197ba5f4SPaul Zimmerman  *                       1 - SRP-Capable OTG (Host & Device)
523197ba5f4SPaul Zimmerman  *                       2 - Non-HNP and Non-SRP Capable OTG (Host & Device)
524197ba5f4SPaul Zimmerman  *                       3 - SRP-Capable Device
525197ba5f4SPaul Zimmerman  *                       4 - Non-OTG Device
526197ba5f4SPaul Zimmerman  *                       5 - SRP-Capable Host
527197ba5f4SPaul Zimmerman  *                       6 - Non-OTG Host
5286fb914d7SGrigor Tovmasyan  * @arch:                Architecture
529197ba5f4SPaul Zimmerman  *                       0 - Slave only
530197ba5f4SPaul Zimmerman  *                       1 - External DMA
531197ba5f4SPaul Zimmerman  *                       2 - Internal DMA
5326fb914d7SGrigor Tovmasyan  * @ipg_isoc_en:        This feature indicates that the controller supports
533b43ebc96SGrigor Tovmasyan  *                      the worst-case scenario of Rx followed by Rx
534b43ebc96SGrigor Tovmasyan  *                      Interpacket Gap (IPG) (32 bitTimes) as per the utmi
535b43ebc96SGrigor Tovmasyan  *                      specification for any token following ISOC OUT token.
536b43ebc96SGrigor Tovmasyan  *                       0 - Don't support
537b43ebc96SGrigor Tovmasyan  *                       1 - Support
5386fb914d7SGrigor Tovmasyan  * @power_optimized:    Are power optimizations enabled?
5396fb914d7SGrigor Tovmasyan  * @num_dev_ep:         Number of device endpoints available
5406fb914d7SGrigor Tovmasyan  * @num_dev_in_eps:     Number of device IN endpoints available
5416fb914d7SGrigor Tovmasyan  * @num_dev_perio_in_ep: Number of device periodic IN endpoints
542997f4f81SMickael Maison  *                       available
5436fb914d7SGrigor Tovmasyan  * @dev_token_q_depth:  Device Mode IN Token Sequence Learning Queue
544197ba5f4SPaul Zimmerman  *                      Depth
545197ba5f4SPaul Zimmerman  *                       0 to 30
5466fb914d7SGrigor Tovmasyan  * @host_perio_tx_q_depth:
547197ba5f4SPaul Zimmerman  *                      Host Mode Periodic Request Queue Depth
548197ba5f4SPaul Zimmerman  *                       2, 4 or 8
5496fb914d7SGrigor Tovmasyan  * @nperio_tx_q_depth:
550197ba5f4SPaul Zimmerman  *                      Non-Periodic Request Queue Depth
551197ba5f4SPaul Zimmerman  *                       2, 4 or 8
5526fb914d7SGrigor Tovmasyan  * @hs_phy_type:         High-speed PHY interface type
553197ba5f4SPaul Zimmerman  *                       0 - High-speed interface not supported
554197ba5f4SPaul Zimmerman  *                       1 - UTMI+
555197ba5f4SPaul Zimmerman  *                       2 - ULPI
556197ba5f4SPaul Zimmerman  *                       3 - UTMI+ and ULPI
5576fb914d7SGrigor Tovmasyan  * @fs_phy_type:         Full-speed PHY interface type
558197ba5f4SPaul Zimmerman  *                       0 - Full speed interface not supported
559197ba5f4SPaul Zimmerman  *                       1 - Dedicated full speed interface
560197ba5f4SPaul Zimmerman  *                       2 - FS pins shared with UTMI+ pins
561197ba5f4SPaul Zimmerman  *                       3 - FS pins shared with ULPI pins
562197ba5f4SPaul Zimmerman  * @total_fifo_size:    Total internal RAM for FIFOs (bytes)
5636fb914d7SGrigor Tovmasyan  * @hibernation:	Is hibernation enabled?
5646fb914d7SGrigor Tovmasyan  * @utmi_phy_data_width: UTMI+ PHY data width
565197ba5f4SPaul Zimmerman  *                       0 - 8 bits
566197ba5f4SPaul Zimmerman  *                       1 - 16 bits
567197ba5f4SPaul Zimmerman  *                       2 - 8 or 16 bits
568197ba5f4SPaul Zimmerman  * @snpsid:             Value from SNPSID register
56955e1040eSJohn Youn  * @dev_ep_dirs:        Direction of device endpoints (GHWCFG1)
5706fb914d7SGrigor Tovmasyan  * @g_tx_fifo_size:	Power-on values of TxFIFO sizes
5716fb914d7SGrigor Tovmasyan  * @dma_desc_enable:    When DMA mode is enabled, specifies whether to use
5726fb914d7SGrigor Tovmasyan  *                      address DMA mode or descriptor DMA mode for accessing
5736fb914d7SGrigor Tovmasyan  *                      the data FIFOs. The driver will automatically detect the
5746fb914d7SGrigor Tovmasyan  *                      value for this if none is specified.
5756fb914d7SGrigor Tovmasyan  *                       0 - Address DMA
5766fb914d7SGrigor Tovmasyan  *                       1 - Descriptor DMA (default, if available)
5776fb914d7SGrigor Tovmasyan  * @enable_dynamic_fifo: 0 - Use coreConsultant-specified FIFO size parameters
5786fb914d7SGrigor Tovmasyan  *                       1 - Allow dynamic FIFO sizing (default, if available)
5796fb914d7SGrigor Tovmasyan  * @en_multiple_tx_fifo: Specifies whether dedicated per-endpoint transmit FIFOs
5806fb914d7SGrigor Tovmasyan  *                      are enabled for non-periodic IN endpoints in device
5816fb914d7SGrigor Tovmasyan  *                      mode.
5826fb914d7SGrigor Tovmasyan  * @host_nperio_tx_fifo_size: Number of 4-byte words in the non-periodic Tx FIFO
5836fb914d7SGrigor Tovmasyan  *                      in host mode when dynamic FIFO sizing is enabled
5846fb914d7SGrigor Tovmasyan  *                       16 to 32768
5856fb914d7SGrigor Tovmasyan  *                      Actual maximum value is autodetected and also
5866fb914d7SGrigor Tovmasyan  *                      the default.
5876fb914d7SGrigor Tovmasyan  * @host_perio_tx_fifo_size: Number of 4-byte words in the periodic Tx FIFO in
5886fb914d7SGrigor Tovmasyan  *                      host mode when dynamic FIFO sizing is enabled
5896fb914d7SGrigor Tovmasyan  *                       16 to 32768
5906fb914d7SGrigor Tovmasyan  *                      Actual maximum value is autodetected and also
5916fb914d7SGrigor Tovmasyan  *                      the default.
5926fb914d7SGrigor Tovmasyan  * @max_transfer_size:  The maximum transfer size supported, in bytes
5936fb914d7SGrigor Tovmasyan  *                       2047 to 65,535
5946fb914d7SGrigor Tovmasyan  *                      Actual maximum value is autodetected and also
5956fb914d7SGrigor Tovmasyan  *                      the default.
5966fb914d7SGrigor Tovmasyan  * @max_packet_count:   The maximum number of packets in a transfer
5976fb914d7SGrigor Tovmasyan  *                       15 to 511
5986fb914d7SGrigor Tovmasyan  *                      Actual maximum value is autodetected and also
5996fb914d7SGrigor Tovmasyan  *                      the default.
6006fb914d7SGrigor Tovmasyan  * @host_channels:      The number of host channel registers to use
6016fb914d7SGrigor Tovmasyan  *                       1 to 16
6026fb914d7SGrigor Tovmasyan  *                      Actual maximum value is autodetected and also
6036fb914d7SGrigor Tovmasyan  *                      the default.
6046fb914d7SGrigor Tovmasyan  * @dev_nperio_tx_fifo_size: Number of 4-byte words in the non-periodic Tx FIFO
6056fb914d7SGrigor Tovmasyan  *			     in device mode when dynamic FIFO sizing is enabled
6066fb914d7SGrigor Tovmasyan  *			     16 to 32768
6076fb914d7SGrigor Tovmasyan  *			     Actual maximum value is autodetected and also
6086fb914d7SGrigor Tovmasyan  *			     the default.
6096fb914d7SGrigor Tovmasyan  * @i2c_enable:         Specifies whether to use the I2Cinterface for a full
6106fb914d7SGrigor Tovmasyan  *                      speed PHY. This parameter is only applicable if phy_type
6116fb914d7SGrigor Tovmasyan  *                      is FS.
6126fb914d7SGrigor Tovmasyan  *                       0 - No (default)
6136fb914d7SGrigor Tovmasyan  *                       1 - Yes
6146fb914d7SGrigor Tovmasyan  * @acg_enable:		For enabling Active Clock Gating in the controller
6156fb914d7SGrigor Tovmasyan  *                       0 - Disable
6166fb914d7SGrigor Tovmasyan  *                       1 - Enable
6176fb914d7SGrigor Tovmasyan  * @lpm_mode:		For enabling Link Power Management in the controller
6186fb914d7SGrigor Tovmasyan  *                       0 - Disable
6196fb914d7SGrigor Tovmasyan  *                       1 - Enable
6206fb914d7SGrigor Tovmasyan  * @rx_fifo_size:	Number of 4-byte words in the  Rx FIFO when dynamic
6216fb914d7SGrigor Tovmasyan  *			FIFO sizing is enabled 16 to 32768
6226fb914d7SGrigor Tovmasyan  *			Actual maximum value is autodetected and also
6236fb914d7SGrigor Tovmasyan  *			the default.
624ca531bc2SGrigor Tovmasyan  * @service_interval_mode: For enabling service interval based scheduling in the
625ca531bc2SGrigor Tovmasyan  *                         controller.
626ca531bc2SGrigor Tovmasyan  *                           0 - Disable
627ca531bc2SGrigor Tovmasyan  *                           1 - Enable
628197ba5f4SPaul Zimmerman  */
629197ba5f4SPaul Zimmerman struct dwc2_hw_params {
630197ba5f4SPaul Zimmerman 	unsigned op_mode:3;
631197ba5f4SPaul Zimmerman 	unsigned arch:2;
632197ba5f4SPaul Zimmerman 	unsigned dma_desc_enable:1;
633197ba5f4SPaul Zimmerman 	unsigned enable_dynamic_fifo:1;
634197ba5f4SPaul Zimmerman 	unsigned en_multiple_tx_fifo:1;
635d1531319SJohn Youn 	unsigned rx_fifo_size:16;
636197ba5f4SPaul Zimmerman 	unsigned host_nperio_tx_fifo_size:16;
63755e1040eSJohn Youn 	unsigned dev_nperio_tx_fifo_size:16;
638197ba5f4SPaul Zimmerman 	unsigned host_perio_tx_fifo_size:16;
639197ba5f4SPaul Zimmerman 	unsigned nperio_tx_q_depth:3;
640197ba5f4SPaul Zimmerman 	unsigned host_perio_tx_q_depth:3;
641197ba5f4SPaul Zimmerman 	unsigned dev_token_q_depth:5;
642197ba5f4SPaul Zimmerman 	unsigned max_transfer_size:26;
643197ba5f4SPaul Zimmerman 	unsigned max_packet_count:11;
644197ba5f4SPaul Zimmerman 	unsigned host_channels:5;
645197ba5f4SPaul Zimmerman 	unsigned hs_phy_type:2;
646197ba5f4SPaul Zimmerman 	unsigned fs_phy_type:2;
647197ba5f4SPaul Zimmerman 	unsigned i2c_enable:1;
64866e77a24SRazmik Karapetyan 	unsigned acg_enable:1;
649197ba5f4SPaul Zimmerman 	unsigned num_dev_ep:4;
6509273083aSMinas Harutyunyan 	unsigned num_dev_in_eps : 4;
651197ba5f4SPaul Zimmerman 	unsigned num_dev_perio_in_ep:4;
652197ba5f4SPaul Zimmerman 	unsigned total_fifo_size:16;
653197ba5f4SPaul Zimmerman 	unsigned power_optimized:1;
654631a2310SVardan Mikayelyan 	unsigned hibernation:1;
655197ba5f4SPaul Zimmerman 	unsigned utmi_phy_data_width:2;
6566f80b6deSSevak Arakelyan 	unsigned lpm_mode:1;
657b43ebc96SGrigor Tovmasyan 	unsigned ipg_isoc_en:1;
658ca531bc2SGrigor Tovmasyan 	unsigned service_interval_mode:1;
659197ba5f4SPaul Zimmerman 	u32 snpsid;
66055e1040eSJohn Youn 	u32 dev_ep_dirs;
6619273083aSMinas Harutyunyan 	u32 g_tx_fifo_size[MAX_EPS_CHANNELS];
662197ba5f4SPaul Zimmerman };
663197ba5f4SPaul Zimmerman 
6643f95001dSMian Yousaf Kaukab /* Size of control and EP0 buffers */
6653f95001dSMian Yousaf Kaukab #define DWC2_CTRL_BUFF_SIZE 8
6663f95001dSMian Yousaf Kaukab 
667197ba5f4SPaul Zimmerman /**
66838beaec6SJohn Youn  * struct dwc2_gregs_backup - Holds global registers state before
66938beaec6SJohn Youn  * entering partial power down
670d17ee77bSGregory Herrero  * @gotgctl:		Backup of GOTGCTL register
671d17ee77bSGregory Herrero  * @gintmsk:		Backup of GINTMSK register
672d17ee77bSGregory Herrero  * @gahbcfg:		Backup of GAHBCFG register
673d17ee77bSGregory Herrero  * @gusbcfg:		Backup of GUSBCFG register
674d17ee77bSGregory Herrero  * @grxfsiz:		Backup of GRXFSIZ register
675d17ee77bSGregory Herrero  * @gnptxfsiz:		Backup of GNPTXFSIZ register
676d17ee77bSGregory Herrero  * @gi2cctl:		Backup of GI2CCTL register
67766a36096SVardan Mikayelyan  * @glpmcfg:		Backup of GLPMCFG register
678d17ee77bSGregory Herrero  * @gdfifocfg:		Backup of GDFIFOCFG register
6796fb914d7SGrigor Tovmasyan  * @pcgcctl:		Backup of PCGCCTL register
6806fb914d7SGrigor Tovmasyan  * @pcgcctl1:		Backup of PCGCCTL1 register
6816fb914d7SGrigor Tovmasyan  * @dtxfsiz:		Backup of DTXFSIZ registers for each endpoint
682d17ee77bSGregory Herrero  * @gpwrdn:		Backup of GPWRDN register
6836fb914d7SGrigor Tovmasyan  * @valid:		True if registers values backuped.
684d17ee77bSGregory Herrero  */
685d17ee77bSGregory Herrero struct dwc2_gregs_backup {
686d17ee77bSGregory Herrero 	u32 gotgctl;
687d17ee77bSGregory Herrero 	u32 gintmsk;
688d17ee77bSGregory Herrero 	u32 gahbcfg;
689d17ee77bSGregory Herrero 	u32 gusbcfg;
690d17ee77bSGregory Herrero 	u32 grxfsiz;
691d17ee77bSGregory Herrero 	u32 gnptxfsiz;
692d17ee77bSGregory Herrero 	u32 gi2cctl;
69366a36096SVardan Mikayelyan 	u32 glpmcfg;
694d17ee77bSGregory Herrero 	u32 pcgcctl;
695600a490eSRazmik Karapetyan 	u32 pcgcctl1;
696d17ee77bSGregory Herrero 	u32 gdfifocfg;
697d17ee77bSGregory Herrero 	u32 gpwrdn;
698cc1e204cSMian Yousaf Kaukab 	bool valid;
699d17ee77bSGregory Herrero };
700d17ee77bSGregory Herrero 
701d17ee77bSGregory Herrero /**
70238beaec6SJohn Youn  * struct dwc2_dregs_backup - Holds device registers state before
70338beaec6SJohn Youn  * entering partial power down
704d17ee77bSGregory Herrero  * @dcfg:		Backup of DCFG register
705d17ee77bSGregory Herrero  * @dctl:		Backup of DCTL register
706d17ee77bSGregory Herrero  * @daintmsk:		Backup of DAINTMSK register
707d17ee77bSGregory Herrero  * @diepmsk:		Backup of DIEPMSK register
708d17ee77bSGregory Herrero  * @doepmsk:		Backup of DOEPMSK register
709d17ee77bSGregory Herrero  * @diepctl:		Backup of DIEPCTL register
710d17ee77bSGregory Herrero  * @dieptsiz:		Backup of DIEPTSIZ register
711d17ee77bSGregory Herrero  * @diepdma:		Backup of DIEPDMA register
712d17ee77bSGregory Herrero  * @doepctl:		Backup of DOEPCTL register
713d17ee77bSGregory Herrero  * @doeptsiz:		Backup of DOEPTSIZ register
714d17ee77bSGregory Herrero  * @doepdma:		Backup of DOEPDMA register
715af7c2bd3SVardan Mikayelyan  * @dtxfsiz:		Backup of DTXFSIZ registers for each endpoint
7166fb914d7SGrigor Tovmasyan  * @valid:      True if registers values backuped.
717d17ee77bSGregory Herrero  */
718d17ee77bSGregory Herrero struct dwc2_dregs_backup {
719d17ee77bSGregory Herrero 	u32 dcfg;
720d17ee77bSGregory Herrero 	u32 dctl;
721d17ee77bSGregory Herrero 	u32 daintmsk;
722d17ee77bSGregory Herrero 	u32 diepmsk;
723d17ee77bSGregory Herrero 	u32 doepmsk;
724d17ee77bSGregory Herrero 	u32 diepctl[MAX_EPS_CHANNELS];
725d17ee77bSGregory Herrero 	u32 dieptsiz[MAX_EPS_CHANNELS];
726d17ee77bSGregory Herrero 	u32 diepdma[MAX_EPS_CHANNELS];
727d17ee77bSGregory Herrero 	u32 doepctl[MAX_EPS_CHANNELS];
728d17ee77bSGregory Herrero 	u32 doeptsiz[MAX_EPS_CHANNELS];
729d17ee77bSGregory Herrero 	u32 doepdma[MAX_EPS_CHANNELS];
730af7c2bd3SVardan Mikayelyan 	u32 dtxfsiz[MAX_EPS_CHANNELS];
731cc1e204cSMian Yousaf Kaukab 	bool valid;
732d17ee77bSGregory Herrero };
733d17ee77bSGregory Herrero 
734d17ee77bSGregory Herrero /**
73538beaec6SJohn Youn  * struct dwc2_hregs_backup - Holds host registers state before
73638beaec6SJohn Youn  * entering partial power down
737d17ee77bSGregory Herrero  * @hcfg:		Backup of HCFG register
7383c7b9856SMinas Harutyunyan  * @hflbaddr:		Backup of HFLBADDR register
739d17ee77bSGregory Herrero  * @haintmsk:		Backup of HAINTMSK register
7403c7b9856SMinas Harutyunyan  * @hcchar:		Backup of HCCHAR register
7413c7b9856SMinas Harutyunyan  * @hcsplt:		Backup of HCSPLT register
742d17ee77bSGregory Herrero  * @hcintmsk:		Backup of HCINTMSK register
7433c7b9856SMinas Harutyunyan  * @hctsiz:		Backup of HCTSIZ register
7443c7b9856SMinas Harutyunyan  * @hdma:		Backup of HCDMA register
7453c7b9856SMinas Harutyunyan  * @hcdmab:		Backup of HCDMAB 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;
7533c7b9856SMinas Harutyunyan 	u32 hflbaddr;
754d17ee77bSGregory Herrero 	u32 haintmsk;
7553c7b9856SMinas Harutyunyan 	u32 hcchar[MAX_EPS_CHANNELS];
7563c7b9856SMinas Harutyunyan 	u32 hcsplt[MAX_EPS_CHANNELS];
757d17ee77bSGregory Herrero 	u32 hcintmsk[MAX_EPS_CHANNELS];
7583c7b9856SMinas Harutyunyan 	u32 hctsiz[MAX_EPS_CHANNELS];
7593c7b9856SMinas Harutyunyan 	u32 hcidma[MAX_EPS_CHANNELS];
7603c7b9856SMinas Harutyunyan 	u32 hcidmab[MAX_EPS_CHANNELS];
761d17ee77bSGregory Herrero 	u32 hprt0;
762d17ee77bSGregory Herrero 	u32 hfir;
76366a36096SVardan Mikayelyan 	u32 hptxfsiz;
764cc1e204cSMian Yousaf Kaukab 	bool valid;
765d17ee77bSGregory Herrero };
766d17ee77bSGregory Herrero 
7679f9f09b0SDouglas Anderson /*
7689f9f09b0SDouglas Anderson  * Constants related to high speed periodic scheduling
7699f9f09b0SDouglas Anderson  *
7709f9f09b0SDouglas Anderson  * We have a periodic schedule that is DWC2_HS_SCHEDULE_UFRAMES long.  From a
7719f9f09b0SDouglas Anderson  * reservation point of view it's assumed that the schedule goes right back to
7729f9f09b0SDouglas Anderson  * the beginning after the end of the schedule.
7739f9f09b0SDouglas Anderson  *
7749f9f09b0SDouglas Anderson  * What does that mean for scheduling things with a long interval?  It means
7759f9f09b0SDouglas Anderson  * we'll reserve time for them in every possible microframe that they could
7769f9f09b0SDouglas Anderson  * ever be scheduled in.  ...but we'll still only actually schedule them as
7779f9f09b0SDouglas Anderson  * often as they were requested.
7789f9f09b0SDouglas Anderson  *
7799f9f09b0SDouglas Anderson  * We keep our schedule in a "bitmap" structure.  This simplifies having
7809f9f09b0SDouglas Anderson  * to keep track of and merge intervals: we just let the bitmap code do most
7819f9f09b0SDouglas Anderson  * of the heavy lifting.  In a way scheduling is much like memory allocation.
7829f9f09b0SDouglas Anderson  *
7839f9f09b0SDouglas Anderson  * We schedule 100us per uframe or 80% of 125us (the maximum amount you're
7849f9f09b0SDouglas Anderson  * supposed to schedule for periodic transfers).  That's according to spec.
7859f9f09b0SDouglas Anderson  *
7869f9f09b0SDouglas Anderson  * Note that though we only schedule 80% of each microframe, the bitmap that we
7879f9f09b0SDouglas Anderson  * keep the schedule in is tightly packed (AKA it doesn't have 100us worth of
7889f9f09b0SDouglas Anderson  * space for each uFrame).
7899f9f09b0SDouglas Anderson  *
7909f9f09b0SDouglas Anderson  * Requirements:
7919f9f09b0SDouglas Anderson  * - DWC2_HS_SCHEDULE_UFRAMES must even divide 0x4000 (HFNUM_MAX_FRNUM + 1)
7929f9f09b0SDouglas Anderson  * - DWC2_HS_SCHEDULE_UFRAMES must be 8 times DWC2_LS_SCHEDULE_FRAMES (probably
7939f9f09b0SDouglas Anderson  *   could be any multiple of 8 times DWC2_LS_SCHEDULE_FRAMES, but there might
7949f9f09b0SDouglas Anderson  *   be bugs).  The 8 comes from the USB spec: number of microframes per frame.
7959f9f09b0SDouglas Anderson  */
7969f9f09b0SDouglas Anderson #define DWC2_US_PER_UFRAME		125
7979f9f09b0SDouglas Anderson #define DWC2_HS_PERIODIC_US_PER_UFRAME	100
7989f9f09b0SDouglas Anderson 
7999f9f09b0SDouglas Anderson #define DWC2_HS_SCHEDULE_UFRAMES	8
8009f9f09b0SDouglas Anderson #define DWC2_HS_SCHEDULE_US		(DWC2_HS_SCHEDULE_UFRAMES * \
8019f9f09b0SDouglas Anderson 					 DWC2_HS_PERIODIC_US_PER_UFRAME)
8029f9f09b0SDouglas Anderson 
8039f9f09b0SDouglas Anderson /*
8049f9f09b0SDouglas Anderson  * Constants related to low speed scheduling
8059f9f09b0SDouglas Anderson  *
8069f9f09b0SDouglas Anderson  * For high speed we schedule every 1us.  For low speed that's a bit overkill,
8079f9f09b0SDouglas Anderson  * so we make up a unit called a "slice" that's worth 25us.  There are 40
8089f9f09b0SDouglas Anderson  * slices in a full frame and we can schedule 36 of those (90%) for periodic
8099f9f09b0SDouglas Anderson  * transfers.
8109f9f09b0SDouglas Anderson  *
8119f9f09b0SDouglas Anderson  * Our low speed schedule can be as short as 1 frame or could be longer.  When
8129f9f09b0SDouglas Anderson  * we only schedule 1 frame it means that we'll need to reserve a time every
8139f9f09b0SDouglas Anderson  * frame even for things that only transfer very rarely, so something that runs
8149f9f09b0SDouglas Anderson  * every 2048 frames will get time reserved in every frame.  Our low speed
8159f9f09b0SDouglas Anderson  * schedule can be longer and we'll be able to handle more overlap, but that
8169f9f09b0SDouglas Anderson  * will come at increased memory cost and increased time to schedule.
8179f9f09b0SDouglas Anderson  *
8189f9f09b0SDouglas Anderson  * Note: one other advantage of a short low speed schedule is that if we mess
8199f9f09b0SDouglas Anderson  * up and miss scheduling we can jump in and use any of the slots that we
8209f9f09b0SDouglas Anderson  * happened to reserve.
8219f9f09b0SDouglas Anderson  *
8229f9f09b0SDouglas Anderson  * With 25 us per slice and 1 frame in the schedule, we only need 4 bytes for
8239f9f09b0SDouglas Anderson  * the schedule.  There will be one schedule per TT.
8249f9f09b0SDouglas Anderson  *
8259f9f09b0SDouglas Anderson  * Requirements:
8269f9f09b0SDouglas Anderson  * - DWC2_US_PER_SLICE must evenly divide DWC2_LS_PERIODIC_US_PER_FRAME.
8279f9f09b0SDouglas Anderson  */
8289f9f09b0SDouglas Anderson #define DWC2_US_PER_SLICE	25
8299f9f09b0SDouglas Anderson #define DWC2_SLICES_PER_UFRAME	(DWC2_US_PER_UFRAME / DWC2_US_PER_SLICE)
8309f9f09b0SDouglas Anderson 
8319f9f09b0SDouglas Anderson #define DWC2_ROUND_US_TO_SLICE(us) \
8329f9f09b0SDouglas Anderson 				(DIV_ROUND_UP((us), DWC2_US_PER_SLICE) * \
8339f9f09b0SDouglas Anderson 				 DWC2_US_PER_SLICE)
8349f9f09b0SDouglas Anderson 
8359f9f09b0SDouglas Anderson #define DWC2_LS_PERIODIC_US_PER_FRAME \
8369f9f09b0SDouglas Anderson 				900
8379f9f09b0SDouglas Anderson #define DWC2_LS_PERIODIC_SLICES_PER_FRAME \
8389f9f09b0SDouglas Anderson 				(DWC2_LS_PERIODIC_US_PER_FRAME / \
8399f9f09b0SDouglas Anderson 				 DWC2_US_PER_SLICE)
8409f9f09b0SDouglas Anderson 
8419f9f09b0SDouglas Anderson #define DWC2_LS_SCHEDULE_FRAMES	1
8429f9f09b0SDouglas Anderson #define DWC2_LS_SCHEDULE_SLICES	(DWC2_LS_SCHEDULE_FRAMES * \
8439f9f09b0SDouglas Anderson 				 DWC2_LS_PERIODIC_SLICES_PER_FRAME)
8449f9f09b0SDouglas Anderson 
845d17ee77bSGregory Herrero /**
846197ba5f4SPaul Zimmerman  * struct dwc2_hsotg - Holds the state of the driver, including the non-periodic
847197ba5f4SPaul Zimmerman  * and periodic schedules
848197ba5f4SPaul Zimmerman  *
849941fcce4SDinh Nguyen  * These are common for both host and peripheral modes:
850941fcce4SDinh Nguyen  *
851197ba5f4SPaul Zimmerman  * @dev:                The struct device pointer
852197ba5f4SPaul Zimmerman  * @regs:		Pointer to controller regs
853197ba5f4SPaul Zimmerman  * @hw_params:          Parameters that were autodetected from the
854197ba5f4SPaul Zimmerman  *                      hardware registers
8556fb914d7SGrigor Tovmasyan  * @params:	Parameters that define how the core should be configured
856197ba5f4SPaul Zimmerman  * @op_state:           The operational State, during transitions (a_host=>
857197ba5f4SPaul Zimmerman  *                      a_peripheral and b_device=>b_host) this may not match
858197ba5f4SPaul Zimmerman  *                      the core, but allows the software to determine
859197ba5f4SPaul Zimmerman  *                      transitions
860c0155b9dSKever Yang  * @dr_mode:            Requested mode of operation, one of following:
861c0155b9dSKever Yang  *                      - USB_DR_MODE_PERIPHERAL
862c0155b9dSKever Yang  *                      - USB_DR_MODE_HOST
863c0155b9dSKever Yang  *                      - USB_DR_MODE_OTG
86417f93402SAmelie Delaunay  * @role_sw:		usb_role_switch handle
865e14acb87SFabrice Gasnier  * @role_sw_default_mode: default operation mode of controller while usb role
866e14acb87SFabrice Gasnier  *			is USB_ROLE_NONE
8676fb914d7SGrigor Tovmasyan  * @hcd_enabled:	Host mode sub-driver initialization indicator.
8686fb914d7SGrigor Tovmasyan  * @gadget_enabled:	Peripheral mode sub-driver initialization indicator.
8696fb914d7SGrigor Tovmasyan  * @ll_hw_enabled:	Status of low-level hardware resources.
87020fe4409SVardan Mikayelyan  * @hibernated:		True if core is hibernated
871be2b960eSArtur Petrosyan  * @in_ppd:		True if core is partial power down mode.
872012466fcSArtur Petrosyan  * @bus_suspended:	True if bus is suspended
873c40cf770SDouglas Anderson  * @reset_phy_on_wake:	Quirk saying that we should assert PHY reset on a
874c40cf770SDouglas Anderson  *			remote wakeup.
875c846b03fSDouglas Anderson  * @phy_off_for_suspend: Status of whether we turned the PHY off at suspend.
876c846b03fSDouglas Anderson  * @need_phy_for_wake:	Quirk saying that we should keep the PHY on at
877c846b03fSDouglas Anderson  *			suspend if we need USB to wake us up.
878c7c24e7aSArtur Petrosyan  * @frame_number:       Frame number read from the core. For both device
879c7c24e7aSArtur Petrosyan  *			and host modes. The value ranges are from 0
880c7c24e7aSArtur Petrosyan  *			to HFNUM_MAX_FRNUM.
88109a75e85SMarek Szyprowski  * @phy:                The otg phy transceiver structure for phy control.
88238beaec6SJohn Youn  * @uphy:               The otg phy transceiver structure for old USB phy
88338beaec6SJohn Youn  *                      control.
88438beaec6SJohn Youn  * @plat:               The platform specific configuration data. This can be
88538beaec6SJohn Youn  *                      removed once all SoCs support usb transceiver.
88609a75e85SMarek Szyprowski  * @supplies:           Definition of USB power supplies
887531ef5ebSAmelie Delaunay  * @vbus_supply:        Regulator supplying vbus.
888a415083aSAmelie Delaunay  * @usb33d:		Optional 3.3v regulator used on some stm32 devices to
889a415083aSAmelie Delaunay  *			supply ID and VBUS detection hardware.
890941fcce4SDinh Nguyen  * @lock:		Spinlock that protects all the driver data structures
891941fcce4SDinh Nguyen  * @priv:		Stores a pointer to the struct usb_hcd
892197ba5f4SPaul Zimmerman  * @queuing_high_bandwidth: True if multiple packets of a high-bandwidth
893197ba5f4SPaul Zimmerman  *                      transfer are in process of being queued
894197ba5f4SPaul Zimmerman  * @srp_success:        Stores status of SRP request in the case of a FS PHY
895197ba5f4SPaul Zimmerman  *                      with an I2C interface
896197ba5f4SPaul Zimmerman  * @wq_otg:             Workqueue object used for handling of some interrupts
897197ba5f4SPaul Zimmerman  * @wf_otg:             Work object for handling Connector ID Status Change
898197ba5f4SPaul Zimmerman  *                      interrupt
899197ba5f4SPaul Zimmerman  * @wkp_timer:          Timer object for handling Wakeup Detected interrupt
900197ba5f4SPaul Zimmerman  * @lx_state:           Lx state of connected device
9016fb914d7SGrigor Tovmasyan  * @gr_backup: Backup of global registers during suspend
9026fb914d7SGrigor Tovmasyan  * @dr_backup: Backup of device registers during suspend
9036fb914d7SGrigor Tovmasyan  * @hr_backup: Backup of host registers during suspend
904fe369e18SGevorg Sahakyan  * @needs_byte_swap:		Specifies whether the opposite endianness.
905941fcce4SDinh Nguyen  *
906941fcce4SDinh Nguyen  * These are for host mode:
907941fcce4SDinh Nguyen  *
908197ba5f4SPaul Zimmerman  * @flags:              Flags for handling root port state changes
9096fb914d7SGrigor Tovmasyan  * @flags.d32:          Contain all root port flags
9106fb914d7SGrigor Tovmasyan  * @flags.b:            Separate root port flags from each other
9116fb914d7SGrigor Tovmasyan  * @flags.b.port_connect_status_change: True if root port connect status
9126fb914d7SGrigor Tovmasyan  *                      changed
9136fb914d7SGrigor Tovmasyan  * @flags.b.port_connect_status: True if device connected to root port
9146fb914d7SGrigor Tovmasyan  * @flags.b.port_reset_change: True if root port reset status changed
9156fb914d7SGrigor Tovmasyan  * @flags.b.port_enable_change: True if root port enable status changed
9166fb914d7SGrigor Tovmasyan  * @flags.b.port_suspend_change: True if root port suspend status changed
9176fb914d7SGrigor Tovmasyan  * @flags.b.port_over_current_change: True if root port over current state
9186fb914d7SGrigor Tovmasyan  *                       changed.
9196fb914d7SGrigor Tovmasyan  * @flags.b.port_l1_change: True if root port l1 status changed
9206fb914d7SGrigor Tovmasyan  * @flags.b.reserved:   Reserved bits of root port register
921197ba5f4SPaul Zimmerman  * @non_periodic_sched_inactive: Inactive QHs in the non-periodic schedule.
922197ba5f4SPaul Zimmerman  *                      Transfers associated with these QHs are not currently
923197ba5f4SPaul Zimmerman  *                      assigned to a host channel.
924197ba5f4SPaul Zimmerman  * @non_periodic_sched_active: Active QHs in the non-periodic schedule.
925197ba5f4SPaul Zimmerman  *                      Transfers associated with these QHs are currently
926197ba5f4SPaul Zimmerman  *                      assigned to a host channel.
927197ba5f4SPaul Zimmerman  * @non_periodic_qh_ptr: Pointer to next QH to process in the active
928197ba5f4SPaul Zimmerman  *                      non-periodic schedule
9296fb914d7SGrigor Tovmasyan  * @non_periodic_sched_waiting: Waiting QHs in the non-periodic schedule.
9306fb914d7SGrigor Tovmasyan  *                      Transfers associated with these QHs are not currently
9316fb914d7SGrigor Tovmasyan  *                      assigned to a host channel.
932197ba5f4SPaul Zimmerman  * @periodic_sched_inactive: Inactive QHs in the periodic schedule. This is a
933197ba5f4SPaul Zimmerman  *                      list of QHs for periodic transfers that are _not_
934197ba5f4SPaul Zimmerman  *                      scheduled for the next frame. Each QH in the list has an
935197ba5f4SPaul Zimmerman  *                      interval counter that determines when it needs to be
936197ba5f4SPaul Zimmerman  *                      scheduled for execution. This scheduling mechanism
937197ba5f4SPaul Zimmerman  *                      allows only a simple calculation for periodic bandwidth
938197ba5f4SPaul Zimmerman  *                      used (i.e. must assume that all periodic transfers may
939197ba5f4SPaul Zimmerman  *                      need to execute in the same frame). However, it greatly
940197ba5f4SPaul Zimmerman  *                      simplifies scheduling and should be sufficient for the
941197ba5f4SPaul Zimmerman  *                      vast majority of OTG hosts, which need to connect to a
942197ba5f4SPaul Zimmerman  *                      small number of peripherals at one time. Items move from
943197ba5f4SPaul Zimmerman  *                      this list to periodic_sched_ready when the QH interval
944197ba5f4SPaul Zimmerman  *                      counter is 0 at SOF.
945197ba5f4SPaul Zimmerman  * @periodic_sched_ready:  List of periodic QHs that are ready for execution in
946197ba5f4SPaul Zimmerman  *                      the next frame, but have not yet been assigned to host
947197ba5f4SPaul Zimmerman  *                      channels. Items move from this list to
948197ba5f4SPaul Zimmerman  *                      periodic_sched_assigned as host channels become
949197ba5f4SPaul Zimmerman  *                      available during the current frame.
950197ba5f4SPaul Zimmerman  * @periodic_sched_assigned: List of periodic QHs to be executed in the next
951197ba5f4SPaul Zimmerman  *                      frame that are assigned to host channels. Items move
952197ba5f4SPaul Zimmerman  *                      from this list to periodic_sched_queued as the
953197ba5f4SPaul Zimmerman  *                      transactions for the QH are queued to the DWC_otg
954197ba5f4SPaul Zimmerman  *                      controller.
955197ba5f4SPaul Zimmerman  * @periodic_sched_queued: List of periodic QHs that have been queued for
956197ba5f4SPaul Zimmerman  *                      execution. Items move from this list to either
957197ba5f4SPaul Zimmerman  *                      periodic_sched_inactive or periodic_sched_ready when the
958197ba5f4SPaul Zimmerman  *                      channel associated with the transfer is released. If the
959197ba5f4SPaul Zimmerman  *                      interval for the QH is 1, the item moves to
960197ba5f4SPaul Zimmerman  *                      periodic_sched_ready because it must be rescheduled for
961197ba5f4SPaul Zimmerman  *                      the next frame. Otherwise, the item moves to
962197ba5f4SPaul Zimmerman  *                      periodic_sched_inactive.
963c9c8ac01SDouglas Anderson  * @split_order:        List keeping track of channels doing splits, in order.
964197ba5f4SPaul Zimmerman  * @periodic_usecs:     Total bandwidth claimed so far for periodic transfers.
965197ba5f4SPaul Zimmerman  *                      This value is in microseconds per (micro)frame. The
966197ba5f4SPaul Zimmerman  *                      assumption is that all periodic transfers may occur in
967197ba5f4SPaul Zimmerman  *                      the same (micro)frame.
9689f9f09b0SDouglas Anderson  * @hs_periodic_bitmap: Bitmap used by the microframe scheduler any time the
9699f9f09b0SDouglas Anderson  *                      host is in high speed mode; low speed schedules are
9709f9f09b0SDouglas Anderson  *                      stored elsewhere since we need one per TT.
971197ba5f4SPaul Zimmerman  * @periodic_qh_count:  Count of periodic QHs, if using several eps. Used for
972197ba5f4SPaul Zimmerman  *                      SOF enable/disable.
973197ba5f4SPaul Zimmerman  * @free_hc_list:       Free host channels in the controller. This is a list of
974197ba5f4SPaul Zimmerman  *                      struct dwc2_host_chan items.
975197ba5f4SPaul Zimmerman  * @periodic_channels:  Number of host channels assigned to periodic transfers.
976197ba5f4SPaul Zimmerman  *                      Currently assuming that there is a dedicated host
977197ba5f4SPaul Zimmerman  *                      channel for each periodic transaction and at least one
978197ba5f4SPaul Zimmerman  *                      host channel is available for non-periodic transactions.
979197ba5f4SPaul Zimmerman  * @non_periodic_channels: Number of host channels assigned to non-periodic
980197ba5f4SPaul Zimmerman  *                      transfers
9816fb914d7SGrigor Tovmasyan  * @available_host_channels: Number of host channels available for the
9826fb914d7SGrigor Tovmasyan  *			     microframe scheduler to use
983197ba5f4SPaul Zimmerman  * @hc_ptr_array:       Array of pointers to the host channel descriptors.
984197ba5f4SPaul Zimmerman  *                      Allows accessing a host channel descriptor given the
985197ba5f4SPaul Zimmerman  *                      host channel number. This is useful in interrupt
986197ba5f4SPaul Zimmerman  *                      handlers.
987197ba5f4SPaul Zimmerman  * @status_buf:         Buffer used for data received during the status phase of
988197ba5f4SPaul Zimmerman  *                      a control transfer.
989197ba5f4SPaul Zimmerman  * @status_buf_dma:     DMA address for status_buf
990197ba5f4SPaul Zimmerman  * @start_work:         Delayed work for handling host A-cable connection
991197ba5f4SPaul Zimmerman  * @reset_work:         Delayed work for handling a port reset
992c40cf770SDouglas Anderson  * @phy_reset_work:     Work structure for doing a PHY reset
993197ba5f4SPaul Zimmerman  * @otg_port:           OTG port number
994197ba5f4SPaul Zimmerman  * @frame_list:         Frame list
995197ba5f4SPaul Zimmerman  * @frame_list_dma:     Frame list DMA address
99695105a99SGregory Herrero  * @frame_list_sz:      Frame list size
9973b5fcc9aSGregory Herrero  * @desc_gen_cache:     Kmem cache for generic descriptors
9983b5fcc9aSGregory Herrero  * @desc_hsisoc_cache:  Kmem cache for hs isochronous descriptors
999af424a41SWilliam Wu  * @unaligned_cache:    Kmem cache for DMA mode to handle non-aligned buf
1000941fcce4SDinh Nguyen  *
1001941fcce4SDinh Nguyen  * These are for peripheral mode:
1002941fcce4SDinh Nguyen  *
1003941fcce4SDinh Nguyen  * @driver:             USB gadget driver
1004941fcce4SDinh Nguyen  * @dedicated_fifos:    Set if the hardware has dedicated IN-EP fifos.
1005941fcce4SDinh Nguyen  * @num_of_eps:         Number of available EPs (excluding EP0)
1006941fcce4SDinh Nguyen  * @debug_root:         Root directrory for debugfs.
1007941fcce4SDinh Nguyen  * @ep0_reply:          Request used for ep0 reply.
1008941fcce4SDinh Nguyen  * @ep0_buff:           Buffer for EP0 reply data, if needed.
1009941fcce4SDinh Nguyen  * @ctrl_buff:          Buffer for EP0 control requests.
1010941fcce4SDinh Nguyen  * @ctrl_req:           Request for EP0 control packets.
1011fe0b94abSMian Yousaf Kaukab  * @ep0_state:          EP0 control transfers state
1012b4c53b4aSMinas Harutyunyan  * @delayed_status:		true when gadget driver asks for delayed status
10139e14d0a5SGregory Herrero  * @test_mode:          USB test mode requested by the host
1014fa389a6dSVardan Mikayelyan  * @remote_wakeup_allowed: True if device is allowed to wake-up host by
1015fa389a6dSVardan Mikayelyan  *                      remote-wakeup signalling
10160f6b80c0SVahram Aharonyan  * @setup_desc_dma:	EP0 setup stage desc chain DMA address
10170f6b80c0SVahram Aharonyan  * @setup_desc:		EP0 setup stage desc chain pointer
10180f6b80c0SVahram Aharonyan  * @ctrl_in_desc_dma:	EP0 IN data phase desc chain DMA address
10190f6b80c0SVahram Aharonyan  * @ctrl_in_desc:	EP0 IN data phase desc chain pointer
10200f6b80c0SVahram Aharonyan  * @ctrl_out_desc_dma:	EP0 OUT data phase desc chain DMA address
10210f6b80c0SVahram Aharonyan  * @ctrl_out_desc:	EP0 OUT data phase desc chain pointer
10226fb914d7SGrigor Tovmasyan  * @irq:		Interrupt request line number
10236fb914d7SGrigor Tovmasyan  * @clk:		Pointer to otg clock
102402329adeSFabrice Gasnier  * @utmi_clk:		Pointer to utmi_clk clock
10256fb914d7SGrigor Tovmasyan  * @reset:		Pointer to dwc2 reset controller
10266fb914d7SGrigor Tovmasyan  * @reset_ecc:          Pointer to dwc2 optional reset controller in Stratix10.
10276fb914d7SGrigor Tovmasyan  * @regset:		A pointer to a struct debugfs_regset32, which contains
10286fb914d7SGrigor Tovmasyan  *			a pointer to an array of register definitions, the
10296fb914d7SGrigor Tovmasyan  *			array size and the base address where the register bank
10306fb914d7SGrigor Tovmasyan  *			is to be found.
10316fb914d7SGrigor Tovmasyan  * @last_frame_num:	Number of last frame. Range from 0 to  32768
10326fb914d7SGrigor Tovmasyan  * @frame_num_array:    Used only  if CONFIG_USB_DWC2_TRACK_MISSED_SOFS is
10336fb914d7SGrigor Tovmasyan  *			defined, for missed SOFs tracking. Array holds that
10346fb914d7SGrigor Tovmasyan  *			frame numbers, which not equal to last_frame_num +1
10356fb914d7SGrigor Tovmasyan  * @last_frame_num_array:   Used only  if CONFIG_USB_DWC2_TRACK_MISSED_SOFS is
10366fb914d7SGrigor Tovmasyan  *			    defined, for missed SOFs tracking.
10376fb914d7SGrigor Tovmasyan  *			    If current_frame_number != last_frame_num+1
10386fb914d7SGrigor Tovmasyan  *			    then last_frame_num added to this array
10396fb914d7SGrigor Tovmasyan  * @frame_num_idx:	Actual size of frame_num_array and last_frame_num_array
10406fb914d7SGrigor Tovmasyan  * @dumped_frame_num_array:	1 - if missed SOFs frame numbers dumbed
10416fb914d7SGrigor Tovmasyan  *				0 - if missed SOFs frame numbers not dumbed
10426fb914d7SGrigor Tovmasyan  * @fifo_mem:			Total internal RAM for FIFOs (bytes)
10436fb914d7SGrigor Tovmasyan  * @fifo_map:		Each bit intend for concrete fifo. If that bit is set,
10446fb914d7SGrigor Tovmasyan  *			then that fifo is used
1045b9b70170SGreg Kroah-Hartman  * @gadget:		Represents a usb gadget device
10466fb914d7SGrigor Tovmasyan  * @connected:		Used in slave mode. True if device connected with host
10476fb914d7SGrigor Tovmasyan  * @eps_in:		The IN endpoints being supplied to the gadget framework
10486fb914d7SGrigor Tovmasyan  * @eps_out:		The OUT endpoints being supplied to the gadget framework
10496fb914d7SGrigor Tovmasyan  * @new_connection:	Used in host mode. True if there are new connected
10506fb914d7SGrigor Tovmasyan  *			device
10516fb914d7SGrigor Tovmasyan  * @enabled:		Indicates the enabling state of controller
10526fb914d7SGrigor Tovmasyan  *
1053197ba5f4SPaul Zimmerman  */
1054197ba5f4SPaul Zimmerman struct dwc2_hsotg {
1055197ba5f4SPaul Zimmerman 	struct device *dev;
1056197ba5f4SPaul Zimmerman 	void __iomem *regs;
1057197ba5f4SPaul Zimmerman 	/** Params detected from hardware */
1058197ba5f4SPaul Zimmerman 	struct dwc2_hw_params hw_params;
1059197ba5f4SPaul Zimmerman 	/** Params to actually use */
1060bea8e86cSJohn Youn 	struct dwc2_core_params params;
1061197ba5f4SPaul Zimmerman 	enum usb_otg_state op_state;
1062c0155b9dSKever Yang 	enum usb_dr_mode dr_mode;
106317f93402SAmelie Delaunay 	struct usb_role_switch *role_sw;
1064e14acb87SFabrice Gasnier 	enum usb_dr_mode role_sw_default_mode;
1065e39af88fSMarek Szyprowski 	unsigned int hcd_enabled:1;
1066e39af88fSMarek Szyprowski 	unsigned int gadget_enabled:1;
106709a75e85SMarek Szyprowski 	unsigned int ll_hw_enabled:1;
106820fe4409SVardan Mikayelyan 	unsigned int hibernated:1;
1069be2b960eSArtur Petrosyan 	unsigned int in_ppd:1;
1070012466fcSArtur Petrosyan 	bool bus_suspended;
1071c40cf770SDouglas Anderson 	unsigned int reset_phy_on_wake:1;
1072c846b03fSDouglas Anderson 	unsigned int need_phy_for_wake:1;
1073c846b03fSDouglas Anderson 	unsigned int phy_off_for_suspend:1;
1074c7c24e7aSArtur Petrosyan 	u16 frame_number;
1075197ba5f4SPaul Zimmerman 
1076941fcce4SDinh Nguyen 	struct phy *phy;
1077941fcce4SDinh Nguyen 	struct usb_phy *uphy;
107809a75e85SMarek Szyprowski 	struct dwc2_hsotg_plat *plat;
1079b98866c2SJohn Youn 	struct regulator_bulk_data supplies[DWC2_NUM_SUPPLIES];
1080531ef5ebSAmelie Delaunay 	struct regulator *vbus_supply;
1081a415083aSAmelie Delaunay 	struct regulator *usb33d;
1082941fcce4SDinh Nguyen 
1083941fcce4SDinh Nguyen 	spinlock_t lock;
1084941fcce4SDinh Nguyen 	void *priv;
1085941fcce4SDinh Nguyen 	int     irq;
1086941fcce4SDinh Nguyen 	struct clk *clk;
108702329adeSFabrice Gasnier 	struct clk *utmi_clk;
108883f8da56SDinh Nguyen 	struct reset_control *reset;
1089f2830ad4SDinh Nguyen 	struct reset_control *reset_ecc;
1090941fcce4SDinh Nguyen 
1091197ba5f4SPaul Zimmerman 	unsigned int queuing_high_bandwidth:1;
1092197ba5f4SPaul Zimmerman 	unsigned int srp_success:1;
1093197ba5f4SPaul Zimmerman 
1094197ba5f4SPaul Zimmerman 	struct workqueue_struct *wq_otg;
1095197ba5f4SPaul Zimmerman 	struct work_struct wf_otg;
1096197ba5f4SPaul Zimmerman 	struct timer_list wkp_timer;
1097197ba5f4SPaul Zimmerman 	enum dwc2_lx_state lx_state;
1098cc1e204cSMian Yousaf Kaukab 	struct dwc2_gregs_backup gr_backup;
1099cc1e204cSMian Yousaf Kaukab 	struct dwc2_dregs_backup dr_backup;
1100cc1e204cSMian Yousaf Kaukab 	struct dwc2_hregs_backup hr_backup;
1101197ba5f4SPaul Zimmerman 
1102941fcce4SDinh Nguyen 	struct dentry *debug_root;
1103563cf017SMian Yousaf Kaukab 	struct debugfs_regset32 *regset;
1104fe369e18SGevorg Sahakyan 	bool needs_byte_swap;
1105941fcce4SDinh Nguyen 
1106941fcce4SDinh Nguyen 	/* DWC OTG HW Release versions */
1107bae2bc73SMinas Harutyunyan #define DWC2_CORE_REV_4_30a	0x4f54430a
1108941fcce4SDinh Nguyen #define DWC2_CORE_REV_2_71a	0x4f54271a
11095295322aSArtur Petrosyan #define DWC2_CORE_REV_2_72a     0x4f54272a
11106f80b6deSSevak Arakelyan #define DWC2_CORE_REV_2_80a	0x4f54280a
1111941fcce4SDinh Nguyen #define DWC2_CORE_REV_2_90a	0x4f54290a
1112e1f411d1SSevak Arakelyan #define DWC2_CORE_REV_2_91a	0x4f54291a
1113941fcce4SDinh Nguyen #define DWC2_CORE_REV_2_92a	0x4f54292a
1114941fcce4SDinh Nguyen #define DWC2_CORE_REV_2_94a	0x4f54294a
1115941fcce4SDinh Nguyen #define DWC2_CORE_REV_3_00a	0x4f54300a
1116fef6bc37SJohn Youn #define DWC2_CORE_REV_3_10a	0x4f54310a
11175295322aSArtur Petrosyan #define DWC2_CORE_REV_4_00a	0x4f54400a
111865dc2e72SMinas Harutyunyan #define DWC2_CORE_REV_4_20a	0x4f54420a
1119799d9c27SMinas Harutyunyan #define DWC2_CORE_REV_5_00a	0x4f54500a
11201e6b98ebSVardan Mikayelyan #define DWC2_FS_IOT_REV_1_00a	0x5531100a
11211e6b98ebSVardan Mikayelyan #define DWC2_HS_IOT_REV_1_00a	0x5532100a
1122799d9c27SMinas Harutyunyan #define DWC2_HS_IOT_REV_5_00a	0x5532500a
112365dc2e72SMinas Harutyunyan #define DWC2_CORE_REV_MASK	0x0000ffff
1124941fcce4SDinh Nguyen 
1125d14ccabaSGevorg Sahakyan 	/* DWC OTG HW Core ID */
1126d14ccabaSGevorg Sahakyan #define DWC2_OTG_ID		0x4f540000
1127d14ccabaSGevorg Sahakyan #define DWC2_FS_IOT_ID		0x55310000
1128d14ccabaSGevorg Sahakyan #define DWC2_HS_IOT_ID		0x55320000
1129d14ccabaSGevorg Sahakyan 
1130941fcce4SDinh Nguyen #if IS_ENABLED(CONFIG_USB_DWC2_HOST) || IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE)
1131197ba5f4SPaul Zimmerman 	union dwc2_hcd_internal_flags {
1132197ba5f4SPaul Zimmerman 		u32 d32;
1133197ba5f4SPaul Zimmerman 		struct {
1134197ba5f4SPaul Zimmerman 			unsigned port_connect_status_change:1;
1135197ba5f4SPaul Zimmerman 			unsigned port_connect_status:1;
1136197ba5f4SPaul Zimmerman 			unsigned port_reset_change:1;
1137197ba5f4SPaul Zimmerman 			unsigned port_enable_change:1;
1138197ba5f4SPaul Zimmerman 			unsigned port_suspend_change:1;
1139197ba5f4SPaul Zimmerman 			unsigned port_over_current_change:1;
1140197ba5f4SPaul Zimmerman 			unsigned port_l1_change:1;
1141fd4850cfSCharles Manning 			unsigned reserved:25;
1142197ba5f4SPaul Zimmerman 		} b;
1143197ba5f4SPaul Zimmerman 	} flags;
1144197ba5f4SPaul Zimmerman 
1145197ba5f4SPaul Zimmerman 	struct list_head non_periodic_sched_inactive;
114638d2b5fbSDouglas Anderson 	struct list_head non_periodic_sched_waiting;
1147197ba5f4SPaul Zimmerman 	struct list_head non_periodic_sched_active;
1148197ba5f4SPaul Zimmerman 	struct list_head *non_periodic_qh_ptr;
1149197ba5f4SPaul Zimmerman 	struct list_head periodic_sched_inactive;
1150197ba5f4SPaul Zimmerman 	struct list_head periodic_sched_ready;
1151197ba5f4SPaul Zimmerman 	struct list_head periodic_sched_assigned;
1152197ba5f4SPaul Zimmerman 	struct list_head periodic_sched_queued;
1153c9c8ac01SDouglas Anderson 	struct list_head split_order;
1154197ba5f4SPaul Zimmerman 	u16 periodic_usecs;
1155db3e8244SChristophe JAILLET 	DECLARE_BITMAP(hs_periodic_bitmap, DWC2_HS_SCHEDULE_US);
1156197ba5f4SPaul Zimmerman 	u16 periodic_qh_count;
1157fbb9e22bSMian Yousaf Kaukab 	bool new_connection;
1158197ba5f4SPaul Zimmerman 
1159483bb254SDouglas Anderson 	u16 last_frame_num;
1160483bb254SDouglas Anderson 
1161197ba5f4SPaul Zimmerman #ifdef CONFIG_USB_DWC2_TRACK_MISSED_SOFS
1162197ba5f4SPaul Zimmerman #define FRAME_NUM_ARRAY_SIZE 1000
1163197ba5f4SPaul Zimmerman 	u16 *frame_num_array;
1164197ba5f4SPaul Zimmerman 	u16 *last_frame_num_array;
1165197ba5f4SPaul Zimmerman 	int frame_num_idx;
1166197ba5f4SPaul Zimmerman 	int dumped_frame_num_array;
1167197ba5f4SPaul Zimmerman #endif
1168197ba5f4SPaul Zimmerman 
1169197ba5f4SPaul Zimmerman 	struct list_head free_hc_list;
1170197ba5f4SPaul Zimmerman 	int periodic_channels;
1171197ba5f4SPaul Zimmerman 	int non_periodic_channels;
1172197ba5f4SPaul Zimmerman 	int available_host_channels;
1173197ba5f4SPaul Zimmerman 	struct dwc2_host_chan *hc_ptr_array[MAX_EPS_CHANNELS];
1174197ba5f4SPaul Zimmerman 	u8 *status_buf;
1175197ba5f4SPaul Zimmerman 	dma_addr_t status_buf_dma;
1176197ba5f4SPaul Zimmerman #define DWC2_HCD_STATUS_BUF_SIZE 64
1177197ba5f4SPaul Zimmerman 
1178197ba5f4SPaul Zimmerman 	struct delayed_work start_work;
1179197ba5f4SPaul Zimmerman 	struct delayed_work reset_work;
1180c40cf770SDouglas Anderson 	struct work_struct phy_reset_work;
1181197ba5f4SPaul Zimmerman 	u8 otg_port;
1182197ba5f4SPaul Zimmerman 	u32 *frame_list;
1183197ba5f4SPaul Zimmerman 	dma_addr_t frame_list_dma;
118495105a99SGregory Herrero 	u32 frame_list_sz;
11853b5fcc9aSGregory Herrero 	struct kmem_cache *desc_gen_cache;
11863b5fcc9aSGregory Herrero 	struct kmem_cache *desc_hsisoc_cache;
1187af424a41SWilliam Wu 	struct kmem_cache *unaligned_cache;
1188af424a41SWilliam Wu #define DWC2_KMEM_UNALIGNED_BUF_SIZE 1024
1189197ba5f4SPaul Zimmerman 
1190941fcce4SDinh Nguyen #endif /* CONFIG_USB_DWC2_HOST || CONFIG_USB_DWC2_DUAL_ROLE */
1191941fcce4SDinh Nguyen 
1192b98866c2SJohn Youn #if IS_ENABLED(CONFIG_USB_DWC2_PERIPHERAL) || \
1193b98866c2SJohn Youn 	IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE)
1194941fcce4SDinh Nguyen 	/* Gadget structures */
1195941fcce4SDinh Nguyen 	struct usb_gadget_driver *driver;
1196941fcce4SDinh Nguyen 	int fifo_mem;
1197941fcce4SDinh Nguyen 	unsigned int dedicated_fifos:1;
1198941fcce4SDinh Nguyen 	unsigned char num_of_eps;
1199941fcce4SDinh Nguyen 	u32 fifo_map;
1200941fcce4SDinh Nguyen 
1201941fcce4SDinh Nguyen 	struct usb_request *ep0_reply;
1202941fcce4SDinh Nguyen 	struct usb_request *ctrl_req;
12033f95001dSMian Yousaf Kaukab 	void *ep0_buff;
12043f95001dSMian Yousaf Kaukab 	void *ctrl_buff;
1205fe0b94abSMian Yousaf Kaukab 	enum dwc2_ep0_state ep0_state;
1206b4c53b4aSMinas Harutyunyan 	unsigned delayed_status : 1;
12079e14d0a5SGregory Herrero 	u8 test_mode;
1208941fcce4SDinh Nguyen 
12090f6b80c0SVahram Aharonyan 	dma_addr_t setup_desc_dma[2];
12100f6b80c0SVahram Aharonyan 	struct dwc2_dma_desc *setup_desc[2];
12110f6b80c0SVahram Aharonyan 	dma_addr_t ctrl_in_desc_dma;
12120f6b80c0SVahram Aharonyan 	struct dwc2_dma_desc *ctrl_in_desc;
12130f6b80c0SVahram Aharonyan 	dma_addr_t ctrl_out_desc_dma;
12140f6b80c0SVahram Aharonyan 	struct dwc2_dma_desc *ctrl_out_desc;
12150f6b80c0SVahram Aharonyan 
1216941fcce4SDinh Nguyen 	struct usb_gadget gadget;
1217dc6e69e6SMarek Szyprowski 	unsigned int enabled:1;
12184ace06e8SMarek Szyprowski 	unsigned int connected:1;
1219fa389a6dSVardan Mikayelyan 	unsigned int remote_wakeup_allowed:1;
12201f91b4ccSFelipe Balbi 	struct dwc2_hsotg_ep *eps_in[MAX_EPS_CHANNELS];
12211f91b4ccSFelipe Balbi 	struct dwc2_hsotg_ep *eps_out[MAX_EPS_CHANNELS];
1222941fcce4SDinh Nguyen #endif /* CONFIG_USB_DWC2_PERIPHERAL || CONFIG_USB_DWC2_DUAL_ROLE */
1223197ba5f4SPaul Zimmerman };
1224197ba5f4SPaul Zimmerman 
12250f548098SGevorg Sahakyan /* Normal architectures just use readl/write */
1226f25c42b8SGevorg Sahakyan static inline u32 dwc2_readl(struct dwc2_hsotg *hsotg, u32 offset)
12270f548098SGevorg Sahakyan {
1228fe369e18SGevorg Sahakyan 	u32 val;
1229fe369e18SGevorg Sahakyan 
1230fe369e18SGevorg Sahakyan 	val = readl(hsotg->regs + offset);
1231fe369e18SGevorg Sahakyan 	if (hsotg->needs_byte_swap)
1232fe369e18SGevorg Sahakyan 		return swab32(val);
1233fe369e18SGevorg Sahakyan 	else
1234fe369e18SGevorg Sahakyan 		return val;
12350f548098SGevorg Sahakyan }
12360f548098SGevorg Sahakyan 
1237f25c42b8SGevorg Sahakyan static inline void dwc2_writel(struct dwc2_hsotg *hsotg, u32 value, u32 offset)
12380f548098SGevorg Sahakyan {
1239fe369e18SGevorg Sahakyan 	if (hsotg->needs_byte_swap)
1240fe369e18SGevorg Sahakyan 		writel(swab32(value), hsotg->regs + offset);
1241fe369e18SGevorg Sahakyan 	else
1242f25c42b8SGevorg Sahakyan 		writel(value, hsotg->regs + offset);
12430f548098SGevorg Sahakyan 
12440f548098SGevorg Sahakyan #ifdef DWC2_LOG_WRITES
1245f25c42b8SGevorg Sahakyan 	pr_info("info:: wrote %08x to %p\n", value, hsotg->regs + offset);
12460f548098SGevorg Sahakyan #endif
12470f548098SGevorg Sahakyan }
1248342ccce1SGevorg Sahakyan 
1249342ccce1SGevorg Sahakyan static inline void dwc2_readl_rep(struct dwc2_hsotg *hsotg, u32 offset,
1250342ccce1SGevorg Sahakyan 				  void *buffer, unsigned int count)
1251342ccce1SGevorg Sahakyan {
1252342ccce1SGevorg Sahakyan 	if (count) {
1253342ccce1SGevorg Sahakyan 		u32 *buf = buffer;
1254342ccce1SGevorg Sahakyan 
1255342ccce1SGevorg Sahakyan 		do {
1256342ccce1SGevorg Sahakyan 			u32 x = dwc2_readl(hsotg, offset);
1257342ccce1SGevorg Sahakyan 			*buf++ = x;
1258342ccce1SGevorg Sahakyan 		} while (--count);
1259342ccce1SGevorg Sahakyan 	}
1260342ccce1SGevorg Sahakyan }
1261342ccce1SGevorg Sahakyan 
1262342ccce1SGevorg Sahakyan static inline void dwc2_writel_rep(struct dwc2_hsotg *hsotg, u32 offset,
1263342ccce1SGevorg Sahakyan 				   const void *buffer, unsigned int count)
1264342ccce1SGevorg Sahakyan {
1265342ccce1SGevorg Sahakyan 	if (count) {
1266342ccce1SGevorg Sahakyan 		const u32 *buf = buffer;
1267342ccce1SGevorg Sahakyan 
1268342ccce1SGevorg Sahakyan 		do {
1269342ccce1SGevorg Sahakyan 			dwc2_writel(hsotg, *buf++, offset);
1270342ccce1SGevorg Sahakyan 		} while (--count);
1271342ccce1SGevorg Sahakyan 	}
1272342ccce1SGevorg Sahakyan }
12730f548098SGevorg Sahakyan 
1274197ba5f4SPaul Zimmerman /* Reasons for halting a host channel */
1275197ba5f4SPaul Zimmerman enum dwc2_halt_status {
1276197ba5f4SPaul Zimmerman 	DWC2_HC_XFER_NO_HALT_STATUS,
1277197ba5f4SPaul Zimmerman 	DWC2_HC_XFER_COMPLETE,
1278197ba5f4SPaul Zimmerman 	DWC2_HC_XFER_URB_COMPLETE,
1279197ba5f4SPaul Zimmerman 	DWC2_HC_XFER_ACK,
1280197ba5f4SPaul Zimmerman 	DWC2_HC_XFER_NAK,
1281197ba5f4SPaul Zimmerman 	DWC2_HC_XFER_NYET,
1282197ba5f4SPaul Zimmerman 	DWC2_HC_XFER_STALL,
1283197ba5f4SPaul Zimmerman 	DWC2_HC_XFER_XACT_ERR,
1284197ba5f4SPaul Zimmerman 	DWC2_HC_XFER_FRAME_OVERRUN,
1285197ba5f4SPaul Zimmerman 	DWC2_HC_XFER_BABBLE_ERR,
1286197ba5f4SPaul Zimmerman 	DWC2_HC_XFER_DATA_TOGGLE_ERR,
1287197ba5f4SPaul Zimmerman 	DWC2_HC_XFER_AHB_ERR,
1288197ba5f4SPaul Zimmerman 	DWC2_HC_XFER_PERIODIC_INCOMPLETE,
1289197ba5f4SPaul Zimmerman 	DWC2_HC_XFER_URB_DEQUEUE,
1290197ba5f4SPaul Zimmerman };
1291197ba5f4SPaul Zimmerman 
12921e6b98ebSVardan Mikayelyan /* Core version information */
12931e6b98ebSVardan Mikayelyan static inline bool dwc2_is_iot(struct dwc2_hsotg *hsotg)
12941e6b98ebSVardan Mikayelyan {
12951e6b98ebSVardan Mikayelyan 	return (hsotg->hw_params.snpsid & 0xfff00000) == 0x55300000;
12961e6b98ebSVardan Mikayelyan }
12971e6b98ebSVardan Mikayelyan 
12981e6b98ebSVardan Mikayelyan static inline bool dwc2_is_fs_iot(struct dwc2_hsotg *hsotg)
12991e6b98ebSVardan Mikayelyan {
13001e6b98ebSVardan Mikayelyan 	return (hsotg->hw_params.snpsid & 0xffff0000) == 0x55310000;
13011e6b98ebSVardan Mikayelyan }
13021e6b98ebSVardan Mikayelyan 
13031e6b98ebSVardan Mikayelyan static inline bool dwc2_is_hs_iot(struct dwc2_hsotg *hsotg)
13041e6b98ebSVardan Mikayelyan {
13051e6b98ebSVardan Mikayelyan 	return (hsotg->hw_params.snpsid & 0xffff0000) == 0x55320000;
13061e6b98ebSVardan Mikayelyan }
13071e6b98ebSVardan Mikayelyan 
1308197ba5f4SPaul Zimmerman /*
1309197ba5f4SPaul Zimmerman  * The following functions support initialization of the core driver component
1310197ba5f4SPaul Zimmerman  * and the DWC_otg controller
1311197ba5f4SPaul Zimmerman  */
13126e6360b6SJohn Stultz int dwc2_core_reset(struct dwc2_hsotg *hsotg, bool skip_wait);
131341ba9b9bSVardan Mikayelyan int dwc2_enter_partial_power_down(struct dwc2_hsotg *hsotg);
1314c9c394abSArtur Petrosyan int dwc2_exit_partial_power_down(struct dwc2_hsotg *hsotg, int rem_wakeup,
1315c9c394abSArtur Petrosyan 				 bool restore);
1316624815ceSVardan Mikayelyan int dwc2_enter_hibernation(struct dwc2_hsotg *hsotg, int is_host);
1317624815ceSVardan Mikayelyan int dwc2_exit_hibernation(struct dwc2_hsotg *hsotg, int rem_wakeup,
1318624815ceSVardan Mikayelyan 		int reset, int is_host);
1319059d8d52SJules Maselbas void dwc2_init_fs_ls_pclk_sel(struct dwc2_hsotg *hsotg);
1320059d8d52SJules Maselbas int dwc2_phy_init(struct dwc2_hsotg *hsotg, bool select_phy);
1321197ba5f4SPaul Zimmerman 
132213b1f8e2SVardan Mikayelyan void dwc2_force_mode(struct dwc2_hsotg *hsotg, bool host);
132309c96980SJohn Youn void dwc2_force_dr_mode(struct dwc2_hsotg *hsotg);
132409c96980SJohn Youn 
13259da51974SJohn Youn bool dwc2_is_controller_alive(struct dwc2_hsotg *hsotg);
1326197ba5f4SPaul Zimmerman 
132765dc2e72SMinas Harutyunyan int dwc2_check_core_version(struct dwc2_hsotg *hsotg);
132865dc2e72SMinas Harutyunyan 
1329197ba5f4SPaul Zimmerman /*
1330197ba5f4SPaul Zimmerman  * Common core Functions.
1331197ba5f4SPaul Zimmerman  * The following functions support managing the DWC_otg controller in either
1332197ba5f4SPaul Zimmerman  * device or host mode.
1333197ba5f4SPaul Zimmerman  */
13349da51974SJohn Youn void dwc2_read_packet(struct dwc2_hsotg *hsotg, u8 *dest, u16 bytes);
13359da51974SJohn Youn void dwc2_flush_tx_fifo(struct dwc2_hsotg *hsotg, const int num);
13369da51974SJohn Youn void dwc2_flush_rx_fifo(struct dwc2_hsotg *hsotg);
1337197ba5f4SPaul Zimmerman 
13389da51974SJohn Youn void dwc2_enable_global_interrupts(struct dwc2_hsotg *hcd);
13399da51974SJohn Youn void dwc2_disable_global_interrupts(struct dwc2_hsotg *hcd);
1340197ba5f4SPaul Zimmerman 
134194d2666cSVardan Mikayelyan void dwc2_hib_restore_common(struct dwc2_hsotg *hsotg, int rem_wakeup,
134294d2666cSVardan Mikayelyan 			     int is_host);
1343c5c403dcSVardan Mikayelyan int dwc2_backup_global_registers(struct dwc2_hsotg *hsotg);
1344c5c403dcSVardan Mikayelyan int dwc2_restore_global_registers(struct dwc2_hsotg *hsotg);
134594d2666cSVardan Mikayelyan 
134666e77a24SRazmik Karapetyan void dwc2_enable_acg(struct dwc2_hsotg *hsotg);
13475d69a3b5SMinas Harutyunyan void dwc2_wakeup_from_lpm_l1(struct dwc2_hsotg *hsotg, bool remotewakeup);
134866e77a24SRazmik Karapetyan 
1349197ba5f4SPaul Zimmerman /* This function should be called on every hardware interrupt. */
13509da51974SJohn Youn irqreturn_t dwc2_handle_common_intr(int irq, void *dev);
1351197ba5f4SPaul Zimmerman 
1352323230efSJohn Youn /* The device ID match table */
1353323230efSJohn Youn extern const struct of_device_id dwc2_of_match_table[];
13542e5db2c0SJeremy Linton extern const struct acpi_device_id dwc2_acpi_match[];
1355e16d5f14SYinbo Zhu extern const struct pci_device_id dwc2_pci_ids[];
1356323230efSJohn Youn 
13579da51974SJohn Youn int dwc2_lowlevel_hw_enable(struct dwc2_hsotg *hsotg);
13589da51974SJohn Youn int dwc2_lowlevel_hw_disable(struct dwc2_hsotg *hsotg);
1359ecb176c6SMian Yousaf Kaukab 
136079d6b8c5SSevak Arakelyan /* Common polling functions */
136179d6b8c5SSevak Arakelyan int dwc2_hsotg_wait_bit_set(struct dwc2_hsotg *hs_otg, u32 reg, u32 bit,
136279d6b8c5SSevak Arakelyan 			    u32 timeout);
136379d6b8c5SSevak Arakelyan int dwc2_hsotg_wait_bit_clear(struct dwc2_hsotg *hs_otg, u32 reg, u32 bit,
136479d6b8c5SSevak Arakelyan 			      u32 timeout);
1365334bbd4eSJohn Youn /* Parameters */
1366c1d286cfSJohn Youn int dwc2_get_hwparams(struct dwc2_hsotg *hsotg);
1367334bbd4eSJohn Youn int dwc2_init_params(struct dwc2_hsotg *hsotg);
1368334bbd4eSJohn Youn 
1369197ba5f4SPaul Zimmerman /*
13706bea9620SJohn Youn  * The following functions check the controller's OTG operation mode
13716bea9620SJohn Youn  * capability (GHWCFG2.OTG_MODE).
13726bea9620SJohn Youn  *
13736bea9620SJohn Youn  * These functions can be used before the internal hsotg->hw_params
13746bea9620SJohn Youn  * are read in and cached so they always read directly from the
13756bea9620SJohn Youn  * GHWCFG2 register.
13766bea9620SJohn Youn  */
13779da51974SJohn Youn unsigned int dwc2_op_mode(struct dwc2_hsotg *hsotg);
13786bea9620SJohn Youn bool dwc2_hw_is_otg(struct dwc2_hsotg *hsotg);
13796bea9620SJohn Youn bool dwc2_hw_is_host(struct dwc2_hsotg *hsotg);
13806bea9620SJohn Youn bool dwc2_hw_is_device(struct dwc2_hsotg *hsotg);
13816bea9620SJohn Youn 
13826bea9620SJohn Youn /*
13831696d5abSJohn Youn  * Returns the mode of operation, host or device
13841696d5abSJohn Youn  */
13851696d5abSJohn Youn static inline int dwc2_is_host_mode(struct dwc2_hsotg *hsotg)
13861696d5abSJohn Youn {
1387f25c42b8SGevorg Sahakyan 	return (dwc2_readl(hsotg, GINTSTS) & GINTSTS_CURMODE_HOST) != 0;
13881696d5abSJohn Youn }
13899da51974SJohn Youn 
13901696d5abSJohn Youn static inline int dwc2_is_device_mode(struct dwc2_hsotg *hsotg)
13911696d5abSJohn Youn {
1392f25c42b8SGevorg Sahakyan 	return (dwc2_readl(hsotg, GINTSTS) & GINTSTS_CURMODE_HOST) == 0;
13931696d5abSJohn Youn }
13941696d5abSJohn Youn 
139517f93402SAmelie Delaunay int dwc2_drd_init(struct dwc2_hsotg *hsotg);
139617f93402SAmelie Delaunay void dwc2_drd_suspend(struct dwc2_hsotg *hsotg);
139717f93402SAmelie Delaunay void dwc2_drd_resume(struct dwc2_hsotg *hsotg);
139817f93402SAmelie Delaunay void dwc2_drd_exit(struct dwc2_hsotg *hsotg);
139917f93402SAmelie Delaunay 
14001696d5abSJohn Youn /*
1401197ba5f4SPaul Zimmerman  * Dump core registers and SPRAM
1402197ba5f4SPaul Zimmerman  */
14039da51974SJohn Youn void dwc2_dump_dev_registers(struct dwc2_hsotg *hsotg);
14049da51974SJohn Youn void dwc2_dump_host_registers(struct dwc2_hsotg *hsotg);
14059da51974SJohn Youn void dwc2_dump_global_registers(struct dwc2_hsotg *hsotg);
1406197ba5f4SPaul Zimmerman 
1407117777b2SDinh Nguyen /* Gadget defines */
1408b98866c2SJohn Youn #if IS_ENABLED(CONFIG_USB_DWC2_PERIPHERAL) || \
1409b98866c2SJohn Youn 	IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE)
14109da51974SJohn Youn int dwc2_hsotg_remove(struct dwc2_hsotg *hsotg);
14119da51974SJohn Youn int dwc2_hsotg_suspend(struct dwc2_hsotg *dwc2);
14129da51974SJohn Youn int dwc2_hsotg_resume(struct dwc2_hsotg *dwc2);
1413f3768997SVardan Mikayelyan int dwc2_gadget_init(struct dwc2_hsotg *hsotg);
14149da51974SJohn Youn void dwc2_hsotg_core_init_disconnected(struct dwc2_hsotg *dwc2,
1415643cc4deSGregory Herrero 				       bool reset);
141617f93402SAmelie Delaunay void dwc2_hsotg_core_disconnect(struct dwc2_hsotg *hsotg);
14179da51974SJohn Youn void dwc2_hsotg_core_connect(struct dwc2_hsotg *hsotg);
14189da51974SJohn Youn void dwc2_hsotg_disconnect(struct dwc2_hsotg *dwc2);
14199da51974SJohn Youn int dwc2_hsotg_set_test_mode(struct dwc2_hsotg *hsotg, int testmode);
1420f81f46e1SGregory Herrero #define dwc2_is_device_connected(hsotg) (hsotg->connected)
142132fde843SFabrice Gasnier #define dwc2_is_device_enabled(hsotg) (hsotg->enabled)
142258e52ff6SJohn Youn int dwc2_backup_device_registers(struct dwc2_hsotg *hsotg);
14239a5d2816SVardan Mikayelyan int dwc2_restore_device_registers(struct dwc2_hsotg *hsotg, int remote_wakeup);
1424c5c403dcSVardan Mikayelyan int dwc2_gadget_enter_hibernation(struct dwc2_hsotg *hsotg);
1425c5c403dcSVardan Mikayelyan int dwc2_gadget_exit_hibernation(struct dwc2_hsotg *hsotg,
1426c5c403dcSVardan Mikayelyan 				 int rem_wakeup, int reset);
1427be2b960eSArtur Petrosyan int dwc2_gadget_enter_partial_power_down(struct dwc2_hsotg *hsotg);
1428be2b960eSArtur Petrosyan int dwc2_gadget_exit_partial_power_down(struct dwc2_hsotg *hsotg,
1429be2b960eSArtur Petrosyan 					bool restore);
1430012466fcSArtur Petrosyan void dwc2_gadget_enter_clock_gating(struct dwc2_hsotg *hsotg);
1431012466fcSArtur Petrosyan void dwc2_gadget_exit_clock_gating(struct dwc2_hsotg *hsotg,
1432012466fcSArtur Petrosyan 				   int rem_wakeup);
1433c138ecfaSSevak Arakelyan int dwc2_hsotg_tx_fifo_count(struct dwc2_hsotg *hsotg);
1434c138ecfaSSevak Arakelyan int dwc2_hsotg_tx_fifo_total_depth(struct dwc2_hsotg *hsotg);
1435c138ecfaSSevak Arakelyan int dwc2_hsotg_tx_fifo_average_depth(struct dwc2_hsotg *hsotg);
143621b03405SSevak Arakelyan void dwc2_gadget_init_lpm(struct dwc2_hsotg *hsotg);
143715d9dbf8SGrigor Tovmasyan void dwc2_gadget_program_ref_clk(struct dwc2_hsotg *hsotg);
1438238f65aeSArtur Petrosyan static inline void dwc2_clear_fifo_map(struct dwc2_hsotg *hsotg)
1439238f65aeSArtur Petrosyan { hsotg->fifo_map = 0; }
1440117777b2SDinh Nguyen #else
14411f91b4ccSFelipe Balbi static inline int dwc2_hsotg_remove(struct dwc2_hsotg *dwc2)
1442117777b2SDinh Nguyen { return 0; }
14431f91b4ccSFelipe Balbi static inline int dwc2_hsotg_suspend(struct dwc2_hsotg *dwc2)
1444117777b2SDinh Nguyen { return 0; }
14451f91b4ccSFelipe Balbi static inline int dwc2_hsotg_resume(struct dwc2_hsotg *dwc2)
1446117777b2SDinh Nguyen { return 0; }
1447f3768997SVardan Mikayelyan static inline int dwc2_gadget_init(struct dwc2_hsotg *hsotg)
1448117777b2SDinh Nguyen { return 0; }
14491f91b4ccSFelipe Balbi static inline void dwc2_hsotg_core_init_disconnected(struct dwc2_hsotg *dwc2,
1450643cc4deSGregory Herrero 						     bool reset) {}
145117f93402SAmelie Delaunay static inline void dwc2_hsotg_core_disconnect(struct dwc2_hsotg *hsotg) {}
14521f91b4ccSFelipe Balbi static inline void dwc2_hsotg_core_connect(struct dwc2_hsotg *hsotg) {}
14531f91b4ccSFelipe Balbi static inline void dwc2_hsotg_disconnect(struct dwc2_hsotg *dwc2) {}
14541f91b4ccSFelipe Balbi static inline int dwc2_hsotg_set_test_mode(struct dwc2_hsotg *hsotg,
1455f91eea44SMian Yousaf Kaukab 					   int testmode)
1456f91eea44SMian Yousaf Kaukab { return 0; }
1457f81f46e1SGregory Herrero #define dwc2_is_device_connected(hsotg) (0)
145832fde843SFabrice Gasnier #define dwc2_is_device_enabled(hsotg) (0)
145958e52ff6SJohn Youn static inline int dwc2_backup_device_registers(struct dwc2_hsotg *hsotg)
146058e52ff6SJohn Youn { return 0; }
14619a5d2816SVardan Mikayelyan static inline int dwc2_restore_device_registers(struct dwc2_hsotg *hsotg,
14629a5d2816SVardan Mikayelyan 						int remote_wakeup)
146358e52ff6SJohn Youn { return 0; }
1464c5c403dcSVardan Mikayelyan static inline int dwc2_gadget_enter_hibernation(struct dwc2_hsotg *hsotg)
1465c5c403dcSVardan Mikayelyan { return 0; }
1466c5c403dcSVardan Mikayelyan static inline int dwc2_gadget_exit_hibernation(struct dwc2_hsotg *hsotg,
1467c5c403dcSVardan Mikayelyan 					       int rem_wakeup, int reset)
1468c5c403dcSVardan Mikayelyan { return 0; }
1469be2b960eSArtur Petrosyan static inline int dwc2_gadget_enter_partial_power_down(struct dwc2_hsotg *hsotg)
1470be2b960eSArtur Petrosyan { return 0; }
1471be2b960eSArtur Petrosyan static inline int dwc2_gadget_exit_partial_power_down(struct dwc2_hsotg *hsotg,
1472be2b960eSArtur Petrosyan 						      bool restore)
1473be2b960eSArtur Petrosyan { return 0; }
1474012466fcSArtur Petrosyan static inline void dwc2_gadget_enter_clock_gating(struct dwc2_hsotg *hsotg) {}
1475012466fcSArtur Petrosyan static inline void dwc2_gadget_exit_clock_gating(struct dwc2_hsotg *hsotg,
1476012466fcSArtur Petrosyan 						 int rem_wakeup) {}
1477c138ecfaSSevak Arakelyan static inline int dwc2_hsotg_tx_fifo_count(struct dwc2_hsotg *hsotg)
1478c138ecfaSSevak Arakelyan { return 0; }
1479c138ecfaSSevak Arakelyan static inline int dwc2_hsotg_tx_fifo_total_depth(struct dwc2_hsotg *hsotg)
1480c138ecfaSSevak Arakelyan { return 0; }
1481c138ecfaSSevak Arakelyan static inline int dwc2_hsotg_tx_fifo_average_depth(struct dwc2_hsotg *hsotg)
1482c138ecfaSSevak Arakelyan { return 0; }
148321b03405SSevak Arakelyan static inline void dwc2_gadget_init_lpm(struct dwc2_hsotg *hsotg) {}
148415d9dbf8SGrigor Tovmasyan static inline void dwc2_gadget_program_ref_clk(struct dwc2_hsotg *hsotg) {}
1485238f65aeSArtur Petrosyan static inline void dwc2_clear_fifo_map(struct dwc2_hsotg *hsotg) {}
1486117777b2SDinh Nguyen #endif
1487117777b2SDinh Nguyen 
1488117777b2SDinh Nguyen #if IS_ENABLED(CONFIG_USB_DWC2_HOST) || IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE)
14899da51974SJohn Youn int dwc2_hcd_get_frame_number(struct dwc2_hsotg *hsotg);
14909da51974SJohn Youn int dwc2_hcd_get_future_frame_number(struct dwc2_hsotg *hsotg, int us);
14919da51974SJohn Youn void dwc2_hcd_connect(struct dwc2_hsotg *hsotg);
14929da51974SJohn Youn void dwc2_hcd_disconnect(struct dwc2_hsotg *hsotg, bool force);
14939da51974SJohn Youn void dwc2_hcd_start(struct dwc2_hsotg *hsotg);
149465c9c4c6SVardan Mikayelyan int dwc2_core_init(struct dwc2_hsotg *hsotg, bool initial_setup);
149522ff0c8eSArtur Petrosyan int dwc2_port_suspend(struct dwc2_hsotg *hsotg, u16 windex);
14961e0890ebSArtur Petrosyan int dwc2_port_resume(struct dwc2_hsotg *hsotg);
149758e52ff6SJohn Youn int dwc2_backup_host_registers(struct dwc2_hsotg *hsotg);
149858e52ff6SJohn Youn int dwc2_restore_host_registers(struct dwc2_hsotg *hsotg);
1499c5c403dcSVardan Mikayelyan int dwc2_host_enter_hibernation(struct dwc2_hsotg *hsotg);
1500c5c403dcSVardan Mikayelyan int dwc2_host_exit_hibernation(struct dwc2_hsotg *hsotg,
1501c5c403dcSVardan Mikayelyan 			       int rem_wakeup, int reset);
15029ce9e5adSArtur Petrosyan int dwc2_host_enter_partial_power_down(struct dwc2_hsotg *hsotg);
15039ce9e5adSArtur Petrosyan int dwc2_host_exit_partial_power_down(struct dwc2_hsotg *hsotg,
15049ce9e5adSArtur Petrosyan 				      int rem_wakeup, bool restore);
150579c87c3cSArtur Petrosyan void dwc2_host_enter_clock_gating(struct dwc2_hsotg *hsotg);
150679c87c3cSArtur Petrosyan void dwc2_host_exit_clock_gating(struct dwc2_hsotg *hsotg, int rem_wakeup);
1507c846b03fSDouglas Anderson bool dwc2_host_can_poweroff_phy(struct dwc2_hsotg *dwc2);
1508c40cf770SDouglas Anderson static inline void dwc2_host_schedule_phy_reset(struct dwc2_hsotg *hsotg)
1509c40cf770SDouglas Anderson { schedule_work(&hsotg->phy_reset_work); }
1510117777b2SDinh Nguyen #else
1511117777b2SDinh Nguyen static inline int dwc2_hcd_get_frame_number(struct dwc2_hsotg *hsotg)
1512117777b2SDinh Nguyen { return 0; }
1513fae4e826SDouglas Anderson static inline int dwc2_hcd_get_future_frame_number(struct dwc2_hsotg *hsotg,
1514fae4e826SDouglas Anderson 						   int us)
1515fae4e826SDouglas Anderson { return 0; }
15166a659531SDouglas Anderson static inline void dwc2_hcd_connect(struct dwc2_hsotg *hsotg) {}
15176a659531SDouglas Anderson static inline void dwc2_hcd_disconnect(struct dwc2_hsotg *hsotg, bool force) {}
1518117777b2SDinh Nguyen static inline void dwc2_hcd_start(struct dwc2_hsotg *hsotg) {}
1519117777b2SDinh Nguyen static inline void dwc2_hcd_remove(struct dwc2_hsotg *hsotg) {}
152065c9c4c6SVardan Mikayelyan static inline int dwc2_core_init(struct dwc2_hsotg *hsotg, bool initial_setup)
152165c9c4c6SVardan Mikayelyan { return 0; }
152222ff0c8eSArtur Petrosyan static inline int dwc2_port_suspend(struct dwc2_hsotg *hsotg, u16 windex)
152322ff0c8eSArtur Petrosyan { return 0; }
15241e0890ebSArtur Petrosyan static inline int dwc2_port_resume(struct dwc2_hsotg *hsotg)
15251e0890ebSArtur Petrosyan { return 0; }
15264fe160d5SHeiner Kallweit static inline int dwc2_hcd_init(struct dwc2_hsotg *hsotg)
1527117777b2SDinh Nguyen { return 0; }
152858e52ff6SJohn Youn static inline int dwc2_backup_host_registers(struct dwc2_hsotg *hsotg)
152958e52ff6SJohn Youn { return 0; }
153058e52ff6SJohn Youn static inline int dwc2_restore_host_registers(struct dwc2_hsotg *hsotg)
153158e52ff6SJohn Youn { return 0; }
1532c5c403dcSVardan Mikayelyan static inline int dwc2_host_enter_hibernation(struct dwc2_hsotg *hsotg)
1533c5c403dcSVardan Mikayelyan { return 0; }
1534c5c403dcSVardan Mikayelyan static inline int dwc2_host_exit_hibernation(struct dwc2_hsotg *hsotg,
1535c5c403dcSVardan Mikayelyan 					     int rem_wakeup, int reset)
1536c5c403dcSVardan Mikayelyan { return 0; }
15379ce9e5adSArtur Petrosyan static inline int dwc2_host_enter_partial_power_down(struct dwc2_hsotg *hsotg)
15389ce9e5adSArtur Petrosyan { return 0; }
15399ce9e5adSArtur Petrosyan static inline int dwc2_host_exit_partial_power_down(struct dwc2_hsotg *hsotg,
15409ce9e5adSArtur Petrosyan 						    int rem_wakeup, bool restore)
15419ce9e5adSArtur Petrosyan { return 0; }
154279c87c3cSArtur Petrosyan static inline void dwc2_host_enter_clock_gating(struct dwc2_hsotg *hsotg) {}
154379c87c3cSArtur Petrosyan static inline void dwc2_host_exit_clock_gating(struct dwc2_hsotg *hsotg,
154479c87c3cSArtur Petrosyan 					       int rem_wakeup) {}
1545c846b03fSDouglas Anderson static inline bool dwc2_host_can_poweroff_phy(struct dwc2_hsotg *dwc2)
1546c846b03fSDouglas Anderson { return false; }
1547c40cf770SDouglas Anderson static inline void dwc2_host_schedule_phy_reset(struct dwc2_hsotg *hsotg) {}
154858e52ff6SJohn Youn 
1549117777b2SDinh Nguyen #endif
1550117777b2SDinh Nguyen 
1551197ba5f4SPaul Zimmerman #endif /* __DWC2_CORE_H__ */
1552