1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2018 Xilinx
5 * Xilinx ZynqMP Generic Quad-SPI(QSPI) controller driver(master mode only)
11 #include <asm/arch/sys_proto.h>
12 #include <asm/cache.h>
20 #include <ubi_uboot.h>
22 #include <dm/device_compat.h>
23 #include <linux/bitops.h>
24 #include <linux/err.h>
26 #define GQSPI_GFIFO_STRT_MODE_MASK BIT(29)
27 #define GQSPI_CONFIG_MODE_EN_MASK (3 << 30)
28 #define GQSPI_CONFIG_DMA_MODE (2 << 30)
29 #define GQSPI_CONFIG_CPHA_MASK BIT(2)
30 #define GQSPI_CONFIG_CPOL_MASK BIT(1)
33 * QSPI Interrupt Registers bit Masks
35 * All the four interrupt registers (Status/Mask/Enable/Disable) have the same
38 #define GQSPI_IXR_TXNFULL_MASK 0x00000004 /* QSPI TX FIFO Overflow */
39 #define GQSPI_IXR_TXFULL_MASK 0x00000008 /* QSPI TX FIFO is full */
40 #define GQSPI_IXR_TXFIFOEMPTY_MASK 0x00000100 /* QSPI TX FIFO is Empty */
41 #define GQSPI_IXR_RXNEMTY_MASK 0x00000010 /* QSPI RX FIFO Not Empty */
42 #define GQSPI_IXR_GFEMTY_MASK 0x00000080 /* QSPI Generic FIFO Empty */
43 #define GQSPI_IXR_GFNFULL_MASK 0x00000200 /* QSPI GENFIFO not full */
44 #define GQSPI_IXR_ALL_MASK (GQSPI_IXR_TXNFULL_MASK | \
45 GQSPI_IXR_RXNEMTY_MASK)
48 * QSPI Enable Register bit Masks
50 * This register is used to enable or disable the QSPI controller
52 #define GQSPI_ENABLE_ENABLE_MASK 0x00000001 /* QSPI Enable Bit Mask */
54 #define GQSPI_GFIFO_LOW_BUS BIT(14)
55 #define GQSPI_GFIFO_CS_LOWER BIT(12)
56 #define GQSPI_GFIFO_UP_BUS BIT(15)
57 #define GQSPI_GFIFO_CS_UPPER BIT(13)
58 #define GQSPI_SPI_MODE_QSPI (3 << 10)
59 #define GQSPI_SPI_MODE_SPI BIT(10)
60 #define GQSPI_SPI_MODE_DUAL_SPI (2 << 10)
61 #define GQSPI_IMD_DATA_CS_ASSERT 5
62 #define GQSPI_IMD_DATA_CS_DEASSERT 5
63 #define GQSPI_GFIFO_TX BIT(16)
64 #define GQSPI_GFIFO_RX BIT(17)
65 #define GQSPI_GFIFO_STRIPE_MASK BIT(18)
66 #define GQSPI_GFIFO_IMD_MASK 0xFF
67 #define GQSPI_GFIFO_EXP_MASK BIT(9)
68 #define GQSPI_GFIFO_DATA_XFR_MASK BIT(8)
69 #define GQSPI_STRT_GEN_FIFO BIT(28)
70 #define GQSPI_GEN_FIFO_STRT_MOD BIT(29)
71 #define GQSPI_GFIFO_WP_HOLD BIT(19)
72 #define GQSPI_BAUD_DIV_MASK (7 << 3)
73 #define GQSPI_DFLT_BAUD_RATE_DIV BIT(3)
74 #define GQSPI_GFIFO_ALL_INT_MASK 0xFBE
75 #define GQSPI_DMA_DST_I_STS_DONE BIT(1)
76 #define GQSPI_DMA_DST_I_STS_MASK 0xFE
79 #define GQSPI_GFIFO_SELECT BIT(0)
80 #define GQSPI_FIFO_THRESHOLD 1
81 #define GQSPI_GENFIFO_THRESHOLD 31
83 #define SPI_XFER_ON_BOTH 0
84 #define SPI_XFER_ON_LOWER 1
85 #define SPI_XFER_ON_UPPER 2
87 #define GQSPI_DMA_ALIGN 0x4
88 #define GQSPI_MAX_BAUD_RATE_VAL 7
89 #define GQSPI_DFLT_BAUD_RATE_VAL 2
91 #define GQSPI_TIMEOUT 100000000
93 #define GQSPI_BAUD_DIV_SHIFT 2
94 #define GQSPI_LPBK_DLY_ADJ_LPBK_SHIFT 5
95 #define GQSPI_LPBK_DLY_ADJ_DLY_1 0x2
96 #define GQSPI_LPBK_DLY_ADJ_DLY_1_SHIFT 3
97 #define GQSPI_LPBK_DLY_ADJ_DLY_0 0x3
98 #define GQSPI_USE_DATA_DLY 0x1
99 #define GQSPI_USE_DATA_DLY_SHIFT 31
100 #define GQSPI_DATA_DLY_ADJ_VALUE 0x2
101 #define GQSPI_DATA_DLY_ADJ_SHIFT 28
102 #define TAP_DLY_BYPASS_LQSPI_RX_VALUE 0x1
103 #define TAP_DLY_BYPASS_LQSPI_RX_SHIFT 2
104 #define GQSPI_DATA_DLY_ADJ_OFST 0x000001F8
105 #define IOU_TAPDLY_BYPASS_OFST 0xFF180390
106 #define GQSPI_LPBK_DLY_ADJ_LPBK_MASK 0x00000020
107 #define GQSPI_FREQ_40MHZ 40000000
108 #define GQSPI_FREQ_100MHZ 100000000
109 #define GQSPI_FREQ_150MHZ 150000000
110 #define IOU_TAPDLY_BYPASS_MASK 0x7
112 #define GQSPI_REG_OFFSET 0x100
113 #define GQSPI_DMA_REG_OFFSET 0x800
115 /* QSPI register offsets */
116 struct zynqmp_qspi_regs {
117 u32 confr; /* 0x00 */
120 u32 idisr; /* 0x0C */
121 u32 imaskr; /* 0x10 */
124 u32 txd0r; /* 0x1C */
127 u32 txftr; /* 0x28 */
128 u32 rxftr; /* 0x2C */
129 u32 gpior; /* 0x30 */
130 u32 reserved0; /* 0x34 */
131 u32 lpbkdly; /* 0x38 */
132 u32 reserved1; /* 0x3C */
133 u32 genfifo; /* 0x40 */
134 u32 gqspisel; /* 0x44 */
135 u32 reserved2; /* 0x48 */
136 u32 gqfifoctrl; /* 0x4C */
137 u32 gqfthr; /* 0x50 */
138 u32 gqpollcfg; /* 0x54 */
139 u32 gqpollto; /* 0x58 */
140 u32 gqxfersts; /* 0x5C */
141 u32 gqfifosnap; /* 0x60 */
142 u32 gqrxcpy; /* 0x64 */
143 u32 reserved3[36]; /* 0x68 */
144 u32 gqspidlyadj; /* 0xF8 */
147 struct zynqmp_qspi_dma_regs {
148 u32 dmadst; /* 0x00 */
149 u32 dmasize; /* 0x04 */
150 u32 dmasts; /* 0x08 */
151 u32 dmactrl; /* 0x0C */
152 u32 reserved0; /* 0x10 */
153 u32 dmaisr; /* 0x14 */
154 u32 dmaier; /* 0x18 */
155 u32 dmaidr; /* 0x1C */
156 u32 dmaimr; /* 0x20 */
157 u32 dmactrl2; /* 0x24 */
158 u32 dmadstmsb; /* 0x28 */
161 struct zynqmp_qspi_plat {
162 struct zynqmp_qspi_regs *regs;
163 struct zynqmp_qspi_dma_regs *dma_regs;
168 struct zynqmp_qspi_priv {
169 struct zynqmp_qspi_regs *regs;
170 struct zynqmp_qspi_dma_regs *dma_regs;
174 int bytes_to_transfer;
175 int bytes_to_receive;
176 const struct spi_mem_op *op;
179 static int zynqmp_qspi_of_to_plat(struct udevice *bus)
181 struct zynqmp_qspi_plat *plat = dev_get_plat(bus);
183 debug("%s\n", __func__);
185 plat->regs = (struct zynqmp_qspi_regs *)(dev_read_addr(bus) +
187 plat->dma_regs = (struct zynqmp_qspi_dma_regs *)
188 (dev_read_addr(bus) + GQSPI_DMA_REG_OFFSET);
193 static void zynqmp_qspi_init_hw(struct zynqmp_qspi_priv *priv)
196 struct zynqmp_qspi_regs *regs = priv->regs;
198 writel(GQSPI_GFIFO_SELECT, ®s->gqspisel);
199 writel(GQSPI_GFIFO_ALL_INT_MASK, ®s->idisr);
200 writel(GQSPI_FIFO_THRESHOLD, ®s->txftr);
201 writel(GQSPI_FIFO_THRESHOLD, ®s->rxftr);
202 writel(GQSPI_GENFIFO_THRESHOLD, ®s->gqfthr);
203 writel(GQSPI_GFIFO_ALL_INT_MASK, ®s->isr);
204 writel(~GQSPI_ENABLE_ENABLE_MASK, ®s->enbr);
206 config_reg = readl(®s->confr);
207 config_reg &= ~(GQSPI_GFIFO_STRT_MODE_MASK |
208 GQSPI_CONFIG_MODE_EN_MASK);
209 config_reg |= GQSPI_CONFIG_DMA_MODE | GQSPI_GFIFO_WP_HOLD |
210 GQSPI_DFLT_BAUD_RATE_DIV | GQSPI_GFIFO_STRT_MODE_MASK;
211 writel(config_reg, ®s->confr);
213 writel(GQSPI_ENABLE_ENABLE_MASK, ®s->enbr);
216 static u32 zynqmp_qspi_bus_select(struct zynqmp_qspi_priv *priv)
218 u32 gqspi_fifo_reg = 0;
220 gqspi_fifo_reg = GQSPI_GFIFO_LOW_BUS |
221 GQSPI_GFIFO_CS_LOWER;
223 return gqspi_fifo_reg;
226 static u32 zynqmp_qspi_genfifo_mode(u8 buswidth)
230 return GQSPI_SPI_MODE_SPI;
232 return GQSPI_SPI_MODE_DUAL_SPI;
234 return GQSPI_SPI_MODE_QSPI;
236 debug("Unsupported bus width %u\n", buswidth);
237 return GQSPI_SPI_MODE_SPI;
241 static void zynqmp_qspi_fill_gen_fifo(struct zynqmp_qspi_priv *priv,
244 struct zynqmp_qspi_regs *regs = priv->regs;
248 writel(gqspi_fifo_reg, ®s->genfifo);
250 config_reg = readl(®s->confr);
251 /* Manual start if needed */
252 config_reg |= GQSPI_STRT_GEN_FIFO;
253 writel(config_reg, ®s->confr);
255 /* Enable interrupts */
256 ier = readl(®s->ier);
257 ier |= GQSPI_IXR_GFEMTY_MASK;
258 writel(ier, ®s->ier);
260 /* Wait until the gen fifo is empty to write the new command */
261 ret = wait_for_bit_le32(®s->isr, GQSPI_IXR_GFEMTY_MASK, 1,
264 printf("%s Timeout\n", __func__);
268 static void zynqmp_qspi_chipselect(struct zynqmp_qspi_priv *priv, int is_on)
270 u32 gqspi_fifo_reg = 0;
273 gqspi_fifo_reg = zynqmp_qspi_bus_select(priv);
274 gqspi_fifo_reg |= GQSPI_SPI_MODE_SPI |
275 GQSPI_IMD_DATA_CS_ASSERT;
277 gqspi_fifo_reg = GQSPI_GFIFO_LOW_BUS;
278 gqspi_fifo_reg |= GQSPI_IMD_DATA_CS_DEASSERT;
281 debug("GFIFO_CMD_CS: 0x%x\n", gqspi_fifo_reg);
283 zynqmp_qspi_fill_gen_fifo(priv, gqspi_fifo_reg);
286 void zynqmp_qspi_set_tapdelay(struct udevice *bus, u32 baudrateval)
288 struct zynqmp_qspi_plat *plat = dev_get_plat(bus);
289 struct zynqmp_qspi_priv *priv = dev_get_priv(bus);
290 struct zynqmp_qspi_regs *regs = priv->regs;
291 u32 tapdlybypass = 0, lpbkdlyadj = 0, datadlyadj = 0, clk_rate;
294 clk_rate = plat->frequency;
295 reqhz = (clk_rate / (GQSPI_BAUD_DIV_SHIFT << baudrateval));
297 debug("%s, req_hz:%d, clk_rate:%d, baudrateval:%d\n",
298 __func__, reqhz, clk_rate, baudrateval);
300 if (reqhz < GQSPI_FREQ_40MHZ) {
301 zynqmp_mmio_read(IOU_TAPDLY_BYPASS_OFST, &tapdlybypass);
302 tapdlybypass |= (TAP_DLY_BYPASS_LQSPI_RX_VALUE <<
303 TAP_DLY_BYPASS_LQSPI_RX_SHIFT);
304 } else if (reqhz <= GQSPI_FREQ_100MHZ) {
305 zynqmp_mmio_read(IOU_TAPDLY_BYPASS_OFST, &tapdlybypass);
306 tapdlybypass |= (TAP_DLY_BYPASS_LQSPI_RX_VALUE <<
307 TAP_DLY_BYPASS_LQSPI_RX_SHIFT);
308 lpbkdlyadj = readl(®s->lpbkdly);
309 lpbkdlyadj |= (GQSPI_LPBK_DLY_ADJ_LPBK_MASK);
310 datadlyadj = readl(®s->gqspidlyadj);
311 datadlyadj |= ((GQSPI_USE_DATA_DLY << GQSPI_USE_DATA_DLY_SHIFT)
312 | (GQSPI_DATA_DLY_ADJ_VALUE <<
313 GQSPI_DATA_DLY_ADJ_SHIFT));
314 } else if (reqhz <= GQSPI_FREQ_150MHZ) {
315 lpbkdlyadj = readl(®s->lpbkdly);
316 lpbkdlyadj |= ((GQSPI_LPBK_DLY_ADJ_LPBK_MASK) |
317 GQSPI_LPBK_DLY_ADJ_DLY_0);
320 zynqmp_mmio_write(IOU_TAPDLY_BYPASS_OFST, IOU_TAPDLY_BYPASS_MASK,
322 writel(lpbkdlyadj, ®s->lpbkdly);
323 writel(datadlyadj, ®s->gqspidlyadj);
326 static int zynqmp_qspi_set_speed(struct udevice *bus, uint speed)
328 struct zynqmp_qspi_plat *plat = dev_get_plat(bus);
329 struct zynqmp_qspi_priv *priv = dev_get_priv(bus);
330 struct zynqmp_qspi_regs *regs = priv->regs;
332 u8 baud_rate_val = 0;
334 debug("%s\n", __func__);
335 if (speed > plat->frequency)
336 speed = plat->frequency;
338 if (plat->speed_hz != speed) {
339 /* Set the clock frequency */
340 /* If speed == 0, default to lowest speed */
341 while ((baud_rate_val < 8) &&
343 (2 << baud_rate_val)) > speed))
346 if (baud_rate_val > GQSPI_MAX_BAUD_RATE_VAL)
347 baud_rate_val = GQSPI_DFLT_BAUD_RATE_VAL;
349 plat->speed_hz = plat->frequency / (2 << baud_rate_val);
351 confr = readl(®s->confr);
352 confr &= ~GQSPI_BAUD_DIV_MASK;
353 confr |= (baud_rate_val << 3);
354 writel(confr, ®s->confr);
355 zynqmp_qspi_set_tapdelay(bus, baud_rate_val);
357 debug("regs=%p, speed=%d\n", priv->regs, plat->speed_hz);
363 static int zynqmp_qspi_probe(struct udevice *bus)
365 struct zynqmp_qspi_plat *plat = dev_get_plat(bus);
366 struct zynqmp_qspi_priv *priv = dev_get_priv(bus);
371 debug("%s: bus:%p, priv:%p\n", __func__, bus, priv);
373 priv->regs = plat->regs;
374 priv->dma_regs = plat->dma_regs;
376 ret = clk_get_by_index(bus, 0, &clk);
378 dev_err(bus, "failed to get clock\n");
382 clock = clk_get_rate(&clk);
383 if (IS_ERR_VALUE(clock)) {
384 dev_err(bus, "failed to get rate\n");
387 debug("%s: CLK %ld\n", __func__, clock);
389 ret = clk_enable(&clk);
391 dev_err(bus, "failed to enable clock\n");
394 plat->frequency = clock;
395 plat->speed_hz = plat->frequency / 2;
397 /* init the zynq spi hw */
398 zynqmp_qspi_init_hw(priv);
403 static int zynqmp_qspi_set_mode(struct udevice *bus, uint mode)
405 struct zynqmp_qspi_priv *priv = dev_get_priv(bus);
406 struct zynqmp_qspi_regs *regs = priv->regs;
409 debug("%s\n", __func__);
410 /* Set the SPI Clock phase and polarities */
411 confr = readl(®s->confr);
412 confr &= ~(GQSPI_CONFIG_CPHA_MASK |
413 GQSPI_CONFIG_CPOL_MASK);
416 confr |= GQSPI_CONFIG_CPHA_MASK;
418 confr |= GQSPI_CONFIG_CPOL_MASK;
420 writel(confr, ®s->confr);
425 static int zynqmp_qspi_fill_tx_fifo(struct zynqmp_qspi_priv *priv, u32 size)
429 struct zynqmp_qspi_regs *regs = priv->regs;
430 u32 *buf = (u32 *)priv->tx_buf;
433 debug("TxFIFO: 0x%x, size: 0x%x\n", readl(®s->isr),
437 ret = wait_for_bit_le32(®s->isr, GQSPI_IXR_TXNFULL_MASK, 1,
440 printf("%s: Timeout\n", __func__);
445 writel(*buf, ®s->txd0r);
453 data |= GENMASK(31, 8);
456 data = *((u16 *)buf);
458 data |= GENMASK(31, 16);
463 data |= GENMASK(31, 24);
466 writel(data, ®s->txd0r);
471 ret = wait_for_bit_le32(®s->isr, GQSPI_IXR_TXFIFOEMPTY_MASK, 1,
474 printf("%s: Timeout\n", __func__);
482 static void zynqmp_qspi_genfifo_cmd(struct zynqmp_qspi_priv *priv)
484 const struct spi_mem_op *op = priv->op;
486 u8 i, dummy_cycles, addr;
489 gen_fifo_cmd = zynqmp_qspi_bus_select(priv);
490 gen_fifo_cmd |= zynqmp_qspi_genfifo_mode(op->cmd.buswidth);
491 gen_fifo_cmd |= GQSPI_GFIFO_TX;
492 gen_fifo_cmd |= op->cmd.opcode;
493 zynqmp_qspi_fill_gen_fifo(priv, gen_fifo_cmd);
496 for (i = 0; i < op->addr.nbytes; i++) {
497 addr = op->addr.val >> (8 * (op->addr.nbytes - i - 1));
499 gen_fifo_cmd = zynqmp_qspi_bus_select(priv);
500 gen_fifo_cmd |= zynqmp_qspi_genfifo_mode(op->addr.buswidth);
501 gen_fifo_cmd |= GQSPI_GFIFO_TX;
502 gen_fifo_cmd |= addr;
504 debug("GFIFO_CMD_Cmd = 0x%x\n", gen_fifo_cmd);
506 zynqmp_qspi_fill_gen_fifo(priv, gen_fifo_cmd);
510 if (op->dummy.nbytes) {
511 dummy_cycles = op->dummy.nbytes * 8 / op->dummy.buswidth;
513 gen_fifo_cmd = zynqmp_qspi_bus_select(priv);
514 gen_fifo_cmd |= zynqmp_qspi_genfifo_mode(op->dummy.buswidth);
515 gen_fifo_cmd &= ~(GQSPI_GFIFO_TX | GQSPI_GFIFO_RX);
516 gen_fifo_cmd |= GQSPI_GFIFO_DATA_XFR_MASK;
517 gen_fifo_cmd |= dummy_cycles;
518 zynqmp_qspi_fill_gen_fifo(priv, gen_fifo_cmd);
522 static u32 zynqmp_qspi_calc_exp(struct zynqmp_qspi_priv *priv,
529 if (priv->len > 255) {
530 if (priv->len & (1 << expval)) {
531 *gen_fifo_cmd &= ~GQSPI_GFIFO_IMD_MASK;
532 *gen_fifo_cmd |= GQSPI_GFIFO_EXP_MASK;
533 *gen_fifo_cmd |= expval;
534 priv->len -= (1 << expval);
539 *gen_fifo_cmd &= ~(GQSPI_GFIFO_IMD_MASK |
540 GQSPI_GFIFO_EXP_MASK);
541 *gen_fifo_cmd |= (u8)priv->len;
549 static int zynqmp_qspi_genfifo_fill_tx(struct zynqmp_qspi_priv *priv)
555 gen_fifo_cmd = zynqmp_qspi_bus_select(priv);
556 gen_fifo_cmd |= zynqmp_qspi_genfifo_mode(priv->op->data.buswidth);
557 gen_fifo_cmd |= GQSPI_GFIFO_TX |
558 GQSPI_GFIFO_DATA_XFR_MASK;
561 len = zynqmp_qspi_calc_exp(priv, &gen_fifo_cmd);
562 zynqmp_qspi_fill_gen_fifo(priv, gen_fifo_cmd);
564 debug("GFIFO_CMD_TX:0x%x\n", gen_fifo_cmd);
566 if (gen_fifo_cmd & GQSPI_GFIFO_EXP_MASK)
567 ret = zynqmp_qspi_fill_tx_fifo(priv,
570 ret = zynqmp_qspi_fill_tx_fifo(priv,
579 static int zynqmp_qspi_start_dma(struct zynqmp_qspi_priv *priv,
580 u32 gen_fifo_cmd, u32 *buf)
584 u32 actuallen = priv->len;
586 struct zynqmp_qspi_dma_regs *dma_regs = priv->dma_regs;
588 writel((unsigned long)buf, &dma_regs->dmadst);
589 writel(roundup(priv->len, GQSPI_DMA_ALIGN), &dma_regs->dmasize);
590 writel(GQSPI_DMA_DST_I_STS_MASK, &dma_regs->dmaier);
591 addr = (unsigned long)buf;
592 size = roundup(priv->len, GQSPI_DMA_ALIGN);
593 flush_dcache_range(addr, addr + size);
596 zynqmp_qspi_calc_exp(priv, &gen_fifo_cmd);
597 zynqmp_qspi_fill_gen_fifo(priv, gen_fifo_cmd);
599 debug("GFIFO_CMD_RX:0x%x\n", gen_fifo_cmd);
602 ret = wait_for_bit_le32(&dma_regs->dmaisr, GQSPI_DMA_DST_I_STS_DONE,
603 1, GQSPI_TIMEOUT, 1);
605 printf("DMA Timeout:0x%x\n", readl(&dma_regs->dmaisr));
609 writel(GQSPI_DMA_DST_I_STS_DONE, &dma_regs->dmaisr);
611 debug("buf:0x%lx, rxbuf:0x%lx, *buf:0x%x len: 0x%x\n",
612 (unsigned long)buf, (unsigned long)priv->rx_buf, *buf,
615 if (buf != priv->rx_buf)
616 memcpy(priv->rx_buf, buf, actuallen);
621 static int zynqmp_qspi_genfifo_fill_rx(struct zynqmp_qspi_priv *priv)
625 u32 actuallen = priv->len;
627 gen_fifo_cmd = zynqmp_qspi_bus_select(priv);
628 gen_fifo_cmd |= zynqmp_qspi_genfifo_mode(priv->op->data.buswidth);
629 gen_fifo_cmd |= GQSPI_GFIFO_RX |
630 GQSPI_GFIFO_DATA_XFR_MASK;
633 * Check if receive buffer is aligned to 4 byte and length
634 * is multiples of four byte as we are using dma to receive.
636 if (!((unsigned long)priv->rx_buf & (GQSPI_DMA_ALIGN - 1)) &&
637 !(actuallen % GQSPI_DMA_ALIGN)) {
638 buf = (u32 *)priv->rx_buf;
639 return zynqmp_qspi_start_dma(priv, gen_fifo_cmd, buf);
642 ALLOC_CACHE_ALIGN_BUFFER(u8, tmp, roundup(priv->len,
645 return zynqmp_qspi_start_dma(priv, gen_fifo_cmd, buf);
648 static int zynqmp_qspi_claim_bus(struct udevice *dev)
650 struct udevice *bus = dev->parent;
651 struct zynqmp_qspi_priv *priv = dev_get_priv(bus);
652 struct zynqmp_qspi_regs *regs = priv->regs;
654 writel(GQSPI_ENABLE_ENABLE_MASK, ®s->enbr);
659 static int zynqmp_qspi_release_bus(struct udevice *dev)
661 struct udevice *bus = dev->parent;
662 struct zynqmp_qspi_priv *priv = dev_get_priv(bus);
663 struct zynqmp_qspi_regs *regs = priv->regs;
665 writel(~GQSPI_ENABLE_ENABLE_MASK, ®s->enbr);
670 static int zynqmp_qspi_exec_op(struct spi_slave *slave,
671 const struct spi_mem_op *op)
673 struct zynqmp_qspi_priv *priv = dev_get_priv(slave->dev->parent);
677 priv->tx_buf = op->data.buf.out;
678 priv->rx_buf = op->data.buf.in;
679 priv->len = op->data.nbytes;
681 zynqmp_qspi_chipselect(priv, 1);
683 /* Send opcode, addr, dummy */
684 zynqmp_qspi_genfifo_cmd(priv);
686 /* Request the transfer */
687 if (op->data.dir == SPI_MEM_DATA_IN)
688 ret = zynqmp_qspi_genfifo_fill_rx(priv);
689 else if (op->data.dir == SPI_MEM_DATA_OUT)
690 ret = zynqmp_qspi_genfifo_fill_tx(priv);
692 zynqmp_qspi_chipselect(priv, 0);
697 static const struct spi_controller_mem_ops zynqmp_qspi_mem_ops = {
698 .exec_op = zynqmp_qspi_exec_op,
701 static const struct dm_spi_ops zynqmp_qspi_ops = {
702 .claim_bus = zynqmp_qspi_claim_bus,
703 .release_bus = zynqmp_qspi_release_bus,
704 .set_speed = zynqmp_qspi_set_speed,
705 .set_mode = zynqmp_qspi_set_mode,
706 .mem_ops = &zynqmp_qspi_mem_ops,
709 static const struct udevice_id zynqmp_qspi_ids[] = {
710 { .compatible = "xlnx,zynqmp-qspi-1.0" },
711 { .compatible = "xlnx,versal-qspi-1.0" },
715 U_BOOT_DRIVER(zynqmp_qspi) = {
716 .name = "zynqmp_qspi",
718 .of_match = zynqmp_qspi_ids,
719 .ops = &zynqmp_qspi_ops,
720 .of_to_plat = zynqmp_qspi_of_to_plat,
721 .plat_auto = sizeof(struct zynqmp_qspi_plat),
722 .priv_auto = sizeof(struct zynqmp_qspi_priv),
723 .probe = zynqmp_qspi_probe,