SDIO驱动(10)Host的operations实现

本文深入解析SDIO驱动中Host的operations各函数实现,包括get_cd、get_ro、set_ios等,详细阐述了如何检测卡的存在、读写类型以及设置接口参数。同时,介绍了enable_sdio_irq、request等功能,特别是request函数中的命令发送过程,包括清除状态寄存器、设置中断标志和启动命令发送等关键步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Linux 2.6.38
S3C2440

SDIO驱动(9)Host驱动probe实现中简单介绍了host操作card的接口mmc_host_ops一些成员函数的作用,接下来分析下各个函数的实现。

static struct mmc_host_ops s3cmci_ops = {
	.request	= s3cmci_request,
	.set_ios	= s3cmci_set_ios,
	.get_ro		= s3cmci_get_ro,
	.get_cd		= s3cmci_card_present,
	.enable_sdio_irq = s3cmci_enable_sdio_irq,
};

get_cd,检测card是否存在,返回值有4种:card存在返回1,不存在返回0;如果不支持这个操作返回-ENOSYS(Function not implemented),支持但出现错误返回负的错误码。s3cmci_card_present实现:

static int s3cmci_card_present(struct mmc_host *mmc)
{
	struct s3cmci_host *host = mmc_priv(mmc);
	struct s3c24xx_mci_pdata *pdata = host->pdata;
	int ret;

	if (pdata->no_detect)
		return -ENOSYS;

	ret = gpio_get_value(pdata->gpio_detect) ? 0 : 1;
	return ret ^ pdata->detect_invert;
}
3行的小伎俩无需赘言。在硬件连接上,gpio_detect对应的pin用于card detection,如果插入了card那么该pin的电平为0;detect_invert作为一个flag,如果该标志设置的话card detection对应的电平反转,即1电平表示card已经插入。有了以上信息代码的意图就昭然明揭了。


get_ro,获取card的读写类型,返回值有4种:0表明这是一张read/write,1说这是一张read-only卡);后两种返回类型同get_cd函数,s3cmci_get_ro实现:

static int s3cmci_get_ro(struct mmc_host *mmc)
{
	struct s3cmci_host *host = mmc_priv(mmc);
	struct s3c24xx_mci_pdata *pdata = host->pdata;
	int ret;

	if (pdata->no_wprotect)
		return 0;

	ret = gpio_get_value(pdata->gpio_wprotect) ? 1 : 0;
	ret ^= pdata->wprotect_invert;

	return ret;
}
### SDIO Driver Information SDIO (Secure Digital Input Output) drivers are essential components that facilitate communication between the host system and SDIO devices over an SDIO bus. The `sdio_driver` structure represents a driver's encapsulation specifically designed to operate on the `sdio_bus_type`. This design allows for streamlined interaction with SDIO peripherals, ensuring compatibility and efficient data transfer. The `sdio_driver` is part of a larger framework where: - **Bus Type**: The associated bus type for this driver is defined as `sdio_bus_type`, which governs how device enumeration and communication occur[^1]. A typical implementation involves registering the driver within the operating system so it can be matched against connected hardware during boot or hot-plugging events. Once registered, the driver handles initialization, configuration changes, power management, and other operational aspects required by the attached SDIO device. For deeper integration into specific platforms like QNX combined with Android virtualization environments, additional libraries such as `libDSI_MAX9678x_0.so` may provide specialized functionality tailored towards particular use cases involving display panels or similar complex peripherals[^2]. In terms of architecture organization, relevant codebases often reside under directories named after their purpose—such as `core` handling fundamental operations including buses (`mmc_bus`, `sdio_bus`) alongside card interactions; while platform-specific controllers find themselves categorized under `host`; block-level abstractions sit comfortably inside `card`. When troubleshooting issues related to storage media accessed via these interfaces, examining logs provided by the underlying OS becomes crucial since they offer insights not readily apparent through basic tracing mechanisms alone[^4]. ```c // Example C Code Snippet Demonstrating Registration of an SDIO Driver struct sdio_driver my_sdio_driver = { .probe = my_probe_function, .remove = my_remove_function, .name = "my_sdio_device", }; module_sdio_driver(my_sdio_driver); ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值