4 在 Linux 对 Nand Flash 的支持
4.1 Linux 下 Nand Flash 调用关系
4.1.1 Nand Flash 设备添加时数据结构包含关系
struct mtd_partition partition_info[]--> struct s3c2410_nand_set nandset--> struct s3c2410_platform_nand superlpplatfrom--> struct platform_device s3c_device_nand
在该数据结构的 name 字段的初始化值"s3c2410-nand",必须与 Nand Flash 设备驱动注册时
struct device_driver结构中的 name 字段相同,因为 platfrom bus 是依靠名字来匹配的.
--> struct platform_device *smdk2410_devices[]
4.1.2 Nand Flash 设备注册时数据结构包含关系
struct device_driver s3c2410_nand_driver
-->struct device *dev
该数据构由系统分配.
-->struct platform_device *pdev
-->struct s3c2410_platform_nand *plat
-->struct s3c2410_nand_set nset
-->struct mtd_partition
4.1.3 当发生系统调用时数据结构调用关系
struct mtd_info
它的*priv 指向 chip
-->struct nand_chip
它的*priv 指向 nmtd
-->struct s3c2410_nand_mtd
它是 s3c2410_nand_info 的一个字段
-->s3c2410_nand_info
它被设为 Nand Flash 设备驱动的私有数据结构,在 Nand Flash 设备驱动注册时分配空间.
-->struct device
4.2 Linux 下 Nand Flash 驱动主要数据结构说明
4.2.1 s3c2410 专有数据结构
- s3c2410_nand_set
struct s3c2410_nand_set {
int nr_chips; /* 芯片的数目 /int nr_partitions; / 分区的数目 */char name; / 集合名称 /int nr_map; / 可选, 底层逻辑到物理的芯片数目 /struct mtd_partition partitions; / 分区列表 */
}; - s3c2410_platform_and
struct s3c2410_platform_nand {
/* timing information for controller, all times in nanoseconds /
int tacls; / 从 CLE/ALE 有效到 nWE/nOE 的时间 /
int twrph0; / nWE/nOE 的有效时间 /
int twrph1; / 从释放 CLE/ALE 到 nWE/nOE 不活动的时间 /
int nr_sets; / 集合数目 /struct s3c2410_nand_set sets; / 集合列表 // 根据芯片编号选择有效集合 */
void (*select_chip)(struct s3c2410_nand_set , int chip);
}; - s3c2410_nand_mtd
在 drivers/mtd/nand/s3c2410.c 中,
struct s3c2410_nand_mtd {
struct mtd_info mtd; /* MTD 信息 /struct nand_chip chip; / nand flash 芯片信息 /
struct s3c2410_nand_set set; / nand flash 集合 */
struct s3c2410_nand_info info; / nand flash 信息 */
int scan_res;
}; - s3c2410_nand_info
struct s3c2410_nand_info {
/* mtd info /
struct nand_hw_control controller; / 硬件控制器 */
struct s3c2410_nand_mtd mtds; / MTD 设备表 /
struct s3c2410_platform_nand platform; / Nand 设备的平台 /
/ device info */
struct device *device; /*设备指针 */
struct resource *area; /*资源指针 */
struct clk clk; / Nand Flash 时钟 */
void __iomem regs; / 寄存器基地址(map后的逻辑地址) /
int mtd_count; / MTD的数目 */
unsigned char is_s3c2440;
}; - struct clk
在 arch/arm/machs3c2410/clock.h 中
struct clk {
struct list_head list; /* clock 列表结点 */
struct module owner; / 所属模块 */
struct clk parent; / 父结点 */
const char name; / 名称 /
int id; / 编号 /
atomic_t used; / 使用者计数 /
unsigned long rate; / 时钟速率 /
unsigned long ctrlbit; / 控制位 */
int (*enable)(struct clk , int enable); / Clock 打开方法 */};