Linux Driver Development

The MMC/SD driver model is widely used in embedded development, and its corresponding Linux system framework can be classified under block devices. If you want to understand the IO storage stack, you can start with the simple MMC/SD driver model.

  1. Linux MMC/SD Driver Model

The MMC/SD driver in Linux is mainly divided into three layers: card layer, core layer, and host layer.

  • Card Layer:

    This layer is responsible for writing data to memory or reading data from memory in a block device manner.

  • Core Layer:

    This layer determines how data is formatted and transmitted between the MMC/SD host controller and the memory of the MMC/SD card (i.e., block device). This format and method are referred to as specifications or protocols.

  • Host Layer:

    This layer implements the specific driver for the corresponding MMC/SD controller, including the initialization of the MMC/SD controller, register read/write operations, and the command and data transmission interface for the SD card.

Linux Driver Development

2. Important Data Structures in the Linux MMC/SD Driver Framework

2.1 struct mmc_host Structure

Linux Driver Development

The struct mmc_host is used for command requests and data transfer information with the core layer.

2.2 struct mmc_host_ops Structure

Linux Driver Development

In this structure, request is the main entry point for SD card command data transfer operations, and set_ios is the entry point for configuring SD controller register operations. These are two essential operations that must be implemented in the driver.

3. SD Card Initialization Process

The SD card initialization process is implemented in the core layer and integrates all commands for the SD card. For driver development, it is only necessary to implement the request operation and report command and data interrupts using the mmc_request_done() function. The SD card initialization process is shown in the figure below:

Linux Driver Development

4. MMC/SD Card Hot Plugging

For the hot plugging feature, the MMC/SD framework provides the mmc_detect_change() function to report card insertion and removal events. Generally, the MMC/SD controller will provide interrupt functionality for insertion and removal, and the driver software only needs to report this in the interrupt function.

Leave a Comment