微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > S5PV210(TQ210)学习笔记——Nand驱动之HWECC

S5PV210(TQ210)学习笔记——Nand驱动之HWECC

时间:11-28 来源:互联网 点击:

  1. stat=chip->ecc.correct(mtd,p,chip->->ecc.correct(mtd,p,chip->oob_poi+mecc_pos[0]+
  2. ((chip->ecc.steps-eccsteps)*eccbytes),0);
  3. if(stat==-1)
  4. mtd->ecc_stats.failed++;
  5. col=eccsize*(chip->ecc.steps+1-eccsteps);
  6. }
  7. return0;
  8. }
  9. staticints5p_nand_write_page(structmtd_info*mtd,structnand_chip*chip,
  10. constuint8_t*buf,intoob_required)
  11. {
  12. inti,eccsize=chip->ecc.size;
  13. inteccbytes=chip->ecc.bytes;
  14. inteccsteps=chip->ecc.steps;
  15. intsecc_start=mtd->oobsize-eccbytes;
  16. uint8_t*ecc_calc=chip->buffers->ecccalc;
  17. constuint8_t*p=buf;
  18. uint32_t*eccpos=chip->ecc.layout->eccpos;
  19. /*mainarea*/
  20. for(i=0;eccsteps;eccsteps--,i+=eccbytes,p+=eccsize){
  21. chip->ecc.hwctl(mtd,NAND_ECC_WRITE);
  22. chip->write_buf(mtd,p,eccsize);
  23. chip->ecc.calculate(mtd,p,&ecc_calc[i]);
  24. }
  25. for(i=0;iecc.total;i++)
  26. chip->oob_poi[eccpos[i]]=ecc_calc[i];
  27. /*sparearea*/
  28. chip->ecc.hwctl(mtd,NAND_ECC_WRITE);
  29. chip->write_buf(mtd,chip->oob_poi,secc_start);
  30. chip->ecc.calculate(mtd,p,&ecc_calc[chip->ecc.total]);
  31. for(i=0;i
  32. chip->oob_poi[secc_start+i]=ecc_calc[chip->ecc.total+i];
  33. chip->write_buf(mtd,chip->oob_poi+secc_start,eccbytes);
  34. return0;
  35. }
  36. staticints5p_nand_read_oob(structmtd_info*mtd,structnand_chip*chip,
  37. intpage)
  38. {
  39. uint8_t*ecc_calc=chip->buffers->ecccalc;
  40. inteccbytes=chip->ecc.bytes;
  41. intsecc_start=mtd->oobsize-eccbytes;
  42. chip->cmdfunc(mtd,NAND_CMD_READOOB,0,page);
  43. chip->ecc.hwctl(mtd,NAND_ECC_READ);
  44. chip->read_buf(mtd,chip->oob_poi,secc_start);
  45. chip->ecc.calculate(mtd,0,&ecc_calc[chip->ecc.total]);
  46. chip->read_buf(mtd,chip->oob_poi+secc_start,eccbytes);
  47. return0;
  48. }
  49. staticints5p_nand_write_oob(structmtd_info*mtd,structnand_chip*chip,
  50. intpage)
  51. {
  52. intstatus=0;
  53. inteccbytes=chip->ecc.bytes;
  54. intsecc_start=mtd->oobsize-eccbytes;
  55. uint8_t*ecc_calc=chip->buffers->ecccalc;
  56. inti;
  57. chip->cmdfunc(mtd,NAND_CMD_SEQIN,mtd->writesize,page);
  58. /*sparearea*/
  59. chip->ecc.hwctl(mtd,NAND_ECC_WRITE);
  60. chip->write_buf(mtd,chip->oob_poi,secc_start);
  61. chip->ecc.calculate(mtd,0,&ecc_calc[chip->ecc.total]);
  62. for(i=0;i
  63. chip->oob_poi[secc_start+i]=ecc_calc[chip->ecc.total+i];
  64. chip->write_buf(mtd,chip->oob_poi+secc_start,eccbytes);
  65. /*SendcommandtoprogramtheOOBdata*/
  66. chip->cmdfunc(mtd,NAND_CMD_PAGEPROG,-1,-1);
  67. status=chip->waitfunc(mtd,chip);
  68. returnstatus&NAND_STATUS_FAIL?-EIO:0;
  69. }
  70. staticints5p_nand_probe(structplatform_device*pdev){
  71. intret=0;
  72. structresource*mem;
  73. //硬件部分初始化
  74. mem=platform_get_resource(pdev,IORESOURCE_MEM,0);
  75. if(!mem){
  76. dev_err(&pdev->dev,"cantgetI/Oresourcemem");
  77. return-ENXIO;
  78. }
  79. s5p_nand_regs=(volatilestructs5p_nand_regs*)ioremap(mem->start,resource_size(mem));
  80. if(s5p_nand_regs==NULL){
  81. dev_err(&pdev->dev,"ioremapfailed");
  82. ret=-EIO;
  83. gotoerr_exit;
  84. }
  85. s5p_nand_clk=clk_get(&pdev->dev,"nand");
  86. if(s5p_nand_clk==NULL){
  87. dev_dbg(&pdev->dev,"getclkfailed");
  88. ret=-ENODEV;
  89. gotoerr_iounmap;
  90. }
  91. clk_enable(s5p_nand_clk);
  92. //s5p_nand_regs->nfconf&=~(0xfff<4);
  93. //s5p_nand_regs->nfconf|=(3<12)|(5<8)|(3<4);
  94. //s5p_nand_regs->nfcont|=3;
  95. //分配驱动相关结构体
  96. nand_chip=(structnand_chip*)kzalloc(sizeof(structnand_chip),GFP_KERNEL);
  97. if(nand_chip==NULL){
  98. dev_err(&pdev->dev,"failedtoallocatenand_chipstructure");
  99. ret=-ENOMEM;
  100. gotoerr_clk_put;
  101. }
  102. s5p_mtd_info=(structmtd_info*)kzalloc(sizeof(structmtd_info),GFP_KERNEL);
  103. if(s5p_mtd_info==NULL){
  104. dev_err(&pdev->dev,"failedtoallocatemtd_infostructure");
  105. ret=-ENOMEM;
  106. gotoerr_free_chip;
  107. }
  108. //设置驱动相关结构体
  109. nand_chip->IO_ADDR_R=(unsignedchar*)&s5p_nand_regs->nfdata;
  110. nand_chip->IO_ADDR_W=(unsignedchar*)&s5p_nand_regs->nfdata;
  111. nand_chip->cmd_ctrl=s5p_nand_cmd_ctrl;
  112. nand_chip->dev_ready=s5p_nand_ready;
  113. nand_chip->ecc.mode=NAND_ECC_HW;
  114. nand_chip->ecc.hwctl=s5p_ecc_hwctl;
  115. nand_chip->ecc.calculate=s5p_ecc_calculate;
  116. nand_chip->ecc.correct=s5p_ecc_correct;
  117. nand_chip->ecc.read_oob=s5p_nand_read_oob;
  118. nand_chip->ecc.write_oob=s5p_nand_write_oob;
  119. nand_chip->ecc.read_page=s5p_nand_read_page;
  120. nand_chip->nand_chip->ecc.w

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top