/**HEADER********************************************************************
* 
* Copyright (c) 2008 Freescale Semiconductor;
* All Rights Reserved                       
*
* Copyright (c) 1989-2008 ARC International;
* All Rights Reserved
*
*************************************************************************** 
*
* THIS SOFTWARE IS PROVIDED BY FREESCALE "AS IS" AND ANY EXPRESSED OR 
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  
* IN NO EVENT SHALL FREESCALE OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 
* THE POSSIBILITY OF SUCH DAMAGE.
*
**************************************************************************
*
* $FileName: mcf5xxx_usbotg.h$
* $Version : 3.4.3.0$
* $Date    : Sep-7-2009$
*
* Comments:
*
*   This file contains the type definitions for the mcf522x usbotg module.
*
*END************************************************************************/

#ifndef __mcf5xxx_usbotg_h__
#define __mcf5xxx_usbotg_h__

#define __mcf5xxx_usbotg_h__version "$Version:3.4.3.0$"
#define __mcf5xxx_usbotg_h__date    "$Date:Sep-7-2009$"

#ifdef __cplusplus
extern "C" {
#endif

/*------------------------------------------------------------------------*/
/*
** USB OTG
*/

/* Bit definitions and macros for OTG_PORTSC1 */
#define MCF5XXX_USBOTG_PORTSC1_PTS      (0xC0000000)
#define MCF5XXX_USBOTG_PORTSC1_PTS_ULPI (0x80000000) /* ULPI interface */
#define MCF5XXX_USBOTG_PORTSC1_PTS_OCT  (0xC0000000) /* on chip transciever */

#define MCF5XXX_USBOTG_PORTSC1_PSPD      (0x0C000000)
#define MCF5XXX_USBOTG_PORTSC1_PSPD_FS   (0x00000000)
#define MCF5XXX_USBOTG_PORTSC1_PSPD_LS   (0x04000000)
#define MCF5XXX_USBOTG_PORTSC1_PSPD_HS   (0x08000000)

#define MCF5XXX_USBOTG_GPTIMER_MODE(x)   ((x & 1) << 24)
#define MCF5XXX_USBOTG_GPTIMER_ONESHOT   (0x00000000)
#define MCF5XXX_USBOTG_GPTIMER_REPEAT    (0x01000000)

#define MCF5XXX_USBOTG_GPTIMER_RESET     (0x40000000)

#define MCF5XXX_USBOTG_GPTIMER_RUN       (0x80000000)


#if 0

/* Bit definitions and macros for PER_ID */
#define MCF5XXX_USBOTG_PER_ID_ID(x)             (((x)&0x3F)<<0)

/* Bit definitions and macros for ID_COMP */
#define MCF5XXX_USBOTG_ID_COMP_NID(x)           (((x)&0x3F)<<0)

/* Bit definitions and macros for REV */
#define MCF5XXX_USBOTG_REV_REV(x)               (((x)&0xFF)<<0)

/* Bit definitions and macros for ADD_INFO */
#define MCF5XXX_USBOTG_ADD_INFO_IEHOST          (0x1)
#define MCF5XXX_USBOTG_ADD_INFO_IRQ_NUM(x)      (((x)&0x1F)<<0x3)

/* Bit definitions and macros for OTG_INT_STAT */
#define MCF5XXX_USBOTG_OTG_INT_STAT_A_VBUS_CHG  (0x1)
#define MCF5XXX_USBOTG_OTG_INT_STAT_B_SESS_CHG  (0x4)
#define MCF5XXX_USBOTG_OTG_INT_STAT_SESS_VLD_CHG (0x8)
#define MCF5XXX_USBOTG_OTG_INT_STAT_LINE_STATE_CHG (0x20)
#define MCF5XXX_USBOTG_OTG_INT_STAT_1_MSEC      (0x40)
#define MCF5XXX_USBOTG_OTG_INT_STAT_ID_CHG      (0x80)

/* Bit definitions and macros for OTG_INT_EN */
#define MCF5XXX_USBOTG_OTG_INT_EN_A_VBUS_EN     (0x1)
#define MCF5XXX_USBOTG_OTG_INT_EN_B_SESS_EN     (0x4)
#define MCF5XXX_USBOTG_OTG_INT_EN_SESS_VLD_EN   (0x8)
#define MCF5XXX_USBOTG_OTG_INT_EN_LINE_STATE_EN (0x20)
#define MCF5XXX_USBOTG_OTG_INT_EN_1_MSEC_EN     (0x40)
#define MCF5XXX_USBOTG_OTG_INT_EN_ID_EN         (0x80)

/* Bit definitions and macros for OTG_STAT */
#define MCF5XXX_USBOTG_OTG_STAT_A_VBUS_VLD      (0x1)
#define MCF5XXX_USBOTG_OTG_STAT_B_SESS_END      (0x4)
#define MCF5XXX_USBOTG_OTG_STAT_SESS_VLD        (0x8)
#define MCF5XXX_USBOTG_OTG_STAT_LINE_STATE_STABLE (0x20)
#define MCF5XXX_USBOTG_OTG_STAT_1_MSEC_EN       (0x40)
#define MCF5XXX_USBOTG_OTG_STAT_ID              (0x80)

/* Bit definitions and macros for OTG_CTRL */
#define MCF5XXX_USBOTG_OTG_CTRL_VBUS_DSCHG      (0x1)
#define MCF5XXX_USBOTG_OTG_CTRL_VBUS_CHG        (0x2)
#define MCF5XXX_USBOTG_OTG_CTRL_OTG_EN          (0x4)
#define MCF5XXX_USBOTG_OTG_CTRL_VBUS_ON         (0x8)
#define MCF5XXX_USBOTG_OTG_CTRL_DM_LOW          (0x10)
#define MCF5XXX_USBOTG_OTG_CTRL_DP_LOW          (0x20)
#define MCF5XXX_USBOTG_OTG_CTRL_DM_HIGH         (0x40)
#define MCF5XXX_USBOTG_OTG_CTRL_DP_HIGH         (0x80)

/* Bit definitions and macros for INT_STAT */
#define MCF5XXX_USBOTG_INT_STAT_USB_RST         (0x1)
#define MCF5XXX_USBOTG_INT_STAT_ERROR           (0x2)
#define MCF5XXX_USBOTG_INT_STAT_SOF_TOK         (0x4)
#define MCF5XXX_USBOTG_INT_STAT_TOK_DNE         (0x8)
#define MCF5XXX_USBOTG_INT_STAT_SLEEP           (0x10)
#define MCF5XXX_USBOTG_INT_STAT_RESUME          (0x20)
#define MCF5XXX_USBOTG_INT_STAT_ATTACH          (0x40)
#define MCF5XXX_USBOTG_INT_STAT_STALL           (0x80)

/* Bit definitions and macros for INT_ENB */
#define MCF5XXX_USBOTG_INT_ENB_USB_RST_EN       (0x1)
#define MCF5XXX_USBOTG_INT_ENB_ERROR_EN         (0x2)
#define MCF5XXX_USBOTG_INT_ENB_SOF_TOK_EN       (0x4)
#define MCF5XXX_USBOTG_INT_ENB_TOK_DNE_EN       (0x8)
#define MCF5XXX_USBOTG_INT_ENB_SLEEP_EN         (0x10)
#define MCF5XXX_USBOTG_INT_ENB_RESUME_EN        (0x20)
#define MCF5XXX_USBOTG_INT_ENB_ATTACH_EN        (0x40)
#define MCF5XXX_USBOTG_INT_ENB_STALL_EN         (0x80)

/* Bit definitions and macros for ERR_STAT */
#define MCF5XXX_USBOTG_ERR_STAT_PID_ERR         (0x1)
#define MCF5XXX_USBOTG_ERR_STAT_CRC5_EOF        (0x2)
#define MCF5XXX_USBOTG_ERR_STAT_CRC16           (0x4)
#define MCF5XXX_USBOTG_ERR_STAT_DFN8            (0x8)
#define MCF5XXX_USBOTG_ERR_STAT_BTO_ERR         (0x10)
#define MCF5XXX_USBOTG_ERR_STAT_DMA_ERR         (0x20)
#define MCF5XXX_USBOTG_ERR_STAT_BTS_ERR         (0x80)

/* Bit definitions and macros for ERR_ENB */
#define MCF5XXX_USBOTG_ERR_ENB_PID_ERR_EN       (0x1)
#define MCF5XXX_USBOTG_ERR_ENB_CRC5_EOF_EN      (0x2)
#define MCF5XXX_USBOTG_ERR_ENB_CRC16_EN         (0x4)
#define MCF5XXX_USBOTG_ERR_ENB_DFN8_EN          (0x8)
#define MCF5XXX_USBOTG_ERR_ENB_BTO_ERR_EN       (0x10)
#define MCF5XXX_USBOTG_ERR_ENB_DMA_ERR_EN       (0x20)
#define MCF5XXX_USBOTG_ERR_ENB_BTS_ERR_EN       (0x80)

/* Bit definitions and macros for STAT */
#define MCF5XXX_USBOTG_STAT_ODD                 (0x4)
#define MCF5XXX_USBOTG_STAT_TX                  (0x8)
#define MCF5XXX_USBOTG_STAT_ENDP(x)             (((x)&0xF)<<0x4)

/* Bit definitions and macros for OTG_CTL */
#define MCF5XXX_USBOTG_CTL_USB_EN_SOF_EN        (0x1)
#define MCF5XXX_USBOTG_CTL_ODD_RST              (0x2)
#define MCF5XXX_USBOTG_CTL_RESUME               (0x4)
#define MCF5XXX_USBOTG_CTL_HOST_MODE_EN         (0x8)
#define MCF5XXX_USBOTG_CTL_RESET                (0x10)
#define MCF5XXX_USBOTG_CTL_TXSUSPEND_TOKENBUSY  (0x20)
#define MCF5XXX_USBOTG_CTL_SE0                  (0x40)
#define MCF5XXX_USBOTG_CTL_JSTATE               (0x80)

/* Bit definitions and macros for ADDR */
#define MCF5XXX_USBOTG_ADDR_ADDR(x)             (((x)&0x7F)<<0)
#define MCF5XXX_USBOTG_ADDR_LS_EN               (0x80)

/* Bit definitions and macros for BDT_PAGE_01 */
#define MCF5XXX_USBOTG_BDT_PAGE_01_BDT_BA9      (0x2)
#define MCF5XXX_USBOTG_BDT_PAGE_01_BDT_BA10     (0x4)
#define MCF5XXX_USBOTG_BDT_PAGE_01_BDT_BA11     (0x8)
#define MCF5XXX_USBOTG_BDT_PAGE_01_BDT_BA12     (0x10)
#define MCF5XXX_USBOTG_BDT_PAGE_01_BDT_BA13     (0x20)
#define MCF5XXX_USBOTG_BDT_PAGE_01_BDT_BA14     (0x40)
#define MCF5XXX_USBOTG_BDT_PAGE_01_BDT_BA15     (0x80)

/* Bit definitions and macros for FRM_NUML */
#define MCF5XXX_USBOTG_FRM_NUML_FRM0            (0x1)
#define MCF5XXX_USBOTG_FRM_NUML_FRM1            (0x2)
#define MCF5XXX_USBOTG_FRM_NUML_FRM2            (0x4)
#define MCF5XXX_USBOTG_FRM_NUML_FRM3            (0x8)
#define MCF5XXX_USBOTG_FRM_NUML_FRM4            (0x10)
#define MCF5XXX_USBOTG_FRM_NUML_FRM5            (0x20)
#define MCF5XXX_USBOTG_FRM_NUML_FRM6            (0x40)
#define MCF5XXX_USBOTG_FRM_NUML_FRM7            (0x80)

/* Bit definitions and macros for FRM_NUMH */
#define MCF5XXX_USBOTG_FRM_NUMH_FRM8            (0x1)
#define MCF5XXX_USBOTG_FRM_NUMH_FRM9            (0x2)
#define MCF5XXX_USBOTG_FRM_NUMH_FRM10           (0x4)

/* Bit definitions and macros for TOKEN */
#define MCF5XXX_USBOTG_TOKEN_TOKEN_ENDPT(x)     (((x)&0xF)<<0)
#define MCF5XXX_USBOTG_TOKEN_TOKEN_PID(x)       (((x)&0xF)<<0x4)
#define MCF5XXX_USBOTG_TOKEN_TOKEN_PID_OUT      (0x10)
#define MCF5XXX_USBOTG_TOKEN_TOKEN_PID_IN       (0x90)
#define MCF5XXX_USBOTG_TOKEN_TOKEN_PID_SETUP    (0xD0)

/* Bit definitions and macros for SOF_THLD */
#define MCF5XXX_USBOTG_SOF_THLD_CNT0            (0x1)
#define MCF5XXX_USBOTG_SOF_THLD_CNT1            (0x2)
#define MCF5XXX_USBOTG_SOF_THLD_CNT2            (0x4)
#define MCF5XXX_USBOTG_SOF_THLD_CNT3            (0x8)
#define MCF5XXX_USBOTG_SOF_THLD_CNT4            (0x10)
#define MCF5XXX_USBOTG_SOF_THLD_CNT5            (0x20)
#define MCF5XXX_USBOTG_SOF_THLD_CNT6            (0x40)
#define MCF5XXX_USBOTG_SOF_THLD_CNT7            (0x80)

/* Bit definitions and macros for BDT_PAGE_02 */
#define MCF5XXX_USBOTG_BDT_PAGE_02_BDT_BA16     (0x1)
#define MCF5XXX_USBOTG_BDT_PAGE_02_BDT_BA17     (0x2)
#define MCF5XXX_USBOTG_BDT_PAGE_02_BDT_BA18     (0x4)
#define MCF5XXX_USBOTG_BDT_PAGE_02_BDT_BA19     (0x8)
#define MCF5XXX_USBOTG_BDT_PAGE_02_BDT_BA20     (0x10)
#define MCF5XXX_USBOTG_BDT_PAGE_02_BDT_BA21     (0x20)
#define MCF5XXX_USBOTG_BDT_PAGE_02_BDT_BA22     (0x40)
#define MCF5XXX_USBOTG_BDT_PAGE_02_BDT_BA23     (0x80)

/* Bit definitions and macros for BDT_PAGE_03 */
#define MCF5XXX_USBOTG_BDT_PAGE_03_BDT_BA24     (0x1)
#define MCF5XXX_USBOTG_BDT_PAGE_03_BDT_BA25     (0x2)
#define MCF5XXX_USBOTG_BDT_PAGE_03_BDT_BA26     (0x4)
#define MCF5XXX_USBOTG_BDT_PAGE_03_BDT_BA27     (0x8)
#define MCF5XXX_USBOTG_BDT_PAGE_03_BDT_BA28     (0x10)
#define MCF5XXX_USBOTG_BDT_PAGE_03_BDT_BA29     (0x20)
#define MCF5XXX_USBOTG_BDT_PAGE_03_BDT_BA30     (0x40)
#define MCF5XXX_USBOTG_BDT_PAGE_03_BDT_BA31     (0x80)

/* Bit definitions and macros for ENDPT */
#define MCF5XXX_USBOTG_ENDPT_EP_HSHK            (0x1)
#define MCF5XXX_USBOTG_ENDPT_EP_STALL           (0x2)
#define MCF5XXX_USBOTG_ENDPT_EP_TX_EN           (0x4)
#define MCF5XXX_USBOTG_ENDPT_EP_RX_EN           (0x8)
#define MCF5XXX_USBOTG_ENDPT_EP_CTL_DIS         (0x10)
#define MCF5XXX_USBOTG_ENDPT_RETRY_DIS          (0x40)
#define MCF5XXX_USBOTG_ENDPT_HOST_WO_HUB        (0x80)

/* Bit definitions and macros for USB_CTRL */
#define MCF5XXX_USBOTG_USB_CTRL_CLK_SRC(x)      (((x)&0x3)<<0)
#define MCF5XXX_USBOTG_USB_CTRL_CLK_SRC_ALTCLK  (0)
#define MCF5XXX_USBOTG_USB_CTRL_CLK_SRC_OSCCLK  (0x1)
#define MCF5XXX_USBOTG_USB_CTRL_CLK_SRC_SYSCLK  (0x3)
#define MCF5XXX_USBOTG_USB_CTRL_PDE             (0x40)
#define MCF5XXX_USBOTG_USB_CTRL_SUSP            (0x80)

/* Bit definitions and macros for OTG_OBSERVE */
#define MCF5XXX_USBOTG_USB_OTG_OBSERVE_VBUSDIS  (0x2)
#define MCF5XXX_USBOTG_USB_OTG_OBSERVE_VBUSCHG  (0x4)
#define MCF5XXX_USBOTG_USB_OTG_OBSERVE_VBUSE    (0x8)
#define MCF5XXX_USBOTG_USB_OTG_OBSERVE_DM_PD    (0x10)
#define MCF5XXX_USBOTG_USB_OTG_OBSERVE_DP_PD    (0x40)
#define MCF5XXX_USBOTG_USB_OTG_OBSERVE_DP_PU    (0x80)

/* Bit definitions and macros for OTG_CONTROL */
#define MCF5XXX_USBOTG_USB_OTG_CONTROL_SESSEND  (0x1)
#define MCF5XXX_USBOTG_USB_OTG_CONTROL_SESSVLD  (0x2)
#define MCF5XXX_USBOTG_USB_OTG_CONTROL_VBUSVLD  (0x4)
#define MCF5XXX_USBOTG_USB_OTG_CONTROL_ID       (0x8)
#define MCF5XXX_USBOTG_USB_OTG_CONTROL_VBUSD    (0x10)

/* Bit definitions and macros for OTG_PORTSC1 */
#define MCF5XXX_USBOTG_USB_OTG_PORTSC1_PTS      (0xC0000000)
#define MCF5XXX_USBOTG_USB_OTG_PORTSC1_PTS_ULPI (0x80000000) /* ULPI interface */
#define MCF5XXX_USBOTG_USB_OTG_PORTSC1_PTS_OCT  (0xC0000000) /* on chip transciever */

/* Bit definitons and macros for USB buffer descriptor */
#define MCF5XXX_USBOTG_BD_BC(n)                 ((n & 0x3ff) << 16)
#define MCF5XXX_USBOTG_BD_OWN                   0x80
#define MCF5XXX_USBOTG_BD_DATA01(n)             ((n & 1) << 6)
//#define MCF5XXX_USBOTG_BD_DATA0                 0
//#define MCF5XXX_USBOTG_BD_DATA1                 0x40
#define MCF5XXX_USBOTG_BD_KEEP                  0x20
#define MCF5XXX_USBOTG_BD_NINC                  0x10
#define MCF5XXX_USBOTG_BD_DTS                   0x08
#define MCF5XXX_USBOTG_BD_STALL                 0x04

#define MCF5XXX_USBOTG_BD_PID(n)                ((n & 0x0f) << 2)

#endif

/*------------------------------------------------------------------------*/
/*
** MCF5XXX_USBOTG_STRUCT
** USB OTG
*/
typedef struct mcf5xxx_usbotg_struct {
    // Module Identification Registers
	uint_32 ID;             // Identification Register
	uint_32 HWGENERAL;      // General Hardware Parameters
	uint_32 HWHOST;         // Host Hardware Parameters
	uint_32 HWDEVICE;       // Device Hardware Parameters
	uint_32 HWTXBUF;        // TX Buffer Hardware Parameters
	uint_32 HWRXBUF;        // RX Buffer Hardware Parameters

	uint_8  filler0[104];
	
	// Device/Host Timer Registers
	uint_32 GPTIMER0LD;     // General Purpose Timer 0 Load
	uint_32 GPTIMER0CTL;    // General Purpose Timer 0 Control
	uint_32 GPTIMER1LD;     // General Purpose Timer 1 Load
	uint_32 GPTIMER1CTL;    // General Purpose Timer 1 Control

	uint_8  filler1[112];

    // Capability Registers
	uint_16 HCIVERSION;     // Host Interface Version Number
	uint_8  filler2;
	uint_8  CAPLENGTH;      // Capability Register Length
	uint_32 HCSPARAMS;      // Host Structural Parameters   
	uint_32 HCCPARAMS;      // Host Capability Parameters   

	uint_8 filler3[22];

	uint_16 DCIVERSION;     // Device Interface Version Number
	uint_32 DCCPARAMS;      // Device Capability Parameters

	uint_8 filler4[24];
	
	// Operational Registers
	uint_32 USBCMD;         // USB Command
	uint_32 USBSTS;         // USB Status
	uint_32 USBINTR;        // USB Interrupt Enable
	uint_32 FRINDEX;        // USB Frame Index
	
	uint_8 filler5[4];
	
	union {
	    uint_32 PERIODICLISTBASE;   // Periodic Frame List Base Address
	    uint_32 DEVICEADDR;     // Device Address
    };
    
    union {
	    uint_32 ASYNCLISTADDR;  // Current Asynchronous List Address
	    uint_32 EPLISTADDR;     // Address at Endpoint List
    };
	
	uint_32 TTCTRL;         // Host TT Asynchronous Buffer Control
	uint_32 BURSTSIZE;      // Master Interface Data Burst Size
	uint_32 TXFILLTUNING;   // Host Transmit FIFO Tuning Control
	
	uint_8 filler6[24];
	
	uint_32 CONFIGFLAG;     // Configure Flag Register
	uint_32 PORTSC1;        // Port Status/Control
	
	uint_8 filler7[28];
	
	uint_32 OTGSC;          // On-The-Go Status and Control
	uint_32 MODE;           // USB Mode Register
	uint_32 EPSETUPSR;      // Endpoint Setup Status Register
	uint_32 EPPRIME;        // Endpoint Initialization
	uint_32 EPFLUSH;        // Endpoint De-initialize
	uint_32 EPSR;           // Endpoint Status Register
	uint_32 EPCOMPLETE;     // Endpoint Complete
	uint_32 EPCR0;          // Endpoint Control Register 0
	uint_32 EPCR1;          // Endpoint Control Register 1
	uint_32 EPCR2;          // Endpoint Control Register 2
	uint_32 EPCR3;          // Endpoint Control Register 3
} MCF5XXX_USBOTG_STRUCT, _PTR_ MCF5XXX_USBOTG_STRUCT_PTR;
typedef volatile struct mcf5xxx_usbotg_struct _PTR_ VMCF5XXX_USBOTG_STRUCT_PTR;

#ifdef __cplusplus
}
#endif


#endif
