新闻  |   论坛  |   博客  |   在线研讨会
s3c2410的nand flash的驱动分析
tongxin | 2009-03-20 15:04:29    阅读:807   发布文章

以前都是把别人写好的代码直接拿过来用,而没有去关心里面到底怎么实现的,昨晚对照着samsung 2410和k9f1208的芯片资料把这些代码读了一遍,终于明白了对nand flash的操作一步步是怎么实现的了。
%A
%A
%A 以下的这些代码可以在vivi或者kernel里面找到
%A
%A
%A 对一个nand flash的操作,总体上可以分为这么四步:
%A
%A
%A 一、Select the NAND device
%A
%A 二、Send command to NAND device
%A
%A 三、Operation
%A
%A 四、De-select the NAND device
%A
%A
%A 下面是以上四步的实现代码:
%A
%A
%A 一、Select the NAND device
%A
%A
%A #define nand_select()   this->hwcontrol(NAND_CTL_SETNCE); \
%A
%A
%A                         nand_command(mtd, NAND_CMD_RESET, -1, -1); \
%A
%A
%A                         udelay (10);
%A
%A
%A hwcontrol(NAND_CTL_SETNCE)的作用是设置2410的NAND FLASH CONFIGURATION (NFCONF) REGISTER的NAND Flash Memory chip enable位为0,具体请参考samsung 2410 datasheet。
%A
%A
%A NAND Flash Memory chip enable   [11] NAND flash memory nFCE control
%A
%A
%A 0 : NAND flash nFCE = L (active)
%A
%A
%A 1 : NAND flash nFCE = H (inactive)
%A
%A
%A (After auto-boot, nFCE will be inactive.)
%A
%A
%A nand_command(mtd, NAND_CMD_RESET, -1, -1);看字面意思都知道是reset nand device,具体实现请看下面。
%A
%A
%A 二、Send command to NAND device
%A
%A
%A 这步又主要有以下几个过程
%A
%A
%A 1、  Begin command latch cycle
%A
%A
%A 实现代码:
%A
%A
%A this->hwcontrol(NAND_CTL_SETCLE);  // set command latch enable
%A
%A
%A this->hwcontrol(NAND_CTL_DAT_OUT);  // 这个我还不清楚
%A
%A
%A 2、  Write out the command to the device
%A
%A
%A 实现代码:
%A
%A
%A this->write_cmd (command); // write the command to NAND FLASH COMMAND SET (NFCMD) REGISTER
%A
%A
%A 3、  Set ALE and clear CLE to start address cycle
%A
%A
%A 实现代码:
%A
%A
%A this->hwcontrol(NAND_CTL_CLRCLE); // clear the command latch enable
%A
%A
%A     this->hwcontrol(NAND_CTL_SETALE); // set the address latch enable
%A
%A
%A 4、  Serially input address
%A
%A
%A 实现代码:
%A
%A
%A this->write_addr (address);  // write the address to NAND FLASH ADDRESS SET (NFADDR) REGISTER
%A
%A
%A 具体请参考所使用的Nand Flash datasheet以及Nand Flash的寻址方式http://sniper167.bokee.com/5494041.html]
%A
%A
%A 5、  Latch in address
%A
%A
%A 实现代码:
%A
%A
%A     this->hwcontrol(NAND_CTL_CLRALE);  // clear the address latch enable
%A
%A
%A     this->hwcontrol(NAND_CTL_DAT_IN);  // 这个我也不清楚
%A
%A
%A 6、  Pause for ?us
%A
%A
%A 实现代码:
%A
%A
%A udelay (?)  // 延时,总得给Nand Flash一点反应时间三
%A
%A            // 时间视具体Nand Flash而定
%A
%A
%A 三、Operation
%A
%A
%A 主要是往NAND FLASH DATA (NFDATA) REGISTER里面写或者读数据
%A
%A
%A 例如:
%A
%A
%A static u_char read_data(void)
%A
%A {
%A
%A     return (u_char)NFDATA;
%A
%A }
%A
%A
%A
%A
%A 四、De-select the NAND device
%A
%A
%A 实现代码:
%A
%A
%A #define nand_deselect() this->hwcontrol(NAND_CTL_CLRNCE);
%A
%A
%A 跟select the NAND device相反,把NAND FLASH CONFIGURATION (NFCONF) REGISTER的NAND Flash Memory chip enable位置1
%A
%A
%A 至此,对samsung 2410平台上的Nand Flash一个操作完成。
%A
%A
%A 以上是偶的个人理解,有啥不正确的地方还请大家指出来,感谢。
%A
%A
%A 下面是一个我还没搞明白的问题,希望看到的朋友能指点下:
%A
%A
%A 这段代码来自mizi_linux\drivers\mtd\nand\smc_s3c2410.c
%A
%A
%A static void smc_hwcontrol(int cmd)
%A
%A {
%A
%A     switch (cmd)
%A
%A     {
%A
%A         case NAND_CTL_SETNCE:   NFCONF &= ~NFCONF_nFCE_HIGH; break;
%A
%A         case NAND_CTL_CLRNCE:   NFCONF |= NFCONF_nFCE_HIGH; break;
%A
%A         case NAND_CTL_SETCLE:   break;
%A
%A         case NAND_CTL_CLRCLE:   break;
%A
%A         case NAND_CTL_SETALE:   break;
%A
%A         case NAND_CTL_CLRALE:   break;
%A
%A         case NAND_CTL_DAT_IN:   break;
%A
%A         case NAND_CTL_DAT_OUT:  break;
%A
%A     }
%A
%A }
%A
%A
%A NAND_CTL_SETCLE、NAND_CTL_CLRCLE、NAND_CTL_SETALE以及后面几个cmd,传进去了啥活都不干喃,这能达到set or clear的效果吗?
%A
%A%A
%A

*博客内容为网友个人发布,仅代表博主个人观点,如有侵权请联系工作人员删除。

参与讨论
登录后参与讨论
最近文章
寂寞如雪
2009-05-19 19:01:18
夜色花
2009-05-19 18:56:22
没有爱可以重来
2009-05-19 18:54:59
推荐文章
最近访客