blob: 6e50b94e142576e04875966d3318d2438b676fb3 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Stefan Roese10e8bf82014-11-07 12:37:49 +01002/*
3 * Copyright (C) 2012
4 * Altera Corporation <www.altera.com>
Stefan Roese10e8bf82014-11-07 12:37:49 +01005 */
6
7#include <common.h>
Simon Goldschmidt64c7c8c2019-11-20 22:27:31 +01008#include <clk.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -06009#include <log.h>
Vignesh Raghavendra0f247842019-12-05 15:46:06 +053010#include <asm-generic/io.h>
Stefan Roese10e8bf82014-11-07 12:37:49 +010011#include <dm.h>
12#include <fdtdec.h>
13#include <malloc.h>
Simon Goldschmidtac7e14a2019-03-01 20:12:35 +010014#include <reset.h>
Stefan Roese10e8bf82014-11-07 12:37:49 +010015#include <spi.h>
Vignesh Raghavendrad6407722020-01-27 10:36:39 +053016#include <spi-mem.h>
Simon Glass336d4612020-02-03 07:36:16 -070017#include <dm/device_compat.h>
Simon Glass61b29b82020-02-03 07:36:15 -070018#include <linux/err.h>
Masahiro Yamada1221ce42016-09-21 11:28:55 +090019#include <linux/errno.h>
Vignesh Raghavendraffab2122020-01-27 10:36:40 +053020#include <linux/sizes.h>
T Karthik Reddy248fe9f2022-05-12 04:05:34 -060021#include <zynqmp_firmware.h>
Stefan Roese10e8bf82014-11-07 12:37:49 +010022#include "cadence_qspi.h"
T Karthik Reddy248fe9f2022-05-12 04:05:34 -060023#include <dt-bindings/power/xlnx-versal-power.h>
Stefan Roese10e8bf82014-11-07 12:37:49 +010024
Pratyush Yadava6903aa2021-06-26 00:47:08 +053025#define NSEC_PER_SEC 1000000000L
26
Stefan Roese10e8bf82014-11-07 12:37:49 +010027#define CQSPI_STIG_READ 0
28#define CQSPI_STIG_WRITE 1
Vignesh Raghavendraffab2122020-01-27 10:36:40 +053029#define CQSPI_READ 2
30#define CQSPI_WRITE 3
Stefan Roese10e8bf82014-11-07 12:37:49 +010031
T Karthik Reddycf553bf2022-05-12 04:05:32 -060032__weak int cadence_qspi_apb_dma_read(struct cadence_spi_plat *plat,
33 const struct spi_mem_op *op)
34{
35 return 0;
36}
37
T Karthik Reddybf8dae52022-05-12 04:05:33 -060038__weak int cadence_qspi_versal_flash_reset(struct udevice *dev)
39{
40 return 0;
41}
42
Stefan Roese10e8bf82014-11-07 12:37:49 +010043static int cadence_spi_write_speed(struct udevice *bus, uint hz)
44{
Simon Glass0fd3d912020-12-22 19:30:28 -070045 struct cadence_spi_plat *plat = dev_get_plat(bus);
Stefan Roese10e8bf82014-11-07 12:37:49 +010046 struct cadence_spi_priv *priv = dev_get_priv(bus);
47
48 cadence_qspi_apb_config_baudrate_div(priv->regbase,
Simon Goldschmidt64c7c8c2019-11-20 22:27:31 +010049 plat->ref_clk_hz, hz);
Stefan Roese10e8bf82014-11-07 12:37:49 +010050
51 /* Reconfigure delay timing if speed is changed. */
Simon Goldschmidt64c7c8c2019-11-20 22:27:31 +010052 cadence_qspi_apb_delay(priv->regbase, plat->ref_clk_hz, hz,
Stefan Roese10e8bf82014-11-07 12:37:49 +010053 plat->tshsl_ns, plat->tsd2d_ns,
54 plat->tchsh_ns, plat->tslch_ns);
55
56 return 0;
57}
58
Pratyush Yadav38b08522021-06-26 00:47:09 +053059static int cadence_spi_read_id(struct cadence_spi_plat *plat, u8 len,
60 u8 *idcode)
Vignesh Raghavendrad6407722020-01-27 10:36:39 +053061{
Ashok Reddy Somad0003b52022-08-24 05:38:46 -060062 int err;
Vignesh Raghavendrad6407722020-01-27 10:36:39 +053063 struct spi_mem_op op = SPI_MEM_OP(SPI_MEM_OP_CMD(0x9F, 1),
64 SPI_MEM_OP_NO_ADDR,
65 SPI_MEM_OP_NO_DUMMY,
66 SPI_MEM_OP_DATA_IN(len, idcode, 1));
67
Ashok Reddy Somad0003b52022-08-24 05:38:46 -060068 err = cadence_qspi_apb_command_read_setup(plat, &op);
69 if (!err)
70 err = cadence_qspi_apb_command_read(plat, &op);
71
72 return err;
Vignesh Raghavendrad6407722020-01-27 10:36:39 +053073}
74
Stefan Roese10e8bf82014-11-07 12:37:49 +010075/* Calibration sequence to determine the read data capture delay register */
Chin Liang See98fbd712015-10-17 08:31:55 -050076static int spi_calibration(struct udevice *bus, uint hz)
Stefan Roese10e8bf82014-11-07 12:37:49 +010077{
Stefan Roese10e8bf82014-11-07 12:37:49 +010078 struct cadence_spi_priv *priv = dev_get_priv(bus);
Pratyush Yadav38b08522021-06-26 00:47:09 +053079 struct cadence_spi_plat *plat = dev_get_plat(bus);
Stefan Roese10e8bf82014-11-07 12:37:49 +010080 void *base = priv->regbase;
Stefan Roese10e8bf82014-11-07 12:37:49 +010081 unsigned int idcode = 0, temp = 0;
82 int err = 0, i, range_lo = -1, range_hi = -1;
83
84 /* start with slowest clock (1 MHz) */
85 cadence_spi_write_speed(bus, 1000000);
86
87 /* configure the read data capture delay register to 0 */
88 cadence_qspi_apb_readdata_capture(base, 1, 0);
89
90 /* Enable QSPI */
91 cadence_qspi_apb_controller_enable(base);
92
93 /* read the ID which will be our golden value */
Pratyush Yadav38b08522021-06-26 00:47:09 +053094 err = cadence_spi_read_id(plat, 3, (u8 *)&idcode);
Stefan Roese10e8bf82014-11-07 12:37:49 +010095 if (err) {
96 puts("SF: Calibration failed (read)\n");
97 return err;
98 }
99
100 /* use back the intended clock and find low range */
Chin Liang See98fbd712015-10-17 08:31:55 -0500101 cadence_spi_write_speed(bus, hz);
Stefan Roese10e8bf82014-11-07 12:37:49 +0100102 for (i = 0; i < CQSPI_READ_CAPTURE_MAX_DELAY; i++) {
103 /* Disable QSPI */
104 cadence_qspi_apb_controller_disable(base);
105
106 /* reconfigure the read data capture delay register */
107 cadence_qspi_apb_readdata_capture(base, 1, i);
108
109 /* Enable back QSPI */
110 cadence_qspi_apb_controller_enable(base);
111
112 /* issue a RDID to get the ID value */
Pratyush Yadav38b08522021-06-26 00:47:09 +0530113 err = cadence_spi_read_id(plat, 3, (u8 *)&temp);
Stefan Roese10e8bf82014-11-07 12:37:49 +0100114 if (err) {
115 puts("SF: Calibration failed (read)\n");
116 return err;
117 }
118
119 /* search for range lo */
120 if (range_lo == -1 && temp == idcode) {
121 range_lo = i;
122 continue;
123 }
124
125 /* search for range hi */
126 if (range_lo != -1 && temp != idcode) {
127 range_hi = i - 1;
128 break;
129 }
130 range_hi = i;
131 }
132
133 if (range_lo == -1) {
134 puts("SF: Calibration failed (low range)\n");
135 return err;
136 }
137
138 /* Disable QSPI for subsequent initialization */
139 cadence_qspi_apb_controller_disable(base);
140
141 /* configure the final value for read data capture delay register */
142 cadence_qspi_apb_readdata_capture(base, 1, (range_hi + range_lo) / 2);
143 debug("SF: Read data capture delay calibrated to %i (%i - %i)\n",
144 (range_hi + range_lo) / 2, range_lo, range_hi);
145
146 /* just to ensure we do once only when speed or chip select change */
Chin Liang See98fbd712015-10-17 08:31:55 -0500147 priv->qspi_calibrated_hz = hz;
Stefan Roese10e8bf82014-11-07 12:37:49 +0100148 priv->qspi_calibrated_cs = spi_chip_select(bus);
149
150 return 0;
151}
152
153static int cadence_spi_set_speed(struct udevice *bus, uint hz)
154{
Simon Glass0fd3d912020-12-22 19:30:28 -0700155 struct cadence_spi_plat *plat = dev_get_plat(bus);
Stefan Roese10e8bf82014-11-07 12:37:49 +0100156 struct cadence_spi_priv *priv = dev_get_priv(bus);
157 int err;
158
T Karthik Reddy2c27fdc2022-05-12 04:05:35 -0600159 if (!hz || hz > plat->max_hz)
Chin Liang See4e609b62015-10-17 08:32:38 -0500160 hz = plat->max_hz;
161
Stefan Roese10e8bf82014-11-07 12:37:49 +0100162 /* Disable QSPI */
163 cadence_qspi_apb_controller_disable(priv->regbase);
164
Chin Liang See98fbd712015-10-17 08:31:55 -0500165 /*
Pratyush Yadavbd8c8dc2021-06-26 00:47:07 +0530166 * If the device tree already provides a read delay value, use that
167 * instead of calibrating.
Chin Liang See98fbd712015-10-17 08:31:55 -0500168 */
Pratyush Yadavbd8c8dc2021-06-26 00:47:07 +0530169 if (plat->read_delay >= 0) {
170 cadence_spi_write_speed(bus, hz);
171 cadence_qspi_apb_readdata_capture(priv->regbase, 1,
172 plat->read_delay);
173 } else if (priv->previous_hz != hz ||
174 priv->qspi_calibrated_hz != hz ||
175 priv->qspi_calibrated_cs != spi_chip_select(bus)) {
176 /*
177 * Calibration required for different current SCLK speed,
178 * requested SCLK speed or chip select
179 */
Chin Liang See98fbd712015-10-17 08:31:55 -0500180 err = spi_calibration(bus, hz);
Stefan Roese10e8bf82014-11-07 12:37:49 +0100181 if (err)
182 return err;
Chin Liang See98fbd712015-10-17 08:31:55 -0500183
184 /* prevent calibration run when same as previous request */
185 priv->previous_hz = hz;
Stefan Roese10e8bf82014-11-07 12:37:49 +0100186 }
187
188 /* Enable QSPI */
189 cadence_qspi_apb_controller_enable(priv->regbase);
190
191 debug("%s: speed=%d\n", __func__, hz);
192
193 return 0;
194}
195
196static int cadence_spi_probe(struct udevice *bus)
197{
Simon Glass0fd3d912020-12-22 19:30:28 -0700198 struct cadence_spi_plat *plat = dev_get_plat(bus);
Stefan Roese10e8bf82014-11-07 12:37:49 +0100199 struct cadence_spi_priv *priv = dev_get_priv(bus);
Pratyush Yadav0a9c2872020-02-24 12:40:51 +0530200 struct clk clk;
Simon Goldschmidtac7e14a2019-03-01 20:12:35 +0100201 int ret;
Stefan Roese10e8bf82014-11-07 12:37:49 +0100202
203 priv->regbase = plat->regbase;
204 priv->ahbbase = plat->ahbbase;
205
T Karthik Reddy248fe9f2022-05-12 04:05:34 -0600206 if (CONFIG_IS_ENABLED(ZYNQMP_FIRMWARE))
207 xilinx_pm_request(PM_REQUEST_NODE, PM_DEV_OSPI,
208 ZYNQMP_PM_CAPABILITY_ACCESS, ZYNQMP_PM_MAX_QOS,
209 ZYNQMP_PM_REQUEST_ACK_NO, NULL);
210
Pratyush Yadav0a9c2872020-02-24 12:40:51 +0530211 if (plat->ref_clk_hz == 0) {
212 ret = clk_get_by_index(bus, 0, &clk);
213 if (ret) {
Tom Rini55b3ba42022-03-30 18:07:23 -0400214#ifdef CONFIG_HAS_CQSPI_REF_CLK
Pratyush Yadav0a9c2872020-02-24 12:40:51 +0530215 plat->ref_clk_hz = CONFIG_CQSPI_REF_CLK;
Tom Rini55b3ba42022-03-30 18:07:23 -0400216#elif defined(CONFIG_ARCH_SOCFPGA)
217 plat->ref_clk_hz = cm_get_qspi_controller_clk_hz();
Pratyush Yadav0a9c2872020-02-24 12:40:51 +0530218#else
219 return ret;
220#endif
221 } else {
222 plat->ref_clk_hz = clk_get_rate(&clk);
223 clk_free(&clk);
224 if (IS_ERR_VALUE(plat->ref_clk_hz))
225 return plat->ref_clk_hz;
226 }
227 }
228
Christian Gmeinere1456062022-02-22 17:23:25 +0100229 priv->resets = devm_reset_bulk_get_optional(bus);
230 if (priv->resets)
231 reset_deassert_bulk(priv->resets);
Simon Goldschmidtac7e14a2019-03-01 20:12:35 +0100232
Stefan Roese10e8bf82014-11-07 12:37:49 +0100233 if (!priv->qspi_is_init) {
234 cadence_qspi_apb_controller_init(plat);
235 priv->qspi_is_init = 1;
236 }
237
Pratyush Yadava6903aa2021-06-26 00:47:08 +0530238 plat->wr_delay = 50 * DIV_ROUND_UP(NSEC_PER_SEC, plat->ref_clk_hz);
239
T Karthik Reddybf8dae52022-05-12 04:05:33 -0600240 if (CONFIG_IS_ENABLED(ARCH_VERSAL)) {
241 /* Versal platform uses spi calibration to set read delay */
242 if (plat->read_delay >= 0)
243 plat->read_delay = -1;
244 /* Reset ospi flash device */
245 ret = cadence_qspi_versal_flash_reset(bus);
246 if (ret)
247 return ret;
248 }
249
Stefan Roese10e8bf82014-11-07 12:37:49 +0100250 return 0;
251}
252
Simon Goldschmidtac7e14a2019-03-01 20:12:35 +0100253static int cadence_spi_remove(struct udevice *dev)
254{
255 struct cadence_spi_priv *priv = dev_get_priv(dev);
Christian Gmeinere1456062022-02-22 17:23:25 +0100256 int ret = 0;
Simon Goldschmidtac7e14a2019-03-01 20:12:35 +0100257
Christian Gmeinere1456062022-02-22 17:23:25 +0100258 if (priv->resets)
259 ret = reset_release_bulk(priv->resets);
260
261 return ret;
Simon Goldschmidtac7e14a2019-03-01 20:12:35 +0100262}
263
Stefan Roese10e8bf82014-11-07 12:37:49 +0100264static int cadence_spi_set_mode(struct udevice *bus, uint mode)
265{
Simon Glass0fd3d912020-12-22 19:30:28 -0700266 struct cadence_spi_plat *plat = dev_get_plat(bus);
Stefan Roese10e8bf82014-11-07 12:37:49 +0100267 struct cadence_spi_priv *priv = dev_get_priv(bus);
Stefan Roese10e8bf82014-11-07 12:37:49 +0100268
269 /* Disable QSPI */
270 cadence_qspi_apb_controller_disable(priv->regbase);
271
272 /* Set SPI mode */
Phil Edworthy7d403f22016-11-29 12:58:31 +0000273 cadence_qspi_apb_set_clk_mode(priv->regbase, mode);
Stefan Roese10e8bf82014-11-07 12:37:49 +0100274
Vignesh Raghavendraffab2122020-01-27 10:36:40 +0530275 /* Enable Direct Access Controller */
276 if (plat->use_dac_mode)
277 cadence_qspi_apb_dac_mode_enable(priv->regbase);
278
Stefan Roese10e8bf82014-11-07 12:37:49 +0100279 /* Enable QSPI */
280 cadence_qspi_apb_controller_enable(priv->regbase);
281
282 return 0;
283}
284
Vignesh Raghavendrad6407722020-01-27 10:36:39 +0530285static int cadence_spi_mem_exec_op(struct spi_slave *spi,
286 const struct spi_mem_op *op)
Stefan Roese10e8bf82014-11-07 12:37:49 +0100287{
Vignesh Raghavendrad6407722020-01-27 10:36:39 +0530288 struct udevice *bus = spi->dev->parent;
Simon Glass0fd3d912020-12-22 19:30:28 -0700289 struct cadence_spi_plat *plat = dev_get_plat(bus);
Stefan Roese10e8bf82014-11-07 12:37:49 +0100290 struct cadence_spi_priv *priv = dev_get_priv(bus);
291 void *base = priv->regbase;
Stefan Roese10e8bf82014-11-07 12:37:49 +0100292 int err = 0;
Vignesh Raghavendrad6407722020-01-27 10:36:39 +0530293 u32 mode;
Stefan Roese10e8bf82014-11-07 12:37:49 +0100294
295 /* Set Chip select */
Vignesh Raghavendrad6407722020-01-27 10:36:39 +0530296 cadence_qspi_apb_chipselect(base, spi_chip_select(spi->dev),
Jason Rush15a70a52018-01-23 17:13:09 -0600297 plat->is_decoded_cs);
Stefan Roese10e8bf82014-11-07 12:37:49 +0100298
Vignesh Raghavendrad6407722020-01-27 10:36:39 +0530299 if (op->data.dir == SPI_MEM_DATA_IN && op->data.buf.in) {
300 if (!op->addr.nbytes)
301 mode = CQSPI_STIG_READ;
302 else
Vignesh Raghavendraffab2122020-01-27 10:36:40 +0530303 mode = CQSPI_READ;
Vignesh Raghavendrad6407722020-01-27 10:36:39 +0530304 } else {
305 if (!op->addr.nbytes || !op->data.buf.out)
306 mode = CQSPI_STIG_WRITE;
307 else
Vignesh Raghavendraffab2122020-01-27 10:36:40 +0530308 mode = CQSPI_WRITE;
Vignesh Raghavendrad6407722020-01-27 10:36:39 +0530309 }
Stefan Roese10e8bf82014-11-07 12:37:49 +0100310
Vignesh Raghavendrad6407722020-01-27 10:36:39 +0530311 switch (mode) {
312 case CQSPI_STIG_READ:
Pratyush Yadav38b08522021-06-26 00:47:09 +0530313 err = cadence_qspi_apb_command_read_setup(plat, op);
314 if (!err)
315 err = cadence_qspi_apb_command_read(plat, op);
Vignesh Raghavendrad6407722020-01-27 10:36:39 +0530316 break;
317 case CQSPI_STIG_WRITE:
Pratyush Yadav38b08522021-06-26 00:47:09 +0530318 err = cadence_qspi_apb_command_write_setup(plat, op);
319 if (!err)
320 err = cadence_qspi_apb_command_write(plat, op);
Vignesh Raghavendrad6407722020-01-27 10:36:39 +0530321 break;
Vignesh Raghavendraffab2122020-01-27 10:36:40 +0530322 case CQSPI_READ:
323 err = cadence_qspi_apb_read_setup(plat, op);
T Karthik Reddycf553bf2022-05-12 04:05:32 -0600324 if (!err) {
325 if (plat->is_dma)
326 err = cadence_qspi_apb_dma_read(plat, op);
327 else
328 err = cadence_qspi_apb_read_execute(plat, op);
329 }
Stefan Roese10e8bf82014-11-07 12:37:49 +0100330 break;
Vignesh Raghavendraffab2122020-01-27 10:36:40 +0530331 case CQSPI_WRITE:
332 err = cadence_qspi_apb_write_setup(plat, op);
333 if (!err)
334 err = cadence_qspi_apb_write_execute(plat, op);
Vignesh Raghavendrad6407722020-01-27 10:36:39 +0530335 break;
336 default:
337 err = -1;
338 break;
Stefan Roese10e8bf82014-11-07 12:37:49 +0100339 }
340
341 return err;
342}
343
Pratyush Yadav38b08522021-06-26 00:47:09 +0530344static bool cadence_spi_mem_supports_op(struct spi_slave *slave,
345 const struct spi_mem_op *op)
346{
347 bool all_true, all_false;
348
349 all_true = op->cmd.dtr && op->addr.dtr && op->dummy.dtr &&
350 op->data.dtr;
351 all_false = !op->cmd.dtr && !op->addr.dtr && !op->dummy.dtr &&
352 !op->data.dtr;
353
354 /* Mixed DTR modes not supported. */
355 if (!(all_true || all_false))
356 return false;
357
358 if (all_true)
359 return spi_mem_dtr_supports_op(slave, op);
360 else
361 return spi_mem_default_supports_op(slave, op);
362}
363
Simon Glassd1998a92020-12-03 16:55:21 -0700364static int cadence_spi_of_to_plat(struct udevice *bus)
Stefan Roese10e8bf82014-11-07 12:37:49 +0100365{
Simon Glass0fd3d912020-12-22 19:30:28 -0700366 struct cadence_spi_plat *plat = dev_get_plat(bus);
Simon Goldschmidt46b633d2019-05-09 22:11:56 +0200367 ofnode subnode;
Stefan Roese10e8bf82014-11-07 12:37:49 +0100368
Ley Foon Tan6c353672018-05-07 17:42:55 +0800369 plat->regbase = (void *)devfdt_get_addr_index(bus, 0);
Vignesh Raghavendraffab2122020-01-27 10:36:40 +0530370 plat->ahbbase = (void *)devfdt_get_addr_size_index(bus, 1,
371 &plat->ahbsize);
Simon Goldschmidt46b633d2019-05-09 22:11:56 +0200372 plat->is_decoded_cs = dev_read_bool(bus, "cdns,is-decoded-cs");
373 plat->fifo_depth = dev_read_u32_default(bus, "cdns,fifo-depth", 128);
374 plat->fifo_width = dev_read_u32_default(bus, "cdns,fifo-width", 4);
375 plat->trigger_address = dev_read_u32_default(bus,
376 "cdns,trigger-address",
377 0);
Vignesh Raghavendraffab2122020-01-27 10:36:40 +0530378 /* Use DAC mode only when MMIO window is at least 8M wide */
379 if (plat->ahbsize >= SZ_8M)
380 plat->use_dac_mode = true;
Stefan Roese10e8bf82014-11-07 12:37:49 +0100381
T Karthik Reddycf553bf2022-05-12 04:05:32 -0600382 plat->is_dma = dev_read_bool(bus, "cdns,is-dma");
383
Stefan Roese10e8bf82014-11-07 12:37:49 +0100384 /* All other paramters are embedded in the child node */
Simon Goldschmidt46b633d2019-05-09 22:11:56 +0200385 subnode = dev_read_first_subnode(bus);
386 if (!ofnode_valid(subnode)) {
Stefan Roese10e8bf82014-11-07 12:37:49 +0100387 printf("Error: subnode with SPI flash config missing!\n");
388 return -ENODEV;
389 }
390
Chin Liang See040f4ba2015-10-17 08:32:14 -0500391 /* Use 500 KHz as a suitable default */
Simon Goldschmidt46b633d2019-05-09 22:11:56 +0200392 plat->max_hz = ofnode_read_u32_default(subnode, "spi-max-frequency",
393 500000);
Chin Liang See040f4ba2015-10-17 08:32:14 -0500394
Stefan Roese10e8bf82014-11-07 12:37:49 +0100395 /* Read other parameters from DT */
Simon Goldschmidt46b633d2019-05-09 22:11:56 +0200396 plat->page_size = ofnode_read_u32_default(subnode, "page-size", 256);
397 plat->block_size = ofnode_read_u32_default(subnode, "block-size", 16);
398 plat->tshsl_ns = ofnode_read_u32_default(subnode, "cdns,tshsl-ns",
399 200);
400 plat->tsd2d_ns = ofnode_read_u32_default(subnode, "cdns,tsd2d-ns",
401 255);
402 plat->tchsh_ns = ofnode_read_u32_default(subnode, "cdns,tchsh-ns", 20);
403 plat->tslch_ns = ofnode_read_u32_default(subnode, "cdns,tslch-ns", 20);
Pratyush Yadavbd8c8dc2021-06-26 00:47:07 +0530404 /*
405 * Read delay should be an unsigned value but we use a signed integer
406 * so that negative values can indicate that the device tree did not
407 * specify any signed values and we need to perform the calibration
408 * sequence to find it out.
409 */
410 plat->read_delay = ofnode_read_s32_default(subnode, "cdns,read-delay",
411 -1);
Stefan Roese10e8bf82014-11-07 12:37:49 +0100412
413 debug("%s: regbase=%p ahbbase=%p max-frequency=%d page-size=%d\n",
414 __func__, plat->regbase, plat->ahbbase, plat->max_hz,
415 plat->page_size);
416
417 return 0;
418}
419
Vignesh Raghavendrad6407722020-01-27 10:36:39 +0530420static const struct spi_controller_mem_ops cadence_spi_mem_ops = {
421 .exec_op = cadence_spi_mem_exec_op,
Pratyush Yadav38b08522021-06-26 00:47:09 +0530422 .supports_op = cadence_spi_mem_supports_op,
Vignesh Raghavendrad6407722020-01-27 10:36:39 +0530423};
424
Stefan Roese10e8bf82014-11-07 12:37:49 +0100425static const struct dm_spi_ops cadence_spi_ops = {
Stefan Roese10e8bf82014-11-07 12:37:49 +0100426 .set_speed = cadence_spi_set_speed,
427 .set_mode = cadence_spi_set_mode,
Vignesh Raghavendrad6407722020-01-27 10:36:39 +0530428 .mem_ops = &cadence_spi_mem_ops,
Stefan Roese10e8bf82014-11-07 12:37:49 +0100429 /*
430 * cs_info is not needed, since we require all chip selects to be
431 * in the device tree explicitly
432 */
433};
434
435static const struct udevice_id cadence_spi_ids[] = {
Simon Goldschmidt2a3a9992018-11-02 11:54:51 +0100436 { .compatible = "cdns,qspi-nor" },
Vignesh Raghavendradaa94052019-12-05 15:46:07 +0530437 { .compatible = "ti,am654-ospi" },
Stefan Roese10e8bf82014-11-07 12:37:49 +0100438 { }
439};
440
441U_BOOT_DRIVER(cadence_spi) = {
442 .name = "cadence_spi",
443 .id = UCLASS_SPI,
444 .of_match = cadence_spi_ids,
445 .ops = &cadence_spi_ops,
Simon Glassd1998a92020-12-03 16:55:21 -0700446 .of_to_plat = cadence_spi_of_to_plat,
Simon Glass8a8d24b2020-12-03 16:55:23 -0700447 .plat_auto = sizeof(struct cadence_spi_plat),
Simon Glass41575d82020-12-03 16:55:17 -0700448 .priv_auto = sizeof(struct cadence_spi_priv),
Stefan Roese10e8bf82014-11-07 12:37:49 +0100449 .probe = cadence_spi_probe,
Simon Goldschmidtac7e14a2019-03-01 20:12:35 +0100450 .remove = cadence_spi_remove,
451 .flags = DM_FLAG_OS_PREPARE,
Stefan Roese10e8bf82014-11-07 12:37:49 +0100452};