linux内核静态添加sdio设备,Linux下sdio设备扫描过程

本文深入分析了Linux 3.10.52内核中SDIO设备的扫描和初始化过程,包括SDIO硬件接口、内部结构、设备状态、命令与应答以及设备扫描步骤。内容涵盖了SDIO接口的三种模式,设备内部寄存器,如CCCR、FBR、CIS区域,以及CMD52、CMD53等关键命令的使用。在设备扫描部分,文章详述了从mmc_rescan开始,通过mmc_rescan.Try_freq、mmc_go_idle、mmc_select_card等一系列命令,直至完成mmc_add_card和sdio_add_func的过程,从而全面揭示了Linux内核如何识别和初始化SDIO设备。
摘要由CSDN通过智能技术生成

前言

本文基于Linux version 3.10.52版本代码分析sdio设备的扫描过程,同时选择sdio wifi设备作为分析对象,在分析过程中,附带上sdio的协议内容,帮助初学人员学习sdio协议基本内容及sdio的扫描过程。

1 SDIO设备接口及内部结构

本节介绍SDIO设备的硬件接口及内部寄存器等。

1.1 SDIO设备硬件接口

SDIO设备的硬件操作接口有3种方式:

A、 SPI mode;

B、 SD 1-bit mode;

C、 SD 4-bit mode;

这3种方式的硬件接口及管脚定义如下面图、表:

ca1d2c5caf1d36e610eabd7e2e08d6d2.png

图1 SDIO硬件接口(连接了2组sdio设备)

a9b41bacb8ba30e4c0c8d8651a40d261.png

表1 SDIO各种模式管脚对应关系

本文不对SPI mode的相关内容介绍,有关SPI mode的内容不做过多说明。

1.2 SDIO设备内部寄存器

下图为SDIO设备内部操作空间的映射表。

89f30f6ab4f44a6bdddbd5eac6131ae2.png

图2 sdio internal map

CIA: Common I/O Area

CCCR:Card Common Control Registers

FBR :Function Basic Registers

CIS:Card Information Structure

RFU: Reserved for Future Use

图中两个蓝色框表示的是一个东西,只是一个图更详细描述内部各个地址段的用途。CIS区域除了保存CIS信息外,sdio设备商也把设备使用的寄存器定义在这个区域,或作为RAM存储运行固件(fw)等。CSA区域的读写,需要借助FBR中的寄存器0xn0Ch—0xn0Eh、0xn0Fh(n等1~7)。

其中function number的个数随着不同设备而不同,并不一定都需要7个function,如后面介绍的扫描设备就只有function1、function2两个function。

CCCR、FBR、CIS区域的寄存器或数据存储格式如下面各个表,各个寄存器bit的意义在后面介绍扫描过程时再结合实际说明:

a71426ee11ca901e0c5f0388f7d0f15e.png

表2 Card Common Control Registers (CCCR)

225e3210bde1a19a83dc49a3f281e6da.png

表3 Function Basic Information Registers (这里为function1的FBR)

在FBR寄存器中,0Ch—0Eh、0Fh用于读写CSA区域,操作方式如下面描述:

In order for the host to access a function’s CSA, it first shall determine if that function supports a CSA. The host reads the FBR register at address 00n00h where n is the function number (1 to 7). If bit 6=1, then the function supports a CSA and the host enables access by writing bit 7=1. The next step is for the host to load the 24 bit address to start reading or writing. This is accomplished by writing the 24 bits (A23-0) to registers

00n0Ch to 00n0Eh where n is the function number (1 to 7). Once the start address is written, data can be read or written by accessing register 00n0Fh, the CSA data window register. If more than 1 byte needs to be read or written, an extended I/O command (byte or block) can be performed with an OP code of 0 (fixed address). The address pointer shall be automatically incremented with each access to the window register, so the access will be to sequential addresses within the CSA. Once the operation is complete, the address of the NEXT operation shall be held in the 24 bit address register for the host to read.

CIS区域从0x001000h~0x017FFFh,其中CIS信息采用一种结构化的信息存储,每一条信息作为一个tuple结构体,该结构体中第一个字节为tuple code,用于表示该tuple存储的信息类型,第二个字节表示该tuple的长度n,同时也指明下一个tuple的开始位置,跟在长度后面就是n bytes的tuple内容,如下表所示。整个CIS信息最后是以一个0xFF字节作为结束符。

b7eecb81a91630e508c028e68b76902a.png

表4 Basic Tuple Format

SDIO支持的tuple code如下表:

1292d0040224ab7e2429c204c2ddcb1e.png

表5 Tuples Supported by SDIO Cards

394b3fca45332a4fbcc0f59bbf71c394.png

表6 CISTPL_MANFID: Manufacturer Identification Tuple

如上表,sdio设备的id就存储在tuple code(0x20)的tuple中,就是后续扫描中说到的vendor id与device id。

f01370e99e0d3a299402429757296158.png

表7 CISTPL_FUNCID Tuple

在tuple code为0x22的CISTPL_FUNCE中,有3中不同类型的tuple,所在在tuple结构体中增加了一个TYPE字节,但又为

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值