1 /* ==========================================================================
2 * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_cil.h $
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.
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.
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
32 * ========================================================================== */
34 #if !defined(__DWC_CIL_H__)
39 #include "dwc_otg_dbg.h"
40 #include "dwc_otg_regs.h"
42 #include "dwc_otg_core_if.h"
46 * This file contains the interface to the Core Interface Layer.
51 #define MAX_DMA_DESCS_PER_EP 256
54 * Enumeration for the data buffer mode
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 */
65 /** Macros defined for DWC OTG HW Release verison */
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
75 * Information for each ISOC packet.
77 typedef struct iso_pkt_info {
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.
88 typedef struct dwc_ep {
89 /** EP number used for register address lookup */
91 /** EP direction 0 = OUT */
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 */
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
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;
113 /** Max Transfer size */
116 /** @name Transfer state */
120 * Pointer to the beginning of the transfer buffer -- do not modify
126 dwc_dma_t dma_desc_addr;
127 dwc_otg_dma_desc_t *desc_addr;
129 uint8_t *start_xfer_buff;
130 /** pointer to the transfer buffer */
132 /** Number of bytes to transfer */
133 unsigned xfer_len:19;
134 /** Number of bytes transferred. */
135 unsigned xfer_count:19;
138 /** Total len for control transfer */
139 unsigned total_len:19;
141 /** stall clear flag */
142 unsigned stall_clear_flag:1;
145 /* The buffer mode */
146 data_buffer_mode_e buff_mode;
148 /* The chain of DMA descriptors.
149 * MAX_DMA_DESCS_PER_EP will be allocated for each active EP.
151 dwc_otg_dma_desc_t *descs;
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;
159 /** Allocated DMA Desc count */
164 * Variables specific for ISOC EPs
167 /** DMA addresses of ISOC buffers */
171 dwc_dma_t iso_dma_desc_addr;
172 dwc_otg_dma_desc_t *iso_desc_addr;
174 /** pointer to the transfer buffers */
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;
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 */
193 /** ISO Packet number per frame */
194 uint32_t pkt_per_frm;
195 /** Next frame num for which will be setup DMA Desc */
197 /** Number of packets per buffer processing */
199 /** Info for all isoc packets */
200 iso_pkt_info_t *pkt_info;
201 /** current pkt number */
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 */
213 * Reasons for halting a host channel.
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,
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;
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.
237 typedef struct dwc_hc {
238 /** Host channel number used for register address lookup */
241 /** Device to access */
247 /** EP direction. 0: OUT, 1: IN */
252 * One of the following values:
253 * - DWC_OTG_EP_SPEED_LOW
254 * - DWC_OTG_EP_SPEED_FULL
255 * - DWC_OTG_EP_SPEED_HIGH
258 #define DWC_OTG_EP_SPEED_LOW 0
259 #define DWC_OTG_EP_SPEED_FULL 1
260 #define DWC_OTG_EP_SPEED_HIGH 2
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
272 /** Max packet size in bytes */
273 unsigned max_packet:11;
276 * PID for initial transaction.
280 * 3: MDATA (non-Control EP),
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
290 /** Number of periodic transactions per (micro)frame */
291 unsigned multi_count:2;
293 /** @name Transfer State */
296 /** Pointer to the current transfer buffer position. */
298 /** Total number of bytes to transfer. */
300 /** Number of bytes transferred so far. */
302 /** Packet count at start of transfer.*/
303 uint16_t start_pkt_count;
306 * Flag to indicate whether the transfer has been started. Set to 1 if
307 * it has been started, 0 otherwise.
309 uint8_t xfer_started;
312 * Set to 1 to indicate that a PING request should be issued on this
313 * channel. If 0, process normally.
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.
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.
329 uint8_t halt_on_queue;
332 * Set to 1 if the host channel has been halted, but the core is not
333 * finished flushing queued requests. Otherwise 0.
335 uint8_t halt_pending;
338 * Reason for halting the host channel.
340 dwc_otg_halt_status_e halt_status;
343 * Split settings for the host channel
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 */
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 */
358 /** Set when the host channel does a short read. */
362 * Number of requests issued for this channel since it was assigned to
363 * the current transfer (not counting PINGs).
368 * Queue Head for the transfer being processed by this channel.
370 struct dwc_otg_qh *qh;
374 /** Entry in list of host channels. */
375 DWC_CIRCLEQ_ENTRY(dwc_hc) hc_list_entry;
379 * The following parameters may be specified when starting the module. These
380 * parameters define how the DWC_otg controller should be configured.
382 typedef struct dwc_otg_core_params {
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
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.
399 * 1 - DMA (default, if available)
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.
408 * 1 - DMA Descriptor(default, if available)
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)
414 int32_t dma_burst_size; /* Translate this to GAHBCFG values */
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
421 * 0 - High Speed (default)
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
430 int32_t host_support_fs_ls_low_power;
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.
440 int32_t host_ls_low_power_phy_clk;
443 * 0 - Use cC FIFO size parameters
444 * 1 - Allow dynamic FIFO sizing (default)
446 int32_t enable_dynamic_fifo;
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
451 * 32 to 32768 (default 8192)
452 * Note: The total FIFO memory depth in the FPGA configuration is 8192.
454 int32_t data_fifo_size;
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)
460 int32_t dev_rx_fifo_size;
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)
466 int32_t dev_nperio_tx_fifo_size;
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)
472 uint32_t dev_perio_tx_fifo_size[MAX_PERIO_FIFOS];
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)
478 int32_t host_rx_fifo_size;
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)
484 int32_t host_nperio_tx_fifo_size;
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)
490 int32_t host_perio_tx_fifo_size;
492 /** The maximum transfer size supported in bytes.
493 * 2047 to 65,535 (default 65,535)
495 int32_t max_transfer_size;
497 /** The maximum number of packets in a transfer.
498 * 15 to 511 (default 511)
500 int32_t max_packet_count;
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.
506 int32_t host_channels;
508 /** The number of endpoints in addition to EP0 available for device
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.
514 int32_t dev_endpoints;
517 * Specifies the type of PHY interface to use. By default, the driver
518 * will automatically detect the phy_type.
521 * 1 - UTMI+ (default)
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.
535 * 8 or 16 bits (default 16)
537 int32_t phy_utmi_width;
540 * Specifies whether the ULPI operates at double or single
541 * data rate. This parameter is only applicable if PHY_TYPE is
544 * 0 - single data rate ULPI interface with 8 bit wide data
546 * 1 - double data rate ULPI interface with 4 bit wide data
549 int32_t phy_ulpi_ddr;
552 * Specifies whether to use the internal or external supply to
553 * drive the vbus with a ULPI phy.
555 int32_t phy_ulpi_ext_vbus;
558 * Specifies whether to use the I2Cinterface for full speed PHY. This
559 * parameter is only applicable if PHY_TYPE is FS.
570 * Specifies whether dedicated transmit FIFOs are
571 * enabled for non periodic IN endpoints in device mode
575 int32_t en_multiple_tx_fifo;
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)
581 uint32_t dev_tx_fifo_size[MAX_TX_FIFOS];
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
590 /** Thresholding length for Tx
591 * FIFOs in 32 bit DWORDs
593 uint32_t tx_thr_length;
595 /** Thresholding length for Rx
596 * FIFOs in 32 bit DWORDs
598 uint32_t rx_thr_length;
601 * Specifies whether LPM (Link Power Management) support is enabled
605 /** Per Transfer Interrupt
612 /** Multi Processor Interrupt
619 /** IS_USB Capability
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
631 int32_t ahb_thr_ratio;
633 } dwc_otg_core_params_t;
636 struct dwc_otg_core_if;
637 typedef struct hc_xfer_info {
638 struct dwc_otg_core_if *core_if;
645 typedef enum dwc_otg_lx_state {
648 /** LPM sleep state*/
650 /** USB suspend state*/
654 } dwc_otg_lx_state_e;
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.
661 struct dwc_otg_core_if {
662 /** Parameters that define how the core should be configured.*/
663 dwc_otg_core_params_t *core_params;
665 /** Core Global registers starting at offset 000h. */
666 dwc_otg_core_global_regs_t *core_global_regs;
668 /** Device-specific information */
669 dwc_otg_dev_if_t *dev_if;
670 /** Host-specific information */
671 dwc_otg_host_if_t *host_if;
673 /** Value from SNPSID register */
677 * Set to 1 if the core PHY interface bits in USBCFG have been
680 uint8_t phy_init_done;
683 * SRP Success flag, set by srp success interrupt in FS I2C mode
686 uint8_t srp_timer_started;
688 /* Common configuration information */
689 /** Power and Clock Gating Control Register */
690 volatile uint32_t *pcgcctl;
691 #define DWC_OTG_PCGCCTL_OFFSET 0xE00
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
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;
705 /** 1 if DMA is enabled, 0 otherwise. */
708 /** 1 if DMA descriptor is enabled, 0 otherwise. */
709 uint8_t dma_desc_enable;
711 /** 1 if PTI Enhancement mode is enabled, 0 otherwise. */
712 uint8_t pti_enh_enable;
714 /** 1 if MPI Enhancement mode is enabled, 0 otherwise. */
715 uint8_t multiproc_int_enable;
717 /** 1 if dedicated Tx FIFOs are enabled, 0 otherwise. */
718 uint8_t en_multiple_tx_fifo;
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;
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;
730 /** Host and Device Configuration -- stored here for convenience.*/
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
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.
746 uint8_t restart_hcd_on_session_req;
749 /** A-Device is a_host */
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. */
761 struct dwc_otg_cil_callbacks *hcd_cb;
763 struct dwc_otg_cil_callbacks *pcd_cb;
765 /** Device mode Periodic Tx FIFO Mask */
767 /** Device mode Periodic Tx FIFO Mask */
770 /** Workqueue object used for handling several interrupts */
773 /** Timer object used for handling "Wakeup Detected" Interrupt */
774 dwc_timer_t *wkp_timer;
777 uint32_t start_hcchar_val[MAX_EPS_CHANNELS];
779 hc_xfer_info_t hc_xfer_info[MAX_EPS_CHANNELS];
780 dwc_timer_t *hc_xfer_timer[MAX_EPS_CHANNELS];
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;
791 uint16_t pwron_rxfsiz;
792 uint16_t pwron_gnptxfsiz;
793 uint16_t pwron_txfsiz[15];
795 uint16_t init_rxfsiz;
796 uint16_t init_gnptxfsiz;
797 uint16_t init_txfsiz[15];
800 /** Lx state of device */
801 dwc_otg_lx_state_e lx_state;
807 * This function is called when transfer is timed out.
809 extern void hc_xfer_timeout(void *ptr);
813 * The following functions are functions for works
814 * using during handling some interrupts
816 extern void w_conn_id_status_change(void *p);
818 extern void w_wakeup_detected(void *p);
821 * The following functions support initialization of the CIL driver component
822 * and the DWC_otg controller.
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);
827 /** @name Device CIL Functions
828 * The following functions support managing the DWC_otg controller in device
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,
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,
841 extern void dwc_otg_ep_start_zl_transfer(dwc_otg_core_if_t * _core_if,
843 extern void dwc_otg_ep0_start_transfer(dwc_otg_core_if_t * _core_if,
845 extern void dwc_otg_ep0_continue_transfer(dwc_otg_core_if_t * _core_if,
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,
852 extern void dwc_otg_enable_device_interrupts(dwc_otg_core_if_t * _core_if);
855 extern void dwc_otg_iso_ep_start_frm_transfer(dwc_otg_core_if_t * core_if,
857 extern void dwc_otg_iso_ep_start_buf_transfer(dwc_otg_core_if_t * core_if,
859 #endif /* DWC_EN_ISOC */
862 /** @name Host CIL Functions
863 * The following functions support managing the DWC_otg controller in host
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,
873 extern int dwc_otg_hc_continue_transfer(dwc_otg_core_if_t * _core_if,
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,
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);
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
886 static inline uint32_t dwc_otg_read_hprt0(dwc_otg_core_if_t * _core_if)
889 hprt0.d32 = dwc_read_reg32(_core_if->host_if->hprt0);
891 hprt0.b.prtconndet = 0;
892 hprt0.b.prtenchng = 0;
893 hprt0.b.prtovrcurrchng = 0;
899 /** @name Common CIL Functions
900 * The following functions support managing the DWC_otg controller in either
901 * device or host mode.
905 extern void dwc_otg_read_packet(dwc_otg_core_if_t * core_if,
906 uint8_t * dest, uint16_t bytes);
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);
913 * This function returns the Core Interrupt register.
915 static inline uint32_t dwc_otg_read_core_intr(dwc_otg_core_if_t * core_if)
917 return (dwc_read_reg32(&core_if->core_global_regs->gintsts) &
918 dwc_read_reg32(&core_if->core_global_regs->gintmsk));
922 * This function returns the OTG Interrupt register.
924 static inline uint32_t dwc_otg_read_otg_intr(dwc_otg_core_if_t * core_if)
926 return (dwc_read_reg32(&core_if->core_global_regs->gotgint));
930 * This function reads the Device All Endpoints Interrupt register and
931 * returns the IN endpoint interrupt bits.
933 static inline uint32_t dwc_otg_read_dev_all_in_ep_intr(dwc_otg_core_if_t *
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->
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);
952 * This function reads the Device All Endpoints Interrupt register and
953 * returns the OUT endpoint interrupt bits.
955 static inline uint32_t dwc_otg_read_dev_all_out_ep_intr(dwc_otg_core_if_t *
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->
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);
970 return ((v & 0xffff0000) >> 16);
974 * This function returns the Device IN EP Interrupt register
976 static inline uint32_t dwc_otg_read_dev_in_ep_intr(dwc_otg_core_if_t * core_if,
979 dwc_otg_dev_if_t *dev_if = core_if->dev_if;
980 uint32_t v, msk, emp;
982 if (core_if->multiproc_int_enable) {
984 dwc_read_reg32(&dev_if->dev_global_regs->
985 diepeachintmsk[ep->num]);
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;
992 msk = dwc_read_reg32(&dev_if->dev_global_regs->diepmsk);
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;
1004 * This function returns the Device OUT EP Interrupt register
1006 static inline uint32_t dwc_otg_read_dev_out_ep_intr(dwc_otg_core_if_t *
1007 _core_if, dwc_ep_t * _ep)
1009 dwc_otg_dev_if_t *dev_if = _core_if->dev_if;
1011 doepmsk_data_t msk = {.d32 = 0 };
1013 if (_core_if->multiproc_int_enable) {
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;
1020 v = dwc_read_reg32(&dev_if->out_ep_regs[_ep->num]->
1023 msk.d32 = dwc_read_reg32(&dev_if->dev_global_regs->doepmsk);
1024 if (_core_if->pti_enh_enable) {
1025 msk.b.pktdrpsts = 1;
1027 v = dwc_read_reg32(&dev_if->out_ep_regs[_ep->num]->
1034 * This function returns the Host All Channel Interrupt register
1036 static inline uint32_t dwc_otg_read_host_all_channels_intr(dwc_otg_core_if_t *
1039 return (dwc_read_reg32(&_core_if->host_if->host_global_regs->haint));
1042 static inline uint32_t dwc_otg_read_host_channel_intr(dwc_otg_core_if_t *
1043 _core_if, dwc_hc_t * _hc)
1045 return (dwc_read_reg32
1046 (&_core_if->host_if->hc_regs[_hc->hc_num]->hcint));
1050 * This function returns the mode of the operation, host or device.
1052 * @return 0 - Device Mode, 1 - Host Mode
1054 static inline uint32_t dwc_otg_mode(dwc_otg_core_if_t * _core_if)
1056 return (dwc_read_reg32(&_core_if->core_global_regs->gintsts) & 0x1);
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.
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);
1083 /** Pointer passed to start() and stop() */
1085 } dwc_otg_cil_callbacks_t;
1087 extern void dwc_otg_cil_register_pcd_callbacks(dwc_otg_core_if_t * _core_if,
1088 dwc_otg_cil_callbacks_t * _cb,
1090 extern void dwc_otg_cil_register_hcd_callbacks(dwc_otg_core_if_t * _core_if,
1091 dwc_otg_cil_callbacks_t * _cb,