⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mmcoem.c

📁 WINDOWSCE4.2 ARM PXA255 SDMMC驱动程序源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
/*****************************************************************************
* FileName: MMCOEM.C
*
* SanDisk Host Developer's Toolkit
*
* Copyright (c) 1997 - 2000 SanDisk Corporation
* All rights reserved.
* This code may not be redistributed in source or linkable object form
* without the consent of its author.
*
* Description:
*
*       MMC platform specific routines.
*
******************************************************************************/

#include "sdapi.h"
#include "sdmmc.h"

extern void msWait(unsigned);

SDLOCAL MMC_CC MMCExchangeData(UCHAR odata, UCHAR *idata);
extern SDVOID setupMMcHostDataRegister(UINT16 cmdIndex, UINT16 *cmdDatContReg, UINT16 *noBlocks, UINT16 *blkLength);
#include <stdio.h>
#include "plx9054.h"
#include <xsc1.h>
#include <oalintr.h>
#include <nkintr.h>
#include <windows.h>
#include <blrbits.h>
#include "bcr.h"
#include "blrbits.h"
#include <oalintr.h>
#include <nkintr.h>
#include <xsc1bd.h>


#define SSTOP_TRANSMISSION       0x4C

HANDLE gSDMMCIntrEvent;
int data_trans_flag = 0;

UINT32  portAddress = 0;
INT16 driveSave = 0;

volatile	GPIO_REGS	*v_pGPIOReg	= NULL; 
volatile	MMC_REGS	*v_pMMCReg	= NULL;

#ifdef PLAT_LUBBOCK
	volatile    BLR_REGS    *v_pBLReg = NULL;
#endif

PVOID	  VirtualAllocCopy(unsigned size,char *str,PVOID pVirtualAddress);

/************************************************************************/
/*    PCI  Internal variables                                           */
/************************************************************************/
SDLOCAL INT16   noController = 0;
SDLOCAL ADAPTER myAdapters[N_CONTROLLERS];

/* Function prototypes */
SDBOOL mmcAdapterInfo(INT16 controller, UINT32 *pPort, INT16 *pIntr);
void hw_powerup(void);
void hw_powerdown(void);
void hw_mmc_hex_led(DWORD );


void hw_mmc_hex_led(DWORD dis)
{
#ifdef PLAT_LUBBOCK
	 v_pBLReg->hex_led=dis;
#endif
}


void hw_powerdown()
{
	if(data_trans_flag == 1)
             	while(!(v_pMMCReg->stat & 0x00000800));
        stopMMCClock();
	

}

void hw_powerup()
{
	RETAILMSG(1, (TEXT("power up\r\n")));
        startMMCClock();
}
/**************************** MMC Controller ********************************/
/****************************************************************************/

SDVOID MMCSelectController(INT16 ctrlNo, INT16 phys_drive)
{
	return;
}


