PageRenderTime 51ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/drivers/spi/stm32_qspi.c

https://bitbucket.org/hldspb/uboot-sbc8600
C | 650 lines | 502 code | 119 blank | 29 comment | 64 complexity | b8ae2df50c82ef5dde8f297c45f616af MD5 | raw file
  1. /*
  2. * (C) Copyright 2016
  3. *
  4. * Michael Kurz, <michi.kurz@gmail.com>
  5. *
  6. * STM32 QSPI driver
  7. *
  8. * SPDX-License-Identifier: GPL-2.0+
  9. */
  10. #include <common.h>
  11. #include <malloc.h>
  12. #include <spi.h>
  13. #include <spi_flash.h>
  14. #include <asm/io.h>
  15. #include <dm.h>
  16. #include <errno.h>
  17. #include <asm/arch/stm32.h>
  18. #include <asm/arch/stm32_defs.h>
  19. #include <clk.h>
  20. DECLARE_GLOBAL_DATA_PTR;
  21. struct stm32_qspi_regs {
  22. u32 cr; /* 0x00 */
  23. u32 dcr; /* 0x04 */
  24. u32 sr; /* 0x08 */
  25. u32 fcr; /* 0x0C */
  26. u32 dlr; /* 0x10 */
  27. u32 ccr; /* 0x14 */
  28. u32 ar; /* 0x18 */
  29. u32 abr; /* 0x1C */
  30. u32 dr; /* 0x20 */
  31. u32 psmkr; /* 0x24 */
  32. u32 psmar; /* 0x28 */
  33. u32 pir; /* 0x2C */
  34. u32 lptr; /* 0x30 */
  35. };
  36. /*
  37. * QUADSPI control register
  38. */
  39. #define STM32_QSPI_CR_EN BIT(0)
  40. #define STM32_QSPI_CR_ABORT BIT(1)
  41. #define STM32_QSPI_CR_DMAEN BIT(2)
  42. #define STM32_QSPI_CR_TCEN BIT(3)
  43. #define STM32_QSPI_CR_SSHIFT BIT(4)
  44. #define STM32_QSPI_CR_DFM BIT(6)
  45. #define STM32_QSPI_CR_FSEL BIT(7)
  46. #define STM32_QSPI_CR_FTHRES_MASK GENMASK(4, 0)
  47. #define STM32_QSPI_CR_FTHRES_SHIFT (8)
  48. #define STM32_QSPI_CR_TEIE BIT(16)
  49. #define STM32_QSPI_CR_TCIE BIT(17)
  50. #define STM32_QSPI_CR_FTIE BIT(18)
  51. #define STM32_QSPI_CR_SMIE BIT(19)
  52. #define STM32_QSPI_CR_TOIE BIT(20)
  53. #define STM32_QSPI_CR_APMS BIT(22)
  54. #define STM32_QSPI_CR_PMM BIT(23)
  55. #define STM32_QSPI_CR_PRESCALER_MASK GENMASK(7, 0)
  56. #define STM32_QSPI_CR_PRESCALER_SHIFT (24)
  57. /*
  58. * QUADSPI device configuration register
  59. */
  60. #define STM32_QSPI_DCR_CKMODE BIT(0)
  61. #define STM32_QSPI_DCR_CSHT_MASK GENMASK(2, 0)
  62. #define STM32_QSPI_DCR_CSHT_SHIFT (8)
  63. #define STM32_QSPI_DCR_FSIZE_MASK GENMASK(4, 0)
  64. #define STM32_QSPI_DCR_FSIZE_SHIFT (16)
  65. /*
  66. * QUADSPI status register
  67. */
  68. #define STM32_QSPI_SR_TEF BIT(0)
  69. #define STM32_QSPI_SR_TCF BIT(1)
  70. #define STM32_QSPI_SR_FTF BIT(2)
  71. #define STM32_QSPI_SR_SMF BIT(3)
  72. #define STM32_QSPI_SR_TOF BIT(4)
  73. #define STM32_QSPI_SR_BUSY BIT(5)
  74. #define STM32_QSPI_SR_FLEVEL_MASK GENMASK(5, 0)
  75. #define STM32_QSPI_SR_FLEVEL_SHIFT (8)
  76. /*
  77. * QUADSPI flag clear register
  78. */
  79. #define STM32_QSPI_FCR_CTEF BIT(0)
  80. #define STM32_QSPI_FCR_CTCF BIT(1)
  81. #define STM32_QSPI_FCR_CSMF BIT(3)
  82. #define STM32_QSPI_FCR_CTOF BIT(4)
  83. /*
  84. * QUADSPI communication configuration register
  85. */
  86. #define STM32_QSPI_CCR_DDRM BIT(31)
  87. #define STM32_QSPI_CCR_DHHC BIT(30)
  88. #define STM32_QSPI_CCR_SIOO BIT(28)
  89. #define STM32_QSPI_CCR_FMODE_SHIFT (26)
  90. #define STM32_QSPI_CCR_DMODE_SHIFT (24)
  91. #define STM32_QSPI_CCR_DCYC_SHIFT (18)
  92. #define STM32_QSPI_CCR_DCYC_MASK GENMASK(4, 0)
  93. #define STM32_QSPI_CCR_ABSIZE_SHIFT (16)
  94. #define STM32_QSPI_CCR_ABMODE_SHIFT (14)
  95. #define STM32_QSPI_CCR_ADSIZE_SHIFT (12)
  96. #define STM32_QSPI_CCR_ADMODE_SHIFT (10)
  97. #define STM32_QSPI_CCR_IMODE_SHIFT (8)
  98. #define STM32_QSPI_CCR_INSTRUCTION_MASK GENMASK(7, 0)
  99. enum STM32_QSPI_CCR_IMODE {
  100. STM32_QSPI_CCR_IMODE_NONE = 0,
  101. STM32_QSPI_CCR_IMODE_ONE_LINE = 1,
  102. STM32_QSPI_CCR_IMODE_TWO_LINE = 2,
  103. STM32_QSPI_CCR_IMODE_FOUR_LINE = 3,
  104. };
  105. enum STM32_QSPI_CCR_ADMODE {
  106. STM32_QSPI_CCR_ADMODE_NONE = 0,
  107. STM32_QSPI_CCR_ADMODE_ONE_LINE = 1,
  108. STM32_QSPI_CCR_ADMODE_TWO_LINE = 2,
  109. STM32_QSPI_CCR_ADMODE_FOUR_LINE = 3,
  110. };
  111. enum STM32_QSPI_CCR_ADSIZE {
  112. STM32_QSPI_CCR_ADSIZE_8BIT = 0,
  113. STM32_QSPI_CCR_ADSIZE_16BIT = 1,
  114. STM32_QSPI_CCR_ADSIZE_24BIT = 2,
  115. STM32_QSPI_CCR_ADSIZE_32BIT = 3,
  116. };
  117. enum STM32_QSPI_CCR_ABMODE {
  118. STM32_QSPI_CCR_ABMODE_NONE = 0,
  119. STM32_QSPI_CCR_ABMODE_ONE_LINE = 1,
  120. STM32_QSPI_CCR_ABMODE_TWO_LINE = 2,
  121. STM32_QSPI_CCR_ABMODE_FOUR_LINE = 3,
  122. };
  123. enum STM32_QSPI_CCR_ABSIZE {
  124. STM32_QSPI_CCR_ABSIZE_8BIT = 0,
  125. STM32_QSPI_CCR_ABSIZE_16BIT = 1,
  126. STM32_QSPI_CCR_ABSIZE_24BIT = 2,
  127. STM32_QSPI_CCR_ABSIZE_32BIT = 3,
  128. };
  129. enum STM32_QSPI_CCR_DMODE {
  130. STM32_QSPI_CCR_DMODE_NONE = 0,
  131. STM32_QSPI_CCR_DMODE_ONE_LINE = 1,
  132. STM32_QSPI_CCR_DMODE_TWO_LINE = 2,
  133. STM32_QSPI_CCR_DMODE_FOUR_LINE = 3,
  134. };
  135. enum STM32_QSPI_CCR_FMODE {
  136. STM32_QSPI_CCR_IND_WRITE = 0,
  137. STM32_QSPI_CCR_IND_READ = 1,
  138. STM32_QSPI_CCR_AUTO_POLL = 2,
  139. STM32_QSPI_CCR_MEM_MAP = 3,
  140. };
  141. /* default SCK frequency, unit: HZ */
  142. #define STM32_QSPI_DEFAULT_SCK_FREQ 108000000
  143. struct stm32_qspi_platdata {
  144. u32 base;
  145. u32 memory_map;
  146. u32 max_hz;
  147. };
  148. struct stm32_qspi_priv {
  149. struct stm32_qspi_regs *regs;
  150. ulong clock_rate;
  151. u32 max_hz;
  152. u32 mode;
  153. u32 command;
  154. u32 address;
  155. u32 dummycycles;
  156. #define CMD_HAS_ADR BIT(24)
  157. #define CMD_HAS_DUMMY BIT(25)
  158. #define CMD_HAS_DATA BIT(26)
  159. };
  160. static void _stm32_qspi_disable(struct stm32_qspi_priv *priv)
  161. {
  162. clrbits_le32(&priv->regs->cr, STM32_QSPI_CR_EN);
  163. }
  164. static void _stm32_qspi_enable(struct stm32_qspi_priv *priv)
  165. {
  166. setbits_le32(&priv->regs->cr, STM32_QSPI_CR_EN);
  167. }
  168. static void _stm32_qspi_wait_for_not_busy(struct stm32_qspi_priv *priv)
  169. {
  170. while (readl(&priv->regs->sr) & STM32_QSPI_SR_BUSY)
  171. ;
  172. }
  173. static void _stm32_qspi_wait_for_complete(struct stm32_qspi_priv *priv)
  174. {
  175. while (!(readl(&priv->regs->sr) & STM32_QSPI_SR_TCF))
  176. ;
  177. }
  178. static void _stm32_qspi_wait_for_ftf(struct stm32_qspi_priv *priv)
  179. {
  180. while (!(readl(&priv->regs->sr) & STM32_QSPI_SR_FTF))
  181. ;
  182. }
  183. static void _stm32_qspi_set_flash_size(struct stm32_qspi_priv *priv, u32 size)
  184. {
  185. u32 fsize = fls(size) - 1;
  186. clrsetbits_le32(&priv->regs->dcr,
  187. STM32_QSPI_DCR_FSIZE_MASK << STM32_QSPI_DCR_FSIZE_SHIFT,
  188. fsize << STM32_QSPI_DCR_FSIZE_SHIFT);
  189. }
  190. static unsigned int _stm32_qspi_gen_ccr(struct stm32_qspi_priv *priv)
  191. {
  192. unsigned int ccr_reg = 0;
  193. u8 imode, admode, dmode;
  194. u32 mode = priv->mode;
  195. u32 cmd = (priv->command & STM32_QSPI_CCR_INSTRUCTION_MASK);
  196. imode = STM32_QSPI_CCR_IMODE_ONE_LINE;
  197. admode = STM32_QSPI_CCR_ADMODE_ONE_LINE;
  198. if (mode & SPI_RX_QUAD) {
  199. dmode = STM32_QSPI_CCR_DMODE_FOUR_LINE;
  200. if (mode & SPI_TX_QUAD) {
  201. imode = STM32_QSPI_CCR_IMODE_FOUR_LINE;
  202. admode = STM32_QSPI_CCR_ADMODE_FOUR_LINE;
  203. }
  204. } else if (mode & SPI_RX_DUAL) {
  205. dmode = STM32_QSPI_CCR_DMODE_TWO_LINE;
  206. if (mode & SPI_TX_DUAL) {
  207. imode = STM32_QSPI_CCR_IMODE_TWO_LINE;
  208. admode = STM32_QSPI_CCR_ADMODE_TWO_LINE;
  209. }
  210. } else {
  211. dmode = STM32_QSPI_CCR_DMODE_ONE_LINE;
  212. }
  213. if (priv->command & CMD_HAS_DATA)
  214. ccr_reg |= (dmode << STM32_QSPI_CCR_DMODE_SHIFT);
  215. if (priv->command & CMD_HAS_DUMMY)
  216. ccr_reg |= ((priv->dummycycles & STM32_QSPI_CCR_DCYC_MASK)
  217. << STM32_QSPI_CCR_DCYC_SHIFT);
  218. if (priv->command & CMD_HAS_ADR) {
  219. ccr_reg |= (STM32_QSPI_CCR_ADSIZE_24BIT
  220. << STM32_QSPI_CCR_ADSIZE_SHIFT);
  221. ccr_reg |= (admode << STM32_QSPI_CCR_ADMODE_SHIFT);
  222. }
  223. ccr_reg |= (imode << STM32_QSPI_CCR_IMODE_SHIFT);
  224. ccr_reg |= cmd;
  225. return ccr_reg;
  226. }
  227. static void _stm32_qspi_enable_mmap(struct stm32_qspi_priv *priv,
  228. struct spi_flash *flash)
  229. {
  230. priv->command = flash->read_cmd | CMD_HAS_ADR | CMD_HAS_DATA
  231. | CMD_HAS_DUMMY;
  232. priv->dummycycles = flash->dummy_byte * 8;
  233. unsigned int ccr_reg = _stm32_qspi_gen_ccr(priv);
  234. ccr_reg |= (STM32_QSPI_CCR_MEM_MAP << STM32_QSPI_CCR_FMODE_SHIFT);
  235. _stm32_qspi_wait_for_not_busy(priv);
  236. writel(ccr_reg, &priv->regs->ccr);
  237. priv->dummycycles = 0;
  238. }
  239. static void _stm32_qspi_disable_mmap(struct stm32_qspi_priv *priv)
  240. {
  241. setbits_le32(&priv->regs->cr, STM32_QSPI_CR_ABORT);
  242. }
  243. static void _stm32_qspi_set_xfer_length(struct stm32_qspi_priv *priv,
  244. u32 length)
  245. {
  246. writel(length - 1, &priv->regs->dlr);
  247. }
  248. static void _stm32_qspi_start_xfer(struct stm32_qspi_priv *priv, u32 cr_reg)
  249. {
  250. writel(cr_reg, &priv->regs->ccr);
  251. if (priv->command & CMD_HAS_ADR)
  252. writel(priv->address, &priv->regs->ar);
  253. }
  254. static int _stm32_qspi_xfer(struct stm32_qspi_priv *priv,
  255. struct spi_flash *flash, unsigned int bitlen,
  256. const u8 *dout, u8 *din, unsigned long flags)
  257. {
  258. unsigned int words = bitlen / 8;
  259. if (flags & SPI_XFER_MMAP) {
  260. _stm32_qspi_enable_mmap(priv, flash);
  261. return 0;
  262. } else if (flags & SPI_XFER_MMAP_END) {
  263. _stm32_qspi_disable_mmap(priv);
  264. return 0;
  265. }
  266. if (bitlen == 0)
  267. return -1;
  268. if (bitlen % 8) {
  269. debug("spi_xfer: Non byte aligned SPI transfer\n");
  270. return -1;
  271. }
  272. if (dout && din) {
  273. debug("spi_xfer: QSPI cannot have data in and data out set\n");
  274. return -1;
  275. }
  276. if (!dout && (flags & SPI_XFER_BEGIN)) {
  277. debug("spi_xfer: QSPI transfer must begin with command\n");
  278. return -1;
  279. }
  280. if (dout) {
  281. if (flags & SPI_XFER_BEGIN) {
  282. /* data is command */
  283. priv->command = dout[0] | CMD_HAS_DATA;
  284. if (words >= 4) {
  285. /* address is here too */
  286. priv->address = (dout[1] << 16) |
  287. (dout[2] << 8) | dout[3];
  288. priv->command |= CMD_HAS_ADR;
  289. }
  290. if (words > 4) {
  291. /* rest is dummy bytes */
  292. priv->dummycycles = (words - 4) * 8;
  293. priv->command |= CMD_HAS_DUMMY;
  294. }
  295. if (flags & SPI_XFER_END) {
  296. /* command without data */
  297. priv->command &= ~(CMD_HAS_DATA);
  298. }
  299. }
  300. if (flags & SPI_XFER_END) {
  301. u32 ccr_reg = _stm32_qspi_gen_ccr(priv);
  302. ccr_reg |= STM32_QSPI_CCR_IND_WRITE
  303. << STM32_QSPI_CCR_FMODE_SHIFT;
  304. _stm32_qspi_wait_for_not_busy(priv);
  305. if (priv->command & CMD_HAS_DATA)
  306. _stm32_qspi_set_xfer_length(priv, words);
  307. _stm32_qspi_start_xfer(priv, ccr_reg);
  308. debug("%s: write: ccr:0x%08x adr:0x%08x\n",
  309. __func__, priv->regs->ccr, priv->regs->ar);
  310. if (priv->command & CMD_HAS_DATA) {
  311. _stm32_qspi_wait_for_ftf(priv);
  312. debug("%s: words:%d data:", __func__, words);
  313. int i = 0;
  314. while (words > i) {
  315. writeb(dout[i], &priv->regs->dr);
  316. debug("%02x ", dout[i]);
  317. i++;
  318. }
  319. debug("\n");
  320. _stm32_qspi_wait_for_complete(priv);
  321. } else {
  322. _stm32_qspi_wait_for_not_busy(priv);
  323. }
  324. }
  325. } else if (din) {
  326. u32 ccr_reg = _stm32_qspi_gen_ccr(priv);
  327. ccr_reg |= STM32_QSPI_CCR_IND_READ
  328. << STM32_QSPI_CCR_FMODE_SHIFT;
  329. _stm32_qspi_wait_for_not_busy(priv);
  330. _stm32_qspi_set_xfer_length(priv, words);
  331. _stm32_qspi_start_xfer(priv, ccr_reg);
  332. debug("%s: read: ccr:0x%08x adr:0x%08x len:%d\n", __func__,
  333. priv->regs->ccr, priv->regs->ar, priv->regs->dlr);
  334. debug("%s: data:", __func__);
  335. int i = 0;
  336. while (words > i) {
  337. din[i] = readb(&priv->regs->dr);
  338. debug("%02x ", din[i]);
  339. i++;
  340. }
  341. debug("\n");
  342. }
  343. return 0;
  344. }
  345. static int stm32_qspi_ofdata_to_platdata(struct udevice *bus)
  346. {
  347. struct fdt_resource res_regs, res_mem;
  348. struct stm32_qspi_platdata *plat = bus->platdata;
  349. const void *blob = gd->fdt_blob;
  350. int node = dev_of_offset(bus);
  351. int ret;
  352. ret = fdt_get_named_resource(blob, node, "reg", "reg-names",
  353. "QuadSPI", &res_regs);
  354. if (ret) {
  355. debug("Error: can't get regs base addresses(ret = %d)!\n", ret);
  356. return -ENOMEM;
  357. }
  358. ret = fdt_get_named_resource(blob, node, "reg", "reg-names",
  359. "QuadSPI-memory", &res_mem);
  360. if (ret) {
  361. debug("Error: can't get mmap base address(ret = %d)!\n", ret);
  362. return -ENOMEM;
  363. }
  364. plat->max_hz = fdtdec_get_int(blob, node, "spi-max-frequency",
  365. STM32_QSPI_DEFAULT_SCK_FREQ);
  366. plat->base = res_regs.start;
  367. plat->memory_map = res_mem.start;
  368. debug("%s: regs=<0x%x> mapped=<0x%x>, max-frequency=%d\n",
  369. __func__,
  370. plat->base,
  371. plat->memory_map,
  372. plat->max_hz
  373. );
  374. return 0;
  375. }
  376. static int stm32_qspi_probe(struct udevice *bus)
  377. {
  378. struct stm32_qspi_platdata *plat = dev_get_platdata(bus);
  379. struct stm32_qspi_priv *priv = dev_get_priv(bus);
  380. struct dm_spi_bus *dm_spi_bus;
  381. dm_spi_bus = bus->uclass_priv;
  382. dm_spi_bus->max_hz = plat->max_hz;
  383. priv->regs = (struct stm32_qspi_regs *)(uintptr_t)plat->base;
  384. priv->max_hz = plat->max_hz;
  385. #ifdef CONFIG_CLK
  386. int ret;
  387. struct clk clk;
  388. ret = clk_get_by_index(bus, 0, &clk);
  389. if (ret < 0)
  390. return ret;
  391. ret = clk_enable(&clk);
  392. if (ret) {
  393. dev_err(bus, "failed to enable clock\n");
  394. return ret;
  395. }
  396. priv->clock_rate = clk_get_rate(&clk);
  397. if (priv->clock_rate < 0) {
  398. clk_disable(&clk);
  399. return priv->clock_rate;
  400. }
  401. #endif
  402. setbits_le32(&priv->regs->cr, STM32_QSPI_CR_SSHIFT);
  403. return 0;
  404. }
  405. static int stm32_qspi_remove(struct udevice *bus)
  406. {
  407. return 0;
  408. }
  409. static int stm32_qspi_claim_bus(struct udevice *dev)
  410. {
  411. struct stm32_qspi_priv *priv;
  412. struct udevice *bus;
  413. struct spi_flash *flash;
  414. bus = dev->parent;
  415. priv = dev_get_priv(bus);
  416. flash = dev_get_uclass_priv(dev);
  417. _stm32_qspi_set_flash_size(priv, flash->size);
  418. _stm32_qspi_enable(priv);
  419. return 0;
  420. }
  421. static int stm32_qspi_release_bus(struct udevice *dev)
  422. {
  423. struct stm32_qspi_priv *priv;
  424. struct udevice *bus;
  425. bus = dev->parent;
  426. priv = dev_get_priv(bus);
  427. _stm32_qspi_disable(priv);
  428. return 0;
  429. }
  430. static int stm32_qspi_xfer(struct udevice *dev, unsigned int bitlen,
  431. const void *dout, void *din, unsigned long flags)
  432. {
  433. struct stm32_qspi_priv *priv;
  434. struct udevice *bus;
  435. struct spi_flash *flash;
  436. bus = dev->parent;
  437. priv = dev_get_priv(bus);
  438. flash = dev_get_uclass_priv(dev);
  439. return _stm32_qspi_xfer(priv, flash, bitlen, (const u8 *)dout,
  440. (u8 *)din, flags);
  441. }
  442. static int stm32_qspi_set_speed(struct udevice *bus, uint speed)
  443. {
  444. struct stm32_qspi_platdata *plat = bus->platdata;
  445. struct stm32_qspi_priv *priv = dev_get_priv(bus);
  446. if (speed > plat->max_hz)
  447. speed = plat->max_hz;
  448. u32 qspi_clk = priv->clock_rate;
  449. u32 prescaler = 255;
  450. if (speed > 0) {
  451. prescaler = DIV_ROUND_UP(qspi_clk, speed) - 1;
  452. if (prescaler > 255)
  453. prescaler = 255;
  454. else if (prescaler < 0)
  455. prescaler = 0;
  456. }
  457. u32 csht = DIV_ROUND_UP((5 * qspi_clk) / (prescaler + 1), 100000000);
  458. csht = (csht - 1) & STM32_QSPI_DCR_CSHT_MASK;
  459. _stm32_qspi_wait_for_not_busy(priv);
  460. clrsetbits_le32(&priv->regs->cr,
  461. STM32_QSPI_CR_PRESCALER_MASK <<
  462. STM32_QSPI_CR_PRESCALER_SHIFT,
  463. prescaler << STM32_QSPI_CR_PRESCALER_SHIFT);
  464. clrsetbits_le32(&priv->regs->dcr,
  465. STM32_QSPI_DCR_CSHT_MASK << STM32_QSPI_DCR_CSHT_SHIFT,
  466. csht << STM32_QSPI_DCR_CSHT_SHIFT);
  467. debug("%s: regs=%p, speed=%d\n", __func__, priv->regs,
  468. (qspi_clk / (prescaler + 1)));
  469. return 0;
  470. }
  471. static int stm32_qspi_set_mode(struct udevice *bus, uint mode)
  472. {
  473. struct stm32_qspi_priv *priv = dev_get_priv(bus);
  474. _stm32_qspi_wait_for_not_busy(priv);
  475. if ((mode & SPI_CPHA) && (mode & SPI_CPOL))
  476. setbits_le32(&priv->regs->dcr, STM32_QSPI_DCR_CKMODE);
  477. else if (!(mode & SPI_CPHA) && !(mode & SPI_CPOL))
  478. clrbits_le32(&priv->regs->dcr, STM32_QSPI_DCR_CKMODE);
  479. else
  480. return -ENODEV;
  481. if (mode & SPI_CS_HIGH)
  482. return -ENODEV;
  483. if (mode & SPI_RX_QUAD)
  484. priv->mode |= SPI_RX_QUAD;
  485. else if (mode & SPI_RX_DUAL)
  486. priv->mode |= SPI_RX_DUAL;
  487. else
  488. priv->mode &= ~(SPI_RX_QUAD | SPI_RX_DUAL);
  489. if (mode & SPI_TX_QUAD)
  490. priv->mode |= SPI_TX_QUAD;
  491. else if (mode & SPI_TX_DUAL)
  492. priv->mode |= SPI_TX_DUAL;
  493. else
  494. priv->mode &= ~(SPI_TX_QUAD | SPI_TX_DUAL);
  495. debug("%s: regs=%p, mode=%d rx: ", __func__, priv->regs, mode);
  496. if (mode & SPI_RX_QUAD)
  497. debug("quad, tx: ");
  498. else if (mode & SPI_RX_DUAL)
  499. debug("dual, tx: ");
  500. else
  501. debug("single, tx: ");
  502. if (mode & SPI_TX_QUAD)
  503. debug("quad\n");
  504. else if (mode & SPI_TX_DUAL)
  505. debug("dual\n");
  506. else
  507. debug("single\n");
  508. return 0;
  509. }
  510. static const struct dm_spi_ops stm32_qspi_ops = {
  511. .claim_bus = stm32_qspi_claim_bus,
  512. .release_bus = stm32_qspi_release_bus,
  513. .xfer = stm32_qspi_xfer,
  514. .set_speed = stm32_qspi_set_speed,
  515. .set_mode = stm32_qspi_set_mode,
  516. };
  517. static const struct udevice_id stm32_qspi_ids[] = {
  518. { .compatible = "st,stm32-qspi" },
  519. { }
  520. };
  521. U_BOOT_DRIVER(stm32_qspi) = {
  522. .name = "stm32_qspi",
  523. .id = UCLASS_SPI,
  524. .of_match = stm32_qspi_ids,
  525. .ops = &stm32_qspi_ops,
  526. .ofdata_to_platdata = stm32_qspi_ofdata_to_platdata,
  527. .platdata_auto_alloc_size = sizeof(struct stm32_qspi_platdata),
  528. .priv_auto_alloc_size = sizeof(struct stm32_qspi_priv),
  529. .probe = stm32_qspi_probe,
  530. .remove = stm32_qspi_remove,
  531. };