TianoCore EDK2 master
Loading...
Searching...
No Matches
SdDevice.c File Reference
#include "SdMmcPciHcDxe.h"

Go to the source code of this file.

Functions

EFI_STATUS SdCardReset (IN EFI_SD_MMC_PASS_THRU_PROTOCOL *PassThru, IN UINT8 Slot)
 
EFI_STATUS SdCardVoltageCheck (IN EFI_SD_MMC_PASS_THRU_PROTOCOL *PassThru, IN UINT8 Slot, IN UINT8 SupplyVoltage, IN UINT8 CheckPattern)
 
EFI_STATUS SdioSendOpCond (IN EFI_SD_MMC_PASS_THRU_PROTOCOL *PassThru, IN UINT8 Slot, IN UINT32 VoltageWindow, IN BOOLEAN S18R)
 
EFI_STATUS SdCardSendOpCond (IN EFI_SD_MMC_PASS_THRU_PROTOCOL *PassThru, IN UINT8 Slot, IN UINT16 Rca, IN UINT32 VoltageWindow, IN BOOLEAN S18R, IN BOOLEAN Xpc, IN BOOLEAN Hcs, OUT UINT32 *Ocr)
 
EFI_STATUS SdCardAllSendCid (IN EFI_SD_MMC_PASS_THRU_PROTOCOL *PassThru, IN UINT8 Slot)
 
EFI_STATUS SdCardSetRca (IN EFI_SD_MMC_PASS_THRU_PROTOCOL *PassThru, IN UINT8 Slot, OUT UINT16 *Rca)
 
EFI_STATUS SdCardSelect (IN EFI_SD_MMC_PASS_THRU_PROTOCOL *PassThru, IN UINT8 Slot, IN UINT16 Rca)
 
EFI_STATUS SdCardVoltageSwitch (IN EFI_SD_MMC_PASS_THRU_PROTOCOL *PassThru, IN UINT8 Slot)
 
EFI_STATUS SdCardSetBusWidth (IN EFI_SD_MMC_PASS_THRU_PROTOCOL *PassThru, IN UINT8 Slot, IN UINT16 Rca, IN UINT8 BusWidth)
 
EFI_STATUS SdCardSwitch (IN EFI_SD_MMC_PASS_THRU_PROTOCOL *PassThru, IN UINT8 Slot, IN SD_MMC_BUS_MODE BusTiming, IN UINT8 CommandSystem, IN SD_DRIVER_STRENGTH_TYPE DriverStrength, IN UINT8 PowerLimit, IN BOOLEAN Mode, OUT UINT8 *SwitchResp)
 
EFI_STATUS SdCardSendStatus (IN EFI_SD_MMC_PASS_THRU_PROTOCOL *PassThru, IN UINT8 Slot, IN UINT16 Rca, OUT UINT32 *DevStatus)
 
EFI_STATUS SdCardSendTuningBlk (IN EFI_SD_MMC_PASS_THRU_PROTOCOL *PassThru, IN UINT8 Slot)
 
EFI_STATUS SdCardTuningClock (IN EFI_PCI_IO_PROTOCOL *PciIo, IN EFI_SD_MMC_PASS_THRU_PROTOCOL *PassThru, IN UINT8 Slot)
 
EFI_STATUS SdCardSwitchBusWidth (IN EFI_PCI_IO_PROTOCOL *PciIo, IN EFI_SD_MMC_PASS_THRU_PROTOCOL *PassThru, IN UINT8 Slot, IN UINT16 Rca, IN UINT8 BusWidth)
 
BOOLEAN SdIsBusTimingSupported (IN SD_MMC_HC_PRIVATE_DATA *Private, IN UINT8 SlotIndex, IN UINT8 CardSupportedBusTimings, IN BOOLEAN IsInUhsI, IN SD_MMC_BUS_MODE BusTiming)
 
SD_MMC_BUS_MODE SdGetTargetBusTiming (IN SD_MMC_HC_PRIVATE_DATA *Private, IN UINT8 SlotIndex, IN UINT8 CardSupportedBusTimings, IN BOOLEAN IsInUhsI)
 
UINT8 SdGetTargetBusWidth (IN SD_MMC_HC_PRIVATE_DATA *Private, IN UINT8 SlotIndex, IN SD_MMC_BUS_MODE BusTiming)
 
UINT32 SdGetTargetBusClockFreq (IN SD_MMC_HC_PRIVATE_DATA *Private, IN UINT8 SlotIndex, IN SD_MMC_BUS_MODE BusTiming)
 
