zynq_qspi.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  1. /*
  2. * (C) Copyright 2013 Xilinx, Inc.
  3. * (C) Copyright 2015 Jagan Teki <jteki@openedev.com>
  4. *
  5. * Xilinx Zynq Quad-SPI(QSPI) controller driver (master mode only)
  6. *
  7. * SPDX-License-Identifier: GPL-2.0+
  8. */
  9. #include <common.h>
  10. #include <dm.h>
  11. #include <malloc.h>
  12. #include <spi.h>
  13. #include <asm/io.h>
  14. DECLARE_GLOBAL_DATA_PTR;
  15. /* zynq qspi register bit masks ZYNQ_QSPI_<REG>_<BIT>_MASK */
  16. #define ZYNQ_QSPI_CR_IFMODE_MASK BIT(31) /* Flash intrface mode*/
  17. #define ZYNQ_QSPI_CR_MSA_MASK BIT(15) /* Manual start enb */
  18. #define ZYNQ_QSPI_CR_MCS_MASK BIT(14) /* Manual chip select */
  19. #define ZYNQ_QSPI_CR_PCS_MASK BIT(10) /* Peri chip select */
  20. #define ZYNQ_QSPI_CR_FW_MASK GENMASK(7, 6) /* FIFO width */
  21. #define ZYNQ_QSPI_CR_SS_MASK GENMASK(13, 10) /* Slave Select */
  22. #define ZYNQ_QSPI_CR_BAUD_MASK GENMASK(5, 3) /* Baud rate div */
  23. #define ZYNQ_QSPI_CR_CPHA_MASK BIT(2) /* Clock phase */
  24. #define ZYNQ_QSPI_CR_CPOL_MASK BIT(1) /* Clock polarity */
  25. #define ZYNQ_QSPI_CR_MSTREN_MASK BIT(0) /* Mode select */
  26. #define ZYNQ_QSPI_IXR_RXNEMPTY_MASK BIT(4) /* RX_FIFO_not_empty */
  27. #define ZYNQ_QSPI_IXR_TXOW_MASK BIT(2) /* TX_FIFO_not_full */
  28. #define ZYNQ_QSPI_IXR_ALL_MASK GENMASK(6, 0) /* All IXR bits */
  29. #define ZYNQ_QSPI_ENR_SPI_EN_MASK BIT(0) /* SPI Enable */
  30. /* zynq qspi Transmit Data Register */
  31. #define ZYNQ_QSPI_TXD_00_00_OFFSET 0x1C /* Transmit 4-byte inst */
  32. #define ZYNQ_QSPI_TXD_00_01_OFFSET 0x80 /* Transmit 1-byte inst */
  33. #define ZYNQ_QSPI_TXD_00_10_OFFSET 0x84 /* Transmit 2-byte inst */
  34. #define ZYNQ_QSPI_TXD_00_11_OFFSET 0x88 /* Transmit 3-byte inst */
  35. #define ZYNQ_QSPI_TXFIFO_THRESHOLD 1 /* Tx FIFO threshold level*/
  36. #define ZYNQ_QSPI_RXFIFO_THRESHOLD 32 /* Rx FIFO threshold level */
  37. #define ZYNQ_QSPI_CR_BAUD_MAX 8 /* Baud rate divisor max val */
  38. #define ZYNQ_QSPI_CR_BAUD_SHIFT 3 /* Baud rate divisor shift */
  39. #define ZYNQ_QSPI_CR_SS_SHIFT 10 /* Slave select shift */
  40. #define ZYNQ_QSPI_FIFO_DEPTH 63
  41. #ifndef CONFIG_SYS_ZYNQ_QSPI_WAIT
  42. #define CONFIG_SYS_ZYNQ_QSPI_WAIT CONFIG_SYS_HZ/100 /* 10 ms */
  43. #endif
  44. /* zynq qspi register set */
  45. struct zynq_qspi_regs {
  46. u32 cr; /* 0x00 */
  47. u32 isr; /* 0x04 */
  48. u32 ier; /* 0x08 */
  49. u32 idr; /* 0x0C */
  50. u32 imr; /* 0x10 */
  51. u32 enr; /* 0x14 */
  52. u32 dr; /* 0x18 */
  53. u32 txd0r; /* 0x1C */
  54. u32 drxr; /* 0x20 */
  55. u32 sicr; /* 0x24 */
  56. u32 txftr; /* 0x28 */
  57. u32 rxftr; /* 0x2C */
  58. u32 gpior; /* 0x30 */
  59. u32 reserved0[19];
  60. u32 txd1r; /* 0x80 */
  61. u32 txd2r; /* 0x84 */
  62. u32 txd3r; /* 0x88 */
  63. };
  64. /* zynq qspi platform data */
  65. struct zynq_qspi_platdata {
  66. struct zynq_qspi_regs *regs;
  67. u32 frequency; /* input frequency */
  68. u32 speed_hz;
  69. };
  70. /* zynq qspi priv */
  71. struct zynq_qspi_priv {
  72. struct zynq_qspi_regs *regs;
  73. u8 cs;
  74. u8 mode;
  75. u8 fifo_depth;
  76. u32 freq; /* required frequency */
  77. const void *tx_buf;
  78. void *rx_buf;
  79. unsigned len;
  80. int bytes_to_transfer;
  81. int bytes_to_receive;
  82. unsigned int is_inst;
  83. unsigned cs_change:1;
  84. };
  85. static int zynq_qspi_ofdata_to_platdata(struct udevice *bus)
  86. {
  87. struct zynq_qspi_platdata *plat = bus->platdata;
  88. const void *blob = gd->fdt_blob;
  89. int node = bus->of_offset;
  90. plat->regs = (struct zynq_qspi_regs *)fdtdec_get_addr(blob,
  91. node, "reg");
  92. /* FIXME: Use 166MHz as a suitable default */
  93. plat->frequency = fdtdec_get_int(blob, node, "spi-max-frequency",
  94. 166666666);
  95. plat->speed_hz = plat->frequency / 2;
  96. debug("%s: regs=%p max-frequency=%d\n", __func__,
  97. plat->regs, plat->frequency);
  98. return 0;
  99. }
  100. static void zynq_qspi_init_hw(struct zynq_qspi_priv *priv)
  101. {
  102. struct zynq_qspi_regs *regs = priv->regs;
  103. u32 confr;
  104. /* Disable QSPI */
  105. writel(~ZYNQ_QSPI_ENR_SPI_EN_MASK, &regs->enr);
  106. /* Disable Interrupts */
  107. writel(ZYNQ_QSPI_IXR_ALL_MASK, &regs->idr);
  108. /* Clear the TX and RX threshold reg */
  109. writel(ZYNQ_QSPI_TXFIFO_THRESHOLD, &regs->txftr);
  110. writel(ZYNQ_QSPI_RXFIFO_THRESHOLD, &regs->rxftr);
  111. /* Clear the RX FIFO */
  112. while (readl(&regs->isr) & ZYNQ_QSPI_IXR_RXNEMPTY_MASK)
  113. readl(&regs->drxr);
  114. /* Clear Interrupts */
  115. writel(ZYNQ_QSPI_IXR_ALL_MASK, &regs->isr);
  116. /* Manual slave select and Auto start */
  117. confr = readl(&regs->cr);
  118. confr &= ~ZYNQ_QSPI_CR_MSA_MASK;
  119. confr |= ZYNQ_QSPI_CR_IFMODE_MASK | ZYNQ_QSPI_CR_MCS_MASK |
  120. ZYNQ_QSPI_CR_PCS_MASK | ZYNQ_QSPI_CR_FW_MASK |
  121. ZYNQ_QSPI_CR_MSTREN_MASK;
  122. writel(confr, &regs->cr);
  123. /* Enable SPI */
  124. writel(ZYNQ_QSPI_ENR_SPI_EN_MASK, &regs->enr);
  125. }
  126. static int zynq_qspi_probe(struct udevice *bus)
  127. {
  128. struct zynq_qspi_platdata *plat = dev_get_platdata(bus);
  129. struct zynq_qspi_priv *priv = dev_get_priv(bus);
  130. priv->regs = plat->regs;
  131. priv->fifo_depth = ZYNQ_QSPI_FIFO_DEPTH;
  132. /* init the zynq spi hw */
  133. zynq_qspi_init_hw(priv);
  134. return 0;
  135. }
  136. /*
  137. * zynq_qspi_read_data - Copy data to RX buffer
  138. * @zqspi: Pointer to the zynq_qspi structure
  139. * @data: The 32 bit variable where data is stored
  140. * @size: Number of bytes to be copied from data to RX buffer
  141. */
  142. static void zynq_qspi_read_data(struct zynq_qspi_priv *priv, u32 data, u8 size)
  143. {
  144. u8 byte3;
  145. debug("%s: data 0x%04x rx_buf addr: 0x%08x size %d\n", __func__ ,
  146. data, (unsigned)(priv->rx_buf), size);
  147. if (priv->rx_buf) {
  148. switch (size) {
  149. case 1:
  150. *((u8 *)priv->rx_buf) = data;
  151. priv->rx_buf += 1;
  152. break;
  153. case 2:
  154. *((u16 *)priv->rx_buf) = data;
  155. priv->rx_buf += 2;
  156. break;
  157. case 3:
  158. *((u16 *)priv->rx_buf) = data;
  159. priv->rx_buf += 2;
  160. byte3 = (u8)(data >> 16);
  161. *((u8 *)priv->rx_buf) = byte3;
  162. priv->rx_buf += 1;
  163. break;
  164. case 4:
  165. /* Can not assume word aligned buffer */
  166. memcpy(priv->rx_buf, &data, size);
  167. priv->rx_buf += 4;
  168. break;
  169. default:
  170. /* This will never execute */
  171. break;
  172. }
  173. }
  174. priv->bytes_to_receive -= size;
  175. if (priv->bytes_to_receive < 0)
  176. priv->bytes_to_receive = 0;
  177. }
  178. /*
  179. * zynq_qspi_write_data - Copy data from TX buffer
  180. * @zqspi: Pointer to the zynq_qspi structure
  181. * @data: Pointer to the 32 bit variable where data is to be copied
  182. * @size: Number of bytes to be copied from TX buffer to data
  183. */
  184. static void zynq_qspi_write_data(struct zynq_qspi_priv *priv,
  185. u32 *data, u8 size)
  186. {
  187. if (priv->tx_buf) {
  188. switch (size) {
  189. case 1:
  190. *data = *((u8 *)priv->tx_buf);
  191. priv->tx_buf += 1;
  192. *data |= 0xFFFFFF00;
  193. break;
  194. case 2:
  195. *data = *((u16 *)priv->tx_buf);
  196. priv->tx_buf += 2;
  197. *data |= 0xFFFF0000;
  198. break;
  199. case 3:
  200. *data = *((u16 *)priv->tx_buf);
  201. priv->tx_buf += 2;
  202. *data |= (*((u8 *)priv->tx_buf) << 16);
  203. priv->tx_buf += 1;
  204. *data |= 0xFF000000;
  205. break;
  206. case 4:
  207. /* Can not assume word aligned buffer */
  208. memcpy(data, priv->tx_buf, size);
  209. priv->tx_buf += 4;
  210. break;
  211. default:
  212. /* This will never execute */
  213. break;
  214. }
  215. } else {
  216. *data = 0;
  217. }
  218. debug("%s: data 0x%08x tx_buf addr: 0x%08x size %d\n", __func__,
  219. *data, (u32)priv->tx_buf, size);
  220. priv->bytes_to_transfer -= size;
  221. if (priv->bytes_to_transfer < 0)
  222. priv->bytes_to_transfer = 0;
  223. }
  224. static void zynq_qspi_chipselect(struct zynq_qspi_priv *priv, int is_on)
  225. {
  226. u32 confr;
  227. struct zynq_qspi_regs *regs = priv->regs;
  228. confr = readl(&regs->cr);
  229. if (is_on) {
  230. /* Select the slave */
  231. confr &= ~ZYNQ_QSPI_CR_SS_MASK;
  232. confr |= (~(1 << priv->cs) << ZYNQ_QSPI_CR_SS_SHIFT) &
  233. ZYNQ_QSPI_CR_SS_MASK;
  234. } else
  235. /* Deselect the slave */
  236. confr |= ZYNQ_QSPI_CR_SS_MASK;
  237. writel(confr, &regs->cr);
  238. }
  239. /*
  240. * zynq_qspi_fill_tx_fifo - Fills the TX FIFO with as many bytes as possible
  241. * @zqspi: Pointer to the zynq_qspi structure
  242. */
  243. static void zynq_qspi_fill_tx_fifo(struct zynq_qspi_priv *priv, u32 size)
  244. {
  245. u32 data = 0;
  246. u32 fifocount = 0;
  247. unsigned len, offset;
  248. struct zynq_qspi_regs *regs = priv->regs;
  249. static const unsigned offsets[4] = {
  250. ZYNQ_QSPI_TXD_00_00_OFFSET, ZYNQ_QSPI_TXD_00_01_OFFSET,
  251. ZYNQ_QSPI_TXD_00_10_OFFSET, ZYNQ_QSPI_TXD_00_11_OFFSET };
  252. while ((fifocount < size) &&
  253. (priv->bytes_to_transfer > 0)) {
  254. if (priv->bytes_to_transfer >= 4) {
  255. if (priv->tx_buf) {
  256. memcpy(&data, priv->tx_buf, 4);
  257. priv->tx_buf += 4;
  258. } else {
  259. data = 0;
  260. }
  261. writel(data, &regs->txd0r);
  262. priv->bytes_to_transfer -= 4;
  263. fifocount++;
  264. } else {
  265. /* Write TXD1, TXD2, TXD3 only if TxFIFO is empty. */
  266. if (!(readl(&regs->isr)
  267. & ZYNQ_QSPI_IXR_TXOW_MASK) &&
  268. !priv->rx_buf)
  269. return;
  270. len = priv->bytes_to_transfer;
  271. zynq_qspi_write_data(priv, &data, len);
  272. offset = (priv->rx_buf) ? offsets[0] : offsets[len];
  273. writel(data, &regs->cr + (offset / 4));
  274. }
  275. }
  276. }
  277. /*
  278. * zynq_qspi_irq_poll - Interrupt service routine of the QSPI controller
  279. * @zqspi: Pointer to the zynq_qspi structure
  280. *
  281. * This function handles TX empty and Mode Fault interrupts only.
  282. * On TX empty interrupt this function reads the received data from RX FIFO and
  283. * fills the TX FIFO if there is any data remaining to be transferred.
  284. * On Mode Fault interrupt this function indicates that transfer is completed,
  285. * the SPI subsystem will identify the error as the remaining bytes to be
  286. * transferred is non-zero.
  287. *
  288. * returns: 0 for poll timeout
  289. * 1 transfer operation complete
  290. */
  291. static int zynq_qspi_irq_poll(struct zynq_qspi_priv *priv)
  292. {
  293. struct zynq_qspi_regs *regs = priv->regs;
  294. u32 rxindex = 0;
  295. u32 rxcount;
  296. u32 status, timeout;
  297. /* Poll until any of the interrupt status bits are set */
  298. timeout = get_timer(0);
  299. do {
  300. status = readl(&regs->isr);
  301. } while ((status == 0) &&
  302. (get_timer(timeout) < CONFIG_SYS_ZYNQ_QSPI_WAIT));
  303. if (status == 0) {
  304. printf("zynq_qspi_irq_poll: Timeout!\n");
  305. return -ETIMEDOUT;
  306. }
  307. writel(status, &regs->isr);
  308. /* Disable all interrupts */
  309. writel(ZYNQ_QSPI_IXR_ALL_MASK, &regs->idr);
  310. if ((status & ZYNQ_QSPI_IXR_TXOW_MASK) ||
  311. (status & ZYNQ_QSPI_IXR_RXNEMPTY_MASK)) {
  312. /*
  313. * This bit is set when Tx FIFO has < THRESHOLD entries. We have
  314. * the THRESHOLD value set to 1, so this bit indicates Tx FIFO
  315. * is empty
  316. */
  317. rxcount = priv->bytes_to_receive - priv->bytes_to_transfer;
  318. rxcount = (rxcount % 4) ? ((rxcount/4)+1) : (rxcount/4);
  319. while ((rxindex < rxcount) &&
  320. (rxindex < ZYNQ_QSPI_RXFIFO_THRESHOLD)) {
  321. /* Read out the data from the RX FIFO */
  322. u32 data;
  323. data = readl(&regs->drxr);
  324. if (priv->bytes_to_receive >= 4) {
  325. if (priv->rx_buf) {
  326. memcpy(priv->rx_buf, &data, 4);
  327. priv->rx_buf += 4;
  328. }
  329. priv->bytes_to_receive -= 4;
  330. } else {
  331. zynq_qspi_read_data(priv, data,
  332. priv->bytes_to_receive);
  333. }
  334. rxindex++;
  335. }
  336. if (priv->bytes_to_transfer) {
  337. /* There is more data to send */
  338. zynq_qspi_fill_tx_fifo(priv,
  339. ZYNQ_QSPI_RXFIFO_THRESHOLD);
  340. writel(ZYNQ_QSPI_IXR_ALL_MASK, &regs->ier);
  341. } else {
  342. /*
  343. * If transfer and receive is completed then only send
  344. * complete signal
  345. */
  346. if (!priv->bytes_to_receive) {
  347. /* return operation complete */
  348. writel(ZYNQ_QSPI_IXR_ALL_MASK,
  349. &regs->idr);
  350. return 1;
  351. }
  352. }
  353. }
  354. return 0;
  355. }
  356. /*
  357. * zynq_qspi_start_transfer - Initiates the QSPI transfer
  358. * @qspi: Pointer to the spi_device structure
  359. * @transfer: Pointer to the spi_transfer structure which provide information
  360. * about next transfer parameters
  361. *
  362. * This function fills the TX FIFO, starts the QSPI transfer, and waits for the
  363. * transfer to be completed.
  364. *
  365. * returns: Number of bytes transferred in the last transfer
  366. */
  367. static int zynq_qspi_start_transfer(struct zynq_qspi_priv *priv)
  368. {
  369. u32 data = 0;
  370. struct zynq_qspi_regs *regs = priv->regs;
  371. debug("%s: qspi: 0x%08x transfer: 0x%08x len: %d\n", __func__,
  372. (u32)priv, (u32)priv, priv->len);
  373. priv->bytes_to_transfer = priv->len;
  374. priv->bytes_to_receive = priv->len;
  375. if (priv->len < 4)
  376. zynq_qspi_fill_tx_fifo(priv, priv->len);
  377. else
  378. zynq_qspi_fill_tx_fifo(priv, priv->fifo_depth);
  379. writel(ZYNQ_QSPI_IXR_ALL_MASK, &regs->ier);
  380. /* wait for completion */
  381. do {
  382. data = zynq_qspi_irq_poll(priv);
  383. } while (data == 0);
  384. return (priv->len) - (priv->bytes_to_transfer);
  385. }
  386. static int zynq_qspi_transfer(struct zynq_qspi_priv *priv)
  387. {
  388. unsigned cs_change = 1;
  389. int status = 0;
  390. while (1) {
  391. /* Select the chip if required */
  392. if (cs_change)
  393. zynq_qspi_chipselect(priv, 1);
  394. cs_change = priv->cs_change;
  395. if (!priv->tx_buf && !priv->rx_buf && priv->len) {
  396. status = -1;
  397. break;
  398. }
  399. /* Request the transfer */
  400. if (priv->len) {
  401. status = zynq_qspi_start_transfer(priv);
  402. priv->is_inst = 0;
  403. }
  404. if (status != priv->len) {
  405. if (status > 0)
  406. status = -EMSGSIZE;
  407. debug("zynq_qspi_transfer:%d len:%d\n",
  408. status, priv->len);
  409. break;
  410. }
  411. status = 0;
  412. if (cs_change)
  413. /* Deselect the chip */
  414. zynq_qspi_chipselect(priv, 0);
  415. break;
  416. }
  417. return 0;
  418. }
  419. static int zynq_qspi_claim_bus(struct udevice *dev)
  420. {
  421. struct udevice *bus = dev->parent;
  422. struct zynq_qspi_priv *priv = dev_get_priv(bus);
  423. struct zynq_qspi_regs *regs = priv->regs;
  424. writel(ZYNQ_QSPI_ENR_SPI_EN_MASK, &regs->enr);
  425. return 0;
  426. }
  427. static int zynq_qspi_release_bus(struct udevice *dev)
  428. {
  429. struct udevice *bus = dev->parent;
  430. struct zynq_qspi_priv *priv = dev_get_priv(bus);
  431. struct zynq_qspi_regs *regs = priv->regs;
  432. writel(~ZYNQ_QSPI_ENR_SPI_EN_MASK, &regs->enr);
  433. return 0;
  434. }
  435. static int zynq_qspi_xfer(struct udevice *dev, unsigned int bitlen,
  436. const void *dout, void *din, unsigned long flags)
  437. {
  438. struct udevice *bus = dev->parent;
  439. struct zynq_qspi_priv *priv = dev_get_priv(bus);
  440. struct dm_spi_slave_platdata *slave_plat = dev_get_parent_platdata(dev);
  441. priv->cs = slave_plat->cs;
  442. priv->tx_buf = dout;
  443. priv->rx_buf = din;
  444. priv->len = bitlen / 8;
  445. debug("zynq_qspi_xfer: bus:%i cs:%i bitlen:%i len:%i flags:%lx\n",
  446. bus->seq, slave_plat->cs, bitlen, priv->len, flags);
  447. /*
  448. * Festering sore.
  449. * Assume that the beginning of a transfer with bits to
  450. * transmit must contain a device command.
  451. */
  452. if (dout && flags & SPI_XFER_BEGIN)
  453. priv->is_inst = 1;
  454. else
  455. priv->is_inst = 0;
  456. if (flags & SPI_XFER_END)
  457. priv->cs_change = 1;
  458. else
  459. priv->cs_change = 0;
  460. zynq_qspi_transfer(priv);
  461. return 0;
  462. }
  463. static int zynq_qspi_set_speed(struct udevice *bus, uint speed)
  464. {
  465. struct zynq_qspi_platdata *plat = bus->platdata;
  466. struct zynq_qspi_priv *priv = dev_get_priv(bus);
  467. struct zynq_qspi_regs *regs = priv->regs;
  468. uint32_t confr;
  469. u8 baud_rate_val = 0;
  470. if (speed > plat->frequency)
  471. speed = plat->frequency;
  472. /* Set the clock frequency */
  473. confr = readl(&regs->cr);
  474. if (speed == 0) {
  475. /* Set baudrate x8, if the freq is 0 */
  476. baud_rate_val = 0x2;
  477. } else if (plat->speed_hz != speed) {
  478. while ((baud_rate_val < ZYNQ_QSPI_CR_BAUD_MAX) &&
  479. ((plat->frequency /
  480. (2 << baud_rate_val)) > speed))
  481. baud_rate_val++;
  482. plat->speed_hz = speed / (2 << baud_rate_val);
  483. }
  484. confr &= ~ZYNQ_QSPI_CR_BAUD_MASK;
  485. confr |= (baud_rate_val << ZYNQ_QSPI_CR_BAUD_SHIFT);
  486. writel(confr, &regs->cr);
  487. priv->freq = speed;
  488. debug("%s: regs=%p, speed=%d\n", __func__, priv->regs, priv->freq);
  489. return 0;
  490. }
  491. static int zynq_qspi_set_mode(struct udevice *bus, uint mode)
  492. {
  493. struct zynq_qspi_priv *priv = dev_get_priv(bus);
  494. struct zynq_qspi_regs *regs = priv->regs;
  495. uint32_t confr;
  496. /* Set the SPI Clock phase and polarities */
  497. confr = readl(&regs->cr);
  498. confr &= ~(ZYNQ_QSPI_CR_CPHA_MASK | ZYNQ_QSPI_CR_CPOL_MASK);
  499. if (mode & SPI_CPHA)
  500. confr |= ZYNQ_QSPI_CR_CPHA_MASK;
  501. if (mode & SPI_CPOL)
  502. confr |= ZYNQ_QSPI_CR_CPOL_MASK;
  503. writel(confr, &regs->cr);
  504. priv->mode = mode;
  505. debug("%s: regs=%p, mode=%d\n", __func__, priv->regs, priv->mode);
  506. return 0;
  507. }
  508. static const struct dm_spi_ops zynq_qspi_ops = {
  509. .claim_bus = zynq_qspi_claim_bus,
  510. .release_bus = zynq_qspi_release_bus,
  511. .xfer = zynq_qspi_xfer,
  512. .set_speed = zynq_qspi_set_speed,
  513. .set_mode = zynq_qspi_set_mode,
  514. };
  515. static const struct udevice_id zynq_qspi_ids[] = {
  516. { .compatible = "xlnx,zynq-qspi-1.0" },
  517. { }
  518. };
  519. U_BOOT_DRIVER(zynq_qspi) = {
  520. .name = "zynq_qspi",
  521. .id = UCLASS_SPI,
  522. .of_match = zynq_qspi_ids,
  523. .ops = &zynq_qspi_ops,
  524. .ofdata_to_platdata = zynq_qspi_ofdata_to_platdata,
  525. .platdata_auto_alloc_size = sizeof(struct zynq_qspi_platdata),
  526. .priv_auto_alloc_size = sizeof(struct zynq_qspi_priv),
  527. .probe = zynq_qspi_probe,
  528. };