⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sdhcslot.h

📁 SAMSUNG S3C6410 CPU BSP for winmobile6
💻 H
📖 第 1 页 / 共 2 页
字号:
//
// 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.
//
//
// 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 BSQUARE Corporation.  All rights reserved.
// DO NOT REMOVE --- BEGIN EXTERNALLY DEVELOPED SOURCE CODE ID 40973--- DO NOT REMOVE

#ifndef _SDHCSLOT_DEFINED
#define _SDHCSLOT_DEFINED

#include "../../HSMMC_inc/SDCardDDK.h"
#include "../../HSMMC_inc/SDHCD.h"
#include <ceddk.h>
#include "SDHCRegs.h"


#define SDHC_MAX_POWER_SUPPLY_RAMP_UP   250     // SD Phys Layer 6.6
#define NUM_BYTE_FOR_POLLING_MODE 0x800

#define SDHC_POWER_UP_DELAY_KEY         _T("PowerUpDelay")
#define SDHC_WAKEUP_SOURCES_KEY         _T("DefaultWakeupSources")
#define SDHC_CAN_WAKE_ON_INT_KEY        _T("AllowWakeOnSDIOInterrupts")
#define SDHC_FREQUENCY_KEY              _T("BaseClockFrequency")
#define SDHC_TIMEOUT_FREQUENCY_KEY      _T("TimeoutClockFrequency")
#define SDHC_TIMEOUT_KEY                _T("TimeoutInMS")
#define SDHC_POLLINGMODE_SIZE           _T("PollingModeSize")

