Return to Unit Reference
Description
Broadcom BCM27XX SDHOST Driver unit
The SDHOST controller on the BCM27XX is a non SDHCI-compliant device which requires a specific driver.
It can be routed to GPIO pins 22 to 27 (ALT0) or 48 to 53 (ALT0) in order to control the SD card slot when the SDHCI device is being used for the on board WiFi.
Note that on the Raspberry Pi 4 the SD card is no longer connected to pins 48 to 53 so the SDHOST controller cannot control the primary SD card, there is an additional SDHCI controller (EMMC2) for that purpose.
Constants
[Expand]
BCMSDHOST specific constants BCMSDHOST_*
BCMSDHOST_DESCRIPTION = 'Broadcom BCM27XX SDHOST';
|
Description of BCMSDHOST device
|
|
BCMSDHOST_FIFO_READ_THRESHOLD = 4;
|
|
BCMSDHOST_FIFO_WRITE_THRESHOLD = 4;
|
|
BCMSDHOST_ALLOW_CMD23_READ = 1;
|
|
BCMSDHOST_ALLOW_CMD23_WRITE = 0;
|
|
BCMSDHOST_SDDATA_FIFO_PIO_BURST = 8;
|
|
BCMSDHOST_CMD_DALLY_US = 1;
|
|
[Expand]
BCMSDHOST register BCMSDHOST_*
BCMSDHOST_SDCMD = $00;
|
Command to SD card - 16 R/W
|
BCMSDHOST_SDARG = $04;
|
Argument to SD card - 32 R/W
|
BCMSDHOST_SDTOUT = $08;
|
Start value for timeout counter - 32 R/W
|
BCMSDHOST_SDCDIV = $0c;
|
Start value for clock divider - 11 R/W
|
BCMSDHOST_SDRSP0 = $10;
|
SD card response (31:0)- 32 R
|
BCMSDHOST_SDRSP1 = $14;
|
SD card response (63:32) - 32 R
|
BCMSDHOST_SDRSP2 = $18;
|
SD card response (95:64) - 32 R
|
BCMSDHOST_SDRSP3 = $1c;
|
SD card response (127:96)- 32 R
|
BCMSDHOST_SDHSTS = $20;
|
SD host status - 11 R
|
BCMSDHOST_SDVDD = $30;
|
SD card power control - 1 R/W
|
BCMSDHOST_SDEDM = $34;
|
Emergency Debug Mode - 13 R/W
|
BCMSDHOST_SDHCFG = $38;
|
Host configuration - 2 R/W
|
BCMSDHOST_SDHBCT = $3c;
|
Host byte count (debug) - 32 R/W
|
BCMSDHOST_SDDATA = $40;
|
Data to/from SD card - 32 R/W
|
BCMSDHOST_SDHBLC = $50;
|
Host block count (SDIO/SDHC) - 9 R/W
|
[Expand]
BCMSDHOST command register BCMSDHOST_SDCMD_*
BCMSDHOST_SDCMD_NEW_FLAG = $8000;
|
|
BCMSDHOST_SDCMD_FAIL_FLAG = $4000;
|
|
BCMSDHOST_SDCMD_BUSYWAIT = $800;
|
|
BCMSDHOST_SDCMD_NO_RESPONSE = $400;
|
|
BCMSDHOST_SDCMD_LONG_RESPONSE = $200;
|
|
BCMSDHOST_SDCMD_WRITE_CMD = $80;
|
|
BCMSDHOST_SDCMD_READ_CMD = $40;
|
|
BCMSDHOST_SDCMD_CMD_MASK = $3f;
|
|
[Expand]
BCMSDHOST clock divider register BCMSDHOST_SDCDIV_*
BCMSDHOST_SDCDIV_MAX_CDIV = $7ff;
|
|
[Expand]
BCMSDHOST host status register BCMSDHOST_SDHSTS_*
BCMSDHOST_SDHSTS_BUSY_IRPT = $400;
|
|
BCMSDHOST_SDHSTS_BLOCK_IRPT = $200;
|
|
BCMSDHOST_SDHSTS_SDIO_IRPT = $100;
|
|
BCMSDHOST_SDHSTS_REW_TIME_OUT = $80;
|
|
BCMSDHOST_SDHSTS_CMD_TIME_OUT = $40;
|
|
BCMSDHOST_SDHSTS_CRC16_ERROR = $20;
|
|
BCMSDHOST_SDHSTS_CRC7_ERROR = $10;
|
|
BCMSDHOST_SDHSTS_FIFO_ERROR = $08;
|
|
04 Reserved
|
02 Reserved
|
BCMSDHOST_SDHSTS_DATA_FLAG = $01;
|
|
|
BCMSDHOST_SDHSTS_TRANSFER_ERROR_MASK = BCMSDHOST_SDHSTS_CRC7_ERROR or BCMSDHOST_SDHSTS_CRC16_ERROR or BCMSDHOST_SDHSTS_REW_TIME_OUT or BCMSDHOST_SDHSTS_FIFO_ERROR;
|
|
BCMSDHOST_SDHSTS_ERROR_MASK = BCMSDHOST_SDHSTS_CMD_TIME_OUT or BCMSDHOST_SDHSTS_TRANSFER_ERROR_MASK;
|
|
[Expand]
BCMSDHOST host configuration register BCMSDHOST_SDHCFG_*
BCMSDHOST_SDHCFG_BUSY_IRPT_EN = (1 shl 10);
|
|
BCMSDHOST_SDHCFG_BLOCK_IRPT_EN = (1 shl 8);
|
|
BCMSDHOST_SDHCFG_SDIO_IRPT_EN = (1 shl 5);
|
|
BCMSDHOST_SDHCFG_DATA_IRPT_EN = (1 shl 4);
|
|
BCMSDHOST_SDHCFG_SLOW_CARD = (1 shl 3);
|
|
BCMSDHOST_SDHCFG_WIDE_EXT_BUS = (1 shl 2);
|
|
BCMSDHOST_SDHCFG_WIDE_INT_BUS = (1 shl 1);
|
|
BCMSDHOST_SDHCFG_REL_CMD_LINE = (1 shl 0);
|
|
[Expand]
BCMSDHOST emergency debug mode register BCMSDHOST_SDEDM_*
BCMSDHOST_SDEDM_FORCE_DATA_MODE = (1 shl 19);
|
|
BCMSDHOST_SDEDM_CLOCK_PULSE = (1 shl 20);
|
|
BCMSDHOST_SDEDM_BYPASS = (1 shl 21);
|
|
|
BCMSDHOST_SDEDM_WRITE_THRESHOLD_SHIFT = 9;
|
|
BCMSDHOST_SDEDM_READ_THRESHOLD_SHIFT = 14;
|
|
BCMSDHOST_SDEDM_THRESHOLD_MASK = $1f;
|
|
|
BCMSDHOST_SDEDM_FSM_MASK = $f;
|
|
BCMSDHOST_SDEDM_FSM_IDENTMODE = $0;
|
|
BCMSDHOST_SDEDM_FSM_DATAMODE = $1;
|
|
BCMSDHOST_SDEDM_FSM_READDATA = $2;
|
|
BCMSDHOST_SDEDM_FSM_WRITEDATA = $3;
|
|
BCMSDHOST_SDEDM_FSM_READWAIT = $4;
|
|
BCMSDHOST_SDEDM_FSM_READCRC = $5;
|
|
BCMSDHOST_SDEDM_FSM_WRITECRC = $6;
|
|
BCMSDHOST_SDEDM_FSM_WRITEWAIT1 = $7;
|
|
BCMSDHOST_SDEDM_FSM_POWERDOWN = $8;
|
|
BCMSDHOST_SDEDM_FSM_POWERUP = $9;
|
|
BCMSDHOST_SDEDM_FSM_WRITESTART1 = $a;
|
|
BCMSDHOST_SDEDM_FSM_WRITESTART2 = $b;
|
|
BCMSDHOST_SDEDM_FSM_GENPULSES = $c;
|
|
BCMSDHOST_SDEDM_FSM_WRITEWAIT2 = $d;
|
|
BCMSDHOST_SDEDM_FSM_STARTPOWDOWN = $f;
|
|
|
BCMSDHOST_SDDATA_FIFO_WORDS = 16;
|
|
|
BCMSDHOST_USE_CMD23_FLAGS = (BCMSDHOST_ALLOW_CMD23_READ * MMC_DATA_READ) or (BCMSDHOST_ALLOW_CMD23_WRITE * MMC_DATA_WRITE);
|
|
[Expand]
BCMSDHOST mailbox constants BCMSDHOST_MBOX_TAG_SET_*
BCMSDHOST_MBOX_TAG_SET_SDHOST_CLOCK = $00038042;
|
Tell the firmware the SD Host clock setting so it will be adjusted for changes in core frequency
|
Type definitions
BCMSDHOST mailbox tag request
[Expand]
TBCMSDHOSTMailboxTagSetSDHostClock = record
Mailbox tag request for BCMSDHOST_MBOX_TAG_SET_SDHOST_CLOCK
|
Clock:LongWord;
|
|
Value1:LongWord;
|
|
Value2:LongWord;
|
|
BCMSDHOST host
[Expand]
PBCMSDHOSTHost = ^TBCMSDHOSTHost;
TBCMSDHOSTHost = record
SDHCI Properties
|
SDHCI:TSDHCIHost;
|
|
BCMSDHOST Properties
|
IRQ:LongWord;
|
The IRQ number for this device
|
Lock:TSpinHandle;
|
Host lock (Differs from lock in Host portion) (Spin lock due to use by interrupt handler)
|
EnableFIQ:LongBool;
|
Use FIQ instead of IRQ
|
GPIOFirst:LongWord;
|
The starting pin number for GPIO assignments (or GPIO_PIN_UNKNOWN if externally configured)
|
GPIOLast:LongWord;
|
The ending pin number for GPIO assignments (or GPIO_PIN_UNKNOWN if externally configured)
|
GPIOFunction:LongWord;
|
The function number for GPIO assignments (or GPIO_FUNCTION_UNKNOWN if externally configured)
|
ClockDivider:LongWord;
|
Cached Clock Divider (CDIV) register
|
HostConfiguration:LongWord;
|
Cached Host Configuration (HCFG) register
|
FirmwareSetsClockDivider:LongBool;
|
True if the firmware controls the clock divider
|
CommandQuickPollRetries:LongWord;
|
|
NanosecondsPerFifoWord:LongWord;
|
|
AllowDMA:LongBool;
|
Allow DMA to be used for data transfers
|
ResetClock:LongBool;
|
Reset the clock for the next request
|
MaxDelay:LongWord;
|
Maximum length of time spent waiting (in Milliseconds)
|
StopTime:Int64;
|
When the last stop was issued (in Clock Ticks)
|
DrainWords:LongWord;
|
Last words of FIFO to drain on DMA read
|
DrainOffset:LongWord;
|
Offset for data during FIFO drain on DMA read
|
UseSBC:LongBool;
|
Use CMD23 (Set Block Count) for the current transfer
|
UseBusy:LongBool;
|
Wait for busy interrupt on current command
|
DelayAfterStop:LongWord;
|
Minimum time between stop and subsequent data transfer (in Microseconds)
|
DelayAfterThisStop:LongWord;
|
Minimum time between this stop and subsequent data transfer (in Microseconds)
|
UserOverclock50:LongWord;
|
User's preferred frequency to use when 50MHz is requested (in MHz)
|
Overclock50:LongWord;
|
Frequency to use when 50MHz is requested (in MHz)
|
Overclock:LongWord;
|
Current frequency if overclocked, else zero (in Hz)
|
PIOLimit:LongWord;
|
Maximum block count for PIO (0 = always DMA / 0x7FFFFFF = always PIO)
|
PIOTimeout:LongWord;
|
PIO Read or Write block timeout (in milliseconds)
|
Public variables
None defined
Function declarations
Initialization functions
[Expand]
procedure BCMSDHOSTInit;
Description: Initialize the BCMSDHOST unit and parameters
Note
|
Called only during system startup
|
BCMSDHOST functions
[Expand]
function BCMSDHOSTCreate(Address:PtrUInt; const Name:String; IRQ,DREQ,ClockMinimum,ClockMaximum,GPIOFirst,GPIOLast,GPIOFunction:LongWord; EnableFIQ:Boolean):PSDHCIHost;
Description: Create and register a new BCMSDHOST SDHCI device which can be accessed using the SDHCI API
Address
|
The address of the BCMSDHOST registers
|
Name
|
The text description of this device which will show in the device list (Optional)
|
IRQ
|
The interrupt number for the BCMSDHOST
|
DREQ
|
The DMA data request ID for the BCMSDHOST
|
ClockMinimum
|
The minimum frequency for the BCMSDHOST clock
|
ClockMaximum
|
The maximum frequency for the BCMSDHOST clock
|
GPIOFirst
|
The starting pin number for GPIO assignments (or GPIO_PIN_UNKNOWN if externally configured)
|
GPIOLast
|
The ending pin number for GPIO assignments (or GPIO_PIN_UNKNOWN if externally configured)
|
GPIOFunction
|
The function number for GPIO assignments (or GPIO_FUNCTION_UNKNOWN if externally configured)
|
EnableFIQ
|
Enable fast interrupt support for the BCMSDHOST
|
Return
|
Pointer to the new SDHCI device or nil if the SDHCI device could not be created
|
[Expand]
function BCMSDHOSTDestroy(SDHCI:PSDHCIHost):LongWord;
Description: Stop, deregister and destroy a BCMSDHOST SDHCI device created by this driver
SDHCI
|
The SDHCI device to destroy
|
Return
|
ERROR_SUCCESS if completed or another error code on failure
|
BCMSDHOST MMC functions
[Expand]
function BCMSDHOSTSendCommand(MMC:PMMCDevice; Command:PMMCCommand):LongWord;
Description: Implementation of MMCDeviceSendCommand API for BCMSDHOST SDHCI
Note
|
Not intended to be called directly by applications, use MMCDeviceSendCommand instead.
|
[Expand]
function BCMSDHOSTSetIOS(MMC:PMMCDevice):LongWord;
Description: Implementation of MMCDeviceSetIOS API for BCMSDHOST SDHCI
Note
|
Not intended to be called directly by applications, use MMCDeviceSetIOS instead.
|
[Expand]
function BCMSDHOSTGetCardDetect(MMC:PMMCDevice):LongWord;
Description: Implementation of MMCDeviceGetCardDetect API for BCMSDHOST SDHCI
Note
|
Not intended to be called directly by applications, use MMCDeviceGetCardDetect instead.
|
[Expand]
function BCMSDHOSTGetWriteProtect(MMC:PMMCDevice):LongWord;
Description: Implementation of MMCDeviceGetWriteProtect API for BCMSDHOST SDHCI
Note
|
Not intended to be called directly by applications, use MMCDeviceGetWriteProtect instead.
|
BCMSDHOST SDHCI functions
[Expand]
function BCMSDHOSTHostStart(SDHCI:PSDHCIHost):LongWord;
Description: Implementation of SDHCIHostStart API for BCMSDHOST SDHCI
Note
|
Not intended to be called directly by applications, use SDHCIHostStart instead.
|
[Expand]
function BCMSDHOSTHostStop(SDHCI:PSDHCIHost):LongWord;
Description: Implementation of SDHCIHostStop API for BCMSDHOST SDHCI
Note
|
Not intended to be called directly by applications, use SDHCIHostStop instead.
|
[Expand]
function BCMSDHOSTReset(SDHCI:PSDHCIHost; Mask:Byte):LongWord;
Description: Implementation of SDHCIReset API for BCMSDHOST SDHCI
Note
|
Not intended to be called directly by applications, use SDHCIReset instead.
|
[Expand]
function BCMSDHOSTHardwareReset(SDHCI:PSDHCIHost):LongWord;
Description: Implementation of SDHCIHardwareReset API for BCMSDHOST SDHCI
Note
|
Not intended to be called directly by applications, use SDHCIHardwareReset instead.
|
[Expand]
function BCMSDHOSTSetPower(SDHCI:PSDHCIHost; Power:Word):LongWord;
Description: Implementation of SDHCISetPower API for BCMSDHOST SDHCI
Note
|
Not intended to be called directly by applications, use SDHCISetPower instead.
|
[Expand]
function BCMSDHOSTSetClock(SDHCI:PSDHCIHost; Clock:LongWord):LongWord;
Description: Implementation of SDHCISetClock API for BCMSDHOST SDHCI
Note
|
Not intended to be called directly by applications, use SDHCISetClock instead.
|
[Expand]
procedure BCMSDHOSTCommandWaitWorker(SDHCI:PSDHCIHost);
Description: Worker thread task to wait for BCMSDHOST command completion
Note
|
Not intended to be called directly by applications
|
[Expand]
procedure BCMSDHOSTDMARequestCompleted(Request:PDMARequest);
Description: DMA Request completion callback for the BCMSDHOST host controller
Note
|
Not intended to be called directly by applications
|
[Expand]
function BCMSDHOSTSharedInterruptHandler(Number,CPUID,Flags:LongWord; SDHCI:PSDHCIHost):LongWord;
Description: Interrupt handler for the BCMSDHOST host controller
Note
|
Not intended to be called directly by applications
|
BCMSDHOST helper functions
[Expand]
function BCMSDHOSTSetSDHostClock(var Clock,Value1,Value2:LongWord):LongWord;
Description: Set the SD Host Clock value in the Mailbox property tags channel
Return to Unit Reference