s3c2410的nand flash的驅動分析

以前都是把別人寫好的代碼直接拿過來用,而沒有去關心裏面到底怎麼實現的,昨晚對照着samsung 2410和k9f1208的芯片資料把這些代碼讀了一遍,終於明白了對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)的作用是設置2410的NAND FLASH CONFIGURATION (NFCONF) REGISTER的NAND 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) REGISTER的NAND 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_CLRCLE、NAND_CTL_SETALE以及後面幾個cmd,傳進去了啥活都不幹喃,這能達到set or clear的效果嗎 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章