📄 sdhcslot.cpp
字号:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
// Copyright (c) 2002 BSQUARE Corporation. All rights reserved.
// DO NOT REMOVE --- BEGIN EXTERNALLY DEVELOPED SOURCE CODE ID 40973--- DO NOT REMOVE
#include <windows.h>
#include <nkintr.h>
#include <ceddk.h>
#include <s3c6400.h>
#include <bsp.h>
#include <DrvLib.h>
#include "SDHC.h"
#include "SDHCSlot.h"
static volatile BSP_ARGS *v_gBspArgs;
#define CARD_INSERTED 1
#define CARD_REMOVED 2
//2007.09.19 D.Baek
#define SDIO_DEBUG 0
#define SRCCLK_48MHZ //USB_PHY 48MHZ Clock. Keep sync with "sdhc_s3c6400.cpp"
// 2007.06.25 D.Baek
// Define the global variable to check the initial state of card slot. When the driver is loading at boot,
// Check whether the card is inserted or not. If inserted, the process of insertion is executed automatically.
DWORD g_initialInsertion = 1;
//---------------------------------------------------------------------------------------------------
// 2007.10.08 D.Baek
// To support the MMCmicro card. The following variable is used in
// 1. "SlotOptionHandler" function.
// 2. "SetClockRate" function.
#ifdef __MMCmicro_SUPPORT__
BOOL g_bIsMMCmicro;
#endif
//---------------------------------------------------------------------------------------------------
// Macros
#define DX_D1_OR_D2(cps) ((cps) == D1 || (cps) == D2)
#define SETFNAME() LPCTSTR pszFname = _T(__FUNCTION__) _T(":")
#ifdef DEBUG
// dump the current request info to the debugger
static
VOID
DumpRequest(
PSD_BUS_REQUEST pRequest,
DWORD dwZone
)
{
PREFAST_DEBUGCHK(pRequest);
if (dwZone) {
DEBUGMSG(1, (TEXT("DumpCurrentRequest: 0x%08X\n"), pRequest));
DEBUGMSG(1, (TEXT("\t Command: %d\n"), pRequest->CommandCode));
DEBUGMSG(1, (TEXT("\t Argument: 0x%08x\n"), pRequest->CommandArgument));
DEBUGMSG(1, (TEXT("\t ResponseType: %d\n"), pRequest->CommandResponse.ResponseType));
DEBUGMSG(1, (TEXT("\t NumBlocks: %d\n"), pRequest->NumBlocks));
DEBUGMSG(1, (TEXT("\t BlockSize: %d\n"), pRequest->BlockSize));
DEBUGMSG(1, (TEXT("\t HCParam: %d\n"), pRequest->HCParam));
}
}
#else
#define DumpRequest(ptr, dw)
#endif
CSDHCSlotBase::CSDHCSlotBase(
)
{
m_pregDevice = NULL;
m_dwSlot = 0;
m_pbRegisters = NULL;
m_pHCDContext = NULL;
m_dwSysIntr = 0;
m_hBusAccess = NULL;
m_interfaceType = InterfaceTypeUndefined;
m_dwBusNumber = 0;
m_dwVddWindows = 0;
m_dwMaxClockRate = 0;
m_dwTimeoutControl = 0;
m_dwMaxBlockLen = 0;
m_pbDmaBuffer = NULL;
m_paDmaBuffer = 0;
m_wRegClockControl = 0;
m_wIntSignals = 0;
m_cpsCurrent = D0;
m_cpsAtPowerDown = D0;
m_dwDefaultWakeupControl = 0;
m_bWakeupControl = 0;
#ifdef DEBUG
m_dwReadyInts = 0;
#endif
m_fCommandCompleteOccurred = FALSE;
m_fSleepsWithPower = FALSE;
m_fPowerUpDisabledInts = FALSE;
m_fIsPowerManaged = FALSE;
m_fSDIOInterruptsEnabled = FALSE;
m_fCardPresent = FALSE;
m_fAutoCMD12Success = FALSE;
m_fCheckSlot = TRUE;
m_fCanWakeOnSDIOInterrupts = FALSE;
m_f4BitMode = FALSE;
m_fFakeCardRemoval = FALSE;
#ifdef NEW_POWER_MANAGEMENT
m_fWhileWakeup = FALSE;
#endif
}
CSDHCSlotBase::~CSDHCSlotBase(
)
{
DEBUGCHK(m_pbDmaBuffer == NULL);
}
BOOL
CSDHCSlotBase::Init(
DWORD dwSlot,
volatile BYTE *pbRegisters,
PSDCARD_HC_CONTEXT pHCDContext,
DWORD dwSysIntr,
HANDLE hBusAccess,
INTERFACE_TYPE interfaceType,
DWORD dwBusNumber,
CReg *pregDevice
)
{
BOOL fRet = TRUE;
DEBUGCHK(dwSlot < SDHC_MAX_SLOTS);
DEBUGCHK(pbRegisters);
DEBUGCHK(pHCDContext);
DEBUGCHK(hBusAccess);
PREFAST_DEBUGCHK(pregDevice && pregDevice->IsOK());
m_dwSlot = dwSlot;
m_pbRegisters = pbRegisters;
m_pHCDContext = pHCDContext;
m_dwSysIntr = dwSysIntr;
m_hBusAccess = hBusAccess;
m_interfaceType = interfaceType;
m_dwBusNumber = dwBusNumber;
m_pregDevice = pregDevice;
#ifdef NEW_POWER_MANAGEMENT
m_hWaitForEndofWakeup = CreateEvent(NULL, FALSE, FALSE, NULL);
if (!m_hWaitForEndofWakeup)
{
RETAILMSG(1,(TEXT("m_hWaitForEndofWakeup is invalid.\r\n")));
return FALSE;
}
#endif
fRet = SoftwareReset(SOFT_RESET_ALL);
if (fRet) {
Sleep(10); // Allow time for card to power down after a device reset
SSDHC_CAPABILITIES caps = GetCapabilities();
DEBUGMSG(SDCARD_ZONE_INIT && caps.bits.DMA,
(_T("SDHC Will use DMA for slot %u\n"), m_dwSlot));
m_dwVddWindows = DetermineVddWindows();
m_dwMaxClockRate = DetermineMaxClockRate();
m_dwMaxBlockLen = DetermineMaxBlockLen();
m_dwTimeoutControl = DetermineTimeoutControl();
m_dwDefaultWakeupControl = DetermineWakeupSources();
m_fCanWakeOnSDIOInterrupts = m_pregDevice->ValueDW(SDHC_CAN_WAKE_ON_INT_KEY);
Validate();
DumpRegisters();
}
return fRet;
}
SD_API_STATUS
CSDHCSlotBase::Start(
)
{
Validate();
SD_API_STATUS status;
RETAILMSG(CRC_DEBUG,(TEXT("---------------------------CSDHCSlotBase::Start().\r\n")));
if (SoftwareReset(SOFT_RESET_ALL)) {
RETAILMSG(0,(TEXT("CSDHCSlotBase::Start\n"))); // jylee
// Set the timeout control value
// The value of "timeout control" must be set to the maximum value
//WriteByte(SDHC_TIMEOUT_CONTROL, (BYTE) m_dwTimeoutControl);
WriteByte(SDHC_TIMEOUT_CONTROL, (BYTE)0xE);
// Enable error interrupt status and signals for all but the vendor
// errors. This allows any normal error to generate an interrupt.
WriteWord(SDHC_ERROR_INT_STATUS_ENABLE,( ~0 & ~ERR_INT_STATUS_VENDOR));
WriteWord(SDHC_ERROR_INT_SIGNAL_ENABLE, (~0 & ~ERR_INT_STATUS_VENDOR));
// Enable all interrupt signals. During execution, we will enable
// and disable interrupt statuses as desired.
// 2007.04.03 D.Baek
// Disable signal interrupt enable for FIFO SD Address pointer interrupt 0,1,2,3
// NORMAL_INT_SIGNAL_ENABLE[14:11] = 4'b0000 (Masked)
WriteWord(SDHC_NORMAL_INT_SIGNAL_ENABLE, 0x1FF);
WriteWord(SDHC_NORMAL_INT_STATUS_ENABLE, 0x1FF);
RETAILMSG(0,(TEXT("CSDHCBase::Start() NORMAL_INT_STATUS_ENABLE : 0x%x\n"),ReadWord(SDHC_NORMAL_INT_STATUS_ENABLE)));
status = SD_API_STATUS_SUCCESS;
}
else {
status = SD_API_STATUS_DEVICE_NOT_RESPONDING;
RETAILMSG(0,(TEXT("CSDHCSlotBase::Start() SoftwareReset Failed.\r\n")));
}
RETAILMSG(0,(TEXT("CSDHCSlotBase::Start()\r\n"))); // jylee
if (v_gBspArgs == NULL)
{
v_gBspArgs = (volatile BSP_ARGS *)DrvLib_MapIoSpace(IMAGE_SHARE_ARGS_PA_START, sizeof(BSP_ARGS), FALSE);
if (v_gBspArgs == NULL)
{
RETAILMSG(1, (TEXT("[HSMMC]HSMMC DrvLib_MapIoSpace: FAILED\r\n")));
if (v_gBspArgs)
{
DrvLib_UnmapIoSpace((PVOID) v_gBspArgs);
v_gBspArgs = NULL;
}
return FALSE;
}
v_gBspArgs->g_SDCardState = CARD_REMOVED; //initialize
v_gBspArgs->g_SDCardDetectEvent = CreateEvent(NULL, FALSE, FALSE,NULL);
}
return status;
}
SD_API_STATUS
CSDHCSlotBase::Stop(
)
{
RETAILMSG(0,(TEXT("CSDHCSlotBase::Stop() called.\r\n"))); // jylee
if (m_fCardPresent) {
// Remove device
HandleRemoval(FALSE);
}
SoftwareReset(SOFT_RESET_ALL);
RETAILMSG(0,(TEXT("CSDHCSlotBase::Stop() exited.\r\n"))); // jylee
if(NULL != v_gBspArgs->g_SDCardDetectEvent)
{
CloseHandle(v_gBspArgs->g_SDCardDetectEvent);
v_gBspArgs->g_SDCardDetectEvent = NULL;
}
if (v_gBspArgs)
{
DrvLib_UnmapIoSpace((PVOID) v_gBspArgs);
v_gBspArgs = NULL;
}
return SD_API_STATUS_SUCCESS;
}
SD_API_STATUS
CSDHCSlotBase::GetSlotInfo(
PSDCARD_HC_SLOT_INFO pSlotInfo
)
{
PREFAST_DEBUGCHK(pSlotInfo);
DEBUGCHK(m_pregDevice->IsOK());
// set the slot capabilities
#ifdef MMC_SPEC_40
/*************************************************************************/
/****** Date : 07.05.14 ******/
/****** Developer : HS.JANG ******/
/****** Description : to support SD SPEC20 card. Response7 is added ******/
/****** for supporting SD SPEC20 card ******/
/*************************************************************************/
SDHCDSetSlotCapabilities(pSlotInfo, SD_SLOT_SD_4BIT_CAPABLE |
SD_SLOT_SD_1BIT_CAPABLE |
SD_SLOT_SDIO_CAPABLE |
SD_SLOT_SDIO_INT_DETECT_4BIT_MULTI_BLOCK |
SD_SLOT_HIGH_SPEED_CAPABLE );
/*************************************************************************/
#else
SDHCDSetSlotCapabilities(pSlotInfo, SD_SLOT_SD_4BIT_CAPABLE |
SD_SLOT_SD_1BIT_CAPABLE |
SD_SLOT_SDIO_CAPABLE |
SD_SLOT_SDIO_INT_DETECT_4BIT_MULTI_BLOCK);
#endif
SDHCDSetVoltageWindowMask(pSlotInfo, m_dwVddWindows);
// Set optimal voltage
SDHCDSetDesiredSlotVoltage(pSlotInfo, GetDesiredVddWindow());
// Controller may be able to clock at higher than the max SD rate,
// but we should only report the highest rate in the range.
DWORD dwMaxClockRateInSDRange = SD_FULL_SPEED_RATE;
SetClockRate(&dwMaxClockRateInSDRange);
SDHCDSetMaxClockRate(pSlotInfo, dwMaxClockRateInSDRange);
// Set power up delay. We handle this in SetVoltage().
SDHCDSetPowerUpDelay(pSlotInfo, 1);
return SD_API_STATUS_SUCCESS;
}
SD_API_STATUS
CSDHCSlotBase::SlotOptionHandler(
SD_SLOT_OPTION_CODE sdOption,
PVOID pData,
DWORD cbData
)
{
SD_API_STATUS status = SD_API_STATUS_SUCCESS;
RETAILMSG(0,(TEXT("CSDHCSlotBase::SlotOptionHandle\r\n"))); // jylee
switch (sdOption) {
case SDHCDSetSlotPower: {
RETAILMSG(CRC_DEBUG,(TEXT("CSDHCSlotBase::SlotOptionHandler -> SetVoltage()\r\n"))); // jylee
DEBUGCHK(cbData == sizeof(DWORD));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -