📄 sdhceventhandlers.cpp
字号:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES OR INDEMNITIES.
//
// Copyright (c) 2002-2004 BSQUARE Corporation. All rights reserved.
// DO NOT REMOVE --- BEGIN EXTERNALLY DEVELOPED SOURCE CODE ID 40973--- DO NOT REMOVE
// SD Host Controller Event Handlers
#include "SDbusdriver.h"
#ifdef SD_SPEC_20
/*************************************************************************/
/****** Date : 07.05.04 ******/
/****** Developer : HS.JANG ******/
/****** Description : It has to know that SDcard inserted is in ******/
/****** which slot ( It is needed on SMDK2443 ******/
/*************************************************************************/
#define GET_HC_NAME_FROM_SLOT(s) (s)->pHostController->HostControllerName // added by JJG 06.11.17
/*************************************************************************/
#endif
// macro to get the function number from an R4 response
#define SD_GET_NUMBER_OF_FUNCTIONS(pResponse) (((pResponse)->ResponseBuffer[4] >> 4) & 0x7)
// macro to get the memory present bit from an R4 response
#define SD_MEMORY_PRESENT_WITH_IO(pResponse) (((pResponse)->ResponseBuffer[4] >> 3) & 0x1)
// macro to get the I/O ready flag from an R4 response
#define SD_IS_IO_READY(pResponse) ((pResponse)->ResponseBuffer[4] & 0x80)
// macro to get the Memory card ready flag from an R3 response
#define SD_IS_MEM_READY(pResponse) ((pResponse)->ResponseBuffer[4] & 0x80)
// macro to call slot option handler for power setting
#define SDSetSlotPower(pSlot,Setting) \
(pSlot)->pHostController->pSlotOptionHandler((pSlot)->pHostController, \
(pSlot)->SlotIndex, \
SDHCDSetSlotPower, \
&(Setting), \
sizeof(Setting))
// macro for synchronous bus commands
#ifdef ENABLE_SDIO_V1_1_SUPPORT
#define SendSDCommand(hDevice, Command,Argument,ResponseType,pResponse) \
SDSynchronousBusRequest__X(hDevice, \
Command, \
Argument, \
SD_COMMAND, \
ResponseType, \
pResponse, \
0, \
0, \
NULL, \
(DWORD)SD_SLOTRESET_REQUEST)
#else
#define SendSDCommand(hDevice, Command,Argument,ResponseType,pResponse) \
SDSynchronousBusRequest__X(hDevice, \
Command, \
Argument, \
SD_COMMAND, \
ResponseType, \
pResponse, \
0, \
0, \
NULL, \
0)
#endif //ENABLE_SDIO_V1_1_SUPPORT
// macro to send an application specific command with no data transfer
#define SendSDAppCommand(hDevice,AppCommand,Argument,ResponseType,pResponse) \
SendSDAppCmd(hDevice, \
AppCommand, \
Argument, \
SD_COMMAND, \
ResponseType, \
pResponse, \
0, \
0, \
0)
#define GetDeviceVoltageRangeFromOCR(pVoltageRange, pDevice) \
{ \
*pVoltageRange = (DWORD)pDevice->CachedRegisters.OCR[0] & ~0xF; \
*pVoltageRange |= ((DWORD)pDevice->CachedRegisters.OCR[1]) << 8; \
*pVoltageRange |= ((DWORD)pDevice->CachedRegisters.OCR[2]) << 16; \
}
#define GetDeviceVoltageRangeFromIO_OCR(pVoltageRange, pDevice) \
{ \
*pVoltageRange = (DWORD)pDevice->CachedRegisters.IO_OCR[0] & ~0xF; \
*pVoltageRange |= ((DWORD)pDevice->CachedRegisters.IO_OCR[1]) << 8; \
*pVoltageRange |= ((DWORD)pDevice->CachedRegisters.IO_OCR[2]) << 16; \
}
#define GetOEMIDFromCID(pOID, pDevice) \
{ \
*pOID = (USHORT)((pDevice)->CachedRegisters.CID[SD_CID_OID_OFFSET]); \
*pOID |= ((USHORT)((pDevice)->CachedRegisters.CID[SD_CID_OID_OFFSET + 1])) << 8; \
}
#define CIS_CSA_BYTES (SD_IO_CIS_PTR_BYTES + SD_IO_CSA_PTR_BYTES)
#define CIS_OFFSET_BYTE_0 0
#define CIS_OFFSET_BYTE_1 1
#define CIS_OFFSET_BYTE_2 2
#define CSA_OFFSET_BYTE_0 3
#define CSA_OFFSET_BYTE_1 4
#define CSA_OFFSET_BYTE_2 5
#define UNKNOWN_PRODUCT_INFO_STRING_LENGTH 64
#define IS_PARENT(p) (p == p->pParentDevice)
#ifdef SD_SPEC_20
/*************************************************************************/
/****** Date : 07.05.04 ******/
/****** Developer : HS.JANG ******/
/****** Description : g_bIsSupportSDHC means This card supports SD ******/
/****** high capacity card. ******/
/****** g_bIsSupportSPEC20 means This card support SD ******/
/****** Spec 2.0 ******/
/****** g_bIsSupportHSMMC means This card support MMC ******/
/****** Spec 4.x ******/
/*************************************************************************/
int g_bIsSupportSDHC;
int g_bIsSupportSPEC20;
int g_bIsSupportHSMMC;
// 2007.10.05 D.Baek
bool g_bIsHighSpeedSD;
int g_MMCSpeedMode;
/*************************************************************************/
#endif
///////////////////////////////////////////////////////////////////////////////
// FormatProductString - format a raw CISPTPL_VERS_1 data buffer into a
// displayable string
// Input: pAsciiString - raw product string buffer retreived from VERS_1 tuple
// the tuple is stored as ASCII characters
// pString - the wide char string to store the version 1 tuple
//
// Output:
// Return:
// Notes:
// This function converts the raw version tuple data buffer
// into a wide char displayable string
// All non-displayable characters and spaces are converted to
// an underscore.
///////////////////////////////////////////////////////////////////////////////
VOID FormatProductString(PCHAR pAsciiString, PWCHAR pString )
{
ULONG ii; // loop variable
for (ii = 0; ii < strlen(pAsciiString); ii++) {
// convert to Wide char
pString[ii] = (WCHAR)pAsciiString[ii];
// if the character is outside the range of displayable characters
// then substitute with an under score
if ((pAsciiString[ii] <= 0x20) || (pAsciiString[ii] > 0x7E)) {
pString[ii] = TEXT('_');
}
}
// terminate
pString[ii] = NULL;
}
///////////////////////////////////////////////////////////////////////////////
// SDSetCardInterfaceForSlot - set Card interface for the slot
// Input: pSlot - the slot to set the card interface for
// pSetting - card interface settings
// Output:
// Return: SD_API_STATUS
// Notes:
// this function calls the slot option handler in the host controller
// driver
//
///////////////////////////////////////////////////////////////////////////////
SD_API_STATUS SDSetCardInterfaceForSlot(PSDBUS_HC_SLOT_CONTEXT pSlot,
PSD_CARD_INTERFACE pSetting)
{
SD_API_STATUS status; // intermediate status
DWORD origClockSetting; // original clock setting upon entry
origClockSetting = pSetting->ClockRate;
status = pSlot->pHostController->pSlotOptionHandler(pSlot->pHostController,
pSlot->SlotIndex,
SDHCDSetSlotInterface,
pSetting,
sizeof(SD_CARD_INTERFACE));
if (SD_API_SUCCESS(status)) {
if (origClockSetting != pSetting->ClockRate){
DEBUGMSG(SDCARD_ZONE_WARN, (TEXT("SDSetCardInterfaceForSlot - HC ClockRate differs desired setting: desired: %d Hz, Actual : %d Hz \n"),
origClockSetting, pSetting->ClockRate));
}
}
return status;
}
//Structure definiton of SDIO Version 1.0 term
typedef struct _SDIO_TPLFID_FUNC17_V10 {
UCHAR ExtendedDataType;
UCHAR FunctionInfo;
UCHAR StandardRev;
USHORT CardPSN;
USHORT CSASize;
UCHAR CSAProperty;
USHORT MaxBlockSize;
USHORT OCR;
UCHAR OpMinPwr;
UCHAR OpAvgPwr;
UCHAR OpMaxPwr;
UCHAR StbyMinPwr;
UCHAR StbyAvgPwr;
UCHAR StbyMaxPwr;
USHORT MinBandwidth;
USHORT OptimalBandwidth;
}SDIO_TPLFID_FUNC17_V10, *P_SDIO_TPLFID_FUNC17_V10;
//Structure definiton of SDIO Version 1.10 added term
typedef struct _SDIO_TPLFID_FUNC17_V11 {
USHORT EnableTimoutVal;
USHORT SpAvePwr33V;
USHORT SpMaxPwr33V;
USHORT HpAvePwr33V;
USHORT HpMaxPwr33V;
USHORT LpAvePwr33V;
USHORT LpMaxPwr33V;
}SDIO_TPLFID_FUNC17_V11, *P_SDIO_TPLFID_FUNC17_V11;
///////////////////////////////////////////////////////////////////////////////
// SDGetFunctionPowerControlTuples - Get SDIO Power control Tuples for an SDIO device function
// Input: pDevice - the device context
// Output: pPowerDrawData - Data about function's power draw
// Return: SD_API_STATUS code
// Notes:
// This function collects pwer draw data for a SD function
// via the tuple CITPL_FUNCE (extended 0x01).
//
///////////////////////////////////////////////////////////////////////////////
SD_API_STATUS SDGetFunctionPowerControlTuples(PSDCARD_DEVICE_CONTEXT pDevice)
{
SD_API_STATUS status; // intermediate status
ULONG length; // tuple length
UCHAR buffer[SD_CISTPLE_MAX_BODY_SIZE]; //tupple info
P_SDIO_TPLFID_FUNC17_V10 pV1FunctionTuple; // SDIO V1.0 Function Tuple
P_SDIO_TPLFID_FUNC17_V11 pV11FunctionTupleExt;// SDIO V1.1 Extentions to Function Tuple
PSD_FUNCTION_POWER_DRAW pPowerDrawData = &pDevice->SDCardInfo.SDIOInformation.PowerDrawData;
length = 0;
// get the FUNCE tuple
status = SDGetTuple__X(pDevice,
SD_CISTPL_FUNCE,
NULL,
&length,
FALSE);
if (!SD_API_SUCCESS(status)) {
return status;
}
if (0 == length) {
DbgPrintZo(SDCARD_ZONE_ERROR,
(TEXT("SDBusDriver: Card does not have FUNCE tuple! \n")));
return SD_API_STATUS_DEVICE_UNSUPPORTED;
} else {
if (length < sizeof(SDIO_TPLFID_FUNC17_V10)) {
DbgPrintZo(SDCARD_ZONE_ERROR,
(TEXT("SDBusDriver: Function tuple reports size of %d , expecting %d or greater\n"),
length, sizeof(SDIO_TPLFID_FUNC17_V10)));
return SD_API_STATUS_DEVICE_UNSUPPORTED;
}
// get the tplIDfunction tuple
status = SDGetTuple__X((SD_DEVICE_HANDLE)pDevice,
SD_CISTPL_FUNCE,
(PUCHAR)buffer,
&length,
FALSE);
if (!SD_API_SUCCESS(status)) {
return status;
}
if (buffer[0] != 0x01) {
DbgPrintZo(SDCARD_ZONE_ERROR,
(TEXT("SDBusDriver: Tuple is not Extended Data type: %d \n"),
buffer[0]));
return SD_API_STATUS_DEVICE_UNSUPPORTED;
}
pV1FunctionTuple = (P_SDIO_TPLFID_FUNC17_V10)buffer;
pPowerDrawData->OpMinPower = pV1FunctionTuple->OpMinPwr;
pPowerDrawData->OpAvePower = pV1FunctionTuple->OpAvgPwr;
pPowerDrawData->OpMaxPower = pV1FunctionTuple->OpMaxPwr;
if (length < (sizeof(SDIO_TPLFID_FUNC17_V10) + sizeof(SDIO_TPLFID_FUNC17_V11))) {
pPowerDrawData->SpAvePower33 = 0;
pPowerDrawData->SpMaxPower33 = 0;
pPowerDrawData->HpAvePower33 = 0;
pPowerDrawData->HpMaxPower33 = 0;
pPowerDrawData->LpAvePower33 = 0;
pPowerDrawData->LpMaxPower33 = 0;
}
else
{
pV11FunctionTupleExt = (P_SDIO_TPLFID_FUNC17_V11)(&buffer[sizeof(SDIO_TPLFID_FUNC17_V10)]);
pPowerDrawData->SpAvePower33 = pV11FunctionTupleExt->SpAvePwr33V;
pPowerDrawData->SpMaxPower33 = pV11FunctionTupleExt->SpMaxPwr33V;
pPowerDrawData->HpAvePower33 = pV11FunctionTupleExt->HpAvePwr33V;
pPowerDrawData->HpMaxPower33 = pV11FunctionTupleExt->HpMaxPwr33V;
pPowerDrawData->LpAvePower33 = pV11FunctionTupleExt->LpAvePwr33V;
pPowerDrawData->LpMaxPower33 = pV11FunctionTupleExt->LpMaxPwr33V;
}
}
DbgPrintZo(SDBUS_ZONE_DEVICE, (TEXT("SDBusDriver: Function %d Power Draw:\r\n"),
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -