手机版
你好,游客 登录 注册
背景:
阅读新闻

MTD 设备驱动 和 NAND Flash 驱动程序分析

[日期:2012-05-01] 来源:Linux社区  作者:acanoe [字体:大 中 小]

第二、NAND Flash 驱动程序分析:

Linux 内核在 MTD的下层实现了通用NAND 驱动(主要通过 drivers/mtd/nand/nand_base.c 文件实现),因此芯片级的驱动不再需要实现 mtd_info 中的: read(), write() ,

read_oob(), write_oob 等成员函数,而主体 转移到了 nand_chip 数据结构。

关键词解析:

ALE:地址锁存使能(Address Latch Enable, ALE):当ALE为高时,在WE#信号的上升沿,地址被锁存到NAND地址寄存器中。

CLE:指令锁存使能(Command Latch Enable, CLE): 当CLE为高时,在WE#信号的上升沿,指令被锁存到NAND指令寄存器中。

BSP:Board Support Package

1、nand_chip 结构体分析       该结构体定义在 ./include/linux/mtd/nand.h

  1. struct nand_chip {  
  2.     void  __iomem   *IO_ADDR_R;               // 读 8 位 I/O 线地址,由主板决定   
  3.     void  __iomem   *IO_ADDR_W;               // 写 8 为 I/O 线地址,由主板决定    
  4.   
  5.     uint8_t     (*read_byte)(struct mtd_info *mtd);  
  6.     u16     (*read_word)(struct mtd_info *mtd);  
  7.     void        (*write_buf)(struct mtd_info *mtd, const uint8_t *buf, int len);  
  8.     void        (*read_buf)(struct mtd_info *mtd, uint8_t *buf, int len);  
  9.     int     (*verify_buf)(struct mtd_info *mtd, const uint8_t *buf, int len);  
  10.     void        (*select_chip)(struct mtd_info *mtd, int chip);                    // 片选芯片   
  11.     int     (*block_bad)(struct mtd_info *mtd, loff_t ofs, int getchip);       // 是否为坏块   
  12.     int     (*block_markbad)(struct mtd_info *mtd, loff_t ofs);                // 标记坏块   
  13.     void        (*cmd_ctrl)(struct mtd_info *mtd, int dat,  
  14.                     unsigned int ctrl);                                    // 控制 AEL/CLE/nCE, 也用于写命令 和 地址   
  15.     int     (*dev_ready)(struct mtd_info *mtd);                                // 设备就绪   
  16.     void        (*cmdfunc)(struct mtd_info *mtd, unsigned command, int column, int page_addr);  
  17.     int     (*waitfunc)(struct mtd_info *mtd, struct nand_chip *this);  
  18.     void        (*erase_cmd)(struct mtd_info *mtd, int page);  
  19.     int     (*scan_bbt)(struct mtd_info *mtd);  
  20.     int     (*errstat)(struct mtd_info *mtd, struct nand_chip *this, int state, int status, int page);  
  21.     int     (*write_page)(struct mtd_info *mtd, struct nand_chip *chip,  
  22.                       const uint8_t *buf, int page, int cached, int raw);  
  23.   
  24.     int     chip_delay;  
  25.     unsigned int    options;  
  26.   
  27.     int     page_shift;  
  28.     int     phys_erase_shift;  
  29.     int     bbt_erase_shift;  
  30.     int     chip_shift;  
  31.     int     numchips;  
  32.     uint64_t    chipsize;  
  33.     int     pagemask;  
  34.     int     pagebuf;  
  35.     int     subpagesize;  
  36.     uint8_t     cellinfo;  
  37.     int     badblockpos;  
  38.     int     badblockbits;  
  39.   
  40.     flstate_t   state;  
  41.   
  42.     uint8_t     *oob_poi;  
  43.     struct nand_hw_control  *controller;  
  44.     struct nand_ecclayout   *ecclayout;  
  45.   
  46.     struct nand_ecc_ctrl ecc;  
  47.     struct nand_buffers *buffers;  
  48.     struct nand_hw_control hwcontrol;  
  49.   
  50.     struct mtd_oob_ops ops;  
  51.   
  52.     uint8_t     *bbt;  
  53.     struct nand_bbt_descr   *bbt_td;  
  54.     struct nand_bbt_descr   *bbt_md;  
  55.   
  56.     struct nand_bbt_descr   *badblock_pattern;  
  57.   
  58.     void        *priv;  
  59. };  

MTD 使用 nand_chip 数据结构表示一个NAND Flash 芯片,这个结构体中包含了关于 NAND Flash 的地址信息、读写方法、ECC模式、硬件控制等一系列底层机制。

linux
相关资讯       Linux驱动开发 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款