📄 sdhceventhandlers.cpp
字号:
// must get CID first in order to get the cards into the IDENT state.
// Check for SD I/O - only cards; will not have CID.
if (Device_SD_IO != BaseDeviceType) {
DEBUGMSG(SDBUS_ZONE_DEVICE, (TEXT("SDBusDriver: Getting registers from slot %d \n"),
pSlot->SlotIndex));
// for MMC, SD Memory and SD Combo cards, retreive the CID
status = SendSDCommand(pSlot->hDevice,
SD_CMD_ALL_SEND_CID,
0x00000000,
ResponseR2,
&response);
if (!SD_API_SUCCESS(status)){
return status;
}
DEBUGMSG(SDBUS_ZONE_DEVICE, (TEXT("SDBusDriver: Got CID from device in slot %d \n"),
pSlot->SlotIndex));
// update shadow registers
UpdateCachedRegisterFromResponse(pBaseDevice,
SD_INFO_REGISTER_CID,
&response);
}
// fetch/set the RCA
if (Device_MMC != BaseDeviceType) {
DEBUGMSG(SDBUS_ZONE_DEVICE, (TEXT("SDBusDriver: Getting RCA from SD card in slot %d .... \n"),
pSlot->SlotIndex));
// get the RCA
status = SendSDCommand(pSlot->hDevice,
SD_CMD_SEND_RELATIVE_ADDR,
0x00000000,
ResponseR6,
&response);
if (!SD_API_SUCCESS(status)){
return status;
}
// update shadow registers
UpdateCachedRegisterFromResponse(pBaseDevice,
SD_INFO_REGISTER_RCA,
&response);
DEBUGMSG(SDBUS_ZONE_DEVICE, (TEXT("SDBusDriver: Got RCA (0x%04X) from SD card in slot %d \n"),
pBaseDevice->RelativeAddress,
pSlot->SlotIndex));
} else {
// get OEM ID from the CID
GetOEMIDFromCID(&oidValue, pBaseDevice);
// for MMC cards set the RCA
// take the unique OEM ID and add the slot number to it to form a system unique address
pBaseDevice->RelativeAddress = (SD_CARD_RCA)(oidValue + pSlot->SlotIndex);
// add 1 if this is zero
if (pBaseDevice->RelativeAddress == 0) {
pBaseDevice->RelativeAddress++;
}
// for MMC cards, we must set the RCA
DEBUGMSG(SDBUS_ZONE_DEVICE, (TEXT("SDBusDriver: Setting MMC RCA to 0x%04X .... \n"),
pBaseDevice->RelativeAddress));
// set the RCA
status = SendSDCommand(pSlot->hDevice,
SD_CMD_MMC_SET_RCA,
((DWORD)pBaseDevice->RelativeAddress) << 16,
ResponseR1,
&response);
if (!SD_API_SUCCESS(status)){
return status;
}
DEBUGMSG(SDBUS_ZONE_DEVICE, (TEXT("SDBusDriver: RCA set for MMC device in slot %d \n"), pSlot->SlotIndex));
}
// now that the RCA has been fetched/set, we can move on to do other things.........
// check for SD I/O - Only cards. They will not have a CSD or card status
if (Device_SD_IO != BaseDeviceType) {
DEBUGMSG(SDBUS_ZONE_DEVICE, (TEXT("SDBusDriver: Getting CSD in slot %d .... \n"), pSlot->SlotIndex));
// get the CSD
// CMD9
status = SendSDCommand(pSlot->hDevice,
SD_CMD_SEND_CSD,
((DWORD)pBaseDevice->RelativeAddress) << 16,
ResponseR2,
&response);
if (!SD_API_SUCCESS(status)){
return status;
}
// update shadow registers
UpdateCachedRegisterFromResponse(pBaseDevice,
SD_INFO_REGISTER_CSD,
&response);
DEBUGMSG(SDBUS_ZONE_DEVICE, (TEXT("SDBusDriver: Got CSD from device in slot %d \n"), pSlot->SlotIndex));
#if 1
//----------------------------------------------------------
// 2007.10.05 D.Baek
// To check the manufacture ID (moviNAND)
// get the CIS - CMD10
status = SendSDCommand(pSlot->hDevice,
SD_CMD_SEND_CID,
((DWORD)pBaseDevice->RelativeAddress) << 16,
ResponseR2,
&response);
if (!SD_API_SUCCESS(status)){
return status;
}
//----------------------------------------------------------
#endif
// get the card status
// CMD13
status = SendSDCommand(pSlot->hDevice,
SD_CMD_SEND_STATUS,
((DWORD)pBaseDevice->RelativeAddress) << 16,
ResponseR1,
&response);
RETAILMSG(0,(TEXT("[GetCardRegisters] 0x%x\r\n"),((DWORD)pBaseDevice->RelativeAddress)<<16));
if (!SD_API_SUCCESS(status)){
return status;
}
SDGetCardStatusFromResponse(&response, &cardStatus);
if (cardStatus & SD_STATUS_CARD_IS_LOCKED) {
DEBUGMSG(SDBUS_ZONE_DEVICE, (TEXT("SDBusDriver: card in slot %d is locked\n"), pSlot->SlotIndex));
pBaseDevice->SDCardInfo.SDMMCInformation.CardIsLocked = TRUE;
}
}
// now in order to get the SCR register we must be in the trans state
// also in order to do a few other things, so lets select the card now and leave it
// selected
// send CMD 7 to select the card and keep it selected, this is required for SDIO cards
// too as mentioned in I/O working group newsgroup
// CMD7
status = SendSDCommand(pSlot->hDevice,
SD_CMD_SELECT_DESELECT_CARD,
((DWORD)pBaseDevice->RelativeAddress) << 16,
ResponseR1b,
&response);
if (!SD_API_SUCCESS(status)){
DEBUGMSG(SDCARD_ZONE_ERROR, (TEXT("SDBusDriver: Failed to select card in slot %d \n"),
pSlot->SlotIndex));
return status;
}
DEBUGMSG(SDBUS_ZONE_DEVICE, (TEXT("SDBusDriver:Card in slot %d is now selected \n"), pSlot->SlotIndex));
// only SD Memory and Combo cards have an SCR
if ((Device_SD_Memory == BaseDeviceType) ||
(Device_SD_Combo == BaseDeviceType)) {
// if the card is unlocked, get the SCR
if (!pBaseDevice->SDCardInfo.SDMMCInformation.CardIsLocked) {
// get the SD Configuration register
// CMD55
// CMD41
status = SendSDAppCmd(pSlot->hDevice,
SD_ACMD_SEND_SCR,
0,
SD_READ,
ResponseR1,
&response,
1, // 1 block
SD_SCR_REGISTER_SIZE, // 64 bits
scrReg);
// If the memory card is locked then the SCR becomes inaccessable. If we fail
// to read the SCR then just set up the cached SCR register to default to
// a 1bit access mode.
if (!SD_API_SUCCESS(status)){
DEBUGMSG(SDCARD_ZONE_ERROR, (TEXT("SDBusDriver: Failed to get SCR from device in slot %d \n"),
pSlot->SlotIndex));
memset(pBaseDevice->CachedRegisters.SCR, 0, sizeof(pBaseDevice->CachedRegisters.SCR));
} else {
// this is a spec discrepency, since the SCR register is not associated with
// an address, the byte order it ambiguous. All the cards we have seen store the data
// most significant byte first as it arrives.
for (ULONG ii = 0 ; ii < sizeof(pBaseDevice->CachedRegisters.SCR); ii++) {
pBaseDevice->CachedRegisters.SCR[ii] = scrReg[(SD_SCR_REGISTER_SIZE - 1) - ii];
}
DEBUGMSG(SDBUS_ZONE_DEVICE, (TEXT("SDBusDriver: Got SCR from device in slot %d \n"), pSlot->SlotIndex));
}
}
}
#ifdef __MMC_SPEC_4_2_SUPPORT__ // set block length 512 - MMC spec 4.2 mandatory
#if 0
if(Device_MMC == BaseDeviceType)
{
status = SendSDCommand(pSlot->hDevice,
SD_CMD_SET_BLOCKLEN ,
((DWORD)512),
ResponseR1,
&response);
if (!SD_API_SUCCESS(status))
{
return status;
}
}
#endif
#endif
return SD_API_STATUS_SUCCESS;
}
#ifdef __MMC_SPEC_4_2_SUPPORT__ // the function to change bus width
SD_CARD_STATUS TestMMCBusBandwidth(PSDCARD_DEVICE_CONTEXT pDevice)
{
UINT32 ucPattern[128] = { 0x5a5a5a5a, };
UINT32 ucAnswer[128] = {0,};
SD_API_STATUS status;
SD_COMMAND_RESPONSE response;
/*
for ( i = 0 ; i < 128 ; i++)
{
ucPattern[i] = 0;
ucPattern[i] = 0;
}
ucPattern[0] = 0x5a5a5a5a;
ucPattern[1] = 0x5a5a5a5a;
// ucPattern[2] = 0x5a;
// ucPattern[3] = 0x5a;
*/
RETAILMSG(1,(TEXT("BUS_TEST_W Function INININ.\r\n")));
#if 1
status = SDSynchronousBusRequest__X( (SD_DEVICE_HANDLE)pDevice,
MMC_CMD_WRITE_BUSTEST,
0,
SD_WRITE,
ResponseR1,
&response,
1,
512,
(PUCHAR)ucPattern,
0);
if (!SD_API_SUCCESS(status))
{
RETAILMSG(1,(TEXT("BUS_TEST_W returns invalid value. 0x%x\r\n"),status));
}
#endif
#if 0
status = SendSDCommand(pDevice,
SD_CMD_SEND_STATUS,
(pDevice->RelativeAddress) << 16,
ResponseR1,
&response);
if (!SD_API_SUCCESS(status)){
return status;
}
SDGetCardStatusFromResponse(&response, &cardStatus);
RETAILMSG(1,(TEXT("Current Card Status 0x%x #######\n"),cardStatus));
#endif
RETAILMSG(1,(TEXT("BUS_TEST_R Function INININ.\r\n")));
#if 1
ucAnswer[1] = 0;
ucAnswer[0] = 0;
status = SDSynchronousBusRequest__X( (SD_DEVICE_HANDLE)pDevice,
MMC_CMD_READ_BUSTEST,
0,
SD_READ,
ResponseR1,
&response,
1,
512,
(PUCHAR)ucAnswer,
0);
#endif
if (!SD_API_SUCCESS(status))
{
RETAILMSG(1,(TEXT("BUS_TEST_R returns invalid value. 0x%x\r\n"),status));
}
RETAILMSG(1,(TEXT("ucAnswer[0] = 0x%x , ucAnswer[1] = 0x%x\r\n"),
ucAnswer[0],ucAnswer[1]));
return status;
}
#endif
#ifdef __MMC_SPEC_4_2_SUPPORT__ // the function to change bus width
SD_CARD_STATUS TestForMMCMicro(PSDCARD_DEVICE_CONTEXT pDevice)
{
SD_API_STATUS status = SD_API_STATUS_SUCCESS;
UINT8 ucTempBuffer[512] = { 0, };
RETAILMSG(1,(TEXT("[SDBUS] TestForMMCMicro()+++\r\n")));
status = SDSynchronousBusRequest__X( (SD_DEVICE_HANDLE)pDevice,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -