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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993
  1. From c03c545e064a81515fe109ddcc4ecb3895528e58 Mon Sep 17 00:00:00 2001
  2. From: Yangbo Lu <[email protected]>
  3. Date: Fri, 6 Jul 2018 15:32:05 +0800
  4. Subject: [PATCH] mtd: spi-nor: support layerscape
  5. This is an 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/devices/m25p80.c | 3 +-
  19. drivers/mtd/mtdchar.c | 2 +-
  20. drivers/mtd/spi-nor/fsl-quadspi.c | 327 ++++++++++++++++++++++++------
  21. drivers/mtd/spi-nor/spi-nor.c | 141 ++++++++++++-
  22. include/linux/mtd/spi-nor.h | 14 +-
  23. 5 files changed, 416 insertions(+), 71 deletions(-)
  24. --- a/drivers/mtd/mtdchar.c
  25. +++ b/drivers/mtd/mtdchar.c
  26. @@ -455,7 +455,7 @@ static int mtdchar_readoob(struct file *
  27. * data. For our userspace tools it is important to dump areas
  28. * with ECC errors!
  29. * For kernel internal usage it also might return -EUCLEAN
  30. - * to signal the caller that a bitflip has occured and has
  31. + * to signal the caller that a bitflip has occurred and has
  32. * been corrected by the ECC algorithm.
  33. *
  34. * Note: currently the standard NAND function, nand_read_oob_std,
  35. --- a/drivers/mtd/spi-nor/fsl-quadspi.c
  36. +++ b/drivers/mtd/spi-nor/fsl-quadspi.c
  37. @@ -41,6 +41,8 @@
  38. #define QUADSPI_QUIRK_TKT253890 (1 << 2)
  39. /* Controller cannot wake up from wait mode, TKT245618 */
  40. #define QUADSPI_QUIRK_TKT245618 (1 << 3)
  41. +/* QSPI_AMBA_BASE is internally added by SOC design */
  42. +#define QUADSPI_AMBA_BASE_INTERNAL (0x10000)
  43. /* The registers */
  44. #define QUADSPI_MCR 0x00
  45. @@ -193,7 +195,7 @@
  46. #define QUADSPI_LUT_NUM 64
  47. /* SEQID -- we can have 16 seqids at most. */
  48. -#define SEQID_QUAD_READ 0
  49. +#define SEQID_READ 0
  50. #define SEQID_WREN 1
  51. #define SEQID_WRDI 2
  52. #define SEQID_RDSR 3
  53. @@ -205,15 +207,22 @@
  54. #define SEQID_RDCR 9
  55. #define SEQID_EN4B 10
  56. #define SEQID_BRWR 11
  57. +#define SEQID_RDAR_OR_RD_EVCR 12
  58. +#define SEQID_WRAR 13
  59. +#define SEQID_WD_EVCR 14
  60. #define QUADSPI_MIN_IOMAP SZ_4M
  61. +#define FLASH_VENDOR_SPANSION_FS "s25fs"
  62. +#define SPANSION_S25FS_FAMILY (1 << 1)
  63. +
  64. enum fsl_qspi_devtype {
  65. FSL_QUADSPI_VYBRID,
  66. FSL_QUADSPI_IMX6SX,
  67. FSL_QUADSPI_IMX7D,
  68. FSL_QUADSPI_IMX6UL,
  69. FSL_QUADSPI_LS1021A,
  70. + FSL_QUADSPI_LS2080A,
  71. };
  72. struct fsl_qspi_devtype_data {
  73. @@ -224,7 +233,7 @@ struct fsl_qspi_devtype_data {
  74. int driver_data;
  75. };
  76. -static struct fsl_qspi_devtype_data vybrid_data = {
  77. +static const struct fsl_qspi_devtype_data vybrid_data = {
  78. .devtype = FSL_QUADSPI_VYBRID,
  79. .rxfifo = 128,
  80. .txfifo = 64,
  81. @@ -232,7 +241,7 @@ static struct fsl_qspi_devtype_data vybr
  82. .driver_data = QUADSPI_QUIRK_SWAP_ENDIAN,
  83. };
  84. -static struct fsl_qspi_devtype_data imx6sx_data = {
  85. +static const struct fsl_qspi_devtype_data imx6sx_data = {
  86. .devtype = FSL_QUADSPI_IMX6SX,
  87. .rxfifo = 128,
  88. .txfifo = 512,
  89. @@ -241,7 +250,7 @@ static struct fsl_qspi_devtype_data imx6
  90. | QUADSPI_QUIRK_TKT245618,
  91. };
  92. -static struct fsl_qspi_devtype_data imx7d_data = {
  93. +static const struct fsl_qspi_devtype_data imx7d_data = {
  94. .devtype = FSL_QUADSPI_IMX7D,
  95. .rxfifo = 512,
  96. .txfifo = 512,
  97. @@ -250,7 +259,7 @@ static struct fsl_qspi_devtype_data imx7
  98. | QUADSPI_QUIRK_4X_INT_CLK,
  99. };
  100. -static struct fsl_qspi_devtype_data imx6ul_data = {
  101. +static const struct fsl_qspi_devtype_data imx6ul_data = {
  102. .devtype = FSL_QUADSPI_IMX6UL,
  103. .rxfifo = 128,
  104. .txfifo = 512,
  105. @@ -267,6 +276,14 @@ static struct fsl_qspi_devtype_data ls10
  106. .driver_data = 0,
  107. };
  108. +static struct fsl_qspi_devtype_data ls2080a_data = {
  109. + .devtype = FSL_QUADSPI_LS2080A,
  110. + .rxfifo = 128,
  111. + .txfifo = 64,
  112. + .ahb_buf_size = 1024,
  113. + .driver_data = QUADSPI_AMBA_BASE_INTERNAL | QUADSPI_QUIRK_TKT253890,
  114. +};
  115. +
  116. #define FSL_QSPI_MAX_CHIP 4
  117. struct fsl_qspi {
  118. struct spi_nor nor[FSL_QSPI_MAX_CHIP];
  119. @@ -282,6 +299,7 @@ struct fsl_qspi {
  120. u32 nor_size;
  121. u32 nor_num;
  122. u32 clk_rate;
  123. + u32 ddr_smp;
  124. unsigned int chip_base_addr; /* We may support two chips. */
  125. bool has_second_chip;
  126. bool big_endian;
  127. @@ -309,6 +327,23 @@ static inline int needs_wakeup_wait_mode
  128. return q->devtype_data->driver_data & QUADSPI_QUIRK_TKT245618;
  129. }
  130. +static inline int has_added_amba_base_internal(struct fsl_qspi *q)
  131. +{
  132. + return q->devtype_data->driver_data & QUADSPI_AMBA_BASE_INTERNAL;
  133. +}
  134. +
  135. +static u32 fsl_get_nor_vendor(struct spi_nor *nor)
  136. +{
  137. + u32 vendor_id;
  138. +
  139. + if (nor->vendor) {
  140. + if (memcmp(nor->vendor, FLASH_VENDOR_SPANSION_FS,
  141. + sizeof(FLASH_VENDOR_SPANSION_FS) - 1))
  142. + vendor_id = SPANSION_S25FS_FAMILY;
  143. + }
  144. + return vendor_id;
  145. +}
  146. +
  147. /*
  148. * R/W functions for big- or little-endian registers:
  149. * The qSPI controller's endian is independent of the CPU core's endian.
  150. @@ -331,6 +366,31 @@ static u32 qspi_readl(struct fsl_qspi *q
  151. return ioread32(addr);
  152. }
  153. +static inline u32 *u8tou32(u32 *dest, const u8 *src, size_t n)
  154. +{
  155. + size_t i;
  156. + *dest = 0;
  157. +
  158. + n = n > 4 ? 4 : n;
  159. + for (i = 0; i < n; i++)
  160. + *dest |= *src++ << i * 8;
  161. +
  162. + return dest;
  163. +
  164. +}
  165. +
  166. +static inline u8 *u32tou8(u8 *dest, const u32 *src, size_t n)
  167. +{
  168. + size_t i;
  169. + u8 *xdest = dest;
  170. +
  171. + n = n > 4 ? 4 : n;
  172. + for (i = 0; i < n; i++)
  173. + *xdest++ = *src >> i * 8;
  174. +
  175. + return dest;
  176. +}
  177. +
  178. /*
  179. * An IC bug makes us to re-arrange the 32-bit data.
  180. * The following chips, such as IMX6SLX, have fixed this bug.
  181. @@ -373,8 +433,15 @@ static void fsl_qspi_init_lut(struct fsl
  182. void __iomem *base = q->iobase;
  183. int rxfifo = q->devtype_data->rxfifo;
  184. u32 lut_base;
  185. - u8 cmd, addrlen, dummy;
  186. int i;
  187. + u32 vendor;
  188. +
  189. + struct spi_nor *nor = &q->nor[0];
  190. + u8 addrlen = (nor->addr_width == 3) ? ADDR24BIT : ADDR32BIT;
  191. + u8 read_op = nor->read_opcode;
  192. + u8 read_dm = nor->read_dummy;
  193. +
  194. + vendor = fsl_get_nor_vendor(nor);
  195. fsl_qspi_unlock_lut(q);
  196. @@ -382,24 +449,50 @@ static void fsl_qspi_init_lut(struct fsl
  197. for (i = 0; i < QUADSPI_LUT_NUM; i++)
  198. qspi_writel(q, 0, base + QUADSPI_LUT_BASE + i * 4);
  199. - /* Quad Read */
  200. - lut_base = SEQID_QUAD_READ * 4;
  201. + /* Read */
  202. + lut_base = SEQID_READ * 4;
  203. - if (q->nor_size <= SZ_16M) {
  204. - cmd = SPINOR_OP_READ_1_1_4;
  205. - addrlen = ADDR24BIT;
  206. - dummy = 8;
  207. - } else {
  208. - /* use the 4-byte address */
  209. - cmd = SPINOR_OP_READ_1_1_4;
  210. - addrlen = ADDR32BIT;
  211. - dummy = 8;
  212. - }
  213. -
  214. - qspi_writel(q, LUT0(CMD, PAD1, cmd) | LUT1(ADDR, PAD1, addrlen),
  215. + if (nor->flash_read == SPI_NOR_FAST) {
  216. + qspi_writel(q, LUT0(CMD, PAD1, read_op) |
  217. + LUT1(ADDR, PAD1, addrlen),
  218. + base + QUADSPI_LUT(lut_base));
  219. + qspi_writel(q, LUT0(DUMMY, PAD1, read_dm) |
  220. + LUT1(FSL_READ, PAD1, rxfifo),
  221. + base + QUADSPI_LUT(lut_base + 1));
  222. + } else if (nor->flash_read == SPI_NOR_QUAD) {
  223. + if (q->nor_size == 0x4000000) {
  224. + read_op = 0xEC;
  225. + qspi_writel(q,
  226. + LUT0(CMD, PAD1, read_op) | LUT1(ADDR, PAD4, addrlen),
  227. base + QUADSPI_LUT(lut_base));
  228. - qspi_writel(q, LUT0(DUMMY, PAD1, dummy) | LUT1(FSL_READ, PAD4, rxfifo),
  229. + qspi_writel(q,
  230. + LUT0(MODE, PAD4, 0xff) | LUT1(DUMMY, PAD4, read_dm),
  231. base + QUADSPI_LUT(lut_base + 1));
  232. + qspi_writel(q,
  233. + LUT0(FSL_READ, PAD4, rxfifo),
  234. + base + QUADSPI_LUT(lut_base + 2));
  235. + } else {
  236. + qspi_writel(q, LUT0(CMD, PAD1, read_op) |
  237. + LUT1(ADDR, PAD1, addrlen),
  238. + base + QUADSPI_LUT(lut_base));
  239. + qspi_writel(q, LUT0(DUMMY, PAD1, read_dm) |
  240. + LUT1(FSL_READ, PAD4, rxfifo),
  241. + base + QUADSPI_LUT(lut_base + 1));
  242. + }
  243. + } else if (nor->flash_read == SPI_NOR_DDR_QUAD) {
  244. + /* read mode : 1-4-4, such as Spansion s25fl128s. */
  245. + qspi_writel(q, LUT0(CMD, PAD1, read_op)
  246. + | LUT1(ADDR_DDR, PAD4, addrlen),
  247. + base + QUADSPI_LUT(lut_base));
  248. +
  249. + qspi_writel(q, LUT0(MODE_DDR, PAD4, 0xff)
  250. + | LUT1(DUMMY, PAD1, read_dm),
  251. + base + QUADSPI_LUT(lut_base + 1));
  252. +
  253. + qspi_writel(q, LUT0(FSL_READ_DDR, PAD4, rxfifo)
  254. + | LUT1(JMP_ON_CS, PAD1, 0),
  255. + base + QUADSPI_LUT(lut_base + 2));
  256. + }
  257. /* Write enable */
  258. lut_base = SEQID_WREN * 4;
  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. @@ -704,6 +883,11 @@ static void fsl_qspi_init_abh_read(struc
  471. seqid = fsl_qspi_get_seqid(q, q->nor[0].read_opcode);
  472. qspi_writel(q, seqid << QUADSPI_BFGENCR_SEQID_SHIFT,
  473. q->iobase + QUADSPI_BFGENCR);
  474. +
  475. + /* enable the DDR quad read */
  476. + if (q->nor->flash_read == SPI_NOR_DDR_QUAD)
  477. + set_ddr_quad_mode(q);
  478. +
  479. }
  480. /* This function was used to prepare and enable QSPI clock */
  481. @@ -822,6 +1006,7 @@ static const struct of_device_id fsl_qsp
  482. { .compatible = "fsl,imx7d-qspi", .data = (void *)&imx7d_data, },
  483. { .compatible = "fsl,imx6ul-qspi", .data = (void *)&imx6ul_data, },
  484. { .compatible = "fsl,ls1021a-qspi", .data = (void *)&ls1021a_data, },
  485. + { .compatible = "fsl,ls2080a-qspi", .data = (void *)&ls2080a_data, },
  486. { /* sentinel */ }
  487. };
  488. MODULE_DEVICE_TABLE(of, fsl_qspi_dt_ids);
  489. @@ -835,8 +1020,12 @@ static int fsl_qspi_read_reg(struct spi_
  490. {
  491. int ret;
  492. struct fsl_qspi *q = nor->priv;
  493. + u32 to = 0;
  494. - ret = fsl_qspi_runcmd(q, opcode, 0, len);
  495. + if (opcode == SPINOR_OP_SPANSION_RDAR)
  496. + u8tou32(&to, nor->cmd_buf, 4);
  497. +
  498. + ret = fsl_qspi_runcmd(q, opcode, to, len);
  499. if (ret)
  500. return ret;
  501. @@ -848,9 +1037,13 @@ static int fsl_qspi_write_reg(struct spi
  502. {
  503. struct fsl_qspi *q = nor->priv;
  504. int ret;
  505. + u32 to = 0;
  506. +
  507. + if (opcode == SPINOR_OP_SPANSION_WRAR)
  508. + u8tou32(&to, nor->cmd_buf, 4);
  509. if (!buf) {
  510. - ret = fsl_qspi_runcmd(q, opcode, 0, 1);
  511. + ret = fsl_qspi_runcmd(q, opcode, to, 1);
  512. if (ret)
  513. return ret;
  514. @@ -859,7 +1052,7 @@ static int fsl_qspi_write_reg(struct spi
  515. } else if (len > 0) {
  516. ret = fsl_qspi_nor_write(q, nor, opcode, 0,
  517. - (u32 *)buf, len);
  518. + buf, len);
  519. if (ret > 0)
  520. return 0;
  521. } else {
  522. @@ -875,7 +1068,7 @@ static ssize_t fsl_qspi_write(struct spi
  523. {
  524. struct fsl_qspi *q = nor->priv;
  525. ssize_t ret = fsl_qspi_nor_write(q, nor, nor->program_opcode, to,
  526. - (u32 *)buf, len);
  527. + (u8 *)buf, len);
  528. /* invalid the data in the AHB buffer. */
  529. fsl_qspi_invalid(q);
  530. @@ -922,7 +1115,7 @@ static ssize_t fsl_qspi_read(struct spi_
  531. len);
  532. /* Read out the data directly from the AHB buffer.*/
  533. - memcpy(buf, q->ahb_addr + q->chip_base_addr + from - q->memmap_offs,
  534. + memcpy_toio(buf, q->ahb_addr + q->chip_base_addr + from - q->memmap_offs,
  535. len);
  536. return len;
  537. @@ -980,6 +1173,8 @@ static int fsl_qspi_probe(struct platfor
  538. struct spi_nor *nor;
  539. struct mtd_info *mtd;
  540. int ret, i = 0;
  541. + int find_node;
  542. + enum read_mode mode = SPI_NOR_QUAD;
  543. q = devm_kzalloc(dev, sizeof(*q), GFP_KERNEL);
  544. if (!q)
  545. @@ -1027,6 +1222,12 @@ static int fsl_qspi_probe(struct platfor
  546. goto clk_failed;
  547. }
  548. + /* find ddrsmp value */
  549. + ret = of_property_read_u32(dev->of_node, "fsl,ddr-sampling-point",
  550. + &q->ddr_smp);
  551. + if (ret)
  552. + q->ddr_smp = 0;
  553. +
  554. /* find the irq */
  555. ret = platform_get_irq(pdev, 0);
  556. if (ret < 0) {
  557. @@ -1050,6 +1251,7 @@ static int fsl_qspi_probe(struct platfor
  558. mutex_init(&q->lock);
  559. + find_node = 0;
  560. /* iterate the subnodes. */
  561. for_each_available_child_of_node(dev->of_node, np) {
  562. /* skip the holes */
  563. @@ -1076,18 +1278,25 @@ static int fsl_qspi_probe(struct platfor
  564. ret = of_property_read_u32(np, "spi-max-frequency",
  565. &q->clk_rate);
  566. if (ret < 0)
  567. - goto mutex_failed;
  568. + continue;
  569. /* set the chip address for READID */
  570. fsl_qspi_set_base_addr(q, nor);
  571. - ret = spi_nor_scan(nor, NULL, SPI_NOR_QUAD);
  572. + ret = of_property_read_bool(np, "m25p,fast-read");
  573. + mode = (ret) ? SPI_NOR_FAST : SPI_NOR_QUAD;
  574. + /* Can we enable the DDR Quad Read? */
  575. + ret = of_property_read_bool(np, "ddr-quad-read");
  576. if (ret)
  577. - goto mutex_failed;
  578. + mode = SPI_NOR_DDR_QUAD;
  579. +
  580. + ret = spi_nor_scan(nor, NULL, mode);
  581. + if (ret)
  582. + continue;
  583. ret = mtd_device_register(mtd, NULL, 0);
  584. if (ret)
  585. - goto mutex_failed;
  586. + continue;
  587. /* Set the correct NOR size now. */
  588. if (q->nor_size == 0) {
  589. @@ -1110,8 +1319,12 @@ static int fsl_qspi_probe(struct platfor
  590. nor->page_size = q->devtype_data->txfifo;
  591. i++;
  592. + find_node++;
  593. }
  594. + if (find_node == 0)
  595. + goto mutex_failed;
  596. +
  597. /* finish the rest init. */
  598. ret = fsl_qspi_nor_setup_last(q);
  599. if (ret)
  600. --- a/drivers/mtd/spi-nor/spi-nor.c
  601. +++ b/drivers/mtd/spi-nor/spi-nor.c
  602. @@ -40,6 +40,13 @@
  603. #define SPI_NOR_MAX_ID_LEN 6
  604. #define SPI_NOR_MAX_ADDR_WIDTH 4
  605. +#define SPI_NOR_MICRON_WRITE_ENABLE 0x7f
  606. +/* Added for S25FS-S family flash */
  607. +#define SPINOR_CONFIG_REG3_OFFSET 0x800004
  608. +#define CR3V_4KB_ERASE_UNABLE 0x8
  609. +#define SPINOR_S25FS_FAMILY_ID 0x81
  610. +
  611. +
  612. struct flash_info {
  613. char *name;
  614. @@ -68,7 +75,8 @@ struct flash_info {
  615. #define SECT_4K_PMC BIT(4) /* SPINOR_OP_BE_4K_PMC works uniformly */
  616. #define SPI_NOR_DUAL_READ BIT(5) /* Flash supports Dual Read */
  617. #define SPI_NOR_QUAD_READ BIT(6) /* Flash supports Quad Read */
  618. -#define USE_FSR BIT(7) /* use flag status register */
  619. +#define USE_FSR BIT(13) /* use flag status register */
  620. +#define SPI_NOR_DDR_QUAD_READ BIT(7) /* Flash supports DDR Quad Read */
  621. #define SPI_NOR_HAS_LOCK BIT(8) /* Flash supports lock/unlock via SR */
  622. #define SPI_NOR_HAS_TB BIT(9) /*
  623. * Flash SR has Top/Bottom (TB) protect
  624. @@ -85,9 +93,11 @@ struct flash_info {
  625. * Use dedicated 4byte address op codes
  626. * to support memory size above 128Mib.
  627. */
  628. +#define NO_CHIP_ERASE BIT(12) /* Chip does not support chip erase */
  629. };
  630. #define JEDEC_MFR(info) ((info)->id[0])
  631. +#define EXT_ID(info) ((info)->id[5])
  632. static const struct flash_info *spi_nor_match_id(const char *name);
  633. @@ -132,7 +142,7 @@ static int read_fsr(struct spi_nor *nor)
  634. /*
  635. * Read configuration register, returning its value in the
  636. * location. Return the configuration register value.
  637. - * Returns negative if error occured.
  638. + * Returns negative if error occurred.
  639. */
  640. static int read_cr(struct spi_nor *nor)
  641. {
  642. @@ -160,6 +170,8 @@ static inline int spi_nor_read_dummy_cyc
  643. case SPI_NOR_DUAL:
  644. case SPI_NOR_QUAD:
  645. return 8;
  646. + case SPI_NOR_DDR_QUAD:
  647. + return 6;
  648. case SPI_NOR_NORMAL:
  649. return 0;
  650. }
  651. @@ -962,6 +974,8 @@ static const struct flash_info spi_nor_i
  652. /* ESMT */
  653. { "f25l32pa", INFO(0x8c2016, 0, 64 * 1024, 64, SECT_4K | SPI_NOR_HAS_LOCK) },
  654. + { "f25l32qa", INFO(0x8c4116, 0, 64 * 1024, 64, SECT_4K | SPI_NOR_HAS_LOCK) },
  655. + { "f25l64qa", INFO(0x8c4117, 0, 64 * 1024, 128, SECT_4K | SPI_NOR_HAS_LOCK) },
  656. /* Everspin */
  657. { "mr25h256", CAT25_INFO( 32 * 1024, 1, 256, 2, SPI_NOR_NO_ERASE | SPI_NOR_NO_FR) },
  658. @@ -1015,12 +1029,15 @@ static const struct flash_info spi_nor_i
  659. { "mx25l3205d", INFO(0xc22016, 0, 64 * 1024, 64, SECT_4K) },
  660. { "mx25l3255e", INFO(0xc29e16, 0, 64 * 1024, 64, SECT_4K) },
  661. { "mx25l6405d", INFO(0xc22017, 0, 64 * 1024, 128, SECT_4K) },
  662. + { "mx25u2033e", INFO(0xc22532, 0, 64 * 1024, 4, SECT_4K) },
  663. + { "mx25u4035", INFO(0xc22533, 0, 64 * 1024, 8, SECT_4K) },
  664. + { "mx25u8035", INFO(0xc22534, 0, 64 * 1024, 16, SECT_4K) },
  665. { "mx25u3235f", INFO(0xc22536, 0, 64 * 1024, 64, 0) },
  666. { "mx25u6435f", INFO(0xc22537, 0, 64 * 1024, 128, SECT_4K) },
  667. { "mx25l12805d", INFO(0xc22018, 0, 64 * 1024, 256, 0) },
  668. { "mx25l12855e", INFO(0xc22618, 0, 64 * 1024, 256, 0) },
  669. { "mx25l25635e", INFO(0xc22019, 0, 64 * 1024, 512, 0) },
  670. - { "mx25u25635f", INFO(0xc22539, 0, 64 * 1024, 512, SECT_4K | SPI_NOR_4B_OPCODES) },
  671. + { "mx25u25635f", INFO(0xc22539, 0, 64 * 1024, 512, SECT_4K) },
  672. { "mx25l25655e", INFO(0xc22619, 0, 64 * 1024, 512, 0) },
  673. { "mx66l51235l", INFO(0xc2201a, 0, 64 * 1024, 1024, SPI_NOR_QUAD_READ) },
  674. { "mx66l1g55g", INFO(0xc2261b, 0, 64 * 1024, 2048, SPI_NOR_QUAD_READ) },
  675. @@ -1034,10 +1051,11 @@ static const struct flash_info spi_nor_i
  676. { "n25q128a11", INFO(0x20bb18, 0, 64 * 1024, 256, SECT_4K | SPI_NOR_QUAD_READ) },
  677. { "n25q128a13", INFO(0x20ba18, 0, 64 * 1024, 256, SECT_4K | SPI_NOR_QUAD_READ) },
  678. { "n25q256a", INFO(0x20ba19, 0, 64 * 1024, 512, SECT_4K | SPI_NOR_QUAD_READ) },
  679. + { "n25q256ax1", INFO(0x20bb19, 0, 64 * 1024, 512, SECT_4K | SPI_NOR_QUAD_READ) },
  680. { "n25q512a", INFO(0x20bb20, 0, 64 * 1024, 1024, SECT_4K | USE_FSR | SPI_NOR_QUAD_READ) },
  681. { "n25q512ax3", INFO(0x20ba20, 0, 64 * 1024, 1024, SECT_4K | USE_FSR | SPI_NOR_QUAD_READ) },
  682. - { "n25q00", INFO(0x20ba21, 0, 64 * 1024, 2048, SECT_4K | USE_FSR | SPI_NOR_QUAD_READ) },
  683. - { "n25q00a", INFO(0x20bb21, 0, 64 * 1024, 2048, SECT_4K | USE_FSR | SPI_NOR_QUAD_READ) },
  684. + { "n25q00", INFO(0x20ba21, 0, 64 * 1024, 2048, SECT_4K | USE_FSR | SPI_NOR_QUAD_READ | NO_CHIP_ERASE) },
  685. + { "n25q00a", INFO(0x20bb21, 0, 64 * 1024, 2048, SECT_4K | USE_FSR | SPI_NOR_QUAD_READ | NO_CHIP_ERASE) },
  686. /* PMC */
  687. { "pm25lv512", INFO(0, 0, 32 * 1024, 2, SECT_4K_PMC) },
  688. @@ -1055,8 +1073,11 @@ static const struct flash_info spi_nor_i
  689. { "s70fl01gs", INFO(0x010221, 0x4d00, 256 * 1024, 256, 0) },
  690. { "s25sl12800", INFO(0x012018, 0x0300, 256 * 1024, 64, 0) },
  691. { "s25sl12801", INFO(0x012018, 0x0301, 64 * 1024, 256, 0) },
  692. - { "s25fl128s", INFO6(0x012018, 0x4d0180, 64 * 1024, 256, SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) },
  693. + { "s25fs256s1", INFO6(0x010219, 0x4d0181, 64 * 1024, 512, 0)},
  694. + { "s25fl128s", INFO6(0x012018, 0x4d0180, 64 * 1024, 256, SPI_NOR_QUAD_READ
  695. + | SPI_NOR_DDR_QUAD_READ) },
  696. { "s25fl129p0", INFO(0x012018, 0x4d00, 256 * 1024, 64, SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) },
  697. + { "s25fs512s", INFO6(0x010220, 0x4d0081, 256 * 1024, 256, SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ)},
  698. { "s25fl129p1", INFO(0x012018, 0x4d01, 64 * 1024, 256, SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) },
  699. { "s25sl004a", INFO(0x010212, 0, 64 * 1024, 8, 0) },
  700. { "s25sl008a", INFO(0x010213, 0, 64 * 1024, 16, 0) },
  701. @@ -1130,7 +1151,15 @@ static const struct flash_info spi_nor_i
  702. { "w25x40", INFO(0xef3013, 0, 64 * 1024, 8, SECT_4K) },
  703. { "w25x80", INFO(0xef3014, 0, 64 * 1024, 16, SECT_4K) },
  704. { "w25x16", INFO(0xef3015, 0, 64 * 1024, 32, SECT_4K) },
  705. + {
  706. + "w25q16dw", INFO(0xef6015, 0, 64 * 1024, 32,
  707. + SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ |
  708. + SPI_NOR_HAS_LOCK | SPI_NOR_HAS_TB)
  709. + },
  710. { "w25x32", INFO(0xef3016, 0, 64 * 1024, 64, SECT_4K) },
  711. + { "w25q20cl", INFO(0xef4012, 0, 64 * 1024, 4, SECT_4K) },
  712. + { "w25q20bw", INFO(0xef5012, 0, 64 * 1024, 4, SECT_4K) },
  713. + { "w25q20ew", INFO(0xef6012, 0, 64 * 1024, 4, SECT_4K) },
  714. { "w25q32", INFO(0xef4016, 0, 64 * 1024, 64, SECT_4K) },
  715. {
  716. "w25q32dw", INFO(0xef6016, 0, 64 * 1024, 64,
  717. @@ -1197,6 +1226,53 @@ static const struct flash_info *spi_nor_
  718. id[0], id[1], id[2]);
  719. return ERR_PTR(-ENODEV);
  720. }
  721. +/*
  722. + * The S25FS-S family physical sectors may be configured as a
  723. + * hybrid combination of eight 4-kB parameter sectors
  724. + * at the top or bottom of the address space with all
  725. + * but one of the remaining sectors being uniform size.
  726. + * The Parameter Sector Erase commands (20h or 21h) must
  727. + * be used to erase the 4-kB parameter sectors individually.
  728. + * The Sector (uniform sector) Erase commands (D8h or DCh)
  729. + * must be used to erase any of the remaining
  730. + * sectors, including the portion of highest or lowest address
  731. + * sector that is not overlaid by the parameter sectors.
  732. + * The uniform sector erase command has no effect on parameter sectors.
  733. + */
  734. +static int spansion_s25fs_disable_4kb_erase(struct spi_nor *nor)
  735. +{
  736. + struct fsl_qspi *q;
  737. + u32 cr3v_addr = SPINOR_CONFIG_REG3_OFFSET;
  738. + u8 cr3v = 0x0;
  739. + int ret = 0x0;
  740. +
  741. + q = nor->priv;
  742. +
  743. + nor->cmd_buf[2] = cr3v_addr >> 16;
  744. + nor->cmd_buf[1] = cr3v_addr >> 8;
  745. + nor->cmd_buf[0] = cr3v_addr >> 0;
  746. +
  747. + ret = nor->read_reg(nor, SPINOR_OP_SPANSION_RDAR, &cr3v, 1);
  748. + if (ret)
  749. + return ret;
  750. + if (cr3v & CR3V_4KB_ERASE_UNABLE)
  751. + return 0;
  752. + ret = nor->write_reg(nor, SPINOR_OP_WREN, NULL, 0);
  753. + if (ret)
  754. + return ret;
  755. + cr3v = CR3V_4KB_ERASE_UNABLE;
  756. + nor->program_opcode = SPINOR_OP_SPANSION_WRAR;
  757. + nor->write(nor, cr3v_addr, 1, &cr3v);
  758. +
  759. + ret = nor->read_reg(nor, SPINOR_OP_SPANSION_RDAR, &cr3v, 1);
  760. + if (ret)
  761. + return ret;
  762. + if (!(cr3v & CR3V_4KB_ERASE_UNABLE))
  763. + return -EPERM;
  764. +
  765. + return 0;
  766. +}
  767. +
  768. static int spi_nor_read(struct mtd_info *mtd, loff_t from, size_t len,
  769. size_t *retlen, u_char *buf)
  770. @@ -1416,7 +1492,7 @@ static int macronix_quad_enable(struct s
  771. * Write status Register and configuration register with 2 bytes
  772. * The first byte will be written to the status register, while the
  773. * second byte will be written to the configuration register.
  774. - * Return negative if error occured.
  775. + * Return negative if error occurred.
  776. */
  777. static int write_sr_cr(struct spi_nor *nor, u16 val)
  778. {
  779. @@ -1464,6 +1540,24 @@ static int spansion_quad_enable(struct s
  780. return 0;
  781. }
  782. +static int set_ddr_quad_mode(struct spi_nor *nor, const struct flash_info *info)
  783. +{
  784. + int status;
  785. +
  786. + switch (JEDEC_MFR(info)) {
  787. + case SNOR_MFR_SPANSION:
  788. + status = spansion_quad_enable(nor);
  789. + if (status) {
  790. + dev_err(nor->dev, "Spansion DDR quad-read not enabled\n");
  791. + return status;
  792. + }
  793. + return status;
  794. + default:
  795. + return -EINVAL;
  796. + }
  797. +}
  798. +
  799. +
  800. static int set_quad_mode(struct spi_nor *nor, const struct flash_info *info)
  801. {
  802. int status;
  803. @@ -1610,9 +1704,25 @@ int spi_nor_scan(struct spi_nor *nor, co
  804. write_sr(nor, 0);
  805. spi_nor_wait_till_ready(nor);
  806. }
  807. + if (JEDEC_MFR(info) == SNOR_MFR_MICRON) {
  808. + ret = read_sr(nor);
  809. + ret &= SPI_NOR_MICRON_WRITE_ENABLE;
  810. +
  811. + write_enable(nor);
  812. + write_sr(nor, ret);
  813. + }
  814. +
  815. + if (EXT_ID(info) == SPINOR_S25FS_FAMILY_ID) {
  816. + ret = spansion_s25fs_disable_4kb_erase(nor);
  817. + if (ret)
  818. + return ret;
  819. + }
  820. +
  821. if (!mtd->name)
  822. mtd->name = dev_name(dev);
  823. + if (info->name)
  824. + nor->vendor = info->name;
  825. mtd->priv = nor;
  826. mtd->type = MTD_NORFLASH;
  827. mtd->writesize = 1;
  828. @@ -1646,6 +1756,8 @@ int spi_nor_scan(struct spi_nor *nor, co
  829. nor->flags |= SNOR_F_USE_FSR;
  830. if (info->flags & SPI_NOR_HAS_TB)
  831. nor->flags |= SNOR_F_HAS_SR_TB;
  832. + if (info->flags & NO_CHIP_ERASE)
  833. + nor->flags |= SNOR_F_NO_OP_CHIP_ERASE;
  834. #ifdef CONFIG_MTD_SPI_NOR_USE_4K_SECTORS
  835. /* prefer "small sector" erase if possible */
  836. @@ -1685,9 +1797,15 @@ int spi_nor_scan(struct spi_nor *nor, co
  837. /* Some devices cannot do fast-read, no matter what DT tells us */
  838. if (info->flags & SPI_NOR_NO_FR)
  839. nor->flash_read = SPI_NOR_NORMAL;
  840. -
  841. - /* Quad/Dual-read mode takes precedence over fast/normal */
  842. - if (mode == SPI_NOR_QUAD && info->flags & SPI_NOR_QUAD_READ) {
  843. + /* DDR Quad/Quad/Dual-read mode takes precedence over fast/normal */
  844. + if (mode == SPI_NOR_DDR_QUAD && info->flags & SPI_NOR_DDR_QUAD_READ) {
  845. + ret = set_ddr_quad_mode(nor, info);
  846. + if (ret) {
  847. + dev_err(dev, "DDR quad mode not supported\n");
  848. + return ret;
  849. + }
  850. + nor->flash_read = SPI_NOR_DDR_QUAD;
  851. + } else if (mode == SPI_NOR_QUAD && info->flags & SPI_NOR_QUAD_READ) {
  852. ret = set_quad_mode(nor, info);
  853. if (ret) {
  854. dev_err(dev, "quad mode not supported\n");
  855. @@ -1700,6 +1818,9 @@ int spi_nor_scan(struct spi_nor *nor, co
  856. /* Default commands */
  857. switch (nor->flash_read) {
  858. + case SPI_NOR_DDR_QUAD:
  859. + nor->read_opcode = SPINOR_OP_READ4_1_4_4_D;
  860. + break;
  861. case SPI_NOR_QUAD:
  862. nor->read_opcode = SPINOR_OP_READ_1_1_4;
  863. break;
  864. --- a/include/linux/mtd/spi-nor.h
  865. +++ b/include/linux/mtd/spi-nor.h
  866. @@ -31,10 +31,10 @@
  867. /*
  868. * Note on opcode nomenclature: some opcodes have a format like
  869. - * SPINOR_OP_FUNCTION{4,}_x_y_z. The numbers x, y, and z stand for the number
  870. + * SPINOR_OP_FUNCTION{4,}_x_y_z{_D}. The numbers x, y,and z stand for the number
  871. * of I/O lines used for the opcode, address, and data (respectively). The
  872. * FUNCTION has an optional suffix of '4', to represent an opcode which
  873. - * requires a 4-byte (32-bit) address.
  874. + * requires a 4-byte (32-bit) address. The suffix of 'D' stands for the
  875. */
  876. /* Flash opcodes. */
  877. @@ -46,7 +46,9 @@
  878. #define SPINOR_OP_READ_1_1_2 0x3b /* Read data bytes (Dual Output SPI) */
  879. #define SPINOR_OP_READ_1_2_2 0xbb /* Read data bytes (Dual I/O SPI) */
  880. #define SPINOR_OP_READ_1_1_4 0x6b /* Read data bytes (Quad Output SPI) */
  881. +#define SPINOR_OP_READ_1_4_4_D 0xed /* Read data bytes (DDR Quad SPI) */
  882. #define SPINOR_OP_READ_1_4_4 0xeb /* Read data bytes (Quad I/O SPI) */
  883. +#define SPINOR_OP_READ4_1_4_4_D 0xee /* Read data bytes (DDR Quad SPI) */
  884. #define SPINOR_OP_PP 0x02 /* Page program (up to 256 bytes) */
  885. #define SPINOR_OP_PP_1_1_4 0x32 /* Quad page program */
  886. #define SPINOR_OP_PP_1_4_4 0x38 /* Quad page program */
  887. @@ -62,9 +64,11 @@
  888. /* 4-byte address opcodes - used on Spansion and some Macronix flashes. */
  889. #define SPINOR_OP_READ_4B 0x13 /* Read data bytes (low frequency) */
  890. #define SPINOR_OP_READ_FAST_4B 0x0c /* Read data bytes (high frequency) */
  891. +#define SPINOR_OP_READ4_FAST 0x0c /* Read data bytes (high frequency) */
  892. #define SPINOR_OP_READ_1_1_2_4B 0x3c /* Read data bytes (Dual Output SPI) */
  893. #define SPINOR_OP_READ_1_2_2_4B 0xbc /* Read data bytes (Dual I/O SPI) */
  894. #define SPINOR_OP_READ_1_1_4_4B 0x6c /* Read data bytes (Quad Output SPI) */
  895. +#define SPINOR_OP_READ4_1_1_4 0x6c /* Read data bytes (Quad SPI) */
  896. #define SPINOR_OP_READ_1_4_4_4B 0xec /* Read data bytes (Quad I/O SPI) */
  897. #define SPINOR_OP_PP_4B 0x12 /* Page program (up to 256 bytes) */
  898. #define SPINOR_OP_PP_1_1_4_4B 0x34 /* Quad page program */
  899. @@ -94,6 +98,10 @@
  900. /* Used for Spansion flashes only. */
  901. #define SPINOR_OP_BRWR 0x17 /* Bank register write */
  902. +/* Used for Spansion S25FS-S family flash only. */
  903. +#define SPINOR_OP_SPANSION_RDAR 0x65 /* Read any device register */
  904. +#define SPINOR_OP_SPANSION_WRAR 0x71 /* Write any device register */
  905. +
  906. /* Used for Micron flashes only. */
  907. #define SPINOR_OP_RD_EVCR 0x65 /* Read EVCR register */
  908. #define SPINOR_OP_WD_EVCR 0x61 /* Write EVCR register */
  909. @@ -124,6 +132,7 @@ enum read_mode {
  910. SPI_NOR_FAST,
  911. SPI_NOR_DUAL,
  912. SPI_NOR_QUAD,
  913. + SPI_NOR_DDR_QUAD,
  914. };
  915. #define SPI_NOR_MAX_CMD_SIZE 8
  916. @@ -189,6 +198,7 @@ struct spi_nor {
  917. bool sst_write_second;
  918. u32 flags;
  919. u8 cmd_buf[SPI_NOR_MAX_CMD_SIZE];
  920. + char *vendor;
  921. int (*prepare)(struct spi_nor *nor, enum spi_nor_ops ops);
  922. void (*unprepare)(struct spi_nor *nor, enum spi_nor_ops ops);