SD Card Analysis Two

Source: Internet
Author: User
Tags goto

4, Core layer analysis:
The core layer completes the implementation of the different protocols and specifications and provides the interface function for the driver of the host layer, the two functions we have called in the host layer:
Mmc_alloc_host (sizeof (struct s3cmci_host), &pdev->dev);
Mmc_add_host (MMC);
We start with these two functions to analyze how the core layer interacts with the host layer.
First look at the Mmc_alloc_host function:
Dev_set_name (&host->class_dev, "mmc%d", Host->index);
host->parent = Dev;
host->class_dev.parent = Dev;
Host->class_dev.class = &mmc_host_class;
Device_initialize (&host->class_dev);
These sentences will result in/sys/class/mmc_host under the MMC0 directory, add Class equipment, in the 2.6.21 version, the Class_device of class equipment has been nearly replaced by device, ldd3p387 content a bit out of the
Init_delayed_work (&host->detect, Mmc_rescan);
Initialization of a Task Force column, the delay function is mmc_rescan, this delay function is very important, the afternoon to be detailed analysis
Finally, some default configurations are made to host, but these configurations are reset after the probe function.
Analysis Mmc_add_host (MMC);
Device_add (&host->class_dev); This is the true addition of the class device.
which calls the Mmc_start_host
void Mmc_start_host (struct mmc_host *host)
{
Mmc_power_off (host);
Mmc_detect_change (host, 0);
}
Mmc_power_off iOS is set up, and then call Mmc_set_ios (host);
Host->ios.power_mode = Mmc_power_off;
Host->ios.bus_width = mmc_bus_width_1;
host->ios.timing = mmc_timing_legacy;
Mmc_set_ios (host);
Mmc_set_ios (host) key statement Host->ops->set_ios (host, iOS); the set_ios here is actually what we mentioned earlier. Set_ios = S3cmci_set_ios,
Look at Mmc_detect_change (host, 0) and the last sentence is
Mmc_schedule_delayed_work (&host->detect, delay);
is actually calling the delay function we said earlier Mmc_rescan
MMC_POWER_UP (host);//This function is actually similar to the previous Mmc_power_off, but set the iOS needed for startup
Mmc_go_idle (host);
CMD0, from inactive to idle
Mmc_send_if_cond (host, Host->ocr_avail),//Send Sd_send_if_cond, is the command to be set using SD2.0 card
/*suppot for 2.0 card*/
* ... then normal SD ...
*/
Err = Mmc_send_app_op_cond (host, 0, &OCR);
if (!err) {
if (MMC_ATTACH_SD (host, OCR))
Mmc_power_off (host);
Goto out;
}
The blue part is in accordance with the SD Card protocol SD card boot process, including the inactive mode, card recognition mode and data transmission mode of three modes of a total of nine states of conversion, you need to refer to the relevant specifications to understand. You can refer to the following three Zhangtu for a preliminary understanding of patterns and states, and state transitions.

Our initial SD card status when inactive state calls Mmc_go_idle (host), Send command CMD0 is its in idle state.
Let's analyze the mmc_go_idle in detail.
memset (&cmd, 0, sizeof (struct mmc_command));
Cmd.opcode = mmc_go_idle_state; Mmc_go_idle_state is an order CMD0
Cmd.arg = 0; This command has no parameters
Cmd.flags = Mmc_rsp_spi_r1 | Mmc_rsp_none | MMC_CMD_BC;
Err = Mmc_wait_for_cmd (host, &cmd, 0);//See note 1
Mmc_delay (1);


Note 1:mmc_wait_for_cmd (host, &cmd, 0) is used to send commands, let's uncover its mystery.
memset (&MRQ, 0, sizeof (struct mmc_request));
memset (cmd->resp, 0, sizeof (CMD->RESP));
Cmd->retries = retries;
mrq.cmd = cmd; embed a command in an MMC request
Cmd->data = The data portion of the NULL;MMC command is set to NULL, which means that we are transferring commands rather than data
Mmc_wait_for_req (host, &MRQ);//Key part
Mmc_start_request is called in this function, and this function calls Host->ops->request (host, MRQ), which is the s3cmci_request we analyzed earlier, so that the MMC The core second nuclear host layer shook hands.

Let's look again: Err = Mmc_send_app_op_cond (host, 0, &OCR);//Note a
if (!err) {
if (MMC_ATTACH_SD (host, OCR))//Note II
Mmc_power_off (host);
Goto out;
Note: In fact, to send the ACMD41 command, this command can be used to obtain the SDcard allowable voltage range value, because this is an application command, all send it need to send the cmd_55 command. After completion of the card state becomes ready to obtain the voltage range stored in OCR, and then call MMC_ATTACH_SD (Host, OCR) to see whether this voltage range to meet the requirements of the host, not satisfied, then Power_off host.
Note II: MMC_ATTACH_SD completes the match, and initializes the function of the card
HOST->OCR = Mmc_select_voltage (host, OCR); see if it matches, and if it does, do the following initialization work
Mmc_sd_init_card (host, HOST->OCR, NULL); we analyze the function
(1) mmc_all_send_cid () This function takes place CMD2, obtains card's identity information, enters the identity state
(2) card = Mmc_alloc_card (host, &sd_type); Assign an SD-type cards structure
(3) Then call Mmc_send_relative_add, get the relative address of the card, note that a front card and host communications are using the default address, now has its own address, into the stand_by state
(4) Obtain information about CSD registers by sending SEND_CSD (CMD9), including block length, card capacity, etc.
(5) Mmc_select_card (card) to send CMD7, select the current radd address cards, any time the bus only a card was selected to enter the transmission state,
(6) Call MMC_APP_SEND_SCR Send command ACMD51 get the content of SRC register, enter to Sending-data state
In the function, the contents of each card register are decoded and saved to the corresponding members of the CMD structure.
(7) if (Host->ops->get_ro (host) > 0)
Mmc_card_set_readonly (card);
By invoking the Get_ro (host) function, it is actually the S3cmci_get_ro function. We decide whether to write protection, and if yes, set the card status to read-only
Finally, in MMC_ATTACH_SD, we add the card structure
Mmc_add_card (Host->card);
Dev_set_name (&card->dev, "%s:%04x", Mmc_hostname (Card->host), Card->rca); Here we name the card with the host name +rca address we can see in the /sys/devices/platform/s3c2440-sdi/mmc_host:mmc0/appears in the mmc0:0002 directory, this 0002 is the RCA address

Here we analyzed the core layer of MMC.

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.