[MMC] Identification and operation of Mmc/sd/sdio under Linux

Source: Internet
Author: User

Transferred from: http://blog.csdn.net/skdkjzz/article/details/38927943

We know that in the process of scanning the card, the host is identified in the order of Sdio SD MMC, and it is important to note that this order is in its annotations. In this article, we'll look at the sdio identification process, which corresponds to the function of Mmc_attach_sdio (host) (the function is located in the file drivers/mmc/core/sdio.c), then the same controller is how to distinguish between Mmc/sd/sdio devices, The software keeps rotation the device, sending different instructions, and then different devices react differently.

This function probably does the following work

1, send the CMD5 command to the card, the command has two functions: first, by judging whether the card has feedback information to determine whether it is a sdio device (only sdio equipment to CMD5 command feedback, other cards are not feedback); second, if it is a sdio device, will give the host feedback voltage information, that is, tell the host, the card can support the voltage is how much.

2, host according to the SDIO card feedback back voltage requirements, to provide the appropriate voltage.

3. Initialize the Sdio card

4, the registration Sdio each function module

5. Register Sdio Card

For specific explanations of the above features, the following will be combined with the program to

1, the CMD5 command send

The function of line No. 789 is the CMD5 command sent, if the card has feedback to the command, err is 0, otherwise, err is not 0, exit directly, and the point to note is that the function of the last parameter of the OCR, which is stored in the feedback command, Sdio Device to CMD5 Feedback command for R4, the following to carefully analyze this R4, because the subsequent use of this R4 command. From the Sdio spec document, we can get the format of the R4 command.

as can be seen, the command has 48 bits, but our OCR variable is 32 bits, then how to store it? The system removes the first 8 bits of the original command and the 8 bits at the end, leaving only the intermediate 32, which is the truncated command format, as follows:

The specific descriptions are as follows:

C--I don't know yet.

Number 0f IO functions-Each SDIO device has a function block, which three bits records how many function blocks the device has, up to 7

Memory present– Indicates whether the device is purely a function block device, or contains storage space, if 0 is the former, if 1 is the latter

Stuff Bits--no practical purpose is typically 0

I/O ocr– the voltage range that the device can support (see SDIO spec for specific description)

2. Configure the voltage

OCR is our feedback command R4 (32 bits after truncation), so what is the meaning of ocr&0x7f? As can be seen from the R4 format, its low 24 bits represent the voltage range that can be supported, let's take a detailed look at the 24-bit OCR format

Now it should be possible to know the meaning of ocr&0x7f, that is, to abandon the reserved voltage range.

Focus on Mmc_select_voltage

The phase of the 1080th line is to determine whether the actual voltage supported by the host matches the voltage required by the card, and if so, the value of OCR is not 0, otherwise it will be 0.

A simple introduction to the 1082th row of the FFS function, its role is to return the parameter of the first 1 bit of the position (FFS (0) =0,ffs (1) =1,ffs (8) =4), then the function used here is to remove the card required the actual voltage is how much;

The Mmc_set_ios function in line 1090th completes that voltage reconfiguration by calling Sdhci_set_power to write the voltage that HOST->IOS.VDD represents to the register pwrconn (for a more detailed procedure, keep track of the source code)

3. Initialize the Sdio card

The No. 821 line is to initialize the function of the Sdio card This function is very long, also very important, here the author does not list its program code, just lists the most important of the several:

1. Assign a Mmc_card variable card through the function Mmc_alloc_card

2, by reading the R4 command in the Bit27 (that is, memory Present) to determine whether the card is a pure IO card, or also contains storage functions. I use the WiFi module for pure io function, so card->type = Mmc_type_sdio (This is very important, will be used later) (next focus on analyzing the situation of Mmc_type_sdio)

3. Obtain the slave address of the device (relative addr) by sending the CMD3 command, and store it in the variable Card->rca. The Card->rca of the WiFi module used by the author = 1

4, by sending CMD7, select the corresponding card from the address

5. Set the clock frequency of the card work by calling the function Mmc_set_clock

6. Set the 4-bit data transmission mode by sending the CMD52 command

4. Register Sdio function Module

847 rows of variables Funcs store the Sdio card contains the number of IO function blocks, 851 rows to 857 lines is one by one to initialize each IO function block, the following to focus on the contents of the function:

The 71st line is to assign the Sdio_func struct variable, which stores the parameters of the function block.

The 75th line is to give the function block number, the number is from 1 to 7 (because a SDIO device has a maximum of 7 function blocks), stored in the variable Func->num

The 78th line is to read the Sdio card in the FBR register on the card's function type data, stored in the Func->class variable (specifically about the FBR register content, you can refer to the SDIO spec document)

The 82nd line is to read the contents of the CIS register in the SDIO card

The above program is to register the function module one by one into the device model, here want to focus on the registration name (name), it is composed of three parts, each part is separated by a colon (that is, the name of the host: RCA: function block number). Specifically to the author's use of the WiFi module, because its host name is MMC2, RCA = 1, and there are two function modules (the function module number is 1 and 2), so in the/sys/bus/sdio/devices directory can see the following two device names

Mmc2:0001:1

Mmc2:0001:2

5. Register Sdio Card

The Mmc_add_card function above is the registration card (this card is assigned and defined in the 3rd part, the Sdio card is initialized)

The No. 259 line is to name the card, the format of the host name: from the address, for the author's WiFi module is mmc2:0001

The No. 261 to No. 273 line is based on Card->type to identify the type of card, to give the corresponding string, the author's WiFi module is "SDIO"

The No. 275 line is to print information, specifically does not explain the author's printing information for mmc2:new High speed SDIO card at address 0001 (can usually be seen in the kernel boot information whether the statement to determine whether the card is correctly identified)

The No. 283 line is to register the card into the Linux device model registration results can be seen in the/sys/bus/mmc/devices directory card name, the author is mmc2:0001

[MMC] Identification and operation of Mmc/sd/sdio under Linux

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.