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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550
  1. From a3c5878599d530330027412eb8be12f816ac215c 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 | 8 +
  9. drivers/mtd/nand/spi/core.c | 101 ++++++----
  10. drivers/mtd/nand/spi/gigadevice.c | 322 ++++++++++++++++++++++++++----
  11. drivers/mtd/nand/spi/macronix.c | 173 +++++++++++++---
  12. drivers/mtd/nand/spi/micron.c | 50 ++---
  13. drivers/mtd/nand/spi/toshiba.c | 66 +++---
  14. drivers/mtd/nand/spi/winbond.c | 171 +++++++++++++---
  15. include/linux/mtd/spinand.h | 86 +++++---
  16. 8 files changed, 753 insertions(+), 224 deletions(-)
  17. --- a/drivers/mtd/nand/spi/Kconfig
  18. +++ b/drivers/mtd/nand/spi/Kconfig
  19. @@ -5,3 +5,11 @@ menuconfig MTD_SPI_NAND
  20. select SPI_MEM
  21. help
  22. This is the framework for the SPI NAND device drivers.
  23. +
  24. +config MTD_SPI_NAND_W25N01KV
  25. + tristate "Winbond W25N01KV Support"
  26. + select MTD_SPI_NAND
  27. + default n
  28. + help
  29. + Winbond W25N01KV share the same ID with W25N01GV. However, they have
  30. + different attributes.
  31. --- a/drivers/mtd/nand/spi/core.c
  32. +++ b/drivers/mtd/nand/spi/core.c
  33. @@ -17,6 +17,7 @@
  34. #include <linux/mtd/spinand.h>
  35. #include <linux/of.h>
  36. #include <linux/slab.h>
  37. +#include <linux/string.h>
  38. #include <linux/spi/spi.h>
  39. #include <linux/spi/spi-mem.h>
  40. #else
  41. @@ -451,10 +452,11 @@ out:
  42. return status & STATUS_BUSY ? -ETIMEDOUT : 0;
  43. }
  44. -static int spinand_read_id_op(struct spinand_device *spinand, u8 *buf)
  45. +static int spinand_read_id_op(struct spinand_device *spinand, u8 naddr,
  46. + u8 ndummy, u8 *buf)
  47. {
  48. - struct spi_mem_op op = SPINAND_READID_OP(0, spinand->scratchbuf,
  49. - SPINAND_MAX_ID_LEN);
  50. + struct spi_mem_op op = SPINAND_READID_OP(
  51. + naddr, ndummy, spinand->scratchbuf, SPINAND_MAX_ID_LEN);
  52. int ret;
  53. ret = spi_mem_exec_op(spinand->slave, &op);
  54. @@ -464,18 +466,6 @@ static int spinand_read_id_op(struct spi
  55. return ret;
  56. }
  57. -static int spinand_reset_op(struct spinand_device *spinand)
  58. -{
  59. - struct spi_mem_op op = SPINAND_RESET_OP;
  60. - int ret;
  61. -
  62. - ret = spi_mem_exec_op(spinand->slave, &op);
  63. - if (ret)
  64. - return ret;
  65. -
  66. - return spinand_wait(spinand, NULL);
  67. -}
  68. -
  69. static int spinand_lock_block(struct spinand_device *spinand, u8 lock)
  70. {
  71. return spinand_write_reg_op(spinand, REG_BLOCK_LOCK, lock);
  72. @@ -836,24 +826,63 @@ static const struct spinand_manufacturer
  73. &winbond_spinand_manufacturer,
  74. };
  75. -static int spinand_manufacturer_detect(struct spinand_device *spinand)
  76. +static int spinand_manufacturer_match(struct spinand_device *spinand,
  77. + enum spinand_readid_method rdid_method)
  78. {
  79. + u8 *id = spinand->id.data;
  80. unsigned int i;
  81. int ret;
  82. for (i = 0; i < ARRAY_SIZE(spinand_manufacturers); i++) {
  83. - ret = spinand_manufacturers[i]->ops->detect(spinand);
  84. - if (ret > 0) {
  85. - spinand->manufacturer = spinand_manufacturers[i];
  86. - return 0;
  87. - } else if (ret < 0) {
  88. - return ret;
  89. - }
  90. + const struct spinand_manufacturer *manufacturer =
  91. + spinand_manufacturers[i];
  92. +
  93. + if (id[0] != manufacturer->id)
  94. + continue;
  95. +
  96. + ret = spinand_match_and_init(spinand,
  97. + manufacturer->chips,
  98. + manufacturer->nchips,
  99. + rdid_method);
  100. + if (ret < 0)
  101. + continue;
  102. +
  103. + spinand->manufacturer = manufacturer;
  104. + return 0;
  105. }
  106. return -ENOTSUPP;
  107. }
  108. +static int spinand_id_detect(struct spinand_device *spinand)
  109. +{
  110. + u8 *id = spinand->id.data;
  111. + int ret;
  112. +
  113. + ret = spinand_read_id_op(spinand, 0, 0, id);
  114. + if (ret)
  115. + return ret;
  116. + ret = spinand_manufacturer_match(spinand, SPINAND_READID_METHOD_OPCODE);
  117. + if (!ret)
  118. + return 0;
  119. +
  120. + ret = spinand_read_id_op(spinand, 1, 0, id);
  121. + if (ret)
  122. + return ret;
  123. + ret = spinand_manufacturer_match(spinand,
  124. + SPINAND_READID_METHOD_OPCODE_ADDR);
  125. + if (!ret)
  126. + return 0;
  127. +
  128. + ret = spinand_read_id_op(spinand, 0, 1, id);
  129. + if (ret)
  130. + return ret;
  131. + ret = spinand_manufacturer_match(spinand,
  132. + SPINAND_READID_METHOD_OPCODE_DUMMY);
  133. +
  134. + return ret;
  135. +}
  136. +
  137. static int spinand_manufacturer_init(struct spinand_device *spinand)
  138. {
  139. if (spinand->manufacturer->ops->init)
  140. @@ -909,9 +938,9 @@ spinand_select_op_variant(struct spinand
  141. * @spinand: SPI NAND object
  142. * @table: SPI NAND device description table
  143. * @table_size: size of the device description table
  144. + * @rdid_method: read id method to match
  145. *
  146. - * Should be used by SPI NAND manufacturer drivers when they want to find a
  147. - * match between a device ID retrieved through the READ_ID command and an
  148. + * Match between a device ID retrieved through the READ_ID command and an
  149. * entry in the SPI NAND description table. If a match is found, the spinand
  150. * object will be initialized with information provided by the matching
  151. * spinand_info entry.
  152. @@ -920,8 +949,10 @@ spinand_select_op_variant(struct spinand
  153. */
  154. int spinand_match_and_init(struct spinand_device *spinand,
  155. const struct spinand_info *table,
  156. - unsigned int table_size, u8 devid)
  157. + unsigned int table_size,
  158. + enum spinand_readid_method rdid_method)
  159. {
  160. + u8 *id = spinand->id.data;
  161. struct nand_device *nand = spinand_to_nand(spinand);
  162. unsigned int i;
  163. @@ -929,13 +960,17 @@ int spinand_match_and_init(struct spinan
  164. const struct spinand_info *info = &table[i];
  165. const struct spi_mem_op *op;
  166. - if (devid != info->devid)
  167. + if (rdid_method != info->devid.method)
  168. + continue;
  169. +
  170. + if (memcmp(id + 1, info->devid.id, info->devid.len))
  171. continue;
  172. nand->memorg = table[i].memorg;
  173. nand->eccreq = table[i].eccreq;
  174. spinand->eccinfo = table[i].eccinfo;
  175. spinand->flags = table[i].flags;
  176. + spinand->id.len = 1 + table[i].devid.len;
  177. spinand->select_target = table[i].select_target;
  178. op = spinand_select_op_variant(spinand,
  179. @@ -967,17 +1002,7 @@ static int spinand_detect(struct spinand
  180. struct nand_device *nand = spinand_to_nand(spinand);
  181. int ret;
  182. - ret = spinand_reset_op(spinand);
  183. - if (ret)
  184. - return ret;
  185. -
  186. - ret = spinand_read_id_op(spinand, spinand->id.data);
  187. - if (ret)
  188. - return ret;
  189. -
  190. - spinand->id.len = SPINAND_MAX_ID_LEN;
  191. -
  192. - ret = spinand_manufacturer_detect(spinand);
  193. + ret = spinand_id_detect(spinand);
  194. if (ret) {
  195. dev_err(spinand->slave->dev, "unknown raw ID %02x %02x %02x %02x\n",
  196. spinand->id.data[0], spinand->id.data[1],
  197. --- a/drivers/mtd/nand/spi/gigadevice.c
  198. +++ b/drivers/mtd/nand/spi/gigadevice.c
  199. @@ -22,8 +22,13 @@
  200. #define GD5FXGQXXEXXG_REG_STATUS2 0xf0
  201. +#define GD5FXGQ4UXFXXG_STATUS_ECC_MASK (7 << 4)
  202. +#define GD5FXGQ4UXFXXG_STATUS_ECC_NO_BITFLIPS (0 << 4)
  203. +#define GD5FXGQ4UXFXXG_STATUS_ECC_1_3_BITFLIPS (1 << 4)
  204. +#define GD5FXGQ4UXFXXG_STATUS_ECC_UNCOR_ERROR (7 << 4)
  205. +
  206. /* Q4 devices, QUADIO: Dummy bytes valid for 1 and 2 GBit variants */
  207. -static SPINAND_OP_VARIANTS(gd5fxgq4_read_cache_variants,
  208. +static SPINAND_OP_VARIANTS(read_cache_variants,
  209. SPINAND_PAGE_READ_FROM_CACHE_QUADIO_OP(0, 1, NULL, 0),
  210. SPINAND_PAGE_READ_FROM_CACHE_X4_OP(0, 1, NULL, 0),
  211. SPINAND_PAGE_READ_FROM_CACHE_DUALIO_OP(0, 1, NULL, 0),
  212. @@ -31,8 +36,17 @@ static SPINAND_OP_VARIANTS(gd5fxgq4_read
  213. SPINAND_PAGE_READ_FROM_CACHE_OP(true, 0, 1, NULL, 0),
  214. SPINAND_PAGE_READ_FROM_CACHE_OP(false, 0, 1, NULL, 0));
  215. -/* Q5 devices, QUADIO: Dummy bytes only valid for 1 GBit variants */
  216. -static SPINAND_OP_VARIANTS(gd5f1gq5_read_cache_variants,
  217. +static SPINAND_OP_VARIANTS(read_cache_variants_f,
  218. + SPINAND_PAGE_READ_FROM_CACHE_QUADIO_OP(0, 1, NULL, 0),
  219. + SPINAND_PAGE_READ_FROM_CACHE_X4_OP_3A(0, 1, NULL, 0),
  220. + SPINAND_PAGE_READ_FROM_CACHE_DUALIO_OP(0, 1, NULL, 0),
  221. + SPINAND_PAGE_READ_FROM_CACHE_X2_OP_3A(0, 1, NULL, 0),
  222. + SPINAND_PAGE_READ_FROM_CACHE_OP_3A(true, 0, 1, NULL, 0),
  223. + SPINAND_PAGE_READ_FROM_CACHE_OP_3A(false, 0, 0, NULL, 0));
  224. +
  225. +/* For Q5 devices, QUADIO use different dummy byte settings */
  226. +/* Q5 1Gb */
  227. +static SPINAND_OP_VARIANTS(dummy2_read_cache_variants,
  228. SPINAND_PAGE_READ_FROM_CACHE_QUADIO_OP(0, 2, NULL, 0),
  229. SPINAND_PAGE_READ_FROM_CACHE_X4_OP(0, 1, NULL, 0),
  230. SPINAND_PAGE_READ_FROM_CACHE_DUALIO_OP(0, 1, NULL, 0),
  231. @@ -40,6 +54,15 @@ static SPINAND_OP_VARIANTS(gd5f1gq5_read
  232. SPINAND_PAGE_READ_FROM_CACHE_OP(true, 0, 1, NULL, 0),
  233. SPINAND_PAGE_READ_FROM_CACHE_OP(false, 0, 1, NULL, 0));
  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. @@ -48,7 +71,65 @@ static SPINAND_OP_VARIANTS(update_cache_
  247. SPINAND_PROG_LOAD_X4(false, 0, NULL, 0),
  248. SPINAND_PROG_LOAD(false, 0, NULL, 0));
  249. -static int gd5fxgqxxexxg_ooblayout_ecc(struct mtd_info *mtd, int section,
  250. +static int gd5fxgq4xa_ooblayout_ecc(struct mtd_info *mtd, int section,
  251. + struct mtd_oob_region *region)
  252. +{
  253. + if (section > 3)
  254. + return -ERANGE;
  255. +
  256. + region->offset = (16 * section) + 8;
  257. + region->length = 8;
  258. +
  259. + return 0;
  260. +}
  261. +
  262. +static int gd5fxgq4xa_ooblayout_free(struct mtd_info *mtd, int section,
  263. + struct mtd_oob_region *region)
  264. +{
  265. + if (section > 3)
  266. + return -ERANGE;
  267. +
  268. + if (section) {
  269. + region->offset = 16 * section;
  270. + region->length = 8;
  271. + } else {
  272. + /* section 0 has one byte reserved for bad block mark */
  273. + region->offset = 1;
  274. + region->length = 7;
  275. + }
  276. + return 0;
  277. +}
  278. +
  279. +static const struct mtd_ooblayout_ops gd5fxgq4xa_ooblayout = {
  280. + .ecc = gd5fxgq4xa_ooblayout_ecc,
  281. + .rfree = gd5fxgq4xa_ooblayout_free,
  282. +};
  283. +
  284. +static int gd5fxgq4xa_ecc_get_status(struct spinand_device *spinand,
  285. + u8 status)
  286. +{
  287. + switch (status & STATUS_ECC_MASK) {
  288. + case STATUS_ECC_NO_BITFLIPS:
  289. + return 0;
  290. +
  291. + case GD5FXGQ4XA_STATUS_ECC_1_7_BITFLIPS:
  292. + /* 1-7 bits are flipped. return the maximum. */
  293. + return 7;
  294. +
  295. + case GD5FXGQ4XA_STATUS_ECC_8_BITFLIPS:
  296. + return 8;
  297. +
  298. + case STATUS_ECC_UNCOR_ERROR:
  299. + return -EBADMSG;
  300. +
  301. + default:
  302. + break;
  303. + }
  304. +
  305. + return -EINVAL;
  306. +}
  307. +
  308. +static int gd5fxgqx_variant2_ooblayout_ecc(struct mtd_info *mtd, int section,
  309. struct mtd_oob_region *region)
  310. {
  311. if (section)
  312. @@ -60,7 +141,7 @@ static int gd5fxgqxxexxg_ooblayout_ecc(s
  313. return 0;
  314. }
  315. -static int gd5fxgqxxexxg_ooblayout_free(struct mtd_info *mtd, int section,
  316. +static int gd5fxgqx_variant2_ooblayout_free(struct mtd_info *mtd, int section,
  317. struct mtd_oob_region *region)
  318. {
  319. if (section)
  320. @@ -73,7 +154,13 @@ static int gd5fxgqxxexxg_ooblayout_free(
  321. return 0;
  322. }
  323. -static int gd5fxgq4xexxg_ecc_get_status(struct spinand_device *spinand,
  324. +/* Valid for Q4/Q5 and Q6 (untested) devices */
  325. +static const struct mtd_ooblayout_ops gd5fxgqx_variant2_ooblayout = {
  326. + .ecc = gd5fxgqx_variant2_ooblayout_ecc,
  327. + .rfree = gd5fxgqx_variant2_ooblayout_free,
  328. +};
  329. +
  330. +static int gd5fxgq4uexxg_ecc_get_status(struct spinand_device *spinand,
  331. u8 status)
  332. {
  333. u8 status2;
  334. @@ -152,59 +239,214 @@ static int gd5fxgq5xexxg_ecc_get_status(
  335. return -EINVAL;
  336. }
  337. -static const struct mtd_ooblayout_ops gd5fxgqxxexxg_ooblayout = {
  338. - .ecc = gd5fxgqxxexxg_ooblayout_ecc,
  339. - .rfree = gd5fxgqxxexxg_ooblayout_free,
  340. +static int gd5fxgq4ufxxg_ecc_get_status(struct spinand_device *spinand,
  341. + u8 status)
  342. +{
  343. + switch (status & GD5FXGQ4UXFXXG_STATUS_ECC_MASK) {
  344. + case GD5FXGQ4UXFXXG_STATUS_ECC_NO_BITFLIPS:
  345. + return 0;
  346. +
  347. + case GD5FXGQ4UXFXXG_STATUS_ECC_1_3_BITFLIPS:
  348. + return 3;
  349. +
  350. + case GD5FXGQ4UXFXXG_STATUS_ECC_UNCOR_ERROR:
  351. + return -EBADMSG;
  352. +
  353. + default: /* (2 << 4) through (6 << 4) are 4-8 corrected errors */
  354. + return ((status & GD5FXGQ4UXFXXG_STATUS_ECC_MASK) >> 4) + 2;
  355. + }
  356. +
  357. + return -EINVAL;
  358. +}
  359. +
  360. +static int esmt_1_ooblayout_ecc(struct mtd_info *mtd, int section,
  361. + struct mtd_oob_region *region)
  362. +{
  363. + if (section > 3)
  364. + return -ERANGE;
  365. +
  366. + region->offset = (16 * section) + 8;
  367. + region->length = 8;
  368. +
  369. + return 0;
  370. +}
  371. +
  372. +static int esmt_1_ooblayout_free(struct mtd_info *mtd, int section,
  373. + struct mtd_oob_region *region)
  374. +{
  375. + if (section > 3)
  376. + return -ERANGE;
  377. +
  378. + region->offset = (16 * section) + 2;
  379. + region->length = 6;
  380. +
  381. + return 0;
  382. +}
  383. +
  384. +static const struct mtd_ooblayout_ops esmt_1_ooblayout = {
  385. + .ecc = esmt_1_ooblayout_ecc,
  386. + .rfree = esmt_1_ooblayout_free,
  387. };
  388. static const struct spinand_info gigadevice_spinand_table[] = {
  389. - SPINAND_INFO("GD5F1GQ4UExxG", 0xd1,
  390. - NAND_MEMORG(1, 2048, 128, 64, 1024, 1, 1, 1),
  391. + SPINAND_INFO("F50L1G41LB",
  392. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_ADDR, 0x01),
  393. + NAND_MEMORG(1, 2048, 64, 64, 1024, 1, 1, 1),
  394. NAND_ECCREQ(8, 512),
  395. - SPINAND_INFO_OP_VARIANTS(&gd5fxgq4_read_cache_variants,
  396. + SPINAND_INFO_OP_VARIANTS(&dummy2_read_cache_variants,
  397. &write_cache_variants,
  398. &update_cache_variants),
  399. 0,
  400. - SPINAND_ECCINFO(&gd5fxgqxxexxg_ooblayout,
  401. - gd5fxgq4xexxg_ecc_get_status)),
  402. - SPINAND_INFO("GD5F1GQ5UExxG", 0x51,
  403. + SPINAND_ECCINFO(&esmt_1_ooblayout, NULL)),
  404. + SPINAND_INFO("GD5F1GQ4xA",
  405. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_ADDR, 0xf1),
  406. + NAND_MEMORG(1, 2048, 64, 64, 1024, 1, 1, 1),
  407. + NAND_ECCREQ(8, 512),
  408. + SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  409. + &write_cache_variants,
  410. + &update_cache_variants),
  411. + SPINAND_HAS_QE_BIT,
  412. + SPINAND_ECCINFO(&gd5fxgq4xa_ooblayout,
  413. + gd5fxgq4xa_ecc_get_status)),
  414. + SPINAND_INFO("GD5F2GQ4xA",
  415. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_ADDR, 0xf2),
  416. + NAND_MEMORG(1, 2048, 64, 64, 2048, 1, 1, 1),
  417. + NAND_ECCREQ(8, 512),
  418. + SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  419. + &write_cache_variants,
  420. + &update_cache_variants),
  421. + SPINAND_HAS_QE_BIT,
  422. + SPINAND_ECCINFO(&gd5fxgq4xa_ooblayout,
  423. + gd5fxgq4xa_ecc_get_status)),
  424. + SPINAND_INFO("GD5F4GQ4xA",
  425. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_ADDR, 0xf4),
  426. + NAND_MEMORG(1, 2048, 64, 64, 4096, 1, 1, 1),
  427. + NAND_ECCREQ(8, 512),
  428. + SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  429. + &write_cache_variants,
  430. + &update_cache_variants),
  431. + SPINAND_HAS_QE_BIT,
  432. + SPINAND_ECCINFO(&gd5fxgq4xa_ooblayout,
  433. + gd5fxgq4xa_ecc_get_status)),
  434. + SPINAND_INFO("GD5F1GQ4UExxG",
  435. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_ADDR, 0xd1),
  436. + NAND_MEMORG(1, 2048, 128, 64, 1024, 1, 1, 1),
  437. + NAND_ECCREQ(8, 512),
  438. + SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  439. + &write_cache_variants,
  440. + &update_cache_variants),
  441. + SPINAND_HAS_QE_BIT,
  442. + SPINAND_ECCINFO(&gd5fxgqx_variant2_ooblayout,
  443. + gd5fxgq4uexxg_ecc_get_status)),
  444. + SPINAND_INFO("GD5F1GQ4UFxxG",
  445. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE, 0xb1, 0x48),
  446. + NAND_MEMORG(1, 2048, 128, 64, 1024, 1, 1, 1),
  447. + NAND_ECCREQ(8, 512),
  448. + SPINAND_INFO_OP_VARIANTS(&read_cache_variants_f,
  449. + &write_cache_variants,
  450. + &update_cache_variants),
  451. + SPINAND_HAS_QE_BIT,
  452. + SPINAND_ECCINFO(&gd5fxgqx_variant2_ooblayout,
  453. + gd5fxgq4ufxxg_ecc_get_status)),
  454. + SPINAND_INFO("GD5F1GQ5UExxG",
  455. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x51),
  456. NAND_MEMORG(1, 2048, 128, 64, 1024, 1, 1, 1),
  457. NAND_ECCREQ(4, 512),
  458. - SPINAND_INFO_OP_VARIANTS(&gd5f1gq5_read_cache_variants,
  459. + SPINAND_INFO_OP_VARIANTS(&dummy2_read_cache_variants,
  460. &write_cache_variants,
  461. &update_cache_variants),
  462. - 0,
  463. - SPINAND_ECCINFO(&gd5fxgqxxexxg_ooblayout,
  464. + SPINAND_HAS_QE_BIT,
  465. + SPINAND_ECCINFO(&gd5fxgqx_variant2_ooblayout,
  466. + gd5fxgq5xexxg_ecc_get_status)),
  467. + SPINAND_INFO("GD5F2GQ5UExxG",
  468. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_ADDR, 0x52),
  469. + NAND_MEMORG(1, 2048, 128, 64, 2048, 1, 1, 1),
  470. + NAND_ECCREQ(4, 512),
  471. + SPINAND_INFO_OP_VARIANTS(&dummy4_read_cache_variants,
  472. + &write_cache_variants,
  473. + &update_cache_variants),
  474. + SPINAND_HAS_QE_BIT,
  475. + SPINAND_ECCINFO(&gd5fxgqx_variant2_ooblayout,
  476. + gd5fxgq5xexxg_ecc_get_status)),
  477. + SPINAND_INFO("GD5F4GQ6UExxG",
  478. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_ADDR, 0x55),
  479. + NAND_MEMORG(1, 2048, 128, 64, 4096, 1, 1, 1),
  480. + NAND_ECCREQ(4, 512),
  481. + SPINAND_INFO_OP_VARIANTS(&dummy4_read_cache_variants,
  482. + &write_cache_variants,
  483. + &update_cache_variants),
  484. + SPINAND_HAS_QE_BIT,
  485. + SPINAND_ECCINFO(&gd5fxgqx_variant2_ooblayout,
  486. + gd5fxgq5xexxg_ecc_get_status)),
  487. + SPINAND_INFO("GD5F1GM7UExxG",
  488. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_ADDR, 0x91),
  489. + NAND_MEMORG(1, 2048, 128, 64, 1024, 1, 1, 1),
  490. + NAND_ECCREQ(8, 512),
  491. + SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  492. + &write_cache_variants,
  493. + &update_cache_variants),
  494. + SPINAND_HAS_QE_BIT,
  495. + SPINAND_ECCINFO(&gd5fxgqx_variant2_ooblayout,
  496. + gd5fxgq4uexxg_ecc_get_status)),
  497. + SPINAND_INFO("GD5F2GM7UExxG",
  498. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_ADDR, 0x92),
  499. + NAND_MEMORG(1, 2048, 128, 64, 2048, 1, 1, 1),
  500. + NAND_ECCREQ(8, 512),
  501. + SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  502. + &write_cache_variants,
  503. + &update_cache_variants),
  504. + SPINAND_HAS_QE_BIT,
  505. + SPINAND_ECCINFO(&gd5fxgqx_variant2_ooblayout,
  506. + gd5fxgq4uexxg_ecc_get_status)),
  507. + SPINAND_INFO("GD5F4GM8UExxG",
  508. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_ADDR, 0x95),
  509. + NAND_MEMORG(1, 2048, 128, 64, 4096, 1, 1, 1),
  510. + NAND_ECCREQ(8, 512),
  511. + SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  512. + &write_cache_variants,
  513. + &update_cache_variants),
  514. + SPINAND_HAS_QE_BIT,
  515. + SPINAND_ECCINFO(&gd5fxgqx_variant2_ooblayout,
  516. + gd5fxgq4uexxg_ecc_get_status)),
  517. + SPINAND_INFO("GD5F1GQ5UExxH",
  518. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x31),
  519. + NAND_MEMORG(1, 2048, 64, 64, 1024, 1, 1, 1),
  520. + NAND_ECCREQ(4, 512),
  521. + SPINAND_INFO_OP_VARIANTS(&dummy2_read_cache_variants,
  522. + &write_cache_variants,
  523. + &update_cache_variants),
  524. + SPINAND_HAS_QE_BIT,
  525. + SPINAND_ECCINFO(&gd5fxgqx_variant2_ooblayout,
  526. + gd5fxgq5xexxg_ecc_get_status)),
  527. + SPINAND_INFO("GD5F2GQ5UExxH",
  528. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x32),
  529. + NAND_MEMORG(1, 2048, 64, 64, 2048, 1, 1, 1),
  530. + NAND_ECCREQ(4, 512),
  531. + SPINAND_INFO_OP_VARIANTS(&dummy4_read_cache_variants,
  532. + &write_cache_variants,
  533. + &update_cache_variants),
  534. + SPINAND_HAS_QE_BIT,
  535. + SPINAND_ECCINFO(&gd5fxgqx_variant2_ooblayout,
  536. + gd5fxgq5xexxg_ecc_get_status)),
  537. + SPINAND_INFO("GD5F4GQ6UExxH",
  538. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x35),
  539. + NAND_MEMORG(1, 2048, 64, 64, 4096, 1, 1, 1),
  540. + NAND_ECCREQ(4, 512),
  541. + SPINAND_INFO_OP_VARIANTS(&dummy4_read_cache_variants,
  542. + &write_cache_variants,
  543. + &update_cache_variants),
  544. + SPINAND_HAS_QE_BIT,
  545. + SPINAND_ECCINFO(&gd5fxgqx_variant2_ooblayout,
  546. gd5fxgq5xexxg_ecc_get_status)),
  547. };
  548. -static int gigadevice_spinand_detect(struct spinand_device *spinand)
  549. -{
  550. - u8 *id = spinand->id.data;
  551. - int ret;
  552. -
  553. - /*
  554. - * For GD NANDs, There is an address byte needed to shift in before IDs
  555. - * are read out, so the first byte in raw_id is dummy.
  556. - */
  557. - if (id[1] != SPINAND_MFR_GIGADEVICE)
  558. - return 0;
  559. -
  560. - ret = spinand_match_and_init(spinand, gigadevice_spinand_table,
  561. - ARRAY_SIZE(gigadevice_spinand_table),
  562. - id[2]);
  563. - if (ret)
  564. - return ret;
  565. -
  566. - return 1;
  567. -}
  568. -
  569. static const struct spinand_manufacturer_ops gigadevice_spinand_manuf_ops = {
  570. - .detect = gigadevice_spinand_detect,
  571. };
  572. const struct spinand_manufacturer gigadevice_spinand_manufacturer = {
  573. .id = SPINAND_MFR_GIGADEVICE,
  574. .name = "GigaDevice",
  575. + .chips = gigadevice_spinand_table,
  576. + .nchips = ARRAY_SIZE(gigadevice_spinand_table),
  577. .ops = &gigadevice_spinand_manuf_ops,
  578. };
  579. --- a/drivers/mtd/nand/spi/macronix.c
  580. +++ b/drivers/mtd/nand/spi/macronix.c
  581. @@ -105,7 +105,8 @@ static int mx35lf1ge4ab_ecc_get_status(s
  582. }
  583. static const struct spinand_info macronix_spinand_table[] = {
  584. - SPINAND_INFO("MX35LF1GE4AB", 0x12,
  585. + SPINAND_INFO("MX35LF1GE4AB",
  586. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x12),
  587. NAND_MEMORG(1, 2048, 64, 64, 1024, 1, 1, 1),
  588. NAND_ECCREQ(4, 512),
  589. SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  590. @@ -114,7 +115,8 @@ static const struct spinand_info macroni
  591. SPINAND_HAS_QE_BIT,
  592. SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout,
  593. mx35lf1ge4ab_ecc_get_status)),
  594. - SPINAND_INFO("MX35LF2GE4AB", 0x22,
  595. + SPINAND_INFO("MX35LF2GE4AB",
  596. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x22),
  597. NAND_MEMORG(1, 2048, 64, 64, 2048, 2, 1, 1),
  598. NAND_ECCREQ(4, 512),
  599. SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  600. @@ -122,7 +124,96 @@ static const struct spinand_info macroni
  601. &update_cache_variants),
  602. SPINAND_HAS_QE_BIT,
  603. SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout, NULL)),
  604. - SPINAND_INFO("MX35UF4GE4AD", 0xb7,
  605. + SPINAND_INFO("MX35LF2GE4AD",
  606. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x26),
  607. + NAND_MEMORG(1, 2048, 64, 64, 2048, 1, 1, 1),
  608. + NAND_ECCREQ(8, 512),
  609. + SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  610. + &write_cache_variants,
  611. + &update_cache_variants),
  612. + SPINAND_HAS_QE_BIT,
  613. + SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout,
  614. + mx35lf1ge4ab_ecc_get_status)),
  615. + SPINAND_INFO("MX35LF4GE4AD",
  616. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x37),
  617. + NAND_MEMORG(1, 4096, 128, 64, 2048, 1, 1, 1),
  618. + NAND_ECCREQ(8, 512),
  619. + SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  620. + &write_cache_variants,
  621. + &update_cache_variants),
  622. + SPINAND_HAS_QE_BIT,
  623. + SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout,
  624. + mx35lf1ge4ab_ecc_get_status)),
  625. + SPINAND_INFO("MX35LF1G24AD",
  626. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x14),
  627. + NAND_MEMORG(1, 2048, 128, 64, 1024, 1, 1, 1),
  628. + NAND_ECCREQ(8, 512),
  629. + SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  630. + &write_cache_variants,
  631. + &update_cache_variants),
  632. + SPINAND_HAS_QE_BIT,
  633. + SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout, NULL)),
  634. + SPINAND_INFO("MX35LF2G24AD",
  635. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x24),
  636. + NAND_MEMORG(1, 2048, 128, 64, 2048, 2, 1, 1),
  637. + NAND_ECCREQ(8, 512),
  638. + SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  639. + &write_cache_variants,
  640. + &update_cache_variants),
  641. + SPINAND_HAS_QE_BIT,
  642. + SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout, NULL)),
  643. + SPINAND_INFO("MX35LF4G24AD",
  644. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x35),
  645. + NAND_MEMORG(1, 4096, 256, 64, 2048, 2, 1, 1),
  646. + NAND_ECCREQ(8, 512),
  647. + SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  648. + &write_cache_variants,
  649. + &update_cache_variants),
  650. + SPINAND_HAS_QE_BIT,
  651. + SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout, NULL)),
  652. + SPINAND_INFO("MX31LF1GE4BC",
  653. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x1e),
  654. + NAND_MEMORG(1, 2048, 64, 64, 1024, 1, 1, 1),
  655. + NAND_ECCREQ(8, 512),
  656. + SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  657. + &write_cache_variants,
  658. + &update_cache_variants),
  659. + SPINAND_HAS_QE_BIT,
  660. + SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout,
  661. + mx35lf1ge4ab_ecc_get_status)),
  662. + SPINAND_INFO("MX31UF1GE4BC",
  663. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x9e),
  664. + NAND_MEMORG(1, 2048, 64, 64, 1024, 1, 1, 1),
  665. + NAND_ECCREQ(8, 512),
  666. + SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  667. + &write_cache_variants,
  668. + &update_cache_variants),
  669. + SPINAND_HAS_QE_BIT,
  670. + SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout,
  671. + mx35lf1ge4ab_ecc_get_status)),
  672. +
  673. + SPINAND_INFO("MX35LF2G14AC",
  674. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x20),
  675. + NAND_MEMORG(1, 2048, 64, 64, 2048, 2, 1, 1),
  676. + NAND_ECCREQ(4, 512),
  677. + SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  678. + &write_cache_variants,
  679. + &update_cache_variants),
  680. + SPINAND_HAS_QE_BIT,
  681. + SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout,
  682. + mx35lf1ge4ab_ecc_get_status)),
  683. + SPINAND_INFO("MX35UF4G24AD",
  684. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xb5),
  685. + NAND_MEMORG(1, 4096, 256, 64, 2048, 2, 1, 1),
  686. + NAND_ECCREQ(8, 512),
  687. + SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  688. + &write_cache_variants,
  689. + &update_cache_variants),
  690. + SPINAND_HAS_QE_BIT,
  691. + SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout,
  692. + mx35lf1ge4ab_ecc_get_status)),
  693. + SPINAND_INFO("MX35UF4GE4AD",
  694. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xb7),
  695. NAND_MEMORG(1, 4096, 256, 64, 2048, 1, 1, 1),
  696. NAND_ECCREQ(8, 512),
  697. SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  698. @@ -131,7 +222,28 @@ static const struct spinand_info macroni
  699. SPINAND_HAS_QE_BIT,
  700. SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout,
  701. mx35lf1ge4ab_ecc_get_status)),
  702. - SPINAND_INFO("MX35UF2GE4AD", 0xa6,
  703. + SPINAND_INFO("MX35UF2G14AC",
  704. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xa0),
  705. + NAND_MEMORG(1, 2048, 64, 64, 2048, 2, 1, 1),
  706. + NAND_ECCREQ(4, 512),
  707. + SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  708. + &write_cache_variants,
  709. + &update_cache_variants),
  710. + SPINAND_HAS_QE_BIT,
  711. + SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout,
  712. + mx35lf1ge4ab_ecc_get_status)),
  713. + SPINAND_INFO("MX35UF2G24AD",
  714. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xa4),
  715. + NAND_MEMORG(1, 2048, 128, 64, 2048, 2, 1, 1),
  716. + NAND_ECCREQ(8, 512),
  717. + SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  718. + &write_cache_variants,
  719. + &update_cache_variants),
  720. + SPINAND_HAS_QE_BIT,
  721. + SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout,
  722. + mx35lf1ge4ab_ecc_get_status)),
  723. + SPINAND_INFO("MX35UF2GE4AD",
  724. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xa6),
  725. NAND_MEMORG(1, 2048, 128, 64, 2048, 1, 1, 1),
  726. NAND_ECCREQ(8, 512),
  727. SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  728. @@ -140,16 +252,28 @@ static const struct spinand_info macroni
  729. SPINAND_HAS_QE_BIT,
  730. SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout,
  731. mx35lf1ge4ab_ecc_get_status)),
  732. - SPINAND_INFO("MX35UF2GE4AC", 0xa2,
  733. + SPINAND_INFO("MX35UF2GE4AC",
  734. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xa2),
  735. NAND_MEMORG(1, 2048, 64, 64, 2048, 1, 1, 1),
  736. NAND_ECCREQ(4, 512),
  737. + SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  738. + &write_cache_variants,
  739. + &update_cache_variants),
  740. + SPINAND_HAS_QE_BIT,
  741. + SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout,
  742. + mx35lf1ge4ab_ecc_get_status)),
  743. + SPINAND_INFO("MX35UF1G14AC",
  744. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x90),
  745. + NAND_MEMORG(1, 2048, 64, 64, 1024, 1, 1, 1),
  746. + NAND_ECCREQ(4, 512),
  747. SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  748. &write_cache_variants,
  749. &update_cache_variants),
  750. SPINAND_HAS_QE_BIT,
  751. SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout,
  752. mx35lf1ge4ab_ecc_get_status)),
  753. - SPINAND_INFO("MX35UF1GE4AD", 0x96,
  754. + SPINAND_INFO("MX35UF1G24AD",
  755. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x94),
  756. NAND_MEMORG(1, 2048, 128, 64, 1024, 1, 1, 1),
  757. NAND_ECCREQ(8, 512),
  758. SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  759. @@ -158,7 +282,18 @@ static const struct spinand_info macroni
  760. SPINAND_HAS_QE_BIT,
  761. SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout,
  762. mx35lf1ge4ab_ecc_get_status)),
  763. - SPINAND_INFO("MX35UF1GE4AC", 0x92,
  764. + SPINAND_INFO("MX35UF1GE4AD",
  765. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x96),
  766. + NAND_MEMORG(1, 2048, 128, 64, 1024, 1, 1, 1),
  767. + NAND_ECCREQ(8, 512),
  768. + SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  769. + &write_cache_variants,
  770. + &update_cache_variants),
  771. + SPINAND_HAS_QE_BIT,
  772. + SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout,
  773. + mx35lf1ge4ab_ecc_get_status)),
  774. + SPINAND_INFO("MX35UF1GE4AC",
  775. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x92),
  776. NAND_MEMORG(1, 2048, 64, 64, 1024, 1, 1, 1),
  777. NAND_ECCREQ(4, 512),
  778. SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  779. @@ -170,33 +305,13 @@ static const struct spinand_info macroni
  780. };
  781. -static int macronix_spinand_detect(struct spinand_device *spinand)
  782. -{
  783. - u8 *id = spinand->id.data;
  784. - int ret;
  785. -
  786. - /*
  787. - * Macronix SPI NAND read ID needs a dummy byte, so the first byte in
  788. - * raw_id is garbage.
  789. - */
  790. - if (id[1] != SPINAND_MFR_MACRONIX)
  791. - return 0;
  792. -
  793. - ret = spinand_match_and_init(spinand, macronix_spinand_table,
  794. - ARRAY_SIZE(macronix_spinand_table),
  795. - id[2]);
  796. - if (ret)
  797. - return ret;
  798. -
  799. - return 1;
  800. -}
  801. -
  802. static const struct spinand_manufacturer_ops macronix_spinand_manuf_ops = {
  803. - .detect = macronix_spinand_detect,
  804. };
  805. const struct spinand_manufacturer macronix_spinand_manufacturer = {
  806. .id = SPINAND_MFR_MACRONIX,
  807. .name = "Macronix",
  808. + .chips = macronix_spinand_table,
  809. + .nchips = ARRAY_SIZE(macronix_spinand_table),
  810. .ops = &macronix_spinand_manuf_ops,
  811. };
  812. --- a/drivers/mtd/nand/spi/micron.c
  813. +++ b/drivers/mtd/nand/spi/micron.c
  814. @@ -120,7 +120,8 @@ static int micron_8_ecc_get_status(struc
  815. static const struct spinand_info micron_spinand_table[] = {
  816. /* M79A 2Gb 3.3V */
  817. - SPINAND_INFO("MT29F2G01ABAGD", 0x24,
  818. + SPINAND_INFO("MT29F2G01ABAGD",
  819. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x24),
  820. NAND_MEMORG(1, 2048, 128, 64, 2048, 2, 1, 1),
  821. NAND_ECCREQ(8, 512),
  822. SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  823. @@ -130,7 +131,8 @@ static const struct spinand_info micron_
  824. SPINAND_ECCINFO(&micron_8_ooblayout,
  825. micron_8_ecc_get_status)),
  826. /* M79A 2Gb 1.8V */
  827. - SPINAND_INFO("MT29F2G01ABBGD", 0x25,
  828. + SPINAND_INFO("MT29F2G01ABBGD",
  829. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x25),
  830. NAND_MEMORG(1, 2048, 128, 64, 2048, 2, 1, 1),
  831. NAND_ECCREQ(8, 512),
  832. SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  833. @@ -140,7 +142,8 @@ static const struct spinand_info micron_
  834. SPINAND_ECCINFO(&micron_8_ooblayout,
  835. micron_8_ecc_get_status)),
  836. /* M78A 1Gb 3.3V */
  837. - SPINAND_INFO("MT29F1G01ABAFD", 0x14,
  838. + SPINAND_INFO("MT29F1G01ABAFD",
  839. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x14),
  840. NAND_MEMORG(1, 2048, 128, 64, 1024, 1, 1, 1),
  841. NAND_ECCREQ(8, 512),
  842. SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  843. @@ -150,7 +153,8 @@ static const struct spinand_info micron_
  844. SPINAND_ECCINFO(&micron_8_ooblayout,
  845. micron_8_ecc_get_status)),
  846. /* M78A 1Gb 1.8V */
  847. - SPINAND_INFO("MT29F1G01ABAFD", 0x15,
  848. + SPINAND_INFO("MT29F1G01ABAFD",
  849. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x15),
  850. NAND_MEMORG(1, 2048, 128, 64, 1024, 1, 1, 1),
  851. NAND_ECCREQ(8, 512),
  852. SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  853. @@ -160,7 +164,8 @@ static const struct spinand_info micron_
  854. SPINAND_ECCINFO(&micron_8_ooblayout,
  855. micron_8_ecc_get_status)),
  856. /* M79A 4Gb 3.3V */
  857. - SPINAND_INFO("MT29F4G01ADAGD", 0x36,
  858. + SPINAND_INFO("MT29F4G01ADAGD",
  859. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x36),
  860. NAND_MEMORG(1, 2048, 128, 64, 2048, 2, 1, 2),
  861. NAND_ECCREQ(8, 512),
  862. SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  863. @@ -171,7 +176,8 @@ static const struct spinand_info micron_
  864. micron_8_ecc_get_status),
  865. SPINAND_SELECT_TARGET(micron_select_target)),
  866. /* M70A 4Gb 3.3V */
  867. - SPINAND_INFO("MT29F4G01ABAFD", 0x34,
  868. + SPINAND_INFO("MT29F4G01ABAFD",
  869. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x34),
  870. NAND_MEMORG(1, 4096, 256, 64, 2048, 1, 1, 1),
  871. NAND_ECCREQ(8, 512),
  872. SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  873. @@ -181,7 +187,8 @@ static const struct spinand_info micron_
  874. SPINAND_ECCINFO(&micron_8_ooblayout,
  875. micron_8_ecc_get_status)),
  876. /* M70A 4Gb 1.8V */
  877. - SPINAND_INFO("MT29F4G01ABBFD", 0x35,
  878. + SPINAND_INFO("MT29F4G01ABBFD",
  879. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x35),
  880. NAND_MEMORG(1, 4096, 256, 64, 2048, 1, 1, 1),
  881. NAND_ECCREQ(8, 512),
  882. SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  883. @@ -191,7 +198,8 @@ static const struct spinand_info micron_
  884. SPINAND_ECCINFO(&micron_8_ooblayout,
  885. micron_8_ecc_get_status)),
  886. /* M70A 8Gb 3.3V */
  887. - SPINAND_INFO("MT29F8G01ADAFD", 0x46,
  888. + SPINAND_INFO("MT29F8G01ADAFD",
  889. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x46),
  890. NAND_MEMORG(1, 4096, 256, 64, 2048, 1, 1, 2),
  891. NAND_ECCREQ(8, 512),
  892. SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  893. @@ -202,7 +210,8 @@ static const struct spinand_info micron_
  894. micron_8_ecc_get_status),
  895. SPINAND_SELECT_TARGET(micron_select_target)),
  896. /* M70A 8Gb 1.8V */
  897. - SPINAND_INFO("MT29F8G01ADBFD", 0x47,
  898. + SPINAND_INFO("MT29F8G01ADBFD",
  899. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x47),
  900. NAND_MEMORG(1, 4096, 256, 64, 2048, 1, 1, 2),
  901. NAND_ECCREQ(8, 512),
  902. SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  903. @@ -214,26 +223,6 @@ static const struct spinand_info micron_
  904. SPINAND_SELECT_TARGET(micron_select_target)),
  905. };
  906. -static int micron_spinand_detect(struct spinand_device *spinand)
  907. -{
  908. - u8 *id = spinand->id.data;
  909. - int ret;
  910. -
  911. - /*
  912. - * Micron SPI NAND read ID need a dummy byte,
  913. - * so the first byte in raw_id is dummy.
  914. - */
  915. - if (id[1] != SPINAND_MFR_MICRON)
  916. - return 0;
  917. -
  918. - ret = spinand_match_and_init(spinand, micron_spinand_table,
  919. - ARRAY_SIZE(micron_spinand_table), id[2]);
  920. - if (ret)
  921. - return ret;
  922. -
  923. - return 1;
  924. -}
  925. -
  926. static int micron_spinand_init(struct spinand_device *spinand)
  927. {
  928. /*
  929. @@ -248,12 +237,13 @@ static int micron_spinand_init(struct sp
  930. }
  931. static const struct spinand_manufacturer_ops micron_spinand_manuf_ops = {
  932. - .detect = micron_spinand_detect,
  933. .init = micron_spinand_init,
  934. };
  935. const struct spinand_manufacturer micron_spinand_manufacturer = {
  936. .id = SPINAND_MFR_MICRON,
  937. .name = "Micron",
  938. + .chips = micron_spinand_table,
  939. + .nchips = ARRAY_SIZE(micron_spinand_table),
  940. .ops = &micron_spinand_manuf_ops,
  941. };
  942. --- a/drivers/mtd/nand/spi/toshiba.c
  943. +++ b/drivers/mtd/nand/spi/toshiba.c
  944. @@ -111,7 +111,8 @@ static int tx58cxgxsxraix_ecc_get_status
  945. static const struct spinand_info toshiba_spinand_table[] = {
  946. /* 3.3V 1Gb (1st generation) */
  947. - SPINAND_INFO("TC58CVG0S3HRAIG", 0xC2,
  948. + SPINAND_INFO("TC58CVG0S3HRAIG",
  949. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xC2),
  950. NAND_MEMORG(1, 2048, 128, 64, 1024, 1, 1, 1),
  951. NAND_ECCREQ(8, 512),
  952. SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  953. @@ -121,7 +122,8 @@ static const struct spinand_info toshiba
  954. SPINAND_ECCINFO(&tx58cxgxsxraix_ooblayout,
  955. tx58cxgxsxraix_ecc_get_status)),
  956. /* 3.3V 2Gb (1st generation) */
  957. - SPINAND_INFO("TC58CVG1S3HRAIG", 0xCB,
  958. + SPINAND_INFO("TC58CVG1S3HRAIG",
  959. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xCB),
  960. NAND_MEMORG(1, 2048, 128, 64, 2048, 1, 1, 1),
  961. NAND_ECCREQ(8, 512),
  962. SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  963. @@ -131,7 +133,8 @@ static const struct spinand_info toshiba
  964. SPINAND_ECCINFO(&tx58cxgxsxraix_ooblayout,
  965. tx58cxgxsxraix_ecc_get_status)),
  966. /* 3.3V 4Gb (1st generation) */
  967. - SPINAND_INFO("TC58CVG2S0HRAIG", 0xCD,
  968. + SPINAND_INFO("TC58CVG2S0HRAIG",
  969. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xCD),
  970. NAND_MEMORG(1, 4096, 256, 64, 2048, 1, 1, 1),
  971. NAND_ECCREQ(8, 512),
  972. SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  973. @@ -141,7 +144,8 @@ static const struct spinand_info toshiba
  974. SPINAND_ECCINFO(&tx58cxgxsxraix_ooblayout,
  975. tx58cxgxsxraix_ecc_get_status)),
  976. /* 1.8V 1Gb (1st generation) */
  977. - SPINAND_INFO("TC58CYG0S3HRAIG", 0xB2,
  978. + SPINAND_INFO("TC58CYG0S3HRAIG",
  979. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xB2),
  980. NAND_MEMORG(1, 2048, 128, 64, 1024, 1, 1, 1),
  981. NAND_ECCREQ(8, 512),
  982. SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  983. @@ -151,7 +155,8 @@ static const struct spinand_info toshiba
  984. SPINAND_ECCINFO(&tx58cxgxsxraix_ooblayout,
  985. tx58cxgxsxraix_ecc_get_status)),
  986. /* 1.8V 2Gb (1st generation) */
  987. - SPINAND_INFO("TC58CYG1S3HRAIG", 0xBB,
  988. + SPINAND_INFO("TC58CYG1S3HRAIG",
  989. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xBB),
  990. NAND_MEMORG(1, 2048, 128, 64, 2048, 1, 1, 1),
  991. NAND_ECCREQ(8, 512),
  992. SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  993. @@ -161,7 +166,8 @@ static const struct spinand_info toshiba
  994. SPINAND_ECCINFO(&tx58cxgxsxraix_ooblayout,
  995. tx58cxgxsxraix_ecc_get_status)),
  996. /* 1.8V 4Gb (1st generation) */
  997. - SPINAND_INFO("TC58CYG2S0HRAIG", 0xBD,
  998. + SPINAND_INFO("TC58CYG2S0HRAIG",
  999. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xBD),
  1000. NAND_MEMORG(1, 4096, 256, 64, 2048, 1, 1, 1),
  1001. NAND_ECCREQ(8, 512),
  1002. SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  1003. @@ -176,7 +182,8 @@ static const struct spinand_info toshiba
  1004. * QE_BIT.
  1005. */
  1006. /* 3.3V 1Gb (2nd generation) */
  1007. - SPINAND_INFO("TC58CVG0S3HRAIJ", 0xE2,
  1008. + SPINAND_INFO("TC58CVG0S3HRAIJ",
  1009. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xE2),
  1010. NAND_MEMORG(1, 2048, 128, 64, 1024, 1, 1, 1),
  1011. NAND_ECCREQ(8, 512),
  1012. SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  1013. @@ -186,7 +193,8 @@ static const struct spinand_info toshiba
  1014. SPINAND_ECCINFO(&tx58cxgxsxraix_ooblayout,
  1015. tx58cxgxsxraix_ecc_get_status)),
  1016. /* 3.3V 2Gb (2nd generation) */
  1017. - SPINAND_INFO("TC58CVG1S3HRAIJ", 0xEB,
  1018. + SPINAND_INFO("TC58CVG1S3HRAIJ",
  1019. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xEB),
  1020. NAND_MEMORG(1, 2048, 128, 64, 2048, 1, 1, 1),
  1021. NAND_ECCREQ(8, 512),
  1022. SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  1023. @@ -196,7 +204,8 @@ static const struct spinand_info toshiba
  1024. SPINAND_ECCINFO(&tx58cxgxsxraix_ooblayout,
  1025. tx58cxgxsxraix_ecc_get_status)),
  1026. /* 3.3V 4Gb (2nd generation) */
  1027. - SPINAND_INFO("TC58CVG2S0HRAIJ", 0xED,
  1028. + SPINAND_INFO("TC58CVG2S0HRAIJ",
  1029. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xED),
  1030. NAND_MEMORG(1, 4096, 256, 64, 2048, 1, 1, 1),
  1031. NAND_ECCREQ(8, 512),
  1032. SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  1033. @@ -206,7 +215,8 @@ static const struct spinand_info toshiba
  1034. SPINAND_ECCINFO(&tx58cxgxsxraix_ooblayout,
  1035. tx58cxgxsxraix_ecc_get_status)),
  1036. /* 3.3V 8Gb (2nd generation) */
  1037. - SPINAND_INFO("TH58CVG3S0HRAIJ", 0xE4,
  1038. + SPINAND_INFO("TH58CVG3S0HRAIJ",
  1039. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xE4),
  1040. NAND_MEMORG(1, 4096, 256, 64, 4096, 1, 1, 1),
  1041. NAND_ECCREQ(8, 512),
  1042. SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  1043. @@ -216,7 +226,8 @@ static const struct spinand_info toshiba
  1044. SPINAND_ECCINFO(&tx58cxgxsxraix_ooblayout,
  1045. tx58cxgxsxraix_ecc_get_status)),
  1046. /* 1.8V 1Gb (2nd generation) */
  1047. - SPINAND_INFO("TC58CYG0S3HRAIJ", 0xD2,
  1048. + SPINAND_INFO("TC58CYG0S3HRAIJ",
  1049. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xD2),
  1050. NAND_MEMORG(1, 2048, 128, 64, 1024, 1, 1, 1),
  1051. NAND_ECCREQ(8, 512),
  1052. SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  1053. @@ -226,7 +237,8 @@ static const struct spinand_info toshiba
  1054. SPINAND_ECCINFO(&tx58cxgxsxraix_ooblayout,
  1055. tx58cxgxsxraix_ecc_get_status)),
  1056. /* 1.8V 2Gb (2nd generation) */
  1057. - SPINAND_INFO("TC58CYG1S3HRAIJ", 0xDB,
  1058. + SPINAND_INFO("TC58CYG1S3HRAIJ",
  1059. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xDB),
  1060. NAND_MEMORG(1, 2048, 128, 64, 2048, 1, 1, 1),
  1061. NAND_ECCREQ(8, 512),
  1062. SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  1063. @@ -236,7 +248,8 @@ static const struct spinand_info toshiba
  1064. SPINAND_ECCINFO(&tx58cxgxsxraix_ooblayout,
  1065. tx58cxgxsxraix_ecc_get_status)),
  1066. /* 1.8V 4Gb (2nd generation) */
  1067. - SPINAND_INFO("TC58CYG2S0HRAIJ", 0xDD,
  1068. + SPINAND_INFO("TC58CYG2S0HRAIJ",
  1069. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xDD),
  1070. NAND_MEMORG(1, 4096, 256, 64, 2048, 1, 1, 1),
  1071. NAND_ECCREQ(8, 512),
  1072. SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  1073. @@ -246,7 +259,8 @@ static const struct spinand_info toshiba
  1074. SPINAND_ECCINFO(&tx58cxgxsxraix_ooblayout,
  1075. tx58cxgxsxraix_ecc_get_status)),
  1076. /* 1.8V 8Gb (2nd generation) */
  1077. - SPINAND_INFO("TH58CYG3S0HRAIJ", 0xD4,
  1078. + SPINAND_INFO("TH58CYG3S0HRAIJ",
  1079. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xD4),
  1080. NAND_MEMORG(1, 4096, 256, 64, 4096, 1, 1, 1),
  1081. NAND_ECCREQ(8, 512),
  1082. SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  1083. @@ -257,33 +271,13 @@ static const struct spinand_info toshiba
  1084. tx58cxgxsxraix_ecc_get_status)),
  1085. };
  1086. -static int toshiba_spinand_detect(struct spinand_device *spinand)
  1087. -{
  1088. - u8 *id = spinand->id.data;
  1089. - int ret;
  1090. -
  1091. - /*
  1092. - * Toshiba SPI NAND read ID needs a dummy byte,
  1093. - * so the first byte in id is garbage.
  1094. - */
  1095. - if (id[1] != SPINAND_MFR_TOSHIBA)
  1096. - return 0;
  1097. -
  1098. - ret = spinand_match_and_init(spinand, toshiba_spinand_table,
  1099. - ARRAY_SIZE(toshiba_spinand_table),
  1100. - id[2]);
  1101. - if (ret)
  1102. - return ret;
  1103. -
  1104. - return 1;
  1105. -}
  1106. -
  1107. static const struct spinand_manufacturer_ops toshiba_spinand_manuf_ops = {
  1108. - .detect = toshiba_spinand_detect,
  1109. };
  1110. const struct spinand_manufacturer toshiba_spinand_manufacturer = {
  1111. .id = SPINAND_MFR_TOSHIBA,
  1112. .name = "Toshiba",
  1113. + .chips = toshiba_spinand_table,
  1114. + .nchips = ARRAY_SIZE(toshiba_spinand_table),
  1115. .ops = &toshiba_spinand_manuf_ops,
  1116. };
  1117. --- a/drivers/mtd/nand/spi/winbond.c
  1118. +++ b/drivers/mtd/nand/spi/winbond.c
  1119. @@ -19,6 +19,25 @@
  1120. #define WINBOND_CFG_BUF_READ BIT(3)
  1121. +#define W25N02_N04KV_STATUS_ECC_MASK (3 << 4)
  1122. +#define W25N02_N04KV_STATUS_ECC_NO_BITFLIPS (0 << 4)
  1123. +#define W25N02_N04KV_STATUS_ECC_1_4_BITFLIPS (1 << 4)
  1124. +#define W25N02_N04KV_STATUS_ECC_5_8_BITFLIPS (3 << 4)
  1125. +#define W25N02_N04KV_STATUS_ECC_UNCOR_ERROR (2 << 4)
  1126. +
  1127. +#define W25N01_M02GV_STATUS_ECC_MASK (3 << 4)
  1128. +#define W25N01_M02GV_STATUS_ECC_NO_BITFLIPS (0 << 4)
  1129. +#define W25N01_M02GV_STATUS_ECC_1_BITFLIPS (1 << 4)
  1130. +#define W25N01_M02GV_STATUS_ECC_UNCOR_ERROR (2 << 4)
  1131. +
  1132. +#if IS_ENABLED(CONFIG_MTD_SPI_NAND_W25N01KV)
  1133. +#define W25N01KV_STATUS_ECC_MASK (3 << 4)
  1134. +#define W25N01KV_STATUS_ECC_NO_BITFLIPS (0 << 4)
  1135. +#define W25N01KV_STATUS_ECC_1_3_BITFLIPS (1 << 4)
  1136. +#define W25N01KV_STATUS_ECC_4_BITFLIPS (3 << 4)
  1137. +#define W25N01KV_STATUS_ECC_UNCOR_ERROR (2 << 4)
  1138. +#endif
  1139. +
  1140. static SPINAND_OP_VARIANTS(read_cache_variants,
  1141. SPINAND_PAGE_READ_FROM_CACHE_QUADIO_OP(0, 2, NULL, 0),
  1142. SPINAND_PAGE_READ_FROM_CACHE_X4_OP(0, 1, NULL, 0),
  1143. @@ -35,6 +54,35 @@ static SPINAND_OP_VARIANTS(update_cache_
  1144. SPINAND_PROG_LOAD_X4(false, 0, NULL, 0),
  1145. SPINAND_PROG_LOAD(false, 0, NULL, 0));
  1146. +static int w25n02kv_n04kv_ooblayout_ecc(struct mtd_info *mtd, int section,
  1147. + struct mtd_oob_region *region)
  1148. +{
  1149. + if (section > 3)
  1150. + return -ERANGE;
  1151. +
  1152. + region->offset = (16 * section) + 64;
  1153. + region->length = 16;
  1154. +
  1155. + return 0;
  1156. +}
  1157. +
  1158. +static int w25n02kv_n04kv_ooblayout_free(struct mtd_info *mtd, int section,
  1159. + struct mtd_oob_region *region)
  1160. +{
  1161. + if (section > 3)
  1162. + return -ERANGE;
  1163. +
  1164. + region->offset = (16 * section) + 2;
  1165. + region->length = 14;
  1166. +
  1167. + return 0;
  1168. +}
  1169. +
  1170. +static const struct mtd_ooblayout_ops w25n02kv_n04kv_ooblayout = {
  1171. + .ecc = w25n02kv_n04kv_ooblayout_ecc,
  1172. + .rfree = w25n02kv_n04kv_ooblayout_free,
  1173. +};
  1174. +
  1175. static int w25m02gv_ooblayout_ecc(struct mtd_info *mtd, int section,
  1176. struct mtd_oob_region *region)
  1177. {
  1178. @@ -78,8 +126,63 @@ static int w25m02gv_select_target(struct
  1179. return spi_mem_exec_op(spinand->slave, &op);
  1180. }
  1181. +#if IS_ENABLED(CONFIG_MTD_SPI_NAND_W25N01KV)
  1182. +static int w25n01kv_ecc_get_status(struct spinand_device *spinand,
  1183. + u8 status)
  1184. +{
  1185. + switch (status & W25N01KV_STATUS_ECC_MASK) {
  1186. + case W25N01KV_STATUS_ECC_NO_BITFLIPS:
  1187. + return 0;
  1188. +
  1189. + case W25N01KV_STATUS_ECC_1_3_BITFLIPS:
  1190. + return 3;
  1191. +
  1192. + case W25N01KV_STATUS_ECC_4_BITFLIPS:
  1193. + return 4;
  1194. +
  1195. + case W25N01KV_STATUS_ECC_UNCOR_ERROR:
  1196. + return -EBADMSG;
  1197. +
  1198. + default:
  1199. + break;
  1200. + }
  1201. +
  1202. + return -EINVAL;
  1203. +}
  1204. +#endif
  1205. +
  1206. +static int w25n02kv_n04kv_ecc_get_status(struct spinand_device *spinand,
  1207. + u8 status)
  1208. +{
  1209. + switch (status & W25N02_N04KV_STATUS_ECC_MASK) {
  1210. + case W25N02_N04KV_STATUS_ECC_NO_BITFLIPS:
  1211. + return 0;
  1212. +
  1213. + case W25N02_N04KV_STATUS_ECC_1_4_BITFLIPS:
  1214. + return 3;
  1215. +
  1216. + case W25N02_N04KV_STATUS_ECC_5_8_BITFLIPS:
  1217. + return 4;
  1218. +
  1219. + /* W25N02_N04KV_use internal 8bit ECC algorithm.
  1220. + * But the ECC strength is 4 bit requried.
  1221. + * Return 3 if the bit bit flip count less than 5.
  1222. + * Return 4 if the bit bit flip count more than 5 to 8.
  1223. + */
  1224. +
  1225. + case W25N02_N04KV_STATUS_ECC_UNCOR_ERROR:
  1226. + return -EBADMSG;
  1227. +
  1228. + default:
  1229. + break;
  1230. + }
  1231. +
  1232. + return -EINVAL;
  1233. +}
  1234. +
  1235. static const struct spinand_info winbond_spinand_table[] = {
  1236. - SPINAND_INFO("W25M02GV", 0xAB,
  1237. + SPINAND_INFO("W25M02GV",
  1238. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xab, 0x21),
  1239. NAND_MEMORG(1, 2048, 64, 64, 1024, 1, 1, 2),
  1240. NAND_ECCREQ(1, 512),
  1241. SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  1242. @@ -88,7 +191,19 @@ static const struct spinand_info winbond
  1243. 0,
  1244. SPINAND_ECCINFO(&w25m02gv_ooblayout, NULL),
  1245. SPINAND_SELECT_TARGET(w25m02gv_select_target)),
  1246. - SPINAND_INFO("W25N01GV", 0xAA,
  1247. +#if IS_ENABLED(CONFIG_MTD_SPI_NAND_W25N01KV)
  1248. + SPINAND_INFO("W25N01KV",
  1249. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xaa, 0x21),
  1250. + NAND_MEMORG(1, 2048, 96, 64, 1024, 1, 1, 1),
  1251. + NAND_ECCREQ(4, 512),
  1252. + SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  1253. + &write_cache_variants,
  1254. + &update_cache_variants),
  1255. + 0,
  1256. + SPINAND_ECCINFO(&w25n02kv_n04kv_ooblayout, w25n01kv_ecc_get_status)),
  1257. +#else
  1258. + SPINAND_INFO("W25N01GV",
  1259. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xaa, 0x21),
  1260. NAND_MEMORG(1, 2048, 64, 64, 1024, 1, 1, 1),
  1261. NAND_ECCREQ(1, 512),
  1262. SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  1263. @@ -96,32 +211,31 @@ static const struct spinand_info winbond
  1264. &update_cache_variants),
  1265. 0,
  1266. SPINAND_ECCINFO(&w25m02gv_ooblayout, NULL)),
  1267. -};
  1268. -
  1269. -/**
  1270. - * winbond_spinand_detect - initialize device related part in spinand_device
  1271. - * struct if it is a Winbond device.
  1272. - * @spinand: SPI NAND device structure
  1273. - */
  1274. -static int winbond_spinand_detect(struct spinand_device *spinand)
  1275. -{
  1276. - u8 *id = spinand->id.data;
  1277. - int ret;
  1278. -
  1279. - /*
  1280. - * Winbond SPI NAND read ID need a dummy byte,
  1281. - * so the first byte in raw_id is dummy.
  1282. +#endif
  1283. + SPINAND_INFO("W25N02KV",
  1284. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xaa, 0x22),
  1285. + NAND_MEMORG(1, 2048, 128, 64, 2048, 2, 1, 1),
  1286. + NAND_ECCREQ(4, 512),
  1287. + SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  1288. + &write_cache_variants,
  1289. + &update_cache_variants),
  1290. + 0,
  1291. + SPINAND_ECCINFO(&w25n02kv_n04kv_ooblayout,
  1292. + w25n02kv_n04kv_ecc_get_status)),
  1293. + /* W25N04KV has 2-die(lun), however, it can select die automatically.
  1294. + * Treat it as single die here and double block size.
  1295. */
  1296. - if (id[1] != SPINAND_MFR_WINBOND)
  1297. - return 0;
  1298. -
  1299. - ret = spinand_match_and_init(spinand, winbond_spinand_table,
  1300. - ARRAY_SIZE(winbond_spinand_table), id[2]);
  1301. - if (ret)
  1302. - return ret;
  1303. -
  1304. - return 1;
  1305. -}
  1306. + SPINAND_INFO("W25N04KV",
  1307. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xaa, 0x23),
  1308. + NAND_MEMORG(1, 2048, 128, 64, 4096, 2, 1, 1),
  1309. + NAND_ECCREQ(4, 512),
  1310. + SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  1311. + &write_cache_variants,
  1312. + &update_cache_variants),
  1313. + 0,
  1314. + SPINAND_ECCINFO(&w25n02kv_n04kv_ooblayout,
  1315. + w25n02kv_n04kv_ecc_get_status)),
  1316. +};
  1317. static int winbond_spinand_init(struct spinand_device *spinand)
  1318. {
  1319. @@ -142,12 +256,13 @@ static int winbond_spinand_init(struct s
  1320. }
  1321. static const struct spinand_manufacturer_ops winbond_spinand_manuf_ops = {
  1322. - .detect = winbond_spinand_detect,
  1323. .init = winbond_spinand_init,
  1324. };
  1325. const struct spinand_manufacturer winbond_spinand_manufacturer = {
  1326. .id = SPINAND_MFR_WINBOND,
  1327. .name = "Winbond",
  1328. + .chips = winbond_spinand_table,
  1329. + .nchips = ARRAY_SIZE(winbond_spinand_table),
  1330. .ops = &winbond_spinand_manuf_ops,
  1331. };
  1332. --- a/include/linux/mtd/spinand.h
  1333. +++ b/include/linux/mtd/spinand.h
  1334. @@ -39,15 +39,15 @@
  1335. SPI_MEM_OP_NO_DUMMY, \
  1336. SPI_MEM_OP_NO_DATA)
  1337. -#define SPINAND_READID_OP(ndummy, buf, len) \
  1338. +#define SPINAND_READID_OP(naddr, ndummy, buf, len) \
  1339. SPI_MEM_OP(SPI_MEM_OP_CMD(0x9f, 1), \
  1340. - SPI_MEM_OP_NO_ADDR, \
  1341. + SPI_MEM_OP_ADDR(naddr, 0, 1), \
  1342. SPI_MEM_OP_DUMMY(ndummy, 1), \
  1343. SPI_MEM_OP_DATA_IN(len, buf, 1))
  1344. #define SPINAND_SET_FEATURE_OP(reg, valptr) \
  1345. SPI_MEM_OP(SPI_MEM_OP_CMD(0x1f, 1), \
  1346. - SPI_MEM_OP_ADDR(1, reg, 1), \
  1347. + SPI_MEM_OP_ADDR(1, reg, 1), \
  1348. SPI_MEM_OP_NO_DUMMY, \
  1349. SPI_MEM_OP_DATA_OUT(1, valptr, 1))
  1350. @@ -75,18 +75,36 @@
  1351. SPI_MEM_OP_DUMMY(ndummy, 1), \
  1352. SPI_MEM_OP_DATA_IN(len, buf, 1))
  1353. +#define SPINAND_PAGE_READ_FROM_CACHE_OP_3A(fast, addr, ndummy, buf, len)\
  1354. + SPI_MEM_OP(SPI_MEM_OP_CMD(fast ? 0x0b : 0x03, 1), \
  1355. + SPI_MEM_OP_ADDR(3, addr, 1), \
  1356. + SPI_MEM_OP_DUMMY(ndummy, 1), \
  1357. + SPI_MEM_OP_DATA_IN(len, buf, 1))
  1358. +
  1359. #define SPINAND_PAGE_READ_FROM_CACHE_X2_OP(addr, ndummy, buf, len) \
  1360. SPI_MEM_OP(SPI_MEM_OP_CMD(0x3b, 1), \
  1361. SPI_MEM_OP_ADDR(2, addr, 1), \
  1362. SPI_MEM_OP_DUMMY(ndummy, 1), \
  1363. SPI_MEM_OP_DATA_IN(len, buf, 2))
  1364. +#define SPINAND_PAGE_READ_FROM_CACHE_X2_OP_3A(addr, ndummy, buf, len) \
  1365. + SPI_MEM_OP(SPI_MEM_OP_CMD(0x3b, 1), \
  1366. + SPI_MEM_OP_ADDR(3, addr, 1), \
  1367. + SPI_MEM_OP_DUMMY(ndummy, 1), \
  1368. + SPI_MEM_OP_DATA_IN(len, buf, 2))
  1369. +
  1370. #define SPINAND_PAGE_READ_FROM_CACHE_X4_OP(addr, ndummy, buf, len) \
  1371. SPI_MEM_OP(SPI_MEM_OP_CMD(0x6b, 1), \
  1372. SPI_MEM_OP_ADDR(2, addr, 1), \
  1373. SPI_MEM_OP_DUMMY(ndummy, 1), \
  1374. SPI_MEM_OP_DATA_IN(len, buf, 4))
  1375. +#define SPINAND_PAGE_READ_FROM_CACHE_X4_OP_3A(addr, ndummy, buf, len) \
  1376. + SPI_MEM_OP(SPI_MEM_OP_CMD(0x6b, 1), \
  1377. + SPI_MEM_OP_ADDR(3, addr, 1), \
  1378. + SPI_MEM_OP_DUMMY(ndummy, 1), \
  1379. + SPI_MEM_OP_DATA_IN(len, buf, 4))
  1380. +
  1381. #define SPINAND_PAGE_READ_FROM_CACHE_DUALIO_OP(addr, ndummy, buf, len) \
  1382. SPI_MEM_OP(SPI_MEM_OP_CMD(0xbb, 1), \
  1383. SPI_MEM_OP_ADDR(2, addr, 2), \
  1384. @@ -153,37 +171,46 @@ struct spinand_device;
  1385. * @data: buffer containing the id bytes. Currently 4 bytes large, but can
  1386. * be extended if required
  1387. * @len: ID length
  1388. - *
  1389. - * struct_spinand_id->data contains all bytes returned after a READ_ID command,
  1390. - * including dummy bytes if the chip does not emit ID bytes right after the
  1391. - * READ_ID command. The responsibility to extract real ID bytes is left to
  1392. - * struct_manufacurer_ops->detect().
  1393. */
  1394. struct spinand_id {
  1395. u8 data[SPINAND_MAX_ID_LEN];
  1396. int len;
  1397. };
  1398. +enum spinand_readid_method {
  1399. + SPINAND_READID_METHOD_OPCODE,
  1400. + SPINAND_READID_METHOD_OPCODE_ADDR,
  1401. + SPINAND_READID_METHOD_OPCODE_DUMMY,
  1402. +};
  1403. +
  1404. +/**
  1405. + * struct spinand_devid - SPI NAND device id structure
  1406. + * @id: device id of current chip
  1407. + * @len: number of bytes in device id
  1408. + * @method: method to read chip id
  1409. + * There are 3 possible variants:
  1410. + * SPINAND_READID_METHOD_OPCODE: chip id is returned immediately
  1411. + * after read_id opcode.
  1412. + * SPINAND_READID_METHOD_OPCODE_ADDR: chip id is returned after
  1413. + * read_id opcode + 1-byte address.
  1414. + * SPINAND_READID_METHOD_OPCODE_DUMMY: chip id is returned after
  1415. + * read_id opcode + 1 dummy byte.
  1416. + */
  1417. +struct spinand_devid {
  1418. + const u8 *id;
  1419. + const u8 len;
  1420. + const enum spinand_readid_method method;
  1421. +};
  1422. +
  1423. /**
  1424. * struct manufacurer_ops - SPI NAND manufacturer specific operations
  1425. - * @detect: detect a SPI NAND device. Every time a SPI NAND device is probed
  1426. - * the core calls the struct_manufacurer_ops->detect() hook of each
  1427. - * registered manufacturer until one of them return 1. Note that
  1428. - * the first thing to check in this hook is that the manufacturer ID
  1429. - * in struct_spinand_device->id matches the manufacturer whose
  1430. - * ->detect() hook has been called. Should return 1 if there's a
  1431. - * match, 0 if the manufacturer ID does not match and a negative
  1432. - * error code otherwise. When true is returned, the core assumes
  1433. - * that properties of the NAND chip (spinand->base.memorg and
  1434. - * spinand->base.eccreq) have been filled
  1435. * @init: initialize a SPI NAND device
  1436. * @cleanup: cleanup a SPI NAND device
  1437. *
  1438. * Each SPI NAND manufacturer driver should implement this interface so that
  1439. - * NAND chips coming from this vendor can be detected and initialized properly.
  1440. + * NAND chips coming from this vendor can be initialized properly.
  1441. */
  1442. struct spinand_manufacturer_ops {
  1443. - int (*detect)(struct spinand_device *spinand);
  1444. int (*init)(struct spinand_device *spinand);
  1445. void (*cleanup)(struct spinand_device *spinand);
  1446. };
  1447. @@ -192,11 +219,16 @@ struct spinand_manufacturer_ops {
  1448. * struct spinand_manufacturer - SPI NAND manufacturer instance
  1449. * @id: manufacturer ID
  1450. * @name: manufacturer name
  1451. + * @devid_len: number of bytes in device ID
  1452. + * @chips: supported SPI NANDs under current manufacturer
  1453. + * @nchips: number of SPI NANDs available in chips array
  1454. * @ops: manufacturer operations
  1455. */
  1456. struct spinand_manufacturer {
  1457. u8 id;
  1458. char *name;
  1459. + const struct spinand_info *chips;
  1460. + const size_t nchips;
  1461. const struct spinand_manufacturer_ops *ops;
  1462. };
  1463. @@ -268,7 +300,7 @@ struct spinand_ecc_info {
  1464. */
  1465. struct spinand_info {
  1466. const char *model;
  1467. - u8 devid;
  1468. + struct spinand_devid devid;
  1469. u32 flags;
  1470. struct nand_memory_organization memorg;
  1471. struct nand_ecc_req eccreq;
  1472. @@ -282,6 +314,13 @@ struct spinand_info {
  1473. unsigned int target);
  1474. };
  1475. +#define SPINAND_ID(__method, ...) \
  1476. + { \
  1477. + .id = (const u8[]){ __VA_ARGS__ }, \
  1478. + .len = sizeof((u8[]){ __VA_ARGS__ }), \
  1479. + .method = __method, \
  1480. + }
  1481. +
  1482. #define SPINAND_INFO_OP_VARIANTS(__read, __write, __update) \
  1483. { \
  1484. .read_cache = __read, \
  1485. @@ -440,9 +479,10 @@ static inline void spinand_set_ofnode(st
  1486. }
  1487. #endif /* __UBOOT__ */
  1488. -int spinand_match_and_init(struct spinand_device *dev,
  1489. +int spinand_match_and_init(struct spinand_device *spinand,
  1490. const struct spinand_info *table,
  1491. - unsigned int table_size, u8 devid);
  1492. + unsigned int table_size,
  1493. + enum spinand_readid_method rdid_method);
  1494. int spinand_upd_cfg(struct spinand_device *spinand, u8 mask, u8 val);
  1495. int spinand_select_target(struct spinand_device *spinand, unsigned int target);