EDKII_SD_MMC_DRIVER_STRENGTH SdGetTargetDriverStrength (IN SD_MMC_HC_PRIVATE_DATA *Private, IN UINT8 SlotIndex, IN UINT8 CardSupportedDriverStrengths, IN SD_MMC_BUS_MODE BusTiming)
 
VOID SdGetTargetBusMode (IN SD_MMC_HC_PRIVATE_DATA *Private, IN UINT8 SlotIndex, IN UINT8 *SwitchQueryResp, IN BOOLEAN IsInUhsI, OUT SD_MMC_BUS_SETTINGS *BusMode)
 
EFI_STATUS SdCardSetBusMode (IN EFI_PCI_IO_PROTOCOL *PciIo, IN EFI_SD_MMC_PASS_THRU_PROTOCOL *PassThru, IN UINT8 Slot, IN UINT16 Rca, IN BOOLEAN S18A, IN BOOLEAN SdVersion1)
 
EFI_STATUS SdCardIdentification (IN SD_MMC_HC_PRIVATE_DATA *Private, IN UINT8 Slot)
 

Detailed Description

This file provides some helper functions which are specific for SD card device.

Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved. Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent

Definition in file SdDevice.c.

Function Documentation

◆ SdCardAllSendCid()

EFI_STATUS SdCardAllSendCid ( IN EFI_SD_MMC_PASS_THRU_PROTOCOL PassThru,
IN UINT8  Slot 
)

Broadcast command ALL_SEND_CID to the bus to ask all the SD devices to send the data of their CID registers.

Refer to SD Physical Layer Simplified Spec 4.1 Section 4.7 for details.

Parameters
[in]PassThruA pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
[in]SlotThe slot number of the SD card to send the command to.
Return values
EFI_SUCCESSThe operation is done correctly.
OthersThe operation fails.

Definition at line 243 of file SdDevice.c.

◆ SdCardIdentification()

EFI_STATUS SdCardIdentification ( IN SD_MMC_HC_PRIVATE_DATA Private,
IN UINT8  Slot 
)

Execute SD device identification procedure.

Refer to SD Physical Layer Simplified Spec 4.1 Section 3.6 for details.

Parameters
[in]PrivateA pointer to the SD_MMC_HC_PRIVATE_DATA instance.
[in]SlotThe slot number of the SD card to send the command to.
Return values
EFI_SUCCESSThere is a SD card.
OthersThere is not a SD card.

Definition at line 1210 of file SdDevice.c.

◆ SdCardReset()

EFI_STATUS SdCardReset ( IN EFI_SD_MMC_PASS_THRU_PROTOCOL PassThru,
IN UINT8  Slot 
)

Send command GO_IDLE_STATE to the device to make it go to Idle State.

Refer to SD Physical Layer Simplified Spec 4.1 Section 4.7 for details.

Parameters
[in]PassThruA pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
[in]SlotThe slot number of the SD card to send the command to.
Return values
EFI_SUCCESSThe SD device is reset correctly.
OthersThe device reset fails.

Definition at line 25 of file SdDevice.c.

◆ SdCardSelect()

EFI_STATUS SdCardSelect ( IN EFI_SD_MMC_PASS_THRU_PROTOCOL PassThru,
IN UINT8  Slot,
IN UINT16  Rca 
)

Send command SELECT_DESELECT_CARD to the SD device to select/deselect it.

Refer to SD Physical Layer Simplified Spec 4.1 Section 4.7 for details.

Parameters
[in]PassThruA pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
[in]SlotThe slot number of the SD card to send the command to.
[in]RcaThe relative device address of selected device.
Return values
EFI_SUCCESSThe operation is done correctly.
OthersThe operation fails.

Definition at line 330 of file SdDevice.c.

◆ SdCardSendOpCond()

EFI_STATUS SdCardSendOpCond ( IN EFI_SD_MMC_PASS_THRU_PROTOCOL PassThru,
IN UINT8  Slot,
IN UINT16  Rca,
IN UINT32  VoltageWindow,
IN BOOLEAN  S18R,
IN BOOLEAN  Xpc,
IN BOOLEAN  Hcs,
OUT UINT32 *  Ocr 
)

Send command SD_SEND_OP_COND to the device to see whether it is SDIO device.

Refer to SD Physical Layer Simplified Spec 4.1 Section 4.7 for details.

Parameters
[in]PassThruA pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
[in]SlotThe slot number of the SD card to send the command to.
[in]RcaThe relative device address of addressed device.
[in]VoltageWindowThe supply voltage window.
[in]S18RThe boolean to show if it should switch to 1.8v.
[in]XpcThe boolean to show if it should provide 0.36w power control.
[in]HcsThe boolean to show if it support host capacity info.
[out]OcrThe buffer to store returned OCR register value.
Return values
EFI_SUCCESSThe operation is done correctly.
OthersThe operation fails.