/****************************************************************************
* Name: mmc_hw_init - Initialize MMC hardware
*
* Description:
*       MMC controller intialization
*
* Input:
*       controller_no   Controller number
*
* Output:
*       None
*
* Return:
*       None
*
****************************************************************************/
SDVOID mmc_hw_init(INT16 ctrlno) /*__fn__*/
{
	 VOID	*SDMMCIntrEvent;    

#ifdef PLAT_SANDGATE
	// set the Board Control Register values
	set_BCRVal(BCR_SD_MMC_ON, 0, FALSE);
	msWait(1000);
#endif

#ifdef PLAT_LUBBOCK 
      v_pBLReg = (BLR_REGS *)VirtualAllocCopy(sizeof(BLR_REGS),"FPGA service", (PVOID)FPGA_REGS_BASE_U_VIRTUAL);
#endif
//    RETAILMSG(1, (TEXT("mmc_hw_init is entered\r\n")));													//do some stuff here
	SDMMCIntrEvent = CreateEvent(NULL, FALSE, FALSE, NULL);

	v_pGPIOReg = (volatile GPIO_REGS *)VirtualAllocCopy(0x400,(char *)TEXT("mmc_hw_init gpio regs"),
														(PVOID)GPIO_BASE_U_VIRTUAL); //just modify one line.
	if (!v_pGPIOReg) 
		return ;

	v_pMMCReg = (volatile MMC_REGS *)VirtualAllocCopy(0x400,(char *)TEXT("TouchPanelEnable: GPIO_BASE_U_VIRTUAL"),
													 (PVOID)MMC_BASE_U_VIRTUAL);
	if (!v_pMMCReg) 
		return;

//   configure GPIO to enable the MMC controller

#ifdef SABINAL
// COMMENTED OUT AS IS NO LONGER NECESSARY FOR B0 steppings and greater of Dalhart processors!!!!
//#ifdef DALHART
#ifdef B_STEP_PXA2X0
    v_pGPIOReg->GPDR_x |= GPIO_6 ;				// set the direction for MMCCLK
	v_pGPIOReg->GAFR0_x |= GPIO_6_AF1_MMCCLK;	// set alternate function for gpio 6 MMCCLK
#else
    v_pGPIOReg->GPDR_y |= GPIO_53 ;				// set the direction for MMCCLK
	v_pGPIOReg->GAFR1_y = (v_pGPIOReg->GAFR1_y & 0xFFFFF3FF) | GPIO_53_AF1_MMCCLK;	// set alternate function for gpio 53 MMCCLK
#endif //B_STEP_PXA2X0
#else
	v_pGPIOReg->GPDR_x |= GPIO_6 ;				// set the direction for MMCCLK
	v_pGPIOReg->GAFR0_x |= GPIO_6_AF1_MMCCLK;	// set alternate function for gpio 6 MMCCLK
#endif //sabinal

	msWait(20);   //wait 1ms per MMC specification.

	v_pMMCReg->imask = 0x7F;			// enable all interrupts

	gSDMMCIntrEvent = CreateEvent(NULL, FALSE, FALSE, TEXT("SDMMC"));
	

	if (!(InterruptInitialize(SYSINTR_SDMMC, gSDMMCIntrEvent, NULL, 0))) 
	{
		RETAILMSG(1, (TEXT("SDMMC IntrInit Failed\r\n")));
 		//return FALSE;		
	}
	


//	RETAILMSG(1, (TEXT("Finished mmc_hw_init\r\n")));
//	test_mmc();
    return;

}


/**************************************************************************
* Name: stopMMCClock - Stop the MMC Host controller clock
*
* Description:
*       The clocks of the MMC Host controller is stopped.      
*
* Input:
*       portAddress     Controller base address
*
* Output:
*       Stopping the MMC Host clock.
*
* Return:
*       None
*
**************************************************************************/
SDBOOL stopMMCClock(SDVOID)
{
    UINT16  dTime;
    UINT32  dStatus;

    /* Disable MMC clock. */

	v_pMMCReg->strpc = STOP_CLOCK;
    dTime = 0x200;
    dStatus = 0;

    /* Check status register */
	dStatus = v_pMMCReg->stat;

    while ( dTime )
    {
		dStatus = v_pMMCReg->stat;
        dTime--;
        if ( !(dStatus & CLOCK_ENABLE) )
            return YES;
    }

    return NO;
}


/**************************************************************************
* Name: startMMCClock - Start the MMC Host Controller clock
*
* Description:
*       The MMC clock is started by the.       
*
* Input:
*       portAddress     Controller bas address
*
* Output:
*       Starting the clock.
*
* Return:
*       None
*
**************************************************************************/
SDVOID startMMCClock(SDVOID)
{
    /* Start the MMC clock. */
	v_pMMCReg->strpc = START_CLOCK;
}


