/*****************************************************************************
* Copyright Statement:
* --------------------
* This software is protected by Copyright and the information contained
* herein is confidential. The software may not be copied and the information
* contained herein may not be used or disclosed except with the written
* permission of MediaTek Inc. (C) 2005
*
* BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
* THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
* RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
* AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
* NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
* SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
* SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
* THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
* NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
* SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
*
* BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
* LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
* AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
* OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
* MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
*
* THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
* WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
* LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
* RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
* THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
*
*****************************************************************************/
/*****************************************************************************
*
* Filename:
* ---------
* usb_drv.c
*
* Project:
* --------
* Maui_Software
*
* Description:
* ------------
* This file implements usb hardware related functions
*
* Author:
* -------
* -------
*
*============================================================================
* HISTORY
* Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
*------------------------------------------------------------------------------
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*------------------------------------------------------------------------------
* Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
*============================================================================
****************************************************************************/
#ifdef __USB_DOWNLOAD__
#include "drv_comm.h"
#include "reg_base.h"
//#include "intrCtrl.h"
#include "gpio_sw.h"
#include "usb_hw.h"
#include "usb_drv.h"
#include "usb_drv_pri.h"
#include "usb_custom.h"
#include "usb_comm.h"
/* usb driver information*/
USB_Drv_Info g_UsbDrvInfo;
#if defined(DRV_USB_IP_V3)
/* EP0's FIFO address is fixed from 0~63 */
static kal_uint32 g_FIFOadd = USB_FIFO_START_ADDRESS;
/* static functions*/
static kal_uint8 USB_Get_DMA_Channel_Num(kal_uint8 ep_num, USB_EP_TYPE direction);
static void USBDMA_HISR(void);
static void USBDMA_LISR(void);
static void USB_DMA_Callback(kal_uint8 dma_chan);
static void USB_High_Speed_Enable(void);
static void USB_Set_DP_Pull_Up(kal_bool bset);
#if 0
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#endif
#endif
static kal_uint32 g_usb_pdn_owner = 0;
static void USB_EnSysIntr(void);
static void USBDL_CLK_ON(void);
#if 0
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#endif
/************************************************************
driver info functions
*************************************************************/
/* initialize usb driver information, called at USB_Init() */
void USB_Init_Drv_Info(kal_bool FT)
{
kal_uint32 index;
g_UsbDrvInfo.power_state = USB_STATE_NORMAL;
// g_UsbDrvInfo.is_unMaskUSB = KAL_TRUE;
// g_UsbDrvInfo.is_ProUSBHISR = KAL_FALSE;
g_UsbDrvInfo.reset_hdlr = NULL;
g_UsbDrvInfo.ep0_hdlr = NULL;
for(index=0; index< MAX_INTR_EP_NUM; index++)
{
g_UsbDrvInfo.ep_tx_hdlr[index] = NULL;
g_UsbDrvInfo.ep_rx_hdlr[index] = NULL;
g_UsbDrvInfo.ep_tx_stall_status[index] = KAL_FALSE;
g_UsbDrvInfo.ep_rx_stall_status[index] = KAL_FALSE;
#if defined(DRV_USB_IP_V3)
g_UsbDrvInfo.dma_port[USB_TX_EP_TYPE][index] = 0;
g_UsbDrvInfo.dma_port[USB_RX_EP_TYPE][index] = 0;
#endif
}
for(index=0; index<MAX_DMA_EP_NUM; index++)
{
#if defined(DRV_USB_IP_V3)
g_UsbDrvInfo.dma_pktrdy[index] = KAL_FALSE;
g_UsbDrvInfo.dma_running[index] = KAL_FALSE;
g_UsbDrvInfo.dma_callback_upd_run[index] = KAL_FALSE;
g_UsbDrvInfo.dma_callback[index] = KAL_FALSE;
g_UsbDrvInfo.dma_ep_num[index] = 0;
// g_UsbDrvInfo.dma_is_pp[index] = KAL_FALSE;
// g_UsbDrvInfo.dma_is_running[0][index] = KAL_FALSE;
// g_UsbDrvInfo.dma_is_running[1][index] = KAL_FALSE;
#else
g_UsbDrvInfo.dma_port[index] = 0;
g_UsbDrvInfo.dma_pktrdy[index] = KAL_FALSE;
g_UsbDrvInfo.dma_running[index] = KAL_FALSE;
g_UsbDrvInfo.dma_callback_upd_run[index] = KAL_FALSE;
g_UsbDrvInfo.dma_callback[index] = KAL_FALSE;
#if defined(DRV_USB_IP_V2)
g_UsbDrvInfo.dma_pktlength[index] = 0;
#endif
#endif
}
#if defined(DRV_USB_IP_V2)
/* dma and fast mode sequence parametes */
g_UsbDrvInfo.dma_tx_ep = 0;
g_UsbDrvInfo.dma_res_tx_ep = 0;
g_UsbDrvInfo.fast_mode_tx_ep = 0;
/* Error record */
g_UsbDrvInfo.error_count = 0;
g_UsbDrvInfo.error_reason = 0;
g_UsbDrvInfo.fm_error_reason = 0;
/* BDT */
WRITE_EP0_BDT(USB_BDT_RX, USB_BDT_EVEN, (USB_BDT_PTR)USB_BDT_RX0_EVEN);
WRITE_EP0_BDT(USB_BDT_RX, USB_BDT_ODD, (USB_BDT_PTR)USB_BDT_RX0_ODD);
WRITE_EP0_BDT(USB_BDT_TX, USB_BDT_EVEN, (USB_BDT_PTR)USB_BDT_TX0_EVEN);
WRITE_EP0_BDT(USB_BDT_TX, USB_BDT_ODD, (USB_BDT_PTR)USB_BDT_TX0_ODD);
WRITE_EPN_BDT(1, USB_BDT_RX, (USB_BDT_PTR)USB_BDT_RX1);
WRITE_EPN_BDT(1, USB_BDT_TX, (USB_BDT_PTR)USB_BDT_TX1);
WRITE_EPN_BDT(2, USB_BDT_RX, (USB_BDT_PTR)USB_BDT_RX2);
WRITE_EPN_BDT(2, USB_BDT_TX, (USB_BDT_PTR)USB_BDT_TX2);
WRITE_EPN_BDT(3, USB_BDT_RX, (USB_BDT_PTR)USB_BDT_RX3);
WRITE_EPN_BDT(3, USB_BDT_TX, (USB_BDT_PTR)USB_BDT_TX3);
/* EP0 parametes */
g_UsbDrvInfo.ep0_rx_even_odd = 0;
g_UsbDrvInfo.ep0_tx_even_odd = 0;
g_UsbDrvInfo.ep0_current_dir = 0;
g_UsbDrvInfo.ep0_tx_data01 = 0;
g_UsbDrvInfo.ep0_transaction_type = USB_EP0_TRANS_NONE;
/* EPn parametes */
for(index=0; index< MAX_INTR_EP_NUM; index++)
{
g_UsbDrvInfo.ep_in_enb_state[index] = USB_EP_DIS;
g_UsbDrvInfo.ep_out_enb_state[index] = USB_EP_DIS;
g_UsbDrvInfo.ep_in_max_data_size[index] = 0;
g_UsbDrvInfo.ep_out_max_data_size[index]