blob: ae795e50b0a53efb4173d007efabb42ad6cb22bd [file] [log] [blame]
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +05301// SPDX-License-Identifier: GPL-2.0+
2/*
3 * (C) Copyright 2018 Xilinx
4 *
5 * Xilinx ZynqMP Generic Quad-SPI(QSPI) controller driver(master mode only)
6 */
7
Ibai Erkiaga78974fb2023-10-13 13:37:27 +01008#define LOG_CATEGORY UCLASS_SPI
9
Simon Glass63334482019-11-14 12:57:39 -070010#include <cpu_func.h>
Simon Glass0f2af882020-05-10 11:40:05 -060011#include <log.h>
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +053012#include <asm/arch/sys_proto.h>
Simon Glass274e0b02020-05-10 11:39:56 -060013#include <asm/cache.h>
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +053014#include <asm/io.h>
15#include <clk.h>
16#include <dm.h>
17#include <malloc.h>
18#include <memalign.h>
19#include <spi.h>
Brandon Maier4d9cce72021-01-20 10:39:46 -060020#include <spi-mem.h>
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +053021#include <ubi_uboot.h>
22#include <wait_bit.h>
Simon Glass9bc15642020-02-03 07:36:16 -070023#include <dm/device_compat.h>
Simon Glass4dcacfc2020-05-10 11:40:13 -060024#include <linux/bitops.h>
Simon Glassd66c5f72020-02-03 07:36:15 -070025#include <linux/err.h>
Ashok Reddy Soma2d322cc2022-08-25 06:59:04 -060026#include <linux/sizes.h>
Ashok Reddy Somae3c77a62022-08-25 06:59:01 -060027#include <zynqmp_firmware.h>
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +053028
29#define GQSPI_GFIFO_STRT_MODE_MASK BIT(29)
30#define GQSPI_CONFIG_MODE_EN_MASK (3 << 30)
31#define GQSPI_CONFIG_DMA_MODE (2 << 30)
32#define GQSPI_CONFIG_CPHA_MASK BIT(2)
33#define GQSPI_CONFIG_CPOL_MASK BIT(1)
34
35/*
36 * QSPI Interrupt Registers bit Masks
37 *
38 * All the four interrupt registers (Status/Mask/Enable/Disable) have the same
39 * bit definitions.
40 */
41#define GQSPI_IXR_TXNFULL_MASK 0x00000004 /* QSPI TX FIFO Overflow */
42#define GQSPI_IXR_TXFULL_MASK 0x00000008 /* QSPI TX FIFO is full */
Ashok Reddy Soma26f77d72021-10-19 19:43:00 +053043#define GQSPI_IXR_TXFIFOEMPTY_MASK 0x00000100 /* QSPI TX FIFO is Empty */
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +053044#define GQSPI_IXR_RXNEMTY_MASK 0x00000010 /* QSPI RX FIFO Not Empty */
45#define GQSPI_IXR_GFEMTY_MASK 0x00000080 /* QSPI Generic FIFO Empty */
Ashok Reddy Soma2af829f2021-05-25 06:36:27 -060046#define GQSPI_IXR_GFNFULL_MASK 0x00000200 /* QSPI GENFIFO not full */
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +053047#define GQSPI_IXR_ALL_MASK (GQSPI_IXR_TXNFULL_MASK | \
48 GQSPI_IXR_RXNEMTY_MASK)
49
50/*
51 * QSPI Enable Register bit Masks
52 *
53 * This register is used to enable or disable the QSPI controller
54 */
55#define GQSPI_ENABLE_ENABLE_MASK 0x00000001 /* QSPI Enable Bit Mask */
56
57#define GQSPI_GFIFO_LOW_BUS BIT(14)
58#define GQSPI_GFIFO_CS_LOWER BIT(12)
59#define GQSPI_GFIFO_UP_BUS BIT(15)
60#define GQSPI_GFIFO_CS_UPPER BIT(13)
61#define GQSPI_SPI_MODE_QSPI (3 << 10)
62#define GQSPI_SPI_MODE_SPI BIT(10)
63#define GQSPI_SPI_MODE_DUAL_SPI (2 << 10)
64#define GQSPI_IMD_DATA_CS_ASSERT 5
65#define GQSPI_IMD_DATA_CS_DEASSERT 5
66#define GQSPI_GFIFO_TX BIT(16)
67#define GQSPI_GFIFO_RX BIT(17)
68#define GQSPI_GFIFO_STRIPE_MASK BIT(18)
69#define GQSPI_GFIFO_IMD_MASK 0xFF
70#define GQSPI_GFIFO_EXP_MASK BIT(9)
71#define GQSPI_GFIFO_DATA_XFR_MASK BIT(8)
72#define GQSPI_STRT_GEN_FIFO BIT(28)
73#define GQSPI_GEN_FIFO_STRT_MOD BIT(29)
74#define GQSPI_GFIFO_WP_HOLD BIT(19)
75#define GQSPI_BAUD_DIV_MASK (7 << 3)
76#define GQSPI_DFLT_BAUD_RATE_DIV BIT(3)
77#define GQSPI_GFIFO_ALL_INT_MASK 0xFBE
78#define GQSPI_DMA_DST_I_STS_DONE BIT(1)
79#define GQSPI_DMA_DST_I_STS_MASK 0xFE
80#define MODEBITS 0x6
81
82#define GQSPI_GFIFO_SELECT BIT(0)
83#define GQSPI_FIFO_THRESHOLD 1
Ashok Reddy Soma822a2432021-08-20 07:43:17 -060084#define GQSPI_GENFIFO_THRESHOLD 31
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +053085
86#define SPI_XFER_ON_BOTH 0
87#define SPI_XFER_ON_LOWER 1
88#define SPI_XFER_ON_UPPER 2
89
90#define GQSPI_DMA_ALIGN 0x4
91#define GQSPI_MAX_BAUD_RATE_VAL 7
92#define GQSPI_DFLT_BAUD_RATE_VAL 2
93
94#define GQSPI_TIMEOUT 100000000
95
96#define GQSPI_BAUD_DIV_SHIFT 2
97#define GQSPI_LPBK_DLY_ADJ_LPBK_SHIFT 5
T Karthik Reddy751533d2022-11-23 02:04:51 -070098#define GQSPI_LPBK_DLY_ADJ_DLY_1 0x1
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +053099#define GQSPI_LPBK_DLY_ADJ_DLY_1_SHIFT 3
100#define GQSPI_LPBK_DLY_ADJ_DLY_0 0x3
101#define GQSPI_USE_DATA_DLY 0x1
102#define GQSPI_USE_DATA_DLY_SHIFT 31
103#define GQSPI_DATA_DLY_ADJ_VALUE 0x2
104#define GQSPI_DATA_DLY_ADJ_SHIFT 28
105#define TAP_DLY_BYPASS_LQSPI_RX_VALUE 0x1
106#define TAP_DLY_BYPASS_LQSPI_RX_SHIFT 2
107#define GQSPI_DATA_DLY_ADJ_OFST 0x000001F8
Ashok Reddy Somaef3e30b2022-11-16 16:40:30 +0100108#define IOU_TAPDLY_BYPASS_OFST !(IS_ENABLED(CONFIG_ARCH_VERSAL) || \
Michal Simek71bfd392024-05-29 16:48:01 +0200109 IS_ENABLED(CONFIG_ARCH_VERSAL_NET) || \
110 IS_ENABLED(CONFIG_ARCH_VERSAL2)) ? \
Ashok Reddy Somae3c77a62022-08-25 06:59:01 -0600111 0xFF180390 : 0xF103003C
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530112#define GQSPI_LPBK_DLY_ADJ_LPBK_MASK 0x00000020
Ashok Reddy Somae3c77a62022-08-25 06:59:01 -0600113#define GQSPI_FREQ_37_5MHZ 37500000
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530114#define GQSPI_FREQ_40MHZ 40000000
115#define GQSPI_FREQ_100MHZ 100000000
116#define GQSPI_FREQ_150MHZ 150000000
117#define IOU_TAPDLY_BYPASS_MASK 0x7
118
119#define GQSPI_REG_OFFSET 0x100
120#define GQSPI_DMA_REG_OFFSET 0x800
121
122/* QSPI register offsets */
123struct zynqmp_qspi_regs {
124 u32 confr; /* 0x00 */
125 u32 isr; /* 0x04 */
126 u32 ier; /* 0x08 */
127 u32 idisr; /* 0x0C */
128 u32 imaskr; /* 0x10 */
129 u32 enbr; /* 0x14 */
130 u32 dr; /* 0x18 */
131 u32 txd0r; /* 0x1C */
132 u32 drxr; /* 0x20 */
133 u32 sicr; /* 0x24 */
134 u32 txftr; /* 0x28 */
135 u32 rxftr; /* 0x2C */
136 u32 gpior; /* 0x30 */
137 u32 reserved0; /* 0x34 */
138 u32 lpbkdly; /* 0x38 */
139 u32 reserved1; /* 0x3C */
140 u32 genfifo; /* 0x40 */
141 u32 gqspisel; /* 0x44 */
142 u32 reserved2; /* 0x48 */
143 u32 gqfifoctrl; /* 0x4C */
144 u32 gqfthr; /* 0x50 */
145 u32 gqpollcfg; /* 0x54 */
146 u32 gqpollto; /* 0x58 */
147 u32 gqxfersts; /* 0x5C */
148 u32 gqfifosnap; /* 0x60 */
149 u32 gqrxcpy; /* 0x64 */
150 u32 reserved3[36]; /* 0x68 */
151 u32 gqspidlyadj; /* 0xF8 */
152};
153
154struct zynqmp_qspi_dma_regs {
155 u32 dmadst; /* 0x00 */
156 u32 dmasize; /* 0x04 */
157 u32 dmasts; /* 0x08 */
158 u32 dmactrl; /* 0x0C */
159 u32 reserved0; /* 0x10 */
160 u32 dmaisr; /* 0x14 */
161 u32 dmaier; /* 0x18 */
162 u32 dmaidr; /* 0x1C */
163 u32 dmaimr; /* 0x20 */
164 u32 dmactrl2; /* 0x24 */
165 u32 dmadstmsb; /* 0x28 */
166};
167
Simon Glassb75b15b2020-12-03 16:55:23 -0700168struct zynqmp_qspi_plat {
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530169 struct zynqmp_qspi_regs *regs;
170 struct zynqmp_qspi_dma_regs *dma_regs;
171 u32 frequency;
172 u32 speed_hz;
Ashok Reddy Soma96db8b62022-08-25 06:59:03 -0600173 unsigned int io_mode;
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530174};
175
176struct zynqmp_qspi_priv {
177 struct zynqmp_qspi_regs *regs;
178 struct zynqmp_qspi_dma_regs *dma_regs;
179 const void *tx_buf;
180 void *rx_buf;
181 unsigned int len;
Ashok Reddy Soma96db8b62022-08-25 06:59:03 -0600182 unsigned int io_mode;
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530183 int bytes_to_transfer;
184 int bytes_to_receive;
Brandon Maier4d9cce72021-01-20 10:39:46 -0600185 const struct spi_mem_op *op;
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530186};
187
Algapally Santosh Sagar58f731a2023-03-01 03:33:33 -0700188__weak int zynqmp_mmio_write(const u32 address, const u32 mask, const u32 value)
189{
190 return 0;
191}
192
Simon Glassaad29ae2020-12-03 16:55:21 -0700193static int zynqmp_qspi_of_to_plat(struct udevice *bus)
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530194{
Simon Glass95588622020-12-22 19:30:28 -0700195 struct zynqmp_qspi_plat *plat = dev_get_plat(bus);
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530196
Masahiro Yamadaa89b4de2020-07-17 14:36:48 +0900197 plat->regs = (struct zynqmp_qspi_regs *)(dev_read_addr(bus) +
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530198 GQSPI_REG_OFFSET);
199 plat->dma_regs = (struct zynqmp_qspi_dma_regs *)
Masahiro Yamadaa89b4de2020-07-17 14:36:48 +0900200 (dev_read_addr(bus) + GQSPI_DMA_REG_OFFSET);
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530201
Ashok Reddy Soma96db8b62022-08-25 06:59:03 -0600202 plat->io_mode = dev_read_bool(bus, "has-io-mode");
203
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530204 return 0;
205}
206
207static void zynqmp_qspi_init_hw(struct zynqmp_qspi_priv *priv)
208{
209 u32 config_reg;
210 struct zynqmp_qspi_regs *regs = priv->regs;
211
212 writel(GQSPI_GFIFO_SELECT, &regs->gqspisel);
213 writel(GQSPI_GFIFO_ALL_INT_MASK, &regs->idisr);
214 writel(GQSPI_FIFO_THRESHOLD, &regs->txftr);
215 writel(GQSPI_FIFO_THRESHOLD, &regs->rxftr);
Ashok Reddy Soma822a2432021-08-20 07:43:17 -0600216 writel(GQSPI_GENFIFO_THRESHOLD, &regs->gqfthr);
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530217 writel(GQSPI_GFIFO_ALL_INT_MASK, &regs->isr);
Ashok Reddy Soma822a2432021-08-20 07:43:17 -0600218 writel(~GQSPI_ENABLE_ENABLE_MASK, &regs->enbr);
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530219
220 config_reg = readl(&regs->confr);
221 config_reg &= ~(GQSPI_GFIFO_STRT_MODE_MASK |
222 GQSPI_CONFIG_MODE_EN_MASK);
Ashok Reddy Soma96db8b62022-08-25 06:59:03 -0600223 config_reg |= GQSPI_GFIFO_WP_HOLD | GQSPI_DFLT_BAUD_RATE_DIV;
224 config_reg |= GQSPI_GFIFO_STRT_MODE_MASK;
225 if (!priv->io_mode)
226 config_reg |= GQSPI_CONFIG_DMA_MODE;
227
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530228 writel(config_reg, &regs->confr);
229
230 writel(GQSPI_ENABLE_ENABLE_MASK, &regs->enbr);
231}
232
233static u32 zynqmp_qspi_bus_select(struct zynqmp_qspi_priv *priv)
234{
235 u32 gqspi_fifo_reg = 0;
236
237 gqspi_fifo_reg = GQSPI_GFIFO_LOW_BUS |
238 GQSPI_GFIFO_CS_LOWER;
239
240 return gqspi_fifo_reg;
241}
242
Brandon Maier4d9cce72021-01-20 10:39:46 -0600243static u32 zynqmp_qspi_genfifo_mode(u8 buswidth)
244{
245 switch (buswidth) {
246 case 1:
247 return GQSPI_SPI_MODE_SPI;
248 case 2:
249 return GQSPI_SPI_MODE_DUAL_SPI;
250 case 4:
251 return GQSPI_SPI_MODE_QSPI;
252 default:
Ibai Erkiaga78974fb2023-10-13 13:37:27 +0100253 log_warning("Unsupported bus width %u\n", buswidth);
Brandon Maier4d9cce72021-01-20 10:39:46 -0600254 return GQSPI_SPI_MODE_SPI;
255 }
256}
257
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530258static void zynqmp_qspi_fill_gen_fifo(struct zynqmp_qspi_priv *priv,
259 u32 gqspi_fifo_reg)
260{
261 struct zynqmp_qspi_regs *regs = priv->regs;
Ashok Reddy Soma2af829f2021-05-25 06:36:27 -0600262 u32 config_reg, ier;
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530263 int ret = 0;
264
Ibai Erkiaga78974fb2023-10-13 13:37:27 +0100265 log_content("%s, GFIFO_CMD: 0x%X\n", __func__, gqspi_fifo_reg);
266
Ashok Reddy Soma1c35adc2021-08-20 07:43:16 -0600267 writel(gqspi_fifo_reg, &regs->genfifo);
268
Ashok Reddy Soma2af829f2021-05-25 06:36:27 -0600269 config_reg = readl(&regs->confr);
270 /* Manual start if needed */
271 config_reg |= GQSPI_STRT_GEN_FIFO;
272 writel(config_reg, &regs->confr);
273
274 /* Enable interrupts */
275 ier = readl(&regs->ier);
Ashok Reddy Soma1c35adc2021-08-20 07:43:16 -0600276 ier |= GQSPI_IXR_GFEMTY_MASK;
Ashok Reddy Soma2af829f2021-05-25 06:36:27 -0600277 writel(ier, &regs->ier);
278
Ashok Reddy Soma1c35adc2021-08-20 07:43:16 -0600279 /* Wait until the gen fifo is empty to write the new command */
280 ret = wait_for_bit_le32(&regs->isr, GQSPI_IXR_GFEMTY_MASK, 1,
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530281 GQSPI_TIMEOUT, 1);
282 if (ret)
Ibai Erkiaga78974fb2023-10-13 13:37:27 +0100283 log_warning("%s, Timeout\n", __func__);
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530284
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530285}
286
287static void zynqmp_qspi_chipselect(struct zynqmp_qspi_priv *priv, int is_on)
288{
289 u32 gqspi_fifo_reg = 0;
290
Ibai Erkiaga78974fb2023-10-13 13:37:27 +0100291 log_debug("%s, assert: %d\r\n", __func__, is_on);
292
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530293 if (is_on) {
294 gqspi_fifo_reg = zynqmp_qspi_bus_select(priv);
295 gqspi_fifo_reg |= GQSPI_SPI_MODE_SPI |
296 GQSPI_IMD_DATA_CS_ASSERT;
297 } else {
298 gqspi_fifo_reg = GQSPI_GFIFO_LOW_BUS;
299 gqspi_fifo_reg |= GQSPI_IMD_DATA_CS_DEASSERT;
300 }
301
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530302 zynqmp_qspi_fill_gen_fifo(priv, gqspi_fifo_reg);
303}
304
Venkatesh Yadav Abbarapuf6dfade2022-10-04 11:07:30 +0530305static void zynqmp_qspi_set_tapdelay(struct udevice *bus, u32 baudrateval)
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530306{
Simon Glass95588622020-12-22 19:30:28 -0700307 struct zynqmp_qspi_plat *plat = dev_get_plat(bus);
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530308 struct zynqmp_qspi_priv *priv = dev_get_priv(bus);
309 struct zynqmp_qspi_regs *regs = priv->regs;
310 u32 tapdlybypass = 0, lpbkdlyadj = 0, datadlyadj = 0, clk_rate;
311 u32 reqhz = 0;
312
313 clk_rate = plat->frequency;
314 reqhz = (clk_rate / (GQSPI_BAUD_DIV_SHIFT << baudrateval));
315
Ibai Erkiaga78974fb2023-10-13 13:37:27 +0100316 log_debug("%s, clk_rate:%d, baudrateval:%d, bus_clk: %d\n",
317 __func__, clk_rate, baudrateval, reqhz);
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530318
Michal Simek06995c42022-09-19 14:21:04 +0200319 if (!(IS_ENABLED(CONFIG_ARCH_VERSAL) ||
Michal Simek71bfd392024-05-29 16:48:01 +0200320 IS_ENABLED(CONFIG_ARCH_VERSAL_NET) ||
321 IS_ENABLED(CONFIG_ARCH_VERSAL2))) {
Ashok Reddy Somae3c77a62022-08-25 06:59:01 -0600322 if (reqhz <= GQSPI_FREQ_40MHZ) {
323 tapdlybypass = TAP_DLY_BYPASS_LQSPI_RX_VALUE <<
324 TAP_DLY_BYPASS_LQSPI_RX_SHIFT;
325 } else if (reqhz <= GQSPI_FREQ_100MHZ) {
326 tapdlybypass = TAP_DLY_BYPASS_LQSPI_RX_VALUE <<
327 TAP_DLY_BYPASS_LQSPI_RX_SHIFT;
328 lpbkdlyadj = GQSPI_LPBK_DLY_ADJ_LPBK_MASK;
329 datadlyadj = (GQSPI_USE_DATA_DLY <<
330 GQSPI_USE_DATA_DLY_SHIFT) |
331 (GQSPI_DATA_DLY_ADJ_VALUE <<
332 GQSPI_DATA_DLY_ADJ_SHIFT);
333 } else if (reqhz <= GQSPI_FREQ_150MHZ) {
334 lpbkdlyadj = GQSPI_LPBK_DLY_ADJ_LPBK_MASK |
335 GQSPI_LPBK_DLY_ADJ_DLY_0;
336 }
337 zynqmp_mmio_write(IOU_TAPDLY_BYPASS_OFST,
338 IOU_TAPDLY_BYPASS_MASK, tapdlybypass);
339 } else {
340 if (reqhz <= GQSPI_FREQ_37_5MHZ) {
341 tapdlybypass = TAP_DLY_BYPASS_LQSPI_RX_VALUE <<
342 TAP_DLY_BYPASS_LQSPI_RX_SHIFT;
343 } else if (reqhz <= GQSPI_FREQ_100MHZ) {
344 tapdlybypass = TAP_DLY_BYPASS_LQSPI_RX_VALUE <<
345 TAP_DLY_BYPASS_LQSPI_RX_SHIFT;
346 lpbkdlyadj = GQSPI_LPBK_DLY_ADJ_LPBK_MASK;
347 datadlyadj = GQSPI_USE_DATA_DLY <<
348 GQSPI_USE_DATA_DLY_SHIFT;
349 } else if (reqhz <= GQSPI_FREQ_150MHZ) {
350 lpbkdlyadj = GQSPI_LPBK_DLY_ADJ_LPBK_MASK |
351 (GQSPI_LPBK_DLY_ADJ_DLY_1 <<
352 GQSPI_LPBK_DLY_ADJ_DLY_1_SHIFT);
353 }
354 writel(tapdlybypass, IOU_TAPDLY_BYPASS_OFST);
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530355 }
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530356 writel(lpbkdlyadj, &regs->lpbkdly);
357 writel(datadlyadj, &regs->gqspidlyadj);
358}
359
360static int zynqmp_qspi_set_speed(struct udevice *bus, uint speed)
361{
Simon Glass95588622020-12-22 19:30:28 -0700362 struct zynqmp_qspi_plat *plat = dev_get_plat(bus);
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530363 struct zynqmp_qspi_priv *priv = dev_get_priv(bus);
364 struct zynqmp_qspi_regs *regs = priv->regs;
365 u32 confr;
366 u8 baud_rate_val = 0;
367
Ibai Erkiaga78974fb2023-10-13 13:37:27 +0100368 log_debug("%s, Speed: %d, Max: %d\n", __func__, speed, plat->frequency);
369
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530370 if (speed > plat->frequency)
371 speed = plat->frequency;
372
Brandon Maierb8003d52021-01-20 14:28:30 -0600373 if (plat->speed_hz != speed) {
374 /* Set the clock frequency */
375 /* If speed == 0, default to lowest speed */
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530376 while ((baud_rate_val < 8) &&
377 ((plat->frequency /
378 (2 << baud_rate_val)) > speed))
379 baud_rate_val++;
380
381 if (baud_rate_val > GQSPI_MAX_BAUD_RATE_VAL)
382 baud_rate_val = GQSPI_DFLT_BAUD_RATE_VAL;
383
384 plat->speed_hz = plat->frequency / (2 << baud_rate_val);
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530385
Brandon Maierb8003d52021-01-20 14:28:30 -0600386 confr = readl(&regs->confr);
387 confr &= ~GQSPI_BAUD_DIV_MASK;
388 confr |= (baud_rate_val << 3);
389 writel(confr, &regs->confr);
Brandon Maierb8003d52021-01-20 14:28:30 -0600390
Ibai Erkiaga78974fb2023-10-13 13:37:27 +0100391 zynqmp_qspi_set_tapdelay(bus, baud_rate_val);
Brandon Maierb8003d52021-01-20 14:28:30 -0600392 }
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530393
394 return 0;
395}
396
397static int zynqmp_qspi_probe(struct udevice *bus)
398{
Simon Glassb75b15b2020-12-03 16:55:23 -0700399 struct zynqmp_qspi_plat *plat = dev_get_plat(bus);
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530400 struct zynqmp_qspi_priv *priv = dev_get_priv(bus);
401 struct clk clk;
402 unsigned long clock;
403 int ret;
404
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530405 priv->regs = plat->regs;
406 priv->dma_regs = plat->dma_regs;
Ashok Reddy Soma96db8b62022-08-25 06:59:03 -0600407 priv->io_mode = plat->io_mode;
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530408
409 ret = clk_get_by_index(bus, 0, &clk);
410 if (ret < 0) {
Sean Anderson241232a2020-09-15 10:45:12 -0400411 dev_err(bus, "failed to get clock\n");
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530412 return ret;
413 }
414
415 clock = clk_get_rate(&clk);
416 if (IS_ERR_VALUE(clock)) {
Sean Anderson241232a2020-09-15 10:45:12 -0400417 dev_err(bus, "failed to get rate\n");
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530418 return clock;
419 }
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530420
421 ret = clk_enable(&clk);
Michal Simek41710952021-02-09 15:28:15 +0100422 if (ret) {
Sean Anderson241232a2020-09-15 10:45:12 -0400423 dev_err(bus, "failed to enable clock\n");
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530424 return ret;
425 }
426 plat->frequency = clock;
427 plat->speed_hz = plat->frequency / 2;
428
429 /* init the zynq spi hw */
430 zynqmp_qspi_init_hw(priv);
431
Ibai Erkiaga78974fb2023-10-13 13:37:27 +0100432 log_debug("%s, Rerence clock frequency: %ld\n", __func__, clock);
433
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530434 return 0;
435}
436
437static int zynqmp_qspi_set_mode(struct udevice *bus, uint mode)
438{
439 struct zynqmp_qspi_priv *priv = dev_get_priv(bus);
440 struct zynqmp_qspi_regs *regs = priv->regs;
441 u32 confr;
442
Ibai Erkiaga78974fb2023-10-13 13:37:27 +0100443 log_debug("%s, 0x%X\n", __func__, mode);
444
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530445 /* Set the SPI Clock phase and polarities */
446 confr = readl(&regs->confr);
Ashok Reddy Soma7b4bded2022-08-25 06:59:05 -0600447 confr &= ~(GQSPI_CONFIG_CPHA_MASK | GQSPI_CONFIG_CPOL_MASK);
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530448
449 if (mode & SPI_CPHA)
450 confr |= GQSPI_CONFIG_CPHA_MASK;
451 if (mode & SPI_CPOL)
452 confr |= GQSPI_CONFIG_CPOL_MASK;
453
454 writel(confr, &regs->confr);
455
456 return 0;
457}
458
459static int zynqmp_qspi_fill_tx_fifo(struct zynqmp_qspi_priv *priv, u32 size)
460{
461 u32 data;
462 int ret = 0;
463 struct zynqmp_qspi_regs *regs = priv->regs;
464 u32 *buf = (u32 *)priv->tx_buf;
465 u32 len = size;
466
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530467 while (size) {
468 ret = wait_for_bit_le32(&regs->isr, GQSPI_IXR_TXNFULL_MASK, 1,
469 GQSPI_TIMEOUT, 1);
Ibai Erkiaga78974fb2023-10-13 13:37:27 +0100470 if (ret)
471 return log_msg_ret("Timeout\n", ret);
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530472
473 if (size >= 4) {
474 writel(*buf, &regs->txd0r);
475 buf++;
476 size -= 4;
477 } else {
478 switch (size) {
479 case 1:
480 data = *((u8 *)buf);
481 buf += 1;
482 data |= GENMASK(31, 8);
483 break;
484 case 2:
485 data = *((u16 *)buf);
486 buf += 2;
487 data |= GENMASK(31, 16);
488 break;
489 case 3:
T Karthik Reddycc59fc92020-11-19 05:00:36 -0700490 data = *buf;
491 buf += 3;
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530492 data |= GENMASK(31, 24);
493 break;
494 }
495 writel(data, &regs->txd0r);
496 size = 0;
497 }
498 }
499
Ashok Reddy Soma26f77d72021-10-19 19:43:00 +0530500 ret = wait_for_bit_le32(&regs->isr, GQSPI_IXR_TXFIFOEMPTY_MASK, 1,
501 GQSPI_TIMEOUT, 1);
Ibai Erkiaga78974fb2023-10-13 13:37:27 +0100502 if (ret)
503 return log_msg_ret("Timeout\n", ret);
Ashok Reddy Soma26f77d72021-10-19 19:43:00 +0530504
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530505 priv->tx_buf += len;
506 return 0;
507}
508
509static void zynqmp_qspi_genfifo_cmd(struct zynqmp_qspi_priv *priv)
510{
Brandon Maier4d9cce72021-01-20 10:39:46 -0600511 const struct spi_mem_op *op = priv->op;
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530512 u32 gen_fifo_cmd;
Brandon Maier4d9cce72021-01-20 10:39:46 -0600513 u8 i, dummy_cycles, addr;
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530514
Ibai Erkiaga78974fb2023-10-13 13:37:27 +0100515 log_debug("%s, opcode: 0x%0X, addr.nbytes: %d, dummy.mbytes: %d\r\n",
516 __func__, op->cmd.opcode, op->addr.nbytes, op->dummy.nbytes);
517
Brandon Maier4d9cce72021-01-20 10:39:46 -0600518 /* Send opcode */
519 gen_fifo_cmd = zynqmp_qspi_bus_select(priv);
520 gen_fifo_cmd |= zynqmp_qspi_genfifo_mode(op->cmd.buswidth);
521 gen_fifo_cmd |= GQSPI_GFIFO_TX;
522 gen_fifo_cmd |= op->cmd.opcode;
523 zynqmp_qspi_fill_gen_fifo(priv, gen_fifo_cmd);
524
525 /* Send address */
526 for (i = 0; i < op->addr.nbytes; i++) {
527 addr = op->addr.val >> (8 * (op->addr.nbytes - i - 1));
528
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530529 gen_fifo_cmd = zynqmp_qspi_bus_select(priv);
Brandon Maier4d9cce72021-01-20 10:39:46 -0600530 gen_fifo_cmd |= zynqmp_qspi_genfifo_mode(op->addr.buswidth);
531 gen_fifo_cmd |= GQSPI_GFIFO_TX;
532 gen_fifo_cmd |= addr;
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530533
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530534 zynqmp_qspi_fill_gen_fifo(priv, gen_fifo_cmd);
535 }
Brandon Maier4d9cce72021-01-20 10:39:46 -0600536
537 /* Send dummy */
538 if (op->dummy.nbytes) {
539 dummy_cycles = op->dummy.nbytes * 8 / op->dummy.buswidth;
540
541 gen_fifo_cmd = zynqmp_qspi_bus_select(priv);
542 gen_fifo_cmd |= zynqmp_qspi_genfifo_mode(op->dummy.buswidth);
543 gen_fifo_cmd &= ~(GQSPI_GFIFO_TX | GQSPI_GFIFO_RX);
544 gen_fifo_cmd |= GQSPI_GFIFO_DATA_XFR_MASK;
545 gen_fifo_cmd |= dummy_cycles;
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530546 zynqmp_qspi_fill_gen_fifo(priv, gen_fifo_cmd);
547 }
548}
549
550static u32 zynqmp_qspi_calc_exp(struct zynqmp_qspi_priv *priv,
551 u32 *gen_fifo_cmd)
552{
553 u32 expval = 8;
554 u32 len;
555
556 while (1) {
557 if (priv->len > 255) {
558 if (priv->len & (1 << expval)) {
559 *gen_fifo_cmd &= ~GQSPI_GFIFO_IMD_MASK;
560 *gen_fifo_cmd |= GQSPI_GFIFO_EXP_MASK;
561 *gen_fifo_cmd |= expval;
562 priv->len -= (1 << expval);
563 return expval;
564 }
565 expval++;
566 } else {
567 *gen_fifo_cmd &= ~(GQSPI_GFIFO_IMD_MASK |
568 GQSPI_GFIFO_EXP_MASK);
569 *gen_fifo_cmd |= (u8)priv->len;
570 len = (u8)priv->len;
571 priv->len = 0;
572 return len;
573 }
574 }
575}
576
577static int zynqmp_qspi_genfifo_fill_tx(struct zynqmp_qspi_priv *priv)
578{
579 u32 gen_fifo_cmd;
580 u32 len;
581 int ret = 0;
582
Ibai Erkiaga78974fb2023-10-13 13:37:27 +0100583 log_debug("%s, length: %d\r\n", __func__, priv->len);
584
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530585 gen_fifo_cmd = zynqmp_qspi_bus_select(priv);
Brandon Maier4d9cce72021-01-20 10:39:46 -0600586 gen_fifo_cmd |= zynqmp_qspi_genfifo_mode(priv->op->data.buswidth);
Ashok Reddy Soma7b4bded2022-08-25 06:59:05 -0600587 gen_fifo_cmd |= GQSPI_GFIFO_TX | GQSPI_GFIFO_DATA_XFR_MASK;
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530588
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530589 while (priv->len) {
590 len = zynqmp_qspi_calc_exp(priv, &gen_fifo_cmd);
591 zynqmp_qspi_fill_gen_fifo(priv, gen_fifo_cmd);
592
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530593 if (gen_fifo_cmd & GQSPI_GFIFO_EXP_MASK)
Ashok Reddy Soma7b4bded2022-08-25 06:59:05 -0600594 ret = zynqmp_qspi_fill_tx_fifo(priv, 1 << len);
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530595 else
Ashok Reddy Soma7b4bded2022-08-25 06:59:05 -0600596 ret = zynqmp_qspi_fill_tx_fifo(priv, len);
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530597
598 if (ret)
599 return ret;
600 }
601 return ret;
602}
603
Ashok Reddy Soma96db8b62022-08-25 06:59:03 -0600604static int zynqmp_qspi_start_io(struct zynqmp_qspi_priv *priv,
605 u32 gen_fifo_cmd, u32 *buf)
606{
607 u32 len;
Ashok Reddy Soma96db8b62022-08-25 06:59:03 -0600608 u32 config_reg, ier, isr;
609 u32 timeout = GQSPI_TIMEOUT;
610 struct zynqmp_qspi_regs *regs = priv->regs;
611 u32 last_bits;
612 u32 *traverse = buf;
613
614 while (priv->len) {
615 len = zynqmp_qspi_calc_exp(priv, &gen_fifo_cmd);
616 /* If exponent bit is set, reset immediate to be 2^len */
617 if (gen_fifo_cmd & GQSPI_GFIFO_EXP_MASK)
618 priv->bytes_to_receive = (1 << len);
619 else
620 priv->bytes_to_receive = len;
621 zynqmp_qspi_fill_gen_fifo(priv, gen_fifo_cmd);
Ibai Erkiaga78974fb2023-10-13 13:37:27 +0100622
Ashok Reddy Soma96db8b62022-08-25 06:59:03 -0600623 /* Manual start */
624 config_reg = readl(&regs->confr);
625 config_reg |= GQSPI_STRT_GEN_FIFO;
626 writel(config_reg, &regs->confr);
627 /* Enable RX interrupts for IO mode */
628 ier = readl(&regs->ier);
629 ier |= GQSPI_IXR_ALL_MASK;
630 writel(ier, &regs->ier);
631 while (priv->bytes_to_receive && timeout) {
632 isr = readl(&regs->isr);
633 if (isr & GQSPI_IXR_RXNEMTY_MASK) {
634 if (priv->bytes_to_receive >= 4) {
635 *traverse = readl(&regs->drxr);
636 traverse++;
637 priv->bytes_to_receive -= 4;
638 } else {
639 last_bits = readl(&regs->drxr);
640 memcpy(traverse, &last_bits,
641 priv->bytes_to_receive);
642 priv->bytes_to_receive = 0;
643 }
644 timeout = GQSPI_TIMEOUT;
645 } else {
646 udelay(1);
647 timeout--;
648 }
649 }
650
Ibai Erkiaga78974fb2023-10-13 13:37:27 +0100651 if (!timeout)
652 return log_msg_retz("Timeout\n", timeout);
Ashok Reddy Soma96db8b62022-08-25 06:59:03 -0600653 }
654
655 return 0;
656}
657
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530658static int zynqmp_qspi_start_dma(struct zynqmp_qspi_priv *priv,
659 u32 gen_fifo_cmd, u32 *buf)
660{
Venkatesh Yadav Abbarapufce730e2022-11-25 16:14:13 +0530661 unsigned long addr;
Ashok Reddy Soma822a2432021-08-20 07:43:17 -0600662 u32 size;
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530663 u32 actuallen = priv->len;
Ashok Reddy Soma2d322cc2022-08-25 06:59:04 -0600664 u32 totallen = priv->len;
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530665 int ret = 0;
666 struct zynqmp_qspi_dma_regs *dma_regs = priv->dma_regs;
667
Ashok Reddy Soma2d322cc2022-08-25 06:59:04 -0600668 while (totallen) {
669 if (totallen >= SZ_512M)
670 priv->len = SZ_256M;
671 else
672 priv->len = totallen;
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530673
Ashok Reddy Soma2d322cc2022-08-25 06:59:04 -0600674 totallen -= priv->len; /* Save remaining bytes length to read */
675 actuallen = priv->len; /* Actual number of bytes reading */
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530676
Venkatesh Yadav Abbarapufce730e2022-11-25 16:14:13 +0530677 writel(lower_32_bits((unsigned long)buf), &dma_regs->dmadst);
678 writel(upper_32_bits((unsigned long)buf) & GENMASK(11, 0),
679 &dma_regs->dmadstmsb);
Ashok Reddy Soma2d322cc2022-08-25 06:59:04 -0600680 writel(roundup(priv->len, GQSPI_DMA_ALIGN), &dma_regs->dmasize);
681 writel(GQSPI_DMA_DST_I_STS_MASK, &dma_regs->dmaier);
682 addr = (unsigned long)buf;
683 size = roundup(priv->len, GQSPI_DMA_ALIGN);
Ashok Reddy Soma6753c8b2023-09-15 08:47:58 +0530684 invalidate_dcache_range(addr, addr + size);
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530685
Ashok Reddy Soma2d322cc2022-08-25 06:59:04 -0600686 while (priv->len) {
687 zynqmp_qspi_calc_exp(priv, &gen_fifo_cmd);
688 zynqmp_qspi_fill_gen_fifo(priv, gen_fifo_cmd);
Ashok Reddy Soma2d322cc2022-08-25 06:59:04 -0600689 }
690
691 ret = wait_for_bit_le32(&dma_regs->dmaisr,
692 GQSPI_DMA_DST_I_STS_DONE, 1,
693 GQSPI_TIMEOUT, 1);
Ibai Erkiaga78974fb2023-10-13 13:37:27 +0100694 if (ret)
695 return log_msg_ret("Timeout:\n", ret);
Ashok Reddy Soma2d322cc2022-08-25 06:59:04 -0600696
Venkatesh Yadav Abbarapu5f97cef2023-09-15 08:47:59 +0530697 invalidate_dcache_range(addr, addr + size);
698
Ashok Reddy Soma2d322cc2022-08-25 06:59:04 -0600699 writel(GQSPI_DMA_DST_I_STS_DONE, &dma_regs->dmaisr);
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530700
Ashok Reddy Soma2d322cc2022-08-25 06:59:04 -0600701 if (buf != priv->rx_buf)
702 memcpy(priv->rx_buf, buf, actuallen);
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530703
Ashok Reddy Soma2d322cc2022-08-25 06:59:04 -0600704 buf = (u32 *)((u8 *)buf + actuallen);
705 priv->rx_buf = (u8 *)priv->rx_buf + actuallen;
706 }
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530707
708 return 0;
709}
710
711static int zynqmp_qspi_genfifo_fill_rx(struct zynqmp_qspi_priv *priv)
712{
713 u32 gen_fifo_cmd;
714 u32 *buf;
715 u32 actuallen = priv->len;
716
Ibai Erkiaga78974fb2023-10-13 13:37:27 +0100717 log_debug("%s, length: %d\r\n", __func__, priv->len);
718
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530719 gen_fifo_cmd = zynqmp_qspi_bus_select(priv);
Brandon Maier4d9cce72021-01-20 10:39:46 -0600720 gen_fifo_cmd |= zynqmp_qspi_genfifo_mode(priv->op->data.buswidth);
Ashok Reddy Soma7b4bded2022-08-25 06:59:05 -0600721 gen_fifo_cmd |= GQSPI_GFIFO_RX | GQSPI_GFIFO_DATA_XFR_MASK;
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530722
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530723 /*
724 * Check if receive buffer is aligned to 4 byte and length
725 * is multiples of four byte as we are using dma to receive.
726 */
Ashok Reddy Soma96db8b62022-08-25 06:59:03 -0600727 if ((!((unsigned long)priv->rx_buf & (GQSPI_DMA_ALIGN - 1)) &&
728 !(actuallen % GQSPI_DMA_ALIGN)) || priv->io_mode) {
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530729 buf = (u32 *)priv->rx_buf;
Ashok Reddy Soma96db8b62022-08-25 06:59:03 -0600730 if (priv->io_mode)
731 return zynqmp_qspi_start_io(priv, gen_fifo_cmd, buf);
732 else
733 return zynqmp_qspi_start_dma(priv, gen_fifo_cmd, buf);
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530734 }
735
Ashok Reddy Soma7b4bded2022-08-25 06:59:05 -0600736 ALLOC_CACHE_ALIGN_BUFFER(u8, tmp, roundup(priv->len, GQSPI_DMA_ALIGN));
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530737 buf = (u32 *)tmp;
738 return zynqmp_qspi_start_dma(priv, gen_fifo_cmd, buf);
739}
740
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530741static int zynqmp_qspi_claim_bus(struct udevice *dev)
742{
743 struct udevice *bus = dev->parent;
744 struct zynqmp_qspi_priv *priv = dev_get_priv(bus);
745 struct zynqmp_qspi_regs *regs = priv->regs;
746
747 writel(GQSPI_ENABLE_ENABLE_MASK, &regs->enbr);
748
749 return 0;
750}
751
752static int zynqmp_qspi_release_bus(struct udevice *dev)
753{
754 struct udevice *bus = dev->parent;
755 struct zynqmp_qspi_priv *priv = dev_get_priv(bus);
756 struct zynqmp_qspi_regs *regs = priv->regs;
757
758 writel(~GQSPI_ENABLE_ENABLE_MASK, &regs->enbr);
759
760 return 0;
761}
762
Brandon Maier4d9cce72021-01-20 10:39:46 -0600763static int zynqmp_qspi_exec_op(struct spi_slave *slave,
764 const struct spi_mem_op *op)
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530765{
Brandon Maier4d9cce72021-01-20 10:39:46 -0600766 struct zynqmp_qspi_priv *priv = dev_get_priv(slave->dev->parent);
767 int ret = 0;
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530768
Brandon Maier4d9cce72021-01-20 10:39:46 -0600769 priv->op = op;
770 priv->tx_buf = op->data.buf.out;
771 priv->rx_buf = op->data.buf.in;
772 priv->len = op->data.nbytes;
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530773
Brandon Maier4d9cce72021-01-20 10:39:46 -0600774 zynqmp_qspi_chipselect(priv, 1);
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530775
Brandon Maier4d9cce72021-01-20 10:39:46 -0600776 /* Send opcode, addr, dummy */
777 zynqmp_qspi_genfifo_cmd(priv);
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530778
Brandon Maier4d9cce72021-01-20 10:39:46 -0600779 /* Request the transfer */
780 if (op->data.dir == SPI_MEM_DATA_IN)
781 ret = zynqmp_qspi_genfifo_fill_rx(priv);
782 else if (op->data.dir == SPI_MEM_DATA_OUT)
783 ret = zynqmp_qspi_genfifo_fill_tx(priv);
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530784
Brandon Maier4d9cce72021-01-20 10:39:46 -0600785 zynqmp_qspi_chipselect(priv, 0);
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530786
Brandon Maier4d9cce72021-01-20 10:39:46 -0600787 return ret;
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530788}
789
Brandon Maier4d9cce72021-01-20 10:39:46 -0600790static const struct spi_controller_mem_ops zynqmp_qspi_mem_ops = {
791 .exec_op = zynqmp_qspi_exec_op,
792};
793
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530794static const struct dm_spi_ops zynqmp_qspi_ops = {
795 .claim_bus = zynqmp_qspi_claim_bus,
796 .release_bus = zynqmp_qspi_release_bus,
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530797 .set_speed = zynqmp_qspi_set_speed,
798 .set_mode = zynqmp_qspi_set_mode,
Brandon Maier4d9cce72021-01-20 10:39:46 -0600799 .mem_ops = &zynqmp_qspi_mem_ops,
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530800};
801
802static const struct udevice_id zynqmp_qspi_ids[] = {
803 { .compatible = "xlnx,zynqmp-qspi-1.0" },
Michal Simeked373eb2018-11-29 08:48:28 +0100804 { .compatible = "xlnx,versal-qspi-1.0" },
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530805 { }
806};
807
808U_BOOT_DRIVER(zynqmp_qspi) = {
809 .name = "zynqmp_qspi",
810 .id = UCLASS_SPI,
811 .of_match = zynqmp_qspi_ids,
812 .ops = &zynqmp_qspi_ops,
Simon Glassaad29ae2020-12-03 16:55:21 -0700813 .of_to_plat = zynqmp_qspi_of_to_plat,
Simon Glassb75b15b2020-12-03 16:55:23 -0700814 .plat_auto = sizeof(struct zynqmp_qspi_plat),
Simon Glass8a2b47f2020-12-03 16:55:17 -0700815 .priv_auto = sizeof(struct zynqmp_qspi_priv),
Siva Durga Prasad Paladugu76597382018-07-04 17:31:23 +0530816 .probe = zynqmp_qspi_probe,
817};