1
0

0040-nand-add-mtk-nand-hack-hook.patch 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. From 61e17c2f864698033f4661e1fc7ba63d4d982491 Mon Sep 17 00:00:00 2001
  2. From: John Crispin <blogic@openwrt.org>
  3. Date: Mon, 7 Dec 2015 17:21:55 +0100
  4. Subject: [PATCH 40/53] nand: add mtk-nand hack/hook
  5. Signed-off-by: John Crispin <blogic@openwrt.org>
  6. ---
  7. drivers/mtd/nand/mtk_nand.c | 34 ++++++++++++++++++++++++++++++----
  8. drivers/mtd/nand/nand_base.c | 9 ++++++++-
  9. drivers/mtd/nand/nand_device_list.h | 2 ++
  10. include/linux/mtd/nand.h | 4 ++++
  11. 4 files changed, 44 insertions(+), 5 deletions(-)
  12. --- a/drivers/mtd/nand/mtk_nand.c
  13. +++ b/drivers/mtd/nand/mtk_nand.c
  14. @@ -110,6 +110,10 @@ int part_num = NUM_PARTITIONS;
  15. int manu_id;
  16. int dev_id;
  17. +/* this constant was taken from linux/nand/nand.h v 3.14
  18. + * in later versions it seems it was removed in order to save a bit of space
  19. + */
  20. +#define NAND_MAX_OOBSIZE 774
  21. static u8 local_oob_buf[NAND_MAX_OOBSIZE];
  22. static u8 nand_badblock_offset = 0;
  23. @@ -348,7 +352,7 @@ mtk_nand_check_bch_error(struct mtd_info
  24. if (0xF == u4ErrNum) {
  25. mtd->ecc_stats.failed++;
  26. bRet = false;
  27. - //printk(KERN_ERR"UnCorrectable at PageAddr=%d\n", u4PageAddr);
  28. + printk(KERN_ERR"mtk_nand: UnCorrectable at PageAddr=%d\n", u4PageAddr);
  29. } else {
  30. for (i = 0; i < ((u4ErrNum + 1) >> 1); ++i) {
  31. au4ErrBitLoc[i] = DRV_Reg32(ECC_DECEL0_REG32 + i);
  32. @@ -1422,7 +1426,7 @@ mtk_nand_erase_hw(struct mtd_info *mtd,
  33. {
  34. struct nand_chip *chip = (struct nand_chip *)mtd->priv;
  35. - chip->erase_cmd(mtd, page);
  36. + chip->erase(mtd, page);
  37. return chip->waitfunc(mtd, chip);
  38. }
  39. @@ -2094,8 +2098,8 @@ mtk_nand_probe(struct platform_device *p
  40. nand_chip->write_page = mtk_nand_write_page;
  41. nand_chip->ecc.write_oob = mtk_nand_write_oob;
  42. nand_chip->block_markbad = mtk_nand_block_markbad; // need to add nand_get_device()/nand_release_device().
  43. - // nand_chip->erase = mtk_nand_erase;
  44. - // nand_chip->read_page = mtk_nand_read_page;
  45. + nand_chip->erase_mtk = mtk_nand_erase;
  46. + nand_chip->read_page = mtk_nand_read_page;
  47. nand_chip->ecc.read_oob = mtk_nand_read_oob;
  48. nand_chip->block_bad = mtk_nand_block_bad;
  49. @@ -2175,6 +2179,21 @@ mtk_nand_probe(struct platform_device *p
  50. nand_chip->pagemask = (nand_chip->chipsize >> nand_chip->page_shift) - 1;
  51. nand_chip->phys_erase_shift = ffs(mtd->erasesize) - 1;
  52. nand_chip->chip_shift = ffs(nand_chip->chipsize) - 1;//0x1C;//ffs(nand_chip->chipsize) - 1;
  53. +
  54. + /* allocate buffers or call select_chip here or a bit earlier*/
  55. + {
  56. + struct nand_buffers *nbuf = kzalloc(sizeof(*nbuf) + mtd->writesize + mtd->oobsize * 3, GFP_KERNEL);
  57. + if (!nbuf) {
  58. + return -ENOMEM;
  59. + }
  60. + nbuf->ecccalc = (uint8_t *)(nbuf + 1);
  61. + nbuf->ecccode = nbuf->ecccalc + mtd->oobsize;
  62. + nbuf->databuf = nbuf->ecccode + mtd->oobsize;
  63. +
  64. + nand_chip->buffers = nbuf;
  65. + nand_chip->options |= NAND_OWN_BUFFERS;
  66. + }
  67. +
  68. nand_chip->oob_poi = nand_chip->buffers->databuf + mtd->writesize;
  69. nand_chip->badblockpos = 0;
  70. @@ -2251,6 +2270,9 @@ out:
  71. MSG(INIT, "[NFI] mtk_nand_probe fail, err = %d!\n", err);
  72. nand_release(mtd);
  73. platform_set_drvdata(pdev, NULL);
  74. + if ( NULL != nand_chip->buffers) {
  75. + kfree(nand_chip->buffers);
  76. + }
  77. kfree(host);
  78. nand_disable_clock();
  79. return err;
  80. @@ -2261,8 +2283,12 @@ mtk_nand_remove(struct platform_device *
  81. {
  82. struct mtk_nand_host *host = platform_get_drvdata(pdev);
  83. struct mtd_info *mtd = &host->mtd;
  84. + struct nand_chip *nand_chip = &host->nand_chip;
  85. nand_release(mtd);
  86. + if ( NULL != nand_chip->buffers) {
  87. + kfree(nand_chip->buffers);
  88. + }
  89. kfree(host);
  90. nand_disable_clock();
  91. --- a/drivers/mtd/nand/nand_base.c
  92. +++ b/drivers/mtd/nand/nand_base.c
  93. @@ -1727,6 +1727,9 @@ static int nand_do_read_ops(struct mtd_i
  94. __func__, buf);
  95. read_retry:
  96. +#ifdef CONFIG_MTK_MTD_NAND
  97. + ret = chip->read_page(mtd, chip, bufpoi, page);
  98. +#else
  99. chip->cmdfunc(mtd, NAND_CMD_READ0, 0x00, page);
  100. /*
  101. @@ -1745,6 +1748,7 @@ read_retry:
  102. else
  103. ret = chip->ecc.read_page(mtd, chip, bufpoi,
  104. oob_required, page);
  105. +#endif /* CONFIG_MTK_MTD_NAND */
  106. if (ret < 0) {
  107. if (use_bufpoi)
  108. /* Invalidate page cache */
  109. @@ -2935,8 +2939,11 @@ int nand_erase_nand(struct mtd_info *mtd
  110. if (page <= chip->pagebuf && chip->pagebuf <
  111. (page + pages_per_block))
  112. chip->pagebuf = -1;
  113. -
  114. +#ifdef CONFIG_MTK_MTD_NAND
  115. + status = chip->erase_mtk(mtd, page & chip->pagemask);
  116. +#else
  117. status = chip->erase(mtd, page & chip->pagemask);
  118. +#endif /* CONFIG_MTK_MTD_NAND */
  119. /*
  120. * See if operation failed and additional status checks are
  121. --- a/drivers/mtd/nand/nand_device_list.h
  122. +++ b/drivers/mtd/nand/nand_device_list.h
  123. @@ -43,6 +43,8 @@ static const flashdev_info gen_FlashTabl
  124. {0xADBC, 0x905554, 5, 16, 512, 128, 2048, 64, 0x10801011, "H9DA4GH4JJAMC", 0},
  125. {0x01F1, 0x801D01, 4, 8, 128, 128, 2048, 64, 0x30C77fff, "S34ML01G100TF", 0},
  126. {0x92F1, 0x8095FF, 4, 8, 128, 128, 2048, 64, 0x30C77fff, "F59L1G81A", 0},
  127. + {0xC8DA, 0x909544, 5, 8, 256, 128, 2048, 64, 0x30C77fff, "F59L2G81A", 0},
  128. + {0xC8DC, 0x909554, 5, 8, 512, 128, 2048, 64, 0x30C77fff, "F59L4G81A", 0},
  129. {0xECD3, 0x519558, 5, 8, 1024, 128, 2048, 64, 0x44333, "K9K8G8000", 0},
  130. {0xC2F1, 0x801DC2, 4, 8, 128, 128, 2048, 64, 0x30C77fff, "MX30LF1G08AA", 0},
  131. {0x98D3, 0x902676, 5, 8, 1024, 256, 4096, 224, 0x00C25332, "TC58NVG3S0F", 0},
  132. --- a/include/linux/mtd/nand.h
  133. +++ b/include/linux/mtd/nand.h
  134. @@ -665,6 +665,10 @@ struct nand_chip {
  135. int (*write_page)(struct mtd_info *mtd, struct nand_chip *chip,
  136. uint32_t offset, int data_len, const uint8_t *buf,
  137. int oob_required, int page, int cached, int raw);
  138. +#ifdef CONFIG_MTK_MTD_NAND
  139. + int (*read_page)(struct mtd_info *mtd, struct nand_chip *chip, u8 *buf, int page);
  140. + int (*erase_mtk)(struct mtd_info *mtd, int page);
  141. +#endif /* CONFIG_MTK_MTD_NAND */
  142. int (*onfi_set_features)(struct mtd_info *mtd, struct nand_chip *chip,
  143. int feature_addr, uint8_t *subfeature_para);
  144. int (*onfi_get_features)(struct mtd_info *mtd, struct nand_chip *chip,