详解linux 驱动编写(sd卡驱动)
程序员文章站
2022-06-07 19:20:51
随着sd卡的流行,sd卡在嵌入式设备上使用的场景也越来越多。那下面我们可以看一下,linux驱动框架上是怎么处理sd卡驱动的?
1、代码目录地址
drivers...
随着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协议,这里面花的时间最多。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。