It describes the MMC storage device driver functionality in Linux Kernel and it's role. It explains different type of storage devices available and how they are handled from MMC driver point of view. It describes eMMC (internal storage) device and SD (external storage) devices in details and SD protocol used for communicating with these devices in Linux.
2. Outline
0 Storage Devices on mobile platform
(smart phones, tablets etc.)
0 RAM
0 Internal Storage Devices
0 External Storage Devices
0 What is Flash Memory ?
0 Kernel storage driver overview
(http://lxr.free-
electrons.com/source/drivers/mmc/ )
0 mmc device driver overview
0 Top view diagram
0 block diagram and Internal diagram
0 SD and SPI protocol
0 Mmc driver different Layers
0 Important functions to look
for
0 Tuning procedure
0 SD Hot-plug
0 Sdhci controller role in Data
transfer
0 SDMMC device registration
0 Sdhci probe()
0 How to configure/enable
SDHCI support
Note: To understand the few terms in this presentation, please refer
to Introduction to Kernel & Device Drivers PPT
(http://www.slideshare.net/rampalliraj/kernel-device-drivers): It
covers what is Kernel, what is a Module and what is device driver .
3. Storage Devices on Mobile Platforms
0 Mobile Platforms will have mainly Three storage devices for applications/users to
store the Data
0 RAM (Random Access Memory): also known as main memory and primary memory.
0 Internal Storage device (Non-removable device)
0 External Storage device (Removable device)
0 RAM is Volatile memory i.e. data present in this device will be lost when power is
removed/off.
0 Internal Storage Device: Mobile devices will have a built-in non-volatile memory
called internal storage.
0 External Storage Device: Android devices may support removable non-volatile
memory called external storage devices.
0 Example: Look at Memory & Storage specification of smartphone mobile.
RAM: 2GB
Internal Storage:
16GB
External storage:
upto 128GB
Snapshot taken from Flipkart Samsung j5-6 mobile spec.
4. What is Flash Memory ?
0 Flash Memory is a non-volatile, solid state storage device i.e. keeps
its data without power.
0 Flash Memory is being used in wide range of devices. Examples are
0 Internal storage devices (eMMC or UFS)
0 USB sticks and SD Memory Cards
0 Digital audio players
0 Flash memory offers very high speed access to data.
0 Advantage: Flash memory, when packaged in a "memory card", is
very resilient to damage, unlike many other storage devices. It can
withstand extremes of temperature, being immersed in water or
being accidentally dropped [2].
0 Disadvantage: It has a limited number of read/write cycles which
limits its useful life span.
5. Internal Storage Device
0 Internal Storage mostly holds the android operating
system so that the android device is able to access
input and output devices.
0 System memory (see image)
0 It is also called as Device Memory (internal memory).
0 Go to settings page and select Storage option and you will
see the internal storage capacity of your device.
0 It also stores the applications or data that user saves in
it.
0 The data stored in internal storage can be accesses
much faster than the data present in external storage
device.
0 Internal storage device is directly connected to the
mother board where as the external device connected
through a hardware interface.
0 Disadvantage: If device fails to boot then all the data
present in the internal storage device may be lost.
6. Internal Storage Devices
0 Following are the storage devices which are mainly used for
main storage devices on mobile platforms
0 eMMC: embedded Multi-Media Controller, refers to a package
consisting of both flash memory and a flash memory controller
integrated on the same silicon die.
0 UFS: Universal Flash Storage (UFS) is a flash storage like eMMC
device with higher data rates compared to it.
0 SATA: Serial ATA is a computer bus interface that connects host
bus adapters to mass storage devices such as hard disk drives,
optical drives, and solid-state drives.
0 Will cover Linux Kernel eMMC (MMC storage)device drivers
in this presentation.
7. External Storage Device
0 Android devices may support
the capability of adding more
external storage via removable
cards like SD memory cards.
0 SD card: Secure Digital (SD) is
a non-volatile memory card
format developed by the SD
Card Association (SDA) for use
in portable devices.
0 Advantage: External storage
devices are portal i.e. data can
be easily moved from one
location to other location.
0 These storage devices are
used for data backup
0 Disadvantage: Data transfer
rate is slow compared to
internal storage devices.
SD card details found in
settings->storage android
8. How to identify SD card’s class?
Preferable card: class 10 or UHS-I cards
Class
Minimum
Serial Data
Writing
Speed
Symbol on
SD card
Class 2 2MB/s
Class 4 4MB/s
Class 6 6MB/s
Class 10 10MB/s
UHS Speed
Class 1 (U1)
10MB/s
9. SD Memory card architecture
Card Info
registers
Usage
CID Card identification number
RCA Relative card address published by
the card during card identification
process.
DSR Driver stage register
CSD Max data transfer rate and defines
data format, error correction type,
maximum data access/transfer time,
Maximum read/write block length.
SCR SD configuration register
OCR Operation condition reg
SSR SD status register
CSR Card status register
10. SD and SPI protocol
SPI Protocol SD Protocol
Design simple Complex
Loss of performance: 1bit mode Wide bus option. Supports 1bit and 4bit
modes.
Card identification and addressing
methods replaced by the h/w chip select
CS signal
Its own Card Identification process
No broadcast commands Available
Uses only 7 pins
DAT1 and DAT2 are not used
DAT3 used as CS
DAT0 data transfer
CLK line
DataIn line (Host to card line)
9 pins model:
DAT0-DAT3 lines for data transfer
CLK line – clock line
CMD line – command line
3 Power lines – supply voltage lines
11. Storage Device Driver for
eMMC and SD devices
0 Storage Device Driver ($kernel/drivers/mmc) is common
for eMMC devices (internal storage device) and for SD
memory cards (external storage device).
0 eMMC and SD are block devices i.e. mmc device driver
communicates with these devices in the form of blocks of
data (512 bytes)
0 Character device is one with which the driver communicates
by sending/receiving single characters (bytes), eg:
0 mmc drivers receives the block requests from generic block
layer (upper layer)
12. mmc Device Driver Top View
Kernel
Space
User Space
Virtual File System Layer
Generic Block Layer
mmc device driver
Hardware
devices
eMMC device SD memory card
User applications
14. mmc device driver overview
0 mmc queue receives block read/write/erase
requests from the generic core block layer
0 mmc queue driver picks up one request from its
queue and assign it to mmc block driver
0 mmc block driver analyze the type of request and
forwards the request to mmc core driver.
0 mmc core driver has the protocol implementation
for eMMC/SD devices detection, enumeration and
data transfers to communicated with the actual
Hardware device.
0 mmc core driver receives the request from block
driver, prepares a mmc_request and forwards it to
the mmc host driver.
0 mmc host driver initiates the transfer to device by
programming Hardware controller registers.
0 Once the request get processed by the hardware
controller, an interrupt gets generated .
0 mmc host driver receives request complete
interrupt, analyzes it and pass the response to block
driver. This process continues for all block requests.
mmc Queue driver
(queue.c)
mmc core driver
(core.c, mmc.c, sd.c)
mmc host (controller)
driver
SDHCI Host driver
sdhci.c
mmc Block driver
(block.c)
15. mmc queue layer
(/drivers/mmc/card/queue.c)
0 Important functions:
0 mmc_init_queue()
0 initializes the device queue
0 Creates and run the kernel thread (mmc_queue_thread)
“mmcqd” to fetch block I/O requests from core block
layer and pass it mmc block layer.
0 mmc_queue_thread()
0 Fetch block I/O requests using blk_fetch_request()
0 Pass the request to mmc block layer using callback
issue_fn() -> redirects to -> mmc_blk_issue_rq() in
mmc block driver
16. mmc block layer (/drivers/mmc/card/block.c)
0 Important functions: 1) mmc_blk_probe()
0 Calls the mmc_queue_initialize() to initialize mmc queue.
0 Allocates the block devices (eMMC and SD card) and its partitions.
0 Initializes the mmc_blk_data (md) structure with required function callbacks for
I/O requests, assigns MAJOR/MINOR info.
md->queue.issue_fn = mmc_blk_issue_rq; md->disk->major =
MMC_BLOCK_MAJOR; md->disk->first_minor = devidx * perdev_minors;
0 2) mmc_blk_issue_rq() – receives block I/O request from mmc queue thread
from mmc queue driver. If I/O request type is ERASE then it calls
mmc_blk_issue_discard_rq(). If I/O request is READ/WRITE then calls
mmc_blk_issue_rw_rq()
0 2A) mmc_blk_issue_rw_rq() – prepares mmc block request and responsible
for followings: Sets data block size to 512 (FIXED)
0 Retrieve block count information using blk_rq_sectors()
0 Assigns appropriate command flags and data flags
0 Sets the timeout for a Data command using mmc_set_data_timeout() function
(defined in mmc core driver)
0 Assign the mmc block request to mmc core driver by calling mmc_start_req()
function.
17. mmc core layer
(/drivers/mmc/core/*)
0 It Implements all SD/eMMC-dependent functionality, entire
communication protocol is implemented in this layer.
0 Receives request in mmc_start_req() from mmc block layer
0 Before starting this new request, it checks for any ongoing
request. Holds this new request until the ongoing request is
processed.
0 It calls mmc host layer function sdhci_request() to program the
command and its dependant parameters in the mmc controller
register for initiating the command transfer.
(/drivers/mmc/host/sdhci.c)
18. mmc host layer (drivers/mmc/host/*)
0 It implements the driver for most known platform controllers and
is platform dependent.
0 Important functions:
0 sdhci_add_host() : adds the sdhci host controller with the driver model.
It initializes the sdhci h/w controller and enables sdhci interrupts.
0 sdhci_request(): It initiates the data transfer of received request by
programming the command details in the corresponding h/w register.
0 Sets the SW timer to ensure that there is no infinite wait for the transfer
complete interrupt
0 Prepares the data and sets SDMA or ADMA mode
0 sdhci_irq(): It receives the transfer complete interrupt and analyzes it
for any errors. It sends the response of the transfer to block layer.
0 sdhci_execute_tuning(): Tuning procedure: It is required for reliable data
transfers when interface freq is more than 50MHz. It determines the TAP value by
issuing CMD19.
0 Controller issues CMD19 (SD/SDIO) or CMD21(eMMC) to get card’s tuning block at the
current tap value X. Compares with its tuning block
0 If matches - Tuning is passed for the tap value X
0 Else - Tuning is not passed for the tap value X, try next tap X+1
19. SD Host controller role @Data Transfer
0 Data location of system memory DMA_SYSTEM_ADDR (If DMA supported)
0 Set Block size BLOCK_SIZE
0 Set Block count BLOCK_COUNT
0 Set argument value ARGUMENT
0 Set TRANSFER_MODE value, determines
0 Single/Multi-Block transfer
0 Block count enabled ?
0 Data transfer direction
0 ACMD12(eMMC/SD) or CMD52(SDIO) enabled ?
0 DMA enabled ?
0 Set COMMAND execution started
0 Wait for CMD complete Interrupt
0 Write 1 to the CMD_COMPLETE in Normal status Interrupt Register
0 Based on Read/Write CMD, the associated Registers/Interrupts enabled
0 Wait for Buffer Read Ready or Buffer Write Ready Interrupt
0 Clear Buffer Read Ready Status or Buffer Write Ready Status
0 Wait for TRANSFER_COMPLETE Interrupt
0 Clear TRANSFER_COMPLETE Status
20. Mmc driver features
0 Host-Device interface is reliable when FREQ limits upto 50MHz
0 SD: High speed (HS) SD cards, class 4 cards
0 eMMC: eMMC devices with versions 4.41 or below
0 Tuning procedure is required when host-device interface runs at more
than 50MHz.
0 SD: Ultra High Speed (UHS) SD cards, and class 10 SD cards.
0 eMMC: eMMC devices with versions 4.5 or more supports tuning
0 Mmc driver supports SD hot-plug feature, so that SD card can be inserted
into already running device without powering of the device.
0 MMC driver supports voltage switching feature, if SD cards of type 10 or
UHS-I inserted then voltage switching is invoked to switch voltage from
3.3 V to 1.8V for power optimization.
0 UHS SD cards runs at 1.8V
0 Clock gating is enabled: If there are no transactions on eMMC/SD interface
then clock supply will be off, to save the power of the device.
21. SDMMC devices registration
0 Device registration requires both device name and driver name should
match
0 Device registration is done in board-<board-name>-sdhci.c
0 platform_device_register(&tegra_sdhci_device3); /* eMMC */
platform_device_register(&tegra_sdhci_device2); /* SD/SDIO */
platform_device_register(&tegra_sdhci_device0); /* SDIO/SD */
0 Platform_device Structure:
static struct platform_device tegra_sdhci_deviceX = {
.name = "sdhci-tegra",
.id = X, /* X = 0 or 1 or 2 or 3 */
.resource = sdhci_resourceX,
.num_resources = ARRAY_SIZE(sdhci_resourceX),
.dev = { .platform_data = &tegra_sdhci_platform_data3, },
};
0 As part of device enumeration, we use discovery method to identify
whether the device is eMMC or SD or SDIO.
22. SDHCI probe()
Probe() is called when device is recognized by the platform
Driver’s init function gives kernel a list of devices it is able to
service, along with a pointer to a probe function. Kernel then calls
the driver’s probe function one for each device.
0 probe function starts the per-device initialization:
0 initializing hardware, allocating resources, and
0 registering the device with the kernel as a block device.
0 Kernel/drivers/mmc/host/sdhic-tegra.c sdhci_tegra_probe()
0 Host controller initialization at
kernel/drivers/mmc/host/sdhci.c sdhci_add_host()
0 Device initialization starts in
kernel/drivers/mmc/core/core.c mmc_rescan()
0 Starts execution when Host detects the device.
0 mmc_attach_sdio() sdio.c [core driver]
0 mmc_attach_sd() sd.c [core driver]
0 mmc_attach_mmc() mmc.c [core driver]
23. How to enable SDHCI controller:
MMC/SD Card support Configuration
0 Configure below variables for mmc devices (eMMC
and SD devices share same sdhci controller)
0 MMC
0 MMC_SDHCI
0 MMC_SDHCI_PLTFM
0 Optional
0 MMC_DEBUG
0 MMC_BLOCK
0 drivers/mmc/Kconfig
24. Conclusion
0 eMMC device is used for internal storage on mobile platforms
0 SD device (external SD cards) is used for external storage on
mobile platforms
0 eMMC device and SD device both uses same driver on Linux
platform. Pointer to this driver is
http://lxr.free-electrons.com/source/drivers/mmc/
0 eMMC and SD devices registers with block layer as a block devices.
0 Mmc driver sub-divided into three layers block (or queue)
subsystem, core layer and host layer.
0 eMMC and SD uses SD protocol for communication.
0 Sdhci host controller communicates with eMMC and SD devices.
0 Class 10 or UHS-I type SD cards are preferable for high data rates.
25. References
1. Wikipedia:
https://en.wikipedia.org/wiki/Secure_Digital
2. TEACH-ICT – The very best KS3, GCSE and A Level
Computer Science resources.
3. SAMSUNG Galaxy J5 - 6 (New 2016 Edition)(Black,
16 GB) Specification snapshot from flipkart.com
4. SD Specifications Part A2 SD Host Controller
Standard Specification Version 3.0
5. JEDEC STANDARD EMBEDDED MULTI-MEDIA CARD
(e•MMC), ELECTRICAL STANDARD (4.5 device)
26. THANK YOU
Have a look at
My PPTs:
http://www.slideshare.net/rampalliraj/
My Blog: http://practicepeople.blogspot.in/
Editor's Notes
Platform devices represent devices that are usually integrated into a given chip and therefore are always there. The platform-specific initialization code statically initializes such arrays of platform devices and then registers them in a row using platform_register. Therefore there is no need for sophisticated probing. Instead, the string contained in platform_device.name is compared platform_driver.driver.name and a match is assumed if they are equal.
MMC support
selects the generic Secure Digital Host Controller Interface. If you have a controller with this interface, say Y or M here.
Selects the common helper functions support for SD host controller based platform and OF drivers
Selects the Tegra SD/MMC controller. If you have a Tegra platform with SD or MMC devices, say Y or M here.