www.pudn.com > Sdio.rar > platspecific.c


/*++ 
Copyright (c) 2005  BSQUARE Corporation.  All rights reserved. 
 
Module Name: 
 
    platspecific.c 
 
Module Description: 
 
    This file contains platform specific functions for the SD driver. 
 
Author: 
 
    Ian Rae 3-Feb-2005 
 
Notes: 
 
Revision History: 
 
--*/ 
 
#include "sdcardddk.h" 
#include "sdhcd.h" 
#include "sdio.h" 
#include  
 
 
// Db1200 has just the one slot 
int SDIOPlatNumSlots() 
{ 
	return 1; 
} 
 
 
// card insertion interrupts 
// mapping BCSR etc 
SD_API_STATUS SDIOPlatInit(PSDIO_HW_CONTEXT pController) 
{ 
    SD_API_STATUS    status = SD_API_STATUS_SUCCESS; 
    PHYSICAL_ADDRESS PhysAddr; 
	HANDLE           hGPIO; 
 
	PhysAddr.HighPart = 0; 
	PhysAddr.LowPart = BCSR_PHYSADDR; 
 
	pController->pPlatSpecificPtr = MmMapIoSpace(PhysAddr, 
	                                             sizeof(BCSR), 
												 FALSE); 
 
	if (NULL==pController->pPlatSpecificPtr) { 
		DbgPrintZo(SDCARD_ZONE_ERROR,(TEXT("SDIOPlatInit - failed to map BCSR\n"))); 
        status = SD_API_STATUS_INSUFFICIENT_RESOURCES; 
		goto ErrorReturn; 
	} 
	 
 
	hGPIO = GPIO_Init(); 
 
    if(hGPIO==INVALID_HANDLE_VALUE) { 
        DbgPrintZo(SDCARD_ZONE_ERROR,(L"SDIOPlatInit -  Can not open GPIO device\r\n")); 
        status = SD_API_STATUS_INSUFFICIENT_RESOURCES; 
		goto ErrorReturn; 
    } 
 
       // connect slot 0 insertion interrupt 
    pController->Slots[0].InsertionSysIntr = InterruptConnect(Internal, 
                                                              0, 
                                                              (HWINTR_EXT_SD0INSERT << 8) | HWINTR_EXT_SD0EJECT, 
                                                              0); 
 
    if (SYSINTR_NOP==pController->Slots[0].InsertionSysIntr) { 
        DbgPrintZo(SDCARD_ZONE_ERROR,(TEXT("InterruptConnect returned SYSINTR_NOP\r\n"))); 
        status = SD_API_STATUS_INSUFFICIENT_RESOURCES; 
		goto ErrorReturn; 
    } 
 
	// Set Pinfunc for SD0 
	GPIO_SetPinFunction(hGPIO,SYS_PINFUNC_S0A|SYS_PINFUNC_S0B); 
	GPIO_ClearPinFunction(hGPIO,SYS_PINFUNC_S0C); 
 
ErrorReturn: 
	if (hGPIO) { 
		CloseHandle(hGPIO); 
	} 
 
	return status; 
} 
 
// un-mapping BCSR etc 
SD_API_STATUS SDIOPlatDeinit(PSDIO_HW_CONTEXT pController) 
{ 
    SD_API_STATUS status = SD_API_STATUS_SUCCESS; 
 
	if (NULL!=pController->pPlatSpecificPtr) { 
		MmUnmapIoSpace(pController->pPlatSpecificPtr,sizeof(BCSR)); 
		pController->pPlatSpecificPtr = NULL; 
	} 
 
	return status; 
} 
 
SD_API_STATUS SDIOPlatPower(PSDIO_HW_CONTEXT pController, BOOL PowerOn, ULONG Slot) 
{ 
	USHORT tmp; 
	pBCSR pDb1200BCSR = pController->pPlatSpecificPtr; 
 
	tmp = READ_REGISTER_USHORT((PUSHORT)&pDb1200BCSR->specific); 
 
	if (PowerOn) { 
		tmp |= BCSR_SPECIFIC_SD0PWR; 
	} else { 
		tmp &= ~BCSR_SPECIFIC_SD0PWR; 
	} 
 
	WRITE_REGISTER_USHORT((PUSHORT)&pDb1200BCSR->specific,tmp); 
 
	return SD_API_STATUS_SUCCESS; 
} 
 
BOOL SDIOPlatCardWriteProteced(PSDIO_HW_CONTEXT pController, ULONG Slot) 
{ 
	pBCSR pDb1200BCSR = pController->pPlatSpecificPtr; 
 
	if (BCSR_STATUS_SD0WP & READ_REGISTER_USHORT((PUSHORT)&pDb1200BCSR->status)) { 
		return TRUE; 
	} else { 
		return FALSE; 
	} 
} 
 
BOOL SDIOPlatCardInserted(PSDIO_HW_CONTEXT pController, ULONG Slot) 
{ 
	pBCSR pDb1200BCSR = pController->pPlatSpecificPtr; 
 
	if (BCSR_BIC_SD0INSERT & READ_REGISTER_USHORT((PUSHORT)&pDb1200BCSR->sigstatus)) { 
		// Disable insertion interrupt, enable ejection interrupt 
		WRITE_REGISTER_USHORT((PUSHORT)&pDb1200BCSR->intclrenable,BCSR_BIC_SD0INSERT); 
		WRITE_REGISTER_USHORT((PUSHORT)&pDb1200BCSR->intsetenable,BCSR_BIC_SD0EJECT); 
		return TRUE; 
	} else { 
		// Disable ejection interrupt, enable insertion interrupt 
		WRITE_REGISTER_USHORT((PUSHORT)&pDb1200BCSR->intsetenable,BCSR_BIC_SD0INSERT); 
		WRITE_REGISTER_USHORT((PUSHORT)&pDb1200BCSR->intclrenable,BCSR_BIC_SD0EJECT); 
		return FALSE; 
	} 
}