Root/package/platform/lantiq/ltq-hcd/src/ifxusb_cif.h

1/*****************************************************************************
2 ** FILE NAME : ifxusb_cif.h
3 ** PROJECT : IFX USB sub-system V3
4 ** MODULES : IFX USB sub-system Host and Device driver
5 ** SRC VERSION : 3.2
6 ** DATE : 1/Jan/2011
7 ** AUTHOR : Chen, Howard
8 ** DESCRIPTION : The Core Interface provides basic services for accessing and
9 ** managing the IFX USB hardware. These services are used by both the
10 ** Host Controller Driver and the Peripheral Controller Driver.
11 ** FUNCTIONS :
12 ** COMPILER : gcc
13 ** REFERENCE : Synopsys DWC-OTG Driver 2.7
14 ** COPYRIGHT : Copyright (c) 2010
15 ** LANTIQ DEUTSCHLAND GMBH,
16 ** Am Campeon 3, 85579 Neubiberg, Germany
17 **
18 ** This program is free software; you can redistribute it and/or modify
19 ** it under the terms of the GNU General Public License as published by
20 ** the Free Software Foundation; either version 2 of the License, or
21 ** (at your option) any later version.
22 **
23 ** Version Control Section **
24 ** $Author$
25 ** $Date$
26 ** $Revisions$
27 ** $Log$ Revision history
28 *****************************************************************************/
29
30/*
31 * This file contains code fragments from Synopsys HS OTG Linux Software Driver.
32 * For this code the following notice is applicable:
33 *
34 * ==========================================================================
35 *
36 * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
37 * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
38 * otherwise expressly agreed to in writing between Synopsys and you.
39 *
40 * The Software IS NOT an item of Licensed Software or Licensed Product under
41 * any End User Software License Agreement or Agreement for Licensed Product
42 * with Synopsys or any supplement thereto. You are permitted to use and
43 * redistribute this Software in source and binary forms, with or without
44 * modification, provided that redistributions of source code must retain this
45 * notice. You may not view, use, disclose, copy or distribute this file or
46 * any information contained herein except pursuant to this license grant from
47 * Synopsys. If you do not agree with this notice, including the disclaimer
48 * below, then you are not authorized to use the Software.
49 *
50 * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
51 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
52 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
53 * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
54 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
55 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
56 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
57 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
58 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
59 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
60 * DAMAGE.
61 * ========================================================================== */
62
63/*!
64 \defgroup IFXUSB_DRIVER_V3 IFX USB SS Project
65 \brief IFX USB subsystem V3.x
66 */
67
68/*!
69 \defgroup IFXUSB_CIF Core Interface APIs
70 \ingroup IFXUSB_DRIVER_V3
71 \brief The Core Interface provides basic services for accessing and
72        managing the IFXUSB hardware. These services are used by both the
73        Host Controller Driver and the Peripheral Controller Driver.
74 */
75
76
77/*!
78 \file ifxusb_cif.h
79 \ingroup IFXUSB_DRIVER_V3
80 \brief This file contains the interface to the IFX USB Core.
81 */
82
83#if !defined(__IFXUSB_CIF_H__)
84#define __IFXUSB_CIF_H__
85
86#include <linux/workqueue.h>
87
88#include <linux/version.h>
89#include <asm/param.h>
90
91#include "ifxusb_plat.h"
92#include "ifxusb_regs.h"
93
94#ifdef __DEBUG__
95    #include "linux/timer.h"
96#endif
97
98///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
99
100#define IFXUSB_PARAM_SPEED_HIGH 0 /*!< Build stage parameter: High Speed */
101#define IFXUSB_PARAM_SPEED_FULL 1 /*!< Build stage parameter: Full Speed */
102
103#define IFXUSB_EP_SPEED_LOW 0 /*!< Run-Time Status: High Speed */
104#define IFXUSB_EP_SPEED_FULL 1 /*!< Run-Time Status: Full Speed */
105#define IFXUSB_EP_SPEED_HIGH 2 /*!< Run-Time Status: Low Speed */
106
107#define IFXUSB_EP_TYPE_CTRL 0 /*!< Run-Time Status: CTRL */
108#define IFXUSB_EP_TYPE_ISOC 1 /*!< Run-Time Status: ISOC */
109#define IFXUSB_EP_TYPE_BULK 2 /*!< Run-Time Status: BULK */
110#define IFXUSB_EP_TYPE_INTR 3 /*!< Run-Time Status: INTR */
111
112#define IFXUSB_HC_PID_DATA0 0 /*!< Run-Time Data Toggle: Data 0 */
113#define IFXUSB_HC_PID_DATA2 1 /*!< Run-Time Data Toggle: Data 2 */
114#define IFXUSB_HC_PID_DATA1 2 /*!< Run-Time Data Toggle: Data 1 */
115#define IFXUSB_HC_PID_MDATA 3 /*!< Run-Time Data Toggle: MData */
116#define IFXUSB_HC_PID_SETUP 3 /*!< Run-Time Data Toggle: Setup */
117
118
119/*!
120 \addtogroup IFXUSB_CIF
121 */
122/*@{*/
123
124/*! typedef ifxusb_params_t
125 \brief IFXUSB Parameters structure.
126       This structure is used for both importing from insmod stage and run-time storage.
127       These parameters define how the IFXUSB controller should be configured.
128 */
129typedef struct ifxusb_params
130{
131    int32_t dma_burst_size; /*!< The DMA Burst size (applicable only for Internal DMA
132                                  Mode). 0(for single), 1(incr), 4(incr4), 8(incr8) 16(incr16)
133                              */
134                             /* Translate this to GAHBCFG values */
135    int32_t speed; /*!< Specifies the maximum speed of operation in host and device mode.
136                                  The actual speed depends on the speed of the attached device and
137                                  the value of phy_type. The actual speed depends on the speed of the
138                                  attached device.
139                                  0 - High Speed (default)
140                                  1 - Full Speed
141                              */
142
143    int32_t data_fifo_size; /*!< Total number of dwords in the data FIFO memory. This
144                                   memory includes the Rx FIFO, non-periodic Tx FIFO, and periodic
145                                   Tx FIFOs.
146                                   32 to 32768
147                               */
148    #ifdef __IS_DEVICE__
149        int32_t rx_fifo_size; /*!< Number of dwords in the Rx FIFO in device mode.
150                                   16 to 32768
151                               */
152
153
154        int32_t tx_fifo_size[MAX_EPS_CHANNELS]; /*!< Number of dwords in each of the Tx FIFOs in device mode.
155                                                     4 to 768
156                                                 */
157        #ifdef __DED_FIFO__
158            int32_t thr_ctl; /*!< Threshold control on/off */
159            int32_t tx_thr_length; /*!< Threshold length for Tx */
160            int32_t rx_thr_length; /*!< Threshold length for Rx*/
161        #endif
162    #else //__IS_HOST__
163        int32_t host_channels; /*!< The number of host channel registers to use.
164                                         1 to 16
165                                     */
166
167        int32_t rx_fifo_size; /*!< Number of dwords in the Rx FIFO in host mode.
168                                        16 to 32768
169                                     */
170
171        int32_t nperio_tx_fifo_size;/*!< Number of dwords in the non-periodic Tx FIFO in host mode.
172                                         16 to 32768
173                                     */
174
175        int32_t perio_tx_fifo_size; /*!< Number of dwords in the host periodic Tx FIFO.
176                                         16 to 32768
177                                     */
178    #endif //__IS_HOST__
179
180    int32_t max_transfer_size; /*!< The maximum transfer size supported in bytes.
181                                         2047 to 65,535
182                                     */
183
184    int32_t max_packet_count; /*!< The maximum number of packets in a transfer.
185                                         15 to 511 (default 511)
186                                     */
187    int32_t phy_utmi_width; /*!< Specifies the UTMI+ Data Width.
188                                         8 or 16 bits (default 16)
189                                     */
190
191    int32_t turn_around_time_hs; /*!< Specifies the Turn-Around time at HS*/
192    int32_t turn_around_time_fs; /*!< Specifies the Turn-Around time at FS*/
193
194    int32_t timeout_cal_hs; /*!< Specifies the Timeout_Calibration at HS*/
195    int32_t timeout_cal_fs; /*!< Specifies the Timeout_Calibration at FS*/
196} ifxusb_params_t;
197
198///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
199///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
200
201/*! typedef ifxusb_core_if_t
202 \brief The ifx_core_if structure contains information needed to manage
203       the IFX USB controller acting in either host or device mode. It
204       represents the programming view of the controller as a whole.
205 */
206typedef struct ifxusb_core_if
207{
208    ifxusb_params_t params; /*!< Run-time Parameters */
209
210    uint8_t core_no; /*!< core number (used as id when multi-core case */
211    char *core_name; /*!< core name used for registration and informative purpose*/
212    int irq; /*!< irq number this core is hooked */
213
214    /*****************************************************************
215     * Structures and pointers to physical register interface.
216     *****************************************************************/
217    /** Core Global registers starting at offset 000h. */
218    ifxusb_core_global_regs_t *core_global_regs; /*!< pointer to Core Global Registers, offset at 000h */
219
220    /** Host-specific registers */
221    #ifdef __IS_HOST__
222        /** Host Global Registers starting at offset 400h.*/
223        ifxusb_host_global_regs_t *host_global_regs; /*!< pointer to Host Global Registers, offset at 400h */
224            #define IFXUSB_HOST_GLOBAL_REG_OFFSET 0x400
225        /** Host Port 0 Control and Status Register */
226        volatile uint32_t *hprt0; /*!< pointer to HPRT0 Registers, offset at 440h */
227            #define IFXUSB_HOST_PORT_REGS_OFFSET 0x440
228        /** Host Channel Specific Registers at offsets 500h-5FCh. */
229        ifxusb_hc_regs_t *hc_regs[MAX_EPS_CHANNELS]; /*!< pointer to Host-Channel n Registers, offset at 500h */
230            #define IFXUSB_HOST_CHAN_REGS_OFFSET 0x500
231            #define IFXUSB_CHAN_REGS_OFFSET 0x20
232    #endif
233
234    /** Device-specific registers */
235    #ifdef __IS_DEVICE__
236        /** Device Global Registers starting at offset 800h */
237        ifxusb_device_global_regs_t *dev_global_regs; /*!< pointer to Device Global Registers, offset at 800h */
238            #define IFXUSB_DEV_GLOBAL_REG_OFFSET 0x800
239
240        /** Device Logical IN Endpoint-Specific Registers 900h-AFCh */
241        ifxusb_dev_in_ep_regs_t *in_ep_regs[MAX_EPS_CHANNELS]; /*!< pointer to Device IN-EP Registers, offset at 900h */
242            #define IFXUSB_DEV_IN_EP_REG_OFFSET 0x900
243            #define IFXUSB_EP_REG_OFFSET 0x20
244        /** Device Logical OUT Endpoint-Specific Registers B00h-CFCh */
245        ifxusb_dev_out_ep_regs_t *out_ep_regs[MAX_EPS_CHANNELS];/*!< pointer to Device OUT-EP Registers, offset at 900h */
246            #define IFXUSB_DEV_OUT_EP_REG_OFFSET 0xB00
247    #endif
248
249    /** Power and Clock Gating Control Register */
250    volatile uint32_t *pcgcctl; /*!< pointer to Power and Clock Gating Control Registers, offset at E00h */
251        #define IFXUSB_PCGCCTL_OFFSET 0xE00
252
253    /** Push/pop addresses for endpoints or host channels.*/
254    uint32_t *data_fifo[MAX_EPS_CHANNELS]; /*!< pointer to FIFO access windows, offset at 1000h */
255        #define IFXUSB_DATA_FIFO_OFFSET 0x1000
256        #define IFXUSB_DATA_FIFO_SIZE 0x1000
257
258    uint32_t *data_fifo_dbg; /*!< pointer to FIFO debug windows, offset at 1000h */
259
260    /** Hardware Configuration -- stored here for convenience.*/
261    hwcfg1_data_t hwcfg1; /*!< preserved Hardware Configuration 1 */
262    hwcfg2_data_t hwcfg2; /*!< preserved Hardware Configuration 2 */
263    hwcfg3_data_t hwcfg3; /*!< preserved Hardware Configuration 3 */
264    hwcfg4_data_t hwcfg4; /*!< preserved Hardware Configuration 3 */
265    uint32_t snpsid; /*!< preserved SNPSID */
266
267    /*****************************************************************
268     * Run-time informations.
269     *****************************************************************/
270    /* Set to 1 if the core PHY interface bits in USBCFG have been initialized. */
271    uint8_t phy_init_done; /*!< indicated PHY is initialized. */
272
273    #ifdef __IS_HOST__
274        uint8_t queuing_high_bandwidth; /*!< Host mode, Queueing High Bandwidth. */
275    #endif
276
277    #if defined(__UNALIGNED_BUF_ADJ__) || defined(__UNALIGNED_BUF_CHK__)
278        uint32_t unaligned_mask;
279    #endif
280} ifxusb_core_if_t;
281
282/*@}*//*IFXUSB_CIF*/
283
284
285/*!
286 \fn void *ifxusb_alloc_buf(size_t size, int clear)
287 \brief This function is called to allocate buffer of specified size.
288        The allocated buffer is mapped into DMA accessable address.
289 \param size Size in BYTE to be allocated
290 \param clear 0: don't do clear after buffer allocated, other: do clear to zero
291 \return 0/NULL: Fail; uncached pointer of allocated buffer
292 \ingroup IFXUSB_CIF
293 */
294#ifdef __IS_HOST__
295extern void *ifxusb_alloc_buf_h(size_t size, int clear);
296#else
297extern void *ifxusb_alloc_buf_d(size_t size, int clear);
298#endif
299
300
301/*!
302 \fn void ifxusb_free_buf(void *vaddr)
303 \brief This function is called to free allocated buffer.
304 \param vaddr the uncached pointer of the buffer
305 \ingroup IFXUSB_CIF
306 */
307#ifdef __IS_HOST__
308extern void ifxusb_free_buf_h(void *vaddr);
309#else
310extern void ifxusb_free_buf_d(void *vaddr);
311#endif
312
313/*!
314 \fn int ifxusb_core_if_init(ifxusb_core_if_t *_core_if,
315                        int _irq,
316                        uint32_t _reg_base_addr,
317                        uint32_t _fifo_base_addr,
318                        uint32_t _fifo_dbg_addr)
319 \brief This function is called to initialize the IFXUSB CSR data
320        structures. The register addresses in the device and host
321        structures are initialized from the base address supplied by the
322        caller. The calling function must make the OS calls to get the
323        base address of the IFXUSB controller registers.
324 \param _core_if Pointer of core_if structure
325 \param _irq irq number
326 \param _reg_base_addr Base address of IFXUSB core registers
327 \param _fifo_base_addr Fifo base address
328 \param _fifo_dbg_addr Fifo debug address
329 \return 0: success;
330 \ingroup IFXUSB_CIF
331 */
332#ifdef __IS_HOST__
333extern int ifxusb_core_if_init_h(ifxusb_core_if_t *_core_if,
334#else
335extern int ifxusb_core_if_init_d(ifxusb_core_if_t *_core_if,
336#endif
337                        int _irq,
338                        uint32_t _reg_base_addr,
339                        uint32_t _fifo_base_addr,
340                        uint32_t _fifo_dbg_addr);
341
342
343/*!
344 \fn void ifxusb_core_if_remove(ifxusb_core_if_t *_core_if)
345 \brief This function free the mapped address in the IFXUSB CSR data structures.
346 \param _core_if Pointer of core_if structure
347 \ingroup IFXUSB_CIF
348 */
349#ifdef __IS_HOST__
350extern void ifxusb_core_if_remove_h(ifxusb_core_if_t *_core_if);
351#else
352extern void ifxusb_core_if_remove_d(ifxusb_core_if_t *_core_if);
353#endif
354
355/*!
356 \fn void ifxusb_enable_global_interrupts( ifxusb_core_if_t *_core_if )
357 \brief This function enbles the controller's Global Interrupt in the AHB Config register.
358 \param _core_if Pointer of core_if structure
359 */
360#ifdef __IS_HOST__
361extern void ifxusb_enable_global_interrupts_h( ifxusb_core_if_t *_core_if );
362#else
363extern void ifxusb_enable_global_interrupts_d( ifxusb_core_if_t *_core_if );
364#endif
365
366/*!
367 \fn void ifxusb_disable_global_interrupts( ifxusb_core_if_t *_core_if )
368 \brief This function disables the controller's Global Interrupt in the AHB Config register.
369 \param _core_if Pointer of core_if structure
370 \ingroup IFXUSB_CIF
371 */
372#ifdef __IS_HOST__
373extern void ifxusb_disable_global_interrupts_h( ifxusb_core_if_t *_core_if );
374#else
375extern void ifxusb_disable_global_interrupts_d( ifxusb_core_if_t *_core_if );
376#endif
377
378/*!
379 \fn void ifxusb_flush_tx_fifo( ifxusb_core_if_t *_core_if, const int _num )
380 \brief Flush a Tx FIFO.
381 \param _core_if Pointer of core_if structure
382 \param _num Tx FIFO to flush. ( 0x10 for ALL TX FIFO )
383 \ingroup IFXUSB_CIF
384 */
385#ifdef __IS_HOST__
386extern void ifxusb_flush_tx_fifo_h( ifxusb_core_if_t *_core_if, const int _num );
387#else
388extern void ifxusb_flush_tx_fifo_d( ifxusb_core_if_t *_core_if, const int _num );
389#endif
390
391/*!
392 \fn void ifxusb_flush_rx_fifo( ifxusb_core_if_t *_core_if )
393 \brief Flush Rx FIFO.
394 \param _core_if Pointer of core_if structure
395 \ingroup IFXUSB_CIF
396 */
397#ifdef __IS_HOST__
398extern void ifxusb_flush_rx_fifo_h( ifxusb_core_if_t *_core_if );
399#else
400extern void ifxusb_flush_rx_fifo_d( ifxusb_core_if_t *_core_if );
401#endif
402
403/*!
404 \fn void ifxusb_flush_both_fifo( ifxusb_core_if_t *_core_if )
405 \brief Flush ALL Rx and Tx FIFO.
406 \param _core_if Pointer of core_if structure
407 \ingroup IFXUSB_CIF
408 */
409#ifdef __IS_HOST__
410extern void ifxusb_flush_both_fifo_h( ifxusb_core_if_t *_core_if );
411#else
412extern void ifxusb_flush_both_fifo_d( ifxusb_core_if_t *_core_if );
413#endif
414
415
416/*!
417 \fn int ifxusb_core_soft_reset(ifxusb_core_if_t *_core_if)
418 \brief Do core a soft reset of the core. Be careful with this because it
419        resets all the internal state machines of the core.
420 \param _core_if Pointer of core_if structure
421 \ingroup IFXUSB_CIF
422 */
423#ifdef __IS_HOST__
424extern int ifxusb_core_soft_reset_h(ifxusb_core_if_t *_core_if);
425#else
426extern int ifxusb_core_soft_reset_d(ifxusb_core_if_t *_core_if);
427#endif
428
429
430/*!
431 \brief Turn on the USB Core Power
432 \param _core_if Pointer of core_if structure
433 \ingroup IFXUSB_CIF
434*/
435#ifdef __IS_HOST__
436    extern void ifxusb_power_on_h (ifxusb_core_if_t *_core_if);
437#else
438    extern void ifxusb_power_on_d (ifxusb_core_if_t *_core_if);
439#endif
440
441/*!
442 \fn void ifxusb_power_off (ifxusb_core_if_t *_core_if)
443 \brief Turn off the USB Core Power
444 \param _core_if Pointer of core_if structure
445 \ingroup IFXUSB_CIF
446*/
447#ifdef __IS_HOST__
448    extern void ifxusb_power_off_h (ifxusb_core_if_t *_core_if);
449#else
450    extern void ifxusb_power_off_d (ifxusb_core_if_t *_core_if);
451#endif
452
453/*!
454 \fn void ifxusb_phy_power_on (ifxusb_core_if_t *_core_if)
455 \brief Turn on the USB PHY Power
456 \param _core_if Pointer of core_if structure
457 \ingroup IFXUSB_CIF
458*/
459#ifdef __IS_HOST__
460    extern void ifxusb_phy_power_on_h (ifxusb_core_if_t *_core_if);
461#else
462    extern void ifxusb_phy_power_on_d (ifxusb_core_if_t *_core_if);
463#endif
464
465
466/*!
467 \fn void ifxusb_phy_power_off (ifxusb_core_if_t *_core_if)
468 \brief Turn off the USB PHY Power
469 \param _core_if Pointer of core_if structure
470 \ingroup IFXUSB_CIF
471*/
472#ifdef __IS_HOST__
473    extern void ifxusb_phy_power_off_h (ifxusb_core_if_t *_core_if);
474#else
475    extern void ifxusb_phy_power_off_d (ifxusb_core_if_t *_core_if);
476#endif
477
478/*!
479 \fn void ifxusb_hard_reset(ifxusb_core_if_t *_core_if)
480 \brief Reset on the USB Core RCU
481 \param _core_if Pointer of core_if structure
482 \ingroup IFXUSB_CIF
483 */
484#ifdef __IS_HOST__
485    extern void ifxusb_hard_reset_h(ifxusb_core_if_t *_core_if);
486#else
487    extern void ifxusb_hard_reset_d(ifxusb_core_if_t *_core_if);
488#endif
489
490
491///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
492
493
494#ifdef __IS_HOST__
495    /*!
496     \fn void ifxusb_host_core_init(ifxusb_core_if_t *_core_if, ifxusb_params_t *_params)
497     \brief This function initializes the IFXUSB controller registers for Host mode.
498            This function flushes the Tx and Rx FIFOs and it flushes any entries in the
499            request queues.
500     \param _core_if Pointer of core_if structure
501     \param _params parameters to be set
502     \ingroup IFXUSB_CIF
503     */
504    extern void ifxusb_host_core_init(ifxusb_core_if_t *_core_if, ifxusb_params_t *_params);
505
506    /*!
507     \fn void ifxusb_host_enable_interrupts(ifxusb_core_if_t *_core_if)
508     \brief This function enables the Host mode interrupts.
509     \param _core_if Pointer of core_if structure
510     \ingroup IFXUSB_CIF
511     */
512    extern void ifxusb_host_enable_interrupts(ifxusb_core_if_t *_core_if);
513
514    /*!
515     \fn void ifxusb_host_disable_interrupts(ifxusb_core_if_t *_core_if)
516     \brief This function disables the Host mode interrupts.
517     \param _core_if Pointer of core_if structure
518     \ingroup IFXUSB_CIF
519     */
520    extern void ifxusb_host_disable_interrupts(ifxusb_core_if_t *_core_if);
521
522    #if defined(__IS_TWINPASS__)
523        extern void ifxusb_enable_afe_oc(void);
524    #endif
525
526    /*!
527     \fn void ifxusb_vbus_init(ifxusb_core_if_t *_core_if)
528     \brief This function init the VBUS control.
529     \param _core_if Pointer of core_if structure
530     \ingroup IFXUSB_CIF
531     */
532    extern void ifxusb_vbus_init(ifxusb_core_if_t *_core_if);
533
534    /*!
535     \fn void ifxusb_vbus_free(ifxusb_core_if_t *_core_if)
536     \brief This function free the VBUS control.
537     \param _core_if Pointer of core_if structure
538     \ingroup IFXUSB_CIF
539     */
540    extern void ifxusb_vbus_free(ifxusb_core_if_t *_core_if);
541
542    /*!
543     \fn void ifxusb_vbus_on(ifxusb_core_if_t *_core_if)
544     \brief Turn on the USB 5V VBus Power
545     \param _core_if Pointer of core_if structure
546     \ingroup IFXUSB_CIF
547     */
548    extern void ifxusb_vbus_on(ifxusb_core_if_t *_core_if);
549
550    /*!
551     \fn void ifxusb_vbus_off(ifxusb_core_if_t *_core_if)
552     \brief Turn off the USB 5V VBus Power
553     \param _core_if Pointer of core_if structure
554     \ingroup IFXUSB_CIF
555     */
556    extern void ifxusb_vbus_off(ifxusb_core_if_t *_core_if);
557
558    /*!
559     \fn int ifxusb_vbus(ifxusb_core_if_t *_core_if)
560     \brief Read Current VBus status
561     \param _core_if Pointer of core_if structure
562     \ingroup IFXUSB_CIF
563     */
564    extern int ifxusb_vbus(ifxusb_core_if_t *_core_if);
565#endif
566
567///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
568
569
570#ifdef __IS_DEVICE__
571    /*!
572     \fn void ifxusb_dev_enable_interrupts(ifxusb_core_if_t *_core_if)
573     \brief This function enables the Device mode interrupts.
574     \param _core_if Pointer of core_if structure
575     \ingroup IFXUSB_CIF
576     */
577    extern void ifxusb_dev_enable_interrupts(ifxusb_core_if_t *_core_if);
578
579    /*!
580     \fn uint32_t ifxusb_dev_get_frame_number(ifxusb_core_if_t *_core_if)
581     \brief Gets the current USB frame number. This is the frame number from the last SOF packet.
582     \param _core_if Pointer of core_if structure
583     \ingroup IFXUSB_CIF
584     */
585    extern uint32_t ifxusb_dev_get_frame_number(ifxusb_core_if_t *_core_if);
586
587    /*!
588     \fn void ifxusb_dev_ep_set_stall(ifxusb_core_if_t *_core_if, uint8_t _epno, uint8_t _is_in)
589     \brief Set the EP STALL.
590     \param _core_if Pointer of core_if structure
591     \param _epno EP number
592     \param _is_in 1: is IN transfer
593     \ingroup IFXUSB_CIF
594     */
595    extern void ifxusb_dev_ep_set_stall(ifxusb_core_if_t *_core_if, uint8_t _epno, uint8_t _is_in);
596
597    /*!
598     \fn void ifxusb_dev_ep_clear_stall(ifxusb_core_if_t *_core_if, uint8_t _epno, uint8_t _ep_type, uint8_t _is_in)
599     \brief Set the EP STALL.
600     \param _core_if Pointer of core_if structure
601     \param _epno EP number
602     \param _ep_type EP Type
603     \ingroup IFXUSB_CIF
604     */
605    extern void ifxusb_dev_ep_clear_stall(ifxusb_core_if_t *_core_if, uint8_t _epno, uint8_t _ep_type, uint8_t _is_in);
606
607    /*!
608     \fn void ifxusb_dev_core_init(ifxusb_core_if_t *_core_if, ifxusb_params_t *_params)
609     \brief This function initializes the IFXUSB controller registers for Device mode.
610             This function flushes the Tx and Rx FIFOs and it flushes any entries in the
611             request queues.
612             This function validate the imported parameters and store the result in the CIF structure.
613                 After
614     \param _core_if Pointer of core_if structure
615     \param _params structure of inported parameters
616     \ingroup IFXUSB_CIF
617     */
618    extern void ifxusb_dev_core_init(ifxusb_core_if_t *_core_if, ifxusb_params_t *_params);
619#endif
620
621///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
622
623#if defined(__GADGET_LED__) || defined(__HOST_LED__)
624    /*!
625     \fn void ifxusb_led_init(ifxusb_core_if_t *_core_if)
626     \brief This function init the LED control.
627     \param _core_if Pointer of core_if structure
628     \ingroup IFXUSB_CIF
629     */
630    extern void ifxusb_led_init(ifxusb_core_if_t *_core_if);
631
632    /*!
633     \fn void ifxusb_led_free(ifxusb_core_if_t *_core_if)
634     \brief This function free the LED control.
635     \param _core_if Pointer of core_if structure
636     \ingroup IFXUSB_CIF
637     */
638    extern void ifxusb_led_free(ifxusb_core_if_t *_core_if);
639
640    /*!
641     \fn void ifxusb_led(ifxusb_core_if_t *_core_if)
642     \brief This function trigger the LED access.
643     \param _core_if Pointer of core_if structure
644     \ingroup IFXUSB_CIF
645     */
646    extern void ifxusb_led(ifxusb_core_if_t *_core_if);
647#endif
648
649///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
650
651/* internal routines for debugging */
652#ifdef __IS_HOST__
653    extern void ifxusb_dump_msg_h(const u8 *buf, unsigned int length);
654    extern void ifxusb_dump_spram_h(ifxusb_core_if_t *_core_if);
655    extern void ifxusb_dump_registers_h(ifxusb_core_if_t *_core_if);
656#else
657    extern void ifxusb_dump_msg_d(const u8 *buf, unsigned int length);
658    extern void ifxusb_dump_spram_d(ifxusb_core_if_t *_core_if);
659    extern void ifxusb_dump_registers_d(ifxusb_core_if_t *_core_if);
660#endif
661
662///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
663
664static inline uint32_t ifxusb_read_core_intr(ifxusb_core_if_t *_core_if)
665{
666    return (ifxusb_rreg(&_core_if->core_global_regs->gintsts) &
667            ifxusb_rreg(&_core_if->core_global_regs->gintmsk));
668}
669
670static inline uint32_t ifxusb_read_otg_intr (ifxusb_core_if_t *_core_if)
671{
672    return (ifxusb_rreg (&_core_if->core_global_regs->gotgint));
673}
674
675static inline uint32_t ifxusb_mode(ifxusb_core_if_t *_core_if)
676{
677    return (ifxusb_rreg( &_core_if->core_global_regs->gintsts ) & 0x1);
678}
679static inline uint8_t ifxusb_is_device_mode(ifxusb_core_if_t *_core_if)
680{
681    return (ifxusb_mode(_core_if) != 1);
682}
683static inline uint8_t ifxusb_is_host_mode(ifxusb_core_if_t *_core_if)
684{
685    return (ifxusb_mode(_core_if) == 1);
686}
687
688///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
689
690#ifdef __IS_HOST__
691    static inline uint32_t ifxusb_read_hprt0(ifxusb_core_if_t *_core_if)
692    {
693        hprt0_data_t hprt0;
694        hprt0.d32 = ifxusb_rreg(_core_if->hprt0);
695        hprt0.b.prtena = 0;
696        hprt0.b.prtconndet = 0;
697        hprt0.b.prtenchng = 0;
698        hprt0.b.prtovrcurrchng = 0;
699        return hprt0.d32;
700    }
701
702    static inline uint32_t ifxusb_read_host_all_channels_intr (ifxusb_core_if_t *_core_if)
703    {
704        return (ifxusb_rreg (&_core_if->host_global_regs->haint));
705    }
706
707    static inline uint32_t ifxusb_read_host_channel_intr (ifxusb_core_if_t *_core_if, int hc_num)
708    {
709        return (ifxusb_rreg (&_core_if->hc_regs[hc_num]->hcint));
710    }
711#endif
712
713#ifdef __IS_DEVICE__
714    static inline uint32_t ifxusb_read_dev_all_in_ep_intr(ifxusb_core_if_t *_core_if)
715    {
716        uint32_t v;
717        v = ifxusb_rreg(&_core_if->dev_global_regs->daint) &
718            ifxusb_rreg(&_core_if->dev_global_regs->daintmsk);
719        return (v & 0xffff);
720    }
721
722    static inline uint32_t ifxusb_read_dev_all_out_ep_intr(ifxusb_core_if_t *_core_if)
723    {
724        uint32_t v;
725        v = ifxusb_rreg(&_core_if->dev_global_regs->daint) &
726            ifxusb_rreg(&_core_if->dev_global_regs->daintmsk);
727        return ((v & 0xffff0000) >> 16);
728    }
729
730    static inline uint32_t ifxusb_read_dev_in_ep_intr(ifxusb_core_if_t *_core_if, int _ep_num)
731    {
732        uint32_t v;
733        v = ifxusb_rreg(&_core_if->in_ep_regs[_ep_num]->diepint) &
734            ifxusb_rreg(&_core_if->dev_global_regs->diepmsk);
735        return v;
736    }
737
738    static inline uint32_t ifxusb_read_dev_out_ep_intr(ifxusb_core_if_t *_core_if, int _ep_num)
739    {
740        uint32_t v;
741        v = ifxusb_rreg(&_core_if->out_ep_regs[_ep_num]->doepint) &
742            ifxusb_rreg(&_core_if->dev_global_regs->doepmsk);
743        return v;
744    }
745
746#endif
747
748#ifdef __IS_HOST__
749extern void ifxusb_attr_create_h (void *_dev);
750extern void ifxusb_attr_remove_h (void *_dev);
751#else
752extern void ifxusb_attr_create_d (void *_dev);
753extern void ifxusb_attr_remove_d (void *_dev);
754#endif
755
756#ifdef __IS_HOST__
757extern void do_suspend_h(ifxusb_core_if_t *core_if);
758extern void do_resume_h(ifxusb_core_if_t *_core_if);
759#else
760extern void do_suspend_d(ifxusb_core_if_t *core_if);
761extern void do_resume_d(ifxusb_core_if_t *_core_if);
762#endif
763
764///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
765
766#endif // !defined(__IFXUSB_CIF_H__)
767
768

Archive Download this file



interactive