S5PV210之Nand flash驱动编写_第1页
免费预览已结束,剩余3页可下载查看

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、s5pv210之nand flash驱动编写 大家好,又到了天嵌【共享】的时光,相对于前几期【嵌入式共享】做的主要是tq335x开发板的技术共享,本期打算做同是cortex-a8系列的tq210开发板的技术共享。本期是关于tq210开发板的nand flash驱动编写,可能源码部分会比较多,本文由博主girlkoo编写,谢谢他的共享。 跟裸机程序一样,s5pv210(tq210)的nand flash模块跟s3c2440(tq2440)的nand flash模块十分相像,假如不引入ecc,驱动程序的编写也十分容易,我是用法的-3.8.6(linux-3.8.3也一样)内核,驱动的api函数有些

2、变幻,不过原理是相通的,略微看一下内核源码并参考下其他平台的相关代码就可以自己写出nand flash驱动了,下面是nand flash驱动的源码,没有启用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; /分配驱动相关结构体 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; /设置驱动相关结构体 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 设备 if(nand_scan(s5p_mtd_info, 1) dev_dbg(&pdev->dev, "nand scan errorn"); goto err_free_info; /添加分区信息 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. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论