Definition at line 171 of file SdDevice.c.

◆ SdCardSendStatus()

EFI_STATUS SdCardSendStatus ( IN EFI_SD_MMC_PASS_THRU_PROTOCOL PassThru,
IN UINT8  Slot,
IN UINT16  Rca,
OUT UINT32 *  DevStatus 
)

Send command SEND_STATUS to the addressed SD device to get its status register.

Refer to SD Physical Layer Simplified Spec 4.1 Section 4.7 for details.

Parameters
[in]PassThruA pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
[in]SlotThe slot number of the SD card to send the command to.
[in]RcaThe relative device address of addressed device.
[out]DevStatusThe returned device status.
Return values
EFI_SUCCESSThe operation is done correctly.
OthersThe operation fails.

Definition at line 580 of file SdDevice.c.

◆ SdCardSendTuningBlk()

EFI_STATUS SdCardSendTuningBlk ( IN EFI_SD_MMC_PASS_THRU_PROTOCOL PassThru,
IN UINT8  Slot 
)

Send command SEND_TUNING_BLOCK to the SD device for HS200 optimal sampling point detection.

It may be sent up to 40 times until the host finishes the tuning procedure.

Refer to SD Physical Layer Simplified Spec 4.1 Section 4.7 for details.

Parameters
[in]PassThruA pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
[in]SlotThe slot number of the SD card to send the command to.
Return values
EFI_SUCCESSThe operation is done correctly.
OthersThe operation fails.

Definition at line 629 of file SdDevice.c.

◆ SdCardSetBusMode()

EFI_STATUS SdCardSetBusMode ( IN EFI_PCI_IO_PROTOCOL PciIo,
IN EFI_SD_MMC_PASS_THRU_PROTOCOL PassThru,
IN UINT8  Slot,
IN UINT16  Rca,
IN BOOLEAN  S18A,
IN BOOLEAN  SdVersion1 
)

Switch the high speed timing according to request.

Refer to SD Physical Layer Simplified Spec 4.1 Section 4.7 and SD Host Controller Simplified Spec 3.0 section Figure 2-29 for details.

Parameters
[in]PciIoA pointer to the EFI_PCI_IO_PROTOCOL instance.
[in]PassThruA pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
[in]SlotThe slot number of the SD card to send the command to.
[in]RcaThe relative device address to be assigned.
[in]S18AThe boolean to show if it's a UHS-I SD card.
[in]SdVersion1The boolean to show if it's a Version 1 SD card.
Return values
EFI_SUCCESSThe operation is done correctly.
OthersThe operation fails.

Definition at line 1084 of file SdDevice.c.

◆ SdCardSetBusWidth()

EFI_STATUS SdCardSetBusWidth ( IN EFI_SD_MMC_PASS_THRU_PROTOCOL PassThru,
IN UINT8  Slot,
IN UINT16  Rca,
IN UINT8  BusWidth 
)

Send command SET_BUS_WIDTH to the SD device to set the bus width.

Refer to SD Physical Layer Simplified Spec 4.1 Section 4.7 for details.

Parameters
[in]PassThruA pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
[in]SlotThe slot number of the SD card to send the command to.
[in]RcaThe relative device address of addressed device.
[in]BusWidthThe bus width to be set, it could be 1 or 4.
Return values
EFI_SUCCESSThe operation is done correctly.
OthersThe operation fails.

Definition at line 418 of file SdDevice.c.

◆ SdCardSetRca()

EFI_STATUS SdCardSetRca ( IN EFI_SD_MMC_PASS_THRU_PROTOCOL PassThru,
IN UINT8  Slot,
OUT UINT16 *  Rca 
)

Send command SET_RELATIVE_ADDR to the SD device to assign a Relative device Address (RCA).

Refer to SD Physical Layer Simplified Spec 4.1 Section 4.7 for details.

Parameters
[in]PassThruA pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
[in]SlotThe slot number of the SD card to send the command to.
[out]RcaThe relative device address to assign.
Return values
EFI_SUCCESSThe operation is done correctly.
OthersThe operation fails.

Definition at line 285 of file SdDevice.c.

◆ SdCardSwitch()

EFI_STATUS SdCardSwitch ( IN EFI_SD_MMC_PASS_THRU_PROTOCOL PassThru,
IN UINT8  Slot,
IN SD_MMC_BUS_MODE  BusTiming,
IN UINT8  CommandSystem,
IN SD_DRIVER_STRENGTH_TYPE  DriverStrength,
IN UINT8  PowerLimit,
IN BOOLEAN  Mode,
OUT UINT8 *  SwitchResp 
)

