1 /* ==========================================================================
2 * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_cil.h $
4 * $Date: 2008-11-21 05:39:15 $
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 <linux/workqueue.h>
38 #include <linux/version.h>
39 #include <asm/param.h>
41 #include "linux/dwc_otg_plat.h"
42 #include "dwc_otg_regs.h"
44 #include "linux/timer.h"
49 * This file contains the interface to the Core Interface Layer.
53 /** Macros defined for DWC OTG HW Release verison */
54 #define OTG_CORE_REV_2_00 0x4F542000
55 #define OTG_CORE_REV_2_60a 0x4F54260A
56 #define OTG_CORE_REV_2_71a 0x4F54271A
57 #define OTG_CORE_REV_2_72a 0x4F54272A
61 typedef struct iso_pkt_info
68 * The <code>dwc_ep</code> structure represents the state of a single
69 * endpoint when acting in device mode. It contains the data items
70 * needed for an endpoint to be activated and transfer packets.
74 /** EP number used for register address lookup */
76 /** EP direction 0 = OUT */
81 /** Periodic Tx FIFO # for IN EPs For INTR EP set to 0 to use non-periodic Tx FIFO
82 If dedicated Tx FIFOs are enabled for all IN Eps - Tx FIFO # FOR IN EPs*/
83 unsigned tx_fifo_num
: 4;
84 /** EP type: 0 - Control, 1 - ISOC, 2 - BULK, 3 - INTR */
86 #define DWC_OTG_EP_TYPE_CONTROL 0
87 #define DWC_OTG_EP_TYPE_ISOC 1
88 #define DWC_OTG_EP_TYPE_BULK 2
89 #define DWC_OTG_EP_TYPE_INTR 3
91 /** DATA start PID for INTR and BULK EP */
92 unsigned data_pid_start
: 1;
93 /** Frame (even/odd) for ISOC EP */
94 unsigned even_odd_frame
: 1;
95 /** Max Packet bytes */
96 unsigned maxpacket
: 11;
98 /** Max Transfer size */
99 unsigned maxxfer
: 16;
101 /** @name Transfer state */
105 * Pointer to the beginning of the transfer buffer -- do not modify
111 uint32_t dma_desc_addr
;
112 dwc_otg_dma_desc_t
* desc_addr
;
115 uint8_t *start_xfer_buff
;
116 /** pointer to the transfer buffer */
118 /** Number of bytes to transfer */
119 unsigned xfer_len
: 19;
120 /** Number of bytes transferred. */
121 unsigned xfer_count
: 19;
123 unsigned sent_zlp
: 1;
124 /** Total len for control transfer */
125 unsigned total_len
: 19;
127 /** stall clear flag */
128 unsigned stall_clear_flag
: 1;
130 /** Allocated DMA Desc count */
135 * Variables specific for ISOC EPs
138 /** DMA addresses of ISOC buffers */
142 uint32_t iso_dma_desc_addr
;
143 dwc_otg_dma_desc_t
* iso_desc_addr
;
145 /** pointer to the transfer buffers */
149 /** number of ISOC Buffer is processing */
150 uint32_t proc_buf_num
;
151 /** Interval of ISOC Buffer processing */
152 uint32_t buf_proc_intrvl
;
153 /** Data size for regular frame */
154 uint32_t data_per_frame
;
156 /* todo - pattern data support is to be implemented in the future */
157 /** Data size for pattern frame */
158 uint32_t data_pattern_frame
;
159 /** Frame number of pattern data */
164 /** ISO Packet number per frame */
165 uint32_t pkt_per_frm
;
166 /** Next frame num for which will be setup DMA Desc */
168 /** Number of packets per buffer processing */
170 /** Info for all isoc packets */
171 iso_pkt_info_t
*pkt_info
;
172 /** current pkt number */
174 /** current pkt number */
175 uint8_t *cur_pkt_addr
;
176 /** current pkt number */
177 uint32_t cur_pkt_dma_addr
;
183 * Reasons for halting a host channel.
185 typedef enum dwc_otg_halt_status
187 DWC_OTG_HC_XFER_NO_HALT_STATUS
,
188 DWC_OTG_HC_XFER_COMPLETE
,
189 DWC_OTG_HC_XFER_URB_COMPLETE
,
192 DWC_OTG_HC_XFER_NYET
,
193 DWC_OTG_HC_XFER_STALL
,
194 DWC_OTG_HC_XFER_XACT_ERR
,
195 DWC_OTG_HC_XFER_FRAME_OVERRUN
,
196 DWC_OTG_HC_XFER_BABBLE_ERR
,
197 DWC_OTG_HC_XFER_DATA_TOGGLE_ERR
,
198 DWC_OTG_HC_XFER_AHB_ERR
,
199 DWC_OTG_HC_XFER_PERIODIC_INCOMPLETE
,
200 DWC_OTG_HC_XFER_URB_DEQUEUE
201 } dwc_otg_halt_status_e
;
204 * Host channel descriptor. This structure represents the state of a single
205 * host channel when acting in host mode. It contains the data items needed to
206 * transfer packets to an endpoint via a host channel.
208 typedef struct dwc_hc
210 /** Host channel number used for register address lookup */
213 /** Device to access */
214 unsigned dev_addr
: 7;
219 /** EP direction. 0: OUT, 1: IN */
220 unsigned ep_is_in
: 1;
224 * One of the following values:
225 * - DWC_OTG_EP_SPEED_LOW
226 * - DWC_OTG_EP_SPEED_FULL
227 * - DWC_OTG_EP_SPEED_HIGH
230 #define DWC_OTG_EP_SPEED_LOW 0
231 #define DWC_OTG_EP_SPEED_FULL 1
232 #define DWC_OTG_EP_SPEED_HIGH 2
236 * One of the following values:
237 * - DWC_OTG_EP_TYPE_CONTROL: 0
238 * - DWC_OTG_EP_TYPE_ISOC: 1
239 * - DWC_OTG_EP_TYPE_BULK: 2
240 * - DWC_OTG_EP_TYPE_INTR: 3
242 unsigned ep_type
: 2;
244 /** Max packet size in bytes */
245 unsigned max_packet
: 11;
248 * PID for initial transaction.
252 * 3: MDATA (non-Control EP),
255 unsigned data_pid_start
: 2;
256 #define DWC_OTG_HC_PID_DATA0 0
257 #define DWC_OTG_HC_PID_DATA2 1
258 #define DWC_OTG_HC_PID_DATA1 2
259 #define DWC_OTG_HC_PID_MDATA 3
260 #define DWC_OTG_HC_PID_SETUP 3
262 /** Number of periodic transactions per (micro)frame */
263 unsigned multi_count
: 2;
265 /** @name Transfer State */
268 /** Pointer to the current transfer buffer position. */
270 /** Total number of bytes to transfer. */
272 /** Number of bytes transferred so far. */
274 /** Packet count at start of transfer.*/
275 uint16_t start_pkt_count
;
278 * Flag to indicate whether the transfer has been started. Set to 1 if
279 * it has been started, 0 otherwise.
281 uint8_t xfer_started
;
284 * Set to 1 to indicate that a PING request should be issued on this
285 * channel. If 0, process normally.
290 * Set to 1 to indicate that the error count for this transaction is
291 * non-zero. Set to 0 if the error count is 0.
296 * Set to 1 to indicate that this channel should be halted the next
297 * time a request is queued for the channel. This is necessary in
298 * slave mode if no request queue space is available when an attempt
299 * is made to halt the channel.
301 uint8_t halt_on_queue
;
304 * Set to 1 if the host channel has been halted, but the core is not
305 * finished flushing queued requests. Otherwise 0.
307 uint8_t halt_pending
;
310 * Reason for halting the host channel.
312 dwc_otg_halt_status_e halt_status
;
315 * Split settings for the host channel
317 uint8_t do_split
; /**< Enable split for the channel */
318 uint8_t complete_split
; /**< Enable complete split */
319 uint8_t hub_addr
; /**< Address of high speed hub */
321 uint8_t port_addr
; /**< Port of the low/full speed device */
322 /** Split transaction position
323 * One of the following values:
324 * - DWC_HCSPLIT_XACTPOS_MID
325 * - DWC_HCSPLIT_XACTPOS_BEGIN
326 * - DWC_HCSPLIT_XACTPOS_END
327 * - DWC_HCSPLIT_XACTPOS_ALL */
330 /** Set when the host channel does a short read. */
334 * Number of requests issued for this channel since it was assigned to
335 * the current transfer (not counting PINGs).
340 * Queue Head for the transfer being processed by this channel.
342 struct dwc_otg_qh
*qh
;
346 /** Entry in list of host channels. */
347 struct list_head hc_list_entry
;
351 * The following parameters may be specified when starting the module. These
352 * parameters define how the DWC_otg controller should be configured.
353 * Parameter values are passed to the CIL initialization function
356 typedef struct dwc_otg_core_params
359 #define dwc_param_opt_default 1
362 * Specifies the OTG capabilities. The driver will automatically
363 * detect the value for this parameter if none is specified.
364 * 0 - HNP and SRP capable (default)
365 * 1 - SRP Only capable
366 * 2 - No HNP/SRP capable
369 #define DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE 0
370 #define DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE 1
371 #define DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE 2
372 #define dwc_param_otg_cap_default DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE
375 * Specifies whether to use slave or DMA mode for accessing the data
376 * FIFOs. The driver will automatically detect the value for this
377 * parameter if none is specified.
379 * 1 - DMA (default, if available)
382 #define dwc_param_dma_enable_default 1
385 * When DMA mode is enabled specifies whether to use address DMA or DMA Descritor mode for accessing the data
386 * FIFOs in device mode. The driver will automatically detect the value for this
387 * parameter if none is specified.
389 * 1 - DMA Descriptor(default, if available)
391 int32_t dma_desc_enable
;
392 #define dwc_param_dma_desc_enable_default 0
393 /** The DMA Burst size (applicable only for External DMA
394 * Mode). 1, 4, 8 16, 32, 64, 128, 256 (default 32)
396 int32_t dma_burst_size
; /* Translate this to GAHBCFG values */
397 #define dwc_param_dma_burst_size_default 32
400 * Specifies the maximum speed of operation in host and device mode.
401 * The actual speed depends on the speed of the attached device and
402 * the value of phy_type. The actual speed depends on the speed of the
404 * 0 - High Speed (default)
408 #define dwc_param_speed_default 0
409 #define DWC_SPEED_PARAM_HIGH 0
410 #define DWC_SPEED_PARAM_FULL 1
412 /** Specifies whether low power mode is supported when attached
413 * to a Full Speed or Low Speed device in host mode.
414 * 0 - Don't support low power mode (default)
415 * 1 - Support low power mode
417 int32_t host_support_fs_ls_low_power
;
418 #define dwc_param_host_support_fs_ls_low_power_default 0
420 /** Specifies the PHY clock rate in low power mode when connected to a
421 * Low Speed device in host mode. This parameter is applicable only if
422 * HOST_SUPPORT_FS_LS_LOW_POWER is enabled. If PHY_TYPE is set to FS
423 * then defaults to 6 MHZ otherwise 48 MHZ.
428 int32_t host_ls_low_power_phy_clk
;
429 #define dwc_param_host_ls_low_power_phy_clk_default 0
430 #define DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ 0
431 #define DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ 1
434 * 0 - Use cC FIFO size parameters
435 * 1 - Allow dynamic FIFO sizing (default)
437 int32_t enable_dynamic_fifo
;
438 #define dwc_param_enable_dynamic_fifo_default 1
440 /** Total number of 4-byte words in the data FIFO memory. This
441 * memory includes the Rx FIFO, non-periodic Tx FIFO, and periodic
443 * 32 to 32768 (default 8192)
444 * Note: The total FIFO memory depth in the FPGA configuration is 8192.
446 int32_t data_fifo_size
;
447 #define dwc_param_data_fifo_size_default 8192
449 /** Number of 4-byte words in the Rx FIFO in device mode when dynamic
450 * FIFO sizing is enabled.
451 * 16 to 32768 (default 1064)
453 int32_t dev_rx_fifo_size
;
454 #define dwc_param_dev_rx_fifo_size_default 1064
456 /** Number of 4-byte words in the non-periodic Tx FIFO in device mode
457 * when dynamic FIFO sizing is enabled.
458 * 16 to 32768 (default 1024)
460 int32_t dev_nperio_tx_fifo_size
;
461 #define dwc_param_dev_nperio_tx_fifo_size_default 1024
463 /** Number of 4-byte words in each of the periodic Tx FIFOs in device
464 * mode when dynamic FIFO sizing is enabled.
465 * 4 to 768 (default 256)
467 uint32_t dev_perio_tx_fifo_size
[MAX_PERIO_FIFOS
];
468 #define dwc_param_dev_perio_tx_fifo_size_default 256
470 /** Number of 4-byte words in the Rx FIFO in host mode when dynamic
471 * FIFO sizing is enabled.
472 * 16 to 32768 (default 1024)
474 int32_t host_rx_fifo_size
;
475 #define dwc_param_host_rx_fifo_size_default 1024
477 /** Number of 4-byte words in the non-periodic Tx FIFO in host mode
478 * when Dynamic FIFO sizing is enabled in the core.
479 * 16 to 32768 (default 1024)
481 int32_t host_nperio_tx_fifo_size
;
482 #define dwc_param_host_nperio_tx_fifo_size_default 1024
484 /** Number of 4-byte words in the host periodic Tx FIFO when dynamic
485 * FIFO sizing is enabled.
486 * 16 to 32768 (default 1024)
488 int32_t host_perio_tx_fifo_size
;
489 #define dwc_param_host_perio_tx_fifo_size_default 1024
491 /** The maximum transfer size supported in bytes.
492 * 2047 to 65,535 (default 65,535)
494 int32_t max_transfer_size
;
495 #define dwc_param_max_transfer_size_default 65535
497 /** The maximum number of packets in a transfer.
498 * 15 to 511 (default 511)
500 int32_t max_packet_count
;
501 #define dwc_param_max_packet_count_default 511
503 /** The number of host channel registers to use.
504 * 1 to 16 (default 12)
505 * Note: The FPGA configuration supports a maximum of 12 host channels.
507 int32_t host_channels
;
508 #define dwc_param_host_channels_default 12
510 /** The number of endpoints in addition to EP0 available for device
512 * 1 to 15 (default 6 IN and OUT)
513 * Note: The FPGA configuration supports a maximum of 6 IN and OUT
514 * endpoints in addition to EP0.
516 int32_t dev_endpoints
;
517 #define dwc_param_dev_endpoints_default 6
520 * Specifies the type of PHY interface to use. By default, the driver
521 * will automatically detect the phy_type.
524 * 1 - UTMI+ (default)
528 #define DWC_PHY_TYPE_PARAM_FS 0
529 #define DWC_PHY_TYPE_PARAM_UTMI 1
530 #define DWC_PHY_TYPE_PARAM_ULPI 2
531 #define dwc_param_phy_type_default DWC_PHY_TYPE_PARAM_UTMI
534 * Specifies the UTMI+ Data Width. This parameter is
535 * applicable for a PHY_TYPE of UTMI+ or ULPI. (For a ULPI
536 * PHY_TYPE, this parameter indicates the data width between
537 * the MAC and the ULPI Wrapper.) Also, this parameter is
538 * applicable only if the OTG_HSPHY_WIDTH cC parameter was set
539 * to "8 and 16 bits", meaning that the core has been
540 * configured to work at either data path width.
542 * 8 or 16 bits (default 16)
544 int32_t phy_utmi_width
;
545 #define dwc_param_phy_utmi_width_default 16
548 * Specifies whether the ULPI operates at double or single
549 * data rate. This parameter is only applicable if PHY_TYPE is
552 * 0 - single data rate ULPI interface with 8 bit wide data
554 * 1 - double data rate ULPI interface with 4 bit wide data
557 int32_t phy_ulpi_ddr
;
558 #define dwc_param_phy_ulpi_ddr_default 0
561 * Specifies whether to use the internal or external supply to
562 * drive the vbus with a ULPI phy.
564 int32_t phy_ulpi_ext_vbus
;
565 #define DWC_PHY_ULPI_INTERNAL_VBUS 0
566 #define DWC_PHY_ULPI_EXTERNAL_VBUS 1
567 #define dwc_param_phy_ulpi_ext_vbus_default DWC_PHY_ULPI_INTERNAL_VBUS
570 * Specifies whether to use the I2Cinterface for full speed PHY. This
571 * parameter is only applicable if PHY_TYPE is FS.
576 #define dwc_param_i2c_enable_default 0
579 #define dwc_param_ulpi_fs_ls_default 0
582 #define dwc_param_ts_dline_default 0
585 * Specifies whether dedicated transmit FIFOs are
586 * enabled for non periodic IN endpoints in device mode
590 int32_t en_multiple_tx_fifo
;
591 #define dwc_param_en_multiple_tx_fifo_default 1
593 /** Number of 4-byte words in each of the Tx FIFOs in device
594 * mode when dynamic FIFO sizing is enabled.
595 * 4 to 768 (default 256)
597 uint32_t dev_tx_fifo_size
[MAX_TX_FIFOS
];
598 #define dwc_param_dev_tx_fifo_size_default 256
600 /** Thresholding enable flag-
601 * bit 0 - enable non-ISO Tx thresholding
602 * bit 1 - enable ISO Tx thresholding
603 * bit 2 - enable Rx thresholding
606 #define dwc_param_thr_ctl_default 0
608 /** Thresholding length for Tx
609 * FIFOs in 32 bit DWORDs
611 uint32_t tx_thr_length
;
612 #define dwc_param_tx_thr_length_default 64
614 /** Thresholding length for Rx
615 * FIFOs in 32 bit DWORDs
617 uint32_t rx_thr_length
;
618 #define dwc_param_rx_thr_length_default 64
620 /** Per Transfer Interrupt
626 #define dwc_param_pti_enable_default 0
628 /** Molti Processor Interrupt
634 #define dwc_param_mpi_enable_default 0
636 } dwc_otg_core_params_t
;
639 struct dwc_otg_core_if
;
640 typedef struct hc_xfer_info
642 struct dwc_otg_core_if
*core_if
;
648 * The <code>dwc_otg_core_if</code> structure contains information needed to manage
649 * the DWC_otg controller acting in either host or device mode. It
650 * represents the programming view of the controller as a whole.
652 typedef struct dwc_otg_core_if
654 /** Parameters that define how the core should be configured.*/
655 dwc_otg_core_params_t
*core_params
;
657 /** Core Global registers starting at offset 000h. */
658 dwc_otg_core_global_regs_t
*core_global_regs
;
660 /** Device-specific information */
661 dwc_otg_dev_if_t
*dev_if
;
662 /** Host-specific information */
663 dwc_otg_host_if_t
*host_if
;
665 /** Value from SNPSID register */
669 * Set to 1 if the core PHY interface bits in USBCFG have been
672 uint8_t phy_init_done
;
675 * SRP Success flag, set by srp success interrupt in FS I2C mode
678 uint8_t srp_timer_started
;
680 /* Common configuration information */
681 /** Power and Clock Gating Control Register */
682 volatile uint32_t *pcgcctl
;
683 #define DWC_OTG_PCGCCTL_OFFSET 0xE00
685 /** Push/pop addresses for endpoints or host channels.*/
686 uint32_t *data_fifo
[MAX_EPS_CHANNELS
];
687 #define DWC_OTG_DATA_FIFO_OFFSET 0x1000
688 #define DWC_OTG_DATA_FIFO_SIZE 0x1000
690 /** Total RAM for FIFOs (Bytes) */
691 uint16_t total_fifo_size
;
692 /** Size of Rx FIFO (Bytes) */
693 uint16_t rx_fifo_size
;
694 /** Size of Non-periodic Tx FIFO (Bytes) */
695 uint16_t nperio_tx_fifo_size
;
698 /** 1 if DMA is enabled, 0 otherwise. */
701 /** 1 if Descriptor DMA mode is enabled, 0 otherwise. */
702 uint8_t dma_desc_enable
;
704 /** 1 if PTI Enhancement mode is enabled, 0 otherwise. */
705 uint8_t pti_enh_enable
;
707 /** 1 if MPI Enhancement mode is enabled, 0 otherwise. */
708 uint8_t multiproc_int_enable
;
710 /** 1 if dedicated Tx FIFOs are enabled, 0 otherwise. */
711 uint8_t en_multiple_tx_fifo
;
713 /** Set to 1 if multiple packets of a high-bandwidth transfer is in
714 * process of being queued */
715 uint8_t queuing_high_bandwidth
;
717 /** Hardware Configuration -- stored here for convenience.*/
718 hwcfg1_data_t hwcfg1
;
719 hwcfg2_data_t hwcfg2
;
720 hwcfg3_data_t hwcfg3
;
721 hwcfg4_data_t hwcfg4
;
723 /** Host and Device Configuration -- stored here for convenience.*/
727 /** The operational State, during transations
728 * (a_host>>a_peripherial and b_device=>b_host) this may not
729 * match the core but allows the software to determine
735 * Set to 1 if the HCD needs to be restarted on a session request
736 * interrupt. This is required if no connector ID status change has
737 * occurred since the HCD was last disconnected.
739 uint8_t restart_hcd_on_session_req
;
742 /** A-Device is a_host */
744 /** A-Device is a_suspend */
745 #define A_SUSPEND (2)
746 /** A-Device is a_peripherial */
747 #define A_PERIPHERAL (3)
748 /** B-Device is operating as a Peripheral. */
749 #define B_PERIPHERAL (4)
750 /** B-Device is operating as a Host. */
754 struct dwc_otg_cil_callbacks
*hcd_cb
;
756 struct dwc_otg_cil_callbacks
*pcd_cb
;
758 /** Device mode Periodic Tx FIFO Mask */
760 /** Device mode Periodic Tx FIFO Mask */
763 /** Workqueue object used for handling several interrupts */
764 struct workqueue_struct
*wq_otg
;
766 /** Work object used for handling "Connector ID Status Change" Interrupt */
767 struct work_struct w_conn_id
;
769 /** Work object used for handling "Wakeup Detected" Interrupt */
770 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
771 struct work_struct w_wkp
;
773 struct delayed_work w_wkp
;
777 uint32_t start_hcchar_val
[MAX_EPS_CHANNELS
];
779 hc_xfer_info_t hc_xfer_info
[MAX_EPS_CHANNELS
];
780 struct timer_list 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
;
793 /*We must clear S3C24XX_EINTPEND external interrupt register
794 * because after clearing in this register trigerred IRQ from
795 * H/W core in kernel interrupt can be occured again before OTG
796 * handlers clear all IRQ sources of Core registers because of
797 * timing latencies and Low Level IRQ Type.
800 #ifdef CONFIG_MACH_IPMATE
801 #define S3C2410X_CLEAR_EINTPEND() \
803 if (!dwc_otg_read_core_intr(core_if)) { \
804 __raw_writel(1UL << 11,S3C24XX_EINTPEND); \
808 #define S3C2410X_CLEAR_EINTPEND() do { } while (0)
812 * The following functions are functions for works
813 * using during handling some interrupts
815 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
817 extern void w_conn_id_status_change(void *p
);
818 extern void w_wakeup_detected(void *p
);
822 extern void w_conn_id_status_change(struct work_struct
*p
);
823 extern void w_wakeup_detected(struct work_struct
*p
);
829 * The following functions support initialization of the CIL driver component
830 * and the DWC_otg controller.
832 extern dwc_otg_core_if_t
*dwc_otg_cil_init(const uint32_t *_reg_base_addr
,
833 dwc_otg_core_params_t
*_core_params
);
834 extern void dwc_otg_cil_remove(dwc_otg_core_if_t
*_core_if
);
835 extern void dwc_otg_core_init(dwc_otg_core_if_t
*_core_if
);
836 extern void dwc_otg_core_host_init(dwc_otg_core_if_t
*_core_if
);
837 extern void dwc_otg_core_dev_init(dwc_otg_core_if_t
*_core_if
);
838 extern void dwc_otg_enable_global_interrupts( dwc_otg_core_if_t
*_core_if
);
839 extern void dwc_otg_disable_global_interrupts( dwc_otg_core_if_t
*_core_if
);
841 /** @name Device CIL Functions
842 * The following functions support managing the DWC_otg controller in device
846 extern void dwc_otg_wakeup(dwc_otg_core_if_t
*_core_if
);
847 extern void dwc_otg_read_setup_packet (dwc_otg_core_if_t
*_core_if
, uint32_t *_dest
);
848 extern uint32_t dwc_otg_get_frame_number(dwc_otg_core_if_t
*_core_if
);
849 extern void dwc_otg_ep0_activate(dwc_otg_core_if_t
*_core_if
, dwc_ep_t
*_ep
);
850 extern void dwc_otg_ep_activate(dwc_otg_core_if_t
*_core_if
, dwc_ep_t
*_ep
);
851 extern void dwc_otg_ep_deactivate(dwc_otg_core_if_t
*_core_if
, dwc_ep_t
*_ep
);
852 extern void dwc_otg_ep_start_transfer(dwc_otg_core_if_t
*_core_if
, dwc_ep_t
*_ep
);
853 extern void dwc_otg_ep_start_zl_transfer(dwc_otg_core_if_t
*_core_if
, dwc_ep_t
*_ep
);
854 extern void dwc_otg_ep0_start_transfer(dwc_otg_core_if_t
*_core_if
, dwc_ep_t
*_ep
);
855 extern void dwc_otg_ep0_continue_transfer(dwc_otg_core_if_t
*_core_if
, dwc_ep_t
*_ep
);
856 extern void dwc_otg_ep_write_packet(dwc_otg_core_if_t
*_core_if
, dwc_ep_t
*_ep
, int _dma
);
857 extern void dwc_otg_ep_set_stall(dwc_otg_core_if_t
*_core_if
, dwc_ep_t
*_ep
);
858 extern void dwc_otg_ep_clear_stall(dwc_otg_core_if_t
*_core_if
, dwc_ep_t
*_ep
);
859 extern void dwc_otg_enable_device_interrupts(dwc_otg_core_if_t
*_core_if
);
860 extern void dwc_otg_dump_dev_registers(dwc_otg_core_if_t
*_core_if
);
861 extern void dwc_otg_dump_spram(dwc_otg_core_if_t
*_core_if
);
863 extern void dwc_otg_iso_ep_start_frm_transfer(dwc_otg_core_if_t
*core_if
, dwc_ep_t
*ep
);
864 extern void dwc_otg_iso_ep_start_buf_transfer(dwc_otg_core_if_t
*core_if
, dwc_ep_t
*ep
);
868 /** @name Host CIL Functions
869 * The following functions support managing the DWC_otg controller in host
873 extern void dwc_otg_hc_init(dwc_otg_core_if_t
*_core_if
, dwc_hc_t
*_hc
);
874 extern void dwc_otg_hc_halt(dwc_otg_core_if_t
*_core_if
,
876 dwc_otg_halt_status_e _halt_status
);
877 extern void dwc_otg_hc_cleanup(dwc_otg_core_if_t
*_core_if
, dwc_hc_t
*_hc
);
878 extern void dwc_otg_hc_start_transfer(dwc_otg_core_if_t
*_core_if
, dwc_hc_t
*_hc
);
879 extern int dwc_otg_hc_continue_transfer(dwc_otg_core_if_t
*_core_if
, dwc_hc_t
*_hc
);
880 extern void dwc_otg_hc_do_ping(dwc_otg_core_if_t
*_core_if
, dwc_hc_t
*_hc
);
881 extern void dwc_otg_hc_write_packet(dwc_otg_core_if_t
*_core_if
, dwc_hc_t
*_hc
);
882 extern void dwc_otg_enable_host_interrupts(dwc_otg_core_if_t
*_core_if
);
883 extern void dwc_otg_disable_host_interrupts(dwc_otg_core_if_t
*_core_if
);
886 * This function Reads HPRT0 in preparation to modify. It keeps the
887 * WC bits 0 so that if they are read as 1, they won't clear when you
890 static inline uint32_t dwc_otg_read_hprt0(dwc_otg_core_if_t
*_core_if
)
893 hprt0
.d32
= dwc_read_reg32(_core_if
->host_if
->hprt0
);
895 hprt0
.b
.prtconndet
= 0;
896 hprt0
.b
.prtenchng
= 0;
897 hprt0
.b
.prtovrcurrchng
= 0;
901 extern void dwc_otg_dump_host_registers(dwc_otg_core_if_t
*_core_if
);
904 /** @name Common CIL Functions
905 * The following functions support managing the DWC_otg controller in either
906 * device or host mode.
910 extern void dwc_otg_read_packet(dwc_otg_core_if_t
*core_if
,
914 extern void dwc_otg_dump_global_registers(dwc_otg_core_if_t
*_core_if
);
916 extern void dwc_otg_flush_tx_fifo( dwc_otg_core_if_t
*_core_if
,
918 extern void dwc_otg_flush_rx_fifo( dwc_otg_core_if_t
*_core_if
);
919 extern void dwc_otg_core_reset( dwc_otg_core_if_t
*_core_if
);
921 extern dwc_otg_dma_desc_t
* dwc_otg_ep_alloc_desc_chain(uint32_t * dma_desc_addr
, uint32_t count
);
922 extern void dwc_otg_ep_free_desc_chain(dwc_otg_dma_desc_t
* desc_addr
, uint32_t dma_desc_addr
, uint32_t count
);
925 * This function returns the Core Interrupt register.
927 static inline uint32_t dwc_otg_read_core_intr(dwc_otg_core_if_t
*_core_if
)
929 return (dwc_read_reg32(&_core_if
->core_global_regs
->gintsts
) &
930 dwc_read_reg32(&_core_if
->core_global_regs
->gintmsk
));
934 * This function returns the OTG Interrupt register.
936 static inline uint32_t dwc_otg_read_otg_intr (dwc_otg_core_if_t
*_core_if
)
938 return (dwc_read_reg32 (&_core_if
->core_global_regs
->gotgint
));
942 * This function reads the Device All Endpoints Interrupt register and
943 * returns the IN endpoint interrupt bits.
945 static inline uint32_t dwc_otg_read_dev_all_in_ep_intr(dwc_otg_core_if_t
*core_if
)
949 if(core_if
->multiproc_int_enable
) {
950 v
= dwc_read_reg32(&core_if
->dev_if
->dev_global_regs
->deachint
) &
951 dwc_read_reg32(&core_if
->dev_if
->dev_global_regs
->deachintmsk
);
953 v
= dwc_read_reg32(&core_if
->dev_if
->dev_global_regs
->daint
) &
954 dwc_read_reg32(&core_if
->dev_if
->dev_global_regs
->daintmsk
);
961 * This function reads the Device All Endpoints Interrupt register and
962 * returns the OUT endpoint interrupt bits.
964 static inline uint32_t dwc_otg_read_dev_all_out_ep_intr(dwc_otg_core_if_t
*core_if
)
968 if(core_if
->multiproc_int_enable
) {
969 v
= dwc_read_reg32(&core_if
->dev_if
->dev_global_regs
->deachint
) &
970 dwc_read_reg32(&core_if
->dev_if
->dev_global_regs
->deachintmsk
);
972 v
= dwc_read_reg32(&core_if
->dev_if
->dev_global_regs
->daint
) &
973 dwc_read_reg32(&core_if
->dev_if
->dev_global_regs
->daintmsk
);
976 return ((v
& 0xffff0000) >> 16);
980 * This function returns the Device IN EP Interrupt register
982 static inline uint32_t dwc_otg_read_dev_in_ep_intr(dwc_otg_core_if_t
*core_if
,
985 dwc_otg_dev_if_t
*dev_if
= core_if
->dev_if
;
986 uint32_t v
, msk
, emp
;
988 if(core_if
->multiproc_int_enable
) {
989 msk
= dwc_read_reg32(&dev_if
->dev_global_regs
->diepeachintmsk
[ep
->num
]);
990 emp
= dwc_read_reg32(&dev_if
->dev_global_regs
->dtknqr4_fifoemptymsk
);
991 msk
|= ((emp
>> ep
->num
) & 0x1) << 7;
992 v
= dwc_read_reg32(&dev_if
->in_ep_regs
[ep
->num
]->diepint
) & msk
;
994 msk
= dwc_read_reg32(&dev_if
->dev_global_regs
->diepmsk
);
995 emp
= dwc_read_reg32(&dev_if
->dev_global_regs
->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
*_core_if
,
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
) {
1014 msk
.d32
= dwc_read_reg32(&dev_if
->dev_global_regs
->doepeachintmsk
[_ep
->num
]);
1015 if(_core_if
->pti_enh_enable
) {
1016 msk
.b
.pktdrpsts
= 1;
1018 v
= dwc_read_reg32( &dev_if
->out_ep_regs
[_ep
->num
]->doepint
) & msk
.d32
;
1020 msk
.d32
= dwc_read_reg32(&dev_if
->dev_global_regs
->doepmsk
);
1021 if(_core_if
->pti_enh_enable
) {
1022 msk
.b
.pktdrpsts
= 1;
1024 v
= dwc_read_reg32( &dev_if
->out_ep_regs
[_ep
->num
]->doepint
) & msk
.d32
;
1030 * This function returns the Host All Channel Interrupt register
1032 static inline uint32_t dwc_otg_read_host_all_channels_intr (dwc_otg_core_if_t
*_core_if
)
1034 return (dwc_read_reg32 (&_core_if
->host_if
->host_global_regs
->haint
));
1037 static inline uint32_t dwc_otg_read_host_channel_intr (dwc_otg_core_if_t
*_core_if
, dwc_hc_t
*_hc
)
1039 return (dwc_read_reg32 (&_core_if
->host_if
->hc_regs
[_hc
->hc_num
]->hcint
));
1044 * This function returns the mode of the operation, host or device.
1046 * @return 0 - Device Mode, 1 - Host Mode
1048 static inline uint32_t dwc_otg_mode(dwc_otg_core_if_t
*_core_if
)
1050 return (dwc_read_reg32( &_core_if
->core_global_regs
->gintsts
) & 0x1);
1053 static inline uint8_t dwc_otg_is_device_mode(dwc_otg_core_if_t
*_core_if
)
1055 return (dwc_otg_mode(_core_if
) != DWC_HOST_MODE
);
1057 static inline uint8_t dwc_otg_is_host_mode(dwc_otg_core_if_t
*_core_if
)
1059 return (dwc_otg_mode(_core_if
) == DWC_HOST_MODE
);
1062 extern int32_t dwc_otg_handle_common_intr( dwc_otg_core_if_t
*_core_if
);
1068 * DWC_otg CIL callback structure. This structure allows the HCD and
1069 * PCD to register functions used for starting and stopping the PCD
1070 * and HCD for role change on for a DRD.
1072 typedef struct dwc_otg_cil_callbacks
1074 /** Start function for role change */
1075 int (*start
) (void *_p
);
1076 /** Stop Function for role change */
1077 int (*stop
) (void *_p
);
1078 /** Disconnect Function for role change */
1079 int (*disconnect
) (void *_p
);
1080 /** Resume/Remote wakeup Function */
1081 int (*resume_wakeup
) (void *_p
);
1082 /** Suspend function */
1083 int (*suspend
) (void *_p
);
1084 /** Session Start (SRP) */
1085 int (*session_start
) (void *_p
);
1086 /** Pointer passed to start() and stop() */
1088 } dwc_otg_cil_callbacks_t
;
1090 extern void dwc_otg_cil_register_pcd_callbacks( dwc_otg_core_if_t
*_core_if
,
1091 dwc_otg_cil_callbacks_t
*_cb
,
1093 extern void dwc_otg_cil_register_hcd_callbacks( dwc_otg_core_if_t
*_core_if
,
1094 dwc_otg_cil_callbacks_t
*_cb
,