?? sdiofeat.cpp
字號:
return SD_API_STATUS_INVALID_DEVICE_REQUEST;
}
}
// Changing the bus width is tricky when SDIO interrupts are
// enabled. In 1-bit mode, DAT[1] is used as the interrupt line.
// In 4-bit mode, DAT[1] is used for data and interrupts. If
// we change from 1-bit mode to 4-bit mode while interrupts are
// occurring (like when a BTH mouse is being moved franticly), we
// need to disable SDIO interrupts while we are changing the mode
// on both the host controller and the card. Otherwise an interrupt in
// the middle could confuse the host controller.
PSD_INTERRUPT_CALLBACK pInterruptCallBack = NULL;
if ( (Device_SD_IO == m_DeviceType) && m_sdSlot.IsSlotInterruptOn() &&
(m_CardInterfaceEx.InterfaceModeEx.bit.sd4Bit != CardInterfaceEx.InterfaceModeEx.bit.sd4Bit) ) {
// Temporarily disable SDIO interrupts
pInterruptCallBack = m_SDCardInfo.SDIOInformation.pInterruptCallBack;
DEBUGCHK(pInterruptCallBack);
SDIOConnectDisconnectInterrupt( NULL, FALSE);
}
SD_CARD_INTERFACE_EX CardInterfaceExBackup = m_CardInterfaceEx;
BOOL isRestore = FALSE;
while (TRUE) {
SD_API_STATUS inStatus = SD_API_STATUS_SUCCESS ;
// check for success
BOOL fContinue = TRUE;
if (SD_API_SUCCESS(inStatus)) {
// set the card interface for device's slot
inStatus = m_sdSlot.GetHost().SlotSetupInterface(m_sdSlot.GetSlotIndex(),&CardInterfaceEx);
//m_sdSlot.GetHost().SlotOptionHandler(m_sdSlot.GetSlotIndex(), SDHCDSetSlotInterface, &CardInterface, sizeof(CardInterface));
fContinue = SD_API_SUCCESS(inStatus) ;
}
for (DWORD dwIndex = 0; dwIndex < SD_MAXIMUM_DEVICE_PER_SLOT && fContinue; dwIndex++) {
CSDDevice * pDevice = m_sdSlot.GetFunctionDevice(dwIndex);
if (pDevice != NULL) {
inStatus = pDevice->SetCardInterface(&CardInterfaceEx);
if (!SD_API_SUCCESS(inStatus)) {
fContinue = FALSE;
}
pDevice->DeRef();
}
}
if (!SD_API_SUCCESS(inStatus) &&!isRestore ) {
ASSERT(FALSE);
status = inStatus;
CardInterfaceEx = CardInterfaceExBackup;
isRestore = TRUE;
}
else
break;
}
if (pInterruptCallBack) {
// Re-enable SDIO interrupts
DEBUGCHK(!m_sdSlot.IsSlotInterruptOn());
DEBUGCHK(Device_SD_IO == m_DeviceType);
SDIOConnectDisconnectInterrupt(pInterruptCallBack, TRUE);
}
return status;
}
///////////////////////////////////////////////////////////////////////////////
// SDSetCardFeature - Set card feature
// Input: hDevice - SD Device Handle
// CardFeature - Card Feature to set
// StructureSize - size of card feature structure
// Output: pCardInfo - Information for the feature
// Return: SD_API_STATUS code
// Notes: This function is provided to set various card features
// in a thread safe manner. SDIO cards utilize shared register sets
// between functions. This requires that the
// register state be preserved between functions that can be
// controlled in separate thread contexts.
// This function can potentially block by issuing synchronous bus
// request. This function must not be called from a bus request callback
///////////////////////////////////////////////////////////////////////////////
SD_API_STATUS CSDDevice::SDSetCardFeature_I(SD_SET_FEATURE_TYPE CardFeature,PVOID pCardInfo,ULONG StructureSize)
{
SD_API_STATUS status = SD_API_STATUS_SUCCESS; // intermediate status
PSD_DATA_TRANSFER_CLOCKS pClocks; // data transfer clocks variable
switch (CardFeature) {
case SD_IO_FUNCTION_ENABLE:
if ((sizeof(SD_IO_FUNCTION_ENABLE_INFO) != StructureSize) || (NULL == pCardInfo)) {
DEBUGMSG(SDCARD_ZONE_ERROR, (TEXT("SDSetCardFeature: SD_IO_FUNCTION_ENABLE - Invalid params \n")));
return SD_API_STATUS_INVALID_PARAMETER;
}
if (Device_SD_IO != m_DeviceType) {
DEBUGMSG(SDCARD_ZONE_ERROR, (TEXT("SDSetCardFeature: device is not SDIO ! \n")));
return SD_API_STATUS_INVALID_PARAMETER;
}
status = SDEnableDisableFunction((PSD_IO_FUNCTION_ENABLE_INFO)pCardInfo, TRUE);
break;
case SD_IO_FUNCTION_DISABLE:
if (Device_SD_IO != m_DeviceType) {
DEBUGMSG(SDCARD_ZONE_ERROR, (TEXT("SDSetCardFeature: device is not SDIO ! \n")));
return SD_API_STATUS_INVALID_PARAMETER;
}
status = SDEnableDisableFunction(NULL, FALSE);
break;
case SD_IO_FUNCTION_HIGH_POWER:
if (Device_SD_IO != m_DeviceType) {
DEBUGMSG(SDCARD_ZONE_ERROR, (TEXT("SDSetCardFeature: device is not SDIO ! \n")));
return SD_API_STATUS_INVALID_PARAMETER;
}
status = SDFunctionSelectPower(FALSE);
break;
case SD_IO_FUNCTION_LOW_POWER:
if (Device_SD_IO != m_DeviceType) {
DEBUGMSG(SDCARD_ZONE_ERROR, (TEXT("SDSetCardFeature: device is not SDIO ! \n")));
return SD_API_STATUS_INVALID_PARAMETER;
}
status = SDFunctionSelectPower(TRUE);
break;
case SD_INFO_POWER_CONTROL_STATE:
if ((sizeof(FUNCTION_POWER_STATE) != StructureSize) || (NULL == pCardInfo)) {
DEBUGMSG(SDCARD_ZONE_ERROR, (TEXT("SDSetCardFeature: SD_INFO_POWER_CONTROL_STATE - Invalid params \n")));
return SD_API_STATUS_INVALID_PARAMETER;
}
if (Device_SD_IO != m_DeviceType) {
DEBUGMSG(SDCARD_ZONE_ERROR, (TEXT("SDSetCardFeature: device is not SDIO ! \n")));
return SD_API_STATUS_INVALID_PARAMETER;
}
status = GetFunctionPowerState((PFUNCTION_POWER_STATE)pCardInfo);
break;
case SD_IO_FUNCTION_SET_BLOCK_SIZE:
if ((sizeof(DWORD) != StructureSize) || (NULL == pCardInfo)) {
DEBUGMSG(SDCARD_ZONE_ERROR, (TEXT("SDSetCardFeature: SD_IO_FUNCTION_SET_BLOCK_SIZE - Invalid params \n")));
return SD_API_STATUS_INVALID_PARAMETER;
}
if (Device_SD_IO != m_DeviceType) {
DEBUGMSG(SDCARD_ZONE_ERROR, (TEXT("SDSetCardFeature: device is not SDIO ! \n")));
return SD_API_STATUS_INVALID_PARAMETER;
}
status = SDSetFunctionBlockSize(*((DWORD *)pCardInfo));
break;
case SD_SET_DATA_TRANSFER_CLOCKS:
if ((sizeof(SD_DATA_TRANSFER_CLOCKS) != StructureSize) || (NULL == pCardInfo)) {
DEBUGMSG(SDCARD_ZONE_ERROR, (TEXT("SDSetCardFeature: SD_SET_DATA_TRANSFER_CLOCKS - Invalid params \n")));
return SD_API_STATUS_INVALID_PARAMETER;
}
pClocks = (PSD_DATA_TRANSFER_CLOCKS)pCardInfo;
m_SDCardInfo.SDMMCInformation.DataAccessReadClocks = pClocks->ReadClocks;
m_SDCardInfo.SDMMCInformation.DataAccessWriteClocks = pClocks->WriteClocks;
status = SD_API_STATUS_SUCCESS;
break;
case SD_IS_FAST_PATH_AVAILABLE:
status = SD_API_STATUS_SUCCESS;
break;
case SD_FAST_PATH_DISABLE:
// Disable the use of Fast-Path for testing.
m_SDCardInfo.SDIOInformation.Flags |= FSTPTH_DISABLE;
status = SD_API_STATUS_SUCCESS;
break;
case SD_FAST_PATH_ENABLE:
#ifdef _FASTPATH_ENABLE_
// Always use Fast-Path operations.
m_SDCardInfo.SDIOInformation.Flags &= ~ FSTPTH_DISABLE;
#else
m_SDCardInfo.SDIOInformation.Flags |= FSTPTH_DISABLE;
#endif
status = SD_API_STATUS_SUCCESS;
break;
case SD_IS_SOFT_BLOCK_AVAILABLE:
status = SD_API_STATUS_SUCCESS;
break;
case SD_SOFT_BLOCK_FORCE_UTILIZATION:
// Always use Soft-Block operations.
m_SDCardInfo.SDIOInformation.Flags |= SFTBLK_USE_ALWAYS;
status = SD_API_STATUS_SUCCESS;
break;
case SD_SOFT_BLOCK_DEFAULT_UTILIZATON:
// Use hardware multi-block operations if supported by the card,
// otherwise use Soft-Block.
m_SDCardInfo.SDIOInformation.Flags &= ~ SFTBLK_USE_ALWAYS;
status = SD_API_STATUS_SUCCESS;
break;
case SD_SET_CARD_INTERFACE: {
if ((sizeof(SD_CARD_INTERFACE) != StructureSize) || (NULL == pCardInfo)) {
DEBUGMSG(SDCARD_ZONE_ERROR, (TEXT("SDSetCardFeature: SD_SET_CARD_INTERFACE - Invalid params \n")));
return SD_API_STATUS_INVALID_PARAMETER;
}
PSD_CARD_INTERFACE pCardInterface = (PSD_CARD_INTERFACE) pCardInfo ;
SD_CARD_INTERFACE_EX sdCardInterfaceEx;
memset (&sdCardInterfaceEx, 0, sizeof(sdCardInterfaceEx));
sdCardInterfaceEx.ClockRate = pCardInterface->ClockRate;
sdCardInterfaceEx.InterfaceModeEx.bit.sdWriteProtected = (pCardInterface->WriteProtected?1:0);
sdCardInterfaceEx.InterfaceModeEx.bit.sd4Bit = (pCardInterface->InterfaceMode == SD_INTERFACE_SD_4BIT?1:0) ;
status =SetCardFeature_Interface(sdCardInterfaceEx);
break;
}
case SD_SET_CARD_INTERFACE_EX: {
if ((sizeof(SD_CARD_INTERFACE_EX) != StructureSize) || (NULL == pCardInfo)) {
DEBUGMSG(SDCARD_ZONE_ERROR, (TEXT("SDSetCardFeature: SD_SET_CARD_INTERFACE_EX - Invalid params \n")));
return SD_API_STATUS_INVALID_PARAMETER;
}
status = SetCardFeature_Interface(*(PSD_CARD_INTERFACE_EX)pCardInfo);
break;
}
case SD_SET_CLOCK_STATE_DURING_IDLE:
if ( (sizeof(BOOL) != StructureSize) || (NULL == pCardInfo) ) {
DEBUGMSG(SDCARD_ZONE_ERROR,(TEXT("SDSetCardFeature: SD_SET_CLOCK_ON_DURING_IDLE - Invalid params \n")));
return SD_API_STATUS_INVALID_PARAMETER;
}
// prompt the host to turn on or off the clock during the idle state based on the client's
// request.
status = m_sdSlot.GetHost().SlotOptionHandler(m_sdSlot.GetSlotIndex(), SDHCDSetClockStateDuringIdle, pCardInfo,StructureSize);
DEBUGMSG(SDCARD_ZONE_INFO, (TEXT("SDSetCardFeature: SDHCDSetClockStateDuringIdle finished with status: %x\n"),
status));
break;
case SD_CARD_FORCE_RESET:
DbgPrintZo(SDCARD_ZONE_INIT, (TEXT("SDSetCardFeature: call SD_CARD_FORCE_RESET \n")));
m_sdSlot.PostEvent(SlotResetRequest);
break;
case SD_CARD_SELECT_REQUEST:
// request made by client driver to select the card. The request will not be honored
// until all client drivers in this slot make such request.
{
BOOL bAllFunctionsRequestedCardSelect = TRUE;;
DbgPrintZo(SDCARD_ZONE_INIT,(TEXT("SDSetCardFeature: call SD_CARD_SELECT_REQUEST \n")));
m_bCardSelectRequest = TRUE;
NotifyClient(SDCardSelectRequest);
for (DWORD dwIndex = 0; dwIndex < SD_MAXIMUM_DEVICE_PER_SLOT; dwIndex++) {
CSDDevice * pDevice = m_sdSlot.GetFunctionDevice(dwIndex);
if (pDevice != NULL) {
if (pDevice->m_bCardSelectRequest == FALSE && pDevice->GetDeviceType()!= Device_Unknown ) {
bAllFunctionsRequestedCardSelect = FALSE;
}
pDevice->DeRef();
}
}
if (bAllFunctionsRequestedCardSelect == FALSE) {
DbgPrintZo(SDCARD_ZONE_INFO, (TEXT("SDSetCardFeature: SD_CARD_SELECT_REQUEST - request is pending\n")));
return SD_API_STATUS_PENDING;
}
DbgPrintZo(SDCARD_ZONE_INIT, (TEXT("SDSetCardFeature: SD_CARD_SELECT_REQUEST - request is processing\n")));
m_sdSlot.PostEvent(SlotSelectRequest);
}
break;
case SD_CARD_DESELECT_REQUEST:
{
BOOL bAllFunctionsRequestedCardDeselect= TRUE;;
DbgPrintZo(SDCARD_ZONE_INIT, (TEXT("SDSetCardFeature: call SD_CARD_DESELECT_REQUEST \n")));
if (!m_bCardDeselectRequest) {
m_bCardDeselectRequest = TRUE;
NotifyClient(SDCardDeselectRequest);
}
for (DWORD dwIndex = 0; dwIndex < SD_MAXIMUM_DEVICE_PER_SLOT; dwIndex++) {
CSDDevice * pDevice = m_sdSlot.GetFunctionDevice(dwIndex);
if (pDevice != NULL) {
if (pDevice->m_bCardDeselectRequest == FALSE && pDevice->GetDeviceType()!= Device_Unknown) {
bAllFunctionsRequestedCardDeselect = FALSE ;
}
pDevice->DeRef();
}
}
if (bAllFunctionsRequestedCardDeselect == FALSE) {
DbgPrintZo(SDCARD_ZONE_INFO, (TEXT("SDSetCardFeature: SD_CARD_DESELECT_REQUEST - request is pending\n")));
return SD_API_STATUS_PENDING;
}
DbgPrintZo(SDCARD_ZONE_INIT, (TEXT("SDSetCardFeature: SD_CARD_DESELECT_REQUEST - request is processing\n")));
m_sdSlot.PostEvent(SlotDeselectRequest);
}
break;
case SD_SET_SWITCH_FUNCTION: {
if (pCardInfo!=NULL && StructureSize >= sizeof(SD_CARD_SWITCH_FUNCTION)) {
PSD_CARD_SWITCH_FUNCTION psdSwitchFunction = (PSD_CARD_SWITCH_FUNCTION)pCardInfo;
status = SwitchFunction((PSD_CARD_SWITCH_FUNCTION)pCardInfo,FALSE);
}
}
break;
case SD_DMA_ALLOC_PHYS_MEM:
if (pCardInfo!=NULL && StructureSize >= sizeof(SD_HOST_ALLOC_FREE_DMA_BUFFER)) {
status = m_sdSlot.GetHost().SlotOptionHandler(m_sdSlot.GetSlotIndex(),SDHCAllocateDMABuffer, pCardInfo,sizeof(SD_HOST_ALLOC_FREE_DMA_BUFFER));
}
break;
case SD_DMA_FREE_PHYS_MEM:
if (pCardInfo!=NULL && StructureSize >= sizeof(SD_HOST_ALLOC_FREE_DMA_BUFFER)) {
status = m_sdSlot.GetHost().SlotOptionHandler(m_sdSlot.GetSlotIndex(),SDHCFreeDMABuffer, pCardInfo,sizeof(SD_HOST_ALLOC_FREE_DMA_BUFFER));
}
break;
default:
status = SD_API_STATUS_INVALID_PARAMETER;
break;
}
return status;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -