linux 驱动编写(sd卡驱动)

【 声明:版权所有,欢迎转载,请勿用于商业用途。 联系信箱:feixiaoxing @163.com


    随着sd卡的流行,sd卡在嵌入式设备上使用的场景也越来越多。那下面我们可以看一下,linux驱动框架上是怎么处理sd卡驱动的?


1、代码目录地址

drivers/mmc


2、基本结构

从mmc的代码结构可以看得出,主要分为两个部分,其中core为协议部分,host为各个soc的适配部分

host是我们需要真正关心的代码


3、以s3c为例,观察makefile

obj-$(CONFIG_MMC_SDHCI_S3C)	+= sdhci-s3c.o
......
obj-$(CONFIG_MMC_S3C)   	+= s3cmci.o

4、根据s3c阅读Kconfig,确认s3c下的sd卡还依赖哪些文件

config MMC_SDHCI_S3C
	tristate "SDHCI support on Samsung S3C SoC"
	depends on MMC_SDHCI && PLAT_SAMSUNG
	help
	  This selects the Secure Digital Host Controller Interface (SDHCI)
	  often referrered to as the HSMMC block in some of the Samsung S3C
	  range of SoC.

	  If you have a controller with this interface, say Y or M here.

	  If unsure, say N.

config MMC_SDHCI_S3C_DMA
	bool "DMA support on S3C SDHCI"
	depends on MMC_SDHCI_S3C
	help
	  Enable DMA support on the Samsung S3C SDHCI glue. The DMA
	  has proved to be problematic if the controller encounters
	  certain errors, and thus should be treated with care.

	  YMMV.

config MMC_S3C
	tristate "Samsung S3C SD/MMC Card Interface support"
	depends on ARCH_S3C24XX
	depends on S3C24XX_DMAC
	help
	  This selects a driver for the MCI interface found in
          Samsung's S3C2410, S3C2412, S3C2440, S3C2442 CPUs.
	  If you have a board based on one of those and a MMC/SD
	  slot, say Y or M here.

	  If unsure, say N.


5、MMC_S3C和MMC_SDHCI_S3C是主要的macro,接着了解两个macro对应文件的数据结构

首先看一下s3cmci.c文件,

static const struct mmc_host_ops s3cmci_ops = {
	.request	= s3cmci_request,
	.set_ios	= s3cmci_set_ios,
	.get_ro		= mmc_gpio_get_ro,
	.get_cd		= mmc_gpio_get_cd,
	.enable_sdio_irq = s3cmci_enable_sdio_irq,
};

再看一下sdhci-s3c.c文件,

static struct sdhci_ops sdhci_s3c_ops = {
	.get_max_clock		= sdhci_s3c_get_max_clk,
	.set_clock		= sdhci_s3c_set_clock,
	.get_min_clock		= sdhci_s3c_get_min_clock,
	.set_bus_width		= sdhci_set_bus_width,
	.reset			= sdhci_reset,
	.set_uhs_signaling	= sdhci_set_uhs_signaling,
};

6 、从host角度来说,有了platform driver和上面的host driver,驱动流程就算搞清楚了。

但是如果深入下去的话,还是需要好好读一下sd协议,这里面花的时间最多。



SD 卡驱动分析...................................................................................................................................1 块请求处理(linux/driver/mmc/card).....................................................................................2 1.probe.................................................................................................................................................2 2.do_request......................................................................................................................................13 3.小结................................................................................................................................................24 core 层处理(linux/driver/mmc/core)...................................................................................25 1.core 层初始化................................................................................................................................25 2.mmc_claim_host............................................................................................................................28 3.mmc_release_host..........................................................................................................................31 4.mmc_wait_for_req.........................................................................................................................33 5.mmc_wait_for_cmd.......................................................................................................................35 SD 控制器之初始化(linux/driver/mmc/host).....................................................................37 core 层续集之 mmc_add_host..................................................................................................49 SD 控制器之真正的硬件操作.................................................................................................82 1.s3cmci_get_ro................................................................................................................................83 2.s3cmci_set_ios...............................................................................................................................84 3.s3cmci_request 之命令处理..........................................................................................................86 4.s3cmci_request 之数据传输..........................................................................................................97 小结.........................................................................................................................................113
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

嵌入式-老费

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值