S5PV210之Nand flash驅(qū)動編寫_第1頁
全文預(yù)覽已結(jié)束

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

1、s5pv210之nand flash驅(qū)動編寫 大家好,又到了天嵌【共享】的時光,相對于前幾期【嵌入式共享】做的主要是tq335x開發(fā)板的技術(shù)共享,本期打算做同是cortex-a8系列的tq210開發(fā)板的技術(shù)共享。本期是關(guān)于tq210開發(fā)板的nand flash驅(qū)動編寫,可能源碼部分會比較多,本文由博主girlkoo編寫,謝謝他的共享。 跟裸機程序一樣,s5pv210(tq210)的nand flash模塊跟s3c2440(tq2440)的nand flash模塊十分相像,假如不引入ecc,驅(qū)動程序的編寫也十分容易,我是用法的-3.8.6(linux-3.8.3也一樣)內(nèi)核,驅(qū)動的api函數(shù)有些

2、變幻,不過原理是相通的,略微看一下內(nèi)核源碼并參考下其他平臺的相關(guān)代碼就可以自己寫出nand flash驅(qū)動了,下面是nand flash驅(qū)動的源碼,沒有啟用ecc,固然,你也可以改成軟件ecc,但是我的覺得既然軟件ecc不如hwecc快,我就采納硬件ecc吧。include include include include include include include include struct s5p_nand_regs unsigned long nfconf; unsigned long nfcont; unsigned long nfcmmd; unsigned long nfadd

3、r; unsigned long nfdata; unsigned long nfmeccd0; unsigned long nfmeccd1; unsigned long nfseccd; unsigned long nfsblk; unsigned long nfeblk; unsigned long nfstat; unsigned long nfeccerr0; unsigned long nfeccerr1; unsigned long nfmecc0; unsigned long nfmecc1; unsigned long nfsecc; unsigned long nfmlcb

4、itpt; ; struct s5p_nand_ecc unsigned long nfeccconf; unsigned long nfecccont; unsigned long nfeccstat; unsigned long nfeccsecstat; unsigned long nfeccprgecc0; unsigned long nfeccprgecc1; unsigned long nfeccprgecc2; unsigned long nfeccprgecc3; unsigned long nfeccprgecc4; unsigned long nfeccprgecc5; u

5、nsigned long nfeccprgecc6; unsigned long nfeccerl0; unsigned long nfeccerl1; unsigned long nfeccerl2; unsigned long nfeccerl3; unsigned long nfeccerl4; unsigned long nfeccerl5; unsigned long nfeccerl6; unsigned long nfeccerl7; unsigned long nfeccerp0; unsigned long nfeccerp1; unsigned long nfeccerp2

6、; unsigned long nfeccerp3; unsigned long nfeccconecc0; unsigned long nfeccconecc1; unsigned long nfeccconecc2; unsigned long nfeccconecc3; unsigned long nfeccconecc4; unsigned long nfeccconecc5; unsigned long nfeccconecc6; ; static struct nand_chip *nand_chip; static struct mtd_info *s5p_mtd_info; s

7、tatic struct s5p_nand_regs *s5p_nand_regs; static struct s5p_nand_ecc *s5p_nand_ecc; static struct clk *s5p_nand_clk; static struct mtd_partition s5p_nand_partions = 0 = .name = "bootloader", .offset = 0, .size = sz_1m, , 1 = .name = "kernel", .offset = mtdpart_ofs_append, .size

8、= 5*sz_1m, , 2 = .name = "rootfs", .offset = mtdpart_ofs_append, .size = mtdpart_siz_full, , ; static void s5p_nand_select_chip(struct mtd_info *mtd, int chipnr) if(chipnr = -1) s5p_nand_regs->nfcont |= (1 else s5p_nand_regs->nfcont &= (1 static void s5p_nand_cmd_ctrl(struct mtd_

9、info *mtd, int cmd, unsigned int ctrl) if (ctrl & nand_cle) s5p_nand_regs->nfcmmd = cmd; else s5p_nand_regs->nfaddr = cmd; static int s5p_nand_ready(struct mtd_info *mtd) return (s5p_nand_regs->nfstat static int s5p_nand_probe(struct platform_device *pdev) int ret = 0; struct resource *

10、mem; /硬件部分初始化 mem = platform_get_resource(pdev, ioresource_mem, 0); if (!mem) dev_err(&pdev->dev, "can't get i/o resource memn"); return -enxio; s5p_nand_regs = (struct s5p_nand_regs *)ioremap(mem->start, resource_size(mem); if (s5p_nand_regs = null) dev_err(&pdev->dev

11、, "ioremap failedn"); ret = -eio; goto err_exit; s5p_nand_ecc = (struct s5p_nand_ecc *)ioremap(0xb0e20000, sizeof(struct s5p_nand_ecc); if(s5p_nand_ecc = null) dev_err(&pdev->dev, "ioremap failedn"); ret = -eio; goto err_iounmap; s5p_nand_clk = clk_get(&pdev->dev, &

12、quot;nand"); if(s5p_nand_clk = null) dev_dbg(&pdev->dev, "get clk failedn"); ret = -enodev; goto err_iounmap; clk_enable(s5p_nand_clk); s5p_nand_regs->nfconf = (3 s5p_nand_regs->nfcont |= 3; /分配驅(qū)動相關(guān)結(jié)構(gòu)體 nand_chip = (struct nand_chip *)kzalloc(sizeof(struct nand_chip), gfp_

13、kernel); if(nand_chip = null) dev_err(&pdev->dev, "failed to allocate nand_chip structuren"); ret = -enomem; goto err_clk_put; s5p_mtd_info = (struct mtd_info *)kzalloc(sizeof(struct mtd_info), gfp_kernel); if(s5p_mtd_info = null) dev_err(&pdev->dev, "failed to allocate

14、mtd_info structuren"); ret = -enomem; goto err_free_chip; /設(shè)置驅(qū)動相關(guān)結(jié)構(gòu)體 nand_chip->select_chip = s5p_nand_select_chip; nand_chip->cmd_ctrl = s5p_nand_cmd_ctrl; nand_chip->io_addr_r = &s5p_nand_regs->nfdata; nand_chip->io_addr_w = &s5p_nand_regs->nfdata; nand_chip->dev_

15、ready = s5p_nand_ready; nand_chip->ecc.mode = nand_ecc_soft; s5p_mtd_info->priv = nand_chip; s5p_mtd_info->owner = this_module; /掃描nand flash 設(shè)備 if(nand_scan(s5p_mtd_info, 1) dev_dbg(&pdev->dev, "nand scan errorn"); goto err_free_info; /添加分區(qū)信息 ret = mtd_device_parse_registe

16、r(s5p_mtd_info, null, null, s5p_nand_partions, array_size(s5p_nand_partions); if(!ret) return 0; err_free_info: kfree(s5p_mtd_info); err_free_chip: kfree(nand_chip); err_clk_put: clk_disable(s5p_nand_clk); clk_put(s5p_nand_clk); err_iounmap: /if(s5p_nand_ecc = null) / iounmap(s5p_nand_ecc); if(s5p_n

17、and_regs = null) iounmap(s5p_nand_regs); err_exit: return ret; static int s5p_nand_remove(struct platform_device *pdev) nand_release(s5p_mtd_info); kfree(s5p_mtd_info); kfree(nand_chip); clk_disable(s5p_nand_clk); clk_put(s5p_nand_clk); if(s5p_nand_regs = null) iounmap(s5p_nand_regs); return 0; static struct platform_driver s5p_na

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論