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