Send command SWITCH_FUNC to the SD device to check switchable function or switch card function.

Refer to SD Physical Layer Simplified Spec 4.1 Section 4.7 for details.

Parameters
[in]PassThruA pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
[in]SlotThe slot number of the SD card to send the command to.
[in]BusTimingTarget bus timing based on which access group value will be set.
[in]CommandSystemThe value for command set group.
[in]DriverStrengthThe value for driver strength group.
[in]PowerLimitThe value for power limit group.
[in]ModeSwitch or check function.
[out]SwitchRespThe return switch function status.
Return values
EFI_SUCCESSThe operation is done correctly.
OthersThe operation fails.

Definition at line 486 of file SdDevice.c.

◆ SdCardSwitchBusWidth()

EFI_STATUS SdCardSwitchBusWidth ( IN EFI_PCI_IO_PROTOCOL PciIo,
IN EFI_SD_MMC_PASS_THRU_PROTOCOL PassThru,
IN UINT8  Slot,
IN UINT16  Rca,
IN UINT8  BusWidth 
)

Switch the bus width to specified width.

Refer to SD Physical Layer Simplified Spec 4.1 Section 4.7 and SD Host Controller Simplified Spec 3.0 section Figure 3-7 for details.

Parameters
[in]PciIoA pointer to the EFI_PCI_IO_PROTOCOL instance.
[in]PassThruA pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
[in]SlotThe slot number of the SD card to send the command to.
[in]RcaThe relative device address to be assigned.
[in]BusWidthThe bus width to be set, it could be 4 or 8.
Return values
EFI_SUCCESSThe operation is done correctly.
OthersThe operation fails.

Definition at line 753 of file SdDevice.c.

◆ SdCardTuningClock()

EFI_STATUS SdCardTuningClock ( IN EFI_PCI_IO_PROTOCOL PciIo,
IN EFI_SD_MMC_PASS_THRU_PROTOCOL PassThru,
IN UINT8  Slot 
)

Tunning the sampling point of SDR104 or SDR50 bus speed mode.

Command SD_SEND_TUNING_BLOCK may be sent up to 40 times until the host finishes the tuning procedure.

Refer to SD Physical Layer Simplified Spec 4.1 Section 4.7 and SD Host Controller Simplified Spec 3.0 section Figure 3-7 for details.

Parameters
[in]PciIoA pointer to the EFI_PCI_IO_PROTOCOL instance.
[in]PassThruA pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
[in]SlotThe slot number of the SD card to send the command to.
Return values
EFI_SUCCESSThe operation is done correctly.
OthersThe operation fails.

Definition at line 679 of file SdDevice.c.

◆ SdCardVoltageCheck()

EFI_STATUS SdCardVoltageCheck ( IN EFI_SD_MMC_PASS_THRU_PROTOCOL PassThru,
IN UINT8  Slot,
IN UINT8  SupplyVoltage,
IN UINT8  CheckPattern 
)

Send command SEND_IF_COND to the device to inquiry the SD Memory Card interface condition.

Refer to SD Physical Layer Simplified Spec 4.1 Section 4.7 for details.

Parameters
[in]PassThruA pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
[in]SlotThe slot number of the SD card to send the command to.
[in]SupplyVoltageThe supplied voltage by the host.
[in]CheckPatternThe check pattern to be sent to the device.
Return values
EFI_SUCCESSThe operation is done correctly.
OthersThe operation fails.

Definition at line 67 of file SdDevice.c.

◆ SdCardVoltageSwitch()

EFI_STATUS SdCardVoltageSwitch ( IN EFI_SD_MMC_PASS_THRU_PROTOCOL PassThru,
IN UINT8  Slot 
)

Send command VOLTAGE_SWITCH to the SD device to switch the voltage of the device.

Refer to SD Physical Layer Simplified Spec 4.1 Section 4.7 for details.

Parameters
[in]PassThruA pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
[in]SlotThe slot number of the SD card to send the command to.
Return values
EFI_SUCCESSThe operation is done correctly.
OthersThe operation fails.

Definition at line 375 of file SdDevice.c.

◆ SdGetTargetBusClockFreq()

UINT32 SdGetTargetBusClockFreq ( IN SD_MMC_HC_PRIVATE_DATA Private,
IN UINT8  SlotIndex,
IN SD_MMC_BUS_MODE  BusTiming 
)

Get the target clock frequency to be set on the bus.

