日志档案

发表于 2007-3-9 23:49:50

1

标签: nand  flash的驱动分析  

对s3c2410平台上nandflash的驱动分析

2007-3-9

s3c2410的nand flash的驱动分析

 

 

以前都是把别人写好的代码直接拿过来用,而没有去关心里面到底怎么实现的,昨晚对照着samsung 2410k9f1208的芯片资料把这些代码读了一遍,终于明白了对nand flash的操作一步步是怎么实现的了。

以下的这些代码可以在vivi或者kernel里面找到

对一个nand flash的操作,总体上可以分为这么四步:

一、Select the NAND device

二、Send command to NAND device

三、Operation

四、De-select the NAND device

下面是以上四步的实现代码:

一、Select the NAND device

#define nand_select()   this->hwcontrol(NAND_CTL_SETNCE); \

                        nand_command(mtd, NAND_CMD_RESET, -1, -1); \

                        udelay (10);

hwcontrol(NAND_CTL_SETNCE)的作用是设置2410NAND FLASH CONFIGURATION (NFCONF) REGISTERNAND Flash Memory chip enable位为0,具体请参考samsung 2410 datasheet

NAND Flash Memory chip enable   [11] NAND flash memory nFCE control

0 : NAND flash nFCE = L (active)

1 : NAND flash nFCE = H (inactive)

(After auto-boot, nFCE will be inactive.)

nand_command(mtd, NAND_CMD_RESET, -1, -1);看字面意思都知道是reset nand device,具体实现请看下面。

二、Send command to NAND device

这步又主要有以下几个过程

1、  Begin command latch cycle

实现代码:

this->hwcontrol(NAND_CTL_SETCLE);  // set command latch enable

this->hwcontrol(NAND_CTL_DAT_OUT);  // 这个我还不清楚

2、  Write out the command to the device

实现代码:

this->write_cmd (command); // write the command to NAND FLASH COMMAND SET (NFCMD) REGISTER

3、  Set ALE and clear CLE to start address cycle

实现代码:

this->hwcontrol(NAND_CTL_CLRCLE); // clear the command latch enable

    this->hwcontrol(NAND_CTL_SETALE); // set the address latch enable

4、  Serially input address

实现代码:

this->write_addr (address);  // write the address to NAND FLASH ADDRESS SET (NFADDR) REGISTER

具体请参考所使用的Nand Flash datasheet以及Nand Flash的寻址方式[http://sniper167.bokee.com/5494041.html]

5、  Latch in address

实现代码:

    this->hwcontrol(NAND_CTL_CLRALE);  // clear the address latch enable

    this->hwcontrol(NAND_CTL_DAT_IN);  // 这个我也不清楚

6、  Pause for us

实现代码:

udelay (?)  // 延时,总得给Nand Flash一点反应时间三

           // 时间视具体Nand Flash而定

三、Operation

主要是往NAND FLASH DATA (NFDATA) REGISTER里面写或者读数据

例如:

static u_char read_data(void)

{

    return (u_char)NFDATA;

}

四、De-select the NAND device

实现代码:

#define nand_deselect() this->hwcontrol(NAND_CTL_CLRNCE);

select the NAND device相反,把NAND FLASH CONFIGURATION (NFCONF) REGISTERNAND Flash Memory chip enable位置1

至此,对samsung 2410平台上的Nand Flash一个操作完成。

以上是偶的个人理解,有啥不正确的地方还请大家指出来,感谢。

下面是一个我还没搞明白的问题,希望看到的朋友能指点下:

这段代码来自mizi_linux\drivers\mtd\nand\smc_s3c2410.c

static void smc_hwcontrol(int cmd)

{

    switch (cmd)

    {

        case NAND_CTL_SETNCE:   NFCONF &= ~NFCONF_nFCE_HIGH; break;

        case NAND_CTL_CLRNCE:   NFCONF |= NFCONF_nFCE_HIGH; break;

        case NAND_CTL_SETCLE:   break;

        case NAND_CTL_CLRCLE:   break;

        case NAND_CTL_SETALE:   break;

        case NAND_CTL_CLRALE:   break;

        case NAND_CTL_DAT_IN:   break;

        case NAND_CTL_DAT_OUT:  break;

    }

}

NAND_CTL_SETCLENAND_CTL_CLRCLENAND_CTL_SETALE以及后面几个cmd,传进去了啥活都不干喃,这能达到set or clear的效果吗?

系统分类: 嵌入式   |   用户分类: 无分类   |   来源: 无分类   |   【推荐给朋友】

    阅读(1868)    回复(3)  

投一票您将和博主都有获奖机会!

  • riple

    2007-3-15 11:25:16

    提醒一句,k9f1208是容量相对较小的nand flash,如果能够把上面代码中和容量相关的参数提取出来,应该可以支持容量更大的nand flash。

  • 啥都不会

    2007-5-10 22:47:29

    老兄,转载请注明啊。。。

    H。。。

  • AIJING

    2007-9-20 14:27:52

    我是台湾davicom大陆代理,有网口芯片DM9000AEP/DM9008AEP可配合。请联系黄生  haj83@163.com   or    aijing.huang@kada.com.cn    13798306786    MSN :aijinghuang0803@hotmail.com