About the Linux 2.6 MMC/SD driver

Source: Internet
Author: User

The following are my notes from jollen (non-teaching documents), which cannot be clearly explained in many places. Please complete this part on your own. This article is a reference for anyone who wants to study the implementation of the Linux MMC driver (MMC core. Based on Linux 2.6.17.7, the kernel of the updated version is added with many patches (for example, sdhc patches of Linux 2.6.19). These updates are not discussed.

As mentioned in the previous article "Overview of SD/MMC/sdio support for Linux (Open Source)", the current Linux SD/MMC/sdio "strictly speaking 」, only MMC memory cards are supported. If an SD memory card is to be inserted, there are many restrictions.

From the perspective of the Linux driver, the SD/MMC driver layer in Linux contains the following implementation (kconfig ):

  • Config_mmc
  • Config_mmc_block

The related files are located in the drivers/MMC/directory. We can find the actual files by using makefile:

#

# Core

#

OBJ-$ (config_mmc) + = mmc_core.o

#

# Media drivers

#

OBJ-$ (config_mmc_block) + = mmc_block.o

#

# Host drivers

#

OBJ-$ (config_mmc_armmmci) + = mmci. o

OBJ-$ (config_mmc_pxa) + = pxamci. o

OBJ-$ (config_mmc_imx) + = imxmmc. o

OBJ-$ (config_mmc_sdhci) + = sdhci. o

OBJ-$ (config_mmc_wbsd) + = wbsd. o

OBJ-$ (config_mmc_au1x) + = au1xmmc. o

OBJ-$ (config_mmc_omap) + = OMAP. o

OBJ-$ (config_mmc_at91rm9200) + = at91_mci.o

The mmc_core-y: = MMC. O mmc_queue.o mmc_sysfs.o

The host controller driver is not discussed. The implementation files of the MMC core API layer are as follows:

  1. Drivers/MMC/mmc. C: implements the main MMC command and protocol.
  2. Drivers/MMC/mmc_queue.c: Implementation of I/O Request queue.
  3. Drivers/MMC/mmc_sysfs.c: For Linux 2.6KobjectAndSysfsImplementation.
  4. Drivers/MMC/mmc_block.c: The implementation of the block layer architecture, that is, the file operation part of interface to user-space.

The MMC core layer contains the following original program code:

  • Drivers/MMC/mmc. c
  • Drivers/MMC/mmc_queue.c
  • Drivers/MMC/mmc_sysfs.c

In the block layer, mmc_block.c registers with the kernel as devfs:

Static struct mmc_driverMmc_driver= {

. DRV = {

. Name = "mmcblk ",

},

. Probe = mmc_blk_probe,

. Remove = mmc_blk_remove,

. Suspend = mmc_blk_suspend,

. Resume = mmc_blk_resume,

};

 

Static int _ init mmc_blk_init (void)

{

Int res =-enomem;

 

Res =Register_blkdev (Major, "MMC ");

If (RES <0 ){

Printk (kern_warning "unable to get Major % d for MMC media: % d/N ",

Major, Res );

Goto out;

}

If (Major = 0)

Major = res;

 

Devfs_mk_dir ("MMC ");

ReturnMmc_register_driver (& mmc_driver );

 

Out:

Return res;

}

...

Module_init (mmc_blk_init );

Mmc_register_driver () registers with the MMC core layer, and then the MMC CoreKobjectRegister. All the friends who have learned the Linux 2.6 driver know that the core API layer must call driver_register ()KobjectRegisterDriverFor the host controller driver of the underlying machine-dependentKobjectRegisterPlatform driver.

BecauseKobjectYes callbackFoPsSo the mmc_blk_probe () function is the entry point of the MMC block layer ). Therefore, the mmc_blk_probe () function determines all actions of the MMC block layer. The MMC block layer of Linux 2.6.17.7 uses the familiar genhd. C layer.

The most important "initialize I/O Request queue" action of the Linux block-layer driver is to call mmc_init_queue () of the MMC core layer in the mmc_blk_probe () phase.

After learning about the overall architecture of MMC in Linux, you can start to study the implementation of specifications in depth.

 

 

 

========================================================== ========================================================== ========================

========================================================== ========================================================== ========================

About the Linux 2.6 MMC/SD driver

The MMC/SD driver in Linux 2.6 is divided into the following parts:
1. sysfs-layer Bus Type processing: registers a group of MMC type processing functions, marked as "MMC"
2. MMC/SD fast device management: register a block device and a group of MMC bus driver sub-functions to implement queue management for Block devices.
3. MMC/SD host management: Implements host management.
4. Implement a host driver instance for a specific MCU: register a host entity, interrupt processing function, Io setting function, request processing function, etc.

The above 1.2.3 basically does not need to be modified, and what needs to be processed is 4. the work to be done. when a card is inserted, the card in Step 4 interrupts the activation card initialization program and bus detection function. the MMC bus detection function calls the detection function of the block device, in the card device detection function, the request queue of the block device is initialized and a gendisk entity is registered (the file system will access the MMC block device through the gendisk entity in the future ), create a real MMC/SD device in sysfs. the block device communicates with the specific host through the IO setting function and request function registered by the specific host.

 

 Original article addressHttp://www.ednchina.com/blog/mcu_study/19902/message.aspx

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.