GNU Linux-libre 4.4.284-gnu1
[releases.git] / drivers / usb / dwc2 / core.h
1 /*
2  * core.h - DesignWare HS OTG Controller common declarations
3  *
4  * Copyright (C) 2004-2013 Synopsys, Inc.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions, and the following disclaimer,
11  *    without modification.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. The names of the above-listed copyright holders may not be used
16  *    to endorse or promote products derived from this software without
17  *    specific prior written permission.
18  *
19  * ALTERNATIVELY, this software may be distributed under the terms of the
20  * GNU General Public License ("GPL") as published by the Free Software
21  * Foundation; either version 2 of the License, or (at your option) any
22  * later version.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
25  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
26  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
27  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
28  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
31  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
32  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
33  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35  */
36
37 #ifndef __DWC2_CORE_H__
38 #define __DWC2_CORE_H__
39
40 #include <linux/phy/phy.h>
41 #include <linux/regulator/consumer.h>
42 #include <linux/usb/gadget.h>
43 #include <linux/usb/otg.h>
44 #include <linux/usb/phy.h>
45 #include "hw.h"
46
47 #ifdef CONFIG_MIPS
48 /*
49  * There are some MIPS machines that can run in either big-endian
50  * or little-endian mode and that use the dwc2 register without
51  * a byteswap in both ways.
52  * Unlike other architectures, MIPS apparently does not require a
53  * barrier before the __raw_writel() to synchronize with DMA but does
54  * require the barrier after the __raw_writel() to serialize a set of
55  * writes. This set of operations was added specifically for MIPS and
56  * should only be used there.
57  */
58 static inline u32 dwc2_readl(const void __iomem *addr)
59 {
60         u32 value = __raw_readl(addr);
61
62         /* In order to preserve endianness __raw_* operation is used. Therefore
63          * a barrier is needed to ensure IO access is not re-ordered across
64          * reads or writes
65          */
66         mb();
67         return value;
68 }
69
70 static inline void dwc2_writel(u32 value, void __iomem *addr)
71 {
72         __raw_writel(value, addr);
73
74         /*
75          * In order to preserve endianness __raw_* operation is used. Therefore
76          * a barrier is needed to ensure IO access is not re-ordered across
77          * reads or writes
78          */
79         mb();
80 #ifdef DWC2_LOG_WRITES
81         pr_info("INFO:: wrote %08x to %p\n", value, addr);
82 #endif
83 }
84 #else
85 /* Normal architectures just use readl/write */
86 static inline u32 dwc2_readl(const void __iomem *addr)
87 {
88         return readl(addr);
89 }
90
91 static inline void dwc2_writel(u32 value, void __iomem *addr)
92 {
93         writel(value, addr);
94
95 #ifdef DWC2_LOG_WRITES
96         pr_info("info:: wrote %08x to %p\n", value, addr);
97 #endif
98 }
99 #endif
100
101 /* Maximum number of Endpoints/HostChannels */
102 #define MAX_EPS_CHANNELS        16
103
104 /* dwc2-hsotg declarations */
105 static const char * const dwc2_hsotg_supply_names[] = {
106         "vusb_d",               /* digital USB supply, 1.2V */
107         "vusb_a",               /* analog USB supply, 1.1V */
108 };
109
110 /*
111  * EP0_MPS_LIMIT
112  *
113  * Unfortunately there seems to be a limit of the amount of data that can
114  * be transferred by IN transactions on EP0. This is either 127 bytes or 3
115  * packets (which practically means 1 packet and 63 bytes of data) when the
116  * MPS is set to 64.
117  *
118  * This means if we are wanting to move >127 bytes of data, we need to
119  * split the transactions up, but just doing one packet at a time does
120  * not work (this may be an implicit DATA0 PID on first packet of the
121  * transaction) and doing 2 packets is outside the controller's limits.
122  *
123  * If we try to lower the MPS size for EP0, then no transfers work properly
124  * for EP0, and the system will fail basic enumeration. As no cause for this
125  * has currently been found, we cannot support any large IN transfers for
126  * EP0.
127  */
128 #define EP0_MPS_LIMIT   64
129
130 struct dwc2_hsotg;
131 struct dwc2_hsotg_req;
132
133 /**
134  * struct dwc2_hsotg_ep - driver endpoint definition.
135  * @ep: The gadget layer representation of the endpoint.
136  * @name: The driver generated name for the endpoint.
137  * @queue: Queue of requests for this endpoint.
138  * @parent: Reference back to the parent device structure.
139  * @req: The current request that the endpoint is processing. This is
140  *       used to indicate an request has been loaded onto the endpoint
141  *       and has yet to be completed (maybe due to data move, or simply
142  *       awaiting an ack from the core all the data has been completed).
143  * @debugfs: File entry for debugfs file for this endpoint.
144  * @lock: State lock to protect contents of endpoint.
145  * @dir_in: Set to true if this endpoint is of the IN direction, which
146  *          means that it is sending data to the Host.
147  * @map_dir: Set to the value of dir_in when the DMA buffer is mapped.
148  * @index: The index for the endpoint registers.
149  * @mc: Multi Count - number of transactions per microframe
150  * @interval - Interval for periodic endpoints
151  * @name: The name array passed to the USB core.
152  * @halted: Set if the endpoint has been halted.
153  * @periodic: Set if this is a periodic ep, such as Interrupt
154  * @isochronous: Set if this is a isochronous ep
155  * @send_zlp: Set if we need to send a zero-length packet.
156  * @total_data: The total number of data bytes done.
157  * @fifo_size: The size of the FIFO (for periodic IN endpoints)
158  * @fifo_load: The amount of data loaded into the FIFO (periodic IN)
159  * @last_load: The offset of data for the last start of request.
160  * @size_loaded: The last loaded size for DxEPTSIZE for periodic IN
161  *
162  * This is the driver's state for each registered enpoint, allowing it
163  * to keep track of transactions that need doing. Each endpoint has a
164  * lock to protect the state, to try and avoid using an overall lock
165  * for the host controller as much as possible.
166  *
167  * For periodic IN endpoints, we have fifo_size and fifo_load to try
168  * and keep track of the amount of data in the periodic FIFO for each
169  * of these as we don't have a status register that tells us how much
170  * is in each of them. (note, this may actually be useless information
171  * as in shared-fifo mode periodic in acts like a single-frame packet
172  * buffer than a fifo)
173  */
174 struct dwc2_hsotg_ep {
175         struct usb_ep           ep;
176         struct list_head        queue;
177         struct dwc2_hsotg       *parent;
178         struct dwc2_hsotg_req    *req;
179         struct dentry           *debugfs;
180
181         unsigned long           total_data;
182         unsigned int            size_loaded;
183         unsigned int            last_load;
184         unsigned int            fifo_load;
185         unsigned short          fifo_size;
186         unsigned short          fifo_index;
187
188         unsigned char           dir_in;
189         unsigned char           map_dir;
190         unsigned char           index;
191         unsigned char           mc;
192         u16                     interval;
193
194         unsigned int            halted:1;
195         unsigned int            periodic:1;
196         unsigned int            isochronous:1;
197         unsigned int            send_zlp:1;
198         unsigned int            has_correct_parity:1;
199
200         char                    name[10];
201 };
202
203 /**
204  * struct dwc2_hsotg_req - data transfer request
205  * @req: The USB gadget request
206  * @queue: The list of requests for the endpoint this is queued for.
207  * @saved_req_buf: variable to save req.buf when bounce buffers are used.
208  */
209 struct dwc2_hsotg_req {
210         struct usb_request      req;
211         struct list_head        queue;
212         void *saved_req_buf;
213 };
214
215 #if IS_ENABLED(CONFIG_USB_DWC2_PERIPHERAL) || IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE)
216 #define call_gadget(_hs, _entry) \
217 do { \
218         if ((_hs)->gadget.speed != USB_SPEED_UNKNOWN && \
219                 (_hs)->driver && (_hs)->driver->_entry) { \
220                 spin_unlock(&_hs->lock); \
221                 (_hs)->driver->_entry(&(_hs)->gadget); \
222                 spin_lock(&_hs->lock); \
223         } \
224 } while (0)
225 #else
226 #define call_gadget(_hs, _entry)        do {} while (0)
227 #endif
228
229 struct dwc2_hsotg;
230 struct dwc2_host_chan;
231
232 /* Device States */
233 enum dwc2_lx_state {
234         DWC2_L0,        /* On state */
235         DWC2_L1,        /* LPM sleep state */
236         DWC2_L2,        /* USB suspend state */
237         DWC2_L3,        /* Off state */
238 };
239
240 /*
241  * Gadget periodic tx fifo sizes as used by legacy driver
242  * EP0 is not included
243  */
244 #define DWC2_G_P_LEGACY_TX_FIFO_SIZE {256, 256, 256, 256, 768, 768, 768, \
245                                            768, 0, 0, 0, 0, 0, 0, 0}
246
247 /* Gadget ep0 states */
248 enum dwc2_ep0_state {
249         DWC2_EP0_SETUP,
250         DWC2_EP0_DATA_IN,
251         DWC2_EP0_DATA_OUT,
252         DWC2_EP0_STATUS_IN,
253         DWC2_EP0_STATUS_OUT,
254 };
255
256 /**
257  * struct dwc2_core_params - Parameters for configuring the core
258  *
259  * @otg_cap:            Specifies the OTG capabilities.
260  *                       0 - HNP and SRP capable
261  *                       1 - SRP Only capable
262  *                       2 - No HNP/SRP capable (always available)
263  *                      Defaults to best available option (0, 1, then 2)
264  * @otg_ver:            OTG version supported
265  *                       0 - 1.3 (default)
266  *                       1 - 2.0
267  * @dma_enable:         Specifies whether to use slave or DMA mode for accessing
268  *                      the data FIFOs. The driver will automatically detect the
269  *                      value for this parameter if none is specified.
270  *                       0 - Slave (always available)
271  *                       1 - DMA (default, if available)
272  * @dma_desc_enable:    When DMA mode is enabled, specifies whether to use
273  *                      address DMA mode or descriptor DMA mode for accessing
274  *                      the data FIFOs. The driver will automatically detect the
275  *                      value for this if none is specified.
276  *                       0 - Address DMA
277  *                       1 - Descriptor DMA (default, if available)
278  * @speed:              Specifies the maximum speed of operation in host and
279  *                      device mode. The actual speed depends on the speed of
280  *                      the attached device and the value of phy_type.
281  *                       0 - High Speed
282  *                           (default when phy_type is UTMI+ or ULPI)
283  *                       1 - Full Speed
284  *                           (default when phy_type is Full Speed)
285  * @enable_dynamic_fifo: 0 - Use coreConsultant-specified FIFO size parameters
286  *                       1 - Allow dynamic FIFO sizing (default, if available)
287  * @en_multiple_tx_fifo: Specifies whether dedicated per-endpoint transmit FIFOs
288  *                      are enabled
289  * @host_rx_fifo_size:  Number of 4-byte words in the Rx FIFO in host mode when
290  *                      dynamic FIFO sizing is enabled
291  *                       16 to 32768
292  *                      Actual maximum value is autodetected and also
293  *                      the default.
294  * @host_nperio_tx_fifo_size: Number of 4-byte words in the non-periodic Tx FIFO
295  *                      in host mode when dynamic FIFO sizing is enabled
296  *                       16 to 32768
297  *                      Actual maximum value is autodetected and also
298  *                      the default.
299  * @host_perio_tx_fifo_size: Number of 4-byte words in the periodic Tx FIFO in
300  *                      host mode when dynamic FIFO sizing is enabled
301  *                       16 to 32768
302  *                      Actual maximum value is autodetected and also
303  *                      the default.
304  * @max_transfer_size:  The maximum transfer size supported, in bytes
305  *                       2047 to 65,535
306  *                      Actual maximum value is autodetected and also
307  *                      the default.
308  * @max_packet_count:   The maximum number of packets in a transfer
309  *                       15 to 511
310  *                      Actual maximum value is autodetected and also
311  *                      the default.
312  * @host_channels:      The number of host channel registers to use
313  *                       1 to 16
314  *                      Actual maximum value is autodetected and also
315  *                      the default.
316  * @phy_type:           Specifies the type of PHY interface to use. By default,
317  *                      the driver will automatically detect the phy_type.
318  *                       0 - Full Speed Phy
319  *                       1 - UTMI+ Phy
320  *                       2 - ULPI Phy
321  *                      Defaults to best available option (2, 1, then 0)
322  * @phy_utmi_width:     Specifies the UTMI+ Data Width (in bits). This parameter
323  *                      is applicable for a phy_type of UTMI+ or ULPI. (For a
324  *                      ULPI phy_type, this parameter indicates the data width
325  *                      between the MAC and the ULPI Wrapper.) Also, this
326  *                      parameter is applicable only if the OTG_HSPHY_WIDTH cC
327  *                      parameter was set to "8 and 16 bits", meaning that the
328  *                      core has been configured to work at either data path
329  *                      width.
330  *                       8 or 16 (default 16 if available)
331  * @phy_ulpi_ddr:       Specifies whether the ULPI operates at double or single
332  *                      data rate. This parameter is only applicable if phy_type
333  *                      is ULPI.
334  *                       0 - single data rate ULPI interface with 8 bit wide
335  *                           data bus (default)
336  *                       1 - double data rate ULPI interface with 4 bit wide
337  *                           data bus
338  * @phy_ulpi_ext_vbus:  For a ULPI phy, specifies whether to use the internal or
339  *                      external supply to drive the VBus
340  *                       0 - Internal supply (default)
341  *                       1 - External supply
342  * @i2c_enable:         Specifies whether to use the I2Cinterface for a full
343  *                      speed PHY. This parameter is only applicable if phy_type
344  *                      is FS.
345  *                       0 - No (default)
346  *                       1 - Yes
347  * @ulpi_fs_ls:         Make ULPI phy operate in FS/LS mode only
348  *                       0 - No (default)
349  *                       1 - Yes
350  * @host_support_fs_ls_low_power: Specifies whether low power mode is supported
351  *                      when attached to a Full Speed or Low Speed device in
352  *                      host mode.
353  *                       0 - Don't support low power mode (default)
354  *                       1 - Support low power mode
355  * @host_ls_low_power_phy_clk: Specifies the PHY clock rate in low power mode
356  *                      when connected to a Low Speed device in host
357  *                      mode. This parameter is applicable only if
358  *                      host_support_fs_ls_low_power is enabled.
359  *                       0 - 48 MHz
360  *                           (default when phy_type is UTMI+ or ULPI)
361  *                       1 - 6 MHz
362  *                           (default when phy_type is Full Speed)
363  * @ts_dline:           Enable Term Select Dline pulsing
364  *                       0 - No (default)
365  *                       1 - Yes
366  * @reload_ctl:         Allow dynamic reloading of HFIR register during runtime
367  *                       0 - No (default for core < 2.92a)
368  *                       1 - Yes (default for core >= 2.92a)
369  * @ahbcfg:             This field allows the default value of the GAHBCFG
370  *                      register to be overridden
371  *                       -1         - GAHBCFG value will be set to 0x06
372  *                                    (INCR4, default)
373  *                       all others - GAHBCFG value will be overridden with
374  *                                    this value
375  *                      Not all bits can be controlled like this, the
376  *                      bits defined by GAHBCFG_CTRL_MASK are controlled
377  *                      by the driver and are ignored in this
378  *                      configuration value.
379  * @uframe_sched:       True to enable the microframe scheduler
380  * @external_id_pin_ctl: Specifies whether ID pin is handled externally.
381  *                      Disable CONIDSTSCHNG controller interrupt in such
382  *                      case.
383  *                      0 - No (default)
384  *                      1 - Yes
385  * @hibernation:        Specifies whether the controller support hibernation.
386  *                      If hibernation is enabled, the controller will enter
387  *                      hibernation in both peripheral and host mode when
388  *                      needed.
389  *                      0 - No (default)
390  *                      1 - Yes
391  *
392  * The following parameters may be specified when starting the module. These
393  * parameters define how the DWC_otg controller should be configured. A
394  * value of -1 (or any other out of range value) for any parameter means
395  * to read the value from hardware (if possible) or use the builtin
396  * default described above.
397  */
398 struct dwc2_core_params {
399         /*
400          * Don't add any non-int members here, this will break
401          * dwc2_set_all_params!
402          */
403         int otg_cap;
404         int otg_ver;
405         int dma_enable;
406         int dma_desc_enable;
407         int speed;
408         int enable_dynamic_fifo;
409         int en_multiple_tx_fifo;
410         int host_rx_fifo_size;
411         int host_nperio_tx_fifo_size;
412         int host_perio_tx_fifo_size;
413         int max_transfer_size;
414         int max_packet_count;
415         int host_channels;
416         int phy_type;
417         int phy_utmi_width;
418         int phy_ulpi_ddr;
419         int phy_ulpi_ext_vbus;
420         int i2c_enable;
421         int ulpi_fs_ls;
422         int host_support_fs_ls_low_power;
423         int host_ls_low_power_phy_clk;
424         int ts_dline;
425         int reload_ctl;
426         int ahbcfg;
427         int uframe_sched;
428         int external_id_pin_ctl;
429         int hibernation;
430 };
431
432 /**
433  * struct dwc2_hw_params - Autodetected parameters.
434  *
435  * These parameters are the various parameters read from hardware
436  * registers during initialization. They typically contain the best
437  * supported or maximum value that can be configured in the
438  * corresponding dwc2_core_params value.
439  *
440  * The values that are not in dwc2_core_params are documented below.
441  *
442  * @op_mode             Mode of Operation
443  *                       0 - HNP- and SRP-Capable OTG (Host & Device)
444  *                       1 - SRP-Capable OTG (Host & Device)
445  *                       2 - Non-HNP and Non-SRP Capable OTG (Host & Device)
446  *                       3 - SRP-Capable Device
447  *                       4 - Non-OTG Device
448  *                       5 - SRP-Capable Host
449  *                       6 - Non-OTG Host
450  * @arch                Architecture
451  *                       0 - Slave only
452  *                       1 - External DMA
453  *                       2 - Internal DMA
454  * @power_optimized     Are power optimizations enabled?
455  * @num_dev_ep          Number of device endpoints available
456  * @num_dev_perio_in_ep Number of device periodic IN endpoints
457  *                      available
458  * @dev_token_q_depth   Device Mode IN Token Sequence Learning Queue
459  *                      Depth
460  *                       0 to 30
461  * @host_perio_tx_q_depth
462  *                      Host Mode Periodic Request Queue Depth
463  *                       2, 4 or 8
464  * @nperio_tx_q_depth
465  *                      Non-Periodic Request Queue Depth
466  *                       2, 4 or 8
467  * @hs_phy_type         High-speed PHY interface type
468  *                       0 - High-speed interface not supported
469  *                       1 - UTMI+
470  *                       2 - ULPI
471  *                       3 - UTMI+ and ULPI
472  * @fs_phy_type         Full-speed PHY interface type
473  *                       0 - Full speed interface not supported
474  *                       1 - Dedicated full speed interface
475  *                       2 - FS pins shared with UTMI+ pins
476  *                       3 - FS pins shared with ULPI pins
477  * @total_fifo_size:    Total internal RAM for FIFOs (bytes)
478  * @utmi_phy_data_width UTMI+ PHY data width
479  *                       0 - 8 bits
480  *                       1 - 16 bits
481  *                       2 - 8 or 16 bits
482  * @snpsid:             Value from SNPSID register
483  */
484 struct dwc2_hw_params {
485         unsigned op_mode:3;
486         unsigned arch:2;
487         unsigned dma_desc_enable:1;
488         unsigned enable_dynamic_fifo:1;
489         unsigned en_multiple_tx_fifo:1;
490         unsigned host_rx_fifo_size:16;
491         unsigned host_nperio_tx_fifo_size:16;
492         unsigned host_perio_tx_fifo_size:16;
493         unsigned nperio_tx_q_depth:3;
494         unsigned host_perio_tx_q_depth:3;
495         unsigned dev_token_q_depth:5;
496         unsigned max_transfer_size:26;
497         unsigned max_packet_count:11;
498         unsigned host_channels:5;
499         unsigned hs_phy_type:2;
500         unsigned fs_phy_type:2;
501         unsigned i2c_enable:1;
502         unsigned num_dev_ep:4;
503         unsigned num_dev_perio_in_ep:4;
504         unsigned total_fifo_size:16;
505         unsigned power_optimized:1;
506         unsigned utmi_phy_data_width:2;
507         u32 snpsid;
508 };
509
510 /* Size of control and EP0 buffers */
511 #define DWC2_CTRL_BUFF_SIZE 8
512
513 /**
514  * struct dwc2_gregs_backup - Holds global registers state before entering partial
515  * power down
516  * @gotgctl:            Backup of GOTGCTL register
517  * @gintmsk:            Backup of GINTMSK register
518  * @gahbcfg:            Backup of GAHBCFG register
519  * @gusbcfg:            Backup of GUSBCFG register
520  * @grxfsiz:            Backup of GRXFSIZ register
521  * @gnptxfsiz:          Backup of GNPTXFSIZ register
522  * @gi2cctl:            Backup of GI2CCTL register
523  * @hptxfsiz:           Backup of HPTXFSIZ register
524  * @gdfifocfg:          Backup of GDFIFOCFG register
525  * @dtxfsiz:            Backup of DTXFSIZ registers for each endpoint
526  * @gpwrdn:             Backup of GPWRDN register
527  */
528 struct dwc2_gregs_backup {
529         u32 gotgctl;
530         u32 gintmsk;
531         u32 gahbcfg;
532         u32 gusbcfg;
533         u32 grxfsiz;
534         u32 gnptxfsiz;
535         u32 gi2cctl;
536         u32 hptxfsiz;
537         u32 pcgcctl;
538         u32 gdfifocfg;
539         u32 dtxfsiz[MAX_EPS_CHANNELS];
540         u32 gpwrdn;
541         bool valid;
542 };
543
544 /**
545  * struct  dwc2_dregs_backup - Holds device registers state before entering partial
546  * power down
547  * @dcfg:               Backup of DCFG register
548  * @dctl:               Backup of DCTL register
549  * @daintmsk:           Backup of DAINTMSK register
550  * @diepmsk:            Backup of DIEPMSK register
551  * @doepmsk:            Backup of DOEPMSK register
552  * @diepctl:            Backup of DIEPCTL register
553  * @dieptsiz:           Backup of DIEPTSIZ register
554  * @diepdma:            Backup of DIEPDMA register
555  * @doepctl:            Backup of DOEPCTL register
556  * @doeptsiz:           Backup of DOEPTSIZ register
557  * @doepdma:            Backup of DOEPDMA register
558  */
559 struct dwc2_dregs_backup {
560         u32 dcfg;
561         u32 dctl;
562         u32 daintmsk;
563         u32 diepmsk;
564         u32 doepmsk;
565         u32 diepctl[MAX_EPS_CHANNELS];
566         u32 dieptsiz[MAX_EPS_CHANNELS];
567         u32 diepdma[MAX_EPS_CHANNELS];
568         u32 doepctl[MAX_EPS_CHANNELS];
569         u32 doeptsiz[MAX_EPS_CHANNELS];
570         u32 doepdma[MAX_EPS_CHANNELS];
571         bool valid;
572 };
573
574 /**
575  * struct  dwc2_hregs_backup - Holds host registers state before entering partial
576  * power down
577  * @hcfg:               Backup of HCFG register
578  * @haintmsk:           Backup of HAINTMSK register
579  * @hcintmsk:           Backup of HCINTMSK register
580  * @hptr0:              Backup of HPTR0 register
581  * @hfir:               Backup of HFIR register
582  */
583 struct dwc2_hregs_backup {
584         u32 hcfg;
585         u32 haintmsk;
586         u32 hcintmsk[MAX_EPS_CHANNELS];
587         u32 hprt0;
588         u32 hfir;
589         bool valid;
590 };
591
592 /**
593  * struct dwc2_hsotg - Holds the state of the driver, including the non-periodic
594  * and periodic schedules
595  *
596  * These are common for both host and peripheral modes:
597  *
598  * @dev:                The struct device pointer
599  * @regs:               Pointer to controller regs
600  * @hw_params:          Parameters that were autodetected from the
601  *                      hardware registers
602  * @core_params:        Parameters that define how the core should be configured
603  * @op_state:           The operational State, during transitions (a_host=>
604  *                      a_peripheral and b_device=>b_host) this may not match
605  *                      the core, but allows the software to determine
606  *                      transitions
607  * @dr_mode:            Requested mode of operation, one of following:
608  *                      - USB_DR_MODE_PERIPHERAL
609  *                      - USB_DR_MODE_HOST
610  *                      - USB_DR_MODE_OTG
611  * @hcd_enabled         Host mode sub-driver initialization indicator.
612  * @gadget_enabled      Peripheral mode sub-driver initialization indicator.
613  * @ll_hw_enabled       Status of low-level hardware resources.
614  * @phy:                The otg phy transceiver structure for phy control.
615  * @uphy:               The otg phy transceiver structure for old USB phy control.
616  * @plat:               The platform specific configuration data. This can be removed once
617  *                      all SoCs support usb transceiver.
618  * @supplies:           Definition of USB power supplies
619  * @phyif:              PHY interface width
620  * @lock:               Spinlock that protects all the driver data structures
621  * @priv:               Stores a pointer to the struct usb_hcd
622  * @queuing_high_bandwidth: True if multiple packets of a high-bandwidth
623  *                      transfer are in process of being queued
624  * @srp_success:        Stores status of SRP request in the case of a FS PHY
625  *                      with an I2C interface
626  * @wq_otg:             Workqueue object used for handling of some interrupts
627  * @wf_otg:             Work object for handling Connector ID Status Change
628  *                      interrupt
629  * @wkp_timer:          Timer object for handling Wakeup Detected interrupt
630  * @lx_state:           Lx state of connected device
631  * @gregs_backup: Backup of global registers during suspend
632  * @dregs_backup: Backup of device registers during suspend
633  * @hregs_backup: Backup of host registers during suspend
634  *
635  * These are for host mode:
636  *
637  * @flags:              Flags for handling root port state changes
638  * @non_periodic_sched_inactive: Inactive QHs in the non-periodic schedule.
639  *                      Transfers associated with these QHs are not currently
640  *                      assigned to a host channel.
641  * @non_periodic_sched_active: Active QHs in the non-periodic schedule.
642  *                      Transfers associated with these QHs are currently
643  *                      assigned to a host channel.
644  * @non_periodic_qh_ptr: Pointer to next QH to process in the active
645  *                      non-periodic schedule
646  * @periodic_sched_inactive: Inactive QHs in the periodic schedule. This is a
647  *                      list of QHs for periodic transfers that are _not_
648  *                      scheduled for the next frame. Each QH in the list has an
649  *                      interval counter that determines when it needs to be
650  *                      scheduled for execution. This scheduling mechanism
651  *                      allows only a simple calculation for periodic bandwidth
652  *                      used (i.e. must assume that all periodic transfers may
653  *                      need to execute in the same frame). However, it greatly
654  *                      simplifies scheduling and should be sufficient for the
655  *                      vast majority of OTG hosts, which need to connect to a
656  *                      small number of peripherals at one time. Items move from
657  *                      this list to periodic_sched_ready when the QH interval
658  *                      counter is 0 at SOF.
659  * @periodic_sched_ready:  List of periodic QHs that are ready for execution in
660  *                      the next frame, but have not yet been assigned to host
661  *                      channels. Items move from this list to
662  *                      periodic_sched_assigned as host channels become
663  *                      available during the current frame.
664  * @periodic_sched_assigned: List of periodic QHs to be executed in the next
665  *                      frame that are assigned to host channels. Items move
666  *                      from this list to periodic_sched_queued as the
667  *                      transactions for the QH are queued to the DWC_otg
668  *                      controller.
669  * @periodic_sched_queued: List of periodic QHs that have been queued for
670  *                      execution. Items move from this list to either
671  *                      periodic_sched_inactive or periodic_sched_ready when the
672  *                      channel associated with the transfer is released. If the
673  *                      interval for the QH is 1, the item moves to
674  *                      periodic_sched_ready because it must be rescheduled for
675  *                      the next frame. Otherwise, the item moves to
676  *                      periodic_sched_inactive.
677  * @periodic_usecs:     Total bandwidth claimed so far for periodic transfers.
678  *                      This value is in microseconds per (micro)frame. The
679  *                      assumption is that all periodic transfers may occur in
680  *                      the same (micro)frame.
681  * @frame_usecs:        Internal variable used by the microframe scheduler
682  * @frame_number:       Frame number read from the core at SOF. The value ranges
683  *                      from 0 to HFNUM_MAX_FRNUM.
684  * @periodic_qh_count:  Count of periodic QHs, if using several eps. Used for
685  *                      SOF enable/disable.
686  * @free_hc_list:       Free host channels in the controller. This is a list of
687  *                      struct dwc2_host_chan items.
688  * @periodic_channels:  Number of host channels assigned to periodic transfers.
689  *                      Currently assuming that there is a dedicated host
690  *                      channel for each periodic transaction and at least one
691  *                      host channel is available for non-periodic transactions.
692  * @non_periodic_channels: Number of host channels assigned to non-periodic
693  *                      transfers
694  * @available_host_channels Number of host channels available for the microframe
695  *                      scheduler to use
696  * @hc_ptr_array:       Array of pointers to the host channel descriptors.
697  *                      Allows accessing a host channel descriptor given the
698  *                      host channel number. This is useful in interrupt
699  *                      handlers.
700  * @status_buf:         Buffer used for data received during the status phase of
701  *                      a control transfer.
702  * @status_buf_dma:     DMA address for status_buf
703  * @start_work:         Delayed work for handling host A-cable connection
704  * @reset_work:         Delayed work for handling a port reset
705  * @otg_port:           OTG port number
706  * @frame_list:         Frame list
707  * @frame_list_dma:     Frame list DMA address
708  *
709  * These are for peripheral mode:
710  *
711  * @driver:             USB gadget driver
712  * @dedicated_fifos:    Set if the hardware has dedicated IN-EP fifos.
713  * @num_of_eps:         Number of available EPs (excluding EP0)
714  * @debug_root:         Root directrory for debugfs.
715  * @debug_file:         Main status file for debugfs.
716  * @debug_testmode:     Testmode status file for debugfs.
717  * @debug_fifo:         FIFO status file for debugfs.
718  * @ep0_reply:          Request used for ep0 reply.
719  * @ep0_buff:           Buffer for EP0 reply data, if needed.
720  * @ctrl_buff:          Buffer for EP0 control requests.
721  * @ctrl_req:           Request for EP0 control packets.
722  * @ep0_state:          EP0 control transfers state
723  * @test_mode:          USB test mode requested by the host
724  * @eps:                The endpoints being supplied to the gadget framework
725  * @g_using_dma:          Indicate if dma usage is enabled
726  * @g_rx_fifo_sz:         Contains rx fifo size value
727  * @g_np_g_tx_fifo_sz:      Contains Non-Periodic tx fifo size value
728  * @g_tx_fifo_sz:         Contains tx fifo size value per endpoints
729  */
730 struct dwc2_hsotg {
731         struct device *dev;
732         void __iomem *regs;
733         /** Params detected from hardware */
734         struct dwc2_hw_params hw_params;
735         /** Params to actually use */
736         struct dwc2_core_params *core_params;
737         enum usb_otg_state op_state;
738         enum usb_dr_mode dr_mode;
739         unsigned int hcd_enabled:1;
740         unsigned int gadget_enabled:1;
741         unsigned int ll_hw_enabled:1;
742
743         struct phy *phy;
744         struct usb_phy *uphy;
745         struct dwc2_hsotg_plat *plat;
746         struct regulator_bulk_data supplies[ARRAY_SIZE(dwc2_hsotg_supply_names)];
747         u32 phyif;
748
749         spinlock_t lock;
750         void *priv;
751         int     irq;
752         struct clk *clk;
753
754         unsigned int queuing_high_bandwidth:1;
755         unsigned int srp_success:1;
756
757         struct workqueue_struct *wq_otg;
758         struct work_struct wf_otg;
759         struct timer_list wkp_timer;
760         enum dwc2_lx_state lx_state;
761         struct dwc2_gregs_backup gr_backup;
762         struct dwc2_dregs_backup dr_backup;
763         struct dwc2_hregs_backup hr_backup;
764
765         struct dentry *debug_root;
766         struct debugfs_regset32 *regset;
767
768         /* DWC OTG HW Release versions */
769 #define DWC2_CORE_REV_2_71a     0x4f54271a
770 #define DWC2_CORE_REV_2_90a     0x4f54290a
771 #define DWC2_CORE_REV_2_92a     0x4f54292a
772 #define DWC2_CORE_REV_2_94a     0x4f54294a
773 #define DWC2_CORE_REV_3_00a     0x4f54300a
774
775 #if IS_ENABLED(CONFIG_USB_DWC2_HOST) || IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE)
776         union dwc2_hcd_internal_flags {
777                 u32 d32;
778                 struct {
779                         unsigned port_connect_status_change:1;
780                         unsigned port_connect_status:1;
781                         unsigned port_reset_change:1;
782                         unsigned port_enable_change:1;
783                         unsigned port_suspend_change:1;
784                         unsigned port_over_current_change:1;
785                         unsigned port_l1_change:1;
786                         unsigned reserved:25;
787                 } b;
788         } flags;
789
790         struct list_head non_periodic_sched_inactive;
791         struct list_head non_periodic_sched_active;
792         struct list_head *non_periodic_qh_ptr;
793         struct list_head periodic_sched_inactive;
794         struct list_head periodic_sched_ready;
795         struct list_head periodic_sched_assigned;
796         struct list_head periodic_sched_queued;
797         u16 periodic_usecs;
798         u16 frame_usecs[8];
799         u16 frame_number;
800         u16 periodic_qh_count;
801         bool bus_suspended;
802
803 #ifdef CONFIG_USB_DWC2_TRACK_MISSED_SOFS
804 #define FRAME_NUM_ARRAY_SIZE 1000
805         u16 last_frame_num;
806         u16 *frame_num_array;
807         u16 *last_frame_num_array;
808         int frame_num_idx;
809         int dumped_frame_num_array;
810 #endif
811
812         struct list_head free_hc_list;
813         int periodic_channels;
814         int non_periodic_channels;
815         int available_host_channels;
816         struct dwc2_host_chan *hc_ptr_array[MAX_EPS_CHANNELS];
817         u8 *status_buf;
818         dma_addr_t status_buf_dma;
819 #define DWC2_HCD_STATUS_BUF_SIZE 64
820
821         struct delayed_work start_work;
822         struct delayed_work reset_work;
823         u8 otg_port;
824         u32 *frame_list;
825         dma_addr_t frame_list_dma;
826
827 #ifdef DEBUG
828         u32 frrem_samples;
829         u64 frrem_accum;
830
831         u32 hfnum_7_samples_a;
832         u64 hfnum_7_frrem_accum_a;
833         u32 hfnum_0_samples_a;
834         u64 hfnum_0_frrem_accum_a;
835         u32 hfnum_other_samples_a;
836         u64 hfnum_other_frrem_accum_a;
837
838         u32 hfnum_7_samples_b;
839         u64 hfnum_7_frrem_accum_b;
840         u32 hfnum_0_samples_b;
841         u64 hfnum_0_frrem_accum_b;
842         u32 hfnum_other_samples_b;
843         u64 hfnum_other_frrem_accum_b;
844 #endif
845 #endif /* CONFIG_USB_DWC2_HOST || CONFIG_USB_DWC2_DUAL_ROLE */
846
847 #if IS_ENABLED(CONFIG_USB_DWC2_PERIPHERAL) || IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE)
848         /* Gadget structures */
849         struct usb_gadget_driver *driver;
850         int fifo_mem;
851         unsigned int dedicated_fifos:1;
852         unsigned char num_of_eps;
853         u32 fifo_map;
854
855         struct usb_request *ep0_reply;
856         struct usb_request *ctrl_req;
857         void *ep0_buff;
858         void *ctrl_buff;
859         enum dwc2_ep0_state ep0_state;
860         u8 test_mode;
861
862         struct usb_gadget gadget;
863         unsigned int enabled:1;
864         unsigned int connected:1;
865         struct dwc2_hsotg_ep *eps_in[MAX_EPS_CHANNELS];
866         struct dwc2_hsotg_ep *eps_out[MAX_EPS_CHANNELS];
867         u32 g_using_dma;
868         u32 g_rx_fifo_sz;
869         u32 g_np_g_tx_fifo_sz;
870         u32 g_tx_fifo_sz[MAX_EPS_CHANNELS];
871 #endif /* CONFIG_USB_DWC2_PERIPHERAL || CONFIG_USB_DWC2_DUAL_ROLE */
872 };
873
874 /* Reasons for halting a host channel */
875 enum dwc2_halt_status {
876         DWC2_HC_XFER_NO_HALT_STATUS,
877         DWC2_HC_XFER_COMPLETE,
878         DWC2_HC_XFER_URB_COMPLETE,
879         DWC2_HC_XFER_ACK,
880         DWC2_HC_XFER_NAK,
881         DWC2_HC_XFER_NYET,
882         DWC2_HC_XFER_STALL,
883         DWC2_HC_XFER_XACT_ERR,
884         DWC2_HC_XFER_FRAME_OVERRUN,
885         DWC2_HC_XFER_BABBLE_ERR,
886         DWC2_HC_XFER_DATA_TOGGLE_ERR,
887         DWC2_HC_XFER_AHB_ERR,
888         DWC2_HC_XFER_PERIODIC_INCOMPLETE,
889         DWC2_HC_XFER_URB_DEQUEUE,
890 };
891
892 /*
893  * The following functions support initialization of the core driver component
894  * and the DWC_otg controller
895  */
896 extern void dwc2_core_host_init(struct dwc2_hsotg *hsotg);
897 extern int dwc2_enter_hibernation(struct dwc2_hsotg *hsotg);
898 extern int dwc2_exit_hibernation(struct dwc2_hsotg *hsotg, bool restore);
899
900 /*
901  * Host core Functions.
902  * The following functions support managing the DWC_otg controller in host
903  * mode.
904  */
905 extern void dwc2_hc_init(struct dwc2_hsotg *hsotg, struct dwc2_host_chan *chan);
906 extern void dwc2_hc_halt(struct dwc2_hsotg *hsotg, struct dwc2_host_chan *chan,
907                          enum dwc2_halt_status halt_status);
908 extern void dwc2_hc_cleanup(struct dwc2_hsotg *hsotg,
909                             struct dwc2_host_chan *chan);
910 extern void dwc2_hc_start_transfer(struct dwc2_hsotg *hsotg,
911                                    struct dwc2_host_chan *chan);
912 extern void dwc2_hc_start_transfer_ddma(struct dwc2_hsotg *hsotg,
913                                         struct dwc2_host_chan *chan);
914 extern int dwc2_hc_continue_transfer(struct dwc2_hsotg *hsotg,
915                                      struct dwc2_host_chan *chan);
916 extern void dwc2_hc_do_ping(struct dwc2_hsotg *hsotg,
917                             struct dwc2_host_chan *chan);
918 extern void dwc2_enable_host_interrupts(struct dwc2_hsotg *hsotg);
919 extern void dwc2_disable_host_interrupts(struct dwc2_hsotg *hsotg);
920
921 extern u32 dwc2_calc_frame_interval(struct dwc2_hsotg *hsotg);
922 extern bool dwc2_is_controller_alive(struct dwc2_hsotg *hsotg);
923
924 /*
925  * Common core Functions.
926  * The following functions support managing the DWC_otg controller in either
927  * device or host mode.
928  */
929 extern void dwc2_read_packet(struct dwc2_hsotg *hsotg, u8 *dest, u16 bytes);
930 extern void dwc2_flush_tx_fifo(struct dwc2_hsotg *hsotg, const int num);
931 extern void dwc2_flush_rx_fifo(struct dwc2_hsotg *hsotg);
932
933 extern int dwc2_core_init(struct dwc2_hsotg *hsotg, bool select_phy, int irq);
934 extern void dwc2_enable_global_interrupts(struct dwc2_hsotg *hcd);
935 extern void dwc2_disable_global_interrupts(struct dwc2_hsotg *hcd);
936
937 /* This function should be called on every hardware interrupt. */
938 extern irqreturn_t dwc2_handle_common_intr(int irq, void *dev);
939
940 /* OTG Core Parameters */
941
942 /*
943  * Specifies the OTG capabilities. The driver will automatically
944  * detect the value for this parameter if none is specified.
945  * 0 - HNP and SRP capable (default)
946  * 1 - SRP Only capable
947  * 2 - No HNP/SRP capable
948  */
949 extern void dwc2_set_param_otg_cap(struct dwc2_hsotg *hsotg, int val);
950 #define DWC2_CAP_PARAM_HNP_SRP_CAPABLE          0
951 #define DWC2_CAP_PARAM_SRP_ONLY_CAPABLE         1
952 #define DWC2_CAP_PARAM_NO_HNP_SRP_CAPABLE       2
953
954 /*
955  * Specifies whether to use slave or DMA mode for accessing the data
956  * FIFOs. The driver will automatically detect the value for this
957  * parameter if none is specified.
958  * 0 - Slave
959  * 1 - DMA (default, if available)
960  */
961 extern void dwc2_set_param_dma_enable(struct dwc2_hsotg *hsotg, int val);
962
963 /*
964  * When DMA mode is enabled specifies whether to use
965  * address DMA or DMA Descritor mode for accessing the data
966  * FIFOs in device mode. The driver will automatically detect
967  * the value for this parameter if none is specified.
968  * 0 - address DMA
969  * 1 - DMA Descriptor(default, if available)
970  */
971 extern void dwc2_set_param_dma_desc_enable(struct dwc2_hsotg *hsotg, int val);
972
973 /*
974  * Specifies the maximum speed of operation in host and device mode.
975  * The actual speed depends on the speed of the attached device and
976  * the value of phy_type. The actual speed depends on the speed of the
977  * attached device.
978  * 0 - High Speed (default)
979  * 1 - Full Speed
980  */
981 extern void dwc2_set_param_speed(struct dwc2_hsotg *hsotg, int val);
982 #define DWC2_SPEED_PARAM_HIGH   0
983 #define DWC2_SPEED_PARAM_FULL   1
984
985 /*
986  * Specifies whether low power mode is supported when attached
987  * to a Full Speed or Low Speed device in host mode.
988  *
989  * 0 - Don't support low power mode (default)
990  * 1 - Support low power mode
991  */
992 extern void dwc2_set_param_host_support_fs_ls_low_power(
993                 struct dwc2_hsotg *hsotg, int val);
994
995 /*
996  * Specifies the PHY clock rate in low power mode when connected to a
997  * Low Speed device in host mode. This parameter is applicable only if
998  * HOST_SUPPORT_FS_LS_LOW_POWER is enabled. If PHY_TYPE is set to FS
999  * then defaults to 6 MHZ otherwise 48 MHZ.
1000  *
1001  * 0 - 48 MHz
1002  * 1 - 6 MHz
1003  */
1004 extern void dwc2_set_param_host_ls_low_power_phy_clk(struct dwc2_hsotg *hsotg,
1005                                                      int val);
1006 #define DWC2_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ      0
1007 #define DWC2_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ       1
1008
1009 /*
1010  * 0 - Use cC FIFO size parameters
1011  * 1 - Allow dynamic FIFO sizing (default)
1012  */
1013 extern void dwc2_set_param_enable_dynamic_fifo(struct dwc2_hsotg *hsotg,
1014                                                int val);
1015
1016 /*
1017  * Number of 4-byte words in the Rx FIFO in host mode when dynamic
1018  * FIFO sizing is enabled.
1019  * 16 to 32768 (default 1024)
1020  */
1021 extern void dwc2_set_param_host_rx_fifo_size(struct dwc2_hsotg *hsotg, int val);
1022
1023 /*
1024  * Number of 4-byte words in the non-periodic Tx FIFO in host mode
1025  * when Dynamic FIFO sizing is enabled in the core.
1026  * 16 to 32768 (default 256)
1027  */
1028 extern void dwc2_set_param_host_nperio_tx_fifo_size(struct dwc2_hsotg *hsotg,
1029                                                     int val);
1030
1031 /*
1032  * Number of 4-byte words in the host periodic Tx FIFO when dynamic
1033  * FIFO sizing is enabled.
1034  * 16 to 32768 (default 256)
1035  */
1036 extern void dwc2_set_param_host_perio_tx_fifo_size(struct dwc2_hsotg *hsotg,
1037                                                    int val);
1038
1039 /*
1040  * The maximum transfer size supported in bytes.
1041  * 2047 to 65,535  (default 65,535)
1042  */
1043 extern void dwc2_set_param_max_transfer_size(struct dwc2_hsotg *hsotg, int val);
1044
1045 /*
1046  * The maximum number of packets in a transfer.
1047  * 15 to 511  (default 511)
1048  */
1049 extern void dwc2_set_param_max_packet_count(struct dwc2_hsotg *hsotg, int val);
1050
1051 /*
1052  * The number of host channel registers to use.
1053  * 1 to 16 (default 11)
1054  * Note: The FPGA configuration supports a maximum of 11 host channels.
1055  */
1056 extern void dwc2_set_param_host_channels(struct dwc2_hsotg *hsotg, int val);
1057
1058 /*
1059  * Specifies the type of PHY interface to use. By default, the driver
1060  * will automatically detect the phy_type.
1061  *
1062  * 0 - Full Speed PHY
1063  * 1 - UTMI+ (default)
1064  * 2 - ULPI
1065  */
1066 extern void dwc2_set_param_phy_type(struct dwc2_hsotg *hsotg, int val);
1067 #define DWC2_PHY_TYPE_PARAM_FS          0
1068 #define DWC2_PHY_TYPE_PARAM_UTMI        1
1069 #define DWC2_PHY_TYPE_PARAM_ULPI        2
1070
1071 /*
1072  * Specifies the UTMI+ Data Width. This parameter is
1073  * applicable for a PHY_TYPE of UTMI+ or ULPI. (For a ULPI
1074  * PHY_TYPE, this parameter indicates the data width between
1075  * the MAC and the ULPI Wrapper.) Also, this parameter is
1076  * applicable only if the OTG_HSPHY_WIDTH cC parameter was set
1077  * to "8 and 16 bits", meaning that the core has been
1078  * configured to work at either data path width.
1079  *
1080  * 8 or 16 bits (default 16)
1081  */
1082 extern void dwc2_set_param_phy_utmi_width(struct dwc2_hsotg *hsotg, int val);
1083
1084 /*
1085  * Specifies whether the ULPI operates at double or single
1086  * data rate. This parameter is only applicable if PHY_TYPE is
1087  * ULPI.
1088  *
1089  * 0 - single data rate ULPI interface with 8 bit wide data
1090  * bus (default)
1091  * 1 - double data rate ULPI interface with 4 bit wide data
1092  * bus
1093  */
1094 extern void dwc2_set_param_phy_ulpi_ddr(struct dwc2_hsotg *hsotg, int val);
1095
1096 /*
1097  * Specifies whether to use the internal or external supply to
1098  * drive the vbus with a ULPI phy.
1099  */
1100 extern void dwc2_set_param_phy_ulpi_ext_vbus(struct dwc2_hsotg *hsotg, int val);
1101 #define DWC2_PHY_ULPI_INTERNAL_VBUS     0
1102 #define DWC2_PHY_ULPI_EXTERNAL_VBUS     1
1103
1104 /*
1105  * Specifies whether to use the I2Cinterface for full speed PHY. This
1106  * parameter is only applicable if PHY_TYPE is FS.
1107  * 0 - No (default)
1108  * 1 - Yes
1109  */
1110 extern void dwc2_set_param_i2c_enable(struct dwc2_hsotg *hsotg, int val);
1111
1112 extern void dwc2_set_param_ulpi_fs_ls(struct dwc2_hsotg *hsotg, int val);
1113
1114 extern void dwc2_set_param_ts_dline(struct dwc2_hsotg *hsotg, int val);
1115
1116 /*
1117  * Specifies whether dedicated transmit FIFOs are
1118  * enabled for non periodic IN endpoints in device mode
1119  * 0 - No
1120  * 1 - Yes
1121  */
1122 extern void dwc2_set_param_en_multiple_tx_fifo(struct dwc2_hsotg *hsotg,
1123                                                int val);
1124
1125 extern void dwc2_set_param_reload_ctl(struct dwc2_hsotg *hsotg, int val);
1126
1127 extern void dwc2_set_param_ahbcfg(struct dwc2_hsotg *hsotg, int val);
1128
1129 extern void dwc2_set_param_otg_ver(struct dwc2_hsotg *hsotg, int val);
1130
1131 extern void dwc2_set_parameters(struct dwc2_hsotg *hsotg,
1132                                 const struct dwc2_core_params *params);
1133
1134 extern void dwc2_set_all_params(struct dwc2_core_params *params, int value);
1135
1136 extern int dwc2_get_hwparams(struct dwc2_hsotg *hsotg);
1137
1138 extern int dwc2_lowlevel_hw_enable(struct dwc2_hsotg *hsotg);
1139 extern int dwc2_lowlevel_hw_disable(struct dwc2_hsotg *hsotg);
1140
1141 /*
1142  * Dump core registers and SPRAM
1143  */
1144 extern void dwc2_dump_dev_registers(struct dwc2_hsotg *hsotg);
1145 extern void dwc2_dump_host_registers(struct dwc2_hsotg *hsotg);
1146 extern void dwc2_dump_global_registers(struct dwc2_hsotg *hsotg);
1147
1148 /*
1149  * Return OTG version - either 1.3 or 2.0
1150  */
1151 extern u16 dwc2_get_otg_version(struct dwc2_hsotg *hsotg);
1152
1153 /* Gadget defines */
1154 #if IS_ENABLED(CONFIG_USB_DWC2_PERIPHERAL) || IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE)
1155 extern int dwc2_hsotg_remove(struct dwc2_hsotg *hsotg);
1156 extern int dwc2_hsotg_suspend(struct dwc2_hsotg *dwc2);
1157 extern int dwc2_hsotg_resume(struct dwc2_hsotg *dwc2);
1158 extern int dwc2_gadget_init(struct dwc2_hsotg *hsotg, int irq);
1159 extern void dwc2_hsotg_core_init_disconnected(struct dwc2_hsotg *dwc2,
1160                 bool reset);
1161 extern void dwc2_hsotg_core_connect(struct dwc2_hsotg *hsotg);
1162 extern void dwc2_hsotg_disconnect(struct dwc2_hsotg *dwc2);
1163 extern int dwc2_hsotg_set_test_mode(struct dwc2_hsotg *hsotg, int testmode);
1164 #define dwc2_is_device_connected(hsotg) (hsotg->connected)
1165 #else
1166 static inline int dwc2_hsotg_remove(struct dwc2_hsotg *dwc2)
1167 { return 0; }
1168 static inline int dwc2_hsotg_suspend(struct dwc2_hsotg *dwc2)
1169 { return 0; }
1170 static inline int dwc2_hsotg_resume(struct dwc2_hsotg *dwc2)
1171 { return 0; }
1172 static inline int dwc2_gadget_init(struct dwc2_hsotg *hsotg, int irq)
1173 { return 0; }
1174 static inline void dwc2_hsotg_core_init_disconnected(struct dwc2_hsotg *dwc2,
1175                 bool reset) {}
1176 static inline void dwc2_hsotg_core_connect(struct dwc2_hsotg *hsotg) {}
1177 static inline void dwc2_hsotg_disconnect(struct dwc2_hsotg *dwc2) {}
1178 static inline int dwc2_hsotg_set_test_mode(struct dwc2_hsotg *hsotg,
1179                                                         int testmode)
1180 { return 0; }
1181 #define dwc2_is_device_connected(hsotg) (0)
1182 #endif
1183
1184 #if IS_ENABLED(CONFIG_USB_DWC2_HOST) || IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE)
1185 extern int dwc2_hcd_get_frame_number(struct dwc2_hsotg *hsotg);
1186 extern void dwc2_hcd_disconnect(struct dwc2_hsotg *hsotg);
1187 extern void dwc2_hcd_start(struct dwc2_hsotg *hsotg);
1188 #else
1189 static inline int dwc2_hcd_get_frame_number(struct dwc2_hsotg *hsotg)
1190 { return 0; }
1191 static inline void dwc2_hcd_disconnect(struct dwc2_hsotg *hsotg) {}
1192 static inline void dwc2_hcd_start(struct dwc2_hsotg *hsotg) {}
1193 static inline void dwc2_hcd_remove(struct dwc2_hsotg *hsotg) {}
1194 static inline int dwc2_hcd_init(struct dwc2_hsotg *hsotg, int irq)
1195 { return 0; }
1196 #endif
1197
1198 #endif /* __DWC2_CORE_H__ */