S5PV210(TQ210)学习笔记——Nand flash驱动编写
时间:11-28
来源:互联网
点击:
跟裸机程序一样,S5PV210的Nand flash模块跟S3C2440的Nand flash模块非常相似,如果不引入ECC,驱动程序的编写也非常简单,具体的分析及编写过程强烈推荐观看韦东山老师的视频教程,我是使用的Linux-3.8.6(Linux-3.8.3也一样)内核,驱动的API函数有些变化,不过原理是相通的,稍微看一下内核源码并参考下其他平台的相关代码就可以自己写出Nand flash驱动了,下面是Nand flash驱动的源码,没有启用ECC,当然,你也可以改成软件ECC,但是我的觉得既然软件ECC不如HWECC快,我就采用硬件ECC吧,我会在下篇文章中加入HWECC。
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- structs5p_nand_regs{
- unsignedlongnfconf;
- unsignedlongnfcont;
- unsignedlongnfcmmd;
- unsignedlongnfaddr;
- unsignedlongnfdata;
- unsignedlongnfmeccd0;
- unsignedlongnfmeccd1;
- unsignedlongnfseccd;
- unsignedlongnfsblk;
- unsignedlongnfeblk;
- unsignedlongnfstat;
- unsignedlongnfeccerr0;
- unsignedlongnfeccerr1;
- unsignedlongnfmecc0;
- unsignedlongnfmecc1;
- unsignedlongnfsecc;
- unsignedlongnfmlcbitpt;
- };
- structs5p_nand_ecc{
- unsignedlongnfeccconf;
- unsignedlongnfecccont;
- unsignedlongnfeccstat;
- unsignedlongnfeccsecstat;
- unsignedlongnfeccprgecc0;
- unsignedlongnfeccprgecc1;
- unsignedlongnfeccprgecc2;
- unsignedlongnfeccprgecc3;
- unsignedlongnfeccprgecc4;
- unsignedlongnfeccprgecc5;
- unsignedlongnfeccprgecc6;
- unsignedlongnfeccerl0;
- unsignedlongnfeccerl1;
- unsignedlongnfeccerl2;
- unsignedlongnfeccerl3;
- unsignedlongnfeccerl4;
- unsignedlongnfeccerl5;
- unsignedlongnfeccerl6;
- unsignedlongnfeccerl7;
- unsignedlongnfeccerp0;
- unsignedlongnfeccerp1;
- unsignedlongnfeccerp2;
- unsignedlongnfeccerp3;
- unsignedlongnfeccconecc0;
- unsignedlongnfeccconecc1;
- unsignedlongnfeccconecc2;
- unsignedlongnfeccconecc3;
- unsignedlongnfeccconecc4;
- unsignedlongnfeccconecc5;
- unsignedlongnfeccconecc6;
- };
- staticstructnand_chip*nand_chip;
- staticstructmtd_info*s5p_mtd_info;
- staticstructs5p_nand_regs*s5p_nand_regs;
- staticstructs5p_nand_ecc*s5p_nand_ecc;
- staticstructclk*s5p_nand_clk;
- staticstructmtd_partitions5p_nand_partions[]={
- [0]={
- .name="bootloader",
- .offset=0,
- .size=SZ_1M,
- },
- [1]={
- .name="kernel",
- .offset=MTDPART_OFS_APPEND,
- .size=5*SZ_1M,
- },
- [2]={
- .name="rootfs",
- .offset=MTDPART_OFS_APPEND,
- .size=MTDPART_SIZ_FULL,
- },
- };
- staticvoids5p_nand_select_chip(structmtd_info*mtd,intchipnr){
- if(chipnr==-1){
- s5p_nand_regs->nfcont|=(1<1);
- }
- else{
- s5p_nand_regs->nfcont&=~(1<1);
- }
- }
- staticvoids5p_nand_cmd_ctrl(structmtd_info*mtd,intcmd,unsignedintctrl)
- {
- if(ctrl&NAND_CLE){
- s5p_nand_regs->nfcmmd=cmd;
- }
- else{
- s5p_nand_regs->nfaddr=cmd;
- }
- }
- staticints5p_nand_ready(structmtd_info*mtd){
- return(s5p_nand_regs->nfstat&0x1);
- }
- staticints5p_nand_probe(structplatform_device*pdev){
- intret=0;
- structresource*mem;
- //硬件部分初始化
- mem=platform_get_resource(pdev,IORESOURCE_MEM,0);
- if(!mem){
- dev_err(&pdev->dev,"cantgetI/Oresourcemem");
- return-ENXIO;
- }
- s5p_nand_regs=(structs5p_nand_regs*)ioremap(mem->start,resource_size(mem));
- if(s5p_nand_regs==NULL){
- dev_err(&pdev->dev,"ioremapfailed");
- ret=-EIO;
- gotoerr_exit;
- }
- s5p_nand_ecc=(structs5p_nand_ecc*)ioremap(0xB0E20000,sizeof(structs5p_nand_ecc));
- if(s5p_nand_ecc==NULL){
- dev_err(&pdev->dev,"ioremapfailed");
- ret=-EIO;
- gotoerr_iounmap;
- }
- s5p_nand_clk=clk_get(&pdev->dev,"nand");
- if(s5p_nand_clk==NULL){
- dev_dbg(&pdev->dev,"getclkfailed");
- ret=-ENODEV;
- gotoerr_iounmap;
- }
- clk_enable(s5p_nand_clk);
- s5p_nand_regs->nfconf=(3<12)|(5<8)|(3<4)|(1<1);
- s5p_nand_regs->nfcont|=3;
- //分配驱动相关结构体
- nand_chip=(structnand_chip*)kzalloc(sizeof(structnand_chip),GFP_KERNEL);
- if(nand_chip==NULL){
- dev_err(&pdev->dev,"failedtoallocatenand_chipstructure");
- ret=-ENOMEM;
- gotoerr_clk_put;
- }
- s5p_mtd_info=(structmtd_info*)kzalloc(sizeof(structmtd_info),GFP_KERNEL);
- if(s5p_mtd_info==NULL){
- dev_err(&pdev->dev,"failedtoallocatemtd_infostructure");
- ret=-ENOMEM;
- gotoerr_free_chip;
- }
- //设置驱动相关结构体
- nand_chip->select_chip=s5p_nand_select_chip;
- nand_chip->nand_c
S5PV210Nandflash驱动编 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)