微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > ARM-Linux驱动--MTD驱动分析(三)

ARM-Linux驱动--MTD驱动分析(三)

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

  1. td_part*part=PART(mtd);
  2. if(!(mtd->flags&MTD_WRITEABLE))
  3. return-EROFS;
  4. returnpart->master->writev(part->master,vecs,count,
  5. to+part->offset,retlen);
  6. }
  7. staticintpart_erase(structmtd_info*mtd,structerase_info*instr)
  8. {
  9. structmtd_part*part=PART(mtd);
  10. intret;
  11. if(!(mtd->flags&MTD_WRITEABLE))
  12. return-EROFS;
  13. if(instr->addr>=mtd->size)
  14. return-EINVAL;
  15. instr->addr+=part->offset;
  16. ret=part->master->erase(part->master,instr);
  17. if(ret){
  18. if(instr->fail_addr!=MTD_FAIL_ADDR_UNKNOWN)
  19. instr->fail_addr-=part->offset;
  20. instr->addr-=part->offset;
  21. }
  22. returnret;
  23. }
  24. voidmtd_erase_callback(structerase_info*instr)
  25. {
  26. if(instr->mtd->erase==part_erase){
  27. structmtd_part*part=PART(instr->mtd);
  28. if(instr->fail_addr!=MTD_FAIL_ADDR_UNKNOWN)
  29. instr->fail_addr-=part->offset;
  30. instr->addr-=part->offset;
  31. }
  32. if(instr->callback)
  33. instr->callback(instr);
  34. }
  35. EXPORT_SYMBOL_GPL(mtd_erase_callback);
  36. staticintpart_lock(structmtd_info*mtd,loff_tofs,uint64_tlen)
  37. {
  38. structmtd_part*part=PART(mtd);
  39. if((len+ofs)>mtd->size)
  40. return-EINVAL;
  41. returnpart->master->lock(part->master,ofs+part->offset,len);
  42. }
  43. staticintpart_unlock(structmtd_info*mtd,loff_tofs,uint64_tlen)
  44. {
  45. structmtd_part*part=PART(mtd);
  46. if((len+ofs)>mtd->size)
  47. return-EINVAL;
  48. returnpart->master->unlock(part->master,ofs+part->offset,len);
  49. }
  50. //分区同步函数
  51. staticvoidpart_sync(structmtd_info*mtd)
  52. {
  53. structmtd_part*part=PART(mtd);
  54. part->master->sync(part->master);
  55. }
  56. //支持电源管理的功能函数
  57. staticintpart_suspend(structmtd_info*mtd)
  58. {
  59. structmtd_part*part=PART(mtd);
  60. returnpart->master->suspend(part->master);
  61. }
  62. staticvoidpart_resume(structmtd_info*mtd)
  63. {
  64. structmtd_part*part=PART(mtd);
  65. part->master->resume(part->master);
  66. }
  67. staticintpart_block_isbad(structmtd_info*mtd,loff_tofs)
  68. {
  69. structmtd_part*part=PART(mtd);
  70. if(ofs>=mtd->size)
  71. return-EINVAL;
  72. ofs+=part->offset;
  73. returnpart->master->block_isbad(part->master,ofs);
  74. }
  75. //标记设备地址坏块
  76. staticintpart_block_markbad(structmtd_info*mtd,loff_tofs)
  77. {
  78. structmtd_part*part=PART(mtd);
  79. intres;
  80. if(!(mtd->flags&MTD_WRITEABLE))
  81. return-EROFS;
  82. if(ofs>=mtd->size)
  83. return-EINVAL;
  84. ofs+=part->offset;
  85. res=part->master->block_markbad(part->master,ofs);
  86. if(!res)
  87. mtd->ecc_stats.badblocks++;
  88. returnres;
  89. }


下篇分析具体的MTD设备,字符设备和块设备,待续........

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

网站地图

Top