www.pudn.com > iMx31_WCE600.rar > nfc.cpp


//------------------------------------------------------------------------------ 
// 
//  Copyright (C) 2004-2007, Freescale Semiconductor, Inc. All Rights Reserved. 
//  THIS SOURCE CODE, AND ITS USE AND DISTRIBUTION, IS SUBJECT TO THE TERMS 
//  AND CONDITIONS OF THE APPLICABLE LICENSE AGREEMENT 
// 
//------------------------------------------------------------------------------ 
#include "bsp.h" 
 
 
//----------------------------------------------------------------------------- 
// External Functions 
 
 
//----------------------------------------------------------------------------- 
// External Variables 
extern "C" PCSP_NANDFC_REGS g_pNFC; 
 
 
//----------------------------------------------------------------------------- 
// Defines 
 
 
//----------------------------------------------------------------------------- 
// Types 
 
 
//----------------------------------------------------------------------------- 
// Global Variables 
 
 
//----------------------------------------------------------------------------- 
// Local Variables 
 
 
//----------------------------------------------------------------------------- 
// Local Functions 
 
//----------------------------------------------------------------------------- 
// 
//  Function: NFCMapRegister 
// 
//  This function maps the NFC register from physical address to virtual 
//  address. 
// 
//  Parameters: 
//      None. 
// 
//  Returns: 
//      Returns TRUE on success. Returns FALSE on failure. 
// 
//----------------------------------------------------------------------------- 
BOOL NFCMapRegister(VOID) 
{ 
    // Map peripheral physical address to virtual address 
    g_pNFC = (PCSP_NANDFC_REGS) OALPAtoUA(CSP_BASE_REG_PA_NANDFC); 
 
    // Check if virtual mapping failed 
    if (g_pNFC == NULL) 
    { 
        OALMSG(1, (_T("NFCMapRegister:  MmMapIoSpace failed!\r\n"))); 
        return FALSE; 
    } 
  
    return TRUE;    
} 
 
//----------------------------------------------------------------------------- 
// 
//  Function: NFCAlloc 
// 
//  This function configures interupts, and create interrupt service thread(IST) 
//  for the driver 
// 
//  Parameters: 
//      None. 
// 
//  Returns: 
//      Returns TRUE on success. Returns FALSE on failure. 
// 
//----------------------------------------------------------------------------- 
BOOL NFCAlloc(VOID) 
{ 
    // For EBOOT, no interrupt is supported 
    return TRUE; 
} 
 
 
//----------------------------------------------------------------------------- 
// 
// Function: NFCSetPagesize 
// 
// This function will set the NFMS bit of register RCSR in CCM module. For large 
// page size nand flash, bit NFMS should be set to 1. 
//  
// Parameters: 
//      bLargePage 
//          [in] - Set TRUE for large page size nand flash, Set FALSE for small 
//          page size nand flash. 
// 
// Returns: 
//      None. 
// 
//----------------------------------------------------------------------------- 
BOOL NFCSetPagesize(BOOL bLargePage) 
{ 
   PCSP_CCM_REGS pCCM; 
    
   // Map peripheral physical address to virtual address 
   pCCM = (PCSP_CCM_REGS)OALPAtoUA(CSP_BASE_REG_PA_CCM); 
 
    // Check if virtual mapping failed 
    if (pCCM == NULL) 
    { 
        OALMSG(1, (_T("NFCSetPagesize: MmMapIoSpace failed!\r\n"))); 
        return FALSE; 
    } 
  
    if(bLargePage) 
        INSREG32BF(&pCCM->RCSR, CCM_RCSR_NFMS, 1); 
    else 
        INSREG32BF(&pCCM->RCSR, CCM_RCSR_NFMS, 0); 
         
    return TRUE; 
} 
 
 
//----------------------------------------------------------------------------- 
// 
//  Function:  NFCWait 
// 
//  This functions waits for the pending NANDFC opeation to complete.   
// 
//  Parameters: 
//      bPoll 
//          [in] - Ignored.  Bootloader always polls for completion. 
// 
//  Returns: 
//      None. 
// 
//----------------------------------------------------------------------------- 
VOID NFCWait(BOOL bPoll) 
{ 
    // Remove-W4: Warning C4100 workaround 
    UNREFERENCED_PARAMETER(bPoll); 
 
    while (!(INREG16(&g_pNFC->NAND_FLASH_CONFIG2) & CSP_BITFMASK(NANDFC_NAND_FLASH_CONFIG2_INT))); 
     
    // Clear the NANDFC interrupt 
    CLRREG16(&g_pNFC->NAND_FLASH_CONFIG2,  
             CSP_BITFMASK(NANDFC_NAND_FLASH_CONFIG2_INT)); 
 
} 
 
 
//----------------------------------------------------------------------------- 
// 
//  Function:  NFCSetClock 
// 
//  This enables/disable clocks for the NANDFC. 
// 
//  Parameters: 
//      None. 
// 
//  Returns: 
//      Returns TRUE on success. Returns FALSE on failure. 
// 
//----------------------------------------------------------------------------- 
BOOL NFCSetClock(BOOL bEnabled) 
{ 
    // TLSbo89535: Warning C4100 workaround 
    UNREFERENCED_PARAMETER(bEnabled); 
 
    // Bootloader does not use clock gating, just return success 
    return TRUE; 
}