1 /* ==========================================================================
2 * $File: //dwh/usb_iip/dev/software/otg_ipmate/linux/drivers/dwc_otg_cil.h $
4 * $Date: 2009-04-17 06:15:34 $
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__)
37 #include "dwc_otg_plat.h"
39 #include "dwc_otg_regs.h"
41 #include "linux/timer.h"
44 /* the OTG capabilities. */
45 #define DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE 0
46 #define DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE 1
47 #define DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE 2
48 /* the maximum speed of operation in host and device mode. */
49 #define DWC_SPEED_PARAM_HIGH 0
50 #define DWC_SPEED_PARAM_FULL 1
51 /* the PHY clock rate in low power mode when connected to a
52 * Low Speed device in host mode. */
53 #define DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ 0
54 #define DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ 1
55 /* the type of PHY interface to use. */
56 #define DWC_PHY_TYPE_PARAM_FS 0
57 #define DWC_PHY_TYPE_PARAM_UTMI 1
58 #define DWC_PHY_TYPE_PARAM_ULPI 2
59 /* whether to use the internal or external supply to
60 * drive the vbus with a ULPI phy. */
61 #define DWC_PHY_ULPI_INTERNAL_VBUS 0
62 #define DWC_PHY_ULPI_EXTERNAL_VBUS 1
67 * This file contains the interface to the Core Interface Layer.
71 * The <code>dwc_ep</code> structure represents the state of a single
72 * endpoint when acting in device mode. It contains the data items
73 * needed for an endpoint to be activated and transfer packets.
75 typedef struct dwc_ep {
76 /** EP number used for register address lookup */
78 /** EP direction 0 = OUT */
83 /** Periodic Tx FIFO # for IN EPs For INTR EP set to 0 to use non-periodic Tx FIFO
84 If dedicated Tx FIFOs are enabled for all IN Eps - Tx FIFO # FOR IN EPs*/
85 unsigned tx_fifo_num : 4;
86 /** EP type: 0 - Control, 1 - ISOC, 2 - BULK, 3 - INTR */
88 #define DWC_OTG_EP_TYPE_CONTROL 0
89 #define DWC_OTG_EP_TYPE_ISOC 1
90 #define DWC_OTG_EP_TYPE_BULK 2
91 #define DWC_OTG_EP_TYPE_INTR 3
93 /** DATA start PID for INTR and BULK EP */
94 unsigned data_pid_start : 1;
95 /** Frame (even/odd) for ISOC EP */
96 unsigned even_odd_frame : 1;
97 /** Max Packet bytes */
98 unsigned maxpacket : 11;
100 /** @name Transfer state */
104 * Pointer to the beginning of the transfer buffer -- do not modify
110 uint8_t *start_xfer_buff;
111 /** pointer to the transfer buffer */
113 /** Number of bytes to transfer */
114 unsigned xfer_len : 19;
115 /** Number of bytes transferred. */
116 unsigned xfer_count : 19;
118 unsigned sent_zlp : 1;
119 /** Total len for control transfer */
120 unsigned total_len : 19;
122 /** stall clear flag */
123 unsigned stall_clear_flag : 1;
129 * Reasons for halting a host channel.
131 typedef enum dwc_otg_halt_status {
132 DWC_OTG_HC_XFER_NO_HALT_STATUS,
133 DWC_OTG_HC_XFER_COMPLETE,
134 DWC_OTG_HC_XFER_URB_COMPLETE,
137 DWC_OTG_HC_XFER_NYET,
138 DWC_OTG_HC_XFER_STALL,
139 DWC_OTG_HC_XFER_XACT_ERR,
140 DWC_OTG_HC_XFER_FRAME_OVERRUN,
141 DWC_OTG_HC_XFER_BABBLE_ERR,
142 DWC_OTG_HC_XFER_DATA_TOGGLE_ERR,
143 DWC_OTG_HC_XFER_AHB_ERR,
144 DWC_OTG_HC_XFER_PERIODIC_INCOMPLETE,
145 DWC_OTG_HC_XFER_URB_DEQUEUE
146 } dwc_otg_halt_status_e;
149 * Host channel descriptor. This structure represents the state of a single
150 * host channel when acting in host mode. It contains the data items needed to
151 * transfer packets to an endpoint via a host channel.
153 typedef struct dwc_hc {
154 /** Host channel number used for register address lookup */
157 /** Device to access */
158 unsigned dev_addr : 7;
163 /** EP direction. 0: OUT, 1: IN */
164 unsigned ep_is_in : 1;
168 * One of the following values:
169 * - DWC_OTG_EP_SPEED_LOW
170 * - DWC_OTG_EP_SPEED_FULL
171 * - DWC_OTG_EP_SPEED_HIGH
174 #define DWC_OTG_EP_SPEED_LOW 0
175 #define DWC_OTG_EP_SPEED_FULL 1
176 #define DWC_OTG_EP_SPEED_HIGH 2
180 * One of the following values:
181 * - DWC_OTG_EP_TYPE_CONTROL: 0
182 * - DWC_OTG_EP_TYPE_ISOC: 1
183 * - DWC_OTG_EP_TYPE_BULK: 2
184 * - DWC_OTG_EP_TYPE_INTR: 3
186 unsigned ep_type : 2;
188 /** Max packet size in bytes */
189 unsigned max_packet : 11;
192 * PID for initial transaction.
196 * 3: MDATA (non-Control EP),
199 unsigned data_pid_start : 2;
200 #define DWC_OTG_HC_PID_DATA0 0
201 #define DWC_OTG_HC_PID_DATA2 1
202 #define DWC_OTG_HC_PID_DATA1 2
203 #define DWC_OTG_HC_PID_MDATA 3
204 #define DWC_OTG_HC_PID_SETUP 3
206 /** Number of periodic transactions per (micro)frame */
207 unsigned multi_count: 2;
209 /** @name Transfer State */
212 /** Pointer to the current transfer buffer position. */
214 /** Total number of bytes to transfer. */
216 /** Number of bytes transferred so far. */
218 /** Packet count at start of transfer.*/
219 uint16_t start_pkt_count;
222 * Flag to indicate whether the transfer has been started. Set to 1 if
223 * it has been started, 0 otherwise.
225 uint8_t xfer_started;
228 * Set to 1 to indicate that a PING request should be issued on this
229 * channel. If 0, process normally.
234 * Set to 1 to indicate that the error count for this transaction is
235 * non-zero. Set to 0 if the error count is 0.
240 * Set to 1 to indicate that this channel should be halted the next
241 * time a request is queued for the channel. This is necessary in
242 * slave mode if no request queue space is available when an attempt
243 * is made to halt the channel.
245 uint8_t halt_on_queue;
248 * Set to 1 if the host channel has been halted, but the core is not
249 * finished flushing queued requests. Otherwise 0.
251 uint8_t halt_pending;
254 * Reason for halting the host channel.
256 dwc_otg_halt_status_e halt_status;
259 * Split settings for the host channel
261 uint8_t do_split; /**< Enable split for the channel */
262 uint8_t complete_split; /**< Enable complete split */
263 uint8_t hub_addr; /**< Address of high speed hub */
265 uint8_t port_addr; /**< Port of the low/full speed device */
266 /** Split transaction position
267 * One of the following values:
268 * - DWC_HCSPLIT_XACTPOS_MID
269 * - DWC_HCSPLIT_XACTPOS_BEGIN
270 * - DWC_HCSPLIT_XACTPOS_END
271 * - DWC_HCSPLIT_XACTPOS_ALL */
274 /** Set when the host channel does a short read. */
278 * Number of requests issued for this channel since it was assigned to
279 * the current transfer (not counting PINGs).
284 * Queue Head for the transfer being processed by this channel.
286 struct dwc_otg_qh *qh;
290 /** Entry in list of host channels. */
291 struct list_head hc_list_entry;
295 * The following parameters may be specified when starting the module. These
296 * parameters define how the DWC_otg controller should be configured.
297 * Parameter values are passed to the CIL initialization function
301 typedef struct dwc_otg_core_params
304 //#define dwc_param_opt_default 1
306 * Specifies the OTG capabilities. The driver will automatically
307 * detect the value for this parameter if none is specified.
308 * 0 - HNP and SRP capable (default)
309 * 1 - SRP Only capable
310 * 2 - No HNP/SRP capable
313 #define DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE 0
314 #define DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE 1
315 #define DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE 2
316 //#define dwc_param_otg_cap_default DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE
318 * Specifies whether to use slave or DMA mode for accessing the data
319 * FIFOs. The driver will automatically detect the value for this
320 * parameter if none is specified.
322 * 1 - DMA (default, if available)
325 //#define dwc_param_dma_enable_default 1
326 /** The DMA Burst size (applicable only for External DMA
327 * Mode). 1, 4, 8 16, 32, 64, 128, 256 (default 32)
329 int32_t dma_burst_size; /* Translate this to GAHBCFG values */
330 //#define dwc_param_dma_burst_size_default 32
332 * Specifies the maximum speed of operation in host and device mode.
333 * The actual speed depends on the speed of the attached device and
334 * the value of phy_type. The actual speed depends on the speed of the
336 * 0 - High Speed (default)
340 //#define dwc_param_speed_default 0
341 #define DWC_SPEED_PARAM_HIGH 0
342 #define DWC_SPEED_PARAM_FULL 1
344 /** Specifies whether low power mode is supported when attached
345 * to a Full Speed or Low Speed device in host mode.
346 * 0 - Don't support low power mode (default)
347 * 1 - Support low power mode
349 int32_t host_support_fs_ls_low_power;
350 //#define dwc_param_host_support_fs_ls_low_power_default 0
351 /** Specifies the PHY clock rate in low power mode when connected to a
352 * Low Speed device in host mode. This parameter is applicable only if
353 * HOST_SUPPORT_FS_LS_LOW_POWER is enabled. If PHY_TYPE is set to FS
354 * then defaults to 6 MHZ otherwise 48 MHZ.
359 int32_t host_ls_low_power_phy_clk;
360 //#define dwc_param_host_ls_low_power_phy_clk_default 0
361 #define DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ 0
362 #define DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ 1
364 * 0 - Use cC FIFO size parameters
365 * 1 - Allow dynamic FIFO sizing (default)
367 int32_t enable_dynamic_fifo;
368 //#define dwc_param_enable_dynamic_fifo_default 1
369 /** Total number of 4-byte words in the data FIFO memory. This
370 * memory includes the Rx FIFO, non-periodic Tx FIFO, and periodic
372 * 32 to 32768 (default 8192)
373 * Note: The total FIFO memory depth in the FPGA configuration is 8192.
375 int32_t data_fifo_size;
376 //#define dwc_param_data_fifo_size_default 8192
377 /** Number of 4-byte words in the Rx FIFO in device mode when dynamic
378 * FIFO sizing is enabled.
379 * 16 to 32768 (default 1064)
381 int32_t dev_rx_fifo_size;
382 //#define dwc_param_dev_rx_fifo_size_default 1064
383 /** Number of 4-byte words in the non-periodic Tx FIFO in device mode
384 * when dynamic FIFO sizing is enabled.
385 * 16 to 32768 (default 1024)
387 int32_t dev_nperio_tx_fifo_size;
388 //#define dwc_param_dev_nperio_tx_fifo_size_default 1024
389 /** Number of 4-byte words in each of the periodic Tx FIFOs in device
390 * mode when dynamic FIFO sizing is enabled.
391 * 4 to 768 (default 256)
393 uint32_t dev_perio_tx_fifo_size[MAX_PERIO_FIFOS];
394 //#define dwc_param_dev_perio_tx_fifo_size_default 256
395 /** Number of 4-byte words in the Rx FIFO in host mode when dynamic
396 * FIFO sizing is enabled.
397 * 16 to 32768 (default 1024)
399 int32_t host_rx_fifo_size;
400 //#define dwc_param_host_rx_fifo_size_default 1024
401 /** Number of 4-byte words in the non-periodic Tx FIFO in host mode
402 * when Dynamic FIFO sizing is enabled in the core.
403 * 16 to 32768 (default 1024)
405 int32_t host_nperio_tx_fifo_size;
406 //#define dwc_param_host_nperio_tx_fifo_size_default 1024
407 /** Number of 4-byte words in the host periodic Tx FIFO when dynamic
408 * FIFO sizing is enabled.
409 * 16 to 32768 (default 1024)
411 int32_t host_perio_tx_fifo_size;
412 //#define dwc_param_host_perio_tx_fifo_size_default 1024
413 /** The maximum transfer size supported in bytes.
414 * 2047 to 65,535 (default 65,535)
416 int32_t max_transfer_size;
417 //#define dwc_param_max_transfer_size_default 65535
418 /** The maximum number of packets in a transfer.
419 * 15 to 511 (default 511)
421 int32_t max_packet_count;
422 //#define dwc_param_max_packet_count_default 511
423 /** The number of host channel registers to use.
424 * 1 to 16 (default 12)
425 * Note: The FPGA configuration supports a maximum of 12 host channels.
427 int32_t host_channels;
428 //#define dwc_param_host_channels_default 12
429 /** The number of endpoints in addition to EP0 available for device
431 * 1 to 15 (default 6 IN and OUT)
432 * Note: The FPGA configuration supports a maximum of 6 IN and OUT
433 * endpoints in addition to EP0.
435 int32_t dev_endpoints;
436 //#define dwc_param_dev_endpoints_default 6
438 * Specifies the type of PHY interface to use. By default, the driver
439 * will automatically detect the phy_type.
442 * 1 - UTMI+ (default)
446 #define DWC_PHY_TYPE_PARAM_FS 0
447 #define DWC_PHY_TYPE_PARAM_UTMI 1
448 #define DWC_PHY_TYPE_PARAM_ULPI 2
449 //#define dwc_param_phy_type_default DWC_PHY_TYPE_PARAM_UTMI
451 * Specifies the UTMI+ Data Width. This parameter is
452 * applicable for a PHY_TYPE of UTMI+ or ULPI. (For a ULPI
453 * PHY_TYPE, this parameter indicates the data width between
454 * the MAC and the ULPI Wrapper.) Also, this parameter is
455 * applicable only if the OTG_HSPHY_WIDTH cC parameter was set
456 * to "8 and 16 bits", meaning that the core has been
457 * configured to work at either data path width.
459 * 8 or 16 bits (default 16)
461 int32_t phy_utmi_width;
462 //#define dwc_param_phy_utmi_width_default 16
464 * Specifies whether the ULPI operates at double or single
465 * data rate. This parameter is only applicable if PHY_TYPE is
468 * 0 - single data rate ULPI interface with 8 bit wide data
470 * 1 - double data rate ULPI interface with 4 bit wide data
473 int32_t phy_ulpi_ddr;
474 //#define dwc_param_phy_ulpi_ddr_default 0
476 * Specifies whether to use the internal or external supply to
477 * drive the vbus with a ULPI phy.
479 int32_t phy_ulpi_ext_vbus;
480 #define DWC_PHY_ULPI_INTERNAL_VBUS 0
481 #define DWC_PHY_ULPI_EXTERNAL_VBUS 1
482 //#define dwc_param_phy_ulpi_ext_vbus_default DWC_PHY_ULPI_INTERNAL_VBUS
484 * Specifies whether to use the I2Cinterface for full speed PHY. This
485 * parameter is only applicable if PHY_TYPE is FS.
490 //#define dwc_param_i2c_enable_default 0
493 //#define dwc_param_ulpi_fs_ls_default 0
496 //#define dwc_param_ts_dline_default 0
499 * Specifies whether dedicated transmit FIFOs are
500 * enabled for non periodic IN endpoints in device mode
504 int32_t en_multiple_tx_fifo;
505 #define dwc_param_en_multiple_tx_fifo_default 1
507 /** Number of 4-byte words in each of the Tx FIFOs in device
508 * mode when dynamic FIFO sizing is enabled.
509 * 4 to 768 (default 256)
511 uint32_t dev_tx_fifo_size[MAX_TX_FIFOS];
512 #define dwc_param_dev_tx_fifo_size_default 256
514 /** Thresholding enable flag-
515 * bit 0 - enable non-ISO Tx thresholding
516 * bit 1 - enable ISO Tx thresholding
517 * bit 2 - enable Rx thresholding
520 #define dwc_param_thr_ctl_default 0
522 /** Thresholding length for Tx
523 * FIFOs in 32 bit DWORDs
525 uint32_t tx_thr_length;
526 #define dwc_param_tx_thr_length_default 64
528 /** Thresholding length for Rx
529 * FIFOs in 32 bit DWORDs
531 uint32_t rx_thr_length;
532 #define dwc_param_rx_thr_length_default 64
533 } dwc_otg_core_params_t;
536 struct dwc_otg_core_if;
537 typedef struct hc_xfer_info
539 struct dwc_otg_core_if *core_if;
545 * The <code>dwc_otg_core_if</code> structure contains information needed to manage
546 * the DWC_otg controller acting in either host or device mode. It
547 * represents the programming view of the controller as a whole.
549 typedef struct dwc_otg_core_if
551 /** Parameters that define how the core should be configured.*/
552 dwc_otg_core_params_t *core_params;
554 /** Core Global registers starting at offset 000h. */
555 dwc_otg_core_global_regs_t *core_global_regs;
557 /** Device-specific information */
558 dwc_otg_dev_if_t *dev_if;
559 /** Host-specific information */
560 dwc_otg_host_if_t *host_if;
563 * Set to 1 if the core PHY interface bits in USBCFG have been
566 uint8_t phy_init_done;
569 * SRP Success flag, set by srp success interrupt in FS I2C mode
572 uint8_t srp_timer_started;
574 /* Common configuration information */
575 /** Power and Clock Gating Control Register */
576 volatile uint32_t *pcgcctl;
577 #define DWC_OTG_PCGCCTL_OFFSET 0xE00
579 /** Push/pop addresses for endpoints or host channels.*/
580 uint32_t *data_fifo[MAX_EPS_CHANNELS];
581 #define DWC_OTG_DATA_FIFO_OFFSET 0x1000
582 #define DWC_OTG_DATA_FIFO_SIZE 0x1000
584 /** Total RAM for FIFOs (Bytes) */
585 uint16_t total_fifo_size;
586 /** Size of Rx FIFO (Bytes) */
587 uint16_t rx_fifo_size;
588 /** Size of Non-periodic Tx FIFO (Bytes) */
589 uint16_t nperio_tx_fifo_size;
591 /** 1 if DMA is enabled, 0 otherwise. */
594 /** 1 if dedicated Tx FIFOs are enabled, 0 otherwise. */
595 uint8_t en_multiple_tx_fifo;
597 /** Set to 1 if multiple packets of a high-bandwidth transfer is in
598 * process of being queued */
599 uint8_t queuing_high_bandwidth;
601 /** Hardware Configuration -- stored here for convenience.*/
602 hwcfg1_data_t hwcfg1;
603 hwcfg2_data_t hwcfg2;
604 hwcfg3_data_t hwcfg3;
605 hwcfg4_data_t hwcfg4;
607 /** The operational State, during transations
608 * (a_host>>a_peripherial and b_device=>b_host) this may not
609 * match the core but allows the software to determine
615 * Set to 1 if the HCD needs to be restarted on a session request
616 * interrupt. This is required if no connector ID status change has
617 * occurred since the HCD was last disconnected.
619 uint8_t restart_hcd_on_session_req;
622 /** A-Device is a_host */
624 /** A-Device is a_suspend */
625 #define A_SUSPEND (2)
626 /** A-Device is a_peripherial */
627 #define A_PERIPHERAL (3)
628 /** B-Device is operating as a Peripheral. */
629 #define B_PERIPHERAL (4)
630 /** B-Device is operating as a Host. */
634 struct dwc_otg_cil_callbacks *hcd_cb;
636 struct dwc_otg_cil_callbacks *pcd_cb;
638 /** Device mode Periodic Tx FIFO Mask */
640 /** Device mode Periodic Tx FIFO Mask */
644 uint32_t start_hcchar_val[MAX_EPS_CHANNELS];
646 hc_xfer_info_t hc_xfer_info[MAX_EPS_CHANNELS];
647 struct timer_list hc_xfer_timer[MAX_EPS_CHANNELS];
650 uint32_t hfnum_7_samples;
651 uint32_t hfnum_7_frrem_accum;
652 uint32_t hfnum_0_samples;
653 uint32_t hfnum_0_frrem_accum;
654 uint32_t hfnum_other_samples;
655 uint32_t hfnum_other_frrem_accum;
657 uint32_t hfnum_7_samples;
658 uint64_t hfnum_7_frrem_accum;
659 uint32_t hfnum_0_samples;
660 uint64_t hfnum_0_frrem_accum;
661 uint32_t hfnum_other_samples;
662 uint64_t hfnum_other_frrem_accum;
664 resource_size_t phys_addr; /* Added to support PLB DMA : phys-virt mapping */
670 * The following functions support initialization of the CIL driver component
671 * and the DWC_otg controller.
673 extern dwc_otg_core_if_t *dwc_otg_cil_init(const uint32_t *_reg_base_addr,
674 dwc_otg_core_params_t *_core_params);
675 extern void dwc_otg_cil_remove(dwc_otg_core_if_t *_core_if);
676 extern void dwc_otg_core_init(dwc_otg_core_if_t *_core_if);
677 extern void dwc_otg_core_host_init(dwc_otg_core_if_t *_core_if);
678 extern void dwc_otg_core_dev_init(dwc_otg_core_if_t *_core_if);
679 extern void dwc_otg_enable_global_interrupts( dwc_otg_core_if_t *_core_if );
680 extern void dwc_otg_disable_global_interrupts( dwc_otg_core_if_t *_core_if );
682 /** @name Device CIL Functions
683 * The following functions support managing the DWC_otg controller in device
687 extern void dwc_otg_wakeup(dwc_otg_core_if_t *_core_if);
688 extern void dwc_otg_read_setup_packet (dwc_otg_core_if_t *_core_if, uint32_t *_dest);
689 extern uint32_t dwc_otg_get_frame_number(dwc_otg_core_if_t *_core_if);
690 extern void dwc_otg_ep0_activate(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep);
691 extern void dwc_otg_ep_activate(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep);
692 extern void dwc_otg_ep_deactivate(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep);
693 extern void dwc_otg_ep_start_transfer(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep);
694 extern void dwc_otg_ep0_start_transfer(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep);
695 extern void dwc_otg_ep0_continue_transfer(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep);
696 extern void dwc_otg_ep_write_packet(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep, int _dma);
697 extern void dwc_otg_ep_set_stall(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep);
698 extern void dwc_otg_ep_clear_stall(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep);
699 extern void dwc_otg_enable_device_interrupts(dwc_otg_core_if_t *_core_if);
700 extern void dwc_otg_dump_dev_registers(dwc_otg_core_if_t *_core_if);
703 /** @name Host CIL Functions
704 * The following functions support managing the DWC_otg controller in host
708 extern void dwc_otg_hc_init(dwc_otg_core_if_t *_core_if, dwc_hc_t *_hc);
709 extern void dwc_otg_hc_halt(dwc_otg_core_if_t *_core_if,
711 dwc_otg_halt_status_e _halt_status);
712 extern void dwc_otg_hc_cleanup(dwc_otg_core_if_t *_core_if, dwc_hc_t *_hc);
713 extern void dwc_otg_hc_start_transfer(dwc_otg_core_if_t *_core_if, dwc_hc_t *_hc);
714 extern int dwc_otg_hc_continue_transfer(dwc_otg_core_if_t *_core_if, dwc_hc_t *_hc);
715 extern void dwc_otg_hc_do_ping(dwc_otg_core_if_t *_core_if, dwc_hc_t *_hc);
716 extern void dwc_otg_hc_write_packet(dwc_otg_core_if_t *_core_if, dwc_hc_t *_hc);
717 extern void dwc_otg_enable_host_interrupts(dwc_otg_core_if_t *_core_if);
718 extern void dwc_otg_disable_host_interrupts(dwc_otg_core_if_t *_core_if);
721 * This function Reads HPRT0 in preparation to modify. It keeps the
722 * WC bits 0 so that if they are read as 1, they won't clear when you
725 static inline uint32_t dwc_otg_read_hprt0(dwc_otg_core_if_t *_core_if)
728 hprt0.d32 = dwc_read_reg32(_core_if->host_if->hprt0);
730 hprt0.b.prtconndet = 0;
731 hprt0.b.prtenchng = 0;
732 hprt0.b.prtovrcurrchng = 0;
736 extern void dwc_otg_dump_host_registers(dwc_otg_core_if_t *_core_if);
739 /** @name Common CIL Functions
740 * The following functions support managing the DWC_otg controller in either
741 * device or host mode.
745 extern void dwc_otg_read_packet(dwc_otg_core_if_t *core_if,
749 extern void dwc_otg_dump_global_registers(dwc_otg_core_if_t *_core_if);
751 extern void dwc_otg_flush_tx_fifo( dwc_otg_core_if_t *_core_if,
753 extern void dwc_otg_flush_rx_fifo( dwc_otg_core_if_t *_core_if );
754 extern void dwc_otg_core_reset( dwc_otg_core_if_t *_core_if );
756 #define NP_TXFIFO_EMPTY -1
757 #define MAX_NP_TXREQUEST_Q_SLOTS 8
759 * This function returns the endpoint number of the request at
760 * the top of non-periodic TX FIFO, or -1 if the request FIFO is
763 static inline int dwc_otg_top_nptxfifo_epnum(dwc_otg_core_if_t *_core_if) {
764 gnptxsts_data_t txstatus = {.d32 = 0};
766 txstatus.d32 = dwc_read_reg32(&_core_if->core_global_regs->gnptxsts);
767 return (txstatus.b.nptxqspcavail == MAX_NP_TXREQUEST_Q_SLOTS ?
768 -1 : txstatus.b.nptxqtop_chnep);
771 * This function returns the Core Interrupt register.
773 static inline uint32_t dwc_otg_read_core_intr(dwc_otg_core_if_t *_core_if) {
774 return (dwc_read_reg32(&_core_if->core_global_regs->gintsts) &
775 dwc_read_reg32(&_core_if->core_global_regs->gintmsk));
779 * This function returns the OTG Interrupt register.
781 static inline uint32_t dwc_otg_read_otg_intr (dwc_otg_core_if_t *_core_if) {
782 return (dwc_read_reg32 (&_core_if->core_global_regs->gotgint));
786 * This function reads the Device All Endpoints Interrupt register and
787 * returns the IN endpoint interrupt bits.
789 static inline uint32_t dwc_otg_read_dev_all_in_ep_intr(dwc_otg_core_if_t *_core_if) {
791 v = dwc_read_reg32(&_core_if->dev_if->dev_global_regs->daint) &
792 dwc_read_reg32(&_core_if->dev_if->dev_global_regs->daintmsk);
798 * This function reads the Device All Endpoints Interrupt register and
799 * returns the OUT endpoint interrupt bits.
801 static inline uint32_t dwc_otg_read_dev_all_out_ep_intr(dwc_otg_core_if_t *_core_if) {
803 v = dwc_read_reg32(&_core_if->dev_if->dev_global_regs->daint) &
804 dwc_read_reg32(&_core_if->dev_if->dev_global_regs->daintmsk);
805 return ((v & 0xffff0000) >> 16);
809 * This function returns the Device IN EP Interrupt register
811 static inline uint32_t dwc_otg_read_dev_in_ep_intr(dwc_otg_core_if_t *_core_if,
814 dwc_otg_dev_if_t *dev_if = _core_if->dev_if;
815 uint32_t v, msk, emp;
816 msk = dwc_read_reg32(&dev_if->dev_global_regs->diepmsk);
817 emp = dwc_read_reg32(&dev_if->dev_global_regs->dtknqr4_fifoemptymsk);
818 msk |= ((emp >> _ep->num) & 0x1) << 7;
819 v = dwc_read_reg32(&dev_if->in_ep_regs[_ep->num]->diepint) & msk;
821 dwc_otg_dev_if_t *dev_if = _core_if->dev_if;
823 v = dwc_read_reg32(&dev_if->in_ep_regs[_ep->num]->diepint) &
824 dwc_read_reg32(&dev_if->dev_global_regs->diepmsk);
829 * This function returns the Device OUT EP Interrupt register
831 static inline uint32_t dwc_otg_read_dev_out_ep_intr(dwc_otg_core_if_t *_core_if,
834 dwc_otg_dev_if_t *dev_if = _core_if->dev_if;
836 v = dwc_read_reg32( &dev_if->out_ep_regs[_ep->num]->doepint) &
837 dwc_read_reg32(&dev_if->dev_global_regs->doepmsk);
842 * This function returns the Host All Channel Interrupt register
844 static inline uint32_t dwc_otg_read_host_all_channels_intr (dwc_otg_core_if_t *_core_if)
846 return (dwc_read_reg32 (&_core_if->host_if->host_global_regs->haint));
849 static inline uint32_t dwc_otg_read_host_channel_intr (dwc_otg_core_if_t *_core_if, dwc_hc_t *_hc)
851 return (dwc_read_reg32 (&_core_if->host_if->hc_regs[_hc->hc_num]->hcint));
856 * This function returns the mode of the operation, host or device.
858 * @return 0 - Device Mode, 1 - Host Mode
860 static inline uint32_t dwc_otg_mode(dwc_otg_core_if_t *_core_if) {
861 return (dwc_read_reg32( &_core_if->core_global_regs->gintsts ) & 0x1);
864 static inline uint8_t dwc_otg_is_device_mode(dwc_otg_core_if_t *_core_if)
866 return (dwc_otg_mode(_core_if) != DWC_HOST_MODE);
868 static inline uint8_t dwc_otg_is_host_mode(dwc_otg_core_if_t *_core_if)
870 return (dwc_otg_mode(_core_if) == DWC_HOST_MODE);
873 extern int32_t dwc_otg_handle_common_intr( dwc_otg_core_if_t *_core_if );
879 * DWC_otg CIL callback structure. This structure allows the HCD and
880 * PCD to register functions used for starting and stopping the PCD
881 * and HCD for role change on for a DRD.
883 typedef struct dwc_otg_cil_callbacks
885 /** Start function for role change */
886 int (*start) (void *_p);
887 /** Stop Function for role change */
888 int (*stop) (void *_p);
889 /** Disconnect Function for role change */
890 int (*disconnect) (void *_p);
891 /** Resume/Remote wakeup Function */
892 int (*resume_wakeup) (void *_p);
893 /** Suspend function */
894 int (*suspend) (void *_p);
895 /** Session Start (SRP) */
896 int (*session_start) (void *_p);
897 /** Pointer passed to start() and stop() */
899 } dwc_otg_cil_callbacks_t;
903 extern void dwc_otg_cil_register_pcd_callbacks( dwc_otg_core_if_t *_core_if,
904 dwc_otg_cil_callbacks_t *_cb,
906 extern void dwc_otg_cil_register_hcd_callbacks( dwc_otg_core_if_t *_core_if,
907 dwc_otg_cil_callbacks_t *_cb,