tizen 2.4 release
[kernel/u-boot-tm1.git] / drivers / usb / gadget / dwc_otg / dwc_otg_cil.h
1 /* ==========================================================================
2  * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_cil.h $
3  * $Revision: #95 $
4  * $Date: 2008/12/18 $
5  * $Change: 1155299 $
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 "dwc_os.h"
38 #include "dwc_list.h"
39 #include "dwc_otg_dbg.h"
40 #include "dwc_otg_regs.h"
41
42 #include "dwc_otg_core_if.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 verison */
66
67 #define OTG_CORE_REV_2_00       0x4F542000
68 #define OTG_CORE_REV_2_60a      0x4F54260A
69 #define OTG_CORE_REV_2_71a      0x4F54271A
70 #define OTG_CORE_REV_2_72a      0x4F54272A
71 #define OTG_CORE_REV_2_80a      0x4F54280A
72 #define OTG_CORE_REV_2_81a      0x4F54281A
73
74 /**
75  * Information for each ISOC packet.
76  */
77 typedef struct iso_pkt_info {
78         uint32_t offset;
79         uint32_t length;
80         int32_t status;
81 } iso_pkt_info_t;
82
83 /**
84  * The <code>dwc_ep</code> structure represents the state of a single
85  * endpoint when acting in device mode. It contains the data items
86  * needed for an endpoint to be activated and transfer packets.
87  */
88 typedef struct dwc_ep {
89         /** EP number used for register address lookup */
90         uint8_t num;
91         /** EP direction 0 = OUT */
92         unsigned is_in:1;
93         /** EP active. */
94         unsigned active:1;
95
96         /** Periodic Tx FIFO # for IN EPs For INTR EP set to 0 to use non-periodic Tx FIFO
97                 If dedicated Tx FIFOs are enabled for all IN Eps - Tx FIFO # FOR IN EPs*/
98         unsigned tx_fifo_num:4;
99         /** EP type: 0 - Control, 1 - ISOC,      2 - BULK,      3 - INTR */
100         unsigned type:2;
101 #define DWC_OTG_EP_TYPE_CONTROL    0
102 #define DWC_OTG_EP_TYPE_ISOC       1
103 #define DWC_OTG_EP_TYPE_BULK       2
104 #define DWC_OTG_EP_TYPE_INTR       3
105
106         /** DATA start PID for INTR and BULK EP */
107         unsigned data_pid_start:1;
108         /** Frame (even/odd) for ISOC EP */
109         unsigned even_odd_frame:1;
110         /** Max Packet bytes */
111         unsigned maxpacket:11;
112
113         /** Max Transfer size */
114         uint32_t maxxfer;
115
116         /** @name Transfer state */
117         /** @{ */
118
119         /**
120          * Pointer to the beginning of the transfer buffer -- do not modify
121          * during transfer.
122          */
123
124         dwc_dma_t dma_addr;
125
126         dwc_dma_t dma_desc_addr;
127         dwc_otg_dma_desc_t *desc_addr;
128
129         uint8_t *start_xfer_buff;
130         /** pointer to the transfer buffer */
131         uint8_t *xfer_buff;
132         /** Number of bytes to transfer */
133         unsigned xfer_len:19;
134         /** Number of bytes transferred. */
135         unsigned xfer_count:19;
136         /** Sent ZLP */
137         unsigned sent_zlp:1;
138         /** Total len for control transfer */
139         unsigned total_len:19;
140
141         /** stall clear flag */
142         unsigned stall_clear_flag:1;
143
144 #ifdef DWC_UTE_CFI
145         /* The buffer mode */
146         data_buffer_mode_e buff_mode;
147
148         /* The chain of DMA descriptors.
149          * MAX_DMA_DESCS_PER_EP will be allocated for each active EP.
150          */
151         dwc_otg_dma_desc_t *descs;
152
153         /* The DMA address of the descriptors chain start */
154         dma_addr_t descs_dma_addr;
155         /** This variable stores the length of the last enqueued request */
156         uint32_t cfi_req_len;
157 #endif                          //DWC_UTE_CFI
158
159         /** Allocated DMA Desc count */
160         uint32_t desc_cnt;
161
162 #ifdef DWC_EN_ISOC
163         /**
164          * Variables specific for ISOC EPs
165          *
166          */
167         /** DMA addresses of ISOC buffers */
168         dwc_dma_t dma_addr0;
169         dwc_dma_t dma_addr1;
170
171         dwc_dma_t iso_dma_desc_addr;
172         dwc_otg_dma_desc_t *iso_desc_addr;
173
174         /** pointer to the transfer buffers */
175         uint8_t *xfer_buff0;
176         uint8_t *xfer_buff1;
177
178         /** number of ISOC Buffer is processing */
179         uint32_t proc_buf_num;
180         /** Interval of ISOC Buffer processing */
181         uint32_t buf_proc_intrvl;
182         /** Data size for regular frame */
183         uint32_t data_per_frame;
184
185         /* todo - pattern data support is to be implemented in the future */
186         /** Data size for pattern frame */
187         uint32_t data_pattern_frame;
188         /** Frame number of pattern data */
189         uint32_t sync_frame;
190
191         /** bInterval */
192         uint32_t bInterval;
193         /** ISO Packet number per frame */
194         uint32_t pkt_per_frm;
195         /** Next frame num for which will be setup DMA Desc */
196         uint32_t next_frame;
197         /** Number of packets per buffer processing */
198         uint32_t pkt_cnt;
199         /** Info for all isoc packets */
200         iso_pkt_info_t *pkt_info;
201         /** current pkt number */
202         uint32_t cur_pkt;
203         /** current pkt number */
204         uint8_t *cur_pkt_addr;
205         /** current pkt number */
206         uint32_t cur_pkt_dma_addr;
207 #endif                          /* DWC_EN_ISOC */
208
209 /** @} */
210 } dwc_ep_t;
211
212 /*
213  * Reasons for halting a host channel.
214  */
215 typedef enum dwc_otg_halt_status {
216         DWC_OTG_HC_XFER_NO_HALT_STATUS,
217         DWC_OTG_HC_XFER_COMPLETE,
218         DWC_OTG_HC_XFER_URB_COMPLETE,
219         DWC_OTG_HC_XFER_ACK,
220         DWC_OTG_HC_XFER_NAK,
221         DWC_OTG_HC_XFER_NYET,
222         DWC_OTG_HC_XFER_STALL,
223         DWC_OTG_HC_XFER_XACT_ERR,
224         DWC_OTG_HC_XFER_FRAME_OVERRUN,
225         DWC_OTG_HC_XFER_BABBLE_ERR,
226         DWC_OTG_HC_XFER_DATA_TOGGLE_ERR,
227         DWC_OTG_HC_XFER_AHB_ERR,
228         DWC_OTG_HC_XFER_PERIODIC_INCOMPLETE,
229         DWC_OTG_HC_XFER_URB_DEQUEUE
230 } dwc_otg_halt_status_e;
231
232 /**
233  * Host channel descriptor. This structure represents the state of a single
234  * host channel when acting in host mode. It contains the data items needed to
235  * transfer packets to an endpoint via a host channel.
236  */
237 typedef struct dwc_hc {
238         /** Host channel number used for register address lookup */
239         uint8_t hc_num;
240
241         /** Device to access */
242         unsigned dev_addr:7;
243
244         /** EP to access */
245         unsigned ep_num:4;
246
247         /** EP direction. 0: OUT, 1: IN */
248         unsigned ep_is_in:1;
249
250         /**
251          * EP speed.
252          * One of the following values:
253          *      - DWC_OTG_EP_SPEED_LOW
254          *      - DWC_OTG_EP_SPEED_FULL
255          *      - DWC_OTG_EP_SPEED_HIGH
256          */
257         unsigned speed:2;
258 #define DWC_OTG_EP_SPEED_LOW    0
259 #define DWC_OTG_EP_SPEED_FULL   1
260 #define DWC_OTG_EP_SPEED_HIGH   2
261
262         /**
263          * Endpoint type.
264          * One of the following values:
265          *      - DWC_OTG_EP_TYPE_CONTROL: 0
266          *      - DWC_OTG_EP_TYPE_ISOC: 1
267          *      - DWC_OTG_EP_TYPE_BULK: 2
268          *      - DWC_OTG_EP_TYPE_INTR: 3
269          */
270         unsigned ep_type:2;
271
272         /** Max packet size in bytes */
273         unsigned max_packet:11;
274
275         /**
276          * PID for initial transaction.
277          * 0: DATA0,<br>
278          * 1: DATA2,<br>
279          * 2: DATA1,<br>
280          * 3: MDATA (non-Control EP),
281          *        SETUP (Control EP)
282          */
283         unsigned data_pid_start:2;
284 #define DWC_OTG_HC_PID_DATA0 0
285 #define DWC_OTG_HC_PID_DATA2 1
286 #define DWC_OTG_HC_PID_DATA1 2
287 #define DWC_OTG_HC_PID_MDATA 3
288 #define DWC_OTG_HC_PID_SETUP 3
289
290         /** Number of periodic transactions per (micro)frame */
291         unsigned multi_count:2;
292
293         /** @name Transfer State */
294         /** @{ */
295
296         /** Pointer to the current transfer buffer position. */
297         uint8_t *xfer_buff;
298         /** Total number of bytes to transfer. */
299         uint32_t xfer_len;
300         /** Number of bytes transferred so far. */
301         uint32_t xfer_count;
302         /** Packet count at start of transfer.*/
303         uint16_t start_pkt_count;
304
305         /**
306          * Flag to indicate whether the transfer has been started. Set to 1 if
307          * it has been started, 0 otherwise.
308          */
309         uint8_t xfer_started;
310
311         /**
312          * Set to 1 to indicate that a PING request should be issued on this
313          * channel. If 0, process normally.
314          */
315         uint8_t do_ping;
316
317         /**
318          * Set to 1 to indicate that the error count for this transaction is
319          * non-zero. Set to 0 if the error count is 0.
320          */
321         uint8_t error_state;
322
323         /**
324          * Set to 1 to indicate that this channel should be halted the next
325          * time a request is queued for the channel. This is necessary in
326          * slave mode if no request queue space is available when an attempt
327          * is made to halt the channel.
328          */
329         uint8_t halt_on_queue;
330
331         /**
332          * Set to 1 if the host channel has been halted, but the core is not
333          * finished flushing queued requests. Otherwise 0.
334          */
335         uint8_t halt_pending;
336
337         /**
338          * Reason for halting the host channel.
339          */
340         dwc_otg_halt_status_e halt_status;
341
342         /*
343          * Split settings for the host channel
344          */
345         uint8_t do_split;                  /**< Enable split for the channel */
346         uint8_t complete_split;    /**< Enable complete split */
347         uint8_t hub_addr;                  /**< Address of high speed hub */
348
349         uint8_t port_addr;                 /**< Port of the low/full speed device */
350         /** Split transaction position
351          * One of the following values:
352          *        - DWC_HCSPLIT_XACTPOS_MID
353          *        - DWC_HCSPLIT_XACTPOS_BEGIN
354          *        - DWC_HCSPLIT_XACTPOS_END
355          *        - DWC_HCSPLIT_XACTPOS_ALL */
356         uint8_t xact_pos;
357
358         /** Set when the host channel does a short read. */
359         uint8_t short_read;
360
361         /**
362          * Number of requests issued for this channel since it was assigned to
363          * the current transfer (not counting PINGs).
364          */
365         uint8_t requests;
366
367         /**
368          * Queue Head for the transfer being processed by this channel.
369          */
370         struct dwc_otg_qh *qh;
371
372         /** @} */
373
374         /** Entry in list of host channels. */
375          DWC_CIRCLEQ_ENTRY(dwc_hc) hc_list_entry;
376 } dwc_hc_t;
377
378 /**
379  * The following parameters may be specified when starting the module. These
380  * parameters define how the DWC_otg controller should be configured.
381  */
382 typedef struct dwc_otg_core_params {
383         int32_t opt;
384
385         /**
386          * Specifies the OTG capabilities. The driver will automatically
387          * detect the value for this parameter if none is specified.
388          * 0 - HNP and SRP capable (default)
389          * 1 - SRP Only capable
390          * 2 - No HNP/SRP capable
391          */
392         int32_t otg_cap;
393
394         /**
395          * Specifies whether to use slave or DMA mode for accessing the data
396          * FIFOs. The driver will automatically detect the value for this
397          * parameter if none is specified.
398          * 0 - Slave
399          * 1 - DMA (default, if available)
400          */
401         int32_t dma_enable;
402
403         /**
404          * When DMA mode is enabled specifies whether to use address DMA or DMA Descritor mode for accessing the data
405          * FIFOs in device mode. The driver will automatically detect the value for this
406          * parameter if none is specified.
407          * 0 - address DMA
408          * 1 - DMA Descriptor(default, if available)
409          */
410         int32_t dma_desc_enable;
411         /** The DMA Burst size (applicable only for External DMA
412          * Mode). 1, 4, 8 16, 32, 64, 128, 256 (default 32)
413          */
414         int32_t dma_burst_size; /* Translate this to GAHBCFG values */
415
416         /**
417          * Specifies the maximum speed of operation in host and device mode.
418          * The actual speed depends on the speed of the attached device and
419          * the value of phy_type. The actual speed depends on the speed of the
420          * attached device.
421          * 0 - High Speed (default)
422          * 1 - Full Speed
423          */
424         int32_t speed;
425         /** Specifies whether low power mode is supported when attached
426          *      to a Full Speed or Low Speed device in host mode.
427          * 0 - Don't support low power mode (default)
428          * 1 - Support low power mode
429          */
430         int32_t host_support_fs_ls_low_power;
431
432         /** Specifies the PHY clock rate in low power mode when connected to a
433          * Low Speed device in host mode. This parameter is applicable only if
434          * HOST_SUPPORT_FS_LS_LOW_POWER is enabled.      If PHY_TYPE is set to FS
435          * then defaults to 6 MHZ otherwise 48 MHZ.
436          *
437          * 0 - 48 MHz
438          * 1 - 6 MHz
439          */
440         int32_t host_ls_low_power_phy_clk;
441
442         /**
443          * 0 - Use cC FIFO size parameters
444          * 1 - Allow dynamic FIFO sizing (default)
445          */
446         int32_t enable_dynamic_fifo;
447
448         /** Total number of 4-byte words in the data FIFO memory. This
449          * memory includes the Rx FIFO, non-periodic Tx FIFO, and periodic
450          * Tx FIFOs.
451          * 32 to 32768 (default 8192)
452          * Note: The total FIFO memory depth in the FPGA configuration is 8192.
453          */
454         int32_t data_fifo_size;
455
456         /** Number of 4-byte words in the Rx FIFO in device mode when dynamic
457          * FIFO sizing is enabled.
458          * 16 to 32768 (default 1064)
459          */
460         int32_t dev_rx_fifo_size;
461
462         /** Number of 4-byte words in the non-periodic Tx FIFO in device mode
463          * when dynamic FIFO sizing is enabled.
464          * 16 to 32768 (default 1024)
465          */
466         int32_t dev_nperio_tx_fifo_size;
467
468         /** Number of 4-byte words in each of the periodic Tx FIFOs in device
469          * mode when dynamic FIFO sizing is enabled.
470          * 4 to 768 (default 256)
471          */
472         uint32_t dev_perio_tx_fifo_size[MAX_PERIO_FIFOS];
473
474         /** Number of 4-byte words in the Rx FIFO in host mode when dynamic
475          * FIFO sizing is enabled.
476          * 16 to 32768 (default 1024)
477          */
478         int32_t host_rx_fifo_size;
479
480                 /** Number of 4-byte words in the non-periodic Tx FIFO in host mode
481          * when Dynamic FIFO sizing is enabled in the core.
482          * 16 to 32768 (default 1024)
483          */
484         int32_t host_nperio_tx_fifo_size;
485
486         /** Number of 4-byte words in the host periodic Tx FIFO when dynamic
487          * FIFO sizing is enabled.
488          * 16 to 32768 (default 1024)
489          */
490         int32_t host_perio_tx_fifo_size;
491
492         /** The maximum transfer size supported in bytes.
493          * 2047 to 65,535  (default 65,535)
494          */
495         int32_t max_transfer_size;
496
497         /** The maximum number of packets in a transfer.
498          * 15 to 511  (default 511)
499          */
500         int32_t max_packet_count;
501
502         /** The number of host channel registers to use.
503          * 1 to 16 (default 12)
504          * Note: The FPGA configuration supports a maximum of 12 host channels.
505          */
506         int32_t host_channels;
507
508         /** The number of endpoints in addition to EP0 available for device
509          * mode operations.
510          * 1 to 15 (default 6 IN and OUT)
511          * Note: The FPGA configuration supports a maximum of 6 IN and OUT
512          * endpoints in addition to EP0.
513          */
514         int32_t dev_endpoints;
515
516                 /**
517                  * Specifies the type of PHY interface to use. By default, the driver
518                  * will automatically detect the phy_type.
519                  *
520                  * 0 - Full Speed PHY
521                  * 1 - UTMI+ (default)
522                  * 2 - ULPI
523                  */
524         int32_t phy_type;
525
526         /**
527          * Specifies the UTMI+ Data Width.      This parameter is
528          * applicable for a PHY_TYPE of UTMI+ or ULPI. (For a ULPI
529          * PHY_TYPE, this parameter indicates the data width between
530          * the MAC and the ULPI Wrapper.) Also, this parameter is
531          * applicable only if the OTG_HSPHY_WIDTH cC parameter was set
532          * to "8 and 16 bits", meaning that the core has been
533          * configured to work at either data path width.
534          *
535          * 8 or 16 bits (default 16)
536          */
537         int32_t phy_utmi_width;
538
539         /**
540          * Specifies whether the ULPI operates at double or single
541          * data rate. This parameter is only applicable if PHY_TYPE is
542          * ULPI.
543          *
544          * 0 - single data rate ULPI interface with 8 bit wide data
545          * bus (default)
546          * 1 - double data rate ULPI interface with 4 bit wide data
547          * bus
548          */
549         int32_t phy_ulpi_ddr;
550
551         /**
552          * Specifies whether to use the internal or external supply to
553          * drive the vbus with a ULPI phy.
554          */
555         int32_t phy_ulpi_ext_vbus;
556
557         /**
558          * Specifies whether to use the I2Cinterface for full speed PHY. This
559          * parameter is only applicable if PHY_TYPE is FS.
560          * 0 - No (default)
561          * 1 - Yes
562          */
563         int32_t i2c_enable;
564
565         int32_t ulpi_fs_ls;
566
567         int32_t ts_dline;
568
569         /**
570          * Specifies whether dedicated transmit FIFOs are
571          * enabled for non periodic IN endpoints in device mode
572          * 0 - No
573          * 1 - Yes
574          */
575         int32_t en_multiple_tx_fifo;
576
577         /** Number of 4-byte words in each of the Tx FIFOs in device
578          * mode when dynamic FIFO sizing is enabled.
579          * 4 to 768 (default 256)
580          */
581         uint32_t dev_tx_fifo_size[MAX_TX_FIFOS];
582
583         /** Thresholding enable flag-
584          * bit 0 - enable non-ISO Tx thresholding
585          * bit 1 - enable ISO Tx thresholding
586          * bit 2 - enable Rx thresholding
587          */
588         uint32_t thr_ctl;
589
590         /** Thresholding length for Tx
591          *      FIFOs in 32 bit DWORDs
592          */
593         uint32_t tx_thr_length;
594
595         /** Thresholding length for Rx
596          *      FIFOs in 32 bit DWORDs
597          */
598         uint32_t rx_thr_length;
599
600         /**
601          * Specifies whether LPM (Link Power Management) support is enabled
602          */
603         int32_t lpm_enable;
604
605         /** Per Transfer Interrupt
606          *      mode enable flag
607          * 1 - Enabled
608          * 0 - Disabled
609          */
610         int32_t pti_enable;
611
612         /** Multi Processor Interrupt
613          *      mode enable flag
614          * 1 - Enabled
615          * 0 - Disabled
616          */
617         int32_t mpi_enable;
618
619         /** IS_USB Capability
620          * 1 - Enabled
621          * 0 - Disabled
622          */
623         int32_t ic_usb_cap;
624
625         /** AHB Threshold Ratio
626          * 2'b00 AHB Threshold =        MAC Threshold
627          * 2'b01 AHB Threshold = 1/2    MAC Threshold
628          * 2'b10 AHB Threshold = 1/4    MAC Threshold
629          * 2'b11 AHB Threshold = 1/8    MAC Threshold
630          */
631         int32_t ahb_thr_ratio;
632
633 } dwc_otg_core_params_t;
634
635 #ifdef DEBUG
636 struct dwc_otg_core_if;
637 typedef struct hc_xfer_info {
638         struct dwc_otg_core_if *core_if;
639         dwc_hc_t *hc;
640 } hc_xfer_info_t;
641 #endif
642 /*
643  * Device States
644  */
645 typedef enum dwc_otg_lx_state {
646         /** On state */
647         DWC_OTG_L0,
648         /** LPM sleep state*/
649         DWC_OTG_L1,
650         /** USB suspend state*/
651         DWC_OTG_L2,
652         /** Off state*/
653         DWC_OTG_L3
654 } dwc_otg_lx_state_e;
655
656 /**
657  * The <code>dwc_otg_core_if</code> structure contains information needed to manage
658  * the DWC_otg controller acting in either host or device mode. It
659  * represents the programming view of the controller as a whole.
660  */
661 struct dwc_otg_core_if {
662         /** Parameters that define how the core should be configured.*/
663         dwc_otg_core_params_t *core_params;
664
665         /** Core Global registers starting at offset 000h. */
666         dwc_otg_core_global_regs_t *core_global_regs;
667
668         /** Device-specific information */
669         dwc_otg_dev_if_t *dev_if;
670         /** Host-specific information */
671         dwc_otg_host_if_t *host_if;
672
673         /** Value from SNPSID register */
674         uint32_t snpsid;
675
676         /*
677          * Set to 1 if the core PHY interface bits in USBCFG have been
678          * initialized.
679          */
680         uint8_t phy_init_done;
681
682         /*
683          * SRP Success flag, set by srp success interrupt in FS I2C mode
684          */
685         uint8_t srp_success;
686         uint8_t srp_timer_started;
687
688         /* Common configuration information */
689         /** Power and Clock Gating Control Register */
690         volatile uint32_t *pcgcctl;
691 #define DWC_OTG_PCGCCTL_OFFSET 0xE00
692
693         /** Push/pop addresses for endpoints or host channels.*/
694         uint32_t *data_fifo[MAX_EPS_CHANNELS];
695 #define DWC_OTG_DATA_FIFO_OFFSET 0x1000
696 #define DWC_OTG_DATA_FIFO_SIZE 0x1000
697
698         /** Total RAM for FIFOs (Bytes) */
699         uint16_t total_fifo_size;
700         /** Size of Rx FIFO (Bytes) */
701         uint16_t rx_fifo_size;
702         /** Size of Non-periodic Tx FIFO (Bytes) */
703         uint16_t nperio_tx_fifo_size;
704
705         /** 1 if DMA is enabled, 0 otherwise. */
706         uint8_t dma_enable;
707
708         /** 1 if DMA descriptor is enabled, 0 otherwise. */
709         uint8_t dma_desc_enable;
710
711         /** 1 if PTI Enhancement mode is enabled, 0 otherwise. */
712         uint8_t pti_enh_enable;
713
714         /** 1 if MPI Enhancement mode is enabled, 0 otherwise. */
715         uint8_t multiproc_int_enable;
716
717         /** 1 if dedicated Tx FIFOs are enabled, 0 otherwise. */
718         uint8_t en_multiple_tx_fifo;
719
720         /** Set to 1 if multiple packets of a high-bandwidth transfer is in
721          * process of being queued */
722         uint8_t queuing_high_bandwidth;
723
724         /** Hardware Configuration -- stored here for convenience.*/
725         hwcfg1_data_t hwcfg1;
726         hwcfg2_data_t hwcfg2;
727         hwcfg3_data_t hwcfg3;
728         hwcfg4_data_t hwcfg4;
729
730         /** Host and Device Configuration -- stored here for convenience.*/
731         hcfg_data_t hcfg;
732         dcfg_data_t dcfg;
733
734         /** The operational State, during transations
735          * (a_host>>a_peripherial and b_device=>b_host) this may not
736          * match the core but allows the software to determine
737          * transitions.
738          */
739         uint8_t op_state;
740
741         /**
742          * Set to 1 if the HCD needs to be restarted on a session request
743          * interrupt. This is required if no connector ID status change has
744          * occurred since the HCD was last disconnected.
745          */
746         uint8_t restart_hcd_on_session_req;
747
748         /** HCD callbacks */
749         /** A-Device is a_host */
750 #define A_HOST          (1)
751         /** A-Device is a_suspend */
752 #define A_SUSPEND       (2)
753         /** A-Device is a_peripherial */
754 #define A_PERIPHERAL    (3)
755         /** B-Device is operating as a Peripheral. */
756 #define B_PERIPHERAL    (4)
757         /** B-Device is operating as a Host. */
758 #define B_HOST          (5)
759
760         /** HCD callbacks */
761         struct dwc_otg_cil_callbacks *hcd_cb;
762         /** PCD callbacks */
763         struct dwc_otg_cil_callbacks *pcd_cb;
764
765         /** Device mode Periodic Tx FIFO Mask */
766         uint32_t p_tx_msk;
767         /** Device mode Periodic Tx FIFO Mask */
768         uint32_t tx_msk;
769
770         /** Workqueue object used for handling several interrupts */
771         dwc_workq_t *wq_otg;
772
773         /** Timer object used for handling "Wakeup Detected" Interrupt */
774         dwc_timer_t *wkp_timer;
775
776 #ifdef DEBUG
777         uint32_t start_hcchar_val[MAX_EPS_CHANNELS];
778
779         hc_xfer_info_t hc_xfer_info[MAX_EPS_CHANNELS];
780         dwc_timer_t *hc_xfer_timer[MAX_EPS_CHANNELS];
781
782         uint32_t hfnum_7_samples;
783         uint64_t hfnum_7_frrem_accum;
784         uint32_t hfnum_0_samples;
785         uint64_t hfnum_0_frrem_accum;
786         uint32_t hfnum_other_samples;
787         uint64_t hfnum_other_frrem_accum;
788 #endif
789
790 #ifdef DWC_UTE_CFI
791         uint16_t pwron_rxfsiz;
792         uint16_t pwron_gnptxfsiz;
793         uint16_t pwron_txfsiz[15];
794
795         uint16_t init_rxfsiz;
796         uint16_t init_gnptxfsiz;
797         uint16_t init_txfsiz[15];
798 #endif
799
800         /** Lx state of device */
801         dwc_otg_lx_state_e lx_state;
802
803 };
804
805 #ifdef DEBUG
806 /*
807  * This function is called when transfer is timed out.
808  */
809 extern void hc_xfer_timeout(void *ptr);
810 #endif
811
812 /*
813  * The following functions are functions for works
814  * using during handling some interrupts
815  */
816 extern void w_conn_id_status_change(void *p);
817
818 extern void w_wakeup_detected(void *p);
819
820 /*
821  * The following functions support initialization of the CIL driver component
822  * and the DWC_otg controller.
823  */
824 extern void dwc_otg_core_host_init(dwc_otg_core_if_t * _core_if);
825 extern void dwc_otg_core_dev_init(dwc_otg_core_if_t * _core_if);
826
827 /** @name Device CIL Functions
828  * The following functions support managing the DWC_otg controller in device
829  * mode.
830  */
831 /**@{*/
832 extern void dwc_otg_wakeup(dwc_otg_core_if_t * _core_if);
833 extern void dwc_otg_read_setup_packet(dwc_otg_core_if_t * _core_if,
834                                       uint32_t * _dest);
835 extern uint32_t dwc_otg_get_frame_number(dwc_otg_core_if_t * _core_if);
836 extern void dwc_otg_ep0_activate(dwc_otg_core_if_t * _core_if, dwc_ep_t * _ep);
837 extern void dwc_otg_ep_activate(dwc_otg_core_if_t * _core_if, dwc_ep_t * _ep);
838 extern void dwc_otg_ep_deactivate(dwc_otg_core_if_t * _core_if, dwc_ep_t * _ep);
839 extern void dwc_otg_ep_start_transfer(dwc_otg_core_if_t * _core_if,
840                                       dwc_ep_t * _ep);
841 extern void dwc_otg_ep_start_zl_transfer(dwc_otg_core_if_t * _core_if,
842                                          dwc_ep_t * _ep);
843 extern void dwc_otg_ep0_start_transfer(dwc_otg_core_if_t * _core_if,
844                                        dwc_ep_t * _ep);
845 extern void dwc_otg_ep0_continue_transfer(dwc_otg_core_if_t * _core_if,
846                                           dwc_ep_t * _ep);
847 extern void dwc_otg_ep_write_packet(dwc_otg_core_if_t * _core_if,
848                                     dwc_ep_t * _ep, int _dma);
849 extern void dwc_otg_ep_set_stall(dwc_otg_core_if_t * _core_if, dwc_ep_t * _ep);
850 extern void dwc_otg_ep_clear_stall(dwc_otg_core_if_t * _core_if,
851                                    dwc_ep_t * _ep);
852 extern void dwc_otg_enable_device_interrupts(dwc_otg_core_if_t * _core_if);
853
854 #ifdef DWC_EN_ISOC
855 extern void dwc_otg_iso_ep_start_frm_transfer(dwc_otg_core_if_t * core_if,
856                                               dwc_ep_t * ep);
857 extern void dwc_otg_iso_ep_start_buf_transfer(dwc_otg_core_if_t * core_if,
858                                               dwc_ep_t * ep);
859 #endif                          /* DWC_EN_ISOC */
860 /**@}*/
861
862 /** @name Host CIL Functions
863  * The following functions support managing the DWC_otg controller in host
864  * mode.
865  */
866 /**@{*/
867 extern void dwc_otg_hc_init(dwc_otg_core_if_t * _core_if, dwc_hc_t * _hc);
868 extern void dwc_otg_hc_halt(dwc_otg_core_if_t * _core_if,
869                             dwc_hc_t * _hc, dwc_otg_halt_status_e _halt_status);
870 extern void dwc_otg_hc_cleanup(dwc_otg_core_if_t * _core_if, dwc_hc_t * _hc);
871 extern void dwc_otg_hc_start_transfer(dwc_otg_core_if_t * _core_if,
872                                       dwc_hc_t * _hc);
873 extern int dwc_otg_hc_continue_transfer(dwc_otg_core_if_t * _core_if,
874                                         dwc_hc_t * _hc);
875 extern void dwc_otg_hc_do_ping(dwc_otg_core_if_t * _core_if, dwc_hc_t * _hc);
876 extern void dwc_otg_hc_write_packet(dwc_otg_core_if_t * _core_if,
877                                     dwc_hc_t * _hc);
878 extern void dwc_otg_enable_host_interrupts(dwc_otg_core_if_t * _core_if);
879 extern void dwc_otg_disable_host_interrupts(dwc_otg_core_if_t * _core_if);
880
881 /**
882  * This function Reads HPRT0 in preparation to modify.  It keeps the
883  * WC bits 0 so that if they are read as 1, they won't clear when you
884  * write it back
885  */
886 static inline uint32_t dwc_otg_read_hprt0(dwc_otg_core_if_t * _core_if)
887 {
888         hprt0_data_t hprt0;
889         hprt0.d32 = dwc_read_reg32(_core_if->host_if->hprt0);
890         hprt0.b.prtena = 0;
891         hprt0.b.prtconndet = 0;
892         hprt0.b.prtenchng = 0;
893         hprt0.b.prtovrcurrchng = 0;
894         return hprt0.d32;
895 }
896
897 /**@}*/
898
899 /** @name Common CIL Functions
900  * The following functions support managing the DWC_otg controller in either
901  * device or host mode.
902  */
903 /**@{*/
904
905 extern void dwc_otg_read_packet(dwc_otg_core_if_t * core_if,
906                                 uint8_t * dest, uint16_t bytes);
907
908 extern void dwc_otg_flush_tx_fifo(dwc_otg_core_if_t * _core_if, const int _num);
909 extern void dwc_otg_flush_rx_fifo(dwc_otg_core_if_t * _core_if);
910 extern void dwc_otg_core_reset(dwc_otg_core_if_t * _core_if);
911
912 /**
913  * This function returns the Core Interrupt register.
914  */
915 static inline uint32_t dwc_otg_read_core_intr(dwc_otg_core_if_t * core_if)
916 {
917         return (dwc_read_reg32(&core_if->core_global_regs->gintsts) &
918                 dwc_read_reg32(&core_if->core_global_regs->gintmsk));
919 }
920
921 /**
922  * This function returns the OTG Interrupt register.
923  */
924 static inline uint32_t dwc_otg_read_otg_intr(dwc_otg_core_if_t * core_if)
925 {
926         return (dwc_read_reg32(&core_if->core_global_regs->gotgint));
927 }
928
929 /**
930  * This function reads the Device All Endpoints Interrupt register and
931  * returns the IN endpoint interrupt bits.
932  */
933 static inline uint32_t dwc_otg_read_dev_all_in_ep_intr(dwc_otg_core_if_t *
934                                                        core_if)
935 {
936
937         uint32_t v;
938
939         if (core_if->multiproc_int_enable) {
940                 v = dwc_read_reg32(&core_if->dev_if->dev_global_regs->
941                                    deachint) & dwc_read_reg32(&core_if->dev_if->
942                                                               dev_global_regs->
943                                                               deachintmsk);
944         } else {
945                 v = dwc_read_reg32(&core_if->dev_if->dev_global_regs->daint) &
946                     dwc_read_reg32(&core_if->dev_if->dev_global_regs->daintmsk);
947         }
948         return (v & 0xffff);
949 }
950
951 /**
952  * This function reads the Device All Endpoints Interrupt register and
953  * returns the OUT endpoint interrupt bits.
954  */
955 static inline uint32_t dwc_otg_read_dev_all_out_ep_intr(dwc_otg_core_if_t *
956                                                         core_if)
957 {
958         uint32_t v;
959
960         if (core_if->multiproc_int_enable) {
961                 v = dwc_read_reg32(&core_if->dev_if->dev_global_regs->
962                                    deachint) & dwc_read_reg32(&core_if->dev_if->
963                                                               dev_global_regs->
964                                                               deachintmsk);
965         } else {
966                 v = dwc_read_reg32(&core_if->dev_if->dev_global_regs->daint) &
967                     dwc_read_reg32(&core_if->dev_if->dev_global_regs->daintmsk);
968         }
969
970         return ((v & 0xffff0000) >> 16);
971 }
972
973 /**
974  * This function returns the Device IN EP Interrupt register
975  */
976 static inline uint32_t dwc_otg_read_dev_in_ep_intr(dwc_otg_core_if_t * core_if,
977                                                    dwc_ep_t * ep)
978 {
979         dwc_otg_dev_if_t *dev_if = core_if->dev_if;
980         uint32_t v, msk, emp;
981
982         if (core_if->multiproc_int_enable) {
983                 msk =
984                     dwc_read_reg32(&dev_if->dev_global_regs->
985                                    diepeachintmsk[ep->num]);
986                 emp =
987                     dwc_read_reg32(&dev_if->dev_global_regs->
988                                    dtknqr4_fifoemptymsk);
989                 msk |= ((emp >> ep->num) & 0x1) << 7;
990                 v = dwc_read_reg32(&dev_if->in_ep_regs[ep->num]->diepint) & msk;
991         } else {
992                 msk = dwc_read_reg32(&dev_if->dev_global_regs->diepmsk);
993                 emp =
994                     dwc_read_reg32(&dev_if->dev_global_regs->
995                                    dtknqr4_fifoemptymsk);
996                 msk |= ((emp >> ep->num) & 0x1) << 7;
997                 v = dwc_read_reg32(&dev_if->in_ep_regs[ep->num]->diepint) & msk;
998         }
999
1000         return v;
1001 }
1002
1003 /**
1004  * This function returns the Device OUT EP Interrupt register
1005  */
1006 static inline uint32_t dwc_otg_read_dev_out_ep_intr(dwc_otg_core_if_t *
1007                                                     _core_if, dwc_ep_t * _ep)
1008 {
1009         dwc_otg_dev_if_t *dev_if = _core_if->dev_if;
1010         uint32_t v;
1011         doepmsk_data_t msk = {.d32 = 0 };
1012
1013         if (_core_if->multiproc_int_enable) {
1014                 msk.d32 =
1015                     dwc_read_reg32(&dev_if->dev_global_regs->
1016                                    doepeachintmsk[_ep->num]);
1017                 if (_core_if->pti_enh_enable) {
1018                         msk.b.pktdrpsts = 1;
1019                 }
1020                 v = dwc_read_reg32(&dev_if->out_ep_regs[_ep->num]->
1021                                    doepint) & msk.d32;
1022         } else {
1023                 msk.d32 = dwc_read_reg32(&dev_if->dev_global_regs->doepmsk);
1024                 if (_core_if->pti_enh_enable) {
1025                         msk.b.pktdrpsts = 1;
1026                 }
1027                 v = dwc_read_reg32(&dev_if->out_ep_regs[_ep->num]->
1028                                    doepint) & msk.d32;
1029         }
1030         return v;
1031 }
1032
1033 /**
1034  * This function returns the Host All Channel Interrupt register
1035  */
1036 static inline uint32_t dwc_otg_read_host_all_channels_intr(dwc_otg_core_if_t *
1037                                                            _core_if)
1038 {
1039         return (dwc_read_reg32(&_core_if->host_if->host_global_regs->haint));
1040 }
1041
1042 static inline uint32_t dwc_otg_read_host_channel_intr(dwc_otg_core_if_t *
1043                                                       _core_if, dwc_hc_t * _hc)
1044 {
1045         return (dwc_read_reg32
1046                 (&_core_if->host_if->hc_regs[_hc->hc_num]->hcint));
1047 }
1048
1049 /**
1050  * This function returns the mode of the operation, host or device.
1051  *
1052  * @return 0 - Device Mode, 1 - Host Mode
1053  */
1054 static inline uint32_t dwc_otg_mode(dwc_otg_core_if_t * _core_if)
1055 {
1056         return (dwc_read_reg32(&_core_if->core_global_regs->gintsts) & 0x1);
1057 }
1058
1059 /**@}*/
1060
1061 /**
1062  * DWC_otg CIL callback structure.      This structure allows the HCD and
1063  * PCD to register functions used for starting and stopping the PCD
1064  * and HCD for role change on for a DRD.
1065  */
1066 typedef struct dwc_otg_cil_callbacks {
1067         /** Start function for role change */
1068         int (*start) (void *_p);
1069         /** Stop Function for role change */
1070         int (*stop) (void *_p);
1071         /** Disconnect Function for role change */
1072         int (*disconnect) (void *_p);
1073         /** Resume/Remote wakeup Function */
1074         int (*resume_wakeup) (void *_p);
1075         /** Suspend function */
1076         int (*suspend) (void *_p);
1077         /** Session Start (SRP) */
1078         int (*session_start) (void *_p);
1079 #ifdef CONFIG_USB_DWC_OTG_LPM
1080         /** Sleep (switch to L0 state) */
1081         int (*sleep) (void *_p);
1082 #endif
1083         /** Pointer passed to start() and stop() */
1084         void *p;
1085 } dwc_otg_cil_callbacks_t;
1086
1087 extern void dwc_otg_cil_register_pcd_callbacks(dwc_otg_core_if_t * _core_if,
1088                                                dwc_otg_cil_callbacks_t * _cb,
1089                                                void *_p);
1090 extern void dwc_otg_cil_register_hcd_callbacks(dwc_otg_core_if_t * _core_if,
1091                                                dwc_otg_cil_callbacks_t * _cb,
1092                                                void *_p);
1093
1094 #endif