toshiba.c 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2018 exceet electronics GmbH
  4. * Copyright (c) 2018 Kontron Electronics GmbH
  5. *
  6. * Author: Frieder Schrempf <[email protected]>
  7. */
  8. #include <linux/device.h>
  9. #include <linux/kernel.h>
  10. #include <linux/mtd/spinand.h>
  11. /* Kioxia is new name of Toshiba memory. */
  12. #define SPINAND_MFR_TOSHIBA 0x98
  13. #define TOSH_STATUS_ECC_HAS_BITFLIPS_T (3 << 4)
  14. static SPINAND_OP_VARIANTS(read_cache_variants,
  15. SPINAND_PAGE_READ_FROM_CACHE_X4_OP(0, 1, NULL, 0),
  16. SPINAND_PAGE_READ_FROM_CACHE_X2_OP(0, 1, NULL, 0),
  17. SPINAND_PAGE_READ_FROM_CACHE_OP(true, 0, 1, NULL, 0),
  18. SPINAND_PAGE_READ_FROM_CACHE_OP(false, 0, 1, NULL, 0));
  19. static SPINAND_OP_VARIANTS(write_cache_x4_variants,
  20. SPINAND_PROG_LOAD_X4(true, 0, NULL, 0),
  21. SPINAND_PROG_LOAD(true, 0, NULL, 0));
  22. static SPINAND_OP_VARIANTS(update_cache_x4_variants,
  23. SPINAND_PROG_LOAD_X4(false, 0, NULL, 0),
  24. SPINAND_PROG_LOAD(false, 0, NULL, 0));
  25. /*
  26. * Backward compatibility for 1st generation Serial NAND devices
  27. * which don't support Quad Program Load operation.
  28. */
  29. static SPINAND_OP_VARIANTS(write_cache_variants,
  30. SPINAND_PROG_LOAD(true, 0, NULL, 0));
  31. static SPINAND_OP_VARIANTS(update_cache_variants,
  32. SPINAND_PROG_LOAD(false, 0, NULL, 0));
  33. static int tx58cxgxsxraix_ooblayout_ecc(struct mtd_info *mtd, int section,
  34. struct mtd_oob_region *region)
  35. {
  36. if (section > 0)
  37. return -ERANGE;
  38. region->offset = mtd->oobsize / 2;
  39. region->length = mtd->oobsize / 2;
  40. return 0;
  41. }
  42. static int tx58cxgxsxraix_ooblayout_free(struct mtd_info *mtd, int section,
  43. struct mtd_oob_region *region)
  44. {
  45. if (section > 0)
  46. return -ERANGE;
  47. /* 2 bytes reserved for BBM */
  48. region->offset = 2;
  49. region->length = (mtd->oobsize / 2) - 2;
  50. return 0;
  51. }
  52. static const struct mtd_ooblayout_ops tx58cxgxsxraix_ooblayout = {
  53. .ecc = tx58cxgxsxraix_ooblayout_ecc,
  54. .free = tx58cxgxsxraix_ooblayout_free,
  55. };
  56. static int tx58cxgxsxraix_ecc_get_status(struct spinand_device *spinand,
  57. u8 status)
  58. {
  59. struct nand_device *nand = spinand_to_nand(spinand);
  60. u8 mbf = 0;
  61. struct spi_mem_op op = SPINAND_GET_FEATURE_OP(0x30, spinand->scratchbuf);
  62. switch (status & STATUS_ECC_MASK) {
  63. case STATUS_ECC_NO_BITFLIPS:
  64. return 0;
  65. case STATUS_ECC_UNCOR_ERROR:
  66. return -EBADMSG;
  67. case STATUS_ECC_HAS_BITFLIPS:
  68. case TOSH_STATUS_ECC_HAS_BITFLIPS_T:
  69. /*
  70. * Let's try to retrieve the real maximum number of bitflips
  71. * in order to avoid forcing the wear-leveling layer to move
  72. * data around if it's not necessary.
  73. */
  74. if (spi_mem_exec_op(spinand->spimem, &op))
  75. return nanddev_get_ecc_conf(nand)->strength;
  76. mbf = *(spinand->scratchbuf) >> 4;
  77. if (WARN_ON(mbf > nanddev_get_ecc_conf(nand)->strength || !mbf))
  78. return nanddev_get_ecc_conf(nand)->strength;
  79. return mbf;
  80. default:
  81. break;
  82. }
  83. return -EINVAL;
  84. }
  85. static const struct spinand_info toshiba_spinand_table[] = {
  86. /* 3.3V 1Gb (1st generation) */
  87. SPINAND_INFO("TC58CVG0S3HRAIG",
  88. SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xC2),
  89. NAND_MEMORG(1, 2048, 128, 64, 1024, 20, 1, 1, 1),
  90. NAND_ECCREQ(8, 512),
  91. SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  92. &write_cache_variants,
  93. &update_cache_variants),
  94. 0,
  95. SPINAND_ECCINFO(&tx58cxgxsxraix_ooblayout,
  96. tx58cxgxsxraix_ecc_get_status)),
  97. /* 3.3V 2Gb (1st generation) */
  98. SPINAND_INFO("TC58CVG1S3HRAIG",
  99. SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xCB),
  100. NAND_MEMORG(1, 2048, 128, 64, 2048, 40, 1, 1, 1),
  101. NAND_ECCREQ(8, 512),
  102. SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  103. &write_cache_variants,
  104. &update_cache_variants),
  105. 0,
  106. SPINAND_ECCINFO(&tx58cxgxsxraix_ooblayout,
  107. tx58cxgxsxraix_ecc_get_status)),
  108. /* 3.3V 4Gb (1st generation) */
  109. SPINAND_INFO("TC58CVG2S0HRAIG",
  110. SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xCD),
  111. NAND_MEMORG(1, 4096, 256, 64, 2048, 40, 1, 1, 1),
  112. NAND_ECCREQ(8, 512),
  113. SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  114. &write_cache_variants,
  115. &update_cache_variants),
  116. 0,
  117. SPINAND_ECCINFO(&tx58cxgxsxraix_ooblayout,
  118. tx58cxgxsxraix_ecc_get_status)),
  119. /* 1.8V 1Gb (1st generation) */
  120. SPINAND_INFO("TC58CYG0S3HRAIG",
  121. SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xB2),
  122. NAND_MEMORG(1, 2048, 128, 64, 1024, 20, 1, 1, 1),
  123. NAND_ECCREQ(8, 512),
  124. SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  125. &write_cache_variants,
  126. &update_cache_variants),
  127. 0,
  128. SPINAND_ECCINFO(&tx58cxgxsxraix_ooblayout,
  129. tx58cxgxsxraix_ecc_get_status)),
  130. /* 1.8V 2Gb (1st generation) */
  131. SPINAND_INFO("TC58CYG1S3HRAIG",
  132. SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xBB),
  133. NAND_MEMORG(1, 2048, 128, 64, 2048, 40, 1, 1, 1),
  134. NAND_ECCREQ(8, 512),
  135. SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  136. &write_cache_variants,
  137. &update_cache_variants),
  138. 0,
  139. SPINAND_ECCINFO(&tx58cxgxsxraix_ooblayout,
  140. tx58cxgxsxraix_ecc_get_status)),
  141. /* 1.8V 4Gb (1st generation) */
  142. SPINAND_INFO("TC58CYG2S0HRAIG",
  143. SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xBD),
  144. NAND_MEMORG(1, 4096, 256, 64, 2048, 40, 1, 1, 1),
  145. NAND_ECCREQ(8, 512),
  146. SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  147. &write_cache_variants,
  148. &update_cache_variants),
  149. 0,
  150. SPINAND_ECCINFO(&tx58cxgxsxraix_ooblayout,
  151. tx58cxgxsxraix_ecc_get_status)),
  152. /*
  153. * 2nd generation serial nand has HOLD_D which is equivalent to
  154. * QE_BIT.
  155. */
  156. /* 3.3V 1Gb (2nd generation) */
  157. SPINAND_INFO("TC58CVG0S3HRAIJ",
  158. SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xE2),
  159. NAND_MEMORG(1, 2048, 128, 64, 1024, 20, 1, 1, 1),
  160. NAND_ECCREQ(8, 512),
  161. SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  162. &write_cache_x4_variants,
  163. &update_cache_x4_variants),
  164. SPINAND_HAS_QE_BIT,
  165. SPINAND_ECCINFO(&tx58cxgxsxraix_ooblayout,
  166. tx58cxgxsxraix_ecc_get_status)),
  167. /* 3.3V 2Gb (2nd generation) */
  168. SPINAND_INFO("TC58CVG1S3HRAIJ",
  169. SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xEB),
  170. NAND_MEMORG(1, 2048, 128, 64, 2048, 40, 1, 1, 1),
  171. NAND_ECCREQ(8, 512),
  172. SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  173. &write_cache_x4_variants,
  174. &update_cache_x4_variants),
  175. SPINAND_HAS_QE_BIT,
  176. SPINAND_ECCINFO(&tx58cxgxsxraix_ooblayout,
  177. tx58cxgxsxraix_ecc_get_status)),
  178. /* 3.3V 4Gb (2nd generation) */
  179. SPINAND_INFO("TC58CVG2S0HRAIJ",
  180. SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xED),
  181. NAND_MEMORG(1, 4096, 256, 64, 2048, 40, 1, 1, 1),
  182. NAND_ECCREQ(8, 512),
  183. SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  184. &write_cache_x4_variants,
  185. &update_cache_x4_variants),
  186. SPINAND_HAS_QE_BIT,
  187. SPINAND_ECCINFO(&tx58cxgxsxraix_ooblayout,
  188. tx58cxgxsxraix_ecc_get_status)),
  189. /* 3.3V 8Gb (2nd generation) */
  190. SPINAND_INFO("TH58CVG3S0HRAIJ",
  191. SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xE4),
  192. NAND_MEMORG(1, 4096, 256, 64, 4096, 80, 1, 1, 1),
  193. NAND_ECCREQ(8, 512),
  194. SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  195. &write_cache_x4_variants,
  196. &update_cache_x4_variants),
  197. SPINAND_HAS_QE_BIT,
  198. SPINAND_ECCINFO(&tx58cxgxsxraix_ooblayout,
  199. tx58cxgxsxraix_ecc_get_status)),
  200. /* 1.8V 1Gb (2nd generation) */
  201. SPINAND_INFO("TC58CYG0S3HRAIJ",
  202. SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xD2),
  203. NAND_MEMORG(1, 2048, 128, 64, 1024, 20, 1, 1, 1),
  204. NAND_ECCREQ(8, 512),
  205. SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  206. &write_cache_x4_variants,
  207. &update_cache_x4_variants),
  208. SPINAND_HAS_QE_BIT,
  209. SPINAND_ECCINFO(&tx58cxgxsxraix_ooblayout,
  210. tx58cxgxsxraix_ecc_get_status)),
  211. /* 1.8V 2Gb (2nd generation) */
  212. SPINAND_INFO("TC58CYG1S3HRAIJ",
  213. SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xDB),
  214. NAND_MEMORG(1, 2048, 128, 64, 2048, 40, 1, 1, 1),
  215. NAND_ECCREQ(8, 512),
  216. SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  217. &write_cache_x4_variants,
  218. &update_cache_x4_variants),
  219. SPINAND_HAS_QE_BIT,
  220. SPINAND_ECCINFO(&tx58cxgxsxraix_ooblayout,
  221. tx58cxgxsxraix_ecc_get_status)),
  222. /* 1.8V 4Gb (2nd generation) */
  223. SPINAND_INFO("TC58CYG2S0HRAIJ",
  224. SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xDD),
  225. NAND_MEMORG(1, 4096, 256, 64, 2048, 40, 1, 1, 1),
  226. NAND_ECCREQ(8, 512),
  227. SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  228. &write_cache_x4_variants,
  229. &update_cache_x4_variants),
  230. SPINAND_HAS_QE_BIT,
  231. SPINAND_ECCINFO(&tx58cxgxsxraix_ooblayout,
  232. tx58cxgxsxraix_ecc_get_status)),
  233. /* 1.8V 8Gb (2nd generation) */
  234. SPINAND_INFO("TH58CYG3S0HRAIJ",
  235. SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xD4),
  236. NAND_MEMORG(1, 4096, 256, 64, 4096, 80, 1, 1, 1),
  237. NAND_ECCREQ(8, 512),
  238. SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  239. &write_cache_x4_variants,
  240. &update_cache_x4_variants),
  241. SPINAND_HAS_QE_BIT,
  242. SPINAND_ECCINFO(&tx58cxgxsxraix_ooblayout,
  243. tx58cxgxsxraix_ecc_get_status)),
  244. };
  245. static const struct spinand_manufacturer_ops toshiba_spinand_manuf_ops = {
  246. };
  247. const struct spinand_manufacturer toshiba_spinand_manufacturer = {
  248. .id = SPINAND_MFR_TOSHIBA,
  249. .name = "Toshiba",
  250. .chips = toshiba_spinand_table,
  251. .nchips = ARRAY_SIZE(toshiba_spinand_table),
  252. .ops = &toshiba_spinand_manuf_ops,
  253. };