usbdl_usb_drv.c

来自「MTK 平台启动源码」· C语言 代码 · 共 2,365 行 · 第 1/5 页

C
2,365
字号
/*****************************************************************************
*  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] = 0;
		g_UsbDrvInfo.ep_in_data01[index] = 0;
		g_UsbDrvInfo.ep_out_data01[index] = 0;
	}
#endif	
}

void USB_ResetDrv_Info(void)
{
	kal_uint32 index;
	
	g_UsbDrvInfo.power_state = USB_STATE_NORMAL;
//	g_UsbDrvInfo.is_unMaskUSB = KAL_TRUE;
//	g_UsbDrvInfo.is_ProUSBHISR = KAL_FALSE;

	for(index=0; index< MAX_INTR_EP_NUM; index++)
	{
		g_UsbDrvInfo.ep_tx_stall_status[index] = KAL_FALSE;
		g_UsbDrvInfo.ep_rx_stall_status[index] = KAL_FALSE;
#if defined(DRV_USB_IP_V3)
		USBDMA_Stop(index+1);
//		USBDMA_PPStop(index+1);
#endif
	}

#if defined(DRV_USB_IP_V3)
	//clear interrupt. write 0 clear
	DRV_WriteReg32(USB_DMAINTR, 0x00);
#endif

	#if 0
/* under construction !*/
/* under construction !*/
/* under construction !*/
#if (defined(DRV_USB_IP_V1)||defined(DRV_USB_IP_V2))
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#endif
/* under construction !*/
#if defined(DRV_USB_IP_V3)
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#else
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#if defined(DRV_USB_IP_V2)
/* under construction !*/
#endif
#endif
/* under construction !*/
	#endif /* USBACM_TX_WITHOUT_DMA */ 

#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;

	/* 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] = 0;
		g_UsbDrvInfo.ep_in_data01[index] = 0;
		g_UsbDrvInfo.ep_out_data01[index] = 0;
	}	
#endif	
}

/* register interrupt handler*/
void USB_Register_Drv_Info(USB_DRV_HDLR_TYPE type, kal_uint32 ep_num, usb_drv_intr_handler_ptr hdlr)
{
	if(ep_num > MAX_INTR_EP_NUM)
		EXT_ASSERT(0, ep_num, MAX_INTR_EP_NUM, 0);
	
	switch(type)
	{
	case USB_DRV_HDLR_RESET:
		g_UsbDrvInfo.reset_hdlr = hdlr;
		break;
	case USB_DRV_HDLR_EP0:
		g_UsbDrvInfo.ep0_hdlr = hdlr;
		break;
	case USB_DRV_HDLR_EP_TX:
		g_UsbDrvInfo.ep_tx_hdlr[ep_num-1]= hdlr;
		break;
	case USB_DRV_HDLR_EP_RX:
		g_UsbDrvInfo.ep_rx_hdlr[ep_num-1]= hdlr;
		break;	
	}
}

kal_uint32 USB_Get_HW_Error_Count(void)
{
#if defined(DRV_USB_IP_V3)
	return 0;
#elif defined(DRV_USB_IP_V2)
	return g_UsbDrvInfo.error_count;
#elif defined(DRV_USB_IP_V1)
	return 0;
#endif
}

#if 0
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#endif

/* get stall status for endpoint */
kal_bool USB_Get_EP_Stall_Status(kal_uint8 ep_num, USB_EP_TYPE direction)
{
	if(ep_num > MAX_INTR_EP_NUM)
		EXT_ASSERT(0, ep_num, MAX_INTR_EP_NUM, 0);
	
	if(direction == USB_TX_EP_TYPE)
	{
		return g_UsbDrvInfo.ep_tx_stall_status[ep_num-1];
	}
	else
	{
		return g_UsbDrvInfo.ep_rx_stall_status[ep_num-1];
	}
}

/************************************************************
	system ctrl functions
*************************************************************/

#if 0
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#if (defined(DRV_USB_IP_V1)||defined(DRV_USB_IP_V3))
/* under construction !*/
#endif
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#if defined(DRV_USB_IP_V3)
/* under construction !*/
#else
/* under construction !*/
#endif
/* under construction !*/
#if defined(DRV_USB_IP_V2)
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#elif defined(DRV_USB_IP_V1)
/* under construction !*/
#endif
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#if defined(DRV_USB_IP_V1)
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?