Parameters
[in]PrivatePointer to controller private data
[in]SlotIndexIndex of the slot in the controller
[in]BusTimingBus timing to be set on the bus
Returns
Value of the clock frequency to be set on bus in MHz

Definition at line 960 of file SdDevice.c.

◆ SdGetTargetBusMode()

VOID SdGetTargetBusMode ( IN SD_MMC_HC_PRIVATE_DATA Private,
IN UINT8  SlotIndex,
IN UINT8 *  SwitchQueryResp,
IN BOOLEAN  IsInUhsI,
OUT SD_MMC_BUS_SETTINGS BusMode 
)

Get the target settings for the bus mode.

Parameters
[in]PrivatePointer to controller private data
[in]SlotIndexIndex of the slot in the controller
[in]SwitchQueryRespPointer to switch query response
[in]IsInUhsIFlag indicating if link is in UHS-I mode
[out]BusModeTarget configuration of the bus

Definition at line 1052 of file SdDevice.c.

◆ SdGetTargetBusTiming()

SD_MMC_BUS_MODE SdGetTargetBusTiming ( IN SD_MMC_HC_PRIVATE_DATA Private,
IN UINT8  SlotIndex,
IN UINT8  CardSupportedBusTimings,
IN BOOLEAN  IsInUhsI 
)

Get the target bus timing to set on the link. This function will try to select highest bus timing supported by card, controller and the driver.

Parameters
[in]PrivatePointer to controller private data
[in]SlotIndexIndex of the slot in the controller
[in]CardSupportedBusTimingsBitmask indicating which bus timings are supported by card
[in]IsInUhsIFlag indicating if link is in UHS-I
Returns
Bus timing value that should be set on link

Definition at line 883 of file SdDevice.c.

◆ SdGetTargetBusWidth()

UINT8 SdGetTargetBusWidth ( IN SD_MMC_HC_PRIVATE_DATA Private,
IN UINT8  SlotIndex,
IN SD_MMC_BUS_MODE  BusTiming 
)

Get the target bus width to be set on the bus.

Parameters
[in]PrivatePointer to controller private data
[in]SlotIndexIndex of the slot in the controller
[in]BusTimingBus timing set on the bus
Returns
Bus width to be set on the bus

Definition at line 919 of file SdDevice.c.

◆ SdGetTargetDriverStrength()

EDKII_SD_MMC_DRIVER_STRENGTH SdGetTargetDriverStrength ( IN SD_MMC_HC_PRIVATE_DATA Private,
IN UINT8  SlotIndex,
IN UINT8  CardSupportedDriverStrengths,
IN SD_MMC_BUS_MODE  BusTiming 
)

Get the driver strength to be set on bus.

Parameters
[in]PrivatePointer to controller private data
[in]SlotIndexIndex of the slot in the controller
[in]CardSupportedDriverStrengthsBitmask indicating which driver strengths are supported on the card
[in]BusTimingBus timing set on the bus
Returns
Value of the driver strength to be set on the bus

Definition at line 1007 of file SdDevice.c.

◆ SdioSendOpCond()

EFI_STATUS SdioSendOpCond ( IN EFI_SD_MMC_PASS_THRU_PROTOCOL PassThru,
IN UINT8  Slot,
IN UINT32  VoltageWindow,
IN BOOLEAN  S18R 
)

Send command SDIO_SEND_OP_COND to the device to see whether it is SDIO device.

Refer to SDIO Simplified Spec 3 Section 3.2 for details.

Parameters
[in]PassThruA pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
[in]SlotThe slot number of the SD card to send the command to.
[in]VoltageWindowThe supply voltage window.
[in]S18RThe boolean to show if it should switch to 1.8v.
Return values
EFI_SUCCESSThe operation is done correctly.
OthersThe operation fails.

Definition at line 118 of file SdDevice.c.

◆ SdIsBusTimingSupported()

BOOLEAN SdIsBusTimingSupported ( IN SD_MMC_HC_PRIVATE_DATA Private,
IN UINT8  SlotIndex,
IN UINT8  CardSupportedBusTimings,
IN BOOLEAN  IsInUhsI,
IN SD_MMC_BUS_MODE  BusTiming 
)

Check if passed BusTiming is supported in both controller and card.

Parameters
[in]PrivatePointer to controller private data
[in]SlotIndexIndex of the slot in the controller
[in]CardSupportedBusTimingsBitmask indicating which bus timings are supported by card
[in]IsInUhsIFlag indicating if link is in UHS-I
Return values
TRUEBoth card and controller support given BusTiming
FALSECard or controller doesn't support given BusTiming

Definition at line 801 of file SdDevice.c.