blob: 140817593de0931d39adbf127e2d773fbf0fe225 [file] [log] [blame]
yuezonghe824eb0c2024-06-27 02:32:26 -07001/* ==========================================================================
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 "type.h"
38#include "dwc_otg_regs.h"
39
40#include "dwc_otg_core_if.h"
41
42//ÊÕ·¢»Øµ÷º¯ÊýµÄÔ­ÐÍ
43typedef void (*F_USB_CB)(WORD32 dwPara, WORD32 dwResult, WORD32 dwLen, WORD32 dwWantLen);
44
45
46/** Macros defined for DWC OTG HW Release version */
47
48#define OTG_CORE_REV_2_60a 0x4F54260A
49#define OTG_CORE_REV_2_94a 0x4F54294A
50/**
51 * The <code>dwc_ep</code> structure represents the state of a single
52 * endpoint when acting in device mode. It contains the data items
53 * needed for an endpoint to be activated and transfer packets.
54 */
55#define DWC_OTG_EP_TYPE_ISOC 1
56#define DWC_OTG_EP_TYPE_BULK 2
57#define DWC_OTG_EP_TYPE_INTR 3
58
59typedef struct dwc_ep
60{
61 /** EP number used for register address lookup */
62 uint8_t num;
63 /** EP direction 0 = OUT */
64 unsigned is_in;//:1;
65 /** EP active. */
66 unsigned active;//:1;
67 /**
68 * Periodic Tx FIFO # for IN EPs For INTR EP set to 0 to use non-periodic
69 * Tx FIFO. If dedicated Tx FIFOs are enabled Tx FIFO # FOR IN EPs*/
70 unsigned tx_fifo_num;//:4;
71 /** EP type: 0 - Control, 1 - ISOC, 2 - BULK, 3 - INTR */
72 unsigned type;//:2;
73 /** DATA start PID for INTR and BULK EP */
74 unsigned data_pid_start;//:1;
75 /** Frame (even/odd) for ISOC EP */
76 unsigned even_odd_frame;//:1;
77 /** Max Packet bytes */
78 unsigned maxpacket;//:11;
79
80 /** Max Transfer size */
81 uint32_t maxxfer;
82
83 F_USB_CB fnUsbCb;
84
85 void *pPara;
86
87 uint8_t *start_xfer_buff;
88 /** pointer to the transfer buffer */
89 uint8_t *xfer_buff;
90 /** Number of bytes to transfer */
91 unsigned xfer_len;//:19;
92 /** Number of bytes transferred. */
93 unsigned xfer_count;//:19;
94 /** Sent ZLP */
95 unsigned sent_zlp;//:1;
96 /** Total len for control transfer */
97 unsigned total_len;//:19;
98
99 /** stall clear flag */
100 unsigned stall_clear_flag;//:1;
101
102 /** SETUP pkt cnt rollover flag for EP0 out*/
103 unsigned stp_rollover;
104
105} dwc_ep_t;
106
107/**
108 * The following parameters may be specified when starting the module. These
109 * parameters define how the DWC_otg controller should be configured.
110 */
111typedef struct dwc_otg_core_params
112{
113 /**
114 * Specifies the OTG capabilities. The driver will automatically
115 * detect the value for this parameter if none is specified.
116 * 0 - HNP and SRP capable (default)
117 * 1 - SRP Only capable
118 * 2 - No HNP/SRP capable
119 */
120 int32_t otg_cap;
121
122
123 /**
124 * Specifies the maximum speed of operation in host and device mode.
125 * The actual speed depends on the speed of the attached device and
126 * the value of phy_type. The actual speed depends on the speed of the
127 * attached device.
128 * 0 - High Speed (default)
129 * 1 - Full Speed
130 */
131 int32_t speed;
132
133 /**
134 * Specifies the type of PHY interface to use. By default, the driver
135 * will automatically detect the phy_type.
136 *
137 * 0 - Full Speed PHY
138 * 1 - UTMI+ (default)
139 * 2 - ULPI
140 */
141 int32_t phy_type;
142
143 /**
144 * Specifies the UTMI+ Data Width. This parameter is
145 * applicable for a PHY_TYPE of UTMI+ or ULPI. (For a ULPI
146 * PHY_TYPE, this parameter indicates the data width between
147 * the MAC and the ULPI Wrapper.) Also, this parameter is
148 * applicable only if the OTG_HSPHY_WIDTH cC parameter was set
149 * to "8 and 16 bits", meaning that the core has been
150 * configured to work at either data path width.
151 *
152 * 8 or 16 bits (default 16)
153 */
154 int32_t phy_utmi_width;
155
156 /**
157 * Specifies whether the ULPI operates at double or single
158 * data rate. This parameter is only applicable if PHY_TYPE is
159 * ULPI.
160 *
161 * 0 - single data rate ULPI interface with 8 bit wide data
162 * bus (default)
163 * 1 - double data rate ULPI interface with 4 bit wide data
164 * bus
165 */
166 int32_t phy_ulpi_ddr;
167
168 /**
169 * Specifies whether to use the internal or external supply to
170 * drive the vbus with a ULPI phy.
171 */
172 int32_t phy_ulpi_ext_vbus;
173
174 int32_t ulpi_fs_ls;
175
176 int32_t ts_dline;
177
178 /**
179 * Specifies whether dedicated transmit FIFOs are
180 * enabled for non periodic IN endpoints in device mode
181 * 0 - No
182 * 1 - Yes
183 */
184 int32_t en_multiple_tx_fifo;
185
186 /** Number of 4-byte words in each of the Tx FIFOs in device
187 * mode when dynamic FIFO sizing is enabled.
188 * 4 to 768 (default 256)
189 */
190 uint32_t dev_tx_fifo_size[MAX_TX_FIFOS];
191
192 /** Thresholding enable flag-
193 * bit 0 - enable non-ISO Tx thresholding
194 * bit 1 - enable ISO Tx thresholding
195 * bit 2 - enable Rx thresholding
196 */
197 //uint32_t thr_ctl;
198
199 /** Thresholding length for Tx
200 * FIFOs in 32 bit DWORDs
201 */
202 //uint32_t tx_thr_length;
203
204 /** Thresholding length for Rx
205 * FIFOs in 32 bit DWORDs
206 */
207 //uint32_t rx_thr_length;
208
209
210 /** Per Transfer Interrupt
211 * mode enable flag
212 * 1 - Enabled
213 * 0 - Disabled
214 */
215 int32_t pti_enable;
216
217
218 /** HFIR Reload Control
219 * 0 - The HFIR cannot be reloaded dynamically.
220 * 1 - Allow dynamic reloading of the HFIR register during runtime.
221 */
222 //int32_t reload_ctl;
223 /** DCFG: Enable device Out NAK
224 * 0 - The core does not set NAK after Bulk Out transfer complete.
225 * 1 - The core sets NAK after Bulk OUT transfer complete.
226 */
227 int32_t dev_out_nak;
228
229
230 /** OTG revision supported
231 * 0 - OTG 1.3 revision
232 * 1 - OTG 2.0 revision
233 */
234 int32_t otg_ver;
235
236} dwc_otg_core_params_t;
237/**
238 * The <code>dwc_otg_core_if</code> structure contains information needed to manage
239 * the DWC_otg controller acting in either host or device mode. It
240 * represents the programming view of the controller as a whole.
241 */
242#define DWC_OTG_PCGCCTL_OFFSET 0xE00
243#define DWC_OTG_DATA_FIFO_OFFSET 0x1000
244#define DWC_OTG_DATA_FIFO_SIZE 0x1000
245#define A_HOST (1)
246#define A_SUSPEND (2)
247#define A_PERIPHERAL (3)
248#define B_PERIPHERAL (4)
249#define B_HOST (5)
250
251struct dwc_otg_core_if
252{
253 dwc_otg_core_params_t *core_params;
254
255 dwc_otg_core_global_regs_t *core_global_regs;
256
257 dwc_otg_dev_if_t *dev_if;
258 uint8_t phy_init_done;
259
260
261 volatile uint32_t *pcgcctl;
262
263 uint32_t *data_fifo[MAX_EPS_CHANNELS];
264
265 uint16_t total_fifo_size;
266 uint16_t rx_fifo_size;
267 uint16_t nperio_tx_fifo_size;
268
269 uint8_t pti_enh_enable;
270
271 uint8_t multiproc_int_enable;
272
273 uint8_t en_multiple_tx_fifo;
274
275 hwcfg1_data_t hwcfg1;
276 hwcfg2_data_t hwcfg2;
277 hwcfg3_data_t hwcfg3;
278 hwcfg4_data_t hwcfg4;
279 fifosize_data_t hptxfsiz;
280 dcfg_data_t dcfg;
281
282 uint32_t otg_ver;
283
284};
285
286extern void dwc_otg_core_dev_init(dwc_otg_core_if_t * _core_if);
287
288extern void dwc_otg_read_setup_packet(dwc_otg_core_if_t * _core_if,
289 uint32_t * _dest);
290extern void dwc_otg_ep0_activate(dwc_otg_core_if_t * _core_if, dwc_ep_t * _ep);
291extern void dwc_otg_ep_activate(dwc_otg_core_if_t * _core_if, dwc_ep_t * _ep);
292extern void dwc_otg_ep_start_transfer(dwc_otg_core_if_t * _core_if,
293 dwc_ep_t * _ep);
294extern void dwc_otg_ep_start_zl_transfer(dwc_otg_core_if_t * _core_if,
295 dwc_ep_t * _ep);
296extern void dwc_otg_ep0_start_transfer(dwc_otg_core_if_t * _core_if,
297 dwc_ep_t * _ep);
298extern void dwc_otg_ep0_continue_transfer(dwc_otg_core_if_t * _core_if,
299 dwc_ep_t * _ep);
300extern void dwc_otg_ep_write_packet(dwc_otg_core_if_t * _core_if,
301 dwc_ep_t * _ep, int _dma);
302extern void dwc_otg_ep_set_stall(dwc_otg_core_if_t * _core_if, dwc_ep_t * _ep);
303extern void dwc_otg_ep_clear_stall(dwc_otg_core_if_t * _core_if,
304 dwc_ep_t * _ep);
305extern void dwc_otg_enable_device_interrupts(dwc_otg_core_if_t * _core_if);
306
307void DWC_MODIFY_REG32(uint32_t volatile *reg, uint32_t clear_mask, uint32_t set_mask);
308
309
310extern void dwc_otg_read_packet(dwc_otg_core_if_t * core_if,
311 uint8_t * dest, uint16_t bytes);
312
313extern void dwc_otg_flush_tx_fifo(dwc_otg_core_if_t * _core_if, const int _num);
314extern void dwc_otg_flush_rx_fifo(dwc_otg_core_if_t * _core_if);
315extern void dwc_otg_core_reset(dwc_otg_core_if_t * _core_if);
316
317/**
318 * This function returns the Core Interrupt register.
319 */
320static uint32_t dwc_otg_read_core_intr(dwc_otg_core_if_t * core_if)
321{
322 return (DWC_READ_REG32(&core_if->core_global_regs->gintsts) &
323 DWC_READ_REG32(&core_if->core_global_regs->gintmsk));
324}
325
326
327/**
328 * This function reads the Device All Endpoints Interrupt register and
329 * returns the IN endpoint interrupt bits.
330 */
331static uint32_t dwc_otg_read_dev_all_in_ep_intr(dwc_otg_core_if_t *
332 core_if)
333{
334
335 uint32_t v;
336 {
337 v = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->daint) &
338 DWC_READ_REG32(&core_if->dev_if->dev_global_regs->daintmsk);
339 }
340 return (v & 0xffff);
341}
342
343/**
344 * This function reads the Device All Endpoints Interrupt register and
345 * returns the OUT endpoint interrupt bits.
346 */
347static uint32_t dwc_otg_read_dev_all_out_ep_intr(dwc_otg_core_if_t *
348 core_if)
349{
350 uint32_t v;
351
352 {
353 v = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->daint) &
354 DWC_READ_REG32(&core_if->dev_if->dev_global_regs->daintmsk);
355 }
356
357 return ((v & 0xffff0000) >> 16);
358}
359
360/**
361 * This function returns the Device IN EP Interrupt register
362 */
363static uint32_t dwc_otg_read_dev_in_ep_intr(dwc_otg_core_if_t * core_if,
364 dwc_ep_t * ep)
365{
366 dwc_otg_dev_if_t *dev_if = core_if->dev_if;
367 uint32_t v, msk, emp;
368
369 {
370 msk = DWC_READ_REG32(&dev_if->dev_global_regs->diepmsk);
371 emp = DWC_READ_REG32(&dev_if->dev_global_regs->dtknqr4_fifoemptymsk);
372 msk |= ((emp >> ep->num) & 0x1) << 7;
373 v = DWC_READ_REG32(&dev_if->in_ep_regs[ep->num]->diepint) & msk;
374 }
375
376 return v;
377}
378
379/**
380 * This function returns the Device OUT EP Interrupt register
381 */
382static uint32_t dwc_otg_read_dev_out_ep_intr(dwc_otg_core_if_t *_core_if, dwc_ep_t * _ep)
383{
384 dwc_otg_dev_if_t *dev_if = _core_if->dev_if;
385 uint32_t v;
386 doepmsk_data_t msk;
387 msk.d32 = 0;
388 {
389 msk.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->doepmsk);
390 if (_core_if->pti_enh_enable)
391 {
392 msk.b.pktdrpsts = 1;
393 }
394 v = DWC_READ_REG32(&dev_if->out_ep_regs[_ep->num]->doepint) & msk.d32;
395 }
396 return v;
397}
398
399static uint32_t dwc_otg_mode(dwc_otg_core_if_t * _core_if)
400{
401 return (DWC_READ_REG32(&_core_if->core_global_regs->gintsts) & 0x1);
402}
403
404#endif