100-22-mtd-spi-nand-backport-from-upstream-kernel.patch 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549
  1. From 8d0665327819c41fce2c8d50f19c967b22eae564 Mon Sep 17 00:00:00 2001
  2. From: Weijie Gao <[email protected]>
  3. Date: Wed, 27 Jul 2022 16:36:13 +0800
  4. Subject: [PATCH 57/71] mtd: spi-nand: backport from upstream kernel
  5. Backport new features from upstream kernel
  6. Signed-off-by: Weijie Gao <[email protected]>
  7. ---
  8. drivers/mtd/nand/spi/Kconfig | 1 +
  9. drivers/mtd/nand/spi/Makefile | 2 +-
  10. drivers/mtd/nand/spi/core.c | 102 ++++++----
  11. drivers/mtd/nand/spi/etron.c | 181 +++++++++++++++++
  12. drivers/mtd/nand/spi/gigadevice.c | 322 ++++++++++++++++++++++++++----
  13. drivers/mtd/nand/spi/macronix.c | 173 +++++++++++++---
  14. drivers/mtd/nand/spi/micron.c | 50 ++---
  15. drivers/mtd/nand/spi/toshiba.c | 66 +++---
  16. drivers/mtd/nand/spi/winbond.c | 164 ++++++++++++---
  17. include/linux/mtd/spinand.h | 87 +++++---
  18. 10 files changed, 923 insertions(+), 225 deletions(-)
  19. create mode 100644 drivers/mtd/nand/spi/etron.c
  20. --- a/drivers/mtd/nand/spi/Makefile
  21. +++ b/drivers/mtd/nand/spi/Makefile
  22. @@ -1,4 +1,4 @@
  23. # SPDX-License-Identifier: GPL-2.0
  24. -spinand-objs := core.o gigadevice.o macronix.o micron.o paragon.o toshiba.o winbond.o
  25. +spinand-objs := core.o etron.o gigadevice.o macronix.o micron.o paragon.o toshiba.o winbond.o
  26. obj-$(CONFIG_MTD_SPI_NAND) += spinand.o
  27. --- a/drivers/mtd/nand/spi/core.c
  28. +++ b/drivers/mtd/nand/spi/core.c
  29. @@ -822,6 +822,7 @@ static const struct nand_ops spinand_ops
  30. };
  31. static const struct spinand_manufacturer *spinand_manufacturers[] = {
  32. + &etron_spinand_manufacturer,
  33. &gigadevice_spinand_manufacturer,
  34. &macronix_spinand_manufacturer,
  35. &micron_spinand_manufacturer,
  36. --- /dev/null
  37. +++ b/drivers/mtd/nand/spi/etron.c
  38. @@ -0,0 +1,181 @@
  39. +// SPDX-License-Identifier: GPL-2.0
  40. +/*
  41. + * Copyright (c) 2020 Etron Technology, Inc.
  42. + *
  43. + */
  44. +#ifndef __UBOOT__
  45. +#include <malloc.h>
  46. +#include <linux/device.h>
  47. +#include <linux/kernel.h>
  48. +#endif
  49. +#include <linux/bug.h>
  50. +#include <linux/mtd/spinand.h>
  51. +
  52. +#define SPINAND_MFR_ETRON 0xD5
  53. +
  54. +#define STATUS_ECC_LIMIT_BITFLIPS (3 << 4)
  55. +
  56. +static SPINAND_OP_VARIANTS(read_cache_variants,
  57. + SPINAND_PAGE_READ_FROM_CACHE_QUADIO_OP(0, 1, NULL, 0),
  58. + SPINAND_PAGE_READ_FROM_CACHE_X4_OP(0, 1, NULL, 0),
  59. + SPINAND_PAGE_READ_FROM_CACHE_DUALIO_OP(0, 1, NULL, 0),
  60. + SPINAND_PAGE_READ_FROM_CACHE_X2_OP(0, 1, NULL, 0),
  61. + SPINAND_PAGE_READ_FROM_CACHE_OP(true, 0, 1, NULL, 0),
  62. + SPINAND_PAGE_READ_FROM_CACHE_OP(false, 0, 1, NULL, 0));
  63. +
  64. +static SPINAND_OP_VARIANTS(write_cache_variants,
  65. + SPINAND_PROG_LOAD_X4(true, 0, NULL, 0),
  66. + SPINAND_PROG_LOAD(true, 0, NULL, 0));
  67. +
  68. +static SPINAND_OP_VARIANTS(update_cache_variants,
  69. + SPINAND_PROG_LOAD_X4(false, 0, NULL, 0),
  70. + SPINAND_PROG_LOAD(false, 0, NULL, 0));
  71. +
  72. +static int etron_ooblayout_ecc(struct mtd_info *mtd, int section,
  73. + struct mtd_oob_region *region)
  74. +{
  75. + if (section > 3)
  76. + return -ERANGE;
  77. +
  78. + region->offset = (14 * section) + 72;
  79. + region->length = 14;
  80. +
  81. + return 0;
  82. +}
  83. +
  84. +static int etron_ooblayout_free(struct mtd_info *mtd, int section,
  85. + struct mtd_oob_region *region)
  86. +{
  87. + if (section > 3)
  88. + return -ERANGE;
  89. +
  90. + if (section) {
  91. + region->offset = 18 * section;
  92. + region->length = 18;
  93. + } else {
  94. + /* section 0 has one byte reserved for bad block mark */
  95. + region->offset = 2;
  96. + region->length = 16;
  97. + }
  98. + return 0;
  99. +}
  100. +
  101. +static const struct mtd_ooblayout_ops etron_ooblayout = {
  102. + .ecc = etron_ooblayout_ecc,
  103. + .rfree = etron_ooblayout_free,
  104. +};
  105. +
  106. +static int etron_ecc_get_status(struct spinand_device *spinand,
  107. + u8 status)
  108. +{
  109. + struct nand_device *nand = spinand_to_nand(spinand);
  110. +
  111. + switch (status & STATUS_ECC_MASK) {
  112. + case STATUS_ECC_NO_BITFLIPS:
  113. + return 0;
  114. +
  115. + case STATUS_ECC_UNCOR_ERROR:
  116. + return -EBADMSG;
  117. +
  118. + case STATUS_ECC_HAS_BITFLIPS:
  119. + return nand->eccreq.strength >> 1;
  120. +
  121. + case STATUS_ECC_LIMIT_BITFLIPS:
  122. + return nand->eccreq.strength;
  123. +
  124. + default:
  125. + break;
  126. + }
  127. +
  128. + return -EINVAL;
  129. +}
  130. +
  131. +static const struct spinand_info etron_spinand_table[] = {
  132. + /* EM73C 1Gb 3.3V */
  133. + SPINAND_INFO("EM73C044VCF",
  134. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_ADDR, 0x25),
  135. + NAND_MEMORG(1, 2048, 64, 64, 1024, 20, 1, 1, 1),
  136. + NAND_ECCREQ(4, 512),
  137. + SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  138. + &write_cache_variants,
  139. + &update_cache_variants),
  140. + SPINAND_HAS_QE_BIT,
  141. + SPINAND_ECCINFO(&etron_ooblayout, etron_ecc_get_status)),
  142. + /* EM7xD 2Gb */
  143. + SPINAND_INFO("EM73D044VCR",
  144. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_ADDR, 0x41),
  145. + NAND_MEMORG(1, 2048, 64, 64, 2048, 40, 1, 1, 1),
  146. + NAND_ECCREQ(4, 512),
  147. + SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  148. + &write_cache_variants,
  149. + &update_cache_variants),
  150. + SPINAND_HAS_QE_BIT,
  151. + SPINAND_ECCINFO(&etron_ooblayout, etron_ecc_get_status)),
  152. + SPINAND_INFO("EM73D044VCO",
  153. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_ADDR, 0x3A),
  154. + NAND_MEMORG(1, 2048, 128, 64, 2048, 40, 1, 1, 1),
  155. + NAND_ECCREQ(8, 512),
  156. + SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  157. + &write_cache_variants,
  158. + &update_cache_variants),
  159. + SPINAND_HAS_QE_BIT,
  160. + SPINAND_ECCINFO(&etron_ooblayout, etron_ecc_get_status)),
  161. + SPINAND_INFO("EM78D044VCM",
  162. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_ADDR, 0x8E),
  163. + NAND_MEMORG(1, 2048, 128, 64, 2048, 40, 1, 1, 1),
  164. + NAND_ECCREQ(8, 512),
  165. + SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  166. + &write_cache_variants,
  167. + &update_cache_variants),
  168. + SPINAND_HAS_QE_BIT,
  169. + SPINAND_ECCINFO(&etron_ooblayout, etron_ecc_get_status)),
  170. + /* EM7xE 4Gb */
  171. + SPINAND_INFO("EM73E044VCE",
  172. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_ADDR, 0x3B),
  173. + NAND_MEMORG(1, 2048, 128, 64, 4096, 80, 1, 1, 1),
  174. + NAND_ECCREQ(8, 512),
  175. + SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  176. + &write_cache_variants,
  177. + &update_cache_variants),
  178. + SPINAND_HAS_QE_BIT,
  179. + SPINAND_ECCINFO(&etron_ooblayout, etron_ecc_get_status)),
  180. + SPINAND_INFO("EM78E044VCD",
  181. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_ADDR, 0x8F),
  182. + NAND_MEMORG(1, 2048, 128, 64, 4096, 80, 1, 1, 1),
  183. + NAND_ECCREQ(8, 512),
  184. + SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  185. + &write_cache_variants,
  186. + &update_cache_variants),
  187. + SPINAND_HAS_QE_BIT,
  188. + SPINAND_ECCINFO(&etron_ooblayout, etron_ecc_get_status)),
  189. + /* EM7xF044VCA 8Gb */
  190. + SPINAND_INFO("EM73F044VCA",
  191. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x15),
  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_variants,
  196. + &update_cache_variants),
  197. + SPINAND_HAS_QE_BIT,
  198. + SPINAND_ECCINFO(&etron_ooblayout, etron_ecc_get_status)),
  199. + SPINAND_INFO("EM78F044VCA",
  200. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x8D),
  201. + NAND_MEMORG(1, 4096, 256, 64, 4096, 80, 1, 1, 1),
  202. + NAND_ECCREQ(8, 512),
  203. + SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  204. + &write_cache_variants,
  205. + &update_cache_variants),
  206. + SPINAND_HAS_QE_BIT,
  207. + SPINAND_ECCINFO(&etron_ooblayout, etron_ecc_get_status)),
  208. +};
  209. +
  210. +static const struct spinand_manufacturer_ops etron_spinand_manuf_ops = {
  211. +};
  212. +
  213. +const struct spinand_manufacturer etron_spinand_manufacturer = {
  214. + .id = SPINAND_MFR_ETRON,
  215. + .name = "Etron",
  216. + .chips = etron_spinand_table,
  217. + .nchips = ARRAY_SIZE(etron_spinand_table),
  218. + .ops = &etron_spinand_manuf_ops,
  219. +};
  220. --- a/drivers/mtd/nand/spi/gigadevice.c
  221. +++ b/drivers/mtd/nand/spi/gigadevice.c
  222. @@ -43,6 +43,24 @@ static SPINAND_OP_VARIANTS(read_cache_va
  223. SPINAND_PAGE_READ_FROM_CACHE_OP_3A(true, 0, 1, NULL, 0),
  224. SPINAND_PAGE_READ_FROM_CACHE_OP_3A(false, 0, 0, NULL, 0));
  225. +/* Q5 1Gb */
  226. +static SPINAND_OP_VARIANTS(dummy2_read_cache_variants,
  227. + SPINAND_PAGE_READ_FROM_CACHE_QUADIO_OP(0, 2, NULL, 0),
  228. + SPINAND_PAGE_READ_FROM_CACHE_X4_OP(0, 1, NULL, 0),
  229. + SPINAND_PAGE_READ_FROM_CACHE_DUALIO_OP(0, 1, NULL, 0),
  230. + SPINAND_PAGE_READ_FROM_CACHE_X2_OP(0, 1, NULL, 0),
  231. + SPINAND_PAGE_READ_FROM_CACHE_OP(true, 0, 1, NULL, 0),
  232. + SPINAND_PAGE_READ_FROM_CACHE_OP(false, 0, 1, NULL, 0));
  233. +
  234. +/* Q5 2Gb & 4Gb */
  235. +static SPINAND_OP_VARIANTS(dummy4_read_cache_variants,
  236. + SPINAND_PAGE_READ_FROM_CACHE_QUADIO_OP(0, 4, NULL, 0),
  237. + SPINAND_PAGE_READ_FROM_CACHE_X4_OP(0, 1, NULL, 0),
  238. + SPINAND_PAGE_READ_FROM_CACHE_DUALIO_OP(0, 2, NULL, 0),
  239. + SPINAND_PAGE_READ_FROM_CACHE_X2_OP(0, 1, NULL, 0),
  240. + SPINAND_PAGE_READ_FROM_CACHE_OP(true, 0, 1, NULL, 0),
  241. + SPINAND_PAGE_READ_FROM_CACHE_OP(false, 0, 1, NULL, 0));
  242. +
  243. static SPINAND_OP_VARIANTS(write_cache_variants,
  244. SPINAND_PROG_LOAD_X4(true, 0, NULL, 0),
  245. SPINAND_PROG_LOAD(true, 0, NULL, 0));
  246. @@ -268,7 +286,45 @@ static int gd5fxgq4ufxxg_ecc_get_status(
  247. return -EINVAL;
  248. }
  249. +static int esmt_1_ooblayout_ecc(struct mtd_info *mtd, int section,
  250. + struct mtd_oob_region *region)
  251. +{
  252. + if (section > 3)
  253. + return -ERANGE;
  254. +
  255. + region->offset = (16 * section) + 8;
  256. + region->length = 8;
  257. +
  258. + return 0;
  259. +}
  260. +
  261. +static int esmt_1_ooblayout_free(struct mtd_info *mtd, int section,
  262. + struct mtd_oob_region *region)
  263. +{
  264. + if (section > 3)
  265. + return -ERANGE;
  266. +
  267. + region->offset = (16 * section) + 2;
  268. + region->length = 6;
  269. +
  270. + return 0;
  271. +}
  272. +
  273. +static const struct mtd_ooblayout_ops esmt_1_ooblayout = {
  274. + .ecc = esmt_1_ooblayout_ecc,
  275. + .rfree = esmt_1_ooblayout_free,
  276. + };
  277. +
  278. static const struct spinand_info gigadevice_spinand_table[] = {
  279. + SPINAND_INFO("F50L1G41LB",
  280. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_ADDR, 0x01),
  281. + NAND_MEMORG(1, 2048, 64, 64, 1024, 20, 1, 1, 1),
  282. + NAND_ECCREQ(8, 512),
  283. + SPINAND_INFO_OP_VARIANTS(&dummy2_read_cache_variants,
  284. + &write_cache_variants,
  285. + &update_cache_variants),
  286. + 0,
  287. + SPINAND_ECCINFO(&esmt_1_ooblayout, NULL)),
  288. SPINAND_INFO("GD5F1GQ4xA",
  289. SPINAND_ID(SPINAND_READID_METHOD_OPCODE_ADDR, 0xf1),
  290. NAND_MEMORG(1, 2048, 64, 64, 1024, 20, 1, 1, 1),
  291. @@ -349,6 +405,87 @@ static const struct spinand_info gigadev
  292. SPINAND_HAS_QE_BIT,
  293. SPINAND_ECCINFO(&gd5fxgqx_variant2_ooblayout,
  294. gd5fxgq5xexxg_ecc_get_status)),
  295. + SPINAND_INFO("GD5F2GQ5UExxG",
  296. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_ADDR, 0x52),
  297. + NAND_MEMORG(1, 2048, 128, 64, 2048, 40, 1, 1, 1),
  298. + NAND_ECCREQ(4, 512),
  299. + SPINAND_INFO_OP_VARIANTS(&dummy4_read_cache_variants,
  300. + &write_cache_variants,
  301. + &update_cache_variants),
  302. + SPINAND_HAS_QE_BIT,
  303. + SPINAND_ECCINFO(&gd5fxgqx_variant2_ooblayout,
  304. + gd5fxgq5xexxg_ecc_get_status)),
  305. + SPINAND_INFO("GD5F4GQ6UExxG",
  306. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_ADDR, 0x55),
  307. + NAND_MEMORG(1, 2048, 128, 64, 4096, 80, 1, 1, 1),
  308. + NAND_ECCREQ(4, 512),
  309. + SPINAND_INFO_OP_VARIANTS(&dummy4_read_cache_variants,
  310. + &write_cache_variants,
  311. + &update_cache_variants),
  312. + SPINAND_HAS_QE_BIT,
  313. + SPINAND_ECCINFO(&gd5fxgqx_variant2_ooblayout,
  314. + gd5fxgq5xexxg_ecc_get_status)),
  315. + SPINAND_INFO("GD5F1GM7UExxG",
  316. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_ADDR, 0x91),
  317. + NAND_MEMORG(1, 2048, 128, 64, 1024, 20, 1, 1, 1),
  318. + NAND_ECCREQ(8, 512),
  319. + SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  320. + &write_cache_variants,
  321. + &update_cache_variants),
  322. + SPINAND_HAS_QE_BIT,
  323. + SPINAND_ECCINFO(&gd5fxgqx_variant2_ooblayout,
  324. + gd5fxgq4uexxg_ecc_get_status)),
  325. + SPINAND_INFO("GD5F2GM7UExxG",
  326. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_ADDR, 0x92),
  327. + NAND_MEMORG(1, 2048, 128, 64, 2048, 40, 1, 1, 1),
  328. + NAND_ECCREQ(8, 512),
  329. + SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  330. + &write_cache_variants,
  331. + &update_cache_variants),
  332. + SPINAND_HAS_QE_BIT,
  333. + SPINAND_ECCINFO(&gd5fxgqx_variant2_ooblayout,
  334. + gd5fxgq4uexxg_ecc_get_status)),
  335. + SPINAND_INFO("GD5F4GM8UExxG",
  336. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_ADDR, 0x95),
  337. + NAND_MEMORG(1, 2048, 128, 64, 4096, 80, 1, 1, 1),
  338. + NAND_ECCREQ(8, 512),
  339. + SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  340. + &write_cache_variants,
  341. + &update_cache_variants),
  342. + SPINAND_HAS_QE_BIT,
  343. + SPINAND_ECCINFO(&gd5fxgqx_variant2_ooblayout,
  344. + gd5fxgq4uexxg_ecc_get_status)),
  345. + SPINAND_INFO("GD5F1GQ5UExxH",
  346. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x31),
  347. + NAND_MEMORG(1, 2048, 64, 64, 1024, 20, 1, 1, 1),
  348. + NAND_ECCREQ(4, 512),
  349. + SPINAND_INFO_OP_VARIANTS(&dummy2_read_cache_variants,
  350. + &write_cache_variants,
  351. + &update_cache_variants),
  352. + SPINAND_HAS_QE_BIT,
  353. + SPINAND_ECCINFO(&gd5fxgqx_variant2_ooblayout,
  354. + gd5fxgq5xexxg_ecc_get_status)),
  355. + SPINAND_INFO("GD5F2GQ5UExxH",
  356. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x32),
  357. + NAND_MEMORG(1, 2048, 64, 64, 2048, 40, 1, 1, 1),
  358. + NAND_ECCREQ(4, 512),
  359. + SPINAND_INFO_OP_VARIANTS(&dummy4_read_cache_variants,
  360. + &write_cache_variants,
  361. + &update_cache_variants),
  362. + SPINAND_HAS_QE_BIT,
  363. + SPINAND_ECCINFO(&gd5fxgqx_variant2_ooblayout,
  364. + gd5fxgq5xexxg_ecc_get_status)),
  365. + SPINAND_INFO("GD5F4GQ6UExxH",
  366. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x35),
  367. + NAND_MEMORG(1, 2048, 64, 64, 4096, 40, 1, 1, 1),
  368. + NAND_ECCREQ(4, 512),
  369. + SPINAND_INFO_OP_VARIANTS(&dummy4_read_cache_variants,
  370. + &write_cache_variants,
  371. + &update_cache_variants),
  372. + SPINAND_HAS_QE_BIT,
  373. + SPINAND_ECCINFO(&gd5fxgqx_variant2_ooblayout,
  374. + gd5fxgq5xexxg_ecc_get_status)),
  375. +
  376. };
  377. static const struct spinand_manufacturer_ops gigadevice_spinand_manuf_ops = {
  378. --- a/drivers/mtd/nand/spi/winbond.c
  379. +++ b/drivers/mtd/nand/spi/winbond.c
  380. @@ -18,6 +18,23 @@
  381. #define WINBOND_CFG_BUF_READ BIT(3)
  382. +#define W25N02_N04KV_STATUS_ECC_MASK (3 << 4)
  383. +#define W25N02_N04KV_STATUS_ECC_NO_BITFLIPS (0 << 4)
  384. +#define W25N02_N04KV_STATUS_ECC_1_4_BITFLIPS (1 << 4)
  385. +#define W25N02_N04KV_STATUS_ECC_5_8_BITFLIPS (3 << 4)
  386. +#define W25N02_N04KV_STATUS_ECC_UNCOR_ERROR (2 << 4)
  387. +
  388. +#define W25N01_M02GV_STATUS_ECC_MASK (3 << 4)
  389. +#define W25N01_M02GV_STATUS_ECC_NO_BITFLIPS (0 << 4)
  390. +#define W25N01_M02GV_STATUS_ECC_1_BITFLIPS (1 << 4)
  391. +#define W25N01_M02GV_STATUS_ECC_UNCOR_ERROR (2 << 4)
  392. +
  393. +#define W25N01KV_STATUS_ECC_MASK (3 << 4)
  394. +#define W25N01KV_STATUS_ECC_NO_BITFLIPS (0 << 4)
  395. +#define W25N01KV_STATUS_ECC_1_3_BITFLIPS (1 << 4)
  396. +#define W25N01KV_STATUS_ECC_4_BITFLIPS (3 << 4)
  397. +#define W25N01KV_STATUS_ECC_UNCOR_ERROR (2 << 4)
  398. +
  399. static SPINAND_OP_VARIANTS(read_cache_variants,
  400. SPINAND_PAGE_READ_FROM_CACHE_QUADIO_OP(0, 2, NULL, 0),
  401. SPINAND_PAGE_READ_FROM_CACHE_X4_OP(0, 1, NULL, 0),
  402. @@ -34,6 +51,35 @@ static SPINAND_OP_VARIANTS(update_cache_
  403. SPINAND_PROG_LOAD_X4(false, 0, NULL, 0),
  404. SPINAND_PROG_LOAD(false, 0, NULL, 0));
  405. +static int w25n02kv_n04kv_ooblayout_ecc(struct mtd_info *mtd, int section,
  406. + struct mtd_oob_region *region)
  407. +{
  408. + if (section > 3)
  409. + return -ERANGE;
  410. +
  411. + region->offset = (16 * section) + 64;
  412. + region->length = 16;
  413. +
  414. + return 0;
  415. +}
  416. +
  417. +static int w25n02kv_n04kv_ooblayout_free(struct mtd_info *mtd, int section,
  418. + struct mtd_oob_region *region)
  419. +{
  420. + if (section > 3)
  421. + return -ERANGE;
  422. +
  423. + region->offset = (16 * section) + 2;
  424. + region->length = 14;
  425. +
  426. + return 0;
  427. +}
  428. +
  429. +static const struct mtd_ooblayout_ops w25n02kv_n04kv_ooblayout = {
  430. + .ecc = w25n02kv_n04kv_ooblayout_ecc,
  431. + .rfree = w25n02kv_n04kv_ooblayout_free,
  432. +};
  433. +
  434. static int w25m02gv_ooblayout_ecc(struct mtd_info *mtd, int section,
  435. struct mtd_oob_region *region)
  436. {
  437. @@ -106,6 +152,58 @@ static const struct mtd_ooblayout_ops w2
  438. .rfree = w25n02kv_ooblayout_free,
  439. };
  440. +static int w25n01kv_ecc_get_status(struct spinand_device *spinand,
  441. + u8 status)
  442. +{
  443. + switch (status & W25N01KV_STATUS_ECC_MASK) {
  444. + case W25N01KV_STATUS_ECC_NO_BITFLIPS:
  445. + return 0;
  446. +
  447. + case W25N01KV_STATUS_ECC_1_3_BITFLIPS:
  448. + return 3;
  449. +
  450. + case W25N01KV_STATUS_ECC_4_BITFLIPS:
  451. + return 4;
  452. +
  453. + case W25N01KV_STATUS_ECC_UNCOR_ERROR:
  454. + return -EBADMSG;
  455. +
  456. + default:
  457. + break;
  458. + }
  459. +
  460. + return -EINVAL;
  461. +}
  462. +
  463. +static int w25n02kv_n04kv_ecc_get_status(struct spinand_device *spinand,
  464. + u8 status)
  465. +{
  466. + switch (status & W25N02_N04KV_STATUS_ECC_MASK) {
  467. + case W25N02_N04KV_STATUS_ECC_NO_BITFLIPS:
  468. + return 0;
  469. +
  470. + case W25N02_N04KV_STATUS_ECC_1_4_BITFLIPS:
  471. + return 3;
  472. +
  473. + case W25N02_N04KV_STATUS_ECC_5_8_BITFLIPS:
  474. + return 4;
  475. +
  476. + /* W25N02_N04KV_use internal 8bit ECC algorithm.
  477. + * But the ECC strength is 4 bit requried.
  478. + * Return 3 if the bit bit flip count less than 5.
  479. + * Return 4 if the bit bit flip count more than 5 to 8.
  480. + */
  481. +
  482. + case W25N02_N04KV_STATUS_ECC_UNCOR_ERROR:
  483. + return -EBADMSG;
  484. +
  485. + default:
  486. + break;
  487. + }
  488. +
  489. + return -EINVAL;
  490. +}
  491. +
  492. static int w25n02kv_ecc_get_status(struct spinand_device *spinand,
  493. u8 status)
  494. {
  495. @@ -163,6 +261,15 @@ static const struct spinand_info winbond
  496. &update_cache_variants),
  497. 0,
  498. SPINAND_ECCINFO(&w25m02gv_ooblayout, NULL)),
  499. + SPINAND_INFO("W25N01KV",
  500. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xae, 0x21),
  501. + NAND_MEMORG(1, 2048, 64, 64, 1024, 20, 1, 1, 1),
  502. + NAND_ECCREQ(4, 512),
  503. + SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  504. + &write_cache_variants,
  505. + &update_cache_variants),
  506. + 0,
  507. + SPINAND_ECCINFO(&w25n02kv_n04kv_ooblayout, w25n01kv_ecc_get_status)),
  508. SPINAND_INFO("W25N02KV",
  509. SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xaa, 0x22),
  510. NAND_MEMORG(1, 2048, 128, 64, 2048, 40, 1, 1, 1),
  511. @@ -172,6 +279,16 @@ static const struct spinand_info winbond
  512. &update_cache_variants),
  513. 0,
  514. SPINAND_ECCINFO(&w25n02kv_ooblayout, w25n02kv_ecc_get_status)),
  515. + SPINAND_INFO("W25N04KV",
  516. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xaa, 0x23),
  517. + NAND_MEMORG(1, 2048, 128, 64, 4096, 80, 2, 1, 1),
  518. + NAND_ECCREQ(4, 512),
  519. + SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  520. + &write_cache_variants,
  521. + &update_cache_variants),
  522. + 0,
  523. + SPINAND_ECCINFO(&w25n02kv_n04kv_ooblayout,
  524. + w25n02kv_n04kv_ecc_get_status)),
  525. };
  526. static int winbond_spinand_init(struct spinand_device *spinand)
  527. --- a/include/linux/mtd/spinand.h
  528. +++ b/include/linux/mtd/spinand.h
  529. @@ -245,6 +245,7 @@ struct spinand_manufacturer {
  530. };
  531. /* SPI NAND manufacturers */
  532. +extern const struct spinand_manufacturer etron_spinand_manufacturer;
  533. extern const struct spinand_manufacturer gigadevice_spinand_manufacturer;
  534. extern const struct spinand_manufacturer macronix_spinand_manufacturer;
  535. extern const struct spinand_manufacturer micron_spinand_manufacturer;