tizen 2.4 release
[profile/mobile/platform/kernel/linux-3.10-sc7730.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: #123 $
4  * $Date: 2012/08/10 $
5  * $Change: 2047372 $
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 <linux/scatterlist.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 #include "dwc_otg_adp.h"
44
45 /**
46  * @file
47  * This file contains the interface to the Core Interface Layer.
48  */
49
50 #ifdef DWC_UTE_CFI
51
52 #define MAX_DMA_DESCS_PER_EP    256
53
54 /**
55  * Enumeration for the data buffer mode
56  */
57 typedef enum _data_buffer_mode {
58         BM_STANDARD = 0,        /* data buffer is in normal mode */
59         BM_SG = 1,              /* data buffer uses the scatter/gather mode */
60         BM_CONCAT = 2,          /* data buffer uses the concatenation mode */
61         BM_CIRCULAR = 3,        /* data buffer uses the circular DMA mode */
62         BM_ALIGN = 4            /* data buffer is in buffer alignment mode */
63 } data_buffer_mode_e;
64 #endif //DWC_UTE_CFI
65
66 /** Macros defined for DWC OTG HW Release version */
67
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 #define OTG_CORE_REV_2_90a      0x4F54290A
74 #define OTG_CORE_REV_2_91a      0x4F54291A
75 #define OTG_CORE_REV_2_92a      0x4F54292A
76 #define OTG_CORE_REV_2_93a      0x4F54293A
77 #define OTG_CORE_REV_2_94a      0x4F54294A
78 #define OTG_CORE_REV_3_00a      0x4F54300A
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 hub_addr;                  /**< Address of high speed hub */
381
382         uint8_t port_addr;                 /**< Port of the low/full speed device */
383         /** Split transaction position
384          * One of the following values:
385          *        - DWC_HCSPLIT_XACTPOS_MID
386          *        - DWC_HCSPLIT_XACTPOS_BEGIN
387          *        - DWC_HCSPLIT_XACTPOS_END
388          *        - DWC_HCSPLIT_XACTPOS_ALL */
389         uint8_t xact_pos;
390
391         /** Set when the host channel does a short read. */
392         uint8_t short_read;
393
394         /**
395          * Number of requests issued for this channel since it was assigned to
396          * the current transfer (not counting PINGs).
397          */
398         uint8_t requests;
399
400         /**
401          * Queue Head for the transfer being processed by this channel.
402          */
403         struct dwc_otg_qh *qh;
404
405         /** @} */
406
407         /** Entry in list of host channels. */
408          DWC_CIRCLEQ_ENTRY(dwc_hc) hc_list_entry;
409
410         /** @name Descriptor DMA support */
411         /** @{ */
412
413         /** Number of Transfer Descriptors */
414         uint16_t ntd;
415
416         /** Descriptor List DMA address */
417         dwc_dma_t desc_list_addr;
418
419         /** Scheduling micro-frame bitmap. */
420         uint8_t schinfo;
421
422         /** @} */
423 } dwc_hc_t;
424
425 /**
426  * The following parameters may be specified when starting the module. These
427  * parameters define how the DWC_otg controller should be configured.
428  */
429 typedef struct dwc_otg_core_params {
430         int32_t opt;
431
432         /**
433          * Specifies the OTG capabilities. The driver will automatically
434          * detect the value for this parameter if none is specified.
435          * 0 - HNP and SRP capable (default)
436          * 1 - SRP Only capable
437          * 2 - No HNP/SRP capable
438          */
439         int32_t otg_cap;
440
441         /**
442          * Specifies whether to use slave or DMA mode for accessing the data
443          * FIFOs. The driver will automatically detect the value for this
444          * parameter if none is specified.
445          * 0 - Slave
446          * 1 - DMA (default, if available)
447          */
448         int32_t dma_enable;
449
450         /**
451          * When DMA mode is enabled specifies whether to use address DMA or DMA
452          * Descriptor mode for accessing the data FIFOs in device mode. The driver
453          * will automatically detect the value for this if none is specified.
454          * 0 - address DMA
455          * 1 - DMA Descriptor(default, if available)
456          */
457         int32_t dma_desc_enable;
458         /** The DMA Burst size (applicable only for External DMA
459          * Mode). 1, 4, 8 16, 32, 64, 128, 256 (default 32)
460          */
461         int32_t dma_burst_size; /* Translate this to GAHBCFG values */
462
463         /**
464          * Specifies the maximum speed of operation in host and device mode.
465          * The actual speed depends on the speed of the attached device and
466          * the value of phy_type. The actual speed depends on the speed of the
467          * attached device.
468          * 0 - High Speed (default)
469          * 1 - Full Speed
470          */
471         int32_t speed;
472         /** Specifies whether low power mode is supported when attached
473          *      to a Full Speed or Low Speed device in host mode.
474          * 0 - Don't support low power mode (default)
475          * 1 - Support low power mode
476          */
477         int32_t host_support_fs_ls_low_power;
478
479         /** Specifies the PHY clock rate in low power mode when connected to a
480          * Low Speed device in host mode. This parameter is applicable only if
481          * HOST_SUPPORT_FS_LS_LOW_POWER is enabled. If PHY_TYPE is set to FS
482          * then defaults to 6 MHZ otherwise 48 MHZ.
483          *
484          * 0 - 48 MHz
485          * 1 - 6 MHz
486          */
487         int32_t host_ls_low_power_phy_clk;
488
489         /**
490          * 0 - Use cC FIFO size parameters
491          * 1 - Allow dynamic FIFO sizing (default)
492          */
493         int32_t enable_dynamic_fifo;
494
495         /** Total number of 4-byte words in the data FIFO memory. This
496          * memory includes the Rx FIFO, non-periodic Tx FIFO, and periodic
497          * Tx FIFOs.
498          * 32 to 32768 (default 8192)
499          * Note: The total FIFO memory depth in the FPGA configuration is 8192.
500          */
501         int32_t data_fifo_size;
502
503         /** Number of 4-byte words in the Rx FIFO in device mode when dynamic
504          * FIFO sizing is enabled.
505          * 16 to 32768 (default 1064)
506          */
507         int32_t dev_rx_fifo_size;
508
509         /** Number of 4-byte words in the non-periodic Tx FIFO in device mode
510          * when dynamic FIFO sizing is enabled.
511          * 16 to 32768 (default 1024)
512          */
513         int32_t dev_nperio_tx_fifo_size;
514
515         /** Number of 4-byte words in each of the periodic Tx FIFOs in device
516          * mode when dynamic FIFO sizing is enabled.
517          * 4 to 768 (default 256)
518          */
519         uint32_t dev_perio_tx_fifo_size[MAX_PERIO_FIFOS];
520
521         /** Number of 4-byte words in the Rx FIFO in host mode when dynamic
522          * FIFO sizing is enabled.
523          * 16 to 32768 (default 1024)
524          */
525         int32_t host_rx_fifo_size;
526
527         /** Number of 4-byte words in the non-periodic Tx FIFO in host mode
528          * when Dynamic FIFO sizing is enabled in the core.
529          * 16 to 32768 (default 1024)
530          */
531         int32_t host_nperio_tx_fifo_size;
532
533         /** Number of 4-byte words in the host periodic Tx FIFO when dynamic
534          * FIFO sizing is enabled.
535          * 16 to 32768 (default 1024)
536          */
537         int32_t host_perio_tx_fifo_size;
538
539         /** The maximum transfer size supported in bytes.
540          * 2047 to 65,535  (default 65,535)
541          */
542         int32_t max_transfer_size;
543
544         /** The maximum number of packets in a transfer.
545          * 15 to 511  (default 511)
546          */
547         int32_t max_packet_count;
548
549         /** The number of host channel registers to use.
550          * 1 to 16 (default 12)
551          * Note: The FPGA configuration supports a maximum of 12 host channels.
552          */
553         int32_t host_channels;
554
555         /** The number of endpoints in addition to EP0 available for device
556          * mode operations.
557          * 1 to 15 (default 6 IN and OUT)
558          * Note: The FPGA configuration supports a maximum of 6 IN and OUT
559          * endpoints in addition to EP0.
560          */
561         int32_t dev_endpoints;
562
563                 /**
564                  * Specifies the type of PHY interface to use. By default, the driver
565                  * will automatically detect the phy_type.
566                  *
567                  * 0 - Full Speed PHY
568                  * 1 - UTMI+ (default)
569                  * 2 - ULPI
570                  */
571         int32_t phy_type;
572
573         /**
574          * Specifies the UTMI+ Data Width. This parameter is
575          * applicable for a PHY_TYPE of UTMI+ or ULPI. (For a ULPI
576          * PHY_TYPE, this parameter indicates the data width between
577          * the MAC and the ULPI Wrapper.) Also, this parameter is
578          * applicable only if the OTG_HSPHY_WIDTH cC parameter was set
579          * to "8 and 16 bits", meaning that the core has been
580          * configured to work at either data path width.
581          *
582          * 8 or 16 bits (default 16)
583          */
584         int32_t phy_utmi_width;
585
586         /**
587          * Specifies whether the ULPI operates at double or single
588          * data rate. This parameter is only applicable if PHY_TYPE is
589          * ULPI.
590          *
591          * 0 - single data rate ULPI interface with 8 bit wide data
592          * bus (default)
593          * 1 - double data rate ULPI interface with 4 bit wide data
594          * bus
595          */
596         int32_t phy_ulpi_ddr;
597
598         /**
599          * Specifies whether to use the internal or external supply to
600          * drive the vbus with a ULPI phy.
601          */
602         int32_t phy_ulpi_ext_vbus;
603
604         /**
605          * Specifies whether to use the I2Cinterface for full speed PHY. This
606          * parameter is only applicable if PHY_TYPE is FS.
607          * 0 - No (default)
608          * 1 - Yes
609          */
610         int32_t i2c_enable;
611
612         int32_t ulpi_fs_ls;
613
614         int32_t ts_dline;
615
616         /**
617          * Specifies whether dedicated transmit FIFOs are
618          * enabled for non periodic IN endpoints in device mode
619          * 0 - No
620          * 1 - Yes
621          */
622         int32_t en_multiple_tx_fifo;
623
624         /** Number of 4-byte words in each of the Tx FIFOs in device
625          * mode when dynamic FIFO sizing is enabled.
626          * 4 to 768 (default 256)
627          */
628         uint32_t dev_tx_fifo_size[MAX_TX_FIFOS];
629
630         /** Thresholding enable flag-
631          * bit 0 - enable non-ISO Tx thresholding
632          * bit 1 - enable ISO Tx thresholding
633          * bit 2 - enable Rx thresholding
634          */
635         uint32_t thr_ctl;
636
637         /** Thresholding length for Tx
638          *      FIFOs in 32 bit DWORDs
639          */
640         uint32_t tx_thr_length;
641
642         /** Thresholding length for Rx
643          *      FIFOs in 32 bit DWORDs
644          */
645         uint32_t rx_thr_length;
646
647         /**
648          * Specifies whether LPM (Link Power Management) support is enabled
649          */
650         int32_t lpm_enable;
651
652         /** Per Transfer Interrupt
653          *      mode enable flag
654          * 1 - Enabled
655          * 0 - Disabled
656          */
657         int32_t pti_enable;
658
659         /** Multi Processor Interrupt
660          *      mode enable flag
661          * 1 - Enabled
662          * 0 - Disabled
663          */
664         int32_t mpi_enable;
665
666         /** IS_USB Capability
667          * 1 - Enabled
668          * 0 - Disabled
669          */
670         int32_t ic_usb_cap;
671
672         /** AHB Threshold Ratio
673          * 2'b00 AHB Threshold =        MAC Threshold
674          * 2'b01 AHB Threshold = 1/2    MAC Threshold
675          * 2'b10 AHB Threshold = 1/4    MAC Threshold
676          * 2'b11 AHB Threshold = 1/8    MAC Threshold
677          */
678         int32_t ahb_thr_ratio;
679
680         /** ADP Support
681          * 1 - Enabled
682          * 0 - Disabled
683          */
684         int32_t adp_supp_enable;
685
686         /** HFIR Reload Control
687          * 0 - The HFIR cannot be reloaded dynamically.
688          * 1 - Allow dynamic reloading of the HFIR register during runtime.
689          */
690         int32_t reload_ctl;
691
692         /** DCFG: Enable device Out NAK
693          * 0 - The core does not set NAK after Bulk Out transfer complete.
694          * 1 - The core sets NAK after Bulk OUT transfer complete.
695          */
696         int32_t dev_out_nak;
697
698         /** DCFG: Enable Continue on BNA
699          * After receiving BNA interrupt the core disables the endpoint,when the
700          * endpoint is re-enabled by the application the core starts processing
701          * 0 - from the DOEPDMA descriptor
702          * 1 - from the descriptor which received the BNA.
703          */
704         int32_t cont_on_bna;
705
706         /** GAHBCFG: AHB Single Support
707          * This bit when programmed supports SINGLE transfers for remainder
708          * data in a transfer for DMA mode of operation.
709          * 0 - in this case the remainder data will be sent using INCR burst size.
710          * 1 - in this case the remainder data will be sent using SINGLE burst size.
711          */
712         int32_t ahb_single;
713
714         /** Core Power down mode
715          * 0 - No Power Down is enabled
716          * 1 - Reserved
717          * 2 - Complete Power Down (Hibernation)
718          */
719         int32_t power_down;
720
721         /** OTG revision supported
722          * 0 - OTG 1.3 revision
723          * 1 - OTG 2.0 revision
724          */
725         int32_t otg_ver;
726
727 } dwc_otg_core_params_t;
728
729 #ifdef DEBUG
730 struct dwc_otg_core_if;
731 typedef struct hc_xfer_info {
732         struct dwc_otg_core_if *core_if;
733         dwc_hc_t *hc;
734 } hc_xfer_info_t;
735 #endif
736
737 typedef struct ep_xfer_info {
738         struct dwc_otg_core_if *core_if;
739         dwc_ep_t *ep;
740         uint8_t state;
741 } ep_xfer_info_t;
742 /*
743  * Device States
744  */
745 typedef enum dwc_otg_lx_state {
746         /** On state */
747         DWC_OTG_L0,
748         /** LPM sleep state*/
749         DWC_OTG_L1,
750         /** USB suspend state*/
751         DWC_OTG_L2,
752         /** Off state*/
753         DWC_OTG_L3
754 } dwc_otg_lx_state_e;
755
756 struct dwc_otg_global_regs_backup {
757         uint32_t gotgctl_local;
758         uint32_t gintmsk_local;
759         uint32_t gahbcfg_local;
760         uint32_t gusbcfg_local;
761         uint32_t grxfsiz_local;
762         uint32_t gnptxfsiz_local;
763 #ifdef CONFIG_USB_DWC_OTG_LPM
764         uint32_t glpmcfg_local;
765 #endif
766         uint32_t gi2cctl_local;
767         uint32_t hptxfsiz_local;
768         uint32_t pcgcctl_local;
769         uint32_t gdfifocfg_local;
770         uint32_t dtxfsiz_local[MAX_EPS_CHANNELS];
771         uint32_t gpwrdn_local;
772         uint32_t xhib_pcgcctl;
773         uint32_t xhib_gpwrdn;
774 };
775
776 struct dwc_otg_host_regs_backup {
777         uint32_t hcfg_local;
778         uint32_t haintmsk_local;
779         uint32_t hcintmsk_local[MAX_EPS_CHANNELS];
780         uint32_t hprt0_local;
781         uint32_t hfir_local;
782 };
783
784 struct dwc_otg_dev_regs_backup {
785         uint32_t dcfg;
786         uint32_t dctl;
787         uint32_t daintmsk;
788         uint32_t diepmsk;
789         uint32_t doepmsk;
790         uint32_t diepctl[MAX_EPS_CHANNELS];
791         uint32_t dieptsiz[MAX_EPS_CHANNELS];
792         uint32_t diepdma[MAX_EPS_CHANNELS];
793 };
794 /**
795  * The <code>dwc_otg_core_if</code> structure contains information needed to manage
796  * the DWC_otg controller acting in either host or device mode. It
797  * represents the programming view of the controller as a whole.
798  */
799 struct dwc_otg_core_if {
800         /** Parameters that define how the core should be configured.*/
801         dwc_otg_core_params_t *core_params;
802
803         /** Core Global registers starting at offset 000h. */
804         dwc_otg_core_global_regs_t *core_global_regs;
805
806         /** Device-specific information */
807         dwc_otg_dev_if_t *dev_if;
808         /** Host-specific information */
809         dwc_otg_host_if_t *host_if;
810
811         /** Value from SNPSID register */
812         uint32_t snpsid;
813
814         /*
815          * Set to 1 if the core PHY interface bits in USBCFG have been
816          * initialized.
817          */
818         uint8_t phy_init_done;
819
820         /*
821          * SRP Success flag, set by srp success interrupt in FS I2C mode
822          */
823         uint8_t srp_success;
824         uint8_t srp_timer_started;
825         /** Timer for SRP. If it expires before SRP is successful
826          * clear the SRP. */
827         dwc_timer_t *srp_timer;
828
829 #ifdef DWC_DEV_SRPCAP
830         /* This timer is needed to power on the hibernated host core if SRP is not
831          * initiated on connected SRP capable device for limited period of time
832          */
833         uint8_t pwron_timer_started;
834         dwc_timer_t *pwron_timer;
835 #endif
836         /* Common configuration information */
837         /** Power and Clock Gating Control Register */
838         volatile uint32_t *pcgcctl;
839 #define DWC_OTG_PCGCCTL_OFFSET 0xE00
840
841         /** Push/pop addresses for endpoints or host channels.*/
842         uint32_t *data_fifo[MAX_EPS_CHANNELS];
843 #define DWC_OTG_DATA_FIFO_OFFSET 0x1000
844 #define DWC_OTG_DATA_FIFO_SIZE 0x1000
845
846         /** Total RAM for FIFOs (Bytes) */
847         uint16_t total_fifo_size;
848         /** Size of Rx FIFO (Bytes) */
849         uint16_t rx_fifo_size;
850         /** Size of Non-periodic Tx FIFO (Bytes) */
851         uint16_t nperio_tx_fifo_size;
852
853         /** 1 if DMA is enabled, 0 otherwise. */
854         uint8_t dma_enable;
855
856         /** 1 if DMA descriptor is enabled, 0 otherwise. */
857         uint8_t dma_desc_enable;
858
859         /** 1 if PTI Enhancement mode is enabled, 0 otherwise. */
860         uint8_t pti_enh_enable;
861
862         /** 1 if MPI Enhancement mode is enabled, 0 otherwise. */
863         uint8_t multiproc_int_enable;
864
865         /** 1 if dedicated Tx FIFOs are enabled, 0 otherwise. */
866         uint8_t en_multiple_tx_fifo;
867
868         /** Set to 1 if multiple packets of a high-bandwidth transfer is in
869          * process of being queued */
870         uint8_t queuing_high_bandwidth;
871
872         /** Hardware Configuration -- stored here for convenience.*/
873         hwcfg1_data_t hwcfg1;
874         hwcfg2_data_t hwcfg2;
875         hwcfg3_data_t hwcfg3;
876         hwcfg4_data_t hwcfg4;
877         fifosize_data_t hptxfsiz;
878
879         /** Host and Device Configuration -- stored here for convenience.*/
880         hcfg_data_t hcfg;
881         dcfg_data_t dcfg;
882
883         /** The operational State, during transations
884          * (a_host>>a_peripherial and b_device=>b_host) this may not
885          * match the core but allows the software to determine
886          * transitions.
887          */
888         uint8_t op_state;
889
890         /**
891          * Set to 1 if the HCD needs to be restarted on a session request
892          * interrupt. This is required if no connector ID status change has
893          * occurred since the HCD was last disconnected.
894          */
895         uint8_t restart_hcd_on_session_req;
896
897         /** HCD callbacks */
898         /** A-Device is a_host */
899 #define A_HOST          (1)
900         /** A-Device is a_suspend */
901 #define A_SUSPEND       (2)
902         /** A-Device is a_peripherial */
903 #define A_PERIPHERAL    (3)
904         /** B-Device is operating as a Peripheral. */
905 #define B_PERIPHERAL    (4)
906         /** B-Device is operating as a Host. */
907 #define B_HOST          (5)
908
909         /** HCD callbacks */
910         struct dwc_otg_cil_callbacks *hcd_cb;
911         /** PCD callbacks */
912         struct dwc_otg_cil_callbacks *pcd_cb;
913
914         /** Device mode Periodic Tx FIFO Mask */
915         uint32_t p_tx_msk;
916         /** Device mode Periodic Tx FIFO Mask */
917         uint32_t tx_msk;
918
919         /** Workqueue object used for handling several interrupts */
920         dwc_workq_t *wq_otg;
921
922         /** Timer object used for handling "Wakeup Detected" Interrupt */
923         dwc_timer_t *wkp_timer;
924         /** This arrays used for debug purposes for DEV OUT NAK enhancement */
925         uint32_t start_doeptsiz_val[MAX_EPS_CHANNELS];
926         ep_xfer_info_t ep_xfer_info[MAX_EPS_CHANNELS];
927         dwc_timer_t *ep_xfer_timer[MAX_EPS_CHANNELS];
928 #ifdef DEBUG
929         uint32_t start_hcchar_val[MAX_EPS_CHANNELS];
930
931         hc_xfer_info_t hc_xfer_info[MAX_EPS_CHANNELS];
932         dwc_timer_t *hc_xfer_timer[MAX_EPS_CHANNELS];
933
934         uint32_t hfnum_7_samples;
935         uint64_t hfnum_7_frrem_accum;
936         uint32_t hfnum_0_samples;
937         uint64_t hfnum_0_frrem_accum;
938         uint32_t hfnum_other_samples;
939         uint64_t hfnum_other_frrem_accum;
940 #endif
941
942 #ifdef DWC_UTE_CFI
943         uint16_t pwron_rxfsiz;
944         uint16_t pwron_gnptxfsiz;
945         uint16_t pwron_txfsiz[15];
946
947         uint16_t init_rxfsiz;
948         uint16_t init_gnptxfsiz;
949         uint16_t init_txfsiz[15];
950 #endif
951
952         /** Lx state of device */
953         dwc_otg_lx_state_e lx_state;
954
955         /** Saved Core Global registers */
956         struct dwc_otg_global_regs_backup *gr_backup;
957         /** Saved Host registers */
958         struct dwc_otg_host_regs_backup *hr_backup;
959         /** Saved Device registers */
960         struct dwc_otg_dev_regs_backup *dr_backup;
961
962         /** Power Down Enable */
963         uint32_t power_down;
964
965         /** ADP support Enable */
966         uint32_t adp_enable;
967
968         /** ADP structure object */
969         dwc_otg_adp_t adp;
970
971         /** hibernation/suspend flag */
972         int hibernation_suspend;
973
974         /** Device mode extended hibernation flag */
975         int xhib;
976
977         /** OTG revision supported */
978         uint32_t otg_ver;
979
980         /** OTG status flag used for HNP polling */
981         uint8_t otg_sts;
982
983         /** Pointer to either hcd->lock or pcd->lock */
984         dwc_spinlock_t *lock;
985
986         /** Start predict NextEP based on Learning Queue if equal 1,
987          * also used as counter of disabled NP IN EP's */
988         uint8_t start_predict;
989
990         /** NextEp sequence, including EP0: nextep_seq[] = EP if non-periodic and
991          * active, 0xff otherwise */
992         uint8_t nextep_seq[MAX_EPS_CHANNELS];
993
994         /** Index of fisrt EP in nextep_seq array which should be re-enabled **/
995         uint8_t first_in_nextep_seq;
996
997         /** Frame number while entering to ISR - needed for ISOCs **/
998         uint32_t frame_num;
999
1000 };
1001
1002 /** DWC_otg request structure.
1003  * This structure is a list of requests.
1004  */
1005
1006 typedef struct dwc_otg_pcd_request {
1007         void *priv;
1008         void *buf;
1009         dwc_dma_t dma;
1010         uint32_t num_mapped_sgs;
1011         struct scatterlist *sg;
1012         uint32_t length;
1013         uint32_t actual;
1014
1015         unsigned short_packet:1;
1016         unsigned sent_zlp:1;
1017         unsigned mapped;//for DMA transfer lee
1018         /**
1019          * Used instead of original buffer if
1020          * it(physical address) is not dword-aligned.
1021          **/
1022         uint8_t *dw_align_buf;
1023         dwc_dma_t dw_align_buf_dma;
1024
1025         DWC_CIRCLEQ_ENTRY(dwc_otg_pcd_request) queue_entry;
1026 #ifdef DWC_UTE_PER_IO
1027         struct dwc_iso_xreq_port ext_req;
1028         //void *priv_ereq_nport; /*  */
1029 #endif
1030 } dwc_otg_pcd_request_t;
1031
1032 DWC_CIRCLEQ_HEAD(req_list, dwc_otg_pcd_request);
1033
1034
1035 #ifdef DEBUG
1036 /*
1037  * This function is called when transfer is timed out.
1038  */
1039 extern void hc_xfer_timeout(void *ptr);
1040 #endif
1041
1042 /*
1043  * This function is called when transfer is timed out on endpoint.
1044  */
1045 extern void ep_xfer_timeout(void *ptr);
1046
1047 /*
1048  * The following functions are functions for works
1049  * using during handling some interrupts
1050  */
1051 extern void w_conn_id_status_change(void *p);
1052
1053 extern void w_wakeup_detected(void *p);
1054
1055 /** Saves global register values into system memory. */
1056 extern int dwc_otg_save_global_regs(dwc_otg_core_if_t * core_if);
1057 /** Saves device register values into system memory. */
1058 extern int dwc_otg_save_dev_regs(dwc_otg_core_if_t * core_if);
1059 /** Saves host register values into system memory. */
1060 extern int dwc_otg_save_host_regs(dwc_otg_core_if_t * core_if);
1061 /** Restore global register values. */
1062 extern int dwc_otg_restore_global_regs(dwc_otg_core_if_t * core_if);
1063 /** Restore host register values. */
1064 extern int dwc_otg_restore_host_regs(dwc_otg_core_if_t * core_if, int reset);
1065 /** Restore device register values. */
1066 extern int dwc_otg_restore_dev_regs(dwc_otg_core_if_t * core_if,
1067                                     int rem_wakeup);
1068 extern int restore_lpm_i2c_regs(dwc_otg_core_if_t * core_if);
1069 extern int restore_essential_regs(dwc_otg_core_if_t * core_if, int rmode,
1070                                   int is_host);
1071
1072 extern int dwc_otg_host_hibernation_restore(dwc_otg_core_if_t * core_if,
1073                                             int restore_mode, int reset);
1074 extern int dwc_otg_device_hibernation_restore(dwc_otg_core_if_t * core_if,
1075                                               int rem_wakeup, int reset);
1076
1077 /*
1078  * The following functions support initialization of the CIL driver component
1079  * and the DWC_otg controller.
1080  */
1081 extern void dwc_otg_core_host_init(dwc_otg_core_if_t * _core_if);
1082 extern void dwc_otg_core_dev_init(dwc_otg_core_if_t * _core_if);
1083
1084 /** @name Device CIL Functions
1085  * The following functions support managing the DWC_otg controller in device
1086  * mode.
1087  */
1088 /**@{*/
1089 extern void dwc_otg_wakeup(dwc_otg_core_if_t * _core_if);
1090 extern void dwc_otg_read_setup_packet(dwc_otg_core_if_t * _core_if,
1091                                       uint32_t * _dest);
1092 extern uint32_t dwc_otg_get_frame_number(dwc_otg_core_if_t * _core_if);
1093 extern void dwc_otg_ep0_activate(dwc_otg_core_if_t * _core_if, dwc_ep_t * _ep);
1094 extern void dwc_otg_ep_activate(dwc_otg_core_if_t * _core_if, dwc_ep_t * _ep);
1095 extern void dwc_otg_ep_deactivate(dwc_otg_core_if_t * _core_if, dwc_ep_t * _ep);
1096 extern void dwc_otg_ep_start_transfer(dwc_otg_core_if_t * core_if, dwc_ep_t * ep,
1097                                  dwc_otg_pcd_request_t *req);
1098 extern void dwc_otg_ep_start_zl_transfer(dwc_otg_core_if_t * _core_if,
1099                                  dwc_ep_t * _ep);
1100 extern void dwc_otg_ep0_start_transfer(dwc_otg_core_if_t * _core_if,
1101                                  dwc_ep_t * _ep);
1102 extern void dwc_otg_ep0_continue_transfer(dwc_otg_core_if_t * _core_if,
1103                                  dwc_ep_t * _ep);
1104 extern void dwc_otg_ep_write_packet(dwc_otg_core_if_t * _core_if,
1105                                  dwc_ep_t * _ep, int _dma);
1106 extern void dwc_otg_ep_set_stall(dwc_otg_core_if_t * _core_if, dwc_ep_t * _ep);
1107 extern void dwc_otg_ep_clear_stall(dwc_otg_core_if_t * _core_if,
1108                                  dwc_ep_t * _ep);
1109 extern void dwc_otg_enable_device_interrupts(dwc_otg_core_if_t * _core_if);
1110
1111 #ifdef DWC_EN_ISOC
1112 extern void dwc_otg_iso_ep_start_frm_transfer(dwc_otg_core_if_t * core_if,
1113                                       dwc_ep_t * ep);
1114 extern void dwc_otg_iso_ep_start_buf_transfer(dwc_otg_core_if_t * core_if,
1115                                       dwc_ep_t * ep);
1116 #endif /* DWC_EN_ISOC */
1117 /**@}*/
1118
1119 /** @name Host CIL Functions
1120  * The following functions support managing the DWC_otg controller in host
1121  * mode.
1122  */
1123 /**@{*/
1124 extern void dwc_otg_hc_init(dwc_otg_core_if_t * _core_if, dwc_hc_t * _hc);
1125 extern void dwc_otg_hc_halt(dwc_otg_core_if_t * _core_if,
1126                             dwc_hc_t * _hc, dwc_otg_halt_status_e _halt_status);
1127 extern void dwc_otg_hc_cleanup(dwc_otg_core_if_t * _core_if, dwc_hc_t * _hc);
1128 extern void dwc_otg_hc_start_transfer(dwc_otg_core_if_t * _core_if,
1129                                       dwc_hc_t * _hc);
1130 extern int dwc_otg_hc_continue_transfer(dwc_otg_core_if_t * _core_if,
1131                                         dwc_hc_t * _hc);
1132 extern void dwc_otg_hc_do_ping(dwc_otg_core_if_t * _core_if, dwc_hc_t * _hc);
1133 extern void dwc_otg_hc_write_packet(dwc_otg_core_if_t * _core_if,
1134                                     dwc_hc_t * _hc);
1135 extern void dwc_otg_enable_host_interrupts(dwc_otg_core_if_t * _core_if);
1136 extern void dwc_otg_disable_host_interrupts(dwc_otg_core_if_t * _core_if);
1137
1138 extern void dwc_otg_hc_start_transfer_ddma(dwc_otg_core_if_t * core_if,
1139                                            dwc_hc_t * hc);
1140
1141 extern uint32_t calc_frame_interval(dwc_otg_core_if_t * core_if);
1142
1143 /* Macro used to clear one channel interrupt */
1144 #define clear_hc_int(_hc_regs_, _intr_) \
1145 do { \
1146         hcint_data_t hcint_clear = {.d32 = 0}; \
1147         hcint_clear.b._intr_ = 1; \
1148         DWC_WRITE_REG32(&(_hc_regs_)->hcint, hcint_clear.d32); \
1149 } while (0)
1150
1151 /*
1152  * Macro used to disable one channel interrupt. Channel interrupts are
1153  * disabled when the channel is halted or released by the interrupt handler.
1154  * There is no need to handle further interrupts of that type until the
1155  * channel is re-assigned. In fact, subsequent handling may cause crashes
1156  * because the channel structures are cleaned up when the channel is released.
1157  */
1158 #define disable_hc_int(_hc_regs_, _intr_) \
1159 do { \
1160         hcintmsk_data_t hcintmsk = {.d32 = 0}; \
1161         hcintmsk.b._intr_ = 1; \
1162         DWC_MODIFY_REG32(&(_hc_regs_)->hcintmsk, hcintmsk.d32, 0); \
1163 } while (0)
1164
1165 /**
1166  * This function Reads HPRT0 in preparation to modify. It keeps the
1167  * WC bits 0 so that if they are read as 1, they won't clear when you
1168  * write it back
1169  */
1170 static inline uint32_t dwc_otg_read_hprt0(dwc_otg_core_if_t * _core_if)
1171 {
1172         hprt0_data_t hprt0;
1173         hprt0.d32 = DWC_READ_REG32(_core_if->host_if->hprt0);
1174         hprt0.b.prtena = 0;
1175         hprt0.b.prtconndet = 0;
1176         hprt0.b.prtenchng = 0;
1177         hprt0.b.prtovrcurrchng = 0;
1178         return hprt0.d32;
1179 }
1180
1181 /**@}*/
1182
1183 /** @name Common CIL Functions
1184  * The following functions support managing the DWC_otg controller in either
1185  * device or host mode.
1186  */
1187 /**@{*/
1188
1189 extern void dwc_otg_read_packet(dwc_otg_core_if_t * core_if,
1190                                 uint8_t * dest, uint16_t bytes);
1191
1192 extern void dwc_otg_flush_tx_fifo(dwc_otg_core_if_t * _core_if, const int _num);
1193 extern void dwc_otg_flush_rx_fifo(dwc_otg_core_if_t * _core_if);
1194 extern void dwc_otg_core_reset(dwc_otg_core_if_t * _core_if);
1195
1196 /**
1197  * This function returns the Core Interrupt register.
1198  */
1199 static inline uint32_t dwc_otg_read_core_intr(dwc_otg_core_if_t * core_if)
1200 {
1201         return (DWC_READ_REG32(&core_if->core_global_regs->gintsts) &
1202                 DWC_READ_REG32(&core_if->core_global_regs->gintmsk));
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         return (DWC_READ_REG32(&core_if->core_global_regs->gotgint));
1211 }
1212
1213 /**
1214  * This function reads the Device All Endpoints Interrupt register and
1215  * returns the IN endpoint interrupt bits.
1216  */
1217 static inline uint32_t dwc_otg_read_dev_all_in_ep_intr(dwc_otg_core_if_t *
1218                                                        core_if)
1219 {
1220
1221         uint32_t v;
1222
1223         if (core_if->multiproc_int_enable) {
1224                 v = DWC_READ_REG32(&core_if->dev_if->
1225                                    dev_global_regs->deachint) &
1226                     DWC_READ_REG32(&core_if->
1227                                    dev_if->dev_global_regs->deachintmsk);
1228         } else {
1229                 v = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->daint) &
1230                     DWC_READ_REG32(&core_if->dev_if->dev_global_regs->daintmsk);
1231         }
1232         return (v & 0xffff);
1233 }
1234
1235 /**
1236  * This function reads the Device All Endpoints Interrupt register and
1237  * returns the OUT endpoint interrupt bits.
1238  */
1239 static inline uint32_t dwc_otg_read_dev_all_out_ep_intr(dwc_otg_core_if_t *
1240                                                         core_if)
1241 {
1242         uint32_t v;
1243
1244         if (core_if->multiproc_int_enable) {
1245                 v = DWC_READ_REG32(&core_if->dev_if->
1246                                    dev_global_regs->deachint) &
1247                     DWC_READ_REG32(&core_if->
1248                                    dev_if->dev_global_regs->deachintmsk);
1249         } else {
1250                 v = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->daint) &
1251                     DWC_READ_REG32(&core_if->dev_if->dev_global_regs->daintmsk);
1252         }
1253
1254         return ((v & 0xffff0000) >> 16);
1255 }
1256
1257 /**
1258  * This function returns the Device IN EP Interrupt register
1259  */
1260 static inline uint32_t dwc_otg_read_dev_in_ep_intr(dwc_otg_core_if_t * core_if,
1261                                                    dwc_ep_t * ep)
1262 {
1263         dwc_otg_dev_if_t *dev_if = core_if->dev_if;
1264         uint32_t v, msk, emp;
1265
1266         if (core_if->multiproc_int_enable) {
1267                 msk =
1268                     DWC_READ_REG32(&dev_if->
1269                                    dev_global_regs->diepeachintmsk[ep->num]);
1270                 emp =
1271                     DWC_READ_REG32(&dev_if->
1272                                    dev_global_regs->dtknqr4_fifoemptymsk);
1273                 msk |= ((emp >> ep->num) & 0x1) << 7;
1274                 v = DWC_READ_REG32(&dev_if->in_ep_regs[ep->num]->diepint) & msk;
1275         } else {
1276                 msk = DWC_READ_REG32(&dev_if->dev_global_regs->diepmsk);
1277                 emp =
1278                     DWC_READ_REG32(&dev_if->
1279                                    dev_global_regs->dtknqr4_fifoemptymsk);
1280                 msk |= ((emp >> ep->num) & 0x1) << 7;
1281                 v = DWC_READ_REG32(&dev_if->in_ep_regs[ep->num]->diepint) & msk;
1282         }
1283
1284         return v;
1285 }
1286
1287 /**
1288  * This function returns the Device OUT EP Interrupt register
1289  */
1290 static inline uint32_t dwc_otg_read_dev_out_ep_intr(dwc_otg_core_if_t *
1291                                                     _core_if, dwc_ep_t * _ep)
1292 {
1293         dwc_otg_dev_if_t *dev_if = _core_if->dev_if;
1294         uint32_t v;
1295         doepmsk_data_t msk = {.d32 = 0 };
1296
1297         if (_core_if->multiproc_int_enable) {
1298                 msk.d32 =
1299                     DWC_READ_REG32(&dev_if->
1300                                    dev_global_regs->doepeachintmsk[_ep->num]);
1301                 if (_core_if->pti_enh_enable) {
1302                         msk.b.pktdrpsts = 1;
1303                 }
1304                 v = DWC_READ_REG32(&dev_if->
1305                                    out_ep_regs[_ep->num]->doepint) & msk.d32;
1306         } else {
1307                 msk.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->doepmsk);
1308                 if (_core_if->pti_enh_enable) {
1309                         msk.b.pktdrpsts = 1;
1310                 }
1311                 v = DWC_READ_REG32(&dev_if->
1312                                    out_ep_regs[_ep->num]->doepint) & msk.d32;
1313         }
1314         return v;
1315 }
1316
1317 /**
1318  * This function returns the Host All Channel Interrupt register
1319  */
1320 static inline uint32_t dwc_otg_read_host_all_channels_intr(dwc_otg_core_if_t *
1321                                                            _core_if)
1322 {
1323         return (DWC_READ_REG32(&_core_if->host_if->host_global_regs->haint));
1324 }
1325
1326 static inline uint32_t dwc_otg_read_host_channel_intr(dwc_otg_core_if_t *
1327                                                       _core_if, dwc_hc_t * _hc)
1328 {
1329         return (DWC_READ_REG32
1330                 (&_core_if->host_if->hc_regs[_hc->hc_num]->hcint));
1331 }
1332
1333 /**
1334  * This function returns the mode of the operation, host or device.
1335  *
1336  * @return 0 - Device Mode, 1 - Host Mode
1337  */
1338 static inline uint32_t dwc_otg_mode(dwc_otg_core_if_t * _core_if)
1339 {
1340         return (DWC_READ_REG32(&_core_if->core_global_regs->gintsts) & 0x1);
1341 }
1342
1343 /**@}*/
1344
1345 /**
1346  * DWC_otg CIL callback structure. This structure allows the HCD and
1347  * PCD to register functions used for starting and stopping the PCD
1348  * and HCD for role change on for a DRD.
1349  */
1350 typedef struct dwc_otg_cil_callbacks {
1351         /** Start function for role change */
1352         int (*start) (void *_p);
1353         /** Stop Function for role change */
1354         int (*stop) (void *_p);
1355         /** Disconnect Function for role change */
1356         int (*disconnect) (void *_p);
1357         /** Resume/Remote wakeup Function */
1358         int (*resume_wakeup) (void *_p);
1359         /** Suspend function */
1360         int (*suspend) (void *_p);
1361         /** Session Start (SRP) */
1362         int (*session_start) (void *_p);
1363 #ifdef CONFIG_USB_DWC_OTG_LPM
1364         /** Sleep (switch to L0 state) */
1365         int (*sleep) (void *_p);
1366 #endif
1367         /** Pointer passed to start() and stop() */
1368         void *p;
1369 } dwc_otg_cil_callbacks_t;
1370
1371 extern void dwc_otg_cil_register_pcd_callbacks(dwc_otg_core_if_t * _core_if,
1372                                                dwc_otg_cil_callbacks_t * _cb,
1373                                                void *_p);
1374 extern void dwc_otg_cil_register_hcd_callbacks(dwc_otg_core_if_t * _core_if,
1375                                                dwc_otg_cil_callbacks_t * _cb,
1376                                                void *_p);
1377
1378 void dwc_otg_initiate_srp(dwc_otg_core_if_t * core_if);
1379
1380 //////////////////////////////////////////////////////////////////////
1381 /** Start the HCD.  Helper function for using the HCD callbacks.
1382  *
1383  * @param core_if Programming view of DWC_otg controller.
1384  */
1385 static inline void cil_hcd_start(dwc_otg_core_if_t * core_if)
1386 {
1387         if (core_if->hcd_cb && core_if->hcd_cb->start) {
1388                 core_if->hcd_cb->start(core_if->hcd_cb->p);
1389         }
1390 }
1391
1392 /** Stop the HCD.  Helper function for using the HCD callbacks.
1393  *
1394  * @param core_if Programming view of DWC_otg controller.
1395  */
1396 static inline void cil_hcd_stop(dwc_otg_core_if_t * core_if)
1397 {
1398         if (core_if->hcd_cb && core_if->hcd_cb->stop) {
1399                 core_if->hcd_cb->stop(core_if->hcd_cb->p);
1400         }
1401 }
1402
1403 /** Disconnect the HCD.  Helper function for using the HCD callbacks.
1404  *
1405  * @param core_if Programming view of DWC_otg controller.
1406  */
1407 static inline void cil_hcd_disconnect(dwc_otg_core_if_t * core_if)
1408 {
1409         if (core_if->hcd_cb && core_if->hcd_cb->disconnect) {
1410                 core_if->hcd_cb->disconnect(core_if->hcd_cb->p);
1411         }
1412 }
1413
1414 /** Inform the HCD the a New Session has begun.  Helper function for
1415  * using the HCD callbacks.
1416  *
1417  * @param core_if Programming view of DWC_otg controller.
1418  */
1419 static inline void cil_hcd_session_start(dwc_otg_core_if_t * core_if)
1420 {
1421         if (core_if->hcd_cb && core_if->hcd_cb->session_start) {
1422                 core_if->hcd_cb->session_start(core_if->hcd_cb->p);
1423         }
1424 }
1425
1426 #ifdef CONFIG_USB_DWC_OTG_LPM
1427 /**
1428  * Inform the HCD about LPM sleep.
1429  * Helper function for using the HCD callbacks.
1430  *
1431  * @param core_if Programming view of DWC_otg controller.
1432  */
1433 static inline void cil_hcd_sleep(dwc_otg_core_if_t * core_if)
1434 {
1435         if (core_if->hcd_cb && core_if->hcd_cb->sleep) {
1436                 core_if->hcd_cb->sleep(core_if->hcd_cb->p);
1437         }
1438 }
1439 #endif
1440
1441 /** Resume the HCD.  Helper function for using the HCD callbacks.
1442  *
1443  * @param core_if Programming view of DWC_otg controller.
1444  */
1445 static inline void cil_hcd_resume(dwc_otg_core_if_t * core_if)
1446 {
1447         if (core_if->hcd_cb && core_if->hcd_cb->resume_wakeup) {
1448                 core_if->hcd_cb->resume_wakeup(core_if->hcd_cb->p);
1449         }
1450 }
1451
1452 /** Start the PCD.  Helper function for using the PCD callbacks.
1453  *
1454  * @param core_if Programming view of DWC_otg controller.
1455  */
1456 static inline void cil_pcd_start(dwc_otg_core_if_t * core_if)
1457 {
1458         if (core_if->pcd_cb && core_if->pcd_cb->start) {
1459                 core_if->pcd_cb->start(core_if->pcd_cb->p);
1460         }
1461 }
1462
1463 /** Stop the PCD.  Helper function for using the PCD callbacks.
1464  *
1465  * @param core_if Programming view of DWC_otg controller.
1466  */
1467 static inline void cil_pcd_stop(dwc_otg_core_if_t * core_if)
1468 {
1469         if (core_if->pcd_cb && core_if->pcd_cb->stop) {
1470                 core_if->pcd_cb->stop(core_if->pcd_cb->p);
1471         }
1472 }
1473
1474 /** Suspend the PCD.  Helper function for using the PCD callbacks.
1475  *
1476  * @param core_if Programming view of DWC_otg controller.
1477  */
1478 static inline void cil_pcd_suspend(dwc_otg_core_if_t * core_if)
1479 {
1480         if (core_if->pcd_cb && core_if->pcd_cb->suspend) {
1481                 core_if->pcd_cb->suspend(core_if->pcd_cb->p);
1482         }
1483 }
1484
1485 /** Resume the PCD.  Helper function for using the PCD callbacks.
1486  *
1487  * @param core_if Programming view of DWC_otg controller.
1488  */
1489 static inline void cil_pcd_resume(dwc_otg_core_if_t * core_if)
1490 {
1491         if (core_if->pcd_cb && core_if->pcd_cb->resume_wakeup) {
1492                 core_if->pcd_cb->resume_wakeup(core_if->pcd_cb->p);
1493         }
1494 }
1495
1496 //////////////////////////////////////////////////////////////////////
1497
1498 #endif