CAM, FreeBSD, Hardware, mmccam, SDIO, Software

Detailed SDIO protocol Implementation

Reference: Wikipedia, 

SDIO cards are intended to provide high-speed data Input/Output on our regular sd card slot. SDIO cards are compatible with any sd card slot and will not cause any physical damage to the host if it’s not compatible with SDIO. When SDIO is plugged in an SDIO compatible host, in its early stage it is in low power mode and consumes very little current. The host identifies the SDIO card, it’s power requirement, it’s I/O capabilities, etc. If the host finds that the power requirement is manageable and there is a driver for the I/O functionality card is offering it allows the SDIO card to power up completely and start it’s I/O functions.  SDIO card allows up to 7 different I/O functions along with 1 memory function. It’s available in the market in 2 form factors: miniSDIO and full-size SDIO. For example, is a miniSDIO wifi card by spectec.

Types of SDIO cards

Full speed SDIO cards:

It supports SPI, 1 bit SD mode, 4 bit SD transfer mode at a full clock speed of 1-25 Mhz, with data transfer rate up to 100Mbps

Low-speed SDIO cards:

It supports SPI, 1 bit SD transfer mode, and optional 4-bit mode is optional. It operates at a low clock frequency of 0-400 kHz. It’s usually used to provide low speed I/O compatibility with minimum hardware like that in GPS, Scanners, etc.

For SD-Combo cards, 4-bit mode and full speed are mandatory.

SDIO Card Modes

Consider the pinout of the SD card (again):

Note that Vcc and Vdd pin’s pads are a little bit extended. This is to ensure that upon insertion of the card, these two pins come in contact with the host first. This further ensures that POR works correctly and resets all registers to their default values. Which otherwise may corrupt the data and could thus increase the card initialization failure chances.

SPI Mode

In this mode pin, 8 is used as an interrupt pin, and rest other pins are used in the way they are described in the image. DO(Data Out) and DI(data input) is MISO and MOSI pins respectively. It’s mandatory for all SD cards.

1-bit data transfer mode

In this mode data is transferred only on the Data 0 pin and pin 8 is still used for the interrupt. Other pins are used to normally as per defined by the SD protocol. It’s also mandatory for all SD cards.

4-bit data transfer mode

This data is transferred on all 4 data pins. Thus, there is no pin left for interrupt. Then, for interrupts, a special sequence of the clock signal is used. This mode is optional/ Only available in SDHC High capacity SD cards.

Note: A low-speed SDIO card with only 1-bit transfer mode available is compatible with an SDIO aware host that supports only 4-bit data transfer mode. Only, performance will be reduced.

Before looking at the initialization process, I would refer to have some background of different SDIO registers and commands available.

SDIO Card internal structure and associated registers

In the image given above, the area is SDIO specific register area. Apart from this, within an SDIO card there are also 7 standard registers as defined by SD specifications, which are namely:

  • OCR(32 bit)
    • describes card power state, voltage level it supports, PSU status
    • in an SD Combo, there may be 2 OCR registers one for I/O and one for memory
    • I/O and memory may work on different voltages
    • Note that the I/O OCR format is different from the memory version in that it is only 24 bits long.
  • CID(128 bits)
    • this register provides contains Card IDentification number
    • Max. number of CIDs is 1
    • If the card is I/O only, It might not have a CID register and any attempt to read it will return in an invalid command(In SPI mode) or card won’t just respond(In SD mode)
  • CSD(128 bits)
    • Card Specific Data register contains all technical details of the card
    • It might be absent in I/O only cards
  • RCA(16 bits)
    • Relative Card Access register is used to store card address in SD mode
    • There can be max. of one RCA register
  • DSR(16 bits)
    • SDIO cards do not support DSR register
  • SCR(64 bits)
    • SCR provides info. of SD card’s special features
    • Max. of one SCR register per SD card
    • In I/O only case, SCR register is not supported
    • The structure of this register differs in SDIO mode.

Notice the current state register(9:12), it can be used to distinguish between an I/O only card and normal memory card. Note that In the SD bus mode, the card shall not respond to an Illegal Command or a command with a CRC error. This is true for an I/O only card as well as for combo cards, even in cases where the erroneous command and the command that follows are not targeting the same card module (Memory or I/O).

CIA(Common Input/Output Area)

It must is a must in all SDIO cards. The CIA is accessed by the host via I/O read and write functions. The registers in CIA are provided to enable/disable the functions of I/O operations, control interrupts, optionally load software modules to support I/O functionality. Within the CIA there are 3 specific registers:

  • Card Common Control Registers(CCCR)
  • Function Basic Registers(FBR)
  • Card Information Structure(CIS)

Card common control registers(CCCR)

Bits in CCCR are mixed R/W and Read Only. They provide quick host checking and control of I/O cards enable or interrupt on a per-function basis. CCCR is accessible even if none of the I/O function is working. It can thus be used to enable/disable any function. Access to CCCR can be achieved via I/O Read/Write commands. All RFU(Reserved for Future Use) bits are by default 0 after power-up and are read-only. Below is the detailed structure of the CCCR register: Let’s now study each Register one by one.

CCCR/SDIO Register
  • 4 CCCRx bits defines the version used by CCCR and the FBR format it supports
  • 4 SDIOx bits defines SDIO specs that this card supports
SD Specification number
  • SD Format Version number. These 4 bits contain the version of the SD Physical
    Specification that this card supports
I/O Enable
  • It is used to enable(bit=1) or disable(bit=0) a function of SDIO
  • It must be called only if IOR=1 i.e module is ready for I/O operations
I/O Ready
  • IOR=0 if the function is not ready for I/O operations on any register, maybe due to internal fault or just waiting for some uninterruptable command to complete its execution
IEN (Interrupt enable)
  • If IENx is set to 1, the function is allowed to send interrupt to the host.
  • Make sure that master Interrupt Enable is also 1(Bit 0 of this register) to enable interrupts
INTx (Interrupt pending)
  • If INTx = 0 it means there is no pending interrupt for this function.
I/O Abort
  • Used in order to abort an I/O read or write and free the SD bus
  • Other 3 bits are used to point towards the I/O function to be aborted
  • This abort procedure does not work for SPI write operations.
  • RES bit is used to reset all SDIO function at once
Bus Interface control
  • Bus Width register is used to select between low speed and high-speed mode
  • CD bit is used to connect/disconnect a pull up register, mainly used for SDIO card detection
  • Support Continuous SPI interrupt(SCSI bit) indicates that SDIO card supports SPI interrupt irrespective of CS pin
  • ECSI (Enable Continuous SPI interrupt) is used to enable SPI interrupts

Card Capability

  • (SDC)Card Supports Direct Commands during data transfer.
  • This bit applies only to the SD modes, it does not apply to SPI mode.
  • It’s essential in SD Combo cards
  • SMB- Card support multiple blocks for extended R/W operations
  • SRW- card supports read wait. In this, all functions can wait for a signal on data[2] bit

Other registers are quite obvious, so I am skipping them. Refer directly to above-mentioned datasheet for any queries related to them.

Function Basic Registers(FBR)

Each SDIO function has 256 bytes of registers under FBR that are used for function-specific configurations. Here is the basic outline of FBR:

CIS(Card Information Structure) Register

The Card Information Structure provides more complete information about the card and the individual functions.

We will continue with other SDIO functions in my next post.

Tagged ,

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.