Merge tag 'lsk-v3.10-15.04-android'
[firefly-linux-kernel-4.4.55.git] / drivers / usb / dwc_otg_310 / dwc_otg_cil.h
1 /* ==========================================================================
2  * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_cil.h $
3  * $Revision: #127 $
4  * $Date: 2012/12/21 $
5  * $Change: 2131568 $
6  *
7  * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
8  * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
9  * otherwise expressly agreed to in writing between Synopsys and you.
10  *
11  * The Software IS NOT an item of Licensed Software or Licensed Product under
12  * any End User Software License Agreement or Agreement for Licensed Product
13  * with Synopsys or any supplement thereto. You are permitted to use and
14  * redistribute this Software in source and binary forms, with or without
15  * modification, provided that redistributions of source code must retain this
16  * notice. You may not view, use, disclose, copy or distribute this file or
17  * any information contained herein except pursuant to this license grant from
18  * Synopsys. If you do not agree with this notice, including the disclaimer
19  * below, then you are not authorized to use the Software.
20  *
21  * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
25  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
31  * DAMAGE.
32  * ========================================================================== */
33
34 #if !defined(__DWC_CIL_H__)
35 #define __DWC_CIL_H__
36
37 #include "common_port/dwc_list.h"
38 #include "dwc_otg_dbg.h"
39 #include "dwc_otg_regs.h"
40
41 #include "dwc_otg_core_if.h"
42 #include "dwc_otg_adp.h"
43
44 /**
45  * @file
46  * This file contains the interface to the Core Interface Layer.
47  */
48
49 #ifdef DWC_UTE_CFI
50
51 #define MAX_DMA_DESCS_PER_EP    256
52
53 /**
54  * Enumeration for the data buffer mode
55  */
56 typedef enum _data_buffer_mode {
57         BM_STANDARD = 0,        /* data buffer is in normal mode */
58         BM_SG = 1,              /* data buffer uses the scatter/gather mode */
59         BM_CONCAT = 2,          /* data buffer uses the concatenation mode */
60         BM_CIRCULAR = 3,        /* data buffer uses the circular DMA mode */
61         BM_ALIGN = 4            /* data buffer is in buffer alignment mode */
62 } data_buffer_mode_e;
63 #endif /* DWC_UTE_CFI */
64
65 /** Macros defined for DWC OTG HW Release version */
66
67 #define OTG_CORE_REV_2_60a      0x4F54260A
68 #define OTG_CORE_REV_2_71a      0x4F54271A
69 #define OTG_CORE_REV_2_72a      0x4F54272A
70 #define OTG_CORE_REV_2_80a      0x4F54280A
71 #define OTG_CORE_REV_2_81a      0x4F54281A
72 #define OTG_CORE_REV_2_90a      0x4F54290A
73 #define OTG_CORE_REV_2_91a      0x4F54291A
74 #define OTG_CORE_REV_2_92a      0x4F54292A
75 #define OTG_CORE_REV_2_93a      0x4F54293A
76 #define OTG_CORE_REV_2_94a      0x4F54294A
77 #define OTG_CORE_REV_3_00a      0x4F54300A
78 #define OTG_CORE_REV_3_10a      0x4F54310A
79
80 /**
81  * Information for each ISOC packet.
82  */
83 typedef struct iso_pkt_info {
84         uint32_t offset;
85         uint32_t length;
86         int32_t status;
87 } iso_pkt_info_t;
88
89 /**
90  * The <code>dwc_ep</code> structure represents the state of a single
91  * endpoint when acting in device mode. It contains the data items
92  * needed for an endpoint to be activated and transfer packets.
93  */
94 typedef struct dwc_ep {
95         /** EP number used for register address lookup */
96         uint8_t num;
97         /** EP direction 0 = OUT */
98         unsigned is_in:1;
99         /** EP active. */
100         unsigned active:1;
101
102         /**
103          * Periodic Tx FIFO # for IN EPs For INTR EP set to 0 to use non-periodic
104          * Tx FIFO. If dedicated Tx FIFOs are enabled Tx FIFO # FOR IN EPs*/
105         unsigned tx_fifo_num:4;
106         /** EP type: 0 - Control, 1 - ISOC,      2 - BULK,      3 - INTR */
107         unsigned type:2;
108 #define DWC_OTG_EP_TYPE_CONTROL    0
109 #define DWC_OTG_EP_TYPE_ISOC       1
110 #define DWC_OTG_EP_TYPE_BULK       2
111 #define DWC_OTG_EP_TYPE_INTR       3
112
113         /** DATA start PID for INTR and BULK EP */
114         unsigned data_pid_start:1;
115         /** Frame (even/odd) for ISOC EP */
116         unsigned even_odd_frame:1;
117         /** Max Packet bytes */
118         unsigned maxpacket:11;
119
120         /** Max Transfer size */
121         uint32_t maxxfer;
122
123         /** @name Transfer state */
124         /** @{ */
125
126         /**
127          * Pointer to the beginning of the transfer buffer -- do not modify
128          * during transfer.
129          */
130
131         dwc_dma_t dma_addr;
132
133         dwc_dma_t dma_desc_addr;
134         dwc_otg_dev_dma_desc_t *desc_addr;
135
136         uint8_t *start_xfer_buff;
137         /** pointer to the transfer buffer */
138         uint8_t *xfer_buff;
139         /** Number of bytes to transfer */
140         unsigned xfer_len:19;
141         /** Number of bytes transferred. */
142         unsigned xfer_count:19;
143         /** Sent ZLP */
144         unsigned sent_zlp:1;
145         /** Total len for control transfer */
146         unsigned total_len:19;
147
148         /** stall clear flag */
149         unsigned stall_clear_flag:1;
150
151         /** SETUP pkt cnt rollover flag for EP0 out*/
152         unsigned stp_rollover;
153
154 #ifdef DWC_UTE_CFI
155         /* The buffer mode */
156         data_buffer_mode_e buff_mode;
157
158         /* The chain of DMA descriptors.
159          * MAX_DMA_DESCS_PER_EP will be allocated for each active EP.
160          */
161         dwc_otg_dma_desc_t *descs;
162
163         /* The DMA address of the descriptors chain start */
164         dma_addr_t descs_dma_addr;
165         /** This variable stores the length of the last enqueued request */
166         uint32_t cfi_req_len;
167 #endif/* DWC_UTE_CFI */
168
169 /** Max DMA Descriptor count for any EP */
170 #define MAX_DMA_DESC_CNT 256
171         /** Allocated DMA Desc count */
172         uint32_t desc_cnt;
173
174         /** bInterval */
175         uint32_t bInterval;
176         /** Next frame num to setup next ISOC transfer */
177         uint32_t frame_num;
178         /** Indicates SOF number overrun in DSTS */
179         uint8_t frm_overrun;
180
181 #ifdef DWC_UTE_PER_IO
182         /** Next frame num for which will be setup DMA Desc */
183         uint32_t xiso_frame_num;
184         /** bInterval */
185         uint32_t xiso_bInterval;
186         /** Count of currently active transfers - shall be either 0 or 1 */
187         int xiso_active_xfers;
188         int xiso_queued_xfers;
189 #endif
190 #ifdef DWC_EN_ISOC
191         /**
192          * Variables specific for ISOC EPs
193          *
194          */
195         /** DMA addresses of ISOC buffers */
196         dwc_dma_t dma_addr0;
197         dwc_dma_t dma_addr1;
198
199         dwc_dma_t iso_dma_desc_addr;
200         dwc_otg_dev_dma_desc_t *iso_desc_addr;
201
202         /** pointer to the transfer buffers */
203         uint8_t *xfer_buff0;
204         uint8_t *xfer_buff1;
205
206         /** number of ISOC Buffer is processing */
207         uint32_t proc_buf_num;
208         /** Interval of ISOC Buffer processing */
209         uint32_t buf_proc_intrvl;
210         /** Data size for regular frame */
211         uint32_t data_per_frame;
212
213         /* todo - pattern data support is to be implemented in the future */
214         /** Data size for pattern frame */
215         uint32_t data_pattern_frame;
216         /** Frame number of pattern data */
217         uint32_t sync_frame;
218
219         /** bInterval */
220         uint32_t bInterval;
221         /** ISO Packet number per frame */
222         uint32_t pkt_per_frm;
223         /** Next frame num for which will be setup DMA Desc */
224         uint32_t next_frame;
225         /** Number of packets per buffer processing */
226         uint32_t pkt_cnt;
227         /** Info for all isoc packets */
228         iso_pkt_info_t *pkt_info;
229         /** current pkt number */
230         uint32_t cur_pkt;
231         /** current pkt number */
232         uint8_t *cur_pkt_addr;
233         /** current pkt number */
234         uint32_t cur_pkt_dma_addr;
235 #endif                          /* DWC_EN_ISOC */
236
237 /** @} */
238 } dwc_ep_t;
239
240 /*
241  * Reasons for halting a host channel.
242  */
243 typedef enum dwc_otg_halt_status {
244         DWC_OTG_HC_XFER_NO_HALT_STATUS,
245         DWC_OTG_HC_XFER_COMPLETE,
246         DWC_OTG_HC_XFER_URB_COMPLETE,
247         DWC_OTG_HC_XFER_ACK,
248         DWC_OTG_HC_XFER_NAK,
249         DWC_OTG_HC_XFER_NYET,
250         DWC_OTG_HC_XFER_STALL,
251         DWC_OTG_HC_XFER_XACT_ERR,
252         DWC_OTG_HC_XFER_FRAME_OVERRUN,
253         DWC_OTG_HC_XFER_BABBLE_ERR,
254         DWC_OTG_HC_XFER_DATA_TOGGLE_ERR,
255         DWC_OTG_HC_XFER_AHB_ERR,
256         DWC_OTG_HC_XFER_PERIODIC_INCOMPLETE,
257         DWC_OTG_HC_XFER_URB_DEQUEUE
258 } dwc_otg_halt_status_e;
259
260 /**
261  * Host channel descriptor. This structure represents the state of a single
262  * host channel when acting in host mode. It contains the data items needed to
263  * transfer packets to an endpoint via a host channel.
264  */
265 typedef struct dwc_hc {
266         /** Host channel number used for register address lookup */
267         uint8_t hc_num;
268
269         /** Device to access */
270         unsigned dev_addr:7;
271
272         /** EP to access */
273         unsigned ep_num:4;
274
275         /** EP direction. 0: OUT, 1: IN */
276         unsigned ep_is_in:1;
277
278         /**
279          * EP speed.
280          * One of the following values:
281          *      - DWC_OTG_EP_SPEED_LOW
282          *      - DWC_OTG_EP_SPEED_FULL
283          *      - DWC_OTG_EP_SPEED_HIGH
284          */
285         unsigned speed:2;
286 #define DWC_OTG_EP_SPEED_LOW    0
287 #define DWC_OTG_EP_SPEED_FULL   1
288 #define DWC_OTG_EP_SPEED_HIGH   2
289
290         /**
291          * Endpoint type.
292          * One of the following values:
293          *      - DWC_OTG_EP_TYPE_CONTROL: 0
294          *      - DWC_OTG_EP_TYPE_ISOC: 1
295          *      - DWC_OTG_EP_TYPE_BULK: 2
296          *      - DWC_OTG_EP_TYPE_INTR: 3
297          */
298         unsigned ep_type:2;
299
300         /** Max packet size in bytes */
301         unsigned max_packet:11;
302
303         /**
304          * PID for initial transaction.
305          * 0: DATA0,<br>
306          * 1: DATA2,<br>
307          * 2: DATA1,<br>
308          * 3: MDATA (non-Control EP),
309          *        SETUP (Control EP)
310          */
311         unsigned data_pid_start:2;
312 #define DWC_OTG_HC_PID_DATA0 0
313 #define DWC_OTG_HC_PID_DATA2 1
314 #define DWC_OTG_HC_PID_DATA1 2
315 #define DWC_OTG_HC_PID_MDATA 3
316 #define DWC_OTG_HC_PID_SETUP 3
317
318         /** Number of periodic transactions per (micro)frame */
319         unsigned multi_count:2;
320
321         /** @name Transfer State */
322         /** @{ */
323
324         /** Pointer to the current transfer buffer position. */
325         uint8_t *xfer_buff;
326         /**
327          * In Buffer DMA mode this buffer will be used
328          * if xfer_buff is not DWORD aligned.
329          */
330         dwc_dma_t align_buff;
331         /** Total number of bytes to transfer. */
332         uint32_t xfer_len;
333         /** Number of bytes transferred so far. */
334         uint32_t xfer_count;
335         /** Packet count at start of transfer.*/
336         uint16_t start_pkt_count;
337
338         /**
339          * Flag to indicate whether the transfer has been started. Set to 1 if
340          * it has been started, 0 otherwise.
341          */
342         uint8_t xfer_started;
343
344         /**
345          * Set to 1 to indicate that a PING request should be issued on this
346          * channel. If 0, process normally.
347          */
348         uint8_t do_ping;
349
350         /**
351          * Set to 1 to indicate that the error count for this transaction is
352          * non-zero. Set to 0 if the error count is 0.
353          */
354         uint8_t error_state;
355
356         /**
357          * Set to 1 to indicate that this channel should be halted the next
358          * time a request is queued for the channel. This is necessary in
359          * slave mode if no request queue space is available when an attempt
360          * is made to halt the channel.
361          */
362         uint8_t halt_on_queue;
363
364         /**
365          * Set to 1 if the host channel has been halted, but the core is not
366          * finished flushing queued requests. Otherwise 0.
367          */
368         uint8_t halt_pending;
369
370         /**
371          * Reason for halting the host channel.
372          */
373         dwc_otg_halt_status_e halt_status;
374
375         /*
376          * Split settings for the host channel
377          */
378         uint8_t do_split;                  /**< Enable split for the channel */
379         uint8_t complete_split;    /**< Enable complete split */
380         uint8_t csplit_nak;
381         uint8_t hub_addr;                  /**< Address of high speed hub */
382
383         uint8_t port_addr;                 /**< Port of the low/full speed device */
384         /** Split transaction position
385          * One of the following values:
386          *        - DWC_HCSPLIT_XACTPOS_MID
387          *        - DWC_HCSPLIT_XACTPOS_BEGIN
388          *        - DWC_HCSPLIT_XACTPOS_END
389          *        - DWC_HCSPLIT_XACTPOS_ALL */
390         uint8_t xact_pos;
391
392         /** Set when the host channel does a short read. */
393         uint8_t short_read;
394
395         /**
396          * Number of requests issued for this channel since it was assigned to
397          * the current transfer (not counting PINGs).
398          */
399         uint8_t requests;
400
401         /**
402          * Queue Head for the transfer being processed by this channel.
403          */
404         struct dwc_otg_qh *qh;
405
406         /** @} */
407
408         /** Entry in list of host channels. */
409          DWC_CIRCLEQ_ENTRY(dwc_hc) hc_list_entry;
410
411         /** @name Descriptor DMA support */
412         /** @{ */
413
414         /** Number of Transfer Descriptors */
415         uint16_t ntd;
416
417         /** Descriptor List DMA address */
418         dwc_dma_t desc_list_addr;
419
420         /** Scheduling micro-frame bitmap. */
421         uint8_t schinfo;
422
423         /** @} */
424 } dwc_hc_t;
425
426 /**
427  * The following parameters may be specified when starting the module. These
428  * parameters define how the DWC_otg controller should be configured.
429  */
430 typedef struct dwc_otg_core_params {
431         int32_t opt;
432
433         /**
434          * Specifies the OTG capabilities. The driver will automatically
435          * detect the value for this parameter if none is specified.
436          * 0 - HNP and SRP capable (default)
437          * 1 - SRP Only capable
438          * 2 - No HNP/SRP capable
439          */
440         int32_t otg_cap;
441
442         /**
443          * Specifies whether to use slave or DMA mode for accessing the data
444          * FIFOs. The driver will automatically detect the value for this
445          * parameter if none is specified.
446          * 0 - Slave
447          * 1 - DMA (default, if available)
448          */
449         int32_t dma_enable;
450
451         /**
452          * When DMA mode is enabled specifies whether to use address DMA or DMA
453          * Descriptor mode for accessing the data FIFOs in device mode. The driver
454          * will automatically detect the value for this if none is specified.
455          * 0 - address DMA
456          * 1 - DMA Descriptor(default, if available)
457          */
458         int32_t dma_desc_enable;
459         /** The DMA Burst size (applicable only for External DMA
460          * Mode). 1, 4, 8 16, 32, 64, 128, 256 (default 32)
461          */
462         int32_t dma_burst_size; /* Translate this to GAHBCFG values */
463
464         /**
465          * Specifies the maximum speed of operation in host and device mode.
466          * The actual speed depends on the speed of the attached device and
467          * the value of phy_type. The actual speed depends on the speed of the
468          * attached device.
469          * 0 - High Speed (default)
470          * 1 - Full Speed
471          */
472         int32_t speed;
473         /** Specifies whether low power mode is supported when attached
474          *      to a Full Speed or Low Speed device in host mode.
475          * 0 - Don't support low power mode (default)
476          * 1 - Support low power mode
477          */
478         int32_t host_support_fs_ls_low_power;
479
480         /** Specifies the PHY clock rate in low power mode when connected to a
481          * Low Speed device in host mode. This parameter is applicable only if
482          * HOST_SUPPORT_FS_LS_LOW_POWER is enabled. If PHY_TYPE is set to FS
483          * then defaults to 6 MHZ otherwise 48 MHZ.
484          *
485          * 0 - 48 MHz
486          * 1 - 6 MHz
487          */
488         int32_t host_ls_low_power_phy_clk;
489
490         /**
491          * 0 - Use cC FIFO size parameters
492          * 1 - Allow dynamic FIFO sizing (default)
493          */
494         int32_t enable_dynamic_fifo;
495
496         /** Total number of 4-byte words in the data FIFO memory. This
497          * memory includes the Rx FIFO, non-periodic Tx FIFO, and periodic
498          * Tx FIFOs.
499          * 32 to 32768 (default 8192)
500          * Note: The total FIFO memory depth in the FPGA configuration is 8192.
501          */
502         int32_t data_fifo_size;
503
504         /** Number of 4-byte words in the Rx FIFO in device mode when dynamic
505          * FIFO sizing is enabled.
506          * 16 to 32768 (default 1064)
507          */
508         int32_t dev_rx_fifo_size;
509
510         /** Number of 4-byte words in the non-periodic Tx FIFO in device mode
511          * when dynamic FIFO sizing is enabled.
512          * 16 to 32768 (default 1024)
513          */
514         int32_t dev_nperio_tx_fifo_size;
515
516         /** Number of 4-byte words in each of the periodic Tx FIFOs in device
517          * mode when dynamic FIFO sizing is enabled.
518          * 4 to 768 (default 256)
519          */
520         uint32_t dev_perio_tx_fifo_size[MAX_PERIO_FIFOS];
521
522         /** Number of 4-byte words in the Rx FIFO in host mode when dynamic
523          * FIFO sizing is enabled.
524          * 16 to 32768 (default 1024)
525          */
526         int32_t host_rx_fifo_size;
527
528         /** Number of 4-byte words in the non-periodic Tx FIFO in host mode
529          * when Dynamic FIFO sizing is enabled in the core.
530          * 16 to 32768 (default 1024)
531          */
532         int32_t host_nperio_tx_fifo_size;
533
534         /** Number of 4-byte words in the host periodic Tx FIFO when dynamic
535          * FIFO sizing is enabled.
536          * 16 to 32768 (default 1024)
537          */
538         int32_t host_perio_tx_fifo_size;
539
540         /** The maximum transfer size supported in bytes.
541          * 2047 to 65,535  (default 65,535)
542          */
543         int32_t max_transfer_size;
544
545         /** The maximum number of packets in a transfer.
546          * 15 to 511  (default 511)
547          */
548         int32_t max_packet_count;
549
550         /** The number of host channel registers to use.
551          * 1 to 16 (default 12)
552          * Note: The FPGA configuration supports a maximum of 12 host channels.
553          */
554         int32_t host_channels;
555
556         /** The number of endpoints in addition to EP0 available for device
557          * mode operations.
558          * 1 to 15 (default 6 IN and OUT)
559          * Note: The FPGA configuration supports a maximum of 6 IN and OUT
560          * endpoints in addition to EP0.
561          */
562         int32_t dev_endpoints;
563
564                 /**
565                  * Specifies the type of PHY interface to use. By default, the driver
566                  * will automatically detect the phy_type.
567                  *
568                  * 0 - Full Speed PHY
569                  * 1 - UTMI+ (default)
570                  * 2 - ULPI
571                  */
572         int32_t phy_type;
573
574         /**
575          * Specifies the UTMI+ Data Width. This parameter is
576          * applicable for a PHY_TYPE of UTMI+ or ULPI. (For a ULPI
577          * PHY_TYPE, this parameter indicates the data width between
578          * the MAC and the ULPI Wrapper.) Also, this parameter is
579          * applicable only if the OTG_HSPHY_WIDTH cC parameter was set
580          * to "8 and 16 bits", meaning that the core has been
581          * configured to work at either data path width.
582          *
583          * 8 or 16 bits (default 16)
584          */
585         int32_t phy_utmi_width;
586
587         /**
588          * Specifies whether the ULPI operates at double or single
589          * data rate. This parameter is only applicable if PHY_TYPE is
590          * ULPI.
591          *
592          * 0 - single data rate ULPI interface with 8 bit wide data
593          * bus (default)
594          * 1 - double data rate ULPI interface with 4 bit wide data
595          * bus
596          */
597         int32_t phy_ulpi_ddr;
598
599         /**
600          * Specifies whether to use the internal or external supply to
601          * drive the vbus with a ULPI phy.
602          */
603         int32_t phy_ulpi_ext_vbus;
604
605         /**
606          * Specifies whether to use the I2Cinterface for full speed PHY. This
607          * parameter is only applicable if PHY_TYPE is FS.
608          * 0 - No (default)
609          * 1 - Yes
610          */
611         int32_t i2c_enable;
612
613         int32_t ulpi_fs_ls;
614
615         int32_t ts_dline;
616
617         /**
618          * Specifies whether dedicated transmit FIFOs are
619          * enabled for non periodic IN endpoints in device mode
620          * 0 - No
621          * 1 - Yes
622          */
623         int32_t en_multiple_tx_fifo;
624
625         /** Number of 4-byte words in each of the Tx FIFOs in device
626          * mode when dynamic FIFO sizing is enabled.
627          * 4 to 768 (default 256)
628          */
629         uint32_t dev_tx_fifo_size[MAX_TX_FIFOS];
630
631         /** Thresholding enable flag-
632          * bit 0 - enable non-ISO Tx thresholding
633          * bit 1 - enable ISO Tx thresholding
634          * bit 2 - enable Rx thresholding
635          */
636         uint32_t thr_ctl;
637
638         /** Thresholding length for Tx
639          *      FIFOs in 32 bit DWORDs
640          */
641         uint32_t tx_thr_length;
642
643         /** Thresholding length for Rx
644          *      FIFOs in 32 bit DWORDs
645          */
646         uint32_t rx_thr_length;
647
648         /**
649          * Specifies whether LPM (Link Power Management) support is enabled
650          */
651         int32_t lpm_enable;
652
653         /**
654         * Specifies whether LPM Errata (Link Power Management) support is enabled
655         */
656         int32_t besl_enable;
657
658         /**
659         * Specifies the baseline besl value
660         */
661         int32_t baseline_besl;
662
663         /**
664         * Specifies the deep besl value
665         */
666         int32_t deep_besl;
667         /** Per Transfer Interrupt
668          *      mode enable flag
669          * 1 - Enabled
670          * 0 - Disabled
671          */
672         int32_t pti_enable;
673
674         /** Multi Processor Interrupt
675          *      mode enable flag
676          * 1 - Enabled
677          * 0 - Disabled
678          */
679         int32_t mpi_enable;
680
681         /** IS_USB Capability
682          * 1 - Enabled
683          * 0 - Disabled
684          */
685         int32_t ic_usb_cap;
686
687         /** AHB Threshold Ratio
688          * 2'b00 AHB Threshold =        MAC Threshold
689          * 2'b01 AHB Threshold = 1/2    MAC Threshold
690          * 2'b10 AHB Threshold = 1/4    MAC Threshold
691          * 2'b11 AHB Threshold = 1/8    MAC Threshold
692          */
693         int32_t ahb_thr_ratio;
694
695         /** ADP Support
696          * 1 - Enabled
697          * 0 - Disabled
698          */
699         int32_t adp_supp_enable;
700
701         /** HFIR Reload Control
702          * 0 - The HFIR cannot be reloaded dynamically.
703          * 1 - Allow dynamic reloading of the HFIR register during runtime.
704          */
705         int32_t reload_ctl;
706
707         /** DCFG: Enable device Out NAK
708          * 0 - The core does not set NAK after Bulk Out transfer complete.
709          * 1 - The core sets NAK after Bulk OUT transfer complete.
710          */
711         int32_t dev_out_nak;
712
713         /** DCFG: Enable Continue on BNA
714          * After receiving BNA interrupt the core disables the endpoint,when the
715          * endpoint is re-enabled by the application the core starts processing
716          * 0 - from the DOEPDMA descriptor
717          * 1 - from the descriptor which received the BNA.
718          */
719         int32_t cont_on_bna;
720
721         /** GAHBCFG: AHB Single Support
722          * This bit when programmed supports SINGLE transfers for remainder
723          * data in a transfer for DMA mode of operation.
724          * 0 - in this case the remainder data will be sent using INCR burst size.
725          * 1 - in this case the remainder data will be sent using SINGLE burst size.
726          */
727         int32_t ahb_single;
728
729         /** Core Power down mode
730          * 0 - No Power Down is enabled
731          * 1 - Reserved
732          * 2 - Complete Power Down (Hibernation)
733          */
734         int32_t power_down;
735
736         /** OTG revision supported
737          * 0 - OTG 1.3 revision
738          * 1 - OTG 2.0 revision
739          */
740         int32_t otg_ver;
741
742 } dwc_otg_core_params_t;
743
744 #ifdef DEBUG
745 struct dwc_otg_core_if;
746 typedef struct hc_xfer_info {
747         struct dwc_otg_core_if *core_if;
748         dwc_hc_t *hc;
749 } hc_xfer_info_t;
750 #endif
751
752 typedef struct ep_xfer_info {
753         struct dwc_otg_core_if *core_if;
754         dwc_ep_t *ep;
755         uint8_t state;
756 } ep_xfer_info_t;
757 /*
758  * Device States
759  */
760 typedef enum dwc_otg_lx_state {
761         /** On state */
762         DWC_OTG_L0,
763         /** LPM sleep state*/
764         DWC_OTG_L1,
765         /** USB suspend state*/
766         DWC_OTG_L2,
767         /** Off state*/
768         DWC_OTG_L3
769 } dwc_otg_lx_state_e;
770
771 struct dwc_otg_global_regs_backup {
772         uint32_t gotgctl_local;
773         uint32_t gintmsk_local;
774         uint32_t gahbcfg_local;
775         uint32_t gusbcfg_local;
776         uint32_t grxfsiz_local;
777         uint32_t gnptxfsiz_local;
778 #ifdef CONFIG_USB_DWC_OTG_LPM
779         uint32_t glpmcfg_local;
780 #endif
781         uint32_t gi2cctl_local;
782         uint32_t hptxfsiz_local;
783         uint32_t pcgcctl_local;
784         uint32_t gdfifocfg_local;
785         uint32_t dtxfsiz_local[MAX_EPS_CHANNELS];
786         uint32_t gpwrdn_local;
787         uint32_t xhib_pcgcctl;
788         uint32_t xhib_gpwrdn;
789 };
790
791 struct dwc_otg_host_regs_backup {
792         uint32_t hcfg_local;
793         uint32_t haintmsk_local;
794         uint32_t hcintmsk_local[MAX_EPS_CHANNELS];
795         uint32_t hprt0_local;
796         uint32_t hfir_local;
797 };
798
799 struct dwc_otg_dev_regs_backup {
800         uint32_t dcfg;
801         uint32_t dctl;
802         uint32_t daintmsk;
803         uint32_t diepmsk;
804         uint32_t doepmsk;
805         uint32_t diepctl[MAX_EPS_CHANNELS];
806         uint32_t dieptsiz[MAX_EPS_CHANNELS];
807         uint32_t diepdma[MAX_EPS_CHANNELS];
808 };
809 /**
810  * The <code>dwc_otg_core_if</code> structure contains information needed to manage
811  * the DWC_otg controller acting in either host or device mode. It
812  * represents the programming view of the controller as a whole.
813  */
814 struct dwc_otg_core_if {
815         /** Parameters that define how the core should be configured.*/
816         dwc_otg_core_params_t *core_params;
817
818         /** Core Global registers starting at offset 000h. */
819         dwc_otg_core_global_regs_t *core_global_regs;
820
821         /** Device-specific information */
822         dwc_otg_dev_if_t *dev_if;
823         /** Host-specific information */
824         dwc_otg_host_if_t *host_if;
825
826         /** Value from SNPSID register */
827         uint32_t snpsid;
828
829         /** The DWC otg device pointer. */
830         struct dwc_otg_device *otg_dev;
831
832         /*
833          * Set to 1 if the core PHY interface bits in USBCFG have been
834          * initialized.
835          */
836         uint8_t phy_init_done;
837
838         /*
839          * SRP Success flag, set by srp success interrupt in FS I2C mode
840          */
841         uint8_t srp_success;
842         uint8_t srp_timer_started;
843         /** Timer for SRP. If it expires before SRP is successful
844          * clear the SRP. */
845         dwc_timer_t *srp_timer;
846
847         uint8_t usb_mode;
848 #define USB_MODE_NORMAL (0)
849 #define USB_MODE_FORCE_HOST (1)
850 #define USB_MODE_FORCE_DEVICE (2)
851
852 #ifdef DWC_DEV_SRPCAP
853         /* This timer is needed to power on the hibernated host core if SRP is not
854          * initiated on connected SRP capable device for limited period of time
855          */
856         uint8_t pwron_timer_started;
857         dwc_timer_t *pwron_timer;
858 #endif
859         /* Common configuration information */
860         /** Power and Clock Gating Control Register */
861         volatile uint32_t *pcgcctl;
862 #define DWC_OTG_PCGCCTL_OFFSET 0xE00
863
864         /** Push/pop addresses for endpoints or host channels.*/
865         uint32_t *data_fifo[MAX_EPS_CHANNELS];
866 #define DWC_OTG_DATA_FIFO_OFFSET 0x1000
867 #define DWC_OTG_DATA_FIFO_SIZE 0x1000
868
869         /** Total RAM for FIFOs (Bytes) */
870         uint16_t total_fifo_size;
871         /** Size of Rx FIFO (Bytes) */
872         uint16_t rx_fifo_size;
873         /** Size of Non-periodic Tx FIFO (Bytes) */
874         uint16_t nperio_tx_fifo_size;
875
876         /** 1 if DMA is enabled, 0 otherwise. */
877         uint8_t dma_enable;
878
879         /** 1 if DMA descriptor is enabled, 0 otherwise. */
880         uint8_t dma_desc_enable;
881
882         /** 1 if PTI Enhancement mode is enabled, 0 otherwise. */
883         uint8_t pti_enh_enable;
884
885         /** 1 if MPI Enhancement mode is enabled, 0 otherwise. */
886         uint8_t multiproc_int_enable;
887
888         /** 1 if dedicated Tx FIFOs are enabled, 0 otherwise. */
889         uint8_t en_multiple_tx_fifo;
890
891         /** Set to 1 if multiple packets of a high-bandwidth transfer is in
892          * process of being queued */
893         uint8_t queuing_high_bandwidth;
894
895         /** Hardware Configuration -- stored here for convenience.*/
896         hwcfg1_data_t hwcfg1;
897         hwcfg2_data_t hwcfg2;
898         hwcfg3_data_t hwcfg3;
899         hwcfg4_data_t hwcfg4;
900         fifosize_data_t hptxfsiz;
901
902         /** Host and Device Configuration -- stored here for convenience.*/
903         hcfg_data_t hcfg;
904         dcfg_data_t dcfg;
905
906         /** The operational State, during transations
907          * (a_host>>a_peripherial and b_device=>b_host) this may not
908          * match the core but allows the software to determine
909          * transitions.
910          */
911         uint8_t op_state;
912
913         /** Test mode for PET testing */
914         uint8_t test_mode;
915
916         /**
917          * Set to 1 if the HCD needs to be restarted on a session request
918          * interrupt. This is required if no connector ID status change has
919          * occurred since the HCD was last disconnected.
920          */
921         uint8_t restart_hcd_on_session_req;
922
923         /** HCD callbacks */
924         /** A-Device is a_host */
925 #define A_HOST          (1)
926         /** A-Device is a_suspend */
927 #define A_SUSPEND       (2)
928         /** A-Device is a_peripherial */
929 #define A_PERIPHERAL    (3)
930         /** B-Device is operating as a Peripheral. */
931 #define B_PERIPHERAL    (4)
932         /** B-Device is operating as a Host. */
933 #define B_HOST          (5)
934
935         /** HCD callbacks */
936         struct dwc_otg_cil_callbacks *hcd_cb;
937         void *hcd_cb_p;
938         /** PCD callbacks */
939         struct dwc_otg_cil_callbacks *pcd_cb;
940
941         /** Device mode Periodic Tx FIFO Mask */
942         uint32_t p_tx_msk;
943         /** Device mode Periodic Tx FIFO Mask */
944         uint32_t tx_msk;
945
946         /** Workqueue object used for handling several interrupts */
947         dwc_workq_t *wq_otg;
948
949         /** Tasklet used for handling "Wakeup Detected" Interrupt*/
950         dwc_tasklet_t *wkp_tasklet;
951         /** This arrays used for debug purposes for DEV OUT NAK enhancement */
952         uint32_t start_doeptsiz_val[MAX_EPS_CHANNELS];
953         ep_xfer_info_t ep_xfer_info[MAX_EPS_CHANNELS];
954         dwc_timer_t *ep_xfer_timer[MAX_EPS_CHANNELS];
955 #ifdef DEBUG
956         uint32_t start_hcchar_val[MAX_EPS_CHANNELS];
957
958         hc_xfer_info_t hc_xfer_info[MAX_EPS_CHANNELS];
959         dwc_timer_t *hc_xfer_timer[MAX_EPS_CHANNELS];
960
961         uint32_t hfnum_7_samples;
962         uint64_t hfnum_7_frrem_accum;
963         uint32_t hfnum_0_samples;
964         uint64_t hfnum_0_frrem_accum;
965         uint32_t hfnum_other_samples;
966         uint64_t hfnum_other_frrem_accum;
967 #endif
968
969 #ifdef DWC_UTE_CFI
970         uint16_t pwron_rxfsiz;
971         uint16_t pwron_gnptxfsiz;
972         uint16_t pwron_txfsiz[15];
973
974         uint16_t init_rxfsiz;
975         uint16_t init_gnptxfsiz;
976         uint16_t init_txfsiz[15];
977 #endif
978
979         /** Lx state of device */
980         dwc_otg_lx_state_e lx_state;
981
982         /** Saved Core Global registers */
983         struct dwc_otg_global_regs_backup *gr_backup;
984         /** Saved Host registers */
985         struct dwc_otg_host_regs_backup *hr_backup;
986         /** Saved Device registers */
987         struct dwc_otg_dev_regs_backup *dr_backup;
988
989         /** Power Down Enable */
990         uint32_t power_down;
991
992         /** ADP support Enable */
993         uint32_t adp_enable;
994
995         /** ADP structure object */
996         dwc_otg_adp_t adp;
997
998         /** hibernation/suspend flag */
999         int hibernation_suspend;
1000
1001         /** Device mode extended hibernation flag */
1002         int xhib;
1003
1004         /** OTG revision supported */
1005         uint32_t otg_ver;
1006
1007         /** OTG status flag used for HNP polling */
1008         uint8_t otg_sts;
1009
1010         /** Pointer to either hcd->lock or pcd->lock */
1011         dwc_spinlock_t *lock;
1012
1013         /** Start predict NextEP based on Learning Queue if equal 1,
1014          * also used as counter of disabled NP IN EP's */
1015         uint8_t start_predict;
1016
1017         /** NextEp sequence, including EP0: nextep_seq[] = EP if non-periodic and
1018          * active, 0xff otherwise */
1019         uint8_t nextep_seq[MAX_EPS_CHANNELS];
1020
1021         /** Index of fisrt EP in nextep_seq array which should be re-enabled **/
1022         uint8_t first_in_nextep_seq;
1023
1024         /** Frame number while entering to ISR - needed for ISOCs **/
1025         uint32_t frame_num;
1026
1027         /** Flag to not perform ADP probing if IDSTS event happened */
1028         uint8_t stop_adpprb;
1029
1030 };
1031
1032 #ifdef DEBUG
1033 /*
1034  * This function is called when transfer is timed out.
1035  */
1036 extern void hc_xfer_timeout(void *ptr);
1037 #endif
1038
1039 /*
1040  * This function is called when transfer is timed out on endpoint.
1041  */
1042 extern void ep_xfer_timeout(void *ptr);
1043
1044 /*
1045  * The following functions are functions for works
1046  * using during handling some interrupts
1047  */
1048 extern void w_conn_id_status_change(void *p);
1049
1050 extern void w_wakeup_detected(void *data);
1051
1052 /** Saves global register values into system memory. */
1053 extern int dwc_otg_save_global_regs(dwc_otg_core_if_t *core_if);
1054 /** Saves device register values into system memory. */
1055 extern int dwc_otg_save_dev_regs(dwc_otg_core_if_t *core_if);
1056 /** Saves host register values into system memory. */
1057 extern int dwc_otg_save_host_regs(dwc_otg_core_if_t *core_if);
1058 /** Restore global register values. */
1059 extern int dwc_otg_restore_global_regs(dwc_otg_core_if_t *core_if);
1060 /** Restore host register values. */
1061 extern int dwc_otg_restore_host_regs(dwc_otg_core_if_t *core_if, int reset);
1062 /** Restore device register values. */
1063 extern int dwc_otg_restore_dev_regs(dwc_otg_core_if_t *core_if,
1064                                     int rem_wakeup);
1065 extern int restore_lpm_i2c_regs(dwc_otg_core_if_t *core_if);
1066 extern int restore_essential_regs(dwc_otg_core_if_t *core_if, int rmode,
1067                                   int is_host);
1068
1069 extern int dwc_otg_host_hibernation_restore(dwc_otg_core_if_t *core_if,
1070                                             int restore_mode, int reset);
1071 extern int dwc_otg_device_hibernation_restore(dwc_otg_core_if_t *core_if,
1072                                               int rem_wakeup, int reset);
1073
1074 /*
1075  * The following functions support initialization of the CIL driver component
1076  * and the DWC_otg controller.
1077  */
1078 extern void dwc_otg_core_host_init(dwc_otg_core_if_t *_core_if);
1079 extern void dwc_otg_core_dev_init(dwc_otg_core_if_t *_core_if);
1080
1081 /** @name Device CIL Functions
1082  * The following functions support managing the DWC_otg controller in device
1083  * mode.
1084  */
1085 /**@{*/
1086 extern void dwc_otg_wakeup(dwc_otg_core_if_t *_core_if);
1087 extern void dwc_otg_read_setup_packet(dwc_otg_core_if_t *_core_if,
1088                                       uint32_t *_dest);
1089 extern uint32_t dwc_otg_get_frame_number(dwc_otg_core_if_t *_core_if);
1090 extern void dwc_otg_ep0_activate(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep);
1091 extern void dwc_otg_ep_activate(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep);
1092 extern void dwc_otg_ep_deactivate(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep);
1093 extern void dwc_otg_ep_start_transfer(dwc_otg_core_if_t *_core_if,
1094                                       dwc_ep_t *_ep);
1095 extern void dwc_otg_ep_start_zl_transfer(dwc_otg_core_if_t *_core_if,
1096                                          dwc_ep_t *_ep);
1097 extern void dwc_otg_ep0_start_transfer(dwc_otg_core_if_t *_core_if,
1098                                        dwc_ep_t *_ep);
1099 extern void dwc_otg_ep0_continue_transfer(dwc_otg_core_if_t *_core_if,
1100                                           dwc_ep_t *_ep);
1101 extern void dwc_otg_ep_write_packet(dwc_otg_core_if_t *_core_if,
1102                                     dwc_ep_t *_ep, int _dma);
1103 extern void dwc_otg_ep_set_stall(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep);
1104 extern void dwc_otg_ep_clear_stall(dwc_otg_core_if_t *_core_if,
1105                                    dwc_ep_t *_ep);
1106 extern void dwc_otg_enable_device_interrupts(dwc_otg_core_if_t *_core_if);
1107
1108 #ifdef DWC_EN_ISOC
1109 extern void dwc_otg_iso_ep_start_frm_transfer(dwc_otg_core_if_t *core_if,
1110                                               dwc_ep_t *ep);
1111 extern void dwc_otg_iso_ep_start_buf_transfer(dwc_otg_core_if_t *core_if,
1112                                               dwc_ep_t *ep);
1113 #endif /* DWC_EN_ISOC */
1114 /**@}*/
1115
1116 /** @name Host CIL Functions
1117  * The following functions support managing the DWC_otg controller in host
1118  * mode.
1119  */
1120 /**@{*/
1121 extern void dwc_otg_hc_init(dwc_otg_core_if_t *_core_if, dwc_hc_t *_hc);
1122 extern void dwc_otg_hc_halt(dwc_otg_core_if_t *_core_if,
1123                             dwc_hc_t *_hc, dwc_otg_halt_status_e _halt_status);
1124 extern void dwc_otg_hc_cleanup(dwc_otg_core_if_t *_core_if, dwc_hc_t *_hc);
1125 extern void dwc_otg_hc_start_transfer(dwc_otg_core_if_t *_core_if,
1126                                       dwc_hc_t *_hc);
1127 extern int dwc_otg_hc_continue_transfer(dwc_otg_core_if_t *_core_if,
1128                                         dwc_hc_t *_hc);
1129 extern void dwc_otg_hc_do_ping(dwc_otg_core_if_t *_core_if, dwc_hc_t *_hc);
1130 extern void dwc_otg_hc_write_packet(dwc_otg_core_if_t *_core_if,
1131                                     dwc_hc_t *_hc);
1132 extern void dwc_otg_enable_host_interrupts(dwc_otg_core_if_t *_core_if);
1133 extern void dwc_otg_disable_host_interrupts(dwc_otg_core_if_t *_core_if);
1134
1135 extern void dwc_otg_hc_start_transfer_ddma(dwc_otg_core_if_t *core_if,
1136                                            dwc_hc_t *hc);
1137
1138 extern uint32_t calc_frame_interval(dwc_otg_core_if_t *core_if);
1139 extern int dwc_otg_check_haps_status(dwc_otg_core_if_t *core_if);
1140
1141 /* Macro used to clear one channel interrupt */
1142 #define clear_hc_int(_hc_regs_, _intr_) \
1143 do { \
1144         hcint_data_t hcint_clear = {.d32 = 0}; \
1145         hcint_clear.b._intr_ = 1; \
1146         DWC_WRITE_REG32(&(_hc_regs_)->hcint, hcint_clear.d32); \
1147 } while (0)
1148
1149 /*
1150  * Macro used to disable one channel interrupt. Channel interrupts are
1151  * disabled when the channel is halted or released by the interrupt handler.
1152  * There is no need to handle further interrupts of that type until the
1153  * channel is re-assigned. In fact, subsequent handling may cause crashes
1154  * because the channel structures are cleaned up when the channel is released.
1155  */
1156 #define disable_hc_int(_hc_regs_, _intr_) \
1157 do { \
1158         hcintmsk_data_t hcintmsk = {.d32 = 0}; \
1159         hcintmsk.b._intr_ = 1; \
1160         DWC_MODIFY_REG32(&(_hc_regs_)->hcintmsk, hcintmsk.d32, 0); \
1161 } while (0)
1162
1163 /**
1164  * This function Reads HPRT0 in preparation to modify. It keeps the
1165  * WC bits 0 so that if they are read as 1, they won't clear when you
1166  * write it back
1167  */
1168 static inline uint32_t dwc_otg_read_hprt0(dwc_otg_core_if_t *_core_if)
1169 {
1170         hprt0_data_t hprt0;
1171         hprt0.d32 = DWC_READ_REG32(_core_if->host_if->hprt0);
1172         hprt0.b.prtena = 0;
1173         hprt0.b.prtconndet = 0;
1174         hprt0.b.prtenchng = 0;
1175         hprt0.b.prtovrcurrchng = 0;
1176         return hprt0.d32;
1177 }
1178
1179 /**@}*/
1180
1181 /** @name Common CIL Functions
1182  * The following functions support managing the DWC_otg controller in either
1183  * device or host mode.
1184  */
1185 /**@{*/
1186
1187 extern void dwc_otg_read_packet(dwc_otg_core_if_t *core_if,
1188                                 uint8_t *dest, uint16_t bytes);
1189
1190 extern void dwc_otg_flush_tx_fifo(dwc_otg_core_if_t *_core_if, const int _num);
1191 extern void dwc_otg_flush_rx_fifo(dwc_otg_core_if_t *_core_if);
1192 extern void dwc_otg_core_reset(dwc_otg_core_if_t *_core_if);
1193
1194 /**
1195  * This function returns the Core Interrupt register.
1196  */
1197 static inline uint32_t dwc_otg_read_core_intr(dwc_otg_core_if_t *core_if)
1198 {
1199         uint32_t retval;
1200         retval = DWC_READ_REG32(&core_if->core_global_regs->gintsts) &
1201                  DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
1202         return retval;
1203 }
1204
1205 /**
1206  * This function returns the OTG Interrupt register.
1207  */
1208 static inline uint32_t dwc_otg_read_otg_intr(dwc_otg_core_if_t *core_if)
1209 {
1210         uint32_t retval;
1211         retval = DWC_READ_REG32(&core_if->core_global_regs->gotgint);
1212         return retval;
1213 }
1214
1215 /**
1216  * This function reads the Device All Endpoints Interrupt register and
1217  * returns the IN endpoint interrupt bits.
1218  */
1219 static inline uint32_t dwc_otg_read_dev_all_in_ep_intr(dwc_otg_core_if_t
1220                                                        *core_if)
1221 {
1222
1223         uint32_t v;
1224
1225         if (core_if->multiproc_int_enable) {
1226                 v = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->
1227                                    deachint) & DWC_READ_REG32(&core_if->dev_if->
1228                                                               dev_global_regs->
1229                                                               deachintmsk);
1230         } else {
1231                 v = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->daint) &
1232                     DWC_READ_REG32(&core_if->dev_if->dev_global_regs->daintmsk);
1233         }
1234         v &= 0xffff;
1235         return v;
1236 }
1237
1238 /**
1239  * This function reads the Device All Endpoints Interrupt register and
1240  * returns the OUT endpoint interrupt bits.
1241  */
1242 static inline uint32_t dwc_otg_read_dev_all_out_ep_intr(dwc_otg_core_if_t
1243                                                         *core_if)
1244 {
1245         uint32_t v;
1246
1247         if (core_if->multiproc_int_enable) {
1248                 v = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->
1249                                    deachint) & DWC_READ_REG32(&core_if->dev_if->
1250                                                               dev_global_regs->
1251                                                               deachintmsk);
1252         } else {
1253                 v = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->daint) &
1254                     DWC_READ_REG32(&core_if->dev_if->dev_global_regs->daintmsk);
1255         }
1256
1257         v = (v & 0xffff0000) >> 16;
1258         return v;
1259 }
1260
1261 /**
1262  * This function returns the Device IN EP Interrupt register
1263  */
1264 static inline uint32_t dwc_otg_read_dev_in_ep_intr(dwc_otg_core_if_t *core_if,
1265                                                    dwc_ep_t *ep)
1266 {
1267         dwc_otg_dev_if_t *dev_if = core_if->dev_if;
1268         uint32_t v, msk, emp;
1269
1270         if (core_if->multiproc_int_enable) {
1271                 msk =
1272                     DWC_READ_REG32(&dev_if->dev_global_regs->
1273                                    diepeachintmsk[ep->num]);
1274                 emp =
1275                     DWC_READ_REG32(&dev_if->dev_global_regs->
1276                                    dtknqr4_fifoemptymsk);
1277                 msk |= ((emp >> ep->num) & 0x1) << 7;
1278                 v = DWC_READ_REG32(&dev_if->in_ep_regs[ep->num]->diepint) & msk;
1279         } else {
1280                 msk = DWC_READ_REG32(&dev_if->dev_global_regs->diepmsk);
1281                 emp =
1282                     DWC_READ_REG32(&dev_if->dev_global_regs->
1283                                    dtknqr4_fifoemptymsk);
1284                 msk |= ((emp >> ep->num) & 0x1) << 7;
1285                 v = DWC_READ_REG32(&dev_if->in_ep_regs[ep->num]->diepint) & msk;
1286         }
1287
1288         return v;
1289 }
1290
1291 /**
1292  * This function returns the Device OUT EP Interrupt register
1293  */
1294 static inline uint32_t dwc_otg_read_dev_out_ep_intr(dwc_otg_core_if_t *
1295                                                     _core_if, dwc_ep_t *_ep)
1296 {
1297         dwc_otg_dev_if_t *dev_if = _core_if->dev_if;
1298         uint32_t v;
1299         doepmsk_data_t msk = {.d32 = 0 };
1300
1301         if (_core_if->multiproc_int_enable) {
1302                 msk.d32 =
1303                     DWC_READ_REG32(&dev_if->dev_global_regs->
1304                                    doepeachintmsk[_ep->num]);
1305                 if (_core_if->pti_enh_enable) {
1306                         msk.b.pktdrpsts = 1;
1307                 }
1308                 v = DWC_READ_REG32(&dev_if->out_ep_regs[_ep->num]->
1309                                    doepint) & msk.d32;
1310         } else {
1311                 msk.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->doepmsk);
1312                 if (_core_if->pti_enh_enable) {
1313                         msk.b.pktdrpsts = 1;
1314                 }
1315                 v = DWC_READ_REG32(&dev_if->out_ep_regs[_ep->num]->
1316                                    doepint) & msk.d32;
1317         }
1318         return v;
1319 }
1320
1321 /**
1322  * This function returns the Host All Channel Interrupt register
1323  */
1324 static inline uint32_t dwc_otg_read_host_all_channels_intr(dwc_otg_core_if_t *
1325                                                            _core_if)
1326 {
1327         uint32_t retval;
1328         retval = DWC_READ_REG32(&_core_if->host_if->host_global_regs->haint);
1329         return retval;
1330 }
1331
1332 static inline uint32_t dwc_otg_read_host_channel_intr(dwc_otg_core_if_t *
1333                                                       _core_if, dwc_hc_t *_hc)
1334 {
1335         uint32_t retval;
1336         retval = DWC_READ_REG32(&_core_if->host_if->hc_regs[_hc->hc_num]->hcint);
1337         return retval;
1338 }
1339
1340 /**
1341  * This function returns the mode of the operation, host or device.
1342  *
1343  * @return 0 - Device Mode, 1 - Host Mode
1344  */
1345 static inline uint32_t dwc_otg_mode(dwc_otg_core_if_t *_core_if)
1346 {
1347         uint32_t retval;
1348         retval = DWC_READ_REG32(&_core_if->core_global_regs->gintsts) & 0x1;
1349         return retval;
1350 }
1351
1352 /**@}*/
1353
1354 /**
1355  * DWC_otg CIL callback structure. This structure allows the HCD and
1356  * PCD to register functions used for starting and stopping the PCD
1357  * and HCD for role change on for a DRD.
1358  */
1359 typedef struct dwc_otg_cil_callbacks {
1360         /** Start function for role change */
1361         int (*start) (void *_p);
1362         /** Stop Function for role change */
1363         int (*stop) (void *_p);
1364         /** Disconnect Function for role change */
1365         int (*disconnect) (void *_p);
1366         /** Resume/Remote wakeup Function */
1367         int (*resume_wakeup) (void *_p);
1368         /** Suspend function */
1369         int (*suspend) (void *_p);
1370         /** Session Start (SRP) */
1371         int (*session_start) (void *_p);
1372 #ifdef CONFIG_USB_DWC_OTG_LPM
1373         /** Sleep (switch to L0 state) */
1374         int (*sleep) (void *_p);
1375 #endif
1376         /** Pointer passed to start() and stop() */
1377         void *p;
1378 } dwc_otg_cil_callbacks_t;
1379
1380 extern void dwc_otg_cil_register_pcd_callbacks(dwc_otg_core_if_t *_core_if,
1381                                                dwc_otg_cil_callbacks_t *_cb,
1382                                                void *_p);
1383 extern void dwc_otg_cil_register_hcd_callbacks(dwc_otg_core_if_t *_core_if,
1384                                                dwc_otg_cil_callbacks_t *_cb,
1385                                                void *_p);
1386
1387 void dwc_otg_initiate_srp(void *core_if);
1388
1389 /** Start the HCD.  Helper function for using the HCD callbacks.
1390  *
1391  * @param core_if Programming view of DWC_otg controller.
1392  */
1393 static inline void cil_hcd_start(dwc_otg_core_if_t *core_if)
1394 {
1395         if (core_if->hcd_cb && core_if->hcd_cb->start) {
1396                 core_if->hcd_cb->start(core_if->hcd_cb_p);
1397         }
1398 }
1399
1400 /** Stop the HCD.  Helper function for using the HCD callbacks.
1401  *
1402  * @param core_if Programming view of DWC_otg controller.
1403  */
1404 static inline void cil_hcd_stop(dwc_otg_core_if_t *core_if)
1405 {
1406         if (core_if->hcd_cb && core_if->hcd_cb->stop) {
1407                 core_if->hcd_cb->stop(core_if->hcd_cb_p);
1408         }
1409 }
1410
1411 /** Disconnect the HCD.  Helper function for using the HCD callbacks.
1412  *
1413  * @param core_if Programming view of DWC_otg controller.
1414  */
1415 static inline void cil_hcd_disconnect(dwc_otg_core_if_t *core_if)
1416 {
1417         if (core_if->hcd_cb && core_if->hcd_cb->disconnect) {
1418                 core_if->hcd_cb->disconnect(core_if->hcd_cb_p);
1419         }
1420 }
1421
1422 /** Inform the HCD the a New Session has begun.  Helper function for
1423  * using the HCD callbacks.
1424  *
1425  * @param core_if Programming view of DWC_otg controller.
1426  */
1427 static inline void cil_hcd_session_start(dwc_otg_core_if_t *core_if)
1428 {
1429         if (core_if->hcd_cb && core_if->hcd_cb->session_start) {
1430                 core_if->hcd_cb->session_start(core_if->hcd_cb_p);
1431         }
1432 }
1433
1434 #ifdef CONFIG_USB_DWC_OTG_LPM
1435 /**
1436  * Inform the HCD about LPM sleep.
1437  * Helper function for using the HCD callbacks.
1438  *
1439  * @param core_if Programming view of DWC_otg controller.
1440  */
1441 static inline void cil_hcd_sleep(dwc_otg_core_if_t *core_if)
1442 {
1443         if (core_if->hcd_cb && core_if->hcd_cb->sleep) {
1444                 core_if->hcd_cb->sleep(core_if->hcd_cb_p);
1445         }
1446 }
1447 #endif
1448
1449 /** Resume the HCD.  Helper function for using the HCD callbacks.
1450  *
1451  * @param core_if Programming view of DWC_otg controller.
1452  */
1453 static inline void cil_hcd_resume(dwc_otg_core_if_t *core_if)
1454 {
1455         if (core_if->hcd_cb && core_if->hcd_cb->resume_wakeup) {
1456                 core_if->hcd_cb->resume_wakeup(core_if->hcd_cb_p);
1457         }
1458 }
1459
1460 /** Start the PCD.  Helper function for using the PCD callbacks.
1461  *
1462  * @param core_if Programming view of DWC_otg controller.
1463  */
1464 static inline void cil_pcd_start(dwc_otg_core_if_t *core_if)
1465 {
1466         if (core_if->pcd_cb && core_if->pcd_cb->start) {
1467                 core_if->pcd_cb->start(core_if->pcd_cb->p);
1468         }
1469 }
1470
1471 /** Stop the PCD.  Helper function for using the PCD callbacks.
1472  *
1473  * @param core_if Programming view of DWC_otg controller.
1474  */
1475 static inline void cil_pcd_stop(dwc_otg_core_if_t *core_if)
1476 {
1477         if (core_if->pcd_cb && core_if->pcd_cb->stop) {
1478                 core_if->pcd_cb->stop(core_if->pcd_cb->p);
1479         }
1480 }
1481
1482 /** Suspend the PCD.  Helper function for using the PCD callbacks.
1483  *
1484  * @param core_if Programming view of DWC_otg controller.
1485  */
1486 static inline void cil_pcd_suspend(dwc_otg_core_if_t *core_if)
1487 {
1488         if (core_if->pcd_cb && core_if->pcd_cb->suspend) {
1489                 core_if->pcd_cb->suspend(core_if->pcd_cb->p);
1490         }
1491 }
1492
1493 /** Resume the PCD.  Helper function for using the PCD callbacks.
1494  *
1495  * @param core_if Programming view of DWC_otg controller.
1496  */
1497 static inline void cil_pcd_resume(dwc_otg_core_if_t *core_if)
1498 {
1499         if (core_if->pcd_cb && core_if->pcd_cb->resume_wakeup) {
1500                 core_if->pcd_cb->resume_wakeup(core_if->pcd_cb->p);
1501         }
1502 }
1503
1504 void dwc_otg_set_force_mode(dwc_otg_core_if_t *core_if, int mode);
1505
1506 #endif