Statement: Many of the contents and ideas of this article refer to http://www.wowotech.net/comm/mmc_host_driver.html, thank the original author!
1. Preface
This article is the second chapter of the Linux MMC framework, which introduces the knowledge of the MMC host controller driver from the perspective of the driver engineer, learning and mastering how to write a driver for an MMC controller under the framework of the MMC framework. At the same time, through this article, we will further understand the MMC, SD, Sdio and other related basic knowledge.
2. Main data structure and API 2.1 struct MMC_HOST
Elemete Name |
struct Mmc_host |
Path |
Include/linux/mmc/host.h |
Responsiblities |
MMC core uses struct mmc_host to abstract MMC host controller |
Attributions |
- Parent:struct device * Type, which points to the parent of this MMC host, is typically the platform device that registers this mmc_host
- Class_dev: A struct device type variable that is the embodiment of the MMC host as a "device" in the device model. Of course, in the name of a person, the device belongs to a class (Mmc_host_class)
- Index: The mmc_host number, because there may be multiple MMC host controllers
- Ops:struct mmc_host_ops * Type of pointer containing all of this mmc_host set of operating functions, see struct mmc_host_ops struct body description
- F_min, F_max, f_init, the clock frequency range supported by the MMC host, minimum frequency, maximum frequency, and initial frequency
- Ocr_avail: Normal OCR voltage range
- Ocr_avail_sdio, OCR_AVAIL_SD, ocr_avail_mmc:sdio SD MMC-specific voltage range
- Pm_notify:struct notifier_block type, power management related notify
- MAX_CURRENT_330/MAX_CURRENT_300/MAX_CURRENT_180: Maximum current supported
- Mmcid:
- The capabilities of the Caps:host
- Other features of the Caps2:host
- pm_caps:mmc_pm_flag_t type, supported PM features
- Clk_requests:
- Clk_delay:
- Whether the CLK_GATED:CLK has been opened
- Clk_gate_work:struct delayed_work Type
- Clk_old:
- clk_lock:spinlock_t type, protection of CLK-related critical resources
- Clk_gate_mutex:struct mutex to protect the exclusive lock of CLK Gate
- Clkgate_delay_attr:struct Device_attribute Type
- Clkgate_delay:
- Max_seg_size: The maximum number of bytes for a segment
- Max_segs: Up to how many segments are supported
- Unused
- Max_req_size: Maximum number of bytes for a request
- Max_blk_size: Maximum size of an MMC block
- Max_blk_count: Maximum block number for a request
- Max_discard_to: Maximum Discard time-out (ms)
- Mutex protection for lock:spinlock_t type mmc
- Ios:struct mmc_ios type, current IO bus settings
- OCR: Current operating voltage setting
- USE_SPI_CRC:
- Claimed:host Exclusive declarations
- Bus_dead: Whether the bus is released
- Whether Removed:host was removed
- Rescan_disable: Whether to disable the card detection, generally initially disabled, ready to enable
- Rescan_entered: For non-removable devices
- Card:struct Mmc_card * Type, used to connect to this host device
- wq:wait_queue_head_t type, Work queue
- Claimer:struct task_struct * Type, the task declared by host
- CLAIM_CNT: "Claim" nesting count
- Detect:struct delayed_work type, the work thread used to detect the card
- Detect_wake_lock:struct Wake_lock
- Detect_change:card Detect Flag
- Slot:struct Mmc_slot type;
- Bus_ops:struct mmc_bus_ops * Type, current bus driver
- Bus_refs:reference counter
- Bus_resume_flags:
- Sdio_irqs:
- Sdio_irq_thread:struct task_struct * Type
- Sdio_irq_pending:
- sdio_irq_thread_abort:atomic_t type
- pm_flags:mmc_pm_flag_t type, requested PM attribute
- Led:struct Led_trigger * Type
- Regulator_enabled:regulator status
- Supply:struct mmc_supply Type
- Debugfs_root:struct dentry * Type, for displaying the corresponding node in Debugfs
- Areq:struct mmc_async_req * Type,/* Active Async req */
- Context_info:struct mmc_context_info type,; /* Async Synchronization Info */
- Fail_mmc_request:struct fault_attr Type
- Actual_clock:actual HC Clock Rate
- Slotno:used for Sdio ACPI binding
- Private: A 0-length array that can be specified at Mmc_alloc_host, and is controlled by host controller driver
|
Operations |
- struct mmc_host *mmc_alloc_host (int extra, struct device *dev)
Assigns a mmc_host struct and initializes it
- int mmc_add_host (struct mmc_host *host)
Register the host device into the drive model and initialize the host hardware, register the notify with PM core, and before this function is complete, you must ensure that the host is able to use
- void Mmc_remove_host (struct mmc_host *host)
Remove the host device from the device-driven model and disconnect all cards from the bus, log off the notify to PM core, and power down the MMC bus |
2.2 struct Mmc_host_ops
Elemete Name |
struct MMC_HOST_OPS |
Path |
Include/linux/mmc/host.h |
Responsiblities |
Contains primarily the actions that host Contrller needs to implement |
Attributions |
- Post_req/pre_req: is to support a double buffer request (one request is being processed while another request is being prepared)
- Request: To process a transfer request
The following function may sleep and cannot be called in the context of the interrupt:
- Set_ios:
- Get_ro: Gets the read and write status of the card, returns 0 for the read-write card, returns 1 for the card, returns-enosys for no support, and returns other negative values to indicate that other errors have occurred
- GET_CD: return 0 means the card is not connected, return 1 means the card has a connection, return-enosys is not supported, return other negative value indicates other error occurred
- ENABLE_SDIO_IRQ:
- Init_card:
- Start_signal_voltage_switch:
- Card_busy:
- Execute_tuning: Adjust tuning command opcode value according to SD and EMMC card.
- Select_drive_strength: Set Drive capability
- Hw_reset: Perform a reset operation on the device
- Card_event:
|
Operations |
|
Todo
About Linux MMC Framework2-host driver