typedef class CSDHCSlotBase {
public:
    // Constructor - only initializes the member data. True initialization
    // occurs in Init().
    CSDHCSlotBase();
    virtual ~CSDHCSlotBase();

    // Perform basic initialization including initializing the hardware
    // so that the capabilities register can be read.
    virtual BOOL Init(DWORD dwSlot, volatile BYTE *pbRegisters,
        PSDCARD_HC_CONTEXT pHCDContext, DWORD dwSysIntr, HANDLE hBusAccess,
        INTERFACE_TYPE interfaceType, DWORD dwBusNumber, CReg *pregDevice);

    // Second stage of hardware initialization. Complete slot configuration
    // and enable interrupts.
    virtual SD_API_STATUS Start();
    // Signals card removal disables the slot.
    virtual SD_API_STATUS Stop();

    // Process a slot option call.
    virtual SD_API_STATUS SlotOptionHandler(SD_SLOT_OPTION_CODE sdOption, 
        PVOID pData, DWORD cbData);

    // Get this slot's power state.
    virtual CEDEVICE_POWER_STATE GetPowerState() { return m_cpsCurrent; }

    // What power state is required upon power up?
    virtual CEDEVICE_POWER_STATE GetPowerUpRequirement() { return m_cpsAtPowerDown; }

    // Called when the device is suspending.
    virtual VOID PowerDown();
    // Called when the device is resuming.
    virtual VOID PowerUp();

    // Start this bus request.
    virtual SD_API_STATUS BusRequestHandler(PSD_BUS_REQUEST pRequest);

    // Returns TRUE if the interrupt routine needs servicing, say at
    // initialization to see if a card is present.
    virtual BOOL NeedsServicing() { return m_fCheckSlot; }

    // Handle a slot interrupt. Also called when NeedsServicing() returns TRUE.
    virtual VOID HandleInterrupt();

	BOOL IsOnlySDIOInterrupt();	// copied from CE6.0 by KYS

    // Called by the controller to get the controller interrupt register.
    inline WORD ReadControllerInterrupts() {
        //return ReadWord(SDHC_SLOT_INT_STATUS);
        // 08.07.09 by KYS
        // We must use NORMAL_INT_STATUS instead of SLOT_INT_STATUS because SLOT_INT_STATUS is not apply to our controller.
        return ReadWord(SDHC_NORMAL_INT_STATUS);
    }

protected:
    virtual SD_API_STATUS SubmitBusRequestHandler(PSD_BUS_REQUEST pRequest );
    virtual BOOL PollingForCommandComplete();

    // What is this slot's maximum clock rate?
    virtual DWORD DetermineMaxClockRate();

    // What is this slot's maximum block length?
    virtual DWORD DetermineMaxBlockLen();

    // What should this slot use for timeout control?
    virtual DWORD DetermineTimeoutControl();

    // What are the default wakeup sources?
    virtual DWORD DetermineWakeupSources();
    
    // Set the slot voltage.
    virtual VOID SetVoltage(DWORD dwVddSetting);
    // Set the bus width and clock rate.
    virtual VOID SetInterface(PSD_CARD_INTERFACE_EX pInterface);

    // Set this slot's power state.
    virtual VOID SetPowerState(CEDEVICE_POWER_STATE cpsNew);

    // Get the capabilities register.
    virtual SSDHC_CAPABILITIES GetCapabilities() {
        SSDHC_CAPABILITIES caps;
        caps.dw = ReadDword(SDHC_CAPABILITIES);
        return caps;
    }

    virtual SSDHC_VERSION GetSDHCVersion() {
        SSDHC_VERSION version;
        version.uw = ReadWord(SDHC_HOST_CONTROLLER_VER);
        return version;
    }
    // Fill in the slot info structure.
    virtual SD_API_STATUS GetSlotInfo(PSDCARD_HC_SLOT_INFO pSlotInfo);

    // Get the desired Vdd window.
    virtual DWORD GetDesiredVddWindow();

    // Get the max Vdd window.
    virtual DWORD GetMaxVddWindow();

    // Is the card write-protected?
    virtual BOOL IsWriteProtected() {
#ifdef _SMDK6410_CH1_WP_
        // 08.03.29 by KYS
        // On the CPU B'd Rev 0.0 of SMDK6410 , Write protect is detected with GPIO_F[13]
        BOOL fRet = FALSE;
				volatile S3C6410_GPIO_REG *pIOPreg = NULL;
				pIOPreg = (volatile S3C6410_GPIO_REG *)DrvLib_MapIoSpace(S3C6410_BASE_REG_PA_GPIO, sizeof(S3C6410_GPIO_REG), FALSE);
				if (pIOPreg == NULL) {
					RETAILMSG (1,(TEXT("[HSMMC1] GPIO registers is *NOT* mapped.\n")));
					return FALSE;
				}
				fRet = (pIOPreg->GPFDAT & (0x1<<13)) ? 0 : 1; // It is always "0" because WP pin is not connected for now and the status of line is pulled-up.
				DrvLib_UnmapIoSpace((PVOID)pIOPreg);
				return fRet;
#else
        return ((ReadDword(SDHC_PRESENT_STATE) & STATE_WRITE_PROTECT) == 0);
#endif
    }

    // Enable/disable SDIO card interrupts.
    virtual VOID EnableSDIOInterrupts(BOOL fEnable);

    // How much extra time in ms for initial clocks is needed upon
    // insertion of a card for the power supply ramp up?
    virtual DWORD GetPowerSupplyRampUpMs() {
        return m_pregDevice->ValueDW(SDHC_POWER_UP_DELAY_KEY,
            SDHC_MAX_POWER_SUPPLY_RAMP_UP);
    }
    
    // Register access routines. These are not virtual so that we get
    // good inline read/write perf.
    template <class T>
    inline VOID WriteReg   (DWORD dwOffset, T tValue) {
        CheckRegOffset(dwOffset, sizeof(T));
        volatile T *ptRegister = (volatile T *) (m_pbRegisters + dwOffset);
        *ptRegister = tValue;
    }
    template <class T>
    inline T ReadReg       (DWORD dwOffset) {
        CheckRegOffset(dwOffset, sizeof(T));
        volatile T *ptRegister = (volatile T *) (m_pbRegisters + dwOffset);
        return *ptRegister;
    }

    inline BYTE  ReadByte  (DWORD dwOffset) {
        return ReadReg<BYTE>(dwOffset);
    }
    inline VOID  WriteByte (DWORD dwOffset, BYTE bValue) {
        WriteReg(dwOffset, bValue);
    }

    inline WORD  ReadWord  (DWORD dwOffset) {
        return ReadReg<WORD>(dwOffset);
    }
    inline VOID  WriteWord (DWORD dwOffset, WORD wValue) {
        WriteReg(dwOffset, wValue);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -