S5PV210(TQ210)学习笔记——Nand驱动之HWECC
时间:11-28
来源:互联网
点击:
- stat=chip->ecc.correct(mtd,p,chip->->ecc.correct(mtd,p,chip->oob_poi+mecc_pos[0]+
- ((chip->ecc.steps-eccsteps)*eccbytes),0);
- if(stat==-1)
- mtd->ecc_stats.failed++;
- col=eccsize*(chip->ecc.steps+1-eccsteps);
- }
- return0;
- }
- staticints5p_nand_write_page(structmtd_info*mtd,structnand_chip*chip,
- constuint8_t*buf,intoob_required)
- {
- inti,eccsize=chip->ecc.size;
- inteccbytes=chip->ecc.bytes;
- inteccsteps=chip->ecc.steps;
- intsecc_start=mtd->oobsize-eccbytes;
- uint8_t*ecc_calc=chip->buffers->ecccalc;
- constuint8_t*p=buf;
- uint32_t*eccpos=chip->ecc.layout->eccpos;
- /*mainarea*/
- for(i=0;eccsteps;eccsteps--,i+=eccbytes,p+=eccsize){
- chip->ecc.hwctl(mtd,NAND_ECC_WRITE);
- chip->write_buf(mtd,p,eccsize);
- chip->ecc.calculate(mtd,p,&ecc_calc[i]);
- }
- for(i=0;i
ecc.total;i++) - chip->oob_poi[eccpos[i]]=ecc_calc[i];
- /*sparearea*/
- chip->ecc.hwctl(mtd,NAND_ECC_WRITE);
- chip->write_buf(mtd,chip->oob_poi,secc_start);
- chip->ecc.calculate(mtd,p,&ecc_calc[chip->ecc.total]);
- for(i=0;i
- chip->oob_poi[secc_start+i]=ecc_calc[chip->ecc.total+i];
- chip->write_buf(mtd,chip->oob_poi+secc_start,eccbytes);
- return0;
- }
- staticints5p_nand_read_oob(structmtd_info*mtd,structnand_chip*chip,
- intpage)
- {
- uint8_t*ecc_calc=chip->buffers->ecccalc;
- inteccbytes=chip->ecc.bytes;
- intsecc_start=mtd->oobsize-eccbytes;
- chip->cmdfunc(mtd,NAND_CMD_READOOB,0,page);
- chip->ecc.hwctl(mtd,NAND_ECC_READ);
- chip->read_buf(mtd,chip->oob_poi,secc_start);
- chip->ecc.calculate(mtd,0,&ecc_calc[chip->ecc.total]);
- chip->read_buf(mtd,chip->oob_poi+secc_start,eccbytes);
- return0;
- }
- staticints5p_nand_write_oob(structmtd_info*mtd,structnand_chip*chip,
- intpage)
- {
- intstatus=0;
- inteccbytes=chip->ecc.bytes;
- intsecc_start=mtd->oobsize-eccbytes;
- uint8_t*ecc_calc=chip->buffers->ecccalc;
- inti;
- chip->cmdfunc(mtd,NAND_CMD_SEQIN,mtd->writesize,page);
- /*sparearea*/
- chip->ecc.hwctl(mtd,NAND_ECC_WRITE);
- chip->write_buf(mtd,chip->oob_poi,secc_start);
- chip->ecc.calculate(mtd,0,&ecc_calc[chip->ecc.total]);
- for(i=0;i
- chip->oob_poi[secc_start+i]=ecc_calc[chip->ecc.total+i];
- chip->write_buf(mtd,chip->oob_poi+secc_start,eccbytes);
- /*SendcommandtoprogramtheOOBdata*/
- chip->cmdfunc(mtd,NAND_CMD_PAGEPROG,-1,-1);
- status=chip->waitfunc(mtd,chip);
- returnstatus&NAND_STATUS_FAIL?-EIO:0;
- }
- 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=(volatilestructs5p_nand_regs*)ioremap(mem->start,resource_size(mem));
- if(s5p_nand_regs==NULL){
- dev_err(&pdev->dev,"ioremapfailed");
- ret=-EIO;
- gotoerr_exit;
- }
- 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&=~(0xfff<4);
- //s5p_nand_regs->nfconf|=(3<12)|(5<8)|(3<4);
- //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->IO_ADDR_R=(unsignedchar*)&s5p_nand_regs->nfdata;
- nand_chip->IO_ADDR_W=(unsignedchar*)&s5p_nand_regs->nfdata;
- nand_chip->cmd_ctrl=s5p_nand_cmd_ctrl;
- nand_chip->dev_ready=s5p_nand_ready;
- nand_chip->ecc.mode=NAND_ECC_HW;
- nand_chip->ecc.hwctl=s5p_ecc_hwctl;
- nand_chip->ecc.calculate=s5p_ecc_calculate;
- nand_chip->ecc.correct=s5p_ecc_correct;
- nand_chip->ecc.read_oob=s5p_nand_read_oob;
- nand_chip->ecc.write_oob=s5p_nand_write_oob;
- nand_chip->ecc.read_page=s5p_nand_read_page;
- nand_chip->nand_chip->ecc.w
S5PV210Nand驱动HWEC 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)
