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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986
  1. From a3757157751a8a5302ee5e11faf828dc5db02018 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 | 327 +++++++++++++++++++++++++++++++-------
  20. drivers/mtd/spi-nor/spi-nor.c | 136 ++++++++++++++--
  21. include/linux/mtd/spi-nor.h | 14 +-
  22. 4 files changed, 409 insertions(+), 70 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,24 +449,50 @@ 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. + /* Read */
  201. + lut_base = SEQID_READ * 4;
  202. - if (q->nor_size <= SZ_16M) {
  203. - cmd = SPINOR_OP_READ_1_1_4;
  204. - addrlen = ADDR24BIT;
  205. - dummy = 8;
  206. - } else {
  207. - /* use the 4-byte address */
  208. - cmd = SPINOR_OP_READ_1_1_4;
  209. - addrlen = ADDR32BIT;
  210. - dummy = 8;
  211. - }
  212. -
  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, LUT0(DUMMY, PAD1, dummy) | LUT1(FSL_READ, PAD4, rxfifo),
  228. + qspi_writel(q,
  229. + LUT0(MODE, PAD4, 0xff) | LUT1(DUMMY, PAD4, read_dm),
  230. base + QUADSPI_LUT(lut_base + 1));
  231. + qspi_writel(q,
  232. + LUT0(FSL_READ, PAD4, rxfifo),
  233. + base + QUADSPI_LUT(lut_base + 2));
  234. + } else {
  235. + qspi_writel(q, LUT0(CMD, PAD1, read_op) |
  236. + LUT1(ADDR, PAD1, addrlen),
  237. + base + QUADSPI_LUT(lut_base));
  238. + qspi_writel(q, LUT0(DUMMY, PAD1, read_dm) |
  239. + LUT1(FSL_READ, PAD4, rxfifo),
  240. + base + QUADSPI_LUT(lut_base + 1));
  241. + }
  242. + } else if (nor->flash_read == SPI_NOR_DDR_QUAD) {
  243. + /* read mode : 1-4-4, such as Spansion s25fl128s. */
  244. + qspi_writel(q, LUT0(CMD, PAD1, read_op)
  245. + | LUT1(ADDR_DDR, PAD4, addrlen),
  246. + base + QUADSPI_LUT(lut_base));
  247. +
  248. + qspi_writel(q, LUT0(MODE_DDR, PAD4, 0xff)
  249. + | LUT1(DUMMY, PAD1, read_dm),
  250. + base + QUADSPI_LUT(lut_base + 1));
  251. +
  252. + qspi_writel(q, LUT0(FSL_READ_DDR, PAD4, rxfifo)
  253. + | LUT1(JMP_ON_CS, PAD1, 0),
  254. + base + QUADSPI_LUT(lut_base + 2));
  255. + }
  256. /* Write enable */
  257. lut_base = SEQID_WREN * 4;
  258. @@ -409,16 +502,8 @@ static void fsl_qspi_init_lut(struct fsl
  259. /* Page Program */
  260. lut_base = SEQID_PP * 4;
  261. - if (q->nor_size <= SZ_16M) {
  262. - cmd = SPINOR_OP_PP;
  263. - addrlen = ADDR24BIT;
  264. - } else {
  265. - /* use the 4-byte address */
  266. - cmd = SPINOR_OP_PP;
  267. - addrlen = ADDR32BIT;
  268. - }
  269. -
  270. - qspi_writel(q, LUT0(CMD, PAD1, cmd) | LUT1(ADDR, PAD1, addrlen),
  271. + qspi_writel(q, LUT0(CMD, PAD1, nor->program_opcode) |
  272. + LUT1(ADDR, PAD1, addrlen),
  273. base + QUADSPI_LUT(lut_base));
  274. qspi_writel(q, LUT0(FSL_WRITE, PAD1, 0),
  275. base + QUADSPI_LUT(lut_base + 1));
  276. @@ -432,10 +517,8 @@ static void fsl_qspi_init_lut(struct fsl
  277. /* Erase a sector */
  278. lut_base = SEQID_SE * 4;
  279. - cmd = q->nor[0].erase_opcode;
  280. - addrlen = q->nor_size <= SZ_16M ? ADDR24BIT : ADDR32BIT;
  281. -
  282. - qspi_writel(q, LUT0(CMD, PAD1, cmd) | LUT1(ADDR, PAD1, addrlen),
  283. + qspi_writel(q, LUT0(CMD, PAD1, nor->erase_opcode) |
  284. + LUT1(ADDR, PAD1, addrlen),
  285. base + QUADSPI_LUT(lut_base));
  286. /* Erase the whole chip */
  287. @@ -476,6 +559,44 @@ static void fsl_qspi_init_lut(struct fsl
  288. qspi_writel(q, LUT0(CMD, PAD1, SPINOR_OP_BRWR),
  289. base + QUADSPI_LUT(lut_base));
  290. +
  291. + /*
  292. + * Flash Micron and Spansion command confilict
  293. + * use the same value 0x65. But it indicates different meaning.
  294. + */
  295. + lut_base = SEQID_RDAR_OR_RD_EVCR * 4;
  296. +
  297. + if (vendor == SPANSION_S25FS_FAMILY) {
  298. + /*
  299. + * Read any device register.
  300. + * Used for Spansion S25FS-S family flash only.
  301. + */
  302. + qspi_writel(q, LUT0(CMD, PAD1, SPINOR_OP_SPANSION_RDAR) |
  303. + LUT1(ADDR, PAD1, ADDR24BIT),
  304. + base + QUADSPI_LUT(lut_base));
  305. + qspi_writel(q, LUT0(DUMMY, PAD1, 8) | LUT1(FSL_READ, PAD1, 1),
  306. + base + QUADSPI_LUT(lut_base + 1));
  307. + } else {
  308. + qspi_writel(q, LUT0(CMD, PAD1, SPINOR_OP_RD_EVCR),
  309. + base + QUADSPI_LUT(lut_base));
  310. + }
  311. +
  312. + /*
  313. + * Write any device register.
  314. + * Used for Spansion S25FS-S family flash only.
  315. + */
  316. + lut_base = SEQID_WRAR * 4;
  317. + qspi_writel(q, LUT0(CMD, PAD1, SPINOR_OP_SPANSION_WRAR) |
  318. + LUT1(ADDR, PAD1, ADDR24BIT),
  319. + base + QUADSPI_LUT(lut_base));
  320. + qspi_writel(q, LUT0(FSL_WRITE, PAD1, 1),
  321. + base + QUADSPI_LUT(lut_base + 1));
  322. +
  323. + /* Write EVCR register */
  324. + lut_base = SEQID_WD_EVCR * 4;
  325. + qspi_writel(q, LUT0(CMD, PAD1, SPINOR_OP_WD_EVCR),
  326. + base + QUADSPI_LUT(lut_base));
  327. +
  328. fsl_qspi_lock_lut(q);
  329. }
  330. @@ -483,8 +604,24 @@ static void fsl_qspi_init_lut(struct fsl
  331. static int fsl_qspi_get_seqid(struct fsl_qspi *q, u8 cmd)
  332. {
  333. switch (cmd) {
  334. + case SPINOR_OP_READ_1_4_4_D:
  335. + case SPINOR_OP_READ4_1_4_4_D:
  336. + case SPINOR_OP_READ4_1_1_4:
  337. case SPINOR_OP_READ_1_1_4:
  338. - return SEQID_QUAD_READ;
  339. + case SPINOR_OP_READ_FAST:
  340. + case SPINOR_OP_READ4_FAST:
  341. + return SEQID_READ;
  342. + /*
  343. + * Spansion & Micron use the same command value 0x65
  344. + * Spansion: SPINOR_OP_SPANSION_RDAR, read any register.
  345. + * Micron: SPINOR_OP_RD_EVCR,
  346. + * read enhanced volatile configuration register.
  347. + * case SPINOR_OP_RD_EVCR:
  348. + */
  349. + case SPINOR_OP_SPANSION_RDAR:
  350. + return SEQID_RDAR_OR_RD_EVCR;
  351. + case SPINOR_OP_SPANSION_WRAR:
  352. + return SEQID_WRAR;
  353. case SPINOR_OP_WREN:
  354. return SEQID_WREN;
  355. case SPINOR_OP_WRDI:
  356. @@ -496,6 +633,7 @@ static int fsl_qspi_get_seqid(struct fsl
  357. case SPINOR_OP_CHIP_ERASE:
  358. return SEQID_CHIP_ERASE;
  359. case SPINOR_OP_PP:
  360. + case SPINOR_OP_PP_4B:
  361. return SEQID_PP;
  362. case SPINOR_OP_RDID:
  363. return SEQID_RDID;
  364. @@ -507,6 +645,8 @@ static int fsl_qspi_get_seqid(struct fsl
  365. return SEQID_EN4B;
  366. case SPINOR_OP_BRWR:
  367. return SEQID_BRWR;
  368. + case SPINOR_OP_WD_EVCR:
  369. + return SEQID_WD_EVCR;
  370. default:
  371. if (cmd == q->nor[0].erase_opcode)
  372. return SEQID_SE;
  373. @@ -531,8 +671,11 @@ fsl_qspi_runcmd(struct fsl_qspi *q, u8 c
  374. /* save the reg */
  375. reg = qspi_readl(q, base + QUADSPI_MCR);
  376. - qspi_writel(q, q->memmap_phy + q->chip_base_addr + addr,
  377. - base + QUADSPI_SFAR);
  378. + if (has_added_amba_base_internal(q))
  379. + qspi_writel(q, q->chip_base_addr + addr, base + QUADSPI_SFAR);
  380. + else
  381. + qspi_writel(q, q->memmap_phy + q->chip_base_addr + addr,
  382. + base + QUADSPI_SFAR);
  383. qspi_writel(q, QUADSPI_RBCT_WMRK_MASK | QUADSPI_RBCT_RXBRD_USEIPS,
  384. base + QUADSPI_RBCT);
  385. qspi_writel(q, reg | QUADSPI_MCR_CLR_RXF_MASK, base + QUADSPI_MCR);
  386. @@ -582,10 +725,10 @@ static void fsl_qspi_read_data(struct fs
  387. q->chip_base_addr, tmp);
  388. if (len >= 4) {
  389. - *((u32 *)rxbuf) = tmp;
  390. + u32tou8(rxbuf, &tmp, 4);
  391. rxbuf += 4;
  392. } else {
  393. - memcpy(rxbuf, &tmp, len);
  394. + u32tou8(rxbuf, &tmp, len);
  395. break;
  396. }
  397. @@ -619,11 +762,12 @@ static inline void fsl_qspi_invalid(stru
  398. }
  399. static ssize_t fsl_qspi_nor_write(struct fsl_qspi *q, struct spi_nor *nor,
  400. - u8 opcode, unsigned int to, u32 *txbuf,
  401. + u8 opcode, unsigned int to, u8 *txbuf,
  402. unsigned count)
  403. {
  404. int ret, i, j;
  405. u32 tmp;
  406. + u8 byts;
  407. dev_dbg(q->dev, "to 0x%.8x:0x%.8x, len : %d\n",
  408. q->chip_base_addr, to, count);
  409. @@ -633,10 +777,13 @@ static ssize_t fsl_qspi_nor_write(struct
  410. qspi_writel(q, tmp | QUADSPI_MCR_CLR_TXF_MASK, q->iobase + QUADSPI_MCR);
  411. /* fill the TX data to the FIFO */
  412. + byts = count;
  413. for (j = 0, i = ((count + 3) / 4); j < i; j++) {
  414. - tmp = fsl_qspi_endian_xchg(q, *txbuf);
  415. + u8tou32(&tmp, txbuf, byts);
  416. + tmp = fsl_qspi_endian_xchg(q, tmp);
  417. qspi_writel(q, tmp, q->iobase + QUADSPI_TBDR);
  418. - txbuf++;
  419. + txbuf += 4;
  420. + byts -= 4;
  421. }
  422. /* fill the TXFIFO upto 16 bytes for i.MX7d */
  423. @@ -657,11 +804,43 @@ static void fsl_qspi_set_map_addr(struct
  424. {
  425. int nor_size = q->nor_size;
  426. void __iomem *base = q->iobase;
  427. + u32 mem_base;
  428. +
  429. + if (has_added_amba_base_internal(q))
  430. + mem_base = 0x0;
  431. + else
  432. + mem_base = q->memmap_phy;
  433. +
  434. + qspi_writel(q, nor_size + mem_base, base + QUADSPI_SFA1AD);
  435. + qspi_writel(q, nor_size * 2 + mem_base, base + QUADSPI_SFA2AD);
  436. + qspi_writel(q, nor_size * 3 + mem_base, base + QUADSPI_SFB1AD);
  437. + qspi_writel(q, nor_size * 4 + mem_base, base + QUADSPI_SFB2AD);
  438. +}
  439. +
  440. +/*
  441. + * enable controller ddr quad mode to support different
  442. + * vender flashes ddr quad mode.
  443. + */
  444. +static void set_ddr_quad_mode(struct fsl_qspi *q)
  445. +{
  446. + u32 reg, reg2;
  447. +
  448. + reg = qspi_readl(q, q->iobase + QUADSPI_MCR);
  449. +
  450. + /* Firstly, disable the module */
  451. + qspi_writel(q, reg | QUADSPI_MCR_MDIS_MASK, q->iobase + QUADSPI_MCR);
  452. +
  453. + /* Set the Sampling Register for DDR */
  454. + reg2 = qspi_readl(q, q->iobase + QUADSPI_SMPR);
  455. + reg2 &= ~QUADSPI_SMPR_DDRSMP_MASK;
  456. + reg2 |= (((q->ddr_smp) << QUADSPI_SMPR_DDRSMP_SHIFT) &
  457. + QUADSPI_SMPR_DDRSMP_MASK);
  458. + qspi_writel(q, reg2, q->iobase + QUADSPI_SMPR);
  459. +
  460. + /* Enable the module again (enable the DDR too) */
  461. + reg |= QUADSPI_MCR_DDR_EN_MASK;
  462. + qspi_writel(q, reg, q->iobase + QUADSPI_MCR);
  463. - qspi_writel(q, nor_size + q->memmap_phy, base + QUADSPI_SFA1AD);
  464. - qspi_writel(q, nor_size * 2 + q->memmap_phy, base + QUADSPI_SFA2AD);
  465. - qspi_writel(q, nor_size * 3 + q->memmap_phy, base + QUADSPI_SFB1AD);
  466. - qspi_writel(q, nor_size * 4 + q->memmap_phy, base + QUADSPI_SFB2AD);
  467. }
  468. /*
  469. @@ -704,6 +883,11 @@ static void fsl_qspi_init_abh_read(struc
  470. seqid = fsl_qspi_get_seqid(q, q->nor[0].read_opcode);
  471. qspi_writel(q, seqid << QUADSPI_BFGENCR_SEQID_SHIFT,
  472. q->iobase + QUADSPI_BFGENCR);
  473. +
  474. + /* enable the DDR quad read */
  475. + if (q->nor->flash_read == SPI_NOR_DDR_QUAD)
  476. + set_ddr_quad_mode(q);
  477. +
  478. }
  479. /* This function was used to prepare and enable QSPI clock */
  480. @@ -822,6 +1006,7 @@ static const struct of_device_id fsl_qsp
  481. { .compatible = "fsl,imx7d-qspi", .data = (void *)&imx7d_data, },
  482. { .compatible = "fsl,imx6ul-qspi", .data = (void *)&imx6ul_data, },
  483. { .compatible = "fsl,ls1021a-qspi", .data = (void *)&ls1021a_data, },
  484. + { .compatible = "fsl,ls2080a-qspi", .data = (void *)&ls2080a_data, },
  485. { /* sentinel */ }
  486. };
  487. MODULE_DEVICE_TABLE(of, fsl_qspi_dt_ids);
  488. @@ -835,8 +1020,12 @@ static int fsl_qspi_read_reg(struct spi_
  489. {
  490. int ret;
  491. struct fsl_qspi *q = nor->priv;
  492. + u32 to = 0;
  493. - ret = fsl_qspi_runcmd(q, opcode, 0, len);
  494. + if (opcode == SPINOR_OP_SPANSION_RDAR)
  495. + u8tou32(&to, nor->cmd_buf, 4);
  496. +
  497. + ret = fsl_qspi_runcmd(q, opcode, to, len);
  498. if (ret)
  499. return ret;
  500. @@ -848,9 +1037,13 @@ static int fsl_qspi_write_reg(struct spi
  501. {
  502. struct fsl_qspi *q = nor->priv;
  503. int ret;
  504. + u32 to = 0;
  505. +
  506. + if (opcode == SPINOR_OP_SPANSION_WRAR)
  507. + u8tou32(&to, nor->cmd_buf, 4);
  508. if (!buf) {
  509. - ret = fsl_qspi_runcmd(q, opcode, 0, 1);
  510. + ret = fsl_qspi_runcmd(q, opcode, to, 1);
  511. if (ret)
  512. return ret;
  513. @@ -859,7 +1052,7 @@ static int fsl_qspi_write_reg(struct spi
  514. } else if (len > 0) {
  515. ret = fsl_qspi_nor_write(q, nor, opcode, 0,
  516. - (u32 *)buf, len);
  517. + buf, len);
  518. if (ret > 0)
  519. return 0;
  520. } else {
  521. @@ -875,7 +1068,7 @@ static ssize_t fsl_qspi_write(struct spi
  522. {
  523. struct fsl_qspi *q = nor->priv;
  524. ssize_t ret = fsl_qspi_nor_write(q, nor, nor->program_opcode, to,
  525. - (u32 *)buf, len);
  526. + (u8 *)buf, len);
  527. /* invalid the data in the AHB buffer. */
  528. fsl_qspi_invalid(q);
  529. @@ -922,7 +1115,7 @@ static ssize_t fsl_qspi_read(struct spi_
  530. len);
  531. /* Read out the data directly from the AHB buffer.*/
  532. - memcpy(buf, q->ahb_addr + q->chip_base_addr + from - q->memmap_offs,
  533. + memcpy_toio(buf, q->ahb_addr + q->chip_base_addr + from - q->memmap_offs,
  534. len);
  535. return len;
  536. @@ -980,6 +1173,8 @@ static int fsl_qspi_probe(struct platfor
  537. struct spi_nor *nor;
  538. struct mtd_info *mtd;
  539. int ret, i = 0;
  540. + int find_node;
  541. + enum read_mode mode = SPI_NOR_QUAD;
  542. q = devm_kzalloc(dev, sizeof(*q), GFP_KERNEL);
  543. if (!q)
  544. @@ -1027,6 +1222,12 @@ static int fsl_qspi_probe(struct platfor
  545. goto clk_failed;
  546. }
  547. + /* find ddrsmp value */
  548. + ret = of_property_read_u32(dev->of_node, "fsl,ddr-sampling-point",
  549. + &q->ddr_smp);
  550. + if (ret)
  551. + q->ddr_smp = 0;
  552. +
  553. /* find the irq */
  554. ret = platform_get_irq(pdev, 0);
  555. if (ret < 0) {
  556. @@ -1050,6 +1251,7 @@ static int fsl_qspi_probe(struct platfor
  557. mutex_init(&q->lock);
  558. + find_node = 0;
  559. /* iterate the subnodes. */
  560. for_each_available_child_of_node(dev->of_node, np) {
  561. /* skip the holes */
  562. @@ -1076,18 +1278,25 @@ static int fsl_qspi_probe(struct platfor
  563. ret = of_property_read_u32(np, "spi-max-frequency",
  564. &q->clk_rate);
  565. if (ret < 0)
  566. - goto mutex_failed;
  567. + continue;
  568. /* set the chip address for READID */
  569. fsl_qspi_set_base_addr(q, nor);
  570. - ret = spi_nor_scan(nor, NULL, SPI_NOR_QUAD);
  571. + ret = of_property_read_bool(np, "m25p,fast-read");
  572. + mode = (ret) ? SPI_NOR_FAST : SPI_NOR_QUAD;
  573. + /* Can we enable the DDR Quad Read? */
  574. + ret = of_property_read_bool(np, "ddr-quad-read");
  575. if (ret)
  576. - goto mutex_failed;
  577. + mode = SPI_NOR_DDR_QUAD;
  578. +
  579. + ret = spi_nor_scan(nor, NULL, mode);
  580. + if (ret)
  581. + continue;
  582. ret = mtd_device_register(mtd, NULL, 0);
  583. if (ret)
  584. - goto mutex_failed;
  585. + continue;
  586. /* Set the correct NOR size now. */
  587. if (q->nor_size == 0) {
  588. @@ -1110,8 +1319,12 @@ static int fsl_qspi_probe(struct platfor
  589. nor->page_size = q->devtype_data->txfifo;
  590. i++;
  591. + find_node++;
  592. }
  593. + if (find_node == 0)
  594. + goto mutex_failed;
  595. +
  596. /* finish the rest init. */
  597. ret = fsl_qspi_nor_setup_last(q);
  598. if (ret)
  599. --- a/drivers/mtd/spi-nor/spi-nor.c
  600. +++ b/drivers/mtd/spi-nor/spi-nor.c
  601. @@ -40,6 +40,13 @@
  602. #define SPI_NOR_MAX_ID_LEN 6
  603. #define SPI_NOR_MAX_ADDR_WIDTH 4
  604. +#define SPI_NOR_MICRON_WRITE_ENABLE 0x7f
  605. +/* Added for S25FS-S family flash */
  606. +#define SPINOR_CONFIG_REG3_OFFSET 0x800004
  607. +#define CR3V_4KB_ERASE_UNABLE 0x8
  608. +#define SPINOR_S25FS_FAMILY_ID 0x81
  609. +
  610. +
  611. struct flash_info {
  612. char *name;
  613. @@ -68,7 +75,8 @@ struct flash_info {
  614. #define SECT_4K_PMC BIT(4) /* SPINOR_OP_BE_4K_PMC works uniformly */
  615. #define SPI_NOR_DUAL_READ BIT(5) /* Flash supports Dual Read */
  616. #define SPI_NOR_QUAD_READ BIT(6) /* Flash supports Quad Read */
  617. -#define USE_FSR BIT(7) /* use flag status register */
  618. +#define USE_FSR BIT(13) /* use flag status register */
  619. +#define SPI_NOR_DDR_QUAD_READ BIT(7) /* Flash supports DDR Quad Read */
  620. #define SPI_NOR_HAS_LOCK BIT(8) /* Flash supports lock/unlock via SR */
  621. #define SPI_NOR_HAS_TB BIT(9) /*
  622. * Flash SR has Top/Bottom (TB) protect
  623. @@ -85,9 +93,11 @@ struct flash_info {
  624. * Use dedicated 4byte address op codes
  625. * to support memory size above 128Mib.
  626. */
  627. +#define NO_CHIP_ERASE BIT(12) /* Chip does not support chip erase */
  628. };
  629. #define JEDEC_MFR(info) ((info)->id[0])
  630. +#define EXT_ID(info) ((info)->id[5])
  631. static const struct flash_info *spi_nor_match_id(const char *name);
  632. @@ -132,7 +142,7 @@ static int read_fsr(struct spi_nor *nor)
  633. /*
  634. * Read configuration register, returning its value in the
  635. * location. Return the configuration register value.
  636. - * Returns negative if error occured.
  637. + * Returns negative if error occurred.
  638. */
  639. static int read_cr(struct spi_nor *nor)
  640. {
  641. @@ -160,6 +170,8 @@ static inline int spi_nor_read_dummy_cyc
  642. case SPI_NOR_DUAL:
  643. case SPI_NOR_QUAD:
  644. return 8;
  645. + case SPI_NOR_DDR_QUAD:
  646. + return 6;
  647. case SPI_NOR_NORMAL:
  648. return 0;
  649. }
  650. @@ -961,6 +973,8 @@ static const struct flash_info spi_nor_i
  651. /* ESMT */
  652. { "f25l32pa", INFO(0x8c2016, 0, 64 * 1024, 64, SECT_4K | SPI_NOR_HAS_LOCK) },
  653. + { "f25l32qa", INFO(0x8c4116, 0, 64 * 1024, 64, SECT_4K | SPI_NOR_HAS_LOCK) },
  654. + { "f25l64qa", INFO(0x8c4117, 0, 64 * 1024, 128, SECT_4K | SPI_NOR_HAS_LOCK) },
  655. /* Everspin */
  656. { "mr25h256", CAT25_INFO( 32 * 1024, 1, 256, 2, SPI_NOR_NO_ERASE | SPI_NOR_NO_FR) },
  657. @@ -1014,12 +1028,15 @@ static const struct flash_info spi_nor_i
  658. { "mx25l3205d", INFO(0xc22016, 0, 64 * 1024, 64, SECT_4K) },
  659. { "mx25l3255e", INFO(0xc29e16, 0, 64 * 1024, 64, SECT_4K) },
  660. { "mx25l6405d", INFO(0xc22017, 0, 64 * 1024, 128, SECT_4K) },
  661. + { "mx25u2033e", INFO(0xc22532, 0, 64 * 1024, 4, SECT_4K) },
  662. + { "mx25u4035", INFO(0xc22533, 0, 64 * 1024, 8, SECT_4K) },
  663. + { "mx25u8035", INFO(0xc22534, 0, 64 * 1024, 16, SECT_4K) },
  664. { "mx25u3235f", INFO(0xc22536, 0, 64 * 1024, 64, 0) },
  665. { "mx25u6435f", INFO(0xc22537, 0, 64 * 1024, 128, SECT_4K) },
  666. { "mx25l12805d", INFO(0xc22018, 0, 64 * 1024, 256, 0) },
  667. { "mx25l12855e", INFO(0xc22618, 0, 64 * 1024, 256, 0) },
  668. { "mx25l25635e", INFO(0xc22019, 0, 64 * 1024, 512, 0) },
  669. - { "mx25u25635f", INFO(0xc22539, 0, 64 * 1024, 512, SECT_4K | SPI_NOR_4B_OPCODES) },
  670. + { "mx25u25635f", INFO(0xc22539, 0, 64 * 1024, 512, SECT_4K) },
  671. { "mx25l25655e", INFO(0xc22619, 0, 64 * 1024, 512, 0) },
  672. { "mx66l51235l", INFO(0xc2201a, 0, 64 * 1024, 1024, SPI_NOR_QUAD_READ) },
  673. { "mx66l1g55g", INFO(0xc2261b, 0, 64 * 1024, 2048, SPI_NOR_QUAD_READ) },
  674. @@ -1033,10 +1050,11 @@ static const struct flash_info spi_nor_i
  675. { "n25q128a11", INFO(0x20bb18, 0, 64 * 1024, 256, SECT_4K | SPI_NOR_QUAD_READ) },
  676. { "n25q128a13", INFO(0x20ba18, 0, 64 * 1024, 256, SECT_4K | SPI_NOR_QUAD_READ) },
  677. { "n25q256a", INFO(0x20ba19, 0, 64 * 1024, 512, SECT_4K | SPI_NOR_QUAD_READ) },
  678. + { "n25q256ax1", INFO(0x20bb19, 0, 64 * 1024, 512, SECT_4K | SPI_NOR_QUAD_READ) },
  679. { "n25q512a", INFO(0x20bb20, 0, 64 * 1024, 1024, SECT_4K | USE_FSR | SPI_NOR_QUAD_READ) },
  680. { "n25q512ax3", INFO(0x20ba20, 0, 64 * 1024, 1024, SECT_4K | USE_FSR | SPI_NOR_QUAD_READ) },
  681. - { "n25q00", INFO(0x20ba21, 0, 64 * 1024, 2048, SECT_4K | USE_FSR | SPI_NOR_QUAD_READ) },
  682. - { "n25q00a", INFO(0x20bb21, 0, 64 * 1024, 2048, SECT_4K | USE_FSR | SPI_NOR_QUAD_READ) },
  683. + { "n25q00", INFO(0x20ba21, 0, 64 * 1024, 2048, SECT_4K | USE_FSR | SPI_NOR_QUAD_READ | NO_CHIP_ERASE) },
  684. + { "n25q00a", INFO(0x20bb21, 0, 64 * 1024, 2048, SECT_4K | USE_FSR | SPI_NOR_QUAD_READ | NO_CHIP_ERASE) },
  685. /* PMC */
  686. { "pm25lv512", INFO(0, 0, 32 * 1024, 2, SECT_4K_PMC) },
  687. @@ -1054,8 +1072,11 @@ static const struct flash_info spi_nor_i
  688. { "s70fl01gs", INFO(0x010221, 0x4d00, 256 * 1024, 256, 0) },
  689. { "s25sl12800", INFO(0x012018, 0x0300, 256 * 1024, 64, 0) },
  690. { "s25sl12801", INFO(0x012018, 0x0301, 64 * 1024, 256, 0) },
  691. - { "s25fl128s", INFO6(0x012018, 0x4d0180, 64 * 1024, 256, SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) },
  692. + { "s25fs256s1", INFO6(0x010219, 0x4d0181, 64 * 1024, 512, 0)},
  693. + { "s25fl128s", INFO6(0x012018, 0x4d0180, 64 * 1024, 256, SPI_NOR_QUAD_READ
  694. + | SPI_NOR_DDR_QUAD_READ) },
  695. { "s25fl129p0", INFO(0x012018, 0x4d00, 256 * 1024, 64, SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) },
  696. + { "s25fs512s", INFO6(0x010220, 0x4d0081, 256 * 1024, 256, SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ)},
  697. { "s25fl129p1", INFO(0x012018, 0x4d01, 64 * 1024, 256, SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) },
  698. { "s25sl004a", INFO(0x010212, 0, 64 * 1024, 8, 0) },
  699. { "s25sl008a", INFO(0x010213, 0, 64 * 1024, 16, 0) },
  700. @@ -1130,6 +1151,9 @@ static const struct flash_info spi_nor_i
  701. { "w25x80", INFO(0xef3014, 0, 64 * 1024, 16, SECT_4K) },
  702. { "w25x16", INFO(0xef3015, 0, 64 * 1024, 32, SECT_4K) },
  703. { "w25x32", INFO(0xef3016, 0, 64 * 1024, 64, SECT_4K) },
  704. + { "w25q20cl", INFO(0xef4012, 0, 64 * 1024, 4, SECT_4K) },
  705. + { "w25q20bw", INFO(0xef5012, 0, 64 * 1024, 4, SECT_4K) },
  706. + { "w25q20ew", INFO(0xef6012, 0, 64 * 1024, 4, SECT_4K) },
  707. { "w25q32", INFO(0xef4016, 0, 64 * 1024, 64, SECT_4K) },
  708. {
  709. "w25q32dw", INFO(0xef6016, 0, 64 * 1024, 64,
  710. @@ -1192,6 +1216,53 @@ static const struct flash_info *spi_nor_
  711. id[0], id[1], id[2]);
  712. return ERR_PTR(-ENODEV);
  713. }
  714. +/*
  715. + * The S25FS-S family physical sectors may be configured as a
  716. + * hybrid combination of eight 4-kB parameter sectors
  717. + * at the top or bottom of the address space with all
  718. + * but one of the remaining sectors being uniform size.
  719. + * The Parameter Sector Erase commands (20h or 21h) must
  720. + * be used to erase the 4-kB parameter sectors individually.
  721. + * The Sector (uniform sector) Erase commands (D8h or DCh)
  722. + * must be used to erase any of the remaining
  723. + * sectors, including the portion of highest or lowest address
  724. + * sector that is not overlaid by the parameter sectors.
  725. + * The uniform sector erase command has no effect on parameter sectors.
  726. + */
  727. +static int spansion_s25fs_disable_4kb_erase(struct spi_nor *nor)
  728. +{
  729. + struct fsl_qspi *q;
  730. + u32 cr3v_addr = SPINOR_CONFIG_REG3_OFFSET;
  731. + u8 cr3v = 0x0;
  732. + int ret = 0x0;
  733. +
  734. + q = nor->priv;
  735. +
  736. + nor->cmd_buf[2] = cr3v_addr >> 16;
  737. + nor->cmd_buf[1] = cr3v_addr >> 8;
  738. + nor->cmd_buf[0] = cr3v_addr >> 0;
  739. +
  740. + ret = nor->read_reg(nor, SPINOR_OP_SPANSION_RDAR, &cr3v, 1);
  741. + if (ret)
  742. + return ret;
  743. + if (cr3v & CR3V_4KB_ERASE_UNABLE)
  744. + return 0;
  745. + ret = nor->write_reg(nor, SPINOR_OP_WREN, NULL, 0);
  746. + if (ret)
  747. + return ret;
  748. + cr3v = CR3V_4KB_ERASE_UNABLE;
  749. + nor->program_opcode = SPINOR_OP_SPANSION_WRAR;
  750. + nor->write(nor, cr3v_addr, 1, &cr3v);
  751. +
  752. + ret = nor->read_reg(nor, SPINOR_OP_SPANSION_RDAR, &cr3v, 1);
  753. + if (ret)
  754. + return ret;
  755. + if (!(cr3v & CR3V_4KB_ERASE_UNABLE))
  756. + return -EPERM;
  757. +
  758. + return 0;
  759. +}
  760. +
  761. static int spi_nor_read(struct mtd_info *mtd, loff_t from, size_t len,
  762. size_t *retlen, u_char *buf)
  763. @@ -1411,7 +1482,7 @@ static int macronix_quad_enable(struct s
  764. * Write status Register and configuration register with 2 bytes
  765. * The first byte will be written to the status register, while the
  766. * second byte will be written to the configuration register.
  767. - * Return negative if error occured.
  768. + * Return negative if error occurred.
  769. */
  770. static int write_sr_cr(struct spi_nor *nor, u16 val)
  771. {
  772. @@ -1459,6 +1530,24 @@ static int spansion_quad_enable(struct s
  773. return 0;
  774. }
  775. +static int set_ddr_quad_mode(struct spi_nor *nor, const struct flash_info *info)
  776. +{
  777. + int status;
  778. +
  779. + switch (JEDEC_MFR(info)) {
  780. + case SNOR_MFR_SPANSION:
  781. + status = spansion_quad_enable(nor);
  782. + if (status) {
  783. + dev_err(nor->dev, "Spansion DDR quad-read not enabled\n");
  784. + return status;
  785. + }
  786. + return status;
  787. + default:
  788. + return -EINVAL;
  789. + }
  790. +}
  791. +
  792. +
  793. static int set_quad_mode(struct spi_nor *nor, const struct flash_info *info)
  794. {
  795. int status;
  796. @@ -1605,9 +1694,25 @@ int spi_nor_scan(struct spi_nor *nor, co
  797. write_sr(nor, 0);
  798. spi_nor_wait_till_ready(nor);
  799. }
  800. + if (JEDEC_MFR(info) == SNOR_MFR_MICRON) {
  801. + ret = read_sr(nor);
  802. + ret &= SPI_NOR_MICRON_WRITE_ENABLE;
  803. +
  804. + write_enable(nor);
  805. + write_sr(nor, ret);
  806. + }
  807. +
  808. + if (EXT_ID(info) == SPINOR_S25FS_FAMILY_ID) {
  809. + ret = spansion_s25fs_disable_4kb_erase(nor);
  810. + if (ret)
  811. + return ret;
  812. + }
  813. +
  814. if (!mtd->name)
  815. mtd->name = dev_name(dev);
  816. + if (info->name)
  817. + nor->vendor = info->name;
  818. mtd->priv = nor;
  819. mtd->type = MTD_NORFLASH;
  820. mtd->writesize = 1;
  821. @@ -1641,6 +1746,8 @@ int spi_nor_scan(struct spi_nor *nor, co
  822. nor->flags |= SNOR_F_USE_FSR;
  823. if (info->flags & SPI_NOR_HAS_TB)
  824. nor->flags |= SNOR_F_HAS_SR_TB;
  825. + if (info->flags & NO_CHIP_ERASE)
  826. + nor->flags |= SNOR_F_NO_OP_CHIP_ERASE;
  827. #ifdef CONFIG_MTD_SPI_NOR_USE_4K_SECTORS
  828. /* prefer "small sector" erase if possible */
  829. @@ -1680,9 +1787,15 @@ int spi_nor_scan(struct spi_nor *nor, co
  830. /* Some devices cannot do fast-read, no matter what DT tells us */
  831. if (info->flags & SPI_NOR_NO_FR)
  832. nor->flash_read = SPI_NOR_NORMAL;
  833. -
  834. - /* Quad/Dual-read mode takes precedence over fast/normal */
  835. - if (mode == SPI_NOR_QUAD && info->flags & SPI_NOR_QUAD_READ) {
  836. + /* DDR Quad/Quad/Dual-read mode takes precedence over fast/normal */
  837. + if (mode == SPI_NOR_DDR_QUAD && info->flags & SPI_NOR_DDR_QUAD_READ) {
  838. + ret = set_ddr_quad_mode(nor, info);
  839. + if (ret) {
  840. + dev_err(dev, "DDR quad mode not supported\n");
  841. + return ret;
  842. + }
  843. + nor->flash_read = SPI_NOR_DDR_QUAD;
  844. + } else if (mode == SPI_NOR_QUAD && info->flags & SPI_NOR_QUAD_READ) {
  845. ret = set_quad_mode(nor, info);
  846. if (ret) {
  847. dev_err(dev, "quad mode not supported\n");
  848. @@ -1695,6 +1808,9 @@ int spi_nor_scan(struct spi_nor *nor, co
  849. /* Default commands */
  850. switch (nor->flash_read) {
  851. + case SPI_NOR_DDR_QUAD:
  852. + nor->read_opcode = SPINOR_OP_READ4_1_4_4_D;
  853. + break;
  854. case SPI_NOR_QUAD:
  855. nor->read_opcode = SPINOR_OP_READ_1_1_4;
  856. break;
  857. --- a/include/linux/mtd/spi-nor.h
  858. +++ b/include/linux/mtd/spi-nor.h
  859. @@ -31,10 +31,10 @@
  860. /*
  861. * Note on opcode nomenclature: some opcodes have a format like
  862. - * SPINOR_OP_FUNCTION{4,}_x_y_z. The numbers x, y, and z stand for the number
  863. + * SPINOR_OP_FUNCTION{4,}_x_y_z{_D}. The numbers x, y,and z stand for the number
  864. * of I/O lines used for the opcode, address, and data (respectively). The
  865. * FUNCTION has an optional suffix of '4', to represent an opcode which
  866. - * requires a 4-byte (32-bit) address.
  867. + * requires a 4-byte (32-bit) address. The suffix of 'D' stands for the
  868. */
  869. /* Flash opcodes. */
  870. @@ -46,7 +46,9 @@
  871. #define SPINOR_OP_READ_1_1_2 0x3b /* Read data bytes (Dual Output SPI) */
  872. #define SPINOR_OP_READ_1_2_2 0xbb /* Read data bytes (Dual I/O SPI) */
  873. #define SPINOR_OP_READ_1_1_4 0x6b /* Read data bytes (Quad Output SPI) */
  874. +#define SPINOR_OP_READ_1_4_4_D 0xed /* Read data bytes (DDR Quad SPI) */
  875. #define SPINOR_OP_READ_1_4_4 0xeb /* Read data bytes (Quad I/O SPI) */
  876. +#define SPINOR_OP_READ4_1_4_4_D 0xee /* Read data bytes (DDR Quad SPI) */
  877. #define SPINOR_OP_PP 0x02 /* Page program (up to 256 bytes) */
  878. #define SPINOR_OP_PP_1_1_4 0x32 /* Quad page program */
  879. #define SPINOR_OP_PP_1_4_4 0x38 /* Quad page program */
  880. @@ -62,9 +64,11 @@
  881. /* 4-byte address opcodes - used on Spansion and some Macronix flashes. */
  882. #define SPINOR_OP_READ_4B 0x13 /* Read data bytes (low frequency) */
  883. #define SPINOR_OP_READ_FAST_4B 0x0c /* Read data bytes (high frequency) */
  884. +#define SPINOR_OP_READ4_FAST 0x0c /* Read data bytes (high frequency) */
  885. #define SPINOR_OP_READ_1_1_2_4B 0x3c /* Read data bytes (Dual Output SPI) */
  886. #define SPINOR_OP_READ_1_2_2_4B 0xbc /* Read data bytes (Dual I/O SPI) */
  887. #define SPINOR_OP_READ_1_1_4_4B 0x6c /* Read data bytes (Quad Output SPI) */
  888. +#define SPINOR_OP_READ4_1_1_4 0x6c /* Read data bytes (Quad SPI) */
  889. #define SPINOR_OP_READ_1_4_4_4B 0xec /* Read data bytes (Quad I/O SPI) */
  890. #define SPINOR_OP_PP_4B 0x12 /* Page program (up to 256 bytes) */
  891. #define SPINOR_OP_PP_1_1_4_4B 0x34 /* Quad page program */
  892. @@ -94,6 +98,10 @@
  893. /* Used for Spansion flashes only. */
  894. #define SPINOR_OP_BRWR 0x17 /* Bank register write */
  895. +/* Used for Spansion S25FS-S family flash only. */
  896. +#define SPINOR_OP_SPANSION_RDAR 0x65 /* Read any device register */
  897. +#define SPINOR_OP_SPANSION_WRAR 0x71 /* Write any device register */
  898. +
  899. /* Used for Micron flashes only. */
  900. #define SPINOR_OP_RD_EVCR 0x65 /* Read EVCR register */
  901. #define SPINOR_OP_WD_EVCR 0x61 /* Write EVCR register */
  902. @@ -124,6 +132,7 @@ enum read_mode {
  903. SPI_NOR_FAST,
  904. SPI_NOR_DUAL,
  905. SPI_NOR_QUAD,
  906. + SPI_NOR_DDR_QUAD,
  907. };
  908. #define SPI_NOR_MAX_CMD_SIZE 8
  909. @@ -189,6 +198,7 @@ struct spi_nor {
  910. bool sst_write_second;
  911. u32 flags;
  912. u8 cmd_buf[SPI_NOR_MAX_CMD_SIZE];
  913. + char *vendor;
  914. int (*prepare)(struct spi_nor *nor, enum spi_nor_ops ops);
  915. void (*unprepare)(struct spi_nor *nor, enum spi_nor_ops ops);