401-mtd-spi-nor-support-layerscape.patch 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030
  1. From 120fa458ffe2250ea58578ccfc85e674005463dc Mon Sep 17 00:00:00 2001
  2. From: Yangbo Lu <[email protected]>
  3. Date: Mon, 25 Sep 2017 10:53:50 +0800
  4. Subject: [PATCH] mtd: spi-nor: support layerscape
  5. This is a integrated patch for layerscape qspi support.
  6. Signed-off-by: Suresh Gupta <[email protected]>
  7. Signed-off-by: Yunhui Cui <[email protected]>
  8. Signed-off-by: mar.krzeminski <[email protected]>
  9. Signed-off-by: Alison Wang <[email protected]>
  10. Signed-off-by: Nobuhiro Iwamatsu <[email protected]>
  11. Signed-off-by: LABBE Corentin <[email protected]>
  12. Signed-off-by: Yuan Yao <[email protected]>
  13. Signed-off-by: Alexander Kurz <[email protected]>
  14. Signed-off-by: L. D. Pinney <[email protected]>
  15. Signed-off-by: Ash Benz <[email protected]>
  16. Signed-off-by: Yangbo Lu <[email protected]>
  17. ---
  18. drivers/mtd/mtdchar.c | 2 +-
  19. drivers/mtd/spi-nor/fsl-quadspi.c | 356 +++++++++++++++++++++++++++++++-------
  20. drivers/mtd/spi-nor/spi-nor.c | 136 +++++++++++++--
  21. include/linux/mtd/spi-nor.h | 14 +-
  22. 4 files changed, 432 insertions(+), 76 deletions(-)
  23. --- a/drivers/mtd/mtdchar.c
  24. +++ b/drivers/mtd/mtdchar.c
  25. @@ -451,7 +451,7 @@ static int mtdchar_readoob(struct file *
  26. * data. For our userspace tools it is important to dump areas
  27. * with ECC errors!
  28. * For kernel internal usage it also might return -EUCLEAN
  29. - * to signal the caller that a bitflip has occured and has
  30. + * to signal the caller that a bitflip has occurred and has
  31. * been corrected by the ECC algorithm.
  32. *
  33. * Note: currently the standard NAND function, nand_read_oob_std,
  34. --- a/drivers/mtd/spi-nor/fsl-quadspi.c
  35. +++ b/drivers/mtd/spi-nor/fsl-quadspi.c
  36. @@ -41,6 +41,8 @@
  37. #define QUADSPI_QUIRK_TKT253890 (1 << 2)
  38. /* Controller cannot wake up from wait mode, TKT245618 */
  39. #define QUADSPI_QUIRK_TKT245618 (1 << 3)
  40. +/* QSPI_AMBA_BASE is internally added by SOC design */
  41. +#define QUADSPI_AMBA_BASE_INTERNAL (0x10000)
  42. /* The registers */
  43. #define QUADSPI_MCR 0x00
  44. @@ -193,7 +195,7 @@
  45. #define QUADSPI_LUT_NUM 64
  46. /* SEQID -- we can have 16 seqids at most. */
  47. -#define SEQID_QUAD_READ 0
  48. +#define SEQID_READ 0
  49. #define SEQID_WREN 1
  50. #define SEQID_WRDI 2
  51. #define SEQID_RDSR 3
  52. @@ -205,15 +207,22 @@
  53. #define SEQID_RDCR 9
  54. #define SEQID_EN4B 10
  55. #define SEQID_BRWR 11
  56. +#define SEQID_RDAR_OR_RD_EVCR 12
  57. +#define SEQID_WRAR 13
  58. +#define SEQID_WD_EVCR 14
  59. #define QUADSPI_MIN_IOMAP SZ_4M
  60. +#define FLASH_VENDOR_SPANSION_FS "s25fs"
  61. +#define SPANSION_S25FS_FAMILY (1 << 1)
  62. +
  63. enum fsl_qspi_devtype {
  64. FSL_QUADSPI_VYBRID,
  65. FSL_QUADSPI_IMX6SX,
  66. FSL_QUADSPI_IMX7D,
  67. FSL_QUADSPI_IMX6UL,
  68. FSL_QUADSPI_LS1021A,
  69. + FSL_QUADSPI_LS2080A,
  70. };
  71. struct fsl_qspi_devtype_data {
  72. @@ -224,7 +233,7 @@ struct fsl_qspi_devtype_data {
  73. int driver_data;
  74. };
  75. -static struct fsl_qspi_devtype_data vybrid_data = {
  76. +static const struct fsl_qspi_devtype_data vybrid_data = {
  77. .devtype = FSL_QUADSPI_VYBRID,
  78. .rxfifo = 128,
  79. .txfifo = 64,
  80. @@ -232,7 +241,7 @@ static struct fsl_qspi_devtype_data vybr
  81. .driver_data = QUADSPI_QUIRK_SWAP_ENDIAN,
  82. };
  83. -static struct fsl_qspi_devtype_data imx6sx_data = {
  84. +static const struct fsl_qspi_devtype_data imx6sx_data = {
  85. .devtype = FSL_QUADSPI_IMX6SX,
  86. .rxfifo = 128,
  87. .txfifo = 512,
  88. @@ -241,7 +250,7 @@ static struct fsl_qspi_devtype_data imx6
  89. | QUADSPI_QUIRK_TKT245618,
  90. };
  91. -static struct fsl_qspi_devtype_data imx7d_data = {
  92. +static const struct fsl_qspi_devtype_data imx7d_data = {
  93. .devtype = FSL_QUADSPI_IMX7D,
  94. .rxfifo = 512,
  95. .txfifo = 512,
  96. @@ -250,7 +259,7 @@ static struct fsl_qspi_devtype_data imx7
  97. | QUADSPI_QUIRK_4X_INT_CLK,
  98. };
  99. -static struct fsl_qspi_devtype_data imx6ul_data = {
  100. +static const struct fsl_qspi_devtype_data imx6ul_data = {
  101. .devtype = FSL_QUADSPI_IMX6UL,
  102. .rxfifo = 128,
  103. .txfifo = 512,
  104. @@ -267,6 +276,14 @@ static struct fsl_qspi_devtype_data ls10
  105. .driver_data = 0,
  106. };
  107. +static struct fsl_qspi_devtype_data ls2080a_data = {
  108. + .devtype = FSL_QUADSPI_LS2080A,
  109. + .rxfifo = 128,
  110. + .txfifo = 64,
  111. + .ahb_buf_size = 1024,
  112. + .driver_data = QUADSPI_AMBA_BASE_INTERNAL | QUADSPI_QUIRK_TKT253890,
  113. +};
  114. +
  115. #define FSL_QSPI_MAX_CHIP 4
  116. struct fsl_qspi {
  117. struct spi_nor nor[FSL_QSPI_MAX_CHIP];
  118. @@ -282,6 +299,7 @@ struct fsl_qspi {
  119. u32 nor_size;
  120. u32 nor_num;
  121. u32 clk_rate;
  122. + u32 ddr_smp;
  123. unsigned int chip_base_addr; /* We may support two chips. */
  124. bool has_second_chip;
  125. bool big_endian;
  126. @@ -309,6 +327,23 @@ static inline int needs_wakeup_wait_mode
  127. return q->devtype_data->driver_data & QUADSPI_QUIRK_TKT245618;
  128. }
  129. +static inline int has_added_amba_base_internal(struct fsl_qspi *q)
  130. +{
  131. + return q->devtype_data->driver_data & QUADSPI_AMBA_BASE_INTERNAL;
  132. +}
  133. +
  134. +static u32 fsl_get_nor_vendor(struct spi_nor *nor)
  135. +{
  136. + u32 vendor_id;
  137. +
  138. + if (nor->vendor) {
  139. + if (memcmp(nor->vendor, FLASH_VENDOR_SPANSION_FS,
  140. + sizeof(FLASH_VENDOR_SPANSION_FS) - 1))
  141. + vendor_id = SPANSION_S25FS_FAMILY;
  142. + }
  143. + return vendor_id;
  144. +}
  145. +
  146. /*
  147. * R/W functions for big- or little-endian registers:
  148. * The qSPI controller's endian is independent of the CPU core's endian.
  149. @@ -331,6 +366,31 @@ static u32 qspi_readl(struct fsl_qspi *q
  150. return ioread32(addr);
  151. }
  152. +static inline u32 *u8tou32(u32 *dest, const u8 *src, size_t n)
  153. +{
  154. + size_t i;
  155. + *dest = 0;
  156. +
  157. + n = n > 4 ? 4 : n;
  158. + for (i = 0; i < n; i++)
  159. + *dest |= *src++ << i * 8;
  160. +
  161. + return dest;
  162. +
  163. +}
  164. +
  165. +static inline u8 *u32tou8(u8 *dest, const u32 *src, size_t n)
  166. +{
  167. + size_t i;
  168. + u8 *xdest = dest;
  169. +
  170. + n = n > 4 ? 4 : n;
  171. + for (i = 0; i < n; i++)
  172. + *xdest++ = *src >> i * 8;
  173. +
  174. + return dest;
  175. +}
  176. +
  177. /*
  178. * An IC bug makes us to re-arrange the 32-bit data.
  179. * The following chips, such as IMX6SLX, have fixed this bug.
  180. @@ -373,8 +433,15 @@ static void fsl_qspi_init_lut(struct fsl
  181. void __iomem *base = q->iobase;
  182. int rxfifo = q->devtype_data->rxfifo;
  183. u32 lut_base;
  184. - u8 cmd, addrlen, dummy;
  185. int i;
  186. + u32 vendor;
  187. +
  188. + struct spi_nor *nor = &q->nor[0];
  189. + u8 addrlen = (nor->addr_width == 3) ? ADDR24BIT : ADDR32BIT;
  190. + u8 read_op = nor->read_opcode;
  191. + u8 read_dm = nor->read_dummy;
  192. +
  193. + vendor = fsl_get_nor_vendor(nor);
  194. fsl_qspi_unlock_lut(q);
  195. @@ -382,25 +449,51 @@ static void fsl_qspi_init_lut(struct fsl
  196. for (i = 0; i < QUADSPI_LUT_NUM; i++)
  197. qspi_writel(q, 0, base + QUADSPI_LUT_BASE + i * 4);
  198. - /* Quad Read */
  199. - lut_base = SEQID_QUAD_READ * 4;
  200. -
  201. - if (q->nor_size <= SZ_16M) {
  202. - cmd = SPINOR_OP_READ_1_1_4;
  203. - addrlen = ADDR24BIT;
  204. - dummy = 8;
  205. - } else {
  206. - /* use the 4-byte address */
  207. - cmd = SPINOR_OP_READ_1_1_4;
  208. - addrlen = ADDR32BIT;
  209. - dummy = 8;
  210. - }
  211. + /* Read */
  212. + lut_base = SEQID_READ * 4;
  213. - qspi_writel(q, LUT0(CMD, PAD1, cmd) | LUT1(ADDR, PAD1, addrlen),
  214. + if (nor->flash_read == SPI_NOR_FAST) {
  215. + qspi_writel(q, LUT0(CMD, PAD1, read_op) |
  216. + LUT1(ADDR, PAD1, addrlen),
  217. + base + QUADSPI_LUT(lut_base));
  218. + qspi_writel(q, LUT0(DUMMY, PAD1, read_dm) |
  219. + LUT1(FSL_READ, PAD1, rxfifo),
  220. + base + QUADSPI_LUT(lut_base + 1));
  221. + } else if (nor->flash_read == SPI_NOR_QUAD) {
  222. + if (q->nor_size == 0x4000000) {
  223. + read_op = 0xEC;
  224. + qspi_writel(q,
  225. + LUT0(CMD, PAD1, read_op) | LUT1(ADDR, PAD4, addrlen),
  226. + base + QUADSPI_LUT(lut_base));
  227. + qspi_writel(q,
  228. + LUT0(MODE, PAD4, 0xff) | LUT1(DUMMY, PAD4, read_dm),
  229. + base + QUADSPI_LUT(lut_base + 1));
  230. + qspi_writel(q,
  231. + LUT0(FSL_READ, PAD4, rxfifo),
  232. + base + QUADSPI_LUT(lut_base + 2));
  233. + } else {
  234. + qspi_writel(q, LUT0(CMD, PAD1, read_op) |
  235. + LUT1(ADDR, PAD1, addrlen),
  236. + base + QUADSPI_LUT(lut_base));
  237. + qspi_writel(q, LUT0(DUMMY, PAD1, read_dm) |
  238. + LUT1(FSL_READ, PAD4, rxfifo),
  239. + base + QUADSPI_LUT(lut_base + 1));
  240. + }
  241. + } else if (nor->flash_read == SPI_NOR_DDR_QUAD) {
  242. + /* read mode : 1-4-4, such as Spansion s25fl128s. */
  243. + qspi_writel(q, LUT0(CMD, PAD1, read_op)
  244. + | LUT1(ADDR_DDR, PAD4, addrlen),
  245. base + QUADSPI_LUT(lut_base));
  246. - qspi_writel(q, LUT0(DUMMY, PAD1, dummy) | LUT1(FSL_READ, PAD4, rxfifo),
  247. +
  248. + qspi_writel(q, LUT0(MODE_DDR, PAD4, 0xff)
  249. + | LUT1(DUMMY, PAD1, read_dm),
  250. base + QUADSPI_LUT(lut_base + 1));
  251. + qspi_writel(q, LUT0(FSL_READ_DDR, PAD4, rxfifo)
  252. + | LUT1(JMP_ON_CS, PAD1, 0),
  253. + base + QUADSPI_LUT(lut_base + 2));
  254. + }
  255. +
  256. /* Write enable */
  257. lut_base = SEQID_WREN * 4;
  258. qspi_writel(q, LUT0(CMD, PAD1, SPINOR_OP_WREN),
  259. @@ -409,16 +502,8 @@ static void fsl_qspi_init_lut(struct fsl
  260. /* Page Program */
  261. lut_base = SEQID_PP * 4;
  262. - if (q->nor_size <= SZ_16M) {
  263. - cmd = SPINOR_OP_PP;
  264. - addrlen = ADDR24BIT;
  265. - } else {
  266. - /* use the 4-byte address */
  267. - cmd = SPINOR_OP_PP;
  268. - addrlen = ADDR32BIT;
  269. - }
  270. -
  271. - qspi_writel(q, LUT0(CMD, PAD1, cmd) | LUT1(ADDR, PAD1, addrlen),
  272. + qspi_writel(q, LUT0(CMD, PAD1, nor->program_opcode) |
  273. + LUT1(ADDR, PAD1, addrlen),
  274. base + QUADSPI_LUT(lut_base));
  275. qspi_writel(q, LUT0(FSL_WRITE, PAD1, 0),
  276. base + QUADSPI_LUT(lut_base + 1));
  277. @@ -432,10 +517,8 @@ static void fsl_qspi_init_lut(struct fsl
  278. /* Erase a sector */
  279. lut_base = SEQID_SE * 4;
  280. - cmd = q->nor[0].erase_opcode;
  281. - addrlen = q->nor_size <= SZ_16M ? ADDR24BIT : ADDR32BIT;
  282. -
  283. - qspi_writel(q, LUT0(CMD, PAD1, cmd) | LUT1(ADDR, PAD1, addrlen),
  284. + qspi_writel(q, LUT0(CMD, PAD1, nor->erase_opcode) |
  285. + LUT1(ADDR, PAD1, addrlen),
  286. base + QUADSPI_LUT(lut_base));
  287. /* Erase the whole chip */
  288. @@ -476,6 +559,44 @@ static void fsl_qspi_init_lut(struct fsl
  289. qspi_writel(q, LUT0(CMD, PAD1, SPINOR_OP_BRWR),
  290. base + QUADSPI_LUT(lut_base));
  291. +
  292. + /*
  293. + * Flash Micron and Spansion command confilict
  294. + * use the same value 0x65. But it indicates different meaning.
  295. + */
  296. + lut_base = SEQID_RDAR_OR_RD_EVCR * 4;
  297. +
  298. + if (vendor == SPANSION_S25FS_FAMILY) {
  299. + /*
  300. + * Read any device register.
  301. + * Used for Spansion S25FS-S family flash only.
  302. + */
  303. + qspi_writel(q, LUT0(CMD, PAD1, SPINOR_OP_SPANSION_RDAR) |
  304. + LUT1(ADDR, PAD1, ADDR24BIT),
  305. + base + QUADSPI_LUT(lut_base));
  306. + qspi_writel(q, LUT0(DUMMY, PAD1, 8) | LUT1(FSL_READ, PAD1, 1),
  307. + base + QUADSPI_LUT(lut_base + 1));
  308. + } else {
  309. + qspi_writel(q, LUT0(CMD, PAD1, SPINOR_OP_RD_EVCR),
  310. + base + QUADSPI_LUT(lut_base));
  311. + }
  312. +
  313. + /*
  314. + * Write any device register.
  315. + * Used for Spansion S25FS-S family flash only.
  316. + */
  317. + lut_base = SEQID_WRAR * 4;
  318. + qspi_writel(q, LUT0(CMD, PAD1, SPINOR_OP_SPANSION_WRAR) |
  319. + LUT1(ADDR, PAD1, ADDR24BIT),
  320. + base + QUADSPI_LUT(lut_base));
  321. + qspi_writel(q, LUT0(FSL_WRITE, PAD1, 1),
  322. + base + QUADSPI_LUT(lut_base + 1));
  323. +
  324. + /* Write EVCR register */
  325. + lut_base = SEQID_WD_EVCR * 4;
  326. + qspi_writel(q, LUT0(CMD, PAD1, SPINOR_OP_WD_EVCR),
  327. + base + QUADSPI_LUT(lut_base));
  328. +
  329. fsl_qspi_lock_lut(q);
  330. }
  331. @@ -483,8 +604,24 @@ static void fsl_qspi_init_lut(struct fsl
  332. static int fsl_qspi_get_seqid(struct fsl_qspi *q, u8 cmd)
  333. {
  334. switch (cmd) {
  335. + case SPINOR_OP_READ_1_4_4_D:
  336. + case SPINOR_OP_READ4_1_4_4_D:
  337. + case SPINOR_OP_READ4_1_1_4:
  338. case SPINOR_OP_READ_1_1_4:
  339. - return SEQID_QUAD_READ;
  340. + case SPINOR_OP_READ_FAST:
  341. + case SPINOR_OP_READ4_FAST:
  342. + return SEQID_READ;
  343. + /*
  344. + * Spansion & Micron use the same command value 0x65
  345. + * Spansion: SPINOR_OP_SPANSION_RDAR, read any register.
  346. + * Micron: SPINOR_OP_RD_EVCR,
  347. + * read enhanced volatile configuration register.
  348. + * case SPINOR_OP_RD_EVCR:
  349. + */
  350. + case SPINOR_OP_SPANSION_RDAR:
  351. + return SEQID_RDAR_OR_RD_EVCR;
  352. + case SPINOR_OP_SPANSION_WRAR:
  353. + return SEQID_WRAR;
  354. case SPINOR_OP_WREN:
  355. return SEQID_WREN;
  356. case SPINOR_OP_WRDI:
  357. @@ -496,6 +633,7 @@ static int fsl_qspi_get_seqid(struct fsl
  358. case SPINOR_OP_CHIP_ERASE:
  359. return SEQID_CHIP_ERASE;
  360. case SPINOR_OP_PP:
  361. + case SPINOR_OP_PP_4B:
  362. return SEQID_PP;
  363. case SPINOR_OP_RDID:
  364. return SEQID_RDID;
  365. @@ -507,6 +645,8 @@ static int fsl_qspi_get_seqid(struct fsl
  366. return SEQID_EN4B;
  367. case SPINOR_OP_BRWR:
  368. return SEQID_BRWR;
  369. + case SPINOR_OP_WD_EVCR:
  370. + return SEQID_WD_EVCR;
  371. default:
  372. if (cmd == q->nor[0].erase_opcode)
  373. return SEQID_SE;
  374. @@ -531,8 +671,11 @@ fsl_qspi_runcmd(struct fsl_qspi *q, u8 c
  375. /* save the reg */
  376. reg = qspi_readl(q, base + QUADSPI_MCR);
  377. - qspi_writel(q, q->memmap_phy + q->chip_base_addr + addr,
  378. - base + QUADSPI_SFAR);
  379. + if (has_added_amba_base_internal(q))
  380. + qspi_writel(q, q->chip_base_addr + addr, base + QUADSPI_SFAR);
  381. + else
  382. + qspi_writel(q, q->memmap_phy + q->chip_base_addr + addr,
  383. + base + QUADSPI_SFAR);
  384. qspi_writel(q, QUADSPI_RBCT_WMRK_MASK | QUADSPI_RBCT_RXBRD_USEIPS,
  385. base + QUADSPI_RBCT);
  386. qspi_writel(q, reg | QUADSPI_MCR_CLR_RXF_MASK, base + QUADSPI_MCR);
  387. @@ -582,10 +725,10 @@ static void fsl_qspi_read_data(struct fs
  388. q->chip_base_addr, tmp);
  389. if (len >= 4) {
  390. - *((u32 *)rxbuf) = tmp;
  391. + u32tou8(rxbuf, &tmp, 4);
  392. rxbuf += 4;
  393. } else {
  394. - memcpy(rxbuf, &tmp, len);
  395. + u32tou8(rxbuf, &tmp, len);
  396. break;
  397. }
  398. @@ -619,11 +762,12 @@ static inline void fsl_qspi_invalid(stru
  399. }
  400. static ssize_t fsl_qspi_nor_write(struct fsl_qspi *q, struct spi_nor *nor,
  401. - u8 opcode, unsigned int to, u32 *txbuf,
  402. + u8 opcode, unsigned int to, u8 *txbuf,
  403. unsigned count)
  404. {
  405. int ret, i, j;
  406. u32 tmp;
  407. + u8 byts;
  408. dev_dbg(q->dev, "to 0x%.8x:0x%.8x, len : %d\n",
  409. q->chip_base_addr, to, count);
  410. @@ -633,10 +777,13 @@ static ssize_t fsl_qspi_nor_write(struct
  411. qspi_writel(q, tmp | QUADSPI_MCR_CLR_TXF_MASK, q->iobase + QUADSPI_MCR);
  412. /* fill the TX data to the FIFO */
  413. + byts = count;
  414. for (j = 0, i = ((count + 3) / 4); j < i; j++) {
  415. - tmp = fsl_qspi_endian_xchg(q, *txbuf);
  416. + u8tou32(&tmp, txbuf, byts);
  417. + tmp = fsl_qspi_endian_xchg(q, tmp);
  418. qspi_writel(q, tmp, q->iobase + QUADSPI_TBDR);
  419. - txbuf++;
  420. + txbuf += 4;
  421. + byts -= 4;
  422. }
  423. /* fill the TXFIFO upto 16 bytes for i.MX7d */
  424. @@ -657,11 +804,43 @@ static void fsl_qspi_set_map_addr(struct
  425. {
  426. int nor_size = q->nor_size;
  427. void __iomem *base = q->iobase;
  428. + u32 mem_base;
  429. +
  430. + if (has_added_amba_base_internal(q))
  431. + mem_base = 0x0;
  432. + else
  433. + mem_base = q->memmap_phy;
  434. +
  435. + qspi_writel(q, nor_size + mem_base, base + QUADSPI_SFA1AD);
  436. + qspi_writel(q, nor_size * 2 + mem_base, base + QUADSPI_SFA2AD);
  437. + qspi_writel(q, nor_size * 3 + mem_base, base + QUADSPI_SFB1AD);
  438. + qspi_writel(q, nor_size * 4 + mem_base, base + QUADSPI_SFB2AD);
  439. +}
  440. +
  441. +/*
  442. + * enable controller ddr quad mode to support different
  443. + * vender flashes ddr quad mode.
  444. + */
  445. +static void set_ddr_quad_mode(struct fsl_qspi *q)
  446. +{
  447. + u32 reg, reg2;
  448. +
  449. + reg = qspi_readl(q, q->iobase + QUADSPI_MCR);
  450. +
  451. + /* Firstly, disable the module */
  452. + qspi_writel(q, reg | QUADSPI_MCR_MDIS_MASK, q->iobase + QUADSPI_MCR);
  453. +
  454. + /* Set the Sampling Register for DDR */
  455. + reg2 = qspi_readl(q, q->iobase + QUADSPI_SMPR);
  456. + reg2 &= ~QUADSPI_SMPR_DDRSMP_MASK;
  457. + reg2 |= (((q->ddr_smp) << QUADSPI_SMPR_DDRSMP_SHIFT) &
  458. + QUADSPI_SMPR_DDRSMP_MASK);
  459. + qspi_writel(q, reg2, q->iobase + QUADSPI_SMPR);
  460. +
  461. + /* Enable the module again (enable the DDR too) */
  462. + reg |= QUADSPI_MCR_DDR_EN_MASK;
  463. + qspi_writel(q, reg, q->iobase + QUADSPI_MCR);
  464. - qspi_writel(q, nor_size + q->memmap_phy, base + QUADSPI_SFA1AD);
  465. - qspi_writel(q, nor_size * 2 + q->memmap_phy, base + QUADSPI_SFA2AD);
  466. - qspi_writel(q, nor_size * 3 + q->memmap_phy, base + QUADSPI_SFB1AD);
  467. - qspi_writel(q, nor_size * 4 + q->memmap_phy, base + QUADSPI_SFB2AD);
  468. }
  469. /*
  470. @@ -681,19 +860,36 @@ static void fsl_qspi_init_abh_read(struc
  471. {
  472. void __iomem *base = q->iobase;
  473. int seqid;
  474. + const struct fsl_qspi_devtype_data *devtype_data = q->devtype_data;
  475. /* AHB configuration for access buffer 0/1/2 .*/
  476. qspi_writel(q, QUADSPI_BUFXCR_INVALID_MSTRID, base + QUADSPI_BUF0CR);
  477. qspi_writel(q, QUADSPI_BUFXCR_INVALID_MSTRID, base + QUADSPI_BUF1CR);
  478. qspi_writel(q, QUADSPI_BUFXCR_INVALID_MSTRID, base + QUADSPI_BUF2CR);
  479. +
  480. /*
  481. - * Set ADATSZ with the maximum AHB buffer size to improve the
  482. - * read performance.
  483. + * Errata: A-009282: QuadSPI data prefetch may result in incorrect data
  484. + * Workaround: Keep the read data size to 64 bits (8 bytes).
  485. + * This disables the prefetch on the AHB buffer and
  486. + * prevents this issue from occurring.
  487. */
  488. - qspi_writel(q, QUADSPI_BUF3CR_ALLMST_MASK |
  489. - ((q->devtype_data->ahb_buf_size / 8)
  490. - << QUADSPI_BUF3CR_ADATSZ_SHIFT),
  491. - base + QUADSPI_BUF3CR);
  492. + if (devtype_data->devtype == FSL_QUADSPI_LS2080A ||
  493. + devtype_data->devtype == FSL_QUADSPI_LS1021A) {
  494. +
  495. + qspi_writel(q, QUADSPI_BUF3CR_ALLMST_MASK |
  496. + (1 << QUADSPI_BUF3CR_ADATSZ_SHIFT),
  497. + base + QUADSPI_BUF3CR);
  498. +
  499. + } else {
  500. + /*
  501. + * Set ADATSZ with the maximum AHB buffer size to improve the
  502. + * read performance.
  503. + */
  504. + qspi_writel(q, QUADSPI_BUF3CR_ALLMST_MASK |
  505. + ((q->devtype_data->ahb_buf_size / 8)
  506. + << QUADSPI_BUF3CR_ADATSZ_SHIFT),
  507. + base + QUADSPI_BUF3CR);
  508. + }
  509. /* We only use the buffer3 */
  510. qspi_writel(q, 0, base + QUADSPI_BUF0IND);
  511. @@ -704,6 +900,11 @@ static void fsl_qspi_init_abh_read(struc
  512. seqid = fsl_qspi_get_seqid(q, q->nor[0].read_opcode);
  513. qspi_writel(q, seqid << QUADSPI_BFGENCR_SEQID_SHIFT,
  514. q->iobase + QUADSPI_BFGENCR);
  515. +
  516. + /* enable the DDR quad read */
  517. + if (q->nor->flash_read == SPI_NOR_DDR_QUAD)
  518. + set_ddr_quad_mode(q);
  519. +
  520. }
  521. /* This function was used to prepare and enable QSPI clock */
  522. @@ -822,6 +1023,7 @@ static const struct of_device_id fsl_qsp
  523. { .compatible = "fsl,imx7d-qspi", .data = (void *)&imx7d_data, },
  524. { .compatible = "fsl,imx6ul-qspi", .data = (void *)&imx6ul_data, },
  525. { .compatible = "fsl,ls1021a-qspi", .data = (void *)&ls1021a_data, },
  526. + { .compatible = "fsl,ls2080a-qspi", .data = (void *)&ls2080a_data, },
  527. { /* sentinel */ }
  528. };
  529. MODULE_DEVICE_TABLE(of, fsl_qspi_dt_ids);
  530. @@ -835,8 +1037,12 @@ static int fsl_qspi_read_reg(struct spi_
  531. {
  532. int ret;
  533. struct fsl_qspi *q = nor->priv;
  534. + u32 to = 0;
  535. +
  536. + if (opcode == SPINOR_OP_SPANSION_RDAR)
  537. + u8tou32(&to, nor->cmd_buf, 4);
  538. - ret = fsl_qspi_runcmd(q, opcode, 0, len);
  539. + ret = fsl_qspi_runcmd(q, opcode, to, len);
  540. if (ret)
  541. return ret;
  542. @@ -848,9 +1054,13 @@ static int fsl_qspi_write_reg(struct spi
  543. {
  544. struct fsl_qspi *q = nor->priv;
  545. int ret;
  546. + u32 to = 0;
  547. +
  548. + if (opcode == SPINOR_OP_SPANSION_WRAR)
  549. + u8tou32(&to, nor->cmd_buf, 4);
  550. if (!buf) {
  551. - ret = fsl_qspi_runcmd(q, opcode, 0, 1);
  552. + ret = fsl_qspi_runcmd(q, opcode, to, 1);
  553. if (ret)
  554. return ret;
  555. @@ -859,7 +1069,7 @@ static int fsl_qspi_write_reg(struct spi
  556. } else if (len > 0) {
  557. ret = fsl_qspi_nor_write(q, nor, opcode, 0,
  558. - (u32 *)buf, len);
  559. + buf, len);
  560. if (ret > 0)
  561. return 0;
  562. } else {
  563. @@ -875,7 +1085,7 @@ static ssize_t fsl_qspi_write(struct spi
  564. {
  565. struct fsl_qspi *q = nor->priv;
  566. ssize_t ret = fsl_qspi_nor_write(q, nor, nor->program_opcode, to,
  567. - (u32 *)buf, len);
  568. + (u8 *)buf, len);
  569. /* invalid the data in the AHB buffer. */
  570. fsl_qspi_invalid(q);
  571. @@ -922,7 +1132,7 @@ static ssize_t fsl_qspi_read(struct spi_
  572. len);
  573. /* Read out the data directly from the AHB buffer.*/
  574. - memcpy(buf, q->ahb_addr + q->chip_base_addr + from - q->memmap_offs,
  575. + memcpy_toio(buf, q->ahb_addr + q->chip_base_addr + from - q->memmap_offs,
  576. len);
  577. return len;
  578. @@ -980,6 +1190,8 @@ static int fsl_qspi_probe(struct platfor
  579. struct spi_nor *nor;
  580. struct mtd_info *mtd;
  581. int ret, i = 0;
  582. + int find_node;
  583. + enum read_mode mode = SPI_NOR_QUAD;
  584. q = devm_kzalloc(dev, sizeof(*q), GFP_KERNEL);
  585. if (!q)
  586. @@ -1027,6 +1239,12 @@ static int fsl_qspi_probe(struct platfor
  587. goto clk_failed;
  588. }
  589. + /* find ddrsmp value */
  590. + ret = of_property_read_u32(dev->of_node, "fsl,ddr-sampling-point",
  591. + &q->ddr_smp);
  592. + if (ret)
  593. + q->ddr_smp = 0;
  594. +
  595. /* find the irq */
  596. ret = platform_get_irq(pdev, 0);
  597. if (ret < 0) {
  598. @@ -1050,6 +1268,7 @@ static int fsl_qspi_probe(struct platfor
  599. mutex_init(&q->lock);
  600. + find_node = 0;
  601. /* iterate the subnodes. */
  602. for_each_available_child_of_node(dev->of_node, np) {
  603. /* skip the holes */
  604. @@ -1076,18 +1295,25 @@ static int fsl_qspi_probe(struct platfor
  605. ret = of_property_read_u32(np, "spi-max-frequency",
  606. &q->clk_rate);
  607. if (ret < 0)
  608. - goto mutex_failed;
  609. + continue;
  610. /* set the chip address for READID */
  611. fsl_qspi_set_base_addr(q, nor);
  612. - ret = spi_nor_scan(nor, NULL, SPI_NOR_QUAD);
  613. + ret = of_property_read_bool(np, "m25p,fast-read");
  614. + mode = (ret) ? SPI_NOR_FAST : SPI_NOR_QUAD;
  615. + /* Can we enable the DDR Quad Read? */
  616. + ret = of_property_read_bool(np, "ddr-quad-read");
  617. if (ret)
  618. - goto mutex_failed;
  619. + mode = SPI_NOR_DDR_QUAD;
  620. +
  621. + ret = spi_nor_scan(nor, NULL, mode);
  622. + if (ret)
  623. + continue;
  624. ret = mtd_device_register(mtd, NULL, 0);
  625. if (ret)
  626. - goto mutex_failed;
  627. + continue;
  628. /* Set the correct NOR size now. */
  629. if (q->nor_size == 0) {
  630. @@ -1110,8 +1336,12 @@ static int fsl_qspi_probe(struct platfor
  631. nor->page_size = q->devtype_data->txfifo;
  632. i++;
  633. + find_node++;
  634. }
  635. + if (find_node == 0)
  636. + goto mutex_failed;
  637. +
  638. /* finish the rest init. */
  639. ret = fsl_qspi_nor_setup_last(q);
  640. if (ret)
  641. --- a/drivers/mtd/spi-nor/spi-nor.c
  642. +++ b/drivers/mtd/spi-nor/spi-nor.c
  643. @@ -40,6 +40,13 @@
  644. #define SPI_NOR_MAX_ID_LEN 6
  645. #define SPI_NOR_MAX_ADDR_WIDTH 4
  646. +#define SPI_NOR_MICRON_WRITE_ENABLE 0x7f
  647. +/* Added for S25FS-S family flash */
  648. +#define SPINOR_CONFIG_REG3_OFFSET 0x800004
  649. +#define CR3V_4KB_ERASE_UNABLE 0x8
  650. +#define SPINOR_S25FS_FAMILY_ID 0x81
  651. +
  652. +
  653. struct flash_info {
  654. char *name;
  655. @@ -68,7 +75,8 @@ struct flash_info {
  656. #define SECT_4K_PMC BIT(4) /* SPINOR_OP_BE_4K_PMC works uniformly */
  657. #define SPI_NOR_DUAL_READ BIT(5) /* Flash supports Dual Read */
  658. #define SPI_NOR_QUAD_READ BIT(6) /* Flash supports Quad Read */
  659. -#define USE_FSR BIT(7) /* use flag status register */
  660. +#define USE_FSR BIT(13) /* use flag status register */
  661. +#define SPI_NOR_DDR_QUAD_READ BIT(7) /* Flash supports DDR Quad Read */
  662. #define SPI_NOR_HAS_LOCK BIT(8) /* Flash supports lock/unlock via SR */
  663. #define SPI_NOR_HAS_TB BIT(9) /*
  664. * Flash SR has Top/Bottom (TB) protect
  665. @@ -85,9 +93,11 @@ struct flash_info {
  666. * Use dedicated 4byte address op codes
  667. * to support memory size above 128Mib.
  668. */
  669. +#define NO_CHIP_ERASE BIT(12) /* Chip does not support chip erase */
  670. };
  671. #define JEDEC_MFR(info) ((info)->id[0])
  672. +#define EXT_ID(info) ((info)->id[5])
  673. static const struct flash_info *spi_nor_match_id(const char *name);
  674. @@ -132,7 +142,7 @@ static int read_fsr(struct spi_nor *nor)
  675. /*
  676. * Read configuration register, returning its value in the
  677. * location. Return the configuration register value.
  678. - * Returns negative if error occured.
  679. + * Returns negative if error occurred.
  680. */
  681. static int read_cr(struct spi_nor *nor)
  682. {
  683. @@ -160,6 +170,8 @@ static inline int spi_nor_read_dummy_cyc
  684. case SPI_NOR_DUAL:
  685. case SPI_NOR_QUAD:
  686. return 8;
  687. + case SPI_NOR_DDR_QUAD:
  688. + return 6;
  689. case SPI_NOR_NORMAL:
  690. return 0;
  691. }
  692. @@ -961,6 +973,8 @@ static const struct flash_info spi_nor_i
  693. /* ESMT */
  694. { "f25l32pa", INFO(0x8c2016, 0, 64 * 1024, 64, SECT_4K | SPI_NOR_HAS_LOCK) },
  695. + { "f25l32qa", INFO(0x8c4116, 0, 64 * 1024, 64, SECT_4K | SPI_NOR_HAS_LOCK) },
  696. + { "f25l64qa", INFO(0x8c4117, 0, 64 * 1024, 128, SECT_4K | SPI_NOR_HAS_LOCK) },
  697. /* Everspin */
  698. { "mr25h256", CAT25_INFO( 32 * 1024, 1, 256, 2, SPI_NOR_NO_ERASE | SPI_NOR_NO_FR) },
  699. @@ -1014,12 +1028,15 @@ static const struct flash_info spi_nor_i
  700. { "mx25l3205d", INFO(0xc22016, 0, 64 * 1024, 64, SECT_4K) },
  701. { "mx25l3255e", INFO(0xc29e16, 0, 64 * 1024, 64, SECT_4K) },
  702. { "mx25l6405d", INFO(0xc22017, 0, 64 * 1024, 128, SECT_4K) },
  703. + { "mx25u2033e", INFO(0xc22532, 0, 64 * 1024, 4, SECT_4K) },
  704. + { "mx25u4035", INFO(0xc22533, 0, 64 * 1024, 8, SECT_4K) },
  705. + { "mx25u8035", INFO(0xc22534, 0, 64 * 1024, 16, SECT_4K) },
  706. { "mx25u3235f", INFO(0xc22536, 0, 64 * 1024, 64, 0) },
  707. { "mx25u6435f", INFO(0xc22537, 0, 64 * 1024, 128, SECT_4K) },
  708. { "mx25l12805d", INFO(0xc22018, 0, 64 * 1024, 256, 0) },
  709. { "mx25l12855e", INFO(0xc22618, 0, 64 * 1024, 256, 0) },
  710. { "mx25l25635e", INFO(0xc22019, 0, 64 * 1024, 512, 0) },
  711. - { "mx25u25635f", INFO(0xc22539, 0, 64 * 1024, 512, SECT_4K | SPI_NOR_4B_OPCODES) },
  712. + { "mx25u25635f", INFO(0xc22539, 0, 64 * 1024, 512, SECT_4K) },
  713. { "mx25l25655e", INFO(0xc22619, 0, 64 * 1024, 512, 0) },
  714. { "mx66l51235l", INFO(0xc2201a, 0, 64 * 1024, 1024, SPI_NOR_QUAD_READ) },
  715. { "mx66l1g55g", INFO(0xc2261b, 0, 64 * 1024, 2048, SPI_NOR_QUAD_READ) },
  716. @@ -1033,10 +1050,11 @@ static const struct flash_info spi_nor_i
  717. { "n25q128a11", INFO(0x20bb18, 0, 64 * 1024, 256, SECT_4K | SPI_NOR_QUAD_READ) },
  718. { "n25q128a13", INFO(0x20ba18, 0, 64 * 1024, 256, SECT_4K | SPI_NOR_QUAD_READ) },
  719. { "n25q256a", INFO(0x20ba19, 0, 64 * 1024, 512, SECT_4K | SPI_NOR_QUAD_READ) },
  720. + { "n25q256ax1", INFO(0x20bb19, 0, 64 * 1024, 512, SECT_4K | SPI_NOR_QUAD_READ) },
  721. { "n25q512a", INFO(0x20bb20, 0, 64 * 1024, 1024, SECT_4K | USE_FSR | SPI_NOR_QUAD_READ) },
  722. { "n25q512ax3", INFO(0x20ba20, 0, 64 * 1024, 1024, SECT_4K | USE_FSR | SPI_NOR_QUAD_READ) },
  723. - { "n25q00", INFO(0x20ba21, 0, 64 * 1024, 2048, SECT_4K | USE_FSR | SPI_NOR_QUAD_READ) },
  724. - { "n25q00a", INFO(0x20bb21, 0, 64 * 1024, 2048, SECT_4K | USE_FSR | SPI_NOR_QUAD_READ) },
  725. + { "n25q00", INFO(0x20ba21, 0, 64 * 1024, 2048, SECT_4K | USE_FSR | SPI_NOR_QUAD_READ | NO_CHIP_ERASE) },
  726. + { "n25q00a", INFO(0x20bb21, 0, 64 * 1024, 2048, SECT_4K | USE_FSR | SPI_NOR_QUAD_READ | NO_CHIP_ERASE) },
  727. /* PMC */
  728. { "pm25lv512", INFO(0, 0, 32 * 1024, 2, SECT_4K_PMC) },
  729. @@ -1054,8 +1072,11 @@ static const struct flash_info spi_nor_i
  730. { "s70fl01gs", INFO(0x010221, 0x4d00, 256 * 1024, 256, 0) },
  731. { "s25sl12800", INFO(0x012018, 0x0300, 256 * 1024, 64, 0) },
  732. { "s25sl12801", INFO(0x012018, 0x0301, 64 * 1024, 256, 0) },
  733. - { "s25fl128s", INFO6(0x012018, 0x4d0180, 64 * 1024, 256, SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) },
  734. + { "s25fs256s1", INFO6(0x010219, 0x4d0181, 64 * 1024, 512, 0)},
  735. + { "s25fl128s", INFO6(0x012018, 0x4d0180, 64 * 1024, 256, SPI_NOR_QUAD_READ
  736. + | SPI_NOR_DDR_QUAD_READ) },
  737. { "s25fl129p0", INFO(0x012018, 0x4d00, 256 * 1024, 64, SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) },
  738. + { "s25fs512s", INFO6(0x010220, 0x4d0081, 256 * 1024, 256, SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ)},
  739. { "s25fl129p1", INFO(0x012018, 0x4d01, 64 * 1024, 256, SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) },
  740. { "s25sl004a", INFO(0x010212, 0, 64 * 1024, 8, 0) },
  741. { "s25sl008a", INFO(0x010213, 0, 64 * 1024, 16, 0) },
  742. @@ -1130,6 +1151,9 @@ static const struct flash_info spi_nor_i
  743. { "w25x80", INFO(0xef3014, 0, 64 * 1024, 16, SECT_4K) },
  744. { "w25x16", INFO(0xef3015, 0, 64 * 1024, 32, SECT_4K) },
  745. { "w25x32", INFO(0xef3016, 0, 64 * 1024, 64, SECT_4K) },
  746. + { "w25q20cl", INFO(0xef4012, 0, 64 * 1024, 4, SECT_4K) },
  747. + { "w25q20bw", INFO(0xef5012, 0, 64 * 1024, 4, SECT_4K) },
  748. + { "w25q20ew", INFO(0xef6012, 0, 64 * 1024, 4, SECT_4K) },
  749. { "w25q32", INFO(0xef4016, 0, 64 * 1024, 64, SECT_4K) },
  750. {
  751. "w25q32dw", INFO(0xef6016, 0, 64 * 1024, 64,
  752. @@ -1192,6 +1216,53 @@ static const struct flash_info *spi_nor_
  753. id[0], id[1], id[2]);
  754. return ERR_PTR(-ENODEV);
  755. }
  756. +/*
  757. + * The S25FS-S family physical sectors may be configured as a
  758. + * hybrid combination of eight 4-kB parameter sectors
  759. + * at the top or bottom of the address space with all
  760. + * but one of the remaining sectors being uniform size.
  761. + * The Parameter Sector Erase commands (20h or 21h) must
  762. + * be used to erase the 4-kB parameter sectors individually.
  763. + * The Sector (uniform sector) Erase commands (D8h or DCh)
  764. + * must be used to erase any of the remaining
  765. + * sectors, including the portion of highest or lowest address
  766. + * sector that is not overlaid by the parameter sectors.
  767. + * The uniform sector erase command has no effect on parameter sectors.
  768. + */
  769. +static int spansion_s25fs_disable_4kb_erase(struct spi_nor *nor)
  770. +{
  771. + struct fsl_qspi *q;
  772. + u32 cr3v_addr = SPINOR_CONFIG_REG3_OFFSET;
  773. + u8 cr3v = 0x0;
  774. + int ret = 0x0;
  775. +
  776. + q = nor->priv;
  777. +
  778. + nor->cmd_buf[2] = cr3v_addr >> 16;
  779. + nor->cmd_buf[1] = cr3v_addr >> 8;
  780. + nor->cmd_buf[0] = cr3v_addr >> 0;
  781. +
  782. + ret = nor->read_reg(nor, SPINOR_OP_SPANSION_RDAR, &cr3v, 1);
  783. + if (ret)
  784. + return ret;
  785. + if (cr3v & CR3V_4KB_ERASE_UNABLE)
  786. + return 0;
  787. + ret = nor->write_reg(nor, SPINOR_OP_WREN, NULL, 0);
  788. + if (ret)
  789. + return ret;
  790. + cr3v = CR3V_4KB_ERASE_UNABLE;
  791. + nor->program_opcode = SPINOR_OP_SPANSION_WRAR;
  792. + nor->write(nor, cr3v_addr, 1, &cr3v);
  793. +
  794. + ret = nor->read_reg(nor, SPINOR_OP_SPANSION_RDAR, &cr3v, 1);
  795. + if (ret)
  796. + return ret;
  797. + if (!(cr3v & CR3V_4KB_ERASE_UNABLE))
  798. + return -EPERM;
  799. +
  800. + return 0;
  801. +}
  802. +
  803. static int spi_nor_read(struct mtd_info *mtd, loff_t from, size_t len,
  804. size_t *retlen, u_char *buf)
  805. @@ -1411,7 +1482,7 @@ static int macronix_quad_enable(struct s
  806. * Write status Register and configuration register with 2 bytes
  807. * The first byte will be written to the status register, while the
  808. * second byte will be written to the configuration register.
  809. - * Return negative if error occured.
  810. + * Return negative if error occurred.
  811. */
  812. static int write_sr_cr(struct spi_nor *nor, u16 val)
  813. {
  814. @@ -1459,6 +1530,24 @@ static int spansion_quad_enable(struct s
  815. return 0;
  816. }
  817. +static int set_ddr_quad_mode(struct spi_nor *nor, const struct flash_info *info)
  818. +{
  819. + int status;
  820. +
  821. + switch (JEDEC_MFR(info)) {
  822. + case SNOR_MFR_SPANSION:
  823. + status = spansion_quad_enable(nor);
  824. + if (status) {
  825. + dev_err(nor->dev, "Spansion DDR quad-read not enabled\n");
  826. + return status;
  827. + }
  828. + return status;
  829. + default:
  830. + return -EINVAL;
  831. + }
  832. +}
  833. +
  834. +
  835. static int set_quad_mode(struct spi_nor *nor, const struct flash_info *info)
  836. {
  837. int status;
  838. @@ -1604,9 +1693,25 @@ int spi_nor_scan(struct spi_nor *nor, co
  839. write_sr(nor, 0);
  840. spi_nor_wait_till_ready(nor);
  841. }
  842. + if (JEDEC_MFR(info) == SNOR_MFR_MICRON) {
  843. + ret = read_sr(nor);
  844. + ret &= SPI_NOR_MICRON_WRITE_ENABLE;
  845. +
  846. + write_enable(nor);
  847. + write_sr(nor, ret);
  848. + }
  849. +
  850. + if (EXT_ID(info) == SPINOR_S25FS_FAMILY_ID) {
  851. + ret = spansion_s25fs_disable_4kb_erase(nor);
  852. + if (ret)
  853. + return ret;
  854. + }
  855. +
  856. if (!mtd->name)
  857. mtd->name = dev_name(dev);
  858. + if (info->name)
  859. + nor->vendor = info->name;
  860. mtd->priv = nor;
  861. mtd->type = MTD_NORFLASH;
  862. mtd->writesize = 1;
  863. @@ -1639,6 +1744,8 @@ int spi_nor_scan(struct spi_nor *nor, co
  864. nor->flags |= SNOR_F_USE_FSR;
  865. if (info->flags & SPI_NOR_HAS_TB)
  866. nor->flags |= SNOR_F_HAS_SR_TB;
  867. + if (info->flags & NO_CHIP_ERASE)
  868. + nor->flags |= SNOR_F_NO_OP_CHIP_ERASE;
  869. #ifdef CONFIG_MTD_SPI_NOR_USE_4K_SECTORS
  870. /* prefer "small sector" erase if possible */
  871. @@ -1676,9 +1783,15 @@ int spi_nor_scan(struct spi_nor *nor, co
  872. /* Some devices cannot do fast-read, no matter what DT tells us */
  873. if (info->flags & SPI_NOR_NO_FR)
  874. nor->flash_read = SPI_NOR_NORMAL;
  875. -
  876. - /* Quad/Dual-read mode takes precedence over fast/normal */
  877. - if (mode == SPI_NOR_QUAD && info->flags & SPI_NOR_QUAD_READ) {
  878. + /* DDR Quad/Quad/Dual-read mode takes precedence over fast/normal */
  879. + if (mode == SPI_NOR_DDR_QUAD && info->flags & SPI_NOR_DDR_QUAD_READ) {
  880. + ret = set_ddr_quad_mode(nor, info);
  881. + if (ret) {
  882. + dev_err(dev, "DDR quad mode not supported\n");
  883. + return ret;
  884. + }
  885. + nor->flash_read = SPI_NOR_DDR_QUAD;
  886. + } else if (mode == SPI_NOR_QUAD && info->flags & SPI_NOR_QUAD_READ) {
  887. ret = set_quad_mode(nor, info);
  888. if (ret) {
  889. dev_err(dev, "quad mode not supported\n");
  890. @@ -1691,6 +1804,9 @@ int spi_nor_scan(struct spi_nor *nor, co
  891. /* Default commands */
  892. switch (nor->flash_read) {
  893. + case SPI_NOR_DDR_QUAD:
  894. + nor->read_opcode = SPINOR_OP_READ4_1_4_4_D;
  895. + break;
  896. case SPI_NOR_QUAD:
  897. nor->read_opcode = SPINOR_OP_READ_1_1_4;
  898. break;
  899. --- a/include/linux/mtd/spi-nor.h
  900. +++ b/include/linux/mtd/spi-nor.h
  901. @@ -31,10 +31,10 @@
  902. /*
  903. * Note on opcode nomenclature: some opcodes have a format like
  904. - * SPINOR_OP_FUNCTION{4,}_x_y_z. The numbers x, y, and z stand for the number
  905. + * SPINOR_OP_FUNCTION{4,}_x_y_z{_D}. The numbers x, y,and z stand for the number
  906. * of I/O lines used for the opcode, address, and data (respectively). The
  907. * FUNCTION has an optional suffix of '4', to represent an opcode which
  908. - * requires a 4-byte (32-bit) address.
  909. + * requires a 4-byte (32-bit) address. The suffix of 'D' stands for the
  910. */
  911. /* Flash opcodes. */
  912. @@ -46,7 +46,9 @@
  913. #define SPINOR_OP_READ_1_1_2 0x3b /* Read data bytes (Dual Output SPI) */
  914. #define SPINOR_OP_READ_1_2_2 0xbb /* Read data bytes (Dual I/O SPI) */
  915. #define SPINOR_OP_READ_1_1_4 0x6b /* Read data bytes (Quad Output SPI) */
  916. +#define SPINOR_OP_READ_1_4_4_D 0xed /* Read data bytes (DDR Quad SPI) */
  917. #define SPINOR_OP_READ_1_4_4 0xeb /* Read data bytes (Quad I/O SPI) */
  918. +#define SPINOR_OP_READ4_1_4_4_D 0xee /* Read data bytes (DDR Quad SPI) */
  919. #define SPINOR_OP_PP 0x02 /* Page program (up to 256 bytes) */
  920. #define SPINOR_OP_PP_1_1_4 0x32 /* Quad page program */
  921. #define SPINOR_OP_PP_1_4_4 0x38 /* Quad page program */
  922. @@ -62,9 +64,11 @@
  923. /* 4-byte address opcodes - used on Spansion and some Macronix flashes. */
  924. #define SPINOR_OP_READ_4B 0x13 /* Read data bytes (low frequency) */
  925. #define SPINOR_OP_READ_FAST_4B 0x0c /* Read data bytes (high frequency) */
  926. +#define SPINOR_OP_READ4_FAST 0x0c /* Read data bytes (high frequency) */
  927. #define SPINOR_OP_READ_1_1_2_4B 0x3c /* Read data bytes (Dual Output SPI) */
  928. #define SPINOR_OP_READ_1_2_2_4B 0xbc /* Read data bytes (Dual I/O SPI) */
  929. #define SPINOR_OP_READ_1_1_4_4B 0x6c /* Read data bytes (Quad Output SPI) */
  930. +#define SPINOR_OP_READ4_1_1_4 0x6c /* Read data bytes (Quad SPI) */
  931. #define SPINOR_OP_READ_1_4_4_4B 0xec /* Read data bytes (Quad I/O SPI) */
  932. #define SPINOR_OP_PP_4B 0x12 /* Page program (up to 256 bytes) */
  933. #define SPINOR_OP_PP_1_1_4_4B 0x34 /* Quad page program */
  934. @@ -94,6 +98,10 @@
  935. /* Used for Spansion flashes only. */
  936. #define SPINOR_OP_BRWR 0x17 /* Bank register write */
  937. +/* Used for Spansion S25FS-S family flash only. */
  938. +#define SPINOR_OP_SPANSION_RDAR 0x65 /* Read any device register */
  939. +#define SPINOR_OP_SPANSION_WRAR 0x71 /* Write any device register */
  940. +
  941. /* Used for Micron flashes only. */
  942. #define SPINOR_OP_RD_EVCR 0x65 /* Read EVCR register */
  943. #define SPINOR_OP_WD_EVCR 0x61 /* Write EVCR register */
  944. @@ -124,6 +132,7 @@ enum read_mode {
  945. SPI_NOR_FAST,
  946. SPI_NOR_DUAL,
  947. SPI_NOR_QUAD,
  948. + SPI_NOR_DDR_QUAD,
  949. };
  950. #define SPI_NOR_MAX_CMD_SIZE 8
  951. @@ -189,6 +198,7 @@ struct spi_nor {
  952. bool sst_write_second;
  953. u32 flags;
  954. u8 cmd_buf[SPI_NOR_MAX_CMD_SIZE];
  955. + char *vendor;
  956. int (*prepare)(struct spi_nor *nor, enum spi_nor_ops ops);
  957. void (*unprepare)(struct spi_nor *nor, enum spi_nor_ops ops);