/**************************************************************************
* Name: setMMCClockRate - Set the MMC clock rate
*
* Description:
*       Stop the MMC clock and set the new clock rate       
*       then start the clock again.       
*
* Input:
*       ClockRate       Clock rate
*
* Output:
*       Set new clock rate.
*
* Return:
*       YES if successful
*       NO if failure
*
**************************************************************************/
SDBOOL setMMCClockRate(UINT16 ClockRate)
{
    /* The clock needs to be stopped if currently active */
    if ( !stopMMCClock() )  /* STOP MMC CLOCK */
	{
		RETAILMSG(1, (TEXT("fail to stopMMCClock()\r\n")));
        return NO;
	}

    /* Set the clock rate */
	v_pMMCReg->clkrt  = ClockRate;
	v_pMMCReg->resto  = 0x0000007f;
	v_pMMCReg->rdto = 0xFFFF;
  
    /* Start the clock again */
    startMMCClock();        /* START MMC CLOCK */

    return YES;
}

#define GO_IDLE_STATE  0x0
#define INIT_80CLCOK   (1u << 6)
/**************************************************************************
* Name: startMMC80Clocks - Start the MMC devices
*
* Description:
*       The 80 clocks is required to start initializing the       
*       devices.       
*
* Input:
*       ctrlNo  Controller number
*
* Output:
*       Sending out 80 clocks.
*
* Return:
*       None
*
**************************************************************************/
SDVOID startMMC80Clocks(INT16 ctrlNo)
{
    UINT16  ij, dStatus;

    ij = (UINT16)ctrlNo;    /* Make compiler happy! */

    //Send the 80 clocks to start all devices      
 
	if ( !stopMMCClock() )  /* STOP MMC CLOCK */
        return;

	v_pMMCReg->cmd    = GO_IDLE_STATE;	//CMD0 
	v_pMMCReg->argh   = 0x00000000;	
	v_pMMCReg->argl   = 0x00000000;	
	v_pMMCReg->cmdat  = RESPONSE_TYPE_R0 |SEND_80_CLOCKS;	//set init bit for initial 80 clocks, expect response 3
	v_pMMCReg->strpc = START_CLOCK;	//start clock
	startMMCClock();

    for (ij = 0; ij < 0x200; ij++ )
    {
         dStatus = v_pMMCReg->stat;
         if ( dStatus & END_CMD_RES )
         {
              break;
         }
    }
        
	//Ramp-up time 
    OS_WAIT(200);
}


/**************************************************************************
* Name: resetMMCController - Reset MMC host controller
*
* Description:
*       Writing to the port with any value will reset the
*       MMC Host controller
*
* Input:
*       ctrlNo  Controller number
*
* Output:
*       Reset the controller
*
* Return:
*       None
*
**************************************************************************/
SDVOID resetMMCController(UINT16 ctrlNo)
{
 
}
    

/**************************************************************************
* Name: setupMMCSetupInterrupt - Enable MMC interrupt setting
*
* Description:
*
* Input:
*       bitMask         set the bis to 1's which need to be enabled
*
* Output:
*
* Return:
*
* Function: mmc interrupt enable subroutine
*
*************************************************************************/
SDVOID SetupMMCInterrupt(UINT16 bitMask)
{
    UINT16  dtmp;

    /* Set interrupt mask value */
	dtmp = v_pMMCReg->imask;
#if (USE_INTERRUPTS)
    dtmp &= 0x0F;
    dtmp |= bitMask;
#else
    dtmp = bitMask;
    dtmp &= 0;
#endif

	v_pMMCReg->imask = dtmp;
}


/**************************************************************************
* Name: disableMMCInterrupt - Disable MMC interrupt setting
*
* Description:
*
* Input:
*       unMaskBit       set the bis to 1's which need to be disabled
*
* Output:
*
* Return:
*
* Function: mmc interrupt disable subroutine
**************************************************************************/
SDVOID disableMMCInterrupt(UINT16 unMaskBit)
{
    UINT16  dtmp;

    /* Get Interrupt Mask value */
       dtmp = v_pMMCReg->imask;
    /* Mask off unwanted interrupts. */
    dtmp &= (~unMaskBit);
	v_pMMCReg->imask = dtmp;
}


/*********************** MMC command and response ***************************/
/****************************************************************************/


/***************************************************************************
* Name: MMCSendCommand
*
* Description:
*
* Input:

⌨️ 快捷键说明

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