818-qspi-support-layerscape.patch 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774
  1. From 60eee49f37b77bc2d5f46c5db5a5c24d0c31bd02 Mon Sep 17 00:00:00 2001
  2. From: Biwen Li <[email protected]>
  3. Date: Tue, 20 Nov 2018 15:36:57 +0800
  4. Subject: [PATCH] qspi: support layerscape
  5. This is an integrated patch of qspi for layerscape
  6. Signed-off-by: Abhimanyu Saini <[email protected]>
  7. Signed-off-by: Cyrille Pitchen <[email protected]>
  8. Signed-off-by: Neil Armstrong <[email protected]>
  9. Signed-off-by: Prabhakar Kushwaha <[email protected]>
  10. Signed-off-by: Suresh Gupta <[email protected]>
  11. Signed-off-by: Yogesh Gaur <[email protected]>
  12. Signed-off-by: Biwen Li <[email protected]>
  13. Signed-off-by: Yangbo Lu <[email protected]>
  14. ---
  15. .../devicetree/bindings/mtd/fsl-quadspi.txt | 31 ++
  16. drivers/mtd/spi-nor/fsl-quadspi.c | 444 +++++++++++-------
  17. drivers/mtd/spi-nor/spi-nor.c | 5 +
  18. 3 files changed, 320 insertions(+), 160 deletions(-)
  19. --- a/Documentation/devicetree/bindings/mtd/fsl-quadspi.txt
  20. +++ b/Documentation/devicetree/bindings/mtd/fsl-quadspi.txt
  21. @@ -7,6 +7,7 @@ Required properties:
  22. or
  23. "fsl,ls2080a-qspi" followed by "fsl,ls1021a-qspi",
  24. "fsl,ls1043a-qspi" followed by "fsl,ls1021a-qspi"
  25. + "fsl,ls2080a-qspi" followed by "fsl,ls1088a-qspi",
  26. - reg : the first contains the register location and length,
  27. the second contains the memory mapping address and length
  28. - reg-names: Should contain the reg names "QuadSPI" and "QuadSPI-memory"
  29. @@ -39,3 +40,33 @@ qspi0: quadspi@40044000 {
  30. ....
  31. };
  32. };
  33. +
  34. +qspi1: quadspi@20c0000 {
  35. + #address-cells = <1>;
  36. + #size-cells = <0>;
  37. + reg = <0x0 0x20c0000 0x0 0x10000>,
  38. + <0x0 0x20000000 0x0 0x10000000>;
  39. + reg-names = "QuadSPI", "QuadSPI-memory";
  40. + interrupts = <0 25 0x4>; /* Level high type */
  41. + clocks = <&clockgen 4 3>, <&clockgen 4 3>;
  42. + clock-names = "qspi_en", "qspi";
  43. + status = "okay";
  44. +
  45. + qflash0: s25fs512s@0 {
  46. + #address-cells = <1>;
  47. + #size-cells = <1>;
  48. + spi-max-frequency = <20000000>;
  49. + reg = <0>;
  50. + spi-rx-bus-width = <4>;
  51. + spi-tx-bus-width = <4>;
  52. + };
  53. +
  54. + qflash1: s25fs512s@1 {
  55. + #address-cells = <1>;
  56. + #size-cells = <1>;
  57. + spi-max-frequency = <20000000>;
  58. + reg = <1>;
  59. + spi-rx-bus-width = <4>;
  60. + spi-tx-bus-width = <4>;
  61. + };
  62. +};
  63. --- a/drivers/mtd/spi-nor/fsl-quadspi.c
  64. +++ b/drivers/mtd/spi-nor/fsl-quadspi.c
  65. @@ -41,6 +41,7 @@
  66. #define QUADSPI_QUIRK_TKT253890 (1 << 2)
  67. /* Controller cannot wake up from wait mode, TKT245618 */
  68. #define QUADSPI_QUIRK_TKT245618 (1 << 3)
  69. +#define QUADSPI_ADDR_REMAP (1 << 4)
  70. /* The registers */
  71. #define QUADSPI_MCR 0x00
  72. @@ -183,7 +184,7 @@
  73. /* Macros for constructing the LUT register. */
  74. #define LUT0(ins, pad, opr) \
  75. - (((opr) << OPRND0_SHIFT) | ((LUT_##pad) << PAD0_SHIFT) | \
  76. + (((opr) << OPRND0_SHIFT) | ((pad) << PAD0_SHIFT) | \
  77. ((LUT_##ins) << INSTR0_SHIFT))
  78. #define LUT1(ins, pad, opr) (LUT0(ins, pad, opr) << OPRND1_SHIFT)
  79. @@ -193,27 +194,29 @@
  80. #define QUADSPI_LUT_NUM 64
  81. /* SEQID -- we can have 16 seqids at most. */
  82. -#define SEQID_READ 0
  83. -#define SEQID_WREN 1
  84. -#define SEQID_WRDI 2
  85. -#define SEQID_RDSR 3
  86. -#define SEQID_SE 4
  87. -#define SEQID_CHIP_ERASE 5
  88. -#define SEQID_PP 6
  89. -#define SEQID_RDID 7
  90. -#define SEQID_WRSR 8
  91. -#define SEQID_RDCR 9
  92. -#define SEQID_EN4B 10
  93. -#define SEQID_BRWR 11
  94. +/* LUT0 programmed by bootloader, for run-time create entry for LUT seqid 1 */
  95. +#define SEQID_LUT0_BOOTLOADER 0
  96. +#define SEQID_LUT1_RUNTIME 1
  97. +#define SEQID_LUT2_AHBREAD 2
  98. #define QUADSPI_MIN_IOMAP SZ_4M
  99. +enum fsl_qspi_ops {
  100. + FSL_QSPI_OPS_READ = 0,
  101. + FSL_QSPI_OPS_WRITE,
  102. + FSL_QSPI_OPS_ERASE,
  103. + FSL_QSPI_OPS_READ_REG,
  104. + FSL_QSPI_OPS_WRITE_REG,
  105. + FSL_QSPI_OPS_WRITE_BUF_REG,
  106. +};
  107. +
  108. enum fsl_qspi_devtype {
  109. FSL_QUADSPI_VYBRID,
  110. FSL_QUADSPI_IMX6SX,
  111. FSL_QUADSPI_IMX7D,
  112. FSL_QUADSPI_IMX6UL,
  113. FSL_QUADSPI_LS1021A,
  114. + FSL_QUADSPI_LS2080A,
  115. };
  116. struct fsl_qspi_devtype_data {
  117. @@ -267,6 +270,15 @@ static struct fsl_qspi_devtype_data ls10
  118. .driver_data = 0,
  119. };
  120. +static const struct fsl_qspi_devtype_data ls2080a_data = {
  121. + .devtype = FSL_QUADSPI_LS2080A,
  122. + .rxfifo = 128,
  123. + .txfifo = 64,
  124. + .ahb_buf_size = 1024,
  125. + .driver_data = QUADSPI_QUIRK_TKT253890 | QUADSPI_ADDR_REMAP,
  126. +};
  127. +
  128. +
  129. #define FSL_QSPI_MAX_CHIP 4
  130. struct fsl_qspi {
  131. struct spi_nor nor[FSL_QSPI_MAX_CHIP];
  132. @@ -310,6 +322,22 @@ static inline int needs_wakeup_wait_mode
  133. }
  134. /*
  135. + * QSPI memory regions split into two parts: a 256MB region that is located
  136. + * in the least significant 4GB of the SoC address space and a 3.75GB region
  137. + * that is located above the least significant 4GB of the SoC address space.
  138. + *
  139. + * The 4GB QSPI address space map is shown below.
  140. + *
  141. + * SoC Address QSPI Address
  142. + * 0x00_2000_0000-0x00_2FFF_FFFF 0x00_0000_0000-0x00_0FFF_FFFF First 256MB
  143. + * 0x04_1000_0000-0x04_FFFF_FFFF 0x00_1000_0000-0x00_FFFF_FFFF Last 3.75GB
  144. + */
  145. +static inline int need_address_remap(struct fsl_qspi *q)
  146. +{
  147. + return q->devtype_data->driver_data & QUADSPI_ADDR_REMAP;
  148. +}
  149. +
  150. +/*
  151. * R/W functions for big- or little-endian registers:
  152. * The qSPI controller's endian is independent of the CPU core's endian.
  153. * So far, although the CPU core is little-endian but the qSPI have two
  154. @@ -368,137 +396,160 @@ static irqreturn_t fsl_qspi_irq_handler(
  155. return IRQ_HANDLED;
  156. }
  157. -static void fsl_qspi_init_lut(struct fsl_qspi *q)
  158. +static inline s8 pad_count(s8 pad_val)
  159. {
  160. + s8 count = -1;
  161. +
  162. + if (!pad_val)
  163. + return 0;
  164. +
  165. + while (pad_val) {
  166. + pad_val >>= 1;
  167. + count++;
  168. + }
  169. + return count;
  170. +}
  171. +
  172. +/*
  173. + * Prepare LUT entry for the input cmd.
  174. + * Protocol info is present in instance of struct spi_nor, using which fields
  175. + * like cmd, data, addrlen along with pad info etc can be parsed.
  176. + */
  177. +static void fsl_qspi_prepare_lut(struct spi_nor *nor,
  178. + enum fsl_qspi_ops ops, u8 cmd)
  179. +{
  180. + struct fsl_qspi *q = nor->priv;
  181. void __iomem *base = q->iobase;
  182. int rxfifo = q->devtype_data->rxfifo;
  183. + int txfifo = q->devtype_data->txfifo;
  184. u32 lut_base;
  185. - int i;
  186. + u8 cmd_pad, addr_pad, data_pad, dummy_pad;
  187. + enum spi_nor_protocol protocol = 0;
  188. + u8 addrlen = 0;
  189. + u8 read_dm, opcode;
  190. + int stop_lut;
  191. +
  192. + read_dm = opcode = cmd_pad = addr_pad = data_pad = dummy_pad = 0;
  193. +
  194. + switch (ops) {
  195. + case FSL_QSPI_OPS_READ_REG:
  196. + case FSL_QSPI_OPS_WRITE_REG:
  197. + case FSL_QSPI_OPS_WRITE_BUF_REG:
  198. + opcode = cmd;
  199. + protocol = nor->reg_proto;
  200. + break;
  201. + case FSL_QSPI_OPS_READ:
  202. + opcode = cmd;
  203. + read_dm = nor->read_dummy;
  204. + protocol = nor->read_proto;
  205. + break;
  206. + case FSL_QSPI_OPS_WRITE:
  207. + opcode = cmd;
  208. + protocol = nor->write_proto;
  209. + break;
  210. + case FSL_QSPI_OPS_ERASE:
  211. + opcode = cmd;
  212. + break;
  213. + default:
  214. + dev_err(q->dev, "Unsupported operation 0x%.2x\n", ops);
  215. + return;
  216. + }
  217. +
  218. + if (protocol) {
  219. + cmd_pad = spi_nor_get_protocol_inst_nbits(protocol);
  220. + addr_pad = spi_nor_get_protocol_addr_nbits(protocol);
  221. + data_pad = spi_nor_get_protocol_data_nbits(protocol);
  222. + }
  223. +
  224. + dummy_pad = data_pad;
  225. - struct spi_nor *nor = &q->nor[0];
  226. - u8 addrlen = (nor->addr_width == 3) ? ADDR24BIT : ADDR32BIT;
  227. - u8 read_op = nor->read_opcode;
  228. - u8 read_dm = nor->read_dummy;
  229. + dev_dbg(q->dev, "ops:%x opcode:%x pad[cmd:%d, addr:%d, data:%d]\n",
  230. + ops, opcode, cmd_pad, addr_pad, data_pad);
  231. fsl_qspi_unlock_lut(q);
  232. - /* Clear all the LUT table */
  233. - for (i = 0; i < QUADSPI_LUT_NUM; i++)
  234. - qspi_writel(q, 0, base + QUADSPI_LUT_BASE + i * 4);
  235. -
  236. - /* Read */
  237. - lut_base = SEQID_READ * 4;
  238. -
  239. - qspi_writel(q, LUT0(CMD, PAD1, read_op) | LUT1(ADDR, PAD1, addrlen),
  240. - base + QUADSPI_LUT(lut_base));
  241. - qspi_writel(q, LUT0(DUMMY, PAD1, read_dm) |
  242. - LUT1(FSL_READ, PAD4, rxfifo),
  243. - base + QUADSPI_LUT(lut_base + 1));
  244. -
  245. - /* Write enable */
  246. - lut_base = SEQID_WREN * 4;
  247. - qspi_writel(q, LUT0(CMD, PAD1, SPINOR_OP_WREN),
  248. - base + QUADSPI_LUT(lut_base));
  249. -
  250. - /* Page Program */
  251. - lut_base = SEQID_PP * 4;
  252. -
  253. - qspi_writel(q, LUT0(CMD, PAD1, nor->program_opcode) |
  254. - LUT1(ADDR, PAD1, addrlen),
  255. - base + QUADSPI_LUT(lut_base));
  256. - qspi_writel(q, LUT0(FSL_WRITE, PAD1, 0),
  257. - base + QUADSPI_LUT(lut_base + 1));
  258. -
  259. - /* Read Status */
  260. - lut_base = SEQID_RDSR * 4;
  261. - qspi_writel(q, LUT0(CMD, PAD1, SPINOR_OP_RDSR) |
  262. - LUT1(FSL_READ, PAD1, 0x1),
  263. - base + QUADSPI_LUT(lut_base));
  264. -
  265. - /* Erase a sector */
  266. - lut_base = SEQID_SE * 4;
  267. -
  268. - qspi_writel(q, LUT0(CMD, PAD1, nor->erase_opcode) |
  269. - LUT1(ADDR, PAD1, addrlen),
  270. - base + QUADSPI_LUT(lut_base));
  271. -
  272. - /* Erase the whole chip */
  273. - lut_base = SEQID_CHIP_ERASE * 4;
  274. - qspi_writel(q, LUT0(CMD, PAD1, SPINOR_OP_CHIP_ERASE),
  275. - base + QUADSPI_LUT(lut_base));
  276. -
  277. - /* READ ID */
  278. - lut_base = SEQID_RDID * 4;
  279. - qspi_writel(q, LUT0(CMD, PAD1, SPINOR_OP_RDID) |
  280. - LUT1(FSL_READ, PAD1, 0x8),
  281. - base + QUADSPI_LUT(lut_base));
  282. -
  283. - /* Write Register */
  284. - lut_base = SEQID_WRSR * 4;
  285. - qspi_writel(q, LUT0(CMD, PAD1, SPINOR_OP_WRSR) |
  286. - LUT1(FSL_WRITE, PAD1, 0x2),
  287. - base + QUADSPI_LUT(lut_base));
  288. -
  289. - /* Read Configuration Register */
  290. - lut_base = SEQID_RDCR * 4;
  291. - qspi_writel(q, LUT0(CMD, PAD1, SPINOR_OP_RDCR) |
  292. - LUT1(FSL_READ, PAD1, 0x1),
  293. - base + QUADSPI_LUT(lut_base));
  294. -
  295. - /* Write disable */
  296. - lut_base = SEQID_WRDI * 4;
  297. - qspi_writel(q, LUT0(CMD, PAD1, SPINOR_OP_WRDI),
  298. - base + QUADSPI_LUT(lut_base));
  299. -
  300. - /* Enter 4 Byte Mode (Micron) */
  301. - lut_base = SEQID_EN4B * 4;
  302. - qspi_writel(q, LUT0(CMD, PAD1, SPINOR_OP_EN4B),
  303. - base + QUADSPI_LUT(lut_base));
  304. -
  305. - /* Enter 4 Byte Mode (Spansion) */
  306. - lut_base = SEQID_BRWR * 4;
  307. - qspi_writel(q, LUT0(CMD, PAD1, SPINOR_OP_BRWR),
  308. - base + QUADSPI_LUT(lut_base));
  309. + /* Dynamic LUT */
  310. + lut_base = SEQID_LUT1_RUNTIME * 4;
  311. + if (ops == FSL_QSPI_OPS_READ)
  312. + lut_base = SEQID_LUT2_AHBREAD * 4;
  313. +
  314. + /* default, STOP instruction to be programmed in (lut_base + 1) reg */
  315. + stop_lut = 1;
  316. + switch (ops) {
  317. + case FSL_QSPI_OPS_READ_REG:
  318. + qspi_writel(q, LUT0(CMD, pad_count(cmd_pad), opcode) |
  319. + LUT1(FSL_READ, pad_count(data_pad), rxfifo),
  320. + base + QUADSPI_LUT(lut_base));
  321. + break;
  322. + case FSL_QSPI_OPS_WRITE_REG:
  323. + qspi_writel(q, LUT0(CMD, pad_count(cmd_pad), opcode),
  324. + base + QUADSPI_LUT(lut_base));
  325. + break;
  326. + case FSL_QSPI_OPS_WRITE_BUF_REG:
  327. + qspi_writel(q, LUT0(CMD, pad_count(cmd_pad), opcode) |
  328. + LUT1(FSL_WRITE, pad_count(data_pad), txfifo),
  329. + base + QUADSPI_LUT(lut_base));
  330. + break;
  331. + case FSL_QSPI_OPS_READ:
  332. + case FSL_QSPI_OPS_WRITE:
  333. + case FSL_QSPI_OPS_ERASE:
  334. + /* Common for Read, Write and Erase ops. */
  335. +
  336. + addrlen = (nor->addr_width == 3) ? ADDR24BIT : ADDR32BIT;
  337. +
  338. + qspi_writel(q, LUT0(CMD, pad_count(cmd_pad), opcode) |
  339. + LUT1(ADDR, pad_count(addr_pad), addrlen),
  340. + base + QUADSPI_LUT(lut_base));
  341. + /*
  342. + * For Erase ops - Data and Dummy not required.
  343. + * For Write ops - Dummy not required.
  344. + */
  345. - fsl_qspi_lock_lut(q);
  346. -}
  347. + if (ops == FSL_QSPI_OPS_READ) {
  348. -/* Get the SEQID for the command */
  349. -static int fsl_qspi_get_seqid(struct fsl_qspi *q, u8 cmd)
  350. -{
  351. - switch (cmd) {
  352. - case SPINOR_OP_READ_1_1_4:
  353. - case SPINOR_OP_READ_1_1_4_4B:
  354. - return SEQID_READ;
  355. - case SPINOR_OP_WREN:
  356. - return SEQID_WREN;
  357. - case SPINOR_OP_WRDI:
  358. - return SEQID_WRDI;
  359. - case SPINOR_OP_RDSR:
  360. - return SEQID_RDSR;
  361. - case SPINOR_OP_SE:
  362. - return SEQID_SE;
  363. - case SPINOR_OP_CHIP_ERASE:
  364. - return SEQID_CHIP_ERASE;
  365. - case SPINOR_OP_PP:
  366. - return SEQID_PP;
  367. - case SPINOR_OP_RDID:
  368. - return SEQID_RDID;
  369. - case SPINOR_OP_WRSR:
  370. - return SEQID_WRSR;
  371. - case SPINOR_OP_RDCR:
  372. - return SEQID_RDCR;
  373. - case SPINOR_OP_EN4B:
  374. - return SEQID_EN4B;
  375. - case SPINOR_OP_BRWR:
  376. - return SEQID_BRWR;
  377. + /*
  378. + * For cmds SPINOR_OP_READ and SPINOR_OP_READ_4B value
  379. + * of dummy cycles are 0.
  380. + */
  381. + if (read_dm)
  382. + qspi_writel(q,
  383. + LUT0(DUMMY, pad_count(dummy_pad),
  384. + read_dm) |
  385. + LUT1(FSL_READ, pad_count(data_pad),
  386. + rxfifo),
  387. + base + QUADSPI_LUT(lut_base + 1));
  388. + else
  389. + qspi_writel(q,
  390. + LUT0(FSL_READ, pad_count(data_pad),
  391. + rxfifo),
  392. + base + QUADSPI_LUT(lut_base + 1));
  393. +
  394. + stop_lut = 2;
  395. +
  396. + /* TODO Add condition to check if READ is IP/AHB. */
  397. +
  398. + /* For AHB read, add seqid in BFGENCR register. */
  399. + qspi_writel(q,
  400. + SEQID_LUT2_AHBREAD <<
  401. + QUADSPI_BFGENCR_SEQID_SHIFT,
  402. + q->iobase + QUADSPI_BFGENCR);
  403. + }
  404. +
  405. + if (ops == FSL_QSPI_OPS_WRITE) {
  406. + qspi_writel(q, LUT0(FSL_WRITE, pad_count(data_pad), 0),
  407. + base + QUADSPI_LUT(lut_base + 1));
  408. + stop_lut = 2;
  409. + }
  410. + break;
  411. default:
  412. - if (cmd == q->nor[0].erase_opcode)
  413. - return SEQID_SE;
  414. - dev_err(q->dev, "Unsupported cmd 0x%.2x\n", cmd);
  415. + dev_err(q->dev, "Unsupported operation 0x%.2x\n", ops);
  416. break;
  417. }
  418. - return -EINVAL;
  419. +
  420. + /* prepare LUT for STOP instruction. */
  421. + qspi_writel(q, 0, base + QUADSPI_LUT(lut_base + stop_lut));
  422. +
  423. + fsl_qspi_lock_lut(q);
  424. }
  425. static int
  426. @@ -508,6 +559,10 @@ fsl_qspi_runcmd(struct fsl_qspi *q, u8 c
  427. int seqid;
  428. u32 reg, reg2;
  429. int err;
  430. + u32 memmap_phyadd = q->memmap_phy;
  431. +
  432. + if (need_address_remap(q))
  433. + memmap_phyadd = 0;
  434. init_completion(&q->c);
  435. dev_dbg(q->dev, "to 0x%.8x:0x%.8x, len:%d, cmd:%.2x\n",
  436. @@ -516,7 +571,7 @@ fsl_qspi_runcmd(struct fsl_qspi *q, u8 c
  437. /* save the reg */
  438. reg = qspi_readl(q, base + QUADSPI_MCR);
  439. - qspi_writel(q, q->memmap_phy + q->chip_base_addr + addr,
  440. + qspi_writel(q, memmap_phyadd + q->chip_base_addr + addr,
  441. base + QUADSPI_SFAR);
  442. qspi_writel(q, QUADSPI_RBCT_WMRK_MASK | QUADSPI_RBCT_RXBRD_USEIPS,
  443. base + QUADSPI_RBCT);
  444. @@ -533,7 +588,7 @@ fsl_qspi_runcmd(struct fsl_qspi *q, u8 c
  445. } while (1);
  446. /* trigger the LUT now */
  447. - seqid = fsl_qspi_get_seqid(q, cmd);
  448. + seqid = SEQID_LUT1_RUNTIME;
  449. qspi_writel(q, (seqid << QUADSPI_IPCR_SEQID_SHIFT) | len,
  450. base + QUADSPI_IPCR);
  451. @@ -609,6 +664,7 @@ static ssize_t fsl_qspi_nor_write(struct
  452. {
  453. int ret, i, j;
  454. u32 tmp;
  455. + u8 byts;
  456. dev_dbg(q->dev, "to 0x%.8x:0x%.8x, len : %d\n",
  457. q->chip_base_addr, to, count);
  458. @@ -618,10 +674,18 @@ static ssize_t fsl_qspi_nor_write(struct
  459. qspi_writel(q, tmp | QUADSPI_MCR_CLR_TXF_MASK, q->iobase + QUADSPI_MCR);
  460. /* fill the TX data to the FIFO */
  461. + byts = count;
  462. for (j = 0, i = ((count + 3) / 4); j < i; j++) {
  463. - tmp = fsl_qspi_endian_xchg(q, *txbuf);
  464. + if(byts >= 4)
  465. + tmp = fsl_qspi_endian_xchg(q, *txbuf);
  466. + else {
  467. + memcpy(&tmp, txbuf, byts);
  468. + tmp = fsl_qspi_endian_xchg(q, tmp);
  469. + }
  470. +
  471. qspi_writel(q, tmp, q->iobase + QUADSPI_TBDR);
  472. txbuf++;
  473. + byts -= 4;
  474. }
  475. /* fill the TXFIFO upto 16 bytes for i.MX7d */
  476. @@ -642,11 +706,15 @@ static void fsl_qspi_set_map_addr(struct
  477. {
  478. int nor_size = q->nor_size;
  479. void __iomem *base = q->iobase;
  480. + u32 memmap_phyadd = q->memmap_phy;
  481. +
  482. + if (need_address_remap(q))
  483. + memmap_phyadd = 0;
  484. - qspi_writel(q, nor_size + q->memmap_phy, base + QUADSPI_SFA1AD);
  485. - qspi_writel(q, nor_size * 2 + q->memmap_phy, base + QUADSPI_SFA2AD);
  486. - qspi_writel(q, nor_size * 3 + q->memmap_phy, base + QUADSPI_SFB1AD);
  487. - qspi_writel(q, nor_size * 4 + q->memmap_phy, base + QUADSPI_SFB2AD);
  488. + qspi_writel(q, nor_size + memmap_phyadd, base + QUADSPI_SFA1AD);
  489. + qspi_writel(q, nor_size * 2 + memmap_phyadd, base + QUADSPI_SFA2AD);
  490. + qspi_writel(q, nor_size * 3 + memmap_phyadd, base + QUADSPI_SFB1AD);
  491. + qspi_writel(q, nor_size * 4 + memmap_phyadd, base + QUADSPI_SFB2AD);
  492. }
  493. /*
  494. @@ -662,7 +730,7 @@ static void fsl_qspi_set_map_addr(struct
  495. * causes the controller to clear the buffer, and use the sequence pointed
  496. * by the QUADSPI_BFGENCR[SEQID] to initiate a read from the flash.
  497. */
  498. -static void fsl_qspi_init_abh_read(struct fsl_qspi *q)
  499. +static void fsl_qspi_init_ahb_read(struct fsl_qspi *q)
  500. {
  501. void __iomem *base = q->iobase;
  502. int seqid;
  503. @@ -685,8 +753,8 @@ static void fsl_qspi_init_abh_read(struc
  504. qspi_writel(q, 0, base + QUADSPI_BUF1IND);
  505. qspi_writel(q, 0, base + QUADSPI_BUF2IND);
  506. - /* Set the default lut sequence for AHB Read. */
  507. - seqid = fsl_qspi_get_seqid(q, q->nor[0].read_opcode);
  508. + /* Set dynamic LUT entry as lut sequence for AHB Read . */
  509. + seqid = SEQID_LUT2_AHBREAD;
  510. qspi_writel(q, seqid << QUADSPI_BFGENCR_SEQID_SHIFT,
  511. q->iobase + QUADSPI_BFGENCR);
  512. }
  513. @@ -729,7 +797,6 @@ static int fsl_qspi_nor_setup(struct fsl
  514. void __iomem *base = q->iobase;
  515. u32 reg;
  516. int ret;
  517. -
  518. /* disable and unprepare clock to avoid glitch pass to controller */
  519. fsl_qspi_clk_disable_unprep(q);
  520. @@ -747,9 +814,6 @@ static int fsl_qspi_nor_setup(struct fsl
  521. base + QUADSPI_MCR);
  522. udelay(1);
  523. - /* Init the LUT table. */
  524. - fsl_qspi_init_lut(q);
  525. -
  526. /* Disable the module */
  527. qspi_writel(q, QUADSPI_MCR_MDIS_MASK | QUADSPI_MCR_RESERVED_MASK,
  528. base + QUADSPI_MCR);
  529. @@ -770,6 +834,9 @@ static int fsl_qspi_nor_setup(struct fsl
  530. /* enable the interrupt */
  531. qspi_writel(q, QUADSPI_RSER_TFIE, q->iobase + QUADSPI_RSER);
  532. + /* Init for AHB read */
  533. + fsl_qspi_init_ahb_read(q);
  534. +
  535. return 0;
  536. }
  537. @@ -792,12 +859,6 @@ static int fsl_qspi_nor_setup_last(struc
  538. if (ret)
  539. return ret;
  540. - /* Init the LUT table again. */
  541. - fsl_qspi_init_lut(q);
  542. -
  543. - /* Init for AHB read */
  544. - fsl_qspi_init_abh_read(q);
  545. -
  546. return 0;
  547. }
  548. @@ -807,6 +868,7 @@ static const struct of_device_id fsl_qsp
  549. { .compatible = "fsl,imx7d-qspi", .data = (void *)&imx7d_data, },
  550. { .compatible = "fsl,imx6ul-qspi", .data = (void *)&imx6ul_data, },
  551. { .compatible = "fsl,ls1021a-qspi", .data = (void *)&ls1021a_data, },
  552. + { .compatible = "fsl,ls2080a-qspi", .data = &ls2080a_data, },
  553. { /* sentinel */ }
  554. };
  555. MODULE_DEVICE_TABLE(of, fsl_qspi_dt_ids);
  556. @@ -821,6 +883,7 @@ static int fsl_qspi_read_reg(struct spi_
  557. int ret;
  558. struct fsl_qspi *q = nor->priv;
  559. + fsl_qspi_prepare_lut(nor, FSL_QSPI_OPS_READ_REG, opcode);
  560. ret = fsl_qspi_runcmd(q, opcode, 0, len);
  561. if (ret)
  562. return ret;
  563. @@ -835,6 +898,8 @@ static int fsl_qspi_write_reg(struct spi
  564. int ret;
  565. if (!buf) {
  566. + /* Prepare LUT for WRITE_REG cmd with input BUF as NULL. */
  567. + fsl_qspi_prepare_lut(nor, FSL_QSPI_OPS_WRITE_REG, opcode);
  568. ret = fsl_qspi_runcmd(q, opcode, 0, 1);
  569. if (ret)
  570. return ret;
  571. @@ -843,6 +908,8 @@ static int fsl_qspi_write_reg(struct spi
  572. fsl_qspi_invalid(q);
  573. } else if (len > 0) {
  574. + /* Prepare LUT for WRITE_REG cmd with input BUF non-NULL. */
  575. + fsl_qspi_prepare_lut(nor, FSL_QSPI_OPS_WRITE_BUF_REG, opcode);
  576. ret = fsl_qspi_nor_write(q, nor, opcode, 0,
  577. (u32 *)buf, len);
  578. if (ret > 0)
  579. @@ -859,8 +926,11 @@ static ssize_t fsl_qspi_write(struct spi
  580. size_t len, const u_char *buf)
  581. {
  582. struct fsl_qspi *q = nor->priv;
  583. - ssize_t ret = fsl_qspi_nor_write(q, nor, nor->program_opcode, to,
  584. - (u32 *)buf, len);
  585. + ssize_t ret;
  586. +
  587. + fsl_qspi_prepare_lut(nor, FSL_QSPI_OPS_WRITE, nor->program_opcode);
  588. + ret = fsl_qspi_nor_write(q, nor, nor->program_opcode, to,
  589. + (u32 *)buf, len);
  590. /* invalid the data in the AHB buffer. */
  591. fsl_qspi_invalid(q);
  592. @@ -873,6 +943,8 @@ static ssize_t fsl_qspi_read(struct spi_
  593. struct fsl_qspi *q = nor->priv;
  594. u8 cmd = nor->read_opcode;
  595. + fsl_qspi_prepare_lut(nor, FSL_QSPI_OPS_READ, nor->read_opcode);
  596. +
  597. /* if necessary,ioremap buffer before AHB read, */
  598. if (!q->ahb_addr) {
  599. q->memmap_offs = q->chip_base_addr + from;
  600. @@ -907,8 +979,9 @@ static ssize_t fsl_qspi_read(struct spi_
  601. len);
  602. /* Read out the data directly from the AHB buffer.*/
  603. - memcpy(buf, q->ahb_addr + q->chip_base_addr + from - q->memmap_offs,
  604. - len);
  605. + memcpy_fromio(buf,
  606. + q->ahb_addr + q->chip_base_addr + from - q->memmap_offs,
  607. + len);
  608. return len;
  609. }
  610. @@ -921,6 +994,7 @@ static int fsl_qspi_erase(struct spi_nor
  611. dev_dbg(nor->dev, "%dKiB at 0x%08x:0x%08x\n",
  612. nor->mtd.erasesize / 1024, q->chip_base_addr, (u32)offs);
  613. + fsl_qspi_prepare_lut(nor, FSL_QSPI_OPS_ERASE, nor->erase_opcode);
  614. ret = fsl_qspi_runcmd(q, nor->erase_opcode, offs, 0);
  615. if (ret)
  616. return ret;
  617. @@ -958,17 +1032,14 @@ static void fsl_qspi_unprep(struct spi_n
  618. static int fsl_qspi_probe(struct platform_device *pdev)
  619. {
  620. - const struct spi_nor_hwcaps hwcaps = {
  621. - .mask = SNOR_HWCAPS_READ_1_1_4 |
  622. - SNOR_HWCAPS_PP,
  623. - };
  624. + struct spi_nor_hwcaps hwcaps;
  625. struct device_node *np = pdev->dev.of_node;
  626. struct device *dev = &pdev->dev;
  627. struct fsl_qspi *q;
  628. struct resource *res;
  629. struct spi_nor *nor;
  630. struct mtd_info *mtd;
  631. - int ret, i = 0;
  632. + int ret, i = 0, value;
  633. q = devm_kzalloc(dev, sizeof(*q), GFP_KERNEL);
  634. if (!q)
  635. @@ -1041,6 +1112,10 @@ static int fsl_qspi_probe(struct platfor
  636. /* iterate the subnodes. */
  637. for_each_available_child_of_node(dev->of_node, np) {
  638. + /* Reset hwcaps mask to minimal caps for the slave node. */
  639. + hwcaps.mask = SNOR_HWCAPS_READ | SNOR_HWCAPS_PP;
  640. + value = 0;
  641. +
  642. /* skip the holes */
  643. if (!q->has_second_chip)
  644. i *= 2;
  645. @@ -1070,6 +1145,51 @@ static int fsl_qspi_probe(struct platfor
  646. /* set the chip address for READID */
  647. fsl_qspi_set_base_addr(q, nor);
  648. + /*
  649. + * If spi-rx-bus-width and spi-tx-bus-width not defined assign
  650. + * default hardware capabilities SNOR_HWCAPS_READ_1_1_4 and
  651. + * SNOR_HWCAPS_PP supported by the Quad-SPI controller.
  652. + */
  653. + if (!of_property_read_u32(np, "spi-rx-bus-width", &value)) {
  654. + switch (value) {
  655. + case 1:
  656. + hwcaps.mask |= SNOR_HWCAPS_READ |
  657. + SNOR_HWCAPS_READ_FAST;
  658. + break;
  659. + case 2:
  660. + hwcaps.mask |= SNOR_HWCAPS_READ_1_1_2 |
  661. + SNOR_HWCAPS_READ_1_2_2;
  662. + break;
  663. + case 4:
  664. + hwcaps.mask |= SNOR_HWCAPS_READ_1_1_4 |
  665. + SNOR_HWCAPS_READ_1_4_4;
  666. + break;
  667. + default:
  668. + dev_err(dev,
  669. + "spi-rx-bus-width %d not supported\n",
  670. + value);
  671. + break;
  672. + }
  673. + } else
  674. + hwcaps.mask |= SNOR_HWCAPS_READ_1_1_4;
  675. +
  676. + if (!of_property_read_u32(np, "spi-tx-bus-width", &value)) {
  677. + switch (value) {
  678. + case 1:
  679. + hwcaps.mask |= SNOR_HWCAPS_PP;
  680. + break;
  681. + case 4:
  682. + hwcaps.mask |= SNOR_HWCAPS_PP_1_1_4 |
  683. + SNOR_HWCAPS_PP_1_4_4;
  684. + break;
  685. + default:
  686. + dev_err(dev,
  687. + "spi-tx-bus-width %d not supported\n",
  688. + value);
  689. + break;
  690. + }
  691. + }
  692. +
  693. ret = spi_nor_scan(nor, NULL, &hwcaps);
  694. if (ret)
  695. goto mutex_failed;
  696. @@ -1098,6 +1218,8 @@ static int fsl_qspi_probe(struct platfor
  697. if (nor->page_size > q->devtype_data->txfifo)
  698. nor->page_size = q->devtype_data->txfifo;
  699. + /*required for memory mapped AHB read*/
  700. + fsl_qspi_prepare_lut(nor, FSL_QSPI_OPS_READ, nor->read_opcode);
  701. i++;
  702. }
  703. @@ -1106,6 +1228,8 @@ static int fsl_qspi_probe(struct platfor
  704. if (ret)
  705. goto last_init_failed;
  706. +
  707. +
  708. fsl_qspi_clk_disable_unprep(q);
  709. return 0;
  710. --- a/drivers/mtd/spi-nor/spi-nor.c
  711. +++ b/drivers/mtd/spi-nor/spi-nor.c
  712. @@ -1147,6 +1147,11 @@ static const struct flash_info spi_nor_i
  713. { "w25x40", INFO(0xef3013, 0, 64 * 1024, 8, SECT_4K) },
  714. { "w25x80", INFO(0xef3014, 0, 64 * 1024, 16, SECT_4K) },
  715. { "w25x16", INFO(0xef3015, 0, 64 * 1024, 32, SECT_4K) },
  716. + {
  717. + "w25q16dw", INFO(0xef6015, 0, 64 * 1024, 32,
  718. + SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ |
  719. + SPI_NOR_HAS_LOCK | SPI_NOR_HAS_TB)
  720. + },
  721. { "w25x32", INFO(0xef3016, 0, 64 * 1024, 64, SECT_4K) },
  722. { "w25q20cl", INFO(0xef4012, 0, 64 * 1024, 4, SECT_4K) },
  723. { "w25q20bw", INFO(0xef5012, 0, 64 * 1024, 4, SECT_4K) },